wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001, 2002 |
| 3 | * Dave Ellis, SIXNET, dge@sixnetio.com. |
| 4 | * Based on code by: |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * and other contributors to U-Boot. See file CREDITS for list |
| 7 | * of people who contributed to this project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <config.h> |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 27 | #include <jffs2/jffs2.h> |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 28 | #include <mpc8xx.h> |
| 29 | #include <net.h> /* for eth_init() */ |
| 30 | #include <rtc.h> |
| 31 | #include "sixnet.h" |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 33 | # include <status_led.h> |
| 34 | #endif |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 35 | |
Jon Loeliger | ab3abcb | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 36 | #if defined(CONFIG_CMD_NAND) |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 37 | #include <linux/mtd/nand_legacy.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 38 | extern struct nand_chip nand_dev_desc[CONFIG_SYS_MAX_NAND_DEVICE]; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 43 | #define ORMASK(size) ((-size) & OR_AM_MSK) |
| 44 | |
| 45 | static long ram_size(ulong *, long); |
| 46 | |
| 47 | /* ------------------------------------------------------------------------- */ |
| 48 | |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 49 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 50 | void show_boot_progress (int status) |
| 51 | { |
| 52 | #if defined(CONFIG_STATUS_LED) |
| 53 | # if defined(STATUS_LED_BOOT) |
| 54 | if (status == 15) { |
| 55 | /* ready to transfer to kernel, make sure LED is proper state */ |
| 56 | status_led_set(STATUS_LED_BOOT, CONFIG_BOOT_LED_STATE); |
| 57 | } |
| 58 | # endif /* STATUS_LED_BOOT */ |
| 59 | #endif /* CONFIG_STATUS_LED */ |
| 60 | } |
| 61 | #endif |
| 62 | |
| 63 | /* ------------------------------------------------------------------------- */ |
| 64 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 65 | /* |
| 66 | * Check Board Identity: |
| 67 | * returns 0 if recognized, -1 if unknown |
| 68 | */ |
| 69 | |
| 70 | int checkboard (void) |
| 71 | { |
| 72 | puts ("Board: SIXNET SXNI855T\n"); |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | /* ------------------------------------------------------------------------- */ |
| 77 | |
Jon Loeliger | ab3abcb | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 78 | #if defined(CONFIG_CMD_PCMCIA) |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 79 | #error "SXNI855T has no PCMCIA port" |
Jon Loeliger | d39b574 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 80 | #endif |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 81 | |
| 82 | /* ------------------------------------------------------------------------- */ |
| 83 | |
| 84 | #define _not_used_ 0xffffffff |
| 85 | |
| 86 | /* UPMB table for dual UART. */ |
| 87 | |
| 88 | /* this table is for 50MHz operation, it should work at all lower speeds */ |
| 89 | const uint duart_table[] = |
| 90 | { |
| 91 | /* single read. (offset 0 in upm RAM) */ |
| 92 | 0xfffffc04, 0x0ffffc04, 0x0ff3fc04, 0x0ff3fc04, |
| 93 | 0x0ff3fc00, 0x0ff3fc04, 0xfffffc04, 0xfffffc05, |
| 94 | |
| 95 | /* burst read. (offset 8 in upm RAM) */ |
| 96 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 97 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 98 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 99 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 100 | |
| 101 | /* single write. (offset 18 in upm RAM) */ |
| 102 | 0xfffffc04, 0x0ffffc04, 0x00fffc04, 0x00fffc04, |
| 103 | 0x00fffc04, 0x00fffc00, 0xfffffc04, 0xfffffc05, |
| 104 | |
| 105 | /* burst write. (offset 20 in upm RAM) */ |
| 106 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 107 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 108 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 109 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 110 | |
| 111 | /* refresh. (offset 30 in upm RAM) */ |
| 112 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 113 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 114 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 115 | |
| 116 | /* exception. (offset 3c in upm RAM) */ |
| 117 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 118 | }; |
| 119 | |
| 120 | /* Load FPGA very early in boot sequence, since it must be |
| 121 | * loaded before the 16C2550 serial channels can be used as |
| 122 | * console channels. |
| 123 | * |
| 124 | * Note: Much of the configuration is not complete. The |
| 125 | * stack is in DPRAM since SDRAM has not been initialized, |
| 126 | * so the stack must be kept small. Global variables |
| 127 | * are still in FLASH, so they cannot be written. |
| 128 | * Only the FLASH, DPRAM, immap and FPGA can be addressed, |
| 129 | * the other chip selects may not have been initialized. |
| 130 | * The clocks have been initialized, so udelay() can be |
| 131 | * used. |
| 132 | */ |
| 133 | #define FPGA_DONE 0x0080 /* PA8, input, high when FPGA load complete */ |
| 134 | #define FPGA_PROGRAM_L 0x0040 /* PA9, output, low to reset, high to start */ |
| 135 | #define FPGA_INIT_L 0x0020 /* PA10, input, low indicates not ready */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 136 | #define fpga (*(volatile unsigned char *)(CONFIG_SYS_FPGA_PROG)) /* FPGA port */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 137 | |
| 138 | int board_postclk_init (void) |
| 139 | { |
| 140 | |
| 141 | /* the data to load to the XCSxxXL FPGA */ |
| 142 | static const unsigned char fpgadata[] = { |
| 143 | # include "fpgadata.c" |
| 144 | }; |
| 145 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 146 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 147 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 148 | #define porta (immap->im_ioport.iop_padat) |
| 149 | const unsigned char* pdata; |
| 150 | |
| 151 | /* /INITFPGA and DONEFPGA signals are inputs */ |
| 152 | immap->im_ioport.iop_padir &= ~(FPGA_INIT_L | FPGA_DONE); |
| 153 | |
| 154 | /* Force output pin to begin at 0, /PROGRAM asserted (0) resets FPGA */ |
| 155 | porta &= ~FPGA_PROGRAM_L; |
| 156 | |
| 157 | /* Set FPGA as an output */ |
| 158 | immap->im_ioport.iop_padir |= FPGA_PROGRAM_L; |
| 159 | |
| 160 | /* delay a little to make sure FPGA sees it, really |
| 161 | * only need less than a microsecond. |
| 162 | */ |
| 163 | udelay(10); |
| 164 | |
| 165 | /* unassert /PROGRAM */ |
| 166 | porta |= FPGA_PROGRAM_L; |
| 167 | |
| 168 | /* delay while FPGA does last erase, indicated by |
| 169 | * /INITFPGA going high. This should happen within a |
| 170 | * few milliseconds. |
| 171 | */ |
| 172 | /* ### FIXME - a timeout check would be good, maybe flash |
| 173 | * the status LED to indicate the error? |
| 174 | */ |
| 175 | while ((porta & FPGA_INIT_L) == 0) |
| 176 | ; /* waiting */ |
| 177 | |
| 178 | /* write program data to FPGA at the programming address |
| 179 | * so extra /CS1 strobes at end of configuration don't actually |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 180 | * write to any registers. |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 181 | */ |
| 182 | fpga = 0xff; /* first write is ignored */ |
| 183 | fpga = 0xff; /* fill byte */ |
| 184 | fpga = 0xff; /* fill byte */ |
| 185 | fpga = 0x4f; /* preamble code */ |
| 186 | fpga = 0x80; fpga = 0xaf; fpga = 0x9b; /* length (ignored) */ |
| 187 | fpga = 0x4b; /* field check code */ |
| 188 | |
| 189 | pdata = fpgadata; |
| 190 | /* while no error write out each of the 28 byte frames */ |
| 191 | while ((porta & (FPGA_INIT_L | FPGA_DONE)) == FPGA_INIT_L |
| 192 | && pdata < fpgadata + sizeof(fpgadata)) { |
| 193 | |
| 194 | fpga = 0x4f; /* preamble code */ |
| 195 | |
| 196 | /* 21 bytes of data in a frame */ |
| 197 | fpga = *(pdata++); fpga = *(pdata++); |
| 198 | fpga = *(pdata++); fpga = *(pdata++); |
| 199 | fpga = *(pdata++); fpga = *(pdata++); |
| 200 | fpga = *(pdata++); fpga = *(pdata++); |
| 201 | fpga = *(pdata++); fpga = *(pdata++); |
| 202 | fpga = *(pdata++); fpga = *(pdata++); |
| 203 | fpga = *(pdata++); fpga = *(pdata++); |
| 204 | fpga = *(pdata++); fpga = *(pdata++); |
| 205 | fpga = *(pdata++); fpga = *(pdata++); |
| 206 | fpga = *(pdata++); fpga = *(pdata++); |
| 207 | fpga = *(pdata++); |
| 208 | |
| 209 | fpga = 0x4b; /* field check code */ |
| 210 | fpga = 0xff; /* extended write cycle */ |
| 211 | fpga = 0x4b; /* extended write cycle |
| 212 | * (actually 0x4b from bitgen.exe) |
| 213 | */ |
| 214 | fpga = 0xff; /* extended write cycle */ |
| 215 | fpga = 0xff; /* extended write cycle */ |
| 216 | fpga = 0xff; /* extended write cycle */ |
| 217 | } |
| 218 | |
| 219 | fpga = 0xff; /* startup byte */ |
| 220 | fpga = 0xff; /* startup byte */ |
| 221 | fpga = 0xff; /* startup byte */ |
| 222 | fpga = 0xff; /* startup byte */ |
| 223 | |
| 224 | #if 0 /* ### FIXME */ |
| 225 | /* If didn't load all the data or FPGA_DONE is low the load failed. |
| 226 | * Maybe someday stop here and flash the status LED? The console |
| 227 | * is not configured, so can't print an error message. Can't write |
| 228 | * global variables to set a flag (except gd?). |
| 229 | * For now it must work. |
| 230 | */ |
| 231 | #endif |
| 232 | |
| 233 | /* Now that the FPGA is loaded, set up the Dual UART chip |
| 234 | * selects. Must be done here since it may be used as the console. |
| 235 | */ |
| 236 | upmconfig(UPMB, (uint *)duart_table, sizeof(duart_table)/sizeof(uint)); |
| 237 | |
| 238 | memctl->memc_mbmr = DUART_MBMR; |
| 239 | memctl->memc_or5 = DUART_OR_VALUE; |
| 240 | memctl->memc_br5 = DUART_BR5_VALUE; |
| 241 | memctl->memc_or6 = DUART_OR_VALUE; |
| 242 | memctl->memc_br6 = DUART_BR6_VALUE; |
| 243 | |
| 244 | return (0); |
| 245 | } |
| 246 | |
| 247 | /* ------------------------------------------------------------------------- */ |
| 248 | |
| 249 | /* base address for SRAM, assume 32-bit port, valid */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 250 | #define NVRAM_BR_VALUE (CONFIG_SYS_SRAM_BASE | BR_PS_32 | BR_V) |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 251 | |
| 252 | /* up to 64MB - will be adjusted for actual size */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 253 | #define NVRAM_OR_PRELIM (ORMASK(CONFIG_SYS_SRAM_SIZE) \ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 254 | | OR_CSNT_SAM | OR_ACS_DIV4 | OR_BI | OR_SCY_5_CLK | OR_EHTR) |
| 255 | /* |
| 256 | * Miscellaneous platform dependent initializations after running in RAM. |
| 257 | */ |
| 258 | |
| 259 | int misc_init_r (void) |
| 260 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 261 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 262 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 263 | bd_t *bd = gd->bd; |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 264 | uchar enetaddr[6]; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 265 | |
| 266 | memctl->memc_or2 = NVRAM_OR_PRELIM; |
| 267 | memctl->memc_br2 = NVRAM_BR_VALUE; |
| 268 | |
| 269 | /* Is there any SRAM? Is it 16 or 32 bits wide? */ |
| 270 | |
| 271 | /* First look for 32-bit SRAM */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 272 | bd->bi_sramsize = ram_size((ulong*)CONFIG_SYS_SRAM_BASE, CONFIG_SYS_SRAM_SIZE); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 273 | |
| 274 | if (bd->bi_sramsize == 0) { |
| 275 | /* no 32-bit SRAM, but there could be 16-bit SRAM since |
| 276 | * it would report size 0 when configured for 32-bit bus. |
| 277 | * Try again with a 16-bit bus. |
| 278 | */ |
| 279 | memctl->memc_br2 |= BR_PS_16; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 280 | bd->bi_sramsize = ram_size((ulong*)CONFIG_SYS_SRAM_BASE, CONFIG_SYS_SRAM_SIZE); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | if (bd->bi_sramsize == 0) { |
| 284 | memctl->memc_br2 = 0; /* disable select since nothing there */ |
| 285 | } |
| 286 | else { |
| 287 | /* adjust or2 for actual size of SRAM */ |
| 288 | memctl->memc_or2 |= ORMASK(bd->bi_sramsize); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 289 | bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 290 | printf("SRAM: %lu KB\n", bd->bi_sramsize >> 10); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | /* set standard MPC8xx clock so kernel will see the time |
| 295 | * even if it doesn't have a DS1306 clock driver. |
| 296 | * This helps with experimenting with standard kernels. |
| 297 | */ |
| 298 | { |
| 299 | ulong tim; |
| 300 | struct rtc_time tmp; |
| 301 | |
| 302 | rtc_get(&tmp); /* get time from DS1306 RTC */ |
| 303 | |
| 304 | /* convert to seconds since 1970 */ |
| 305 | tim = mktime(tmp.tm_year, tmp.tm_mon, tmp.tm_mday, |
| 306 | tmp.tm_hour, tmp.tm_min, tmp.tm_sec); |
| 307 | |
| 308 | immap->im_sitk.sitk_rtck = KAPWR_KEY; |
| 309 | immap->im_sit.sit_rtc = tim; |
| 310 | } |
| 311 | |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 312 | /* set up ethernet address for SCC ethernet. If eth1addr |
| 313 | * is present it gets a unique address, otherwise it |
| 314 | * shares the FEC address. |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 315 | */ |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 316 | if (!eth_getenv_enetaddr("eth1addr", enetaddr)) { |
| 317 | eth_getenv_enetaddr("ethaddr", enetaddr); |
| 318 | eth_setenv_enetaddr("eth1addr", enetaddr); |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 319 | } |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 320 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 321 | return (0); |
| 322 | } |
| 323 | |
Jon Loeliger | ab3abcb | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 324 | #if defined(CONFIG_CMD_NAND) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 325 | void nand_init(void) |
| 326 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 327 | unsigned long totlen = nand_probe(CONFIG_SYS_DFLASH_BASE); |
wdenk | a43278a | 2003-09-11 19:48:06 +0000 | [diff] [blame] | 328 | |
| 329 | printf ("%4lu MB\n", totlen >> 20); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 330 | } |
| 331 | #endif |
| 332 | |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 333 | /* ------------------------------------------------------------------------- */ |
| 334 | |
| 335 | /* |
| 336 | * Check memory range for valid RAM. A simple memory test determines |
| 337 | * the actually available RAM size between addresses `base' and |
| 338 | * `base + maxsize'. |
| 339 | * |
| 340 | * The memory size MUST be a power of 2 for this to work. |
| 341 | * |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 342 | * The only memory modified is 8 bytes at offset 0. This is important |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 343 | * since for the SRAM this location is reserved for autosizing, so if |
| 344 | * it is modified and the board is reset before ram_size() completes |
| 345 | * no damage is done. Normally even the memory at 0 is preserved. The |
| 346 | * higher SRAM addresses may contain battery backed RAM disk data which |
| 347 | * must never be corrupted. |
| 348 | */ |
| 349 | |
| 350 | static long ram_size(ulong *base, long maxsize) |
| 351 | { |
| 352 | volatile long *test_addr; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 353 | volatile ulong *base_addr = base; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 354 | ulong ofs; /* byte offset from base_addr */ |
| 355 | ulong save; /* to make test non-destructive */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 356 | ulong save2; /* to make test non-destructive */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 357 | long ramsize = -1; /* size not determined yet */ |
| 358 | |
| 359 | save = *base_addr; /* save value at 0 so can restore */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 360 | save2 = *(base_addr+1); /* save value at 4 so can restore */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 361 | |
| 362 | /* is any SRAM present? */ |
| 363 | *base_addr = 0x5555aaaa; |
| 364 | |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 365 | /* It is important to drive the data bus with different data so |
| 366 | * it doesn't remember the value and look like RAM that isn't there. |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 367 | */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 368 | *(base_addr + 1) = 0xaaaa5555; /* use write to modify data bus */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 369 | |
| 370 | if (*base_addr != 0x5555aaaa) |
| 371 | ramsize = 0; /* no RAM present, or defective */ |
| 372 | else { |
| 373 | *base_addr = 0xaaaa5555; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 374 | *(base_addr + 1) = 0x5555aaaa; /* use write to modify data bus */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 375 | if (*base_addr != 0xaaaa5555) |
| 376 | ramsize = 0; /* no RAM present, or defective */ |
| 377 | } |
| 378 | |
| 379 | /* now size it if any is present */ |
| 380 | for (ofs = 4; ofs < maxsize && ramsize < 0; ofs <<= 1) { |
| 381 | test_addr = (long*)((long)base_addr + ofs); /* location to test */ |
| 382 | |
| 383 | *base_addr = ~*test_addr; |
| 384 | if (*base_addr == *test_addr) |
| 385 | ramsize = ofs; /* wrapped back to 0, so this is the size */ |
| 386 | } |
| 387 | |
| 388 | *base_addr = save; /* restore value at 0 */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 389 | *(base_addr+1) = save2; /* restore value at 4 */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 390 | return (ramsize); |
| 391 | } |
| 392 | |
| 393 | /* ------------------------------------------------------------------------- */ |
| 394 | /* sdram table based on the FADS manual */ |
| 395 | /* for chip MB811171622A-100 */ |
| 396 | |
| 397 | /* this table is for 50MHz operation, it should work at all lower speeds */ |
| 398 | |
| 399 | const uint sdram_table[] = |
| 400 | { |
| 401 | /* single read. (offset 0 in upm RAM) */ |
| 402 | 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00, |
| 403 | 0x1ff77c47, |
| 404 | |
| 405 | /* precharge and Mode Register Set initialization (offset 5). |
| 406 | * This is also entered at offset 6 to do Mode Register Set |
| 407 | * without the precharge. |
| 408 | */ |
| 409 | 0x1ff77c34, 0xefeabc34, 0x1fb57c35, |
| 410 | |
| 411 | /* burst read. (offset 8 in upm RAM) */ |
| 412 | 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00, |
| 413 | 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, |
| 414 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 415 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 416 | |
| 417 | /* single write. (offset 18 in upm RAM) */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 418 | /* FADS had 0x1f27fc04, ... |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 419 | * but most other boards have 0x1f07fc04, which |
| 420 | * sets GPL0 from A11MPC to 0 1/4 clock earlier, |
| 421 | * like the single read. |
| 422 | * This seems better so I am going with the change. |
| 423 | */ |
| 424 | 0x1f07fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, |
| 425 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 426 | |
| 427 | /* burst write. (offset 20 in upm RAM) */ |
| 428 | 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00, |
| 429 | 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _not_used_, |
| 430 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 431 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 432 | |
| 433 | /* refresh. (offset 30 in upm RAM) */ |
| 434 | 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 435 | 0xfffffc84, 0xfffffc07, _not_used_, _not_used_, |
| 436 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 437 | |
| 438 | /* exception. (offset 3c in upm RAM) */ |
| 439 | 0x7ffffc07, _not_used_, _not_used_, _not_used_ }; |
| 440 | |
| 441 | /* ------------------------------------------------------------------------- */ |
| 442 | |
| 443 | #define SDRAM_MAX_SIZE 0x10000000 /* max 256 MB SDRAM */ |
| 444 | |
| 445 | /* precharge and set Mode Register */ |
| 446 | #define SDRAM_MCR_PRE (MCR_OP_RUN | MCR_UPM_A | /* select UPM */ \ |
| 447 | MCR_MB_CS3 | /* chip select */ \ |
| 448 | MCR_MLCF(1) | MCR_MAD(5)) /* 1 time at 0x05 */ |
| 449 | |
| 450 | /* set Mode Register, no precharge */ |
| 451 | #define SDRAM_MCR_MRS (MCR_OP_RUN | MCR_UPM_A | /* select UPM */ \ |
| 452 | MCR_MB_CS3 | /* chip select */ \ |
| 453 | MCR_MLCF(1) | MCR_MAD(6)) /* 1 time at 0x06 */ |
| 454 | |
| 455 | /* runs refresh loop twice so get 8 refresh cycles */ |
| 456 | #define SDRAM_MCR_REFR (MCR_OP_RUN | MCR_UPM_A | /* select UPM */ \ |
| 457 | MCR_MB_CS3 | /* chip select */ \ |
| 458 | MCR_MLCF(2) | MCR_MAD(0x30)) /* twice at 0x30 */ |
| 459 | |
| 460 | /* MAMR values work in either mamr or mbmr */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 461 | #define SDRAM_MAMR_BASE /* refresh at 50MHz */ \ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 462 | ((195 << MAMR_PTA_SHIFT) | MAMR_PTAE \ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 463 | | MAMR_DSA_1_CYCL /* 1 cycle disable */ \ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 464 | | MAMR_RLFA_1X /* Read loop 1 time */ \ |
| 465 | | MAMR_WLFA_1X /* Write loop 1 time */ \ |
| 466 | | MAMR_TLFA_4X) /* Timer loop 4 times */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 467 | /* 8 column SDRAM */ |
| 468 | #define SDRAM_MAMR_8COL (SDRAM_MAMR_BASE \ |
| 469 | | MAMR_AMA_TYPE_0 /* Address MUX 0 */ \ |
| 470 | | MAMR_G0CLA_A11) /* GPL0 A11[MPC] */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 471 | |
| 472 | /* 9 column SDRAM */ |
wdenk | 506f044 | 2003-03-28 14:40:36 +0000 | [diff] [blame] | 473 | #define SDRAM_MAMR_9COL (SDRAM_MAMR_BASE \ |
| 474 | | MAMR_AMA_TYPE_1 /* Address MUX 1 */ \ |
| 475 | | MAMR_G0CLA_A10) /* GPL0 A10[MPC] */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 476 | |
| 477 | /* base address 0, 32-bit port, SDRAM UPM, valid */ |
| 478 | #define SDRAM_BR_VALUE (BR_PS_32 | BR_MS_UPMA | BR_V) |
| 479 | |
| 480 | /* up to 256MB, SAM, G5LS - will be adjusted for actual size */ |
| 481 | #define SDRAM_OR_PRELIM (ORMASK(SDRAM_MAX_SIZE) | OR_CSNT_SAM | OR_G5LS) |
| 482 | |
| 483 | /* This is the Mode Select Register value for the SDRAM. |
| 484 | * Burst length: 4 |
| 485 | * Burst Type: sequential |
| 486 | * CAS Latency: 2 |
| 487 | * Write Burst Length: burst |
| 488 | */ |
| 489 | #define SDRAM_MODE 0x22 /* CAS latency 2, burst length 4 */ |
| 490 | |
| 491 | /* ------------------------------------------------------------------------- */ |
| 492 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 493 | phys_size_t initdram(int board_type) |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 494 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 495 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 496 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 497 | uint size_sdram = 0; |
| 498 | uint size_sdram9 = 0; |
| 499 | uint base = 0; /* SDRAM must start at 0 */ |
| 500 | int i; |
| 501 | |
| 502 | upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint)); |
| 503 | |
| 504 | /* Configure the refresh (mostly). This needs to be |
| 505 | * based upon processor clock speed and optimized to provide |
| 506 | * the highest level of performance. |
| 507 | * |
| 508 | * Preliminary prescaler for refresh. |
| 509 | * This value is selected for four cycles in 31.2 us, |
| 510 | * which gives 8192 cycles in 64 milliseconds. |
| 511 | * This may be too fast, but works for any memory. |
| 512 | * It is adjusted to 4096 cycles in 64 milliseconds if |
| 513 | * possible once we know what memory we have. |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 514 | * |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 515 | * We have to be careful changing UPM registers after we |
| 516 | * ask it to run these commands. |
| 517 | * |
| 518 | * PTA - periodic timer period for our design is |
| 519 | * 50 MHz x 31.2us |
| 520 | * --------------- = 195 |
| 521 | * 1 x 8 x 1 |
| 522 | * |
| 523 | * 50MHz clock |
| 524 | * 31.2us refresh interval |
| 525 | * SCCR[DFBRG] 0 |
| 526 | * PTP divide by 8 |
| 527 | * 1 chip select |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 528 | */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 529 | memctl->memc_mptpr = MPTPR_PTP_DIV8; /* 0x0800 */ |
| 530 | memctl->memc_mamr = SDRAM_MAMR_8COL & (~MAMR_PTAE); /* no refresh yet */ |
| 531 | |
| 532 | /* The SDRAM Mode Register value is shifted left 2 bits since |
| 533 | * A30 and A31 don't connect to the SDRAM for 32-bit wide memory. |
| 534 | */ |
| 535 | memctl->memc_mar = SDRAM_MODE << 2; /* MRS code */ |
| 536 | udelay(200); /* SDRAM needs 200uS before set it up */ |
| 537 | |
| 538 | /* Now run the precharge/nop/mrs commands. */ |
| 539 | memctl->memc_mcr = SDRAM_MCR_PRE; |
| 540 | udelay(2); |
| 541 | |
| 542 | /* Run 8 refresh cycles (2 sets of 4) */ |
| 543 | memctl->memc_mcr = SDRAM_MCR_REFR; /* run refresh twice */ |
| 544 | udelay(2); |
| 545 | |
| 546 | /* some brands want Mode Register set after the refresh |
| 547 | * cycles. This shouldn't hurt anything for the brands |
| 548 | * that were happy with the first time we set it. |
| 549 | */ |
| 550 | memctl->memc_mcr = SDRAM_MCR_MRS; |
| 551 | udelay(2); |
| 552 | |
| 553 | memctl->memc_mamr = SDRAM_MAMR_8COL; /* enable refresh */ |
| 554 | memctl->memc_or3 = SDRAM_OR_PRELIM; |
| 555 | memctl->memc_br3 = SDRAM_BR_VALUE + base; |
| 556 | |
| 557 | /* Some brands need at least 10 DRAM accesses to stabilize. |
| 558 | * It wont hurt the brands that don't. |
| 559 | */ |
| 560 | for (i=0; i<10; ++i) { |
| 561 | volatile ulong *addr = (volatile ulong *)base; |
| 562 | ulong val; |
| 563 | |
| 564 | val = *(addr + i); |
| 565 | *(addr + i) = val; |
| 566 | } |
| 567 | |
| 568 | /* Check SDRAM memory Size in 8 column mode. |
| 569 | * For a 9 column memory we will get half the actual size. |
| 570 | */ |
| 571 | size_sdram = ram_size((ulong *)0, SDRAM_MAX_SIZE); |
| 572 | |
| 573 | /* Check SDRAM memory Size in 9 column mode. |
| 574 | * For an 8 column memory we will see at most 4 megabytes. |
| 575 | */ |
| 576 | memctl->memc_mamr = SDRAM_MAMR_9COL; |
| 577 | size_sdram9 = ram_size((ulong *)0, SDRAM_MAX_SIZE); |
| 578 | |
| 579 | if (size_sdram < size_sdram9) /* leave configuration at 9 columns */ |
| 580 | size_sdram = size_sdram9; |
| 581 | else /* go back to 8 columns */ |
| 582 | memctl->memc_mamr = SDRAM_MAMR_8COL; |
| 583 | |
| 584 | /* adjust or3 for actual size of SDRAM |
| 585 | */ |
| 586 | memctl->memc_or3 |= ORMASK(size_sdram); |
| 587 | |
| 588 | /* Adjust refresh rate depending on SDRAM type. |
| 589 | * For types > 128 MBit (32 Mbyte for 2 x16 devices) leave |
| 590 | * it at the current (fast) rate. |
| 591 | * For 16, 64 and 128 MBit half the rate will do. |
| 592 | */ |
| 593 | if (size_sdram <= 32 * 1024 * 1024) |
| 594 | memctl->memc_mptpr = MPTPR_PTP_DIV16; /* 0x0400 */ |
| 595 | |
| 596 | return (size_sdram); |
| 597 | } |