1 /* linux/arch/arm/mach-rk30/clock_data.c
3 * Copyright (C) 2012 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.
15 #include <linux/clk.h>
16 #include <linux/clkdev.h>
17 #include <linux/err.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
22 #include <linux/delay.h>
23 #include <linux/hardirq.h>
25 #include <mach/iomux.h>
26 #include <mach/clock.h>
28 #include <mach/dvfs.h>
31 #define MHZ (1000*1000)
33 #define CLK_LOOPS_JIFFY_REF 11996091ULL
34 #define CLK_LOOPS_RATE_REF (1200) //Mhz
35 #define CLK_LOOPS_RECALC(new_rate) div_u64(CLK_LOOPS_JIFFY_REF*(new_rate),CLK_LOOPS_RATE_REF*MHZ)
36 void rk30_clk_dump_regs(void);
40 #define CLK_FLG_EXT_27MHZ (1<<0)
42 #define CLK_FLG_MAX_I2S_12288KHZ (1<<1)
43 #define CLK_FLG_MAX_I2S_22579_2KHZ (1<<2)
44 #define CLK_FLG_MAX_I2S_24576KHZ (1<<3)
45 #define CLK_FLG_MAX_I2S_49152KHZ (1<<4)
47 #define CLK_FLG_UART_1_3M (1<<5)
55 u32 pllcon2; //nb=bwadj+1;0:11;nb=nf/2
65 u32 pllcon2; //nb=bwadj+1;0:11;nb=nf/2
69 #define SET_PLL_DATA(_pll_id,_table) \
76 #define _PLL_SET_CLKS(_mhz, nr, nf, no) \
78 .rate = (_mhz) * KHZ, \
79 .pllcon0 = PLL_CLKR_SET(nr)|PLL_CLKOD_SET(no), \
80 .pllcon1 = PLL_CLKF_SET(nf),\
81 .rst_dly=((nr*500)/24+1),\
85 #define _APLL_SET_LPJ(_mhz) \
86 .lpj= (CLK_LOOPS_JIFFY_REF * _mhz)/CLK_LOOPS_RATE_REF
89 #define _APLL_SET_CLKS(_mhz, nr, nf, no, _periph_div, _axi_core_div,\
90 _axi_div,_ahb_div, _apb_div,_ahb2apb) \
93 .pllcon0 = PLL_CLKR_SET(nr) | PLL_CLKOD_SET(no), \
94 .pllcon1 = PLL_CLKF_SET(nf),\
95 .clksel0 = CORE_PERIPH_W_MSK | CORE_PERIPH_##_periph_div,\
96 .clksel1 = CORE_ACLK_W_MSK | CORE_ACLK_##_axi_core_div,\
98 .rst_dly=((nr*500)/24+1),\
101 #define CRU_DIV_SET(mask,shift,max) \
107 #define CRU_SRC_SET(mask,shift ) \
111 #define CRU_PARENTS_SET(parents_array) \
112 .parents=(parents_array),\
113 .parents_num=ARRAY_SIZE((parents_array))
115 #define CRU_GATE_MODE_SET(_func,_IDX) \
126 #define GATE_CLK(NAME,PARENT,ID) \
127 static struct clk clk_##NAME = { \
131 .gate_idx = CLK_GATE_##ID, \
133 #ifdef RK30_CLK_OFFBOARD_TEST
134 u32 TEST_GRF_REG[0x240];
135 u32 TEST_CRU_REG[0x240];
136 #define cru_readl(offset) (TEST_CRU_REG[offset/4])
138 u32 cru_writel_is_pr(u32 offset)
140 return (offset == 0x4000);
142 void cru_writel(u32 v, u32 offset)
145 u32 mask_v = v >> 16;
146 TEST_CRU_REG[offset/4] &= (~mask_v);
150 TEST_CRU_REG[offset/4] |= v;
151 TEST_CRU_REG[offset/4] &= 0x0000ffff;
153 if(cru_writel_is_pr(offset)) {
154 CLKDATA_DBG("cru w offset=%d,set=%x,reg=%x\n", offset, v, TEST_CRU_REG[offset/4]);
159 void cru_writel_i2s(u32 v, u32 offset)
161 TEST_CRU_REG[offset/4] = v;
163 #define cru_writel_frac(v,offset) cru_writel_i2s((v),(offset))
165 #define regfile_readl(offset) (0xffffffff)
166 //#define pmu_readl(offset) readl(RK30_GRF_BASE + offset)
167 void rk30_clkdev_add(struct clk_lookup *cl);
169 #define regfile_readl(offset) readl_relaxed(RK30_GRF_BASE + offset)
170 #define regfile_writel(v, offset) do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
171 #define cru_readl(offset) readl_relaxed(RK30_CRU_BASE + offset)
172 #define cru_writel(v, offset) do { writel_relaxed(v, RK30_CRU_BASE + offset); dsb(); } while (0)
174 #define cru_writel_frac(v,offset) cru_writel((v),(offset))
179 #define CLKDATA_DBG(fmt, args...) printk(KERN_DEBUG "CLKDATA_DBG:\t"fmt, ##args)
180 #define CLKDATA_LOG(fmt, args...) printk(KERN_INFO "CLKDATA_LOG:\t"fmt, ##args)
182 #define CLKDATA_DBG(fmt, args...) do {} while(0)
183 #define CLKDATA_LOG(fmt, args...) do {} while(0)
185 #define CLKDATA_ERR(fmt, args...) printk(KERN_ERR "CLKDATA_ERR:\t"fmt, ##args)
186 #define CLKDATA_WARNNING(fmt, args...) printk("CLKDATA_WANNING:\t"fmt, ##args)
189 #define get_cru_bits(con,mask,shift)\
190 ((cru_readl((con)) >> (shift)) & (mask))
192 #define set_cru_bits_w_msk(val,mask,shift,con)\
193 cru_writel(((mask)<<(shift+16))|((val)<<(shift)),(con))
196 #define PLLS_IN_NORM(pll_id) (((cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id))==(PLL_MODE_NORM(pll_id)&PLL_MODE_MSK(pll_id)))\
197 &&!(cru_readl(PLL_CONS(pll_id,3))&PLL_BYPASS))
200 static u32 rk30_clock_flags = 0;
201 static struct clk codec_pll_clk;
202 static struct clk general_pll_clk;
203 static struct clk arm_pll_clk;
204 static unsigned long lpj_gpll;
205 static unsigned int __initdata armclk = 504 * MHZ;
208 /************************clk recalc div rate*********************************/
211 static unsigned long clksel_recalc_div(struct clk *clk)
213 u32 div = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1;
215 unsigned long rate = clk->parent->rate / div;
216 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
221 static unsigned long clksel_recalc_shift(struct clk *clk)
223 u32 shift = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift);
224 unsigned long rate = clk->parent->rate >> shift;
225 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
230 static unsigned long clksel_recalc_shift_2(struct clk *clk)
232 u32 shift = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1;
233 unsigned long rate = clk->parent->rate >> shift;
234 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
238 static unsigned long clksel_recalc_parent_rate(struct clk *clk)
240 unsigned long rate = clk->parent->rate;
241 pr_debug("%s new clock rate is %lu\n", clk->name, rate);
244 /********************************set div rate***********************************/
247 static int clksel_set_rate_freediv(struct clk *clk, unsigned long rate)
250 for (div = 0; div < clk->div_max; div++) {
251 u32 new_rate = clk->parent->rate / (div + 1);
252 if (new_rate <= rate) {
253 set_cru_bits_w_msk(div, clk->div_mask, clk->div_shift, clk->clksel_con);
254 //clk->rate = new_rate;
255 pr_debug("clksel_set_rate_freediv for clock %s to rate %ld (div %d)\n",
256 clk->name, rate, div + 1);
264 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
267 for (shift = 0; (1 << shift) < clk->div_max; shift++) {
268 u32 new_rate = clk->parent->rate >> shift;
269 if (new_rate <= rate) {
270 set_cru_bits_w_msk(shift, clk->div_mask, clk->div_shift, clk->clksel_con);
271 clk->rate = new_rate;
272 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n",
273 clk->name, rate, shift);
281 static int clksel_set_rate_shift_2(struct clk *clk, unsigned long rate)
285 for (shift = 1; (1 << shift) < clk->div_max; shift++) {
286 u32 new_rate = clk->parent->rate >> shift;
287 if (new_rate <= rate) {
288 set_cru_bits_w_msk(shift - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
289 clk->rate = new_rate;
290 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n",
291 clk->name, rate, shift);
300 static int clksel_set_rate_even(struct clk *clk, unsigned long rate)
303 for (div = 2; div < clk->div_max; div += 2) {
304 u32 new_rate = clk->parent->rate / div;
305 if (new_rate <= rate) {
306 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
307 clk->rate = new_rate;
308 pr_debug("%s for clock %s to rate %ld (even div = %d)\n",
309 __func__, clk->name, rate, div);
316 static u32 clk_get_evendiv(unsigned long rate_out, unsigned long rate , u32 div_max)
319 unsigned long new_rate;
320 for (div = 1; div < div_max; div += 2) {
321 new_rate = rate / (div + 1);
322 if (new_rate <= rate_out) {
326 return div_max ? div_max : 1;
329 static u32 clk_get_freediv(unsigned long rate_out, unsigned long rate , u32 div_max)
332 unsigned long new_rate;
333 for (div = 0; div < div_max; div++) {
334 new_rate = rate / (div + 1);
335 if (new_rate <= rate_out) {
339 return div_max ? div_max : 1;
342 struct clk *get_evendiv_parents_div(struct clk *clk, unsigned long rate, u32 *div_out) {
344 unsigned long new_rate[2] = {0, 0};
347 if(clk->rate == rate)
349 for(i = 0; i < 2; i++) {
350 div[i] = clk_get_evendiv(rate, clk->parents[i]->rate, clk->div_max);
351 new_rate[i] = clk->parents[i]->rate / div[i];
352 if(new_rate[i] == rate) {
354 return clk->parents[i];
357 if(new_rate[0] < new_rate[1])
362 return clk->parents[i];
365 struct clk *get_freediv_parents_div(struct clk *clk, unsigned long rate, u32 *div_out) {
367 unsigned long new_rate[2] = {0, 0};
370 if(clk->rate == rate)
372 for(i = 0; i < 2; i++) {
373 div[i] = clk_get_freediv(rate, clk->parents[i]->rate, clk->div_max);
374 new_rate[i] = clk->parents[i]->rate / div[i];
375 if(new_rate[i] == rate) {
377 return clk->parents[i];
380 if(new_rate[0] < new_rate[1])
385 return clk->parents[i];
388 static int clkset_rate_evendiv_autosel_parents(struct clk *clk, unsigned long rate)
393 if(clk->rate == rate)
395 p_clk = get_evendiv_parents_div(clk, rate, &div);
400 CLKDATA_DBG("%s %lu,form %s\n", clk->name, rate, p_clk->name);
401 if (clk->parent != p_clk) {
402 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con), clk->div_shift, clk->div_mask) + 1;
405 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
407 ret = clk_set_parent_nolock(clk, p_clk);
409 CLKDATA_ERR("%s can't set %lu,reparent err\n", clk->name, rate);
414 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
418 static int clkset_rate_freediv_autosel_parents(struct clk *clk, unsigned long rate)
423 if(clk->rate == rate)
425 p_clk = get_freediv_parents_div(clk, rate, &div);
430 CLKDATA_DBG("%s %lu,form %s\n", clk->name, rate, p_clk->name);
431 if (clk->parent != p_clk) {
432 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con), clk->div_shift, clk->div_mask) + 1;
435 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
437 ret = clk_set_parent_nolock(clk, p_clk);
439 CLKDATA_ERR("%s can't set %lu,reparent err\n", clk->name, rate);
444 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
448 //rate==div rate //hdmi
449 static int clk_freediv_autosel_parents_set_fixed_rate(struct clk *clk, unsigned long rate)
454 p_clk = get_freediv_parents_div(clk, rate, &div);
459 if((p_clk->rate / div) != rate || (p_clk->rate % div))
462 if (clk->parent != p_clk) {
463 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con),
464 clk->div_shift, clk->div_mask) + 1;
466 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
468 ret = clk_set_parent_nolock(clk, p_clk);
470 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
475 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
479 /***************************round********************************/
481 static long clksel_freediv_round_rate(struct clk *clk, unsigned long rate)
483 return clk->parent->rate / clk_get_freediv(rate, clk->parent->rate, clk->div_max);
486 static long clk_freediv_round_autosel_parents_rate(struct clk *clk, unsigned long rate)
490 if(clk->rate == rate)
492 p_clk = get_freediv_parents_div(clk, rate, &div);
495 return p_clk->rate / div;
498 /**************************************others seting************************************/
500 static struct clk *clksel_get_parent(struct clk *clk) {
501 return clk->parents[(cru_readl(clk->clksel_con) >> clk->src_shift) & clk->src_mask];
503 static int clksel_set_parent(struct clk *clk, struct clk *parent)
506 if (unlikely(!clk->parents))
508 for (i = 0; (i < clk->parents_num); i++) {
509 if (clk->parents[i] != parent)
511 set_cru_bits_w_msk(i, clk->src_mask, clk->src_shift, clk->clksel_con);
517 static int gate_mode(struct clk *clk, int on)
519 int idx = clk->gate_idx;
520 if (idx >= CLK_GATE_MAX)
523 cru_writel(CLK_GATE_W_MSK(idx) | CLK_UN_GATE(idx), CLK_GATE_CLKID_CONS(idx));
524 //CLKDATA_DBG("un gate id=%d %s(%x),con %x\n",idx,clk->name,
525 // CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx),CLK_GATE_CLKID_CONS(idx));
527 cru_writel(CLK_GATE_W_MSK(idx) | CLK_GATE(idx), CLK_GATE_CLKID_CONS(idx));
528 // CLKDATA_DBG("gate id=%d %s(%x),con%x\n",idx,clk->name,
529 // CLK_GATE_W_MSK(idx)|CLK_GATE(idx),CLK_GATE_CLKID_CONS(idx));
533 /*****************************frac set******************************************/
535 static unsigned long clksel_recalc_frac(struct clk *clk)
539 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
540 if (r == 0) // FPGA ?
541 return clk->parent->rate;
543 denominator = r & 0xFFFF;
544 rate64 = (u64)clk->parent->rate * numerator;
545 do_div(rate64, denominator);
547 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
551 static u32 clk_gcd(u32 numerator, u32 denominator)
555 if (!numerator || !denominator)
557 if (numerator > denominator) {
573 static int frac_div_get_seting(unsigned long rate_out, unsigned long rate,
574 u32 *numerator, u32 *denominator)
577 gcd_vl = clk_gcd(rate, rate_out);
578 CLKDATA_DBG("frac_get_seting rate=%lu,parent=%lu,gcd=%d\n", rate_out, rate, gcd_vl);
581 CLKDATA_ERR("gcd=0, i2s frac div is not be supported\n");
585 *numerator = rate_out / gcd_vl;
586 *denominator = rate / gcd_vl;
588 CLKDATA_DBG("frac_get_seting numerator=%d,denominator=%d,times=%d\n",
589 *numerator, *denominator, *denominator / *numerator);
591 if (*numerator > 0xffff || *denominator > 0xffff ||
592 (*denominator / (*numerator)) < 20) {
593 CLKDATA_ERR("can't get a available nume and deno\n");
600 /* *********************pll **************************/
602 #define rk30_clock_udelay(a) udelay(a);
604 /*********************pll lock status**********************************/
605 //#define GRF_SOC_CON0 0x15c
606 static void pll_wait_lock(int pll_idx)
608 u32 pll_state[4] = {1, 0, 2, 3};
609 u32 bit = 0x20u << pll_state[pll_idx];
610 int delay = 24000000;
612 if (regfile_readl(GRF_SOC_STATUS0) & bit)
617 CLKDATA_ERR("wait pll bit 0x%x time out!\n", bit);
624 /***************************pll function**********************************/
625 static unsigned long pll_clk_recalc(u32 pll_id, unsigned long parent_rate)
629 if (PLLS_IN_NORM(pll_id)) {
630 u32 pll_con0 = cru_readl(PLL_CONS(pll_id, 0));
631 u32 pll_con1 = cru_readl(PLL_CONS(pll_id, 1));
634 u64 rate64 = (u64)parent_rate * PLL_NF(pll_con1);
637 CLKDATA_DBG("selcon con0(%x) %x,con1(%x)%x, rate64 %llu\n",PLL_CONS(pll_id,0),pll_con0
638 ,PLL_CONS(pll_id,1),pll_con1, rate64);
642 //CLKDATA_DBG("pll id=%d con0=%x,con1=%x,parent=%lu\n",pll_id,pll_con0,pll_con1,parent_rate);
643 //CLKDATA_DBG("first pll id=%d rate is %lu (NF %d NR %d NO %d)\n",
644 //pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0), 1 << PLL_NO(pll_con0));
646 do_div(rate64, PLL_NR(pll_con0));
647 do_div(rate64, PLL_NO(pll_con0));
651 CLKDATA_DBG("pll_clk_recalc id=%d rate=%lu (NF %d NR %d NO %d) rate64=%llu\n",
652 pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0),PLL_NO(pll_con0), rate64);
656 CLKDATA_DBG("pll_clk_recalc id=%d rate=%lu by pass mode\n", pll_id, rate);
660 static unsigned long plls_clk_recalc(struct clk *clk)
662 return pll_clk_recalc(clk->pll->id, clk->parent->rate);
665 static int pll_clk_set_rate(struct pll_clk_set *clk_set, u8 pll_id)
668 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
669 cru_writel((0x1<<(16+1))|(0x1<<1), PLL_CONS(pll_id, 3));
676 cru_writel(clk_set->pllcon0, PLL_CONS(pll_id, 0));
677 cru_writel(clk_set->pllcon1, PLL_CONS(pll_id, 1));
679 rk30_clock_udelay(1);
680 cru_writel((0x1<<(16+1)), PLL_CONS(pll_id, 3));
682 pll_wait_lock(pll_id);
685 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
688 CLKDATA_ERR("pll reg id=%d,con0=%x,con1=%x,mode=%x\n",pll_id,
689 cru_readl(PLL_CONS(pll_id,0)),(PLL_CONS(pll_id,1)),cru_readl(CRU_MODE_CON));
694 static int gpll_clk_set_rate(struct clk *c, unsigned long rate)
696 struct _pll_data *pll_data = c->pll;
697 struct pll_clk_set *clk_set = (struct pll_clk_set *)pll_data->table;
699 while(clk_set->rate) {
700 if (clk_set->rate == rate) {
705 if(clk_set->rate == rate) {
706 pll_clk_set_rate(clk_set, pll_data->id);
707 lpj_gpll = CLK_LOOPS_RECALC(rate);
709 CLKDATA_ERR("gpll is no corresponding rate=%lu\n", rate);
715 #define PLL_FREF_MIN (183*KHZ)
716 #define PLL_FREF_MAX (1500*MHZ)
718 #define PLL_FVCO_MIN (300*MHZ)
719 #define PLL_FVCO_MAX (1500*MHZ)
721 #define PLL_FOUT_MIN (18750*KHZ)
722 #define PLL_FOUT_MAX (1500*MHZ)
724 #define PLL_NF_MAX (65536)
725 #define PLL_NR_MAX (64)
726 #define PLL_NO_MAX (64)
728 static int pll_clk_get_set(unsigned long fin_hz, unsigned long fout_hz, u32 *clk_nr, u32 *clk_nf, u32 *clk_no)
730 u32 nr, nf, no, nonr;
734 unsigned long fref, fvco, fout;
737 CLKDATA_DBG("pll_clk_get_set fin=%lu,fout=%lu\n", fin_hz, fout_hz);
738 if(!fin_hz || !fout_hz || fout_hz == fin_hz)
740 gcd_val = clk_gcd(fin_hz, fout_hz);
741 YFfenzi = fout_hz / gcd_val;
742 YFfenmu = fin_hz / gcd_val;
747 if(nf > PLL_NF_MAX || nonr > (PLL_NO_MAX * PLL_NR_MAX))
749 for(no = 1; no <= PLL_NO_MAX; no++) {
750 if(!(no == 1 || !(no % 2)))
757 if(nr > PLL_NR_MAX) //PLL_NR_MAX
761 if(fref < PLL_FREF_MIN || fref > PLL_FREF_MAX)
764 fvco = (fin_hz / nr) * nf;
765 if(fvco < PLL_FVCO_MIN || fvco > PLL_FVCO_MAX)
768 if(fout < PLL_FOUT_MIN || fout > PLL_FOUT_MAX)
781 static int pll_clk_mode(struct clk *clk, int on)
783 u8 pll_id = clk->pll->id;
784 u32 nr = PLL_NR(cru_readl(PLL_CONS(pll_id, 0)));
785 u32 dly = (nr * 500) / 24 + 1;
786 CLKDATA_DBG("pll_mode %s(%d)\n", clk->name, on);
788 cru_writel(PLL_PWR_ON | PLL_PWR_DN_W_MSK, PLL_CONS(pll_id, 3));
789 rk30_clock_udelay(dly);
790 pll_wait_lock(pll_id);
791 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
793 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
794 cru_writel(PLL_PWR_DN | PLL_PWR_DN_W_MSK, PLL_CONS(pll_id, 3));
799 static int cpll_clk_set_rate(struct clk *c, unsigned long rate)
801 struct _pll_data *pll_data = c->pll;
802 struct pll_clk_set *clk_set = (struct pll_clk_set *)pll_data->table;
803 struct pll_clk_set temp_clk_set;
804 u32 clk_nr, clk_nf, clk_no;
807 while(clk_set->rate) {
808 if (clk_set->rate == rate) {
813 if(clk_set->rate == rate) {
814 CLKDATA_DBG("cpll get a rate\n");
815 pll_clk_set_rate(clk_set, pll_data->id);
818 CLKDATA_DBG("cpll get auto calc a rate\n");
819 if(pll_clk_get_set(c->parent->rate, rate, &clk_nr, &clk_nf, &clk_no) == 0) {
820 pr_err("cpll auto set rate error\n");
823 CLKDATA_DBG("cpll auto ger rate set nr=%d,nf=%d,no=%d\n", clk_nr, clk_nf, clk_no);
824 temp_clk_set.pllcon0 = PLL_CLKR_SET(clk_nr) | PLL_CLKOD_SET(clk_no);
825 temp_clk_set.pllcon1 = PLL_CLKF_SET(clk_nf);
826 temp_clk_set.rst_dly = (clk_nr * 500) / 24 + 1;
827 pll_clk_set_rate(&temp_clk_set, pll_data->id);
834 /* ******************fixed input clk ***********************************************/
835 static struct clk xin24m = {
841 static struct clk xin27m = {
849 static struct clk clk_12m = {
856 /************************************pll func***************************/
857 static const struct apll_clk_set *arm_pll_clk_get_best_pll_set(unsigned long rate,
858 struct apll_clk_set *tables) {
859 const struct apll_clk_set *ps, *pt;
861 /* find the arm_pll we want. */
864 if (pt->rate == rate) {
868 // we are sorted, and ps->rate > pt->rate.
869 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
875 //CLKDATA_DBG("arm pll best rate=%lu\n",ps->rate);
878 static long arm_pll_clk_round_rate(struct clk *clk, unsigned long rate)
880 return arm_pll_clk_get_best_pll_set(rate, clk->pll->table)->rate;
883 struct arm_clks_div_set {
889 #define _arm_clks_div_set(_mhz,_periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
892 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
893 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
894 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
895 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
896 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
898 struct arm_clks_div_set arm_clk_div_tlb[] = {
899 _arm_clks_div_set(50 , 2, 11, 11, 11, 11),//25,50,50,50,50
900 _arm_clks_div_set(100 , 4, 11, 21, 21, 11),//25,100,50,50,50
901 _arm_clks_div_set(150 , 4, 11, 21, 21, 11),//37,150,75,75,75
902 _arm_clks_div_set(200 , 8, 21, 21, 21, 11),//25,100,50,50,50
903 _arm_clks_div_set(300 , 8, 21, 21, 21, 11),//37,150,75,75,75
904 _arm_clks_div_set(400 , 8, 21, 21, 41, 21),//50,200,100,50,50
905 _arm_clks_div_set(0 , 2, 11, 11, 11, 11),//25,50,50,50,50
907 struct arm_clks_div_set *arm_clks_get_div(u32 rate) {
909 for(i = 0; arm_clk_div_tlb[i].rate != 0; i++) {
910 if(arm_clk_div_tlb[i].rate >= rate)
911 return &arm_clk_div_tlb[i];
918 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
921 const struct apll_clk_set *ps;
922 u32 pll_id = clk->pll->id;
924 u32 old_aclk_div = 0, new_aclk_div;
926 ps = arm_pll_clk_get_best_pll_set(rate, (struct apll_clk_set *)clk->pll->table);
928 old_aclk_div = GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
929 new_aclk_div = GET_CORE_ACLK_VAL(ps->clksel1 & CORE_ACLK_MSK);
931 CLKDATA_LOG("apll will set rate(%lu) tlb con(%x,%x,%x),sel(%x,%x)\n",
932 ps->rate, ps->pllcon0, ps->pllcon1, ps->pllcon2, ps->clksel0, ps->clksel1);
934 if(general_pll_clk.rate > clk->rate) {
935 temp_div = clk_get_freediv(clk->rate, general_pll_clk.rate, 10);
940 // ungating cpu gpll path
941 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH) | CLK_UN_GATE(CLK_GATE_CPU_GPLL_PATH),
942 // CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
944 local_irq_save(flags);
945 //div arm clk for gpll
947 cru_writel(CORE_CLK_DIV_W_MSK|CORE_CLK_DIV(temp_div), CRU_CLKSELS_CON(0));
948 cru_writel(CORE_SEL_PLL_W_MSK|CORE_SEL_GPLL, CRU_CLKSELS_CON(0));
950 loops_per_jiffy = lpj_gpll / temp_div;
953 /*if core src don't select gpll ,apll neet to enter slow mode */
954 //cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
957 cru_writel((0x1<<(16+1))|(0x1<<1), PLL_CONS(pll_id, 3));
964 cru_writel(ps->pllcon0, PLL_CONS(pll_id, 0));
965 cru_writel(ps->pllcon1, PLL_CONS(pll_id, 1));
967 rk30_clock_udelay(1);
968 cru_writel((0x1<<(16+1)), PLL_CONS(pll_id, 3));
970 pll_wait_lock(pll_id);
973 //cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
976 if(new_aclk_div>=old_aclk_div) {
977 cru_writel(ps->clksel0, CRU_CLKSELS_CON(0));
978 cru_writel(ps->clksel1, CRU_CLKSELS_CON(1));
981 cru_writel(CORE_SEL_PLL_W_MSK | CORE_SEL_APLL, CRU_CLKSELS_CON(0));
982 if(old_aclk_div>new_aclk_div) {
983 cru_writel(ps->clksel0, CRU_CLKSELS_CON(0));
984 cru_writel(ps->clksel1, CRU_CLKSELS_CON(1));
987 cru_writel(CORE_CLK_DIV_W_MSK|CORE_CLK_DIV(1), CRU_CLKSELS_CON(0));
989 loops_per_jiffy = ps->lpj;
992 //CLKDATA_DBG("apll set loops_per_jiffy =%lu,rate(%lu)\n",loops_per_jiffy,ps->rate);
994 local_irq_restore(flags);
998 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH) | CLK_GATE(CLK_GATE_CPU_GPLL_PATH)
999 // , CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
1001 CLKDATA_LOG("apll set over con(%x,%x,%x,%x),sel(%x,%x)\n", cru_readl(PLL_CONS(pll_id, 0)),
1002 cru_readl(PLL_CONS(pll_id, 1)), cru_readl(PLL_CONS(pll_id, 2)),
1003 cru_readl(PLL_CONS(pll_id, 3)), cru_readl(CRU_CLKSELS_CON(0)),
1004 cru_readl(CRU_CLKSELS_CON(1)));
1009 /************************************pll clocks***************************/
1011 static const struct apll_clk_set apll_clks[] = {
1012 //_APLL_SET_CLKS(_mhz, nr, nf, no, _periph_div,
1013 // _axi_core_div, _axi_div, _ahb_div, _apb_div, _ahb2apb)
1014 _APLL_SET_CLKS(1992, 1, 83, 1, 8, 81, 81, 21, 41, 21),
1015 _APLL_SET_CLKS(1896, 1, 79, 1, 8, 81, 81, 21, 41, 21),
1016 _APLL_SET_CLKS(1800, 1, 75, 1, 8, 81, 81, 21, 41, 21),
1017 _APLL_SET_CLKS(1704, 1, 71, 1, 8, 81, 81, 21, 41, 21),
1018 _APLL_SET_CLKS(1608, 1, 67, 1, 8, 41, 41, 21, 41, 21),
1019 _APLL_SET_CLKS(1560, 1, 65, 1, 8, 41, 41, 21, 41, 21),
1020 _APLL_SET_CLKS(1512, 1, 63, 1, 8, 41, 41, 21, 41, 21),
1021 _APLL_SET_CLKS(1464, 1, 61, 1, 8, 41, 41, 21, 41, 21),
1022 _APLL_SET_CLKS(1416, 1, 59, 1, 8, 41, 41, 21, 41, 21),
1023 _APLL_SET_CLKS(1368, 1, 57, 1, 8, 41, 41, 21, 41, 21),
1024 _APLL_SET_CLKS(1320, 1, 55, 1, 8, 41, 41, 21, 41, 21),
1025 _APLL_SET_CLKS(1296, 1, 54, 1, 8, 41, 41, 21, 41, 21),
1026 _APLL_SET_CLKS(1272, 1, 53, 1, 8, 41, 41, 21, 41, 21),
1027 _APLL_SET_CLKS(1200, 1, 50, 1, 8, 41, 41, 21, 41, 21),
1028 _APLL_SET_CLKS(1176, 1, 49, 1, 8, 41, 41, 21, 41, 21),
1029 _APLL_SET_CLKS(1128, 1, 47, 1, 8, 41, 41, 21, 41, 21),
1030 _APLL_SET_CLKS(1104, 1, 46, 1, 8, 41, 41, 21, 41, 21),
1031 _APLL_SET_CLKS(1008, 1, 84, 2, 8, 41, 31, 21, 41, 21),
1032 _APLL_SET_CLKS(912, 1, 76, 2, 8, 41, 31, 21, 41, 21),
1033 _APLL_SET_CLKS(888, 1, 74, 2, 8, 41, 31, 21, 41, 21),
1034 _APLL_SET_CLKS(816 , 1, 68, 2, 8, 41, 31, 21, 41, 21),
1035 _APLL_SET_CLKS(792 , 1, 66, 2, 8, 41, 31, 21, 41, 21),
1036 _APLL_SET_CLKS(696 , 1, 58, 2, 8, 41, 31, 21, 41, 21),
1037 _APLL_SET_CLKS(600 , 1, 50, 2, 4, 41, 31, 21, 41, 21),
1038 _APLL_SET_CLKS(504 , 1, 84, 4, 4, 41, 21, 21, 41, 21),
1039 _APLL_SET_CLKS(408 , 1, 68, 4, 4, 21, 21, 21, 41, 21),
1040 _APLL_SET_CLKS(312 , 1, 52, 4, 2, 21, 21, 21, 21, 11),
1041 _APLL_SET_CLKS(252 , 1, 84, 8, 2, 21, 21, 21, 21, 11),
1042 _APLL_SET_CLKS(216 , 1, 72, 8, 2, 21, 21, 21, 21, 11),
1043 _APLL_SET_CLKS(126 , 1, 84, 16, 2, 11, 21, 11, 11, 11),
1044 _APLL_SET_CLKS(48 , 1, 64, 32, 2, 11, 11, 11, 11, 11),
1045 _APLL_SET_CLKS(0 , 1, 21, 4, 2, 11, 11, 11, 11, 11),
1048 static struct _pll_data apll_data = SET_PLL_DATA(APLL_ID, (void *)apll_clks);
1049 static struct clk arm_pll_clk = {
1052 .mode = pll_clk_mode,
1053 .recalc = plls_clk_recalc,
1054 .set_rate = arm_pll_clk_set_rate,
1055 .round_rate = arm_pll_clk_round_rate,
1059 static int ddr_pll_clk_set_rate(struct clk *clk, unsigned long rate)
1061 /* do nothing here */
1064 static struct _pll_data dpll_data = SET_PLL_DATA(DPLL_ID, NULL);
1065 static struct clk ddr_pll_clk = {
1068 .recalc = plls_clk_recalc,
1069 .set_rate = ddr_pll_clk_set_rate,
1073 static const struct pll_clk_set cpll_clks[] = {
1074 _PLL_SET_CLKS(360000, 1, 60, 4),
1075 _PLL_SET_CLKS(408000, 1, 68, 4),
1076 _PLL_SET_CLKS(456000, 1, 76, 4),
1077 _PLL_SET_CLKS(504000, 1, 84, 4),
1078 _PLL_SET_CLKS(552000, 1, 46, 2),
1079 _PLL_SET_CLKS(600000, 1, 50, 2),
1080 _PLL_SET_CLKS(742500, 8, 495, 2),
1081 _PLL_SET_CLKS(768000, 1, 64, 2),
1082 _PLL_SET_CLKS(798000, 2, 133, 2),
1083 _PLL_SET_CLKS(1188000, 2, 99, 1),
1084 _PLL_SET_CLKS( 0, 4, 133, 1),
1086 static struct _pll_data cpll_data = SET_PLL_DATA(CPLL_ID, (void *)cpll_clks);
1087 static struct clk codec_pll_clk = {
1088 .name = "codec_pll",
1090 .mode = pll_clk_mode,
1091 .recalc = plls_clk_recalc,
1092 .set_rate = cpll_clk_set_rate,
1096 static const struct pll_clk_set gpll_clks[] = {
1097 _PLL_SET_CLKS(148500, 2, 99, 8),
1098 _PLL_SET_CLKS(297000, 2, 198, 8),
1099 _PLL_SET_CLKS(300000, 1, 50, 4),
1100 _PLL_SET_CLKS(594000, 2, 198, 4),
1101 _PLL_SET_CLKS(1188000, 2, 99, 1),
1102 _PLL_SET_CLKS(1200000, 1, 50, 1),
1103 _PLL_SET_CLKS(0, 0, 0, 0),
1105 static struct _pll_data gpll_data = SET_PLL_DATA(GPLL_ID, (void *)gpll_clks);
1106 static struct clk general_pll_clk = {
1107 .name = "general_pll",
1109 .recalc = plls_clk_recalc,
1110 .set_rate = gpll_clk_set_rate,
1113 /********************************clocks***********************************/
1114 /* core and cpu setting */
1115 static int ddr_clk_set_rate(struct clk *c, unsigned long rate)
1120 static long ddr_clk_round_rate(struct clk *clk, unsigned long rate)
1122 return ddr_set_pll_rk3066b(rate / MHZ, 0) * MHZ;
1124 static unsigned long ddr_clk_recalc_rate(struct clk *clk)
1126 u32 shift = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift);
1127 unsigned long rate = clk->parent->recalc(clk->parent) >> shift;
1128 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
1131 static struct clk *clk_ddr_parents[2] = {&ddr_pll_clk, &general_pll_clk};
1132 static struct clk clk_ddr = {
1134 .parent = &ddr_pll_clk,
1135 .recalc = ddr_clk_recalc_rate,
1136 .set_rate = ddr_clk_set_rate,
1137 .round_rate = ddr_clk_round_rate,
1138 .clksel_con = CRU_CLKSELS_CON(26),
1139 CRU_DIV_SET(0x3, 0, 4),
1141 CRU_PARENTS_SET(clk_ddr_parents),
1143 static int arm_core_clk_set_rate(struct clk *c, unsigned long rate)
1147 ret = clk_set_rate_nolock(c->parent, rate);
1149 CLKDATA_ERR("Failed to change clk pll %s to %lu\n", c->name, rate);
1153 set_cru_bits_w_msk(0, c->div_mask, c->div_shift, c->clksel_con);
1156 static unsigned long arm_core_clk_get_rate(struct clk *c)
1158 u32 div = (get_cru_bits(c->clksel_con, c->div_mask, c->div_shift) + 1);
1159 //c->parent->rate=c->parent->recalc(c->parent);
1160 return c->parent->rate / div;
1162 static long core_clk_round_rate(struct clk *clk, unsigned long rate)
1164 u32 div = (get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1);
1165 return clk_round_rate_nolock(clk->parent, rate) / div;
1168 static int core_clksel_set_parent(struct clk *clk, struct clk *new_prt)
1172 struct clk *old_prt;
1174 if(clk->parent == new_prt)
1176 if (unlikely(!clk->parents))
1178 CLKDATA_DBG("%s,reparent %s\n", clk->name, new_prt->name);
1180 old_prt = clk->parent;
1182 if(clk->parents[0] == new_prt) {
1183 new_prt->set_rate(new_prt, 300 * MHZ);
1184 set_cru_bits_w_msk(0, clk->div_mask, clk->div_shift, clk->clksel_con);
1185 } else if(clk->parents[1] == new_prt) {
1187 if(new_prt->rate > old_prt->rate) {
1188 temp_div = clk_get_freediv(old_prt->rate, new_prt->rate, clk->div_max);
1189 set_cru_bits_w_msk(temp_div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
1191 set_cru_bits_w_msk(1, clk->src_mask, clk->src_shift, clk->clksel_con);
1192 new_prt->set_rate(new_prt, 300 * MHZ);
1201 static int core_gpll_clk_set_rate(struct clk *c, unsigned long rate)
1204 u32 old_aclk_div = 0, new_aclk_div;
1205 struct arm_clks_div_set *temp_clk_div;
1206 unsigned long arm_gpll_rate, arm_gpll_lpj;
1207 temp_div = clk_get_freediv(rate, c->parent->rate, c->div_max);
1208 arm_gpll_rate = c->parent->rate / temp_div;
1210 temp_clk_div = arm_clks_get_div(arm_gpll_rate / MHZ);
1212 temp_clk_div = &arm_clk_div_tlb[4];
1214 old_aclk_div = GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
1215 new_aclk_div = GET_CORE_ACLK_VAL(temp_clk_div->clksel1 & CORE_ACLK_MSK);
1216 if(c->rate >= rate) {
1217 arm_gpll_lpj = lpj_gpll / temp_div;
1218 set_cru_bits_w_msk(temp_div - 1, c->div_mask, c->div_shift, c->clksel_con);
1221 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
1222 cru_writel((temp_clk_div->clksel0) | CORE_CLK_DIV(temp_div) | CORE_CLK_DIV_W_MSK,
1223 CRU_CLKSELS_CON(0));
1224 if((c->rate < rate)) {
1225 arm_gpll_lpj = lpj_gpll / temp_div;
1226 set_cru_bits_w_msk(temp_div - 1, c->div_mask, c->div_shift, c->clksel_con);
1230 static unsigned long arm_core_gpll_clk_get_rate(struct clk *c)
1232 return c->parent->rate;
1234 static struct clk clk_core_gpll_path = {
1235 .name = "cpu_gpll_path",
1236 .parent = &general_pll_clk,
1237 .gate_idx = CLK_GATE_CPU_GPLL_PATH,
1238 .recalc = arm_core_gpll_clk_get_rate,
1239 .set_rate = core_gpll_clk_set_rate,
1240 CRU_GATE_MODE_SET(gate_mode, CLK_GATE_CPU_GPLL_PATH),
1244 static struct clk *clk_cpu_parents[2] = {&arm_pll_clk, &clk_core_gpll_path};
1246 static struct clk clk_core = {
1248 .parent = &arm_pll_clk,
1249 .set_rate = arm_core_clk_set_rate,
1250 .recalc = arm_core_clk_get_rate,
1251 .round_rate = core_clk_round_rate,
1252 .set_parent = core_clksel_set_parent,
1253 .clksel_con = CRU_CLKSELS_CON(0),
1254 CRU_DIV_SET(0x1f, 9, 32),
1256 CRU_PARENTS_SET(clk_cpu_parents),
1259 static struct clk *clk_cpu_div_parents[2] = {&arm_pll_clk, &general_pll_clk};
1260 static struct clk clk_cpu_div = {
1262 .parent = &arm_pll_clk,
1263 .set_rate = clksel_set_rate_freediv,
1264 .recalc = clksel_recalc_div,
1265 .clksel_con = CRU_CLKSELS_CON(0),
1266 CRU_DIV_SET(0x1f, 0, 32),
1268 CRU_PARENTS_SET(clk_cpu_div_parents),
1273 GATE_CLK(l2c, clk_core, CLK_L2C);
1274 GATE_CLK(core_dbg, clk_core, CLK_CORE_DBG);
1276 static unsigned long aclk_recalc(struct clk *clk)
1279 u32 div = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1;
1284 rate = clk->parent->rate / div;
1285 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
1289 static struct clk core_periph = {
1290 .name = "core_periph",
1291 .parent = &clk_core,
1292 .gate_idx = CLK_GATE_CORE_PERIPH,
1293 .recalc = clksel_recalc_shift_2,
1294 .clksel_con = CRU_CLKSELS_CON(0),
1295 CRU_DIV_SET(0x3, 6, 16),
1298 static struct clk aclk_core = {
1299 .name = "aclk_core",
1300 .parent = &clk_core,
1301 .gate_idx = CLK_GATE_ACLK_CORE,
1302 .recalc = aclk_recalc,
1303 .clksel_con = CRU_CLKSELS_CON(1),
1304 CRU_DIV_SET(0x7, 3, 8),
1308 static struct clk aclk_cpu = {
1310 .parent = &clk_cpu_div,
1311 .gate_idx = CLK_GATE_ACLK_CPU,
1312 .recalc = aclk_recalc,
1313 .set_rate = clksel_set_rate_shift,
1314 .clksel_con = CRU_CLKSELS_CON(1),
1315 CRU_DIV_SET(0x7, 0, 8),
1318 static struct clk hclk_cpu = {
1320 .parent = &aclk_cpu,
1321 .gate_idx = CLK_GATE_HCLK_CPU,
1322 .recalc = clksel_recalc_shift,
1323 .set_rate = clksel_set_rate_shift,
1324 .clksel_con = CRU_CLKSELS_CON(1),
1325 CRU_DIV_SET(0x3, 8, 4),
1329 static struct clk pclk_cpu = {
1331 .parent = &aclk_cpu,
1332 .gate_idx = CLK_GATE_PCLK_CPU,
1333 .recalc = clksel_recalc_shift,
1334 .set_rate = clksel_set_rate_shift,
1335 .clksel_con = CRU_CLKSELS_CON(1),
1336 CRU_DIV_SET(0x3, 12, 8),
1339 static struct clk ahb2apb_cpu = {
1341 .parent = &hclk_cpu,
1342 .recalc = clksel_recalc_shift,
1343 .set_rate = clksel_set_rate_shift,
1344 .clksel_con = CRU_CLKSELS_CON(1),
1345 CRU_DIV_SET(0x3, 14, 4),
1349 static struct clk atclk_cpu = {
1350 .name = "atclk_cpu",
1351 .parent = &pclk_cpu,
1352 .gate_idx = CLK_GATE_ATCLK_CPU,
1355 /* GPU setting test */
1356 #if 0 //for gpu rate test
1358 static int clk_gpu_set_rate(struct clk *clk, unsigned long rate)
1360 printk("gpu dbg clk %s set %lu\n",clk->name,rate);
1361 return clksel_set_rate_freediv(clk, rate);
1364 #define clk_gpu_set_rate_callback clk_gpu_set_rate
1366 #define clk_gpu_set_rate(clk,rate) clksel_set_rate_freediv((clk),(rate))
1367 #define clk_gpu_set_rate_callback clksel_set_rate_freediv
1370 #define GPU_CORE_ACLK_CTR_TOGETHER
1372 #ifdef GPU_CORE_ACLK_CTR_TOGETHER
1373 static struct clk aclk_gpu;
1374 static struct clk clk_gpu;
1376 static int clk_gpu_ref_set_rate(struct clk *clk, unsigned long rate)
1379 ret=clk_gpu_set_rate(clk, rate);
1382 ret=clk_set_rate_nolock(&aclk_gpu, rate);
1385 static long clk_gpu_ref_round_rate(struct clk *clk, unsigned long rate)
1387 unsigned long rate_gpu;
1388 rate_gpu=clksel_freediv_round_rate(clk,rate);
1390 if(rate_gpu!=clksel_freediv_round_rate(&aclk_gpu,rate))
1392 CLKDATA_ERR("gpu rate is not equal ack gpu rate in %s\n",__FUNCTION__);
1399 static struct clk *gpu_parents[2] = {&codec_pll_clk, &general_pll_clk};
1401 static struct clk clk_gpu = {
1404 .recalc = clksel_recalc_div,
1405 #ifdef GPU_CORE_ACLK_CTR_TOGETHER
1406 .round_rate = clk_gpu_ref_round_rate,
1407 .set_rate = clk_gpu_ref_set_rate,
1409 .round_rate = clksel_freediv_round_rate,
1410 .set_rate = clk_gpu_set_rate_callback,
1412 .clksel_con = CRU_CLKSELS_CON(33),
1413 .gate_idx = CLK_GATE_CLK_GPU,
1414 CRU_DIV_SET(0x1f, 0, 32),
1415 CRU_SRC_SET(0x1, 7),
1416 CRU_PARENTS_SET(gpu_parents),
1419 static struct clk *gpu_aclk_parents[2] = {&codec_pll_clk, &general_pll_clk};
1420 static struct clk aclk_gpu = {
1422 .recalc = clksel_recalc_div,
1423 .round_rate = clksel_freediv_round_rate,
1424 .set_rate = clk_gpu_set_rate_callback,
1425 .clksel_con = CRU_CLKSELS_CON(34),
1426 CRU_DIV_SET(0x1f, 0, 32),
1427 CRU_SRC_SET(0x1, 7),
1428 CRU_PARENTS_SET(gpu_parents),
1431 #ifdef GPU_CORE_ACLK_CTR_TOGETHER
1432 static int clk_aclk_gpu_null_set_rate(struct clk *clk, unsigned long rate)
1437 static long clk_aclk_gpu_null_round_rate(struct clk *clk, unsigned long rate)
1439 return clk->parent->round_rate(clk->parent,rate);
1441 static unsigned long clk_aclk_gpu_null_recalc_div(struct clk *clk)
1443 return clk->parent->rate;
1445 //gpu and gpu together ctr,this clk is following aclk gpu.
1446 static struct clk aclk_gpu_null = {
1447 .name = "aclk_gpu_null",
1448 .parent = &aclk_gpu,
1449 .recalc = clk_aclk_gpu_null_recalc_div,
1450 .round_rate = clk_aclk_gpu_null_round_rate,
1451 .set_rate = clk_aclk_gpu_null_set_rate,
1454 static struct clk aclk_gpu_slv = {
1455 .name = "aclk_gpu_slv",
1456 .parent = &aclk_gpu,
1458 .gate_idx = CLK_GATE_ACLK_GPU_SLV,
1461 static struct clk aclk_gpu_mst = {
1462 .name = "aclk_gpu_mst",
1463 .parent = &aclk_gpu,
1465 .gate_idx = CLK_GATE_ACLK_GPU_MST,
1469 /* vcodec setting */
1470 static unsigned long clksel_recalc_vpu_hclk(struct clk *clk)
1472 unsigned long rate = clk->parent->rate / 4;
1473 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, 4);
1477 static struct clk *aclk_vepu_parents[2] = {&codec_pll_clk, &general_pll_clk};
1479 static struct clk aclk_vepu = {
1480 .name = "aclk_vepu",
1481 .parent = &codec_pll_clk,
1483 .recalc = clksel_recalc_div,
1484 //.set_rate = clksel_set_rate_freediv,
1485 .set_rate = clkset_rate_freediv_autosel_parents,
1486 .clksel_con = CRU_CLKSELS_CON(32),
1487 .gate_idx = CLK_GATE_ACLK_VEPU,
1488 CRU_DIV_SET(0x1f, 0, 32),
1489 CRU_SRC_SET(0x1, 7),
1490 CRU_PARENTS_SET(aclk_vepu_parents),
1493 static struct clk *aclk_vdpu_parents[2] = {&codec_pll_clk, &general_pll_clk};
1495 static struct clk aclk_vdpu = {
1496 .name = "aclk_vdpu",
1498 .recalc = clksel_recalc_div,
1499 //.set_rate = clksel_set_rate_freediv,
1500 .set_rate = clkset_rate_freediv_autosel_parents,
1501 .clksel_con = CRU_CLKSELS_CON(32),
1502 .gate_idx = CLK_GATE_ACLK_VDPU,
1503 CRU_DIV_SET(0x1f, 8, 32),
1504 CRU_SRC_SET(0x1, 15),
1505 CRU_PARENTS_SET(aclk_vdpu_parents),
1507 static struct clk hclk_vepu = {
1508 .name = "hclk_vepu",
1509 .parent = &aclk_vepu,
1511 .recalc = clksel_recalc_vpu_hclk,
1512 .gate_idx = CLK_GATE_HCLK_VEPU,
1515 static struct clk hclk_vdpu = {
1516 .name = "hclk_vdpu",
1517 .parent = &aclk_vdpu,
1519 .recalc = clksel_recalc_vpu_hclk,
1520 .gate_idx = CLK_GATE_HCLK_VDPU,
1523 /* aclk lcdc setting */
1524 static struct clk *aclk_lcdc0_parents[] = {&codec_pll_clk, &general_pll_clk};
1526 static struct clk aclk_lcdc0_pre = {
1527 .name = "aclk_lcdc0_pre",
1528 .parent = &codec_pll_clk,
1530 .recalc = clksel_recalc_div,
1531 .set_rate = clkset_rate_freediv_autosel_parents,
1532 //.set_rate = clksel_set_rate_freediv,
1533 .gate_idx = CLK_GATE_ACLK_LCDC0_SRC,
1534 .clksel_con = CRU_CLKSELS_CON(31),
1535 CRU_DIV_SET(0x1f, 0, 32),
1536 CRU_SRC_SET(0x1, 7),
1537 CRU_PARENTS_SET(aclk_lcdc0_parents),
1540 static struct clk *aclk_lcdc1_parents[] = {&codec_pll_clk, &general_pll_clk};
1542 static struct clk aclk_lcdc1_pre = {
1543 .name = "aclk_lcdc1_pre",
1544 .parent = &codec_pll_clk,
1546 .recalc = clksel_recalc_div,
1547 .set_rate = clkset_rate_freediv_autosel_parents,
1548 .gate_idx = CLK_GATE_ACLK_LCDC1_SRC,
1549 .clksel_con = CRU_CLKSELS_CON(31),
1550 CRU_DIV_SET(0x1f, 8, 32),
1551 CRU_SRC_SET(0x1, 15),
1552 CRU_PARENTS_SET(aclk_lcdc1_parents),
1555 /* aclk/hclk/pclk periph setting */
1556 static struct clk *aclk_periph_parents[2] = {&general_pll_clk, &codec_pll_clk};
1558 static struct clk aclk_periph = {
1559 .name = "aclk_periph",
1560 .parent = &general_pll_clk,
1562 .gate_idx = CLK_GATE_ACLK_PERIPH,
1563 .recalc = clksel_recalc_div,
1564 .set_rate = clksel_set_rate_freediv,
1565 .clksel_con = CRU_CLKSELS_CON(10),
1566 CRU_DIV_SET(0x1f, 0, 32),
1568 CRU_PARENTS_SET(aclk_periph_parents),
1570 GATE_CLK(periph_src, aclk_periph, PERIPH_SRC);
1572 static struct clk pclk_periph = {
1573 .name = "pclk_periph",
1574 .parent = &aclk_periph,
1576 .gate_idx = CLK_GATE_PCLK_PERIPH,
1577 .recalc = clksel_recalc_shift,
1578 .set_rate = clksel_set_rate_shift,
1579 .clksel_con = CRU_CLKSELS_CON(10),
1580 CRU_DIV_SET(0x3, 12, 8),
1583 static struct clk hclk_periph = {
1584 .name = "hclk_periph",
1585 .parent = &aclk_periph,
1587 .gate_idx = CLK_GATE_HCLK_PERIPH,
1588 .recalc = clksel_recalc_shift,
1589 .set_rate = clksel_set_rate_shift,
1590 .clksel_con = CRU_CLKSELS_CON(10),
1591 CRU_DIV_SET(0x3, 8, 4),
1593 /* dclk lcdc setting */
1595 static int clksel_set_rate_hdmi(struct clk *clk, unsigned long rate)
1599 unsigned long new_rate;
1602 if(clk->rate == rate)
1604 for(i = 0; i < 2; i++) {
1605 div = clk_get_freediv(rate, clk->parents[i]->rate, clk->div_max);
1606 new_rate = clk->parents[i]->rate / div;
1607 if((rate == new_rate) && !(clk->parents[i]->rate % div)) {
1612 CLKDATA_ERR("%s can't set fixed rate%lu\n", clk->name, rate);
1616 //CLKDATA_DBG("%s set rate %lu(from %s)\n",clk->name,rate,clk->parents[i]->name);
1618 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con),
1619 clk->div_shift, clk->div_mask) + 1;
1621 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
1623 if(clk->parents[i] != clk->parent) {
1624 ret = clk_set_parent_nolock(clk, clk->parents[i]);
1628 CLKDATA_ERR("lcdc1 %s can't get rate%lu,reparent%s(now %s) err\n",
1629 clk->name, rate, clk->parents[i]->name, clk->parent->name);
1632 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
1636 static int dclk_lcdc_set_rate(struct clk *clk, unsigned long rate)
1641 if (rate == 27 * MHZ && (rk30_clock_flags & CLK_FLG_EXT_27MHZ)) {
1642 parent = clk->parents[1];
1643 //CLKDATA_DBG(" %s from=%s\n",clk->name,parent->name);
1645 parent = clk->parents[0];
1647 //CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1648 //clk->name,rate,parent->name,clk->parent->name);
1650 if(parent != clk->parents[1]) {
1651 ret = clk_set_rate_nolock(parent, rate); //div 1:1
1653 CLKDATA_DBG("%s set rate=%lu err\n", clk->name, rate);
1657 if (clk->parent != parent) {
1658 ret = clk_set_parent_nolock(clk, parent);
1660 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
1667 static struct clk *dclk_lcdc0_parents[2] = {&codec_pll_clk, &general_pll_clk};
1668 static struct clk dclk_lcdc0 = {
1669 .name = "dclk_lcdc0",
1671 .set_rate = clkset_rate_evendiv_autosel_parents,
1672 .recalc = clksel_recalc_div,
1673 .gate_idx = CLK_GATE_DCLK_LCDC0_SRC,
1674 .clksel_con = CRU_CLKSELS_CON(27),
1675 CRU_SRC_SET(0x1, 0),
1676 CRU_DIV_SET(0xff, 8, 256),
1677 CRU_PARENTS_SET(dclk_lcdc0_parents),
1680 static struct clk *dclk_lcdc1_parents[2] = {&codec_pll_clk, &general_pll_clk};
1681 static struct clk dclk_lcdc1 = {
1682 .name = "dclk_lcdc1",
1684 .set_rate = clkset_rate_evendiv_autosel_parents,
1685 .recalc = clksel_recalc_div,
1686 .gate_idx = CLK_GATE_DCLK_LCDC1_SRC,
1687 .clksel_con = CRU_CLKSELS_CON(28),
1688 CRU_SRC_SET(0x1, 0),
1689 CRU_DIV_SET(0xff, 8, 256),
1690 CRU_PARENTS_SET(dclk_lcdc1_parents),
1695 static struct clk *cifout_sel_pll_parents[2] = {&codec_pll_clk, &general_pll_clk};
1696 static struct clk cif_out_pll = {
1697 .name = "cif_out_pll",
1698 .parent = &general_pll_clk,
1699 .clksel_con = CRU_CLKSELS_CON(29),
1700 CRU_SRC_SET(0x1, 0),
1701 CRU_PARENTS_SET(cifout_sel_pll_parents),
1704 static struct clk cif0_out_div = {
1705 .name = "cif0_out_div",
1706 .parent = &cif_out_pll,
1708 .recalc = clksel_recalc_div,
1709 .set_rate = clksel_set_rate_freediv,
1710 .gate_idx = CLK_GATE_CIF0_OUT,
1711 .clksel_con = CRU_CLKSELS_CON(29),
1712 CRU_DIV_SET(0x1f, 1, 32),
1715 static int cif_out_set_rate(struct clk *clk, unsigned long rate)
1720 if (rate == 24 * MHZ) {
1721 parent = clk->parents[1];
1723 parent = clk->parents[0];
1724 ret = clk_set_rate_nolock(parent, rate);
1728 if (clk->parent != parent)
1729 ret = clk_set_parent_nolock(clk, parent);
1734 static struct clk *cif0_out_parents[2] = {&cif0_out_div, &xin24m};
1735 static struct clk cif0_out = {
1737 .parent = &cif0_out_div,
1738 .set_rate = cif_out_set_rate,
1739 .clksel_con = CRU_CLKSELS_CON(29),
1740 CRU_SRC_SET(0x1, 7),
1741 CRU_PARENTS_SET(cif0_out_parents),
1744 static struct clk pclkin_cif0 = {
1745 .name = "pclkin_cif0",
1747 .gate_idx = CLK_GATE_PCLKIN_CIF0,
1750 static struct clk inv_cif0 = {
1752 .parent = &pclkin_cif0,
1755 static struct clk *cif0_in_parents[2] = {&pclkin_cif0, &inv_cif0};
1756 static struct clk cif0_in = {
1758 .parent = &pclkin_cif0,
1759 .clksel_con = CRU_CLKSELS_CON(30),
1760 CRU_SRC_SET(0x1, 8),
1761 CRU_PARENTS_SET(cif0_in_parents),
1764 /* i2s/spdif setting */
1765 static struct clk *clk_i2s_div_parents[] = {&general_pll_clk, &codec_pll_clk};
1766 static struct clk clk_i2s_pll = {
1768 .parent = &general_pll_clk,
1769 .clksel_con = CRU_CLKSELS_CON(2),
1770 CRU_SRC_SET(0x1, 15),
1771 CRU_PARENTS_SET(clk_i2s_div_parents),
1774 static struct clk clk_i2s0_div = {
1776 .parent = &clk_i2s_pll,
1778 .recalc = clksel_recalc_div,
1779 .set_rate = clksel_set_rate_freediv,
1780 .round_rate = clksel_freediv_round_rate,
1781 .gate_idx = CLK_GATE_I2S0_SRC,
1782 .clksel_con = CRU_CLKSELS_CON(3),
1783 CRU_DIV_SET(0x7f, 0, 64),
1786 static struct clk clk_spdif_div = {
1787 .name = "spdif_div",
1788 .parent = &clk_i2s_pll,
1789 .recalc = clksel_recalc_div,
1790 .set_rate = clksel_set_rate_freediv,
1791 .round_rate = clksel_freediv_round_rate,
1793 .gate_idx = CLK_GATE_SPDIF_SRC,
1794 .clksel_con = CRU_CLKSELS_CON(5),
1795 CRU_DIV_SET(0x7f, 0, 64),
1797 static int clk_i2s_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1799 u32 numerator, denominator;
1800 //clk_i2s_div->clk_i2s_pll->gpll/cpll
1801 //clk->parent->parent
1802 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1803 &numerator, &denominator) == 0) {
1804 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
1805 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1806 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
1808 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1814 static struct clk clk_i2s0_frac_div = {
1815 .name = "i2s0_frac_div",
1816 .parent = &clk_i2s0_div,
1818 .gate_idx = CLK_GATE_I2S0_FRAC,
1819 .recalc = clksel_recalc_frac,
1820 .set_rate = clk_i2s_fracdiv_set_rate,
1821 .clksel_con = CRU_CLKSELS_CON(7),
1824 static struct clk clk_spdif_frac_div = {
1825 .name = "spdif_frac_div",
1826 .parent = &clk_spdif_div,
1828 .gate_idx = CLK_GATE_SPDIF_FRAC,
1829 .recalc = clksel_recalc_frac,
1830 .set_rate = clk_i2s_fracdiv_set_rate,
1831 .clksel_con = CRU_CLKSELS_CON(9),
1834 #define I2S_SRC_DIV (0x0)
1835 #define I2S_SRC_FRAC (0x1)
1836 #define I2S_SRC_12M (0x2)
1838 static int i2s_set_rate(struct clk *clk, unsigned long rate)
1843 if (rate == clk->parents[I2S_SRC_12M]->rate) {
1844 parent = clk->parents[I2S_SRC_12M];
1845 } else if((long)clk_round_rate_nolock(clk->parents[I2S_SRC_DIV], rate) == rate) {
1846 parent = clk->parents[I2S_SRC_DIV];
1848 parent = clk->parents[I2S_SRC_FRAC];
1851 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1852 clk->name, rate, parent->name, clk->parent->name);
1854 if(parent != clk->parents[I2S_SRC_12M]) {
1855 ret = clk_set_rate_nolock(parent, rate); //div 1:1
1857 CLKDATA_DBG("%s set rate%lu err\n", clk->name, rate);
1862 if (clk->parent != parent) {
1863 ret = clk_set_parent_nolock(clk, parent);
1865 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
1873 static struct clk *clk_i2s0_parents[3] = {&clk_i2s0_div, &clk_i2s0_frac_div, &clk_12m};
1875 static struct clk clk_i2s0 = {
1877 .set_rate = i2s_set_rate,
1878 .clksel_con = CRU_CLKSELS_CON(3),
1879 CRU_SRC_SET(0x3, 8),
1880 CRU_PARENTS_SET(clk_i2s0_parents),
1883 static struct clk *clk_spdif_parents[3] = {&clk_spdif_div, &clk_spdif_frac_div, &clk_12m};
1885 static struct clk clk_spdif = {
1887 .parent = &clk_spdif_frac_div,
1888 .set_rate = i2s_set_rate,
1889 .clksel_con = CRU_CLKSELS_CON(5),
1890 CRU_SRC_SET(0x3, 8),
1891 CRU_PARENTS_SET(clk_spdif_parents),
1894 /* otgphy setting */
1895 GATE_CLK(otgphy0, xin24m, OTGPHY0);
1896 GATE_CLK(otgphy1, xin24m, OTGPHY1);
1898 static struct clk clk_otgphy0_480m = {
1899 .name = "otgphy0_480m",
1900 .parent = &clk_otgphy0,
1902 static struct clk clk_otgphy1_480m = {
1903 .name = "otgphy1_480m",
1904 .parent = &clk_otgphy1,
1907 /* hsicphy setting */
1909 static struct clk *clk_hsicphy_parents[4] = {&clk_otgphy0_480m, &clk_otgphy1_480m, &general_pll_clk, &codec_pll_clk};
1910 static struct clk clk_hsicphy_480m = {
1911 .name = "hsicphy_480m",
1912 .parent = &clk_otgphy0_480m,
1913 .clksel_con = CRU_CLKSELS_CON(30),
1914 CRU_SRC_SET(0x3, 0),
1915 CRU_PARENTS_SET(clk_hsicphy_parents),
1917 static struct clk clk_hsicphy_12m = {
1918 .name = "hsicphy_12m",
1919 .parent = &clk_hsicphy_480m,
1920 .clksel_con = CRU_CLKSELS_CON(11),
1921 CRU_DIV_SET(0x3f, 8, 64),
1925 /* mac and rmii setting */
1927 static struct clk rmii_clkin = {
1928 .name = "rmii_clkin",
1930 static struct clk *clk_mac_ref_div_parents[2] = {&general_pll_clk, &ddr_pll_clk};
1931 static struct clk clk_mac_pll_div = {
1932 .name = "mac_pll_div",
1933 .parent = &general_pll_clk,
1935 .gate_idx = CLK_GATE_MAC_SRC,
1936 .recalc = clksel_recalc_div,
1937 .set_rate = clksel_set_rate_freediv,
1938 .clksel_con = CRU_CLKSELS_CON(21),
1939 CRU_DIV_SET(0x1f, 8, 32),
1940 CRU_SRC_SET(0x1, 0),
1941 CRU_PARENTS_SET(clk_mac_ref_div_parents),
1944 static int clksel_mac_ref_set_rate(struct clk *clk, unsigned long rate)
1946 if(clk->parent == clk->parents[1]) {
1947 CLKDATA_DBG("mac_ref clk is form mii clkin,can't set it\n" );
1949 } else if(clk->parent == clk->parents[0]) {
1950 return clk_set_rate_nolock(clk->parents[0], rate);
1955 static struct clk *clk_mac_ref_parents[2] = {&clk_mac_pll_div, &rmii_clkin};
1957 static struct clk clk_mac_ref = {
1959 .parent = &clk_mac_pll_div,
1960 .set_rate = clksel_mac_ref_set_rate,
1961 .clksel_con = CRU_CLKSELS_CON(21),
1962 CRU_SRC_SET(0x1, 4),
1963 CRU_PARENTS_SET(clk_mac_ref_parents),
1966 static int clk_set_mii_tx_parent(struct clk *clk, struct clk *parent)
1968 return clk_set_parent_nolock(clk->parent, parent);
1971 static struct clk clk_mii_tx = {
1973 .parent = &clk_mac_ref,
1974 //.set_parent = clk_set_mii_tx_parent,
1976 .gate_idx = CLK_GATE_MAC_LBTEST,
1979 /* hsadc and saradc */
1980 static struct clk *clk_hsadc_pll_parents[2] = {&general_pll_clk, &codec_pll_clk};
1981 static struct clk clk_hsadc_pll_div = {
1982 .name = "hsadc_pll_div",
1983 .parent = &general_pll_clk,
1985 .gate_idx = CLK_GATE_HSADC_SRC,
1986 .recalc = clksel_recalc_div,
1987 .round_rate = clk_freediv_round_autosel_parents_rate,
1988 .set_rate = clkset_rate_freediv_autosel_parents,
1989 //.round_rate = clksel_freediv_round_rate,
1990 //.set_rate = clksel_set_rate_freediv,
1991 .clksel_con = CRU_CLKSELS_CON(22),
1992 CRU_DIV_SET(0xff, 8, 256),
1993 CRU_SRC_SET(0x1, 0),
1994 CRU_PARENTS_SET(clk_hsadc_pll_parents),
1996 static int clk_hsadc_fracdiv_set_rate_fixed_parent(struct clk *clk, unsigned long rate)
1998 u32 numerator, denominator;
1999 // clk_hsadc_pll_div->gpll/cpll
2000 //clk->parent->parent
2001 if(frac_div_get_seting(rate, clk->parent->parent->rate,
2002 &numerator, &denominator) == 0) {
2003 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
2005 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2007 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
2009 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
2014 static int clk_hsadc_fracdiv_set_rate_auto_parents(struct clk *clk, unsigned long rate)
2016 u32 numerator, denominator;
2018 // clk_hsadc_pll_div->gpll/cpll
2019 //clk->parent->parent
2020 for(i = 0; i < 2; i++) {
2021 if(frac_div_get_seting(rate, clk->parent->parents[i]->rate,
2022 &numerator, &denominator) == 0)
2028 if(clk->parent->parent != clk->parent->parents[i])
2029 ret = clk_set_parent_nolock(clk->parent, clk->parent->parents[i]);
2031 clk_set_rate_nolock(clk->parent, clk->parent->parents[i]->rate); //PLL:DIV 1:
2033 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2035 CLKDATA_DBG("clk_frac_div %s, rate=%lu\n", clk->name, rate);
2037 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
2043 static long clk_hsadc_fracdiv_round_rate(struct clk *clk, unsigned long rate)
2045 u32 numerator, denominator;
2047 CLKDATA_ERR("clk_hsadc_fracdiv_round_rate\n");
2048 if(frac_div_get_seting(rate, clk->parent->parent->rate,
2049 &numerator, &denominator) == 0)
2054 static struct clk clk_hsadc_frac_div = {
2055 .name = "hsadc_frac_div",
2056 .parent = &clk_hsadc_pll_div,
2058 .recalc = clksel_recalc_frac,
2059 .set_rate = clk_hsadc_fracdiv_set_rate_auto_parents,
2060 .round_rate = clk_hsadc_fracdiv_round_rate,
2061 .gate_idx = CLK_GATE_HSADC_FRAC_SRC,
2062 .clksel_con = CRU_CLKSELS_CON(23),
2065 #define HSADC_SRC_DIV 0x0
2066 #define HSADC_SRC_FRAC 0x1
2067 #define HSADC_SRC_EXT 0x2
2068 static int clk_hsadc_set_rate(struct clk *clk, unsigned long rate)
2073 if(clk->parent == clk->parents[HSADC_SRC_EXT]) {
2074 CLKDATA_DBG("hsadc clk is form ext\n");
2076 } else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_DIV], rate) == rate) {
2077 parent = clk->parents[HSADC_SRC_DIV];
2078 } else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_FRAC], rate) == rate) {
2079 parent = clk->parents[HSADC_SRC_FRAC];
2081 parent = clk->parents[HSADC_SRC_DIV];
2083 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
2084 clk->name, rate, parent->name, clk->parent->name);
2086 ret = clk_set_rate_nolock(parent, rate);
2088 CLKDATA_ERR("%s set rate%lu err\n", clk->name, rate);
2091 if (clk->parent != parent) {
2092 ret = clk_set_parent_nolock(clk, parent);
2094 CLKDATA_ERR("%s can't get rate%lu,reparent err\n", clk->name, rate);
2101 static struct clk clk_hsadc_ext = {
2102 .name = "hsadc_ext",
2105 static struct clk *clk_hsadc_out_parents[3] = {&clk_hsadc_pll_div, &clk_hsadc_frac_div, &clk_hsadc_ext};
2106 static struct clk clk_hsadc_out = {
2107 .name = "hsadc_out",
2108 .parent = &clk_hsadc_pll_div,
2109 .set_rate = clk_hsadc_set_rate,
2110 .clksel_con = CRU_CLKSELS_CON(22),
2111 CRU_SRC_SET(0x3, 4),
2112 CRU_PARENTS_SET(clk_hsadc_out_parents),
2114 static struct clk clk_hsadc_out_inv = {
2115 .name = "hsadc_out_inv",
2116 .parent = &clk_hsadc_pll_div,
2119 static struct clk *clk_hsadc_parents[3] = {&clk_hsadc_out, &clk_hsadc_out_inv};
2120 static struct clk clk_hsadc = {
2122 .parent = &clk_hsadc_out,
2123 .clksel_con = CRU_CLKSELS_CON(22),
2124 CRU_SRC_SET(0x1, 7),
2125 CRU_PARENTS_SET(clk_hsadc_parents),
2128 static struct clk clk_saradc = {
2132 .recalc = clksel_recalc_div,
2133 .set_rate = clksel_set_rate_freediv,
2134 .gate_idx = CLK_GATE_SARADC_SRC,
2135 .clksel_con = CRU_CLKSELS_CON(24),
2136 CRU_DIV_SET(0xff, 8, 256),
2140 GATE_CLK(smc, hclk_periph, SMC_SRC);//smc
2141 static struct clk clkn_smc = {
2147 static struct clk clk_spi0 = {
2149 .parent = &pclk_periph,
2151 .recalc = clksel_recalc_div,
2152 .set_rate = clksel_set_rate_freediv,
2153 .gate_idx = CLK_GATE_SPI0_SRC,
2154 .clksel_con = CRU_CLKSELS_CON(25),
2155 CRU_DIV_SET(0x7f, 0, 128),
2158 static struct clk clk_spi1 = {
2160 .parent = &pclk_periph,
2162 .recalc = clksel_recalc_div,
2163 .set_rate = clksel_set_rate_freediv,
2164 .gate_idx = CLK_GATE_SPI1_SRC,
2165 .clksel_con = CRU_CLKSELS_CON(25),
2166 CRU_DIV_SET(0x7f, 8, 128),
2169 /* sdmmc/sdio/emmc setting */
2170 static struct clk clk_sdmmc = {
2172 .parent = &hclk_periph,
2174 .recalc = clksel_recalc_div,
2175 .set_rate = clksel_set_rate_even,
2176 .gate_idx = CLK_GATE_MMC0_SRC,
2177 .clksel_con = CRU_CLKSELS_CON(11),
2178 CRU_DIV_SET(0x3f, 0, 64),
2181 static struct clk clk_sdio = {
2183 .parent = &hclk_periph,
2185 .recalc = clksel_recalc_div,
2186 .set_rate = clksel_set_rate_even,
2187 .gate_idx = CLK_GATE_SDIO_SRC,
2188 .clksel_con = CRU_CLKSELS_CON(12),
2189 CRU_DIV_SET(0x3f, 0, 64),
2193 static struct clk clk_emmc = {
2195 .parent = &hclk_periph,
2197 .recalc = clksel_recalc_div,
2198 .set_rate = clksel_set_rate_freediv,
2199 .gate_idx = CLK_GATE_EMMC_SRC,
2200 .clksel_con = CRU_CLKSELS_CON(12),
2201 CRU_DIV_SET(0x3f, 8, 64),
2205 static struct clk *clk_uart_src_parents[2] = {&general_pll_clk, &codec_pll_clk};
2206 static struct clk clk_uart_pll = {
2208 .parent = &general_pll_clk,
2209 .clksel_con = CRU_CLKSELS_CON(12),
2210 CRU_SRC_SET(0x1, 15),
2211 CRU_PARENTS_SET(clk_uart_src_parents),
2213 static struct clk clk_uart0_div = {
2214 .name = "uart0_div",
2215 .parent = &clk_uart_pll,
2217 .gate_idx = CLK_GATE_UART0_SRC,
2218 .recalc = clksel_recalc_div,
2219 .set_rate = clksel_set_rate_freediv,
2220 .round_rate = clksel_freediv_round_rate,
2221 .clksel_con = CRU_CLKSELS_CON(13),
2222 CRU_DIV_SET(0x7f, 0, 64),
2224 static struct clk clk_uart1_div = {
2225 .name = "uart1_div",
2226 .parent = &clk_uart_pll,
2228 .gate_idx = CLK_GATE_UART1_SRC,
2229 .recalc = clksel_recalc_div,
2230 .round_rate = clksel_freediv_round_rate,
2231 .set_rate = clksel_set_rate_freediv,
2232 .clksel_con = CRU_CLKSELS_CON(14),
2233 CRU_DIV_SET(0x7f, 0, 64),
2236 static struct clk clk_uart2_div = {
2237 .name = "uart2_div",
2238 .parent = &clk_uart_pll,
2240 .gate_idx = CLK_GATE_UART2_SRC,
2241 .recalc = clksel_recalc_div,
2242 .round_rate = clksel_freediv_round_rate,
2243 .set_rate = clksel_set_rate_freediv,
2244 .clksel_con = CRU_CLKSELS_CON(15),
2245 CRU_DIV_SET(0x7f, 0, 64),
2248 static struct clk clk_uart3_div = {
2249 .name = "uart3_div",
2250 .parent = &clk_uart_pll,
2252 .gate_idx = CLK_GATE_UART3_SRC,
2253 .recalc = clksel_recalc_div,
2254 .round_rate = clksel_freediv_round_rate,
2255 .set_rate = clksel_set_rate_freediv,
2256 .clksel_con = CRU_CLKSELS_CON(16),
2257 CRU_DIV_SET(0x7f, 0, 64),
2259 static int clk_uart_fracdiv_set_rate(struct clk *clk, unsigned long rate)
2261 u32 numerator, denominator;
2262 //clk_uart0_div->clk_uart_pll->gpll/cpll
2263 //clk->parent->parent
2264 if(frac_div_get_seting(rate, clk->parent->parent->rate,
2265 &numerator, &denominator) == 0) {
2266 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
2268 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2270 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
2272 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
2278 static struct clk clk_uart0_frac_div = {
2279 .name = "uart0_frac_div",
2280 .parent = &clk_uart0_div,
2282 .recalc = clksel_recalc_frac,
2283 .set_rate = clk_uart_fracdiv_set_rate,
2284 .gate_idx = CLK_GATE_UART0_FRAC_SRC,
2285 .clksel_con = CRU_CLKSELS_CON(17),
2287 static struct clk clk_uart1_frac_div = {
2288 .name = "uart1_frac_div",
2289 .parent = &clk_uart1_div,
2291 .recalc = clksel_recalc_frac,
2292 .set_rate = clk_uart_fracdiv_set_rate,
2293 .gate_idx = CLK_GATE_UART1_FRAC_SRC,
2294 .clksel_con = CRU_CLKSELS_CON(18),
2296 static struct clk clk_uart2_frac_div = {
2297 .name = "uart2_frac_div",
2299 .parent = &clk_uart2_div,
2300 .recalc = clksel_recalc_frac,
2301 .set_rate = clk_uart_fracdiv_set_rate,
2302 .gate_idx = CLK_GATE_UART2_FRAC_SRC,
2303 .clksel_con = CRU_CLKSELS_CON(19),
2305 static struct clk clk_uart3_frac_div = {
2306 .name = "uart3_frac_div",
2307 .parent = &clk_uart3_div,
2309 .recalc = clksel_recalc_frac,
2310 .set_rate = clk_uart_fracdiv_set_rate,
2311 .gate_idx = CLK_GATE_UART3_FRAC_SRC,
2312 .clksel_con = CRU_CLKSELS_CON(20),
2315 #define UART_SRC_DIV 0
2316 #define UART_SRC_FRAC 1
2317 #define UART_SRC_24M 2
2319 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
2324 if(rate == clk->parents[UART_SRC_24M]->rate) { //24m
2325 parent = clk->parents[UART_SRC_24M];
2326 } else if((long)clk_round_rate_nolock(clk->parents[UART_SRC_DIV], rate) == rate) {
2327 parent = clk->parents[UART_SRC_DIV];
2329 parent = clk->parents[UART_SRC_FRAC];
2332 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
2333 clk->name, rate, parent->name, clk->parent->name);
2335 if(parent != clk->parents[UART_SRC_24M]) {
2336 ret = clk_set_rate_nolock(parent, rate);
2338 CLKDATA_DBG("%s set rate%lu err\n", clk->name, rate);
2343 if (clk->parent != parent) {
2344 ret = clk_set_parent_nolock(clk, parent);
2346 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
2354 static struct clk *clk_uart0_parents[3] = {&clk_uart0_div, &clk_uart0_frac_div, &xin24m};
2355 static struct clk clk_uart0 = {
2357 .set_rate = clk_uart_set_rate,
2358 .clksel_con = CRU_CLKSELS_CON(13),
2359 CRU_SRC_SET(0x3, 8),
2360 CRU_PARENTS_SET(clk_uart0_parents),
2363 static struct clk *clk_uart1_parents[3] = {&clk_uart1_div, &clk_uart1_frac_div, &xin24m};
2364 static struct clk clk_uart1 = {
2366 .set_rate = clk_uart_set_rate,
2367 .clksel_con = CRU_CLKSELS_CON(14),
2368 CRU_SRC_SET(0x3, 8),
2369 CRU_PARENTS_SET(clk_uart1_parents),
2372 static struct clk *clk_uart2_parents[3] = {&clk_uart2_div, &clk_uart2_frac_div, &xin24m};
2373 static struct clk clk_uart2 = {
2375 .set_rate = clk_uart_set_rate,
2376 .clksel_con = CRU_CLKSELS_CON(15),
2377 CRU_SRC_SET(0x3, 8),
2378 CRU_PARENTS_SET(clk_uart2_parents),
2380 static struct clk *clk_uart3_parents[3] = {&clk_uart3_div, &clk_uart3_frac_div, &xin24m};
2381 static struct clk clk_uart3 = {
2383 .set_rate = clk_uart_set_rate,
2384 .clksel_con = CRU_CLKSELS_CON(16),
2385 CRU_SRC_SET(0x3, 8),
2386 CRU_PARENTS_SET(clk_uart3_parents),
2390 GATE_CLK(timer0, xin24m, TIMER0);
2391 GATE_CLK(timer1, xin24m, TIMER1);
2392 GATE_CLK(timer2, xin24m, TIMER2);
2394 /*********************power domain*******************************/
2396 #ifdef RK30_CLK_OFFBOARD_TEST
2397 void pmu_set_power_domain_test(enum pmu_power_domain pd, bool on) {};
2398 #define _pmu_set_power_domain pmu_set_power_domain_test//rk30_pmu_set_power_domain
2400 void pmu_set_power_domain(enum pmu_power_domain pd, bool on);
2401 #define _pmu_set_power_domain pmu_set_power_domain
2404 static int pd_video_mode(struct clk *clk, int on)
2407 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2408 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2409 //gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2410 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2411 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2412 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2413 pmu_set_power_domain(PD_VIDEO, on);
2414 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2415 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2416 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2420 static struct clk pd_video = {
2423 .mode = pd_video_mode,
2424 .gate_idx = PD_VIDEO,
2426 static int pd_display_mode(struct clk *clk, int on)
2429 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2430 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2431 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2432 gate[3] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2433 gate[4] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2434 //gate[5] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2435 gate[6] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2436 gate[7] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2437 gate[8] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2438 gate[9] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2439 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2440 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2441 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2442 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2443 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2444 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2445 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2446 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2447 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2448 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2449 pmu_set_power_domain(PD_VIO, on);
2450 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2451 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2452 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2453 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1) | gate[3], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2454 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0) | gate[4], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2455 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1) | gate[5], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2456 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0) | gate[6], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2457 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1) | gate[7], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2458 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP) | gate[8], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2459 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA) | gate[9], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2463 static struct clk pd_display = {
2466 .mode = pd_display_mode,
2469 static struct clk pd_lcdc0 = {
2470 .parent = &pd_display,
2473 static struct clk pd_lcdc1 = {
2474 .parent = &pd_display,
2477 static struct clk pd_cif0 = {
2478 .parent = &pd_display,
2481 static struct clk pd_rga = {
2482 .parent = &pd_display,
2485 static struct clk pd_ipp = {
2486 .parent = &pd_display,
2489 static struct clk pd_hdmi = {
2490 .parent = &pd_display,
2495 static int pd_gpu_mode(struct clk *clk, int on)
2498 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_CLK_GPU));
2499 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU_MST));
2500 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU_SLV));
2501 cru_writel(CLK_GATE_W_MSK(CLK_GATE_CLK_GPU), CLK_GATE_CLKID_CONS(CLK_GATE_CLK_GPU));
2502 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU_SLV), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU_SLV));
2503 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU_MST), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU_MST));
2504 pmu_set_power_domain(PD_GPU, on);
2505 cru_writel(CLK_GATE_W_MSK(CLK_GATE_CLK_GPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_CLK_GPU));
2506 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU_SLV) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU_SLV));
2507 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU_MST) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU_MST));
2511 static struct clk pd_gpu = {
2514 .mode = pd_gpu_mode,
2518 static int pm_off_mode(struct clk *clk, int on)
2520 _pmu_set_power_domain(clk->gate_idx, on); //on 1
2523 static struct clk pd_peri = {
2526 .mode = pm_off_mode,
2527 .gate_idx = PD_PERI,
2531 #define PD_CLK(name) \
2539 /************************rk30 fixed div clock****************************************/
2541 /*************************aclk_cpu***********************/
2543 GATE_CLK(dma1, aclk_cpu, ACLK_DMAC1);
2544 GATE_CLK(l2mem_con, aclk_cpu, ACLK_L2MEM_CON);
2545 GATE_CLK(intmem, aclk_cpu, ACLK_INTMEM);
2546 GATE_CLK(aclk_strc_sys, aclk_cpu, ACLK_STRC_SYS);
2548 /*************************hclk_cpu***********************/
2550 GATE_CLK(rom, hclk_cpu, HCLK_ROM);
2551 GATE_CLK(hclk_i2s0_2ch, hclk_cpu, HCLK_I2S0_2CH);
2552 GATE_CLK(hclk_spdif, hclk_cpu, HCLK_SPDIF);
2553 GATE_CLK(hclk_cpubus, hclk_cpu, HCLK_CPUBUS);
2554 GATE_CLK(hclk_ahb2apb, hclk_cpu, HCLK_AHB2APB);
2555 GATE_CLK(hclk_vio_bus, hclk_cpu, HCLK_VIO_BUS);
2556 GATE_CLK(hclk_lcdc0, hclk_cpu, HCLK_LCDC0);
2557 GATE_CLK(hclk_lcdc1, hclk_cpu, HCLK_LCDC1);
2558 GATE_CLK(hclk_cif0, hclk_cpu, HCLK_CIF0);
2559 GATE_CLK(hclk_ipp, hclk_cpu, HCLK_IPP);
2560 GATE_CLK(hclk_rga, hclk_cpu, HCLK_RGA);
2561 GATE_CLK(hclk_l2mem, hclk_cpu, HCLK_L2MEM);
2562 GATE_CLK(hclk_video_h2h, hclk_cpu, HCLK_VIDEO_H2H);
2563 /*************************pclk_cpu***********************/
2564 GATE_CLK(pwm01, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2565 GATE_CLK(pclk_timer0, pclk_cpu, PCLK_TIMER0);
2566 GATE_CLK(pclk_timer1, pclk_cpu, PCLK_TIMER1);
2567 GATE_CLK(pclk_timer2, pclk_cpu, PCLK_TIMER2);
2568 GATE_CLK(i2c0, pclk_cpu, PCLK_I2C0);
2569 GATE_CLK(i2c1, pclk_cpu, PCLK_I2C1);
2570 GATE_CLK(gpio0, pclk_cpu, PCLK_GPIO0);
2571 GATE_CLK(gpio1, pclk_cpu, PCLK_GPIO1);
2572 GATE_CLK(gpio2, pclk_cpu, PCLK_GPIO2);
2573 GATE_CLK(efuse, pclk_cpu, PCLK_EFUSE);
2574 GATE_CLK(tzpc, pclk_cpu, PCLK_TZPC);
2575 GATE_CLK(pclk_uart0, pclk_cpu, PCLK_UART0);
2576 GATE_CLK(pclk_uart1, pclk_cpu, PCLK_UART1);
2577 GATE_CLK(pclk_ddrupctl, pclk_cpu, PCLK_DDRUPCTL);
2578 GATE_CLK(pclk_ddrpubl, pclk_cpu, PCLK_PUBL);
2579 GATE_CLK(dbg, pclk_cpu, PCLK_DBG);
2580 GATE_CLK(grf, pclk_cpu, PCLK_GRF);
2581 GATE_CLK(pmu, pclk_cpu, PCLK_PMU);
2583 /*************************aclk_periph***********************/
2585 GATE_CLK(dma2, aclk_periph, ACLK_DMAC2);
2586 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
2587 GATE_CLK(aclk_peri_niu, aclk_periph, ACLK_PEI_NIU);
2588 GATE_CLK(aclk_cpu_peri, aclk_periph, ACLK_CPU_PERI);
2589 GATE_CLK(aclk_peri_axi_matrix, aclk_periph, ACLK_PERI_AXI_MATRIX);
2591 /*************************hclk_periph***********************/
2592 GATE_CLK(hclk_peri_axi_matrix, hclk_periph, HCLK_PERI_AXI_MATRIX);
2593 GATE_CLK(hclk_peri_ahb_arbi, hclk_periph, HCLK_PERI_AHB_ARBI);
2594 GATE_CLK(hclk_emem_peri, hclk_periph, HCLK_EMEM_PERI);
2595 GATE_CLK(hclk_mac, hclk_periph, HCLK_EMAC);
2596 GATE_CLK(nandc, hclk_periph, HCLK_NANDC);
2597 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
2598 GATE_CLK(hclk_otg0, clk_hclk_usb_peri, HCLK_OTG0);
2599 GATE_CLK(hclk_otg1, clk_hclk_usb_peri, HCLK_OTG1);
2600 GATE_CLK(hclk_hsic, hclk_periph, HCLK_HSIC);
2601 GATE_CLK(hclk_gps, hclk_periph, HCLK_GPS);
2602 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
2603 GATE_CLK(hclk_pidfilter, hclk_periph, HCLK_PIDF);
2604 GATE_CLK(hclk_sdmmc, hclk_periph, HCLK_SDMMC0);
2605 GATE_CLK(hclk_sdio, hclk_periph, HCLK_SDIO);
2606 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
2607 /*************************pclk_periph***********************/
2608 GATE_CLK(pclk_peri_axi_matrix, pclk_periph, PCLK_PERI_AXI_MATRIX);
2609 GATE_CLK(pwm23, pclk_periph, PCLK_PWM23);
2610 GATE_CLK(wdt, pclk_periph, PCLK_WDT);
2611 GATE_CLK(pclk_spi0, pclk_periph, PCLK_SPI0);
2612 GATE_CLK(pclk_spi1, pclk_periph, PCLK_SPI1);
2613 GATE_CLK(pclk_uart2, pclk_periph, PCLK_UART2);
2614 GATE_CLK(pclk_uart3, pclk_periph, PCLK_UART3);
2615 GATE_CLK(i2c2, pclk_periph, PCLK_I2C2);
2616 GATE_CLK(i2c3, pclk_periph, PCLK_I2C3);
2617 GATE_CLK(i2c4, pclk_periph, PCLK_I2C4);
2618 GATE_CLK(gpio3, pclk_periph, PCLK_GPIO3);
2619 GATE_CLK(pclk_saradc, pclk_periph, PCLK_SARADC);
2620 /*************************aclk_lcdc0***********************/
2622 GATE_CLK(aclk_vio0, aclk_lcdc0_pre, ACLK_VIO0);
2624 GATE_CLK(aclk_lcdc0, clk_aclk_vio0, ACLK_LCDC0);
2625 GATE_CLK(aclk_cif0, clk_aclk_vio0, ACLK_CIF0);
2626 GATE_CLK(aclk_ipp, clk_aclk_vio0, ACLK_IPP);
2628 /*************************aclk_lcdc0***********************/
2630 GATE_CLK(aclk_vio1, aclk_lcdc1_pre, ACLK_VIO1);
2631 GATE_CLK(aclk_lcdc1, clk_aclk_vio1, ACLK_LCDC1);
2632 GATE_CLK(aclk_rga, clk_aclk_vio1, ACLK_RGA);
2636 #define CLK(dev, con, ck) \
2644 #define CLK1(name) \
2648 .clk = &clk_##name,\
2653 static struct clk_lookup clks[] = {
2654 CLK(NULL, "xin24m", &xin24m),
2655 //CLK(NULL, "xin27m", &xin27m),
2656 CLK(NULL, "xin12m", &clk_12m),
2657 CLK(NULL, "arm_pll", &arm_pll_clk),
2658 CLK(NULL, "ddr_pll", &ddr_pll_clk),
2659 CLK(NULL, "codec_pll", &codec_pll_clk),
2660 CLK(NULL, "general_pll", &general_pll_clk),
2662 CLK(NULL, "ddr", &clk_ddr),
2663 CLK(NULL, "cpu", &clk_core),
2664 CLK(NULL, "logic", &clk_cpu_div),
2665 CLK(NULL, "arm_gpll", &clk_core_gpll_path),
2668 CLK("smp_twd", NULL, &core_periph),
2669 CLK(NULL, "aclk_core", &aclk_core),
2670 CLK(NULL, "aclk_cpu", &aclk_cpu),
2671 CLK(NULL, "pclk_cpu", &pclk_cpu),
2672 CLK(NULL, "atclk_cpu", &atclk_cpu),
2673 CLK(NULL, "hclk_cpu", &hclk_cpu),
2674 CLK(NULL, "ahb2apb_cpu", &ahb2apb_cpu),
2677 #ifdef GPU_CORE_ACLK_CTR_TOGETHER
2678 CLK(NULL, "aclk_gpu_real",&aclk_gpu),
2679 CLK(NULL, "aclk_gpu", &aclk_gpu_null),
2681 CLK(NULL, "aclk_gpu", &aclk_gpu),
2683 CLK(NULL, "gpu_slv", &aclk_gpu_slv),
2684 CLK(NULL, "gpu_mst", &aclk_gpu_mst),
2686 CLK(NULL, "aclk_vepu", &aclk_vepu),
2687 CLK(NULL, "hclk_vepu", &hclk_vepu),
2688 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
2689 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
2691 CLK(NULL, "aclk_lcdc0_pre", &aclk_lcdc0_pre),
2692 CLK(NULL, "aclk_lcdc1_pre", &aclk_lcdc1_pre),
2694 CLK(NULL, "aclk_periph", &aclk_periph),
2695 CLK(NULL, "pclk_periph", &pclk_periph),
2696 CLK(NULL, "hclk_periph", &hclk_periph),
2698 CLK(NULL, "dclk_lcdc0", &dclk_lcdc0),
2699 CLK(NULL, "dclk_lcdc1", &dclk_lcdc1),
2701 CLK(NULL, "cif_out_pll", &cif_out_pll),
2702 CLK(NULL, "cif0_out_div", &cif0_out_div),
2704 CLK(NULL, "cif0_out", &cif0_out),
2705 CLK(NULL, "pclkin_cif0", &pclkin_cif0),
2706 CLK(NULL, "inv_cif0", &inv_cif0),
2707 CLK(NULL, "cif0_in", &cif0_in),
2710 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
2711 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
2712 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
2715 CLK("rk29_i2s.1", "i2s_div", &clk_i2s0_div),
2716 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s0_frac_div),
2717 CLK("rk29_i2s.1", "i2s", &clk_i2s0),
2721 CLK1(spdif_frac_div),
2731 CLK(NULL, "rmii_clkin", &rmii_clkin),
2732 CLK(NULL, "mac_ref_div", &clk_mac_pll_div), // compatible with rk29
2736 CLK1(hsadc_pll_div),
2737 CLK1(hsadc_frac_div),
2740 CLK1(hsadc_out_inv),
2746 CLK(NULL, "smc_inv", &clkn_smc),
2748 CLK("rk29xx_spim.0", "spi", &clk_spi0),
2749 CLK("rk29xx_spim.1", "spi", &clk_spi1),
2751 CLK("rk29_sdmmc.0", "mmc", &clk_sdmmc),
2752 CLK("rk29_sdmmc.1", "mmc", &clk_sdio),
2756 CLK("rk_serial.0", "uart_div", &clk_uart0_div),
2757 CLK("rk_serial.0", "uart_frac_div", &clk_uart0_frac_div),
2758 CLK("rk_serial.0", "uart", &clk_uart0),
2759 CLK("rk_serial.1", "uart_div", &clk_uart1_div),
2760 CLK("rk_serial.1", "uart_frac_div", &clk_uart1_frac_div),
2761 CLK("rk_serial.1", "uart", &clk_uart1),
2762 CLK("rk_serial.2", "uart_div", &clk_uart2_div),
2763 CLK("rk_serial.2", "uart_frac_div", &clk_uart2_frac_div),
2764 CLK("rk_serial.2", "uart", &clk_uart2),
2765 CLK("rk_serial.3", "uart_div", &clk_uart3_div),
2766 CLK("rk_serial.3", "uart_frac_div", &clk_uart3_frac_div),
2767 CLK("rk_serial.3", "uart", &clk_uart3),
2773 /*************************aclk_cpu***********************/
2777 CLK1(aclk_strc_sys),
2779 /*************************hclk_cpu***********************/
2781 CLK("rk29_i2s.0", "hclk_i2s", &clk_hclk_i2s0_2ch),
2783 CLK("rk29_i2s.1", "hclk_i2s", &clk_hclk_i2s0_2ch),
2793 CLK1(hclk_video_h2h),
2796 /*************************pclk_cpu***********************/
2801 CLK("rk30_i2c.0", "i2c", &clk_i2c0),
2802 CLK("rk30_i2c.1", "i2c", &clk_i2c1),
2808 CLK("rk_serial.0", "pclk_uart", &clk_pclk_uart0),
2809 CLK("rk_serial.1", "pclk_uart", &clk_pclk_uart1),
2810 CLK1(pclk_ddrupctl),
2816 /*************************aclk_periph***********************/
2819 CLK1(aclk_peri_niu),
2820 CLK1(aclk_cpu_peri),
2821 CLK1(aclk_peri_axi_matrix),
2823 /*************************hclk_periph***********************/
2824 CLK1(hclk_peri_axi_matrix),
2825 CLK1(hclk_peri_ahb_arbi),
2826 CLK1(hclk_emem_peri),
2829 CLK1(hclk_usb_peri),
2835 CLK1(hclk_pidfilter),
2836 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_sdmmc),
2837 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_sdio),
2840 /*************************pclk_periph***********************/
2841 CLK1(pclk_peri_axi_matrix),
2844 CLK("rk29xx_spim.0", "pclk_spi", &clk_pclk_spi0),
2845 CLK("rk29xx_spim.1", "pclk_spi", &clk_pclk_spi1),
2846 CLK("rk_serial.2", "pclk_uart", &clk_pclk_uart2),
2847 CLK("rk_serial.3", "pclk_uart", &clk_pclk_uart3),
2848 CLK("rk30_i2c.2", "i2c", &clk_i2c2),
2849 CLK("rk30_i2c.3", "i2c", &clk_i2c3),
2850 CLK("rk30_i2c.4", "i2c", &clk_i2c4),
2854 /*************************aclk_lcdc0***********************/
2856 CLK(NULL, "aclk_lcdc0", &clk_aclk_lcdc0),
2860 /*************************aclk_lcdc1***********************/
2862 CLK(NULL, "aclk_lcdc1", &clk_aclk_lcdc1),
2864 /************************power domain**********************/
2879 static void __init rk30_init_enable_clocks(void)
2882 //clk_enable_nolock(&xin24m);
2883 //clk_enable_nolock(&clk_12m);
2884 //clk_enable_nolock(&arm_pll_clk);
2885 //clk_enable_nolock(&ddr_pll_clk);
2886 //clk_enable_nolock(&codec_pll_clk);
2887 //clk_enable_nolock(&general_pll_clk);
2889 clk_enable_nolock(&clk_ddr);
2890 //clk_enable_nolock(&clk_core);
2891 clk_enable_nolock(&clk_cpu_div);
2892 clk_enable_nolock(&clk_core_gpll_path);
2893 clk_enable_nolock(&clk_l2c);
2894 clk_enable_nolock(&clk_core_dbg);
2895 clk_enable_nolock(&core_periph);
2896 clk_enable_nolock(&aclk_core);
2897 //clk_enable_nolock(&aclk_cpu);
2898 //clk_enable_nolock(&pclk_cpu);
2899 clk_enable_nolock(&atclk_cpu);
2900 //clk_enable_nolock(&hclk_cpu);
2901 clk_enable_nolock(&ahb2apb_cpu);
2903 clk_enable_nolock(&clk_gpu);
2904 clk_enable_nolock(&aclk_gpu);
2905 clk_enable_nolock(&aclk_gpu_slv);
2906 clk_enable_nolock(&aclk_gpu_mst);
2908 clk_enable_nolock(&aclk_vepu);
2909 clk_enable_nolock(&hclk_vepu);
2910 clk_enable_nolock(&aclk_vdpu);
2911 clk_enable_nolock(&hclk_vdpu);
2913 clk_enable_nolock(&aclk_lcdc0_pre);
2914 clk_enable_nolock(&aclk_lcdc1_pre);
2916 clk_enable_nolock(&aclk_periph);
2917 clk_enable_nolock(&pclk_periph);
2918 clk_enable_nolock(&hclk_periph);
2921 clk_enable_nolock(&dclk_lcdc0);
2922 clk_enable_nolock(&dclk_lcdc1);
2924 clk_enable_nolock(&cif_out_pll);
2925 clk_enable_nolock(&cif0_out_div);
2927 clk_enable_nolock(&cif0_out);
2928 clk_enable_nolock(&pclkin_cif0);
2929 clk_enable_nolock(&inv_cif0);
2930 clk_enable_nolock(&cif0_in);
2932 clk_enable_nolock(&clk_i2s_pll);
2933 clk_enable_nolock(&clk_i2s0_div);
2934 clk_enable_nolock(&clk_i2s0_frac_div);
2935 clk_enable_nolock(&clk_i2s0);
2938 clk_enable_nolock(&clk_i2s0_div);
2939 clk_enable_nolock(&clk_i2s0_frac_div);
2940 clk_enable_nolock(&clk_i2s0);
2942 clk_enable_nolock(&clk_spdif_div);
2943 clk_enable_nolock(&clk_spdif_frac_div);
2944 clk_enable_nolock(&clk_spdif);
2947 clk_enable_nolock(&clk_otgphy0);
2948 clk_enable_nolock(&clk_otgphy1);
2949 clk_enable_nolock(&clk_otgphy0_480m);
2950 clk_enable_nolock(&clk_otgphy1_480m);
2951 clk_enable_nolock(&clk_hsicphy_480m);
2952 clk_enable_nolock(&clk_hsicphy_12m);
2956 clk_enable_nolock(&rmii_clkin);
2957 clk_enable_nolock(&clk_mac_pll_div); // compatible with rk29
2958 clk_enable_nolock(&clk_mac_ref);
2959 clk_enable_nolock(&clk_mii_tx);
2963 clk_enable_nolock(&clk_hsadc_pll_div);
2964 clk_enable_nolock(&clk_hsadc_frac_div);
2965 clk_enable_nolock(&clk_hsadc_ext);
2966 clk_enable_nolock(&clk_hsadc_out);
2967 clk_enable_nolock(&clk_hsadc_out_inv);
2968 clk_enable_nolock(&clk_hsadc);
2970 clk_enable_nolock(&clk_saradc);
2973 clk_enable_nolock(&clk_smc);
2974 clk_enable_nolock(&clkn_smc);
2977 clk_enable_nolock(&clk_spi0);
2978 clk_enable_nolock(&clk_spi1);
2981 clk_enable_nolock(&clk_sdmmc);
2982 clk_enable_nolock(&clk_sdio);
2983 clk_enable_nolock(&clk_emmc);
2986 clk_enable_nolock(&clk_uart_pll);
2987 clk_enable_nolock(&clk_uart0_div);
2988 clk_enable_nolock(&clk_uart0_frac_div);
2989 clk_enable_nolock(&clk_uart0);
2990 clk_enable_nolock(&clk_uart1_div);
2991 clk_enable_nolock(&clk_uart1_frac_div);
2992 clk_enable_nolock(&clk_uart1);
2993 clk_enable_nolock(&clk_uart2_div);
2994 clk_enable_nolock(&clk_uart2_frac_div);
2995 clk_enable_nolock(&clk_uart2);
2996 clk_enable_nolock(&clk_uart3_div);
2997 clk_enable_nolock(&clk_uart3_frac_div);
2998 clk_enable_nolock(&clk_uart3);
3000 #if CONFIG_RK_DEBUG_UART == 0
3001 clk_enable_nolock(&clk_uart0);
3002 clk_enable_nolock(&clk_pclk_uart0);
3003 #elif CONFIG_RK_DEBUG_UART == 1
3004 clk_enable_nolock(&clk_uart1);
3005 clk_enable_nolock(&clk_pclk_uart1);
3007 #elif CONFIG_RK_DEBUG_UART == 2
3008 clk_enable_nolock(&clk_uart2);
3009 clk_enable_nolock(&clk_pclk_uart2);
3011 #elif CONFIG_RK_DEBUG_UART == 3
3012 clk_enable_nolock(&clk_uart3);
3013 clk_enable_nolock(&clk_pclk_uart3);
3017 clk_enable_nolock(&clk_timer0);
3018 clk_enable_nolock(&clk_timer1);
3019 clk_enable_nolock(&clk_timer2);
3022 /*************************aclk_cpu***********************/
3023 clk_enable_nolock(&clk_dma1);
3024 clk_enable_nolock(&clk_l2mem_con);
3025 clk_enable_nolock(&clk_intmem);
3026 clk_enable_nolock(&clk_aclk_strc_sys);
3028 /*************************hclk_cpu***********************/
3029 clk_enable_nolock(&clk_rom);
3031 clk_enable_nolock(&clk_hclk_i2s0_2ch);
3033 clk_enable_nolock(&clk_hclk_i2s0_2ch);
3034 clk_enable_nolock(&clk_hclk_spdif);
3036 clk_enable_nolock(&clk_hclk_cpubus);
3037 clk_enable_nolock(&clk_hclk_ahb2apb);
3038 clk_enable_nolock(&clk_hclk_vio_bus);
3040 clk_enable_nolock(&clk_hclk_lcdc0);
3041 clk_enable_nolock(&clk_hclk_lcdc1);
3042 clk_enable_nolock(&clk_hclk_cif0);
3043 clk_enable_nolock(&clk_hclk_ipp);
3044 clk_enable_nolock(&clk_hclk_rga);
3046 clk_enable_nolock(&clk_hclk_video_h2h);
3047 clk_enable_nolock(&clk_hclk_l2mem);
3049 /*************************pclk_cpu***********************/
3051 clk_enable_nolock(&clk_pwm01);
3052 clk_enable_nolock(&clk_pclk_timer0);
3053 clk_enable_nolock(&clk_pclk_timer1);
3054 clk_enable_nolock(&clk_pclk_timer2);
3055 clk_enable_nolock(&clk_i2c0);
3056 clk_enable_nolock(&clk_i2c1);
3057 clk_enable_nolock(&clk_gpio0);
3058 clk_enable_nolock(&clk_gpio1);
3059 clk_enable_nolock(&clk_gpio2);
3060 clk_enable_nolock(&clk_efuse);
3062 clk_enable_nolock(&clk_tzpc);
3063 //clk_enable_nolock(&clk_pclk_uart0);
3064 //clk_enable_nolock(&clk_pclk_uart1);
3065 clk_enable_nolock(&clk_pclk_ddrupctl);
3066 clk_enable_nolock(&clk_pclk_ddrpubl);
3067 clk_enable_nolock(&clk_dbg);
3068 clk_enable_nolock(&clk_grf);
3069 clk_enable_nolock(&clk_pmu);
3071 /*************************aclk_periph***********************/
3072 clk_enable_nolock(&clk_dma2);
3073 clk_enable_nolock(&clk_aclk_smc);
3074 clk_enable_nolock(&clk_aclk_peri_niu);
3075 clk_enable_nolock(&clk_aclk_cpu_peri);
3076 clk_enable_nolock(&clk_aclk_peri_axi_matrix);
3078 /*************************hclk_periph***********************/
3079 clk_enable_nolock(&clk_hclk_peri_axi_matrix);
3080 clk_enable_nolock(&clk_hclk_peri_ahb_arbi);
3081 clk_enable_nolock(&clk_hclk_emem_peri);
3082 //clk_enable_nolock(&clk_hclk_mac);
3083 //clk_enable_nolock(&clk_nandc);
3084 clk_enable_nolock(&clk_hclk_usb_peri);
3086 clk_enable_nolock(&clk_hclk_otg0);
3087 clk_enable_nolock(&clk_hclk_otg1);
3088 clk_enable_nolock(&clk_hclk_hsic);
3089 clk_enable_nolock(&clk_hclk_gps);
3090 clk_enable_nolock(&clk_hclk_hsadc);
3091 clk_enable_nolock(&clk_hclk_pidfilter);
3092 clk_enable_nolock(&clk_hclk_sdmmc);
3093 clk_enable_nolock(&clk_hclk_sdio);
3094 clk_enable_nolock(&clk_hclk_emmc);
3097 /*************************pclk_periph***********************/
3098 clk_enable_nolock(&clk_pclk_peri_axi_matrix);
3100 clk_enable_nolock(&clk_pwm23);
3101 clk_enable_nolock(&clk_wdt);
3102 clk_enable_nolock(&clk_pclk_spi0);
3103 clk_enable_nolock(&clk_pclk_spi1);
3104 clk_enable_nolock(&clk_pclk_uart2);
3105 clk_enable_nolock(&clk_pclk_uart3);
3108 clk_enable_nolock(&clk_i2c2);
3109 clk_enable_nolock(&clk_i2c3);
3110 clk_enable_nolock(&clk_i2c4);
3111 clk_enable_nolock(&clk_gpio3);
3112 clk_enable_nolock(&clk_pclk_saradc);
3114 /*************************aclk_lcdc0***********************/
3116 //clk_enable_nolock(&clk_aclk_vio0);
3117 //clk_enable_nolock(&clk_aclk_lcdc0);
3118 //clk_enable_nolock(&clk_aclk_cif0);
3119 //clk_enable_nolock(&clk_aclk_ipp);
3121 /*************************aclk_lcdc1***********************/
3123 //clk_enable_nolock(&clk_aclk_vio1);
3124 //clk_enable_nolock(&clk_aclk_lcdc1);
3125 //clk_enable_nolock(&clk_aclk_rga);
3127 /************************power domain**********************/
3130 static void periph_clk_set_init(void)
3132 unsigned long aclk_p, hclk_p, pclk_p;
3133 unsigned long ppll_rate = general_pll_clk.rate;
3137 switch (ppll_rate) {
3139 aclk_p = 148500 * KHZ;
3140 hclk_p = aclk_p >> 1;
3141 pclk_p = aclk_p >> 2;
3144 aclk_p = aclk_p >> 3; // 0
3145 hclk_p = aclk_p >> 1;
3146 pclk_p = aclk_p >> 2;
3149 aclk_p = ppll_rate >> 1;
3150 hclk_p = aclk_p >> 0;
3151 pclk_p = aclk_p >> 1;
3155 aclk_p = ppll_rate >> 1;
3156 hclk_p = aclk_p >> 0;
3157 pclk_p = aclk_p >> 1;
3160 aclk_p = ppll_rate >> 2;
3161 hclk_p = aclk_p >> 0;
3162 pclk_p = aclk_p >> 1;
3170 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3171 clk_set_rate_nolock(&aclk_periph, aclk_p);
3172 clk_set_rate_nolock(&hclk_periph, hclk_p);
3173 clk_set_rate_nolock(&pclk_periph, pclk_p);
3176 static void cpu_axi_init(void)
3178 unsigned long cpu_div_rate, aclk_cpu_rate, hclk_cpu_rate, pclk_cpu_rate, ahb2apb_cpu_rate;
3179 unsigned long gpll_rate = general_pll_clk.rate;
3181 switch (gpll_rate) {
3183 cpu_div_rate = gpll_rate;
3184 aclk_cpu_rate = cpu_div_rate >> 0;
3185 hclk_cpu_rate = aclk_cpu_rate >> 1;
3186 pclk_cpu_rate = aclk_cpu_rate >> 2;
3190 cpu_div_rate = gpll_rate >> 1;
3191 aclk_cpu_rate = cpu_div_rate >> 0;
3192 hclk_cpu_rate = aclk_cpu_rate >> 1;
3193 pclk_cpu_rate = aclk_cpu_rate >> 2;
3196 aclk_cpu_rate = 150 * MHZ;
3197 hclk_cpu_rate = 150 * MHZ;
3198 pclk_cpu_rate = 75 * MHZ;
3201 ahb2apb_cpu_rate = pclk_cpu_rate;
3203 clk_set_parent_nolock(&clk_cpu_div, &general_pll_clk);
3204 clk_set_rate_nolock(&clk_cpu_div, cpu_div_rate);
3205 clk_set_rate_nolock(&aclk_cpu, aclk_cpu_rate);
3206 clk_set_rate_nolock(&hclk_cpu, hclk_cpu_rate);
3207 clk_set_rate_nolock(&pclk_cpu, pclk_cpu_rate);
3208 clk_set_rate_nolock(&ahb2apb_cpu, ahb2apb_cpu_rate);
3211 void rk30_clock_common_i2s_init(void)
3213 unsigned long i2s_rate;
3215 if(rk30_clock_flags & CLK_FLG_MAX_I2S_49152KHZ) {
3216 i2s_rate = 49152000;
3217 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_24576KHZ) {
3218 i2s_rate = 24576000;
3219 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_22579_2KHZ) {
3220 i2s_rate = 22579000;
3221 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_12288KHZ) {
3222 i2s_rate = 12288000;
3224 i2s_rate = 49152000;
3227 if(((i2s_rate * 20) <= general_pll_clk.rate) || !(general_pll_clk.rate % i2s_rate)) {
3228 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3229 } else if(((i2s_rate * 20) <= codec_pll_clk.rate) || !(codec_pll_clk.rate % i2s_rate)) {
3230 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3232 if(general_pll_clk.rate > codec_pll_clk.rate)
3233 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3235 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3239 static void __init rk30_clock_common_init(unsigned long gpll_rate, unsigned long cpll_rate)
3243 clk_set_rate_nolock(&general_pll_clk, gpll_rate);
3245 clk_set_rate_nolock(&codec_pll_clk, cpll_rate);
3248 clk_set_rate_nolock(&clk_core, 312 * MHZ);
3250 periph_clk_set_init();
3253 rk30_clock_common_i2s_init();
3256 clk_set_rate_nolock(&clk_spi0, clk_spi0.parent->rate);
3257 clk_set_rate_nolock(&clk_spi1, clk_spi1.parent->rate);
3260 if(rk30_clock_flags & CLK_FLG_UART_1_3M)
3261 clk_set_parent_nolock(&clk_uart_pll, &codec_pll_clk);
3263 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3265 if(!(gpll_rate % (50 * MHZ)))
3266 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3267 else if(!(ddr_pll_clk.rate % (50 * MHZ)))
3268 clk_set_parent_nolock(&clk_mac_pll_div, &ddr_pll_clk);
3270 CLKDATA_ERR("mac can't get 50mhz\n");
3274 //clk_set_parent_nolock(&clk_hsadc_pll_div, &general_pll_clk);
3276 //lcdc0 lcd auto sel pll
3277 clk_set_parent_nolock(&dclk_lcdc0, &general_pll_clk);
3278 clk_set_parent_nolock(&dclk_lcdc1, &general_pll_clk);
3281 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3284 clk_set_parent_nolock(&aclk_lcdc0_pre, &general_pll_clk);
3285 clk_set_parent_nolock(&aclk_lcdc1_pre, &general_pll_clk);
3286 clk_set_rate_nolock(&aclk_lcdc0_pre, 300 * MHZ);
3287 clk_set_rate_nolock(&aclk_lcdc1_pre, 300 * MHZ);
3290 //clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
3291 //clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
3293 clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3294 clk_set_rate_nolock(&aclk_vdpu, 300 * MHZ);
3296 clk_set_parent_nolock(&clk_gpu, &codec_pll_clk);
3297 clk_set_parent_nolock(&aclk_gpu, &codec_pll_clk);
3298 clk_set_rate_nolock(&clk_gpu, 200 * MHZ);
3299 clk_set_rate_nolock(&aclk_gpu, 200 * MHZ);
3301 clk_set_rate_nolock(&clk_uart0, 49500000);
3302 clk_set_rate_nolock(&clk_sdmmc, 24750000);
3303 clk_set_rate_nolock(&clk_sdio, 24750000);
3306 static struct clk def_ops_clk = {
3307 .get_parent = clksel_get_parent,
3308 .set_parent = clksel_set_parent,
3311 #ifdef CONFIG_PROC_FS
3312 struct clk_dump_ops dump_ops;
3314 void rk_dump_clock_info(void);
3316 void __init _rk30_clock_data_init(unsigned long gpll, unsigned long cpll, int flags)
3318 struct clk_lookup *lk;
3320 clk_register_dump_ops(&dump_ops);
3321 clk_register_default_ops_clk(&def_ops_clk);
3322 rk30_clock_flags = flags;
3323 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
3324 #ifdef RK30_CLK_OFFBOARD_TEST
3325 rk30_clkdev_add(lk);
3329 clk_register(lk->clk);
3331 clk_recalculate_root_clocks_nolock();
3333 loops_per_jiffy = CLK_LOOPS_RECALC(arm_pll_clk.rate);
3336 * Only enable those clocks we will need, let the drivers
3337 * enable other clocks as necessary
3339 rk30_init_enable_clocks();
3341 // print loader config
3342 rk_dump_clock_info();
3346 * Disable any unused clocks left on by the bootloader
3348 //clk_disable_unused();
3349 rk30_clock_common_init(gpll, cpll);
3350 preset_lpj = loops_per_jiffy;
3353 //regfile_writel(0xc0004000,0x10c);
3354 //cru_writel(0x07000000,CRU_MISC_CON);
3358 void __init rk30_clock_data_init(unsigned long gpll, unsigned long cpll, u32 flags)
3360 _rk30_clock_data_init(gpll, cpll, flags);
3365 * You can override arm_clk rate with armclk= cmdline option.
3367 static int __init armclk_setup(char *str)
3369 get_option(&str, &armclk);
3375 //clk_set_rate_nolock(&arm_pll_clk, armclk);
3378 #ifndef RK30_CLK_OFFBOARD_TEST
3379 early_param("armclk", armclk_setup);
3383 static void rk_dump_clock(struct clk *clk, int deep, const struct list_head *root_clocks)
3387 unsigned long rate = clk->rate;
3388 //CLKDATA_DBG("dump_clock %s\n",clk->name);
3389 for (i = 0; i < deep; i++)
3392 printk("%-11s ", clk->name);
3393 #ifndef RK30_CLK_OFFBOARD_TEST
3394 if (clk->flags & IS_PD) {
3395 printk("%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3398 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3399 int idx = clk->gate_idx;
3401 v = cru_readl(CLK_GATE_CLKID_CONS(idx)) & ((0x1) << (idx % 16));
3402 printk("%s ", v ? "off" : "on ");
3407 u32 pll_id = clk->pll->id;
3408 pll_mode = cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3409 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3411 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3413 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3416 if(cru_readl(PLL_CONS(pll_id, 3)) & PLL_BYPASS)
3418 } else if(clk == &clk_ddr) {
3419 rate = clk->recalc(clk);
3424 printk("%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3426 printk("%ld MHz", rate / MHZ);
3427 } else if (rate >= KHZ) {
3429 printk("%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3431 printk("%ld KHz", rate / KHZ);
3433 printk("%ld Hz", rate);
3436 printk(" usecount = %d", clk->usecount);
3439 printk(" parent = %s", clk->parent->name);
3443 list_for_each_entry(ck, root_clocks, node) {
3444 if (ck->parent == clk)
3445 rk_dump_clock(ck, deep + 1, root_clocks);
3450 struct list_head *get_rk_clocks_head(void);
3452 void rk_dump_clock_info(void)
3455 list_for_each_entry(clk, get_rk_clocks_head(), node) {
3457 rk_dump_clock(clk, 0,get_rk_clocks_head());
3462 #ifdef CONFIG_PROC_FS
3464 static void dump_clock(struct seq_file *s, struct clk *clk, int deep, const struct list_head *root_clocks)
3468 unsigned long rate = clk->rate;
3469 //CLKDATA_DBG("dump_clock %s\n",clk->name);
3470 for (i = 0; i < deep; i++)
3473 seq_printf(s, "%-11s ", clk->name);
3474 #ifndef RK30_CLK_OFFBOARD_TEST
3475 if (clk->flags & IS_PD) {
3476 seq_printf(s, "%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3479 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3480 int idx = clk->gate_idx;
3482 v = cru_readl(CLK_GATE_CLKID_CONS(idx)) & ((0x1) << (idx % 16));
3483 seq_printf(s, "%s ", v ? "off" : "on ");
3488 u32 pll_id = clk->pll->id;
3489 pll_mode = cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3490 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3491 seq_printf(s, "slow ");
3492 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3493 seq_printf(s, "normal ");
3494 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3495 seq_printf(s, "deep ");
3497 if(cru_readl(PLL_CONS(pll_id, 3)) & PLL_BYPASS)
3498 seq_printf(s, "bypass ");
3499 } else if(clk == &clk_ddr) {
3500 rate = clk->recalc(clk);
3505 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3507 seq_printf(s, "%ld MHz", rate / MHZ);
3508 } else if (rate >= KHZ) {
3510 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3512 seq_printf(s, "%ld KHz", rate / KHZ);
3514 seq_printf(s, "%ld Hz", rate);
3517 seq_printf(s, " usecount = %d", clk->usecount);
3520 seq_printf(s, " parent = %s", clk->parent->name);
3522 seq_printf(s, "\n");
3524 list_for_each_entry(ck, root_clocks, node) {
3525 if (ck->parent == clk)
3526 dump_clock(s, ck, deep + 1, root_clocks);
3530 static void dump_regs(struct seq_file *s)
3533 seq_printf(s, "\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3534 seq_printf(s, "\nPLLRegisters:\n");
3535 for(i = 0; i < END_PLL_ID; i++) {
3536 seq_printf(s, "pll%d :cons:%x,%x,%x,%x\n", i,
3537 cru_readl(PLL_CONS(i, 0)),
3538 cru_readl(PLL_CONS(i, 1)),
3539 cru_readl(PLL_CONS(i, 2)),
3540 cru_readl(PLL_CONS(i, 3))
3543 seq_printf(s, "MODE :%x\n", cru_readl(CRU_MODE_CON));
3545 for(i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
3546 seq_printf(s, "CLKSEL%d :%x\n", i, cru_readl(CRU_CLKSELS_CON(i)));
3548 for(i = 0; i < CRU_CLKGATES_CON_CNT; i++) {
3549 seq_printf(s, "CLKGATE%d :%x\n", i, cru_readl(CRU_CLKGATES_CON(i)));
3551 seq_printf(s, "GLB_SRST_FST:%x\n", cru_readl(CRU_GLB_SRST_FST));
3552 seq_printf(s, "GLB_SRST_SND:%x\n", cru_readl(CRU_GLB_SRST_SND));
3554 for(i = 0; i < CRU_SOFTRSTS_CON_CNT; i++) {
3555 seq_printf(s, "CLKGATE%d :%x\n", i, cru_readl(CRU_SOFTRSTS_CON(i)));
3557 seq_printf(s, "CRU MISC :%x\n", cru_readl(CRU_MISC_CON));
3558 seq_printf(s, "GLB_CNT_TH :%x\n", cru_readl(CRU_GLB_CNT_TH));
3562 void rk30_clk_dump_regs(void)
3565 printk("\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3566 printk("\nPLLRegisters:\n");
3567 for(i = 0; i < END_PLL_ID; i++) {
3568 printk("pll%d :cons:%x,%x,%x,%x\n", i,
3569 cru_readl(PLL_CONS(i, 0)),
3570 cru_readl(PLL_CONS(i, 1)),
3571 cru_readl(PLL_CONS(i, 2)),
3572 cru_readl(PLL_CONS(i, 3))
3575 printk("MODE :%x\n", cru_readl(CRU_MODE_CON));
3577 for(i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
3578 printk("CLKSEL%d :%x\n", i, cru_readl(CRU_CLKSELS_CON(i)));
3580 for(i = 0; i < CRU_CLKGATES_CON_CNT; i++) {
3581 printk("CLKGATE%d :%x\n", i, cru_readl(CRU_CLKGATES_CON(i)));
3583 printk("GLB_SRST_FST:%x\n", cru_readl(CRU_GLB_SRST_FST));
3584 printk("GLB_SRST_SND:%x\n", cru_readl(CRU_GLB_SRST_SND));
3586 for(i = 0; i < CRU_SOFTRSTS_CON_CNT; i++) {
3587 printk("SOFTRST%d :%x\n", i, cru_readl(CRU_SOFTRSTS_CON(i)));
3589 printk("CRU MISC :%x\n", cru_readl(CRU_MISC_CON));
3590 printk("GLB_CNT_TH :%x\n", cru_readl(CRU_GLB_CNT_TH));
3595 #ifdef CONFIG_PROC_FS
3596 static void dump_clock(struct seq_file *s, struct clk *clk, int deep, const struct list_head *root_clocks);
3597 struct clk_dump_ops dump_ops = {
3598 .dump_clk = dump_clock,
3599 .dump_regs = dump_regs,
3604 #endif /* CONFIG_PROC_FS */
3609 #ifdef RK30_CLK_OFFBOARD_TEST
3610 struct clk *test_get_parent(struct clk *clk) {
3616 struct clk *i2s_clk = &clk_i2s0;
3618 clk_enable_nolock(i2s_clk);
3620 clk_set_rate_nolock(i2s_clk, 12288000);
3621 printk("int %s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3622 clk_set_rate_nolock(i2s_clk, 297 * MHZ / 2);
3623 printk("int%s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3624 clk_set_rate_nolock(i2s_clk, 12 * MHZ);
3625 printk("int%s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3629 void uart_test(void)
3631 struct clk *uart_clk = &clk_uart0;
3633 clk_enable_nolock(uart_clk);
3635 clk_set_rate_nolock(uart_clk, 12288000);
3636 printk("int %s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3637 clk_set_rate_nolock(uart_clk, 297 * MHZ / 2);
3638 printk("int%s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3639 clk_set_rate_nolock(uart_clk, 12 * MHZ);
3640 printk("int%s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3643 void hsadc_test(void)
3645 struct clk *hsadc_clk = &clk_hsadc;
3647 printk("******************hsadc_test**********************\n");
3648 clk_enable_nolock(hsadc_clk);
3650 clk_set_rate_nolock(hsadc_clk, 12288000);
3651 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3654 clk_set_rate_nolock(hsadc_clk, 297 * MHZ / 2);
3655 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3657 clk_set_rate_nolock(hsadc_clk, 300 * MHZ / 2);
3659 clk_set_rate_nolock(hsadc_clk, 296 * MHZ / 2);
3661 printk("******************hsadc out clock**********************\n");
3663 clk_set_parent_nolock(hsadc_clk, &clk_hsadc_ext);
3664 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3665 clk_set_rate_nolock(hsadc_clk, 297 * MHZ / 2);
3666 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3672 static void __init rk30_clock_test_init(unsigned long ppll_rate)
3675 printk("*********arm_pll_clk***********\n");
3676 clk_set_rate_nolock(&arm_pll_clk, 816 * MHZ);
3678 printk("*********set clk_core parent***********\n");
3679 clk_set_parent_nolock(&clk_core, &arm_pll_clk);
3680 clk_set_rate_nolock(&clk_core, 504 * MHZ);
3683 printk("*********general_pll_clk***********\n");
3684 clk_set_rate_nolock(&general_pll_clk, ppll_rate);
3687 printk("*********codec_pll_clk***********\n");
3688 clk_set_rate_nolock(&codec_pll_clk, 600 * MHZ);
3691 printk("*********periph_clk_set_init***********\n");
3692 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3693 periph_clk_set_init();
3696 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3698 printk("*********clk i2s***********\n");
3699 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3700 printk("common %s parent is %s\n", clk_i2s_pll.name, test_get_parent(&clk_i2s_pll)->name);
3704 clk_enable_nolock(&clk_spi0);
3705 clk_set_rate_nolock(&clk_spi0, 30 * MHZ);
3706 printk("common %s parent is %s\n", clk_spi0.name, test_get_parent(&clk_spi0)->name);
3708 clk_enable_nolock(&clk_saradc);
3709 clk_set_rate_nolock(&clk_saradc, 6 * MHZ);
3710 printk("common %s parent is %s\n", clk_saradc.name, test_get_parent(&clk_saradc)->name);
3712 clk_enable_nolock(&clk_sdio);
3713 clk_set_rate_nolock(&clk_sdio, 50 * MHZ);
3714 printk("common %s parent is %s\n", clk_sdio.name, test_get_parent(&clk_sdio)->name);
3716 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3719 printk("*********mac***********\n");
3721 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3722 printk("common %s parent is %s\n", clk_mac_pll_div.name, test_get_parent(&clk_mac_pll_div)->name);
3724 //clk_set_parent_nolock(&clk_mac_ref, &clk_mac_pll_div);
3725 clk_set_rate_nolock(&clk_mac_ref, 50 * MHZ);
3726 printk("common %s parent is %s\n", clk_mac_ref.name, test_get_parent(&clk_mac_ref)->name);
3728 printk("*********mac mii set***********\n");
3729 clk_set_parent_nolock(&clk_mac_ref, &rmii_clkin);
3730 clk_set_rate_nolock(&clk_mac_ref, 20 * MHZ);
3731 printk("common %s parent is %s\n", clk_mac_ref.name, test_get_parent(&clk_mac_ref)->name);
3733 printk("*********hsadc 1***********\n");
3737 clk_enable_nolock(&dclk_lcdc0);
3739 clk_set_rate_nolock(&dclk_lcdc0, 60 * MHZ);
3740 clk_set_rate_nolock(&dclk_lcdc0, 27 * MHZ);
3743 clk_enable_nolock(&cif0_out);
3745 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3746 printk("common %s parent is %s\n", cif_out_pll.name, test_get_parent(&cif_out_pll)->name);
3748 clk_set_rate_nolock(&cif0_out, 60 * MHZ);
3749 printk("common %s parent is %s\n", cif0_out.name, test_get_parent(&cif0_out)->name);
3751 clk_set_rate_nolock(&cif0_out, 24 * MHZ);
3752 printk("common %s parent is %s\n", cif0_out.name, test_get_parent(&cif0_out)->name);
3754 clk_enable_nolock(&cif0_in);
3755 clk_set_rate_nolock(&cif0_in, 24 * MHZ);
3757 clk_enable_nolock(&aclk_lcdc0);
3758 clk_set_rate_nolock(&aclk_lcdc0, 150 * MHZ);
3759 printk("common %s parent is %s\n", aclk_lcdc0.name, test_get_parent(&aclk_lcdc0)->name);
3761 clk_enable_nolock(&aclk_vepu);
3762 clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3763 printk("common %s parent is %s\n", aclk_vepu.name, test_get_parent(&aclk_vepu)->name);
3765 clk_set_rate_nolock(&hclk_vepu, 300 * MHZ);
3766 printk("common %s parent is %s\n", hclk_vepu.name, test_get_parent(&hclk_vepu)->name);
3768 printk("test end\n");
3771 clk_set_rate_nolock(&arm_pll_clk, armclk);
3772 clk_set_rate_nolock(&clk_core, armclk);//pll:core =1:1
3775 //clk_set_rate_nolock(&codec_pll_clk, ppll_rate*2);
3777 //clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3778 //clk_set_rate_nolock(&clk_gpu, 300 * MHZ);
3786 static LIST_HEAD(rk30_clocks);
3787 static DEFINE_MUTEX(rk30_clocks_mutex);
3789 static inline int __rk30clk_get(struct clk *clk)
3793 void rk30_clkdev_add(struct clk_lookup *cl)
3795 mutex_lock(&rk30_clocks_mutex);
3796 list_add_tail(&cl->node, &rk30_clocks);
3797 mutex_unlock(&rk30_clocks_mutex);
3799 static struct clk_lookup *rk30_clk_find(const char *dev_id, const char *con_id) {
3800 struct clk_lookup *p, *cl = NULL;
3801 int match, best = 0;
3803 list_for_each_entry(p, &rk30_clocks, node) {
3806 if (!dev_id || strcmp(p->dev_id, dev_id))
3811 if (!con_id || strcmp(p->con_id, con_id))
3827 struct clk *rk30_clk_get_sys(const char *dev_id, const char *con_id) {
3828 struct clk_lookup *cl;
3830 mutex_lock(&rk30_clocks_mutex);
3831 cl = rk30_clk_find(dev_id, con_id);
3832 if (cl && !__rk30clk_get(cl->clk))
3834 mutex_unlock(&rk30_clocks_mutex);
3836 return cl ? cl->clk : ERR_PTR(-ENOENT);
3838 //EXPORT_SYMBOL(rk30_clk_get_sys);
3840 struct clk *rk30_clk_get(struct device *dev, const char *con_id) {
3841 const char *dev_id = dev ? dev_name(dev) : NULL;
3842 return rk30_clk_get_sys(dev_id, con_id);
3844 //EXPORT_SYMBOL(rk30_clk_get);
3847 int rk30_clk_set_rate(struct clk *clk, unsigned long rate);
3849 void rk30_clocks_test(void)
3851 struct clk *test_gpll;
3852 test_gpll = rk30_clk_get(NULL, "general_pll");
3854 rk30_clk_set_rate(test_gpll, 297 * 2 * MHZ);
3855 printk("gpll rate=%lu\n", test_gpll->rate);
3860 void __init rk30_clock_init_test(void)
3863 rk30_clock_init(periph_pll_297mhz, codec_pll_360mhz, max_i2s_12288khz);