Stefan Roese | 6e7fb6e | 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 | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 6e7fb6e | 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 | |
Stefan Roese | 2a49fc1 | 2007-07-16 10:01:38 +0200 | [diff] [blame] | 107 | /* |
| 108 | * Override the default functions in cpu/ppc4xx/44x_spd_ddr2.c with |
| 109 | * board specific values. |
| 110 | */ |
| 111 | u32 ddr_clktr(u32 default_val) { |
| 112 | return (SDRAM_CLKTR_CLKP_180_DEG_ADV); |
| 113 | } |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 114 | |
| 115 | /************************************************************************* |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 116 | * int testdram() |
| 117 | * |
| 118 | ************************************************************************/ |
| 119 | #if defined(CFG_DRAM_TEST) |
| 120 | int testdram(void) |
| 121 | { |
| 122 | unsigned long *mem = (unsigned long *) 0; |
| 123 | const unsigned long kend = (1024 / sizeof(unsigned long)); |
| 124 | unsigned long k, n; |
| 125 | |
| 126 | mtmsr(0); |
| 127 | |
| 128 | for (k = 0; k < CFG_KBYTES_SDRAM; |
| 129 | ++k, mem += (1024 / sizeof(unsigned long))) { |
| 130 | if ((k & 1023) == 0) { |
| 131 | printf("%3d MB\r", k / 1024); |
| 132 | } |
| 133 | |
| 134 | memset(mem, 0xaaaaaaaa, 1024); |
| 135 | for (n = 0; n < kend; ++n) { |
| 136 | if (mem[n] != 0xaaaaaaaa) { |
| 137 | printf("SDRAM test fails at: %08x\n", |
| 138 | (uint) & mem[n]); |
| 139 | return 1; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | memset(mem, 0x55555555, 1024); |
| 144 | for (n = 0; n < kend; ++n) { |
| 145 | if (mem[n] != 0x55555555) { |
| 146 | printf("SDRAM test fails at: %08x\n", |
| 147 | (uint) & mem[n]); |
| 148 | return 1; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | printf("SDRAM test passes\n"); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | #endif |
| 157 | |
| 158 | |
| 159 | /************************************************************************* |
| 160 | * pci_pre_init |
| 161 | * |
| 162 | * This routine is called just prior to registering the hose and gives |
| 163 | * the board the opportunity to check things. Returning a value of zero |
| 164 | * indicates that things are bad & PCI initialization should be aborted. |
| 165 | * |
| 166 | * Different boards may wish to customize the pci controller structure |
| 167 | * (add regions, override default access routines, etc) or perform |
| 168 | * certain pre-initialization actions. |
| 169 | * |
| 170 | ************************************************************************/ |
Stefan Roese | 466fff1 | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 171 | #if defined(CONFIG_PCI) |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 172 | int pci_pre_init( struct pci_controller *hose ) |
| 173 | { |
| 174 | unsigned long strap; |
| 175 | |
| 176 | /*--------------------------------------------------------------------------+ |
| 177 | * The luan board is always configured as the host & requires the |
| 178 | * PCI arbiter to be enabled. |
| 179 | *--------------------------------------------------------------------------*/ |
| 180 | mfsdr(sdr_sdstp1, strap); |
| 181 | if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ) { |
| 182 | printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | return 1; |
| 188 | } |
Stefan Roese | 466fff1 | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 189 | #endif /* defined(CONFIG_PCI) */ |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 190 | |
| 191 | |
| 192 | /************************************************************************* |
| 193 | * pci_target_init |
| 194 | * |
| 195 | * The bootstrap configuration provides default settings for the pci |
| 196 | * inbound map (PIM). But the bootstrap config choices are limited and |
| 197 | * may not be sufficient for a given board. |
| 198 | * |
| 199 | ************************************************************************/ |
| 200 | #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) |
| 201 | void pci_target_init(struct pci_controller *hose) |
| 202 | { |
Stefan Roese | 6e7fb6e | 2005-11-29 18:18:21 +0100 | [diff] [blame] | 203 | /*--------------------------------------------------------------------------+ |
| 204 | * Disable everything |
| 205 | *--------------------------------------------------------------------------*/ |
| 206 | out32r( PCIX0_PIM0SA, 0 ); /* disable */ |
| 207 | out32r( PCIX0_PIM1SA, 0 ); /* disable */ |
| 208 | out32r( PCIX0_PIM2SA, 0 ); /* disable */ |
| 209 | out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */ |
| 210 | |
| 211 | /*--------------------------------------------------------------------------+ |
| 212 | * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping |
| 213 | * options to not support sizes such as 128/256 MB. |
| 214 | *--------------------------------------------------------------------------*/ |
| 215 | out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE ); |
| 216 | out32r( PCIX0_PIM0LAH, 0 ); |
| 217 | out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 ); |
| 218 | |
| 219 | out32r( PCIX0_BAR0, 0 ); |
| 220 | |
| 221 | /*--------------------------------------------------------------------------+ |
| 222 | * Program the board's subsystem id/vendor id |
| 223 | *--------------------------------------------------------------------------*/ |
| 224 | out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID ); |
| 225 | out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID ); |
| 226 | |
| 227 | out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY ); |
| 228 | } |
| 229 | #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */ |
| 230 | |
| 231 | |
| 232 | /************************************************************************* |
| 233 | * is_pci_host |
| 234 | * |
| 235 | * This routine is called to determine if a pci scan should be |
| 236 | * performed. With various hardware environments (especially cPCI and |
| 237 | * PPMC) it's insufficient to depend on the state of the arbiter enable |
| 238 | * bit in the strap register, or generic host/adapter assumptions. |
| 239 | * |
| 240 | * Rather than hard-code a bad assumption in the general 440 code, the |
| 241 | * 440 pci code requires the board to decide at runtime. |
| 242 | * |
| 243 | * Return 0 for adapter mode, non-zero for host (monarch) mode. |
| 244 | * |
| 245 | * |
| 246 | ************************************************************************/ |
| 247 | #if defined(CONFIG_PCI) |
| 248 | int is_pci_host(struct pci_controller *hose) |
| 249 | { |
| 250 | return 1; |
| 251 | } |
| 252 | #endif /* defined(CONFIG_PCI) */ |
| 253 | |
| 254 | |
| 255 | /************************************************************************* |
| 256 | * hw_watchdog_reset |
| 257 | * |
| 258 | * This routine is called to reset (keep alive) the watchdog timer |
| 259 | * |
| 260 | ************************************************************************/ |
| 261 | #if defined(CONFIG_HW_WATCHDOG) |
| 262 | void hw_watchdog_reset(void) |
| 263 | { |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | |
| 268 | /************************************************************************* |
| 269 | * int on_off() |
| 270 | * |
| 271 | ************************************************************************/ |
| 272 | static int on_off( const char *s ) |
| 273 | { |
| 274 | if (strcmp(s, "on") == 0) { |
| 275 | return 1; |
| 276 | } else if (strcmp(s, "off") == 0) { |
| 277 | return 0; |
| 278 | } |
| 279 | return -1; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | /************************************************************************* |
| 284 | * void l2cache_disable() |
| 285 | * |
| 286 | ************************************************************************/ |
| 287 | static void l2cache_disable(void) |
| 288 | { |
| 289 | mtdcr( l2_cache_cfg, 0 ); |
| 290 | } |
| 291 | |
| 292 | |
| 293 | /************************************************************************* |
| 294 | * void l2cache_enable() |
| 295 | * |
| 296 | ************************************************************************/ |
| 297 | static void l2cache_enable(void) /* see p258 7.4.1 Enabling L2 Cache */ |
| 298 | { |
| 299 | mtdcr( l2_cache_cfg, 0x80000000 ); /* enable L2_MODE L2_CFG[L2M] */ |
| 300 | |
| 301 | mtdcr( l2_cache_addr, 0 ); /* set L2_ADDR with all zeros */ |
| 302 | |
| 303 | mtdcr( l2_cache_cmd, 0x80000000 ); /* issue HCLEAR command via L2_CMD */ |
| 304 | |
| 305 | while (!(mfdcr( l2_cache_stat ) & 0x80000000 )) ;; /* poll L2_SR for completion */ |
| 306 | |
| 307 | mtdcr( l2_cache_cmd, 0x10000000 ); /* clear cache errors L2_CMD[CCP] */ |
| 308 | |
| 309 | mtdcr( l2_cache_cmd, 0x08000000 ); /* clear tag errors L2_CMD[CTE] */ |
| 310 | |
| 311 | mtdcr( l2_cache_snp0, 0 ); /* snoop registers */ |
| 312 | mtdcr( l2_cache_snp1, 0 ); |
| 313 | |
| 314 | __asm__ volatile ("sync"); /* msync */ |
| 315 | |
| 316 | mtdcr( l2_cache_cfg, 0xe0000000 ); /* inst and data use L2 */ |
| 317 | |
| 318 | __asm__ volatile ("sync"); |
| 319 | } |
| 320 | |
| 321 | |
| 322 | /************************************************************************* |
| 323 | * int l2cache_status() |
| 324 | * |
| 325 | ************************************************************************/ |
| 326 | static int l2cache_status(void) |
| 327 | { |
| 328 | return (mfdcr( l2_cache_cfg ) & 0x60000000) != 0; |
| 329 | } |
| 330 | |
| 331 | |
| 332 | /************************************************************************* |
| 333 | * int do_l2cache() |
| 334 | * |
| 335 | ************************************************************************/ |
| 336 | int do_l2cache( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) |
| 337 | { |
| 338 | switch (argc) { |
| 339 | case 2: /* on / off */ |
| 340 | switch (on_off(argv[1])) { |
| 341 | case 0: l2cache_disable(); |
| 342 | break; |
| 343 | case 1: l2cache_enable(); |
| 344 | break; |
| 345 | } |
| 346 | /* FALL TROUGH */ |
| 347 | case 1: /* get status */ |
| 348 | printf ("L2 Cache is %s\n", |
| 349 | l2cache_status() ? "ON" : "OFF"); |
| 350 | return 0; |
| 351 | default: |
| 352 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 353 | return 1; |
| 354 | } |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | U_BOOT_CMD( |
| 361 | l2cache, 2, 1, do_l2cache, |
| 362 | "l2cache - enable or disable L2 cache\n", |
| 363 | "[on, off]\n" |
| 364 | " - enable or disable L2 cache\n" |
| 365 | ); |