nand:lpc32xx:NAND Flash ECC correction fixes
authorJeanPhilippeEIMER <JeanPhilippeEIMER@xxx.com>
Tue, 20 Mar 2012 10:12:14 +0000 (10:12 +0000)
committerBangaragiri G <bangaragiri.g@nxp.com>
Tue, 20 Mar 2012 10:12:14 +0000 (10:12 +0000)
In NAND Flash driver, the ECC correcrion function added so that
the ECC can be corrected for the whole page.

Signed-off-by: Bangaragiri G <bangaragiri.g@nxp.com>

drivers/mtd/nand/lpc32xx_nand.c

index e6821eb..daf0a05 100644 (file)
@@ -352,6 +352,40 @@ static void lpc32xx_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
        lpc32xx_nand_xfer(mtd, buf, len, 0);
 }
 
+/**
+ * lpc32xx_correct_data - [NAND Interface] Detect and correct bit error(s)
+ * mtd:        MTD block structure
+ * dat:        raw data read from the chip
+ * read_ecc:   ECC from the chip
+ * calc_ecc:   the ECC calculated from raw data
+ *
+ * Detect and correct a 1 bit error for 256 byte block
+ *
+ */
+int lpc32xx_correct_data(struct mtd_info *mtd, u_char *dat,
+                     u_char *read_ecc, u_char *calc_ecc)
+{
+       uint8_t i, nb_ecc256;
+       int     ret1, ret2 = 0;
+       u_char  *r = read_ecc;
+       u_char  *c = calc_ecc;
+       uint16_t        data_offset = 0;
+
+       nb_ecc256 = (CONFIG_SYS_NAND_ECCSIZE == NAND_LARGE_BLOCK_PAGE_SIZE ? 8 : 2);
+
+       for( i = 0 ; i < nb_ecc256 ; i++ , r += 3, c += 3, data_offset += 256 )
+       {
+               ret1 = nand_correct_data(mtd, dat + data_offset, r, c);
+
+               if( ret1 < 0 )
+                       return -EBADMSG;
+               else
+                       ret2 += ret1;
+       }
+
+       return(ret2);
+}
+
 /*
  * lpc32xx_read_buf - [DEFAULT] read chip data into buffer
  * mtd:        MTD device structure
@@ -387,7 +421,7 @@ int board_nand_init(struct nand_chip *nand)
                nand->ecc.layout = &lpc32xx_nand_oob_16;
 
        nand->ecc.calculate = lpc32xx_ecc_calculate;
-       nand->ecc.correct = nand_correct_data;
+       nand->ecc.correct = lpc32xx_correct_data;
        nand->ecc.hwctl = lpc32xx_hwecc_enable;
        nand->cmd_ctrl = lpc32xx_nand_hwcontrol;
        nand->dev_ready = lpc32xx_nand_ready;