options.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 "ddr.h"
  11. /* Board-specific functions defined in each board's ddr.c */
  12. extern void fsl_ddr_board_options(memctl_options_t *popts,
  13. dimm_params_t *pdimm,
  14. unsigned int ctrl_num);
  15. unsigned int populate_memctl_options(int all_DIMMs_registered,
  16. memctl_options_t *popts,
  17. dimm_params_t *pdimm,
  18. unsigned int ctrl_num)
  19. {
  20. unsigned int i;
  21. /* Chip select options. */
  22. /* Pick chip-select local options. */
  23. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  24. /* If not DDR2, odt_rd_cfg and odt_wr_cfg need to be 0. */
  25. /* only for single CS? */
  26. popts->cs_local_opts[i].odt_rd_cfg = 0;
  27. popts->cs_local_opts[i].odt_wr_cfg = 1;
  28. popts->cs_local_opts[i].auto_precharge = 0;
  29. }
  30. /* Pick interleaving mode. */
  31. /*
  32. * 0 = no interleaving
  33. * 1 = interleaving between 2 controllers
  34. */
  35. popts->memctl_interleaving = 0;
  36. /*
  37. * 0 = cacheline
  38. * 1 = page
  39. * 2 = (logical) bank
  40. * 3 = superbank (only if CS interleaving is enabled)
  41. */
  42. popts->memctl_interleaving_mode = 0;
  43. /*
  44. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  45. * 1: page: bit to the left of the column bits selects the memctl
  46. * 2: bank: bit to the left of the bank bits selects the memctl
  47. * 3: superbank: bit to the left of the chip select selects the memctl
  48. *
  49. * NOTE: ba_intlv (rank interleaving) is independent of memory
  50. * controller interleaving; it is only within a memory controller.
  51. * Must use superbank interleaving if rank interleaving is used and
  52. * memory controller interleaving is enabled.
  53. */
  54. /*
  55. * 0 = no
  56. * 0x40 = CS0,CS1
  57. * 0x20 = CS2,CS3
  58. * 0x60 = CS0,CS1 + CS2,CS3
  59. * 0x04 = CS0,CS1,CS2,CS3
  60. */
  61. popts->ba_intlv_ctl = 0;
  62. /* Memory Organization Parameters */
  63. popts->registered_dimm_en = all_DIMMs_registered;
  64. /* Operational Mode Paramters */
  65. /* Pick ECC modes */
  66. #ifdef CONFIG_DDR_ECC
  67. popts->ECC_mode = 1; /* 0 = disabled, 1 = enabled */
  68. #else
  69. popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */
  70. #endif
  71. popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  72. /*
  73. * Choose DQS config
  74. * 0 for DDR1
  75. * 1 for DDR2
  76. */
  77. #if defined(CONFIG_FSL_DDR1)
  78. popts->DQS_config = 0;
  79. #elif defined(CONFIG_FSL_DDR2)
  80. popts->DQS_config = 1;
  81. #else
  82. #error "Fix DQS for DDR3"
  83. #endif
  84. /* Choose self-refresh during sleep. */
  85. popts->self_refresh_in_sleep = 1;
  86. /* Choose dynamic power management mode. */
  87. popts->dynamic_power = 0;
  88. /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */
  89. popts->data_bus_width = 0;
  90. /* Choose burst length. */
  91. popts->burst_length = 4; /* has to be 4 for DDR2 */
  92. /* Global Timing Parameters. */
  93. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  94. /* Pick a caslat override. */
  95. popts->cas_latency_override = 0;
  96. popts->cas_latency_override_value = 3;
  97. if (popts->cas_latency_override) {
  98. debug("using caslat override value = %u\n",
  99. popts->cas_latency_override_value);
  100. }
  101. /* Decide whether to use the computed derated latency */
  102. popts->use_derated_caslat = 0;
  103. /* Choose an additive latency. */
  104. popts->additive_latency_override = 0;
  105. popts->additive_latency_override_value = 3;
  106. if (popts->additive_latency_override) {
  107. debug("using additive latency override value = %u\n",
  108. popts->additive_latency_override_value);
  109. }
  110. /*
  111. * 2T_EN setting
  112. *
  113. * Factors to consider for 2T_EN:
  114. * - number of DIMMs installed
  115. * - number of components, number of active ranks
  116. * - how much time you want to spend playing around
  117. */
  118. popts->twoT_en = 1;
  119. popts->threeT_en = 0;
  120. /*
  121. * BSTTOPRE precharge interval
  122. *
  123. * Set this to 0 for global auto precharge
  124. *
  125. * FIXME: Should this be configured in picoseconds?
  126. * Why it should be in ps: better understanding of this
  127. * relative to actual DRAM timing parameters such as tRAS.
  128. * e.g. tRAS(min) = 40 ns
  129. */
  130. popts->bstopre = 0x100;
  131. /* Minimum CKE pulse width -- tCKE(MIN) */
  132. popts->tCKE_clock_pulse_width_ps
  133. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  134. /*
  135. * Window for four activates -- tFAW
  136. *
  137. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  138. * FIXME: varies depending upon number of column addresses or data
  139. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  140. */
  141. #if defined(CONFIG_FSL_DDR1)
  142. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  143. #elif defined(CONFIG_FSL_DDR2)
  144. /*
  145. * x4/x8; some datasheets have 35000
  146. * x16 wide columns only? Use 50000?
  147. */
  148. popts->tFAW_window_four_activates_ps = 37500;
  149. #elif defined(CONFIG_FSL_DDR3)
  150. #error "FIXME determine four activates for DDR3"
  151. #endif
  152. /* ODT should only be used for DDR2 */
  153. /* FIXME? */
  154. /*
  155. * Interleaving checks.
  156. *
  157. * If memory controller interleaving is enabled, then the data
  158. * bus widths must be programmed identically for the 2 memory
  159. * controllers.
  160. */
  161. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  162. return 0;
  163. }