Skip to content

Commit 3666c03

Browse files
Sanjai-DCTgregkh
authored andcommitted
mtd: spi-nor: sst: Fix write enable before AAI sequence
commit a0f6424 upstream. 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: b199489 ("mtd: spi-nor: add the framework for SPI NOR") Cc: stable@vger.kernel.org Signed-off-by: Sanjaikumar V S <sanjaikumar.vs@dicortech.com> Tested-by: Hendrik Donner <hd@os-cillation.de> Reviewed-by: Hendrik Donner <hd@os-cillation.de> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b7cd63d commit 3666c03

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

drivers/mtd/spi-nor/sst.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,26 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
159159

160160
/* Start write from odd address. */
161161
if (to % 2) {
162+
bool needs_write_enable = (len > 1);
163+
162164
/* write one byte. */
163165
ret = sst_nor_write_data(nor, to, 1, buf);
164166
if (ret < 0)
165167
goto out;
166168

167169
to++;
168170
actual++;
171+
172+
/*
173+
* Byte program clears the write enable latch. If more
174+
* data needs to be written using the AAI sequence,
175+
* re-enable writes.
176+
*/
177+
if (needs_write_enable) {
178+
ret = spi_nor_write_enable(nor);
179+
if (ret)
180+
goto out;
181+
}
169182
}
170183

171184
/* Write out most of the data here. */

0 commit comments

Comments
 (0)