Andy Fleming | 6743105 | 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> |
| 30 | |
| 31 | #include "bcsr.h" |
| 32 | |
| 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 | /* |
| 46 | * Initialize local bus. |
| 47 | */ |
| 48 | local_bus_init (); |
| 49 | |
| 50 | enable_8568mds_duart(); |
| 51 | enable_8568mds_flash_write(); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int checkboard (void) |
| 57 | { |
| 58 | printf ("Board: 8568 MDS\n"); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | long int |
| 64 | initdram(int board_type) |
| 65 | { |
| 66 | long dram_size = 0; |
| 67 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 68 | |
| 69 | puts("Initializing\n"); |
| 70 | |
| 71 | #if defined(CONFIG_DDR_DLL) |
| 72 | { |
| 73 | /* |
| 74 | * Work around to stabilize DDR DLL MSYNC_IN. |
| 75 | * Errata DDR9 seems to have been fixed. |
| 76 | * This is now the workaround for Errata DDR11: |
| 77 | * Override DLL = 1, Course Adj = 1, Tap Select = 0 |
| 78 | */ |
| 79 | |
| 80 | volatile ccsr_gur_t *gur= &immap->im_gur; |
| 81 | |
| 82 | gur->ddrdllcr = 0x81000000; |
| 83 | asm("sync;isync;msync"); |
| 84 | udelay(200); |
| 85 | } |
| 86 | #endif |
| 87 | dram_size = spd_sdram(); |
| 88 | |
| 89 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 90 | /* |
| 91 | * Initialize and enable DDR ECC. |
| 92 | */ |
| 93 | ddr_enable_ecc(dram_size); |
| 94 | #endif |
| 95 | /* |
| 96 | * SDRAM Initialization |
| 97 | */ |
| 98 | sdram_init(); |
| 99 | |
| 100 | puts(" DDR: "); |
| 101 | return dram_size; |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * Initialize Local Bus |
| 106 | */ |
| 107 | void |
| 108 | local_bus_init(void) |
| 109 | { |
| 110 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 111 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 112 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 113 | |
| 114 | uint clkdiv; |
| 115 | uint lbc_hz; |
| 116 | sys_info_t sysinfo; |
| 117 | |
| 118 | get_sys_info(&sysinfo); |
| 119 | clkdiv = (lbc->lcrr & 0x0f) * 2; |
| 120 | lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv; |
| 121 | |
| 122 | gur->lbiuiplldcr1 = 0x00078080; |
| 123 | if (clkdiv == 16) { |
| 124 | gur->lbiuiplldcr0 = 0x7c0f1bf0; |
| 125 | } else if (clkdiv == 8) { |
| 126 | gur->lbiuiplldcr0 = 0x6c0f1bf0; |
| 127 | } else if (clkdiv == 4) { |
| 128 | gur->lbiuiplldcr0 = 0x5c0f1bf0; |
| 129 | } |
| 130 | |
| 131 | lbc->lcrr |= 0x00030000; |
| 132 | |
| 133 | asm("sync;isync;msync"); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Initialize SDRAM memory on the Local Bus. |
| 138 | */ |
| 139 | void |
| 140 | sdram_init(void) |
| 141 | { |
| 142 | #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM) |
| 143 | |
| 144 | uint idx; |
| 145 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 146 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
| 147 | uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE; |
| 148 | uint lsdmr_common; |
| 149 | |
| 150 | puts(" SDRAM: "); |
| 151 | |
| 152 | print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); |
| 153 | |
| 154 | /* |
| 155 | * Setup SDRAM Base and Option Registers |
| 156 | */ |
| 157 | lbc->or2 = CFG_OR2_PRELIM; |
| 158 | asm("msync"); |
| 159 | |
| 160 | lbc->br2 = CFG_BR2_PRELIM; |
| 161 | asm("msync"); |
| 162 | |
| 163 | lbc->lbcr = CFG_LBC_LBCR; |
| 164 | asm("msync"); |
| 165 | |
| 166 | |
| 167 | lbc->lsrt = CFG_LBC_LSRT; |
| 168 | lbc->mrtpr = CFG_LBC_MRTPR; |
| 169 | asm("msync"); |
| 170 | |
| 171 | /* |
| 172 | * MPC8568 uses "new" 15-16 style addressing. |
| 173 | */ |
| 174 | lsdmr_common = CFG_LBC_LSDMR_COMMON; |
| 175 | lsdmr_common |= CFG_LBC_LSDMR_BSMA1516; |
| 176 | |
| 177 | /* |
| 178 | * Issue PRECHARGE ALL command. |
| 179 | */ |
| 180 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL; |
| 181 | asm("sync;msync"); |
| 182 | *sdram_addr = 0xff; |
| 183 | ppcDcbf((unsigned long) sdram_addr); |
| 184 | udelay(100); |
| 185 | |
| 186 | /* |
| 187 | * Issue 8 AUTO REFRESH commands. |
| 188 | */ |
| 189 | for (idx = 0; idx < 8; idx++) { |
| 190 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH; |
| 191 | asm("sync;msync"); |
| 192 | *sdram_addr = 0xff; |
| 193 | ppcDcbf((unsigned long) sdram_addr); |
| 194 | udelay(100); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Issue 8 MODE-set command. |
| 199 | */ |
| 200 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW; |
| 201 | asm("sync;msync"); |
| 202 | *sdram_addr = 0xff; |
| 203 | ppcDcbf((unsigned long) sdram_addr); |
| 204 | udelay(100); |
| 205 | |
| 206 | /* |
| 207 | * Issue NORMAL OP command. |
| 208 | */ |
| 209 | lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL; |
| 210 | asm("sync;msync"); |
| 211 | *sdram_addr = 0xff; |
| 212 | ppcDcbf((unsigned long) sdram_addr); |
| 213 | udelay(200); /* Overkill. Must wait > 200 bus cycles */ |
| 214 | |
| 215 | #endif /* enable SDRAM init */ |
| 216 | } |
| 217 | |
| 218 | #if defined(CFG_DRAM_TEST) |
| 219 | int |
| 220 | testdram(void) |
| 221 | { |
| 222 | uint *pstart = (uint *) CFG_MEMTEST_START; |
| 223 | uint *pend = (uint *) CFG_MEMTEST_END; |
| 224 | uint *p; |
| 225 | |
| 226 | printf("Testing DRAM from 0x%08x to 0x%08x\n", |
| 227 | CFG_MEMTEST_START, |
| 228 | CFG_MEMTEST_END); |
| 229 | |
| 230 | printf("DRAM test phase 1:\n"); |
| 231 | for (p = pstart; p < pend; p++) |
| 232 | *p = 0xaaaaaaaa; |
| 233 | |
| 234 | for (p = pstart; p < pend; p++) { |
| 235 | if (*p != 0xaaaaaaaa) { |
| 236 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 237 | return 1; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | printf("DRAM test phase 2:\n"); |
| 242 | for (p = pstart; p < pend; p++) |
| 243 | *p = 0x55555555; |
| 244 | |
| 245 | for (p = pstart; p < pend; p++) { |
| 246 | if (*p != 0x55555555) { |
| 247 | printf ("DRAM test fails at: %08x\n", (uint) p); |
| 248 | return 1; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | printf("DRAM test passed.\n"); |
| 253 | return 0; |
| 254 | } |
| 255 | #endif |
| 256 | |
| 257 | #if defined(CONFIG_PCI) |
| 258 | #ifndef CONFIG_PCI_PNP |
| 259 | static struct pci_config_table pci_mpc8568mds_config_table[] = { |
| 260 | { |
| 261 | PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 262 | pci_cfgfunc_config_device, |
| 263 | {PCI_ENET0_IOADDR, |
| 264 | PCI_ENET0_MEMADDR, |
| 265 | PCI_COMMON_MEMORY | PCI_COMMAND_MASTER} |
| 266 | }, |
| 267 | {} |
| 268 | }; |
| 269 | #endif |
| 270 | |
| 271 | static struct pci_controller hose[] = { |
| 272 | #ifndef CONFIG_PCI_PNP |
| 273 | { config_table: pci_mpc8568mds_config_table,}, |
| 274 | #endif |
| 275 | #ifdef CONFIG_MPC85XX_PCI2 |
| 276 | {}, |
| 277 | #endif |
| 278 | }; |
| 279 | |
| 280 | #endif /* CONFIG_PCI */ |
| 281 | |
| 282 | void |
| 283 | pci_init_board(void) |
| 284 | { |
| 285 | #ifdef CONFIG_PCI |
| 286 | pci_mpc85xx_init(&hose); |
| 287 | #endif |
| 288 | } |