2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
7 * SPDX-License-Identifier: GPL-2.0+
9 * Based on the MPC83xx code.
15 #include <asm/processor.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 static int spmf_mult[] = {
26 static int cpmf_mult[][2] = {
27 {0, 1}, {0, 1}, /* 0 and 1 are not valid */
31 {0, 1}, {0, 1}, /* and all above 7 are not valid too */
37 static int sys_dividors[][2] = {
38 {2, 1}, {5, 2}, {3, 1}, {7, 2}, {4, 1},
39 {9, 2}, {5, 1}, {7, 1}, {6, 1}, {8, 1},
40 {9, 1}, {11, 1}, {10, 1}, {12, 1}, {13, 1},
41 {15, 1}, {14, 1}, {16, 1}, {17, 1}, {19, 1},
42 {18, 1}, {20, 1}, {21, 1}, {23, 1}, {22, 1},
43 {24, 1}, {25, 1}, {27, 1}, {26, 1}, {28, 1},
44 {29, 1}, {31, 1}, {30, 1}, {32, 1}, {33, 1}
49 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
55 u32 ref_clk = CONFIG_SYS_MPC512X_CLKIN;
64 reg = in_be32(&im->sysconf.immrbar);
65 if ((reg & IMMRBAR_BASE_ADDR) != (u32) im)
68 reg = in_be32(&im->clk.spmr);
69 spmf = (reg & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
70 spll = ref_clk * spmf_mult[spmf];
72 reg = in_be32(&im->clk.scfr[1]);
73 sys_div = (reg & SCFR2_SYS_DIV) >> SCFR2_SYS_DIV_SHIFT;
74 sys_clk = (spll * sys_dividors[sys_div][1]) / sys_dividors[sys_div][0];
76 csb_clk = sys_clk / 2;
78 reg = in_be32(&im->clk.spmr);
79 cpmf = (reg & SPMR_CPMF) >> SPMR_CPMF_SHIFT;
80 core_clk = (csb_clk * cpmf_mult[cpmf][0]) / cpmf_mult[cpmf][1];
82 reg = in_be32(&im->clk.scfr[0]);
83 ips_div = (reg & SCFR1_IPS_DIV_MASK) >> SCFR1_IPS_DIV_SHIFT;
85 ips_clk = csb_clk / ips_div;
87 /* in case we cannot get a sane IPS divisor, fail gracefully */
91 reg = in_be32(&im->clk.scfr[0]);
92 pci_div = (reg & SCFR1_PCI_DIV_MASK) >> SCFR1_PCI_DIV_SHIFT;
94 pci_clk = csb_clk / pci_div;
96 /* in case we cannot get a sane IPS divisor, fail gracefully */
100 gd->arch.ips_clk = ips_clk;
101 gd->pci_clk = pci_clk;
102 gd->arch.csb_clk = csb_clk;
103 gd->cpu_clk = core_clk;
104 gd->bus_clk = csb_clk;
109 /********************************************
111 * return system bus freq in Hz
112 *********************************************/
113 ulong get_bus_freq (ulong dummy)
115 return gd->arch.csb_clk;
118 int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
122 printf("Clock configuration:\n");
123 printf(" CPU: %-4s MHz\n", strmhz(buf, gd->cpu_clk));
124 printf(" Coherent System Bus: %-4s MHz\n",
125 strmhz(buf, gd->arch.csb_clk));
126 printf(" IPS Bus: %-4s MHz\n",
127 strmhz(buf, gd->arch.ips_clk));
128 printf(" PCI: %-4s MHz\n", strmhz(buf, gd->pci_clk));
129 printf(" DDR: %-4s MHz\n",
130 strmhz(buf, 2 * gd->arch.csb_clk));
134 U_BOOT_CMD(clocks, 1, 0, do_clocks,
135 "print clock configuration",