2 * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <linux/delay.h>
21 #include <linux/clk.h>
23 #include <linux/jiffies.h>
24 #include <linux/clkdev.h>
25 #include <linux/spinlock.h>
27 #include <asm/clkdev.h>
28 #include <asm/div64.h>
30 #include <mach/mx28.h>
31 #include <mach/common.h>
32 #include <mach/clock.h>
33 #include <mach/digctl.h>
35 #include "regs-clkctrl-mx28.h"
37 #define CLKCTRL_BASE_ADDR MX28_IO_ADDRESS(MX28_CLKCTRL_BASE_ADDR)
38 #define DIGCTRL_BASE_ADDR MX28_IO_ADDRESS(MX28_DIGCTL_BASE_ADDR)
40 #define PARENT_RATE_SHIFT 8
42 static struct clk pll2_clk
;
43 static struct clk cpu_clk
;
44 static struct clk emi_clk
;
45 static struct clk saif0_clk
;
46 static struct clk saif1_clk
;
47 static struct clk clk32k_clk
;
48 static DEFINE_SPINLOCK(clkmux_lock
);
52 * DIRECT(0x0): SAIF0 clock pins selected for SAIF0 input clocks, and SAIF1
53 * clock pins selected for SAIF1 input clocks.
54 * CROSSINPUT(0x1): SAIF1 clock inputs selected for SAIF0 input clocks, and
55 * SAIF0 clock inputs selected for SAIF1 input clocks.
56 * EXTMSTR0(0x2): SAIF0 clock pin selected for both SAIF0 and SAIF1 input
58 * EXTMSTR1(0x3): SAIF1 clock pin selected for both SAIF0 and SAIF1 input
61 int mxs_saif_clkmux_select(unsigned int clkmux
)
66 spin_lock(&clkmux_lock
);
67 __raw_writel(BM_DIGCTL_CTRL_SAIF_CLKMUX
,
68 DIGCTRL_BASE_ADDR
+ HW_DIGCTL_CTRL
+ MXS_CLR_ADDR
);
69 __raw_writel(clkmux
<< BP_DIGCTL_CTRL_SAIF_CLKMUX
,
70 DIGCTRL_BASE_ADDR
+ HW_DIGCTL_CTRL
+ MXS_SET_ADDR
);
71 spin_unlock(&clkmux_lock
);
76 static int _raw_clk_enable(struct clk
*clk
)
80 if (clk
->enable_reg
) {
81 reg
= __raw_readl(clk
->enable_reg
);
82 reg
&= ~(1 << clk
->enable_shift
);
83 __raw_writel(reg
, clk
->enable_reg
);
89 static void _raw_clk_disable(struct clk
*clk
)
93 if (clk
->enable_reg
) {
94 reg
= __raw_readl(clk
->enable_reg
);
95 reg
|= 1 << clk
->enable_shift
;
96 __raw_writel(reg
, clk
->enable_reg
);
103 static unsigned long ref_xtal_clk_get_rate(struct clk
*clk
)
108 static struct clk ref_xtal_clk
= {
109 .get_rate
= ref_xtal_clk_get_rate
,
115 static unsigned long pll0_clk_get_rate(struct clk
*clk
)
120 static unsigned long pll1_clk_get_rate(struct clk
*clk
)
125 static unsigned long pll2_clk_get_rate(struct clk
*clk
)
130 #define _CLK_ENABLE_PLL(name, r, g) \
131 static int name##_enable(struct clk *clk) \
133 __raw_writel(BM_CLKCTRL_##r##CTRL0_POWER, \
134 CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_SET); \
137 if (clk == &pll2_clk) \
138 __raw_writel(BM_CLKCTRL_##r##CTRL0_##g, \
139 CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR); \
141 __raw_writel(BM_CLKCTRL_##r##CTRL0_##g, \
142 CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_SET); \
147 _CLK_ENABLE_PLL(pll0_clk
, PLL0
, EN_USB_CLKS
)
148 _CLK_ENABLE_PLL(pll1_clk
, PLL1
, EN_USB_CLKS
)
149 _CLK_ENABLE_PLL(pll2_clk
, PLL2
, CLKGATE
)
151 #define _CLK_DISABLE_PLL(name, r, g) \
152 static void name##_disable(struct clk *clk) \
154 __raw_writel(BM_CLKCTRL_##r##CTRL0_POWER, \
155 CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR); \
157 if (clk == &pll2_clk) \
158 __raw_writel(BM_CLKCTRL_##r##CTRL0_##g, \
159 CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_SET); \
161 __raw_writel(BM_CLKCTRL_##r##CTRL0_##g, \
162 CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR); \
166 _CLK_DISABLE_PLL(pll0_clk
, PLL0
, EN_USB_CLKS
)
167 _CLK_DISABLE_PLL(pll1_clk
, PLL1
, EN_USB_CLKS
)
168 _CLK_DISABLE_PLL(pll2_clk
, PLL2
, CLKGATE
)
170 #define _DEFINE_CLOCK_PLL(name) \
171 static struct clk name = { \
172 .get_rate = name##_get_rate, \
173 .enable = name##_enable, \
174 .disable = name##_disable, \
175 .parent = &ref_xtal_clk, \
178 _DEFINE_CLOCK_PLL(pll0_clk
);
179 _DEFINE_CLOCK_PLL(pll1_clk
);
180 _DEFINE_CLOCK_PLL(pll2_clk
);
185 #define _CLK_GET_RATE_REF(name, sr, ss) \
186 static unsigned long name##_get_rate(struct clk *clk) \
188 unsigned long parent_rate; \
191 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##sr); \
192 div = (reg >> BP_CLKCTRL_##sr##_##ss##FRAC) & 0x3f; \
193 parent_rate = clk_get_rate(clk->parent); \
195 return SH_DIV((parent_rate >> PARENT_RATE_SHIFT) * 18, \
196 div, PARENT_RATE_SHIFT); \
199 _CLK_GET_RATE_REF(ref_cpu_clk
, FRAC0
, CPU
)
200 _CLK_GET_RATE_REF(ref_emi_clk
, FRAC0
, EMI
)
201 _CLK_GET_RATE_REF(ref_io0_clk
, FRAC0
, IO0
)
202 _CLK_GET_RATE_REF(ref_io1_clk
, FRAC0
, IO1
)
203 _CLK_GET_RATE_REF(ref_pix_clk
, FRAC1
, PIX
)
204 _CLK_GET_RATE_REF(ref_gpmi_clk
, FRAC1
, GPMI
)
206 #define _DEFINE_CLOCK_REF(name, er, es) \
207 static struct clk name = { \
208 .enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er, \
209 .enable_shift = BP_CLKCTRL_##er##_CLKGATE##es, \
210 .get_rate = name##_get_rate, \
211 .enable = _raw_clk_enable, \
212 .disable = _raw_clk_disable, \
213 .parent = &pll0_clk, \
216 _DEFINE_CLOCK_REF(ref_cpu_clk
, FRAC0
, CPU
);
217 _DEFINE_CLOCK_REF(ref_emi_clk
, FRAC0
, EMI
);
218 _DEFINE_CLOCK_REF(ref_io0_clk
, FRAC0
, IO0
);
219 _DEFINE_CLOCK_REF(ref_io1_clk
, FRAC0
, IO1
);
220 _DEFINE_CLOCK_REF(ref_pix_clk
, FRAC1
, PIX
);
221 _DEFINE_CLOCK_REF(ref_gpmi_clk
, FRAC1
, GPMI
);
228 static unsigned long lradc_clk_get_rate(struct clk
*clk
)
230 return clk_get_rate(clk
->parent
) / 16;
233 static unsigned long rtc_clk_get_rate(struct clk
*clk
)
235 /* ref_xtal_clk is implemented as the only parent */
236 return clk_get_rate(clk
->parent
) / 768;
239 static unsigned long clk32k_clk_get_rate(struct clk
*clk
)
241 return clk
->parent
->get_rate(clk
->parent
) / 750;
244 static unsigned long spdif_clk_get_rate(struct clk
*clk
)
246 return clk_get_rate(clk
->parent
) / 4;
249 #define _CLK_GET_RATE(name, rs) \
250 static unsigned long name##_get_rate(struct clk *clk) \
254 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs); \
256 if (clk->parent == &ref_xtal_clk) \
257 div = (reg & BM_CLKCTRL_##rs##_DIV_XTAL) >> \
258 BP_CLKCTRL_##rs##_DIV_XTAL; \
260 div = (reg & BM_CLKCTRL_##rs##_DIV_##rs) >> \
261 BP_CLKCTRL_##rs##_DIV_##rs; \
266 return clk_get_rate(clk->parent) / div; \
269 _CLK_GET_RATE(cpu_clk
, CPU
)
270 _CLK_GET_RATE(emi_clk
, EMI
)
272 #define _CLK_GET_RATE1(name, rs) \
273 static unsigned long name##_get_rate(struct clk *clk) \
277 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs); \
278 div = (reg & BM_CLKCTRL_##rs##_DIV) >> BP_CLKCTRL_##rs##_DIV; \
283 if (clk == &saif0_clk || clk == &saif1_clk) \
284 return clk_get_rate(clk->parent) >> 16 * div; \
286 return clk_get_rate(clk->parent) / div; \
289 _CLK_GET_RATE1(hbus_clk
, HBUS
)
290 _CLK_GET_RATE1(xbus_clk
, XBUS
)
291 _CLK_GET_RATE1(ssp0_clk
, SSP0
)
292 _CLK_GET_RATE1(ssp1_clk
, SSP1
)
293 _CLK_GET_RATE1(ssp2_clk
, SSP2
)
294 _CLK_GET_RATE1(ssp3_clk
, SSP3
)
295 _CLK_GET_RATE1(gpmi_clk
, GPMI
)
296 _CLK_GET_RATE1(lcdif_clk
, DIS_LCDIF
)
297 _CLK_GET_RATE1(saif0_clk
, SAIF0
)
298 _CLK_GET_RATE1(saif1_clk
, SAIF1
)
300 #define _CLK_GET_RATE_STUB(name) \
301 static unsigned long name##_get_rate(struct clk *clk) \
303 return clk_get_rate(clk->parent); \
306 _CLK_GET_RATE_STUB(uart_clk
)
307 _CLK_GET_RATE_STUB(pwm_clk
)
308 _CLK_GET_RATE_STUB(can0_clk
)
309 _CLK_GET_RATE_STUB(can1_clk
)
310 _CLK_GET_RATE_STUB(fec_clk
)
316 #define BM_CLKCTRL_CPU_DIV 0
317 #define BP_CLKCTRL_CPU_DIV 0
318 #define BM_CLKCTRL_CPU_BUSY 0
320 #define _CLK_SET_RATE(name, dr, fr, fs) \
321 static int name##_set_rate(struct clk *clk, unsigned long rate) \
323 u32 reg, bm_busy, div_max, d, f, div, frac; \
324 unsigned long diff, parent_rate, calc_rate; \
327 div_max = BM_CLKCTRL_##dr##_DIV >> BP_CLKCTRL_##dr##_DIV; \
328 bm_busy = BM_CLKCTRL_##dr##_BUSY; \
330 if (clk->parent == &ref_xtal_clk) { \
331 parent_rate = clk_get_rate(clk->parent); \
332 div = DIV_ROUND_UP(parent_rate, rate); \
333 if (clk == &cpu_clk) { \
334 div_max = BM_CLKCTRL_CPU_DIV_XTAL >> \
335 BP_CLKCTRL_CPU_DIV_XTAL; \
336 bm_busy = BM_CLKCTRL_CPU_BUSY_REF_XTAL; \
338 if (div == 0 || div > div_max) \
342 * hack alert: this block modifies clk->parent, too, \
343 * so the base to use it the grand parent. \
345 parent_rate = clk_get_rate(clk->parent->parent); \
346 rate >>= PARENT_RATE_SHIFT; \
347 parent_rate >>= PARENT_RATE_SHIFT; \
348 diff = parent_rate; \
350 if (clk == &cpu_clk) { \
351 div_max = BM_CLKCTRL_CPU_DIV_CPU >> \
352 BP_CLKCTRL_CPU_DIV_CPU; \
353 bm_busy = BM_CLKCTRL_CPU_BUSY_REF_CPU; \
355 for (d = 1; d <= div_max; d++) { \
356 f = parent_rate * 18 / d / rate; \
357 if ((parent_rate * 18 / d) % rate) \
359 if (f < 18 || f > 35) \
362 calc_rate = parent_rate * 18 / f / d; \
363 if (calc_rate > rate) \
366 if (rate - calc_rate < diff) { \
369 diff = rate - calc_rate; \
376 if (diff == parent_rate) \
379 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##fr); \
380 reg &= ~BM_CLKCTRL_##fr##_##fs##FRAC; \
381 reg |= frac << BP_CLKCTRL_##fr##_##fs##FRAC; \
382 __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_##fr); \
385 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr); \
386 if (clk == &cpu_clk) { \
387 reg &= ~BM_CLKCTRL_CPU_DIV_CPU; \
388 reg |= div << BP_CLKCTRL_CPU_DIV_CPU; \
390 reg &= ~BM_CLKCTRL_##dr##_DIV; \
391 reg |= div << BP_CLKCTRL_##dr##_DIV; \
392 if (reg & (1 << clk->enable_shift)) { \
393 pr_err("%s: clock is gated\n", __func__); \
397 __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr); \
399 for (i = 10000; i; i--) \
400 if (!(__raw_readl(CLKCTRL_BASE_ADDR + \
401 HW_CLKCTRL_##dr) & bm_busy)) \
404 pr_err("%s: divider writing timeout\n", __func__); \
411 _CLK_SET_RATE(cpu_clk
, CPU
, FRAC0
, CPU
)
412 _CLK_SET_RATE(ssp0_clk
, SSP0
, FRAC0
, IO0
)
413 _CLK_SET_RATE(ssp1_clk
, SSP1
, FRAC0
, IO0
)
414 _CLK_SET_RATE(ssp2_clk
, SSP2
, FRAC0
, IO1
)
415 _CLK_SET_RATE(ssp3_clk
, SSP3
, FRAC0
, IO1
)
416 _CLK_SET_RATE(lcdif_clk
, DIS_LCDIF
, FRAC1
, PIX
)
417 _CLK_SET_RATE(gpmi_clk
, GPMI
, FRAC1
, GPMI
)
419 #define _CLK_SET_RATE1(name, dr) \
420 static int name##_set_rate(struct clk *clk, unsigned long rate) \
422 u32 reg, div_max, div; \
423 unsigned long parent_rate; \
426 parent_rate = clk_get_rate(clk->parent); \
427 div_max = BM_CLKCTRL_##dr##_DIV >> BP_CLKCTRL_##dr##_DIV; \
429 div = DIV_ROUND_UP(parent_rate, rate); \
430 if (div == 0 || div > div_max) \
433 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr); \
434 reg &= ~BM_CLKCTRL_##dr##_DIV; \
435 reg |= div << BP_CLKCTRL_##dr##_DIV; \
436 if (reg & (1 << clk->enable_shift)) { \
437 pr_err("%s: clock is gated\n", __func__); \
440 __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr); \
442 for (i = 10000; i; i--) \
443 if (!(__raw_readl(CLKCTRL_BASE_ADDR + \
444 HW_CLKCTRL_##dr) & BM_CLKCTRL_##dr##_BUSY)) \
447 pr_err("%s: divider writing timeout\n", __func__); \
454 _CLK_SET_RATE1(xbus_clk
, XBUS
)
456 /* saif clock uses 16 bits frac div */
457 #define _CLK_SET_RATE_SAIF(name, rs) \
458 static int name##_set_rate(struct clk *clk, unsigned long rate) \
463 unsigned long parent_rate; \
466 parent_rate = clk_get_rate(clk->parent); \
467 if (rate > parent_rate) \
470 lrate = (u64)rate << 16; \
471 do_div(lrate, parent_rate); \
477 reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs); \
478 reg &= ~BM_CLKCTRL_##rs##_DIV; \
479 reg |= div << BP_CLKCTRL_##rs##_DIV; \
480 __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs); \
482 for (i = 10000; i; i--) \
483 if (!(__raw_readl(CLKCTRL_BASE_ADDR + \
484 HW_CLKCTRL_##rs) & BM_CLKCTRL_##rs##_BUSY)) \
487 pr_err("%s: divider writing timeout\n", __func__); \
494 _CLK_SET_RATE_SAIF(saif0_clk
, SAIF0
)
495 _CLK_SET_RATE_SAIF(saif1_clk
, SAIF1
)
497 #define _CLK_SET_RATE_STUB(name) \
498 static int name##_set_rate(struct clk *clk, unsigned long rate) \
503 _CLK_SET_RATE_STUB(emi_clk
)
504 _CLK_SET_RATE_STUB(uart_clk
)
505 _CLK_SET_RATE_STUB(pwm_clk
)
506 _CLK_SET_RATE_STUB(spdif_clk
)
507 _CLK_SET_RATE_STUB(clk32k_clk
)
508 _CLK_SET_RATE_STUB(can0_clk
)
509 _CLK_SET_RATE_STUB(can1_clk
)
510 _CLK_SET_RATE_STUB(fec_clk
)
515 #define _CLK_SET_PARENT(name, bit) \
516 static int name##_set_parent(struct clk *clk, struct clk *parent) \
518 if (parent != clk->parent) { \
519 __raw_writel(BM_CLKCTRL_CLKSEQ_BYPASS_##bit, \
520 CLKCTRL_BASE_ADDR + HW_CLKCTRL_CLKSEQ_TOG); \
521 clk->parent = parent; \
527 _CLK_SET_PARENT(cpu_clk
, CPU
)
528 _CLK_SET_PARENT(emi_clk
, EMI
)
529 _CLK_SET_PARENT(ssp0_clk
, SSP0
)
530 _CLK_SET_PARENT(ssp1_clk
, SSP1
)
531 _CLK_SET_PARENT(ssp2_clk
, SSP2
)
532 _CLK_SET_PARENT(ssp3_clk
, SSP3
)
533 _CLK_SET_PARENT(lcdif_clk
, DIS_LCDIF
)
534 _CLK_SET_PARENT(gpmi_clk
, GPMI
)
535 _CLK_SET_PARENT(saif0_clk
, SAIF0
)
536 _CLK_SET_PARENT(saif1_clk
, SAIF1
)
538 #define _CLK_SET_PARENT_STUB(name) \
539 static int name##_set_parent(struct clk *clk, struct clk *parent) \
541 if (parent != clk->parent) \
547 _CLK_SET_PARENT_STUB(pwm_clk
)
548 _CLK_SET_PARENT_STUB(uart_clk
)
549 _CLK_SET_PARENT_STUB(clk32k_clk
)
550 _CLK_SET_PARENT_STUB(spdif_clk
)
551 _CLK_SET_PARENT_STUB(fec_clk
)
552 _CLK_SET_PARENT_STUB(can0_clk
)
553 _CLK_SET_PARENT_STUB(can1_clk
)
558 static struct clk cpu_clk
= {
559 .get_rate
= cpu_clk_get_rate
,
560 .set_rate
= cpu_clk_set_rate
,
561 .set_parent
= cpu_clk_set_parent
,
562 .parent
= &ref_cpu_clk
,
565 static struct clk hbus_clk
= {
566 .get_rate
= hbus_clk_get_rate
,
570 static struct clk xbus_clk
= {
571 .get_rate
= xbus_clk_get_rate
,
572 .set_rate
= xbus_clk_set_rate
,
573 .parent
= &ref_xtal_clk
,
576 static struct clk lradc_clk
= {
577 .get_rate
= lradc_clk_get_rate
,
578 .parent
= &clk32k_clk
,
581 static struct clk rtc_clk
= {
582 .get_rate
= rtc_clk_get_rate
,
583 .parent
= &ref_xtal_clk
,
586 /* usb_clk gate is controlled in DIGCTRL other than CLKCTRL */
587 static struct clk usb0_clk
= {
588 .enable_reg
= DIGCTRL_BASE_ADDR
,
590 .enable
= _raw_clk_enable
,
591 .disable
= _raw_clk_disable
,
595 static struct clk usb1_clk
= {
596 .enable_reg
= DIGCTRL_BASE_ADDR
,
598 .enable
= _raw_clk_enable
,
599 .disable
= _raw_clk_disable
,
603 #define _DEFINE_CLOCK(name, er, es, p) \
604 static struct clk name = { \
605 .enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er, \
606 .enable_shift = BP_CLKCTRL_##er##_##es, \
607 .get_rate = name##_get_rate, \
608 .set_rate = name##_set_rate, \
609 .set_parent = name##_set_parent, \
610 .enable = _raw_clk_enable, \
611 .disable = _raw_clk_disable, \
615 _DEFINE_CLOCK(emi_clk
, EMI
, CLKGATE
, &ref_xtal_clk
);
616 _DEFINE_CLOCK(ssp0_clk
, SSP0
, CLKGATE
, &ref_xtal_clk
);
617 _DEFINE_CLOCK(ssp1_clk
, SSP1
, CLKGATE
, &ref_xtal_clk
);
618 _DEFINE_CLOCK(ssp2_clk
, SSP2
, CLKGATE
, &ref_xtal_clk
);
619 _DEFINE_CLOCK(ssp3_clk
, SSP3
, CLKGATE
, &ref_xtal_clk
);
620 _DEFINE_CLOCK(lcdif_clk
, DIS_LCDIF
, CLKGATE
, &ref_xtal_clk
);
621 _DEFINE_CLOCK(gpmi_clk
, GPMI
, CLKGATE
, &ref_xtal_clk
);
622 _DEFINE_CLOCK(saif0_clk
, SAIF0
, CLKGATE
, &ref_xtal_clk
);
623 _DEFINE_CLOCK(saif1_clk
, SAIF1
, CLKGATE
, &ref_xtal_clk
);
624 _DEFINE_CLOCK(can0_clk
, FLEXCAN
, STOP_CAN0
, &ref_xtal_clk
);
625 _DEFINE_CLOCK(can1_clk
, FLEXCAN
, STOP_CAN1
, &ref_xtal_clk
);
626 _DEFINE_CLOCK(pwm_clk
, XTAL
, PWM_CLK24M_GATE
, &ref_xtal_clk
);
627 _DEFINE_CLOCK(uart_clk
, XTAL
, UART_CLK_GATE
, &ref_xtal_clk
);
628 _DEFINE_CLOCK(clk32k_clk
, XTAL
, TIMROT_CLK32K_GATE
, &ref_xtal_clk
);
629 _DEFINE_CLOCK(spdif_clk
, SPDIF
, CLKGATE
, &pll0_clk
);
630 _DEFINE_CLOCK(fec_clk
, ENET
, DISABLE
, &hbus_clk
);
632 #define _REGISTER_CLOCK(d, n, c) \
639 static struct clk_lookup lookups
[] = {
640 /* for amba bus driver */
641 _REGISTER_CLOCK("duart", "apb_pclk", xbus_clk
)
642 /* for amba-pl011 driver */
643 _REGISTER_CLOCK("duart", NULL
, uart_clk
)
644 _REGISTER_CLOCK("imx28-fec.0", NULL
, fec_clk
)
645 _REGISTER_CLOCK("imx28-fec.1", NULL
, fec_clk
)
646 _REGISTER_CLOCK("mxs-auart.0", NULL
, uart_clk
)
647 _REGISTER_CLOCK("mxs-auart.1", NULL
, uart_clk
)
648 _REGISTER_CLOCK("mxs-auart.2", NULL
, uart_clk
)
649 _REGISTER_CLOCK("mxs-auart.3", NULL
, uart_clk
)
650 _REGISTER_CLOCK("mxs-auart.4", NULL
, uart_clk
)
651 _REGISTER_CLOCK("rtc", NULL
, rtc_clk
)
652 _REGISTER_CLOCK("pll2", NULL
, pll2_clk
)
653 _REGISTER_CLOCK("mxs-dma-apbh", NULL
, hbus_clk
)
654 _REGISTER_CLOCK("mxs-dma-apbx", NULL
, xbus_clk
)
655 _REGISTER_CLOCK("mxs-mmc.0", NULL
, ssp0_clk
)
656 _REGISTER_CLOCK("mxs-mmc.1", NULL
, ssp1_clk
)
657 _REGISTER_CLOCK("flexcan.0", NULL
, can0_clk
)
658 _REGISTER_CLOCK("flexcan.1", NULL
, can1_clk
)
659 _REGISTER_CLOCK(NULL
, "usb0", usb0_clk
)
660 _REGISTER_CLOCK(NULL
, "usb1", usb1_clk
)
661 _REGISTER_CLOCK("mxs-pwm.0", NULL
, pwm_clk
)
662 _REGISTER_CLOCK("mxs-pwm.1", NULL
, pwm_clk
)
663 _REGISTER_CLOCK("mxs-pwm.2", NULL
, pwm_clk
)
664 _REGISTER_CLOCK("mxs-pwm.3", NULL
, pwm_clk
)
665 _REGISTER_CLOCK("mxs-pwm.4", NULL
, pwm_clk
)
666 _REGISTER_CLOCK("mxs-pwm.5", NULL
, pwm_clk
)
667 _REGISTER_CLOCK("mxs-pwm.6", NULL
, pwm_clk
)
668 _REGISTER_CLOCK("mxs-pwm.7", NULL
, pwm_clk
)
669 _REGISTER_CLOCK(NULL
, "lradc", lradc_clk
)
670 _REGISTER_CLOCK(NULL
, "spdif", spdif_clk
)
671 _REGISTER_CLOCK("imx28-fb", NULL
, lcdif_clk
)
672 _REGISTER_CLOCK("mxs-saif.0", NULL
, saif0_clk
)
673 _REGISTER_CLOCK("mxs-saif.1", NULL
, saif1_clk
)
676 static int clk_misc_init(void)
681 /* Fix up parent per register setting */
682 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_CLKSEQ
);
683 cpu_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_CPU
) ?
684 &ref_xtal_clk
: &ref_cpu_clk
;
685 emi_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_EMI
) ?
686 &ref_xtal_clk
: &ref_emi_clk
;
687 ssp0_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_SSP0
) ?
688 &ref_xtal_clk
: &ref_io0_clk
;
689 ssp1_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_SSP1
) ?
690 &ref_xtal_clk
: &ref_io0_clk
;
691 ssp2_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_SSP2
) ?
692 &ref_xtal_clk
: &ref_io1_clk
;
693 ssp3_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_SSP3
) ?
694 &ref_xtal_clk
: &ref_io1_clk
;
695 lcdif_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_DIS_LCDIF
) ?
696 &ref_xtal_clk
: &ref_pix_clk
;
697 gpmi_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_GPMI
) ?
698 &ref_xtal_clk
: &ref_gpmi_clk
;
699 saif0_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_SAIF0
) ?
700 &ref_xtal_clk
: &pll0_clk
;
701 saif1_clk
.parent
= (reg
& BM_CLKCTRL_CLKSEQ_BYPASS_SAIF1
) ?
702 &ref_xtal_clk
: &pll0_clk
;
704 /* Use int div over frac when both are available */
705 __raw_writel(BM_CLKCTRL_CPU_DIV_XTAL_FRAC_EN
,
706 CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_CPU_CLR
);
707 __raw_writel(BM_CLKCTRL_CPU_DIV_CPU_FRAC_EN
,
708 CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_CPU_CLR
);
709 __raw_writel(BM_CLKCTRL_HBUS_DIV_FRAC_EN
,
710 CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_HBUS_CLR
);
712 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_XBUS
);
713 reg
&= ~BM_CLKCTRL_XBUS_DIV_FRAC_EN
;
714 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_XBUS
);
716 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP0
);
717 reg
&= ~BM_CLKCTRL_SSP0_DIV_FRAC_EN
;
718 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP0
);
720 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP1
);
721 reg
&= ~BM_CLKCTRL_SSP1_DIV_FRAC_EN
;
722 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP1
);
724 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP2
);
725 reg
&= ~BM_CLKCTRL_SSP2_DIV_FRAC_EN
;
726 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP2
);
728 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP3
);
729 reg
&= ~BM_CLKCTRL_SSP3_DIV_FRAC_EN
;
730 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SSP3
);
732 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_GPMI
);
733 reg
&= ~BM_CLKCTRL_GPMI_DIV_FRAC_EN
;
734 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_GPMI
);
736 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_DIS_LCDIF
);
737 reg
&= ~BM_CLKCTRL_DIS_LCDIF_DIV_FRAC_EN
;
738 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_DIS_LCDIF
);
740 /* SAIF has to use frac div for functional operation */
741 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SAIF0
);
742 reg
|= BM_CLKCTRL_SAIF0_DIV_FRAC_EN
;
743 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SAIF0
);
745 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SAIF1
);
746 reg
|= BM_CLKCTRL_SAIF1_DIV_FRAC_EN
;
747 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_SAIF1
);
750 * Set safe hbus clock divider. A divider of 3 ensure that
751 * the Vddd voltage required for the cpu clock is sufficiently
752 * high for the hbus clock.
754 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_HBUS
);
755 reg
&= BM_CLKCTRL_HBUS_DIV
;
756 reg
|= 3 << BP_CLKCTRL_HBUS_DIV
;
757 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_HBUS
);
759 for (i
= 10000; i
; i
--)
760 if (!(__raw_readl(CLKCTRL_BASE_ADDR
+
761 HW_CLKCTRL_HBUS
) & BM_CLKCTRL_HBUS_ASM_BUSY
))
764 pr_err("%s: divider writing timeout\n", __func__
);
768 /* Gate off cpu clock in WFI for power saving */
769 __raw_writel(BM_CLKCTRL_CPU_INTERRUPT_WAIT
,
770 CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_CPU_SET
);
773 * Extra fec clock setting
774 * The DENX M28 uses an external clock source
775 * and the clock output must not be enabled
777 if (!machine_is_m28evk()) {
778 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_ENET
);
779 reg
&= ~BM_CLKCTRL_ENET_SLEEP
;
780 reg
|= BM_CLKCTRL_ENET_CLK_OUT_EN
;
781 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_ENET
);
785 * 480 MHz seems too high to be ssp clock source directly,
786 * so set frac0 to get a 288 MHz ref_io0.
788 reg
= __raw_readl(CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_FRAC0
);
789 reg
&= ~BM_CLKCTRL_FRAC0_IO0FRAC
;
790 reg
|= 30 << BP_CLKCTRL_FRAC0_IO0FRAC
;
791 __raw_writel(reg
, CLKCTRL_BASE_ADDR
+ HW_CLKCTRL_FRAC0
);
796 int __init
mx28_clocks_init(void)
801 * source ssp clock from ref_io0 than ref_xtal,
802 * as ref_xtal only provides 24 MHz as maximum.
804 clk_set_parent(&ssp0_clk
, &ref_io0_clk
);
805 clk_set_parent(&ssp1_clk
, &ref_io0_clk
);
807 clk_prepare_enable(&cpu_clk
);
808 clk_prepare_enable(&hbus_clk
);
809 clk_prepare_enable(&xbus_clk
);
810 clk_prepare_enable(&emi_clk
);
811 clk_prepare_enable(&uart_clk
);
813 clk_set_parent(&lcdif_clk
, &ref_pix_clk
);
814 clk_set_parent(&saif0_clk
, &pll0_clk
);
815 clk_set_parent(&saif1_clk
, &pll0_clk
);
818 * Set an initial clock rate for the saif internal logic to work
819 * properly. This is important when working in EXTMASTER mode that
820 * uses the other saif's BITCLK&LRCLK but it still needs a basic
821 * clock which should be fast enough for the internal logic.
823 clk_set_rate(&saif0_clk
, 24000000);
824 clk_set_rate(&saif1_clk
, 24000000);
826 clkdev_add_table(lookups
, ARRAY_SIZE(lookups
));
828 mxs_timer_init(&clk32k_clk
, MX28_INT_TIMER0
);