[PATCH] spi: spi-qpic-snand: fix read location register usage in qcom_spi_config_cw_read()

From: Gabor Juhos

Date: Tue Sep 22 2026 - 13:53:38 EST


While configuring a codeword read, the com_spi_config_cw_read()
function unconditionally schedules writing of the regular read
location registers. However these registers should be written
only if the actual codeword is not the last one.

Change the function to schedule writing of the registers corresponding
to the acual codeword only.

While at it, also drop the single-use 'reg' and 'num_cw' local variables
and use the respective values directly in order to make the code easier
to understand.

Fixes: 7304d1909080 ("spi: spi-qpic: add driver for QCOM SPI NAND flash Interface")
Signed-off-by: Gabor Juhos <j4g8y7@xxxxxxxxx>
---
drivers/spi/spi-qpic-snand.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 05efe6313b7f..ce03599f90df 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -503,15 +503,14 @@ static void qcom_spi_set_read_loc(struct qcom_nand_controller *snandc, int cw, i
static void
qcom_spi_config_cw_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_write_reg_dma(snandc, reg, NAND_READ_LOCATION_0, 4, NAND_BAM_NEXT_SGL);
- if (cw == (num_cw - 1)) {
- reg = &snandc->regs->read_location_last0;
- qcom_write_reg_dma(snandc, reg, NAND_READ_LOCATION_LAST_CW_0, 4,
+ if (cw == (snandc->qspi->num_cw - 1))
+ qcom_write_reg_dma(snandc, &snandc->regs->read_location_last0,
+ NAND_READ_LOCATION_LAST_CW_0, 4,
+ NAND_BAM_NEXT_SGL);
+ else
+ qcom_write_reg_dma(snandc, &snandc->regs->read_location0,
+ NAND_READ_LOCATION_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);

---
base-commit: 3d743adf090cd4c9a2120c1e02b0482e88aa0d2d
change-id: 20260922-qpic-snand-fix-cw_read-readloc-4449108092d2

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