public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Sanjaikumar V S <sanjaikumarvs@gmail.com>
To: mwalle@kernel.org, pratyush@kernel.org
Cc: hd@os-cillation.de, linux-kernel@vger.kernel.org,
	linux-mtd@lists.infradead.org, miquel.raynal@bootlin.com,
	richard@nod.at, sanjaikumar.vs@dicortech.com,
	sanjaikumarvs@gmail.com, stable@vger.kernel.org,
	tudor.ambarus@linaro.org, vigneshr@ti.com
Subject: [PATCH v5] mtd: spi-nor: Fix SST AAI write mode opcode handling
Date: Tue, 31 Mar 2026 09:50:26 +0000	[thread overview]
Message-ID: <20260331095026.38-1-sanjaikumarvs@gmail.com> (raw)

From: Sanjaikumar V S <sanjaikumar.vs@dicortech.com>

When the SPI controller lacks direct mapping support, the fallback path
in spi_nor_spimem_write_data() uses nor->write_proto based operation
template. However, this template uses the standard page program opcode
set during probe, not the AAI opcode required for SST flash.

Additionally, controllers that do support direct mapping will also use
the wrong opcode since the dirmap template is created at probe time
with the standard page program opcode.

Fix this by:
1. Checking the nodirmap flag in spi_nor_spimem_write_data() to ensure
   the code falls through to spi_nor_spimem_exec_op() path which builds
   the operation at runtime with the correct program_opcode.
2. Setting nodirmap=true for SST AAI devices in sst_nor_late_init() to
   disable dirmap and force the runtime opcode path.

This only affects SST devices with SST_WRITE flag. Other SST devices
that use standard page program can still benefit from dirmap.

Fixes: df5c21002cf4 ("mtd: spi-nor: use spi-mem dirmap API")
Cc: stable@vger.kernel.org
Signed-off-by: Sanjaikumar V S <sanjaikumar.vs@dicortech.com>
---
Changes since v4:
- Disable dirmap for SST AAI devices in sst_nor_late_init() to fix
  the case when controller supports direct mapping (Pratyush)
- Updated commit message and subject to reflect the broader fix

Note: Patch 1/2 from v4 series is already in spi-nor/next.

I don't have hardware to test the new sst.c change. Hendrik, could you
please verify this on your SST25VF032B setup?

 drivers/mtd/spi-nor/core.c |  2 +-
 drivers/mtd/spi-nor/sst.c  | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index e6c1fda61f57..2e4b167cab57 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -281,7 +281,7 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
 	if (spi_nor_spimem_bounce(nor, &op))
 		memcpy(nor->bouncebuf, buf, op.data.nbytes);
 
-	if (nor->dirmap.wdesc) {
+	if (nor->dirmap.wdesc && !nor->dirmap.wdesc->nodirmap) {
 		nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc, op.addr.val,
 					      op.data.nbytes, op.data.buf.out);
 	} else {
diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index db02c14ba16f..cd2f04830a6b 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -267,8 +267,16 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 static int sst_nor_late_init(struct spi_nor *nor)
 {
-	if (nor->info->mfr_flags & SST_WRITE)
+	if (nor->info->mfr_flags & SST_WRITE) {
 		nor->mtd._write = sst_nor_write;
+		/*
+		 * AAI mode requires dynamic opcode changes (BP vs AAI_WP).
+		 * Disable dirmap to ensure spi_nor_spimem_exec_op() uses
+		 * the runtime opcode instead of the dirmap template.
+		 */
+		if (nor->dirmap.wdesc)
+			nor->dirmap.wdesc->nodirmap = true;
+	}
 
 	return 0;
 }
-- 
2.43.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

             reply	other threads:[~2026-03-31  9:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  9:50 Sanjaikumar V S [this message]
2026-04-01 15:53 ` [PATCH v5] mtd: spi-nor: Fix SST AAI write mode opcode handling Hendrik Donner

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=20260331095026.38-1-sanjaikumarvs@gmail.com \
    --to=sanjaikumarvs@gmail.com \
    --cc=hd@os-cillation.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sanjaikumar.vs@dicortech.com \
    --cc=stable@vger.kernel.org \
    --cc=tudor.ambarus@linaro.org \
    --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