sdram.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. * SPDX-License-Identifier: GPL-2.0+
  16. */
  17. /* define DEBUG for debug output */
  18. #undef DEBUG
  19. #include <common.h>
  20. #include <asm/processor.h>
  21. #include <asm/io.h>
  22. #include <asm/mmu.h>
  23. #include <asm/ppc440.h>
  24. extern int denali_wait_for_dlllock(void);
  25. extern void denali_core_search_data_eye(void);
  26. struct sdram_conf_s {
  27. ulong size;
  28. int rows;
  29. int banks;
  30. };
  31. struct sdram_conf_s sdram_conf[] = {
  32. {(1024 << 20), 14, 8}, /* 1GByte: 4x2GBit, 14x10, 8 banks */
  33. {(512 << 20), 13, 8}, /* 512MByte: 4x1GBit, 13x10, 8 banks */
  34. {(256 << 20), 13, 4}, /* 256MByte: 4x512MBit, 13x10, 4 banks */
  35. };
  36. /*
  37. * initdram -- 440EPx's DDR controller is a DENALI Core
  38. */
  39. int initdram_by_rb(int rows, int banks)
  40. {
  41. ulong speed = get_bus_freq(0);
  42. mtsdram(DDR0_02, 0x00000000);
  43. mtsdram(DDR0_00, 0x0000190A);
  44. mtsdram(DDR0_01, 0x01000000);
  45. mtsdram(DDR0_03, 0x02030602);
  46. mtsdram(DDR0_04, 0x0A020200);
  47. mtsdram(DDR0_05, 0x02020308);
  48. mtsdram(DDR0_06, 0x0102C812);
  49. mtsdram(DDR0_07, 0x000D0100);
  50. mtsdram(DDR0_08, 0x02430001);
  51. mtsdram(DDR0_09, 0x00011D5F);
  52. mtsdram(DDR0_10, 0x00000100);
  53. mtsdram(DDR0_11, 0x0027C800);
  54. mtsdram(DDR0_12, 0x00000003);
  55. mtsdram(DDR0_14, 0x00000000);
  56. mtsdram(DDR0_17, 0x19000000);
  57. mtsdram(DDR0_18, 0x19191919);
  58. mtsdram(DDR0_19, 0x19191919);
  59. mtsdram(DDR0_20, 0x0B0B0B0B);
  60. mtsdram(DDR0_21, 0x0B0B0B0B);
  61. mtsdram(DDR0_22, 0x00267F0B);
  62. mtsdram(DDR0_23, 0x00000000);
  63. mtsdram(DDR0_24, 0x01010002);
  64. if (speed > 133333334)
  65. mtsdram(DDR0_26, 0x5B26050C);
  66. else
  67. mtsdram(DDR0_26, 0x5B260408);
  68. mtsdram(DDR0_27, 0x0000682B);
  69. mtsdram(DDR0_28, 0x00000000);
  70. mtsdram(DDR0_31, 0x00000000);
  71. mtsdram(DDR0_42,
  72. DDR0_42_ADDR_PINS_DECODE(14 - rows) |
  73. 0x00000006);
  74. mtsdram(DDR0_43,
  75. DDR0_43_EIGHT_BANK_MODE_ENCODE(8 == banks ? 1 : 0) |
  76. 0x030A0200);
  77. mtsdram(DDR0_44, 0x00000003);
  78. mtsdram(DDR0_02, 0x00000001);
  79. denali_wait_for_dlllock();
  80. #ifdef CONFIG_DDR_DATA_EYE
  81. /*
  82. * Perform data eye search if requested.
  83. */
  84. denali_core_search_data_eye();
  85. #endif
  86. /*
  87. * Clear possible errors resulting from data-eye-search.
  88. * If not done, then we could get an interrupt later on when
  89. * exceptions are enabled.
  90. */
  91. set_mcsr(get_mcsr());
  92. return 0;
  93. }
  94. phys_size_t initdram(int board_type)
  95. {
  96. phys_size_t size;
  97. int n;
  98. /* go through supported memory configurations */
  99. for (n = 0; n < ARRAY_SIZE(sdram_conf); n++) {
  100. size = sdram_conf[n].size;
  101. /* program TLB entries */
  102. program_tlb(0, CONFIG_SYS_SDRAM_BASE, size,
  103. TLB_WORD2_I_ENABLE);
  104. /*
  105. * setup denali core
  106. */
  107. initdram_by_rb(sdram_conf[n].rows,
  108. sdram_conf[n].banks);
  109. /* check for suitable configuration */
  110. if (get_ram_size(CONFIG_SYS_SDRAM_BASE, size) == size)
  111. return size;
  112. /* delete TLB entries */
  113. remove_tlb(CONFIG_SYS_SDRAM_BASE, size);
  114. }
  115. return 0;
  116. }