icu862.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * (C) Copyright 2001
  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 <config.h>
  25. #include <mpc8xx.h>
  26. /*
  27. * Memory Controller Using
  28. *
  29. * CS0 - Flash memory (0x40000000)
  30. * CS1 - SDRAM (0x00000000}
  31. * CS2 - S/UNI Ultra ATM155
  32. * CS3 - IDT 77106 ATM25
  33. * CS4 - DSP HPI
  34. * CS5 - E1/T1 Interface device
  35. * CS6 - PCMCIA device
  36. * CS7 - PCMCIA device
  37. */
  38. /* ------------------------------------------------------------------------- */
  39. #define _not_used_ 0xffffffff
  40. const uint sdram_table[] = {
  41. /* single read. (offset 0 in upm RAM) */
  42. 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
  43. 0x1ff77c47,
  44. /* MRS initialization (offset 5) */
  45. 0x1ff77c34, 0xefeabc34, 0x1fb57c35,
  46. /* burst read. (offset 8 in upm RAM) */
  47. 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
  48. 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47,
  49. _not_used_, _not_used_, _not_used_, _not_used_,
  50. _not_used_, _not_used_, _not_used_, _not_used_,
  51. /* single write. (offset 18 in upm RAM) */
  52. 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47,
  53. _not_used_, _not_used_, _not_used_, _not_used_,
  54. /* burst write. (offset 20 in upm RAM) */
  55. 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
  56. 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _not_used_,
  57. _not_used_, _not_used_, _not_used_, _not_used_,
  58. _not_used_, _not_used_, _not_used_, _not_used_,
  59. /* refresh. (offset 30 in upm RAM) */
  60. 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  61. 0xfffffc84, 0xfffffc07, _not_used_, _not_used_,
  62. _not_used_, _not_used_, _not_used_, _not_used_,
  63. /* exception. (offset 3c in upm RAM) */
  64. 0x7ffffc07, _not_used_, _not_used_, _not_used_
  65. };
  66. /* ------------------------------------------------------------------------- */
  67. /*
  68. * Check Board Identity:
  69. */
  70. int checkboard (void)
  71. {
  72. puts ("Board: ICU862 Board\n");
  73. return 0;
  74. }
  75. /* ------------------------------------------------------------------------- */
  76. static long int dram_size (long int, long int *, long int);
  77. /* ------------------------------------------------------------------------- */
  78. long int initdram (int board_type)
  79. {
  80. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  81. volatile memctl8xx_t *memctl = &immap->im_memctl;
  82. long int size8, size9;
  83. long int size_b0 = 0;
  84. unsigned long reg;
  85. upmconfig (UPMA, (uint *) sdram_table,
  86. sizeof (sdram_table) / sizeof (uint));
  87. /*
  88. * Preliminary prescaler for refresh (depends on number of
  89. * banks): This value is selected for four cycles every 62.4 us
  90. * with two SDRAM banks or four cycles every 31.2 us with one
  91. * bank. It will be adjusted after memory sizing.
  92. */
  93. memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
  94. memctl->memc_mar = 0x00000088;
  95. /*
  96. * Map controller bank 1 to the SDRAM bank at
  97. * preliminary address - these have to be modified after the
  98. * SDRAM size has been determined.
  99. */
  100. memctl->memc_or1 = CFG_OR1_PRELIM;
  101. memctl->memc_br1 = CFG_BR1_PRELIM;
  102. memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  103. udelay (200);
  104. /* perform SDRAM initializsation sequence */
  105. memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
  106. udelay (200);
  107. memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - execute twice */
  108. udelay (200);
  109. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  110. udelay (1000);
  111. /*
  112. * Check Bank 0 Memory Size for re-configuration
  113. *
  114. * try 8 column mode
  115. */
  116. size8 = dram_size (CFG_MAMR_8COL, SDRAM_BASE1_PRELIM,
  117. SDRAM_MAX_SIZE);
  118. udelay (1000);
  119. /*
  120. * try 9 column mode
  121. */
  122. size9 = dram_size (CFG_MAMR_9COL, SDRAM_BASE1_PRELIM,
  123. SDRAM_MAX_SIZE);
  124. if (size8 < size9) { /* leave configuration at 9 columns */
  125. size_b0 = size9;
  126. /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
  127. } else { /* back to 8 columns */
  128. size_b0 = size8;
  129. memctl->memc_mamr = CFG_MAMR_8COL;
  130. udelay (500);
  131. /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
  132. }
  133. udelay (1000);
  134. /*
  135. * Adjust refresh rate depending on SDRAM type, both banks
  136. * For types > 128 MBit leave it at the current (fast) rate
  137. */
  138. if ((size_b0 < 0x02000000)) {
  139. /* reduce to 15.6 us (62.4 us / quad) */
  140. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  141. udelay (1000);
  142. }
  143. /*
  144. * Final mapping
  145. */
  146. memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  147. memctl->memc_br1 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  148. /* adjust refresh rate depending on SDRAM type, one bank */
  149. reg = memctl->memc_mptpr;
  150. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  151. memctl->memc_mptpr = reg;
  152. udelay (10000);
  153. return (size_b0);
  154. }
  155. /* ------------------------------------------------------------------------- */
  156. /*
  157. * Check memory range for valid RAM. A simple memory test determines
  158. * the actually available RAM size between addresses `base' and
  159. * `base + maxsize'. Some (not all) hardware errors are detected:
  160. * - short between address lines
  161. * - short between data lines
  162. */
  163. static long int dram_size (long int mamr_value, long int *base,
  164. long int maxsize)
  165. {
  166. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  167. volatile memctl8xx_t *memctl = &immap->im_memctl;
  168. memctl->memc_mamr = mamr_value;
  169. return (get_ram_size(base, maxsize));
  170. }