1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
6 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
9 #ifndef CONFIG_CLK_MPC83XX
12 #include <clock_legacy.h>
16 #include <asm/processor.h>
18 DECLARE_GLOBAL_DATA_PTR;
20 /* ----------------------------------------------------------------- */
38 mult_t core_csb_ratio;
42 static corecnf_t corecnf_tab[] = {
43 {_byp, _byp}, /* 0x00 */
44 {_byp, _byp}, /* 0x01 */
45 {_byp, _byp}, /* 0x02 */
46 {_byp, _byp}, /* 0x03 */
47 {_byp, _byp}, /* 0x04 */
48 {_byp, _byp}, /* 0x05 */
49 {_byp, _byp}, /* 0x06 */
50 {_byp, _byp}, /* 0x07 */
51 {_1x, _x2}, /* 0x08 */
52 {_1x, _x4}, /* 0x09 */
53 {_1x, _x8}, /* 0x0A */
54 {_1x, _x8}, /* 0x0B */
55 {_1_5x, _x2}, /* 0x0C */
56 {_1_5x, _x4}, /* 0x0D */
57 {_1_5x, _x8}, /* 0x0E */
58 {_1_5x, _x8}, /* 0x0F */
59 {_2x, _x2}, /* 0x10 */
60 {_2x, _x4}, /* 0x11 */
61 {_2x, _x8}, /* 0x12 */
62 {_2x, _x8}, /* 0x13 */
63 {_2_5x, _x2}, /* 0x14 */
64 {_2_5x, _x4}, /* 0x15 */
65 {_2_5x, _x8}, /* 0x16 */
66 {_2_5x, _x8}, /* 0x17 */
67 {_3x, _x2}, /* 0x18 */
68 {_3x, _x4}, /* 0x19 */
69 {_3x, _x8}, /* 0x1A */
70 {_3x, _x8}, /* 0x1B */
73 /* ----------------------------------------------------------------- */
80 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
85 u32 corecnf_tab_index;
90 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
91 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
95 #elif defined(CONFIG_ARCH_MPC8309)
98 #ifdef CONFIG_ARCH_MPC834X
103 #if !defined(CONFIG_ARCH_MPC832X)
106 #if defined(CONFIG_ARCH_MPC8315)
109 #if defined(CONFIG_FSL_ESDHC)
112 #if !defined(CONFIG_ARCH_MPC8309)
118 #if defined(CONFIG_ARCH_MPC8360)
121 #if defined(CONFIG_QE)
127 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
128 defined(CONFIG_ARCH_MPC837X)
132 #if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
136 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
139 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
141 if (im->reset.rcwh & HRCWH_PCI_HOST) {
142 #if defined(CONFIG_SYS_CLK_FREQ)
143 pci_sync_in = CONFIG_SYS_CLK_FREQ / (1 + clkin_div);
145 pci_sync_in = 0xDEADBEEF;
148 #if defined(CONFIG_83XX_PCICLK)
149 pci_sync_in = CONFIG_83XX_PCICLK;
151 pci_sync_in = 0xDEADBEEF;
155 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
156 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
160 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
161 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
162 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
170 tsec1_clk = csb_clk / 2;
173 tsec1_clk = csb_clk / 3;
176 /* unknown SCCR_TSEC1CM value */
181 #if defined(CONFIG_ARCH_MPC830X) || defined(CONFIG_ARCH_MPC831X) || \
182 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
183 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
191 usbdr_clk = csb_clk / 2;
194 usbdr_clk = csb_clk / 3;
197 /* unknown SCCR_USBDRCM value */
202 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC8315) || \
203 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
204 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
212 tsec2_clk = csb_clk / 2;
215 tsec2_clk = csb_clk / 3;
218 /* unknown SCCR_TSEC2CM value */
221 #elif defined(CONFIG_ARCH_MPC8313)
222 tsec2_clk = tsec1_clk;
224 if (!(sccr & SCCR_TSEC1ON))
226 if (!(sccr & SCCR_TSEC2ON))
230 #if defined(CONFIG_ARCH_MPC834X)
231 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
236 usbmph_clk = csb_clk;
239 usbmph_clk = csb_clk / 2;
242 usbmph_clk = csb_clk / 3;
245 /* unknown SCCR_USBMPHCM value */
249 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
250 /* if USB MPH clock is not disabled and
251 * USB DR clock is not disabled then
252 * USB MPH & USB DR must have the same rate
257 #if !defined(CONFIG_ARCH_MPC8309)
258 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
266 enc_clk = csb_clk / 2;
269 enc_clk = csb_clk / 3;
272 /* unknown SCCR_ENCCM value */
277 #if defined(CONFIG_FSL_ESDHC)
278 switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) {
286 sdhc_clk = csb_clk / 2;
289 sdhc_clk = csb_clk / 3;
292 /* unknown SCCR_SDHCCM value */
296 #if defined(CONFIG_ARCH_MPC8315)
297 switch ((sccr & SCCR_TDMCM) >> SCCR_TDMCM_SHIFT) {
305 tdm_clk = csb_clk / 2;
308 tdm_clk = csb_clk / 3;
311 /* unknown SCCR_TDMCM value */
316 #if defined(CONFIG_ARCH_MPC834X)
317 i2c1_clk = tsec2_clk;
318 #elif defined(CONFIG_ARCH_MPC8360)
320 #elif defined(CONFIG_ARCH_MPC832X)
322 #elif defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X)
324 #elif defined(CONFIG_FSL_ESDHC)
326 #elif defined(CONFIG_ARCH_MPC837X)
328 #elif defined(CONFIG_ARCH_MPC8309)
331 #if !defined(CONFIG_ARCH_MPC832X)
332 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
335 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
336 defined(CONFIG_ARCH_MPC837X)
337 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
342 pciexp1_clk = csb_clk;
345 pciexp1_clk = csb_clk / 2;
348 pciexp1_clk = csb_clk / 3;
351 /* unknown SCCR_PCIEXP1CM value */
355 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
360 pciexp2_clk = csb_clk;
363 pciexp2_clk = csb_clk / 2;
366 pciexp2_clk = csb_clk / 3;
369 /* unknown SCCR_PCIEXP2CM value */
374 #if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
375 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
383 sata_clk = csb_clk / 2;
386 sata_clk = csb_clk / 3;
389 /* unknown SCCR_SATA1CM value */
395 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
396 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
401 lclk_clk = lbiu_clk / lcrr;
409 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
410 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
412 #if defined(CONFIG_ARCH_MPC8360)
413 mem_sec_clk = csb_clk * (1 +
414 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
417 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
418 if (corecnf_tab_index > (ARRAY_SIZE(corecnf_tab))) {
419 /* corecnf_tab_index is too high, possibly wrong value */
422 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
429 core_clk = (3 * csb_clk) / 2;
432 core_clk = 2 * csb_clk;
435 core_clk = (5 * csb_clk) / 2;
438 core_clk = 3 * csb_clk;
441 /* unknown core to csb ratio */
445 #if defined(CONFIG_QE)
446 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
447 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
448 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
449 brg_clk = qe_clk / 2;
452 gd->arch.csb_clk = csb_clk;
453 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
454 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
455 gd->arch.tsec1_clk = tsec1_clk;
456 gd->arch.tsec2_clk = tsec2_clk;
457 gd->arch.usbdr_clk = usbdr_clk;
458 #elif defined(CONFIG_ARCH_MPC8309)
459 gd->arch.usbdr_clk = usbdr_clk;
461 #if defined(CONFIG_ARCH_MPC834X)
462 gd->arch.usbmph_clk = usbmph_clk;
464 #if defined(CONFIG_ARCH_MPC8315)
465 gd->arch.tdm_clk = tdm_clk;
467 #if defined(CONFIG_FSL_ESDHC)
468 gd->arch.sdhc_clk = sdhc_clk;
470 gd->arch.core_clk = core_clk;
471 gd->arch.i2c1_clk = i2c1_clk;
472 #if !defined(CONFIG_ARCH_MPC832X)
473 gd->arch.i2c2_clk = i2c2_clk;
475 #if !defined(CONFIG_ARCH_MPC8309)
476 gd->arch.enc_clk = enc_clk;
478 gd->arch.lbiu_clk = lbiu_clk;
479 gd->arch.lclk_clk = lclk_clk;
480 gd->mem_clk = mem_clk;
481 #if defined(CONFIG_ARCH_MPC8360)
482 gd->arch.mem_sec_clk = mem_sec_clk;
484 #if defined(CONFIG_QE)
485 gd->arch.qe_clk = qe_clk;
486 gd->arch.brg_clk = brg_clk;
488 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
489 defined(CONFIG_ARCH_MPC837X)
490 gd->arch.pciexp1_clk = pciexp1_clk;
491 gd->arch.pciexp2_clk = pciexp2_clk;
493 #if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
494 gd->arch.sata_clk = sata_clk;
496 gd->pci_clk = pci_sync_in;
497 gd->cpu_clk = gd->arch.core_clk;
498 gd->bus_clk = gd->arch.csb_clk;
503 /********************************************
505 * return system bus freq in Hz
506 *********************************************/
507 ulong get_bus_freq(ulong dummy)
509 return gd->arch.csb_clk;
512 /********************************************
514 * return ddr bus freq in Hz
515 *********************************************/
516 ulong get_ddr_freq(ulong dummy)
521 int get_serial_clock(void)
523 return get_bus_freq(0);
526 static int do_clocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
530 printf("Clock configuration:\n");
531 printf(" Core: %-4s MHz\n",
532 strmhz(buf, gd->arch.core_clk));
533 printf(" Coherent System Bus: %-4s MHz\n",
534 strmhz(buf, gd->arch.csb_clk));
535 #if defined(CONFIG_QE)
536 printf(" QE: %-4s MHz\n",
537 strmhz(buf, gd->arch.qe_clk));
538 printf(" BRG: %-4s MHz\n",
539 strmhz(buf, gd->arch.brg_clk));
541 printf(" Local Bus Controller:%-4s MHz\n",
542 strmhz(buf, gd->arch.lbiu_clk));
543 printf(" Local Bus: %-4s MHz\n",
544 strmhz(buf, gd->arch.lclk_clk));
545 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
546 #if defined(CONFIG_ARCH_MPC8360)
547 printf(" DDR Secondary: %-4s MHz\n",
548 strmhz(buf, gd->arch.mem_sec_clk));
550 #if !defined(CONFIG_ARCH_MPC8309)
551 printf(" SEC: %-4s MHz\n",
552 strmhz(buf, gd->arch.enc_clk));
554 printf(" I2C1: %-4s MHz\n",
555 strmhz(buf, gd->arch.i2c1_clk));
556 #if !defined(CONFIG_ARCH_MPC832X)
557 printf(" I2C2: %-4s MHz\n",
558 strmhz(buf, gd->arch.i2c2_clk));
560 #if defined(CONFIG_ARCH_MPC8315)
561 printf(" TDM: %-4s MHz\n",
562 strmhz(buf, gd->arch.tdm_clk));
564 #if defined(CONFIG_FSL_ESDHC)
565 printf(" SDHC: %-4s MHz\n",
566 strmhz(buf, gd->arch.sdhc_clk));
568 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
569 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
570 printf(" TSEC1: %-4s MHz\n",
571 strmhz(buf, gd->arch.tsec1_clk));
572 printf(" TSEC2: %-4s MHz\n",
573 strmhz(buf, gd->arch.tsec2_clk));
574 printf(" USB DR: %-4s MHz\n",
575 strmhz(buf, gd->arch.usbdr_clk));
576 #elif defined(CONFIG_ARCH_MPC8309)
577 printf(" USB DR: %-4s MHz\n",
578 strmhz(buf, gd->arch.usbdr_clk));
580 #if defined(CONFIG_ARCH_MPC834X)
581 printf(" USB MPH: %-4s MHz\n",
582 strmhz(buf, gd->arch.usbmph_clk));
584 #if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
585 defined(CONFIG_ARCH_MPC837X)
586 printf(" PCIEXP1: %-4s MHz\n",
587 strmhz(buf, gd->arch.pciexp1_clk));
588 printf(" PCIEXP2: %-4s MHz\n",
589 strmhz(buf, gd->arch.pciexp2_clk));
591 #if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
592 printf(" SATA: %-4s MHz\n",
593 strmhz(buf, gd->arch.sata_clk));
598 U_BOOT_CMD(clocks, 1, 0, do_clocks,
599 "print clock configuration",