summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorTudor Ambarus <tudor.ambarus@microchip.com>2020-03-23 19:50:40 +0200
committerTudor Ambarus <tudor.ambarus@microchip.com>2020-03-23 19:50:40 +0200
commite0fe5339d4886c48cdd68a2c49d602c4c1864c38 (patch)
treeae0b30e2daccee58ec4f6ff2892d8015a111de19 /drivers/mtd
parent6d4e346435b9b90bb7cca1d296adb6f6c7930c2d (diff)
downloadlinux-e0fe5339d4886c48cdd68a2c49d602c4c1864c38.tar.bz2
mtd: spi-nor: Clear WEL bit when erase or program errors occur
When an Erase or Program error occurs on a spansion/cypress or a micron flash, the WEL bit remains set to one and should be cleared with a WRDI command in order to protect against inadvertent writes that can possible corrupt the contents of the memory. Winbond, macronix, gd, etc., do not support the E_ERR and P_ERR bits in the Status Register and always clear the WEL bit regardless of the outcome of the erase or page program operation (ex w25q40bw, MX25L25635E). Issue a WRDI command when erase or page program errors occur. Reported-by: John Garry <john.garry@huawei.com> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Tested-by: John Garry <john.garry@huawei.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/spi-nor/core.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 877557dbda7f..e0021dd34bfe 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -559,6 +559,17 @@ static int spi_nor_sr_ready(struct spi_nor *nor)
dev_err(nor->dev, "Programming Error occurred\n");
spi_nor_clear_sr(nor);
+
+ /*
+ * WEL bit remains set to one when an erase or page program
+ * error occurs. Issue a Write Disable command to protect
+ * against inadvertent writes that can possibly corrupt the
+ * contents of the memory.
+ */
+ ret = spi_nor_write_disable(nor);
+ if (ret)
+ return ret;
+
return -EIO;
}
@@ -615,6 +626,17 @@ static int spi_nor_fsr_ready(struct spi_nor *nor)
"Attempted to modify a protected sector.\n");
spi_nor_clear_fsr(nor);
+
+ /*
+ * WEL bit remains set to one when an erase or page program
+ * error occurs. Issue a Write Disable command to protect
+ * against inadvertent writes that can possibly corrupt the
+ * contents of the memory.
+ */
+ ret = spi_nor_write_disable(nor);
+ if (ret)
+ return ret;
+
return -EIO;
}