Skip to content

Commit 7ef969a

Browse files
committed
mtd: rawnand: r852: Move the ECC initialization to ->attach_chip()
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: d7157ff ("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
1 parent 612e048 commit 7ef969a

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

drivers/mtd/nand/raw/r852.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,29 @@ static irqreturn_t r852_irq(int irq, void *data)
817817
return ret;
818818
}
819819

820+
static int r852_attach_chip(struct nand_chip *chip)
821+
{
822+
if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
823+
return 0;
824+
825+
chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
826+
chip->ecc.size = R852_DMA_LEN;
827+
chip->ecc.bytes = SM_OOB_SIZE;
828+
chip->ecc.strength = 2;
829+
chip->ecc.hwctl = r852_ecc_hwctl;
830+
chip->ecc.calculate = r852_ecc_calculate;
831+
chip->ecc.correct = r852_ecc_correct;
832+
833+
/* TODO: hack */
834+
chip->ecc.read_oob = r852_read_oob;
835+
836+
return 0;
837+
}
838+
839+
static const struct nand_controller_ops r852_ops = {
840+
.attach_chip = r852_attach_chip,
841+
};
842+
820843
static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
821844
{
822845
int error;
@@ -858,19 +881,6 @@ static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
858881
chip->legacy.read_buf = r852_read_buf;
859882
chip->legacy.write_buf = r852_write_buf;
860883

861-
/* ecc */
862-
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
863-
chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
864-
chip->ecc.size = R852_DMA_LEN;
865-
chip->ecc.bytes = SM_OOB_SIZE;
866-
chip->ecc.strength = 2;
867-
chip->ecc.hwctl = r852_ecc_hwctl;
868-
chip->ecc.calculate = r852_ecc_calculate;
869-
chip->ecc.correct = r852_ecc_correct;
870-
871-
/* TODO: hack */
872-
chip->ecc.read_oob = r852_read_oob;
873-
874884
/* init our device structure */
875885
dev = kzalloc(sizeof(struct r852_device), GFP_KERNEL);
876886

@@ -882,6 +892,10 @@ static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
882892
dev->pci_dev = pci_dev;
883893
pci_set_drvdata(pci_dev, dev);
884894

895+
nand_controller_init(&dev->controller);
896+
dev->controller.ops = &r852_ops;
897+
chip->controller = &dev->controller;
898+
885899
dev->bounce_buffer = dma_alloc_coherent(&pci_dev->dev, R852_DMA_LEN,
886900
&dev->phys_bounce_buffer, GFP_KERNEL);
887901

drivers/mtd/nand/raw/r852.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#define DMA_MEMORY 1
105105

106106
struct r852_device {
107+
struct nand_controller controller;
107108
void __iomem *mmio; /* mmio */
108109
struct nand_chip *chip; /* nand chip backpointer */
109110
struct pci_dev *pci_dev; /* pci backpointer */

0 commit comments

Comments
 (0)