1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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>
30
31struct sdram_conf_s {
32 unsigned long size;
33 unsigned long reg;
34#ifdef CONFIG_TQM8548
35 unsigned long refresh;
36#endif
37};
38
39typedef struct sdram_conf_s sdram_conf_t;
40
41#ifdef CONFIG_TQM8548
42#ifdef CONFIG_TQM8548_AG
43sdram_conf_t ddr_cs_conf[] = {
44 {(1024 << 20), 0x80044202, 0x0002D000},
45 { (512 << 20), 0x80044102, 0x0001A000},
46 { (256 << 20), 0x80040102, 0x00014000},
47 { (128 << 20), 0x80040101, 0x0000C000},
48};
49#else
50sdram_conf_t ddr_cs_conf[] = {
51 {(512 << 20), 0x80044102, 0x0001A000},
52 {(256 << 20), 0x80040102, 0x00014000},
53 {(128 << 20), 0x80040101, 0x0000C000},
54};
55#endif
56#else
57sdram_conf_t ddr_cs_conf[] = {
58 {(512 << 20), 0x80000202},
59 {(256 << 20), 0x80000102},
60 {(128 << 20), 0x80000101},
61 {( 64 << 20), 0x80000001},
62};
63#endif
64
65#define N_DDR_CS_CONF (sizeof(ddr_cs_conf) / sizeof(ddr_cs_conf[0]))
66
67int cas_latency (void);
68
69
70
71
72
73
74
75
76long int sdram_setup (int casl)
77{
78 int i;
79 volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
80#ifdef CONFIG_TQM8548
81 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
82#if defined(CONFIG_TQM8548_AG) || defined(CONFIG_TQM8548_BE)
83 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
84#endif
85#else
86 unsigned long cfg_ddr_timing1;
87 unsigned long cfg_ddr_mode;
88#endif
89
90
91
92
93 ddr->cs0_config = 0;
94 ddr->sdram_cfg = 0;
95
96#ifdef CONFIG_TQM8548
97
98
99 ddr->cs0_bnds = (ddr_cs_conf[0].size - 1) >> 24;
100 ddr->cs0_config = ddr_cs_conf[0].reg;
101 ddr->timing_cfg_3 = 0x00020000;
102
103
104
105
106
107
108
109
110
111
112
113 ddr->timing_cfg_1 = 0x4C47D432;
114
115
116
117
118
119
120
121
122
123
124 ddr->timing_cfg_2 = 0x331848CE;
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 ddr->sdram_mode = 0x439E0642;
146
147
148
149
150
151 ddr->sdram_interval = (1040 << 16) | 0x100;
152
153
154
155
156
157
158 if (SVR_REV (get_svr ()) < 0x21)
159 gur->ddrioovcr = 0x90000000;
160
161
162
163
164
165
166
167
168
169
170
171
172 ddr->sdram_cfg_2 = 0x04401000;
173
174
175
176
177 ddr->sdram_mode_2 = 0x8000C000;
178
179
180
181
182
183 ddr->sdram_clk_cntl = 0x02800000;
184
185
186 asm ("sync;isync;msync");
187 udelay (1000);
188
189#if defined(CONFIG_TQM8548_AG) || defined(CONFIG_TQM8548_BE)
190
191
192
193
194
195
196
197
198
199
200
201 ecm->eebacr |= 0x10000000;
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 ddr->sdram_cfg_2 |= 0x00000010;
218
219
220
221
222
223 ddr->debug_3 |= 0x00000400;
224
225
226
227
228 udelay (200);
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253 ddr->sdram_cfg = 0x83000008;
254
255
256
257
258 asm ("sync;isync;msync");
259 while (ddr->sdram_cfg_2 & 0x00000010)
260 asm ("eieio");
261
262
263
264
265 ddr->debug_3 &= ~0x00000400;
266
267
268
269
270 ddr->debug_2 |= 0x00000400;
271
272
273
274
275 asm ("sync;isync;msync");
276 while (ddr->debug_2 & 0x00000400)
277 asm ("eieio");
278
279
280
281
282 ecm->eebacr &= ~0x10000000;
283
284#else
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305 ddr->sdram_cfg = 0x83000008;
306
307#endif
308
309 asm ("sync; isync; msync");
310 udelay (1000);
311#else
312 switch (casl) {
313 case 20:
314 cfg_ddr_timing1 = 0x47405331 | (3 << 16);
315 cfg_ddr_mode = 0x40020002 | (2 << 4);
316 break;
317
318 case 25:
319 cfg_ddr_timing1 = 0x47405331 | (4 << 16);
320 cfg_ddr_mode = 0x40020002 | (6 << 4);
321 break;
322
323 case 30:
324 default:
325 cfg_ddr_timing1 = 0x47405331 | (5 << 16);
326 cfg_ddr_mode = 0x40020002 | (3 << 4);
327 break;
328 }
329
330 ddr->cs0_bnds = (ddr_cs_conf[0].size - 1) >> 24;
331 ddr->cs0_config = ddr_cs_conf[0].reg;
332 ddr->timing_cfg_1 = cfg_ddr_timing1;
333 ddr->timing_cfg_2 = 0x00000800;
334 ddr->sdram_mode = cfg_ddr_mode;
335 ddr->sdram_interval = 0x05160100;
336 ddr->err_disable = 0x0000000D;
337
338 asm ("sync; isync; msync");
339 udelay (1000);
340
341 ddr->sdram_cfg = 0xc2000000;
342 asm ("sync; isync; msync");
343 udelay (1000);
344#endif
345
346 for (i = 0; i < N_DDR_CS_CONF; i++) {
347 ddr->cs0_config = ddr_cs_conf[i].reg;
348
349 if (get_ram_size (0, ddr_cs_conf[i].size) ==
350 ddr_cs_conf[i].size) {
351
352
353
354 ddr->cs0_bnds = (ddr_cs_conf[i].size - 1) >> 24;
355
356 break;
357 }
358 }
359
360#ifdef CONFIG_TQM8548
361 if (i < N_DDR_CS_CONF) {
362
363
364 ddr->timing_cfg_3 = ddr_cs_conf[i].refresh & 0x00070000;
365
366 ddr->timing_cfg_1 = (ddr->timing_cfg_1 & 0xFFFF0FFF) |
367 (ddr_cs_conf[i].refresh & 0x0000F000);
368
369 return ddr_cs_conf[i].size;
370 }
371#endif
372
373
374 return (i < N_DDR_CS_CONF) ? ddr_cs_conf[i].size : 0;
375}
376
377phys_size_t initdram (int board_type)
378{
379 long dram_size = 0;
380 int casl;
381
382#if defined(CONFIG_DDR_DLL)
383
384
385
386 {
387 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
388 int i, x;
389
390 x = 10;
391
392
393
394
395 gur->ddrdllcr = 0x81000000;
396 asm ("sync; isync; msync");
397 udelay (200);
398 while (gur->ddrdllcr != 0x81000100) {
399 gur->devdisr = gur->devdisr | 0x00010000;
400 asm ("sync; isync; msync");
401 for (i = 0; i < x; i++)
402 ;
403 gur->devdisr = gur->devdisr & 0xfff7ffff;
404 asm ("sync; isync; msync");
405 x++;
406 }
407 }
408#endif
409
410 casl = cas_latency ();
411 dram_size = sdram_setup (casl);
412 if ((dram_size == 0) && (casl != CONFIG_DDR_DEFAULT_CL)) {
413
414
415
416 printf ("Problem with CAS lantency, using default CL %d/10!\n",
417 CONFIG_DDR_DEFAULT_CL);
418 dram_size = sdram_setup (CONFIG_DDR_DEFAULT_CL);
419 puts (" ");
420 }
421
422 return dram_size;
423}
424
425#if defined(CONFIG_SYS_DRAM_TEST)
426int testdram (void)
427{
428 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
429 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
430 uint *p;
431
432 printf ("SDRAM test phase 1:\n");
433 for (p = pstart; p < pend; p++)
434 *p = 0xaaaaaaaa;
435
436 for (p = pstart; p < pend; p++) {
437 if (*p != 0xaaaaaaaa) {
438 printf ("SDRAM test fails at: %08x\n", (uint) p);
439 return 1;
440 }
441 }
442
443 printf ("SDRAM test phase 2:\n");
444 for (p = pstart; p < pend; p++)
445 *p = 0x55555555;
446
447 for (p = pstart; p < pend; p++) {
448 if (*p != 0x55555555) {
449 printf ("SDRAM test fails at: %08x\n", (uint) p);
450 return 1;
451 }
452 }
453
454 printf ("SDRAM test passed.\n");
455 return 0;
456}
457#endif
458