1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments, <www.ti.com>
7 * Manikandan Pillai <mani.pillai@ti.com>
9 * Derived from Beagle Board and OMAP3 SDP code by
10 * Richard Woodruff <r-woodruff2@ti.com>
11 * Syed Mohammed Khasim <khasim@ti.com>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/clocks_omap3.h>
18 #include <asm/arch/mem.h>
19 #include <asm/arch/sys_proto.h>
20 #include <environment.h>
23 /******************************************************************************
24 * get_sys_clk_speed() - determine reference oscillator speed
25 * based on known 32kHz clock and gptimer.
26 *****************************************************************************/
27 u32 get_osc_clk_speed(void)
29 u32 start, cstart, cend, cdiff, cdiv, val;
30 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
31 struct prm *prm_base = (struct prm *)PRM_BASE;
32 struct gptimer *gpt1_base = (struct gptimer *)OMAP34XX_GPT1;
33 struct s32ktimer *s32k_base = (struct s32ktimer *)SYNC_32KTIMER_BASE;
35 val = readl(&prm_base->clksrc_ctrl);
37 if (val & SYSCLKDIV_2)
43 val = readl(&prcm_base->clksel_wkup) | CLKSEL_GPT1;
45 /* select sys_clk for GPT1 */
46 writel(val, &prcm_base->clksel_wkup);
48 /* Enable I and F Clocks for GPT1 */
49 val = readl(&prcm_base->iclken_wkup) | EN_GPT1 | EN_32KSYNC;
50 writel(val, &prcm_base->iclken_wkup);
52 val = readl(&prcm_base->fclken_wkup) | EN_GPT1;
53 writel(val, &prcm_base->fclken_wkup);
55 writel(0, &gpt1_base->tldr); /* start counting at 0 */
56 writel(GPT_EN, &gpt1_base->tclr); /* enable clock */
58 /* enable 32kHz source, determine sys_clk via gauging */
60 /* start time in 20 cycles */
61 start = 20 + readl(&s32k_base->s32k_cr);
63 /* dead loop till start time */
64 while (readl(&s32k_base->s32k_cr) < start);
66 /* get start sys_clk count */
67 cstart = readl(&gpt1_base->tcrr);
69 /* wait for 40 cycles */
70 while (readl(&s32k_base->s32k_cr) < (start + 20)) ;
71 cend = readl(&gpt1_base->tcrr); /* get end sys_clk count */
72 cdiff = cend - cstart; /* get elapsed ticks */
75 /* based on number of ticks assign speed */
78 else if (cdiff > 15200)
80 else if (cdiff > 13000)
82 else if (cdiff > 9000)
84 else if (cdiff > 7600)
90 /******************************************************************************
91 * get_sys_clkin_sel() - returns the sys_clkin_sel field value based on
92 * input oscillator clock frequency.
93 *****************************************************************************/
94 void get_sys_clkin_sel(u32 osc_clk, u32 *sys_clkin_sel)
116 * OMAP34XX/35XX specific functions
119 static void dpll3_init_34xx(u32 sil_index, u32 clk_index)
121 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
122 dpll_param *ptr = (dpll_param *) get_core_dpll_param();
123 void (*f_lock_pll) (u32, u32, u32, u32);
124 int xip_safe, p0, p1, p2, p3;
126 xip_safe = is_running_in_sram();
128 /* Moving to the right sysclk and ES rev base */
129 ptr = ptr + (3 * clk_index) + sil_index;
135 clrsetbits_le32(&prcm_base->clken_pll,
136 0x00000007, PLL_FAST_RELOCK_BYPASS);
137 wait_on_value(ST_CORE_CLK, 0, &prcm_base->idlest_ckgen,
141 * For OMAP3 ES1.0 Errata 1.50, default value directly doesn't
142 * work. write another value and then default value.
145 /* CM_CLKSEL1_EMU[DIV_DPLL3] */
146 clrsetbits_le32(&prcm_base->clksel1_emu,
147 0x001F0000, (CORE_M3X2 + 1) << 16) ;
148 clrsetbits_le32(&prcm_base->clksel1_emu,
149 0x001F0000, CORE_M3X2 << 16);
151 /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
152 clrsetbits_le32(&prcm_base->clksel1_pll,
153 0xF8000000, ptr->m2 << 27);
155 /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
156 clrsetbits_le32(&prcm_base->clksel1_pll,
157 0x07FF0000, ptr->m << 16);
159 /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
160 clrsetbits_le32(&prcm_base->clksel1_pll,
161 0x00007F00, ptr->n << 8);
163 /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
164 clrbits_le32(&prcm_base->clksel1_pll, 0x00000040);
167 clrsetbits_le32(&prcm_base->clksel_core,
168 0x00000F00, CORE_SSI_DIV << 8);
170 clrsetbits_le32(&prcm_base->clksel_core,
171 0x00000030, CORE_FUSB_DIV << 4);
173 clrsetbits_le32(&prcm_base->clksel_core,
174 0x0000000C, CORE_L4_DIV << 2);
176 clrsetbits_le32(&prcm_base->clksel_core,
177 0x00000003, CORE_L3_DIV);
179 clrsetbits_le32(&prcm_base->clksel_gfx,
180 0x00000007, GFX_DIV);
182 clrsetbits_le32(&prcm_base->clksel_wkup,
183 0x00000006, WKUP_RSM << 1);
184 /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
185 clrsetbits_le32(&prcm_base->clken_pll,
186 0x000000F0, ptr->fsel << 4);
188 clrsetbits_le32(&prcm_base->clken_pll,
189 0x00000007, PLL_LOCK);
191 wait_on_value(ST_CORE_CLK, 1, &prcm_base->idlest_ckgen,
193 } else if (is_running_in_flash()) {
195 * if running from flash, jump to small relocated code
198 f_lock_pll = (void *) (SRAM_CLK_CODE);
200 p0 = readl(&prcm_base->clken_pll);
201 clrsetbits_le32(&p0, 0x00000007, PLL_FAST_RELOCK_BYPASS);
202 /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
203 clrsetbits_le32(&p0, 0x000000F0, ptr->fsel << 4);
205 p1 = readl(&prcm_base->clksel1_pll);
206 /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
207 clrsetbits_le32(&p1, 0xF8000000, ptr->m2 << 27);
208 /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
209 clrsetbits_le32(&p1, 0x07FF0000, ptr->m << 16);
210 /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
211 clrsetbits_le32(&p1, 0x00007F00, ptr->n << 8);
212 /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
213 clrbits_le32(&p1, 0x00000040);
215 p2 = readl(&prcm_base->clksel_core);
217 clrsetbits_le32(&p2, 0x00000F00, CORE_SSI_DIV << 8);
219 clrsetbits_le32(&p2, 0x00000030, CORE_FUSB_DIV << 4);
221 clrsetbits_le32(&p2, 0x0000000C, CORE_L4_DIV << 2);
223 clrsetbits_le32(&p2, 0x00000003, CORE_L3_DIV);
225 p3 = (u32)&prcm_base->idlest_ckgen;
227 (*f_lock_pll) (p0, p1, p2, p3);
231 static void dpll4_init_34xx(u32 sil_index, u32 clk_index)
233 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
234 dpll_param *ptr = (dpll_param *) get_per_dpll_param();
236 /* Moving it to the right sysclk base */
237 ptr = ptr + clk_index;
239 /* EN_PERIPH_DPLL: CM_CLKEN_PLL[16:18] */
240 clrsetbits_le32(&prcm_base->clken_pll, 0x00070000, PLL_STOP << 16);
241 wait_on_value(ST_PERIPH_CLK, 0, &prcm_base->idlest_ckgen, LDELAY);
244 * Errata 1.50 Workaround for OMAP3 ES1.0 only
245 * If using default divisors, write default divisor + 1
246 * and then the actual divisor value
249 clrsetbits_le32(&prcm_base->clksel1_emu,
250 0x1F000000, (PER_M6X2 + 1) << 24);
251 clrsetbits_le32(&prcm_base->clksel1_emu,
252 0x1F000000, PER_M6X2 << 24);
254 clrsetbits_le32(&prcm_base->clksel_cam, 0x0000001F, (PER_M5X2 + 1));
255 clrsetbits_le32(&prcm_base->clksel_cam, 0x0000001F, PER_M5X2);
257 clrsetbits_le32(&prcm_base->clksel_dss, 0x0000001F, (PER_M4X2 + 1));
258 clrsetbits_le32(&prcm_base->clksel_dss, 0x0000001F, PER_M4X2);
260 clrsetbits_le32(&prcm_base->clksel_dss,
261 0x00001F00, (PER_M3X2 + 1) << 8);
262 clrsetbits_le32(&prcm_base->clksel_dss,
263 0x00001F00, PER_M3X2 << 8);
264 /* M2 (DIV_96M): CM_CLKSEL3_PLL[0:4] */
265 clrsetbits_le32(&prcm_base->clksel3_pll, 0x0000001F, (ptr->m2 + 1));
266 clrsetbits_le32(&prcm_base->clksel3_pll, 0x0000001F, ptr->m2);
269 /* M (PERIPH_DPLL_MULT): CM_CLKSEL2_PLL[8:18] */
270 clrsetbits_le32(&prcm_base->clksel2_pll,
271 0x0007FF00, ptr->m << 8);
273 /* N (PERIPH_DPLL_DIV): CM_CLKSEL2_PLL[0:6] */
274 clrsetbits_le32(&prcm_base->clksel2_pll, 0x0000007F, ptr->n);
276 /* FREQSEL (PERIPH_DPLL_FREQSEL): CM_CLKEN_PLL[20:23] */
277 clrsetbits_le32(&prcm_base->clken_pll, 0x00F00000, ptr->fsel << 20);
279 /* LOCK MODE (EN_PERIPH_DPLL): CM_CLKEN_PLL[16:18] */
280 clrsetbits_le32(&prcm_base->clken_pll, 0x00070000, PLL_LOCK << 16);
281 wait_on_value(ST_PERIPH_CLK, 2, &prcm_base->idlest_ckgen, LDELAY);
284 static void dpll5_init_34xx(u32 sil_index, u32 clk_index)
286 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
287 dpll_param *ptr = (dpll_param *) get_per2_dpll_param();
289 /* Moving it to the right sysclk base */
290 ptr = ptr + clk_index;
292 /* PER2 DPLL (DPLL5) */
293 clrsetbits_le32(&prcm_base->clken2_pll, 0x00000007, PLL_STOP);
294 wait_on_value(1, 0, &prcm_base->idlest2_ckgen, LDELAY);
295 /* set M2 (usbtll_fck) */
296 clrsetbits_le32(&prcm_base->clksel5_pll, 0x0000001F, ptr->m2);
297 /* set m (11-bit multiplier) */
298 clrsetbits_le32(&prcm_base->clksel4_pll, 0x0007FF00, ptr->m << 8);
299 /* set n (7-bit divider)*/
300 clrsetbits_le32(&prcm_base->clksel4_pll, 0x0000007F, ptr->n);
302 clrsetbits_le32(&prcm_base->clken_pll, 0x000000F0, ptr->fsel << 4);
304 clrsetbits_le32(&prcm_base->clken2_pll, 0x00000007, PLL_LOCK);
305 wait_on_value(1, 1, &prcm_base->idlest2_ckgen, LDELAY);
308 static void mpu_init_34xx(u32 sil_index, u32 clk_index)
310 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
311 dpll_param *ptr = (dpll_param *) get_mpu_dpll_param();
313 /* Moving to the right sysclk and ES rev base */
314 ptr = ptr + (3 * clk_index) + sil_index;
316 /* MPU DPLL (unlocked already) */
318 /* M2 (MPU_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_MPU[0:4] */
319 clrsetbits_le32(&prcm_base->clksel2_pll_mpu,
320 0x0000001F, ptr->m2);
322 /* M (MPU_DPLL_MULT) : CM_CLKSEL2_PLL_MPU[8:18] */
323 clrsetbits_le32(&prcm_base->clksel1_pll_mpu,
324 0x0007FF00, ptr->m << 8);
326 /* N (MPU_DPLL_DIV) : CM_CLKSEL2_PLL_MPU[0:6] */
327 clrsetbits_le32(&prcm_base->clksel1_pll_mpu,
330 /* FREQSEL (MPU_DPLL_FREQSEL) : CM_CLKEN_PLL_MPU[4:7] */
331 clrsetbits_le32(&prcm_base->clken_pll_mpu,
332 0x000000F0, ptr->fsel << 4);
335 static void iva_init_34xx(u32 sil_index, u32 clk_index)
337 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
338 dpll_param *ptr = (dpll_param *) get_iva_dpll_param();
340 /* Moving to the right sysclk and ES rev base */
341 ptr = ptr + (3 * clk_index) + sil_index;
344 /* EN_IVA2_DPLL : CM_CLKEN_PLL_IVA2[0:2] */
345 clrsetbits_le32(&prcm_base->clken_pll_iva2,
346 0x00000007, PLL_STOP);
347 wait_on_value(ST_IVA2_CLK, 0, &prcm_base->idlest_pll_iva2, LDELAY);
349 /* M2 (IVA2_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_IVA2[0:4] */
350 clrsetbits_le32(&prcm_base->clksel2_pll_iva2,
351 0x0000001F, ptr->m2);
353 /* M (IVA2_DPLL_MULT) : CM_CLKSEL1_PLL_IVA2[8:18] */
354 clrsetbits_le32(&prcm_base->clksel1_pll_iva2,
355 0x0007FF00, ptr->m << 8);
357 /* N (IVA2_DPLL_DIV) : CM_CLKSEL1_PLL_IVA2[0:6] */
358 clrsetbits_le32(&prcm_base->clksel1_pll_iva2,
361 /* FREQSEL (IVA2_DPLL_FREQSEL) : CM_CLKEN_PLL_IVA2[4:7] */
362 clrsetbits_le32(&prcm_base->clken_pll_iva2,
363 0x000000F0, ptr->fsel << 4);
365 /* LOCK MODE (EN_IVA2_DPLL) : CM_CLKEN_PLL_IVA2[0:2] */
366 clrsetbits_le32(&prcm_base->clken_pll_iva2,
367 0x00000007, PLL_LOCK);
369 wait_on_value(ST_IVA2_CLK, 1, &prcm_base->idlest_pll_iva2, LDELAY);
373 * OMAP3630 specific functions
376 static void dpll3_init_36xx(u32 sil_index, u32 clk_index)
378 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
379 dpll_param *ptr = (dpll_param *) get_36x_core_dpll_param();
380 void (*f_lock_pll) (u32, u32, u32, u32);
381 int xip_safe, p0, p1, p2, p3;
383 xip_safe = is_running_in_sram();
385 /* Moving it to the right sysclk base */
391 /* Select relock bypass: CM_CLKEN_PLL[0:2] */
392 clrsetbits_le32(&prcm_base->clken_pll,
393 0x00000007, PLL_FAST_RELOCK_BYPASS);
394 wait_on_value(ST_CORE_CLK, 0, &prcm_base->idlest_ckgen,
397 /* CM_CLKSEL1_EMU[DIV_DPLL3] */
398 clrsetbits_le32(&prcm_base->clksel1_emu,
399 0x001F0000, CORE_M3X2 << 16);
401 /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
402 clrsetbits_le32(&prcm_base->clksel1_pll,
403 0xF8000000, ptr->m2 << 27);
405 /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
406 clrsetbits_le32(&prcm_base->clksel1_pll,
407 0x07FF0000, ptr->m << 16);
409 /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
410 clrsetbits_le32(&prcm_base->clksel1_pll,
411 0x00007F00, ptr->n << 8);
413 /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
414 clrbits_le32(&prcm_base->clksel1_pll, 0x00000040);
417 clrsetbits_le32(&prcm_base->clksel_core,
418 0x00000F00, CORE_SSI_DIV << 8);
420 clrsetbits_le32(&prcm_base->clksel_core,
421 0x00000030, CORE_FUSB_DIV << 4);
423 clrsetbits_le32(&prcm_base->clksel_core,
424 0x0000000C, CORE_L4_DIV << 2);
426 clrsetbits_le32(&prcm_base->clksel_core,
427 0x00000003, CORE_L3_DIV);
429 clrsetbits_le32(&prcm_base->clksel_gfx,
430 0x00000007, GFX_DIV_36X);
432 clrsetbits_le32(&prcm_base->clksel_wkup,
433 0x00000006, WKUP_RSM << 1);
434 /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
435 clrsetbits_le32(&prcm_base->clken_pll,
436 0x000000F0, ptr->fsel << 4);
438 clrsetbits_le32(&prcm_base->clken_pll,
439 0x00000007, PLL_LOCK);
441 wait_on_value(ST_CORE_CLK, 1, &prcm_base->idlest_ckgen,
443 } else if (is_running_in_flash()) {
445 * if running from flash, jump to small relocated code
448 f_lock_pll = (void *) (SRAM_CLK_CODE);
450 p0 = readl(&prcm_base->clken_pll);
451 clrsetbits_le32(&p0, 0x00000007, PLL_FAST_RELOCK_BYPASS);
452 /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
453 clrsetbits_le32(&p0, 0x000000F0, ptr->fsel << 4);
455 p1 = readl(&prcm_base->clksel1_pll);
456 /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
457 clrsetbits_le32(&p1, 0xF8000000, ptr->m2 << 27);
458 /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
459 clrsetbits_le32(&p1, 0x07FF0000, ptr->m << 16);
460 /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
461 clrsetbits_le32(&p1, 0x00007F00, ptr->n << 8);
462 /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
463 clrbits_le32(&p1, 0x00000040);
465 p2 = readl(&prcm_base->clksel_core);
467 clrsetbits_le32(&p2, 0x00000F00, CORE_SSI_DIV << 8);
469 clrsetbits_le32(&p2, 0x00000030, CORE_FUSB_DIV << 4);
471 clrsetbits_le32(&p2, 0x0000000C, CORE_L4_DIV << 2);
473 clrsetbits_le32(&p2, 0x00000003, CORE_L3_DIV);
475 p3 = (u32)&prcm_base->idlest_ckgen;
477 (*f_lock_pll) (p0, p1, p2, p3);
481 static void dpll4_init_36xx(u32 sil_index, u32 clk_index)
483 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
484 struct dpll_per_36x_param *ptr;
486 ptr = (struct dpll_per_36x_param *)get_36x_per_dpll_param();
488 /* Moving it to the right sysclk base */
491 /* EN_PERIPH_DPLL: CM_CLKEN_PLL[16:18] */
492 clrsetbits_le32(&prcm_base->clken_pll, 0x00070000, PLL_STOP << 16);
493 wait_on_value(ST_PERIPH_CLK, 0, &prcm_base->idlest_ckgen, LDELAY);
495 /* M6 (DIV_DPLL4): CM_CLKSEL1_EMU[24:29] */
496 clrsetbits_le32(&prcm_base->clksel1_emu, 0x3F000000, ptr->m6 << 24);
498 /* M5 (CLKSEL_CAM): CM_CLKSEL1_EMU[0:5] */
499 clrsetbits_le32(&prcm_base->clksel_cam, 0x0000003F, ptr->m5);
501 /* M4 (CLKSEL_DSS1): CM_CLKSEL_DSS[0:5] */
502 clrsetbits_le32(&prcm_base->clksel_dss, 0x0000003F, ptr->m4);
504 /* M3 (CLKSEL_DSS1): CM_CLKSEL_DSS[8:13] */
505 clrsetbits_le32(&prcm_base->clksel_dss, 0x00003F00, ptr->m3 << 8);
507 /* M2 (DIV_96M): CM_CLKSEL3_PLL[0:4] */
508 clrsetbits_le32(&prcm_base->clksel3_pll, 0x0000001F, ptr->m2);
510 /* M (PERIPH_DPLL_MULT): CM_CLKSEL2_PLL[8:19] */
511 clrsetbits_le32(&prcm_base->clksel2_pll, 0x000FFF00, ptr->m << 8);
513 /* N (PERIPH_DPLL_DIV): CM_CLKSEL2_PLL[0:6] */
514 clrsetbits_le32(&prcm_base->clksel2_pll, 0x0000007F, ptr->n);
516 /* M2DIV (CLKSEL_96M): CM_CLKSEL_CORE[12:13] */
517 clrsetbits_le32(&prcm_base->clksel_core, 0x00003000, ptr->m2div << 12);
519 /* LOCK MODE (EN_PERIPH_DPLL): CM_CLKEN_PLL[16:18] */
520 clrsetbits_le32(&prcm_base->clken_pll, 0x00070000, PLL_LOCK << 16);
521 wait_on_value(ST_PERIPH_CLK, 2, &prcm_base->idlest_ckgen, LDELAY);
524 static void dpll5_init_36xx(u32 sil_index, u32 clk_index)
526 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
527 dpll_param *ptr = (dpll_param *) get_36x_per2_dpll_param();
529 /* Moving it to the right sysclk base */
530 ptr = ptr + clk_index;
532 /* PER2 DPLL (DPLL5) */
533 clrsetbits_le32(&prcm_base->clken2_pll, 0x00000007, PLL_STOP);
534 wait_on_value(1, 0, &prcm_base->idlest2_ckgen, LDELAY);
535 /* set M2 (usbtll_fck) */
536 clrsetbits_le32(&prcm_base->clksel5_pll, 0x0000001F, ptr->m2);
537 /* set m (11-bit multiplier) */
538 clrsetbits_le32(&prcm_base->clksel4_pll, 0x0007FF00, ptr->m << 8);
539 /* set n (7-bit divider)*/
540 clrsetbits_le32(&prcm_base->clksel4_pll, 0x0000007F, ptr->n);
542 clrsetbits_le32(&prcm_base->clken2_pll, 0x00000007, PLL_LOCK);
543 wait_on_value(1, 1, &prcm_base->idlest2_ckgen, LDELAY);
546 static void mpu_init_36xx(u32 sil_index, u32 clk_index)
548 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
549 dpll_param *ptr = (dpll_param *) get_36x_mpu_dpll_param();
551 /* Moving to the right sysclk */
554 /* MPU DPLL (unlocked already */
556 /* M2 (MPU_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_MPU[0:4] */
557 clrsetbits_le32(&prcm_base->clksel2_pll_mpu, 0x0000001F, ptr->m2);
559 /* M (MPU_DPLL_MULT) : CM_CLKSEL2_PLL_MPU[8:18] */
560 clrsetbits_le32(&prcm_base->clksel1_pll_mpu, 0x0007FF00, ptr->m << 8);
562 /* N (MPU_DPLL_DIV) : CM_CLKSEL2_PLL_MPU[0:6] */
563 clrsetbits_le32(&prcm_base->clksel1_pll_mpu, 0x0000007F, ptr->n);
566 static void iva_init_36xx(u32 sil_index, u32 clk_index)
568 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
569 dpll_param *ptr = (dpll_param *)get_36x_iva_dpll_param();
571 /* Moving to the right sysclk */
575 /* EN_IVA2_DPLL : CM_CLKEN_PLL_IVA2[0:2] */
576 clrsetbits_le32(&prcm_base->clken_pll_iva2, 0x00000007, PLL_STOP);
577 wait_on_value(ST_IVA2_CLK, 0, &prcm_base->idlest_pll_iva2, LDELAY);
579 /* M2 (IVA2_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_IVA2[0:4] */
580 clrsetbits_le32(&prcm_base->clksel2_pll_iva2, 0x0000001F, ptr->m2);
582 /* M (IVA2_DPLL_MULT) : CM_CLKSEL1_PLL_IVA2[8:18] */
583 clrsetbits_le32(&prcm_base->clksel1_pll_iva2, 0x0007FF00, ptr->m << 8);
585 /* N (IVA2_DPLL_DIV) : CM_CLKSEL1_PLL_IVA2[0:6] */
586 clrsetbits_le32(&prcm_base->clksel1_pll_iva2, 0x0000007F, ptr->n);
588 /* LOCK (MODE (EN_IVA2_DPLL) : CM_CLKEN_PLL_IVA2[0:2] */
589 clrsetbits_le32(&prcm_base->clken_pll_iva2, 0x00000007, PLL_LOCK);
591 wait_on_value(ST_IVA2_CLK, 1, &prcm_base->idlest_pll_iva2, LDELAY);
594 /******************************************************************************
595 * prcm_init() - inits clocks for PRCM as defined in clocks.h
596 * called from SRAM, or Flash (using temp SRAM stack).
597 *****************************************************************************/
600 u32 osc_clk = 0, sys_clkin_sel;
601 u32 clk_index, sil_index = 0;
602 struct prm *prm_base = (struct prm *)PRM_BASE;
603 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
606 * Gauge the input clock speed and find out the sys_clkin_sel
607 * value corresponding to the input clock.
609 osc_clk = get_osc_clk_speed();
610 get_sys_clkin_sel(osc_clk, &sys_clkin_sel);
612 /* set input crystal speed */
613 clrsetbits_le32(&prm_base->clksel, 0x00000007, sys_clkin_sel);
615 /* If the input clock is greater than 19.2M always divide/2 */
616 if (sys_clkin_sel > 2) {
617 /* input clock divider */
618 clrsetbits_le32(&prm_base->clksrc_ctrl, 0x000000C0, 2 << 6);
619 clk_index = sys_clkin_sel / 2;
621 /* input clock divider */
622 clrsetbits_le32(&prm_base->clksrc_ctrl, 0x000000C0, 1 << 6);
623 clk_index = sys_clkin_sel;
626 if (get_cpu_family() == CPU_OMAP36XX) {
628 * In warm reset conditions on OMAP36xx/AM/DM37xx
629 * the rom code incorrectly sets the DPLL4 clock
630 * input divider to /6.5. Section 3.5.3.3.3.2.1 of
631 * the AM/DM37x TRM explains that the /6.5 divider
632 * is used only when the input clock is 13MHz.
634 * If the part is in this cpu family *and* the input
635 * clock *is not* 13 MHz, then reset the DPLL4 clock
636 * input divider to /1 as it should never set to /6.5
639 if (sys_clkin_sel != 1) { /* 13 MHz */
640 /* Bit 8: DPLL4_CLKINP_DIV */
641 clrbits_le32(&prm_base->clksrc_ctrl, 0x00000100);
644 /* Unlock MPU DPLL (slows things down, and needed later) */
645 clrsetbits_le32(&prcm_base->clken_pll_mpu,
646 0x00000007, PLL_LOW_POWER_BYPASS);
647 wait_on_value(ST_MPU_CLK, 0, &prcm_base->idlest_pll_mpu,
650 dpll3_init_36xx(0, clk_index);
651 dpll4_init_36xx(0, clk_index);
652 dpll5_init_36xx(0, clk_index);
653 iva_init_36xx(0, clk_index);
654 mpu_init_36xx(0, clk_index);
656 /* Lock MPU DPLL to set frequency */
657 clrsetbits_le32(&prcm_base->clken_pll_mpu,
658 0x00000007, PLL_LOCK);
659 wait_on_value(ST_MPU_CLK, 1, &prcm_base->idlest_pll_mpu,
663 * The DPLL tables are defined according to sysclk value and
664 * silicon revision. The clk_index value will be used to get
665 * the values for that input sysclk from the DPLL param table
666 * and sil_index will get the values for that SysClk for the
667 * appropriate silicon rev.
669 if (((get_cpu_family() == CPU_OMAP34XX)
670 && (get_cpu_rev() >= CPU_3XX_ES20)) ||
671 (get_cpu_family() == CPU_AM35XX))
674 /* Unlock MPU DPLL (slows things down, and needed later) */
675 clrsetbits_le32(&prcm_base->clken_pll_mpu,
676 0x00000007, PLL_LOW_POWER_BYPASS);
677 wait_on_value(ST_MPU_CLK, 0, &prcm_base->idlest_pll_mpu,
680 dpll3_init_34xx(sil_index, clk_index);
681 dpll4_init_34xx(sil_index, clk_index);
682 dpll5_init_34xx(sil_index, clk_index);
683 if (get_cpu_family() != CPU_AM35XX)
684 iva_init_34xx(sil_index, clk_index);
686 mpu_init_34xx(sil_index, clk_index);
688 /* Lock MPU DPLL to set frequency */
689 clrsetbits_le32(&prcm_base->clken_pll_mpu,
690 0x00000007, PLL_LOCK);
691 wait_on_value(ST_MPU_CLK, 1, &prcm_base->idlest_pll_mpu,
695 /* Set up GPTimers to sys_clk source only */
696 setbits_le32(&prcm_base->clksel_per, 0x000000FF);
697 setbits_le32(&prcm_base->clksel_wkup, 1);
703 * Enable usb ehci uhh, tll clocks
705 void ehci_clocks_enable(void)
707 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
709 /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
710 setbits_le32(&prcm_base->iclken_usbhost, 1);
712 * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
713 * and USBHOST_120M_FCLK (USBHOST_FCLK2)
715 setbits_le32(&prcm_base->fclken_usbhost, 0x00000003);
716 /* Enable USBTTL_ICLK */
717 setbits_le32(&prcm_base->iclken3_core, 0x00000004);
718 /* Enable USBTTL_FCLK */
719 setbits_le32(&prcm_base->fclken3_core, 0x00000004);
722 /******************************************************************************
723 * peripheral_enable() - Enable the clks & power for perifs (GPT2, UART1,...)
724 *****************************************************************************/
725 void per_clocks_enable(void)
727 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
729 /* Enable GP2 timer. */
730 setbits_le32(&prcm_base->clksel_per, 0x01); /* GPT2 = sys clk */
731 setbits_le32(&prcm_base->iclken_per, 0x08); /* ICKen GPT2 */
732 setbits_le32(&prcm_base->fclken_per, 0x08); /* FCKen GPT2 */
734 /* Enable GP9 timer. */
735 setbits_le32(&prcm_base->clksel_per, 0x80); /* GPT9 = 32kHz clk */
736 setbits_le32(&prcm_base->iclken_per, 0x400); /* ICKen GPT9 */
737 setbits_le32(&prcm_base->fclken_per, 0x400); /* FCKen GPT9 */
739 #ifdef CONFIG_SYS_NS16550
740 /* Enable UART1 clocks */
741 setbits_le32(&prcm_base->fclken1_core, 0x00002000);
742 setbits_le32(&prcm_base->iclken1_core, 0x00002000);
744 /* Enable UART2 clocks */
745 setbits_le32(&prcm_base->fclken1_core, 0x00004000);
746 setbits_le32(&prcm_base->iclken1_core, 0x00004000);
749 setbits_le32(&prcm_base->fclken_per, 0x00000800);
750 setbits_le32(&prcm_base->iclken_per, 0x00000800);
753 #ifdef CONFIG_OMAP3_GPIO_2
754 setbits_le32(&prcm_base->fclken_per, 0x00002000);
755 setbits_le32(&prcm_base->iclken_per, 0x00002000);
757 #ifdef CONFIG_OMAP3_GPIO_3
758 setbits_le32(&prcm_base->fclken_per, 0x00004000);
759 setbits_le32(&prcm_base->iclken_per, 0x00004000);
761 #ifdef CONFIG_OMAP3_GPIO_4
762 setbits_le32(&prcm_base->fclken_per, 0x00008000);
763 setbits_le32(&prcm_base->iclken_per, 0x00008000);
765 #ifdef CONFIG_OMAP3_GPIO_5
766 setbits_le32(&prcm_base->fclken_per, 0x00010000);
767 setbits_le32(&prcm_base->iclken_per, 0x00010000);
769 #ifdef CONFIG_OMAP3_GPIO_6
770 setbits_le32(&prcm_base->fclken_per, 0x00020000);
771 setbits_le32(&prcm_base->iclken_per, 0x00020000);
774 #ifdef CONFIG_SYS_I2C_OMAP24XX
775 /* Turn on all 3 I2C clocks */
776 setbits_le32(&prcm_base->fclken1_core, 0x00038000);
777 setbits_le32(&prcm_base->iclken1_core, 0x00038000); /* I2C1,2,3 = on */
779 /* Enable the ICLK for 32K Sync Timer as its used in udelay */
780 setbits_le32(&prcm_base->iclken_wkup, 0x00000004);
782 if (get_cpu_family() != CPU_AM35XX)
783 out_le32(&prcm_base->fclken_iva2, FCK_IVA2_ON);
785 out_le32(&prcm_base->fclken1_core, FCK_CORE1_ON);
786 out_le32(&prcm_base->iclken1_core, ICK_CORE1_ON);
787 out_le32(&prcm_base->iclken2_core, ICK_CORE2_ON);
788 out_le32(&prcm_base->fclken_wkup, FCK_WKUP_ON);
789 out_le32(&prcm_base->iclken_wkup, ICK_WKUP_ON);
790 out_le32(&prcm_base->fclken_dss, FCK_DSS_ON);
791 out_le32(&prcm_base->iclken_dss, ICK_DSS_ON);
792 if (get_cpu_family() != CPU_AM35XX) {
793 out_le32(&prcm_base->fclken_cam, FCK_CAM_ON);
794 out_le32(&prcm_base->iclken_cam, ICK_CAM_ON);