sixnet.c 19 KB

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