eeec5f174401197a21b1e0a8e219c12e19c4d406
[pandora-kernel.git] / arch / arm / mach-omap2 / clock34xx.c
1 /*
2  * OMAP3-specific clock framework functions
3  *
4  * Copyright (C) 2007-2008 Texas Instruments, Inc.
5  * Copyright (C) 2007-2008 Nokia Corporation
6  *
7  * Written by Paul Walmsley
8  * Testing and integration fixes by Jouni Högander
9  *
10  * Parts of this code are based on code written by
11  * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License version 2 as
15  * published by the Free Software Foundation.
16  */
17 #undef DEBUG
18
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>
26 #include <linux/io.h>
27 #include <linux/limits.h>
28
29 #include <mach/clock.h>
30 #include <mach/sram.h>
31 #include <asm/div64.h>
32 #include <asm/bitops.h>
33
34 #include <mach/sdrc.h>
35 #include "clock.h"
36 #include "clock34xx.h"
37 #include "prm.h"
38 #include "prm-regbits-34xx.h"
39 #include "cm.h"
40 #include "cm-regbits-34xx.h"
41
42 /* CM_AUTOIDLE_PLL*.AUTO_* bit values */
43 #define DPLL_AUTOIDLE_DISABLE                   0x0
44 #define DPLL_AUTOIDLE_LOW_POWER_STOP            0x1
45
46 #define MAX_DPLL_WAIT_TRIES             1000000
47
48 /**
49  * omap3_dpll_recalc - recalculate DPLL rate
50  * @clk: DPLL struct clk
51  *
52  * Recalculate and propagate the DPLL rate.
53  */
54 static void omap3_dpll_recalc(struct clk *clk)
55 {
56         clk->rate = omap2_get_dpll_rate(clk);
57
58         propagate_rate(clk);
59 }
60
61 /* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */
62 static void _omap3_dpll_write_clken(struct clk *clk, u8 clken_bits)
63 {
64         const struct dpll_data *dd;
65         u32 v;
66
67         dd = clk->dpll_data;
68
69         v = cm_read_mod_reg(clk->prcm_mod, dd->control_reg);
70         v &= ~dd->enable_mask;
71         v |= clken_bits << __ffs(dd->enable_mask);
72         cm_write_mod_reg(v, clk->prcm_mod, dd->control_reg);
73 }
74
75 /* _omap3_wait_dpll_status: wait for a DPLL to enter a specific state */
76 static int _omap3_wait_dpll_status(struct clk *clk, u8 state)
77 {
78         const struct dpll_data *dd;
79         int i = 0;
80         int ret = -EINVAL;
81
82         dd = clk->dpll_data;
83
84         state <<= __ffs(dd->idlest_mask);
85
86         while (((cm_read_mod_reg(clk->prcm_mod, dd->idlest_reg)
87                  & dd->idlest_mask) != state) &&
88                i < MAX_DPLL_WAIT_TRIES) {
89                 i++;
90                 udelay(1);
91         }
92
93         if (i == MAX_DPLL_WAIT_TRIES) {
94                 printk(KERN_ERR "clock: %s failed transition to '%s'\n",
95                        clk->name, (state) ? "locked" : "bypassed");
96         } else {
97                 pr_debug("clock: %s transition to '%s' in %d loops\n",
98                          clk->name, (state) ? "locked" : "bypassed", i);
99
100                 ret = 0;
101         }
102
103         return ret;
104 }
105
106 /* From 3430 TRM ES2 4.7.6.2 */
107 static u16 _omap3_dpll_compute_freqsel(struct clk *clk, u8 n)
108 {
109         unsigned long fint;
110         u16 f = 0;
111
112         fint = clk->parent->rate / (n + 1);
113
114         pr_debug("clock: fint is %lu\n", fint);
115
116         if (fint >= 750000 && fint <= 1000000)
117                 f = 0x3;
118         else if (fint > 1000000 && fint <= 1250000)
119                 f = 0x4;
120         else if (fint > 1250000 && fint <= 1500000)
121                 f = 0x5;
122         else if (fint > 1500000 && fint <= 1750000)
123                 f = 0x6;
124         else if (fint > 1750000 && fint <= 2100000)
125                 f = 0x7;
126         else if (fint > 7500000 && fint <= 10000000)
127                 f = 0xB;
128         else if (fint > 10000000 && fint <= 12500000)
129                 f = 0xC;
130         else if (fint > 12500000 && fint <= 15000000)
131                 f = 0xD;
132         else if (fint > 15000000 && fint <= 17500000)
133                 f = 0xE;
134         else if (fint > 17500000 && fint <= 21000000)
135                 f = 0xF;
136         else
137                 pr_debug("clock: unknown freqsel setting for %d\n", n);
138
139         return f;
140 }
141
142 /* Non-CORE DPLL (e.g., DPLLs that do not control SDRC) clock functions */
143
144 /*
145  * _omap3_noncore_dpll_lock - instruct a DPLL to lock and wait for readiness
146  * @clk: pointer to a DPLL struct clk
147  *
148  * Instructs a non-CORE DPLL to lock.  Waits for the DPLL to report
149  * readiness before returning.  Will save and restore the DPLL's
150  * autoidle state across the enable, per the CDP code.  If the DPLL
151  * locked successfully, return 0; if the DPLL did not lock in the time
152  * allotted, or DPLL3 was passed in, return -EINVAL.
153  */
154 static int _omap3_noncore_dpll_lock(struct clk *clk)
155 {
156         u8 ai;
157         int r;
158
159         if (clk == &dpll3_ck)
160                 return -EINVAL;
161
162         pr_debug("clock: locking DPLL %s\n", clk->name);
163
164         ai = omap3_dpll_autoidle_read(clk);
165
166         _omap3_dpll_write_clken(clk, DPLL_LOCKED);
167
168         if (ai) {
169                 /*
170                  * If no downstream clocks are enabled, CM_IDLEST bit
171                  * may never become active, so don't wait for DPLL to lock.
172                  */
173                 r = 0;
174                 omap3_dpll_allow_idle(clk);
175         } else {
176                 r = _omap3_wait_dpll_status(clk, 1);
177                 omap3_dpll_deny_idle(clk);
178         };
179
180         return r;
181 }
182
183 /*
184  * _omap3_noncore_dpll_bypass - instruct a DPLL to bypass and wait for readiness
185  * @clk: pointer to a DPLL struct clk
186  *
187  * Instructs a non-CORE DPLL to enter low-power bypass mode.  In
188  * bypass mode, the DPLL's rate is set equal to its parent clock's
189  * rate.  Waits for the DPLL to report readiness before returning.
190  * Will save and restore the DPLL's autoidle state across the enable,
191  * per the CDP code.  If the DPLL entered bypass mode successfully,
192  * return 0; if the DPLL did not enter bypass in the time allotted, or
193  * DPLL3 was passed in, or the DPLL does not support low-power bypass,
194  * return -EINVAL.
195  */
196 static int _omap3_noncore_dpll_bypass(struct clk *clk)
197 {
198         int r;
199         u8 ai;
200
201         if (clk == &dpll3_ck)
202                 return -EINVAL;
203
204         if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS)))
205                 return -EINVAL;
206
207         pr_debug("clock: configuring DPLL %s for low-power bypass\n",
208                  clk->name);
209
210         ai = omap3_dpll_autoidle_read(clk);
211
212         _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_BYPASS);
213
214         r = _omap3_wait_dpll_status(clk, 0);
215
216         if (ai)
217                 omap3_dpll_allow_idle(clk);
218         else
219                 omap3_dpll_deny_idle(clk);
220
221         return r;
222 }
223
224 /*
225  * _omap3_noncore_dpll_stop - instruct a DPLL to stop
226  * @clk: pointer to a DPLL struct clk
227  *
228  * Instructs a non-CORE DPLL to enter low-power stop. Will save and
229  * restore the DPLL's autoidle state across the stop, per the CDP
230  * code.  If DPLL3 was passed in, or the DPLL does not support
231  * low-power stop, return -EINVAL; otherwise, return 0.
232  */
233 static int _omap3_noncore_dpll_stop(struct clk *clk)
234 {
235         u8 ai;
236
237         if (clk == &dpll3_ck)
238                 return -EINVAL;
239
240         if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_STOP)))
241                 return -EINVAL;
242
243         pr_debug("clock: stopping DPLL %s\n", clk->name);
244
245         ai = omap3_dpll_autoidle_read(clk);
246
247         _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_STOP);
248
249         if (ai)
250                 omap3_dpll_allow_idle(clk);
251         else
252                 omap3_dpll_deny_idle(clk);
253
254         return 0;
255 }
256
257 /**
258  * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
259  * @clk: pointer to a DPLL struct clk
260  *
261  * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
262  * The choice of modes depends on the DPLL's programmed rate: if it is
263  * the same as the DPLL's parent clock, it will enter bypass;
264  * otherwise, it will enter lock.  This code will wait for the DPLL to
265  * indicate readiness before returning, unless the DPLL takes too long
266  * to enter the target state.  Intended to be used as the struct clk's
267  * enable function.  If DPLL3 was passed in, or the DPLL does not
268  * support low-power stop, or if the DPLL took too long to enter
269  * bypass or lock, return -EINVAL; otherwise, return 0.
270  */
271 static int omap3_noncore_dpll_enable(struct clk *clk)
272 {
273         int r;
274         struct dpll_data *dd;
275         u32 rate;
276
277         if (clk == &dpll3_ck)
278                 return -EINVAL;
279
280         dd = clk->dpll_data;
281         if (!dd)
282                 return -EINVAL;
283
284         rate = omap2_get_dpll_rate(clk);
285
286         if (dd->bypass_clk->rate == rate)
287                 r = _omap3_noncore_dpll_bypass(clk);
288         else
289                 r = _omap3_noncore_dpll_lock(clk);
290
291         if (!r)
292                 clk->rate = omap2_get_dpll_rate(clk);
293
294         return r;
295 }
296
297 /**
298  * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
299  * @clk: pointer to a DPLL struct clk
300  *
301  * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
302  * The choice of modes depends on the DPLL's programmed rate: if it is
303  * the same as the DPLL's parent clock, it will enter bypass;
304  * otherwise, it will enter lock.  This code will wait for the DPLL to
305  * indicate readiness before returning, unless the DPLL takes too long
306  * to enter the target state.  Intended to be used as the struct clk's
307  * enable function.  If DPLL3 was passed in, or the DPLL does not
308  * support low-power stop, or if the DPLL took too long to enter
309  * bypass or lock, return -EINVAL; otherwise, return 0.
310  */
311 static void omap3_noncore_dpll_disable(struct clk *clk)
312 {
313         if (clk == &dpll3_ck)
314                 return;
315
316         _omap3_noncore_dpll_stop(clk);
317 }
318
319
320 /* Non-CORE DPLL rate set code */
321
322 /*
323  * omap3_noncore_dpll_program - set non-core DPLL M,N values directly
324  * @clk: struct clk * of DPLL to set
325  * @m: DPLL multiplier to set
326  * @n: DPLL divider to set
327  * @freqsel: FREQSEL value to set
328  *
329  * Program the DPLL with the supplied M, N values, and wait for the DPLL to
330  * lock..  Returns -EINVAL upon error, or 0 upon success.
331  */
332 static int omap3_noncore_dpll_program(struct clk *clk, u16 m, u8 n, u16 freqsel)
333 {
334         struct dpll_data *dd;
335         u32 v;
336
337         if (!clk)
338                 return -EINVAL;
339
340         dd = clk->dpll_data;
341         if (!dd)
342                 return -EINVAL;
343
344         /*
345          * According to the 12-5 CDP code from TI, "Limitation 2.5"
346          * on 3430ES1 prevents us from changing DPLL multipliers or dividers
347          * on DPLL4.
348          */
349         if (system_rev == OMAP3430_REV_ES1_0 &&
350             !strcmp("dpll4_ck", clk->name)) {
351                 printk(KERN_ERR "clock: DPLL4 cannot change rate due to "
352                        "silicon 'Limitation 2.5' on 3430ES1.\n");
353                 return -EINVAL;
354         }
355
356         /* 3430 ES2 TRM: 4.7.6.9 DPLL Programming Sequence */
357         _omap3_noncore_dpll_bypass(clk);
358
359         /* Set jitter correction */
360         v = cm_read_mod_reg(clk->prcm_mod, dd->control_reg);
361         v &= ~dd->freqsel_mask;
362         v |= freqsel << __ffs(dd->freqsel_mask);
363         cm_write_mod_reg(v, clk->prcm_mod, dd->control_reg);
364
365         /* Set DPLL multiplier, divider */
366         v = cm_read_mod_reg(clk->prcm_mod, dd->mult_div1_reg);
367         v &= ~(dd->mult_mask | dd->div1_mask);
368         v |= m << __ffs(dd->mult_mask);
369         v |= (n - 1) << __ffs(dd->div1_mask);
370         cm_write_mod_reg(v, clk->prcm_mod, dd->mult_div1_reg);
371
372         /* We let the clock framework set the other output dividers later */
373
374         /* REVISIT: Set ramp-up delay? */
375
376         _omap3_noncore_dpll_lock(clk);
377
378         return 0;
379 }
380
381 /**
382  * omap3_noncore_dpll_set_rate - set non-core DPLL rate
383  * @clk: struct clk * of DPLL to set
384  * @rate: rounded target rate
385  *
386  * Set the DPLL CLKOUT to the target rate.  If the DPLL can enter
387  * low-power bypass, and the target rate is the bypass source clock
388  * rate, then configure the DPLL for bypass.  Otherwise, round the
389  * target rate if it hasn't been done already, then program and lock
390  * the DPLL.  Returns -EINVAL upon error, or 0 upon success.
391  */
392 static int omap3_noncore_dpll_set_rate(struct clk *clk, unsigned long rate)
393 {
394         u16 freqsel;
395         struct dpll_data *dd;
396         int ret;
397
398         if (!clk || !rate)
399                 return -EINVAL;
400
401         dd = clk->dpll_data;
402         if (!dd)
403                 return -EINVAL;
404
405         if (rate == omap2_get_dpll_rate(clk))
406                 return 0;
407
408         if (dd->bypass_clk->rate == rate &&
409             (clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS))) {
410
411                 pr_debug("clock: %s: set rate: entering bypass.\n", clk->name);
412
413                 ret = _omap3_noncore_dpll_bypass(clk);
414                 if (!ret)
415                         clk->rate = rate;
416
417         } else {
418
419                 if (dd->last_rounded_rate != rate)
420                         omap2_dpll_round_rate(clk, rate);
421
422                 if (dd->last_rounded_rate == 0)
423                         return -EINVAL;
424
425                 freqsel = _omap3_dpll_compute_freqsel(clk, dd->last_rounded_n);
426                 if (!freqsel)
427                         WARN_ON(1);
428
429                 pr_debug("clock: %s: set rate: locking rate to %lu.\n",
430                          clk->name, rate);
431
432                 ret = omap3_noncore_dpll_program(clk, dd->last_rounded_m,
433                                                  dd->last_rounded_n, freqsel);
434
435                 if (!ret)
436                         clk->rate = rate;
437
438         }
439
440         omap3_dpll_recalc(clk);
441
442         return 0;
443 }
444
445
446 /*
447  * CORE DPLL (DPLL3) rate programming functions
448  *
449  * These call into SRAM code to do the actual CM writes, since the SDRAM
450  * is clocked from DPLL3.
451  */
452
453 /**
454  * omap3_core_dpll_m2_set_rate - set CORE DPLL M2 divider
455  * @clk: struct clk * of DPLL to set
456  * @rate: rounded target rate
457  *
458  * Program the DPLL M2 divider with the rounded target rate.  Returns
459  * -EINVAL upon error, or 0 upon success.
460  */
461 static int omap3_core_dpll_m2_set_rate(struct clk *clk, unsigned long rate)
462 {
463         u32 new_div = 0;
464         unsigned long validrate, sdrcrate;
465         struct omap_sdrc_params *sp;
466
467         if (!clk || !rate)
468                 return -EINVAL;
469
470         if (clk != &dpll3_m2_ck)
471                 return -EINVAL;
472
473         if (rate == clk->rate)
474                 return 0;
475
476         validrate = omap2_clksel_round_rate_div(clk, rate, &new_div);
477         if (validrate != rate)
478                 return -EINVAL;
479
480         sdrcrate = sdrc_ick.rate;
481         if (rate > clk->rate)
482                 sdrcrate <<= ((rate / clk->rate) - 1);
483         else
484                 sdrcrate >>= ((clk->rate / rate) - 1);
485
486         sp = omap2_sdrc_get_params(sdrcrate);
487         if (!sp)
488                 return -EINVAL;
489
490         pr_info("clock: changing CORE DPLL rate from %lu to %lu\n", clk->rate,
491                 validrate);
492         pr_info("clock: SDRC timing params used: %08x %08x %08x\n",
493                 sp->rfr_ctrl, sp->actim_ctrla, sp->actim_ctrlb);
494
495         /* REVISIT: SRAM code doesn't support other M2 divisors yet */
496         WARN_ON(new_div != 1 && new_div != 2);
497
498         /* REVISIT: Add SDRC_MR changing to this code also */
499         local_irq_disable();
500         omap3_configure_core_dpll(sp->rfr_ctrl, sp->actim_ctrla,
501                                   sp->actim_ctrlb, new_div);
502         local_irq_enable();
503
504         omap2_clksel_recalc(clk);
505
506         return 0;
507 }
508
509
510 /* DPLL autoidle read/set code */
511
512
513 /**
514  * omap3_dpll_autoidle_read - read a DPLL's autoidle bits
515  * @clk: struct clk * of the DPLL to read
516  *
517  * Return the DPLL's autoidle bits, shifted down to bit 0.  Returns
518  * -EINVAL if passed a null pointer or if the struct clk does not
519  * appear to refer to a DPLL.
520  */
521 static u32 omap3_dpll_autoidle_read(struct clk *clk)
522 {
523         const struct dpll_data *dd;
524         u32 v;
525
526         if (!clk || !clk->dpll_data)
527                 return -EINVAL;
528
529         dd = clk->dpll_data;
530
531         v = cm_read_mod_reg(clk->prcm_mod, dd->autoidle_reg);
532         v &= dd->autoidle_mask;
533         v >>= __ffs(dd->autoidle_mask);
534
535         return v;
536 }
537
538 /**
539  * omap3_dpll_allow_idle - enable DPLL autoidle bits
540  * @clk: struct clk * of the DPLL to operate on
541  *
542  * Enable DPLL automatic idle control.  This automatic idle mode
543  * switching takes effect only when the DPLL is locked, at least on
544  * OMAP3430.  The DPLL will enter low-power stop when its downstream
545  * clocks are gated.  No return value.
546  */
547 static void omap3_dpll_allow_idle(struct clk *clk)
548 {
549         const struct dpll_data *dd;
550         u32 v;
551
552         if (!clk || !clk->dpll_data)
553                 return;
554
555         dd = clk->dpll_data;
556
557         /*
558          * REVISIT: CORE DPLL can optionally enter low-power bypass
559          * by writing 0x5 instead of 0x1.  Add some mechanism to
560          * optionally enter this mode.
561          */
562         v = cm_read_mod_reg(clk->prcm_mod, dd->autoidle_reg);
563         v &= ~dd->autoidle_mask;
564         v |= DPLL_AUTOIDLE_LOW_POWER_STOP << __ffs(dd->autoidle_mask);
565         cm_write_mod_reg(v, clk->prcm_mod, dd->autoidle_reg);
566 }
567
568 /**
569  * omap3_dpll_deny_idle - prevent DPLL from automatically idling
570  * @clk: struct clk * of the DPLL to operate on
571  *
572  * Disable DPLL automatic idle control.  No return value.
573  */
574 static void omap3_dpll_deny_idle(struct clk *clk)
575 {
576         const struct dpll_data *dd;
577         u32 v;
578
579         if (!clk || !clk->dpll_data)
580                 return;
581
582         dd = clk->dpll_data;
583
584         v = cm_read_mod_reg(clk->prcm_mod, dd->autoidle_reg);
585         v &= ~dd->autoidle_mask;
586         v |= DPLL_AUTOIDLE_DISABLE << __ffs(dd->autoidle_mask);
587         cm_write_mod_reg(v, clk->prcm_mod, dd->autoidle_reg);
588 }
589
590 /* Clock control for DPLL outputs */
591
592 /**
593  * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
594  * @clk: DPLL output struct clk
595  *
596  * Using parent clock DPLL data, look up DPLL state.  If locked, set our
597  * rate to the dpll_clk * 2; otherwise, just use dpll_clk.
598  */
599 static void omap3_clkoutx2_recalc(struct clk *clk)
600 {
601         const struct dpll_data *dd;
602         u32 v;
603         struct clk *pclk;
604
605         /* Walk up the parents of clk, looking for a DPLL */
606         pclk = clk->parent;
607         while (pclk && !pclk->dpll_data)
608                 pclk = pclk->parent;
609
610         /* clk does not have a DPLL as a parent? */
611         WARN_ON(!pclk);
612
613         dd = pclk->dpll_data;
614
615         WARN_ON(!dd->idlest_reg || !dd->idlest_mask);
616
617         v = cm_read_mod_reg(pclk->prcm_mod, dd->idlest_reg) & dd->idlest_mask;
618         if (!v)
619                 clk->rate = clk->parent->rate;
620         else
621                 clk->rate = clk->parent->rate * 2;
622
623         if (clk->flags & RATE_PROPAGATES)
624                 propagate_rate(clk);
625 }
626
627 /* Common clock code */
628
629 /*
630  * As it is structured now, this will prevent an OMAP2/3 multiboot
631  * kernel from compiling.  This will need further attention.
632  */
633 #if defined(CONFIG_ARCH_OMAP3)
634
635 static struct clk_functions omap2_clk_functions = {
636         .clk_enable             = omap2_clk_enable,
637         .clk_disable            = omap2_clk_disable,
638         .clk_round_rate         = omap2_clk_round_rate,
639         .clk_set_rate           = omap2_clk_set_rate,
640         .clk_set_parent         = omap2_clk_set_parent,
641         .clk_disable_unused     = omap2_clk_disable_unused,
642 };
643
644 /*
645  * Set clocks for bypass mode for reboot to work.
646  */
647 void omap2_clk_prepare_for_reboot(void)
648 {
649         /* REVISIT: Not ready for 343x */
650 #if 0
651         u32 rate;
652
653         if (vclk == NULL || sclk == NULL)
654                 return;
655
656         rate = clk_get_rate(sclk);
657         clk_set_rate(vclk, rate);
658 #endif
659 }
660
661 /* REVISIT: Move this init stuff out into clock.c */
662
663 /*
664  * Switch the MPU rate if specified on cmdline.
665  * We cannot do this early until cmdline is parsed.
666  */
667 static int __init omap2_clk_arch_init(void)
668 {
669         if (!mpurate)
670                 return -EINVAL;
671
672         /* REVISIT: not yet ready for 343x */
673 #if 0
674         if (omap2_select_table_rate(&virt_prcm_set, mpurate))
675                 printk(KERN_ERR "Could not find matching MPU rate\n");
676 #endif
677
678         recalculate_root_clocks();
679
680         printk(KERN_INFO "Switched to new clocking rate (Crystal/DPLL3/MPU): "
681                "%ld.%01ld/%ld/%ld MHz\n",
682                (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
683                (core_ck.rate / 1000000), (dpll1_fck.rate / 1000000)) ;
684
685         return 0;
686 }
687 arch_initcall(omap2_clk_arch_init);
688
689 int __init omap2_clk_init(void)
690 {
691         /* struct prcm_config *prcm; */
692         struct clk **clkp;
693         /* u32 clkrate; */
694         u32 cpu_clkflg;
695
696         /* REVISIT: Ultimately this will be used for multiboot */
697 #if 0
698         if (cpu_is_omap242x()) {
699                 cpu_mask = RATE_IN_242X;
700                 cpu_clkflg = CLOCK_IN_OMAP242X;
701                 clkp = onchip_24xx_clks;
702         } else if (cpu_is_omap2430()) {
703                 cpu_mask = RATE_IN_243X;
704                 cpu_clkflg = CLOCK_IN_OMAP243X;
705                 clkp = onchip_24xx_clks;
706         }
707 #endif
708         if (cpu_is_omap34xx()) {
709                 cpu_mask = RATE_IN_343X;
710                 cpu_clkflg = CLOCK_IN_OMAP343X;
711                 clkp = onchip_34xx_clks;
712
713                 /*
714                  * Update this if there are further clock changes between ES2
715                  * and production parts
716                  */
717                 if (system_rev == OMAP3430_REV_ES1_0) {
718                         /* No 3430ES1-only rates exist, so no RATE_IN_3430ES1 */
719                         cpu_clkflg |= CLOCK_IN_OMAP3430ES1;
720                 } else {
721                         cpu_mask |= RATE_IN_3430ES2;
722                         cpu_clkflg |= CLOCK_IN_OMAP3430ES2;
723                 }
724         }
725
726         clk_init(&omap2_clk_functions);
727
728         for (clkp = onchip_34xx_clks;
729              clkp < onchip_34xx_clks + ARRAY_SIZE(onchip_34xx_clks);
730              clkp++) {
731                 if ((*clkp)->flags & cpu_clkflg) {
732                         clk_register(*clkp);
733                         omap2_init_clk_clkdm(*clkp);
734                 }
735         }
736
737         /* REVISIT: Not yet ready for OMAP3 */
738 #if 0
739         /* Check the MPU rate set by bootloader */
740         clkrate = omap2_get_dpll_rate_24xx(&dpll_ck);
741         for (prcm = rate_table; prcm->mpu_speed; prcm++) {
742                 if (!(prcm->flags & cpu_mask))
743                         continue;
744                 if (prcm->xtal_speed != sys_ck.rate)
745                         continue;
746                 if (prcm->dpll_speed <= clkrate)
747                          break;
748         }
749         curr_prcm_set = prcm;
750 #endif
751
752         recalculate_root_clocks();
753
754         printk(KERN_INFO "Clocking rate (Crystal/DPLL/ARM core): "
755                "%ld.%01ld/%ld/%ld MHz\n",
756                (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
757                (core_ck.rate / 1000000), (arm_fck.rate / 1000000));
758
759         /*
760          * Only enable those clocks we will need, let the drivers
761          * enable other clocks as necessary
762          */
763         clk_enable_init_clocks();
764
765         /* Avoid sleeping during omap2_clk_prepare_for_reboot() */
766         /* REVISIT: not yet ready for 343x */
767 #if 0
768         vclk = clk_get(NULL, "virt_prcm_set");
769         sclk = clk_get(NULL, "sys_ck");
770 #endif
771         return 0;
772 }
773
774 #endif