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>
35 #define PWM_VCORE_120 40
36 #define PWM_VCORE_125 32
37 #define PWM_VCORE_130 21
38 #define PWM_VCORE_135 10
39 #define PWM_VCORE_140 0
42 #define PLL_HIGH_BAND (0x01 << 16)
43 #define PLL_LOW_BAND (0x00 << 16)
44 #define PLL_PD (0x01 << 15)
46 #define PLL_CLKR(i) ((((i) - 1) & 0x1f) << 10)
47 #define PLL_NR(v) ((((v) >> 10) & 0x1f) + 1)
49 #define PLL_CLKF(i) ((((i) - 1) & 0x7f) << 3)
50 #define PLL_NF(v) ((((v) >> 3) & 0x7f) + 1)
51 #define PLL_NF2(v) (((((v) >> 3) & 0x7f) + 1) << 1)
53 #define PLL_CLKOD(i) (((i) & 0x03) << 1)
54 #define PLL_NO_1 PLL_CLKOD(0)
55 #define PLL_NO_2 PLL_CLKOD(1)
56 #define PLL_NO_4 PLL_CLKOD(2)
57 #define PLL_NO_8 PLL_CLKOD(3)
58 #define PLL_NO_SHIFT(v) (((v) >> 1) & 0x03)
60 #define PLL_BYPASS (0x01)
63 #define CRU_CPU_MODE_MASK (0x03u << 0)
64 #define CRU_CPU_MODE_SLOW (0x00u << 0)
65 #define CRU_CPU_MODE_NORMAL (0x01u << 0)
66 #define CRU_CPU_MODE_DSLOW (0x02u << 0)
68 #define CRU_PERIPH_MODE_MASK (0x03u << 2)
69 #define CRU_PERIPH_MODE_SLOW (0x00u << 2)
70 #define CRU_PERIPH_MODE_NORMAL (0x01u << 2)
71 #define CRU_PERIPH_MODE_DSLOW (0x02u << 2)
73 #define CRU_CODEC_MODE_MASK (0x03u << 4)
74 #define CRU_CODEC_MODE_SLOW (0x00u << 4)
75 #define CRU_CODEC_MODE_NORMAL (0x01u << 4)
76 #define CRU_CODEC_MODE_DSLOW (0x02u << 4)
78 #define CRU_DDR_MODE_MASK (0x03u << 6)
79 #define CRU_DDR_MODE_SLOW (0x00u << 6)
80 #define CRU_DDR_MODE_NORMAL (0x01u << 6)
81 #define CRU_DDR_MODE_DSLOW (0x02u << 6)
85 #define RATE_FIXED (1 << 1) /* Fixed clock rate */
86 #define CONFIG_PARTICIPANT (1 << 10) /* Fundamental clock */
87 #define ENABLE_ON_INIT (1 << 11) /* Enable upon framework init */
89 #define cru_readl(offset) readl(RK29_CRU_BASE + offset)
90 #define cru_writel(v, offset) writel(v, RK29_CRU_BASE + offset)
91 #define cru_writel_force(v, offset) do { u32 _v = v; u32 _count = 5; do { cru_writel(_v, offset); } while (cru_readl(offset) != _v && _count--); } while (0) /* huangtao: when write CRU_xPLL_CON, first time may failed, so try again. unknown why. */
93 #define regfile_readl(offset) readl(RK29_GRF_BASE + offset)
95 #define MHZ (1000*1000)
99 struct list_head node;
102 struct list_head children;
103 struct list_head sibling; /* node for children */
106 int (*mode)(struct clk *clk, int on);
107 unsigned long (*recalc)(struct clk *); /* if null, follow parent */
108 int (*set_rate)(struct clk *, unsigned long);
109 long (*round_rate)(struct clk *, unsigned long);
110 struct clk* (*get_parent)(struct clk *); /* get clk's parent from the hardware. default is clksel_get_parent if parents present */
111 int (*set_parent)(struct clk *, struct clk *); /* default is clksel_set_parent if parents present */
119 u8 clksel_parent_mask;
120 u8 clksel_parent_shift;
121 struct clk **parents;
124 static int clk_enable_nolock(struct clk *clk);
125 static void clk_disable_nolock(struct clk *clk);
126 static int clk_set_rate_nolock(struct clk *clk, unsigned long rate);
127 static int clk_set_parent_nolock(struct clk *clk, struct clk *parent);
128 static void __clk_reparent(struct clk *child, struct clk *parent);
129 static void __propagate_rate(struct clk *tclk);
130 static struct clk codec_pll_clk;
131 static struct clk periph_pll_clk;
133 static unsigned long clksel_recalc_div(struct clk *clk)
135 u32 div = ((cru_readl(clk->clksel_con) >> clk->clksel_shift) & clk->clksel_mask) + 1;
136 unsigned long rate = clk->parent->rate / div;
137 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
141 static unsigned long clksel_recalc_shift(struct clk *clk)
143 u32 shift = (cru_readl(clk->clksel_con) >> clk->clksel_shift) & clk->clksel_mask;
144 unsigned long rate = clk->parent->rate >> shift;
145 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
149 static unsigned long clksel_recalc_frac(struct clk *clk)
153 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
154 if (r == 0) // FPGA ?
155 return clk->parent->rate;
157 denominator = r & 0xFFFF;
158 rate64 = (u64)clk->parent->rate * numerator;
159 do_div(rate64, denominator);
161 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
165 static int clksel_set_rate_div(struct clk *clk, unsigned long rate)
169 for (div = 0; div <= clk->clksel_mask; div++) {
170 u32 new_rate = clk->parent->rate / (div + 1);
171 if (new_rate <= rate) {
172 u32 v = cru_readl(clk->clksel_con);
173 v &= ~((u32) clk->clksel_mask << clk->clksel_shift);
174 v |= div << clk->clksel_shift;
175 cru_writel(v, clk->clksel_con);
176 clk->rate = new_rate;
177 pr_debug("clksel_set_rate_div for clock %s to rate %ld (div %d)\n", clk->name, rate, div + 1);
185 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
189 for (shift = 0; (1 << shift) <= clk->clksel_maxdiv; shift++) {
190 u32 new_rate = clk->parent->rate >> shift;
191 if (new_rate <= rate) {
192 u32 v = cru_readl(clk->clksel_con);
193 v &= ~((u32) clk->clksel_mask << clk->clksel_shift);
194 v |= shift << clk->clksel_shift;
195 cru_writel(v, clk->clksel_con);
196 clk->rate = new_rate;
197 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
205 static struct clk* clksel_get_parent(struct clk *clk)
207 return clk->parents[(cru_readl(clk->clksel_con) >> clk->clksel_parent_shift) & clk->clksel_parent_mask];
210 static int clksel_set_parent(struct clk *clk, struct clk *parent)
212 struct clk **p = clk->parents;
217 for (i = 0; (i <= clk->clksel_parent_mask) && *p; i++, p++) {
221 v = cru_readl(clk->clksel_con);
222 v &= ~((u32) clk->clksel_parent_mask << clk->clksel_parent_shift);
223 v |= (i << clk->clksel_parent_shift);
224 cru_writel(v, clk->clksel_con);
230 static int gate_mode(struct clk *clk, int on)
233 int idx = clk->gate_idx;
236 if (idx >= CLK_GATE_MAX)
239 reg = CRU_CLKGATE0_CON;
240 reg += (idx >> 5) << 2;
245 v &= ~(1 << idx); // clear bit
247 v |= (1 << idx); // set bit
254 static struct clk xin24m = {
260 static struct clk clk_12m = {
267 static struct clk xin27m = {
273 static struct clk otgphy0_clkin = {
274 .name = "otgphy0_clkin",
279 static struct clk otgphy1_clkin = {
280 .name = "otgphy1_clkin",
286 static void delay_500ns(void)
294 #define PERIPH_PLL_IDX 0
295 #define CODEC_PLL_IDX 1
296 #define ARM_PLL_IDX 2
297 #define DDR_PLL_IDX 3
299 #define GRF_SOC_CON0 0xbc
300 static void pll_wait_lock(int pll_idx, int delay)
302 u32 bit = 0x2000000u << pll_idx;
304 if (regfile_readl(GRF_SOC_CON0) & bit)
309 pr_warning("wait pll bit 0x%x time out!\n", bit);
313 static unsigned long arm_pll_clk_recalc(struct clk *clk)
317 if ((cru_readl(CRU_MODE_CON) & CRU_CPU_MODE_MASK) == CRU_CPU_MODE_NORMAL) {
318 u32 v = cru_readl(CRU_APLL_CON);
319 u64 rate64 = (u64) clk->parent->rate * PLL_NF2(v);
320 do_div(rate64, PLL_NR(v));
321 rate = rate64 >> PLL_NO_SHIFT(v);
322 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));
324 rate = clk->parent->rate;
325 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
337 #define CORE_ACLK_11 (0 << 5)
338 #define CORE_ACLK_21 (1 << 5)
339 #define CORE_ACLK_31 (2 << 5)
340 #define CORE_ACLK_41 (3 << 5)
341 #define CORE_ACLK_81 (4 << 5)
342 #define CORE_ACLK_MASK (7 << 5)
344 #define ACLK_HCLK_11 (0 << 8)
345 #define ACLK_HCLK_21 (1 << 8)
346 #define ACLK_HCLK_41 (2 << 8)
347 #define ACLK_HCLK_MASK (3 << 8)
349 #define ACLK_PCLK_11 (0 << 10)
350 #define ACLK_PCLK_21 (1 << 10)
351 #define ACLK_PCLK_41 (2 << 10)
352 #define ACLK_PCLK_81 (3 << 10)
353 #define ACLK_PCLK_MASK (3 << 10)
355 #define ARM_PLL(_mhz, nr, nf, no, _axi_div, _ahb_div, _apb_div) \
357 .rate = _mhz * MHZ, \
358 .apll_con = PLL_CLKR(nr) | PLL_CLKF(nf >> 1) | PLL_NO_##no, \
359 .clksel0_con = CORE_ACLK_##_axi_div | ACLK_HCLK_##_ahb_div | ACLK_PCLK_##_apb_div, \
362 static const struct arm_pll_set arm_pll[] = {
363 // rate = 24 * NF / (NR * NO)
364 // rate NR NF NO adiv hdiv pdiv
365 ARM_PLL(1200, 1, 50, 1, 41, 21, 81),
366 ARM_PLL(1176, 2, 98, 1, 41, 21, 81),
367 ARM_PLL(1152, 1, 48, 1, 41, 21, 81),
368 ARM_PLL(1104, 1, 46, 1, 41, 21, 81),
369 ARM_PLL(1056, 1, 44, 1, 41, 21, 81),
370 ARM_PLL(1008, 1, 42, 1, 41, 21, 81),
371 ARM_PLL( 960, 1, 40, 1, 41, 21, 81),
372 ARM_PLL( 912, 1, 38, 1, 41, 21, 81),
373 ARM_PLL( 888, 2, 74, 1, 31, 21, 81),
374 ARM_PLL( 624, 1, 52, 2, 31, 21, 81),
375 // last item, pll power down.
376 ARM_PLL( 24, 1, 64, 8, 21, 21, 41),
379 #define CORE_PARENT_MASK (3 << 23)
380 #define CORE_PARENT_ARM_PLL (0 << 23)
381 #define CORE_PARENT_PERIPH_PLL (1 << 23)
383 #define PWM_DIV2 (0<<9)
384 #define PWM_DIV4 (1<<9)
385 #define PWM_DIV8 (2<<9)
386 #define PWM_DIV16 (3<<9)
387 #define PWM_DIV32 (4<<9)
388 #define PWM_DIV64 (5<<9)
389 #define PWM_DIV128 (6<<9)
390 #define PWM_DIV256 (7<<9)
391 #define PWM_DIV512 (8<<9)
392 #define PWM_DIV1024 (9<<9)
394 #define PWM_CAPTURE (1<<8)
395 #define PWM_RESET (1<<7)
396 #define PWM_INTCLR (1<<6)
397 #define PWM_INTEN (1<<5)
398 #define PWM_SINGLE (1<<6)
400 #define PWM_ENABLE (1<<3)
401 #define PWM_TimeEN (1)
403 #define PWM_DIV PWM_DIV2
405 static struct clk pclk_periph;
406 void PWMInit(u32 nHz, u32 rate)
411 #define REG_FILE_BASE_ADDR RK29_GRF_BASE
412 volatile unsigned int * pGRF_GPIO2L_IOMUX = (volatile unsigned int *)(REG_FILE_BASE_ADDR + 0x58);
413 *pGRF_GPIO2L_IOMUX &= ~(0x3<<6);
414 *pGRF_GPIO2L_IOMUX |= (0x2<<6);
418 #define PWM_BASE_ADDR RK29_PWM_BASE
419 volatile unsigned int * pPWM2_CTRL = (volatile unsigned int *)(PWM_BASE_ADDR + 0x2C);
420 volatile unsigned int * pPWM2_LRC = (volatile unsigned int *)(PWM_BASE_ADDR + 0x28);
421 volatile unsigned int * pPWM2_HRC = (volatile unsigned int *)(PWM_BASE_ADDR + 0x24);
422 volatile unsigned int * pPWM2_CNTR = (volatile unsigned int *)(PWM_BASE_ADDR + 0x20);
424 #define GPIO2_BASE_ADDR RK29_GPIO2_BASE
425 volatile unsigned int *pGPIO2_DIR = (volatile unsigned int *)(GPIO2_BASE_ADDR + 0x4);
426 volatile unsigned int *pGPIO2_LEVEL = (volatile unsigned int *)GPIO2_BASE_ADDR;
429 // iomux pwm2 to gpio2_a[3]
430 *pGRF_GPIO2L_IOMUX &= ~(0x3<<6);
431 // set gpio to low level
432 *pGPIO2_DIR |= 0x1<<3;
433 *pGPIO2_LEVEL &= ~(0x1<<3);
435 *pPWM2_CTRL= PWM_DIV|PWM_RESET;
436 divh = pclk_periph.rate / nHz;
437 divh = divh >> (1+(PWM_DIV>>9));
438 *pPWM2_LRC = (divh == 0)?1:divh;
440 divh = (*pPWM2_LRC)*rate/100;
441 *pPWM2_HRC = divh?divh:1;
444 *pPWM2_CTRL = PWM_DIV|PWM_ENABLE|PWM_TimeEN;
445 printk("pclk_periph %d LRC %08x HRC %08x\n", pclk_periph.rate, *pPWM2_LRC, *pPWM2_HRC);
448 int i; for (i = 0; i < 6000; i++)
452 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
454 const struct arm_pll_set *ps, *pt;
457 /* find the arm_pll we want. */
458 ps = pt = &arm_pll[0];
460 if (pt->rate == rate) {
464 // we are sorted, and ps->rate > pt->rate.
465 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
467 if (pt->rate < rate || pt->rate == 24 * MHZ)
472 PWMInit(1 * MHZ, PWM_VCORE_135); // 1.35V
474 /* make aclk safe & reparent to periph pll */
475 cru_writel((cru_readl(CRU_CLKSEL0_CON) & ~(CORE_PARENT_MASK | CORE_ACLK_MASK)) | CORE_PARENT_PERIPH_PLL | CORE_ACLK_21, CRU_CLKSEL0_CON);
477 /* enter slow mode */
478 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | CRU_CPU_MODE_SLOW, CRU_MODE_CON);
481 cru_writel(cru_readl(CRU_APLL_CON) | PLL_PD, CRU_APLL_CON);
485 cru_writel(ps->apll_con | PLL_PD, CRU_APLL_CON);
490 cru_writel(ps->apll_con, CRU_APLL_CON);
492 for (i = 0; i < 600; i++)
494 pll_wait_lock(ARM_PLL_IDX, 2400000);
496 /* reparent to arm pll & set aclk/hclk/pclk */
497 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);
499 /* enter normal mode */
500 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | CRU_CPU_MODE_NORMAL, CRU_MODE_CON);
505 static struct clk *arm_pll_parents[2] = { &xin24m, &xin27m };
507 static struct clk arm_pll_clk = {
510 .recalc = arm_pll_clk_recalc,
511 .set_rate = arm_pll_clk_set_rate,
512 .clksel_con = CRU_MODE_CON,
513 .clksel_parent_mask = 1,
514 .clksel_parent_shift = 8,
515 .parents = arm_pll_parents,
518 static unsigned long ddr_pll_clk_recalc(struct clk *clk)
522 if ((cru_readl(CRU_MODE_CON) & CRU_DDR_MODE_MASK) == CRU_DDR_MODE_NORMAL) {
523 u32 v = cru_readl(CRU_DPLL_CON);
524 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
525 do_div(rate64, PLL_NR(v));
526 rate = rate64 >> PLL_NO_SHIFT(v);
527 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));
529 rate = clk->parent->rate;
530 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
536 static struct clk *ddr_pll_parents[4] = { &xin24m, &xin27m, &codec_pll_clk, &periph_pll_clk };
538 static struct clk ddr_pll_clk = {
541 .recalc = ddr_pll_clk_recalc,
542 .clksel_con = CRU_MODE_CON,
543 .clksel_parent_mask = 3,
544 .clksel_parent_shift = 13,
545 .parents = ddr_pll_parents,
549 static unsigned long codec_pll_clk_recalc(struct clk *clk)
553 if ((cru_readl(CRU_MODE_CON) & CRU_CODEC_MODE_MASK) == CRU_CODEC_MODE_NORMAL) {
554 u32 v = cru_readl(CRU_CPLL_CON);
555 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
556 do_div(rate64, PLL_NR(v));
557 rate = rate64 >> PLL_NO_SHIFT(v);
558 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));
560 rate = clk->parent->rate;
561 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
567 #define CODEC_PLL_PARENT_MASK (3 << 11)
568 #define CODEC_PLL_PARENT_XIN24M (0 << 11)
569 #define CODEC_PLL_PARENT_XIN27M (1 << 11)
570 #define CODEC_PLL_PARENT_DDR_PLL (2 << 11)
571 #define CODEC_PLL_PARENT_PERIPH_PLL (3 << 11)
573 static int codec_pll_clk_set_rate(struct clk *clk, unsigned long rate)
583 cpll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(18) | PLL_NO_4;
584 mode_con = CODEC_PLL_PARENT_XIN24M;
589 cpll_con = PLL_LOW_BAND | PLL_CLKR(1) | PLL_CLKF(22) | PLL_NO_2;
590 mode_con = CODEC_PLL_PARENT_XIN27M;
598 /* enter slow mode */
599 cru_writel((cru_readl(CRU_MODE_CON) & ~(CRU_CODEC_MODE_MASK | CODEC_PLL_PARENT_MASK)) | CRU_CODEC_MODE_SLOW | mode_con, CRU_MODE_CON);
602 cru_writel(cru_readl(CRU_CPLL_CON) | PLL_PD, CRU_CPLL_CON);
606 cru_writel(cpll_con | PLL_PD, CRU_CPLL_CON);
611 cru_writel(cpll_con, CRU_CPLL_CON);
613 for (i = 0; i < 600; i++)
615 pll_wait_lock(CODEC_PLL_IDX, 2400000);
617 /* enter normal mode */
618 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | CRU_CODEC_MODE_NORMAL, CRU_MODE_CON);
620 clk_set_parent_nolock(clk, parent);
625 static struct clk *codec_pll_parents[4] = { &xin24m, &xin27m, &ddr_pll_clk, &periph_pll_clk };
627 static struct clk codec_pll_clk = {
630 .recalc = codec_pll_clk_recalc,
631 .set_rate = codec_pll_clk_set_rate,
632 .clksel_con = CRU_MODE_CON,
633 .clksel_parent_mask = 3,
634 .clksel_parent_shift = 11,
635 .parents = codec_pll_parents,
639 static unsigned long periph_pll_clk_recalc(struct clk *clk)
643 if ((cru_readl(CRU_MODE_CON) & CRU_PERIPH_MODE_MASK) == CRU_PERIPH_MODE_NORMAL) {
644 u32 v = cru_readl(CRU_PPLL_CON);
645 u64 rate64 = (u64) clk->parent->rate * PLL_NF(v);
646 do_div(rate64, PLL_NR(v));
647 rate = rate64 >> PLL_NO_SHIFT(v);
648 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));
650 rate = clk->parent->rate;
651 pr_debug("%s new clock rate is %ld (slow mode)\n", clk->name, rate);
657 static int periph_pll_clk_set_rate(struct clk *clk, unsigned long rate)
660 /* 624M: high-band, NR=1, NF=26, NO=1 */
661 u32 v = PLL_HIGH_BAND | PLL_CLKR(1) | PLL_CLKF(26) | PLL_NO_1;
663 /* enter slow mode */
664 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_PERIPH_MODE_MASK) | CRU_PERIPH_MODE_SLOW, CRU_MODE_CON);
667 cru_writel(cru_readl(CRU_PPLL_CON) | PLL_PD, CRU_PPLL_CON);
671 cru_writel(v | PLL_PD, CRU_PPLL_CON);
676 cru_writel(v, CRU_PPLL_CON);
678 for (i = 0; i < 600; i++)
680 pll_wait_lock(PERIPH_PLL_IDX, 2400000);
682 /* enter normal mode */
683 cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_PERIPH_MODE_MASK) | CRU_PERIPH_MODE_NORMAL, CRU_MODE_CON);
688 static struct clk *periph_pll_parents[4] = { &xin24m, &xin27m, &ddr_pll_clk, &codec_pll_clk };
690 static struct clk periph_pll_clk = {
691 .name = "periph_pll",
693 .recalc = periph_pll_clk_recalc,
694 .set_rate = periph_pll_clk_set_rate,
695 .clksel_con = CRU_MODE_CON,
696 .clksel_parent_mask = 3,
697 .clksel_parent_shift = 9,
698 .parents = periph_pll_parents,
702 static struct clk *clk_core_parents[4] = { &arm_pll_clk, &periph_pll_clk, &codec_pll_clk, &ddr_pll_clk };
704 static struct clk clk_core = {
706 .parent = &arm_pll_clk,
707 .recalc = clksel_recalc_div,
708 .clksel_con = CRU_CLKSEL0_CON,
711 .clksel_parent_mask = 3,
712 .clksel_parent_shift = 23,
713 .parents = clk_core_parents,
716 static unsigned long aclk_cpu_recalc(struct clk *clk)
719 u32 div = ((cru_readl(CRU_CLKSEL0_CON) >> 5) & 0x7) + 1;
724 rate = clk->parent->rate / div;
725 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
730 static struct clk aclk_cpu = {
733 .recalc = aclk_cpu_recalc,
736 static struct clk hclk_cpu = {
739 .recalc = clksel_recalc_shift,
740 .set_rate = clksel_set_rate_shift,
741 .clksel_con = CRU_CLKSEL0_CON,
747 static struct clk pclk_cpu = {
750 .recalc = clksel_recalc_shift,
751 .set_rate = clksel_set_rate_shift,
752 .clksel_con = CRU_CLKSEL0_CON,
758 static struct clk *aclk_periph_parents[4] = { &periph_pll_clk, &arm_pll_clk, &ddr_pll_clk, &codec_pll_clk };
760 static struct clk aclk_periph = {
761 .name = "aclk_periph",
763 .gate_idx = CLK_GATE_PEIRPH_AXI,
764 .recalc = clksel_recalc_div,
765 .set_rate = clksel_set_rate_div,
766 .clksel_con = CRU_CLKSEL0_CON,
769 .clksel_parent_mask = 3,
770 .clksel_parent_shift = 12,
771 .parents = aclk_periph_parents,
774 static struct clk pclk_periph = {
775 .name = "pclk_periph",
777 .gate_idx = CLK_GATE_PEIRPH_APB,
778 .parent = &aclk_periph,
779 .recalc = clksel_recalc_shift,
780 .set_rate = clksel_set_rate_shift,
781 .clksel_con = CRU_CLKSEL0_CON,
787 static struct clk hclk_periph = {
788 .name = "hclk_periph",
790 .gate_idx = CLK_GATE_PEIRPH_AHB,
791 .parent = &aclk_periph,
792 .recalc = clksel_recalc_shift,
793 .set_rate = clksel_set_rate_shift,
794 .clksel_con = CRU_CLKSEL0_CON,
801 static struct clk *clk_uhost_parents[8] = { &periph_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
803 static struct clk clk_uhost = {
806 .recalc = clksel_recalc_div,
807 .set_rate = clksel_set_rate_div,
808 .gate_idx = CLK_GATE_UHOST,
809 .clksel_con = CRU_CLKSEL1_CON,
812 .clksel_parent_mask = 7,
813 .clksel_parent_shift = 13,
814 .parents = clk_uhost_parents,
817 static struct clk *clk_otgphy_parents[4] = { &xin24m, &clk_12m, &clk_uhost };
819 static struct clk clk_otgphy0 = {
822 .gate_idx = CLK_GATE_USBPHY0,
823 .clksel_con = CRU_CLKSEL1_CON,
824 .clksel_parent_mask = 3,
825 .clksel_parent_shift = 9,
826 .parents = clk_otgphy_parents,
829 static struct clk clk_otgphy1 = {
832 .gate_idx = CLK_GATE_USBPHY1,
833 .clksel_con = CRU_CLKSEL1_CON,
834 .clksel_parent_mask = 3,
835 .clksel_parent_shift = 11,
836 .parents = clk_otgphy_parents,
840 static struct clk rmii_clkin = {
841 .name = "rmii_clkin",
844 static struct clk *clk_mac_ref_div_parents[4] = { &arm_pll_clk, &periph_pll_clk, &codec_pll_clk, &ddr_pll_clk };
846 static struct clk clk_mac_ref_div = {
847 .name = "mac_ref_div",
848 .recalc = clksel_recalc_div,
849 .set_rate = clksel_set_rate_div,
850 .clksel_con = CRU_CLKSEL1_CON,
853 .clksel_parent_mask = 3,
854 .clksel_parent_shift = 21,
855 .parents = clk_mac_ref_div_parents,
858 static struct clk *clk_mac_ref_parents[2] = { &clk_mac_ref_div, &rmii_clkin };
860 static struct clk clk_mac_ref = {
863 .gate_idx = CLK_GATE_MAC_PHY,
864 .clksel_con = CRU_CLKSEL1_CON,
865 .clksel_parent_mask = 1,
866 .clksel_parent_shift = 28,
867 .parents = clk_mac_ref_parents,
871 static struct clk *clk_i2s_div_parents[8] = { &codec_pll_clk, &periph_pll_clk, &arm_pll_clk, &ddr_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
873 static struct clk clk_i2s0_div = {
875 .recalc = clksel_recalc_div,
876 .set_rate = clksel_set_rate_div,
877 .clksel_con = CRU_CLKSEL2_CON,
880 .clksel_parent_mask = 7,
881 .clksel_parent_shift = 0,
882 .parents = clk_i2s_div_parents,
885 static struct clk clk_i2s1_div = {
887 .recalc = clksel_recalc_div,
888 .set_rate = clksel_set_rate_div,
889 .clksel_con = CRU_CLKSEL2_CON,
892 .clksel_parent_mask = 7,
893 .clksel_parent_shift = 10,
894 .parents = clk_i2s_div_parents,
897 static struct clk clk_spdif_div = {
899 .recalc = clksel_recalc_div,
900 .set_rate = clksel_set_rate_div,
901 .clksel_con = CRU_CLKSEL2_CON,
904 .clksel_parent_mask = 7,
905 .clksel_parent_shift = 20,
906 .parents = clk_i2s_div_parents,
909 static int clk_i2s_frac_div_set_rate(struct clk *clk, unsigned long rate)
911 u16 numerator, denominator;
914 case 8192000: /* 624*128/9750 */
918 case 11289600: /* 624*294/16250 */
922 case 12288000: /* 624*64/3250 */
926 case 22579200: /* 624*294/8125 */
930 case 24576000: /* 624*64/1625 */
934 case 45158400: /* 624*588/8125 */
938 case 49152000: /* 624*128/1625 */
946 pr_debug("set clock %s to rate %ld (%d/%d)\n", clk->name, rate, numerator, denominator);
947 cru_writel((u32)numerator << 16 | denominator, clk->clksel_con);
952 static struct clk clk_i2s0_frac_div = {
953 .name = "i2s0_frac_div",
954 .parent = &clk_i2s0_div,
955 .recalc = clksel_recalc_frac,
956 .set_rate = clk_i2s_frac_div_set_rate,
957 .clksel_con = CRU_CLKSEL3_CON,
960 static struct clk clk_i2s1_frac_div = {
961 .name = "i2s1_frac_div",
962 .parent = &clk_i2s1_div,
963 .recalc = clksel_recalc_frac,
964 .set_rate = clk_i2s_frac_div_set_rate,
965 .clksel_con = CRU_CLKSEL4_CON,
968 static struct clk clk_spdif_frac_div = {
969 .name = "spdif_frac_div",
970 .parent = &clk_spdif_div,
971 .recalc = clksel_recalc_frac,
972 .set_rate = clk_i2s_frac_div_set_rate,
973 .clksel_con = CRU_CLKSEL5_CON,
976 static int i2s_set_rate(struct clk *clk, unsigned long rate)
981 if (rate == 12 * MHZ) {
984 parent = clk->parents[1]; /* frac div */
985 ret = clk_set_rate_nolock(parent, rate);
989 if (clk->parent != parent)
990 clk_set_parent_nolock(clk, parent);
995 static struct clk *clk_i2s0_parents[4] = { &clk_i2s0_div, &clk_i2s0_frac_div, &clk_12m, &xin24m };
997 static struct clk clk_i2s0 = {
1000 .gate_idx = CLK_GATE_I2S0,
1001 .set_rate = i2s_set_rate,
1002 .clksel_con = CRU_CLKSEL2_CON,
1003 .clksel_parent_mask = 3,
1004 .clksel_parent_shift = 8,
1005 .parents = clk_i2s0_parents,
1008 static struct clk *clk_i2s1_parents[4] = { &clk_i2s1_div, &clk_i2s1_frac_div, &clk_12m, &xin24m };
1010 static struct clk clk_i2s1 = {
1013 .gate_idx = CLK_GATE_I2S1,
1014 .set_rate = i2s_set_rate,
1015 .clksel_con = CRU_CLKSEL2_CON,
1016 .clksel_parent_mask = 3,
1017 .clksel_parent_shift = 18,
1018 .parents = clk_i2s1_parents,
1021 static struct clk *clk_spdif_parents[4] = { &clk_spdif_div, &clk_spdif_frac_div, &clk_12m, &xin24m };
1023 static struct clk clk_spdif = {
1026 .gate_idx = CLK_GATE_SPDIF,
1027 .set_rate = i2s_set_rate,
1028 .clksel_con = CRU_CLKSEL2_CON,
1029 .clksel_parent_mask = 3,
1030 .clksel_parent_shift = 28,
1031 .parents = clk_spdif_parents,
1035 static struct clk *clk_spi_src_parents[4] = { &periph_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk };
1037 static struct clk clk_spi_src = {
1039 .clksel_con = CRU_CLKSEL6_CON,
1040 .clksel_parent_mask = 3,
1041 .clksel_parent_shift = 0,
1042 .parents = clk_spi_src_parents,
1045 static struct clk clk_spi0 = {
1047 .parent = &clk_spi_src,
1049 .recalc = clksel_recalc_div,
1050 .set_rate = clksel_set_rate_div,
1051 .gate_idx = CLK_GATE_SPI0,
1052 .clksel_con = CRU_CLKSEL6_CON,
1053 .clksel_mask = 0x7F,
1057 static struct clk clk_spi1 = {
1059 .parent = &clk_spi_src,
1061 .recalc = clksel_recalc_div,
1062 .set_rate = clksel_set_rate_div,
1063 .gate_idx = CLK_GATE_SPI1,
1064 .clksel_con = CRU_CLKSEL6_CON,
1065 .clksel_mask = 0x7F,
1070 static struct clk clk_saradc = {
1072 .parent = &pclk_periph,
1074 .recalc = clksel_recalc_div,
1075 .set_rate = clksel_set_rate_div,
1076 .gate_idx = CLK_GATE_SARADC,
1077 .clksel_con = CRU_CLKSEL6_CON,
1078 .clksel_mask = 0xFF,
1083 static struct clk *clk_cpu_timer_parents[2] = { &pclk_cpu, &xin24m };
1085 static struct clk clk_timer0 = {
1088 .gate_idx = CLK_GATE_TIMER0,
1089 .clksel_con = CRU_CLKSEL6_CON,
1090 .clksel_parent_mask = 1,
1091 .clksel_parent_shift = 26,
1092 .parents = clk_cpu_timer_parents,
1095 static struct clk clk_timer1 = {
1098 .gate_idx = CLK_GATE_TIMER1,
1099 .clksel_con = CRU_CLKSEL6_CON,
1100 .clksel_parent_mask = 1,
1101 .clksel_parent_shift = 27,
1102 .parents = clk_cpu_timer_parents,
1105 static struct clk *clk_periph_timer_parents[2] = { &pclk_periph, &xin24m };
1107 static struct clk clk_timer2 = {
1110 .gate_idx = CLK_GATE_TIMER2,
1111 .clksel_con = CRU_CLKSEL6_CON,
1112 .clksel_parent_mask = 1,
1113 .clksel_parent_shift = 28,
1114 .parents = clk_periph_timer_parents,
1117 static struct clk clk_timer3 = {
1120 .gate_idx = CLK_GATE_TIMER3,
1121 .clksel_con = CRU_CLKSEL6_CON,
1122 .clksel_parent_mask = 1,
1123 .clksel_parent_shift = 29,
1124 .parents = clk_periph_timer_parents,
1128 static struct clk *clk_sdmmc_src_parents[4] = { &arm_pll_clk, &periph_pll_clk, &codec_pll_clk, &ddr_pll_clk };
1130 static struct clk clk_sdmmc_src = {
1131 .name = "sdmmc_src",
1132 .clksel_con = CRU_CLKSEL7_CON,
1133 .clksel_parent_mask = 3,
1134 .clksel_parent_shift = 0,
1135 .parents = clk_sdmmc_src_parents,
1138 static struct clk clk_sdmmc0 = {
1140 .parent = &clk_sdmmc_src,
1142 .recalc = clksel_recalc_div,
1143 .set_rate = clksel_set_rate_div,
1144 .gate_idx = CLK_GATE_SDMMC0,
1145 .clksel_con = CRU_CLKSEL7_CON,
1146 .clksel_mask = 0x3F,
1150 static struct clk clk_sdmmc1 = {
1152 .parent = &clk_sdmmc_src,
1154 .recalc = clksel_recalc_div,
1155 .set_rate = clksel_set_rate_div,
1156 .gate_idx = CLK_GATE_SDMMC1,
1157 .clksel_con = CRU_CLKSEL7_CON,
1158 .clksel_mask = 0x3F,
1162 static struct clk clk_emmc = {
1164 .parent = &clk_sdmmc_src,
1166 .recalc = clksel_recalc_div,
1167 .set_rate = clksel_set_rate_div,
1168 .gate_idx = CLK_GATE_EMMC,
1169 .clksel_con = CRU_CLKSEL7_CON,
1170 .clksel_mask = 0x3F,
1175 static struct clk *clk_ddr_parents[8] = { &ddr_pll_clk, &periph_pll_clk, &codec_pll_clk, &arm_pll_clk };
1177 static struct clk clk_ddr = {
1179 .recalc = clksel_recalc_shift,
1180 .clksel_con = CRU_CLKSEL7_CON,
1183 .clksel_maxdiv = 32,
1184 .clksel_parent_mask = 3,
1185 .clksel_parent_shift = 24,
1186 .parents = clk_ddr_parents,
1190 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
1194 struct clk *clk_div = clk->parents[0];
1197 case 24*MHZ: /* 1.5M/0.5M/50/75/150/200/300/600/1200/2400 */
1198 parent = clk->parents[2]; /* xin24m */
1210 parent = clk->parents[1]; /* frac div */
1211 /* reset div to 1 */
1212 ret = clk_set_rate_nolock(clk_div, clk_div->parent->rate);
1221 if (parent->set_rate) {
1222 ret = clk_set_rate_nolock(parent, rate);
1227 if (clk->parent != parent)
1228 clk_set_parent_nolock(clk, parent);
1233 static int clk_uart_frac_div_set_rate(struct clk *clk, unsigned long rate)
1235 u16 numerator, denominator;
1282 pr_debug("set clock %s to rate %ld (%d/%d)\n", clk->name, rate, numerator, denominator);
1283 cru_writel((u32)numerator << 16 | denominator, clk->clksel_con);
1287 static struct clk *clk_uart_src_parents[8] = { &periph_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
1289 static struct clk clk_uart01_src = {
1290 .name = "uart01_src",
1291 .clksel_con = CRU_CLKSEL8_CON,
1292 .clksel_parent_mask = 7,
1293 .clksel_parent_shift = 0,
1294 .parents = clk_uart_src_parents,
1297 static struct clk clk_uart0_div = {
1298 .name = "uart0_div",
1299 .parent = &clk_uart01_src,
1300 .recalc = clksel_recalc_div,
1301 .set_rate = clksel_set_rate_div,
1302 .clksel_con = CRU_CLKSEL8_CON,
1303 .clksel_mask = 0x3F,
1307 static struct clk clk_uart0_frac_div = {
1308 .name = "uart0_frac_div",
1309 .parent = &clk_uart0_div,
1310 .recalc = clksel_recalc_frac,
1311 .set_rate = clk_uart_frac_div_set_rate,
1312 .clksel_con = CRU_CLKSEL10_CON,
1315 static struct clk *clk_uart0_parents[4] = { &clk_uart0_div, &clk_uart0_frac_div, &xin24m };
1317 static struct clk clk_uart0 = {
1320 .set_rate = clk_uart_set_rate,
1321 .gate_idx = CLK_GATE_UART0,
1322 .clksel_con = CRU_CLKSEL8_CON,
1323 .clksel_parent_mask = 3,
1324 .clksel_parent_shift = 9,
1325 .parents = clk_uart0_parents,
1328 static struct clk clk_uart1_div = {
1329 .name = "uart1_div",
1330 .parent = &clk_uart01_src,
1331 .recalc = clksel_recalc_div,
1332 .set_rate = clksel_set_rate_div,
1333 .clksel_con = CRU_CLKSEL8_CON,
1334 .clksel_mask = 0x3F,
1338 static struct clk clk_uart1_frac_div = {
1339 .name = "uart1_frac_div",
1340 .parent = &clk_uart1_div,
1341 .recalc = clksel_recalc_frac,
1342 .set_rate = clk_uart_frac_div_set_rate,
1343 .clksel_con = CRU_CLKSEL11_CON,
1346 static struct clk *clk_uart1_parents[4] = { &clk_uart1_div, &clk_uart1_frac_div, &xin24m };
1348 static struct clk clk_uart1 = {
1351 .set_rate = clk_uart_set_rate,
1352 .gate_idx = CLK_GATE_UART1,
1353 .clksel_con = CRU_CLKSEL8_CON,
1354 .clksel_parent_mask = 3,
1355 .clksel_parent_shift = 20,
1356 .parents = clk_uart1_parents,
1359 static struct clk clk_uart23_src = {
1360 .name = "uart23_src",
1361 .clksel_con = CRU_CLKSEL9_CON,
1362 .clksel_parent_mask = 7,
1363 .clksel_parent_shift = 0,
1364 .parents = clk_uart_src_parents,
1367 static struct clk clk_uart2_div = {
1368 .name = "uart2_div",
1369 .parent = &clk_uart23_src,
1370 .recalc = clksel_recalc_div,
1371 .set_rate = clksel_set_rate_div,
1372 .clksel_con = CRU_CLKSEL9_CON,
1373 .clksel_mask = 0x3F,
1377 static struct clk clk_uart2_frac_div = {
1378 .name = "uart2_frac_div",
1379 .parent = &clk_uart2_div,
1380 .recalc = clksel_recalc_frac,
1381 .set_rate = clk_uart_frac_div_set_rate,
1382 .clksel_con = CRU_CLKSEL12_CON,
1385 static struct clk *clk_uart2_parents[4] = { &clk_uart2_div, &clk_uart2_frac_div, &xin24m };
1387 static struct clk clk_uart2 = {
1390 .set_rate = clk_uart_set_rate,
1391 .gate_idx = CLK_GATE_UART2,
1392 .clksel_con = CRU_CLKSEL9_CON,
1393 .clksel_parent_mask = 3,
1394 .clksel_parent_shift = 9,
1395 .parents = clk_uart2_parents,
1398 static struct clk clk_uart3_div = {
1399 .name = "uart3_div",
1400 .parent = &clk_uart23_src,
1401 .recalc = clksel_recalc_div,
1402 .set_rate = clksel_set_rate_div,
1403 .clksel_con = CRU_CLKSEL9_CON,
1404 .clksel_mask = 0x3F,
1408 static struct clk clk_uart3_frac_div = {
1409 .name = "uart3_frac_div",
1410 .parent = &clk_uart3_div,
1411 .recalc = clksel_recalc_frac,
1412 .set_rate = clk_uart_frac_div_set_rate,
1413 .clksel_con = CRU_CLKSEL13_CON,
1416 static struct clk *clk_uart3_parents[4] = { &clk_uart3_div, &clk_uart3_frac_div, &xin24m };
1418 static struct clk clk_uart3 = {
1421 .set_rate = clk_uart_set_rate,
1422 .gate_idx = CLK_GATE_UART3,
1423 .clksel_con = CRU_CLKSEL9_CON,
1424 .clksel_parent_mask = 3,
1425 .clksel_parent_shift = 20,
1426 .parents = clk_uart3_parents,
1430 static struct clk *clk_hsadc_div_parents[8] = { &codec_pll_clk, &ddr_pll_clk, &periph_pll_clk, &arm_pll_clk, &otgphy0_clkin, &otgphy1_clkin };
1432 static struct clk clk_hsadc_div = {
1433 .name = "hsadc_div",
1434 .recalc = clksel_recalc_div,
1435 .set_rate = clksel_set_rate_div,
1436 .clksel_con = CRU_CLKSEL14_CON,
1437 .clksel_mask = 0xFF,
1439 .clksel_parent_mask = 7,
1440 .clksel_parent_shift = 7,
1441 .parents = clk_hsadc_div_parents,
1444 static struct clk clk_hsadc_frac_div = {
1445 .name = "hsadc_frac_div",
1446 .parent = &clk_hsadc_div,
1447 .recalc = clksel_recalc_frac,
1448 .clksel_con = CRU_CLKSEL15_CON,
1451 static struct clk *clk_demod_parents[4] = { &clk_hsadc_div, &clk_hsadc_frac_div, &xin27m };
1453 static struct clk clk_demod = {
1455 .clksel_con = CRU_CLKSEL14_CON,
1456 .clksel_parent_mask = 3,
1457 .clksel_parent_shift = 18,
1458 .parents = clk_demod_parents,
1461 static struct clk gpsclk = {
1465 static struct clk *clk_hsadc_parents[2] = { &clk_demod, &gpsclk };
1467 static struct clk clk_hsadc = {
1470 .gate_idx = CLK_GATE_HSADC,
1471 .clksel_con = CRU_CLKSEL14_CON,
1472 .clksel_parent_mask = 1,
1473 .clksel_parent_shift = 21,
1474 .parents = clk_hsadc_parents,
1477 static unsigned long div2_recalc(struct clk *clk)
1479 return clk->parent->rate >> 1;
1482 static struct clk clk_hsadc_div2 = {
1483 .name = "hsadc_div2",
1484 .parent = &clk_demod,
1485 .recalc = div2_recalc,
1488 static struct clk clk_hsadc_div2_inv = {
1489 .name = "hsadc_div2_inv",
1490 .parent = &clk_demod,
1491 .recalc = div2_recalc,
1494 static struct clk *clk_hsadc_out_parents[2] = { &clk_hsadc_div2, &clk_hsadc_div2_inv };
1496 static struct clk clk_hsadc_out = {
1497 .name = "hsadc_out",
1498 .clksel_con = CRU_CLKSEL14_CON,
1499 .clksel_parent_mask = 1,
1500 .clksel_parent_shift = 20,
1501 .parents = clk_hsadc_out_parents,
1505 static struct clk *dclk_lcdc_div_parents[4] = { &codec_pll_clk, &ddr_pll_clk, &periph_pll_clk, &arm_pll_clk };
1507 static struct clk dclk_lcdc_div = {
1508 .name = "dclk_lcdc_div",
1509 .recalc = clksel_recalc_div,
1510 .set_rate = clksel_set_rate_div,
1511 .clksel_con = CRU_CLKSEL16_CON,
1512 .clksel_mask = 0xFF,
1514 .clksel_parent_mask = 3,
1515 .clksel_parent_shift = 0,
1516 .parents = dclk_lcdc_div_parents,
1519 static struct clk *dclk_lcdc_parents[2] = { &dclk_lcdc_div, &xin27m };
1521 static struct clk dclk_lcdc = {
1522 .name = "dclk_lcdc",
1524 .gate_idx = CLK_GATE_LCDC,
1525 .clksel_con = CRU_CLKSEL16_CON,
1526 .clksel_parent_mask = 1,
1527 .clksel_parent_shift = 10,
1528 .parents = dclk_lcdc_parents,
1531 static struct clk dclk_ebook = {
1532 .name = "dclk_ebook",
1534 .gate_idx = CLK_GATE_EBOOK,
1535 .recalc = clksel_recalc_div,
1536 .set_rate = clksel_set_rate_div,
1537 .clksel_con = CRU_CLKSEL16_CON,
1538 .clksel_mask = 0x1F,
1540 .clksel_parent_mask = 3,
1541 .clksel_parent_shift = 11,
1542 .parents = dclk_lcdc_div_parents,
1545 static struct clk *aclk_lcdc_parents[4] = { &ddr_pll_clk, &codec_pll_clk, &periph_pll_clk, &arm_pll_clk };
1547 static struct clk aclk_lcdc = {
1548 .name = "aclk_lcdc",
1550 .gate_idx = CLK_GATE_LCDC_AXI,
1551 .recalc = clksel_recalc_div,
1552 .set_rate = clksel_set_rate_div,
1553 .clksel_con = CRU_CLKSEL16_CON,
1554 .clksel_mask = 0x1F,
1556 .clksel_parent_mask = 3,
1557 .clksel_parent_shift = 18,
1558 .parents = aclk_lcdc_parents,
1561 static struct clk hclk_lcdc = {
1562 .name = "hclk_lcdc",
1564 .gate_idx = CLK_GATE_LCDC_AHB,
1565 .parent = &aclk_lcdc,
1566 .clksel_con = CRU_CLKSEL16_CON,
1567 .recalc = clksel_recalc_shift,
1568 .set_rate = clksel_set_rate_shift,
1574 static struct clk *xpu_parents[4] = { &periph_pll_clk, &ddr_pll_clk, &codec_pll_clk, &arm_pll_clk };
1576 static struct clk aclk_vepu = {
1577 .name = "aclk_vepu",
1579 .recalc = clksel_recalc_div,
1580 .set_rate = clksel_set_rate_div,
1581 .gate_idx = CLK_GAET_VEPU_AXI,
1582 .clksel_con = CRU_CLKSEL17_CON,
1583 .clksel_mask = 0x1F,
1585 .clksel_parent_mask = 3,
1586 .clksel_parent_shift = 0,
1587 .parents = xpu_parents,
1590 static struct clk hclk_vepu = {
1591 .name = "hclk_vepu",
1592 .parent = &aclk_vepu,
1594 .recalc = clksel_recalc_shift,
1595 .set_rate = clksel_set_rate_shift,
1596 .gate_idx = CLK_GATE_VEPU_AHB,
1597 .clksel_con = CRU_CLKSEL17_CON,
1603 static struct clk aclk_vdpu = {
1604 .name = "aclk_vdpu",
1605 .parent = &periph_pll_clk,
1607 .recalc = clksel_recalc_div,
1608 .set_rate = clksel_set_rate_div,
1609 .gate_idx = CLK_GATE_VDPU_AXI,
1610 .clksel_con = CRU_CLKSEL17_CON,
1611 .clksel_mask = 0x1F,
1613 .clksel_parent_mask = 3,
1614 .clksel_parent_shift = 7,
1615 .parents = xpu_parents,
1618 static struct clk hclk_vdpu = {
1619 .name = "hclk_vdpu",
1620 .parent = &aclk_vdpu,
1622 .recalc = clksel_recalc_shift,
1623 .set_rate = clksel_set_rate_shift,
1624 .gate_idx = CLK_GATE_VDPU_AHB,
1625 .clksel_con = CRU_CLKSEL17_CON,
1631 static struct clk clk_gpu = {
1634 .gate_idx = CLK_GATE_GPU,
1635 .recalc = clksel_recalc_div,
1636 .set_rate = clksel_set_rate_div,
1637 .clksel_con = CRU_CLKSEL17_CON,
1638 .clksel_mask = 0x1F,
1640 .clksel_parent_mask = 3,
1641 .clksel_parent_shift = 14,
1642 .parents = xpu_parents,
1645 static struct clk aclk_gpu = {
1648 .gate_idx = CLK_GATE_GPU_AXI,
1649 .recalc = clksel_recalc_div,
1650 .set_rate = clksel_set_rate_div,
1651 .clksel_con = CRU_CLKSEL17_CON,
1652 .clksel_mask = 0x1F,
1654 .clksel_parent_mask = 3,
1655 .clksel_parent_shift = 21,
1656 .parents = xpu_parents,
1660 static struct clk *clk_vip_parents[4] = { &xin24m, &xin27m, &dclk_ebook };
1662 static struct clk clk_vip = {
1665 .gate_idx = CLK_GATE_VIP,
1666 .clksel_con = CRU_CLKSEL1_CON,
1667 .clksel_parent_mask = 3,
1668 .clksel_parent_shift = 7,
1669 .parents = clk_vip_parents,
1673 #define GATE_CLK(NAME,PARENT,ID) \
1674 static struct clk clk_##NAME = { \
1676 .parent = &PARENT, \
1677 .mode = gate_mode, \
1678 .gate_idx = CLK_GATE_##ID, \
1681 GATE_CLK(i2c0, pclk_cpu, I2C0);
1682 GATE_CLK(i2c1, pclk_periph, I2C1);
1683 GATE_CLK(i2c2, pclk_periph, I2C2);
1684 GATE_CLK(i2c3, pclk_periph, I2C3);
1686 GATE_CLK(gpio0, pclk_cpu, GPIO0);
1687 GATE_CLK(gpio1, pclk_periph, GPIO1);
1688 GATE_CLK(gpio2, pclk_periph, GPIO2);
1689 GATE_CLK(gpio3, pclk_periph, GPIO3);
1690 GATE_CLK(gpio4, pclk_cpu, GPIO4);
1691 GATE_CLK(gpio5, pclk_periph, GPIO5);
1692 GATE_CLK(gpio6, pclk_cpu, GPIO6);
1694 GATE_CLK(dma0, aclk_cpu, DMA0);
1695 GATE_CLK(dma1, aclk_periph, DMA1);
1696 GATE_CLK(dma2, aclk_periph, DMA2);
1698 GATE_CLK(gic, aclk_cpu, GIC);
1699 GATE_CLK(imem, aclk_cpu, IMEM);
1700 GATE_CLK(ebrom, hclk_cpu, EBROM);
1701 GATE_CLK(ddr_phy, aclk_cpu, DDR_PHY);
1702 GATE_CLK(ddr_reg, aclk_cpu, DDR_REG);
1703 GATE_CLK(ddr_cpu, aclk_cpu, DDR_CPU);
1704 GATE_CLK(efuse, pclk_cpu, EFUSE);
1705 GATE_CLK(tzpc, pclk_cpu, TZPC);
1706 GATE_CLK(debug, pclk_cpu, DEBUG);
1707 GATE_CLK(tpiu, pclk_cpu, TPIU);
1708 GATE_CLK(rtc, pclk_cpu, RTC);
1709 GATE_CLK(pmu, pclk_cpu, PMU);
1710 GATE_CLK(grf, pclk_cpu, GRF);
1712 GATE_CLK(emem, hclk_periph, EMEM);
1713 GATE_CLK(usb, hclk_periph, USB);
1714 GATE_CLK(ddr_periph, aclk_periph, DDR_PERIPH);
1715 GATE_CLK(periph_cpu, aclk_cpu, PERIPH_CPU);
1716 GATE_CLK(smc_axi, aclk_periph, SMC_AXI);
1717 GATE_CLK(smc, pclk_periph, SMC);
1718 GATE_CLK(mac_ahb, hclk_periph, MAC_AHB);
1719 GATE_CLK(mac_tx, hclk_periph, MAC_TX);
1720 GATE_CLK(mac_rx, hclk_periph, MAC_RX);
1721 GATE_CLK(hif, hclk_periph, HIF);
1722 GATE_CLK(nandc, hclk_periph, NANDC);
1723 GATE_CLK(hsadc_ahb, hclk_periph, HSADC_AHB);
1724 GATE_CLK(usbotg0, hclk_periph, USBOTG0);
1725 GATE_CLK(usbotg1, hclk_periph, USBOTG1);
1726 GATE_CLK(uhost_ahb, hclk_periph, UHOST_AHB);
1727 GATE_CLK(pid_filter, hclk_periph, PID_FILTER);
1729 GATE_CLK(vip_slave, hclk_cpu, VIP_SLAVE);
1730 GATE_CLK(wdt, pclk_periph, WDT);
1731 GATE_CLK(pwm, pclk_periph, PWM);
1732 GATE_CLK(vip_bus, aclk_cpu, VIP_BUS);
1733 GATE_CLK(vip_matrix, hclk_cpu, VIP_MATRIX);
1734 GATE_CLK(vip_input, hclk_cpu, VIP_INPUT);
1735 GATE_CLK(jtag, aclk_cpu, JTAG);
1737 GATE_CLK(ddr_lcdc_axi, aclk_cpu, DDR_LCDC_AXI);
1738 GATE_CLK(ipp_axi, aclk_cpu, IPP_AXI);
1739 GATE_CLK(ipp_ahb, hclk_cpu, IPP_AHB);
1740 GATE_CLK(ebook_ahb, hclk_cpu, EBOOK_AHB);
1741 GATE_CLK(display_matrix_axi, aclk_cpu, DISPLAY_MATRIX_AXI);
1742 GATE_CLK(display_matrix_ahb, hclk_cpu, DISPLAY_MATRIX_AHB);
1743 GATE_CLK(ddr_vepu_axi, aclk_cpu, DDR_VEPU_AXI);
1744 GATE_CLK(ddr_vdpu_axi, aclk_cpu, DDR_VDPU_AXI);
1745 GATE_CLK(ddr_gpu_axi, aclk_cpu, DDR_GPU_AXI);
1746 GATE_CLK(gpu_ahb, hclk_cpu, GPU_AHB);
1747 GATE_CLK(cpu_vcodec_ahb, hclk_cpu, CPU_VCODEC_AHB);
1748 GATE_CLK(cpu_display_ahb, hclk_cpu, CPU_DISPLAY_AHB);
1750 GATE_CLK(sdmmc0_ahb, hclk_periph, SDMMC0_AHB);
1751 GATE_CLK(sdmmc1_ahb, hclk_periph, SDMMC1_AHB);
1752 GATE_CLK(emmc_ahb, hclk_periph, EMMC_AHB);
1754 #define CLK(dev, con, ck) \
1761 #define CLK1(name) \
1765 .clk = &clk_##name, \
1768 static struct clk_lookup clks[] = {
1769 CLK(NULL, "xin24m", &xin24m),
1770 CLK(NULL, "xin27m", &xin27m),
1771 CLK(NULL, "otgphy0_clkin", &otgphy0_clkin),
1772 CLK(NULL, "otgphy1_clkin", &otgphy1_clkin),
1773 CLK(NULL, "gpsclk", &gpsclk),
1776 CLK(NULL, "arm_pll", &arm_pll_clk),
1777 CLK(NULL, "ddr_pll", &ddr_pll_clk),
1778 CLK(NULL, "codec_pll", &codec_pll_clk),
1779 CLK(NULL, "periph_pll", &periph_pll_clk),
1782 CLK(NULL, "aclk_cpu", &aclk_cpu),
1783 CLK(NULL, "hclk_cpu", &hclk_cpu),
1784 CLK(NULL, "pclk_cpu", &pclk_cpu),
1786 CLK(NULL, "aclk_periph", &aclk_periph),
1787 CLK(NULL, "hclk_periph", &hclk_periph),
1788 CLK(NULL, "pclk_periph", &pclk_periph),
1791 CLK("rk29_otgphy.0", "otgphy", &clk_otgphy0),
1792 CLK("rk29_otgphy.1", "otgphy", &clk_otgphy1),
1793 CLK(NULL, "uhost", &clk_uhost),
1794 CLK(NULL, "mac_ref_div", &clk_mac_ref_div),
1795 CLK(NULL, "mac_ref", &clk_mac_ref),
1797 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
1798 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
1799 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
1800 CLK("rk29_i2s.1", "i2s_div", &clk_i2s1_div),
1801 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s1_frac_div),
1802 CLK("rk29_i2s.1", "i2s", &clk_i2s1),
1803 CLK(NULL, "spdif_div", &clk_spdif_div),
1804 CLK(NULL, "spdif_frac_div", &clk_spdif_frac_div),
1805 CLK(NULL, "spdif", &clk_spdif),
1808 CLK("rk29xx_spim.0", "spi0", &clk_spi0),
1809 CLK("rk29xx_spim.1", "spi1", &clk_spi1),
1818 CLK("rk29_sdmmc.0", "sdmmc", &clk_sdmmc0),
1819 CLK("rk29_sdmmc.0", "sdmmc_ahb", &clk_sdmmc0_ahb),
1820 CLK("rk29_sdmmc.1", "sdmmc", &clk_sdmmc1),
1821 CLK("rk29_sdmmc.1", "sdmmc_ahb", &clk_sdmmc1_ahb),
1827 CLK("rk29_serial.0", "uart", &clk_uart0),
1828 CLK("rk29_serial.0", "uart_div", &clk_uart0_div),
1829 CLK("rk29_serial.0", "uart_frac_div", &clk_uart0_frac_div),
1830 CLK("rk29_serial.1", "uart", &clk_uart1),
1831 CLK("rk29_serial.1", "uart_div", &clk_uart1_div),
1832 CLK("rk29_serial.1", "uart_frac_div", &clk_uart1_frac_div),
1835 CLK("rk29_serial.2", "uart", &clk_uart2),
1836 CLK("rk29_serial.2", "uart_div", &clk_uart2_div),
1837 CLK("rk29_serial.2", "uart_frac_div", &clk_uart2_frac_div),
1838 CLK("rk29_serial.3", "uart", &clk_uart3),
1839 CLK("rk29_serial.3", "uart_div", &clk_uart3_div),
1840 CLK("rk29_serial.3", "uart_frac_div", &clk_uart3_frac_div),
1843 CLK1(hsadc_frac_div),
1847 CLK1(hsadc_div2_inv),
1850 CLK(NULL, "dclk_lcdc_div", &dclk_lcdc_div),
1851 CLK(NULL, "dclk_lcdc", &dclk_lcdc),
1852 CLK(NULL, "dclk_ebook", &dclk_ebook),
1853 CLK(NULL, "aclk_lcdc", &aclk_lcdc),
1854 CLK(NULL, "hclk_lcdc", &hclk_lcdc),
1856 CLK(NULL, "aclk_vepu", &aclk_vepu),
1857 CLK(NULL, "hclk_vepu", &hclk_vepu),
1858 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
1859 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
1861 CLK(NULL, "aclk_gpu", &aclk_gpu),
1863 CLK("rk29_i2c.0", "i2c", &clk_i2c0),
1864 CLK("rk29_i2c.1", "i2c", &clk_i2c1),
1865 CLK("rk29_i2c.2", "i2c", &clk_i2c2),
1866 CLK("rk29_i2c.3", "i2c", &clk_i2c3),
1923 CLK1(display_matrix_axi),
1924 CLK1(display_matrix_ahb),
1929 CLK1(cpu_vcodec_ahb),
1930 CLK1(cpu_display_ahb),
1933 static LIST_HEAD(clocks);
1934 static DEFINE_MUTEX(clocks_mutex);
1935 static DEFINE_SPINLOCK(clockfw_lock);
1936 #define LOCK() do { WARN_ON(in_irq()); if (!irqs_disabled()) spin_lock_bh(&clockfw_lock); } while (0)
1937 #define UNLOCK() do { if (!irqs_disabled()) spin_unlock_bh(&clockfw_lock); } while (0)
1939 static int clk_enable_nolock(struct clk *clk)
1943 if (clk->usecount == 0) {
1945 ret = clk_enable_nolock(clk->parent);
1951 ret = clk->mode(clk, 1);
1954 clk_disable_nolock(clk->parent);
1958 pr_debug("%s enabled\n", clk->name);
1965 int clk_enable(struct clk *clk)
1969 if (clk == NULL || IS_ERR(clk))
1973 ret = clk_enable_nolock(clk);
1978 EXPORT_SYMBOL(clk_enable);
1980 static void clk_disable_nolock(struct clk *clk)
1982 if (clk->usecount == 0) {
1983 printk(KERN_ERR "Trying disable clock %s with 0 usecount\n", clk->name);
1988 if (--clk->usecount == 0) {
1991 pr_debug("%s disabled\n", clk->name);
1993 clk_disable_nolock(clk->parent);
1997 void clk_disable(struct clk *clk)
1999 if (clk == NULL || IS_ERR(clk))
2003 clk_disable_nolock(clk);
2006 EXPORT_SYMBOL(clk_disable);
2008 unsigned long clk_get_rate(struct clk *clk)
2010 if (clk == NULL || IS_ERR(clk))
2015 EXPORT_SYMBOL(clk_get_rate);
2017 /*-------------------------------------------------------------------------
2018 * Optional clock functions defined in include/linux/clk.h
2019 *-------------------------------------------------------------------------*/
2021 /* Given a clock and a rate apply a clock specific rounding function */
2022 static long clk_round_rate_nolock(struct clk *clk, unsigned long rate)
2024 if (clk->round_rate)
2025 return clk->round_rate(clk, rate);
2027 if (clk->flags & RATE_FIXED)
2028 printk(KERN_ERR "clock: clk_round_rate called on fixed-rate clock %s\n", clk->name);
2033 long clk_round_rate(struct clk *clk, unsigned long rate)
2037 if (clk == NULL || IS_ERR(clk))
2041 ret = clk_round_rate_nolock(clk, rate);
2046 EXPORT_SYMBOL(clk_round_rate);
2048 static void __clk_recalc(struct clk *clk)
2050 if (unlikely(clk->flags & RATE_FIXED))
2053 clk->rate = clk->recalc(clk);
2054 else if (clk->parent)
2055 clk->rate = clk->parent->rate;
2056 pr_debug("%s new clock rate is %lu\n", clk->name, clk->rate);
2059 static int clk_set_rate_nolock(struct clk *clk, unsigned long rate)
2063 if (rate == clk->rate)
2066 pr_debug("set_rate for clock %s to rate %ld\n", clk->name, rate);
2068 if (clk->flags & CONFIG_PARTICIPANT)
2074 ret = clk->set_rate(clk, rate);
2078 __propagate_rate(clk);
2084 /* Set the clock rate for a clock source */
2085 int clk_set_rate(struct clk *clk, unsigned long rate)
2089 if (clk == NULL || IS_ERR(clk))
2093 ret = clk_set_rate_nolock(clk, rate);
2098 EXPORT_SYMBOL(clk_set_rate);
2100 static int clk_set_parent_nolock(struct clk *clk, struct clk *parent)
2103 int enabled = clk->usecount > 0;
2104 struct clk *old_parent = clk->parent;
2106 if (clk->parent == parent)
2109 /* if clk is already enabled, enable new parent first and disable old parent later. */
2111 clk_enable_nolock(parent);
2113 if (clk->set_parent)
2114 ret = clk->set_parent(clk, parent);
2116 ret = clksel_set_parent(clk, parent);
2120 __clk_reparent(clk, parent);
2122 __propagate_rate(clk);
2124 clk_disable_nolock(old_parent);
2127 clk_disable_nolock(parent);
2133 int clk_set_parent(struct clk *clk, struct clk *parent)
2137 if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent))
2140 if (clk->set_parent == NULL && clk->parents == NULL)
2144 if (clk->usecount == 0)
2145 ret = clk_set_parent_nolock(clk, parent);
2152 EXPORT_SYMBOL(clk_set_parent);
2154 struct clk *clk_get_parent(struct clk *clk)
2158 EXPORT_SYMBOL(clk_get_parent);
2160 static void __clk_reparent(struct clk *child, struct clk *parent)
2162 if (child->parent == parent)
2164 pr_debug("%s reparent to %s (was %s)\n", child->name, parent->name, ((child->parent) ? child->parent->name : "NULL"));
2166 list_del_init(&child->sibling);
2168 list_add(&child->sibling, &parent->children);
2169 child->parent = parent;
2172 /* Propagate rate to children */
2173 static void __propagate_rate(struct clk *tclk)
2177 list_for_each_entry(clkp, &tclk->children, sibling) {
2179 __propagate_rate(clkp);
2183 static LIST_HEAD(root_clks);
2186 * recalculate_root_clocks - recalculate and propagate all root clocks
2188 * Recalculates all root clocks (clocks with no parent), which if the
2189 * clock's .recalc is set correctly, should also propagate their rates.
2192 static void clk_recalculate_root_clocks_nolock(void)
2196 list_for_each_entry(clkp, &root_clks, sibling) {
2198 __propagate_rate(clkp);
2202 void clk_recalculate_root_clocks(void)
2205 clk_recalculate_root_clocks_nolock();
2211 * clk_preinit - initialize any fields in the struct clk before clk init
2212 * @clk: struct clk * to initialize
2214 * Initialize any struct clk fields needed before normal clk initialization
2215 * can run. No return value.
2217 static void clk_preinit(struct clk *clk)
2219 INIT_LIST_HEAD(&clk->children);
2222 static int clk_register(struct clk *clk)
2224 if (clk == NULL || IS_ERR(clk))
2228 * trap out already registered clocks
2230 if (clk->node.next || clk->node.prev)
2233 mutex_lock(&clocks_mutex);
2235 if (clk->get_parent)
2236 clk->parent = clk->get_parent(clk);
2237 else if (clk->parents)
2238 clk->parent = clksel_get_parent(clk);
2241 list_add(&clk->sibling, &clk->parent->children);
2243 list_add(&clk->sibling, &root_clks);
2245 list_add(&clk->node, &clocks);
2247 mutex_unlock(&clocks_mutex);
2252 static void clk_enable_init_clocks(void)
2256 list_for_each_entry(clkp, &clocks, node) {
2257 if (clkp->flags & ENABLE_ON_INIT)
2262 static void rk29_clock_common_init(void)
2265 clk_set_rate_nolock(&periph_pll_clk, 624 * MHZ);
2266 clk_set_parent_nolock(&aclk_periph, &periph_pll_clk);
2267 clk_set_rate_nolock(&aclk_periph, 208 * MHZ);
2268 clk_set_rate_nolock(&hclk_periph, 104 * MHZ);
2269 clk_set_rate_nolock(&pclk_periph, 52 * MHZ);
2270 clk_set_parent_nolock(&clk_uhost, &periph_pll_clk);
2271 clk_set_rate_nolock(&clk_uhost, 48 * MHZ);
2272 clk_set_parent_nolock(&clk_i2s0_div, &periph_pll_clk);
2273 clk_set_parent_nolock(&clk_i2s1_div, &periph_pll_clk);
2274 clk_set_parent_nolock(&clk_spdif_div, &periph_pll_clk);
2275 clk_set_parent_nolock(&clk_spi_src, &periph_pll_clk);
2276 clk_set_parent_nolock(&clk_sdmmc_src, &periph_pll_clk);
2277 clk_set_parent_nolock(&clk_uart01_src, &periph_pll_clk);
2278 clk_set_parent_nolock(&clk_uart23_src, &periph_pll_clk);
2279 clk_set_parent_nolock(&dclk_lcdc_div, &periph_pll_clk);
2280 clk_set_parent_nolock(&aclk_lcdc, &periph_pll_clk);
2281 clk_set_parent_nolock(&aclk_vepu, &periph_pll_clk);
2282 clk_set_parent_nolock(&aclk_vdpu, &periph_pll_clk);
2283 clk_set_parent_nolock(&clk_gpu, &periph_pll_clk);
2284 clk_set_parent_nolock(&aclk_gpu, &periph_pll_clk);
2285 clk_set_parent_nolock(&clk_mac_ref_div, &periph_pll_clk);
2286 clk_set_parent_nolock(&clk_hsadc_div, &periph_pll_clk);
2289 clk_set_rate_nolock(&arm_pll_clk, 624 * MHZ);
2292 void __init rk29_clock_init(void)
2294 struct clk_lookup *lk;
2296 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++)
2297 clk_preinit(lk->clk);
2299 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
2301 clk_register(lk->clk);
2304 clk_recalculate_root_clocks_nolock();
2306 rk29_clock_common_init();
2308 printk(KERN_INFO "Clocking rate (apll/dpll/cpll/ppll/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",
2309 arm_pll_clk.rate / MHZ, ddr_pll_clk.rate / MHZ, codec_pll_clk.rate / MHZ, periph_pll_clk.rate / MHZ, clk_core.rate / MHZ,
2310 aclk_cpu.rate / MHZ, hclk_cpu.rate / MHZ, pclk_cpu.rate / MHZ, aclk_periph.rate / MHZ, hclk_periph.rate / MHZ, pclk_periph.rate / MHZ);
2313 * Only enable those clocks we will need, let the drivers
2314 * enable other clocks as necessary
2316 clk_enable_init_clocks();
2319 #ifdef CONFIG_PROC_FS
2320 #include <linux/proc_fs.h>
2321 #include <linux/seq_file.h>
2323 static void dump_clock(struct seq_file *s, struct clk *clk, int deep)
2327 unsigned long rate = clk->rate;
2329 for (i = 0; i < deep; i++)
2332 seq_printf(s, "%-9s ", clk->name);
2334 if (clk->mode && (clk->gate_idx < CLK_GATE_MAX)) {
2336 int idx = clk->gate_idx;
2339 reg = CRU_CLKGATE0_CON;
2340 reg += (idx >> 5) << 2;
2343 v = cru_readl(reg) & (1 << idx);
2345 seq_printf(s, "%s ", v ? "off" : "on ");
2350 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
2352 seq_printf(s, "%ld MHz", rate / MHZ);
2353 } else if (rate >= KHZ) {
2355 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
2357 seq_printf(s, "%ld KHz", rate / KHZ);
2359 seq_printf(s, "%ld Hz", rate);
2362 seq_printf(s, " usecount = %d", clk->usecount);
2364 seq_printf(s, " parent = %s\n", clk->parent ? clk->parent->name : "NULL");
2366 list_for_each_entry(ck, &clocks, node) {
2367 if (ck->parent == clk)
2368 dump_clock(s, ck, deep + 1);
2372 static int proc_clk_show(struct seq_file *s, void *v)
2376 mutex_lock(&clocks_mutex);
2377 list_for_each_entry(clk, &clocks, node) {
2379 dump_clock(s, clk, 0);
2381 mutex_unlock(&clocks_mutex);
2383 seq_printf(s, "\nRegisters:\n");
2384 seq_printf(s, "APLL : 0x%08x\n", cru_readl(CRU_APLL_CON));
2385 seq_printf(s, "DPLL : 0x%08x\n", cru_readl(CRU_DPLL_CON));
2386 seq_printf(s, "CPLL : 0x%08x\n", cru_readl(CRU_CPLL_CON));
2387 seq_printf(s, "PPLL : 0x%08x\n", cru_readl(CRU_PPLL_CON));
2388 seq_printf(s, "MODE : 0x%08x\n", cru_readl(CRU_MODE_CON));
2389 seq_printf(s, "CLKSEL0 : 0x%08x\n", cru_readl(CRU_CLKSEL0_CON));
2390 seq_printf(s, "CLKSEL1 : 0x%08x\n", cru_readl(CRU_CLKSEL1_CON));
2391 seq_printf(s, "CLKSEL2 : 0x%08x\n", cru_readl(CRU_CLKSEL2_CON));
2392 seq_printf(s, "CLKSEL3 : 0x%08x\n", cru_readl(CRU_CLKSEL3_CON));
2393 seq_printf(s, "CLKSEL4 : 0x%08x\n", cru_readl(CRU_CLKSEL4_CON));
2394 seq_printf(s, "CLKSEL5 : 0x%08x\n", cru_readl(CRU_CLKSEL5_CON));
2395 seq_printf(s, "CLKSEL6 : 0x%08x\n", cru_readl(CRU_CLKSEL6_CON));
2396 seq_printf(s, "CLKSEL7 : 0x%08x\n", cru_readl(CRU_CLKSEL7_CON));
2397 seq_printf(s, "CLKSEL8 : 0x%08x\n", cru_readl(CRU_CLKSEL8_CON));
2398 seq_printf(s, "CLKSEL9 : 0x%08x\n", cru_readl(CRU_CLKSEL9_CON));
2399 seq_printf(s, "CLKSEL10 : 0x%08x\n", cru_readl(CRU_CLKSEL10_CON));
2400 seq_printf(s, "CLKSEL11 : 0x%08x\n", cru_readl(CRU_CLKSEL11_CON));
2401 seq_printf(s, "CLKSEL12 : 0x%08x\n", cru_readl(CRU_CLKSEL12_CON));
2402 seq_printf(s, "CLKSEL13 : 0x%08x\n", cru_readl(CRU_CLKSEL13_CON));
2403 seq_printf(s, "CLKSEL14 : 0x%08x\n", cru_readl(CRU_CLKSEL14_CON));
2404 seq_printf(s, "CLKSEL15 : 0x%08x\n", cru_readl(CRU_CLKSEL15_CON));
2405 seq_printf(s, "CLKSEL16 : 0x%08x\n", cru_readl(CRU_CLKSEL16_CON));
2406 seq_printf(s, "CLKSEL17 : 0x%08x\n", cru_readl(CRU_CLKSEL17_CON));
2407 seq_printf(s, "CLKGATE0 : 0x%08x\n", cru_readl(CRU_CLKGATE0_CON));
2408 seq_printf(s, "CLKGATE1 : 0x%08x\n", cru_readl(CRU_CLKGATE1_CON));
2409 seq_printf(s, "CLKGATE2 : 0x%08x\n", cru_readl(CRU_CLKGATE2_CON));
2410 seq_printf(s, "CLKGATE3 : 0x%08x\n", cru_readl(CRU_CLKGATE3_CON));
2415 static int proc_clk_open(struct inode *inode, struct file *file)
2417 return single_open(file, proc_clk_show, NULL);
2420 static const struct file_operations proc_clk_fops = {
2421 .open = proc_clk_open,
2423 .llseek = seq_lseek,
2424 .release = single_release,
2427 static int __init clk_proc_init(void)
2429 proc_create("clocks", 0, NULL, &proc_clk_fops);
2433 late_initcall(clk_proc_init);
2434 #endif /* CONFIG_PROC_FS */