Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 1 | /* |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2009 |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * Copyright (C) 2004-2006 Freescale Semiconductor, Inc. |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 8 | * |
| 9 | * Based on the MPC83xx code. |
| 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 13 | #include <command.h> |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 14 | #include <asm/io.h> |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 15 | #include <asm/processor.h> |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | static 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 | |
| 26 | static 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 | |
| 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} |
| 45 | }; |
| 46 | |
| 47 | int get_clocks (void) |
| 48 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 50 | u8 spmf; |
| 51 | u8 cpmf; |
| 52 | u8 sys_div; |
| 53 | u8 ips_div; |
John Rigby | d1228c9 | 2008-02-26 09:38:14 -0700 | [diff] [blame] | 54 | u8 pci_div; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | u32 ref_clk = CONFIG_SYS_MPC512X_CLKIN; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 56 | u32 spll; |
| 57 | u32 sys_clk; |
| 58 | u32 core_clk; |
| 59 | u32 csb_clk; |
| 60 | u32 ips_clk; |
John Rigby | d1228c9 | 2008-02-26 09:38:14 -0700 | [diff] [blame] | 61 | u32 pci_clk; |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 62 | u32 reg; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 63 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 64 | reg = in_be32(&im->sysconf.immrbar); |
| 65 | if ((reg & IMMRBAR_BASE_ADDR) != (u32) im) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 66 | return -1; |
| 67 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 68 | reg = in_be32(&im->clk.spmr); |
| 69 | spmf = (reg & SPMR_SPMF) >> SPMR_SPMF_SHIFT; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 70 | spll = ref_clk * spmf_mult[spmf]; |
Wolfgang Denk | 530181f | 2007-08-02 21:27:46 +0200 | [diff] [blame] | 71 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 72 | reg = in_be32(&im->clk.scfr[1]); |
| 73 | sys_div = (reg & SCFR2_SYS_DIV) >> SCFR2_SYS_DIV_SHIFT; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 74 | sys_clk = (spll * sys_dividors[sys_div][1]) / sys_dividors[sys_div][0]; |
| 75 | |
| 76 | csb_clk = sys_clk / 2; |
| 77 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 78 | reg = in_be32(&im->clk.spmr); |
| 79 | cpmf = (reg & SPMR_CPMF) >> SPMR_CPMF_SHIFT; |
Wolfgang Denk | 530181f | 2007-08-02 21:27:46 +0200 | [diff] [blame] | 80 | core_clk = (csb_clk * cpmf_mult[cpmf][0]) / cpmf_mult[cpmf][1]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 81 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 82 | reg = in_be32(&im->clk.scfr[0]); |
| 83 | ips_div = (reg & SCFR1_IPS_DIV_MASK) >> SCFR1_IPS_DIV_SHIFT; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 84 | 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 Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 90 | |
| 91 | reg = in_be32(&im->clk.scfr[0]); |
| 92 | pci_div = (reg & SCFR1_PCI_DIV_MASK) >> SCFR1_PCI_DIV_SHIFT; |
John Rigby | d1228c9 | 2008-02-26 09:38:14 -0700 | [diff] [blame] | 93 | 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 Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 99 | |
Simon Glass | 6c6cbd1 | 2012-12-13 20:48:54 +0000 | [diff] [blame] | 100 | gd->arch.ips_clk = ips_clk; |
John Rigby | d1228c9 | 2008-02-26 09:38:14 -0700 | [diff] [blame] | 101 | gd->pci_clk = pci_clk; |
Simon Glass | 6c6cbd1 | 2012-12-13 20:48:54 +0000 | [diff] [blame] | 102 | gd->arch.csb_clk = csb_clk; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 103 | 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 | *********************************************/ |
| 113 | ulong get_bus_freq (ulong dummy) |
| 114 | { |
Simon Glass | 6c6cbd1 | 2012-12-13 20:48:54 +0000 | [diff] [blame] | 115 | return gd->arch.csb_clk; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 118 | int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 119 | { |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 120 | char buf[32]; |
| 121 | |
John Rigby | d1228c9 | 2008-02-26 09:38:14 -0700 | [diff] [blame] | 122 | printf("Clock configuration:\n"); |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 123 | printf(" CPU: %-4s MHz\n", strmhz(buf, gd->cpu_clk)); |
Simon Glass | 6c6cbd1 | 2012-12-13 20:48:54 +0000 | [diff] [blame] | 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)); |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 128 | printf(" PCI: %-4s MHz\n", strmhz(buf, gd->pci_clk)); |
Simon Glass | 6c6cbd1 | 2012-12-13 20:48:54 +0000 | [diff] [blame] | 129 | printf(" DDR: %-4s MHz\n", |
| 130 | strmhz(buf, 2 * gd->arch.csb_clk)); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | U_BOOT_CMD(clocks, 1, 0, do_clocks, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 135 | "print clock configuration", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 136 | " clocks" |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 137 | ); |