* [PATCH v5] mtd: spi-nor: Fix SST AAI write mode opcode handling
@ 2026-03-31 9:50 Sanjaikumar V S
2026-04-01 15:53 ` Hendrik Donner
0 siblings, 1 reply; 2+ messages in thread
From: Sanjaikumar V S @ 2026-03-31 9:50 UTC (permalink / raw)
To: mwalle, pratyush
Cc: hd, linux-kernel, linux-mtd, miquel.raynal, richard,
sanjaikumar.vs, sanjaikumarvs, stable, tudor.ambarus, vigneshr
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v5] mtd: spi-nor: Fix SST AAI write mode opcode handling
2026-03-31 9:50 [PATCH v5] mtd: spi-nor: Fix SST AAI write mode opcode handling Sanjaikumar V S
@ 2026-04-01 15:53 ` Hendrik Donner
0 siblings, 0 replies; 2+ messages in thread
From: Hendrik Donner @ 2026-04-01 15:53 UTC (permalink / raw)
To: Sanjaikumar V S, mwalle, pratyush
Cc: linux-kernel, linux-mtd, miquel.raynal, richard, sanjaikumar.vs,
stable, tudor.ambarus, vigneshr
Hello,
On 3/31/26 11:50, Sanjaikumar V S wrote:
> 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?
>
retested, works the same as v4 on the SST25VF032B, don't have other SST
flashes at hand to test though.
Tested-by: Hendrik Donner <hd@os-cillation.de>
Reviewed-by: Hendrik Donner <hd@os-cillation.de>
Regards,
Hendrik
> 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;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-01 16:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 9:50 [PATCH v5] mtd: spi-nor: Fix SST AAI write mode opcode handling Sanjaikumar V S
2026-04-01 15:53 ` Hendrik Donner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox