quantum.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * (C) Copyright 2000
  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. #include "fpga.h"
  26. /* ------------------------------------------------------------------------- */
  27. static long int dram_size (long int, long int *, long int);
  28. unsigned long flash_init (void);
  29. /* ------------------------------------------------------------------------- */
  30. #define _NOT_USED_ 0xFFFFCC25
  31. const uint sdram_table[] = {
  32. /*
  33. * Single Read. (Offset 00h in UPMA RAM)
  34. */
  35. 0x0F03CC04, 0x00ACCC24, 0x1FF74C20, _NOT_USED_,
  36. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  37. /*
  38. * Burst Read. (Offset 08h in UPMA RAM)
  39. */
  40. 0x0F03CC04, 0x00ACCC24, 0x00FFCC20, 0x00FFCC20,
  41. 0x01FFCC20, 0x1FF74C20, _NOT_USED_, _NOT_USED_,
  42. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  43. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  44. /*
  45. * Single Write. (Offset 18h in UPMA RAM)
  46. */
  47. 0x0F03CC02, 0x00AC0C24, 0x1FF74C25, _NOT_USED_,
  48. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  49. /*
  50. * Burst Write. (Offset 20h in UPMA RAM)
  51. */
  52. 0x0F03CC00, 0x00AC0C20, 0x00FFFC20, 0x00FFFC22,
  53. 0x01FFFC24, 0x1FF74C25, _NOT_USED_, _NOT_USED_,
  54. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  55. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  56. /*
  57. * Refresh. (Offset 30h in UPMA RAM)
  58. * (Initialization code at 0x36)
  59. */
  60. 0x0FF0CC24, 0xFFFFCC24, _NOT_USED_, _NOT_USED_,
  61. _NOT_USED_, _NOT_USED_, 0xEFFB8C34, 0x0FF74C34,
  62. 0x0FFACCB4, 0x0FF5CC34, 0x0FFCC34, 0x0FFFCCB4,
  63. /*
  64. * Exception. (Offset 3Ch in UPMA RAM)
  65. */
  66. 0x0FEA8C34, 0x1FB54C34, 0xFFFFCC34, _NOT_USED_
  67. };
  68. /* ------------------------------------------------------------------------- */
  69. /*
  70. * Check Board Identity:
  71. */
  72. int checkboard (void)
  73. {
  74. char buf[64];
  75. int i;
  76. int l = getenv_f("serial#", buf, sizeof(buf));
  77. puts ("Board QUANTUM, Serial No: ");
  78. for (i = 0; i < l; ++i) {
  79. if (buf[i] == ' ')
  80. break;
  81. putc (buf[i]);
  82. }
  83. putc ('\n');
  84. return (0); /* success */
  85. }
  86. /* ------------------------------------------------------------------------- */
  87. phys_size_t initdram (int board_type)
  88. {
  89. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  90. volatile memctl8xx_t *memctl = &immap->im_memctl;
  91. long int size9;
  92. upmconfig (UPMA, (uint *) sdram_table,
  93. sizeof (sdram_table) / sizeof (uint));
  94. /* Refresh clock prescalar */
  95. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  96. memctl->memc_mar = 0x00000088;
  97. /* Map controller banks 1 to the SDRAM bank */
  98. memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
  99. memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
  100. memctl->memc_mamr = CONFIG_SYS_MAMR_9COL & (~(MAMR_PTAE)); /* no refresh yet */
  101. udelay (200);
  102. /* perform SDRAM initializsation sequence */
  103. memctl->memc_mcr = 0x80002136; /* SDRAM bank 0 */
  104. udelay (1);
  105. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  106. udelay (1000);
  107. /* Check Bank 0 Memory Size,
  108. * 9 column mode
  109. */
  110. size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE_PRELIM,
  111. SDRAM_MAX_SIZE);
  112. /*
  113. * Final mapping:
  114. */
  115. memctl->memc_or1 = ((-size9) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  116. udelay (1000);
  117. return (size9);
  118. }
  119. /* ------------------------------------------------------------------------- */
  120. /*
  121. * Check memory range for valid RAM. A simple memory test determines
  122. * the actually available RAM size between addresses `base' and
  123. * `base + maxsize'. Some (not all) hardware errors are detected:
  124. * - short between address lines
  125. * - short between data lines
  126. */
  127. static long int dram_size (long int mamr_value, long int *base,
  128. long int maxsize)
  129. {
  130. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  131. volatile memctl8xx_t *memctl = &immap->im_memctl;
  132. volatile ulong *addr;
  133. ulong cnt, val, size;
  134. ulong save[32]; /* to make test non-destructive */
  135. unsigned char i = 0;
  136. memctl->memc_mamr = mamr_value;
  137. for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
  138. addr = (volatile ulong *)(base + cnt); /* pointer arith! */
  139. save[i++] = *addr;
  140. *addr = ~cnt;
  141. }
  142. /* write 0 to base address */
  143. addr = (volatile ulong *)base;
  144. save[i] = *addr;
  145. *addr = 0;
  146. /* check at base address */
  147. if ((val = *addr) != 0) {
  148. /* Restore the original data before leaving the function.
  149. */
  150. *addr = save[i];
  151. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  152. addr = (volatile ulong *) base + cnt;
  153. *addr = save[--i];
  154. }
  155. return (0);
  156. }
  157. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  158. addr = (volatile ulong *)(base + cnt); /* pointer arith! */
  159. val = *addr;
  160. *addr = save[--i];
  161. if (val != (~cnt)) {
  162. size = cnt * sizeof (long);
  163. /* Restore the original data before returning
  164. */
  165. for (cnt <<= 1; cnt <= maxsize / sizeof (long);
  166. cnt <<= 1) {
  167. addr = (volatile ulong *) base + cnt;
  168. *addr = save[--i];
  169. }
  170. return (size);
  171. }
  172. }
  173. return (maxsize);
  174. }
  175. /*
  176. * Miscellaneous intialization
  177. */
  178. int misc_init_r (void)
  179. {
  180. char *fpga_data_str = getenv ("fpgadata");
  181. char *fpga_size_str = getenv ("fpgasize");
  182. void *fpga_data;
  183. int fpga_size;
  184. int status;
  185. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  186. volatile memctl8xx_t *memctl = &immap->im_memctl;
  187. int flash_size;
  188. /* Remap FLASH according to real size */
  189. flash_size = flash_init ();
  190. memctl->memc_or0 = CONFIG_SYS_OR_TIMING_FLASH | (-flash_size & 0xFFFF8000);
  191. memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V;
  192. if (fpga_data_str && fpga_size_str) {
  193. fpga_data = (void *) simple_strtoul (fpga_data_str, NULL, 16);
  194. fpga_size = simple_strtoul (fpga_size_str, NULL, 10);
  195. status = fpga_boot (fpga_data, fpga_size);
  196. if (status != 0) {
  197. printf ("\nFPGA: Booting failed ");
  198. switch (status) {
  199. case ERROR_FPGA_PRG_INIT_LOW:
  200. printf ("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  201. break;
  202. case ERROR_FPGA_PRG_INIT_HIGH:
  203. printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  204. break;
  205. case ERROR_FPGA_PRG_DONE:
  206. printf ("(Timeout: DONE not high after programming FPGA)\n ");
  207. break;
  208. }
  209. }
  210. }
  211. return 0;
  212. }