On Sun, 3 May 2020 13:40:27 +0200 Miquel Raynal <miquel.raynal@xxxxxxxxxxx> wrote: > In order to solve an issue with Micron NANDs, we must be able to > overload the erase operation. With this in mind, we create a ->erase > hook in the nand_chip structure which points by default to the > currently in use nand_erase_nand() helper. > > Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx> > --- > drivers/mtd/nand/raw/nand_base.c | 6 +++++- > include/linux/mtd/rawnand.h | 3 +++ > 2 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > index c24e5e2ba130..7c7ac722d88b 100644 > --- a/drivers/mtd/nand/raw/nand_base.c > +++ b/drivers/mtd/nand/raw/nand_base.c > @@ -4158,7 +4158,9 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, > */ > static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) > { > - return nand_erase_nand(mtd_to_nand(mtd), instr, 0); > + struct nand_chip *chip = mtd_to_nand(mtd); > + > + return chip->erase(chip, instr, 0); > } > > /** > @@ -4419,6 +4421,8 @@ static void nand_set_defaults(struct nand_chip *chip) > > if (!chip->buf_align) > chip->buf_align = 1; > + > + chip->erase = nand_erase_nand; > } > > /* Sanitize ONFI strings so we can safely print them */ > diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h > index 1e76196f9829..505c13f7a2ba 100644 > --- a/include/linux/mtd/rawnand.h > +++ b/include/linux/mtd/rawnand.h > @@ -1020,6 +1020,7 @@ struct nand_legacy { > * avoid using them. > * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for > * setting the read-retry mode. Mostly needed for MLC NAND. > + * @erase: Raw NAND erase operation. > * @ecc: [BOARDSPECIFIC] ECC control structure > * @buf_align: minimum buffer alignment required by a platform > * @oob_poi: "poison value buffer," used for laying out OOB data > @@ -1089,6 +1090,8 @@ struct nand_chip { > struct nand_legacy legacy; > > int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); > + int (*erase)(struct nand_chip *chip, struct erase_info *instr, > + int allowbbt); > Before we do that, can we create a nand_chip_ops struct and place all NAND-specific ops in there? Regarding the erase hook itself, I wonder if it wouldn't be simpler to have optional {pre,post}_erase() hooks instead (I think makes even more sense for the ->write_oob() hook). > unsigned int options; > unsigned int bbt_options; ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/