ivm.c 10 KB

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