* [PATCH v2 0/2] mtd: spi-nor: Add flash reset support during resume
@ 2026-12-01 12:38 Srikanth Boyapally
2026-12-01 12:38 ` [PATCH v2 1/2] mtd: spi-nor: Store GPIO info for resetting device " Srikanth Boyapally
2026-12-01 12:38 ` [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume Srikanth Boyapally
0 siblings, 2 replies; 4+ messages in thread
From: Srikanth Boyapally @ 2026-12-01 12:38 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
Cc: linux-mtd, linux-kernel, michal.simek, git, Srikanth Boyapally,
Amit Kumar Mahapatra, Sai Krishna Potthuri
This series adds support for resetting SPI NOR devices during resume.
The first patch stores the reset GPIO information required to reset the
flash device, and the second patch uses it to perform the reset during resume.
---
Changes in v2:
- Get the reset GPIO once in spi_nor_scan() and
restore 4-byte address mode after the resume reset.
---
To: Pratyush Yadav <pratyush@kernel.org>
To: Michael Walle <mwalle@kernel.org>
To: Takahiro Kuwano <takahiro.kuwano@infineon.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
To: Richard Weinberger <richard@nod.at>
To: Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: michal.simek@amd.com
Cc: git@amd.com
Signed-off-by: Srikanth Boyapally <srikanth.boyapally@amd.com>
---
Amit Kumar Mahapatra (1):
mtd: spi-nor: Store GPIO info for resetting device during resume
Sai Krishna Potthuri (1):
mtd: spi-nor: Reset flash device on resume
drivers/mtd/spi-nor/core.c | 40 ++++++++++++++++++++++++++++++----------
include/linux/mtd/spi-nor.h | 2 ++
2 files changed, 32 insertions(+), 10 deletions(-)
---
base-commit: 7a7f426ca93dbbcb0a2b4f52fe48226fc2be71ca
change-id: 20261201-ospi_reset_v2-fb2faddf4eec
Best regards,
--
Srikanth Boyapally <srikanth.boyapally@amd.com>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] mtd: spi-nor: Store GPIO info for resetting device during resume
2026-12-01 12:38 [PATCH v2 0/2] mtd: spi-nor: Add flash reset support during resume Srikanth Boyapally
@ 2026-12-01 12:38 ` Srikanth Boyapally
2026-12-01 12:38 ` [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume Srikanth Boyapally
1 sibling, 0 replies; 4+ messages in thread
From: Srikanth Boyapally @ 2026-12-01 12:38 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
Cc: linux-mtd, linux-kernel, michal.simek, git, Srikanth Boyapally,
Amit Kumar Mahapatra
From: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
Upon resume, SPI-NOR triggers the hardware reset API to reset the flash
device by toggling the GPIO. This step is necessary because after resume,
the flash needs to be put in SDR mode. To facilitate this, SPI-NOR needs
GPIO information to reset the flash device.
Acquire the optional reset GPIO once in spi_nor_scan() and retain it in a
new gpio_desc member of struct spi_nor, so that spi_nor_hw_reset() can
use it later without looking it up again.
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
Signed-off-by: Srikanth Boyapally <srikanth.boyapally@amd.com>
---
drivers/mtd/spi-nor/core.c | 19 +++++++++----------
include/linux/mtd/spi-nor.h | 2 ++
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index bc9c413df8df..0e0960bc6f63 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3383,13 +3383,12 @@ static int spi_nor_set_mtd_info(struct spi_nor *nor)
return 0;
}
-static int spi_nor_hw_reset(struct spi_nor *nor)
+static void spi_nor_hw_reset(struct spi_nor *nor)
{
- struct gpio_desc *reset;
+ struct gpio_desc *reset = nor->reset;
- reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
- if (IS_ERR_OR_NULL(reset))
- return PTR_ERR_OR_ZERO(reset);
+ if (!reset)
+ return;
/*
* Experimental delay values by looking at different flash device
@@ -3400,8 +3399,6 @@ static int spi_nor_hw_reset(struct spi_nor *nor)
usleep_range(100, 150);
gpiod_set_value_cansleep(reset, 0);
usleep_range(1000, 1200);
-
- return 0;
}
int spi_nor_scan(struct spi_nor *nor, const char *name,
@@ -3434,9 +3431,11 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (!nor->bouncebuf)
return -ENOMEM;
- ret = spi_nor_hw_reset(nor);
- if (ret)
- return ret;
+ nor->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+ if (IS_ERR(nor->reset))
+ return PTR_ERR(nor->reset);
+
+ spi_nor_hw_reset(nor);
info = spi_nor_get_flash_info(nor, name);
if (IS_ERR(info))
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index b3e3c6b10186..79775d5d8d0a 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -374,6 +374,7 @@ struct spi_nor_flash_parameter;
* settings that can be overwritten by the spi_nor_fixups
* hooks, or dynamically when parsing the SFDP tables.
* @dirmap: pointers to struct spi_mem_dirmap_desc for reads/writes.
+ * @reset: optional GPIO descriptor used to reset the flash device.
* @priv: pointer to the private data
*/
struct spi_nor {
@@ -415,6 +416,7 @@ struct spi_nor {
struct spi_mem_dirmap_desc *rdesc;
struct spi_mem_dirmap_desc *wdesc;
} dirmap;
+ struct gpio_desc *reset;
void *priv;
};
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume
2026-12-01 12:38 [PATCH v2 0/2] mtd: spi-nor: Add flash reset support during resume Srikanth Boyapally
2026-12-01 12:38 ` [PATCH v2 1/2] mtd: spi-nor: Store GPIO info for resetting device " Srikanth Boyapally
@ 2026-12-01 12:38 ` Srikanth Boyapally
2026-12-01 12:50 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Srikanth Boyapally @ 2026-12-01 12:38 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra
Cc: linux-mtd, linux-kernel, michal.simek, git, Srikanth Boyapally,
Sai Krishna Potthuri
From: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
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@amd.com>
Signed-off-by: Srikanth Boyapally <srikanth.boyapally@amd.com>
---
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume
2026-12-01 12:38 ` [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume Srikanth Boyapally
@ 2026-12-01 12:50 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-01 12:50 UTC (permalink / raw)
To: Srikanth Boyapally, Pratyush Yadav, Michael Walle,
Takahiro Kuwano, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra
Cc: linux-mtd, michal.simek, git, Sai Krishna Potthuri
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: spi-nor: spi_nor_resume() calls spi_nor_init() on 4-byte
mode failure
--
commit 4cc851bee16e0903423a0be769db3ce9037e0647
Author: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
mtd: spi-nor: Reset flash device on resume
This commit resets the SPI NOR flash via its hardware reset GPIO during
resume and restores 4-byte address mode if it was in use before calling
spi_nor_init().
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 0e0960bc6f63f..0166f2b332469 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
[ ... ]
> @@ -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)
[Severity: Medium]
Should spi_nor_resume() return early when spi_nor_set_4byte_addr_mode()
fails?
When spi_nor_set_4byte_addr_mode() returns an error, the flash remains in
its power-on 3-byte address mode while nor->params->addr_mode_nbytes stays
4. Falling through to spi_nor_init() will then issue volatile register
writes with 4-byte addresses (such as micron_st_nor_octal_dtr_en()),
causing the flash to treat the fourth address byte as data written to the
wrong configuration register.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-ospi_reset_v2-v2-0-ceb06548d531@amd.com?part=2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 12:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 12:38 [PATCH v2 0/2] mtd: spi-nor: Add flash reset support during resume Srikanth Boyapally
2026-12-01 12:38 ` [PATCH v2 1/2] mtd: spi-nor: Store GPIO info for resetting device " Srikanth Boyapally
2026-12-01 12:38 ` [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume Srikanth Boyapally
2026-12-01 12:50 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox