mtd: rawnand: r852: Move the ECC initialization to ->attach_chip()
authorMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 13 Nov 2020 12:34:22 +0000 (13:34 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 20 Nov 2020 11:30:53 +0000 (12:30 +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: Maxim Levitsky <maximlevitsky@gmail.com>
Link: https://lore.kernel.org/linux-mtd/20201113123424.32233-18-miquel.raynal@bootlin.com
drivers/mtd/nand/raw/r852.c
drivers/mtd/nand/raw/r852.h

index 6b7addd..c742354 100644 (file)
@@ -817,6 +817,29 @@ out:
        return ret;
 }
 
+static int r852_attach_chip(struct nand_chip *chip)
+{
+       if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
+               return 0;
+
+       chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
+       chip->ecc.size = R852_DMA_LEN;
+       chip->ecc.bytes = SM_OOB_SIZE;
+       chip->ecc.strength = 2;
+       chip->ecc.hwctl = r852_ecc_hwctl;
+       chip->ecc.calculate = r852_ecc_calculate;
+       chip->ecc.correct = r852_ecc_correct;
+
+       /* TODO: hack */
+       chip->ecc.read_oob = r852_read_oob;
+
+       return 0;
+}
+
+static const struct nand_controller_ops r852_ops = {
+       .attach_chip = r852_attach_chip,
+};
+
 static int  r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
 {
        int error;
@@ -858,19 +881,6 @@ static int  r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
        chip->legacy.read_buf = r852_read_buf;
        chip->legacy.write_buf = r852_write_buf;
 
-       /* ecc */
-       chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
-       chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
-       chip->ecc.size = R852_DMA_LEN;
-       chip->ecc.bytes = SM_OOB_SIZE;
-       chip->ecc.strength = 2;
-       chip->ecc.hwctl = r852_ecc_hwctl;
-       chip->ecc.calculate = r852_ecc_calculate;
-       chip->ecc.correct = r852_ecc_correct;
-
-       /* TODO: hack */
-       chip->ecc.read_oob = r852_read_oob;
-
        /* init our device structure */
        dev = kzalloc(sizeof(struct r852_device), GFP_KERNEL);
 
@@ -882,6 +892,10 @@ static int  r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
        dev->pci_dev = pci_dev;
        pci_set_drvdata(pci_dev, dev);
 
+       nand_controller_init(&dev->controller);
+       dev->controller.ops = &r852_ops;
+       chip->controller = &dev->controller;
+
        dev->bounce_buffer = dma_alloc_coherent(&pci_dev->dev, R852_DMA_LEN,
                &dev->phys_bounce_buffer, GFP_KERNEL);
 
index e9ce299..96fe301 100644 (file)
 #define DMA_MEMORY     1
 
 struct r852_device {
+       struct nand_controller          controller;
        void __iomem *mmio;             /* mmio */
        struct nand_chip *chip;         /* nand chip backpointer */
        struct pci_dev *pci_dev;        /* pci backpointer */