ddr.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 as published by the Free Software Foundation.
  7. */
  8. #include <common.h>
  9. #include <i2c.h>
  10. #include <asm/fsl_ddr_sdram.h>
  11. #include <asm/fsl_ddr_dimm_params.h>
  12. static void get_spd(ddr2_spd_eeprom_t *spd, unsigned char i2c_address)
  13. {
  14. i2c_read(i2c_address, 0, 1, (uchar *)spd, sizeof(ddr2_spd_eeprom_t));
  15. }
  16. void fsl_ddr_get_spd(ddr2_spd_eeprom_t *ctrl_dimms_spd,
  17. unsigned int ctrl_num)
  18. {
  19. unsigned int i;
  20. unsigned int i2c_address = 0;
  21. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  22. if (ctrl_num == 0 && i == 0) {
  23. i2c_address = SPD_EEPROM_ADDRESS1;
  24. }
  25. if (ctrl_num == 1 && i == 0) {
  26. i2c_address = SPD_EEPROM_ADDRESS2;
  27. }
  28. get_spd(&(ctrl_dimms_spd[i]), i2c_address);
  29. }
  30. }
  31. typedef struct {
  32. u32 datarate_mhz_low;
  33. u32 datarate_mhz_high;
  34. u32 n_ranks;
  35. u32 clk_adjust;
  36. u32 cpo;
  37. u32 write_data_delay;
  38. u32 force_2T;
  39. } board_specific_parameters_t;
  40. /*
  41. * CPO value doesn't matter if workaround for errata 111 and 134 enabled.
  42. *
  43. * For DDR2 DIMM, all combinations of clk_adjust and write_data_delay have been
  44. * tested. For RDIMM, clk_adjust = 4 and write_data_delay = 3 is optimized for
  45. * all clocks from 400MT/s to 800MT/s, verified with Kingston KVR800D2D8P6/2G.
  46. * For UDIMM, clk_adjust = 8 and write_delay = 5 is optimized for all clocks
  47. * from 400MT/s to 800MT/s, verified with Micron MT18HTF25672AY-800E1.
  48. */
  49. const board_specific_parameters_t board_specific_parameters_udimm[][20] = {
  50. {
  51. /*
  52. * memory controller 0
  53. * lo| hi| num| clk| cpo|wrdata|2T
  54. * mhz| mhz|ranks|adjst| | delay|
  55. */
  56. { 0, 333, 2, 8, 7, 5, 0},
  57. {334, 400, 2, 8, 9, 5, 0},
  58. {401, 549, 2, 8, 11, 5, 0},
  59. {550, 680, 2, 8, 10, 5, 0},
  60. {681, 850, 2, 8, 12, 5, 1},
  61. { 0, 333, 1, 6, 7, 3, 0},
  62. {334, 400, 1, 6, 9, 3, 0},
  63. {401, 549, 1, 6, 11, 3, 0},
  64. {550, 680, 1, 1, 10, 5, 0},
  65. {681, 850, 1, 1, 12, 5, 0}
  66. },
  67. {
  68. /*
  69. * memory controller 1
  70. * lo| hi| num| clk| cpo|wrdata|2T
  71. * mhz| mhz|ranks|adjst| | delay|
  72. */
  73. { 0, 333, 2, 8, 7, 5, 0},
  74. {334, 400, 2, 8, 9, 5, 0},
  75. {401, 549, 2, 8, 11, 5, 0},
  76. {550, 680, 2, 8, 11, 5, 0},
  77. {681, 850, 2, 8, 13, 5, 1},
  78. { 0, 333, 1, 6, 7, 3, 0},
  79. {334, 400, 1, 6, 9, 3, 0},
  80. {401, 549, 1, 6, 11, 3, 0},
  81. {550, 680, 1, 1, 11, 6, 0},
  82. {681, 850, 1, 1, 13, 6, 0}
  83. }
  84. };
  85. const board_specific_parameters_t board_specific_parameters_rdimm[][20] = {
  86. {
  87. /*
  88. * memory controller 0
  89. * lo| hi| num| clk| cpo|wrdata|2T
  90. * mhz| mhz|ranks|adjst| | delay|
  91. */
  92. { 0, 333, 2, 4, 7, 3, 0},
  93. {334, 400, 2, 4, 9, 3, 0},
  94. {401, 549, 2, 4, 11, 3, 0},
  95. {550, 680, 2, 4, 10, 3, 0},
  96. {681, 850, 2, 4, 12, 3, 1},
  97. },
  98. {
  99. /*
  100. * memory controller 1
  101. * lo| hi| num| clk| cpo|wrdata|2T
  102. * mhz| mhz|ranks|adjst| | delay|
  103. */
  104. { 0, 333, 2, 4, 7, 3, 0},
  105. {334, 400, 2, 4, 9, 3, 0},
  106. {401, 549, 2, 4, 11, 3, 0},
  107. {550, 680, 2, 4, 11, 3, 0},
  108. {681, 850, 2, 4, 13, 3, 1},
  109. }
  110. };
  111. void fsl_ddr_board_options(memctl_options_t *popts,
  112. dimm_params_t *pdimm,
  113. unsigned int ctrl_num)
  114. {
  115. const board_specific_parameters_t *pbsp;
  116. u32 num_params;
  117. u32 i;
  118. ulong ddr_freq;
  119. int matched = 0;
  120. if (!pdimm->n_ranks)
  121. return;
  122. if (popts->registered_dimm_en) {
  123. pbsp = &(board_specific_parameters_rdimm[ctrl_num][0]);
  124. num_params = sizeof(board_specific_parameters_rdimm[ctrl_num]) /
  125. sizeof(board_specific_parameters_rdimm[0][0]);
  126. } else {
  127. pbsp = &(board_specific_parameters_udimm[ctrl_num][0]);
  128. num_params = sizeof(board_specific_parameters_udimm[ctrl_num]) /
  129. sizeof(board_specific_parameters_udimm[0][0]);
  130. }
  131. /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
  132. * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
  133. * there are two dimms in the controller, set odt_rd_cfg to 3 and
  134. * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
  135. */
  136. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  137. if (i&1) { /* odd CS */
  138. popts->cs_local_opts[i].odt_rd_cfg = 0;
  139. popts->cs_local_opts[i].odt_wr_cfg = 0;
  140. } else { /* even CS */
  141. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  142. popts->cs_local_opts[i].odt_rd_cfg = 0;
  143. popts->cs_local_opts[i].odt_wr_cfg = 4;
  144. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  145. popts->cs_local_opts[i].odt_rd_cfg = 3;
  146. popts->cs_local_opts[i].odt_wr_cfg = 3;
  147. }
  148. }
  149. }
  150. /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  151. * freqency and n_banks specified in board_specific_parameters table.
  152. */
  153. ddr_freq = get_ddr_freq(0) / 1000000;
  154. for (i = 0; i < num_params; i++) {
  155. if (ddr_freq >= pbsp->datarate_mhz_low &&
  156. ddr_freq <= pbsp->datarate_mhz_high &&
  157. pdimm->n_ranks == pbsp->n_ranks) {
  158. popts->clk_adjust = pbsp->clk_adjust;
  159. popts->cpo_override = pbsp->cpo;
  160. popts->write_data_delay = pbsp->write_data_delay;
  161. popts->twoT_en = pbsp->force_2T;
  162. matched = 1;
  163. break;
  164. }
  165. pbsp++;
  166. }
  167. if (!matched)
  168. printf("Warning: board specific timing not found!\n");
  169. /*
  170. * Factors to consider for half-strength driver enable:
  171. * - number of DIMMs installed
  172. */
  173. popts->half_strength_driver_enable = 0;
  174. }