Stefan Roese | 9964474 | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2005 |
| 3 | * John Otken, jotken@softadvances.com |
| 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 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <ppc4xx.h> |
| 27 | #include <asm/processor.h> |
| 28 | #include <spd_sdram.h> |
| 29 | #include "epld.h" |
| 30 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame^] | 31 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 9964474 | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 32 | |
| 33 | extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
| 34 | |
| 35 | |
| 36 | /************************************************************************* |
| 37 | * int board_early_init_f() |
| 38 | * |
| 39 | ************************************************************************/ |
| 40 | int board_early_init_f(void) |
| 41 | { |
| 42 | volatile epld_t *x = (epld_t *) CFG_EPLD_BASE; |
| 43 | |
| 44 | mtebc( pb0ap, 0x03800000 ); /* set chip selects */ |
| 45 | mtebc( pb0cr, 0xffc58000 ); /* ebc0_b0cr, 4MB at 0xffc00000 CS0 */ |
| 46 | mtebc( pb1ap, 0x03800000 ); |
| 47 | mtebc( pb1cr, 0xff018000 ); /* ebc0_b1cr, 1MB at 0xff000000 CS1 */ |
| 48 | mtebc( pb2ap, 0x03800000 ); |
| 49 | mtebc( pb2cr, 0xff838000 ); /* ebc0_b2cr, 2MB at 0xff800000 CS2 */ |
| 50 | |
| 51 | mtdcr( uic1sr, 0xffffffff ); /* Clear all interrupts */ |
| 52 | mtdcr( uic1er, 0x00000000 ); /* disable all interrupts */ |
| 53 | mtdcr( uic1cr, 0x00000000 ); /* Set Critical / Non Critical interrupts */ |
| 54 | mtdcr( uic1pr, 0x7fff83ff ); /* Set Interrupt Polarities */ |
| 55 | mtdcr( uic1tr, 0x001f8000 ); /* Set Interrupt Trigger Levels */ |
| 56 | mtdcr( uic1vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */ |
| 57 | mtdcr( uic1sr, 0x00000000 ); /* clear all interrupts */ |
| 58 | mtdcr( uic1sr, 0xffffffff ); |
| 59 | |
| 60 | mtdcr( uic0sr, 0xffffffff ); /* Clear all interrupts */ |
| 61 | mtdcr( uic0er, 0x00000000 ); /* disable all interrupts excepted cascade */ |
| 62 | mtdcr( uic0cr, 0x00000001 ); /* Set Critical / Non Critical interrupts */ |
| 63 | mtdcr( uic0pr, 0xffffffff ); /* Set Interrupt Polarities */ |
| 64 | mtdcr( uic0tr, 0x01000004 ); /* Set Interrupt Trigger Levels */ |
| 65 | mtdcr( uic0vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */ |
| 66 | mtdcr( uic0sr, 0x00000000 ); /* clear all interrupts */ |
| 67 | mtdcr( uic0sr, 0xffffffff ); |
| 68 | |
| 69 | x->ethuart &= ~EPLD2_RESET_ETH_N; /* put Ethernet+PHY in reset */ |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /************************************************************************* |
| 76 | * int misc_init_r() |
| 77 | * |
| 78 | ************************************************************************/ |
| 79 | int misc_init_r(void) |
| 80 | { |
| 81 | volatile epld_t *x = (epld_t *) CFG_EPLD_BASE; |
| 82 | x->ethuart |= EPLD2_RESET_ETH_N; /* take Ethernet+PHY out of reset */ |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | /************************************************************************* |
| 89 | * int checkboard() |
| 90 | * |
| 91 | ************************************************************************/ |
| 92 | int checkboard(void) |
| 93 | { |
| 94 | char *s = getenv("serial#"); |
| 95 | |
| 96 | printf("Board: Luan - AMCC PPC440SP Evaluation Board"); |
| 97 | |
| 98 | if (s != NULL) { |
| 99 | puts(", serial# "); |
| 100 | puts(s); |
| 101 | } |
| 102 | putc('\n'); |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /************************************************************************* |
| 109 | * long int fixed_sdram() |
| 110 | * |
| 111 | ************************************************************************/ |
| 112 | static long int fixed_sdram(void) |
| 113 | { /* DDR2 init from BDI2000 script */ |
| 114 | mtdcr( 0x10, 0x00000021 ); /* MCIF0_MCOPT2 - zero DCEN bit */ |
| 115 | mtdcr( 0x11, 0x84000000 ); |
| 116 | mtdcr( 0x10, 0x00000020 ); /* MCIF0_MCOPT1 - no ECC, 64 bits, 4 banks, DDR2 */ |
| 117 | mtdcr( 0x11, 0x2D122000 ); |
| 118 | mtdcr( 0x10, 0x00000026 ); /* MCIF0_CODT - die termination on */ |
| 119 | mtdcr( 0x11, 0x00800026 ); |
| 120 | mtdcr( 0x10, 0x00000081 ); /* MCIF0_WRDTR - Write DQS Adv 90 + Fractional DQS Delay */ |
| 121 | mtdcr( 0x11, 0x82000800 ); |
| 122 | mtdcr( 0x10, 0x00000080 ); /* MCIF0_CLKTR - advance addr clock by 180 deg */ |
| 123 | mtdcr( 0x11, 0x80000000 ); |
| 124 | mtdcr( 0x10, 0x00000040 ); /* MCIF0_MB0CF - turn on CS0, N x 10 coll */ |
| 125 | mtdcr( 0x11, 0x00000201 ); |
| 126 | mtdcr( 0x10, 0x00000044 ); /* MCIF0_MB1CF - turn on CS0, N x 10 coll */ |
| 127 | mtdcr( 0x11, 0x00000201 ); |
| 128 | mtdcr( 0x10, 0x00000030 ); /* MCIF0_RTR - refresh every 7.8125uS */ |
| 129 | mtdcr( 0x11, 0x08200000 ); |
| 130 | mtdcr( 0x10, 0x00000085 ); /* MCIF0_SDTR1 - timing register 1 */ |
| 131 | mtdcr( 0x11, 0x80201000 ); |
| 132 | mtdcr( 0x10, 0x00000086 ); /* MCIF0_SDTR2 - timing register 2 */ |
| 133 | mtdcr( 0x11, 0x42103242 ); |
| 134 | mtdcr( 0x10, 0x00000087 ); /* MCIF0_SDTR3 - timing register 3 */ |
| 135 | mtdcr( 0x11, 0x0C100D14 ); |
| 136 | mtdcr( 0x10, 0x00000088 ); /* MCIF0_MMODE - CAS is 4 cycles */ |
| 137 | mtdcr( 0x11, 0x00000642 ); |
| 138 | mtdcr( 0x10, 0x00000089 ); /* MCIF0_MEMODE - diff DQS disabled */ |
| 139 | mtdcr( 0x11, 0x00000400 ); /* ODT term disabled */ |
| 140 | |
| 141 | mtdcr( 0x10, 0x00000050 ); /* MCIF0_INITPLR0 - NOP */ |
| 142 | mtdcr( 0x11, 0x81b80000 ); |
| 143 | mtdcr( 0x10, 0x00000051 ); /* MCIF0_INITPLR1 - PRE */ |
| 144 | mtdcr( 0x11, 0x82100400 ); |
| 145 | mtdcr( 0x10, 0x00000052 ); /* MCIF0_INITPLR2 - EMR2 */ |
| 146 | mtdcr( 0x11, 0x80820000 ); |
| 147 | mtdcr( 0x10, 0x00000053 ); /* MCIF0_INITPLR3 - EMR3 */ |
| 148 | mtdcr( 0x11, 0x80830000 ); |
| 149 | mtdcr( 0x10, 0x00000054 ); /* MCIF0_INITPLR4 - EMR DLL ENABLE */ |
| 150 | mtdcr( 0x11, 0x80810000 ); |
| 151 | mtdcr( 0x10, 0x00000055 ); /* MCIF0_INITPLR5 - MR DLL RESET */ |
| 152 | mtdcr( 0x11, 0x80800542 ); |
| 153 | mtdcr( 0x10, 0x00000056 ); /* MCIF0_INITPLR6 - PRE */ |
| 154 | mtdcr( 0x11, 0x82100400 ); |
| 155 | mtdcr( 0x10, 0x00000057 ); /* MCIF0_INITPLR7 - refresh */ |
| 156 | mtdcr( 0x11, 0x99080000 ); |
| 157 | mtdcr( 0x10, 0x00000058 ); /* MCIF0_INITPLR8 */ |
| 158 | mtdcr( 0x11, 0x99080000 ); |
| 159 | mtdcr( 0x10, 0x00000059 ); /* MCIF0_INITPLR9 */ |
| 160 | mtdcr( 0x11, 0x99080000 ); |
| 161 | mtdcr( 0x10, 0x0000005A ); /* MCIF0_INITPLR10 */ |
| 162 | mtdcr( 0x11, 0x99080000 ); |
| 163 | mtdcr( 0x10, 0x0000005B ); /* MCIF0_INITPLR11 - MR */ |
| 164 | mtdcr( 0x11, 0x80800442 ); |
| 165 | mtdcr( 0x10, 0x0000005C ); /* MCIF0_INITPLR12 - EMR OCD Default */ |
| 166 | mtdcr( 0x11, 0x80810380 ); |
| 167 | mtdcr( 0x10, 0x0000005D ); /* MCIF0_INITPLR13 - EMR OCD exit */ |
| 168 | mtdcr( 0x11, 0x80810000 ); |
| 169 | udelay( 10*1000 ); |
| 170 | |
| 171 | mtdcr( 0x10, 0x00000021 ); /* MCIF0_MCOPT2 - execute preloaded init */ |
| 172 | mtdcr( 0x11, 0x28000000 ); /* set DC_EN */ |
| 173 | udelay( 100*1000 ); |
| 174 | |
| 175 | mtdcr( 0x40, 0x0000F800 ); /* MQ0_B0BAS: base addr 00000000 / 256MB */ |
| 176 | mtdcr( 0x41, 0x1000F800 ); /* MQ0_B1BAS: base addr 10000000 / 256MB */ |
| 177 | |
| 178 | mtdcr( 0x10, 0x00000078 ); /* MCIF0_RDCC - auto set read stage */ |
| 179 | mtdcr( 0x11, 0x00000000 ); |
| 180 | mtdcr( 0x10, 0x00000070 ); /* MCIF0_RQDC - read DQS delay control */ |
| 181 | mtdcr( 0x11, 0x8000003A ); /* enabled, frac DQS delay */ |
| 182 | mtdcr( 0x10, 0x00000074 ); /* MCIF0_RFDC - two clock feedback delay */ |
| 183 | mtdcr( 0x11, 0x00000200 ); |
| 184 | |
| 185 | return 512 << 20; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /************************************************************************* |
| 190 | * long int initdram |
| 191 | * |
| 192 | ************************************************************************/ |
| 193 | long int initdram( int board_type ) |
| 194 | { |
| 195 | long dram_size = 0; |
| 196 | |
| 197 | #if defined(CONFIG_SPD_EEPROM) |
| 198 | dram_size = spd_sdram (0); |
| 199 | #else |
| 200 | dram_size = fixed_sdram (); |
| 201 | #endif |
| 202 | |
| 203 | return dram_size; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /************************************************************************* |
| 208 | * int testdram() |
| 209 | * |
| 210 | ************************************************************************/ |
| 211 | #if defined(CFG_DRAM_TEST) |
| 212 | int testdram(void) |
| 213 | { |
| 214 | unsigned long *mem = (unsigned long *) 0; |
| 215 | const unsigned long kend = (1024 / sizeof(unsigned long)); |
| 216 | unsigned long k, n; |
| 217 | |
| 218 | mtmsr(0); |
| 219 | |
| 220 | for (k = 0; k < CFG_KBYTES_SDRAM; |
| 221 | ++k, mem += (1024 / sizeof(unsigned long))) { |
| 222 | if ((k & 1023) == 0) { |
| 223 | printf("%3d MB\r", k / 1024); |
| 224 | } |
| 225 | |
| 226 | memset(mem, 0xaaaaaaaa, 1024); |
| 227 | for (n = 0; n < kend; ++n) { |
| 228 | if (mem[n] != 0xaaaaaaaa) { |
| 229 | printf("SDRAM test fails at: %08x\n", |
| 230 | (uint) & mem[n]); |
| 231 | return 1; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | memset(mem, 0x55555555, 1024); |
| 236 | for (n = 0; n < kend; ++n) { |
| 237 | if (mem[n] != 0x55555555) { |
| 238 | printf("SDRAM test fails at: %08x\n", |
| 239 | (uint) & mem[n]); |
| 240 | return 1; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | printf("SDRAM test passes\n"); |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | |
| 251 | /************************************************************************* |
| 252 | * pci_pre_init |
| 253 | * |
| 254 | * This routine is called just prior to registering the hose and gives |
| 255 | * the board the opportunity to check things. Returning a value of zero |
| 256 | * indicates that things are bad & PCI initialization should be aborted. |
| 257 | * |
| 258 | * Different boards may wish to customize the pci controller structure |
| 259 | * (add regions, override default access routines, etc) or perform |
| 260 | * certain pre-initialization actions. |
| 261 | * |
| 262 | ************************************************************************/ |
| 263 | #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) |
| 264 | int pci_pre_init( struct pci_controller *hose ) |
| 265 | { |
| 266 | unsigned long strap; |
| 267 | |
| 268 | /*--------------------------------------------------------------------------+ |
| 269 | * The luan board is always configured as the host & requires the |
| 270 | * PCI arbiter to be enabled. |
| 271 | *--------------------------------------------------------------------------*/ |
| 272 | mfsdr(sdr_sdstp1, strap); |
| 273 | if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ) { |
| 274 | printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap); |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | return 1; |
| 280 | } |
| 281 | #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */ |
| 282 | |
| 283 | |
| 284 | /************************************************************************* |
| 285 | * pci_target_init |
| 286 | * |
| 287 | * The bootstrap configuration provides default settings for the pci |
| 288 | * inbound map (PIM). But the bootstrap config choices are limited and |
| 289 | * may not be sufficient for a given board. |
| 290 | * |
| 291 | ************************************************************************/ |
| 292 | #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) |
| 293 | void pci_target_init(struct pci_controller *hose) |
| 294 | { |
Stefan Roese | 9964474 | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 295 | /*--------------------------------------------------------------------------+ |
| 296 | * Disable everything |
| 297 | *--------------------------------------------------------------------------*/ |
| 298 | out32r( PCIX0_PIM0SA, 0 ); /* disable */ |
| 299 | out32r( PCIX0_PIM1SA, 0 ); /* disable */ |
| 300 | out32r( PCIX0_PIM2SA, 0 ); /* disable */ |
| 301 | out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */ |
| 302 | |
| 303 | /*--------------------------------------------------------------------------+ |
| 304 | * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping |
| 305 | * options to not support sizes such as 128/256 MB. |
| 306 | *--------------------------------------------------------------------------*/ |
| 307 | out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE ); |
| 308 | out32r( PCIX0_PIM0LAH, 0 ); |
| 309 | out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 ); |
| 310 | |
| 311 | out32r( PCIX0_BAR0, 0 ); |
| 312 | |
| 313 | /*--------------------------------------------------------------------------+ |
| 314 | * Program the board's subsystem id/vendor id |
| 315 | *--------------------------------------------------------------------------*/ |
| 316 | out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID ); |
| 317 | out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID ); |
| 318 | |
| 319 | out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY ); |
| 320 | } |
| 321 | #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */ |
| 322 | |
| 323 | |
| 324 | /************************************************************************* |
| 325 | * is_pci_host |
| 326 | * |
| 327 | * This routine is called to determine if a pci scan should be |
| 328 | * performed. With various hardware environments (especially cPCI and |
| 329 | * PPMC) it's insufficient to depend on the state of the arbiter enable |
| 330 | * bit in the strap register, or generic host/adapter assumptions. |
| 331 | * |
| 332 | * Rather than hard-code a bad assumption in the general 440 code, the |
| 333 | * 440 pci code requires the board to decide at runtime. |
| 334 | * |
| 335 | * Return 0 for adapter mode, non-zero for host (monarch) mode. |
| 336 | * |
| 337 | * |
| 338 | ************************************************************************/ |
| 339 | #if defined(CONFIG_PCI) |
| 340 | int is_pci_host(struct pci_controller *hose) |
| 341 | { |
| 342 | return 1; |
| 343 | } |
| 344 | #endif /* defined(CONFIG_PCI) */ |
| 345 | |
| 346 | |
| 347 | /************************************************************************* |
| 348 | * hw_watchdog_reset |
| 349 | * |
| 350 | * This routine is called to reset (keep alive) the watchdog timer |
| 351 | * |
| 352 | ************************************************************************/ |
| 353 | #if defined(CONFIG_HW_WATCHDOG) |
| 354 | void hw_watchdog_reset(void) |
| 355 | { |
| 356 | } |
| 357 | #endif |
| 358 | |
| 359 | |
| 360 | /************************************************************************* |
| 361 | * int on_off() |
| 362 | * |
| 363 | ************************************************************************/ |
| 364 | static int on_off( const char *s ) |
| 365 | { |
| 366 | if (strcmp(s, "on") == 0) { |
| 367 | return 1; |
| 368 | } else if (strcmp(s, "off") == 0) { |
| 369 | return 0; |
| 370 | } |
| 371 | return -1; |
| 372 | } |
| 373 | |
| 374 | |
| 375 | /************************************************************************* |
| 376 | * void l2cache_disable() |
| 377 | * |
| 378 | ************************************************************************/ |
| 379 | static void l2cache_disable(void) |
| 380 | { |
| 381 | mtdcr( l2_cache_cfg, 0 ); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | /************************************************************************* |
| 386 | * void l2cache_enable() |
| 387 | * |
| 388 | ************************************************************************/ |
| 389 | static void l2cache_enable(void) /* see p258 7.4.1 Enabling L2 Cache */ |
| 390 | { |
| 391 | mtdcr( l2_cache_cfg, 0x80000000 ); /* enable L2_MODE L2_CFG[L2M] */ |
| 392 | |
| 393 | mtdcr( l2_cache_addr, 0 ); /* set L2_ADDR with all zeros */ |
| 394 | |
| 395 | mtdcr( l2_cache_cmd, 0x80000000 ); /* issue HCLEAR command via L2_CMD */ |
| 396 | |
| 397 | while (!(mfdcr( l2_cache_stat ) & 0x80000000 )) ;; /* poll L2_SR for completion */ |
| 398 | |
| 399 | mtdcr( l2_cache_cmd, 0x10000000 ); /* clear cache errors L2_CMD[CCP] */ |
| 400 | |
| 401 | mtdcr( l2_cache_cmd, 0x08000000 ); /* clear tag errors L2_CMD[CTE] */ |
| 402 | |
| 403 | mtdcr( l2_cache_snp0, 0 ); /* snoop registers */ |
| 404 | mtdcr( l2_cache_snp1, 0 ); |
| 405 | |
| 406 | __asm__ volatile ("sync"); /* msync */ |
| 407 | |
| 408 | mtdcr( l2_cache_cfg, 0xe0000000 ); /* inst and data use L2 */ |
| 409 | |
| 410 | __asm__ volatile ("sync"); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | /************************************************************************* |
| 415 | * int l2cache_status() |
| 416 | * |
| 417 | ************************************************************************/ |
| 418 | static int l2cache_status(void) |
| 419 | { |
| 420 | return (mfdcr( l2_cache_cfg ) & 0x60000000) != 0; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | /************************************************************************* |
| 425 | * int do_l2cache() |
| 426 | * |
| 427 | ************************************************************************/ |
| 428 | int do_l2cache( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) |
| 429 | { |
| 430 | switch (argc) { |
| 431 | case 2: /* on / off */ |
| 432 | switch (on_off(argv[1])) { |
| 433 | case 0: l2cache_disable(); |
| 434 | break; |
| 435 | case 1: l2cache_enable(); |
| 436 | break; |
| 437 | } |
| 438 | /* FALL TROUGH */ |
| 439 | case 1: /* get status */ |
| 440 | printf ("L2 Cache is %s\n", |
| 441 | l2cache_status() ? "ON" : "OFF"); |
| 442 | return 0; |
| 443 | default: |
| 444 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 445 | return 1; |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | U_BOOT_CMD( |
| 453 | l2cache, 2, 1, do_l2cache, |
| 454 | "l2cache - enable or disable L2 cache\n", |
| 455 | "[on, off]\n" |
| 456 | " - enable or disable L2 cache\n" |
| 457 | ); |