ddr.c 2.7 KB

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