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(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 = clksel_set_rate_freediv,
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)
1555 if (rate == 27 * MHZ && (rk30_clock_flags & CLK_FLG_EXT_27MHZ)) {
1556 parent = clk->parents[1];
1557 //CLKDATA_DBG(" %s from=%s\n",clk->name,parent->name);
1559 parent = clk->parents[0];
1561 //CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1562 //clk->name,rate,parent->name,clk->parent->name);
1564 if(parent != clk->parents[1]) {
1565 ret = clk_set_rate_nolock(parent, rate); //div 1:1
1567 CLKDATA_DBG("%s set rate=%lu err\n", clk->name, rate);
1571 if (clk->parent != parent) {
1572 ret = clk_set_parent_nolock(clk, parent);
1574 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
1581 static struct clk *dclk_lcdc0_parents[2] = {&codec_pll_clk, &general_pll_clk};
1582 static struct clk dclk_lcdc0 = {
1583 .name = "dclk_lcdc0",
1585 .set_rate = clkset_rate_evendiv_autosel_parents,
1586 .recalc = clksel_recalc_div,
1587 .gate_idx = CLK_GATE_DCLK_LCDC0_SRC,
1588 .clksel_con = CRU_CLKSELS_CON(27),
1589 CRU_SRC_SET(0x1, 0),
1590 CRU_DIV_SET(0xff, 8, 256),
1591 CRU_PARENTS_SET(dclk_lcdc0_parents),
1594 static struct clk *dclk_lcdc1_parents[2] = {&codec_pll_clk, &general_pll_clk};
1595 static struct clk dclk_lcdc1 = {
1596 .name = "dclk_lcdc1",
1598 .set_rate = clkset_rate_evendiv_autosel_parents,
1599 .recalc = clksel_recalc_div,
1600 .gate_idx = CLK_GATE_DCLK_LCDC1_SRC,
1601 .clksel_con = CRU_CLKSELS_CON(28),
1602 CRU_SRC_SET(0x1, 0),
1603 CRU_DIV_SET(0xff, 8, 256),
1604 CRU_PARENTS_SET(dclk_lcdc1_parents),
1609 static struct clk *cifout_sel_pll_parents[2] = {&codec_pll_clk, &general_pll_clk};
1610 static struct clk cif_out_pll = {
1611 .name = "cif_out_pll",
1612 .parent = &general_pll_clk,
1613 .clksel_con = CRU_CLKSELS_CON(29),
1614 CRU_SRC_SET(0x1, 0),
1615 CRU_PARENTS_SET(cifout_sel_pll_parents),
1618 static struct clk cif0_out_div = {
1619 .name = "cif0_out_div",
1620 .parent = &cif_out_pll,
1622 .recalc = clksel_recalc_div,
1623 .set_rate = clksel_set_rate_freediv,
1624 .gate_idx = CLK_GATE_CIF0_OUT,
1625 .clksel_con = CRU_CLKSELS_CON(29),
1626 CRU_DIV_SET(0x1f, 1, 32),
1629 static int cif_out_set_rate(struct clk *clk, unsigned long rate)
1634 if (rate == 24 * MHZ) {
1635 parent = clk->parents[1];
1637 parent = clk->parents[0];
1638 ret = clk_set_rate_nolock(parent, rate);
1642 if (clk->parent != parent)
1643 ret = clk_set_parent_nolock(clk, parent);
1648 static struct clk *cif0_out_parents[2] = {&cif0_out_div, &xin24m};
1649 static struct clk cif0_out = {
1651 .parent = &cif0_out_div,
1652 .set_rate = cif_out_set_rate,
1653 .clksel_con = CRU_CLKSELS_CON(29),
1654 CRU_SRC_SET(0x1, 7),
1655 CRU_PARENTS_SET(cif0_out_parents),
1658 static struct clk pclkin_cif0 = {
1659 .name = "pclkin_cif0",
1661 .gate_idx = CLK_GATE_PCLKIN_CIF0,
1664 static struct clk inv_cif0 = {
1666 .parent = &pclkin_cif0,
1669 static struct clk *cif0_in_parents[2] = {&pclkin_cif0, &inv_cif0};
1670 static struct clk cif0_in = {
1672 .parent = &pclkin_cif0,
1673 .clksel_con = CRU_CLKSELS_CON(30),
1674 CRU_SRC_SET(0x1, 8),
1675 CRU_PARENTS_SET(cif0_in_parents),
1678 /* i2s/spdif setting */
1679 static struct clk *clk_i2s_div_parents[] = {&general_pll_clk, &codec_pll_clk};
1680 static struct clk clk_i2s_pll = {
1682 .parent = &general_pll_clk,
1683 .clksel_con = CRU_CLKSELS_CON(2),
1684 CRU_SRC_SET(0x1, 15),
1685 CRU_PARENTS_SET(clk_i2s_div_parents),
1688 static struct clk clk_i2s0_div = {
1690 .parent = &clk_i2s_pll,
1692 .recalc = clksel_recalc_div,
1693 .set_rate = clksel_set_rate_freediv,
1694 .round_rate = clksel_freediv_round_rate,
1695 .gate_idx = CLK_GATE_I2S0_SRC,
1696 .clksel_con = CRU_CLKSELS_CON(3),
1697 CRU_DIV_SET(0x7f, 0, 64),
1700 static struct clk clk_spdif_div = {
1701 .name = "spdif_div",
1702 .parent = &clk_i2s_pll,
1703 .recalc = clksel_recalc_div,
1704 .set_rate = clksel_set_rate_freediv,
1705 .round_rate = clksel_freediv_round_rate,
1707 .gate_idx = CLK_GATE_SPDIF_SRC,
1708 .clksel_con = CRU_CLKSELS_CON(5),
1709 CRU_DIV_SET(0x7f, 0, 64),
1711 static int clk_i2s_fracdiv_set_rate(struct clk *clk, unsigned long rate)
1713 u32 numerator, denominator;
1714 //clk_i2s_div->clk_i2s_pll->gpll/cpll
1715 //clk->parent->parent
1716 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1717 &numerator, &denominator) == 0) {
1718 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
1719 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1720 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
1722 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1728 static struct clk clk_i2s0_frac_div = {
1729 .name = "i2s0_frac_div",
1730 .parent = &clk_i2s0_div,
1732 .gate_idx = CLK_GATE_I2S0_FRAC,
1733 .recalc = clksel_recalc_frac,
1734 .set_rate = clk_i2s_fracdiv_set_rate,
1735 .clksel_con = CRU_CLKSELS_CON(7),
1738 static struct clk clk_spdif_frac_div = {
1739 .name = "spdif_frac_div",
1740 .parent = &clk_spdif_div,
1742 .gate_idx = CLK_GATE_SPDIF_FRAC,
1743 .recalc = clksel_recalc_frac,
1744 .set_rate = clk_i2s_fracdiv_set_rate,
1745 .clksel_con = CRU_CLKSELS_CON(9),
1748 #define I2S_SRC_DIV (0x0)
1749 #define I2S_SRC_FRAC (0x1)
1750 #define I2S_SRC_12M (0x2)
1752 static int i2s_set_rate(struct clk *clk, unsigned long rate)
1757 if (rate == clk->parents[I2S_SRC_12M]->rate) {
1758 parent = clk->parents[I2S_SRC_12M];
1759 } else if((long)clk_round_rate_nolock(clk->parents[I2S_SRC_DIV], rate) == rate) {
1760 parent = clk->parents[I2S_SRC_DIV];
1762 parent = clk->parents[I2S_SRC_FRAC];
1765 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1766 clk->name, rate, parent->name, clk->parent->name);
1768 if(parent != clk->parents[I2S_SRC_12M]) {
1769 ret = clk_set_rate_nolock(parent, rate); //div 1:1
1771 CLKDATA_DBG("%s set rate%lu err\n", clk->name, rate);
1776 if (clk->parent != parent) {
1777 ret = clk_set_parent_nolock(clk, parent);
1779 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
1787 static struct clk *clk_i2s0_parents[3] = {&clk_i2s0_div, &clk_i2s0_frac_div, &clk_12m};
1789 static struct clk clk_i2s0 = {
1791 .set_rate = i2s_set_rate,
1792 .clksel_con = CRU_CLKSELS_CON(3),
1793 CRU_SRC_SET(0x3, 8),
1794 CRU_PARENTS_SET(clk_i2s0_parents),
1797 static struct clk *clk_spdif_parents[3] = {&clk_spdif_div, &clk_spdif_frac_div, &clk_12m};
1799 static struct clk clk_spdif = {
1801 .parent = &clk_spdif_frac_div,
1802 .set_rate = i2s_set_rate,
1803 .clksel_con = CRU_CLKSELS_CON(5),
1804 CRU_SRC_SET(0x3, 8),
1805 CRU_PARENTS_SET(clk_spdif_parents),
1808 /* otgphy setting */
1809 GATE_CLK(otgphy0, xin24m, OTGPHY0);
1810 GATE_CLK(otgphy1, xin24m, OTGPHY1);
1812 static struct clk clk_otgphy0_480m = {
1813 .name = "otgphy0_480m",
1814 .parent = &clk_otgphy0,
1816 static struct clk clk_otgphy1_480m = {
1817 .name = "otgphy1_480m",
1818 .parent = &clk_otgphy1,
1821 /* hsicphy setting */
1823 static struct clk *clk_hsicphy_parents[4] = {&clk_otgphy0_480m, &clk_otgphy1_480m, &general_pll_clk, &codec_pll_clk};
1824 static struct clk clk_hsicphy_480m = {
1825 .name = "hsicphy_480m",
1826 .parent = &clk_otgphy0_480m,
1827 .clksel_con = CRU_CLKSELS_CON(30),
1828 CRU_SRC_SET(0x3, 0),
1829 CRU_PARENTS_SET(clk_hsicphy_parents),
1831 static struct clk clk_hsicphy_12m = {
1832 .name = "hsicphy_12m",
1833 .parent = &clk_hsicphy_480m,
1834 .clksel_con = CRU_CLKSELS_CON(11),
1835 CRU_DIV_SET(0x3f, 8, 64),
1839 /* mac and rmii setting */
1841 static struct clk rmii_clkin = {
1842 .name = "rmii_clkin",
1844 static struct clk *clk_mac_ref_div_parents[2] = {&general_pll_clk, &ddr_pll_clk};
1845 static struct clk clk_mac_pll_div = {
1846 .name = "mac_pll_div",
1847 .parent = &general_pll_clk,
1849 .gate_idx = CLK_GATE_MAC_SRC,
1850 .recalc = clksel_recalc_div,
1851 .set_rate = clksel_set_rate_freediv,
1852 .clksel_con = CRU_CLKSELS_CON(21),
1853 CRU_DIV_SET(0x1f, 8, 32),
1854 CRU_SRC_SET(0x1, 0),
1855 CRU_PARENTS_SET(clk_mac_ref_div_parents),
1858 static int clksel_mac_ref_set_rate(struct clk *clk, unsigned long rate)
1860 if(clk->parent == clk->parents[1]) {
1861 CLKDATA_DBG("mac_ref clk is form mii clkin,can't set it\n" );
1863 } else if(clk->parent == clk->parents[0]) {
1864 return clk_set_rate_nolock(clk->parents[0], rate);
1869 static struct clk *clk_mac_ref_parents[2] = {&clk_mac_pll_div, &rmii_clkin};
1871 static struct clk clk_mac_ref = {
1873 .parent = &clk_mac_pll_div,
1874 .set_rate = clksel_mac_ref_set_rate,
1875 .clksel_con = CRU_CLKSELS_CON(21),
1876 CRU_SRC_SET(0x1, 4),
1877 CRU_PARENTS_SET(clk_mac_ref_parents),
1880 static int clk_set_mii_tx_parent(struct clk *clk, struct clk *parent)
1882 return clk_set_parent_nolock(clk->parent, parent);
1885 static struct clk clk_mii_tx = {
1887 .parent = &clk_mac_ref,
1888 //.set_parent = clk_set_mii_tx_parent,
1890 .gate_idx = CLK_GATE_MAC_LBTEST,
1893 /* hsadc and saradc */
1894 static struct clk *clk_hsadc_pll_parents[2] = {&general_pll_clk, &codec_pll_clk};
1895 static struct clk clk_hsadc_pll_div = {
1896 .name = "hsadc_pll_div",
1897 .parent = &general_pll_clk,
1899 .gate_idx = CLK_GATE_HSADC_SRC,
1900 .recalc = clksel_recalc_div,
1901 .round_rate = clk_freediv_round_autosel_parents_rate,
1902 .set_rate = clkset_rate_freediv_autosel_parents,
1903 //.round_rate = clksel_freediv_round_rate,
1904 //.set_rate = clksel_set_rate_freediv,
1905 .clksel_con = CRU_CLKSELS_CON(22),
1906 CRU_DIV_SET(0xff, 8, 256),
1907 CRU_SRC_SET(0x1, 0),
1908 CRU_PARENTS_SET(clk_hsadc_pll_parents),
1910 static int clk_hsadc_fracdiv_set_rate_fixed_parent(struct clk *clk, unsigned long rate)
1912 u32 numerator, denominator;
1913 // clk_hsadc_pll_div->gpll/cpll
1914 //clk->parent->parent
1915 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1916 &numerator, &denominator) == 0) {
1917 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
1919 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1921 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
1923 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1928 static int clk_hsadc_fracdiv_set_rate_auto_parents(struct clk *clk, unsigned long rate)
1930 u32 numerator, denominator;
1932 // clk_hsadc_pll_div->gpll/cpll
1933 //clk->parent->parent
1934 for(i = 0; i < 2; i++) {
1935 if(frac_div_get_seting(rate, clk->parent->parents[i]->rate,
1936 &numerator, &denominator) == 0)
1942 if(clk->parent->parent != clk->parent->parents[i])
1943 ret = clk_set_parent_nolock(clk->parent, clk->parent->parents[i]);
1945 clk_set_rate_nolock(clk->parent, clk->parent->parents[i]->rate); //PLL:DIV 1:
1947 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
1949 CLKDATA_DBG("clk_frac_div %s, rate=%lu\n", clk->name, rate);
1951 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
1957 static long clk_hsadc_fracdiv_round_rate(struct clk *clk, unsigned long rate)
1959 u32 numerator, denominator;
1961 CLKDATA_ERR("clk_hsadc_fracdiv_round_rate\n");
1962 if(frac_div_get_seting(rate, clk->parent->parent->rate,
1963 &numerator, &denominator) == 0)
1968 static struct clk clk_hsadc_frac_div = {
1969 .name = "hsadc_frac_div",
1970 .parent = &clk_hsadc_pll_div,
1972 .recalc = clksel_recalc_frac,
1973 .set_rate = clk_hsadc_fracdiv_set_rate_auto_parents,
1974 .round_rate = clk_hsadc_fracdiv_round_rate,
1975 .gate_idx = CLK_GATE_HSADC_FRAC_SRC,
1976 .clksel_con = CRU_CLKSELS_CON(23),
1979 #define HSADC_SRC_DIV 0x0
1980 #define HSADC_SRC_FRAC 0x1
1981 #define HSADC_SRC_EXT 0x2
1982 static int clk_hsadc_set_rate(struct clk *clk, unsigned long rate)
1987 if(clk->parent == clk->parents[HSADC_SRC_EXT]) {
1988 CLKDATA_DBG("hsadc clk is form ext\n");
1990 } else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_DIV], rate) == rate) {
1991 parent = clk->parents[HSADC_SRC_DIV];
1992 } else if((long)clk_round_rate_nolock(clk->parents[HSADC_SRC_FRAC], rate) == rate) {
1993 parent = clk->parents[HSADC_SRC_FRAC];
1995 parent = clk->parents[HSADC_SRC_DIV];
1997 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
1998 clk->name, rate, parent->name, clk->parent->name);
2000 ret = clk_set_rate_nolock(parent, rate);
2002 CLKDATA_ERR("%s set rate%lu err\n", clk->name, rate);
2005 if (clk->parent != parent) {
2006 ret = clk_set_parent_nolock(clk, parent);
2008 CLKDATA_ERR("%s can't get rate%lu,reparent err\n", clk->name, rate);
2015 static struct clk clk_hsadc_ext = {
2016 .name = "hsadc_ext",
2019 static struct clk *clk_hsadc_out_parents[3] = {&clk_hsadc_pll_div, &clk_hsadc_frac_div, &clk_hsadc_ext};
2020 static struct clk clk_hsadc_out = {
2021 .name = "hsadc_out",
2022 .parent = &clk_hsadc_pll_div,
2023 .set_rate = clk_hsadc_set_rate,
2024 .clksel_con = CRU_CLKSELS_CON(22),
2025 CRU_SRC_SET(0x3, 4),
2026 CRU_PARENTS_SET(clk_hsadc_out_parents),
2028 static struct clk clk_hsadc_out_inv = {
2029 .name = "hsadc_out_inv",
2030 .parent = &clk_hsadc_out,
2033 static struct clk *clk_hsadc_parents[3] = {&clk_hsadc_out, &clk_hsadc_out_inv};
2034 static struct clk clk_hsadc = {
2036 .parent = &clk_hsadc_out,
2037 .clksel_con = CRU_CLKSELS_CON(22),
2038 CRU_SRC_SET(0x1, 7),
2039 CRU_PARENTS_SET(clk_hsadc_parents),
2042 static struct clk clk_saradc = {
2046 .recalc = clksel_recalc_div,
2047 .set_rate = clksel_set_rate_freediv,
2048 .gate_idx = CLK_GATE_SARADC_SRC,
2049 .clksel_con = CRU_CLKSELS_CON(24),
2050 CRU_DIV_SET(0xff, 8, 256),
2054 GATE_CLK(smc, hclk_periph, SMC_SRC);//smc
2055 static struct clk clkn_smc = {
2061 static struct clk clk_spi0 = {
2063 .parent = &pclk_periph,
2065 .recalc = clksel_recalc_div,
2066 .set_rate = clksel_set_rate_freediv,
2067 .gate_idx = CLK_GATE_SPI0_SRC,
2068 .clksel_con = CRU_CLKSELS_CON(25),
2069 CRU_DIV_SET(0x7f, 0, 128),
2072 static struct clk clk_spi1 = {
2074 .parent = &pclk_periph,
2076 .recalc = clksel_recalc_div,
2077 .set_rate = clksel_set_rate_freediv,
2078 .gate_idx = CLK_GATE_SPI1_SRC,
2079 .clksel_con = CRU_CLKSELS_CON(25),
2080 CRU_DIV_SET(0x7f, 8, 128),
2083 /* sdmmc/sdio/emmc setting */
2084 static struct clk clk_sdmmc = {
2086 .parent = &hclk_periph,
2088 .recalc = clksel_recalc_div,
2089 .set_rate = clksel_set_rate_even,
2090 .gate_idx = CLK_GATE_MMC0_SRC,
2091 .clksel_con = CRU_CLKSELS_CON(11),
2092 CRU_DIV_SET(0x3f, 0, 64),
2095 static struct clk clk_sdio = {
2097 .parent = &hclk_periph,
2099 .recalc = clksel_recalc_div,
2100 .set_rate = clksel_set_rate_even,
2101 .gate_idx = CLK_GATE_SDIO_SRC,
2102 .clksel_con = CRU_CLKSELS_CON(12),
2103 CRU_DIV_SET(0x3f, 0, 64),
2107 static struct clk clk_emmc = {
2109 .parent = &hclk_periph,
2111 .recalc = clksel_recalc_div,
2112 .set_rate = clksel_set_rate_freediv,
2113 .gate_idx = CLK_GATE_EMMC_SRC,
2114 .clksel_con = CRU_CLKSELS_CON(12),
2115 CRU_DIV_SET(0x3f, 8, 64),
2119 static struct clk *clk_uart_src_parents[2] = {&general_pll_clk, &codec_pll_clk};
2120 static struct clk clk_uart_pll = {
2122 .parent = &general_pll_clk,
2123 .clksel_con = CRU_CLKSELS_CON(12),
2124 CRU_SRC_SET(0x1, 15),
2125 CRU_PARENTS_SET(clk_uart_src_parents),
2127 static struct clk clk_uart0_div = {
2128 .name = "uart0_div",
2129 .parent = &clk_uart_pll,
2131 .gate_idx = CLK_GATE_UART0_SRC,
2132 .recalc = clksel_recalc_div,
2133 .set_rate = clksel_set_rate_freediv,
2134 .round_rate = clksel_freediv_round_rate,
2135 .clksel_con = CRU_CLKSELS_CON(13),
2136 CRU_DIV_SET(0x7f, 0, 64),
2138 static struct clk clk_uart1_div = {
2139 .name = "uart1_div",
2140 .parent = &clk_uart_pll,
2142 .gate_idx = CLK_GATE_UART1_SRC,
2143 .recalc = clksel_recalc_div,
2144 .round_rate = clksel_freediv_round_rate,
2145 .set_rate = clksel_set_rate_freediv,
2146 .clksel_con = CRU_CLKSELS_CON(14),
2147 CRU_DIV_SET(0x7f, 0, 64),
2150 static struct clk clk_uart2_div = {
2151 .name = "uart2_div",
2152 .parent = &clk_uart_pll,
2154 .gate_idx = CLK_GATE_UART2_SRC,
2155 .recalc = clksel_recalc_div,
2156 .round_rate = clksel_freediv_round_rate,
2157 .set_rate = clksel_set_rate_freediv,
2158 .clksel_con = CRU_CLKSELS_CON(15),
2159 CRU_DIV_SET(0x7f, 0, 64),
2162 static struct clk clk_uart3_div = {
2163 .name = "uart3_div",
2164 .parent = &clk_uart_pll,
2166 .gate_idx = CLK_GATE_UART3_SRC,
2167 .recalc = clksel_recalc_div,
2168 .round_rate = clksel_freediv_round_rate,
2169 .set_rate = clksel_set_rate_freediv,
2170 .clksel_con = CRU_CLKSELS_CON(16),
2171 CRU_DIV_SET(0x7f, 0, 64),
2173 static int clk_uart_fracdiv_set_rate(struct clk *clk, unsigned long rate)
2175 u32 numerator, denominator;
2176 //clk_uart0_div->clk_uart_pll->gpll/cpll
2177 //clk->parent->parent
2178 if(frac_div_get_seting(rate, clk->parent->parent->rate,
2179 &numerator, &denominator) == 0) {
2180 clk_set_rate_nolock(clk->parent, clk->parent->parent->rate); //PLL:DIV 1:
2182 cru_writel_frac(numerator << 16 | denominator, clk->clksel_con);
2184 CLKDATA_DBG("%s set rate=%lu,is ok\n", clk->name, rate);
2186 CLKDATA_ERR("clk_frac_div can't get rate=%lu,%s\n", rate, clk->name);
2192 static struct clk clk_uart0_frac_div = {
2193 .name = "uart0_frac_div",
2194 .parent = &clk_uart0_div,
2196 .recalc = clksel_recalc_frac,
2197 .set_rate = clk_uart_fracdiv_set_rate,
2198 .gate_idx = CLK_GATE_UART0_FRAC_SRC,
2199 .clksel_con = CRU_CLKSELS_CON(17),
2201 static struct clk clk_uart1_frac_div = {
2202 .name = "uart1_frac_div",
2203 .parent = &clk_uart1_div,
2205 .recalc = clksel_recalc_frac,
2206 .set_rate = clk_uart_fracdiv_set_rate,
2207 .gate_idx = CLK_GATE_UART1_FRAC_SRC,
2208 .clksel_con = CRU_CLKSELS_CON(18),
2210 static struct clk clk_uart2_frac_div = {
2211 .name = "uart2_frac_div",
2213 .parent = &clk_uart2_div,
2214 .recalc = clksel_recalc_frac,
2215 .set_rate = clk_uart_fracdiv_set_rate,
2216 .gate_idx = CLK_GATE_UART2_FRAC_SRC,
2217 .clksel_con = CRU_CLKSELS_CON(19),
2219 static struct clk clk_uart3_frac_div = {
2220 .name = "uart3_frac_div",
2221 .parent = &clk_uart3_div,
2223 .recalc = clksel_recalc_frac,
2224 .set_rate = clk_uart_fracdiv_set_rate,
2225 .gate_idx = CLK_GATE_UART3_FRAC_SRC,
2226 .clksel_con = CRU_CLKSELS_CON(20),
2229 #define UART_SRC_DIV 0
2230 #define UART_SRC_FRAC 1
2231 #define UART_SRC_24M 2
2233 static int clk_uart_set_rate(struct clk *clk, unsigned long rate)
2238 if(rate == clk->parents[UART_SRC_24M]->rate) { //24m
2239 parent = clk->parents[UART_SRC_24M];
2240 } else if((long)clk_round_rate_nolock(clk->parents[UART_SRC_DIV], rate) == rate) {
2241 parent = clk->parents[UART_SRC_DIV];
2243 parent = clk->parents[UART_SRC_FRAC];
2246 CLKDATA_DBG(" %s set rate=%lu parent %s(old %s)\n",
2247 clk->name, rate, parent->name, clk->parent->name);
2249 if(parent != clk->parents[UART_SRC_24M]) {
2250 ret = clk_set_rate_nolock(parent, rate);
2252 CLKDATA_DBG("%s set rate%lu err\n", clk->name, rate);
2257 if (clk->parent != parent) {
2258 ret = clk_set_parent_nolock(clk, parent);
2260 CLKDATA_DBG("%s can't get rate%lu,reparent err\n", clk->name, rate);
2268 static struct clk *clk_uart0_parents[3] = {&clk_uart0_div, &clk_uart0_frac_div, &xin24m};
2269 static struct clk clk_uart0 = {
2271 .set_rate = clk_uart_set_rate,
2272 .clksel_con = CRU_CLKSELS_CON(13),
2273 CRU_SRC_SET(0x3, 8),
2274 CRU_PARENTS_SET(clk_uart0_parents),
2277 static struct clk *clk_uart1_parents[3] = {&clk_uart1_div, &clk_uart1_frac_div, &xin24m};
2278 static struct clk clk_uart1 = {
2280 .set_rate = clk_uart_set_rate,
2281 .clksel_con = CRU_CLKSELS_CON(14),
2282 CRU_SRC_SET(0x3, 8),
2283 CRU_PARENTS_SET(clk_uart1_parents),
2286 static struct clk *clk_uart2_parents[3] = {&clk_uart2_div, &clk_uart2_frac_div, &xin24m};
2287 static struct clk clk_uart2 = {
2289 .set_rate = clk_uart_set_rate,
2290 .clksel_con = CRU_CLKSELS_CON(15),
2291 CRU_SRC_SET(0x3, 8),
2292 CRU_PARENTS_SET(clk_uart2_parents),
2294 static struct clk *clk_uart3_parents[3] = {&clk_uart3_div, &clk_uart3_frac_div, &xin24m};
2295 static struct clk clk_uart3 = {
2297 .set_rate = clk_uart_set_rate,
2298 .clksel_con = CRU_CLKSELS_CON(16),
2299 CRU_SRC_SET(0x3, 8),
2300 CRU_PARENTS_SET(clk_uart3_parents),
2304 GATE_CLK(timer0, xin24m, TIMER0);
2305 GATE_CLK(timer1, xin24m, TIMER1);
2306 GATE_CLK(timer2, xin24m, TIMER2);
2307 GATE_CLK(timer3, xin24m, TIMER3);
2308 GATE_CLK(timer4, xin24m, TIMER4);
2309 GATE_CLK(timer5, xin24m, TIMER5);
2310 GATE_CLK(timer6, xin24m, TIMER6);
2312 /*********************power domain*******************************/
2314 #ifdef RK30_CLK_OFFBOARD_TEST
2315 void pmu_set_power_domain_test(enum pmu_power_domain pd, bool on) {};
2316 #define _pmu_set_power_domain pmu_set_power_domain_test//rk30_pmu_set_power_domain
2318 void pmu_set_power_domain(enum pmu_power_domain pd, bool on);
2319 #define _pmu_set_power_domain pmu_set_power_domain
2322 static int pd_video_mode(struct clk *clk, int on)
2325 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2326 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2327 //gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2328 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2329 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2330 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2331 pmu_set_power_domain(PD_VIDEO, on);
2332 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VEPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VEPU));
2333 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VDPU) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VDPU));
2334 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VCODEC) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VCODEC));
2338 static struct clk pd_video = {
2341 .mode = pd_video_mode,
2342 .gate_idx = PD_VIDEO,
2344 static int pd_display_mode(struct clk *clk, int on)
2347 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2348 gate[1] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2349 gate[2] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2350 gate[3] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2351 gate[4] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2352 //gate[5] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2353 gate[6] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2354 gate[7] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2355 gate[8] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2356 gate[9] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2357 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2358 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2359 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2360 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2361 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2362 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2363 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2364 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2365 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2366 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2367 pmu_set_power_domain(PD_VIO, on);
2368 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0_SRC) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0_SRC));
2369 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1_SRC) | gate[1], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1_SRC));
2370 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC0) | gate[2], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC0));
2371 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_LCDC1) | gate[3], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_LCDC1));
2372 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF0) | gate[4], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF0));
2373 //cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_CIF1) | gate[5], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_CIF1));
2374 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO0) | gate[6], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO0));
2375 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_VIO1) | gate[7], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_VIO1));
2376 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_IPP) | gate[8], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_IPP));
2377 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_RGA) | gate[9], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_RGA));
2381 static struct clk pd_display = {
2384 .mode = pd_display_mode,
2387 static struct clk pd_lcdc0 = {
2388 .parent = &pd_display,
2391 static struct clk pd_lcdc1 = {
2392 .parent = &pd_display,
2395 static struct clk pd_cif0 = {
2396 .parent = &pd_display,
2399 static struct clk pd_rga = {
2400 .parent = &pd_display,
2403 static struct clk pd_ipp = {
2404 .parent = &pd_display,
2407 static struct clk pd_hdmi = {
2408 .parent = &pd_display,
2413 static int pd_gpu_mode(struct clk *clk, int on)
2416 gate[0] = cru_readl(CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2417 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU), CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2418 pmu_set_power_domain(PD_GPU, on);
2419 cru_writel(CLK_GATE_W_MSK(CLK_GATE_ACLK_GPU) | gate[0], CLK_GATE_CLKID_CONS(CLK_GATE_ACLK_GPU));
2423 static struct clk pd_gpu = {
2426 .mode = pd_gpu_mode,
2430 static int pm_off_mode(struct clk *clk, int on)
2432 _pmu_set_power_domain(clk->gate_idx, on); //on 1
2435 static struct clk pd_peri = {
2438 .mode = pm_off_mode,
2439 .gate_idx = PD_PERI,
2443 #define PD_CLK(name) \
2451 /************************rk30 fixed div clock****************************************/
2453 /*************************aclk_cpu***********************/
2455 GATE_CLK(dma1, aclk_cpu, ACLK_DMAC1);
2456 GATE_CLK(intmem, aclk_cpu, ACLK_INTMEM);
2457 GATE_CLK(aclk_strc_sys, aclk_cpu, ACLK_STRC_SYS);
2459 /*************************hclk_cpu***********************/
2461 GATE_CLK(rom, hclk_cpu, HCLK_ROM);
2462 GATE_CLK(hclk_i2s0_2ch, hclk_cpu, HCLK_I2S0_2CH);
2463 GATE_CLK(hclk_spdif, hclk_cpu, HCLK_SPDIF);
2464 GATE_CLK(hclk_cpubus, hclk_cpu, HCLK_CPUBUS);
2465 GATE_CLK(hclk_ahb2apb, hclk_cpu, HCLK_AHB2APB);
2466 GATE_CLK(hclk_vio_bus, hclk_cpu, HCLK_VIO_BUS);
2467 GATE_CLK(hclk_lcdc0, hclk_cpu, HCLK_LCDC0);
2468 GATE_CLK(hclk_lcdc1, hclk_cpu, HCLK_LCDC1);
2469 GATE_CLK(hclk_cif0, hclk_cpu, HCLK_CIF0);
2470 GATE_CLK(hclk_ipp, hclk_cpu, HCLK_IPP);
2471 GATE_CLK(hclk_rga, hclk_cpu, HCLK_RGA);
2472 GATE_CLK(hclk_imem0, hclk_cpu, HCLK_IMEM0);
2473 GATE_CLK(hclk_imem1, hclk_cpu, HCLK_IMEM1);
2475 /*************************ahb2apb_cpu(pclk_cpu_h2p)***********************/
2476 GATE_CLK(pclk_uart0, ahb2apb_cpu, PCLK_UART0);
2477 GATE_CLK(pclk_uart1, ahb2apb_cpu, PCLK_UART1);
2478 /*************************pclk_cpu***********************/
2479 GATE_CLK(pwm01, pclk_cpu, PCLK_PWM01);//pwm 0¡¢1
2480 GATE_CLK(pclk_timer0, pclk_cpu, PCLK_TIMER0);
2481 GATE_CLK(pclk_timer2, pclk_cpu, PCLK_TIMER2);
2482 GATE_CLK(i2c0, pclk_cpu, PCLK_I2C0);
2483 GATE_CLK(i2c1, pclk_cpu, PCLK_I2C1);
2484 GATE_CLK(gpio0, pclk_cpu, PCLK_GPIO0);
2485 GATE_CLK(gpio1, pclk_cpu, PCLK_GPIO1);
2486 GATE_CLK(gpio2, pclk_cpu, PCLK_GPIO2);
2487 GATE_CLK(efuse, pclk_cpu, PCLK_EFUSE);
2488 GATE_CLK(tzpc, pclk_cpu, PCLK_TZPC);
2489 GATE_CLK(pclk_ddrupctl, pclk_cpu, PCLK_DDRUPCTL);
2490 GATE_CLK(pclk_ddrpubl, pclk_cpu, PCLK_PUBL);
2491 GATE_CLK(dbg, pclk_cpu, PCLK_DBG);
2492 GATE_CLK(grf, pclk_cpu, PCLK_GRF);
2493 GATE_CLK(pmu, pclk_cpu, PCLK_PMU);
2495 /*************************aclk_periph***********************/
2497 GATE_CLK(dma2, aclk_periph, ACLK_DMAC2);
2498 GATE_CLK(aclk_smc, aclk_periph, ACLK_SMC);
2499 GATE_CLK(aclk_gps, aclk_periph, ACLK_GPS);
2500 GATE_CLK(aclk_peri_niu, aclk_periph, ACLK_PEI_NIU);
2501 GATE_CLK(aclk_cpu_peri, aclk_periph, ACLK_CPU_PERI);
2502 GATE_CLK(aclk_peri_axi_matrix, aclk_periph, ACLK_PERI_AXI_MATRIX);
2504 /*************************hclk_periph***********************/
2505 GATE_CLK(hclk_peri_axi_matrix, hclk_periph, HCLK_PERI_AXI_MATRIX);
2506 GATE_CLK(hclk_peri_ahb_arbi, hclk_periph, HCLK_PERI_AHB_ARBI);
2507 GATE_CLK(hclk_emem_peri, hclk_periph, HCLK_EMEM_PERI);
2508 GATE_CLK(hclk_mac, hclk_periph, HCLK_EMAC);
2509 GATE_CLK(nandc, hclk_periph, HCLK_NANDC);
2510 GATE_CLK(hclk_usb_peri, hclk_periph, HCLK_USB_PERI);
2511 GATE_CLK(hclk_otg0, clk_hclk_usb_peri, HCLK_OTG0);
2512 GATE_CLK(hclk_otg1, clk_hclk_usb_peri, HCLK_OTG1);
2513 GATE_CLK(hclk_hsic, hclk_periph, HCLK_HSIC);
2514 GATE_CLK(hclk_hsadc, hclk_periph, HCLK_HSADC);
2515 GATE_CLK(hclk_pidfilter, hclk_periph, HCLK_PIDF);
2516 GATE_CLK(hclk_sdmmc, hclk_periph, HCLK_SDMMC0);
2517 GATE_CLK(hclk_sdio, hclk_periph, HCLK_SDIO);
2518 GATE_CLK(hclk_emmc, hclk_periph, HCLK_EMMC);
2519 /*************************pclk_periph***********************/
2520 GATE_CLK(pclk_peri_axi_matrix, pclk_periph, PCLK_PERI_AXI_MATRIX);
2521 GATE_CLK(pwm23, pclk_periph, PCLK_PWM23);
2522 GATE_CLK(wdt, pclk_periph, PCLK_WDT);
2523 GATE_CLK(pclk_spi0, pclk_periph, PCLK_SPI0);
2524 GATE_CLK(pclk_spi1, pclk_periph, PCLK_SPI1);
2525 GATE_CLK(pclk_uart2, pclk_periph, PCLK_UART2);
2526 GATE_CLK(pclk_uart3, pclk_periph, PCLK_UART3);
2527 GATE_CLK(i2c2, pclk_periph, PCLK_I2C2);
2528 GATE_CLK(i2c3, pclk_periph, PCLK_I2C3);
2529 GATE_CLK(i2c4, pclk_periph, PCLK_I2C4);
2530 GATE_CLK(gpio3, pclk_periph, PCLK_GPIO3);
2531 GATE_CLK(pclk_saradc, pclk_periph, PCLK_SARADC);
2532 /*************************aclk_lcdc0***********************/
2534 GATE_CLK(aclk_vio0, aclk_lcdc0_pre, ACLK_VIO0);
2535 GATE_CLK(aclk_lcdc0, clk_aclk_vio0, ACLK_LCDC0);
2536 GATE_CLK(aclk_cif0, clk_aclk_vio0, ACLK_CIF0);
2537 GATE_CLK(aclk_ipp, clk_aclk_vio0, ACLK_IPP);
2539 /*************************aclk_lcdc0***********************/
2541 GATE_CLK(aclk_vio1, aclk_lcdc1_pre, ACLK_VIO1);
2542 GATE_CLK(aclk_lcdc1, clk_aclk_vio1, ACLK_LCDC1);
2543 GATE_CLK(aclk_rga, clk_aclk_vio1, ACLK_RGA);
2547 #define CLK(dev, con, ck) \
2555 #define CLK1(name) \
2559 .clk = &clk_##name,\
2564 static struct clk_lookup clks[] = {
2565 CLK(NULL, "xin24m", &xin24m),
2566 //CLK(NULL, "xin27m", &xin27m),
2567 CLK(NULL, "xin12m", &clk_12m),
2568 CLK(NULL, "arm_pll", &arm_pll_clk),
2569 CLK(NULL, "ddr_pll", &ddr_pll_clk),
2570 CLK(NULL, "codec_pll", &codec_pll_clk),
2571 CLK(NULL, "general_pll", &general_pll_clk),
2573 CLK(NULL, "arm_gpll", &clk_core_gpll_path),
2574 CLK(NULL, "ddr_gpll", &clk_ddr_gpll_path),
2576 CLK(NULL, "ddr", &clk_ddr),
2577 CLK(NULL, "cpu", &clk_core),
2580 CLK("smp_twd", NULL, &core_periph),
2581 CLK(NULL, "aclk_core", &aclk_core),
2583 CLK(NULL, "logic", &clk_cpu_div),
2584 CLK(NULL, "aclk_cpu", &aclk_cpu),
2585 CLK(NULL, "pclk_cpu", &pclk_cpu),
2586 CLK(NULL, "atclk_cpu", &atclk_cpu),
2587 CLK(NULL, "hclk_cpu", &hclk_cpu),
2588 CLK(NULL, "ahb2apb_cpu", &ahb2apb_cpu),
2590 CLK(NULL, "gpu", &aclk_gpu),
2592 CLK(NULL, "aclk_vepu", &aclk_vepu),
2593 CLK(NULL, "hclk_vepu", &hclk_vepu),
2594 CLK(NULL, "aclk_vdpu", &aclk_vdpu),
2595 CLK(NULL, "hclk_vdpu", &hclk_vdpu),
2597 CLK(NULL, "aclk_lcdc0_pre", &aclk_lcdc0_pre),
2598 CLK(NULL, "aclk_lcdc1_pre", &aclk_lcdc1_pre),
2600 CLK(NULL, "aclk_periph", &aclk_periph),
2601 CLK(NULL, "pclk_periph", &pclk_periph),
2602 CLK(NULL, "hclk_periph", &hclk_periph),
2604 CLK(NULL, "dclk_lcdc0", &dclk_lcdc0),
2605 CLK(NULL, "dclk_lcdc1", &dclk_lcdc1),
2607 CLK(NULL, "cif_out_pll", &cif_out_pll),
2608 CLK(NULL, "cif0_out_div", &cif0_out_div),
2609 CLK(NULL, "cif0_out", &cif0_out),
2611 CLK(NULL, "pclkin_cif0", &pclkin_cif0),
2612 CLK(NULL, "inv_cif0", &inv_cif0),
2613 CLK(NULL, "cif0_in", &cif0_in),
2616 CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div),
2617 CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div),
2618 CLK("rk29_i2s.0", "i2s", &clk_i2s0),
2621 CLK("rk29_i2s.1", "i2s_div", &clk_i2s0_div),
2622 CLK("rk29_i2s.1", "i2s_frac_div", &clk_i2s0_frac_div),
2623 CLK("rk29_i2s.1", "i2s", &clk_i2s0),
2627 CLK1(spdif_frac_div),
2637 CLK(NULL, "rmii_clkin", &rmii_clkin),
2638 CLK(NULL, "mac_ref_div", &clk_mac_pll_div), // compatible with rk29
2642 CLK1(hsadc_pll_div),
2643 CLK1(hsadc_frac_div),
2646 CLK1(hsadc_out_inv),
2652 CLK(NULL, "smc_inv", &clkn_smc),
2654 CLK("rk29xx_spim.0", "spi", &clk_spi0),
2655 CLK("rk29xx_spim.1", "spi", &clk_spi1),
2657 CLK("rk29_sdmmc.0", "mmc", &clk_sdmmc),
2658 CLK("rk29_sdmmc.1", "mmc", &clk_sdio),
2662 CLK("rk_serial.0", "uart_div", &clk_uart0_div),
2663 CLK("rk_serial.0", "uart_frac_div", &clk_uart0_frac_div),
2664 CLK("rk_serial.0", "uart", &clk_uart0),
2665 CLK("rk_serial.1", "uart_div", &clk_uart1_div),
2666 CLK("rk_serial.1", "uart_frac_div", &clk_uart1_frac_div),
2667 CLK("rk_serial.1", "uart", &clk_uart1),
2668 CLK("rk_serial.2", "uart_div", &clk_uart2_div),
2669 CLK("rk_serial.2", "uart_frac_div", &clk_uart2_frac_div),
2670 CLK("rk_serial.2", "uart", &clk_uart2),
2671 CLK("rk_serial.3", "uart_div", &clk_uart3_div),
2672 CLK("rk_serial.3", "uart_frac_div", &clk_uart3_frac_div),
2673 CLK("rk_serial.3", "uart", &clk_uart3),
2683 /*************************aclk_cpu***********************/
2686 CLK1(aclk_strc_sys),
2688 /*************************hclk_cpu***********************/
2690 CLK("rk29_i2s.0", "hclk_i2s", &clk_hclk_i2s0_2ch),
2692 CLK("rk29_i2s.1", "hclk_i2s", &clk_hclk_i2s0_2ch),
2705 /*************************pclk_cpu***********************/
2709 CLK("rk30_i2c.0", "i2c", &clk_i2c0),
2710 CLK("rk30_i2c.1", "i2c", &clk_i2c1),
2716 CLK("rk_serial.0", "pclk_uart", &clk_pclk_uart0),
2717 CLK("rk_serial.1", "pclk_uart", &clk_pclk_uart1),
2718 CLK1(pclk_ddrupctl),
2724 /*************************aclk_periph***********************/
2728 CLK1(aclk_peri_niu),
2729 CLK1(aclk_cpu_peri),
2730 CLK1(aclk_peri_axi_matrix),
2732 /*************************hclk_periph***********************/
2733 CLK1(hclk_peri_axi_matrix),
2734 CLK1(hclk_peri_ahb_arbi),
2735 CLK1(hclk_emem_peri),
2738 CLK1(hclk_usb_peri),
2743 CLK1(hclk_pidfilter),
2744 CLK("rk29_sdmmc.0", "hclk_mmc", &clk_hclk_sdmmc),
2745 CLK("rk29_sdmmc.1", "hclk_mmc", &clk_hclk_sdio),
2748 /*************************pclk_periph***********************/
2749 CLK1(pclk_peri_axi_matrix),
2752 CLK("rk29xx_spim.0", "pclk_spi", &clk_pclk_spi0),
2753 CLK("rk29xx_spim.1", "pclk_spi", &clk_pclk_spi1),
2754 CLK("rk_serial.2", "pclk_uart", &clk_pclk_uart2),
2755 CLK("rk_serial.3", "pclk_uart", &clk_pclk_uart3),
2756 CLK("rk30_i2c.2", "i2c", &clk_i2c2),
2757 CLK("rk30_i2c.3", "i2c", &clk_i2c3),
2758 CLK("rk30_i2c.4", "i2c", &clk_i2c4),
2762 /*************************aclk_lcdc0***********************/
2764 CLK(NULL, "aclk_lcdc0", &clk_aclk_lcdc0),
2768 /*************************aclk_lcdc1***********************/
2770 CLK(NULL, "aclk_lcdc1", &clk_aclk_lcdc1),
2772 /************************power domain**********************/
2786 static void __init rk30_init_enable_clocks(void)
2789 //clk_enable_nolock(&xin24m);
2790 //clk_enable_nolock(&clk_12m);
2791 //clk_enable_nolock(&arm_pll_clk);
2792 //clk_enable_nolock(&ddr_pll_clk);
2793 //clk_enable_nolock(&codec_pll_clk);
2794 //clk_enable_nolock(&general_pll_clk);
2796 clk_enable_nolock(&clk_ddr);
2797 //clk_enable_nolock(&clk_core);
2798 clk_enable_nolock(&clk_cpu_div);
2799 clk_enable_nolock(&clk_core_gpll_path);
2800 clk_enable_nolock(&clk_l2c);
2801 clk_enable_nolock(&clk_core_dbg);
2802 clk_enable_nolock(&core_periph);
2803 clk_enable_nolock(&aclk_core);
2804 //clk_enable_nolock(&aclk_cpu);
2805 //clk_enable_nolock(&pclk_cpu);
2806 clk_enable_nolock(&atclk_cpu);
2807 //clk_enable_nolock(&hclk_cpu);
2808 clk_enable_nolock(&ahb2apb_cpu);
2810 clk_enable_nolock(&clk_gpu);
2811 clk_enable_nolock(&aclk_gpu);
2812 clk_enable_nolock(&aclk_gpu_slv);
2813 clk_enable_nolock(&aclk_gpu_mst);
2815 clk_enable_nolock(&aclk_vepu);
2816 clk_enable_nolock(&hclk_vepu);
2817 clk_enable_nolock(&aclk_vdpu);
2818 clk_enable_nolock(&hclk_vdpu);
2820 clk_enable_nolock(&aclk_lcdc0_pre);
2821 clk_enable_nolock(&aclk_lcdc1_pre);
2823 clk_enable_nolock(&aclk_periph);
2824 clk_enable_nolock(&pclk_periph);
2825 clk_enable_nolock(&hclk_periph);
2828 clk_enable_nolock(&dclk_lcdc0);
2829 clk_enable_nolock(&dclk_lcdc1);
2831 clk_enable_nolock(&cif_out_pll);
2832 clk_enable_nolock(&cif0_out_div);
2834 clk_enable_nolock(&cif0_out);
2835 clk_enable_nolock(&pclkin_cif0);
2836 clk_enable_nolock(&inv_cif0);
2837 clk_enable_nolock(&cif0_in);
2839 clk_enable_nolock(&clk_i2s_pll);
2840 clk_enable_nolock(&clk_i2s0_div);
2841 clk_enable_nolock(&clk_i2s0_frac_div);
2842 clk_enable_nolock(&clk_i2s0);
2845 clk_enable_nolock(&clk_i2s0_div);
2846 clk_enable_nolock(&clk_i2s0_frac_div);
2847 clk_enable_nolock(&clk_i2s0);
2849 clk_enable_nolock(&clk_spdif_div);
2850 clk_enable_nolock(&clk_spdif_frac_div);
2851 clk_enable_nolock(&clk_spdif);
2854 clk_enable_nolock(&clk_otgphy0);
2855 clk_enable_nolock(&clk_otgphy1);
2856 clk_enable_nolock(&clk_otgphy0_480m);
2857 clk_enable_nolock(&clk_otgphy1_480m);
2858 clk_enable_nolock(&clk_hsicphy_480m);
2859 clk_enable_nolock(&clk_hsicphy_12m);
2863 clk_enable_nolock(&rmii_clkin);
2864 clk_enable_nolock(&clk_mac_pll_div); // compatible with rk29
2865 clk_enable_nolock(&clk_mac_ref);
2866 clk_enable_nolock(&clk_mii_tx);
2870 clk_enable_nolock(&clk_hsadc_pll_div);
2871 clk_enable_nolock(&clk_hsadc_frac_div);
2872 clk_enable_nolock(&clk_hsadc_ext);
2873 clk_enable_nolock(&clk_hsadc_out);
2874 clk_enable_nolock(&clk_hsadc_out_inv);
2875 clk_enable_nolock(&clk_hsadc);
2877 clk_enable_nolock(&clk_saradc);
2880 clk_enable_nolock(&clk_smc);
2881 clk_enable_nolock(&clkn_smc);
2884 clk_enable_nolock(&clk_spi0);
2885 clk_enable_nolock(&clk_spi1);
2888 clk_enable_nolock(&clk_sdmmc);
2889 clk_enable_nolock(&clk_sdio);
2890 clk_enable_nolock(&clk_emmc);
2893 clk_enable_nolock(&clk_uart_pll);
2894 clk_enable_nolock(&clk_uart0_div);
2895 clk_enable_nolock(&clk_uart0_frac_div);
2896 clk_enable_nolock(&clk_uart0);
2897 clk_enable_nolock(&clk_uart1_div);
2898 clk_enable_nolock(&clk_uart1_frac_div);
2899 clk_enable_nolock(&clk_uart1);
2900 clk_enable_nolock(&clk_uart2_div);
2901 clk_enable_nolock(&clk_uart2_frac_div);
2902 clk_enable_nolock(&clk_uart2);
2903 clk_enable_nolock(&clk_uart3_div);
2904 clk_enable_nolock(&clk_uart3_frac_div);
2905 clk_enable_nolock(&clk_uart3);
2907 #if CONFIG_RK_DEBUG_UART == 0
2908 clk_enable_nolock(&clk_uart0);
2909 clk_enable_nolock(&clk_pclk_uart0);
2910 #elif CONFIG_RK_DEBUG_UART == 1
2911 clk_enable_nolock(&clk_uart1);
2912 clk_enable_nolock(&clk_pclk_uart1);
2914 #elif CONFIG_RK_DEBUG_UART == 2
2915 clk_enable_nolock(&clk_uart2);
2916 clk_enable_nolock(&clk_pclk_uart2);
2918 #elif CONFIG_RK_DEBUG_UART == 3
2919 clk_enable_nolock(&clk_uart3);
2920 clk_enable_nolock(&clk_pclk_uart3);
2924 clk_enable_nolock(&clk_timer0);
2925 clk_enable_nolock(&clk_timer1);
2926 clk_enable_nolock(&clk_timer2);
2929 /*************************aclk_cpu***********************/
2930 clk_enable_nolock(&clk_dma1);
2931 clk_enable_nolock(&clk_intmem);
2932 clk_enable_nolock(&clk_aclk_strc_sys);
2934 /*************************hclk_cpu***********************/
2935 clk_enable_nolock(&clk_rom);
2937 clk_enable_nolock(&clk_hclk_i2s0_2ch);
2939 clk_enable_nolock(&clk_hclk_i2s0_2ch);
2940 clk_enable_nolock(&clk_hclk_spdif);
2942 clk_enable_nolock(&clk_hclk_cpubus);
2943 clk_enable_nolock(&clk_hclk_ahb2apb);
2944 clk_enable_nolock(&clk_hclk_vio_bus);
2946 clk_enable_nolock(&clk_hclk_lcdc0);
2947 clk_enable_nolock(&clk_hclk_lcdc1);
2948 clk_enable_nolock(&clk_hclk_cif0);
2949 clk_enable_nolock(&clk_hclk_ipp);
2950 clk_enable_nolock(&clk_hclk_rga);
2952 clk_enable_nolock(&clk_hclk_imem0);
2953 clk_enable_nolock(&clk_hclk_imem1);
2955 /*************************pclk_cpu***********************/
2957 clk_enable_nolock(&clk_pwm01);
2958 clk_enable_nolock(&clk_pclk_timer0);
2959 clk_enable_nolock(&clk_pclk_timer1);
2960 clk_enable_nolock(&clk_pclk_timer2);
2961 clk_enable_nolock(&clk_i2c0);
2962 clk_enable_nolock(&clk_i2c1);
2963 clk_enable_nolock(&clk_gpio0);
2964 clk_enable_nolock(&clk_gpio1);
2965 clk_enable_nolock(&clk_gpio2);
2966 clk_enable_nolock(&clk_efuse);
2968 clk_enable_nolock(&clk_tzpc);
2969 //clk_enable_nolock(&clk_pclk_uart0);
2970 //clk_enable_nolock(&clk_pclk_uart1);
2971 clk_enable_nolock(&clk_pclk_ddrupctl);
2972 clk_enable_nolock(&clk_pclk_ddrpubl);
2973 clk_enable_nolock(&clk_dbg);
2974 clk_enable_nolock(&clk_grf);
2975 clk_enable_nolock(&clk_pmu);
2977 /*************************aclk_periph***********************/
2978 clk_enable_nolock(&clk_dma2);
2979 clk_enable_nolock(&clk_aclk_smc);
2980 clk_enable_nolock(&clk_aclk_peri_niu);
2981 clk_enable_nolock(&clk_aclk_cpu_peri);
2982 clk_enable_nolock(&clk_aclk_peri_axi_matrix);
2984 /*************************hclk_periph***********************/
2985 clk_enable_nolock(&clk_hclk_peri_axi_matrix);
2986 clk_enable_nolock(&clk_hclk_peri_ahb_arbi);
2987 clk_enable_nolock(&clk_hclk_emem_peri);
2988 //clk_enable_nolock(&clk_hclk_mac);
2989 //clk_enable_nolock(&clk_nandc);
2990 clk_enable_nolock(&clk_hclk_usb_peri);
2992 clk_enable_nolock(&clk_hclk_otg0);
2993 clk_enable_nolock(&clk_hclk_otg1);
2994 clk_enable_nolock(&clk_hclk_hsic);
2995 clk_enable_nolock(&clk_hclk_gps);
2996 clk_enable_nolock(&clk_hclk_hsadc);
2997 clk_enable_nolock(&clk_hclk_pidfilter);
2998 clk_enable_nolock(&clk_hclk_sdmmc);
2999 clk_enable_nolock(&clk_hclk_sdio);
3000 clk_enable_nolock(&clk_hclk_emmc);
3003 /*************************pclk_periph***********************/
3004 clk_enable_nolock(&clk_pclk_peri_axi_matrix);
3006 clk_enable_nolock(&clk_pwm23);
3007 clk_enable_nolock(&clk_wdt);
3008 clk_enable_nolock(&clk_pclk_spi0);
3009 clk_enable_nolock(&clk_pclk_spi1);
3010 clk_enable_nolock(&clk_pclk_uart2);
3011 clk_enable_nolock(&clk_pclk_uart3);
3014 clk_enable_nolock(&clk_i2c2);
3015 clk_enable_nolock(&clk_i2c3);
3016 clk_enable_nolock(&clk_i2c4);
3017 clk_enable_nolock(&clk_gpio3);
3018 clk_enable_nolock(&clk_pclk_saradc);
3020 /*************************aclk_lcdc0***********************/
3022 //clk_enable_nolock(&clk_aclk_vio0);
3023 //clk_enable_nolock(&clk_aclk_lcdc0);
3024 //clk_enable_nolock(&clk_aclk_cif0);
3025 //clk_enable_nolock(&clk_aclk_ipp);
3027 /*************************aclk_lcdc1***********************/
3029 //clk_enable_nolock(&clk_aclk_vio1);
3030 //clk_enable_nolock(&clk_aclk_lcdc1);
3031 //clk_enable_nolock(&clk_aclk_rga);
3033 /************************power domain**********************/
3036 static void periph_clk_set_init(void)
3038 unsigned long aclk_p, hclk_p, pclk_p;
3039 unsigned long ppll_rate = general_pll_clk.rate;
3043 switch (ppll_rate) {
3045 aclk_p = 148500 * KHZ;
3046 hclk_p = aclk_p >> 1;
3047 pclk_p = aclk_p >> 2;
3050 aclk_p = aclk_p >> 3; // 0
3051 hclk_p = aclk_p >> 1;
3052 pclk_p = aclk_p >> 2;
3055 aclk_p = ppll_rate >> 1;
3056 hclk_p = aclk_p >> 0;
3057 pclk_p = aclk_p >> 1;
3061 aclk_p = ppll_rate >> 1;
3062 hclk_p = aclk_p >> 0;
3063 pclk_p = aclk_p >> 1;
3066 aclk_p = ppll_rate >> 2;
3067 hclk_p = aclk_p >> 0;
3068 pclk_p = aclk_p >> 1;
3076 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3077 clk_set_rate_nolock(&aclk_periph, aclk_p);
3078 clk_set_rate_nolock(&hclk_periph, hclk_p);
3079 clk_set_rate_nolock(&pclk_periph, pclk_p);
3082 static void cpu_axi_init(void)
3084 unsigned long cpu_div_rate, aclk_cpu_rate, hclk_cpu_rate, pclk_cpu_rate, ahb2apb_cpu_rate;
3085 unsigned long gpll_rate = general_pll_clk.rate;
3087 switch (gpll_rate) {
3089 cpu_div_rate = gpll_rate;
3090 aclk_cpu_rate = cpu_div_rate >> 0;
3091 hclk_cpu_rate = aclk_cpu_rate >> 1;
3092 pclk_cpu_rate = aclk_cpu_rate >> 2;
3096 cpu_div_rate = gpll_rate >> 1;
3097 aclk_cpu_rate = cpu_div_rate >> 0;
3098 hclk_cpu_rate = aclk_cpu_rate >> 1;
3099 pclk_cpu_rate = aclk_cpu_rate >> 2;
3102 aclk_cpu_rate = 150 * MHZ;
3103 hclk_cpu_rate = 150 * MHZ;
3104 pclk_cpu_rate = 75 * MHZ;
3107 ahb2apb_cpu_rate = pclk_cpu_rate;
3109 clk_set_parent_nolock(&clk_cpu_div, &general_pll_clk);
3110 clk_set_rate_nolock(&clk_cpu_div, cpu_div_rate);
3111 clk_set_rate_nolock(&aclk_cpu, aclk_cpu_rate);
3112 clk_set_rate_nolock(&hclk_cpu, hclk_cpu_rate);
3113 clk_set_rate_nolock(&pclk_cpu, pclk_cpu_rate);
3114 clk_set_rate_nolock(&ahb2apb_cpu, ahb2apb_cpu_rate);
3117 void rk30_clock_common_i2s_init(void)
3119 unsigned long i2s_rate;
3121 if(rk30_clock_flags & CLK_FLG_MAX_I2S_49152KHZ) {
3122 i2s_rate = 49152000;
3123 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_24576KHZ) {
3124 i2s_rate = 24576000;
3125 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_22579_2KHZ) {
3126 i2s_rate = 22579000;
3127 } else if(rk30_clock_flags & CLK_FLG_MAX_I2S_12288KHZ) {
3128 i2s_rate = 12288000;
3130 i2s_rate = 49152000;
3133 if(((i2s_rate * 20) <= general_pll_clk.rate) || !(general_pll_clk.rate % i2s_rate)) {
3134 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3135 } else if(((i2s_rate * 20) <= codec_pll_clk.rate) || !(codec_pll_clk.rate % i2s_rate)) {
3136 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3138 if(general_pll_clk.rate > codec_pll_clk.rate)
3139 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3141 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3145 static void __init rk30_clock_common_init(unsigned long gpll_rate, unsigned long cpll_rate)
3149 clk_set_rate_nolock(&general_pll_clk, gpll_rate);
3151 clk_set_rate_nolock(&codec_pll_clk, cpll_rate);
3154 clk_set_rate_nolock(&clk_core, 816 * MHZ);
3156 periph_clk_set_init();
3159 rk30_clock_common_i2s_init();
3162 clk_set_rate_nolock(&clk_spi0, clk_spi0.parent->rate);
3163 clk_set_rate_nolock(&clk_spi1, clk_spi1.parent->rate);
3166 if(rk30_clock_flags & CLK_FLG_UART_1_3M)
3167 clk_set_parent_nolock(&clk_uart_pll, &codec_pll_clk);
3169 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3171 if(!(gpll_rate % (50 * MHZ)))
3172 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3173 else if(!(ddr_pll_clk.rate % (50 * MHZ)))
3174 clk_set_parent_nolock(&clk_mac_pll_div, &ddr_pll_clk);
3176 CLKDATA_ERR("mac can't get 50mhz\n");
3180 //clk_set_parent_nolock(&clk_hsadc_pll_div, &general_pll_clk);
3182 //lcdc0 lcd auto sel pll
3183 clk_set_parent_nolock(&dclk_lcdc0, &general_pll_clk);
3184 clk_set_parent_nolock(&dclk_lcdc1, &general_pll_clk);
3187 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3190 clk_set_parent_nolock(&aclk_lcdc0_pre, &general_pll_clk);
3191 clk_set_parent_nolock(&aclk_lcdc1_pre, &general_pll_clk);
3192 clk_set_rate_nolock(&aclk_lcdc0_pre, 300 * MHZ);
3193 clk_set_rate_nolock(&aclk_lcdc1_pre, 300 * MHZ);
3196 //clk_set_parent_nolock(&aclk_vepu, &general_pll_clk);
3197 //clk_set_parent_nolock(&aclk_vdpu, &general_pll_clk);
3199 clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3200 clk_set_rate_nolock(&aclk_vdpu, 300 * MHZ);
3202 clk_set_parent_nolock(&aclk_gpu, &codec_pll_clk);
3203 clk_set_rate_nolock(&aclk_gpu, 200 * MHZ);
3205 clk_set_rate_nolock(&clk_uart0, 49500000);
3206 clk_set_rate_nolock(&clk_sdmmc, 24750000);
3207 clk_set_rate_nolock(&clk_sdio, 24750000);
3211 static struct clk def_ops_clk = {
3212 .get_parent = clksel_get_parent,
3213 .set_parent = clksel_set_parent,
3216 #ifdef CONFIG_PROC_FS
3217 struct clk_dump_ops dump_ops;
3219 void rk_dump_clock_info(void);
3221 void __init _rk30_clock_data_init(unsigned long gpll, unsigned long cpll, int flags)
3223 struct clk_lookup *lk;
3225 clk_register_dump_ops(&dump_ops);
3226 clk_register_default_ops_clk(&def_ops_clk);
3227 rk30_clock_flags = flags;
3228 for (lk = clks; lk < clks + ARRAY_SIZE(clks); lk++) {
3229 #ifdef RK30_CLK_OFFBOARD_TEST
3230 rk30_clkdev_add(lk);
3234 clk_register(lk->clk);
3236 clk_recalculate_root_clocks_nolock();
3238 loops_per_jiffy = CLK_LOOPS_RECALC(arm_pll_clk.rate);
3241 * Only enable those clocks we will need, let the drivers
3242 * enable other clocks as necessary
3244 rk30_init_enable_clocks();
3246 // print loader config
3247 CLKDATA_DBG("%s clks register dbg start\n", __func__);
3248 rk_dump_clock_info();
3249 rk30_clk_dump_regs();
3251 CLKDATA_DBG("%s clks register dbg end\n", __func__);
3254 * Disable any unused clocks left on by the bootloader
3256 //clk_disable_unused();
3257 rk30_clock_common_init(gpll, cpll);
3258 preset_lpj = loops_per_jiffy;
3261 //regfile_writel(0xc0004000,0x10c);
3262 //cru_writel(0x07000000,CRU_MISC_CON);
3265 extern int rk3188_dvfs_init(void);
3267 void __init rk30_clock_data_init(unsigned long gpll, unsigned long cpll, u32 flags)
3269 _rk30_clock_data_init(gpll, cpll, flags);
3274 * You can override arm_clk rate with armclk= cmdline option.
3276 static int __init armclk_setup(char *str)
3278 get_option(&str, &armclk);
3284 //clk_set_rate_nolock(&arm_pll_clk, armclk);
3287 #ifndef RK30_CLK_OFFBOARD_TEST
3288 early_param("armclk", armclk_setup);
3292 static void rk_dump_clock(struct clk *clk, int deep, const struct list_head *root_clocks)
3296 unsigned long rate = clk->rate;
3297 //CLKDATA_DBG("dump_clock %s\n",clk->name);
3298 for (i = 0; i < deep; i++)
3301 printk("%-11s ", clk->name);
3302 #ifndef RK30_CLK_OFFBOARD_TEST
3303 if (clk->flags & IS_PD) {
3304 printk("%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3307 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3308 int idx = clk->gate_idx;
3310 v = cru_readl(CLK_GATE_CLKID_CONS(idx)) & ((0x1) << (idx % 16));
3311 printk("%s ", v ? "off" : "on ");
3316 u32 pll_id = clk->pll->id;
3317 pll_mode = cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3318 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3320 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3322 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3325 if(cru_readl(PLL_CONS(pll_id, 3)) & PLL_BYPASS)
3327 } else if(clk == &clk_ddr) {
3328 rate = clk->recalc(clk);
3333 printk("%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3335 printk("%ld MHz", rate / MHZ);
3336 } else if (rate >= KHZ) {
3338 printk("%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3340 printk("%ld KHz", rate / KHZ);
3342 printk("%ld Hz", rate);
3345 printk(" usecount = %d", clk->usecount);
3348 printk(" parent = %s", clk->parent->name);
3352 list_for_each_entry(ck, root_clocks, node) {
3353 if (ck->parent == clk)
3354 rk_dump_clock(ck, deep + 1, root_clocks);
3359 struct list_head *get_rk_clocks_head(void);
3361 void rk_dump_clock_info(void)
3364 list_for_each_entry(clk, get_rk_clocks_head(), node) {
3366 rk_dump_clock(clk, 0,get_rk_clocks_head());
3371 #ifdef CONFIG_PROC_FS
3373 static void dump_clock(struct seq_file *s, struct clk *clk, int deep, const struct list_head *root_clocks)
3377 unsigned long rate = clk->rate;
3378 //CLKDATA_DBG("dump_clock %s\n",clk->name);
3379 for (i = 0; i < deep; i++)
3382 seq_printf(s, "%-11s ", clk->name);
3383 #ifndef RK30_CLK_OFFBOARD_TEST
3384 if (clk->flags & IS_PD) {
3385 seq_printf(s, "%s ", pmu_power_domain_is_on(clk->gate_idx) ? "on " : "off");
3388 if ((clk->mode == gate_mode) && (clk->gate_idx < CLK_GATE_MAX)) {
3389 int idx = clk->gate_idx;
3391 v = cru_readl(CLK_GATE_CLKID_CONS(idx)) & ((0x1) << (idx % 16));
3392 seq_printf(s, "%s ", v ? "off" : "on ");
3397 u32 pll_id = clk->pll->id;
3398 pll_mode = cru_readl(CRU_MODE_CON)&PLL_MODE_MSK(pll_id);
3399 if (pll_mode == (PLL_MODE_SLOW(pll_id) & PLL_MODE_MSK(pll_id)))
3400 seq_printf(s, "slow ");
3401 else if (pll_mode == (PLL_MODE_NORM(pll_id) & PLL_MODE_MSK(pll_id)))
3402 seq_printf(s, "normal ");
3403 else if (pll_mode == (PLL_MODE_DEEP(pll_id) & PLL_MODE_MSK(pll_id)))
3404 seq_printf(s, "deep ");
3406 if(cru_readl(PLL_CONS(pll_id, 3)) & PLL_BYPASS)
3407 seq_printf(s, "bypass ");
3408 } else if(clk == &clk_ddr) {
3409 rate = clk->recalc(clk);
3414 seq_printf(s, "%ld.%06ld MHz", rate / MHZ, rate % MHZ);
3416 seq_printf(s, "%ld MHz", rate / MHZ);
3417 } else if (rate >= KHZ) {
3419 seq_printf(s, "%ld.%03ld KHz", rate / KHZ, rate % KHZ);
3421 seq_printf(s, "%ld KHz", rate / KHZ);
3423 seq_printf(s, "%ld Hz", rate);
3426 seq_printf(s, " usecount = %d", clk->usecount);
3429 seq_printf(s, " parent = %s", clk->parent->name);
3431 seq_printf(s, "\n");
3433 list_for_each_entry(ck, root_clocks, node) {
3434 if (ck->parent == clk)
3435 dump_clock(s, ck, deep + 1, root_clocks);
3439 static void dump_regs(struct seq_file *s)
3442 seq_printf(s, "\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3443 seq_printf(s, "\nPLLRegisters:\n");
3444 for(i = 0; i < END_PLL_ID; i++) {
3445 seq_printf(s, "pll%d :cons:%x,%x,%x,%x\n", i,
3446 cru_readl(PLL_CONS(i, 0)),
3447 cru_readl(PLL_CONS(i, 1)),
3448 cru_readl(PLL_CONS(i, 2)),
3449 cru_readl(PLL_CONS(i, 3))
3452 seq_printf(s, "MODE :%x\n", cru_readl(CRU_MODE_CON));
3454 for(i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
3455 seq_printf(s, "CLKSEL%d :%x\n", i, cru_readl(CRU_CLKSELS_CON(i)));
3457 for(i = 0; i < CRU_CLKGATES_CON_CNT; i++) {
3458 seq_printf(s, "CLKGATE%d :%x\n", i, cru_readl(CRU_CLKGATES_CON(i)));
3460 seq_printf(s, "GLB_SRST_FST:%x\n", cru_readl(CRU_GLB_SRST_FST));
3461 seq_printf(s, "GLB_SRST_SND:%x\n", cru_readl(CRU_GLB_SRST_SND));
3463 for(i = 0; i < CRU_SOFTRSTS_CON_CNT; i++) {
3464 seq_printf(s, "CLKGATE%d :%x\n", i, cru_readl(CRU_SOFTRSTS_CON(i)));
3466 seq_printf(s, "CRU MISC :%x\n", cru_readl(CRU_MISC_CON));
3467 seq_printf(s, "GLB_CNT_TH :%x\n", cru_readl(CRU_GLB_CNT_TH));
3471 void rk30_clk_dump_regs(void)
3474 printk("\nPLL(id=0 apll,id=1,dpll,id=2,cpll,id=3 cpll)\n");
3475 printk("\nPLLRegisters:\n");
3476 for(i = 0; i < END_PLL_ID; i++) {
3477 printk("pll%d :cons:%x,%x,%x,%x\n", i,
3478 cru_readl(PLL_CONS(i, 0)),
3479 cru_readl(PLL_CONS(i, 1)),
3480 cru_readl(PLL_CONS(i, 2)),
3481 cru_readl(PLL_CONS(i, 3))
3484 printk("MODE :%x\n", cru_readl(CRU_MODE_CON));
3486 for(i = 0; i < CRU_CLKSELS_CON_CNT; i++) {
3487 printk("CLKSEL%d :%x\n", i, cru_readl(CRU_CLKSELS_CON(i)));
3489 for(i = 0; i < CRU_CLKGATES_CON_CNT; i++) {
3490 printk("CLKGATE%d :%x\n", i, cru_readl(CRU_CLKGATES_CON(i)));
3492 printk("GLB_SRST_FST:%x\n", cru_readl(CRU_GLB_SRST_FST));
3493 printk("GLB_SRST_SND:%x\n", cru_readl(CRU_GLB_SRST_SND));
3495 for(i = 0; i < CRU_SOFTRSTS_CON_CNT; i++) {
3496 printk("SOFTRST%d :%x\n", i, cru_readl(CRU_SOFTRSTS_CON(i)));
3498 printk("CRU MISC :%x\n", cru_readl(CRU_MISC_CON));
3499 printk("GLB_CNT_TH :%x\n", cru_readl(CRU_GLB_CNT_TH));
3504 #ifdef CONFIG_PROC_FS
3505 static void dump_clock(struct seq_file *s, struct clk *clk, int deep, const struct list_head *root_clocks);
3506 struct clk_dump_ops dump_ops = {
3507 .dump_clk = dump_clock,
3508 .dump_regs = dump_regs,
3513 #endif /* CONFIG_PROC_FS */
3518 #ifdef RK30_CLK_OFFBOARD_TEST
3519 struct clk *test_get_parent(struct clk *clk) {
3525 struct clk *i2s_clk = &clk_i2s0;
3527 clk_enable_nolock(i2s_clk);
3529 clk_set_rate_nolock(i2s_clk, 12288000);
3530 printk("int %s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3531 clk_set_rate_nolock(i2s_clk, 297 * MHZ / 2);
3532 printk("int%s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3533 clk_set_rate_nolock(i2s_clk, 12 * MHZ);
3534 printk("int%s parent is %s\n", i2s_clk->name, test_get_parent(i2s_clk)->name);
3538 void uart_test(void)
3540 struct clk *uart_clk = &clk_uart0;
3542 clk_enable_nolock(uart_clk);
3544 clk_set_rate_nolock(uart_clk, 12288000);
3545 printk("int %s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3546 clk_set_rate_nolock(uart_clk, 297 * MHZ / 2);
3547 printk("int%s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3548 clk_set_rate_nolock(uart_clk, 12 * MHZ);
3549 printk("int%s parent is %s\n", uart_clk->name, test_get_parent(uart_clk)->name);
3552 void hsadc_test(void)
3554 struct clk *hsadc_clk = &clk_hsadc;
3556 printk("******************hsadc_test**********************\n");
3557 clk_enable_nolock(hsadc_clk);
3559 clk_set_rate_nolock(hsadc_clk, 12288000);
3560 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3563 clk_set_rate_nolock(hsadc_clk, 297 * MHZ / 2);
3564 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3566 clk_set_rate_nolock(hsadc_clk, 300 * MHZ / 2);
3568 clk_set_rate_nolock(hsadc_clk, 296 * MHZ / 2);
3570 printk("******************hsadc out clock**********************\n");
3572 clk_set_parent_nolock(hsadc_clk, &clk_hsadc_ext);
3573 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3574 clk_set_rate_nolock(hsadc_clk, 297 * MHZ / 2);
3575 printk("****end %s parent is %s\n", hsadc_clk->name, test_get_parent(hsadc_clk)->name);
3581 static void __init rk30_clock_test_init(unsigned long ppll_rate)
3584 printk("*********arm_pll_clk***********\n");
3585 clk_set_rate_nolock(&arm_pll_clk, 816 * MHZ);
3587 printk("*********set clk_core parent***********\n");
3588 clk_set_parent_nolock(&clk_core, &arm_pll_clk);
3589 clk_set_rate_nolock(&clk_core, 504 * MHZ);
3592 printk("*********general_pll_clk***********\n");
3593 clk_set_rate_nolock(&general_pll_clk, ppll_rate);
3596 printk("*********codec_pll_clk***********\n");
3597 clk_set_rate_nolock(&codec_pll_clk, 600 * MHZ);
3600 printk("*********periph_clk_set_init***********\n");
3601 clk_set_parent_nolock(&aclk_periph, &general_pll_clk);
3602 periph_clk_set_init();
3605 clk_set_parent_nolock(&clk_i2s_pll, &codec_pll_clk);
3607 printk("*********clk i2s***********\n");
3608 clk_set_parent_nolock(&clk_i2s_pll, &general_pll_clk);
3609 printk("common %s parent is %s\n", clk_i2s_pll.name, test_get_parent(&clk_i2s_pll)->name);
3613 clk_enable_nolock(&clk_spi0);
3614 clk_set_rate_nolock(&clk_spi0, 30 * MHZ);
3615 printk("common %s parent is %s\n", clk_spi0.name, test_get_parent(&clk_spi0)->name);
3617 clk_enable_nolock(&clk_saradc);
3618 clk_set_rate_nolock(&clk_saradc, 6 * MHZ);
3619 printk("common %s parent is %s\n", clk_saradc.name, test_get_parent(&clk_saradc)->name);
3621 clk_enable_nolock(&clk_sdio);
3622 clk_set_rate_nolock(&clk_sdio, 50 * MHZ);
3623 printk("common %s parent is %s\n", clk_sdio.name, test_get_parent(&clk_sdio)->name);
3625 clk_set_parent_nolock(&clk_uart_pll, &general_pll_clk);
3628 printk("*********mac***********\n");
3630 clk_set_parent_nolock(&clk_mac_pll_div, &general_pll_clk);
3631 printk("common %s parent is %s\n", clk_mac_pll_div.name, test_get_parent(&clk_mac_pll_div)->name);
3633 //clk_set_parent_nolock(&clk_mac_ref, &clk_mac_pll_div);
3634 clk_set_rate_nolock(&clk_mac_ref, 50 * MHZ);
3635 printk("common %s parent is %s\n", clk_mac_ref.name, test_get_parent(&clk_mac_ref)->name);
3637 printk("*********mac mii set***********\n");
3638 clk_set_parent_nolock(&clk_mac_ref, &rmii_clkin);
3639 clk_set_rate_nolock(&clk_mac_ref, 20 * MHZ);
3640 printk("common %s parent is %s\n", clk_mac_ref.name, test_get_parent(&clk_mac_ref)->name);
3642 printk("*********hsadc 1***********\n");
3646 clk_enable_nolock(&dclk_lcdc0);
3648 clk_set_rate_nolock(&dclk_lcdc0, 60 * MHZ);
3649 clk_set_rate_nolock(&dclk_lcdc0, 27 * MHZ);
3652 clk_enable_nolock(&cif0_out);
3654 clk_set_parent_nolock(&cif_out_pll, &general_pll_clk);
3655 printk("common %s parent is %s\n", cif_out_pll.name, test_get_parent(&cif_out_pll)->name);
3657 clk_set_rate_nolock(&cif0_out, 60 * MHZ);
3658 printk("common %s parent is %s\n", cif0_out.name, test_get_parent(&cif0_out)->name);
3660 clk_set_rate_nolock(&cif0_out, 24 * MHZ);
3661 printk("common %s parent is %s\n", cif0_out.name, test_get_parent(&cif0_out)->name);
3663 clk_enable_nolock(&cif0_in);
3664 clk_set_rate_nolock(&cif0_in, 24 * MHZ);
3666 clk_enable_nolock(&aclk_lcdc0);
3667 clk_set_rate_nolock(&aclk_lcdc0, 150 * MHZ);
3668 printk("common %s parent is %s\n", aclk_lcdc0.name, test_get_parent(&aclk_lcdc0)->name);
3670 clk_enable_nolock(&aclk_vepu);
3671 clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3672 printk("common %s parent is %s\n", aclk_vepu.name, test_get_parent(&aclk_vepu)->name);
3674 clk_set_rate_nolock(&hclk_vepu, 300 * MHZ);
3675 printk("common %s parent is %s\n", hclk_vepu.name, test_get_parent(&hclk_vepu)->name);
3677 printk("test end\n");
3680 clk_set_rate_nolock(&arm_pll_clk, armclk);
3681 clk_set_rate_nolock(&clk_core, armclk);//pll:core =1:1
3684 //clk_set_rate_nolock(&codec_pll_clk, ppll_rate*2);
3686 //clk_set_rate_nolock(&aclk_vepu, 300 * MHZ);
3687 //clk_set_rate_nolock(&clk_gpu, 300 * MHZ);
3695 static LIST_HEAD(rk30_clocks);
3696 static DEFINE_MUTEX(rk30_clocks_mutex);
3698 static inline int __rk30clk_get(struct clk *clk)
3702 void rk30_clkdev_add(struct clk_lookup *cl)
3704 mutex_lock(&rk30_clocks_mutex);
3705 list_add_tail(&cl->node, &rk30_clocks);
3706 mutex_unlock(&rk30_clocks_mutex);
3708 static struct clk_lookup *rk30_clk_find(const char *dev_id, const char *con_id) {
3709 struct clk_lookup *p, *cl = NULL;
3710 int match, best = 0;
3712 list_for_each_entry(p, &rk30_clocks, node) {
3715 if (!dev_id || strcmp(p->dev_id, dev_id))
3720 if (!con_id || strcmp(p->con_id, con_id))
3736 struct clk *rk30_clk_get_sys(const char *dev_id, const char *con_id) {
3737 struct clk_lookup *cl;
3739 mutex_lock(&rk30_clocks_mutex);
3740 cl = rk30_clk_find(dev_id, con_id);
3741 if (cl && !__rk30clk_get(cl->clk))
3743 mutex_unlock(&rk30_clocks_mutex);
3745 return cl ? cl->clk : ERR_PTR(-ENOENT);
3747 //EXPORT_SYMBOL(rk30_clk_get_sys);
3749 struct clk *rk30_clk_get(struct device *dev, const char *con_id) {
3750 const char *dev_id = dev ? dev_name(dev) : NULL;
3751 return rk30_clk_get_sys(dev_id, con_id);
3753 //EXPORT_SYMBOL(rk30_clk_get);
3756 int rk30_clk_set_rate(struct clk *clk, unsigned long rate);
3758 void rk30_clocks_test(void)
3760 struct clk *test_gpll;
3761 test_gpll = rk30_clk_get(NULL, "general_pll");
3763 rk30_clk_set_rate(test_gpll, 297 * 2 * MHZ);
3764 printk("gpll rate=%lu\n", test_gpll->rate);
3769 void __init rk30_clock_init_test(void)
3772 rk30_clock_init(periph_pll_297mhz, codec_pll_360mhz, max_i2s_12288khz);