ddr.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright 2009 Extreme Engineering Solutions, Inc.
  3. * Copyright 2007-2008 Freescale Semiconductor, Inc.
  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 <i2c.h>
  25. #include <asm/fsl_ddr_sdram.h>
  26. #include <asm/fsl_ddr_dimm_params.h>
  27. static void get_spd(ddr2_spd_eeprom_t *spd, unsigned char i2c_address)
  28. {
  29. i2c_read(i2c_address, SPD_EEPROM_OFFSET, 2, (uchar *)spd,
  30. sizeof(ddr2_spd_eeprom_t));
  31. }
  32. unsigned int fsl_ddr_get_mem_data_rate(void)
  33. {
  34. return get_bus_freq(0);
  35. }
  36. void fsl_ddr_get_spd(ddr2_spd_eeprom_t *ctrl_dimms_spd,
  37. unsigned int ctrl_num)
  38. {
  39. unsigned int i;
  40. unsigned int i2c_address = 0;
  41. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  42. if (ctrl_num == 0) {
  43. i2c_address = SPD_EEPROM_ADDRESS1;
  44. #ifdef SPD_EEPROM_ADDRESS2
  45. } else if (ctrl_num == 1) {
  46. i2c_address = SPD_EEPROM_ADDRESS2;
  47. #endif
  48. } else {
  49. /* An inalid ctrl number was give, use default SPD */
  50. printf("ERROR: invalid DDR ctrl: %d\n", ctrl_num);
  51. i2c_address = SPD_EEPROM_ADDRESS1;
  52. }
  53. get_spd(&(ctrl_dimms_spd[i]), i2c_address);
  54. }
  55. }
  56. /*
  57. * There are four board-specific SDRAM timing parameters which must be
  58. * calculated based on the particular PCB artwork. These are:
  59. * 1.) CPO (Read Capture Delay)
  60. * - TIMING_CFG_2 register
  61. * Source: Calculation based on board trace lengths and
  62. * chip-specific internal delays.
  63. * 2.) WR_DATA_DELAY (Write Command to Data Strobe Delay)
  64. * - TIMING_CFG_2 register
  65. * Source: Calculation based on board trace lengths.
  66. * Unless clock and DQ lanes are very different
  67. * lengths (>2"), this should be set to the nominal value
  68. * of 1/2 clock delay.
  69. * 3.) CLK_ADJUST (Clock and Addr/Cmd alignment control)
  70. * - DDR_SDRAM_CLK_CNTL register
  71. * Source: Signal Integrity Simulations
  72. * 4.) 2T Timing on Addr/Ctl
  73. * - TIMING_CFG_2 register
  74. * Source: Signal Integrity Simulations
  75. * Usually only needed with heavy load/very high speed (>DDR2-800)
  76. *
  77. * PCB routing on the XPedite5170 is nearly identical to the XPedite5370
  78. * so we use the XPedite5370 settings as a basis for the XPedite5170.
  79. */
  80. typedef struct board_memctl_options {
  81. uint16_t datarate_mhz_low;
  82. uint16_t datarate_mhz_high;
  83. uint8_t clk_adjust;
  84. uint8_t cpo_override;
  85. uint8_t write_data_delay;
  86. } board_memctl_options_t;
  87. static struct board_memctl_options bopts_ctrl[][2] = {
  88. {
  89. /* Controller 0 */
  90. {
  91. /* DDR2 600/667 */
  92. .datarate_mhz_low = 500,
  93. .datarate_mhz_high = 750,
  94. .clk_adjust = 5,
  95. .cpo_override = 8,
  96. .write_data_delay = 2,
  97. },
  98. {
  99. /* DDR2 800 */
  100. .datarate_mhz_low = 750,
  101. .datarate_mhz_high = 850,
  102. .clk_adjust = 5,
  103. .cpo_override = 9,
  104. .write_data_delay = 2,
  105. },
  106. },
  107. {
  108. /* Controller 1 */
  109. {
  110. /* DDR2 600/667 */
  111. .datarate_mhz_low = 500,
  112. .datarate_mhz_high = 750,
  113. .clk_adjust = 5,
  114. .cpo_override = 7,
  115. .write_data_delay = 2,
  116. },
  117. {
  118. /* DDR2 800 */
  119. .datarate_mhz_low = 750,
  120. .datarate_mhz_high = 850,
  121. .clk_adjust = 5,
  122. .cpo_override = 8,
  123. .write_data_delay = 2,
  124. },
  125. },
  126. };
  127. void fsl_ddr_board_options(memctl_options_t *popts,
  128. dimm_params_t *pdimm,
  129. unsigned int ctrl_num)
  130. {
  131. struct board_memctl_options *bopts = bopts_ctrl[ctrl_num];
  132. sys_info_t sysinfo;
  133. int i;
  134. unsigned int datarate;
  135. get_sys_info(&sysinfo);
  136. datarate = fsl_ddr_get_mem_data_rate() / 1000000;
  137. for (i = 0; i < ARRAY_SIZE(bopts_ctrl[ctrl_num]); i++) {
  138. if ((bopts[i].datarate_mhz_low <= datarate) &&
  139. (bopts[i].datarate_mhz_high >= datarate)) {
  140. debug("controller %d:\n", ctrl_num);
  141. debug(" clk_adjust = %d\n", bopts[i].clk_adjust);
  142. debug(" cpo = %d\n", bopts[i].cpo_override);
  143. debug(" write_data_delay = %d\n",
  144. bopts[i].write_data_delay);
  145. popts->clk_adjust = bopts[i].clk_adjust;
  146. popts->cpo_override = bopts[i].cpo_override;
  147. popts->write_data_delay = bopts[i].write_data_delay;
  148. }
  149. }
  150. /*
  151. * Factors to consider for half-strength driver enable:
  152. * - number of DIMMs installed
  153. */
  154. popts->half_strength_driver_enable = 0;
  155. }