tqm8xx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. * (C) Copyright 2000, 2001, 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc8xx.h>
  25. /* ------------------------------------------------------------------------- */
  26. static long int dram_size (long int, long int *, long int);
  27. /* ------------------------------------------------------------------------- */
  28. #define _NOT_USED_ 0xFFFFFFFF
  29. const uint sdram_table[] =
  30. {
  31. /*
  32. * Single Read. (Offset 0 in UPMA RAM)
  33. */
  34. 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
  35. 0x1FF5FC47, /* last */
  36. /*
  37. * SDRAM Initialization (offset 5 in UPMA RAM)
  38. *
  39. * This is no UPM entry point. The following definition uses
  40. * the remaining space to establish an initialization
  41. * sequence, which is executed by a RUN command.
  42. *
  43. */
  44. 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
  45. /*
  46. * Burst Read. (Offset 8 in UPMA RAM)
  47. */
  48. 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
  49. 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
  50. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  51. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  52. /*
  53. * Single Write. (Offset 18 in UPMA RAM)
  54. */
  55. 0x1F0DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
  56. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  57. /*
  58. * Burst Write. (Offset 20 in UPMA RAM)
  59. */
  60. 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
  61. 0xF0AFFC00, 0xE1BAFC04, 0x1FF5FC47, /* last */
  62. _NOT_USED_,
  63. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  64. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  65. /*
  66. * Refresh (Offset 30 in UPMA RAM)
  67. */
  68. 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  69. 0xFFFFFC84, 0xFFFFFC07, /* last */
  70. _NOT_USED_, _NOT_USED_,
  71. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  72. /*
  73. * Exception. (Offset 3c in UPMA RAM)
  74. */
  75. 0x7FFFFC07, /* last */
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  77. };
  78. /* ------------------------------------------------------------------------- */
  79. /*
  80. * Check Board Identity:
  81. *
  82. * Test TQ ID string (TQM8xx...)
  83. * If present, check for "L" type (no second DRAM bank),
  84. * otherwise "L" type is assumed as default.
  85. *
  86. * Set board_type to 'L' for "L" type, 0 else.
  87. */
  88. int checkboard (void)
  89. {
  90. DECLARE_GLOBAL_DATA_PTR;
  91. unsigned char *s = getenv ("serial#");
  92. puts ("Board: ");
  93. if (!s || strncmp (s, "TQM8", 4)) {
  94. puts ("### No HW ID - assuming TQM8xxL\n");
  95. return (0);
  96. }
  97. if ((*(s + 6) == 'L')) { /* a TQM8xxL type */
  98. gd->board_type = 'L';
  99. }
  100. for (; *s; ++s) {
  101. if (*s == ' ')
  102. break;
  103. putc (*s);
  104. }
  105. putc ('\n');
  106. return (0);
  107. }
  108. /* ------------------------------------------------------------------------- */
  109. long int initdram (int board_type)
  110. {
  111. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  112. volatile memctl8xx_t *memctl = &immap->im_memctl;
  113. long int size8, size9;
  114. long int size_b0 = 0;
  115. long int size_b1 = 0;
  116. upmconfig (UPMA, (uint *) sdram_table,
  117. sizeof (sdram_table) / sizeof (uint));
  118. /*
  119. * Preliminary prescaler for refresh (depends on number of
  120. * banks): This value is selected for four cycles every 62.4 us
  121. * with two SDRAM banks or four cycles every 31.2 us with one
  122. * bank. It will be adjusted after memory sizing.
  123. */
  124. memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
  125. /*
  126. * The following value is used as an address (i.e. opcode) for
  127. * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
  128. * the port size is 32bit the SDRAM does NOT "see" the lower two
  129. * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
  130. * MICRON SDRAMs:
  131. * -> 0 00 010 0 010
  132. * | | | | +- Burst Length = 4
  133. * | | | +----- Burst Type = Sequential
  134. * | | +------- CAS Latency = 2
  135. * | +----------- Operating Mode = Standard
  136. * +-------------- Write Burst Mode = Programmed Burst Length
  137. */
  138. memctl->memc_mar = 0x00000088;
  139. /*
  140. * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
  141. * preliminary addresses - these have to be modified after the
  142. * SDRAM size has been determined.
  143. */
  144. memctl->memc_or2 = CFG_OR2_PRELIM;
  145. memctl->memc_br2 = CFG_BR2_PRELIM;
  146. #ifndef CONFIG_CAN_DRIVER
  147. if (board_type != 'L') { /* "L" type boards have only one bank SDRAM */
  148. memctl->memc_or3 = CFG_OR3_PRELIM;
  149. memctl->memc_br3 = CFG_BR3_PRELIM;
  150. }
  151. #endif /* CONFIG_CAN_DRIVER */
  152. memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  153. udelay (200);
  154. /* perform SDRAM initializsation sequence */
  155. memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
  156. udelay (1);
  157. memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
  158. udelay (1);
  159. #ifndef CONFIG_CAN_DRIVER
  160. if (board_type != 'L') { /* "L" type boards have only one bank SDRAM */
  161. memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
  162. udelay (1);
  163. memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */
  164. udelay (1);
  165. }
  166. #endif /* CONFIG_CAN_DRIVER */
  167. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  168. udelay (1000);
  169. /*
  170. * Check Bank 0 Memory Size for re-configuration
  171. *
  172. * try 8 column mode
  173. */
  174. size8 = dram_size (CFG_MAMR_8COL, (ulong *) SDRAM_BASE2_PRELIM,
  175. SDRAM_MAX_SIZE);
  176. udelay (1000);
  177. /*
  178. * try 9 column mode
  179. */
  180. size9 = dram_size (CFG_MAMR_9COL, (ulong *) SDRAM_BASE2_PRELIM,
  181. SDRAM_MAX_SIZE);
  182. if (size8 < size9) { /* leave configuration at 9 columns */
  183. size_b0 = size9;
  184. /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
  185. } else { /* back to 8 columns */
  186. size_b0 = size8;
  187. memctl->memc_mamr = CFG_MAMR_8COL;
  188. udelay (500);
  189. /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
  190. }
  191. #ifndef CONFIG_CAN_DRIVER
  192. if (board_type != 'L') { /* "L" type boards have only one bank SDRAM */
  193. /*
  194. * Check Bank 1 Memory Size
  195. * use current column settings
  196. * [9 column SDRAM may also be used in 8 column mode,
  197. * but then only half the real size will be used.]
  198. */
  199. size_b1 =
  200. dram_size (memctl->memc_mamr, (ulong *) SDRAM_BASE3_PRELIM,
  201. SDRAM_MAX_SIZE);
  202. /* debug ("SDRAM Bank 1: %ld MB\n", size8 >> 20); */
  203. } else {
  204. size_b1 = 0;
  205. }
  206. #endif /* CONFIG_CAN_DRIVER */
  207. udelay (1000);
  208. /*
  209. * Adjust refresh rate depending on SDRAM type, both banks
  210. * For types > 128 MBit leave it at the current (fast) rate
  211. */
  212. if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
  213. /* reduce to 15.6 us (62.4 us / quad) */
  214. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  215. udelay (1000);
  216. }
  217. /*
  218. * Final mapping: map bigger bank first
  219. */
  220. if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
  221. memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  222. memctl->memc_br3 =
  223. (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  224. if (size_b0 > 0) {
  225. /*
  226. * Position Bank 0 immediately above Bank 1
  227. */
  228. memctl->memc_or2 =
  229. ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  230. memctl->memc_br2 =
  231. ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  232. + size_b1;
  233. } else {
  234. unsigned long reg;
  235. /*
  236. * No bank 0
  237. *
  238. * invalidate bank
  239. */
  240. memctl->memc_br2 = 0;
  241. /* adjust refresh rate depending on SDRAM type, one bank */
  242. reg = memctl->memc_mptpr;
  243. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  244. memctl->memc_mptpr = reg;
  245. }
  246. } else { /* SDRAM Bank 0 is bigger - map first */
  247. memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  248. memctl->memc_br2 =
  249. (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  250. if (size_b1 > 0) {
  251. /*
  252. * Position Bank 1 immediately above Bank 0
  253. */
  254. memctl->memc_or3 =
  255. ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  256. memctl->memc_br3 =
  257. ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  258. + size_b0;
  259. } else {
  260. unsigned long reg;
  261. #ifndef CONFIG_CAN_DRIVER
  262. /*
  263. * No bank 1
  264. *
  265. * invalidate bank
  266. */
  267. memctl->memc_br3 = 0;
  268. #endif /* CONFIG_CAN_DRIVER */
  269. /* adjust refresh rate depending on SDRAM type, one bank */
  270. reg = memctl->memc_mptpr;
  271. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  272. memctl->memc_mptpr = reg;
  273. }
  274. }
  275. udelay (10000);
  276. #ifdef CONFIG_CAN_DRIVER
  277. /* Initialize OR3 / BR3 */
  278. memctl->memc_or3 = CFG_OR3_CAN;
  279. memctl->memc_br3 = CFG_BR3_CAN;
  280. /* Initialize MBMR */
  281. memctl->memc_mbmr = MAMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */
  282. /* Initialize UPMB for CAN: single read */
  283. memctl->memc_mdr = 0xFFFFC004;
  284. memctl->memc_mcr = 0x0100 | UPMB;
  285. memctl->memc_mdr = 0x0FFFD004;
  286. memctl->memc_mcr = 0x0101 | UPMB;
  287. memctl->memc_mdr = 0x0FFFC000;
  288. memctl->memc_mcr = 0x0102 | UPMB;
  289. memctl->memc_mdr = 0x3FFFC004;
  290. memctl->memc_mcr = 0x0103 | UPMB;
  291. memctl->memc_mdr = 0xFFFFDC05;
  292. memctl->memc_mcr = 0x0104 | UPMB;
  293. /* Initialize UPMB for CAN: single write */
  294. memctl->memc_mdr = 0xFFFCC004;
  295. memctl->memc_mcr = 0x0118 | UPMB;
  296. memctl->memc_mdr = 0xCFFCD004;
  297. memctl->memc_mcr = 0x0119 | UPMB;
  298. memctl->memc_mdr = 0x0FFCC000;
  299. memctl->memc_mcr = 0x011A | UPMB;
  300. memctl->memc_mdr = 0x7FFCC004;
  301. memctl->memc_mcr = 0x011B | UPMB;
  302. memctl->memc_mdr = 0xFFFDCC05;
  303. memctl->memc_mcr = 0x011C | UPMB;
  304. #endif /* CONFIG_CAN_DRIVER */
  305. #ifdef CONFIG_ISP1362_USB
  306. /* Initialize OR5 / BR5 */
  307. memctl->memc_or5 = CFG_OR5_ISP1362;
  308. memctl->memc_br5 = CFG_BR5_ISP1362;
  309. #endif /* CONFIG_ISP1362_USB */
  310. return (size_b0 + size_b1);
  311. }
  312. /* ------------------------------------------------------------------------- */
  313. /*
  314. * Check memory range for valid RAM. A simple memory test determines
  315. * the actually available RAM size between addresses `base' and
  316. * `base + maxsize'. Some (not all) hardware errors are detected:
  317. * - short between address lines
  318. * - short between data lines
  319. */
  320. static long int dram_size (long int mamr_value, long int *base,
  321. long int maxsize)
  322. {
  323. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  324. volatile memctl8xx_t *memctl = &immap->im_memctl;
  325. volatile long int *addr;
  326. ulong cnt, val;
  327. ulong save[32]; /* to make test non-destructive */
  328. unsigned char i = 0;
  329. memctl->memc_mamr = mamr_value;
  330. for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
  331. addr = base + cnt; /* pointer arith! */
  332. save[i++] = *addr;
  333. *addr = ~cnt;
  334. }
  335. /* write 0 to base address */
  336. addr = base;
  337. save[i] = *addr;
  338. *addr = 0;
  339. /* check at base address */
  340. if ((val = *addr) != 0) {
  341. *addr = save[i];
  342. return (0);
  343. }
  344. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  345. addr = base + cnt; /* pointer arith! */
  346. val = *addr;
  347. *addr = save[--i];
  348. if (val != (~cnt)) {
  349. return (cnt * sizeof (long));
  350. }
  351. }
  352. return (maxsize);
  353. }
  354. /* ------------------------------------------------------------------------- */