ddr.c 4.1 KB

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