ddr.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/fsl_ddr_sdram.h>
  24. #include <asm/fsl_ddr_dimm_params.h>
  25. struct board_specific_parameters {
  26. u32 n_ranks;
  27. u32 datarate_mhz_high;
  28. u32 clk_adjust;
  29. u32 cpo;
  30. u32 write_data_delay;
  31. u32 force_2T;
  32. };
  33. /*
  34. * This table contains all valid speeds we want to override with board
  35. * specific parameters. datarate_mhz_high values need to be in ascending order
  36. * for each n_ranks group.
  37. */
  38. static const struct board_specific_parameters udimm0[] = {
  39. /*
  40. * memory controller 0
  41. * num| hi| clk| cpo|wrdata|2T
  42. * ranks| mhz|adjst| | delay|
  43. */
  44. {2, 300, 4, 4, 2, 0},
  45. {2, 365, 4, 6, 2, 0},
  46. {2, 450, 4, 7, 2, 0},
  47. {2, 850, 4, 31, 2, 0},
  48. {1, 300, 4, 4, 2, 0},
  49. {1, 365, 4, 6, 2, 0},
  50. {1, 450, 4, 7, 2, 0},
  51. {1, 850, 4, 31, 2, 0},
  52. {}
  53. };
  54. void fsl_ddr_board_options(memctl_options_t *popts,
  55. dimm_params_t *pdimm,
  56. unsigned int ctrl_num)
  57. {
  58. const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
  59. unsigned int i;
  60. ulong ddr_freq;
  61. if (ctrl_num != 0) /* we have only one controller */
  62. return;
  63. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  64. if (pdimm[i].n_ranks)
  65. break;
  66. }
  67. if (i >= CONFIG_DIMM_SLOTS_PER_CTLR) /* no DIMM */
  68. return;
  69. pbsp = udimm0;
  70. /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  71. * freqency and n_banks specified in board_specific_parameters table.
  72. */
  73. ddr_freq = get_ddr_freq(0) / 1000000;
  74. while (pbsp->datarate_mhz_high) {
  75. if (pbsp->n_ranks == pdimm[i].n_ranks) {
  76. if (ddr_freq <= pbsp->datarate_mhz_high) {
  77. popts->clk_adjust = pbsp->clk_adjust;
  78. popts->cpo_override = pbsp->cpo;
  79. popts->write_data_delay =
  80. pbsp->write_data_delay;
  81. popts->twoT_en = pbsp->force_2T;
  82. goto found;
  83. }
  84. pbsp_highest = pbsp;
  85. }
  86. pbsp++;
  87. }
  88. if (pbsp_highest) {
  89. printf("Error: board specific timing not found "
  90. "for data rate %lu MT/s!\n"
  91. "Trying to use the highest speed (%u) parameters\n",
  92. ddr_freq, pbsp_highest->datarate_mhz_high);
  93. popts->clk_adjust = pbsp_highest->clk_adjust;
  94. popts->cpo_override = pbsp_highest->cpo;
  95. popts->write_data_delay = pbsp_highest->write_data_delay;
  96. popts->twoT_en = pbsp_highest->force_2T;
  97. } else {
  98. panic("DIMM is not supported by this board");
  99. }
  100. found:
  101. /*
  102. * Factors to consider for half-strength driver enable:
  103. * - number of DIMMs installed
  104. */
  105. popts->half_strength_driver_enable = 0;
  106. popts->DQS_config = 0; /* only true DQS signal is used on board */
  107. }