blob: afc0d9205937354b70fa64e1c7ebc83eea746c08 [file] [log] [blame]
Chandan Nath4ba33452011-10-14 02:58:23 +00001/*
Matt Porter57da6662013-03-15 10:07:04 +00002 * clock_am33xx.c
Chandan Nath4ba33452011-10-14 02:58:23 +00003 *
4 * clocks for AM33XX based boards
5 *
Matt Porter57da6662013-03-15 10:07:04 +00006 * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
Chandan Nath4ba33452011-10-14 02:58:23 +00007 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <common.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/hardware.h>
23#include <asm/io.h>
24
25#define PRCM_MOD_EN 0x2
26#define PRCM_FORCE_WAKEUP 0x2
Chandan Nath2015c382012-07-24 12:22:17 +000027#define PRCM_FUNCTL 0x0
Chandan Nath4ba33452011-10-14 02:58:23 +000028
29#define PRCM_EMIF_CLK_ACTIVITY BIT(2)
30#define PRCM_L3_GCLK_ACTIVITY BIT(4)
31
32#define PLL_BYPASS_MODE 0x4
33#define ST_MN_BYPASS 0x00000100
34#define ST_DPLL_CLK 0x00000001
35#define CLK_SEL_MASK 0x7ffff
36#define CLK_DIV_MASK 0x1f
37#define CLK_DIV2_MASK 0x7f
38#define CLK_SEL_SHIFT 0x8
39#define CLK_MODE_SEL 0x7
40#define CLK_MODE_MASK 0xfffffff8
41#define CLK_DIV_SEL 0xFFFFFFE0
Chandan Nath2015c382012-07-24 12:22:17 +000042#define CPGMAC0_IDLE 0x30000
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000043#define DPLL_CLKDCOLDO_GATE_CTRL 0x300
Chandan Nath4ba33452011-10-14 02:58:23 +000044
Matt Porter57da6662013-03-15 10:07:04 +000045#define OSC (V_OSCK/1000000)
46
47#define MPUPLL_M CONFIG_SYS_MPUCLK
48#define MPUPLL_N (OSC-1)
49#define MPUPLL_M2 1
50
51/* Core PLL Fdll = 1 GHZ, */
52#define COREPLL_M 1000
53#define COREPLL_N (OSC-1)
54
55#define COREPLL_M4 10 /* CORE_CLKOUTM4 = 200 MHZ */
56#define COREPLL_M5 8 /* CORE_CLKOUTM5 = 250 MHZ */
57#define COREPLL_M6 4 /* CORE_CLKOUTM6 = 500 MHZ */
58
59/*
60 * USB PHY clock is 960 MHZ. Since, this comes directly from Fdll, Fdll
61 * frequency needs to be set to 960 MHZ. Hence,
62 * For clkout = 192 MHZ, Fdll = 960 MHZ, divider values are given below
63 */
64#define PERPLL_M 960
65#define PERPLL_N (OSC-1)
66#define PERPLL_M2 5
67
68/* DDR Freq is 266 MHZ for now */
69/* Set Fdll = 400 MHZ , Fdll = M * 2 * CLKINP/ N + 1; clkout = Fdll /(2 * M2) */
70#define DDRPLL_M 266
71#define DDRPLL_N (OSC-1)
72#define DDRPLL_M2 1
73
Chandan Nath4ba33452011-10-14 02:58:23 +000074const struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
75const struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP;
76const struct cm_dpll *cmdpll = (struct cm_dpll *)CM_DPLL;
Vaibhav Hiremath2d7da5f2012-03-08 17:15:47 +053077const struct cm_rtc *cmrtc = (struct cm_rtc *)CM_RTC;
Chandan Nath4ba33452011-10-14 02:58:23 +000078
79static void enable_interface_clocks(void)
80{
81 /* Enable all the Interconnect Modules */
82 writel(PRCM_MOD_EN, &cmper->l3clkctrl);
83 while (readl(&cmper->l3clkctrl) != PRCM_MOD_EN)
84 ;
85
86 writel(PRCM_MOD_EN, &cmper->l4lsclkctrl);
87 while (readl(&cmper->l4lsclkctrl) != PRCM_MOD_EN)
88 ;
89
90 writel(PRCM_MOD_EN, &cmper->l4fwclkctrl);
91 while (readl(&cmper->l4fwclkctrl) != PRCM_MOD_EN)
92 ;
93
94 writel(PRCM_MOD_EN, &cmwkup->wkl4wkclkctrl);
95 while (readl(&cmwkup->wkl4wkclkctrl) != PRCM_MOD_EN)
96 ;
97
98 writel(PRCM_MOD_EN, &cmper->l3instrclkctrl);
99 while (readl(&cmper->l3instrclkctrl) != PRCM_MOD_EN)
100 ;
101
102 writel(PRCM_MOD_EN, &cmper->l4hsclkctrl);
103 while (readl(&cmper->l4hsclkctrl) != PRCM_MOD_EN)
104 ;
Tom Rinif8bf6b22012-07-31 07:22:47 -0700105
106 writel(PRCM_MOD_EN, &cmwkup->wkgpio0clkctrl);
107 while (readl(&cmwkup->wkgpio0clkctrl) != PRCM_MOD_EN)
108 ;
Chandan Nath4ba33452011-10-14 02:58:23 +0000109}
110
111/*
112 * Force power domain wake up transition
113 * Ensure that the corresponding interface clock is active before
114 * using the peripheral
115 */
116static void power_domain_wkup_transition(void)
117{
118 writel(PRCM_FORCE_WAKEUP, &cmper->l3clkstctrl);
119 writel(PRCM_FORCE_WAKEUP, &cmper->l4lsclkstctrl);
120 writel(PRCM_FORCE_WAKEUP, &cmwkup->wkclkstctrl);
121 writel(PRCM_FORCE_WAKEUP, &cmper->l4fwclkstctrl);
122 writel(PRCM_FORCE_WAKEUP, &cmper->l3sclkstctrl);
123}
124
125/*
126 * Enable the peripheral clock for required peripherals
127 */
128static void enable_per_clocks(void)
129{
130 /* Enable the control module though RBL would have done it*/
131 writel(PRCM_MOD_EN, &cmwkup->wkctrlclkctrl);
132 while (readl(&cmwkup->wkctrlclkctrl) != PRCM_MOD_EN)
133 ;
134
135 /* Enable the module clock */
136 writel(PRCM_MOD_EN, &cmper->timer2clkctrl);
137 while (readl(&cmper->timer2clkctrl) != PRCM_MOD_EN)
138 ;
139
Chandan Nath5b5c2122012-01-09 20:38:56 +0000140 /* Select the Master osc 24 MHZ as Timer2 clock source */
141 writel(0x1, &cmdpll->clktimer2clk);
142
Chandan Nath4ba33452011-10-14 02:58:23 +0000143 /* UART0 */
144 writel(PRCM_MOD_EN, &cmwkup->wkup_uart0ctrl);
145 while (readl(&cmwkup->wkup_uart0ctrl) != PRCM_MOD_EN)
146 ;
Chandan Nathd6e97f82012-01-09 20:38:58 +0000147
Andrew Bradfordcca45e72012-10-25 08:21:29 -0400148 /* UART1 */
149#ifdef CONFIG_SERIAL2
150 writel(PRCM_MOD_EN, &cmper->uart1clkctrl);
151 while (readl(&cmper->uart1clkctrl) != PRCM_MOD_EN)
152 ;
153#endif /* CONFIG_SERIAL2 */
154
155 /* UART2 */
156#ifdef CONFIG_SERIAL3
157 writel(PRCM_MOD_EN, &cmper->uart2clkctrl);
158 while (readl(&cmper->uart2clkctrl) != PRCM_MOD_EN)
159 ;
160#endif /* CONFIG_SERIAL3 */
161
162 /* UART3 */
163#ifdef CONFIG_SERIAL4
164 writel(PRCM_MOD_EN, &cmper->uart3clkctrl);
165 while (readl(&cmper->uart3clkctrl) != PRCM_MOD_EN)
166 ;
167#endif /* CONFIG_SERIAL4 */
168
169 /* UART4 */
170#ifdef CONFIG_SERIAL5
171 writel(PRCM_MOD_EN, &cmper->uart4clkctrl);
172 while (readl(&cmper->uart4clkctrl) != PRCM_MOD_EN)
173 ;
174#endif /* CONFIG_SERIAL5 */
175
176 /* UART5 */
177#ifdef CONFIG_SERIAL6
178 writel(PRCM_MOD_EN, &cmper->uart5clkctrl);
179 while (readl(&cmper->uart5clkctrl) != PRCM_MOD_EN)
180 ;
181#endif /* CONFIG_SERIAL6 */
182
Ilya Yanok2ebbb862012-11-06 13:06:30 +0000183 /* GPMC */
184 writel(PRCM_MOD_EN, &cmper->gpmcclkctrl);
185 while (readl(&cmper->gpmcclkctrl) != PRCM_MOD_EN)
186 ;
187
Mansoor Ahamed59e38b42012-11-06 13:06:32 +0000188 /* ELM */
189 writel(PRCM_MOD_EN, &cmper->elmclkctrl);
190 while (readl(&cmper->elmclkctrl) != PRCM_MOD_EN)
191 ;
192
Chandan Nathd6e97f82012-01-09 20:38:58 +0000193 /* MMC0*/
194 writel(PRCM_MOD_EN, &cmper->mmc0clkctrl);
195 while (readl(&cmper->mmc0clkctrl) != PRCM_MOD_EN)
196 ;
Patil, Rachna5f70c512012-01-22 23:47:01 +0000197
198 /* i2c0 */
199 writel(PRCM_MOD_EN, &cmwkup->wkup_i2c0ctrl);
200 while (readl(&cmwkup->wkup_i2c0ctrl) != PRCM_MOD_EN)
201 ;
Steve Sakoman6229e332012-06-04 05:35:34 +0000202
203 /* gpio1 module */
204 writel(PRCM_MOD_EN, &cmper->gpio1clkctrl);
205 while (readl(&cmper->gpio1clkctrl) != PRCM_MOD_EN)
206 ;
207
208 /* gpio2 module */
209 writel(PRCM_MOD_EN, &cmper->gpio2clkctrl);
210 while (readl(&cmper->gpio2clkctrl) != PRCM_MOD_EN)
211 ;
212
213 /* gpio3 module */
214 writel(PRCM_MOD_EN, &cmper->gpio3clkctrl);
215 while (readl(&cmper->gpio3clkctrl) != PRCM_MOD_EN)
216 ;
Steve Sakoman695b1fe2012-06-22 07:45:57 +0000217
218 /* i2c1 */
219 writel(PRCM_MOD_EN, &cmper->i2c1clkctrl);
220 while (readl(&cmper->i2c1clkctrl) != PRCM_MOD_EN)
221 ;
Chandan Nath2015c382012-07-24 12:22:17 +0000222
223 /* Ethernet */
224 writel(PRCM_MOD_EN, &cmper->cpgmac0clkctrl);
225 while ((readl(&cmper->cpgmac0clkctrl) & CPGMAC0_IDLE) != PRCM_FUNCTL)
226 ;
Tom Rini470e2a22012-08-08 14:29:51 -0700227
228 /* spi0 */
229 writel(PRCM_MOD_EN, &cmper->spi0clkctrl);
230 while (readl(&cmper->spi0clkctrl) != PRCM_MOD_EN)
231 ;
Vaibhav Hiremath2d7da5f2012-03-08 17:15:47 +0530232
233 /* RTC */
234 writel(PRCM_MOD_EN, &cmrtc->rtcclkctrl);
235 while (readl(&cmrtc->rtcclkctrl) != PRCM_MOD_EN)
236 ;
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000237
238 /* MUSB */
239 writel(PRCM_MOD_EN, &cmper->usb0clkctrl);
240 while (readl(&cmper->usb0clkctrl) != PRCM_MOD_EN)
241 ;
Chandan Nath4ba33452011-10-14 02:58:23 +0000242}
243
244static void mpu_pll_config(void)
245{
246 u32 clkmode, clksel, div_m2;
247
248 clkmode = readl(&cmwkup->clkmoddpllmpu);
249 clksel = readl(&cmwkup->clkseldpllmpu);
250 div_m2 = readl(&cmwkup->divm2dpllmpu);
251
252 /* Set the PLL to bypass Mode */
253 writel(PLL_BYPASS_MODE, &cmwkup->clkmoddpllmpu);
254 while (readl(&cmwkup->idlestdpllmpu) != ST_MN_BYPASS)
255 ;
256
257 clksel = clksel & (~CLK_SEL_MASK);
258 clksel = clksel | ((MPUPLL_M << CLK_SEL_SHIFT) | MPUPLL_N);
259 writel(clksel, &cmwkup->clkseldpllmpu);
260
261 div_m2 = div_m2 & ~CLK_DIV_MASK;
262 div_m2 = div_m2 | MPUPLL_M2;
263 writel(div_m2, &cmwkup->divm2dpllmpu);
264
265 clkmode = clkmode | CLK_MODE_SEL;
266 writel(clkmode, &cmwkup->clkmoddpllmpu);
267
268 while (readl(&cmwkup->idlestdpllmpu) != ST_DPLL_CLK)
269 ;
270}
271
272static void core_pll_config(void)
273{
274 u32 clkmode, clksel, div_m4, div_m5, div_m6;
275
276 clkmode = readl(&cmwkup->clkmoddpllcore);
277 clksel = readl(&cmwkup->clkseldpllcore);
278 div_m4 = readl(&cmwkup->divm4dpllcore);
279 div_m5 = readl(&cmwkup->divm5dpllcore);
280 div_m6 = readl(&cmwkup->divm6dpllcore);
281
282 /* Set the PLL to bypass Mode */
283 writel(PLL_BYPASS_MODE, &cmwkup->clkmoddpllcore);
284
285 while (readl(&cmwkup->idlestdpllcore) != ST_MN_BYPASS)
286 ;
287
288 clksel = clksel & (~CLK_SEL_MASK);
289 clksel = clksel | ((COREPLL_M << CLK_SEL_SHIFT) | COREPLL_N);
290 writel(clksel, &cmwkup->clkseldpllcore);
291
292 div_m4 = div_m4 & ~CLK_DIV_MASK;
293 div_m4 = div_m4 | COREPLL_M4;
294 writel(div_m4, &cmwkup->divm4dpllcore);
295
296 div_m5 = div_m5 & ~CLK_DIV_MASK;
297 div_m5 = div_m5 | COREPLL_M5;
298 writel(div_m5, &cmwkup->divm5dpllcore);
299
300 div_m6 = div_m6 & ~CLK_DIV_MASK;
301 div_m6 = div_m6 | COREPLL_M6;
302 writel(div_m6, &cmwkup->divm6dpllcore);
303
304 clkmode = clkmode | CLK_MODE_SEL;
305 writel(clkmode, &cmwkup->clkmoddpllcore);
306
307 while (readl(&cmwkup->idlestdpllcore) != ST_DPLL_CLK)
308 ;
309}
310
311static void per_pll_config(void)
312{
313 u32 clkmode, clksel, div_m2;
314
315 clkmode = readl(&cmwkup->clkmoddpllper);
316 clksel = readl(&cmwkup->clkseldpllper);
317 div_m2 = readl(&cmwkup->divm2dpllper);
318
319 /* Set the PLL to bypass Mode */
320 writel(PLL_BYPASS_MODE, &cmwkup->clkmoddpllper);
321
322 while (readl(&cmwkup->idlestdpllper) != ST_MN_BYPASS)
323 ;
324
325 clksel = clksel & (~CLK_SEL_MASK);
326 clksel = clksel | ((PERPLL_M << CLK_SEL_SHIFT) | PERPLL_N);
327 writel(clksel, &cmwkup->clkseldpllper);
328
329 div_m2 = div_m2 & ~CLK_DIV2_MASK;
330 div_m2 = div_m2 | PERPLL_M2;
331 writel(div_m2, &cmwkup->divm2dpllper);
332
333 clkmode = clkmode | CLK_MODE_SEL;
334 writel(clkmode, &cmwkup->clkmoddpllper);
335
336 while (readl(&cmwkup->idlestdpllper) != ST_DPLL_CLK)
337 ;
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000338
339 writel(DPLL_CLKDCOLDO_GATE_CTRL, &cmwkup->clkdcoldodpllper);
Chandan Nath4ba33452011-10-14 02:58:23 +0000340}
341
Tom Rini034aba72012-07-03 09:20:06 -0700342void ddr_pll_config(unsigned int ddrpll_m)
Chandan Nath4ba33452011-10-14 02:58:23 +0000343{
344 u32 clkmode, clksel, div_m2;
345
346 clkmode = readl(&cmwkup->clkmoddpllddr);
347 clksel = readl(&cmwkup->clkseldpllddr);
348 div_m2 = readl(&cmwkup->divm2dpllddr);
349
350 /* Set the PLL to bypass Mode */
351 clkmode = (clkmode & CLK_MODE_MASK) | PLL_BYPASS_MODE;
352 writel(clkmode, &cmwkup->clkmoddpllddr);
353
354 /* Wait till bypass mode is enabled */
355 while ((readl(&cmwkup->idlestdpllddr) & ST_MN_BYPASS)
356 != ST_MN_BYPASS)
357 ;
358
359 clksel = clksel & (~CLK_SEL_MASK);
Tom Rini034aba72012-07-03 09:20:06 -0700360 clksel = clksel | ((ddrpll_m << CLK_SEL_SHIFT) | DDRPLL_N);
Chandan Nath4ba33452011-10-14 02:58:23 +0000361 writel(clksel, &cmwkup->clkseldpllddr);
362
363 div_m2 = div_m2 & CLK_DIV_SEL;
364 div_m2 = div_m2 | DDRPLL_M2;
365 writel(div_m2, &cmwkup->divm2dpllddr);
366
367 clkmode = (clkmode & CLK_MODE_MASK) | CLK_MODE_SEL;
368 writel(clkmode, &cmwkup->clkmoddpllddr);
369
370 /* Wait till dpll is locked */
371 while ((readl(&cmwkup->idlestdpllddr) & ST_DPLL_CLK) != ST_DPLL_CLK)
372 ;
373}
374
375void enable_emif_clocks(void)
376{
377 /* Enable the EMIF_FW Functional clock */
378 writel(PRCM_MOD_EN, &cmper->emiffwclkctrl);
379 /* Enable EMIF0 Clock */
380 writel(PRCM_MOD_EN, &cmper->emifclkctrl);
Chandan Nath4ba33452011-10-14 02:58:23 +0000381 /* Poll if module is functional */
382 while ((readl(&cmper->emifclkctrl)) != PRCM_MOD_EN)
383 ;
384}
385
386/*
387 * Configure the PLL/PRCM for necessary peripherals
388 */
389void pll_init()
390{
391 mpu_pll_config();
392 core_pll_config();
393 per_pll_config();
Chandan Nath4ba33452011-10-14 02:58:23 +0000394
395 /* Enable the required interconnect clocks */
396 enable_interface_clocks();
397
398 /* Power domain wake up transition */
399 power_domain_wkup_transition();
400
401 /* Enable the required peripherals */
402 enable_per_clocks();
403}