ivm.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. * (C) Copyright 2000, 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * Ulrich Lutz, Speech Design GmbH, ulutz@datalab.de.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * 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 <mpc8xx.h>
  26. #include <commproc.h>
  27. #ifdef CONFIG_STATUS_LED
  28. # include <status_led.h>
  29. #endif
  30. /* ------------------------------------------------------------------------- */
  31. static long int dram_size (long int, long int *, long int);
  32. /* ------------------------------------------------------------------------- */
  33. #define _NOT_USED_ 0xFFFFFFFF
  34. /*
  35. * 50 MHz SHARC access using UPM A
  36. */
  37. const uint sharc_table[] = {
  38. /*
  39. * Single Read. (Offset 0 in UPM RAM)
  40. */
  41. 0x0FF3FC04, 0x0FF3EC00, 0x7FFFEC04, 0xFFFFEC04,
  42. 0xFFFFEC05, /* last */
  43. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  44. /*
  45. * Burst Read. (Offset 8 in UPM RAM)
  46. */
  47. /* last */
  48. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  49. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  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 UPM RAM)
  54. */
  55. 0x0FAFFC04, 0x0FAFEC00, 0x7FFFEC04, 0xFFFFEC04,
  56. 0xFFFFEC05, /* last */
  57. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  58. /*
  59. * Burst Write. (Offset 20 in UPM RAM)
  60. */
  61. /* last */
  62. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  63. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  64. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  65. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  66. /*
  67. * Refresh (Offset 30 in UPM RAM)
  68. */
  69. /* last */
  70. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  71. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  72. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  73. /*
  74. * Exception. (Offset 3c in UPM RAM)
  75. */
  76. 0x7FFFFC07, /* last */
  77. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  78. };
  79. /*
  80. * 50 MHz SDRAM access using UPM B
  81. */
  82. const uint sdram_table[] = {
  83. /*
  84. * Single Read. (Offset 0 in UPM RAM)
  85. */
  86. 0x0E26FC04, 0x11ADFC04, 0xEFBBBC00, 0x1FF77C45, /* last */
  87. _NOT_USED_,
  88. /*
  89. * SDRAM Initialization (offset 5 in UPM RAM)
  90. *
  91. * This is no UPM entry point. The following definition uses
  92. * the remaining space to establish an initialization
  93. * sequence, which is executed by a RUN command.
  94. *
  95. */
  96. 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */
  97. /*
  98. * Burst Read. (Offset 8 in UPM RAM)
  99. */
  100. 0x0E26FC04, 0x10ADFC04, 0xF0AFFC00, 0xF0AFFC00,
  101. 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C45, /* last */
  102. _NOT_USED_,
  103. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  104. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  105. /*
  106. * Single Write. (Offset 18 in UPM RAM)
  107. */
  108. 0x1F27FC04, 0xEEAEBC04, 0x01B93C00, 0x1FF77C45, /* last */
  109. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  110. /*
  111. * Burst Write. (Offset 20 in UPM RAM)
  112. */
  113. 0x0E26BC00, 0x10AD7C00, 0xF0AFFC00, 0xF0AFFC00,
  114. 0xE1BBBC04, 0x1FF77C45, /* last */
  115. _NOT_USED_, _NOT_USED_,
  116. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  117. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  118. /*
  119. * Refresh (Offset 30 in UPM RAM)
  120. */
  121. 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC84,
  122. 0xFFFFFC05, /* last */
  123. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  124. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  125. /*
  126. * Exception. (Offset 3c in UPM RAM)
  127. */
  128. 0x7FFFFC07, /* last */
  129. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  130. };
  131. /* ------------------------------------------------------------------------- */
  132. /*
  133. * Check Board Identity:
  134. *
  135. */
  136. int checkboard (void)
  137. {
  138. #ifdef CONFIG_IVMS8
  139. puts ("Board: IVMS8\n");
  140. #endif
  141. #ifdef CONFIG_IVML24
  142. puts ("Board: IVM-L8/24\n");
  143. #endif
  144. return (0);
  145. }
  146. /* ------------------------------------------------------------------------- */
  147. long int initdram (int board_type)
  148. {
  149. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  150. volatile memctl8xx_t *memctl = &immr->im_memctl;
  151. long int size_b0;
  152. /* enable SDRAM clock ("switch on" SDRAM) */
  153. immr->im_cpm.cp_pbpar &= ~(CFG_PB_SDRAM_CLKE); /* GPIO */
  154. immr->im_cpm.cp_pbodr &= ~(CFG_PB_SDRAM_CLKE); /* active output */
  155. immr->im_cpm.cp_pbdir |= CFG_PB_SDRAM_CLKE; /* output */
  156. immr->im_cpm.cp_pbdat |= CFG_PB_SDRAM_CLKE; /* assert SDRAM CLKE */
  157. udelay (1);
  158. /*
  159. * Map controller bank 1 for ELIC SACCO
  160. */
  161. memctl->memc_or1 = CFG_OR1;
  162. memctl->memc_br1 = CFG_BR1;
  163. /*
  164. * Map controller bank 2 for ELIC EPIC
  165. */
  166. memctl->memc_or2 = CFG_OR2;
  167. memctl->memc_br2 = CFG_BR2;
  168. /*
  169. * Configure UPMA for SHARC
  170. */
  171. upmconfig (UPMA, (uint *) sharc_table,
  172. sizeof (sharc_table) / sizeof (uint));
  173. #if defined(CONFIG_IVML24)
  174. /*
  175. * Map controller bank 4 for HDLC Address space
  176. */
  177. memctl->memc_or4 = CFG_OR4;
  178. memctl->memc_br4 = CFG_BR4;
  179. #endif
  180. /*
  181. * Map controller bank 5 for SHARC
  182. */
  183. memctl->memc_or5 = CFG_OR5;
  184. memctl->memc_br5 = CFG_BR5;
  185. memctl->memc_mamr = 0x00001000;
  186. /*
  187. * Configure UPMB for SDRAM
  188. */
  189. upmconfig (UPMB, (uint *) sdram_table,
  190. sizeof (sdram_table) / sizeof (uint));
  191. memctl->memc_mptpr = CFG_MPTPR_1BK_8K;
  192. memctl->memc_mar = 0x00000088;
  193. /*
  194. * Map controller bank 3 to the SDRAM bank at preliminary address.
  195. */
  196. memctl->memc_or3 = CFG_OR3_PRELIM;
  197. memctl->memc_br3 = CFG_BR3_PRELIM;
  198. memctl->memc_mbmr = CFG_MBMR_8COL; /* refresh not enabled yet */
  199. udelay (200);
  200. memctl->memc_mcr = 0x80806105; /* precharge */
  201. udelay (1);
  202. memctl->memc_mcr = 0x80806106; /* load mode register */
  203. udelay (1);
  204. memctl->memc_mcr = 0x80806130; /* autorefresh */
  205. udelay (1);
  206. memctl->memc_mcr = 0x80806130; /* autorefresh */
  207. udelay (1);
  208. memctl->memc_mcr = 0x80806130; /* autorefresh */
  209. udelay (1);
  210. memctl->memc_mcr = 0x80806130; /* autorefresh */
  211. udelay (1);
  212. memctl->memc_mcr = 0x80806130; /* autorefresh */
  213. udelay (1);
  214. memctl->memc_mcr = 0x80806130; /* autorefresh */
  215. udelay (1);
  216. memctl->memc_mcr = 0x80806130; /* autorefresh */
  217. udelay (1);
  218. memctl->memc_mcr = 0x80806130; /* autorefresh */
  219. memctl->memc_mbmr |= MBMR_PTBE; /* refresh enabled */
  220. /*
  221. * Check Bank 0 Memory Size for re-configuration
  222. */
  223. size_b0 =
  224. dram_size (CFG_MBMR_8COL, (ulong *) SDRAM_BASE3_PRELIM,
  225. SDRAM_MAX_SIZE);
  226. memctl->memc_mbmr = CFG_MBMR_8COL | MBMR_PTBE;
  227. return (size_b0);
  228. }
  229. /* ------------------------------------------------------------------------- */
  230. /*
  231. * Check memory range for valid RAM. A simple memory test determines
  232. * the actually available RAM size between addresses `base' and
  233. * `base + maxsize'. Some (not all) hardware errors are detected:
  234. * - short between address lines
  235. * - short between data lines
  236. */
  237. static long int dram_size (long int mamr_value, long int *base,
  238. long int maxsize)
  239. {
  240. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  241. volatile memctl8xx_t *memctl = &immr->im_memctl;
  242. memctl->memc_mbmr = mamr_value;
  243. return (get_ram_size (base, maxsize));
  244. }
  245. /* ------------------------------------------------------------------------- */
  246. void reset_phy (void)
  247. {
  248. immap_t *immr = (immap_t *) CFG_IMMR;
  249. /* De-assert Ethernet Powerdown */
  250. immr->im_cpm.cp_pbpar &= ~(CFG_PB_ETH_POWERDOWN); /* GPIO */
  251. immr->im_cpm.cp_pbodr &= ~(CFG_PB_ETH_POWERDOWN); /* active output */
  252. immr->im_cpm.cp_pbdir |= CFG_PB_ETH_POWERDOWN; /* output */
  253. immr->im_cpm.cp_pbdat &= ~(CFG_PB_ETH_POWERDOWN); /* Enable PHY power */
  254. udelay (1000);
  255. /*
  256. * RESET is implemented by a positive pulse of at least 1 us
  257. * at the reset pin.
  258. *
  259. * Configure RESET pins for NS DP83843 PHY, and RESET chip.
  260. *
  261. * Note: The RESET pin is high active, but there is an
  262. * inverter on the SPD823TS board...
  263. */
  264. immr->im_ioport.iop_pcpar &= ~(CFG_PC_ETH_RESET);
  265. immr->im_ioport.iop_pcdir |= CFG_PC_ETH_RESET;
  266. /* assert RESET signal of PHY */
  267. immr->im_ioport.iop_pcdat &= ~(CFG_PC_ETH_RESET);
  268. udelay (10);
  269. /* de-assert RESET signal of PHY */
  270. immr->im_ioport.iop_pcdat |= CFG_PC_ETH_RESET;
  271. udelay (10);
  272. }
  273. /* ------------------------------------------------------------------------- */
  274. void show_boot_progress (int status)
  275. {
  276. #if defined(CONFIG_STATUS_LED)
  277. # if defined(STATUS_LED_YELLOW)
  278. status_led_set (STATUS_LED_YELLOW,
  279. (status < 0) ? STATUS_LED_ON : STATUS_LED_OFF);
  280. # endif /* STATUS_LED_YELLOW */
  281. # if defined(STATUS_LED_BOOT)
  282. if (status == 6)
  283. status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
  284. # endif /* STATUS_LED_BOOT */
  285. #endif /* CONFIG_STATUS_LED */
  286. }
  287. /* ------------------------------------------------------------------------- */
  288. void ide_set_reset (int on)
  289. {
  290. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  291. /*
  292. * Configure PC for IDE Reset Pin
  293. */
  294. if (on) { /* assert RESET */
  295. immr->im_ioport.iop_pcdat &= ~(CFG_PC_IDE_RESET);
  296. } else { /* release RESET */
  297. immr->im_ioport.iop_pcdat |= CFG_PC_IDE_RESET;
  298. }
  299. /* program port pin as GPIO output */
  300. immr->im_ioport.iop_pcpar &= ~(CFG_PC_IDE_RESET);
  301. immr->im_ioport.iop_pcso &= ~(CFG_PC_IDE_RESET);
  302. immr->im_ioport.iop_pcdir |= CFG_PC_IDE_RESET;
  303. }
  304. /* ------------------------------------------------------------------------- */