[PATCH v9 15/18] mtd: rawnand: sunxi: avoid duplicate chip setup before page commands

From: James Hilliard

Date: Sat Oct 17 2026 - 15:54:35 EST


sunxi_nfc_select_chip() programs chip selection, timing and the
spare-area base. The page-read callbacks and PIO page/subpage writers
call it directly, then immediately call nand_read_page_op() or
nand_prog_page_begin_op(). Those helpers dispatch through
sunxi_nfc_exec_op(), which performs the same selection before executing
the command. No controller access between the two selections needs the
first one.

Remove the duplicate calls from those callbacks. Keep selection in the
DMA writer: it accesses registers and prepares DMA before program-begin,
so it cannot rely on the later exec_op() call. This removes redundant
setup only; selection still runs for each executed operation, with no
new cached state to invalidate after resets or chip switches.

Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/mtd/nand/raw/sunxi_nand.c | 12 ------------
1 file changed, 12 deletions(-)

diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
index 993e2efcee04..45172175d4e6 100644
--- a/drivers/mtd/nand/raw/sunxi_nand.c
+++ b/drivers/mtd/nand/raw/sunxi_nand.c
@@ -1685,8 +1685,6 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf,
};
int ret, i, cur_off = 0;

- sunxi_nfc_select_chip(nand, nand->cur_cs);
-
ret = nand_read_page_op(nand, page, 0, NULL, 0);
if (ret)
return ret;
@@ -1712,8 +1710,6 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf,
{
int ret;

- sunxi_nfc_select_chip(nand, nand->cur_cs);
-
ret = nand_read_page_op(nand, page, 0, NULL, 0);
if (ret)
return ret;
@@ -1739,8 +1735,6 @@ static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand,
};
int ret, i, cur_off = 0;

- sunxi_nfc_select_chip(nand, nand->cur_cs);
-
ret = nand_read_page_op(nand, page, 0, NULL, 0);
if (ret)
return ret;
@@ -1769,8 +1763,6 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand,
int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
int ret;

- sunxi_nfc_select_chip(nand, nand->cur_cs);
-
ret = nand_read_page_op(nand, page, 0, NULL, 0);
if (ret)
return ret;
@@ -1794,8 +1786,6 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand,
struct nand_ecc_ctrl *ecc = &nand->ecc;
int ret = 0, i, cur_off = 0;

- sunxi_nfc_select_chip(nand, nand->cur_cs);
-
ret = nand_prog_page_begin_op(nand, page, 0, NULL, 0);
if (ret)
return ret;
@@ -1839,8 +1829,6 @@ static int sunxi_nfc_hw_ecc_write_subpage(struct nand_chip *nand,
struct nand_ecc_ctrl *ecc = &nand->ecc;
int ret = 0, i, cur_off = 0;

- sunxi_nfc_select_chip(nand, nand->cur_cs);
-
ret = nand_prog_page_begin_op(nand, page, 0, NULL, 0);
if (ret)
return ret;

--
2.53.0