blob: 6d8f7c6402370f5cdc4e7bf3eade9dc0f222ed3b [file] [log] [blame]
Tony Lindgren3179a012005-11-10 14:26:48 +00001/*
2 * linux/arch/arm/mach-omap1/clock.c
3 *
Paul Walmsley51c19542010-02-22 22:09:26 -07004 * Copyright (C) 2004 - 2005, 2009-2010 Nokia Corporation
Tony Lindgren3179a012005-11-10 14:26:48 +00005 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
6 *
7 * Modified to use omap shared clock framework by
8 * Tony Lindgren <tony@atomide.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
Tony Lindgren3179a012005-11-10 14:26:48 +000014#include <linux/kernel.h>
15#include <linux/list.h>
16#include <linux/errno.h>
17#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000018#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010019#include <linux/io.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010020#include <linux/clkdev.h>
Tony Lindgren3179a012005-11-10 14:26:48 +000021
Tony Lindgren90afd5c2006-09-25 13:27:20 +030022#include <asm/mach-types.h>
Tony Lindgren3179a012005-11-10 14:26:48 +000023
Tony Lindgrence491cf2009-10-20 09:40:47 -070024#include <plat/cpu.h>
25#include <plat/usb.h>
26#include <plat/clock.h>
27#include <plat/sram.h>
Paul Walmsley52650502009-12-08 16:29:38 -070028#include <plat/clkdev_omap.h>
Russell King548d8492008-11-04 14:02:46 +000029
Tony Lindgren3179a012005-11-10 14:26:48 +000030#include "clock.h"
Paul Walmsley52650502009-12-08 16:29:38 -070031#include "opp.h"
32
33__u32 arm_idlect1_mask;
34struct clk *api_ck_p, *ck_dpll1_p, *ck_ref_p;
35
Paul Walmsleyfb2fc922010-07-26 16:34:28 -060036/*
Paul Walmsley52650502009-12-08 16:29:38 -070037 * Omap1 specific clock functions
Paul Walmsleyfb2fc922010-07-26 16:34:28 -060038 */
Tony Lindgren3179a012005-11-10 14:26:48 +000039
Paul Walmsley52650502009-12-08 16:29:38 -070040unsigned long omap1_uart_recalc(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +000041{
Tony Lindgrenfed415e2009-01-28 12:18:48 -070042 unsigned int val = __raw_readl(clk->enable_reg);
Russell King8b9dbc12009-02-12 10:12:59 +000043 return val & clk->enable_bit ? 48000000 : 12000000;
Tony Lindgren3179a012005-11-10 14:26:48 +000044}
45
Paul Walmsley52650502009-12-08 16:29:38 -070046unsigned long omap1_sossi_recalc(struct clk *clk)
Imre Deakdf2c2e72007-03-05 17:22:58 +020047{
48 u32 div = omap_readl(MOD_CONF_CTRL_1);
49
50 div = (div >> 17) & 0x7;
51 div++;
Russell King8b9dbc12009-02-12 10:12:59 +000052
53 return clk->parent->rate / div;
Imre Deakdf2c2e72007-03-05 17:22:58 +020054}
55
Tony Lindgren3179a012005-11-10 14:26:48 +000056static void omap1_clk_allow_idle(struct clk *clk)
57{
58 struct arm_idlect1_clk * iclk = (struct arm_idlect1_clk *)clk;
59
60 if (!(clk->flags & CLOCK_IDLE_CONTROL))
61 return;
62
63 if (iclk->no_idle_count > 0 && !(--iclk->no_idle_count))
64 arm_idlect1_mask |= 1 << iclk->idlect_shift;
65}
66
67static void omap1_clk_deny_idle(struct clk *clk)
68{
69 struct arm_idlect1_clk * iclk = (struct arm_idlect1_clk *)clk;
70
71 if (!(clk->flags & CLOCK_IDLE_CONTROL))
72 return;
73
74 if (iclk->no_idle_count++ == 0)
75 arm_idlect1_mask &= ~(1 << iclk->idlect_shift);
76}
77
78static __u16 verify_ckctl_value(__u16 newval)
79{
80 /* This function checks for following limitations set
81 * by the hardware (all conditions must be true):
82 * DSPMMU_CK == DSP_CK or DSPMMU_CK == DSP_CK/2
83 * ARM_CK >= TC_CK
84 * DSP_CK >= TC_CK
85 * DSPMMU_CK >= TC_CK
86 *
87 * In addition following rules are enforced:
88 * LCD_CK <= TC_CK
89 * ARMPER_CK <= TC_CK
90 *
91 * However, maximum frequencies are not checked for!
92 */
93 __u8 per_exp;
94 __u8 lcd_exp;
95 __u8 arm_exp;
96 __u8 dsp_exp;
97 __u8 tc_exp;
98 __u8 dspmmu_exp;
99
100 per_exp = (newval >> CKCTL_PERDIV_OFFSET) & 3;
101 lcd_exp = (newval >> CKCTL_LCDDIV_OFFSET) & 3;
102 arm_exp = (newval >> CKCTL_ARMDIV_OFFSET) & 3;
103 dsp_exp = (newval >> CKCTL_DSPDIV_OFFSET) & 3;
104 tc_exp = (newval >> CKCTL_TCDIV_OFFSET) & 3;
105 dspmmu_exp = (newval >> CKCTL_DSPMMUDIV_OFFSET) & 3;
106
107 if (dspmmu_exp < dsp_exp)
108 dspmmu_exp = dsp_exp;
109 if (dspmmu_exp > dsp_exp+1)
110 dspmmu_exp = dsp_exp+1;
111 if (tc_exp < arm_exp)
112 tc_exp = arm_exp;
113 if (tc_exp < dspmmu_exp)
114 tc_exp = dspmmu_exp;
115 if (tc_exp > lcd_exp)
116 lcd_exp = tc_exp;
117 if (tc_exp > per_exp)
118 per_exp = tc_exp;
119
120 newval &= 0xf000;
121 newval |= per_exp << CKCTL_PERDIV_OFFSET;
122 newval |= lcd_exp << CKCTL_LCDDIV_OFFSET;
123 newval |= arm_exp << CKCTL_ARMDIV_OFFSET;
124 newval |= dsp_exp << CKCTL_DSPDIV_OFFSET;
125 newval |= tc_exp << CKCTL_TCDIV_OFFSET;
126 newval |= dspmmu_exp << CKCTL_DSPMMUDIV_OFFSET;
127
128 return newval;
129}
130
131static int calc_dsor_exp(struct clk *clk, unsigned long rate)
132{
133 /* Note: If target frequency is too low, this function will return 4,
134 * which is invalid value. Caller must check for this value and act
135 * accordingly.
136 *
137 * Note: This function does not check for following limitations set
138 * by the hardware (all conditions must be true):
139 * DSPMMU_CK == DSP_CK or DSPMMU_CK == DSP_CK/2
140 * ARM_CK >= TC_CK
141 * DSP_CK >= TC_CK
142 * DSPMMU_CK >= TC_CK
143 */
144 unsigned long realrate;
145 struct clk * parent;
146 unsigned dsor_exp;
147
Tony Lindgren3179a012005-11-10 14:26:48 +0000148 parent = clk->parent;
Russell Kingc0fc18c52008-09-05 15:10:27 +0100149 if (unlikely(parent == NULL))
Tony Lindgren3179a012005-11-10 14:26:48 +0000150 return -EIO;
151
152 realrate = parent->rate;
153 for (dsor_exp=0; dsor_exp<4; dsor_exp++) {
154 if (realrate <= rate)
155 break;
156
157 realrate /= 2;
158 }
159
160 return dsor_exp;
161}
162
Paul Walmsley52650502009-12-08 16:29:38 -0700163unsigned long omap1_ckctl_recalc(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000164{
Tony Lindgren3179a012005-11-10 14:26:48 +0000165 /* Calculate divisor encoded as 2-bit exponent */
Russell King8b9dbc12009-02-12 10:12:59 +0000166 int dsor = 1 << (3 & (omap_readw(ARM_CKCTL) >> clk->rate_offset));
Tony Lindgren3179a012005-11-10 14:26:48 +0000167
Russell King8b9dbc12009-02-12 10:12:59 +0000168 return clk->parent->rate / dsor;
Tony Lindgren3179a012005-11-10 14:26:48 +0000169}
170
Paul Walmsley52650502009-12-08 16:29:38 -0700171unsigned long omap1_ckctl_recalc_dsp_domain(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000172{
173 int dsor;
174
175 /* Calculate divisor encoded as 2-bit exponent
176 *
177 * The clock control bits are in DSP domain,
178 * so api_ck is needed for access.
179 * Note that DSP_CKCTL virt addr = phys addr, so
180 * we must use __raw_readw() instead of omap_readw().
181 */
Paul Walmsley52650502009-12-08 16:29:38 -0700182 omap1_clk_enable(api_ck_p);
Tony Lindgren3179a012005-11-10 14:26:48 +0000183 dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset));
Paul Walmsley52650502009-12-08 16:29:38 -0700184 omap1_clk_disable(api_ck_p);
Tony Lindgren3179a012005-11-10 14:26:48 +0000185
Russell King8b9dbc12009-02-12 10:12:59 +0000186 return clk->parent->rate / dsor;
Tony Lindgren3179a012005-11-10 14:26:48 +0000187}
188
189/* MPU virtual clock functions */
Paul Walmsley52650502009-12-08 16:29:38 -0700190int omap1_select_table_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000191{
192 /* Find the highest supported frequency <= rate and switch to it */
193 struct mpu_rate * ptr;
Paul Walmsley52650502009-12-08 16:29:38 -0700194 unsigned long dpll1_rate, ref_rate;
Tony Lindgren3179a012005-11-10 14:26:48 +0000195
Paul Walmsleyaf022fa2010-01-19 17:30:55 -0700196 dpll1_rate = ck_dpll1_p->rate;
197 ref_rate = ck_ref_p->rate;
Paul Walmsley52650502009-12-08 16:29:38 -0700198
199 for (ptr = omap1_rate_table; ptr->rate; ptr++) {
Janusz Krzysztofik24ce2702011-12-08 18:01:41 -0800200 if (!(ptr->flags & cpu_mask))
201 continue;
202
Paul Walmsley52650502009-12-08 16:29:38 -0700203 if (ptr->xtal != ref_rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000204 continue;
205
206 /* DPLL1 cannot be reprogrammed without risking system crash */
Paul Walmsley52650502009-12-08 16:29:38 -0700207 if (likely(dpll1_rate != 0) && ptr->pll_rate != dpll1_rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000208 continue;
209
210 /* Can check only after xtal frequency check */
211 if (ptr->rate <= rate)
212 break;
213 }
214
215 if (!ptr->rate)
216 return -EINVAL;
217
218 /*
219 * In most cases we should not need to reprogram DPLL.
220 * Reprogramming the DPLL is tricky, it must be done from SRAM.
221 */
Janusz Krzysztofikf9e59082011-12-01 22:16:26 +0100222 omap_sram_reprogram_clock(ptr->dpllctl_val, ptr->ckctl_val);
Tony Lindgren3179a012005-11-10 14:26:48 +0000223
Paul Walmsley52650502009-12-08 16:29:38 -0700224 /* XXX Do we need to recalculate the tree below DPLL1 at this point? */
225 ck_dpll1_p->rate = ptr->pll_rate;
226
Tony Lindgren3179a012005-11-10 14:26:48 +0000227 return 0;
228}
229
Paul Walmsley52650502009-12-08 16:29:38 -0700230int omap1_clk_set_rate_dsp_domain(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000231{
Russell Kingd5e60722009-02-08 16:07:46 +0000232 int dsor_exp;
233 u16 regval;
Tony Lindgren3179a012005-11-10 14:26:48 +0000234
Russell Kingd5e60722009-02-08 16:07:46 +0000235 dsor_exp = calc_dsor_exp(clk, rate);
236 if (dsor_exp > 3)
237 dsor_exp = -EINVAL;
238 if (dsor_exp < 0)
239 return dsor_exp;
Tony Lindgren3179a012005-11-10 14:26:48 +0000240
Russell Kingd5e60722009-02-08 16:07:46 +0000241 regval = __raw_readw(DSP_CKCTL);
242 regval &= ~(3 << clk->rate_offset);
243 regval |= dsor_exp << clk->rate_offset;
244 __raw_writew(regval, DSP_CKCTL);
245 clk->rate = clk->parent->rate / (1 << dsor_exp);
Tony Lindgren3179a012005-11-10 14:26:48 +0000246
Russell Kingd5e60722009-02-08 16:07:46 +0000247 return 0;
248}
249
Paul Walmsley52650502009-12-08 16:29:38 -0700250long omap1_clk_round_rate_ckctl_arm(struct clk *clk, unsigned long rate)
Russell Kingd5e60722009-02-08 16:07:46 +0000251{
252 int dsor_exp = calc_dsor_exp(clk, rate);
253 if (dsor_exp < 0)
254 return dsor_exp;
255 if (dsor_exp > 3)
256 dsor_exp = 3;
257 return clk->parent->rate / (1 << dsor_exp);
258}
259
Paul Walmsley52650502009-12-08 16:29:38 -0700260int omap1_clk_set_rate_ckctl_arm(struct clk *clk, unsigned long rate)
Russell Kingd5e60722009-02-08 16:07:46 +0000261{
262 int dsor_exp;
263 u16 regval;
264
265 dsor_exp = calc_dsor_exp(clk, rate);
266 if (dsor_exp > 3)
267 dsor_exp = -EINVAL;
268 if (dsor_exp < 0)
269 return dsor_exp;
270
271 regval = omap_readw(ARM_CKCTL);
272 regval &= ~(3 << clk->rate_offset);
273 regval |= dsor_exp << clk->rate_offset;
274 regval = verify_ckctl_value(regval);
275 omap_writew(regval, ARM_CKCTL);
276 clk->rate = clk->parent->rate / (1 << dsor_exp);
277 return 0;
Tony Lindgren3179a012005-11-10 14:26:48 +0000278}
279
Paul Walmsley52650502009-12-08 16:29:38 -0700280long omap1_round_to_table_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000281{
282 /* Find the highest supported frequency <= rate */
283 struct mpu_rate * ptr;
Paul Walmsley52650502009-12-08 16:29:38 -0700284 long highest_rate;
285 unsigned long ref_rate;
286
Paul Walmsleyaf022fa2010-01-19 17:30:55 -0700287 ref_rate = ck_ref_p->rate;
Tony Lindgren3179a012005-11-10 14:26:48 +0000288
Tony Lindgren3179a012005-11-10 14:26:48 +0000289 highest_rate = -EINVAL;
290
Paul Walmsley52650502009-12-08 16:29:38 -0700291 for (ptr = omap1_rate_table; ptr->rate; ptr++) {
Janusz Krzysztofik24ce2702011-12-08 18:01:41 -0800292 if (!(ptr->flags & cpu_mask))
293 continue;
294
Paul Walmsley52650502009-12-08 16:29:38 -0700295 if (ptr->xtal != ref_rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000296 continue;
297
298 highest_rate = ptr->rate;
299
300 /* Can check only after xtal frequency check */
301 if (ptr->rate <= rate)
302 break;
303 }
304
305 return highest_rate;
306}
307
308static unsigned calc_ext_dsor(unsigned long rate)
309{
310 unsigned dsor;
311
312 /* MCLK and BCLK divisor selection is not linear:
313 * freq = 96MHz / dsor
314 *
315 * RATIO_SEL range: dsor <-> RATIO_SEL
316 * 0..6: (RATIO_SEL+2) <-> (dsor-2)
317 * 6..48: (8+(RATIO_SEL-6)*2) <-> ((dsor-8)/2+6)
318 * Minimum dsor is 2 and maximum is 96. Odd divisors starting from 9
319 * can not be used.
320 */
321 for (dsor = 2; dsor < 96; ++dsor) {
322 if ((dsor & 1) && dsor > 8)
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100323 continue;
Tony Lindgren3179a012005-11-10 14:26:48 +0000324 if (rate >= 96000000 / dsor)
325 break;
326 }
327 return dsor;
328}
329
Paul Walmsley52650502009-12-08 16:29:38 -0700330/* XXX Only needed on 1510 */
331int omap1_set_uart_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000332{
333 unsigned int val;
334
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700335 val = __raw_readl(clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000336 if (rate == 12000000)
337 val &= ~(1 << clk->enable_bit);
338 else if (rate == 48000000)
339 val |= (1 << clk->enable_bit);
340 else
341 return -EINVAL;
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700342 __raw_writel(val, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000343 clk->rate = rate;
344
345 return 0;
346}
347
348/* External clock (MCLK & BCLK) functions */
Paul Walmsley52650502009-12-08 16:29:38 -0700349int omap1_set_ext_clk_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000350{
351 unsigned dsor;
352 __u16 ratio_bits;
353
354 dsor = calc_ext_dsor(rate);
355 clk->rate = 96000000 / dsor;
356 if (dsor > 8)
357 ratio_bits = ((dsor - 8) / 2 + 6) << 2;
358 else
359 ratio_bits = (dsor - 2) << 2;
360
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700361 ratio_bits |= __raw_readw(clk->enable_reg) & ~0xfd;
362 __raw_writew(ratio_bits, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000363
364 return 0;
365}
366
Paul Walmsley52650502009-12-08 16:29:38 -0700367int omap1_set_sossi_rate(struct clk *clk, unsigned long rate)
Imre Deakdf2c2e72007-03-05 17:22:58 +0200368{
369 u32 l;
370 int div;
371 unsigned long p_rate;
372
373 p_rate = clk->parent->rate;
374 /* Round towards slower frequency */
375 div = (p_rate + rate - 1) / rate;
376 div--;
377 if (div < 0 || div > 7)
378 return -EINVAL;
379
380 l = omap_readl(MOD_CONF_CTRL_1);
381 l &= ~(7 << 17);
382 l |= div << 17;
383 omap_writel(l, MOD_CONF_CTRL_1);
384
385 clk->rate = p_rate / (div + 1);
Imre Deakdf2c2e72007-03-05 17:22:58 +0200386
387 return 0;
388}
389
Paul Walmsley52650502009-12-08 16:29:38 -0700390long omap1_round_ext_clk_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000391{
392 return 96000000 / calc_ext_dsor(rate);
393}
394
Paul Walmsley52650502009-12-08 16:29:38 -0700395void omap1_init_ext_clk(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000396{
397 unsigned dsor;
398 __u16 ratio_bits;
399
400 /* Determine current rate and ensure clock is based on 96MHz APLL */
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700401 ratio_bits = __raw_readw(clk->enable_reg) & ~1;
402 __raw_writew(ratio_bits, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000403
404 ratio_bits = (ratio_bits & 0xfc) >> 2;
405 if (ratio_bits > 6)
406 dsor = (ratio_bits - 6) * 2 + 8;
407 else
408 dsor = ratio_bits + 2;
409
410 clk-> rate = 96000000 / dsor;
411}
412
Paul Walmsley52650502009-12-08 16:29:38 -0700413int omap1_clk_enable(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000414{
415 int ret = 0;
Tony Lindgren3179a012005-11-10 14:26:48 +0000416
Russell King3ef48fa2009-04-05 12:27:24 +0100417 if (clk->usecount++ == 0) {
418 if (clk->parent) {
419 ret = omap1_clk_enable(clk->parent);
420 if (ret)
421 goto err;
Tony Lindgren3179a012005-11-10 14:26:48 +0000422
423 if (clk->flags & CLOCK_NO_IDLE_PARENT)
Dirk Behme6f9c92f2006-12-06 17:13:51 -0800424 omap1_clk_deny_idle(clk->parent);
Tony Lindgren3179a012005-11-10 14:26:48 +0000425 }
426
Russell King548d8492008-11-04 14:02:46 +0000427 ret = clk->ops->enable(clk);
Russell King3ef48fa2009-04-05 12:27:24 +0100428 if (ret) {
429 if (clk->parent)
430 omap1_clk_disable(clk->parent);
431 goto err;
Tony Lindgren3179a012005-11-10 14:26:48 +0000432 }
433 }
Russell King3ef48fa2009-04-05 12:27:24 +0100434 return ret;
Tony Lindgren3179a012005-11-10 14:26:48 +0000435
Russell King3ef48fa2009-04-05 12:27:24 +0100436err:
437 clk->usecount--;
Tony Lindgren3179a012005-11-10 14:26:48 +0000438 return ret;
439}
440
Paul Walmsley52650502009-12-08 16:29:38 -0700441void omap1_clk_disable(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000442{
443 if (clk->usecount > 0 && !(--clk->usecount)) {
Russell King548d8492008-11-04 14:02:46 +0000444 clk->ops->disable(clk);
Tony Lindgren3179a012005-11-10 14:26:48 +0000445 if (likely(clk->parent)) {
Tony Lindgren10b55792006-01-17 15:30:42 -0800446 omap1_clk_disable(clk->parent);
Tony Lindgren3179a012005-11-10 14:26:48 +0000447 if (clk->flags & CLOCK_NO_IDLE_PARENT)
Dirk Behme6f9c92f2006-12-06 17:13:51 -0800448 omap1_clk_allow_idle(clk->parent);
Tony Lindgren3179a012005-11-10 14:26:48 +0000449 }
450 }
451}
452
Tony Lindgren10b55792006-01-17 15:30:42 -0800453static int omap1_clk_enable_generic(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000454{
455 __u16 regval16;
456 __u32 regval32;
457
Russell Kingc0fc18c52008-09-05 15:10:27 +0100458 if (unlikely(clk->enable_reg == NULL)) {
Tony Lindgren3179a012005-11-10 14:26:48 +0000459 printk(KERN_ERR "clock.c: Enable for %s without enable code\n",
460 clk->name);
Dirk Behme6f9c92f2006-12-06 17:13:51 -0800461 return -EINVAL;
Tony Lindgren3179a012005-11-10 14:26:48 +0000462 }
463
464 if (clk->flags & ENABLE_REG_32BIT) {
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700465 regval32 = __raw_readl(clk->enable_reg);
466 regval32 |= (1 << clk->enable_bit);
467 __raw_writel(regval32, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000468 } else {
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700469 regval16 = __raw_readw(clk->enable_reg);
470 regval16 |= (1 << clk->enable_bit);
471 __raw_writew(regval16, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000472 }
473
Dirk Behme6f9c92f2006-12-06 17:13:51 -0800474 return 0;
Tony Lindgren3179a012005-11-10 14:26:48 +0000475}
476
Tony Lindgren10b55792006-01-17 15:30:42 -0800477static void omap1_clk_disable_generic(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000478{
479 __u16 regval16;
480 __u32 regval32;
481
Russell Kingc0fc18c52008-09-05 15:10:27 +0100482 if (clk->enable_reg == NULL)
Tony Lindgren3179a012005-11-10 14:26:48 +0000483 return;
484
485 if (clk->flags & ENABLE_REG_32BIT) {
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700486 regval32 = __raw_readl(clk->enable_reg);
487 regval32 &= ~(1 << clk->enable_bit);
488 __raw_writel(regval32, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000489 } else {
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700490 regval16 = __raw_readw(clk->enable_reg);
491 regval16 &= ~(1 << clk->enable_bit);
492 __raw_writew(regval16, clk->enable_reg);
Tony Lindgren3179a012005-11-10 14:26:48 +0000493 }
494}
495
Paul Walmsley52650502009-12-08 16:29:38 -0700496const struct clkops clkops_generic = {
497 .enable = omap1_clk_enable_generic,
498 .disable = omap1_clk_disable_generic,
Russell King548d8492008-11-04 14:02:46 +0000499};
500
Paul Walmsley52650502009-12-08 16:29:38 -0700501static int omap1_clk_enable_dsp_domain(struct clk *clk)
502{
503 int retval;
504
505 retval = omap1_clk_enable(api_ck_p);
506 if (!retval) {
507 retval = omap1_clk_enable_generic(clk);
508 omap1_clk_disable(api_ck_p);
509 }
510
511 return retval;
512}
513
514static void omap1_clk_disable_dsp_domain(struct clk *clk)
515{
516 if (omap1_clk_enable(api_ck_p) == 0) {
517 omap1_clk_disable_generic(clk);
518 omap1_clk_disable(api_ck_p);
519 }
520}
521
522const struct clkops clkops_dspck = {
523 .enable = omap1_clk_enable_dsp_domain,
524 .disable = omap1_clk_disable_dsp_domain,
525};
526
Paul Walmsleyfb2fc922010-07-26 16:34:28 -0600527/* XXX SYSC register handling does not belong in the clock framework */
528static int omap1_clk_enable_uart_functional_16xx(struct clk *clk)
Paul Walmsley52650502009-12-08 16:29:38 -0700529{
530 int ret;
531 struct uart_clk *uclk;
532
533 ret = omap1_clk_enable_generic(clk);
534 if (ret == 0) {
535 /* Set smart idle acknowledgement mode */
536 uclk = (struct uart_clk *)clk;
537 omap_writeb((omap_readb(uclk->sysc_addr) & ~0x10) | 8,
538 uclk->sysc_addr);
539 }
540
541 return ret;
542}
543
Paul Walmsleyfb2fc922010-07-26 16:34:28 -0600544/* XXX SYSC register handling does not belong in the clock framework */
545static void omap1_clk_disable_uart_functional_16xx(struct clk *clk)
Paul Walmsley52650502009-12-08 16:29:38 -0700546{
547 struct uart_clk *uclk;
548
549 /* Set force idle acknowledgement mode */
550 uclk = (struct uart_clk *)clk;
551 omap_writeb((omap_readb(uclk->sysc_addr) & ~0x18), uclk->sysc_addr);
552
553 omap1_clk_disable_generic(clk);
554}
555
Paul Walmsleyfb2fc922010-07-26 16:34:28 -0600556/* XXX SYSC register handling does not belong in the clock framework */
557const struct clkops clkops_uart_16xx = {
558 .enable = omap1_clk_enable_uart_functional_16xx,
559 .disable = omap1_clk_disable_uart_functional_16xx,
Paul Walmsley52650502009-12-08 16:29:38 -0700560};
561
562long omap1_clk_round_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000563{
Russell Kingc0fc18c52008-09-05 15:10:27 +0100564 if (clk->round_rate != NULL)
Tony Lindgren3179a012005-11-10 14:26:48 +0000565 return clk->round_rate(clk, rate);
566
567 return clk->rate;
568}
569
Paul Walmsley52650502009-12-08 16:29:38 -0700570int omap1_clk_set_rate(struct clk *clk, unsigned long rate)
Tony Lindgren3179a012005-11-10 14:26:48 +0000571{
572 int ret = -EINVAL;
Tony Lindgren3179a012005-11-10 14:26:48 +0000573
574 if (clk->set_rate)
575 ret = clk->set_rate(clk, rate);
Tony Lindgren3179a012005-11-10 14:26:48 +0000576 return ret;
577}
578
Paul Walmsleyfb2fc922010-07-26 16:34:28 -0600579/*
Tony Lindgren3179a012005-11-10 14:26:48 +0000580 * Omap1 clock reset and init functions
Paul Walmsleyfb2fc922010-07-26 16:34:28 -0600581 */
Tony Lindgren3179a012005-11-10 14:26:48 +0000582
583#ifdef CONFIG_OMAP_RESET_CLOCKS
Tony Lindgren3179a012005-11-10 14:26:48 +0000584
Felipe Balbi5838bb62010-05-20 12:31:04 -0600585void omap1_clk_disable_unused(struct clk *clk)
Tony Lindgren3179a012005-11-10 14:26:48 +0000586{
Tony Lindgren3179a012005-11-10 14:26:48 +0000587 __u32 regval32;
588
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300589 /* Clocks in the DSP domain need api_ck. Just assume bootloader
590 * has not enabled any DSP clocks */
Russell King397fcaf2008-09-05 15:46:19 +0100591 if (clk->enable_reg == DSP_IDLECT2) {
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300592 printk(KERN_INFO "Skipping reset check for DSP domain "
593 "clock \"%s\"\n", clk->name);
594 return;
Tony Lindgren3179a012005-11-10 14:26:48 +0000595 }
596
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300597 /* Is the clock already disabled? */
Tony Lindgrenfed415e2009-01-28 12:18:48 -0700598 if (clk->flags & ENABLE_REG_32BIT)
599 regval32 = __raw_readl(clk->enable_reg);
600 else
601 regval32 = __raw_readw(clk->enable_reg);
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300602
603 if ((regval32 & (1 << clk->enable_bit)) == 0)
604 return;
605
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300606 printk(KERN_INFO "Disabling unused clock \"%s\"... ", clk->name);
Russell King548d8492008-11-04 14:02:46 +0000607 clk->ops->disable(clk);
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300608 printk(" done\n");
Tony Lindgren3179a012005-11-10 14:26:48 +0000609}
Tony Lindgren3179a012005-11-10 14:26:48 +0000610
Tony Lindgren3179a012005-11-10 14:26:48 +0000611#endif