Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 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> |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 30 | #include <i2c.h> |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 31 | #include <ioports.h> |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 32 | |
| 33 | #include "bcsr.h" |
| 34 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 35 | const qe_iop_conf_t qe_iop_conf_tab[] = { |
| 36 | /* GETH1 */ |
| 37 | {4, 10, 1, 0, 2}, /* TxD0 */ |
| 38 | {4, 9, 1, 0, 2}, /* TxD1 */ |
| 39 | {4, 8, 1, 0, 2}, /* TxD2 */ |
| 40 | {4, 7, 1, 0, 2}, /* TxD3 */ |
| 41 | {4, 23, 1, 0, 2}, /* TxD4 */ |
| 42 | {4, 22, 1, 0, 2}, /* TxD5 */ |
| 43 | {4, 21, 1, 0, 2}, /* TxD6 */ |
| 44 | {4, 20, 1, 0, 2}, /* TxD7 */ |
| 45 | {4, 15, 2, 0, 2}, /* RxD0 */ |
| 46 | {4, 14, 2, 0, 2}, /* RxD1 */ |
| 47 | {4, 13, 2, 0, 2}, /* RxD2 */ |
| 48 | {4, 12, 2, 0, 2}, /* RxD3 */ |
| 49 | {4, 29, 2, 0, 2}, /* RxD4 */ |
| 50 | {4, 28, 2, 0, 2}, /* RxD5 */ |
| 51 | {4, 27, 2, 0, 2}, /* RxD6 */ |
| 52 | {4, 26, 2, 0, 2}, /* RxD7 */ |
| 53 | {4, 11, 1, 0, 2}, /* TX_EN */ |
| 54 | {4, 24, 1, 0, 2}, /* TX_ER */ |
| 55 | {4, 16, 2, 0, 2}, /* RX_DV */ |
| 56 | {4, 30, 2, 0, 2}, /* RX_ER */ |
| 57 | {4, 17, 2, 0, 2}, /* RX_CLK */ |
| 58 | {4, 19, 1, 0, 2}, /* GTX_CLK */ |
| 59 | {1, 31, 2, 0, 3}, /* GTX125 */ |
| 60 | |
| 61 | /* GETH2 */ |
| 62 | {5, 10, 1, 0, 2}, /* TxD0 */ |
| 63 | {5, 9, 1, 0, 2}, /* TxD1 */ |
| 64 | {5, 8, 1, 0, 2}, /* TxD2 */ |
| 65 | {5, 7, 1, 0, 2}, /* TxD3 */ |
| 66 | {5, 23, 1, 0, 2}, /* TxD4 */ |
| 67 | {5, 22, 1, 0, 2}, /* TxD5 */ |
| 68 | {5, 21, 1, 0, 2}, /* TxD6 */ |
| 69 | {5, 20, 1, 0, 2}, /* TxD7 */ |
| 70 | {5, 15, 2, 0, 2}, /* RxD0 */ |
| 71 | {5, 14, 2, 0, 2}, /* RxD1 */ |
| 72 | {5, 13, 2, 0, 2}, /* RxD2 */ |
| 73 | {5, 12, 2, 0, 2}, /* RxD3 */ |
| 74 | {5, 29, 2, 0, 2}, /* RxD4 */ |
| 75 | {5, 28, 2, 0, 2}, /* RxD5 */ |
| 76 | {5, 27, 2, 0, 3}, /* RxD6 */ |
| 77 | {5, 26, 2, 0, 2}, /* RxD7 */ |
| 78 | {5, 11, 1, 0, 2}, /* TX_EN */ |
| 79 | {5, 24, 1, 0, 2}, /* TX_ER */ |
| 80 | {5, 16, 2, 0, 2}, /* RX_DV */ |
| 81 | {5, 30, 2, 0, 2}, /* RX_ER */ |
| 82 | {5, 17, 2, 0, 2}, /* RX_CLK */ |
| 83 | {5, 19, 1, 0, 2}, /* GTX_CLK */ |
| 84 | {1, 31, 2, 0, 3}, /* GTX125 */ |
| 85 | {4, 6, 3, 0, 2}, /* MDIO */ |
| 86 | {4, 5, 1, 0, 2}, /* MDC */ |
| 87 | {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */ |
| 88 | }; |
| 89 | |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 90 | |
| 91 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 92 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 93 | #endif |
| 94 | |
| 95 | extern long int spd_sdram(void); |
| 96 | |
| 97 | void local_bus_init(void); |
| 98 | void sdram_init(void); |
| 99 | |
| 100 | int board_early_init_f (void) |
| 101 | { |
| 102 | /* |
| 103 | * Initialize local bus. |
| 104 | */ |
| 105 | local_bus_init (); |
| 106 | |
| 107 | enable_8568mds_duart(); |
| 108 | enable_8568mds_flash_write(); |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 109 | #if defined(CONFIG_QE) && !defined(CONFIG_eTSEC_MDIO_BUS) |
| 110 | enable_8568mds_qe_mdio(); |
| 111 | #endif |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 112 | |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 113 | #ifdef CFG_I2C2_OFFSET |
| 114 | /* Enable I2C2_SCL and I2C2_SDA */ |
| 115 | volatile struct par_io *port_c; |
| 116 | port_c = (struct par_io*)(CFG_IMMR + 0xe0140); |
| 117 | port_c->cpdir2 |= 0x0f000000; |
| 118 | port_c->cppar2 &= ~0x0f000000; |
| 119 | port_c->cppar2 |= 0x0a000000; |
| 120 | #endif |
| 121 | |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | int checkboard (void) |
| 126 | { |
| 127 | printf ("Board: 8568 MDS\n"); |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | long int |
| 133 | initdram(int board_type) |
| 134 | { |
| 135 | long dram_size = 0; |
| 136 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 137 | |
| 138 | puts("Initializing\n"); |
| 139 | |
| 140 | #if defined(CONFIG_DDR_DLL) |
| 141 | { |
| 142 | /* |
| 143 | * Work around to stabilize DDR DLL MSYNC_IN. |
| 144 | * Errata DDR9 seems to have been fixed. |
| 145 | * This is now the workaround for Errata DDR11: |
| 146 | * Override DLL = 1, Course Adj = 1, Tap Select = 0 |
| 147 | */ |
| 148 | |
| 149 | volatile ccsr_gur_t *gur= &immap->im_gur; |
| 150 | |
| 151 | gur->ddrdllcr = 0x81000000; |
| 152 | asm("sync;isync;msync"); |
| 153 | udelay(200); |
| 154 | } |
| 155 | #endif |
| 156 | dram_size = spd_sdram(); |
| 157 | |
| 158 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 159 | /* |
| 160 | * Initialize and enable DDR ECC. |
| 161 | */ |
| 162 | ddr_enable_ecc(dram_size); |
| 163 | #endif |
| 164 | /* |
| 165 | * SDRAM Initialization |
| 166 | */ |
| 167 | sdram_init(); |
| 168 | |
| 169 | puts(" DDR: "); |
| 170 | return dram_size; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Initialize Local Bus |
| 175 | */ |
| 176 | void |
| 177 | local_bus_init(void) |
| 178 | { |
| 179 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 180 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 181 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 182 | |
| 183 | uint clkdiv; |
| 184 | uint lbc_hz; |
| 185 | sys_info_t sysinfo; |
| 186 | |
| 187 | get_sys_info(&sysinfo); |
| 188 | clkdiv = (lbc->lcrr & 0x0f) * 2; |
| 189 | lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv; |
| 190 | |
| 191 | gur->lbiuiplldcr1 = 0x00078080; |
| 192 | if (clkdiv == 16) { |
| 193 | gur->lbiuiplldcr0 = 0x7c0f1bf0; |
| 194 | } else if (clkdiv == 8) { |
| 195 | gur->lbiuiplldcr0 = 0x6c0f1bf0; |
| 196 | } else if (clkdiv == 4) { |
| 197 | gur->lbiuiplldcr0 = 0x5c0f1bf0; |
| 198 | } |
| 199 | |
| 200 | lbc->lcrr |= 0x00030000; |
| 201 | |
| 202 | asm("sync;isync;msync"); |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * Initialize SDRAM memory on the Local Bus. |
| 207 | */ |
| 208 | void |
| 209 | sdram_init(void) |
| 210 | { |
| 211 | #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM) |
| 212 | |
| 213 | uint idx; |
| 214 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 215 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 216 | uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE; |
| 217 | uint lsdmr_common; |
| 218 | |
| 219 | puts(" SDRAM: "); |
| 220 | |
| 221 | print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
| 222 | |
| 223 | /* |
| 224 | * Setup SDRAM Base and Option Registers |
| 225 | */ |
| 226 | lbc->or2 = CFG_OR2_PRELIM; |
| 227 | asm("msync"); |
| 228 | |
| 229 | lbc->br2 = CFG_BR2_PRELIM; |
| 230 | asm("msync"); |
| 231 | |
| 232 | lbc->lbcr = CFG_LBC_LBCR; |
| 233 | asm("msync"); |
| 234 | |
| 235 | |
| 236 | lbc->lsrt = CFG_LBC_LSRT; |
| 237 | lbc->mrtpr = CFG_LBC_MRTPR; |
| 238 | asm("msync"); |
| 239 | |
| 240 | /* |
| 241 | * MPC8568 uses "new" 15-16 style addressing. |
| 242 | */ |
| 243 | lsdmr_common = CFG_LBC_LSDMR_COMMON; |
| 244 | lsdmr_common |= CFG_LBC_LSDMR_BSMA1516; |
| 245 | |
| 246 | /* |
| 247 | * Issue PRECHARGE ALL command. |
| 248 | */ |
| 249 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL; |
| 250 | asm("sync;msync"); |
| 251 | *sdram_addr = 0xff; |
| 252 | ppcDcbf((unsigned long) sdram_addr); |
| 253 | udelay(100); |
| 254 | |
| 255 | /* |
| 256 | * Issue 8 AUTO REFRESH commands. |
| 257 | */ |
| 258 | for (idx = 0; idx < 8; idx++) { |
| 259 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH; |
| 260 | asm("sync;msync"); |
| 261 | *sdram_addr = 0xff; |
| 262 | ppcDcbf((unsigned long) sdram_addr); |
| 263 | udelay(100); |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Issue 8 MODE-set command. |
| 268 | */ |
| 269 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW; |
| 270 | asm("sync;msync"); |
| 271 | *sdram_addr = 0xff; |
| 272 | ppcDcbf((unsigned long) sdram_addr); |
| 273 | udelay(100); |
| 274 | |
| 275 | /* |
| 276 | * Issue NORMAL OP command. |
| 277 | */ |
| 278 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL; |
| 279 | asm("sync;msync"); |
| 280 | *sdram_addr = 0xff; |
| 281 | ppcDcbf((unsigned long) sdram_addr); |
| 282 | udelay(200); /* Overkill. Must wait > 200 bus cycles */ |
| 283 | |
| 284 | #endif /* enable SDRAM init */ |
| 285 | } |
| 286 | |
| 287 | #if defined(CFG_DRAM_TEST) |
| 288 | int |
| 289 | testdram(void) |
| 290 | { |
| 291 | uint *pstart = (uint *) CFG_MEMTEST_START; |
| 292 | uint *pend = (uint *) CFG_MEMTEST_END; |
| 293 | uint *p; |
| 294 | |
| 295 | printf("Testing DRAM from 0x%08x to 0x%08x\n", |
| 296 | CFG_MEMTEST_START, |
| 297 | CFG_MEMTEST_END); |
| 298 | |
| 299 | printf("DRAM test phase 1:\n"); |
| 300 | for (p = pstart; p < pend; p++) |
| 301 | *p = 0xaaaaaaaa; |
| 302 | |
| 303 | for (p = pstart; p < pend; p++) { |
| 304 | if (*p != 0xaaaaaaaa) { |
| 305 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 306 | return 1; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | printf("DRAM test phase 2:\n"); |
| 311 | for (p = pstart; p < pend; p++) |
| 312 | *p = 0x55555555; |
| 313 | |
| 314 | for (p = pstart; p < pend; p++) { |
| 315 | if (*p != 0x55555555) { |
| 316 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 317 | return 1; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | printf("DRAM test passed.\n"); |
| 322 | return 0; |
| 323 | } |
| 324 | #endif |
| 325 | |
| 326 | #if defined(CONFIG_PCI) |
| 327 | #ifndef CONFIG_PCI_PNP |
| 328 | static struct pci_config_table pci_mpc8568mds_config_table[] = { |
| 329 | { |
| 330 | PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 331 | pci_cfgfunc_config_device, |
| 332 | {PCI_ENET0_IOADDR, |
| 333 | PCI_ENET0_MEMADDR, |
| 334 | PCI_COMMON_MEMORY | PCI_COMMAND_MASTER} |
| 335 | }, |
| 336 | {} |
| 337 | }; |
| 338 | #endif |
| 339 | |
| 340 | static struct pci_controller hose[] = { |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 341 | { |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 342 | #ifndef CONFIG_PCI_PNP |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 343 | config_table: pci_mpc8568mds_config_table, |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 344 | #endif |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 345 | } |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 346 | }; |
| 347 | |
| 348 | #endif /* CONFIG_PCI */ |
| 349 | |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 350 | /* |
| 351 | * pib_init() -- Initialize the PCA9555 IO expander on the PIB board |
| 352 | */ |
| 353 | void |
| 354 | pib_init(void) |
| 355 | { |
| 356 | u8 val8, orig_i2c_bus; |
| 357 | /* |
| 358 | * Assign PIB PMC2/3 to PCI bus |
| 359 | */ |
| 360 | |
| 361 | /*switch temporarily to I2C bus #2 */ |
| 362 | orig_i2c_bus = i2c_get_bus_num(); |
| 363 | i2c_set_bus_num(1); |
| 364 | |
| 365 | val8 = 0x00; |
| 366 | i2c_write(0x23, 0x6, 1, &val8, 1); |
| 367 | i2c_write(0x23, 0x7, 1, &val8, 1); |
| 368 | val8 = 0xff; |
| 369 | i2c_write(0x23, 0x2, 1, &val8, 1); |
| 370 | i2c_write(0x23, 0x3, 1, &val8, 1); |
| 371 | |
| 372 | val8 = 0x00; |
| 373 | i2c_write(0x26, 0x6, 1, &val8, 1); |
| 374 | val8 = 0x34; |
| 375 | i2c_write(0x26, 0x7, 1, &val8, 1); |
| 376 | val8 = 0xf9; |
| 377 | i2c_write(0x26, 0x2, 1, &val8, 1); |
| 378 | val8 = 0xff; |
| 379 | i2c_write(0x26, 0x3, 1, &val8, 1); |
| 380 | |
| 381 | val8 = 0x00; |
| 382 | i2c_write(0x27, 0x6, 1, &val8, 1); |
| 383 | i2c_write(0x27, 0x7, 1, &val8, 1); |
| 384 | val8 = 0xff; |
| 385 | i2c_write(0x27, 0x2, 1, &val8, 1); |
| 386 | val8 = 0xef; |
| 387 | i2c_write(0x27, 0x3, 1, &val8, 1); |
| 388 | |
| 389 | asm("eieio"); |
| 390 | } |
| 391 | |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 392 | void |
| 393 | pci_init_board(void) |
| 394 | { |
| 395 | #ifdef CONFIG_PCI |
Haiying Wang | c4fc883 | 2007-06-19 14:18:34 -0400 | [diff] [blame] | 396 | pib_init(); |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 397 | pci_mpc85xx_init(hose); |
Andy Fleming | 71706df | 2007-04-23 02:54:25 -0500 | [diff] [blame] | 398 | #endif |
| 399 | } |