ddr.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. typedef struct {
  15. u32 datarate_mhz_low;
  16. u32 datarate_mhz_high;
  17. u32 n_ranks;
  18. u32 clk_adjust; /* Range: 0-8 */
  19. u32 cpo; /* Range: 2-31 */
  20. u32 write_data_delay; /* Range: 0-6 */
  21. u32 force_2T;
  22. } board_specific_parameters_t;
  23. static const board_specific_parameters_t bsp[] = {
  24. /*
  25. * lo| hi| num| clk| cpo|wrdata|2T
  26. * mhz| mhz|ranks|adjst| | delay|
  27. */
  28. { 0, 333, 1, 5, 31, 3, 0},
  29. {334, 400, 1, 5, 31, 3, 0},
  30. {401, 549, 1, 5, 31, 3, 0},
  31. {550, 680, 1, 5, 31, 5, 0},
  32. {681, 850, 1, 5, 31, 5, 0},
  33. { 0, 333, 2, 5, 31, 3, 0},
  34. {334, 400, 2, 5, 31, 3, 0},
  35. {401, 549, 2, 5, 31, 3, 0},
  36. {550, 680, 2, 5, 31, 5, 0},
  37. {681, 850, 2, 5, 31, 5, 0},
  38. };
  39. void fsl_ddr_board_options(memctl_options_t *popts, dimm_params_t *pdimm,
  40. unsigned int ctrl_num)
  41. {
  42. unsigned long ddr_freq;
  43. unsigned int i;
  44. /* set odt_rd_cfg and odt_wr_cfg. */
  45. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  46. popts->cs_local_opts[i].odt_rd_cfg = 0;
  47. popts->cs_local_opts[i].odt_wr_cfg = 1;
  48. }
  49. /*
  50. * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  51. * freqency and n_banks specified in board_specific_parameters table.
  52. */
  53. ddr_freq = get_ddr_freq(0) / 1000000;
  54. for (i = 0; i < ARRAY_SIZE(bsp); i++) {
  55. if (ddr_freq >= bsp[i].datarate_mhz_low &&
  56. ddr_freq <= bsp[i].datarate_mhz_high &&
  57. pdimm->n_ranks == bsp[i].n_ranks) {
  58. popts->clk_adjust = bsp[i].clk_adjust;
  59. popts->cpo_override = bsp[i].cpo;
  60. popts->write_data_delay = bsp[i].write_data_delay;
  61. popts->twoT_en = bsp[i].force_2T;
  62. break;
  63. }
  64. }
  65. popts->half_strength_driver_enable = 1;
  66. /* Per AN4039, enable ZQ calibration. */
  67. popts->zq_en = 1;
  68. /*
  69. * For wake-up on ARP, we need auto self refresh enabled
  70. */
  71. popts->auto_self_refresh_en = 1;
  72. popts->sr_it = 0xb;
  73. }