coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
clock.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <assert.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <lib.h>
8 #include <soc/addressmap.h>
9 #include <soc/clock.h>
10 #include <soc/grf.h>
11 #include <soc/i2c.h>
12 #include <soc/soc.h>
13 #include <stdint.h>
14 #include <string.h>
15 
16 struct pll_div {
20 };
21 
47 };
48 check_member(rk3288_cru_reg, cru_emmc_con[1], 0x021c);
49 
50 static struct rk3288_cru_reg * const cru_ptr = (void *)CRU_BASE;
51 
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__));
57 
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);
61 
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[] = {
70 };
71 
72 /*******************PLL CON0 BITS***************************/
73 #define PLL_OD_MSK (0x0F)
74 
75 #define PLL_NR_MSK (0x3F << 8)
76 #define PLL_NR_SHIFT (8)
77 
78 /*******************PLL CON1 BITS***************************/
79 #define PLL_NF_MSK (0x1FFF)
80 
81 /*******************PLL CON2 BITS***************************/
82 #define PLL_BWADJ_MSK (0x0FFF)
83 
84 /*******************PLL CON3 BITS***************************/
85 #define PLL_RESET_MSK (1 << 5)
86 #define PLL_RESET (1 << 5)
87 #define PLL_RESET_RESUME (0 << 5)
88 
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)
94 
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)
98 
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)
102 
103 /* m0 core axi clock div: clk = clk_src / (div_con + 1) */
104 #define M0_DIV_MSK (0xF)
105 
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)
111 
112 /* pd bus pclk div:
113  * pclk = pd_bus_aclk /(div + 1)
114  */
115 #define PD_BUS_PCLK_DIV_SHIFT (12)
116 #define PD_BUS_PCLK_DIV_MSK (0x7 << 12)
117 
118 /* pd bus hclk div:
119  * aclk_bus: hclk_bus = 1:1 or 2:1 or 4:1
120  */
121 #define PD_BUS_HCLK_DIV_SHIFT (8)
122 #define PD_BUS_HCLK_DIV_MSK (0x3 << 8)
123 
124 /* pd bus aclk div:
125  * pd_bus_aclk = pd_bus_src_clk /(div0 * div1)
126  */
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)
131 
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)
137 
138 /* peripheral bus pclk div:
139  * aclk_bus: pclk_bus = 1:1 or 2:1 or 4:1 or 8:1
140  */
141 #define PERI_PCLK_DIV_SHIFT (12)
142 #define PERI_PCLK_DIV_MSK (0x7 << 12)
143 
144 /* peripheral bus hclk div:
145  * aclk_bus: hclk_bus = 1:1 or 2:1 or 4:1
146  */
147 #define PERI_HCLK_DIV_SHIFT (8)
148 #define PERI_HCLK_DIV_MSK (0x3 << 8)
149 
150 /* peripheral bus aclk div:
151  * aclk_periph =
152  * periph_clk_src / (peri_aclk_div_con + 1)
153  */
154 #define PERI_ACLK_DIV_SHIFT (0x0)
155 #define PERI_ACLK_DIV_MSK (0x1F)
156 
157 /*******************CLKSEL37 BITS***************************/
158 #define L2_DIV_MSK (0x7)
159 
160 #define ATCLK_DIV_MSK (0x1F << 4)
161 #define ATCLK_DIV_SHIFT (4)
162 
163 #define PCLK_DBG_DIV_MSK (0x1F << 9)
164 #define PCLK_DBG_DIV_SHIFT (9)
165 
166 #define APLL_MODE_MSK (0x3)
167 #define APLL_MODE_SLOW (0)
168 #define APLL_MODE_NORM (1)
169 
170 #define DPLL_MODE_MSK (0x3 << 4)
171 #define DPLL_MODE_SLOW (0 << 4)
172 #define DPLL_MODE_NORM (1 << 4)
173 
174 #define CPLL_MODE_MSK (0x3 << 8)
175 #define CPLL_MODE_SLOW (0 << 8)
176 #define CPLL_MODE_NORM (1 << 8)
177 
178 #define GPLL_MODE_MSK (0x3 << 12)
179 #define GPLL_MODE_SLOW (0 << 12)
180 #define GPLL_MODE_NORM (1 << 12)
181 
182 #define NPLL_MODE_MSK (0x3 << 14)
183 #define NPLL_MODE_SLOW (0 << 14)
184 #define NPLL_MODE_NORM (1 << 14)
185 
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)
191 
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
198 
199 static int rkclk_set_pll(u32 *pll_con, const struct pll_div *div)
200 {
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;
204 
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)));
211 
212  /* enter rest */
213  write32(&pll_con[3], RK_SETBITS(PLL_RESET_MSK));
214 
215  write32(&pll_con[0],
216  RK_CLRSETBITS(PLL_NR_MSK, (div->nr - 1) << PLL_NR_SHIFT) |
217  RK_CLRSETBITS(PLL_OD_MSK, (div->no - 1)));
218 
219  write32(&pll_con[1], RK_CLRSETBITS(PLL_NF_MSK, (div->nf - 1)));
220 
221  write32(&pll_con[2],
222  RK_CLRSETBITS(PLL_BWADJ_MSK, ((div->nf >> 1) - 1)));
223 
224  udelay(10);
225 
226  /* return form rest */
227  write32(&pll_con[3], RK_CLRBITS(PLL_RESET_MSK));
228 
229  return 0;
230 }
231 
232 void rkclk_init(void)
233 {
234  u32 aclk_div;
235  u32 hclk_div;
236  u32 pclk_div;
237 
238  /* pll enter slow-mode */
242 
243  /* init pll */
246 
247  /* waiting for pll lock */
248  while (1) {
249  if ((read32(&rk3288_grf->soc_status[1])
252  break;
253  udelay(1);
254  }
255 
256  /*
257  * pd_bus clock pll source selection and
258  * set up dependent divisors for PCLK/HCLK and ACLK clocks.
259  */
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));
265 
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);
269 
272  pclk_div << PD_BUS_PCLK_DIV_SHIFT) |
274  hclk_div << PD_BUS_HCLK_DIV_SHIFT) |
276  aclk_div << PD_BUS_ACLK_DIV0_SHIFT) |
278 
279  /*
280  * peri clock pll source selection and
281  * set up dependent divisors for PCLK/HCLK and ACLK clocks.
282  */
283  aclk_div = GPLL_HZ / PERI_ACLK_HZ - 1;
284  assert((aclk_div + 1) * PERI_ACLK_HZ == GPLL_HZ && aclk_div <= 0x1f);
285 
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));
289 
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));
293 
296  pclk_div << PERI_PCLK_DIV_SHIFT) |
298  hclk_div << PERI_HCLK_DIV_SHIFT) |
300  aclk_div << PERI_ACLK_DIV_SHIFT));
301 
302  /* PLL enter normal-mode */
306 
307 }
308 
310 {
311  /* pll enter slow-mode */
314 
315  rkclk_set_pll(&cru_ptr->cru_apll_con[0], apll_cfgs[apll_freq]);
316 
317  /* waiting for pll lock */
318  while (1) {
320  break;
321  udelay(1);
322  }
323 
324  /*
325  * core clock pll source selection and
326  * set up dependent divisors for MPAXI/M0AXI and ARM clocks.
327  * core clock select apll, apll clk = 1800MHz
328  * arm clk = 1800MHz, mpclk = 450MHz, m0clk = 900MHz
329  */
333  RK_CLRSETBITS(M0_DIV_MSK, 1 << 0));
334 
335  /*
336  * set up dependent divisors for L2RAM/ATCLK and PCLK clocks.
337  * l2ramclk = 900MHz, atclk = 450MHz, pclk_dbg = 450MHz
338  */
340  RK_CLRSETBITS(L2_DIV_MSK, 1 << 0) |
343 
344  /* PLL enter normal-mode */
347 }
348 
349 void rkclk_configure_ddr(unsigned int hz)
350 {
351  struct pll_div dpll_cfg;
352 
353  switch (hz) {
354  case 300*MHz:
355  dpll_cfg = (struct pll_div){.nf = 50, .nr = 2, .no = 2};
356  break;
357  case 533*MHz: /* actually 533.3P MHz */
358  dpll_cfg = (struct pll_div){.nf = 400, .nr = 9, .no = 2};
359  break;
360  case 666*MHz: /* actually 666.6P MHz */
361  dpll_cfg = (struct pll_div){.nf = 500, .nr = 9, .no = 2};
362  break;
363  case 800*MHz:
364  dpll_cfg = (struct pll_div){.nf = 100, .nr = 3, .no = 1};
365  break;
366  default:
367  die("Unsupported SDRAM frequency, add to clock.c!");
368  }
369 
370  /* pll enter slow-mode */
373 
374  rkclk_set_pll(&cru_ptr->cru_dpll_con[0], &dpll_cfg);
375 
376  /* waiting for pll lock */
377  while (1) {
379  break;
380  udelay(1);
381  }
382 
383  /* PLL enter normal-mode */
386 }
387 
388 void rkclk_ddr_reset(u32 ch, u32 ctl, u32 phy)
389 {
390  u32 phy_ctl_srstn_shift = 4 + 5 * ch;
391  u32 ctl_psrstn_shift = 3 + 5 * ch;
392  u32 ctl_srstn_shift = 2 + 5 * ch;
393  u32 phy_psrstn_shift = 1 + 5 * ch;
394  u32 phy_srstn_shift = 5 * ch;
395 
397  RK_CLRSETBITS(1 << phy_ctl_srstn_shift,
398  phy << phy_ctl_srstn_shift) |
399  RK_CLRSETBITS(1 << ctl_psrstn_shift, ctl << ctl_psrstn_shift) |
400  RK_CLRSETBITS(1 << ctl_srstn_shift, ctl << ctl_srstn_shift) |
401  RK_CLRSETBITS(1 << phy_psrstn_shift, phy << phy_psrstn_shift) |
402  RK_CLRSETBITS(1 << phy_srstn_shift, phy << phy_srstn_shift));
403 }
404 
406 {
407  u32 phy_ctl_srstn_shift = 4 + 5 * ch;
408 
410  RK_CLRSETBITS(1 << phy_ctl_srstn_shift,
411  n << phy_ctl_srstn_shift));
412 }
413 
414 void rkclk_configure_spi(unsigned int bus, unsigned int hz)
415 {
416  int src_clk_div = GPLL_HZ / hz;
417 
418  assert((src_clk_div - 1 <= 127) && (src_clk_div * hz == GPLL_HZ));
419 
420  switch (bus) { /*select gpll as spi src clk, and set div*/
421  case 0:
423  RK_CLRSETBITS(1 << 7 | 0x1f << 0,
424  1 << 7 | (src_clk_div - 1) << 0));
425  break;
426  case 1:
428  RK_CLRSETBITS(1 << 15 | 0x1f << 8,
429  1 << 15 | (src_clk_div - 1) << 8));
430  break;
431  case 2:
433  RK_CLRSETBITS(1 << 7 | 0x1f << 0,
434  1 << 7 | (src_clk_div - 1) << 0));
435  break;
436  default:
437  printk(BIOS_ERR, "do not support this spi bus\n");
438  }
439 }
440 
441 static u32 clk_gcd(u32 a, u32 b)
442 {
443  while (b != 0) {
444  int r = b;
445  b = a % b;
446  a = r;
447  }
448  return a;
449 }
450 
451 void rkclk_configure_i2s(unsigned int hz)
452 {
453  int n, d;
454  int v;
455 
456  /* i2s source clock: gpll
457  i2s0_outclk_sel: clk_i2s
458  i2s0_clk_sel: divider output from fraction
459  i2s0_pll_div_con: 0*/
461  RK_CLRSETBITS(1 << 15 | 1 << 12 | 3 << 8 | 0x7f << 0,
462  1 << 15 | 0 << 12 | 1 << 8 | 0 << 0));
463 
464  /* set frac divider */
465  v = clk_gcd(GPLL_HZ, hz);
466  n = (GPLL_HZ / v) & (0xffff);
467  d = (hz / v) & (0xffff);
468  assert(hz == GPLL_HZ / n * d);
469  write32(&cru_ptr->cru_clksel_con[8], d << 16 | n);
470 }
471 
472 void rkclk_configure_crypto(unsigned int hz)
473 {
474  u32 div = PD_BUS_ACLK_HZ / hz;
475 
476  assert((div - 1 <= 3) && (div * hz == PD_BUS_ACLK_HZ));
477  assert(hz <= 150*MHz); /* Suggested max in TRM. */
479  RK_CLRSETBITS(0x3 << 6, (div - 1) << 6));
480 }
481 
482 void rkclk_configure_tsadc(unsigned int hz)
483 {
484  u32 div;
485  u32 src_clk = 32 * KHz; /* tsadc source clock is 32KHz*/
486 
487  div = src_clk / hz;
488  assert((div - 1 <= 63) && (div * hz == 32 * KHz));
490  RK_CLRSETBITS(0x3f << 0, (div - 1) << 0));
491 }
492 
493 static int pll_para_config(u32 freq_hz, struct pll_div *div, u32 *ext_div)
494 {
495  u32 ref_khz = OSC_HZ / KHz, nr, nf = 0;
496  u32 fref_khz;
497  u32 diff_khz, best_diff_khz;
498  const u32 max_nr = 1 << 6, max_nf = 1 << 12, max_no = 1 << 4;
499  u32 vco_khz;
500  u32 no = 1;
501  u32 freq_khz = freq_hz / KHz;
502 
503  if (!freq_hz) {
504  printk(BIOS_ERR, "%s: the frequency can not be 0 Hz\n", __func__);
505  return -1;
506  }
507 
508  no = DIV_ROUND_UP(VCO_MIN_KHZ, freq_khz);
509  if (ext_div) {
510  *ext_div = DIV_ROUND_UP(no, max_no);
511  no = DIV_ROUND_UP(no, *ext_div);
512  }
513 
514  /* only even divisors (and 1) are supported */
515  if (no > 1)
516  no = DIV_ROUND_UP(no, 2) * 2;
517 
518  vco_khz = freq_khz * no;
519  if (ext_div)
520  vco_khz *= *ext_div;
521 
522  if (vco_khz < VCO_MIN_KHZ || vco_khz > VCO_MAX_KHZ || no > max_no) {
523  printk(BIOS_ERR, "%s: Cannot find out a supported VCO"
524  " for Frequency (%uHz).\n", __func__, freq_hz);
525  return -1;
526  }
527 
528  div->no = no;
529 
530  best_diff_khz = vco_khz;
531  for (nr = 1; nr < max_nr && best_diff_khz; nr++) {
532  fref_khz = ref_khz / nr;
533  if (fref_khz < FREF_MIN_KHZ)
534  break;
535  if (fref_khz > FREF_MAX_KHZ)
536  continue;
537 
538  nf = vco_khz / fref_khz;
539  if (nf >= max_nf)
540  continue;
541  diff_khz = vco_khz - nf * fref_khz;
542  if (nf + 1 < max_nf && diff_khz > fref_khz / 2) {
543  nf++;
544  diff_khz = fref_khz - diff_khz;
545  }
546 
547  if (diff_khz >= best_diff_khz)
548  continue;
549 
550  best_diff_khz = diff_khz;
551  div->nr = nr;
552  div->nf = nf;
553  }
554 
555  if (best_diff_khz > 4 * (MHz/KHz)) {
556  printk(BIOS_ERR, "%s: Failed to match output frequency %u, "
557  "difference is %u Hz,exceed 4MHZ\n", __func__, freq_hz,
558  best_diff_khz * KHz);
559  return -1;
560  }
561 
562  return 0;
563 }
564 
566 {
567  /* clk_edp_24M source: 24M */
568  write32(&cru_ptr->cru_clksel_con[28], RK_SETBITS(1 << 15));
569 
570  /* rst edp */
571  write32(&cru_ptr->cru_softrst_con[6], RK_SETBITS(1 << 15));
572  udelay(1);
573  write32(&cru_ptr->cru_softrst_con[6], RK_CLRBITS(1 << 15));
574 }
575 
577 {
578  /* enable pclk hdmi ctrl */
579  write32(&cru_ptr->cru_clkgate_con[16], RK_CLRBITS(1 << 9));
580 
581  /* software reset hdmi */
582  write32(&cru_ptr->cru_softrst_con[7], RK_SETBITS(1 << 9));
583  udelay(1);
584  write32(&cru_ptr->cru_softrst_con[7], RK_CLRBITS(1 << 9));
585 }
586 
587 void rkclk_configure_vop_aclk(u32 vop_id, u32 aclk_hz)
588 {
589  u32 div;
590 
591  /* vop aclk source clk: cpll */
592  div = CPLL_HZ / aclk_hz;
593  assert((div - 1 <= 63) && (div * aclk_hz == CPLL_HZ));
594 
595  switch (vop_id) {
596  case 0:
598  RK_CLRSETBITS(3 << 6 | 0x1f << 0,
599  0 << 6 | (div - 1) << 0));
600  break;
601 
602  case 1:
604  RK_CLRSETBITS(3 << 14 | 0x1f << 8,
605  0 << 14 | (div - 1) << 8));
606  break;
607  }
608 }
609 
610 int rkclk_configure_vop_dclk(u32 vop_id, u32 dclk_hz)
611 {
612  struct pll_div npll_config = {0};
613  u32 lcdc_div;
614 
615  if (pll_para_config(dclk_hz, &npll_config, &lcdc_div))
616  return -1;
617 
618  /* npll enter slow-mode */
621 
622  rkclk_set_pll(&cru_ptr->cru_npll_con[0], &npll_config);
623 
624  /* waiting for pll lock */
625  while (1) {
627  break;
628  udelay(1);
629  }
630 
631  /* npll enter normal-mode */
634 
635  /* vop dclk source clk: npll,dclk_div: 1 */
636  switch (vop_id) {
637  case 0:
639  RK_CLRSETBITS(0xff << 8 | 3 << 0,
640  (lcdc_div - 1) << 8 | 2 << 0));
641  break;
642 
643  case 1:
645  RK_CLRSETBITS(0xff << 8 | 3 << 6,
646  (lcdc_div - 1) << 8 | 2 << 6));
647  break;
648  }
649  return 0;
650 }
651 
653 {
654  /* Bits 5 and 4 are "second" and "first" global watchdog reset. */
655  return read32(&cru_ptr->cru_glb_rst_st) & 0x30;
656 }
657 
658 unsigned int rkclk_i2c_clock_for_bus(unsigned int bus)
659 {
660  /*i2c0,i2c2 src clk from pd_bus_pclk
661  other i2c src clk from peri_pclk
662  */
663  switch (bus) {
664  case 0:
665  case 2:
666  return PD_BUS_PCLK_HZ;
667 
668  case 1:
669  case 3:
670  case 4:
671  case 5:
672  return PERI_PCLK_HZ;
673 
674  default:
675  return -1; /* Should never happen. */
676  }
677 
678 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define assert(statement)
Definition: assert.h:74
#define MHz
Definition: helpers.h:80
#define KHz
Definition: helpers.h:79
#define DIV_ROUND_UP(x, y)
Definition: helpers.h:60
#define printk(level,...)
Definition: stdlib.h:16
void __noreturn die(const char *fmt,...)
Definition: die.c:17
static int log2(u32 x)
Definition: lib.h:53
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
static struct dramc_channel const ch[2]
static struct rk3288_grf_regs *const rk3288_grf
Definition: grf.h:181
#define RK_CLRBITS(clr)
Definition: soc.h:10
#define RK_SETBITS(set)
Definition: soc.h:9
#define RK_CLRSETBITS(clr, set)
Definition: soc.h:8
#define GPLL_MODE_NORM
Definition: clock.c:180
#define APLL_MODE_NORM
Definition: clock.c:168
static int rkclk_set_pll(u32 *pll_con, const struct pll_div *div)
Definition: clock.c:199
#define PLL_DIVISORS(hz, _nr, _no)
Definition: clock.c:52
#define PD_BUS_ACLK_DIV0_MASK
Definition: clock.c:128
#define PLL_NR_SHIFT
Definition: clock.c:76
#define GPLL_MODE_MSK
Definition: clock.c:178
#define PCLK_DBG_DIV_SHIFT
Definition: clock.c:164
#define PERI_PCLK_DIV_MSK
Definition: clock.c:142
#define FREF_MAX_KHZ
Definition: clock.c:196
#define ATCLK_DIV_MSK
Definition: clock.c:160
#define L2_DIV_MSK
Definition: clock.c:158
#define M0_DIV_MSK
Definition: clock.c:104
#define PERI_SEL_GPLL
Definition: clock.c:136
void rkclk_ddr_phy_ctl_reset(u32 ch, u32 n)
Definition: clock.c:405
#define PD_BUS_SEL_GPLL
Definition: clock.c:110
static const struct pll_div apll_1800_cfg
Definition: clock.c:63
#define PLL_OD_MSK
Definition: clock.c:73
void rkclk_configure_cpu(enum apll_frequencies apll_freq)
Definition: clock.c:309
#define SOCSTS_APLL_LOCK
Definition: clock.c:187
#define PD_BUS_PCLK_DIV_MSK
Definition: clock.c:116
#define PLL_NF_MSK
Definition: clock.c:79
#define VCO_MIN_KHZ
Definition: clock.c:193
#define A12_DIV_MSK
Definition: clock.c:97
#define OUTPUT_MIN_KHZ
Definition: clock.c:195
#define A12_DIV_SHIFT
Definition: clock.c:96
#define PERI_HCLK_DIV_SHIFT
Definition: clock.c:147
#define CORE_SEL_PLL_MSK
Definition: clock.c:91
void rkclk_ddr_reset(u32 ch, u32 ctl, u32 phy)
Definition: clock.c:388
#define DPLL_MODE_MSK
Definition: clock.c:170
static struct rk3288_cru_reg *const cru_ptr
Definition: clock.c:50
#define PD_BUS_ACLK_DIV1_MASK
Definition: clock.c:130
int rkclk_was_watchdog_reset(void)
Definition: clock.c:652
void rkclk_configure_tsadc(unsigned int hz)
Definition: clock.c:482
#define SOCSTS_NPLL_LOCK
Definition: clock.c:190
unsigned int rkclk_i2c_clock_for_bus(unsigned int bus)
Definition: clock.c:658
#define PERI_HCLK_DIV_MSK
Definition: clock.c:148
#define NPLL_MODE_SLOW
Definition: clock.c:183
#define CPLL_MODE_NORM
Definition: clock.c:176
#define FREF_MIN_KHZ
Definition: clock.c:197
#define MP_DIV_MSK
Definition: clock.c:101
#define DPLL_MODE_NORM
Definition: clock.c:172
void rkclk_configure_vop_aclk(u32 vop_id, u32 aclk_hz)
Definition: clock.c:587
static int pll_para_config(u32 freq_hz, struct pll_div *div, u32 *ext_div)
Definition: clock.c:493
#define OUTPUT_MAX_KHZ
Definition: clock.c:194
#define APLL_MODE_MSK
Definition: clock.c:166
void rkclk_init(void)
Definition: clock.c:232
void rkclk_configure_ddr(unsigned int hz)
Definition: clock.c:349
void rkclk_configure_edp(void)
Definition: clock.c:565
#define PLL_NR_MSK
Definition: clock.c:75
#define CPLL_MODE_SLOW
Definition: clock.c:175
#define PD_BUS_ACLK_DIV0_SHIFT
Definition: clock.c:127
#define SOCSTS_GPLL_LOCK
Definition: clock.c:189
#define PLL_BWADJ_MSK
Definition: clock.c:82
static const struct pll_div cpll_init_cfg
Definition: clock.c:60
#define CPLL_MODE_MSK
Definition: clock.c:174
static const struct pll_div apll_600_cfg
Definition: clock.c:65
#define PCLK_DBG_DIV_MSK
Definition: clock.c:163
#define GPLL_MODE_SLOW
Definition: clock.c:179
void rkclk_configure_i2s(unsigned int hz)
Definition: clock.c:451
void rkclk_configure_spi(unsigned int bus, unsigned int hz)
Definition: clock.c:414
static const struct pll_div * apll_cfgs[]
Definition: clock.c:66
#define VCO_MAX_KHZ
Definition: clock.c:192
check_member(rk3288_cru_reg, cru_emmc_con[1], 0x021c)
#define MP_DIV_SHIFT
Definition: clock.c:100
static const struct pll_div apll_1416_cfg
Definition: clock.c:64
#define PD_BUS_PCLK_DIV_SHIFT
Definition: clock.c:115
#define PERI_PCLK_DIV_SHIFT
Definition: clock.c:141
#define NPLL_MODE_MSK
Definition: clock.c:182
void rkclk_configure_hdmi(void)
Definition: clock.c:576
#define PD_BUS_HCLK_DIV_MSK
Definition: clock.c:122
#define ATCLK_DIV_SHIFT
Definition: clock.c:161
#define PERI_ACLK_DIV_SHIFT
Definition: clock.c:154
#define APLL_MODE_SLOW
Definition: clock.c:167
int rkclk_configure_vop_dclk(u32 vop_id, u32 dclk_hz)
Definition: clock.c:610
#define DPLL_MODE_SLOW
Definition: clock.c:171
#define PD_BUS_HCLK_DIV_SHIFT
Definition: clock.c:121
#define PLL_RESET_MSK
Definition: clock.c:85
static u32 clk_gcd(u32 a, u32 b)
Definition: clock.c:441
void rkclk_configure_crypto(unsigned int hz)
Definition: clock.c:472
static const struct pll_div gpll_init_cfg
Definition: clock.c:59
#define PERI_ACLK_DIV_MSK
Definition: clock.c:155
#define NPLL_MODE_NORM
Definition: clock.c:184
#define SOCSTS_DPLL_LOCK
Definition: clock.c:186
#define SOCSTS_CPLL_LOCK
Definition: clock.c:188
#define CRU_BASE
Definition: addressmap.h:52
#define PERI_ACLK_HZ
Definition: clock.h:26
#define PD_BUS_PCLK_HZ
Definition: clock.h:24
#define PD_BUS_ACLK_HZ
Definition: clock.h:22
#define GPLL_HZ
Definition: clock.h:11
#define PD_BUS_HCLK_HZ
Definition: clock.h:23
#define PERI_PCLK_HZ
Definition: clock.h:28
#define OSC_HZ
Definition: clock.h:9
apll_frequencies
Definition: clock.h:15
@ APLL_600_MHZ
Definition: clock.h:18
@ APLL_1416_MHZ
Definition: clock.h:17
@ APLL_1800_MHZ
Definition: clock.h:16
#define PERI_HCLK_HZ
Definition: clock.h:27
#define CPLL_HZ
Definition: clock.h:12
uint32_t u32
Definition: stdint.h:51
Definition: device.h:76
Definition: clock.c:16
u32 nf
Definition: clock.c:18
u32 nr
Definition: clock.c:17
u32 no
Definition: clock.c:19
u32 cru_misc_con
Definition: clock.c:37
u32 cru_glb_rst_con
Definition: clock.c:39
u32 cru_emmc_con[2]
Definition: clock.c:46
u32 reserved1[21]
Definition: clock.c:31
u32 cru_clkgate_con[19]
Definition: clock.c:32
u32 cru_clksel_con[43]
Definition: clock.c:30
u32 cru_glb_rst_st
Definition: clock.c:41
u32 reserved4
Definition: clock.c:42
u32 cru_glb_srst_fst_value
Definition: clock.c:34
u32 cru_sdmmc_con[2]
Definition: clock.c:43
u32 cru_glb_cnt_th
Definition: clock.c:38
u32 reserved0[3]
Definition: clock.c:29
u32 cru_sdio1_con[2]
Definition: clock.c:45
u32 cru_gpll_con[4]
Definition: clock.c:26
u32 cru_sdio0_con[2]
Definition: clock.c:44
u32 cru_apll_con[4]
Definition: clock.c:23
u32 cru_dpll_con[4]
Definition: clock.c:24
u32 cru_cpll_con[4]
Definition: clock.c:25
u32 cru_npll_con[4]
Definition: clock.c:27
u32 cru_glb_srst_snd_value
Definition: clock.c:35
u32 reserved2
Definition: clock.c:33
u32 cru_mode_con
Definition: clock.c:28
u32 cru_softrst_con[12]
Definition: clock.c:36
u32 reserved3
Definition: clock.c:40
u32 soc_status[22]
Definition: grf.h:119
void udelay(uint32_t us)
Definition: udelay.c:15