ddr.c 4.5 KB

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