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);
297 static u32 clk_get_freediv(unsigned long rate_out, unsigned long rate ,u32 div_max)
300 unsigned long new_rate;
301 for (div = 0; div <div_max; div++) {
302 new_rate = rate / (div + 1);
303 if (new_rate <= rate_out) {
307 return div_max?div_max:1;
309 struct clk *get_freediv_parents_div(struct clk *clk,unsigned long rate,u32 *div_out)
312 unsigned long new_rate[2]={0,0};
319 div[i]=clk_get_freediv(rate,clk->parents[i]->rate,clk->div_max);
320 new_rate[i] = clk->parents[i]->rate/div[i];
321 if(new_rate[i]==rate)
324 return clk->parents[i];
327 if(new_rate[0]<new_rate[1])
332 return clk->parents[i];
335 static int clkset_rate_freediv_autosel_parents(struct clk *clk, unsigned long rate)
342 p_clk=get_freediv_parents_div(clk,rate,&div);
347 CRU_PRINTK_DBG("%s %lu,form %s\n",clk->name,rate,p_clk->name);
348 if (clk->parent != p_clk)
350 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),clk->div_shift,clk->div_mask)+1;
354 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
356 ret=clk_set_parent_nolock(clk,p_clk);
359 CRU_PRINTK_ERR("%s can't set %lu,reparent err\n",clk->name,rate);
364 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
368 //rate==div rate //hdmi
369 static int clk_freediv_autosel_parents_set_fixed_rate(struct clk *clk, unsigned long rate)
374 p_clk=get_freediv_parents_div(clk,rate,&div);
379 if((p_clk->rate/div)!=rate||(p_clk->rate%div))
382 if (clk->parent != p_clk)
384 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),
385 clk->div_shift,clk->div_mask)+1;
388 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
390 ret=clk_set_parent_nolock(clk,p_clk);
393 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
398 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
402 /***************************round********************************/
404 static long clksel_freediv_round_rate(struct clk *clk, unsigned long rate)
406 return clk->parent->rate/clk_get_freediv(rate,clk->parent->rate,clk->div_max);
409 static long clk_freediv_round_autosel_parents_rate(struct clk *clk, unsigned long rate)
413 if(clk->rate == rate)
415 p_clk=get_freediv_parents_div(clk,rate,&div);
418 return p_clk->rate/div;
421 /**************************************others seting************************************/
423 static struct clk* clksel_get_parent(struct clk *clk)
425 return clk->parents[(cru_readl(clk->clksel_con) >> clk->src_shift) & clk->src_mask];
427 static int clksel_set_parent(struct clk *clk, struct clk *parent)
430 if (unlikely(!clk->parents))
432 for (i = 0; (i <clk->parents_num); i++) {
433 if (clk->parents[i]!= parent)
435 set_cru_bits_w_msk(i,clk->src_mask,clk->src_shift,clk->clksel_con);
441 static int gate_mode(struct clk *clk, int on)
443 int idx = clk->gate_idx;
444 if (idx >= CLK_GATE_MAX)
448 cru_writel(CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx), CLK_GATE_CLKID_CONS(idx));
449 //CRU_PRINTK_DBG("un gate id=%d %s(%x),con %x\n",idx,clk->name,
450 // CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx),CLK_GATE_CLKID_CONS(idx));
454 cru_writel(CLK_GATE_W_MSK(idx)|CLK_GATE(idx), CLK_GATE_CLKID_CONS(idx));
455 // CRU_PRINTK_DBG("gate id=%d %s(%x),con%x\n",idx,clk->name,
456 // CLK_GATE_W_MSK(idx)|CLK_GATE(idx),CLK_GATE_CLKID_CONS(idx));
460 /*****************************frac set******************************************/
462 static unsigned long clksel_recalc_frac(struct clk *clk)
466 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
467 if (r == 0) // FPGA ?
468 return clk->parent->rate;
470 denominator = r & 0xFFFF;
471 rate64 = (u64)clk->parent->rate * numerator;
472 do_div(rate64, denominator);
474 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
478 static u32 clk_gcd(u32 numerator, u32 denominator)
482 if (!numerator || !denominator)
484 if (numerator > denominator) {
500 static int frac_div_get_seting(unsigned long rate_out,unsigned long rate,
501 u32 *numerator,u32 *denominator)
504 gcd_vl = clk_gcd(rate, rate_out);
505 CRU_PRINTK_DBG("frac_get_seting rate=%lu,parent=%lu,gcd=%d\n",rate_out,rate, gcd_vl);
508 CRU_PRINTK_ERR("gcd=0, i2s frac div is not be supported\n");
512 *numerator = rate_out / gcd_vl;
513 *denominator = rate/ gcd_vl;
515 CRU_PRINTK_DBG("frac_get_seting numerator=%d,denominator=%d,times=%d\n",
516 *numerator, *denominator, *denominator / *numerator);
518 if (*numerator > 0xffff || *denominator > 0xffff||
519 (*denominator/(*numerator))<20) {
520 CRU_PRINTK_ERR("can't get a available nume and deno\n");
527 /* *********************pll **************************/
529 #define rk30_clock_udelay(a) udelay(a);
531 /*********************pll lock status**********************************/
532 //#define GRF_SOC_CON0 0x15c
533 static void pll_wait_lock(int pll_idx)
535 u32 pll_state[4]={1,0,2,3};
536 u32 bit = 0x10u << pll_state[pll_idx];
537 int delay = 24000000;
539 if (regfile_readl(GRF_SOC_STATUS0) & bit)
544 CRU_PRINTK_ERR("wait pll bit 0x%x time out!\n", bit);
551 /***************************pll function**********************************/
552 static unsigned long pll_clk_recalc(u32 pll_id,unsigned long parent_rate)
556 if (PLLS_IN_NORM(pll_id)) {
557 u32 pll_con0 = cru_readl(PLL_CONS(pll_id,0));
558 u32 pll_con1 = cru_readl(PLL_CONS(pll_id,1));
561 u64 rate64 = (u64)parent_rate*PLL_NF(pll_con1);
564 CRU_PRINTK_DBG("selcon con0(%x) %x,con1(%x)%x, rate64 %llu\n",PLL_CONS(pll_id,0),pll_con0
565 ,PLL_CONS(pll_id,1),pll_con1, rate64);
569 //CRU_PRINTK_DBG("pll id=%d con0=%x,con1=%x,parent=%lu\n",pll_id,pll_con0,pll_con1,parent_rate);
570 //CRU_PRINTK_DBG("first pll id=%d rate is %lu (NF %d NR %d NO %d)\n",
571 //pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0), 1 << PLL_NO(pll_con0));
573 do_div(rate64, PLL_NR(pll_con0));
574 do_div(rate64, PLL_NO(pll_con0));
578 CRU_PRINTK_DBG("pll_clk_recalc id=%d rate=%lu (NF %d NR %d NO %d) rate64=%llu\n",
579 pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0),PLL_NO(pll_con0), rate64);
583 CRU_PRINTK_DBG("pll_clk_recalc id=%d rate=%lu by pass mode\n",pll_id,rate);
587 static unsigned long plls_clk_recalc(struct clk *clk)
589 return pll_clk_recalc(clk->pll->id,clk->parent->rate);
592 static int pll_clk_set_rate(struct pll_clk_set *clk_set,u8 pll_id)
595 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
597 cru_writel(PLL_REST_W_MSK|PLL_REST, PLL_CONS(pll_id,3));
598 cru_writel(clk_set->pllcon0, PLL_CONS(pll_id,0));
599 cru_writel(clk_set->pllcon1, PLL_CONS(pll_id,1));
600 cru_writel(clk_set->pllcon2, PLL_CONS(pll_id,2));
601 rk30_clock_udelay(5);
604 cru_writel(PLL_REST_W_MSK|PLL_REST_RESM, PLL_CONS(pll_id,3));
607 rk30_clock_udelay(clk_set->rst_dly);
608 pll_wait_lock(pll_id);
611 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
614 CRU_PRINTK_ERR("pll reg id=%d,con0=%x,con1=%x,mode=%x\n",pll_id,
615 cru_readl(PLL_CONS(pll_id,0)),(PLL_CONS(pll_id,1)),cru_readl(CRU_MODE_CON));
621 static int gpll_clk_set_rate(struct clk *c, unsigned long rate)
623 struct _pll_data *pll_data=c->pll;
624 struct pll_clk_set *clk_set=(struct pll_clk_set*)pll_data->table;
628 if (clk_set->rate == rate) {
633 if(clk_set->rate== rate)
635 pll_clk_set_rate(clk_set,pll_data->id);
636 lpj_gpll = CLK_LOOPS_RECALC(rate);
640 CRU_PRINTK_ERR("gpll is no corresponding rate=%lu\n", rate);
646 #define PLL_FREF_MIN (183*KHZ)
647 #define PLL_FREF_MAX (1500*MHZ)
649 #define PLL_FVCO_MIN (300*MHZ)
650 #define PLL_FVCO_MAX (1500*MHZ)
652 #define PLL_FOUT_MIN (18750*KHZ)
653 #define PLL_FOUT_MAX (1500*MHZ)
655 #define PLL_NF_MAX (4096)
656 #define PLL_NR_MAX (64)
657 #define PLL_NO_MAX (16)
659 static int pll_clk_get_set(unsigned long fin_hz,unsigned long fout_hz,u32 *clk_nr,u32 *clk_nf,u32 *clk_no)
665 unsigned long fref,fvco,fout;
668 CRU_PRINTK_DBG("pll_clk_get_set fin=%lu,fout=%lu\n",fin_hz,fout_hz);
669 if(!fin_hz||!fout_hz||fout_hz==fin_hz)
671 gcd_val=clk_gcd(fin_hz,fout_hz);
672 YFfenzi=fout_hz/gcd_val;
673 YFfenmu=fin_hz/gcd_val;
679 if(nf>PLL_NF_MAX||nonr>(PLL_NO_MAX*PLL_NR_MAX))
681 for(no=1;no<=PLL_NO_MAX;no++)
683 if(!(no==1||!(no%2)))
690 if(nr>PLL_NR_MAX)//PLL_NR_MAX
694 if(fref<PLL_FREF_MIN||fref>PLL_FREF_MAX)
698 if(fvco<PLL_FVCO_MIN||fvco>PLL_FVCO_MAX)
701 if(fout<PLL_FOUT_MIN||fout>PLL_FOUT_MAX)
714 static int pll_clk_mode(struct clk *clk, int on)
716 u8 pll_id=clk->pll->id;
717 u32 nr=PLL_NR(cru_readl(PLL_CONS(pll_id,0)));
718 u32 dly= (nr*500)/24+1;
719 CRU_PRINTK_DBG("pll_mode %s(%d)",clk->name,on);
721 cru_writel(PLL_PWR_ON|PLL_PWR_DN_W_MSK,PLL_CONS(pll_id,3));
722 rk30_clock_udelay(dly);
723 pll_wait_lock(pll_id);
724 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
726 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
727 cru_writel(PLL_PWR_DN|PLL_PWR_DN_W_MSK, PLL_CONS(pll_id,3));
732 static int cpll_clk_set_rate(struct clk *c, unsigned long rate)
734 struct _pll_data *pll_data=c->pll;
735 struct pll_clk_set *clk_set=(struct pll_clk_set*)pll_data->table;
736 struct pll_clk_set temp_clk_set;
737 u32 clk_nr,clk_nf,clk_no;
742 if (clk_set->rate == rate) {
747 if(clk_set->rate==rate)
749 CRU_PRINTK_DBG("cpll get a rate\n");
750 pll_clk_set_rate(clk_set,pll_data->id);
755 CRU_PRINTK_DBG("cpll get auto calc a rate\n");
756 if(pll_clk_get_set(c->parent->rate,rate,&clk_nr,&clk_nf,&clk_no)==0)
758 pr_err("cpll auto set rate error\n");
761 CRU_PRINTK_DBG("cpll auto ger rate set nr=%d,nf=%d,no=%d\n",clk_nr,clk_nf,clk_no);
762 temp_clk_set.pllcon0=PLL_CLKR_SET(clk_nr)|PLL_CLKOD_SET(clk_no);
763 temp_clk_set.pllcon1=PLL_CLKF_SET(clk_nf);
764 temp_clk_set.pllcon2=PLL_CLK_BWADJ_SET(clk_nf/2-1);
765 temp_clk_set.rst_dly=(clk_nr*500)/24+1;
766 pll_clk_set_rate(&temp_clk_set,pll_data->id);
773 /* ******************fixed input clk ***********************************************/
774 static struct clk xin24m = {
779 static struct clk xin27m = {
786 static struct clk clk_12m = {
793 /************************************pll func***************************/
794 static const struct apll_clk_set* arm_pll_clk_get_best_pll_set(unsigned long rate,
795 struct apll_clk_set *tables)
797 const struct apll_clk_set *ps, *pt;
799 /* find the arm_pll we want. */
802 if (pt->rate == rate) {
806 // we are sorted, and ps->rate > pt->rate.
807 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
813 //CRU_PRINTK_DBG("arm pll best rate=%lu\n",ps->rate);
816 static long arm_pll_clk_round_rate(struct clk *clk, unsigned long rate)
818 return arm_pll_clk_get_best_pll_set(rate,clk->pll->table)->rate;
821 struct arm_clks_div_set {
827 #define _arm_clks_div_set(_mhz,_periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
830 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
831 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
832 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
833 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
834 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
836 struct arm_clks_div_set arm_clk_div_tlb[]={
837 _arm_clks_div_set(50 , 2, 11, 11, 11, 11),//25,50,50,50,50
838 _arm_clks_div_set(100 , 4, 11, 21, 21, 11),//25,100,50,50,50
839 _arm_clks_div_set(150 , 4, 11, 21, 21, 11),//37,150,75,75,75
840 _arm_clks_div_set(200 , 8, 21, 21, 21, 11),//25,100,50,50,50
841 _arm_clks_div_set(300 , 8, 21, 21, 21, 11),//37,150,75,75,75
842 _arm_clks_div_set(400 , 8, 21, 21, 41, 21),//50,200,100,50,50
843 _arm_clks_div_set(0 , 2, 11, 11, 11, 11),//25,50,50,50,50
845 struct arm_clks_div_set * arm_clks_get_div(u32 rate)
848 for(i=0;arm_clk_div_tlb[i].rate!=0;i++)
850 if(arm_clk_div_tlb[i].rate>=rate)
851 return &arm_clk_div_tlb[i];
858 u32 force_cpu_hpclk_11(u32 clksel1)
860 u8 p_bits=(clksel1&ACLK_PCLK_MSK)>>ACLK_PCLK_OFF;
863 return ((clksel1&(~(ACLK_HCLK_MSK|AHB2APB_MSK)))|AHB2APB_11|(p_bits<<ACLK_HCLK_OFF));
871 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
874 const struct apll_clk_set *ps;
875 u32 pll_id=clk->pll->id;
877 u32 old_aclk_div=0,new_aclk_div,gpll_arm_aclk_div;
878 struct arm_clks_div_set *temp_clk_div;
879 unsigned long arm_gpll_rate, arm_gpll_lpj;
882 ps = arm_pll_clk_get_best_pll_set(rate,(struct apll_clk_set *)clk->pll->table);
884 old_aclk_div=GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
885 new_aclk_div=GET_CORE_ACLK_VAL(ps->clksel1&CORE_ACLK_MSK);
887 CRU_PRINTK_LOG("apll will set rate(%lu) tlb con(%x,%x,%x),sel(%x,%x)\n",
888 ps->rate,ps->pllcon0,ps->pllcon1,ps->pllcon2,ps->clksel0,ps->clksel1);
890 //rk30_l2_cache_latency(ps->rate/MHZ);
892 if(general_pll_clk.rate>clk->rate)
894 temp_div=clk_get_freediv(clk->rate,general_pll_clk.rate,10);
901 //cru_writel(CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
903 arm_gpll_rate=general_pll_clk.rate/temp_div;
904 arm_gpll_lpj = lpj_gpll / temp_div;
905 temp_clk_div=arm_clks_get_div(arm_gpll_rate/MHZ);
907 temp_clk_div=&arm_clk_div_tlb[4];
908 if(rk30_clock_flags&CLK_CPU_HPCLK_11)
910 temp_clk_div->clksel1=force_cpu_hpclk_11(temp_clk_div->clksel1);
913 gpll_arm_aclk_div=GET_CORE_ACLK_VAL(temp_clk_div->clksel1&CORE_ACLK_MSK);
915 CRU_PRINTK_LOG("gpll_arm_rate=%lu,sel rate%u,sel0%x,sel1%x\n",arm_gpll_rate,temp_clk_div->rate,
916 temp_clk_div->clksel0,temp_clk_div->clksel1);
918 local_irq_save(flags);
920 if(gpll_arm_aclk_div>=old_aclk_div)
922 if((old_aclk_div==3||gpll_arm_aclk_div==3)&&(gpll_arm_aclk_div!=old_aclk_div))
924 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
925 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
926 cru_writel((temp_clk_div->clksel0|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK),
928 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
932 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
933 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
937 // open gpu gpll path
938 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));
939 cru_writel(CORE_SEL_GPLL|CORE_SEL_PLL_W_MSK, CRU_CLKSELS_CON(0));
940 loops_per_jiffy = arm_gpll_lpj;
943 if(gpll_arm_aclk_div<old_aclk_div)
945 if((old_aclk_div==3||gpll_arm_aclk_div==3)&&(gpll_arm_aclk_div!=old_aclk_div))
947 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
948 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
949 cru_writel((temp_clk_div->clksel0|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK),
951 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
955 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
956 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
961 /*if core src don't select gpll ,apll neet to enter slow mode */
962 //cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
965 cru_writel(PLL_REST_W_MSK|PLL_REST, PLL_CONS(pll_id,3));
966 cru_writel(ps->pllcon0, PLL_CONS(pll_id,0));
967 cru_writel(ps->pllcon1, PLL_CONS(pll_id,1));
968 cru_writel(ps->pllcon2, PLL_CONS(pll_id,2));
970 rk30_clock_udelay(5);
973 cru_writel(PLL_REST_W_MSK|PLL_REST_RESM, PLL_CONS(pll_id,3));
976 ///rk30_clock_udelay(ps->rst_dly);//lcdc flash
978 pll_wait_lock(pll_id);
980 if(rk30_clock_flags&CLK_CPU_HPCLK_11)
982 ps_clksel1=force_cpu_hpclk_11(ps->clksel1);
986 ps_clksel1=ps->clksel1;
989 //cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
991 if(new_aclk_div>=gpll_arm_aclk_div)
993 if((gpll_arm_aclk_div==3||new_aclk_div==3)&&(new_aclk_div!=gpll_arm_aclk_div))
995 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
996 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
997 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
998 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
1002 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1003 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1008 cru_writel(CORE_SEL_PLL_W_MSK|CORE_SEL_APLL, CRU_CLKSELS_CON(0));
1009 loops_per_jiffy = ps->lpj;
1012 if(new_aclk_div<gpll_arm_aclk_div)
1014 if((gpll_arm_aclk_div==3||new_aclk_div==3)&&(new_aclk_div!=gpll_arm_aclk_div))
1016 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
1017 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1018 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1019 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
1023 cru_writel((ps_clksel1), CRU_CLKSELS_CON(1));
1024 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
1027 //CRU_PRINTK_DBG("apll set loops_per_jiffy =%lu,rate(%lu)\n",loops_per_jiffy,ps->rate);
1029 local_irq_restore(flags);
1032 cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH)|CLK_GATE(CLK_GATE_CPU_GPLL_PATH)
1033 , CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
1035 CRU_PRINTK_LOG("apll set over con(%x,%x,%x,%x),sel(%x,%x)\n",cru_readl(PLL_CONS(pll_id,0)),
1036 cru_readl(PLL_CONS(pll_id,1)),cru_readl(PLL_CONS(pll_id,2)),
1037 cru_readl(PLL_CONS(pll_id,3)),cru_readl(CRU_CLKSELS_CON(0)),
1038 cru_readl(CRU_CLKSELS_CON(1)));
1043 /************************************pll clocks***************************/
1045 static const struct apll_clk_set apll_clks[] = {
1046 //rate, nr ,nf ,no,core_div,peri,axi,hclk,pclk,_ahb2apb
1047 //_APLL_SET_CLKS(1800, 1, 75, 1, 8, 41, 41, 81,21),
1048 //_APLL_SET_CLKS(1752, 1, 73, 1, 8, 41, 41, 81,21),
1049 //_APLL_SET_CLKS(1704, 1, 71, 1, 8, 41, 41, 81,21),
1050 //_APLL_SET_CLKS(1656, 1, 69, 1, 8, 41, 41, 81,21),
1051 _APLL_SET_CLKS(1608, 1, 67, 1, 8, 41, 21, 41, 21),
1052 _APLL_SET_CLKS(1560, 1, 65, 1, 8, 41, 21, 41, 21),
1053 _APLL_SET_CLKS(1512, 1, 63, 1, 8, 41, 21, 41, 21),
1054 _APLL_SET_CLKS(1464, 1, 61, 1, 8, 41, 21, 41, 21),
1055 _APLL_SET_CLKS(1416, 1, 59, 1, 8, 41, 21, 41, 21),
1056 _APLL_SET_CLKS(1368, 1, 57, 1, 8, 41, 21, 41, 21),
1057 _APLL_SET_CLKS(1320, 1, 55, 1, 8, 41, 21, 41, 21),
1058 _APLL_SET_CLKS(1296, 1, 54, 1, 8, 41, 21, 41, 21),
1059 _APLL_SET_CLKS(1272, 1, 53, 1, 8, 41, 21, 41, 21),
1060 _APLL_SET_CLKS(1200, 1, 50, 1, 8, 41, 21, 41, 21),
1061 _APLL_SET_CLKS(1176, 1, 49, 1, 8, 41, 21, 41, 21),
1062 _APLL_SET_CLKS(1128, 1, 47, 1, 8, 41, 21, 41, 21),
1063 _APLL_SET_CLKS(1104, 1, 46, 1, 8, 41, 21, 41, 21),
1064 _APLL_SET_CLKS(1008, 1, 42, 1, 8, 31, 21, 41, 21),
1065 _APLL_SET_CLKS(888, 1, 37, 1, 8, 31, 21, 41, 21),
1066 _APLL_SET_CLKS(816 , 1, 34, 1, 8, 31, 21, 41, 21),
1067 _APLL_SET_CLKS(792 , 1, 33, 1, 8, 31, 21, 41, 21),
1068 _APLL_SET_CLKS(696 , 1, 29, 1, 8, 31, 21, 41, 21),
1069 _APLL_SET_CLKS(600 , 1, 25, 1, 4, 31, 21, 41, 21),
1070 _APLL_SET_CLKS(504 , 1, 21, 1, 4, 21, 21, 41, 21),
1071 _APLL_SET_CLKS(408 , 1, 17, 1, 4, 21, 21, 41, 21),
1072 _APLL_SET_CLKS(312 , 1, 13, 1, 2, 21, 21, 21, 11),
1073 _APLL_SET_CLKS(252 , 1, 21, 2, 2, 21, 21, 21, 11),
1074 _APLL_SET_CLKS(216 , 1, 18, 2, 2, 21, 21, 21, 11),
1075 _APLL_SET_CLKS(126 , 1, 21, 4, 2, 21, 11, 11, 11),
1076 _APLL_SET_CLKS(48 , 1, 16, 8, 2, 11, 11, 11, 11),
1077 _APLL_SET_CLKS(0 , 1, 21, 4, 2, 21, 21, 41, 21),
1080 static struct _pll_data apll_data=SET_PLL_DATA(APLL_ID,(void *)apll_clks);
1081 static struct clk arm_pll_clk ={
1084 .mode = pll_clk_mode,
1085 .recalc = plls_clk_recalc,
1086 .set_rate = arm_pll_clk_set_rate,
1087 .round_rate = arm_pll_clk_round_rate,
1091 static int ddr_pll_clk_set_rate(struct clk *clk, unsigned long rate)
1093 /* do nothing here */
1096 static struct _pll_data dpll_data=SET_PLL_DATA(DPLL_ID,NULL);
1097 static struct clk ddr_pll_clk = {
1100 .recalc = plls_clk_recalc,
1101 .set_rate = ddr_pll_clk_set_rate,
1105 static const struct pll_clk_set cpll_clks[] = {
1106 _PLL_SET_CLKS(360000, 1, 15, 1),
1107 _PLL_SET_CLKS(408000, 1, 17, 1),
1108 _PLL_SET_CLKS(456000, 1, 19, 1),
1109 _PLL_SET_CLKS(504000, 1, 21, 1),
1110 _PLL_SET_CLKS(552000, 1, 23, 1),
1111 _PLL_SET_CLKS(600000, 1, 25, 1),
1112 _PLL_SET_CLKS(742500, 8, 495, 2),
1113 _PLL_SET_CLKS(768000, 1, 32, 1),
1114 _PLL_SET_CLKS(798000, 4, 133, 1),
1115 _PLL_SET_CLKS(1188000,2, 99, 1),
1116 _PLL_SET_CLKS( 0, 4, 133, 1),
1118 static struct _pll_data cpll_data=SET_PLL_DATA(CPLL_ID,(void *)cpll_clks);
1119 static struct clk codec_pll_clk = {
1120 .name = "codec_pll",
1122 .mode = pll_clk_mode,
1123 .recalc = plls_clk_recalc,
1124 .set_rate = cpll_clk_set_rate,
1128 static const struct pll_clk_set gpll_clks[] = {
1129 _PLL_SET_CLKS(148500, 4, 99, 4),
1130 _PLL_SET_CLKS(297000, 2, 99, 4),
1131 _PLL_SET_CLKS(300000, 1, 25, 2),
1132 _PLL_SET_CLKS(1188000, 2, 99, 1),
1133 _PLL_SET_CLKS(0, 0, 0, 0),
1135 static struct _pll_data gpll_data=SET_PLL_DATA(GPLL_ID,(void *)gpll_clks);
1136 static struct clk general_pll_clk = {
1137 .name = "general_pll",
1139 .recalc = plls_clk_recalc,
1140 .set_rate = gpll_clk_set_rate,
1143 /********************************clocks***********************************/
1144 static int ddr_clk_set_rate(struct clk *c, unsigned long rate)
1149 static long ddr_clk_round_rate(struct clk *clk, unsigned long rate)
1151 return ddr_set_pll(rate/MHZ,0)*MHZ;
1153 static unsigned long ddr_clk_recalc_rate(struct clk *clk)
1155 u32 shift = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift);
1156 unsigned long rate = clk->parent->recalc(clk->parent)>> shift;
1157 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
1160 static struct clk *clk_ddr_parents[2] = {&ddr_pll_clk, &general_pll_clk};
1161 static struct clk clk_ddr = {
1163 .parent = &ddr_pll_clk,
1164 .recalc = ddr_clk_recalc_rate,
1165 .set_rate = ddr_clk_set_rate,
1166 .round_rate = ddr_clk_round_rate,
1167 .clksel_con = CRU_CLKSELS_CON(26),
1168 //CRU_DIV_SET(0x3,0,4),
1170 //CRU_PARENTS_SET(clk_ddr_parents),
1172 static int arm_core_clk_set_rate(struct clk *c, unsigned long rate)
1176 //set_cru_bits_w_msk(0,c->div_mask,c->div_shift,c->clksel_con);
1178 ret = clk_set_rate_nolock(c->parent, rate);
1180 CRU_PRINTK_ERR("Failed to change clk pll %s to %lu\n",c->name,rate);
1185 static unsigned long arm_core_clk_get_rate(struct clk *c)
1187 u32 div=(get_cru_bits(c->clksel_con,c->div_mask,c->div_shift)+1);
1188 //c->parent->rate=c->parent->recalc(c->parent);
1189 return c->parent->rate/div;
1191 static long core_clk_round_rate(struct clk *clk, unsigned long rate)
1193 u32 div=(get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1);
1194 return clk_round_rate_nolock(clk->parent,rate)/div;
1197 static int core_clksel_set_parent(struct clk *clk, struct clk *new_prt)
1201 struct clk *old_prt;
1203 if(clk->parent==new_prt)
1205 if (unlikely(!clk->parents))
1207 CRU_PRINTK_DBG("%s,reparent %s\n",clk->name,new_prt->name);
1209 old_prt=clk->parent;
1211 if(clk->parents[0]==new_prt)
1213 new_prt->set_rate(new_prt,300*MHZ);
1214 set_cru_bits_w_msk(0,clk->div_mask,clk->div_shift,clk->clksel_con);
1216 else if(clk->parents[1]==new_prt)
1219 if(new_prt->rate>old_prt->rate)
1221 temp_div=clk_get_freediv(old_prt->rate,new_prt->rate,clk->div_max);
1222 set_cru_bits_w_msk(temp_div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
1224 set_cru_bits_w_msk(1,clk->src_mask,clk->src_shift,clk->clksel_con);
1225 new_prt->set_rate(new_prt,300*MHZ);
1235 static int core_gpll_clk_set_rate(struct clk *c, unsigned long rate)
1237 unsigned long flags;
1240 u32 old_aclk_div=0,new_aclk_div;
1241 struct arm_clks_div_set *temp_clk_div;
1242 unsigned long arm_gpll_rate, arm_gpll_lpj;
1243 temp_div=clk_get_freediv(rate,c->parent->rate,c->div_max);
1244 arm_gpll_rate=c->parent->rate/temp_div;
1246 temp_clk_div=arm_clks_get_div(arm_gpll_rate/MHZ);
1248 temp_clk_div=&arm_clk_div_tlb[4];
1250 old_aclk_div=GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
1251 new_aclk_div=GET_CORE_ACLK_VAL(temp_clk_div->clksel1&CORE_ACLK_MSK);
1254 arm_gpll_lpj = lpj_gpll / temp_div;
1255 set_cru_bits_w_msk(temp_div-1,c->div_mask,c->div_shift,c->clksel_con);
1258 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
1259 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
1260 CRU_CLKSELS_CON(0));
1263 arm_gpll_lpj = lpj_gpll / temp_div;
1264 set_cru_bits_w_msk(temp_div-1,c->div_mask,c->div_shift,c->clksel_con);
1268 static unsigned long arm_core_gpll_clk_get_rate(struct clk *c)
1270 return c->parent->rate;
1273 static struct clk clk_cpu_gpll_path = {
1274 .name = "cpu_gpll_path",
1275 .parent = &general_pll_clk,
1276 .recalc = arm_core_gpll_clk_get_rate,
1277 .set_rate = core_gpll_clk_set_rate,
1278 CRU_DIV_SET(0x1f,0,32),
1279 CRU_GATE_MODE_SET(gate_mode,CLK_GATE_CPU_GPLL_PATH),
1283 static struct clk *clk_cpu_parents[2] = {&arm_pll_clk,&clk_cpu_gpll_path};
1285 static struct clk clk_cpu = {
1287 .parent = &arm_pll_clk,
1288 .set_rate = arm_core_clk_set_rate,
1289 .recalc = arm_core_clk_get_rate,
1290 .round_rate = core_clk_round_rate,
1291 .set_parent = core_clksel_set_parent,
1292 .clksel_con = CRU_CLKSELS_CON(0),
1293 CRU_DIV_SET(0x1f,0,32),
1295 CRU_PARENTS_SET(clk_cpu_parents),
1297 static unsigned long aclk_cpu_recalc(struct clk *clk)
1300 u32 div = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1;
1305 rate = clk->parent->rate / div;
1306 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
1310 static struct clk core_periph = {
1311 .name = "core_periph",
1313 .recalc = clksel_recalc_shift_2,
1314 .clksel_con = CRU_CLKSELS_CON(0),
1315 CRU_DIV_SET(0x3,6,16),
1318 static struct clk aclk_cpu = {
1321 .recalc = aclk_cpu_recalc,
1322 .clksel_con = CRU_CLKSELS_CON(1),
1323 CRU_DIV_SET(0x7,0,8),
1326 static struct clk hclk_cpu = {
1328 .parent = &aclk_cpu,
1329 .recalc = clksel_recalc_shift,
1330 //.set_rate = clksel_set_rate_shift,
1331 .clksel_con = CRU_CLKSELS_CON(1),
1332 CRU_DIV_SET(0x3,8,4),
1336 static struct clk pclk_cpu = {
1338 .parent = &aclk_cpu,
1339 .recalc = clksel_recalc_shift,
1340 //.set_rate = clksel_set_rate_shift,
1341 .clksel_con = CRU_CLKSELS_CON(1),
1342 CRU_DIV_SET(0x3,12,8),
1344 static struct clk ahb2apb_cpu = {
1346 .parent = &hclk_cpu,
1347 .recalc = clksel_recalc_shift,
1348 .clksel_con = CRU_CLKSELS_CON(1),
1349 CRU_DIV_SET(0x3,14,4),
1353 static struct clk atclk_cpu = {
1354 .name = "atclk_cpu",
1355 .parent = &pclk_cpu,
1358 static struct clk *clk_i2s_div_parents[]={&general_pll_clk,&codec_pll_clk};
1359 static struct clk clk_i2s_pll = {
1361 .parent = &general_pll_clk,
1362 .clksel_con = CRU_CLKSELS_CON(2),
1363 CRU_SRC_SET(0x1,16),
1364 CRU_PARENTS_SET(clk_i2s_div_parents),
1367 static struct clk clk_i2s0_div = {
1369 .parent = &clk_i2s_pll,
1371 .recalc = clksel_recalc_div,
1372 .set_rate = clksel_set_rate_freediv,
1373 .round_rate =clksel_freediv_round_rate,
1374 .gate_idx = CLK_GATE_I2S0,
1375 .clksel_con = CRU_CLKSELS_CON(2),
1376 CRU_DIV_SET(0x7f,0,64),
1379 static struct clk clk_i2s1_div = {
1381 .parent = &clk_i2s_pll,
1382 .recalc = clksel_recalc_div,
1383 .set_rate = clksel_set_rate_freediv,
1384 .round_rate =clksel_freediv_round_rate,
1386 .gate_idx = CLK_GATE_I2S1,
1387 .clksel_con = CRU_CLKSELS_CON(3),
1388 CRU_DIV_SET(0x7f,0,64),
1392 static struct clk clk_i2s2_div = {
1394 .parent = &clk_i2s_pll,
1395 .recalc = clksel_recalc_div,
1396 .set_rate = clksel_set_rate_freediv,
1397 .round_rate =clksel_freediv_round_rate,
1399 .gate_idx = CLK_GATE_I2S2,
1400 .clksel_con = CRU_CLKSELS_CON(4),
1401 CRU_DIV_SET(0x7f,0,64),
1403 static struct clk clk_spdif_div = {
1404 .name = "spdif_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_SPDIF,
1411 .clksel_con = CRU_CLKSELS_CON(5),
1412 CRU_DIV_SET(0x7f,0,64),
1414 static int clk_i2s_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1416 u32 numerator, denominator;
1417 //clk_i2s_div->clk_i2s_pll->gpll/cpll
1418 //clk->parent->parent
1419 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1420 &numerator,&denominator)==0)
1422 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1423 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1424 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1428 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1435 static struct clk clk_i2s0_frac_div = {
1436 .name = "i2s0_frac_div",
1437 .parent = &clk_i2s0_div,
1439 .gate_idx = CLK_GATE_I2S0_FRAC,
1440 .recalc = clksel_recalc_frac,
1441 .set_rate = clk_i2s_fracdiv_set_rate,
1442 .clksel_con = CRU_CLKSELS_CON(6),
1445 static struct clk clk_i2s1_frac_div = {
1446 .name = "i2s1_frac_div",
1447 .parent = &clk_i2s1_div,
1449 .gate_idx = CLK_GATE_I2S1_FRAC,
1450 .recalc = clksel_recalc_frac,
1451 .set_rate = clk_i2s_fracdiv_set_rate,
1452 .clksel_con = CRU_CLKSELS_CON(7),
1455 static struct clk clk_i2s2_frac_div = {
1456 .name = "i2s2_frac_div",
1458 .gate_idx = CLK_GATE_I2S2_FRAC,
1459 .parent = &clk_i2s2_div,
1460 .recalc = clksel_recalc_frac,
1461 .set_rate = clk_i2s_fracdiv_set_rate,
1462 .clksel_con = CRU_CLKSELS_CON(8),
1464 static struct clk clk_spdif_frac_div = {
1465 .name = "spdif_frac_div",
1466 .parent = &clk_spdif_div,
1468 .gate_idx = CLK_GATE_SPDIF_FRAC,
1469 .recalc = clksel_recalc_frac,
1470 .set_rate = clk_i2s_fracdiv_set_rate,
1471 .clksel_con = CRU_CLKSELS_CON(9),
1474 #define I2S_SRC_DIV (0x0)
1475 #define I2S_SRC_FRAC (0x1)
1476 #define I2S_SRC_12M (0x2)
1478 static int i2s_set_rate(struct clk *clk, unsigned long rate)
1483 if (rate == clk->parents[I2S_SRC_12M]->rate){
1484 parent = clk->parents[I2S_SRC_12M];
1485 }else if((long)clk_round_rate_nolock(clk->parents[I2S_SRC_DIV],rate)==rate)
1487 parent = clk->parents[I2S_SRC_DIV];
1491 parent =clk->parents[I2S_SRC_FRAC];
1494 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
1495 clk->name,rate,parent->name,clk->parent->name);
1497 if(parent!=clk->parents[I2S_SRC_12M])
1499 ret = clk_set_rate_nolock(parent,rate);//div 1:1
1502 CRU_PRINTK_DBG("%s set rate%lu err\n",clk->name,rate);
1507 if (clk->parent != parent)
1509 ret = clk_set_parent_nolock(clk, parent);
1512 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
1520 static struct clk *clk_i2s0_parents[3]={&clk_i2s0_div,&clk_i2s0_frac_div,&clk_12m};
1522 static struct clk clk_i2s0 = {
1524 .set_rate = i2s_set_rate,
1525 .clksel_con = CRU_CLKSELS_CON(2),
1527 CRU_PARENTS_SET(clk_i2s0_parents),
1530 static struct clk *clk_i2s1_parents[3]={&clk_i2s1_div,&clk_i2s1_frac_div,&clk_12m};
1532 static struct clk clk_i2s1 = {
1534 .set_rate = i2s_set_rate,
1535 .clksel_con = CRU_CLKSELS_CON(3),
1537 CRU_PARENTS_SET(clk_i2s1_parents),
1540 static struct clk *clk_i2s2_parents[3]={&clk_i2s2_div,&clk_i2s2_frac_div,&clk_12m};
1542 static struct clk clk_i2s2 = {
1544 .set_rate = i2s_set_rate,
1545 .clksel_con = CRU_CLKSELS_CON(4),
1547 CRU_PARENTS_SET(clk_i2s2_parents),
1550 static struct clk *clk_spdif_parents[3]={&clk_spdif_div,&clk_spdif_frac_div,&clk_12m};
1552 static struct clk clk_spdif = {
1554 .parent = &clk_spdif_frac_div,
1555 .set_rate = i2s_set_rate,
1556 .clksel_con = CRU_CLKSELS_CON(5),
1558 CRU_PARENTS_SET(clk_spdif_parents),
1561 static struct clk *aclk_periph_parents[2]={&general_pll_clk,&codec_pll_clk};
1563 static struct clk aclk_periph = {
1564 .name = "aclk_periph",
1565 .parent = &general_pll_clk,
1567 .gate_idx = CLK_GATE_ACLK_PERIPH,
1568 .recalc = clksel_recalc_div,
1569 .set_rate = clksel_set_rate_freediv,
1570 .clksel_con = CRU_CLKSELS_CON(10),
1571 CRU_DIV_SET(0x1f,0,32),
1573 CRU_PARENTS_SET(aclk_periph_parents),
1575 GATE_CLK(periph_src, aclk_periph, PERIPH_SRC);
1577 static struct clk pclk_periph = {
1578 .name = "pclk_periph",
1579 .parent = &aclk_periph,
1581 .gate_idx = CLK_GATE_PCLK_PERIPH,
1582 .recalc = clksel_recalc_shift,
1583 .set_rate = clksel_set_rate_shift,
1584 .clksel_con = CRU_CLKSELS_CON(10),
1585 CRU_DIV_SET(0x3,12,8),
1588 static struct clk hclk_periph = {
1589 .name = "hclk_periph",
1590 .parent = &aclk_periph,
1592 .gate_idx = CLK_GATE_HCLK_PERIPH,
1593 .recalc = clksel_recalc_shift,
1594 .set_rate = clksel_set_rate_shift,
1595 .clksel_con = CRU_CLKSELS_CON(10),
1596 CRU_DIV_SET(0x3,8,4),
1599 static struct clk clk_spi0 = {
1601 .parent = &pclk_periph,
1603 .recalc = clksel_recalc_div,
1604 .set_rate = clksel_set_rate_freediv,
1605 .gate_idx = CLK_GATE_SPI0,
1606 .clksel_con = CRU_CLKSELS_CON(25),
1607 CRU_DIV_SET(0x7f,0,128),
1610 static struct clk clk_spi1 = {
1612 .parent = &pclk_periph,
1614 .recalc = clksel_recalc_div,
1615 .set_rate = clksel_set_rate_freediv,
1616 .gate_idx = CLK_GATE_SPI1,
1617 .clksel_con = CRU_CLKSELS_CON(25),
1618 CRU_DIV_SET(0x7f,8,128),
1621 static struct clk clk_saradc = {
1625 .recalc = clksel_recalc_div,
1626 .set_rate = clksel_set_rate_freediv,
1627 .gate_idx = CLK_GATE_SARADC,
1628 .clksel_con =CRU_CLKSELS_CON(24),
1629 CRU_DIV_SET(0xff,8,256),
1631 static struct clk clk_tsadc = {
1635 .recalc = clksel_recalc_div,
1636 .set_rate = clksel_set_rate_freediv,
1637 .gate_idx = CLK_GATE_TSADC,
1638 .clksel_con =CRU_CLKSELS_CON(34),
1639 CRU_DIV_SET(0xffff,0,65536),
1641 GATE_CLK(otgphy0, xin24m, OTGPHY0);
1642 GATE_CLK(otgphy1, xin24m, OTGPHY1);
1645 GATE_CLK(smc, pclk_periph, SMC);//smc
1647 static struct clk clk_sdmmc = {
1649 .parent = &hclk_periph,
1651 .recalc = clksel_recalc_div,
1652 .set_rate = clksel_set_rate_freediv,
1653 .gate_idx = CLK_GATE_MMC0,
1654 .clksel_con =CRU_CLKSELS_CON(11),
1655 CRU_DIV_SET(0x3f,0,64),
1658 static struct clk clk_sdio = {
1660 .parent = &hclk_periph,
1662 .recalc = clksel_recalc_div,
1663 .set_rate = clksel_set_rate_freediv,
1664 .gate_idx = CLK_GATE_SDIO,
1665 .clksel_con =CRU_CLKSELS_CON(12),
1666 CRU_DIV_SET(0x3f,0,64),
1670 static struct clk clk_emmc = {
1672 .parent = &hclk_periph,
1674 .recalc = clksel_recalc_div,
1675 .set_rate = clksel_set_rate_freediv,
1676 .gate_idx = CLK_GATE_EMMC,
1677 .clksel_con =CRU_CLKSELS_CON(12),
1678 CRU_DIV_SET(0x3f,8,64),
1681 static struct clk *clk_uart_src_parents[2]={&general_pll_clk,&codec_pll_clk};
1682 static struct clk clk_uart_pll = {
1684 .parent = &general_pll_clk,
1685 .clksel_con =CRU_CLKSELS_CON(12),
1686 CRU_SRC_SET(0x1,15),
1687 CRU_PARENTS_SET(clk_uart_src_parents),
1689 static struct clk clk_uart0_div = {
1690 .name = "uart0_div",
1691 .parent = &clk_uart_pll,
1693 .gate_idx = CLK_GATE_UART0,
1694 .recalc = clksel_recalc_div,
1695 .set_rate = clksel_set_rate_freediv,
1696 .round_rate =clksel_freediv_round_rate,
1697 .clksel_con = CRU_CLKSELS_CON(13),
1698 CRU_DIV_SET(0x7f,0,64),
1700 static struct clk clk_uart1_div = {
1701 .name = "uart1_div",
1702 .parent = &clk_uart_pll,
1704 .gate_idx = CLK_GATE_UART1,
1705 .recalc = clksel_recalc_div,
1706 .round_rate =clksel_freediv_round_rate,
1707 .set_rate = clksel_set_rate_freediv,
1708 .clksel_con = CRU_CLKSELS_CON(14),
1709 CRU_DIV_SET(0x7f,0,64),
1712 static struct clk clk_uart2_div = {
1713 .name = "uart2_div",
1714 .parent = &clk_uart_pll,
1716 .gate_idx = CLK_GATE_UART2,
1717 .recalc = clksel_recalc_div,
1718 .round_rate =clksel_freediv_round_rate,
1719 .set_rate = clksel_set_rate_freediv,
1720 .clksel_con = CRU_CLKSELS_CON(15),
1721 CRU_DIV_SET(0x7f,0,64),
1724 static struct clk clk_uart3_div = {
1725 .name = "uart3_div",
1726 .parent = &clk_uart_pll,
1728 .gate_idx = CLK_GATE_UART3,
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(16),
1733 CRU_DIV_SET(0x7f,0,64),
1735 static int clk_uart_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1737 u32 numerator, denominator;
1738 //clk_uart0_div->clk_uart_pll->gpll/cpll
1739 //clk->parent->parent
1740 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1741 &numerator,&denominator)==0)
1743 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1745 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1747 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1751 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1757 static struct clk clk_uart0_frac_div = {
1758 .name = "uart0_frac_div",
1759 .parent = &clk_uart0_div,
1761 .recalc = clksel_recalc_frac,
1762 .set_rate = clk_uart_fracdiv_set_rate,
1763 .gate_idx = CLK_GATE_FRAC_UART0,
1764 .clksel_con = CRU_CLKSELS_CON(17),
1766 static struct clk clk_uart1_frac_div = {
1767 .name = "uart1_frac_div",
1768 .parent = &clk_uart1_div,
1770 .recalc = clksel_recalc_frac,
1771 .set_rate = clk_uart_fracdiv_set_rate,
1772 .gate_idx = CLK_GATE_FRAC_UART1,
1773 .clksel_con = CRU_CLKSELS_CON(18),
1775 static struct clk clk_uart2_frac_div = {
1776 .name = "uart2_frac_div",
1778 .parent = &clk_uart2_div,
1779 .recalc = clksel_recalc_frac,
1780 .set_rate = clk_uart_fracdiv_set_rate,
1781 .gate_idx = CLK_GATE_FRAC_UART2,
1782 .clksel_con = CRU_CLKSELS_CON(19),
1784 static struct clk clk_uart3_frac_div = {
1785 .name = "uart3_frac_div",
1786 .parent = &clk_uart3_div,
1788 .recalc = clksel_recalc_frac,
1789 .set_rate = clk_uart_fracdiv_set_rate,
1790 .gate_idx = CLK_GATE_FRAC_UART3,
1791 .clksel_con = CRU_CLKSELS_CON(20),
1795 #define UART_SRC_DIV 0
1796 #define UART_SRC_FRAC 1
1797 #define UART_SRC_24M 2
1799 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
1804 if(rate==clk->parents[UART_SRC_24M]->rate)//24m
1806 parent = clk->parents[UART_SRC_24M];
1808 else if((long)clk_round_rate_nolock(clk->parents[UART_SRC_DIV], rate)==rate)
1810 parent = clk->parents[UART_SRC_DIV];
1814 parent = clk->parents[UART_SRC_FRAC];
1817 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
1818 clk->name,rate,parent->name,clk->parent->name);
1821 if(parent!=clk->parents[UART_SRC_24M])
1823 ret = clk_set_rate_nolock(parent,rate);
1826 CRU_PRINTK_DBG("%s set rate%lu err\n",clk->name,rate);
1831 if (clk->parent != parent)
1833 ret = clk_set_parent_nolock(clk, parent);
1836 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
1846 static struct clk *clk_uart0_parents[3]={&clk_uart0_div,&clk_uart0_frac_div,&xin24m};
1847 static struct clk clk_uart0 = {
1849 .set_rate = clk_uart_set_rate,
1850 .clksel_con = CRU_CLKSELS_CON(13),
1852 CRU_PARENTS_SET(clk_uart0_parents),
1855 static struct clk *clk_uart1_parents[3]={&clk_uart1_div,&clk_uart1_frac_div,&xin24m};
1856 static struct clk clk_uart1 = {
1858 .set_rate = clk_uart_set_rate,
1859 .clksel_con = CRU_CLKSELS_CON(14),
1861 CRU_PARENTS_SET(clk_uart1_parents),
1864 static struct clk *clk_uart2_parents[3]={&clk_uart2_div,&clk_uart2_frac_div,&xin24m};
1865 static struct clk clk_uart2 = {
1867 .set_rate = clk_uart_set_rate,
1868 .clksel_con = CRU_CLKSELS_CON(15),
1870 CRU_PARENTS_SET(clk_uart2_parents),
1872 static struct clk *clk_uart3_parents[3]={&clk_uart3_div,&clk_uart3_frac_div,&xin24m};
1873 static struct clk clk_uart3 = {
1875 .set_rate = clk_uart_set_rate,
1876 .clksel_con = CRU_CLKSELS_CON(16),
1878 CRU_PARENTS_SET(clk_uart3_parents),
1881 GATE_CLK(timer0, xin24m, TIMER0);
1882 GATE_CLK(timer1, xin24m, TIMER1);
1883 GATE_CLK(timer2, xin24m, TIMER2);
1885 static struct clk rmii_clkin = {
1886 .name = "rmii_clkin",
1888 static struct clk *clk_mac_ref_div_parents[2]={&general_pll_clk,&ddr_pll_clk};
1889 static struct clk clk_mac_pll_div = {
1890 .name = "mac_pll_div",
1891 .parent = &ddr_pll_clk,
1893 .gate_idx = CLK_GATE_MAC,
1894 .recalc = clksel_recalc_div,
1895 .set_rate =clksel_set_rate_freediv,
1896 //.set_rate = clksel_set_rate_freediv,
1897 .clksel_con =CRU_CLKSELS_CON(21),
1898 CRU_DIV_SET(0x1f,8,32),
1900 CRU_PARENTS_SET(clk_mac_ref_div_parents),
1903 static int clksel_mac_ref_set_rate(struct clk *clk, unsigned long rate)
1906 if(clk->parent==clk->parents[1])
1908 CRU_PRINTK_DBG("mac_ref clk is form mii clkin,can't set it\n" );
1911 else if(clk->parent==clk->parents[0])
1913 return clk_set_rate_nolock(clk->parents[0],rate);
1918 static struct clk *clk_mac_ref_parents[2]={&clk_mac_pll_div,&rmii_clkin};
1920 static struct clk clk_mac_ref = {
1922 .parent = &clk_mac_pll_div,
1923 .set_rate = clksel_mac_ref_set_rate,
1924 .clksel_con =CRU_CLKSELS_CON(21),
1926 CRU_PARENTS_SET(clk_mac_ref_parents),
1929 static int clk_set_mii_tx_parent(struct clk *clk, struct clk *parent)
1931 return clk_set_parent_nolock(clk->parent,parent);
1934 static struct clk clk_mii_tx = {
1936 .parent = &clk_mac_ref,
1937 //.set_parent = clk_set_mii_tx_parent,
1939 .gate_idx = CLK_GATE_MAC_LBTEST,//???
1942 static struct clk *clk_hsadc_pll_parents[2]={&general_pll_clk,&codec_pll_clk};
1943 static struct clk clk_hsadc_pll_div = {
1944 .name = "hsadc_pll_div",
1945 .parent = &general_pll_clk,
1947 .gate_idx = CLK_GATE_SARADC,
1948 .recalc = clksel_recalc_div,
1949 .round_rate =clk_freediv_round_autosel_parents_rate,
1950 .set_rate = clkset_rate_freediv_autosel_parents,
1951 //.round_rate =clksel_freediv_round_rate,
1952 //.set_rate = clksel_set_rate_freediv,
1953 .clksel_con =CRU_CLKSELS_CON(22),
1954 CRU_DIV_SET(0xff,8,256),
1956 CRU_PARENTS_SET(clk_hsadc_pll_parents),
1959 static int clk_hsadc_fracdiv_set_rate_fixed_parent(struct clk *clk, unsigned long rate)
1961 u32 numerator, denominator;
1962 // clk_hsadc_pll_div->gpll/cpll
1963 //clk->parent->parent
1964 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1965 &numerator,&denominator)==0)
1967 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1969 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1971 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1975 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1980 static int clk_hsadc_fracdiv_set_rate_auto_parents(struct clk *clk, unsigned long rate)
1982 u32 numerator, denominator;
1984 // clk_hsadc_pll_div->gpll/cpll
1985 //clk->parent->parent
1988 if(frac_div_get_seting(rate,clk->parent->parents[i]->rate,
1989 &numerator,&denominator)==0)
1995 if(clk->parent->parent!=clk->parent->parents[i])
1996 ret=clk_set_parent_nolock(clk->parent, clk->parent->parents[i]);
1999 clk_set_rate_nolock(clk->parent,clk->parent->parents[i]->rate);//PLL:DIV 1:
2001 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2003 CRU_PRINTK_DBG("clk_frac_div %s, rate=%lu\n",clk->name,rate);
2007 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
2013 static long clk_hsadc_fracdiv_round_rate(struct clk *clk, unsigned long rate)
2015 u32 numerator, denominator;
2017 CRU_PRINTK_ERR("clk_hsadc_fracdiv_round_rate\n");
2018 if(frac_div_get_seting(rate,clk->parent->parent->rate,
2019 &numerator,&denominator)==0)
2024 static struct clk clk_hsadc_frac_div = {
2025 .name = "hsadc_frac_div",
2026 .parent = &clk_hsadc_pll_div,
2028 .recalc = clksel_recalc_frac,
2029 .set_rate = clk_hsadc_fracdiv_set_rate_auto_parents,
2030 .round_rate =clk_hsadc_fracdiv_round_rate,
2031 .gate_idx = CLK_GATE_HSADC_FRAC,
2032 .clksel_con = CRU_CLKSELS_CON(23),
2035 #define HSADC_SRC_DIV 0x0
2036 #define HSADC_SRC_FRAC 0x1
2037 #define HSADC_SRC_EXT 0x2
2038 static int clk_hsadc_set_rate(struct clk *clk, unsigned long rate)
2043 if(clk->parent == clk->parents[HSADC_SRC_EXT]){
2044 CRU_PRINTK_DBG("hsadc clk is form ext\n");
2047 else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_DIV],rate)==rate)
2049 parent =clk->parents[HSADC_SRC_DIV];
2051 else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_FRAC],rate)==rate)
2053 parent = clk->parents[HSADC_SRC_FRAC];
2056 parent =clk->parents[HSADC_SRC_DIV];
2058 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
2059 clk->name,rate,parent->name,clk->parent->name);
2061 ret = clk_set_rate_nolock(parent,rate);
2064 CRU_PRINTK_ERR("%s set rate%lu err\n",clk->name,rate);
2067 if (clk->parent != parent)
2069 ret = clk_set_parent_nolock(clk, parent);
2072 CRU_PRINTK_ERR("%s can't get rate%lu,reparent err\n",clk->name,rate);
2079 static struct clk clk_hsadc_ext = {
2080 .name = "hsadc_ext",
2083 static struct clk *clk_hsadc_parents[3]={&clk_hsadc_pll_div,&clk_hsadc_frac_div,&clk_hsadc_ext};
2084 static struct clk clk_hsadc = {
2086 .parent = &clk_hsadc_pll_div,
2087 .set_rate = clk_hsadc_set_rate,
2088 .clksel_con = CRU_CLKSELS_CON(22),
2090 CRU_PARENTS_SET(clk_hsadc_parents),
2093 static struct clk *dclk_lcdc_div_parents[]={&codec_pll_clk,&general_pll_clk};
2094 static struct clk dclk_lcdc0_div = {
2095 .name = "dclk_lcdc0_div",
2096 .parent = &general_pll_clk,
2097 .recalc = clksel_recalc_div,
2098 .set_rate = clkset_rate_freediv_autosel_parents,
2099 .clksel_con = CRU_CLKSELS_CON(27),
2100 CRU_DIV_SET(0xff,8,256),
2102 CRU_PARENTS_SET(dclk_lcdc_div_parents),
2105 static int clksel_set_rate_hdmi(struct clk *clk, unsigned long rate)
2109 unsigned long new_rate;
2116 div=clk_get_freediv(rate,clk->parents[i]->rate,clk->div_max);
2117 new_rate= clk->parents[i]->rate/div;
2118 if((rate==new_rate)&&!(clk->parents[i]->rate%div))
2125 CRU_PRINTK_ERR("%s can't set fixed rate%lu\n",clk->name,rate);
2129 //CRU_PRINTK_DBG("%s set rate %lu(from %s)\n",clk->name,rate,clk->parents[i]->name);
2131 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),
2132 clk->div_shift,clk->div_mask)+1;
2134 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
2136 if(clk->parents[i]!=clk->parent)
2138 ret=clk_set_parent_nolock(clk,clk->parents[i]);
2143 CRU_PRINTK_ERR("lcdc1 %s can't get rate%lu,reparent%s(now %s) err\n",
2144 clk->name,rate,clk->parents[i]->name,clk->parent->name);
2147 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
2151 static struct clk dclk_lcdc1_div = {
2152 .name = "dclk_lcdc1_div",
2153 .parent = &general_pll_clk,
2154 .recalc = clksel_recalc_div,
2155 .set_rate = clksel_set_rate_hdmi,//clk_freediv_autosel_parents_set_fixed_rate
2156 .clksel_con = CRU_CLKSELS_CON(28),
2157 CRU_DIV_SET(0xff,8,256),
2159 CRU_PARENTS_SET(dclk_lcdc_div_parents),
2162 static int dclk_lcdc_set_rate(struct clk *clk, unsigned long rate)
2167 if (rate == 27 * MHZ&&(rk30_clock_flags&CLK_FLG_EXT_27MHZ)) {
2168 parent =clk->parents[1];
2169 //CRU_PRINTK_DBG(" %s from=%s\n",clk->name,parent->name);
2171 parent=clk->parents[0];
2173 //CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
2174 //clk->name,rate,parent->name,clk->parent->name);
2176 if(parent!=clk->parents[1])
2178 ret = clk_set_rate_nolock(parent,rate);//div 1:1
2181 CRU_PRINTK_DBG("%s set rate=%lu err\n",clk->name,rate);
2185 if (clk->parent != parent)
2187 ret = clk_set_parent_nolock(clk, parent);
2190 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
2197 static struct clk *dclk_lcdc0_parents[2]={&dclk_lcdc0_div,&xin27m};
2198 static struct clk dclk_lcdc0 = {
2199 .name = "dclk_lcdc0",
2201 .set_rate = dclk_lcdc_set_rate,
2202 .gate_idx = CLK_GATE_DCLK_LCDC0,
2203 .clksel_con = CRU_CLKSELS_CON(27),
2205 CRU_PARENTS_SET(dclk_lcdc0_parents),
2208 static struct clk *dclk_lcdc1_parents[2]={&dclk_lcdc1_div,&xin27m};
2209 static struct clk dclk_lcdc1 = {
2210 .name = "dclk_lcdc1",
2212 .set_rate = dclk_lcdc_set_rate,
2213 .gate_idx = CLK_GATE_DCLK_LCDC1,
2214 .clksel_con = CRU_CLKSELS_CON(28),
2216 CRU_PARENTS_SET(dclk_lcdc1_parents),
2219 static struct clk *cifout_sel_pll_parents[2]={&codec_pll_clk,&general_pll_clk};
2220 static struct clk cif_out_pll = {
2221 .name = "cif_out_pll",
2222 .parent = &general_pll_clk,
2223 .clksel_con = CRU_CLKSELS_CON(29),
2225 CRU_PARENTS_SET(cifout_sel_pll_parents),
2228 static struct clk cif0_out_div = {
2229 .name = "cif0_out_div",
2230 .parent = &cif_out_pll,
2232 .recalc = clksel_recalc_div,
2233 .set_rate = clksel_set_rate_freediv,
2234 .gate_idx =CLK_GATE_CIF0_OUT,
2235 .clksel_con = CRU_CLKSELS_CON(29),
2236 CRU_DIV_SET(0x1f,1,32),
2239 static struct clk cif1_out_div = {
2240 .name = "cif1_out_div",
2241 .parent = &cif_out_pll,
2243 .recalc = clksel_recalc_div,
2244 .set_rate = clksel_set_rate_freediv,
2245 .gate_idx = CLK_GATE_CIF1_OUT,
2246 .clksel_con = CRU_CLKSELS_CON(29),
2247 CRU_DIV_SET(0x1f,8,32),
2251 static int cif_out_set_rate(struct clk *clk, unsigned long rate)
2256 if (rate == 24 * MHZ) {
2257 parent =clk->parents[1];
2259 parent=clk->parents[0];
2260 ret = clk_set_rate_nolock(parent, rate);
2264 if (clk->parent != parent)
2265 ret = clk_set_parent_nolock(clk, parent);
2270 static struct clk *cif0_out_parents[2]={&cif0_out_div,&xin24m};
2271 static struct clk cif0_out = {
2273 .parent = &cif0_out_div,
2274 .set_rate = cif_out_set_rate,
2275 .clksel_con = CRU_CLKSELS_CON(29),
2277 CRU_PARENTS_SET(cif0_out_parents),
2279 static struct clk *cif1_out_parents[2]={&cif1_out_div,&xin24m};
2281 static struct clk cif1_out = {
2283 .parent = &cif1_out_div,
2284 .set_rate = cif_out_set_rate,
2285 .clksel_con = CRU_CLKSELS_CON(29),
2286 CRU_SRC_SET(0x1,15),
2287 CRU_PARENTS_SET(cif1_out_parents),
2290 static struct clk pclkin_cif0 = {
2291 .name = "pclkin_cif0",
2293 .gate_idx =CLK_GATE_PCLKIN_CIF0,
2296 static struct clk inv_cif0 = {
2298 .parent = &pclkin_cif0,
2301 static struct clk *cif0_in_parents[2]={&pclkin_cif0,&inv_cif0};
2302 static struct clk cif0_in = {
2304 .parent = &pclkin_cif0,
2305 .clksel_con = CRU_CLKSELS_CON(30),
2307 CRU_PARENTS_SET(cif0_in_parents),
2310 static struct clk pclkin_cif1 = {
2311 .name = "pclkin_cif1",
2313 .gate_idx =CLK_GATE_PCLKIN_CIF1,
2316 static struct clk inv_cif1 = {
2318 .parent = &pclkin_cif1,
2320 static struct clk *cif1_in_parents[2]={&pclkin_cif1,&inv_cif1};
2322 static struct clk cif1_in = {
2324 .parent = &pclkin_cif1,
2325 .clksel_con = CRU_CLKSELS_CON(30),
2326 CRU_SRC_SET(0x1,12),
2327 CRU_PARENTS_SET(cif1_in_parents),
2330 static struct clk *aclk_lcdc0_ipp_parents[]={&codec_pll_clk,&general_pll_clk};
2332 static struct clk aclk_lcdc0_ipp_parent = {
2333 .name = "aclk_lcdc0_ipp_parent",
2334 .parent = &codec_pll_clk,
2336 .recalc = clksel_recalc_div,
2337 .set_rate = clkset_rate_freediv_autosel_parents,
2338 //.set_rate = clksel_set_rate_freediv,
2339 .gate_idx = CLK_GATE_ACLK_LCDC0_SRC,
2340 .clksel_con = CRU_CLKSELS_CON(31),
2341 CRU_DIV_SET(0x1f,0,32),
2343 CRU_PARENTS_SET(aclk_lcdc0_ipp_parents),
2346 static struct clk *aclk_lcdc1_rga_parents[]={&codec_pll_clk,&general_pll_clk};
2348 static struct clk aclk_lcdc1_rga_parent = {
2349 .name = "aclk_lcdc1_rga_parent",
2350 .parent = &codec_pll_clk,
2352 .recalc = clksel_recalc_div,
2353 .set_rate = clkset_rate_freediv_autosel_parents,
2354 .gate_idx = CLK_GATE_ACLK_LCDC1_SRC,
2355 .clksel_con = CRU_CLKSELS_CON(31),
2356 CRU_DIV_SET(0x1f,8,32),
2357 CRU_SRC_SET(0x1,15),
2358 CRU_PARENTS_SET(aclk_lcdc1_rga_parents),
2363 static unsigned long clksel_recalc_vpu_hclk(struct clk *clk)
2365 unsigned long rate = clk->parent->rate / 4;
2366 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, 4);
2370 static struct clk *aclk_vepu_parents[2]={&codec_pll_clk,&general_pll_clk};
2372 static struct clk aclk_vepu = {
2373 .name = "aclk_vepu",
2374 .parent = &codec_pll_clk,
2376 .recalc = clksel_recalc_div,
2377 //.set_rate = clksel_set_rate_freediv,
2378 .set_rate =clkset_rate_freediv_autosel_parents,
2379 .clksel_con = CRU_CLKSELS_CON(32),
2380 .gate_idx = CLK_GATE_ACLK_VEPU,
2381 CRU_DIV_SET(0x1f,0,32),
2383 CRU_PARENTS_SET(aclk_vepu_parents),
2386 static struct clk hclk_vepu = {
2387 .name = "hclk_vepu",
2388 .parent = &aclk_vepu,
2390 .recalc = clksel_recalc_vpu_hclk,
2391 .clksel_con = CRU_CLKSELS_CON(32),
2392 .gate_idx = CLK_GATE_HCLK_VEPU,
2395 static struct clk *aclk_vdpu_parents[2]={&codec_pll_clk,&general_pll_clk};
2397 static struct clk aclk_vdpu = {
2398 .name = "aclk_vdpu",
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_VDPU,
2405 CRU_DIV_SET(0x1f,8,32),
2406 CRU_SRC_SET(0x1,15),
2407 CRU_PARENTS_SET(aclk_vdpu_parents),
2409 static struct clk hclk_vdpu = {
2410 .name = "hclk_vdpu",
2411 .parent = &aclk_vdpu,
2413 .recalc = clksel_recalc_vpu_hclk,
2414 .clksel_con = CRU_CLKSELS_CON(32),
2415 .gate_idx = CLK_GATE_HCLK_VDPU,
2419 static int clk_gpu_set_rate(struct clk *clk, unsigned long rate)
2421 unsigned long max_rate = rate / 100 * 105; /* +5% */
2422 return clkset_rate_freediv_autosel_parents(clk,max_rate);
2425 static struct clk *gpu_parents[2]={&codec_pll_clk,&general_pll_clk};
2427 static struct clk clk_gpu = {
2430 .recalc = clksel_recalc_div,
2431 .round_rate = clk_freediv_round_autosel_parents_rate,
2432 .set_rate = clkset_rate_freediv_autosel_parents,
2433 .clksel_con = CRU_CLKSELS_CON(33),
2434 .gate_idx = CLK_GATE_GPU_SRC,
2435 CRU_DIV_SET(0x1f,0,32),
2437 CRU_PARENTS_SET(gpu_parents),
2440 /*********************power domain*******************************/
2441 #ifdef RK30_CLK_OFFBOARD_TEST
2442 void pmu_set_power_domain_test(enum pmu_power_domain pd, bool on){};
2443 #define _pmu_set_power_domain pmu_set_power_domain_test//rk30_pmu_set_power_domain
2445 void pmu_set_power_domain(enum pmu_power_domain pd, bool on);
2446 #define _pmu_set_power_domain pmu_set_power_domain
2448 static int pm_off_mode(struct clk *clk, int on)
2450 _pmu_set_power_domain(clk->gate_idx,on);//on 1
2453 static struct clk pd_peri = {
2456 .mode = pm_off_mode,
2457 .gate_idx = PD_PERI,
2460 static int pd_display_mode(struct clk *clk, int on)
2464 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2465 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2466 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2467 gate[3] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2468 gate[4] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2469 gate[5] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2470 gate[6] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2471 gate[7] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2472 gate[8] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2473 gate[9] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2474 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2475 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2476 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2477 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2478 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2479 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2480 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2481 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2482 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2483 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2484 pmu_set_power_domain(PD_VIO, on);
2485 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2486 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2487 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2488 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1) | gate[3], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2489 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0) | gate[4], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2490 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1) | gate[5], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2491 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0) | gate[6], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2492 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1) | gate[7], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2493 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP) | gate[8], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2494 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA) | gate[9], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2499 static struct clk pd_display = {
2500 .name = "pd_display",
2502 .mode = pd_display_mode,
2506 static struct clk pd_lcdc0 = {
2507 .parent = &pd_display,
2510 static struct clk pd_lcdc1 = {
2511 .parent = &pd_display,
2514 static struct clk pd_cif0 = {
2515 .parent = &pd_display,
2518 static struct clk pd_cif1 = {
2519 .parent = &pd_display,
2522 static struct clk pd_rga = {
2523 .parent = &pd_display,
2526 static struct clk pd_ipp = {
2527 .parent = &pd_display,
2531 static int pd_video_mode(struct clk *clk, int on)
2535 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2536 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2537 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2538 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2539 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2540 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2541 pmu_set_power_domain(PD_VIDEO, on);
2542 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2543 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2544 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2549 static struct clk pd_video = {
2552 .mode = pd_video_mode,
2553 .gate_idx = PD_VIDEO,
2556 static int pd_gpu_mode(struct clk *clk, int on)
2560 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2561 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2562 cru_writel(CLK_GATE_W_MSK(CLK_GATE_GPU_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2563 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2564 pmu_set_power_domain(PD_GPU, on);
2565 cru_writel(CLK_GATE_W_MSK(CLK_GATE_GPU_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2566 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2571 static struct clk pd_gpu = {
2574 .mode = pd_gpu_mode,
2577 static struct clk pd_dbg = {
2580 .mode = pm_off_mode,
2584 #define PD_CLK(name) \
2592 /************************rk30 fixed div clock****************************************/
2594 /*************************aclk_cpu***********************/
2596 GATE_CLK(dma1, aclk_cpu, ACLK_DMAC1);
2597 GATE_CLK(l2mem_con, aclk_cpu, ACLK_L2MEM_CON);
2598 GATE_CLK(intmem, aclk_cpu, ACLK_INTMEM);
2599 GATE_CLK(aclk_strc_sys, aclk_cpu, ACLK_STRC_SYS);
2601 /*************************hclk_cpu***********************/
2603 GATE_CLK(rom, hclk_cpu, HCLK_ROM);
2604 GATE_CLK(hclk_i2s0_2ch, hclk_cpu, HCLK_I2S0_2CH);
2605 GATE_CLK(hclk_i2s1_2ch, hclk_cpu, HCLK_I2S1_2CH);
2606 GATE_CLK(hclk_spdif, hclk_cpu, HCLK_SPDIF);
2607 GATE_CLK(hclk_i2s_8ch, hclk_cpu, HCLK_I2S_8CH);
2608 GATE_CLK(hclk_cpubus, hclk_cpu, HCLK_CPUBUS);
2609 GATE_CLK(hclk_ahb2apb, hclk_cpu, HCLK_AHB2APB);
2610 GATE_CLK(hclk_vio_bus, hclk_cpu, HCLK_VIO_BUS);
2611 GATE_CLK(hclk_lcdc0, hclk_cpu, HCLK_LCDC0);
2612 GATE_CLK(hclk_lcdc1, hclk_cpu, HCLK_LCDC1);
2613 GATE_CLK(hclk_cif0, hclk_cpu, HCLK_CIF0);
2614 GATE_CLK(hclk_cif1, hclk_cpu, HCLK_CIF1);
2615 GATE_CLK(hclk_ipp, hclk_cpu, HCLK_IPP);
2616 GATE_CLK(hclk_rga, hclk_cpu, HCLK_RGA);
2617 GATE_CLK(hclk_hdmi, hclk_cpu, HCLK_HDMI);
2618 //GATE_CLK(hclk_vidoe_h2h, hclk_cpu, ); ???
2619 /*************************pclk_cpu***********************/
2620 GATE_CLK(pwm01, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2621 //GATE_CLK(pclk_pwm1, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2622 GATE_CLK(pclk_timer0, pclk_cpu, PCLK_TIMER0);
2623 GATE_CLK(pclk_timer1, pclk_cpu, PCLK_TIMER1);
2624 GATE_CLK(pclk_timer2, pclk_cpu, PCLK_TIMER2);
2625 GATE_CLK(i2c0, pclk_cpu, PCLK_I2C0);
2626 GATE_CLK(i2c1, pclk_cpu, PCLK_I2C1);
2627 GATE_CLK(gpio0, pclk_cpu, PCLK_GPIO0);
2628 GATE_CLK(gpio1, pclk_cpu, PCLK_GPIO1);
2629 GATE_CLK(gpio2, pclk_cpu, PCLK_GPIO2);
2630 GATE_CLK(gpio6, pclk_cpu, PCLK_GPIO6);
2631 GATE_CLK(efuse, pclk_cpu, PCLK_EFUSE);
2632 GATE_CLK(tzpc, pclk_cpu, PCLK_TZPC);
2633 GATE_CLK(pclk_uart0, pclk_cpu, PCLK_UART0);
2634 GATE_CLK(pclk_uart1, pclk_cpu, PCLK_UART1);
2635 GATE_CLK(pclk_ddrupctl, pclk_cpu, PCLK_DDRUPCTL);
2636 GATE_CLK(pclk_ddrpubl, pclk_cpu, PCLK_PUBL);
2637 GATE_CLK(dbg, pclk_cpu, PCLK_DBG);
2638 GATE_CLK(grf, pclk_cpu, PCLK_GRF);
2639 GATE_CLK(pmu, pclk_cpu, PCLK_PMU);
2641 /*************************aclk_periph***********************/
2643 GATE_CLK(dma2, aclk_periph,ACLK_DMAC2);
2644 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
2645 GATE_CLK(aclk_peri_niu, aclk_periph, ACLK_PEI_NIU);
2646 GATE_CLK(aclk_cpu_peri, aclk_periph, ACLK_CPU_PERI);
2647 GATE_CLK(aclk_peri_axi_matrix, aclk_periph, ACLK_PERI_AXI_MATRIX);
2649 /*************************hclk_periph***********************/
2650 GATE_CLK(hclk_peri_axi_matrix, hclk_periph, HCLK_PERI_AXI_MATRIX);
2651 GATE_CLK(hclk_peri_ahb_arbi, hclk_periph, HCLK_PERI_AHB_ARBI);
2652 GATE_CLK(hclk_emem_peri, hclk_periph, HCLK_EMEM_PERI);
2653 GATE_CLK(hclk_mac, hclk_periph, HCLK_EMAC);
2654 GATE_CLK(nandc, hclk_periph, HCLK_NANDC);
2655 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
2656 GATE_CLK(hclk_otg0, clk_hclk_usb_peri, HCLK_OTG0);
2657 GATE_CLK(hclk_otg1, clk_hclk_usb_peri, HCLK_OTG1);
2658 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
2659 GATE_CLK(hclk_pidfilter, hclk_periph, HCLK_PIDF);
2660 GATE_CLK(hclk_sdmmc, hclk_periph, HCLK_SDMMC0);
2661 GATE_CLK(hclk_sdio, hclk_periph, HCLK_SDIO);
2662 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
2663 /*************************pclk_periph***********************/
2664 GATE_CLK(pclk_peri_axi_matrix, pclk_periph, PCLK_PERI_AXI_MATRIX);
2665 GATE_CLK(pwm23, pclk_periph, PCLK_PWM23);
2666 //GATE_CLK(pclk_pwm3, pclk_periph, PCLK_PWM3);
2667 GATE_CLK(wdt, pclk_periph, PCLK_WDT);
2668 GATE_CLK(pclk_spi0, pclk_periph, PCLK_SPI0);
2669 GATE_CLK(pclk_spi1, pclk_periph, PCLK_SPI1);
2670 GATE_CLK(pclk_uart2, pclk_periph, PCLK_UART2);
2671 GATE_CLK(pclk_uart3, pclk_periph, PCLK_UART3);
2672 GATE_CLK(i2c2, pclk_periph, PCLK_I2C2);
2673 GATE_CLK(i2c3, pclk_periph, PCLK_I2C3);
2674 GATE_CLK(i2c4, pclk_periph, PCLK_I2C4);
2675 GATE_CLK(gpio3, pclk_periph, PCLK_GPIO3);
2676 GATE_CLK(gpio4, pclk_periph, PCLK_GPIO4);
2677 GATE_CLK(pclk_saradc, pclk_periph, PCLK_SARADC);
2678 GATE_CLK(pclk_tsadc, pclk_periph, PCLK_TSADC);
2679 /*************************aclk_lcdc0***********************/
2680 GATE_CLK(aclk_lcdc0, aclk_lcdc0_ipp_parent, ACLK_LCDC0);
2681 GATE_CLK(aclk_vio0, aclk_lcdc0_ipp_parent, ACLK_VIO0);
2682 GATE_CLK(aclk_cif0, aclk_lcdc0_ipp_parent, ACLK_CIF0);
2683 GATE_CLK(aclk_ipp, aclk_lcdc0_ipp_parent, ACLK_IPP);
2685 /*************************aclk_lcdc0***********************/
2687 GATE_CLK(aclk_lcdc1, aclk_lcdc1_rga_parent, ACLK_LCDC1);
2688 GATE_CLK(aclk_vio1, aclk_lcdc1_rga_parent, ACLK_VIO1);
2689 GATE_CLK(aclk_cif1, aclk_lcdc1_rga_parent, ACLK_CIF0);
2690 GATE_CLK(aclk_rga, aclk_lcdc1_rga_parent, ACLK_RGA);
2694 #define CLK(dev, con, ck) \
2702 #define CLK1(name) \
2706 .clk = &clk_##name,\
2714 static struct clk_lookup clks[] = {
2715 CLK(NULL, "xin24m", &xin24m),
2716 CLK(NULL, "xin27m", &xin27m),
2717 CLK(NULL, "xin12m", &clk_12m),
2718 CLK(NULL, "arm_pll", &arm_pll_clk),
2719 CLK(NULL, "ddr_pll", &ddr_pll_clk),
2720 CLK(NULL, "codec_pll", &codec_pll_clk),
2721 CLK(NULL, "general_pll", &general_pll_clk),
2723 CLK(NULL, "ddr", &clk_ddr),
2724 //CLK(NULL, "core_gpll_path", &clk_cpu_gpll_path),
2725 CLK(NULL, "cpu", &clk_cpu),
2726 CLK(NULL, "arm_gpll", &clk_cpu_gpll_path),
2727 CLK("smp_twd", NULL, &core_periph),
2728 CLK(NULL, "aclk_cpu", &aclk_cpu),
2729 CLK(NULL, "hclk_cpu", &hclk_cpu),
2730 CLK(NULL, "pclk_cpu", &pclk_cpu),
2731 CLK(NULL, "atclk_cpu", &atclk_cpu),
2735 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
2736 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
2737 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
2738 CLK("rk29_i2s.0", "hclk_i2s", &clk_hclk_i2s_8ch),
2740 CLK("rk29_i2s.1", "i2s_div", &clk_i2s1_div),
2741 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s1_frac_div),
2742 CLK("rk29_i2s.1", "i2s", &clk_i2s1),
2743 CLK("rk29_i2s.1", "hclk_i2s", &clk_hclk_i2s0_2ch),
2745 CLK("rk29_i2s.2", "i2s_div", &clk_i2s2_div),
2746 CLK("rk29_i2s.2", "i2s_frac_div", &clk_i2s2_frac_div),
2747 CLK("rk29_i2s.2", "i2s", &clk_i2s2),
2748 CLK("rk29_i2s.2", "hclk_i2s", &clk_hclk_i2s1_2ch),
2751 CLK1(spdif_frac_div),
2755 CLK(NULL, "aclk_periph", &aclk_periph),
2756 CLK(NULL, "pclk_periph", &pclk_periph),
2757 CLK(NULL, "hclk_periph", &hclk_periph),
2759 CLK("rk29xx_spim.0", "spi", &clk_spi0),
2760 CLK("rk29xx_spim.0", "pclk_spi", &clk_pclk_spi0),
2762 CLK("rk29xx_spim.1", "spi", &clk_spi1),
2763 CLK("rk29xx_spim.1", "pclk_spi", &clk_pclk_spi1),
2771 CLK1(hclk_usb_peri),
2782 CLK("rk29_sdmmc.0", "mmc", &clk_sdmmc),
2783 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_sdmmc),
2784 CLK("rk29_sdmmc.1", "mmc", &clk_sdio),
2785 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_sdio),
2792 CLK("rk_serial.0", "uart_div", &clk_uart0_div),
2793 CLK("rk_serial.0", "uart_frac_div", &clk_uart0_frac_div),
2794 CLK("rk_serial.0", "uart", &clk_uart0),
2795 CLK("rk_serial.0", "pclk_uart", &clk_pclk_uart0),
2796 CLK("rk_serial.1", "uart_div", &clk_uart1_div),
2797 CLK("rk_serial.1", "uart_frac_div", &clk_uart1_frac_div),
2798 CLK("rk_serial.1", "uart", &clk_uart1),
2799 CLK("rk_serial.1", "pclk_uart", &clk_pclk_uart1),
2800 CLK("rk_serial.2", "uart_div", &clk_uart2_div),
2801 CLK("rk_serial.2", "uart_frac_div", &clk_uart2_frac_div),
2802 CLK("rk_serial.2", "uart", &clk_uart2),
2803 CLK("rk_serial.2", "pclk_uart", &clk_pclk_uart2),
2804 CLK("rk_serial.3", "uart_div", &clk_uart3_div),
2805 CLK("rk_serial.3", "uart_frac_div", &clk_uart3_frac_div),
2806 CLK("rk_serial.3", "uart", &clk_uart3),
2807 CLK("rk_serial.3", "pclk_uart", &clk_pclk_uart3),
2818 CLK(NULL, "rmii_clkin", &rmii_clkin),
2819 CLK(NULL, "mac_ref_div", &clk_mac_pll_div), // compatible with rk29
2822 CLK1(hsadc_pll_div),
2823 CLK1(hsadc_frac_div),
2828 CLK(NULL, "aclk_lcdc0_ipp_parent", &aclk_lcdc0_ipp_parent),
2829 CLK(NULL, "aclk_lcdc1_rga_parent", &aclk_lcdc1_rga_parent),
2831 CLK(NULL, "dclk_lcdc0_div", &dclk_lcdc0_div),
2832 CLK(NULL, "dclk_lcdc1_div", &dclk_lcdc1_div),
2834 CLK(NULL, "dclk_lcdc0", &dclk_lcdc0),
2835 CLK(NULL, "aclk_lcdc0", &clk_aclk_lcdc0),
2838 CLK(NULL, "dclk_lcdc1", &dclk_lcdc1),
2839 CLK(NULL, "aclk_lcdc1", &clk_aclk_lcdc1),
2842 CLK(NULL, "cif_out_pll", &cif_out_pll),
2843 CLK(NULL, "cif0_out_div", &cif0_out_div),
2844 CLK(NULL, "cif1_out_div", &cif1_out_div),
2846 CLK(NULL, "cif0_out", &cif0_out),
2849 CLK(NULL, "cif1_out", &cif1_out),
2856 CLK(NULL, "pclkin_cif0", &pclkin_cif0),
2857 CLK(NULL, "inv_cif0", &inv_cif0),
2858 CLK(NULL, "cif0_in", &cif0_in),
2859 CLK(NULL, "pclkin_cif1", &pclkin_cif1),
2860 CLK(NULL, "inv_cif1", &inv_cif1),
2861 CLK(NULL, "cif1_in", &cif1_in),
2862 //CLK(NULL, "aclk_lcdc0", &aclk_lcdc0),
2863 //CLK(NULL, "aclk_lcdc1", &aclk_lcdc1),
2864 CLK(NULL, "aclk_vepu", &aclk_vepu),
2865 CLK(NULL, "hclk_vepu", &hclk_vepu),
2866 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
2867 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
2873 CLK1(aclk_strc_sys),
2875 /*************************hclk_cpu***********************/
2878 //CLK1(hclk_i2s0_2ch),
2879 //CLK1(hclk_i2s1_2ch),
2881 //CLK1(hclk_i2s_8ch),
2892 //CLK1(hclk_vidoe_h2h, hclk_cpu, ); ???
2893 /*************************pclk_cpu***********************/
2894 CLK1(pwm01),//pwm 0¡¢1
2896 //CLK1(pclk_timer0),
2897 //CLK1(pclk_timer1),
2898 //CLK1(pclk_timer2),
2900 CLK("rk30_i2c.0", "i2c", &clk_i2c0),
2901 CLK("rk30_i2c.1", "i2c", &clk_i2c1),
2911 CLK1(pclk_ddrupctl),
2917 /*************************aclk_periph***********************/
2921 CLK1(aclk_peri_niu),
2922 CLK1(aclk_cpu_peri),
2923 CLK1(aclk_peri_axi_matrix),
2925 /*************************hclk_periph***********************/
2926 CLK1(hclk_peri_axi_matrix),
2927 CLK1(hclk_peri_ahb_arbi),
2928 CLK1(hclk_emem_peri),
2931 //CLK1(hclk_usb_peri),
2932 //CLK1(hclk_usbotg0),
2933 //CLK1(hclk_usbotg1),
2935 CLK1(hclk_pidfilter),
2938 /*************************pclk_periph***********************/
2939 CLK1(pclk_peri_axi_matrix),
2948 CLK("rk30_i2c.2", "i2c", &clk_i2c2),
2949 CLK("rk30_i2c.3", "i2c", &clk_i2c3),
2950 CLK("rk30_i2c.4", "i2c", &clk_i2c4),
2955 /*************************aclk_lcdc0***********************/
2960 /*************************aclk_lcdc0***********************/
2964 /************************power domain**********************/
2978 static void __init rk30_init_enable_clocks(void)
2980 //clk_enable_nolock(&xin24m);
2981 //clk_enable_nolock(&xin27m);
2982 //clk_enable_nolock(&clk_12m);
2983 //clk_enable_nolock(&arm_pll_clk);
2984 //clk_enable_nolock(&ddr_pll_clk);
2985 //clk_enable_nolock(&codec_pll_clk);
2986 //clk_enable_nolock(&general_pll_clk);
2987 //clk_enable_nolock(&clk_ddr);
2989 clk_enable_nolock(&clk_cpu);
2990 clk_enable_nolock(&core_periph);
2991 clk_enable_nolock(&aclk_cpu);
2992 clk_enable_nolock(&hclk_cpu);
2993 clk_enable_nolock(&pclk_cpu);
2994 clk_enable_nolock(&atclk_cpu);
2997 clk_enable_nolock(&clk_i2s_pll);
2998 clk_enable_nolock(&clk_i2s0_div);
2999 clk_enable_nolock(&clk_i2s0_frac_div);
3000 clk_enable_nolock(&clk_i2s0);
3001 clk_enable_nolock(&clk_hclk_i2s_8ch);
3003 clk_enable_nolock(&clk_i2s1_div);
3004 clk_enable_nolock(&clk_i2s1_frac_div);
3005 clk_enable_nolock(&clk_i2s1);
3006 clk_enable_nolock(&clk_hclk_i2s0_2ch);
3008 clk_enable_nolock(&clk_i2s2_div);
3009 clk_enable_nolock(&clk_i2s2_frac_div);
3010 clk_enable_nolock(&clk_i2s2);
3011 clk_enable_nolock(&clk_hclk_i2s1_2ch);
3013 clk_enable_nolock(&clk_spdif_div);
3014 clk_enable_nolock(&clk_spdif_frac_div);
3015 clk_enable_nolock(&clk_spdif);
3016 clk_enable_nolock(&clk_hclk_spdif);
3018 clk_enable_nolock(&aclk_periph);
3019 clk_enable_nolock(&pclk_periph);
3020 clk_enable_nolock(&hclk_periph);
3023 clk_enable_nolock(&clk_spi0);
3024 clk_enable_nolock(&clk_pclk_spi0);
3026 clk_enable_nolock(&clk_spi1);
3027 clk_enable_nolock(&clk_pclk_spi1);
3028 clk_enable_nolock(&clk_saradc);
3029 clk_enable_nolock(&clk_pclk_saradc);
3030 clk_enable_nolock(&clk_tsadc);
3031 clk_enable_nolock(&clk_pclk_tsadc);
3034 clk_enable_nolock(&clk_otgphy0);
3035 clk_enable_nolock(&clk_otgphy1);
3036 clk_enable_nolock(&clk_hclk_usb_peri);
3037 clk_enable_nolock(&clk_hclk_otg0);
3038 clk_enable_nolock(&clk_hclk_otg1);
3041 clk_enable_nolock(&clk_smc);
3042 clk_enable_nolock(&clk_aclk_smc);
3044 clk_enable_nolock(&clk_sdmmc);
3045 clk_enable_nolock(&clk_hclk_sdmmc);
3046 clk_enable_nolock(&clk_sdio);
3047 clk_enable_nolock(&clk_hclk_sdio);
3049 clk_enable_nolock(&clk_emmc);
3050 clk_enable_nolock(&clk_hclk_emmc);
3054 #if CONFIG_RK_DEBUG_UART == 0
3055 clk_enable_nolock(&clk_uart0);
3056 clk_enable_nolock(&clk_pclk_uart0);
3057 #elif CONFIG_RK_DEBUG_UART == 1
3058 clk_enable_nolock(&clk_uart1);
3059 clk_enable_nolock(&clk_pclk_uart1);
3061 #elif CONFIG_RK_DEBUG_UART == 2
3062 clk_enable_nolock(&clk_uart2);
3063 clk_enable_nolock(&clk_pclk_uart2);
3065 #elif CONFIG_RK_DEBUG_UART == 3
3066 clk_enable_nolock(&clk_uart3);
3067 clk_enable_nolock(&clk_pclk_uart3);
3072 clk_enable_nolock(&clk_timer0);
3073 clk_enable_nolock(&clk_pclk_timer0);
3075 clk_enable_nolock(&clk_timer1);
3076 clk_enable_nolock(&clk_pclk_timer1);
3078 clk_enable_nolock(&clk_timer2);
3079 clk_enable_nolock(&clk_pclk_timer2);
3082 clk_enable_nolock(&rmii_clkin);
3083 clk_enable_nolock(&clk_mac_pll_div);
3084 clk_enable_nolock(&clk_mac_ref);
3085 clk_enable_nolock(&clk_mii_tx);
3089 clk_enable_nolock(&clk_hsadc_pll_div);
3090 clk_enable_nolock(&clk_hsadc_frac_div);
3091 clk_enable_nolock(&clk_hsadc_ext);
3092 clk_enable_nolock(&clk_hsadc);
3093 clk_enable_nolock(&clk_hclk_hsadc);
3097 clk_enable_nolock(&aclk_lcdc0_ipp_parent);
3098 clk_enable_nolock(&aclk_lcdc1_rga_parent);
3100 clk_enable_nolock(&dclk_lcdc0_div);
3101 clk_enable_nolock(&dclk_lcdc1_div);
3103 clk_enable_nolock(&dclk_lcdc0);
3104 clk_enable_nolock(&clk_aclk_lcdc0);
3105 clk_enable_nolock(&clk_hclk_lcdc0);
3107 clk_enable_nolock(&dclk_lcdc1);
3108 clk_enable_nolock(&clk_aclk_lcdc1);
3109 clk_enable_nolock(&clk_hclk_lcdc1);
3111 clk_enable_nolock(&cif_out_pll);
3112 clk_enable_nolock(&cif0_out_div);
3113 clk_enable_nolock(&cif1_out_div);
3115 clk_enable_nolock(&cif0_out);
3116 clk_enable_nolock(&clk_hclk_cif0);
3118 clk_enable_nolock(&cif1_out);
3119 clk_enable_nolock(&clk_hclk_cif1);
3121 clk_enable_nolock(&clk_hclk_ipp);
3122 clk_enable_nolock(&clk_hclk_rga);
3123 clk_enable_nolock(&clk_hclk_hdmi);
3125 clk_enable_nolock(&pclkin_cif0);
3126 clk_enable_nolock(&inv_cif0);
3127 clk_enable_nolock(&cif0_in);
3128 clk_enable_nolock(&pclkin_cif1);
3129 clk_enable_nolock(&inv_cif1);
3130 clk_enable_nolock(&cif1_in);
3131 //CLK(NULL, "aclk_lcdc0", &aclk_lcdc0),
3132 //CLK(NULL, "aclk_lcdc1", &aclk_lcdc1),
3133 clk_enable_nolock(&aclk_vepu);
3134 clk_enable_nolock(&hclk_vepu);
3135 clk_enable_nolock(&aclk_vdpu);
3136 clk_enable_nolock(&hclk_vdpu);
3137 clk_enable_nolock(&clk_gpu);
3140 clk_enable_nolock(&clk_dma1);
3141 clk_enable_nolock(&clk_l2mem_con);
3142 clk_enable_nolock(&clk_intmem);
3144 clk_enable_nolock(&clk_aclk_strc_sys);
3146 /*************************hclk_cpu***********************/
3148 clk_enable_nolock(&clk_rom);
3150 clk_enable_nolock(&clk_hclk_cpubus);
3151 clk_enable_nolock(&clk_hclk_ahb2apb);
3152 clk_enable_nolock(&clk_hclk_vio_bus);
3154 /*************************pclk_cpu***********************/
3156 //clk_enable_nolock(&clk_pwm01);//pwm 0¡¢1
3160 clk_enable_nolock(&clk_i2c0);
3161 clk_enable_nolock(&clk_i2c1);
3163 clk_enable_nolock(&clk_gpio0);
3164 clk_enable_nolock(&clk_gpio1);
3165 clk_enable_nolock(&clk_gpio2);
3166 clk_enable_nolock(&clk_gpio6);
3167 clk_enable_nolock(&clk_efuse);
3169 clk_enable_nolock(&clk_tzpc);
3173 clk_enable_nolock(&clk_pclk_ddrupctl);
3174 clk_enable_nolock(&clk_pclk_ddrpubl);
3175 clk_enable_nolock(&clk_dbg);
3176 clk_enable_nolock(&clk_grf);
3177 clk_enable_nolock(&clk_pmu);
3179 /*************************aclk_periph***********************/
3181 clk_enable_nolock(&clk_dma2);
3183 clk_enable_nolock(&clk_aclk_peri_niu);
3184 clk_enable_nolock(&clk_aclk_cpu_peri);
3185 clk_enable_nolock(&clk_aclk_peri_axi_matrix);
3187 /*************************hclk_periph***********************/
3188 clk_enable_nolock(&clk_hclk_peri_axi_matrix);
3189 clk_enable_nolock(&clk_hclk_peri_ahb_arbi);
3190 clk_enable_nolock(&clk_hclk_emem_peri);
3191 clk_enable_nolock(&clk_hclk_mac);
3192 clk_enable_nolock(&clk_nandc);
3193 //CLK1(hclk_usb_peri),
3194 //CLK1(hclk_usbotg0),
3195 //CLK1(hclk_usbotg1),
3197 clk_enable_nolock(&clk_hclk_pidfilter);
3199 /*************************pclk_periph***********************/
3200 clk_enable_nolock(&clk_pclk_peri_axi_matrix);
3201 //clk_enable_nolock(&clk_pwm23);
3203 //clk_enable_nolock(&clk_wdt);
3207 clk_enable_nolock(&clk_i2c2);
3208 clk_enable_nolock(&clk_i2c3);
3209 clk_enable_nolock(&clk_i2c4);
3211 clk_enable_nolock(&clk_gpio3);
3212 clk_enable_nolock(&clk_gpio4);
3214 /*************************aclk_lcdc0***********************/
3215 //clk_enable_nolock(&clk_aclk_vio0);
3216 //clk_enable_nolock(&clk_aclk_cif0);
3217 //clk_enable_nolock(&clk_aclk_ipp);
3219 /*************************aclk_lcdc0***********************/
3220 //clk_enable_nolock(&clk_aclk_vio1);
3221 //clk_enable_nolock(&clk_aclk_cif1);
3222 //clk_enable_nolock(&clk_aclk_rga);
3223 /************************power domain**********************/
3225 static void periph_clk_set_init(void)
3227 unsigned long aclk_p, hclk_p, pclk_p;
3228 unsigned long ppll_rate=general_pll_clk.rate;
3232 switch (ppll_rate) {
3234 aclk_p = 148500*KHZ;
3239 aclk_p = aclk_p>>3;// 0
3244 aclk_p = ppll_rate>>1;
3250 aclk_p = ppll_rate>>1;
3260 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3261 clk_set_rate_nolock(&aclk_periph, aclk_p);
3262 clk_set_rate_nolock(&hclk_periph, hclk_p);
3263 clk_set_rate_nolock(&pclk_periph, pclk_p);
3267 void rk30_clock_common_i2s_init(void)
3269 struct clk *max_clk,*min_clk;
3270 unsigned long i2s_rate;
3272 if(rk30_clock_flags&CLK_FLG_MAX_I2S_49152KHZ)
3275 }else if(rk30_clock_flags&CLK_FLG_MAX_I2S_24576KHZ)
3279 else if(rk30_clock_flags&CLK_FLG_MAX_I2S_22579_2KHZ)
3283 else if(rk30_clock_flags&CLK_FLG_MAX_I2S_12288KHZ)
3292 if(((i2s_rate*20)<=general_pll_clk.rate)||!(general_pll_clk.rate%i2s_rate))
3294 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3296 else if(((i2s_rate*20)<=codec_pll_clk.rate)||!(codec_pll_clk.rate%i2s_rate))
3298 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3302 if(general_pll_clk.rate>codec_pll_clk.rate)
3303 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3305 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3314 static void __init rk30_clock_common_init(unsigned long gpll_rate,unsigned long cpll_rate)
3317 clk_set_rate_nolock(&clk_cpu, 816*MHZ);//816
3319 clk_set_rate_nolock(&general_pll_clk, gpll_rate);
3321 clk_set_rate_nolock(&codec_pll_clk, cpll_rate);
3324 periph_clk_set_init();
3327 rk30_clock_common_i2s_init();
3330 clk_set_rate_nolock(&clk_spi0, clk_spi0.parent->rate);
3331 clk_set_rate_nolock(&clk_spi1, clk_spi1.parent->rate);
3334 if(rk30_clock_flags&CLK_FLG_UART_1_3M)
3335 clk_set_parent_nolock(&clk_uart_pll, &codec_pll_clk);
3337 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3339 if(!(gpll_rate%(50*MHZ)))
3340 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3341 else if(!(ddr_pll_clk.rate%(50*MHZ)))
3342 clk_set_parent_nolock(&clk_mac_pll_div, &ddr_pll_clk);
3344 CRU_PRINTK_ERR("mac can't get 50mhz\n");
3348 //clk_set_parent_nolock(&clk_hsadc_pll_div, &general_pll_clk);
3351 clk_set_parent_nolock(&dclk_lcdc1_div, &general_pll_clk);
3353 //lcdc0 lcd auto sel pll
3354 //clk_set_parent_nolock(&dclk_lcdc0_div, &general_pll_clk);
3357 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3360 //clk_set_parent_nolock(&aclk_lcdc0, &general_pll_clk);
3361 //clk_set_parent_nolock(&aclk_lcdc1, &general_pll_clk);
3362 clk_set_rate_nolock(&aclk_lcdc0_ipp_parent, 300*MHZ);
3363 clk_set_rate_nolock(&aclk_lcdc1_rga_parent, 300*MHZ);
3366 //clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
3367 //clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
3369 clk_set_rate_nolock(&aclk_vepu, 300*MHZ);
3370 clk_set_rate_nolock(&aclk_vdpu, 300*MHZ);
3372 //clk_set_parent_nolock(&clk_gpu, &general_pll_clk);
3375 static struct clk def_ops_clk={
3376 .get_parent=clksel_get_parent,
3377 .set_parent=clksel_set_parent,
3380 #ifdef CONFIG_PROC_FS
3381 struct clk_dump_ops dump_ops;
3384 static void clk_dump_regs(void);
3386 void __init _rk30_clock_data_init(unsigned long gpll,unsigned long cpll,int flags)
3388 struct clk_lookup *lk;
3390 clk_register_dump_ops(&dump_ops);
3391 clk_register_default_ops_clk(&def_ops_clk);
3392 rk30_clock_flags=flags;
3393 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
3394 #ifdef RK30_CLK_OFFBOARD_TEST
3395 rk30_clkdev_add(lk);
3399 clk_register(lk->clk);
3401 clk_recalculate_root_clocks_nolock();
3403 loops_per_jiffy = CLK_LOOPS_RECALC(arm_pll_clk.rate);
3406 * Only enable those clocks we will need, let the drivers
3407 * enable other clocks as necessary
3409 rk30_init_enable_clocks();
3412 * Disable any unused clocks left on by the bootloader
3414 //clk_disable_unused();
3415 rk30_clock_common_init(gpll,cpll);
3416 preset_lpj = loops_per_jiffy;
3419 //regfile_writel(0xc0004000,0x10c);
3420 //cru_writel(0x07000000,CRU_MISC_CON);
3424 void __init rk30_clock_data_init(unsigned long gpll,unsigned long cpll,u32 flags)
3426 _rk30_clock_data_init(gpll,cpll,flags);
3431 * You can override arm_clk rate with armclk= cmdline option.
3433 static int __init armclk_setup(char *str)
3435 get_option(&str, &armclk);
3441 //clk_set_rate_nolock(&arm_pll_clk, armclk);
3444 #ifndef RK30_CLK_OFFBOARD_TEST
3445 early_param("armclk", armclk_setup);
3450 #ifdef CONFIG_PROC_FS
3452 static void dump_clock(struct seq_file *s, struct clk *clk, int deep,const struct list_head *root_clocks)
3456 unsigned long rate = clk->rate;
3457 //CRU_PRINTK_DBG("dump_clock %s\n",clk->name);
3458 for (i = 0; i < deep; i++)
3461 seq_printf(s, "%-11s ", clk->name);
3462 #ifndef RK30_CLK_OFFBOARD_TEST
3463 if (clk->flags & IS_PD) {
3464 seq_printf(s, "%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3467 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3468 int idx = clk->gate_idx;
3470 v = cru_readl(CLK_GATE_CLKID_CONS(idx))&((0x1)<<(idx%16));
3471 seq_printf(s, "%s ", v ? "off" : "on ");
3477 u32 pll_id=clk->pll->id;
3478 pll_mode=cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3479 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3480 seq_printf(s, "slow ");
3481 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3482 seq_printf(s, "normal ");
3483 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3484 seq_printf(s, "deep ");
3486 if(cru_readl(PLL_CONS(pll_id,3)) & PLL_BYPASS)
3487 seq_printf(s, "bypass ");
3489 else if(clk == &clk_ddr) {
3490 rate = clk->recalc(clk);
3495 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3497 seq_printf(s, "%ld MHz", rate / MHZ);
3498 } else if (rate >= KHZ) {
3500 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3502 seq_printf(s, "%ld KHz", rate / KHZ);
3504 seq_printf(s, "%ld Hz", rate);
3507 seq_printf(s, " usecount = %d", clk->usecount);
3510 seq_printf(s, " parent = %s", clk->parent->name);
3512 seq_printf(s, "\n");
3514 list_for_each_entry(ck, root_clocks, node) {
3515 if (ck->parent == clk)
3516 dump_clock(s, ck, deep + 1,root_clocks);
3520 static void dump_regs(struct seq_file *s)
3523 seq_printf(s, "\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3524 seq_printf(s, "\nPLLRegisters:\n");
3525 for(i=0;i<END_PLL_ID;i++)
3527 seq_printf(s,"pll%d :cons:%x,%x,%x,%x\n",i,
3528 cru_readl(PLL_CONS(i,0)),
3529 cru_readl(PLL_CONS(i,1)),
3530 cru_readl(PLL_CONS(i,2)),
3531 cru_readl(PLL_CONS(i,3))
3534 seq_printf(s, "MODE :%x\n", cru_readl(CRU_MODE_CON));
3536 for(i=0;i<CRU_CLKSELS_CON_CNT;i++)
3538 seq_printf(s,"CLKSEL%d :%x\n",i,cru_readl(CRU_CLKSELS_CON(i)));
3540 for(i=0;i<CRU_CLKGATES_CON_CNT;i++)
3542 seq_printf(s,"CLKGATE%d :%x\n",i,cru_readl(CRU_CLKGATES_CON(i)));
3544 seq_printf(s,"GLB_SRST_FST:%x\n",cru_readl(CRU_GLB_SRST_FST));
3545 seq_printf(s,"GLB_SRST_SND:%x\n",cru_readl(CRU_GLB_SRST_SND));
3547 for(i=0;i<CRU_SOFTRSTS_CON_CNT;i++)
3549 seq_printf(s,"CLKGATE%d :%x\n",i,cru_readl(CRU_SOFTRSTS_CON(i)));
3551 seq_printf(s,"CRU MISC :%x\n",cru_readl(CRU_MISC_CON));
3552 seq_printf(s,"GLB_CNT_TH :%x\n",cru_readl(CRU_GLB_CNT_TH));
3556 void rk30_clk_dump_regs(void)
3559 printk("\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3560 printk("\nPLLRegisters:\n");
3561 for(i=0;i<END_PLL_ID;i++)
3563 printk("pll%d :cons:%x,%x,%x,%x\n",i,
3564 cru_readl(PLL_CONS(i,0)),
3565 cru_readl(PLL_CONS(i,1)),
3566 cru_readl(PLL_CONS(i,2)),
3567 cru_readl(PLL_CONS(i,3))
3570 printk("MODE :%x\n", cru_readl(CRU_MODE_CON));
3572 for(i=0;i<CRU_CLKSELS_CON_CNT;i++)
3574 printk("CLKSEL%d :%x\n",i,cru_readl(CRU_CLKSELS_CON(i)));
3576 for(i=0;i<CRU_CLKGATES_CON_CNT;i++)
3578 printk("CLKGATE%d :%x\n",i,cru_readl(CRU_CLKGATES_CON(i)));
3580 printk("GLB_SRST_FST:%x\n",cru_readl(CRU_GLB_SRST_FST));
3581 printk("GLB_SRST_SND:%x\n",cru_readl(CRU_GLB_SRST_SND));
3583 for(i=0;i<CRU_SOFTRSTS_CON_CNT;i++)
3585 printk("SOFTRST%d :%x\n",i,cru_readl(CRU_SOFTRSTS_CON(i)));
3587 printk("CRU MISC :%x\n",cru_readl(CRU_MISC_CON));
3588 printk("GLB_CNT_TH :%x\n",cru_readl(CRU_GLB_CNT_TH));
3593 #ifdef CONFIG_PROC_FS
3594 static void dump_clock(struct seq_file *s, struct clk *clk, int deep,const struct list_head *root_clocks);
3595 struct clk_dump_ops dump_ops={
3596 .dump_clk=dump_clock,
3597 .dump_regs=dump_regs,
3602 #endif /* CONFIG_PROC_FS */
3607 #ifdef RK30_CLK_OFFBOARD_TEST
3608 struct clk *test_get_parent(struct clk *clk)
3615 struct clk *i2s_clk=&clk_i2s0;
3617 clk_enable_nolock(i2s_clk);
3619 clk_set_rate_nolock(i2s_clk, 12288000);
3620 printk("int %s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3621 clk_set_rate_nolock(i2s_clk, 297*MHZ/2);
3622 printk("int%s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3623 clk_set_rate_nolock(i2s_clk, 12*MHZ);
3624 printk("int%s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3628 void uart_test(void)
3630 struct clk *uart_clk=&clk_uart0;
3632 clk_enable_nolock(uart_clk);
3634 clk_set_rate_nolock(uart_clk, 12288000);
3635 printk("int %s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3636 clk_set_rate_nolock(uart_clk, 297*MHZ/2);
3637 printk("int%s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3638 clk_set_rate_nolock(uart_clk, 12*MHZ);
3639 printk("int%s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3642 void hsadc_test(void)
3644 struct clk *hsadc_clk=&clk_hsadc;
3646 printk("******************hsadc_test**********************\n");
3647 clk_enable_nolock(hsadc_clk);
3649 clk_set_rate_nolock(hsadc_clk, 12288000);
3650 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3653 clk_set_rate_nolock(hsadc_clk, 297*MHZ/2);
3654 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3656 clk_set_rate_nolock(hsadc_clk, 300*MHZ/2);
3658 clk_set_rate_nolock(hsadc_clk, 296*MHZ/2);
3660 printk("******************hsadc out clock**********************\n");
3662 clk_set_parent_nolock(hsadc_clk, &clk_hsadc_ext);
3663 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3664 clk_set_rate_nolock(hsadc_clk, 297*MHZ/2);
3665 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3671 static void __init rk30_clock_test_init(unsigned long ppll_rate)
3674 printk("*********arm_pll_clk***********\n");
3675 clk_set_rate_nolock(&arm_pll_clk, 816*MHZ);
3677 printk("*********set clk_cpu parent***********\n");
3678 clk_set_parent_nolock(&clk_cpu, &arm_pll_clk);
3679 clk_set_rate_nolock(&clk_cpu, 504*MHZ);
3682 printk("*********general_pll_clk***********\n");
3683 clk_set_rate_nolock(&general_pll_clk, ppll_rate);
3686 printk("*********codec_pll_clk***********\n");
3687 clk_set_rate_nolock(&codec_pll_clk, 600*MHZ);
3690 printk("*********periph_clk_set_init***********\n");
3691 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3692 periph_clk_set_init();
3695 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3697 printk("*********clk i2s***********\n");
3698 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3699 printk("common %s parent is %s\n",clk_i2s_pll.name,test_get_parent(&clk_i2s_pll)->name);
3703 clk_enable_nolock(&clk_spi0);
3704 clk_set_rate_nolock(&clk_spi0, 30*MHZ);
3705 printk("common %s parent is %s\n",clk_spi0.name,test_get_parent(&clk_spi0)->name);
3707 clk_enable_nolock(&clk_saradc);
3708 clk_set_rate_nolock(&clk_saradc, 6*MHZ);
3709 printk("common %s parent is %s\n",clk_saradc.name,test_get_parent(&clk_saradc)->name);
3711 clk_enable_nolock(&clk_sdio);
3712 clk_set_rate_nolock(&clk_sdio, 50*MHZ);
3713 printk("common %s parent is %s\n",clk_sdio.name,test_get_parent(&clk_sdio)->name);
3715 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3718 printk("*********mac***********\n");
3720 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3721 printk("common %s parent is %s\n",clk_mac_pll_div.name,test_get_parent(&clk_mac_pll_div)->name);
3723 //clk_set_parent_nolock(&clk_mac_ref, &clk_mac_pll_div);
3724 clk_set_rate_nolock(&clk_mac_ref, 50*MHZ);
3725 printk("common %s parent is %s\n",clk_mac_ref.name,test_get_parent(&clk_mac_ref)->name);
3727 printk("*********mac mii set***********\n");
3728 clk_set_parent_nolock(&clk_mac_ref, &rmii_clkin);
3729 clk_set_rate_nolock(&clk_mac_ref, 20*MHZ);
3730 printk("common %s parent is %s\n",clk_mac_ref.name,test_get_parent(&clk_mac_ref)->name);
3732 printk("*********hsadc 1***********\n");
3736 clk_enable_nolock(&dclk_lcdc0);
3738 clk_set_rate_nolock(&dclk_lcdc0, 60*MHZ);
3739 clk_set_rate_nolock(&dclk_lcdc0, 27*MHZ);
3742 clk_enable_nolock(&cif0_out);
3744 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3745 printk("common %s parent is %s\n",cif_out_pll.name,test_get_parent(&cif_out_pll)->name);
3747 clk_set_rate_nolock(&cif0_out, 60*MHZ);
3748 printk("common %s parent is %s\n",cif0_out.name,test_get_parent(&cif0_out)->name);
3750 clk_set_rate_nolock(&cif0_out, 24*MHZ);
3751 printk("common %s parent is %s\n",cif0_out.name,test_get_parent(&cif0_out)->name);
3753 clk_enable_nolock(&cif0_in);
3754 clk_set_rate_nolock(&cif0_in, 24*MHZ);
3756 clk_enable_nolock(&aclk_lcdc0);
3757 clk_set_rate_nolock(&aclk_lcdc0, 150*MHZ);
3758 printk("common %s parent is %s\n",aclk_lcdc0.name,test_get_parent(&aclk_lcdc0)->name);
3760 clk_enable_nolock(&aclk_vepu);
3761 clk_set_rate_nolock(&aclk_vepu, 300*MHZ);
3762 printk("common %s parent is %s\n",aclk_vepu.name,test_get_parent(&aclk_vepu)->name);
3764 clk_set_rate_nolock(&hclk_vepu, 300*MHZ);
3765 printk("common %s parent is %s\n",hclk_vepu.name,test_get_parent(&hclk_vepu)->name);
3767 printk("test end\n");
3770 clk_set_rate_nolock(&arm_pll_clk, armclk);
3771 clk_set_rate_nolock(&clk_cpu, armclk);//pll:core =1:1
3774 //clk_set_rate_nolock(&codec_pll_clk, ppll_rate*2);
3776 //clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3777 //clk_set_rate_nolock(&clk_gpu, 300 * MHZ);
3785 static LIST_HEAD(rk30_clocks);
3786 static DEFINE_MUTEX(rk30_clocks_mutex);
3788 static inline int __rk30clk_get(struct clk *clk)
3792 void rk30_clkdev_add(struct clk_lookup *cl)
3794 mutex_lock(&rk30_clocks_mutex);
3795 list_add_tail(&cl->node, &rk30_clocks);
3796 mutex_unlock(&rk30_clocks_mutex);
3798 static struct clk_lookup *rk30_clk_find(const char *dev_id, const char *con_id)
3800 struct clk_lookup *p, *cl = NULL;
3801 int match, best = 0;
3803 list_for_each_entry(p, &rk30_clocks, node) {
3806 if (!dev_id || strcmp(p->dev_id, dev_id))
3811 if (!con_id || strcmp(p->con_id, con_id))
3827 struct clk *rk30_clk_get_sys(const char *dev_id, const char *con_id)
3829 struct clk_lookup *cl;
3831 mutex_lock(&rk30_clocks_mutex);
3832 cl = rk30_clk_find(dev_id, con_id);
3833 if (cl && !__rk30clk_get(cl->clk))
3835 mutex_unlock(&rk30_clocks_mutex);
3837 return cl ? cl->clk : ERR_PTR(-ENOENT);
3839 //EXPORT_SYMBOL(rk30_clk_get_sys);
3841 struct clk *rk30_clk_get(struct device *dev, const char *con_id)
3843 const char *dev_id = dev ? dev_name(dev) : NULL;
3844 return rk30_clk_get_sys(dev_id, con_id);
3846 //EXPORT_SYMBOL(rk30_clk_get);
3849 int rk30_clk_set_rate(struct clk *clk, unsigned long rate);
3851 void rk30_clocks_test(void)
3853 struct clk *test_gpll;
3854 test_gpll=rk30_clk_get(NULL,"general_pll");
3857 rk30_clk_set_rate(test_gpll,297*2*MHZ);
3858 printk("gpll rate=%lu\n",test_gpll->rate);
3863 void __init rk30_clock_init_test(void){
3865 rk30_clock_init(periph_pll_297mhz,codec_pll_360mhz,max_i2s_12288khz);