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