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)
39 #define CLK_FLG_EXT_27MHZ (1<<0)
41 #define CLK_FLG_MAX_I2S_12288KHZ (1<<1)
42 #define CLK_FLG_MAX_I2S_22579_2KHZ (1<<2)
43 #define CLK_FLG_MAX_I2S_24576KHZ (1<<3)
44 #define CLK_FLG_MAX_I2S_49152KHZ (1<<4)
46 #define CLK_FLG_UART_1_3M (1<<5)
47 #define CLK_CPU_HPCLK_11 (1<<6)
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 .pllcon2 = PLL_CLK_BWADJ_SET(nf/2-1),\
82 .rst_dly=((nr*500)/24+1),\
86 #define _APLL_SET_LPJ(_mhz) \
87 .lpj= (CLK_LOOPS_JIFFY_REF * _mhz)/CLK_LOOPS_RATE_REF
90 #define _APLL_SET_CLKS(_mhz, nr, nf, no, _periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
93 .pllcon0 = PLL_CLKR_SET(nr)|PLL_CLKOD_SET(no),\
94 .pllcon1 = PLL_CLKF_SET(nf),\
95 .pllcon2 = PLL_CLK_BWADJ_SET(nf>>1),\
96 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
97 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
98 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
99 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
100 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
101 _APLL_SET_LPJ(_mhz),\
102 .rst_dly=((nr*500)/24+1),\
105 #define CRU_DIV_SET(mask,shift,max) \
111 #define CRU_SRC_SET(mask,shift ) \
115 #define CRU_PARENTS_SET(parents_array) \
116 .parents=(parents_array),\
117 .parents_num=ARRAY_SIZE((parents_array))
119 #define CRU_GATE_MODE_SET(_func,_IDX) \
130 #define GATE_CLK(NAME,PARENT,ID) \
131 static struct clk clk_##NAME = { \
135 .gate_idx = CLK_GATE_##ID, \
137 #ifdef RK30_CLK_OFFBOARD_TEST
138 u32 TEST_GRF_REG[0x240];
139 u32 TEST_CRU_REG[0x240];
140 #define cru_readl(offset) (TEST_CRU_REG[offset/4])
142 u32 cru_writel_is_pr(u32 offset)
144 return (offset==0x4000);
146 void cru_writel(u32 v, u32 offset)
150 TEST_CRU_REG[offset/4]&=(~mask_v);
154 TEST_CRU_REG[offset/4]|=v;
155 TEST_CRU_REG[offset/4]&=0x0000ffff;
157 if(cru_writel_is_pr(offset))
159 CRU_PRINTK_DBG("cru w offset=%d,set=%x,reg=%x\n",offset,v,TEST_CRU_REG[offset/4]);
164 void cru_writel_i2s(u32 v, u32 offset)
166 TEST_CRU_REG[offset/4]=v;
168 #define cru_writel_frac(v,offset) cru_writel_i2s((v),(offset))
170 #define regfile_readl(offset) (0xffffffff)
171 //#define pmu_readl(offset) readl(RK30_GRF_BASE + offset)
172 void rk30_clkdev_add(struct clk_lookup *cl);
174 #define regfile_readl(offset) readl_relaxed(RK30_GRF_BASE + offset)
175 #define regfile_writel(v, offset) do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
176 #define cru_readl(offset) readl_relaxed(RK30_CRU_BASE + offset)
177 #define cru_writel(v, offset) do { writel_relaxed(v, RK30_CRU_BASE + offset); dsb(); } while (0)
179 #define cru_writel_frac(v,offset) cru_writel((v),(offset))
183 #define CRU_PRINTK_DBG(fmt, args...) pr_debug(fmt, ## args)
184 #define CRU_PRINTK_LOG(fmt, args...) pr_debug(fmt, ## args)
186 #define CRU_PRINTK_DBG(fmt, args...) do {} while(0)
187 #define CRU_PRINTK_LOG(fmt, args...) do {} while(0)
189 #define CRU_PRINTK_ERR(fmt, args...) pr_err(fmt, ## args)
192 #define get_cru_bits(con,mask,shift)\
193 ((cru_readl((con)) >> (shift)) & (mask))
195 #define set_cru_bits_w_msk(val,mask,shift,con)\
196 cru_writel(((mask)<<(shift+16))|((val)<<(shift)),(con))
199 #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)))\
200 &&!(cru_readl(PLL_CONS(pll_id,3))&PLL_BYPASS))
203 static u32 rk30_clock_flags=0;
204 static struct clk codec_pll_clk;
205 static struct clk general_pll_clk;
206 static struct clk arm_pll_clk;
207 static unsigned long lpj_gpll;
208 static unsigned int __initdata armclk = 504*MHZ;
211 /************************clk recalc div rate*********************************/
214 static unsigned long clksel_recalc_div(struct clk *clk)
216 u32 div = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift) + 1;
218 unsigned long rate = clk->parent->rate / div;
219 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
224 static unsigned long clksel_recalc_shift(struct clk *clk)
226 u32 shift = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift);
227 unsigned long rate = clk->parent->rate >> shift;
228 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
233 static unsigned long clksel_recalc_shift_2(struct clk *clk)
235 u32 shift = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1;
236 unsigned long rate = clk->parent->rate >> shift;
237 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
241 static unsigned long clksel_recalc_parent_rate(struct clk *clk)
243 unsigned long rate = clk->parent->rate;
244 pr_debug("%s new clock rate is %lu\n", clk->name, rate);
247 /********************************set div rate***********************************/
250 static int clksel_set_rate_freediv(struct clk *clk, unsigned long rate)
253 for (div = 0; div < clk->div_max; div++) {
254 u32 new_rate = clk->parent->rate / (div + 1);
255 if (new_rate <= rate) {
256 set_cru_bits_w_msk(div,clk->div_mask,clk->div_shift,clk->clksel_con);
257 //clk->rate = new_rate;
258 pr_debug("clksel_set_rate_freediv for clock %s to rate %ld (div %d)\n", clk->name, rate, div + 1);
266 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
269 for (shift = 0; (1 << shift) < clk->div_max; shift++) {
270 u32 new_rate = clk->parent->rate >> shift;
271 if (new_rate <= rate) {
272 set_cru_bits_w_msk(shift,clk->div_mask,clk->div_shift,clk->clksel_con);
273 clk->rate = new_rate;
274 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
282 static int clksel_set_rate_shift_2(struct clk *clk, unsigned long rate)
286 for (shift = 1; (1 << shift) < clk->div_max; shift++) {
287 u32 new_rate = clk->parent->rate >> shift;
288 if (new_rate <= rate) {
289 set_cru_bits_w_msk(shift-1,clk->div_mask,clk->div_shift,clk->clksel_con);
290 clk->rate = new_rate;
291 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
299 static int clksel_set_rate_even(struct clk *clk, unsigned long rate)
302 for (div = 2; div < clk->div_max; div += 2) {
303 u32 new_rate = clk->parent->rate / div;
304 if (new_rate <= rate) {
305 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
306 clk->rate = new_rate;
307 pr_debug("%s for clock %s to rate %ld (even div = %d)\n",
308 __func__, clk->name, rate, div);
315 static u32 clk_get_freediv(unsigned long rate_out, unsigned long rate ,u32 div_max)
318 unsigned long new_rate;
319 for (div = 0; div <div_max; div++) {
320 new_rate = rate / (div + 1);
321 if (new_rate <= rate_out) {
325 return div_max?div_max:1;
327 struct clk *get_freediv_parents_div(struct clk *clk,unsigned long rate,u32 *div_out)
330 unsigned long new_rate[2]={0,0};
337 div[i]=clk_get_freediv(rate,clk->parents[i]->rate,clk->div_max);
338 new_rate[i] = clk->parents[i]->rate/div[i];
339 if(new_rate[i]==rate)
342 return clk->parents[i];
345 if(new_rate[0]<new_rate[1])
350 return clk->parents[i];
353 static int clkset_rate_freediv_autosel_parents(struct clk *clk, unsigned long rate)
360 p_clk=get_freediv_parents_div(clk,rate,&div);
365 CRU_PRINTK_DBG("%s %lu,form %s\n",clk->name,rate,p_clk->name);
366 if (clk->parent != p_clk)
368 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),clk->div_shift,clk->div_mask)+1;
372 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
374 ret=clk_set_parent_nolock(clk,p_clk);
377 CRU_PRINTK_ERR("%s can't set %lu,reparent err\n",clk->name,rate);
382 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
386 //rate==div rate //hdmi
387 static int clk_freediv_autosel_parents_set_fixed_rate(struct clk *clk, unsigned long rate)
392 p_clk=get_freediv_parents_div(clk,rate,&div);
397 if((p_clk->rate/div)!=rate||(p_clk->rate%div))
400 if (clk->parent != p_clk)
402 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),
403 clk->div_shift,clk->div_mask)+1;
406 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
408 ret=clk_set_parent_nolock(clk,p_clk);
411 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
416 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
420 /***************************round********************************/
422 static long clksel_freediv_round_rate(struct clk *clk, unsigned long rate)
424 return clk->parent->rate/clk_get_freediv(rate,clk->parent->rate,clk->div_max);
427 static long clk_freediv_round_autosel_parents_rate(struct clk *clk, unsigned long rate)
431 if(clk->rate == rate)
433 p_clk=get_freediv_parents_div(clk,rate,&div);
436 return p_clk->rate/div;
439 /**************************************others seting************************************/
441 static struct clk* clksel_get_parent(struct clk *clk)
443 return clk->parents[(cru_readl(clk->clksel_con) >> clk->src_shift) & clk->src_mask];
445 static int clksel_set_parent(struct clk *clk, struct clk *parent)
448 if (unlikely(!clk->parents))
450 for (i = 0; (i <clk->parents_num); i++) {
451 if (clk->parents[i]!= parent)
453 set_cru_bits_w_msk(i,clk->src_mask,clk->src_shift,clk->clksel_con);
459 static int gate_mode(struct clk *clk, int on)
461 int idx = clk->gate_idx;
462 if (idx >= CLK_GATE_MAX)
466 cru_writel(CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx), CLK_GATE_CLKID_CONS(idx));
467 //CRU_PRINTK_DBG("un gate id=%d %s(%x),con %x\n",idx,clk->name,
468 // CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx),CLK_GATE_CLKID_CONS(idx));
472 cru_writel(CLK_GATE_W_MSK(idx)|CLK_GATE(idx), CLK_GATE_CLKID_CONS(idx));
473 // CRU_PRINTK_DBG("gate id=%d %s(%x),con%x\n",idx,clk->name,
474 // CLK_GATE_W_MSK(idx)|CLK_GATE(idx),CLK_GATE_CLKID_CONS(idx));
478 /*****************************frac set******************************************/
480 static unsigned long clksel_recalc_frac(struct clk *clk)
484 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
485 if (r == 0) // FPGA ?
486 return clk->parent->rate;
488 denominator = r & 0xFFFF;
489 rate64 = (u64)clk->parent->rate * numerator;
490 do_div(rate64, denominator);
492 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
496 static u32 clk_gcd(u32 numerator, u32 denominator)
500 if (!numerator || !denominator)
502 if (numerator > denominator) {
518 static int frac_div_get_seting(unsigned long rate_out,unsigned long rate,
519 u32 *numerator,u32 *denominator)
522 gcd_vl = clk_gcd(rate, rate_out);
523 CRU_PRINTK_DBG("frac_get_seting rate=%lu,parent=%lu,gcd=%d\n",rate_out,rate, gcd_vl);
526 CRU_PRINTK_ERR("gcd=0, i2s frac div is not be supported\n");
530 *numerator = rate_out / gcd_vl;
531 *denominator = rate/ gcd_vl;
533 CRU_PRINTK_DBG("frac_get_seting numerator=%d,denominator=%d,times=%d\n",
534 *numerator, *denominator, *denominator / *numerator);
536 if (*numerator > 0xffff || *denominator > 0xffff||
537 (*denominator/(*numerator))<20) {
538 CRU_PRINTK_ERR("can't get a available nume and deno\n");
545 /* *********************pll **************************/
547 #define rk30_clock_udelay(a) udelay(a);
549 /*********************pll lock status**********************************/
550 //#define GRF_SOC_CON0 0x15c
551 static void pll_wait_lock(int pll_idx)
553 u32 pll_state[4]={1,0,2,3};
554 u32 bit = 0x10u << pll_state[pll_idx];
555 int delay = 24000000;
557 if (regfile_readl(GRF_SOC_STATUS0) & bit)
562 CRU_PRINTK_ERR("PLL_ID=%d\npll_con0=%08x\npll_con1=%08x\npll_con2=%08x\npll_con3=%08x\n", pll_idx,
563 cru_readl(PLL_CONS(pll_idx, 0)),
564 cru_readl(PLL_CONS(pll_idx, 1)),
565 cru_readl(PLL_CONS(pll_idx, 2)),
566 cru_readl(PLL_CONS(pll_idx, 3)));
568 CRU_PRINTK_ERR("wait pll bit 0x%x time out!\n", bit);
575 /***************************pll function**********************************/
576 static unsigned long pll_clk_recalc(u32 pll_id,unsigned long parent_rate)
580 if (PLLS_IN_NORM(pll_id)) {
581 u32 pll_con0 = cru_readl(PLL_CONS(pll_id,0));
582 u32 pll_con1 = cru_readl(PLL_CONS(pll_id,1));
585 u64 rate64 = (u64)parent_rate*PLL_NF(pll_con1);
588 CRU_PRINTK_DBG("selcon con0(%x) %x,con1(%x)%x, rate64 %llu\n",PLL_CONS(pll_id,0),pll_con0
589 ,PLL_CONS(pll_id,1),pll_con1, rate64);
593 //CRU_PRINTK_DBG("pll id=%d con0=%x,con1=%x,parent=%lu\n",pll_id,pll_con0,pll_con1,parent_rate);
594 //CRU_PRINTK_DBG("first pll id=%d rate is %lu (NF %d NR %d NO %d)\n",
595 //pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0), 1 << PLL_NO(pll_con0));
597 do_div(rate64, PLL_NR(pll_con0));
598 do_div(rate64, PLL_NO(pll_con0));
602 CRU_PRINTK_DBG("pll_clk_recalc id=%d rate=%lu (NF %d NR %d NO %d) rate64=%llu\n",
603 pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0),PLL_NO(pll_con0), rate64);
607 CRU_PRINTK_DBG("pll_clk_recalc id=%d rate=%lu by pass mode\n",pll_id,rate);
611 static unsigned long plls_clk_recalc(struct clk *clk)
613 return pll_clk_recalc(clk->pll->id,clk->parent->rate);
616 static int pll_clk_set_rate(struct pll_clk_set *clk_set,u8 pll_id)
619 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
621 cru_writel(PLL_REST_W_MSK|PLL_REST, PLL_CONS(pll_id,3));
622 cru_writel(clk_set->pllcon0, PLL_CONS(pll_id,0));
623 cru_writel(clk_set->pllcon1, PLL_CONS(pll_id,1));
624 cru_writel(clk_set->pllcon2, PLL_CONS(pll_id,2));
625 rk30_clock_udelay(5);
628 cru_writel(PLL_REST_W_MSK|PLL_REST_RESM, PLL_CONS(pll_id,3));
631 rk30_clock_udelay(clk_set->rst_dly);
632 pll_wait_lock(pll_id);
635 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
638 CRU_PRINTK_ERR("pll reg id=%d,con0=%x,con1=%x,mode=%x\n",pll_id,
639 cru_readl(PLL_CONS(pll_id,0)),(PLL_CONS(pll_id,1)),cru_readl(CRU_MODE_CON));
645 static int gpll_clk_set_rate(struct clk *c, unsigned long rate)
647 struct _pll_data *pll_data=c->pll;
648 struct pll_clk_set *clk_set=(struct pll_clk_set*)pll_data->table;
652 if (clk_set->rate == rate) {
657 if(clk_set->rate== rate)
659 pll_clk_set_rate(clk_set,pll_data->id);
660 lpj_gpll = CLK_LOOPS_RECALC(rate);
664 CRU_PRINTK_ERR("gpll is no corresponding rate=%lu\n", rate);
670 #define PLL_FREF_MIN (183*KHZ)
671 #define PLL_FREF_MAX (1500*MHZ)
673 #define PLL_FVCO_MIN (300*MHZ)
674 #define PLL_FVCO_MAX (1500*MHZ)
676 #define PLL_FOUT_MIN (18750*KHZ)
677 #define PLL_FOUT_MAX (1500*MHZ)
679 #define PLL_NF_MAX (4096)
680 #define PLL_NR_MAX (64)
681 #define PLL_NO_MAX (16)
683 static int pll_clk_get_set(unsigned long fin_hz,unsigned long fout_hz,u32 *clk_nr,u32 *clk_nf,u32 *clk_no)
689 unsigned long fref,fvco,fout;
692 CRU_PRINTK_DBG("pll_clk_get_set fin=%lu,fout=%lu\n",fin_hz,fout_hz);
693 if(!fin_hz||!fout_hz||fout_hz==fin_hz)
695 gcd_val=clk_gcd(fin_hz,fout_hz);
696 YFfenzi=fout_hz/gcd_val;
697 YFfenmu=fin_hz/gcd_val;
703 if(nf>PLL_NF_MAX||nonr>(PLL_NO_MAX*PLL_NR_MAX))
705 for(no=1;no<=PLL_NO_MAX;no++)
707 if(!(no==1||!(no%2)))
714 if(nr>PLL_NR_MAX)//PLL_NR_MAX
718 if(fref<PLL_FREF_MIN||fref>PLL_FREF_MAX)
722 if(fvco<PLL_FVCO_MIN||fvco>PLL_FVCO_MAX)
725 if(fout<PLL_FOUT_MIN||fout>PLL_FOUT_MAX)
738 static int pll_clk_mode(struct clk *clk, int on)
740 u8 pll_id=clk->pll->id;
741 u32 nr=PLL_NR(cru_readl(PLL_CONS(pll_id,0)));
742 u32 dly= (nr*500)/24+1;
743 CRU_PRINTK_DBG("pll_mode %s(%d)",clk->name,on);
745 cru_writel(PLL_PWR_ON|PLL_PWR_DN_W_MSK,PLL_CONS(pll_id,3));
746 rk30_clock_udelay(dly);
747 pll_wait_lock(pll_id);
748 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
750 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
751 cru_writel(PLL_PWR_DN|PLL_PWR_DN_W_MSK, PLL_CONS(pll_id,3));
756 static int cpll_clk_set_rate(struct clk *c, unsigned long rate)
758 struct _pll_data *pll_data=c->pll;
759 struct pll_clk_set *clk_set=(struct pll_clk_set*)pll_data->table;
760 struct pll_clk_set temp_clk_set;
761 u32 clk_nr,clk_nf,clk_no;
766 if (clk_set->rate == rate) {
771 if(clk_set->rate==rate)
773 CRU_PRINTK_DBG("cpll get a rate\n");
774 pll_clk_set_rate(clk_set,pll_data->id);
779 CRU_PRINTK_DBG("cpll get auto calc a rate\n");
780 if(pll_clk_get_set(c->parent->rate,rate,&clk_nr,&clk_nf,&clk_no)==0)
782 pr_err("cpll auto set rate error\n");
785 CRU_PRINTK_DBG("cpll auto ger rate set nr=%d,nf=%d,no=%d\n",clk_nr,clk_nf,clk_no);
786 temp_clk_set.pllcon0=PLL_CLKR_SET(clk_nr)|PLL_CLKOD_SET(clk_no);
787 temp_clk_set.pllcon1=PLL_CLKF_SET(clk_nf);
788 temp_clk_set.pllcon2=PLL_CLK_BWADJ_SET(clk_nf/2-1);
789 temp_clk_set.rst_dly=(clk_nr*500)/24+1;
790 pll_clk_set_rate(&temp_clk_set,pll_data->id);
797 /* ******************fixed input clk ***********************************************/
798 static struct clk xin24m = {
803 static struct clk xin27m = {
810 static struct clk clk_12m = {
817 /************************************pll func***************************/
818 static const struct apll_clk_set* arm_pll_clk_get_best_pll_set(unsigned long rate,
819 struct apll_clk_set *tables)
821 const struct apll_clk_set *ps, *pt;
823 /* find the arm_pll we want. */
826 if (pt->rate == rate) {
830 // we are sorted, and ps->rate > pt->rate.
831 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
837 //CRU_PRINTK_DBG("arm pll best rate=%lu\n",ps->rate);
840 static long arm_pll_clk_round_rate(struct clk *clk, unsigned long rate)
842 return arm_pll_clk_get_best_pll_set(rate,clk->pll->table)->rate;
845 struct arm_clks_div_set {
851 #define _arm_clks_div_set(_mhz,_periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
854 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
855 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
856 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
857 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
858 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
860 struct arm_clks_div_set arm_clk_div_tlb[]={
861 _arm_clks_div_set(50 , 2, 11, 11, 11, 11),//25,50,50,50,50
862 _arm_clks_div_set(100 , 4, 11, 21, 21, 11),//25,100,50,50,50
863 _arm_clks_div_set(150 , 4, 11, 21, 21, 11),//37,150,75,75,75
864 _arm_clks_div_set(200 , 8, 21, 21, 21, 11),//25,100,50,50,50
865 _arm_clks_div_set(300 , 8, 21, 21, 21, 11),//37,150,75,75,75
866 _arm_clks_div_set(400 , 8, 21, 21, 41, 21),//50,200,100,50,50
867 _arm_clks_div_set(0 , 2, 11, 11, 11, 11),//25,50,50,50,50
869 struct arm_clks_div_set * arm_clks_get_div(u32 rate)
872 for(i=0;arm_clk_div_tlb[i].rate!=0;i++)
874 if(arm_clk_div_tlb[i].rate>=rate)
875 return &arm_clk_div_tlb[i];
882 static u32 force_cpu_hpclk_11(u32 clksel1)
884 u8 p_bits=(clksel1&ACLK_PCLK_MSK)>>ACLK_PCLK_OFF;
887 return ((clksel1&(~(ACLK_HCLK_MSK|AHB2APB_MSK)))|AHB2APB_11|(p_bits<<ACLK_HCLK_OFF));
895 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
898 const struct apll_clk_set *ps;
899 u32 pll_id=clk->pll->id;
901 u32 old_aclk_div=0,new_aclk_div,gpll_arm_aclk_div;
902 struct arm_clks_div_set *temp_clk_div;
903 unsigned long arm_gpll_rate, arm_gpll_lpj;
906 ps = arm_pll_clk_get_best_pll_set(rate,(struct apll_clk_set *)clk->pll->table);
908 old_aclk_div=GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
909 new_aclk_div=GET_CORE_ACLK_VAL(ps->clksel1&CORE_ACLK_MSK);
911 CRU_PRINTK_LOG("apll will set rate(%lu) tlb con(%x,%x,%x),sel(%x,%x)\n",
912 ps->rate,ps->pllcon0,ps->pllcon1,ps->pllcon2,ps->clksel0,ps->clksel1);
914 //rk30_l2_cache_latency(ps->rate/MHZ);
916 if(general_pll_clk.rate>clk->rate)
918 temp_div=clk_get_freediv(clk->rate,general_pll_clk.rate,10);
925 //cru_writel(CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
927 arm_gpll_rate=general_pll_clk.rate/temp_div;
928 arm_gpll_lpj = lpj_gpll / temp_div;
929 temp_clk_div=arm_clks_get_div(arm_gpll_rate/MHZ);
931 temp_clk_div=&arm_clk_div_tlb[4];
932 if(rk30_clock_flags&CLK_CPU_HPCLK_11)
934 temp_clk_div->clksel1=force_cpu_hpclk_11(temp_clk_div->clksel1);
937 gpll_arm_aclk_div=GET_CORE_ACLK_VAL(temp_clk_div->clksel1&CORE_ACLK_MSK);
939 CRU_PRINTK_LOG("gpll_arm_rate=%lu,sel rate%u,sel0%x,sel1%x\n",arm_gpll_rate,temp_clk_div->rate,
940 temp_clk_div->clksel0,temp_clk_div->clksel1);
942 local_irq_save(flags);
944 if(gpll_arm_aclk_div>=old_aclk_div)
946 if((old_aclk_div==3||gpll_arm_aclk_div==3)&&(gpll_arm_aclk_div!=old_aclk_div))
948 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
949 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
950 cru_writel((temp_clk_div->clksel0|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK),
952 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
956 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
957 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
961 // open gpu gpll path
962 cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH)|CLK_UN_GATE(CLK_GATE_CPU_GPLL_PATH),CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
963 cru_writel(CORE_SEL_GPLL|CORE_SEL_PLL_W_MSK, CRU_CLKSELS_CON(0));
964 loops_per_jiffy = arm_gpll_lpj;
967 if(gpll_arm_aclk_div<old_aclk_div)
969 if((old_aclk_div==3||gpll_arm_aclk_div==3)&&(gpll_arm_aclk_div!=old_aclk_div))
971 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
972 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
973 cru_writel((temp_clk_div->clksel0|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK),
975 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
979 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
980 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
985 /*if core src don't select gpll ,apll neet to enter slow mode */
986 //cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
989 cru_writel(PLL_REST_W_MSK|PLL_REST, PLL_CONS(pll_id,3));
990 cru_writel(ps->pllcon0, PLL_CONS(pll_id,0));
991 cru_writel(ps->pllcon1, PLL_CONS(pll_id,1));
992 cru_writel(ps->pllcon2, PLL_CONS(pll_id,2));
994 rk30_clock_udelay(5);
997 cru_writel(PLL_REST_W_MSK|PLL_REST_RESM, PLL_CONS(pll_id,3));
1000 ///rk30_clock_udelay(ps->rst_dly);//lcdc flash
1002 pll_wait_lock(pll_id);
1004 if(rk30_clock_flags&CLK_CPU_HPCLK_11)
1006 ps_clksel1=force_cpu_hpclk_11(ps->clksel1);
1010 ps_clksel1=ps->clksel1;
1013 //cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
1015 if(new_aclk_div>=gpll_arm_aclk_div)
1017 if((gpll_arm_aclk_div==3||new_aclk_div==3)&&(new_aclk_div!=gpll_arm_aclk_div))
1019 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
1020 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1021 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1022 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
1026 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1027 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1032 cru_writel(CORE_SEL_PLL_W_MSK|CORE_SEL_APLL, CRU_CLKSELS_CON(0));
1033 loops_per_jiffy = ps->lpj;
1036 if(new_aclk_div<gpll_arm_aclk_div)
1038 if((gpll_arm_aclk_div==3||new_aclk_div==3)&&(new_aclk_div!=gpll_arm_aclk_div))
1040 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
1041 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1042 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1043 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
1047 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1048 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1051 //CRU_PRINTK_DBG("apll set loops_per_jiffy =%lu,rate(%lu)\n",loops_per_jiffy,ps->rate);
1053 local_irq_restore(flags);
1056 cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH)|CLK_GATE(CLK_GATE_CPU_GPLL_PATH)
1057 , CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
1059 CRU_PRINTK_LOG("apll set over con(%x,%x,%x,%x),sel(%x,%x)\n",cru_readl(PLL_CONS(pll_id,0)),
1060 cru_readl(PLL_CONS(pll_id,1)),cru_readl(PLL_CONS(pll_id,2)),
1061 cru_readl(PLL_CONS(pll_id,3)),cru_readl(CRU_CLKSELS_CON(0)),
1062 cru_readl(CRU_CLKSELS_CON(1)));
1067 /************************************pll clocks***************************/
1069 static const struct apll_clk_set apll_clks[] = {
1070 //rate, nr ,nf ,no,core_div,peri,axi,hclk,pclk,_ahb2apb
1071 //_APLL_SET_CLKS(1800, 1, 75, 1, 8, 41, 41, 81,21),
1072 //_APLL_SET_CLKS(1752, 1, 73, 1, 8, 41, 41, 81,21),
1073 //_APLL_SET_CLKS(1704, 1, 71, 1, 8, 41, 41, 81,21),
1074 //_APLL_SET_CLKS(1656, 1, 69, 1, 8, 41, 41, 81,21),
1075 _APLL_SET_CLKS(1608, 1, 67, 1, 8, 41, 21, 41, 21),
1076 _APLL_SET_CLKS(1560, 1, 65, 1, 8, 41, 21, 41, 21),
1077 _APLL_SET_CLKS(1512, 1, 63, 1, 8, 41, 21, 41, 21),
1078 _APLL_SET_CLKS(1464, 1, 61, 1, 8, 41, 21, 41, 21),
1079 _APLL_SET_CLKS(1416, 1, 59, 1, 8, 41, 21, 41, 21),
1080 _APLL_SET_CLKS(1368, 1, 57, 1, 8, 41, 21, 41, 21),
1081 _APLL_SET_CLKS(1320, 1, 55, 1, 8, 41, 21, 41, 21),
1082 _APLL_SET_CLKS(1296, 1, 54, 1, 8, 41, 21, 41, 21),
1083 _APLL_SET_CLKS(1272, 1, 53, 1, 8, 41, 21, 41, 21),
1084 _APLL_SET_CLKS(1200, 1, 50, 1, 8, 41, 21, 41, 21),
1085 _APLL_SET_CLKS(1176, 1, 49, 1, 8, 41, 21, 41, 21),
1086 _APLL_SET_CLKS(1128, 1, 47, 1, 8, 41, 21, 41, 21),
1087 _APLL_SET_CLKS(1104, 1, 46, 1, 8, 41, 21, 41, 21),
1088 _APLL_SET_CLKS(1008, 1, 42, 1, 8, 31, 21, 41, 21),
1089 _APLL_SET_CLKS(888, 1, 37, 1, 8, 31, 21, 41, 21),
1090 _APLL_SET_CLKS(816 , 1, 34, 1, 8, 31, 21, 41, 21),
1091 _APLL_SET_CLKS(792 , 1, 33, 1, 8, 31, 21, 41, 21),
1092 _APLL_SET_CLKS(696 , 1, 29, 1, 8, 31, 21, 41, 21),
1093 _APLL_SET_CLKS(600 , 1, 25, 1, 4, 31, 21, 41, 21),
1094 _APLL_SET_CLKS(504 , 1, 21, 1, 4, 21, 21, 41, 21),
1095 _APLL_SET_CLKS(408 , 1, 17, 1, 4, 21, 21, 41, 21),
1096 _APLL_SET_CLKS(312 , 1, 13, 1, 2, 21, 21, 21, 11),
1097 _APLL_SET_CLKS(252 , 1, 21, 2, 2, 21, 21, 21, 11),
1098 _APLL_SET_CLKS(216 , 1, 18, 2, 2, 21, 21, 21, 11),
1099 _APLL_SET_CLKS(126 , 1, 21, 4, 2, 21, 11, 11, 11),
1100 _APLL_SET_CLKS(48 , 1, 16, 8, 2, 11, 11, 11, 11),
1101 _APLL_SET_CLKS(0 , 1, 21, 4, 2, 21, 21, 41, 21),
1104 static struct _pll_data apll_data=SET_PLL_DATA(APLL_ID,(void *)apll_clks);
1105 static struct clk arm_pll_clk ={
1108 .mode = pll_clk_mode,
1109 .recalc = plls_clk_recalc,
1110 .set_rate = arm_pll_clk_set_rate,
1111 .round_rate = arm_pll_clk_round_rate,
1115 static int ddr_pll_clk_set_rate(struct clk *clk, unsigned long rate)
1117 /* do nothing here */
1120 static struct _pll_data dpll_data=SET_PLL_DATA(DPLL_ID,NULL);
1121 static struct clk ddr_pll_clk = {
1124 .recalc = plls_clk_recalc,
1125 .set_rate = ddr_pll_clk_set_rate,
1129 static const struct pll_clk_set cpll_clks[] = {
1130 _PLL_SET_CLKS(360000, 1, 15, 1),
1131 _PLL_SET_CLKS(408000, 1, 17, 1),
1132 _PLL_SET_CLKS(456000, 1, 19, 1),
1133 _PLL_SET_CLKS(504000, 1, 21, 1),
1134 _PLL_SET_CLKS(552000, 1, 23, 1),
1135 _PLL_SET_CLKS(600000, 1, 25, 1),
1136 _PLL_SET_CLKS(742500, 8, 495, 2),
1137 _PLL_SET_CLKS(768000, 1, 32, 1),
1138 _PLL_SET_CLKS(798000, 4, 133, 1),
1139 _PLL_SET_CLKS(1188000,2, 99, 1),
1140 _PLL_SET_CLKS( 0, 4, 133, 1),
1142 static struct _pll_data cpll_data=SET_PLL_DATA(CPLL_ID,(void *)cpll_clks);
1143 static struct clk codec_pll_clk = {
1144 .name = "codec_pll",
1146 .mode = pll_clk_mode,
1147 .recalc = plls_clk_recalc,
1148 .set_rate = cpll_clk_set_rate,
1152 static const struct pll_clk_set gpll_clks[] = {
1153 _PLL_SET_CLKS(148500, 4, 99, 4),
1154 _PLL_SET_CLKS(297000, 2, 99, 4),
1155 _PLL_SET_CLKS(300000, 1, 25, 2),
1156 _PLL_SET_CLKS(1188000, 2, 99, 1),
1157 _PLL_SET_CLKS(0, 0, 0, 0),
1159 static struct _pll_data gpll_data=SET_PLL_DATA(GPLL_ID,(void *)gpll_clks);
1160 static struct clk general_pll_clk = {
1161 .name = "general_pll",
1163 .recalc = plls_clk_recalc,
1164 .set_rate = gpll_clk_set_rate,
1167 /********************************clocks***********************************/
1168 static int ddr_clk_set_rate(struct clk *c, unsigned long rate)
1173 static long ddr_clk_round_rate(struct clk *clk, unsigned long rate)
1175 return ddr_set_pll(rate/MHZ,0)*MHZ;
1177 static unsigned long ddr_clk_recalc_rate(struct clk *clk)
1179 u32 shift = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift);
1180 unsigned long rate = clk->parent->recalc(clk->parent)>> shift;
1181 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
1184 static struct clk *clk_ddr_parents[2] = {&ddr_pll_clk, &general_pll_clk};
1185 static struct clk clk_ddr = {
1187 .parent = &ddr_pll_clk,
1188 .recalc = ddr_clk_recalc_rate,
1189 .set_rate = ddr_clk_set_rate,
1190 .round_rate = ddr_clk_round_rate,
1191 .clksel_con = CRU_CLKSELS_CON(26),
1192 //CRU_DIV_SET(0x3,0,4),
1194 //CRU_PARENTS_SET(clk_ddr_parents),
1196 static int arm_core_clk_set_rate(struct clk *c, unsigned long rate)
1200 //set_cru_bits_w_msk(0,c->div_mask,c->div_shift,c->clksel_con);
1202 ret = clk_set_rate_nolock(c->parent, rate);
1204 CRU_PRINTK_ERR("Failed to change clk pll %s to %lu\n",c->name,rate);
1209 static unsigned long arm_core_clk_get_rate(struct clk *c)
1211 u32 div=(get_cru_bits(c->clksel_con,c->div_mask,c->div_shift)+1);
1212 //c->parent->rate=c->parent->recalc(c->parent);
1213 return c->parent->rate/div;
1215 static long core_clk_round_rate(struct clk *clk, unsigned long rate)
1217 u32 div=(get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1);
1218 return clk_round_rate_nolock(clk->parent,rate)/div;
1221 static int core_clksel_set_parent(struct clk *clk, struct clk *new_prt)
1225 struct clk *old_prt;
1227 if(clk->parent==new_prt)
1229 if (unlikely(!clk->parents))
1231 CRU_PRINTK_DBG("%s,reparent %s\n",clk->name,new_prt->name);
1233 old_prt=clk->parent;
1235 if(clk->parents[0]==new_prt)
1237 new_prt->set_rate(new_prt,300*MHZ);
1238 set_cru_bits_w_msk(0,clk->div_mask,clk->div_shift,clk->clksel_con);
1240 else if(clk->parents[1]==new_prt)
1243 if(new_prt->rate>old_prt->rate)
1245 temp_div=clk_get_freediv(old_prt->rate,new_prt->rate,clk->div_max);
1246 set_cru_bits_w_msk(temp_div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
1248 set_cru_bits_w_msk(1,clk->src_mask,clk->src_shift,clk->clksel_con);
1249 new_prt->set_rate(new_prt,300*MHZ);
1259 static int core_gpll_clk_set_rate(struct clk *c, unsigned long rate)
1261 unsigned long flags;
1264 u32 old_aclk_div=0,new_aclk_div;
1265 struct arm_clks_div_set *temp_clk_div;
1266 unsigned long arm_gpll_rate, arm_gpll_lpj;
1267 temp_div=clk_get_freediv(rate,c->parent->rate,c->div_max);
1268 arm_gpll_rate=c->parent->rate/temp_div;
1270 temp_clk_div=arm_clks_get_div(arm_gpll_rate/MHZ);
1272 temp_clk_div=&arm_clk_div_tlb[4];
1274 old_aclk_div=GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
1275 new_aclk_div=GET_CORE_ACLK_VAL(temp_clk_div->clksel1&CORE_ACLK_MSK);
1278 arm_gpll_lpj = lpj_gpll / temp_div;
1279 set_cru_bits_w_msk(temp_div-1,c->div_mask,c->div_shift,c->clksel_con);
1282 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
1283 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
1284 CRU_CLKSELS_CON(0));
1287 arm_gpll_lpj = lpj_gpll / temp_div;
1288 set_cru_bits_w_msk(temp_div-1,c->div_mask,c->div_shift,c->clksel_con);
1292 static unsigned long arm_core_gpll_clk_get_rate(struct clk *c)
1294 return c->parent->rate;
1297 static struct clk clk_cpu_gpll_path = {
1298 .name = "cpu_gpll_path",
1299 .parent = &general_pll_clk,
1300 .recalc = arm_core_gpll_clk_get_rate,
1301 .set_rate = core_gpll_clk_set_rate,
1302 CRU_DIV_SET(0x1f,0,32),
1303 CRU_GATE_MODE_SET(gate_mode,CLK_GATE_CPU_GPLL_PATH),
1307 static struct clk *clk_cpu_parents[2] = {&arm_pll_clk,&clk_cpu_gpll_path};
1309 static struct clk clk_cpu = {
1311 .parent = &arm_pll_clk,
1312 .set_rate = arm_core_clk_set_rate,
1313 .recalc = arm_core_clk_get_rate,
1314 .round_rate = core_clk_round_rate,
1315 .set_parent = core_clksel_set_parent,
1316 .clksel_con = CRU_CLKSELS_CON(0),
1317 CRU_DIV_SET(0x1f,0,32),
1319 CRU_PARENTS_SET(clk_cpu_parents),
1321 static unsigned long aclk_cpu_recalc(struct clk *clk)
1324 u32 div = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1;
1329 rate = clk->parent->rate / div;
1330 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
1334 static struct clk core_periph = {
1335 .name = "core_periph",
1337 .recalc = clksel_recalc_shift_2,
1338 .clksel_con = CRU_CLKSELS_CON(0),
1339 CRU_DIV_SET(0x3,6,16),
1342 static struct clk aclk_cpu = {
1345 .recalc = aclk_cpu_recalc,
1346 .clksel_con = CRU_CLKSELS_CON(1),
1347 CRU_DIV_SET(0x7,0,8),
1350 static struct clk hclk_cpu = {
1352 .parent = &aclk_cpu,
1353 .recalc = clksel_recalc_shift,
1354 //.set_rate = clksel_set_rate_shift,
1355 .clksel_con = CRU_CLKSELS_CON(1),
1356 CRU_DIV_SET(0x3,8,4),
1360 static struct clk pclk_cpu = {
1362 .parent = &aclk_cpu,
1363 .recalc = clksel_recalc_shift,
1364 //.set_rate = clksel_set_rate_shift,
1365 .clksel_con = CRU_CLKSELS_CON(1),
1366 CRU_DIV_SET(0x3,12,8),
1368 static struct clk ahb2apb_cpu = {
1370 .parent = &hclk_cpu,
1371 .recalc = clksel_recalc_shift,
1372 .clksel_con = CRU_CLKSELS_CON(1),
1373 CRU_DIV_SET(0x3,14,4),
1377 static struct clk atclk_cpu = {
1378 .name = "atclk_cpu",
1379 .parent = &pclk_cpu,
1382 static struct clk *clk_i2s_div_parents[]={&general_pll_clk,&codec_pll_clk};
1383 static struct clk clk_i2s_pll = {
1385 .parent = &general_pll_clk,
1386 .clksel_con = CRU_CLKSELS_CON(2),
1387 CRU_SRC_SET(0x1,16),
1388 CRU_PARENTS_SET(clk_i2s_div_parents),
1391 static struct clk clk_i2s0_div = {
1393 .parent = &clk_i2s_pll,
1395 .recalc = clksel_recalc_div,
1396 .set_rate = clksel_set_rate_freediv,
1397 .round_rate =clksel_freediv_round_rate,
1398 .gate_idx = CLK_GATE_I2S0,
1399 .clksel_con = CRU_CLKSELS_CON(2),
1400 CRU_DIV_SET(0x7f,0,64),
1403 static struct clk clk_i2s1_div = {
1405 .parent = &clk_i2s_pll,
1406 .recalc = clksel_recalc_div,
1407 .set_rate = clksel_set_rate_freediv,
1408 .round_rate =clksel_freediv_round_rate,
1410 .gate_idx = CLK_GATE_I2S1,
1411 .clksel_con = CRU_CLKSELS_CON(3),
1412 CRU_DIV_SET(0x7f,0,64),
1416 static struct clk clk_i2s2_div = {
1418 .parent = &clk_i2s_pll,
1419 .recalc = clksel_recalc_div,
1420 .set_rate = clksel_set_rate_freediv,
1421 .round_rate =clksel_freediv_round_rate,
1423 .gate_idx = CLK_GATE_I2S2,
1424 .clksel_con = CRU_CLKSELS_CON(4),
1425 CRU_DIV_SET(0x7f,0,64),
1427 static struct clk clk_spdif_div = {
1428 .name = "spdif_div",
1429 .parent = &clk_i2s_pll,
1430 .recalc = clksel_recalc_div,
1431 .set_rate = clksel_set_rate_freediv,
1432 .round_rate =clksel_freediv_round_rate,
1434 .gate_idx = CLK_GATE_SPDIF,
1435 .clksel_con = CRU_CLKSELS_CON(5),
1436 CRU_DIV_SET(0x7f,0,64),
1438 static int clk_i2s_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1440 u32 numerator, denominator;
1441 //clk_i2s_div->clk_i2s_pll->gpll/cpll
1442 //clk->parent->parent
1443 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1444 &numerator,&denominator)==0)
1446 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1447 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1448 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1452 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1459 static struct clk clk_i2s0_frac_div = {
1460 .name = "i2s0_frac_div",
1461 .parent = &clk_i2s0_div,
1463 .gate_idx = CLK_GATE_I2S0_FRAC,
1464 .recalc = clksel_recalc_frac,
1465 .set_rate = clk_i2s_fracdiv_set_rate,
1466 .clksel_con = CRU_CLKSELS_CON(6),
1469 static struct clk clk_i2s1_frac_div = {
1470 .name = "i2s1_frac_div",
1471 .parent = &clk_i2s1_div,
1473 .gate_idx = CLK_GATE_I2S1_FRAC,
1474 .recalc = clksel_recalc_frac,
1475 .set_rate = clk_i2s_fracdiv_set_rate,
1476 .clksel_con = CRU_CLKSELS_CON(7),
1479 static struct clk clk_i2s2_frac_div = {
1480 .name = "i2s2_frac_div",
1482 .gate_idx = CLK_GATE_I2S2_FRAC,
1483 .parent = &clk_i2s2_div,
1484 .recalc = clksel_recalc_frac,
1485 .set_rate = clk_i2s_fracdiv_set_rate,
1486 .clksel_con = CRU_CLKSELS_CON(8),
1488 static struct clk clk_spdif_frac_div = {
1489 .name = "spdif_frac_div",
1490 .parent = &clk_spdif_div,
1492 .gate_idx = CLK_GATE_SPDIF_FRAC,
1493 .recalc = clksel_recalc_frac,
1494 .set_rate = clk_i2s_fracdiv_set_rate,
1495 .clksel_con = CRU_CLKSELS_CON(9),
1498 #define I2S_SRC_DIV (0x0)
1499 #define I2S_SRC_FRAC (0x1)
1500 #define I2S_SRC_12M (0x2)
1502 static int i2s_set_rate(struct clk *clk, unsigned long rate)
1507 if (rate == clk->parents[I2S_SRC_12M]->rate){
1508 parent = clk->parents[I2S_SRC_12M];
1509 }else if((long)clk_round_rate_nolock(clk->parents[I2S_SRC_DIV],rate)==rate)
1511 parent = clk->parents[I2S_SRC_DIV];
1515 parent =clk->parents[I2S_SRC_FRAC];
1518 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
1519 clk->name,rate,parent->name,clk->parent->name);
1521 if(parent!=clk->parents[I2S_SRC_12M])
1523 ret = clk_set_rate_nolock(parent,rate);//div 1:1
1526 CRU_PRINTK_DBG("%s set rate%lu err\n",clk->name,rate);
1531 if (clk->parent != parent)
1533 ret = clk_set_parent_nolock(clk, parent);
1536 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
1544 static struct clk *clk_i2s0_parents[3]={&clk_i2s0_div,&clk_i2s0_frac_div,&clk_12m};
1546 static struct clk clk_i2s0 = {
1548 .set_rate = i2s_set_rate,
1549 .clksel_con = CRU_CLKSELS_CON(2),
1551 CRU_PARENTS_SET(clk_i2s0_parents),
1554 static struct clk *clk_i2s1_parents[3]={&clk_i2s1_div,&clk_i2s1_frac_div,&clk_12m};
1556 static struct clk clk_i2s1 = {
1558 .set_rate = i2s_set_rate,
1559 .clksel_con = CRU_CLKSELS_CON(3),
1561 CRU_PARENTS_SET(clk_i2s1_parents),
1564 static struct clk *clk_i2s2_parents[3]={&clk_i2s2_div,&clk_i2s2_frac_div,&clk_12m};
1566 static struct clk clk_i2s2 = {
1568 .set_rate = i2s_set_rate,
1569 .clksel_con = CRU_CLKSELS_CON(4),
1571 CRU_PARENTS_SET(clk_i2s2_parents),
1574 static struct clk *clk_spdif_parents[3]={&clk_spdif_div,&clk_spdif_frac_div,&clk_12m};
1576 static struct clk clk_spdif = {
1578 .parent = &clk_spdif_frac_div,
1579 .set_rate = i2s_set_rate,
1580 .clksel_con = CRU_CLKSELS_CON(5),
1582 CRU_PARENTS_SET(clk_spdif_parents),
1585 static struct clk *aclk_periph_parents[2]={&general_pll_clk,&codec_pll_clk};
1587 static struct clk aclk_periph = {
1588 .name = "aclk_periph",
1589 .parent = &general_pll_clk,
1591 .gate_idx = CLK_GATE_ACLK_PERIPH,
1592 .recalc = clksel_recalc_div,
1593 .set_rate = clksel_set_rate_freediv,
1594 .clksel_con = CRU_CLKSELS_CON(10),
1595 CRU_DIV_SET(0x1f,0,32),
1597 CRU_PARENTS_SET(aclk_periph_parents),
1599 GATE_CLK(periph_src, aclk_periph, PERIPH_SRC);
1601 static struct clk pclk_periph = {
1602 .name = "pclk_periph",
1603 .parent = &aclk_periph,
1605 .gate_idx = CLK_GATE_PCLK_PERIPH,
1606 .recalc = clksel_recalc_shift,
1607 .set_rate = clksel_set_rate_shift,
1608 .clksel_con = CRU_CLKSELS_CON(10),
1609 CRU_DIV_SET(0x3,12,8),
1612 static struct clk hclk_periph = {
1613 .name = "hclk_periph",
1614 .parent = &aclk_periph,
1616 .gate_idx = CLK_GATE_HCLK_PERIPH,
1617 .recalc = clksel_recalc_shift,
1618 .set_rate = clksel_set_rate_shift,
1619 .clksel_con = CRU_CLKSELS_CON(10),
1620 CRU_DIV_SET(0x3,8,4),
1623 static struct clk clk_spi0 = {
1625 .parent = &pclk_periph,
1627 .recalc = clksel_recalc_div,
1628 .set_rate = clksel_set_rate_freediv,
1629 .gate_idx = CLK_GATE_SPI0,
1630 .clksel_con = CRU_CLKSELS_CON(25),
1631 CRU_DIV_SET(0x7f,0,128),
1634 static struct clk clk_spi1 = {
1636 .parent = &pclk_periph,
1638 .recalc = clksel_recalc_div,
1639 .set_rate = clksel_set_rate_freediv,
1640 .gate_idx = CLK_GATE_SPI1,
1641 .clksel_con = CRU_CLKSELS_CON(25),
1642 CRU_DIV_SET(0x7f,8,128),
1645 static struct clk clk_saradc = {
1649 .recalc = clksel_recalc_div,
1650 .set_rate = clksel_set_rate_freediv,
1651 .gate_idx = CLK_GATE_SARADC,
1652 .clksel_con =CRU_CLKSELS_CON(24),
1653 CRU_DIV_SET(0xff,8,256),
1655 static struct clk clk_tsadc = {
1659 .recalc = clksel_recalc_div,
1660 .set_rate = clksel_set_rate_freediv,
1661 .gate_idx = CLK_GATE_TSADC,
1662 .clksel_con =CRU_CLKSELS_CON(34),
1663 CRU_DIV_SET(0xffff,0,65536),
1665 GATE_CLK(otgphy0, xin24m, OTGPHY0);
1666 GATE_CLK(otgphy1, xin24m, OTGPHY1);
1669 GATE_CLK(smc, pclk_periph, SMC);//smc
1671 static struct clk clk_sdmmc = {
1673 .parent = &hclk_periph,
1675 .recalc = clksel_recalc_div,
1676 .set_rate = clksel_set_rate_even,
1677 .gate_idx = CLK_GATE_MMC0,
1678 .clksel_con =CRU_CLKSELS_CON(11),
1679 CRU_DIV_SET(0x3f,0,64),
1682 static struct clk clk_sdio = {
1684 .parent = &hclk_periph,
1686 .recalc = clksel_recalc_div,
1687 .set_rate = clksel_set_rate_even,
1688 .gate_idx = CLK_GATE_SDIO,
1689 .clksel_con =CRU_CLKSELS_CON(12),
1690 CRU_DIV_SET(0x3f,0,64),
1694 static struct clk clk_emmc = {
1696 .parent = &hclk_periph,
1698 .recalc = clksel_recalc_div,
1699 .set_rate = clksel_set_rate_freediv,
1700 .gate_idx = CLK_GATE_EMMC,
1701 .clksel_con =CRU_CLKSELS_CON(12),
1702 CRU_DIV_SET(0x3f,8,64),
1705 static struct clk *clk_uart_src_parents[2]={&general_pll_clk,&codec_pll_clk};
1706 static struct clk clk_uart_pll = {
1708 .parent = &general_pll_clk,
1709 .clksel_con =CRU_CLKSELS_CON(12),
1710 CRU_SRC_SET(0x1,15),
1711 CRU_PARENTS_SET(clk_uart_src_parents),
1713 static struct clk clk_uart0_div = {
1714 .name = "uart0_div",
1715 .parent = &clk_uart_pll,
1717 .gate_idx = CLK_GATE_UART0,
1718 .recalc = clksel_recalc_div,
1719 .set_rate = clksel_set_rate_freediv,
1720 .round_rate =clksel_freediv_round_rate,
1721 .clksel_con = CRU_CLKSELS_CON(13),
1722 CRU_DIV_SET(0x7f,0,64),
1724 static struct clk clk_uart1_div = {
1725 .name = "uart1_div",
1726 .parent = &clk_uart_pll,
1728 .gate_idx = CLK_GATE_UART1,
1729 .recalc = clksel_recalc_div,
1730 .round_rate =clksel_freediv_round_rate,
1731 .set_rate = clksel_set_rate_freediv,
1732 .clksel_con = CRU_CLKSELS_CON(14),
1733 CRU_DIV_SET(0x7f,0,64),
1736 static struct clk clk_uart2_div = {
1737 .name = "uart2_div",
1738 .parent = &clk_uart_pll,
1740 .gate_idx = CLK_GATE_UART2,
1741 .recalc = clksel_recalc_div,
1742 .round_rate =clksel_freediv_round_rate,
1743 .set_rate = clksel_set_rate_freediv,
1744 .clksel_con = CRU_CLKSELS_CON(15),
1745 CRU_DIV_SET(0x7f,0,64),
1748 static struct clk clk_uart3_div = {
1749 .name = "uart3_div",
1750 .parent = &clk_uart_pll,
1752 .gate_idx = CLK_GATE_UART3,
1753 .recalc = clksel_recalc_div,
1754 .round_rate =clksel_freediv_round_rate,
1755 .set_rate = clksel_set_rate_freediv,
1756 .clksel_con = CRU_CLKSELS_CON(16),
1757 CRU_DIV_SET(0x7f,0,64),
1759 static int clk_uart_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1761 u32 numerator, denominator;
1762 //clk_uart0_div->clk_uart_pll->gpll/cpll
1763 //clk->parent->parent
1764 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1765 &numerator,&denominator)==0)
1767 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1769 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1771 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1775 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1781 static struct clk clk_uart0_frac_div = {
1782 .name = "uart0_frac_div",
1783 .parent = &clk_uart0_div,
1785 .recalc = clksel_recalc_frac,
1786 .set_rate = clk_uart_fracdiv_set_rate,
1787 .gate_idx = CLK_GATE_FRAC_UART0,
1788 .clksel_con = CRU_CLKSELS_CON(17),
1790 static struct clk clk_uart1_frac_div = {
1791 .name = "uart1_frac_div",
1792 .parent = &clk_uart1_div,
1794 .recalc = clksel_recalc_frac,
1795 .set_rate = clk_uart_fracdiv_set_rate,
1796 .gate_idx = CLK_GATE_FRAC_UART1,
1797 .clksel_con = CRU_CLKSELS_CON(18),
1799 static struct clk clk_uart2_frac_div = {
1800 .name = "uart2_frac_div",
1802 .parent = &clk_uart2_div,
1803 .recalc = clksel_recalc_frac,
1804 .set_rate = clk_uart_fracdiv_set_rate,
1805 .gate_idx = CLK_GATE_FRAC_UART2,
1806 .clksel_con = CRU_CLKSELS_CON(19),
1808 static struct clk clk_uart3_frac_div = {
1809 .name = "uart3_frac_div",
1810 .parent = &clk_uart3_div,
1812 .recalc = clksel_recalc_frac,
1813 .set_rate = clk_uart_fracdiv_set_rate,
1814 .gate_idx = CLK_GATE_FRAC_UART3,
1815 .clksel_con = CRU_CLKSELS_CON(20),
1819 #define UART_SRC_DIV 0
1820 #define UART_SRC_FRAC 1
1821 #define UART_SRC_24M 2
1823 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
1828 if(rate==clk->parents[UART_SRC_24M]->rate)//24m
1830 parent = clk->parents[UART_SRC_24M];
1832 else if((long)clk_round_rate_nolock(clk->parents[UART_SRC_DIV], rate)==rate)
1834 parent = clk->parents[UART_SRC_DIV];
1838 parent = clk->parents[UART_SRC_FRAC];
1841 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
1842 clk->name,rate,parent->name,clk->parent->name);
1845 if(parent!=clk->parents[UART_SRC_24M])
1847 ret = clk_set_rate_nolock(parent,rate);
1850 CRU_PRINTK_DBG("%s set rate%lu err\n",clk->name,rate);
1855 if (clk->parent != parent)
1857 ret = clk_set_parent_nolock(clk, parent);
1860 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
1870 static struct clk *clk_uart0_parents[3]={&clk_uart0_div,&clk_uart0_frac_div,&xin24m};
1871 static struct clk clk_uart0 = {
1873 .set_rate = clk_uart_set_rate,
1874 .clksel_con = CRU_CLKSELS_CON(13),
1876 CRU_PARENTS_SET(clk_uart0_parents),
1879 static struct clk *clk_uart1_parents[3]={&clk_uart1_div,&clk_uart1_frac_div,&xin24m};
1880 static struct clk clk_uart1 = {
1882 .set_rate = clk_uart_set_rate,
1883 .clksel_con = CRU_CLKSELS_CON(14),
1885 CRU_PARENTS_SET(clk_uart1_parents),
1888 static struct clk *clk_uart2_parents[3]={&clk_uart2_div,&clk_uart2_frac_div,&xin24m};
1889 static struct clk clk_uart2 = {
1891 .set_rate = clk_uart_set_rate,
1892 .clksel_con = CRU_CLKSELS_CON(15),
1894 CRU_PARENTS_SET(clk_uart2_parents),
1896 static struct clk *clk_uart3_parents[3]={&clk_uart3_div,&clk_uart3_frac_div,&xin24m};
1897 static struct clk clk_uart3 = {
1899 .set_rate = clk_uart_set_rate,
1900 .clksel_con = CRU_CLKSELS_CON(16),
1902 CRU_PARENTS_SET(clk_uart3_parents),
1905 GATE_CLK(timer0, xin24m, TIMER0);
1906 GATE_CLK(timer1, xin24m, TIMER1);
1907 GATE_CLK(timer2, xin24m, TIMER2);
1909 static struct clk rmii_clkin = {
1910 .name = "rmii_clkin",
1912 static struct clk *clk_mac_ref_div_parents[2]={&general_pll_clk,&ddr_pll_clk};
1913 static struct clk clk_mac_pll_div = {
1914 .name = "mac_pll_div",
1915 .parent = &ddr_pll_clk,
1917 .gate_idx = CLK_GATE_MAC,
1918 .recalc = clksel_recalc_div,
1919 .set_rate =clksel_set_rate_freediv,
1920 //.set_rate = clksel_set_rate_freediv,
1921 .clksel_con =CRU_CLKSELS_CON(21),
1922 CRU_DIV_SET(0x1f,8,32),
1924 CRU_PARENTS_SET(clk_mac_ref_div_parents),
1927 static int clksel_mac_ref_set_rate(struct clk *clk, unsigned long rate)
1930 if(clk->parent==clk->parents[1])
1932 CRU_PRINTK_DBG("mac_ref clk is form mii clkin,can't set it\n" );
1935 else if(clk->parent==clk->parents[0])
1937 return clk_set_rate_nolock(clk->parents[0],rate);
1942 static struct clk *clk_mac_ref_parents[2]={&clk_mac_pll_div,&rmii_clkin};
1944 static struct clk clk_mac_ref = {
1946 .parent = &clk_mac_pll_div,
1947 .set_rate = clksel_mac_ref_set_rate,
1948 .clksel_con =CRU_CLKSELS_CON(21),
1950 CRU_PARENTS_SET(clk_mac_ref_parents),
1953 static int clk_set_mii_tx_parent(struct clk *clk, struct clk *parent)
1955 return clk_set_parent_nolock(clk->parent,parent);
1958 static struct clk clk_mii_tx = {
1960 .parent = &clk_mac_ref,
1961 //.set_parent = clk_set_mii_tx_parent,
1963 .gate_idx = CLK_GATE_MAC_LBTEST,//???
1966 static struct clk *clk_hsadc_pll_parents[2]={&general_pll_clk,&codec_pll_clk};
1967 static struct clk clk_hsadc_pll_div = {
1968 .name = "hsadc_pll_div",
1969 .parent = &general_pll_clk,
1971 .gate_idx = CLK_GATE_SARADC,
1972 .recalc = clksel_recalc_div,
1973 .round_rate =clk_freediv_round_autosel_parents_rate,
1974 .set_rate = clkset_rate_freediv_autosel_parents,
1975 //.round_rate =clksel_freediv_round_rate,
1976 //.set_rate = clksel_set_rate_freediv,
1977 .clksel_con =CRU_CLKSELS_CON(22),
1978 CRU_DIV_SET(0xff,8,256),
1980 CRU_PARENTS_SET(clk_hsadc_pll_parents),
1983 static int clk_hsadc_fracdiv_set_rate_fixed_parent(struct clk *clk, unsigned long rate)
1985 u32 numerator, denominator;
1986 // clk_hsadc_pll_div->gpll/cpll
1987 //clk->parent->parent
1988 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1989 &numerator,&denominator)==0)
1991 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1993 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1995 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1999 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
2004 static int clk_hsadc_fracdiv_set_rate_auto_parents(struct clk *clk, unsigned long rate)
2006 u32 numerator, denominator;
2008 // clk_hsadc_pll_div->gpll/cpll
2009 //clk->parent->parent
2012 if(frac_div_get_seting(rate,clk->parent->parents[i]->rate,
2013 &numerator,&denominator)==0)
2019 if(clk->parent->parent!=clk->parent->parents[i])
2020 ret=clk_set_parent_nolock(clk->parent, clk->parent->parents[i]);
2023 clk_set_rate_nolock(clk->parent,clk->parent->parents[i]->rate);//PLL:DIV 1:
2025 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2027 CRU_PRINTK_DBG("clk_frac_div %s, rate=%lu\n",clk->name,rate);
2031 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
2037 static long clk_hsadc_fracdiv_round_rate(struct clk *clk, unsigned long rate)
2039 u32 numerator, denominator;
2041 CRU_PRINTK_ERR("clk_hsadc_fracdiv_round_rate\n");
2042 if(frac_div_get_seting(rate,clk->parent->parent->rate,
2043 &numerator,&denominator)==0)
2048 static struct clk clk_hsadc_frac_div = {
2049 .name = "hsadc_frac_div",
2050 .parent = &clk_hsadc_pll_div,
2052 .recalc = clksel_recalc_frac,
2053 .set_rate = clk_hsadc_fracdiv_set_rate_auto_parents,
2054 .round_rate =clk_hsadc_fracdiv_round_rate,
2055 .gate_idx = CLK_GATE_HSADC_FRAC,
2056 .clksel_con = CRU_CLKSELS_CON(23),
2059 #define HSADC_SRC_DIV 0x0
2060 #define HSADC_SRC_FRAC 0x1
2061 #define HSADC_SRC_EXT 0x2
2062 static int clk_hsadc_set_rate(struct clk *clk, unsigned long rate)
2067 if(clk->parent == clk->parents[HSADC_SRC_EXT]){
2068 CRU_PRINTK_DBG("hsadc clk is form ext\n");
2071 else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_DIV],rate)==rate)
2073 parent =clk->parents[HSADC_SRC_DIV];
2075 else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_FRAC],rate)==rate)
2077 parent = clk->parents[HSADC_SRC_FRAC];
2080 parent =clk->parents[HSADC_SRC_DIV];
2082 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
2083 clk->name,rate,parent->name,clk->parent->name);
2085 ret = clk_set_rate_nolock(parent,rate);
2088 CRU_PRINTK_ERR("%s set rate%lu err\n",clk->name,rate);
2091 if (clk->parent != parent)
2093 ret = clk_set_parent_nolock(clk, parent);
2096 CRU_PRINTK_ERR("%s can't get rate%lu,reparent err\n",clk->name,rate);
2103 static struct clk clk_hsadc_ext = {
2104 .name = "hsadc_ext",
2107 static struct clk *clk_hsadc_parents[3]={&clk_hsadc_pll_div,&clk_hsadc_frac_div,&clk_hsadc_ext};
2108 static struct clk clk_hsadc = {
2110 .parent = &clk_hsadc_pll_div,
2111 .set_rate = clk_hsadc_set_rate,
2112 .clksel_con = CRU_CLKSELS_CON(22),
2114 CRU_PARENTS_SET(clk_hsadc_parents),
2117 static struct clk *dclk_lcdc_div_parents[]={&codec_pll_clk,&general_pll_clk};
2118 static struct clk dclk_lcdc0_div = {
2119 .name = "dclk_lcdc0_div",
2120 .parent = &general_pll_clk,
2121 .recalc = clksel_recalc_div,
2122 .set_rate = clkset_rate_freediv_autosel_parents,
2123 .clksel_con = CRU_CLKSELS_CON(27),
2124 CRU_DIV_SET(0xff,8,256),
2126 CRU_PARENTS_SET(dclk_lcdc_div_parents),
2129 static int clksel_set_rate_hdmi(struct clk *clk, unsigned long rate)
2133 unsigned long new_rate;
2140 div=clk_get_freediv(rate,clk->parents[i]->rate,clk->div_max);
2141 new_rate= clk->parents[i]->rate/div;
2142 if((rate==new_rate)&&!(clk->parents[i]->rate%div))
2149 CRU_PRINTK_ERR("%s can't set fixed rate%lu\n",clk->name,rate);
2153 //CRU_PRINTK_DBG("%s set rate %lu(from %s)\n",clk->name,rate,clk->parents[i]->name);
2155 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),
2156 clk->div_shift,clk->div_mask)+1;
2158 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
2160 if(clk->parents[i]!=clk->parent)
2162 ret=clk_set_parent_nolock(clk,clk->parents[i]);
2167 CRU_PRINTK_ERR("lcdc1 %s can't get rate%lu,reparent%s(now %s) err\n",
2168 clk->name,rate,clk->parents[i]->name,clk->parent->name);
2171 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
2175 static struct clk dclk_lcdc1_div = {
2176 .name = "dclk_lcdc1_div",
2177 .parent = &general_pll_clk,
2178 .recalc = clksel_recalc_div,
2179 .set_rate = clksel_set_rate_hdmi,//clk_freediv_autosel_parents_set_fixed_rate
2180 .clksel_con = CRU_CLKSELS_CON(28),
2181 CRU_DIV_SET(0xff,8,256),
2183 CRU_PARENTS_SET(dclk_lcdc_div_parents),
2186 static int dclk_lcdc_set_rate(struct clk *clk, unsigned long rate)
2191 if (rate == 27 * MHZ&&(rk30_clock_flags&CLK_FLG_EXT_27MHZ)) {
2192 parent =clk->parents[1];
2193 //CRU_PRINTK_DBG(" %s from=%s\n",clk->name,parent->name);
2195 parent=clk->parents[0];
2197 //CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
2198 //clk->name,rate,parent->name,clk->parent->name);
2200 if(parent!=clk->parents[1])
2202 ret = clk_set_rate_nolock(parent,rate);//div 1:1
2205 CRU_PRINTK_DBG("%s set rate=%lu err\n",clk->name,rate);
2209 if (clk->parent != parent)
2211 ret = clk_set_parent_nolock(clk, parent);
2214 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
2221 static struct clk *dclk_lcdc0_parents[2]={&dclk_lcdc0_div,&xin27m};
2222 static struct clk dclk_lcdc0 = {
2223 .name = "dclk_lcdc0",
2225 .set_rate = dclk_lcdc_set_rate,
2226 .gate_idx = CLK_GATE_DCLK_LCDC0,
2227 .clksel_con = CRU_CLKSELS_CON(27),
2229 CRU_PARENTS_SET(dclk_lcdc0_parents),
2232 static struct clk *dclk_lcdc1_parents[2]={&dclk_lcdc1_div,&xin27m};
2233 static struct clk dclk_lcdc1 = {
2234 .name = "dclk_lcdc1",
2236 .set_rate = dclk_lcdc_set_rate,
2237 .gate_idx = CLK_GATE_DCLK_LCDC1,
2238 .clksel_con = CRU_CLKSELS_CON(28),
2240 CRU_PARENTS_SET(dclk_lcdc1_parents),
2243 static struct clk *cifout_sel_pll_parents[2]={&codec_pll_clk,&general_pll_clk};
2244 static struct clk cif_out_pll = {
2245 .name = "cif_out_pll",
2246 .parent = &general_pll_clk,
2247 .clksel_con = CRU_CLKSELS_CON(29),
2249 CRU_PARENTS_SET(cifout_sel_pll_parents),
2252 static struct clk cif0_out_div = {
2253 .name = "cif0_out_div",
2254 .parent = &cif_out_pll,
2256 .recalc = clksel_recalc_div,
2257 .set_rate = clksel_set_rate_freediv,
2258 .gate_idx =CLK_GATE_CIF0_OUT,
2259 .clksel_con = CRU_CLKSELS_CON(29),
2260 CRU_DIV_SET(0x1f,1,32),
2263 static struct clk cif1_out_div = {
2264 .name = "cif1_out_div",
2265 .parent = &cif_out_pll,
2267 .recalc = clksel_recalc_div,
2268 .set_rate = clksel_set_rate_freediv,
2269 .gate_idx = CLK_GATE_CIF1_OUT,
2270 .clksel_con = CRU_CLKSELS_CON(29),
2271 CRU_DIV_SET(0x1f,8,32),
2275 static int cif_out_set_rate(struct clk *clk, unsigned long rate)
2280 if (rate == 24 * MHZ) {
2281 parent =clk->parents[1];
2283 parent=clk->parents[0];
2284 ret = clk_set_rate_nolock(parent, rate);
2288 if (clk->parent != parent)
2289 ret = clk_set_parent_nolock(clk, parent);
2294 static struct clk *cif0_out_parents[2]={&cif0_out_div,&xin24m};
2295 static struct clk cif0_out = {
2297 .parent = &cif0_out_div,
2298 .set_rate = cif_out_set_rate,
2299 .clksel_con = CRU_CLKSELS_CON(29),
2301 CRU_PARENTS_SET(cif0_out_parents),
2303 static struct clk *cif1_out_parents[2]={&cif1_out_div,&xin24m};
2305 static struct clk cif1_out = {
2307 .parent = &cif1_out_div,
2308 .set_rate = cif_out_set_rate,
2309 .clksel_con = CRU_CLKSELS_CON(29),
2310 CRU_SRC_SET(0x1,15),
2311 CRU_PARENTS_SET(cif1_out_parents),
2314 static struct clk pclkin_cif0 = {
2315 .name = "pclkin_cif0",
2317 .gate_idx =CLK_GATE_PCLKIN_CIF0,
2320 static struct clk inv_cif0 = {
2322 .parent = &pclkin_cif0,
2325 static struct clk *cif0_in_parents[2]={&pclkin_cif0,&inv_cif0};
2326 static struct clk cif0_in = {
2328 .parent = &pclkin_cif0,
2329 .clksel_con = CRU_CLKSELS_CON(30),
2331 CRU_PARENTS_SET(cif0_in_parents),
2334 static struct clk pclkin_cif1 = {
2335 .name = "pclkin_cif1",
2337 .gate_idx =CLK_GATE_PCLKIN_CIF1,
2340 static struct clk inv_cif1 = {
2342 .parent = &pclkin_cif1,
2344 static struct clk *cif1_in_parents[2]={&pclkin_cif1,&inv_cif1};
2346 static struct clk cif1_in = {
2348 .parent = &pclkin_cif1,
2349 .clksel_con = CRU_CLKSELS_CON(30),
2350 CRU_SRC_SET(0x1,12),
2351 CRU_PARENTS_SET(cif1_in_parents),
2354 static struct clk *aclk_lcdc0_ipp_parents[]={&codec_pll_clk,&general_pll_clk};
2356 static struct clk aclk_lcdc0_ipp_parent = {
2357 .name = "aclk_lcdc0_ipp_parent",
2358 .parent = &codec_pll_clk,
2360 .recalc = clksel_recalc_div,
2361 .set_rate = clkset_rate_freediv_autosel_parents,
2362 //.set_rate = clksel_set_rate_freediv,
2363 .gate_idx = CLK_GATE_ACLK_LCDC0_SRC,
2364 .clksel_con = CRU_CLKSELS_CON(31),
2365 CRU_DIV_SET(0x1f,0,32),
2367 CRU_PARENTS_SET(aclk_lcdc0_ipp_parents),
2370 static struct clk *aclk_lcdc1_rga_parents[]={&codec_pll_clk,&general_pll_clk};
2372 static struct clk aclk_lcdc1_rga_parent = {
2373 .name = "aclk_lcdc1_rga_parent",
2374 .parent = &codec_pll_clk,
2376 .recalc = clksel_recalc_div,
2377 .set_rate = clkset_rate_freediv_autosel_parents,
2378 .gate_idx = CLK_GATE_ACLK_LCDC1_SRC,
2379 .clksel_con = CRU_CLKSELS_CON(31),
2380 CRU_DIV_SET(0x1f,8,32),
2381 CRU_SRC_SET(0x1,15),
2382 CRU_PARENTS_SET(aclk_lcdc1_rga_parents),
2387 static unsigned long clksel_recalc_vpu_hclk(struct clk *clk)
2389 unsigned long rate = clk->parent->rate / 4;
2390 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, 4);
2394 static struct clk *aclk_vepu_parents[2]={&codec_pll_clk,&general_pll_clk};
2396 static struct clk aclk_vepu = {
2397 .name = "aclk_vepu",
2398 .parent = &codec_pll_clk,
2400 .recalc = clksel_recalc_div,
2401 //.set_rate = clksel_set_rate_freediv,
2402 .set_rate =clkset_rate_freediv_autosel_parents,
2403 .clksel_con = CRU_CLKSELS_CON(32),
2404 .gate_idx = CLK_GATE_ACLK_VEPU,
2405 CRU_DIV_SET(0x1f,0,32),
2407 CRU_PARENTS_SET(aclk_vepu_parents),
2410 static struct clk hclk_vepu = {
2411 .name = "hclk_vepu",
2412 .parent = &aclk_vepu,
2414 .recalc = clksel_recalc_vpu_hclk,
2415 .clksel_con = CRU_CLKSELS_CON(32),
2416 .gate_idx = CLK_GATE_HCLK_VEPU,
2419 static struct clk *aclk_vdpu_parents[2]={&codec_pll_clk,&general_pll_clk};
2421 static struct clk aclk_vdpu = {
2422 .name = "aclk_vdpu",
2424 .recalc = clksel_recalc_div,
2425 //.set_rate = clksel_set_rate_freediv,
2426 .set_rate =clkset_rate_freediv_autosel_parents,
2427 .clksel_con = CRU_CLKSELS_CON(32),
2428 .gate_idx = CLK_GATE_ACLK_VDPU,
2429 CRU_DIV_SET(0x1f,8,32),
2430 CRU_SRC_SET(0x1,15),
2431 CRU_PARENTS_SET(aclk_vdpu_parents),
2433 static struct clk hclk_vdpu = {
2434 .name = "hclk_vdpu",
2435 .parent = &aclk_vdpu,
2437 .recalc = clksel_recalc_vpu_hclk,
2438 .clksel_con = CRU_CLKSELS_CON(32),
2439 .gate_idx = CLK_GATE_HCLK_VDPU,
2443 static int clk_gpu_set_rate(struct clk *clk, unsigned long rate)
2445 unsigned long max_rate = rate / 100 * 105; /* +5% */
2446 return clkset_rate_freediv_autosel_parents(clk,max_rate);
2449 static struct clk *gpu_parents[2]={&codec_pll_clk,&general_pll_clk};
2451 static struct clk clk_gpu = {
2454 .recalc = clksel_recalc_div,
2455 .round_rate = clk_freediv_round_autosel_parents_rate,
2456 .set_rate = clkset_rate_freediv_autosel_parents,
2457 .clksel_con = CRU_CLKSELS_CON(33),
2458 .gate_idx = CLK_GATE_GPU_SRC,
2459 CRU_DIV_SET(0x1f,0,32),
2461 CRU_PARENTS_SET(gpu_parents),
2464 /*********************power domain*******************************/
2465 #ifdef RK30_CLK_OFFBOARD_TEST
2466 void pmu_set_power_domain_test(enum pmu_power_domain pd, bool on){};
2467 #define _pmu_set_power_domain pmu_set_power_domain_test//rk30_pmu_set_power_domain
2469 void pmu_set_power_domain(enum pmu_power_domain pd, bool on);
2470 #define _pmu_set_power_domain pmu_set_power_domain
2472 static int pm_off_mode(struct clk *clk, int on)
2474 _pmu_set_power_domain(clk->gate_idx,on);//on 1
2477 static struct clk pd_peri = {
2480 .mode = pm_off_mode,
2481 .gate_idx = PD_PERI,
2484 static int pd_display_mode(struct clk *clk, int on)
2488 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2489 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2490 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2491 gate[3] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2492 gate[4] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2493 gate[5] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2494 gate[6] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2495 gate[7] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2496 gate[8] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2497 gate[9] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2498 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2499 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2500 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2501 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2502 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2503 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2504 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2505 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2506 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2507 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2508 pmu_set_power_domain(PD_VIO, on);
2509 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2510 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2511 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2512 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1) | gate[3], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2513 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0) | gate[4], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2514 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1) | gate[5], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2515 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0) | gate[6], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2516 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1) | gate[7], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2517 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP) | gate[8], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2518 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA) | gate[9], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2523 static struct clk pd_display = {
2524 .name = "pd_display",
2526 .mode = pd_display_mode,
2530 static struct clk pd_lcdc0 = {
2531 .parent = &pd_display,
2534 static struct clk pd_lcdc1 = {
2535 .parent = &pd_display,
2538 static struct clk pd_cif0 = {
2539 .parent = &pd_display,
2542 static struct clk pd_cif1 = {
2543 .parent = &pd_display,
2546 static struct clk pd_rga = {
2547 .parent = &pd_display,
2550 static struct clk pd_ipp = {
2551 .parent = &pd_display,
2555 static int pd_video_mode(struct clk *clk, int on)
2559 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2560 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2561 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2562 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2563 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2564 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2565 pmu_set_power_domain(PD_VIDEO, on);
2566 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2567 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2568 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2573 static struct clk pd_video = {
2576 .mode = pd_video_mode,
2577 .gate_idx = PD_VIDEO,
2580 static int pd_gpu_mode(struct clk *clk, int on)
2584 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2585 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2586 cru_writel(CLK_GATE_W_MSK(CLK_GATE_GPU_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2587 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2588 pmu_set_power_domain(PD_GPU, on);
2589 cru_writel(CLK_GATE_W_MSK(CLK_GATE_GPU_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2590 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2595 static struct clk pd_gpu = {
2598 .mode = pd_gpu_mode,
2601 static struct clk pd_dbg = {
2604 .mode = pm_off_mode,
2608 #define PD_CLK(name) \
2616 /************************rk30 fixed div clock****************************************/
2618 /*************************aclk_cpu***********************/
2620 GATE_CLK(dma1, aclk_cpu, ACLK_DMAC1);
2621 GATE_CLK(l2mem_con, aclk_cpu, ACLK_L2MEM_CON);
2622 GATE_CLK(intmem, aclk_cpu, ACLK_INTMEM);
2623 GATE_CLK(aclk_strc_sys, aclk_cpu, ACLK_STRC_SYS);
2625 /*************************hclk_cpu***********************/
2627 GATE_CLK(rom, hclk_cpu, HCLK_ROM);
2628 GATE_CLK(hclk_i2s0_2ch, hclk_cpu, HCLK_I2S0_2CH);
2629 GATE_CLK(hclk_i2s1_2ch, hclk_cpu, HCLK_I2S1_2CH);
2630 GATE_CLK(hclk_spdif, hclk_cpu, HCLK_SPDIF);
2631 GATE_CLK(hclk_i2s_8ch, hclk_cpu, HCLK_I2S_8CH);
2632 GATE_CLK(hclk_cpubus, hclk_cpu, HCLK_CPUBUS);
2633 GATE_CLK(hclk_ahb2apb, hclk_cpu, HCLK_AHB2APB);
2634 GATE_CLK(hclk_vio_bus, hclk_cpu, HCLK_VIO_BUS);
2635 GATE_CLK(hclk_lcdc0, hclk_cpu, HCLK_LCDC0);
2636 GATE_CLK(hclk_lcdc1, hclk_cpu, HCLK_LCDC1);
2637 GATE_CLK(hclk_cif0, hclk_cpu, HCLK_CIF0);
2638 GATE_CLK(hclk_cif1, hclk_cpu, HCLK_CIF1);
2639 GATE_CLK(hclk_ipp, hclk_cpu, HCLK_IPP);
2640 GATE_CLK(hclk_rga, hclk_cpu, HCLK_RGA);
2641 GATE_CLK(hclk_hdmi, hclk_cpu, HCLK_HDMI);
2642 //GATE_CLK(hclk_vidoe_h2h, hclk_cpu, ); ???
2643 /*************************pclk_cpu***********************/
2644 GATE_CLK(pwm01, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2645 //GATE_CLK(pclk_pwm1, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2646 GATE_CLK(pclk_timer0, pclk_cpu, PCLK_TIMER0);
2647 GATE_CLK(pclk_timer1, pclk_cpu, PCLK_TIMER1);
2648 GATE_CLK(pclk_timer2, pclk_cpu, PCLK_TIMER2);
2649 GATE_CLK(i2c0, pclk_cpu, PCLK_I2C0);
2650 GATE_CLK(i2c1, pclk_cpu, PCLK_I2C1);
2651 GATE_CLK(gpio0, pclk_cpu, PCLK_GPIO0);
2652 GATE_CLK(gpio1, pclk_cpu, PCLK_GPIO1);
2653 GATE_CLK(gpio2, pclk_cpu, PCLK_GPIO2);
2654 GATE_CLK(gpio6, pclk_cpu, PCLK_GPIO6);
2655 GATE_CLK(efuse, pclk_cpu, PCLK_EFUSE);
2656 GATE_CLK(tzpc, pclk_cpu, PCLK_TZPC);
2657 GATE_CLK(pclk_uart0, pclk_cpu, PCLK_UART0);
2658 GATE_CLK(pclk_uart1, pclk_cpu, PCLK_UART1);
2659 GATE_CLK(pclk_ddrupctl, pclk_cpu, PCLK_DDRUPCTL);
2660 GATE_CLK(pclk_ddrpubl, pclk_cpu, PCLK_PUBL);
2661 GATE_CLK(dbg, pclk_cpu, PCLK_DBG);
2662 GATE_CLK(grf, pclk_cpu, PCLK_GRF);
2663 GATE_CLK(pmu, pclk_cpu, PCLK_PMU);
2665 /*************************aclk_periph***********************/
2667 GATE_CLK(dma2, aclk_periph,ACLK_DMAC2);
2668 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
2669 GATE_CLK(aclk_peri_niu, aclk_periph, ACLK_PEI_NIU);
2670 GATE_CLK(aclk_cpu_peri, aclk_periph, ACLK_CPU_PERI);
2671 GATE_CLK(aclk_peri_axi_matrix, aclk_periph, ACLK_PERI_AXI_MATRIX);
2673 /*************************hclk_periph***********************/
2674 GATE_CLK(hclk_peri_axi_matrix, hclk_periph, HCLK_PERI_AXI_MATRIX);
2675 GATE_CLK(hclk_peri_ahb_arbi, hclk_periph, HCLK_PERI_AHB_ARBI);
2676 GATE_CLK(hclk_emem_peri, hclk_periph, HCLK_EMEM_PERI);
2677 GATE_CLK(hclk_mac, hclk_periph, HCLK_EMAC);
2678 GATE_CLK(nandc, hclk_periph, HCLK_NANDC);
2679 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
2680 GATE_CLK(hclk_otg0, clk_hclk_usb_peri, HCLK_OTG0);
2681 GATE_CLK(hclk_otg1, clk_hclk_usb_peri, HCLK_OTG1);
2682 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
2683 GATE_CLK(hclk_pidfilter, hclk_periph, HCLK_PIDF);
2684 GATE_CLK(hclk_sdmmc, hclk_periph, HCLK_SDMMC0);
2685 GATE_CLK(hclk_sdio, hclk_periph, HCLK_SDIO);
2686 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
2687 /*************************pclk_periph***********************/
2688 GATE_CLK(pclk_peri_axi_matrix, pclk_periph, PCLK_PERI_AXI_MATRIX);
2689 GATE_CLK(pwm23, pclk_periph, PCLK_PWM23);
2690 //GATE_CLK(pclk_pwm3, pclk_periph, PCLK_PWM3);
2691 GATE_CLK(wdt, pclk_periph, PCLK_WDT);
2692 GATE_CLK(pclk_spi0, pclk_periph, PCLK_SPI0);
2693 GATE_CLK(pclk_spi1, pclk_periph, PCLK_SPI1);
2694 GATE_CLK(pclk_uart2, pclk_periph, PCLK_UART2);
2695 GATE_CLK(pclk_uart3, pclk_periph, PCLK_UART3);
2696 GATE_CLK(i2c2, pclk_periph, PCLK_I2C2);
2697 GATE_CLK(i2c3, pclk_periph, PCLK_I2C3);
2698 GATE_CLK(i2c4, pclk_periph, PCLK_I2C4);
2699 GATE_CLK(gpio3, pclk_periph, PCLK_GPIO3);
2700 GATE_CLK(gpio4, pclk_periph, PCLK_GPIO4);
2701 GATE_CLK(pclk_saradc, pclk_periph, PCLK_SARADC);
2702 GATE_CLK(pclk_tsadc, pclk_periph, PCLK_TSADC);
2703 /*************************aclk_lcdc0***********************/
2704 GATE_CLK(aclk_lcdc0, aclk_lcdc0_ipp_parent, ACLK_LCDC0);
2705 GATE_CLK(aclk_vio0, aclk_lcdc0_ipp_parent, ACLK_VIO0);
2706 GATE_CLK(aclk_cif0, aclk_lcdc0_ipp_parent, ACLK_CIF0);
2707 GATE_CLK(aclk_ipp, aclk_lcdc0_ipp_parent, ACLK_IPP);
2709 /*************************aclk_lcdc0***********************/
2711 GATE_CLK(aclk_lcdc1, aclk_lcdc1_rga_parent, ACLK_LCDC1);
2712 GATE_CLK(aclk_vio1, aclk_lcdc1_rga_parent, ACLK_VIO1);
2713 GATE_CLK(aclk_cif1, aclk_lcdc1_rga_parent, ACLK_CIF0);
2714 GATE_CLK(aclk_rga, aclk_lcdc1_rga_parent, ACLK_RGA);
2718 #define CLK(dev, con, ck) \
2726 #define CLK1(name) \
2730 .clk = &clk_##name,\
2738 static struct clk_lookup clks[] = {
2739 CLK(NULL, "xin24m", &xin24m),
2740 CLK(NULL, "xin27m", &xin27m),
2741 CLK(NULL, "xin12m", &clk_12m),
2742 CLK(NULL, "arm_pll", &arm_pll_clk),
2743 CLK(NULL, "ddr_pll", &ddr_pll_clk),
2744 CLK(NULL, "codec_pll", &codec_pll_clk),
2745 CLK(NULL, "general_pll", &general_pll_clk),
2747 CLK(NULL, "ddr", &clk_ddr),
2748 //CLK(NULL, "core_gpll_path", &clk_cpu_gpll_path),
2749 CLK(NULL, "cpu", &clk_cpu),
2750 CLK(NULL, "arm_gpll", &clk_cpu_gpll_path),
2751 CLK("smp_twd", NULL, &core_periph),
2752 CLK(NULL, "aclk_cpu", &aclk_cpu),
2753 CLK(NULL, "hclk_cpu", &hclk_cpu),
2754 CLK(NULL, "pclk_cpu", &pclk_cpu),
2755 CLK(NULL, "atclk_cpu", &atclk_cpu),
2759 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
2760 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
2761 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
2762 CLK("rk29_i2s.0", "hclk_i2s", &clk_hclk_i2s_8ch),
2764 CLK("rk29_i2s.1", "i2s_div", &clk_i2s1_div),
2765 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s1_frac_div),
2766 CLK("rk29_i2s.1", "i2s", &clk_i2s1),
2767 CLK("rk29_i2s.1", "hclk_i2s", &clk_hclk_i2s0_2ch),
2769 CLK("rk29_i2s.2", "i2s_div", &clk_i2s2_div),
2770 CLK("rk29_i2s.2", "i2s_frac_div", &clk_i2s2_frac_div),
2771 CLK("rk29_i2s.2", "i2s", &clk_i2s2),
2772 CLK("rk29_i2s.2", "hclk_i2s", &clk_hclk_i2s1_2ch),
2775 CLK1(spdif_frac_div),
2779 CLK(NULL, "aclk_periph", &aclk_periph),
2780 CLK(NULL, "pclk_periph", &pclk_periph),
2781 CLK(NULL, "hclk_periph", &hclk_periph),
2783 CLK("rk29xx_spim.0", "spi", &clk_spi0),
2784 CLK("rk29xx_spim.0", "pclk_spi", &clk_pclk_spi0),
2786 CLK("rk29xx_spim.1", "spi", &clk_spi1),
2787 CLK("rk29xx_spim.1", "pclk_spi", &clk_pclk_spi1),
2795 CLK1(hclk_usb_peri),
2806 CLK("rk29_sdmmc.0", "mmc", &clk_sdmmc),
2807 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_sdmmc),
2808 CLK("rk29_sdmmc.1", "mmc", &clk_sdio),
2809 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_sdio),
2816 CLK("rk_serial.0", "uart_div", &clk_uart0_div),
2817 CLK("rk_serial.0", "uart_frac_div", &clk_uart0_frac_div),
2818 CLK("rk_serial.0", "uart", &clk_uart0),
2819 CLK("rk_serial.0", "pclk_uart", &clk_pclk_uart0),
2820 CLK("rk_serial.1", "uart_div", &clk_uart1_div),
2821 CLK("rk_serial.1", "uart_frac_div", &clk_uart1_frac_div),
2822 CLK("rk_serial.1", "uart", &clk_uart1),
2823 CLK("rk_serial.1", "pclk_uart", &clk_pclk_uart1),
2824 CLK("rk_serial.2", "uart_div", &clk_uart2_div),
2825 CLK("rk_serial.2", "uart_frac_div", &clk_uart2_frac_div),
2826 CLK("rk_serial.2", "uart", &clk_uart2),
2827 CLK("rk_serial.2", "pclk_uart", &clk_pclk_uart2),
2828 CLK("rk_serial.3", "uart_div", &clk_uart3_div),
2829 CLK("rk_serial.3", "uart_frac_div", &clk_uart3_frac_div),
2830 CLK("rk_serial.3", "uart", &clk_uart3),
2831 CLK("rk_serial.3", "pclk_uart", &clk_pclk_uart3),
2842 CLK(NULL, "rmii_clkin", &rmii_clkin),
2843 CLK(NULL, "mac_ref_div", &clk_mac_pll_div), // compatible with rk29
2846 CLK1(hsadc_pll_div),
2847 CLK1(hsadc_frac_div),
2852 CLK(NULL, "aclk_lcdc0_ipp_parent", &aclk_lcdc0_ipp_parent),
2853 CLK(NULL, "aclk_lcdc1_rga_parent", &aclk_lcdc1_rga_parent),
2855 CLK(NULL, "dclk_lcdc0_div", &dclk_lcdc0_div),
2856 CLK(NULL, "dclk_lcdc1_div", &dclk_lcdc1_div),
2858 CLK(NULL, "dclk_lcdc0", &dclk_lcdc0),
2859 CLK(NULL, "aclk_lcdc0", &clk_aclk_lcdc0),
2862 CLK(NULL, "dclk_lcdc1", &dclk_lcdc1),
2863 CLK(NULL, "aclk_lcdc1", &clk_aclk_lcdc1),
2866 CLK(NULL, "cif_out_pll", &cif_out_pll),
2867 CLK(NULL, "cif0_out_div", &cif0_out_div),
2868 CLK(NULL, "cif1_out_div", &cif1_out_div),
2870 CLK(NULL, "cif0_out", &cif0_out),
2873 CLK(NULL, "cif1_out", &cif1_out),
2880 CLK(NULL, "pclkin_cif0", &pclkin_cif0),
2881 CLK(NULL, "inv_cif0", &inv_cif0),
2882 CLK(NULL, "cif0_in", &cif0_in),
2883 CLK(NULL, "pclkin_cif1", &pclkin_cif1),
2884 CLK(NULL, "inv_cif1", &inv_cif1),
2885 CLK(NULL, "cif1_in", &cif1_in),
2886 //CLK(NULL, "aclk_lcdc0", &aclk_lcdc0),
2887 //CLK(NULL, "aclk_lcdc1", &aclk_lcdc1),
2888 CLK(NULL, "aclk_vepu", &aclk_vepu),
2889 CLK(NULL, "hclk_vepu", &hclk_vepu),
2890 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
2891 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
2897 CLK1(aclk_strc_sys),
2899 /*************************hclk_cpu***********************/
2902 //CLK1(hclk_i2s0_2ch),
2903 //CLK1(hclk_i2s1_2ch),
2905 //CLK1(hclk_i2s_8ch),
2916 //CLK1(hclk_vidoe_h2h, hclk_cpu, ); ???
2917 /*************************pclk_cpu***********************/
2918 CLK1(pwm01),//pwm 0¡¢1
2920 //CLK1(pclk_timer0),
2921 //CLK1(pclk_timer1),
2922 //CLK1(pclk_timer2),
2924 CLK("rk30_i2c.0", "i2c", &clk_i2c0),
2925 CLK("rk30_i2c.1", "i2c", &clk_i2c1),
2935 CLK1(pclk_ddrupctl),
2941 /*************************aclk_periph***********************/
2945 CLK1(aclk_peri_niu),
2946 CLK1(aclk_cpu_peri),
2947 CLK1(aclk_peri_axi_matrix),
2949 /*************************hclk_periph***********************/
2950 CLK1(hclk_peri_axi_matrix),
2951 CLK1(hclk_peri_ahb_arbi),
2952 CLK1(hclk_emem_peri),
2955 //CLK1(hclk_usb_peri),
2956 //CLK1(hclk_usbotg0),
2957 //CLK1(hclk_usbotg1),
2959 CLK1(hclk_pidfilter),
2962 /*************************pclk_periph***********************/
2963 CLK1(pclk_peri_axi_matrix),
2972 CLK("rk30_i2c.2", "i2c", &clk_i2c2),
2973 CLK("rk30_i2c.3", "i2c", &clk_i2c3),
2974 CLK("rk30_i2c.4", "i2c", &clk_i2c4),
2979 /*************************aclk_lcdc0***********************/
2984 /*************************aclk_lcdc0***********************/
2988 /************************power domain**********************/
3002 static void __init rk30_init_enable_clocks(void)
3004 //clk_enable_nolock(&xin24m);
3005 //clk_enable_nolock(&xin27m);
3006 //clk_enable_nolock(&clk_12m);
3007 //clk_enable_nolock(&arm_pll_clk);
3008 //clk_enable_nolock(&ddr_pll_clk);
3009 //clk_enable_nolock(&codec_pll_clk);
3010 //clk_enable_nolock(&general_pll_clk);
3011 //clk_enable_nolock(&clk_ddr);
3013 clk_enable_nolock(&clk_cpu);
3014 clk_enable_nolock(&core_periph);
3015 clk_enable_nolock(&aclk_cpu);
3016 clk_enable_nolock(&hclk_cpu);
3017 clk_enable_nolock(&pclk_cpu);
3018 clk_enable_nolock(&atclk_cpu);
3021 clk_enable_nolock(&clk_i2s_pll);
3022 clk_enable_nolock(&clk_i2s0_div);
3023 clk_enable_nolock(&clk_i2s0_frac_div);
3024 clk_enable_nolock(&clk_i2s0);
3025 clk_enable_nolock(&clk_hclk_i2s_8ch);
3027 clk_enable_nolock(&clk_i2s1_div);
3028 clk_enable_nolock(&clk_i2s1_frac_div);
3029 clk_enable_nolock(&clk_i2s1);
3030 clk_enable_nolock(&clk_hclk_i2s0_2ch);
3032 clk_enable_nolock(&clk_i2s2_div);
3033 clk_enable_nolock(&clk_i2s2_frac_div);
3034 clk_enable_nolock(&clk_i2s2);
3035 clk_enable_nolock(&clk_hclk_i2s1_2ch);
3037 clk_enable_nolock(&clk_spdif_div);
3038 clk_enable_nolock(&clk_spdif_frac_div);
3039 clk_enable_nolock(&clk_spdif);
3040 clk_enable_nolock(&clk_hclk_spdif);
3042 clk_enable_nolock(&aclk_periph);
3043 clk_enable_nolock(&pclk_periph);
3044 clk_enable_nolock(&hclk_periph);
3047 clk_enable_nolock(&clk_spi0);
3048 clk_enable_nolock(&clk_pclk_spi0);
3050 clk_enable_nolock(&clk_spi1);
3051 clk_enable_nolock(&clk_pclk_spi1);
3052 clk_enable_nolock(&clk_saradc);
3053 clk_enable_nolock(&clk_pclk_saradc);
3054 clk_enable_nolock(&clk_tsadc);
3055 clk_enable_nolock(&clk_pclk_tsadc);
3058 clk_enable_nolock(&clk_otgphy0);
3059 clk_enable_nolock(&clk_otgphy1);
3060 clk_enable_nolock(&clk_hclk_usb_peri);
3061 clk_enable_nolock(&clk_hclk_otg0);
3062 clk_enable_nolock(&clk_hclk_otg1);
3065 clk_enable_nolock(&clk_smc);
3066 clk_enable_nolock(&clk_aclk_smc);
3068 clk_enable_nolock(&clk_sdmmc);
3069 clk_enable_nolock(&clk_hclk_sdmmc);
3070 clk_enable_nolock(&clk_sdio);
3071 clk_enable_nolock(&clk_hclk_sdio);
3073 clk_enable_nolock(&clk_emmc);
3074 clk_enable_nolock(&clk_hclk_emmc);
3078 #if CONFIG_RK_DEBUG_UART == 0
3079 clk_enable_nolock(&clk_uart0);
3080 clk_enable_nolock(&clk_pclk_uart0);
3081 #elif CONFIG_RK_DEBUG_UART == 1
3082 clk_enable_nolock(&clk_uart1);
3083 clk_enable_nolock(&clk_pclk_uart1);
3085 #elif CONFIG_RK_DEBUG_UART == 2
3086 clk_enable_nolock(&clk_uart2);
3087 clk_enable_nolock(&clk_pclk_uart2);
3089 #elif CONFIG_RK_DEBUG_UART == 3
3090 clk_enable_nolock(&clk_uart3);
3091 clk_enable_nolock(&clk_pclk_uart3);
3096 clk_enable_nolock(&clk_timer0);
3097 clk_enable_nolock(&clk_pclk_timer0);
3099 clk_enable_nolock(&clk_timer1);
3100 clk_enable_nolock(&clk_pclk_timer1);
3102 clk_enable_nolock(&clk_timer2);
3103 clk_enable_nolock(&clk_pclk_timer2);
3106 clk_enable_nolock(&rmii_clkin);
3107 clk_enable_nolock(&clk_mac_pll_div);
3108 clk_enable_nolock(&clk_mac_ref);
3109 clk_enable_nolock(&clk_mii_tx);
3113 clk_enable_nolock(&clk_hsadc_pll_div);
3114 clk_enable_nolock(&clk_hsadc_frac_div);
3115 clk_enable_nolock(&clk_hsadc_ext);
3116 clk_enable_nolock(&clk_hsadc);
3117 clk_enable_nolock(&clk_hclk_hsadc);
3121 clk_enable_nolock(&aclk_lcdc0_ipp_parent);
3122 clk_enable_nolock(&aclk_lcdc1_rga_parent);
3124 clk_enable_nolock(&dclk_lcdc0_div);
3125 clk_enable_nolock(&dclk_lcdc1_div);
3127 clk_enable_nolock(&dclk_lcdc0);
3128 clk_enable_nolock(&clk_aclk_lcdc0);
3129 clk_enable_nolock(&clk_hclk_lcdc0);
3131 clk_enable_nolock(&dclk_lcdc1);
3132 clk_enable_nolock(&clk_aclk_lcdc1);
3133 clk_enable_nolock(&clk_hclk_lcdc1);
3135 clk_enable_nolock(&cif_out_pll);
3136 clk_enable_nolock(&cif0_out_div);
3137 clk_enable_nolock(&cif1_out_div);
3139 clk_enable_nolock(&cif0_out);
3140 clk_enable_nolock(&clk_hclk_cif0);
3142 clk_enable_nolock(&cif1_out);
3143 clk_enable_nolock(&clk_hclk_cif1);
3145 clk_enable_nolock(&clk_hclk_ipp);
3146 clk_enable_nolock(&clk_hclk_rga);
3147 clk_enable_nolock(&clk_hclk_hdmi);
3149 clk_enable_nolock(&pclkin_cif0);
3150 clk_enable_nolock(&inv_cif0);
3151 clk_enable_nolock(&cif0_in);
3152 clk_enable_nolock(&pclkin_cif1);
3153 clk_enable_nolock(&inv_cif1);
3154 clk_enable_nolock(&cif1_in);
3155 //CLK(NULL, "aclk_lcdc0", &aclk_lcdc0),
3156 //CLK(NULL, "aclk_lcdc1", &aclk_lcdc1),
3157 clk_enable_nolock(&aclk_vepu);
3158 clk_enable_nolock(&hclk_vepu);
3159 clk_enable_nolock(&aclk_vdpu);
3160 clk_enable_nolock(&hclk_vdpu);
3161 clk_enable_nolock(&clk_gpu);
3164 clk_enable_nolock(&clk_dma1);
3165 clk_enable_nolock(&clk_l2mem_con);
3166 clk_enable_nolock(&clk_intmem);
3168 clk_enable_nolock(&clk_aclk_strc_sys);
3170 /*************************hclk_cpu***********************/
3172 clk_enable_nolock(&clk_rom);
3174 clk_enable_nolock(&clk_hclk_cpubus);
3175 clk_enable_nolock(&clk_hclk_ahb2apb);
3176 clk_enable_nolock(&clk_hclk_vio_bus);
3178 /*************************pclk_cpu***********************/
3180 //clk_enable_nolock(&clk_pwm01);//pwm 0¡¢1
3184 clk_enable_nolock(&clk_i2c0);
3185 clk_enable_nolock(&clk_i2c1);
3187 clk_enable_nolock(&clk_gpio0);
3188 clk_enable_nolock(&clk_gpio1);
3189 clk_enable_nolock(&clk_gpio2);
3190 clk_enable_nolock(&clk_gpio6);
3191 clk_enable_nolock(&clk_efuse);
3193 clk_enable_nolock(&clk_tzpc);
3197 clk_enable_nolock(&clk_pclk_ddrupctl);
3198 clk_enable_nolock(&clk_pclk_ddrpubl);
3199 clk_enable_nolock(&clk_dbg);
3200 clk_enable_nolock(&clk_grf);
3201 clk_enable_nolock(&clk_pmu);
3203 /*************************aclk_periph***********************/
3205 clk_enable_nolock(&clk_dma2);
3207 clk_enable_nolock(&clk_aclk_peri_niu);
3208 clk_enable_nolock(&clk_aclk_cpu_peri);
3209 clk_enable_nolock(&clk_aclk_peri_axi_matrix);
3211 /*************************hclk_periph***********************/
3212 clk_enable_nolock(&clk_hclk_peri_axi_matrix);
3213 clk_enable_nolock(&clk_hclk_peri_ahb_arbi);
3214 clk_enable_nolock(&clk_hclk_emem_peri);
3215 clk_enable_nolock(&clk_hclk_mac);
3216 clk_enable_nolock(&clk_nandc);
3217 //CLK1(hclk_usb_peri),
3218 //CLK1(hclk_usbotg0),
3219 //CLK1(hclk_usbotg1),
3221 clk_enable_nolock(&clk_hclk_pidfilter);
3223 /*************************pclk_periph***********************/
3224 clk_enable_nolock(&clk_pclk_peri_axi_matrix);
3225 //clk_enable_nolock(&clk_pwm23);
3227 //clk_enable_nolock(&clk_wdt);
3231 clk_enable_nolock(&clk_i2c2);
3232 clk_enable_nolock(&clk_i2c3);
3233 clk_enable_nolock(&clk_i2c4);
3235 clk_enable_nolock(&clk_gpio3);
3236 clk_enable_nolock(&clk_gpio4);
3238 /*************************aclk_lcdc0***********************/
3239 //clk_enable_nolock(&clk_aclk_vio0);
3240 //clk_enable_nolock(&clk_aclk_cif0);
3241 //clk_enable_nolock(&clk_aclk_ipp);
3243 /*************************aclk_lcdc0***********************/
3244 //clk_enable_nolock(&clk_aclk_vio1);
3245 //clk_enable_nolock(&clk_aclk_cif1);
3246 //clk_enable_nolock(&clk_aclk_rga);
3247 /************************power domain**********************/
3249 static void periph_clk_set_init(void)
3251 unsigned long aclk_p, hclk_p, pclk_p;
3252 unsigned long ppll_rate=general_pll_clk.rate;
3256 switch (ppll_rate) {
3258 aclk_p = 148500*KHZ;
3263 aclk_p = aclk_p>>3;// 0
3268 aclk_p = ppll_rate>>1;
3274 aclk_p = ppll_rate>>1;
3284 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3285 clk_set_rate_nolock(&aclk_periph, aclk_p);
3286 clk_set_rate_nolock(&hclk_periph, hclk_p);
3287 clk_set_rate_nolock(&pclk_periph, pclk_p);
3291 void rk30_clock_common_i2s_init(void)
3293 struct clk *max_clk,*min_clk;
3294 unsigned long i2s_rate;
3296 if(rk30_clock_flags&CLK_FLG_MAX_I2S_49152KHZ)
3299 }else if(rk30_clock_flags&CLK_FLG_MAX_I2S_24576KHZ)
3303 else if(rk30_clock_flags&CLK_FLG_MAX_I2S_22579_2KHZ)
3307 else if(rk30_clock_flags&CLK_FLG_MAX_I2S_12288KHZ)
3316 if(((i2s_rate*20)<=general_pll_clk.rate)||!(general_pll_clk.rate%i2s_rate))
3318 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3320 else if(((i2s_rate*20)<=codec_pll_clk.rate)||!(codec_pll_clk.rate%i2s_rate))
3322 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3326 if(general_pll_clk.rate>codec_pll_clk.rate)
3327 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3329 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3338 static void __init rk30_clock_common_init(unsigned long gpll_rate,unsigned long cpll_rate)
3341 clk_set_rate_nolock(&clk_cpu, 816*MHZ);//816
3343 #ifdef CONFIG_RK29_VMAC
3344 /* because loader gpll_rate = 300M, but config(nr, nf, no) is not fit for VMAC,
3345 * board with VMAC need gpll 300, so it will do nothing when gpll init,
3346 * DO below to make sure gpll's config use (nr = 1, nf = 25, no = 2)
3348 clk_set_rate_nolock(&general_pll_clk, 297 * MHZ);
3350 clk_set_rate_nolock(&general_pll_clk, gpll_rate);
3351 lpj_gpll = CLK_LOOPS_RECALC(general_pll_clk.rate);
3354 clk_set_rate_nolock(&codec_pll_clk, cpll_rate);
3357 periph_clk_set_init();
3360 rk30_clock_common_i2s_init();
3363 clk_set_rate_nolock(&clk_spi0, clk_spi0.parent->rate);
3364 clk_set_rate_nolock(&clk_spi1, clk_spi1.parent->rate);
3367 if(rk30_clock_flags&CLK_FLG_UART_1_3M)
3368 clk_set_parent_nolock(&clk_uart_pll, &codec_pll_clk);
3370 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3372 if(!(gpll_rate%(50*MHZ)))
3373 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3374 else if(!(ddr_pll_clk.rate%(50*MHZ)))
3375 clk_set_parent_nolock(&clk_mac_pll_div, &ddr_pll_clk);
3377 CRU_PRINTK_ERR("mac can't get 50mhz\n");
3381 //clk_set_parent_nolock(&clk_hsadc_pll_div, &general_pll_clk);
3384 clk_set_parent_nolock(&dclk_lcdc1_div, &general_pll_clk);
3386 //lcdc0 lcd auto sel pll
3387 //clk_set_parent_nolock(&dclk_lcdc0_div, &general_pll_clk);
3390 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3393 //clk_set_parent_nolock(&aclk_lcdc0, &general_pll_clk);
3394 //clk_set_parent_nolock(&aclk_lcdc1, &general_pll_clk);
3395 clk_set_rate_nolock(&aclk_lcdc0_ipp_parent, 300*MHZ);
3396 clk_set_rate_nolock(&aclk_lcdc1_rga_parent, 300*MHZ);
3399 //clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
3400 //clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
3402 clk_set_rate_nolock(&aclk_vepu, 300*MHZ);
3403 clk_set_rate_nolock(&aclk_vdpu, 300*MHZ);
3405 //clk_set_parent_nolock(&clk_gpu, &general_pll_clk);
3407 clk_set_rate_nolock(&clk_uart0, 49500000);
3408 clk_set_rate_nolock(&clk_sdmmc, 24750000);
3409 clk_set_rate_nolock(&clk_sdio, 24750000);
3412 static struct clk def_ops_clk={
3413 .get_parent=clksel_get_parent,
3414 .set_parent=clksel_set_parent,
3417 #ifdef CONFIG_PROC_FS
3418 struct clk_dump_ops dump_ops;
3421 static void clk_dump_regs(void);
3423 void __init _rk30_clock_data_init(unsigned long gpll,unsigned long cpll,int flags)
3425 struct clk_lookup *lk;
3427 clk_register_dump_ops(&dump_ops);
3428 clk_register_default_ops_clk(&def_ops_clk);
3429 rk30_clock_flags=flags;
3430 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
3431 #ifdef RK30_CLK_OFFBOARD_TEST
3432 rk30_clkdev_add(lk);
3436 clk_register(lk->clk);
3438 clk_recalculate_root_clocks_nolock();
3440 loops_per_jiffy = CLK_LOOPS_RECALC(arm_pll_clk.rate);
3443 * Only enable those clocks we will need, let the drivers
3444 * enable other clocks as necessary
3446 rk30_init_enable_clocks();
3449 * Disable any unused clocks left on by the bootloader
3451 //clk_disable_unused();
3452 rk30_clock_common_init(gpll,cpll);
3453 preset_lpj = loops_per_jiffy;
3456 //regfile_writel(0xc0004000,0x10c);
3457 //cru_writel(0x07000000,CRU_MISC_CON);
3460 int rk_dvfs_init(void);
3462 void __init rk30_clock_data_init(unsigned long gpll,unsigned long cpll,u32 flags)
3464 _rk30_clock_data_init(gpll,cpll,flags);
3469 * You can override arm_clk rate with armclk= cmdline option.
3471 static int __init armclk_setup(char *str)
3473 get_option(&str, &armclk);
3479 //clk_set_rate_nolock(&arm_pll_clk, armclk);
3482 #ifndef RK30_CLK_OFFBOARD_TEST
3483 early_param("armclk", armclk_setup);
3488 #ifdef CONFIG_PROC_FS
3490 static void dump_clock(struct seq_file *s, struct clk *clk, int deep,const struct list_head *root_clocks)
3494 unsigned long rate = clk->rate;
3495 //CRU_PRINTK_DBG("dump_clock %s\n",clk->name);
3496 for (i = 0; i < deep; i++)
3499 seq_printf(s, "%-11s ", clk->name);
3500 #ifndef RK30_CLK_OFFBOARD_TEST
3501 if (clk->flags & IS_PD) {
3502 seq_printf(s, "%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3505 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3506 int idx = clk->gate_idx;
3508 v = cru_readl(CLK_GATE_CLKID_CONS(idx))&((0x1)<<(idx%16));
3509 seq_printf(s, "%s ", v ? "off" : "on ");
3515 u32 pll_id=clk->pll->id;
3516 pll_mode=cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3517 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3518 seq_printf(s, "slow ");
3519 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3520 seq_printf(s, "normal ");
3521 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3522 seq_printf(s, "deep ");
3524 if(cru_readl(PLL_CONS(pll_id,3)) & PLL_BYPASS)
3525 seq_printf(s, "bypass ");
3527 else if(clk == &clk_ddr) {
3528 rate = clk->recalc(clk);
3533 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3535 seq_printf(s, "%ld MHz", rate / MHZ);
3536 } else if (rate >= KHZ) {
3538 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3540 seq_printf(s, "%ld KHz", rate / KHZ);
3542 seq_printf(s, "%ld Hz", rate);
3545 seq_printf(s, " usecount = %d", clk->usecount);
3548 seq_printf(s, " parent = %s", clk->parent->name);
3550 seq_printf(s, "\n");
3552 list_for_each_entry(ck, root_clocks, node) {
3553 if (ck->parent == clk)
3554 dump_clock(s, ck, deep + 1,root_clocks);
3558 static void dump_regs(struct seq_file *s)
3561 seq_printf(s, "\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3562 seq_printf(s, "\nPLLRegisters:\n");
3563 for(i=0;i<END_PLL_ID;i++)
3565 seq_printf(s,"pll%d :cons:%x,%x,%x,%x\n",i,
3566 cru_readl(PLL_CONS(i,0)),
3567 cru_readl(PLL_CONS(i,1)),
3568 cru_readl(PLL_CONS(i,2)),
3569 cru_readl(PLL_CONS(i,3))
3572 seq_printf(s, "MODE :%x\n", cru_readl(CRU_MODE_CON));
3574 for(i=0;i<CRU_CLKSELS_CON_CNT;i++)
3576 seq_printf(s,"CLKSEL%d :%x\n",i,cru_readl(CRU_CLKSELS_CON(i)));
3578 for(i=0;i<CRU_CLKGATES_CON_CNT;i++)
3580 seq_printf(s,"CLKGATE%d :%x\n",i,cru_readl(CRU_CLKGATES_CON(i)));
3582 seq_printf(s,"GLB_SRST_FST:%x\n",cru_readl(CRU_GLB_SRST_FST));
3583 seq_printf(s,"GLB_SRST_SND:%x\n",cru_readl(CRU_GLB_SRST_SND));
3585 for(i=0;i<CRU_SOFTRSTS_CON_CNT;i++)
3587 seq_printf(s,"CLKGATE%d :%x\n",i,cru_readl(CRU_SOFTRSTS_CON(i)));
3589 seq_printf(s,"CRU MISC :%x\n",cru_readl(CRU_MISC_CON));
3590 seq_printf(s,"GLB_CNT_TH :%x\n",cru_readl(CRU_GLB_CNT_TH));
3594 void rk30_clk_dump_regs(void)
3597 printk("\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3598 printk("\nPLLRegisters:\n");
3599 for(i=0;i<END_PLL_ID;i++)
3601 printk("pll%d :cons:%x,%x,%x,%x\n",i,
3602 cru_readl(PLL_CONS(i,0)),
3603 cru_readl(PLL_CONS(i,1)),
3604 cru_readl(PLL_CONS(i,2)),
3605 cru_readl(PLL_CONS(i,3))
3608 printk("MODE :%x\n", cru_readl(CRU_MODE_CON));
3610 for(i=0;i<CRU_CLKSELS_CON_CNT;i++)
3612 printk("CLKSEL%d :%x\n",i,cru_readl(CRU_CLKSELS_CON(i)));
3614 for(i=0;i<CRU_CLKGATES_CON_CNT;i++)
3616 printk("CLKGATE%d :%x\n",i,cru_readl(CRU_CLKGATES_CON(i)));
3618 printk("GLB_SRST_FST:%x\n",cru_readl(CRU_GLB_SRST_FST));
3619 printk("GLB_SRST_SND:%x\n",cru_readl(CRU_GLB_SRST_SND));
3621 for(i=0;i<CRU_SOFTRSTS_CON_CNT;i++)
3623 printk("SOFTRST%d :%x\n",i,cru_readl(CRU_SOFTRSTS_CON(i)));
3625 printk("CRU MISC :%x\n",cru_readl(CRU_MISC_CON));
3626 printk("GLB_CNT_TH :%x\n",cru_readl(CRU_GLB_CNT_TH));
3631 #ifdef CONFIG_PROC_FS
3632 static void dump_clock(struct seq_file *s, struct clk *clk, int deep,const struct list_head *root_clocks);
3633 struct clk_dump_ops dump_ops={
3634 .dump_clk=dump_clock,
3635 .dump_regs=dump_regs,
3640 #endif /* CONFIG_PROC_FS */
3645 #ifdef RK30_CLK_OFFBOARD_TEST
3646 struct clk *test_get_parent(struct clk *clk)
3653 struct clk *i2s_clk=&clk_i2s0;
3655 clk_enable_nolock(i2s_clk);
3657 clk_set_rate_nolock(i2s_clk, 12288000);
3658 printk("int %s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3659 clk_set_rate_nolock(i2s_clk, 297*MHZ/2);
3660 printk("int%s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3661 clk_set_rate_nolock(i2s_clk, 12*MHZ);
3662 printk("int%s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3666 void uart_test(void)
3668 struct clk *uart_clk=&clk_uart0;
3670 clk_enable_nolock(uart_clk);
3672 clk_set_rate_nolock(uart_clk, 12288000);
3673 printk("int %s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3674 clk_set_rate_nolock(uart_clk, 297*MHZ/2);
3675 printk("int%s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3676 clk_set_rate_nolock(uart_clk, 12*MHZ);
3677 printk("int%s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3680 void hsadc_test(void)
3682 struct clk *hsadc_clk=&clk_hsadc;
3684 printk("******************hsadc_test**********************\n");
3685 clk_enable_nolock(hsadc_clk);
3687 clk_set_rate_nolock(hsadc_clk, 12288000);
3688 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3691 clk_set_rate_nolock(hsadc_clk, 297*MHZ/2);
3692 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3694 clk_set_rate_nolock(hsadc_clk, 300*MHZ/2);
3696 clk_set_rate_nolock(hsadc_clk, 296*MHZ/2);
3698 printk("******************hsadc out clock**********************\n");
3700 clk_set_parent_nolock(hsadc_clk, &clk_hsadc_ext);
3701 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3702 clk_set_rate_nolock(hsadc_clk, 297*MHZ/2);
3703 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3709 static void __init rk30_clock_test_init(unsigned long ppll_rate)
3712 printk("*********arm_pll_clk***********\n");
3713 clk_set_rate_nolock(&arm_pll_clk, 816*MHZ);
3715 printk("*********set clk_cpu parent***********\n");
3716 clk_set_parent_nolock(&clk_cpu, &arm_pll_clk);
3717 clk_set_rate_nolock(&clk_cpu, 504*MHZ);
3720 printk("*********general_pll_clk***********\n");
3721 clk_set_rate_nolock(&general_pll_clk, ppll_rate);
3724 printk("*********codec_pll_clk***********\n");
3725 clk_set_rate_nolock(&codec_pll_clk, 600*MHZ);
3728 printk("*********periph_clk_set_init***********\n");
3729 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3730 periph_clk_set_init();
3733 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3735 printk("*********clk i2s***********\n");
3736 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3737 printk("common %s parent is %s\n",clk_i2s_pll.name,test_get_parent(&clk_i2s_pll)->name);
3741 clk_enable_nolock(&clk_spi0);
3742 clk_set_rate_nolock(&clk_spi0, 30*MHZ);
3743 printk("common %s parent is %s\n",clk_spi0.name,test_get_parent(&clk_spi0)->name);
3745 clk_enable_nolock(&clk_saradc);
3746 clk_set_rate_nolock(&clk_saradc, 6*MHZ);
3747 printk("common %s parent is %s\n",clk_saradc.name,test_get_parent(&clk_saradc)->name);
3749 clk_enable_nolock(&clk_sdio);
3750 clk_set_rate_nolock(&clk_sdio, 50*MHZ);
3751 printk("common %s parent is %s\n",clk_sdio.name,test_get_parent(&clk_sdio)->name);
3753 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3756 printk("*********mac***********\n");
3758 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3759 printk("common %s parent is %s\n",clk_mac_pll_div.name,test_get_parent(&clk_mac_pll_div)->name);
3761 //clk_set_parent_nolock(&clk_mac_ref, &clk_mac_pll_div);
3762 clk_set_rate_nolock(&clk_mac_ref, 50*MHZ);
3763 printk("common %s parent is %s\n",clk_mac_ref.name,test_get_parent(&clk_mac_ref)->name);
3765 printk("*********mac mii set***********\n");
3766 clk_set_parent_nolock(&clk_mac_ref, &rmii_clkin);
3767 clk_set_rate_nolock(&clk_mac_ref, 20*MHZ);
3768 printk("common %s parent is %s\n",clk_mac_ref.name,test_get_parent(&clk_mac_ref)->name);
3770 printk("*********hsadc 1***********\n");
3774 clk_enable_nolock(&dclk_lcdc0);
3776 clk_set_rate_nolock(&dclk_lcdc0, 60*MHZ);
3777 clk_set_rate_nolock(&dclk_lcdc0, 27*MHZ);
3780 clk_enable_nolock(&cif0_out);
3782 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3783 printk("common %s parent is %s\n",cif_out_pll.name,test_get_parent(&cif_out_pll)->name);
3785 clk_set_rate_nolock(&cif0_out, 60*MHZ);
3786 printk("common %s parent is %s\n",cif0_out.name,test_get_parent(&cif0_out)->name);
3788 clk_set_rate_nolock(&cif0_out, 24*MHZ);
3789 printk("common %s parent is %s\n",cif0_out.name,test_get_parent(&cif0_out)->name);
3791 clk_enable_nolock(&cif0_in);
3792 clk_set_rate_nolock(&cif0_in, 24*MHZ);
3794 clk_enable_nolock(&aclk_lcdc0);
3795 clk_set_rate_nolock(&aclk_lcdc0, 150*MHZ);
3796 printk("common %s parent is %s\n",aclk_lcdc0.name,test_get_parent(&aclk_lcdc0)->name);
3798 clk_enable_nolock(&aclk_vepu);
3799 clk_set_rate_nolock(&aclk_vepu, 300*MHZ);
3800 printk("common %s parent is %s\n",aclk_vepu.name,test_get_parent(&aclk_vepu)->name);
3802 clk_set_rate_nolock(&hclk_vepu, 300*MHZ);
3803 printk("common %s parent is %s\n",hclk_vepu.name,test_get_parent(&hclk_vepu)->name);
3805 printk("test end\n");
3808 clk_set_rate_nolock(&arm_pll_clk, armclk);
3809 clk_set_rate_nolock(&clk_cpu, armclk);//pll:core =1:1
3812 //clk_set_rate_nolock(&codec_pll_clk, ppll_rate*2);
3814 //clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3815 //clk_set_rate_nolock(&clk_gpu, 300 * MHZ);
3823 static LIST_HEAD(rk30_clocks);
3824 static DEFINE_MUTEX(rk30_clocks_mutex);
3826 static inline int __rk30clk_get(struct clk *clk)
3830 void rk30_clkdev_add(struct clk_lookup *cl)
3832 mutex_lock(&rk30_clocks_mutex);
3833 list_add_tail(&cl->node, &rk30_clocks);
3834 mutex_unlock(&rk30_clocks_mutex);
3836 static struct clk_lookup *rk30_clk_find(const char *dev_id, const char *con_id)
3838 struct clk_lookup *p, *cl = NULL;
3839 int match, best = 0;
3841 list_for_each_entry(p, &rk30_clocks, node) {
3844 if (!dev_id || strcmp(p->dev_id, dev_id))
3849 if (!con_id || strcmp(p->con_id, con_id))
3865 struct clk *rk30_clk_get_sys(const char *dev_id, const char *con_id)
3867 struct clk_lookup *cl;
3869 mutex_lock(&rk30_clocks_mutex);
3870 cl = rk30_clk_find(dev_id, con_id);
3871 if (cl && !__rk30clk_get(cl->clk))
3873 mutex_unlock(&rk30_clocks_mutex);
3875 return cl ? cl->clk : ERR_PTR(-ENOENT);
3877 //EXPORT_SYMBOL(rk30_clk_get_sys);
3879 struct clk *rk30_clk_get(struct device *dev, const char *con_id)
3881 const char *dev_id = dev ? dev_name(dev) : NULL;
3882 return rk30_clk_get_sys(dev_id, con_id);
3884 //EXPORT_SYMBOL(rk30_clk_get);
3887 int rk30_clk_set_rate(struct clk *clk, unsigned long rate);
3889 void rk30_clocks_test(void)
3891 struct clk *test_gpll;
3892 test_gpll=rk30_clk_get(NULL,"general_pll");
3895 rk30_clk_set_rate(test_gpll,297*2*MHZ);
3896 printk("gpll rate=%lu\n",test_gpll->rate);
3901 void __init rk30_clock_init_test(void){
3903 rk30_clock_init(periph_pll_297mhz,codec_pll_360mhz,max_i2s_12288khz);