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>
28 #include <mach/dvfs.h>
30 #define MHZ (1000*1000)
32 #define CLK_LOOPS_JIFFY_REF 11996091ULL
33 #define CLK_LOOPS_RATE_REF (1200) //Mhz
34 #define CLK_LOOPS_RECALC(new_rate) div_u64(CLK_LOOPS_JIFFY_REF*(new_rate),CLK_LOOPS_RATE_REF*MHZ)
38 #define CLK_FLG_EXT_27MHZ (1<<0)
40 #define CLK_FLG_MAX_I2S_12288KHZ (1<<1)
41 #define CLK_FLG_MAX_I2S_22579_2KHZ (1<<2)
42 #define CLK_FLG_MAX_I2S_24576KHZ (1<<3)
43 #define CLK_FLG_MAX_I2S_49152KHZ (1<<4)
51 u32 pllcon2; //nb=bwadj+1;0:11;nb=nf/2
61 u32 pllcon2; //nb=bwadj+1;0:11;nb=nf/2
65 #define SET_PLL_DATA(_pll_id,_table) \
72 #define _PLL_SET_CLKS(_mhz, nr, nf, no) \
74 .rate = (_mhz) * KHZ, \
75 .pllcon0 = PLL_CLKR_SET(nr)|PLL_CLKOD_SET(no), \
76 .pllcon1 = PLL_CLKF_SET(nf),\
77 .pllcon2 = PLL_CLK_BWADJ_SET(nf/2-1),\
78 .rst_dly=((nr*500)/24+1),\
82 #define _APLL_SET_LPJ(_mhz) \
83 .lpj= (CLK_LOOPS_JIFFY_REF * _mhz)/CLK_LOOPS_RATE_REF
86 #define _APLL_SET_CLKS(_mhz, nr, nf, no, _periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
89 .pllcon0 = PLL_CLKR_SET(nr)|PLL_CLKOD_SET(no),\
90 .pllcon1 = PLL_CLKF_SET(nf),\
91 .pllcon2 = PLL_CLK_BWADJ_SET(nf>>1),\
92 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
93 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
94 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
95 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
96 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
98 .rst_dly=((nr*500)/24+1),\
101 #define CRU_DIV_SET(mask,shift,max) \
107 #define CRU_SRC_SET(mask,shift ) \
111 #define CRU_PARENTS_SET(parents_array) \
112 .parents=(parents_array),\
113 .parents_num=ARRAY_SIZE((parents_array))
115 #define CRU_GATE_MODE_SET(_func,_IDX) \
126 #define GATE_CLK(NAME,PARENT,ID) \
127 static struct clk clk_##NAME = { \
131 .gate_idx = CLK_GATE_##ID, \
133 #ifdef RK30_CLK_OFFBOARD_TEST
134 u32 TEST_GRF_REG[0x240];
135 u32 TEST_CRU_REG[0x240];
136 #define cru_readl(offset) (TEST_CRU_REG[offset/4])
138 u32 cru_writel_is_pr(u32 offset)
140 return (offset==0x4000);
142 void cru_writel(u32 v, u32 offset)
146 TEST_CRU_REG[offset/4]&=(~mask_v);
150 TEST_CRU_REG[offset/4]|=v;
151 TEST_CRU_REG[offset/4]&=0x0000ffff;
153 if(cru_writel_is_pr(offset))
155 CRU_PRINTK_DBG("cru w offset=%d,set=%x,reg=%x\n",offset,v,TEST_CRU_REG[offset/4]);
160 void cru_writel_i2s(u32 v, u32 offset)
162 TEST_CRU_REG[offset/4]=v;
164 #define cru_writel_frac(v,offset) cru_writel_i2s((v),(offset))
166 #define regfile_readl(offset) (0xffffffff)
167 //#define pmu_readl(offset) readl(RK30_GRF_BASE + offset)
168 void rk30_clkdev_add(struct clk_lookup *cl);
170 #define regfile_readl(offset) readl_relaxed(RK30_GRF_BASE + offset)
171 #define regfile_writel(v, offset) do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
172 #define cru_readl(offset) readl_relaxed(RK30_CRU_BASE + offset)
173 #define cru_writel(v, offset) do { writel_relaxed(v, RK30_CRU_BASE + offset); dsb(); } while (0)
175 #define cru_writel_frac(v,offset) cru_writel((v),(offset))
179 #define CRU_PRINTK_DBG(fmt, args...) pr_debug(fmt, ## args)
180 #define CRU_PRINTK_LOG(fmt, args...) pr_debug(fmt, ## args)
182 #define CRU_PRINTK_DBG(fmt, args...) do {} while(0)
183 #define CRU_PRINTK_LOG(fmt, args...) do {} while(0)
185 #define CRU_PRINTK_ERR(fmt, args...) pr_err(fmt, ## args)
188 #define get_cru_bits(con,mask,shift)\
189 ((cru_readl((con)) >> (shift)) & (mask))
191 #define set_cru_bits_w_msk(val,mask,shift,con)\
192 cru_writel(((mask)<<(shift+16))|((val)<<(shift)),(con))
195 #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)))\
196 &&!(cru_readl(PLL_CONS(pll_id,3))&PLL_BYPASS))
199 static u32 rk30_clock_flags=0;
200 static struct clk codec_pll_clk;
201 static struct clk general_pll_clk;
202 static struct clk arm_pll_clk;
203 static unsigned long lpj_gpll;
204 static unsigned int __initdata armclk = 504*MHZ;
207 /************************clk recalc div rate*********************************/
210 static unsigned long clksel_recalc_div(struct clk *clk)
212 u32 div = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift) + 1;
214 unsigned long rate = clk->parent->rate / div;
215 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
220 static unsigned long clksel_recalc_shift(struct clk *clk)
222 u32 shift = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift);
223 unsigned long rate = clk->parent->rate >> shift;
224 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
229 static unsigned long clksel_recalc_shift_2(struct clk *clk)
231 u32 shift = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1;
232 unsigned long rate = clk->parent->rate >> shift;
233 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
237 static unsigned long clksel_recalc_parent_rate(struct clk *clk)
239 unsigned long rate = clk->parent->rate;
240 pr_debug("%s new clock rate is %lu\n", clk->name, rate);
243 /********************************set div rate***********************************/
246 static int clksel_set_rate_freediv(struct clk *clk, unsigned long rate)
249 for (div = 0; div < clk->div_max; div++) {
250 u32 new_rate = clk->parent->rate / (div + 1);
251 if (new_rate <= rate) {
252 set_cru_bits_w_msk(div,clk->div_mask,clk->div_shift,clk->clksel_con);
253 //clk->rate = new_rate;
254 pr_debug("clksel_set_rate_freediv for clock %s to rate %ld (div %d)\n", clk->name, rate, div + 1);
262 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
265 for (shift = 0; (1 << shift) < clk->div_max; shift++) {
266 u32 new_rate = clk->parent->rate >> shift;
267 if (new_rate <= rate) {
268 set_cru_bits_w_msk(shift,clk->div_mask,clk->div_shift,clk->clksel_con);
269 clk->rate = new_rate;
270 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
278 static int clksel_set_rate_shift_2(struct clk *clk, unsigned long rate)
282 for (shift = 1; (1 << shift) < clk->div_max; shift++) {
283 u32 new_rate = clk->parent->rate >> shift;
284 if (new_rate <= rate) {
285 set_cru_bits_w_msk(shift-1,clk->div_mask,clk->div_shift,clk->clksel_con);
286 clk->rate = new_rate;
287 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n", clk->name, rate, shift);
293 static u32 clk_get_freediv(unsigned long rate_out, unsigned long rate ,u32 div_max)
296 unsigned long new_rate;
297 for (div = 0; div <div_max; div++) {
298 new_rate = rate / (div + 1);
299 if (new_rate <= rate_out) {
303 return div_max?div_max:1;
305 struct clk *get_freediv_parents_div(struct clk *clk,unsigned long rate,u32 *div_out)
308 unsigned long new_rate[2]={0,0};
315 div[i]=clk_get_freediv(rate,clk->parents[i]->rate,clk->div_max);
316 new_rate[i] = clk->parents[i]->rate/div[i];
317 if(new_rate[i]==rate)
320 return clk->parents[i];
323 if(new_rate[0]<new_rate[1])
328 return clk->parents[i];
331 static int clkset_rate_freediv_autosel_parents(struct clk *clk, unsigned long rate)
338 p_clk=get_freediv_parents_div(clk,rate,&div);
343 CRU_PRINTK_DBG("%s %lu,form %s\n",clk->name,rate,p_clk->name);
344 if (clk->parent != p_clk)
346 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),clk->div_shift,clk->div_mask)+1;
350 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
352 ret=clk_set_parent_nolock(clk,p_clk);
355 CRU_PRINTK_ERR("%s can't set %lu,reparent err\n",clk->name,rate);
360 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
364 //rate==div rate //hdmi
365 static int clk_freediv_autosel_parents_set_fixed_rate(struct clk *clk, unsigned long rate)
370 p_clk=get_freediv_parents_div(clk,rate,&div);
375 if((p_clk->rate/div)!=rate||(p_clk->rate%div))
378 if (clk->parent != p_clk)
380 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),
381 clk->div_shift,clk->div_mask)+1;
384 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
386 ret=clk_set_parent_nolock(clk,p_clk);
389 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
394 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
398 /***************************round********************************/
400 static long clksel_freediv_round_rate(struct clk *clk, unsigned long rate)
402 return clk->parent->rate/clk_get_freediv(rate,clk->parent->rate,clk->div_max);
405 static long clk_freediv_round_autosel_parents_rate(struct clk *clk, unsigned long rate)
409 if(clk->rate == rate)
411 p_clk=get_freediv_parents_div(clk,rate,&div);
414 return p_clk->rate/div;
417 /**************************************others seting************************************/
419 static struct clk* clksel_get_parent(struct clk *clk)
421 return clk->parents[(cru_readl(clk->clksel_con) >> clk->src_shift) & clk->src_mask];
423 static int clksel_set_parent(struct clk *clk, struct clk *parent)
426 if (unlikely(!clk->parents))
428 for (i = 0; (i <clk->parents_num); i++) {
429 if (clk->parents[i]!= parent)
431 set_cru_bits_w_msk(i,clk->src_mask,clk->src_shift,clk->clksel_con);
437 static int gate_mode(struct clk *clk, int on)
439 int idx = clk->gate_idx;
440 if (idx >= CLK_GATE_MAX)
444 cru_writel(CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx), CLK_GATE_CLKID_CONS(idx));
445 //CRU_PRINTK_DBG("un gate id=%d %s(%x),con %x\n",idx,clk->name,
446 // CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx),CLK_GATE_CLKID_CONS(idx));
450 cru_writel(CLK_GATE_W_MSK(idx)|CLK_GATE(idx), CLK_GATE_CLKID_CONS(idx));
451 // CRU_PRINTK_DBG("gate id=%d %s(%x),con%x\n",idx,clk->name,
452 // CLK_GATE_W_MSK(idx)|CLK_GATE(idx),CLK_GATE_CLKID_CONS(idx));
456 /*****************************frac set******************************************/
458 static unsigned long clksel_recalc_frac(struct clk *clk)
462 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
463 if (r == 0) // FPGA ?
464 return clk->parent->rate;
466 denominator = r & 0xFFFF;
467 rate64 = (u64)clk->parent->rate * numerator;
468 do_div(rate64, denominator);
470 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
474 static u32 clk_gcd(u32 numerator, u32 denominator)
478 if (!numerator || !denominator)
480 if (numerator > denominator) {
496 static int frac_div_get_seting(unsigned long rate_out,unsigned long rate,
497 u32 *numerator,u32 *denominator)
500 gcd_vl = clk_gcd(rate, rate_out);
501 CRU_PRINTK_DBG("frac_get_seting rate=%lu,parent=%lu,gcd=%d\n",rate_out,rate, gcd_vl);
504 CRU_PRINTK_ERR("gcd=0, i2s frac div is not be supported\n");
508 *numerator = rate_out / gcd_vl;
509 *denominator = rate/ gcd_vl;
511 CRU_PRINTK_DBG("frac_get_seting numerator=%d,denominator=%d,times=%d\n",
512 *numerator, *denominator, *denominator / *numerator);
514 if (*numerator > 0xffff || *denominator > 0xffff||
515 (*denominator/(*numerator))<20) {
516 CRU_PRINTK_ERR("can't get a available nume and deno\n");
523 /* *********************pll **************************/
525 #define rk30_clock_udelay(a) udelay(a);
527 /*********************pll lock status**********************************/
528 //#define GRF_SOC_CON0 0x15c
529 static void pll_wait_lock(int pll_idx)
531 u32 pll_state[4]={1,0,2,3};
532 u32 bit = 0x10u << pll_state[pll_idx];
533 int delay = 24000000;
535 if (regfile_readl(GRF_SOC_STATUS0) & bit)
540 CRU_PRINTK_ERR("wait pll bit 0x%x time out!\n", bit);
547 /***************************pll function**********************************/
548 static unsigned long pll_clk_recalc(u32 pll_id,unsigned long parent_rate)
552 if (PLLS_IN_NORM(pll_id)) {
553 u32 pll_con0 = cru_readl(PLL_CONS(pll_id,0));
554 u32 pll_con1 = cru_readl(PLL_CONS(pll_id,1));
557 u64 rate64 = (u64)parent_rate*PLL_NF(pll_con1);
560 CRU_PRINTK_DBG("selcon con0(%x) %x,con1(%x)%x, rate64 %llu\n",PLL_CONS(pll_id,0),pll_con0
561 ,PLL_CONS(pll_id,1),pll_con1, rate64);
565 //CRU_PRINTK_DBG("pll id=%d con0=%x,con1=%x,parent=%lu\n",pll_id,pll_con0,pll_con1,parent_rate);
566 //CRU_PRINTK_DBG("first pll id=%d rate is %lu (NF %d NR %d NO %d)\n",
567 //pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0), 1 << PLL_NO(pll_con0));
569 do_div(rate64, PLL_NR(pll_con0));
570 do_div(rate64, PLL_NO(pll_con0));
574 CRU_PRINTK_DBG("pll_clk_recalc id=%d rate=%lu (NF %d NR %d NO %d) rate64=%llu\n",
575 pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0),PLL_NO(pll_con0), rate64);
579 CRU_PRINTK_DBG("pll_clk_recalc id=%d rate=%lu by pass mode\n",pll_id,rate);
583 static unsigned long plls_clk_recalc(struct clk *clk)
585 return pll_clk_recalc(clk->pll->id,clk->parent->rate);
588 static int pll_clk_set_rate(struct pll_clk_set *clk_set,u8 pll_id)
591 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
593 cru_writel(PLL_REST_W_MSK|PLL_REST, PLL_CONS(pll_id,3));
594 cru_writel(clk_set->pllcon0, PLL_CONS(pll_id,0));
595 cru_writel(clk_set->pllcon1, PLL_CONS(pll_id,1));
596 cru_writel(clk_set->pllcon2, PLL_CONS(pll_id,2));
597 rk30_clock_udelay(5);
600 cru_writel(PLL_REST_W_MSK|PLL_REST_RESM, PLL_CONS(pll_id,3));
603 rk30_clock_udelay(clk_set->rst_dly);
604 pll_wait_lock(pll_id);
607 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
610 CRU_PRINTK_ERR("pll reg id=%d,con0=%x,con1=%x,mode=%x\n",pll_id,
611 cru_readl(PLL_CONS(pll_id,0)),(PLL_CONS(pll_id,1)),cru_readl(CRU_MODE_CON));
617 static int gpll_clk_set_rate(struct clk *c, unsigned long rate)
619 struct _pll_data *pll_data=c->pll;
620 struct pll_clk_set *clk_set=(struct pll_clk_set*)pll_data->table;
624 if (clk_set->rate == rate) {
629 if(clk_set->rate== rate)
631 pll_clk_set_rate(clk_set,pll_data->id);
632 lpj_gpll = CLK_LOOPS_RECALC(rate);
636 CRU_PRINTK_ERR("gpll is no corresponding rate=%lu\n", rate);
642 #define PLL_FREF_MIN (183*KHZ)
643 #define PLL_FREF_MAX (1500*MHZ)
645 #define PLL_FVCO_MIN (300*MHZ)
646 #define PLL_FVCO_MAX (1500*MHZ)
648 #define PLL_FOUT_MIN (18750*KHZ)
649 #define PLL_FOUT_MAX (1500*MHZ)
651 #define PLL_NF_MAX (4096)
652 #define PLL_NR_MAX (64)
653 #define PLL_NO_MAX (16)
655 static int pll_clk_get_set(unsigned long fin_hz,unsigned long fout_hz,u32 *clk_nr,u32 *clk_nf,u32 *clk_no)
661 unsigned long fref,fvco,fout;
664 CRU_PRINTK_DBG("pll_clk_get_set fin=%lu,fout=%lu\n",fin_hz,fout_hz);
665 if(!fin_hz||!fout_hz||fout_hz==fin_hz)
667 gcd_val=clk_gcd(fin_hz,fout_hz);
668 YFfenzi=fout_hz/gcd_val;
669 YFfenmu=fin_hz/gcd_val;
675 if(nf>PLL_NF_MAX||nonr>(PLL_NO_MAX*PLL_NR_MAX))
677 for(no=1;no<=PLL_NO_MAX;no++)
679 if(!(no==1||!(no%2)))
686 if(nr>PLL_NR_MAX)//PLL_NR_MAX
690 if(fref<PLL_FREF_MIN||fref>PLL_FREF_MAX)
694 if(fvco<PLL_FVCO_MIN||fvco>PLL_FVCO_MAX)
697 if(fout<PLL_FOUT_MIN||fout>PLL_FOUT_MAX)
710 static int pll_clk_mode(struct clk *clk, int on)
712 u8 pll_id=clk->pll->id;
713 u32 nr=PLL_NR(cru_readl(PLL_CONS(pll_id,0)));
714 u32 dly= (nr*500)/24+1;
715 CRU_PRINTK_DBG("pll_mode %s(%d)",clk->name,on);
717 cru_writel(PLL_PWR_ON|PLL_PWR_DN_W_MSK,PLL_CONS(pll_id,3));
718 rk30_clock_udelay(dly);
719 pll_wait_lock(pll_id);
720 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
722 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
723 cru_writel(PLL_PWR_DN|PLL_PWR_DN_W_MSK, PLL_CONS(pll_id,3));
728 static int cpll_clk_set_rate(struct clk *c, unsigned long rate)
730 struct _pll_data *pll_data=c->pll;
731 struct pll_clk_set *clk_set=(struct pll_clk_set*)pll_data->table;
732 struct pll_clk_set temp_clk_set;
733 u32 clk_nr,clk_nf,clk_no;
738 if (clk_set->rate == rate) {
743 if(clk_set->rate==rate)
745 CRU_PRINTK_DBG("cpll get a rate\n");
746 pll_clk_set_rate(clk_set,pll_data->id);
751 CRU_PRINTK_DBG("cpll get auto calc a rate\n");
752 if(pll_clk_get_set(c->parent->rate,rate,&clk_nr,&clk_nf,&clk_no)==0)
754 pr_err("cpll auto set rate error\n");
757 CRU_PRINTK_DBG("cpll auto ger rate set nr=%d,nf=%d,no=%d\n",clk_nr,clk_nf,clk_no);
758 temp_clk_set.pllcon0=PLL_CLKR_SET(clk_nr)|PLL_CLKOD_SET(clk_no);
759 temp_clk_set.pllcon1=PLL_CLKF_SET(clk_nf);
760 temp_clk_set.pllcon2=PLL_CLK_BWADJ_SET(clk_nf/2-1);
761 temp_clk_set.rst_dly=(clk_nr*500)/24+1;
762 pll_clk_set_rate(&temp_clk_set,pll_data->id);
769 /* ******************fixed input clk ***********************************************/
770 static struct clk xin24m = {
775 static struct clk xin27m = {
782 static struct clk clk_12m = {
789 /************************************pll func***************************/
790 static const struct apll_clk_set* arm_pll_clk_get_best_pll_set(unsigned long rate,
791 struct apll_clk_set *tables)
793 const struct apll_clk_set *ps, *pt;
795 /* find the arm_pll we want. */
798 if (pt->rate == rate) {
802 // we are sorted, and ps->rate > pt->rate.
803 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
809 //CRU_PRINTK_DBG("arm pll best rate=%lu\n",ps->rate);
812 static long arm_pll_clk_round_rate(struct clk *clk, unsigned long rate)
814 return arm_pll_clk_get_best_pll_set(rate,clk->pll->table)->rate;
817 struct arm_clks_div_set {
823 #define _arm_clks_div_set(_mhz,_periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
826 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
827 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
828 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
829 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
830 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
832 struct arm_clks_div_set arm_clk_div_tlb[]={
833 _arm_clks_div_set(50 , 2, 11, 11, 11, 11),//25,50,50,50,50
834 _arm_clks_div_set(100 , 4, 11, 21, 21, 11),//25,100,50,50,50
835 _arm_clks_div_set(150 , 4, 11, 21, 21, 11),//37,150,75,75,75
836 _arm_clks_div_set(200 , 8, 21, 21, 21, 11),//25,100,50,50,50
837 _arm_clks_div_set(300 , 8, 21, 21, 21, 11),//37,150,75,75,75
838 _arm_clks_div_set(400 , 8, 21, 21, 41, 21),//50,200,100,50,50
839 _arm_clks_div_set(0 , 2, 11, 11, 11, 11),//25,50,50,50,50
841 struct arm_clks_div_set * arm_clks_get_div(u32 rate)
844 for(i=0;arm_clk_div_tlb[i].rate!=0;i++)
846 if(arm_clk_div_tlb[i].rate>=rate)
847 return &arm_clk_div_tlb[i];
854 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
857 const struct apll_clk_set *ps;
858 u32 pll_id=clk->pll->id;
860 u32 old_aclk_div=0,new_aclk_div,gpll_arm_aclk_div;
861 struct arm_clks_div_set *temp_clk_div;
862 unsigned long arm_gpll_rate, arm_gpll_lpj;
864 ps = arm_pll_clk_get_best_pll_set(rate,(struct apll_clk_set *)clk->pll->table);
866 old_aclk_div=GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
867 new_aclk_div=GET_CORE_ACLK_VAL(ps->clksel1&CORE_ACLK_MSK);
869 CRU_PRINTK_LOG("apll will set rate(%lu) tlb con(%x,%x,%x),sel(%x,%x)\n",
870 ps->rate,ps->pllcon0,ps->pllcon1,ps->pllcon2,ps->clksel0,ps->clksel1);
872 //rk30_l2_cache_latency(ps->rate/MHZ);
874 if(general_pll_clk.rate>clk->rate)
876 temp_div=clk_get_freediv(clk->rate,general_pll_clk.rate,10);
883 //cru_writel(CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
885 arm_gpll_rate=general_pll_clk.rate/temp_div;
886 arm_gpll_lpj = lpj_gpll / temp_div;
887 temp_clk_div=arm_clks_get_div(arm_gpll_rate/MHZ);
889 temp_clk_div=&arm_clk_div_tlb[4];
891 gpll_arm_aclk_div=GET_CORE_ACLK_VAL(temp_clk_div->clksel1&CORE_ACLK_MSK);
893 CRU_PRINTK_LOG("gpll_arm_rate=%lu,sel rate%u,sel0%x,sel1%x\n",arm_gpll_rate,temp_clk_div->rate,
894 temp_clk_div->clksel0,temp_clk_div->clksel1);
896 local_irq_save(flags);
898 if(gpll_arm_aclk_div>=old_aclk_div)
900 if((old_aclk_div==3||gpll_arm_aclk_div==3)&&(gpll_arm_aclk_div!=old_aclk_div))
902 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
903 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
904 cru_writel((temp_clk_div->clksel0|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK),
906 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
910 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
911 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
915 // open gpu gpll path
916 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));
917 cru_writel(CORE_SEL_GPLL|CORE_SEL_PLL_W_MSK, CRU_CLKSELS_CON(0));
918 loops_per_jiffy = arm_gpll_lpj;
921 if(gpll_arm_aclk_div<old_aclk_div)
923 if((old_aclk_div==3||gpll_arm_aclk_div==3)&&(gpll_arm_aclk_div!=old_aclk_div))
925 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
926 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
927 cru_writel((temp_clk_div->clksel0|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK),
929 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
933 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
934 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
939 /*if core src don't select gpll ,apll neet to enter slow mode */
940 //cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
943 cru_writel(PLL_REST_W_MSK|PLL_REST, PLL_CONS(pll_id,3));
944 cru_writel(ps->pllcon0, PLL_CONS(pll_id,0));
945 cru_writel(ps->pllcon1, PLL_CONS(pll_id,1));
946 cru_writel(ps->pllcon2, PLL_CONS(pll_id,2));
948 rk30_clock_udelay(5);
951 cru_writel(PLL_REST_W_MSK|PLL_REST_RESM, PLL_CONS(pll_id,3));
954 ///rk30_clock_udelay(ps->rst_dly);//lcdc flash
956 pll_wait_lock(pll_id);
959 //cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
961 if(new_aclk_div>=gpll_arm_aclk_div)
963 if((gpll_arm_aclk_div==3||new_aclk_div==3)&&(new_aclk_div!=gpll_arm_aclk_div))
965 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
966 cru_writel((ps->clksel1), CRU_CLKSELS_CON(1));
967 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
968 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
972 cru_writel((ps->clksel1), CRU_CLKSELS_CON(1));
973 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
978 cru_writel(CORE_SEL_PLL_W_MSK|CORE_SEL_APLL, CRU_CLKSELS_CON(0));
979 loops_per_jiffy = ps->lpj;
982 if(new_aclk_div<gpll_arm_aclk_div)
984 if((gpll_arm_aclk_div==3||new_aclk_div==3)&&(new_aclk_div!=gpll_arm_aclk_div))
986 cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
987 cru_writel((ps->clksel1), CRU_CLKSELS_CON(1));
988 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
989 cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
993 cru_writel((ps->clksel1), CRU_CLKSELS_CON(1));
994 cru_writel((ps->clksel0)|CORE_CLK_DIV(1)|CORE_CLK_DIV_W_MSK, CRU_CLKSELS_CON(0));
997 //CRU_PRINTK_DBG("apll set loops_per_jiffy =%lu,rate(%lu)\n",loops_per_jiffy,ps->rate);
999 local_irq_restore(flags);
1002 cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH)|CLK_GATE(CLK_GATE_CPU_GPLL_PATH)
1003 , CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
1005 CRU_PRINTK_LOG("apll set over con(%x,%x,%x,%x),sel(%x,%x)\n",cru_readl(PLL_CONS(pll_id,0)),
1006 cru_readl(PLL_CONS(pll_id,1)),cru_readl(PLL_CONS(pll_id,2)),
1007 cru_readl(PLL_CONS(pll_id,3)),cru_readl(CRU_CLKSELS_CON(0)),
1008 cru_readl(CRU_CLKSELS_CON(1)));
1013 /************************************pll clocks***************************/
1015 static const struct apll_clk_set apll_clks[] = {
1016 //rate, nr ,nf ,no,core_div,peri,axi,hclk,pclk,_ahb2apb
1017 //_APLL_SET_CLKS(1800, 1, 75, 1, 8, 41, 41, 81,21),
1018 //_APLL_SET_CLKS(1752, 1, 73, 1, 8, 41, 41, 81,21),
1019 //_APLL_SET_CLKS(1704, 1, 71, 1, 8, 41, 41, 81,21),
1020 //_APLL_SET_CLKS(1656, 1, 69, 1, 8, 41, 41, 81,21),
1021 _APLL_SET_CLKS(1608, 1, 67, 1, 8, 41, 21, 41, 21),
1022 _APLL_SET_CLKS(1560, 1, 65, 1, 8, 41, 21, 41, 21),
1023 _APLL_SET_CLKS(1512, 1, 63, 1, 8, 41, 21, 41, 21),
1024 _APLL_SET_CLKS(1464, 1, 61, 1, 8, 41, 21, 41, 21),
1025 _APLL_SET_CLKS(1416, 1, 59, 1, 8, 41, 21, 41, 21),
1026 _APLL_SET_CLKS(1368, 1, 57, 1, 8, 41, 21, 41, 21),
1027 _APLL_SET_CLKS(1320, 1, 55, 1, 8, 41, 21, 41, 21),
1028 _APLL_SET_CLKS(1296, 1, 54, 1, 8, 41, 21, 41, 21),
1029 _APLL_SET_CLKS(1272, 1, 53, 1, 8, 41, 21, 41, 21),
1030 _APLL_SET_CLKS(1200, 1, 50, 1, 8, 41, 21, 41, 21),
1031 _APLL_SET_CLKS(1176, 1, 49, 1, 8, 41, 21, 41, 21),
1032 _APLL_SET_CLKS(1128, 1, 47, 1, 8, 41, 21, 41, 21),
1033 _APLL_SET_CLKS(1104, 1, 46, 1, 8, 41, 21, 41, 21),
1034 _APLL_SET_CLKS(1008, 1, 42, 1, 8, 31, 21, 41, 21),
1035 _APLL_SET_CLKS(888, 1, 37, 1, 8, 31, 21, 41, 21),
1036 _APLL_SET_CLKS(816 , 1, 34, 1, 8, 31, 21, 41, 21),
1037 _APLL_SET_CLKS(792 , 1, 33, 1, 8, 31, 21, 41, 21),
1038 _APLL_SET_CLKS(696 , 1, 29, 1, 8, 31, 21, 41, 21),
1039 _APLL_SET_CLKS(600 , 1, 25, 1, 4, 31, 21, 41, 21),
1040 _APLL_SET_CLKS(504 , 1, 21, 1, 4, 21, 21, 41, 21),
1041 _APLL_SET_CLKS(408 , 1, 17, 1, 4, 21, 21, 41, 21),
1042 _APLL_SET_CLKS(312 , 1, 13, 1, 2, 21, 21, 21, 11),
1043 _APLL_SET_CLKS(252 , 1, 21, 2, 2, 21, 21, 21, 11),
1044 _APLL_SET_CLKS(216 , 1, 18, 2, 2, 21, 21, 21, 11),
1045 _APLL_SET_CLKS(126 , 1, 21, 4, 2, 21, 11, 11, 11),
1046 _APLL_SET_CLKS(48 , 1, 16, 8, 2, 11, 11, 11, 11),
1047 _APLL_SET_CLKS(0 , 1, 21, 4, 2, 21, 21, 41, 21),
1050 static struct _pll_data apll_data=SET_PLL_DATA(APLL_ID,(void *)apll_clks);
1051 static struct clk arm_pll_clk ={
1054 .mode = pll_clk_mode,
1055 .recalc = plls_clk_recalc,
1056 .set_rate = arm_pll_clk_set_rate,
1057 .round_rate = arm_pll_clk_round_rate,
1061 static int ddr_pll_clk_set_rate(struct clk *clk, unsigned long rate)
1063 /* do nothing here */
1066 static struct _pll_data dpll_data=SET_PLL_DATA(DPLL_ID,NULL);
1067 static struct clk ddr_pll_clk = {
1070 .recalc = plls_clk_recalc,
1071 .set_rate = ddr_pll_clk_set_rate,
1075 static const struct pll_clk_set cpll_clks[] = {
1076 _PLL_SET_CLKS(360000, 1, 15, 1),
1077 _PLL_SET_CLKS(408000, 1, 17, 1),
1078 _PLL_SET_CLKS(456000, 1, 19, 1),
1079 _PLL_SET_CLKS(504000, 1, 21, 1),
1080 _PLL_SET_CLKS(552000, 1, 23, 1),
1081 _PLL_SET_CLKS(600000, 1, 25, 1),
1082 _PLL_SET_CLKS(742500, 8, 495, 2),
1083 _PLL_SET_CLKS(798000, 4, 133, 1),
1084 _PLL_SET_CLKS(1188000,2, 99, 1),
1085 _PLL_SET_CLKS( 0, 4, 133, 1),
1087 static struct _pll_data cpll_data=SET_PLL_DATA(CPLL_ID,(void *)cpll_clks);
1088 static struct clk codec_pll_clk = {
1089 .name = "codec_pll",
1091 .mode = pll_clk_mode,
1092 .recalc = plls_clk_recalc,
1093 .set_rate = cpll_clk_set_rate,
1097 static const struct pll_clk_set gpll_clks[] = {
1098 _PLL_SET_CLKS(148500, 4, 99, 4),
1099 _PLL_SET_CLKS(297000, 2, 99, 4),
1100 _PLL_SET_CLKS(300000, 1, 25, 2),
1101 _PLL_SET_CLKS(1188000, 2, 99, 1),
1102 _PLL_SET_CLKS(0, 0, 0, 0),
1104 static struct _pll_data gpll_data=SET_PLL_DATA(GPLL_ID,(void *)gpll_clks);
1105 static struct clk general_pll_clk = {
1106 .name = "general_pll",
1108 .recalc = plls_clk_recalc,
1109 .set_rate = gpll_clk_set_rate,
1112 /********************************clocks***********************************/
1113 static int ddr_clk_set_rate(struct clk *c, unsigned long rate)
1118 static struct clk *clk_ddr_parents[2] = {&ddr_pll_clk, &general_pll_clk};
1119 static struct clk clk_ddr = {
1121 .parent = &ddr_pll_clk,
1122 .recalc = clksel_recalc_shift,
1123 .set_rate = ddr_clk_set_rate,
1124 .clksel_con = CRU_CLKSELS_CON(26),
1125 //CRU_DIV_SET(0x3,0,4),
1127 //CRU_PARENTS_SET(clk_ddr_parents),
1129 static int arm_core_clk_set_rate(struct clk *c, unsigned long rate)
1133 //set_cru_bits_w_msk(0,c->div_mask,c->div_shift,c->clksel_con);
1135 ret = clk_set_rate_nolock(c->parent, rate);
1137 CRU_PRINTK_ERR("Failed to change clk pll %s to %lu\n",c->name,rate);
1142 static unsigned long arm_core_clk_get_rate(struct clk *c)
1144 u32 div=(get_cru_bits(c->clksel_con,c->div_mask,c->div_shift)+1);
1145 //c->parent->rate=c->parent->recalc(c->parent);
1146 return c->parent->rate/div;
1148 static long core_clk_round_rate(struct clk *clk, unsigned long rate)
1150 u32 div=(get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1);
1151 return clk_round_rate_nolock(clk->parent,rate)/div;
1154 static int core_clksel_set_parent(struct clk *clk, struct clk *new_prt)
1158 struct clk *old_prt;
1160 if(clk->parent==new_prt)
1162 if (unlikely(!clk->parents))
1164 CRU_PRINTK_DBG("%s,reparent %s\n",clk->name,new_prt->name);
1166 old_prt=clk->parent;
1168 if(clk->parents[0]==new_prt)
1170 new_prt->set_rate(new_prt,300*MHZ);
1171 set_cru_bits_w_msk(0,clk->div_mask,clk->div_shift,clk->clksel_con);
1173 else if(clk->parents[1]==new_prt)
1176 if(new_prt->rate>old_prt->rate)
1178 temp_div=clk_get_freediv(old_prt->rate,new_prt->rate,clk->div_max);
1179 set_cru_bits_w_msk(temp_div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
1181 set_cru_bits_w_msk(1,clk->src_mask,clk->src_shift,clk->clksel_con);
1182 new_prt->set_rate(new_prt,300*MHZ);
1192 static int core_gpll_clk_set_rate(struct clk *c, unsigned long rate)
1194 unsigned long flags;
1197 u32 old_aclk_div=0,new_aclk_div;
1198 struct arm_clks_div_set *temp_clk_div;
1199 unsigned long arm_gpll_rate, arm_gpll_lpj;
1200 temp_div=clk_get_freediv(rate,c->parent->rate,c->div_max);
1201 arm_gpll_rate=c->parent->rate/temp_div;
1203 temp_clk_div=arm_clks_get_div(arm_gpll_rate/MHZ);
1205 temp_clk_div=&arm_clk_div_tlb[4];
1207 old_aclk_div=GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
1208 new_aclk_div=GET_CORE_ACLK_VAL(temp_clk_div->clksel1&CORE_ACLK_MSK);
1211 arm_gpll_lpj = lpj_gpll / temp_div;
1212 set_cru_bits_w_msk(temp_div-1,c->div_mask,c->div_shift,c->clksel_con);
1215 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
1216 cru_writel((temp_clk_div->clksel0)|CORE_CLK_DIV(temp_div)|CORE_CLK_DIV_W_MSK,
1217 CRU_CLKSELS_CON(0));
1220 arm_gpll_lpj = lpj_gpll / temp_div;
1221 set_cru_bits_w_msk(temp_div-1,c->div_mask,c->div_shift,c->clksel_con);
1225 static unsigned long arm_core_gpll_clk_get_rate(struct clk *c)
1227 return c->parent->rate;
1230 static struct clk clk_cpu_gpll_path = {
1231 .name = "cpu_gpll_path",
1232 .parent = &general_pll_clk,
1233 .recalc = arm_core_gpll_clk_get_rate,
1234 .set_rate = core_gpll_clk_set_rate,
1235 CRU_DIV_SET(0x1f,0,32),
1236 CRU_GATE_MODE_SET(gate_mode,CLK_GATE_CPU_GPLL_PATH),
1240 static struct clk *clk_cpu_parents[2] = {&arm_pll_clk,&clk_cpu_gpll_path};
1242 static struct clk clk_cpu = {
1244 .parent = &arm_pll_clk,
1245 .set_rate = arm_core_clk_set_rate,
1246 .recalc = arm_core_clk_get_rate,
1247 .round_rate = core_clk_round_rate,
1248 .set_parent = core_clksel_set_parent,
1249 .clksel_con = CRU_CLKSELS_CON(0),
1250 CRU_DIV_SET(0x1f,0,32),
1252 CRU_PARENTS_SET(clk_cpu_parents),
1254 static unsigned long aclk_cpu_recalc(struct clk *clk)
1257 u32 div = get_cru_bits(clk->clksel_con,clk->div_mask,clk->div_shift)+1;
1262 rate = clk->parent->rate / div;
1263 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
1267 static struct clk core_periph = {
1268 .name = "core_periph",
1270 .recalc = clksel_recalc_shift_2,
1271 .clksel_con = CRU_CLKSELS_CON(0),
1272 CRU_DIV_SET(0x3,6,16),
1275 static struct clk aclk_cpu = {
1278 .recalc = aclk_cpu_recalc,
1279 .clksel_con = CRU_CLKSELS_CON(1),
1280 CRU_DIV_SET(0x7,0,8),
1283 static struct clk hclk_cpu = {
1285 .parent = &aclk_cpu,
1286 .recalc = clksel_recalc_shift,
1287 //.set_rate = clksel_set_rate_shift,
1288 .clksel_con = CRU_CLKSELS_CON(1),
1289 CRU_DIV_SET(0x3,8,4),
1293 static struct clk pclk_cpu = {
1295 .parent = &aclk_cpu,
1296 .recalc = clksel_recalc_shift,
1297 //.set_rate = clksel_set_rate_shift,
1298 .clksel_con = CRU_CLKSELS_CON(1),
1299 CRU_DIV_SET(0x3,12,8),
1301 static struct clk ahb2apb_cpu = {
1303 .parent = &hclk_cpu,
1304 .recalc = clksel_recalc_shift,
1305 .clksel_con = CRU_CLKSELS_CON(1),
1306 CRU_DIV_SET(0x3,14,4),
1310 static struct clk atclk_cpu = {
1311 .name = "atclk_cpu",
1312 .parent = &pclk_cpu,
1315 static struct clk *clk_i2s_div_parents[]={&general_pll_clk,&codec_pll_clk};
1316 static struct clk clk_i2s_pll = {
1318 .parent = &general_pll_clk,
1319 .clksel_con = CRU_CLKSELS_CON(2),
1320 CRU_SRC_SET(0x1,16),
1321 CRU_PARENTS_SET(clk_i2s_div_parents),
1324 static struct clk clk_i2s0_div = {
1326 .parent = &clk_i2s_pll,
1328 .recalc = clksel_recalc_div,
1329 .set_rate = clksel_set_rate_freediv,
1330 .round_rate =clksel_freediv_round_rate,
1331 .gate_idx = CLK_GATE_I2S0,
1332 .clksel_con = CRU_CLKSELS_CON(2),
1333 CRU_DIV_SET(0x7f,0,64),
1336 static struct clk clk_i2s1_div = {
1338 .parent = &clk_i2s_pll,
1339 .recalc = clksel_recalc_div,
1340 .set_rate = clksel_set_rate_freediv,
1341 .round_rate =clksel_freediv_round_rate,
1343 .gate_idx = CLK_GATE_I2S1,
1344 .clksel_con = CRU_CLKSELS_CON(3),
1345 CRU_DIV_SET(0x7f,0,64),
1349 static struct clk clk_i2s2_div = {
1351 .parent = &clk_i2s_pll,
1352 .recalc = clksel_recalc_div,
1353 .set_rate = clksel_set_rate_freediv,
1354 .round_rate =clksel_freediv_round_rate,
1356 .gate_idx = CLK_GATE_I2S2,
1357 .clksel_con = CRU_CLKSELS_CON(4),
1358 CRU_DIV_SET(0x7f,0,64),
1360 static struct clk clk_spdif_div = {
1361 .name = "spdif_div",
1362 .parent = &clk_i2s_pll,
1363 .recalc = clksel_recalc_div,
1364 .set_rate = clksel_set_rate_freediv,
1365 .round_rate =clksel_freediv_round_rate,
1367 .gate_idx = CLK_GATE_SPDIF,
1368 .clksel_con = CRU_CLKSELS_CON(5),
1369 CRU_DIV_SET(0x7f,0,64),
1371 static int clk_i2s_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1373 u32 numerator, denominator;
1374 //clk_i2s_div->clk_i2s_pll->gpll/cpll
1375 //clk->parent->parent
1376 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1377 &numerator,&denominator)==0)
1379 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1380 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1381 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1385 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1392 static struct clk clk_i2s0_frac_div = {
1393 .name = "i2s0_frac_div",
1394 .parent = &clk_i2s0_div,
1396 .gate_idx = CLK_GATE_I2S0_FRAC,
1397 .recalc = clksel_recalc_frac,
1398 .set_rate = clk_i2s_fracdiv_set_rate,
1399 .clksel_con = CRU_CLKSELS_CON(6),
1402 static struct clk clk_i2s1_frac_div = {
1403 .name = "i2s1_frac_div",
1404 .parent = &clk_i2s1_div,
1406 .gate_idx = CLK_GATE_I2S1_FRAC,
1407 .recalc = clksel_recalc_frac,
1408 .set_rate = clk_i2s_fracdiv_set_rate,
1409 .clksel_con = CRU_CLKSELS_CON(7),
1412 static struct clk clk_i2s2_frac_div = {
1413 .name = "i2s2_frac_div",
1415 .gate_idx = CLK_GATE_I2S2_FRAC,
1416 .parent = &clk_i2s2_div,
1417 .recalc = clksel_recalc_frac,
1418 .set_rate = clk_i2s_fracdiv_set_rate,
1419 .clksel_con = CRU_CLKSELS_CON(8),
1421 static struct clk clk_spdif_frac_div = {
1422 .name = "spdif_frac_div",
1423 .parent = &clk_spdif_div,
1425 .gate_idx = CLK_GATE_SPDIF_FRAC,
1426 .recalc = clksel_recalc_frac,
1427 .set_rate = clk_i2s_fracdiv_set_rate,
1428 .clksel_con = CRU_CLKSELS_CON(9),
1431 #define I2S_SRC_DIV (0x0)
1432 #define I2S_SRC_FRAC (0x1)
1433 #define I2S_SRC_12M (0x2)
1435 static int i2s_set_rate(struct clk *clk, unsigned long rate)
1440 if (rate == clk->parents[I2S_SRC_12M]->rate){
1441 parent = clk->parents[I2S_SRC_12M];
1442 }else if((long)clk_round_rate_nolock(clk->parents[I2S_SRC_DIV],rate)==rate)
1444 parent = clk->parents[I2S_SRC_DIV];
1448 parent =clk->parents[I2S_SRC_FRAC];
1451 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
1452 clk->name,rate,parent->name,clk->parent->name);
1454 if(parent!=clk->parents[I2S_SRC_12M])
1456 ret = clk_set_rate_nolock(parent,rate);//div 1:1
1459 CRU_PRINTK_DBG("%s set rate%lu err\n",clk->name,rate);
1464 if (clk->parent != parent)
1466 ret = clk_set_parent_nolock(clk, parent);
1469 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
1477 static struct clk *clk_i2s0_parents[3]={&clk_i2s0_div,&clk_i2s0_frac_div,&clk_12m};
1479 static struct clk clk_i2s0 = {
1481 .set_rate = i2s_set_rate,
1482 .clksel_con = CRU_CLKSELS_CON(2),
1484 CRU_PARENTS_SET(clk_i2s0_parents),
1487 static struct clk *clk_i2s1_parents[3]={&clk_i2s1_div,&clk_i2s1_frac_div,&clk_12m};
1489 static struct clk clk_i2s1 = {
1491 .set_rate = i2s_set_rate,
1492 .clksel_con = CRU_CLKSELS_CON(3),
1494 CRU_PARENTS_SET(clk_i2s1_parents),
1497 static struct clk *clk_i2s2_parents[3]={&clk_i2s2_div,&clk_i2s2_frac_div,&clk_12m};
1499 static struct clk clk_i2s2 = {
1501 .set_rate = i2s_set_rate,
1502 .clksel_con = CRU_CLKSELS_CON(4),
1504 CRU_PARENTS_SET(clk_i2s2_parents),
1507 static struct clk *clk_spdif_parents[3]={&clk_spdif_div,&clk_spdif_frac_div,&clk_12m};
1509 static struct clk clk_spdif = {
1511 .parent = &clk_spdif_frac_div,
1512 .set_rate = i2s_set_rate,
1513 .clksel_con = CRU_CLKSELS_CON(5),
1515 CRU_PARENTS_SET(clk_spdif_parents),
1518 static struct clk *aclk_periph_parents[2]={&general_pll_clk,&codec_pll_clk};
1520 static struct clk aclk_periph = {
1521 .name = "aclk_periph",
1522 .parent = &general_pll_clk,
1524 .gate_idx = CLK_GATE_ACLK_PERIPH,
1525 .recalc = clksel_recalc_div,
1526 .set_rate = clksel_set_rate_freediv,
1527 .clksel_con = CRU_CLKSELS_CON(10),
1528 CRU_DIV_SET(0x1f,0,32),
1530 CRU_PARENTS_SET(aclk_periph_parents),
1532 GATE_CLK(periph_src, aclk_periph, PERIPH_SRC);
1534 static struct clk pclk_periph = {
1535 .name = "pclk_periph",
1536 .parent = &aclk_periph,
1538 .gate_idx = CLK_GATE_PCLK_PERIPH,
1539 .recalc = clksel_recalc_shift,
1540 .set_rate = clksel_set_rate_shift,
1541 .clksel_con = CRU_CLKSELS_CON(10),
1542 CRU_DIV_SET(0x3,12,8),
1545 static struct clk hclk_periph = {
1546 .name = "hclk_periph",
1547 .parent = &aclk_periph,
1549 .gate_idx = CLK_GATE_HCLK_PERIPH,
1550 .recalc = clksel_recalc_shift,
1551 .set_rate = clksel_set_rate_shift,
1552 .clksel_con = CRU_CLKSELS_CON(10),
1553 CRU_DIV_SET(0x3,8,4),
1556 static struct clk clk_spi0 = {
1558 .parent = &pclk_periph,
1560 .recalc = clksel_recalc_div,
1561 .set_rate = clksel_set_rate_freediv,
1562 .gate_idx = CLK_GATE_SPI0,
1563 .clksel_con = CRU_CLKSELS_CON(25),
1564 CRU_DIV_SET(0x7f,0,128),
1567 static struct clk clk_spi1 = {
1569 .parent = &pclk_periph,
1571 .recalc = clksel_recalc_div,
1572 .set_rate = clksel_set_rate_freediv,
1573 .gate_idx = CLK_GATE_SPI1,
1574 .clksel_con = CRU_CLKSELS_CON(25),
1575 CRU_DIV_SET(0x7f,8,128),
1578 static struct clk clk_saradc = {
1582 .recalc = clksel_recalc_div,
1583 .set_rate = clksel_set_rate_freediv,
1584 .gate_idx = CLK_GATE_SARADC,
1585 .clksel_con =CRU_CLKSELS_CON(24),
1586 CRU_DIV_SET(0xff,8,256),
1588 static struct clk clk_tsadc = {
1592 .recalc = clksel_recalc_div,
1593 .set_rate = clksel_set_rate_freediv,
1594 .gate_idx = CLK_GATE_TSADC,
1595 .clksel_con =CRU_CLKSELS_CON(34),
1596 CRU_DIV_SET(0xffff,0,65536),
1598 GATE_CLK(otgphy0, xin24m, OTGPHY0);
1599 GATE_CLK(otgphy1, xin24m, OTGPHY1);
1602 GATE_CLK(smc, pclk_periph, SMC);//smc
1604 static struct clk clk_sdmmc = {
1606 .parent = &hclk_periph,
1608 .recalc = clksel_recalc_div,
1609 .set_rate = clksel_set_rate_freediv,
1610 .gate_idx = CLK_GATE_MMC0,
1611 .clksel_con =CRU_CLKSELS_CON(11),
1612 CRU_DIV_SET(0x3f,0,64),
1615 static struct clk clk_sdio = {
1617 .parent = &hclk_periph,
1619 .recalc = clksel_recalc_div,
1620 .set_rate = clksel_set_rate_freediv,
1621 .gate_idx = CLK_GATE_SDIO,
1622 .clksel_con =CRU_CLKSELS_CON(12),
1623 CRU_DIV_SET(0x3f,0,64),
1627 static struct clk clk_emmc = {
1629 .parent = &hclk_periph,
1631 .recalc = clksel_recalc_div,
1632 .set_rate = clksel_set_rate_freediv,
1633 .gate_idx = CLK_GATE_EMMC,
1634 .clksel_con =CRU_CLKSELS_CON(12),
1635 CRU_DIV_SET(0x3f,8,64),
1638 static struct clk *clk_uart_src_parents[2]={&general_pll_clk,&codec_pll_clk};
1639 static struct clk clk_uart_pll = {
1641 .parent = &general_pll_clk,
1642 .clksel_con =CRU_CLKSELS_CON(12),
1643 CRU_SRC_SET(0x1,15),
1644 CRU_PARENTS_SET(clk_uart_src_parents),
1646 static struct clk clk_uart0_div = {
1647 .name = "uart0_div",
1648 .parent = &clk_uart_pll,
1650 .gate_idx = CLK_GATE_UART0,
1651 .recalc = clksel_recalc_div,
1652 .set_rate = clksel_set_rate_freediv,
1653 .round_rate =clksel_freediv_round_rate,
1654 .clksel_con = CRU_CLKSELS_CON(13),
1655 CRU_DIV_SET(0x7f,0,64),
1657 static struct clk clk_uart1_div = {
1658 .name = "uart1_div",
1659 .parent = &clk_uart_pll,
1661 .gate_idx = CLK_GATE_UART1,
1662 .recalc = clksel_recalc_div,
1663 .round_rate =clksel_freediv_round_rate,
1664 .set_rate = clksel_set_rate_freediv,
1665 .clksel_con = CRU_CLKSELS_CON(14),
1666 CRU_DIV_SET(0x7f,0,64),
1669 static struct clk clk_uart2_div = {
1670 .name = "uart2_div",
1671 .parent = &clk_uart_pll,
1673 .gate_idx = CLK_GATE_UART2,
1674 .recalc = clksel_recalc_div,
1675 .round_rate =clksel_freediv_round_rate,
1676 .set_rate = clksel_set_rate_freediv,
1677 .clksel_con = CRU_CLKSELS_CON(15),
1678 CRU_DIV_SET(0x7f,0,64),
1681 static struct clk clk_uart3_div = {
1682 .name = "uart3_div",
1683 .parent = &clk_uart_pll,
1685 .gate_idx = CLK_GATE_UART3,
1686 .recalc = clksel_recalc_div,
1687 .round_rate =clksel_freediv_round_rate,
1688 .set_rate = clksel_set_rate_freediv,
1689 .clksel_con = CRU_CLKSELS_CON(16),
1690 CRU_DIV_SET(0x7f,0,64),
1692 static int clk_uart_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1694 u32 numerator, denominator;
1695 //clk_uart0_div->clk_uart_pll->gpll/cpll
1696 //clk->parent->parent
1697 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1698 &numerator,&denominator)==0)
1700 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1702 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1704 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1708 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1714 static struct clk clk_uart0_frac_div = {
1715 .name = "uart0_frac_div",
1716 .parent = &clk_uart0_div,
1718 .recalc = clksel_recalc_frac,
1719 .set_rate = clk_uart_fracdiv_set_rate,
1720 .gate_idx = CLK_GATE_FRAC_UART0,
1721 .clksel_con = CRU_CLKSELS_CON(17),
1723 static struct clk clk_uart1_frac_div = {
1724 .name = "uart1_frac_div",
1725 .parent = &clk_uart1_div,
1727 .recalc = clksel_recalc_frac,
1728 .set_rate = clk_uart_fracdiv_set_rate,
1729 .gate_idx = CLK_GATE_FRAC_UART1,
1730 .clksel_con = CRU_CLKSELS_CON(18),
1732 static struct clk clk_uart2_frac_div = {
1733 .name = "uart2_frac_div",
1735 .parent = &clk_uart2_div,
1736 .recalc = clksel_recalc_frac,
1737 .set_rate = clk_uart_fracdiv_set_rate,
1738 .gate_idx = CLK_GATE_FRAC_UART2,
1739 .clksel_con = CRU_CLKSELS_CON(19),
1741 static struct clk clk_uart3_frac_div = {
1742 .name = "uart3_frac_div",
1743 .parent = &clk_uart3_div,
1745 .recalc = clksel_recalc_frac,
1746 .set_rate = clk_uart_fracdiv_set_rate,
1747 .gate_idx = CLK_GATE_FRAC_UART3,
1748 .clksel_con = CRU_CLKSELS_CON(20),
1752 #define UART_SRC_DIV 0
1753 #define UART_SRC_FRAC 1
1754 #define UART_SRC_24M 2
1756 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
1761 if(rate==clk->parents[UART_SRC_24M]->rate)//24m
1763 parent = clk->parents[UART_SRC_24M];
1765 else if((long)clk_round_rate_nolock(clk->parents[UART_SRC_DIV], rate)==rate)
1767 parent = clk->parents[UART_SRC_DIV];
1771 parent = clk->parents[UART_SRC_FRAC];
1776 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
1777 clk->name,rate,parent->name,clk->parent->name);
1780 if(parent!=clk->parents[UART_SRC_24M])
1782 ret = clk_set_rate_nolock(parent,rate);
1785 CRU_PRINTK_DBG("%s set rate%lu err\n",clk->name,rate);
1790 if (clk->parent != parent)
1792 ret = clk_set_parent_nolock(clk, parent);
1795 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
1805 static struct clk *clk_uart0_parents[3]={&clk_uart0_div,&clk_uart0_frac_div,&xin24m};
1806 static struct clk clk_uart0 = {
1808 .set_rate = clk_uart_set_rate,
1809 .clksel_con = CRU_CLKSELS_CON(13),
1811 CRU_PARENTS_SET(clk_uart0_parents),
1814 static struct clk *clk_uart1_parents[3]={&clk_uart1_div,&clk_uart1_frac_div,&xin24m};
1815 static struct clk clk_uart1 = {
1817 .set_rate = clk_uart_set_rate,
1818 .clksel_con = CRU_CLKSELS_CON(14),
1820 CRU_PARENTS_SET(clk_uart1_parents),
1823 static struct clk *clk_uart2_parents[3]={&clk_uart2_div,&clk_uart2_frac_div,&xin24m};
1824 static struct clk clk_uart2 = {
1826 .set_rate = clk_uart_set_rate,
1827 .clksel_con = CRU_CLKSELS_CON(15),
1829 CRU_PARENTS_SET(clk_uart2_parents),
1831 static struct clk *clk_uart3_parents[3]={&clk_uart3_div,&clk_uart3_frac_div,&xin24m};
1832 static struct clk clk_uart3 = {
1834 .set_rate = clk_uart_set_rate,
1835 .clksel_con = CRU_CLKSELS_CON(16),
1837 CRU_PARENTS_SET(clk_uart3_parents),
1840 GATE_CLK(timer0, xin24m, TIMER0);
1841 GATE_CLK(timer1, xin24m, TIMER1);
1842 GATE_CLK(timer2, xin24m, TIMER2);
1844 static struct clk rmii_clkin = {
1845 .name = "rmii_clkin",
1847 static struct clk *clk_mac_ref_div_parents[2]={&general_pll_clk,&ddr_pll_clk};
1848 static struct clk clk_mac_pll_div = {
1849 .name = "mac_pll_div",
1850 .parent = &ddr_pll_clk,
1852 .gate_idx = CLK_GATE_MAC,
1853 .recalc = clksel_recalc_div,
1854 .set_rate =clksel_set_rate_freediv,
1855 //.set_rate = clksel_set_rate_freediv,
1856 .clksel_con =CRU_CLKSELS_CON(21),
1857 CRU_DIV_SET(0x1f,8,32),
1859 CRU_PARENTS_SET(clk_mac_ref_div_parents),
1862 static int clksel_mac_ref_set_rate(struct clk *clk, unsigned long rate)
1865 if(clk->parent==clk->parents[1])
1867 CRU_PRINTK_DBG("mac_ref clk is form mii clkin,can't set it\n" );
1870 else if(clk->parent==clk->parents[0])
1872 return clk_set_rate_nolock(clk->parents[0],rate);
1877 static struct clk *clk_mac_ref_parents[2]={&clk_mac_pll_div,&rmii_clkin};
1879 static struct clk clk_mac_ref = {
1881 .parent = &clk_mac_pll_div,
1882 .set_rate = clksel_mac_ref_set_rate,
1883 .clksel_con =CRU_CLKSELS_CON(21),
1885 CRU_PARENTS_SET(clk_mac_ref_parents),
1888 static int clk_set_mii_tx_parent(struct clk *clk, struct clk *parent)
1890 return clk_set_parent_nolock(clk->parent,parent);
1893 static struct clk clk_mii_tx = {
1895 .parent = &clk_mac_ref,
1896 //.set_parent = clk_set_mii_tx_parent,
1898 .gate_idx = CLK_GATE_MAC_LBTEST,//???
1901 static struct clk *clk_hsadc_pll_parents[2]={&general_pll_clk,&codec_pll_clk};
1902 static struct clk clk_hsadc_pll_div = {
1903 .name = "hsadc_pll_div",
1904 .parent = &general_pll_clk,
1906 .gate_idx = CLK_GATE_SARADC,
1907 .recalc = clksel_recalc_div,
1908 .round_rate =clk_freediv_round_autosel_parents_rate,
1909 .set_rate = clkset_rate_freediv_autosel_parents,
1910 //.round_rate =clksel_freediv_round_rate,
1911 //.set_rate = clksel_set_rate_freediv,
1912 .clksel_con =CRU_CLKSELS_CON(22),
1913 CRU_DIV_SET(0xff,8,256),
1915 CRU_PARENTS_SET(clk_hsadc_pll_parents),
1918 static int clk_hsadc_fracdiv_set_rate_fixed_parent(struct clk *clk, unsigned long rate)
1920 u32 numerator, denominator;
1921 // clk_hsadc_pll_div->gpll/cpll
1922 //clk->parent->parent
1923 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1924 &numerator,&denominator)==0)
1926 clk_set_rate_nolock(clk->parent,clk->parent->parent->rate);//PLL:DIV 1:
1928 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1930 CRU_PRINTK_DBG("%s set rate=%lu,is ok\n",clk->name,rate);
1934 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1939 static int clk_hsadc_fracdiv_set_rate_auto_parents(struct clk *clk, unsigned long rate)
1941 u32 numerator, denominator;
1943 // clk_hsadc_pll_div->gpll/cpll
1944 //clk->parent->parent
1947 if(frac_div_get_seting(rate,clk->parent->parents[i]->rate,
1948 &numerator,&denominator)==0)
1954 if(clk->parent->parent!=clk->parent->parents[i])
1955 ret=clk_set_parent_nolock(clk->parent, clk->parent->parents[i]);
1958 clk_set_rate_nolock(clk->parent,clk->parent->parents[i]->rate);//PLL:DIV 1:
1960 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1962 CRU_PRINTK_DBG("clk_frac_div %s, rate=%lu\n",clk->name,rate);
1966 CRU_PRINTK_ERR("clk_frac_div can't get rate=%lu,%s\n",rate,clk->name);
1972 static long clk_hsadc_fracdiv_round_rate(struct clk *clk, unsigned long rate)
1974 u32 numerator, denominator;
1976 CRU_PRINTK_ERR("clk_hsadc_fracdiv_round_rate\n");
1977 if(frac_div_get_seting(rate,clk->parent->parent->rate,
1978 &numerator,&denominator)==0)
1983 static struct clk clk_hsadc_frac_div = {
1984 .name = "hsadc_frac_div",
1985 .parent = &clk_hsadc_pll_div,
1987 .recalc = clksel_recalc_frac,
1988 .set_rate = clk_hsadc_fracdiv_set_rate_auto_parents,
1989 .round_rate =clk_hsadc_fracdiv_round_rate,
1990 .gate_idx = CLK_GATE_HSADC_FRAC,
1991 .clksel_con = CRU_CLKSELS_CON(23),
1994 #define HSADC_SRC_DIV 0x0
1995 #define HSADC_SRC_FRAC 0x1
1996 #define HSADC_SRC_EXT 0x2
1997 static int clk_hsadc_set_rate(struct clk *clk, unsigned long rate)
2002 if(clk->parent == clk->parents[HSADC_SRC_EXT]){
2003 CRU_PRINTK_DBG("hsadc clk is form ext\n");
2006 else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_DIV],rate)==rate)
2008 parent =clk->parents[HSADC_SRC_DIV];
2010 else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_FRAC],rate)==rate)
2012 parent = clk->parents[HSADC_SRC_FRAC];
2015 parent =clk->parents[HSADC_SRC_DIV];
2017 CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
2018 clk->name,rate,parent->name,clk->parent->name);
2020 ret = clk_set_rate_nolock(parent,rate);
2023 CRU_PRINTK_ERR("%s set rate%lu err\n",clk->name,rate);
2026 if (clk->parent != parent)
2028 ret = clk_set_parent_nolock(clk, parent);
2031 CRU_PRINTK_ERR("%s can't get rate%lu,reparent err\n",clk->name,rate);
2038 static struct clk clk_hsadc_ext = {
2039 .name = "hsadc_ext",
2042 static struct clk *clk_hsadc_parents[3]={&clk_hsadc_pll_div,&clk_hsadc_frac_div,&clk_hsadc_ext};
2043 static struct clk clk_hsadc = {
2045 .parent = &clk_hsadc_pll_div,
2046 .set_rate = clk_hsadc_set_rate,
2047 .clksel_con = CRU_CLKSELS_CON(22),
2049 CRU_PARENTS_SET(clk_hsadc_parents),
2052 static struct clk *dclk_lcdc_div_parents[]={&codec_pll_clk,&general_pll_clk};
2053 static struct clk dclk_lcdc0_div = {
2054 .name = "dclk_lcdc0_div",
2055 .parent = &general_pll_clk,
2056 .recalc = clksel_recalc_div,
2057 .set_rate = clkset_rate_freediv_autosel_parents,
2058 .clksel_con = CRU_CLKSELS_CON(27),
2059 CRU_DIV_SET(0xff,8,256),
2061 CRU_PARENTS_SET(dclk_lcdc_div_parents),
2064 static int clksel_set_rate_hdmi(struct clk *clk, unsigned long rate)
2068 unsigned long new_rate;
2075 div=clk_get_freediv(rate,clk->parents[i]->rate,clk->div_max);
2076 new_rate= clk->parents[i]->rate/div;
2077 if((rate==new_rate)&&!(clk->parents[i]->rate%div))
2084 CRU_PRINTK_ERR("%s can't set fixed rate%lu\n",clk->name,rate);
2088 //CRU_PRINTK_DBG("%s set rate %lu(from %s)\n",clk->name,rate,clk->parents[i]->name);
2090 old_div=CRU_GET_REG_BIYS_VAL(cru_readl(clk->clksel_con),
2091 clk->div_shift,clk->div_mask)+1;
2093 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
2095 if(clk->parents[i]!=clk->parent)
2097 ret=clk_set_parent_nolock(clk,clk->parents[i]);
2102 CRU_PRINTK_ERR("lcdc1 %s can't get rate%lu,reparent%s(now %s) err\n",
2103 clk->name,rate,clk->parents[i]->name,clk->parent->name);
2106 set_cru_bits_w_msk(div-1,clk->div_mask,clk->div_shift,clk->clksel_con);
2110 static struct clk dclk_lcdc1_div = {
2111 .name = "dclk_lcdc1_div",
2112 .parent = &general_pll_clk,
2113 .recalc = clksel_recalc_div,
2114 .set_rate = clksel_set_rate_hdmi,//clk_freediv_autosel_parents_set_fixed_rate
2115 .clksel_con = CRU_CLKSELS_CON(28),
2116 CRU_DIV_SET(0xff,8,256),
2118 CRU_PARENTS_SET(dclk_lcdc_div_parents),
2121 static int dclk_lcdc_set_rate(struct clk *clk, unsigned long rate)
2126 if (rate == 27 * MHZ&&(rk30_clock_flags&CLK_FLG_EXT_27MHZ)) {
2127 parent =clk->parents[1];
2128 //CRU_PRINTK_DBG(" %s from=%s\n",clk->name,parent->name);
2130 parent=clk->parents[0];
2132 //CRU_PRINTK_DBG(" %s set rate=%lu parent %s(old %s)\n",
2133 //clk->name,rate,parent->name,clk->parent->name);
2135 if(parent!=clk->parents[1])
2137 ret = clk_set_rate_nolock(parent,rate);//div 1:1
2140 CRU_PRINTK_DBG("%s set rate=%lu err\n",clk->name,rate);
2144 if (clk->parent != parent)
2146 ret = clk_set_parent_nolock(clk, parent);
2149 CRU_PRINTK_DBG("%s can't get rate%lu,reparent err\n",clk->name,rate);
2156 static struct clk *dclk_lcdc0_parents[2]={&dclk_lcdc0_div,&xin27m};
2157 static struct clk dclk_lcdc0 = {
2158 .name = "dclk_lcdc0",
2160 .set_rate = dclk_lcdc_set_rate,
2161 .gate_idx = CLK_GATE_DCLK_LCDC0,
2162 .clksel_con = CRU_CLKSELS_CON(27),
2164 CRU_PARENTS_SET(dclk_lcdc0_parents),
2167 static struct clk *dclk_lcdc1_parents[2]={&dclk_lcdc1_div,&xin27m};
2168 static struct clk dclk_lcdc1 = {
2169 .name = "dclk_lcdc1",
2171 .set_rate = dclk_lcdc_set_rate,
2172 .gate_idx = CLK_GATE_DCLK_LCDC1,
2173 .clksel_con = CRU_CLKSELS_CON(28),
2175 CRU_PARENTS_SET(dclk_lcdc1_parents),
2178 static struct clk *cifout_sel_pll_parents[2]={&codec_pll_clk,&general_pll_clk};
2179 static struct clk cif_out_pll = {
2180 .name = "cif_out_pll",
2181 .parent = &general_pll_clk,
2182 .clksel_con = CRU_CLKSELS_CON(29),
2184 CRU_PARENTS_SET(cifout_sel_pll_parents),
2187 static struct clk cif0_out_div = {
2188 .name = "cif0_out_div",
2189 .parent = &cif_out_pll,
2191 .recalc = clksel_recalc_div,
2192 .set_rate = clksel_set_rate_freediv,
2193 .gate_idx =CLK_GATE_CIF0_OUT,
2194 .clksel_con = CRU_CLKSELS_CON(29),
2195 CRU_DIV_SET(0x1f,1,32),
2198 static struct clk cif1_out_div = {
2199 .name = "cif1_out_div",
2200 .parent = &cif_out_pll,
2202 .recalc = clksel_recalc_div,
2203 .set_rate = clksel_set_rate_freediv,
2204 .gate_idx = CLK_GATE_CIF1_OUT,
2205 .clksel_con = CRU_CLKSELS_CON(29),
2206 CRU_DIV_SET(0x1f,8,32),
2210 static int cif_out_set_rate(struct clk *clk, unsigned long rate)
2215 if (rate == 24 * MHZ) {
2216 parent =clk->parents[1];
2218 parent=clk->parents[0];
2219 ret = clk_set_rate_nolock(parent, rate);
2223 if (clk->parent != parent)
2224 ret = clk_set_parent_nolock(clk, parent);
2229 static struct clk *cif0_out_parents[2]={&cif0_out_div,&xin24m};
2230 static struct clk cif0_out = {
2232 .parent = &cif0_out_div,
2233 .set_rate = cif_out_set_rate,
2234 .clksel_con = CRU_CLKSELS_CON(29),
2236 CRU_PARENTS_SET(cif0_out_parents),
2238 static struct clk *cif1_out_parents[2]={&cif1_out_div,&xin24m};
2240 static struct clk cif1_out = {
2242 .parent = &cif1_out_div,
2243 .set_rate = cif_out_set_rate,
2244 .clksel_con = CRU_CLKSELS_CON(29),
2245 CRU_SRC_SET(0x1,15),
2246 CRU_PARENTS_SET(cif1_out_parents),
2249 static struct clk pclkin_cif0 = {
2250 .name = "pclkin_cif0",
2252 .gate_idx =CLK_GATE_PCLKIN_CIF0,
2255 static struct clk inv_cif0 = {
2257 .parent = &pclkin_cif0,
2260 static struct clk *cif0_in_parents[2]={&pclkin_cif0,&inv_cif0};
2261 static struct clk cif0_in = {
2263 .parent = &pclkin_cif0,
2264 .clksel_con = CRU_CLKSELS_CON(30),
2266 CRU_PARENTS_SET(cif0_in_parents),
2269 static struct clk pclkin_cif1 = {
2270 .name = "pclkin_cif1",
2272 .gate_idx =CLK_GATE_PCLKIN_CIF1,
2275 static struct clk inv_cif1 = {
2277 .parent = &pclkin_cif1,
2279 static struct clk *cif1_in_parents[2]={&pclkin_cif1,&inv_cif1};
2281 static struct clk cif1_in = {
2283 .parent = &pclkin_cif1,
2284 .clksel_con = CRU_CLKSELS_CON(30),
2285 CRU_SRC_SET(0x1,12),
2286 CRU_PARENTS_SET(cif1_in_parents),
2289 static struct clk *aclk_lcdc0_ipp_parents[]={&codec_pll_clk,&general_pll_clk};
2291 static struct clk aclk_lcdc0_ipp_parent = {
2292 .name = "aclk_lcdc0_ipp_parent",
2293 .parent = &codec_pll_clk,
2295 .recalc = clksel_recalc_div,
2296 .set_rate = clkset_rate_freediv_autosel_parents,
2297 //.set_rate = clksel_set_rate_freediv,
2298 .gate_idx = CLK_GATE_ACLK_LCDC0_SRC,
2299 .clksel_con = CRU_CLKSELS_CON(31),
2300 CRU_DIV_SET(0x1f,0,32),
2302 CRU_PARENTS_SET(aclk_lcdc0_ipp_parents),
2305 static struct clk *aclk_lcdc1_rga_parents[]={&codec_pll_clk,&general_pll_clk};
2307 static struct clk aclk_lcdc1_rga_parent = {
2308 .name = "aclk_lcdc1_rga_parent",
2309 .parent = &codec_pll_clk,
2311 .recalc = clksel_recalc_div,
2312 .set_rate = clkset_rate_freediv_autosel_parents,
2313 .gate_idx = CLK_GATE_ACLK_LCDC1_SRC,
2314 .clksel_con = CRU_CLKSELS_CON(31),
2315 CRU_DIV_SET(0x1f,8,32),
2316 CRU_SRC_SET(0x1,15),
2317 CRU_PARENTS_SET(aclk_lcdc1_rga_parents),
2322 static unsigned long clksel_recalc_vpu_hclk(struct clk *clk)
2324 unsigned long rate = clk->parent->rate / 4;
2325 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, 4);
2329 static struct clk *aclk_vepu_parents[2]={&codec_pll_clk,&general_pll_clk};
2331 static struct clk aclk_vepu = {
2332 .name = "aclk_vepu",
2333 .parent = &codec_pll_clk,
2335 .recalc = clksel_recalc_div,
2336 //.set_rate = clksel_set_rate_freediv,
2337 .set_rate =clkset_rate_freediv_autosel_parents,
2338 .clksel_con = CRU_CLKSELS_CON(32),
2339 .gate_idx = CLK_GATE_ACLK_VEPU,
2340 CRU_DIV_SET(0x1f,0,32),
2342 CRU_PARENTS_SET(aclk_vepu_parents),
2345 static struct clk hclk_vepu = {
2346 .name = "hclk_vepu",
2347 .parent = &aclk_vepu,
2349 .recalc = clksel_recalc_vpu_hclk,
2350 .clksel_con = CRU_CLKSELS_CON(32),
2351 .gate_idx = CLK_GATE_HCLK_VEPU,
2354 static struct clk *aclk_vdpu_parents[2]={&codec_pll_clk,&general_pll_clk};
2356 static struct clk aclk_vdpu = {
2357 .name = "aclk_vdpu",
2359 .recalc = clksel_recalc_div,
2360 //.set_rate = clksel_set_rate_freediv,
2361 .set_rate =clkset_rate_freediv_autosel_parents,
2362 .clksel_con = CRU_CLKSELS_CON(32),
2363 .gate_idx = CLK_GATE_ACLK_VDPU,
2364 CRU_DIV_SET(0x1f,8,32),
2365 CRU_SRC_SET(0x1,15),
2366 CRU_PARENTS_SET(aclk_vdpu_parents),
2368 static struct clk hclk_vdpu = {
2369 .name = "hclk_vdpu",
2370 .parent = &aclk_vdpu,
2372 .recalc = clksel_recalc_vpu_hclk,
2373 .clksel_con = CRU_CLKSELS_CON(32),
2374 .gate_idx = CLK_GATE_HCLK_VDPU,
2378 static int clk_gpu_set_rate(struct clk *clk, unsigned long rate)
2380 unsigned long max_rate = rate / 100 * 105; /* +5% */
2381 return clkset_rate_freediv_autosel_parents(clk,max_rate);
2384 static struct clk *gpu_parents[2]={&codec_pll_clk,&general_pll_clk};
2386 static struct clk clk_gpu = {
2389 .recalc = clksel_recalc_div,
2390 .round_rate = clk_freediv_round_autosel_parents_rate,
2391 .set_rate = clkset_rate_freediv_autosel_parents,
2392 .clksel_con = CRU_CLKSELS_CON(33),
2393 .gate_idx = CLK_GATE_GPU_SRC,
2394 CRU_DIV_SET(0x1f,0,32),
2396 CRU_PARENTS_SET(gpu_parents),
2399 /*********************power domain*******************************/
2400 #ifdef RK30_CLK_OFFBOARD_TEST
2401 void pmu_set_power_domain_test(enum pmu_power_domain pd, bool on){};
2402 #define _pmu_set_power_domain pmu_set_power_domain_test//rk30_pmu_set_power_domain
2404 void pmu_set_power_domain(enum pmu_power_domain pd, bool on);
2405 #define _pmu_set_power_domain pmu_set_power_domain
2407 static int pm_off_mode(struct clk *clk, int on)
2409 _pmu_set_power_domain(clk->gate_idx,on);//on 1
2412 static struct clk pd_peri = {
2415 .mode = pm_off_mode,
2416 .gate_idx = PD_PERI,
2419 static int pd_display_mode(struct clk *clk, int on)
2423 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2424 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2425 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2426 gate[3] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2427 gate[4] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2428 gate[5] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2429 gate[6] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2430 gate[7] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2431 gate[8] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2432 gate[9] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2433 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2434 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2435 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2436 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2437 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2438 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2439 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2440 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2441 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2442 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2443 pmu_set_power_domain(PD_VIO, on);
2444 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2445 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2446 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2447 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1) | gate[3], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2448 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0) | gate[4], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2449 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1) | gate[5], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2450 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0) | gate[6], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2451 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1) | gate[7], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2452 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP) | gate[8], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2453 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA) | gate[9], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2458 static struct clk pd_display = {
2459 .name = "pd_display",
2461 .mode = pd_display_mode,
2465 static struct clk pd_lcdc0 = {
2466 .parent = &pd_display,
2469 static struct clk pd_lcdc1 = {
2470 .parent = &pd_display,
2473 static struct clk pd_cif0 = {
2474 .parent = &pd_display,
2477 static struct clk pd_cif1 = {
2478 .parent = &pd_display,
2481 static struct clk pd_rga = {
2482 .parent = &pd_display,
2485 static struct clk pd_ipp = {
2486 .parent = &pd_display,
2490 static int pd_video_mode(struct clk *clk, int on)
2494 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2495 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2496 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2497 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2498 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2499 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2500 pmu_set_power_domain(PD_VIDEO, on);
2501 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2502 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2503 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2508 static struct clk pd_video = {
2511 .mode = pd_video_mode,
2512 .gate_idx = PD_VIDEO,
2515 static int pd_gpu_mode(struct clk *clk, int on)
2519 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2520 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2521 cru_writel(CLK_GATE_W_MSK(CLK_GATE_GPU_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2522 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2523 pmu_set_power_domain(PD_GPU, on);
2524 cru_writel(CLK_GATE_W_MSK(CLK_GATE_GPU_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_GPU_SRC));
2525 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2530 static struct clk pd_gpu = {
2533 .mode = pd_gpu_mode,
2536 static struct clk pd_dbg = {
2539 .mode = pm_off_mode,
2543 #define PD_CLK(name) \
2551 /************************rk30 fixed div clock****************************************/
2553 /*************************aclk_cpu***********************/
2555 GATE_CLK(dma1, aclk_cpu, ACLK_DMAC1);
2556 GATE_CLK(l2mem_con, aclk_cpu, ACLK_L2MEM_CON);
2557 GATE_CLK(intmem, aclk_cpu, ACLK_INTMEM);
2558 GATE_CLK(aclk_strc_sys, aclk_cpu, ACLK_STRC_SYS);
2560 /*************************hclk_cpu***********************/
2562 GATE_CLK(rom, hclk_cpu, HCLK_ROM);
2563 GATE_CLK(hclk_i2s0_2ch, hclk_cpu, HCLK_I2S0_2CH);
2564 GATE_CLK(hclk_i2s1_2ch, hclk_cpu, HCLK_I2S1_2CH);
2565 GATE_CLK(hclk_spdif, hclk_cpu, HCLK_SPDIF);
2566 GATE_CLK(hclk_i2s_8ch, hclk_cpu, HCLK_I2S_8CH);
2567 GATE_CLK(hclk_cpubus, hclk_cpu, HCLK_CPUBUS);
2568 GATE_CLK(hclk_ahb2apb, hclk_cpu, HCLK_AHB2APB);
2569 GATE_CLK(hclk_vio_bus, hclk_cpu, HCLK_VIO_BUS);
2570 GATE_CLK(hclk_lcdc0, hclk_cpu, HCLK_LCDC0);
2571 GATE_CLK(hclk_lcdc1, hclk_cpu, HCLK_LCDC1);
2572 GATE_CLK(hclk_cif0, hclk_cpu, HCLK_CIF0);
2573 GATE_CLK(hclk_cif1, hclk_cpu, HCLK_CIF1);
2574 GATE_CLK(hclk_ipp, hclk_cpu, HCLK_IPP);
2575 GATE_CLK(hclk_rga, hclk_cpu, HCLK_RGA);
2576 GATE_CLK(hclk_hdmi, hclk_cpu, HCLK_HDMI);
2577 //GATE_CLK(hclk_vidoe_h2h, hclk_cpu, ); ???
2578 /*************************pclk_cpu***********************/
2579 GATE_CLK(pwm01, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2580 //GATE_CLK(pclk_pwm1, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2581 GATE_CLK(pclk_timer0, pclk_cpu, PCLK_TIMER0);
2582 GATE_CLK(pclk_timer1, pclk_cpu, PCLK_TIMER1);
2583 GATE_CLK(pclk_timer2, pclk_cpu, PCLK_TIMER2);
2584 GATE_CLK(i2c0, pclk_cpu, PCLK_I2C0);
2585 GATE_CLK(i2c1, pclk_cpu, PCLK_I2C1);
2586 GATE_CLK(gpio0, pclk_cpu, PCLK_GPIO0);
2587 GATE_CLK(gpio1, pclk_cpu, PCLK_GPIO1);
2588 GATE_CLK(gpio2, pclk_cpu, PCLK_GPIO2);
2589 GATE_CLK(gpio6, pclk_cpu, PCLK_GPIO6);
2590 GATE_CLK(efuse, pclk_cpu, PCLK_EFUSE);
2591 GATE_CLK(tzpc, pclk_cpu, PCLK_TZPC);
2592 GATE_CLK(pclk_uart0, pclk_cpu, PCLK_UART0);
2593 GATE_CLK(pclk_uart1, pclk_cpu, PCLK_UART1);
2594 GATE_CLK(pclk_ddrupctl, pclk_cpu, PCLK_DDRUPCTL);
2595 GATE_CLK(pclk_ddrpubl, pclk_cpu, PCLK_PUBL);
2596 GATE_CLK(dbg, pclk_cpu, PCLK_DBG);
2597 GATE_CLK(grf, pclk_cpu, PCLK_GRF);
2598 GATE_CLK(pmu, pclk_cpu, PCLK_PMU);
2600 /*************************aclk_periph***********************/
2602 GATE_CLK(dma2, aclk_periph,ACLK_DMAC2);
2603 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
2604 GATE_CLK(aclk_peri_niu, aclk_periph, ACLK_PEI_NIU);
2605 GATE_CLK(aclk_cpu_peri, aclk_periph, ACLK_CPU_PERI);
2606 GATE_CLK(aclk_peri_axi_matrix, aclk_periph, ACLK_PERI_AXI_MATRIX);
2608 /*************************hclk_periph***********************/
2609 GATE_CLK(hclk_peri_axi_matrix, hclk_periph, HCLK_PERI_AXI_MATRIX);
2610 GATE_CLK(hclk_peri_ahb_arbi, hclk_periph, HCLK_PERI_AHB_ARBI);
2611 GATE_CLK(hclk_emem_peri, hclk_periph, HCLK_EMEM_PERI);
2612 GATE_CLK(hclk_mac, hclk_periph, HCLK_EMAC);
2613 GATE_CLK(nandc, hclk_periph, HCLK_NANDC);
2614 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
2615 GATE_CLK(hclk_otg0, clk_hclk_usb_peri, HCLK_OTG0);
2616 GATE_CLK(hclk_otg1, clk_hclk_usb_peri, HCLK_OTG1);
2617 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
2618 GATE_CLK(hclk_pidfilter, hclk_periph, HCLK_PIDF);
2619 GATE_CLK(hclk_sdmmc, hclk_periph, HCLK_SDMMC0);
2620 GATE_CLK(hclk_sdio, hclk_periph, HCLK_SDIO);
2621 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
2622 /*************************pclk_periph***********************/
2623 GATE_CLK(pclk_peri_axi_matrix, pclk_periph, PCLK_PERI_AXI_MATRIX);
2624 GATE_CLK(pwm23, pclk_periph, PCLK_PWM23);
2625 //GATE_CLK(pclk_pwm3, pclk_periph, PCLK_PWM3);
2626 GATE_CLK(wdt, pclk_periph, PCLK_WDT);
2627 GATE_CLK(pclk_spi0, pclk_periph, PCLK_SPI0);
2628 GATE_CLK(pclk_spi1, pclk_periph, PCLK_SPI1);
2629 GATE_CLK(pclk_uart2, pclk_periph, PCLK_UART2);
2630 GATE_CLK(pclk_uart3, pclk_periph, PCLK_UART3);
2631 GATE_CLK(i2c2, pclk_periph, PCLK_I2C2);
2632 GATE_CLK(i2c3, pclk_periph, PCLK_I2C3);
2633 GATE_CLK(i2c4, pclk_periph, PCLK_I2C4);
2634 GATE_CLK(gpio3, pclk_periph, PCLK_GPIO3);
2635 GATE_CLK(gpio4, pclk_periph, PCLK_GPIO4);
2636 GATE_CLK(pclk_saradc, pclk_periph, PCLK_SARADC);
2637 GATE_CLK(pclk_tsadc, pclk_periph, PCLK_TSADC);
2638 /*************************aclk_lcdc0***********************/
2639 GATE_CLK(aclk_lcdc0, aclk_lcdc0_ipp_parent, ACLK_LCDC0);
2640 GATE_CLK(aclk_vio0, aclk_lcdc0_ipp_parent, ACLK_VIO0);
2641 GATE_CLK(aclk_cif0, aclk_lcdc0_ipp_parent, ACLK_CIF0);
2642 GATE_CLK(aclk_ipp, aclk_lcdc0_ipp_parent, ACLK_IPP);
2644 /*************************aclk_lcdc0***********************/
2646 GATE_CLK(aclk_lcdc1, aclk_lcdc1_rga_parent, ACLK_LCDC1);
2647 GATE_CLK(aclk_vio1, aclk_lcdc1_rga_parent, ACLK_VIO1);
2648 GATE_CLK(aclk_cif1, aclk_lcdc1_rga_parent, ACLK_CIF0);
2649 GATE_CLK(aclk_rga, aclk_lcdc1_rga_parent, ACLK_RGA);
2653 #define CLK(dev, con, ck) \
2661 #define CLK1(name) \
2665 .clk = &clk_##name,\
2673 static struct clk_lookup clks[] = {
2674 CLK(NULL, "xin24m", &xin24m),
2675 CLK(NULL, "xin27m", &xin27m),
2676 CLK(NULL, "xin12m", &clk_12m),
2677 CLK(NULL, "arm_pll", &arm_pll_clk),
2678 CLK(NULL, "ddr_pll", &ddr_pll_clk),
2679 CLK(NULL, "codec_pll", &codec_pll_clk),
2680 CLK(NULL, "general_pll", &general_pll_clk),
2682 CLK(NULL, "ddr", &clk_ddr),
2683 //CLK(NULL, "core_gpll_path", &clk_cpu_gpll_path),
2684 CLK(NULL, "cpu", &clk_cpu),
2685 CLK(NULL, "arm_gpll", &clk_cpu_gpll_path),
2686 CLK("smp_twd", NULL, &core_periph),
2687 CLK(NULL, "aclk_cpu", &aclk_cpu),
2688 CLK(NULL, "hclk_cpu", &hclk_cpu),
2689 CLK(NULL, "pclk_cpu", &pclk_cpu),
2690 CLK(NULL, "atclk_cpu", &atclk_cpu),
2694 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
2695 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
2696 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
2697 CLK("rk29_i2s.0", "hclk_i2s", &clk_hclk_i2s_8ch),
2699 CLK("rk29_i2s.1", "i2s_div", &clk_i2s1_div),
2700 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s1_frac_div),
2701 CLK("rk29_i2s.1", "i2s", &clk_i2s1),
2702 CLK("rk29_i2s.1", "hclk_i2s", &clk_hclk_i2s0_2ch),
2704 CLK("rk29_i2s.2", "i2s_div", &clk_i2s2_div),
2705 CLK("rk29_i2s.2", "i2s_frac_div", &clk_i2s2_frac_div),
2706 CLK("rk29_i2s.2", "i2s", &clk_i2s2),
2707 CLK("rk29_i2s.2", "hclk_i2s", &clk_hclk_i2s1_2ch),
2710 CLK1(spdif_frac_div),
2714 CLK(NULL, "aclk_periph", &aclk_periph),
2715 CLK(NULL, "pclk_periph", &pclk_periph),
2716 CLK(NULL, "hclk_periph", &hclk_periph),
2718 CLK("rk29xx_spim.0", "spi", &clk_spi0),
2719 CLK("rk29xx_spim.0", "pclk_spi", &clk_pclk_spi0),
2721 CLK("rk29xx_spim.1", "spi", &clk_spi1),
2722 CLK("rk29xx_spim.1", "pclk_spi", &clk_pclk_spi1),
2730 CLK1(hclk_usb_peri),
2741 CLK("rk29_sdmmc.0", "mmc", &clk_sdmmc),
2742 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_sdmmc),
2743 CLK("rk29_sdmmc.1", "mmc", &clk_sdio),
2744 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_sdio),
2751 CLK("rk_serial.0", "uart_div", &clk_uart0_div),
2752 CLK("rk_serial.0", "uart_frac_div", &clk_uart0_frac_div),
2753 CLK("rk_serial.0", "uart", &clk_uart0),
2754 CLK("rk_serial.0", "pclk_uart", &clk_pclk_uart0),
2755 CLK("rk_serial.1", "uart_div", &clk_uart1_div),
2756 CLK("rk_serial.1", "uart_frac_div", &clk_uart1_frac_div),
2757 CLK("rk_serial.1", "uart", &clk_uart1),
2758 CLK("rk_serial.1", "pclk_uart", &clk_pclk_uart1),
2759 CLK("rk_serial.2", "uart_div", &clk_uart2_div),
2760 CLK("rk_serial.2", "uart_frac_div", &clk_uart2_frac_div),
2761 CLK("rk_serial.2", "uart", &clk_uart2),
2762 CLK("rk_serial.2", "pclk_uart", &clk_pclk_uart2),
2763 CLK("rk_serial.3", "uart_div", &clk_uart3_div),
2764 CLK("rk_serial.3", "uart_frac_div", &clk_uart3_frac_div),
2765 CLK("rk_serial.3", "uart", &clk_uart3),
2766 CLK("rk_serial.3", "pclk_uart", &clk_pclk_uart3),
2777 CLK(NULL, "rmii_clkin", &rmii_clkin),
2778 CLK(NULL, "mac_ref_div", &clk_mac_pll_div), // compatible with rk29
2781 CLK1(hsadc_pll_div),
2782 CLK1(hsadc_frac_div),
2787 CLK(NULL, "aclk_lcdc0_ipp_parent", &aclk_lcdc0_ipp_parent),
2788 CLK(NULL, "aclk_lcdc1_rga_parent", &aclk_lcdc1_rga_parent),
2790 CLK(NULL, "dclk_lcdc0_div", &dclk_lcdc0_div),
2791 CLK(NULL, "dclk_lcdc1_div", &dclk_lcdc1_div),
2793 CLK(NULL, "dclk_lcdc0", &dclk_lcdc0),
2794 CLK(NULL, "aclk_lcdc0", &clk_aclk_lcdc0),
2797 CLK(NULL, "dclk_lcdc1", &dclk_lcdc1),
2798 CLK(NULL, "aclk_lcdc1", &clk_aclk_lcdc1),
2801 CLK(NULL, "cif_out_pll", &cif_out_pll),
2802 CLK(NULL, "cif0_out_div", &cif0_out_div),
2803 CLK(NULL, "cif1_out_div", &cif1_out_div),
2805 CLK(NULL, "cif0_out", &cif0_out),
2808 CLK(NULL, "cif1_out", &cif1_out),
2815 CLK(NULL, "pclkin_cif0", &pclkin_cif0),
2816 CLK(NULL, "inv_cif0", &inv_cif0),
2817 CLK(NULL, "cif0_in", &cif0_in),
2818 CLK(NULL, "pclkin_cif1", &pclkin_cif1),
2819 CLK(NULL, "inv_cif1", &inv_cif1),
2820 CLK(NULL, "cif1_in", &cif1_in),
2821 //CLK(NULL, "aclk_lcdc0", &aclk_lcdc0),
2822 //CLK(NULL, "aclk_lcdc1", &aclk_lcdc1),
2823 CLK(NULL, "aclk_vepu", &aclk_vepu),
2824 CLK(NULL, "hclk_vepu", &hclk_vepu),
2825 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
2826 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
2832 CLK1(aclk_strc_sys),
2834 /*************************hclk_cpu***********************/
2837 //CLK1(hclk_i2s0_2ch),
2838 //CLK1(hclk_i2s1_2ch),
2840 //CLK1(hclk_i2s_8ch),
2851 //CLK1(hclk_vidoe_h2h, hclk_cpu, ); ???
2852 /*************************pclk_cpu***********************/
2853 CLK1(pwm01),//pwm 0¡¢1
2855 //CLK1(pclk_timer0),
2856 //CLK1(pclk_timer1),
2857 //CLK1(pclk_timer2),
2859 CLK("rk30_i2c.0", "i2c", &clk_i2c0),
2860 CLK("rk30_i2c.1", "i2c", &clk_i2c1),
2870 CLK1(pclk_ddrupctl),
2876 /*************************aclk_periph***********************/
2880 CLK1(aclk_peri_niu),
2881 CLK1(aclk_cpu_peri),
2882 CLK1(aclk_peri_axi_matrix),
2884 /*************************hclk_periph***********************/
2885 CLK1(hclk_peri_axi_matrix),
2886 CLK1(hclk_peri_ahb_arbi),
2887 CLK1(hclk_emem_peri),
2890 //CLK1(hclk_usb_peri),
2891 //CLK1(hclk_usbotg0),
2892 //CLK1(hclk_usbotg1),
2894 CLK1(hclk_pidfilter),
2897 /*************************pclk_periph***********************/
2898 CLK1(pclk_peri_axi_matrix),
2907 CLK("rk30_i2c.2", "i2c", &clk_i2c2),
2908 CLK("rk30_i2c.3", "i2c", &clk_i2c3),
2909 CLK("rk30_i2c.4", "i2c", &clk_i2c4),
2914 /*************************aclk_lcdc0***********************/
2919 /*************************aclk_lcdc0***********************/
2923 /************************power domain**********************/
2937 static void __init rk30_init_enable_clocks(void)
2939 //clk_enable_nolock(&xin24m);
2940 //clk_enable_nolock(&xin27m);
2941 //clk_enable_nolock(&clk_12m);
2942 //clk_enable_nolock(&arm_pll_clk);
2943 //clk_enable_nolock(&ddr_pll_clk);
2944 //clk_enable_nolock(&codec_pll_clk);
2945 //clk_enable_nolock(&general_pll_clk);
2946 //clk_enable_nolock(&clk_ddr);
2948 clk_enable_nolock(&clk_cpu);
2949 clk_enable_nolock(&core_periph);
2950 clk_enable_nolock(&aclk_cpu);
2951 clk_enable_nolock(&hclk_cpu);
2952 clk_enable_nolock(&pclk_cpu);
2953 clk_enable_nolock(&atclk_cpu);
2956 clk_enable_nolock(&clk_i2s_pll);
2957 clk_enable_nolock(&clk_i2s0_div);
2958 clk_enable_nolock(&clk_i2s0_frac_div);
2959 clk_enable_nolock(&clk_i2s0);
2960 clk_enable_nolock(&clk_hclk_i2s_8ch);
2962 clk_enable_nolock(&clk_i2s1_div);
2963 clk_enable_nolock(&clk_i2s1_frac_div);
2964 clk_enable_nolock(&clk_i2s1);
2965 clk_enable_nolock(&clk_hclk_i2s0_2ch);
2967 clk_enable_nolock(&clk_i2s2_div);
2968 clk_enable_nolock(&clk_i2s2_frac_div);
2969 clk_enable_nolock(&clk_i2s2);
2970 clk_enable_nolock(&clk_hclk_i2s1_2ch);
2972 clk_enable_nolock(&clk_spdif_div);
2973 clk_enable_nolock(&clk_spdif_frac_div);
2974 clk_enable_nolock(&clk_spdif);
2975 clk_enable_nolock(&clk_hclk_spdif);
2977 clk_enable_nolock(&aclk_periph);
2978 clk_enable_nolock(&pclk_periph);
2979 clk_enable_nolock(&hclk_periph);
2982 clk_enable_nolock(&clk_spi0);
2983 clk_enable_nolock(&clk_pclk_spi0);
2985 clk_enable_nolock(&clk_spi1);
2986 clk_enable_nolock(&clk_pclk_spi1);
2987 clk_enable_nolock(&clk_saradc);
2988 clk_enable_nolock(&clk_pclk_saradc);
2989 clk_enable_nolock(&clk_tsadc);
2990 clk_enable_nolock(&clk_pclk_tsadc);
2993 clk_enable_nolock(&clk_otgphy0);
2994 clk_enable_nolock(&clk_otgphy1);
2995 clk_enable_nolock(&clk_hclk_usb_peri);
2996 clk_enable_nolock(&clk_hclk_otg0);
2997 clk_enable_nolock(&clk_hclk_otg1);
3000 clk_enable_nolock(&clk_smc);
3001 clk_enable_nolock(&clk_aclk_smc);
3003 clk_enable_nolock(&clk_sdmmc);
3004 clk_enable_nolock(&clk_hclk_sdmmc);
3005 clk_enable_nolock(&clk_sdio);
3006 clk_enable_nolock(&clk_hclk_sdio);
3008 clk_enable_nolock(&clk_emmc);
3009 clk_enable_nolock(&clk_hclk_emmc);
3013 #if CONFIG_RK_DEBUG_UART == 0
3014 clk_enable_nolock(&clk_uart0);
3015 clk_enable_nolock(&clk_pclk_uart0);
3016 #elif CONFIG_RK_DEBUG_UART == 1
3017 clk_enable_nolock(&clk_uart1);
3018 clk_enable_nolock(&clk_pclk_uart1);
3020 #elif CONFIG_RK_DEBUG_UART == 2
3021 clk_enable_nolock(&clk_uart2);
3022 clk_enable_nolock(&clk_pclk_uart2);
3024 #elif CONFIG_RK_DEBUG_UART == 3
3025 clk_enable_nolock(&clk_uart3);
3026 clk_enable_nolock(&clk_pclk_uart3);
3031 clk_enable_nolock(&clk_timer0);
3032 clk_enable_nolock(&clk_pclk_timer0);
3034 clk_enable_nolock(&clk_timer1);
3035 clk_enable_nolock(&clk_pclk_timer1);
3037 clk_enable_nolock(&clk_timer2);
3038 clk_enable_nolock(&clk_pclk_timer2);
3041 clk_enable_nolock(&rmii_clkin);
3042 clk_enable_nolock(&clk_mac_pll_div);
3043 clk_enable_nolock(&clk_mac_ref);
3044 clk_enable_nolock(&clk_mii_tx);
3048 clk_enable_nolock(&clk_hsadc_pll_div);
3049 clk_enable_nolock(&clk_hsadc_frac_div);
3050 clk_enable_nolock(&clk_hsadc_ext);
3051 clk_enable_nolock(&clk_hsadc);
3052 clk_enable_nolock(&clk_hclk_hsadc);
3056 clk_enable_nolock(&aclk_lcdc0_ipp_parent);
3057 clk_enable_nolock(&aclk_lcdc1_rga_parent);
3059 clk_enable_nolock(&dclk_lcdc0_div);
3060 clk_enable_nolock(&dclk_lcdc1_div);
3062 clk_enable_nolock(&dclk_lcdc0);
3063 clk_enable_nolock(&clk_aclk_lcdc0);
3064 clk_enable_nolock(&clk_hclk_lcdc0);
3066 clk_enable_nolock(&dclk_lcdc1);
3067 clk_enable_nolock(&clk_aclk_lcdc1);
3068 clk_enable_nolock(&clk_hclk_lcdc1);
3070 clk_enable_nolock(&cif_out_pll);
3071 clk_enable_nolock(&cif0_out_div);
3072 clk_enable_nolock(&cif1_out_div);
3074 clk_enable_nolock(&cif0_out);
3075 clk_enable_nolock(&clk_hclk_cif0);
3077 clk_enable_nolock(&cif1_out);
3078 clk_enable_nolock(&clk_hclk_cif1);
3080 clk_enable_nolock(&clk_hclk_ipp);
3081 clk_enable_nolock(&clk_hclk_rga);
3082 clk_enable_nolock(&clk_hclk_hdmi);
3084 clk_enable_nolock(&pclkin_cif0);
3085 clk_enable_nolock(&inv_cif0);
3086 clk_enable_nolock(&cif0_in);
3087 clk_enable_nolock(&pclkin_cif1);
3088 clk_enable_nolock(&inv_cif1);
3089 clk_enable_nolock(&cif1_in);
3090 //CLK(NULL, "aclk_lcdc0", &aclk_lcdc0),
3091 //CLK(NULL, "aclk_lcdc1", &aclk_lcdc1),
3092 clk_enable_nolock(&aclk_vepu);
3093 clk_enable_nolock(&hclk_vepu);
3094 clk_enable_nolock(&aclk_vdpu);
3095 clk_enable_nolock(&hclk_vdpu);
3096 clk_enable_nolock(&clk_gpu);
3099 clk_enable_nolock(&clk_dma1);
3100 clk_enable_nolock(&clk_l2mem_con);
3101 clk_enable_nolock(&clk_intmem);
3103 clk_enable_nolock(&clk_aclk_strc_sys);
3105 /*************************hclk_cpu***********************/
3107 clk_enable_nolock(&clk_rom);
3109 clk_enable_nolock(&clk_hclk_cpubus);
3110 clk_enable_nolock(&clk_hclk_ahb2apb);
3111 clk_enable_nolock(&clk_hclk_vio_bus);
3113 /*************************pclk_cpu***********************/
3115 //clk_enable_nolock(&clk_pwm01);//pwm 0¡¢1
3119 clk_enable_nolock(&clk_i2c0);
3120 clk_enable_nolock(&clk_i2c1);
3122 clk_enable_nolock(&clk_gpio0);
3123 clk_enable_nolock(&clk_gpio1);
3124 clk_enable_nolock(&clk_gpio2);
3125 clk_enable_nolock(&clk_gpio6);
3126 clk_enable_nolock(&clk_efuse);
3128 clk_enable_nolock(&clk_tzpc);
3132 clk_enable_nolock(&clk_pclk_ddrupctl);
3133 clk_enable_nolock(&clk_pclk_ddrpubl);
3134 clk_enable_nolock(&clk_dbg);
3135 clk_enable_nolock(&clk_grf);
3136 clk_enable_nolock(&clk_pmu);
3138 /*************************aclk_periph***********************/
3140 clk_enable_nolock(&clk_dma2);
3142 clk_enable_nolock(&clk_aclk_peri_niu);
3143 clk_enable_nolock(&clk_aclk_cpu_peri);
3144 clk_enable_nolock(&clk_aclk_peri_axi_matrix);
3146 /*************************hclk_periph***********************/
3147 clk_enable_nolock(&clk_hclk_peri_axi_matrix);
3148 clk_enable_nolock(&clk_hclk_peri_ahb_arbi);
3149 clk_enable_nolock(&clk_hclk_emem_peri);
3150 clk_enable_nolock(&clk_hclk_mac);
3151 clk_enable_nolock(&clk_nandc);
3152 //CLK1(hclk_usb_peri),
3153 //CLK1(hclk_usbotg0),
3154 //CLK1(hclk_usbotg1),
3156 clk_enable_nolock(&clk_hclk_pidfilter);
3158 /*************************pclk_periph***********************/
3159 clk_enable_nolock(&clk_pclk_peri_axi_matrix);
3160 //clk_enable_nolock(&clk_pwm23);
3162 //clk_enable_nolock(&clk_wdt);
3166 clk_enable_nolock(&clk_i2c2);
3167 clk_enable_nolock(&clk_i2c3);
3168 clk_enable_nolock(&clk_i2c4);
3170 clk_enable_nolock(&clk_gpio3);
3171 clk_enable_nolock(&clk_gpio4);
3173 /*************************aclk_lcdc0***********************/
3174 //clk_enable_nolock(&clk_aclk_vio0);
3175 //clk_enable_nolock(&clk_aclk_cif0);
3176 //clk_enable_nolock(&clk_aclk_ipp);
3178 /*************************aclk_lcdc0***********************/
3179 //clk_enable_nolock(&clk_aclk_vio1);
3180 //clk_enable_nolock(&clk_aclk_cif1);
3181 //clk_enable_nolock(&clk_aclk_rga);
3182 /************************power domain**********************/
3184 static void periph_clk_set_init(void)
3186 unsigned long aclk_p, hclk_p, pclk_p;
3187 unsigned long ppll_rate=general_pll_clk.rate;
3191 switch (ppll_rate) {
3193 aclk_p = 148500*KHZ;
3198 aclk_p = aclk_p>>3;// 0
3203 aclk_p = ppll_rate>>1;
3209 aclk_p = ppll_rate>>1;
3219 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3220 clk_set_rate_nolock(&aclk_periph, aclk_p);
3221 clk_set_rate_nolock(&hclk_periph, hclk_p);
3222 clk_set_rate_nolock(&pclk_periph, pclk_p);
3226 void rk30_clock_common_i2s_init(void)
3228 struct clk *max_clk,*min_clk;
3229 unsigned long i2s_rate;
3231 if(rk30_clock_flags&CLK_FLG_MAX_I2S_49152KHZ)
3234 }else if(rk30_clock_flags&CLK_FLG_MAX_I2S_24576KHZ)
3238 else if(rk30_clock_flags&CLK_FLG_MAX_I2S_22579_2KHZ)
3242 else if(rk30_clock_flags&CLK_FLG_MAX_I2S_12288KHZ)
3251 if(((i2s_rate*20)<=general_pll_clk.rate)||!(general_pll_clk.rate%i2s_rate))
3253 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3255 else if(((i2s_rate*20)<=codec_pll_clk.rate)||!(codec_pll_clk.rate%i2s_rate))
3257 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3261 if(general_pll_clk.rate>codec_pll_clk.rate)
3262 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3264 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3273 static void __init rk30_clock_common_init(unsigned long gpll_rate,unsigned long cpll_rate)
3276 clk_set_rate_nolock(&clk_cpu, 816*MHZ);//816
3278 clk_set_rate_nolock(&general_pll_clk, gpll_rate);
3280 clk_set_rate_nolock(&codec_pll_clk, cpll_rate);
3283 periph_clk_set_init();
3286 rk30_clock_common_i2s_init();
3289 clk_set_rate_nolock(&clk_spi0, clk_spi0.parent->rate);
3290 clk_set_rate_nolock(&clk_spi1, clk_spi1.parent->rate);
3294 clk_set_parent_nolock(&clk_uart_pll, &codec_pll_clk);
3296 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3299 if(!(gpll_rate%(50*MHZ)))
3300 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3301 else if(!(ddr_pll_clk.rate%(50*MHZ)))
3302 clk_set_parent_nolock(&clk_mac_pll_div, &ddr_pll_clk);
3304 CRU_PRINTK_ERR("mac can't get 50mhz\n");
3308 //clk_set_parent_nolock(&clk_hsadc_pll_div, &general_pll_clk);
3311 clk_set_parent_nolock(&dclk_lcdc1_div, &general_pll_clk);
3313 //lcdc0 lcd auto sel pll
3314 //clk_set_parent_nolock(&dclk_lcdc0_div, &general_pll_clk);
3317 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3320 //clk_set_parent_nolock(&aclk_lcdc0, &general_pll_clk);
3321 //clk_set_parent_nolock(&aclk_lcdc1, &general_pll_clk);
3322 clk_set_rate_nolock(&aclk_lcdc0_ipp_parent, 300*MHZ);
3323 clk_set_rate_nolock(&aclk_lcdc1_rga_parent, 300*MHZ);
3326 //clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
3327 //clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
3329 clk_set_rate_nolock(&aclk_vepu, 300*MHZ);
3330 clk_set_rate_nolock(&aclk_vdpu, 300*MHZ);
3332 //clk_set_parent_nolock(&clk_gpu, &general_pll_clk);
3335 static struct clk def_ops_clk={
3336 .get_parent=clksel_get_parent,
3337 .set_parent=clksel_set_parent,
3340 #ifdef CONFIG_PROC_FS
3341 struct clk_dump_ops dump_ops;
3344 static void clk_dump_regs(void);
3346 void __init _rk30_clock_data_init(unsigned long gpll,unsigned long cpll,int flags)
3348 struct clk_lookup *lk;
3350 clk_register_dump_ops(&dump_ops);
3351 clk_register_default_ops_clk(&def_ops_clk);
3352 rk30_clock_flags=flags;
3353 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
3354 #ifdef RK30_CLK_OFFBOARD_TEST
3355 rk30_clkdev_add(lk);
3359 clk_register(lk->clk);
3361 clk_recalculate_root_clocks_nolock();
3363 loops_per_jiffy = CLK_LOOPS_RECALC(arm_pll_clk.rate);
3366 * Only enable those clocks we will need, let the drivers
3367 * enable other clocks as necessary
3369 rk30_init_enable_clocks();
3372 * Disable any unused clocks left on by the bootloader
3374 //clk_disable_unused();
3375 rk30_clock_common_init(gpll,cpll);
3376 preset_lpj = loops_per_jiffy;
3379 //regfile_writel(0xc0004000,0x10c);
3380 //cru_writel(0x07000000,CRU_MISC_CON);
3384 void __init rk30_clock_data_init(unsigned long gpll,unsigned long cpll,u32 flags)
3386 _rk30_clock_data_init(gpll,cpll,flags);
3391 * You can override arm_clk rate with armclk= cmdline option.
3393 static int __init armclk_setup(char *str)
3395 get_option(&str, &armclk);
3401 //clk_set_rate_nolock(&arm_pll_clk, armclk);
3404 #ifndef RK30_CLK_OFFBOARD_TEST
3405 early_param("armclk", armclk_setup);
3410 #ifdef CONFIG_PROC_FS
3412 static void dump_clock(struct seq_file *s, struct clk *clk, int deep,const struct list_head *root_clocks)
3416 unsigned long rate = clk->rate;
3417 //CRU_PRINTK_DBG("dump_clock %s\n",clk->name);
3418 for (i = 0; i < deep; i++)
3421 seq_printf(s, "%-11s ", clk->name);
3422 #ifndef RK30_CLK_OFFBOARD_TEST
3423 if (clk->flags & IS_PD) {
3424 seq_printf(s, "%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3427 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3428 int idx = clk->gate_idx;
3430 v = cru_readl(CLK_GATE_CLKID_CONS(idx))&((0x1)<<(idx%16));
3431 seq_printf(s, "%s ", v ? "off" : "on ");
3437 u32 pll_id=clk->pll->id;
3438 pll_mode=cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3439 if(pll_mode==PLL_MODE_SLOW(pll_id))
3440 seq_printf(s, "slow ");
3441 else if(pll_mode==PLL_MODE_NORM(pll_id))
3442 seq_printf(s, "normal ");
3443 else if(pll_mode==PLL_MODE_DEEP(pll_id))
3444 seq_printf(s, "deep ");
3446 if(cru_readl(PLL_CONS(pll_id,3)) & PLL_BYPASS)
3447 seq_printf(s, "bypass ");
3449 else if(clk == &clk_ddr) {
3450 rate = clk->recalc(clk);
3455 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3457 seq_printf(s, "%ld MHz", rate / MHZ);
3458 } else if (rate >= KHZ) {
3460 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3462 seq_printf(s, "%ld KHz", rate / KHZ);
3464 seq_printf(s, "%ld Hz", rate);
3467 seq_printf(s, " usecount = %d", clk->usecount);
3470 seq_printf(s, " parent = %s", clk->parent->name);
3472 seq_printf(s, "\n");
3474 list_for_each_entry(ck, root_clocks, node) {
3475 if (ck->parent == clk)
3476 dump_clock(s, ck, deep + 1,root_clocks);
3480 static void dump_regs(struct seq_file *s)
3483 seq_printf(s, "\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3484 seq_printf(s, "\nPLLRegisters:\n");
3485 for(i=0;i<END_PLL_ID;i++)
3487 seq_printf(s,"pll%d :cons:%x,%x,%x,%x\n",i,
3488 cru_readl(PLL_CONS(i,0)),
3489 cru_readl(PLL_CONS(i,1)),
3490 cru_readl(PLL_CONS(i,2)),
3491 cru_readl(PLL_CONS(i,3))
3494 seq_printf(s, "MODE :%x\n", cru_readl(CRU_MODE_CON));
3496 for(i=0;i<CRU_CLKSELS_CON_CNT;i++)
3498 seq_printf(s,"CLKSEL%d :%x\n",i,cru_readl(CRU_CLKSELS_CON(i)));
3500 for(i=0;i<CRU_CLKGATES_CON_CNT;i++)
3502 seq_printf(s,"CLKGATE%d :%x\n",i,cru_readl(CRU_CLKGATES_CON(i)));
3504 seq_printf(s,"GLB_SRST_FST:%x\n",cru_readl(CRU_GLB_SRST_FST));
3505 seq_printf(s,"GLB_SRST_SND:%x\n",cru_readl(CRU_GLB_SRST_SND));
3507 for(i=0;i<CRU_SOFTRSTS_CON_CNT;i++)
3509 seq_printf(s,"CLKGATE%d :%x\n",i,cru_readl(CRU_SOFTRSTS_CON(i)));
3511 seq_printf(s,"CRU MISC :%x\n",cru_readl(CRU_MISC_CON));
3512 seq_printf(s,"GLB_CNT_TH :%x\n",cru_readl(CRU_GLB_CNT_TH));
3516 void rk30_clk_dump_regs(void)
3519 printk("\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3520 printk("\nPLLRegisters:\n");
3521 for(i=0;i<END_PLL_ID;i++)
3523 printk("pll%d :cons:%x,%x,%x,%x\n",i,
3524 cru_readl(PLL_CONS(i,0)),
3525 cru_readl(PLL_CONS(i,1)),
3526 cru_readl(PLL_CONS(i,2)),
3527 cru_readl(PLL_CONS(i,3))
3530 printk("MODE :%x\n", cru_readl(CRU_MODE_CON));
3532 for(i=0;i<CRU_CLKSELS_CON_CNT;i++)
3534 printk("CLKSEL%d :%x\n",i,cru_readl(CRU_CLKSELS_CON(i)));
3536 for(i=0;i<CRU_CLKGATES_CON_CNT;i++)
3538 printk("CLKGATE%d :%x\n",i,cru_readl(CRU_CLKGATES_CON(i)));
3540 printk("GLB_SRST_FST:%x\n",cru_readl(CRU_GLB_SRST_FST));
3541 printk("GLB_SRST_SND:%x\n",cru_readl(CRU_GLB_SRST_SND));
3543 for(i=0;i<CRU_SOFTRSTS_CON_CNT;i++)
3545 printk("SOFTRST%d :%x\n",i,cru_readl(CRU_SOFTRSTS_CON(i)));
3547 printk("CRU MISC :%x\n",cru_readl(CRU_MISC_CON));
3548 printk("GLB_CNT_TH :%x\n",cru_readl(CRU_GLB_CNT_TH));
3553 #ifdef CONFIG_PROC_FS
3554 static void dump_clock(struct seq_file *s, struct clk *clk, int deep,const struct list_head *root_clocks);
3555 struct clk_dump_ops dump_ops={
3556 .dump_clk=dump_clock,
3557 .dump_regs=dump_regs,
3562 #endif /* CONFIG_PROC_FS */
3567 #ifdef RK30_CLK_OFFBOARD_TEST
3568 struct clk *test_get_parent(struct clk *clk)
3575 struct clk *i2s_clk=&clk_i2s0;
3577 clk_enable_nolock(i2s_clk);
3579 clk_set_rate_nolock(i2s_clk, 12288000);
3580 printk("int %s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3581 clk_set_rate_nolock(i2s_clk, 297*MHZ/2);
3582 printk("int%s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3583 clk_set_rate_nolock(i2s_clk, 12*MHZ);
3584 printk("int%s parent is %s\n",i2s_clk->name,test_get_parent(i2s_clk)->name);
3588 void uart_test(void)
3590 struct clk *uart_clk=&clk_uart0;
3592 clk_enable_nolock(uart_clk);
3594 clk_set_rate_nolock(uart_clk, 12288000);
3595 printk("int %s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3596 clk_set_rate_nolock(uart_clk, 297*MHZ/2);
3597 printk("int%s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3598 clk_set_rate_nolock(uart_clk, 12*MHZ);
3599 printk("int%s parent is %s\n",uart_clk->name,test_get_parent(uart_clk)->name);
3602 void hsadc_test(void)
3604 struct clk *hsadc_clk=&clk_hsadc;
3606 printk("******************hsadc_test**********************\n");
3607 clk_enable_nolock(hsadc_clk);
3609 clk_set_rate_nolock(hsadc_clk, 12288000);
3610 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3613 clk_set_rate_nolock(hsadc_clk, 297*MHZ/2);
3614 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3616 clk_set_rate_nolock(hsadc_clk, 300*MHZ/2);
3618 clk_set_rate_nolock(hsadc_clk, 296*MHZ/2);
3620 printk("******************hsadc out clock**********************\n");
3622 clk_set_parent_nolock(hsadc_clk, &clk_hsadc_ext);
3623 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3624 clk_set_rate_nolock(hsadc_clk, 297*MHZ/2);
3625 printk("****end %s parent is %s\n",hsadc_clk->name,test_get_parent(hsadc_clk)->name);
3631 static void __init rk30_clock_test_init(unsigned long ppll_rate)
3634 printk("*********arm_pll_clk***********\n");
3635 clk_set_rate_nolock(&arm_pll_clk, 816*MHZ);
3637 printk("*********set clk_cpu parent***********\n");
3638 clk_set_parent_nolock(&clk_cpu, &arm_pll_clk);
3639 clk_set_rate_nolock(&clk_cpu, 504*MHZ);
3642 printk("*********general_pll_clk***********\n");
3643 clk_set_rate_nolock(&general_pll_clk, ppll_rate);
3646 printk("*********codec_pll_clk***********\n");
3647 clk_set_rate_nolock(&codec_pll_clk, 600*MHZ);
3650 printk("*********periph_clk_set_init***********\n");
3651 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3652 periph_clk_set_init();
3655 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3657 printk("*********clk i2s***********\n");
3658 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3659 printk("common %s parent is %s\n",clk_i2s_pll.name,test_get_parent(&clk_i2s_pll)->name);
3663 clk_enable_nolock(&clk_spi0);
3664 clk_set_rate_nolock(&clk_spi0, 30*MHZ);
3665 printk("common %s parent is %s\n",clk_spi0.name,test_get_parent(&clk_spi0)->name);
3667 clk_enable_nolock(&clk_saradc);
3668 clk_set_rate_nolock(&clk_saradc, 6*MHZ);
3669 printk("common %s parent is %s\n",clk_saradc.name,test_get_parent(&clk_saradc)->name);
3671 clk_enable_nolock(&clk_sdio);
3672 clk_set_rate_nolock(&clk_sdio, 50*MHZ);
3673 printk("common %s parent is %s\n",clk_sdio.name,test_get_parent(&clk_sdio)->name);
3675 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3678 printk("*********mac***********\n");
3680 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3681 printk("common %s parent is %s\n",clk_mac_pll_div.name,test_get_parent(&clk_mac_pll_div)->name);
3683 //clk_set_parent_nolock(&clk_mac_ref, &clk_mac_pll_div);
3684 clk_set_rate_nolock(&clk_mac_ref, 50*MHZ);
3685 printk("common %s parent is %s\n",clk_mac_ref.name,test_get_parent(&clk_mac_ref)->name);
3687 printk("*********mac mii set***********\n");
3688 clk_set_parent_nolock(&clk_mac_ref, &rmii_clkin);
3689 clk_set_rate_nolock(&clk_mac_ref, 20*MHZ);
3690 printk("common %s parent is %s\n",clk_mac_ref.name,test_get_parent(&clk_mac_ref)->name);
3692 printk("*********hsadc 1***********\n");
3696 clk_enable_nolock(&dclk_lcdc0);
3698 clk_set_rate_nolock(&dclk_lcdc0, 60*MHZ);
3699 clk_set_rate_nolock(&dclk_lcdc0, 27*MHZ);
3702 clk_enable_nolock(&cif0_out);
3704 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3705 printk("common %s parent is %s\n",cif_out_pll.name,test_get_parent(&cif_out_pll)->name);
3707 clk_set_rate_nolock(&cif0_out, 60*MHZ);
3708 printk("common %s parent is %s\n",cif0_out.name,test_get_parent(&cif0_out)->name);
3710 clk_set_rate_nolock(&cif0_out, 24*MHZ);
3711 printk("common %s parent is %s\n",cif0_out.name,test_get_parent(&cif0_out)->name);
3713 clk_enable_nolock(&cif0_in);
3714 clk_set_rate_nolock(&cif0_in, 24*MHZ);
3716 clk_enable_nolock(&aclk_lcdc0);
3717 clk_set_rate_nolock(&aclk_lcdc0, 150*MHZ);
3718 printk("common %s parent is %s\n",aclk_lcdc0.name,test_get_parent(&aclk_lcdc0)->name);
3720 clk_enable_nolock(&aclk_vepu);
3721 clk_set_rate_nolock(&aclk_vepu, 300*MHZ);
3722 printk("common %s parent is %s\n",aclk_vepu.name,test_get_parent(&aclk_vepu)->name);
3724 clk_set_rate_nolock(&hclk_vepu, 300*MHZ);
3725 printk("common %s parent is %s\n",hclk_vepu.name,test_get_parent(&hclk_vepu)->name);
3727 printk("test end\n");
3730 clk_set_rate_nolock(&arm_pll_clk, armclk);
3731 clk_set_rate_nolock(&clk_cpu, armclk);//pll:core =1:1
3734 //clk_set_rate_nolock(&codec_pll_clk, ppll_rate*2);
3736 //clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3737 //clk_set_rate_nolock(&clk_gpu, 300 * MHZ);
3745 static LIST_HEAD(rk30_clocks);
3746 static DEFINE_MUTEX(rk30_clocks_mutex);
3748 static inline int __rk30clk_get(struct clk *clk)
3752 void rk30_clkdev_add(struct clk_lookup *cl)
3754 mutex_lock(&rk30_clocks_mutex);
3755 list_add_tail(&cl->node, &rk30_clocks);
3756 mutex_unlock(&rk30_clocks_mutex);
3758 static struct clk_lookup *rk30_clk_find(const char *dev_id, const char *con_id)
3760 struct clk_lookup *p, *cl = NULL;
3761 int match, best = 0;
3763 list_for_each_entry(p, &rk30_clocks, node) {
3766 if (!dev_id || strcmp(p->dev_id, dev_id))
3771 if (!con_id || strcmp(p->con_id, con_id))
3787 struct clk *rk30_clk_get_sys(const char *dev_id, const char *con_id)
3789 struct clk_lookup *cl;
3791 mutex_lock(&rk30_clocks_mutex);
3792 cl = rk30_clk_find(dev_id, con_id);
3793 if (cl && !__rk30clk_get(cl->clk))
3795 mutex_unlock(&rk30_clocks_mutex);
3797 return cl ? cl->clk : ERR_PTR(-ENOENT);
3799 //EXPORT_SYMBOL(rk30_clk_get_sys);
3801 struct clk *rk30_clk_get(struct device *dev, const char *con_id)
3803 const char *dev_id = dev ? dev_name(dev) : NULL;
3804 return rk30_clk_get_sys(dev_id, con_id);
3806 //EXPORT_SYMBOL(rk30_clk_get);
3809 int rk30_clk_set_rate(struct clk *clk, unsigned long rate);
3811 void rk30_clocks_test(void)
3813 struct clk *test_gpll;
3814 test_gpll=rk30_clk_get(NULL,"general_pll");
3817 rk30_clk_set_rate(test_gpll,297*2*MHZ);
3818 printk("gpll rate=%lu\n",test_gpll->rate);
3823 void __init rk30_clock_init_test(void){
3825 rk30_clock_init(periph_pll_297mhz,codec_pll_360mhz,max_i2s_12288khz);