options.c 5.0 KB

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