ddr.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2008-2009 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(ddr3_spd_eeprom_t *spd, unsigned char i2c_address)
  13. {
  14. i2c_read(i2c_address, 0, 1, (uchar *)spd, sizeof(ddr3_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(ddr3_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. 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. /* ranges for parameters:
  41. * wr_data_delay = 0-6
  42. * clk adjust = 0-8
  43. * cpo 2-0x1E (30)
  44. */
  45. /* XXX: these values need to be checked for all interleaving modes. */
  46. /* XXX: No reliable dual-rank 800 MHz setting has been found. It may
  47. * seem reliable, but errors will appear when memory intensive
  48. * program is run. */
  49. /* XXX: Single rank at 800 MHz is OK. */
  50. const board_specific_parameters_t board_specific_parameters[][20] = {
  51. {
  52. /* memory controller 0 */
  53. /* lo| hi| num| clk| cpo|wrdata|2T */
  54. /* mhz| mhz|ranks|adjst| | delay| */
  55. { 0, 333, 2, 6, 7, 3, 0},
  56. {334, 400, 2, 6, 9, 3, 0},
  57. {401, 549, 2, 6, 11, 3, 0},
  58. {550, 680, 2, 1, 10, 5, 0},
  59. {681, 850, 2, 1, 12, 5, 1},
  60. { 0, 333, 1, 6, 7, 3, 0},
  61. {334, 400, 1, 6, 9, 3, 0},
  62. {401, 549, 1, 6, 11, 3, 0},
  63. {550, 680, 1, 1, 10, 5, 0},
  64. {681, 850, 1, 1, 12, 5, 0}
  65. },
  66. };
  67. void fsl_ddr_board_options(memctl_options_t *popts,
  68. dimm_params_t *pdimm,
  69. unsigned int ctrl_num)
  70. {
  71. const board_specific_parameters_t *pbsp =
  72. &(board_specific_parameters[ctrl_num][0]);
  73. u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
  74. sizeof(board_specific_parameters[0][0]);
  75. u32 i;
  76. ulong ddr_freq;
  77. /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
  78. * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
  79. * there are two dimms in the controller, set odt_rd_cfg to 3 and
  80. * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
  81. */
  82. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  83. if (i&1) { /* odd CS */
  84. popts->cs_local_opts[i].odt_rd_cfg = 0;
  85. popts->cs_local_opts[i].odt_wr_cfg = 0;
  86. } else { /* even CS */
  87. if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
  88. popts->cs_local_opts[i].odt_rd_cfg = 0;
  89. popts->cs_local_opts[i].odt_wr_cfg = 4;
  90. } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
  91. popts->cs_local_opts[i].odt_rd_cfg = 3;
  92. popts->cs_local_opts[i].odt_wr_cfg = 3;
  93. }
  94. }
  95. }
  96. /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  97. * freqency and n_banks specified in board_specific_parameters table.
  98. */
  99. ddr_freq = get_ddr_freq(0) / 1000000;
  100. for (i = 0; i < num_params; i++) {
  101. if (ddr_freq >= pbsp->datarate_mhz_low &&
  102. ddr_freq <= pbsp->datarate_mhz_high &&
  103. pdimm->n_ranks == pbsp->n_ranks) {
  104. popts->clk_adjust = pbsp->clk_adjust;
  105. popts->cpo_override = pbsp->cpo;
  106. popts->write_data_delay = pbsp->write_data_delay;
  107. popts->twoT_en = pbsp->force_2T;
  108. }
  109. pbsp++;
  110. }
  111. /*
  112. * Factors to consider for half-strength driver enable:
  113. * - number of DIMMs installed
  114. */
  115. popts->half_strength_driver_enable = 0;
  116. }