ddr.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. unsigned int fsl_ddr_get_mem_data_rate(void)
  17. {
  18. return get_ddr_freq(0);
  19. }
  20. void fsl_ddr_get_spd(ddr2_spd_eeprom_t *ctrl_dimms_spd,
  21. unsigned int ctrl_num)
  22. {
  23. unsigned int i;
  24. unsigned int i2c_address = 0;
  25. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  26. if (ctrl_num == 0 && i == 0) {
  27. i2c_address = SPD_EEPROM_ADDRESS1;
  28. }
  29. if (ctrl_num == 1 && i == 0) {
  30. i2c_address = SPD_EEPROM_ADDRESS2;
  31. }
  32. get_spd(&(ctrl_dimms_spd[i]), i2c_address);
  33. }
  34. }
  35. typedef struct {
  36. u32 datarate_mhz_low;
  37. u32 datarate_mhz_high;
  38. u32 n_ranks;
  39. u32 clk_adjust;
  40. u32 cpo;
  41. u32 write_data_delay;
  42. u32 force_2T;
  43. } board_specific_parameters_t;
  44. /* ranges for parameters:
  45. * wr_data_delay = 0-6
  46. * clk adjust = 0-8
  47. * cpo 2-0x1E (30)
  48. */
  49. /* XXX: these values need to be checked for all interleaving modes. */
  50. /* XXX: No reliable dual-rank 800 MHz setting has been found. It may
  51. * seem reliable, but errors will appear when memory intensive
  52. * program is run. */
  53. /* XXX: Single rank at 800 MHz is OK. */
  54. const board_specific_parameters_t board_specific_parameters[][20] = {
  55. {
  56. /* memory controller 0 */
  57. /* lo| hi| num| clk| cpo|wrdata|2T */
  58. /* mhz| mhz|ranks|adjst| | delay| */
  59. { 0, 333, 2, 6, 7, 3, 0},
  60. {334, 400, 2, 6, 9, 3, 0},
  61. {401, 549, 2, 6, 11, 3, 0},
  62. {550, 680, 2, 1, 10, 5, 0},
  63. {681, 850, 2, 1, 12, 5, 1},
  64. { 0, 333, 1, 6, 7, 3, 0},
  65. {334, 400, 1, 6, 9, 3, 0},
  66. {401, 549, 1, 6, 11, 3, 0},
  67. {550, 680, 1, 1, 10, 5, 0},
  68. {681, 850, 1, 1, 12, 5, 0}
  69. },
  70. {
  71. /* memory controller 1 */
  72. /* lo| hi| num| clk| cpo|wrdata|2T */
  73. /* mhz| mhz|ranks|adjst| | delay| */
  74. { 0, 333, 2, 6, 7, 3, 0},
  75. {334, 400, 2, 6, 9, 3, 0},
  76. {401, 549, 2, 6, 11, 3, 0},
  77. {550, 680, 2, 1, 11, 6, 0},
  78. {681, 850, 2, 1, 13, 6, 1},
  79. { 0, 333, 1, 6, 7, 3, 0},
  80. {334, 400, 1, 6, 9, 3, 0},
  81. {401, 549, 1, 6, 11, 3, 0},
  82. {550, 680, 1, 1, 11, 6, 0},
  83. {681, 850, 1, 1, 13, 6, 0}
  84. }
  85. };
  86. void fsl_ddr_board_options(memctl_options_t *popts,
  87. dimm_params_t *pdimm,
  88. unsigned int ctrl_num)
  89. {
  90. const board_specific_parameters_t *pbsp =
  91. &(board_specific_parameters[ctrl_num][0]);
  92. u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
  93. sizeof(board_specific_parameters[0][0]);
  94. u32 i;
  95. ulong ddr_freq;
  96. /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
  97. * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
  98. * there are two dimms in the controller, set odt_rd_cfg to 3 and
  99. * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
  100. */
  101. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  102. if (i&1) { /* odd CS */
  103. popts->cs_local_opts[i].odt_rd_cfg = 0;
  104. popts->cs_local_opts[i].odt_wr_cfg = 0;
  105. } else { /* even CS */
  106. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  107. popts->cs_local_opts[i].odt_rd_cfg = 0;
  108. popts->cs_local_opts[i].odt_wr_cfg = 4;
  109. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  110. popts->cs_local_opts[i].odt_rd_cfg = 3;
  111. popts->cs_local_opts[i].odt_wr_cfg = 3;
  112. }
  113. }
  114. }
  115. /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  116. * freqency and n_banks specified in board_specific_parameters table.
  117. */
  118. ddr_freq = get_ddr_freq(0) / 1000000;
  119. for (i = 0; i < num_params; i++) {
  120. if (ddr_freq >= pbsp->datarate_mhz_low &&
  121. ddr_freq <= pbsp->datarate_mhz_high &&
  122. pdimm->n_ranks == pbsp->n_ranks) {
  123. popts->clk_adjust = pbsp->clk_adjust;
  124. popts->cpo_override = pbsp->cpo;
  125. popts->write_data_delay = pbsp->write_data_delay;
  126. popts->twoT_en = pbsp->force_2T;
  127. }
  128. pbsp++;
  129. }
  130. /*
  131. * Factors to consider for half-strength driver enable:
  132. * - number of DIMMs installed
  133. */
  134. popts->half_strength_driver_enable = 0;
  135. }