Skip to content

Commit 3aee8a3

Browse files
fabioestevammiquelraynal
authored andcommitted
mtd: rawnand: ifc: Move the ECC engine initialization to the right place
No ECC initialization should happen during the host controller probe. In fact, we need the probe function to call nand_scan() in order to: - identify the device, its capabilities and constraints (nand_scan_ident()) - configure the ECC engine accordingly (->attach_chip()) - scan its content and prepare the core (nand_scan_tail()) Moving these lines to fsl_ifc_attach_chip() fixes a regression caused by a previous commit supposed to clarify these steps. Based on a fix done for the mxc_nand driver by Miquel Raynal. Fixes: d7157ff ("mtd: rawnand: Use the ECC framework user input parsing bits") Reported-by: Han Xu <[email protected]> Signed-off-by: Fabio Estevam <[email protected]> Tested-by: Han Xu <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 1b8d107 commit 3aee8a3

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

drivers/mtd/nand/raw/fsl_ifc_nand.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,30 @@ static int fsl_ifc_attach_chip(struct nand_chip *chip)
707707
{
708708
struct mtd_info *mtd = nand_to_mtd(chip);
709709
struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
710+
struct fsl_ifc_ctrl *ctrl = priv->ctrl;
711+
struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs;
712+
u32 csor;
713+
714+
csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor);
715+
716+
/* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
717+
if (csor & CSOR_NAND_ECC_DEC_EN) {
718+
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
719+
mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops);
720+
721+
/* Hardware generates ECC per 512 Bytes */
722+
chip->ecc.size = 512;
723+
if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) {
724+
chip->ecc.bytes = 8;
725+
chip->ecc.strength = 4;
726+
} else {
727+
chip->ecc.bytes = 16;
728+
chip->ecc.strength = 8;
729+
}
730+
} else {
731+
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
732+
chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
733+
}
710734

711735
dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__,
712736
nanddev_ntargets(&chip->base));
@@ -910,25 +934,6 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
910934
return -ENODEV;
911935
}
912936

913-
/* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
914-
if (csor & CSOR_NAND_ECC_DEC_EN) {
915-
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
916-
mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops);
917-
918-
/* Hardware generates ECC per 512 Bytes */
919-
chip->ecc.size = 512;
920-
if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) {
921-
chip->ecc.bytes = 8;
922-
chip->ecc.strength = 4;
923-
} else {
924-
chip->ecc.bytes = 16;
925-
chip->ecc.strength = 8;
926-
}
927-
} else {
928-
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
929-
chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
930-
}
931-
932937
ret = fsl_ifc_sram_init(priv);
933938
if (ret)
934939
return ret;

0 commit comments

Comments
 (0)