Skip to content

Commit 1f65976

Browse files
committed
mtd: rawnand: tmio: 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> Link: https://lore.kernel.org/linux-mtd/20201113123424.32233-15-miquel.raynal@bootlin.com
1 parent 3c3bbf0 commit 1f65976

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

drivers/mtd/nand/raw/tmio_nand.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
/*--------------------------------------------------------------------------*/
104104

105105
struct tmio_nand {
106+
struct nand_controller controller;
106107
struct nand_chip chip;
107108
struct completion comp;
108109

@@ -355,6 +356,25 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
355356
cell->disable(dev);
356357
}
357358

359+
static int tmio_attach_chip(struct nand_chip *chip)
360+
{
361+
if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
362+
return 0;
363+
364+
chip->ecc.size = 512;
365+
chip->ecc.bytes = 6;
366+
chip->ecc.strength = 2;
367+
chip->ecc.hwctl = tmio_nand_enable_hwecc;
368+
chip->ecc.calculate = tmio_nand_calculate_ecc;
369+
chip->ecc.correct = tmio_nand_correct_data;
370+
371+
return 0;
372+
}
373+
374+
static const struct nand_controller_ops tmio_ops = {
375+
.attach_chip = tmio_attach_chip,
376+
};
377+
358378
static int tmio_probe(struct platform_device *dev)
359379
{
360380
struct tmio_nand_data *data = dev_get_platdata(&dev->dev);
@@ -385,6 +405,10 @@ static int tmio_probe(struct platform_device *dev)
385405
mtd->name = "tmio-nand";
386406
mtd->dev.parent = &dev->dev;
387407

408+
nand_controller_init(&tmio->controller);
409+
tmio->controller.ops = &tmio_ops;
410+
nand_chip->controller = &tmio->controller;
411+
388412
tmio->ccr = devm_ioremap(&dev->dev, ccr->start, resource_size(ccr));
389413
if (!tmio->ccr)
390414
return -EIO;
@@ -409,15 +433,6 @@ static int tmio_probe(struct platform_device *dev)
409433
nand_chip->legacy.write_buf = tmio_nand_write_buf;
410434
nand_chip->legacy.read_buf = tmio_nand_read_buf;
411435

412-
/* set eccmode using hardware ECC */
413-
nand_chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
414-
nand_chip->ecc.size = 512;
415-
nand_chip->ecc.bytes = 6;
416-
nand_chip->ecc.strength = 2;
417-
nand_chip->ecc.hwctl = tmio_nand_enable_hwecc;
418-
nand_chip->ecc.calculate = tmio_nand_calculate_ecc;
419-
nand_chip->ecc.correct = tmio_nand_correct_data;
420-
421436
if (data)
422437
nand_chip->badblock_pattern = data->badblock_pattern;
423438

0 commit comments

Comments
 (0)