memory.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * (C) Copyright 2007
  3. * Stefan Roese, DENX Software Engineering, sr@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 <asm/processor.h>
  25. void sdram_init(void)
  26. {
  27. return;
  28. }
  29. long int initdram(int board_type)
  30. {
  31. /*
  32. * Same as on Kilauea, Makalu generates exception 0x200
  33. * (machine check) after trap_init() in board_init_f,
  34. * when SDRAM is initialized here (late) and d-cache is
  35. * used earlier as INIT_RAM.
  36. * So for now, initialize DDR2 in init.S very early and
  37. * also use it for INIT_RAM. Then this exception doesn't
  38. * occur.
  39. */
  40. #if 0
  41. u32 val;
  42. /* base=00000000, size=128MByte (5), mode=2 (n*10*4) */
  43. mtsdram(SDRAM_MB0CF, 0x00005201);
  44. /* SET SDRAM_MB1CF - Not enabled */
  45. mtsdram(SDRAM_MB1CF, 0x00000000);
  46. /* SET SDRAM_MB2CF - Not enabled */
  47. mtsdram(SDRAM_MB2CF, 0x00000000);
  48. /* SET SDRAM_MB3CF - Not enabled */
  49. mtsdram(SDRAM_MB3CF, 0x00000000);
  50. /* SDRAM_CLKTR: Adv Addr clock by 90 deg */
  51. mtsdram(SDRAM_CLKTR, 0x80000000);
  52. /* Refresh Time register (0x30) Refresh every 7.8125uS */
  53. mtsdram(SDRAM_RTR, 0x06180000);
  54. /* SDRAM_SDTR1 */
  55. mtsdram(SDRAM_SDTR1, 0x80201000);
  56. /* SDRAM_SDTR2 */
  57. mtsdram(SDRAM_SDTR2, 0x32204232);
  58. /* SDRAM_SDTR3 */
  59. mtsdram(SDRAM_SDTR3, 0x080b0d1a);
  60. mtsdram(SDRAM_MMODE, 0x00000442);
  61. mtsdram(SDRAM_MEMODE, 0x00000404);
  62. /* SDRAM0_MCOPT1 (0X20) No ECC Gen */
  63. mtsdram(SDRAM_MCOPT1, 0x04322000);
  64. /* NOP */
  65. mtsdram(SDRAM_INITPLR0, 0xa8380000);
  66. /* precharge 3 DDR clock cycle */
  67. mtsdram(SDRAM_INITPLR1, 0x81900400);
  68. /* EMR2 twr = 2tck */
  69. mtsdram(SDRAM_INITPLR2, 0x81020000);
  70. /* EMR3 twr = 2tck */
  71. mtsdram(SDRAM_INITPLR3, 0x81030000);
  72. /* EMR DLL ENABLE twr = 2tck */
  73. mtsdram(SDRAM_INITPLR4, 0x81010404);
  74. /* MR w/ DLL reset
  75. * Note: 5 is CL. May need to be changed
  76. */
  77. mtsdram(SDRAM_INITPLR5, 0x81000542);
  78. /* precharge 3 DDR clock cycle */
  79. mtsdram(SDRAM_INITPLR6, 0x81900400);
  80. /* Auto-refresh trfc = 26tck */
  81. mtsdram(SDRAM_INITPLR7, 0x8D080000);
  82. /* Auto-refresh trfc = 26tck */
  83. mtsdram(SDRAM_INITPLR8, 0x8D080000);
  84. /* Auto-refresh */
  85. mtsdram(SDRAM_INITPLR9, 0x8D080000);
  86. /* Auto-refresh */
  87. mtsdram(SDRAM_INITPLR10, 0x8D080000);
  88. /* MRS - normal operation; wait 2 cycle (set wait to tMRD) */
  89. mtsdram(SDRAM_INITPLR11, 0x81000442);
  90. mtsdram(SDRAM_INITPLR12, 0x81010780);
  91. mtsdram(SDRAM_INITPLR13, 0x81010400);
  92. mtsdram(SDRAM_INITPLR14, 0x00000000);
  93. mtsdram(SDRAM_INITPLR15, 0x00000000);
  94. /* SET MCIF0_CODT Die Termination On */
  95. mtsdram(SDRAM_CODT, 0x0080f837);
  96. mtsdram(SDRAM_MODT0, 0x01800000);
  97. mtsdram(SDRAM_MODT1, 0x00000000);
  98. mtsdram(SDRAM_WRDTR, 0x00000000);
  99. /* SDRAM0_MCOPT2 (0X21) Start initialization */
  100. mtsdram(SDRAM_MCOPT2, 0x20000000);
  101. /* Step 5 */
  102. do {
  103. mfsdram(SDRAM_MCSTAT, val);
  104. } while ((val & SDRAM_MCSTAT_MIC_COMP) != SDRAM_MCSTAT_MIC_COMP);
  105. /* Step 6 */
  106. /* SDRAM_DLCR */
  107. mtsdram(SDRAM_DLCR, 0x030000a5);
  108. /* SDRAM_RDCC */
  109. mtsdram(SDRAM_RDCC, 0x40000000);
  110. /* SDRAM_RQDC */
  111. mtsdram(SDRAM_RQDC, 0x80000038);
  112. /* SDRAM_RFDC */
  113. mtsdram(SDRAM_RFDC, 0x00000209);
  114. /* Enable memory controller */
  115. mfsdram(SDRAM_MCOPT2, val);
  116. val |= SDRAM_MCOPT2_DCEN_ENABLE;
  117. mtsdram(SDRAM_MCOPT2, val);
  118. #endif
  119. return (CFG_MBYTES_SDRAM << 20);
  120. }
  121. #if defined(CFG_DRAM_TEST)
  122. int testdram (void)
  123. {
  124. printf ("testdram\n");
  125. #if defined (CONFIG_NAND_U_BOOT)
  126. return 0;
  127. #endif
  128. uint *pstart = (uint *) 0x00000000;
  129. uint *pend = (uint *) 0x00001000;
  130. uint *p;
  131. for (p = pstart; p < pend; p++) {
  132. *p = 0xaaaaaaaa;
  133. }
  134. for (p = pstart; p < pend; p++) {
  135. if (*p != 0xaaaaaaaa) {
  136. #if !defined (CONFIG_NAND_SPL)
  137. printf ("SDRAM test fails at: %08x\n", (uint) p);
  138. #endif
  139. return 1;
  140. }
  141. }
  142. for (p = pstart; p < pend; p++) {
  143. *p = 0x55555555;
  144. }
  145. for (p = pstart; p < pend; p++) {
  146. if (*p != 0x55555555) {
  147. #if !defined (CONFIG_NAND_SPL)
  148. printf ("SDRAM test fails at: %08x\n", (uint) p);
  149. #endif
  150. return 1;
  151. }
  152. }
  153. #if !defined (CONFIG_NAND_SPL)
  154. printf ("SDRAM test passed!!!\n");
  155. #endif
  156. return 0;
  157. }
  158. #endif