ddr.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright 2008 Extreme Engineering Solutions, Inc.
  3. * Copyright 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. * ====== XPedite5370 DDR2-600 read delay calculations ======
  54. *
  55. * See Freescale's App Note AN2583 as refrence. This document also
  56. * contains the chip-specific delays for 8548E, 8572, etc.
  57. *
  58. * For MPC8572E
  59. * Minimum chip delay (Ch 0): 1.372ns
  60. * Maximum chip delay (Ch 0): 2.914ns
  61. * Minimum chip delay (Ch 1): 1.220ns
  62. * Maximum chip delay (Ch 1): 2.595ns
  63. *
  64. * CLK adjust = 5 (from simulations) = 5/8* 3.33ns = 2080ps
  65. *
  66. * Minimum delay calc (Ch 0):
  67. * clock prop - dram skew + min dqs prop delay + clk_adjust + min chip dly
  68. * 2.3" * 180 - 400ps + 1.9" * 180 + 2080ps + 1372ps
  69. * = 3808ps
  70. * = 3.808ns
  71. *
  72. * Maximum delay calc (Ch 0):
  73. * clock prop + dram skew + max dqs prop delay + clk_adjust + max chip dly
  74. * 2.3" * 180 + 400ps + 2.4" * 180 + 2080ps + 2914ps
  75. * = 6240ps
  76. * = 6.240ns
  77. *
  78. * Minimum delay calc (Ch 1):
  79. * clock prop - dram skew + min dqs prop delay + clk_adjust + min chip dly
  80. * 1.46" * 180- 400ps + 0.7" * 180 + 2080ps + 1220ps
  81. * = 3288ps
  82. * = 3.288ns
  83. *
  84. * Maximum delay calc (Ch 1):
  85. * clock prop + dram skew + max dqs prop delay + clk_adjust + min chip dly
  86. * 1.46" * 180+ 400ps + 1.1" * 180 + 2080ps + 2595ps
  87. * = 5536ps
  88. * = 5.536ns
  89. *
  90. * Ch.0: 3.808ns to 6.240ns additional delay needed (pick 5ns as target)
  91. * This is 1.5 clock cycles, pick CPO = READ_LAT + 3/2 (0x8)
  92. * Ch.1: 3.288ns to 5.536ns additional delay needed (pick 4.4ns as target)
  93. * This is 1.32 clock cycles, pick CPO = READ_LAT + 5/4 (0x7)
  94. *
  95. *
  96. * ====== XPedite5370 DDR2-800 read delay calculations ======
  97. *
  98. * See Freescale's App Note AN2583 as refrence. This document also
  99. * contains the chip-specific delays for 8548E, 8572, etc.
  100. *
  101. * For MPC8572E
  102. * Minimum chip delay (Ch 0): 1.372ns
  103. * Maximum chip delay (Ch 0): 2.914ns
  104. * Minimum chip delay (Ch 1): 1.220ns
  105. * Maximum chip delay (Ch 1): 2.595ns
  106. *
  107. * CLK adjust = 5 (from simulations) = 5/8* 2.5ns = 1563ps
  108. *
  109. * Minimum delay calc (Ch 0):
  110. * clock prop - dram skew + min dqs prop delay + clk_adjust + min chip dly
  111. * 2.3" * 180 - 350ps + 1.9" * 180 + 1563ps + 1372ps
  112. * = 3341ps
  113. * = 3.341ns
  114. *
  115. * Maximum delay calc (Ch 0):
  116. * clock prop + dram skew + max dqs prop delay + clk_adjust + max chip dly
  117. * 2.3" * 180 + 350ps + 2.4" * 180 + 1563ps + 2914ps
  118. * = 5673ps
  119. * = 5.673ns
  120. *
  121. * Minimum delay calc (Ch 1):
  122. * clock prop - dram skew + min dqs prop delay + clk_adjust + min chip dly
  123. * 1.46" * 180- 350ps + 0.7" * 180 + 1563ps + 1220ps
  124. * = 2822ps
  125. * = 2.822ns
  126. *
  127. * Maximum delay calc (Ch 1):
  128. * clock prop + dram skew + max dqs prop delay + clk_adjust + min chip dly
  129. * 1.46" * 180+ 350ps + 1.1" * 180 + 1563ps + 2595ps
  130. * = 4968ps
  131. * = 4.968ns
  132. *
  133. * Ch.0: 3.341ns to 5.673ns additional delay needed (pick 4.5ns as target)
  134. * This is 1.8 clock cycles, pick CPO = READ_LAT + 7/4 (0x9)
  135. * Ch.1: 2.822ns to 4.968ns additional delay needed (pick 3.9ns as target)
  136. * This is 1.56 clock cycles, pick CPO = READ_LAT + 3/2 (0x8)
  137. *
  138. * Write latency (WR_DATA_DELAY) is calculated by doing the following:
  139. *
  140. * The DDR SDRAM specification requires DQS be received no sooner than
  141. * 75% of an SDRAM clock period—and no later than 125% of a clock
  142. * period—from the capturing clock edge of the command/address at the
  143. * SDRAM.
  144. *
  145. * Based on the above tracelengths, the following are calculated:
  146. * Ch. 0 8572 to DRAM propagation (DQ lanes) : 1.9" * 180 = 0.342ns
  147. * Ch. 0 8572 to DRAM propagation (CLKs) : 2.3" * 180 = 0.414ns
  148. * Ch. 1 8572 to DRAM propagation (DQ lanes) : 0.7" * 180 = 0.126ns
  149. * Ch. 1 8572 to DRAM propagation (CLKs ) : 1.47" * 180 = 0.264ns
  150. *
  151. * Difference in arrival time CLK vs. DQS:
  152. * Ch. 0 0.072ns
  153. * Ch. 1 0.138ns
  154. *
  155. * Both of these values are much less than 25% of the clock
  156. * period at DDR2-600 or DDR2-800, so no additional delay is needed over
  157. * the 1/2 cycle which normally aligns the first DQS transition
  158. * exactly WL (CAS latency minus one cycle) after the CAS strobe.
  159. * See Figure 9-53 in MPC8572E manual: "1/2 delay" in Freescale's
  160. * terminology corresponds to exactly one clock period delay after
  161. * the CAS strobe. (due to the fact that the "delay" is referenced
  162. * from the *falling* edge of the CLK, just after the rising edge
  163. * which the CAS strobe is latched on.
  164. */
  165. typedef struct board_memctl_options {
  166. uint16_t datarate_mhz_low;
  167. uint16_t datarate_mhz_high;
  168. uint8_t clk_adjust;
  169. uint8_t cpo_override;
  170. uint8_t write_data_delay;
  171. } board_memctl_options_t;
  172. static struct board_memctl_options bopts_ctrl[][2] = {
  173. {
  174. /* Controller 0 */
  175. {
  176. /* DDR2 600/667 */
  177. .datarate_mhz_low = 500,
  178. .datarate_mhz_high = 750,
  179. .clk_adjust = 5,
  180. .cpo_override = 8,
  181. .write_data_delay = 2,
  182. },
  183. {
  184. /* DDR2 800 */
  185. .datarate_mhz_low = 750,
  186. .datarate_mhz_high = 850,
  187. .clk_adjust = 5,
  188. .cpo_override = 9,
  189. .write_data_delay = 2,
  190. },
  191. },
  192. {
  193. /* Controller 1 */
  194. {
  195. /* DDR2 600/667 */
  196. .datarate_mhz_low = 500,
  197. .datarate_mhz_high = 750,
  198. .clk_adjust = 5,
  199. .cpo_override = 7,
  200. .write_data_delay = 2,
  201. },
  202. {
  203. /* DDR2 800 */
  204. .datarate_mhz_low = 750,
  205. .datarate_mhz_high = 850,
  206. .clk_adjust = 5,
  207. .cpo_override = 8,
  208. .write_data_delay = 2,
  209. },
  210. },
  211. };
  212. void fsl_ddr_board_options(memctl_options_t *popts,
  213. dimm_params_t *pdimm,
  214. unsigned int ctrl_num)
  215. {
  216. struct board_memctl_options *bopts = bopts_ctrl[ctrl_num];
  217. sys_info_t sysinfo;
  218. int i;
  219. unsigned int datarate;
  220. get_sys_info(&sysinfo);
  221. datarate = sysinfo.freqDDRBus / 1000 / 1000;
  222. for (i = 0; i < ARRAY_SIZE(bopts_ctrl[ctrl_num]); i++) {
  223. if ((bopts[i].datarate_mhz_low <= datarate) &&
  224. (bopts[i].datarate_mhz_high >= datarate)) {
  225. debug("controller %d:\n", ctrl_num);
  226. debug(" clk_adjust = %d\n", bopts[i].clk_adjust);
  227. debug(" cpo = %d\n", bopts[i].cpo_override);
  228. debug(" write_data_delay = %d\n",
  229. bopts[i].write_data_delay);
  230. popts->clk_adjust = bopts[i].clk_adjust;
  231. popts->cpo_override = bopts[i].cpo_override;
  232. popts->write_data_delay = bopts[i].write_data_delay;
  233. }
  234. }
  235. /*
  236. * Factors to consider for half-strength driver enable:
  237. * - number of DIMMs installed
  238. */
  239. popts->half_strength_driver_enable = 0;
  240. }