nc650.c 5.6 KB

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