ddr.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <asm/fsl_ddr_sdram.h>
  10. #include <asm/fsl_ddr_dimm_params.h>
  11. typedef struct {
  12. u32 datarate_mhz_low;
  13. u32 datarate_mhz_high;
  14. u32 n_ranks;
  15. u32 clk_adjust;
  16. u32 cpo;
  17. u32 write_data_delay;
  18. } board_specific_parameters_t;
  19. /* XXX: these values need to be checked for all interleaving modes. */
  20. const board_specific_parameters_t board_specific_parameters[2][16] = {
  21. {
  22. /* memory controller 0 */
  23. /* lo| hi| num| clk| cpo|wrdata */
  24. /* mhz| mhz|ranks|adjst| | delay */
  25. { 0, 333, 4, 7, 7, 3},
  26. {334, 400, 4, 7, 9, 3},
  27. {401, 549, 4, 7, 9, 3},
  28. {550, 650, 4, 7, 10, 4},
  29. { 0, 333, 3, 7, 7, 3},
  30. {334, 400, 3, 7, 9, 3},
  31. {401, 549, 3, 7, 9, 3},
  32. {550, 650, 3, 7, 10, 4},
  33. { 0, 333, 2, 7, 7, 3},
  34. {334, 400, 2, 7, 9, 3},
  35. {401, 549, 2, 7, 9, 3},
  36. {550, 650, 2, 7, 10, 4},
  37. { 0, 333, 1, 7, 7, 3},
  38. {334, 400, 1, 7, 9, 3},
  39. {401, 549, 1, 7, 9, 3},
  40. {550, 650, 1, 7, 10, 4}
  41. },
  42. {
  43. /* memory controller 1 */
  44. /* lo| hi| num| clk| cpo|wrdata */
  45. /* mhz| mhz|ranks|adjst| | delay */
  46. { 0, 333, 4, 7, 7, 3},
  47. {334, 400, 4, 7, 9, 3},
  48. {401, 549, 4, 7, 9, 3},
  49. {550, 650, 4, 7, 10, 4},
  50. { 0, 333, 3, 7, 7, 3},
  51. {334, 400, 3, 7, 9, 3},
  52. {401, 549, 3, 7, 9, 3},
  53. {550, 650, 3, 7, 10, 4},
  54. { 0, 333, 2, 7, 7, 3},
  55. {334, 400, 2, 7, 9, 3},
  56. {401, 549, 2, 7, 9, 3},
  57. {550, 650, 2, 7, 10, 4},
  58. { 0, 333, 1, 7, 7, 3},
  59. {334, 400, 1, 7, 9, 3},
  60. {401, 549, 1, 7, 9, 3},
  61. {550, 650, 1, 7, 10, 4}
  62. }
  63. };
  64. void fsl_ddr_board_options(memctl_options_t *popts,
  65. dimm_params_t *pdimm,
  66. unsigned int ctrl_num)
  67. {
  68. const board_specific_parameters_t *pbsp =
  69. &(board_specific_parameters[ctrl_num][0]);
  70. u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
  71. sizeof(board_specific_parameters[0][0]);
  72. u32 i;
  73. u32 j;
  74. ulong ddr_freq;
  75. /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
  76. * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
  77. * there are two dimms in the controller, set odt_rd_cfg to 3 and
  78. * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
  79. */
  80. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  81. if (i&1) { /* odd CS */
  82. popts->cs_local_opts[i].odt_rd_cfg = 0;
  83. popts->cs_local_opts[i].odt_wr_cfg = 0;
  84. } else { /* even CS */
  85. if ((CONFIG_DIMM_SLOTS_PER_CTLR == 2) &&
  86. (pdimm[i/2].n_ranks != 0)) {
  87. popts->cs_local_opts[i].odt_rd_cfg = 3;
  88. popts->cs_local_opts[i].odt_wr_cfg = 3;
  89. } else {
  90. popts->cs_local_opts[i].odt_rd_cfg = 0;
  91. popts->cs_local_opts[i].odt_wr_cfg = 4;
  92. }
  93. }
  94. }
  95. /* Get clk_adjust, cpo, write_data_delay, according to the board ddr
  96. * freqency and n_banks specified in board_specific_parameters table.
  97. */
  98. ddr_freq = get_ddr_freq(0) / 1000000;
  99. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
  100. if (pdimm[j].n_ranks > 0) {
  101. for (i = 0; i < num_params; i++) {
  102. if (ddr_freq >= pbsp->datarate_mhz_low &&
  103. ddr_freq <= pbsp->datarate_mhz_high &&
  104. pdimm[j].n_ranks == pbsp->n_ranks) {
  105. popts->clk_adjust = pbsp->clk_adjust;
  106. popts->cpo_override = pbsp->cpo;
  107. popts->write_data_delay =
  108. pbsp->write_data_delay;
  109. break;
  110. }
  111. pbsp++;
  112. }
  113. }
  114. }
  115. /* 2T timing enable */
  116. popts->twoT_en = 1;
  117. }