ddr.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2008,2011 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #include <common.h>
  7. #include <fsl_ddr_sdram.h>
  8. #include <fsl_ddr_dimm_params.h>
  9. struct board_specific_parameters {
  10. u32 n_ranks;
  11. u32 datarate_mhz_high;
  12. u32 clk_adjust;
  13. u32 cpo;
  14. u32 write_data_delay;
  15. };
  16. /*
  17. * This table contains all valid speeds we want to override with board
  18. * specific parameters. datarate_mhz_high values need to be in ascending order
  19. * for each n_ranks group.
  20. */
  21. const struct board_specific_parameters dimm0[] = {
  22. /*
  23. * memory controller 0
  24. * num| hi| clk| cpo|wrdata|2T
  25. * ranks| mhz|adjst| | delay|
  26. */
  27. {4, 333, 7, 7, 3},
  28. {4, 549, 7, 9, 3},
  29. {4, 650, 7, 10, 4},
  30. {2, 333, 7, 7, 3},
  31. {2, 549, 7, 9, 3},
  32. {2, 650, 7, 10, 4},
  33. {1, 333, 7, 7, 3},
  34. {1, 549, 7, 9, 3},
  35. {1, 650, 7, 10, 4},
  36. {}
  37. };
  38. /*
  39. * The two slots have slightly different timing. The center values are good
  40. * for both slots. We use identical speed tables for them. In future use, if
  41. * DIMMs have fewer center values that require two separated tables, copy the
  42. * udimm0 table to udimm1 and make changes to clk_adjust and wrlvl_start.
  43. */
  44. const struct board_specific_parameters *dimms[] = {
  45. dimm0,
  46. dimm0,
  47. };
  48. void fsl_ddr_board_options(memctl_options_t *popts,
  49. dimm_params_t *pdimm,
  50. unsigned int ctrl_num)
  51. {
  52. const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
  53. unsigned int i;
  54. ulong ddr_freq;
  55. if (ctrl_num > 1) {
  56. printf("Wrong parameter for controller number %d", ctrl_num);
  57. return;
  58. }
  59. for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
  60. if (pdimm[i].n_ranks)
  61. break;
  62. }
  63. if (i >= CONFIG_DIMM_SLOTS_PER_CTLR) /* no DIMM */
  64. return;
  65. pbsp = dimms[ctrl_num];
  66. /* Get clk_adjust, cpo, write_data_delay, according to the board ddr
  67. * freqency and n_banks specified in board_specific_parameters table.
  68. */
  69. ddr_freq = get_ddr_freq(0) / 1000000;
  70. while (pbsp->datarate_mhz_high) {
  71. if (pbsp->n_ranks == pdimm[i].n_ranks) {
  72. if (ddr_freq <= pbsp->datarate_mhz_high) {
  73. popts->clk_adjust = pbsp->clk_adjust;
  74. popts->cpo_override = pbsp->cpo;
  75. popts->write_data_delay =
  76. pbsp->write_data_delay;
  77. goto found;
  78. }
  79. pbsp_highest = pbsp;
  80. }
  81. pbsp++;
  82. }
  83. if (pbsp_highest) {
  84. printf("Error: board specific timing not found "
  85. "for data rate %lu MT/s!\n"
  86. "Trying to use the highest speed (%u) parameters\n",
  87. ddr_freq, pbsp_highest->datarate_mhz_high);
  88. popts->clk_adjust = pbsp_highest->clk_adjust;
  89. popts->cpo_override = pbsp_highest->cpo;
  90. popts->write_data_delay = pbsp_highest->write_data_delay;
  91. } else {
  92. panic("DIMM is not supported by this board");
  93. }
  94. found:
  95. /* 2T timing enable */
  96. popts->twot_en = 1;
  97. }