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 | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 5 | * Copyright (C) 2004-2006 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 |
| 24 | * |
| 25 | * Change log: |
| 26 | * |
| 27 | * 20050101: Eran Liberty (liberty@freescale.com) |
| 28 | * Initial file creating (porting from 85XX & 8260) |
| 29 | */ |
| 30 | |
| 31 | #include <common.h> |
| 32 | #include <mpc83xx.h> |
| 33 | #include <asm/processor.h> |
| 34 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 37 | /* ----------------------------------------------------------------- */ |
| 38 | |
| 39 | typedef enum { |
| 40 | _unk, |
| 41 | _off, |
| 42 | _byp, |
| 43 | _x8, |
| 44 | _x4, |
| 45 | _x2, |
| 46 | _x1, |
| 47 | _1x, |
| 48 | _1_5x, |
| 49 | _2x, |
| 50 | _2_5x, |
| 51 | _3x |
| 52 | } mult_t; |
| 53 | |
| 54 | typedef struct { |
| 55 | mult_t core_csb_ratio; |
| 56 | mult_t vco_divider; |
| 57 | } corecnf_t; |
| 58 | |
| 59 | corecnf_t corecnf_tab[] = { |
| 60 | { _byp, _byp}, /* 0x00 */ |
| 61 | { _byp, _byp}, /* 0x01 */ |
| 62 | { _byp, _byp}, /* 0x02 */ |
| 63 | { _byp, _byp}, /* 0x03 */ |
| 64 | { _byp, _byp}, /* 0x04 */ |
| 65 | { _byp, _byp}, /* 0x05 */ |
| 66 | { _byp, _byp}, /* 0x06 */ |
| 67 | { _byp, _byp}, /* 0x07 */ |
| 68 | { _1x, _x2}, /* 0x08 */ |
| 69 | { _1x, _x4}, /* 0x09 */ |
| 70 | { _1x, _x8}, /* 0x0A */ |
| 71 | { _1x, _x8}, /* 0x0B */ |
| 72 | {_1_5x, _x2}, /* 0x0C */ |
| 73 | {_1_5x, _x4}, /* 0x0D */ |
| 74 | {_1_5x, _x8}, /* 0x0E */ |
| 75 | {_1_5x, _x8}, /* 0x0F */ |
| 76 | { _2x, _x2}, /* 0x10 */ |
| 77 | { _2x, _x4}, /* 0x11 */ |
| 78 | { _2x, _x8}, /* 0x12 */ |
| 79 | { _2x, _x8}, /* 0x13 */ |
| 80 | {_2_5x, _x2}, /* 0x14 */ |
| 81 | {_2_5x, _x4}, /* 0x15 */ |
| 82 | {_2_5x, _x8}, /* 0x16 */ |
| 83 | {_2_5x, _x8}, /* 0x17 */ |
| 84 | { _3x, _x2}, /* 0x18 */ |
| 85 | { _3x, _x4}, /* 0x19 */ |
| 86 | { _3x, _x8}, /* 0x1A */ |
| 87 | { _3x, _x8}, /* 0x1B */ |
| 88 | }; |
| 89 | |
| 90 | /* ----------------------------------------------------------------- */ |
| 91 | |
| 92 | /* |
| 93 | * |
| 94 | */ |
| 95 | int get_clocks (void) |
| 96 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 97 | volatile immap_t *im = (immap_t *)CFG_IMMRBAR; |
| 98 | u32 pci_sync_in; |
| 99 | u8 spmf; |
| 100 | u8 clkin_div; |
| 101 | u32 sccr; |
| 102 | u32 corecnf_tab_index; |
| 103 | u8 corepll; |
| 104 | u32 lcrr; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 105 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 106 | u32 csb_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 107 | #if defined(CONFIG_MPC8349) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 108 | u32 tsec1_clk; |
| 109 | u32 tsec2_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 110 | u32 usbmph_clk; |
| 111 | u32 usbdr_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 112 | #endif |
| 113 | u32 core_clk; |
| 114 | u32 i2c1_clk; |
| 115 | u32 i2c2_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 116 | u32 enc_clk; |
| 117 | u32 lbiu_clk; |
| 118 | u32 lclk_clk; |
| 119 | u32 ddr_clk; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 120 | #if defined (CONFIG_MPC8360) |
| 121 | u32 qepmf; |
| 122 | u32 qepdf; |
| 123 | u32 ddr_sec_clk; |
| 124 | u32 qe_clk; |
| 125 | u32 brg_clk; |
| 126 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 127 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 128 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) |
| 129 | return -1; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 130 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 131 | clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT); |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 132 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 133 | if (im->reset.rcwh & HRCWH_PCI_HOST) { |
| 134 | #if defined(CONFIG_83XX_CLKIN) |
| 135 | pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div); |
| 136 | #else |
| 137 | pci_sync_in = 0xDEADBEEF; |
| 138 | #endif |
| 139 | } else { |
| 140 | #if defined(CONFIG_83XX_PCICLK) |
| 141 | pci_sync_in = CONFIG_83XX_PCICLK; |
| 142 | #else |
| 143 | pci_sync_in = 0xDEADBEEF; |
| 144 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 145 | } |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 146 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 147 | spmf = ((im->reset.rcwl & RCWL_SPMF) >> RCWL_SPMF_SHIFT); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 148 | csb_clk = pci_sync_in * (1 + clkin_div) * spmf; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 149 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 150 | sccr = im->clk.sccr; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 151 | |
| 152 | #if defined(CONFIG_MPC8349) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 153 | switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) { |
| 154 | case 0: |
| 155 | tsec1_clk = 0; |
| 156 | break; |
| 157 | case 1: |
| 158 | tsec1_clk = csb_clk; |
| 159 | break; |
| 160 | case 2: |
| 161 | tsec1_clk = csb_clk / 2; |
| 162 | break; |
| 163 | case 3: |
| 164 | tsec1_clk = csb_clk / 3; |
| 165 | break; |
| 166 | default: |
| 167 | /* unkown SCCR_TSEC1CM value */ |
| 168 | return -4; |
| 169 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 170 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 171 | switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) { |
| 172 | case 0: |
| 173 | tsec2_clk = 0; |
| 174 | break; |
| 175 | case 1: |
| 176 | tsec2_clk = csb_clk; |
| 177 | break; |
| 178 | case 2: |
| 179 | tsec2_clk = csb_clk / 2; |
| 180 | break; |
| 181 | case 3: |
| 182 | tsec2_clk = csb_clk / 3; |
| 183 | break; |
| 184 | default: |
| 185 | /* unkown SCCR_TSEC2CM value */ |
| 186 | return -5; |
| 187 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 188 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 189 | i2c1_clk = tsec2_clk; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 190 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 191 | switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) { |
| 192 | case 0: |
| 193 | usbmph_clk = 0; |
| 194 | break; |
| 195 | case 1: |
| 196 | usbmph_clk = csb_clk; |
| 197 | break; |
| 198 | case 2: |
| 199 | usbmph_clk = csb_clk / 2; |
| 200 | break; |
| 201 | case 3: |
| 202 | usbmph_clk = csb_clk / 3; |
| 203 | break; |
| 204 | default: |
| 205 | /* unkown SCCR_USBMPHCM value */ |
| 206 | return -7; |
| 207 | } |
| 208 | |
| 209 | switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) { |
| 210 | case 0: |
| 211 | usbdr_clk = 0; |
| 212 | break; |
| 213 | case 1: |
| 214 | usbdr_clk = csb_clk; |
| 215 | break; |
| 216 | case 2: |
| 217 | usbdr_clk = csb_clk / 2; |
| 218 | break; |
| 219 | case 3: |
| 220 | usbdr_clk = csb_clk / 3; |
| 221 | break; |
| 222 | default: |
| 223 | /* unkown SCCR_USBDRCM value */ |
| 224 | return -8; |
| 225 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 226 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 227 | if (usbmph_clk != 0 |
| 228 | && usbdr_clk != 0 |
| 229 | && usbmph_clk != usbdr_clk ) { |
| 230 | /* if USB MPH clock is not disabled and USB DR clock is not disabled than USB MPH & USB DR must have the same rate */ |
| 231 | return -9; |
| 232 | } |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 233 | #endif |
| 234 | #if defined (CONFIG_MPC8360) |
| 235 | i2c1_clk = csb_clk; |
| 236 | #endif |
| 237 | i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */ |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 238 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 239 | switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) { |
| 240 | case 0: |
| 241 | enc_clk = 0; |
| 242 | break; |
| 243 | case 1: |
| 244 | enc_clk = csb_clk; |
| 245 | break; |
| 246 | case 2: |
| 247 | enc_clk = csb_clk / 2; |
| 248 | break; |
| 249 | case 3: |
| 250 | enc_clk = csb_clk / 3; |
| 251 | break; |
| 252 | default: |
| 253 | /* unkown SCCR_ENCCM value */ |
| 254 | return -6; |
| 255 | } |
| 256 | #if defined(CONFIG_MPC8349) || defined(CONFIG_MPC8360) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 257 | lbiu_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_LBIUCM) >> RCWL_LBIUCM_SHIFT)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 258 | #else |
| 259 | #error Unknown MPC83xx chip |
| 260 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 261 | lcrr = (im->lbus.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT; |
| 262 | switch (lcrr) { |
| 263 | case 2: |
| 264 | case 4: |
| 265 | case 8: |
| 266 | lclk_clk = lbiu_clk / lcrr; |
| 267 | break; |
| 268 | default: |
| 269 | /* unknown lcrr */ |
| 270 | return -10; |
| 271 | } |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 272 | #if defined(CONFIG_MPC8349) || defined(CONFIG_MPC8360) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 273 | ddr_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_DDRCM) >> RCWL_DDRCM_SHIFT)); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 274 | corepll = (im->reset.rcwl & RCWL_COREPLL) >> RCWL_COREPLL_SHIFT; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 275 | #if defined (CONFIG_MPC8360) |
| 276 | ddr_sec_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_LBIUCM) >> RCWL_LBIUCM_SHIFT)); |
| 277 | #endif |
| 278 | #else |
| 279 | #error Unknown MPC83xx chip |
| 280 | #endif |
| 281 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 282 | corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5); |
| 283 | if (corecnf_tab_index > (sizeof(corecnf_tab)/sizeof(corecnf_t)) ) { |
| 284 | /* corecnf_tab_index is too high, possibly worng value */ |
| 285 | return -11; |
| 286 | } |
| 287 | switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) { |
| 288 | case _byp: |
| 289 | case _x1: |
| 290 | case _1x: |
| 291 | core_clk = csb_clk; |
| 292 | break; |
| 293 | case _1_5x: |
| 294 | core_clk = (3 * csb_clk) / 2; |
| 295 | break; |
| 296 | case _2x: |
| 297 | core_clk = 2 * csb_clk; |
| 298 | break; |
| 299 | case _2_5x: |
| 300 | core_clk = ( 5 * csb_clk) / 2; |
| 301 | break; |
| 302 | case _3x: |
| 303 | core_clk = 3 * csb_clk; |
| 304 | break; |
| 305 | default: |
| 306 | /* unkown core to csb ratio */ |
| 307 | return -12; |
| 308 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 309 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 310 | #if defined (CONFIG_MPC8360) |
| 311 | qepmf = (im->reset.rcwl & RCWL_CEPMF) >> RCWL_CEPMF_SHIFT; |
| 312 | qepdf = (im->reset.rcwl & RCWL_CEPDF) >> RCWL_CEPDF_SHIFT; |
| 313 | qe_clk = (pci_sync_in * qepmf)/(1+qepdf); |
| 314 | brg_clk = qe_clk / 2; |
| 315 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 316 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 317 | gd->csb_clk = csb_clk; |
| 318 | #if defined(CONFIG_MPC8349) |
| 319 | gd->tsec1_clk = tsec1_clk; |
| 320 | gd->tsec2_clk = tsec2_clk; |
| 321 | gd->usbmph_clk = usbmph_clk; |
| 322 | gd->usbdr_clk = usbdr_clk; |
| 323 | #endif |
| 324 | gd->core_clk = core_clk; |
| 325 | gd->i2c1_clk = i2c1_clk; |
| 326 | gd->i2c2_clk = i2c2_clk; |
| 327 | gd->enc_clk = enc_clk; |
| 328 | gd->lbiu_clk = lbiu_clk; |
| 329 | gd->lclk_clk = lclk_clk; |
| 330 | gd->ddr_clk = ddr_clk; |
| 331 | #if defined (CONFIG_MPC8360) |
| 332 | gd->ddr_sec_clk = ddr_sec_clk; |
| 333 | gd->qe_clk = qe_clk; |
| 334 | gd->brg_clk = brg_clk; |
| 335 | #endif |
| 336 | gd->cpu_clk = gd->core_clk; |
| 337 | gd->bus_clk = gd->csb_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 338 | return 0; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 339 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 340 | } |
| 341 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 342 | ulong get_ddr_clk(ulong dummy) |
| 343 | { |
| 344 | return gd->ddr_clk; |
| 345 | } |
| 346 | |
| 347 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 348 | /******************************************** |
| 349 | * get_bus_freq |
| 350 | * return system bus freq in Hz |
| 351 | *********************************************/ |
| 352 | ulong get_bus_freq (ulong dummy) |
| 353 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 354 | return gd->csb_clk; |
| 355 | } |
| 356 | |
| 357 | int print_clock_conf (void) |
| 358 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 359 | printf("Clock configuration:\n"); |
| 360 | printf(" Coherent System Bus: %4d MHz\n",gd->csb_clk/1000000); |
| 361 | printf(" Core: %4d MHz\n",gd->core_clk/1000000); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 362 | #if defined (CONFIG_MPC8360) |
| 363 | printf(" QE: %4d MHz\n",gd->qe_clk/1000000); |
| 364 | #endif |
| 365 | printf(" Local Bus Controller:%4d MHz\n",gd->lbiu_clk/1000000); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 366 | printf(" Local Bus: %4d MHz\n",gd->lclk_clk/1000000); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame^] | 367 | printf(" DDR: %4d MHz\n",gd->ddr_clk/1000000); |
| 368 | #if defined (CONFIG_MPC8360) |
| 369 | printf(" DDR Secondary: %4d MHz\n",gd->ddr_sec_clk/1000000); |
| 370 | #endif |
| 371 | printf(" SEC: %4d MHz\n",gd->enc_clk/1000000); |
| 372 | printf(" I2C1: %4d MHz\n",gd->i2c1_clk/1000000); |
| 373 | printf(" I2C2: %4d MHz\n",gd->i2c2_clk/1000000); |
| 374 | #if defined(CONFIG_MPC8349) |
| 375 | printf(" TSEC1: %4d MHz\n",gd->tsec1_clk/1000000); |
| 376 | printf(" TSEC2: %4d MHz\n",gd->tsec2_clk/1000000); |
| 377 | printf(" USB MPH: %4d MHz\n",gd->usbmph_clk/1000000); |
| 378 | printf(" USB DR: %4d MHz\n",gd->usbdr_clk/1000000); |
| 379 | #endif |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 380 | return 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 381 | } |