aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap1/clock.c
diff options
context:
space:
mode:
authorPaul Walmsley <paul@pwsan.com>2009-12-08 18:29:38 -0500
committerpaul <paul@twilight.(none)>2009-12-11 19:00:40 -0500
commit52650505fbf3a6ab851c801f54e73e76c55ab8da (patch)
tree07fc2b2eccb313fc7a0e3ade4a564f2df08fc33c /arch/arm/mach-omap1/clock.c
parent6f62b58dd4e697a23a308f5b77781394949d333e (diff)
OMAP1 clock: convert mach-omap1/clock.h to mach-omap1/clock_data.c
The OMAP1 clock code currently #includes a large .h file full of static data structures. Instead, define the data in a .c file. Russell King <linux@arm.linux.org.uk> proposed this new arrangement: http://marc.info/?l=linux-omap&m=125967425908895&w=2 This patch also deals with most of the flagrant checkpatch violations. While here, separate the mpu_rate data structures out into their own files, opp.h and opp_data.c. In the long run, these mpu_rate tables should be replaced with OPP code. Also includes a patch from Felipe Balbi <felipe.balbi@nokia.com> to mark omap1_clk_functions as __initdata to avoid a section warning: http://patchwork.kernel.org/patch/64366/ Signed-off-by: Paul Walmsley <paul@pwsan.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Felipe Balbi <felipe.balbi@nokia.com> Cc: Nishanth Menon <nm@ti.com>
Diffstat (limited to 'arch/arm/mach-omap1/clock.c')
-rw-r--r--arch/arm/mach-omap1/clock.c488
1 files changed, 114 insertions, 374 deletions
diff --git a/arch/arm/mach-omap1/clock.c b/arch/arm/mach-omap1/clock.c
index 26a887ccda7b..2ba9ab953731 100644
--- a/arch/arm/mach-omap1/clock.c
+++ b/arch/arm/mach-omap1/clock.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/arch/arm/mach-omap1/clock.c 2 * linux/arch/arm/mach-omap1/clock.c
3 * 3 *
4 * Copyright (C) 2004 - 2005 Nokia corporation 4 * Copyright (C) 2004 - 2005, 2009 Nokia corporation
5 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com> 5 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
6 * 6 *
7 * Modified to use omap shared clock framework by 7 * Modified to use omap shared clock framework by
@@ -26,12 +26,17 @@
26#include <plat/usb.h> 26#include <plat/usb.h>
27#include <plat/clock.h> 27#include <plat/clock.h>
28#include <plat/sram.h> 28#include <plat/sram.h>
29 29#include <plat/clkdev_omap.h>
30static const struct clkops clkops_generic;
31static const struct clkops clkops_uart;
32static const struct clkops clkops_dspck;
33 30
34#include "clock.h" 31#include "clock.h"
32#include "opp.h"
33
34__u32 arm_idlect1_mask;
35struct clk *api_ck_p, *ck_dpll1_p, *ck_ref_p;
36
37/*-------------------------------------------------------------------------
38 * Omap1 specific clock functions
39 *-------------------------------------------------------------------------*/
35 40
36static int clk_omap1_dummy_enable(struct clk *clk) 41static int clk_omap1_dummy_enable(struct clk *clk)
37{ 42{
@@ -42,134 +47,24 @@ static void clk_omap1_dummy_disable(struct clk *clk)
42{ 47{
43} 48}
44 49
45static const struct clkops clkops_dummy = { 50const struct clkops clkops_dummy = {
46 .enable = clk_omap1_dummy_enable, 51 .enable = clk_omap1_dummy_enable,
47 .disable = clk_omap1_dummy_disable, 52 .disable = clk_omap1_dummy_disable,
48};
49
50static struct clk dummy_ck = {
51 .name = "dummy",
52 .ops = &clkops_dummy,
53 .flags = RATE_FIXED,
54};
55
56struct omap_clk {
57 u32 cpu;
58 struct clk_lookup lk;
59}; 53};
60 54
61#define CLK(dev, con, ck, cp) \ 55/* XXX can be replaced with a fixed_divisor_recalc */
62 { \ 56unsigned long omap1_watchdog_recalc(struct clk *clk)
63 .cpu = cp, \
64 .lk = { \
65 .dev_id = dev, \
66 .con_id = con, \
67 .clk = ck, \
68 }, \
69 }
70
71#define CK_310 (1 << 0)
72#define CK_7XX (1 << 1)
73#define CK_1510 (1 << 2)
74#define CK_16XX (1 << 3)
75
76static struct omap_clk omap_clks[] = {
77 /* non-ULPD clocks */
78 CLK(NULL, "ck_ref", &ck_ref, CK_16XX | CK_1510 | CK_310 | CK_7XX),
79 CLK(NULL, "ck_dpll1", &ck_dpll1, CK_16XX | CK_1510 | CK_310),
80 /* CK_GEN1 clocks */
81 CLK(NULL, "ck_dpll1out", &ck_dpll1out.clk, CK_16XX),
82 CLK(NULL, "ck_sossi", &sossi_ck, CK_16XX),
83 CLK(NULL, "arm_ck", &arm_ck, CK_16XX | CK_1510 | CK_310),
84 CLK(NULL, "armper_ck", &armper_ck.clk, CK_16XX | CK_1510 | CK_310),
85 CLK(NULL, "arm_gpio_ck", &arm_gpio_ck, CK_1510 | CK_310),
86 CLK(NULL, "armxor_ck", &armxor_ck.clk, CK_16XX | CK_1510 | CK_310 | CK_7XX),
87 CLK(NULL, "armtim_ck", &armtim_ck.clk, CK_16XX | CK_1510 | CK_310),
88 CLK("omap_wdt", "fck", &armwdt_ck.clk, CK_16XX | CK_1510 | CK_310),
89 CLK("omap_wdt", "ick", &armper_ck.clk, CK_16XX),
90 CLK("omap_wdt", "ick", &dummy_ck, CK_1510 | CK_310),
91 CLK(NULL, "arminth_ck", &arminth_ck1510, CK_1510 | CK_310),
92 CLK(NULL, "arminth_ck", &arminth_ck16xx, CK_16XX),
93 /* CK_GEN2 clocks */
94 CLK(NULL, "dsp_ck", &dsp_ck, CK_16XX | CK_1510 | CK_310),
95 CLK(NULL, "dspmmu_ck", &dspmmu_ck, CK_16XX | CK_1510 | CK_310),
96 CLK(NULL, "dspper_ck", &dspper_ck, CK_16XX | CK_1510 | CK_310),
97 CLK(NULL, "dspxor_ck", &dspxor_ck, CK_16XX | CK_1510 | CK_310),
98 CLK(NULL, "dsptim_ck", &dsptim_ck, CK_16XX | CK_1510 | CK_310),
99 /* CK_GEN3 clocks */
100 CLK(NULL, "tc_ck", &tc_ck.clk, CK_16XX | CK_1510 | CK_310 | CK_7XX),
101 CLK(NULL, "tipb_ck", &tipb_ck, CK_1510 | CK_310),
102 CLK(NULL, "l3_ocpi_ck", &l3_ocpi_ck, CK_16XX | CK_7XX),
103 CLK(NULL, "tc1_ck", &tc1_ck, CK_16XX),
104 CLK(NULL, "tc2_ck", &tc2_ck, CK_16XX),
105 CLK(NULL, "dma_ck", &dma_ck, CK_16XX | CK_1510 | CK_310),
106 CLK(NULL, "dma_lcdfree_ck", &dma_lcdfree_ck, CK_16XX),
107 CLK(NULL, "api_ck", &api_ck.clk, CK_16XX | CK_1510 | CK_310),
108 CLK(NULL, "lb_ck", &lb_ck.clk, CK_1510 | CK_310),
109 CLK(NULL, "rhea1_ck", &rhea1_ck, CK_16XX),
110 CLK(NULL, "rhea2_ck", &rhea2_ck, CK_16XX),
111 CLK(NULL, "lcd_ck", &lcd_ck_16xx, CK_16XX | CK_7XX),
112 CLK(NULL, "lcd_ck", &lcd_ck_1510.clk, CK_1510 | CK_310),
113 /* ULPD clocks */
114 CLK(NULL, "uart1_ck", &uart1_1510, CK_1510 | CK_310),
115 CLK(NULL, "uart1_ck", &uart1_16xx.clk, CK_16XX),
116 CLK(NULL, "uart2_ck", &uart2_ck, CK_16XX | CK_1510 | CK_310),
117 CLK(NULL, "uart3_ck", &uart3_1510, CK_1510 | CK_310),
118 CLK(NULL, "uart3_ck", &uart3_16xx.clk, CK_16XX),
119 CLK(NULL, "usb_clko", &usb_clko, CK_16XX | CK_1510 | CK_310),
120 CLK(NULL, "usb_hhc_ck", &usb_hhc_ck1510, CK_1510 | CK_310),
121 CLK(NULL, "usb_hhc_ck", &usb_hhc_ck16xx, CK_16XX),
122 CLK(NULL, "usb_dc_ck", &usb_dc_ck, CK_16XX),
123 CLK(NULL, "usb_dc_ck", &usb_dc_ck7xx, CK_7XX),
124 CLK(NULL, "mclk", &mclk_1510, CK_1510 | CK_310),
125 CLK(NULL, "mclk", &mclk_16xx, CK_16XX),
126 CLK(NULL, "bclk", &bclk_1510, CK_1510 | CK_310),
127 CLK(NULL, "bclk", &bclk_16xx, CK_16XX),
128 CLK("mmci-omap.0", "fck", &mmc1_ck, CK_16XX | CK_1510 | CK_310),
129 CLK("mmci-omap.0", "fck", &mmc3_ck, CK_7XX),
130 CLK("mmci-omap.0", "ick", &armper_ck.clk, CK_16XX | CK_1510 | CK_310 | CK_7XX),
131 CLK("mmci-omap.1", "fck", &mmc2_ck, CK_16XX),
132 CLK("mmci-omap.1", "ick", &armper_ck.clk, CK_16XX),
133 /* Virtual clocks */
134 CLK(NULL, "mpu", &virtual_ck_mpu, CK_16XX | CK_1510 | CK_310),
135 CLK("i2c_omap.1", "fck", &i2c_fck, CK_16XX | CK_1510 | CK_310),
136 CLK("i2c_omap.1", "ick", &i2c_ick, CK_16XX),
137 CLK("i2c_omap.1", "ick", &dummy_ck, CK_1510 | CK_310),
138 CLK("omap_uwire", "fck", &armxor_ck.clk, CK_16XX | CK_1510 | CK_310),
139 CLK("omap-mcbsp.1", "ick", &dspper_ck, CK_16XX),
140 CLK("omap-mcbsp.1", "ick", &dummy_ck, CK_1510 | CK_310),
141 CLK("omap-mcbsp.2", "ick", &armper_ck.clk, CK_16XX),
142 CLK("omap-mcbsp.2", "ick", &dummy_ck, CK_1510 | CK_310),
143 CLK("omap-mcbsp.3", "ick", &dspper_ck, CK_16XX),
144 CLK("omap-mcbsp.3", "ick", &dummy_ck, CK_1510 | CK_310),
145 CLK("omap-mcbsp.1", "fck", &dspxor_ck, CK_16XX | CK_1510 | CK_310),
146 CLK("omap-mcbsp.2", "fck", &armper_ck.clk, CK_16XX | CK_1510 | CK_310),
147 CLK("omap-mcbsp.3", "fck", &dspxor_ck, CK_16XX | CK_1510 | CK_310),
148};
149
150static int omap1_clk_enable_generic(struct clk * clk);
151static int omap1_clk_enable(struct clk *clk);
152static void omap1_clk_disable_generic(struct clk * clk);
153static void omap1_clk_disable(struct clk *clk);
154
155__u32 arm_idlect1_mask;
156
157/*-------------------------------------------------------------------------
158 * Omap1 specific clock functions
159 *-------------------------------------------------------------------------*/
160
161static unsigned long omap1_watchdog_recalc(struct clk *clk)
162{ 57{
163 return clk->parent->rate / 14; 58 return clk->parent->rate / 14;
164} 59}
165 60
166static unsigned long omap1_uart_recalc(struct clk *clk) 61unsigned long omap1_uart_recalc(struct clk *clk)
167{ 62{
168 unsigned int val = __raw_readl(clk->enable_reg); 63 unsigned int val = __raw_readl(clk->enable_reg);
169 return val & clk->enable_bit ? 48000000 : 12000000; 64 return val & clk->enable_bit ? 48000000 : 12000000;
170} 65}
171 66
172static unsigned long omap1_sossi_recalc(struct clk *clk) 67unsigned long omap1_sossi_recalc(struct clk *clk)
173{ 68{
174 u32 div = omap_readl(MOD_CONF_CTRL_1); 69 u32 div = omap_readl(MOD_CONF_CTRL_1);
175 70
@@ -179,64 +74,6 @@ static unsigned long omap1_sossi_recalc(struct clk *clk)
179 return clk->parent->rate / div; 74 return clk->parent->rate / div;
180} 75}
181 76
182static int omap1_clk_enable_dsp_domain(struct clk *clk)
183{
184 int retval;
185
186 retval = omap1_clk_enable(&api_ck.clk);
187 if (!retval) {
188 retval = omap1_clk_enable_generic(clk);
189 omap1_clk_disable(&api_ck.clk);
190 }
191
192 return retval;
193}
194
195static void omap1_clk_disable_dsp_domain(struct clk *clk)
196{
197 if (omap1_clk_enable(&api_ck.clk) == 0) {
198 omap1_clk_disable_generic(clk);
199 omap1_clk_disable(&api_ck.clk);
200 }
201}
202
203static const struct clkops clkops_dspck = {
204 .enable = &omap1_clk_enable_dsp_domain,
205 .disable = &omap1_clk_disable_dsp_domain,
206};
207
208static int omap1_clk_enable_uart_functional(struct clk *clk)
209{
210 int ret;
211 struct uart_clk *uclk;
212
213 ret = omap1_clk_enable_generic(clk);
214 if (ret == 0) {
215 /* Set smart idle acknowledgement mode */
216 uclk = (struct uart_clk *)clk;
217 omap_writeb((omap_readb(uclk->sysc_addr) & ~0x10) | 8,
218 uclk->sysc_addr);
219 }
220
221 return ret;
222}
223
224static void omap1_clk_disable_uart_functional(struct clk *clk)
225{
226 struct uart_clk *uclk;
227
228 /* Set force idle acknowledgement mode */
229 uclk = (struct uart_clk *)clk;
230 omap_writeb((omap_readb(uclk->sysc_addr) & ~0x18), uclk->sysc_addr);
231
232 omap1_clk_disable_generic(clk);
233}
234
235static const struct clkops clkops_uart = {
236 .enable = &omap1_clk_enable_uart_functional,
237 .disable = &omap1_clk_disable_uart_functional,
238};
239
240static void omap1_clk_allow_idle(struct clk *clk) 77static void omap1_clk_allow_idle(struct clk *clk)
241{ 78{
242 struct arm_idlect1_clk * iclk = (struct arm_idlect1_clk *)clk; 79 struct arm_idlect1_clk * iclk = (struct arm_idlect1_clk *)clk;
@@ -344,7 +181,7 @@ static int calc_dsor_exp(struct clk *clk, unsigned long rate)
344 return dsor_exp; 181 return dsor_exp;
345} 182}
346 183
347static unsigned long omap1_ckctl_recalc(struct clk *clk) 184unsigned long omap1_ckctl_recalc(struct clk *clk)
348{ 185{
349 /* Calculate divisor encoded as 2-bit exponent */ 186 /* Calculate divisor encoded as 2-bit exponent */
350 int dsor = 1 << (3 & (omap_readw(ARM_CKCTL) >> clk->rate_offset)); 187 int dsor = 1 << (3 & (omap_readw(ARM_CKCTL) >> clk->rate_offset));
@@ -352,7 +189,7 @@ static unsigned long omap1_ckctl_recalc(struct clk *clk)
352 return clk->parent->rate / dsor; 189 return clk->parent->rate / dsor;
353} 190}
354 191
355static unsigned long omap1_ckctl_recalc_dsp_domain(struct clk *clk) 192unsigned long omap1_ckctl_recalc_dsp_domain(struct clk *clk)
356{ 193{
357 int dsor; 194 int dsor;
358 195
@@ -363,25 +200,29 @@ static unsigned long omap1_ckctl_recalc_dsp_domain(struct clk *clk)
363 * Note that DSP_CKCTL virt addr = phys addr, so 200 * Note that DSP_CKCTL virt addr = phys addr, so
364 * we must use __raw_readw() instead of omap_readw(). 201 * we must use __raw_readw() instead of omap_readw().
365 */ 202 */
366 omap1_clk_enable(&api_ck.clk); 203 omap1_clk_enable(api_ck_p);
367 dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset)); 204 dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset));
368 omap1_clk_disable(&api_ck.clk); 205 omap1_clk_disable(api_ck_p);
369 206
370 return clk->parent->rate / dsor; 207 return clk->parent->rate / dsor;
371} 208}
372 209
373/* MPU virtual clock functions */ 210/* MPU virtual clock functions */
374static int omap1_select_table_rate(struct clk * clk, unsigned long rate) 211int omap1_select_table_rate(struct clk *clk, unsigned long rate)
375{ 212{
376 /* Find the highest supported frequency <= rate and switch to it */ 213 /* Find the highest supported frequency <= rate and switch to it */
377 struct mpu_rate * ptr; 214 struct mpu_rate * ptr;
215 unsigned long dpll1_rate, ref_rate;
216
217 dpll1_rate = clk_get_rate(ck_dpll1_p);
218 ref_rate = clk_get_rate(ck_ref_p);
378 219
379 for (ptr = rate_table; ptr->rate; ptr++) { 220 for (ptr = omap1_rate_table; ptr->rate; ptr++) {
380 if (ptr->xtal != ck_ref.rate) 221 if (ptr->xtal != ref_rate)
381 continue; 222 continue;
382 223
383 /* DPLL1 cannot be reprogrammed without risking system crash */ 224 /* DPLL1 cannot be reprogrammed without risking system crash */
384 if (likely(ck_dpll1.rate!=0) && ptr->pll_rate != ck_dpll1.rate) 225 if (likely(dpll1_rate != 0) && ptr->pll_rate != dpll1_rate)
385 continue; 226 continue;
386 227
387 /* Can check only after xtal frequency check */ 228 /* Can check only after xtal frequency check */
@@ -402,11 +243,13 @@ static int omap1_select_table_rate(struct clk * clk, unsigned long rate)
402 else 243 else
403 omap_sram_reprogram_clock(ptr->dpllctl_val, ptr->ckctl_val); 244 omap_sram_reprogram_clock(ptr->dpllctl_val, ptr->ckctl_val);
404 245
405 ck_dpll1.rate = ptr->pll_rate; 246 /* XXX Do we need to recalculate the tree below DPLL1 at this point? */
247 ck_dpll1_p->rate = ptr->pll_rate;
248
406 return 0; 249 return 0;
407} 250}
408 251
409static int omap1_clk_set_rate_dsp_domain(struct clk *clk, unsigned long rate) 252int omap1_clk_set_rate_dsp_domain(struct clk *clk, unsigned long rate)
410{ 253{
411 int dsor_exp; 254 int dsor_exp;
412 u16 regval; 255 u16 regval;
@@ -426,7 +269,7 @@ static int omap1_clk_set_rate_dsp_domain(struct clk *clk, unsigned long rate)
426 return 0; 269 return 0;
427} 270}
428 271
429static long omap1_clk_round_rate_ckctl_arm(struct clk *clk, unsigned long rate) 272long omap1_clk_round_rate_ckctl_arm(struct clk *clk, unsigned long rate)
430{ 273{
431 int dsor_exp = calc_dsor_exp(clk, rate); 274 int dsor_exp = calc_dsor_exp(clk, rate);
432 if (dsor_exp < 0) 275 if (dsor_exp < 0)
@@ -436,7 +279,7 @@ static long omap1_clk_round_rate_ckctl_arm(struct clk *clk, unsigned long rate)
436 return clk->parent->rate / (1 << dsor_exp); 279 return clk->parent->rate / (1 << dsor_exp);
437} 280}
438 281
439static int omap1_clk_set_rate_ckctl_arm(struct clk *clk, unsigned long rate) 282int omap1_clk_set_rate_ckctl_arm(struct clk *clk, unsigned long rate)
440{ 283{
441 int dsor_exp; 284 int dsor_exp;
442 u16 regval; 285 u16 regval;
@@ -456,16 +299,19 @@ static int omap1_clk_set_rate_ckctl_arm(struct clk *clk, unsigned long rate)
456 return 0; 299 return 0;
457} 300}
458 301
459static long omap1_round_to_table_rate(struct clk * clk, unsigned long rate) 302long omap1_round_to_table_rate(struct clk *clk, unsigned long rate)
460{ 303{
461 /* Find the highest supported frequency <= rate */ 304 /* Find the highest supported frequency <= rate */
462 struct mpu_rate * ptr; 305 struct mpu_rate * ptr;
463 long highest_rate; 306 long highest_rate;
307 unsigned long ref_rate;
308
309 ref_rate = clk_get_rate(ck_ref_p);
464 310
465 highest_rate = -EINVAL; 311 highest_rate = -EINVAL;
466 312
467 for (ptr = rate_table; ptr->rate; ptr++) { 313 for (ptr = omap1_rate_table; ptr->rate; ptr++) {
468 if (ptr->xtal != ck_ref.rate) 314 if (ptr->xtal != ref_rate)
469 continue; 315 continue;
470 316
471 highest_rate = ptr->rate; 317 highest_rate = ptr->rate;
@@ -500,8 +346,8 @@ static unsigned calc_ext_dsor(unsigned long rate)
500 return dsor; 346 return dsor;
501} 347}
502 348
503/* Only needed on 1510 */ 349/* XXX Only needed on 1510 */
504static int omap1_set_uart_rate(struct clk * clk, unsigned long rate) 350int omap1_set_uart_rate(struct clk *clk, unsigned long rate)
505{ 351{
506 unsigned int val; 352 unsigned int val;
507 353
@@ -519,7 +365,7 @@ static int omap1_set_uart_rate(struct clk * clk, unsigned long rate)
519} 365}
520 366
521/* External clock (MCLK & BCLK) functions */ 367/* External clock (MCLK & BCLK) functions */
522static int omap1_set_ext_clk_rate(struct clk * clk, unsigned long rate) 368int omap1_set_ext_clk_rate(struct clk *clk, unsigned long rate)
523{ 369{
524 unsigned dsor; 370 unsigned dsor;
525 __u16 ratio_bits; 371 __u16 ratio_bits;
@@ -537,7 +383,7 @@ static int omap1_set_ext_clk_rate(struct clk * clk, unsigned long rate)
537 return 0; 383 return 0;
538} 384}
539 385
540static int omap1_set_sossi_rate(struct clk *clk, unsigned long rate) 386int omap1_set_sossi_rate(struct clk *clk, unsigned long rate)
541{ 387{
542 u32 l; 388 u32 l;
543 int div; 389 int div;
@@ -560,12 +406,12 @@ static int omap1_set_sossi_rate(struct clk *clk, unsigned long rate)
560 return 0; 406 return 0;
561} 407}
562 408
563static long omap1_round_ext_clk_rate(struct clk * clk, unsigned long rate) 409long omap1_round_ext_clk_rate(struct clk *clk, unsigned long rate)
564{ 410{
565 return 96000000 / calc_ext_dsor(rate); 411 return 96000000 / calc_ext_dsor(rate);
566} 412}
567 413
568static void omap1_init_ext_clk(struct clk * clk) 414void omap1_init_ext_clk(struct clk *clk)
569{ 415{
570 unsigned dsor; 416 unsigned dsor;
571 __u16 ratio_bits; 417 __u16 ratio_bits;
@@ -583,7 +429,7 @@ static void omap1_init_ext_clk(struct clk * clk)
583 clk-> rate = 96000000 / dsor; 429 clk-> rate = 96000000 / dsor;
584} 430}
585 431
586static int omap1_clk_enable(struct clk *clk) 432int omap1_clk_enable(struct clk *clk)
587{ 433{
588 int ret = 0; 434 int ret = 0;
589 435
@@ -611,7 +457,7 @@ err:
611 return ret; 457 return ret;
612} 458}
613 459
614static void omap1_clk_disable(struct clk *clk) 460void omap1_clk_disable(struct clk *clk)
615{ 461{
616 if (clk->usecount > 0 && !(--clk->usecount)) { 462 if (clk->usecount > 0 && !(--clk->usecount)) {
617 clk->ops->disable(clk); 463 clk->ops->disable(clk);
@@ -666,12 +512,70 @@ static void omap1_clk_disable_generic(struct clk *clk)
666 } 512 }
667} 513}
668 514
669static const struct clkops clkops_generic = { 515const struct clkops clkops_generic = {
670 .enable = &omap1_clk_enable_generic, 516 .enable = omap1_clk_enable_generic,
671 .disable = &omap1_clk_disable_generic, 517 .disable = omap1_clk_disable_generic,
518};
519
520static int omap1_clk_enable_dsp_domain(struct clk *clk)
521{
522 int retval;
523
524 retval = omap1_clk_enable(api_ck_p);
525 if (!retval) {
526 retval = omap1_clk_enable_generic(clk);
527 omap1_clk_disable(api_ck_p);
528 }
529
530 return retval;
531}
532
533static void omap1_clk_disable_dsp_domain(struct clk *clk)
534{
535 if (omap1_clk_enable(api_ck_p) == 0) {
536 omap1_clk_disable_generic(clk);
537 omap1_clk_disable(api_ck_p);
538 }
539}
540
541const struct clkops clkops_dspck = {
542 .enable = omap1_clk_enable_dsp_domain,
543 .disable = omap1_clk_disable_dsp_domain,
672}; 544};
673 545
674static long omap1_clk_round_rate(struct clk *clk, unsigned long rate) 546static int omap1_clk_enable_uart_functional(struct clk *clk)
547{
548 int ret;
549 struct uart_clk *uclk;
550
551 ret = omap1_clk_enable_generic(clk);
552 if (ret == 0) {
553 /* Set smart idle acknowledgement mode */
554 uclk = (struct uart_clk *)clk;
555 omap_writeb((omap_readb(uclk->sysc_addr) & ~0x10) | 8,
556 uclk->sysc_addr);
557 }
558
559 return ret;
560}
561
562static void omap1_clk_disable_uart_functional(struct clk *clk)
563{
564 struct uart_clk *uclk;
565
566 /* Set force idle acknowledgement mode */
567 uclk = (struct uart_clk *)clk;
568 omap_writeb((omap_readb(uclk->sysc_addr) & ~0x18), uclk->sysc_addr);
569
570 omap1_clk_disable_generic(clk);
571}
572
573const struct clkops clkops_uart = {
574 .enable = omap1_clk_enable_uart_functional,
575 .disable = omap1_clk_disable_uart_functional,
576};
577
578long omap1_clk_round_rate(struct clk *clk, unsigned long rate)
675{ 579{
676 if (clk->flags & RATE_FIXED) 580 if (clk->flags & RATE_FIXED)
677 return clk->rate; 581 return clk->rate;
@@ -682,7 +586,7 @@ static long omap1_clk_round_rate(struct clk *clk, unsigned long rate)
682 return clk->rate; 586 return clk->rate;
683} 587}
684 588
685static int omap1_clk_set_rate(struct clk *clk, unsigned long rate) 589int omap1_clk_set_rate(struct clk *clk, unsigned long rate)
686{ 590{
687 int ret = -EINVAL; 591 int ret = -EINVAL;
688 592
@@ -697,7 +601,7 @@ static int omap1_clk_set_rate(struct clk *clk, unsigned long rate)
697 601
698#ifdef CONFIG_OMAP_RESET_CLOCKS 602#ifdef CONFIG_OMAP_RESET_CLOCKS
699 603
700static void __init omap1_clk_disable_unused(struct clk *clk) 604void __init omap1_clk_disable_unused(struct clk *clk)
701{ 605{
702 __u32 regval32; 606 __u32 regval32;
703 607
@@ -723,168 +627,4 @@ static void __init omap1_clk_disable_unused(struct clk *clk)
723 printk(" done\n"); 627 printk(" done\n");
724} 628}
725 629
726#else
727#define omap1_clk_disable_unused NULL
728#endif 630#endif
729
730static struct clk_functions omap1_clk_functions = {
731 .clk_enable = omap1_clk_enable,
732 .clk_disable = omap1_clk_disable,
733 .clk_round_rate = omap1_clk_round_rate,
734 .clk_set_rate = omap1_clk_set_rate,
735 .clk_disable_unused = omap1_clk_disable_unused,
736};
737
738int __init omap1_clk_init(void)
739{
740 struct omap_clk *c;
741 const struct omap_clock_config *info;
742 int crystal_type = 0; /* Default 12 MHz */
743 u32 reg, cpu_mask;
744
745#ifdef CONFIG_DEBUG_LL
746 /* Resets some clocks that may be left on from bootloader,
747 * but leaves serial clocks on.
748 */
749 omap_writel(0x3 << 29, MOD_CONF_CTRL_0);
750#endif
751
752 /* USB_REQ_EN will be disabled later if necessary (usb_dc_ck) */
753 reg = omap_readw(SOFT_REQ_REG) & (1 << 4);
754 omap_writew(reg, SOFT_REQ_REG);
755 if (!cpu_is_omap15xx())
756 omap_writew(0, SOFT_REQ_REG2);
757
758 clk_init(&omap1_clk_functions);
759
760 /* By default all idlect1 clocks are allowed to idle */
761 arm_idlect1_mask = ~0;
762
763 for (c = omap_clks; c < omap_clks + ARRAY_SIZE(omap_clks); c++)
764 clk_preinit(c->lk.clk);
765
766 cpu_mask = 0;
767 if (cpu_is_omap16xx())
768 cpu_mask |= CK_16XX;
769 if (cpu_is_omap1510())
770 cpu_mask |= CK_1510;
771 if (cpu_is_omap7xx())
772 cpu_mask |= CK_7XX;
773 if (cpu_is_omap310())
774 cpu_mask |= CK_310;
775
776 for (c = omap_clks; c < omap_clks + ARRAY_SIZE(omap_clks); c++)
777 if (c->cpu & cpu_mask) {
778 clkdev_add(&c->lk);
779 clk_register(c->lk.clk);
780 }
781
782 info = omap_get_config(OMAP_TAG_CLOCK, struct omap_clock_config);
783 if (info != NULL) {
784 if (!cpu_is_omap15xx())
785 crystal_type = info->system_clock_type;
786 }
787
788#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
789 ck_ref.rate = 13000000;
790#elif defined(CONFIG_ARCH_OMAP16XX)
791 if (crystal_type == 2)
792 ck_ref.rate = 19200000;
793#endif
794
795 printk("Clocks: ARM_SYSST: 0x%04x DPLL_CTL: 0x%04x ARM_CKCTL: 0x%04x\n",
796 omap_readw(ARM_SYSST), omap_readw(DPLL_CTL),
797 omap_readw(ARM_CKCTL));
798
799 /* We want to be in syncronous scalable mode */
800 omap_writew(0x1000, ARM_SYSST);
801
802#ifdef CONFIG_OMAP_CLOCKS_SET_BY_BOOTLOADER
803 /* Use values set by bootloader. Determine PLL rate and recalculate
804 * dependent clocks as if kernel had changed PLL or divisors.
805 */
806 {
807 unsigned pll_ctl_val = omap_readw(DPLL_CTL);
808
809 ck_dpll1.rate = ck_ref.rate; /* Base xtal rate */
810 if (pll_ctl_val & 0x10) {
811 /* PLL enabled, apply multiplier and divisor */
812 if (pll_ctl_val & 0xf80)
813 ck_dpll1.rate *= (pll_ctl_val & 0xf80) >> 7;
814 ck_dpll1.rate /= ((pll_ctl_val & 0x60) >> 5) + 1;
815 } else {
816 /* PLL disabled, apply bypass divisor */
817 switch (pll_ctl_val & 0xc) {
818 case 0:
819 break;
820 case 0x4:
821 ck_dpll1.rate /= 2;
822 break;
823 default:
824 ck_dpll1.rate /= 4;
825 break;
826 }
827 }
828 }
829#else
830 /* Find the highest supported frequency and enable it */
831 if (omap1_select_table_rate(&virtual_ck_mpu, ~0)) {
832 printk(KERN_ERR "System frequencies not set. Check your config.\n");
833 /* Guess sane values (60MHz) */
834 omap_writew(0x2290, DPLL_CTL);
835 omap_writew(cpu_is_omap7xx() ? 0x3005 : 0x1005, ARM_CKCTL);
836 ck_dpll1.rate = 60000000;
837 }
838#endif
839 propagate_rate(&ck_dpll1);
840 /* Cache rates for clocks connected to ck_ref (not dpll1) */
841 propagate_rate(&ck_ref);
842 printk(KERN_INFO "Clocking rate (xtal/DPLL1/MPU): "
843 "%ld.%01ld/%ld.%01ld/%ld.%01ld MHz\n",
844 ck_ref.rate / 1000000, (ck_ref.rate / 100000) % 10,
845 ck_dpll1.rate / 1000000, (ck_dpll1.rate / 100000) % 10,
846 arm_ck.rate / 1000000, (arm_ck.rate / 100000) % 10);
847
848#if defined(CONFIG_MACH_OMAP_PERSEUS2) || defined(CONFIG_MACH_OMAP_FSAMPLE)
849 /* Select slicer output as OMAP input clock */
850 omap_writew(omap_readw(OMAP7XX_PCC_UPLD_CTRL) & ~0x1, OMAP7XX_PCC_UPLD_CTRL);
851#endif
852
853 /* Amstrad Delta wants BCLK high when inactive */
854 if (machine_is_ams_delta())
855 omap_writel(omap_readl(ULPD_CLOCK_CTRL) |
856 (1 << SDW_MCLK_INV_BIT),
857 ULPD_CLOCK_CTRL);
858
859 /* Turn off DSP and ARM_TIMXO. Make sure ARM_INTHCK is not divided */
860 /* (on 730, bit 13 must not be cleared) */
861 if (cpu_is_omap7xx())
862 omap_writew(omap_readw(ARM_CKCTL) & 0x2fff, ARM_CKCTL);
863 else
864 omap_writew(omap_readw(ARM_CKCTL) & 0x0fff, ARM_CKCTL);
865
866 /* Put DSP/MPUI into reset until needed */
867 omap_writew(0, ARM_RSTCT1);
868 omap_writew(1, ARM_RSTCT2);
869 omap_writew(0x400, ARM_IDLECT1);
870
871 /*
872 * According to OMAP5910 Erratum SYS_DMA_1, bit DMACK_REQ (bit 8)
873 * of the ARM_IDLECT2 register must be set to zero. The power-on
874 * default value of this bit is one.
875 */
876 omap_writew(0x0000, ARM_IDLECT2); /* Turn LCD clock off also */
877
878 /*
879 * Only enable those clocks we will need, let the drivers
880 * enable other clocks as necessary
881 */
882 clk_enable(&armper_ck.clk);
883 clk_enable(&armxor_ck.clk);
884 clk_enable(&armtim_ck.clk); /* This should be done by timer code */
885
886 if (cpu_is_omap15xx())
887 clk_enable(&arm_gpio_ck);
888
889 return 0;
890}