Skip to content

Commit e0fe533

Browse files
committed
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 <[email protected]> Signed-off-by: Tudor Ambarus <[email protected]> Tested-by: John Garry <[email protected]>
1 parent 6d4e346 commit e0fe533

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ static int spi_nor_sr_ready(struct spi_nor *nor)
559559
dev_err(nor->dev, "Programming Error occurred\n");
560560

561561
spi_nor_clear_sr(nor);
562+
563+
/*
564+
* WEL bit remains set to one when an erase or page program
565+
* error occurs. Issue a Write Disable command to protect
566+
* against inadvertent writes that can possibly corrupt the
567+
* contents of the memory.
568+
*/
569+
ret = spi_nor_write_disable(nor);
570+
if (ret)
571+
return ret;
572+
562573
return -EIO;
563574
}
564575

@@ -615,6 +626,17 @@ static int spi_nor_fsr_ready(struct spi_nor *nor)
615626
"Attempted to modify a protected sector.\n");
616627

617628
spi_nor_clear_fsr(nor);
629+
630+
/*
631+
* WEL bit remains set to one when an erase or page program
632+
* error occurs. Issue a Write Disable command to protect
633+
* against inadvertent writes that can possibly corrupt the
634+
* contents of the memory.
635+
*/
636+
ret = spi_nor_write_disable(nor);
637+
if (ret)
638+
return ret;
639+
618640
return -EIO;
619641
}
620642

0 commit comments

Comments
 (0)