2 * OMAP3-specific clock framework functions
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
5 * Copyright (C) 2007-2009 Nokia Corporation
7 * Written by Paul Walmsley
8 * Testing and integration fixes by Jouni Högander
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/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>
27 #include <linux/limits.h>
28 #include <linux/bitops.h>
31 #include <plat/clock.h>
32 #include <plat/sram.h>
33 #include <plat/sdrc.h>
34 #include <asm/div64.h>
35 #include <asm/clkdev.h>
38 #include "clock34xx.h"
41 #include "prm-regbits-34xx.h"
43 #include "cm-regbits-34xx.h"
45 #define CYCLES_PER_MHZ 1000000
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.
52 #define DPLL5_FREQ_FOR_USBHOST 120000000
54 /* needed by omap3_core_dpll_m2_set_rate() */
55 struct clk
*sdrc_ick_p
, *arm_fck_p
;
58 * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI
59 * @clk: struct clk * being enabled
60 * @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
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
,
73 r
= (((__force u32
)clk
->enable_reg
& ~0xf0) | 0x20);
74 *idlest_reg
= (__force
void __iomem
*)r
;
75 *idlest_bit
= OMAP3430ES2_ST_SSI_IDLE_SHIFT
;
78 const struct clkops clkops_omap3430es2_ssi_wait
= {
79 .enable
= omap2_dflt_clk_enable
,
80 .disable
= omap2_dflt_clk_disable
,
81 .find_idlest
= omap3430es2_clk_ssi_find_idlest
,
82 .find_companion
= omap2_clk_dflt_find_companion
,
86 * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST
87 * @clk: struct clk * being enabled
88 * @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
91 * Some OMAP modules on OMAP3 ES2+ chips have both initiator and
92 * target IDLEST bits. For our purposes, we are concerned with the
93 * target IDLEST bits, which exist at a different bit position than
94 * the *CLKEN bit position for these modules (DSS and USBHOST) (The
95 * default find_idlest code assumes that they are at the same
96 * position.) No return value.
98 static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk
*clk
,
99 void __iomem
**idlest_reg
,
104 r
= (((__force u32
)clk
->enable_reg
& ~0xf0) | 0x20);
105 *idlest_reg
= (__force
void __iomem
*)r
;
106 /* USBHOST_IDLE has same shift */
107 *idlest_bit
= OMAP3430ES2_ST_DSS_IDLE_SHIFT
;
110 const struct clkops clkops_omap3430es2_dss_usbhost_wait
= {
111 .enable
= omap2_dflt_clk_enable
,
112 .disable
= omap2_dflt_clk_disable
,
113 .find_idlest
= omap3430es2_clk_dss_usbhost_find_idlest
,
114 .find_companion
= omap2_clk_dflt_find_companion
,
118 * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB
119 * @clk: struct clk * being enabled
120 * @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
123 * 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
125 * @idlest_reg and @idlest_bit. No return value.
127 static void omap3430es2_clk_hsotgusb_find_idlest(struct clk
*clk
,
128 void __iomem
**idlest_reg
,
133 r
= (((__force u32
)clk
->enable_reg
& ~0xf0) | 0x20);
134 *idlest_reg
= (__force
void __iomem
*)r
;
135 *idlest_bit
= OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT
;
138 const struct clkops clkops_omap3430es2_hsotgusb_wait
= {
139 .enable
= omap2_dflt_clk_enable
,
140 .disable
= omap2_dflt_clk_disable
,
141 .find_idlest
= omap3430es2_clk_hsotgusb_find_idlest
,
142 .find_companion
= omap2_clk_dflt_find_companion
,
145 const struct clkops clkops_noncore_dpll_ops
= {
146 .enable
= omap3_noncore_dpll_enable
,
147 .disable
= omap3_noncore_dpll_disable
,
150 int omap3_dpll4_set_rate(struct clk
*clk
, unsigned long rate
)
153 * According to the 12-5 CDP code from TI, "Limitation 2.5"
154 * on 3430ES1 prevents us from changing DPLL multipliers or dividers
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");
162 return omap3_noncore_dpll_set_rate(clk
, rate
);
167 * CORE DPLL (DPLL3) rate programming functions
169 * These call into SRAM code to do the actual CM writes, since the SDRAM
170 * is clocked from DPLL3.
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
178 * Program the DPLL M2 divider with the rounded target rate. Returns
179 * -EINVAL upon error, or 0 upon success.
181 int omap3_core_dpll_m2_set_rate(struct clk
*clk
, unsigned long rate
)
186 unsigned long validrate
, sdrcrate
, _mpurate
;
187 struct omap_sdrc_params
*sdrc_cs0
;
188 struct omap_sdrc_params
*sdrc_cs1
;
194 validrate
= omap2_clksel_round_rate_div(clk
, rate
, &new_div
);
195 if (validrate
!= rate
)
198 sdrcrate
= sdrc_ick_p
->rate
;
199 if (rate
> clk
->rate
)
200 sdrcrate
<<= ((rate
/ clk
->rate
) >> 1);
202 sdrcrate
>>= ((clk
->rate
/ rate
) >> 1);
204 ret
= omap2_sdrc_get_params(sdrcrate
, &sdrc_cs0
, &sdrc_cs1
);
208 if (sdrcrate
< MIN_SDRC_DLL_LOCK_FREQ
) {
209 pr_debug("clock: will unlock SDRC DLL\n");
214 * XXX This only needs to be done when the CPU frequency changes
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
;
224 pr_debug("clock: changing CORE DPLL rate from %lu to %lu\n", clk
->rate
,
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
);
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
);
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
);
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
,
253 /* Common clock code */
256 * As it is structured now, this will prevent an OMAP2/3 multiboot
257 * kernel from compiling. This will need further attention.
259 #if defined(CONFIG_ARCH_OMAP3)
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
,
271 * Set clocks for bypass mode for reboot to work.
273 void omap2_clk_prepare_for_reboot(void)
275 /* REVISIT: Not ready for 343x */
279 if (vclk
== NULL
|| sclk
== NULL
)
282 rate
= clk_get_rate(sclk
);
283 clk_set_rate(vclk
, rate
);
287 void omap3_clk_lock_dpll5(void)
289 struct clk
*dpll5_clk
;
290 struct clk
*dpll5_m2_clk
;
292 dpll5_clk
= clk_get(NULL
, "dpll5_ck");
293 clk_set_rate(dpll5_clk
, DPLL5_FREQ_FOR_USBHOST
);
294 clk_enable(dpll5_clk
);
296 /* Enable autoidle to allow it to enter low power bypass */
297 omap3_dpll_allow_idle(dpll5_clk
);
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
);
304 clk_disable(dpll5_m2_clk
);
305 clk_disable(dpll5_clk
);
309 /* REVISIT: Move this init stuff out into clock.c */
312 * Switch the MPU rate if specified on cmdline.
313 * We cannot do this early until cmdline is parsed.
315 static int __init
omap2_clk_arch_init(void)
317 struct clk
*osc_sys_ck
, *dpll1_ck
, *arm_fck
, *core_ck
;
318 unsigned long osc_sys_rate
;
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");
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");
333 recalculate_root_clocks();
335 osc_sys_rate
= clk_get_rate(osc_sys_ck
);
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));
348 arch_initcall(omap2_clk_arch_init
);