qs850.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * (C) Copyright 2003
  3. * MuLogic B.V.
  4. *
  5. * (C) Copyright 2002
  6. * Simple Network Magic Corporation, dnevil@snmc.com
  7. *
  8. * (C) Copyright 2000
  9. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <asm/u-boot.h>
  31. #include <commproc.h>
  32. #include "mpc8xx.h"
  33. /* ------------------------------------------------------------------------- */
  34. static long int dram_size (long int, long int *, long int);
  35. /* ------------------------------------------------------------------------- */
  36. const uint sdram_table[] =
  37. {
  38. /*
  39. * Single Read. (Offset 0 in UPMA RAM)
  40. */
  41. 0x0f07cc04, 0x00adcc04, 0x00a74c00, 0x00bfcc04,
  42. 0x1fffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  43. /*
  44. * Burst Read. (Offset 8 in UPMA RAM)
  45. */
  46. 0x0ff7fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00,
  47. 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05,
  48. 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05,
  49. 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05,
  50. /*
  51. * Single Write. (Offset 18 in UPMA RAM)
  52. */
  53. 0x0f07cc04, 0x0fafcc00, 0x01ad0c04, 0x1ff74c07,
  54. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  55. /*
  56. * Burst Write. (Offset 20 in UPMA RAM)
  57. */
  58. 0x0ff7fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00,
  59. 0x00fffc00, 0x00fffc00, 0x0ffffc04, 0x0ff77c04,
  60. 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05,
  61. 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05,
  62. /*
  63. * Refresh (Offset 30 in UPMA RAM)
  64. */
  65. 0xffffcc04, 0x1ff5cc84, 0xffffcc04, 0xffffcc04,
  66. 0xffffcc84, 0xffffcc05, 0xffffcc04, 0xffffcc04,
  67. 0xffffcc04, 0xffffcc04, 0xffffcc04, 0xffffcc04,
  68. /*
  69. * Exception. (Offset 3c in UPMA RAM)
  70. */
  71. 0x1ff74c04, 0xffffcc07, 0xffffaa34, 0x1fb54a37
  72. };
  73. /* ------------------------------------------------------------------------- */
  74. /*
  75. * Check Board Identity:
  76. *
  77. * Test ID string (QS850, QS823, ...)
  78. *
  79. * Always return 1
  80. */
  81. #if defined(CONFIG_QS850)
  82. #define BOARD_IDENTITY "QS850"
  83. #elif defined(CONFIG_QS823)
  84. #define BOARD_IDENTITY "QS823"
  85. #else
  86. #define BOARD_IDENTITY "QS???"
  87. #endif
  88. int checkboard (void)
  89. {
  90. char *s, *e;
  91. char buf[64];
  92. int i;
  93. i = getenv_r("serial#", buf, sizeof(buf));
  94. s = (i>0) ? buf : NULL;
  95. if (!s || strncmp(s, BOARD_IDENTITY, 5)) {
  96. puts ("### No HW ID - assuming " BOARD_IDENTITY);
  97. } else {
  98. for (e=s; *e; ++e) {
  99. if (*e == ' ')
  100. break;
  101. }
  102. for ( ; s<e; ++s) {
  103. putc (*s);
  104. }
  105. }
  106. putc ('\n');
  107. return (0);
  108. }
  109. /* ------------------------------------------------------------------------- */
  110. /* SDRAM Mode Register Definitions */
  111. /* Set SDRAM Burst Length to 4 (010) */
  112. /* See Motorola MPC850 User Manual, Page 13-14 */
  113. #define SDRAM_BURST_LENGTH (2)
  114. /* Set Wrap Type to Sequential (0) */
  115. /* See Motorola MPC850 User Manual, Page 13-14 */
  116. #define SDRAM_WRAP_TYPE (0 << 3)
  117. /* Set /CAS Latentcy to 2 clocks */
  118. #define SDRAM_CAS_LATENTCY (2 << 4)
  119. /* The Mode Register value must be shifted left by 2, since it is */
  120. /* placed on the address bus, and the 2 LSBs are ignored for 32-bit accesses */
  121. #define SDRAM_MODE_REG ((SDRAM_BURST_LENGTH|SDRAM_WRAP_TYPE|SDRAM_CAS_LATENTCY) << 2)
  122. #define UPMA_RUN(loops,index) (0x80002000 + (loops<<8) + index)
  123. /* Please note a value of zero = 16 loops */
  124. #define REFRESH_INIT_LOOPS (0)
  125. phys_size_t initdram (int board_type)
  126. {
  127. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  128. volatile memctl8xx_t *memctl = &immap->im_memctl;
  129. long int size;
  130. upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  131. /*
  132. * Prescaler for refresh
  133. */
  134. memctl->memc_mptpr = CFG_MPTPR;
  135. /*
  136. * Map controller bank 1 to the SDRAM address
  137. */
  138. memctl->memc_or1 = CFG_OR1;
  139. memctl->memc_br1 = CFG_BR1;
  140. udelay(1000);
  141. /* perform SDRAM initialization sequence */
  142. memctl->memc_mamr = CFG_16M_MAMR;
  143. udelay(100);
  144. /* Program the SDRAM's Mode Register */
  145. memctl->memc_mar = SDRAM_MODE_REG;
  146. /* Run the Prechard Pattern at 0x3C */
  147. memctl->memc_mcr = UPMA_RUN(1,0x3c);
  148. udelay(1);
  149. /* Run the Refresh program residing at MAD index 0x30 */
  150. /* This contains the CBR Refresh command with a loop */
  151. /* The SDRAM must be refreshed at least 2 times */
  152. /* Please note a value of zero = 16 loops */
  153. memctl->memc_mcr = UPMA_RUN(REFRESH_INIT_LOOPS,0x30);
  154. udelay(1);
  155. /* Run the Exception program residing at MAD index 0x3E */
  156. /* This contains the Write Mode Register command */
  157. /* The Write Mode Register command uses the value written to MAR */
  158. memctl->memc_mcr = UPMA_RUN(1,0x3e);
  159. udelay (1000);
  160. /*
  161. * Check for 32M SDRAM Memory Size
  162. */
  163. size = dram_size(CFG_32M_MAMR|MAMR_PTAE,
  164. (long *)SDRAM_BASE, SDRAM_32M_MAX_SIZE);
  165. udelay (1000);
  166. /*
  167. * Check for 16M SDRAM Memory Size
  168. */
  169. if (size != SDRAM_32M_MAX_SIZE) {
  170. size = dram_size(CFG_16M_MAMR|MAMR_PTAE,
  171. (long *)SDRAM_BASE, SDRAM_16M_MAX_SIZE);
  172. udelay (1000);
  173. }
  174. udelay(10000);
  175. return (size);
  176. }
  177. /* ------------------------------------------------------------------------- */
  178. /*
  179. * Check memory range for valid RAM. A simple memory test determines
  180. * the actually available RAM size between addresses `base' and
  181. * `base + maxsize'. Some (not all) hardware errors are detected:
  182. * - short between address lines
  183. * - short between data lines
  184. */
  185. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  186. {
  187. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  188. volatile memctl8xx_t *memctl = &immap->im_memctl;
  189. memctl->memc_mamr = mamr_value;
  190. return (get_ram_size(base, maxsize));
  191. }