blob: 95069cad8458f1634a5ce6fcb10d90f709c18b47 [file] [log] [blame]
Rafal Jaworowski8993e542007-07-27 14:43:59 +02001/*
Wolfgang Denk843efb12009-05-16 10:47:43 +02002 * (C) Copyright 2000-2009
Rafal Jaworowski8993e542007-07-27 14:43:59 +02003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Rafal Jaworowski8993e542007-07-27 14:43:59 +02008 *
9 * Based on the MPC83xx code.
10 */
11
12#include <common.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020013#include <command.h>
Wolfgang Denk843efb12009-05-16 10:47:43 +020014#include <asm/io.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020015#include <asm/processor.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
19static int spmf_mult[] = {
20 68, 1, 12, 16,
21 20, 24, 28, 32,
22 36, 40, 44, 48,
23 52, 56, 60, 64
24};
25
26static int cpmf_mult[][2] = {
27 {0, 1}, {0, 1}, /* 0 and 1 are not valid */
28 {1, 1}, {3, 2},
29 {2, 1}, {5, 2},
30 {3, 1}, {7, 2},
31 {0, 1}, {0, 1}, /* and all above 7 are not valid too */
32 {0, 1}, {0, 1},
33 {0, 1}, {0, 1},
34 {0, 1}, {0, 1}
35};
36
37static 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}
45};
46
47int get_clocks (void)
48{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020049 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Rafal Jaworowski8993e542007-07-27 14:43:59 +020050 u8 spmf;
51 u8 cpmf;
52 u8 sys_div;
53 u8 ips_div;
John Rigby5f91db72008-02-26 09:38:14 -070054 u8 pci_div;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055 u32 ref_clk = CONFIG_SYS_MPC512X_CLKIN;
Rafal Jaworowski8993e542007-07-27 14:43:59 +020056 u32 spll;
57 u32 sys_clk;
58 u32 core_clk;
59 u32 csb_clk;
60 u32 ips_clk;
John Rigby5f91db72008-02-26 09:38:14 -070061 u32 pci_clk;
Wolfgang Denk843efb12009-05-16 10:47:43 +020062 u32 reg;
Rafal Jaworowski8993e542007-07-27 14:43:59 +020063
Wolfgang Denk843efb12009-05-16 10:47:43 +020064 reg = in_be32(&im->sysconf.immrbar);
65 if ((reg & IMMRBAR_BASE_ADDR) != (u32) im)
Rafal Jaworowski8993e542007-07-27 14:43:59 +020066 return -1;
67
Wolfgang Denk843efb12009-05-16 10:47:43 +020068 reg = in_be32(&im->clk.spmr);
69 spmf = (reg & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
Rafal Jaworowski8993e542007-07-27 14:43:59 +020070 spll = ref_clk * spmf_mult[spmf];
Wolfgang Denkb1b54e32007-08-02 21:27:46 +020071
Wolfgang Denk843efb12009-05-16 10:47:43 +020072 reg = in_be32(&im->clk.scfr[1]);
73 sys_div = (reg & SCFR2_SYS_DIV) >> SCFR2_SYS_DIV_SHIFT;
Rafal Jaworowski8993e542007-07-27 14:43:59 +020074 sys_clk = (spll * sys_dividors[sys_div][1]) / sys_dividors[sys_div][0];
75
76 csb_clk = sys_clk / 2;
77
Wolfgang Denk843efb12009-05-16 10:47:43 +020078 reg = in_be32(&im->clk.spmr);
79 cpmf = (reg & SPMR_CPMF) >> SPMR_CPMF_SHIFT;
Wolfgang Denkb1b54e32007-08-02 21:27:46 +020080 core_clk = (csb_clk * cpmf_mult[cpmf][0]) / cpmf_mult[cpmf][1];
Rafal Jaworowski8993e542007-07-27 14:43:59 +020081
Wolfgang Denk843efb12009-05-16 10:47:43 +020082 reg = in_be32(&im->clk.scfr[0]);
83 ips_div = (reg & SCFR1_IPS_DIV_MASK) >> SCFR1_IPS_DIV_SHIFT;
Rafal Jaworowski8993e542007-07-27 14:43:59 +020084 if (ips_div != 0) {
85 ips_clk = csb_clk / ips_div;
86 } else {
87 /* in case we cannot get a sane IPS divisor, fail gracefully */
88 ips_clk = 0;
89 }
Wolfgang Denk843efb12009-05-16 10:47:43 +020090
91 reg = in_be32(&im->clk.scfr[0]);
92 pci_div = (reg & SCFR1_PCI_DIV_MASK) >> SCFR1_PCI_DIV_SHIFT;
John Rigby5f91db72008-02-26 09:38:14 -070093 if (pci_div != 0) {
94 pci_clk = csb_clk / pci_div;
95 } else {
96 /* in case we cannot get a sane IPS divisor, fail gracefully */
97 pci_clk = 333333;
98 }
Rafal Jaworowski8993e542007-07-27 14:43:59 +020099
Simon Glassfefb0982012-12-13 20:48:54 +0000100 gd->arch.ips_clk = ips_clk;
John Rigby5f91db72008-02-26 09:38:14 -0700101 gd->pci_clk = pci_clk;
Simon Glassfefb0982012-12-13 20:48:54 +0000102 gd->arch.csb_clk = csb_clk;
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200103 gd->cpu_clk = core_clk;
104 gd->bus_clk = csb_clk;
105 return 0;
106
107}
108
109/********************************************
110 * get_bus_freq
111 * return system bus freq in Hz
112 *********************************************/
113ulong get_bus_freq (ulong dummy)
114{
Simon Glassfefb0982012-12-13 20:48:54 +0000115 return gd->arch.csb_clk;
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200116}
117
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200118int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200119{
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200120 char buf[32];
121
John Rigby5f91db72008-02-26 09:38:14 -0700122 printf("Clock configuration:\n");
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200123 printf(" CPU: %-4s MHz\n", strmhz(buf, gd->cpu_clk));
Simon Glassfefb0982012-12-13 20:48:54 +0000124 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));
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200128 printf(" PCI: %-4s MHz\n", strmhz(buf, gd->pci_clk));
Simon Glassfefb0982012-12-13 20:48:54 +0000129 printf(" DDR: %-4s MHz\n",
130 strmhz(buf, 2 * gd->arch.csb_clk));
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200131 return 0;
132}
133
134U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyser2fb26042009-01-27 18:03:12 -0600135 "print clock configuration",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200136 " clocks"
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200137);