ddr.c 3.4 KB

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