blob: 69015ec5b9271a8b7fc41ddb46cd63d1e9d77371 [file] [log] [blame]
Stefan Roese09554022005-11-30 13:06:40 +01001/*
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 Roese09554022005-11-30 13:06:40 +010024#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 Roese09554022005-11-30 13:06:40 +010029
30struct sdram_conf_s {
31 unsigned long size;
32 unsigned long reg;
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020033#ifdef CONFIG_TQM8548
34 unsigned long refresh;
35#endif /* CONFIG_TQM8548 */
Stefan Roese09554022005-11-30 13:06:40 +010036};
37
38typedef struct sdram_conf_s sdram_conf_t;
39
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020040#ifdef CONFIG_TQM8548
Wolfgang Grandegger57181dd2009-02-11 18:38:24 +010041#ifdef CONFIG_TQM8548_AG
42sdram_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 Grandegger328c6ec2008-06-05 13:12:07 +020049sdram_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 Grandegger57181dd2009-02-11 18:38:24 +010054#endif /* CONFIG_TQM8548_AG */
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020055#else /* !CONFIG_TQM8548 */
Stefan Roese09554022005-11-30 13:06:40 +010056sdram_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 Grandegger9039ce12008-06-05 13:12:00 +020060 {( 64 << 20), 0x80000001}, /* 64MB, 12x9(4) */
Stefan Roese09554022005-11-30 13:06:40 +010061};
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020062#endif /* CONFIG_TQM8548 */
Stefan Roese09554022005-11-30 13:06:40 +010063
64#define N_DDR_CS_CONF (sizeof(ddr_cs_conf) / sizeof(ddr_cs_conf[0]))
65
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +020066int cas_latency (void);
Stefan Roese09554022005-11-30 13:06:40 +010067
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 Grandegger9039ce12008-06-05 13:12:00 +020075long int sdram_setup (int casl)
Stefan Roese09554022005-11-30 13:06:40 +010076{
77 int i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020079#ifdef CONFIG_TQM8548
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020080 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020081#else /* !CONFIG_TQM8548 */
Stefan Roese09554022005-11-30 13:06:40 +010082 unsigned long cfg_ddr_timing1;
83 unsigned long cfg_ddr_mode;
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020084#endif /* CONFIG_TQM8548 */
Stefan Roese09554022005-11-30 13:06:40 +010085
86 /*
87 * Disable memory controller.
88 */
89 ddr->cs0_config = 0;
90 ddr->sdram_cfg = 0;
91
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020092#ifdef CONFIG_TQM8548
Wolfgang Grandegger89ad1852009-02-11 18:38:23 +010093 /* Timing and refresh settings for DDR2-533 and below */
94
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020095 ddr->cs0_bnds = (ddr_cs_conf[0].size - 1) >> 24;
96 ddr->cs0_config = ddr_cs_conf[0].reg;
Wolfgang Grandegger89ad1852009-02-11 18:38:23 +010097 ddr->timing_cfg_3 = 0x00020000;
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +020098
99 /* TIMING CFG 1, 533MHz
100 * PRETOACT: 4 Clocks
101 * ACTTOPRE: 12 Clocks
102 * ACTTORW: 4 Clocks
103 * CASLAT: 4 Clocks
Wolfgang Grandegger89ad1852009-02-11 18:38:23 +0100104 * REFREC: EXT_REFREC:REFREC 53 Clocks
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200105 * WRREC: 4 Clocks
106 * ACTTOACT: 3 Clocks
107 * WRTORD: 2 Clocks
108 */
Wolfgang Grandegger89ad1852009-02-11 18:38:23 +0100109 ddr->timing_cfg_1 = 0x4C47D432;
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200110
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 Grandegger89ad1852009-02-11 18:38:23 +0100117 * CKE_PLS: 3 Clock
118 * FOUR_ACT: 14 Clocks
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200119 */
Wolfgang Grandegger89ad1852009-02-11 18:38:23 +0100120 ddr->timing_cfg_2 = 0x331848CE;
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200121
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 Roese09554022005-11-30 13:06:40 +0100210 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 Grandegger9039ce12008-06-05 13:12:00 +0200236 asm ("sync; isync; msync");
237 udelay (1000);
Stefan Roese09554022005-11-30 13:06:40 +0100238
239 ddr->sdram_cfg = 0xc2000000; /* unbuffered,no DYN_PWR */
240 asm ("sync; isync; msync");
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200241 udelay (1000);
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200242#endif /* CONFIG_TQM8548 */
Stefan Roese09554022005-11-30 13:06:40 +0100243
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200244 for (i = 0; i < N_DDR_CS_CONF; i++) {
Stefan Roese09554022005-11-30 13:06:40 +0100245 ddr->cs0_config = ddr_cs_conf[i].reg;
246
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200247 if (get_ram_size (0, ddr_cs_conf[i].size) ==
248 ddr_cs_conf[i].size) {
Stefan Roese09554022005-11-30 13:06:40 +0100249 /*
Wolfgang Grandegger6d571542008-06-05 13:12:04 +0200250 * size detected -> set Chip Select Bounds Register
Stefan Roese09554022005-11-30 13:06:40 +0100251 */
Wolfgang Grandegger6d571542008-06-05 13:12:04 +0200252 ddr->cs0_bnds = (ddr_cs_conf[i].size - 1) >> 24;
253
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200254 break;
Stefan Roese09554022005-11-30 13:06:40 +0100255 }
256 }
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200257
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 Roese09554022005-11-30 13:06:40 +0100270
Wolfgang Grandegger328c6ec2008-06-05 13:12:07 +0200271 /* return size if detected, else return 0 */
272 return (i < N_DDR_CS_CONF) ? ddr_cs_conf[i].size : 0;
Stefan Roese09554022005-11-30 13:06:40 +0100273}
274
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200275void board_add_ram_info (int use_default)
Stefan Roese09554022005-11-30 13:06:40 +0100276{
277 int casl;
278
279 if (use_default)
280 casl = CONFIG_DDR_DEFAULT_CL;
281 else
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200282 casl = cas_latency ();
Stefan Roese09554022005-11-30 13:06:40 +0100283
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200284 puts (" (CL=");
Stefan Roese09554022005-11-30 13:06:40 +0100285 switch (casl) {
286 case 20:
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200287 puts ("2)");
Stefan Roese09554022005-11-30 13:06:40 +0100288 break;
289
290 case 25:
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200291 puts ("2.5)");
Stefan Roese09554022005-11-30 13:06:40 +0100292 break;
293
294 case 30:
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200295 puts ("3)");
Stefan Roese09554022005-11-30 13:06:40 +0100296 break;
297 }
298}
299
Becky Brucebd99ae72008-06-09 16:03:40 -0500300phys_size_t initdram (int board_type)
Stefan Roese09554022005-11-30 13:06:40 +0100301{
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-VILLARD03836942008-10-16 15:01:15 +0200310 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200311 int i, x;
Stefan Roese09554022005-11-30 13:06:40 +0100312
313 x = 10;
314
315 /*
316 * Work around to stabilize DDR DLL
317 */
318 gur->ddrdllcr = 0x81000000;
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200319 asm ("sync; isync; msync");
Stefan Roese09554022005-11-30 13:06:40 +0100320 udelay (200);
321 while (gur->ddrdllcr != 0x81000100) {
322 gur->devdisr = gur->devdisr | 0x00010000;
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200323 asm ("sync; isync; msync");
324 for (i = 0; i < x; i++)
Stefan Roese09554022005-11-30 13:06:40 +0100325 ;
326 gur->devdisr = gur->devdisr & 0xfff7ffff;
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200327 asm ("sync; isync; msync");
Stefan Roese09554022005-11-30 13:06:40 +0100328 x++;
329 }
330 }
331#endif
332
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200333 casl = cas_latency ();
334 dram_size = sdram_setup (casl);
Stefan Roese09554022005-11-30 13:06:40 +0100335 if ((dram_size == 0) && (casl != CONFIG_DDR_DEFAULT_CL)) {
336 /*
337 * Try again with default CAS latency
338 */
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200339 puts ("Problem with CAS lantency");
340 board_add_ram_info (1);
341 puts (", using default CL!\n");
Stefan Roese09554022005-11-30 13:06:40 +0100342 casl = CONFIG_DDR_DEFAULT_CL;
Wolfgang Grandegger9039ce12008-06-05 13:12:00 +0200343 dram_size = sdram_setup (casl);
344 puts (" ");
Stefan Roese09554022005-11-30 13:06:40 +0100345 }
346
347 return dram_size;
348}
349
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200350#if defined(CONFIG_SYS_DRAM_TEST)
Stefan Roese09554022005-11-30 13:06:40 +0100351int testdram (void)
352{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200353 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
354 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Stefan Roese09554022005-11-30 13:06:40 +0100355 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