[MTD] OneNAND: Single bit error detection

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Nov 28 19:59:02 EST 2006


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=f4f91ac3c833abbd7181ff2122c6b48a653b4e55
Commit:     f4f91ac3c833abbd7181ff2122c6b48a653b4e55
Parent:     08f782b60a633cbd926ef5e49de303a752390719
commit f4f91ac3c833abbd7181ff2122c6b48a653b4e55
Author:     Kyungmin Park <kyungmin.park at samsung.com>
AuthorDate: Thu Nov 16 12:03:56 2006 +0900
Commit:     Kyungmin Park <kyungmin.park at samsung.com>
CommitDate: Thu Nov 16 12:03:56 2006 +0900

    [MTD] OneNAND: Single bit error detection
    
    Idea from Jarkko Lavinen
    
    Signed-off-by: Jarkko Lavinen <jarkko.lavinen at nokia.com>
    Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
---
 drivers/mtd/onenand/onenand_base.c |   18 +++++++++++++-----
 drivers/mtd/onenand/onenand_bbt.c  |    1 +
 include/linux/mtd/onenand_regs.h   |    1 +
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index bef4f26..fc84ddc 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -331,9 +331,12 @@ static int onenand_wait(struct mtd_info 
 
 	if (interrupt & ONENAND_INT_READ) {
 		ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
-		if (ecc & ONENAND_ECC_2BIT_ALL) {
+		if (ecc) {
 			DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc);
-			return -EBADMSG;
+			if (ecc & ONENAND_ECC_2BIT_ALL)
+				mtd->ecc_stats.failed++;
+			else if (ecc & ONENAND_ECC_1BIT_ALL)
+				mtd->ecc_stats.corrected++;
 		}
 	}
 
@@ -715,6 +718,7 @@ static int onenand_read(struct mtd_info 
 	size_t *retlen, u_char *buf)
 {
 	struct onenand_chip *this = mtd->priv;
+	struct mtd_ecc_stats stats;
 	int read = 0, column;
 	int thislen;
 	int ret = 0;
@@ -733,6 +737,7 @@ static int onenand_read(struct mtd_info 
 
 	/* TODO handling oob */
 
+	stats = mtd->ecc_stats;
 	while (read < len) {
 		thislen = min_t(int, mtd->writesize, len - read);
 
@@ -774,7 +779,11 @@ out:
 	 * retlen == desired len and result == -EBADMSG
 	 */
 	*retlen = read;
-	return ret;
+
+	if (mtd->ecc_stats.failed - stats.failed)
+		return -EBADMSG;
+
+	return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;
 }
 
 /**
@@ -1390,7 +1399,6 @@ static int onenand_lock(struct mtd_info 
 	return onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_LOCK);
 }
 
-
 /**
  * onenand_unlock - [MTD Interface] Unlock block(s)
  * @param mtd		MTD device structure
@@ -1900,7 +1908,7 @@ static int onenand_probe(struct mtd_info
 	/* Read manufacturer and device IDs from Register */
 	maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
 	dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
-	ver_id= this->read_word(this->base + ONENAND_REG_VERSION_ID);
+	ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
 
 	/* Check OneNAND device */
 	if (maf_id != bram_maf_id || dev_id != bram_dev_id)
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 1b00dac..c8067b8 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -100,6 +100,7 @@ static int create_bbt(struct mtd_info *m
 				bbm->bbt[i >> 3] |= 0x03 << (i & 0x6);
 				printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
 					i >> 1, (unsigned int) from);
+				mtd->ecc_stats.badblocks++;
 				break;
 			}
 		}
diff --git a/include/linux/mtd/onenand_regs.h b/include/linux/mtd/onenand_regs.h
index 9e409fe..e31c8f5 100644
--- a/include/linux/mtd/onenand_regs.h
+++ b/include/linux/mtd/onenand_regs.h
@@ -179,6 +179,7 @@ #define ONENAND_WP_LTS			(1 << 0)
  * ECC Status Reigser FF00h (R)
  */
 #define ONENAND_ECC_1BIT		(1 << 0)
+#define ONENAND_ECC_1BIT_ALL		(0x5555)
 #define ONENAND_ECC_2BIT		(1 << 1)
 #define ONENAND_ECC_2BIT_ALL		(0xAAAA)
 



More information about the linux-mtd-cvs mailing list