2 * OMAP3-specific clock framework functions
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
5 * Copyright (C) 2007-2010 Nokia Corporation
10 * Parts of this code are based on code written by
11 * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
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.
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/delay.h>
22 #include <linux/clk.h>
24 #include <linux/err.h>
27 #include <plat/clock.h>
30 #include "clock34xx.h"
32 #include "prm-regbits-34xx.h"
34 #include "cm-regbits-34xx.h"
37 * DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks
38 * that are sourced by DPLL5, and both of these require this clock
39 * to be at 120 MHz for proper operation.
41 #define DPLL5_FREQ_FOR_USBHOST 120000000
44 * In AM35xx IPSS, the {ICK,FCK} enable bits for modules are exported
45 * in the same register at a bit offset of 0x8. The EN_ACK for ICK is
46 * at an offset of 4 from ICK enable bit.
48 #define AM35XX_IPSS_ICK_MASK 0xF
49 #define AM35XX_IPSS_ICK_EN_ACK_OFFSET 0x4
50 #define AM35XX_IPSS_ICK_FCK_OFFSET 0x8
51 #define AM35XX_IPSS_CLK_IDLEST_VAL 0
53 /* needed by omap3_core_dpll_m2_set_rate() */
54 struct clk *sdrc_ick_p, *arm_fck_p;
57 * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI
58 * @clk: struct clk * being enabled
59 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
60 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
61 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
63 * 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
65 * @idlest_reg and @idlest_bit. No return value.
67 static void omap3430es2_clk_ssi_find_idlest(struct clk *clk,
68 void __iomem **idlest_reg,
74 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
75 *idlest_reg = (__force void __iomem *)r;
76 *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT;
77 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
80 const struct clkops clkops_omap3430es2_ssi_wait = {
81 .enable = omap2_dflt_clk_enable,
82 .disable = omap2_dflt_clk_disable,
83 .find_idlest = omap3430es2_clk_ssi_find_idlest,
84 .find_companion = omap2_clk_dflt_find_companion,
88 * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST
89 * @clk: struct clk * being enabled
90 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
91 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
92 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
94 * Some OMAP modules on OMAP3 ES2+ chips have both initiator and
95 * target IDLEST bits. For our purposes, we are concerned with the
96 * target IDLEST bits, which exist at a different bit position than
97 * the *CLKEN bit position for these modules (DSS and USBHOST) (The
98 * default find_idlest code assumes that they are at the same
99 * position.) No return value.
101 static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk,
102 void __iomem **idlest_reg,
108 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
109 *idlest_reg = (__force void __iomem *)r;
110 /* USBHOST_IDLE has same shift */
111 *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT;
112 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
115 const struct clkops clkops_omap3430es2_dss_usbhost_wait = {
116 .enable = omap2_dflt_clk_enable,
117 .disable = omap2_dflt_clk_disable,
118 .find_idlest = omap3430es2_clk_dss_usbhost_find_idlest,
119 .find_companion = omap2_clk_dflt_find_companion,
123 * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB
124 * @clk: struct clk * being enabled
125 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
126 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
127 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
129 * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different
130 * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via
131 * @idlest_reg and @idlest_bit. No return value.
133 static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk,
134 void __iomem **idlest_reg,
140 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
141 *idlest_reg = (__force void __iomem *)r;
142 *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT;
143 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
146 const struct clkops clkops_omap3430es2_hsotgusb_wait = {
147 .enable = omap2_dflt_clk_enable,
148 .disable = omap2_dflt_clk_disable,
149 .find_idlest = omap3430es2_clk_hsotgusb_find_idlest,
150 .find_companion = omap2_clk_dflt_find_companion,
154 * omap36xx_pwrdn_clk_enable_with_hsdiv_restore - enable clocks suffering
155 * from HSDivider PWRDN problem Implements Errata ID: i556.
156 * @clk: DPLL output struct clk
158 * 3630 only: dpll3_m3_ck, dpll4_m2_ck, dpll4_m3_ck, dpll4_m4_ck,
159 * dpll4_m5_ck & dpll4_m6_ck dividers gets loaded with reset
160 * valueafter their respective PWRDN bits are set. Any dummy write
161 * (Any other value different from the Read value) to the
162 * corresponding CM_CLKSEL register will refresh the dividers.
164 static int omap36xx_pwrdn_clk_enable_with_hsdiv_restore(struct clk *clk)
166 u32 dummy_v, orig_v, clksel_shift;
169 /* Clear PWRDN bit of HSDIVIDER */
170 ret = omap2_dflt_clk_enable(clk);
172 /* Restore the dividers */
174 clksel_shift = __ffs(clk->parent->clksel_mask);
175 orig_v = __raw_readl(clk->parent->clksel_reg);
178 /* Write any other value different from the Read value */
179 dummy_v ^= (1 << clksel_shift);
180 __raw_writel(dummy_v, clk->parent->clksel_reg);
182 /* Write the original divider */
183 __raw_writel(orig_v, clk->parent->clksel_reg);
189 const struct clkops clkops_omap36xx_pwrdn_with_hsdiv_wait_restore = {
190 .enable = omap36xx_pwrdn_clk_enable_with_hsdiv_restore,
191 .disable = omap2_dflt_clk_disable,
192 .find_companion = omap2_clk_dflt_find_companion,
193 .find_idlest = omap2_clk_dflt_find_idlest,
196 const struct clkops omap3_clkops_noncore_dpll_ops = {
197 .enable = omap3_noncore_dpll_enable,
198 .disable = omap3_noncore_dpll_disable,
202 * am35xx_clk_find_idlest - return clock ACK info for AM35XX IPSS
203 * @clk: struct clk * being enabled
204 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
205 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
206 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
208 * The interface clocks on AM35xx IPSS reflects the clock idle status
209 * in the enable register itsel at a bit offset of 4 from the enable
210 * bit. A value of 1 indicates that clock is enabled.
212 static void am35xx_clk_find_idlest(struct clk *clk,
213 void __iomem **idlest_reg,
217 *idlest_reg = (__force void __iomem *)(clk->enable_reg);
218 *idlest_bit = clk->enable_bit + AM35XX_IPSS_ICK_EN_ACK_OFFSET;
219 *idlest_val = AM35XX_IPSS_CLK_IDLEST_VAL;
223 * am35xx_clk_find_companion - find companion clock to @clk
224 * @clk: struct clk * to find the companion clock of
225 * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in
226 * @other_bit: u8 ** to return the companion clock bit shift in
228 * Some clocks don't have companion clocks. For example, modules with
229 * only an interface clock (such as HECC) don't have a companion
230 * clock. Right now, this code relies on the hardware exporting a bit
231 * in the correct companion register that indicates that the
232 * nonexistent 'companion clock' is active. Future patches will
233 * associate this type of code with per-module data structures to
234 * avoid this issue, and remove the casts. No return value.
236 static void am35xx_clk_find_companion(struct clk *clk, void __iomem **other_reg,
239 *other_reg = (__force void __iomem *)(clk->enable_reg);
240 if (clk->enable_bit & AM35XX_IPSS_ICK_MASK)
241 *other_bit = clk->enable_bit + AM35XX_IPSS_ICK_FCK_OFFSET;
243 *other_bit = clk->enable_bit - AM35XX_IPSS_ICK_FCK_OFFSET;
246 const struct clkops clkops_am35xx_ipss_module_wait = {
247 .enable = omap2_dflt_clk_enable,
248 .disable = omap2_dflt_clk_disable,
249 .find_idlest = am35xx_clk_find_idlest,
250 .find_companion = am35xx_clk_find_companion,
254 * am35xx_clk_ipss_find_idlest - return CM_IDLEST info for IPSS
255 * @clk: struct clk * being enabled
256 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
257 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
258 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
260 * The IPSS target CM_IDLEST bit is at a different shift from the
261 * CM_{I,F}CLKEN bit. Pass back the correct info via @idlest_reg
262 * and @idlest_bit. No return value.
264 static void am35xx_clk_ipss_find_idlest(struct clk *clk,
265 void __iomem **idlest_reg,
271 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
272 *idlest_reg = (__force void __iomem *)r;
273 *idlest_bit = AM35XX_ST_IPSS_SHIFT;
274 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
277 const struct clkops clkops_am35xx_ipss_wait = {
278 .enable = omap2_dflt_clk_enable,
279 .disable = omap2_dflt_clk_disable,
280 .find_idlest = am35xx_clk_ipss_find_idlest,
281 .find_companion = omap2_clk_dflt_find_companion,
284 int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate)
287 * According to the 12-5 CDP code from TI, "Limitation 2.5"
288 * on 3430ES1 prevents us from changing DPLL multipliers or dividers
291 if (omap_rev() == OMAP3430_REV_ES1_0) {
292 printk(KERN_ERR "clock: DPLL4 cannot change rate due to "
293 "silicon 'Limitation 2.5' on 3430ES1.\n");
296 return omap3_noncore_dpll_set_rate(clk, rate);
299 void __init omap3_clk_lock_dpll5(void)
301 struct clk *dpll5_clk;
302 struct clk *dpll5_m2_clk;
304 dpll5_clk = clk_get(NULL, "dpll5_ck");
305 clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST);
306 clk_enable(dpll5_clk);
308 /* Enable autoidle to allow it to enter low power bypass */
309 omap3_dpll_allow_idle(dpll5_clk);
311 /* Program dpll5_m2_clk divider for no division */
312 dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck");
313 clk_enable(dpll5_m2_clk);
314 clk_set_rate(dpll5_m2_clk, DPLL5_FREQ_FOR_USBHOST);
316 clk_disable(dpll5_m2_clk);
317 clk_disable(dpll5_clk);
321 /* Common clock code */
323 /* REVISIT: Move this init stuff out into clock.c */
326 * Switch the MPU rate if specified on cmdline.
327 * We cannot do this early until cmdline is parsed.
329 static int __init omap3xxx_clk_arch_init(void)
331 struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
332 unsigned long osc_sys_rate;
335 if (!cpu_is_omap34xx())
341 /* XXX test these for success */
342 dpll1_ck = clk_get(NULL, "dpll1_ck");
343 if (WARN(IS_ERR(dpll1_ck), "Failed to get dpll1_ck.\n"))
346 arm_fck = clk_get(NULL, "arm_fck");
347 if (WARN(IS_ERR(arm_fck), "Failed to get arm_fck.\n"))
350 core_ck = clk_get(NULL, "core_ck");
351 if (WARN(IS_ERR(core_ck), "Failed to get core_ck.\n"))
354 osc_sys_ck = clk_get(NULL, "osc_sys_ck");
355 if (WARN(IS_ERR(osc_sys_ck), "Failed to get osc_sys_ck.\n"))
361 /* REVISIT: not yet ready for 343x */
362 if (clk_set_rate(dpll1_ck, mpurate))
363 printk(KERN_ERR "*** Unable to set MPU rate\n");
365 recalculate_root_clocks();
367 osc_sys_rate = clk_get_rate(osc_sys_ck);
369 pr_info("Switched to new clocking rate (Crystal/Core/MPU): "
370 "%ld.%01ld/%ld/%ld MHz\n",
371 (osc_sys_rate / 1000000),
372 ((osc_sys_rate / 100000) % 10),
373 (clk_get_rate(core_ck) / 1000000),
374 (clk_get_rate(arm_fck) / 1000000));
380 arch_initcall(omap3xxx_clk_arch_init);