ddr.c 9.7 KB

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