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