Skip to content

Commit 612e048

Browse files
committed
mtd: rawnand: plat_nand: 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-17-miquel.raynal@bootlin.com
1 parent 8fc6f1f commit 612e048

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

drivers/mtd/nand/raw/plat_nand.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,23 @@
1414
#include <linux/mtd/platnand.h>
1515

1616
struct plat_nand_data {
17+
struct nand_controller controller;
1718
struct nand_chip chip;
1819
void __iomem *io_base;
1920
};
2021

22+
static int plat_nand_attach_chip(struct nand_chip *chip)
23+
{
24+
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
25+
chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
26+
27+
return 0;
28+
}
29+
30+
static const struct nand_controller_ops plat_nand_ops = {
31+
.attach_chip = plat_nand_attach_chip,
32+
};
33+
2134
/*
2235
* Probe for the NAND device.
2336
*/
@@ -46,6 +59,10 @@ static int plat_nand_probe(struct platform_device *pdev)
4659
if (!data)
4760
return -ENOMEM;
4861

62+
data->controller.ops = &plat_nand_ops;
63+
nand_controller_init(&data->controller);
64+
data->chip.controller = &data->controller;
65+
4966
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5067
data->io_base = devm_ioremap_resource(&pdev->dev, res);
5168
if (IS_ERR(data->io_base))
@@ -66,9 +83,6 @@ static int plat_nand_probe(struct platform_device *pdev)
6683
data->chip.options |= pdata->chip.options;
6784
data->chip.bbt_options |= pdata->chip.bbt_options;
6885

69-
data->chip.ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
70-
data->chip.ecc.algo = NAND_ECC_ALGO_HAMMING;
71-
7286
platform_set_drvdata(pdev, data);
7387

7488
/* Handle any platform specific setup */

0 commit comments

Comments
 (0)