ddr.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2010 Freescale Semiconductor, Inc.
  3. * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
  4. * Timur Tabi <timur@freescale.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. #include <common.h>
  12. #include <asm/fsl_ddr_sdram.h>
  13. #include <asm/fsl_ddr_dimm_params.h>
  14. struct board_specific_parameters {
  15. u32 n_ranks;
  16. u32 datarate_mhz_high;
  17. u32 clk_adjust; /* Range: 0-8 */
  18. u32 cpo; /* Range: 2-31 */
  19. u32 write_data_delay; /* Range: 0-6 */
  20. u32 force_2T;
  21. };
  22. /*
  23. * This table contains all valid speeds we want to override with board
  24. * specific parameters. datarate_mhz_high values need to be in ascending order
  25. * for each n_ranks group.
  26. */
  27. static const struct board_specific_parameters dimm0[] = {
  28. /*
  29. * memory controller 0
  30. * num| hi| clk| cpo|wrdata|2T
  31. * ranks| mhz|adjst| | delay|
  32. */
  33. {1, 549, 5, 31, 3, 0},
  34. {1, 850, 5, 31, 5, 0},
  35. {2, 549, 5, 31, 3, 0},
  36. {2, 850, 5, 31, 5, 0},
  37. {}
  38. };
  39. void fsl_ddr_board_options(memctl_options_t *popts, dimm_params_t *pdimm,
  40. unsigned int ctrl_num)
  41. {
  42. const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
  43. unsigned long ddr_freq;
  44. unsigned int i;
  45. if (ctrl_num) {
  46. printf("Wrong parameter for controller number %d", ctrl_num);
  47. return;
  48. }
  49. if (!pdimm->n_ranks)
  50. return;
  51. /* set odt_rd_cfg and odt_wr_cfg. */
  52. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  53. popts->cs_local_opts[i].odt_rd_cfg = 0;
  54. popts->cs_local_opts[i].odt_wr_cfg = 1;
  55. }
  56. pbsp = dimm0;
  57. /*
  58. * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  59. * freqency and n_banks specified in board_specific_parameters table.
  60. */
  61. ddr_freq = get_ddr_freq(0) / 1000000;
  62. while (pbsp->datarate_mhz_high) {
  63. if (pbsp->n_ranks == pdimm->n_ranks) {
  64. if (ddr_freq <= pbsp->datarate_mhz_high) {
  65. popts->clk_adjust = pbsp->clk_adjust;
  66. popts->cpo_override = pbsp->cpo;
  67. popts->write_data_delay =
  68. pbsp->write_data_delay;
  69. popts->twoT_en = pbsp->force_2T;
  70. goto found;
  71. }
  72. pbsp_highest = pbsp;
  73. }
  74. pbsp++;
  75. }
  76. if (pbsp_highest) {
  77. printf("Error: board specific timing not found "
  78. "for data rate %lu MT/s!\n"
  79. "Trying to use the highest speed (%u) parameters\n",
  80. ddr_freq, pbsp_highest->datarate_mhz_high);
  81. popts->clk_adjust = pbsp->clk_adjust;
  82. popts->cpo_override = pbsp->cpo;
  83. popts->write_data_delay = pbsp->write_data_delay;
  84. popts->twoT_en = pbsp->force_2T;
  85. } else {
  86. panic("DIMM is not supported by this board");
  87. }
  88. found:
  89. popts->half_strength_driver_enable = 1;
  90. /* Per AN4039, enable ZQ calibration. */
  91. popts->zq_en = 1;
  92. /*
  93. * For wake-up on ARP, we need auto self refresh enabled
  94. */
  95. popts->auto_self_refresh_en = 1;
  96. popts->sr_it = 0xb;
  97. }