From: Artur Kowalski <arturkow2000@gmail.com>
To: Daniel Lezcano <daniel.lezcano@kernel.org>,
Thomas Gleixner <tglx@kernel.org>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Prashant Gaikwad <pgaikwad@nvidia.com>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>
Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org,
linux-watchdog@vger.kernel.org, linux-doc@vger.kernel.org,
clamor95@gmail.com, Artur Kowalski <arturkow2000@gmail.com>,
linux-clk@vger.kernel.org
Subject: [PATCH v2 6/6] watchdog: tegra20_wdt: Stop on VDE power off
Date: Tue, 24 Nov 2026 22:06:04 +0100 [thread overview]
Message-ID: <20261124-t20-for-upstream-v2-6-440116846f97@gmail.com> (raw)
In-Reply-To: <20261124-t20-for-upstream-v2-0-440116846f97@gmail.com>
A watchdog reset doesn't reset the PMC, and Tegra20's boot ROM hangs
after it if the VDE power partition is off. Unless booted with
tegra_pmc.vde_always_on=1, the PMC driver powers the partition off when
it registers it, and genpd powers it off whenever the VDE is idle. A
watchdog started by the bootloader can still catch hangs early during
boot, before that happens.
Register a PMC partition power off notifier to stop the watchdog before
the VDE partition is powered off for the first time. If the partition is
already off, a watchdog left running by the bootloader is stopped
instead of taken over. Afterwards the watchdog refuses to start with
-EBUSY, as a reset would hang, even if the partition is powered on
again. If the notifier can't be registered, the driver warns and keeps
the watchdog running.
The notifier runs outside of the watchdog core's locking, so it only
stops the hardware, under a mutex shared with the watchdog operations,
and leaves the core's state alone. Clearing WDOG_HW_RUNNING there would
race with the core, and leak the module and device references the core
holds for a running watchdog. The core therefore keeps considering a
watchdog stopped this way as running, which shows as follows:
- While the device is closed, the core keeps pinging, which fails
without effect, and holds its references, as for any watchdog that
can't be stopped. They are released when the driver is unbound.
- Opening the device fails with -EBUSY, as the core pings a watchdog it
considers running instead of starting it, and starting fails as well.
- If user space has the device open, keepalives and timeout changes
fail with -EBUSY, so it finds out that the watchdog is gone.
Stopping is the default. With tegra_pmc.vde_always_on=1, the partition
is never powered off, so the watchdog stays usable. Booting with
tegra20_wdt.stop_on_vde_off=0 also keeps it usable, but at the risk of
the system hanging instead of rebooting.
The watchdog is stopped even with nowayout, as a watchdog that can't
reset the system is of no use. Booting with
tegra20_wdt.stop_on_vde_off=0 keeps a nowayout watchdog running after
the partition is powered off.
Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
Documentation/watchdog/watchdog-parameters.rst | 5 +
drivers/watchdog/tegra20_wdt.c | 184 ++++++++++++++++++++++---
2 files changed, 170 insertions(+), 19 deletions(-)
diff --git a/Documentation/watchdog/watchdog-parameters.rst b/Documentation/watchdog/watchdog-parameters.rst
index 8f454c82521a8..1c62d2ad22f7a 100644
--- a/Documentation/watchdog/watchdog-parameters.rst
+++ b/Documentation/watchdog/watchdog-parameters.rst
@@ -609,6 +609,11 @@ tegra20_wdt:
nowayout:
Watchdog cannot be stopped once started
(default=kernel config parameter)
+ stop_on_vde_off:
+ Stop the watchdog for good when the VDE partition is powered
+ off, as a reset would hang the boot ROM. This takes precedence
+ over nowayout. Booting with tegra_pmc.vde_always_on=1 keeps the
+ partition, and with it the watchdog, usable (default=1)
-------------------------------------------------
diff --git a/drivers/watchdog/tegra20_wdt.c b/drivers/watchdog/tegra20_wdt.c
index aa90d538f92f3..0f15805927d20 100644
--- a/drivers/watchdog/tegra20_wdt.c
+++ b/drivers/watchdog/tegra20_wdt.c
@@ -9,11 +9,15 @@
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/stringify.h>
#include <linux/watchdog.h>
+#include <soc/tegra/pmc.h>
+
/* Timer registers */
#define TIMER_PTV 0x0
#define TIMER_EN BIT(31)
@@ -40,6 +44,9 @@
struct tegra20_wdt {
struct watchdog_device wdd;
void __iomem *tmr_regs;
+ struct notifier_block powergate_nb;
+ struct mutex lock; /* hardware and vde_off */
+ bool vde_off;
};
#define WDT_HEARTBEAT 120
@@ -55,10 +62,26 @@ MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
__stringify(WATCHDOG_NOWAYOUT) ")");
-static int tegra20_wdt_start(struct watchdog_device *wdd)
+/*
+ * After a watchdog reset, Tegra20's boot ROM hangs if the VDE partition is
+ * powered off, which the PMC driver does when it registers the partition,
+ * unless booted with tegra_pmc.vde_always_on=1. By default, the watchdog is
+ * therefore only used until the partition is powered off for the first time,
+ * which still allows a watchdog started by the bootloader to catch hangs early
+ * during boot. tegra_pmc.vde_always_on=1 keeps the watchdog usable for good.
+ * Clearing this keeps it usable as well, but at the risk of the system
+ * hanging instead of rebooting. This takes precedence over nowayout, as a
+ * watchdog that can't reset the system is of no use. Clear this to keep a
+ * nowayout watchdog running.
+ */
+static bool stop_on_vde_off = true;
+module_param(stop_on_vde_off, bool, 0);
+MODULE_PARM_DESC(stop_on_vde_off,
+ "Stop the watchdog for good when the VDE partition is powered off, even with nowayout (default=1)");
+
+static int __tegra20_wdt_start(struct tegra20_wdt *wdt)
{
- struct tegra20_wdt *wdt = watchdog_get_drvdata(wdd);
- u32 period = wdd->timeout * USEC_PER_SEC / 2;
+ u32 period = wdt->wdd.timeout * USEC_PER_SEC / 2;
writel(TIMER_EN | TIMER_PERIODIC | (period - 1),
wdt->tmr_regs + TIMER_PTV);
@@ -72,9 +95,8 @@ static int tegra20_wdt_start(struct watchdog_device *wdd)
return tegra20_clk_watchdog_enable(true);
}
-static int tegra20_wdt_stop(struct watchdog_device *wdd)
+static int __tegra20_wdt_stop(struct tegra20_wdt *wdt)
{
- struct tegra20_wdt *wdt = watchdog_get_drvdata(wdd);
int ret;
ret = tegra20_clk_watchdog_enable(false);
@@ -86,32 +108,90 @@ static int tegra20_wdt_stop(struct watchdog_device *wdd)
return ret;
}
+static int tegra20_wdt_start(struct watchdog_device *wdd)
+{
+ struct tegra20_wdt *wdt = watchdog_get_drvdata(wdd);
+ int ret;
+
+ mutex_lock(&wdt->lock);
+
+ /* a reset would hang with the VDE partition powered off */
+ if (wdt->vde_off)
+ ret = -EBUSY;
+ else
+ ret = __tegra20_wdt_start(wdt);
+
+ mutex_unlock(&wdt->lock);
+
+ return ret;
+}
+
+static int tegra20_wdt_stop(struct watchdog_device *wdd)
+{
+ struct tegra20_wdt *wdt = watchdog_get_drvdata(wdd);
+ int ret;
+
+ mutex_lock(&wdt->lock);
+ ret = __tegra20_wdt_stop(wdt);
+ mutex_unlock(&wdt->lock);
+
+ return ret;
+}
+
static int tegra20_wdt_ping(struct watchdog_device *wdd)
{
struct tegra20_wdt *wdt = watchdog_get_drvdata(wdd);
+ int ret = 0;
+
+ mutex_lock(&wdt->lock);
+
+ /*
+ * The notifier stopped the watchdog behind the core's back, which keeps
+ * considering it running. Fail the pings, so that opening the device
+ * fails, and user space that has it open finds out.
+ */
+ if (wdt->vde_off) {
+ ret = -EBUSY;
+ goto unlock;
+ }
/*
* Clearing the interrupt alone doesn't restart the timer's period, so
* the reset could follow as soon as half the timeout after the ping.
* Rewriting the timer setting restarts the period. The interrupt is
- * cleared afterwards, so one fired in between doesn't count.
+ * cleared afterwards, so one fired in between doesn't count. While
+ * stopped, the timer setting reads back as 0, so this doesn't start it.
*/
writel(readl(wdt->tmr_regs + TIMER_PTV), wdt->tmr_regs + TIMER_PTV);
writel(TIMER_PCR_INTR_CLR, wdt->tmr_regs + TIMER_PCR);
- return 0;
+unlock:
+ mutex_unlock(&wdt->lock);
+
+ return ret;
}
static int tegra20_wdt_set_timeout(struct watchdog_device *wdd,
unsigned int timeout)
{
- wdd->timeout = timeout;
+ struct tegra20_wdt *wdt = watchdog_get_drvdata(wdd);
+ int ret = 0;
- /* starting again reprograms the running watchdog */
- if (watchdog_active(wdd))
- return tegra20_wdt_start(wdd);
+ mutex_lock(&wdt->lock);
- return 0;
+ if (wdt->vde_off) {
+ ret = -EBUSY;
+ } else {
+ wdd->timeout = timeout;
+
+ /* starting again reprograms the running watchdog */
+ if (watchdog_active(wdd))
+ ret = __tegra20_wdt_start(wdt);
+ }
+
+ mutex_unlock(&wdt->lock);
+
+ return ret;
}
static const struct watchdog_info tegra20_wdt_info = {
@@ -130,30 +210,96 @@ static const struct watchdog_ops tegra20_wdt_ops = {
.set_timeout = tegra20_wdt_set_timeout,
};
+/*
+ * This runs outside of the watchdog core's locking, and possibly before the
+ * watchdog is registered, so it must not touch the core's state, such as
+ * WDOG_ACTIVE and WDOG_HW_RUNNING. The core keeps considering a stopped
+ * watchdog as running, along with the references it holds for it, and the
+ * operations refuse to start or ping it instead.
+ */
+static int tegra20_wdt_powergate_notify(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct tegra20_wdt *wdt = container_of(nb, struct tegra20_wdt,
+ powergate_nb);
+ unsigned int id = *(unsigned int *)data;
+
+ if (event != TEGRA_PMC_POWERGATE_POWER_OFF ||
+ id != TEGRA_POWERGATE_VDEC)
+ return NOTIFY_DONE;
+
+ mutex_lock(&wdt->lock);
+
+ if (!wdt->vde_off) {
+ wdt->vde_off = true;
+ __tegra20_wdt_stop(wdt);
+
+ dev_info(wdt->wdd.parent,
+ "VDE powered off, watchdog stopped for good\n");
+ }
+
+ mutex_unlock(&wdt->lock);
+
+ return NOTIFY_OK;
+}
+
+static void tegra20_wdt_unregister_notifier(void *data)
+{
+ struct tegra20_wdt *wdt = data;
+
+ tegra_pmc_powergate_unregister_notifier(&wdt->powergate_nb);
+}
+
static int tegra20_wdt_init(struct platform_device *pdev,
struct tegra20_wdt *wdt,
void __iomem *regs)
{
struct device *dev = &pdev->dev;
- int ret;
+ int ret, err;
wdt->tmr_regs = regs;
+ ret = devm_mutex_init(dev, &wdt->lock);
+ if (ret)
+ return ret;
+
+ /*
+ * If the VDE partition is already powered off, the notifier is called
+ * right away and stops a watchdog left running by the bootloader.
+ */
+ if (stop_on_vde_off) {
+ wdt->powergate_nb.notifier_call = tegra20_wdt_powergate_notify;
+
+ err = tegra_pmc_powergate_register_notifier(&wdt->powergate_nb);
+ if (err) {
+ dev_warn(dev, "failed to register VDE notifier: %d\n",
+ err);
+ } else {
+ ret = devm_add_action_or_reset(dev,
+ tegra20_wdt_unregister_notifier, wdt);
+ if (ret)
+ return ret;
+ }
+ }
+
/*
* The bootloader may leave the watchdog running. Take it over with
* our own timeout and timer 1, and let the core ping it until user
* space opens the device.
*/
- if (tegra20_clk_watchdog_is_enabled()) {
+ mutex_lock(&wdt->lock);
+
+ if (!wdt->vde_off && tegra20_clk_watchdog_is_enabled()) {
dev_info(dev, "watchdog left running by the bootloader, taking it over (timeout %u sec)\n",
wdt->wdd.timeout);
- ret = tegra20_wdt_start(&wdt->wdd);
- if (ret)
- return ret;
- set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
+ ret = __tegra20_wdt_start(wdt);
+ if (!ret)
+ set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
}
- return 0;
+ mutex_unlock(&wdt->lock);
+
+ return ret;
}
static int tegra20_wdt_probe(struct platform_device *pdev)
--
2.56.1
prev parent reply other threads:[~2026-11-24 21:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 21:05 [PATCH v2 0/6] watchdog: Add Tegra20 watchdog driver Artur Kowalski
2026-11-24 21:05 ` [PATCH v2 1/6] clocksource/drivers/timer-tegra: Keep Tegra20's watchdog timers free Artur Kowalski
2026-11-24 21:06 ` [PATCH v2 2/6] clk: tegra20: Add watchdog reset control helpers Artur Kowalski
2026-11-24 21:06 ` [PATCH v2 3/6] watchdog: Add Tegra20 watchdog driver Artur Kowalski
2026-11-24 21:06 ` [PATCH v2 4/6] soc/tegra: pmc: Add an option to keep the VDE partition on Artur Kowalski
2026-11-24 21:06 ` [PATCH v2 5/6] soc/tegra: pmc: Add a partition power off notifier Artur Kowalski
2026-11-24 21:06 ` Artur Kowalski [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=20261124-t20-for-upstream-v2-6-440116846f97@gmail.com \
--to=arturkow2000@gmail.com \
--cc=bmasney+clk@redhat.com \
--cc=clamor95@gmail.com \
--cc=corbet@lwn.net \
--cc=daniel.lezcano@kernel.org \
--cc=jbrunet+clk@baylibre.com \
--cc=jonathanh@nvidia.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=p.zabel@pengutronix.de \
--cc=pgaikwad@nvidia.com \
--cc=rdunlap@infradead.org \
--cc=sboyd@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@kernel.org \
--cc=thierry.reding@kernel.org \
--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®