blob: 127a84039c337556c90cff6d55defa8b4eef89ab [file] [log] [blame]
Kumar Gala124b0822008-08-26 15:01:29 -05001/*
Kumar Galaf582d982011-01-09 14:06:28 -06002 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Gala124b0822008-08-26 15:01:29 -05003 *
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
9#ifndef FSL_DDR_MEMCTL_H
10#define FSL_DDR_MEMCTL_H
11
12/*
13 * Pick a basic DDR Technology.
14 */
15#include <ddr_spd.h>
16
17#define SDRAM_TYPE_DDR1 2
18#define SDRAM_TYPE_DDR2 3
19#define SDRAM_TYPE_LPDDR1 6
20#define SDRAM_TYPE_DDR3 7
21
Dave Liu4be87b22009-03-14 12:48:30 +080022#define DDR_BL4 4 /* burst length 4 */
23#define DDR_BC4 DDR_BL4 /* burst chop for ddr3 */
24#define DDR_OTF 6 /* on-the-fly BC4 and BL8 */
25#define DDR_BL8 8 /* burst length 8 */
26
York Sunba0c2eb2011-01-10 12:03:00 +000027#define DDR3_RTT_OFF 0
Dave Liu04899192010-03-05 12:23:00 +080028#define DDR3_RTT_60_OHM 1 /* RTT_Nom = RZQ/4 */
29#define DDR3_RTT_120_OHM 2 /* RTT_Nom = RZQ/2 */
30#define DDR3_RTT_40_OHM 3 /* RTT_Nom = RZQ/6 */
31#define DDR3_RTT_20_OHM 4 /* RTT_Nom = RZQ/12 */
32#define DDR3_RTT_30_OHM 5 /* RTT_Nom = RZQ/8 */
33
Kumar Gala124b0822008-08-26 15:01:29 -050034#if defined(CONFIG_FSL_DDR1)
35#define FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR (1)
36typedef ddr1_spd_eeprom_t generic_spd_eeprom_t;
37#ifndef CONFIG_FSL_SDRAM_TYPE
38#define CONFIG_FSL_SDRAM_TYPE SDRAM_TYPE_DDR1
39#endif
40#elif defined(CONFIG_FSL_DDR2)
41#define FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR (3)
42typedef ddr2_spd_eeprom_t generic_spd_eeprom_t;
43#ifndef CONFIG_FSL_SDRAM_TYPE
44#define CONFIG_FSL_SDRAM_TYPE SDRAM_TYPE_DDR2
45#endif
46#elif defined(CONFIG_FSL_DDR3)
47#define FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR (3) /* FIXME */
48typedef ddr3_spd_eeprom_t generic_spd_eeprom_t;
Dave Liu4758d532008-11-21 16:31:29 +080049#ifndef CONFIG_FSL_SDRAM_TYPE
50#define CONFIG_FSL_SDRAM_TYPE SDRAM_TYPE_DDR3
Kumar Gala124b0822008-08-26 15:01:29 -050051#endif
Dave Liu4758d532008-11-21 16:31:29 +080052#endif /* #if defined(CONFIG_FSL_DDR1) */
Kumar Gala124b0822008-08-26 15:01:29 -050053
York Sunba0c2eb2011-01-10 12:03:00 +000054#define FSL_DDR_ODT_NEVER 0x0
55#define FSL_DDR_ODT_CS 0x1
56#define FSL_DDR_ODT_ALL_OTHER_CS 0x2
57#define FSL_DDR_ODT_OTHER_DIMM 0x3
58#define FSL_DDR_ODT_ALL 0x4
59#define FSL_DDR_ODT_SAME_DIMM 0x5
60#define FSL_DDR_ODT_CS_AND_OTHER_DIMM 0x6
61#define FSL_DDR_ODT_OTHER_CS_ONSAMEDIMM 0x7
62
Haiying Wang272b5962008-10-03 12:36:39 -040063/* define bank(chip select) interleaving mode */
64#define FSL_DDR_CS0_CS1 0x40
65#define FSL_DDR_CS2_CS3 0x20
66#define FSL_DDR_CS0_CS1_AND_CS2_CS3 (FSL_DDR_CS0_CS1 | FSL_DDR_CS2_CS3)
67#define FSL_DDR_CS0_CS1_CS2_CS3 (FSL_DDR_CS0_CS1_AND_CS2_CS3 | 0x04)
68
69/* define memory controller interleaving mode */
70#define FSL_DDR_CACHE_LINE_INTERLEAVING 0x0
71#define FSL_DDR_PAGE_INTERLEAVING 0x1
72#define FSL_DDR_BANK_INTERLEAVING 0x2
73#define FSL_DDR_SUPERBANK_INTERLEAVING 0x3
74
Poonam_Aggrwal-b1081230cb1452009-01-04 08:46:38 +053075/* DDR_SDRAM_CFG - DDR SDRAM Control Configuration
76 */
77#define SDRAM_CFG_MEM_EN 0x80000000
78#define SDRAM_CFG_SREN 0x40000000
79#define SDRAM_CFG_ECC_EN 0x20000000
80#define SDRAM_CFG_RD_EN 0x10000000
81#define SDRAM_CFG_SDRAM_TYPE_DDR1 0x02000000
82#define SDRAM_CFG_SDRAM_TYPE_DDR2 0x03000000
83#define SDRAM_CFG_SDRAM_TYPE_MASK 0x07000000
84#define SDRAM_CFG_SDRAM_TYPE_SHIFT 24
85#define SDRAM_CFG_DYN_PWR 0x00200000
86#define SDRAM_CFG_32_BE 0x00080000
Poonam Aggrwal42d36402011-02-07 15:09:51 +053087#define SDRAM_CFG_16_BE 0x00100000
Poonam_Aggrwal-b1081230cb1452009-01-04 08:46:38 +053088#define SDRAM_CFG_8_BE 0x00040000
89#define SDRAM_CFG_NCAP 0x00020000
90#define SDRAM_CFG_2T_EN 0x00008000
91#define SDRAM_CFG_BI 0x00000001
92
York Sunc8fc9592011-01-25 22:05:49 -080093#define SDRAM_CFG2_D_INIT 0x00000010
94#define SDRAM_CFG2_ODT_CFG_MASK 0x00600000
95
96#define TIMING_CFG_2_CPO_MASK 0x0F800000
97
Dave Liu4be87b22009-03-14 12:48:30 +080098#if defined(CONFIG_P4080)
99#define RD_TO_PRE_MASK 0xf
100#define RD_TO_PRE_SHIFT 13
101#define WR_DATA_DELAY_MASK 0xf
102#define WR_DATA_DELAY_SHIFT 9
103#else
104#define RD_TO_PRE_MASK 0x7
105#define RD_TO_PRE_SHIFT 13
106#define WR_DATA_DELAY_MASK 0x7
107#define WR_DATA_DELAY_SHIFT 10
108#endif
109
York Sun922f40f2011-01-10 12:03:01 +0000110/* DDR_MD_CNTL */
111#define MD_CNTL_MD_EN 0x80000000
112#define MD_CNTL_CS_SEL_CS0 0x00000000
113#define MD_CNTL_CS_SEL_CS1 0x10000000
114#define MD_CNTL_CS_SEL_CS2 0x20000000
115#define MD_CNTL_CS_SEL_CS3 0x30000000
116#define MD_CNTL_CS_SEL_CS0_CS1 0x40000000
117#define MD_CNTL_CS_SEL_CS2_CS3 0x50000000
118#define MD_CNTL_MD_SEL_MR 0x00000000
119#define MD_CNTL_MD_SEL_EMR 0x01000000
120#define MD_CNTL_MD_SEL_EMR2 0x02000000
121#define MD_CNTL_MD_SEL_EMR3 0x03000000
122#define MD_CNTL_SET_REF 0x00800000
123#define MD_CNTL_SET_PRE 0x00400000
124#define MD_CNTL_CKE_CNTL_LOW 0x00100000
125#define MD_CNTL_CKE_CNTL_HIGH 0x00200000
126#define MD_CNTL_WRCW 0x00080000
127#define MD_CNTL_MD_VALUE(x) (x & 0x0000FFFF)
128
York Sun00a69c02011-01-10 12:03:02 +0000129/* DDR_CDR1 */
130#define DDR_CDR1_DHC_EN 0x80000000
131
Kumar Gala124b0822008-08-26 15:01:29 -0500132/* Record of register values computed */
133typedef struct fsl_ddr_cfg_regs_s {
134 struct {
135 unsigned int bnds;
136 unsigned int config;
137 unsigned int config_2;
138 } cs[CONFIG_CHIP_SELECTS_PER_CTRL];
139 unsigned int timing_cfg_3;
140 unsigned int timing_cfg_0;
141 unsigned int timing_cfg_1;
142 unsigned int timing_cfg_2;
143 unsigned int ddr_sdram_cfg;
144 unsigned int ddr_sdram_cfg_2;
145 unsigned int ddr_sdram_mode;
146 unsigned int ddr_sdram_mode_2;
York Sunba0c2eb2011-01-10 12:03:00 +0000147 unsigned int ddr_sdram_mode_3;
148 unsigned int ddr_sdram_mode_4;
149 unsigned int ddr_sdram_mode_5;
150 unsigned int ddr_sdram_mode_6;
151 unsigned int ddr_sdram_mode_7;
152 unsigned int ddr_sdram_mode_8;
Kumar Gala124b0822008-08-26 15:01:29 -0500153 unsigned int ddr_sdram_md_cntl;
154 unsigned int ddr_sdram_interval;
155 unsigned int ddr_data_init;
156 unsigned int ddr_sdram_clk_cntl;
157 unsigned int ddr_init_addr;
158 unsigned int ddr_init_ext_addr;
159 unsigned int timing_cfg_4;
160 unsigned int timing_cfg_5;
161 unsigned int ddr_zq_cntl;
162 unsigned int ddr_wrlvl_cntl;
Kumar Gala124b0822008-08-26 15:01:29 -0500163 unsigned int ddr_sr_cntr;
164 unsigned int ddr_sdram_rcw_1;
165 unsigned int ddr_sdram_rcw_2;
york42603722010-07-02 22:25:54 +0000166 unsigned int ddr_eor;
York Sun7dda8472011-01-10 12:02:59 +0000167 unsigned int ddr_cdr1;
168 unsigned int ddr_cdr2;
169 unsigned int err_disable;
170 unsigned int err_int_en;
171 unsigned int debug[32];
Kumar Gala124b0822008-08-26 15:01:29 -0500172} fsl_ddr_cfg_regs_t;
173
174typedef struct memctl_options_partial_s {
175 unsigned int all_DIMMs_ECC_capable;
176 unsigned int all_DIMMs_tCKmax_ps;
177 unsigned int all_DIMMs_burst_lengths_bitmask;
178 unsigned int all_DIMMs_registered;
179 unsigned int all_DIMMs_unbuffered;
180 /* unsigned int lowest_common_SPD_caslat; */
181 unsigned int all_DIMMs_minimum_tRCD_ps;
182} memctl_options_partial_t;
183
184/*
185 * Generalized parameters for memory controller configuration,
186 * might be a little specific to the FSL memory controller
187 */
188typedef struct memctl_options_s {
189 /*
190 * Memory organization parameters
191 *
192 * if DIMM is present in the system
193 * where DIMMs are with respect to chip select
194 * where chip selects are with respect to memory boundaries
195 */
196 unsigned int registered_dimm_en; /* use registered DIMM support */
197
198 /* Options local to a Chip Select */
199 struct cs_local_opts_s {
200 unsigned int auto_precharge;
201 unsigned int odt_rd_cfg;
202 unsigned int odt_wr_cfg;
York Sunba0c2eb2011-01-10 12:03:00 +0000203 unsigned int odt_rtt_norm;
204 unsigned int odt_rtt_wr;
Kumar Gala124b0822008-08-26 15:01:29 -0500205 } cs_local_opts[CONFIG_CHIP_SELECTS_PER_CTRL];
206
207 /* Special configurations for chip select */
208 unsigned int memctl_interleaving;
209 unsigned int memctl_interleaving_mode;
210 unsigned int ba_intlv_ctl;
york42603722010-07-02 22:25:54 +0000211 unsigned int addr_hash;
Kumar Gala124b0822008-08-26 15:01:29 -0500212
213 /* Operational mode parameters */
214 unsigned int ECC_mode; /* Use ECC? */
215 /* Initialize ECC using memory controller? */
216 unsigned int ECC_init_using_memctl;
217 unsigned int DQS_config; /* Use DQS? maybe only with DDR2? */
218 /* SREN - self-refresh during sleep */
219 unsigned int self_refresh_in_sleep;
220 unsigned int dynamic_power; /* DYN_PWR */
221 /* memory data width to use (16-bit, 32-bit, 64-bit) */
222 unsigned int data_bus_width;
Dave Liu4be87b22009-03-14 12:48:30 +0800223 unsigned int burst_length; /* BL4, OTF and BL8 */
224 /* On-The-Fly Burst Chop enable */
225 unsigned int OTF_burst_chop_en;
226 /* mirrior DIMMs for DDR3 */
227 unsigned int mirrored_dimm;
yorkf4f93c62010-07-02 22:25:53 +0000228 unsigned int quad_rank_present;
York Sun7dda8472011-01-10 12:02:59 +0000229 unsigned int ap_en; /* address parity enable for RDIMM */
Kumar Gala124b0822008-08-26 15:01:29 -0500230
231 /* Global Timing Parameters */
232 unsigned int cas_latency_override;
233 unsigned int cas_latency_override_value;
234 unsigned int use_derated_caslat;
235 unsigned int additive_latency_override;
236 unsigned int additive_latency_override_value;
237
238 unsigned int clk_adjust; /* */
239 unsigned int cpo_override;
240 unsigned int write_data_delay; /* DQS adjust */
Dave Liu64ee7df2009-12-16 10:24:37 -0600241
242 unsigned int wrlvl_override;
243 unsigned int wrlvl_sample; /* Write leveling */
244 unsigned int wrlvl_start;
245
Kumar Gala124b0822008-08-26 15:01:29 -0500246 unsigned int half_strength_driver_enable;
247 unsigned int twoT_en;
248 unsigned int threeT_en;
249 unsigned int bstopre;
250 unsigned int tCKE_clock_pulse_width_ps; /* tCKE */
251 unsigned int tFAW_window_four_activates_ps; /* tFAW -- FOUR_ACT */
Dave Liu2aad0ae2008-11-21 16:31:35 +0800252
Dave Liu4be87b22009-03-14 12:48:30 +0800253 /* Rtt impedance */
254 unsigned int rtt_override; /* rtt_override enable */
255 unsigned int rtt_override_value; /* that is Rtt_Nom for DDR3 */
Dave Liu2d0f1252009-12-16 10:24:38 -0600256 unsigned int rtt_wr_override_value; /* this is Rtt_WR for DDR3 */
Dave Liu4be87b22009-03-14 12:48:30 +0800257
Dave Liu2aad0ae2008-11-21 16:31:35 +0800258 /* Automatic self refresh */
259 unsigned int auto_self_refresh_en;
260 unsigned int sr_it;
Dave Liu4be87b22009-03-14 12:48:30 +0800261 /* ZQ calibration */
262 unsigned int zq_en;
263 /* Write leveling */
264 unsigned int wrlvl_en;
York Sun7dda8472011-01-10 12:02:59 +0000265 /* RCW override for RDIMM */
266 unsigned int rcw_override;
267 unsigned int rcw_1;
268 unsigned int rcw_2;
269 /* control register 1 */
270 unsigned int ddr_cdr1;
Kumar Gala124b0822008-08-26 15:01:29 -0500271} memctl_options_t;
272
273extern phys_size_t fsl_ddr_sdram(void);
Zhao Chenhui1a35f3d2011-01-28 17:58:37 +0800274extern phys_size_t fsl_ddr_sdram_size(void);
Kumar Galaf582d982011-01-09 14:06:28 -0600275extern int fsl_use_spd(void);
Kumar Gala27177192011-01-25 01:48:03 -0600276extern void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs,
277 unsigned int ctrl_num);
York Sun269c7eb2010-10-18 13:46:49 -0700278
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600279/*
280 * The 85xx boards have a common prototype for fixed_sdram so put the
281 * declaration here.
282 */
283#ifdef CONFIG_MPC85xx
284extern phys_size_t fixed_sdram(void);
285#endif
286
287#if defined(CONFIG_DDR_ECC)
288extern void ddr_enable_ecc(unsigned int dram_size);
289#endif
290
291
York Sun269c7eb2010-10-18 13:46:49 -0700292typedef struct fixed_ddr_parm{
293 int min_freq;
294 int max_freq;
295 fsl_ddr_cfg_regs_t *ddr_settings;
296} fixed_ddr_parm_t;
Kumar Gala124b0822008-08-26 15:01:29 -0500297#endif