[PATCH v2 3/3] mtd: rawnand: vf610_nfc: return an error when a command times out
From: Mehmet Fide
Date: Sat Nov 14 2026 - 14:21:26 EST
From: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>
A command that times out only prints a warning. The callers carry on,
copy whatever the SRAM buffer holds and report success.
Return -ETIMEDOUT from vf610_nfc_done() and pass it up through
->exec_op() and the page read and write hooks.
Fixes: 456930d80a2d ("mtd: nand: vf610_nfc: Freescale NFC for VF610, MPC5125 and others")
Signed-off-by: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>
---
drivers/mtd/nand/raw/vf610_nfc.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index 547eb1513893..d6d4a18432ce 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -288,9 +288,10 @@ static inline void vf610_nfc_clear_status(struct vf610_nfc *nfc)
vf610_nfc_write(nfc, NFC_IRQ_STATUS, tmp);
}
-static void vf610_nfc_done(struct vf610_nfc *nfc)
+static int vf610_nfc_done(struct vf610_nfc *nfc)
{
unsigned long timeout = msecs_to_jiffies(100);
+ int ret = 0;
vf610_nfc_clear_status(nfc);
reinit_completion(&nfc->cmd_done);
@@ -309,9 +310,12 @@ static void vf610_nfc_done(struct vf610_nfc *nfc)
dev_warn(nfc->dev, "Timeout while waiting for BUSY.\n");
vf610_nfc_clear(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT);
synchronize_irq(nfc->irq);
+ ret = -ETIMEDOUT;
}
vf610_nfc_clear_status(nfc);
+
+ return ret;
}
static irqreturn_t vf610_nfc_irq(int irq, void *data)
@@ -331,8 +335,8 @@ static inline void vf610_nfc_ecc_mode(struct vf610_nfc *nfc, int ecc_mode)
CONFIG_ECC_MODE_SHIFT, ecc_mode);
}
-static inline void vf610_nfc_run(struct vf610_nfc *nfc, u32 col, u32 row,
- u32 cmd1, u32 cmd2, u32 trfr_sz)
+static inline int vf610_nfc_run(struct vf610_nfc *nfc, u32 col, u32 row,
+ u32 cmd1, u32 cmd2, u32 trfr_sz)
{
vf610_nfc_set_field(nfc, NFC_COL_ADDR, COL_ADDR_MASK,
COL_ADDR_SHIFT, col);
@@ -348,7 +352,7 @@ static inline void vf610_nfc_run(struct vf610_nfc *nfc, u32 col, u32 row,
"col 0x%04x, row 0x%08x, cmd1 0x%08x, cmd2 0x%08x, len %d\n",
col, row, cmd1, cmd2, trfr_sz);
- vf610_nfc_done(nfc);
+ return vf610_nfc_done(nfc);
}
static inline const struct nand_op_instr *
@@ -370,6 +374,7 @@ static int vf610_nfc_cmd(struct nand_chip *chip,
int op_id = -1, trfr_sz = 0, offset = 0;
u32 col = 0, row = 0, cmd1 = 0, cmd2 = 0, code = 0;
bool force8bit = false;
+ int ret;
/*
* Some ops are optional, but the hardware requires the operations
@@ -448,9 +453,9 @@ static int vf610_nfc_cmd(struct nand_chip *chip,
cmd2 |= code << CMD_CODE_SHIFT;
- vf610_nfc_run(nfc, col, row, cmd1, cmd2, trfr_sz);
+ ret = vf610_nfc_run(nfc, col, row, cmd1, cmd2, trfr_sz);
- if (instr && instr->type == NAND_OP_DATA_IN_INSTR) {
+ if (!ret && instr && instr->type == NAND_OP_DATA_IN_INSTR) {
/*
* Don't fix endianness on page access for historical reasons.
* See comment in vf610_nfc_rd_from_sram
@@ -463,7 +468,7 @@ static int vf610_nfc_cmd(struct nand_chip *chip,
if (force8bit && (chip->options & NAND_BUSWIDTH_16))
vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT);
- return 0;
+ return ret;
}
static const struct nand_op_parser vf610_nfc_op_parser = NAND_OP_PARSER(
@@ -572,7 +577,7 @@ static int vf610_nfc_read_page(struct nand_chip *chip, uint8_t *buf,
struct mtd_info *mtd = nand_to_mtd(chip);
int trfr_sz = mtd->writesize + vf610_nfc_spare_size(mtd);
u32 row = 0, cmd1 = 0, cmd2 = 0, code = 0;
- int stat;
+ int stat, ret;
vf610_nfc_select_target(chip, chip->cur_cs);
@@ -587,8 +592,10 @@ static int vf610_nfc_read_page(struct nand_chip *chip, uint8_t *buf,
cmd2 |= code << CMD_CODE_SHIFT;
vf610_nfc_ecc_mode(nfc, nfc->ecc_mode);
- vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz);
+ ret = vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz);
vf610_nfc_ecc_mode(nfc, ECC_BYPASS);
+ if (ret)
+ return ret;
/*
* Don't fix endianness on page access for historical reasons.
@@ -651,8 +658,10 @@ static int vf610_nfc_write_page(struct nand_chip *chip, const uint8_t *buf,
cmd2 |= code << CMD_CODE_SHIFT;
vf610_nfc_ecc_mode(nfc, nfc->ecc_mode);
- vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz);
+ ret = vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz);
vf610_nfc_ecc_mode(nfc, ECC_BYPASS);
+ if (ret)
+ return ret;
ret = nand_status_op(chip, &status);
if (ret)
--
2.56.0