Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
Kumar Gala | f582d98 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 2 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 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 | |
| 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 Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 22 | #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 Sun | ba0c2eb | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 27 | #define DDR3_RTT_OFF 0 |
Dave Liu | 0489919 | 2010-03-05 12:23:00 +0800 | [diff] [blame] | 28 | #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 Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 34 | #if defined(CONFIG_FSL_DDR1) |
| 35 | #define FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR (1) |
| 36 | typedef 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) |
| 42 | typedef 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 */ |
| 48 | typedef ddr3_spd_eeprom_t generic_spd_eeprom_t; |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 49 | #ifndef CONFIG_FSL_SDRAM_TYPE |
| 50 | #define CONFIG_FSL_SDRAM_TYPE SDRAM_TYPE_DDR3 |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 51 | #endif |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 52 | #endif /* #if defined(CONFIG_FSL_DDR1) */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 53 | |
York Sun | ba0c2eb | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 54 | #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 Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 63 | /* 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-b10812 | 30cb145 | 2009-01-04 08:46:38 +0530 | [diff] [blame] | 75 | /* 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 Aggrwal | 42d3640 | 2011-02-07 15:09:51 +0530 | [diff] [blame] | 87 | #define SDRAM_CFG_16_BE 0x00100000 |
Poonam_Aggrwal-b10812 | 30cb145 | 2009-01-04 08:46:38 +0530 | [diff] [blame] | 88 | #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 Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 93 | #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 Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 98 | #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 Sun | 922f40f | 2011-01-10 12:03:01 +0000 | [diff] [blame] | 110 | /* 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 Sun | 00a69c0 | 2011-01-10 12:03:02 +0000 | [diff] [blame] | 129 | /* DDR_CDR1 */ |
| 130 | #define DDR_CDR1_DHC_EN 0x80000000 |
| 131 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 132 | /* Record of register values computed */ |
| 133 | typedef 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 Sun | ba0c2eb | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 147 | 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 Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 153 | 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 Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 163 | unsigned int ddr_sr_cntr; |
| 164 | unsigned int ddr_sdram_rcw_1; |
| 165 | unsigned int ddr_sdram_rcw_2; |
york | 4260372 | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 166 | unsigned int ddr_eor; |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 167 | 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 Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 172 | } fsl_ddr_cfg_regs_t; |
| 173 | |
| 174 | typedef 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 | */ |
| 188 | typedef 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 Sun | ba0c2eb | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 203 | unsigned int odt_rtt_norm; |
| 204 | unsigned int odt_rtt_wr; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 205 | } 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; |
york | 4260372 | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 211 | unsigned int addr_hash; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 212 | |
| 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 Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 223 | 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; |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 228 | unsigned int quad_rank_present; |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 229 | unsigned int ap_en; /* address parity enable for RDIMM */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 230 | |
| 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 Liu | 64ee7df | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 241 | |
| 242 | unsigned int wrlvl_override; |
| 243 | unsigned int wrlvl_sample; /* Write leveling */ |
| 244 | unsigned int wrlvl_start; |
| 245 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 246 | 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 Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 252 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 253 | /* Rtt impedance */ |
| 254 | unsigned int rtt_override; /* rtt_override enable */ |
| 255 | unsigned int rtt_override_value; /* that is Rtt_Nom for DDR3 */ |
Dave Liu | 2d0f125 | 2009-12-16 10:24:38 -0600 | [diff] [blame] | 256 | unsigned int rtt_wr_override_value; /* this is Rtt_WR for DDR3 */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 257 | |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 258 | /* Automatic self refresh */ |
| 259 | unsigned int auto_self_refresh_en; |
| 260 | unsigned int sr_it; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 261 | /* ZQ calibration */ |
| 262 | unsigned int zq_en; |
| 263 | /* Write leveling */ |
| 264 | unsigned int wrlvl_en; |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 265 | /* 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 Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 271 | } memctl_options_t; |
| 272 | |
| 273 | extern phys_size_t fsl_ddr_sdram(void); |
Zhao Chenhui | 1a35f3d | 2011-01-28 17:58:37 +0800 | [diff] [blame^] | 274 | extern phys_size_t fsl_ddr_sdram_size(void); |
Kumar Gala | f582d98 | 2011-01-09 14:06:28 -0600 | [diff] [blame] | 275 | extern int fsl_use_spd(void); |
Kumar Gala | 2717719 | 2011-01-25 01:48:03 -0600 | [diff] [blame] | 276 | extern void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs, |
| 277 | unsigned int ctrl_num); |
York Sun | 269c7eb | 2010-10-18 13:46:49 -0700 | [diff] [blame] | 278 | |
Becky Bruce | 5e35d8a | 2010-12-17 17:17:56 -0600 | [diff] [blame] | 279 | /* |
| 280 | * The 85xx boards have a common prototype for fixed_sdram so put the |
| 281 | * declaration here. |
| 282 | */ |
| 283 | #ifdef CONFIG_MPC85xx |
| 284 | extern phys_size_t fixed_sdram(void); |
| 285 | #endif |
| 286 | |
| 287 | #if defined(CONFIG_DDR_ECC) |
| 288 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 289 | #endif |
| 290 | |
| 291 | |
York Sun | 269c7eb | 2010-10-18 13:46:49 -0700 | [diff] [blame] | 292 | typedef 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 Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 297 | #endif |