Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: rawnand: socrates: 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: d7157ff49a5b ("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-20-miquel.raynal@bootlin.com

+17 -4
+17 -4
drivers/mtd/nand/raw/socrates_nand.c
··· 22 22 #define FPGA_NAND_DATA_SHIFT 16 23 23 24 24 struct socrates_nand_host { 25 + struct nand_controller controller; 25 26 struct nand_chip nand_chip; 26 27 void __iomem *io_base; 27 28 struct device *dev; ··· 117 116 return 1; 118 117 } 119 118 119 + static int socrates_attach_chip(struct nand_chip *chip) 120 + { 121 + chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; 122 + chip->ecc.algo = NAND_ECC_ALGO_HAMMING; 123 + 124 + return 0; 125 + } 126 + 127 + static const struct nand_controller_ops socrates_ops = { 128 + .attach_chip = socrates_attach_chip, 129 + }; 130 + 120 131 /* 121 132 * Probe for the NAND device. 122 133 */ ··· 154 141 mtd = nand_to_mtd(nand_chip); 155 142 host->dev = &ofdev->dev; 156 143 144 + nand_controller_init(&host->controller); 145 + host->controller.ops = &socrates_ops; 146 + nand_chip->controller = &host->controller; 147 + 157 148 /* link the private data structures */ 158 149 nand_set_controller_data(nand_chip, host); 159 150 nand_set_flash_node(nand_chip, ofdev->dev.of_node); ··· 169 152 nand_chip->legacy.write_buf = socrates_nand_write_buf; 170 153 nand_chip->legacy.read_buf = socrates_nand_read_buf; 171 154 nand_chip->legacy.dev_ready = socrates_nand_device_ready; 172 - 173 - /* enable ECC */ 174 - nand_chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; 175 - nand_chip->ecc.algo = NAND_ECC_ALGO_HAMMING; 176 155 177 156 /* TODO: I have no idea what real delay is. */ 178 157 nand_chip->legacy.chip_delay = 20; /* 20us command delay time */