[PATCH 2/3] watchdog: omap: Add support for reading boot status

From: Diogo Ivo

Date: Fri Sep 11 2026 - 05:27:17 EST


Add support for determining the boot status of the watchdog.

Signed-off-by: Diogo Ivo <diogo.ivo@xxxxxxxxxxx>
---
One case worth mentioning explicitly here in terms of regressions:

Consider a machine where:
- the bootloader turns on the wd
- early_init = 0
- omap_wdt is compiled into the kernel
- CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED=n
- userspace does not service the watchdog

The behaviour of such a machine up until this patch was that the
the system would not reboot as the watchdog would be unconditionally
stopped. However, after this patch such systems _will_ reboot since the
watchdog will be kept on and nothing will service it. In practice, with
just this patch this will not happen since the ti-sysc.c driver (that
probes prior to the watchdog driver) will anyway stop the watchdog, but
when adding the next patch in this series to stop that behaviour this
regression becomes a real scenario.
---
drivers/watchdog/omap_wdt.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c
index e6d869e36c43..7627d3c626c2 100644
--- a/drivers/watchdog/omap_wdt.c
+++ b/drivers/watchdog/omap_wdt.c
@@ -26,6 +26,7 @@

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

+#include <linux/delay.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
@@ -42,6 +43,8 @@

#include "omap_wdt.h"

+#define RATE_32K 32768
+
static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
@@ -225,6 +228,20 @@ static const struct watchdog_ops omap_wdt_ops = {
.get_timeleft = omap_wdt_get_timeleft,
};

+static bool omap_wdt_is_running(struct omap_wdt_dev *wdev)
+{
+ unsigned long period_us = USEC_PER_SEC / RATE_32K;
+ void __iomem *base = wdev->base;
+ u32 value;
+
+ value = readl_relaxed(base + OMAP_WATCHDOG_CRR);
+
+ /* Give the watchdog some time to count if it's on */
+ usleep_range(period_us * 10, period_us * 11);
+
+ return readl_relaxed(base + OMAP_WATCHDOG_CRR) != value;
+}
+
static int omap_wdt_probe(struct platform_device *pdev)
{
struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -267,7 +284,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
wdev->wdog.bootstatus = WDIOF_CARDRESET;
}

- if (early_enable) {
+ if (omap_wdt_is_running(wdev) || early_enable) {
omap_wdt_start(&wdev->wdog);
set_bit(WDOG_HW_RUNNING, &wdev->wdog.status);
} else {

--
2.55.0