Re: [PATCH v4 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence

Hendrik Donner
2026-03-16T13:44:49Z

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