nx823.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * (C) Copyright 2001
  3. * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
  4. *
  5. * (C) Copyright 2001-2002
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <malloc.h>
  28. #include <mpc8xx.h>
  29. /* ------------------------------------------------------------------------- */
  30. static long int dram_size (long int, long int *, long int);
  31. /* ------------------------------------------------------------------------- */
  32. #define _NOT_USED_ 0xFFFFFFFF
  33. const uint sdram_table[] =
  34. {
  35. #if (MPC8XX_SPEED <= 50000000L)
  36. /*
  37. * Single Read. (Offset 0 in UPMA RAM)
  38. */
  39. 0x0F07EC04,
  40. 0x01BBD804,
  41. 0x1FF7F440,
  42. 0xFFFFFC07,
  43. 0xFFFFFFFF,
  44. /*
  45. * SDRAM Initialization (offset 5 in UPMA RAM)
  46. *
  47. * This is no UPM entry point. The following definition uses
  48. * the remaining space to establish an initialization
  49. * sequence, which is executed by a RUN command.
  50. *
  51. */
  52. 0x1FE7F434,
  53. 0xEFABE834,
  54. 0x1FA7D435,
  55. /*
  56. * Burst Read. (Offset 8 in UPMA RAM)
  57. */
  58. 0x0F07EC04,
  59. 0x10EFDC04,
  60. 0xF0AFFC00,
  61. 0xF0AFFC00,
  62. 0xF1AFFC00,
  63. 0xFFAFFC40,
  64. 0xFFAFFC07,
  65. 0xFFFFFFFF,
  66. 0xFFFFFFFF,
  67. 0xFFFFFFFF,
  68. 0xFFFFFFFF,
  69. 0xFFFFFFFF,
  70. 0xFFFFFFFF,
  71. 0xFFFFFFFF,
  72. 0xFFFFFFFF,
  73. 0xFFFFFFFF,
  74. /*
  75. * Single Write. (Offset 18 in UPMA RAM)
  76. */
  77. 0x0E07E804,
  78. 0x01BBD000,
  79. 0x1FF7F447,
  80. 0xFFFFFFFF,
  81. 0xFFFFFFFF,
  82. 0xFFFFFFFF,
  83. 0xFFFFFFFF,
  84. 0xFFFFFFFF,
  85. /*
  86. * Burst Write. (Offset 20 in UPMA RAM)
  87. */
  88. 0x0E07E800,
  89. 0x10EFD400,
  90. 0xF0AFFC00,
  91. 0xF0AFFC00,
  92. 0xF1AFFC47,
  93. 0xFFFFFFFF,
  94. 0xFFFFFFFF,
  95. 0xFFFFFFFF,
  96. 0xFFFFFFFF,
  97. 0xFFFFFFFF,
  98. 0xFFFFFFFF,
  99. 0xFFFFFFFF,
  100. 0xFFFFFFFF,
  101. 0xFFFFFFFF,
  102. 0xFFFFFFFF,
  103. 0xFFFFFFFF,
  104. /*
  105. * Refresh (Offset 30 in UPMA RAM)
  106. */
  107. 0x1FF7DC84,
  108. 0xFFFFFC04,
  109. 0xFFFFFC84,
  110. 0xFFFFFC07,
  111. 0xFFFFFFFF,
  112. 0xFFFFFFFF,
  113. 0xFFFFFFFF,
  114. 0xFFFFFFFF,
  115. 0xFFFFFFFF,
  116. 0xFFFFFFFF,
  117. 0xFFFFFFFF,
  118. 0xFFFFFFFF,
  119. /*
  120. * Exception. (Offset 3c in UPMA RAM)
  121. */
  122. 0x7FFFFC07,
  123. 0xFFFFFFFF,
  124. 0xFFFFFFFF,
  125. 0xFFFFFFFF
  126. #else
  127. /*
  128. * Single Read. (Offset 0 in UPMA RAM)
  129. */
  130. 0x1F07FC04,
  131. 0xEEAFEC04,
  132. 0x11AFDC04,
  133. 0xEFBBF800,
  134. 0x1FF7F447,
  135. /*
  136. * SDRAM Initialization (offset 5 in UPMA RAM)
  137. *
  138. * This is no UPM entry point. The following definition uses
  139. * the remaining space to establish an initialization
  140. * sequence, which is executed by a RUN command.
  141. *
  142. */
  143. 0x1FF7F434,
  144. 0xEFEBE834,
  145. 0x1FB7D435,
  146. /*
  147. * Burst Read. (Offset 8 in UPMA RAM)
  148. */
  149. 0x1F07FC04,
  150. 0xEEAFEC04,
  151. 0x10AFDC04,
  152. 0xF0AFFC00,
  153. 0xF0AFFC00,
  154. 0xF1AFFC00,
  155. 0xEFBBF800,
  156. 0x1FF7F447,
  157. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  158. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  159. /*
  160. * Single Write. (Offset 18 in UPMA RAM)
  161. */
  162. 0x1F07FC04,
  163. 0xEEAFE800,
  164. 0x01BBD004,
  165. 0x1FF7F447,
  166. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  167. /*
  168. * Burst Write. (Offset 20 in UPMA RAM)
  169. */
  170. 0x1F07FC04,
  171. 0xEEAFE800,
  172. 0x10AFD400,
  173. 0xF0AFFC00,
  174. 0xF0AFFC00,
  175. 0xE1BBF804,
  176. 0x1FF7F447,
  177. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  178. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  179. /*
  180. * Refresh (Offset 30 in UPMA RAM)
  181. */
  182. 0x1FF7DC84,
  183. 0xFFFFFC04,
  184. 0xFFFFFC04,
  185. 0xFFFFFC04,
  186. 0xFFFFFC84,
  187. 0xFFFFFC07,
  188. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  189. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  190. /*
  191. * Exception. (Offset 3c in UPMA RAM)
  192. */
  193. 0x7FFFFC07, /* last */
  194. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  195. #endif
  196. };
  197. /* ------------------------------------------------------------------------- */
  198. /*
  199. * Check Board Identity:
  200. *
  201. */
  202. int checkboard (void)
  203. {
  204. printf ("Board: Nexus NX823");
  205. return (0);
  206. }
  207. /* ------------------------------------------------------------------------- */
  208. long int initdram (int board_type)
  209. {
  210. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  211. volatile memctl8xx_t *memctl = &immap->im_memctl;
  212. long int size_b0, size_b1, size8, size9;
  213. upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  214. /*
  215. * Up to 2 Banks of 64Mbit x 2 devices
  216. * Initial builds only have 1
  217. */
  218. memctl->memc_mptpr = CFG_MPTPR_1BK_4K;
  219. memctl->memc_mar = 0x00000088;
  220. /*
  221. * Map controller SDRAM bank 0
  222. */
  223. memctl->memc_or1 = CFG_OR1_PRELIM;
  224. memctl->memc_br1 = CFG_BR1_PRELIM;
  225. memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  226. udelay(200);
  227. /*
  228. * Map controller SDRAM bank 1
  229. */
  230. memctl->memc_or2 = CFG_OR2_PRELIM;
  231. memctl->memc_br2 = CFG_BR2_PRELIM;
  232. /*
  233. * Perform SDRAM initializsation sequence
  234. */
  235. memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
  236. udelay(1);
  237. memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - execute twice */
  238. udelay(1);
  239. memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */
  240. udelay(1);
  241. memctl->memc_mcr = 0x80004230; /* SDRAM bank 1 - execute twice */
  242. udelay(1);
  243. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  244. udelay (1000);
  245. /*
  246. * Preliminary prescaler for refresh (depends on number of
  247. * banks): This value is selected for four cycles every 62.4 us
  248. * with two SDRAM banks or four cycles every 31.2 us with one
  249. * bank. It will be adjusted after memory sizing.
  250. */
  251. memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
  252. memctl->memc_mar = 0x00000088;
  253. /*
  254. * Check Bank 0 Memory Size for re-configuration
  255. *
  256. * try 8 column mode
  257. */
  258. size8 = dram_size (CFG_MAMR_8COL, (ulong *)SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE);
  259. udelay (1000);
  260. /*
  261. * try 9 column mode
  262. */
  263. size9 = dram_size (CFG_MAMR_9COL, (ulong *)SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE);
  264. if (size8 < size9) { /* leave configuration at 9 columns */
  265. size_b0 = size9;
  266. /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
  267. } else { /* back to 8 columns */
  268. size_b0 = size8;
  269. memctl->memc_mamr = CFG_MAMR_8COL;
  270. udelay(500);
  271. /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
  272. }
  273. /*
  274. * Check Bank 1 Memory Size
  275. * use current column settings
  276. * [9 column SDRAM may also be used in 8 column mode,
  277. * but then only half the real size will be used.]
  278. */
  279. size_b1 = dram_size (memctl->memc_mamr, (ulong *)SDRAM_BASE2_PRELIM,
  280. SDRAM_MAX_SIZE);
  281. /* debug ("SDRAM Bank 1: %ld MB\n", size8 >> 20); */
  282. udelay (1000);
  283. /*
  284. * Adjust refresh rate depending on SDRAM type, both banks
  285. * For types > 128 MBit leave it at the current (fast) rate
  286. */
  287. if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
  288. /* reduce to 15.6 us (62.4 us / quad) */
  289. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  290. udelay(1000);
  291. }
  292. /*
  293. * Final mapping: map bigger bank first
  294. */
  295. if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
  296. memctl->memc_or2 = ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  297. memctl->memc_br2 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  298. if (size_b0 > 0) {
  299. /*
  300. * Position Bank 0 immediately above Bank 1
  301. */
  302. memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  303. memctl->memc_br1 = ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  304. + size_b1;
  305. } else {
  306. unsigned long reg;
  307. /*
  308. * No bank 0
  309. *
  310. * invalidate bank
  311. */
  312. memctl->memc_br1 = 0;
  313. /* adjust refresh rate depending on SDRAM type, one bank */
  314. reg = memctl->memc_mptpr;
  315. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  316. memctl->memc_mptpr = reg;
  317. }
  318. } else { /* SDRAM Bank 0 is bigger - map first */
  319. memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  320. memctl->memc_br1 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  321. if (size_b1 > 0) {
  322. /*
  323. * Position Bank 1 immediately above Bank 0
  324. */
  325. memctl->memc_or2 = ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  326. memctl->memc_br2 = ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  327. + size_b0;
  328. } else {
  329. unsigned long reg;
  330. /*
  331. * No bank 1
  332. *
  333. * invalidate bank
  334. */
  335. memctl->memc_br2 = 0;
  336. /* adjust refresh rate depending on SDRAM type, one bank */
  337. reg = memctl->memc_mptpr;
  338. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  339. memctl->memc_mptpr = reg;
  340. }
  341. }
  342. udelay(10000);
  343. return (size_b0 + size_b1);
  344. }
  345. /* ------------------------------------------------------------------------- */
  346. /*
  347. * Check memory range for valid RAM. A simple memory test determines
  348. * the actually available RAM size between addresses `base' and
  349. * `base + maxsize'. Some (not all) hardware errors are detected:
  350. * - short between address lines
  351. * - short between data lines
  352. */
  353. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  354. {
  355. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  356. volatile memctl8xx_t *memctl = &immap->im_memctl;
  357. volatile long int *addr;
  358. long int cnt, val;
  359. memctl->memc_mamr = mamr_value;
  360. for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
  361. addr = base + cnt; /* pointer arith! */
  362. *addr = ~cnt;
  363. }
  364. /* write 0 to base address */
  365. addr = base;
  366. *addr = 0;
  367. /* check at base address */
  368. if ((val = *addr) != 0) {
  369. return (0);
  370. }
  371. for (cnt = 1; ; cnt <<= 1) {
  372. addr = base + cnt; /* pointer arith! */
  373. val = *addr;
  374. if (val != (~cnt)) {
  375. return (cnt * sizeof(long));
  376. }
  377. }
  378. /* NOTREACHED */
  379. }
  380. u_long *my_sernum;
  381. int misc_init_r (void)
  382. {
  383. DECLARE_GLOBAL_DATA_PTR;
  384. char tmp[50];
  385. u_char *e = gd->bd->bi_enetaddr;
  386. /* save serial numbre from flash (uniquely programmed) */
  387. my_sernum = malloc(8);
  388. memcpy(my_sernum,gd->bd->bi_sernum,8);
  389. /* save env variables according to sernum */
  390. sprintf(tmp,"%08lx%08lx",my_sernum[0],my_sernum[1]);
  391. setenv("serial#",tmp);
  392. sprintf(tmp,"%02x:%02x:%02x:%02x:%02x:%02x"
  393. ,e[0],e[1],e[2],e[3],e[4],e[5]);
  394. setenv("ethaddr",tmp);
  395. return (0);
  396. }
  397. void load_sernum_ethaddr (void)
  398. {
  399. DECLARE_GLOBAL_DATA_PTR;
  400. int i;
  401. bd_t * bd = gd->bd;
  402. for (i = 0; i < 8; i++) {
  403. bd->bi_sernum[i] = *(u_char *) (CFG_FLASH_SN_BASE + i);
  404. }
  405. bd->bi_enetaddr[0] = 0x10;
  406. bd->bi_enetaddr[1] = 0x20;
  407. bd->bi_enetaddr[2] = 0x30;
  408. bd->bi_enetaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2];
  409. bd->bi_enetaddr[4] = bd->bi_sernum[5];
  410. bd->bi_enetaddr[5] = bd->bi_sernum[6];
  411. }