options.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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)
  83. popts->DQS_config = 1;
  84. #else
  85. #error "Fix DQS for DDR3"
  86. #endif
  87. /* Choose self-refresh during sleep. */
  88. popts->self_refresh_in_sleep = 1;
  89. /* Choose dynamic power management mode. */
  90. popts->dynamic_power = 0;
  91. /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */
  92. popts->data_bus_width = 0;
  93. /* Choose burst length. */
  94. popts->burst_length = 4; /* has to be 4 for DDR2 */
  95. /* Global Timing Parameters. */
  96. debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
  97. /* Pick a caslat override. */
  98. popts->cas_latency_override = 0;
  99. popts->cas_latency_override_value = 3;
  100. if (popts->cas_latency_override) {
  101. debug("using caslat override value = %u\n",
  102. popts->cas_latency_override_value);
  103. }
  104. /* Decide whether to use the computed derated latency */
  105. popts->use_derated_caslat = 0;
  106. /* Choose an additive latency. */
  107. popts->additive_latency_override = 0;
  108. popts->additive_latency_override_value = 3;
  109. if (popts->additive_latency_override) {
  110. debug("using additive latency override value = %u\n",
  111. popts->additive_latency_override_value);
  112. }
  113. /*
  114. * 2T_EN setting
  115. *
  116. * Factors to consider for 2T_EN:
  117. * - number of DIMMs installed
  118. * - number of components, number of active ranks
  119. * - how much time you want to spend playing around
  120. */
  121. popts->twoT_en = 0;
  122. popts->threeT_en = 0;
  123. /*
  124. * BSTTOPRE precharge interval
  125. *
  126. * Set this to 0 for global auto precharge
  127. *
  128. * FIXME: Should this be configured in picoseconds?
  129. * Why it should be in ps: better understanding of this
  130. * relative to actual DRAM timing parameters such as tRAS.
  131. * e.g. tRAS(min) = 40 ns
  132. */
  133. popts->bstopre = 0x100;
  134. /* Minimum CKE pulse width -- tCKE(MIN) */
  135. popts->tCKE_clock_pulse_width_ps
  136. = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
  137. /*
  138. * Window for four activates -- tFAW
  139. *
  140. * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
  141. * FIXME: varies depending upon number of column addresses or data
  142. * FIXME: width, was considering looking at pdimm->primary_sdram_width
  143. */
  144. #if defined(CONFIG_FSL_DDR1)
  145. popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
  146. #elif defined(CONFIG_FSL_DDR2)
  147. /*
  148. * x4/x8; some datasheets have 35000
  149. * x16 wide columns only? Use 50000?
  150. */
  151. popts->tFAW_window_four_activates_ps = 37500;
  152. #elif defined(CONFIG_FSL_DDR3)
  153. #error "FIXME determine four activates for DDR3"
  154. #endif
  155. /*
  156. * Check interleaving configuration from environment.
  157. * Please refer to doc/README.fsl-ddr for the detail.
  158. *
  159. * If memory controller interleaving is enabled, then the data
  160. * bus widths must be programmed identically for the 2 memory
  161. * controllers.
  162. *
  163. * XXX: Attempt to set both controllers to the same chip select
  164. * interleaving mode. It will do a best effort to get the
  165. * requested ranks interleaved together such that the result
  166. * should be a subset of the requested configuration.
  167. */
  168. #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
  169. if ((p = getenv("memctl_intlv_ctl")) != NULL) {
  170. if (pdimm[0].n_ranks == 0) {
  171. printf("There is no rank on CS0. Because only rank on "
  172. "CS0 and ranks chip-select interleaved with CS0"
  173. " are controller interleaved, force non memory "
  174. "controller interleaving\n");
  175. popts->memctl_interleaving = 0;
  176. } else {
  177. popts->memctl_interleaving = 1;
  178. if (strcmp(p, "cacheline") == 0)
  179. popts->memctl_interleaving_mode =
  180. FSL_DDR_CACHE_LINE_INTERLEAVING;
  181. else if (strcmp(p, "page") == 0)
  182. popts->memctl_interleaving_mode =
  183. FSL_DDR_PAGE_INTERLEAVING;
  184. else if (strcmp(p, "bank") == 0)
  185. popts->memctl_interleaving_mode =
  186. FSL_DDR_BANK_INTERLEAVING;
  187. else if (strcmp(p, "superbank") == 0)
  188. popts->memctl_interleaving_mode =
  189. FSL_DDR_SUPERBANK_INTERLEAVING;
  190. else
  191. popts->memctl_interleaving_mode =
  192. simple_strtoul(p, NULL, 0);
  193. }
  194. }
  195. if( (p = getenv("ba_intlv_ctl")) != NULL) {
  196. if (strcmp(p, "cs0_cs1") == 0)
  197. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1;
  198. else if (strcmp(p, "cs2_cs3") == 0)
  199. popts->ba_intlv_ctl = FSL_DDR_CS2_CS3;
  200. else if (strcmp(p, "cs0_cs1_and_cs2_cs3") == 0)
  201. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_AND_CS2_CS3;
  202. else if (strcmp(p, "cs0_cs1_cs2_cs3") == 0)
  203. popts->ba_intlv_ctl = FSL_DDR_CS0_CS1_CS2_CS3;
  204. else
  205. popts->ba_intlv_ctl = simple_strtoul(p, NULL, 0);
  206. switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
  207. case FSL_DDR_CS0_CS1_CS2_CS3:
  208. case FSL_DDR_CS0_CS1:
  209. if (pdimm[0].n_ranks != 2) {
  210. popts->ba_intlv_ctl = 0;
  211. printf("Not enough bank(chip-select) for "
  212. "CS0+CS1, force non-interleaving!\n");
  213. }
  214. break;
  215. case FSL_DDR_CS2_CS3:
  216. if (pdimm[1].n_ranks !=2){
  217. popts->ba_intlv_ctl = 0;
  218. printf("Not enough bank(CS) for CS2+CS3, "
  219. "force non-interleaving!\n");
  220. }
  221. break;
  222. case FSL_DDR_CS0_CS1_AND_CS2_CS3:
  223. if ((pdimm[0].n_ranks != 2)||(pdimm[1].n_ranks != 2)) {
  224. popts->ba_intlv_ctl = 0;
  225. printf("Not enough bank(CS) for CS0+CS1 or "
  226. "CS2+CS3, force non-interleaving!\n");
  227. }
  228. break;
  229. default:
  230. popts->ba_intlv_ctl = 0;
  231. break;
  232. }
  233. }
  234. #endif
  235. fsl_ddr_board_options(popts, pdimm, ctrl_num);
  236. return 0;
  237. }