options.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 all memory controllers.
  183. *
  184. * XXX: Attempt to set all controllers to the same chip select
  185. * interleaving mode. It will do a best effort to get the
  186. * requested ranks interleaved together such that the result
  187. * should be a subset of the requested configuration.
  188. */
  189. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  190. if (hwconfig_sub("fsl_ddr", "ctlr_intlv")) {
  191. if (pdimm[0].n_ranks == 0) {
  192. printf("There is no rank on CS0 for controller %d. Because only"
  193. " rank on CS0 and ranks chip-select interleaved with CS0"
  194. " are controller interleaved, force non memory "
  195. "controller interleaving\n", ctrl_num);
  196. popts->memctl_interleaving = 0;
  197. } else {
  198. popts->memctl_interleaving = 1;
  199. /*
  200. * test null first. if CONFIG_HWCONFIG is not defined
  201. * hwconfig_arg_cmp returns non-zero
  202. */
  203. if (hwconfig_subarg_cmp("fsl_ddr", "ctlr_intlv", "null")) {
  204. popts->memctl_interleaving = 0;
  205. debug("memory controller interleaving disabled.\n");
  206. } else if (hwconfig_subarg_cmp("fsl_ddr", "ctlr_intlv", "cacheline"))
  207. popts->memctl_interleaving_mode =
  208. FSL_DDR_CACHE_LINE_INTERLEAVING;
  209. else if (hwconfig_subarg_cmp("fsl_ddr", "ctlr_intlv", "page"))
  210. popts->memctl_interleaving_mode =
  211. FSL_DDR_PAGE_INTERLEAVING;
  212. else if (hwconfig_subarg_cmp("fsl_ddr", "ctlr_intlv", "bank"))
  213. popts->memctl_interleaving_mode =
  214. FSL_DDR_BANK_INTERLEAVING;
  215. else if (hwconfig_subarg_cmp("fsl_ddr", "ctlr_intlv", "superbank"))
  216. popts->memctl_interleaving_mode =
  217. FSL_DDR_SUPERBANK_INTERLEAVING;
  218. else {
  219. popts->memctl_interleaving = 0;
  220. printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
  221. }
  222. }
  223. }
  224. #endif
  225. if ((hwconfig_sub("fsl_ddr", "bank_intlv")) &&
  226. (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
  227. /* test null first. if CONFIG_HWCONFIG is not defined,
  228. * hwconfig_arg_cmp returns non-zero */
  229. if (hwconfig_subarg_cmp("fsl_ddr", "bank_intlv", "null"))
  230. debug("bank interleaving disabled.\n");
  231. else if (hwconfig_subarg_cmp("fsl_ddr", "bank_intlv", "cs0_cs1"))
  232. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  233. else if (hwconfig_subarg_cmp("fsl_ddr", "bank_intlv", "cs2_cs3"))
  234. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  235. else if (hwconfig_subarg_cmp("fsl_ddr", "bank_intlv", "cs0_cs1_and_cs2_cs3"))
  236. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  237. else if (hwconfig_subarg_cmp("fsl_ddr", "bank_intlv", "cs0_cs1_cs2_cs3"))
  238. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  239. else
  240. printf("hwconfig has unrecognized parameter for bank_intlv.\n");
  241. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  242. case FSL_DDR_CS0_CS1_CS2_CS3:
  243. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  244. if (pdimm[0].n_ranks < 4) {
  245. popts->ba_intlv_ctl = 0;
  246. printf("Not enough bank(chip-select) for "
  247. "CS0+CS1+CS2+CS3 on controller %d, "
  248. "force non-interleaving!\n", ctrl_num);
  249. }
  250. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  251. if ((pdimm[0].n_ranks < 2) && (pdimm[1].n_ranks < 2)) {
  252. popts->ba_intlv_ctl = 0;
  253. printf("Not enough bank(chip-select) for "
  254. "CS0+CS1+CS2+CS3 on controller %d, "
  255. "force non-interleaving!\n", ctrl_num);
  256. }
  257. if (pdimm[0].capacity != pdimm[1].capacity) {
  258. popts->ba_intlv_ctl = 0;
  259. printf("Not identical DIMM size for "
  260. "CS0+CS1+CS2+CS3 on controller %d, "
  261. "force non-interleaving!\n", ctrl_num);
  262. }
  263. #endif
  264. break;
  265. case FSL_DDR_CS0_CS1:
  266. if (pdimm[0].n_ranks < 2) {
  267. popts->ba_intlv_ctl = 0;
  268. printf("Not enough bank(chip-select) for "
  269. "CS0+CS1 on controller %d, "
  270. "force non-interleaving!\n", ctrl_num);
  271. }
  272. break;
  273. case FSL_DDR_CS2_CS3:
  274. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  275. if (pdimm[0].n_ranks < 4) {
  276. popts->ba_intlv_ctl = 0;
  277. printf("Not enough bank(chip-select) for CS2+CS3 "
  278. "on controller %d, force non-interleaving!\n", ctrl_num);
  279. }
  280. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  281. if (pdimm[1].n_ranks < 2) {
  282. popts->ba_intlv_ctl = 0;
  283. printf("Not enough bank(chip-select) for CS2+CS3 "
  284. "on controller %d, force non-interleaving!\n", ctrl_num);
  285. }
  286. #endif
  287. break;
  288. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  289. #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
  290. if (pdimm[0].n_ranks < 4) {
  291. popts->ba_intlv_ctl = 0;
  292. printf("Not enough bank(CS) for CS0+CS1 and "
  293. "CS2+CS3 on controller %d, "
  294. "force non-interleaving!\n", ctrl_num);
  295. }
  296. #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
  297. if ((pdimm[0].n_ranks < 2) || (pdimm[1].n_ranks < 2)) {
  298. popts->ba_intlv_ctl = 0;
  299. printf("Not enough bank(CS) for CS0+CS1 and "
  300. "CS2+CS3 on controller %d, "
  301. "force non-interleaving!\n", ctrl_num);
  302. }
  303. #endif
  304. break;
  305. default:
  306. popts->ba_intlv_ctl = 0;
  307. break;
  308. }
  309. }
  310. if (hwconfig_sub("fsl_ddr", "addr_hash")) {
  311. if (hwconfig_subarg_cmp("fsl_ddr", "addr_hash", "null"))
  312. popts->addr_hash = 0;
  313. else if (hwconfig_subarg_cmp("fsl_ddr", "addr_hash", "true"))
  314. popts->addr_hash = 1;
  315. }
  316. if (pdimm[0].n_ranks == 4)
  317. popts->quad_rank_present = 1;
  318. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  319. return 0;
  320. }
  321. void check_interleaving_options(fsl_ddr_info_t *pinfo)
  322. {
  323. int i, j, check_n_ranks, intlv_fixed = 0;
  324. unsigned long long check_rank_density;
  325. /*
  326. * Check if all controllers are configured for memory
  327. * controller interleaving. Identical dimms are recommended. At least
  328. * the size should be checked.
  329. */
  330. j = 0;
  331. check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
  332. check_rank_density = pinfo->dimm_params[0][0].rank_density;
  333. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  334. if ((pinfo->memctl_opts[i].memctl_interleaving) && \
  335. (check_rank_density == pinfo->dimm_params[i][0].rank_density) && \
  336. (check_n_ranks == pinfo->dimm_params[i][0].n_ranks)) {
  337. j++;
  338. }
  339. }
  340. if (j != CONFIG_NUM_DDR_CONTROLLERS) {
  341. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  342. if (pinfo->memctl_opts[i].memctl_interleaving) {
  343. pinfo->memctl_opts[i].memctl_interleaving = 0;
  344. intlv_fixed = 1;
  345. }
  346. if (intlv_fixed)
  347. printf("Not all DIMMs are identical in size. "
  348. "Memory controller interleaving disabled.\n");
  349. }
  350. }