sixnet.c 20 KB

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