3 * Eastman Kodak Company, <www.kodak.com>
4 * Michael Zaidman, <michael.zaidman@kodak.com>
6 * The code is based on the cpu/mpc83xx/ecc.c written by
7 * Dave Liu <daveliu@freescale.com>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 #if CONFIG_POST & CONFIG_SYS_POST_ECC
36 * We use the RAW I/O accessors where possible in order to
37 * achieve performance goal, since the test's execution time
38 * affects the board start up time.
40 static inline void ecc_clear(ddr83xx_t *ddr)
42 /* Clear capture registers */
43 __raw_writel(0, &ddr->capture_address);
44 __raw_writel(0, &ddr->capture_data_hi);
45 __raw_writel(0, &ddr->capture_data_lo);
46 __raw_writel(0, &ddr->capture_ecc);
47 __raw_writel(0, &ddr->capture_attributes);
49 /* Clear SBEC and set SBET to 1 */
50 out_be32(&ddr->err_sbe, 1 << ECC_ERROR_MAN_SBET_SHIFT);
52 /* Clear Error Detect register */
53 out_be32(&ddr->err_detect, ECC_ERROR_DETECT_MME |\
54 ECC_ERROR_DETECT_MBE |\
55 ECC_ERROR_DETECT_SBE |\
56 ECC_ERROR_DETECT_MSE);
61 int ecc_post_test(int flags)
66 u32 pattern[2], writeback[2], retval[2];
67 ddr83xx_t *ddr = &((immap_t *)CONFIG_SYS_IMMR)->ddr;
68 volatile u64 *addr = (u64 *)CONFIG_SYS_POST_ECC_START_ADDR;
70 /* The pattern is written into memory to generate error */
71 pattern[0] = 0xfedcba98UL;
72 pattern[1] = 0x76543210UL;
74 /* After injecting error, re-initialize the memory with the value */
75 writeback[0] = ~pattern[0];
76 writeback[1] = ~pattern[1];
78 /* Check if ECC is enabled */
79 if (__raw_readl(&ddr->err_disable) & ECC_ERROR_ENABLE) {
80 debug("DDR's ECC is not enabled, skipping the ECC POST.\n");
84 int_state = disable_interrupts();
87 #ifdef CONFIG_DDR_32BIT
88 /* It seems like no one really uses the CONFIG_DDR_32BIT mode */
89 #error "Add ECC POST support for CONFIG_DDR_32BIT here!"
91 for (addr = (u64*)CONFIG_SYS_POST_ECC_START_ADDR, errbit=0;
92 addr < (u64*)CONFIG_SYS_POST_ECC_STOP_ADDR; addr++, errbit++ ) {
98 /* Enable error injection */
99 setbits_be32(&ddr->ecc_err_inject, ECC_ERR_INJECT_EIEN);
103 /* Set bit to be injected */
105 __raw_writel(1 << errbit, &ddr->data_err_inject_lo);
106 __raw_writel(0, &ddr->data_err_inject_hi);
108 __raw_writel(0, &ddr->data_err_inject_lo);
109 __raw_writel(1<<(errbit-32), &ddr->data_err_inject_hi);
114 /* Write memory location injecting SBE */
115 ppcDWstore((u32*)addr, pattern);
118 /* Disable error injection */
119 clrbits_be32(&ddr->ecc_err_inject, ECC_ERR_INJECT_EIEN);
123 /* Data read should generate SBE */
124 ppcDWload((u32*)addr, retval);
127 if (!(__raw_readl(&ddr->err_detect) & ECC_ERROR_DETECT_SBE) ||
128 (__raw_readl(&ddr->data_err_inject_hi) !=
129 (__raw_readl(&ddr->capture_data_hi) ^ pattern[0])) ||
130 (__raw_readl(&ddr->data_err_inject_lo) !=
131 (__raw_readl(&ddr->capture_data_lo) ^ pattern[1]))) {
133 post_log("ECC failed to detect SBE error at %08x, "
134 "SBE injection mask %08x-%08x, wrote "
135 "%08x-%08x, read %08x-%08x\n", addr,
136 ddr->data_err_inject_hi,
137 ddr->data_err_inject_lo,
138 pattern[0], pattern[1],
139 retval[0], retval[1]);
141 printf("ERR_DETECT Reg: %08x\n", ddr->err_detect);
142 printf("ECC CAPTURE_DATA Reg: %08x-%08x\n",
143 ddr->capture_data_hi, ddr->capture_data_lo);
148 /* Re-initialize the ECC memory */
149 ppcDWstore((u32*)addr, writeback);
155 #endif /* !CONFIG_DDR_32BIT */