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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 6 | * |
| 7 | * TODO: clean-up |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * How do I program the SDRAM Timing Register (SDRAM0_TR) for a specific SDRAM or DIMM? |
| 12 | * |
| 13 | * As an example, consider a case where PC133 memory with CAS Latency equal to 2 is being |
| 14 | * used with a 200MHz 405GP. For a typical 128Mb, PC133 SDRAM, the relevant minimum |
| 15 | * parameters from the datasheet are: |
| 16 | * Tclk = 7.5ns (CL = 2) |
| 17 | * Trp = 15ns |
| 18 | * Trc = 60ns |
| 19 | * Trcd = 15ns |
| 20 | * Trfc = 66ns |
| 21 | * |
| 22 | * If we are operating the 405GP with the MemClk output frequency set to 100 MHZ, the clock |
| 23 | * period is 10ns and the parameters needed for the Timing Register are: |
| 24 | * CASL = CL = 2 clock cycles |
| 25 | * PTA = Trp = 15ns / 10ns = 2 clock cycles |
| 26 | * CTP = Trc - Trcd - Trp = (60ns - 15ns - 15ns) / 10ns= 3 clock cycles |
| 27 | * LDF = 2 clock cycles (but can be extended to meet board-level timing) |
| 28 | * RFTA = Trfc = 66ns / 10ns= 7 clock cycles |
| 29 | * RCD = Trcd = 15ns / 10ns= 2 clock cycles |
| 30 | * |
| 31 | * The actual bit settings in the register would be: |
| 32 | * |
| 33 | * CASL = 0b01 |
| 34 | * PTA = 0b01 |
| 35 | * CTP = 0b10 |
| 36 | * LDF = 0b01 |
| 37 | * RFTA = 0b011 |
| 38 | * RCD = 0b01 |
| 39 | * |
| 40 | * If Trfc is not specified in the datasheet for PC100 or PC133 memory, set RFTA = Trc |
| 41 | * instead. Figure 24 in the PC SDRAM Specification Rev. 1.7 shows refresh to active delay |
| 42 | * defined as Trc rather than Trfc. |
| 43 | * When using DIMM modules, most but not all of the required timing parameters can be read |
| 44 | * from the Serial Presence Detect (SPD) EEPROM on the module. Specifically, Trc and Trfc |
| 45 | * are not available from the EEPROM |
| 46 | */ |
| 47 | |
| 48 | #include <common.h> |
| 49 | #include "mip405.h" |
| 50 | #include <asm/processor.h> |
Stefan Roese | afabb49 | 2010-09-12 06:21:37 +0200 | [diff] [blame] | 51 | #include <asm/ppc4xx.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 52 | #include <asm/ppc4xx-i2c.h> |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 53 | #include <miiphy.h> |
| 54 | #include "../common/common_util.h" |
Jean-Christophe PLAGNIOL-VILLARD | 28c3450 | 2009-05-16 12:14:56 +0200 | [diff] [blame] | 55 | #include <stdio_dev.h> |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 56 | #include <i2c.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 57 | #include <rtc.h> |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 58 | |
| 59 | DECLARE_GLOBAL_DATA_PTR; |
| 60 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 61 | #undef SDRAM_DEBUG |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 62 | #define ENABLE_ECC /* for ecc boards */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 63 | |
| 64 | /* stdlib.h causes some compatibility problems; should fixe these! -- wd */ |
| 65 | #ifndef __ldiv_t_defined |
| 66 | typedef struct { |
| 67 | long int quot; /* Quotient */ |
| 68 | long int rem; /* Remainder */ |
| 69 | } ldiv_t; |
| 70 | extern ldiv_t ldiv (long int __numer, long int __denom); |
| 71 | # define __ldiv_t_defined 1 |
| 72 | #endif |
| 73 | |
| 74 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 75 | #define PLD_PART_REG PER_PLD_ADDR + 0 |
| 76 | #define PLD_VERS_REG PER_PLD_ADDR + 1 |
| 77 | #define PLD_BOARD_CFG_REG PER_PLD_ADDR + 2 |
| 78 | #define PLD_IRQ_REG PER_PLD_ADDR + 3 |
| 79 | #define PLD_COM_MODE_REG PER_PLD_ADDR + 4 |
| 80 | #define PLD_EXT_CONF_REG PER_PLD_ADDR + 5 |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 81 | |
| 82 | #define MEGA_BYTE (1024*1024) |
| 83 | |
| 84 | typedef struct { |
| 85 | unsigned char boardtype; /* Board revision and Population Options */ |
| 86 | unsigned char cal; /* cas Latency (will be programmend as cal-1) */ |
| 87 | unsigned char trp; /* datain27 in clocks */ |
| 88 | unsigned char trcd; /* datain29 in clocks */ |
| 89 | unsigned char tras; /* datain30 in clocks */ |
| 90 | unsigned char tctp; /* tras - trcd in clocks */ |
| 91 | unsigned char am; /* Address Mod (will be programmed as am-1) */ |
| 92 | unsigned char sz; /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */ |
| 93 | unsigned char ecc; /* if true, ecc is enabled */ |
| 94 | } sdram_t; |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 95 | #if defined(CONFIG_TARGET_MIP405T) |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 96 | const sdram_t sdram_table[] = { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 97 | { 0x0F, /* MIP405T Rev A, 64MByte -1 Board */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 98 | 3, /* Case Latenty = 3 */ |
| 99 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 100 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 101 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 102 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 103 | 2, /* Address Mode = 2 (12x9x4) */ |
| 104 | 3, /* size value (32MByte) */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 105 | 0}, /* ECC disabled */ |
| 106 | { 0xff, /* terminator */ |
| 107 | 0xff, |
| 108 | 0xff, |
| 109 | 0xff, |
| 110 | 0xff, |
| 111 | 0xff, |
| 112 | 0xff, |
| 113 | 0xff } |
| 114 | }; |
| 115 | #else |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 116 | const sdram_t sdram_table[] = { |
| 117 | { 0x0f, /* Rev A, 128MByte -1 Board */ |
| 118 | 3, /* Case Latenty = 3 */ |
| 119 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 120 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 121 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 122 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 123 | 3, /* Address Mode = 3 */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 124 | 5, /* size value */ |
| 125 | 1}, /* ECC enabled */ |
| 126 | { 0x07, /* Rev A, 64MByte -2 Board */ |
| 127 | 3, /* Case Latenty = 3 */ |
| 128 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 129 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 130 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 131 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 132 | 2, /* Address Mode = 2 */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 133 | 4, /* size value */ |
| 134 | 1}, /* ECC enabled */ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 135 | { 0x03, /* Rev A, 128MByte -4 Board */ |
| 136 | 3, /* Case Latenty = 3 */ |
| 137 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 138 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 139 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 140 | 4, /* tcpt 44 - 20ns = 24ns */ |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 141 | 3, /* Address Mode = 3 */ |
| 142 | 5, /* size value */ |
| 143 | 1}, /* ECC enabled */ |
| 144 | { 0x1f, /* Rev B, 128MByte -3 Board */ |
| 145 | 3, /* Case Latenty = 3 */ |
| 146 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 147 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 148 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 149 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 150 | 3, /* Address Mode = 3 */ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 151 | 5, /* size value */ |
| 152 | 1}, /* ECC enabled */ |
wdenk | 4a55170 | 2003-10-08 23:26:14 +0000 | [diff] [blame] | 153 | { 0x2f, /* Rev C, 128MByte -3 Board */ |
| 154 | 3, /* Case Latenty = 3 */ |
| 155 | 3, /* trp 20ns / 7.5 ns datain[27] */ |
| 156 | 3, /* trcd 20ns /7.5 ns (datain[29]) */ |
| 157 | 6, /* tras 44ns /7.5 ns (datain[30]) */ |
| 158 | 4, /* tcpt 44 - 20ns = 24ns */ |
| 159 | 3, /* Address Mode = 3 */ |
| 160 | 5, /* size value */ |
| 161 | 1}, /* ECC enabled */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 162 | { 0xff, /* terminator */ |
| 163 | 0xff, |
| 164 | 0xff, |
| 165 | 0xff, |
| 166 | 0xff, |
| 167 | 0xff, |
| 168 | 0xff, |
| 169 | 0xff } |
| 170 | }; |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 171 | #endif /*CONFIG_TARGET_MIP405T */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 172 | void SDRAM_err (const char *s) |
| 173 | { |
| 174 | #ifndef SDRAM_DEBUG |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 175 | (void) get_clocks (); |
| 176 | gd->baudrate = 9600; |
| 177 | serial_init (); |
| 178 | #endif |
| 179 | serial_puts ("\n"); |
| 180 | serial_puts (s); |
| 181 | serial_puts ("\n enable SDRAM_DEBUG for more info\n"); |
| 182 | for (;;); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | unsigned char get_board_revcfg (void) |
| 187 | { |
| 188 | out8 (PER_BOARD_ADDR, 0); |
| 189 | return (in8 (PER_BOARD_ADDR)); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | #ifdef SDRAM_DEBUG |
| 194 | |
| 195 | void write_hex (unsigned char i) |
| 196 | { |
| 197 | char cc; |
| 198 | |
| 199 | cc = i >> 4; |
| 200 | cc &= 0xf; |
| 201 | if (cc > 9) |
| 202 | serial_putc (cc + 55); |
| 203 | else |
| 204 | serial_putc (cc + 48); |
| 205 | cc = i & 0xf; |
| 206 | if (cc > 9) |
| 207 | serial_putc (cc + 55); |
| 208 | else |
| 209 | serial_putc (cc + 48); |
| 210 | } |
| 211 | |
| 212 | void write_4hex (unsigned long val) |
| 213 | { |
| 214 | write_hex ((unsigned char) (val >> 24)); |
| 215 | write_hex ((unsigned char) (val >> 16)); |
| 216 | write_hex ((unsigned char) (val >> 8)); |
| 217 | write_hex ((unsigned char) val); |
| 218 | } |
| 219 | |
| 220 | #endif |
| 221 | |
| 222 | |
| 223 | int init_sdram (void) |
| 224 | { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 225 | unsigned long tmp, baseaddr; |
| 226 | unsigned short i; |
| 227 | unsigned char trp_clocks, |
| 228 | trcd_clocks, |
| 229 | tras_clocks, |
Stefan Roese | 4233faf | 2011-11-15 08:03:39 +0000 | [diff] [blame] | 230 | trc_clocks; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 231 | unsigned char cal_val; |
| 232 | unsigned char bc; |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 233 | unsigned long sdram_tim, sdram_bank; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 234 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 235 | /*i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);*/ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 236 | (void) get_clocks (); |
| 237 | gd->baudrate = 9600; |
| 238 | serial_init (); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 239 | /* set up the pld */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 240 | mtdcr (EBC0_CFGADDR, PB7AP); |
| 241 | mtdcr (EBC0_CFGDATA, PLD_AP); |
| 242 | mtdcr (EBC0_CFGADDR, PB7CR); |
| 243 | mtdcr (EBC0_CFGDATA, PLD_CR); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 244 | /* THIS IS OBSOLETE */ |
| 245 | /* set up the board rev reg*/ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 246 | mtdcr (EBC0_CFGADDR, PB5AP); |
| 247 | mtdcr (EBC0_CFGDATA, BOARD_AP); |
| 248 | mtdcr (EBC0_CFGADDR, PB5CR); |
| 249 | mtdcr (EBC0_CFGDATA, BOARD_CR); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 250 | #ifdef SDRAM_DEBUG |
| 251 | /* get all informations from PLD */ |
| 252 | serial_puts ("\nPLD Part 0x"); |
| 253 | bc = in8 (PLD_PART_REG); |
| 254 | write_hex (bc); |
| 255 | serial_puts ("\nPLD Vers 0x"); |
| 256 | bc = in8 (PLD_VERS_REG); |
| 257 | write_hex (bc); |
| 258 | serial_puts ("\nBoard Rev 0x"); |
| 259 | bc = in8 (PLD_BOARD_CFG_REG); |
| 260 | write_hex (bc); |
| 261 | serial_puts ("\n"); |
| 262 | #endif |
| 263 | /* check board */ |
| 264 | bc = in8 (PLD_PART_REG); |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 265 | #if defined(CONFIG_TARGET_MIP405T) |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 266 | if((bc & 0x80)==0) |
| 267 | SDRAM_err ("U-Boot configured for a MIP405T not for a MIP405!!!\n"); |
| 268 | #else |
| 269 | if((bc & 0x80)==0x80) |
| 270 | SDRAM_err ("U-Boot configured for a MIP405 not for a MIP405T!!!\n"); |
| 271 | #endif |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 272 | /* set-up the chipselect machine */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 273 | mtdcr (EBC0_CFGADDR, PB0CR); /* get cs0 config reg */ |
| 274 | tmp = mfdcr (EBC0_CFGDATA); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 275 | if ((tmp & 0x00002000) == 0) { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 276 | /* MPS Boot, set up the flash */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 277 | mtdcr (EBC0_CFGADDR, PB1AP); |
| 278 | mtdcr (EBC0_CFGDATA, FLASH_AP); |
| 279 | mtdcr (EBC0_CFGADDR, PB1CR); |
| 280 | mtdcr (EBC0_CFGDATA, FLASH_CR); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 281 | } else { |
| 282 | /* Flash boot, set up the MPS */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 283 | mtdcr (EBC0_CFGADDR, PB1AP); |
| 284 | mtdcr (EBC0_CFGDATA, MPS_AP); |
| 285 | mtdcr (EBC0_CFGADDR, PB1CR); |
| 286 | mtdcr (EBC0_CFGDATA, MPS_CR); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 287 | } |
| 288 | /* set up UART0 (CS2) and UART1 (CS3) */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 289 | mtdcr (EBC0_CFGADDR, PB2AP); |
| 290 | mtdcr (EBC0_CFGDATA, UART0_AP); |
| 291 | mtdcr (EBC0_CFGADDR, PB2CR); |
| 292 | mtdcr (EBC0_CFGDATA, UART0_CR); |
| 293 | mtdcr (EBC0_CFGADDR, PB3AP); |
| 294 | mtdcr (EBC0_CFGDATA, UART1_AP); |
| 295 | mtdcr (EBC0_CFGADDR, PB3CR); |
| 296 | mtdcr (EBC0_CFGDATA, UART1_CR); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 297 | bc = in8 (PLD_BOARD_CFG_REG); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 298 | #ifdef SDRAM_DEBUG |
| 299 | serial_puts ("\nstart SDRAM Setup\n"); |
| 300 | serial_puts ("\nBoard Rev: "); |
| 301 | write_hex (bc); |
| 302 | serial_puts ("\n"); |
| 303 | #endif |
| 304 | i = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 305 | baseaddr = CONFIG_SYS_SDRAM_BASE; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 306 | while (sdram_table[i].sz != 0xff) { |
| 307 | if (sdram_table[i].boardtype == bc) |
| 308 | break; |
| 309 | i++; |
| 310 | } |
| 311 | if (sdram_table[i].boardtype != bc) |
| 312 | SDRAM_err ("No SDRAM table found for this board!!!\n"); |
| 313 | #ifdef SDRAM_DEBUG |
| 314 | serial_puts (" found table "); |
| 315 | write_hex (i); |
| 316 | serial_puts (" \n"); |
| 317 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 318 | /* since the ECC initialisation needs some time, |
| 319 | * we show that we're alive |
| 320 | */ |
| 321 | if (sdram_table[i].ecc) |
| 322 | serial_puts ("\nInitializing SDRAM, Please stand by"); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 323 | cal_val = sdram_table[i].cal - 1; /* Cas Latency */ |
| 324 | trp_clocks = sdram_table[i].trp; /* 20ns / 7.5 ns datain[27] */ |
| 325 | trcd_clocks = sdram_table[i].trcd; /* 20ns /7.5 ns (datain[29]) */ |
| 326 | tras_clocks = sdram_table[i].tras; /* 44ns /7.5 ns (datain[30]) */ |
| 327 | /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 328 | /* trc_clocks is sum of trp_clocks + tras_clocks */ |
| 329 | trc_clocks = trp_clocks + tras_clocks; |
| 330 | /* get SDRAM timing register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 331 | mtdcr (SDRAM0_CFGADDR, SDRAM0_TR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 332 | sdram_tim = mfdcr (SDRAM0_CFGDATA) & ~0x018FC01F; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 333 | /* insert CASL value */ |
| 334 | sdram_tim |= ((unsigned long) (cal_val)) << 23; |
| 335 | /* insert PTA value */ |
| 336 | sdram_tim |= ((unsigned long) (trp_clocks - 1)) << 18; |
| 337 | /* insert CTP value */ |
| 338 | sdram_tim |= |
| 339 | ((unsigned long) (trc_clocks - trp_clocks - |
| 340 | trcd_clocks)) << 16; |
| 341 | /* insert LDF (always 01) */ |
| 342 | sdram_tim |= ((unsigned long) 0x01) << 14; |
| 343 | /* insert RFTA value */ |
| 344 | sdram_tim |= ((unsigned long) (trc_clocks - 4)) << 2; |
| 345 | /* insert RCD value */ |
| 346 | sdram_tim |= ((unsigned long) (trcd_clocks - 1)) << 0; |
| 347 | |
| 348 | tmp = ((unsigned long) (sdram_table[i].am - 1) << 13); /* AM = 3 */ |
| 349 | /* insert SZ value; */ |
| 350 | tmp |= ((unsigned long) sdram_table[i].sz << 17); |
| 351 | /* get SDRAM bank 0 register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 352 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 353 | sdram_bank = mfdcr (SDRAM0_CFGDATA) & ~0xFFCEE001; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 354 | sdram_bank |= (baseaddr | tmp | 0x01); |
| 355 | |
| 356 | #ifdef SDRAM_DEBUG |
| 357 | serial_puts ("sdtr: "); |
| 358 | write_4hex (sdram_tim); |
| 359 | serial_puts ("\n"); |
| 360 | #endif |
| 361 | |
| 362 | /* write SDRAM timing register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 363 | mtdcr (SDRAM0_CFGADDR, SDRAM0_TR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 364 | mtdcr (SDRAM0_CFGDATA, sdram_tim); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 365 | |
| 366 | #ifdef SDRAM_DEBUG |
| 367 | serial_puts ("mb0cf: "); |
| 368 | write_4hex (sdram_bank); |
| 369 | serial_puts ("\n"); |
| 370 | #endif |
| 371 | |
| 372 | /* write 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 | mtdcr (SDRAM0_CFGDATA, sdram_bank); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 375 | |
| 376 | if (get_bus_freq (tmp) > 110000000) { /* > 110MHz */ |
| 377 | /* get SDRAM refresh interval register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 378 | mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 379 | tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 380 | tmp |= 0x07F00000; |
| 381 | } else { |
| 382 | /* get SDRAM refresh interval register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 383 | mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 384 | tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 385 | tmp |= 0x05F00000; |
| 386 | } |
| 387 | /* write SDRAM refresh interval register */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 388 | mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 389 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 390 | /* enable ECC if used */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 391 | #if defined(ENABLE_ECC) && !defined(CONFIG_BOOT_PCI) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 392 | if (sdram_table[i].ecc) { |
| 393 | /* disable checking for all banks */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 394 | unsigned long *p; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 395 | #ifdef SDRAM_DEBUG |
| 396 | serial_puts ("disable ECC.. "); |
| 397 | #endif |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 398 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 399 | tmp = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 400 | tmp &= 0xff0fffff; /* disable all banks */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 401 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 402 | /* set up SDRAM Controller with ECC enabled */ |
| 403 | #ifdef SDRAM_DEBUG |
| 404 | serial_puts ("setup SDRAM Controller.. "); |
| 405 | #endif |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 406 | mtdcr (SDRAM0_CFGDATA, tmp); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 407 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 408 | tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000; |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 409 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
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 | udelay (600); |
| 412 | #ifdef SDRAM_DEBUG |
| 413 | serial_puts ("fill the memory..\n"); |
| 414 | #endif |
| 415 | serial_puts ("."); |
| 416 | /* now, fill all the memory */ |
| 417 | tmp = ((4 * MEGA_BYTE) << sdram_table[i].sz); |
| 418 | p = (unsigned long) 0; |
| 419 | while ((unsigned long) p < tmp) { |
| 420 | *p++ = 0L; |
| 421 | if (!((unsigned long) p % 0x00800000)) /* every 8MByte */ |
| 422 | serial_puts ("."); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 423 | } |
| 424 | /* enable bank 0 */ |
| 425 | serial_puts ("."); |
| 426 | #ifdef SDRAM_DEBUG |
| 427 | serial_puts ("enable ECC\n"); |
| 428 | #endif |
| 429 | udelay (400); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 430 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 431 | tmp = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 432 | tmp |= 0x00800000; /* enable bank 0 */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 433 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 434 | udelay (400); |
| 435 | } else |
| 436 | #endif |
| 437 | { |
| 438 | /* 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] | 439 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 440 | tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x80C00000; |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 441 | mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 442 | mtdcr (SDRAM0_CFGDATA, tmp); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 443 | udelay (400); |
| 444 | } |
| 445 | serial_puts ("\n"); |
| 446 | return (0); |
| 447 | } |
| 448 | |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 449 | int board_early_init_f (void) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 450 | { |
| 451 | init_sdram (); |
| 452 | |
| 453 | /*-------------------------------------------------------------------------+ |
| 454 | | Interrupt controller setup for the PIP405 board. |
| 455 | | Note: IRQ 0-15 405GP internally generated; active high; level sensitive |
| 456 | | IRQ 16 405GP internally generated; active low; level sensitive |
| 457 | | IRQ 17-24 RESERVED |
| 458 | | IRQ 25 (EXT IRQ 0) SouthBridge; active low; level sensitive |
| 459 | | IRQ 26 (EXT IRQ 1) NMI: active low; level sensitive |
| 460 | | IRQ 27 (EXT IRQ 2) SMI: active Low; level sensitive |
| 461 | | IRQ 28 (EXT IRQ 3) PCI SLOT 3; active low; level sensitive |
| 462 | | IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 463 | | IRQ 30 (EXT IRQ 5) PCI SLOT 1; active low; level sensitive |
| 464 | | IRQ 31 (EXT IRQ 6) PCI SLOT 0; active low; level sensitive |
| 465 | | Note for MIP405 board: |
| 466 | | An interrupt taken for the SouthBridge (IRQ 25) indicates that |
| 467 | | the Interrupt Controller in the South Bridge has caused the |
| 468 | | interrupt. The IC must be read to determine which device |
| 469 | | caused the interrupt. |
| 470 | | |
| 471 | +-------------------------------------------------------------------------*/ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 472 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 473 | mtdcr (UIC0ER, 0x00000000); /* disable all ints */ |
| 474 | mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical (for now) */ |
| 475 | mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */ |
| 476 | mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */ |
| 477 | mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */ |
| 478 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
David Müller | 39441b3 | 2011-12-22 13:38:21 +0100 | [diff] [blame] | 482 | int board_early_init_r(void) |
| 483 | { |
| 484 | int mode; |
| 485 | |
| 486 | /* |
| 487 | * since we are relocated, we can finally enable i-cache |
| 488 | * and set up the flash CS correctly |
| 489 | */ |
| 490 | icache_enable(); |
| 491 | setup_cs_reloc(); |
| 492 | /* get and display boot mode */ |
| 493 | mode = get_boot_mode(); |
| 494 | if (mode & BOOT_PCI) |
| 495 | printf("PCI Boot %s Map\n", (mode & BOOT_MPS) ? |
| 496 | "MPS" : "Flash"); |
| 497 | else |
| 498 | printf("%s Boot\n", (mode & BOOT_MPS) ? |
| 499 | "MPS" : "Flash"); |
| 500 | |
| 501 | return 0; |
| 502 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 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 | { |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 546 | #if !defined(CONFIG_TARGET_MIP405T) |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 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" */ |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 578 | #if !defined(CONFIG_TARGET_MIP405T) |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 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; |
Stefan Roese | 4233faf | 2011-11-15 08:03:39 +0000 | [diff] [blame] | 629 | int i; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 630 | unsigned long TotalSize; |
| 631 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 632 | /* since the DRAM controller is allready set up, calculate the size with the |
| 633 | bank registers */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 634 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 635 | bank_reg[0] = mfdcr (SDRAM0_CFGDATA); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 636 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 637 | bank_reg[1] = mfdcr (SDRAM0_CFGDATA); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 638 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 639 | bank_reg[2] = mfdcr (SDRAM0_CFGDATA); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 640 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 641 | bank_reg[3] = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 642 | TotalSize = 0; |
| 643 | for (i = 0; i < 4; i++) { |
| 644 | if ((bank_reg[i] & 0x1) == 0x1) { |
| 645 | tmp = (bank_reg[i] >> 17) & 0x7; |
| 646 | bank_size = 4 << tmp; |
| 647 | TotalSize += bank_size; |
Stefan Roese | 4233faf | 2011-11-15 08:03:39 +0000 | [diff] [blame] | 648 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 649 | } |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 650 | mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 651 | tmp = mfdcr (SDRAM0_CFGDATA); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 652 | |
| 653 | if (!tmp) |
| 654 | printf ("No "); |
| 655 | printf ("ECC "); |
| 656 | |
| 657 | test_dram (TotalSize * MEGA_BYTE); |
| 658 | return (TotalSize * MEGA_BYTE); |
| 659 | } |
| 660 | |
| 661 | /* ------------------------------------------------------------------------- */ |
| 662 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 663 | |
| 664 | static int test_dram (unsigned long ramsize) |
| 665 | { |
| 666 | #ifdef SDRAM_DEBUG |
| 667 | mem_test (0L, ramsize, 1); |
| 668 | #endif |
| 669 | /* not yet implemented */ |
| 670 | return (1); |
| 671 | } |
| 672 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 673 | /* used to check if the time in RTC is valid */ |
| 674 | static unsigned long start; |
| 675 | static struct rtc_time tm; |
| 676 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 677 | int misc_init_r (void) |
| 678 | { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 679 | /* adjust flash start and size as well as the offset */ |
| 680 | gd->bd->bi_flashstart=0-flash_info[0].size; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 681 | gd->bd->bi_flashsize=flash_info[0].size-CONFIG_SYS_MONITOR_LEN; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 682 | gd->bd->bi_flashoffset=0; |
| 683 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 684 | /* check, if RTC is running */ |
| 685 | rtc_get (&tm); |
| 686 | start=get_timer(0); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 687 | /* 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] | 688 | if (mfdcr(CPC0_PSR) & PSR_ROM_LOC) |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 689 | mtspr(SPRN_CCR0, (mfspr(SPRN_CCR0) & ~0x80)); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 690 | |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 691 | return (0); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void print_mip405_rev (void) |
| 696 | { |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 697 | unsigned char part, vers, pcbrev, var; |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 698 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 699 | get_pcbrev_var(&pcbrev,&var); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 700 | part = in8 (PLD_PART_REG); |
| 701 | vers = in8 (PLD_VERS_REG); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 702 | printf ("Rev: " BOARD_NAME "-%d Rev %c PLD %d Vers %d\n", |
| 703 | var, pcbrev + 'A', part & 0x7F, vers); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 704 | } |
| 705 | |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 706 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 707 | extern int mk_date (char *, struct rtc_time *); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 708 | |
| 709 | int last_stage_init (void) |
| 710 | { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 711 | unsigned long stop; |
| 712 | struct rtc_time newtm; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 713 | char *s; |
Peter Tyser | 331ab60 | 2009-09-21 11:20:33 -0500 | [diff] [blame] | 714 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 715 | /* write correct LED configuration */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 716 | if (miiphy_write("ppc_4xx_eth0", 0x1, 0x14, 0x2402) != 0) { |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 717 | printf ("Error writing to the PHY\n"); |
| 718 | } |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 719 | /* since LED/CFG2 is not connected on the -2, |
| 720 | * write to correct capability information */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 721 | if (miiphy_write("ppc_4xx_eth0", 0x1, 0x4, 0x01E1) != 0) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 722 | printf ("Error writing to the PHY\n"); |
| 723 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 724 | print_mip405_rev (); |
Jean-Christophe PLAGNIOL-VILLARD | 28c3450 | 2009-05-16 12:14:56 +0200 | [diff] [blame] | 725 | stdio_print_current_devices (); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 726 | check_env (); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 727 | /* check if RTC time is valid */ |
| 728 | stop=get_timer(start); |
| 729 | while(stop<1200) { /* we wait 1.2 sec to check if the RTC is running */ |
| 730 | udelay(1000); |
| 731 | stop=get_timer(start); |
| 732 | } |
| 733 | rtc_get (&newtm); |
| 734 | if(tm.tm_sec==newtm.tm_sec) { |
| 735 | s=getenv("defaultdate"); |
| 736 | if(!s) |
| 737 | mk_date ("010112001970", &newtm); |
| 738 | else |
| 739 | if(mk_date (s, &newtm)!=0) { |
| 740 | printf("RTC: Bad date format in defaultdate\n"); |
| 741 | return 0; |
| 742 | } |
| 743 | rtc_reset (); |
| 744 | rtc_set(&newtm); |
| 745 | } |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | /*************************************************************************** |
| 750 | * some helping routines |
| 751 | */ |
| 752 | |
| 753 | int overwrite_console (void) |
| 754 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 755 | /* return true if console should be overwritten */ |
| 756 | return ((in8(PLD_EXT_CONF_REG) & 0x1) == 0); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | |
| 760 | /************************************************************************ |
| 761 | * Print MIP405 Info |
| 762 | ************************************************************************/ |
| 763 | void print_mip405_info (void) |
| 764 | { |
| 765 | unsigned char part, vers, cfg, irq_reg, com_mode, ext; |
| 766 | |
| 767 | part = in8 (PLD_PART_REG); |
| 768 | vers = in8 (PLD_VERS_REG); |
| 769 | cfg = in8 (PLD_BOARD_CFG_REG); |
| 770 | irq_reg = in8 (PLD_IRQ_REG); |
| 771 | com_mode = in8 (PLD_COM_MODE_REG); |
| 772 | ext = in8 (PLD_EXT_CONF_REG); |
| 773 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 774 | printf ("PLD Part %d version %d\n", part & 0x7F, vers); |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 775 | printf ("Board Revision %c\n", ((cfg >> 4) & 0xf) + 'A'); |
| 776 | printf ("Population Options %d %d %d %d\n", (cfg) & 0x1, |
| 777 | (cfg >> 1) & 0x1, (cfg >> 2) & 0x1, (cfg >> 3) & 0x1); |
| 778 | printf ("User LED %s\n", (com_mode & 0x4) ? "on" : "off"); |
| 779 | printf ("UART Clocks %d\n", (com_mode >> 4) & 0x3); |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 780 | #if !defined(CONFIG_TARGET_MIP405T) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 781 | printf ("User Config Switch %d %d %d %d %d %d %d %d\n", |
| 782 | (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1, |
| 783 | (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1, |
| 784 | (ext >> 6) & 0x1, (ext >> 7) & 0x1); |
| 785 | printf ("SER1 uses handshakes %s\n", |
| 786 | (ext & 0x80) ? "DTR/DSR" : "RTS/CTS"); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 787 | #else |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 788 | printf ("User Config Switch %d %d %d %d %d %d %d %d\n", |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 789 | (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1, |
| 790 | (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1, |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 791 | (ext >> 6) & 0x1,(ext >> 7) & 0x1); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 792 | #endif |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 793 | printf ("IDE Reset %s\n", (ext & 0x01) ? "asserted" : "not asserted"); |
| 794 | printf ("IRQs:\n"); |
| 795 | printf (" PIIX INTR: %s\n", (irq_reg & 0x80) ? "inactive" : "active"); |
Tom Rini | adf32ad | 2016-09-19 21:55:34 -0400 | [diff] [blame^] | 796 | #if !defined(CONFIG_TARGET_MIP405T) |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 797 | printf (" UART0 IRQ: %s\n", (irq_reg & 0x40) ? "inactive" : "active"); |
| 798 | printf (" UART1 IRQ: %s\n", (irq_reg & 0x20) ? "inactive" : "active"); |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 799 | #endif |
wdenk | 858b1a6 | 2002-09-30 16:12:23 +0000 | [diff] [blame] | 800 | printf (" PIIX SMI: %s\n", (irq_reg & 0x10) ? "inactive" : "active"); |
| 801 | printf (" PIIX INIT: %s\n", (irq_reg & 0x8) ? "inactive" : "active"); |
| 802 | printf (" PIIX NMI: %s\n", (irq_reg & 0x4) ? "inactive" : "active"); |
| 803 | } |