blob: de4ca1e77470e86bc17c6745645a9c20caf682ff [file] [log] [blame]
Dave Liua46daea2006-11-03 19:33:44 -06001/*
2 * Copyright (C) 2006 Freescale Semiconductor, Inc.
3 *
4 * Dave Liu <daveliu@freescale.com>
5 * based on board/mpc8349emds/mpc8349emds.c
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 */
15
16#include <common.h>
17#include <ioports.h>
18#include <mpc83xx.h>
19#include <i2c.h>
20#include <spd.h>
21#include <miiphy.h>
22#include <command.h>
23#if defined(CONFIG_PCI)
24#include <pci.h>
25#endif
26#if defined(CONFIG_SPD_EEPROM)
27#include <spd_sdram.h>
28#else
29#include <asm/mmu.h>
30#endif
Kim Phillips774e1b52006-11-01 00:10:40 -060031#if defined(CONFIG_OF_FLAT_TREE)
32#include <ft_build.h>
33#endif
Gerald Van Barend6abef42007-03-31 12:23:51 -040034#if defined(CONFIG_OF_LIBFDT)
35#include <libfdt.h>
36#include <libfdt_env.h>
37#endif
Dave Liua46daea2006-11-03 19:33:44 -060038
Dave Liue732e9c2006-11-03 12:11:15 -060039const qe_iop_conf_t qe_iop_conf_tab[] = {
40 /* GETH1 */
41 {0, 3, 1, 0, 1}, /* TxD0 */
42 {0, 4, 1, 0, 1}, /* TxD1 */
43 {0, 5, 1, 0, 1}, /* TxD2 */
44 {0, 6, 1, 0, 1}, /* TxD3 */
45 {1, 6, 1, 0, 3}, /* TxD4 */
46 {1, 7, 1, 0, 1}, /* TxD5 */
47 {1, 9, 1, 0, 2}, /* TxD6 */
48 {1, 10, 1, 0, 2}, /* TxD7 */
49 {0, 9, 2, 0, 1}, /* RxD0 */
50 {0, 10, 2, 0, 1}, /* RxD1 */
51 {0, 11, 2, 0, 1}, /* RxD2 */
52 {0, 12, 2, 0, 1}, /* RxD3 */
53 {0, 13, 2, 0, 1}, /* RxD4 */
54 {1, 1, 2, 0, 2}, /* RxD5 */
55 {1, 0, 2, 0, 2}, /* RxD6 */
56 {1, 4, 2, 0, 2}, /* RxD7 */
57 {0, 7, 1, 0, 1}, /* TX_EN */
58 {0, 8, 1, 0, 1}, /* TX_ER */
59 {0, 15, 2, 0, 1}, /* RX_DV */
60 {0, 16, 2, 0, 1}, /* RX_ER */
61 {0, 0, 2, 0, 1}, /* RX_CLK */
62 {2, 9, 1, 0, 3}, /* GTX_CLK - CLK10 */
63 {2, 8, 2, 0, 1}, /* GTX125 - CLK9 */
64 /* GETH2 */
65 {0, 17, 1, 0, 1}, /* TxD0 */
66 {0, 18, 1, 0, 1}, /* TxD1 */
67 {0, 19, 1, 0, 1}, /* TxD2 */
68 {0, 20, 1, 0, 1}, /* TxD3 */
69 {1, 2, 1, 0, 1}, /* TxD4 */
70 {1, 3, 1, 0, 2}, /* TxD5 */
71 {1, 5, 1, 0, 3}, /* TxD6 */
72 {1, 8, 1, 0, 3}, /* TxD7 */
73 {0, 23, 2, 0, 1}, /* RxD0 */
74 {0, 24, 2, 0, 1}, /* RxD1 */
75 {0, 25, 2, 0, 1}, /* RxD2 */
76 {0, 26, 2, 0, 1}, /* RxD3 */
77 {0, 27, 2, 0, 1}, /* RxD4 */
78 {1, 12, 2, 0, 2}, /* RxD5 */
79 {1, 13, 2, 0, 3}, /* RxD6 */
80 {1, 11, 2, 0, 2}, /* RxD7 */
81 {0, 21, 1, 0, 1}, /* TX_EN */
82 {0, 22, 1, 0, 1}, /* TX_ER */
83 {0, 29, 2, 0, 1}, /* RX_DV */
84 {0, 30, 2, 0, 1}, /* RX_ER */
85 {0, 31, 2, 0, 1}, /* RX_CLK */
86 {2, 2, 1, 0, 2}, /* GTX_CLK = CLK10 */
87 {2, 3, 2, 0, 1}, /* GTX125 - CLK4 */
88
89 {0, 1, 3, 0, 2}, /* MDIO */
90 {0, 2, 1, 0, 1}, /* MDC */
91
92 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
93};
94
Dave Liua46daea2006-11-03 19:33:44 -060095int board_early_init_f(void)
96{
Kim Phillips7a1e91b2007-02-14 19:50:53 -060097
98 u8 *bcsr = (u8 *)CFG_BCSR;
99 const immap_t *immr = (immap_t *)CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -0600100
101 /* Enable flash write */
102 bcsr[0xa] &= ~0x04;
103
Kim Phillips7a1e91b2007-02-14 19:50:53 -0600104 /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2 h/w bug workaround) */
105 if (immr->sysconf.spridr == SPR_8360_REV20 ||
Lee Nipperf600cf32007-06-14 20:07:33 -0500106 immr->sysconf.spridr == SPR_8360E_REV20 ||
107 immr->sysconf.spridr == SPR_8360_REV21 ||
108 immr->sysconf.spridr == SPR_8360E_REV21)
Kim Phillips7a1e91b2007-02-14 19:50:53 -0600109 bcsr[0xe] = 0x30;
110
Dave Liua46daea2006-11-03 19:33:44 -0600111 return 0;
112}
113
114#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
115extern void ddr_enable_ecc(unsigned int dram_size);
116#endif
117int fixed_sdram(void);
118void sdram_init(void);
119
120long int initdram(int board_type)
121{
Timur Tabi386a2802006-11-03 12:00:28 -0600122 volatile immap_t *im = (immap_t *) CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -0600123 u32 msize = 0;
124
125 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
126 return -1;
127
128 /* DDR SDRAM - Main SODIMM */
129 im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
130#if defined(CONFIG_SPD_EEPROM)
131 msize = spd_sdram();
132#else
133 msize = fixed_sdram();
134#endif
135
136#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
137 /*
138 * Initialize DDR ECC byte
139 */
140 ddr_enable_ecc(msize * 1024 * 1024);
141#endif
142 /*
143 * Initialize SDRAM if it is on local bus.
144 */
145 sdram_init();
146 puts(" DDR RAM: ");
147 /* return total bus SDRAM size(bytes) -- DDR */
148 return (msize * 1024 * 1024);
149}
150
151#if !defined(CONFIG_SPD_EEPROM)
152/*************************************************************************
153 * fixed sdram init -- doesn't use serial presence detect.
154 ************************************************************************/
155int fixed_sdram(void)
156{
Timur Tabi386a2802006-11-03 12:00:28 -0600157 volatile immap_t *im = (immap_t *) CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -0600158 u32 msize = 0;
159 u32 ddr_size;
160 u32 ddr_size_log2;
161
162 msize = CFG_DDR_SIZE;
163 for (ddr_size = msize << 20, ddr_size_log2 = 0;
164 (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
165 if (ddr_size & 1) {
166 return -1;
167 }
168 }
169 im->sysconf.ddrlaw[0].ar =
170 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
171#if (CFG_DDR_SIZE != 256)
172#warning Currenly any ddr size other than 256 is not supported
173#endif
Xie Xiaobo6149a5a2007-02-14 18:27:17 +0800174#ifdef CONFIG_DDR_II
175 im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
176 im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
177 im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
178 im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
179 im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
180 im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
181 im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
182 im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
183 im->ddr.sdram_mode = CFG_DDR_MODE;
184 im->ddr.sdram_mode2 = CFG_DDR_MODE2;
185 im->ddr.sdram_interval = CFG_DDR_INTERVAL;
186 im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
187#else
Dave Liua46daea2006-11-03 19:33:44 -0600188 im->ddr.csbnds[0].csbnds = 0x00000007;
189 im->ddr.csbnds[1].csbnds = 0x0008000f;
190
191 im->ddr.cs_config[0] = CFG_DDR_CONFIG;
192 im->ddr.cs_config[1] = CFG_DDR_CONFIG;
193
194 im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
195 im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
196 im->ddr.sdram_cfg = CFG_DDR_CONTROL;
197
198 im->ddr.sdram_mode = CFG_DDR_MODE;
199 im->ddr.sdram_interval = CFG_DDR_INTERVAL;
Xie Xiaobo6149a5a2007-02-14 18:27:17 +0800200#endif
Dave Liua46daea2006-11-03 19:33:44 -0600201 udelay(200);
202 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
203
204 return msize;
205}
206#endif /*!CFG_SPD_EEPROM */
207
208int checkboard(void)
209{
210 puts("Board: Freescale MPC8360EMDS\n");
211 return 0;
212}
213
214/*
215 * if MPC8360EMDS is soldered with SDRAM
216 */
217#if defined(CFG_BR2_PRELIM) \
218 && defined(CFG_OR2_PRELIM) \
219 && defined(CFG_LBLAWBAR2_PRELIM) \
220 && defined(CFG_LBLAWAR2_PRELIM)
221/*
222 * Initialize SDRAM memory on the Local Bus.
223 */
224
225void sdram_init(void)
226{
Timur Tabi386a2802006-11-03 12:00:28 -0600227 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -0600228 volatile lbus83xx_t *lbc = &immap->lbus;
229 uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
230
231 puts("\n SDRAM on Local Bus: ");
232 print_size(CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
233 /*
234 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
235 */
236 /*setup mtrpt, lsrt and lbcr for LB bus */
237 lbc->lbcr = CFG_LBC_LBCR;
238 lbc->mrtpr = CFG_LBC_MRTPR;
239 lbc->lsrt = CFG_LBC_LSRT;
240 asm("sync");
241
242 /*
243 * Configure the SDRAM controller Machine Mode Register.
244 */
245 lbc->lsdmr = CFG_LBC_LSDMR_5; /* Normal Operation */
246 lbc->lsdmr = CFG_LBC_LSDMR_1; /* Precharge All Banks */
247 asm("sync");
248 *sdram_addr = 0xff;
249 udelay(100);
250
251 /*
252 * We need do 8 times auto refresh operation.
253 */
254 lbc->lsdmr = CFG_LBC_LSDMR_2;
255 asm("sync");
256 *sdram_addr = 0xff; /* 1 times */
257 udelay(100);
258 *sdram_addr = 0xff; /* 2 times */
259 udelay(100);
260 *sdram_addr = 0xff; /* 3 times */
261 udelay(100);
262 *sdram_addr = 0xff; /* 4 times */
263 udelay(100);
264 *sdram_addr = 0xff; /* 5 times */
265 udelay(100);
266 *sdram_addr = 0xff; /* 6 times */
267 udelay(100);
268 *sdram_addr = 0xff; /* 7 times */
269 udelay(100);
270 *sdram_addr = 0xff; /* 8 times */
271 udelay(100);
272
273 /* Mode register write operation */
274 lbc->lsdmr = CFG_LBC_LSDMR_4;
275 asm("sync");
276 *(sdram_addr + 0xcc) = 0xff;
277 udelay(100);
278
279 /* Normal operation */
280 lbc->lsdmr = CFG_LBC_LSDMR_5 | 0x40000000;
281 asm("sync");
282 *sdram_addr = 0xff;
283 udelay(100);
284}
285#else
286void sdram_init(void)
287{
288 puts("SDRAM on Local Bus is NOT available!\n");
289}
290#endif
291
292#if defined(CONFIG_DDR_ECC) && defined(CONFIG_DDR_ECC_CMD)
293/*
294 * ECC user commands
295 */
296void ecc_print_status(void)
297{
Timur Tabi386a2802006-11-03 12:00:28 -0600298 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -0600299 volatile ddr83xx_t *ddr = &immap->ddr;
300
301 printf("\nECC mode: %s\n\n",
302 (ddr->sdram_cfg & SDRAM_CFG_ECC_EN) ? "ON" : "OFF");
303
304 /* Interrupts */
305 printf("Memory Error Interrupt Enable:\n");
306 printf(" Multiple-Bit Error Interrupt Enable: %d\n",
307 (ddr->err_int_en & ECC_ERR_INT_EN_MBEE) ? 1 : 0);
308 printf(" Single-Bit Error Interrupt Enable: %d\n",
309 (ddr->err_int_en & ECC_ERR_INT_EN_SBEE) ? 1 : 0);
310 printf(" Memory Select Error Interrupt Enable: %d\n\n",
311 (ddr->err_int_en & ECC_ERR_INT_EN_MSEE) ? 1 : 0);
312
313 /* Error disable */
314 printf("Memory Error Disable:\n");
315 printf(" Multiple-Bit Error Disable: %d\n",
316 (ddr->err_disable & ECC_ERROR_DISABLE_MBED) ? 1 : 0);
317 printf(" Sinle-Bit Error Disable: %d\n",
318 (ddr->err_disable & ECC_ERROR_DISABLE_SBED) ? 1 : 0);
319 printf(" Memory Select Error Disable: %d\n\n",
320 (ddr->err_disable & ECC_ERROR_DISABLE_MSED) ? 1 : 0);
321
322 /* Error injection */
323 printf("Memory Data Path Error Injection Mask High/Low: %08lx %08lx\n",
324 ddr->data_err_inject_hi, ddr->data_err_inject_lo);
325
326 printf("Memory Data Path Error Injection Mask ECC:\n");
327 printf(" ECC Mirror Byte: %d\n",
328 (ddr->ecc_err_inject & ECC_ERR_INJECT_EMB) ? 1 : 0);
329 printf(" ECC Injection Enable: %d\n",
330 (ddr->ecc_err_inject & ECC_ERR_INJECT_EIEN) ? 1 : 0);
331 printf(" ECC Error Injection Mask: 0x%02x\n\n",
332 ddr->ecc_err_inject & ECC_ERR_INJECT_EEIM);
333
334 /* SBE counter/threshold */
335 printf("Memory Single-Bit Error Management (0..255):\n");
336 printf(" Single-Bit Error Threshold: %d\n",
337 (ddr->err_sbe & ECC_ERROR_MAN_SBET) >> ECC_ERROR_MAN_SBET_SHIFT);
338 printf(" Single-Bit Error Counter: %d\n\n",
339 (ddr->err_sbe & ECC_ERROR_MAN_SBEC) >> ECC_ERROR_MAN_SBEC_SHIFT);
340
341 /* Error detect */
342 printf("Memory Error Detect:\n");
343 printf(" Multiple Memory Errors: %d\n",
344 (ddr->err_detect & ECC_ERROR_DETECT_MME) ? 1 : 0);
345 printf(" Multiple-Bit Error: %d\n",
346 (ddr->err_detect & ECC_ERROR_DETECT_MBE) ? 1 : 0);
347 printf(" Single-Bit Error: %d\n",
348 (ddr->err_detect & ECC_ERROR_DETECT_SBE) ? 1 : 0);
349 printf(" Memory Select Error: %d\n\n",
350 (ddr->err_detect & ECC_ERROR_DETECT_MSE) ? 1 : 0);
351
352 /* Capture data */
353 printf("Memory Error Address Capture: 0x%08lx\n", ddr->capture_address);
354 printf("Memory Data Path Read Capture High/Low: %08lx %08lx\n",
355 ddr->capture_data_hi, ddr->capture_data_lo);
356 printf("Memory Data Path Read Capture ECC: 0x%02x\n\n",
357 ddr->capture_ecc & CAPTURE_ECC_ECE);
358
359 printf("Memory Error Attributes Capture:\n");
360 printf(" Data Beat Number: %d\n",
361 (ddr->capture_attributes & ECC_CAPT_ATTR_BNUM) >>
362 ECC_CAPT_ATTR_BNUM_SHIFT);
363 printf(" Transaction Size: %d\n",
364 (ddr->capture_attributes & ECC_CAPT_ATTR_TSIZ) >>
365 ECC_CAPT_ATTR_TSIZ_SHIFT);
366 printf(" Transaction Source: %d\n",
367 (ddr->capture_attributes & ECC_CAPT_ATTR_TSRC) >>
368 ECC_CAPT_ATTR_TSRC_SHIFT);
369 printf(" Transaction Type: %d\n",
370 (ddr->capture_attributes & ECC_CAPT_ATTR_TTYP) >>
371 ECC_CAPT_ATTR_TTYP_SHIFT);
372 printf(" Error Information Valid: %d\n\n",
373 ddr->capture_attributes & ECC_CAPT_ATTR_VLD);
374}
375
376int do_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
377{
Timur Tabi386a2802006-11-03 12:00:28 -0600378 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -0600379 volatile ddr83xx_t *ddr = &immap->ddr;
380 volatile u32 val;
381 u64 *addr;
382 u32 count;
383 register u64 *i;
384 u32 ret[2];
385 u32 pattern[2];
386 u32 writeback[2];
387
388 /* The pattern is written into memory to generate error */
389 pattern[0] = 0xfedcba98UL;
390 pattern[1] = 0x76543210UL;
391
392 /* After injecting error, re-initialize the memory with the value */
393 writeback[0] = 0x01234567UL;
394 writeback[1] = 0x89abcdefUL;
395
396 if (argc > 4) {
397 printf("Usage:\n%s\n", cmdtp->usage);
398 return 1;
399 }
400
401 if (argc == 2) {
402 if (strcmp(argv[1], "status") == 0) {
403 ecc_print_status();
404 return 0;
405 } else if (strcmp(argv[1], "captureclear") == 0) {
406 ddr->capture_address = 0;
407 ddr->capture_data_hi = 0;
408 ddr->capture_data_lo = 0;
409 ddr->capture_ecc = 0;
410 ddr->capture_attributes = 0;
411 return 0;
412 }
413 }
414 if (argc == 3) {
415 if (strcmp(argv[1], "sbecnt") == 0) {
416 val = simple_strtoul(argv[2], NULL, 10);
417 if (val > 255) {
418 printf("Incorrect Counter value, "
419 "should be 0..255\n");
420 return 1;
421 }
422
423 val = (val << ECC_ERROR_MAN_SBEC_SHIFT);
424 val |= (ddr->err_sbe & ECC_ERROR_MAN_SBET);
425
426 ddr->err_sbe = val;
427 return 0;
428 } else if (strcmp(argv[1], "sbethr") == 0) {
429 val = simple_strtoul(argv[2], NULL, 10);
430 if (val > 255) {
431 printf("Incorrect Counter value, "
432 "should be 0..255\n");
433 return 1;
434 }
435
436 val = (val << ECC_ERROR_MAN_SBET_SHIFT);
437 val |= (ddr->err_sbe & ECC_ERROR_MAN_SBEC);
438
439 ddr->err_sbe = val;
440 return 0;
441 } else if (strcmp(argv[1], "errdisable") == 0) {
442 val = ddr->err_disable;
443
444 if (strcmp(argv[2], "+sbe") == 0) {
445 val |= ECC_ERROR_DISABLE_SBED;
446 } else if (strcmp(argv[2], "+mbe") == 0) {
447 val |= ECC_ERROR_DISABLE_MBED;
448 } else if (strcmp(argv[2], "+mse") == 0) {
449 val |= ECC_ERROR_DISABLE_MSED;
450 } else if (strcmp(argv[2], "+all") == 0) {
451 val |= (ECC_ERROR_DISABLE_SBED |
452 ECC_ERROR_DISABLE_MBED |
453 ECC_ERROR_DISABLE_MSED);
454 } else if (strcmp(argv[2], "-sbe") == 0) {
455 val &= ~ECC_ERROR_DISABLE_SBED;
456 } else if (strcmp(argv[2], "-mbe") == 0) {
457 val &= ~ECC_ERROR_DISABLE_MBED;
458 } else if (strcmp(argv[2], "-mse") == 0) {
459 val &= ~ECC_ERROR_DISABLE_MSED;
460 } else if (strcmp(argv[2], "-all") == 0) {
461 val &= ~(ECC_ERROR_DISABLE_SBED |
462 ECC_ERROR_DISABLE_MBED |
463 ECC_ERROR_DISABLE_MSED);
464 } else {
465 printf("Incorrect err_disable field\n");
466 return 1;
467 }
468
469 ddr->err_disable = val;
470 __asm__ __volatile__("sync");
471 __asm__ __volatile__("isync");
472 return 0;
473 } else if (strcmp(argv[1], "errdetectclr") == 0) {
474 val = ddr->err_detect;
475
476 if (strcmp(argv[2], "mme") == 0) {
477 val |= ECC_ERROR_DETECT_MME;
478 } else if (strcmp(argv[2], "sbe") == 0) {
479 val |= ECC_ERROR_DETECT_SBE;
480 } else if (strcmp(argv[2], "mbe") == 0) {
481 val |= ECC_ERROR_DETECT_MBE;
482 } else if (strcmp(argv[2], "mse") == 0) {
483 val |= ECC_ERROR_DETECT_MSE;
484 } else if (strcmp(argv[2], "all") == 0) {
485 val |= (ECC_ERROR_DETECT_MME |
486 ECC_ERROR_DETECT_MBE |
487 ECC_ERROR_DETECT_SBE |
488 ECC_ERROR_DETECT_MSE);
489 } else {
490 printf("Incorrect err_detect field\n");
491 return 1;
492 }
493
494 ddr->err_detect = val;
495 return 0;
496 } else if (strcmp(argv[1], "injectdatahi") == 0) {
497 val = simple_strtoul(argv[2], NULL, 16);
498
499 ddr->data_err_inject_hi = val;
500 return 0;
501 } else if (strcmp(argv[1], "injectdatalo") == 0) {
502 val = simple_strtoul(argv[2], NULL, 16);
503
504 ddr->data_err_inject_lo = val;
505 return 0;
506 } else if (strcmp(argv[1], "injectecc") == 0) {
507 val = simple_strtoul(argv[2], NULL, 16);
508 if (val > 0xff) {
509 printf("Incorrect ECC inject mask, "
510 "should be 0x00..0xff\n");
511 return 1;
512 }
513 val |= (ddr->ecc_err_inject & ~ECC_ERR_INJECT_EEIM);
514
515 ddr->ecc_err_inject = val;
516 return 0;
517 } else if (strcmp(argv[1], "inject") == 0) {
518 val = ddr->ecc_err_inject;
519
520 if (strcmp(argv[2], "en") == 0)
521 val |= ECC_ERR_INJECT_EIEN;
522 else if (strcmp(argv[2], "dis") == 0)
523 val &= ~ECC_ERR_INJECT_EIEN;
524 else
525 printf("Incorrect command\n");
526
527 ddr->ecc_err_inject = val;
528 __asm__ __volatile__("sync");
529 __asm__ __volatile__("isync");
530 return 0;
531 } else if (strcmp(argv[1], "mirror") == 0) {
532 val = ddr->ecc_err_inject;
533
534 if (strcmp(argv[2], "en") == 0)
535 val |= ECC_ERR_INJECT_EMB;
536 else if (strcmp(argv[2], "dis") == 0)
537 val &= ~ECC_ERR_INJECT_EMB;
538 else
539 printf("Incorrect command\n");
540
541 ddr->ecc_err_inject = val;
542 return 0;
543 }
544 }
545 if (argc == 4) {
546 if (strcmp(argv[1], "testdw") == 0) {
547 addr = (u64 *) simple_strtoul(argv[2], NULL, 16);
548 count = simple_strtoul(argv[3], NULL, 16);
549
550 if ((u32) addr % 8) {
551 printf("Address not alligned on "
552 "double word boundary\n");
553 return 1;
554 }
555 disable_interrupts();
556
557 for (i = addr; i < addr + count; i++) {
558
559 /* enable injects */
560 ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
561 __asm__ __volatile__("sync");
562 __asm__ __volatile__("isync");
563
564 /* write memory location injecting errors */
565 ppcDWstore((u32 *) i, pattern);
Dave Liu8c84e472006-11-02 18:05:50 -0600566 __asm__ __volatile__("sync");
Dave Liua46daea2006-11-03 19:33:44 -0600567
568 /* disable injects */
569 ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
570 __asm__ __volatile__("sync");
571 __asm__ __volatile__("isync");
572
573 /* read data, this generates ECC error */
574 ppcDWload((u32 *) i, ret);
Dave Liu8c84e472006-11-02 18:05:50 -0600575 __asm__ __volatile__("sync");
Dave Liua46daea2006-11-03 19:33:44 -0600576
577 /* re-initialize memory, double word write the location again,
578 * generates new ECC code this time */
579 ppcDWstore((u32 *) i, writeback);
Dave Liu8c84e472006-11-02 18:05:50 -0600580 __asm__ __volatile__("sync");
Dave Liua46daea2006-11-03 19:33:44 -0600581 }
582 enable_interrupts();
583 return 0;
584 }
585 if (strcmp(argv[1], "testword") == 0) {
586 addr = (u64 *) simple_strtoul(argv[2], NULL, 16);
587 count = simple_strtoul(argv[3], NULL, 16);
588
589 if ((u32) addr % 8) {
590 printf("Address not alligned on "
591 "double word boundary\n");
592 return 1;
593 }
594 disable_interrupts();
595
596 for (i = addr; i < addr + count; i++) {
597
598 /* enable injects */
599 ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
600 __asm__ __volatile__("sync");
601 __asm__ __volatile__("isync");
602
603 /* write memory location injecting errors */
604 *(u32 *) i = 0xfedcba98UL;
605 __asm__ __volatile__("sync");
606
607 /* sub double word write,
608 * bus will read-modify-write,
609 * generates ECC error */
610 *((u32 *) i + 1) = 0x76543210UL;
611 __asm__ __volatile__("sync");
612
613 /* disable injects */
614 ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
615 __asm__ __volatile__("sync");
616 __asm__ __volatile__("isync");
617
618 /* re-initialize memory,
619 * double word write the location again,
620 * generates new ECC code this time */
621 ppcDWstore((u32 *) i, writeback);
Dave Liu8c84e472006-11-02 18:05:50 -0600622 __asm__ __volatile__("sync");
Dave Liua46daea2006-11-03 19:33:44 -0600623 }
624 enable_interrupts();
625 return 0;
626 }
627 }
628 printf("Usage:\n%s\n", cmdtp->usage);
629 return 1;
630}
631
632U_BOOT_CMD(ecc, 4, 0, do_ecc,
633 "ecc - support for DDR ECC features\n",
634 "status - print out status info\n"
635 "ecc captureclear - clear capture regs data\n"
636 "ecc sbecnt <val> - set Single-Bit Error counter\n"
637 "ecc sbethr <val> - set Single-Bit Threshold\n"
638 "ecc errdisable <flag> - clear/set disable Memory Error Disable, flag:\n"
639 " [-|+]sbe - Single-Bit Error\n"
640 " [-|+]mbe - Multiple-Bit Error\n"
641 " [-|+]mse - Memory Select Error\n"
642 " [-|+]all - all errors\n"
643 "ecc errdetectclr <flag> - clear Memory Error Detect, flag:\n"
644 " mme - Multiple Memory Errors\n"
645 " sbe - Single-Bit Error\n"
646 " mbe - Multiple-Bit Error\n"
647 " mse - Memory Select Error\n"
648 " all - all errors\n"
649 "ecc injectdatahi <hi> - set Memory Data Path Error Injection Mask High\n"
650 "ecc injectdatalo <lo> - set Memory Data Path Error Injection Mask Low\n"
651 "ecc injectecc <ecc> - set ECC Error Injection Mask\n"
652 "ecc inject <en|dis> - enable/disable error injection\n"
653 "ecc mirror <en|dis> - enable/disable mirror byte\n"
654 "ecc testdw <addr> <cnt> - test mem region with double word access:\n"
655 " - enables injects\n"
656 " - writes pattern injecting errors with double word access\n"
657 " - disables injects\n"
658 " - reads pattern back with double word access, generates error\n"
659 " - re-inits memory\n"
660 "ecc testword <addr> <cnt> - test mem region with word access:\n"
661 " - enables injects\n"
662 " - writes pattern injecting errors with word access\n"
663 " - writes pattern with word access, generates error\n"
664 " - disables injects\n" " - re-inits memory");
665#endif /* if defined(CONFIG_DDR_ECC) && defined(CONFIG_DDR_ECC_CMD) */
Kim Phillips774e1b52006-11-01 00:10:40 -0600666
Gerald Van Barend6abef42007-03-31 12:23:51 -0400667#if (defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)) \
668 && defined(CONFIG_OF_BOARD_SETUP)
Gerald Van Barenc4a57ea2007-04-06 14:19:43 -0400669
670/*
671 * Prototypes of functions that we use.
672 */
673void ft_cpu_setup(void *blob, bd_t *bd);
674
675#ifdef CONFIG_PCI
676void ft_pci_setup(void *blob, bd_t *bd);
677#endif
678
Kim Phillips774e1b52006-11-01 00:10:40 -0600679void
680ft_board_setup(void *blob, bd_t *bd)
681{
Gerald Van Barend6abef42007-03-31 12:23:51 -0400682#if defined(CONFIG_OF_LIBFDT)
683 int nodeoffset;
Gerald Van Barend6abef42007-03-31 12:23:51 -0400684 int tmp[2];
685
686 nodeoffset = fdt_path_offset (fdt, "/memory");
687 if (nodeoffset >= 0) {
688 tmp[0] = cpu_to_be32(bd->bi_memstart);
689 tmp[1] = cpu_to_be32(bd->bi_memsize);
Gerald Van Barenc4a57ea2007-04-06 14:19:43 -0400690 fdt_setprop(fdt, nodeoffset, "reg", tmp, sizeof(tmp));
Gerald Van Barend6abef42007-03-31 12:23:51 -0400691 }
692#else
Kim Phillips774e1b52006-11-01 00:10:40 -0600693 u32 *p;
694 int len;
695
Kim Phillips774e1b52006-11-01 00:10:40 -0600696 p = ft_get_prop(blob, "/memory/reg", &len);
697 if (p != NULL) {
698 *p++ = cpu_to_be32(bd->bi_memstart);
699 *p = cpu_to_be32(bd->bi_memsize);
700 }
Gerald Van Barend6abef42007-03-31 12:23:51 -0400701#endif
702
703#ifdef CONFIG_PCI
704 ft_pci_setup(blob, bd);
705#endif
706 ft_cpu_setup(blob, bd);
Kim Phillips774e1b52006-11-01 00:10:40 -0600707}
Gerald Van Barenc4a57ea2007-04-06 14:19:43 -0400708#endif /* CONFIG_OF_x */