From: Regis Dargent <regis.dargent@gmail.com>
To: linux-sunxi@lists.linux.dev
Subject: [PATCH]: watchdog: Allow watchdog to remain enabled after probe
Date: Mon, 3 Feb 2025 18:19:55 +0100 [thread overview]
Message-ID: <20250203171955.5858-1-regis.dargent@gmail.com> (raw)
---
The sunxi_wdt watchdog unconditionally stops the watchdog during probe (on my Allwinner H616).
This avoids automatic reboot in case a problem occurs during boot (and for example handling in the bootloader).
The driver should detect if the HW watchdog is already running during probe and set its appropriate status bit to allow the kernel to handle the watchdog pings itself.
The call to sunxi_wdt_start/stop allows for proper driver and device configuration.
By default, the kernel will then ping the HW watchdog at apropriate frequency, but the user can have it stop after a time with open_timeout parameter.
drivers/watchdog/sunxi_wdt.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index b85354a99582..20fe7da445ea 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -192,6 +192,16 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)
return 0;
}
+static int sunxi_wdt_enabled(struct sunxi_wdt_dev *wdt)
+{
+ u32 reg;
+ void __iomem *wdt_base = wdt->wdt_base;
+ const struct sunxi_wdt_reg *regs = wdt->wdt_regs;
+
+ reg = readl(wdt_base + regs->wdt_mode);
+ return (reg & WDT_MODE_EN);
+}
+
static const struct watchdog_info sunxi_wdt_info = {
.identity = DRV_NAME,
.options = WDIOF_SETTIMEOUT |
@@ -268,6 +278,11 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
sunxi_wdt->wdt_dev.max_timeout = WDT_MAX_TIMEOUT;
sunxi_wdt->wdt_dev.min_timeout = WDT_MIN_TIMEOUT;
sunxi_wdt->wdt_dev.parent = dev;
+ if (sunxi_wdt_enabled(sunxi_wdt)) {
+ set_bit(WDOG_HW_RUNNING, &sunxi_wdt->wdt_dev.status);
+ } else {
+ clear_bit(WDOG_HW_RUNNING, &sunxi_wdt->wdt_dev.status);
+ }
watchdog_init_timeout(&sunxi_wdt->wdt_dev, timeout, dev);
watchdog_set_nowayout(&sunxi_wdt->wdt_dev, nowayout);
@@ -275,7 +290,10 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
watchdog_set_drvdata(&sunxi_wdt->wdt_dev, sunxi_wdt);
- sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
+ if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+ sunxi_wdt_start(&sunxi_wdt->wdt_dev);
+ else
+ sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
watchdog_stop_on_reboot(&sunxi_wdt->wdt_dev);
err = devm_watchdog_register_device(dev, &sunxi_wdt->wdt_dev);
--
2.25.1
next reply other threads:[~2025-02-03 17:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 17:19 Regis Dargent [this message]
2025-02-04 10:27 ` [PATCH]: watchdog: Allow watchdog to remain enabled after probe Andre Przywara
-- strict thread matches above, loose matches on Subject: below --
2025-02-06 9:39 Regis Dargent
2025-02-06 10:14 ` Chen-Yu Tsai
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=20250203171955.5858-1-regis.dargent@gmail.com \
--to=regis.dargent@gmail.com \
--cc=linux-sunxi@lists.linux.dev \
/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