3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
28 #include <asm/mpc8349_pci.h>
33 #if defined(CONFIG_SPD_EEPROM)
34 #include <spd_sdram.h>
36 int fixed_sdram(void);
37 void sdram_init(void);
39 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
40 void ddr_enable_ecc(unsigned int dram_size);
43 int board_early_init_f (void)
45 volatile u8* bcsr = (volatile u8*)CFG_BCSR;
47 /* Enable flash write */
50 #ifdef CFG_USE_MPC834XSYS_USB_PHY
51 /* Use USB PHY on SYS board */
58 #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
60 long int initdram (int board_type)
62 volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
65 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
68 puts("Initializing\n");
70 /* DDR SDRAM - Main SODIMM */
71 im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
72 #if defined(CONFIG_SPD_EEPROM)
75 msize = fixed_sdram();
78 * Initialize SDRAM if it is on local bus.
82 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
84 * Initialize and enable DDR ECC.
86 ddr_enable_ecc(msize * 1024 * 1024);
89 /* return total bus SDRAM size(bytes) -- DDR */
90 return (msize * 1024 * 1024);
93 #if !defined(CONFIG_SPD_EEPROM)
94 /*************************************************************************
95 * fixed sdram init -- doesn't use serial presence detect.
96 ************************************************************************/
99 volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
104 msize = CFG_DDR_SIZE;
105 for (ddr_size = msize << 20, ddr_size_log2 = 0;
107 ddr_size = ddr_size>>1, ddr_size_log2++) {
112 im->sysconf.ddrlaw[0].bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff);
113 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
115 #if (CFG_DDR_SIZE != 256)
116 #warning Currenly any ddr size other than 256 is not supported
118 im->ddr.csbnds[2].csbnds = 0x0000000f;
119 im->ddr.cs_config[2] = CFG_DDR_CONFIG;
121 /* currently we use only one CS, so disable the other banks */
122 im->ddr.cs_config[0] = 0;
123 im->ddr.cs_config[1] = 0;
124 im->ddr.cs_config[3] = 0;
126 im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
127 im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
131 #if defined(CONFIG_DDR_2T_TIMING)
134 | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
135 #if defined (CONFIG_DDR_32BIT)
136 /* for 32-bit mode burst length is 8 */
137 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
139 im->ddr.sdram_mode = CFG_DDR_MODE;
141 im->ddr.sdram_interval = CFG_DDR_INTERVAL;
144 /* enable DDR controller */
145 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
148 #endif/*!CFG_SPD_EEPROM*/
151 int checkboard (void)
153 puts("Board: Freescale MPC8349EMDS\n");
158 * if MPC8349EMDS is soldered with SDRAM
160 #if defined(CFG_BR2_PRELIM) \
161 && defined(CFG_OR2_PRELIM) \
162 && defined(CFG_LBLAWBAR2_PRELIM) \
163 && defined(CFG_LBLAWAR2_PRELIM)
165 * Initialize SDRAM memory on the Local Bus.
168 void sdram_init(void)
170 volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
171 volatile lbus83xx_t *lbc= &immap->lbus;
172 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
174 puts("\n SDRAM on Local Bus: ");
175 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
178 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
181 /* setup mtrpt, lsrt and lbcr for LB bus */
182 lbc->lbcr = CFG_LBC_LBCR;
183 lbc->mrtpr = CFG_LBC_MRTPR;
184 lbc->lsrt = CFG_LBC_LSRT;
188 * Configure the SDRAM controller Machine Mode Register.
190 lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
192 lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
197 lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
224 /* 0x58636733; mode register write operation */
225 lbc->lsdmr = CFG_LBC_LSDMR_4;
230 lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
236 void sdram_init(void)
238 put("SDRAM on Local Bus is NOT available!\n");
242 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_DDR_ECC_CMD)
246 void ecc_print_status(void)
248 volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
249 volatile ddr83xx_t *ddr = &immap->ddr;
251 printf("\nECC mode: %s\n\n", (ddr->sdram_cfg & SDRAM_CFG_ECC_EN) ? "ON" : "OFF");
254 printf("Memory Error Interrupt Enable:\n");
255 printf(" Multiple-Bit Error Interrupt Enable: %d\n",
256 (ddr->err_int_en & ECC_ERR_INT_EN_MBEE) ? 1 : 0);
257 printf(" Single-Bit Error Interrupt Enable: %d\n",
258 (ddr->err_int_en & ECC_ERR_INT_EN_SBEE) ? 1 : 0);
259 printf(" Memory Select Error Interrupt Enable: %d\n\n",
260 (ddr->err_int_en & ECC_ERR_INT_EN_MSEE) ? 1 : 0);
263 printf("Memory Error Disable:\n");
264 printf(" Multiple-Bit Error Disable: %d\n",
265 (ddr->err_disable & ECC_ERROR_DISABLE_MBED) ? 1 : 0);
266 printf(" Sinle-Bit Error Disable: %d\n",
267 (ddr->err_disable & ECC_ERROR_DISABLE_SBED) ? 1 : 0);
268 printf(" Memory Select Error Disable: %d\n\n",
269 (ddr->err_disable & ECC_ERROR_DISABLE_MSED) ? 1 : 0);
271 /* Error injection */
272 printf("Memory Data Path Error Injection Mask High/Low: %08lx %08lx\n",
273 ddr->data_err_inject_hi, ddr->data_err_inject_lo);
275 printf("Memory Data Path Error Injection Mask ECC:\n");
276 printf(" ECC Mirror Byte: %d\n",
277 (ddr->ecc_err_inject & ECC_ERR_INJECT_EMB) ? 1 : 0);
278 printf(" ECC Injection Enable: %d\n",
279 (ddr->ecc_err_inject & ECC_ERR_INJECT_EIEN) ? 1 : 0);
280 printf(" ECC Error Injection Mask: 0x%02x\n\n",
281 ddr->ecc_err_inject & ECC_ERR_INJECT_EEIM);
283 /* SBE counter/threshold */
284 printf("Memory Single-Bit Error Management (0..255):\n");
285 printf(" Single-Bit Error Threshold: %d\n",
286 (ddr->err_sbe & ECC_ERROR_MAN_SBET) >> ECC_ERROR_MAN_SBET_SHIFT);
287 printf(" Single-Bit Error Counter: %d\n\n",
288 (ddr->err_sbe & ECC_ERROR_MAN_SBEC) >> ECC_ERROR_MAN_SBEC_SHIFT);
291 printf("Memory Error Detect:\n");
292 printf(" Multiple Memory Errors: %d\n",
293 (ddr->err_detect & ECC_ERROR_DETECT_MME) ? 1 : 0);
294 printf(" Multiple-Bit Error: %d\n",
295 (ddr->err_detect & ECC_ERROR_DETECT_MBE) ? 1 : 0);
296 printf(" Single-Bit Error: %d\n",
297 (ddr->err_detect & ECC_ERROR_DETECT_SBE) ? 1 : 0);
298 printf(" Memory Select Error: %d\n\n",
299 (ddr->err_detect & ECC_ERROR_DETECT_MSE) ? 1 : 0);
302 printf("Memory Error Address Capture: 0x%08lx\n", ddr->capture_address);
303 printf("Memory Data Path Read Capture High/Low: %08lx %08lx\n",
304 ddr->capture_data_hi, ddr->capture_data_lo);
305 printf("Memory Data Path Read Capture ECC: 0x%02x\n\n",
306 ddr->capture_ecc & CAPTURE_ECC_ECE);
308 printf("Memory Error Attributes Capture:\n");
309 printf(" Data Beat Number: %d\n",
310 (ddr->capture_attributes & ECC_CAPT_ATTR_BNUM) >> ECC_CAPT_ATTR_BNUM_SHIFT);
311 printf(" Transaction Size: %d\n",
312 (ddr->capture_attributes & ECC_CAPT_ATTR_TSIZ) >> ECC_CAPT_ATTR_TSIZ_SHIFT);
313 printf(" Transaction Source: %d\n",
314 (ddr->capture_attributes & ECC_CAPT_ATTR_TSRC) >> ECC_CAPT_ATTR_TSRC_SHIFT);
315 printf(" Transaction Type: %d\n",
316 (ddr->capture_attributes & ECC_CAPT_ATTR_TTYP) >> ECC_CAPT_ATTR_TTYP_SHIFT);
317 printf(" Error Information Valid: %d\n\n",
318 ddr->capture_attributes & ECC_CAPT_ATTR_VLD);
321 int do_ecc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
323 volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
324 volatile ddr83xx_t *ddr = &immap->ddr;
326 u64 *addr, count, val64;
330 printf ("Usage:\n%s\n", cmdtp->usage);
335 if (strcmp(argv[1], "status") == 0) {
338 } else if (strcmp(argv[1], "captureclear") == 0) {
339 ddr->capture_address = 0;
340 ddr->capture_data_hi = 0;
341 ddr->capture_data_lo = 0;
342 ddr->capture_ecc = 0;
343 ddr->capture_attributes = 0;
349 if (strcmp(argv[1], "sbecnt") == 0) {
350 val = simple_strtoul(argv[2], NULL, 10);
352 printf("Incorrect Counter value, should be 0..255\n");
356 val = (val << ECC_ERROR_MAN_SBEC_SHIFT);
357 val |= (ddr->err_sbe & ECC_ERROR_MAN_SBET);
361 } else if (strcmp(argv[1], "sbethr") == 0) {
362 val = simple_strtoul(argv[2], NULL, 10);
364 printf("Incorrect Counter value, should be 0..255\n");
368 val = (val << ECC_ERROR_MAN_SBET_SHIFT);
369 val |= (ddr->err_sbe & ECC_ERROR_MAN_SBEC);
373 } else if (strcmp(argv[1], "errdisable") == 0) {
374 val = ddr->err_disable;
376 if (strcmp(argv[2], "+sbe") == 0) {
377 val |= ECC_ERROR_DISABLE_SBED;
378 } else if (strcmp(argv[2], "+mbe") == 0) {
379 val |= ECC_ERROR_DISABLE_MBED;
380 } else if (strcmp(argv[2], "+mse") == 0) {
381 val |= ECC_ERROR_DISABLE_MSED;
382 } else if (strcmp(argv[2], "+all") == 0) {
383 val |= (ECC_ERROR_DISABLE_SBED |
384 ECC_ERROR_DISABLE_MBED |
385 ECC_ERROR_DISABLE_MSED);
386 } else if (strcmp(argv[2], "-sbe") == 0) {
387 val &= ~ECC_ERROR_DISABLE_SBED;
388 } else if (strcmp(argv[2], "-mbe") == 0) {
389 val &= ~ECC_ERROR_DISABLE_MBED;
390 } else if (strcmp(argv[2], "-mse") == 0) {
391 val &= ~ECC_ERROR_DISABLE_MSED;
392 } else if (strcmp(argv[2], "-all") == 0) {
393 val &= ~(ECC_ERROR_DISABLE_SBED |
394 ECC_ERROR_DISABLE_MBED |
395 ECC_ERROR_DISABLE_MSED);
397 printf("Incorrect err_disable field\n");
401 ddr->err_disable = val;
402 __asm__ __volatile__ ("sync");
403 __asm__ __volatile__ ("isync");
405 } else if (strcmp(argv[1], "errdetectclr") == 0) {
406 val = ddr->err_detect;
408 if (strcmp(argv[2], "mme") == 0) {
409 val |= ECC_ERROR_DETECT_MME;
410 } else if (strcmp(argv[2], "sbe") == 0) {
411 val |= ECC_ERROR_DETECT_SBE;
412 } else if (strcmp(argv[2], "mbe") == 0) {
413 val |= ECC_ERROR_DETECT_MBE;
414 } else if (strcmp(argv[2], "mse") == 0) {
415 val |= ECC_ERROR_DETECT_MSE;
416 } else if (strcmp(argv[2], "all") == 0) {
417 val |= (ECC_ERROR_DETECT_MME |
418 ECC_ERROR_DETECT_MBE |
419 ECC_ERROR_DETECT_SBE |
420 ECC_ERROR_DETECT_MSE);
422 printf("Incorrect err_detect field\n");
426 ddr->err_detect = val;
428 } else if (strcmp(argv[1], "injectdatahi") == 0) {
429 val = simple_strtoul(argv[2], NULL, 16);
431 ddr->data_err_inject_hi = val;
433 } else if (strcmp(argv[1], "injectdatalo") == 0) {
434 val = simple_strtoul(argv[2], NULL, 16);
436 ddr->data_err_inject_lo = val;
438 } else if (strcmp(argv[1], "injectecc") == 0) {
439 val = simple_strtoul(argv[2], NULL, 16);
441 printf("Incorrect ECC inject mask, should be 0x00..0xff\n");
444 val |= (ddr->ecc_err_inject & ~ECC_ERR_INJECT_EEIM);
446 ddr->ecc_err_inject = val;
448 } else if (strcmp(argv[1], "inject") == 0) {
449 val = ddr->ecc_err_inject;
451 if (strcmp(argv[2], "en") == 0)
452 val |= ECC_ERR_INJECT_EIEN;
453 else if (strcmp(argv[2], "dis") == 0)
454 val &= ~ECC_ERR_INJECT_EIEN;
456 printf("Incorrect command\n");
458 ddr->ecc_err_inject = val;
459 __asm__ __volatile__ ("sync");
460 __asm__ __volatile__ ("isync");
462 } else if (strcmp(argv[1], "mirror") == 0) {
463 val = ddr->ecc_err_inject;
465 if (strcmp(argv[2], "en") == 0)
466 val |= ECC_ERR_INJECT_EMB;
467 else if (strcmp(argv[2], "dis") == 0)
468 val &= ~ECC_ERR_INJECT_EMB;
470 printf("Incorrect command\n");
472 ddr->ecc_err_inject = val;
478 if (strcmp(argv[1], "test") == 0) {
479 addr = (u64 *)simple_strtoul(argv[2], NULL, 16);
480 count = simple_strtoul(argv[3], NULL, 16);
483 printf("Address not alligned on double word boundary\n");
487 disable_interrupts();
490 for (i = addr; i < addr + count; i++) {
492 ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
493 __asm__ __volatile__ ("sync");
494 __asm__ __volatile__ ("isync");
496 /* write memory location injecting errors */
497 *i = 0x1122334455667788ULL;
498 __asm__ __volatile__ ("sync");
500 /* disable injects */
501 ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
502 __asm__ __volatile__ ("sync");
503 __asm__ __volatile__ ("isync");
505 /* read data, this generates ECC error */
507 __asm__ __volatile__ ("sync");
509 /* disable errors for ECC */
510 ddr->err_disable |= ~ECC_ERROR_ENABLE;
511 __asm__ __volatile__ ("sync");
512 __asm__ __volatile__ ("isync");
514 /* re-initialize memory, write the location again
515 * NOT injecting errors this time */
516 *i = 0xcafecafecafecafeULL;
517 __asm__ __volatile__ ("sync");
519 /* enable errors for ECC */
520 ddr->err_disable &= ECC_ERROR_ENABLE;
521 __asm__ __volatile__ ("sync");
522 __asm__ __volatile__ ("isync");
532 printf ("Usage:\n%s\n", cmdtp->usage);
538 "ecc - support for DDR ECC features\n",
539 "status - print out status info\n"
540 "ecc captureclear - clear capture regs data\n"
541 "ecc sbecnt <val> - set Single-Bit Error counter\n"
542 "ecc sbethr <val> - set Single-Bit Threshold\n"
543 "ecc errdisable <flag> - clear/set disable Memory Error Disable, flag:\n"
544 " [-|+]sbe - Single-Bit Error\n"
545 " [-|+]mbe - Multiple-Bit Error\n"
546 " [-|+]mse - Memory Select Error\n"
547 " [-|+]all - all errors\n"
548 "ecc errdetectclr <flag> - clear Memory Error Detect, flag:\n"
549 " mme - Multiple Memory Errors\n"
550 " sbe - Single-Bit Error\n"
551 " mbe - Multiple-Bit Error\n"
552 " mse - Memory Select Error\n"
553 " all - all errors\n"
554 "ecc injectdatahi <hi> - set Memory Data Path Error Injection Mask High\n"
555 "ecc injectdatalo <lo> - set Memory Data Path Error Injection Mask Low\n"
556 "ecc injectecc <ecc> - set ECC Error Injection Mask\n"
557 "ecc inject <en|dis> - enable/disable error injection\n"
558 "ecc mirror <en|dis> - enable/disable mirror byte\n"
559 "ecc test <addr> <cnt> - test mem region:\n"
560 " - enables injects\n"
561 " - writes pattern injecting errors\n"
562 " - disables injects\n"
563 " - reads pattern back, generates error\n"
566 #endif /* if defined(CONFIG_DDR_ECC) && defined(CONFIG_DDR_ECC_CMD) */