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> |
Stefan Roese | afabb49 | 2010-09-12 06:21:37 +0200 | [diff] [blame] | 68 | #include <asm/ppc4xx.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 69 | #include <asm/ppc4xx-i2c.h> |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 70 | #include <miiphy.h> |
| 71 | #include "../common/common_util.h" |
Jean-Christophe PLAGNIOL-VILLARD | 28c3450 | 2009-05-16 12:14:56 +0200 | [diff] [blame] | 72 | #include <stdio_dev.h> |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 73 | #include <i2c.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 74 | #include <rtc.h> |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 75 | |
| 76 | DECLARE_GLOBAL_DATA_PTR; |
| 77 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 78 | #undef SDRAM_DEBUG |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 79 | #define ENABLE_ECC /* for ecc boards */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 80 | #define FALSE 0 |
| 81 | #define TRUE 1 |
| 82 | |
| 83 | /* stdlib.h causes some compatibility problems; should fixe these! -- wd */ |
| 84 | #ifndef __ldiv_t_defined |
| 85 | typedef struct { |
| 86 | long int quot; /* Quotient */ |
| 87 | long int rem; /* Remainder */ |
| 88 | } ldiv_t; |
| 89 | extern ldiv_t ldiv (long int __numer, long int __denom); |
| 90 | # define __ldiv_t_defined 1 |
| 91 | #endif |
| 92 | |
| 93 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 94 | #define PLD_PART_REG PER_PLD_ADDR + 0 |
| 95 | #define PLD_VERS_REG PER_PLD_ADDR + 1 |
| 96 | #define PLD_BOARD_CFG_REG PER_PLD_ADDR + 2 |
| 97 | #define PLD_IRQ_REG PER_PLD_ADDR + 3 |
| 98 | #define PLD_COM_MODE_REG PER_PLD_ADDR + 4 |
| 99 | #define PLD_EXT_CONF_REG PER_PLD_ADDR + 5 |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 100 | |
| 101 | #define MEGA_BYTE (1024*1024) |
| 102 | |
| 103 | typedef struct { |
| 104 | unsigned char boardtype; /* Board revision and Population Options */ |
| 105 | unsigned char cal; /* cas Latency (will be programmend as cal-1) */ |
| 106 | unsigned char trp; /* datain27 in clocks */ |
| 107 | unsigned char trcd; /* datain29 in clocks */ |
| 108 | unsigned char tras; /* datain30 in clocks */ |
| 109 | unsigned char tctp; /* tras - trcd in clocks */ |
| 110 | unsigned char am; /* Address Mod (will be programmed as am-1) */ |
| 111 | unsigned char sz; /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */ |
| 112 | unsigned char ecc; /* if true, ecc is enabled */ |
| 113 | } sdram_t; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 114 | #if defined(CONFIG_MIP405T) |
| 115 | const sdram_t sdram_table[] = { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 116 | { 0x0F, /* MIP405T Rev A, 64MByte -1 Board */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 117 | 3, /* Case Latenty = 3 */ |
| 118 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 119 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 120 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 121 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 122 | 2, /* Address Mode = 2 (12x9x4) */ |
| 123 | 3, /* size value (32MByte) */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 124 | 0}, /* ECC disabled */ |
| 125 | { 0xff, /* terminator */ |
| 126 | 0xff, |
| 127 | 0xff, |
| 128 | 0xff, |
| 129 | 0xff, |
| 130 | 0xff, |
| 131 | 0xff, |
| 132 | 0xff } |
| 133 | }; |
| 134 | #else |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 135 | const sdram_t sdram_table[] = { |
| 136 | { 0x0f, /* Rev A, 128MByte -1 Board */ |
| 137 | 3, /* Case Latenty = 3 */ |
| 138 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 139 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 140 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 141 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 142 | 3, /* Address Mode = 3 */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 143 | 5, /* size value */ |
| 144 | 1}, /* ECC enabled */ |
| 145 | { 0x07, /* Rev A, 64MByte -2 Board */ |
| 146 | 3, /* Case Latenty = 3 */ |
| 147 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 148 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 149 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 150 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 151 | 2, /* Address Mode = 2 */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 152 | 4, /* size value */ |
| 153 | 1}, /* ECC enabled */ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 154 | { 0x03, /* Rev A, 128MByte -4 Board */ |
| 155 | 3, /* Case Latenty = 3 */ |
| 156 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 157 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 158 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 159 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 160 | 3, /* Address Mode = 3 */ |
| 161 | 5, /* size value */ |
| 162 | 1}, /* ECC enabled */ |
| 163 | { 0x1f, /* Rev B, 128MByte -3 Board */ |
| 164 | 3, /* Case Latenty = 3 */ |
| 165 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 166 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 167 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 168 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 169 | 3, /* Address Mode = 3 */ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 170 | 5, /* size value */ |
| 171 | 1}, /* ECC enabled */ |
wdenk | 4a55170 | 2003-10-08 23:26:14 +0000 | [diff] [blame] | 172 | { 0x2f, /* Rev C, 128MByte -3 Board */ |
| 173 | 3, /* Case Latenty = 3 */ |
| 174 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 175 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 176 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 177 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 178 | 3, /* Address Mode = 3 */ |
| 179 | 5, /* size value */ |
| 180 | 1}, /* ECC enabled */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 181 | { 0xff, /* terminator */ |
| 182 | 0xff, |
| 183 | 0xff, |
| 184 | 0xff, |
| 185 | 0xff, |
| 186 | 0xff, |
| 187 | 0xff, |
| 188 | 0xff } |
| 189 | }; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 190 | #endif /*CONFIG_MIP405T */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 191 | void SDRAM_err (const char *s) |
| 192 | { |
| 193 | #ifndef SDRAM_DEBUG |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 194 | (void) get_clocks (); |
| 195 | gd->baudrate = 9600; |
| 196 | serial_init (); |
| 197 | #endif |
| 198 | serial_puts ("\n"); |
| 199 | serial_puts (s); |
| 200 | serial_puts ("\n enable SDRAM_DEBUG for more info\n"); |
| 201 | for (;;); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | unsigned char get_board_revcfg (void) |
| 206 | { |
| 207 | out8 (PER_BOARD_ADDR, 0); |
| 208 | return (in8 (PER_BOARD_ADDR)); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | #ifdef SDRAM_DEBUG |
| 213 | |
| 214 | void write_hex (unsigned char i) |
| 215 | { |
| 216 | char cc; |
| 217 | |
| 218 | cc = i >> 4; |
| 219 | cc &= 0xf; |
| 220 | if (cc > 9) |
| 221 | serial_putc (cc + 55); |
| 222 | else |
| 223 | serial_putc (cc + 48); |
| 224 | cc = i & 0xf; |
| 225 | if (cc > 9) |
| 226 | serial_putc (cc + 55); |
| 227 | else |
| 228 | serial_putc (cc + 48); |
| 229 | } |
| 230 | |
| 231 | void write_4hex (unsigned long val) |
| 232 | { |
| 233 | write_hex ((unsigned char) (val >> 24)); |
| 234 | write_hex ((unsigned char) (val >> 16)); |
| 235 | write_hex ((unsigned char) (val >> 8)); |
| 236 | write_hex ((unsigned char) val); |
| 237 | } |
| 238 | |
| 239 | #endif |
| 240 | |
| 241 | |
| 242 | int init_sdram (void) |
| 243 | { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 244 | unsigned long tmp, baseaddr; |
| 245 | unsigned short i; |
| 246 | unsigned char trp_clocks, |
| 247 | trcd_clocks, |
| 248 | tras_clocks, |
| 249 | trc_clocks, |
| 250 | tctp_clocks; |
| 251 | unsigned char cal_val; |
| 252 | unsigned char bc; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 253 | unsigned long sdram_tim, sdram_bank; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 254 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 255 | /*i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);*/ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 256 | (void) get_clocks (); |
| 257 | gd->baudrate = 9600; |
| 258 | serial_init (); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 259 | /* set up the pld */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 260 | mtdcr (EBC0_CFGADDR, PB7AP); |
| 261 | mtdcr (EBC0_CFGDATA, PLD_AP); |
| 262 | mtdcr (EBC0_CFGADDR, PB7CR); |
| 263 | mtdcr (EBC0_CFGDATA, PLD_CR); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 264 | /* THIS IS OBSOLETE */ |
| 265 | /* set up the board rev reg*/ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 266 | mtdcr (EBC0_CFGADDR, PB5AP); |
| 267 | mtdcr (EBC0_CFGDATA, BOARD_AP); |
| 268 | mtdcr (EBC0_CFGADDR, PB5CR); |
| 269 | mtdcr (EBC0_CFGDATA, BOARD_CR); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 270 | #ifdef SDRAM_DEBUG |
| 271 | /* get all informations from PLD */ |
| 272 | serial_puts ("\nPLD Part 0x"); |
| 273 | bc = in8 (PLD_PART_REG); |
| 274 | write_hex (bc); |
| 275 | serial_puts ("\nPLD Vers 0x"); |
| 276 | bc = in8 (PLD_VERS_REG); |
| 277 | write_hex (bc); |
| 278 | serial_puts ("\nBoard Rev 0x"); |
| 279 | bc = in8 (PLD_BOARD_CFG_REG); |
| 280 | write_hex (bc); |
| 281 | serial_puts ("\n"); |
| 282 | #endif |
| 283 | /* check board */ |
| 284 | bc = in8 (PLD_PART_REG); |
| 285 | #if defined(CONFIG_MIP405T) |
| 286 | if((bc & 0x80)==0) |
| 287 | SDRAM_err ("U-Boot configured for a MIP405T not for a MIP405!!!\n"); |
| 288 | #else |
| 289 | if((bc & 0x80)==0x80) |
| 290 | SDRAM_err ("U-Boot configured for a MIP405 not for a MIP405T!!!\n"); |
| 291 | #endif |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 292 | /* set-up the chipselect machine */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 293 | mtdcr (EBC0_CFGADDR, PB0CR); /* get cs0 config reg */ |
| 294 | tmp = mfdcr (EBC0_CFGDATA); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 295 | if ((tmp & 0x00002000) == 0) { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 296 | /* MPS Boot, set up the flash */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 297 | mtdcr (EBC0_CFGADDR, PB1AP); |
| 298 | mtdcr (EBC0_CFGDATA, FLASH_AP); |
| 299 | mtdcr (EBC0_CFGADDR, PB1CR); |
| 300 | mtdcr (EBC0_CFGDATA, FLASH_CR); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 301 | } else { |
| 302 | /* Flash boot, set up the MPS */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 303 | mtdcr (EBC0_CFGADDR, PB1AP); |
| 304 | mtdcr (EBC0_CFGDATA, MPS_AP); |
| 305 | mtdcr (EBC0_CFGADDR, PB1CR); |
| 306 | mtdcr (EBC0_CFGDATA, MPS_CR); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 307 | } |
| 308 | /* set up UART0 (CS2) and UART1 (CS3) */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 309 | mtdcr (EBC0_CFGADDR, PB2AP); |
| 310 | mtdcr (EBC0_CFGDATA, UART0_AP); |
| 311 | mtdcr (EBC0_CFGADDR, PB2CR); |
| 312 | mtdcr (EBC0_CFGDATA, UART0_CR); |
| 313 | mtdcr (EBC0_CFGADDR, PB3AP); |
| 314 | mtdcr (EBC0_CFGDATA, UART1_AP); |
| 315 | mtdcr (EBC0_CFGADDR, PB3CR); |
| 316 | mtdcr (EBC0_CFGDATA, UART1_CR); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 317 | bc = in8 (PLD_BOARD_CFG_REG); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 318 | #ifdef SDRAM_DEBUG |
| 319 | serial_puts ("\nstart SDRAM Setup\n"); |
| 320 | serial_puts ("\nBoard Rev: "); |
| 321 | write_hex (bc); |
| 322 | serial_puts ("\n"); |
| 323 | #endif |
| 324 | i = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 325 | baseaddr = CONFIG_SYS_SDRAM_BASE; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 326 | while (sdram_table[i].sz != 0xff) { |
| 327 | if (sdram_table[i].boardtype == bc) |
| 328 | break; |
| 329 | i++; |
| 330 | } |
| 331 | if (sdram_table[i].boardtype != bc) |
| 332 | SDRAM_err ("No SDRAM table found for this board!!!\n"); |
| 333 | #ifdef SDRAM_DEBUG |
| 334 | serial_puts (" found table "); |
| 335 | write_hex (i); |
| 336 | serial_puts (" \n"); |
| 337 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 338 | /* since the ECC initialisation needs some time, |
| 339 | * we show that we're alive |
| 340 | */ |
| 341 | if (sdram_table[i].ecc) |
| 342 | serial_puts ("\nInitializing SDRAM, Please stand by"); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 343 | cal_val = sdram_table[i].cal - 1; /* Cas Latency */ |
| 344 | trp_clocks = sdram_table[i].trp; /* 20ns / 7.5 ns datain[27] */ |
| 345 | trcd_clocks = sdram_table[i].trcd; /* 20ns /7.5 ns (datain[29]) */ |
| 346 | tras_clocks = sdram_table[i].tras; /* 44ns /7.5 ns (datain[30]) */ |
| 347 | /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */ |
| 348 | tctp_clocks = sdram_table[i].tctp; /* 44 - 20ns = 24ns */ |
| 349 | /* trc_clocks is sum of trp_clocks + tras_clocks */ |
| 350 | trc_clocks = trp_clocks + tras_clocks; |
| 351 | /* get SDRAM timing register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 352 | mtdcr (SDRAM0_CFGADDR, SDRAM0_TR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 353 | sdram_tim = mfdcr (SDRAM0_CFGDATA) & ~0x018FC01F; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 354 | /* insert CASL value */ |
| 355 | sdram_tim |= ((unsigned long) (cal_val)) << 23; |
| 356 | /* insert PTA value */ |
| 357 | sdram_tim |= ((unsigned long) (trp_clocks - 1)) << 18; |
| 358 | /* insert CTP value */ |
| 359 | sdram_tim |= |
| 360 | ((unsigned long) (trc_clocks - trp_clocks - |
| 361 | trcd_clocks)) << 16; |
| 362 | /* insert LDF (always 01) */ |
| 363 | sdram_tim |= ((unsigned long) 0x01) << 14; |
| 364 | /* insert RFTA value */ |
| 365 | sdram_tim |= ((unsigned long) (trc_clocks - 4)) << 2; |
| 366 | /* insert RCD value */ |
| 367 | sdram_tim |= ((unsigned long) (trcd_clocks - 1)) << 0; |
| 368 | |
| 369 | tmp = ((unsigned long) (sdram_table[i].am - 1) << 13); /* AM = 3 */ |
| 370 | /* insert SZ value; */ |
| 371 | tmp |= ((unsigned long) sdram_table[i].sz << 17); |
| 372 | /* get SDRAM bank 0 register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 373 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 374 | sdram_bank = mfdcr (SDRAM0_CFGDATA) & ~0xFFCEE001; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 375 | sdram_bank |= (baseaddr | tmp | 0x01); |
| 376 | |
| 377 | #ifdef SDRAM_DEBUG |
| 378 | serial_puts ("sdtr: "); |
| 379 | write_4hex (sdram_tim); |
| 380 | serial_puts ("\n"); |
| 381 | #endif |
| 382 | |
| 383 | /* write SDRAM timing register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 384 | mtdcr (SDRAM0_CFGADDR, SDRAM0_TR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 385 | mtdcr (SDRAM0_CFGDATA, sdram_tim); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 386 | |
| 387 | #ifdef SDRAM_DEBUG |
| 388 | serial_puts ("mb0cf: "); |
| 389 | write_4hex (sdram_bank); |
| 390 | serial_puts ("\n"); |
| 391 | #endif |
| 392 | |
| 393 | /* write SDRAM bank 0 register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 394 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 395 | mtdcr (SDRAM0_CFGDATA, sdram_bank); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 396 | |
| 397 | if (get_bus_freq (tmp) > 110000000) { /* > 110MHz */ |
| 398 | /* get SDRAM refresh interval register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 399 | mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 400 | tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 401 | tmp |= 0x07F00000; |
| 402 | } else { |
| 403 | /* get SDRAM refresh interval register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 404 | mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 405 | tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 406 | tmp |= 0x05F00000; |
| 407 | } |
| 408 | /* write SDRAM refresh interval register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 409 | mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 410 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 411 | /* enable ECC if used */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 412 | #if defined(ENABLE_ECC) && !defined(CONFIG_BOOT_PCI) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 413 | if (sdram_table[i].ecc) { |
| 414 | /* disable checking for all banks */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 415 | unsigned long *p; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 416 | #ifdef SDRAM_DEBUG |
| 417 | serial_puts ("disable ECC.. "); |
| 418 | #endif |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 419 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 420 | tmp = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 421 | tmp &= 0xff0fffff; /* disable all banks */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 422 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 423 | /* set up SDRAM Controller with ECC enabled */ |
| 424 | #ifdef SDRAM_DEBUG |
| 425 | serial_puts ("setup SDRAM Controller.. "); |
| 426 | #endif |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 427 | mtdcr (SDRAM0_CFGDATA, tmp); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 428 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 429 | tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000; |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 430 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 431 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 432 | udelay (600); |
| 433 | #ifdef SDRAM_DEBUG |
| 434 | serial_puts ("fill the memory..\n"); |
| 435 | #endif |
| 436 | serial_puts ("."); |
| 437 | /* now, fill all the memory */ |
| 438 | tmp = ((4 * MEGA_BYTE) << sdram_table[i].sz); |
| 439 | p = (unsigned long) 0; |
| 440 | while ((unsigned long) p < tmp) { |
| 441 | *p++ = 0L; |
| 442 | if (!((unsigned long) p % 0x00800000)) /* every 8MByte */ |
| 443 | serial_puts ("."); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 444 | } |
| 445 | /* enable bank 0 */ |
| 446 | serial_puts ("."); |
| 447 | #ifdef SDRAM_DEBUG |
| 448 | serial_puts ("enable ECC\n"); |
| 449 | #endif |
| 450 | udelay (400); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 451 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 452 | tmp = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 453 | tmp |= 0x00800000; /* enable bank 0 */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 454 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 455 | udelay (400); |
| 456 | } else |
| 457 | #endif |
| 458 | { |
| 459 | /* enable SDRAM controller with no ECC, 32-bit SDRAM width, 16 byte burst */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 460 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 461 | tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x80C00000; |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 462 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 463 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 464 | udelay (400); |
| 465 | } |
| 466 | serial_puts ("\n"); |
| 467 | return (0); |
| 468 | } |
| 469 | |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 470 | int board_early_init_f (void) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 471 | { |
| 472 | init_sdram (); |
| 473 | |
| 474 | /*-------------------------------------------------------------------------+ |
| 475 | | Interrupt controller setup for the PIP405 board. |
| 476 | | Note: IRQ 0-15 405GP internally generated; active high; level sensitive |
| 477 | | IRQ 16 405GP internally generated; active low; level sensitive |
| 478 | | IRQ 17-24 RESERVED |
| 479 | | IRQ 25 (EXT IRQ 0) SouthBridge; active low; level sensitive |
| 480 | | IRQ 26 (EXT IRQ 1) NMI: active low; level sensitive |
| 481 | | IRQ 27 (EXT IRQ 2) SMI: active Low; level sensitive |
| 482 | | IRQ 28 (EXT IRQ 3) PCI SLOT 3; active low; level sensitive |
| 483 | | IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 484 | | IRQ 30 (EXT IRQ 5) PCI SLOT 1; active low; level sensitive |
| 485 | | IRQ 31 (EXT IRQ 6) PCI SLOT 0; active low; level sensitive |
| 486 | | Note for MIP405 board: |
| 487 | | An interrupt taken for the SouthBridge (IRQ 25) indicates that |
| 488 | | the Interrupt Controller in the South Bridge has caused the |
| 489 | | interrupt. The IC must be read to determine which device |
| 490 | | caused the interrupt. |
| 491 | | |
| 492 | +-------------------------------------------------------------------------*/ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 493 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 494 | mtdcr (UIC0ER, 0x00000000); /* disable all ints */ |
| 495 | mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical (for now) */ |
| 496 | mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */ |
| 497 | mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */ |
| 498 | mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */ |
| 499 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | /* |
| 505 | * Get some PLD Registers |
| 506 | */ |
| 507 | |
| 508 | unsigned short get_pld_parvers (void) |
| 509 | { |
| 510 | unsigned short result; |
| 511 | unsigned char rc; |
| 512 | |
| 513 | rc = in8 (PLD_PART_REG); |
| 514 | result = (unsigned short) rc << 8; |
| 515 | rc = in8 (PLD_VERS_REG); |
| 516 | result |= rc; |
| 517 | return result; |
| 518 | } |
| 519 | |
| 520 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 521 | void user_led0 (unsigned char on) |
| 522 | { |
| 523 | if (on) |
| 524 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x4)); |
| 525 | else |
| 526 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfb)); |
| 527 | } |
| 528 | |
| 529 | |
| 530 | void ide_set_reset (int idereset) |
| 531 | { |
| 532 | /* if reset = 1 IDE reset will be asserted */ |
| 533 | if (idereset) |
| 534 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x1)); |
| 535 | else { |
| 536 | udelay (10000); |
| 537 | out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfe)); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | |
| 542 | /* ------------------------------------------------------------------------- */ |
| 543 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 544 | void get_pcbrev_var(unsigned char *pcbrev, unsigned char *var) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 545 | { |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 546 | #if !defined(CONFIG_MIP405T) |
| 547 | unsigned char bc,rc,tmp; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 548 | int i; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 549 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 550 | bc = in8 (PLD_BOARD_CFG_REG); |
| 551 | tmp = ~bc; |
| 552 | tmp &= 0xf; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 553 | rc = 0; |
| 554 | for (i = 0; i < 4; i++) { |
| 555 | rc <<= 1; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 556 | rc += (tmp & 0x1); |
| 557 | tmp >>= 1; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 558 | } |
| 559 | rc++; |
wdenk | 4a55170 | 2003-10-08 23:26:14 +0000 | [diff] [blame] | 560 | if(( (((bc>>4) & 0xf)==0x2) /* Rev C PCB or */ |
| 561 | || (((bc>>4) & 0xf)==0x1)) /* Rev B PCB with */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 562 | && (rc==0x1)) /* Population Option 1 is a -3 */ |
| 563 | rc=3; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 564 | *pcbrev=(bc >> 4) & 0xf; |
| 565 | *var=rc; |
| 566 | #else |
| 567 | unsigned char bc; |
| 568 | bc = in8 (PLD_BOARD_CFG_REG); |
| 569 | *pcbrev=(bc >> 4) & 0xf; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 570 | *var=16-(bc & 0xf); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 571 | #endif |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Check Board Identity: |
| 576 | */ |
| 577 | /* serial String: "MIP405_1000" OR "MIP405T_1000" */ |
| 578 | #if !defined(CONFIG_MIP405T) |
| 579 | #define BOARD_NAME "MIP405" |
| 580 | #else |
| 581 | #define BOARD_NAME "MIP405T" |
| 582 | #endif |
| 583 | |
| 584 | int checkboard (void) |
| 585 | { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 586 | char s[50]; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 587 | unsigned char bc, var; |
| 588 | int i; |
| 589 | backup_t *b = (backup_t *) s; |
| 590 | |
| 591 | puts ("Board: "); |
| 592 | get_pcbrev_var(&bc,&var); |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 593 | i = getenv_f("serial#", (char *)s, 32); |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 594 | if ((i == 0) || strncmp ((char *)s, BOARD_NAME,sizeof(BOARD_NAME))) { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 595 | get_backup_values (b); |
| 596 | if (strncmp (b->signature, "MPL\0", 4) != 0) { |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 597 | puts ("### No HW ID - assuming " BOARD_NAME); |
| 598 | printf ("-%d Rev %c", var, 'A' + bc); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 599 | } else { |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 600 | b->serial_name[sizeof(BOARD_NAME)-1] = 0; |
| 601 | printf ("%s-%d Rev %c SN: %s", b->serial_name, var, |
| 602 | 'A' + bc, &b->serial_name[sizeof(BOARD_NAME)]); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 603 | } |
| 604 | } else { |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 605 | s[sizeof(BOARD_NAME)-1] = 0; |
| 606 | printf ("%s-%d Rev %c SN: %s", s, var,'A' + bc, |
| 607 | &s[sizeof(BOARD_NAME)]); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 608 | } |
| 609 | bc = in8 (PLD_EXT_CONF_REG); |
| 610 | printf (" Boot Config: 0x%x\n", bc); |
| 611 | return (0); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | /* ------------------------------------------------------------------------- */ |
| 616 | /* ------------------------------------------------------------------------- */ |
| 617 | /* |
| 618 | initdram(int board_type) reads EEPROM via I2c. EEPROM contains all of |
| 619 | the necessary info for SDRAM controller configuration |
| 620 | */ |
| 621 | /* ------------------------------------------------------------------------- */ |
| 622 | /* ------------------------------------------------------------------------- */ |
| 623 | static int test_dram (unsigned long ramsize); |
| 624 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 625 | phys_size_t initdram (int board_type) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 626 | { |
| 627 | |
| 628 | unsigned long bank_reg[4], tmp, bank_size; |
| 629 | int i, ds; |
| 630 | unsigned long TotalSize; |
| 631 | |
| 632 | ds = 0; |
| 633 | /* since the DRAM controller is allready set up, calculate the size with the |
| 634 | bank registers */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 635 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 636 | bank_reg[0] = mfdcr (SDRAM0_CFGDATA); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 637 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 638 | bank_reg[1] = mfdcr (SDRAM0_CFGDATA); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 639 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 640 | bank_reg[2] = mfdcr (SDRAM0_CFGDATA); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 641 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 642 | bank_reg[3] = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 643 | TotalSize = 0; |
| 644 | for (i = 0; i < 4; i++) { |
| 645 | if ((bank_reg[i] & 0x1) == 0x1) { |
| 646 | tmp = (bank_reg[i] >> 17) & 0x7; |
| 647 | bank_size = 4 << tmp; |
| 648 | TotalSize += bank_size; |
| 649 | } else |
| 650 | ds = 1; |
| 651 | } |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 652 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 653 | tmp = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 654 | |
| 655 | if (!tmp) |
| 656 | printf ("No "); |
| 657 | printf ("ECC "); |
| 658 | |
| 659 | test_dram (TotalSize * MEGA_BYTE); |
| 660 | return (TotalSize * MEGA_BYTE); |
| 661 | } |
| 662 | |
| 663 | /* ------------------------------------------------------------------------- */ |
| 664 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 665 | |
| 666 | static int test_dram (unsigned long ramsize) |
| 667 | { |
| 668 | #ifdef SDRAM_DEBUG |
| 669 | mem_test (0L, ramsize, 1); |
| 670 | #endif |
| 671 | /* not yet implemented */ |
| 672 | return (1); |
| 673 | } |
| 674 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 675 | /* used to check if the time in RTC is valid */ |
| 676 | static unsigned long start; |
| 677 | static struct rtc_time tm; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 678 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 679 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 680 | int misc_init_r (void) |
| 681 | { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 682 | /* adjust flash start and size as well as the offset */ |
| 683 | gd->bd->bi_flashstart=0-flash_info[0].size; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 684 | gd->bd->bi_flashsize=flash_info[0].size-CONFIG_SYS_MONITOR_LEN; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 685 | gd->bd->bi_flashoffset=0; |
| 686 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 687 | /* check, if RTC is running */ |
| 688 | rtc_get (&tm); |
| 689 | start=get_timer(0); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 690 | /* if MIP405 has booted from PCI, reset CCR0[24] as described in errata PCI_18 */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 691 | if (mfdcr(CPC0_PSR) & PSR_ROM_LOC) |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 692 | mtspr(SPRN_CCR0, (mfspr(SPRN_CCR0) & ~0x80)); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 693 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 694 | return (0); |
| 695 | } |
| 696 | |
| 697 | |
| 698 | void print_mip405_rev (void) |
| 699 | { |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 700 | unsigned char part, vers, pcbrev, var; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 701 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 702 | get_pcbrev_var(&pcbrev,&var); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 703 | part = in8 (PLD_PART_REG); |
| 704 | vers = in8 (PLD_VERS_REG); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 705 | printf ("Rev: " BOARD_NAME "-%d Rev %c PLD %d Vers %d\n", |
| 706 | var, pcbrev + 'A', part & 0x7F, vers); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 707 | } |
| 708 | |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 709 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 710 | extern int mk_date (char *, struct rtc_time *); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 711 | |
| 712 | int last_stage_init (void) |
| 713 | { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 714 | unsigned long stop; |
| 715 | struct rtc_time newtm; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 716 | char *s; |
Peter Tyser | 331ab60 | 2009-09-21 11:20:33 -0500 | [diff] [blame] | 717 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 718 | /* write correct LED configuration */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 719 | if (miiphy_write("ppc_4xx_eth0", 0x1, 0x14, 0x2402) != 0) { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 720 | printf ("Error writing to the PHY\n"); |
| 721 | } |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 722 | /* since LED/CFG2 is not connected on the -2, |
| 723 | * write to correct capability information */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 724 | if (miiphy_write("ppc_4xx_eth0", 0x1, 0x4, 0x01E1) != 0) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 725 | printf ("Error writing to the PHY\n"); |
| 726 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 727 | print_mip405_rev (); |
Jean-Christophe PLAGNIOL-VILLARD | 28c3450 | 2009-05-16 12:14:56 +0200 | [diff] [blame] | 728 | stdio_print_current_devices (); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 729 | check_env (); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 730 | /* check if RTC time is valid */ |
| 731 | stop=get_timer(start); |
| 732 | while(stop<1200) { /* we wait 1.2 sec to check if the RTC is running */ |
| 733 | udelay(1000); |
| 734 | stop=get_timer(start); |
| 735 | } |
| 736 | rtc_get (&newtm); |
| 737 | if(tm.tm_sec==newtm.tm_sec) { |
| 738 | s=getenv("defaultdate"); |
| 739 | if(!s) |
| 740 | mk_date ("010112001970", &newtm); |
| 741 | else |
| 742 | if(mk_date (s, &newtm)!=0) { |
| 743 | printf("RTC: Bad date format in defaultdate\n"); |
| 744 | return 0; |
| 745 | } |
| 746 | rtc_reset (); |
| 747 | rtc_set(&newtm); |
| 748 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | |
| 752 | /*************************************************************************** |
| 753 | * some helping routines |
| 754 | */ |
| 755 | |
| 756 | int overwrite_console (void) |
| 757 | { |
| 758 | return ((in8 (PLD_EXT_CONF_REG) & 0x1)==0); /* return TRUE if console should be overwritten */ |
| 759 | } |
| 760 | |
| 761 | |
| 762 | /************************************************************************ |
| 763 | * Print MIP405 Info |
| 764 | ************************************************************************/ |
| 765 | void print_mip405_info (void) |
| 766 | { |
| 767 | unsigned char part, vers, cfg, irq_reg, com_mode, ext; |
| 768 | |
| 769 | part = in8 (PLD_PART_REG); |
| 770 | vers = in8 (PLD_VERS_REG); |
| 771 | cfg = in8 (PLD_BOARD_CFG_REG); |
| 772 | irq_reg = in8 (PLD_IRQ_REG); |
| 773 | com_mode = in8 (PLD_COM_MODE_REG); |
| 774 | ext = in8 (PLD_EXT_CONF_REG); |
| 775 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 776 | printf ("PLD Part %d version %d\n", part & 0x7F, vers); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 777 | printf ("Board Revision %c\n", ((cfg >> 4) & 0xf) + 'A'); |
| 778 | printf ("Population Options %d %d %d %d\n", (cfg) & 0x1, |
| 779 | (cfg >> 1) & 0x1, (cfg >> 2) & 0x1, (cfg >> 3) & 0x1); |
| 780 | printf ("User LED %s\n", (com_mode & 0x4) ? "on" : "off"); |
| 781 | printf ("UART Clocks %d\n", (com_mode >> 4) & 0x3); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 782 | #if !defined(CONFIG_MIP405T) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 783 | printf ("User Config Switch %d %d %d %d %d %d %d %d\n", |
| 784 | (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1, |
| 785 | (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1, |
| 786 | (ext >> 6) & 0x1, (ext >> 7) & 0x1); |
| 787 | printf ("SER1 uses handshakes %s\n", |
| 788 | (ext & 0x80) ? "DTR/DSR" : "RTS/CTS"); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 789 | #else |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 790 | printf ("User Config Switch %d %d %d %d %d %d %d %d\n", |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 791 | (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1, |
| 792 | (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1, |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 793 | (ext >> 6) & 0x1,(ext >> 7) & 0x1); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 794 | #endif |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 795 | printf ("IDE Reset %s\n", (ext & 0x01) ? "asserted" : "not asserted"); |
| 796 | printf ("IRQs:\n"); |
| 797 | printf (" PIIX INTR: %s\n", (irq_reg & 0x80) ? "inactive" : "active"); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 798 | #if !defined(CONFIG_MIP405T) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 799 | printf (" UART0 IRQ: %s\n", (irq_reg & 0x40) ? "inactive" : "active"); |
| 800 | printf (" UART1 IRQ: %s\n", (irq_reg & 0x20) ? "inactive" : "active"); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 801 | #endif |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 802 | printf (" PIIX SMI: %s\n", (irq_reg & 0x10) ? "inactive" : "active"); |
| 803 | printf (" PIIX INIT: %s\n", (irq_reg & 0x8) ? "inactive" : "active"); |
| 804 | printf (" PIIX NMI: %s\n", (irq_reg & 0x4) ? "inactive" : "active"); |
| 805 | } |