ddr.c 2.9 KB

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