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