options.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  22. const char *p;
  23. #endif
  24. /* Chip select options. */
  25. /* Pick chip-select local options. */
  26. for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
  27. /* If not DDR2, odt_rd_cfg and odt_wr_cfg need to be 0. */
  28. /* only for single CS? */
  29. popts->cs_local_opts[i].odt_rd_cfg = 0;
  30. popts->cs_local_opts[i].odt_wr_cfg = 1;
  31. popts->cs_local_opts[i].auto_precharge = 0;
  32. }
  33. /* Pick interleaving mode. */
  34. /*
  35. * 0 = no interleaving
  36. * 1 = interleaving between 2 controllers
  37. */
  38. popts->memctl_interleaving = 0;
  39. /*
  40. * 0 = cacheline
  41. * 1 = page
  42. * 2 = (logical) bank
  43. * 3 = superbank (only if CS interleaving is enabled)
  44. */
  45. popts->memctl_interleaving_mode = 0;
  46. /*
  47. * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
  48. * 1: page: bit to the left of the column bits selects the memctl
  49. * 2: bank: bit to the left of the bank bits selects the memctl
  50. * 3: superbank: bit to the left of the chip select selects the memctl
  51. *
  52. * NOTE: ba_intlv (rank interleaving) is independent of memory
  53. * controller interleaving; it is only within a memory controller.
  54. * Must use superbank interleaving if rank interleaving is used and
  55. * memory controller interleaving is enabled.
  56. */
  57. /*
  58. * 0 = no
  59. * 0x40 = CS0,CS1
  60. * 0x20 = CS2,CS3
  61. * 0x60 = CS0,CS1 + CS2,CS3
  62. * 0x04 = CS0,CS1,CS2,CS3
  63. */
  64. popts->ba_intlv_ctl = 0;
  65. /* Memory Organization Parameters */
  66. popts->registered_dimm_en = all_DIMMs_registered;
  67. /* Operational Mode Paramters */
  68. /* Pick ECC modes */
  69. #ifdef CONFIG_DDR_ECC
  70. popts->ECC_mode = 1; /* 0 = disabled, 1 = enabled */
  71. #else
  72. popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */
  73. #endif
  74. popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
  75. /*
  76. * Choose DQS config
  77. * 0 for DDR1
  78. * 1 for DDR2
  79. */
  80. #if defined(CONFIG_FSL_DDR1)
  81. popts->DQS_config = 0;
  82. #elif defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3)
  83. popts->DQS_config = 1;
  84. #endif
  85. /* Choose self-refresh during sleep. */
  86. popts->self_refresh_in_sleep = 1;
  87. /* Choose dynamic power management mode. */
  88. popts->dynamic_power = 0;
  89. /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */
  90. popts->data_bus_width = 0;
  91. /* Choose burst length. */
  92. #if defined(CONFIG_FSL_DDR3)
  93. popts->OTF_burst_chop_en = 1; /* on-the-fly burst chop */
  94. popts->burst_length = DDR_OTF; /* on-the-fly BC4 and BL8 */
  95. #else
  96. popts->burst_length = DDR_BL4; /* has to be 4 for DDR2 */
  97. #endif
  98. /* Choose ddr controller address mirror mode */
  99. #if defined(CONFIG_FSL_DDR3)
  100. popts->mirrored_dimm = pdimm[0].mirrored_dimm;
  101. #endif
  102. /* Global Timing Parameters. */
  103. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  104. /* Pick a caslat override. */
  105. popts->cas_latency_override = 0;
  106. popts->cas_latency_override_value = 3;
  107. if (popts->cas_latency_override) {
  108. debug("using caslat override value = %u\n",
  109. popts->cas_latency_override_value);
  110. }
  111. /* Decide whether to use the computed derated latency */
  112. popts->use_derated_caslat = 0;
  113. /* Choose an additive latency. */
  114. popts->additive_latency_override = 0;
  115. popts->additive_latency_override_value = 3;
  116. if (popts->additive_latency_override) {
  117. debug("using additive latency override value = %u\n",
  118. popts->additive_latency_override_value);
  119. }
  120. /*
  121. * 2T_EN setting
  122. *
  123. * Factors to consider for 2T_EN:
  124. * - number of DIMMs installed
  125. * - number of components, number of active ranks
  126. * - how much time you want to spend playing around
  127. */
  128. popts->twoT_en = 0;
  129. popts->threeT_en = 0;
  130. /*
  131. * BSTTOPRE precharge interval
  132. *
  133. * Set this to 0 for global auto precharge
  134. *
  135. * FIXME: Should this be configured in picoseconds?
  136. * Why it should be in ps: better understanding of this
  137. * relative to actual DRAM timing parameters such as tRAS.
  138. * e.g. tRAS(min) = 40 ns
  139. */
  140. popts->bstopre = 0x100;
  141. /* Minimum CKE pulse width -- tCKE(MIN) */
  142. popts->tCKE_clock_pulse_width_ps
  143. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  144. /*
  145. * Window for four activates -- tFAW
  146. *
  147. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  148. * FIXME: varies depending upon number of column addresses or data
  149. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  150. */
  151. #if defined(CONFIG_FSL_DDR1)
  152. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  153. #elif defined(CONFIG_FSL_DDR2)
  154. /*
  155. * x4/x8; some datasheets have 35000
  156. * x16 wide columns only? Use 50000?
  157. */
  158. popts->tFAW_window_four_activates_ps = 37500;
  159. #elif defined(CONFIG_FSL_DDR3)
  160. popts->tFAW_window_four_activates_ps = pdimm[0].tFAW_ps;
  161. #endif
  162. popts->zq_en = 0;
  163. popts->wrlvl_en = 0;
  164. #if defined(CONFIG_FSL_DDR3)
  165. /*
  166. * due to ddr3 dimm is fly-by topology
  167. * we suggest to enable write leveling to
  168. * meet the tQDSS under different loading.
  169. */
  170. popts->wrlvl_en = 1;
  171. #endif
  172. /*
  173. * Check interleaving configuration from environment.
  174. * Please refer to doc/README.fsl-ddr for the detail.
  175. *
  176. * If memory controller interleaving is enabled, then the data
  177. * bus widths must be programmed identically for the 2 memory
  178. * controllers.
  179. *
  180. * XXX: Attempt to set both controllers to the same chip select
  181. * interleaving mode. It will do a best effort to get the
  182. * requested ranks interleaved together such that the result
  183. * should be a subset of the requested configuration.
  184. */
  185. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  186. if ((p = getenv("memctl_intlv_ctl")) != NULL) {
  187. if (pdimm[0].n_ranks == 0) {
  188. printf("There is no rank on CS0. Because only rank on "
  189. "CS0 and ranks chip-select interleaved with CS0"
  190. " are controller interleaved, force non memory "
  191. "controller interleaving\n");
  192. popts->memctl_interleaving = 0;
  193. } else {
  194. popts->memctl_interleaving = 1;
  195. if (strcmp(p, "cacheline") == 0)
  196. popts->memctl_interleaving_mode =
  197. FSL_DDR_CACHE_LINE_INTERLEAVING;
  198. else if (strcmp(p, "page") == 0)
  199. popts->memctl_interleaving_mode =
  200. FSL_DDR_PAGE_INTERLEAVING;
  201. else if (strcmp(p, "bank") == 0)
  202. popts->memctl_interleaving_mode =
  203. FSL_DDR_BANK_INTERLEAVING;
  204. else if (strcmp(p, "superbank") == 0)
  205. popts->memctl_interleaving_mode =
  206. FSL_DDR_SUPERBANK_INTERLEAVING;
  207. else
  208. popts->memctl_interleaving_mode =
  209. simple_strtoul(p, NULL, 0);
  210. }
  211. }
  212. if( (p = getenv("ba_intlv_ctl")) != NULL) {
  213. if (strcmp(p, "cs0_cs1") == 0)
  214. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  215. else if (strcmp(p, "cs2_cs3") == 0)
  216. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  217. else if (strcmp(p, "cs0_cs1_and_cs2_cs3") == 0)
  218. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  219. else if (strcmp(p, "cs0_cs1_cs2_cs3") == 0)
  220. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  221. else
  222. popts->ba_intlv_ctl = simple_strtoul(p, NULL, 0);
  223. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  224. case FSL_DDR_CS0_CS1_CS2_CS3:
  225. case FSL_DDR_CS0_CS1:
  226. if (pdimm[0].n_ranks != 2) {
  227. popts->ba_intlv_ctl = 0;
  228. printf("Not enough bank(chip-select) for "
  229. "CS0+CS1, force non-interleaving!\n");
  230. }
  231. break;
  232. case FSL_DDR_CS2_CS3:
  233. if (pdimm[1].n_ranks !=2){
  234. popts->ba_intlv_ctl = 0;
  235. printf("Not enough bank(CS) for CS2+CS3, "
  236. "force non-interleaving!\n");
  237. }
  238. break;
  239. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  240. if ((pdimm[0].n_ranks != 2)||(pdimm[1].n_ranks != 2)) {
  241. popts->ba_intlv_ctl = 0;
  242. printf("Not enough bank(CS) for CS0+CS1 or "
  243. "CS2+CS3, force non-interleaving!\n");
  244. }
  245. break;
  246. default:
  247. popts->ba_intlv_ctl = 0;
  248. break;
  249. }
  250. }
  251. #endif
  252. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  253. return 0;
  254. }