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>
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>
Subject: [PATCH 2/6] watchdog: tegra_wdt: Move SoC specific parts into match data
Date: Tue, 10 Nov 2026 13:39:07 +0100 [thread overview]
Message-ID: <20261110-t20-for-upstream-v1-2-5923449951fe@gmail.com> (raw)
In-Reply-To: <20261110-t20-for-upstream-v1-0-5923449951fe@gmail.com>
The driver only supports the watchdog blocks of Tegra30 and later. Move
the parts that differ between SoC generations, namely the watchdog
operations, the maximum timeout and the register setup, into a per-SoC
structure selected through the match data, so that support for Tegra20,
which has no watchdog block, can be added.
Suspend and resume call the operations through the watchdog device, so
they work with any SoC.
No functional change.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
drivers/watchdog/tegra_wdt.c | 45 +++++++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 9 deletions(-)
diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c
index 6b3f65c4d593..bb6233320579 100644
--- a/drivers/watchdog/tegra_wdt.c
+++ b/drivers/watchdog/tegra_wdt.c
@@ -9,6 +9,7 @@
#include <linux/io.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/stringify.h>
#include <linux/watchdog.h>
@@ -63,6 +64,13 @@ struct tegra_wdt {
void __iomem *tmr_regs;
};
+struct tegra_wdt_soc {
+ const struct watchdog_ops *ops;
+ unsigned int max_timeout;
+ int (*init)(struct platform_device *pdev, struct tegra_wdt *wdt,
+ void __iomem *regs);
+};
+
#define WDT_HEARTBEAT 120
static int heartbeat = WDT_HEARTBEAT;
module_param(heartbeat, int, 0);
@@ -180,14 +188,32 @@ static const struct watchdog_ops tegra_wdt_ops = {
.get_timeleft = tegra_wdt_get_timeleft,
};
+static int tegra30_wdt_init(struct platform_device *pdev, struct tegra_wdt *wdt,
+ void __iomem *regs)
+{
+ wdt->wdt_regs = regs + WDT_BASE;
+ wdt->tmr_regs = regs + WDT_TIMER_BASE;
+
+ return 0;
+}
+
+static const struct tegra_wdt_soc tegra30_wdt_soc = {
+ .ops = &tegra_wdt_ops,
+ .max_timeout = MAX_WDT_TIMEOUT,
+ .init = tegra30_wdt_init,
+};
+
static int tegra_wdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ const struct tegra_wdt_soc *soc;
struct watchdog_device *wdd;
struct tegra_wdt *wdt;
void __iomem *regs;
int ret;
+ soc = device_get_match_data(dev);
+
/* This is the timer base. */
regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(regs))
@@ -201,23 +227,24 @@ static int tegra_wdt_probe(struct platform_device *pdev)
if (!wdt)
return -ENOMEM;
- /* Initialize struct tegra_wdt. */
- wdt->wdt_regs = regs + WDT_BASE;
- wdt->tmr_regs = regs + WDT_TIMER_BASE;
-
/* Initialize struct watchdog_device. */
wdd = &wdt->wdd;
wdd->timeout = heartbeat;
wdd->info = &tegra_wdt_info;
- wdd->ops = &tegra_wdt_ops;
+ wdd->ops = soc->ops;
wdd->min_timeout = MIN_WDT_TIMEOUT;
- wdd->max_timeout = MAX_WDT_TIMEOUT;
+ wdd->max_timeout = soc->max_timeout;
wdd->parent = dev;
watchdog_set_drvdata(wdd, wdt);
watchdog_set_nowayout(wdd, nowayout);
+ /* Initialize struct tegra_wdt. */
+ ret = soc->init(pdev, wdt, regs);
+ if (ret)
+ return ret;
+
watchdog_stop_on_unregister(wdd);
ret = devm_watchdog_register_device(dev, wdd);
if (ret)
@@ -236,7 +263,7 @@ static int tegra_wdt_suspend(struct device *dev)
struct tegra_wdt *wdt = dev_get_drvdata(dev);
if (watchdog_active(&wdt->wdd))
- tegra_wdt_stop(&wdt->wdd);
+ wdt->wdd.ops->stop(&wdt->wdd);
return 0;
}
@@ -246,13 +273,13 @@ static int tegra_wdt_resume(struct device *dev)
struct tegra_wdt *wdt = dev_get_drvdata(dev);
if (watchdog_active(&wdt->wdd))
- tegra_wdt_start(&wdt->wdd);
+ wdt->wdd.ops->start(&wdt->wdd);
return 0;
}
static const struct of_device_id tegra_wdt_of_match[] = {
- { .compatible = "nvidia,tegra30-timer", },
+ { .compatible = "nvidia,tegra30-timer", .data = &tegra30_wdt_soc },
{ },
};
MODULE_DEVICE_TABLE(of, tegra_wdt_of_match);
--
2.56.0
next prev parent reply other threads:[~2026-11-10 12:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 12:39 [PATCH 0/6] watchdog: tegra_wdt: Add Tegra20 support Artur Kowalski
2026-11-10 12:39 ` [PATCH 1/6] clocksource/drivers/timer-tegra: Keep Tegra20's watchdog timers free Artur Kowalski
2026-11-10 12:39 ` Artur Kowalski [this message]
2026-11-10 12:39 ` [PATCH 3/6] watchdog: tegra_wdt: Support Tegra20 Artur Kowalski
2026-11-10 16:21 ` Krzysztof Kozlowski
2026-11-10 12:39 ` [PATCH 4/6] soc/tegra: pmc: Add an option to keep the VDE partition on Artur Kowalski
2026-11-10 12:39 ` [PATCH 5/6] soc/tegra: pmc: Add a partition power off notifier Artur Kowalski
2026-11-10 12:39 ` [PATCH 6/6] watchdog: tegra_wdt: Stop on Tegra20 VDE power off Artur Kowalski
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=20261110-t20-for-upstream-v1-2-5923449951fe@gmail.com \
--to=arturkow2000@gmail.com \
--cc=clamor95@gmail.com \
--cc=corbet@lwn.net \
--cc=daniel.lezcano@kernel.org \
--cc=jonathanh@nvidia.com \
--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=rdunlap@infradead.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®