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