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 <ioports.h>
27#include <mpc83xx.h>
28#include <asm/mpc8349_pci.h>
29#include <i2c.h>
30#include <miiphy.h>
31#include <asm-ppc/mmu.h>
32#include <pci.h>
33
34DECLARE_GLOBAL_DATA_PTR;
35
36#define IOSYNC asm("eieio")
37#define ISYNC asm("isync")
38#define SYNC asm("sync")
39#define FPW FLASH_PORT_WIDTH
40#define FPWV FLASH_PORT_WIDTHV
41
42#define DDR_MAX_SIZE_PER_CS 0x20000000
43
44#if defined(DDR_CASLAT_20)
45#define TIMING_CASLAT TIMING_CFG1_CASLAT_20
46#define MODE_CASLAT DDR_MODE_CASLAT_20
47#else
48#define TIMING_CASLAT TIMING_CFG1_CASLAT_25
49#define MODE_CASLAT DDR_MODE_CASLAT_25
50#endif
51
52#define INITIAL_CS_CONFIG (CSCONFIG_EN | CSCONFIG_ROW_BIT_12 | \
53 CSCONFIG_COL_BIT_9)
54
55
56int tqm834x_num_flash_banks;
57
58
59ulong flash_get_size (ulong base, int banknum);
60extern flash_info_t flash_info[];
61
62
63static int detect_num_flash_banks(void);
64static long int get_ddr_bank_size(short cs, volatile long *base);
65static void set_cs_bounds(short cs, long base, long size);
66static void set_cs_config(short cs, long config);
67static void set_ddr_config(void);
68
69
70static volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
71
72
73
74
75
76int board_early_init_r (void) {
77
78 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
79 return 0;
80
81
82 return detect_num_flash_banks();
83}
84
85
86
87
88phys_size_t initdram (int board_type)
89{
90 long bank_size;
91 long size;
92 int cs;
93
94
95 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE;
96 im->sysconf.ddrlaw[0].ar = (LAWAR_EN | LAWAR_SIZE_2G);
97
98
99 for(cs = 0; cs < 4; ++cs) {
100 set_cs_bounds(cs,
101 CONFIG_SYS_DDR_BASE + (cs * DDR_MAX_SIZE_PER_CS),
102 DDR_MAX_SIZE_PER_CS);
103
104 set_cs_config(cs, INITIAL_CS_CONFIG);
105 }
106
107
108 set_ddr_config();
109
110 udelay(200);
111
112
113 im->ddr.sdram_cfg = (SDRAM_CFG_MEM_EN |
114 SDRAM_CFG_SREN |
115 SDRAM_CFG_SDRAM_TYPE_DDR1);
116 SYNC;
117
118
119 debug("\n");
120 size = 0;
121 for(cs = 0; cs < 4; ++cs) {
122 debug("\nDetecting Bank%d\n", cs);
123
124 bank_size = get_ddr_bank_size(cs,
125 (volatile long*)(CONFIG_SYS_DDR_BASE + size));
126 size += bank_size;
127
128 debug("DDR Bank%d size: %d MiB\n\n", cs, bank_size >> 20);
129
130
131 if(size < DDR_MAX_SIZE_PER_CS) break;
132 }
133
134 return size;
135}
136
137
138
139
140int checkboard (void)
141{
142 puts("Board: TQM834x\n");
143
144#ifdef CONFIG_PCI
145 volatile immap_t * immr;
146 u32 w, f;
147
148 immr = (immap_t *)CONFIG_SYS_IMMR;
149 if (!(immr->reset.rcwh & HRCWH_PCI_HOST)) {
150 printf("PCI: NOT in host mode..?!\n");
151 return 0;
152 }
153
154
155 w = 32;
156 if (immr->reset.rcwh & HRCWH_64_BIT_PCI)
157 w = 64;
158
159
160 f = gd->pci_clk;
161
162 printf("PCI1: %d bit, %d MHz\n", w, f / 1000000);
163#else
164 printf("PCI: disabled\n");
165#endif
166 return 0;
167}
168
169
170
171
172
173
174
175
176
177
178
179
180
181static int detect_num_flash_banks(void)
182{
183 typedef unsigned long FLASH_PORT_WIDTH;
184 typedef volatile unsigned long FLASH_PORT_WIDTHV;
185 FPWV *bank1_base;
186 FPWV *bank2_base;
187 FPW bank1_read;
188 FPW bank2_read;
189 ulong bank1_size;
190 ulong bank2_size;
191 ulong total_size;
192
193 tqm834x_num_flash_banks = 2;
194
195
196 bank1_size = flash_get_size(CONFIG_SYS_FLASH_BASE, 0);
197 debug("Bank1 size: %lu\n", bank1_size);
198 bank2_size = flash_get_size(CONFIG_SYS_FLASH_BASE + bank1_size, 1);
199 debug("Bank2 size: %lu\n", bank2_size);
200 total_size = bank1_size + bank2_size;
201
202 if (bank2_size > 0) {
203
204
205
206 bank1_base = (FPWV *) (CONFIG_SYS_FLASH_BASE);
207 bank2_base = (FPWV *) (CONFIG_SYS_FLASH_BASE + bank1_size);
208
209
210 bank2_base[0x55] = 0x00980098;
211 IOSYNC;
212 ISYNC;
213 bank2_read = bank2_base[0x10];
214
215
216 bank1_read = bank1_base[0x10];
217
218
219 bank1_base[0] = 0x00F000F0;
220 bank2_base[0] = 0x00F000F0;
221
222 if (bank2_read == bank1_read) {
223
224
225
226
227 bank2_base[0x0555] = 0x00AA00AA;
228 bank2_base[0x02AA] = 0x00550055;
229 bank2_base[0x0555] = 0x00900090;
230 IOSYNC;
231 ISYNC;
232 bank2_read = bank2_base[0x10];
233
234
235 bank1_read = bank1_base[0x10];
236
237
238 bank1_base[0] = 0x00F000F0;
239 bank2_base[0] = 0x00F000F0;
240
241 if (bank2_read == bank1_read) {
242
243
244
245
246
247 tqm834x_num_flash_banks = 1;
248 total_size = bank1_size;
249 }
250 }
251 }
252
253 debug("Number of flash banks detected: %d\n", tqm834x_num_flash_banks);
254
255
256 im->lbus.bank[0].or = CONFIG_SYS_OR_TIMING_FLASH |
257 (-(total_size) & OR_GPCM_AM);
258 im->lbus.bank[0].br = (CONFIG_SYS_FLASH_BASE & BR_BA) |
259 (BR_MS_GPCM | BR_PS_32 | BR_V);
260
261 return (0);
262}
263
264
265
266
267static long int get_ddr_bank_size(short cs, volatile long *base)
268{
269
270
271
272
273
274 struct {
275 long row;
276 long col;
277 long size;
278 } conf[] = {
279 {CSCONFIG_ROW_BIT_12, CSCONFIG_COL_BIT_8, 32 << 20},
280 {CSCONFIG_ROW_BIT_12, CSCONFIG_COL_BIT_9, 64 << 20},
281 {CSCONFIG_ROW_BIT_12, CSCONFIG_COL_BIT_10, 128 << 20},
282 {CSCONFIG_ROW_BIT_13, CSCONFIG_COL_BIT_9, 128 << 20},
283 {CSCONFIG_ROW_BIT_13, CSCONFIG_COL_BIT_10, 256 << 20},
284 {CSCONFIG_ROW_BIT_13, CSCONFIG_COL_BIT_11, 512 << 20},
285 {CSCONFIG_ROW_BIT_14, CSCONFIG_COL_BIT_10, 512 << 20},
286 {CSCONFIG_ROW_BIT_14, CSCONFIG_COL_BIT_11, 1024 << 20},
287 {0, 0, 0}
288 };
289
290 int i;
291 int detected;
292 long size;
293
294 detected = -1;
295 for(i = 0; conf[i].size != 0; ++i) {
296
297
298 set_cs_config(cs, CSCONFIG_EN | conf[i].col | conf[i].row);
299
300 debug("Getting RAM size...\n");
301 size = get_ram_size(base, DDR_MAX_SIZE_PER_CS);
302
303 if((size == conf[i].size) && (i == detected + 1))
304 detected = i;
305
306 debug("Trying %ld x %ld (%ld MiB) at addr %p, detected: %ld MiB\n",
307 conf[i].row,
308 conf[i].col,
309 conf[i].size >> 20,
310 base,
311 size >> 20);
312 }
313
314 if(detected == -1){
315
316 debug("\nNo valid configurations for CS%d, disabling...\n", cs);
317 set_cs_config(cs, 0);
318 return 0;
319 }
320
321 debug("\nDetected configuration %ld x %ld (%ld MiB) at addr %p\n",
322 conf[detected].row, conf[detected].col, conf[detected].size >> 20, base);
323
324
325 set_cs_config(cs, CSCONFIG_EN | conf[detected].row |
326 conf[detected].col);
327
328 set_cs_bounds(cs, (long)base, conf[detected].size);
329
330 return(conf[detected].size);
331}
332
333
334
335
336static void set_cs_bounds(short cs, long base, long size)
337{
338 debug("Setting bounds %08x, %08x for cs %d\n", base, size, cs);
339 if(size == 0){
340 im->ddr.csbnds[cs].csbnds = 0x00000000;
341 } else {
342 im->ddr.csbnds[cs].csbnds =
343 ((base >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
344 (((base + size - 1) >> CSBNDS_EA_SHIFT) &
345 CSBNDS_EA);
346 }
347 SYNC;
348}
349
350
351
352
353
354static void set_cs_config(short cs, long config)
355{
356 debug("Setting config %08x for cs %d\n", config, cs);
357 im->ddr.cs_config[cs] = config;
358 SYNC;
359}
360
361
362
363
364static void set_ddr_config(void) {
365
366 im->ddr.sdram_clk_cntl = DDR_SDRAM_CLK_CNTL_SS_EN |
367 DDR_SDRAM_CLK_CNTL_CLK_ADJUST_05;
368 SYNC;
369
370
371 im->ddr.timing_cfg_1 =
372 (4 << TIMING_CFG1_PRETOACT_SHIFT) |
373 (7 << TIMING_CFG1_ACTTOPRE_SHIFT) |
374 (4 << TIMING_CFG1_ACTTORW_SHIFT) |
375 (5 << TIMING_CFG1_REFREC_SHIFT) |
376 (3 << TIMING_CFG1_WRREC_SHIFT) |
377 (3 << TIMING_CFG1_ACTTOACT_SHIFT) |
378 (1 << TIMING_CFG1_WRTORD_SHIFT) |
379 (TIMING_CFG1_CASLAT & TIMING_CASLAT);
380
381 im->ddr.timing_cfg_2 =
382 TIMING_CFG2_CPO_DEF |
383 (2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT);
384 SYNC;
385
386
387 im->ddr.sdram_cfg =
388 SDRAM_CFG_SREN |
389 SDRAM_CFG_SDRAM_TYPE_DDR1;
390 SYNC;
391
392
393 im->ddr.sdram_mode =
394 ((DDR_MODE_EXT_MODEREG | DDR_MODE_WEAK) <<
395 SDRAM_MODE_ESD_SHIFT) |
396 ((DDR_MODE_MODEREG | DDR_MODE_BLEN_4) <<
397 SDRAM_MODE_SD_SHIFT) |
398 ((DDR_MODE_CASLAT << SDRAM_MODE_SD_SHIFT) &
399 MODE_CASLAT);
400 SYNC;
401
402
403 im->ddr.sdram_interval =
404 (DDR_REFINT_166MHZ_7US << SDRAM_INTERVAL_REFINT_SHIFT) |
405 (DDR_BSTOPRE << SDRAM_INTERVAL_BSTOPRE_SHIFT);
406 SYNC;
407
408
409
410
411
412
413
414
415
416
417
418
419 if ((im->sysconf.spridr & SPRIDR_REVID) < 0x200) {
420
421
422
423
424
425 u32 *reserved_p = (u32 *)((u8 *)im + 0x2f00);
426
427#if defined(DDR_CASLAT_20)
428 *reserved_p = 0x201c0000;
429#else
430 *reserved_p = 0x202c0000;
431#endif
432 }
433}
434
435#ifdef CONFIG_OF_BOARD_SETUP
436void ft_board_setup(void *blob, bd_t *bd)
437{
438 ft_cpu_setup(blob, bd);
439
440#ifdef CONFIG_PCI
441 ft_pci_setup(blob, bd);
442#endif
443}
444#endif
445