1 /* linux/arch/arm/mach-rk30/clock_data.c
3 * Copyright (C) 2012 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/clk.h>
16 #include <linux/clkdev.h>
17 #include <linux/err.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
22 #include <linux/delay.h>
23 #include <linux/hardirq.h>
25 #include <mach/iomux.h>
26 #include <mach/clock.h>
28 #include <mach/dvfs.h>
31 #define MHZ (1000UL * 1000UL)
33 #define CLK_LOOPS_JIFFY_REF 11996091ULL
34 #define CLK_LOOPS_RATE_REF (1200UL) //Mhz
35 #define CLK_LOOPS_RECALC(new_rate) div_u64(CLK_LOOPS_JIFFY_REF*(new_rate),CLK_LOOPS_RATE_REF*MHZ)
36 void rk30_clk_dump_regs(void);
40 #define CLK_FLG_EXT_27MHZ (1<<0)
42 #define CLK_FLG_MAX_I2S_12288KHZ (1<<1)
43 #define CLK_FLG_MAX_I2S_22579_2KHZ (1<<2)
44 #define CLK_FLG_MAX_I2S_24576KHZ (1<<3)
45 #define CLK_FLG_MAX_I2S_49152KHZ (1<<4)
47 #define CLK_FLG_UART_1_3M (1<<5)
55 u32 pllcon2; //nb=bwadj+1;0:11;nb=nf/2
65 u32 pllcon2; //nb=bwadj+1;0:11;nb=nf/2
66 unsigned long rst_dly;//us
69 #define SET_PLL_DATA(_pll_id,_table) \
76 #define _PLL_SET_CLKS(_mhz, nr, nf, no) \
78 .rate = (_mhz) * KHZ, \
79 .pllcon0 = PLL_CLKR_SET(nr)|PLL_CLKOD_SET(no), \
80 .pllcon1 = PLL_CLKF_SET(nf),\
81 .rst_dly=((nr*500)/24+1),\
85 #define _APLL_SET_LPJ(_mhz) \
86 .lpj= (CLK_LOOPS_JIFFY_REF * _mhz)/CLK_LOOPS_RATE_REF
89 #define _APLL_SET_CLKS(_mhz, nr, nf, no, _periph_div, _axi_core_div,\
90 _axi_div,_ahb_div, _apb_div,_ahb2apb) \
93 .pllcon0 = PLL_CLKR_SET(nr) | PLL_CLKOD_SET(no), \
94 .pllcon1 = PLL_CLKF_SET(nf),\
95 .clksel0 = CORE_PERIPH_W_MSK | CORE_PERIPH_##_periph_div,\
96 .clksel1 = CORE_ACLK_W_MSK | CORE_ACLK_##_axi_core_div,\
98 .rst_dly=((nr*500)/24+1),\
101 #define CRU_DIV_SET(mask,shift,max) \
107 #define CRU_SRC_SET(mask,shift ) \
111 #define CRU_PARENTS_SET(parents_array) \
112 .parents=(parents_array),\
113 .parents_num=ARRAY_SIZE((parents_array))
115 #define CRU_GATE_MODE_SET(_func,_IDX) \
126 #define GATE_CLK(NAME,PARENT,ID) \
127 static struct clk clk_##NAME = { \
131 .gate_idx = CLK_GATE_##ID, \
133 #ifdef RK30_CLK_OFFBOARD_TEST
134 u32 TEST_GRF_REG[0x240];
135 u32 TEST_CRU_REG[0x240];
136 #define cru_readl(offset) (TEST_CRU_REG[offset/4])
138 u32 cru_writel_is_pr(u32 offset)
140 return (offset == 0x4000);
142 void cru_writel(u32 v, u32 offset)
145 u32 mask_v = v >> 16;
146 TEST_CRU_REG[offset/4] &= (~mask_v);
150 TEST_CRU_REG[offset/4] |= v;
151 TEST_CRU_REG[offset/4] &= 0x0000ffff;
153 if(cru_writel_is_pr(offset)) {
154 CLKDATA_DBG("cru w offset=%d,set=%x,reg=%x\n", offset, v, TEST_CRU_REG[offset/4]);
159 void cru_writel_i2s(u32 v, u32 offset)
161 TEST_CRU_REG[offset/4] = v;
163 #define cru_writel_frac(v,offset) cru_writel_i2s((v),(offset))
165 #define regfile_readl(offset) (0xffffffff)
166 //#define pmu_readl(offset) readl(RK30_GRF_BASE + offset)
167 void rk30_clkdev_add(struct clk_lookup *cl);
169 #define regfile_readl(offset) readl_relaxed(RK30_GRF_BASE + offset)
170 #define regfile_writel(v, offset) do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
171 #define cru_readl(offset) readl_relaxed(RK30_CRU_BASE + offset)
172 #define cru_writel(v, offset) do { writel_relaxed(v, RK30_CRU_BASE + offset); dsb(); } while (0)
174 #define cru_writel_frac(v,offset) cru_writel((v),(offset))
179 #define CLKDATA_DBG(fmt, args...) printk(KERN_DEBUG "CLKDATA_DBG:\t"fmt, ##args)
180 #define CLKDATA_LOG(fmt, args...) printk(KERN_INFO "CLKDATA_LOG:\t"fmt, ##args)
181 //#define CLKDATA_DBG(fmt, args...) printk("CLKDATA_DBG:\t"fmt, ##args)
182 //#define CLKDATA_LOG(fmt, args...) printk("CLKDATA_LOG:\t"fmt, ##args)
184 #define CLKDATA_DBG(fmt, args...) do {} while(0)
185 #define CLKDATA_LOG(fmt, args...) do {} while(0)
187 #define CLKDATA_ERR(fmt, args...) printk(KERN_ERR "CLKDATA_ERR:\t"fmt, ##args)
188 #define CLKDATA_WARNNING(fmt, args...) printk("CLKDATA_WANNING:\t"fmt, ##args)
191 #define get_cru_bits(con,mask,shift)\
192 ((cru_readl((con)) >> (shift)) & (mask))
194 #define set_cru_bits_w_msk(val,mask,shift,con)\
195 cru_writel(((mask)<<(shift+16))|((val)<<(shift)),(con))
198 #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)))\
199 &&!(cru_readl(PLL_CONS(pll_id,3))&PLL_BYPASS))
202 static u32 rk30_clock_flags = 0;
203 static struct clk codec_pll_clk;
204 static struct clk general_pll_clk;
205 static struct clk arm_pll_clk;
206 static unsigned long lpj_gpll;
207 static unsigned int __initdata armclk = 504 * MHZ;
210 /************************clk recalc div rate*********************************/
213 static unsigned long clksel_recalc_div(struct clk *clk)
215 u32 div = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1;
217 unsigned long rate = clk->parent->rate / div;
218 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, div);
223 static unsigned long clksel_recalc_shift(struct clk *clk)
225 u32 shift = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift);
226 unsigned long rate = clk->parent->rate >> shift;
227 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
232 static unsigned long clksel_recalc_shift_2(struct clk *clk)
234 u32 shift = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1;
235 unsigned long rate = clk->parent->rate >> shift;
236 pr_debug("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
240 static unsigned long clksel_recalc_parent_rate(struct clk *clk)
242 unsigned long rate = clk->parent->rate;
243 pr_debug("%s new clock rate is %lu\n", clk->name, rate);
246 /********************************set div rate***********************************/
249 static int clksel_set_rate_freediv(struct clk *clk, unsigned long rate)
252 for (div = 0; div < clk->div_max; div++) {
253 u32 new_rate = clk->parent->rate / (div + 1);
254 if (new_rate <= rate) {
255 set_cru_bits_w_msk(div, clk->div_mask, clk->div_shift, clk->clksel_con);
256 //clk->rate = new_rate;
257 pr_debug("clksel_set_rate_freediv for clock %s to rate %ld (div %d)\n",
258 clk->name, rate, div + 1);
266 static int clksel_set_rate_shift(struct clk *clk, unsigned long rate)
269 for (shift = 0; (1 << shift) < clk->div_max; shift++) {
270 u32 new_rate = clk->parent->rate >> shift;
271 if (new_rate <= rate) {
272 set_cru_bits_w_msk(shift, clk->div_mask, clk->div_shift, clk->clksel_con);
273 clk->rate = new_rate;
274 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n",
275 clk->name, rate, shift);
283 static int clksel_set_rate_shift_2(struct clk *clk, unsigned long rate)
287 for (shift = 1; (1 << shift) < clk->div_max; shift++) {
288 u32 new_rate = clk->parent->rate >> shift;
289 if (new_rate <= rate) {
290 set_cru_bits_w_msk(shift - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
291 clk->rate = new_rate;
292 pr_debug("clksel_set_rate_shift for clock %s to rate %ld (shift %d)\n",
293 clk->name, rate, shift);
301 static int clksel_set_rate_even(struct clk *clk, unsigned long rate)
304 for (div = 2; div < clk->div_max; div += 2) {
305 u32 new_rate = clk->parent->rate / div;
306 if (new_rate <= rate) {
307 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
308 clk->rate = new_rate;
309 pr_debug("%s for clock %s to rate %ld (even div = %d)\n",
310 __func__, clk->name, rate, div);
316 static u32 clk_get_freediv(unsigned long rate_out, unsigned long rate , u32 div_max)
319 unsigned long new_rate;
320 for (div = 0; div < div_max; div++) {
321 new_rate = rate / (div + 1);
322 if (new_rate <= rate_out) {
326 return div_max ? div_max : 1;
328 static u32 clk_get_evendiv(unsigned long rate_out, unsigned long rate , u32 div_max)
331 unsigned long new_rate;
332 for (div = 1; div < div_max; div += 2) {
333 new_rate = rate / (div + 1);
334 if (new_rate <= rate_out) {
338 return div_max ? div_max : 1;
340 struct clk *get_freediv_parents_div(struct clk *clk, unsigned long rate, u32 *div_out) {
342 unsigned long new_rate[2] = {0, 0};
345 if(clk->rate == rate)
347 for(i = 0; i < 2; i++) {
348 div[i] = clk_get_freediv(rate, clk->parents[i]->rate, clk->div_max);
349 new_rate[i] = clk->parents[i]->rate / div[i];
350 if(new_rate[i] == rate) {
352 return clk->parents[i];
355 if(new_rate[0] < new_rate[1])
360 return clk->parents[i];
362 struct clk *get_evendiv_parents_div(struct clk *clk, unsigned long rate, u32 *div_out) {
364 unsigned long new_rate[2] = {0, 0};
367 if(clk->rate == rate)
369 for(i = 0; i < 2; i++) {
370 div[i] = clk_get_evendiv(rate, clk->parents[i]->rate, clk->div_max);
371 new_rate[i] = clk->parents[i]->rate / div[i];
372 if(new_rate[i] == rate) {
374 return clk->parents[i];
377 if(new_rate[0] < new_rate[1])
382 return clk->parents[i];
385 static int clkset_rate_freediv_autosel_parents(struct clk *clk, unsigned long rate)
390 if(clk->rate == rate)
392 p_clk = get_freediv_parents_div(clk, rate, &div);
397 CLKDATA_DBG("%s %lu,form %s\n", clk->name, rate, p_clk->name);
398 if (clk->parent != p_clk) {
399 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con), clk->div_shift, clk->div_mask) + 1;
402 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
404 ret = clk_set_parent_nolock(clk, p_clk);
406 CLKDATA_ERR("%s can't set %lu,reparent err\n", clk->name, rate);
411 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
414 static int clkset_rate_evendiv_autosel_parents(struct clk *clk, unsigned long rate)
419 if(clk->rate == rate)
421 p_clk = get_evendiv_parents_div(clk, rate, &div);
426 CLKDATA_DBG("%s %lu,form %s\n", clk->name, rate, p_clk->name);
427 if (clk->parent != p_clk) {
428 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con), clk->div_shift, clk->div_mask) + 1;
431 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
433 ret = clk_set_parent_nolock(clk, p_clk);
435 CLKDATA_ERR("%s can't set %lu,reparent err\n", clk->name, rate);
440 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
444 //rate==div rate //hdmi
445 static int clk_freediv_autosel_parents_set_fixed_rate(struct clk *clk, unsigned long rate)
450 p_clk = get_freediv_parents_div(clk, rate, &div);
455 if((p_clk->rate / div) != rate || (p_clk->rate % div))
458 if (clk->parent != p_clk) {
459 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con),
460 clk->div_shift, clk->div_mask) + 1;
462 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
464 ret = clk_set_parent_nolock(clk, p_clk);
466 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
471 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
475 /***************************round********************************/
477 static long clksel_freediv_round_rate(struct clk *clk, unsigned long rate)
479 return clk->parent->rate / clk_get_freediv(rate, clk->parent->rate, clk->div_max);
482 static long clk_freediv_round_autosel_parents_rate(struct clk *clk, unsigned long rate)
486 if(clk->rate == rate)
488 p_clk = get_freediv_parents_div(clk, rate, &div);
491 return p_clk->rate / div;
494 /**************************************others seting************************************/
496 static struct clk *clksel_get_parent(struct clk *clk) {
497 return clk->parents[(cru_readl(clk->clksel_con) >> clk->src_shift) & clk->src_mask];
499 static int clksel_set_parent(struct clk *clk, struct clk *parent)
502 if (unlikely(!clk->parents))
504 for (i = 0; (i < clk->parents_num); i++) {
505 if (clk->parents[i] != parent)
507 set_cru_bits_w_msk(i, clk->src_mask, clk->src_shift, clk->clksel_con);
513 static int gate_mode(struct clk *clk, int on)
515 int idx = clk->gate_idx;
516 if (idx >= CLK_GATE_MAX)
519 cru_writel(CLK_GATE_W_MSK(idx) | CLK_UN_GATE(idx), CLK_GATE_CLKID_CONS(idx));
520 //CLKDATA_DBG("un gate id=%d %s(%x),con %x\n",idx,clk->name,
521 // CLK_GATE_W_MSK(idx)|CLK_UN_GATE(idx),CLK_GATE_CLKID_CONS(idx));
523 cru_writel(CLK_GATE_W_MSK(idx) | CLK_GATE(idx), CLK_GATE_CLKID_CONS(idx));
524 // CLKDATA_DBG("gate id=%d %s(%x),con%x\n",idx,clk->name,
525 // CLK_GATE_W_MSK(idx)|CLK_GATE(idx),CLK_GATE_CLKID_CONS(idx));
529 /*****************************frac set******************************************/
531 static unsigned long clksel_recalc_frac(struct clk *clk)
535 u32 r = cru_readl(clk->clksel_con), numerator, denominator;
536 if (r == 0) // FPGA ?
537 return clk->parent->rate;
539 denominator = r & 0xFFFF;
540 rate64 = (u64)clk->parent->rate * numerator;
541 do_div(rate64, denominator);
543 pr_debug("%s new clock rate is %lu (frac %u/%u)\n", clk->name, rate, numerator, denominator);
547 static u32 clk_gcd(u32 numerator, u32 denominator)
551 if (!numerator || !denominator)
553 if (numerator > denominator) {
569 static int frac_div_get_seting(unsigned long rate_out, unsigned long rate,
570 u32 *numerator, u32 *denominator)
573 gcd_vl = clk_gcd(rate, rate_out);
574 CLKDATA_DBG("frac_get_seting rate=%lu,parent=%lu,gcd=%d\n", rate_out, rate, gcd_vl);
577 CLKDATA_ERR("gcd=0, i2s frac div is not be supported\n");
581 *numerator = rate_out / gcd_vl;
582 *denominator = rate / gcd_vl;
584 CLKDATA_DBG("frac_get_seting numerator=%d,denominator=%d,times=%d\n",
585 *numerator, *denominator, *denominator / *numerator);
587 if (*numerator > 0xffff || *denominator > 0xffff ||
588 (*denominator / (*numerator)) < 20) {
589 CLKDATA_ERR("can't get a available nume and deno\n");
596 /* *********************pll **************************/
598 #define rk30_clock_udelay(a) udelay(a);
600 /*********************pll lock status**********************************/
601 //#define GRF_SOC_CON0 0x15c
602 static void pll_wait_lock(int pll_idx)
604 u32 pll_state[4] = {1, 0, 2, 3};
605 u32 bit = 0x20u << pll_state[pll_idx];
606 int delay = 24000000;
608 if (regfile_readl(GRF_SOC_STATUS0) & bit)
613 CLKDATA_ERR("wait pll bit 0x%x time out!\n", bit);
620 /***************************pll function**********************************/
621 static unsigned long pll_clk_recalc(u32 pll_id, unsigned long parent_rate)
625 if (PLLS_IN_NORM(pll_id)) {
626 u32 pll_con0 = cru_readl(PLL_CONS(pll_id, 0));
627 u32 pll_con1 = cru_readl(PLL_CONS(pll_id, 1));
630 u64 rate64 = (u64)parent_rate * PLL_NF(pll_con1);
633 CLKDATA_DBG("selcon con0(%x) %x,con1(%x)%x, rate64 %llu\n",PLL_CONS(pll_id,0),pll_con0
634 ,PLL_CONS(pll_id,1),pll_con1, rate64);
638 //CLKDATA_DBG("pll id=%d con0=%x,con1=%x,parent=%lu\n",pll_id,pll_con0,pll_con1,parent_rate);
639 //CLKDATA_DBG("first pll id=%d rate is %lu (NF %d NR %d NO %d)\n",
640 //pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0), 1 << PLL_NO(pll_con0));
642 do_div(rate64, PLL_NR(pll_con0));
643 do_div(rate64, PLL_NO(pll_con0));
647 CLKDATA_DBG("pll_clk_recalc id=%d rate=%lu (NF %d NR %d NO %d) rate64=%llu\n",
648 pll_id, rate, PLL_NF(pll_con1), PLL_NR(pll_con0),PLL_NO(pll_con0), rate64);
652 CLKDATA_DBG("pll_clk_recalc id=%d rate=%lu by pass mode\n", pll_id, rate);
656 static unsigned long plls_clk_recalc(struct clk *clk)
658 return pll_clk_recalc(clk->pll->id, clk->parent->rate);
661 static int pll_clk_set_rate(struct pll_clk_set *clk_set, u8 pll_id)
664 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
665 cru_writel((0x1<<(16+1))|(0x1<<1), PLL_CONS(pll_id, 3));
672 cru_writel(clk_set->pllcon0, PLL_CONS(pll_id, 0));
673 cru_writel(clk_set->pllcon1, PLL_CONS(pll_id, 1));
675 rk30_clock_udelay(1);
676 cru_writel((0x1<<(16+1)), PLL_CONS(pll_id, 3));
678 pll_wait_lock(pll_id);
681 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
684 CLKDATA_ERR("pll reg id=%d,con0=%x,con1=%x,mode=%x\n",pll_id,
685 cru_readl(PLL_CONS(pll_id,0)),(PLL_CONS(pll_id,1)),cru_readl(CRU_MODE_CON));
690 static int gpll_clk_set_rate(struct clk *c, unsigned long rate)
692 struct _pll_data *pll_data = c->pll;
693 struct pll_clk_set *clk_set = (struct pll_clk_set *)pll_data->table;
695 while(clk_set->rate) {
696 if (clk_set->rate == rate) {
701 if(clk_set->rate == rate) {
702 pll_clk_set_rate(clk_set, pll_data->id);
703 lpj_gpll = CLK_LOOPS_RECALC(rate);
705 CLKDATA_ERR("gpll is no corresponding rate=%lu\n", rate);
711 #define PLL_FREF_MIN (183*KHZ)
712 #define PLL_FREF_MAX (1500*MHZ)
714 #define PLL_FVCO_MIN (300*MHZ)
715 #define PLL_FVCO_MAX (1500*MHZ)
717 #define PLL_FOUT_MIN (18750*KHZ)
718 #define PLL_FOUT_MAX (1500*MHZ)
720 #define PLL_NF_MAX (65536)
721 #define PLL_NR_MAX (64)
722 #define PLL_NO_MAX (64)
724 static int pll_clk_get_set(unsigned long fin_hz, unsigned long fout_hz, u32 *clk_nr, u32 *clk_nf, u32 *clk_no)
726 u32 nr, nf, no, nonr;
730 unsigned long fref, fvco, fout;
733 CLKDATA_DBG("pll_clk_get_set fin=%lu,fout=%lu\n", fin_hz, fout_hz);
734 if(!fin_hz || !fout_hz || fout_hz == fin_hz)
736 gcd_val = clk_gcd(fin_hz, fout_hz);
737 YFfenzi = fout_hz / gcd_val;
738 YFfenmu = fin_hz / gcd_val;
743 if(nf > PLL_NF_MAX || nonr > (PLL_NO_MAX * PLL_NR_MAX))
745 for(no = 1; no <= PLL_NO_MAX; no++) {
746 if(!(no == 1 || !(no % 2)))
753 if(nr > PLL_NR_MAX) //PLL_NR_MAX
757 if(fref < PLL_FREF_MIN || fref > PLL_FREF_MAX)
760 fvco = (fin_hz / nr) * nf;
761 if(fvco < PLL_FVCO_MIN || fvco > PLL_FVCO_MAX)
764 if(fout < PLL_FOUT_MIN || fout > PLL_FOUT_MAX)
777 static int pll_clk_mode(struct clk *clk, int on)
779 u8 pll_id = clk->pll->id;
780 u32 nr = PLL_NR(cru_readl(PLL_CONS(pll_id, 0)));
781 u32 dly = (nr * 500) / 24 + 1;
782 CLKDATA_DBG("pll_mode %s(%d)\n", clk->name, on);
784 cru_writel(PLL_PWR_ON | PLL_PWR_DN_W_MSK, PLL_CONS(pll_id, 3));
785 rk30_clock_udelay(dly);
786 pll_wait_lock(pll_id);
787 cru_writel(PLL_MODE_NORM(pll_id), CRU_MODE_CON);
789 cru_writel(PLL_MODE_SLOW(pll_id), CRU_MODE_CON);
790 cru_writel(PLL_PWR_DN | PLL_PWR_DN_W_MSK, PLL_CONS(pll_id, 3));
795 static int cpll_clk_set_rate(struct clk *c, unsigned long rate)
797 struct _pll_data *pll_data = c->pll;
798 struct pll_clk_set *clk_set = (struct pll_clk_set *)pll_data->table;
799 struct pll_clk_set temp_clk_set;
800 u32 clk_nr, clk_nf, clk_no;
803 while(clk_set->rate) {
804 if (clk_set->rate == rate) {
809 if(clk_set->rate == rate) {
810 CLKDATA_DBG("cpll get a rate\n");
811 pll_clk_set_rate(clk_set, pll_data->id);
814 CLKDATA_DBG("cpll get auto calc a rate\n");
815 if(pll_clk_get_set(c->parent->rate, rate, &clk_nr, &clk_nf, &clk_no) == 0) {
816 pr_err("cpll auto set rate error\n");
819 CLKDATA_DBG("cpll auto ger rate set nr=%d,nf=%d,no=%d\n", clk_nr, clk_nf, clk_no);
820 temp_clk_set.pllcon0 = PLL_CLKR_SET(clk_nr) | PLL_CLKOD_SET(clk_no);
821 temp_clk_set.pllcon1 = PLL_CLKF_SET(clk_nf);
822 temp_clk_set.rst_dly = (clk_nr * 500) / 24 + 1;
823 pll_clk_set_rate(&temp_clk_set, pll_data->id);
830 /* ******************fixed input clk ***********************************************/
831 static struct clk xin24m = {
837 static struct clk clk_12m = {
844 /************************************pll func***************************/
845 static const struct apll_clk_set *arm_pll_clk_get_best_pll_set(unsigned long rate,
846 struct apll_clk_set *tables) {
847 const struct apll_clk_set *ps, *pt;
849 /* find the arm_pll we want. */
852 if (pt->rate == rate) {
856 // we are sorted, and ps->rate > pt->rate.
857 if ((pt->rate > rate || (rate - pt->rate < ps->rate - rate)))
863 //CLKDATA_DBG("arm pll best rate=%lu\n",ps->rate);
866 static long arm_pll_clk_round_rate(struct clk *clk, unsigned long rate)
868 return arm_pll_clk_get_best_pll_set(rate, clk->pll->table)->rate;
871 struct arm_clks_div_set {
877 #define _arm_clks_div_set(_mhz,_periph_div,_axi_div,_ahb_div, _apb_div,_ahb2apb) \
880 .clksel0 = CORE_PERIPH_W_MSK|CORE_PERIPH_##_periph_div,\
881 .clksel1 = CORE_ACLK_W_MSK|CORE_ACLK_##_axi_div\
882 |ACLK_HCLK_W_MSK|ACLK_HCLK_##_ahb_div\
883 |ACLK_PCLK_W_MSK|ACLK_PCLK_##_apb_div\
884 |AHB2APB_W_MSK |AHB2APB_##_ahb2apb,\
886 struct arm_clks_div_set arm_clk_div_tlb[] = {
887 _arm_clks_div_set(50 , 2, 11, 11, 11, 11),//25,50,50,50,50
888 _arm_clks_div_set(100 , 4, 11, 21, 21, 11),//25,100,50,50,50
889 _arm_clks_div_set(150 , 4, 11, 21, 21, 11),//37,150,75,75,75
890 _arm_clks_div_set(200 , 8, 21, 21, 21, 11),//25,100,50,50,50
891 _arm_clks_div_set(300 , 8, 21, 21, 21, 11),//37,150,75,75,75
892 _arm_clks_div_set(400 , 8, 21, 21, 41, 21),//50,200,100,50,50
893 _arm_clks_div_set(0 , 2, 11, 11, 11, 11),//25,50,50,50,50
895 struct arm_clks_div_set *arm_clks_get_div(u32 rate) {
897 for(i = 0; arm_clk_div_tlb[i].rate != 0; i++) {
898 if(arm_clk_div_tlb[i].rate >= rate)
899 return &arm_clk_div_tlb[i];
906 static int arm_pll_clk_set_rate(struct clk *clk, unsigned long rate)
909 const struct apll_clk_set *ps;
910 u32 pll_id = clk->pll->id;
912 u32 old_aclk_div = 0, new_aclk_div;
914 ps = arm_pll_clk_get_best_pll_set(rate, (struct apll_clk_set *)clk->pll->table);
916 old_aclk_div = GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
917 new_aclk_div = GET_CORE_ACLK_VAL(ps->clksel1 & CORE_ACLK_MSK);
919 CLKDATA_LOG("apll will set rate(%lu) tlb con(%x,%x,%x),sel(%x,%x)\n",
920 ps->rate, ps->pllcon0, ps->pllcon1, ps->pllcon2, ps->clksel0, ps->clksel1);
922 if(general_pll_clk.rate > clk->rate) {
923 temp_div = clk_get_freediv(clk->rate, general_pll_clk.rate, 10);
928 // ungating cpu gpll path
929 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH) | CLK_UN_GATE(CLK_GATE_CPU_GPLL_PATH),
930 // CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
932 local_irq_save(flags);
933 //div arm clk for gpll
935 cru_writel(CORE_CLK_DIV_W_MSK|CORE_CLK_DIV(temp_div), CRU_CLKSELS_CON(0));
936 cru_writel(CORE_SEL_PLL_W_MSK|CORE_SEL_GPLL, CRU_CLKSELS_CON(0));
938 loops_per_jiffy = lpj_gpll / temp_div;
941 /*if core src don't select gpll ,apll neet to enter slow mode */
942 //cru_writel(PLL_MODE_SLOW(APLL_ID), CRU_MODE_CON);
945 cru_writel((0x1<<(16+1))|(0x1<<1), PLL_CONS(pll_id, 3));
952 cru_writel(ps->pllcon0, PLL_CONS(pll_id, 0));
953 cru_writel(ps->pllcon1, PLL_CONS(pll_id, 1));
955 rk30_clock_udelay(1);
956 cru_writel((0x1<<(16+1)), PLL_CONS(pll_id, 3));
958 pll_wait_lock(pll_id);
961 //cru_writel(PLL_MODE_NORM(APLL_ID), CRU_MODE_CON);
964 if(new_aclk_div>=old_aclk_div) {
965 cru_writel(ps->clksel0, CRU_CLKSELS_CON(0));
966 cru_writel(ps->clksel1, CRU_CLKSELS_CON(1));
969 cru_writel(CORE_SEL_PLL_W_MSK | CORE_SEL_APLL, CRU_CLKSELS_CON(0));
970 if(old_aclk_div>new_aclk_div) {
971 cru_writel(ps->clksel0, CRU_CLKSELS_CON(0));
972 cru_writel(ps->clksel1, CRU_CLKSELS_CON(1));
975 cru_writel(CORE_CLK_DIV_W_MSK|CORE_CLK_DIV(1), CRU_CLKSELS_CON(0));
977 loops_per_jiffy = ps->lpj;
980 //CLKDATA_DBG("apll set loops_per_jiffy =%lu,rate(%lu)\n",loops_per_jiffy,ps->rate);
982 local_irq_restore(flags);
986 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_CPU_GPLL_PATH) | CLK_GATE(CLK_GATE_CPU_GPLL_PATH)
987 // , CLK_GATE_CLKID_CONS(CLK_GATE_CPU_GPLL_PATH));
989 CLKDATA_LOG("apll set over con(%x,%x,%x,%x),sel(%x,%x)\n", cru_readl(PLL_CONS(pll_id, 0)),
990 cru_readl(PLL_CONS(pll_id, 1)), cru_readl(PLL_CONS(pll_id, 2)),
991 cru_readl(PLL_CONS(pll_id, 3)), cru_readl(CRU_CLKSELS_CON(0)),
992 cru_readl(CRU_CLKSELS_CON(1)));
997 /************************************pll clocks***************************/
999 static const struct apll_clk_set apll_clks[] = {
1000 //_APLL_SET_CLKS(_mhz, nr, nf, no, _periph_div,
1001 // _axi_core_div, _axi_div, _ahb_div, _apb_div, _ahb2apb)
1002 _APLL_SET_CLKS(2208, 1, 92, 1, 8, 81, 81, 21, 41, 21),
1003 _APLL_SET_CLKS(2184, 1, 91, 1, 8, 81, 81, 21, 41, 21),
1004 _APLL_SET_CLKS(2160, 1, 90, 1, 8, 81, 81, 21, 41, 21),
1005 _APLL_SET_CLKS(2136, 1, 89, 1, 8, 81, 81, 21, 41, 21),
1006 _APLL_SET_CLKS(2112, 1, 88, 1, 8, 81, 81, 21, 41, 21),
1007 _APLL_SET_CLKS(2088, 1, 87, 1, 8, 81, 81, 21, 41, 21),
1008 _APLL_SET_CLKS(2064, 1, 86, 1, 8, 81, 81, 21, 41, 21),
1009 _APLL_SET_CLKS(2040, 1, 85, 1, 8, 81, 81, 21, 41, 21),
1010 _APLL_SET_CLKS(2016, 1, 84, 1, 8, 81, 81, 21, 41, 21),
1011 _APLL_SET_CLKS(1992, 1, 83, 1, 8, 81, 81, 21, 41, 21),
1012 _APLL_SET_CLKS(1968, 1, 82, 1, 8, 81, 81, 21, 41, 21),
1013 _APLL_SET_CLKS(1944, 1, 81, 1, 8, 81, 81, 21, 41, 21),
1014 _APLL_SET_CLKS(1920, 1, 80, 1, 8, 81, 81, 21, 41, 21),
1015 _APLL_SET_CLKS(1896, 1, 79, 1, 8, 81, 81, 21, 41, 21),
1016 _APLL_SET_CLKS(1872, 1, 78, 1, 8, 81, 81, 21, 41, 21),
1017 _APLL_SET_CLKS(1848, 1, 77, 1, 8, 81, 81, 21, 41, 21),
1018 _APLL_SET_CLKS(1824, 1, 76, 1, 8, 81, 81, 21, 41, 21),
1019 _APLL_SET_CLKS(1800, 1, 75, 1, 8, 81, 81, 21, 41, 21),
1020 _APLL_SET_CLKS(1776, 1, 74, 1, 8, 81, 81, 21, 41, 21),
1021 _APLL_SET_CLKS(1752, 1, 73, 1, 8, 81, 81, 21, 41, 21),
1022 _APLL_SET_CLKS(1728, 1, 72, 1, 8, 81, 81, 21, 41, 21),
1023 _APLL_SET_CLKS(1704, 1, 71, 1, 8, 81, 81, 21, 41, 21),
1024 _APLL_SET_CLKS(1680, 1, 70, 1, 8, 41, 41, 21, 41, 21),
1025 _APLL_SET_CLKS(1656, 1, 69, 1, 8, 41, 41, 21, 41, 21),
1026 _APLL_SET_CLKS(1632, 1, 68, 1, 8, 41, 41, 21, 41, 21),
1027 _APLL_SET_CLKS(1608, 1, 67, 1, 8, 41, 41, 21, 41, 21),
1028 _APLL_SET_CLKS(1560, 1, 65, 1, 8, 41, 41, 21, 41, 21),
1029 _APLL_SET_CLKS(1512, 1, 63, 1, 8, 41, 41, 21, 41, 21),
1030 _APLL_SET_CLKS(1488, 1, 62, 1, 8, 41, 41, 21, 41, 21),
1031 _APLL_SET_CLKS(1464, 1, 61, 1, 8, 41, 41, 21, 41, 21),
1032 _APLL_SET_CLKS(1440, 1, 60, 1, 8, 41, 41, 21, 41, 21),
1033 _APLL_SET_CLKS(1416, 1, 59, 1, 8, 41, 41, 21, 41, 21),
1034 _APLL_SET_CLKS(1392, 1, 58, 1, 8, 41, 41, 21, 41, 21),
1035 _APLL_SET_CLKS(1368, 1, 57, 1, 8, 41, 41, 21, 41, 21),
1036 _APLL_SET_CLKS(1344, 1, 56, 1, 8, 41, 41, 21, 41, 21),
1037 _APLL_SET_CLKS(1320, 1, 55, 1, 8, 41, 41, 21, 41, 21),
1038 _APLL_SET_CLKS(1296, 1, 54, 1, 8, 41, 41, 21, 41, 21),
1039 _APLL_SET_CLKS(1272, 1, 53, 1, 8, 41, 41, 21, 41, 21),
1040 _APLL_SET_CLKS(1248, 1, 52, 1, 8, 41, 41, 21, 41, 21),
1041 _APLL_SET_CLKS(1224, 1, 51, 1, 8, 41, 41, 21, 41, 21),
1042 _APLL_SET_CLKS(1200, 1, 50, 1, 8, 41, 41, 21, 41, 21),
1043 _APLL_SET_CLKS(1176, 1, 49, 1, 8, 41, 41, 21, 41, 21),
1044 _APLL_SET_CLKS(1128, 1, 47, 1, 8, 41, 41, 21, 41, 21),
1045 _APLL_SET_CLKS(1104, 1, 46, 1, 8, 41, 41, 21, 41, 21),
1046 _APLL_SET_CLKS(1008, 1, 84, 2, 8, 41, 31, 21, 41, 21),
1047 _APLL_SET_CLKS(912, 1, 76, 2, 8, 41, 31, 21, 41, 21),
1048 _APLL_SET_CLKS(888, 1, 74, 2, 8, 41, 31, 21, 41, 21),
1049 _APLL_SET_CLKS(816 , 1, 68, 2, 8, 41, 31, 21, 41, 21),
1050 _APLL_SET_CLKS(792 , 1, 66, 2, 8, 41, 31, 21, 41, 21),
1051 _APLL_SET_CLKS(696 , 1, 58, 2, 8, 41, 31, 21, 41, 21),
1052 _APLL_SET_CLKS(600 , 1, 50, 2, 4, 41, 31, 21, 41, 21),
1053 _APLL_SET_CLKS(504 , 1, 84, 4, 4, 41, 21, 21, 41, 21),
1054 _APLL_SET_CLKS(408 , 1, 68, 4, 4, 21, 21, 21, 41, 21),
1055 _APLL_SET_CLKS(312 , 1, 52, 4, 2, 21, 21, 21, 21, 11),
1056 _APLL_SET_CLKS(252 , 1, 84, 8, 2, 21, 21, 21, 21, 11),
1057 _APLL_SET_CLKS(216 , 1, 72, 8, 2, 21, 21, 21, 21, 11),
1058 _APLL_SET_CLKS(126 , 1, 84, 16, 2, 11, 21, 11, 11, 11),
1059 _APLL_SET_CLKS(48 , 1, 64, 32, 2, 11, 11, 11, 11, 11),
1060 _APLL_SET_CLKS(0 , 1, 21, 4, 2, 11, 11, 11, 11, 11),
1063 static struct _pll_data apll_data = SET_PLL_DATA(APLL_ID, (void *)apll_clks);
1064 static struct clk arm_pll_clk = {
1067 .mode = pll_clk_mode,
1068 .recalc = plls_clk_recalc,
1069 .set_rate = arm_pll_clk_set_rate,
1070 .round_rate = arm_pll_clk_round_rate,
1074 static int ddr_pll_clk_set_rate(struct clk *clk, unsigned long rate)
1076 /* do nothing here */
1079 static struct _pll_data dpll_data = SET_PLL_DATA(DPLL_ID, NULL);
1080 static struct clk ddr_pll_clk = {
1083 .recalc = plls_clk_recalc,
1084 .set_rate = ddr_pll_clk_set_rate,
1088 static const struct pll_clk_set cpll_clks[] = {
1089 _PLL_SET_CLKS(360000, 1, 60, 4),
1090 _PLL_SET_CLKS(408000, 1, 68, 4),
1091 _PLL_SET_CLKS(456000, 1, 76, 4),
1092 _PLL_SET_CLKS(504000, 1, 84, 4),
1093 _PLL_SET_CLKS(552000, 1, 46, 2),
1094 _PLL_SET_CLKS(600000, 1, 50, 2),
1095 _PLL_SET_CLKS(742500, 8, 495, 2),
1096 _PLL_SET_CLKS(768000, 1, 64, 2),
1097 _PLL_SET_CLKS(798000, 2, 133, 2),
1098 _PLL_SET_CLKS(1188000, 2, 99, 1),
1099 _PLL_SET_CLKS( 0, 4, 133, 1),
1101 static struct _pll_data cpll_data = SET_PLL_DATA(CPLL_ID, (void *)cpll_clks);
1102 static struct clk codec_pll_clk = {
1103 .name = "codec_pll",
1105 .mode = pll_clk_mode,
1106 .recalc = plls_clk_recalc,
1107 .set_rate = cpll_clk_set_rate,
1111 static const struct pll_clk_set gpll_clks[] = {
1112 _PLL_SET_CLKS(148500, 2, 99, 8),
1113 _PLL_SET_CLKS(297000, 2, 198, 8),
1114 _PLL_SET_CLKS(300000, 1, 50, 4),
1115 _PLL_SET_CLKS(594000, 2, 198, 4),
1116 _PLL_SET_CLKS(1188000, 2, 99, 1),
1117 _PLL_SET_CLKS(1200000, 1, 50, 1),
1118 _PLL_SET_CLKS(0, 0, 0, 0),
1120 static struct _pll_data gpll_data = SET_PLL_DATA(GPLL_ID, (void *)gpll_clks);
1121 static struct clk general_pll_clk = {
1122 .name = "general_pll",
1124 .recalc = plls_clk_recalc,
1125 .set_rate = gpll_clk_set_rate,
1128 /********************************clocks***********************************/
1129 GATE_CLK(ddr_gpll_path, general_pll_clk, DDR_GPLL);
1131 /* core and cpu setting */
1132 static int ddr_clk_set_rate(struct clk *c, unsigned long rate)
1134 CLKDATA_DBG("%s do nothing for ddr set rate\n", __func__);
1138 static long ddr_clk_round_rate(struct clk *clk, unsigned long rate)
1140 CLKDATA_DBG("%s do nothing for ddr round rate\n", __func__);
1141 return ddr_set_pll_rk3066b(rate / MHZ, 0) * MHZ;
1143 static unsigned long ddr_clk_recalc_rate(struct clk *clk)
1145 u32 shift = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift);
1146 unsigned long rate = clk->parent->recalc(clk->parent) >> shift;
1147 //CLKDATA_DBG("%s new clock rate is %lu (shift %u)\n", clk->name, rate, shift);
1150 static struct clk *clk_ddr_parents[2] = {&ddr_pll_clk, &clk_ddr_gpll_path};
1151 static struct clk clk_ddr = {
1153 .parent = &ddr_pll_clk,
1154 .recalc = ddr_clk_recalc_rate,
1155 .set_rate = ddr_clk_set_rate,
1156 .round_rate = ddr_clk_round_rate,
1157 .gate_idx = CLK_GATE_DDRPHY,
1158 .clksel_con = CRU_CLKSELS_CON(26),
1159 CRU_DIV_SET(0x3, 0, 4),
1161 CRU_PARENTS_SET(clk_ddr_parents),
1163 static int clk_core_set_rate(struct clk *c, unsigned long rate)
1167 ret = clk_set_rate_nolock(c->parent, rate);
1169 CLKDATA_ERR("Failed to change clk pll %s to %lu\n", c->name, rate);
1173 set_cru_bits_w_msk(0, c->div_mask, c->div_shift, c->clksel_con);
1176 static unsigned long clk_core_get_rate(struct clk *c)
1178 u32 div = (get_cru_bits(c->clksel_con, c->div_mask, c->div_shift) + 1);
1179 //c->parent->rate=c->parent->recalc(c->parent);
1180 return c->parent->rate / div;
1182 static long core_clk_round_rate(struct clk *clk, unsigned long rate)
1184 u32 div = (get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1);
1185 return clk_round_rate_nolock(clk->parent, rate) / div;
1188 static int core_clksel_set_parent(struct clk *clk, struct clk *new_prt)
1192 struct clk *old_prt;
1194 if(clk->parent == new_prt)
1196 if (unlikely(!clk->parents))
1198 CLKDATA_DBG("%s,reparent %s\n", clk->name, new_prt->name);
1200 old_prt = clk->parent;
1202 if(clk->parents[0] == new_prt) {
1203 new_prt->set_rate(new_prt, 300 * MHZ);
1204 set_cru_bits_w_msk(0, clk->div_mask, clk->div_shift, clk->clksel_con);
1205 } else if(clk->parents[1] == new_prt) {
1207 if(new_prt->rate > old_prt->rate) {
1208 temp_div = clk_get_freediv(old_prt->rate, new_prt->rate, clk->div_max);
1209 set_cru_bits_w_msk(temp_div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
1211 set_cru_bits_w_msk(1, clk->src_mask, clk->src_shift, clk->clksel_con);
1212 new_prt->set_rate(new_prt, 300 * MHZ);
1221 static int core_gpll_clk_set_rate(struct clk *c, unsigned long rate)
1224 u32 old_aclk_div = 0, new_aclk_div;
1225 struct arm_clks_div_set *temp_clk_div;
1226 unsigned long arm_gpll_rate, arm_gpll_lpj;
1227 temp_div = clk_get_freediv(rate, c->parent->rate, c->div_max);
1228 arm_gpll_rate = c->parent->rate / temp_div;
1230 temp_clk_div = arm_clks_get_div(arm_gpll_rate / MHZ);
1232 temp_clk_div = &arm_clk_div_tlb[4];
1234 old_aclk_div = GET_CORE_ACLK_VAL(cru_readl(CRU_CLKSELS_CON(1))&CORE_ACLK_MSK);
1235 new_aclk_div = GET_CORE_ACLK_VAL(temp_clk_div->clksel1 & CORE_ACLK_MSK);
1236 if(c->rate >= rate) {
1237 arm_gpll_lpj = lpj_gpll / temp_div;
1238 set_cru_bits_w_msk(temp_div - 1, c->div_mask, c->div_shift, c->clksel_con);
1241 cru_writel((temp_clk_div->clksel1), CRU_CLKSELS_CON(1));
1242 cru_writel((temp_clk_div->clksel0) | CORE_CLK_DIV(temp_div) | CORE_CLK_DIV_W_MSK,
1243 CRU_CLKSELS_CON(0));
1244 if((c->rate < rate)) {
1245 arm_gpll_lpj = lpj_gpll / temp_div;
1246 set_cru_bits_w_msk(temp_div - 1, c->div_mask, c->div_shift, c->clksel_con);
1250 static unsigned long arm_core_gpll_clk_get_rate(struct clk *c)
1252 return c->parent->rate;
1254 static struct clk clk_core_gpll_path = {
1255 .name = "cpu_gpll_path",
1256 .parent = &general_pll_clk,
1257 .recalc = arm_core_gpll_clk_get_rate,
1258 .set_rate = core_gpll_clk_set_rate,
1259 CRU_GATE_MODE_SET(gate_mode, CLK_GATE_CPU_GPLL_PATH),
1263 static struct clk *clk_core_parents[2] = {&arm_pll_clk, &clk_core_gpll_path};
1265 static struct clk clk_core = {
1267 .parent = &arm_pll_clk,
1268 .set_rate = clk_core_set_rate,
1269 .recalc = clk_core_get_rate,
1270 .round_rate = core_clk_round_rate,
1271 .set_parent = core_clksel_set_parent,
1272 .clksel_con = CRU_CLKSELS_CON(0),
1273 CRU_DIV_SET(0x1f, 9, 32),
1275 CRU_PARENTS_SET(clk_core_parents),
1277 GATE_CLK(l2c, clk_core, CLK_L2C);
1278 GATE_CLK(core_dbg, clk_core, CLK_CORE_DBG);
1279 static unsigned long aclk_recalc(struct clk *clk)
1282 u32 div = get_cru_bits(clk->clksel_con, clk->div_mask, clk->div_shift) + 1;
1287 rate = clk->parent->rate / div;
1288 pr_debug("%s new clock rate is %ld (div %d)\n", clk->name, rate, div);
1292 static struct clk core_periph = {
1293 .name = "core_periph",
1294 .parent = &clk_core,
1295 .gate_idx = CLK_GATE_CORE_PERIPH,
1296 .recalc = clksel_recalc_shift_2,
1297 .clksel_con = CRU_CLKSELS_CON(0),
1298 CRU_DIV_SET(0x3, 6, 16),
1300 static struct clk aclk_core = {
1301 .name = "aclk_core",
1302 .parent = &clk_core,
1303 .gate_idx = CLK_GATE_ACLK_CORE,
1304 .recalc = aclk_recalc,
1305 .clksel_con = CRU_CLKSELS_CON(1),
1306 CRU_DIV_SET(0x7, 3, 8),
1309 static struct clk *clk_cpu_div_parents[2] = {&arm_pll_clk, &general_pll_clk};
1310 static struct clk clk_cpu_div = {
1312 .parent = &arm_pll_clk,
1313 .set_rate = clksel_set_rate_freediv,
1314 .recalc = clksel_recalc_div,
1315 .clksel_con = CRU_CLKSELS_CON(0),
1316 CRU_DIV_SET(0x1f, 0, 32),
1318 CRU_PARENTS_SET(clk_cpu_div_parents),
1321 static struct clk aclk_cpu = {
1323 .parent = &clk_cpu_div,
1324 .gate_idx = CLK_GATE_ACLK_CPU,
1327 static struct clk hclk_cpu = {
1329 .parent = &aclk_cpu,
1330 .gate_idx = CLK_GATE_HCLK_CPU,
1331 .recalc = clksel_recalc_shift,
1332 .set_rate = clksel_set_rate_shift,
1333 .clksel_con = CRU_CLKSELS_CON(1),
1334 CRU_DIV_SET(0x3, 8, 4),
1338 static struct clk pclk_cpu = {
1340 .parent = &aclk_cpu,
1341 .gate_idx = CLK_GATE_PCLK_CPU,
1342 .recalc = clksel_recalc_shift,
1343 .set_rate = clksel_set_rate_shift,
1344 .clksel_con = CRU_CLKSELS_CON(1),
1345 CRU_DIV_SET(0x3, 12, 8),
1348 static struct clk ahb2apb_cpu = {
1350 .parent = &hclk_cpu,
1351 .recalc = clksel_recalc_shift,
1352 .set_rate = clksel_set_rate_shift,
1353 .clksel_con = CRU_CLKSELS_CON(1),
1354 CRU_DIV_SET(0x3, 14, 4),
1358 static struct clk atclk_cpu = {
1359 .name = "atclk_cpu",
1360 .parent = &pclk_cpu,
1361 .gate_idx = CLK_GATE_ATCLK_CPU,
1365 static int clk_gpu_set_rate(struct clk *clk, unsigned long rate)
1367 unsigned long max_rate = rate / 100 * 105; /* +5% */
1368 return clkset_rate_freediv_autosel_parents(clk, max_rate);
1371 static struct clk *aclk_gpu_parents[2] = {&codec_pll_clk, &general_pll_clk};
1373 static struct clk aclk_gpu = {
1376 .recalc = clksel_recalc_div,
1377 .round_rate = clk_freediv_round_autosel_parents_rate,
1378 .set_rate = clkset_rate_freediv_autosel_parents,
1379 .clksel_con = CRU_CLKSELS_CON(34),
1380 .gate_idx = CLK_GATE_ACLK_GPU,
1381 CRU_DIV_SET(0x1f, 0, 32),
1382 CRU_SRC_SET(0x1, 7),
1383 CRU_PARENTS_SET(aclk_gpu_parents),
1386 /* vcodec setting */
1387 static unsigned long clksel_recalc_vpu_hclk(struct clk *clk)
1389 unsigned long rate = clk->parent->rate / 4;
1390 pr_debug("%s new clock rate is %lu (div %u)\n", clk->name, rate, 4);
1394 static struct clk *aclk_vepu_parents[2] = {&codec_pll_clk, &general_pll_clk};
1396 static struct clk aclk_vepu = {
1397 .name = "aclk_vepu",
1398 .parent = &codec_pll_clk,
1400 .recalc = clksel_recalc_div,
1401 .set_rate = clkset_rate_freediv_autosel_parents,
1402 .clksel_con = CRU_CLKSELS_CON(32),
1403 .gate_idx = CLK_GATE_ACLK_VEPU,
1404 CRU_DIV_SET(0x1f, 0, 32),
1405 CRU_SRC_SET(0x1, 7),
1406 CRU_PARENTS_SET(aclk_vepu_parents),
1409 static struct clk *aclk_vdpu_parents[2] = {&codec_pll_clk, &general_pll_clk};
1411 static struct clk aclk_vdpu = {
1412 .name = "aclk_vdpu",
1414 .recalc = clksel_recalc_div,
1415 .set_rate = clkset_rate_freediv_autosel_parents,
1416 .clksel_con = CRU_CLKSELS_CON(32),
1417 .gate_idx = CLK_GATE_ACLK_VDPU,
1418 CRU_DIV_SET(0x1f, 8, 32),
1419 CRU_SRC_SET(0x1, 15),
1420 CRU_PARENTS_SET(aclk_vdpu_parents),
1422 static struct clk hclk_vepu = {
1423 .name = "hclk_vepu",
1424 .parent = &aclk_vepu,
1426 .recalc = clksel_recalc_vpu_hclk,
1427 .gate_idx = CLK_GATE_HCLK_VEPU,
1430 static struct clk hclk_vdpu = {
1431 .name = "hclk_vdpu",
1432 .parent = &aclk_vdpu,
1434 .recalc = clksel_recalc_vpu_hclk,
1435 .gate_idx = CLK_GATE_HCLK_VDPU,
1438 /* aclk lcdc setting */
1439 static struct clk *aclk_lcdc0_parents[] = {&codec_pll_clk, &general_pll_clk};
1441 static struct clk aclk_lcdc0_pre = {
1442 .name = "aclk_lcdc0_pre",
1443 .parent = &codec_pll_clk,
1445 .recalc = clksel_recalc_div,
1446 .set_rate = clkset_rate_freediv_autosel_parents,
1447 .gate_idx = CLK_GATE_ACLK_LCDC0_SRC,
1448 .clksel_con = CRU_CLKSELS_CON(31),
1449 CRU_DIV_SET(0x1f, 0, 32),
1450 CRU_SRC_SET(0x1, 7),
1451 CRU_PARENTS_SET(aclk_lcdc0_parents),
1454 static struct clk *aclk_lcdc1_parents[] = {&codec_pll_clk, &general_pll_clk};
1456 static struct clk aclk_lcdc1_pre = {
1457 .name = "aclk_lcdc1_pre",
1458 .parent = &codec_pll_clk,
1460 .recalc = clksel_recalc_div,
1461 .set_rate = clkset_rate_freediv_autosel_parents,
1462 .gate_idx = CLK_GATE_ACLK_LCDC1_SRC,
1463 .clksel_con = CRU_CLKSELS_CON(31),
1464 CRU_DIV_SET(0x1f, 8, 32),
1465 CRU_SRC_SET(0x1, 15),
1466 CRU_PARENTS_SET(aclk_lcdc1_parents),
1469 /* aclk/hclk/pclk periph setting */
1470 static struct clk *aclk_periph_parents[2] = {&codec_pll_clk, &general_pll_clk};
1472 static struct clk aclk_periph = {
1473 .name = "aclk_periph",
1474 .parent = &general_pll_clk,
1476 .gate_idx = CLK_GATE_ACLK_PERIPH,
1477 .recalc = clksel_recalc_div,
1478 .set_rate = clksel_set_rate_freediv,
1479 .clksel_con = CRU_CLKSELS_CON(10),
1480 CRU_DIV_SET(0x1f, 0, 32),
1482 CRU_PARENTS_SET(aclk_periph_parents),
1484 GATE_CLK(periph_src, aclk_periph, PERIPH_SRC);
1486 static struct clk pclk_periph = {
1487 .name = "pclk_periph",
1488 .parent = &aclk_periph,
1490 .gate_idx = CLK_GATE_PCLK_PERIPH,
1491 .recalc = clksel_recalc_shift,
1492 .set_rate = clksel_set_rate_shift,
1493 .clksel_con = CRU_CLKSELS_CON(10),
1494 CRU_DIV_SET(0x3, 12, 8),
1497 static struct clk hclk_periph = {
1498 .name = "hclk_periph",
1499 .parent = &aclk_periph,
1501 .gate_idx = CLK_GATE_HCLK_PERIPH,
1502 .recalc = clksel_recalc_shift,
1503 .set_rate = clksel_set_rate_shift,
1504 .clksel_con = CRU_CLKSELS_CON(10),
1505 CRU_DIV_SET(0x3, 8, 4),
1507 /* dclk lcdc setting */
1509 static int clksel_set_rate_hdmi(struct clk *clk, unsigned long rate)
1513 unsigned long new_rate;
1516 if(clk->rate == rate)
1518 for(i = 0; i < 2; i++) {
1519 div = clk_get_freediv(rate, clk->parents[i]->rate, clk->div_max);
1520 new_rate = clk->parents[i]->rate / div;
1521 if((rate == new_rate) && !(clk->parents[i]->rate % div)) {
1526 CLKDATA_ERR("%s can't set fixed rate%lu\n", clk->name, rate);
1530 //CLKDATA_DBG("%s set rate %lu(from %s)\n",clk->name,rate,clk->parents[i]->name);
1532 old_div = CRU_GET_REG_BITS_VAL(cru_readl(clk->clksel_con),
1533 clk->div_shift, clk->div_mask) + 1;
1535 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
1537 if(clk->parents[i] != clk->parent) {
1538 ret = clk_set_parent_nolock(clk, clk->parents[i]);
1542 CLKDATA_ERR("lcdc1 %s can't get rate%lu,reparent%s(now %s) err\n",
1543 clk->name, rate, clk->parents[i]->name, clk->parent->name);
1546 set_cru_bits_w_msk(div - 1, clk->div_mask, clk->div_shift, clk->clksel_con);
1550 static int dclk_lcdc_set_rate(struct clk *clk, unsigned long rate)
1552 if (rate == 27 * MHZ)
1553 return clkset_rate_freediv_autosel_parents(clk, rate);
1555 return clkset_rate_evendiv_autosel_parents(clk, rate);
1560 if (rate == 27 * MHZ && (rk30_clock_flags & CLK_FLG_EXT_27MHZ)) {
1561 parent = clk->parents[1];
1562 //CLKDATA_DBG(" %s from=%s\n",clk->name,parent->name);
1564 parent = clk->parents[0];
1566 //CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1567 //clk->name,rate,parent->name,clk->parent->name);
1569 if(parent != clk->parents[1]) {
1570 ret = clk_set_rate_nolock(parent, rate); //div 1:1
1572 CLKDATA_DBG("%s set rate=%lu err\n", clk->name, rate);
1576 if (clk->parent != parent) {
1577 ret = clk_set_parent_nolock(clk, parent);
1579 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
1587 static struct clk *dclk_lcdc0_parents[2] = {&codec_pll_clk, &general_pll_clk};
1588 static struct clk dclk_lcdc0 = {
1589 .name = "dclk_lcdc0",
1591 .set_rate = dclk_lcdc_set_rate,
1592 .recalc = clksel_recalc_div,
1593 .gate_idx = CLK_GATE_DCLK_LCDC0_SRC,
1594 .clksel_con = CRU_CLKSELS_CON(27),
1595 CRU_SRC_SET(0x1, 0),
1596 CRU_DIV_SET(0xff, 8, 256),
1597 CRU_PARENTS_SET(dclk_lcdc0_parents),
1600 static struct clk *dclk_lcdc1_parents[2] = {&codec_pll_clk, &general_pll_clk};
1601 static struct clk dclk_lcdc1 = {
1602 .name = "dclk_lcdc1",
1604 .set_rate = dclk_lcdc_set_rate,
1605 .recalc = clksel_recalc_div,
1606 .gate_idx = CLK_GATE_DCLK_LCDC1_SRC,
1607 .clksel_con = CRU_CLKSELS_CON(28),
1608 CRU_SRC_SET(0x1, 0),
1609 CRU_DIV_SET(0xff, 8, 256),
1610 CRU_PARENTS_SET(dclk_lcdc1_parents),
1615 static struct clk *cifout_sel_pll_parents[2] = {&codec_pll_clk, &general_pll_clk};
1616 static struct clk cif_out_pll = {
1617 .name = "cif_out_pll",
1618 .parent = &general_pll_clk,
1619 .clksel_con = CRU_CLKSELS_CON(29),
1620 CRU_SRC_SET(0x1, 0),
1621 CRU_PARENTS_SET(cifout_sel_pll_parents),
1624 static struct clk cif0_out_div = {
1625 .name = "cif0_out_div",
1626 .parent = &cif_out_pll,
1628 .recalc = clksel_recalc_div,
1629 .set_rate = clksel_set_rate_freediv,
1630 .gate_idx = CLK_GATE_CIF0_OUT,
1631 .clksel_con = CRU_CLKSELS_CON(29),
1632 CRU_DIV_SET(0x1f, 1, 32),
1635 static int cif_out_set_rate(struct clk *clk, unsigned long rate)
1640 if (rate == 24 * MHZ) {
1641 parent = clk->parents[1];
1643 parent = clk->parents[0];
1644 ret = clk_set_rate_nolock(parent, rate);
1648 if (clk->parent != parent)
1649 ret = clk_set_parent_nolock(clk, parent);
1654 static struct clk *cif0_out_parents[2] = {&cif0_out_div, &xin24m};
1655 static struct clk cif0_out = {
1657 .parent = &cif0_out_div,
1658 .set_rate = cif_out_set_rate,
1659 .clksel_con = CRU_CLKSELS_CON(29),
1660 CRU_SRC_SET(0x1, 7),
1661 CRU_PARENTS_SET(cif0_out_parents),
1664 static struct clk pclkin_cif0 = {
1665 .name = "pclkin_cif0",
1667 .gate_idx = CLK_GATE_PCLKIN_CIF0,
1670 static struct clk inv_cif0 = {
1672 .parent = &pclkin_cif0,
1675 static struct clk *cif0_in_parents[2] = {&pclkin_cif0, &inv_cif0};
1676 static struct clk cif0_in = {
1678 .parent = &pclkin_cif0,
1679 .clksel_con = CRU_CLKSELS_CON(30),
1680 CRU_SRC_SET(0x1, 8),
1681 CRU_PARENTS_SET(cif0_in_parents),
1684 /* i2s/spdif setting */
1685 static struct clk *clk_i2s_div_parents[] = {&general_pll_clk, &codec_pll_clk};
1686 static struct clk clk_i2s_pll = {
1688 .parent = &general_pll_clk,
1689 .clksel_con = CRU_CLKSELS_CON(2),
1690 CRU_SRC_SET(0x1, 15),
1691 CRU_PARENTS_SET(clk_i2s_div_parents),
1694 static struct clk clk_i2s0_div = {
1696 .parent = &clk_i2s_pll,
1698 .recalc = clksel_recalc_div,
1699 .set_rate = clksel_set_rate_freediv,
1700 .round_rate = clksel_freediv_round_rate,
1701 .gate_idx = CLK_GATE_I2S0_SRC,
1702 .clksel_con = CRU_CLKSELS_CON(3),
1703 CRU_DIV_SET(0x7f, 0, 64),
1706 static struct clk clk_spdif_div = {
1707 .name = "spdif_div",
1708 .parent = &clk_i2s_pll,
1709 .recalc = clksel_recalc_div,
1710 .set_rate = clksel_set_rate_freediv,
1711 .round_rate = clksel_freediv_round_rate,
1713 .gate_idx = CLK_GATE_SPDIF_SRC,
1714 .clksel_con = CRU_CLKSELS_CON(5),
1715 CRU_DIV_SET(0x7f, 0, 64),
1717 static int clk_i2s_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1719 u32 numerator, denominator;
1720 //clk_i2s_div->clk_i2s_pll->gpll/cpll
1721 //clk->parent->parent
1722 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1723 &numerator, &denominator) == 0) {
1724 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
1725 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1726 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
1728 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1734 static struct clk clk_i2s0_frac_div = {
1735 .name = "i2s0_frac_div",
1736 .parent = &clk_i2s0_div,
1738 .gate_idx = CLK_GATE_I2S0_FRAC,
1739 .recalc = clksel_recalc_frac,
1740 .set_rate = clk_i2s_fracdiv_set_rate,
1741 .clksel_con = CRU_CLKSELS_CON(7),
1744 static struct clk clk_spdif_frac_div = {
1745 .name = "spdif_frac_div",
1746 .parent = &clk_spdif_div,
1748 .gate_idx = CLK_GATE_SPDIF_FRAC,
1749 .recalc = clksel_recalc_frac,
1750 .set_rate = clk_i2s_fracdiv_set_rate,
1751 .clksel_con = CRU_CLKSELS_CON(9),
1754 #define I2S_SRC_DIV (0x0)
1755 #define I2S_SRC_FRAC (0x1)
1756 #define I2S_SRC_12M (0x2)
1758 static int i2s_set_rate(struct clk *clk, unsigned long rate)
1763 if (rate == clk->parents[I2S_SRC_12M]->rate) {
1764 parent = clk->parents[I2S_SRC_12M];
1765 } else if((long)clk_round_rate_nolock(clk->parents[I2S_SRC_DIV], rate) == rate) {
1766 parent = clk->parents[I2S_SRC_DIV];
1768 parent = clk->parents[I2S_SRC_FRAC];
1771 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1772 clk->name, rate, parent->name, clk->parent->name);
1774 if(parent != clk->parents[I2S_SRC_12M]) {
1775 ret = clk_set_rate_nolock(parent, rate); //div 1:1
1777 CLKDATA_DBG("%s set rate%lu err\n", clk->name, rate);
1782 if (clk->parent != parent) {
1783 ret = clk_set_parent_nolock(clk, parent);
1785 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
1793 static struct clk *clk_i2s0_parents[3] = {&clk_i2s0_div, &clk_i2s0_frac_div, &clk_12m};
1795 static struct clk clk_i2s0 = {
1797 .set_rate = i2s_set_rate,
1798 .clksel_con = CRU_CLKSELS_CON(3),
1799 CRU_SRC_SET(0x3, 8),
1800 CRU_PARENTS_SET(clk_i2s0_parents),
1803 static struct clk *clk_spdif_parents[3] = {&clk_spdif_div, &clk_spdif_frac_div, &clk_12m};
1805 static struct clk clk_spdif = {
1807 .parent = &clk_spdif_frac_div,
1808 .set_rate = i2s_set_rate,
1809 .clksel_con = CRU_CLKSELS_CON(5),
1810 CRU_SRC_SET(0x3, 8),
1811 CRU_PARENTS_SET(clk_spdif_parents),
1814 /* otgphy setting */
1815 GATE_CLK(otgphy0, xin24m, OTGPHY0);
1816 GATE_CLK(otgphy1, xin24m, OTGPHY1);
1818 static struct clk clk_otgphy0_480m = {
1819 .name = "otgphy0_480m",
1820 .parent = &clk_otgphy0,
1822 static struct clk clk_otgphy1_480m = {
1823 .name = "otgphy1_480m",
1824 .parent = &clk_otgphy1,
1827 /* hsicphy setting */
1829 static struct clk *clk_hsicphy_parents[4] = {&clk_otgphy0_480m, &clk_otgphy1_480m, &general_pll_clk, &codec_pll_clk};
1830 static struct clk clk_hsicphy_480m = {
1831 .name = "hsicphy_480m",
1832 .parent = &clk_otgphy0_480m,
1833 .clksel_con = CRU_CLKSELS_CON(30),
1834 CRU_SRC_SET(0x3, 0),
1835 CRU_PARENTS_SET(clk_hsicphy_parents),
1837 static struct clk clk_hsicphy_12m = {
1838 .name = "hsicphy_12m",
1839 .parent = &clk_hsicphy_480m,
1840 .clksel_con = CRU_CLKSELS_CON(11),
1841 CRU_DIV_SET(0x3f, 8, 64),
1845 /* mac and rmii setting */
1847 static struct clk rmii_clkin = {
1848 .name = "rmii_clkin",
1850 static struct clk *clk_mac_ref_div_parents[2] = {&general_pll_clk, &ddr_pll_clk};
1851 static struct clk clk_mac_pll_div = {
1852 .name = "mac_pll_div",
1853 .parent = &general_pll_clk,
1855 .gate_idx = CLK_GATE_MAC_SRC,
1856 .recalc = clksel_recalc_div,
1857 .set_rate = clksel_set_rate_freediv,
1858 .clksel_con = CRU_CLKSELS_CON(21),
1859 CRU_DIV_SET(0x1f, 8, 32),
1860 CRU_SRC_SET(0x1, 0),
1861 CRU_PARENTS_SET(clk_mac_ref_div_parents),
1864 static int clksel_mac_ref_set_rate(struct clk *clk, unsigned long rate)
1866 if(clk->parent == clk->parents[1]) {
1867 CLKDATA_DBG("mac_ref clk is form mii clkin,can't set it\n" );
1869 } else if(clk->parent == clk->parents[0]) {
1870 return clk_set_rate_nolock(clk->parents[0], rate);
1875 static struct clk *clk_mac_ref_parents[2] = {&clk_mac_pll_div, &rmii_clkin};
1877 static struct clk clk_mac_ref = {
1879 .parent = &clk_mac_pll_div,
1880 .set_rate = clksel_mac_ref_set_rate,
1881 .clksel_con = CRU_CLKSELS_CON(21),
1882 CRU_SRC_SET(0x1, 4),
1883 CRU_PARENTS_SET(clk_mac_ref_parents),
1886 static int clk_set_mii_tx_parent(struct clk *clk, struct clk *parent)
1888 return clk_set_parent_nolock(clk->parent, parent);
1891 static struct clk clk_mii_tx = {
1893 .parent = &clk_mac_ref,
1894 //.set_parent = clk_set_mii_tx_parent,
1896 .gate_idx = CLK_GATE_MAC_LBTEST,
1899 /* hsadc and saradc */
1900 static struct clk *clk_hsadc_pll_parents[2] = {&general_pll_clk, &codec_pll_clk};
1901 static struct clk clk_hsadc_pll_div = {
1902 .name = "hsadc_pll_div",
1903 .parent = &general_pll_clk,
1905 .gate_idx = CLK_GATE_HSADC_SRC,
1906 .recalc = clksel_recalc_div,
1907 .round_rate = clk_freediv_round_autosel_parents_rate,
1908 .set_rate = clkset_rate_freediv_autosel_parents,
1909 //.round_rate = clksel_freediv_round_rate,
1910 //.set_rate = clksel_set_rate_freediv,
1911 .clksel_con = CRU_CLKSELS_CON(22),
1912 CRU_DIV_SET(0xff, 8, 256),
1913 CRU_SRC_SET(0x1, 0),
1914 CRU_PARENTS_SET(clk_hsadc_pll_parents),
1916 static int clk_hsadc_fracdiv_set_rate_fixed_parent(struct clk *clk, unsigned long rate)
1918 u32 numerator, denominator;
1919 // clk_hsadc_pll_div->gpll/cpll
1920 //clk->parent->parent
1921 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1922 &numerator, &denominator) == 0) {
1923 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
1925 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1927 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
1929 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1934 static int clk_hsadc_fracdiv_set_rate_auto_parents(struct clk *clk, unsigned long rate)
1936 u32 numerator, denominator;
1938 // clk_hsadc_pll_div->gpll/cpll
1939 //clk->parent->parent
1940 for(i = 0; i < 2; i++) {
1941 if(frac_div_get_seting(rate, clk->parent->parents[i]->rate,
1942 &numerator, &denominator) == 0)
1948 if(clk->parent->parent != clk->parent->parents[i])
1949 ret = clk_set_parent_nolock(clk->parent, clk->parent->parents[i]);
1951 clk_set_rate_nolock(clk->parent, clk->parent->parents[i]->rate); //PLL:DIV 1:
1953 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1955 CLKDATA_DBG("clk_frac_div %s, rate=%lu\n", clk->name, rate);
1957 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1963 static long clk_hsadc_fracdiv_round_rate(struct clk *clk, unsigned long rate)
1965 u32 numerator, denominator;
1967 CLKDATA_ERR("clk_hsadc_fracdiv_round_rate\n");
1968 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1969 &numerator, &denominator) == 0)
1974 static struct clk clk_hsadc_frac_div = {
1975 .name = "hsadc_frac_div",
1976 .parent = &clk_hsadc_pll_div,
1978 .recalc = clksel_recalc_frac,
1979 .set_rate = clk_hsadc_fracdiv_set_rate_auto_parents,
1980 .round_rate = clk_hsadc_fracdiv_round_rate,
1981 .gate_idx = CLK_GATE_HSADC_FRAC_SRC,
1982 .clksel_con = CRU_CLKSELS_CON(23),
1985 #define HSADC_SRC_DIV 0x0
1986 #define HSADC_SRC_FRAC 0x1
1987 #define HSADC_SRC_EXT 0x2
1988 static int clk_hsadc_set_rate(struct clk *clk, unsigned long rate)
1993 if(clk->parent == clk->parents[HSADC_SRC_EXT]) {
1994 CLKDATA_DBG("hsadc clk is form ext\n");
1996 } else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_DIV], rate) == rate) {
1997 parent = clk->parents[HSADC_SRC_DIV];
1998 } else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_FRAC], rate) == rate) {
1999 parent = clk->parents[HSADC_SRC_FRAC];
2001 parent = clk->parents[HSADC_SRC_DIV];
2003 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
2004 clk->name, rate, parent->name, clk->parent->name);
2006 ret = clk_set_rate_nolock(parent, rate);
2008 CLKDATA_ERR("%s set rate%lu err\n", clk->name, rate);
2011 if (clk->parent != parent) {
2012 ret = clk_set_parent_nolock(clk, parent);
2014 CLKDATA_ERR("%s can't get rate%lu,reparent err\n", clk->name, rate);
2021 static struct clk clk_hsadc_ext = {
2022 .name = "hsadc_ext",
2025 static struct clk *clk_hsadc_out_parents[3] = {&clk_hsadc_pll_div, &clk_hsadc_frac_div, &clk_hsadc_ext};
2026 static struct clk clk_hsadc_out = {
2027 .name = "hsadc_out",
2028 .parent = &clk_hsadc_pll_div,
2029 .set_rate = clk_hsadc_set_rate,
2030 .clksel_con = CRU_CLKSELS_CON(22),
2031 CRU_SRC_SET(0x3, 4),
2032 CRU_PARENTS_SET(clk_hsadc_out_parents),
2034 static struct clk clk_hsadc_out_inv = {
2035 .name = "hsadc_out_inv",
2036 .parent = &clk_hsadc_out,
2039 static struct clk *clk_hsadc_parents[3] = {&clk_hsadc_out, &clk_hsadc_out_inv};
2040 static struct clk clk_hsadc = {
2042 .parent = &clk_hsadc_out,
2043 .clksel_con = CRU_CLKSELS_CON(22),
2044 CRU_SRC_SET(0x1, 7),
2045 CRU_PARENTS_SET(clk_hsadc_parents),
2048 static struct clk clk_saradc = {
2052 .recalc = clksel_recalc_div,
2053 .set_rate = clksel_set_rate_freediv,
2054 .gate_idx = CLK_GATE_SARADC_SRC,
2055 .clksel_con = CRU_CLKSELS_CON(24),
2056 CRU_DIV_SET(0xff, 8, 256),
2060 GATE_CLK(smc, hclk_periph, SMC_SRC);//smc
2061 static struct clk clkn_smc = {
2067 static struct clk clk_spi0 = {
2069 .parent = &pclk_periph,
2071 .recalc = clksel_recalc_div,
2072 .set_rate = clksel_set_rate_freediv,
2073 .gate_idx = CLK_GATE_SPI0_SRC,
2074 .clksel_con = CRU_CLKSELS_CON(25),
2075 CRU_DIV_SET(0x7f, 0, 128),
2078 static struct clk clk_spi1 = {
2080 .parent = &pclk_periph,
2082 .recalc = clksel_recalc_div,
2083 .set_rate = clksel_set_rate_freediv,
2084 .gate_idx = CLK_GATE_SPI1_SRC,
2085 .clksel_con = CRU_CLKSELS_CON(25),
2086 CRU_DIV_SET(0x7f, 8, 128),
2089 /* sdmmc/sdio/emmc setting */
2090 static struct clk clk_sdmmc = {
2092 .parent = &hclk_periph,
2094 .recalc = clksel_recalc_div,
2095 .set_rate = clksel_set_rate_even,
2096 .gate_idx = CLK_GATE_MMC0_SRC,
2097 .clksel_con = CRU_CLKSELS_CON(11),
2098 CRU_DIV_SET(0x3f, 0, 64),
2101 static struct clk clk_sdio = {
2103 .parent = &hclk_periph,
2105 .recalc = clksel_recalc_div,
2106 .set_rate = clksel_set_rate_even,
2107 .gate_idx = CLK_GATE_SDIO_SRC,
2108 .clksel_con = CRU_CLKSELS_CON(12),
2109 CRU_DIV_SET(0x3f, 0, 64),
2113 static struct clk clk_emmc = {
2115 .parent = &hclk_periph,
2117 .recalc = clksel_recalc_div,
2118 .set_rate = clksel_set_rate_freediv,
2119 .gate_idx = CLK_GATE_EMMC_SRC,
2120 .clksel_con = CRU_CLKSELS_CON(12),
2121 CRU_DIV_SET(0x3f, 8, 64),
2125 static struct clk *clk_uart_src_parents[2] = {&general_pll_clk, &codec_pll_clk};
2126 static struct clk clk_uart_pll = {
2128 .parent = &general_pll_clk,
2129 .clksel_con = CRU_CLKSELS_CON(12),
2130 CRU_SRC_SET(0x1, 15),
2131 CRU_PARENTS_SET(clk_uart_src_parents),
2133 static struct clk clk_uart0_div = {
2134 .name = "uart0_div",
2135 .parent = &clk_uart_pll,
2137 .gate_idx = CLK_GATE_UART0_SRC,
2138 .recalc = clksel_recalc_div,
2139 .set_rate = clksel_set_rate_freediv,
2140 .round_rate = clksel_freediv_round_rate,
2141 .clksel_con = CRU_CLKSELS_CON(13),
2142 CRU_DIV_SET(0x7f, 0, 64),
2144 static struct clk clk_uart1_div = {
2145 .name = "uart1_div",
2146 .parent = &clk_uart_pll,
2148 .gate_idx = CLK_GATE_UART1_SRC,
2149 .recalc = clksel_recalc_div,
2150 .round_rate = clksel_freediv_round_rate,
2151 .set_rate = clksel_set_rate_freediv,
2152 .clksel_con = CRU_CLKSELS_CON(14),
2153 CRU_DIV_SET(0x7f, 0, 64),
2156 static struct clk clk_uart2_div = {
2157 .name = "uart2_div",
2158 .parent = &clk_uart_pll,
2160 .gate_idx = CLK_GATE_UART2_SRC,
2161 .recalc = clksel_recalc_div,
2162 .round_rate = clksel_freediv_round_rate,
2163 .set_rate = clksel_set_rate_freediv,
2164 .clksel_con = CRU_CLKSELS_CON(15),
2165 CRU_DIV_SET(0x7f, 0, 64),
2168 static struct clk clk_uart3_div = {
2169 .name = "uart3_div",
2170 .parent = &clk_uart_pll,
2172 .gate_idx = CLK_GATE_UART3_SRC,
2173 .recalc = clksel_recalc_div,
2174 .round_rate = clksel_freediv_round_rate,
2175 .set_rate = clksel_set_rate_freediv,
2176 .clksel_con = CRU_CLKSELS_CON(16),
2177 CRU_DIV_SET(0x7f, 0, 64),
2179 static int clk_uart_fracdiv_set_rate(struct clk *clk, unsigned long rate)
2181 u32 numerator, denominator;
2182 //clk_uart0_div->clk_uart_pll->gpll/cpll
2183 //clk->parent->parent
2184 if(frac_div_get_seting(rate, clk->parent->parent->rate,
2185 &numerator, &denominator) == 0) {
2186 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
2188 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2190 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
2192 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
2198 static struct clk clk_uart0_frac_div = {
2199 .name = "uart0_frac_div",
2200 .parent = &clk_uart0_div,
2202 .recalc = clksel_recalc_frac,
2203 .set_rate = clk_uart_fracdiv_set_rate,
2204 .gate_idx = CLK_GATE_UART0_FRAC_SRC,
2205 .clksel_con = CRU_CLKSELS_CON(17),
2207 static struct clk clk_uart1_frac_div = {
2208 .name = "uart1_frac_div",
2209 .parent = &clk_uart1_div,
2211 .recalc = clksel_recalc_frac,
2212 .set_rate = clk_uart_fracdiv_set_rate,
2213 .gate_idx = CLK_GATE_UART1_FRAC_SRC,
2214 .clksel_con = CRU_CLKSELS_CON(18),
2216 static struct clk clk_uart2_frac_div = {
2217 .name = "uart2_frac_div",
2219 .parent = &clk_uart2_div,
2220 .recalc = clksel_recalc_frac,
2221 .set_rate = clk_uart_fracdiv_set_rate,
2222 .gate_idx = CLK_GATE_UART2_FRAC_SRC,
2223 .clksel_con = CRU_CLKSELS_CON(19),
2225 static struct clk clk_uart3_frac_div = {
2226 .name = "uart3_frac_div",
2227 .parent = &clk_uart3_div,
2229 .recalc = clksel_recalc_frac,
2230 .set_rate = clk_uart_fracdiv_set_rate,
2231 .gate_idx = CLK_GATE_UART3_FRAC_SRC,
2232 .clksel_con = CRU_CLKSELS_CON(20),
2235 #define UART_SRC_DIV 0
2236 #define UART_SRC_FRAC 1
2237 #define UART_SRC_24M 2
2239 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
2244 if(rate == clk->parents[UART_SRC_24M]->rate) { //24m
2245 parent = clk->parents[UART_SRC_24M];
2246 } else if((long)clk_round_rate_nolock(clk->parents[UART_SRC_DIV], rate) == rate) {
2247 parent = clk->parents[UART_SRC_DIV];
2249 parent = clk->parents[UART_SRC_FRAC];
2252 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
2253 clk->name, rate, parent->name, clk->parent->name);
2255 if(parent != clk->parents[UART_SRC_24M]) {
2256 ret = clk_set_rate_nolock(parent, rate);
2258 CLKDATA_DBG("%s set rate%lu err\n", clk->name, rate);
2263 if (clk->parent != parent) {
2264 ret = clk_set_parent_nolock(clk, parent);
2266 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
2274 static struct clk *clk_uart0_parents[3] = {&clk_uart0_div, &clk_uart0_frac_div, &xin24m};
2275 static struct clk clk_uart0 = {
2277 .set_rate = clk_uart_set_rate,
2278 .clksel_con = CRU_CLKSELS_CON(13),
2279 CRU_SRC_SET(0x3, 8),
2280 CRU_PARENTS_SET(clk_uart0_parents),
2283 static struct clk *clk_uart1_parents[3] = {&clk_uart1_div, &clk_uart1_frac_div, &xin24m};
2284 static struct clk clk_uart1 = {
2286 .set_rate = clk_uart_set_rate,
2287 .clksel_con = CRU_CLKSELS_CON(14),
2288 CRU_SRC_SET(0x3, 8),
2289 CRU_PARENTS_SET(clk_uart1_parents),
2292 static struct clk *clk_uart2_parents[3] = {&clk_uart2_div, &clk_uart2_frac_div, &xin24m};
2293 static struct clk clk_uart2 = {
2295 .set_rate = clk_uart_set_rate,
2296 .clksel_con = CRU_CLKSELS_CON(15),
2297 CRU_SRC_SET(0x3, 8),
2298 CRU_PARENTS_SET(clk_uart2_parents),
2300 static struct clk *clk_uart3_parents[3] = {&clk_uart3_div, &clk_uart3_frac_div, &xin24m};
2301 static struct clk clk_uart3 = {
2303 .set_rate = clk_uart_set_rate,
2304 .clksel_con = CRU_CLKSELS_CON(16),
2305 CRU_SRC_SET(0x3, 8),
2306 CRU_PARENTS_SET(clk_uart3_parents),
2310 GATE_CLK(timer0, xin24m, TIMER0);
2311 GATE_CLK(timer1, xin24m, TIMER1);
2312 GATE_CLK(timer2, xin24m, TIMER2);
2313 GATE_CLK(timer3, xin24m, TIMER3);
2314 GATE_CLK(timer4, xin24m, TIMER4);
2315 GATE_CLK(timer5, xin24m, TIMER5);
2316 GATE_CLK(timer6, xin24m, TIMER6);
2318 /*********************power domain*******************************/
2320 #ifdef RK30_CLK_OFFBOARD_TEST
2321 void pmu_set_power_domain_test(enum pmu_power_domain pd, bool on) {};
2322 #define _pmu_set_power_domain pmu_set_power_domain_test//rk30_pmu_set_power_domain
2324 void pmu_set_power_domain(enum pmu_power_domain pd, bool on);
2325 #define _pmu_set_power_domain pmu_set_power_domain
2328 static int pd_video_mode(struct clk *clk, int on)
2331 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2332 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2333 //gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2334 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2335 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2336 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2337 pmu_set_power_domain(PD_VIDEO, on);
2338 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2339 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2340 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2344 static struct clk pd_video = {
2347 .mode = pd_video_mode,
2348 .gate_idx = PD_VIDEO,
2350 static int pd_display_mode(struct clk *clk, int on)
2353 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2354 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2355 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2356 gate[3] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2357 gate[4] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2358 //gate[5] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2359 gate[6] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2360 gate[7] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2361 gate[8] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2362 gate[9] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2363 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2364 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2365 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2366 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2367 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2368 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2369 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2370 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2371 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2372 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2373 pmu_set_power_domain(PD_VIO, on);
2374 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2375 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2376 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2377 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1) | gate[3], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2378 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0) | gate[4], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2379 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1) | gate[5], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2380 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0) | gate[6], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2381 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1) | gate[7], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2382 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP) | gate[8], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2383 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA) | gate[9], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2387 static struct clk pd_display = {
2390 .mode = pd_display_mode,
2393 static struct clk pd_lcdc0 = {
2394 .parent = &pd_display,
2397 static struct clk pd_lcdc1 = {
2398 .parent = &pd_display,
2401 static struct clk pd_cif0 = {
2402 .parent = &pd_display,
2405 static struct clk pd_rga = {
2406 .parent = &pd_display,
2409 static struct clk pd_ipp = {
2410 .parent = &pd_display,
2413 static struct clk pd_hdmi = {
2414 .parent = &pd_display,
2419 static int pd_gpu_mode(struct clk *clk, int on)
2422 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2423 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2424 pmu_set_power_domain(PD_GPU, on);
2425 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2429 static struct clk pd_gpu = {
2432 .mode = pd_gpu_mode,
2436 static int pm_off_mode(struct clk *clk, int on)
2438 _pmu_set_power_domain(clk->gate_idx, on); //on 1
2441 static struct clk pd_peri = {
2444 .mode = pm_off_mode,
2445 .gate_idx = PD_PERI,
2449 #define PD_CLK(name) \
2457 /************************rk30 fixed div clock****************************************/
2459 /*************************aclk_cpu***********************/
2461 GATE_CLK(dma1, aclk_cpu, ACLK_DMAC1);
2462 GATE_CLK(intmem, aclk_cpu, ACLK_INTMEM);
2463 GATE_CLK(aclk_strc_sys, aclk_cpu, ACLK_STRC_SYS);
2465 /*************************hclk_cpu***********************/
2467 GATE_CLK(rom, hclk_cpu, HCLK_ROM);
2468 GATE_CLK(hclk_i2s0_2ch, hclk_cpu, HCLK_I2S0_2CH);
2469 GATE_CLK(hclk_spdif, hclk_cpu, HCLK_SPDIF);
2470 GATE_CLK(hclk_cpubus, hclk_cpu, HCLK_CPUBUS);
2471 GATE_CLK(hclk_ahb2apb, hclk_cpu, HCLK_AHB2APB);
2472 GATE_CLK(hclk_vio_bus, hclk_cpu, HCLK_VIO_BUS);
2473 GATE_CLK(hclk_lcdc0, hclk_cpu, HCLK_LCDC0);
2474 GATE_CLK(hclk_lcdc1, hclk_cpu, HCLK_LCDC1);
2475 GATE_CLK(hclk_cif0, hclk_cpu, HCLK_CIF0);
2476 GATE_CLK(hclk_ipp, hclk_cpu, HCLK_IPP);
2477 GATE_CLK(hclk_rga, hclk_cpu, HCLK_RGA);
2478 GATE_CLK(hclk_imem0, hclk_cpu, HCLK_IMEM0);
2479 GATE_CLK(hclk_imem1, hclk_cpu, HCLK_IMEM1);
2481 /*************************ahb2apb_cpu(pclk_cpu_h2p)***********************/
2482 GATE_CLK(pclk_uart0, ahb2apb_cpu, PCLK_UART0);
2483 GATE_CLK(pclk_uart1, ahb2apb_cpu, PCLK_UART1);
2484 /*************************pclk_cpu***********************/
2485 GATE_CLK(pwm01, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2486 GATE_CLK(pclk_timer0, pclk_cpu, PCLK_TIMER0);
2487 GATE_CLK(pclk_timer2, pclk_cpu, PCLK_TIMER2);
2488 GATE_CLK(i2c0, pclk_cpu, PCLK_I2C0);
2489 GATE_CLK(i2c1, pclk_cpu, PCLK_I2C1);
2490 GATE_CLK(gpio0, pclk_cpu, PCLK_GPIO0);
2491 GATE_CLK(gpio1, pclk_cpu, PCLK_GPIO1);
2492 GATE_CLK(gpio2, pclk_cpu, PCLK_GPIO2);
2493 GATE_CLK(efuse, pclk_cpu, PCLK_EFUSE);
2494 GATE_CLK(tzpc, pclk_cpu, PCLK_TZPC);
2495 GATE_CLK(pclk_ddrupctl, pclk_cpu, PCLK_DDRUPCTL);
2496 GATE_CLK(pclk_ddrpubl, pclk_cpu, PCLK_PUBL);
2497 GATE_CLK(dbg, pclk_cpu, PCLK_DBG);
2498 GATE_CLK(grf, pclk_cpu, PCLK_GRF);
2499 GATE_CLK(pmu, pclk_cpu, PCLK_PMU);
2501 /*************************aclk_periph***********************/
2503 GATE_CLK(dma2, aclk_periph, ACLK_DMAC2);
2504 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
2505 GATE_CLK(aclk_gps, aclk_periph, ACLK_GPS);
2506 GATE_CLK(aclk_peri_niu, aclk_periph, ACLK_PEI_NIU);
2507 GATE_CLK(aclk_cpu_peri, aclk_periph, ACLK_CPU_PERI);
2508 GATE_CLK(aclk_peri_axi_matrix, aclk_periph, ACLK_PERI_AXI_MATRIX);
2510 /*************************hclk_periph***********************/
2511 GATE_CLK(hclk_peri_axi_matrix, hclk_periph, HCLK_PERI_AXI_MATRIX);
2512 GATE_CLK(hclk_peri_ahb_arbi, hclk_periph, HCLK_PERI_AHB_ARBI);
2513 GATE_CLK(hclk_emem_peri, hclk_periph, HCLK_EMEM_PERI);
2514 GATE_CLK(hclk_mac, hclk_periph, HCLK_EMAC);
2515 GATE_CLK(nandc, hclk_periph, HCLK_NANDC);
2516 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
2517 GATE_CLK(hclk_otg0, clk_hclk_usb_peri, HCLK_OTG0);
2518 GATE_CLK(hclk_otg1, clk_hclk_usb_peri, HCLK_OTG1);
2519 GATE_CLK(hclk_hsic, hclk_periph, HCLK_HSIC);
2520 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
2521 GATE_CLK(hclk_pidfilter, hclk_periph, HCLK_PIDF);
2522 GATE_CLK(hclk_sdmmc, hclk_periph, HCLK_SDMMC0);
2523 GATE_CLK(hclk_sdio, hclk_periph, HCLK_SDIO);
2524 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
2525 /*************************pclk_periph***********************/
2526 GATE_CLK(pclk_peri_axi_matrix, pclk_periph, PCLK_PERI_AXI_MATRIX);
2527 GATE_CLK(pwm23, pclk_periph, PCLK_PWM23);
2528 GATE_CLK(wdt, pclk_periph, PCLK_WDT);
2529 GATE_CLK(pclk_spi0, pclk_periph, PCLK_SPI0);
2530 GATE_CLK(pclk_spi1, pclk_periph, PCLK_SPI1);
2531 GATE_CLK(pclk_uart2, pclk_periph, PCLK_UART2);
2532 GATE_CLK(pclk_uart3, pclk_periph, PCLK_UART3);
2533 GATE_CLK(i2c2, pclk_periph, PCLK_I2C2);
2534 GATE_CLK(i2c3, pclk_periph, PCLK_I2C3);
2535 GATE_CLK(i2c4, pclk_periph, PCLK_I2C4);
2536 GATE_CLK(gpio3, pclk_periph, PCLK_GPIO3);
2537 GATE_CLK(pclk_saradc, pclk_periph, PCLK_SARADC);
2538 /*************************aclk_lcdc0***********************/
2540 GATE_CLK(aclk_vio0, aclk_lcdc0_pre, ACLK_VIO0);
2541 GATE_CLK(aclk_lcdc0, clk_aclk_vio0, ACLK_LCDC0);
2542 GATE_CLK(aclk_cif0, clk_aclk_vio0, ACLK_CIF0);
2543 GATE_CLK(aclk_ipp, clk_aclk_vio0, ACLK_IPP);
2545 /*************************aclk_lcdc0***********************/
2547 GATE_CLK(aclk_vio1, aclk_lcdc1_pre, ACLK_VIO1);
2548 GATE_CLK(aclk_lcdc1, clk_aclk_vio1, ACLK_LCDC1);
2549 GATE_CLK(aclk_rga, clk_aclk_vio1, ACLK_RGA);
2553 #define CLK(dev, con, ck) \
2561 #define CLK1(name) \
2565 .clk = &clk_##name,\
2570 static struct clk_lookup clks[] = {
2571 CLK(NULL, "xin24m", &xin24m),
2572 //CLK(NULL, "xin27m", &xin27m),
2573 CLK(NULL, "xin12m", &clk_12m),
2574 CLK(NULL, "arm_pll", &arm_pll_clk),
2575 CLK(NULL, "ddr_pll", &ddr_pll_clk),
2576 CLK(NULL, "codec_pll", &codec_pll_clk),
2577 CLK(NULL, "general_pll", &general_pll_clk),
2579 CLK(NULL, "arm_gpll", &clk_core_gpll_path),
2580 CLK(NULL, "ddr_gpll", &clk_ddr_gpll_path),
2582 CLK(NULL, "ddr", &clk_ddr),
2583 CLK(NULL, "cpu", &clk_core),
2586 CLK("smp_twd", NULL, &core_periph),
2587 CLK(NULL, "aclk_core", &aclk_core),
2589 CLK(NULL, "logic", &clk_cpu_div),
2590 CLK(NULL, "aclk_cpu", &aclk_cpu),
2591 CLK(NULL, "pclk_cpu", &pclk_cpu),
2592 CLK(NULL, "atclk_cpu", &atclk_cpu),
2593 CLK(NULL, "hclk_cpu", &hclk_cpu),
2594 CLK(NULL, "ahb2apb_cpu", &ahb2apb_cpu),
2596 CLK(NULL, "gpu", &aclk_gpu),
2598 CLK(NULL, "aclk_vepu", &aclk_vepu),
2599 CLK(NULL, "hclk_vepu", &hclk_vepu),
2600 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
2601 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
2603 CLK(NULL, "aclk_lcdc0_pre", &aclk_lcdc0_pre),
2604 CLK(NULL, "aclk_lcdc1_pre", &aclk_lcdc1_pre),
2606 CLK(NULL, "aclk_periph", &aclk_periph),
2607 CLK(NULL, "pclk_periph", &pclk_periph),
2608 CLK(NULL, "hclk_periph", &hclk_periph),
2610 CLK(NULL, "dclk_lcdc0", &dclk_lcdc0),
2611 CLK(NULL, "dclk_lcdc1", &dclk_lcdc1),
2613 CLK(NULL, "cif_out_pll", &cif_out_pll),
2614 CLK(NULL, "cif0_out_div", &cif0_out_div),
2615 CLK(NULL, "cif0_out", &cif0_out),
2617 CLK(NULL, "pclkin_cif0", &pclkin_cif0),
2618 CLK(NULL, "inv_cif0", &inv_cif0),
2619 CLK(NULL, "cif0_in", &cif0_in),
2622 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
2623 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
2624 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
2627 CLK("rk29_i2s.1", "i2s_div", &clk_i2s0_div),
2628 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s0_frac_div),
2629 CLK("rk29_i2s.1", "i2s", &clk_i2s0),
2633 CLK1(spdif_frac_div),
2643 CLK(NULL, "rmii_clkin", &rmii_clkin),
2644 CLK(NULL, "mac_ref_div", &clk_mac_pll_div), // compatible with rk29
2648 CLK1(hsadc_pll_div),
2649 CLK1(hsadc_frac_div),
2652 CLK1(hsadc_out_inv),
2658 CLK(NULL, "smc_inv", &clkn_smc),
2660 CLK("rk29xx_spim.0", "spi", &clk_spi0),
2661 CLK("rk29xx_spim.1", "spi", &clk_spi1),
2663 CLK("rk29_sdmmc.0", "mmc", &clk_sdmmc),
2664 CLK("rk29_sdmmc.1", "mmc", &clk_sdio),
2668 CLK("rk_serial.0", "uart_div", &clk_uart0_div),
2669 CLK("rk_serial.0", "uart_frac_div", &clk_uart0_frac_div),
2670 CLK("rk_serial.0", "uart", &clk_uart0),
2671 CLK("rk_serial.1", "uart_div", &clk_uart1_div),
2672 CLK("rk_serial.1", "uart_frac_div", &clk_uart1_frac_div),
2673 CLK("rk_serial.1", "uart", &clk_uart1),
2674 CLK("rk_serial.2", "uart_div", &clk_uart2_div),
2675 CLK("rk_serial.2", "uart_frac_div", &clk_uart2_frac_div),
2676 CLK("rk_serial.2", "uart", &clk_uart2),
2677 CLK("rk_serial.3", "uart_div", &clk_uart3_div),
2678 CLK("rk_serial.3", "uart_frac_div", &clk_uart3_frac_div),
2679 CLK("rk_serial.3", "uart", &clk_uart3),
2689 /*************************aclk_cpu***********************/
2692 CLK1(aclk_strc_sys),
2694 /*************************hclk_cpu***********************/
2696 CLK("rk29_i2s.0", "hclk_i2s", &clk_hclk_i2s0_2ch),
2698 CLK("rk29_i2s.1", "hclk_i2s", &clk_hclk_i2s0_2ch),
2711 /*************************pclk_cpu***********************/
2715 CLK("rk30_i2c.0", "i2c", &clk_i2c0),
2716 CLK("rk30_i2c.1", "i2c", &clk_i2c1),
2722 CLK("rk_serial.0", "pclk_uart", &clk_pclk_uart0),
2723 CLK("rk_serial.1", "pclk_uart", &clk_pclk_uart1),
2724 CLK1(pclk_ddrupctl),
2730 /*************************aclk_periph***********************/
2734 CLK1(aclk_peri_niu),
2735 CLK1(aclk_cpu_peri),
2736 CLK1(aclk_peri_axi_matrix),
2738 /*************************hclk_periph***********************/
2739 CLK1(hclk_peri_axi_matrix),
2740 CLK1(hclk_peri_ahb_arbi),
2741 CLK1(hclk_emem_peri),
2744 CLK1(hclk_usb_peri),
2749 CLK1(hclk_pidfilter),
2750 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_sdmmc),
2751 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_sdio),
2754 /*************************pclk_periph***********************/
2755 CLK1(pclk_peri_axi_matrix),
2758 CLK("rk29xx_spim.0", "pclk_spi", &clk_pclk_spi0),
2759 CLK("rk29xx_spim.1", "pclk_spi", &clk_pclk_spi1),
2760 CLK("rk_serial.2", "pclk_uart", &clk_pclk_uart2),
2761 CLK("rk_serial.3", "pclk_uart", &clk_pclk_uart3),
2762 CLK("rk30_i2c.2", "i2c", &clk_i2c2),
2763 CLK("rk30_i2c.3", "i2c", &clk_i2c3),
2764 CLK("rk30_i2c.4", "i2c", &clk_i2c4),
2768 /*************************aclk_lcdc0***********************/
2770 CLK(NULL, "aclk_lcdc0", &clk_aclk_lcdc0),
2774 /*************************aclk_lcdc1***********************/
2776 CLK(NULL, "aclk_lcdc1", &clk_aclk_lcdc1),
2778 /************************power domain**********************/
2792 static void __init rk30_init_enable_clocks(void)
2795 //clk_enable_nolock(&xin24m);
2796 //clk_enable_nolock(&clk_12m);
2797 //clk_enable_nolock(&arm_pll_clk);
2798 //clk_enable_nolock(&ddr_pll_clk);
2799 //clk_enable_nolock(&codec_pll_clk);
2800 //clk_enable_nolock(&general_pll_clk);
2802 clk_enable_nolock(&clk_ddr);
2803 //clk_enable_nolock(&clk_core);
2804 clk_enable_nolock(&clk_cpu_div);
2805 clk_enable_nolock(&clk_core_gpll_path);
2806 clk_enable_nolock(&clk_l2c);
2807 clk_enable_nolock(&clk_core_dbg);
2808 clk_enable_nolock(&core_periph);
2809 clk_enable_nolock(&aclk_core);
2810 //clk_enable_nolock(&aclk_cpu);
2811 //clk_enable_nolock(&pclk_cpu);
2812 clk_enable_nolock(&atclk_cpu);
2813 //clk_enable_nolock(&hclk_cpu);
2814 clk_enable_nolock(&ahb2apb_cpu);
2816 clk_enable_nolock(&clk_gpu);
2817 clk_enable_nolock(&aclk_gpu);
2818 clk_enable_nolock(&aclk_gpu_slv);
2819 clk_enable_nolock(&aclk_gpu_mst);
2821 clk_enable_nolock(&aclk_vepu);
2822 clk_enable_nolock(&hclk_vepu);
2823 clk_enable_nolock(&aclk_vdpu);
2824 clk_enable_nolock(&hclk_vdpu);
2826 clk_enable_nolock(&aclk_lcdc0_pre);
2827 clk_enable_nolock(&aclk_lcdc1_pre);
2829 clk_enable_nolock(&aclk_periph);
2830 clk_enable_nolock(&pclk_periph);
2831 clk_enable_nolock(&hclk_periph);
2834 clk_enable_nolock(&dclk_lcdc0);
2835 clk_enable_nolock(&dclk_lcdc1);
2837 clk_enable_nolock(&cif_out_pll);
2838 clk_enable_nolock(&cif0_out_div);
2840 clk_enable_nolock(&cif0_out);
2841 clk_enable_nolock(&pclkin_cif0);
2842 clk_enable_nolock(&inv_cif0);
2843 clk_enable_nolock(&cif0_in);
2845 clk_enable_nolock(&clk_i2s_pll);
2846 clk_enable_nolock(&clk_i2s0_div);
2847 clk_enable_nolock(&clk_i2s0_frac_div);
2848 clk_enable_nolock(&clk_i2s0);
2851 clk_enable_nolock(&clk_i2s0_div);
2852 clk_enable_nolock(&clk_i2s0_frac_div);
2853 clk_enable_nolock(&clk_i2s0);
2855 clk_enable_nolock(&clk_spdif_div);
2856 clk_enable_nolock(&clk_spdif_frac_div);
2857 clk_enable_nolock(&clk_spdif);
2860 clk_enable_nolock(&clk_otgphy0);
2861 clk_enable_nolock(&clk_otgphy1);
2862 clk_enable_nolock(&clk_otgphy0_480m);
2863 clk_enable_nolock(&clk_otgphy1_480m);
2864 clk_enable_nolock(&clk_hsicphy_480m);
2865 clk_enable_nolock(&clk_hsicphy_12m);
2869 clk_enable_nolock(&rmii_clkin);
2870 clk_enable_nolock(&clk_mac_pll_div); // compatible with rk29
2871 clk_enable_nolock(&clk_mac_ref);
2872 clk_enable_nolock(&clk_mii_tx);
2876 clk_enable_nolock(&clk_hsadc_pll_div);
2877 clk_enable_nolock(&clk_hsadc_frac_div);
2878 clk_enable_nolock(&clk_hsadc_ext);
2879 clk_enable_nolock(&clk_hsadc_out);
2880 clk_enable_nolock(&clk_hsadc_out_inv);
2881 clk_enable_nolock(&clk_hsadc);
2883 clk_enable_nolock(&clk_saradc);
2886 clk_enable_nolock(&clk_smc);
2887 clk_enable_nolock(&clkn_smc);
2890 clk_enable_nolock(&clk_spi0);
2891 clk_enable_nolock(&clk_spi1);
2894 clk_enable_nolock(&clk_sdmmc);
2895 clk_enable_nolock(&clk_sdio);
2896 clk_enable_nolock(&clk_emmc);
2899 clk_enable_nolock(&clk_uart_pll);
2900 clk_enable_nolock(&clk_uart0_div);
2901 clk_enable_nolock(&clk_uart0_frac_div);
2902 clk_enable_nolock(&clk_uart0);
2903 clk_enable_nolock(&clk_uart1_div);
2904 clk_enable_nolock(&clk_uart1_frac_div);
2905 clk_enable_nolock(&clk_uart1);
2906 clk_enable_nolock(&clk_uart2_div);
2907 clk_enable_nolock(&clk_uart2_frac_div);
2908 clk_enable_nolock(&clk_uart2);
2909 clk_enable_nolock(&clk_uart3_div);
2910 clk_enable_nolock(&clk_uart3_frac_div);
2911 clk_enable_nolock(&clk_uart3);
2913 #if CONFIG_RK_DEBUG_UART == 0
2914 clk_enable_nolock(&clk_uart0);
2915 clk_enable_nolock(&clk_pclk_uart0);
2916 #elif CONFIG_RK_DEBUG_UART == 1
2917 clk_enable_nolock(&clk_uart1);
2918 clk_enable_nolock(&clk_pclk_uart1);
2920 #elif CONFIG_RK_DEBUG_UART == 2
2921 clk_enable_nolock(&clk_uart2);
2922 clk_enable_nolock(&clk_pclk_uart2);
2924 #elif CONFIG_RK_DEBUG_UART == 3
2925 clk_enable_nolock(&clk_uart3);
2926 clk_enable_nolock(&clk_pclk_uart3);
2930 clk_enable_nolock(&clk_timer0);
2931 clk_enable_nolock(&clk_timer1);
2932 clk_enable_nolock(&clk_timer2);
2935 /*************************aclk_cpu***********************/
2936 clk_enable_nolock(&clk_dma1);
2937 clk_enable_nolock(&clk_intmem);
2938 clk_enable_nolock(&clk_aclk_strc_sys);
2940 /*************************hclk_cpu***********************/
2941 clk_enable_nolock(&clk_rom);
2943 clk_enable_nolock(&clk_hclk_i2s0_2ch);
2945 clk_enable_nolock(&clk_hclk_i2s0_2ch);
2946 clk_enable_nolock(&clk_hclk_spdif);
2948 clk_enable_nolock(&clk_hclk_cpubus);
2949 clk_enable_nolock(&clk_hclk_ahb2apb);
2950 clk_enable_nolock(&clk_hclk_vio_bus);
2952 clk_enable_nolock(&clk_hclk_lcdc0);
2953 clk_enable_nolock(&clk_hclk_lcdc1);
2954 clk_enable_nolock(&clk_hclk_cif0);
2955 clk_enable_nolock(&clk_hclk_ipp);
2956 clk_enable_nolock(&clk_hclk_rga);
2958 clk_enable_nolock(&clk_hclk_imem0);
2959 clk_enable_nolock(&clk_hclk_imem1);
2961 /*************************pclk_cpu***********************/
2963 clk_enable_nolock(&clk_pwm01);
2964 clk_enable_nolock(&clk_pclk_timer0);
2965 clk_enable_nolock(&clk_pclk_timer1);
2966 clk_enable_nolock(&clk_pclk_timer2);
2967 clk_enable_nolock(&clk_i2c0);
2968 clk_enable_nolock(&clk_i2c1);
2969 clk_enable_nolock(&clk_gpio0);
2970 clk_enable_nolock(&clk_gpio1);
2971 clk_enable_nolock(&clk_gpio2);
2972 clk_enable_nolock(&clk_efuse);
2974 clk_enable_nolock(&clk_tzpc);
2975 //clk_enable_nolock(&clk_pclk_uart0);
2976 //clk_enable_nolock(&clk_pclk_uart1);
2977 clk_enable_nolock(&clk_pclk_ddrupctl);
2978 clk_enable_nolock(&clk_pclk_ddrpubl);
2979 clk_enable_nolock(&clk_dbg);
2980 clk_enable_nolock(&clk_grf);
2981 clk_enable_nolock(&clk_pmu);
2983 /*************************aclk_periph***********************/
2984 clk_enable_nolock(&clk_dma2);
2985 clk_enable_nolock(&clk_aclk_smc);
2986 clk_enable_nolock(&clk_aclk_peri_niu);
2987 clk_enable_nolock(&clk_aclk_cpu_peri);
2988 clk_enable_nolock(&clk_aclk_peri_axi_matrix);
2990 /*************************hclk_periph***********************/
2991 clk_enable_nolock(&clk_hclk_peri_axi_matrix);
2992 clk_enable_nolock(&clk_hclk_peri_ahb_arbi);
2993 clk_enable_nolock(&clk_hclk_emem_peri);
2994 //clk_enable_nolock(&clk_hclk_mac);
2995 clk_enable_nolock(&clk_nandc);
2996 clk_enable_nolock(&clk_hclk_usb_peri);
2998 clk_enable_nolock(&clk_hclk_otg0);
2999 clk_enable_nolock(&clk_hclk_otg1);
3000 clk_enable_nolock(&clk_hclk_hsic);
3001 clk_enable_nolock(&clk_hclk_gps);
3002 clk_enable_nolock(&clk_hclk_hsadc);
3003 clk_enable_nolock(&clk_hclk_pidfilter);
3004 clk_enable_nolock(&clk_hclk_sdmmc);
3005 clk_enable_nolock(&clk_hclk_sdio);
3006 clk_enable_nolock(&clk_hclk_emmc);
3009 /*************************pclk_periph***********************/
3010 clk_enable_nolock(&clk_pclk_peri_axi_matrix);
3012 clk_enable_nolock(&clk_pwm23);
3013 clk_enable_nolock(&clk_wdt);
3014 clk_enable_nolock(&clk_pclk_spi0);
3015 clk_enable_nolock(&clk_pclk_spi1);
3016 clk_enable_nolock(&clk_pclk_uart2);
3017 clk_enable_nolock(&clk_pclk_uart3);
3020 clk_enable_nolock(&clk_i2c2);
3021 clk_enable_nolock(&clk_i2c3);
3022 clk_enable_nolock(&clk_i2c4);
3023 clk_enable_nolock(&clk_gpio3);
3024 clk_enable_nolock(&clk_pclk_saradc);
3026 /*************************aclk_lcdc0***********************/
3028 //clk_enable_nolock(&clk_aclk_vio0);
3029 //clk_enable_nolock(&clk_aclk_lcdc0);
3030 //clk_enable_nolock(&clk_aclk_cif0);
3031 //clk_enable_nolock(&clk_aclk_ipp);
3033 /*************************aclk_lcdc1***********************/
3035 //clk_enable_nolock(&clk_aclk_vio1);
3036 //clk_enable_nolock(&clk_aclk_lcdc1);
3037 //clk_enable_nolock(&clk_aclk_rga);
3039 /************************power domain**********************/
3042 static void periph_clk_set_init(void)
3044 unsigned long aclk_p, hclk_p, pclk_p;
3045 unsigned long ppll_rate = general_pll_clk.rate;
3049 switch (ppll_rate) {
3051 aclk_p = 148500 * KHZ;
3052 hclk_p = aclk_p >> 1;
3053 pclk_p = aclk_p >> 2;
3056 aclk_p = aclk_p >> 3; // 0
3057 hclk_p = aclk_p >> 1;
3058 pclk_p = aclk_p >> 2;
3061 aclk_p = ppll_rate >> 1;
3062 hclk_p = aclk_p >> 0;
3063 pclk_p = aclk_p >> 1;
3067 aclk_p = ppll_rate >> 1;
3068 hclk_p = aclk_p >> 0;
3069 pclk_p = aclk_p >> 1;
3072 aclk_p = ppll_rate >> 2;
3073 hclk_p = aclk_p >> 0;
3074 pclk_p = aclk_p >> 1;
3082 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3083 clk_set_rate_nolock(&aclk_periph, aclk_p);
3084 clk_set_rate_nolock(&hclk_periph, hclk_p);
3085 clk_set_rate_nolock(&pclk_periph, pclk_p);
3088 static void cpu_axi_init(void)
3090 unsigned long cpu_div_rate, aclk_cpu_rate, hclk_cpu_rate, pclk_cpu_rate, ahb2apb_cpu_rate;
3091 unsigned long gpll_rate = general_pll_clk.rate;
3093 switch (gpll_rate) {
3095 cpu_div_rate = gpll_rate;
3096 aclk_cpu_rate = cpu_div_rate >> 0;
3097 hclk_cpu_rate = aclk_cpu_rate >> 1;
3098 pclk_cpu_rate = aclk_cpu_rate >> 2;
3102 cpu_div_rate = gpll_rate >> 1;
3103 aclk_cpu_rate = cpu_div_rate >> 0;
3104 hclk_cpu_rate = aclk_cpu_rate >> 1;
3105 pclk_cpu_rate = aclk_cpu_rate >> 2;
3108 aclk_cpu_rate = 150 * MHZ;
3109 hclk_cpu_rate = 150 * MHZ;
3110 pclk_cpu_rate = 75 * MHZ;
3113 ahb2apb_cpu_rate = pclk_cpu_rate;
3115 clk_set_parent_nolock(&clk_cpu_div, &general_pll_clk);
3116 clk_set_rate_nolock(&clk_cpu_div, cpu_div_rate);
3117 clk_set_rate_nolock(&aclk_cpu, aclk_cpu_rate);
3118 clk_set_rate_nolock(&hclk_cpu, hclk_cpu_rate);
3119 clk_set_rate_nolock(&pclk_cpu, pclk_cpu_rate);
3120 clk_set_rate_nolock(&ahb2apb_cpu, ahb2apb_cpu_rate);
3123 void rk30_clock_common_i2s_init(void)
3125 unsigned long i2s_rate;
3127 if(rk30_clock_flags & CLK_FLG_MAX_I2S_49152KHZ) {
3128 i2s_rate = 49152000;
3129 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_24576KHZ) {
3130 i2s_rate = 24576000;
3131 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_22579_2KHZ) {
3132 i2s_rate = 22579000;
3133 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_12288KHZ) {
3134 i2s_rate = 12288000;
3136 i2s_rate = 49152000;
3139 if(((i2s_rate * 20) <= general_pll_clk.rate) || !(general_pll_clk.rate % i2s_rate)) {
3140 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3141 } else if(((i2s_rate * 20) <= codec_pll_clk.rate) || !(codec_pll_clk.rate % i2s_rate)) {
3142 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3144 if(general_pll_clk.rate > codec_pll_clk.rate)
3145 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3147 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3151 static void __init rk30_clock_common_init(unsigned long gpll_rate, unsigned long cpll_rate)
3155 clk_set_rate_nolock(&general_pll_clk, gpll_rate);
3157 clk_set_rate_nolock(&codec_pll_clk, cpll_rate);
3160 clk_set_rate_nolock(&clk_core, 816 * MHZ);
3162 periph_clk_set_init();
3165 rk30_clock_common_i2s_init();
3168 clk_set_rate_nolock(&clk_spi0, clk_spi0.parent->rate);
3169 clk_set_rate_nolock(&clk_spi1, clk_spi1.parent->rate);
3172 if(rk30_clock_flags & CLK_FLG_UART_1_3M)
3173 clk_set_parent_nolock(&clk_uart_pll, &codec_pll_clk);
3175 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3177 if(!(gpll_rate % (50 * MHZ)))
3178 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3179 else if(!(ddr_pll_clk.rate % (50 * MHZ)))
3180 clk_set_parent_nolock(&clk_mac_pll_div, &ddr_pll_clk);
3182 CLKDATA_ERR("mac can't get 50mhz\n");
3186 //clk_set_parent_nolock(&clk_hsadc_pll_div, &general_pll_clk);
3188 //lcdc0 lcd auto sel pll
3189 clk_set_parent_nolock(&dclk_lcdc0, &general_pll_clk);
3190 clk_set_parent_nolock(&dclk_lcdc1, &general_pll_clk);
3193 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3196 clk_set_parent_nolock(&aclk_lcdc0_pre, &general_pll_clk);
3197 clk_set_parent_nolock(&aclk_lcdc1_pre, &general_pll_clk);
3198 clk_set_rate_nolock(&aclk_lcdc0_pre, 300 * MHZ);
3199 clk_set_rate_nolock(&aclk_lcdc1_pre, 300 * MHZ);
3202 //clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
3203 //clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
3205 clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3206 clk_set_rate_nolock(&aclk_vdpu, 300 * MHZ);
3208 clk_set_parent_nolock(&aclk_gpu, &codec_pll_clk);
3209 clk_set_rate_nolock(&aclk_gpu, 200 * MHZ);
3211 clk_set_rate_nolock(&clk_uart0, 49500000);
3212 clk_set_rate_nolock(&clk_sdmmc, 24750000);
3213 clk_set_rate_nolock(&clk_sdio, 24750000);
3217 static struct clk def_ops_clk = {
3218 .get_parent = clksel_get_parent,
3219 .set_parent = clksel_set_parent,
3222 #ifdef CONFIG_PROC_FS
3223 struct clk_dump_ops dump_ops;
3225 void rk_dump_clock_info(void);
3227 void __init _rk30_clock_data_init(unsigned long gpll, unsigned long cpll, int flags)
3229 struct clk_lookup *lk;
3231 clk_register_dump_ops(&dump_ops);
3232 clk_register_default_ops_clk(&def_ops_clk);
3233 rk30_clock_flags = flags;
3234 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
3235 #ifdef RK30_CLK_OFFBOARD_TEST
3236 rk30_clkdev_add(lk);
3240 clk_register(lk->clk);
3242 clk_recalculate_root_clocks_nolock();
3244 loops_per_jiffy = CLK_LOOPS_RECALC(arm_pll_clk.rate);
3247 * Only enable those clocks we will need, let the drivers
3248 * enable other clocks as necessary
3250 rk30_init_enable_clocks();
3252 // print loader config
3253 CLKDATA_DBG("%s clks register dbg start\n", __func__);
3254 rk_dump_clock_info();
3255 rk30_clk_dump_regs();
3257 CLKDATA_DBG("%s clks register dbg end\n", __func__);
3260 * Disable any unused clocks left on by the bootloader
3262 //clk_disable_unused();
3263 rk30_clock_common_init(gpll, cpll);
3264 preset_lpj = loops_per_jiffy;
3267 //regfile_writel(0xc0004000,0x10c);
3268 //cru_writel(0x07000000,CRU_MISC_CON);
3271 extern int rk3188_dvfs_init(void);
3273 void __init rk30_clock_data_init(unsigned long gpll, unsigned long cpll, u32 flags)
3275 printk("clock: gpll %lu cpll %lu flags 0x%x con2 0x%x/0x%x\n", gpll, cpll, flags, cru_readl(PLL_CONS(DPLL_ID, 2)), cru_readl(PLL_CONS(CPLL_ID, 2)));
3276 _rk30_clock_data_init(gpll, cpll, flags);
3281 * You can override arm_clk rate with armclk= cmdline option.
3283 static int __init armclk_setup(char *str)
3285 get_option(&str, &armclk);
3291 //clk_set_rate_nolock(&arm_pll_clk, armclk);
3294 #ifndef RK30_CLK_OFFBOARD_TEST
3295 early_param("armclk", armclk_setup);
3299 static void rk_dump_clock(struct clk *clk, int deep, const struct list_head *root_clocks)
3303 unsigned long rate = clk->rate;
3304 //CLKDATA_DBG("dump_clock %s\n",clk->name);
3305 for (i = 0; i < deep; i++)
3308 printk("%-11s ", clk->name);
3309 #ifndef RK30_CLK_OFFBOARD_TEST
3310 if (clk->flags & IS_PD) {
3311 printk("%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3314 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3315 int idx = clk->gate_idx;
3317 v = cru_readl(CLK_GATE_CLKID_CONS(idx)) & ((0x1) << (idx % 16));
3318 printk("%s ", v ? "off" : "on ");
3323 u32 pll_id = clk->pll->id;
3324 pll_mode = cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3325 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3327 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3329 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3332 if(cru_readl(PLL_CONS(pll_id, 3)) & PLL_BYPASS)
3334 } else if(clk == &clk_ddr) {
3335 rate = clk->recalc(clk);
3340 printk("%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3342 printk("%ld MHz", rate / MHZ);
3343 } else if (rate >= KHZ) {
3345 printk("%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3347 printk("%ld KHz", rate / KHZ);
3349 printk("%ld Hz", rate);
3352 printk(" usecount = %d", clk->usecount);
3355 printk(" parent = %s", clk->parent->name);
3359 list_for_each_entry(ck, root_clocks, node) {
3360 if (ck->parent == clk)
3361 rk_dump_clock(ck, deep + 1, root_clocks);
3366 struct list_head *get_rk_clocks_head(void);
3368 void rk_dump_clock_info(void)
3371 list_for_each_entry(clk, get_rk_clocks_head(), node) {
3373 rk_dump_clock(clk, 0,get_rk_clocks_head());
3378 #ifdef CONFIG_PROC_FS
3380 static void dump_clock(struct seq_file *s, struct clk *clk, int deep, const struct list_head *root_clocks)
3384 unsigned long rate = clk->rate;
3385 //CLKDATA_DBG("dump_clock %s\n",clk->name);
3386 for (i = 0; i < deep; i++)
3389 seq_printf(s, "%-11s ", clk->name);
3390 #ifndef RK30_CLK_OFFBOARD_TEST
3391 if (clk->flags & IS_PD) {
3392 seq_printf(s, "%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3395 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3396 int idx = clk->gate_idx;
3398 v = cru_readl(CLK_GATE_CLKID_CONS(idx)) & ((0x1) << (idx % 16));
3399 seq_printf(s, "%s ", v ? "off" : "on ");
3404 u32 pll_id = clk->pll->id;
3405 pll_mode = cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3406 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3407 seq_printf(s, "slow ");
3408 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3409 seq_printf(s, "normal ");
3410 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3411 seq_printf(s, "deep ");
3413 if(cru_readl(PLL_CONS(pll_id, 3)) & PLL_BYPASS)
3414 seq_printf(s, "bypass ");
3415 } else if(clk == &clk_ddr) {
3416 rate = clk->recalc(clk);
3421 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3423 seq_printf(s, "%ld MHz", rate / MHZ);
3424 } else if (rate >= KHZ) {
3426 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3428 seq_printf(s, "%ld KHz", rate / KHZ);
3430 seq_printf(s, "%ld Hz", rate);
3433 seq_printf(s, " usecount = %d", clk->usecount);
3436 seq_printf(s, " parent = %s", clk->parent->name);
3438 seq_printf(s, "\n");
3440 list_for_each_entry(ck, root_clocks, node) {
3441 if (ck->parent == clk)
3442 dump_clock(s, ck, deep + 1, root_clocks);
3446 static void dump_regs(struct seq_file *s)
3449 seq_printf(s, "\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3450 seq_printf(s, "\nPLLRegisters:\n");
3451 for(i = 0; i < END_PLL_ID; i++) {
3452 seq_printf(s, "pll%d :cons:%x,%x,%x,%x\n", i,
3453 cru_readl(PLL_CONS(i, 0)),
3454 cru_readl(PLL_CONS(i, 1)),
3455 cru_readl(PLL_CONS(i, 2)),
3456 cru_readl(PLL_CONS(i, 3))
3459 seq_printf(s, "MODE :%x\n", cru_readl(CRU_MODE_CON));
3461 for(i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
3462 seq_printf(s, "CLKSEL%d :%x\n", i, cru_readl(CRU_CLKSELS_CON(i)));
3464 for(i = 0; i < CRU_CLKGATES_CON_CNT; i++) {
3465 seq_printf(s, "CLKGATE%d :%x\n", i, cru_readl(CRU_CLKGATES_CON(i)));
3467 seq_printf(s, "GLB_SRST_FST:%x\n", cru_readl(CRU_GLB_SRST_FST));
3468 seq_printf(s, "GLB_SRST_SND:%x\n", cru_readl(CRU_GLB_SRST_SND));
3470 for(i = 0; i < CRU_SOFTRSTS_CON_CNT; i++) {
3471 seq_printf(s, "CLKGATE%d :%x\n", i, cru_readl(CRU_SOFTRSTS_CON(i)));
3473 seq_printf(s, "CRU MISC :%x\n", cru_readl(CRU_MISC_CON));
3474 seq_printf(s, "GLB_CNT_TH :%x\n", cru_readl(CRU_GLB_CNT_TH));
3478 void rk30_clk_dump_regs(void)
3481 printk("\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3482 printk("\nPLLRegisters:\n");
3483 for(i = 0; i < END_PLL_ID; i++) {
3484 printk("pll%d :cons:%x,%x,%x,%x\n", i,
3485 cru_readl(PLL_CONS(i, 0)),
3486 cru_readl(PLL_CONS(i, 1)),
3487 cru_readl(PLL_CONS(i, 2)),
3488 cru_readl(PLL_CONS(i, 3))
3491 printk("MODE :%x\n", cru_readl(CRU_MODE_CON));
3493 for(i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
3494 printk("CLKSEL%d :%x\n", i, cru_readl(CRU_CLKSELS_CON(i)));
3496 for(i = 0; i < CRU_CLKGATES_CON_CNT; i++) {
3497 printk("CLKGATE%d :%x\n", i, cru_readl(CRU_CLKGATES_CON(i)));
3499 printk("GLB_SRST_FST:%x\n", cru_readl(CRU_GLB_SRST_FST));
3500 printk("GLB_SRST_SND:%x\n", cru_readl(CRU_GLB_SRST_SND));
3502 for(i = 0; i < CRU_SOFTRSTS_CON_CNT; i++) {
3503 printk("SOFTRST%d :%x\n", i, cru_readl(CRU_SOFTRSTS_CON(i)));
3505 printk("CRU MISC :%x\n", cru_readl(CRU_MISC_CON));
3506 printk("GLB_CNT_TH :%x\n", cru_readl(CRU_GLB_CNT_TH));
3511 #ifdef CONFIG_PROC_FS
3512 static void dump_clock(struct seq_file *s, struct clk *clk, int deep, const struct list_head *root_clocks);
3513 struct clk_dump_ops dump_ops = {
3514 .dump_clk = dump_clock,
3515 .dump_regs = dump_regs,
3520 #endif /* CONFIG_PROC_FS */
3525 #ifdef RK30_CLK_OFFBOARD_TEST
3526 struct clk *test_get_parent(struct clk *clk) {
3532 struct clk *i2s_clk = &clk_i2s0;
3534 clk_enable_nolock(i2s_clk);
3536 clk_set_rate_nolock(i2s_clk, 12288000);
3537 printk("int %s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3538 clk_set_rate_nolock(i2s_clk, 297 * MHZ / 2);
3539 printk("int%s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3540 clk_set_rate_nolock(i2s_clk, 12 * MHZ);
3541 printk("int%s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3545 void uart_test(void)
3547 struct clk *uart_clk = &clk_uart0;
3549 clk_enable_nolock(uart_clk);
3551 clk_set_rate_nolock(uart_clk, 12288000);
3552 printk("int %s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3553 clk_set_rate_nolock(uart_clk, 297 * MHZ / 2);
3554 printk("int%s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3555 clk_set_rate_nolock(uart_clk, 12 * MHZ);
3556 printk("int%s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3559 void hsadc_test(void)
3561 struct clk *hsadc_clk = &clk_hsadc;
3563 printk("******************hsadc_test**********************\n");
3564 clk_enable_nolock(hsadc_clk);
3566 clk_set_rate_nolock(hsadc_clk, 12288000);
3567 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3570 clk_set_rate_nolock(hsadc_clk, 297 * MHZ / 2);
3571 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3573 clk_set_rate_nolock(hsadc_clk, 300 * MHZ / 2);
3575 clk_set_rate_nolock(hsadc_clk, 296 * MHZ / 2);
3577 printk("******************hsadc out clock**********************\n");
3579 clk_set_parent_nolock(hsadc_clk, &clk_hsadc_ext);
3580 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3581 clk_set_rate_nolock(hsadc_clk, 297 * MHZ / 2);
3582 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3588 static void __init rk30_clock_test_init(unsigned long ppll_rate)
3591 printk("*********arm_pll_clk***********\n");
3592 clk_set_rate_nolock(&arm_pll_clk, 816 * MHZ);
3594 printk("*********set clk_core parent***********\n");
3595 clk_set_parent_nolock(&clk_core, &arm_pll_clk);
3596 clk_set_rate_nolock(&clk_core, 504 * MHZ);
3599 printk("*********general_pll_clk***********\n");
3600 clk_set_rate_nolock(&general_pll_clk, ppll_rate);
3603 printk("*********codec_pll_clk***********\n");
3604 clk_set_rate_nolock(&codec_pll_clk, 600 * MHZ);
3607 printk("*********periph_clk_set_init***********\n");
3608 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3609 periph_clk_set_init();
3612 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3614 printk("*********clk i2s***********\n");
3615 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3616 printk("common %s parent is %s\n", clk_i2s_pll.name, test_get_parent(&clk_i2s_pll)->name);
3620 clk_enable_nolock(&clk_spi0);
3621 clk_set_rate_nolock(&clk_spi0, 30 * MHZ);
3622 printk("common %s parent is %s\n", clk_spi0.name, test_get_parent(&clk_spi0)->name);
3624 clk_enable_nolock(&clk_saradc);
3625 clk_set_rate_nolock(&clk_saradc, 6 * MHZ);
3626 printk("common %s parent is %s\n", clk_saradc.name, test_get_parent(&clk_saradc)->name);
3628 clk_enable_nolock(&clk_sdio);
3629 clk_set_rate_nolock(&clk_sdio, 50 * MHZ);
3630 printk("common %s parent is %s\n", clk_sdio.name, test_get_parent(&clk_sdio)->name);
3632 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3635 printk("*********mac***********\n");
3637 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3638 printk("common %s parent is %s\n", clk_mac_pll_div.name, test_get_parent(&clk_mac_pll_div)->name);
3640 //clk_set_parent_nolock(&clk_mac_ref, &clk_mac_pll_div);
3641 clk_set_rate_nolock(&clk_mac_ref, 50 * MHZ);
3642 printk("common %s parent is %s\n", clk_mac_ref.name, test_get_parent(&clk_mac_ref)->name);
3644 printk("*********mac mii set***********\n");
3645 clk_set_parent_nolock(&clk_mac_ref, &rmii_clkin);
3646 clk_set_rate_nolock(&clk_mac_ref, 20 * MHZ);
3647 printk("common %s parent is %s\n", clk_mac_ref.name, test_get_parent(&clk_mac_ref)->name);
3649 printk("*********hsadc 1***********\n");
3653 clk_enable_nolock(&dclk_lcdc0);
3655 clk_set_rate_nolock(&dclk_lcdc0, 60 * MHZ);
3656 clk_set_rate_nolock(&dclk_lcdc0, 27 * MHZ);
3659 clk_enable_nolock(&cif0_out);
3661 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3662 printk("common %s parent is %s\n", cif_out_pll.name, test_get_parent(&cif_out_pll)->name);
3664 clk_set_rate_nolock(&cif0_out, 60 * MHZ);
3665 printk("common %s parent is %s\n", cif0_out.name, test_get_parent(&cif0_out)->name);
3667 clk_set_rate_nolock(&cif0_out, 24 * MHZ);
3668 printk("common %s parent is %s\n", cif0_out.name, test_get_parent(&cif0_out)->name);
3670 clk_enable_nolock(&cif0_in);
3671 clk_set_rate_nolock(&cif0_in, 24 * MHZ);
3673 clk_enable_nolock(&aclk_lcdc0);
3674 clk_set_rate_nolock(&aclk_lcdc0, 150 * MHZ);
3675 printk("common %s parent is %s\n", aclk_lcdc0.name, test_get_parent(&aclk_lcdc0)->name);
3677 clk_enable_nolock(&aclk_vepu);
3678 clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3679 printk("common %s parent is %s\n", aclk_vepu.name, test_get_parent(&aclk_vepu)->name);
3681 clk_set_rate_nolock(&hclk_vepu, 300 * MHZ);
3682 printk("common %s parent is %s\n", hclk_vepu.name, test_get_parent(&hclk_vepu)->name);
3684 printk("test end\n");
3687 clk_set_rate_nolock(&arm_pll_clk, armclk);
3688 clk_set_rate_nolock(&clk_core, armclk);//pll:core =1:1
3691 //clk_set_rate_nolock(&codec_pll_clk, ppll_rate*2);
3693 //clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3694 //clk_set_rate_nolock(&clk_gpu, 300 * MHZ);
3702 static LIST_HEAD(rk30_clocks);
3703 static DEFINE_MUTEX(rk30_clocks_mutex);
3705 static inline int __rk30clk_get(struct clk *clk)
3709 void rk30_clkdev_add(struct clk_lookup *cl)
3711 mutex_lock(&rk30_clocks_mutex);
3712 list_add_tail(&cl->node, &rk30_clocks);
3713 mutex_unlock(&rk30_clocks_mutex);
3715 static struct clk_lookup *rk30_clk_find(const char *dev_id, const char *con_id) {
3716 struct clk_lookup *p, *cl = NULL;
3717 int match, best = 0;
3719 list_for_each_entry(p, &rk30_clocks, node) {
3722 if (!dev_id || strcmp(p->dev_id, dev_id))
3727 if (!con_id || strcmp(p->con_id, con_id))
3743 struct clk *rk30_clk_get_sys(const char *dev_id, const char *con_id) {
3744 struct clk_lookup *cl;
3746 mutex_lock(&rk30_clocks_mutex);
3747 cl = rk30_clk_find(dev_id, con_id);
3748 if (cl && !__rk30clk_get(cl->clk))
3750 mutex_unlock(&rk30_clocks_mutex);
3752 return cl ? cl->clk : ERR_PTR(-ENOENT);
3754 //EXPORT_SYMBOL(rk30_clk_get_sys);
3756 struct clk *rk30_clk_get(struct device *dev, const char *con_id) {
3757 const char *dev_id = dev ? dev_name(dev) : NULL;
3758 return rk30_clk_get_sys(dev_id, con_id);
3760 //EXPORT_SYMBOL(rk30_clk_get);
3763 int rk30_clk_set_rate(struct clk *clk, unsigned long rate);
3765 void rk30_clocks_test(void)
3767 struct clk *test_gpll;
3768 test_gpll = rk30_clk_get(NULL, "general_pll");
3770 rk30_clk_set_rate(test_gpll, 297 * 2 * MHZ);
3771 printk("gpll rate=%lu\n", test_gpll->rate);
3776 void __init rk30_clock_init_test(void)
3779 rk30_clock_init(periph_pll_297mhz, codec_pll_360mhz, max_i2s_12288khz);