Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [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 | |
| 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) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 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 | |
| 43 | int board_early_init_f (void) |
| 44 | { |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | int checkboard (void) |
| 49 | { |
| 50 | volatile immap_t *immap = (immap_t *) CFG_CCSRBAR; |
| 51 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 52 | |
| 53 | /* PCI slot in USER bits CSR[6:7] by convention. */ |
| 54 | uint pci_slot = get_pci_slot (); |
| 55 | |
| 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] */ |
| 60 | |
| 61 | uint pci1_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */ |
| 62 | |
| 63 | uint cpu_board_rev = get_cpu_board_revision (); |
| 64 | |
| 65 | printf ("Board: CDS Version 0x%02x, PCI Slot %d\n", |
| 66 | get_board_version (), pci_slot); |
| 67 | |
| 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); |
| 71 | |
| 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"); |
| 77 | |
| 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 | } |
| 84 | |
| 85 | /* |
| 86 | * Initialize local bus. |
| 87 | */ |
| 88 | local_bus_init (); |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * Hack TSEC 3 and 4 IO voltages. |
| 93 | */ |
| 94 | gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */ |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | long int |
| 100 | initdram(int board_type) |
| 101 | { |
| 102 | long dram_size = 0; |
| 103 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 104 | |
| 105 | puts("Initializing\n"); |
| 106 | |
| 107 | #if defined(CONFIG_DDR_DLL) |
| 108 | { |
| 109 | /* |
| 110 | * Work around to stabilize DDR DLL MSYNC_IN. |
| 111 | * Errata DDR9 seems to have been fixed. |
| 112 | * This is now the workaround for Errata DDR11: |
| 113 | * Override DLL = 1, Course Adj = 1, Tap Select = 0 |
| 114 | */ |
| 115 | |
| 116 | volatile ccsr_gur_t *gur= &immap->im_gur; |
| 117 | |
| 118 | gur->ddrdllcr = 0x81000000; |
| 119 | asm("sync;isync;msync"); |
| 120 | udelay(200); |
| 121 | } |
| 122 | #endif |
| 123 | dram_size = spd_sdram(); |
| 124 | |
| 125 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 126 | /* |
| 127 | * Initialize and enable DDR ECC. |
| 128 | */ |
| 129 | ddr_enable_ecc(dram_size); |
| 130 | #endif |
| 131 | /* |
| 132 | * SDRAM Initialization |
| 133 | */ |
| 134 | sdram_init(); |
| 135 | |
| 136 | puts(" DDR: "); |
| 137 | return dram_size; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Initialize Local Bus |
| 142 | */ |
| 143 | void |
| 144 | local_bus_init(void) |
| 145 | { |
| 146 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 147 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 148 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 149 | |
| 150 | uint clkdiv; |
| 151 | uint lbc_hz; |
| 152 | sys_info_t sysinfo; |
| 153 | |
| 154 | get_sys_info(&sysinfo); |
| 155 | clkdiv = (lbc->lcrr & 0x0f) * 2; |
| 156 | lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv; |
| 157 | |
| 158 | gur->lbiuiplldcr1 = 0x00078080; |
| 159 | if (clkdiv == 16) { |
| 160 | gur->lbiuiplldcr0 = 0x7c0f1bf0; |
| 161 | } else if (clkdiv == 8) { |
| 162 | gur->lbiuiplldcr0 = 0x6c0f1bf0; |
| 163 | } else if (clkdiv == 4) { |
| 164 | gur->lbiuiplldcr0 = 0x5c0f1bf0; |
| 165 | } |
| 166 | |
| 167 | lbc->lcrr |= 0x00030000; |
| 168 | |
| 169 | asm("sync;isync;msync"); |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Initialize SDRAM memory on the Local Bus. |
| 174 | */ |
| 175 | void |
| 176 | sdram_init(void) |
| 177 | { |
| 178 | #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM) |
| 179 | |
| 180 | uint idx; |
| 181 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 182 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 183 | uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE; |
| 184 | uint cpu_board_rev; |
| 185 | uint lsdmr_common; |
| 186 | |
| 187 | puts(" SDRAM: "); |
| 188 | |
| 189 | print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
| 190 | |
| 191 | /* |
| 192 | * Setup SDRAM Base and Option Registers |
| 193 | */ |
| 194 | lbc->or2 = CFG_OR2_PRELIM; |
| 195 | asm("msync"); |
| 196 | |
| 197 | lbc->br2 = CFG_BR2_PRELIM; |
| 198 | asm("msync"); |
| 199 | |
| 200 | lbc->lbcr = CFG_LBC_LBCR; |
| 201 | asm("msync"); |
| 202 | |
| 203 | |
| 204 | lbc->lsrt = CFG_LBC_LSRT; |
| 205 | lbc->mrtpr = CFG_LBC_MRTPR; |
| 206 | asm("msync"); |
| 207 | |
| 208 | /* |
| 209 | * MPC8548 uses "new" 15-16 style addressing. |
| 210 | */ |
| 211 | cpu_board_rev = get_cpu_board_revision(); |
| 212 | lsdmr_common = CFG_LBC_LSDMR_COMMON; |
| 213 | lsdmr_common |= CFG_LBC_LSDMR_BSMA1516; |
| 214 | |
| 215 | /* |
| 216 | * Issue PRECHARGE ALL command. |
| 217 | */ |
| 218 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL; |
| 219 | asm("sync;msync"); |
| 220 | *sdram_addr = 0xff; |
| 221 | ppcDcbf((unsigned long) sdram_addr); |
| 222 | udelay(100); |
| 223 | |
| 224 | /* |
| 225 | * Issue 8 AUTO REFRESH commands. |
| 226 | */ |
| 227 | for (idx = 0; idx < 8; idx++) { |
| 228 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH; |
| 229 | asm("sync;msync"); |
| 230 | *sdram_addr = 0xff; |
| 231 | ppcDcbf((unsigned long) sdram_addr); |
| 232 | udelay(100); |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * Issue 8 MODE-set command. |
| 237 | */ |
| 238 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW; |
| 239 | asm("sync;msync"); |
| 240 | *sdram_addr = 0xff; |
| 241 | ppcDcbf((unsigned long) sdram_addr); |
| 242 | udelay(100); |
| 243 | |
| 244 | /* |
| 245 | * Issue NORMAL OP command. |
| 246 | */ |
| 247 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL; |
| 248 | asm("sync;msync"); |
| 249 | *sdram_addr = 0xff; |
| 250 | ppcDcbf((unsigned long) sdram_addr); |
| 251 | udelay(200); /* Overkill. Must wait > 200 bus cycles */ |
| 252 | |
| 253 | #endif /* enable SDRAM init */ |
| 254 | } |
| 255 | |
| 256 | #if defined(CFG_DRAM_TEST) |
| 257 | int |
| 258 | testdram(void) |
| 259 | { |
| 260 | uint *pstart = (uint *) CFG_MEMTEST_START; |
| 261 | uint *pend = (uint *) CFG_MEMTEST_END; |
| 262 | uint *p; |
| 263 | |
| 264 | printf("Testing DRAM from 0x%08x to 0x%08x\n", |
| 265 | CFG_MEMTEST_START, |
| 266 | CFG_MEMTEST_END); |
| 267 | |
| 268 | printf("DRAM test phase 1:\n"); |
| 269 | for (p = pstart; p < pend; p++) |
| 270 | *p = 0xaaaaaaaa; |
| 271 | |
| 272 | for (p = pstart; p < pend; p++) { |
| 273 | if (*p != 0xaaaaaaaa) { |
| 274 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 275 | return 1; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | printf("DRAM test phase 2:\n"); |
| 280 | for (p = pstart; p < pend; p++) |
| 281 | *p = 0x55555555; |
| 282 | |
| 283 | for (p = pstart; p < pend; p++) { |
| 284 | if (*p != 0x55555555) { |
| 285 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 286 | return 1; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | printf("DRAM test passed.\n"); |
| 291 | return 0; |
| 292 | } |
| 293 | #endif |
| 294 | |
| 295 | #if defined(CONFIG_PCI) |
| 296 | |
| 297 | /* |
| 298 | * Initialize PCI Devices, report devices found. |
| 299 | */ |
| 300 | |
| 301 | #ifndef CONFIG_PCI_PNP |
| 302 | static struct pci_config_table pci_mpc85xxcds_config_table[] = { |
| 303 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 304 | PCI_IDSEL_NUMBER, PCI_ANY_ID, |
| 305 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 306 | PCI_ENET0_MEMADDR, |
| 307 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
| 308 | } }, |
| 309 | { } |
| 310 | }; |
| 311 | #endif |
| 312 | |
| 313 | static struct pci_controller hose = { |
| 314 | #ifndef CONFIG_PCI_PNP |
| 315 | config_table: pci_mpc85xxcds_config_table, |
| 316 | #endif |
| 317 | }; |
| 318 | |
| 319 | #endif /* CONFIG_PCI */ |
| 320 | |
| 321 | void |
| 322 | pci_init_board(void) |
| 323 | { |
| 324 | #ifdef CONFIG_PCI |
| 325 | extern void pci_mpc85xx_init(struct pci_controller *hose); |
| 326 | |
| 327 | pci_mpc85xx_init(&hose); |
| 328 | #endif |
| 329 | } |