2 * linux/arch/arm/mach-omap2/clock.c
4 * Copyright (C) 2005 Texas Instruments Inc.
5 * Richard Woodruff <r-woodruff2@ti.com>
8 * Cleaned up and modified to use omap shared clock framework by
9 * Tony Lindgren <tony@atomide.com>
11 * Based on omap1 clock.c, Copyright (C) 2004 - 2005 Nokia corporation
12 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
18 #include <linux/config.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/device.h>
22 #include <linux/list.h>
23 #include <linux/errno.h>
24 #include <linux/delay.h>
25 #include <linux/clk.h>
29 #include <asm/arch/clock.h>
30 #include <asm/arch/sram.h>
31 #include <asm/arch/prcm.h>
35 //#define DOWN_VARIABLE_DPLL 1 /* Experimental */
37 static struct prcm_config *curr_prcm_set;
38 static struct memory_timings mem_timings;
39 static u32 curr_perf_level = PRCM_FULL_SPEED;
41 /*-------------------------------------------------------------------------
42 * Omap2 specific clock functions
43 *-------------------------------------------------------------------------*/
45 /* Recalculate SYST_CLK */
46 static void omap2_sys_clk_recalc(struct clk * clk)
48 u32 div = PRCM_CLKSRC_CTRL;
49 div &= (1 << 7) | (1 << 6); /* Test if ext clk divided by 1 or 2 */
50 div >>= clk->rate_offset;
51 clk->rate = (clk->parent->rate / div);
55 static u32 omap2_get_dpll_rate(struct clk * tclk)
57 int dpll_clk, dpll_mult, dpll_div, amult;
59 dpll_mult = (CM_CLKSEL1_PLL >> 12) & 0x03ff; /* 10 bits */
60 dpll_div = (CM_CLKSEL1_PLL >> 8) & 0x0f; /* 4 bits */
61 dpll_clk = (tclk->parent->rate * dpll_mult) / (dpll_div + 1);
62 amult = CM_CLKSEL2_PLL & 0x3;
68 static void omap2_followparent_recalc(struct clk *clk)
70 followparent_recalc(clk);
73 static void omap2_propagate_rate(struct clk * clk)
75 if (!(clk->flags & RATE_FIXED))
76 clk->rate = clk->parent->rate;
81 /* Enable an APLL if off */
82 static void omap2_clk_fixed_enable(struct clk *clk)
86 if (clk->enable_bit == 0xff) /* Parent will do it */
91 if ((cval & (0x3 << clk->enable_bit)) == (0x3 << clk->enable_bit))
94 cval &= ~(0x3 << clk->enable_bit);
95 cval |= (0x3 << clk->enable_bit);
98 if (clk == &apll96_ck)
100 else if (clk == &apll54_ck)
103 while (!CM_IDLEST_CKGEN & cval) { /* Wait for lock */
111 /* Enables clock without considering parent dependencies or use count
112 * REVISIT: Maybe change this to use clk->enable like on omap1?
114 static int _omap2_clk_enable(struct clk * clk)
118 if (clk->flags & ALWAYS_ENABLED)
121 if (unlikely(clk->enable_reg == 0)) {
122 printk(KERN_ERR "clock.c: Enable for %s without enable code\n",
127 if (clk->enable_reg == (void __iomem *)&CM_CLKEN_PLL) {
128 omap2_clk_fixed_enable(clk);
132 regval32 = __raw_readl(clk->enable_reg);
133 regval32 |= (1 << clk->enable_bit);
134 __raw_writel(regval32, clk->enable_reg);
140 static void omap2_clk_fixed_disable(struct clk *clk)
144 if(clk->enable_bit == 0xff) /* let parent off do it */
148 cval &= ~(0x3 << clk->enable_bit);
152 /* Disables clock without considering parent dependencies or use count */
153 static void _omap2_clk_disable(struct clk *clk)
157 if (clk->enable_reg == 0)
160 if (clk->enable_reg == (void __iomem *)&CM_CLKEN_PLL) {
161 omap2_clk_fixed_disable(clk);
165 regval32 = __raw_readl(clk->enable_reg);
166 regval32 &= ~(1 << clk->enable_bit);
167 __raw_writel(regval32, clk->enable_reg);
170 static int omap2_clk_enable(struct clk *clk)
174 if (clk->usecount++ == 0) {
175 if (likely((u32)clk->parent))
176 ret = omap2_clk_enable(clk->parent);
178 if (unlikely(ret != 0)) {
183 ret = _omap2_clk_enable(clk);
185 if (unlikely(ret != 0) && clk->parent) {
186 omap2_clk_disable(clk->parent);
194 static void omap2_clk_disable(struct clk *clk)
196 if (clk->usecount > 0 && !(--clk->usecount)) {
197 _omap2_clk_disable(clk);
198 if (likely((u32)clk->parent))
199 omap2_clk_disable(clk->parent);
204 * Uses the current prcm set to tell if a rate is valid.
205 * You can go slower, but not faster within a given rate set.
207 static u32 omap2_dpll_round_rate(unsigned long target_rate)
211 if ((CM_CLKSEL2_PLL & 0x3) == 1) { /* DPLL clockout */
212 high = curr_prcm_set->dpll_speed * 2;
213 low = curr_prcm_set->dpll_speed;
214 } else { /* DPLL clockout x 2 */
215 high = curr_prcm_set->dpll_speed;
216 low = curr_prcm_set->dpll_speed / 2;
219 #ifdef DOWN_VARIABLE_DPLL
220 if (target_rate > high)
225 if (target_rate > low)
234 * Used for clocks that are part of CLKSEL_xyz governed clocks.
235 * REVISIT: Maybe change to use clk->enable() functions like on omap1?
237 static void omap2_clksel_recalc(struct clk * clk)
239 u32 fixed = 0, div = 0;
241 if (clk == &dpll_ck) {
242 clk->rate = omap2_get_dpll_rate(clk);
247 if (clk == &iva1_mpu_int_ifck) {
252 if ((clk == &dss1_fck) && ((CM_CLKSEL1_CORE & (0x1f << 8)) == 0)) {
253 clk->rate = sys_ck.rate;
258 div = omap2_clksel_get_divisor(clk);
264 if (unlikely(clk->rate == clk->parent->rate / div))
266 clk->rate = clk->parent->rate / div;
269 if (unlikely(clk->flags & RATE_PROPAGATES))
274 * Finds best divider value in an array based on the source and target
275 * rates. The divider array must be sorted with smallest divider first.
277 static inline u32 omap2_divider_from_table(u32 size, u32 *div_array,
278 u32 src_rate, u32 tgt_rate)
282 if (div_array == NULL)
285 for (i=0; i < size; i++) {
286 test_rate = src_rate / *div_array;
287 if (test_rate <= tgt_rate)
292 return ~0; /* No acceptable divider */
296 * Find divisor for the given clock and target rate.
298 * Note that this will not work for clocks which are part of CONFIG_PARTICIPANT,
299 * they are only settable as part of virtual_prcm set.
301 static u32 omap2_clksel_round_rate(struct clk *tclk, u32 target_rate,
304 u32 gfx_div[] = {2, 3, 4};
305 u32 sysclkout_div[] = {1, 2, 4, 8, 16};
306 u32 dss1_div[] = {1, 2, 3, 4, 5, 6, 8, 9, 12, 16};
307 u32 vylnq_div[] = {1, 2, 3, 4, 6, 8, 9, 12, 16, 18};
308 u32 best_div = ~0, asize = 0;
309 u32 *div_array = NULL;
311 switch (tclk->flags & SRC_RATE_SEL_MASK) {
317 return omap2_dpll_round_rate(target_rate);
318 case CM_SYSCLKOUT_SEL1:
320 div_array = sysclkout_div;
323 if(tclk == &dss1_fck){
324 if(tclk->parent == &core_ck){
326 div_array = dss1_div;
328 *new_div = 0; /* fixed clk */
329 return(tclk->parent->rate);
331 } else if((tclk == &vlynq_fck) && cpu_is_omap2420()){
332 if(tclk->parent == &core_ck){
334 div_array = vylnq_div;
336 *new_div = 0; /* fixed clk */
337 return(tclk->parent->rate);
343 best_div = omap2_divider_from_table(asize, div_array,
344 tclk->parent->rate, target_rate);
347 return best_div; /* signal error */
351 return (tclk->parent->rate / best_div);
354 /* Given a clock and a rate apply a clock specific rounding function */
355 static long omap2_clk_round_rate(struct clk *clk, unsigned long rate)
360 if (clk->flags & RATE_FIXED)
363 if (clk->flags & RATE_CKCTL) {
364 valid_rate = omap2_clksel_round_rate(clk, rate, &new_div);
368 if (clk->round_rate != 0)
369 return clk->round_rate(clk, rate);
375 * Check the DLL lock state, and return tue if running in unlock mode.
376 * This is needed to compenste for the shifted DLL value in unlock mode.
378 static u32 omap2_dll_force_needed(void)
380 u32 dll_state = SDRC_DLLA_CTRL; /* dlla and dllb are a set */
382 if ((dll_state & (1 << 2)) == (1 << 2))
388 static void omap2_init_memory_params(u32 force_lock_to_unlock_mode)
390 unsigned long dll_cnt;
393 mem_timings.m_type = !((SDRC_MR_0 & 0x3) == 0x1); /* DDR = 1, SDR = 0 */
395 /* 2422 es2.05 and beyond has a single SIP DDR instead of 2 like others.
396 * In the case of 2422, its ok to use CS1 instead of CS0.
399 #if 0 /* FIXME: Enable after 24xx cpu detection works */
400 ctype = get_cpu_type();
401 if (cpu_is_omap2422())
402 mem_timings.base_cs = 1;
405 mem_timings.base_cs = 0;
407 if (mem_timings.m_type != M_DDR)
410 /* With DDR we need to determine the low frequency DLL value */
411 if (((mem_timings.fast_dll_ctrl & (1 << 2)) == M_LOCK_CTRL))
412 mem_timings.dll_mode = M_UNLOCK;
414 mem_timings.dll_mode = M_LOCK;
416 if (mem_timings.base_cs == 0) {
417 fast_dll = SDRC_DLLA_CTRL;
418 dll_cnt = SDRC_DLLA_STATUS & 0xff00;
420 fast_dll = SDRC_DLLB_CTRL;
421 dll_cnt = SDRC_DLLB_STATUS & 0xff00;
423 if (force_lock_to_unlock_mode) {
425 fast_dll |= dll_cnt; /* Current lock mode */
427 mem_timings.fast_dll_ctrl = fast_dll;
429 /* No disruptions, DDR will be offline & C-ABI not followed */
430 omap2_sram_ddr_init(&mem_timings.slow_dll_ctrl,
431 mem_timings.fast_dll_ctrl,
433 force_lock_to_unlock_mode);
434 mem_timings.slow_dll_ctrl &= 0xff00; /* Keep lock value */
436 /* Turn status into unlock ctrl */
437 mem_timings.slow_dll_ctrl |=
438 ((mem_timings.fast_dll_ctrl & 0xF) | (1 << 2));
440 /* 90 degree phase for anything below 133Mhz */
441 mem_timings.slow_dll_ctrl |= (1 << 1);
444 static u32 omap2_reprogram_sdrc(u32 level, u32 force)
446 u32 prev = curr_perf_level, flags;
448 if ((curr_perf_level == level) && !force)
451 if (level == PRCM_HALF_SPEED) {
452 local_irq_save(flags);
453 PRCM_VOLTSETUP = 0xffff;
454 omap2_sram_reprogram_sdrc(PRCM_HALF_SPEED,
455 mem_timings.slow_dll_ctrl,
457 curr_perf_level = PRCM_HALF_SPEED;
458 local_irq_restore(flags);
460 if (level == PRCM_FULL_SPEED) {
461 local_irq_save(flags);
462 PRCM_VOLTSETUP = 0xffff;
463 omap2_sram_reprogram_sdrc(PRCM_FULL_SPEED,
464 mem_timings.fast_dll_ctrl,
466 curr_perf_level = PRCM_FULL_SPEED;
467 local_irq_restore(flags);
473 static int omap2_reprogram_dpll(struct clk * clk, unsigned long rate)
475 u32 flags, cur_rate, low, mult, div, valid_rate, done_rate;
477 struct prcm_config tmpset;
480 local_irq_save(flags);
481 cur_rate = omap2_get_dpll_rate(&dpll_ck);
482 mult = CM_CLKSEL2_PLL & 0x3;
484 if ((rate == (cur_rate / 2)) && (mult == 2)) {
485 omap2_reprogram_sdrc(PRCM_HALF_SPEED, 1);
486 } else if ((rate == (cur_rate * 2)) && (mult == 1)) {
487 omap2_reprogram_sdrc(PRCM_FULL_SPEED, 1);
488 } else if (rate != cur_rate) {
489 valid_rate = omap2_dpll_round_rate(rate);
490 if (valid_rate != rate)
493 if ((CM_CLKSEL2_PLL & 0x3) == 1)
494 low = curr_prcm_set->dpll_speed;
496 low = curr_prcm_set->dpll_speed / 2;
498 tmpset.cm_clksel1_pll = CM_CLKSEL1_PLL;
499 tmpset.cm_clksel1_pll &= ~(0x3FFF << 8);
500 div = ((curr_prcm_set->xtal_speed / 1000000) - 1);
501 tmpset.cm_clksel2_pll = CM_CLKSEL2_PLL;
502 tmpset.cm_clksel2_pll &= ~0x3;
504 tmpset.cm_clksel2_pll |= 0x2;
505 mult = ((rate / 2) / 1000000);
506 done_rate = PRCM_FULL_SPEED;
508 tmpset.cm_clksel2_pll |= 0x1;
509 mult = (rate / 1000000);
510 done_rate = PRCM_HALF_SPEED;
512 tmpset.cm_clksel1_pll |= ((div << 8) | (mult << 12));
515 tmpset.base_sdrc_rfr = V24XX_SDRC_RFR_CTRL_BYPASS;
517 if (rate == curr_prcm_set->xtal_speed) /* If asking for 1-1 */
520 omap2_reprogram_sdrc(PRCM_FULL_SPEED, 1); /* For init_mem */
522 /* Force dll lock mode */
523 omap2_set_prcm(tmpset.cm_clksel1_pll, tmpset.base_sdrc_rfr,
526 /* Errata: ret dll entry state */
527 omap2_init_memory_params(omap2_dll_force_needed());
528 omap2_reprogram_sdrc(done_rate, 0);
530 omap2_clksel_recalc(&dpll_ck);
534 local_irq_restore(flags);
538 /* Just return the MPU speed */
539 static void omap2_mpu_recalc(struct clk * clk)
541 clk->rate = curr_prcm_set->mpu_speed;
545 * Look for a rate equal or less than the target rate given a configuration set.
547 * What's not entirely clear is "which" field represents the key field.
548 * Some might argue L3-DDR, others ARM, others IVA. This code is simple and
549 * just uses the ARM rates.
551 static long omap2_round_to_table_rate(struct clk * clk, unsigned long rate)
553 struct prcm_config * ptr;
556 if (clk != &virt_prcm_set)
559 highest_rate = -EINVAL;
561 for (ptr = rate_table; ptr->mpu_speed; ptr++) {
562 if (ptr->xtal_speed != sys_ck.rate)
565 highest_rate = ptr->mpu_speed;
567 /* Can check only after xtal frequency check */
568 if (ptr->mpu_speed <= rate)
575 * omap2_convert_field_to_div() - turn field value into integer divider
577 static u32 omap2_clksel_to_divisor(u32 div_sel, u32 field_val)
580 u32 clkout_array[] = {1, 2, 4, 8, 16};
582 if ((div_sel & SRC_RATE_SEL_MASK) == CM_SYSCLKOUT_SEL1) {
583 for (i = 0; i < 5; i++) {
585 return clkout_array[i];
593 * Returns the CLKSEL divider register value
594 * REVISIT: This should be cleaned up to work nicely with void __iomem *
596 static u32 omap2_get_clksel(u32 *div_sel, u32 *field_mask,
600 u32 reg_val, div_off;
604 div_off = clk->rate_offset;
606 switch ((*div_sel & SRC_RATE_SEL_MASK)) {
608 div_addr = (u32)&CM_CLKSEL_MPU;
612 div_addr = (u32)&CM_CLKSEL_DSP;
613 if (cpu_is_omap2420()) {
614 if ((div_off == 0) || (div_off == 8))
616 else if (div_off == 5)
618 } else if (cpu_is_omap2430()) {
621 else if (div_off == 5)
626 div_addr = (u32)&CM_CLKSEL_GFX;
631 div_addr = (u32)&CM_CLKSEL_MDM;
635 case CM_SYSCLKOUT_SEL1:
636 div_addr = (u32)&PRCM_CLKOUT_CTRL;
637 if ((div_off == 3) || (div_off = 11))
641 div_addr = (u32)&CM_CLKSEL1_CORE;
645 case 15: /* vylnc-2420 */
659 if (unlikely(mask == ~0))
664 if (unlikely(div_addr == 0))
668 reg_val = __raw_readl((void __iomem *)div_addr) & (mask << div_off);
670 /* Normalize back to divider value */
677 * Return divider to be applied to parent clock.
680 static u32 omap2_clksel_get_divisor(struct clk *clk)
683 u32 div, div_sel, div_off, field_mask, field_val;
685 /* isolate control register */
686 div_sel = (SRC_RATE_SEL_MASK & clk->flags);
688 div_off = clk->rate_offset;
689 field_val = omap2_get_clksel(&div_sel, &field_mask, clk);
693 div_sel = (SRC_RATE_SEL_MASK & clk->flags);
694 div = omap2_clksel_to_divisor(div_sel, field_val);
699 /* Set the clock rate for a clock source */
700 static int omap2_clk_set_rate(struct clk *clk, unsigned long rate)
705 u32 div_sel, div_off, field_mask, field_val, reg_val, validrate;
708 if (!(clk->flags & CONFIG_PARTICIPANT) && (clk->flags & RATE_CKCTL)) {
710 return omap2_reprogram_dpll(clk, rate);
712 /* Isolate control register */
713 div_sel = (SRC_RATE_SEL_MASK & clk->flags);
714 div_off = clk->src_offset;
716 validrate = omap2_clksel_round_rate(clk, rate, &new_div);
717 if(validrate != rate)
720 field_val = omap2_get_clksel(&div_sel, &field_mask, clk);
724 if(clk->flags & CM_SYSCLKOUT_SEL1){
726 case 16: field_val = 4; break;
727 case 8: field_val = 3; break;
728 case 4: field_val = 2; break;
729 case 2: field_val = 1; break;
730 case 1: field_val = 0; break;
736 reg = (void __iomem *)div_sel;
738 reg_val = __raw_readl(reg);
739 reg_val &= ~(field_mask << div_off);
740 reg_val |= (field_val << div_off);
742 __raw_writel(reg_val, reg);
743 clk->rate = clk->parent->rate / field_val;
745 if (clk->flags & DELAYED_APP)
746 __raw_writel(0x1, (void __iomem *)&PRCM_CLKCFG_CTRL);
748 } else if (clk->set_rate != 0)
749 ret = clk->set_rate(clk, rate);
751 if (unlikely(ret == 0 && (clk->flags & RATE_PROPAGATES)))
757 /* Converts encoded control register address into a full address */
758 static u32 omap2_get_src_field(u32 *type_to_addr, u32 reg_offset,
759 struct clk *src_clk, u32 *field_mask)
761 u32 val = ~0, src_reg_addr = 0, mask = 0;
763 /* Find target control register.*/
764 switch ((*type_to_addr & SRC_RATE_SEL_MASK)) {
766 src_reg_addr = (u32)&CM_CLKSEL1_CORE;
767 if (reg_offset == 13) { /* DSS2_fclk */
769 if (src_clk == &sys_ck)
771 if (src_clk == &func_48m_ck)
773 } else if (reg_offset == 8) { /* DSS1_fclk */
775 if (src_clk == &sys_ck)
777 else if (src_clk == &core_ck) /* divided clock */
778 val = 0x10; /* rate needs fixing */
779 } else if ((reg_offset == 15) && cpu_is_omap2420()){ /*vlnyq*/
781 if(src_clk == &func_96m_ck)
783 else if (src_clk == &core_ck)
788 src_reg_addr = (u32)&CM_CLKSEL2_CORE;
790 if (src_clk == &func_32k_ck)
792 if (src_clk == &sys_ck)
794 if (src_clk == &alt_ck)
798 src_reg_addr = (u32)&CM_CLKSEL2_CORE;
800 if (src_clk == &func_32k_ck)
802 if (src_clk == &sys_ck)
804 if (src_clk == &alt_ck)
808 src_reg_addr = (u32)&CM_CLKSEL1_PLL;
810 if (reg_offset == 0x3) {
811 if (src_clk == &apll96_ck)
813 if (src_clk == &alt_ck)
816 else if (reg_offset == 0x5) {
817 if (src_clk == &apll54_ck)
819 if (src_clk == &alt_ck)
824 src_reg_addr = (u32)&CM_CLKSEL2_PLL;
826 if (src_clk == &func_32k_ck)
828 if (src_clk == &dpll_ck)
831 case CM_SYSCLKOUT_SEL1:
832 src_reg_addr = (u32)&PRCM_CLKOUT_CTRL;
834 if (src_clk == &dpll_ck)
836 if (src_clk == &sys_ck)
838 if (src_clk == &func_54m_ck)
840 if (src_clk == &func_96m_ck)
845 if (val == ~0) /* Catch errors in offset */
848 *type_to_addr = src_reg_addr;
854 static int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent)
857 u32 src_sel, src_off, field_val, field_mask, reg_val, rate;
860 if (unlikely(clk->flags & CONFIG_PARTICIPANT))
863 if (clk->flags & SRC_SEL_MASK) { /* On-chip SEL collection */
864 src_sel = (SRC_RATE_SEL_MASK & clk->flags);
865 src_off = clk->src_offset;
868 goto set_parent_error;
870 field_val = omap2_get_src_field(&src_sel, src_off, new_parent,
873 reg = (void __iomem *)src_sel;
875 if (clk->usecount > 0)
876 _omap2_clk_disable(clk);
878 /* Set new source value (previous dividers if any in effect) */
879 reg_val = __raw_readl(reg) & ~(field_mask << src_off);
880 reg_val |= (field_val << src_off);
881 __raw_writel(reg_val, reg);
883 if (clk->flags & DELAYED_APP)
884 __raw_writel(0x1, (void __iomem *)&PRCM_CLKCFG_CTRL);
886 if (clk->usecount > 0)
887 _omap2_clk_enable(clk);
889 clk->parent = new_parent;
891 /* SRC_RATE_SEL_MASK clocks follow their parents rates.*/
892 if ((new_parent == &core_ck) && (clk == &dss1_fck))
893 clk->rate = new_parent->rate / 0x10;
895 clk->rate = new_parent->rate;
897 if (unlikely(clk->flags & RATE_PROPAGATES))
902 clk->parent = new_parent;
903 rate = new_parent->rate;
904 omap2_clk_set_rate(clk, rate);
912 /* Sets basic clocks based on the specified rate */
913 static int omap2_select_table_rate(struct clk * clk, unsigned long rate)
915 u32 flags, cur_rate, done_rate, bypass = 0;
917 struct prcm_config *prcm;
918 unsigned long found_speed = 0;
920 if (clk != &virt_prcm_set)
923 /* FIXME: Change cpu_is_omap2420() to cpu_is_omap242x() */
924 if (cpu_is_omap2420())
925 cpu_mask = RATE_IN_242X;
926 else if (cpu_is_omap2430())
927 cpu_mask = RATE_IN_243X;
929 for (prcm = rate_table; prcm->mpu_speed; prcm++) {
930 if (!(prcm->flags & cpu_mask))
933 if (prcm->xtal_speed != sys_ck.rate)
936 if (prcm->mpu_speed <= rate) {
937 found_speed = prcm->mpu_speed;
943 printk(KERN_INFO "Could not set MPU rate to %luMHz\n",
948 curr_prcm_set = prcm;
949 cur_rate = omap2_get_dpll_rate(&dpll_ck);
951 if (prcm->dpll_speed == cur_rate / 2) {
952 omap2_reprogram_sdrc(PRCM_HALF_SPEED, 1);
953 } else if (prcm->dpll_speed == cur_rate * 2) {
954 omap2_reprogram_sdrc(PRCM_FULL_SPEED, 1);
955 } else if (prcm->dpll_speed != cur_rate) {
956 local_irq_save(flags);
958 if (prcm->dpll_speed == prcm->xtal_speed)
961 if ((prcm->cm_clksel2_pll & 0x3) == 2)
962 done_rate = PRCM_FULL_SPEED;
964 done_rate = PRCM_HALF_SPEED;
967 CM_CLKSEL_MPU = prcm->cm_clksel_mpu;
969 /* dsp + iva1 div(2420), iva2.1(2430) */
970 CM_CLKSEL_DSP = prcm->cm_clksel_dsp;
972 CM_CLKSEL_GFX = prcm->cm_clksel_gfx;
974 /* Major subsystem dividers */
975 CM_CLKSEL1_CORE = prcm->cm_clksel1_core;
976 if (cpu_is_omap2430())
977 CM_CLKSEL_MDM = prcm->cm_clksel_mdm;
979 /* x2 to enter init_mem */
980 omap2_reprogram_sdrc(PRCM_FULL_SPEED, 1);
982 omap2_set_prcm(prcm->cm_clksel1_pll, prcm->base_sdrc_rfr,
985 omap2_init_memory_params(omap2_dll_force_needed());
986 omap2_reprogram_sdrc(done_rate, 0);
988 local_irq_restore(flags);
990 omap2_clksel_recalc(&dpll_ck);
995 /*-------------------------------------------------------------------------
996 * Omap2 clock reset and init functions
997 *-------------------------------------------------------------------------*/
999 static struct clk_functions omap2_clk_functions = {
1000 .clk_enable = omap2_clk_enable,
1001 .clk_disable = omap2_clk_disable,
1002 .clk_round_rate = omap2_clk_round_rate,
1003 .clk_set_rate = omap2_clk_set_rate,
1004 .clk_set_parent = omap2_clk_set_parent,
1007 static void __init omap2_get_crystal_rate(struct clk *osc, struct clk *sys)
1009 u32 div, aplls, sclk = 13000000;
1011 aplls = CM_CLKSEL1_PLL;
1012 aplls &= ((1 << 23) | (1 << 24) | (1 << 25));
1013 aplls >>= 23; /* Isolate field, 0,2,3 */
1017 else if (aplls == 2)
1019 else if (aplls == 3)
1022 div = PRCM_CLKSRC_CTRL;
1023 div &= ((1 << 7) | (1 << 6));
1024 div >>= sys->rate_offset;
1026 osc->rate = sclk * div;
1030 #ifdef CONFIG_OMAP_RESET_CLOCKS
1031 static void __init omap2_disable_unused_clocks(void)
1036 list_for_each_entry(ck, &clocks, node) {
1037 if (ck->usecount > 0 || (ck->flags & ALWAYS_ENABLED) ||
1038 ck->enable_reg == 0)
1041 regval32 = __raw_readl(ck->enable_reg);
1042 if ((regval32 & (1 << ck->enable_bit)) == 0)
1045 printk(KERN_INFO "Disabling unused clock \"%s\"\n", ck->name);
1046 _omap2_clk_disable(ck);
1049 late_initcall(omap2_disable_unused_clocks);
1053 * Switch the MPU rate if specified on cmdline.
1054 * We cannot do this early until cmdline is parsed.
1056 static int __init omap2_clk_arch_init(void)
1061 if (omap2_select_table_rate(&virt_prcm_set, mpurate))
1062 printk(KERN_ERR "Could not find matching MPU rate\n");
1064 propagate_rate(&osc_ck); /* update main root fast */
1065 propagate_rate(&func_32k_ck); /* update main root slow */
1067 printk(KERN_INFO "Switched to new clocking rate (Crystal/DPLL/MPU): "
1068 "%ld.%01ld/%ld/%ld MHz\n",
1069 (sys_ck.rate / 1000000), (sys_ck.rate / 100000) % 10,
1070 (dpll_ck.rate / 1000000), (mpu_ck.rate / 1000000)) ;
1074 arch_initcall(omap2_clk_arch_init);
1076 int __init omap2_clk_init(void)
1078 struct prcm_config *prcm;
1082 clk_init(&omap2_clk_functions);
1083 omap2_get_crystal_rate(&osc_ck, &sys_ck);
1085 for (clkp = onchip_clks; clkp < onchip_clks + ARRAY_SIZE(onchip_clks);
1088 if ((*clkp)->flags & CLOCK_IN_OMAP242X && cpu_is_omap2420()) {
1089 clk_register(*clkp);
1093 if ((*clkp)->flags & CLOCK_IN_OMAP243X && cpu_is_omap2430()) {
1094 clk_register(*clkp);
1099 /* Check the MPU rate set by bootloader */
1100 clkrate = omap2_get_dpll_rate(&dpll_ck);
1101 for (prcm = rate_table; prcm->mpu_speed; prcm++) {
1102 if (prcm->xtal_speed != sys_ck.rate)
1104 if (prcm->dpll_speed <= clkrate)
1107 curr_prcm_set = prcm;
1109 propagate_rate(&osc_ck); /* update main root fast */
1110 propagate_rate(&func_32k_ck); /* update main root slow */
1112 printk(KERN_INFO "Clocking rate (Crystal/DPLL/MPU): "
1113 "%ld.%01ld/%ld/%ld MHz\n",
1114 (sys_ck.rate / 1000000), (sys_ck.rate / 100000) % 10,
1115 (dpll_ck.rate / 1000000), (mpu_ck.rate / 1000000)) ;
1118 * Only enable those clocks we will need, let the drivers
1119 * enable other clocks as necessary
1121 clk_enable(&sync_32k_ick);
1122 clk_enable(&omapctrl_ick);
1123 if (cpu_is_omap2430())
1124 clk_enable(&sdrc_ick);