2007-07-27 12:43:59 +00:00
|
|
|
/*
|
2009-05-16 08:47:43 +00:00
|
|
|
* (C) Copyright 2000-2009
|
2007-07-27 12:43:59 +00:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2007-07-27 12:43:59 +00:00
|
|
|
*
|
|
|
|
* Based on the MPC83xx code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2009-05-16 08:47:43 +00:00
|
|
|
#include <asm/io.h>
|
2007-07-27 12:43:59 +00:00
|
|
|
#include <asm/processor.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
static int spmf_mult[] = {
|
|
|
|
68, 1, 12, 16,
|
|
|
|
20, 24, 28, 32,
|
|
|
|
36, 40, 44, 48,
|
|
|
|
52, 56, 60, 64
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cpmf_mult[][2] = {
|
|
|
|
{0, 1}, {0, 1}, /* 0 and 1 are not valid */
|
|
|
|
{1, 1}, {3, 2},
|
|
|
|
{2, 1}, {5, 2},
|
|
|
|
{3, 1}, {7, 2},
|
|
|
|
{0, 1}, {0, 1}, /* and all above 7 are not valid too */
|
|
|
|
{0, 1}, {0, 1},
|
|
|
|
{0, 1}, {0, 1},
|
|
|
|
{0, 1}, {0, 1}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sys_dividors[][2] = {
|
|
|
|
{2, 1}, {5, 2}, {3, 1}, {7, 2}, {4, 1},
|
|
|
|
{9, 2}, {5, 1}, {7, 1}, {6, 1}, {8, 1},
|
|
|
|
{9, 1}, {11, 1}, {10, 1}, {12, 1}, {13, 1},
|
|
|
|
{15, 1}, {14, 1}, {16, 1}, {17, 1}, {19, 1},
|
|
|
|
{18, 1}, {20, 1}, {21, 1}, {23, 1}, {22, 1},
|
|
|
|
{24, 1}, {25, 1}, {27, 1}, {26, 1}, {28, 1},
|
|
|
|
{29, 1}, {31, 1}, {30, 1}, {32, 1}, {33, 1}
|
|
|
|
};
|
|
|
|
|
|
|
|
int get_clocks (void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
u8 spmf;
|
|
|
|
u8 cpmf;
|
|
|
|
u8 sys_div;
|
|
|
|
u8 ips_div;
|
2008-02-26 16:38:14 +00:00
|
|
|
u8 pci_div;
|
2008-10-16 13:01:15 +00:00
|
|
|
u32 ref_clk = CONFIG_SYS_MPC512X_CLKIN;
|
2007-07-27 12:43:59 +00:00
|
|
|
u32 spll;
|
|
|
|
u32 sys_clk;
|
|
|
|
u32 core_clk;
|
|
|
|
u32 csb_clk;
|
|
|
|
u32 ips_clk;
|
2008-02-26 16:38:14 +00:00
|
|
|
u32 pci_clk;
|
2009-05-16 08:47:43 +00:00
|
|
|
u32 reg;
|
2007-07-27 12:43:59 +00:00
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
reg = in_be32(&im->sysconf.immrbar);
|
|
|
|
if ((reg & IMMRBAR_BASE_ADDR) != (u32) im)
|
2007-07-27 12:43:59 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
reg = in_be32(&im->clk.spmr);
|
|
|
|
spmf = (reg & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
|
2007-07-27 12:43:59 +00:00
|
|
|
spll = ref_clk * spmf_mult[spmf];
|
2007-08-02 19:27:46 +00:00
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
reg = in_be32(&im->clk.scfr[1]);
|
|
|
|
sys_div = (reg & SCFR2_SYS_DIV) >> SCFR2_SYS_DIV_SHIFT;
|
2007-07-27 12:43:59 +00:00
|
|
|
sys_clk = (spll * sys_dividors[sys_div][1]) / sys_dividors[sys_div][0];
|
|
|
|
|
|
|
|
csb_clk = sys_clk / 2;
|
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
reg = in_be32(&im->clk.spmr);
|
|
|
|
cpmf = (reg & SPMR_CPMF) >> SPMR_CPMF_SHIFT;
|
2007-08-02 19:27:46 +00:00
|
|
|
core_clk = (csb_clk * cpmf_mult[cpmf][0]) / cpmf_mult[cpmf][1];
|
2007-07-27 12:43:59 +00:00
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
reg = in_be32(&im->clk.scfr[0]);
|
|
|
|
ips_div = (reg & SCFR1_IPS_DIV_MASK) >> SCFR1_IPS_DIV_SHIFT;
|
2007-07-27 12:43:59 +00:00
|
|
|
if (ips_div != 0) {
|
|
|
|
ips_clk = csb_clk / ips_div;
|
|
|
|
} else {
|
|
|
|
/* in case we cannot get a sane IPS divisor, fail gracefully */
|
|
|
|
ips_clk = 0;
|
|
|
|
}
|
2009-05-16 08:47:43 +00:00
|
|
|
|
|
|
|
reg = in_be32(&im->clk.scfr[0]);
|
|
|
|
pci_div = (reg & SCFR1_PCI_DIV_MASK) >> SCFR1_PCI_DIV_SHIFT;
|
2008-02-26 16:38:14 +00:00
|
|
|
if (pci_div != 0) {
|
|
|
|
pci_clk = csb_clk / pci_div;
|
|
|
|
} else {
|
|
|
|
/* in case we cannot get a sane IPS divisor, fail gracefully */
|
|
|
|
pci_clk = 333333;
|
|
|
|
}
|
2007-07-27 12:43:59 +00:00
|
|
|
|
2012-12-13 20:48:54 +00:00
|
|
|
gd->arch.ips_clk = ips_clk;
|
2008-02-26 16:38:14 +00:00
|
|
|
gd->pci_clk = pci_clk;
|
2012-12-13 20:48:54 +00:00
|
|
|
gd->arch.csb_clk = csb_clk;
|
2007-07-27 12:43:59 +00:00
|
|
|
gd->cpu_clk = core_clk;
|
|
|
|
gd->bus_clk = csb_clk;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* get_bus_freq
|
|
|
|
* return system bus freq in Hz
|
|
|
|
*********************************************/
|
|
|
|
ulong get_bus_freq (ulong dummy)
|
|
|
|
{
|
2012-12-13 20:48:54 +00:00
|
|
|
return gd->arch.csb_clk;
|
2007-07-27 12:43:59 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 20:00:46 +00:00
|
|
|
int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
|
2007-07-27 12:43:59 +00:00
|
|
|
{
|
2008-10-19 00:35:49 +00:00
|
|
|
char buf[32];
|
|
|
|
|
2008-02-26 16:38:14 +00:00
|
|
|
printf("Clock configuration:\n");
|
2008-10-19 00:35:49 +00:00
|
|
|
printf(" CPU: %-4s MHz\n", strmhz(buf, gd->cpu_clk));
|
2012-12-13 20:48:54 +00:00
|
|
|
printf(" Coherent System Bus: %-4s MHz\n",
|
|
|
|
strmhz(buf, gd->arch.csb_clk));
|
|
|
|
printf(" IPS Bus: %-4s MHz\n",
|
|
|
|
strmhz(buf, gd->arch.ips_clk));
|
2008-10-19 00:35:49 +00:00
|
|
|
printf(" PCI: %-4s MHz\n", strmhz(buf, gd->pci_clk));
|
2012-12-13 20:48:54 +00:00
|
|
|
printf(" DDR: %-4s MHz\n",
|
|
|
|
strmhz(buf, 2 * gd->arch.csb_clk));
|
2007-07-27 12:43:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(clocks, 1, 0, do_clocks,
|
2009-01-28 00:03:12 +00:00
|
|
|
"print clock configuration",
|
2009-05-24 15:06:54 +00:00
|
|
|
" clocks"
|
2007-07-27 12:43:59 +00:00
|
|
|
);
|