sixnet.c 19 KB

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