[PATCH 1/2] mtd: spi-nor: Store GPIO info for resetting device during resume

From: Srikanth Boyapally

Date: Fri Nov 20 2026 - 06:02:35 EST


From: Amit Kumar Mahapatra <amit.kumar-mahapatra@xxxxxxx>

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. Therefore, a gpio_desc member
is added to the spi_nor structure to retain the GPIO information and
utilize it for resetting the device.

Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xxxxxxx>
Signed-off-by: Srikanth Boyapally <srikanth.boyapally@xxxxxxx>
---
drivers/mtd/spi-nor/core.c | 11 +++++++----
include/linux/mtd/spi-nor.h | 2 ++
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 90524c58602e..11227f8fa8ea 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3389,11 +3389,14 @@ static int spi_nor_set_mtd_info(struct spi_nor *nor)

static int 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) {
+ reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
+ if (IS_ERR_OR_NULL(reset))
+ return PTR_ERR_OR_ZERO(reset);
+ nor->reset = reset;
+ }

/*
* Experimental delay values by looking at different flash device
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index b3e3c6b10186..46b1f92a490a 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: GPIO descriptor for device reset.
* @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