2 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
4 * Copyright 2008 Martin Fuzzey, mfuzzey@gmail.com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 #include <linux/clk.h>
23 #include <linux/module.h>
24 #include <linux/clkdev.h>
27 #include <asm/div64.h>
29 #include <mach/clock.h>
30 #include <mach/common.h>
31 #include <mach/hardware.h>
33 #define IO_ADDR_CCM(off) (MX27_IO_ADDRESS(MX27_CCM_BASE_ADDR + (off)))
35 /* Register offsets */
36 #define CCM_CSCR IO_ADDR_CCM(0x0)
37 #define CCM_MPCTL0 IO_ADDR_CCM(0x4)
38 #define CCM_MPCTL1 IO_ADDR_CCM(0x8)
39 #define CCM_SPCTL0 IO_ADDR_CCM(0xc)
40 #define CCM_SPCTL1 IO_ADDR_CCM(0x10)
41 #define CCM_OSC26MCTL IO_ADDR_CCM(0x14)
42 #define CCM_PCDR0 IO_ADDR_CCM(0x18)
43 #define CCM_PCDR1 IO_ADDR_CCM(0x1c)
44 #define CCM_PCCR0 IO_ADDR_CCM(0x20)
45 #define CCM_PCCR1 IO_ADDR_CCM(0x24)
46 #define CCM_CCSR IO_ADDR_CCM(0x28)
47 #define CCM_PMCTL IO_ADDR_CCM(0x2c)
48 #define CCM_PMCOUNT IO_ADDR_CCM(0x30)
49 #define CCM_WKGDCTL IO_ADDR_CCM(0x34)
51 #define CCM_CSCR_UPDATE_DIS (1 << 31)
52 #define CCM_CSCR_SSI2 (1 << 23)
53 #define CCM_CSCR_SSI1 (1 << 22)
54 #define CCM_CSCR_VPU (1 << 21)
55 #define CCM_CSCR_MSHC (1 << 20)
56 #define CCM_CSCR_SPLLRES (1 << 19)
57 #define CCM_CSCR_MPLLRES (1 << 18)
58 #define CCM_CSCR_SP (1 << 17)
59 #define CCM_CSCR_MCU (1 << 16)
60 #define CCM_CSCR_OSC26MDIV (1 << 4)
61 #define CCM_CSCR_OSC26M (1 << 3)
62 #define CCM_CSCR_FPM (1 << 2)
63 #define CCM_CSCR_SPEN (1 << 1)
64 #define CCM_CSCR_MPEN (1 << 0)
67 #define CCM_CSCR_ARM_SRC (1 << 15)
69 #define CCM_SPCTL1_LF (1 << 15)
70 #define CCM_SPCTL1_BRMO (1 << 6)
72 static struct clk mpll_main1_clk, mpll_main2_clk;
74 static int clk_pccr_enable(struct clk *clk)
81 reg = __raw_readl(clk->enable_reg);
82 reg |= 1 << clk->enable_shift;
83 __raw_writel(reg, clk->enable_reg);
88 static void clk_pccr_disable(struct clk *clk)
95 reg = __raw_readl(clk->enable_reg);
96 reg &= ~(1 << clk->enable_shift);
97 __raw_writel(reg, clk->enable_reg);
100 static int clk_spll_enable(struct clk *clk)
104 reg = __raw_readl(CCM_CSCR);
105 reg |= CCM_CSCR_SPEN;
106 __raw_writel(reg, CCM_CSCR);
108 while (!(__raw_readl(CCM_SPCTL1) & CCM_SPCTL1_LF));
113 static void clk_spll_disable(struct clk *clk)
117 reg = __raw_readl(CCM_CSCR);
118 reg &= ~CCM_CSCR_SPEN;
119 __raw_writel(reg, CCM_CSCR);
122 static int clk_cpu_set_parent(struct clk *clk, struct clk *parent)
124 int cscr = __raw_readl(CCM_CSCR);
126 if (clk->parent == parent)
129 if (mx27_revision() >= IMX_CHIP_REVISION_2_0) {
130 if (parent == &mpll_main1_clk) {
131 cscr |= CCM_CSCR_ARM_SRC;
133 if (parent == &mpll_main2_clk)
134 cscr &= ~CCM_CSCR_ARM_SRC;
138 __raw_writel(cscr, CCM_CSCR);
139 clk->parent = parent;
145 static unsigned long round_rate_cpu(struct clk *clk, unsigned long rate)
148 unsigned long parent_rate;
150 parent_rate = clk_get_rate(clk->parent);
152 div = parent_rate / rate;
153 if (parent_rate % rate)
159 return parent_rate / div;
162 static int set_rate_cpu(struct clk *clk, unsigned long rate)
166 unsigned long parent_rate;
168 parent_rate = clk_get_rate(clk->parent);
170 div = parent_rate / rate;
172 if (div > 4 || div < 1 || ((parent_rate / div) != rate))
177 reg = __raw_readl(CCM_CSCR);
178 if (mx27_revision() >= IMX_CHIP_REVISION_2_0) {
181 reg &= ~(CCM_CSCR_FPM | CCM_CSCR_SPEN);
182 __raw_writel(reg | CCM_CSCR_UPDATE_DIS, CCM_CSCR);
184 printk(KERN_ERR "Can't set CPU frequency!\n");
190 static unsigned long round_rate_per(struct clk *clk, unsigned long rate)
193 unsigned long parent_rate;
195 parent_rate = clk_get_rate(clk->parent);
197 div = parent_rate / rate;
198 if (parent_rate % rate)
204 return parent_rate / div;
207 static int set_rate_per(struct clk *clk, unsigned long rate)
211 unsigned long parent_rate;
213 parent_rate = clk_get_rate(clk->parent);
215 if (clk->id < 0 || clk->id > 3)
218 div = parent_rate / rate;
219 if (div > 64 || div < 1 || ((parent_rate / div) != rate))
223 reg = __raw_readl(CCM_PCDR1) & ~(0x3f << (clk->id << 3));
224 reg |= div << (clk->id << 3);
225 __raw_writel(reg, CCM_PCDR1);
230 static unsigned long get_rate_usb(struct clk *clk)
232 unsigned long usb_pdf;
233 unsigned long parent_rate;
235 parent_rate = clk_get_rate(clk->parent);
237 usb_pdf = (__raw_readl(CCM_CSCR) >> 28) & 0x7;
239 return parent_rate / (usb_pdf + 1U);
242 static unsigned long get_rate_ssix(struct clk *clk, unsigned long pdf)
244 unsigned long parent_rate;
246 parent_rate = clk_get_rate(clk->parent);
248 if (mx27_revision() >= IMX_CHIP_REVISION_2_0)
249 pdf += 4; /* MX27 TO2+ */
251 pdf = (pdf < 2) ? 124UL : pdf; /* MX21 & MX27 TO1 */
253 return 2UL * parent_rate / pdf;
256 static unsigned long get_rate_ssi1(struct clk *clk)
258 return get_rate_ssix(clk, (__raw_readl(CCM_PCDR0) >> 16) & 0x3f);
261 static unsigned long get_rate_ssi2(struct clk *clk)
263 return get_rate_ssix(clk, (__raw_readl(CCM_PCDR0) >> 26) & 0x3f);
266 static unsigned long get_rate_nfc(struct clk *clk)
268 unsigned long nfc_pdf;
269 unsigned long parent_rate;
271 parent_rate = clk_get_rate(clk->parent);
273 if (mx27_revision() >= IMX_CHIP_REVISION_2_0)
274 nfc_pdf = (__raw_readl(CCM_PCDR0) >> 6) & 0xf;
276 nfc_pdf = (__raw_readl(CCM_PCDR0) >> 12) & 0xf;
278 return parent_rate / (nfc_pdf + 1);
281 static unsigned long get_rate_vpu(struct clk *clk)
283 unsigned long vpu_pdf;
284 unsigned long parent_rate;
286 parent_rate = clk_get_rate(clk->parent);
288 if (mx27_revision() >= IMX_CHIP_REVISION_2_0) {
289 vpu_pdf = (__raw_readl(CCM_PCDR0) >> 10) & 0x3f;
292 vpu_pdf = (__raw_readl(CCM_PCDR0) >> 8) & 0xf;
293 vpu_pdf = (vpu_pdf < 2) ? 124 : vpu_pdf;
296 return 2UL * parent_rate / vpu_pdf;
299 static unsigned long round_rate_parent(struct clk *clk, unsigned long rate)
301 return clk->parent->round_rate(clk->parent, rate);
304 static unsigned long get_rate_parent(struct clk *clk)
306 return clk_get_rate(clk->parent);
309 static int set_rate_parent(struct clk *clk, unsigned long rate)
311 return clk->parent->set_rate(clk->parent, rate);
315 static unsigned long external_high_reference = 26000000;
317 static unsigned long get_rate_high_reference(struct clk *clk)
319 return external_high_reference;
323 static unsigned long external_low_reference = 32768;
325 static unsigned long get_rate_low_reference(struct clk *clk)
327 return external_low_reference;
330 static unsigned long get_rate_fpm(struct clk *clk)
332 return clk_get_rate(clk->parent) * 1024;
335 static unsigned long get_rate_mpll(struct clk *clk)
337 return mxc_decode_pll(__raw_readl(CCM_MPCTL0),
338 clk_get_rate(clk->parent));
341 static unsigned long get_rate_mpll_main(struct clk *clk)
343 unsigned long parent_rate;
345 parent_rate = clk_get_rate(clk->parent);
348 * clk->id == 0: arm clock source path 1 which is from 2 * MPLL / 2
349 * clk->id == 1: arm clock source path 2 which is from 2 * MPLL / 3
351 if (mx27_revision() >= IMX_CHIP_REVISION_2_0 && clk->id == 1)
352 return 2UL * parent_rate / 3UL;
357 static unsigned long get_rate_spll(struct clk *clk)
362 rate = clk_get_rate(clk->parent);
364 reg = __raw_readl(CCM_SPCTL0);
366 /* On TO2 we have to write the value back. Otherwise we
367 * read 0 from this register the next time.
369 if (mx27_revision() >= IMX_CHIP_REVISION_2_0)
370 __raw_writel(reg, CCM_SPCTL0);
372 return mxc_decode_pll(reg, rate);
375 static unsigned long get_rate_cpu(struct clk *clk)
380 if (mx27_revision() >= IMX_CHIP_REVISION_2_0)
381 div = (__raw_readl(CCM_CSCR) >> 12) & 0x3;
383 div = (__raw_readl(CCM_CSCR) >> 13) & 0x7;
385 rate = clk_get_rate(clk->parent);
386 return rate / (div + 1);
389 static unsigned long get_rate_ahb(struct clk *clk)
391 unsigned long rate, bclk_pdf;
393 if (mx27_revision() >= IMX_CHIP_REVISION_2_0)
394 bclk_pdf = (__raw_readl(CCM_CSCR) >> 8) & 0x3;
396 bclk_pdf = (__raw_readl(CCM_CSCR) >> 9) & 0xf;
398 rate = clk_get_rate(clk->parent);
399 return rate / (bclk_pdf + 1);
402 static unsigned long get_rate_ipg(struct clk *clk)
404 unsigned long rate, ipg_pdf;
406 if (mx27_revision() >= IMX_CHIP_REVISION_2_0)
407 return clk_get_rate(clk->parent);
409 ipg_pdf = (__raw_readl(CCM_CSCR) >> 8) & 1;
411 rate = clk_get_rate(clk->parent);
412 return rate / (ipg_pdf + 1);
415 static unsigned long get_rate_per(struct clk *clk)
417 unsigned long perclk_pdf, parent_rate;
419 parent_rate = clk_get_rate(clk->parent);
421 if (clk->id < 0 || clk->id > 3)
424 perclk_pdf = (__raw_readl(CCM_PCDR1) >> (clk->id << 3)) & 0x3f;
426 return parent_rate / (perclk_pdf + 1);
430 * the high frequency external clock reference
431 * Default case is 26MHz. Could be changed at runtime
432 * with a call to change_external_high_reference()
434 static struct clk ckih_clk = {
435 .get_rate = get_rate_high_reference,
438 static struct clk mpll_clk = {
440 .get_rate = get_rate_mpll,
443 /* For i.MX27 TO2, it is the MPLL path 1 of ARM core
444 * It provides the clock source whose rate is same as MPLL
446 static struct clk mpll_main1_clk = {
449 .get_rate = get_rate_mpll_main,
452 /* For i.MX27 TO2, it is the MPLL path 2 of ARM core
453 * It provides the clock source whose rate is same MPLL * 2 / 3
455 static struct clk mpll_main2_clk = {
458 .get_rate = get_rate_mpll_main,
461 static struct clk ahb_clk = {
462 .parent = &mpll_main2_clk,
463 .get_rate = get_rate_ahb,
466 static struct clk ipg_clk = {
468 .get_rate = get_rate_ipg,
471 static struct clk cpu_clk = {
472 .parent = &mpll_main2_clk,
473 .set_parent = clk_cpu_set_parent,
474 .round_rate = round_rate_cpu,
475 .get_rate = get_rate_cpu,
476 .set_rate = set_rate_cpu,
479 static struct clk spll_clk = {
481 .get_rate = get_rate_spll,
482 .enable = clk_spll_enable,
483 .disable = clk_spll_disable,
487 * the low frequency external clock reference
488 * Default case is 32.768kHz.
490 static struct clk ckil_clk = {
491 .get_rate = get_rate_low_reference,
494 /* Output of frequency pre multiplier */
495 static struct clk fpm_clk = {
497 .get_rate = get_rate_fpm,
500 #define PCCR0 CCM_PCCR0
501 #define PCCR1 CCM_PCCR1
503 #define DEFINE_CLOCK(name, i, er, es, gr, s, p) \
504 static struct clk name = { \
507 .enable_shift = es, \
509 .enable = clk_pccr_enable, \
510 .disable = clk_pccr_disable, \
515 #define DEFINE_CLOCK1(name, i, er, es, getsetround, s, p) \
516 static struct clk name = { \
519 .enable_shift = es, \
520 .get_rate = get_rate_##getsetround, \
521 .set_rate = set_rate_##getsetround, \
522 .round_rate = round_rate_##getsetround, \
523 .enable = clk_pccr_enable, \
524 .disable = clk_pccr_disable, \
529 /* Forward declaration to keep the following list in order */
530 static struct clk slcdc_clk1, sahara2_clk1, rtic_clk1, fec_clk1, emma_clk1,
531 dma_clk1, lcdc_clk2, vpu_clk1;
533 /* All clocks we can gate through PCCRx in the order of PCCRx bits */
534 DEFINE_CLOCK(ssi2_clk1, 1, PCCR0, 0, NULL, NULL, &ipg_clk);
535 DEFINE_CLOCK(ssi1_clk1, 0, PCCR0, 1, NULL, NULL, &ipg_clk);
536 DEFINE_CLOCK(slcdc_clk, 0, PCCR0, 2, NULL, &slcdc_clk1, &ahb_clk);
537 DEFINE_CLOCK(sdhc3_clk1, 0, PCCR0, 3, NULL, NULL, &ipg_clk);
538 DEFINE_CLOCK(sdhc2_clk1, 0, PCCR0, 4, NULL, NULL, &ipg_clk);
539 DEFINE_CLOCK(sdhc1_clk1, 0, PCCR0, 5, NULL, NULL, &ipg_clk);
540 DEFINE_CLOCK(scc_clk, 0, PCCR0, 6, NULL, NULL, &ipg_clk);
541 DEFINE_CLOCK(sahara2_clk, 0, PCCR0, 7, NULL, &sahara2_clk1, &ahb_clk);
542 DEFINE_CLOCK(rtic_clk, 0, PCCR0, 8, NULL, &rtic_clk1, &ahb_clk);
543 DEFINE_CLOCK(rtc_clk, 0, PCCR0, 9, NULL, NULL, &ipg_clk);
544 DEFINE_CLOCK(pwm_clk1, 0, PCCR0, 11, NULL, NULL, &ipg_clk);
545 DEFINE_CLOCK(owire_clk, 0, PCCR0, 12, NULL, NULL, &ipg_clk);
546 DEFINE_CLOCK(mstick_clk1, 0, PCCR0, 13, NULL, NULL, &ipg_clk);
547 DEFINE_CLOCK(lcdc_clk1, 0, PCCR0, 14, NULL, &lcdc_clk2, &ipg_clk);
548 DEFINE_CLOCK(kpp_clk, 0, PCCR0, 15, NULL, NULL, &ipg_clk);
549 DEFINE_CLOCK(iim_clk, 0, PCCR0, 16, NULL, NULL, &ipg_clk);
550 DEFINE_CLOCK(i2c2_clk, 1, PCCR0, 17, NULL, NULL, &ipg_clk);
551 DEFINE_CLOCK(i2c1_clk, 0, PCCR0, 18, NULL, NULL, &ipg_clk);
552 DEFINE_CLOCK(gpt6_clk1, 0, PCCR0, 29, NULL, NULL, &ipg_clk);
553 DEFINE_CLOCK(gpt5_clk1, 0, PCCR0, 20, NULL, NULL, &ipg_clk);
554 DEFINE_CLOCK(gpt4_clk1, 0, PCCR0, 21, NULL, NULL, &ipg_clk);
555 DEFINE_CLOCK(gpt3_clk1, 0, PCCR0, 22, NULL, NULL, &ipg_clk);
556 DEFINE_CLOCK(gpt2_clk1, 0, PCCR0, 23, NULL, NULL, &ipg_clk);
557 DEFINE_CLOCK(gpt1_clk1, 0, PCCR0, 24, NULL, NULL, &ipg_clk);
558 DEFINE_CLOCK(gpio_clk, 0, PCCR0, 25, NULL, NULL, &ipg_clk);
559 DEFINE_CLOCK(fec_clk, 0, PCCR0, 26, NULL, &fec_clk1, &ahb_clk);
560 DEFINE_CLOCK(emma_clk, 0, PCCR0, 27, NULL, &emma_clk1, &ahb_clk);
561 DEFINE_CLOCK(dma_clk, 0, PCCR0, 28, NULL, &dma_clk1, &ahb_clk);
562 DEFINE_CLOCK(cspi13_clk1, 0, PCCR0, 29, NULL, NULL, &ipg_clk);
563 DEFINE_CLOCK(cspi2_clk1, 0, PCCR0, 30, NULL, NULL, &ipg_clk);
564 DEFINE_CLOCK(cspi1_clk1, 0, PCCR0, 31, NULL, NULL, &ipg_clk);
566 DEFINE_CLOCK(mstick_clk, 0, PCCR1, 2, NULL, &mstick_clk1, &ipg_clk);
567 DEFINE_CLOCK(nfc_clk, 0, PCCR1, 3, get_rate_nfc, NULL, &cpu_clk);
568 DEFINE_CLOCK(ssi2_clk, 1, PCCR1, 4, get_rate_ssi2, &ssi2_clk1, &mpll_main2_clk);
569 DEFINE_CLOCK(ssi1_clk, 0, PCCR1, 5, get_rate_ssi1, &ssi1_clk1, &mpll_main2_clk);
570 DEFINE_CLOCK(vpu_clk, 0, PCCR1, 6, get_rate_vpu, &vpu_clk1, &mpll_main2_clk);
571 DEFINE_CLOCK1(per4_clk, 3, PCCR1, 7, per, NULL, &mpll_main2_clk);
572 DEFINE_CLOCK1(per3_clk, 2, PCCR1, 8, per, NULL, &mpll_main2_clk);
573 DEFINE_CLOCK1(per2_clk, 1, PCCR1, 9, per, NULL, &mpll_main2_clk);
574 DEFINE_CLOCK1(per1_clk, 0, PCCR1, 10, per, NULL, &mpll_main2_clk);
575 DEFINE_CLOCK(usb_clk1, 0, PCCR1, 11, NULL, NULL, &ahb_clk);
576 DEFINE_CLOCK(slcdc_clk1, 0, PCCR1, 12, NULL, NULL, &ahb_clk);
577 DEFINE_CLOCK(sahara2_clk1, 0, PCCR1, 13, NULL, NULL, &ahb_clk);
578 DEFINE_CLOCK(rtic_clk1, 0, PCCR1, 14, NULL, NULL, &ahb_clk);
579 DEFINE_CLOCK(lcdc_clk2, 0, PCCR1, 15, NULL, NULL, &ahb_clk);
580 DEFINE_CLOCK(vpu_clk1, 0, PCCR1, 16, NULL, NULL, &ahb_clk);
581 DEFINE_CLOCK(fec_clk1, 0, PCCR1, 17, NULL, NULL, &ahb_clk);
582 DEFINE_CLOCK(emma_clk1, 0, PCCR1, 18, NULL, NULL, &ahb_clk);
583 DEFINE_CLOCK(emi_clk, 0, PCCR1, 19, NULL, NULL, &ahb_clk);
584 DEFINE_CLOCK(dma_clk1, 0, PCCR1, 20, NULL, NULL, &ahb_clk);
585 DEFINE_CLOCK(csi_clk1, 0, PCCR1, 21, NULL, NULL, &ahb_clk);
586 DEFINE_CLOCK(brom_clk, 0, PCCR1, 22, NULL, NULL, &ahb_clk);
587 DEFINE_CLOCK(pata_clk, 0, PCCR1, 23, NULL, NULL, &ahb_clk);
588 DEFINE_CLOCK(wdog_clk, 0, PCCR1, 24, NULL, NULL, &ipg_clk);
589 DEFINE_CLOCK(usb_clk, 0, PCCR1, 25, get_rate_usb, &usb_clk1, &spll_clk);
590 DEFINE_CLOCK(uart6_clk1, 0, PCCR1, 26, NULL, NULL, &ipg_clk);
591 DEFINE_CLOCK(uart5_clk1, 0, PCCR1, 27, NULL, NULL, &ipg_clk);
592 DEFINE_CLOCK(uart4_clk1, 0, PCCR1, 28, NULL, NULL, &ipg_clk);
593 DEFINE_CLOCK(uart3_clk1, 0, PCCR1, 29, NULL, NULL, &ipg_clk);
594 DEFINE_CLOCK(uart2_clk1, 0, PCCR1, 30, NULL, NULL, &ipg_clk);
595 DEFINE_CLOCK(uart1_clk1, 0, PCCR1, 31, NULL, NULL, &ipg_clk);
597 /* Clocks we cannot directly gate, but drivers need their rates */
598 DEFINE_CLOCK(cspi1_clk, 0, NULL, 0, NULL, &cspi1_clk1, &per2_clk);
599 DEFINE_CLOCK(cspi2_clk, 1, NULL, 0, NULL, &cspi2_clk1, &per2_clk);
600 DEFINE_CLOCK(cspi3_clk, 2, NULL, 0, NULL, &cspi13_clk1, &per2_clk);
601 DEFINE_CLOCK(sdhc1_clk, 0, NULL, 0, NULL, &sdhc1_clk1, &per2_clk);
602 DEFINE_CLOCK(sdhc2_clk, 1, NULL, 0, NULL, &sdhc2_clk1, &per2_clk);
603 DEFINE_CLOCK(sdhc3_clk, 2, NULL, 0, NULL, &sdhc3_clk1, &per2_clk);
604 DEFINE_CLOCK(pwm_clk, 0, NULL, 0, NULL, &pwm_clk1, &per1_clk);
605 DEFINE_CLOCK(gpt1_clk, 0, NULL, 0, NULL, &gpt1_clk1, &per1_clk);
606 DEFINE_CLOCK(gpt2_clk, 1, NULL, 0, NULL, &gpt2_clk1, &per1_clk);
607 DEFINE_CLOCK(gpt3_clk, 2, NULL, 0, NULL, &gpt3_clk1, &per1_clk);
608 DEFINE_CLOCK(gpt4_clk, 3, NULL, 0, NULL, &gpt4_clk1, &per1_clk);
609 DEFINE_CLOCK(gpt5_clk, 4, NULL, 0, NULL, &gpt5_clk1, &per1_clk);
610 DEFINE_CLOCK(gpt6_clk, 5, NULL, 0, NULL, &gpt6_clk1, &per1_clk);
611 DEFINE_CLOCK(uart1_clk, 0, NULL, 0, NULL, &uart1_clk1, &per1_clk);
612 DEFINE_CLOCK(uart2_clk, 1, NULL, 0, NULL, &uart2_clk1, &per1_clk);
613 DEFINE_CLOCK(uart3_clk, 2, NULL, 0, NULL, &uart3_clk1, &per1_clk);
614 DEFINE_CLOCK(uart4_clk, 3, NULL, 0, NULL, &uart4_clk1, &per1_clk);
615 DEFINE_CLOCK(uart5_clk, 4, NULL, 0, NULL, &uart5_clk1, &per1_clk);
616 DEFINE_CLOCK(uart6_clk, 5, NULL, 0, NULL, &uart6_clk1, &per1_clk);
617 DEFINE_CLOCK1(lcdc_clk, 0, NULL, 0, parent, &lcdc_clk1, &per3_clk);
618 DEFINE_CLOCK1(csi_clk, 0, NULL, 0, parent, &csi_clk1, &per4_clk);
620 #define _REGISTER_CLOCK(d, n, c) \
627 static struct clk_lookup lookups[] = {
628 /* i.mx27 has the i.mx21 type uart */
629 _REGISTER_CLOCK("imx21-uart.0", NULL, uart1_clk)
630 _REGISTER_CLOCK("imx21-uart.1", NULL, uart2_clk)
631 _REGISTER_CLOCK("imx21-uart.2", NULL, uart3_clk)
632 _REGISTER_CLOCK("imx21-uart.3", NULL, uart4_clk)
633 _REGISTER_CLOCK("imx21-uart.4", NULL, uart5_clk)
634 _REGISTER_CLOCK("imx21-uart.5", NULL, uart6_clk)
635 _REGISTER_CLOCK(NULL, "gpt1", gpt1_clk)
636 _REGISTER_CLOCK(NULL, "gpt2", gpt2_clk)
637 _REGISTER_CLOCK(NULL, "gpt3", gpt3_clk)
638 _REGISTER_CLOCK(NULL, "gpt4", gpt4_clk)
639 _REGISTER_CLOCK(NULL, "gpt5", gpt5_clk)
640 _REGISTER_CLOCK(NULL, "gpt6", gpt6_clk)
641 _REGISTER_CLOCK("mxc_pwm.0", NULL, pwm_clk)
642 _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
643 _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)
644 _REGISTER_CLOCK("mxc-mmc.2", NULL, sdhc3_clk)
645 _REGISTER_CLOCK("imx27-cspi.0", NULL, cspi1_clk)
646 _REGISTER_CLOCK("imx27-cspi.1", NULL, cspi2_clk)
647 _REGISTER_CLOCK("imx27-cspi.2", NULL, cspi3_clk)
648 _REGISTER_CLOCK("imx-fb.0", NULL, lcdc_clk)
649 _REGISTER_CLOCK("mx2-camera.0", NULL, csi_clk)
650 _REGISTER_CLOCK("fsl-usb2-udc", "usb", usb_clk)
651 _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", usb_clk1)
652 _REGISTER_CLOCK("mxc-ehci.0", "usb", usb_clk)
653 _REGISTER_CLOCK("mxc-ehci.0", "usb_ahb", usb_clk1)
654 _REGISTER_CLOCK("mxc-ehci.1", "usb", usb_clk)
655 _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", usb_clk1)
656 _REGISTER_CLOCK("mxc-ehci.2", "usb", usb_clk)
657 _REGISTER_CLOCK("mxc-ehci.2", "usb_ahb", usb_clk1)
658 _REGISTER_CLOCK("imx-ssi.0", NULL, ssi1_clk)
659 _REGISTER_CLOCK("imx-ssi.1", NULL, ssi2_clk)
660 _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
661 _REGISTER_CLOCK(NULL, "vpu", vpu_clk)
662 _REGISTER_CLOCK(NULL, "dma", dma_clk)
663 _REGISTER_CLOCK(NULL, "rtic", rtic_clk)
664 _REGISTER_CLOCK(NULL, "brom", brom_clk)
665 _REGISTER_CLOCK(NULL, "emma", emma_clk)
666 _REGISTER_CLOCK("m2m-emmaprp.0", NULL, emma_clk)
667 _REGISTER_CLOCK(NULL, "slcdc", slcdc_clk)
668 _REGISTER_CLOCK("imx27-fec.0", NULL, fec_clk)
669 _REGISTER_CLOCK(NULL, "emi", emi_clk)
670 _REGISTER_CLOCK(NULL, "sahara2", sahara2_clk)
671 _REGISTER_CLOCK("pata_imx", NULL, pata_clk)
672 _REGISTER_CLOCK(NULL, "mstick", mstick_clk)
673 _REGISTER_CLOCK("imx2-wdt.0", NULL, wdog_clk)
674 _REGISTER_CLOCK(NULL, "gpio", gpio_clk)
675 _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk)
676 _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
677 _REGISTER_CLOCK(NULL, "iim", iim_clk)
678 _REGISTER_CLOCK(NULL, "kpp", kpp_clk)
679 _REGISTER_CLOCK("mxc_w1.0", NULL, owire_clk)
680 _REGISTER_CLOCK(NULL, "rtc", rtc_clk)
681 _REGISTER_CLOCK(NULL, "scc", scc_clk)
684 /* Adjust the clock path for TO2 and later */
685 static void __init to2_adjust_clocks(void)
687 unsigned long cscr = __raw_readl(CCM_CSCR);
689 if (mx27_revision() >= IMX_CHIP_REVISION_2_0) {
690 if (cscr & CCM_CSCR_ARM_SRC)
691 cpu_clk.parent = &mpll_main1_clk;
693 if (!(cscr & CCM_CSCR_SSI2))
694 ssi1_clk.parent = &spll_clk;
696 if (!(cscr & CCM_CSCR_SSI1))
697 ssi1_clk.parent = &spll_clk;
699 if (!(cscr & CCM_CSCR_VPU))
700 vpu_clk.parent = &spll_clk;
702 cpu_clk.parent = &mpll_clk;
703 cpu_clk.set_parent = NULL;
704 cpu_clk.round_rate = NULL;
705 cpu_clk.set_rate = NULL;
706 ahb_clk.parent = &mpll_clk;
708 per1_clk.parent = &mpll_clk;
709 per2_clk.parent = &mpll_clk;
710 per3_clk.parent = &mpll_clk;
711 per4_clk.parent = &mpll_clk;
713 ssi1_clk.parent = &mpll_clk;
714 ssi2_clk.parent = &mpll_clk;
716 vpu_clk.parent = &mpll_clk;
721 * must be called very early to get information about the
722 * available clock rate when the timer framework starts
724 int __init mx27_clocks_init(unsigned long fref)
726 u32 cscr = __raw_readl(CCM_CSCR);
728 external_high_reference = fref;
730 /* detect clock reference for both system PLLs */
731 if (cscr & CCM_CSCR_MCU)
732 mpll_clk.parent = &ckih_clk;
734 mpll_clk.parent = &fpm_clk;
736 if (cscr & CCM_CSCR_SP)
737 spll_clk.parent = &ckih_clk;
739 spll_clk.parent = &fpm_clk;
743 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
745 /* Turn off all clocks we do not need */
746 __raw_writel(0, CCM_PCCR0);
747 __raw_writel((1 << 10) | (1 << 19), CCM_PCCR1);
749 spll_clk.disable(&spll_clk);
751 /* enable basic clocks */
752 clk_enable(&per1_clk);
753 clk_enable(&gpio_clk);
754 clk_enable(&emi_clk);
755 clk_enable(&iim_clk);
756 imx_print_silicon_rev("i.MX27", mx27_revision());
757 clk_disable(&iim_clk);
759 #if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_ICEDCC)
760 clk_enable(&uart1_clk);
763 mxc_timer_init(&gpt1_clk, MX27_IO_ADDRESS(MX27_GPT1_BASE_ADDR),
770 int __init mx27_clocks_init_dt(void)
772 struct device_node *np;
773 u32 fref = 26000000; /* default */
775 for_each_compatible_node(np, NULL, "fixed-clock") {
776 if (!of_device_is_compatible(np, "fsl,imx-osc26m"))
779 if (!of_property_read_u32(np, "clock-frequency", &fref))
783 return mx27_clocks_init(fref);