RPXlite.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /*
  24. * Yoo. Jonghoon, IPone, yooth@ipone.co.kr
  25. * U-Boot port on RPXlite board
  26. *
  27. * DRAM related UPMA register values are modified.
  28. * See RPXLite engineering note : 50MHz/60ns - UPM RAM WORDS
  29. */
  30. #include <common.h>
  31. #include <mpc8xx.h>
  32. /* ------------------------------------------------------------------------- */
  33. static long int dram_size (long int, long int *, long int);
  34. /* ------------------------------------------------------------------------- */
  35. #define _NOT_USED_ 0xFFFFCC25
  36. const uint sdram_table[] =
  37. {
  38. /*
  39. * Single Read. (Offset 00h in UPMA RAM)
  40. */
  41. 0xCFFFCC24, 0x0FFFCC04, 0X0CAFCC04, 0X03AFCC08,
  42. 0x3FBFCC27, /* last */
  43. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  44. /*
  45. * Burst Read. (Offset 08h in UPMA RAM)
  46. */
  47. 0xCFFFCC24, 0x0FFFCC04, 0x0CAFCC84, 0x03AFCC88,
  48. 0x3FBFCC27, /* last */
  49. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  50. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  51. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  52. /*
  53. * Single Write. (Offset 18h in UPMA RAM)
  54. */
  55. 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC04, 0x03FFCC00,
  56. 0x3FFFCC27, /* last */
  57. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  58. /*
  59. * Burst Write. (Offset 20h in UPMA RAM)
  60. */
  61. 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC80, 0x03FFCC8C,
  62. 0x0CFFCC00, 0x33FFCC27, /* last */
  63. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  64. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  65. _NOT_USED_, _NOT_USED_,
  66. /*
  67. * Refresh. (Offset 30h in UPMA RAM)
  68. */
  69. 0xC0FFCC24, 0x03FFCC24, 0x0FFFCC24, 0x0FFFCC24,
  70. 0x3FFFCC27, /* last */
  71. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  72. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  73. /*
  74. * Exception. (Offset 3Ch in UPMA RAM)
  75. */
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_
  77. };
  78. /* ------------------------------------------------------------------------- */
  79. /*
  80. * Check Board Identity:
  81. */
  82. int checkboard (void)
  83. {
  84. puts ("Board: RPXlite\n") ;
  85. return (0) ;
  86. }
  87. /* ------------------------------------------------------------------------- */
  88. long int initdram (int board_type)
  89. {
  90. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  91. volatile memctl8xx_t *memctl = &immap->im_memctl;
  92. long int size10 ;
  93. upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  94. /* Refresh clock prescalar */
  95. memctl->memc_mptpr = CFG_MPTPR ;
  96. memctl->memc_mar = 0x00000000;
  97. /* Map controller banks 1 to the SDRAM bank */
  98. memctl->memc_or1 = CFG_OR1_PRELIM;
  99. memctl->memc_br1 = CFG_BR1_PRELIM;
  100. memctl->memc_mamr = CFG_MAMR_10COL & (~(MAMR_PTAE)); /* no refresh yet */
  101. udelay(200);
  102. /* perform SDRAM initializsation sequence */
  103. memctl->memc_mcr = 0x80002230 ; /* SDRAM bank 0 - refresh twice */
  104. udelay(1);
  105. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  106. udelay (1000);
  107. /* Check Bank 0 Memory Size
  108. * try 10 column mode
  109. */
  110. size10 = dram_size (CFG_MAMR_10COL, (ulong *)SDRAM_BASE_PRELIM, SDRAM_MAX_SIZE) ;
  111. return (size10);
  112. }
  113. /* ------------------------------------------------------------------------- */
  114. /*
  115. * Check memory range for valid RAM. A simple memory test determines
  116. * the actually available RAM size between addresses `base' and
  117. * `base + maxsize'. Some (not all) hardware errors are detected:
  118. * - short between address lines
  119. * - short between data lines
  120. */
  121. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  122. {
  123. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  124. volatile memctl8xx_t *memctl = &immap->im_memctl;
  125. volatile long int *addr;
  126. ulong cnt, val;
  127. ulong save[32]; /* to make test non-destructive */
  128. unsigned char i = 0;
  129. memctl->memc_mamr = mamr_value;
  130. for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
  131. addr = base + cnt; /* pointer arith! */
  132. save[i++] = *addr;
  133. *addr = ~cnt;
  134. }
  135. /* write 0 to base address */
  136. addr = base;
  137. save[i] = *addr;
  138. *addr = 0;
  139. /* check at base address */
  140. if ((val = *addr) != 0) {
  141. *addr = save[i];
  142. return (0);
  143. }
  144. for (cnt = 1; cnt <= maxsize/sizeof(long); cnt <<= 1) {
  145. addr = base + cnt; /* pointer arith! */
  146. val = *addr;
  147. *addr = save[--i];
  148. if (val != (~cnt)) {
  149. return (cnt * sizeof(long));
  150. }
  151. }
  152. return (maxsize);
  153. }