mtd: rawnand: lpc32xx_slc: Move the ECC initialization to ->attach_chip()
authorMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 13 Nov 2020 12:34:15 +0000 (13:34 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 19 Nov 2020 20:52:32 +0000 (21:52 +0100)
The probe function is only supposed to initialize the controller
hardware but not the ECC engine. Indeed, we don't know anything about
the NAND chip(s) at this stage. Let's move the logic initializing the
ECC engine, even pretty simple, to the ->attach_chip() hook which gets
called during nand_scan() routine, after the NAND chip discovery. As
the previously mentioned logic is supposed to parse the DT for us, it
is likely that the chip->ecc.* entries be overwritten. So let's avoid
this by moving these lines to ->attach_chip().

Fixes: d7157ff49a5b ("mtd: rawnand: Use the ECC framework user input parsing bits")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
drivers/mtd/nand/raw/lpc32xx_slc.c

index 6db9d2e..dc7785e 100644 (file)
@@ -775,6 +775,9 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
        struct mtd_info *mtd = nand_to_mtd(chip);
        struct lpc32xx_nand_host *host = nand_get_controller_data(chip);
 
+       if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
+               return 0;
+
        /* OOB and ECC CPU and DMA work areas */
        host->ecc_buf = (uint32_t *)(host->data_buf + LPC32XX_DMA_DATA_SIZE);
 
@@ -786,11 +789,22 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
        if (mtd->writesize <= 512)
                mtd_set_ooblayout(mtd, &lpc32xx_ooblayout_ops);
 
+       chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
        /* These sizes remain the same regardless of page size */
        chip->ecc.size = 256;
+       chip->ecc.strength = 1;
        chip->ecc.bytes = LPC32XX_SLC_DEV_ECC_BYTES;
        chip->ecc.prepad = 0;
        chip->ecc.postpad = 0;
+       chip->ecc.read_page_raw = lpc32xx_nand_read_page_raw_syndrome;
+       chip->ecc.read_page = lpc32xx_nand_read_page_syndrome;
+       chip->ecc.write_page_raw = lpc32xx_nand_write_page_raw_syndrome;
+       chip->ecc.write_page = lpc32xx_nand_write_page_syndrome;
+       chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
+       chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
+       chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
+       chip->ecc.correct = nand_correct_data;
+       chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
 
        /*
         * Use a custom BBT marker setup for small page FLASH that
@@ -881,21 +895,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, host);
 
        /* NAND callbacks for LPC32xx SLC hardware */
-       chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
-       chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
        chip->legacy.read_byte = lpc32xx_nand_read_byte;
        chip->legacy.read_buf = lpc32xx_nand_read_buf;
        chip->legacy.write_buf = lpc32xx_nand_write_buf;
-       chip->ecc.read_page_raw = lpc32xx_nand_read_page_raw_syndrome;
-       chip->ecc.read_page = lpc32xx_nand_read_page_syndrome;
-       chip->ecc.write_page_raw = lpc32xx_nand_write_page_raw_syndrome;
-       chip->ecc.write_page = lpc32xx_nand_write_page_syndrome;
-       chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
-       chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
-       chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
-       chip->ecc.correct = nand_correct_data;
-       chip->ecc.strength = 1;
-       chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
 
        /*
         * Allocate a large enough buffer for a single huge page plus