Skip to content

Commit

Permalink
mtd: rawnand: r852: Move the ECC initialization to ->attach_chip()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Miquel Raynal committed Nov 20, 2020
1 parent 612e048 commit 7ef969a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
40 changes: 27 additions & 13 deletions drivers/mtd/nand/raw/r852.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,29 @@ static irqreturn_t r852_irq(int irq, void *data)
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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions drivers/mtd/nand/raw/r852.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#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 */
Expand Down

0 comments on commit 7ef969a

Please sign in to comment.