2 * Copyright 2008 Freescale Semiconductor, Inc.
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.
10 #include <asm/fsl_ddr_sdram.h>
14 /* Board-specific functions defined in each board's ddr.c */
15 extern void fsl_ddr_board_options(memctl_options_t *popts,
17 unsigned int ctrl_num);
19 unsigned int populate_memctl_options(int all_DIMMs_registered,
20 memctl_options_t *popts,
22 unsigned int ctrl_num)
26 /* Chip select options. */
28 /* Pick chip-select local options. */
29 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
30 /* If not DDR2, odt_rd_cfg and odt_wr_cfg need to be 0. */
32 /* only for single CS? */
33 popts->cs_local_opts[i].odt_rd_cfg = 0;
35 popts->cs_local_opts[i].odt_wr_cfg = 1;
36 popts->cs_local_opts[i].auto_precharge = 0;
39 /* Pick interleaving mode. */
43 * 1 = interleaving between 2 controllers
45 popts->memctl_interleaving = 0;
51 * 3 = superbank (only if CS interleaving is enabled)
53 popts->memctl_interleaving_mode = 0;
56 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
57 * 1: page: bit to the left of the column bits selects the memctl
58 * 2: bank: bit to the left of the bank bits selects the memctl
59 * 3: superbank: bit to the left of the chip select selects the memctl
61 * NOTE: ba_intlv (rank interleaving) is independent of memory
62 * controller interleaving; it is only within a memory controller.
63 * Must use superbank interleaving if rank interleaving is used and
64 * memory controller interleaving is enabled.
71 * 0x60 = CS0,CS1 + CS2,CS3
72 * 0x04 = CS0,CS1,CS2,CS3
74 popts->ba_intlv_ctl = 0;
76 /* Memory Organization Parameters */
77 popts->registered_dimm_en = all_DIMMs_registered;
79 /* Operational Mode Paramters */
83 popts->ECC_mode = 1; /* 0 = disabled, 1 = enabled */
85 popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */
87 popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
94 #if defined(CONFIG_FSL_DDR1)
95 popts->DQS_config = 0;
96 #elif defined(CONFIG_FSL_DDR2)
97 popts->DQS_config = 1;
99 #error "Fix DQS for DDR3"
102 /* Choose self-refresh during sleep. */
103 popts->self_refresh_in_sleep = 1;
105 /* Choose dynamic power management mode. */
106 popts->dynamic_power = 0;
108 /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */
109 popts->data_bus_width = 0;
111 /* Choose burst length. */
112 popts->burst_length = 4; /* has to be 4 for DDR2 */
114 /* Global Timing Parameters. */
115 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
117 /* Pick a caslat override. */
118 popts->cas_latency_override = 0;
119 popts->cas_latency_override_value = 3;
120 if (popts->cas_latency_override) {
121 debug("using caslat override value = %u\n",
122 popts->cas_latency_override_value);
125 /* Decide whether to use the computed derated latency */
126 popts->use_derated_caslat = 0;
128 /* Choose an additive latency. */
129 popts->additive_latency_override = 0;
130 popts->additive_latency_override_value = 3;
131 if (popts->additive_latency_override) {
132 debug("using additive latency override value = %u\n",
133 popts->additive_latency_override_value);
139 * Factors to consider for 2T_EN:
140 * - number of DIMMs installed
141 * - number of components, number of active ranks
142 * - how much time you want to spend playing around
145 popts->threeT_en = 0;
148 * BSTTOPRE precharge interval
150 * Set this to 0 for global auto precharge
152 * FIXME: Should this be configured in picoseconds?
153 * Why it should be in ps: better understanding of this
154 * relative to actual DRAM timing parameters such as tRAS.
155 * e.g. tRAS(min) = 40 ns
157 popts->bstopre = 0x100;
159 /* Minimum CKE pulse width -- tCKE(MIN) */
160 popts->tCKE_clock_pulse_width_ps
161 = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
164 * Window for four activates -- tFAW
166 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
167 * FIXME: varies depending upon number of column addresses or data
168 * FIXME: width, was considering looking at pdimm->primary_sdram_width
170 #if defined(CONFIG_FSL_DDR1)
171 popts->tFAW_window_four_activates_ps = mclk_to_picos(1);
173 #elif defined(CONFIG_FSL_DDR2)
175 * x4/x8; some datasheets have 35000
176 * x16 wide columns only? Use 50000?
178 popts->tFAW_window_four_activates_ps = 37500;
180 #elif defined(CONFIG_FSL_DDR3)
181 #error "FIXME determine four activates for DDR3"
184 /* ODT should only be used for DDR2 */
189 * Interleaving checks.
191 * If memory controller interleaving is enabled, then the data
192 * bus widths must be programmed identically for the 2 memory
196 fsl_ddr_board_options(popts, pdimm, ctrl_num);