[PATCH v2] spi: spi-qpic-snand: fix various errors in qcom_spi_config_single_cw_page_read()

From: Gabor Juhos

Date: Fri Nov 06 2026 - 14:05:32 EST


The qcom_spi_config_single_cw_page_read() function has several errors.

* When the cw parameter equals with the last codeword, the function
configures the read location last registers. However it completely
misses configuring the regular read location registers for other
codewords.

* The 'use_ecc' parameter of the function is not handled in the code
at all.

* The last qcom_read_reg_dma() call which is supposed to read the
NAND_FLASH_STATUS register does not use the NAND_BAM_NEXT_SGL flag.
Due to this, the respective command element never sent to the hardware
so it never executes the read of the NAND_FLASH_STATUS register.

After fixing these issues we would end up with an open coded
version of the qcom_spi_config_cw_read() function, so drop the
current code and call the existing function instead.

Fixes: 7304d1909080 ("spi: spi-qpic: add driver for QCOM SPI NAND flash Interface")
Signed-off-by: Gabor Juhos <j4g8y7@xxxxxxxxx>
---
Changes in v2:
- Rebase on tip of spi/for-7.5
- Improve the patch to also fix two concerns raised by Sashiko in the
review of the previous version [1].
- Rephrase subject and commit message according to the changes
- Link: https://sashiko.dev/#/map/177852 # [1]
- Link to v1: https://lore.kernel.org/r/20260922-qpic-snand-fix-singlecw-readloc-v1-1-41fd834a10fe@xxxxxxxxx
---
drivers/spi/spi-qpic-snand.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index c90c2001ee8d..41685a286e38 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -588,19 +588,8 @@ static int qcom_spi_block_erase(struct qcom_nand_controller *snandc)
static void qcom_spi_config_single_cw_page_read(struct qcom_nand_controller *snandc,
bool use_ecc, int cw)
{
- __le32 *reg = &snandc->regs->read_location0;
- int num_cw = snandc->qspi->num_cw;
-
qcom_spi_config_page_read(snandc);
-
- if (cw == (num_cw - 1)) {
- reg = &snandc->regs->read_location_last0;
- qcom_write_reg_dma(snandc, reg, NAND_READ_LOCATION_LAST_CW_0, 4, NAND_BAM_NEXT_SGL);
- }
- qcom_write_reg_dma(snandc, &snandc->regs->cmd, NAND_FLASH_CMD, 1, NAND_BAM_NEXT_SGL);
- qcom_write_reg_dma(snandc, &snandc->regs->exec, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL);
-
- qcom_read_reg_dma(snandc, NAND_FLASH_STATUS, 1, 0);
+ qcom_spi_config_cw_read(snandc, use_ecc, cw);
}

static int qcom_spi_check_raw_flash_errors(struct qcom_nand_controller *snandc, int cw_cnt)

---
base-commit: 4a8faaea975be15cb636646c0d4c6ff1c2110baa
change-id: 20260922-qpic-snand-fix-singlecw-readloc-c4c89b4369f5

Best regards,
--
Gabor Juhos <j4g8y7@xxxxxxxxx>