public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] mtd: spi-nor: Fix SST AAI write mode
@ 2026-03-11 10:30 Sanjaikumar V S
  2026-03-11 10:30 ` [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence Sanjaikumar V S
  2026-03-11 10:30 ` [PATCH v4 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available Sanjaikumar V S
  0 siblings, 2 replies; 5+ messages in thread
From: Sanjaikumar V S @ 2026-03-11 10:30 UTC (permalink / raw)
  To: mwalle
  Cc: linux-kernel, linux-mtd, miquel.raynal, pratyush, richard,
	sanjaikumar.vs, sanjaikumarvs, stable, tudor.ambarus, vigneshr

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

This patch series addresses two distinct problems affecting SST flash
Auto Address Increment write functionality:

1. When writes begin at odd addresses, a single byte is programmed first
   using byte program command, which clears the Write Enable Latch. The
   driver fails to re-enable writes before the AAI sequence.

2. When the SPI controller lacks direct mapping support, the fallback
   path uses a probe-time operation template with standard page program
   opcodes instead of AAI opcodes.

Changes in v4:
- Resent as new thread (v3 was incorrectly sent as reply to v2)
- Patch 2/2: Added Fixes tag

Changes in v3:
- Patch 1/2: Use local boolean 'needs_write_enable' for clarity as
  suggested by Michael Walle
- Patch 1/2: Improved comment explaining the fix
- Patch 1/2: Added Fixes tag

Changes in v2:
- Split fixes into separate patches
- Added detailed commit messages

Sanjaikumar V S (2):
  mtd: spi-nor: sst: Fix write enable before AAI sequence
  mtd: spi-nor: core: Fix AAI mode when dirmap is not available

 drivers/mtd/spi-nor/core.c |  2 +-
 drivers/mtd/spi-nor/sst.c  | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

--
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence
  2026-03-11 10:30 [PATCH v4 0/2] mtd: spi-nor: Fix SST AAI write mode Sanjaikumar V S
@ 2026-03-11 10:30 ` Sanjaikumar V S
  2026-03-16 13:44   ` Hendrik Donner
  2026-03-11 10:30 ` [PATCH v4 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available Sanjaikumar V S
  1 sibling, 1 reply; 5+ messages in thread
From: Sanjaikumar V S @ 2026-03-11 10:30 UTC (permalink / raw)
  To: mwalle
  Cc: linux-kernel, linux-mtd, miquel.raynal, pratyush, richard,
	sanjaikumar.vs, sanjaikumarvs, stable, tudor.ambarus, vigneshr

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

When writing to SST flash starting at an odd address, a single byte is
first programmed using the byte program (BP) command. After this
operation completes, the flash hardware automatically clears the Write
Enable Latch (WEL) bit.

If an AAI (Auto Address Increment) word program sequence follows, it
requires WEL to be set. Without re-enabling writes, the AAI sequence
fails.

Add spi_nor_write_enable() after the odd-address byte program when more
data needs to be written. Use a local boolean for clarity.

Fixes: b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")
Cc: stable@vger.kernel.org
Signed-off-by: Sanjaikumar V S <sanjaikumar.vs@dicortech.com>
---
 drivers/mtd/spi-nor/sst.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 175211fe6a5e..db02c14ba16f 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -203,6 +203,8 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 	/* Start write from odd address. */
 	if (to % 2) {
+		bool needs_write_enable = (len > 1);
+
 		/* write one byte. */
 		ret = sst_nor_write_data(nor, to, 1, buf);
 		if (ret < 0)
@@ -210,6 +212,17 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 		to++;
 		actual++;
+
+		/*
+		 * Byte program clears the write enable latch. If more
+		 * data needs to be written using the AAI sequence,
+		 * re-enable writes.
+		 */
+		if (needs_write_enable) {
+			ret = spi_nor_write_enable(nor);
+			if (ret)
+				goto out;
+		}
 	}
 
 	/* Write out most of the data here. */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available
  2026-03-11 10:30 [PATCH v4 0/2] mtd: spi-nor: Fix SST AAI write mode Sanjaikumar V S
  2026-03-11 10:30 ` [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence Sanjaikumar V S
@ 2026-03-11 10:30 ` Sanjaikumar V S
  2026-03-16 13:44   ` Hendrik Donner
  1 sibling, 1 reply; 5+ messages in thread
From: Sanjaikumar V S @ 2026-03-11 10:30 UTC (permalink / raw)
  To: mwalle
  Cc: linux-kernel, linux-mtd, miquel.raynal, pratyush, 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.

Add check for nodirmap flag to ensure the code falls through to
spi_nor_spimem_exec_op() path which builds the operation at runtime
with the correct program_opcode set by sst_nor_write_data().

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>
---
 drivers/mtd/spi-nor/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 8ffeb41c3e08..cb7f4d447156 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 {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence
  2026-03-11 10:30 ` [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence Sanjaikumar V S
@ 2026-03-16 13:44   ` Hendrik Donner
  0 siblings, 0 replies; 5+ messages in thread
From: Hendrik Donner @ 2026-03-16 13:44 UTC (permalink / raw)
  To: Sanjaikumar V S, mwalle
  Cc: linux-kernel, linux-mtd, miquel.raynal, pratyush, richard,
	sanjaikumar.vs, stable, tudor.ambarus, vigneshr

Hello,

On 3/11/26 11:30, Sanjaikumar V S wrote:
> From: Sanjaikumar V S <sanjaikumar.vs@dicortech.com>
> 
> When writing to SST flash starting at an odd address, a single byte is
> first programmed using the byte program (BP) command. After this
> operation completes, the flash hardware automatically clears the Write
> Enable Latch (WEL) bit.
> 
> If an AAI (Auto Address Increment) word program sequence follows, it
> requires WEL to be set. Without re-enabling writes, the AAI sequence
> fails.
> 
> Add spi_nor_write_enable() after the odd-address byte program when more
> data needs to be written. Use a local boolean for clarity.
> 
> Fixes: b199489d37b2 ("mtd: spi-nor: add the framework for SPI NOR")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sanjaikumar V S <sanjaikumar.vs@dicortech.com>
> ---
>   drivers/mtd/spi-nor/sst.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
> index 175211fe6a5e..db02c14ba16f 100644
> --- a/drivers/mtd/spi-nor/sst.c
> +++ b/drivers/mtd/spi-nor/sst.c
> @@ -203,6 +203,8 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>   
>   	/* Start write from odd address. */
>   	if (to % 2) {
> +		bool needs_write_enable = (len > 1);
> +
>   		/* write one byte. */
>   		ret = sst_nor_write_data(nor, to, 1, buf);
>   		if (ret < 0)
> @@ -210,6 +212,17 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>   
>   		to++;
>   		actual++;
> +
> +		/*
> +		 * Byte program clears the write enable latch. If more
> +		 * data needs to be written using the AAI sequence,
> +		 * re-enable writes.
> +		 */
> +		if (needs_write_enable) {
> +			ret = spi_nor_write_enable(nor);
> +			if (ret)
> +				goto out;
> +		}
>   	}
>   
>   	/* Write out most of the data here. */

found a board with

   spi-nor spi0.0: sst25vf032b (4096 Kbytes)

for testing. Tests are on top of

   94645aa41bf9e (mtd/spi-nor/next)

This should be done according to the datasheet and fixes that only 1
byte is written on writes to a an odd address and following AAI writes
fail, resulting in something looking like this:

ffa9 ffff ffff ffff ffff ffff ffff ffff

when

24a9 91b3 7cb6 f01c 2994 c368 fdad d3a2

was supposed to be written.

Tested-by: Hendrik Donner <hd@os-cillation.de>
Reviewed-by: Hendrik Donner <hd@os-cillation.de>

Regards,
Hendrik

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available
  2026-03-11 10:30 ` [PATCH v4 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available Sanjaikumar V S
@ 2026-03-16 13:44   ` Hendrik Donner
  0 siblings, 0 replies; 5+ messages in thread
From: Hendrik Donner @ 2026-03-16 13:44 UTC (permalink / raw)
  To: Sanjaikumar V S, mwalle
  Cc: linux-kernel, linux-mtd, miquel.raynal, pratyush, richard,
	sanjaikumar.vs, stable, tudor.ambarus, vigneshr

Hello,

On 3/11/26 11:30, 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.
> 
> Add check for nodirmap flag to ensure the code falls through to
> spi_nor_spimem_exec_op() path which builds the operation at runtime
> with the correct program_opcode set by sst_nor_write_data().
> 
> 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>
> ---
>   drivers/mtd/spi-nor/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 8ffeb41c3e08..cb7f4d447156 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 {

found a board with

   spi-nor spi0.0: sst25vf032b (4096 Kbytes)

for testing. Tests are on top of

   94645aa41bf9e (mtd/spi-nor/next)

This patch fixes write errors, easily seen with flashcp, which tries to
verify writes:

   flashcp: verification mismatch at 0x0

Tested-by: Hendrik Donner <hd@os-cillation.de>
Reviewed-by: Hendrik Donner <hd@os-cillation.de>

Regards,
Hendrik

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-16 13:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 10:30 [PATCH v4 0/2] mtd: spi-nor: Fix SST AAI write mode Sanjaikumar V S
2026-03-11 10:30 ` [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence Sanjaikumar V S
2026-03-16 13:44   ` Hendrik Donner
2026-03-11 10:30 ` [PATCH v4 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available Sanjaikumar V S
2026-03-16 13:44   ` Hendrik Donner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox