1 /* arch/arm/mach-rk29/clock.c
3 * Copyright (C) 2010 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
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.
17 #define pr_fmt(fmt) "clock: %s: " fmt, __func__
19 #include <linux/clk.h>
20 #include <linux/debugfs.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
26 #include <linux/kernel.h>
27 #include <linux/list.h>
28 #include <linux/module.h>
29 #include <linux/version.h>
30 #include <asm/clkdev.h>
31 #include <mach/rk29_iomap.h>
38 #define RATE_FIXED (1 << 1) /* Fixed clock rate */
39 #define CONFIG_PARTICIPANT (1 << 10) /* Fundamental clock */
41 #define cru_readl(offset) readl(RK29_CRU_BASE + offset)
42 #define cru_writel(v, offset) writel(v, RK29_CRU_BASE + offset)
44 #define regfile_readl(offset) readl(RK29_GRF_BASE + offset)
45 #define pmu_readl(offset) readl(RK29_PMU_BASE + offset)
47 #define MHZ (1000*1000)
51 struct list_head node;
54 struct list_head children;
55 struct list_head sibling; /* node for children */
58 int (*mode)(struct clk *clk, int on);
59 unsigned long (*recalc)(struct clk *); /* if null, follow parent */
60 int (*set_rate)(struct clk *, unsigned long);
61 long (*round_rate)(struct clk *, unsigned long);
62 struct clk* (*get_parent)(struct clk *); /* get clk's parent from the hardware. default is clksel_get_parent if parents present */
63 int (*set_parent)(struct clk *, struct clk *); /* default is clksel_set_parent if parents present */
71 u8 clksel_parent_mask;
72 u8 clksel_parent_shift;
76 static int clk_enable_nolock(struct clk *clk);
77 static void clk_disable_nolock(struct clk *clk);
78 static int clk_set_rate_nolock(struct clk *clk, unsigned long rate);
79 static int clk_set_parent_nolock(struct clk *clk, struct clk *parent);
80 static void __clk_reparent(struct clk *child, struct clk *parent);
81 static void __propagate_rate(struct clk *tclk);
82 static struct clk codec_pll_clk;
83 static struct clk general_pll_clk;
85 static unsigned long clksel_recalc_div(struct clk *clk)
87 u32 div = ((cru_readl(clk->clksel_con) >> clk->clksel_shift) & clk->clksel_mask) + 1;
88 unsigned long rate = clk->parent->rate / div;
89 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
93 static unsigned long clksel_recalc_shift(struct clk *clk)
95 u32 shift = (cru_readl(clk->clksel_con) >> clk->clksel_shift) & clk->clksel_mask;
96 unsigned long rate = clk->parent->rate >> shift;
97 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
101 static unsigned long clksel_recalc_frac(struct clk *clk)
105 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
106 if (r == 0) // FPGA ?
107 return clk->parent->rate;
109 denominator = r & 0xFFFF;
110 rate64 = (u64)clk->parent->rate * numerator;
111 do_div(rate64, denominator);
113 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
117 static int clksel_set_rate_div(struct clk *clk, unsigned long rate)
121 for (div = 0; div <= clk->clksel_mask; div++) {
122 u32 new_rate = clk->parent->rate / (div + 1);
123 if (new_rate <= rate) {
124 u32 v = cru_readl(clk->clksel_con);
125 v &= ~((u32) clk->clksel_mask << clk->clksel_shift);
126 v |= div << clk->clksel_shift;
127 cru_writel(v, clk->clksel_con);
128 clk->rate = new_rate;
129 pr_debug("clksel_set_rate_div for clock %s to rate %ld (div %d)\n", clk->name, rate, div + 1);
137 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
141 for (shift = 0; (1 << shift) <= clk->clksel_maxdiv; shift++) {
142 u32 new_rate = clk->parent->rate >> shift;
143 if (new_rate <= rate) {
144 u32 v = cru_readl(clk->clksel_con);
145 v &= ~((u32) clk->clksel_mask << clk->clksel_shift);
146 v |= shift << clk->clksel_shift;
147 cru_writel(v, clk->clksel_con);
148 clk->rate = new_rate;
149 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
157 static struct clk* clksel_get_parent(struct clk *clk)
159 return clk->parents[(cru_readl(clk->clksel_con) >> clk->clksel_parent_shift) & clk->clksel_parent_mask];
162 static int clksel_set_parent(struct clk *clk, struct clk *parent)
164 struct clk **p = clk->parents;
169 for (i = 0; (i <= clk->clksel_parent_mask) && *p; i++, p++) {
173 v = cru_readl(clk->clksel_con);
174 v &= ~((u32) clk->clksel_parent_mask << clk->clksel_parent_shift);
175 v |= (i << clk->clksel_parent_shift);
176 cru_writel(v, clk->clksel_con);
182 static int gate_mode(struct clk *clk, int on)
185 int idx = clk->gate_idx;
188 if (idx >= CLK_GATE_MAX)
191 reg = CRU_CLKGATE0_CON;
192 reg += (idx >> 5) << 2;
197 v &= ~(1 << idx); // clear bit
199 v |= (1 << idx); // set bit
206 static struct clk xin24m = {
212 static struct clk clk_12m = {
219 static struct clk xin27m = {
225 static struct clk otgphy0_clkin = {
226 .name = "otgphy0_clkin",
231 static struct clk otgphy1_clkin = {
232 .name = "otgphy1_clkin",
238 static void delay_500ns(void)
245 static void delay_300us(void)
248 for (i = 0; i < 600; i++)
252 #define GENERAL_PLL_IDX 0
253 #define CODEC_PLL_IDX 1
254 #define ARM_PLL_IDX 2
255 #define DDR_PLL_IDX 3
257 #define GRF_SOC_CON0 0xbc
258 static void pll_wait_lock(int pll_idx)
260 u32 bit = 0x2000000u << pll_idx;
263 if (regfile_readl(GRF_SOC_CON0) & bit)
268 pr_warning("wait pll bit 0x%x time out!\n", bit);
272 static unsigned long arm_pll_clk_recalc(struct clk *clk)
276 if ((cru_readl(CRU_MODE_CON) & CRU_CPU_MODE_MASK) == CRU_CPU_MODE_NORMAL) {
277 u32 v = cru_readl(CRU_APLL_CON);
278 u64 rate64 = (u64) clk->parent->rate * PLL_NF2(v);
279 do_div(rate64, PLL_NR(v));
280 rate = rate64 >> PLL_NO_SHIFT(v);
281 pr_debug("%s new clock rate is %ld (NF %d NR %d NO %d)\n", clk->name, rate, PLL_NF2(v), PLL_NR(v), 1 << PLL_NO_SHIFT(v));
283 rate = clk->parent->rate;
284 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
296 #define CORE_ACLK_11 (0 << 5)
297 #define CORE_ACLK_21 (1 << 5)
298 #define CORE_ACLK_31 (2 << 5)
299 #define CORE_ACLK_41 (3 << 5)
300 #define CORE_ACLK_81 (4 << 5)
301 #define CORE_ACLK_MASK (7 << 5)
303 #define ACLK_HCLK_11 (0 << 8)
304 #define ACLK_HCLK_21 (1 << 8)
305 #define ACLK_HCLK_41 (2 << 8)
306 #define ACLK_HCLK_MASK (3 << 8)
308 #define ACLK_PCLK_11 (0 << 10)
309 #define ACLK_PCLK_21 (1 << 10)
310 #define ACLK_PCLK_41 (2 << 10)
311 #define ACLK_PCLK_81 (3 << 10)
312 #define ACLK_PCLK_MASK (3 << 10)
314 #define ARM_PLL(_mhz, nr, nf, no, _axi_div, _ahb_div, _apb_div) \
316 .rate = _mhz * MHZ, \
317 .apll_con = PLL_CLKR(nr) | PLL_CLKF(nf >> 1) | PLL_NO_##no, \
318 .clksel0_con = CORE_ACLK_##_axi_div | ACLK_HCLK_##_ahb_div | ACLK_PCLK_##_apb_div, \
321 static const struct arm_pll_set arm_pll[] = {
322 // rate = 24 * NF / (NR * NO)
323 // rate NR NF NO adiv hdiv pdiv
324 ARM_PLL(1200, 1, 50, 1, 41, 21, 81),
325 ARM_PLL(1104, 1, 46, 1, 41, 21, 81),
326 ARM_PLL(1008, 1, 42, 1, 41, 21, 81),
327 ARM_PLL( 912, 1, 38, 1, 31, 21, 81),
328 ARM_PLL( 888, 2, 74, 1, 31, 21, 81),
329 ARM_PLL( 816, 1, 34, 1, 31, 21, 81),
330 ARM_PLL( 696, 1, 58, 2, 31, 21, 81),
331 ARM_PLL( 624, 1, 52, 2, 31, 21, 81),
332 ARM_PLL( 600, 1, 50, 2, 21, 21, 81),
333 ARM_PLL( 504, 1, 42, 2, 21, 21, 81),
334 ARM_PLL( 408, 1, 34, 2, 21, 21, 81),
335 ARM_PLL( 300, 1, 50, 4, 21, 21, 41),
336 ARM_PLL( 204, 1, 34, 4, 21, 21, 41),
337 ARM_PLL( 102, 1, 34, 8, 21, 21, 41),
338 // last item, pll power down.
339 ARM_PLL( 24, 1, 64, 8, 21, 21, 41),
342 #define CORE_PARENT_MASK (3 << 23)
343 #define CORE_PARENT_ARM_PLL (0 << 23)
344 #define CORE_PARENT_GENERAL_PLL (1 << 23)
346 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
348 const struct arm_pll_set *ps, *pt;
350 /* find the arm_pll we want. */
351 ps = pt = &arm_pll[0];
353 if (pt->rate == rate) {
357 // we are sorted, and ps->rate > pt->rate.
358 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
360 if (pt->rate < rate || pt->rate == 24 * MHZ)
365 /* make aclk safe & reparent to general pll */
366 cru_writel((cru_readl(CRU_CLKSEL0_CON) & ~(CORE_PARENT_MASK | CORE_ACLK_MASK)) | CORE_PARENT_GENERAL_PLL | CORE_ACLK_21, CRU_CLKSEL0_CON);
368 /* enter slow mode */
369 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | CRU_CPU_MODE_SLOW, CRU_MODE_CON);
372 cru_writel(cru_readl(CRU_APLL_CON) | PLL_PD, CRU_APLL_CON);
376 cru_writel(ps->apll_con | PLL_PD, CRU_APLL_CON);
381 cru_writel(ps->apll_con, CRU_APLL_CON);
384 pll_wait_lock(ARM_PLL_IDX);
386 /* reparent to arm pll & set aclk/hclk/pclk */
387 cru_writel((cru_readl(CRU_CLKSEL0_CON) & ~(CORE_PARENT_MASK | CORE_ACLK_MASK | ACLK_HCLK_MASK | ACLK_PCLK_MASK)) | CORE_PARENT_ARM_PLL | ps->clksel0_con, CRU_CLKSEL0_CON);
389 /* enter normal mode */
390 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | CRU_CPU_MODE_NORMAL, CRU_MODE_CON);
395 static struct clk *arm_pll_parents[2] = { &xin24m, &xin27m };
397 static struct clk arm_pll_clk = {
400 .recalc = arm_pll_clk_recalc,
401 .set_rate = arm_pll_clk_set_rate,
402 .clksel_con = CRU_MODE_CON,
403 .clksel_parent_mask = 1,
404 .clksel_parent_shift = 8,
405 .parents = arm_pll_parents,
408 static unsigned long ddr_pll_clk_recalc(struct clk *clk)
412 if ((cru_readl(CRU_MODE_CON) & CRU_DDR_MODE_MASK) == CRU_DDR_MODE_NORMAL) {
413 u32 v = cru_readl(CRU_DPLL_CON);
414 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
415 do_div(rate64, PLL_NR(v));
416 rate = rate64 >> PLL_NO_SHIFT(v);
417 pr_debug("%s new clock rate is %ld (NF %d NR %d NO %d)\n", clk->name, rate, PLL_NF(v), PLL_NR(v), 1 << PLL_NO_SHIFT(v));
419 rate = clk->parent->rate;
420 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
426 static struct clk *ddr_pll_parents[4] = { &xin24m, &xin27m, &codec_pll_clk, &general_pll_clk };
428 static struct clk ddr_pll_clk = {
431 .recalc = ddr_pll_clk_recalc,
432 .clksel_con = CRU_MODE_CON,
433 .clksel_parent_mask = 3,
434 .clksel_parent_shift = 13,
435 .parents = ddr_pll_parents,
439 static int codec_pll_clk_mode(struct clk *clk, int on)
441 u32 cpll = cru_readl(CRU_CPLL_CON);
443 cru_writel(cpll & ~(PLL_PD | PLL_BYPASS), CRU_CPLL_CON);
445 pll_wait_lock(CODEC_PLL_IDX);
446 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | CRU_CODEC_MODE_NORMAL, CRU_MODE_CON);
448 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | CRU_CODEC_MODE_SLOW, CRU_MODE_CON);
449 cru_writel(cpll | PLL_BYPASS, CRU_CPLL_CON);
450 cru_writel(cpll | PLL_PD | PLL_BYPASS, CRU_CPLL_CON);
456 static unsigned long codec_pll_clk_recalc(struct clk *clk)
459 u32 v = cru_readl(CRU_CPLL_CON);
460 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
461 do_div(rate64, PLL_NR(v));
462 rate = rate64 >> PLL_NO_SHIFT(v);
463 pr_debug("%s new clock rate is %ld (NF %d NR %d NO %d)\n", clk->name, rate, PLL_NF(v), PLL_NR(v), 1 << PLL_NO_SHIFT(v));
464 if ((cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK) != CRU_CODEC_MODE_NORMAL)
465 pr_debug("%s rate is %ld (slow mode) actually\n", clk->name, clk->parent->rate);
469 #define CODEC_PLL_PARENT_MASK (3 << 11)
470 #define CODEC_PLL_PARENT_XIN24M (0 << 11)
471 #define CODEC_PLL_PARENT_XIN27M (1 << 11)
472 #define CODEC_PLL_PARENT_DDR_PLL (2 << 11)
473 #define CODEC_PLL_PARENT_GENERAL_PLL (3 << 11)
475 struct codec_pll_set {
481 #define CODEC_PLL(_mhz, _parent, band, nr, nf, no) \
483 .rate = _mhz * MHZ, \
484 .pll_con = PLL_##band##_BAND | PLL_CLKR(nr) | PLL_CLKF(nf) | PLL_NO_##no, \
485 .parent_con = CODEC_PLL_PARENT_XIN##_parent##M, \
488 static const struct codec_pll_set codec_pll[] = {
489 // rate parent band NR NF NO
490 CODEC_PLL(108, 24, LOW, 1, 18, 4), // for TV
491 CODEC_PLL(648, 24, HIGH, 1, 27, 1),
492 CODEC_PLL(297, 27, LOW, 1, 22, 2), // for HDMI
493 CODEC_PLL(594, 27, LOW, 1, 22, 1),
494 CODEC_PLL(360, 24, LOW, 1, 15, 1), // for GPU
495 CODEC_PLL(408, 24, LOW, 1, 17, 1),
496 CODEC_PLL(456, 24, LOW, 1, 19, 1),
497 CODEC_PLL(504, 24, LOW, 1, 21, 1),
498 CODEC_PLL(552, 24, LOW, 1, 23, 1),
499 CODEC_PLL(600, 24, HIGH, 1, 25, 1),
502 static int codec_pll_clk_set_rate(struct clk *clk, unsigned long rate)
507 const struct codec_pll_set *ps = NULL;
509 for (i = 0; i < ARRAY_SIZE(codec_pll); i++) {
510 if (codec_pll[i].rate == rate) {
518 work_mode = cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK;
520 /* enter slow mode */
521 cru_writel((cru_readl(CRU_MODE_CON) & ~(CRU_CODEC_MODE_MASK | CODEC_PLL_PARENT_MASK)) | CRU_CODEC_MODE_SLOW | ps->parent_con, CRU_MODE_CON);
524 cru_writel(cru_readl(CRU_CPLL_CON) | PLL_PD, CRU_CPLL_CON);
528 cru_writel(ps->pll_con | PLL_PD, CRU_CPLL_CON);
533 cru_writel(ps->pll_con, CRU_CPLL_CON);
536 pll_wait_lock(CODEC_PLL_IDX);
538 /* enter normal mode */
539 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | work_mode, CRU_MODE_CON);
541 clk_set_parent_nolock(clk, ps->parent_con == CODEC_PLL_PARENT_XIN24M ? &xin24m : &xin27m);
546 static struct clk *codec_pll_parents[4] = { &xin24m, &xin27m, &ddr_pll_clk, &general_pll_clk };
548 static struct clk codec_pll_clk = {
551 .mode = codec_pll_clk_mode,
552 .recalc = codec_pll_clk_recalc,
553 .set_rate = codec_pll_clk_set_rate,
554 .clksel_con = CRU_MODE_CON,
555 .clksel_parent_mask = 3,
556 .clksel_parent_shift = 11,
557 .parents = codec_pll_parents,
561 static unsigned long general_pll_clk_recalc(struct clk *clk)
565 if ((cru_readl(CRU_MODE_CON) & CRU_GENERAL_MODE_MASK) == CRU_GENERAL_MODE_NORMAL) {
566 u32 v = cru_readl(CRU_GPLL_CON);
567 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
568 do_div(rate64, PLL_NR(v));
569 rate = rate64 >> PLL_NO_SHIFT(v);
570 pr_debug("%s new clock rate is %ld (NF %d NR %d NO %d)\n", clk->name, rate, PLL_NF(v), PLL_NR(v), 1 << PLL_NO_SHIFT(v));
572 rate = clk->parent->rate;
573 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
579 static int general_pll_clk_set_rate(struct clk *clk, unsigned long rate)
585 /* 288M: low-band, NR=1, NF=24, NO=2 */
586 pll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(24) | PLL_NO_2;
589 /* 624M: high-band, NR=1, NF=26, NO=1 */
590 pll_con = PLL_HIGH_BAND | PLL_CLKR(1) | PLL_CLKF(26) | PLL_NO_1;
597 /* enter slow mode */
598 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_GENERAL_MODE_MASK) | CRU_GENERAL_MODE_SLOW, CRU_MODE_CON);
601 cru_writel(cru_readl(CRU_GPLL_CON) | PLL_PD, CRU_GPLL_CON);
605 cru_writel(pll_con | PLL_PD, CRU_GPLL_CON);
610 cru_writel(pll_con, CRU_GPLL_CON);
613 pll_wait_lock(GENERAL_PLL_IDX);
615 /* enter normal mode */
616 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_GENERAL_MODE_MASK) | CRU_GENERAL_MODE_NORMAL, CRU_MODE_CON);
621 static struct clk *general_pll_parents[4] = { &xin24m, &xin27m, &ddr_pll_clk, &codec_pll_clk };
623 static struct clk general_pll_clk = {
624 .name = "general_pll",
626 .recalc = general_pll_clk_recalc,
627 .set_rate = general_pll_clk_set_rate,
628 .clksel_con = CRU_MODE_CON,
629 .clksel_parent_mask = 3,
630 .clksel_parent_shift = 9,
631 .parents = general_pll_parents,
635 static struct clk *clk_core_parents[4] = { &arm_pll_clk, &general_pll_clk, &codec_pll_clk, &ddr_pll_clk };
637 static struct clk clk_core = {
639 .parent = &arm_pll_clk,
640 .recalc = clksel_recalc_div,
641 .clksel_con = CRU_CLKSEL0_CON,
644 .clksel_parent_mask = 3,
645 .clksel_parent_shift = 23,
646 .parents = clk_core_parents,
649 static unsigned long aclk_cpu_recalc(struct clk *clk)
652 u32 div = ((cru_readl(CRU_CLKSEL0_CON) >> 5) & 0x7) + 1;
657 rate = clk->parent->rate / div;
658 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
663 static struct clk aclk_cpu = {
666 .recalc = aclk_cpu_recalc,
669 static struct clk hclk_cpu = {
672 .recalc = clksel_recalc_shift,
673 .set_rate = clksel_set_rate_shift,
674 .clksel_con = CRU_CLKSEL0_CON,
680 static struct clk pclk_cpu = {
683 .recalc = clksel_recalc_shift,
684 .set_rate = clksel_set_rate_shift,
685 .clksel_con = CRU_CLKSEL0_CON,
691 static struct clk *aclk_periph_parents[4] = { &general_pll_clk, &arm_pll_clk, &ddr_pll_clk, &codec_pll_clk };
693 static struct clk aclk_periph = {
694 .name = "aclk_periph",
696 .gate_idx = CLK_GATE_ACLK_PEIRPH,
697 .recalc = clksel_recalc_div,
698 .set_rate = clksel_set_rate_div,
699 .clksel_con = CRU_CLKSEL0_CON,
702 .clksel_parent_mask = 3,
703 .clksel_parent_shift = 12,
704 .parents = aclk_periph_parents,
707 static struct clk pclk_periph = {
708 .name = "pclk_periph",
710 .gate_idx = CLK_GATE_PCLK_PEIRPH,
711 .parent = &aclk_periph,
712 .recalc = clksel_recalc_shift,
713 .set_rate = clksel_set_rate_shift,
714 .clksel_con = CRU_CLKSEL0_CON,
720 static struct clk hclk_periph = {
721 .name = "hclk_periph",
723 .gate_idx = CLK_GATE_HCLK_PEIRPH,
724 .parent = &aclk_periph,
725 .recalc = clksel_recalc_shift,
726 .set_rate = clksel_set_rate_shift,
727 .clksel_con = CRU_CLKSEL0_CON,
734 static struct clk *clk_uhost_parents[8] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
736 static struct clk clk_uhost = {
739 .recalc = clksel_recalc_div,
740 .set_rate = clksel_set_rate_div,
741 .gate_idx = CLK_GATE_UHOST,
742 .clksel_con = CRU_CLKSEL1_CON,
745 .clksel_parent_mask = 7,
746 .clksel_parent_shift = 13,
747 .parents = clk_uhost_parents,
750 static struct clk *clk_otgphy_parents[4] = { &xin24m, &clk_12m, &clk_uhost };
752 static struct clk clk_otgphy0 = {
755 .gate_idx = CLK_GATE_USBPHY0,
756 .clksel_con = CRU_CLKSEL1_CON,
757 .clksel_parent_mask = 3,
758 .clksel_parent_shift = 9,
759 .parents = clk_otgphy_parents,
762 static struct clk clk_otgphy1 = {
765 .gate_idx = CLK_GATE_USBPHY1,
766 .clksel_con = CRU_CLKSEL1_CON,
767 .clksel_parent_mask = 3,
768 .clksel_parent_shift = 11,
769 .parents = clk_otgphy_parents,
773 static struct clk rmii_clkin = {
774 .name = "rmii_clkin",
777 static struct clk *clk_mac_ref_div_parents[4] = { &arm_pll_clk, &general_pll_clk, &codec_pll_clk, &ddr_pll_clk };
779 static struct clk clk_mac_ref_div = {
780 .name = "mac_ref_div",
781 .recalc = clksel_recalc_div,
782 .set_rate = clksel_set_rate_div,
783 .clksel_con = CRU_CLKSEL1_CON,
786 .clksel_parent_mask = 3,
787 .clksel_parent_shift = 21,
788 .parents = clk_mac_ref_div_parents,
791 static struct clk *clk_mac_ref_parents[2] = { &clk_mac_ref_div, &rmii_clkin };
793 static struct clk clk_mac_ref = {
796 .gate_idx = CLK_GATE_MAC_REF,
797 .clksel_con = CRU_CLKSEL1_CON,
798 .clksel_parent_mask = 1,
799 .clksel_parent_shift = 28,
800 .parents = clk_mac_ref_parents,
804 static struct clk *clk_i2s_div_parents[8] = { &codec_pll_clk, &general_pll_clk, &arm_pll_clk, &ddr_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
806 static struct clk clk_i2s0_div = {
808 .recalc = clksel_recalc_div,
809 .set_rate = clksel_set_rate_div,
810 .clksel_con = CRU_CLKSEL2_CON,
813 .clksel_parent_mask = 7,
814 .clksel_parent_shift = 0,
815 .parents = clk_i2s_div_parents,
818 static struct clk clk_i2s1_div = {
820 .recalc = clksel_recalc_div,
821 .set_rate = clksel_set_rate_div,
822 .clksel_con = CRU_CLKSEL2_CON,
825 .clksel_parent_mask = 7,
826 .clksel_parent_shift = 10,
827 .parents = clk_i2s_div_parents,
830 static struct clk clk_spdif_div = {
832 .recalc = clksel_recalc_div,
833 .set_rate = clksel_set_rate_div,
834 .clksel_con = CRU_CLKSEL2_CON,
837 .clksel_parent_mask = 7,
838 .clksel_parent_shift = 20,
839 .parents = clk_i2s_div_parents,
842 static int clk_i2s_frac_div_set_rate(struct clk *clk, unsigned long rate)
844 u16 numerator, denominator;
847 case 8192000: /* 288*32/1125 */
851 case 11289600: /* 288*49/1250 */
855 case 12288000: /* 288*16/375 */
863 pr_debug("set clock %s to rate %ld (%d/%d)\n", clk->name, rate, numerator, denominator);
864 cru_writel((u32)numerator << 16 | denominator, clk->clksel_con);
869 static struct clk clk_i2s0_frac_div = {
870 .name = "i2s0_frac_div",
871 .parent = &clk_i2s0_div,
872 .recalc = clksel_recalc_frac,
873 .set_rate = clk_i2s_frac_div_set_rate,
874 .clksel_con = CRU_CLKSEL3_CON,
877 static struct clk clk_i2s1_frac_div = {
878 .name = "i2s1_frac_div",
879 .parent = &clk_i2s1_div,
880 .recalc = clksel_recalc_frac,
881 .set_rate = clk_i2s_frac_div_set_rate,
882 .clksel_con = CRU_CLKSEL4_CON,
885 static struct clk clk_spdif_frac_div = {
886 .name = "spdif_frac_div",
887 .parent = &clk_spdif_div,
888 .recalc = clksel_recalc_frac,
889 .set_rate = clk_i2s_frac_div_set_rate,
890 .clksel_con = CRU_CLKSEL5_CON,
893 static int i2s_set_rate(struct clk *clk, unsigned long rate)
898 if (rate == 12 * MHZ) {
901 parent = clk->parents[1]; /* frac div */
902 ret = clk_set_rate_nolock(parent, rate);
906 if (clk->parent != parent)
907 clk_set_parent_nolock(clk, parent);
912 static struct clk *clk_i2s0_parents[4] = { &clk_i2s0_div, &clk_i2s0_frac_div, &clk_12m, &xin24m };
914 static struct clk clk_i2s0 = {
917 .gate_idx = CLK_GATE_I2S0,
918 .set_rate = i2s_set_rate,
919 .clksel_con = CRU_CLKSEL2_CON,
920 .clksel_parent_mask = 3,
921 .clksel_parent_shift = 8,
922 .parents = clk_i2s0_parents,
925 static struct clk *clk_i2s1_parents[4] = { &clk_i2s1_div, &clk_i2s1_frac_div, &clk_12m, &xin24m };
927 static struct clk clk_i2s1 = {
930 .gate_idx = CLK_GATE_I2S1,
931 .set_rate = i2s_set_rate,
932 .clksel_con = CRU_CLKSEL2_CON,
933 .clksel_parent_mask = 3,
934 .clksel_parent_shift = 18,
935 .parents = clk_i2s1_parents,
938 static struct clk *clk_spdif_parents[4] = { &clk_spdif_div, &clk_spdif_frac_div, &clk_12m, &xin24m };
940 static struct clk clk_spdif = {
943 .gate_idx = CLK_GATE_SPDIF,
944 .set_rate = i2s_set_rate,
945 .clksel_con = CRU_CLKSEL2_CON,
946 .clksel_parent_mask = 3,
947 .clksel_parent_shift = 28,
948 .parents = clk_spdif_parents,
952 static struct clk *clk_spi_src_parents[4] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk };
954 static struct clk clk_spi_src = {
956 .clksel_con = CRU_CLKSEL6_CON,
957 .clksel_parent_mask = 3,
958 .clksel_parent_shift = 0,
959 .parents = clk_spi_src_parents,
962 static struct clk clk_spi0 = {
964 .parent = &clk_spi_src,
966 .recalc = clksel_recalc_div,
967 .set_rate = clksel_set_rate_div,
968 .gate_idx = CLK_GATE_SPI0,
969 .clksel_con = CRU_CLKSEL6_CON,
974 static struct clk clk_spi1 = {
976 .parent = &clk_spi_src,
978 .recalc = clksel_recalc_div,
979 .set_rate = clksel_set_rate_div,
980 .gate_idx = CLK_GATE_SPI1,
981 .clksel_con = CRU_CLKSEL6_CON,
987 static struct clk clk_saradc = {
989 .parent = &pclk_periph,
991 .recalc = clksel_recalc_div,
992 .set_rate = clksel_set_rate_div,
993 .gate_idx = CLK_GATE_SARADC,
994 .clksel_con = CRU_CLKSEL6_CON,
1000 static struct clk *clk_cpu_timer_parents[2] = { &pclk_cpu, &xin24m };
1002 static struct clk clk_timer0 = {
1005 .gate_idx = CLK_GATE_TIMER0,
1006 .clksel_con = CRU_CLKSEL6_CON,
1007 .clksel_parent_mask = 1,
1008 .clksel_parent_shift = 26,
1009 .parents = clk_cpu_timer_parents,
1012 static struct clk clk_timer1 = {
1015 .gate_idx = CLK_GATE_TIMER1,
1016 .clksel_con = CRU_CLKSEL6_CON,
1017 .clksel_parent_mask = 1,
1018 .clksel_parent_shift = 27,
1019 .parents = clk_cpu_timer_parents,
1022 static struct clk *clk_periph_timer_parents[2] = { &pclk_periph, &xin24m };
1024 static struct clk clk_timer2 = {
1027 .gate_idx = CLK_GATE_TIMER2,
1028 .clksel_con = CRU_CLKSEL6_CON,
1029 .clksel_parent_mask = 1,
1030 .clksel_parent_shift = 28,
1031 .parents = clk_periph_timer_parents,
1034 static struct clk clk_timer3 = {
1037 .gate_idx = CLK_GATE_TIMER3,
1038 .clksel_con = CRU_CLKSEL6_CON,
1039 .clksel_parent_mask = 1,
1040 .clksel_parent_shift = 29,
1041 .parents = clk_periph_timer_parents,
1045 static struct clk *clk_mmc_src_parents[4] = { &arm_pll_clk, &general_pll_clk, &codec_pll_clk, &ddr_pll_clk };
1047 static struct clk clk_mmc_src = {
1049 .clksel_con = CRU_CLKSEL7_CON,
1050 .clksel_parent_mask = 3,
1051 .clksel_parent_shift = 0,
1052 .parents = clk_mmc_src_parents,
1055 static struct clk clk_mmc0 = {
1057 .parent = &clk_mmc_src,
1059 .recalc = clksel_recalc_div,
1060 .set_rate = clksel_set_rate_div,
1061 .gate_idx = CLK_GATE_MMC0,
1062 .clksel_con = CRU_CLKSEL7_CON,
1063 .clksel_mask = 0x3F,
1067 static struct clk clk_mmc1 = {
1069 .parent = &clk_mmc_src,
1071 .recalc = clksel_recalc_div,
1072 .set_rate = clksel_set_rate_div,
1073 .gate_idx = CLK_GATE_MMC1,
1074 .clksel_con = CRU_CLKSEL7_CON,
1075 .clksel_mask = 0x3F,
1079 static struct clk clk_emmc = {
1081 .parent = &clk_mmc_src,
1083 .recalc = clksel_recalc_div,
1084 .set_rate = clksel_set_rate_div,
1085 .gate_idx = CLK_GATE_EMMC,
1086 .clksel_con = CRU_CLKSEL7_CON,
1087 .clksel_mask = 0x3F,
1092 static struct clk *clk_ddr_parents[8] = { &ddr_pll_clk, &general_pll_clk, &codec_pll_clk, &arm_pll_clk };
1094 static struct clk clk_ddr = {
1096 .recalc = clksel_recalc_shift,
1097 .clksel_con = CRU_CLKSEL7_CON,
1100 .clksel_maxdiv = 32,
1101 .clksel_parent_mask = 3,
1102 .clksel_parent_shift = 24,
1103 .parents = clk_ddr_parents,
1107 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
1111 struct clk *clk_div = clk->parents[0];
1114 case 24*MHZ: /* 1.5M/0.5M/50/75/150/200/300/600/1200/2400 */
1115 parent = clk->parents[2]; /* xin24m */
1124 parent = clk->parents[1]; /* frac div */
1125 /* reset div to 1 */
1126 ret = clk_set_rate_nolock(clk_div, clk_div->parent->rate);
1135 if (parent->set_rate) {
1136 ret = clk_set_rate_nolock(parent, rate);
1141 if (clk->parent != parent)
1142 clk_set_parent_nolock(clk, parent);
1147 static int clk_uart_frac_div_set_rate(struct clk *clk, unsigned long rate)
1149 u16 numerator, denominator;
1152 case 19200*16: /* 288*2/1875 */
1156 case 38400*16: /* 288*4/1875 */
1160 case 57600*16: /* 288*2/625 */
1164 case 115200*16: /* 288*8/1250 */
1168 case 230400*16: /* 288*8/625 */
1172 case 460800*16: /* 288*16/25 */
1176 case 576000*16: /* 288*20/625 */
1184 pr_debug("set clock %s to rate %ld (%d/%d)\n", clk->name, rate, numerator, denominator);
1185 cru_writel((u32)numerator << 16 | denominator, clk->clksel_con);
1189 static struct clk *clk_uart_src_parents[8] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
1191 static struct clk clk_uart01_src = {
1192 .name = "uart01_src",
1193 .clksel_con = CRU_CLKSEL8_CON,
1194 .clksel_parent_mask = 7,
1195 .clksel_parent_shift = 0,
1196 .parents = clk_uart_src_parents,
1199 static struct clk clk_uart0_div = {
1200 .name = "uart0_div",
1201 .parent = &clk_uart01_src,
1202 .recalc = clksel_recalc_div,
1203 .set_rate = clksel_set_rate_div,
1204 .clksel_con = CRU_CLKSEL8_CON,
1205 .clksel_mask = 0x3F,
1209 static struct clk clk_uart0_frac_div = {
1210 .name = "uart0_frac_div",
1211 .parent = &clk_uart0_div,
1212 .recalc = clksel_recalc_frac,
1213 .set_rate = clk_uart_frac_div_set_rate,
1214 .clksel_con = CRU_CLKSEL10_CON,
1217 static struct clk *clk_uart0_parents[4] = { &clk_uart0_div, &clk_uart0_frac_div, &xin24m };
1219 static struct clk clk_uart0 = {
1222 .set_rate = clk_uart_set_rate,
1223 .gate_idx = CLK_GATE_UART0,
1224 .clksel_con = CRU_CLKSEL8_CON,
1225 .clksel_parent_mask = 3,
1226 .clksel_parent_shift = 9,
1227 .parents = clk_uart0_parents,
1230 static struct clk clk_uart1_div = {
1231 .name = "uart1_div",
1232 .parent = &clk_uart01_src,
1233 .recalc = clksel_recalc_div,
1234 .set_rate = clksel_set_rate_div,
1235 .clksel_con = CRU_CLKSEL8_CON,
1236 .clksel_mask = 0x3F,
1240 static struct clk clk_uart1_frac_div = {
1241 .name = "uart1_frac_div",
1242 .parent = &clk_uart1_div,
1243 .recalc = clksel_recalc_frac,
1244 .set_rate = clk_uart_frac_div_set_rate,
1245 .clksel_con = CRU_CLKSEL11_CON,
1248 static struct clk *clk_uart1_parents[4] = { &clk_uart1_div, &clk_uart1_frac_div, &xin24m };
1250 static struct clk clk_uart1 = {
1253 .set_rate = clk_uart_set_rate,
1254 .gate_idx = CLK_GATE_UART1,
1255 .clksel_con = CRU_CLKSEL8_CON,
1256 .clksel_parent_mask = 3,
1257 .clksel_parent_shift = 20,
1258 .parents = clk_uart1_parents,
1261 static struct clk clk_uart23_src = {
1262 .name = "uart23_src",
1263 .clksel_con = CRU_CLKSEL9_CON,
1264 .clksel_parent_mask = 7,
1265 .clksel_parent_shift = 0,
1266 .parents = clk_uart_src_parents,
1269 static struct clk clk_uart2_div = {
1270 .name = "uart2_div",
1271 .parent = &clk_uart23_src,
1272 .recalc = clksel_recalc_div,
1273 .set_rate = clksel_set_rate_div,
1274 .clksel_con = CRU_CLKSEL9_CON,
1275 .clksel_mask = 0x3F,
1279 static struct clk clk_uart2_frac_div = {
1280 .name = "uart2_frac_div",
1281 .parent = &clk_uart2_div,
1282 .recalc = clksel_recalc_frac,
1283 .set_rate = clk_uart_frac_div_set_rate,
1284 .clksel_con = CRU_CLKSEL12_CON,
1287 static struct clk *clk_uart2_parents[4] = { &clk_uart2_div, &clk_uart2_frac_div, &xin24m };
1289 static struct clk clk_uart2 = {
1292 .set_rate = clk_uart_set_rate,
1293 .gate_idx = CLK_GATE_UART2,
1294 .clksel_con = CRU_CLKSEL9_CON,
1295 .clksel_parent_mask = 3,
1296 .clksel_parent_shift = 9,
1297 .parents = clk_uart2_parents,
1300 static struct clk clk_uart3_div = {
1301 .name = "uart3_div",
1302 .parent = &clk_uart23_src,
1303 .recalc = clksel_recalc_div,
1304 .set_rate = clksel_set_rate_div,
1305 .clksel_con = CRU_CLKSEL9_CON,
1306 .clksel_mask = 0x3F,
1310 static struct clk clk_uart3_frac_div = {
1311 .name = "uart3_frac_div",
1312 .parent = &clk_uart3_div,
1313 .recalc = clksel_recalc_frac,
1314 .set_rate = clk_uart_frac_div_set_rate,
1315 .clksel_con = CRU_CLKSEL13_CON,
1318 static struct clk *clk_uart3_parents[4] = { &clk_uart3_div, &clk_uart3_frac_div, &xin24m };
1320 static struct clk clk_uart3 = {
1323 .set_rate = clk_uart_set_rate,
1324 .gate_idx = CLK_GATE_UART3,
1325 .clksel_con = CRU_CLKSEL9_CON,
1326 .clksel_parent_mask = 3,
1327 .clksel_parent_shift = 20,
1328 .parents = clk_uart3_parents,
1332 static struct clk *clk_hsadc_div_parents[8] = { &codec_pll_clk, &ddr_pll_clk, &general_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
1334 static struct clk clk_hsadc_div = {
1335 .name = "hsadc_div",
1336 .recalc = clksel_recalc_div,
1337 .set_rate = clksel_set_rate_div,
1338 .clksel_con = CRU_CLKSEL14_CON,
1339 .clksel_mask = 0xFF,
1341 .clksel_parent_mask = 7,
1342 .clksel_parent_shift = 7,
1343 .parents = clk_hsadc_div_parents,
1346 static struct clk clk_hsadc_frac_div = {
1347 .name = "hsadc_frac_div",
1348 .parent = &clk_hsadc_div,
1349 .recalc = clksel_recalc_frac,
1350 .clksel_con = CRU_CLKSEL15_CON,
1353 static struct clk *clk_demod_parents[4] = { &clk_hsadc_div, &clk_hsadc_frac_div, &xin27m };
1355 static struct clk clk_demod = {
1357 .clksel_con = CRU_CLKSEL14_CON,
1358 .clksel_parent_mask = 3,
1359 .clksel_parent_shift = 18,
1360 .parents = clk_demod_parents,
1363 static struct clk gpsclk = {
1367 static struct clk *clk_hsadc_parents[2] = { &clk_demod, &gpsclk };
1369 static struct clk clk_hsadc = {
1372 .gate_idx = CLK_GATE_HSADC,
1373 .clksel_con = CRU_CLKSEL14_CON,
1374 .clksel_parent_mask = 1,
1375 .clksel_parent_shift = 21,
1376 .parents = clk_hsadc_parents,
1379 static unsigned long div2_recalc(struct clk *clk)
1381 return clk->parent->rate >> 1;
1384 static struct clk clk_hsadc_div2 = {
1385 .name = "hsadc_div2",
1386 .parent = &clk_demod,
1387 .recalc = div2_recalc,
1390 static struct clk clk_hsadc_div2_inv = {
1391 .name = "hsadc_div2_inv",
1392 .parent = &clk_demod,
1393 .recalc = div2_recalc,
1396 static struct clk *clk_hsadc_out_parents[2] = { &clk_hsadc_div2, &clk_hsadc_div2_inv };
1398 static struct clk clk_hsadc_out = {
1399 .name = "hsadc_out",
1400 .clksel_con = CRU_CLKSEL14_CON,
1401 .clksel_parent_mask = 1,
1402 .clksel_parent_shift = 20,
1403 .parents = clk_hsadc_out_parents,
1407 static struct clk *dclk_lcdc_div_parents[4] = { &codec_pll_clk, &ddr_pll_clk, &general_pll_clk, &arm_pll_clk };
1409 static struct clk dclk_lcdc_div = {
1410 .name = "dclk_lcdc_div",
1411 .recalc = clksel_recalc_div,
1412 .set_rate = clksel_set_rate_div,
1413 .clksel_con = CRU_CLKSEL16_CON,
1414 .clksel_mask = 0xFF,
1416 .clksel_parent_mask = 3,
1417 .clksel_parent_shift = 0,
1418 .parents = dclk_lcdc_div_parents,
1421 static struct clk *dclk_lcdc_parents[2] = { &dclk_lcdc_div, &xin27m };
1423 static struct clk dclk_lcdc = {
1424 .name = "dclk_lcdc",
1426 .gate_idx = CLK_GATE_DCLK_LCDC,
1427 .clksel_con = CRU_CLKSEL16_CON,
1428 .clksel_parent_mask = 1,
1429 .clksel_parent_shift = 10,
1430 .parents = dclk_lcdc_parents,
1433 static struct clk dclk_ebook = {
1434 .name = "dclk_ebook",
1436 .gate_idx = CLK_GATE_DCLK_EBOOK,
1437 .recalc = clksel_recalc_div,
1438 .set_rate = clksel_set_rate_div,
1439 .clksel_con = CRU_CLKSEL16_CON,
1440 .clksel_mask = 0x1F,
1442 .clksel_parent_mask = 3,
1443 .clksel_parent_shift = 11,
1444 .parents = dclk_lcdc_div_parents,
1447 static struct clk *aclk_lcdc_parents[4] = { &ddr_pll_clk, &codec_pll_clk, &general_pll_clk, &arm_pll_clk };
1449 static struct clk aclk_lcdc = {
1450 .name = "aclk_lcdc",
1452 .gate_idx = CLK_GATE_ACLK_LCDC,
1453 .recalc = clksel_recalc_div,
1454 .set_rate = clksel_set_rate_div,
1455 .clksel_con = CRU_CLKSEL16_CON,
1456 .clksel_mask = 0x1F,
1458 .clksel_parent_mask = 3,
1459 .clksel_parent_shift = 18,
1460 .parents = aclk_lcdc_parents,
1463 static struct clk hclk_lcdc = {
1464 .name = "hclk_lcdc",
1466 .gate_idx = CLK_GATE_HCLK_LCDC,
1467 .parent = &aclk_lcdc,
1468 .clksel_con = CRU_CLKSEL16_CON,
1469 .recalc = clksel_recalc_shift,
1470 .set_rate = clksel_set_rate_shift,
1476 static struct clk *xpu_parents[4] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk };
1478 static struct clk aclk_vepu = {
1479 .name = "aclk_vepu",
1481 .recalc = clksel_recalc_div,
1482 .set_rate = clksel_set_rate_div,
1483 .gate_idx = CLK_GATE_ACLK_VEPU,
1484 .clksel_con = CRU_CLKSEL17_CON,
1485 .clksel_mask = 0x1F,
1487 .clksel_parent_mask = 3,
1488 .clksel_parent_shift = 0,
1489 .parents = xpu_parents,
1492 static struct clk hclk_vepu = {
1493 .name = "hclk_vepu",
1494 .parent = &aclk_vepu,
1496 .recalc = clksel_recalc_shift,
1497 .set_rate = clksel_set_rate_shift,
1498 .gate_idx = CLK_GATE_HCLK_VEPU,
1499 .clksel_con = CRU_CLKSEL17_CON,
1505 static struct clk aclk_vdpu = {
1506 .name = "aclk_vdpu",
1507 .parent = &general_pll_clk,
1509 .recalc = clksel_recalc_div,
1510 .set_rate = clksel_set_rate_div,
1511 .gate_idx = CLK_GATE_ACLK_VDPU,
1512 .clksel_con = CRU_CLKSEL17_CON,
1513 .clksel_mask = 0x1F,
1515 .clksel_parent_mask = 3,
1516 .clksel_parent_shift = 7,
1517 .parents = xpu_parents,
1520 static struct clk hclk_vdpu = {
1521 .name = "hclk_vdpu",
1522 .parent = &aclk_vdpu,
1524 .recalc = clksel_recalc_shift,
1525 .set_rate = clksel_set_rate_shift,
1526 .gate_idx = CLK_GATE_HCLK_VDPU,
1527 .clksel_con = CRU_CLKSEL17_CON,
1533 static struct clk clk_gpu = {
1536 .gate_idx = CLK_GATE_GPU,
1537 .recalc = clksel_recalc_div,
1538 .set_rate = clksel_set_rate_div,
1539 .clksel_con = CRU_CLKSEL17_CON,
1540 .clksel_mask = 0x1F,
1542 .clksel_parent_mask = 3,
1543 .clksel_parent_shift = 14,
1544 .parents = xpu_parents,
1547 static struct clk aclk_gpu = {
1550 .gate_idx = CLK_GATE_ACLK_GPU,
1551 .recalc = clksel_recalc_div,
1552 .set_rate = clksel_set_rate_div,
1553 .clksel_con = CRU_CLKSEL17_CON,
1554 .clksel_mask = 0x1F,
1556 .clksel_parent_mask = 3,
1557 .clksel_parent_shift = 21,
1558 .parents = xpu_parents,
1562 static struct clk *clk_vip_parents[4] = { &xin24m, &xin27m, &dclk_ebook };
1564 static struct clk clk_vip = {
1567 .gate_idx = CLK_GATE_VIP,
1568 .clksel_con = CRU_CLKSEL1_CON,
1569 .clksel_parent_mask = 3,
1570 .clksel_parent_shift = 7,
1571 .parents = clk_vip_parents,
1575 #define GATE_CLK(NAME,PARENT,ID) \
1576 static struct clk clk_##NAME = { \
1578 .parent = &PARENT, \
1579 .mode = gate_mode, \
1580 .gate_idx = CLK_GATE_##ID, \
1583 GATE_CLK(i2c0, pclk_cpu, I2C0);
1584 GATE_CLK(i2c1, pclk_periph, I2C1);
1585 GATE_CLK(i2c2, pclk_periph, I2C2);
1586 GATE_CLK(i2c3, pclk_periph, I2C3);
1588 GATE_CLK(gpio0, pclk_cpu, GPIO0);
1589 GATE_CLK(gpio1, pclk_periph, GPIO1);
1590 GATE_CLK(gpio2, pclk_periph, GPIO2);
1591 GATE_CLK(gpio3, pclk_periph, GPIO3);
1592 GATE_CLK(gpio4, pclk_cpu, GPIO4);
1593 GATE_CLK(gpio5, pclk_periph, GPIO5);
1594 GATE_CLK(gpio6, pclk_cpu, GPIO6);
1596 GATE_CLK(dma1, aclk_cpu, DMA1);
1597 GATE_CLK(dma2, aclk_periph, DMA2);
1599 GATE_CLK(gic, aclk_cpu, GIC);
1600 GATE_CLK(intmem, aclk_cpu, INTMEM);
1601 GATE_CLK(rom, hclk_cpu, ROM);
1602 GATE_CLK(ddr_phy, aclk_cpu, DDR_PHY);
1603 GATE_CLK(ddr_reg, aclk_cpu, DDR_REG);
1604 GATE_CLK(ddr_cpu, aclk_cpu, DDR_CPU);
1605 GATE_CLK(efuse, pclk_cpu, EFUSE);
1606 GATE_CLK(tzpc, pclk_cpu, TZPC);
1607 GATE_CLK(debug, pclk_cpu, DEBUG);
1608 GATE_CLK(tpiu, pclk_cpu, TPIU);
1609 GATE_CLK(rtc, pclk_cpu, RTC);
1610 GATE_CLK(pmu, pclk_cpu, PMU);
1611 GATE_CLK(grf, pclk_cpu, GRF);
1613 GATE_CLK(emem, hclk_periph, EMEM);
1614 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
1615 GATE_CLK(aclk_ddr_peri, aclk_periph, ACLK_DDR_PERI);
1616 GATE_CLK(aclk_cpu_peri, aclk_cpu, ACLK_CPU_PERI);
1617 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
1618 GATE_CLK(smc, pclk_periph, SMC);
1619 GATE_CLK(hclk_mac, hclk_periph, HCLK_MAC);
1620 GATE_CLK(mii_tx, hclk_periph, MII_TX);
1621 GATE_CLK(mii_rx, hclk_periph, MII_RX);
1622 GATE_CLK(hif, hclk_periph, HIF);
1623 GATE_CLK(nandc, hclk_periph, NANDC);
1624 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
1625 GATE_CLK(usbotg0, hclk_periph, USBOTG0);
1626 GATE_CLK(usbotg1, hclk_periph, USBOTG1);
1627 GATE_CLK(hclk_uhost, hclk_periph, HCLK_UHOST);
1628 GATE_CLK(pid_filter, hclk_periph, PID_FILTER);
1630 GATE_CLK(vip_slave, hclk_lcdc, VIP_SLAVE);
1631 GATE_CLK(wdt, pclk_periph, WDT);
1632 GATE_CLK(pwm, pclk_periph, PWM);
1633 GATE_CLK(vip_bus, aclk_cpu, VIP_BUS);
1634 GATE_CLK(vip_matrix, clk_vip_bus, VIP_MATRIX);
1635 GATE_CLK(vip_input, hclk_cpu, VIP_INPUT);
1636 GATE_CLK(jtag, aclk_cpu, JTAG);
1638 GATE_CLK(aclk_ddr_lcdc, aclk_lcdc, ACLK_DDR_LCDC);
1639 GATE_CLK(aclk_ipp, aclk_lcdc, ACLK_IPP);
1640 GATE_CLK(hclk_ipp, hclk_lcdc, HCLK_IPP);
1641 GATE_CLK(hclk_ebook, hclk_lcdc, HCLK_EBOOK);
1642 GATE_CLK(aclk_disp_matrix, aclk_lcdc, ACLK_DISP_MATRIX);
1643 GATE_CLK(hclk_disp_matrix, hclk_lcdc, HCLK_DISP_MATRIX);
1644 GATE_CLK(aclk_ddr_vepu, aclk_vepu, ACLK_DDR_VEPU);
1645 GATE_CLK(aclk_ddr_vdpu, aclk_vdpu, ACLK_DDR_VDPU);
1646 GATE_CLK(aclk_ddr_gpu, aclk_gpu, ACLK_DDR_GPU);
1647 GATE_CLK(hclk_gpu, hclk_cpu, HCLK_GPU);
1648 GATE_CLK(hclk_cpu_vcodec, hclk_cpu, HCLK_CPU_VCODEC);
1649 GATE_CLK(hclk_cpu_display, hclk_cpu, HCLK_CPU_DISPLAY);
1651 GATE_CLK(hclk_mmc0, hclk_periph, HCLK_MMC0);
1652 GATE_CLK(hclk_mmc1, hclk_periph, HCLK_MMC1);
1653 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
1655 #define CLK(dev, con, ck) \
1662 #define CLK1(name) \
1666 .clk = &clk_##name, \
1669 static struct clk_lookup clks[] = {
1670 CLK(NULL, "xin24m", &xin24m),
1671 CLK(NULL, "xin27m", &xin27m),
1672 CLK(NULL, "otgphy0_clkin", &otgphy0_clkin),
1673 CLK(NULL, "otgphy1_clkin", &otgphy1_clkin),
1674 CLK(NULL, "gpsclk", &gpsclk),
1677 CLK(NULL, "arm_pll", &arm_pll_clk),
1678 CLK(NULL, "ddr_pll", &ddr_pll_clk),
1679 CLK(NULL, "codec_pll", &codec_pll_clk),
1680 CLK(NULL, "general_pll", &general_pll_clk),
1683 CLK(NULL, "aclk_cpu", &aclk_cpu),
1684 CLK(NULL, "hclk_cpu", &hclk_cpu),
1685 CLK(NULL, "pclk_cpu", &pclk_cpu),
1687 CLK(NULL, "aclk_periph", &aclk_periph),
1688 CLK(NULL, "hclk_periph", &hclk_periph),
1689 CLK(NULL, "pclk_periph", &pclk_periph),
1698 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
1699 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
1700 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
1701 CLK("rk29_i2s.1", "i2s_div", &clk_i2s1_div),
1702 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s1_frac_div),
1703 CLK("rk29_i2s.1", "i2s", &clk_i2s1),
1704 CLK(NULL, "spdif_div", &clk_spdif_div),
1705 CLK(NULL, "spdif_frac_div", &clk_spdif_frac_div),
1706 CLK(NULL, "spdif", &clk_spdif),
1709 CLK("rk29xx_spim.0", "spi", &clk_spi0),
1710 CLK("rk29xx_spim.1", "spi", &clk_spi1),
1719 CLK("rk29_sdmmc.0", "mmc", &clk_mmc0),
1720 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_mmc0),
1721 CLK("rk29_sdmmc.1", "mmc", &clk_mmc1),
1722 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_mmc1),
1728 CLK("rk29_serial.0", "uart", &clk_uart0),
1729 CLK("rk29_serial.0", "uart_div", &clk_uart0_div),
1730 CLK("rk29_serial.0", "uart_frac_div", &clk_uart0_frac_div),
1731 CLK("rk29_serial.1", "uart", &clk_uart1),
1732 CLK("rk29_serial.1", "uart_div", &clk_uart1_div),
1733 CLK("rk29_serial.1", "uart_frac_div", &clk_uart1_frac_div),
1736 CLK("rk29_serial.2", "uart", &clk_uart2),
1737 CLK("rk29_serial.2", "uart_div", &clk_uart2_div),
1738 CLK("rk29_serial.2", "uart_frac_div", &clk_uart2_frac_div),
1739 CLK("rk29_serial.3", "uart", &clk_uart3),
1740 CLK("rk29_serial.3", "uart_div", &clk_uart3_div),
1741 CLK("rk29_serial.3", "uart_frac_div", &clk_uart3_frac_div),
1744 CLK1(hsadc_frac_div),
1748 CLK1(hsadc_div2_inv),
1751 CLK(NULL, "dclk_lcdc_div", &dclk_lcdc_div),
1752 CLK(NULL, "dclk_lcdc", &dclk_lcdc),
1753 CLK(NULL, "dclk_ebook", &dclk_ebook),
1754 CLK(NULL, "aclk_lcdc", &aclk_lcdc),
1755 CLK(NULL, "hclk_lcdc", &hclk_lcdc),
1757 CLK(NULL, "aclk_vepu", &aclk_vepu),
1758 CLK(NULL, "hclk_vepu", &hclk_vepu),
1759 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
1760 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
1762 CLK(NULL, "aclk_gpu", &aclk_gpu),
1764 CLK("rk29_i2c.0", "i2c", &clk_i2c0),
1765 CLK("rk29_i2c.1", "i2c", &clk_i2c1),
1766 CLK("rk29_i2c.2", "i2c", &clk_i2c2),
1767 CLK("rk29_i2c.3", "i2c", &clk_i2c3),
1795 CLK1(hclk_usb_peri),
1796 CLK1(aclk_ddr_peri),
1797 CLK1(aclk_cpu_peri),
1819 CLK1(aclk_ddr_lcdc),
1823 CLK1(aclk_disp_matrix),
1824 CLK1(hclk_disp_matrix),
1825 CLK1(aclk_ddr_vepu),
1826 CLK1(aclk_ddr_vdpu),
1829 CLK1(hclk_cpu_vcodec),
1830 CLK1(hclk_cpu_display),
1833 static LIST_HEAD(clocks);
1834 static DEFINE_MUTEX(clocks_mutex);
1835 static DEFINE_SPINLOCK(clockfw_lock);
1836 #define LOCK() do { WARN_ON(in_irq()); if (!irqs_disabled()) spin_lock_bh(&clockfw_lock); } while (0)
1837 #define UNLOCK() do { if (!irqs_disabled()) spin_unlock_bh(&clockfw_lock); } while (0)
1839 static int clk_enable_nolock(struct clk *clk)
1843 if (clk->usecount == 0) {
1845 ret = clk_enable_nolock(clk->parent);
1851 ret = clk->mode(clk, 1);
1854 clk_disable_nolock(clk->parent);
1858 pr_debug("%s enabled\n", clk->name);
1865 int clk_enable(struct clk *clk)
1869 if (clk == NULL || IS_ERR(clk))
1873 ret = clk_enable_nolock(clk);
1878 EXPORT_SYMBOL(clk_enable);
1880 static void clk_disable_nolock(struct clk *clk)
1882 if (clk->usecount == 0) {
1883 printk(KERN_ERR "Trying disable clock %s with 0 usecount\n", clk->name);
1888 if (--clk->usecount == 0) {
1891 pr_debug("%s disabled\n", clk->name);
1893 clk_disable_nolock(clk->parent);
1897 void clk_disable(struct clk *clk)
1899 if (clk == NULL || IS_ERR(clk))
1903 clk_disable_nolock(clk);
1906 EXPORT_SYMBOL(clk_disable);
1908 unsigned long clk_get_rate(struct clk *clk)
1910 if (clk == NULL || IS_ERR(clk))
1915 EXPORT_SYMBOL(clk_get_rate);
1917 /*-------------------------------------------------------------------------
1918 * Optional clock functions defined in include/linux/clk.h
1919 *-------------------------------------------------------------------------*/
1921 /* Given a clock and a rate apply a clock specific rounding function */
1922 static long clk_round_rate_nolock(struct clk *clk, unsigned long rate)
1924 if (clk->round_rate)
1925 return clk->round_rate(clk, rate);
1927 if (clk->flags & RATE_FIXED)
1928 printk(KERN_ERR "clock: clk_round_rate called on fixed-rate clock %s\n", clk->name);
1933 long clk_round_rate(struct clk *clk, unsigned long rate)
1937 if (clk == NULL || IS_ERR(clk))
1941 ret = clk_round_rate_nolock(clk, rate);
1946 EXPORT_SYMBOL(clk_round_rate);
1948 static void __clk_recalc(struct clk *clk)
1950 if (unlikely(clk->flags & RATE_FIXED))
1953 clk->rate = clk->recalc(clk);
1954 else if (clk->parent)
1955 clk->rate = clk->parent->rate;
1956 pr_debug("%s new clock rate is %lu\n", clk->name, clk->rate);
1959 static int clk_set_rate_nolock(struct clk *clk, unsigned long rate)
1963 if (rate == clk->rate)
1966 pr_debug("set_rate for clock %s to rate %ld\n", clk->name, rate);
1968 if (clk->flags & CONFIG_PARTICIPANT)
1974 ret = clk->set_rate(clk, rate);
1978 __propagate_rate(clk);
1984 /* Set the clock rate for a clock source */
1985 int clk_set_rate(struct clk *clk, unsigned long rate)
1989 if (clk == NULL || IS_ERR(clk))
1993 ret = clk_set_rate_nolock(clk, rate);
1998 EXPORT_SYMBOL(clk_set_rate);
2000 static int clk_set_parent_nolock(struct clk *clk, struct clk *parent)
2003 int enabled = clk->usecount > 0;
2004 struct clk *old_parent = clk->parent;
2006 if (clk->parent == parent)
2009 /* if clk is already enabled, enable new parent first and disable old parent later. */
2011 clk_enable_nolock(parent);
2013 if (clk->set_parent)
2014 ret = clk->set_parent(clk, parent);
2016 ret = clksel_set_parent(clk, parent);
2020 __clk_reparent(clk, parent);
2022 __propagate_rate(clk);
2024 clk_disable_nolock(old_parent);
2027 clk_disable_nolock(parent);
2033 int clk_set_parent(struct clk *clk, struct clk *parent)
2037 if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent))
2040 if (clk->set_parent == NULL && clk->parents == NULL)
2044 if (clk->usecount == 0)
2045 ret = clk_set_parent_nolock(clk, parent);
2052 EXPORT_SYMBOL(clk_set_parent);
2054 struct clk *clk_get_parent(struct clk *clk)
2058 EXPORT_SYMBOL(clk_get_parent);
2060 static void __clk_reparent(struct clk *child, struct clk *parent)
2062 if (child->parent == parent)
2064 pr_debug("%s reparent to %s (was %s)\n", child->name, parent->name, ((child->parent) ? child->parent->name : "NULL"));
2066 list_del_init(&child->sibling);
2068 list_add(&child->sibling, &parent->children);
2069 child->parent = parent;
2072 /* Propagate rate to children */
2073 static void __propagate_rate(struct clk *tclk)
2077 list_for_each_entry(clkp, &tclk->children, sibling) {
2079 __propagate_rate(clkp);
2083 static LIST_HEAD(root_clks);
2086 * recalculate_root_clocks - recalculate and propagate all root clocks
2088 * Recalculates all root clocks (clocks with no parent), which if the
2089 * clock's .recalc is set correctly, should also propagate their rates.
2092 static void clk_recalculate_root_clocks_nolock(void)
2096 list_for_each_entry(clkp, &root_clks, sibling) {
2098 __propagate_rate(clkp);
2102 void clk_recalculate_root_clocks(void)
2105 clk_recalculate_root_clocks_nolock();
2111 * clk_preinit - initialize any fields in the struct clk before clk init
2112 * @clk: struct clk * to initialize
2114 * Initialize any struct clk fields needed before normal clk initialization
2115 * can run. No return value.
2117 static void clk_preinit(struct clk *clk)
2119 INIT_LIST_HEAD(&clk->children);
2122 static int clk_register(struct clk *clk)
2124 if (clk == NULL || IS_ERR(clk))
2128 * trap out already registered clocks
2130 if (clk->node.next || clk->node.prev)
2133 mutex_lock(&clocks_mutex);
2135 if (clk->get_parent)
2136 clk->parent = clk->get_parent(clk);
2137 else if (clk->parents)
2138 clk->parent = clksel_get_parent(clk);
2141 list_add(&clk->sibling, &clk->parent->children);
2143 list_add(&clk->sibling, &root_clks);
2145 list_add(&clk->node, &clocks);
2147 mutex_unlock(&clocks_mutex);
2152 static unsigned int __initdata armclk = 600 * MHZ;
2155 * You can override arm_clk rate with armclk= cmdline option.
2157 static int __init armclk_setup(char *str)
2159 get_option(&str, &armclk);
2167 clk_set_rate_nolock(&arm_pll_clk, armclk);
2170 early_param("armclk", armclk_setup);
2172 static void __init rk29_clock_common_init(void)
2175 clk_set_rate_nolock(&general_pll_clk, 288 * MHZ);
2176 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
2177 clk_set_rate_nolock(&aclk_periph, 144 * MHZ);
2178 clk_set_rate_nolock(&hclk_periph, 144 * MHZ);
2179 clk_set_rate_nolock(&pclk_periph, 36 * MHZ);
2180 clk_set_parent_nolock(&clk_uhost, &general_pll_clk);
2181 clk_set_rate_nolock(&clk_uhost, 48 * MHZ);
2182 clk_set_parent_nolock(&clk_i2s0_div, &general_pll_clk);
2183 clk_set_parent_nolock(&clk_i2s1_div, &general_pll_clk);
2184 clk_set_parent_nolock(&clk_spdif_div, &general_pll_clk);
2185 clk_set_parent_nolock(&clk_spi_src, &general_pll_clk);
2186 clk_set_parent_nolock(&clk_mmc_src, &general_pll_clk);
2187 clk_set_parent_nolock(&clk_uart01_src, &general_pll_clk);
2188 clk_set_parent_nolock(&clk_uart23_src, &general_pll_clk);
2189 clk_set_parent_nolock(&dclk_lcdc_div, &general_pll_clk);
2190 clk_set_parent_nolock(&aclk_lcdc, &general_pll_clk);
2191 clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
2192 clk_set_rate_nolock(&aclk_vepu, 288 * MHZ);
2193 clk_set_rate_nolock(&clk_aclk_ddr_vepu, 288 * MHZ);
2194 clk_set_rate_nolock(&hclk_vepu, 144 * MHZ);
2195 clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
2196 clk_set_parent_nolock(&aclk_gpu, &general_pll_clk);
2197 clk_set_rate_nolock(&aclk_gpu, 288 * MHZ);
2198 clk_set_parent_nolock(&clk_mac_ref_div, &general_pll_clk);
2199 clk_set_parent_nolock(&clk_hsadc_div, &general_pll_clk);
2202 clk_set_rate_nolock(&codec_pll_clk, 552 * MHZ);
2203 clk_set_parent_nolock(&clk_gpu, &codec_pll_clk);
2206 clk_set_rate_nolock(&arm_pll_clk, armclk);
2207 clk_set_parent_nolock(&clk_mac_ref_div, &arm_pll_clk);
2210 static void __init clk_enable_init_clocks(void)
2212 clk_enable_nolock(&hclk_cpu);
2213 clk_enable_nolock(&pclk_cpu);
2214 clk_enable_nolock(&hclk_periph);
2215 clk_enable_nolock(&pclk_periph);
2216 clk_enable_nolock(&clk_nandc);
2217 clk_enable_nolock(&clk_aclk_cpu_peri);
2218 clk_enable_nolock(&clk_aclk_ddr_peri);
2219 clk_enable_nolock(&clk_grf);
2220 clk_enable_nolock(&clk_pmu);
2221 clk_enable_nolock(&clk_ddr_cpu);
2222 clk_enable_nolock(&clk_ddr_reg);
2223 clk_enable_nolock(&clk_ddr_phy);
2224 clk_enable_nolock(&clk_gic);
2225 clk_enable_nolock(&clk_dma2);
2226 clk_enable_nolock(&clk_dma1);
2227 clk_enable_nolock(&clk_emem);
2228 clk_enable_nolock(&clk_intmem);
2229 clk_enable_nolock(&clk_ddr);
2230 clk_enable_nolock(&clk_debug);
2231 clk_enable_nolock(&clk_jtag);
2232 #ifdef CONFIG_DEBUG_LL
2233 clk_enable_nolock(&clk_uart1);
2237 static int __init clk_disable_unused(void)
2241 list_for_each_entry(ck, &clocks, node) {
2242 if (ck->usecount > 0 || ck->mode == NULL)
2246 clk_enable_nolock(ck);
2247 clk_disable_nolock(ck);
2251 pmu_set_power_domain(PD_VCODEC, false);
2252 // pmu_set_power_domain(PD_DISPLAY, false);
2253 pmu_set_power_domain(PD_GPU, false);
2258 void __init rk29_clock_init(void)
2260 struct clk_lookup *lk;
2262 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++)
2263 clk_preinit(lk->clk);
2265 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
2267 clk_register(lk->clk);
2270 clk_recalculate_root_clocks_nolock();
2273 * Only enable those clocks we will need, let the drivers
2274 * enable other clocks as necessary
2276 clk_enable_init_clocks();
2279 * Disable any unused clocks left on by the bootloader
2281 clk_disable_unused();
2283 rk29_clock_common_init();
2285 printk(KERN_INFO "Clocking rate (apll/dpll/cpll/gpll/core/aclk_cpu/hclk_cpu/pclk_cpu/aclk_periph/hclk_periph/pclk_periph): %ld/%ld/%ld/%ld/%ld/%ld/%ld/%ld/%ld/%ld/%ld MHz\n",
2286 arm_pll_clk.rate / MHZ, ddr_pll_clk.rate / MHZ, codec_pll_clk.rate / MHZ, general_pll_clk.rate / MHZ, clk_core.rate / MHZ,
2287 aclk_cpu.rate / MHZ, hclk_cpu.rate / MHZ, pclk_cpu.rate / MHZ, aclk_periph.rate / MHZ, hclk_periph.rate / MHZ, pclk_periph.rate / MHZ);
2290 #ifdef CONFIG_PROC_FS
2291 #include <linux/proc_fs.h>
2292 #include <linux/seq_file.h>
2294 static void dump_clock(struct seq_file *s, struct clk *clk, int deep)
2298 unsigned long rate = clk->rate;
2300 for (i = 0; i < deep; i++)
2303 seq_printf(s, "%-9s ", clk->name);
2305 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
2307 int idx = clk->gate_idx;
2310 reg = CRU_CLKGATE0_CON;
2311 reg += (idx >> 5) << 2;
2314 v = cru_readl(reg) & (1 << idx);
2316 seq_printf(s, "%s ", v ? "off" : "on ");
2319 if (clk == &arm_pll_clk) {
2320 switch (cru_readl(CRU_MODE_CON) & CRU_CPU_MODE_MASK) {
2321 case CRU_CPU_MODE_SLOW: seq_printf(s, "slow "); break;
2322 case CRU_CPU_MODE_NORMAL: seq_printf(s, "normal "); break;
2323 case CRU_CPU_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2325 if (cru_readl(CRU_APLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2326 } else if (clk == &ddr_pll_clk) {
2327 switch (cru_readl(CRU_MODE_CON) & CRU_DDR_MODE_MASK) {
2328 case CRU_DDR_MODE_SLOW: seq_printf(s, "slow "); break;
2329 case CRU_DDR_MODE_NORMAL: seq_printf(s, "normal "); break;
2330 case CRU_DDR_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2332 if (cru_readl(CRU_DPLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2333 } else if (clk == &codec_pll_clk) {
2334 switch (cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK) {
2335 case CRU_CODEC_MODE_SLOW: seq_printf(s, "slow "); break;
2336 case CRU_CODEC_MODE_NORMAL: seq_printf(s, "normal "); break;
2337 case CRU_CODEC_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2339 if (cru_readl(CRU_CPLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2340 } else if (clk == &general_pll_clk) {
2341 switch (cru_readl(CRU_MODE_CON) & CRU_GENERAL_MODE_MASK) {
2342 case CRU_GENERAL_MODE_SLOW: seq_printf(s, "slow "); break;
2343 case CRU_GENERAL_MODE_NORMAL: seq_printf(s, "normal "); break;
2344 case CRU_GENERAL_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2346 if (cru_readl(CRU_GPLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2351 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
2353 seq_printf(s, "%ld MHz", rate / MHZ);
2354 } else if (rate >= KHZ) {
2356 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
2358 seq_printf(s, "%ld KHz", rate / KHZ);
2360 seq_printf(s, "%ld Hz", rate);
2363 seq_printf(s, " usecount = %d", clk->usecount);
2365 seq_printf(s, " parent = %s\n", clk->parent ? clk->parent->name : "NULL");
2367 list_for_each_entry(ck, &clocks, node) {
2368 if (ck->parent == clk)
2369 dump_clock(s, ck, deep + 1);
2373 static int proc_clk_show(struct seq_file *s, void *v)
2377 mutex_lock(&clocks_mutex);
2378 list_for_each_entry(clk, &clocks, node) {
2380 dump_clock(s, clk, 0);
2382 mutex_unlock(&clocks_mutex);
2384 seq_printf(s, "\nCRU Registers:\n");
2385 seq_printf(s, "APLL : 0x%08x\n", cru_readl(CRU_APLL_CON));
2386 seq_printf(s, "DPLL : 0x%08x\n", cru_readl(CRU_DPLL_CON));
2387 seq_printf(s, "CPLL : 0x%08x\n", cru_readl(CRU_CPLL_CON));
2388 seq_printf(s, "GPLL : 0x%08x\n", cru_readl(CRU_GPLL_CON));
2389 seq_printf(s, "MODE : 0x%08x\n", cru_readl(CRU_MODE_CON));
2390 seq_printf(s, "CLKSEL0 : 0x%08x\n", cru_readl(CRU_CLKSEL0_CON));
2391 seq_printf(s, "CLKSEL1 : 0x%08x\n", cru_readl(CRU_CLKSEL1_CON));
2392 seq_printf(s, "CLKSEL2 : 0x%08x\n", cru_readl(CRU_CLKSEL2_CON));
2393 seq_printf(s, "CLKSEL3 : 0x%08x\n", cru_readl(CRU_CLKSEL3_CON));
2394 seq_printf(s, "CLKSEL4 : 0x%08x\n", cru_readl(CRU_CLKSEL4_CON));
2395 seq_printf(s, "CLKSEL5 : 0x%08x\n", cru_readl(CRU_CLKSEL5_CON));
2396 seq_printf(s, "CLKSEL6 : 0x%08x\n", cru_readl(CRU_CLKSEL6_CON));
2397 seq_printf(s, "CLKSEL7 : 0x%08x\n", cru_readl(CRU_CLKSEL7_CON));
2398 seq_printf(s, "CLKSEL8 : 0x%08x\n", cru_readl(CRU_CLKSEL8_CON));
2399 seq_printf(s, "CLKSEL9 : 0x%08x\n", cru_readl(CRU_CLKSEL9_CON));
2400 seq_printf(s, "CLKSEL10 : 0x%08x\n", cru_readl(CRU_CLKSEL10_CON));
2401 seq_printf(s, "CLKSEL11 : 0x%08x\n", cru_readl(CRU_CLKSEL11_CON));
2402 seq_printf(s, "CLKSEL12 : 0x%08x\n", cru_readl(CRU_CLKSEL12_CON));
2403 seq_printf(s, "CLKSEL13 : 0x%08x\n", cru_readl(CRU_CLKSEL13_CON));
2404 seq_printf(s, "CLKSEL14 : 0x%08x\n", cru_readl(CRU_CLKSEL14_CON));
2405 seq_printf(s, "CLKSEL15 : 0x%08x\n", cru_readl(CRU_CLKSEL15_CON));
2406 seq_printf(s, "CLKSEL16 : 0x%08x\n", cru_readl(CRU_CLKSEL16_CON));
2407 seq_printf(s, "CLKSEL17 : 0x%08x\n", cru_readl(CRU_CLKSEL17_CON));
2408 seq_printf(s, "CLKGATE0 : 0x%08x\n", cru_readl(CRU_CLKGATE0_CON));
2409 seq_printf(s, "CLKGATE1 : 0x%08x\n", cru_readl(CRU_CLKGATE1_CON));
2410 seq_printf(s, "CLKGATE2 : 0x%08x\n", cru_readl(CRU_CLKGATE2_CON));
2411 seq_printf(s, "CLKGATE3 : 0x%08x\n", cru_readl(CRU_CLKGATE3_CON));
2413 seq_printf(s, "\nPMU Registers:\n");
2414 seq_printf(s, "WAKEUP_EN0 : 0x%08x\n", pmu_readl(PMU_WAKEUP_EN0));
2415 seq_printf(s, "WAKEUP_EN1 : 0x%08x\n", pmu_readl(PMU_WAKEUP_EN1));
2416 seq_printf(s, "WAKEUP_EN2 : 0x%08x\n", pmu_readl(PMU_WAKEUP_EN2));
2417 seq_printf(s, "PD_CON : 0x%08x\n", pmu_readl(PMU_PD_CON));
2418 seq_printf(s, "MISC_CON : 0x%08x\n", pmu_readl(PMU_MISC_CON));
2419 seq_printf(s, "PLL_CNT : 0x%08x\n", pmu_readl(PMU_PLL_CNT));
2420 seq_printf(s, "PD_ST : 0x%08x\n", pmu_readl(PMU_PD_ST));
2421 seq_printf(s, "INT_ST : 0x%08x\n", pmu_readl(PMU_INT_ST));
2426 static int proc_clk_open(struct inode *inode, struct file *file)
2428 return single_open(file, proc_clk_show, NULL);
2431 static const struct file_operations proc_clk_fops = {
2432 .open = proc_clk_open,
2434 .llseek = seq_lseek,
2435 .release = single_release,
2438 static int __init clk_proc_init(void)
2440 proc_create("clocks", 0, NULL, &proc_clk_fops);
2444 late_initcall(clk_proc_init);
2445 #endif /* CONFIG_PROC_FS */