OMAP2/3 clock: fix sprz319 erratum 2.1
[pandora-kernel.git] / arch / arm / mach-omap2 / clock3xxx.c
1 /*
2  * OMAP3-specific clock framework functions
3  *
4  * Copyright (C) 2007-2008 Texas Instruments, Inc.
5  * Copyright (C) 2007-2010 Nokia Corporation
6  *
7  * Paul Walmsley
8  * 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/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/clk.h>
22 #include <linux/io.h>
23
24 #include <plat/clock.h>
25
26 #include "clock.h"
27 #include "clock3xxx.h"
28 #include "prm2xxx_3xxx.h"
29 #include "prm-regbits-34xx.h"
30 #include "cm2xxx_3xxx.h"
31 #include "cm-regbits-34xx.h"
32
33 /*
34  * DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks
35  * that are sourced by DPLL5, and both of these require this clock
36  * to be at 120 MHz for proper operation.
37  */
38 #define DPLL5_FREQ_FOR_USBHOST          120000000
39
40 /* needed by omap3_core_dpll_m2_set_rate() */
41 struct clk *sdrc_ick_p, *arm_fck_p;
42
43 struct dpll_settings {
44         int rate, m, n, f;
45 };
46
47
48 static int omap3_dpll5_apply_erratum21(struct clk *clk, struct clk *dpll5_m2)
49 {
50         struct clk *sys_clk;
51         int i, rv;
52         static const struct dpll_settings precomputed[] = {
53                 /* From DM3730 errata (sprz319e), table 36
54                 * N+1 is because the values in the table are register values;
55                 * dpll_program() will subtract one from the N we give it,
56                 * so ...
57                 */
58                 { 13000000, 443, 5+1, 8 },
59                 { 26000000, 443, 11+1, 8 }
60         };
61
62         sys_clk = clk_get(NULL, "sys_ck");
63
64         for (i = 0 ; i < (sizeof(precomputed)/sizeof(struct dpll_settings)) ;
65                 ++i) {
66                 const struct dpll_settings *d = &precomputed[i];
67                 if (sys_clk->rate == d->rate) {
68                         rv =  omap3_noncore_dpll_program(clk, d->m , d->n, 0);
69                         if (rv)
70                                 return 1;
71                         rv =  omap2_clksel_force_divisor(dpll5_m2 , d->f);
72                         return 1;
73                 }
74         }
75         return 0;
76 }
77
78 int omap3_dpll5_set_rate(struct clk *clk, unsigned long rate)
79 {
80         struct clk *dpll5_m2;
81         int rv;
82         dpll5_m2 = clk_get(NULL, "dpll5_m2_ck");
83
84         if (cpu_is_omap3630() && rate == DPLL5_FREQ_FOR_USBHOST &&
85                 omap3_dpll5_apply_erratum21(clk, dpll5_m2)) {
86                 return 1;
87         }
88         rv = omap3_noncore_dpll_set_rate(clk, rate);
89         if (rv)
90                 goto out;
91         rv = clk_set_rate(dpll5_m2, rate);
92
93 out:
94         return rv;
95 }
96
97 int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate)
98 {
99         /*
100          * According to the 12-5 CDP code from TI, "Limitation 2.5"
101          * on 3430ES1 prevents us from changing DPLL multipliers or dividers
102          * on DPLL4.
103          */
104         if (omap_rev() == OMAP3430_REV_ES1_0) {
105                 pr_err("clock: DPLL4 cannot change rate due to "
106                        "silicon 'Limitation 2.5' on 3430ES1.\n");
107                 return -EINVAL;
108         }
109
110         return omap3_noncore_dpll_set_rate(clk, rate);
111 }
112
113 void __init omap3_clk_lock_dpll5(void)
114 {
115         struct clk *dpll5_clk;
116
117         dpll5_clk = clk_get(NULL, "dpll5_ck");
118         clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST);
119
120         /* dpll5_m2_ck is now (grottily!) handled by dpll5_clk's set routine,
121          * to cope with an erratum on DM3730
122          */
123
124         return;
125 }
126
127 /* Common clock code */
128
129 /*
130  * Switch the MPU rate if specified on cmdline.  We cannot do this
131  * early until cmdline is parsed.  XXX This should be removed from the
132  * clock code and handled by the OPP layer code in the near future.
133  */
134 static int __init omap3xxx_clk_arch_init(void)
135 {
136         int ret;
137
138         if (!cpu_is_omap34xx())
139                 return 0;
140
141         ret = omap2_clk_switch_mpurate_at_boot("dpll1_ck");
142         if (!ret)
143                 omap2_clk_print_new_rates("osc_sys_ck", "core_ck", "arm_fck");
144
145         return ret;
146 }
147
148 arch_initcall(omap3xxx_clk_arch_init);
149
150