wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch |
| 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 | * TODO: clean-up |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * How do I program the SDRAM Timing Register (SDRAM0_TR) for a specific SDRAM or DIMM? |
| 29 | * |
| 30 | * As an example, consider a case where PC133 memory with CAS Latency equal to 2 is being |
| 31 | * used with a 200MHz 405GP. For a typical 128Mb, PC133 SDRAM, the relevant minimum |
| 32 | * parameters from the datasheet are: |
| 33 | * Tclk = 7.5ns (CL = 2) |
| 34 | * Trp = 15ns |
| 35 | * Trc = 60ns |
| 36 | * Trcd = 15ns |
| 37 | * Trfc = 66ns |
| 38 | * |
| 39 | * If we are operating the 405GP with the MemClk output frequency set to 100 MHZ, the clock |
| 40 | * period is 10ns and the parameters needed for the Timing Register are: |
| 41 | * CASL = CL = 2 clock cycles |
| 42 | * PTA = Trp = 15ns / 10ns = 2 clock cycles |
| 43 | * CTP = Trc - Trcd - Trp = (60ns - 15ns - 15ns) / 10ns= 3 clock cycles |
| 44 | * LDF = 2 clock cycles (but can be extended to meet board-level timing) |
| 45 | * RFTA = Trfc = 66ns / 10ns= 7 clock cycles |
| 46 | * RCD = Trcd = 15ns / 10ns= 2 clock cycles |
| 47 | * |
| 48 | * The actual bit settings in the register would be: |
| 49 | * |
| 50 | * CASL = 0b01 |
| 51 | * PTA = 0b01 |
| 52 | * CTP = 0b10 |
| 53 | * LDF = 0b01 |
| 54 | * RFTA = 0b011 |
| 55 | * RCD = 0b01 |
| 56 | * |
| 57 | * If Trfc is not specified in the datasheet for PC100 or PC133 memory, set RFTA = Trc |
| 58 | * instead. Figure 24 in the PC SDRAM Specification Rev. 1.7 shows refresh to active delay |
| 59 | * defined as Trc rather than Trfc. |
| 60 | * When using DIMM modules, most but not all of the required timing parameters can be read |
| 61 | * from the Serial Presence Detect (SPD) EEPROM on the module. Specifically, Trc and Trfc |
| 62 | * are not available from the EEPROM |
| 63 | */ |
| 64 | |
| 65 | #include <common.h> |
| 66 | #include "mip405.h" |
| 67 | #include <asm/processor.h> |
| 68 | #include <405gp_i2c.h> |
| 69 | #include <miiphy.h> |
| 70 | #include "../common/common_util.h" |
| 71 | #include <i2c.h> |
| 72 | extern block_dev_desc_t * scsi_get_dev(int dev); |
| 73 | extern block_dev_desc_t * ide_get_dev(int dev); |
| 74 | |
| 75 | #undef SDRAM_DEBUG |
| 76 | |
| 77 | #define FALSE 0 |
| 78 | #define TRUE 1 |
| 79 | |
| 80 | /* stdlib.h causes some compatibility problems; should fixe these! -- wd */ |
| 81 | #ifndef __ldiv_t_defined |
| 82 | typedef struct { |
| 83 | long int quot; /* Quotient */ |
| 84 | long int rem; /* Remainder */ |
| 85 | } ldiv_t; |
| 86 | extern ldiv_t ldiv (long int __numer, long int __denom); |
| 87 | # define __ldiv_t_defined 1 |
| 88 | #endif |
| 89 | |
| 90 | |
| 91 | #define PLD_PART_REG PER_PLD_ADDR + 0 |
| 92 | #define PLD_VERS_REG PER_PLD_ADDR + 1 |
| 93 | #define PLD_BOARD_CFG_REG PER_PLD_ADDR + 2 |
| 94 | #define PLD_IRQ_REG PER_PLD_ADDR + 3 |
| 95 | #define PLD_COM_MODE_REG PER_PLD_ADDR + 4 |
| 96 | #define PLD_EXT_CONF_REG PER_PLD_ADDR + 5 |
| 97 | |
| 98 | #define MEGA_BYTE (1024*1024) |
| 99 | |
| 100 | typedef struct { |
| 101 | unsigned char boardtype; /* Board revision and Population Options */ |
| 102 | unsigned char cal; /* cas Latency (will be programmend as cal-1) */ |
| 103 | unsigned char trp; /* datain27 in clocks */ |
| 104 | unsigned char trcd; /* datain29 in clocks */ |
| 105 | unsigned char tras; /* datain30 in clocks */ |
| 106 | unsigned char tctp; /* tras - trcd in clocks */ |
| 107 | unsigned char am; /* Address Mod (will be programmed as am-1) */ |
| 108 | unsigned char sz; /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */ |
| 109 | unsigned char ecc; /* if true, ecc is enabled */ |
| 110 | } sdram_t; |
| 111 | |
| 112 | const sdram_t sdram_table[] = { |
| 113 | { 0x0f, /* Rev A, 128MByte -1 Board */ |
| 114 | 3, /* Case Latenty = 3 */ |
| 115 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 116 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 117 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 118 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 119 | 3, /* Address Mode = 3 */ |
| 120 | 5, /* size value */ |
| 121 | 1}, /* ECC enabled */ |
| 122 | { 0x07, /* Rev A, 64MByte -2 Board */ |
| 123 | 3, /* Case Latenty = 3 */ |
| 124 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 125 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 126 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 127 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 128 | 2, /* Address Mode = 2 */ |
| 129 | 4, /* size value */ |
| 130 | 1}, /* ECC enabled */ |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 131 | { 0x03, /* Rev A, 128MByte -4 Board */ |
| 132 | 3, /* Case Latenty = 3 */ |
| 133 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 134 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 135 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 136 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 137 | 3, /* Address Mode = 3 */ |
| 138 | 5, /* size value */ |
| 139 | 1}, /* ECC enabled */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 140 | { 0xff, /* terminator */ |
| 141 | 0xff, |
| 142 | 0xff, |
| 143 | 0xff, |
| 144 | 0xff, |
| 145 | 0xff, |
| 146 | 0xff, |
| 147 | 0xff } |
| 148 | }; |
| 149 | |
| 150 | void SDRAM_err (const char *s) |
| 151 | { |
| 152 | #ifndef SDRAM_DEBUG |
| 153 | DECLARE_GLOBAL_DATA_PTR; |
| 154 | |
| 155 | (void) get_clocks (); |
| 156 | gd->baudrate = 9600; |
| 157 | serial_init (); |
| 158 | #endif |
| 159 | serial_puts ("\n"); |
| 160 | serial_puts (s); |
| 161 | serial_puts ("\n enable SDRAM_DEBUG for more info\n"); |
| 162 | for (;;); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | unsigned char get_board_revcfg (void) |
| 167 | { |
| 168 | out8 (PER_BOARD_ADDR, 0); |
| 169 | return (in8 (PER_BOARD_ADDR)); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | #ifdef SDRAM_DEBUG |
| 174 | |
| 175 | void write_hex (unsigned char i) |
| 176 | { |
| 177 | char cc; |
| 178 | |
| 179 | cc = i >> 4; |
| 180 | cc &= 0xf; |
| 181 | if (cc > 9) |
| 182 | serial_putc (cc + 55); |
| 183 | else |
| 184 | serial_putc (cc + 48); |
| 185 | cc = i & 0xf; |
| 186 | if (cc > 9) |
| 187 | serial_putc (cc + 55); |
| 188 | else |
| 189 | serial_putc (cc + 48); |
| 190 | } |
| 191 | |
| 192 | void write_4hex (unsigned long val) |
| 193 | { |
| 194 | write_hex ((unsigned char) (val >> 24)); |
| 195 | write_hex ((unsigned char) (val >> 16)); |
| 196 | write_hex ((unsigned char) (val >> 8)); |
| 197 | write_hex ((unsigned char) val); |
| 198 | } |
| 199 | |
| 200 | #endif |
| 201 | |
| 202 | |
| 203 | int init_sdram (void) |
| 204 | { |
| 205 | DECLARE_GLOBAL_DATA_PTR; |
| 206 | |
| 207 | unsigned long tmp, baseaddr; |
| 208 | unsigned short i; |
| 209 | unsigned char trp_clocks, |
| 210 | trcd_clocks, |
| 211 | tras_clocks, |
| 212 | trc_clocks, |
| 213 | tctp_clocks; |
| 214 | unsigned char cal_val; |
| 215 | unsigned char bc; |
| 216 | unsigned long pbcr, sdram_tim, sdram_bank; |
| 217 | unsigned long *p; |
| 218 | |
| 219 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 220 | (void) get_clocks (); |
| 221 | gd->baudrate = 9600; |
| 222 | serial_init (); |
| 223 | serial_puts ("\nInitializing SDRAM, Please stand by"); |
| 224 | mtdcr (ebccfga, pb0cr); /* get cs0 config reg */ |
| 225 | pbcr = mfdcr (ebccfgd); |
| 226 | if ((pbcr & 0x00002000) == 0) { |
| 227 | /* MPS Boot, set up the flash */ |
| 228 | mtdcr (ebccfga, pb1ap); |
| 229 | mtdcr (ebccfgd, FLASH_AP); |
| 230 | mtdcr (ebccfga, pb1cr); |
| 231 | mtdcr (ebccfgd, FLASH_CR); |
| 232 | } else { |
| 233 | /* Flash boot, set up the MPS */ |
| 234 | mtdcr (ebccfga, pb1ap); |
| 235 | mtdcr (ebccfgd, MPS_AP); |
| 236 | mtdcr (ebccfga, pb1cr); |
| 237 | mtdcr (ebccfgd, MPS_CR); |
| 238 | } |
| 239 | /* set up UART0 (CS2) and UART1 (CS3) */ |
| 240 | mtdcr (ebccfga, pb2ap); |
| 241 | mtdcr (ebccfgd, UART0_AP); |
| 242 | mtdcr (ebccfga, pb2cr); |
| 243 | mtdcr (ebccfgd, UART0_CR); |
| 244 | mtdcr (ebccfga, pb3ap); |
| 245 | mtdcr (ebccfgd, UART1_AP); |
| 246 | mtdcr (ebccfga, pb3cr); |
| 247 | mtdcr (ebccfgd, UART1_CR); |
| 248 | |
| 249 | /* set up the pld */ |
| 250 | mtdcr (ebccfga, pb7ap); |
| 251 | mtdcr (ebccfgd, PLD_AP); |
| 252 | mtdcr (ebccfga, pb7cr); |
| 253 | mtdcr (ebccfgd, PLD_CR); |
| 254 | /* set up the board rev reg */ |
| 255 | mtdcr (ebccfga, pb5ap); |
| 256 | mtdcr (ebccfgd, BOARD_AP); |
| 257 | mtdcr (ebccfga, pb5cr); |
| 258 | mtdcr (ebccfgd, BOARD_CR); |
| 259 | |
| 260 | |
| 261 | #ifdef SDRAM_DEBUG |
| 262 | out8 (PER_BOARD_ADDR, 0); |
| 263 | bc = in8 (PER_BOARD_ADDR); |
| 264 | serial_puts ("\nBoard Rev: "); |
| 265 | write_hex (bc); |
| 266 | serial_puts (" (PLD="); |
| 267 | bc = in8 (PLD_BOARD_CFG_REG); |
| 268 | write_hex (bc); |
| 269 | serial_puts (")\n"); |
| 270 | #endif |
| 271 | bc = get_board_revcfg (); |
| 272 | #ifdef SDRAM_DEBUG |
| 273 | serial_puts ("\nstart SDRAM Setup\n"); |
| 274 | serial_puts ("\nBoard Rev: "); |
| 275 | write_hex (bc); |
| 276 | serial_puts ("\n"); |
| 277 | #endif |
| 278 | i = 0; |
| 279 | baseaddr = CFG_SDRAM_BASE; |
| 280 | while (sdram_table[i].sz != 0xff) { |
| 281 | if (sdram_table[i].boardtype == bc) |
| 282 | break; |
| 283 | i++; |
| 284 | } |
| 285 | if (sdram_table[i].boardtype != bc) |
| 286 | SDRAM_err ("No SDRAM table found for this board!!!\n"); |
| 287 | #ifdef SDRAM_DEBUG |
| 288 | serial_puts (" found table "); |
| 289 | write_hex (i); |
| 290 | serial_puts (" \n"); |
| 291 | #endif |
| 292 | cal_val = sdram_table[i].cal - 1; /* Cas Latency */ |
| 293 | trp_clocks = sdram_table[i].trp; /* 20ns / 7.5 ns datain[27] */ |
| 294 | trcd_clocks = sdram_table[i].trcd; /* 20ns /7.5 ns (datain[29]) */ |
| 295 | tras_clocks = sdram_table[i].tras; /* 44ns /7.5 ns (datain[30]) */ |
| 296 | /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */ |
| 297 | tctp_clocks = sdram_table[i].tctp; /* 44 - 20ns = 24ns */ |
| 298 | /* trc_clocks is sum of trp_clocks + tras_clocks */ |
| 299 | trc_clocks = trp_clocks + tras_clocks; |
| 300 | /* get SDRAM timing register */ |
| 301 | mtdcr (memcfga, mem_sdtr1); |
| 302 | sdram_tim = mfdcr (memcfgd) & ~0x018FC01F; |
| 303 | /* insert CASL value */ |
| 304 | sdram_tim |= ((unsigned long) (cal_val)) << 23; |
| 305 | /* insert PTA value */ |
| 306 | sdram_tim |= ((unsigned long) (trp_clocks - 1)) << 18; |
| 307 | /* insert CTP value */ |
| 308 | sdram_tim |= |
| 309 | ((unsigned long) (trc_clocks - trp_clocks - |
| 310 | trcd_clocks)) << 16; |
| 311 | /* insert LDF (always 01) */ |
| 312 | sdram_tim |= ((unsigned long) 0x01) << 14; |
| 313 | /* insert RFTA value */ |
| 314 | sdram_tim |= ((unsigned long) (trc_clocks - 4)) << 2; |
| 315 | /* insert RCD value */ |
| 316 | sdram_tim |= ((unsigned long) (trcd_clocks - 1)) << 0; |
| 317 | |
| 318 | tmp = ((unsigned long) (sdram_table[i].am - 1) << 13); /* AM = 3 */ |
| 319 | /* insert SZ value; */ |
| 320 | tmp |= ((unsigned long) sdram_table[i].sz << 17); |
| 321 | /* get SDRAM bank 0 register */ |
| 322 | mtdcr (memcfga, mem_mb0cf); |
| 323 | sdram_bank = mfdcr (memcfgd) & ~0xFFCEE001; |
| 324 | sdram_bank |= (baseaddr | tmp | 0x01); |
| 325 | |
| 326 | #ifdef SDRAM_DEBUG |
| 327 | serial_puts ("sdtr: "); |
| 328 | write_4hex (sdram_tim); |
| 329 | serial_puts ("\n"); |
| 330 | #endif |
| 331 | |
| 332 | /* write SDRAM timing register */ |
| 333 | mtdcr (memcfga, mem_sdtr1); |
| 334 | mtdcr (memcfgd, sdram_tim); |
| 335 | |
| 336 | #ifdef SDRAM_DEBUG |
| 337 | serial_puts ("mb0cf: "); |
| 338 | write_4hex (sdram_bank); |
| 339 | serial_puts ("\n"); |
| 340 | #endif |
| 341 | |
| 342 | /* write SDRAM bank 0 register */ |
| 343 | mtdcr (memcfga, mem_mb0cf); |
| 344 | mtdcr (memcfgd, sdram_bank); |
| 345 | |
| 346 | if (get_bus_freq (tmp) > 110000000) { /* > 110MHz */ |
| 347 | /* get SDRAM refresh interval register */ |
| 348 | mtdcr (memcfga, mem_rtr); |
| 349 | tmp = mfdcr (memcfgd) & ~0x3FF80000; |
| 350 | tmp |= 0x07F00000; |
| 351 | } else { |
| 352 | /* get SDRAM refresh interval register */ |
| 353 | mtdcr (memcfga, mem_rtr); |
| 354 | tmp = mfdcr (memcfgd) & ~0x3FF80000; |
| 355 | tmp |= 0x05F00000; |
| 356 | } |
| 357 | /* write SDRAM refresh interval register */ |
| 358 | mtdcr (memcfga, mem_rtr); |
| 359 | mtdcr (memcfgd, tmp); |
| 360 | /* enable ECC if used */ |
| 361 | #if 1 |
| 362 | if (sdram_table[i].ecc) { |
| 363 | /* disable checking for all banks */ |
| 364 | #ifdef SDRAM_DEBUG |
| 365 | serial_puts ("disable ECC.. "); |
| 366 | #endif |
| 367 | mtdcr (memcfga, mem_ecccf); |
| 368 | tmp = mfdcr (memcfgd); |
| 369 | tmp &= 0xff0fffff; /* disable all banks */ |
| 370 | mtdcr (memcfga, mem_ecccf); |
| 371 | /* set up SDRAM Controller with ECC enabled */ |
| 372 | #ifdef SDRAM_DEBUG |
| 373 | serial_puts ("setup SDRAM Controller.. "); |
| 374 | #endif |
| 375 | mtdcr (memcfgd, tmp); |
| 376 | mtdcr (memcfga, mem_mcopt1); |
| 377 | tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000; |
| 378 | mtdcr (memcfga, mem_mcopt1); |
| 379 | mtdcr (memcfgd, tmp); |
| 380 | udelay (600); |
| 381 | #ifdef SDRAM_DEBUG |
| 382 | serial_puts ("fill the memory..\n"); |
| 383 | #endif |
| 384 | serial_puts ("."); |
| 385 | /* now, fill all the memory */ |
| 386 | tmp = ((4 * MEGA_BYTE) << sdram_table[i].sz); |
| 387 | p = (unsigned long) 0; |
| 388 | while ((unsigned long) p < tmp) { |
| 389 | *p++ = 0L; |
| 390 | if (!((unsigned long) p % 0x00800000)) /* every 8MByte */ |
| 391 | serial_puts ("."); |
| 392 | |
| 393 | |
| 394 | } |
| 395 | /* enable bank 0 */ |
| 396 | serial_puts ("."); |
| 397 | #ifdef SDRAM_DEBUG |
| 398 | serial_puts ("enable ECC\n"); |
| 399 | #endif |
| 400 | udelay (400); |
| 401 | mtdcr (memcfga, mem_ecccf); |
| 402 | tmp = mfdcr (memcfgd); |
| 403 | tmp |= 0x00800000; /* enable bank 0 */ |
| 404 | mtdcr (memcfgd, tmp); |
| 405 | udelay (400); |
| 406 | } else |
| 407 | #endif |
| 408 | { |
| 409 | /* enable SDRAM controller with no ECC, 32-bit SDRAM width, 16 byte burst */ |
| 410 | mtdcr (memcfga, mem_mcopt1); |
| 411 | tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x80C00000; |
| 412 | mtdcr (memcfga, mem_mcopt1); |
| 413 | mtdcr (memcfgd, tmp); |
| 414 | udelay (400); |
| 415 | } |
| 416 | serial_puts ("\n"); |
| 417 | return (0); |
| 418 | } |
| 419 | |
| 420 | int board_pre_init (void) |
| 421 | { |
| 422 | init_sdram (); |
| 423 | |
| 424 | /*-------------------------------------------------------------------------+ |
| 425 | | Interrupt controller setup for the PIP405 board. |
| 426 | | Note: IRQ 0-15 405GP internally generated; active high; level sensitive |
| 427 | | IRQ 16 405GP internally generated; active low; level sensitive |
| 428 | | IRQ 17-24 RESERVED |
| 429 | | IRQ 25 (EXT IRQ 0) SouthBridge; active low; level sensitive |
| 430 | | IRQ 26 (EXT IRQ 1) NMI: active low; level sensitive |
| 431 | | IRQ 27 (EXT IRQ 2) SMI: active Low; level sensitive |
| 432 | | IRQ 28 (EXT IRQ 3) PCI SLOT 3; active low; level sensitive |
| 433 | | IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 434 | | IRQ 30 (EXT IRQ 5) PCI SLOT 1; active low; level sensitive |
| 435 | | IRQ 31 (EXT IRQ 6) PCI SLOT 0; active low; level sensitive |
| 436 | | Note for MIP405 board: |
| 437 | | An interrupt taken for the SouthBridge (IRQ 25) indicates that |
| 438 | | the Interrupt Controller in the South Bridge has caused the |
| 439 | | interrupt. The IC must be read to determine which device |
| 440 | | caused the interrupt. |
| 441 | | |
| 442 | +-------------------------------------------------------------------------*/ |
| 443 | mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 444 | mtdcr (uicer, 0x00000000); /* disable all ints */ |
| 445 | mtdcr (uiccr, 0x00000000); /* set all to be non-critical (for now) */ |
| 446 | mtdcr (uicpr, 0xFFFFFF80); /* set int polarities */ |
| 447 | mtdcr (uictr, 0x10000000); /* set int trigger levels */ |
| 448 | mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */ |
| 449 | mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /* |
| 455 | * Get some PLD Registers |
| 456 | */ |
| 457 | |
| 458 | unsigned short get_pld_parvers (void) |
| 459 | { |
| 460 | unsigned short result; |
| 461 | unsigned char rc; |
| 462 | |
| 463 | rc = in8 (PLD_PART_REG); |
| 464 | result = (unsigned short) rc << 8; |
| 465 | rc = in8 (PLD_VERS_REG); |
| 466 | result |= rc; |
| 467 | return result; |
| 468 | } |
| 469 | |
| 470 | |
| 471 | |
| 472 | void user_led0 (unsigned char on) |
| 473 | { |
| 474 | if (on) |
| 475 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x4)); |
| 476 | else |
| 477 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfb)); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | void ide_set_reset (int idereset) |
| 482 | { |
| 483 | /* if reset = 1 IDE reset will be asserted */ |
| 484 | if (idereset) |
| 485 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x1)); |
| 486 | else { |
| 487 | udelay (10000); |
| 488 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfe)); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | |
| 493 | /* ------------------------------------------------------------------------- */ |
| 494 | |
| 495 | /* |
| 496 | * Check Board Identity: |
| 497 | */ |
| 498 | |
| 499 | int checkboard (void) |
| 500 | { |
| 501 | unsigned char s[50]; |
| 502 | unsigned char bc, var, rc; |
| 503 | int i; |
| 504 | backup_t *b = (backup_t *) s; |
| 505 | |
| 506 | puts ("Board: "); |
| 507 | |
| 508 | bc = get_board_revcfg (); |
| 509 | var = ~bc; |
| 510 | var &= 0xf; |
| 511 | rc = 0; |
| 512 | for (i = 0; i < 4; i++) { |
| 513 | rc <<= 1; |
| 514 | rc += (var & 0x1); |
| 515 | var >>= 1; |
| 516 | } |
| 517 | rc++; |
| 518 | i = getenv_r ("serial#", s, 32); |
| 519 | if ((i == 0) || strncmp (s, "MIP405", 6)) { |
| 520 | get_backup_values (b); |
| 521 | if (strncmp (b->signature, "MPL\0", 4) != 0) { |
| 522 | puts ("### No HW ID - assuming MIP405"); |
| 523 | printf ("-%d Rev %c", rc, 'A' + ((bc >> 4) & 0xf)); |
| 524 | } else { |
| 525 | b->serial_name[6] = 0; |
| 526 | printf ("%s-%d Rev %c SN: %s", b->serial_name, rc, |
| 527 | 'A' + ((bc >> 4) & 0xf), &b->serial_name[7]); |
| 528 | } |
| 529 | } else { |
| 530 | s[6] = 0; |
| 531 | printf ("%s-%d Rev %c SN: %s", s, rc, 'A' + ((bc >> 4) & 0xf), |
| 532 | &s[7]); |
| 533 | } |
| 534 | bc = in8 (PLD_EXT_CONF_REG); |
| 535 | printf (" Boot Config: 0x%x\n", bc); |
| 536 | return (0); |
| 537 | } |
| 538 | |
| 539 | |
| 540 | /* ------------------------------------------------------------------------- */ |
| 541 | /* ------------------------------------------------------------------------- */ |
| 542 | /* |
| 543 | initdram(int board_type) reads EEPROM via I2c. EEPROM contains all of |
| 544 | the necessary info for SDRAM controller configuration |
| 545 | */ |
| 546 | /* ------------------------------------------------------------------------- */ |
| 547 | /* ------------------------------------------------------------------------- */ |
| 548 | static int test_dram (unsigned long ramsize); |
| 549 | |
| 550 | long int initdram (int board_type) |
| 551 | { |
| 552 | |
| 553 | unsigned long bank_reg[4], tmp, bank_size; |
| 554 | int i, ds; |
| 555 | unsigned long TotalSize; |
| 556 | |
| 557 | ds = 0; |
| 558 | /* since the DRAM controller is allready set up, calculate the size with the |
| 559 | bank registers */ |
| 560 | mtdcr (memcfga, mem_mb0cf); |
| 561 | bank_reg[0] = mfdcr (memcfgd); |
| 562 | mtdcr (memcfga, mem_mb1cf); |
| 563 | bank_reg[1] = mfdcr (memcfgd); |
| 564 | mtdcr (memcfga, mem_mb2cf); |
| 565 | bank_reg[2] = mfdcr (memcfgd); |
| 566 | mtdcr (memcfga, mem_mb3cf); |
| 567 | bank_reg[3] = mfdcr (memcfgd); |
| 568 | TotalSize = 0; |
| 569 | for (i = 0; i < 4; i++) { |
| 570 | if ((bank_reg[i] & 0x1) == 0x1) { |
| 571 | tmp = (bank_reg[i] >> 17) & 0x7; |
| 572 | bank_size = 4 << tmp; |
| 573 | TotalSize += bank_size; |
| 574 | } else |
| 575 | ds = 1; |
| 576 | } |
| 577 | mtdcr (memcfga, mem_ecccf); |
| 578 | tmp = mfdcr (memcfgd); |
| 579 | |
| 580 | if (!tmp) |
| 581 | printf ("No "); |
| 582 | printf ("ECC "); |
| 583 | |
| 584 | test_dram (TotalSize * MEGA_BYTE); |
| 585 | return (TotalSize * MEGA_BYTE); |
| 586 | } |
| 587 | |
| 588 | /* ------------------------------------------------------------------------- */ |
| 589 | |
| 590 | extern int mem_test (unsigned long start, unsigned long ramsize, |
| 591 | int quiet); |
| 592 | |
| 593 | static int test_dram (unsigned long ramsize) |
| 594 | { |
| 595 | #ifdef SDRAM_DEBUG |
| 596 | mem_test (0L, ramsize, 1); |
| 597 | #endif |
| 598 | /* not yet implemented */ |
| 599 | return (1); |
| 600 | } |
| 601 | |
| 602 | int misc_init_r (void) |
| 603 | { |
| 604 | return (0); |
| 605 | } |
| 606 | |
| 607 | |
| 608 | void print_mip405_rev (void) |
| 609 | { |
| 610 | unsigned char part, vers, cfg, rev; |
| 611 | |
| 612 | cfg = get_board_revcfg (); |
| 613 | vers = cfg; |
| 614 | vers &= 0xf; |
| 615 | rev = (((vers & 0x1) ? 0x8 : 0) | |
| 616 | ((vers & 0x2) ? 0x4 : 0) | |
| 617 | ((vers & 0x4) ? 0x2 : 0) | ((vers & 0x8) ? 0x1 : 0)); |
| 618 | |
| 619 | part = in8 (PLD_PART_REG); |
| 620 | vers = in8 (PLD_VERS_REG); |
| 621 | printf ("Rev: MIP405-%d Rev %c PLD%d Vers %d\n", |
| 622 | (16 - rev), ((cfg >> 4) & 0xf) + 'A', part, vers); |
| 623 | } |
| 624 | |
| 625 | |
| 626 | int last_stage_init (void) |
| 627 | { |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 628 | /* write correct LED configuration */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 629 | if (miiphy_write (0x1, 0x14, 0x2402) != 0) { |
| 630 | printf ("Error writing to the PHY\n"); |
| 631 | } |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 632 | /* since LED/CFG2 is not connected on the -2, |
| 633 | * write to correct capability information */ |
| 634 | if (miiphy_write (0x1, 0x4, 0x01E1) != 0) { |
| 635 | printf ("Error writing to the PHY\n"); |
| 636 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 637 | print_mip405_rev (); |
| 638 | show_stdio_dev (); |
| 639 | check_env (); |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | /*************************************************************************** |
| 644 | * some helping routines |
| 645 | */ |
| 646 | |
| 647 | int overwrite_console (void) |
| 648 | { |
| 649 | return ((in8 (PLD_EXT_CONF_REG) & 0x1)==0); /* return TRUE if console should be overwritten */ |
| 650 | } |
| 651 | |
| 652 | |
| 653 | /************************************************************************ |
| 654 | * Print MIP405 Info |
| 655 | ************************************************************************/ |
| 656 | void print_mip405_info (void) |
| 657 | { |
| 658 | unsigned char part, vers, cfg, irq_reg, com_mode, ext; |
| 659 | |
| 660 | part = in8 (PLD_PART_REG); |
| 661 | vers = in8 (PLD_VERS_REG); |
| 662 | cfg = in8 (PLD_BOARD_CFG_REG); |
| 663 | irq_reg = in8 (PLD_IRQ_REG); |
| 664 | com_mode = in8 (PLD_COM_MODE_REG); |
| 665 | ext = in8 (PLD_EXT_CONF_REG); |
| 666 | |
| 667 | printf ("PLD Part %d version %d\n", part, vers); |
| 668 | printf ("Board Revision %c\n", ((cfg >> 4) & 0xf) + 'A'); |
| 669 | printf ("Population Options %d %d %d %d\n", (cfg) & 0x1, |
| 670 | (cfg >> 1) & 0x1, (cfg >> 2) & 0x1, (cfg >> 3) & 0x1); |
| 671 | printf ("User LED %s\n", (com_mode & 0x4) ? "on" : "off"); |
| 672 | printf ("UART Clocks %d\n", (com_mode >> 4) & 0x3); |
| 673 | printf ("Test ist %x\n", com_mode); |
| 674 | printf ("User Config Switch %d %d %d %d %d %d %d %d\n", |
| 675 | (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1, |
| 676 | (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1, |
| 677 | (ext >> 6) & 0x1, (ext >> 7) & 0x1); |
| 678 | printf ("SER1 uses handshakes %s\n", |
| 679 | (ext & 0x80) ? "DTR/DSR" : "RTS/CTS"); |
| 680 | printf ("IDE Reset %s\n", (ext & 0x01) ? "asserted" : "not asserted"); |
| 681 | printf ("IRQs:\n"); |
| 682 | printf (" PIIX INTR: %s\n", (irq_reg & 0x80) ? "inactive" : "active"); |
| 683 | printf (" UART0 IRQ: %s\n", (irq_reg & 0x40) ? "inactive" : "active"); |
| 684 | printf (" UART1 IRQ: %s\n", (irq_reg & 0x20) ? "inactive" : "active"); |
| 685 | printf (" PIIX SMI: %s\n", (irq_reg & 0x10) ? "inactive" : "active"); |
| 686 | printf (" PIIX INIT: %s\n", (irq_reg & 0x8) ? "inactive" : "active"); |
| 687 | printf (" PIIX NMI: %s\n", (irq_reg & 0x4) ? "inactive" : "active"); |
| 688 | } |
| 689 | |
| 690 | |