* [PATCH v3 1/2] spi: axi-spi-engine: fix stale SYNC IRQ pending
2026-10-07 8:52 [PATCH v3 0/2] spi: axi-spi-engine: fix stale SYNC IRQ pending Jonathan Santos
@ 2026-10-07 8:52 ` Jonathan Santos
2026-10-07 8:52 ` [PATCH v3 2/2] spi: axi-spi-engine: fix stale SYNC IRQ pending in trigger_enable Jonathan Santos
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Santos @ 2026-10-07 8:52 UTC (permalink / raw)
To: linux-kernel, linux-spi
Cc: Jonathan Santos, dlechner, broonie, nuno.sa, michael.hennerich,
jonath4nns, andriy.shevchenko, Dennis Heinzel
spi_engine_setup() sends a SYNC(1) command and polls SYNC_ID to confirm
it was parsed by the FPGA, but never clears the corresponding interrupt
pending bit (INT_PENDING[SYNC]). When the first real SPI transfer starts
and INT_SYNC is enabled, that stale pending bit fires immediately, causing
the IRQ handler to see the leftover SYNC_ID from setup, match it against
the current transfer's ID, and prematurely signal completion before the
hardware finishes.
This race manifests at low SPI clock frequencies (~2-3 MHz), where the
FPGA takes long enough to execute the transfer that handler is parsed
before it finishes. At higher SCLK rates the transfer completes fast
enough that the issue is masked.
Fix this by clearing INT_PENDING[SYNC] after the polled SYNC, ensuring no
stale interrupt is left pending.
Reported-by: Dennis Heinzel <dennis.heinzel@irs.systems>
Closes: https://ez.analog.com/linux-software-drivers/f/q-a/604145/axi-spi-engine-stale-sync-pending-can-complete-first-transfer-early-at-low-spi-clock-2-3-mhz
Fixes: 1d0ee0c9df31 ("spi: axi-spi-engine: wait for completion in setup")
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
drivers/spi/spi-axi-spi-engine.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c
index 02bbc5d0cfc5..87c05cb064cc 100644
--- a/drivers/spi/spi-axi-spi-engine.c
+++ b/drivers/spi/spi-axi-spi-engine.c
@@ -887,6 +887,7 @@ static int spi_engine_setup(struct spi_device *device)
struct spi_controller *host = device->controller;
struct spi_engine *spi_engine = spi_controller_get_devdata(host);
unsigned int reg;
+ int ret;
if (device->mode & SPI_CS_HIGH)
spi_engine->cs_inv |= BIT(spi_get_chipselect(device, 0));
@@ -922,8 +923,15 @@ static int spi_engine_setup(struct spi_device *device)
writel_relaxed(SPI_ENGINE_CMD_SYNC(1),
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
- return readl_relaxed_poll_timeout(spi_engine->base + SPI_ENGINE_REG_SYNC_ID,
- reg, reg == 1, 1, 1000);
+ ret = readl_relaxed_poll_timeout(spi_engine->base + SPI_ENGINE_REG_SYNC_ID,
+ reg, reg == 1, 1, 1 * USEC_PER_MSEC);
+
+ /* Clear the stale SYNC pending bit so it doesn't fire when the IRQ is later enabled. */
+ writel_relaxed(SPI_ENGINE_INT_SYNC, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
+ /* Read back to flush posted write. */
+ readl_relaxed(spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
+
+ return ret;
}
static int spi_engine_transfer_one_message(struct spi_controller *host,
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v3 2/2] spi: axi-spi-engine: fix stale SYNC IRQ pending in trigger_enable
2026-10-07 8:52 [PATCH v3 0/2] spi: axi-spi-engine: fix stale SYNC IRQ pending Jonathan Santos
2026-10-07 8:52 ` [PATCH v3 1/2] " Jonathan Santos
@ 2026-10-07 8:52 ` Jonathan Santos
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Santos @ 2026-10-07 8:52 UTC (permalink / raw)
To: linux-kernel, linux-spi
Cc: Jonathan Santos, dlechner, broonie, nuno.sa, michael.hennerich,
jonath4nns, andriy.shevchenko
spi_engine_trigger_enable() sends SYNC(1) and polls SYNC_ID, it never
clears the INT_PENDING[SYNC] bit afterward. This leaves a stale pending
interrupt that can fire spuriously when INT_SYNC is later enabled.
Simillarly to the fix on spi_engine_setup(), clear INT_PENDING[SYNC]
after polling the SYNC_ID.
Fixes: 8fc13b822c74 ("spi: axi-spi-engine: don't repeat mode config for offload")
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
drivers/spi/spi-axi-spi-engine.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c
index 87c05cb064cc..ead5b295e680 100644
--- a/drivers/spi/spi-axi-spi-engine.c
+++ b/drivers/spi/spi-axi-spi-engine.c
@@ -1036,7 +1036,13 @@ static int spi_engine_trigger_enable(struct spi_offload *offload)
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
ret = readl_relaxed_poll_timeout(spi_engine->base + SPI_ENGINE_REG_SYNC_ID,
- reg, reg == 1, 1, 1000);
+ reg, reg == 1, 1, 1 * USEC_PER_MSEC);
+
+ /* Clear the stale SYNC pending bit so it doesn't fire when the IRQ is later enabled */
+ writel_relaxed(SPI_ENGINE_INT_SYNC, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
+ /* Read back to flush posted write. */
+ readl_relaxed(spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
+
if (ret)
return ret;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread