Skip to content

Commit 785818f

Browse files
tpetazzoniBoris Brezillon
authored andcommitted
mtd: nand: add core support for on-die ECC
A number of NAND flashes have a capability called "on-die ECC" where the NAND chip itself is capable of detecting and correcting errors. Linux already has support for using the ECC implementation of the NAND controller, or a software based ECC implementation, but not for using the ECC implementation of the NAND controller. However, such an implementation is sometimes useful in situations where the NAND controller provides ECC algorithms that are not strong enough for the NAND chip used on the system. A typical case is a NAND chip that requires a 4-bit ECC, while the NAND controller only provides a 1-bit ECC algorithm. This commit introduces the support for the NAND_ECC_ON_DIE ECC mode: - Parsing of the "on-die" value for the "nand-ecc-mode" Device Tree property - Handling NAND_ECC_ON_DIE case in nand_scan_tail(). The idea is that the vendor specific code for the NAND chip must implement ->read_page() and ->write_page(). It may optionally provide its own ->read_page_raw() and ->write_page_raw() as well. For OOB operation, we assume the standard operations are good enough, but they can be overridden by the vendor specific code if needed. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Reviewed-by: Richard Weinberger <richard@nod.at> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
1 parent 85f94b5 commit 785818f

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,6 +4177,7 @@ static const char * const nand_ecc_modes[] = {
41774177
[NAND_ECC_HW] = "hw",
41784178
[NAND_ECC_HW_SYNDROME] = "hw_syndrome",
41794179
[NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
4180+
[NAND_ECC_ON_DIE] = "on-die",
41804181
};
41814182

41824183
static int of_get_nand_ecc_mode(struct device_node *np)
@@ -4717,6 +4718,18 @@ int nand_scan_tail(struct mtd_info *mtd)
47174718
}
47184719
break;
47194720

4721+
case NAND_ECC_ON_DIE:
4722+
if (!ecc->read_page || !ecc->write_page) {
4723+
WARN(1, "No ECC functions supplied; on-die ECC not possible\n");
4724+
ret = -EINVAL;
4725+
goto err_free;
4726+
}
4727+
if (!ecc->read_oob)
4728+
ecc->read_oob = nand_read_oob_std;
4729+
if (!ecc->write_oob)
4730+
ecc->write_oob = nand_write_oob_std;
4731+
break;
4732+
47204733
case NAND_ECC_NONE:
47214734
pr_warn("NAND_ECC_NONE selected by board driver. This is not recommended!\n");
47224735
ecc->read_page = nand_read_page_raw;

‎include/linux/mtd/nand.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ typedef enum {
116116
NAND_ECC_HW,
117117
NAND_ECC_HW_SYNDROME,
118118
NAND_ECC_HW_OOB_FIRST,
119+
NAND_ECC_ON_DIE,
119120
} nand_ecc_modes_t;
120121

121122
enum nand_ecc_algo {

0 commit comments

Comments
 (0)