[PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume

From: Srikanth Boyapally

Date: Tue Dec 01 2026 - 07:39:13 EST


From: Sai Krishna Potthuri <sai.krishna.potthuri@xxxxxxx>

Reset the SPI NOR device before reinitializing it during resume.
This ensures that the flash is brought back to a known state before
spi_nor_init() restores the device configuration.

The reset returns the flash to its power-on address mode, which is
3-byte addressing unless the non-volatile configuration says otherwise.
Flashes such as multi-die Micron parts are put in 4-byte address mode
at probe time, so re-enter that mode after the reset. Otherwise
spi_nor_init() would use register accesses with a 4-byte address on a
flash that expects 3 bytes.

Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@xxxxxxx>
Signed-off-by: Srikanth Boyapally <srikanth.boyapally@xxxxxxx>
---
drivers/mtd/spi-nor/core.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0e0960bc6f63..0166f2b33246 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -45,6 +45,9 @@
#define SPI_NOR_SRST_SLEEP_MIN 200
#define SPI_NOR_SRST_SLEEP_MAX 400

+/* Perform a device reset */
+static void spi_nor_hw_reset(struct spi_nor *nor);
+
/**
* spi_nor_get_cmd_ext() - Get the command opcode extension based on the
* extension type.
@@ -3188,6 +3191,24 @@ static void spi_nor_resume(struct mtd_info *mtd)
struct device *dev = nor->dev;
int ret;

+ /*
+ * Reset the flash to a known state before reinitializing it. The reset
+ * returns the flash to its power-on address mode, which is 3-byte
+ * addressing unless configured otherwise in non-volatile memory.
+ * Re-enter 4-byte address mode if it was in use, so that the flash
+ * matches the cached address mode used by spi_nor_init().
+ */
+ if (nor->reset) {
+ spi_nor_hw_reset(nor);
+
+ if (nor->params->addr_mode_nbytes == 4) {
+ ret = spi_nor_set_4byte_addr_mode(nor, true);
+ if (ret)
+ dev_err(dev, "failed to enter 4-byte address mode: %d\n",
+ ret);
+ }
+ }
+
/* re-initialize the nor chip */
ret = spi_nor_init(nor);
if (ret)

--
2.43.0