Skip to contentSkip to conversation

mtd: spi-nor: Fix SST AAI write mode

PATCH Superseded Sanjaikumar V S 1 participant 3 messages Feb 1

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover mtd: spi-nor: Fix SST AAI write mode

This series fixes SST flash AAI (Auto Address Increment) write mode, which was broken due to two issues:

1. When writing starts at an odd address, a single byte is programmed first using the byte program (BP) command. The flash hardware clears the Write Enable Latch (WEL) after this operation, but the driver did not re-enable writes before starting the AAI sequence.

2. When the SPI controller does not support direct mapping (nodirmap=true), the write path falls back to using an operation template created at probe time. This template has the standard page program opcode, not the AAI opcode, causing AAI writes to fail.

Tested on SST25VF016B with i.MX8X running linux-imx 5.15.71. The conditional write enable (only when AAI follows) is based on code analysis and not runtime tested.

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  | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#1 lore raw

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

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, but only when an AAI sequence will follow (len > 2 bytes remaining).

---
 drivers/mtd/spi-nor/sst.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mtd/spi-nor/sst.c +7 -0
index 175211fe6a5e..fe714e6d0914 100644
@@ -210,6 +210,13 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 		to++;
 		actual++;
+
+		/* BP clears WEL, re-enable if AAI sequence follows */
+		if (actual < len - 1) {
+			ret = spi_nor_write_enable(nor);
+			if (ret)
+				goto out;
+		}
 	}
 
 	/* Write out most of the data here. */
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 mtd: spi-nor: core: Fix AAI mode when dirmap is not available

In reply to Sanjaikumar V S

When the SPI controller does not support direct mapping (nodirmap=true), spi_nor_spimem_write_data() calls spi_mem_dirmap_write() which falls back to spi_mem_no_dirmap_write(). This fallback uses the operation template created at probe time with the standard page program opcode.

For SST flashes using AAI mode, this fails because the template cannot handle the dynamic opcode and address byte changes required by AAI.

Fix by checking nodirmap and using spi_nor_spimem_exec_op() directly, which uses the runtime-built operation with correct AAI configuration.

---
 drivers/mtd/spi-nor/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +1 -1
index d3f8a78efd3b..7caeb508d628 100644
@@ -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 {
Signature · 1 line
2.43.0