Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 1 | |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2005 |
| 4 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 25 | #include <common.h> |
| 26 | #include <asm/processor.h> |
| 27 | #include <asm/immap_85xx.h> |
| 28 | #include <asm/processor.h> |
| 29 | #include <asm/mmu.h> |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 30 | |
| 31 | struct sdram_conf_s { |
| 32 | unsigned long size; |
| 33 | unsigned long reg; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 34 | #ifdef CONFIG_TQM8548 |
| 35 | unsigned long refresh; |
| 36 | #endif /* CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | typedef struct sdram_conf_s sdram_conf_t; |
| 40 | |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 41 | #ifdef CONFIG_TQM8548 |
Wolfgang Grandegger | 57181dd | 2009-02-11 18:38:24 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_TQM8548_AG |
| 43 | sdram_conf_t ddr_cs_conf[] = { |
| 44 | {(1024 << 20), 0x80044202, 0x0002D000}, /* 1024MB, 14x10(4) */ |
| 45 | { (512 << 20), 0x80044102, 0x0001A000}, /* 512MB, 13x10(4) */ |
| 46 | { (256 << 20), 0x80040102, 0x00014000}, /* 256MB, 13x10(4) */ |
| 47 | { (128 << 20), 0x80040101, 0x0000C000}, /* 128MB, 13x9(4) */ |
| 48 | }; |
| 49 | #else /* !CONFIG_TQM8548_AG */ |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 50 | sdram_conf_t ddr_cs_conf[] = { |
| 51 | {(512 << 20), 0x80044102, 0x0001A000}, /* 512MB, 13x10(4) */ |
| 52 | {(256 << 20), 0x80040102, 0x00014000}, /* 256MB, 13x10(4) */ |
| 53 | {(128 << 20), 0x80040101, 0x0000C000}, /* 128MB, 13x9(4) */ |
| 54 | }; |
Wolfgang Grandegger | 57181dd | 2009-02-11 18:38:24 +0100 | [diff] [blame] | 55 | #endif /* CONFIG_TQM8548_AG */ |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 56 | #else /* !CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 57 | sdram_conf_t ddr_cs_conf[] = { |
| 58 | {(512 << 20), 0x80000202}, /* 512MB, 14x10(4) */ |
| 59 | {(256 << 20), 0x80000102}, /* 256MB, 13x10(4) */ |
| 60 | {(128 << 20), 0x80000101}, /* 128MB, 13x9(4) */ |
Wolfgang Grandegger | 9039ce1 | 2008-06-05 13:12:00 +0200 | [diff] [blame] | 61 | {( 64 << 20), 0x80000001}, /* 64MB, 12x9(4) */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 62 | }; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 63 | #endif /* CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 64 | |
| 65 | #define N_DDR_CS_CONF (sizeof(ddr_cs_conf) / sizeof(ddr_cs_conf[0])) |
| 66 | |
Wolfgang Grandegger | 9039ce1 | 2008-06-05 13:12:00 +0200 | [diff] [blame] | 67 | int cas_latency (void); |
Becky Bruce | 2956039 | 2010-12-17 17:17:54 -0600 | [diff] [blame] | 68 | static phys_size_t sdram_setup(int); |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * Autodetect onboard DDR SDRAM on 85xx platforms |
| 72 | * |
| 73 | * NOTE: Some of the hardcoded values are hardware dependant, |
| 74 | * so this should be extended for other future boards |
| 75 | * using this routine! |
| 76 | */ |
Becky Bruce | 2956039 | 2010-12-17 17:17:54 -0600 | [diff] [blame] | 77 | phys_size_t fixed_sdram(void) |
| 78 | { |
| 79 | int casl = 0; |
| 80 | phys_size_t dram_size = 0; |
| 81 | |
| 82 | casl = cas_latency(); |
| 83 | dram_size = sdram_setup(casl); |
| 84 | if ((dram_size == 0) && (casl != CONFIG_DDR_DEFAULT_CL)) { |
| 85 | /* |
| 86 | * Try again with default CAS latency |
| 87 | */ |
| 88 | printf("Problem with CAS lantency, using default CL %d/10!\n", |
| 89 | CONFIG_DDR_DEFAULT_CL); |
| 90 | dram_size = sdram_setup(CONFIG_DDR_DEFAULT_CL); |
| 91 | puts(" "); |
| 92 | } |
| 93 | return dram_size; |
| 94 | } |
| 95 | |
| 96 | static phys_size_t sdram_setup(int casl) |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 97 | { |
| 98 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR); |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 100 | #ifdef CONFIG_TQM8548 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Andy Fleming | d4f9e5a | 2009-02-16 09:40:20 -0600 | [diff] [blame] | 102 | #if defined(CONFIG_TQM8548_AG) || defined(CONFIG_TQM8548_BE) |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 103 | volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR); |
Andy Fleming | d4f9e5a | 2009-02-16 09:40:20 -0600 | [diff] [blame] | 104 | #endif |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 105 | #else /* !CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 106 | unsigned long cfg_ddr_timing1; |
| 107 | unsigned long cfg_ddr_mode; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 108 | #endif /* CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * Disable memory controller. |
| 112 | */ |
| 113 | ddr->cs0_config = 0; |
| 114 | ddr->sdram_cfg = 0; |
| 115 | |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 116 | #ifdef CONFIG_TQM8548 |
Wolfgang Grandegger | 89ad185 | 2009-02-11 18:38:23 +0100 | [diff] [blame] | 117 | /* Timing and refresh settings for DDR2-533 and below */ |
| 118 | |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 119 | ddr->cs0_bnds = (ddr_cs_conf[0].size - 1) >> 24; |
| 120 | ddr->cs0_config = ddr_cs_conf[0].reg; |
Wolfgang Grandegger | 89ad185 | 2009-02-11 18:38:23 +0100 | [diff] [blame] | 121 | ddr->timing_cfg_3 = 0x00020000; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 122 | |
| 123 | /* TIMING CFG 1, 533MHz |
| 124 | * PRETOACT: 4 Clocks |
| 125 | * ACTTOPRE: 12 Clocks |
| 126 | * ACTTORW: 4 Clocks |
| 127 | * CASLAT: 4 Clocks |
Wolfgang Grandegger | 89ad185 | 2009-02-11 18:38:23 +0100 | [diff] [blame] | 128 | * REFREC: EXT_REFREC:REFREC 53 Clocks |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 129 | * WRREC: 4 Clocks |
| 130 | * ACTTOACT: 3 Clocks |
| 131 | * WRTORD: 2 Clocks |
| 132 | */ |
Wolfgang Grandegger | 89ad185 | 2009-02-11 18:38:23 +0100 | [diff] [blame] | 133 | ddr->timing_cfg_1 = 0x4C47D432; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 134 | |
| 135 | /* TIMING CFG 2, 533MHz |
| 136 | * ADD_LAT: 3 Clocks |
| 137 | * CPO: READLAT + 1 |
| 138 | * WR_LAT: 3 Clocks |
| 139 | * RD_TO_PRE: 2 Clocks |
| 140 | * WR_DATA_DELAY: 1/2 Clock |
Wolfgang Grandegger | 89ad185 | 2009-02-11 18:38:23 +0100 | [diff] [blame] | 141 | * CKE_PLS: 3 Clock |
| 142 | * FOUR_ACT: 14 Clocks |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 143 | */ |
Wolfgang Grandegger | 89ad185 | 2009-02-11 18:38:23 +0100 | [diff] [blame] | 144 | ddr->timing_cfg_2 = 0x331848CE; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 145 | |
| 146 | /* DDR SDRAM Mode, 533MHz |
| 147 | * MRS: Extended Mode Register |
| 148 | * OUT: Outputs enabled |
| 149 | * RDQS: no |
| 150 | * DQS: enabled |
| 151 | * OCD: default state |
| 152 | * RTT: 75 Ohms |
| 153 | * Posted CAS: 3 Clocks |
| 154 | * ODS: reduced strength |
| 155 | * DLL: enabled |
| 156 | * MR: Mode Register |
| 157 | * PD: fast exit |
| 158 | * WR: 4 Clocks |
| 159 | * DLL: no DLL reset |
| 160 | * TM: normal |
| 161 | * CAS latency: 4 Clocks |
| 162 | * BT: sequential |
| 163 | * Burst length: 4 |
| 164 | */ |
| 165 | ddr->sdram_mode = 0x439E0642; |
| 166 | |
| 167 | /* DDR SDRAM Interval, 533MHz |
| 168 | * REFINT: 1040 Clocks |
| 169 | * BSTOPRE: 256 |
| 170 | */ |
| 171 | ddr->sdram_interval = (1040 << 16) | 0x100; |
| 172 | |
| 173 | /* |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 174 | * Workaround for erratum DDR19 according to MPC8548 Device Errata |
| 175 | * document, Rev. 1: DDR IO receiver must be set to an acceptable |
| 176 | * bias point by modifying a hidden register. |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 177 | */ |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 178 | if (SVR_REV (get_svr ()) < 0x21) |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 179 | gur->ddrioovcr = 0x90000000; /* enable, VSEL 1.8V */ |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 180 | |
| 181 | /* DDR SDRAM CFG 2 |
| 182 | * FRC_SR: normal mode |
| 183 | * SR_IE: no self-refresh interrupt |
| 184 | * DLL_RST_DIS: don't care, leave at reset value |
| 185 | * DQS_CFG: differential DQS signals |
| 186 | * ODT_CFG: assert ODT to internal IOs only during reads to DRAM |
| 187 | * LVWx_CFG: don't care, leave at reset value |
| 188 | * NUM_PR: 1 refresh will be issued at a time |
| 189 | * DM_CFG: don't care, leave at reset value |
| 190 | * D_INIT: no data initialization |
| 191 | */ |
| 192 | ddr->sdram_cfg_2 = 0x04401000; |
| 193 | |
| 194 | /* DDR SDRAM MODE 2 |
| 195 | * MRS: Extended Mode Register 2 |
| 196 | */ |
| 197 | ddr->sdram_mode_2 = 0x8000C000; |
| 198 | |
| 199 | /* DDR SDRAM CLK CNTL |
| 200 | * CLK_ADJUST: 1/2 Clock 0x02000000 |
| 201 | * CLK_ADJUST: 5/8 Clock 0x02800000 |
| 202 | */ |
| 203 | ddr->sdram_clk_cntl = 0x02800000; |
| 204 | |
| 205 | /* wait for clock stabilization */ |
| 206 | asm ("sync;isync;msync"); |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 207 | udelay (1000); |
| 208 | |
| 209 | #if defined(CONFIG_TQM8548_AG) || defined(CONFIG_TQM8548_BE) |
| 210 | /* |
| 211 | * Workaround for erratum DDR20 according to MPC8548 Device Errata |
| 212 | * document, Rev. 1: "CKE signal may not function correctly after |
| 213 | * assertion of HRESET" |
| 214 | */ |
| 215 | |
| 216 | /* 1. Configure DDR register as is done in normal DDR configuration. |
| 217 | * Do not set DDR_SDRAM_CFG[MEM_EN]. |
| 218 | * |
| 219 | * 2. Set reserved bit EEBACR[3] at offset 0x1000 |
| 220 | */ |
| 221 | ecm->eebacr |= 0x10000000; |
| 222 | |
| 223 | /* |
| 224 | * 3. Before DDR_SDRAM_CFG[MEM_EN] is set, write DDR_SDRAM_CFG_2[D_INIT] |
| 225 | * |
| 226 | * DDR_SDRAM_CFG_2: |
| 227 | * FRC_SR: normal mode |
| 228 | * SR_IE: no self-refresh interrupt |
| 229 | * DLL_RST_DIS: don't care, leave at reset value |
| 230 | * DQS_CFG: differential DQS signals |
| 231 | * ODT_CFG: assert ODT to internal IOs only during reads to DRAM |
| 232 | * LVWx_CFG: don't care, leave at reset value |
| 233 | * NUM_PR: 1 refresh will be issued at a time |
| 234 | * DM_CFG: don't care, leave at reset value |
| 235 | * D_INIT: enable data initialization |
| 236 | */ |
| 237 | ddr->sdram_cfg_2 |= 0x00000010; |
| 238 | |
| 239 | /* |
| 240 | * 4. Before DDR_SDRAM_CFG[MEM_EN] set, write D3[21] to disable data |
| 241 | * training |
| 242 | */ |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 243 | ddr->debug[2] |= 0x00000400; |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * 5. Wait 200 micro-seconds |
| 247 | */ |
| 248 | udelay (200); |
| 249 | |
| 250 | /* |
| 251 | * 6. Set DDR_SDRAM_CFG[MEM_EN] |
| 252 | * |
| 253 | * BTW, initialize DDR_SDRAM_CFG: |
| 254 | * MEM_EN: enabled |
| 255 | * SREN: don't care, leave at reset value |
| 256 | * ECC_EN: no error report |
| 257 | * RD_EN: no registered DIMMs |
| 258 | * SDRAM_TYPE: DDR2 |
| 259 | * DYN_PWR: no power management |
| 260 | * 32_BE: don't care, leave at reset value |
| 261 | * 8_BE: 4 beat burst |
| 262 | * NCAP: don't care, leave at reset value |
| 263 | * 2T_EN: 1T Timing |
| 264 | * BA_INTLV_CTL: no interleaving |
| 265 | * x32_EN: x16 organization |
| 266 | * PCHB8: MA[10] for auto-precharge |
| 267 | * HSE: half strength for single and 2-layer stacks |
| 268 | * (full strength for 3- and 4-layer stacks not |
| 269 | * yet considered) |
| 270 | * MEM_HALT: no halt |
| 271 | * BI: automatic initialization |
| 272 | */ |
| 273 | ddr->sdram_cfg = 0x83000008; |
| 274 | |
| 275 | /* |
| 276 | * 7. Poll DDR_SDRAM_CFG_2[D_INIT] until it is cleared by hardware |
| 277 | */ |
| 278 | asm ("sync;isync;msync"); |
| 279 | while (ddr->sdram_cfg_2 & 0x00000010) |
| 280 | asm ("eieio"); |
| 281 | |
| 282 | /* |
| 283 | * 8. Clear D3[21] to re-enable data training |
| 284 | */ |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 285 | ddr->debug[2] &= ~0x00000400; |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 286 | |
| 287 | /* |
| 288 | * 9. Set D2(21) to force data training to run |
| 289 | */ |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 290 | ddr->debug[1] |= 0x00000400; |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 291 | |
| 292 | /* |
| 293 | * 10. Poll on D2[21] until it is cleared by hardware |
| 294 | */ |
| 295 | asm ("sync;isync;msync"); |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 296 | while (ddr->debug[1] & 0x00000400) |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 297 | asm ("eieio"); |
| 298 | |
| 299 | /* |
| 300 | * 11. Clear reserved bit EEBACR[3] at offset 0x1000 |
| 301 | */ |
| 302 | ecm->eebacr &= ~0x10000000; |
| 303 | |
| 304 | #else /* !(CONFIG_TQM8548_AG || CONFIG_TQM8548_BE) */ |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 305 | |
| 306 | /* DDR SDRAM CLK CNTL |
| 307 | * MEM_EN: enabled |
| 308 | * SREN: don't care, leave at reset value |
| 309 | * ECC_EN: no error report |
| 310 | * RD_EN: no register DIMMs |
| 311 | * SDRAM_TYPE: DDR2 |
| 312 | * DYN_PWR: no power management |
| 313 | * 32_BE: don't care, leave at reset value |
| 314 | * 8_BE: 4 beat burst |
| 315 | * NCAP: don't care, leave at reset value |
| 316 | * 2T_EN: 1T Timing |
| 317 | * BA_INTLV_CTL: no interleaving |
| 318 | * x32_EN: x16 organization |
| 319 | * PCHB8: MA[10] for auto-precharge |
| 320 | * HSE: half strength for single and 2-layer stacks |
| 321 | * (full strength for 3- and 4-layer stacks no yet considered) |
| 322 | * MEM_HALT: no halt |
| 323 | * BI: automatic initialization |
| 324 | */ |
| 325 | ddr->sdram_cfg = 0x83000008; |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 326 | |
Wolfgang Grandegger | c7487e9 | 2009-02-11 18:38:26 +0100 | [diff] [blame] | 327 | #endif /* CONFIG_TQM8548_AG || CONFIG_TQM8548_BE */ |
| 328 | |
| 329 | asm ("sync; isync; msync"); |
| 330 | udelay (1000); |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 331 | #else /* !CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 332 | switch (casl) { |
| 333 | case 20: |
| 334 | cfg_ddr_timing1 = 0x47405331 | (3 << 16); |
| 335 | cfg_ddr_mode = 0x40020002 | (2 << 4); |
| 336 | break; |
| 337 | |
| 338 | case 25: |
| 339 | cfg_ddr_timing1 = 0x47405331 | (4 << 16); |
| 340 | cfg_ddr_mode = 0x40020002 | (6 << 4); |
| 341 | break; |
| 342 | |
| 343 | case 30: |
| 344 | default: |
| 345 | cfg_ddr_timing1 = 0x47405331 | (5 << 16); |
| 346 | cfg_ddr_mode = 0x40020002 | (3 << 4); |
| 347 | break; |
| 348 | } |
| 349 | |
| 350 | ddr->cs0_bnds = (ddr_cs_conf[0].size - 1) >> 24; |
| 351 | ddr->cs0_config = ddr_cs_conf[0].reg; |
| 352 | ddr->timing_cfg_1 = cfg_ddr_timing1; |
| 353 | ddr->timing_cfg_2 = 0x00000800; /* P9-45,may need tuning */ |
| 354 | ddr->sdram_mode = cfg_ddr_mode; |
| 355 | ddr->sdram_interval = 0x05160100; /* autocharge,no open page */ |
| 356 | ddr->err_disable = 0x0000000D; |
| 357 | |
Wolfgang Grandegger | 9039ce1 | 2008-06-05 13:12:00 +0200 | [diff] [blame] | 358 | asm ("sync; isync; msync"); |
| 359 | udelay (1000); |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 360 | |
| 361 | ddr->sdram_cfg = 0xc2000000; /* unbuffered,no DYN_PWR */ |
| 362 | asm ("sync; isync; msync"); |
Wolfgang Grandegger | 9039ce1 | 2008-06-05 13:12:00 +0200 | [diff] [blame] | 363 | udelay (1000); |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 364 | #endif /* CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 365 | |
Becky Bruce | 259d9c4 | 2011-07-18 18:49:16 -0500 | [diff] [blame] | 366 | /* |
| 367 | * get_ram_size() depends on having tlbs for the DDR, but they are |
| 368 | * not yet setup because we don't know the size. Set up a temp |
| 369 | * mapping and delete it when done. |
| 370 | */ |
| 371 | setup_ddr_tlbs(CONFIG_SYS_DDR_EARLY_SIZE_MB); |
Wolfgang Grandegger | 9039ce1 | 2008-06-05 13:12:00 +0200 | [diff] [blame] | 372 | for (i = 0; i < N_DDR_CS_CONF; i++) { |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 373 | ddr->cs0_config = ddr_cs_conf[i].reg; |
| 374 | |
Wolfgang Grandegger | 9039ce1 | 2008-06-05 13:12:00 +0200 | [diff] [blame] | 375 | if (get_ram_size (0, ddr_cs_conf[i].size) == |
| 376 | ddr_cs_conf[i].size) { |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 377 | /* |
Wolfgang Grandegger | 6d57154 | 2008-06-05 13:12:04 +0200 | [diff] [blame] | 378 | * size detected -> set Chip Select Bounds Register |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 379 | */ |
Wolfgang Grandegger | 6d57154 | 2008-06-05 13:12:04 +0200 | [diff] [blame] | 380 | ddr->cs0_bnds = (ddr_cs_conf[i].size - 1) >> 24; |
| 381 | |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 382 | break; |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 383 | } |
| 384 | } |
Becky Bruce | 259d9c4 | 2011-07-18 18:49:16 -0500 | [diff] [blame] | 385 | clear_ddr_tlbs(CONFIG_SYS_DDR_EARLY_SIZE_MB); |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 386 | |
| 387 | #ifdef CONFIG_TQM8548 |
| 388 | if (i < N_DDR_CS_CONF) { |
| 389 | /* Adjust refresh rate for DDR2 */ |
| 390 | |
| 391 | ddr->timing_cfg_3 = ddr_cs_conf[i].refresh & 0x00070000; |
| 392 | |
| 393 | ddr->timing_cfg_1 = (ddr->timing_cfg_1 & 0xFFFF0FFF) | |
| 394 | (ddr_cs_conf[i].refresh & 0x0000F000); |
| 395 | |
| 396 | return ddr_cs_conf[i].size; |
| 397 | } |
| 398 | #endif /* CONFIG_TQM8548 */ |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 399 | |
Wolfgang Grandegger | 328c6ec | 2008-06-05 13:12:07 +0200 | [diff] [blame] | 400 | /* return size if detected, else return 0 */ |
| 401 | return (i < N_DDR_CS_CONF) ? ddr_cs_conf[i].size : 0; |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 404 | #if defined(CONFIG_SYS_DRAM_TEST) |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 405 | int testdram (void) |
| 406 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 407 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
| 408 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; |
Stefan Roese | 0955402 | 2005-11-30 13:06:40 +0100 | [diff] [blame] | 409 | uint *p; |
| 410 | |
| 411 | printf ("SDRAM test phase 1:\n"); |
| 412 | for (p = pstart; p < pend; p++) |
| 413 | *p = 0xaaaaaaaa; |
| 414 | |
| 415 | for (p = pstart; p < pend; p++) { |
| 416 | if (*p != 0xaaaaaaaa) { |
| 417 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 418 | return 1; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | printf ("SDRAM test phase 2:\n"); |
| 423 | for (p = pstart; p < pend; p++) |
| 424 | *p = 0x55555555; |
| 425 | |
| 426 | for (p = pstart; p < pend; p++) { |
| 427 | if (*p != 0x55555555) { |
| 428 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 429 | return 1; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | printf ("SDRAM test passed.\n"); |
| 434 | return 0; |
| 435 | } |
| 436 | #endif |