Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Freescale Semiconductor, Inc. |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 3 | * Dave Liu <daveliu@freescale.com> |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <ioports.h> |
| 16 | #include <mpc83xx.h> |
| 17 | #include <i2c.h> |
| 18 | #include <spd.h> |
| 19 | #include <miiphy.h> |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 20 | #if defined(CONFIG_PCI) |
| 21 | #include <pci.h> |
| 22 | #endif |
| 23 | #if defined(CONFIG_SPD_EEPROM) |
| 24 | #include <spd_sdram.h> |
| 25 | #else |
| 26 | #include <asm/mmu.h> |
| 27 | #endif |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 28 | #if defined(CONFIG_OF_FLAT_TREE) |
| 29 | #include <ft_build.h> |
Jerry Van Baren | 26d02c9 | 2007-07-04 21:27:30 -0400 | [diff] [blame] | 30 | #elif defined(CONFIG_OF_LIBFDT) |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 31 | #include <libfdt.h> |
| 32 | #include <libfdt_env.h> |
| 33 | #endif |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 34 | |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 35 | const qe_iop_conf_t qe_iop_conf_tab[] = { |
| 36 | /* GETH1 */ |
| 37 | {0, 3, 1, 0, 1}, /* TxD0 */ |
| 38 | {0, 4, 1, 0, 1}, /* TxD1 */ |
| 39 | {0, 5, 1, 0, 1}, /* TxD2 */ |
| 40 | {0, 6, 1, 0, 1}, /* TxD3 */ |
| 41 | {1, 6, 1, 0, 3}, /* TxD4 */ |
| 42 | {1, 7, 1, 0, 1}, /* TxD5 */ |
| 43 | {1, 9, 1, 0, 2}, /* TxD6 */ |
| 44 | {1, 10, 1, 0, 2}, /* TxD7 */ |
| 45 | {0, 9, 2, 0, 1}, /* RxD0 */ |
| 46 | {0, 10, 2, 0, 1}, /* RxD1 */ |
| 47 | {0, 11, 2, 0, 1}, /* RxD2 */ |
| 48 | {0, 12, 2, 0, 1}, /* RxD3 */ |
| 49 | {0, 13, 2, 0, 1}, /* RxD4 */ |
| 50 | {1, 1, 2, 0, 2}, /* RxD5 */ |
| 51 | {1, 0, 2, 0, 2}, /* RxD6 */ |
| 52 | {1, 4, 2, 0, 2}, /* RxD7 */ |
| 53 | {0, 7, 1, 0, 1}, /* TX_EN */ |
| 54 | {0, 8, 1, 0, 1}, /* TX_ER */ |
| 55 | {0, 15, 2, 0, 1}, /* RX_DV */ |
| 56 | {0, 16, 2, 0, 1}, /* RX_ER */ |
| 57 | {0, 0, 2, 0, 1}, /* RX_CLK */ |
| 58 | {2, 9, 1, 0, 3}, /* GTX_CLK - CLK10 */ |
| 59 | {2, 8, 2, 0, 1}, /* GTX125 - CLK9 */ |
| 60 | /* GETH2 */ |
| 61 | {0, 17, 1, 0, 1}, /* TxD0 */ |
| 62 | {0, 18, 1, 0, 1}, /* TxD1 */ |
| 63 | {0, 19, 1, 0, 1}, /* TxD2 */ |
| 64 | {0, 20, 1, 0, 1}, /* TxD3 */ |
| 65 | {1, 2, 1, 0, 1}, /* TxD4 */ |
| 66 | {1, 3, 1, 0, 2}, /* TxD5 */ |
| 67 | {1, 5, 1, 0, 3}, /* TxD6 */ |
| 68 | {1, 8, 1, 0, 3}, /* TxD7 */ |
| 69 | {0, 23, 2, 0, 1}, /* RxD0 */ |
| 70 | {0, 24, 2, 0, 1}, /* RxD1 */ |
| 71 | {0, 25, 2, 0, 1}, /* RxD2 */ |
| 72 | {0, 26, 2, 0, 1}, /* RxD3 */ |
| 73 | {0, 27, 2, 0, 1}, /* RxD4 */ |
| 74 | {1, 12, 2, 0, 2}, /* RxD5 */ |
| 75 | {1, 13, 2, 0, 3}, /* RxD6 */ |
| 76 | {1, 11, 2, 0, 2}, /* RxD7 */ |
| 77 | {0, 21, 1, 0, 1}, /* TX_EN */ |
| 78 | {0, 22, 1, 0, 1}, /* TX_ER */ |
| 79 | {0, 29, 2, 0, 1}, /* RX_DV */ |
| 80 | {0, 30, 2, 0, 1}, /* RX_ER */ |
| 81 | {0, 31, 2, 0, 1}, /* RX_CLK */ |
| 82 | {2, 2, 1, 0, 2}, /* GTX_CLK = CLK10 */ |
| 83 | {2, 3, 2, 0, 1}, /* GTX125 - CLK4 */ |
| 84 | |
| 85 | {0, 1, 3, 0, 2}, /* MDIO */ |
| 86 | {0, 2, 1, 0, 1}, /* MDC */ |
| 87 | |
| 88 | {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */ |
| 89 | }; |
| 90 | |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 91 | int board_early_init_f(void) |
| 92 | { |
Kim Phillips | 3fc0bd1 | 2007-02-14 19:50:53 -0600 | [diff] [blame] | 93 | |
| 94 | u8 *bcsr = (u8 *)CFG_BCSR; |
| 95 | const immap_t *immr = (immap_t *)CFG_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 96 | |
| 97 | /* Enable flash write */ |
| 98 | bcsr[0xa] &= ~0x04; |
| 99 | |
Kim Phillips | 3fc0bd1 | 2007-02-14 19:50:53 -0600 | [diff] [blame] | 100 | /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2 h/w bug workaround) */ |
| 101 | if (immr->sysconf.spridr == SPR_8360_REV20 || |
Lee Nipper | 1ded024 | 2007-06-14 20:07:33 -0500 | [diff] [blame] | 102 | immr->sysconf.spridr == SPR_8360E_REV20 || |
| 103 | immr->sysconf.spridr == SPR_8360_REV21 || |
| 104 | immr->sysconf.spridr == SPR_8360E_REV21) |
Kim Phillips | 3fc0bd1 | 2007-02-14 19:50:53 -0600 | [diff] [blame] | 105 | bcsr[0xe] = 0x30; |
| 106 | |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
| 111 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 112 | #endif |
| 113 | int fixed_sdram(void); |
| 114 | void sdram_init(void); |
| 115 | |
| 116 | long int initdram(int board_type) |
| 117 | { |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 118 | volatile immap_t *im = (immap_t *) CFG_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 119 | u32 msize = 0; |
| 120 | |
| 121 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
| 122 | return -1; |
| 123 | |
| 124 | /* DDR SDRAM - Main SODIMM */ |
| 125 | im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR; |
| 126 | #if defined(CONFIG_SPD_EEPROM) |
| 127 | msize = spd_sdram(); |
| 128 | #else |
| 129 | msize = fixed_sdram(); |
| 130 | #endif |
| 131 | |
| 132 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
| 133 | /* |
| 134 | * Initialize DDR ECC byte |
| 135 | */ |
| 136 | ddr_enable_ecc(msize * 1024 * 1024); |
| 137 | #endif |
| 138 | /* |
| 139 | * Initialize SDRAM if it is on local bus. |
| 140 | */ |
| 141 | sdram_init(); |
| 142 | puts(" DDR RAM: "); |
| 143 | /* return total bus SDRAM size(bytes) -- DDR */ |
| 144 | return (msize * 1024 * 1024); |
| 145 | } |
| 146 | |
| 147 | #if !defined(CONFIG_SPD_EEPROM) |
| 148 | /************************************************************************* |
| 149 | * fixed sdram init -- doesn't use serial presence detect. |
| 150 | ************************************************************************/ |
| 151 | int fixed_sdram(void) |
| 152 | { |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 153 | volatile immap_t *im = (immap_t *) CFG_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 154 | u32 msize = 0; |
| 155 | u32 ddr_size; |
| 156 | u32 ddr_size_log2; |
| 157 | |
| 158 | msize = CFG_DDR_SIZE; |
| 159 | for (ddr_size = msize << 20, ddr_size_log2 = 0; |
| 160 | (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) { |
| 161 | if (ddr_size & 1) { |
| 162 | return -1; |
| 163 | } |
| 164 | } |
| 165 | im->sysconf.ddrlaw[0].ar = |
| 166 | LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE); |
| 167 | #if (CFG_DDR_SIZE != 256) |
| 168 | #warning Currenly any ddr size other than 256 is not supported |
| 169 | #endif |
Xie Xiaobo | d61853c | 2007-02-14 18:27:17 +0800 | [diff] [blame] | 170 | #ifdef CONFIG_DDR_II |
| 171 | im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS; |
| 172 | im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG; |
| 173 | im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0; |
| 174 | im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1; |
| 175 | im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2; |
| 176 | im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3; |
| 177 | im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG; |
| 178 | im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2; |
| 179 | im->ddr.sdram_mode = CFG_DDR_MODE; |
| 180 | im->ddr.sdram_mode2 = CFG_DDR_MODE2; |
| 181 | im->ddr.sdram_interval = CFG_DDR_INTERVAL; |
| 182 | im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL; |
| 183 | #else |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 184 | im->ddr.csbnds[0].csbnds = 0x00000007; |
| 185 | im->ddr.csbnds[1].csbnds = 0x0008000f; |
| 186 | |
| 187 | im->ddr.cs_config[0] = CFG_DDR_CONFIG; |
| 188 | im->ddr.cs_config[1] = CFG_DDR_CONFIG; |
| 189 | |
| 190 | im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1; |
| 191 | im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2; |
| 192 | im->ddr.sdram_cfg = CFG_DDR_CONTROL; |
| 193 | |
| 194 | im->ddr.sdram_mode = CFG_DDR_MODE; |
| 195 | im->ddr.sdram_interval = CFG_DDR_INTERVAL; |
Xie Xiaobo | d61853c | 2007-02-14 18:27:17 +0800 | [diff] [blame] | 196 | #endif |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 197 | udelay(200); |
| 198 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 199 | |
| 200 | return msize; |
| 201 | } |
| 202 | #endif /*!CFG_SPD_EEPROM */ |
| 203 | |
| 204 | int checkboard(void) |
| 205 | { |
| 206 | puts("Board: Freescale MPC8360EMDS\n"); |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * if MPC8360EMDS is soldered with SDRAM |
| 212 | */ |
| 213 | #if defined(CFG_BR2_PRELIM) \ |
| 214 | && defined(CFG_OR2_PRELIM) \ |
| 215 | && defined(CFG_LBLAWBAR2_PRELIM) \ |
| 216 | && defined(CFG_LBLAWAR2_PRELIM) |
| 217 | /* |
| 218 | * Initialize SDRAM memory on the Local Bus. |
| 219 | */ |
| 220 | |
| 221 | void sdram_init(void) |
| 222 | { |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 223 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 224 | volatile lbus83xx_t *lbc = &immap->lbus; |
| 225 | uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE; |
| 226 | |
| 227 | puts("\n SDRAM on Local Bus: "); |
| 228 | print_size(CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
| 229 | /* |
| 230 | * Setup SDRAM Base and Option Registers, already done in cpu_init.c |
| 231 | */ |
| 232 | /*setup mtrpt, lsrt and lbcr for LB bus */ |
| 233 | lbc->lbcr = CFG_LBC_LBCR; |
| 234 | lbc->mrtpr = CFG_LBC_MRTPR; |
| 235 | lbc->lsrt = CFG_LBC_LSRT; |
| 236 | asm("sync"); |
| 237 | |
| 238 | /* |
| 239 | * Configure the SDRAM controller Machine Mode Register. |
| 240 | */ |
| 241 | lbc->lsdmr = CFG_LBC_LSDMR_5; /* Normal Operation */ |
| 242 | lbc->lsdmr = CFG_LBC_LSDMR_1; /* Precharge All Banks */ |
| 243 | asm("sync"); |
| 244 | *sdram_addr = 0xff; |
| 245 | udelay(100); |
| 246 | |
| 247 | /* |
| 248 | * We need do 8 times auto refresh operation. |
| 249 | */ |
| 250 | lbc->lsdmr = CFG_LBC_LSDMR_2; |
| 251 | asm("sync"); |
| 252 | *sdram_addr = 0xff; /* 1 times */ |
| 253 | udelay(100); |
| 254 | *sdram_addr = 0xff; /* 2 times */ |
| 255 | udelay(100); |
| 256 | *sdram_addr = 0xff; /* 3 times */ |
| 257 | udelay(100); |
| 258 | *sdram_addr = 0xff; /* 4 times */ |
| 259 | udelay(100); |
| 260 | *sdram_addr = 0xff; /* 5 times */ |
| 261 | udelay(100); |
| 262 | *sdram_addr = 0xff; /* 6 times */ |
| 263 | udelay(100); |
| 264 | *sdram_addr = 0xff; /* 7 times */ |
| 265 | udelay(100); |
| 266 | *sdram_addr = 0xff; /* 8 times */ |
| 267 | udelay(100); |
| 268 | |
| 269 | /* Mode register write operation */ |
| 270 | lbc->lsdmr = CFG_LBC_LSDMR_4; |
| 271 | asm("sync"); |
| 272 | *(sdram_addr + 0xcc) = 0xff; |
| 273 | udelay(100); |
| 274 | |
| 275 | /* Normal operation */ |
| 276 | lbc->lsdmr = CFG_LBC_LSDMR_5 | 0x40000000; |
| 277 | asm("sync"); |
| 278 | *sdram_addr = 0xff; |
| 279 | udelay(100); |
| 280 | } |
| 281 | #else |
| 282 | void sdram_init(void) |
| 283 | { |
| 284 | puts("SDRAM on Local Bus is NOT available!\n"); |
| 285 | } |
| 286 | #endif |
| 287 | |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 288 | #if (defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)) \ |
| 289 | && defined(CONFIG_OF_BOARD_SETUP) |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * Prototypes of functions that we use. |
| 293 | */ |
| 294 | void ft_cpu_setup(void *blob, bd_t *bd); |
| 295 | |
| 296 | #ifdef CONFIG_PCI |
| 297 | void ft_pci_setup(void *blob, bd_t *bd); |
| 298 | #endif |
| 299 | |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 300 | void |
| 301 | ft_board_setup(void *blob, bd_t *bd) |
| 302 | { |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 303 | #if defined(CONFIG_OF_LIBFDT) |
| 304 | int nodeoffset; |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 305 | int tmp[2]; |
| 306 | |
Kim Phillips | f57ac7a | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 307 | nodeoffset = fdt_find_node_by_path(blob, "/memory"); |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 308 | if (nodeoffset >= 0) { |
| 309 | tmp[0] = cpu_to_be32(bd->bi_memstart); |
| 310 | tmp[1] = cpu_to_be32(bd->bi_memsize); |
Kim Phillips | f57ac7a | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 311 | fdt_setprop(blob, nodeoffset, "reg", tmp, sizeof(tmp)); |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 312 | } |
| 313 | #else |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 314 | u32 *p; |
| 315 | int len; |
| 316 | |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 317 | p = ft_get_prop(blob, "/memory/reg", &len); |
| 318 | if (p != NULL) { |
| 319 | *p++ = cpu_to_be32(bd->bi_memstart); |
| 320 | *p = cpu_to_be32(bd->bi_memsize); |
| 321 | } |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 322 | #endif |
| 323 | |
| 324 | #ifdef CONFIG_PCI |
| 325 | ft_pci_setup(blob, bd); |
| 326 | #endif |
| 327 | ft_cpu_setup(blob, bd); |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 328 | } |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 329 | #endif /* CONFIG_OF_x */ |