lantec.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * (C) Copyright 2000, 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * (C) Copyright 2001
  5. * Torsten Stevens, FHG IMS, stevens@ims.fhg.de
  6. * Bruno Achauer, Exet AG, bruno@exet-ag.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * Derived from ../tqm8xx/tqm8xx.c
  28. */
  29. #include <common.h>
  30. #include <mpc8xx.h>
  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 UPMA RAM)
  38. */
  39. 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
  40. 0x1ff77c47, /* last */
  41. /*
  42. * SDRAM Initialization (offset 5 in UPMA 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. 0x1ff77c35, 0xefeabc34, 0x1fb57c35, /* last */
  50. /*
  51. * Burst Read. (Offset 8 in UPMA RAM)
  52. */
  53. 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
  54. 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, /* 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 UPMA RAM)
  59. */
  60. 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, /* last */
  61. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  62. /*
  63. * Burst Write. (Offset 20 in UPMA RAM)
  64. */
  65. 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
  66. 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, /* 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 UPMA RAM)
  72. */
  73. 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  74. 0xfffffc84, 0xfffffc07, 0xfffffc07, /* last */
  75. _NOT_USED_,
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  77. /*
  78. * Exception. (Offset 3c in UPMA RAM)
  79. */
  80. 0x7ffffc07, /* last */
  81. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  82. };
  83. /* ------------------------------------------------------------------------- */
  84. /*
  85. * Check Board Identity:
  86. *
  87. * Test TQ ID string (TQM8xx...)
  88. * If present, check for "L" type (no second DRAM bank),
  89. * otherwise "L" type is assumed as default.
  90. *
  91. * Return 1 for "L" type, 0 else.
  92. */
  93. int checkboard (void)
  94. {
  95. printf ("Board: Lantec special edition rev.%d\n", CONFIG_LANTEC);
  96. return 0;
  97. }
  98. /* ------------------------------------------------------------------------- */
  99. long int initdram (int board_type)
  100. {
  101. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  102. volatile memctl8xx_t *memctl = &immap->im_memctl;
  103. long int size_b0;
  104. int i;
  105. /*
  106. * Configure UPMA for SDRAM
  107. */
  108. upmconfig (UPMA, (uint *) sdram_table,
  109. sizeof (sdram_table) / sizeof (uint));
  110. memctl->memc_mptpr = CFG_MPTPR_1BK_8K /* XXX CFG_MPTPR XXX */ ;
  111. /* burst length=4, burst type=sequential, CAS latency=2 */
  112. memctl->memc_mar = 0x00000088;
  113. /*
  114. * Map controller bank 3 to the SDRAM bank at preliminary address.
  115. */
  116. memctl->memc_or3 = CFG_OR3_PRELIM;
  117. memctl->memc_br3 = CFG_BR3_PRELIM;
  118. /* initialize memory address register */
  119. memctl->memc_mamr = CFG_MAMR_8COL; /* refresh not enabled yet */
  120. /* mode initialization (offset 5) */
  121. udelay (200); /* 0x80006105 */
  122. memctl->memc_mcr =
  123. MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x05);
  124. /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */
  125. udelay (1); /* 0x80006130 */
  126. memctl->memc_mcr =
  127. MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x30);
  128. udelay (1); /* 0x80006130 */
  129. memctl->memc_mcr =
  130. MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x30);
  131. udelay (1); /* 0x80006106 */
  132. memctl->memc_mcr =
  133. MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x06);
  134. memctl->memc_mamr |= MAMR_PTAE; /* refresh enabled */
  135. udelay (200);
  136. /* Need at least 10 DRAM accesses to stabilize */
  137. for (i = 0; i < 10; ++i) {
  138. volatile unsigned long *addr =
  139. (volatile unsigned long *) SDRAM_BASE3_PRELIM;
  140. unsigned long val;
  141. val = *(addr + i);
  142. *(addr + i) = val;
  143. }
  144. /*
  145. * Check Bank 0 Memory Size for re-configuration
  146. */
  147. size_b0 = dram_size (CFG_MAMR_8COL,
  148. (ulong *) SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
  149. memctl->memc_mamr = CFG_MAMR_8COL | MAMR_PTAE;
  150. /*
  151. * Final mapping:
  152. */
  153. memctl->memc_or3 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  154. memctl->memc_br3 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  155. udelay (1000);
  156. return (size_b0);
  157. }
  158. /* ------------------------------------------------------------------------- */
  159. /*
  160. * Check memory range for valid RAM. A simple memory test determines
  161. * the actually available RAM size between addresses `base' and
  162. * `base + maxsize'. Some (not all) hardware errors are detected:
  163. * - short between address lines
  164. * - short between data lines
  165. */
  166. static long int dram_size (long int mamr_value, long int *base,
  167. long int maxsize)
  168. {
  169. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  170. volatile memctl8xx_t *memctl = &immap->im_memctl;
  171. memctl->memc_mamr = mamr_value;
  172. return (get_ram_size (base, maxsize));
  173. }