tqm8xx.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * (C) Copyright 2000-2006
  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. #if 0
  24. #define DEBUG
  25. #endif
  26. #include <common.h>
  27. #include <mpc8xx.h>
  28. #ifdef CONFIG_PS2MULT
  29. #include <ps2mult.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. static long int dram_size (long int, long int *, long int);
  33. #define _NOT_USED_ 0xFFFFFFFF
  34. /* UPM initialization table for SDRAM: 40, 50, 66 MHz CLKOUT @ CAS latency 2, tWR=2 */
  35. const uint sdram_table[] =
  36. {
  37. /*
  38. * Single Read. (Offset 0 in UPMA RAM)
  39. */
  40. 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
  41. 0x1FF5FC47, /* last */
  42. /*
  43. * SDRAM Initialization (offset 5 in UPMA RAM)
  44. *
  45. * This is no UPM entry point. The following definition uses
  46. * the remaining space to establish an initialization
  47. * sequence, which is executed by a RUN command.
  48. *
  49. */
  50. 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
  51. /*
  52. * Burst Read. (Offset 8 in UPMA RAM)
  53. */
  54. 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
  55. 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
  56. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  57. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  58. /*
  59. * Single Write. (Offset 18 in UPMA RAM)
  60. */
  61. 0x1F0DFC04, 0xEEABBC00, 0x11B77C04, 0xEFFAFC44,
  62. 0x1FF5FC47, /* last */
  63. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  64. /*
  65. * Burst Write. (Offset 20 in UPMA RAM)
  66. */
  67. 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
  68. 0xF0AFFC00, 0xF0AFFC04, 0xE1BAFC44, 0x1FF5FC47, /* last */
  69. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  70. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  71. /*
  72. * Refresh (Offset 30 in UPMA RAM)
  73. */
  74. 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  75. 0xFFFFFC84, 0xFFFFFC07, /* last */
  76. _NOT_USED_, _NOT_USED_,
  77. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  78. /*
  79. * Exception. (Offset 3c in UPMA RAM)
  80. */
  81. 0xFFFFFC07, /* last */
  82. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  83. };
  84. /* ------------------------------------------------------------------------- */
  85. /*
  86. * Check Board Identity:
  87. *
  88. * Test TQ ID string (TQM8xx...)
  89. * If present, check for "L" type (no second DRAM bank),
  90. * otherwise "L" type is assumed as default.
  91. *
  92. * Set board_type to 'L' for "L" type, 'M' for "M" type, 0 else.
  93. */
  94. int checkboard (void)
  95. {
  96. char *s = getenv ("serial#");
  97. puts ("Board: ");
  98. if (!s || strncmp (s, "TQM8", 4)) {
  99. puts ("### No HW ID - assuming TQM8xxL\n");
  100. return (0);
  101. }
  102. if ((*(s + 6) == 'L')) { /* a TQM8xxL type */
  103. gd->board_type = 'L';
  104. }
  105. if ((*(s + 6) == 'M')) { /* a TQM8xxM type */
  106. gd->board_type = 'M';
  107. }
  108. if ((*(s + 6) == 'D')) { /* a TQM885D type */
  109. gd->board_type = 'D';
  110. }
  111. for (; *s; ++s) {
  112. if (*s == ' ')
  113. break;
  114. putc (*s);
  115. }
  116. #ifdef CONFIG_VIRTLAB2
  117. puts (" (Virtlab2)");
  118. #endif
  119. putc ('\n');
  120. return (0);
  121. }
  122. /* ------------------------------------------------------------------------- */
  123. long int initdram (int board_type)
  124. {
  125. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  126. volatile memctl8xx_t *memctl = &immap->im_memctl;
  127. long int size8, size9, size10;
  128. long int size_b0 = 0;
  129. long int size_b1 = 0;
  130. upmconfig (UPMA, (uint *) sdram_table,
  131. sizeof (sdram_table) / sizeof (uint));
  132. /*
  133. * Preliminary prescaler for refresh (depends on number of
  134. * banks): This value is selected for four cycles every 62.4 us
  135. * with two SDRAM banks or four cycles every 31.2 us with one
  136. * bank. It will be adjusted after memory sizing.
  137. */
  138. memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
  139. /*
  140. * The following value is used as an address (i.e. opcode) for
  141. * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
  142. * the port size is 32bit the SDRAM does NOT "see" the lower two
  143. * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
  144. * MICRON SDRAMs:
  145. * -> 0 00 010 0 010
  146. * | | | | +- Burst Length = 4
  147. * | | | +----- Burst Type = Sequential
  148. * | | +------- CAS Latency = 2
  149. * | +----------- Operating Mode = Standard
  150. * +-------------- Write Burst Mode = Programmed Burst Length
  151. */
  152. memctl->memc_mar = 0x00000088;
  153. /*
  154. * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
  155. * preliminary addresses - these have to be modified after the
  156. * SDRAM size has been determined.
  157. */
  158. memctl->memc_or2 = CFG_OR2_PRELIM;
  159. memctl->memc_br2 = CFG_BR2_PRELIM;
  160. #ifndef CONFIG_CAN_DRIVER
  161. if ((board_type != 'L') &&
  162. (board_type != 'M') &&
  163. (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
  164. memctl->memc_or3 = CFG_OR3_PRELIM;
  165. memctl->memc_br3 = CFG_BR3_PRELIM;
  166. }
  167. #endif /* CONFIG_CAN_DRIVER */
  168. memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  169. udelay (200);
  170. /* perform SDRAM initializsation sequence */
  171. memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
  172. udelay (1);
  173. memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
  174. udelay (1);
  175. #ifndef CONFIG_CAN_DRIVER
  176. if ((board_type != 'L') &&
  177. (board_type != 'M') &&
  178. (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
  179. memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
  180. udelay (1);
  181. memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */
  182. udelay (1);
  183. }
  184. #endif /* CONFIG_CAN_DRIVER */
  185. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  186. udelay (1000);
  187. /*
  188. * Check Bank 0 Memory Size for re-configuration
  189. *
  190. * try 8 column mode
  191. */
  192. size8 = dram_size (CFG_MAMR_8COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  193. debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size8 >> 20);
  194. udelay (1000);
  195. /*
  196. * try 9 column mode
  197. */
  198. size9 = dram_size (CFG_MAMR_9COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  199. debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size9 >> 20);
  200. udelay(1000);
  201. #if defined(CFG_MAMR_10COL)
  202. /*
  203. * try 10 column mode
  204. */
  205. size10 = dram_size (CFG_MAMR_10COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  206. debug ("SDRAM Bank 0 in 10 column mode: %ld MB\n", size10 >> 20);
  207. #else
  208. size10 = 0;
  209. #endif /* CFG_MAMR_10COL */
  210. if ((size8 < size10) && (size9 < size10)) {
  211. size_b0 = size10;
  212. } else if ((size8 < size9) && (size10 < size9)) {
  213. size_b0 = size9;
  214. memctl->memc_mamr = CFG_MAMR_9COL;
  215. udelay (500);
  216. } else {
  217. size_b0 = size8;
  218. memctl->memc_mamr = CFG_MAMR_8COL;
  219. udelay (500);
  220. }
  221. debug ("SDRAM Bank 0: %ld MB\n", size_b0 >> 20);
  222. #ifndef CONFIG_CAN_DRIVER
  223. if ((board_type != 'L') &&
  224. (board_type != 'M') &&
  225. (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
  226. /*
  227. * Check Bank 1 Memory Size
  228. * use current column settings
  229. * [9 column SDRAM may also be used in 8 column mode,
  230. * but then only half the real size will be used.]
  231. */
  232. size_b1 = dram_size (memctl->memc_mamr, (long int *)SDRAM_BASE3_PRELIM,
  233. SDRAM_MAX_SIZE);
  234. debug ("SDRAM Bank 1: %ld MB\n", size_b1 >> 20);
  235. } else {
  236. size_b1 = 0;
  237. }
  238. #endif /* CONFIG_CAN_DRIVER */
  239. udelay (1000);
  240. /*
  241. * Adjust refresh rate depending on SDRAM type, both banks
  242. * For types > 128 MBit leave it at the current (fast) rate
  243. */
  244. if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
  245. /* reduce to 15.6 us (62.4 us / quad) */
  246. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  247. udelay (1000);
  248. }
  249. /*
  250. * Final mapping: map bigger bank first
  251. */
  252. if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
  253. memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  254. memctl->memc_br3 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  255. if (size_b0 > 0) {
  256. /*
  257. * Position Bank 0 immediately above Bank 1
  258. */
  259. memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  260. memctl->memc_br2 = ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  261. + size_b1;
  262. } else {
  263. unsigned long reg;
  264. /*
  265. * No bank 0
  266. *
  267. * invalidate bank
  268. */
  269. memctl->memc_br2 = 0;
  270. /* adjust refresh rate depending on SDRAM type, one bank */
  271. reg = memctl->memc_mptpr;
  272. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  273. memctl->memc_mptpr = reg;
  274. }
  275. } else { /* SDRAM Bank 0 is bigger - map first */
  276. memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  277. memctl->memc_br2 =
  278. (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  279. if (size_b1 > 0) {
  280. /*
  281. * Position Bank 1 immediately above Bank 0
  282. */
  283. memctl->memc_or3 =
  284. ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  285. memctl->memc_br3 =
  286. ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  287. + size_b0;
  288. } else {
  289. unsigned long reg;
  290. #ifndef CONFIG_CAN_DRIVER
  291. /*
  292. * No bank 1
  293. *
  294. * invalidate bank
  295. */
  296. memctl->memc_br3 = 0;
  297. #endif /* CONFIG_CAN_DRIVER */
  298. /* adjust refresh rate depending on SDRAM type, one bank */
  299. reg = memctl->memc_mptpr;
  300. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  301. memctl->memc_mptpr = reg;
  302. }
  303. }
  304. udelay (10000);
  305. #ifdef CONFIG_CAN_DRIVER
  306. /* UPM initialization for CAN @ CLKOUT <= 66 MHz */
  307. /* Initialize OR3 / BR3 */
  308. memctl->memc_or3 = CFG_OR3_CAN;
  309. memctl->memc_br3 = CFG_BR3_CAN;
  310. /* Initialize MBMR */
  311. memctl->memc_mbmr = MBMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */
  312. /* Initialize UPMB for CAN: single read */
  313. memctl->memc_mdr = 0xFFFFCC04;
  314. memctl->memc_mcr = 0x0100 | UPMB;
  315. memctl->memc_mdr = 0x0FFFD004;
  316. memctl->memc_mcr = 0x0101 | UPMB;
  317. memctl->memc_mdr = 0x0FFFC000;
  318. memctl->memc_mcr = 0x0102 | UPMB;
  319. memctl->memc_mdr = 0x3FFFC004;
  320. memctl->memc_mcr = 0x0103 | UPMB;
  321. memctl->memc_mdr = 0xFFFFDC07;
  322. memctl->memc_mcr = 0x0104 | UPMB;
  323. /* Initialize UPMB for CAN: single write */
  324. memctl->memc_mdr = 0xFFFCCC04;
  325. memctl->memc_mcr = 0x0118 | UPMB;
  326. memctl->memc_mdr = 0xCFFCDC04;
  327. memctl->memc_mcr = 0x0119 | UPMB;
  328. memctl->memc_mdr = 0x3FFCC000;
  329. memctl->memc_mcr = 0x011A | UPMB;
  330. memctl->memc_mdr = 0xFFFCC004;
  331. memctl->memc_mcr = 0x011B | UPMB;
  332. memctl->memc_mdr = 0xFFFDC405;
  333. memctl->memc_mcr = 0x011C | UPMB;
  334. #endif /* CONFIG_CAN_DRIVER */
  335. #ifdef CONFIG_ISP1362_USB
  336. /* Initialize OR5 / BR5 */
  337. memctl->memc_or5 = CFG_OR5_ISP1362;
  338. memctl->memc_br5 = CFG_BR5_ISP1362;
  339. #endif /* CONFIG_ISP1362_USB */
  340. return (size_b0 + size_b1);
  341. }
  342. /* ------------------------------------------------------------------------- */
  343. /*
  344. * Check memory range for valid RAM. A simple memory test determines
  345. * the actually available RAM size between addresses `base' and
  346. * `base + maxsize'. Some (not all) hardware errors are detected:
  347. * - short between address lines
  348. * - short between data lines
  349. */
  350. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  351. {
  352. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  353. volatile memctl8xx_t *memctl = &immap->im_memctl;
  354. memctl->memc_mamr = mamr_value;
  355. return (get_ram_size(base, maxsize));
  356. }
  357. /* ------------------------------------------------------------------------- */
  358. #ifdef CONFIG_PS2MULT
  359. #ifdef CONFIG_HMI10
  360. #define BASE_BAUD ( 1843200 / 16 )
  361. struct serial_state rs_table[] = {
  362. { BASE_BAUD, 4, (void*)0xec140000 },
  363. { BASE_BAUD, 2, (void*)0xec150000 },
  364. { BASE_BAUD, 6, (void*)0xec160000 },
  365. { BASE_BAUD, 10, (void*)0xec170000 },
  366. };
  367. #ifdef CONFIG_BOARD_EARLY_INIT_R
  368. int board_early_init_r (void)
  369. {
  370. ps2mult_early_init();
  371. return (0);
  372. }
  373. #endif
  374. #endif /* CONFIG_HMI10 */
  375. #endif /* CONFIG_PS2MULT */
  376. /* ---------------------------------------------------------------------------- */
  377. /* HMI10 specific stuff */
  378. /* ---------------------------------------------------------------------------- */
  379. #ifdef CONFIG_HMI10
  380. int misc_init_r (void)
  381. {
  382. # ifdef CONFIG_IDE_LED
  383. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  384. /* Configure PA15 as output port */
  385. immap->im_ioport.iop_padir |= 0x0001;
  386. immap->im_ioport.iop_paodr |= 0x0001;
  387. immap->im_ioport.iop_papar &= ~0x0001;
  388. immap->im_ioport.iop_padat &= ~0x0001; /* turn it off */
  389. # endif
  390. return (0);
  391. }
  392. # ifdef CONFIG_IDE_LED
  393. void ide_led (uchar led, uchar status)
  394. {
  395. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  396. /* We have one led for both pcmcia slots */
  397. if (status) { /* led on */
  398. immap->im_ioport.iop_padat |= 0x0001;
  399. } else {
  400. immap->im_ioport.iop_padat &= ~0x0001;
  401. }
  402. }
  403. # endif
  404. #endif /* CONFIG_HMI10 */
  405. /* ---------------------------------------------------------------------------- */
  406. /* NSCU specific stuff */
  407. /* ---------------------------------------------------------------------------- */
  408. #ifdef CONFIG_NSCU
  409. int misc_init_r (void)
  410. {
  411. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  412. /* wake up ethernet module */
  413. immr->im_ioport.iop_pcpar &= ~0x0004; /* GPIO pin */
  414. immr->im_ioport.iop_pcdir |= 0x0004; /* output */
  415. immr->im_ioport.iop_pcso &= ~0x0004; /* for clarity */
  416. immr->im_ioport.iop_pcdat |= 0x0004; /* enable */
  417. return (0);
  418. }
  419. #endif /* CONFIG_NSCU */
  420. /* ------------------------------------------------------------------------- */