ddr2_fixed.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * (C) Copyright 2008-2009
  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/ppc4xx.h>
  25. #include <asm/io.h>
  26. #include <asm/processor.h>
  27. /*
  28. * This code can configure those two Crucial SODIMM's:
  29. *
  30. * Crucial CT6464AC667.4FE - 512MB SO-DIMM (single rank)
  31. * Crucial CT6464AC667.8FB - 512MB SO-DIMM (dual rank)
  32. *
  33. */
  34. #define TEST_ADDR 0x10000000
  35. #define TEST_MAGIC 0x11223344
  36. static void wait_init_complete(void)
  37. {
  38. u32 val;
  39. do {
  40. mfsdram(SDRAM_MCSTAT, val);
  41. } while (!(val & 0x80000000));
  42. }
  43. static void ddr_start(void)
  44. {
  45. mtsdram(SDRAM_MCOPT2, 0x28000000);
  46. wait_init_complete();
  47. }
  48. static void ddr_init_common(void)
  49. {
  50. /*
  51. * Reset the DDR-SDRAM controller.
  52. */
  53. mtsdr(SDR0_SRST, SDR0_SRST0_DMC);
  54. mtsdr(SDR0_SRST, 0x00000000);
  55. /*
  56. * These values are cloned from a running NOR booting
  57. * Canyonlands with SPD-DDR2 detection and calibration
  58. * enabled. This will only work for the same memory
  59. * configuration as used here:
  60. *
  61. */
  62. mtsdram(SDRAM_MCOPT2, 0x00000000);
  63. mtsdram(SDRAM_MODT0, 0x01000000);
  64. mtsdram(SDRAM_WRDTR, 0x82000823);
  65. mtsdram(SDRAM_CLKTR, 0x40000000);
  66. mtsdram(SDRAM_MB0CF, 0x00000201);
  67. mtsdram(SDRAM_RTR, 0x06180000);
  68. mtsdram(SDRAM_SDTR1, 0x80201000);
  69. mtsdram(SDRAM_SDTR2, 0x42103243);
  70. mtsdram(SDRAM_SDTR3, 0x0A0D0D16);
  71. mtsdram(SDRAM_MMODE, 0x00000632);
  72. mtsdram(SDRAM_MEMODE, 0x00000040);
  73. mtsdram(SDRAM_INITPLR0, 0xB5380000);
  74. mtsdram(SDRAM_INITPLR1, 0x82100400);
  75. mtsdram(SDRAM_INITPLR2, 0x80820000);
  76. mtsdram(SDRAM_INITPLR3, 0x80830000);
  77. mtsdram(SDRAM_INITPLR4, 0x80810040);
  78. mtsdram(SDRAM_INITPLR5, 0x80800532);
  79. mtsdram(SDRAM_INITPLR6, 0x82100400);
  80. mtsdram(SDRAM_INITPLR7, 0x8A080000);
  81. mtsdram(SDRAM_INITPLR8, 0x8A080000);
  82. mtsdram(SDRAM_INITPLR9, 0x8A080000);
  83. mtsdram(SDRAM_INITPLR10, 0x8A080000);
  84. mtsdram(SDRAM_INITPLR11, 0x80000432);
  85. mtsdram(SDRAM_INITPLR12, 0x808103C0);
  86. mtsdram(SDRAM_INITPLR13, 0x80810040);
  87. mtsdram(SDRAM_RDCC, 0x40000000);
  88. mtsdram(SDRAM_RQDC, 0x80000038);
  89. mtsdram(SDRAM_RFDC, 0x00000257);
  90. mtdcr(SDRAM_R0BAS, 0x0000F800); /* MQ0_B0BAS */
  91. }
  92. phys_size_t initdram(int board_type)
  93. {
  94. /*
  95. * First try init for this module:
  96. *
  97. * Crucial CT6464AC667.8FB - 512MB SO-DIMM (dual rank)
  98. */
  99. ddr_init_common();
  100. /*
  101. * Crucial CT6464AC667.8FB - 512MB SO-DIMM
  102. */
  103. mtdcr(SDRAM_R0BAS, 0x0000F800);
  104. mtdcr(SDRAM_R1BAS, 0x0400F800);
  105. mtsdram(SDRAM_MCOPT1, 0x05122000);
  106. mtsdram(SDRAM_CODT, 0x02800021);
  107. mtsdram(SDRAM_MB1CF, 0x00000201);
  108. ddr_start();
  109. /*
  110. * Now test if the dual-ranked module is really installed
  111. * by checking an address in the upper 256MByte region
  112. */
  113. out_be32((void *)TEST_ADDR, TEST_MAGIC);
  114. if (in_be32((void *)TEST_ADDR) != TEST_MAGIC) {
  115. /*
  116. * The test failed, so we assume that the single
  117. * ranked module is installed:
  118. *
  119. * Crucial CT6464AC667.4FE - 512MB SO-DIMM (single rank)
  120. */
  121. ddr_init_common();
  122. mtdcr(SDRAM_R0BAS, 0x0000F000);
  123. mtsdram(SDRAM_MCOPT1, 0x05322000);
  124. mtsdram(SDRAM_CODT, 0x00800021);
  125. ddr_start();
  126. }
  127. return CONFIG_SYS_MBYTES_SDRAM << 20;
  128. }