wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1 | /* |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 2 | * Copyright 2004 Freescale Semiconductor. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * (C) Copyright 2002,2003, Motorola Inc. |
| 4 | * Xianghua Xiao, (X.Xiao@motorola.com) |
| 5 | * |
| 6 | * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 28 | #include <common.h> |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 29 | #include <pci.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 30 | #include <asm/processor.h> |
| 31 | #include <asm/immap_85xx.h> |
| 32 | #include <spd.h> |
| 33 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 34 | #if defined(CONFIG_DDR_ECC) |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 35 | extern void ddr_enable_ecc(unsigned int dram_size); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 38 | extern long int spd_sdram(void); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 39 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 40 | void local_bus_init(void); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 41 | void sdram_init(void); |
| 42 | long int fixed_sdram(void); |
| 43 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 44 | |
wdenk | da55c6e | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 45 | int board_early_init_f (void) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 46 | { |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 47 | return 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | int checkboard (void) |
| 51 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 52 | puts("Board: ADS\n"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 53 | |
| 54 | #ifdef CONFIG_PCI |
| 55 | printf(" PCI1: 32 bit, %d MHz (compiled)\n", |
| 56 | CONFIG_SYS_CLK_FREQ / 1000000); |
| 57 | #else |
| 58 | printf(" PCI1: disabled\n"); |
| 59 | #endif |
| 60 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 61 | /* |
| 62 | * Initialize local bus. |
| 63 | */ |
| 64 | local_bus_init(); |
| 65 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 66 | return 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 67 | } |
| 68 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 69 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 70 | long int |
| 71 | initdram(int board_type) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 72 | { |
| 73 | long dram_size = 0; |
| 74 | extern long spd_sdram (void); |
| 75 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 76 | |
| 77 | puts("Initializing\n"); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 78 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 79 | #if defined(CONFIG_DDR_DLL) |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 80 | { |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 81 | volatile ccsr_gur_t *gur= &immap->im_gur; |
| 82 | uint temp_ddrdll = 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 83 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 84 | /* |
| 85 | * Work around to stabilize DDR DLL |
| 86 | */ |
| 87 | temp_ddrdll = gur->ddrdllcr; |
| 88 | gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000; |
| 89 | asm("sync;isync;msync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 90 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 91 | #endif |
| 92 | |
| 93 | #if defined(CONFIG_SPD_EEPROM) |
| 94 | dram_size = spd_sdram (); |
| 95 | #else |
| 96 | dram_size = fixed_sdram (); |
| 97 | #endif |
| 98 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 99 | #if defined(CONFIG_DDR_ECC) |
| 100 | /* |
| 101 | * Initialize and enable DDR ECC. |
| 102 | */ |
| 103 | ddr_enable_ecc(dram_size); |
| 104 | #endif |
| 105 | |
| 106 | /* |
| 107 | * Initialize SDRAM. |
| 108 | */ |
| 109 | sdram_init(); |
| 110 | |
| 111 | puts(" DDR: "); |
| 112 | return dram_size; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | /* |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 117 | * Initialize Local Bus |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 118 | */ |
| 119 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 120 | void |
| 121 | local_bus_init(void) |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 122 | { |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 123 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 124 | volatile ccsr_gur_t *gur = &immap->im_gur; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 125 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 126 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 127 | uint clkdiv; |
| 128 | uint lbc_hz; |
| 129 | sys_info_t sysinfo; |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 130 | |
| 131 | /* |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 132 | * Errata LBC11. |
| 133 | * Fix Local Bus clock glitch when DLL is enabled. |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 134 | * |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 135 | * If localbus freq is < 66Mhz, DLL bypass mode must be used. |
| 136 | * If localbus freq is > 133Mhz, DLL can be safely enabled. |
| 137 | * Between 66 and 133, the DLL is enabled with an override workaround. |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 138 | */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 139 | |
| 140 | get_sys_info(&sysinfo); |
| 141 | clkdiv = lbc->lcrr & 0x0f; |
| 142 | lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv; |
| 143 | |
| 144 | if (lbc_hz < 66) { |
| 145 | lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */ |
| 146 | |
| 147 | } else if (lbc_hz >= 133) { |
| 148 | lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */ |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 149 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 150 | } else { |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 151 | /* |
| 152 | * On REV1 boards, need to change CLKDIV before enable DLL. |
| 153 | * Default CLKDIV is 8, change it to 4 temporarily. |
| 154 | */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 155 | uint pvr = get_pvr(); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 156 | uint temp_lbcdll = 0; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 157 | |
| 158 | if (pvr == PVR_85xx_REV1) { |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 159 | /* FIXME: Justify the high bit here. */ |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 160 | lbc->lcrr = 0x10000004; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 161 | } |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 162 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 163 | lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */ |
| 164 | udelay(200); |
| 165 | |
| 166 | /* |
| 167 | * Sample LBC DLL ctrl reg, upshift it to set the |
| 168 | * override bits. |
| 169 | */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 170 | temp_lbcdll = gur->lbcdllcr; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 171 | gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000); |
| 172 | asm("sync;isync;msync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 173 | } |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
| 177 | /* |
| 178 | * Initialize SDRAM memory on the Local Bus. |
| 179 | */ |
| 180 | |
| 181 | void |
| 182 | sdram_init(void) |
| 183 | { |
| 184 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 185 | volatile ccsr_lbc_t *lbc= &immap->im_lbc; |
| 186 | uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE; |
| 187 | |
| 188 | puts(" SDRAM: "); |
| 189 | print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Setup SDRAM Base and Option Registers |
| 193 | */ |
| 194 | lbc->or2 = CFG_OR2_PRELIM; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 195 | lbc->br2 = CFG_BR2_PRELIM; |
| 196 | lbc->lbcr = CFG_LBC_LBCR; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 197 | asm("msync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 198 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 199 | lbc->lsrt = CFG_LBC_LSRT; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 200 | lbc->mrtpr = CFG_LBC_MRTPR; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 201 | asm("sync"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 202 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 203 | /* |
| 204 | * Configure the SDRAM controller. |
| 205 | */ |
| 206 | lbc->lsdmr = CFG_LBC_LSDMR_1; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 207 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 208 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 209 | ppcDcbf((unsigned long) sdram_addr); |
| 210 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 211 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 212 | lbc->lsdmr = CFG_LBC_LSDMR_2; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 213 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 214 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 215 | ppcDcbf((unsigned long) sdram_addr); |
| 216 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 217 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 218 | lbc->lsdmr = CFG_LBC_LSDMR_3; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 219 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 220 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 221 | ppcDcbf((unsigned long) sdram_addr); |
| 222 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 223 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 224 | lbc->lsdmr = CFG_LBC_LSDMR_4; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 225 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 226 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 227 | ppcDcbf((unsigned long) sdram_addr); |
| 228 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 229 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 230 | lbc->lsdmr = CFG_LBC_LSDMR_5; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 231 | asm("sync"); |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 232 | *sdram_addr = 0xff; |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 233 | ppcDcbf((unsigned long) sdram_addr); |
| 234 | udelay(100); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
| 238 | #if defined(CFG_DRAM_TEST) |
| 239 | int testdram (void) |
| 240 | { |
| 241 | uint *pstart = (uint *) CFG_MEMTEST_START; |
| 242 | uint *pend = (uint *) CFG_MEMTEST_END; |
| 243 | uint *p; |
| 244 | |
| 245 | printf("SDRAM test phase 1:\n"); |
| 246 | for (p = pstart; p < pend; p++) |
| 247 | *p = 0xaaaaaaaa; |
| 248 | |
| 249 | for (p = pstart; p < pend; p++) { |
| 250 | if (*p != 0xaaaaaaaa) { |
| 251 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 252 | return 1; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | printf("SDRAM test phase 2:\n"); |
| 257 | for (p = pstart; p < pend; p++) |
| 258 | *p = 0x55555555; |
| 259 | |
| 260 | for (p = pstart; p < pend; p++) { |
| 261 | if (*p != 0x55555555) { |
| 262 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 263 | return 1; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | printf("SDRAM test passed.\n"); |
| 268 | return 0; |
| 269 | } |
| 270 | #endif |
| 271 | |
| 272 | |
| 273 | #if !defined(CONFIG_SPD_EEPROM) |
| 274 | /************************************************************************* |
| 275 | * fixed sdram init -- doesn't use serial presence detect. |
| 276 | ************************************************************************/ |
| 277 | long int fixed_sdram (void) |
| 278 | { |
| 279 | #ifndef CFG_RAMBOOT |
| 280 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 281 | volatile ccsr_ddr_t *ddr= &immap->im_ddr; |
| 282 | |
| 283 | ddr->cs0_bnds = CFG_DDR_CS0_BNDS; |
| 284 | ddr->cs0_config = CFG_DDR_CS0_CONFIG; |
| 285 | ddr->timing_cfg_1 = CFG_DDR_TIMING_1; |
| 286 | ddr->timing_cfg_2 = CFG_DDR_TIMING_2; |
| 287 | ddr->sdram_mode = CFG_DDR_MODE; |
| 288 | ddr->sdram_interval = CFG_DDR_INTERVAL; |
| 289 | #if defined (CONFIG_DDR_ECC) |
| 290 | ddr->err_disable = 0x0000000D; |
| 291 | ddr->err_sbe = 0x00ff0000; |
| 292 | #endif |
| 293 | asm("sync;isync;msync"); |
| 294 | udelay(500); |
| 295 | #if defined (CONFIG_DDR_ECC) |
| 296 | /* Enable ECC checking */ |
| 297 | ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000); |
| 298 | #else |
| 299 | ddr->sdram_cfg = CFG_DDR_CONTROL; |
| 300 | #endif |
| 301 | asm("sync; isync; msync"); |
| 302 | udelay(500); |
| 303 | #endif |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 304 | return CFG_SDRAM_SIZE * 1024 * 1024; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 305 | } |
| 306 | #endif /* !defined(CONFIG_SPD_EEPROM) */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 307 | |
| 308 | |
| 309 | #if defined(CONFIG_PCI) |
| 310 | /* |
| 311 | * Initialize PCI Devices, report devices found. |
| 312 | */ |
| 313 | |
| 314 | #ifndef CONFIG_PCI_PNP |
| 315 | static struct pci_config_table pci_mpc85xxads_config_table[] = { |
| 316 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 317 | PCI_IDSEL_NUMBER, PCI_ANY_ID, |
| 318 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 319 | PCI_ENET0_MEMADDR, |
| 320 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
| 321 | } }, |
| 322 | { } |
| 323 | }; |
| 324 | #endif |
| 325 | |
| 326 | |
| 327 | static struct pci_controller hose = { |
| 328 | #ifndef CONFIG_PCI_PNP |
| 329 | config_table: pci_mpc85xxads_config_table, |
| 330 | #endif |
| 331 | }; |
| 332 | |
| 333 | #endif /* CONFIG_PCI */ |
| 334 | |
| 335 | |
| 336 | void |
| 337 | pci_init_board(void) |
| 338 | { |
| 339 | #ifdef CONFIG_PCI |
| 340 | extern void pci_mpc85xx_init(struct pci_controller *hose); |
| 341 | |
| 342 | pci_mpc85xx_init(&hose); |
| 343 | #endif /* CONFIG_PCI */ |
| 344 | } |