[PATCH v4 05/15] watchdog: stm32_iwdg: add pretimeout support for iwdg v4.0
From: Antonio Borneo
Date: Mon Nov 16 2026 - 08:25:44 EST
IWDG hardware version 4.0, used on STM32MP2xx platforms, has an
independent register ICR for acknowledging the pretimeout
interrupts.
This removes the need for serializing the accesses to the
EWCR register, used in previous versions.
Use the interrupt clear register (ICR) to acknowledge pretimeout
interrupts on hardware version 4.0 and later.
Don't check for HW version in stm32_iwdg_start() and always take
the lock. This makes the code simpler, avoiding the version check
and the duplicated write with and without lock, while adding the
negligible cost of the uncontended lock on HW v4.0.
Signed-off-by: Antonio Borneo <antonio.borneo@xxxxxxxxxxx>
---
drivers/watchdog/stm32_iwdg.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index 1a5715ff9fab3..b3d39d916735f 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -31,6 +31,7 @@
#define IWDG_SR 0x0C /* Status Register */
#define IWDG_WINR 0x10 /* Windows Register */
#define IWDG_EWCR 0x14 /* Early Wake-up Register */
+#define IWDG_ICR 0x18 /* Interrupt Clear Register */
#define IWDG_VERR 0x3F4 /* Version Register */
/* IWDG_KR register bit mask */
@@ -56,11 +57,14 @@
#define EWCR_EWIC BIT(14) /* Watchdog early interrupt acknowledge */
#define EWCR_EWIE BIT(15) /* Watchdog early interrupt enable */
+#define ICR_EWIC BIT(15) /* Watchdog early interrupt acknowledge */
+
/* IWDG_VERR register mask */
#define VERR_MASK GENMASK(7, 0)
/* IWDG Compatibility */
#define ONF_MIN_VER 0x31
+#define ICR_MIN_VER 0x40
/* set timeout to 100000 us */
#define TIMEOUT_US 100000
@@ -203,13 +207,17 @@ static irqreturn_t stm32_iwdg_isr(int irq, void *wdog_arg)
unsigned long flags;
u32 reg;
- spin_lock_irqsave(&wdt->lock, flags);
+ if (wdt->hw_version >= ICR_MIN_VER) {
+ reg_write(wdt->regs, IWDG_ICR, ICR_EWIC);
+ } else {
+ spin_lock_irqsave(&wdt->lock, flags);
- reg = readl(wdt->regs + IWDG_EWCR);
- reg |= EWCR_EWIC;
- writel(reg, wdt->regs + IWDG_EWCR);
+ reg = readl(wdt->regs + IWDG_EWCR);
+ reg |= EWCR_EWIC;
+ writel(reg, wdt->regs + IWDG_EWCR);
- spin_unlock_irqrestore(&wdt->lock, flags);
+ spin_unlock_irqrestore(&wdt->lock, flags);
+ }
watchdog_notify_pretimeout(wdd);
--
2.34.1