OMAP clock: drop .id field; ensure each clock has a unique name
[deliverable/linux.git] / arch / arm / mach-omap2 / clock34xx.c
CommitLineData
02e19a96
PW
1/*
2 * OMAP3-specific clock framework functions
3 *
542313cc 4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
da4d2904 5 * Copyright (C) 2007-2010 Nokia Corporation
02e19a96 6 *
da4d2904
PW
7 * Paul Walmsley
8 * Jouni Högander
02e19a96
PW
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
02e19a96 19#include <linux/kernel.h>
02e19a96
PW
20#include <linux/errno.h>
21#include <linux/delay.h>
22#include <linux/clk.h>
23#include <linux/io.h>
a51ba284 24#include <linux/err.h>
02e19a96 25
ce491cf8
TL
26#include <plat/cpu.h>
27#include <plat/clock.h>
02e19a96 28
02e19a96 29#include "clock.h"
82e9bd58 30#include "clock34xx.h"
02e19a96
PW
31#include "prm.h"
32#include "prm-regbits-34xx.h"
33#include "cm.h"
34#include "cm-regbits-34xx.h"
35
7a66a39b
RN
36/*
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.
40 */
41#define DPLL5_FREQ_FOR_USBHOST 120000000
42
3cc4a2fc
RL
43/*
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.
47 */
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
52
82e9bd58
PW
53/* needed by omap3_core_dpll_m2_set_rate() */
54struct clk *sdrc_ick_p, *arm_fck_p;
55
3c82e229
PW
56/**
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
419cc97d 61 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
3c82e229
PW
62 *
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.
66 */
67static void omap3430es2_clk_ssi_find_idlest(struct clk *clk,
68 void __iomem **idlest_reg,
419cc97d
RL
69 u8 *idlest_bit,
70 u8 *idlest_val)
3c82e229
PW
71{
72 u32 r;
73
74 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
75 *idlest_reg = (__force void __iomem *)r;
76 *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT;
419cc97d 77 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
3c82e229
PW
78}
79
82e9bd58
PW
80const 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,
85};
86
3c82e229
PW
87/**
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
419cc97d 92 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
3c82e229
PW
93 *
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.
100 */
101static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk,
102 void __iomem **idlest_reg,
419cc97d
RL
103 u8 *idlest_bit,
104 u8 *idlest_val)
3c82e229
PW
105{
106 u32 r;
107
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;
419cc97d 112 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
3c82e229
PW
113}
114
82e9bd58
PW
115const 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,
120};
121
3c82e229
PW
122/**
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
419cc97d 127 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
3c82e229
PW
128 *
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.
132 */
133static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk,
134 void __iomem **idlest_reg,
419cc97d
RL
135 u8 *idlest_bit,
136 u8 *idlest_val)
3c82e229
PW
137{
138 u32 r;
139
140 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
141 *idlest_reg = (__force void __iomem *)r;
142 *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT;
419cc97d 143 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
3c82e229
PW
144}
145
82e9bd58
PW
146const 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,
151};
152
a7e069fc
MT
153/**
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
157 *
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.
163 */
164static int omap36xx_pwrdn_clk_enable_with_hsdiv_restore(struct clk *clk)
165{
166 u32 dummy_v, orig_v, clksel_shift;
167 int ret;
168
169 /* Clear PWRDN bit of HSDIVIDER */
170 ret = omap2_dflt_clk_enable(clk);
171
172 /* Restore the dividers */
173 if (!ret) {
174 clksel_shift = __ffs(clk->parent->clksel_mask);
175 orig_v = __raw_readl(clk->parent->clksel_reg);
176 dummy_v = orig_v;
177
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);
181
182 /* Write the original divider */
183 __raw_writel(orig_v, clk->parent->clksel_reg);
184 }
185
186 return ret;
187}
188
189const 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,
194};
195
4751227d 196const struct clkops omap3_clkops_noncore_dpll_ops = {
82e9bd58
PW
197 .enable = omap3_noncore_dpll_enable,
198 .disable = omap3_noncore_dpll_disable,
199};
16c90f02 200
3cc4a2fc
RL
201/**
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
207 *
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.
211 */
212static void am35xx_clk_find_idlest(struct clk *clk,
213 void __iomem **idlest_reg,
214 u8 *idlest_bit,
215 u8 *idlest_val)
216{
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;
220}
221
222/**
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
227 *
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.
235 */
236static void am35xx_clk_find_companion(struct clk *clk, void __iomem **other_reg,
237 u8 *other_bit)
238{
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;
242 else
243 *other_bit = clk->enable_bit - AM35XX_IPSS_ICK_FCK_OFFSET;
244}
245
246const 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,
251};
252
253/**
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
259 *
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.
263 */
264static void am35xx_clk_ipss_find_idlest(struct clk *clk,
265 void __iomem **idlest_reg,
266 u8 *idlest_bit,
267 u8 *idlest_val)
268{
269 u32 r;
270
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;
275}
276
277const 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,
282};
283
82e9bd58 284int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate)
16c90f02
PW
285{
286 /*
287 * According to the 12-5 CDP code from TI, "Limitation 2.5"
288 * on 3430ES1 prevents us from changing DPLL multipliers or dividers
289 * on DPLL4.
290 */
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");
294 return -EINVAL;
295 }
296 return omap3_noncore_dpll_set_rate(clk, rate);
297}
298
e80a9729 299void __init omap3_clk_lock_dpll5(void)
7a66a39b
RN
300{
301 struct clk *dpll5_clk;
302 struct clk *dpll5_m2_clk;
303
304 dpll5_clk = clk_get(NULL, "dpll5_ck");
305 clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST);
306 clk_enable(dpll5_clk);
307
308 /* Enable autoidle to allow it to enter low power bypass */
309 omap3_dpll_allow_idle(dpll5_clk);
310
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);
315
316 clk_disable(dpll5_m2_clk);
317 clk_disable(dpll5_clk);
318 return;
319}
320
feec1277
PW
321/* Common clock code */
322
02e19a96
PW
323/* REVISIT: Move this init stuff out into clock.c */
324
325/*
326 * Switch the MPU rate if specified on cmdline.
327 * We cannot do this early until cmdline is parsed.
328 */
4680c29f 329static int __init omap3xxx_clk_arch_init(void)
02e19a96 330{
82e9bd58
PW
331 struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
332 unsigned long osc_sys_rate;
a51ba284 333 bool err = 0;
82e9bd58 334
4680c29f
PW
335 if (!cpu_is_omap34xx())
336 return 0;
337
02e19a96
PW
338 if (!mpurate)
339 return -EINVAL;
340
82e9bd58
PW
341 /* XXX test these for success */
342 dpll1_ck = clk_get(NULL, "dpll1_ck");
a51ba284
SP
343 if (WARN(IS_ERR(dpll1_ck), "Failed to get dpll1_ck.\n"))
344 err = 1;
345
82e9bd58 346 arm_fck = clk_get(NULL, "arm_fck");
a51ba284
SP
347 if (WARN(IS_ERR(arm_fck), "Failed to get arm_fck.\n"))
348 err = 1;
349
82e9bd58 350 core_ck = clk_get(NULL, "core_ck");
a51ba284
SP
351 if (WARN(IS_ERR(core_ck), "Failed to get core_ck.\n"))
352 err = 1;
353
82e9bd58 354 osc_sys_ck = clk_get(NULL, "osc_sys_ck");
a51ba284
SP
355 if (WARN(IS_ERR(osc_sys_ck), "Failed to get osc_sys_ck.\n"))
356 err = 1;
357
358 if (err)
359 return -ENOENT;
82e9bd58 360
02e19a96 361 /* REVISIT: not yet ready for 343x */
82e9bd58 362 if (clk_set_rate(dpll1_ck, mpurate))
11b66383 363 printk(KERN_ERR "*** Unable to set MPU rate\n");
02e19a96
PW
364
365 recalculate_root_clocks();
366
82e9bd58
PW
367 osc_sys_rate = clk_get_rate(osc_sys_ck);
368
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));
11b66383
SP
375
376 calibrate_delay();
02e19a96
PW
377
378 return 0;
379}
4680c29f 380arch_initcall(omap3xxx_clk_arch_init);
02e19a96 381
02e19a96 382
This page took 0.170483 seconds and 5 git commands to generate.