genietv.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * genietv/genietv.c
  3. *
  4. * The GENIETV is using the following physical memorymap (copied from
  5. * the FADS configuration):
  6. *
  7. * ff020000 -> ff02ffff : pcmcia
  8. * ff010000 -> ff01ffff : BCSR connected to CS1, setup by 8xxROM
  9. * ff000000 -> ff00ffff : IMAP internal in the cpu
  10. * 02800000 -> 0287ffff : flash connected to CS0
  11. * 00000000 -> nnnnnnnn : sdram setup by U-Boot
  12. *
  13. * CS pins are connected as follows:
  14. *
  15. * CS0 -512Kb boot flash
  16. * CS1 - SDRAM #1
  17. * CS2 - SDRAM #2
  18. * CS3 - Flash #1
  19. * CS4 - Flash #2
  20. * CS5 - LON (if present)
  21. * CS6 - PCMCIA #1
  22. * CS7 - PCMCIA #2
  23. *
  24. * Ports are configured as follows:
  25. *
  26. * PA7 - SDRAM banks enable
  27. */
  28. #include <common.h>
  29. #include <mpc8xx.h>
  30. #define CFG_PA7 0x0100
  31. /* ------------------------------------------------------------------------- */
  32. static long int dram_size (long int, long int *, long int);
  33. /* ------------------------------------------------------------------------- */
  34. #define _NOT_USED_ 0xFFFFFFFF
  35. const uint sdram_table[] = {
  36. /*
  37. * Single Read. (Offset 0 in UPMB RAM)
  38. */
  39. 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBEEC00,
  40. 0x1FFDDC47, /* last */
  41. /*
  42. * SDRAM Initialization (offset 5 in UPMB RAM)
  43. *
  44. * This is no UPM entry point. The following definition uses
  45. * the remaining space to establish an initialization
  46. * sequence, which is executed by a RUN command.
  47. *
  48. */
  49. 0x1FFDDC34, 0xEFEEAC34, 0x1FBD5C35, /* last */
  50. /*
  51. * Burst Read. (Offset 8 in UPMB RAM)
  52. */
  53. 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
  54. 0xF0AFFC00, 0xF1AFFC00, 0xEFBEEC00, 0x1FFDDC47, /* last */
  55. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  56. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  57. /*
  58. * Single Write. (Offset 18 in UPMB RAM)
  59. */
  60. 0x1F2DFC04, 0xEEAFAC00, 0x01BE4C04, 0x1FFDDC47, /* last */
  61. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  62. /*
  63. * Burst Write. (Offset 20 in UPMB RAM)
  64. */
  65. 0x1F0DFC04, 0xEEAFAC00, 0x10AF5C00, 0xF0AFFC00,
  66. 0xF0AFFC00, 0xE1BEEC04, 0x1FFDDC47, /* last */
  67. _NOT_USED_,
  68. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  69. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  70. /*
  71. * Refresh (Offset 30 in UPMB RAM)
  72. */
  73. 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  74. 0xFFFFFC84, 0xFFFFFC07, /* last */
  75. _NOT_USED_, _NOT_USED_,
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  77. /*
  78. * Exception. (Offset 3c in UPMB RAM)
  79. */
  80. 0x7FFFFC07, /* last */
  81. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  82. };
  83. /* ------------------------------------------------------------------------- */
  84. /*
  85. * Check Board Identity
  86. */
  87. int checkboard (void)
  88. {
  89. puts ("Board: GenieTV\n");
  90. return 0;
  91. }
  92. #if 0
  93. static void PrintState (void)
  94. {
  95. volatile immap_t *im = (immap_t *) CFG_IMMR;
  96. volatile memctl8xx_t *memctl = &im->im_memctl;
  97. printf ("\n0 - FLASH: B=%08x O=%08x", memctl->memc_br0,
  98. memctl->memc_or0);
  99. printf ("\n1 - SDRAM: B=%08x O=%08x", memctl->memc_br1,
  100. memctl->memc_or1);
  101. printf ("\n2 - SDRAM: B=%08x O=%08x", memctl->memc_br2,
  102. memctl->memc_or2);
  103. }
  104. #endif
  105. /* ------------------------------------------------------------------------- */
  106. long int initdram (int board_type)
  107. {
  108. volatile immap_t *im = (immap_t *) CFG_IMMR;
  109. volatile memctl8xx_t *memctl = &im->im_memctl;
  110. long int size_b0, size_b1, size8;
  111. /* Enable SDRAM */
  112. /* Configuring PA7 for general purpouse output pin */
  113. im->im_ioport.iop_papar &= ~CFG_PA7; /* 0 = general purpouse */
  114. im->im_ioport.iop_padir |= CFG_PA7; /* 1 = output */
  115. /* Enable SDRAM - PA7 = 1 */
  116. im->im_ioport.iop_padat |= CFG_PA7; /* value of PA7 */
  117. /*
  118. * Preliminary prescaler for refresh (depends on number of
  119. * banks): This value is selected for four cycles every 62.4 us
  120. * with two SDRAM banks or four cycles every 31.2 us with one
  121. * bank. It will be adjusted after memory sizing.
  122. */
  123. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  124. memctl->memc_mbmr = CFG_MBMR_8COL;
  125. upmconfig (UPMB, (uint *) sdram_table,
  126. sizeof (sdram_table) / sizeof (uint));
  127. /*
  128. * Map controller banks 1 and 2 to the SDRAM banks 1 and 2 at
  129. * preliminary addresses - these have to be modified after the
  130. * SDRAM size has been determined.
  131. */
  132. memctl->memc_or1 = 0xF0000000 | CFG_OR_TIMING_SDRAM;
  133. memctl->memc_br1 =
  134. ((SDRAM_BASE1_PRELIM & BR_BA_MSK) | BR_MS_UPMB | BR_V);
  135. memctl->memc_or2 = 0xF0000000 | CFG_OR_TIMING_SDRAM;
  136. memctl->memc_br2 =
  137. ((SDRAM_BASE2_PRELIM & BR_BA_MSK) | BR_MS_UPMB | BR_V);
  138. /* perform SDRAM initialization sequence */
  139. memctl->memc_mar = 0x00000088;
  140. memctl->memc_mcr = 0x80802105; /* SDRAM bank 0 */
  141. memctl->memc_mcr = 0x80804105; /* SDRAM bank 1 */
  142. /* Execute refresh 8 times */
  143. memctl->memc_mbmr = (CFG_MBMR_8COL & ~MBMR_TLFB_MSK) | MBMR_TLFB_8X;
  144. memctl->memc_mcr = 0x80802130; /* SDRAM bank 0 - execute twice */
  145. memctl->memc_mcr = 0x80804130; /* SDRAM bank 1 - execute twice */
  146. /* Execute refresh 4 times */
  147. memctl->memc_mbmr = CFG_MBMR_8COL;
  148. /*
  149. * Check Bank 0 Memory Size for re-configuration
  150. *
  151. * try 8 column mode
  152. */
  153. #if 0
  154. PrintState ();
  155. #endif
  156. /* printf ("\nChecking bank1..."); */
  157. size8 = dram_size (CFG_MBMR_8COL, (long *) SDRAM_BASE1_PRELIM,
  158. SDRAM_MAX_SIZE);
  159. size_b0 = size8;
  160. /* printf ("\nChecking bank2..."); */
  161. size_b1 =
  162. dram_size (memctl->memc_mbmr, (long *) SDRAM_BASE2_PRELIM,
  163. SDRAM_MAX_SIZE);
  164. /*
  165. * Final mapping: map bigger bank first
  166. */
  167. memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  168. memctl->memc_br1 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMB | BR_V;
  169. if (size_b1 > 0) {
  170. /*
  171. * Position Bank 1 immediately above Bank 0
  172. */
  173. memctl->memc_or2 =
  174. ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  175. memctl->memc_br2 =
  176. ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMB | BR_V) +
  177. (size_b0 & BR_BA_MSK);
  178. } else {
  179. /*
  180. * No bank 1
  181. *
  182. * invalidate bank
  183. */
  184. memctl->memc_br2 = 0;
  185. /* adjust refresh rate depending on SDRAM type, one bank */
  186. memctl->memc_mptpr = CFG_MPTPR_1BK_4K;
  187. }
  188. /* If no memory detected, disable SDRAM */
  189. if ((size_b0 + size_b1) == 0) {
  190. printf ("disabling SDRAM!\n");
  191. /* Disable SDRAM - PA7 = 1 */
  192. im->im_ioport.iop_padat &= ~CFG_PA7; /* value of PA7 */
  193. }
  194. /* else */
  195. /* printf("done! (%08lx)\n", size_b0 + size_b1); */
  196. #if 0
  197. PrintState ();
  198. #endif
  199. return (size_b0 + size_b1);
  200. }
  201. /* ------------------------------------------------------------------------- */
  202. /*
  203. * Check memory range for valid RAM. A simple memory test determines
  204. * the actually available RAM size between addresses `base' and
  205. * `base + maxsize'. Some (not all) hardware errors are detected:
  206. * - short between address lines
  207. * - short between data lines
  208. */
  209. static long int dram_size (long int mbmr_value, long int *base,
  210. long int maxsize)
  211. {
  212. long size;
  213. /*memctl->memc_mbmr = mbmr_value; */
  214. size = get_ram_size (base, maxsize);
  215. if (size) {
  216. /* printf("(%08lx)", size); */
  217. } else {
  218. printf ("(0)");
  219. }
  220. return (size);
  221. }
  222. #if defined(CONFIG_CMD_PCMCIA)
  223. #ifdef CFG_PCMCIA_MEM_ADDR
  224. volatile unsigned char *pcmcia_mem = (unsigned char *) CFG_PCMCIA_MEM_ADDR;
  225. #endif
  226. int pcmcia_init (void)
  227. {
  228. volatile pcmconf8xx_t *pcmp;
  229. uint v, slota, slotb;
  230. /*
  231. ** Enable the PCMCIA for a Flash card.
  232. */
  233. pcmp = (pcmconf8xx_t *) (&(((immap_t *) CFG_IMMR)->im_pcmcia));
  234. #if 0
  235. pcmp->pcmc_pbr0 = CFG_PCMCIA_MEM_ADDR;
  236. pcmp->pcmc_por0 = 0xc00ff05d;
  237. #endif
  238. /* Set all slots to zero by default. */
  239. pcmp->pcmc_pgcra = 0;
  240. pcmp->pcmc_pgcrb = 0;
  241. #ifdef PCMCIA_SLOT_A
  242. pcmp->pcmc_pgcra = 0x40;
  243. #endif
  244. #ifdef PCMCIA_SLOT_B
  245. pcmp->pcmc_pgcrb = 0x40;
  246. #endif
  247. /* Check if any PCMCIA card is luged in. */
  248. slota = (pcmp->pcmc_pipr & 0x18000000) == 0;
  249. slotb = (pcmp->pcmc_pipr & 0x00001800) == 0;
  250. if (!(slota || slotb)) {
  251. printf ("No card present\n");
  252. #ifdef PCMCIA_SLOT_A
  253. pcmp->pcmc_pgcra = 0;
  254. #endif
  255. #ifdef PCMCIA_SLOT_B
  256. pcmp->pcmc_pgcrb = 0;
  257. #endif
  258. return -1;
  259. } else
  260. printf ("Unknown card (");
  261. v = 0;
  262. switch ((pcmp->pcmc_pipr >> 14) & 3) {
  263. case 0x00:
  264. printf ("5V");
  265. v = 5;
  266. break;
  267. case 0x01:
  268. printf ("5V and 3V");
  269. v = 3;
  270. break;
  271. case 0x03:
  272. printf ("5V, 3V and x.xV");
  273. v = 3;
  274. break;
  275. }
  276. switch (v) {
  277. case 3:
  278. printf ("; using 3V");
  279. /* Enable 3 volt Vcc. */
  280. break;
  281. default:
  282. printf ("; unknown voltage");
  283. return -1;
  284. }
  285. printf (")\n");
  286. /* disable pcmcia reset after a while */
  287. udelay (20);
  288. pcmp->pcmc_pgcrb = 0;
  289. /* If you using a real hd you should give a short
  290. * spin-up time. */
  291. #ifdef CONFIG_DISK_SPINUP_TIME
  292. udelay (CONFIG_DISK_SPINUP_TIME);
  293. #endif
  294. return 0;
  295. }
  296. #endif