ddr.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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
  13. get_spd(ddr2_spd_eeprom_t *spd, unsigned char i2c_address)
  14. {
  15. i2c_read(i2c_address, 0, 1, (uchar *)spd, sizeof(ddr2_spd_eeprom_t));
  16. }
  17. void fsl_ddr_get_spd(ddr2_spd_eeprom_t *ctrl_dimms_spd,
  18. unsigned int ctrl_num)
  19. {
  20. unsigned int i;
  21. unsigned int i2c_address = 0;
  22. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  23. if (ctrl_num == 0 && i == 0) {
  24. i2c_address = SPD_EEPROM_ADDRESS1;
  25. }
  26. if (ctrl_num == 0 && i == 1) {
  27. i2c_address = SPD_EEPROM_ADDRESS2;
  28. }
  29. if (ctrl_num == 1 && i == 0) {
  30. i2c_address = SPD_EEPROM_ADDRESS3;
  31. }
  32. if (ctrl_num == 1 && i == 1) {
  33. i2c_address = SPD_EEPROM_ADDRESS4;
  34. }
  35. get_spd(&(ctrl_dimms_spd[i]), i2c_address);
  36. }
  37. }
  38. typedef struct {
  39. u32 datarate_mhz_low;
  40. u32 datarate_mhz_high;
  41. u32 n_ranks;
  42. u32 clk_adjust;
  43. u32 cpo;
  44. u32 write_data_delay;
  45. } board_specific_parameters_t;
  46. /* XXX: these values need to be checked for all interleaving modes. */
  47. const board_specific_parameters_t board_specific_parameters[2][16] = {
  48. {
  49. /* memory controller 0 */
  50. /* lo| hi| num| clk| cpo|wrdata */
  51. /* mhz| mhz|ranks|adjst| | delay */
  52. { 0, 333, 4, 7, 7, 3},
  53. {334, 400, 4, 7, 9, 3},
  54. {401, 549, 4, 7, 9, 3},
  55. {550, 650, 4, 7, 10, 4},
  56. { 0, 333, 3, 7, 7, 3},
  57. {334, 400, 3, 7, 9, 3},
  58. {401, 549, 3, 7, 9, 3},
  59. {550, 650, 3, 7, 10, 4},
  60. { 0, 333, 2, 7, 7, 3},
  61. {334, 400, 2, 7, 9, 3},
  62. {401, 549, 2, 7, 9, 3},
  63. {550, 650, 2, 7, 10, 4},
  64. { 0, 333, 1, 7, 7, 3},
  65. {334, 400, 1, 7, 9, 3},
  66. {401, 549, 1, 7, 9, 3},
  67. {550, 650, 1, 7, 10, 4}
  68. },
  69. {
  70. /* memory controller 1 */
  71. /* lo| hi| num| clk| cpo|wrdata */
  72. /* mhz| mhz|ranks|adjst| | delay */
  73. { 0, 333, 4, 7, 7, 3},
  74. {334, 400, 4, 7, 9, 3},
  75. {401, 549, 4, 7, 9, 3},
  76. {550, 650, 4, 7, 10, 4},
  77. { 0, 333, 3, 7, 7, 3},
  78. {334, 400, 3, 7, 9, 3},
  79. {401, 549, 3, 7, 9, 3},
  80. {550, 650, 3, 7, 10, 4},
  81. { 0, 333, 2, 7, 7, 3},
  82. {334, 400, 2, 7, 9, 3},
  83. {401, 549, 2, 7, 9, 3},
  84. {550, 650, 2, 7, 10, 4},
  85. { 0, 333, 1, 7, 7, 3},
  86. {334, 400, 1, 7, 9, 3},
  87. {401, 549, 1, 7, 9, 3},
  88. {550, 650, 1, 7, 10, 4}
  89. }
  90. };
  91. void fsl_ddr_board_options(memctl_options_t *popts,
  92. dimm_params_t *pdimm,
  93. unsigned int ctrl_num)
  94. {
  95. const board_specific_parameters_t *pbsp =
  96. &(board_specific_parameters[ctrl_num][0]);
  97. u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
  98. sizeof(board_specific_parameters[0][0]);
  99. u32 i;
  100. u32 j;
  101. ulong ddr_freq;
  102. /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
  103. * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
  104. * there are two dimms in the controller, set odt_rd_cfg to 3 and
  105. * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
  106. */
  107. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  108. if (i&1) { /* odd CS */
  109. popts->cs_local_opts[i].odt_rd_cfg = 0;
  110. popts->cs_local_opts[i].odt_wr_cfg = 0;
  111. } else { /* even CS */
  112. if ((CONFIG_DIMM_SLOTS_PER_CTLR == 2) &&
  113. (pdimm[i/2].n_ranks != 0)) {
  114. popts->cs_local_opts[i].odt_rd_cfg = 3;
  115. popts->cs_local_opts[i].odt_wr_cfg = 3;
  116. } else {
  117. popts->cs_local_opts[i].odt_rd_cfg = 0;
  118. popts->cs_local_opts[i].odt_wr_cfg = 4;
  119. }
  120. }
  121. }
  122. /* Get clk_adjust, cpo, write_data_delay, according to the board ddr
  123. * freqency and n_banks specified in board_specific_parameters table.
  124. */
  125. ddr_freq = get_ddr_freq(0) / 1000000;
  126. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
  127. if (pdimm[j].n_ranks > 0) {
  128. for (i = 0; i < num_params; i++) {
  129. if (ddr_freq >= pbsp->datarate_mhz_low &&
  130. ddr_freq <= pbsp->datarate_mhz_high &&
  131. pdimm[j].n_ranks == pbsp->n_ranks) {
  132. popts->clk_adjust = pbsp->clk_adjust;
  133. popts->cpo_override = pbsp->cpo;
  134. popts->write_data_delay =
  135. pbsp->write_data_delay;
  136. break;
  137. }
  138. pbsp++;
  139. }
  140. }
  141. }
  142. /* 2T timing enable */
  143. popts->twoT_en = 1;
  144. }