[PATCH] mtd: spinand: Avoid encoding the plane select bit twice

From: 兰涛

Date: Fri Dec 04 2026 - 02:49:49 EST


From: "tao.lan" <tao.lan@xxxxxxxxxxxxx>

spinand_create_dirmap() already encodes the plane in each descriptor's
base offset. For devices with an explicit plane-select flag, the cache
read or write path also encodes it in the column passed to spi-mem.
The dirmap fallback adds the base and the column, so plane 1 on a device
with 4 KiB pages starts at column 0x4000 instead of 0x2000.

On an FPGA platform with an MX35UF4G24AD, programming odd eraseblocks
completed without an error, but the blocks read back as erased. On the
vendor kernel, removing the extra encoding stopped the whole-block
write loss. The tested device sets SPINAND_HAS_PROG_PLANE_SELECT_BIT
but not SPINAND_HAS_READ_PLANE_SELECT_BIT, so the read-side change was
not tested on hardware.

Keep the plane encoding in the dirmap descriptor only. Pass a column
relative to that descriptor to both dirmap helpers, as required by the
spi-mem API.

Fixes: ca229bdbef29 ("mtd: spinand: Add support for setting plane select bits")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: "tao.lan" <tao.lan@xxxxxxxxxxxxx>
---

Notes:
OpenAI Codex helped adapt the existing fix for upstream, draft the
commit message, and run local build checks. No new hardware tests were run.

The Airoha-only proposal (Message-ID:
20261130162743.12168-1-vikrantyadav4802@xxxxxxxxx) addresses a controller
that interprets offs as a buffer offset. This patch keeps offs relative
at the common SPI NAND callsites without changing the spi-mem fallback.

drivers/mtd/nand/spi/core.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index e88374529..176fd8bcf 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -531,9 +531,6 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
else
rdesc->info.op_tmpl->data.ecc = false;

- if (spinand->flags & SPINAND_HAS_READ_PLANE_SELECT_BIT)
- column |= req->pos.plane << fls(nanddev_page_size(nand));
-
while (nbytes) {
ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf);
if (ret < 0)
@@ -625,9 +622,6 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
else
wdesc->info.op_tmpl->data.ecc = false;

- if (spinand->flags & SPINAND_HAS_PROG_PLANE_SELECT_BIT)
- column |= req->pos.plane << fls(nanddev_page_size(nand));
-
while (nbytes) {
ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf);
if (ret < 0)

base-commit: 14b6830335eb6d70dec7a235094d66c22d38eb07
--
2.43.0