sdram.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * (C) Copyright 2009
  3. * Matthias Fuchs, esd gmbh, matthias.fuchs@esd.eu
  4. *
  5. * (C) Copyright 2006
  6. * Sylvie Gohl, AMCC/IBM, gohl.sylvie@fr.ibm.com
  7. * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
  8. * Thierry Roman, AMCC/IBM, thierry_roman@fr.ibm.com
  9. * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
  10. * Robert Snyder, AMCC/IBM, rob.snyder@fr.ibm.com
  11. *
  12. * (C) Copyright 2006-2007
  13. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. /* define DEBUG for debug output */
  31. #undef DEBUG
  32. #include <common.h>
  33. #include <asm/processor.h>
  34. #include <asm/io.h>
  35. #include <asm/mmu.h>
  36. #include <asm/ppc440.h>
  37. extern int denali_wait_for_dlllock(void);
  38. extern void denali_core_search_data_eye(void);
  39. struct sdram_conf_s {
  40. ulong size;
  41. int rows;
  42. int banks;
  43. };
  44. struct sdram_conf_s sdram_conf[] = {
  45. {(1024 << 20), 14, 8}, /* 1GByte: 4x2GBit, 14x10, 8 banks */
  46. {(512 << 20), 13, 8}, /* 512MByte: 4x1GBit, 13x10, 8 banks */
  47. {(256 << 20), 13, 4}, /* 256MByte: 4x512MBit, 13x10, 4 banks */
  48. };
  49. /*
  50. * initdram -- 440EPx's DDR controller is a DENALI Core
  51. */
  52. int initdram_by_rb(int rows, int banks)
  53. {
  54. ulong speed = get_bus_freq(0);
  55. mtsdram(DDR0_02, 0x00000000);
  56. mtsdram(DDR0_00, 0x0000190A);
  57. mtsdram(DDR0_01, 0x01000000);
  58. mtsdram(DDR0_03, 0x02030602);
  59. mtsdram(DDR0_04, 0x0A020200);
  60. mtsdram(DDR0_05, 0x02020308);
  61. mtsdram(DDR0_06, 0x0102C812);
  62. mtsdram(DDR0_07, 0x000D0100);
  63. mtsdram(DDR0_08, 0x02430001);
  64. mtsdram(DDR0_09, 0x00011D5F);
  65. mtsdram(DDR0_10, 0x00000100);
  66. mtsdram(DDR0_11, 0x0027C800);
  67. mtsdram(DDR0_12, 0x00000003);
  68. mtsdram(DDR0_14, 0x00000000);
  69. mtsdram(DDR0_17, 0x19000000);
  70. mtsdram(DDR0_18, 0x19191919);
  71. mtsdram(DDR0_19, 0x19191919);
  72. mtsdram(DDR0_20, 0x0B0B0B0B);
  73. mtsdram(DDR0_21, 0x0B0B0B0B);
  74. mtsdram(DDR0_22, 0x00267F0B);
  75. mtsdram(DDR0_23, 0x00000000);
  76. mtsdram(DDR0_24, 0x01010002);
  77. if (speed > 133333334)
  78. mtsdram(DDR0_26, 0x5B26050C);
  79. else
  80. mtsdram(DDR0_26, 0x5B260408);
  81. mtsdram(DDR0_27, 0x0000682B);
  82. mtsdram(DDR0_28, 0x00000000);
  83. mtsdram(DDR0_31, 0x00000000);
  84. mtsdram(DDR0_42,
  85. DDR0_42_ADDR_PINS_DECODE(14 - rows) |
  86. 0x00000006);
  87. mtsdram(DDR0_43,
  88. DDR0_43_EIGHT_BANK_MODE_ENCODE(8 == banks ? 1 : 0) |
  89. 0x030A0200);
  90. mtsdram(DDR0_44, 0x00000003);
  91. mtsdram(DDR0_02, 0x00000001);
  92. denali_wait_for_dlllock();
  93. #ifdef CONFIG_DDR_DATA_EYE
  94. /*
  95. * Perform data eye search if requested.
  96. */
  97. denali_core_search_data_eye();
  98. #endif
  99. /*
  100. * Clear possible errors resulting from data-eye-search.
  101. * If not done, then we could get an interrupt later on when
  102. * exceptions are enabled.
  103. */
  104. set_mcsr(get_mcsr());
  105. return 0;
  106. }
  107. phys_size_t initdram(int board_type)
  108. {
  109. phys_size_t size;
  110. int n;
  111. /* go through supported memory configurations */
  112. for (n = 0; n < ARRAY_SIZE(sdram_conf); n++) {
  113. size = sdram_conf[n].size;
  114. /* program TLB entries */
  115. program_tlb(0, CONFIG_SYS_SDRAM_BASE, size,
  116. TLB_WORD2_I_ENABLE);
  117. /*
  118. * setup denali core
  119. */
  120. initdram_by_rb(sdram_conf[n].rows,
  121. sdram_conf[n].banks);
  122. /* check for suitable configuration */
  123. if (get_ram_size(CONFIG_SYS_SDRAM_BASE, size) == size)
  124. return size;
  125. /* delete TLB entries */
  126. remove_tlb(CONFIG_SYS_SDRAM_BASE, size);
  127. }
  128. return 0;
  129. }