ddr.c 9.7 KB

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