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 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 93 | volatile immap_t *im = (immap_t *) CFG_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 | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 116 | #if defined(CONFIG_MPC837X) |
| 117 | u32 sdhc_clk; |
| 118 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 119 | u32 enc_clk; |
| 120 | u32 lbiu_clk; |
| 121 | u32 lclk_clk; |
| 122 | u32 ddr_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 123 | #if defined(CONFIG_MPC8360) |
| 124 | u32 ddr_sec_clk; |
| 125 | #endif |
| 126 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 127 | u32 qepmf; |
| 128 | u32 qepdf; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 129 | u32 qe_clk; |
| 130 | u32 brg_clk; |
| 131 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 132 | #if defined(CONFIG_MPC837X) |
| 133 | u32 pciexp1_clk; |
| 134 | u32 pciexp2_clk; |
| 135 | u32 sata_clk; |
| 136 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 137 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 138 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 139 | return -1; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 140 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 141 | clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT); |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 142 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 143 | if (im->reset.rcwh & HRCWH_PCI_HOST) { |
| 144 | #if defined(CONFIG_83XX_CLKIN) |
| 145 | pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div); |
| 146 | #else |
| 147 | pci_sync_in = 0xDEADBEEF; |
| 148 | #endif |
| 149 | } else { |
| 150 | #if defined(CONFIG_83XX_PCICLK) |
| 151 | pci_sync_in = CONFIG_83XX_PCICLK; |
| 152 | #else |
| 153 | pci_sync_in = 0xDEADBEEF; |
| 154 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 155 | } |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 156 | |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 157 | spmf = ((im->reset.rcwl & HRCWL_SPMF) >> HRCWL_SPMF_SHIFT); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 158 | csb_clk = pci_sync_in * (1 + clkin_div) * spmf; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 159 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 160 | sccr = im->clk.sccr; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 161 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 162 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 163 | switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) { |
| 164 | case 0: |
| 165 | tsec1_clk = 0; |
| 166 | break; |
| 167 | case 1: |
| 168 | tsec1_clk = csb_clk; |
| 169 | break; |
| 170 | case 2: |
| 171 | tsec1_clk = csb_clk / 2; |
| 172 | break; |
| 173 | case 3: |
| 174 | tsec1_clk = csb_clk / 3; |
| 175 | break; |
| 176 | default: |
| 177 | /* unkown SCCR_TSEC1CM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 178 | return -2; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 179 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 180 | |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 181 | switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) { |
| 182 | case 0: |
| 183 | usbdr_clk = 0; |
| 184 | break; |
| 185 | case 1: |
| 186 | usbdr_clk = csb_clk; |
| 187 | break; |
| 188 | case 2: |
| 189 | usbdr_clk = csb_clk / 2; |
| 190 | break; |
| 191 | case 3: |
| 192 | usbdr_clk = csb_clk / 3; |
| 193 | break; |
| 194 | default: |
| 195 | /* unkown SCCR_USBDRCM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 196 | return -3; |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 197 | } |
| 198 | #endif |
| 199 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 200 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC837X) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 201 | switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) { |
| 202 | case 0: |
| 203 | tsec2_clk = 0; |
| 204 | break; |
| 205 | case 1: |
| 206 | tsec2_clk = csb_clk; |
| 207 | break; |
| 208 | case 2: |
| 209 | tsec2_clk = csb_clk / 2; |
| 210 | break; |
| 211 | case 3: |
| 212 | tsec2_clk = csb_clk / 3; |
| 213 | break; |
| 214 | default: |
| 215 | /* unkown SCCR_TSEC2CM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 216 | return -4; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 217 | } |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 218 | #elif defined(CONFIG_MPC831X) |
| 219 | tsec2_clk = tsec1_clk; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 220 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 221 | if (!(sccr & SCCR_TSEC1ON)) |
| 222 | tsec1_clk = 0; |
| 223 | if (!(sccr & SCCR_TSEC2ON)) |
| 224 | tsec2_clk = 0; |
| 225 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 226 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 227 | #if defined(CONFIG_MPC834X) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 228 | switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) { |
| 229 | case 0: |
| 230 | usbmph_clk = 0; |
| 231 | break; |
| 232 | case 1: |
| 233 | usbmph_clk = csb_clk; |
| 234 | break; |
| 235 | case 2: |
| 236 | usbmph_clk = csb_clk / 2; |
| 237 | break; |
| 238 | case 3: |
| 239 | usbmph_clk = csb_clk / 3; |
| 240 | break; |
| 241 | default: |
| 242 | /* unkown SCCR_USBMPHCM value */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 243 | return -5; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 244 | } |
| 245 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 246 | if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) { |
| 247 | /* if USB MPH clock is not disabled and |
| 248 | * USB DR clock is not disabled then |
| 249 | * USB MPH & USB DR must have the same rate |
| 250 | */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 251 | return -6; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 252 | } |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 253 | #endif |
| 254 | switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) { |
| 255 | case 0: |
| 256 | enc_clk = 0; |
| 257 | break; |
| 258 | case 1: |
| 259 | enc_clk = csb_clk; |
| 260 | break; |
| 261 | case 2: |
| 262 | enc_clk = csb_clk / 2; |
| 263 | break; |
| 264 | case 3: |
| 265 | enc_clk = csb_clk / 3; |
| 266 | break; |
| 267 | default: |
| 268 | /* unkown SCCR_ENCCM value */ |
| 269 | return -7; |
| 270 | } |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 271 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 272 | #if defined(CONFIG_MPC837X) |
| 273 | switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) { |
| 274 | case 0: |
| 275 | sdhc_clk = 0; |
| 276 | break; |
| 277 | case 1: |
| 278 | sdhc_clk = csb_clk; |
| 279 | break; |
| 280 | case 2: |
| 281 | sdhc_clk = csb_clk / 2; |
| 282 | break; |
| 283 | case 3: |
| 284 | sdhc_clk = csb_clk / 3; |
| 285 | break; |
| 286 | default: |
| 287 | /* unkown SCCR_SDHCCM value */ |
| 288 | return -8; |
| 289 | } |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 290 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 291 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 292 | #if defined(CONFIG_MPC834X) |
| 293 | i2c1_clk = tsec2_clk; |
| 294 | #elif defined(CONFIG_MPC8360) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 295 | i2c1_clk = csb_clk; |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 296 | #elif defined(CONFIG_MPC832X) |
| 297 | i2c1_clk = enc_clk; |
| 298 | #elif defined(CONFIG_MPC831X) |
| 299 | i2c1_clk = enc_clk; |
| 300 | #elif defined(CONFIG_MPC837X) |
| 301 | i2c1_clk = sdhc_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 302 | #endif |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 303 | #if !defined(CONFIG_MPC832X) |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 304 | i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */ |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 305 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 306 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 307 | #if defined(CONFIG_MPC837X) |
| 308 | switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 309 | case 0: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 310 | pciexp1_clk = 0; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 311 | break; |
| 312 | case 1: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 313 | pciexp1_clk = csb_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 314 | break; |
| 315 | case 2: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 316 | pciexp1_clk = csb_clk / 2; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 317 | break; |
| 318 | case 3: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 319 | pciexp1_clk = csb_clk / 3; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 320 | break; |
| 321 | default: |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 322 | /* unkown SCCR_PCIEXP1CM value */ |
| 323 | return -9; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 324 | } |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 325 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 326 | switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) { |
| 327 | case 0: |
| 328 | pciexp2_clk = 0; |
| 329 | break; |
| 330 | case 1: |
| 331 | pciexp2_clk = csb_clk; |
| 332 | break; |
| 333 | case 2: |
| 334 | pciexp2_clk = csb_clk / 2; |
| 335 | break; |
| 336 | case 3: |
| 337 | pciexp2_clk = csb_clk / 3; |
| 338 | break; |
| 339 | default: |
| 340 | /* unkown SCCR_PCIEXP2CM value */ |
| 341 | return -10; |
| 342 | } |
| 343 | #endif |
| 344 | |
| 345 | #if defined(CONFIG_MPC837X) |
| 346 | switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) { |
| 347 | case 0: |
| 348 | sata_clk = 0; |
| 349 | break; |
| 350 | case 1: |
| 351 | sata_clk = csb_clk; |
| 352 | break; |
| 353 | case 2: |
| 354 | sata_clk = csb_clk / 2; |
| 355 | break; |
| 356 | case 3: |
| 357 | sata_clk = csb_clk / 3; |
| 358 | break; |
| 359 | default: |
| 360 | /* unkown SCCR_SATA1CM value */ |
| 361 | return -11; |
| 362 | } |
| 363 | #endif |
| 364 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 365 | lbiu_clk = csb_clk * |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 366 | (1 + ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT)); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 367 | lcrr = (im->lbus.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT; |
| 368 | switch (lcrr) { |
| 369 | case 2: |
| 370 | case 4: |
| 371 | case 8: |
| 372 | lclk_clk = lbiu_clk / lcrr; |
| 373 | break; |
| 374 | default: |
| 375 | /* unknown lcrr */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 376 | return -12; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 377 | } |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 378 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 379 | ddr_clk = csb_clk * |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 380 | (1 + ((im->reset.rcwl & HRCWL_DDRCM) >> HRCWL_DDRCM_SHIFT)); |
| 381 | corepll = (im->reset.rcwl & HRCWL_COREPLL) >> HRCWL_COREPLL_SHIFT; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 382 | #if defined(CONFIG_MPC8360) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 383 | ddr_sec_clk = csb_clk * (1 + |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 384 | ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 385 | #endif |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 386 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 387 | corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5); |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 388 | if (corecnf_tab_index > (sizeof(corecnf_tab) / sizeof(corecnf_t))) { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 389 | /* corecnf_tab_index is too high, possibly worng value */ |
| 390 | return -11; |
| 391 | } |
| 392 | switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) { |
| 393 | case _byp: |
| 394 | case _x1: |
| 395 | case _1x: |
| 396 | core_clk = csb_clk; |
| 397 | break; |
| 398 | case _1_5x: |
| 399 | core_clk = (3 * csb_clk) / 2; |
| 400 | break; |
| 401 | case _2x: |
| 402 | core_clk = 2 * csb_clk; |
| 403 | break; |
| 404 | case _2_5x: |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 405 | core_clk = (5 * csb_clk) / 2; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 406 | break; |
| 407 | case _3x: |
| 408 | core_clk = 3 * csb_clk; |
| 409 | break; |
| 410 | default: |
| 411 | /* unkown core to csb ratio */ |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 412 | return -13; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 413 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 414 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 415 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 416 | qepmf = (im->reset.rcwl & HRCWL_CEPMF) >> HRCWL_CEPMF_SHIFT; |
| 417 | qepdf = (im->reset.rcwl & HRCWL_CEPDF) >> HRCWL_CEPDF_SHIFT; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 418 | qe_clk = (pci_sync_in * qepmf) / (1 + qepdf); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 419 | brg_clk = qe_clk / 2; |
| 420 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 421 | |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 422 | gd->csb_clk = csb_clk; |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 423 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 424 | gd->tsec1_clk = tsec1_clk; |
| 425 | gd->tsec2_clk = tsec2_clk; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 426 | gd->usbdr_clk = usbdr_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 427 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 428 | #if defined(CONFIG_MPC834X) |
| 429 | gd->usbmph_clk = usbmph_clk; |
| 430 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 431 | #if defined(CONFIG_MPC837X) |
| 432 | gd->sdhc_clk = sdhc_clk; |
| 433 | #endif |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 434 | gd->core_clk = core_clk; |
| 435 | gd->i2c1_clk = i2c1_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 436 | #if !defined(CONFIG_MPC832X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 437 | gd->i2c2_clk = i2c2_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 438 | #endif |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 439 | gd->enc_clk = enc_clk; |
| 440 | gd->lbiu_clk = lbiu_clk; |
| 441 | gd->lclk_clk = lclk_clk; |
| 442 | gd->ddr_clk = ddr_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 443 | #if defined(CONFIG_MPC8360) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 444 | gd->ddr_sec_clk = ddr_sec_clk; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 445 | #endif |
| 446 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 447 | gd->qe_clk = qe_clk; |
| 448 | gd->brg_clk = brg_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 449 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 450 | #if defined(CONFIG_MPC837X) |
| 451 | gd->pciexp1_clk = pciexp1_clk; |
| 452 | gd->pciexp2_clk = pciexp2_clk; |
| 453 | gd->sata_clk = sata_clk; |
| 454 | #endif |
Kim Phillips | cd9fd70 | 2007-08-15 22:30:19 -0500 | [diff] [blame] | 455 | gd->pci_clk = pci_sync_in; |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 456 | gd->cpu_clk = gd->core_clk; |
| 457 | gd->bus_clk = gd->csb_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 458 | return 0; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 459 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /******************************************** |
| 463 | * get_bus_freq |
| 464 | * return system bus freq in Hz |
| 465 | *********************************************/ |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 466 | ulong get_bus_freq(ulong dummy) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 467 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 468 | return gd->csb_clk; |
| 469 | } |
| 470 | |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 471 | 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] | 472 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 473 | printf("Clock configuration:\n"); |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 474 | printf(" Core: %4d MHz\n", gd->core_clk / 1000000); |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 475 | printf(" Coherent System Bus: %4d MHz\n", gd->csb_clk / 1000000); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 476 | #if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 477 | printf(" QE: %4d MHz\n", gd->qe_clk / 1000000); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 478 | printf(" BRG: %4d MHz\n", gd->brg_clk / 1000000); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 479 | #endif |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 480 | printf(" Local Bus Controller:%4d MHz\n", gd->lbiu_clk / 1000000); |
| 481 | printf(" Local Bus: %4d MHz\n", gd->lclk_clk / 1000000); |
| 482 | printf(" DDR: %4d MHz\n", gd->ddr_clk / 1000000); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 483 | #if defined(CONFIG_MPC8360) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 484 | printf(" DDR Secondary: %4d MHz\n", gd->ddr_sec_clk / 1000000); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 485 | #endif |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 486 | printf(" SEC: %4d MHz\n", gd->enc_clk / 1000000); |
| 487 | printf(" I2C1: %4d MHz\n", gd->i2c1_clk / 1000000); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 488 | #if !defined(CONFIG_MPC832X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 489 | printf(" I2C2: %4d MHz\n", gd->i2c2_clk / 1000000); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 490 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 491 | #if defined(CONFIG_MPC837X) |
| 492 | printf(" SDHC: %4d MHz\n", gd->sdhc_clk / 1000000); |
| 493 | #endif |
| 494 | #if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X) || defined(CONFIG_MPC837X) |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 495 | printf(" TSEC1: %4d MHz\n", gd->tsec1_clk / 1000000); |
| 496 | printf(" TSEC2: %4d MHz\n", gd->tsec2_clk / 1000000); |
Kim Phillips | bae2479 | 2006-11-02 19:47:11 -0600 | [diff] [blame] | 497 | printf(" USB DR: %4d MHz\n", gd->usbdr_clk / 1000000); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 498 | #endif |
Scott Wood | c036fc9 | 2007-04-16 14:34:19 -0500 | [diff] [blame] | 499 | #if defined(CONFIG_MPC834X) |
| 500 | printf(" USB MPH: %4d MHz\n", gd->usbmph_clk / 1000000); |
| 501 | #endif |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame^] | 502 | #if defined(CONFIG_MPC837X) |
| 503 | printf(" PCIEXP1: %4d MHz\n", gd->pciexp1_clk / 1000000); |
| 504 | printf(" PCIEXP2: %4d MHz\n", gd->pciexp2_clk / 1000000); |
| 505 | printf(" SATA: %4d MHz\n", gd->sata_clk / 1000000); |
| 506 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 507 | return 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 508 | } |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 509 | |
| 510 | U_BOOT_CMD(clocks, 1, 0, do_clocks, |
| 511 | "clocks - print clock configuration\n", |
| 512 | " clocks\n" |
| 513 | ); |