ddr.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <i2c.h>
  13. #include <asm/fsl_ddr_sdram.h>
  14. #include <asm/fsl_ddr_dimm_params.h>
  15. unsigned int fsl_ddr_get_mem_data_rate(void)
  16. {
  17. return get_ddr_freq(0);
  18. }
  19. void fsl_ddr_get_spd(ddr3_spd_eeprom_t *ctrl_dimms_spd, unsigned int ctrl_num)
  20. {
  21. int ret;
  22. /*
  23. * The P1022 has only one DDR controller, and the board has only one
  24. * DIMM slot.
  25. */
  26. ret = i2c_read(SPD_EEPROM_ADDRESS1, 0, 1, (u8 *)ctrl_dimms_spd,
  27. sizeof(ddr3_spd_eeprom_t));
  28. if (ret) {
  29. debug("DDR: failed to read SPD from address %u\n",
  30. SPD_EEPROM_ADDRESS1);
  31. memset(ctrl_dimms_spd, 0, sizeof(ddr3_spd_eeprom_t));
  32. }
  33. }
  34. typedef struct {
  35. u32 datarate_mhz_low;
  36. u32 datarate_mhz_high;
  37. u32 n_ranks;
  38. u32 clk_adjust; /* Range: 0-8 */
  39. u32 cpo; /* Range: 2-31 */
  40. u32 write_data_delay; /* Range: 0-6 */
  41. u32 force_2T;
  42. } board_specific_parameters_t;
  43. static const board_specific_parameters_t bsp[] = {
  44. /*
  45. * lo| hi| num| clk| cpo|wrdata|2T
  46. * mhz| mhz|ranks|adjst| | delay|
  47. */
  48. { 0, 333, 1, 5, 31, 3, 0},
  49. {334, 400, 1, 5, 31, 3, 0},
  50. {401, 549, 1, 5, 31, 3, 0},
  51. {550, 680, 1, 5, 31, 5, 0},
  52. {681, 850, 1, 5, 31, 5, 0},
  53. { 0, 333, 2, 5, 31, 3, 0},
  54. {334, 400, 2, 5, 31, 3, 0},
  55. {401, 549, 2, 5, 31, 3, 0},
  56. {550, 680, 2, 5, 31, 5, 0},
  57. {681, 850, 2, 5, 31, 5, 0},
  58. };
  59. void fsl_ddr_board_options(memctl_options_t *popts, dimm_params_t *pdimm,
  60. unsigned int ctrl_num)
  61. {
  62. unsigned long ddr_freq;
  63. unsigned int i;
  64. /* set odt_rd_cfg and odt_wr_cfg. */
  65. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  66. popts->cs_local_opts[i].odt_rd_cfg = 0;
  67. popts->cs_local_opts[i].odt_wr_cfg = 1;
  68. }
  69. /*
  70. * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  71. * freqency and n_banks specified in board_specific_parameters table.
  72. */
  73. ddr_freq = get_ddr_freq(0) / 1000000;
  74. for (i = 0; i < ARRAY_SIZE(bsp); i++) {
  75. if (ddr_freq >= bsp[i].datarate_mhz_low &&
  76. ddr_freq <= bsp[i].datarate_mhz_high &&
  77. pdimm->n_ranks == bsp[i].n_ranks) {
  78. popts->clk_adjust = bsp[i].clk_adjust;
  79. popts->cpo_override = bsp[i].cpo;
  80. popts->write_data_delay = bsp[i].write_data_delay;
  81. popts->twoT_en = bsp[i].force_2T;
  82. break;
  83. }
  84. }
  85. popts->half_strength_driver_enable = 1;
  86. /* Per AN4039, enable ZQ calibration. */
  87. popts->zq_en = 1;
  88. /*
  89. * For wake-up on ARP, we need auto self refresh enabled
  90. */
  91. popts->auto_self_refresh_en = 1;
  92. popts->sr_it = 0xb;
  93. }