mtd: rawnand: tmio: Move the ECC initialization to ->attach_chip()
authorMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 13 Nov 2020 12:34:19 +0000 (13:34 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 19 Nov 2020 20:52:33 +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>
Link: https://lore.kernel.org/linux-mtd/20201113123424.32233-15-miquel.raynal@bootlin.com
drivers/mtd/nand/raw/tmio_nand.c

index 235a2f7b1baddc30aaa04d96d9bef46ff800af83..aa6c7e7bbf1b59f36f50f0b1725a7b2a5136de2f 100644 (file)
 /*--------------------------------------------------------------------------*/
 
 struct tmio_nand {
+       struct nand_controller controller;
        struct nand_chip chip;
        struct completion comp;
 
@@ -355,6 +356,25 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
                cell->disable(dev);
 }
 
+static int tmio_attach_chip(struct nand_chip *chip)
+{
+       if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
+               return 0;
+
+       chip->ecc.size = 512;
+       chip->ecc.bytes = 6;
+       chip->ecc.strength = 2;
+       chip->ecc.hwctl = tmio_nand_enable_hwecc;
+       chip->ecc.calculate = tmio_nand_calculate_ecc;
+       chip->ecc.correct = tmio_nand_correct_data;
+
+       return 0;
+}
+
+static const struct nand_controller_ops tmio_ops = {
+       .attach_chip = tmio_attach_chip,
+};
+
 static int tmio_probe(struct platform_device *dev)
 {
        struct tmio_nand_data *data = dev_get_platdata(&dev->dev);
@@ -385,6 +405,10 @@ static int tmio_probe(struct platform_device *dev)
        mtd->name = "tmio-nand";
        mtd->dev.parent = &dev->dev;
 
+       nand_controller_init(&tmio->controller);
+       tmio->controller.ops = &tmio_ops;
+       nand_chip->controller = &tmio->controller;
+
        tmio->ccr = devm_ioremap(&dev->dev, ccr->start, resource_size(ccr));
        if (!tmio->ccr)
                return -EIO;
@@ -409,15 +433,6 @@ static int tmio_probe(struct platform_device *dev)
        nand_chip->legacy.write_buf = tmio_nand_write_buf;
        nand_chip->legacy.read_buf = tmio_nand_read_buf;
 
-       /* set eccmode using hardware ECC */
-       nand_chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
-       nand_chip->ecc.size = 512;
-       nand_chip->ecc.bytes = 6;
-       nand_chip->ecc.strength = 2;
-       nand_chip->ecc.hwctl = tmio_nand_enable_hwecc;
-       nand_chip->ecc.calculate = tmio_nand_calculate_ecc;
-       nand_chip->ecc.correct = tmio_nand_correct_data;
-
        if (data)
                nand_chip->badblock_pattern = data->badblock_pattern;