Skip to content

Commit 1ac6870

Browse files
committed
mtd: rawnand: sharpsl: 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>
1 parent 7ef969a commit 1ac6870

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

drivers/mtd/nand/raw/sharpsl.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/io.h>
2121

2222
struct sharpsl_nand {
23+
struct nand_controller controller;
2324
struct nand_chip chip;
2425

2526
void __iomem *io;
@@ -96,6 +97,25 @@ static int sharpsl_nand_calculate_ecc(struct nand_chip *chip,
9697
return readb(sharpsl->io + ECCCNTR) != 0;
9798
}
9899

100+
static int sharpsl_attach_chip(struct nand_chip *chip)
101+
{
102+
if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
103+
return 0;
104+
105+
chip->ecc.size = 256;
106+
chip->ecc.bytes = 3;
107+
chip->ecc.strength = 1;
108+
chip->ecc.hwctl = sharpsl_nand_enable_hwecc;
109+
chip->ecc.calculate = sharpsl_nand_calculate_ecc;
110+
chip->ecc.correct = nand_correct_data;
111+
112+
return 0;
113+
}
114+
115+
static const struct nand_controller_ops sharpsl_ops = {
116+
.attach_chip = sharpsl_attach_chip,
117+
};
118+
99119
/*
100120
* Main initialization routine
101121
*/
@@ -136,6 +156,10 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
136156
/* Get pointer to private data */
137157
this = (struct nand_chip *)(&sharpsl->chip);
138158

159+
nand_controller_init(&sharpsl->controller);
160+
sharpsl->controller.ops = &sharpsl_ops;
161+
this->controller = &sharpsl->controller;
162+
139163
/* Link the private data with the MTD structure */
140164
mtd = nand_to_mtd(this);
141165
mtd->dev.parent = &pdev->dev;
@@ -156,15 +180,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
156180
this->legacy.dev_ready = sharpsl_nand_dev_ready;
157181
/* 15 us command delay time */
158182
this->legacy.chip_delay = 15;
159-
/* set eccmode using hardware ECC */
160-
this->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
161-
this->ecc.size = 256;
162-
this->ecc.bytes = 3;
163-
this->ecc.strength = 1;
164183
this->badblock_pattern = data->badblock_pattern;
165-
this->ecc.hwctl = sharpsl_nand_enable_hwecc;
166-
this->ecc.calculate = sharpsl_nand_calculate_ecc;
167-
this->ecc.correct = nand_correct_data;
168184

169185
/* Scan to find existence of the device */
170186
err = nand_scan(this, 1);

0 commit comments

Comments
 (0)