wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 Freescale Semiconductor. |
| 3 | * |
| 4 | * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 25 | #include <common.h> |
| 26 | #include <pci.h> |
| 27 | #include <asm/processor.h> |
| 28 | #include <asm/immap_85xx.h> |
| 29 | #include <spd.h> |
| 30 | |
| 31 | #include "../common/cadmus.h" |
| 32 | #include "../common/eeprom.h" |
| 33 | |
| 34 | #if defined(CONFIG_DDR_ECC) |
| 35 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 36 | #endif |
| 37 | |
| 38 | extern long int spd_sdram(void); |
| 39 | |
| 40 | void local_bus_init(void); |
| 41 | void sdram_init(void); |
| 42 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 43 | int board_early_init_f (void) |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 44 | { |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 45 | return 0; |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 46 | } |
| 47 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 48 | int checkboard (void) |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 49 | { |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 50 | volatile immap_t *immap = (immap_t *) CFG_CCSRBAR; |
| 51 | volatile ccsr_gur_t *gur = &immap->im_gur; |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 52 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 53 | /* PCI slot in USER bits CSR[6:7] by convention. */ |
| 54 | uint pci_slot = get_pci_slot (); |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 55 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 56 | uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */ |
| 57 | uint pci1_32 = gur->pordevsr & 0x10000; /* PORDEVSR[15] */ |
| 58 | uint pci1_clk_sel = gur->porpllsr & 0x8000; /* PORPLLSR[16] */ |
| 59 | uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */ |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 60 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 61 | uint pci1_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */ |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 62 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 63 | uint cpu_board_rev = get_cpu_board_revision (); |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 64 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 65 | printf ("Board: CDS Version 0x%02x, PCI Slot %d\n", |
| 66 | get_board_version (), pci_slot); |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 67 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 68 | printf ("CPU Board Revision %d.%d (0x%04x)\n", |
| 69 | MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev), |
| 70 | MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev); |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 71 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 72 | printf (" PCI1: %d bit, %s MHz, %s\n", |
| 73 | (pci1_32) ? 32 : 64, |
| 74 | (pci1_speed == 33000000) ? "33" : |
| 75 | (pci1_speed == 66000000) ? "66" : "unknown", |
| 76 | pci1_clk_sel ? "sync" : "async"); |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 77 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 78 | if (pci_dual) { |
| 79 | printf (" PCI2: 32 bit, 66 MHz, %s\n", |
| 80 | pci2_clk_sel ? "sync" : "async"); |
| 81 | } else { |
| 82 | printf (" PCI2: disabled\n"); |
| 83 | } |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 84 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 85 | /* |
| 86 | * Initialize local bus. |
| 87 | */ |
| 88 | local_bus_init (); |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 89 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame^] | 90 | return 0; |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 91 | } |
| 92 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 93 | long int |
| 94 | initdram(int board_type) |
| 95 | { |
| 96 | long dram_size = 0; |
| 97 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 98 | |
| 99 | puts("Initializing\n"); |
| 100 | |
| 101 | #if defined(CONFIG_DDR_DLL) |
| 102 | { |
| 103 | /* |
| 104 | * Work around to stabilize DDR DLL MSYNC_IN. |
| 105 | * Errata DDR9 seems to have been fixed. |
| 106 | * This is now the workaround for Errata DDR11: |
| 107 | * Override DLL = 1, Course Adj = 1, Tap Select = 0 |
| 108 | */ |
| 109 | |
| 110 | volatile ccsr_gur_t *gur= &immap->im_gur; |
| 111 | |
| 112 | gur->ddrdllcr = 0x81000000; |
| 113 | asm("sync;isync;msync"); |
| 114 | udelay(200); |
| 115 | } |
| 116 | #endif |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 117 | dram_size = spd_sdram(); |
| 118 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 119 | #if defined(CONFIG_DDR_ECC) |
| 120 | /* |
| 121 | * Initialize and enable DDR ECC. |
| 122 | */ |
| 123 | ddr_enable_ecc(dram_size); |
| 124 | #endif |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 125 | /* |
| 126 | * SDRAM Initialization |
| 127 | */ |
| 128 | sdram_init(); |
| 129 | |
| 130 | puts(" DDR: "); |
| 131 | return dram_size; |
| 132 | } |
| 133 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 134 | /* |
| 135 | * Initialize Local Bus |
| 136 | */ |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 137 | void |
| 138 | local_bus_init(void) |
| 139 | { |
| 140 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 141 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 142 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 143 | |
| 144 | uint clkdiv; |
| 145 | uint lbc_hz; |
| 146 | sys_info_t sysinfo; |
| 147 | uint temp_lbcdll; |
| 148 | |
| 149 | /* |
| 150 | * Errata LBC11. |
| 151 | * Fix Local Bus clock glitch when DLL is enabled. |
| 152 | * |
| 153 | * If localbus freq is < 66Mhz, DLL bypass mode must be used. |
| 154 | * If localbus freq is > 133Mhz, DLL can be safely enabled. |
| 155 | * Between 66 and 133, the DLL is enabled with an override workaround. |
| 156 | */ |
| 157 | |
| 158 | get_sys_info(&sysinfo); |
| 159 | clkdiv = lbc->lcrr & 0x0f; |
| 160 | lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv; |
| 161 | |
| 162 | if (lbc_hz < 66) { |
| 163 | lbc->lcrr |= 0x80000000; /* DLL Bypass */ |
| 164 | |
| 165 | } else if (lbc_hz >= 133) { |
| 166 | lbc->lcrr &= (~0x80000000); /* DLL Enabled */ |
| 167 | |
| 168 | } else { |
| 169 | lbc->lcrr &= (~0x8000000); /* DLL Enabled */ |
| 170 | udelay(200); |
| 171 | |
| 172 | /* |
| 173 | * Sample LBC DLL ctrl reg, upshift it to set the |
| 174 | * override bits. |
| 175 | */ |
| 176 | temp_lbcdll = gur->lbcdllcr; |
| 177 | gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000); |
| 178 | asm("sync;isync;msync"); |
| 179 | } |
| 180 | } |
| 181 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 182 | /* |
| 183 | * Initialize SDRAM memory on the Local Bus. |
| 184 | */ |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 185 | void |
| 186 | sdram_init(void) |
| 187 | { |
| 188 | #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM) |
| 189 | |
| 190 | uint idx; |
| 191 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 192 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 193 | uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE; |
| 194 | uint cpu_board_rev; |
| 195 | uint lsdmr_common; |
| 196 | |
| 197 | puts(" SDRAM: "); |
| 198 | |
| 199 | print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
| 200 | |
| 201 | /* |
| 202 | * Setup SDRAM Base and Option Registers |
| 203 | */ |
| 204 | lbc->or2 = CFG_OR2_PRELIM; |
| 205 | asm("msync"); |
| 206 | |
| 207 | lbc->br2 = CFG_BR2_PRELIM; |
| 208 | asm("msync"); |
| 209 | |
| 210 | lbc->lbcr = CFG_LBC_LBCR; |
| 211 | asm("msync"); |
| 212 | |
| 213 | |
| 214 | lbc->lsrt = CFG_LBC_LSRT; |
| 215 | lbc->mrtpr = CFG_LBC_MRTPR; |
| 216 | asm("msync"); |
| 217 | |
| 218 | /* |
| 219 | * Determine which address lines to use baed on CPU board rev. |
| 220 | */ |
| 221 | cpu_board_rev = get_cpu_board_revision(); |
| 222 | lsdmr_common = CFG_LBC_LSDMR_COMMON; |
| 223 | if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) { |
| 224 | lsdmr_common |= CFG_LBC_LSDMR_BSMA1617; |
| 225 | } else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) { |
| 226 | lsdmr_common |= CFG_LBC_LSDMR_BSMA1516; |
| 227 | } else { |
| 228 | /* |
| 229 | * Assume something unable to identify itself is |
| 230 | * really old, and likely has lines 16/17 mapped. |
| 231 | */ |
| 232 | lsdmr_common |= CFG_LBC_LSDMR_BSMA1617; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * Issue PRECHARGE ALL command. |
| 237 | */ |
| 238 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL; |
| 239 | asm("sync;msync"); |
| 240 | *sdram_addr = 0xff; |
| 241 | ppcDcbf((unsigned long) sdram_addr); |
| 242 | udelay(100); |
| 243 | |
| 244 | /* |
| 245 | * Issue 8 AUTO REFRESH commands. |
| 246 | */ |
| 247 | for (idx = 0; idx < 8; idx++) { |
| 248 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH; |
| 249 | asm("sync;msync"); |
| 250 | *sdram_addr = 0xff; |
| 251 | ppcDcbf((unsigned long) sdram_addr); |
| 252 | udelay(100); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Issue 8 MODE-set command. |
| 257 | */ |
| 258 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW; |
| 259 | asm("sync;msync"); |
| 260 | *sdram_addr = 0xff; |
| 261 | ppcDcbf((unsigned long) sdram_addr); |
| 262 | udelay(100); |
| 263 | |
| 264 | /* |
| 265 | * Issue NORMAL OP command. |
| 266 | */ |
| 267 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL; |
| 268 | asm("sync;msync"); |
| 269 | *sdram_addr = 0xff; |
| 270 | ppcDcbf((unsigned long) sdram_addr); |
| 271 | udelay(200); /* Overkill. Must wait > 200 bus cycles */ |
| 272 | |
| 273 | #endif /* enable SDRAM init */ |
| 274 | } |
| 275 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 276 | #if defined(CFG_DRAM_TEST) |
| 277 | int |
| 278 | testdram(void) |
| 279 | { |
| 280 | uint *pstart = (uint *) CFG_MEMTEST_START; |
| 281 | uint *pend = (uint *) CFG_MEMTEST_END; |
| 282 | uint *p; |
| 283 | |
| 284 | printf("Testing DRAM from 0x%08x to 0x%08x\n", |
| 285 | CFG_MEMTEST_START, |
| 286 | CFG_MEMTEST_END); |
| 287 | |
| 288 | printf("DRAM test phase 1:\n"); |
| 289 | for (p = pstart; p < pend; p++) |
| 290 | *p = 0xaaaaaaaa; |
| 291 | |
| 292 | for (p = pstart; p < pend; p++) { |
| 293 | if (*p != 0xaaaaaaaa) { |
| 294 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 295 | return 1; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | printf("DRAM test phase 2:\n"); |
| 300 | for (p = pstart; p < pend; p++) |
| 301 | *p = 0x55555555; |
| 302 | |
| 303 | for (p = pstart; p < pend; p++) { |
| 304 | if (*p != 0x55555555) { |
| 305 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 306 | return 1; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | printf("DRAM test passed.\n"); |
| 311 | return 0; |
| 312 | } |
| 313 | #endif |
| 314 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 315 | #if defined(CONFIG_PCI) |
| 316 | |
| 317 | /* |
| 318 | * Initialize PCI Devices, report devices found. |
| 319 | */ |
| 320 | |
| 321 | #ifndef CONFIG_PCI_PNP |
| 322 | static struct pci_config_table pci_mpc85xxcds_config_table[] = { |
| 323 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 324 | PCI_IDSEL_NUMBER, PCI_ANY_ID, |
| 325 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 326 | PCI_ENET0_MEMADDR, |
| 327 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
| 328 | } }, |
| 329 | { } |
| 330 | }; |
| 331 | #endif |
| 332 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 333 | static struct pci_controller hose = { |
| 334 | #ifndef CONFIG_PCI_PNP |
| 335 | config_table: pci_mpc85xxcds_config_table, |
| 336 | #endif |
| 337 | }; |
| 338 | |
| 339 | #endif /* CONFIG_PCI */ |
| 340 | |
wdenk | 03f5c55 | 2004-10-10 21:21:55 +0000 | [diff] [blame] | 341 | void |
| 342 | pci_init_board(void) |
| 343 | { |
| 344 | #ifdef CONFIG_PCI |
| 345 | extern void pci_mpc85xx_init(struct pci_controller *hose); |
| 346 | |
| 347 | pci_mpc85xx_init(&hose); |
| 348 | #endif |
| 349 | } |