Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
Dave Liu | 3525e1a | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 2 | * Copyright 2008-2010 Freescale Semiconductor, Inc. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 3 | * |
Dave Liu | 3525e1a | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the Free |
| 6 | * Software Foundation; either version 2 of the License, or (at your option) |
| 7 | * any later version. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Generic driver for Freescale DDR/DDR2/DDR3 memory controller. |
| 12 | * Based on code from spd_sdram.c |
| 13 | * Author: James Yang [at freescale.com] |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | #include <asm/fsl_ddr_sdram.h> |
| 18 | |
| 19 | #include "ddr.h" |
| 20 | |
| 21 | extern unsigned int picos_to_mclk(unsigned int picos); |
| 22 | /* |
| 23 | * Determine Rtt value. |
| 24 | * |
| 25 | * This should likely be either board or controller specific. |
| 26 | * |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 27 | * Rtt(nominal) - DDR2: |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 28 | * 0 = Rtt disabled |
| 29 | * 1 = 75 ohm |
| 30 | * 2 = 150 ohm |
| 31 | * 3 = 50 ohm |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 32 | * Rtt(nominal) - DDR3: |
| 33 | * 0 = Rtt disabled |
| 34 | * 1 = 60 ohm |
| 35 | * 2 = 120 ohm |
| 36 | * 3 = 40 ohm |
| 37 | * 4 = 20 ohm |
| 38 | * 5 = 30 ohm |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 39 | * |
| 40 | * FIXME: Apparently 8641 needs a value of 2 |
| 41 | * FIXME: Old code seys if 667 MHz or higher, use 3 on 8572 |
| 42 | * |
| 43 | * FIXME: There was some effort down this line earlier: |
| 44 | * |
| 45 | * unsigned int i; |
| 46 | * for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL/2; i++) { |
| 47 | * if (popts->dimmslot[i].num_valid_cs |
| 48 | * && (popts->cs_local_opts[2*i].odt_rd_cfg |
| 49 | * || popts->cs_local_opts[2*i].odt_wr_cfg)) { |
| 50 | * rtt = 2; |
| 51 | * break; |
| 52 | * } |
| 53 | * } |
| 54 | */ |
| 55 | static inline int fsl_ddr_get_rtt(void) |
| 56 | { |
| 57 | int rtt; |
| 58 | |
| 59 | #if defined(CONFIG_FSL_DDR1) |
| 60 | rtt = 0; |
| 61 | #elif defined(CONFIG_FSL_DDR2) |
| 62 | rtt = 3; |
| 63 | #else |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 64 | rtt = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | return rtt; |
| 68 | } |
| 69 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 70 | /* |
| 71 | * compute the CAS write latency according to DDR3 spec |
| 72 | * CWL = 5 if tCK >= 2.5ns |
| 73 | * 6 if 2.5ns > tCK >= 1.875ns |
| 74 | * 7 if 1.875ns > tCK >= 1.5ns |
| 75 | * 8 if 1.5ns > tCK >= 1.25ns |
| 76 | */ |
| 77 | static inline unsigned int compute_cas_write_latency(void) |
| 78 | { |
| 79 | unsigned int cwl; |
| 80 | const unsigned int mclk_ps = get_memory_clk_period_ps(); |
| 81 | |
| 82 | if (mclk_ps >= 2500) |
| 83 | cwl = 5; |
| 84 | else if (mclk_ps >= 1875) |
| 85 | cwl = 6; |
| 86 | else if (mclk_ps >= 1500) |
| 87 | cwl = 7; |
| 88 | else if (mclk_ps >= 1250) |
| 89 | cwl = 8; |
| 90 | else |
| 91 | cwl = 8; |
| 92 | return cwl; |
| 93 | } |
| 94 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 95 | /* Chip Select Configuration (CSn_CONFIG) */ |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 96 | static void set_csn_config(int dimm_number, int i, fsl_ddr_cfg_regs_t *ddr, |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 97 | const memctl_options_t *popts, |
| 98 | const dimm_params_t *dimm_params) |
| 99 | { |
| 100 | unsigned int cs_n_en = 0; /* Chip Select enable */ |
| 101 | unsigned int intlv_en = 0; /* Memory controller interleave enable */ |
| 102 | unsigned int intlv_ctl = 0; /* Interleaving control */ |
| 103 | unsigned int ap_n_en = 0; /* Chip select n auto-precharge enable */ |
| 104 | unsigned int odt_rd_cfg = 0; /* ODT for reads configuration */ |
| 105 | unsigned int odt_wr_cfg = 0; /* ODT for writes configuration */ |
| 106 | unsigned int ba_bits_cs_n = 0; /* Num of bank bits for SDRAM on CSn */ |
| 107 | unsigned int row_bits_cs_n = 0; /* Num of row bits for SDRAM on CSn */ |
| 108 | unsigned int col_bits_cs_n = 0; /* Num of ocl bits for SDRAM on CSn */ |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 109 | int go_config = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 110 | |
| 111 | /* Compute CS_CONFIG only for existing ranks of each DIMM. */ |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 112 | switch (i) { |
| 113 | case 0: |
| 114 | if (dimm_params[dimm_number].n_ranks > 0) { |
| 115 | go_config = 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 116 | /* These fields only available in CS0_CONFIG */ |
| 117 | intlv_en = popts->memctl_interleaving; |
| 118 | intlv_ctl = popts->memctl_interleaving_mode; |
| 119 | } |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 120 | break; |
| 121 | case 1: |
| 122 | if ((dimm_number == 0 && dimm_params[0].n_ranks > 1) || \ |
| 123 | (dimm_number == 1 && dimm_params[1].n_ranks > 0)) |
| 124 | go_config = 1; |
| 125 | break; |
| 126 | case 2: |
| 127 | if ((dimm_number == 0 && dimm_params[0].n_ranks > 2) || \ |
| 128 | (dimm_number > 1 && dimm_params[dimm_number].n_ranks > 0)) |
| 129 | go_config = 1; |
| 130 | break; |
| 131 | case 3: |
| 132 | if ((dimm_number == 0 && dimm_params[0].n_ranks > 3) || \ |
| 133 | (dimm_number == 1 && dimm_params[1].n_ranks > 1) || \ |
| 134 | (dimm_number == 3 && dimm_params[3].n_ranks > 0)) |
| 135 | go_config = 1; |
| 136 | break; |
| 137 | default: |
| 138 | break; |
| 139 | } |
| 140 | if (go_config) { |
| 141 | unsigned int n_banks_per_sdram_device; |
| 142 | cs_n_en = 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 143 | ap_n_en = popts->cs_local_opts[i].auto_precharge; |
| 144 | odt_rd_cfg = popts->cs_local_opts[i].odt_rd_cfg; |
| 145 | odt_wr_cfg = popts->cs_local_opts[i].odt_wr_cfg; |
| 146 | n_banks_per_sdram_device |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 147 | = dimm_params[dimm_number].n_banks_per_sdram_device; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 148 | ba_bits_cs_n = __ilog2(n_banks_per_sdram_device) - 2; |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 149 | row_bits_cs_n = dimm_params[dimm_number].n_row_addr - 12; |
| 150 | col_bits_cs_n = dimm_params[dimm_number].n_col_addr - 8; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 151 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 152 | ddr->cs[i].config = (0 |
| 153 | | ((cs_n_en & 0x1) << 31) |
| 154 | | ((intlv_en & 0x3) << 29) |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 155 | | ((intlv_ctl & 0xf) << 24) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 156 | | ((ap_n_en & 0x1) << 23) |
| 157 | |
| 158 | /* XXX: some implementation only have 1 bit starting at left */ |
| 159 | | ((odt_rd_cfg & 0x7) << 20) |
| 160 | |
| 161 | /* XXX: Some implementation only have 1 bit starting at left */ |
| 162 | | ((odt_wr_cfg & 0x7) << 16) |
| 163 | |
| 164 | | ((ba_bits_cs_n & 0x3) << 14) |
| 165 | | ((row_bits_cs_n & 0x7) << 8) |
| 166 | | ((col_bits_cs_n & 0x7) << 0) |
| 167 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 168 | debug("FSLDDR: cs[%d]_config = 0x%08x\n", i,ddr->cs[i].config); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* Chip Select Configuration 2 (CSn_CONFIG_2) */ |
| 172 | /* FIXME: 8572 */ |
| 173 | static void set_csn_config_2(int i, fsl_ddr_cfg_regs_t *ddr) |
| 174 | { |
| 175 | unsigned int pasr_cfg = 0; /* Partial array self refresh config */ |
| 176 | |
| 177 | ddr->cs[i].config_2 = ((pasr_cfg & 7) << 24); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 178 | debug("FSLDDR: cs[%d]_config_2 = 0x%08x\n", i, ddr->cs[i].config_2); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* -3E = 667 CL5, -25 = CL6 800, -25E = CL5 800 */ |
| 182 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 183 | #if !defined(CONFIG_FSL_DDR1) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 184 | /* |
| 185 | * DDR SDRAM Timing Configuration 0 (TIMING_CFG_0) |
| 186 | * |
| 187 | * Avoid writing for DDR I. The new PQ38 DDR controller |
| 188 | * dreams up non-zero default values to be backwards compatible. |
| 189 | */ |
| 190 | static void set_timing_cfg_0(fsl_ddr_cfg_regs_t *ddr) |
| 191 | { |
| 192 | unsigned char trwt_mclk = 0; /* Read-to-write turnaround */ |
| 193 | unsigned char twrt_mclk = 0; /* Write-to-read turnaround */ |
| 194 | /* 7.5 ns on -3E; 0 means WL - CL + BL/2 + 1 */ |
| 195 | unsigned char trrt_mclk = 0; /* Read-to-read turnaround */ |
| 196 | unsigned char twwt_mclk = 0; /* Write-to-write turnaround */ |
| 197 | |
| 198 | /* Active powerdown exit timing (tXARD and tXARDS). */ |
| 199 | unsigned char act_pd_exit_mclk; |
| 200 | /* Precharge powerdown exit timing (tXP). */ |
| 201 | unsigned char pre_pd_exit_mclk; |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 202 | /* ODT powerdown exit timing (tAXPD). */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 203 | unsigned char taxpd_mclk; |
| 204 | /* Mode register set cycle time (tMRD). */ |
| 205 | unsigned char tmrd_mclk; |
| 206 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 207 | #if defined(CONFIG_FSL_DDR3) |
| 208 | /* |
| 209 | * (tXARD and tXARDS). Empirical? |
| 210 | * The DDR3 spec has not tXARD, |
| 211 | * we use the tXP instead of it. |
| 212 | * tXP=max(3nCK, 7.5ns) for DDR3. |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 213 | * spec has not the tAXPD, we use |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 214 | * tAXPD=1, need design to confirm. |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 215 | */ |
Dave Liu | c7d983a | 2009-12-16 10:24:36 -0600 | [diff] [blame] | 216 | int tXP = max((get_memory_clk_period_ps() * 3), 7500); /* unit=ps */ |
| 217 | act_pd_exit_mclk = picos_to_mclk(tXP); |
| 218 | /* Mode register MR0[A12] is '1' - fast exit */ |
| 219 | pre_pd_exit_mclk = act_pd_exit_mclk; |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 220 | taxpd_mclk = 1; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 221 | tmrd_mclk = 4; |
Dave Liu | 8107926 | 2009-12-08 11:56:48 +0800 | [diff] [blame] | 222 | /* set the turnaround time */ |
| 223 | trwt_mclk = 1; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 224 | #else /* CONFIG_FSL_DDR2 */ |
| 225 | /* |
| 226 | * (tXARD and tXARDS). Empirical? |
| 227 | * tXARD = 2 for DDR2 |
| 228 | * tXP=2 |
| 229 | * tAXPD=8 |
| 230 | */ |
| 231 | act_pd_exit_mclk = 2; |
| 232 | pre_pd_exit_mclk = 2; |
| 233 | taxpd_mclk = 8; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 234 | tmrd_mclk = 2; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 235 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 236 | |
| 237 | ddr->timing_cfg_0 = (0 |
| 238 | | ((trwt_mclk & 0x3) << 30) /* RWT */ |
| 239 | | ((twrt_mclk & 0x3) << 28) /* WRT */ |
| 240 | | ((trrt_mclk & 0x3) << 26) /* RRT */ |
| 241 | | ((twwt_mclk & 0x3) << 24) /* WWT */ |
| 242 | | ((act_pd_exit_mclk & 0x7) << 20) /* ACT_PD_EXIT */ |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 243 | | ((pre_pd_exit_mclk & 0xF) << 16) /* PRE_PD_EXIT */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 244 | | ((taxpd_mclk & 0xf) << 8) /* ODT_PD_EXIT */ |
| 245 | | ((tmrd_mclk & 0xf) << 0) /* MRS_CYC */ |
| 246 | ); |
| 247 | debug("FSLDDR: timing_cfg_0 = 0x%08x\n", ddr->timing_cfg_0); |
| 248 | } |
| 249 | #endif /* defined(CONFIG_FSL_DDR2) */ |
| 250 | |
| 251 | /* DDR SDRAM Timing Configuration 3 (TIMING_CFG_3) */ |
| 252 | static void set_timing_cfg_3(fsl_ddr_cfg_regs_t *ddr, |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 253 | const common_timing_params_t *common_dimm, |
| 254 | unsigned int cas_latency) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 255 | { |
| 256 | /* Extended Activate to precharge interval (tRAS) */ |
| 257 | unsigned int ext_acttopre = 0; |
| 258 | unsigned int ext_refrec; /* Extended refresh recovery time (tRFC) */ |
| 259 | unsigned int ext_caslat = 0; /* Extended MCAS latency from READ cmd */ |
| 260 | unsigned int cntl_adj = 0; /* Control Adjust */ |
| 261 | |
Dave Liu | 5c1bb51 | 2008-11-21 16:31:22 +0800 | [diff] [blame] | 262 | /* If the tRAS > 19 MCLK, we use the ext mode */ |
| 263 | if (picos_to_mclk(common_dimm->tRAS_ps) > 0x13) |
| 264 | ext_acttopre = 1; |
| 265 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 266 | ext_refrec = (picos_to_mclk(common_dimm->tRFC_ps) - 8) >> 4; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 267 | |
| 268 | /* If the CAS latency more than 8, use the ext mode */ |
| 269 | if (cas_latency > 8) |
| 270 | ext_caslat = 1; |
| 271 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 272 | ddr->timing_cfg_3 = (0 |
| 273 | | ((ext_acttopre & 0x1) << 24) |
Dave Liu | 5c1bb51 | 2008-11-21 16:31:22 +0800 | [diff] [blame] | 274 | | ((ext_refrec & 0xF) << 16) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 275 | | ((ext_caslat & 0x1) << 12) |
| 276 | | ((cntl_adj & 0x7) << 0) |
| 277 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 278 | debug("FSLDDR: timing_cfg_3 = 0x%08x\n", ddr->timing_cfg_3); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* DDR SDRAM Timing Configuration 1 (TIMING_CFG_1) */ |
| 282 | static void set_timing_cfg_1(fsl_ddr_cfg_regs_t *ddr, |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 283 | const memctl_options_t *popts, |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 284 | const common_timing_params_t *common_dimm, |
| 285 | unsigned int cas_latency) |
| 286 | { |
| 287 | /* Precharge-to-activate interval (tRP) */ |
| 288 | unsigned char pretoact_mclk; |
| 289 | /* Activate to precharge interval (tRAS) */ |
| 290 | unsigned char acttopre_mclk; |
| 291 | /* Activate to read/write interval (tRCD) */ |
| 292 | unsigned char acttorw_mclk; |
| 293 | /* CASLAT */ |
| 294 | unsigned char caslat_ctrl; |
| 295 | /* Refresh recovery time (tRFC) ; trfc_low */ |
| 296 | unsigned char refrec_ctrl; |
| 297 | /* Last data to precharge minimum interval (tWR) */ |
| 298 | unsigned char wrrec_mclk; |
| 299 | /* Activate-to-activate interval (tRRD) */ |
| 300 | unsigned char acttoact_mclk; |
| 301 | /* Last write data pair to read command issue interval (tWTR) */ |
| 302 | unsigned char wrtord_mclk; |
| 303 | |
| 304 | pretoact_mclk = picos_to_mclk(common_dimm->tRP_ps); |
| 305 | acttopre_mclk = picos_to_mclk(common_dimm->tRAS_ps); |
| 306 | acttorw_mclk = picos_to_mclk(common_dimm->tRCD_ps); |
| 307 | |
| 308 | /* |
| 309 | * Translate CAS Latency to a DDR controller field value: |
| 310 | * |
| 311 | * CAS Lat DDR I DDR II Ctrl |
| 312 | * Clocks SPD Bit SPD Bit Value |
| 313 | * ------- ------- ------- ----- |
| 314 | * 1.0 0 0001 |
| 315 | * 1.5 1 0010 |
| 316 | * 2.0 2 2 0011 |
| 317 | * 2.5 3 0100 |
| 318 | * 3.0 4 3 0101 |
| 319 | * 3.5 5 0110 |
| 320 | * 4.0 4 0111 |
| 321 | * 4.5 1000 |
| 322 | * 5.0 5 1001 |
| 323 | */ |
| 324 | #if defined(CONFIG_FSL_DDR1) |
| 325 | caslat_ctrl = (cas_latency + 1) & 0x07; |
| 326 | #elif defined(CONFIG_FSL_DDR2) |
| 327 | caslat_ctrl = 2 * cas_latency - 1; |
| 328 | #else |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 329 | /* |
| 330 | * if the CAS latency more than 8 cycle, |
| 331 | * we need set extend bit for it at |
| 332 | * TIMING_CFG_3[EXT_CASLAT] |
| 333 | */ |
| 334 | if (cas_latency > 8) |
| 335 | cas_latency -= 8; |
| 336 | caslat_ctrl = 2 * cas_latency - 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 337 | #endif |
| 338 | |
| 339 | refrec_ctrl = picos_to_mclk(common_dimm->tRFC_ps) - 8; |
| 340 | wrrec_mclk = picos_to_mclk(common_dimm->tWR_ps); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 341 | if (popts->OTF_burst_chop_en) |
| 342 | wrrec_mclk += 2; |
| 343 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 344 | acttoact_mclk = picos_to_mclk(common_dimm->tRRD_ps); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 345 | /* |
| 346 | * JEDEC has min requirement for tRRD |
| 347 | */ |
| 348 | #if defined(CONFIG_FSL_DDR3) |
| 349 | if (acttoact_mclk < 4) |
| 350 | acttoact_mclk = 4; |
| 351 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 352 | wrtord_mclk = picos_to_mclk(common_dimm->tWTR_ps); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 353 | /* |
| 354 | * JEDEC has some min requirements for tWTR |
| 355 | */ |
| 356 | #if defined(CONFIG_FSL_DDR2) |
| 357 | if (wrtord_mclk < 2) |
| 358 | wrtord_mclk = 2; |
| 359 | #elif defined(CONFIG_FSL_DDR3) |
| 360 | if (wrtord_mclk < 4) |
| 361 | wrtord_mclk = 4; |
| 362 | #endif |
| 363 | if (popts->OTF_burst_chop_en) |
| 364 | wrtord_mclk += 2; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 365 | |
| 366 | ddr->timing_cfg_1 = (0 |
Dave Liu | 5c1bb51 | 2008-11-21 16:31:22 +0800 | [diff] [blame] | 367 | | ((pretoact_mclk & 0x0F) << 28) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 368 | | ((acttopre_mclk & 0x0F) << 24) |
Dave Liu | 5c1bb51 | 2008-11-21 16:31:22 +0800 | [diff] [blame] | 369 | | ((acttorw_mclk & 0xF) << 20) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 370 | | ((caslat_ctrl & 0xF) << 16) |
| 371 | | ((refrec_ctrl & 0xF) << 12) |
Dave Liu | 5c1bb51 | 2008-11-21 16:31:22 +0800 | [diff] [blame] | 372 | | ((wrrec_mclk & 0x0F) << 8) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 373 | | ((acttoact_mclk & 0x07) << 4) |
| 374 | | ((wrtord_mclk & 0x07) << 0) |
| 375 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 376 | debug("FSLDDR: timing_cfg_1 = 0x%08x\n", ddr->timing_cfg_1); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* DDR SDRAM Timing Configuration 2 (TIMING_CFG_2) */ |
| 380 | static void set_timing_cfg_2(fsl_ddr_cfg_regs_t *ddr, |
| 381 | const memctl_options_t *popts, |
| 382 | const common_timing_params_t *common_dimm, |
| 383 | unsigned int cas_latency, |
| 384 | unsigned int additive_latency) |
| 385 | { |
| 386 | /* Additive latency */ |
| 387 | unsigned char add_lat_mclk; |
| 388 | /* CAS-to-preamble override */ |
| 389 | unsigned short cpo; |
| 390 | /* Write latency */ |
| 391 | unsigned char wr_lat; |
| 392 | /* Read to precharge (tRTP) */ |
| 393 | unsigned char rd_to_pre; |
| 394 | /* Write command to write data strobe timing adjustment */ |
| 395 | unsigned char wr_data_delay; |
| 396 | /* Minimum CKE pulse width (tCKE) */ |
| 397 | unsigned char cke_pls; |
| 398 | /* Window for four activates (tFAW) */ |
| 399 | unsigned short four_act; |
| 400 | |
| 401 | /* FIXME add check that this must be less than acttorw_mclk */ |
| 402 | add_lat_mclk = additive_latency; |
| 403 | cpo = popts->cpo_override; |
| 404 | |
| 405 | #if defined(CONFIG_FSL_DDR1) |
| 406 | /* |
| 407 | * This is a lie. It should really be 1, but if it is |
| 408 | * set to 1, bits overlap into the old controller's |
| 409 | * otherwise unused ACSM field. If we leave it 0, then |
| 410 | * the HW will magically treat it as 1 for DDR 1. Oh Yea. |
| 411 | */ |
| 412 | wr_lat = 0; |
| 413 | #elif defined(CONFIG_FSL_DDR2) |
Dave Liu | 82aa953 | 2009-03-14 12:48:19 +0800 | [diff] [blame] | 414 | wr_lat = cas_latency - 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 415 | #else |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 416 | wr_lat = compute_cas_write_latency(); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 417 | #endif |
| 418 | |
| 419 | rd_to_pre = picos_to_mclk(common_dimm->tRTP_ps); |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 420 | /* |
| 421 | * JEDEC has some min requirements for tRTP |
| 422 | */ |
Dave Liu | 82aa953 | 2009-03-14 12:48:19 +0800 | [diff] [blame] | 423 | #if defined(CONFIG_FSL_DDR2) |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 424 | if (rd_to_pre < 2) |
| 425 | rd_to_pre = 2; |
| 426 | #elif defined(CONFIG_FSL_DDR3) |
| 427 | if (rd_to_pre < 4) |
| 428 | rd_to_pre = 4; |
Dave Liu | 82aa953 | 2009-03-14 12:48:19 +0800 | [diff] [blame] | 429 | #endif |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 430 | if (additive_latency) |
| 431 | rd_to_pre += additive_latency; |
| 432 | if (popts->OTF_burst_chop_en) |
| 433 | rd_to_pre += 2; /* according to UM */ |
| 434 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 435 | wr_data_delay = popts->write_data_delay; |
| 436 | cke_pls = picos_to_mclk(popts->tCKE_clock_pulse_width_ps); |
| 437 | four_act = picos_to_mclk(popts->tFAW_window_four_activates_ps); |
| 438 | |
| 439 | ddr->timing_cfg_2 = (0 |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 440 | | ((add_lat_mclk & 0xf) << 28) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 441 | | ((cpo & 0x1f) << 23) |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 442 | | ((wr_lat & 0xf) << 19) |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 443 | | ((rd_to_pre & RD_TO_PRE_MASK) << RD_TO_PRE_SHIFT) |
| 444 | | ((wr_data_delay & WR_DATA_DELAY_MASK) << WR_DATA_DELAY_SHIFT) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 445 | | ((cke_pls & 0x7) << 6) |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 446 | | ((four_act & 0x3f) << 0) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 447 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 448 | debug("FSLDDR: timing_cfg_2 = 0x%08x\n", ddr->timing_cfg_2); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 449 | } |
| 450 | |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 451 | /* DDR SDRAM Register Control Word */ |
| 452 | static void set_ddr_sdram_rcw(fsl_ddr_cfg_regs_t *ddr, |
| 453 | const common_timing_params_t *common_dimm) |
| 454 | { |
| 455 | if (common_dimm->all_DIMMs_registered |
| 456 | && !common_dimm->all_DIMMs_unbuffered) { |
| 457 | ddr->ddr_sdram_rcw_1 = |
| 458 | common_dimm->rcw[0] << 28 | \ |
| 459 | common_dimm->rcw[1] << 24 | \ |
| 460 | common_dimm->rcw[2] << 20 | \ |
| 461 | common_dimm->rcw[3] << 16 | \ |
| 462 | common_dimm->rcw[4] << 12 | \ |
| 463 | common_dimm->rcw[5] << 8 | \ |
| 464 | common_dimm->rcw[6] << 4 | \ |
| 465 | common_dimm->rcw[7]; |
| 466 | ddr->ddr_sdram_rcw_2 = |
| 467 | common_dimm->rcw[8] << 28 | \ |
| 468 | common_dimm->rcw[9] << 24 | \ |
| 469 | common_dimm->rcw[10] << 20 | \ |
| 470 | common_dimm->rcw[11] << 16 | \ |
| 471 | common_dimm->rcw[12] << 12 | \ |
| 472 | common_dimm->rcw[13] << 8 | \ |
| 473 | common_dimm->rcw[14] << 4 | \ |
| 474 | common_dimm->rcw[15]; |
| 475 | debug("FSLDDR: ddr_sdram_rcw_1 = 0x%08x\n", ddr->ddr_sdram_rcw_1); |
| 476 | debug("FSLDDR: ddr_sdram_rcw_2 = 0x%08x\n", ddr->ddr_sdram_rcw_2); |
| 477 | } |
| 478 | } |
| 479 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 480 | /* DDR SDRAM control configuration (DDR_SDRAM_CFG) */ |
| 481 | static void set_ddr_sdram_cfg(fsl_ddr_cfg_regs_t *ddr, |
| 482 | const memctl_options_t *popts, |
| 483 | const common_timing_params_t *common_dimm) |
| 484 | { |
| 485 | unsigned int mem_en; /* DDR SDRAM interface logic enable */ |
| 486 | unsigned int sren; /* Self refresh enable (during sleep) */ |
| 487 | unsigned int ecc_en; /* ECC enable. */ |
| 488 | unsigned int rd_en; /* Registered DIMM enable */ |
| 489 | unsigned int sdram_type; /* Type of SDRAM */ |
| 490 | unsigned int dyn_pwr; /* Dynamic power management mode */ |
| 491 | unsigned int dbw; /* DRAM dta bus width */ |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 492 | unsigned int eight_be = 0; /* 8-beat burst enable, DDR2 is zero */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 493 | unsigned int ncap = 0; /* Non-concurrent auto-precharge */ |
| 494 | unsigned int threeT_en; /* Enable 3T timing */ |
| 495 | unsigned int twoT_en; /* Enable 2T timing */ |
| 496 | unsigned int ba_intlv_ctl; /* Bank (CS) interleaving control */ |
| 497 | unsigned int x32_en = 0; /* x32 enable */ |
| 498 | unsigned int pchb8 = 0; /* precharge bit 8 enable */ |
| 499 | unsigned int hse; /* Global half strength override */ |
| 500 | unsigned int mem_halt = 0; /* memory controller halt */ |
| 501 | unsigned int bi = 0; /* Bypass initialization */ |
| 502 | |
| 503 | mem_en = 1; |
| 504 | sren = popts->self_refresh_in_sleep; |
| 505 | if (common_dimm->all_DIMMs_ECC_capable) { |
| 506 | /* Allow setting of ECC only if all DIMMs are ECC. */ |
| 507 | ecc_en = popts->ECC_mode; |
| 508 | } else { |
| 509 | ecc_en = 0; |
| 510 | } |
| 511 | |
| 512 | rd_en = (common_dimm->all_DIMMs_registered |
| 513 | && !common_dimm->all_DIMMs_unbuffered); |
| 514 | |
| 515 | sdram_type = CONFIG_FSL_SDRAM_TYPE; |
| 516 | |
| 517 | dyn_pwr = popts->dynamic_power; |
| 518 | dbw = popts->data_bus_width; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 519 | /* 8-beat burst enable DDR-III case |
| 520 | * we must clear it when use the on-the-fly mode, |
| 521 | * must set it when use the 32-bits bus mode. |
| 522 | */ |
| 523 | if (sdram_type == SDRAM_TYPE_DDR3) { |
| 524 | if (popts->burst_length == DDR_BL8) |
| 525 | eight_be = 1; |
| 526 | if (popts->burst_length == DDR_OTF) |
| 527 | eight_be = 0; |
| 528 | if (dbw == 0x1) |
| 529 | eight_be = 1; |
| 530 | } |
| 531 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 532 | threeT_en = popts->threeT_en; |
| 533 | twoT_en = popts->twoT_en; |
| 534 | ba_intlv_ctl = popts->ba_intlv_ctl; |
| 535 | hse = popts->half_strength_driver_enable; |
| 536 | |
| 537 | ddr->ddr_sdram_cfg = (0 |
| 538 | | ((mem_en & 0x1) << 31) |
| 539 | | ((sren & 0x1) << 30) |
| 540 | | ((ecc_en & 0x1) << 29) |
| 541 | | ((rd_en & 0x1) << 28) |
| 542 | | ((sdram_type & 0x7) << 24) |
| 543 | | ((dyn_pwr & 0x1) << 21) |
| 544 | | ((dbw & 0x3) << 19) |
| 545 | | ((eight_be & 0x1) << 18) |
| 546 | | ((ncap & 0x1) << 17) |
| 547 | | ((threeT_en & 0x1) << 16) |
| 548 | | ((twoT_en & 0x1) << 15) |
| 549 | | ((ba_intlv_ctl & 0x7F) << 8) |
| 550 | | ((x32_en & 0x1) << 5) |
| 551 | | ((pchb8 & 0x1) << 4) |
| 552 | | ((hse & 0x1) << 3) |
| 553 | | ((mem_halt & 0x1) << 1) |
| 554 | | ((bi & 0x1) << 0) |
| 555 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 556 | debug("FSLDDR: ddr_sdram_cfg = 0x%08x\n", ddr->ddr_sdram_cfg); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* DDR SDRAM control configuration 2 (DDR_SDRAM_CFG_2) */ |
| 560 | static void set_ddr_sdram_cfg_2(fsl_ddr_cfg_regs_t *ddr, |
| 561 | const memctl_options_t *popts) |
| 562 | { |
| 563 | unsigned int frc_sr = 0; /* Force self refresh */ |
| 564 | unsigned int sr_ie = 0; /* Self-refresh interrupt enable */ |
| 565 | unsigned int dll_rst_dis; /* DLL reset disable */ |
| 566 | unsigned int dqs_cfg; /* DQS configuration */ |
| 567 | unsigned int odt_cfg; /* ODT configuration */ |
| 568 | unsigned int num_pr; /* Number of posted refreshes */ |
| 569 | unsigned int obc_cfg; /* On-The-Fly Burst Chop Cfg */ |
| 570 | unsigned int ap_en; /* Address Parity Enable */ |
| 571 | unsigned int d_init; /* DRAM data initialization */ |
| 572 | unsigned int rcw_en = 0; /* Register Control Word Enable */ |
| 573 | unsigned int md_en = 0; /* Mirrored DIMM Enable */ |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 574 | unsigned int qd_en = 0; /* quad-rank DIMM Enable */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 575 | |
| 576 | dll_rst_dis = 1; /* Make this configurable */ |
| 577 | dqs_cfg = popts->DQS_config; |
| 578 | if (popts->cs_local_opts[0].odt_rd_cfg |
| 579 | || popts->cs_local_opts[0].odt_wr_cfg) { |
| 580 | /* FIXME */ |
| 581 | odt_cfg = 2; |
| 582 | } else { |
| 583 | odt_cfg = 0; |
| 584 | } |
| 585 | |
| 586 | num_pr = 1; /* Make this configurable */ |
| 587 | |
| 588 | /* |
| 589 | * 8572 manual says |
| 590 | * {TIMING_CFG_1[PRETOACT] |
| 591 | * + [DDR_SDRAM_CFG_2[NUM_PR] |
| 592 | * * ({EXT_REFREC || REFREC} + 8 + 2)]} |
| 593 | * << DDR_SDRAM_INTERVAL[REFINT] |
| 594 | */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 595 | #if defined(CONFIG_FSL_DDR3) |
| 596 | obc_cfg = popts->OTF_burst_chop_en; |
| 597 | #else |
| 598 | obc_cfg = 0; |
| 599 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 600 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 601 | ap_en = 0; /* Make this configurable? */ |
| 602 | |
| 603 | #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 604 | /* Use the DDR controller to auto initialize memory. */ |
| 605 | d_init = 1; |
| 606 | ddr->ddr_data_init = CONFIG_MEM_INIT_VALUE; |
| 607 | debug("DDR: ddr_data_init = 0x%08x\n", ddr->ddr_data_init); |
| 608 | #else |
| 609 | /* Memory will be initialized via DMA, or not at all. */ |
| 610 | d_init = 0; |
| 611 | #endif |
| 612 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 613 | #if defined(CONFIG_FSL_DDR3) |
| 614 | md_en = popts->mirrored_dimm; |
| 615 | #endif |
York Sun | 5207e77 | 2010-08-27 16:25:56 -0500 | [diff] [blame] | 616 | rcw_en = popts->registered_dimm_en; |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 617 | qd_en = popts->quad_rank_present ? 1 : 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 618 | ddr->ddr_sdram_cfg_2 = (0 |
| 619 | | ((frc_sr & 0x1) << 31) |
| 620 | | ((sr_ie & 0x1) << 30) |
| 621 | | ((dll_rst_dis & 0x1) << 29) |
| 622 | | ((dqs_cfg & 0x3) << 26) |
| 623 | | ((odt_cfg & 0x3) << 21) |
| 624 | | ((num_pr & 0xf) << 12) |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 625 | | (qd_en << 9) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 626 | | ((obc_cfg & 0x1) << 6) |
| 627 | | ((ap_en & 0x1) << 5) |
| 628 | | ((d_init & 0x1) << 4) |
| 629 | | ((rcw_en & 0x1) << 2) |
| 630 | | ((md_en & 0x1) << 0) |
| 631 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 632 | debug("FSLDDR: ddr_sdram_cfg_2 = 0x%08x\n", ddr->ddr_sdram_cfg_2); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */ |
Dave Liu | 2d0f125 | 2009-12-16 10:24:38 -0600 | [diff] [blame] | 636 | static void set_ddr_sdram_mode_2(fsl_ddr_cfg_regs_t *ddr, |
| 637 | const memctl_options_t *popts) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 638 | { |
| 639 | unsigned short esdmode2 = 0; /* Extended SDRAM mode 2 */ |
| 640 | unsigned short esdmode3 = 0; /* Extended SDRAM mode 3 */ |
| 641 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 642 | #if defined(CONFIG_FSL_DDR3) |
Dave Liu | 2d0f125 | 2009-12-16 10:24:38 -0600 | [diff] [blame] | 643 | unsigned int rtt_wr = 0; /* Rtt_WR - dynamic ODT off */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 644 | unsigned int srt = 0; /* self-refresh temerature, normal range */ |
| 645 | unsigned int asr = 0; /* auto self-refresh disable */ |
| 646 | unsigned int cwl = compute_cas_write_latency() - 5; |
| 647 | unsigned int pasr = 0; /* partial array self refresh disable */ |
| 648 | |
Dave Liu | 2d0f125 | 2009-12-16 10:24:38 -0600 | [diff] [blame] | 649 | if (popts->rtt_override) |
| 650 | rtt_wr = popts->rtt_wr_override_value; |
| 651 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 652 | esdmode2 = (0 |
| 653 | | ((rtt_wr & 0x3) << 9) |
| 654 | | ((srt & 0x1) << 7) |
| 655 | | ((asr & 0x1) << 6) |
| 656 | | ((cwl & 0x7) << 3) |
| 657 | | ((pasr & 0x7) << 0)); |
| 658 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 659 | ddr->ddr_sdram_mode_2 = (0 |
| 660 | | ((esdmode2 & 0xFFFF) << 16) |
| 661 | | ((esdmode3 & 0xFFFF) << 0) |
| 662 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 663 | debug("FSLDDR: ddr_sdram_mode_2 = 0x%08x\n", ddr->ddr_sdram_mode_2); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /* DDR SDRAM Interval Configuration (DDR_SDRAM_INTERVAL) */ |
| 667 | static void set_ddr_sdram_interval(fsl_ddr_cfg_regs_t *ddr, |
| 668 | const memctl_options_t *popts, |
| 669 | const common_timing_params_t *common_dimm) |
| 670 | { |
| 671 | unsigned int refint; /* Refresh interval */ |
| 672 | unsigned int bstopre; /* Precharge interval */ |
| 673 | |
| 674 | refint = picos_to_mclk(common_dimm->refresh_rate_ps); |
| 675 | |
| 676 | bstopre = popts->bstopre; |
| 677 | |
| 678 | /* refint field used 0x3FFF in earlier controllers */ |
| 679 | ddr->ddr_sdram_interval = (0 |
| 680 | | ((refint & 0xFFFF) << 16) |
| 681 | | ((bstopre & 0x3FFF) << 0) |
| 682 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 683 | debug("FSLDDR: ddr_sdram_interval = 0x%08x\n", ddr->ddr_sdram_interval); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 684 | } |
| 685 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 686 | #if defined(CONFIG_FSL_DDR3) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 687 | /* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */ |
| 688 | static void set_ddr_sdram_mode(fsl_ddr_cfg_regs_t *ddr, |
| 689 | const memctl_options_t *popts, |
| 690 | const common_timing_params_t *common_dimm, |
| 691 | unsigned int cas_latency, |
| 692 | unsigned int additive_latency) |
| 693 | { |
| 694 | unsigned short esdmode; /* Extended SDRAM mode */ |
| 695 | unsigned short sdmode; /* SDRAM mode */ |
| 696 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 697 | /* Mode Register - MR1 */ |
| 698 | unsigned int qoff = 0; /* Output buffer enable 0=yes, 1=no */ |
| 699 | unsigned int tdqs_en = 0; /* TDQS Enable: 0=no, 1=yes */ |
| 700 | unsigned int rtt; |
| 701 | unsigned int wrlvl_en = 0; /* Write level enable: 0=no, 1=yes */ |
| 702 | unsigned int al = 0; /* Posted CAS# additive latency (AL) */ |
| 703 | unsigned int dic = 1; /* Output driver impedance, 34ohm */ |
| 704 | unsigned int dll_en = 0; /* DLL Enable 0=Enable (Normal), |
| 705 | 1=Disable (Test/Debug) */ |
| 706 | |
| 707 | /* Mode Register - MR0 */ |
| 708 | unsigned int dll_on; /* DLL control for precharge PD, 0=off, 1=on */ |
| 709 | unsigned int wr; /* Write Recovery */ |
| 710 | unsigned int dll_rst; /* DLL Reset */ |
| 711 | unsigned int mode; /* Normal=0 or Test=1 */ |
| 712 | unsigned int caslat = 4;/* CAS# latency, default set as 6 cycles */ |
| 713 | /* BT: Burst Type (0=Nibble Sequential, 1=Interleaved) */ |
| 714 | unsigned int bt; |
| 715 | unsigned int bl; /* BL: Burst Length */ |
| 716 | |
| 717 | unsigned int wr_mclk; |
| 718 | |
| 719 | const unsigned int mclk_ps = get_memory_clk_period_ps(); |
| 720 | |
| 721 | rtt = fsl_ddr_get_rtt(); |
| 722 | if (popts->rtt_override) |
| 723 | rtt = popts->rtt_override_value; |
| 724 | |
| 725 | if (additive_latency == (cas_latency - 1)) |
| 726 | al = 1; |
| 727 | if (additive_latency == (cas_latency - 2)) |
| 728 | al = 2; |
| 729 | |
| 730 | /* |
| 731 | * The esdmode value will also be used for writing |
| 732 | * MR1 during write leveling for DDR3, although the |
| 733 | * bits specifically related to the write leveling |
| 734 | * scheme will be handled automatically by the DDR |
| 735 | * controller. so we set the wrlvl_en = 0 here. |
| 736 | */ |
| 737 | esdmode = (0 |
| 738 | | ((qoff & 0x1) << 12) |
| 739 | | ((tdqs_en & 0x1) << 11) |
Kumar Gala | 14f2eb1 | 2009-09-10 14:54:55 -0500 | [diff] [blame] | 740 | | ((rtt & 0x4) << 7) /* rtt field is split */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 741 | | ((wrlvl_en & 0x1) << 7) |
Kumar Gala | 14f2eb1 | 2009-09-10 14:54:55 -0500 | [diff] [blame] | 742 | | ((rtt & 0x2) << 5) /* rtt field is split */ |
| 743 | | ((dic & 0x2) << 4) /* DIC field is split */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 744 | | ((al & 0x3) << 3) |
Kumar Gala | 14f2eb1 | 2009-09-10 14:54:55 -0500 | [diff] [blame] | 745 | | ((rtt & 0x1) << 2) /* rtt field is split */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 746 | | ((dic & 0x1) << 1) /* DIC field is split */ |
| 747 | | ((dll_en & 0x1) << 0) |
| 748 | ); |
| 749 | |
| 750 | /* |
| 751 | * DLL control for precharge PD |
| 752 | * 0=slow exit DLL off (tXPDLL) |
| 753 | * 1=fast exit DLL on (tXP) |
| 754 | */ |
| 755 | dll_on = 1; |
| 756 | wr_mclk = (common_dimm->tWR_ps + mclk_ps - 1) / mclk_ps; |
| 757 | if (wr_mclk >= 12) |
| 758 | wr = 6; |
| 759 | else if (wr_mclk >= 9) |
| 760 | wr = 5; |
| 761 | else |
| 762 | wr = wr_mclk - 4; |
| 763 | dll_rst = 0; /* dll no reset */ |
| 764 | mode = 0; /* normal mode */ |
| 765 | |
| 766 | /* look up table to get the cas latency bits */ |
| 767 | if (cas_latency >= 5 && cas_latency <= 11) { |
| 768 | unsigned char cas_latency_table[7] = { |
| 769 | 0x2, /* 5 clocks */ |
| 770 | 0x4, /* 6 clocks */ |
| 771 | 0x6, /* 7 clocks */ |
| 772 | 0x8, /* 8 clocks */ |
| 773 | 0xa, /* 9 clocks */ |
| 774 | 0xc, /* 10 clocks */ |
| 775 | 0xe /* 11 clocks */ |
| 776 | }; |
| 777 | caslat = cas_latency_table[cas_latency - 5]; |
| 778 | } |
| 779 | bt = 0; /* Nibble sequential */ |
| 780 | |
| 781 | switch (popts->burst_length) { |
| 782 | case DDR_BL8: |
| 783 | bl = 0; |
| 784 | break; |
| 785 | case DDR_OTF: |
| 786 | bl = 1; |
| 787 | break; |
| 788 | case DDR_BC4: |
| 789 | bl = 2; |
| 790 | break; |
| 791 | default: |
| 792 | printf("Error: invalid burst length of %u specified. " |
| 793 | " Defaulting to on-the-fly BC4 or BL8 beats.\n", |
| 794 | popts->burst_length); |
| 795 | bl = 1; |
| 796 | break; |
| 797 | } |
| 798 | |
| 799 | sdmode = (0 |
| 800 | | ((dll_on & 0x1) << 12) |
| 801 | | ((wr & 0x7) << 9) |
| 802 | | ((dll_rst & 0x1) << 8) |
| 803 | | ((mode & 0x1) << 7) |
| 804 | | (((caslat >> 1) & 0x7) << 4) |
| 805 | | ((bt & 0x1) << 3) |
| 806 | | ((bl & 0x3) << 0) |
| 807 | ); |
| 808 | |
| 809 | ddr->ddr_sdram_mode = (0 |
| 810 | | ((esdmode & 0xFFFF) << 16) |
| 811 | | ((sdmode & 0xFFFF) << 0) |
| 812 | ); |
| 813 | |
| 814 | debug("FSLDDR: ddr_sdram_mode = 0x%08x\n", ddr->ddr_sdram_mode); |
| 815 | } |
| 816 | |
| 817 | #else /* !CONFIG_FSL_DDR3 */ |
| 818 | |
| 819 | /* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */ |
| 820 | static void set_ddr_sdram_mode(fsl_ddr_cfg_regs_t *ddr, |
| 821 | const memctl_options_t *popts, |
| 822 | const common_timing_params_t *common_dimm, |
| 823 | unsigned int cas_latency, |
| 824 | unsigned int additive_latency) |
| 825 | { |
| 826 | unsigned short esdmode; /* Extended SDRAM mode */ |
| 827 | unsigned short sdmode; /* SDRAM mode */ |
| 828 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 829 | /* |
| 830 | * FIXME: This ought to be pre-calculated in a |
| 831 | * technology-specific routine, |
| 832 | * e.g. compute_DDR2_mode_register(), and then the |
| 833 | * sdmode and esdmode passed in as part of common_dimm. |
| 834 | */ |
| 835 | |
| 836 | /* Extended Mode Register */ |
| 837 | unsigned int mrs = 0; /* Mode Register Set */ |
| 838 | unsigned int outputs = 0; /* 0=Enabled, 1=Disabled */ |
| 839 | unsigned int rdqs_en = 0; /* RDQS Enable: 0=no, 1=yes */ |
| 840 | unsigned int dqs_en = 0; /* DQS# Enable: 0=enable, 1=disable */ |
| 841 | unsigned int ocd = 0; /* 0x0=OCD not supported, |
| 842 | 0x7=OCD default state */ |
| 843 | unsigned int rtt; |
| 844 | unsigned int al; /* Posted CAS# additive latency (AL) */ |
| 845 | unsigned int ods = 0; /* Output Drive Strength: |
| 846 | 0 = Full strength (18ohm) |
| 847 | 1 = Reduced strength (4ohm) */ |
| 848 | unsigned int dll_en = 0; /* DLL Enable 0=Enable (Normal), |
| 849 | 1=Disable (Test/Debug) */ |
| 850 | |
| 851 | /* Mode Register (MR) */ |
| 852 | unsigned int mr; /* Mode Register Definition */ |
| 853 | unsigned int pd; /* Power-Down Mode */ |
| 854 | unsigned int wr; /* Write Recovery */ |
| 855 | unsigned int dll_res; /* DLL Reset */ |
| 856 | unsigned int mode; /* Normal=0 or Test=1 */ |
Kumar Gala | 35ad58d | 2008-09-05 14:40:29 -0500 | [diff] [blame] | 857 | unsigned int caslat = 0;/* CAS# latency */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 858 | /* BT: Burst Type (0=Sequential, 1=Interleaved) */ |
| 859 | unsigned int bt; |
| 860 | unsigned int bl; /* BL: Burst Length */ |
| 861 | |
| 862 | #if defined(CONFIG_FSL_DDR2) |
| 863 | const unsigned int mclk_ps = get_memory_clk_period_ps(); |
| 864 | #endif |
| 865 | |
| 866 | rtt = fsl_ddr_get_rtt(); |
| 867 | |
| 868 | al = additive_latency; |
| 869 | |
| 870 | esdmode = (0 |
| 871 | | ((mrs & 0x3) << 14) |
| 872 | | ((outputs & 0x1) << 12) |
| 873 | | ((rdqs_en & 0x1) << 11) |
| 874 | | ((dqs_en & 0x1) << 10) |
| 875 | | ((ocd & 0x7) << 7) |
| 876 | | ((rtt & 0x2) << 5) /* rtt field is split */ |
| 877 | | ((al & 0x7) << 3) |
| 878 | | ((rtt & 0x1) << 2) /* rtt field is split */ |
| 879 | | ((ods & 0x1) << 1) |
| 880 | | ((dll_en & 0x1) << 0) |
| 881 | ); |
| 882 | |
| 883 | mr = 0; /* FIXME: CHECKME */ |
| 884 | |
| 885 | /* |
| 886 | * 0 = Fast Exit (Normal) |
| 887 | * 1 = Slow Exit (Low Power) |
| 888 | */ |
| 889 | pd = 0; |
| 890 | |
| 891 | #if defined(CONFIG_FSL_DDR1) |
| 892 | wr = 0; /* Historical */ |
| 893 | #elif defined(CONFIG_FSL_DDR2) |
| 894 | wr = (common_dimm->tWR_ps + mclk_ps - 1) / mclk_ps - 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 895 | #endif |
| 896 | dll_res = 0; |
| 897 | mode = 0; |
| 898 | |
| 899 | #if defined(CONFIG_FSL_DDR1) |
| 900 | if (1 <= cas_latency && cas_latency <= 4) { |
| 901 | unsigned char mode_caslat_table[4] = { |
| 902 | 0x5, /* 1.5 clocks */ |
| 903 | 0x2, /* 2.0 clocks */ |
| 904 | 0x6, /* 2.5 clocks */ |
| 905 | 0x3 /* 3.0 clocks */ |
| 906 | }; |
Kumar Gala | 35ad58d | 2008-09-05 14:40:29 -0500 | [diff] [blame] | 907 | caslat = mode_caslat_table[cas_latency - 1]; |
| 908 | } else { |
| 909 | printf("Warning: unknown cas_latency %d\n", cas_latency); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 910 | } |
| 911 | #elif defined(CONFIG_FSL_DDR2) |
| 912 | caslat = cas_latency; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 913 | #endif |
| 914 | bt = 0; |
| 915 | |
| 916 | switch (popts->burst_length) { |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 917 | case DDR_BL4: |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 918 | bl = 2; |
| 919 | break; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 920 | case DDR_BL8: |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 921 | bl = 3; |
| 922 | break; |
| 923 | default: |
| 924 | printf("Error: invalid burst length of %u specified. " |
| 925 | " Defaulting to 4 beats.\n", |
| 926 | popts->burst_length); |
| 927 | bl = 2; |
| 928 | break; |
| 929 | } |
| 930 | |
| 931 | sdmode = (0 |
| 932 | | ((mr & 0x3) << 14) |
| 933 | | ((pd & 0x1) << 12) |
| 934 | | ((wr & 0x7) << 9) |
| 935 | | ((dll_res & 0x1) << 8) |
| 936 | | ((mode & 0x1) << 7) |
| 937 | | ((caslat & 0x7) << 4) |
| 938 | | ((bt & 0x1) << 3) |
| 939 | | ((bl & 0x7) << 0) |
| 940 | ); |
| 941 | |
| 942 | ddr->ddr_sdram_mode = (0 |
| 943 | | ((esdmode & 0xFFFF) << 16) |
| 944 | | ((sdmode & 0xFFFF) << 0) |
| 945 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 946 | debug("FSLDDR: ddr_sdram_mode = 0x%08x\n", ddr->ddr_sdram_mode); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 947 | } |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 948 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 949 | |
| 950 | /* DDR SDRAM Data Initialization (DDR_DATA_INIT) */ |
| 951 | static void set_ddr_data_init(fsl_ddr_cfg_regs_t *ddr) |
| 952 | { |
| 953 | unsigned int init_value; /* Initialization value */ |
| 954 | |
| 955 | init_value = 0xDEADBEEF; |
| 956 | ddr->ddr_data_init = init_value; |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | * DDR SDRAM Clock Control (DDR_SDRAM_CLK_CNTL) |
| 961 | * The old controller on the 8540/60 doesn't have this register. |
| 962 | * Hope it's OK to set it (to 0) anyway. |
| 963 | */ |
| 964 | static void set_ddr_sdram_clk_cntl(fsl_ddr_cfg_regs_t *ddr, |
| 965 | const memctl_options_t *popts) |
| 966 | { |
| 967 | unsigned int clk_adjust; /* Clock adjust */ |
| 968 | |
| 969 | clk_adjust = popts->clk_adjust; |
| 970 | ddr->ddr_sdram_clk_cntl = (clk_adjust & 0xF) << 23; |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 971 | debug("FSLDDR: clk_cntl = 0x%08x\n", ddr->ddr_sdram_clk_cntl); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /* DDR Initialization Address (DDR_INIT_ADDR) */ |
| 975 | static void set_ddr_init_addr(fsl_ddr_cfg_regs_t *ddr) |
| 976 | { |
| 977 | unsigned int init_addr = 0; /* Initialization address */ |
| 978 | |
| 979 | ddr->ddr_init_addr = init_addr; |
| 980 | } |
| 981 | |
| 982 | /* DDR Initialization Address (DDR_INIT_EXT_ADDR) */ |
| 983 | static void set_ddr_init_ext_addr(fsl_ddr_cfg_regs_t *ddr) |
| 984 | { |
| 985 | unsigned int uia = 0; /* Use initialization address */ |
| 986 | unsigned int init_ext_addr = 0; /* Initialization address */ |
| 987 | |
| 988 | ddr->ddr_init_ext_addr = (0 |
| 989 | | ((uia & 0x1) << 31) |
| 990 | | (init_ext_addr & 0xF) |
| 991 | ); |
| 992 | } |
| 993 | |
| 994 | /* DDR SDRAM Timing Configuration 4 (TIMING_CFG_4) */ |
Dave Liu | 3525e1a | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 995 | static void set_timing_cfg_4(fsl_ddr_cfg_regs_t *ddr, |
| 996 | const memctl_options_t *popts) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 997 | { |
| 998 | unsigned int rwt = 0; /* Read-to-write turnaround for same CS */ |
| 999 | unsigned int wrt = 0; /* Write-to-read turnaround for same CS */ |
| 1000 | unsigned int rrt = 0; /* Read-to-read turnaround for same CS */ |
| 1001 | unsigned int wwt = 0; /* Write-to-write turnaround for same CS */ |
| 1002 | unsigned int dll_lock = 0; /* DDR SDRAM DLL Lock Time */ |
| 1003 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1004 | #if defined(CONFIG_FSL_DDR3) |
Dave Liu | 3525e1a | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 1005 | if (popts->burst_length == DDR_BL8) { |
| 1006 | /* We set BL/2 for fixed BL8 */ |
| 1007 | rrt = 0; /* BL/2 clocks */ |
| 1008 | wwt = 0; /* BL/2 clocks */ |
| 1009 | } else { |
| 1010 | /* We need to set BL/2 + 2 to BC4 and OTF */ |
| 1011 | rrt = 2; /* BL/2 + 2 clocks */ |
| 1012 | wwt = 2; /* BL/2 + 2 clocks */ |
| 1013 | } |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1014 | dll_lock = 1; /* tDLLK = 512 clocks from spec */ |
| 1015 | #endif |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1016 | ddr->timing_cfg_4 = (0 |
| 1017 | | ((rwt & 0xf) << 28) |
| 1018 | | ((wrt & 0xf) << 24) |
| 1019 | | ((rrt & 0xf) << 20) |
| 1020 | | ((wwt & 0xf) << 16) |
| 1021 | | (dll_lock & 0x3) |
| 1022 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 1023 | debug("FSLDDR: timing_cfg_4 = 0x%08x\n", ddr->timing_cfg_4); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /* DDR SDRAM Timing Configuration 5 (TIMING_CFG_5) */ |
| 1027 | static void set_timing_cfg_5(fsl_ddr_cfg_regs_t *ddr) |
| 1028 | { |
| 1029 | unsigned int rodt_on = 0; /* Read to ODT on */ |
| 1030 | unsigned int rodt_off = 0; /* Read to ODT off */ |
| 1031 | unsigned int wodt_on = 0; /* Write to ODT on */ |
| 1032 | unsigned int wodt_off = 0; /* Write to ODT off */ |
| 1033 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1034 | #if defined(CONFIG_FSL_DDR3) |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 1035 | rodt_on = 2; /* 2 clocks */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1036 | rodt_off = 4; /* 4 clocks */ |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 1037 | wodt_on = 1; /* 1 clocks */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1038 | wodt_off = 4; /* 4 clocks */ |
| 1039 | #endif |
| 1040 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1041 | ddr->timing_cfg_5 = (0 |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 1042 | | ((rodt_on & 0x1f) << 24) |
| 1043 | | ((rodt_off & 0x7) << 20) |
| 1044 | | ((wodt_on & 0x1f) << 12) |
| 1045 | | ((wodt_off & 0x7) << 8) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1046 | ); |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 1047 | debug("FSLDDR: timing_cfg_5 = 0x%08x\n", ddr->timing_cfg_5); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /* DDR ZQ Calibration Control (DDR_ZQ_CNTL) */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1051 | static void set_ddr_zq_cntl(fsl_ddr_cfg_regs_t *ddr, unsigned int zq_en) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1052 | { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1053 | unsigned int zqinit = 0;/* POR ZQ Calibration Time (tZQinit) */ |
| 1054 | /* Normal Operation Full Calibration Time (tZQoper) */ |
| 1055 | unsigned int zqoper = 0; |
| 1056 | /* Normal Operation Short Calibration Time (tZQCS) */ |
| 1057 | unsigned int zqcs = 0; |
| 1058 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1059 | if (zq_en) { |
| 1060 | zqinit = 9; /* 512 clocks */ |
| 1061 | zqoper = 8; /* 256 clocks */ |
| 1062 | zqcs = 6; /* 64 clocks */ |
| 1063 | } |
| 1064 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1065 | ddr->ddr_zq_cntl = (0 |
| 1066 | | ((zq_en & 0x1) << 31) |
| 1067 | | ((zqinit & 0xF) << 24) |
| 1068 | | ((zqoper & 0xF) << 16) |
| 1069 | | ((zqcs & 0xF) << 8) |
| 1070 | ); |
| 1071 | } |
| 1072 | |
| 1073 | /* DDR Write Leveling Control (DDR_WRLVL_CNTL) */ |
Dave Liu | 64ee7df | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 1074 | static void set_ddr_wrlvl_cntl(fsl_ddr_cfg_regs_t *ddr, unsigned int wrlvl_en, |
| 1075 | const memctl_options_t *popts) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1076 | { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1077 | /* |
| 1078 | * First DQS pulse rising edge after margining mode |
| 1079 | * is programmed (tWL_MRD) |
| 1080 | */ |
| 1081 | unsigned int wrlvl_mrd = 0; |
| 1082 | /* ODT delay after margining mode is programmed (tWL_ODTEN) */ |
| 1083 | unsigned int wrlvl_odten = 0; |
| 1084 | /* DQS/DQS_ delay after margining mode is programmed (tWL_DQSEN) */ |
| 1085 | unsigned int wrlvl_dqsen = 0; |
| 1086 | /* WRLVL_SMPL: Write leveling sample time */ |
| 1087 | unsigned int wrlvl_smpl = 0; |
| 1088 | /* WRLVL_WLR: Write leveling repeition time */ |
| 1089 | unsigned int wrlvl_wlr = 0; |
| 1090 | /* WRLVL_START: Write leveling start time */ |
| 1091 | unsigned int wrlvl_start = 0; |
| 1092 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1093 | /* suggest enable write leveling for DDR3 due to fly-by topology */ |
| 1094 | if (wrlvl_en) { |
| 1095 | /* tWL_MRD min = 40 nCK, we set it 64 */ |
| 1096 | wrlvl_mrd = 0x6; |
| 1097 | /* tWL_ODTEN 128 */ |
| 1098 | wrlvl_odten = 0x7; |
| 1099 | /* tWL_DQSEN min = 25 nCK, we set it 32 */ |
| 1100 | wrlvl_dqsen = 0x5; |
| 1101 | /* |
Dave Liu | 64ee7df | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 1102 | * Write leveling sample time at least need 6 clocks |
| 1103 | * higher than tWLO to allow enough time for progagation |
| 1104 | * delay and sampling the prime data bits. |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1105 | */ |
| 1106 | wrlvl_smpl = 0xf; |
| 1107 | /* |
| 1108 | * Write leveling repetition time |
| 1109 | * at least tWLO + 6 clocks clocks |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 1110 | * we set it 64 |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1111 | */ |
york | 1714e49 | 2010-07-02 22:25:56 +0000 | [diff] [blame] | 1112 | wrlvl_wlr = 0x6; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1113 | /* |
| 1114 | * Write leveling start time |
| 1115 | * The value use for the DQS_ADJUST for the first sample |
| 1116 | * when write leveling is enabled. |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1117 | */ |
| 1118 | wrlvl_start = 0x8; |
Dave Liu | 64ee7df | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 1119 | /* |
| 1120 | * Override the write leveling sample and start time |
| 1121 | * according to specific board |
| 1122 | */ |
| 1123 | if (popts->wrlvl_override) { |
| 1124 | wrlvl_smpl = popts->wrlvl_sample; |
| 1125 | wrlvl_start = popts->wrlvl_start; |
| 1126 | } |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1127 | } |
| 1128 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1129 | ddr->ddr_wrlvl_cntl = (0 |
| 1130 | | ((wrlvl_en & 0x1) << 31) |
| 1131 | | ((wrlvl_mrd & 0x7) << 24) |
| 1132 | | ((wrlvl_odten & 0x7) << 20) |
| 1133 | | ((wrlvl_dqsen & 0x7) << 16) |
| 1134 | | ((wrlvl_smpl & 0xf) << 12) |
| 1135 | | ((wrlvl_wlr & 0x7) << 8) |
Dave Liu | 4758d53 | 2008-11-21 16:31:29 +0800 | [diff] [blame] | 1136 | | ((wrlvl_start & 0x1F) << 0) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1137 | ); |
| 1138 | } |
| 1139 | |
| 1140 | /* DDR Self Refresh Counter (DDR_SR_CNTR) */ |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 1141 | static void set_ddr_sr_cntr(fsl_ddr_cfg_regs_t *ddr, unsigned int sr_it) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1142 | { |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 1143 | /* Self Refresh Idle Threshold */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1144 | ddr->ddr_sr_cntr = (sr_it & 0xF) << 16; |
| 1145 | } |
| 1146 | |
york | 4260372 | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 1147 | static void set_ddr_eor(fsl_ddr_cfg_regs_t *ddr, const memctl_options_t *popts) |
| 1148 | { |
| 1149 | if (popts->addr_hash) { |
| 1150 | ddr->ddr_eor = 0x40000000; /* address hash enable */ |
| 1151 | puts("Addess hashing enabled.\n"); |
| 1152 | } |
| 1153 | } |
| 1154 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1155 | unsigned int |
| 1156 | check_fsl_memctl_config_regs(const fsl_ddr_cfg_regs_t *ddr) |
| 1157 | { |
| 1158 | unsigned int res = 0; |
| 1159 | |
| 1160 | /* |
| 1161 | * Check that DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN] are |
| 1162 | * not set at the same time. |
| 1163 | */ |
| 1164 | if (ddr->ddr_sdram_cfg & 0x10000000 |
| 1165 | && ddr->ddr_sdram_cfg & 0x00008000) { |
| 1166 | printf("Error: DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN] " |
| 1167 | " should not be set at the same time.\n"); |
| 1168 | res++; |
| 1169 | } |
| 1170 | |
| 1171 | return res; |
| 1172 | } |
| 1173 | |
| 1174 | unsigned int |
| 1175 | compute_fsl_memctl_config_regs(const memctl_options_t *popts, |
| 1176 | fsl_ddr_cfg_regs_t *ddr, |
| 1177 | const common_timing_params_t *common_dimm, |
| 1178 | const dimm_params_t *dimm_params, |
| 1179 | unsigned int dbw_cap_adj) |
| 1180 | { |
| 1181 | unsigned int i; |
| 1182 | unsigned int cas_latency; |
| 1183 | unsigned int additive_latency; |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 1184 | unsigned int sr_it; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1185 | unsigned int zq_en; |
| 1186 | unsigned int wrlvl_en; |
York Sun | 2927c5e | 2010-10-18 13:46:50 -0700 | [diff] [blame^] | 1187 | int cs_en = 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1188 | |
| 1189 | memset(ddr, 0, sizeof(fsl_ddr_cfg_regs_t)); |
| 1190 | |
| 1191 | if (common_dimm == NULL) { |
| 1192 | printf("Error: subset DIMM params struct null pointer\n"); |
| 1193 | return 1; |
| 1194 | } |
| 1195 | |
| 1196 | /* |
| 1197 | * Process overrides first. |
| 1198 | * |
| 1199 | * FIXME: somehow add dereated caslat to this |
| 1200 | */ |
| 1201 | cas_latency = (popts->cas_latency_override) |
| 1202 | ? popts->cas_latency_override_value |
| 1203 | : common_dimm->lowest_common_SPD_caslat; |
| 1204 | |
| 1205 | additive_latency = (popts->additive_latency_override) |
| 1206 | ? popts->additive_latency_override_value |
| 1207 | : common_dimm->additive_latency; |
| 1208 | |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 1209 | sr_it = (popts->auto_self_refresh_en) |
| 1210 | ? popts->sr_it |
| 1211 | : 0; |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1212 | /* ZQ calibration */ |
| 1213 | zq_en = (popts->zq_en) ? 1 : 0; |
| 1214 | /* write leveling */ |
| 1215 | wrlvl_en = (popts->wrlvl_en) ? 1 : 0; |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 1216 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1217 | /* Chip Select Memory Bounds (CSn_BNDS) */ |
| 1218 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 1219 | unsigned long long ea = 0, sa = 0; |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1220 | unsigned int cs_per_dimm |
| 1221 | = CONFIG_CHIP_SELECTS_PER_CTRL / CONFIG_DIMM_SLOTS_PER_CTLR; |
| 1222 | unsigned int dimm_number |
| 1223 | = i / cs_per_dimm; |
| 1224 | unsigned long long rank_density |
| 1225 | = dimm_params[dimm_number].rank_density; |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1226 | |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1227 | if (((i == 1) && (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1)) || |
| 1228 | ((i == 2) && (popts->ba_intlv_ctl & 0x04)) || |
| 1229 | ((i == 3) && (popts->ba_intlv_ctl & FSL_DDR_CS2_CS3))) { |
| 1230 | /* |
| 1231 | * Don't set up boundaries for unused CS |
| 1232 | * cs1 for cs0_cs1, cs0_cs1_and_cs2_cs3, cs0_cs1_cs2_cs3 |
| 1233 | * cs2 for cs0_cs1_cs2_cs3 |
| 1234 | * cs3 for cs2_cs3, cs0_cs1_and_cs2_cs3, cs0_cs1_cs2_cs3 |
Dave Liu | 625b268 | 2009-12-16 10:24:39 -0600 | [diff] [blame] | 1235 | * But we need to set the ODT_RD_CFG and |
| 1236 | * ODT_WR_CFG for CS1_CONFIG here. |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1237 | */ |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 1238 | set_csn_config(dimm_number, i, ddr, popts, dimm_params); |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1239 | continue; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1240 | } |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1241 | if (dimm_params[dimm_number].n_ranks == 0) { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1242 | debug("Skipping setup of CS%u " |
york | f4f93c6 | 2010-07-02 22:25:53 +0000 | [diff] [blame] | 1243 | "because n_ranks on DIMM %u is 0\n", i, dimm_number); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1244 | continue; |
| 1245 | } |
| 1246 | if (popts->memctl_interleaving && popts->ba_intlv_ctl) { |
| 1247 | /* |
| 1248 | * This works superbank 2CS |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1249 | * There are 2 or more memory controllers configured |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1250 | * identically, memory is interleaved between them, |
| 1251 | * and each controller uses rank interleaving within |
| 1252 | * itself. Therefore the starting and ending address |
| 1253 | * on each controller is twice the amount present on |
York Sun | 2927c5e | 2010-10-18 13:46:50 -0700 | [diff] [blame^] | 1254 | * each controller. If any CS is not included in the |
| 1255 | * interleaving, the memory on that CS is not accssible |
| 1256 | * and the total memory size is reduced. The CS is also |
| 1257 | * disabled. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1258 | */ |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1259 | unsigned long long ctlr_density = 0; |
| 1260 | switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) { |
| 1261 | case FSL_DDR_CS0_CS1: |
| 1262 | case FSL_DDR_CS0_CS1_AND_CS2_CS3: |
| 1263 | ctlr_density = dimm_params[0].rank_density * 2; |
York Sun | 2927c5e | 2010-10-18 13:46:50 -0700 | [diff] [blame^] | 1264 | if (i > 1) |
| 1265 | cs_en = 0; |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1266 | break; |
| 1267 | case FSL_DDR_CS2_CS3: |
| 1268 | ctlr_density = dimm_params[0].rank_density; |
York Sun | 2927c5e | 2010-10-18 13:46:50 -0700 | [diff] [blame^] | 1269 | if (i > 0) |
| 1270 | cs_en = 0; |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1271 | break; |
| 1272 | case FSL_DDR_CS0_CS1_CS2_CS3: |
| 1273 | /* |
| 1274 | * The four CS interleaving should have been verified by |
| 1275 | * populate_memctl_options() |
| 1276 | */ |
| 1277 | ctlr_density = dimm_params[0].rank_density * 4; |
| 1278 | break; |
| 1279 | default: |
| 1280 | break; |
| 1281 | } |
| 1282 | ea = (CONFIG_NUM_DDR_CONTROLLERS * |
| 1283 | (ctlr_density >> dbw_cap_adj)) - 1; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1284 | } |
| 1285 | else if (!popts->memctl_interleaving && popts->ba_intlv_ctl) { |
| 1286 | /* |
| 1287 | * If memory interleaving between controllers is NOT |
| 1288 | * enabled, the starting address for each memory |
| 1289 | * controller is distinct. However, because rank |
| 1290 | * interleaving is enabled, the starting and ending |
| 1291 | * addresses of the total memory on that memory |
| 1292 | * controller needs to be programmed into its |
| 1293 | * respective CS0_BNDS. |
| 1294 | */ |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1295 | switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) { |
| 1296 | case FSL_DDR_CS0_CS1_CS2_CS3: |
| 1297 | /* CS0+CS1+CS2+CS3 interleaving, only CS0_CNDS |
| 1298 | * needs to be set. |
| 1299 | */ |
| 1300 | sa = common_dimm->base_address; |
| 1301 | ea = sa + (4 * (rank_density >> dbw_cap_adj))-1; |
| 1302 | break; |
| 1303 | case FSL_DDR_CS0_CS1_AND_CS2_CS3: |
| 1304 | /* CS0+CS1 and CS2+CS3 interleaving, CS0_CNDS |
| 1305 | * and CS2_CNDS need to be set. |
| 1306 | */ |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1307 | if ((i == 2) && (dimm_number == 0)) { |
| 1308 | sa = dimm_params[dimm_number].base_address + |
| 1309 | 2 * (rank_density >> dbw_cap_adj); |
| 1310 | ea = sa + 2 * (rank_density >> dbw_cap_adj) - 1; |
| 1311 | } else { |
| 1312 | sa = dimm_params[dimm_number].base_address; |
| 1313 | ea = sa + (2 * (rank_density >> |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1314 | dbw_cap_adj)) - 1; |
| 1315 | } |
| 1316 | break; |
| 1317 | case FSL_DDR_CS0_CS1: |
| 1318 | /* CS0+CS1 interleaving, CS0_CNDS needs |
| 1319 | * to be set |
| 1320 | */ |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1321 | if (dimm_params[dimm_number].n_ranks > (i % cs_per_dimm)) { |
| 1322 | sa = dimm_params[dimm_number].base_address; |
| 1323 | ea = sa + (rank_density >> dbw_cap_adj) - 1; |
| 1324 | sa += (i % cs_per_dimm) * (rank_density >> dbw_cap_adj); |
| 1325 | ea += (i % cs_per_dimm) * (rank_density >> dbw_cap_adj); |
| 1326 | } else { |
| 1327 | sa = 0; |
| 1328 | ea = 0; |
| 1329 | } |
| 1330 | if (i == 0) |
| 1331 | ea += (rank_density >> dbw_cap_adj); |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1332 | break; |
| 1333 | case FSL_DDR_CS2_CS3: |
| 1334 | /* CS2+CS3 interleaving*/ |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1335 | if (dimm_params[dimm_number].n_ranks > (i % cs_per_dimm)) { |
| 1336 | sa = dimm_params[dimm_number].base_address; |
| 1337 | ea = sa + (rank_density >> dbw_cap_adj) - 1; |
| 1338 | sa += (i % cs_per_dimm) * (rank_density >> dbw_cap_adj); |
| 1339 | ea += (i % cs_per_dimm) * (rank_density >> dbw_cap_adj); |
| 1340 | } else { |
| 1341 | sa = 0; |
| 1342 | ea = 0; |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1343 | } |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1344 | if (i == 2) |
| 1345 | ea += (rank_density >> dbw_cap_adj); |
Haiying Wang | 272b596 | 2008-10-03 12:36:39 -0400 | [diff] [blame] | 1346 | break; |
| 1347 | default: /* No bank(chip-select) interleaving */ |
| 1348 | break; |
| 1349 | } |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1350 | } |
| 1351 | else if (popts->memctl_interleaving && !popts->ba_intlv_ctl) { |
| 1352 | /* |
| 1353 | * Only the rank on CS0 of each memory controller may |
| 1354 | * be used if memory controller interleaving is used |
| 1355 | * without rank interleaving within each memory |
| 1356 | * controller. However, the ending address programmed |
| 1357 | * into each CS0 must be the sum of the amount of |
| 1358 | * memory in the two CS0 ranks. |
| 1359 | */ |
| 1360 | if (i == 0) { |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1361 | ea = (2 * (rank_density >> dbw_cap_adj)) - 1; |
| 1362 | } |
| 1363 | |
| 1364 | } |
| 1365 | else if (!popts->memctl_interleaving && !popts->ba_intlv_ctl) { |
| 1366 | /* |
| 1367 | * No rank interleaving and no memory controller |
| 1368 | * interleaving. |
| 1369 | */ |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1370 | sa = dimm_params[dimm_number].base_address; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1371 | ea = sa + (rank_density >> dbw_cap_adj) - 1; |
york | 93799ca | 2010-07-02 22:25:52 +0000 | [diff] [blame] | 1372 | if (dimm_params[dimm_number].n_ranks > (i % cs_per_dimm)) { |
| 1373 | sa += (i % cs_per_dimm) * (rank_density >> dbw_cap_adj); |
| 1374 | ea += (i % cs_per_dimm) * (rank_density >> dbw_cap_adj); |
| 1375 | } else { |
| 1376 | sa = 0; |
| 1377 | ea = 0; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | sa >>= 24; |
| 1382 | ea >>= 24; |
| 1383 | |
| 1384 | ddr->cs[i].bnds = (0 |
| 1385 | | ((sa & 0xFFF) << 16) /* starting address MSB */ |
| 1386 | | ((ea & 0xFFF) << 0) /* ending address MSB */ |
| 1387 | ); |
| 1388 | |
Haiying Wang | d90e040 | 2008-10-03 12:37:26 -0400 | [diff] [blame] | 1389 | debug("FSLDDR: cs[%d]_bnds = 0x%08x\n", i, ddr->cs[i].bnds); |
York Sun | 2927c5e | 2010-10-18 13:46:50 -0700 | [diff] [blame^] | 1390 | if (cs_en) { |
| 1391 | set_csn_config(dimm_number, i, ddr, popts, dimm_params); |
| 1392 | set_csn_config_2(i, ddr); |
| 1393 | } else |
| 1394 | printf("CS%d is disabled.\n", i); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1395 | } |
| 1396 | |
york | 4260372 | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 1397 | set_ddr_eor(ddr, popts); |
| 1398 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1399 | #if !defined(CONFIG_FSL_DDR1) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1400 | set_timing_cfg_0(ddr); |
| 1401 | #endif |
| 1402 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1403 | set_timing_cfg_3(ddr, common_dimm, cas_latency); |
| 1404 | set_timing_cfg_1(ddr, popts, common_dimm, cas_latency); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1405 | set_timing_cfg_2(ddr, popts, common_dimm, |
| 1406 | cas_latency, additive_latency); |
| 1407 | |
| 1408 | set_ddr_sdram_cfg(ddr, popts, common_dimm); |
| 1409 | |
| 1410 | set_ddr_sdram_cfg_2(ddr, popts); |
| 1411 | set_ddr_sdram_mode(ddr, popts, common_dimm, |
| 1412 | cas_latency, additive_latency); |
Dave Liu | 2d0f125 | 2009-12-16 10:24:38 -0600 | [diff] [blame] | 1413 | set_ddr_sdram_mode_2(ddr, popts); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1414 | set_ddr_sdram_interval(ddr, popts, common_dimm); |
| 1415 | set_ddr_data_init(ddr); |
| 1416 | set_ddr_sdram_clk_cntl(ddr, popts); |
| 1417 | set_ddr_init_addr(ddr); |
| 1418 | set_ddr_init_ext_addr(ddr); |
Dave Liu | 3525e1a | 2010-03-05 12:22:00 +0800 | [diff] [blame] | 1419 | set_timing_cfg_4(ddr, popts); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1420 | set_timing_cfg_5(ddr); |
| 1421 | |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 1422 | set_ddr_zq_cntl(ddr, zq_en); |
Dave Liu | 64ee7df | 2009-12-16 10:24:37 -0600 | [diff] [blame] | 1423 | set_ddr_wrlvl_cntl(ddr, wrlvl_en, popts); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1424 | |
Dave Liu | 2aad0ae | 2008-11-21 16:31:35 +0800 | [diff] [blame] | 1425 | set_ddr_sr_cntr(ddr, sr_it); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1426 | |
york | de87932 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 1427 | set_ddr_sdram_rcw(ddr, common_dimm); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1428 | |
| 1429 | return check_fsl_memctl_config_regs(ddr); |
| 1430 | } |