ddr.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2010 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(ddr3_spd_eeprom_t *spd, u8 i2c_address)
  28. {
  29. i2c_read(i2c_address, SPD_EEPROM_OFFSET, 2, (uchar *)spd,
  30. sizeof(ddr3_spd_eeprom_t));
  31. }
  32. /*
  33. * There are traditionally three board-specific SDRAM timing parameters
  34. * which must be 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.) CLK_ADJUST (Clock and Addr/Cmd alignment control)
  40. * - DDR_SDRAM_CLK_CNTL register
  41. * Source: Signal Integrity Simulations
  42. * 3.) 2T Timing on Addr/Ctl
  43. * - TIMING_CFG_2 register
  44. * Source: Signal Integrity Simulations
  45. * Usually only needed with heavy load/very high speed (>DDR2-800)
  46. *
  47. * ====== XPedite550x DDR3-800 read delay calculations ======
  48. *
  49. * The P2020 processor provides an autoleveling option. Setting CPO to
  50. * 0x1f enables this auto configuration.
  51. */
  52. typedef struct {
  53. unsigned short datarate_mhz_low;
  54. unsigned short datarate_mhz_high;
  55. unsigned char clk_adjust;
  56. unsigned char cpo;
  57. } board_specific_parameters_t;
  58. const board_specific_parameters_t board_specific_parameters[][20] = {
  59. {
  60. /* Controller 0 */
  61. {
  62. /* DDR3-600/667 */
  63. .datarate_mhz_low = 500,
  64. .datarate_mhz_high = 750,
  65. .clk_adjust = 5,
  66. .cpo = 31,
  67. },
  68. {
  69. /* DDR3-800 */
  70. .datarate_mhz_low = 750,
  71. .datarate_mhz_high = 850,
  72. .clk_adjust = 5,
  73. .cpo = 31,
  74. },
  75. },
  76. };
  77. void fsl_ddr_board_options(memctl_options_t *popts,
  78. dimm_params_t *pdimm,
  79. unsigned int ctrl_num)
  80. {
  81. const board_specific_parameters_t *pbsp =
  82. &(board_specific_parameters[ctrl_num][0]);
  83. u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
  84. sizeof(board_specific_parameters[0][0]);
  85. u32 i;
  86. ulong ddr_freq;
  87. /*
  88. * Set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
  89. * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
  90. * there are two dimms in the controller, set odt_rd_cfg to 3 and
  91. * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
  92. */
  93. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  94. if (i&1) { /* odd CS */
  95. popts->cs_local_opts[i].odt_rd_cfg = 0;
  96. popts->cs_local_opts[i].odt_wr_cfg = 0;
  97. } else { /* even CS */
  98. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  99. popts->cs_local_opts[i].odt_rd_cfg = 0;
  100. popts->cs_local_opts[i].odt_wr_cfg = 4;
  101. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  102. popts->cs_local_opts[i].odt_rd_cfg = 3;
  103. popts->cs_local_opts[i].odt_wr_cfg = 3;
  104. }
  105. }
  106. }
  107. /*
  108. * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  109. * freqency and n_banks specified in board_specific_parameters table.
  110. */
  111. ddr_freq = get_ddr_freq(0) / 1000000;
  112. for (i = 0; i < num_params; i++) {
  113. if (ddr_freq >= pbsp->datarate_mhz_low &&
  114. ddr_freq <= pbsp->datarate_mhz_high) {
  115. popts->clk_adjust = pbsp->clk_adjust;
  116. popts->cpo_override = pbsp->cpo;
  117. popts->twoT_en = 0;
  118. }
  119. pbsp++;
  120. }
  121. /*
  122. * Factors to consider for half-strength driver enable:
  123. * - number of DIMMs installed
  124. */
  125. popts->half_strength_driver_enable = 0;
  126. /*
  127. * Enable on-die termination.
  128. * From the Micron Technical Node TN-41-04, RTT_Nom should typically
  129. * be 30 to 40 ohms, while RTT_WR should be 120 ohms. Setting RTT_WR
  130. * is handled in the Freescale DDR3 driver. Set RTT_Nom here.
  131. */
  132. popts->rtt_override = 1;
  133. popts->rtt_override_value = 3;
  134. }