ddr.c 4.7 KB

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