options.c 9.0 KB

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