diff options
Diffstat (limited to 'arch/arm/mach-omap2/clock34xx.c')
-rw-r--r-- | arch/arm/mach-omap2/clock34xx.c | 261 |
1 files changed, 17 insertions, 244 deletions
diff --git a/arch/arm/mach-omap2/clock34xx.c b/arch/arm/mach-omap2/clock34xx.c index d4217b93e10b..6febd5f11e85 100644 --- a/arch/arm/mach-omap2/clock34xx.c +++ b/arch/arm/mach-omap2/clock34xx.c | |||
@@ -2,13 +2,14 @@ | |||
2 | * OMAP3-specific clock framework functions | 2 | * OMAP3-specific clock framework functions |
3 | * | 3 | * |
4 | * Copyright (C) 2007-2008 Texas Instruments, Inc. | 4 | * Copyright (C) 2007-2008 Texas Instruments, Inc. |
5 | * Copyright (C) 2007-2009 Nokia Corporation | 5 | * Copyright (C) 2007-2010 Nokia Corporation |
6 | * | 6 | * |
7 | * Written by Paul Walmsley | 7 | * Paul Walmsley |
8 | * Testing and integration fixes by Jouni Högander | 8 | * Jouni Högander |
9 | * | 9 | * |
10 | * Parts of this code are based on code written by | 10 | * Parts of this code are based on code written by |
11 | * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu | 11 | * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu, |
12 | * Russell King | ||
12 | * | 13 | * |
13 | * This program is free software; you can redistribute it and/or modify | 14 | * 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 | * it under the terms of the GNU General Public License version 2 as |
@@ -16,49 +17,23 @@ | |||
16 | */ | 17 | */ |
17 | #undef DEBUG | 18 | #undef DEBUG |
18 | 19 | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/kernel.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> | 21 | #include <linux/clk.h> |
26 | #include <linux/io.h> | 22 | #include <linux/io.h> |
27 | #include <linux/limits.h> | ||
28 | #include <linux/bitops.h> | ||
29 | 23 | ||
30 | #include <plat/cpu.h> | ||
31 | #include <plat/clock.h> | 24 | #include <plat/clock.h> |
32 | #include <plat/sram.h> | ||
33 | #include <plat/sdrc.h> | ||
34 | #include <asm/div64.h> | ||
35 | #include <asm/clkdev.h> | ||
36 | 25 | ||
37 | #include "clock.h" | 26 | #include "clock.h" |
38 | #include "clock34xx.h" | 27 | #include "clock34xx.h" |
39 | #include "sdrc.h" | ||
40 | #include "prm.h" | ||
41 | #include "prm-regbits-34xx.h" | ||
42 | #include "cm.h" | 28 | #include "cm.h" |
43 | #include "cm-regbits-34xx.h" | 29 | #include "cm-regbits-34xx.h" |
44 | 30 | ||
45 | #define CYCLES_PER_MHZ 1000000 | ||
46 | |||
47 | /* | ||
48 | * DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks | ||
49 | * that are sourced by DPLL5, and both of these require this clock | ||
50 | * to be at 120 MHz for proper operation. | ||
51 | */ | ||
52 | #define DPLL5_FREQ_FOR_USBHOST 120000000 | ||
53 | |||
54 | /* needed by omap3_core_dpll_m2_set_rate() */ | ||
55 | struct clk *sdrc_ick_p, *arm_fck_p; | ||
56 | |||
57 | /** | 31 | /** |
58 | * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI | 32 | * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI |
59 | * @clk: struct clk * being enabled | 33 | * @clk: struct clk * being enabled |
60 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into | 34 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
61 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into | 35 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
36 | * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator | ||
62 | * | 37 | * |
63 | * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift | 38 | * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift |
64 | * from the CM_{I,F}CLKEN bit. Pass back the correct info via | 39 | * from the CM_{I,F}CLKEN bit. Pass back the correct info via |
@@ -66,13 +41,15 @@ struct clk *sdrc_ick_p, *arm_fck_p; | |||
66 | */ | 41 | */ |
67 | static void omap3430es2_clk_ssi_find_idlest(struct clk *clk, | 42 | static void omap3430es2_clk_ssi_find_idlest(struct clk *clk, |
68 | void __iomem **idlest_reg, | 43 | void __iomem **idlest_reg, |
69 | u8 *idlest_bit) | 44 | u8 *idlest_bit, |
45 | u8 *idlest_val) | ||
70 | { | 46 | { |
71 | u32 r; | 47 | u32 r; |
72 | 48 | ||
73 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); | 49 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
74 | *idlest_reg = (__force void __iomem *)r; | 50 | *idlest_reg = (__force void __iomem *)r; |
75 | *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT; | 51 | *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT; |
52 | *idlest_val = OMAP34XX_CM_IDLEST_VAL; | ||
76 | } | 53 | } |
77 | 54 | ||
78 | const struct clkops clkops_omap3430es2_ssi_wait = { | 55 | const struct clkops clkops_omap3430es2_ssi_wait = { |
@@ -87,6 +64,7 @@ const struct clkops clkops_omap3430es2_ssi_wait = { | |||
87 | * @clk: struct clk * being enabled | 64 | * @clk: struct clk * being enabled |
88 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into | 65 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
89 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into | 66 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
67 | * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator | ||
90 | * | 68 | * |
91 | * Some OMAP modules on OMAP3 ES2+ chips have both initiator and | 69 | * Some OMAP modules on OMAP3 ES2+ chips have both initiator and |
92 | * target IDLEST bits. For our purposes, we are concerned with the | 70 | * target IDLEST bits. For our purposes, we are concerned with the |
@@ -97,7 +75,8 @@ const struct clkops clkops_omap3430es2_ssi_wait = { | |||
97 | */ | 75 | */ |
98 | static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk, | 76 | static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk, |
99 | void __iomem **idlest_reg, | 77 | void __iomem **idlest_reg, |
100 | u8 *idlest_bit) | 78 | u8 *idlest_bit, |
79 | u8 *idlest_val) | ||
101 | { | 80 | { |
102 | u32 r; | 81 | u32 r; |
103 | 82 | ||
@@ -105,6 +84,7 @@ static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk, | |||
105 | *idlest_reg = (__force void __iomem *)r; | 84 | *idlest_reg = (__force void __iomem *)r; |
106 | /* USBHOST_IDLE has same shift */ | 85 | /* USBHOST_IDLE has same shift */ |
107 | *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT; | 86 | *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT; |
87 | *idlest_val = OMAP34XX_CM_IDLEST_VAL; | ||
108 | } | 88 | } |
109 | 89 | ||
110 | const struct clkops clkops_omap3430es2_dss_usbhost_wait = { | 90 | const struct clkops clkops_omap3430es2_dss_usbhost_wait = { |
@@ -119,6 +99,7 @@ const struct clkops clkops_omap3430es2_dss_usbhost_wait = { | |||
119 | * @clk: struct clk * being enabled | 99 | * @clk: struct clk * being enabled |
120 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into | 100 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
121 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into | 101 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
102 | * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator | ||
122 | * | 103 | * |
123 | * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different | 104 | * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different |
124 | * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via | 105 | * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via |
@@ -126,13 +107,15 @@ const struct clkops clkops_omap3430es2_dss_usbhost_wait = { | |||
126 | */ | 107 | */ |
127 | static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk, | 108 | static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk, |
128 | void __iomem **idlest_reg, | 109 | void __iomem **idlest_reg, |
129 | u8 *idlest_bit) | 110 | u8 *idlest_bit, |
111 | u8 *idlest_val) | ||
130 | { | 112 | { |
131 | u32 r; | 113 | u32 r; |
132 | 114 | ||
133 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); | 115 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
134 | *idlest_reg = (__force void __iomem *)r; | 116 | *idlest_reg = (__force void __iomem *)r; |
135 | *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT; | 117 | *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT; |
118 | *idlest_val = OMAP34XX_CM_IDLEST_VAL; | ||
136 | } | 119 | } |
137 | 120 | ||
138 | const struct clkops clkops_omap3430es2_hsotgusb_wait = { | 121 | const struct clkops clkops_omap3430es2_hsotgusb_wait = { |
@@ -141,213 +124,3 @@ const struct clkops clkops_omap3430es2_hsotgusb_wait = { | |||
141 | .find_idlest = omap3430es2_clk_hsotgusb_find_idlest, | 124 | .find_idlest = omap3430es2_clk_hsotgusb_find_idlest, |
142 | .find_companion = omap2_clk_dflt_find_companion, | 125 | .find_companion = omap2_clk_dflt_find_companion, |
143 | }; | 126 | }; |
144 | |||
145 | const struct clkops clkops_noncore_dpll_ops = { | ||
146 | .enable = omap3_noncore_dpll_enable, | ||
147 | .disable = omap3_noncore_dpll_disable, | ||
148 | }; | ||
149 | |||
150 | int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate) | ||
151 | { | ||
152 | /* | ||
153 | * According to the 12-5 CDP code from TI, "Limitation 2.5" | ||
154 | * on 3430ES1 prevents us from changing DPLL multipliers or dividers | ||
155 | * on DPLL4. | ||
156 | */ | ||
157 | if (omap_rev() == OMAP3430_REV_ES1_0) { | ||
158 | printk(KERN_ERR "clock: DPLL4 cannot change rate due to " | ||
159 | "silicon 'Limitation 2.5' on 3430ES1.\n"); | ||
160 | return -EINVAL; | ||
161 | } | ||
162 | return omap3_noncore_dpll_set_rate(clk, rate); | ||
163 | } | ||
164 | |||
165 | |||
166 | /* | ||
167 | * CORE DPLL (DPLL3) rate programming functions | ||
168 | * | ||
169 | * These call into SRAM code to do the actual CM writes, since the SDRAM | ||
170 | * is clocked from DPLL3. | ||
171 | */ | ||
172 | |||
173 | /** | ||
174 | * omap3_core_dpll_m2_set_rate - set CORE DPLL M2 divider | ||
175 | * @clk: struct clk * of DPLL to set | ||
176 | * @rate: rounded target rate | ||
177 | * | ||
178 | * Program the DPLL M2 divider with the rounded target rate. Returns | ||
179 | * -EINVAL upon error, or 0 upon success. | ||
180 | */ | ||
181 | int omap3_core_dpll_m2_set_rate(struct clk *clk, unsigned long rate) | ||
182 | { | ||
183 | u32 new_div = 0; | ||
184 | u32 unlock_dll = 0; | ||
185 | u32 c; | ||
186 | unsigned long validrate, sdrcrate, _mpurate; | ||
187 | struct omap_sdrc_params *sdrc_cs0; | ||
188 | struct omap_sdrc_params *sdrc_cs1; | ||
189 | int ret; | ||
190 | |||
191 | if (!clk || !rate) | ||
192 | return -EINVAL; | ||
193 | |||
194 | validrate = omap2_clksel_round_rate_div(clk, rate, &new_div); | ||
195 | if (validrate != rate) | ||
196 | return -EINVAL; | ||
197 | |||
198 | sdrcrate = sdrc_ick_p->rate; | ||
199 | if (rate > clk->rate) | ||
200 | sdrcrate <<= ((rate / clk->rate) >> 1); | ||
201 | else | ||
202 | sdrcrate >>= ((clk->rate / rate) >> 1); | ||
203 | |||
204 | ret = omap2_sdrc_get_params(sdrcrate, &sdrc_cs0, &sdrc_cs1); | ||
205 | if (ret) | ||
206 | return -EINVAL; | ||
207 | |||
208 | if (sdrcrate < MIN_SDRC_DLL_LOCK_FREQ) { | ||
209 | pr_debug("clock: will unlock SDRC DLL\n"); | ||
210 | unlock_dll = 1; | ||
211 | } | ||
212 | |||
213 | /* | ||
214 | * XXX This only needs to be done when the CPU frequency changes | ||
215 | */ | ||
216 | _mpurate = arm_fck_p->rate / CYCLES_PER_MHZ; | ||
217 | c = (_mpurate << SDRC_MPURATE_SCALE) >> SDRC_MPURATE_BASE_SHIFT; | ||
218 | c += 1; /* for safety */ | ||
219 | c *= SDRC_MPURATE_LOOPS; | ||
220 | c >>= SDRC_MPURATE_SCALE; | ||
221 | if (c == 0) | ||
222 | c = 1; | ||
223 | |||
224 | pr_debug("clock: changing CORE DPLL rate from %lu to %lu\n", clk->rate, | ||
225 | validrate); | ||
226 | pr_debug("clock: SDRC CS0 timing params used:" | ||
227 | " RFR %08x CTRLA %08x CTRLB %08x MR %08x\n", | ||
228 | sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla, | ||
229 | sdrc_cs0->actim_ctrlb, sdrc_cs0->mr); | ||
230 | if (sdrc_cs1) | ||
231 | pr_debug("clock: SDRC CS1 timing params used: " | ||
232 | " RFR %08x CTRLA %08x CTRLB %08x MR %08x\n", | ||
233 | sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla, | ||
234 | sdrc_cs1->actim_ctrlb, sdrc_cs1->mr); | ||
235 | |||
236 | if (sdrc_cs1) | ||
237 | omap3_configure_core_dpll( | ||
238 | new_div, unlock_dll, c, rate > clk->rate, | ||
239 | sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla, | ||
240 | sdrc_cs0->actim_ctrlb, sdrc_cs0->mr, | ||
241 | sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla, | ||
242 | sdrc_cs1->actim_ctrlb, sdrc_cs1->mr); | ||
243 | else | ||
244 | omap3_configure_core_dpll( | ||
245 | new_div, unlock_dll, c, rate > clk->rate, | ||
246 | sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla, | ||
247 | sdrc_cs0->actim_ctrlb, sdrc_cs0->mr, | ||
248 | 0, 0, 0, 0); | ||
249 | |||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | /* Common clock code */ | ||
254 | |||
255 | /* | ||
256 | * As it is structured now, this will prevent an OMAP2/3 multiboot | ||
257 | * kernel from compiling. This will need further attention. | ||
258 | */ | ||
259 | #if defined(CONFIG_ARCH_OMAP3) | ||
260 | |||
261 | struct clk_functions omap2_clk_functions = { | ||
262 | .clk_enable = omap2_clk_enable, | ||
263 | .clk_disable = omap2_clk_disable, | ||
264 | .clk_round_rate = omap2_clk_round_rate, | ||
265 | .clk_set_rate = omap2_clk_set_rate, | ||
266 | .clk_set_parent = omap2_clk_set_parent, | ||
267 | .clk_disable_unused = omap2_clk_disable_unused, | ||
268 | }; | ||
269 | |||
270 | /* | ||
271 | * Set clocks for bypass mode for reboot to work. | ||
272 | */ | ||
273 | void omap2_clk_prepare_for_reboot(void) | ||
274 | { | ||
275 | /* REVISIT: Not ready for 343x */ | ||
276 | #if 0 | ||
277 | u32 rate; | ||
278 | |||
279 | if (vclk == NULL || sclk == NULL) | ||
280 | return; | ||
281 | |||
282 | rate = clk_get_rate(sclk); | ||
283 | clk_set_rate(vclk, rate); | ||
284 | #endif | ||
285 | } | ||
286 | |||
287 | void omap3_clk_lock_dpll5(void) | ||
288 | { | ||
289 | struct clk *dpll5_clk; | ||
290 | struct clk *dpll5_m2_clk; | ||
291 | |||
292 | dpll5_clk = clk_get(NULL, "dpll5_ck"); | ||
293 | clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST); | ||
294 | clk_enable(dpll5_clk); | ||
295 | |||
296 | /* Enable autoidle to allow it to enter low power bypass */ | ||
297 | omap3_dpll_allow_idle(dpll5_clk); | ||
298 | |||
299 | /* Program dpll5_m2_clk divider for no division */ | ||
300 | dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck"); | ||
301 | clk_enable(dpll5_m2_clk); | ||
302 | clk_set_rate(dpll5_m2_clk, DPLL5_FREQ_FOR_USBHOST); | ||
303 | |||
304 | clk_disable(dpll5_m2_clk); | ||
305 | clk_disable(dpll5_clk); | ||
306 | return; | ||
307 | } | ||
308 | |||
309 | /* REVISIT: Move this init stuff out into clock.c */ | ||
310 | |||
311 | /* | ||
312 | * Switch the MPU rate if specified on cmdline. | ||
313 | * We cannot do this early until cmdline is parsed. | ||
314 | */ | ||
315 | static int __init omap2_clk_arch_init(void) | ||
316 | { | ||
317 | struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck; | ||
318 | unsigned long osc_sys_rate; | ||
319 | |||
320 | if (!mpurate) | ||
321 | return -EINVAL; | ||
322 | |||
323 | /* XXX test these for success */ | ||
324 | dpll1_ck = clk_get(NULL, "dpll1_ck"); | ||
325 | arm_fck = clk_get(NULL, "arm_fck"); | ||
326 | core_ck = clk_get(NULL, "core_ck"); | ||
327 | osc_sys_ck = clk_get(NULL, "osc_sys_ck"); | ||
328 | |||
329 | /* REVISIT: not yet ready for 343x */ | ||
330 | if (clk_set_rate(dpll1_ck, mpurate)) | ||
331 | printk(KERN_ERR "*** Unable to set MPU rate\n"); | ||
332 | |||
333 | recalculate_root_clocks(); | ||
334 | |||
335 | osc_sys_rate = clk_get_rate(osc_sys_ck); | ||
336 | |||
337 | pr_info("Switched to new clocking rate (Crystal/Core/MPU): " | ||
338 | "%ld.%01ld/%ld/%ld MHz\n", | ||
339 | (osc_sys_rate / 1000000), | ||
340 | ((osc_sys_rate / 100000) % 10), | ||
341 | (clk_get_rate(core_ck) / 1000000), | ||
342 | (clk_get_rate(arm_fck) / 1000000)); | ||
343 | |||
344 | calibrate_delay(); | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | arch_initcall(omap2_clk_arch_init); | ||
349 | |||
350 | |||
351 | #endif | ||
352 | |||
353 | |||