1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <commonlib/bsd/gcd.h>
5 #include <console/console.h>
7 #include <device/mmio.h>
9 #include <soc/addressmap.h>
10 #include <soc/clock.h>
22 struct rk3288_cru_reg
{
30 u32 cru_clksel_con
[43];
32 u32 cru_clkgate_con
[19];
34 u32 cru_glb_srst_fst_value
;
35 u32 cru_glb_srst_snd_value
;
36 u32 cru_softrst_con
[12];
48 check_member(rk3288_cru_reg
, cru_emmc_con
[1], 0x021c);
50 static struct rk3288_cru_reg
* const cru_ptr
= (void *)CRU_BASE
;
52 #define PLL_DIVISORS(hz, _nr, _no) {\
53 .nr = _nr, .nf = (u32)((u64)hz * _nr * _no / OSC_HZ), .no = _no};\
54 _Static_assert(((u64)hz * _nr * _no / OSC_HZ) * OSC_HZ /\
55 (_nr * _no) == hz, #hz "Hz cannot be hit with PLL "\
56 "divisors on line " STRINGIFY(__LINE__))
58 /* Keep divisors as low as possible to reduce jitter and power usage. */
59 static const struct pll_div gpll_init_cfg
= PLL_DIVISORS(GPLL_HZ
, 2, 2);
60 static const struct pll_div cpll_init_cfg
= PLL_DIVISORS(CPLL_HZ
, 1, 2);
62 /* See linux/drivers/clk/rockchip/clk-rk3288.c for more APLL combinations */
63 static const struct pll_div apll_1800_cfg
= PLL_DIVISORS(1800*MHz
, 1, 1);
64 static const struct pll_div apll_1416_cfg
= PLL_DIVISORS(1416*MHz
, 1, 1);
65 static const struct pll_div apll_600_cfg
= PLL_DIVISORS(600*MHz
, 1, 2);
66 static const struct pll_div
*apll_cfgs
[] = {
67 [APLL_1800_MHZ
] = &apll_1800_cfg
,
68 [APLL_1416_MHZ
] = &apll_1416_cfg
,
69 [APLL_600_MHZ
] = &apll_600_cfg
,
72 /*******************PLL CON0 BITS***************************/
73 #define PLL_OD_MSK (0x0F)
75 #define PLL_NR_MSK (0x3F << 8)
76 #define PLL_NR_SHIFT (8)
78 /*******************PLL CON1 BITS***************************/
79 #define PLL_NF_MSK (0x1FFF)
81 /*******************PLL CON2 BITS***************************/
82 #define PLL_BWADJ_MSK (0x0FFF)
84 /*******************PLL CON3 BITS***************************/
85 #define PLL_RESET_MSK (1 << 5)
86 #define PLL_RESET (1 << 5)
87 #define PLL_RESET_RESUME (0 << 5)
89 /*******************CLKSEL0 BITS***************************/
90 /* core clk pll sel: amr or general */
91 #define CORE_SEL_PLL_MSK (1 << 15)
92 #define CORE_SEL_APLL (0 << 15)
93 #define CORE_SEL_GPLL (1 << 15)
95 /* a12 core clock div: clk_core = clk_src / (div_con + 1) */
96 #define A12_DIV_SHIFT (8)
97 #define A12_DIV_MSK (0x1F << 8)
99 /* mp core axi clock div: clk = clk_src / (div_con + 1) */
100 #define MP_DIV_SHIFT (4)
101 #define MP_DIV_MSK (0xF << 4)
103 /* m0 core axi clock div: clk = clk_src / (div_con + 1) */
104 #define M0_DIV_MSK (0xF)
106 /*******************CLKSEL1 BITS***************************/
107 /* pd bus clk pll sel: codec or general */
108 #define PD_BUS_SEL_PLL_MSK (1 << 15)
109 #define PD_BUS_SEL_CPLL (0 << 15)
110 #define PD_BUS_SEL_GPLL (1 << 15)
113 * pclk = pd_bus_aclk /(div + 1)
115 #define PD_BUS_PCLK_DIV_SHIFT (12)
116 #define PD_BUS_PCLK_DIV_MSK (0x7 << 12)
119 * aclk_bus: hclk_bus = 1:1 or 2:1 or 4:1
121 #define PD_BUS_HCLK_DIV_SHIFT (8)
122 #define PD_BUS_HCLK_DIV_MSK (0x3 << 8)
125 * pd_bus_aclk = pd_bus_src_clk /(div0 * div1)
127 #define PD_BUS_ACLK_DIV0_SHIFT (3)
128 #define PD_BUS_ACLK_DIV0_MASK (0x1f << 3)
129 #define PD_BUS_ACLK_DIV1_SHIFT (0)
130 #define PD_BUS_ACLK_DIV1_MASK (0x7 << 0)
132 /*******************CLKSEL10 BITS***************************/
133 /* peripheral bus clk pll sel: codec or general */
134 #define PERI_SEL_PLL_MSK (1 << 15)
135 #define PERI_SEL_CPLL (0 << 15)
136 #define PERI_SEL_GPLL (1 << 15)
138 /* peripheral bus pclk div:
139 * aclk_bus: pclk_bus = 1:1 or 2:1 or 4:1 or 8:1
141 #define PERI_PCLK_DIV_SHIFT (12)
142 #define PERI_PCLK_DIV_MSK (0x7 << 12)
144 /* peripheral bus hclk div:
145 * aclk_bus: hclk_bus = 1:1 or 2:1 or 4:1
147 #define PERI_HCLK_DIV_SHIFT (8)
148 #define PERI_HCLK_DIV_MSK (0x3 << 8)
150 /* peripheral bus aclk div:
152 * periph_clk_src / (peri_aclk_div_con + 1)
154 #define PERI_ACLK_DIV_SHIFT (0x0)
155 #define PERI_ACLK_DIV_MSK (0x1F)
157 /*******************CLKSEL37 BITS***************************/
158 #define L2_DIV_MSK (0x7)
160 #define ATCLK_DIV_MSK (0x1F << 4)
161 #define ATCLK_DIV_SHIFT (4)
163 #define PCLK_DBG_DIV_MSK (0x1F << 9)
164 #define PCLK_DBG_DIV_SHIFT (9)
166 #define APLL_MODE_MSK (0x3)
167 #define APLL_MODE_SLOW (0)
168 #define APLL_MODE_NORM (1)
170 #define DPLL_MODE_MSK (0x3 << 4)
171 #define DPLL_MODE_SLOW (0 << 4)
172 #define DPLL_MODE_NORM (1 << 4)
174 #define CPLL_MODE_MSK (0x3 << 8)
175 #define CPLL_MODE_SLOW (0 << 8)
176 #define CPLL_MODE_NORM (1 << 8)
178 #define GPLL_MODE_MSK (0x3 << 12)
179 #define GPLL_MODE_SLOW (0 << 12)
180 #define GPLL_MODE_NORM (1 << 12)
182 #define NPLL_MODE_MSK (0x3 << 14)
183 #define NPLL_MODE_SLOW (0 << 14)
184 #define NPLL_MODE_NORM (1 << 14)
186 #define SOCSTS_DPLL_LOCK (1 << 5)
187 #define SOCSTS_APLL_LOCK (1 << 6)
188 #define SOCSTS_CPLL_LOCK (1 << 7)
189 #define SOCSTS_GPLL_LOCK (1 << 8)
190 #define SOCSTS_NPLL_LOCK (1 << 9)
192 #define VCO_MAX_KHZ (2200 * (MHz/KHz))
193 #define VCO_MIN_KHZ (440 * (MHz/KHz))
194 #define OUTPUT_MAX_KHZ (2200 * (MHz/KHz))
195 #define OUTPUT_MIN_KHZ 27500
196 #define FREF_MAX_KHZ (2200 * (MHz/KHz))
197 #define FREF_MIN_KHZ 269
199 static int rkclk_set_pll(u32
*pll_con
, const struct pll_div
*div
)
201 /* All PLLs have same VCO and output frequency range restrictions. */
202 u32 vco_khz
= OSC_HZ
/KHz
* div
->nf
/ div
->nr
;
203 u32 output_khz
= vco_khz
/ div
->no
;
205 printk(BIOS_DEBUG
, "Configuring PLL at %p with NF = %d, NR = %d and "
206 "NO = %d (VCO = %uKHz, output = %uKHz)\n",
207 pll_con
, div
->nf
, div
->nr
, div
->no
, vco_khz
, output_khz
);
208 assert(vco_khz
>= VCO_MIN_KHZ
&& vco_khz
<= VCO_MAX_KHZ
&&
209 output_khz
>= OUTPUT_MIN_KHZ
&& output_khz
<= OUTPUT_MAX_KHZ
&&
210 (div
->no
== 1 || !(div
->no
% 2)));
213 write32(&pll_con
[3], RK_SETBITS(PLL_RESET_MSK
));
216 RK_CLRSETBITS(PLL_NR_MSK
, (div
->nr
- 1) << PLL_NR_SHIFT
) |
217 RK_CLRSETBITS(PLL_OD_MSK
, (div
->no
- 1)));
219 write32(&pll_con
[1], RK_CLRSETBITS(PLL_NF_MSK
, (div
->nf
- 1)));
222 RK_CLRSETBITS(PLL_BWADJ_MSK
, ((div
->nf
>> 1) - 1)));
226 /* return form rest */
227 write32(&pll_con
[3], RK_CLRBITS(PLL_RESET_MSK
));
232 void rkclk_init(void)
238 /* pll enter slow-mode */
239 write32(&cru_ptr
->cru_mode_con
,
240 RK_CLRSETBITS(GPLL_MODE_MSK
, GPLL_MODE_SLOW
) |
241 RK_CLRSETBITS(CPLL_MODE_MSK
, CPLL_MODE_SLOW
));
244 rkclk_set_pll(&cru_ptr
->cru_gpll_con
[0], &gpll_init_cfg
);
245 rkclk_set_pll(&cru_ptr
->cru_cpll_con
[0], &cpll_init_cfg
);
247 /* waiting for pll lock */
249 if ((read32(&rk3288_grf
->soc_status
[1])
250 & (SOCSTS_CPLL_LOCK
| SOCSTS_GPLL_LOCK
))
251 == (SOCSTS_CPLL_LOCK
| SOCSTS_GPLL_LOCK
))
257 * pd_bus clock pll source selection and
258 * set up dependent divisors for PCLK/HCLK and ACLK clocks.
260 aclk_div
= GPLL_HZ
/ PD_BUS_ACLK_HZ
- 1;
261 assert((aclk_div
+ 1) * PD_BUS_ACLK_HZ
== GPLL_HZ
&& aclk_div
<= 0x1f);
262 hclk_div
= PD_BUS_ACLK_HZ
/ PD_BUS_HCLK_HZ
- 1;
263 assert((hclk_div
+ 1) * PD_BUS_HCLK_HZ
==
264 PD_BUS_ACLK_HZ
&& (hclk_div
<= 0x3) && (hclk_div
!= 0x2));
266 pclk_div
= PD_BUS_ACLK_HZ
/ PD_BUS_PCLK_HZ
- 1;
267 assert((pclk_div
+ 1) * PD_BUS_PCLK_HZ
==
268 PD_BUS_ACLK_HZ
&& pclk_div
<= 0x7);
270 write32(&cru_ptr
->cru_clksel_con
[1], RK_SETBITS(PD_BUS_SEL_GPLL
) |
271 RK_CLRSETBITS(PD_BUS_PCLK_DIV_MSK
,
272 pclk_div
<< PD_BUS_PCLK_DIV_SHIFT
) |
273 RK_CLRSETBITS(PD_BUS_HCLK_DIV_MSK
,
274 hclk_div
<< PD_BUS_HCLK_DIV_SHIFT
) |
275 RK_CLRSETBITS(PD_BUS_ACLK_DIV0_MASK
,
276 aclk_div
<< PD_BUS_ACLK_DIV0_SHIFT
) |
277 RK_CLRSETBITS(PD_BUS_ACLK_DIV1_MASK
, 0 << 0));
280 * peri clock pll source selection and
281 * set up dependent divisors for PCLK/HCLK and ACLK clocks.
283 aclk_div
= GPLL_HZ
/ PERI_ACLK_HZ
- 1;
284 assert((aclk_div
+ 1) * PERI_ACLK_HZ
== GPLL_HZ
&& aclk_div
<= 0x1f);
286 hclk_div
= log2(PERI_ACLK_HZ
/ PERI_HCLK_HZ
);
287 assert((1 << hclk_div
) * PERI_HCLK_HZ
==
288 PERI_ACLK_HZ
&& (hclk_div
<= 0x2));
290 pclk_div
= log2(PERI_ACLK_HZ
/ PERI_PCLK_HZ
);
291 assert((1 << pclk_div
) * PERI_PCLK_HZ
==
292 PERI_ACLK_HZ
&& (pclk_div
<= 0x3));
294 write32(&cru_ptr
->cru_clksel_con
[10], RK_SETBITS(PERI_SEL_GPLL
) |
295 RK_CLRSETBITS(PERI_PCLK_DIV_MSK
,
296 pclk_div
<< PERI_PCLK_DIV_SHIFT
) |
297 RK_CLRSETBITS(PERI_HCLK_DIV_MSK
,
298 hclk_div
<< PERI_HCLK_DIV_SHIFT
) |
299 RK_CLRSETBITS(PERI_ACLK_DIV_MSK
,
300 aclk_div
<< PERI_ACLK_DIV_SHIFT
));
302 /* PLL enter normal-mode */
303 write32(&cru_ptr
->cru_mode_con
,
304 RK_CLRSETBITS(GPLL_MODE_MSK
, GPLL_MODE_NORM
) |
305 RK_CLRSETBITS(CPLL_MODE_MSK
, CPLL_MODE_NORM
));
308 void rkclk_configure_cpu(enum apll_frequencies apll_freq
)
310 /* pll enter slow-mode */
311 write32(&cru_ptr
->cru_mode_con
,
312 RK_CLRSETBITS(APLL_MODE_MSK
, APLL_MODE_SLOW
));
314 rkclk_set_pll(&cru_ptr
->cru_apll_con
[0], apll_cfgs
[apll_freq
]);
316 /* waiting for pll lock */
318 if (read32(&rk3288_grf
->soc_status
[1]) & SOCSTS_APLL_LOCK
)
324 * core clock pll source selection and
325 * set up dependent divisors for MPAXI/M0AXI and ARM clocks.
326 * core clock select apll, apll clk = 1800MHz
327 * arm clk = 1800MHz, mpclk = 450MHz, m0clk = 900MHz
329 write32(&cru_ptr
->cru_clksel_con
[0], RK_CLRBITS(CORE_SEL_PLL_MSK
) |
330 RK_CLRSETBITS(A12_DIV_MSK
, 0 << A12_DIV_SHIFT
) |
331 RK_CLRSETBITS(MP_DIV_MSK
, 3 << MP_DIV_SHIFT
) |
332 RK_CLRSETBITS(M0_DIV_MSK
, 1 << 0));
335 * set up dependent divisors for L2RAM/ATCLK and PCLK clocks.
336 * l2ramclk = 900MHz, atclk = 450MHz, pclk_dbg = 450MHz
338 write32(&cru_ptr
->cru_clksel_con
[37],
339 RK_CLRSETBITS(L2_DIV_MSK
, 1 << 0) |
340 RK_CLRSETBITS(ATCLK_DIV_MSK
, (3 << ATCLK_DIV_SHIFT
)) |
341 RK_CLRSETBITS(PCLK_DBG_DIV_MSK
, (3 << PCLK_DBG_DIV_SHIFT
)));
343 /* PLL enter normal-mode */
344 write32(&cru_ptr
->cru_mode_con
,
345 RK_CLRSETBITS(APLL_MODE_MSK
, APLL_MODE_NORM
));
348 void rkclk_configure_ddr(unsigned int hz
)
350 struct pll_div dpll_cfg
;
354 dpll_cfg
= (struct pll_div
){.nf
= 50, .nr
= 2, .no
= 2};
356 case 533*MHz
: /* actually 533.3P MHz */
357 dpll_cfg
= (struct pll_div
){.nf
= 400, .nr
= 9, .no
= 2};
359 case 666*MHz
: /* actually 666.6P MHz */
360 dpll_cfg
= (struct pll_div
){.nf
= 500, .nr
= 9, .no
= 2};
363 dpll_cfg
= (struct pll_div
){.nf
= 100, .nr
= 3, .no
= 1};
366 die("Unsupported SDRAM frequency, add to clock.c!");
369 /* pll enter slow-mode */
370 write32(&cru_ptr
->cru_mode_con
,
371 RK_CLRSETBITS(DPLL_MODE_MSK
, DPLL_MODE_SLOW
));
373 rkclk_set_pll(&cru_ptr
->cru_dpll_con
[0], &dpll_cfg
);
375 /* waiting for pll lock */
377 if (read32(&rk3288_grf
->soc_status
[1]) & SOCSTS_DPLL_LOCK
)
382 /* PLL enter normal-mode */
383 write32(&cru_ptr
->cru_mode_con
,
384 RK_CLRSETBITS(DPLL_MODE_MSK
, DPLL_MODE_NORM
));
387 void rkclk_ddr_reset(u32 ch
, u32 ctl
, u32 phy
)
389 u32 phy_ctl_srstn_shift
= 4 + 5 * ch
;
390 u32 ctl_psrstn_shift
= 3 + 5 * ch
;
391 u32 ctl_srstn_shift
= 2 + 5 * ch
;
392 u32 phy_psrstn_shift
= 1 + 5 * ch
;
393 u32 phy_srstn_shift
= 5 * ch
;
395 write32(&cru_ptr
->cru_softrst_con
[10],
396 RK_CLRSETBITS(1 << phy_ctl_srstn_shift
,
397 phy
<< phy_ctl_srstn_shift
) |
398 RK_CLRSETBITS(1 << ctl_psrstn_shift
, ctl
<< ctl_psrstn_shift
) |
399 RK_CLRSETBITS(1 << ctl_srstn_shift
, ctl
<< ctl_srstn_shift
) |
400 RK_CLRSETBITS(1 << phy_psrstn_shift
, phy
<< phy_psrstn_shift
) |
401 RK_CLRSETBITS(1 << phy_srstn_shift
, phy
<< phy_srstn_shift
));
404 void rkclk_ddr_phy_ctl_reset(u32 ch
, u32 n
)
406 u32 phy_ctl_srstn_shift
= 4 + 5 * ch
;
408 write32(&cru_ptr
->cru_softrst_con
[10],
409 RK_CLRSETBITS(1 << phy_ctl_srstn_shift
,
410 n
<< phy_ctl_srstn_shift
));
413 void rkclk_configure_spi(unsigned int bus
, unsigned int hz
)
415 int src_clk_div
= GPLL_HZ
/ hz
;
417 assert((src_clk_div
- 1 <= 127) && (src_clk_div
* hz
== GPLL_HZ
));
419 switch (bus
) { /*select gpll as spi src clk, and set div*/
421 write32(&cru_ptr
->cru_clksel_con
[25],
422 RK_CLRSETBITS(1 << 7 | 0x1f << 0,
423 1 << 7 | (src_clk_div
- 1) << 0));
426 write32(&cru_ptr
->cru_clksel_con
[25],
427 RK_CLRSETBITS(1 << 15 | 0x1f << 8,
428 1 << 15 | (src_clk_div
- 1) << 8));
431 write32(&cru_ptr
->cru_clksel_con
[39],
432 RK_CLRSETBITS(1 << 7 | 0x1f << 0,
433 1 << 7 | (src_clk_div
- 1) << 0));
436 printk(BIOS_ERR
, "do not support this spi bus\n");
440 void rkclk_configure_i2s(unsigned int hz
)
445 /* i2s source clock: gpll
446 i2s0_outclk_sel: clk_i2s
447 i2s0_clk_sel: divider output from fraction
448 i2s0_pll_div_con: 0*/
449 write32(&cru_ptr
->cru_clksel_con
[4],
450 RK_CLRSETBITS(1 << 15 | 1 << 12 | 3 << 8 | 0x7f << 0,
451 1 << 15 | 0 << 12 | 1 << 8 | 0 << 0));
453 /* set frac divider */
454 v
= gcd(GPLL_HZ
, hz
);
455 n
= (GPLL_HZ
/ v
) & (0xffff);
456 d
= (hz
/ v
) & (0xffff);
457 assert(hz
== GPLL_HZ
/ n
* d
);
458 write32(&cru_ptr
->cru_clksel_con
[8], d
<< 16 | n
);
461 void rkclk_configure_crypto(unsigned int hz
)
463 u32 div
= PD_BUS_ACLK_HZ
/ hz
;
465 assert((div
- 1 <= 3) && (div
* hz
== PD_BUS_ACLK_HZ
));
466 assert(hz
<= 150*MHz
); /* Suggested max in TRM. */
467 write32(&cru_ptr
->cru_clksel_con
[26],
468 RK_CLRSETBITS(0x3 << 6, (div
- 1) << 6));
471 void rkclk_configure_tsadc(unsigned int hz
)
474 u32 src_clk
= 32 * KHz
; /* tsadc source clock is 32KHz*/
477 assert((div
- 1 <= 63) && (div
* hz
== 32 * KHz
));
478 write32(&cru_ptr
->cru_clksel_con
[2],
479 RK_CLRSETBITS(0x3f << 0, (div
- 1) << 0));
482 static int pll_para_config(u32 freq_hz
, struct pll_div
*div
, u32
*ext_div
)
484 u32 ref_khz
= OSC_HZ
/ KHz
, nr
, nf
= 0;
486 u32 diff_khz
, best_diff_khz
;
487 const u32 max_nr
= 1 << 6, max_nf
= 1 << 12, max_no
= 1 << 4;
490 u32 freq_khz
= freq_hz
/ KHz
;
493 printk(BIOS_ERR
, "%s: the frequency can not be 0 Hz\n", __func__
);
497 no
= DIV_ROUND_UP(VCO_MIN_KHZ
, freq_khz
);
499 *ext_div
= DIV_ROUND_UP(no
, max_no
);
500 no
= DIV_ROUND_UP(no
, *ext_div
);
503 /* only even divisors (and 1) are supported */
505 no
= DIV_ROUND_UP(no
, 2) * 2;
507 vco_khz
= freq_khz
* no
;
511 if (vco_khz
< VCO_MIN_KHZ
|| vco_khz
> VCO_MAX_KHZ
|| no
> max_no
) {
512 printk(BIOS_ERR
, "%s: Cannot find out a supported VCO"
513 " for Frequency (%uHz).\n", __func__
, freq_hz
);
519 best_diff_khz
= vco_khz
;
520 for (nr
= 1; nr
< max_nr
&& best_diff_khz
; nr
++) {
521 fref_khz
= ref_khz
/ nr
;
522 if (fref_khz
< FREF_MIN_KHZ
)
524 if (fref_khz
> FREF_MAX_KHZ
)
527 nf
= vco_khz
/ fref_khz
;
530 diff_khz
= vco_khz
- nf
* fref_khz
;
531 if (nf
+ 1 < max_nf
&& diff_khz
> fref_khz
/ 2) {
533 diff_khz
= fref_khz
- diff_khz
;
536 if (diff_khz
>= best_diff_khz
)
539 best_diff_khz
= diff_khz
;
544 if (best_diff_khz
> 4 * (MHz
/KHz
)) {
545 printk(BIOS_ERR
, "%s: Failed to match output frequency %u, "
546 "difference is %u Hz,exceed 4MHZ\n", __func__
, freq_hz
,
547 best_diff_khz
* KHz
);
554 void rkclk_configure_edp(void)
556 /* clk_edp_24M source: 24M */
557 write32(&cru_ptr
->cru_clksel_con
[28], RK_SETBITS(1 << 15));
560 write32(&cru_ptr
->cru_softrst_con
[6], RK_SETBITS(1 << 15));
562 write32(&cru_ptr
->cru_softrst_con
[6], RK_CLRBITS(1 << 15));
565 void rkclk_configure_hdmi(void)
567 /* enable pclk hdmi ctrl */
568 write32(&cru_ptr
->cru_clkgate_con
[16], RK_CLRBITS(1 << 9));
570 /* software reset hdmi */
571 write32(&cru_ptr
->cru_softrst_con
[7], RK_SETBITS(1 << 9));
573 write32(&cru_ptr
->cru_softrst_con
[7], RK_CLRBITS(1 << 9));
576 void rkclk_configure_vop_aclk(u32 vop_id
, u32 aclk_hz
)
580 /* vop aclk source clk: cpll */
581 div
= CPLL_HZ
/ aclk_hz
;
582 assert((div
- 1 <= 63) && (div
* aclk_hz
== CPLL_HZ
));
586 write32(&cru_ptr
->cru_clksel_con
[31],
587 RK_CLRSETBITS(3 << 6 | 0x1f << 0,
588 0 << 6 | (div
- 1) << 0));
592 write32(&cru_ptr
->cru_clksel_con
[31],
593 RK_CLRSETBITS(3 << 14 | 0x1f << 8,
594 0 << 14 | (div
- 1) << 8));
599 int rkclk_configure_vop_dclk(u32 vop_id
, u32 dclk_hz
)
601 struct pll_div npll_config
= {0};
604 if (pll_para_config(dclk_hz
, &npll_config
, &lcdc_div
))
607 /* npll enter slow-mode */
608 write32(&cru_ptr
->cru_mode_con
,
609 RK_CLRSETBITS(NPLL_MODE_MSK
, NPLL_MODE_SLOW
));
611 rkclk_set_pll(&cru_ptr
->cru_npll_con
[0], &npll_config
);
613 /* waiting for pll lock */
615 if (read32(&rk3288_grf
->soc_status
[1]) & SOCSTS_NPLL_LOCK
)
620 /* npll enter normal-mode */
621 write32(&cru_ptr
->cru_mode_con
,
622 RK_CLRSETBITS(NPLL_MODE_MSK
, NPLL_MODE_NORM
));
624 /* vop dclk source clk: npll,dclk_div: 1 */
627 write32(&cru_ptr
->cru_clksel_con
[27],
628 RK_CLRSETBITS(0xff << 8 | 3 << 0,
629 (lcdc_div
- 1) << 8 | 2 << 0));
633 write32(&cru_ptr
->cru_clksel_con
[29],
634 RK_CLRSETBITS(0xff << 8 | 3 << 6,
635 (lcdc_div
- 1) << 8 | 2 << 6));
641 int rkclk_was_watchdog_reset(void)
643 /* Bits 5 and 4 are "second" and "first" global watchdog reset. */
644 return read32(&cru_ptr
->cru_glb_rst_st
) & 0x30;
647 unsigned int rkclk_i2c_clock_for_bus(unsigned int bus
)
649 /*i2c0,i2c2 src clk from pd_bus_pclk
650 other i2c src clk from peri_pclk
655 return PD_BUS_PCLK_HZ
;
664 return -1; /* Should never happen. */