mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srikanth Boyapally <srikanth.boyapally@amd.com>
To: Pratyush Yadav <pratyush@kernel.org>,
	Michael Walle <mwalle@kernel.org>,
	Takahiro Kuwano <takahiro.kuwano@infineon.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>
Cc: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	<michal.simek@amd.com>, <git@amd.com>,
	Srikanth Boyapally <srikanth.boyapally@amd.com>,
	Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Subject: [PATCH v2 2/2] mtd: spi-nor: Reset flash device on resume
Date: Tue, 1 Dec 2026 18:08:25 +0530	[thread overview]
Message-ID: <20261201-ospi_reset_v2-v2-2-ceb06548d531@amd.com> (raw)
In-Reply-To: <20261201-ospi_reset_v2-v2-0-ceb06548d531@amd.com>

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


      parent reply	other threads:[~2026-12-01 12:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-ospi_reset_v2-v2-2-ceb06548d531@amd.com \
    --to=srikanth.boyapally@amd.com \
    --cc=git@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=michal.simek@amd.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sai.krishna.potthuri@amd.com \
    --cc=takahiro.kuwano@infineon.com \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®