From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Wanming Gao <wanming.gao@mediatek.com>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, wallace.yu@mediatek.com,
Jarried.Lin@mediatek.com, vince-wl.liu@mediatek.com
Subject: Re: [PATCH] watchdog: mediatek: Enable pretimeout support
Date: Wed, 26 Aug 2026 04:36:15 +0000 [thread overview]
Message-ID: <ao5tP40Wi-9jJgKk@google.com> (raw)
In-Reply-To: <20260824132914.2662346-1-wanming.gao@mediatek.com>
On Mon, Aug 24, 2026 at 09:29:12PM +0800, Wanming Gao wrote:
> The watchdog pretimeout interrupt needs to be deasserted after the
> hardware pretimeout event is received. Add IRQ level control handling
> to the MediaTek watchdog interrupt handler so the interrupt is cleared
> before notifying the watchdog core.
This could be clearer. Please merge this with the third paragraph to
explain the why rather than just the what (e.g., explain that the hardware
uses level triggering and requires an edge transition to clear the
interrupt, if that is the case).
> Serialize all WDT_MODE read-modify-write operations using the existing
> watchdog spinlock. Initialize the lock before registering the interrupt
> handler and hold it across the complete 70us IRQ level toggle sequence.
> This prevents concurrent watchdog start, stop, or pretimeout updates
> from overwriting the temporary IRQ level state and disrupting the
> deassert pulse.
Please expand on the why here as well. The 70us delay specifically needs
to be explained in the commit message (e.g., waiting for the clock domain
crossing to the 32KHz clock).
>
> This avoids leaving the watchdog pretimeout interrupt asserted, prevents
> a potential interrupt storm, and allows the kernel to handle the
> pretimeout event properly before the final watchdog reset.
As mentioned above, please merge this with the first paragraph.
>
> Test: Boot ok, trigger watchdog pretimeout case and verify the
> pretimeout interrupt is received and handled before watchdog reset.
It is expected that patches are tested before submission. Unless you are
specifying the exact board/platform you tested against, please drop this
section.
> diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c
...
> +static void mtk_wdt_deassert_irq(struct watchdog_device *wdd)
> +{
> + struct mtk_wdt_dev *mtk_wdt = watchdog_get_drvdata(wdd);
> + void __iomem *wdt_base = mtk_wdt->wdt_base;
> + unsigned long flags;
> + u32 reg;
> +
> + spin_lock_irqsave(&mtk_wdt->lock, flags);
> + reg = ioread32(wdt_base + WDT_MODE);
> +
> + if (reg & WDT_MODE_IRQ_LEVEL_EN) {
> + reg &= ~WDT_MODE_IRQ_LEVEL_EN;
> + iowrite32(reg | WDT_MODE_KEY, wdt_base + WDT_MODE);
> + /*
> + * Wait for two 32KHz watchdog clock cycles so the
> + * hardware can latch the IRQ level change across the clock
> + * domain.
> + */
> + udelay(WDT_IRQ_LEVEL_SYNC_US);
> + reg = ioread32(wdt_base + WDT_MODE);
> + reg |= WDT_MODE_IRQ_LEVEL_EN;
> + } else {
> + reg |= WDT_MODE_IRQ_LEVEL_EN;
> + iowrite32(reg | WDT_MODE_KEY, wdt_base + WDT_MODE);
> + udelay(WDT_IRQ_LEVEL_SYNC_US);
> + reg = ioread32(wdt_base + WDT_MODE);
> + reg &= ~WDT_MODE_IRQ_LEVEL_EN;
> + }
Is the main purpose of toggling WDT_MODE_IRQ_LEVEL_EN simply to clear the
interrupt? Since the value of the bit doesn't seem to matter.
> + iowrite32(reg | WDT_MODE_KEY, wdt_base + WDT_MODE);
> + ioread32(wdt_base + WDT_MODE);
This read deserves a comment. Otherwise, it looks like a NOP and might be
accidentally removed by someone in the future.
> + spin_unlock_irqrestore(&mtk_wdt->lock, flags);
> +}
The function can be simplified a bit, e.g.:
/* Trigger a state change */
reg ^= WDT_MODE_IRQ_LEVEL_EN;
iowrite32(...);
/*
* Wait for two 32KHz watchdog clock cycles ...
*/
udelay(...);
/* Restore to its original state */
reg = ioread32(...)
reg ^= WDT_MODE_IRQ_LEVEL_EN;
iowrite32(...)
prev parent reply other threads:[~2026-08-26 4:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:29 [PATCH] watchdog: mediatek: Enable pretimeout support Wanming Gao
2026-08-26 4:36 ` Tzung-Bi Shih [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ao5tP40Wi-9jJgKk@google.com \
--to=tzungbi@kernel.org \
--cc=Jarried.Lin@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=matthias.bgg@gmail.com \
--cc=vince-wl.liu@mediatek.com \
--cc=wallace.yu@mediatek.com \
--cc=wanming.gao@mediatek.com \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox