From: Sven Ulland <sven.ulland@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>,
Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org,
Florian Fainelli <f.fainelli@gmail.com>,
Sven Ulland <sven.ulland@gmail.com>
Subject: [PATCH] watchdog: gpio: Keep GPIO level when taking over a running watchdog
Date: Thu, 19 Nov 2026 17:48:41 +0100 [thread overview]
Message-ID: <20261119164841.1847870-1-sven.ulland@gmail.com> (raw)
For a watchdog with the always-running property, the driver takes over
at probe: it requests a toggle GPIO as input, and gpio_wdt_start()
then drives it low and toggles it. These level changes happen within
microseconds, and a watchdog that needs hw-min-interval-ms resets the
system when pinged that fast, so taking over from the bootloader can
trigger a reset.
The Aruba AP-305 access point (Qualcomm IPQ4029) has an external
watchdog that resets the board when its GPIO is toggled every 6 ms or
faster. Even with hw-min-interval-ms set to 100 ms, 7 of 10 boots
started from the bootloader still reset within two seconds of the kernel
starting.
If the watchdog has both always-running and hw-min-interval-ms, request
the GPIO as is and keep its current level. The watchdog core then sends
the first ping once the minimum interval has passed. Other watchdogs are
unaffected.
Tested on the Aruba AP-305 with this change backported to Linux 6.18,
and 10 of 10 boots survived.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sven Ulland <sven.ulland@gmail.com>
---
This applies on top of watchdog-next, as it depends on Florian's commit
2791c2bc6aca ("watchdog: gpio: Support watchdogs with a minimum
heartbeat interval").
drivers/watchdog/gpio_wdt.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
index 1c79498db69e..4f4f9e9a7031 100644
--- a/drivers/watchdog/gpio_wdt.c
+++ b/drivers/watchdog/gpio_wdt.c
@@ -79,6 +79,20 @@ static int gpio_wdt_start(struct watchdog_device *wdd)
return gpio_wdt_ping(wdd);
}
+/* Take over a running watchdog without changing the GPIO level */
+static int gpio_wdt_adopt(struct gpio_wdt_priv *priv)
+{
+ int level = gpiod_get_value_cansleep(priv->gpiod);
+
+ if (level < 0)
+ return level;
+
+ priv->state = level;
+ set_bit(WDOG_HW_RUNNING, &priv->wdd.status);
+
+ return gpiod_direction_output(priv->gpiod, priv->state);
+}
+
static int gpio_wdt_stop(struct watchdog_device *wdd)
{
struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
@@ -112,6 +126,7 @@ static int gpio_wdt_probe(struct platform_device *pdev)
enum gpiod_flags gflags;
unsigned int hw_margin;
const char *algo;
+ bool adopt = false;
int ret;
priv = devm_kzalloc_obj(dev, *priv);
@@ -120,12 +135,17 @@ static int gpio_wdt_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, priv);
+ priv->always_running = device_property_read_bool(dev, "always-running");
+
ret = device_property_read_string(dev, "hw_algo", &algo);
if (ret)
return ret;
if (!strcmp(algo, "toggle")) {
priv->hw_algo = HW_ALGO_TOGGLE;
- gflags = GPIOD_IN;
+ /* Switching the GPIO to input could cause an edge */
+ adopt = priv->always_running &&
+ device_property_present(dev, "hw-min-interval-ms");
+ gflags = adopt ? GPIOD_ASIS : GPIOD_IN;
} else if (!strcmp(algo, "level")) {
priv->hw_algo = HW_ALGO_LEVEL;
gflags = GPIOD_OUT_LOW;
@@ -168,8 +188,6 @@ static int gpio_wdt_probe(struct platform_device *pdev)
return -EINVAL;
}
- priv->always_running = device_property_read_bool(dev, "always-running");
-
watchdog_set_drvdata(&priv->wdd, priv);
priv->wdd.info = &gpio_wdt_ident;
@@ -184,8 +202,13 @@ static int gpio_wdt_probe(struct platform_device *pdev)
watchdog_stop_on_reboot(&priv->wdd);
- if (priv->always_running)
+ if (adopt) {
+ ret = gpio_wdt_adopt(priv);
+ if (ret)
+ return ret;
+ } else if (priv->always_running) {
gpio_wdt_start(&priv->wdd);
+ }
return devm_watchdog_register_device(dev, &priv->wdd);
}
base-commit: 865c2d0f1dd3f0937865dd11819eeb59298a814c
--
2.43.0
reply other threads:[~2026-11-19 16:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261119164841.1847870-1-sven.ulland@gmail.com \
--to=sven.ulland@gmail.com \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--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
all inboxes | Powered by JetHome®