Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 5 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <mpc83xx.h> |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 28 | #include <command.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 29 | #include <asm/processor.h> |
| 30 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 33 | /* ----------------------------------------------------------------- */ |
| 34 | |
| 35 | typedef enum { |
| 36 | _unk, |
| 37 | _off, |
| 38 | _byp, |
| 39 | _x8, |
| 40 | _x4, |
| 41 | _x2, |
| 42 | _x1, |
| 43 | _1x, |
| 44 | _1_5x, |
| 45 | _2x, |
| 46 | _2_5x, |
| 47 | _3x |
| 48 | } mult_t; |
| 49 | |
| 50 | typedef struct { |
| 51 | mult_t core_csb_ratio; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 52 | mult_t vco_divider; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 53 | } corecnf_t; |
| 54 | |
| 55 | corecnf_t corecnf_tab[] = { |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 56 | {_byp, _byp}, /* 0x00 */ |
| 57 | {_byp, _byp}, /* 0x01 */ |
| 58 | {_byp, _byp}, /* 0x02 */ |
| 59 | {_byp, _byp}, /* 0x03 */ |
| 60 | {_byp, _byp}, /* 0x04 */ |
| 61 | {_byp, _byp}, /* 0x05 */ |
| 62 | {_byp, _byp}, /* 0x06 */ |
| 63 | {_byp, _byp}, /* 0x07 */ |
| 64 | {_1x, _x2}, /* 0x08 */ |
| 65 | {_1x, _x4}, /* 0x09 */ |
| 66 | {_1x, _x8}, /* 0x0A */ |
| 67 | {_1x, _x8}, /* 0x0B */ |
| 68 | {_1_5x, _x2}, /* 0x0C */ |
| 69 | {_1_5x, _x4}, /* 0x0D */ |
| 70 | {_1_5x, _x8}, /* 0x0E */ |
| 71 | {_1_5x, _x8}, /* 0x0F */ |
| 72 | {_2x, _x2}, /* 0x10 */ |
| 73 | {_2x, _x4}, /* 0x11 */ |
| 74 | {_2x, _x8}, /* 0x12 */ |
| 75 | {_2x, _x8}, /* 0x13 */ |
| 76 | {_2_5x, _x2}, /* 0x14 */ |
| 77 | {_2_5x, _x4}, /* 0x15 */ |
| 78 | {_2_5x, _x8}, /* 0x16 */ |
| 79 | {_2_5x, _x8}, /* 0x17 */ |
| 80 | {_3x, _x2}, /* 0x18 */ |
| 81 | {_3x, _x4}, /* 0x19 */ |
| 82 | {_3x, _x8}, /* 0x1A */ |
| 83 | {_3x, _x8}, /* 0x1B */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /* ----------------------------------------------------------------- */ |
| 87 | |
| 88 | /* |
| 89 | * |
| 90 | */ |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 91 | int get_clocks(void) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 92 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 94 | u32 pci_sync_in; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 95 | u8 spmf; |
| 96 | u8 clkin_div; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 97 | u32 sccr; |
| 98 | u32 corecnf_tab_index; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 99 | u8 corepll; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 100 | u32 lcrr; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 101 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 102 | u32 csb_clk; |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 103 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 104 | u32 tsec1_clk; |
| 105 | u32 tsec2_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 106 | u32 usbdr_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 107 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 108 | #ifdef CONFIG_MPC834X |
| 109 | u32 usbmph_clk; |
| 110 | #endif |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 111 | u32 core_clk; |
| 112 | u32 i2c1_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 113 | #if !defined(CONFIG_MPC832X) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 114 | u32 i2c2_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 115 | #endif |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 116 | #if defined(CONFIG_MPC8315) |
| 117 | u32 tdm_clk; |
| 118 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 119 | #if defined(CONFIG_MPC837X) |
| 120 | u32 sdhc_clk; |
| 121 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 122 | u32 enc_clk; |
| 123 | u32 lbiu_clk; |
| 124 | u32 lclk_clk; |
Kim Phillips | c02cf1e | 2008-03-28 10:18:40 -0500 | [diff] [blame] | 125 | u32 mem_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 126 | #if defined(CONFIG_MPC8360) |
Kim Phillips | c02cf1e | 2008-03-28 10:18:40 -0500 | [diff] [blame] | 127 | u32 mem_sec_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 128 | #endif |
| 129 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 130 | u32 qepmf; |
| 131 | u32 qepdf; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 132 | u32 qe_clk; |
| 133 | u32 brg_clk; |
| 134 | #endif |
Anton Vorontsov | 1a8206c | 2009-01-08 04:26:12 +0300 | [diff] [blame] | 135 | #if defined(CONFIG_MPC837X) || defined(CONFIG_MPC831X) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 136 | u32 pciexp1_clk; |
| 137 | u32 pciexp2_clk; |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 138 | #endif |
| 139 | #if defined(CONFIG_MPC837X) || defined(CONFIG_MPC8315) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 140 | u32 sata_clk; |
| 141 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 142 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 143 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 144 | return -1; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 145 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 146 | clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT); |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 147 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 148 | if (im->reset.rcwh & HRCWH_PCI_HOST) { |
| 149 | #if defined(CONFIG_83XX_CLKIN) |
| 150 | pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div); |
| 151 | #else |
| 152 | pci_sync_in = 0xDEADBEEF; |
| 153 | #endif |
| 154 | } else { |
| 155 | #if defined(CONFIG_83XX_PCICLK) |
| 156 | pci_sync_in = CONFIG_83XX_PCICLK; |
| 157 | #else |
| 158 | pci_sync_in = 0xDEADBEEF; |
| 159 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 160 | } |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 161 | |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 162 | spmf = ((im->reset.rcwl & HRCWL_SPMF) >> HRCWL_SPMF_SHIFT); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 163 | csb_clk = pci_sync_in * (1 + clkin_div) * spmf; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 164 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 165 | sccr = im->clk.sccr; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 166 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 167 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 168 | switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) { |
| 169 | case 0: |
| 170 | tsec1_clk = 0; |
| 171 | break; |
| 172 | case 1: |
| 173 | tsec1_clk = csb_clk; |
| 174 | break; |
| 175 | case 2: |
| 176 | tsec1_clk = csb_clk / 2; |
| 177 | break; |
| 178 | case 3: |
| 179 | tsec1_clk = csb_clk / 3; |
| 180 | break; |
| 181 | default: |
| 182 | /* unkown SCCR_TSEC1CM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 183 | return -2; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 184 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 185 | |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 186 | switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) { |
| 187 | case 0: |
| 188 | usbdr_clk = 0; |
| 189 | break; |
| 190 | case 1: |
| 191 | usbdr_clk = csb_clk; |
| 192 | break; |
| 193 | case 2: |
| 194 | usbdr_clk = csb_clk / 2; |
| 195 | break; |
| 196 | case 3: |
| 197 | usbdr_clk = csb_clk / 3; |
| 198 | break; |
| 199 | default: |
| 200 | /* unkown SCCR_USBDRCM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 201 | return -3; |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 202 | } |
| 203 | #endif |
| 204 | |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 205 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC837X) || defined(CONFIG_MPC8315) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 206 | switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) { |
| 207 | case 0: |
| 208 | tsec2_clk = 0; |
| 209 | break; |
| 210 | case 1: |
| 211 | tsec2_clk = csb_clk; |
| 212 | break; |
| 213 | case 2: |
| 214 | tsec2_clk = csb_clk / 2; |
| 215 | break; |
| 216 | case 3: |
| 217 | tsec2_clk = csb_clk / 3; |
| 218 | break; |
| 219 | default: |
| 220 | /* unkown SCCR_TSEC2CM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 221 | return -4; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 222 | } |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 223 | #elif defined(CONFIG_MPC8313) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 224 | tsec2_clk = tsec1_clk; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 225 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 226 | if (!(sccr & SCCR_TSEC1ON)) |
| 227 | tsec1_clk = 0; |
| 228 | if (!(sccr & SCCR_TSEC2ON)) |
| 229 | tsec2_clk = 0; |
| 230 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 231 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 232 | #if defined(CONFIG_MPC834X) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 233 | switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) { |
| 234 | case 0: |
| 235 | usbmph_clk = 0; |
| 236 | break; |
| 237 | case 1: |
| 238 | usbmph_clk = csb_clk; |
| 239 | break; |
| 240 | case 2: |
| 241 | usbmph_clk = csb_clk / 2; |
| 242 | break; |
| 243 | case 3: |
| 244 | usbmph_clk = csb_clk / 3; |
| 245 | break; |
| 246 | default: |
| 247 | /* unkown SCCR_USBMPHCM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 248 | return -5; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 249 | } |
| 250 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 251 | if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) { |
| 252 | /* if USB MPH clock is not disabled and |
| 253 | * USB DR clock is not disabled then |
| 254 | * USB MPH & USB DR must have the same rate |
| 255 | */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 256 | return -6; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 257 | } |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 258 | #endif |
| 259 | switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) { |
| 260 | case 0: |
| 261 | enc_clk = 0; |
| 262 | break; |
| 263 | case 1: |
| 264 | enc_clk = csb_clk; |
| 265 | break; |
| 266 | case 2: |
| 267 | enc_clk = csb_clk / 2; |
| 268 | break; |
| 269 | case 3: |
| 270 | enc_clk = csb_clk / 3; |
| 271 | break; |
| 272 | default: |
| 273 | /* unkown SCCR_ENCCM value */ |
| 274 | return -7; |
| 275 | } |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 276 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 277 | #if defined(CONFIG_MPC837X) |
| 278 | switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) { |
| 279 | case 0: |
| 280 | sdhc_clk = 0; |
| 281 | break; |
| 282 | case 1: |
| 283 | sdhc_clk = csb_clk; |
| 284 | break; |
| 285 | case 2: |
| 286 | sdhc_clk = csb_clk / 2; |
| 287 | break; |
| 288 | case 3: |
| 289 | sdhc_clk = csb_clk / 3; |
| 290 | break; |
| 291 | default: |
| 292 | /* unkown SCCR_SDHCCM value */ |
| 293 | return -8; |
| 294 | } |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 295 | #endif |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 296 | #if defined(CONFIG_MPC8315) |
| 297 | switch ((sccr & SCCR_TDMCM) >> SCCR_TDMCM_SHIFT) { |
| 298 | case 0: |
| 299 | tdm_clk = 0; |
| 300 | break; |
| 301 | case 1: |
| 302 | tdm_clk = csb_clk; |
| 303 | break; |
| 304 | case 2: |
| 305 | tdm_clk = csb_clk / 2; |
| 306 | break; |
| 307 | case 3: |
| 308 | tdm_clk = csb_clk / 3; |
| 309 | break; |
| 310 | default: |
| 311 | /* unkown SCCR_TDMCM value */ |
| 312 | return -8; |
| 313 | } |
| 314 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 315 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 316 | #if defined(CONFIG_MPC834X) |
| 317 | i2c1_clk = tsec2_clk; |
| 318 | #elif defined(CONFIG_MPC8360) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 319 | i2c1_clk = csb_clk; |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 320 | #elif defined(CONFIG_MPC832X) |
| 321 | i2c1_clk = enc_clk; |
| 322 | #elif defined(CONFIG_MPC831X) |
| 323 | i2c1_clk = enc_clk; |
| 324 | #elif defined(CONFIG_MPC837X) |
| 325 | i2c1_clk = sdhc_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 326 | #endif |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 327 | #if !defined(CONFIG_MPC832X) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 328 | i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */ |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 329 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 330 | |
Anton Vorontsov | 1a8206c | 2009-01-08 04:26:12 +0300 | [diff] [blame] | 331 | #if defined(CONFIG_MPC837X) || defined(CONFIG_MPC831X) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 332 | switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 333 | case 0: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 334 | pciexp1_clk = 0; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 335 | break; |
| 336 | case 1: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 337 | pciexp1_clk = csb_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 338 | break; |
| 339 | case 2: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 340 | pciexp1_clk = csb_clk / 2; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 341 | break; |
| 342 | case 3: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 343 | pciexp1_clk = csb_clk / 3; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 344 | break; |
| 345 | default: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 346 | /* unkown SCCR_PCIEXP1CM value */ |
| 347 | return -9; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 348 | } |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 349 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 350 | switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) { |
| 351 | case 0: |
| 352 | pciexp2_clk = 0; |
| 353 | break; |
| 354 | case 1: |
| 355 | pciexp2_clk = csb_clk; |
| 356 | break; |
| 357 | case 2: |
| 358 | pciexp2_clk = csb_clk / 2; |
| 359 | break; |
| 360 | case 3: |
| 361 | pciexp2_clk = csb_clk / 3; |
| 362 | break; |
| 363 | default: |
| 364 | /* unkown SCCR_PCIEXP2CM value */ |
| 365 | return -10; |
| 366 | } |
| 367 | #endif |
| 368 | |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 369 | #if defined(CONFIG_MPC837X) || defined(CONFIG_MPC8315) |
Dave Liu | b7896ad | 2008-01-17 18:23:19 +0800 | [diff] [blame] | 370 | switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) { |
| 371 | case 0: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 372 | sata_clk = 0; |
| 373 | break; |
Dave Liu | b7896ad | 2008-01-17 18:23:19 +0800 | [diff] [blame] | 374 | case 1: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 375 | sata_clk = csb_clk; |
| 376 | break; |
Dave Liu | b7896ad | 2008-01-17 18:23:19 +0800 | [diff] [blame] | 377 | case 2: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 378 | sata_clk = csb_clk / 2; |
| 379 | break; |
Dave Liu | b7896ad | 2008-01-17 18:23:19 +0800 | [diff] [blame] | 380 | case 3: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 381 | sata_clk = csb_clk / 3; |
| 382 | break; |
| 383 | default: |
Kim Phillips | 19a91de | 2008-01-16 12:06:16 -0600 | [diff] [blame] | 384 | /* unkown SCCR_SATACM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 385 | return -11; |
| 386 | } |
| 387 | #endif |
| 388 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 389 | lbiu_clk = csb_clk * |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 390 | (1 + ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT)); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 391 | lcrr = (im->lbus.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT; |
| 392 | switch (lcrr) { |
| 393 | case 2: |
| 394 | case 4: |
| 395 | case 8: |
| 396 | lclk_clk = lbiu_clk / lcrr; |
| 397 | break; |
| 398 | default: |
| 399 | /* unknown lcrr */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 400 | return -12; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 401 | } |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 402 | |
Kim Phillips | c02cf1e | 2008-03-28 10:18:40 -0500 | [diff] [blame] | 403 | mem_clk = csb_clk * |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 404 | (1 + ((im->reset.rcwl & HRCWL_DDRCM) >> HRCWL_DDRCM_SHIFT)); |
| 405 | corepll = (im->reset.rcwl & HRCWL_COREPLL) >> HRCWL_COREPLL_SHIFT; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 406 | #if defined(CONFIG_MPC8360) |
Kim Phillips | c02cf1e | 2008-03-28 10:18:40 -0500 | [diff] [blame] | 407 | mem_sec_clk = csb_clk * (1 + |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 408 | ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 409 | #endif |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 410 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 411 | corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5); |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 412 | if (corecnf_tab_index > (sizeof(corecnf_tab) / sizeof(corecnf_t))) { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 413 | /* corecnf_tab_index is too high, possibly worng value */ |
| 414 | return -11; |
| 415 | } |
| 416 | switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) { |
| 417 | case _byp: |
| 418 | case _x1: |
| 419 | case _1x: |
| 420 | core_clk = csb_clk; |
| 421 | break; |
| 422 | case _1_5x: |
| 423 | core_clk = (3 * csb_clk) / 2; |
| 424 | break; |
| 425 | case _2x: |
| 426 | core_clk = 2 * csb_clk; |
| 427 | break; |
| 428 | case _2_5x: |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 429 | core_clk = (5 * csb_clk) / 2; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 430 | break; |
| 431 | case _3x: |
| 432 | core_clk = 3 * csb_clk; |
| 433 | break; |
| 434 | default: |
| 435 | /* unkown core to csb ratio */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 436 | return -13; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 437 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 438 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 439 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 440 | qepmf = (im->reset.rcwl & HRCWL_CEPMF) >> HRCWL_CEPMF_SHIFT; |
| 441 | qepdf = (im->reset.rcwl & HRCWL_CEPDF) >> HRCWL_CEPDF_SHIFT; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 442 | qe_clk = (pci_sync_in * qepmf) / (1 + qepdf); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 443 | brg_clk = qe_clk / 2; |
| 444 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 445 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 446 | gd->csb_clk = csb_clk; |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 447 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 448 | gd->tsec1_clk = tsec1_clk; |
| 449 | gd->tsec2_clk = tsec2_clk; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 450 | gd->usbdr_clk = usbdr_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 451 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 452 | #if defined(CONFIG_MPC834X) |
| 453 | gd->usbmph_clk = usbmph_clk; |
| 454 | #endif |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 455 | #if defined(CONFIG_MPC8315) |
| 456 | gd->tdm_clk = tdm_clk; |
| 457 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 458 | #if defined(CONFIG_MPC837X) |
| 459 | gd->sdhc_clk = sdhc_clk; |
| 460 | #endif |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 461 | gd->core_clk = core_clk; |
| 462 | gd->i2c1_clk = i2c1_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 463 | #if !defined(CONFIG_MPC832X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 464 | gd->i2c2_clk = i2c2_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 465 | #endif |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 466 | gd->enc_clk = enc_clk; |
| 467 | gd->lbiu_clk = lbiu_clk; |
| 468 | gd->lclk_clk = lclk_clk; |
Kim Phillips | c02cf1e | 2008-03-28 10:18:40 -0500 | [diff] [blame] | 469 | gd->mem_clk = mem_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 470 | #if defined(CONFIG_MPC8360) |
Kim Phillips | c02cf1e | 2008-03-28 10:18:40 -0500 | [diff] [blame] | 471 | gd->mem_sec_clk = mem_sec_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 472 | #endif |
| 473 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 474 | gd->qe_clk = qe_clk; |
| 475 | gd->brg_clk = brg_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 476 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 477 | #if defined(CONFIG_MPC837X) |
| 478 | gd->pciexp1_clk = pciexp1_clk; |
| 479 | gd->pciexp2_clk = pciexp2_clk; |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 480 | #endif |
| 481 | #if defined(CONFIG_MPC837X) || defined(CONFIG_MPC8315) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 482 | gd->sata_clk = sata_clk; |
| 483 | #endif |
Kim Phillips | cd9fd70 | 2007-08-15 22:30:19 -0500 | [diff] [blame] | 484 | gd->pci_clk = pci_sync_in; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 485 | gd->cpu_clk = gd->core_clk; |
| 486 | gd->bus_clk = gd->csb_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 487 | return 0; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 488 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /******************************************** |
| 492 | * get_bus_freq |
| 493 | * return system bus freq in Hz |
| 494 | *********************************************/ |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 495 | ulong get_bus_freq(ulong dummy) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 496 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 497 | return gd->csb_clk; |
| 498 | } |
| 499 | |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 500 | int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 501 | { |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 502 | char buf[32]; |
| 503 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 504 | printf("Clock configuration:\n"); |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 505 | printf(" Core: %-4s MHz\n", strmhz(buf, gd->core_clk)); |
| 506 | printf(" Coherent System Bus: %-4s MHz\n", strmhz(buf, gd->csb_clk)); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 507 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 508 | printf(" QE: %-4s MHz\n", strmhz(buf, gd->qe_clk)); |
| 509 | printf(" BRG: %-4s MHz\n", strmhz(buf, gd->brg_clk)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 510 | #endif |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 511 | printf(" Local Bus Controller:%-4s MHz\n", strmhz(buf, gd->lbiu_clk)); |
| 512 | printf(" Local Bus: %-4s MHz\n", strmhz(buf, gd->lclk_clk)); |
| 513 | printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk)); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 514 | #if defined(CONFIG_MPC8360) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 515 | printf(" DDR Secondary: %-4s MHz\n", strmhz(buf, gd->mem_sec_clk)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 516 | #endif |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 517 | printf(" SEC: %-4s MHz\n", strmhz(buf, gd->enc_clk)); |
| 518 | printf(" I2C1: %-4s MHz\n", strmhz(buf, gd->i2c1_clk)); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 519 | #if !defined(CONFIG_MPC832X) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 520 | printf(" I2C2: %-4s MHz\n", strmhz(buf, gd->i2c2_clk)); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 521 | #endif |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 522 | #if defined(CONFIG_MPC8315) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 523 | printf(" TDM: %-4s MHz\n", strmhz(buf, gd->tdm_clk)); |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 524 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 525 | #if defined(CONFIG_MPC837X) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 526 | printf(" SDHC: %-4s MHz\n", strmhz(buf, gd->sdhc_clk)); |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 527 | #endif |
| 528 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 529 | printf(" TSEC1: %-4s MHz\n", strmhz(buf, gd->tsec1_clk)); |
| 530 | printf(" TSEC2: %-4s MHz\n", strmhz(buf, gd->tsec2_clk)); |
| 531 | printf(" USB DR: %-4s MHz\n", strmhz(buf, gd->usbdr_clk)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 532 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 533 | #if defined(CONFIG_MPC834X) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 534 | printf(" USB MPH: %-4s MHz\n", strmhz(buf, gd->usbmph_clk)); |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 535 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 536 | #if defined(CONFIG_MPC837X) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 537 | printf(" PCIEXP1: %-4s MHz\n", strmhz(buf, gd->pciexp1_clk)); |
| 538 | printf(" PCIEXP2: %-4s MHz\n", strmhz(buf, gd->pciexp2_clk)); |
Dave Liu | e0cfec8 | 2007-09-18 12:36:58 +0800 | [diff] [blame] | 539 | #endif |
| 540 | #if defined(CONFIG_MPC837X) || defined(CONFIG_MPC8315) |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 541 | printf(" SATA: %-4s MHz\n", strmhz(buf, gd->sata_clk)); |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 542 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 543 | return 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 544 | } |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 545 | |
| 546 | U_BOOT_CMD(clocks, 1, 0, do_clocks, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 547 | "print clock configuration", |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 548 | " clocks\n" |
| 549 | ); |