[PATCH 2/3] mtd: nand: set ECC algorithm in nand_dt_init

Rafał Miłecki zajec5 at gmail.com
Tue Mar 22 15:54:13 PDT 2016


Right now we set it based on "nand-ecc-mode" property value. At some
point we will most likely want a new property, but we'll need to keep
backward compatibility, so such code will be needed anyway.

Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
---
 drivers/mtd/nand/nand_base.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index f2c8ff3..75c5564 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3979,7 +3979,7 @@ ident_done:
 static int nand_dt_init(struct nand_chip *chip)
 {
 	struct device_node *dn = nand_get_flash_node(chip);
-	int ecc_mode, ecc_strength, ecc_step;
+	int ecc_mode, ecc_algo, ecc_strength, ecc_step;
 
 	if (!dn)
 		return 0;
@@ -3991,6 +3991,16 @@ static int nand_dt_init(struct nand_chip *chip)
 		chip->bbt_options |= NAND_BBT_USE_FLASH;
 
 	ecc_mode = of_get_nand_ecc_mode(dn);
+	switch (ecc_mode) {
+	case NAND_ECC_SOFT:
+		ecc_algo = NAND_ECC_HAMMING;
+		break;
+	case NAND_ECC_SOFT_BCH:
+		ecc_algo = NAND_ECC_BCH;
+		break;
+	default:
+		ecc_algo = -1;
+	}
 	ecc_strength = of_get_nand_ecc_strength(dn);
 	ecc_step = of_get_nand_ecc_step_size(dn);
 
@@ -4003,6 +4013,9 @@ static int nand_dt_init(struct nand_chip *chip)
 	if (ecc_mode >= 0)
 		chip->ecc.mode = ecc_mode;
 
+	if (ecc_algo >= 0)
+		chip->ecc.algo = ecc_algo;
+
 	if (ecc_strength >= 0)
 		chip->ecc.strength = ecc_strength;
 
-- 
1.8.4.5




More information about the linux-mtd mailing list