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>
34 #include <mach/sram.h>
39 #define RATE_FIXED (1 << 1) /* Fixed clock rate */
40 #define CONFIG_PARTICIPANT (1 << 10) /* Fundamental clock */
41 #define IS_PD (1 << 2) /* Power Domain */
43 #define regfile_readl(offset) readl(RK29_GRF_BASE + offset)
44 #define pmu_readl(offset) readl(RK29_PMU_BASE + offset)
46 #define MHZ (1000*1000)
50 struct list_head node;
53 struct list_head children;
54 struct list_head sibling; /* node for children */
57 int (*mode)(struct clk *clk, int on);
58 unsigned long (*recalc)(struct clk *); /* if null, follow parent */
59 int (*set_rate)(struct clk *, unsigned long);
60 long (*round_rate)(struct clk *, unsigned long);
61 struct clk* (*get_parent)(struct clk *); /* get clk's parent from the hardware. default is clksel_get_parent if parents present */
62 int (*set_parent)(struct clk *, struct clk *); /* default is clksel_set_parent if parents present */
70 u8 clksel_parent_mask;
71 u8 clksel_parent_shift;
75 static int clk_enable_nolock(struct clk *clk);
76 static void clk_disable_nolock(struct clk *clk);
77 static int clk_set_rate_nolock(struct clk *clk, unsigned long rate);
78 static int clk_set_parent_nolock(struct clk *clk, struct clk *parent);
79 static void __clk_reparent(struct clk *child, struct clk *parent);
80 static void __propagate_rate(struct clk *tclk);
81 static struct clk codec_pll_clk;
82 static struct clk general_pll_clk;
84 static unsigned long clksel_recalc_div(struct clk *clk)
86 u32 div = ((cru_readl(clk->clksel_con) >> clk->clksel_shift) & clk->clksel_mask) + 1;
87 unsigned long rate = clk->parent->rate / div;
88 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
92 static unsigned long clksel_recalc_shift(struct clk *clk)
94 u32 shift = (cru_readl(clk->clksel_con) >> clk->clksel_shift) & clk->clksel_mask;
95 unsigned long rate = clk->parent->rate >> shift;
96 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
100 static unsigned long clksel_recalc_frac(struct clk *clk)
104 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
105 if (r == 0) // FPGA ?
106 return clk->parent->rate;
108 denominator = r & 0xFFFF;
109 rate64 = (u64)clk->parent->rate * numerator;
110 do_div(rate64, denominator);
112 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
116 static int clksel_set_rate_div(struct clk *clk, unsigned long rate)
120 for (div = 0; div <= clk->clksel_mask; div++) {
121 u32 new_rate = clk->parent->rate / (div + 1);
122 if (new_rate <= rate) {
123 u32 v = cru_readl(clk->clksel_con);
124 v &= ~((u32) clk->clksel_mask << clk->clksel_shift);
125 v |= div << clk->clksel_shift;
126 cru_writel(v, clk->clksel_con);
127 clk->rate = new_rate;
128 pr_debug("clksel_set_rate_div for clock %s to rate %ld (div %d)\n", clk->name, rate, div + 1);
136 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
140 for (shift = 0; (1 << shift) <= clk->clksel_maxdiv; shift++) {
141 u32 new_rate = clk->parent->rate >> shift;
142 if (new_rate <= rate) {
143 u32 v = cru_readl(clk->clksel_con);
144 v &= ~((u32) clk->clksel_mask << clk->clksel_shift);
145 v |= shift << clk->clksel_shift;
146 cru_writel(v, clk->clksel_con);
147 clk->rate = new_rate;
148 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
156 static struct clk* clksel_get_parent(struct clk *clk)
158 return clk->parents[(cru_readl(clk->clksel_con) >> clk->clksel_parent_shift) & clk->clksel_parent_mask];
161 static int clksel_set_parent(struct clk *clk, struct clk *parent)
163 struct clk **p = clk->parents;
168 for (i = 0; (i <= clk->clksel_parent_mask) && *p; i++, p++) {
172 v = cru_readl(clk->clksel_con);
173 v &= ~((u32) clk->clksel_parent_mask << clk->clksel_parent_shift);
174 v |= (i << clk->clksel_parent_shift);
175 cru_writel(v, clk->clksel_con);
181 /* Work around CRU_CLKGATE3_CON bit21~20 bug */
182 volatile u32 cru_clkgate3_con_mirror;
184 static int gate_mode(struct clk *clk, int on)
187 int idx = clk->gate_idx;
190 if (idx >= CLK_GATE_MAX)
193 reg = CRU_CLKGATE0_CON;
194 reg += (idx >> 5) << 2;
197 if (reg == CRU_CLKGATE3_CON)
198 v = cru_clkgate3_con_mirror;
203 v &= ~(1 << idx); // clear bit
205 v |= (1 << idx); // set bit
207 if (reg == CRU_CLKGATE3_CON)
208 cru_clkgate3_con_mirror = v;
214 /* Work around CRU_SOFTRST0_CON bit29~27 bug */
215 static volatile u32 cru_softrst0_con_mirror;
217 void cru_set_soft_reset(enum cru_soft_reset idx, bool on)
220 u32 reg = CRU_SOFTRST0_CON + ((idx >> 5) << 2);
221 u32 mask = 1 << (idx & 31);
224 if (idx >= SOFT_RST_MAX)
227 local_irq_save(flags);
229 if (reg == CRU_SOFTRST0_CON)
230 v = cru_softrst0_con_mirror;
239 if (reg == CRU_SOFTRST0_CON)
240 cru_softrst0_con_mirror = v;
243 local_irq_restore(flags);
246 static struct clk xin24m = {
252 static struct clk clk_12m = {
259 static struct clk xin27m = {
265 static struct clk otgphy0_clkin = {
266 .name = "otgphy0_clkin",
271 static struct clk otgphy1_clkin = {
272 .name = "otgphy1_clkin",
278 static void delay_500ns(void)
285 static void delay_300us(void)
288 for (i = 0; i < 600; i++)
292 #define GENERAL_PLL_IDX 0
293 #define CODEC_PLL_IDX 1
294 #define ARM_PLL_IDX 2
295 #define DDR_PLL_IDX 3
297 #define GRF_SOC_CON0 0xbc
298 static void pll_wait_lock(int pll_idx)
300 u32 bit = 0x2000000u << pll_idx;
303 if (regfile_readl(GRF_SOC_CON0) & bit)
308 pr_warning("wait pll bit 0x%x time out!\n", bit);
312 static unsigned long arm_pll_clk_recalc(struct clk *clk)
316 if ((cru_readl(CRU_MODE_CON) & CRU_CPU_MODE_MASK) == CRU_CPU_MODE_NORMAL) {
317 u32 v = cru_readl(CRU_APLL_CON);
318 u64 rate64 = (u64) clk->parent->rate * PLL_NF2(v);
319 do_div(rate64, PLL_NR(v));
320 rate = rate64 >> PLL_NO_SHIFT(v);
321 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));
323 rate = clk->parent->rate;
324 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
336 #define CORE_ACLK_11 (0 << 5)
337 #define CORE_ACLK_21 (1 << 5)
338 #define CORE_ACLK_31 (2 << 5)
339 #define CORE_ACLK_41 (3 << 5)
340 #define CORE_ACLK_81 (4 << 5)
341 #define CORE_ACLK_MASK (7 << 5)
343 #define ACLK_HCLK_11 (0 << 8)
344 #define ACLK_HCLK_21 (1 << 8)
345 #define ACLK_HCLK_41 (2 << 8)
346 #define ACLK_HCLK_MASK (3 << 8)
348 #define ACLK_PCLK_11 (0 << 10)
349 #define ACLK_PCLK_21 (1 << 10)
350 #define ACLK_PCLK_41 (2 << 10)
351 #define ACLK_PCLK_81 (3 << 10)
352 #define ACLK_PCLK_MASK (3 << 10)
354 #define ARM_PLL(_mhz, nr, nf, no, _axi_div, _ahb_div, _apb_div) \
356 .rate = _mhz * MHZ, \
357 .apll_con = PLL_CLKR(nr) | PLL_CLKF(nf >> 1) | PLL_NO_##no, \
358 .clksel0_con = CORE_ACLK_##_axi_div | ACLK_HCLK_##_ahb_div | ACLK_PCLK_##_apb_div, \
361 static const struct arm_pll_set arm_pll[] = {
362 // rate = 24 * NF / (NR * NO)
363 // rate NR NF NO adiv hdiv pdiv
364 ARM_PLL(1200, 1, 50, 1, 41, 21, 81),
365 ARM_PLL(1104, 1, 46, 1, 41, 21, 81),
366 ARM_PLL(1008, 1, 42, 1, 41, 21, 81),
367 ARM_PLL( 912, 1, 38, 1, 31, 21, 81),
368 ARM_PLL( 888, 2, 74, 1, 31, 21, 81),
369 ARM_PLL( 816, 1, 34, 1, 31, 21, 81),
370 ARM_PLL( 696, 1, 58, 2, 31, 21, 81),
371 ARM_PLL( 624, 1, 52, 2, 31, 21, 81),
372 ARM_PLL( 600, 1, 50, 2, 21, 21, 81),
373 ARM_PLL( 504, 1, 42, 2, 21, 21, 81),
374 ARM_PLL( 408, 1, 34, 2, 21, 21, 81),
375 ARM_PLL( 300, 1, 50, 4, 21, 21, 41),
376 ARM_PLL( 204, 1, 34, 4, 21, 21, 41),
377 ARM_PLL( 102, 1, 34, 8, 21, 21, 41),
378 // last item, pll power down.
379 ARM_PLL( 24, 1, 64, 8, 21, 21, 41),
382 #define CORE_PARENT_MASK (3 << 23)
383 #define CORE_PARENT_ARM_PLL (0 << 23)
384 #define CORE_PARENT_GENERAL_PLL (1 << 23)
386 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
388 const struct arm_pll_set *ps, *pt;
390 /* find the arm_pll we want. */
391 ps = pt = &arm_pll[0];
393 if (pt->rate == rate) {
397 // we are sorted, and ps->rate > pt->rate.
398 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
400 if (pt->rate < rate || pt->rate == 24 * MHZ)
405 /* make aclk safe & reparent to general pll */
406 cru_writel((cru_readl(CRU_CLKSEL0_CON) & ~(CORE_PARENT_MASK | CORE_ACLK_MASK)) | CORE_PARENT_GENERAL_PLL | CORE_ACLK_21, CRU_CLKSEL0_CON);
408 /* enter slow mode */
409 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | CRU_CPU_MODE_SLOW, CRU_MODE_CON);
412 cru_writel(cru_readl(CRU_APLL_CON) | PLL_PD, CRU_APLL_CON);
416 cru_writel(ps->apll_con | PLL_PD, CRU_APLL_CON);
421 cru_writel(ps->apll_con, CRU_APLL_CON);
424 pll_wait_lock(ARM_PLL_IDX);
426 /* reparent to arm pll & set aclk/hclk/pclk */
427 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);
429 /* enter normal mode */
430 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | CRU_CPU_MODE_NORMAL, CRU_MODE_CON);
435 static struct clk *arm_pll_parents[2] = { &xin24m, &xin27m };
437 static struct clk arm_pll_clk = {
440 .recalc = arm_pll_clk_recalc,
441 .set_rate = arm_pll_clk_set_rate,
442 .clksel_con = CRU_MODE_CON,
443 .clksel_parent_mask = 1,
444 .clksel_parent_shift = 8,
445 .parents = arm_pll_parents,
448 static unsigned long ddr_pll_clk_recalc(struct clk *clk)
452 if ((cru_readl(CRU_MODE_CON) & CRU_DDR_MODE_MASK) == CRU_DDR_MODE_NORMAL) {
453 u32 v = cru_readl(CRU_DPLL_CON);
454 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
455 do_div(rate64, PLL_NR(v));
456 rate = rate64 >> PLL_NO_SHIFT(v);
457 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));
459 rate = clk->parent->rate;
460 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
466 static struct clk *ddr_pll_parents[4] = { &xin24m, &xin27m, &codec_pll_clk, &general_pll_clk };
468 static struct clk ddr_pll_clk = {
471 .recalc = ddr_pll_clk_recalc,
472 .clksel_con = CRU_MODE_CON,
473 .clksel_parent_mask = 3,
474 .clksel_parent_shift = 13,
475 .parents = ddr_pll_parents,
479 static int codec_pll_clk_mode(struct clk *clk, int on)
481 u32 cpll = cru_readl(CRU_CPLL_CON);
483 cru_writel(cpll & ~(PLL_PD | PLL_BYPASS), CRU_CPLL_CON);
485 pll_wait_lock(CODEC_PLL_IDX);
486 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | CRU_CODEC_MODE_NORMAL, CRU_MODE_CON);
488 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | CRU_CODEC_MODE_SLOW, CRU_MODE_CON);
489 cru_writel(cpll | PLL_BYPASS, CRU_CPLL_CON);
490 cru_writel(cpll | PLL_PD | PLL_BYPASS, CRU_CPLL_CON);
496 static unsigned long codec_pll_clk_recalc(struct clk *clk)
499 u32 v = cru_readl(CRU_CPLL_CON);
500 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
501 do_div(rate64, PLL_NR(v));
502 rate = rate64 >> PLL_NO_SHIFT(v);
503 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));
504 if ((cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK) != CRU_CODEC_MODE_NORMAL)
505 pr_debug("%s rate is %ld (slow mode) actually\n", clk->name, clk->parent->rate);
509 #define CODEC_PLL_PARENT_MASK (3 << 11)
510 #define CODEC_PLL_PARENT_XIN24M (0 << 11)
511 #define CODEC_PLL_PARENT_XIN27M (1 << 11)
512 #define CODEC_PLL_PARENT_DDR_PLL (2 << 11)
513 #define CODEC_PLL_PARENT_GENERAL_PLL (3 << 11)
515 struct codec_pll_set {
521 #define CODEC_PLL(_mhz, _parent, band, nr, nf, no) \
523 .rate = _mhz * MHZ, \
524 .pll_con = PLL_##band##_BAND | PLL_CLKR(nr) | PLL_CLKF(nf) | PLL_NO_##no, \
525 .parent_con = CODEC_PLL_PARENT_XIN##_parent##M, \
528 static const struct codec_pll_set codec_pll[] = {
529 // rate parent band NR NF NO
530 CODEC_PLL(108, 24, LOW, 1, 18, 4), // for TV
531 CODEC_PLL(648, 24, HIGH, 1, 27, 1),
532 CODEC_PLL(297, 27, LOW, 1, 22, 2), // for HDMI
533 CODEC_PLL(594, 27, LOW, 1, 22, 1),
534 CODEC_PLL(360, 24, LOW, 1, 15, 1), // for GPU
535 CODEC_PLL(408, 24, LOW, 1, 17, 1),
536 CODEC_PLL(456, 24, LOW, 1, 19, 1),
537 CODEC_PLL(504, 24, LOW, 1, 21, 1),
538 CODEC_PLL(552, 24, LOW, 1, 23, 1),
539 CODEC_PLL(600, 24, HIGH, 1, 25, 1),
542 static int codec_pll_clk_set_rate(struct clk *clk, unsigned long rate)
547 const struct codec_pll_set *ps = NULL;
549 for (i = 0; i < ARRAY_SIZE(codec_pll); i++) {
550 if (codec_pll[i].rate == rate) {
558 work_mode = cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK;
560 /* enter slow mode */
561 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);
564 cru_writel(cru_readl(CRU_CPLL_CON) | PLL_PD, CRU_CPLL_CON);
568 cru_writel(ps->pll_con | PLL_PD, CRU_CPLL_CON);
573 cru_writel(ps->pll_con, CRU_CPLL_CON);
576 pll_wait_lock(CODEC_PLL_IDX);
578 /* enter normal mode */
579 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | work_mode, CRU_MODE_CON);
581 clk_set_parent_nolock(clk, ps->parent_con == CODEC_PLL_PARENT_XIN24M ? &xin24m : &xin27m);
586 static struct clk *codec_pll_parents[4] = { &xin24m, &xin27m, &ddr_pll_clk, &general_pll_clk };
588 static struct clk codec_pll_clk = {
591 .mode = codec_pll_clk_mode,
592 .recalc = codec_pll_clk_recalc,
593 .set_rate = codec_pll_clk_set_rate,
594 .clksel_con = CRU_MODE_CON,
595 .clksel_parent_mask = 3,
596 .clksel_parent_shift = 11,
597 .parents = codec_pll_parents,
601 static unsigned long general_pll_clk_recalc(struct clk *clk)
605 if ((cru_readl(CRU_MODE_CON) & CRU_GENERAL_MODE_MASK) == CRU_GENERAL_MODE_NORMAL) {
606 u32 v = cru_readl(CRU_GPLL_CON);
607 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
608 do_div(rate64, PLL_NR(v));
609 rate = rate64 >> PLL_NO_SHIFT(v);
610 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));
612 rate = clk->parent->rate;
613 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
619 static int general_pll_clk_set_rate(struct clk *clk, unsigned long rate)
625 /* 96M: low-band, NR=1, NF=16, NO=4 */
626 pll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(16) | PLL_NO_4;
629 /* 96M: low-band, NR=1, NF=16, NO=4 */
630 pll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(24) | PLL_NO_4;
633 /* 288M: low-band, NR=1, NF=24, NO=2 */
634 pll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(24) | PLL_NO_2;
637 /* 300M: low-band, NR=1, NF=25, NO=2 */
638 pll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(25) | PLL_NO_2;
641 /* 624M: high-band, NR=1, NF=26, NO=1 */
642 pll_con = PLL_HIGH_BAND | PLL_CLKR(1) | PLL_CLKF(26) | PLL_NO_1;
649 /* enter slow mode */
650 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_GENERAL_MODE_MASK) | CRU_GENERAL_MODE_SLOW, CRU_MODE_CON);
653 cru_writel(cru_readl(CRU_GPLL_CON) | PLL_PD, CRU_GPLL_CON);
657 cru_writel(pll_con | PLL_PD, CRU_GPLL_CON);
662 cru_writel(pll_con, CRU_GPLL_CON);
665 pll_wait_lock(GENERAL_PLL_IDX);
667 /* enter normal mode */
668 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_GENERAL_MODE_MASK) | CRU_GENERAL_MODE_NORMAL, CRU_MODE_CON);
673 static struct clk *general_pll_parents[4] = { &xin24m, &xin27m, &ddr_pll_clk, &codec_pll_clk };
675 static struct clk general_pll_clk = {
676 .name = "general_pll",
678 .recalc = general_pll_clk_recalc,
679 .set_rate = general_pll_clk_set_rate,
680 .clksel_con = CRU_MODE_CON,
681 .clksel_parent_mask = 3,
682 .clksel_parent_shift = 9,
683 .parents = general_pll_parents,
687 static struct clk *clk_core_parents[4] = { &arm_pll_clk, &general_pll_clk, &codec_pll_clk, &ddr_pll_clk };
689 static struct clk clk_core = {
691 .parent = &arm_pll_clk,
692 .recalc = clksel_recalc_div,
693 .clksel_con = CRU_CLKSEL0_CON,
696 .clksel_parent_mask = 3,
697 .clksel_parent_shift = 23,
698 .parents = clk_core_parents,
701 static unsigned long aclk_cpu_recalc(struct clk *clk)
704 u32 div = ((cru_readl(CRU_CLKSEL0_CON) >> 5) & 0x7) + 1;
709 rate = clk->parent->rate / div;
710 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
715 static struct clk aclk_cpu = {
718 .recalc = aclk_cpu_recalc,
721 static struct clk hclk_cpu = {
724 .recalc = clksel_recalc_shift,
725 .set_rate = clksel_set_rate_shift,
726 .clksel_con = CRU_CLKSEL0_CON,
732 static struct clk pclk_cpu = {
735 .recalc = clksel_recalc_shift,
736 .set_rate = clksel_set_rate_shift,
737 .clksel_con = CRU_CLKSEL0_CON,
743 static struct clk *aclk_periph_parents[4] = { &general_pll_clk, &arm_pll_clk, &ddr_pll_clk, &codec_pll_clk };
745 static struct clk aclk_periph = {
746 .name = "aclk_periph",
748 .gate_idx = CLK_GATE_ACLK_PEIRPH,
749 .recalc = clksel_recalc_div,
750 .set_rate = clksel_set_rate_div,
751 .clksel_con = CRU_CLKSEL0_CON,
754 .clksel_parent_mask = 3,
755 .clksel_parent_shift = 12,
756 .parents = aclk_periph_parents,
759 static struct clk pclk_periph = {
760 .name = "pclk_periph",
762 .gate_idx = CLK_GATE_PCLK_PEIRPH,
763 .parent = &aclk_periph,
764 .recalc = clksel_recalc_shift,
765 .set_rate = clksel_set_rate_shift,
766 .clksel_con = CRU_CLKSEL0_CON,
772 static struct clk hclk_periph = {
773 .name = "hclk_periph",
775 .gate_idx = CLK_GATE_HCLK_PEIRPH,
776 .parent = &aclk_periph,
777 .recalc = clksel_recalc_shift,
778 .set_rate = clksel_set_rate_shift,
779 .clksel_con = CRU_CLKSEL0_CON,
786 static struct clk *clk_uhost_parents[8] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
788 static struct clk clk_uhost = {
791 .recalc = clksel_recalc_div,
792 .set_rate = clksel_set_rate_div,
793 .gate_idx = CLK_GATE_UHOST,
794 .clksel_con = CRU_CLKSEL1_CON,
797 .clksel_parent_mask = 7,
798 .clksel_parent_shift = 13,
799 .parents = clk_uhost_parents,
802 static struct clk *clk_otgphy_parents[4] = { &xin24m, &clk_12m, &clk_uhost };
804 static struct clk clk_otgphy0 = {
807 .gate_idx = CLK_GATE_USBPHY0,
808 .clksel_con = CRU_CLKSEL1_CON,
809 .clksel_parent_mask = 3,
810 .clksel_parent_shift = 9,
811 .parents = clk_otgphy_parents,
814 static struct clk clk_otgphy1 = {
817 .gate_idx = CLK_GATE_USBPHY1,
818 .clksel_con = CRU_CLKSEL1_CON,
819 .clksel_parent_mask = 3,
820 .clksel_parent_shift = 11,
821 .parents = clk_otgphy_parents,
825 static struct clk rmii_clkin = {
826 .name = "rmii_clkin",
829 static struct clk *clk_mac_ref_div_parents[4] = { &arm_pll_clk, &general_pll_clk, &codec_pll_clk, &ddr_pll_clk };
831 static struct clk clk_mac_ref_div = {
832 .name = "mac_ref_div",
833 .recalc = clksel_recalc_div,
834 .set_rate = clksel_set_rate_div,
835 .clksel_con = CRU_CLKSEL1_CON,
838 .clksel_parent_mask = 3,
839 .clksel_parent_shift = 21,
840 .parents = clk_mac_ref_div_parents,
843 static struct clk *clk_mac_ref_parents[2] = { &clk_mac_ref_div, &rmii_clkin };
845 static struct clk clk_mac_ref = {
848 .gate_idx = CLK_GATE_MAC_REF,
849 .clksel_con = CRU_CLKSEL1_CON,
850 .clksel_parent_mask = 1,
851 .clksel_parent_shift = 28,
852 .parents = clk_mac_ref_parents,
856 static struct clk *clk_i2s_div_parents[8] = { &codec_pll_clk, &general_pll_clk, &arm_pll_clk, &ddr_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
858 static struct clk clk_i2s0_div = {
860 .recalc = clksel_recalc_div,
861 .set_rate = clksel_set_rate_div,
862 .clksel_con = CRU_CLKSEL2_CON,
865 .clksel_parent_mask = 7,
866 .clksel_parent_shift = 0,
867 .parents = clk_i2s_div_parents,
870 static struct clk clk_i2s1_div = {
872 .recalc = clksel_recalc_div,
873 .set_rate = clksel_set_rate_div,
874 .clksel_con = CRU_CLKSEL2_CON,
877 .clksel_parent_mask = 7,
878 .clksel_parent_shift = 10,
879 .parents = clk_i2s_div_parents,
882 static struct clk clk_spdif_div = {
884 .recalc = clksel_recalc_div,
885 .set_rate = clksel_set_rate_div,
886 .clksel_con = CRU_CLKSEL2_CON,
889 .clksel_parent_mask = 7,
890 .clksel_parent_shift = 20,
891 .parents = clk_i2s_div_parents,
893 u32 clk_gcd(u32 numerator,u32 denominator)
898 if(!numerator||!denominator)
900 if(numerator > denominator){
915 static int clk_i2s_frac_div_set_rate(struct clk *clk, unsigned long rate)
917 u16 numerator, denominator;
919 gcd=clk_gcd(rate,clk->parent->rate);
920 pr_debug("%s i2s rate=%d,parent=%d,gcd=%d\n",__FUNCTION__,
921 rate,clk->parent->rate,gcd);
924 printk("gcd=0,i2s frac div is not be supported\n");
928 denominator=clk->parent->rate/gcd;
929 pr_debug("%s i2s numerator=%d,denominator=%d,times=%d\n",
930 __FUNCTION__,numerator,denominator,denominator/numerator);
931 if(numerator>0xffff||denominator>0xffff)
933 printk("i2s can't get a available nume and deno\n");
938 case 8192000: /* 288*32/1125 */
942 case 11289600: /* 288*49/1250 */
946 case 12288000: /* 288*16/375 */
954 pr_debug("set clock %s to rate %ld (%d/%d)\n", clk->name, rate, numerator, denominator);
955 cru_writel((u32)numerator << 16 | denominator, clk->clksel_con);
960 static struct clk clk_i2s0_frac_div = {
961 .name = "i2s0_frac_div",
962 .parent = &clk_i2s0_div,
963 .recalc = clksel_recalc_frac,
964 .set_rate = clk_i2s_frac_div_set_rate,
965 .clksel_con = CRU_CLKSEL3_CON,
968 static struct clk clk_i2s1_frac_div = {
969 .name = "i2s1_frac_div",
970 .parent = &clk_i2s1_div,
971 .recalc = clksel_recalc_frac,
972 .set_rate = clk_i2s_frac_div_set_rate,
973 .clksel_con = CRU_CLKSEL4_CON,
976 static struct clk clk_spdif_frac_div = {
977 .name = "spdif_frac_div",
978 .parent = &clk_spdif_div,
979 .recalc = clksel_recalc_frac,
980 .set_rate = clk_i2s_frac_div_set_rate,
981 .clksel_con = CRU_CLKSEL5_CON,
984 static int i2s_set_rate(struct clk *clk, unsigned long rate)
989 if (rate == 12 * MHZ) {
992 parent = clk->parents[1]; /* frac div */
993 ret = clk_set_rate_nolock(parent, rate);
997 if (clk->parent != parent)
998 clk_set_parent_nolock(clk, parent);
1003 static struct clk *clk_i2s0_parents[4] = { &clk_i2s0_div, &clk_i2s0_frac_div, &clk_12m, &xin24m };
1005 static struct clk clk_i2s0 = {
1008 .gate_idx = CLK_GATE_I2S0,
1009 .set_rate = i2s_set_rate,
1010 .clksel_con = CRU_CLKSEL2_CON,
1011 .clksel_parent_mask = 3,
1012 .clksel_parent_shift = 8,
1013 .parents = clk_i2s0_parents,
1016 static struct clk *clk_i2s1_parents[4] = { &clk_i2s1_div, &clk_i2s1_frac_div, &clk_12m, &xin24m };
1018 static struct clk clk_i2s1 = {
1021 .gate_idx = CLK_GATE_I2S1,
1022 .set_rate = i2s_set_rate,
1023 .clksel_con = CRU_CLKSEL2_CON,
1024 .clksel_parent_mask = 3,
1025 .clksel_parent_shift = 18,
1026 .parents = clk_i2s1_parents,
1029 static struct clk *clk_spdif_parents[4] = { &clk_spdif_div, &clk_spdif_frac_div, &clk_12m, &xin24m };
1031 static struct clk clk_spdif = {
1034 .gate_idx = CLK_GATE_SPDIF,
1035 .set_rate = i2s_set_rate,
1036 .clksel_con = CRU_CLKSEL2_CON,
1037 .clksel_parent_mask = 3,
1038 .clksel_parent_shift = 28,
1039 .parents = clk_spdif_parents,
1043 static struct clk *clk_spi_src_parents[4] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk };
1045 static struct clk clk_spi_src = {
1047 .clksel_con = CRU_CLKSEL6_CON,
1048 .clksel_parent_mask = 3,
1049 .clksel_parent_shift = 0,
1050 .parents = clk_spi_src_parents,
1053 static struct clk clk_spi0 = {
1055 .parent = &clk_spi_src,
1057 .recalc = clksel_recalc_div,
1058 .set_rate = clksel_set_rate_div,
1059 .gate_idx = CLK_GATE_SPI0,
1060 .clksel_con = CRU_CLKSEL6_CON,
1061 .clksel_mask = 0x7F,
1065 static struct clk clk_spi1 = {
1067 .parent = &clk_spi_src,
1069 .recalc = clksel_recalc_div,
1070 .set_rate = clksel_set_rate_div,
1071 .gate_idx = CLK_GATE_SPI1,
1072 .clksel_con = CRU_CLKSEL6_CON,
1073 .clksel_mask = 0x7F,
1078 static struct clk clk_saradc = {
1080 .parent = &pclk_periph,
1082 .recalc = clksel_recalc_div,
1083 .set_rate = clksel_set_rate_div,
1084 .gate_idx = CLK_GATE_SARADC,
1085 .clksel_con = CRU_CLKSEL6_CON,
1086 .clksel_mask = 0xFF,
1091 static struct clk *clk_cpu_timer_parents[2] = { &pclk_cpu, &xin24m };
1093 static struct clk clk_timer0 = {
1096 .gate_idx = CLK_GATE_TIMER0,
1097 .clksel_con = CRU_CLKSEL6_CON,
1098 .clksel_parent_mask = 1,
1099 .clksel_parent_shift = 26,
1100 .parents = clk_cpu_timer_parents,
1103 static struct clk clk_timer1 = {
1106 .gate_idx = CLK_GATE_TIMER1,
1107 .clksel_con = CRU_CLKSEL6_CON,
1108 .clksel_parent_mask = 1,
1109 .clksel_parent_shift = 27,
1110 .parents = clk_cpu_timer_parents,
1113 static struct clk *clk_periph_timer_parents[2] = { &pclk_periph, &xin24m };
1115 static struct clk clk_timer2 = {
1118 .gate_idx = CLK_GATE_TIMER2,
1119 .clksel_con = CRU_CLKSEL6_CON,
1120 .clksel_parent_mask = 1,
1121 .clksel_parent_shift = 28,
1122 .parents = clk_periph_timer_parents,
1125 static struct clk clk_timer3 = {
1128 .gate_idx = CLK_GATE_TIMER3,
1129 .clksel_con = CRU_CLKSEL6_CON,
1130 .clksel_parent_mask = 1,
1131 .clksel_parent_shift = 29,
1132 .parents = clk_periph_timer_parents,
1136 static struct clk *clk_mmc_src_parents[4] = { &arm_pll_clk, &general_pll_clk, &codec_pll_clk, &ddr_pll_clk };
1138 static struct clk clk_mmc_src = {
1140 .clksel_con = CRU_CLKSEL7_CON,
1141 .clksel_parent_mask = 3,
1142 .clksel_parent_shift = 0,
1143 .parents = clk_mmc_src_parents,
1146 static struct clk clk_mmc0 = {
1148 .parent = &clk_mmc_src,
1150 .recalc = clksel_recalc_div,
1151 .set_rate = clksel_set_rate_div,
1152 .gate_idx = CLK_GATE_MMC0,
1153 .clksel_con = CRU_CLKSEL7_CON,
1154 .clksel_mask = 0x3F,
1158 static struct clk clk_mmc1 = {
1160 .parent = &clk_mmc_src,
1162 .recalc = clksel_recalc_div,
1163 .set_rate = clksel_set_rate_div,
1164 .gate_idx = CLK_GATE_MMC1,
1165 .clksel_con = CRU_CLKSEL7_CON,
1166 .clksel_mask = 0x3F,
1170 static struct clk clk_emmc = {
1172 .parent = &clk_mmc_src,
1174 .recalc = clksel_recalc_div,
1175 .set_rate = clksel_set_rate_div,
1176 .gate_idx = CLK_GATE_EMMC,
1177 .clksel_con = CRU_CLKSEL7_CON,
1178 .clksel_mask = 0x3F,
1183 static struct clk *clk_ddr_parents[8] = { &ddr_pll_clk, &general_pll_clk, &codec_pll_clk, &arm_pll_clk };
1185 static struct clk clk_ddr = {
1187 .recalc = clksel_recalc_shift,
1188 .clksel_con = CRU_CLKSEL7_CON,
1191 .clksel_maxdiv = 32,
1192 .clksel_parent_mask = 3,
1193 .clksel_parent_shift = 24,
1194 .parents = clk_ddr_parents,
1198 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
1202 struct clk *clk_div = clk->parents[0];
1205 case 24*MHZ: /* 1.5M/0.5M/50/75/150/200/300/600/1200/2400 */
1206 parent = clk->parents[2]; /* xin24m */
1215 parent = clk->parents[1]; /* frac div */
1216 /* reset div to 1 */
1217 ret = clk_set_rate_nolock(clk_div, clk_div->parent->rate);
1226 if (parent->set_rate) {
1227 ret = clk_set_rate_nolock(parent, rate);
1232 if (clk->parent != parent)
1233 clk_set_parent_nolock(clk, parent);
1238 static int clk_uart_frac_div_set_rate(struct clk *clk, unsigned long rate)
1240 u16 numerator, denominator;
1242 gcd=clk_gcd(rate,clk->parent->rate);
1243 pr_debug("%s uart rate=%d,parent=%d,gcd=%d\n",__FUNCTION__,rate,clk->parent->rate,gcd);
1246 printk("gcd=0,uart frac div is not be supported\n");
1250 denominator=clk->parent->rate/gcd;
1251 pr_debug("%s uart numerator=%d,denominator=%d,times=%d\n",__FUNCTION__,
1252 numerator,denominator,denominator/numerator);
1253 if(numerator>0xffff||denominator>0xffff)
1255 printk("uart_frac can't get a available nume and deno\n");
1260 case 19200*16: /* 288*2/1875 */
1264 case 38400*16: /* 288*4/1875 */
1268 case 57600*16: /* 288*2/625 */
1272 case 115200*16: /* 288*8/1250 */
1276 case 230400*16: /* 288*8/625 */
1280 case 460800*16: /* 288*16/25 */
1284 case 576000*16: /* 288*20/625 */
1292 pr_debug("set clock %s to rate %ld (%d/%d)\n", clk->name, rate, numerator, denominator);
1293 cru_writel((u32)numerator << 16 | denominator, clk->clksel_con);
1297 static struct clk *clk_uart_src_parents[8] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
1299 static struct clk clk_uart01_src = {
1300 .name = "uart01_src",
1301 .clksel_con = CRU_CLKSEL8_CON,
1302 .clksel_parent_mask = 7,
1303 .clksel_parent_shift = 0,
1304 .parents = clk_uart_src_parents,
1307 static struct clk clk_uart0_div = {
1308 .name = "uart0_div",
1309 .parent = &clk_uart01_src,
1310 .recalc = clksel_recalc_div,
1311 .set_rate = clksel_set_rate_div,
1312 .clksel_con = CRU_CLKSEL8_CON,
1313 .clksel_mask = 0x3F,
1317 static struct clk clk_uart0_frac_div = {
1318 .name = "uart0_frac_div",
1319 .parent = &clk_uart0_div,
1320 .recalc = clksel_recalc_frac,
1321 .set_rate = clk_uart_frac_div_set_rate,
1322 .clksel_con = CRU_CLKSEL10_CON,
1325 static struct clk *clk_uart0_parents[4] = { &clk_uart0_div, &clk_uart0_frac_div, &xin24m };
1327 static struct clk clk_uart0 = {
1330 .set_rate = clk_uart_set_rate,
1331 .gate_idx = CLK_GATE_UART0,
1332 .clksel_con = CRU_CLKSEL8_CON,
1333 .clksel_parent_mask = 3,
1334 .clksel_parent_shift = 9,
1335 .parents = clk_uart0_parents,
1338 static struct clk clk_uart1_div = {
1339 .name = "uart1_div",
1340 .parent = &clk_uart01_src,
1341 .recalc = clksel_recalc_div,
1342 .set_rate = clksel_set_rate_div,
1343 .clksel_con = CRU_CLKSEL8_CON,
1344 .clksel_mask = 0x3F,
1348 static struct clk clk_uart1_frac_div = {
1349 .name = "uart1_frac_div",
1350 .parent = &clk_uart1_div,
1351 .recalc = clksel_recalc_frac,
1352 .set_rate = clk_uart_frac_div_set_rate,
1353 .clksel_con = CRU_CLKSEL11_CON,
1356 static struct clk *clk_uart1_parents[4] = { &clk_uart1_div, &clk_uart1_frac_div, &xin24m };
1358 static struct clk clk_uart1 = {
1361 .set_rate = clk_uart_set_rate,
1362 .gate_idx = CLK_GATE_UART1,
1363 .clksel_con = CRU_CLKSEL8_CON,
1364 .clksel_parent_mask = 3,
1365 .clksel_parent_shift = 20,
1366 .parents = clk_uart1_parents,
1369 static struct clk clk_uart23_src = {
1370 .name = "uart23_src",
1371 .clksel_con = CRU_CLKSEL9_CON,
1372 .clksel_parent_mask = 7,
1373 .clksel_parent_shift = 0,
1374 .parents = clk_uart_src_parents,
1377 static struct clk clk_uart2_div = {
1378 .name = "uart2_div",
1379 .parent = &clk_uart23_src,
1380 .recalc = clksel_recalc_div,
1381 .set_rate = clksel_set_rate_div,
1382 .clksel_con = CRU_CLKSEL9_CON,
1383 .clksel_mask = 0x3F,
1387 static struct clk clk_uart2_frac_div = {
1388 .name = "uart2_frac_div",
1389 .parent = &clk_uart2_div,
1390 .recalc = clksel_recalc_frac,
1391 .set_rate = clk_uart_frac_div_set_rate,
1392 .clksel_con = CRU_CLKSEL12_CON,
1395 static struct clk *clk_uart2_parents[4] = { &clk_uart2_div, &clk_uart2_frac_div, &xin24m };
1397 static struct clk clk_uart2 = {
1400 .set_rate = clk_uart_set_rate,
1401 .gate_idx = CLK_GATE_UART2,
1402 .clksel_con = CRU_CLKSEL9_CON,
1403 .clksel_parent_mask = 3,
1404 .clksel_parent_shift = 9,
1405 .parents = clk_uart2_parents,
1408 static struct clk clk_uart3_div = {
1409 .name = "uart3_div",
1410 .parent = &clk_uart23_src,
1411 .recalc = clksel_recalc_div,
1412 .set_rate = clksel_set_rate_div,
1413 .clksel_con = CRU_CLKSEL9_CON,
1414 .clksel_mask = 0x3F,
1418 static struct clk clk_uart3_frac_div = {
1419 .name = "uart3_frac_div",
1420 .parent = &clk_uart3_div,
1421 .recalc = clksel_recalc_frac,
1422 .set_rate = clk_uart_frac_div_set_rate,
1423 .clksel_con = CRU_CLKSEL13_CON,
1426 static struct clk *clk_uart3_parents[4] = { &clk_uart3_div, &clk_uart3_frac_div, &xin24m };
1428 static struct clk clk_uart3 = {
1431 .set_rate = clk_uart_set_rate,
1432 .gate_idx = CLK_GATE_UART3,
1433 .clksel_con = CRU_CLKSEL9_CON,
1434 .clksel_parent_mask = 3,
1435 .clksel_parent_shift = 20,
1436 .parents = clk_uart3_parents,
1440 static struct clk *clk_hsadc_div_parents[8] = { &codec_pll_clk, &ddr_pll_clk, &general_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
1442 static struct clk clk_hsadc_div = {
1443 .name = "hsadc_div",
1444 .recalc = clksel_recalc_div,
1445 .set_rate = clksel_set_rate_div,
1446 .clksel_con = CRU_CLKSEL14_CON,
1447 .clksel_mask = 0xFF,
1449 .clksel_parent_mask = 7,
1450 .clksel_parent_shift = 7,
1451 .parents = clk_hsadc_div_parents,
1454 static struct clk clk_hsadc_frac_div = {
1455 .name = "hsadc_frac_div",
1456 .parent = &clk_hsadc_div,
1457 .recalc = clksel_recalc_frac,
1458 .clksel_con = CRU_CLKSEL15_CON,
1461 static struct clk *clk_demod_parents[4] = { &clk_hsadc_div, &clk_hsadc_frac_div, &xin27m };
1463 static struct clk clk_demod = {
1465 .clksel_con = CRU_CLKSEL14_CON,
1466 .clksel_parent_mask = 3,
1467 .clksel_parent_shift = 18,
1468 .parents = clk_demod_parents,
1471 static struct clk gpsclk = {
1475 static struct clk *clk_hsadc_parents[2] = { &clk_demod, &gpsclk };
1477 static struct clk clk_hsadc = {
1480 .gate_idx = CLK_GATE_HSADC,
1481 .clksel_con = CRU_CLKSEL14_CON,
1482 .clksel_parent_mask = 1,
1483 .clksel_parent_shift = 21,
1484 .parents = clk_hsadc_parents,
1487 static unsigned long div2_recalc(struct clk *clk)
1489 return clk->parent->rate >> 1;
1492 static struct clk clk_hsadc_div2 = {
1493 .name = "hsadc_div2",
1494 .parent = &clk_demod,
1495 .recalc = div2_recalc,
1498 static struct clk clk_hsadc_div2_inv = {
1499 .name = "hsadc_div2_inv",
1500 .parent = &clk_demod,
1501 .recalc = div2_recalc,
1504 static struct clk *clk_hsadc_out_parents[2] = { &clk_hsadc_div2, &clk_hsadc_div2_inv };
1506 static struct clk clk_hsadc_out = {
1507 .name = "hsadc_out",
1508 .clksel_con = CRU_CLKSEL14_CON,
1509 .clksel_parent_mask = 1,
1510 .clksel_parent_shift = 20,
1511 .parents = clk_hsadc_out_parents,
1515 static struct clk *dclk_lcdc_div_parents[4] = { &codec_pll_clk, &ddr_pll_clk, &general_pll_clk, &arm_pll_clk };
1517 static struct clk dclk_lcdc_div = {
1518 .name = "dclk_lcdc_div",
1519 .recalc = clksel_recalc_div,
1520 .set_rate = clksel_set_rate_div,
1521 .clksel_con = CRU_CLKSEL16_CON,
1522 .clksel_mask = 0xFF,
1524 .clksel_parent_mask = 3,
1525 .clksel_parent_shift = 0,
1526 .parents = dclk_lcdc_div_parents,
1529 static struct clk *dclk_lcdc_parents[2] = { &dclk_lcdc_div, &xin27m };
1531 static struct clk dclk_lcdc = {
1532 .name = "dclk_lcdc",
1534 .gate_idx = CLK_GATE_DCLK_LCDC,
1535 .clksel_con = CRU_CLKSEL16_CON,
1536 .clksel_parent_mask = 1,
1537 .clksel_parent_shift = 10,
1538 .parents = dclk_lcdc_parents,
1541 static struct clk dclk_ebook = {
1542 .name = "dclk_ebook",
1544 .gate_idx = CLK_GATE_DCLK_EBOOK,
1545 .recalc = clksel_recalc_div,
1546 .set_rate = clksel_set_rate_div,
1547 .clksel_con = CRU_CLKSEL16_CON,
1548 .clksel_mask = 0x1F,
1550 .clksel_parent_mask = 3,
1551 .clksel_parent_shift = 11,
1552 .parents = dclk_lcdc_div_parents,
1555 static struct clk *aclk_lcdc_parents[4] = { &ddr_pll_clk, &codec_pll_clk, &general_pll_clk, &arm_pll_clk };
1557 static struct clk aclk_lcdc = {
1558 .name = "aclk_lcdc",
1560 .gate_idx = CLK_GATE_ACLK_LCDC,
1561 .recalc = clksel_recalc_div,
1562 .set_rate = clksel_set_rate_div,
1563 .clksel_con = CRU_CLKSEL16_CON,
1564 .clksel_mask = 0x1F,
1566 .clksel_parent_mask = 3,
1567 .clksel_parent_shift = 18,
1568 .parents = aclk_lcdc_parents,
1571 static struct clk hclk_lcdc = {
1572 .name = "hclk_lcdc",
1574 .gate_idx = CLK_GATE_HCLK_LCDC,
1575 .parent = &aclk_lcdc,
1576 .clksel_con = CRU_CLKSEL16_CON,
1577 .recalc = clksel_recalc_shift,
1578 .set_rate = clksel_set_rate_shift,
1584 static struct clk *xpu_parents[4] = { &general_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk };
1586 static struct clk aclk_vepu = {
1587 .name = "aclk_vepu",
1589 .recalc = clksel_recalc_div,
1590 .set_rate = clksel_set_rate_div,
1591 .gate_idx = CLK_GATE_ACLK_VEPU,
1592 .clksel_con = CRU_CLKSEL17_CON,
1593 .clksel_mask = 0x1F,
1595 .clksel_parent_mask = 3,
1596 .clksel_parent_shift = 0,
1597 .parents = xpu_parents,
1600 static struct clk hclk_vepu = {
1601 .name = "hclk_vepu",
1602 .parent = &aclk_vepu,
1604 .recalc = clksel_recalc_shift,
1605 .set_rate = clksel_set_rate_shift,
1606 .gate_idx = CLK_GATE_HCLK_VEPU,
1607 .clksel_con = CRU_CLKSEL17_CON,
1613 static struct clk aclk_vdpu = {
1614 .name = "aclk_vdpu",
1615 .parent = &general_pll_clk,
1617 .recalc = clksel_recalc_div,
1618 .set_rate = clksel_set_rate_div,
1619 .gate_idx = CLK_GATE_ACLK_VDPU,
1620 .clksel_con = CRU_CLKSEL17_CON,
1621 .clksel_mask = 0x1F,
1623 .clksel_parent_mask = 3,
1624 .clksel_parent_shift = 7,
1625 .parents = xpu_parents,
1628 static struct clk hclk_vdpu = {
1629 .name = "hclk_vdpu",
1630 .parent = &aclk_vdpu,
1632 .recalc = clksel_recalc_shift,
1633 .set_rate = clksel_set_rate_shift,
1634 .gate_idx = CLK_GATE_HCLK_VDPU,
1635 .clksel_con = CRU_CLKSEL17_CON,
1641 static struct clk clk_gpu = {
1644 .gate_idx = CLK_GATE_GPU,
1645 .recalc = clksel_recalc_div,
1646 .set_rate = clksel_set_rate_div,
1647 .clksel_con = CRU_CLKSEL17_CON,
1648 .clksel_mask = 0x1F,
1650 .clksel_parent_mask = 3,
1651 .clksel_parent_shift = 14,
1652 .parents = xpu_parents,
1655 static struct clk aclk_gpu = {
1658 .gate_idx = CLK_GATE_ACLK_GPU,
1659 .recalc = clksel_recalc_div,
1660 .set_rate = clksel_set_rate_div,
1661 .clksel_con = CRU_CLKSEL17_CON,
1662 .clksel_mask = 0x1F,
1664 .clksel_parent_mask = 3,
1665 .clksel_parent_shift = 21,
1666 .parents = xpu_parents,
1670 static struct clk vip_clkin = {
1671 .name = "vip_clkin",
1674 static struct clk *clk_vip_parents[4] = { &xin24m, &xin27m, &dclk_ebook };
1676 static struct clk clk_vip_out = {
1679 .gate_idx = CLK_GATE_VIP_OUT,
1680 .clksel_con = CRU_CLKSEL1_CON,
1681 .clksel_parent_mask = 3,
1682 .clksel_parent_shift = 7,
1683 .parents = clk_vip_parents,
1687 #define GATE_CLK(NAME,PARENT,ID) \
1688 static struct clk clk_##NAME = { \
1690 .parent = &PARENT, \
1691 .mode = gate_mode, \
1692 .gate_idx = CLK_GATE_##ID, \
1695 GATE_CLK(i2c0, pclk_cpu, I2C0);
1696 GATE_CLK(i2c1, pclk_periph, I2C1);
1697 GATE_CLK(i2c2, pclk_periph, I2C2);
1698 GATE_CLK(i2c3, pclk_periph, I2C3);
1700 GATE_CLK(gpio0, pclk_cpu, GPIO0);
1701 GATE_CLK(gpio1, pclk_periph, GPIO1);
1702 GATE_CLK(gpio2, pclk_periph, GPIO2);
1703 GATE_CLK(gpio3, pclk_periph, GPIO3);
1704 GATE_CLK(gpio4, pclk_cpu, GPIO4);
1705 GATE_CLK(gpio5, pclk_periph, GPIO5);
1706 GATE_CLK(gpio6, pclk_cpu, GPIO6);
1708 GATE_CLK(dma1, aclk_cpu, DMA1);
1709 GATE_CLK(dma2, aclk_periph, DMA2);
1711 GATE_CLK(gic, aclk_cpu, GIC);
1712 GATE_CLK(intmem, aclk_cpu, INTMEM);
1713 GATE_CLK(rom, hclk_cpu, ROM);
1714 GATE_CLK(ddr_phy, aclk_cpu, DDR_PHY);
1715 GATE_CLK(ddr_reg, aclk_cpu, DDR_REG);
1716 GATE_CLK(ddr_cpu, aclk_cpu, DDR_CPU);
1717 GATE_CLK(efuse, pclk_cpu, EFUSE);
1718 GATE_CLK(tzpc, pclk_cpu, TZPC);
1719 GATE_CLK(debug, pclk_cpu, DEBUG);
1720 GATE_CLK(tpiu, pclk_cpu, TPIU);
1721 GATE_CLK(rtc, pclk_cpu, RTC);
1722 GATE_CLK(pmu, pclk_cpu, PMU);
1723 GATE_CLK(grf, pclk_cpu, GRF);
1725 GATE_CLK(emem, hclk_periph, EMEM);
1726 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
1727 GATE_CLK(aclk_ddr_peri, aclk_periph, ACLK_DDR_PERI);
1728 GATE_CLK(aclk_cpu_peri, aclk_cpu, ACLK_CPU_PERI);
1729 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
1730 GATE_CLK(smc, pclk_periph, SMC);
1731 GATE_CLK(hclk_mac, hclk_periph, HCLK_MAC);
1732 GATE_CLK(mii_tx, hclk_periph, MII_TX);
1733 GATE_CLK(mii_rx, hclk_periph, MII_RX);
1734 GATE_CLK(hif, hclk_periph, HIF);
1735 GATE_CLK(nandc, hclk_periph, NANDC);
1736 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
1737 GATE_CLK(usbotg0, hclk_periph, USBOTG0);
1738 GATE_CLK(usbotg1, hclk_periph, USBOTG1);
1739 GATE_CLK(hclk_uhost, hclk_periph, HCLK_UHOST);
1740 GATE_CLK(pid_filter, hclk_periph, PID_FILTER);
1742 GATE_CLK(vip_slave, hclk_lcdc, VIP_SLAVE);
1743 GATE_CLK(wdt, pclk_periph, WDT);
1744 GATE_CLK(pwm, pclk_periph, PWM);
1745 GATE_CLK(vip_bus, aclk_cpu, VIP_BUS);
1746 GATE_CLK(vip_matrix, clk_vip_bus, VIP_MATRIX);
1747 GATE_CLK(vip_input, vip_clkin, VIP_INPUT);
1748 GATE_CLK(jtag, aclk_cpu, JTAG);
1750 GATE_CLK(aclk_ddr_lcdc, aclk_lcdc, ACLK_DDR_LCDC);
1751 GATE_CLK(aclk_ipp, aclk_lcdc, ACLK_IPP);
1752 GATE_CLK(hclk_ipp, hclk_lcdc, HCLK_IPP);
1753 GATE_CLK(hclk_ebook, hclk_lcdc, HCLK_EBOOK);
1754 GATE_CLK(aclk_disp_matrix, aclk_lcdc, ACLK_DISP_MATRIX);
1755 GATE_CLK(hclk_disp_matrix, hclk_lcdc, HCLK_DISP_MATRIX);
1756 GATE_CLK(aclk_ddr_vepu, aclk_vepu, ACLK_DDR_VEPU);
1757 GATE_CLK(aclk_ddr_vdpu, aclk_vdpu, ACLK_DDR_VDPU);
1758 GATE_CLK(aclk_ddr_gpu, aclk_gpu, ACLK_DDR_GPU);
1759 GATE_CLK(hclk_gpu, hclk_cpu, HCLK_GPU);
1760 GATE_CLK(hclk_cpu_vcodec, hclk_cpu, HCLK_CPU_VCODEC);
1761 GATE_CLK(hclk_cpu_display, hclk_cpu, HCLK_CPU_DISPLAY);
1763 GATE_CLK(hclk_mmc0, hclk_periph, HCLK_MMC0);
1764 GATE_CLK(hclk_mmc1, hclk_periph, HCLK_MMC1);
1765 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
1768 static void __sramfunc pmu_set_power_domain_sram(enum pmu_power_domain pd, bool on)
1771 writel(readl(RK29_PMU_BASE + PMU_PD_CON) & ~(1 << pd), RK29_PMU_BASE + PMU_PD_CON);
1773 writel(readl(RK29_PMU_BASE + PMU_PD_CON) | (1 << pd), RK29_PMU_BASE + PMU_PD_CON);
1776 while (pmu_power_domain_is_on(pd) != on)
1780 static noinline void do_pmu_set_power_domain(enum pmu_power_domain pd, bool on)
1782 static unsigned long save_sp;
1784 DDR_SAVE_SP(save_sp);
1785 pmu_set_power_domain_sram(pd, on);
1786 DDR_RESTORE_SP(save_sp);
1789 void pmu_set_power_domain(enum pmu_power_domain pd, bool on)
1791 unsigned long flags;
1794 local_irq_save(flags);
1795 do_pmu_set_power_domain(pd, on);
1796 local_irq_restore(flags);
1800 static int pd_vcodec_mode(struct clk *clk, int on)
1805 gate = cru_clkgate3_con_mirror;
1806 gate |= (1 << CLK_GATE_ACLK_DDR_VEPU % 32);
1807 gate &= ~((1 << CLK_GATE_ACLK_VEPU % 32)
1808 | (1 << CLK_GATE_HCLK_VEPU % 32)
1809 | (1 << CLK_GATE_HCLK_CPU_VCODEC % 32));
1810 cru_writel(gate, CRU_CLKGATE3_CON);
1812 pmu_set_power_domain(PD_VCODEC, true);
1814 cru_writel(cru_clkgate3_con_mirror, CRU_CLKGATE3_CON);
1816 pmu_set_power_domain(PD_VCODEC, false);
1822 static struct clk pd_vcodec = {
1823 .name = "pd_vcodec",
1825 .mode = pd_vcodec_mode,
1828 static int pd_display_mode(struct clk *clk, int on)
1833 gate = cru_clkgate3_con_mirror;
1834 gate |= (1 << CLK_GATE_ACLK_DDR_LCDC % 32);
1835 gate &= ~((1 << CLK_GATE_HCLK_CPU_DISPLAY % 32)
1836 | (1 << CLK_GATE_HCLK_DISP_MATRIX % 32)
1837 | (1 << CLK_GATE_ACLK_DISP_MATRIX % 32)
1838 | (1 << CLK_GATE_DCLK_EBOOK % 32)
1839 | (1 << CLK_GATE_HCLK_EBOOK % 32)
1840 | (1 << CLK_GATE_HCLK_IPP % 32)
1841 | (1 << CLK_GATE_ACLK_IPP % 32)
1842 | (1 << CLK_GATE_DCLK_LCDC % 32)
1843 | (1 << CLK_GATE_HCLK_LCDC % 32)
1844 | (1 << CLK_GATE_ACLK_LCDC % 32));
1845 cru_writel(gate, CRU_CLKGATE3_CON);
1847 gate2 = cru_readl(CRU_CLKGATE2_CON);
1849 gate &= ~((1 << CLK_GATE_VIP_OUT % 32)
1850 | (1 << CLK_GATE_VIP_SLAVE % 32)
1851 | (1 << CLK_GATE_VIP_MATRIX % 32)
1852 | (1 << CLK_GATE_VIP_BUS % 32));
1853 cru_writel(gate, CRU_CLKGATE2_CON);
1855 pmu_set_power_domain(PD_DISPLAY, true);
1857 cru_writel(gate2, CRU_CLKGATE2_CON);
1858 cru_writel(cru_clkgate3_con_mirror, CRU_CLKGATE3_CON);
1860 pmu_set_power_domain(PD_DISPLAY, false);
1866 static struct clk pd_display = {
1867 .name = "pd_display",
1869 .mode = pd_display_mode,
1872 static int pd_gpu_mode(struct clk *clk, int on)
1875 pmu_set_power_domain(PD_GPU, true);
1877 pmu_set_power_domain(PD_GPU, false);
1883 static struct clk pd_gpu = {
1886 .mode = pd_gpu_mode,
1890 #define CLK(dev, con, ck) \
1897 #define CLK1(name) \
1901 .clk = &clk_##name, \
1904 static struct clk_lookup clks[] = {
1905 CLK(NULL, "xin24m", &xin24m),
1906 CLK(NULL, "xin27m", &xin27m),
1907 CLK(NULL, "otgphy0_clkin", &otgphy0_clkin),
1908 CLK(NULL, "otgphy1_clkin", &otgphy1_clkin),
1909 CLK(NULL, "gpsclk", &gpsclk),
1910 CLK(NULL, "vip_clkin", &vip_clkin),
1913 CLK(NULL, "arm_pll", &arm_pll_clk),
1914 CLK(NULL, "ddr_pll", &ddr_pll_clk),
1915 CLK(NULL, "codec_pll", &codec_pll_clk),
1916 CLK(NULL, "general_pll", &general_pll_clk),
1919 CLK(NULL, "aclk_cpu", &aclk_cpu),
1920 CLK(NULL, "hclk_cpu", &hclk_cpu),
1921 CLK(NULL, "pclk_cpu", &pclk_cpu),
1923 CLK(NULL, "aclk_periph", &aclk_periph),
1924 CLK(NULL, "hclk_periph", &hclk_periph),
1925 CLK(NULL, "pclk_periph", &pclk_periph),
1934 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
1935 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
1936 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
1937 CLK("rk29_i2s.1", "i2s_div", &clk_i2s1_div),
1938 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s1_frac_div),
1939 CLK("rk29_i2s.1", "i2s", &clk_i2s1),
1940 CLK(NULL, "spdif_div", &clk_spdif_div),
1941 CLK(NULL, "spdif_frac_div", &clk_spdif_frac_div),
1942 CLK(NULL, "spdif", &clk_spdif),
1945 CLK("rk29xx_spim.0", "spi", &clk_spi0),
1946 CLK("rk29xx_spim.1", "spi", &clk_spi1),
1955 CLK("rk29_sdmmc.0", "mmc", &clk_mmc0),
1956 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_mmc0),
1957 CLK("rk29_sdmmc.1", "mmc", &clk_mmc1),
1958 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_mmc1),
1964 CLK("rk29_serial.0", "uart", &clk_uart0),
1965 CLK("rk29_serial.0", "uart_div", &clk_uart0_div),
1966 CLK("rk29_serial.0", "uart_frac_div", &clk_uart0_frac_div),
1967 CLK("rk29_serial.1", "uart", &clk_uart1),
1968 CLK("rk29_serial.1", "uart_div", &clk_uart1_div),
1969 CLK("rk29_serial.1", "uart_frac_div", &clk_uart1_frac_div),
1972 CLK("rk29_serial.2", "uart", &clk_uart2),
1973 CLK("rk29_serial.2", "uart_div", &clk_uart2_div),
1974 CLK("rk29_serial.2", "uart_frac_div", &clk_uart2_frac_div),
1975 CLK("rk29_serial.3", "uart", &clk_uart3),
1976 CLK("rk29_serial.3", "uart_div", &clk_uart3_div),
1977 CLK("rk29_serial.3", "uart_frac_div", &clk_uart3_frac_div),
1980 CLK1(hsadc_frac_div),
1984 CLK1(hsadc_div2_inv),
1987 CLK(NULL, "dclk_lcdc_div", &dclk_lcdc_div),
1988 CLK(NULL, "dclk_lcdc", &dclk_lcdc),
1989 CLK(NULL, "dclk_ebook", &dclk_ebook),
1990 CLK(NULL, "aclk_lcdc", &aclk_lcdc),
1991 CLK(NULL, "hclk_lcdc", &hclk_lcdc),
1993 CLK(NULL, "aclk_vepu", &aclk_vepu),
1994 CLK(NULL, "hclk_vepu", &hclk_vepu),
1995 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
1996 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
1998 CLK(NULL, "aclk_gpu", &aclk_gpu),
2000 CLK("rk29_i2c.0", "i2c", &clk_i2c0),
2001 CLK("rk29_i2c.1", "i2c", &clk_i2c1),
2002 CLK("rk29_i2c.2", "i2c", &clk_i2c2),
2003 CLK("rk29_i2c.3", "i2c", &clk_i2c3),
2031 CLK1(hclk_usb_peri),
2032 CLK1(aclk_ddr_peri),
2033 CLK1(aclk_cpu_peri),
2055 CLK1(aclk_ddr_lcdc),
2059 CLK1(aclk_disp_matrix),
2060 CLK1(hclk_disp_matrix),
2061 CLK1(aclk_ddr_vepu),
2062 CLK1(aclk_ddr_vdpu),
2065 CLK1(hclk_cpu_vcodec),
2066 CLK1(hclk_cpu_display),
2068 CLK(NULL, "pd_vcodec", &pd_vcodec),
2069 CLK(NULL, "pd_display", &pd_display),
2070 CLK(NULL, "pd_gpu", &pd_gpu),
2073 static LIST_HEAD(clocks);
2074 static DEFINE_MUTEX(clocks_mutex);
2075 static DEFINE_SPINLOCK(clockfw_lock);
2076 #define LOCK() do { WARN_ON(in_irq()); if (!irqs_disabled()) spin_lock_bh(&clockfw_lock); } while (0)
2077 #define UNLOCK() do { if (!irqs_disabled()) spin_unlock_bh(&clockfw_lock); } while (0)
2079 static int clk_enable_nolock(struct clk *clk)
2083 if (clk->usecount == 0) {
2085 ret = clk_enable_nolock(clk->parent);
2091 ret = clk->mode(clk, 1);
2094 clk_disable_nolock(clk->parent);
2098 pr_debug("%s enabled\n", clk->name);
2105 int clk_enable(struct clk *clk)
2109 if (clk == NULL || IS_ERR(clk))
2113 ret = clk_enable_nolock(clk);
2118 EXPORT_SYMBOL(clk_enable);
2120 static void clk_disable_nolock(struct clk *clk)
2122 if (clk->usecount == 0) {
2123 printk(KERN_ERR "Trying disable clock %s with 0 usecount\n", clk->name);
2128 if (--clk->usecount == 0) {
2131 pr_debug("%s disabled\n", clk->name);
2133 clk_disable_nolock(clk->parent);
2137 void clk_disable(struct clk *clk)
2139 if (clk == NULL || IS_ERR(clk))
2143 clk_disable_nolock(clk);
2146 EXPORT_SYMBOL(clk_disable);
2148 unsigned long clk_get_rate(struct clk *clk)
2150 if (clk == NULL || IS_ERR(clk))
2155 EXPORT_SYMBOL(clk_get_rate);
2157 /*-------------------------------------------------------------------------
2158 * Optional clock functions defined in include/linux/clk.h
2159 *-------------------------------------------------------------------------*/
2161 /* Given a clock and a rate apply a clock specific rounding function */
2162 static long clk_round_rate_nolock(struct clk *clk, unsigned long rate)
2164 if (clk->round_rate)
2165 return clk->round_rate(clk, rate);
2167 if (clk->flags & RATE_FIXED)
2168 printk(KERN_ERR "clock: clk_round_rate called on fixed-rate clock %s\n", clk->name);
2173 long clk_round_rate(struct clk *clk, unsigned long rate)
2177 if (clk == NULL || IS_ERR(clk))
2181 ret = clk_round_rate_nolock(clk, rate);
2186 EXPORT_SYMBOL(clk_round_rate);
2188 static void __clk_recalc(struct clk *clk)
2190 if (unlikely(clk->flags & RATE_FIXED))
2193 clk->rate = clk->recalc(clk);
2194 else if (clk->parent)
2195 clk->rate = clk->parent->rate;
2196 pr_debug("%s new clock rate is %lu\n", clk->name, clk->rate);
2199 static int clk_set_rate_nolock(struct clk *clk, unsigned long rate)
2203 if (rate == clk->rate)
2206 pr_debug("set_rate for clock %s to rate %ld\n", clk->name, rate);
2208 if (clk->flags & CONFIG_PARTICIPANT)
2214 ret = clk->set_rate(clk, rate);
2218 __propagate_rate(clk);
2224 /* Set the clock rate for a clock source */
2225 int clk_set_rate(struct clk *clk, unsigned long rate)
2229 if (clk == NULL || IS_ERR(clk))
2233 ret = clk_set_rate_nolock(clk, rate);
2238 EXPORT_SYMBOL(clk_set_rate);
2240 static int clk_set_parent_nolock(struct clk *clk, struct clk *parent)
2243 int enabled = clk->usecount > 0;
2244 struct clk *old_parent = clk->parent;
2246 if (clk->parent == parent)
2249 /* if clk is already enabled, enable new parent first and disable old parent later. */
2251 clk_enable_nolock(parent);
2253 if (clk->set_parent)
2254 ret = clk->set_parent(clk, parent);
2256 ret = clksel_set_parent(clk, parent);
2260 __clk_reparent(clk, parent);
2262 __propagate_rate(clk);
2264 clk_disable_nolock(old_parent);
2267 clk_disable_nolock(parent);
2273 int clk_set_parent(struct clk *clk, struct clk *parent)
2277 if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent))
2280 if (clk->set_parent == NULL && clk->parents == NULL)
2284 if (clk->usecount == 0)
2285 ret = clk_set_parent_nolock(clk, parent);
2292 EXPORT_SYMBOL(clk_set_parent);
2294 struct clk *clk_get_parent(struct clk *clk)
2298 EXPORT_SYMBOL(clk_get_parent);
2300 static void __clk_reparent(struct clk *child, struct clk *parent)
2302 if (child->parent == parent)
2304 pr_debug("%s reparent to %s (was %s)\n", child->name, parent->name, ((child->parent) ? child->parent->name : "NULL"));
2306 list_del_init(&child->sibling);
2308 list_add(&child->sibling, &parent->children);
2309 child->parent = parent;
2312 /* Propagate rate to children */
2313 static void __propagate_rate(struct clk *tclk)
2317 list_for_each_entry(clkp, &tclk->children, sibling) {
2319 __propagate_rate(clkp);
2323 static LIST_HEAD(root_clks);
2326 * recalculate_root_clocks - recalculate and propagate all root clocks
2328 * Recalculates all root clocks (clocks with no parent), which if the
2329 * clock's .recalc is set correctly, should also propagate their rates.
2332 static void clk_recalculate_root_clocks_nolock(void)
2336 list_for_each_entry(clkp, &root_clks, sibling) {
2338 __propagate_rate(clkp);
2342 void clk_recalculate_root_clocks(void)
2345 clk_recalculate_root_clocks_nolock();
2351 * clk_preinit - initialize any fields in the struct clk before clk init
2352 * @clk: struct clk * to initialize
2354 * Initialize any struct clk fields needed before normal clk initialization
2355 * can run. No return value.
2357 static void clk_preinit(struct clk *clk)
2359 INIT_LIST_HEAD(&clk->children);
2362 static int clk_register(struct clk *clk)
2364 if (clk == NULL || IS_ERR(clk))
2368 * trap out already registered clocks
2370 if (clk->node.next || clk->node.prev)
2373 mutex_lock(&clocks_mutex);
2375 if (clk->get_parent)
2376 clk->parent = clk->get_parent(clk);
2377 else if (clk->parents)
2378 clk->parent = clksel_get_parent(clk);
2381 list_add(&clk->sibling, &clk->parent->children);
2383 list_add(&clk->sibling, &root_clks);
2385 list_add(&clk->node, &clocks);
2387 mutex_unlock(&clocks_mutex);
2392 static unsigned int __initdata armclk = 300 * MHZ;
2395 * You can override arm_clk rate with armclk= cmdline option.
2397 static int __init armclk_setup(char *str)
2399 get_option(&str, &armclk);
2407 clk_set_rate_nolock(&arm_pll_clk, armclk);
2410 early_param("armclk", armclk_setup);
2412 static void __init rk29_clock_common_init(unsigned long ppll_rate)
2414 unsigned long aclk_p,hclk_p,pclk_p;
2415 struct clk *aclk_vepu_parent,*aclk_vdpu_parent,*aclk_gpu_parent;
2416 unsigned long aclk_vepu_rate,hclk_vepu_rate,aclk_ddr_vepu_rate,aclk_gpu_rate;
2417 unsigned long codec_pll=552 * MHZ;
2425 aclk_gpu_parent=aclk_vdpu_parent=aclk_vepu_parent=&codec_pll_clk;
2426 aclk_gpu_rate=aclk_ddr_vepu_rate=aclk_vepu_rate=codec_pll/2;
2427 hclk_vepu_rate=codec_pll/4;
2433 aclk_gpu_parent=aclk_vdpu_parent=aclk_vepu_parent=&codec_pll_clk;
2434 aclk_gpu_rate=aclk_ddr_vepu_rate=aclk_vepu_rate=codec_pll/2;
2435 hclk_vepu_rate=codec_pll/4;
2442 aclk_gpu_parent=aclk_vdpu_parent=aclk_vepu_parent=&general_pll_clk;
2443 aclk_gpu_rate=aclk_ddr_vepu_rate=aclk_vepu_rate=ppll_rate;
2444 hclk_vepu_rate=ppll_rate/2;
2451 aclk_gpu_parent=aclk_vdpu_parent=aclk_vepu_parent=&general_pll_clk;
2452 aclk_gpu_rate=aclk_ddr_vepu_rate=aclk_vepu_rate=ppll_rate;
2453 hclk_vepu_rate=ppll_rate/2;
2456 clk_set_rate_nolock(&general_pll_clk,ppll_rate);// 288
2457 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
2458 clk_set_rate_nolock(&aclk_periph, aclk_p);//144
2459 clk_set_rate_nolock(&hclk_periph, hclk_p);// 144
2460 clk_set_rate_nolock(&pclk_periph, pclk_p);// 36
2461 clk_set_parent_nolock(&clk_uhost, &general_pll_clk);
2462 clk_set_rate_nolock(&clk_uhost, 48 * MHZ);
2463 clk_set_parent_nolock(&clk_i2s0_div, &general_pll_clk);
2464 clk_set_parent_nolock(&clk_i2s1_div, &general_pll_clk);
2465 clk_set_parent_nolock(&clk_spdif_div, &general_pll_clk);
2466 clk_set_parent_nolock(&clk_spi_src, &general_pll_clk);
2467 clk_set_parent_nolock(&clk_mmc_src, &general_pll_clk);
2468 clk_set_parent_nolock(&clk_uart01_src, &general_pll_clk);
2469 clk_set_parent_nolock(&clk_uart23_src, &general_pll_clk);
2470 clk_set_parent_nolock(&dclk_lcdc_div, &general_pll_clk);
2471 clk_set_parent_nolock(&aclk_lcdc, &general_pll_clk);
2472 clk_set_parent_nolock(&clk_mac_ref_div, &general_pll_clk);
2473 clk_set_parent_nolock(&clk_hsadc_div, &general_pll_clk);
2475 clk_set_rate_nolock(&codec_pll_clk, codec_pll);
2476 clk_set_parent_nolock(&clk_gpu, &codec_pll_clk);
2478 clk_set_rate_nolock(&arm_pll_clk, armclk);
2479 clk_set_parent_nolock(&clk_mac_ref_div, &arm_pll_clk);
2480 /*you can choose clk parent form codec pll or periph pll for following logic*/
2481 clk_set_parent_nolock(&aclk_vepu, aclk_vepu_parent);
2482 clk_set_rate_nolock(&aclk_vepu, aclk_vepu_rate);
2483 clk_set_rate_nolock(&clk_aclk_ddr_vepu,aclk_ddr_vepu_rate);
2484 clk_set_rate_nolock(&hclk_vepu, hclk_vepu_rate);
2485 clk_set_parent_nolock(&aclk_vdpu, aclk_vdpu_parent);
2486 clk_set_parent_nolock(&aclk_gpu, aclk_gpu_parent);
2487 clk_set_rate_nolock(&aclk_gpu,aclk_gpu_rate);
2489 static void __init clk_enable_init_clocks(void)
2491 clk_enable_nolock(&hclk_cpu);
2492 clk_enable_nolock(&pclk_cpu);
2493 clk_enable_nolock(&hclk_periph);
2494 clk_enable_nolock(&pclk_periph);
2495 clk_enable_nolock(&clk_nandc);
2496 clk_enable_nolock(&clk_aclk_cpu_peri);
2497 clk_enable_nolock(&clk_aclk_ddr_peri);
2498 clk_enable_nolock(&clk_grf);
2499 clk_enable_nolock(&clk_pmu);
2500 clk_enable_nolock(&clk_ddr_cpu);
2501 clk_enable_nolock(&clk_ddr_reg);
2502 clk_enable_nolock(&clk_ddr_phy);
2503 clk_enable_nolock(&clk_gic);
2504 clk_enable_nolock(&clk_dma2);
2505 clk_enable_nolock(&clk_dma1);
2506 clk_enable_nolock(&clk_emem);
2507 clk_enable_nolock(&clk_intmem);
2508 clk_enable_nolock(&clk_ddr);
2509 clk_enable_nolock(&clk_debug);
2510 clk_enable_nolock(&clk_jtag);
2511 clk_enable_nolock(&clk_uart1);
2514 static int __init clk_disable_unused(void)
2518 list_for_each_entry(ck, &clocks, node) {
2519 if (ck->usecount > 0 || ck->mode == NULL || (ck->flags & IS_PD))
2523 clk_enable_nolock(ck);
2524 clk_disable_nolock(ck);
2531 void __init rk29_clock_init(unsigned long ppll_rate)
2533 struct clk_lookup *lk;
2535 cru_clkgate3_con_mirror = cru_readl(CRU_CLKGATE3_CON);
2536 cru_softrst0_con_mirror = cru_readl(CRU_SOFTRST0_CON);
2538 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++)
2539 clk_preinit(lk->clk);
2541 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
2543 clk_register(lk->clk);
2546 clk_recalculate_root_clocks_nolock();
2549 * Only enable those clocks we will need, let the drivers
2550 * enable other clocks as necessary
2552 clk_enable_init_clocks();
2555 * Disable any unused clocks left on by the bootloader
2557 clk_disable_unused();
2559 rk29_clock_common_init(ppll_rate);
2561 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",
2562 arm_pll_clk.rate / MHZ, ddr_pll_clk.rate / MHZ, codec_pll_clk.rate / MHZ, general_pll_clk.rate / MHZ, clk_core.rate / MHZ,
2563 aclk_cpu.rate / MHZ, hclk_cpu.rate / MHZ, pclk_cpu.rate / MHZ, aclk_periph.rate / MHZ, hclk_periph.rate / MHZ, pclk_periph.rate / MHZ);
2566 #ifdef CONFIG_PROC_FS
2567 #include <linux/proc_fs.h>
2568 #include <linux/seq_file.h>
2570 static void dump_clock(struct seq_file *s, struct clk *clk, int deep)
2574 unsigned long rate = clk->rate;
2576 for (i = 0; i < deep; i++)
2579 seq_printf(s, "%-9s ", clk->name);
2581 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
2583 int idx = clk->gate_idx;
2586 reg = CRU_CLKGATE0_CON;
2587 reg += (idx >> 5) << 2;
2590 if (reg == CRU_CLKGATE3_CON)
2591 v = cru_clkgate3_con_mirror & (1 << idx);
2593 v = cru_readl(reg) & (1 << idx);
2595 seq_printf(s, "%s ", v ? "off" : "on ");
2598 if (clk == &arm_pll_clk) {
2599 switch (cru_readl(CRU_MODE_CON) & CRU_CPU_MODE_MASK) {
2600 case CRU_CPU_MODE_SLOW: seq_printf(s, "slow "); break;
2601 case CRU_CPU_MODE_NORMAL: seq_printf(s, "normal "); break;
2602 case CRU_CPU_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2604 if (cru_readl(CRU_APLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2605 } else if (clk == &ddr_pll_clk) {
2606 switch (cru_readl(CRU_MODE_CON) & CRU_DDR_MODE_MASK) {
2607 case CRU_DDR_MODE_SLOW: seq_printf(s, "slow "); break;
2608 case CRU_DDR_MODE_NORMAL: seq_printf(s, "normal "); break;
2609 case CRU_DDR_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2611 if (cru_readl(CRU_DPLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2612 } else if (clk == &codec_pll_clk) {
2613 switch (cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK) {
2614 case CRU_CODEC_MODE_SLOW: seq_printf(s, "slow "); break;
2615 case CRU_CODEC_MODE_NORMAL: seq_printf(s, "normal "); break;
2616 case CRU_CODEC_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2618 if (cru_readl(CRU_CPLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2619 } else if (clk == &general_pll_clk) {
2620 switch (cru_readl(CRU_MODE_CON) & CRU_GENERAL_MODE_MASK) {
2621 case CRU_GENERAL_MODE_SLOW: seq_printf(s, "slow "); break;
2622 case CRU_GENERAL_MODE_NORMAL: seq_printf(s, "normal "); break;
2623 case CRU_GENERAL_MODE_SLOW27: seq_printf(s, "slow27 "); break;
2625 if (cru_readl(CRU_GPLL_CON) & PLL_BYPASS) seq_printf(s, "bypass ");
2630 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
2632 seq_printf(s, "%ld MHz", rate / MHZ);
2633 } else if (rate >= KHZ) {
2635 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
2637 seq_printf(s, "%ld KHz", rate / KHZ);
2639 seq_printf(s, "%ld Hz", rate);
2642 seq_printf(s, " usecount = %d", clk->usecount);
2644 seq_printf(s, " parent = %s\n", clk->parent ? clk->parent->name : "NULL");
2646 list_for_each_entry(ck, &clocks, node) {
2647 if (ck->parent == clk)
2648 dump_clock(s, ck, deep + 1);
2652 static int proc_clk_show(struct seq_file *s, void *v)
2656 mutex_lock(&clocks_mutex);
2657 list_for_each_entry(clk, &clocks, node) {
2659 dump_clock(s, clk, 0);
2661 mutex_unlock(&clocks_mutex);
2663 seq_printf(s, "\nCRU Registers:\n");
2664 seq_printf(s, "APLL : 0x%08x\n", cru_readl(CRU_APLL_CON));
2665 seq_printf(s, "DPLL : 0x%08x\n", cru_readl(CRU_DPLL_CON));
2666 seq_printf(s, "CPLL : 0x%08x\n", cru_readl(CRU_CPLL_CON));
2667 seq_printf(s, "GPLL : 0x%08x\n", cru_readl(CRU_GPLL_CON));
2668 seq_printf(s, "MODE : 0x%08x\n", cru_readl(CRU_MODE_CON));
2669 seq_printf(s, "CLKSEL0 : 0x%08x\n", cru_readl(CRU_CLKSEL0_CON));
2670 seq_printf(s, "CLKSEL1 : 0x%08x\n", cru_readl(CRU_CLKSEL1_CON));
2671 seq_printf(s, "CLKSEL2 : 0x%08x\n", cru_readl(CRU_CLKSEL2_CON));
2672 seq_printf(s, "CLKSEL3 : 0x%08x\n", cru_readl(CRU_CLKSEL3_CON));
2673 seq_printf(s, "CLKSEL4 : 0x%08x\n", cru_readl(CRU_CLKSEL4_CON));
2674 seq_printf(s, "CLKSEL5 : 0x%08x\n", cru_readl(CRU_CLKSEL5_CON));
2675 seq_printf(s, "CLKSEL6 : 0x%08x\n", cru_readl(CRU_CLKSEL6_CON));
2676 seq_printf(s, "CLKSEL7 : 0x%08x\n", cru_readl(CRU_CLKSEL7_CON));
2677 seq_printf(s, "CLKSEL8 : 0x%08x\n", cru_readl(CRU_CLKSEL8_CON));
2678 seq_printf(s, "CLKSEL9 : 0x%08x\n", cru_readl(CRU_CLKSEL9_CON));
2679 seq_printf(s, "CLKSEL10 : 0x%08x\n", cru_readl(CRU_CLKSEL10_CON));
2680 seq_printf(s, "CLKSEL11 : 0x%08x\n", cru_readl(CRU_CLKSEL11_CON));
2681 seq_printf(s, "CLKSEL12 : 0x%08x\n", cru_readl(CRU_CLKSEL12_CON));
2682 seq_printf(s, "CLKSEL13 : 0x%08x\n", cru_readl(CRU_CLKSEL13_CON));
2683 seq_printf(s, "CLKSEL14 : 0x%08x\n", cru_readl(CRU_CLKSEL14_CON));
2684 seq_printf(s, "CLKSEL15 : 0x%08x\n", cru_readl(CRU_CLKSEL15_CON));
2685 seq_printf(s, "CLKSEL16 : 0x%08x\n", cru_readl(CRU_CLKSEL16_CON));
2686 seq_printf(s, "CLKSEL17 : 0x%08x\n", cru_readl(CRU_CLKSEL17_CON));
2687 seq_printf(s, "CLKGATE0 : 0x%08x\n", cru_readl(CRU_CLKGATE0_CON));
2688 seq_printf(s, "CLKGATE1 : 0x%08x\n", cru_readl(CRU_CLKGATE1_CON));
2689 seq_printf(s, "CLKGATE2 : 0x%08x\n", cru_readl(CRU_CLKGATE2_CON));
2690 seq_printf(s, "CLKGATE3 : 0x%08x\n", cru_readl(CRU_CLKGATE3_CON));
2691 seq_printf(s, "CLKGATE3M: 0x%08x\n", cru_clkgate3_con_mirror);
2692 seq_printf(s, "SOFTRST0 : 0x%08x\n", cru_readl(CRU_SOFTRST0_CON));
2693 seq_printf(s, "SOFTRST0M: 0x%08x\n", cru_softrst0_con_mirror);
2694 seq_printf(s, "SOFTRST1 : 0x%08x\n", cru_readl(CRU_SOFTRST1_CON));
2695 seq_printf(s, "SOFTRST2 : 0x%08x\n", cru_readl(CRU_SOFTRST2_CON));
2697 seq_printf(s, "\nPMU Registers:\n");
2698 seq_printf(s, "WAKEUP_EN0 : 0x%08x\n", pmu_readl(PMU_WAKEUP_EN0));
2699 seq_printf(s, "WAKEUP_EN1 : 0x%08x\n", pmu_readl(PMU_WAKEUP_EN1));
2700 seq_printf(s, "WAKEUP_EN2 : 0x%08x\n", pmu_readl(PMU_WAKEUP_EN2));
2701 seq_printf(s, "PD_CON : 0x%08x\n", pmu_readl(PMU_PD_CON));
2702 seq_printf(s, "MISC_CON : 0x%08x\n", pmu_readl(PMU_MISC_CON));
2703 seq_printf(s, "PLL_CNT : 0x%08x\n", pmu_readl(PMU_PLL_CNT));
2704 seq_printf(s, "PD_ST : 0x%08x\n", pmu_readl(PMU_PD_ST));
2705 seq_printf(s, "INT_ST : 0x%08x\n", pmu_readl(PMU_INT_ST));
2710 static int proc_clk_open(struct inode *inode, struct file *file)
2712 return single_open(file, proc_clk_show, NULL);
2715 static const struct file_operations proc_clk_fops = {
2716 .open = proc_clk_open,
2718 .llseek = seq_lseek,
2719 .release = single_release,
2722 static int __init clk_proc_init(void)
2724 proc_create("clocks", 0, NULL, &proc_clk_fops);
2728 late_initcall(clk_proc_init);
2729 #endif /* CONFIG_PROC_FS */