mtd: nand: Wait for PAGEPROG to finish in drivers setting NAND_ECC_CUSTOM_PAGE_ACCESS
authorBoris Brezillon <boris.brezillon@free-electrons.com>
Tue, 16 May 2017 16:27:49 +0000 (18:27 +0200)
committerBoris Brezillon <boris.brezillon@free-electrons.com>
Thu, 1 Jun 2017 08:09:33 +0000 (10:09 +0200)
Drivers setting NAND_ECC_CUSTOM_PAGE_ACCESS are supposed to handle the
full read/write page sequence, and waiting for a page to actually be
programmed is part of this write-page sequence.
This is also what is done in ->write_oob_xxx() hooks, so let's do that in
->write_page_xxx() as well to make it consistent.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
drivers/mtd/nand/atmel/nand-controller.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/nand_micron.c
drivers/mtd/nand/tango_nand.c

index 846c555e470b42171767f5ec16286d0982e4fba1..6055831c953ff9e9575c253b4b85f569e064b452 100644 (file)
@@ -917,7 +917,7 @@ static int atmel_hsmc_nand_pmecc_write_pg(struct nand_chip *chip,
        struct mtd_info *mtd = nand_to_mtd(chip);
        struct atmel_nand *nand = to_atmel_nand(chip);
        struct atmel_hsmc_nand_controller *nc;
        struct mtd_info *mtd = nand_to_mtd(chip);
        struct atmel_nand *nand = to_atmel_nand(chip);
        struct atmel_hsmc_nand_controller *nc;
-       int ret;
+       int ret, status;
 
        nc = to_hsmc_nand_controller(chip->controller);
 
 
        nc = to_hsmc_nand_controller(chip->controller);
 
@@ -959,6 +959,10 @@ static int atmel_hsmc_nand_pmecc_write_pg(struct nand_chip *chip,
                dev_err(nc->base.dev, "Failed to program NAND page (err = %d)\n",
                        ret);
 
                dev_err(nc->base.dev, "Failed to program NAND page (err = %d)\n",
                        ret);
 
+       status = chip->waitfunc(mtd, chip);
+       if (status & NAND_STATUS_FAIL)
+               return -EIO;
+
        return ret;
 }
 
        return ret;
 }
 
index df613125795b53da12ea7fca3dec1f5e07fe72ca..4b4fea4a3d1f3c818e8b689332af466061eff47c 100644 (file)
@@ -2750,11 +2750,13 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
        if (status < 0)
                return status;
 
        if (status < 0)
                return status;
 
-       if (nand_standard_page_accessors(&chip->ecc))
+       if (nand_standard_page_accessors(&chip->ecc)) {
                chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
                chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
-       status = chip->waitfunc(mtd, chip);
-       if (status & NAND_STATUS_FAIL)
-               return -EIO;
+
+               status = chip->waitfunc(mtd, chip);
+               if (status & NAND_STATUS_FAIL)
+                       return -EIO;
+       }
 
        return 0;
 }
 
        return 0;
 }
index 9993f8ead1e2f4ab26d41e21416befd3054d8d89..c30ab60f8e1bb1013a7d6fd7f88fd75b958e258a 100644 (file)
@@ -151,15 +151,18 @@ micron_nand_write_page_on_die_ecc(struct mtd_info *mtd, struct nand_chip *chip,
                                  const uint8_t *buf, int oob_required,
                                  int page)
 {
                                  const uint8_t *buf, int oob_required,
                                  int page)
 {
+       int status;
+
        micron_nand_on_die_ecc_setup(chip, true);
 
        chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
        nand_write_page_raw(mtd, chip, buf, oob_required, page);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
        micron_nand_on_die_ecc_setup(chip, true);
 
        chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
        nand_write_page_raw(mtd, chip, buf, oob_required, page);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+       status = chip->waitfunc(mtd, chip);
 
        micron_nand_on_die_ecc_setup(chip, false);
 
 
        micron_nand_on_die_ecc_setup(chip, false);
 
-       return 0;
+       return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
 
 static int
 }
 
 static int
@@ -180,11 +183,14 @@ micron_nand_write_page_raw_on_die_ecc(struct mtd_info *mtd,
                                      const uint8_t *buf, int oob_required,
                                      int page)
 {
                                      const uint8_t *buf, int oob_required,
                                      int page)
 {
+       int status;
+
        chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
        nand_write_page_raw(mtd, chip, buf, oob_required, page);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
        chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
        nand_write_page_raw(mtd, chip, buf, oob_required, page);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+       status = chip->waitfunc(mtd, chip);
 
 
-       return 0;
+       return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
 
 enum {
 }
 
 enum {
index 201979f0c1bdcf17c903b8caf48e14e76a5df1e6..dddc4fa7beb6239a357ae0d4781cac2a736a2524 100644 (file)
@@ -295,7 +295,7 @@ static int tango_write_page(struct mtd_info *mtd, struct nand_chip *chip,
                            const u8 *buf, int oob_required, int page)
 {
        struct tango_nfc *nfc = to_tango_nfc(chip->controller);
                            const u8 *buf, int oob_required, int page)
 {
        struct tango_nfc *nfc = to_tango_nfc(chip->controller);
-       int err, len = mtd->writesize;
+       int err, status, len = mtd->writesize;
 
        /* Calling tango_write_oob() would send PAGEPROG twice */
        if (oob_required)
 
        /* Calling tango_write_oob() would send PAGEPROG twice */
        if (oob_required)
@@ -306,6 +306,10 @@ static int tango_write_page(struct mtd_info *mtd, struct nand_chip *chip,
        if (err)
                return err;
 
        if (err)
                return err;
 
+       status = chip->waitfunc(mtd, chip);
+       if (status & NAND_STATUS_FAIL)
+               return -EIO;
+
        return 0;
 }
 
        return 0;
 }
 
@@ -423,9 +427,16 @@ static int tango_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
 static int tango_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
                                const u8 *buf, int oob_required, int page)
 {
 static int tango_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
                                const u8 *buf, int oob_required, int page)
 {
+       int status;
+
        chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0, page);
        raw_write(chip, buf, chip->oob_poi);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
        chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0, page);
        raw_write(chip, buf, chip->oob_poi);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+
+       status = chip->waitfunc(mtd, chip);
+       if (status & NAND_STATUS_FAIL)
+               return -EIO;
+
        return 0;
 }
 
        return 0;
 }