wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 Freescale Semiconductor. |
| 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 | |
| 28 | #include <common.h> |
| 29 | #include <pci.h> |
| 30 | #include <asm/processor.h> |
Kumar Gala | d53bd3e | 2008-08-26 23:51:49 -0500 | [diff] [blame^] | 31 | #include <asm/mmu.h> |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 32 | #include <asm/immap_85xx.h> |
Kumar Gala | d53bd3e | 2008-08-26 23:51:49 -0500 | [diff] [blame^] | 33 | #include <asm/fsl_ddr_sdram.h> |
Jon Loeliger | a30a549 | 2008-03-04 10:03:03 -0600 | [diff] [blame] | 34 | #include <spd_sdram.h> |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 35 | |
| 36 | #if defined(CONFIG_DDR_ECC) |
| 37 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 38 | #endif |
| 39 | |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 40 | void local_bus_init(void); |
| 41 | void sdram_init(void); |
| 42 | long int fixed_sdram(void); |
| 43 | |
| 44 | |
| 45 | int board_early_init_f (void) |
| 46 | { |
| 47 | #if defined(CONFIG_PCI) |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 48 | volatile ccsr_pcix_t *pci = (void *)(CFG_MPC85xx_PCIX_ADDR); |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 49 | |
| 50 | pci->peer &= 0xffffffdf; /* disable master abort */ |
| 51 | #endif |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int checkboard (void) |
| 57 | { |
| 58 | puts("Board: MicroSys PM854\n"); |
| 59 | |
| 60 | #ifdef CONFIG_PCI |
| 61 | printf(" PCI1: 32 bit, %d MHz (compiled)\n", |
| 62 | CONFIG_SYS_CLK_FREQ / 1000000); |
| 63 | #else |
| 64 | printf(" PCI1: disabled\n"); |
| 65 | #endif |
| 66 | |
| 67 | /* |
| 68 | * Initialize local bus. |
| 69 | */ |
| 70 | local_bus_init(); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 76 | phys_size_t |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 77 | initdram(int board_type) |
| 78 | { |
| 79 | long dram_size = 0; |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 80 | |
| 81 | puts("Initializing\n"); |
| 82 | |
| 83 | #if defined(CONFIG_DDR_DLL) |
| 84 | { |
Kumar Gala | f59b55a | 2007-11-27 23:25:02 -0600 | [diff] [blame] | 85 | volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR); |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 86 | int i,x; |
wdenk | 8b0bfc6 | 2005-04-03 23:11:38 +0000 | [diff] [blame] | 87 | |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 88 | x = 10; |
wdenk | 8b0bfc6 | 2005-04-03 23:11:38 +0000 | [diff] [blame] | 89 | |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 90 | /* |
| 91 | * Work around to stabilize DDR DLL |
| 92 | */ |
| 93 | gur->ddrdllcr = 0x81000000; |
| 94 | asm("sync;isync;msync"); |
| 95 | udelay (200); |
| 96 | while (gur->ddrdllcr != 0x81000100) |
| 97 | { |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 98 | gur->devdisr = gur->devdisr | 0x00010000; |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 99 | asm("sync;isync;msync"); |
| 100 | for (i=0; i<x; i++) |
| 101 | ; |
| 102 | gur->devdisr = gur->devdisr & 0xfff7ffff; |
| 103 | asm("sync;isync;msync"); |
| 104 | x++; |
| 105 | } |
wdenk | 8b0bfc6 | 2005-04-03 23:11:38 +0000 | [diff] [blame] | 106 | } |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 107 | #endif |
| 108 | |
| 109 | #if defined(CONFIG_SPD_EEPROM) |
Kumar Gala | d53bd3e | 2008-08-26 23:51:49 -0500 | [diff] [blame^] | 110 | dram_size = fsl_ddr_sdram(); |
| 111 | dram_size = setup_ddr_tlbs(dram_size / 0x100000); |
| 112 | dram_size *= 0x100000; |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 113 | #else |
| 114 | dram_size = fixed_sdram (); |
| 115 | #endif |
| 116 | |
| 117 | #if defined(CONFIG_DDR_ECC) |
| 118 | /* |
| 119 | * Initialize and enable DDR ECC. |
| 120 | */ |
| 121 | ddr_enable_ecc(dram_size); |
| 122 | #endif |
| 123 | puts(" DDR: "); |
| 124 | return dram_size; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /* |
| 129 | * Initialize Local Bus |
| 130 | */ |
| 131 | |
| 132 | void |
| 133 | local_bus_init(void) |
| 134 | { |
Kumar Gala | f59b55a | 2007-11-27 23:25:02 -0600 | [diff] [blame] | 135 | volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR); |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 136 | volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR); |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 137 | |
| 138 | uint clkdiv; |
| 139 | uint lbc_hz; |
| 140 | sys_info_t sysinfo; |
| 141 | |
| 142 | /* |
| 143 | * Errata LBC11. |
| 144 | * Fix Local Bus clock glitch when DLL is enabled. |
| 145 | * |
| 146 | * If localbus freq is < 66Mhz, DLL bypass mode must be used. |
| 147 | * If localbus freq is > 133Mhz, DLL can be safely enabled. |
| 148 | * Between 66 and 133, the DLL is enabled with an override workaround. |
| 149 | */ |
| 150 | |
| 151 | get_sys_info(&sysinfo); |
| 152 | clkdiv = lbc->lcrr & 0x0f; |
| 153 | lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv; |
| 154 | |
| 155 | if (lbc_hz < 66) { |
| 156 | lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */ |
| 157 | |
| 158 | } else if (lbc_hz >= 133) { |
| 159 | lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */ |
| 160 | |
| 161 | } else { |
| 162 | /* |
| 163 | * On REV1 boards, need to change CLKDIV before enable DLL. |
| 164 | * Default CLKDIV is 8, change it to 4 temporarily. |
| 165 | */ |
| 166 | uint pvr = get_pvr(); |
| 167 | uint temp_lbcdll = 0; |
| 168 | |
| 169 | if (pvr == PVR_85xx_REV1) { |
| 170 | /* FIXME: Justify the high bit here. */ |
| 171 | lbc->lcrr = 0x10000004; |
| 172 | } |
| 173 | |
| 174 | lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */ |
| 175 | udelay(200); |
| 176 | |
| 177 | /* |
| 178 | * Sample LBC DLL ctrl reg, upshift it to set the |
| 179 | * override bits. |
| 180 | */ |
| 181 | temp_lbcdll = gur->lbcdllcr; |
| 182 | gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000); |
| 183 | asm("sync;isync;msync"); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | #if defined(CFG_DRAM_TEST) |
| 189 | int testdram (void) |
| 190 | { |
| 191 | uint *pstart = (uint *) CFG_MEMTEST_START; |
| 192 | uint *pend = (uint *) CFG_MEMTEST_END; |
| 193 | uint *p; |
| 194 | |
| 195 | printf("SDRAM test phase 1:\n"); |
| 196 | for (p = pstart; p < pend; p++) |
| 197 | *p = 0xaaaaaaaa; |
| 198 | |
| 199 | for (p = pstart; p < pend; p++) { |
| 200 | if (*p != 0xaaaaaaaa) { |
| 201 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 202 | return 1; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | printf("SDRAM test phase 2:\n"); |
| 207 | for (p = pstart; p < pend; p++) |
| 208 | *p = 0x55555555; |
| 209 | |
| 210 | for (p = pstart; p < pend; p++) { |
| 211 | if (*p != 0x55555555) { |
| 212 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 213 | return 1; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | printf("SDRAM test passed.\n"); |
| 218 | return 0; |
| 219 | } |
| 220 | #endif |
| 221 | |
| 222 | |
| 223 | #if !defined(CONFIG_SPD_EEPROM) |
| 224 | /************************************************************************* |
| 225 | * fixed sdram init -- doesn't use serial presence detect. |
| 226 | ************************************************************************/ |
| 227 | long int fixed_sdram (void) |
| 228 | { |
| 229 | #ifndef CFG_RAMBOOT |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 230 | volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR); |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 231 | |
| 232 | ddr->cs0_bnds = CFG_DDR_CS0_BNDS; |
| 233 | ddr->cs0_config = CFG_DDR_CS0_CONFIG; |
| 234 | ddr->timing_cfg_1 = CFG_DDR_TIMING_1; |
| 235 | ddr->timing_cfg_2 = CFG_DDR_TIMING_2; |
| 236 | ddr->sdram_mode = CFG_DDR_MODE; |
| 237 | ddr->sdram_interval = CFG_DDR_INTERVAL; |
| 238 | #if defined (CONFIG_DDR_ECC) |
| 239 | ddr->err_disable = 0x0000000D; |
| 240 | ddr->err_sbe = 0x00ff0000; |
| 241 | #endif |
| 242 | asm("sync;isync;msync"); |
| 243 | udelay(500); |
| 244 | #if defined (CONFIG_DDR_ECC) |
| 245 | /* Enable ECC checking */ |
| 246 | ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000); |
| 247 | #else |
| 248 | ddr->sdram_cfg = CFG_DDR_CONTROL; |
| 249 | #endif |
| 250 | asm("sync; isync; msync"); |
| 251 | udelay(500); |
| 252 | #endif |
| 253 | return CFG_SDRAM_SIZE * 1024 * 1024; |
| 254 | } |
| 255 | #endif /* !defined(CONFIG_SPD_EEPROM) */ |
| 256 | |
| 257 | |
| 258 | #if defined(CONFIG_PCI) |
| 259 | /* |
| 260 | * Initialize PCI Devices, report devices found. |
| 261 | */ |
| 262 | |
| 263 | #ifndef CONFIG_PCI_PNP |
| 264 | static struct pci_config_table pci_pm854_config_table[] = { |
| 265 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 266 | PCI_IDSEL_NUMBER, PCI_ANY_ID, |
| 267 | pci_cfgfunc_config_device, { PCI_ENET0_IOADDR, |
| 268 | PCI_ENET0_MEMADDR, |
| 269 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
| 270 | } }, |
| 271 | { } |
| 272 | }; |
| 273 | #endif |
| 274 | |
| 275 | |
| 276 | static struct pci_controller hose = { |
| 277 | #ifndef CONFIG_PCI_PNP |
| 278 | config_table: pci_pm854_config_table, |
| 279 | #endif |
| 280 | }; |
| 281 | |
| 282 | #endif /* CONFIG_PCI */ |
| 283 | |
| 284 | |
| 285 | void |
| 286 | pci_init_board(void) |
| 287 | { |
| 288 | #ifdef CONFIG_PCI |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 289 | pci_mpc85xx_init(&hose); |
| 290 | #endif /* CONFIG_PCI */ |
| 291 | } |