From: Rustam Adilov <adilov@disroot.org>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
Sander Vanheule <sander@svanheule.net>,
linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Rustam Adilov <adilov@disroot.org>
Subject: [PATCH v3 1/1] watchdog: realtek-otto: Change to use regmap API
Date: Fri, 10 Jul 2026 12:43:16 +0500 [thread overview]
Message-ID: <20260710074316.46643-2-adilov@disroot.org> (raw)
In-Reply-To: <20260710074316.46643-1-adilov@disroot.org>
To make the realtek watchdog driver functional when SWAP_IO_SPACE
config is enabled, change all of the register access to be done
by regmap API which helps us to tweak endianness with big-endian
or little-endian property from within the device tree node.
Add the REGMAP_MMIO as a select to REALTEK_OTTO_WDT now that the
regmap is used.
Signed-off-by: Rustam Adilov <adilov@disroot.org>
---
drivers/watchdog/Kconfig | 1 +
drivers/watchdog/realtek_otto_wdt.c | 74 +++++++++++++++--------------
2 files changed, 39 insertions(+), 36 deletions(-)
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 08cb8612d41f..e0ef0b339abd 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1076,6 +1076,7 @@ config REALTEK_OTTO_WDT
depends on MACH_REALTEK_RTL || COMPILE_TEST
depends on COMMON_CLK
select WATCHDOG_CORE
+ select REGMAP_MMIO
default MACH_REALTEK_RTL
help
Say Y here to include support for the watchdog timer on Realtek
diff --git a/drivers/watchdog/realtek_otto_wdt.c b/drivers/watchdog/realtek_otto_wdt.c
index 9094f2189f55..5c48ffba70a2 100644
--- a/drivers/watchdog/realtek_otto_wdt.c
+++ b/drivers/watchdog/realtek_otto_wdt.c
@@ -27,6 +27,7 @@
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/reboot.h>
+#include <linux/regmap.h>
#include <linux/watchdog.h>
#define OTTO_WDT_REG_CNTR 0x0
@@ -65,7 +66,7 @@
struct otto_wdt_ctrl {
struct watchdog_device wdev;
struct device *dev;
- void __iomem *base;
+ struct regmap *regmap;
unsigned int clk_rate_khz;
int irq_phase1;
};
@@ -73,24 +74,17 @@ struct otto_wdt_ctrl {
static int otto_wdt_start(struct watchdog_device *wdev)
{
struct otto_wdt_ctrl *ctrl = watchdog_get_drvdata(wdev);
- u32 v;
-
- v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
- v |= OTTO_WDT_CTRL_ENABLE;
- iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
+ regmap_set_bits(ctrl->regmap, OTTO_WDT_REG_CTRL, OTTO_WDT_CTRL_ENABLE);
return 0;
}
static int otto_wdt_stop(struct watchdog_device *wdev)
{
struct otto_wdt_ctrl *ctrl = watchdog_get_drvdata(wdev);
- u32 v;
-
- v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
- v &= ~OTTO_WDT_CTRL_ENABLE;
- iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
+ regmap_clear_bits(ctrl->regmap, OTTO_WDT_REG_CTRL,
+ OTTO_WDT_CTRL_ENABLE);
return 0;
}
@@ -98,8 +92,7 @@ static int otto_wdt_ping(struct watchdog_device *wdev)
{
struct otto_wdt_ctrl *ctrl = watchdog_get_drvdata(wdev);
- iowrite32(OTTO_WDT_CNTR_PING, ctrl->base + OTTO_WDT_REG_CNTR);
-
+ regmap_write(ctrl->regmap, OTTO_WDT_REG_CNTR, OTTO_WDT_CNTR_PING);
return 0;
}
@@ -125,7 +118,7 @@ static int otto_wdt_determine_timeouts(struct watchdog_device *wdev, unsigned in
unsigned int total_ticks;
unsigned int prescale;
unsigned int tick_ms;
- u32 v;
+ u32 mask, val;
do {
prescale = prescale_next;
@@ -141,14 +134,11 @@ static int otto_wdt_determine_timeouts(struct watchdog_device *wdev, unsigned in
} while (phase1_ticks > OTTO_WDT_PHASE_TICKS_MAX
|| phase2_ticks > OTTO_WDT_PHASE_TICKS_MAX);
- v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
-
- v &= ~(OTTO_WDT_CTRL_PRESCALE | OTTO_WDT_CTRL_PHASE1 | OTTO_WDT_CTRL_PHASE2);
- v |= FIELD_PREP(OTTO_WDT_CTRL_PHASE1, phase1_ticks - 1);
- v |= FIELD_PREP(OTTO_WDT_CTRL_PHASE2, phase2_ticks - 1);
- v |= FIELD_PREP(OTTO_WDT_CTRL_PRESCALE, prescale);
-
- iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
+ mask = OTTO_WDT_CTRL_PRESCALE | OTTO_WDT_CTRL_PHASE1 | OTTO_WDT_CTRL_PHASE2;
+ val = FIELD_PREP(OTTO_WDT_CTRL_PHASE1, phase1_ticks - 1);
+ val |= FIELD_PREP(OTTO_WDT_CTRL_PHASE2, phase2_ticks - 1);
+ val |= FIELD_PREP(OTTO_WDT_CTRL_PRESCALE, prescale);
+ regmap_update_bits(ctrl->regmap, OTTO_WDT_REG_CTRL, mask, val);
timeout_ms = total_ticks * tick_ms;
ctrl->wdev.timeout = timeout_ms / 1000;
@@ -192,7 +182,7 @@ static int otto_wdt_restart(struct watchdog_device *wdev, unsigned long reboot_m
/* Configure for shortest timeout and wait for reset to occur */
v = FIELD_PREP(OTTO_WDT_CTRL_RST_MODE, reset_mode) | OTTO_WDT_CTRL_ENABLE;
- iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
+ regmap_write(ctrl->regmap, OTTO_WDT_REG_CTRL, v);
mdelay(3 * otto_wdt_tick_ms(ctrl, 0));
@@ -203,7 +193,7 @@ static irqreturn_t otto_wdt_phase1_isr(int irq, void *dev_id)
{
struct otto_wdt_ctrl *ctrl = dev_id;
- iowrite32(OTTO_WDT_INTR_PHASE_1, ctrl->base + OTTO_WDT_REG_INTR);
+ regmap_write(ctrl->regmap, OTTO_WDT_REG_INTR, OTTO_WDT_INTR_PHASE_1);
dev_crit(ctrl->dev, "phase 1 timeout\n");
watchdog_notify_pretimeout(&ctrl->wdev);
@@ -249,7 +239,6 @@ static int otto_wdt_probe_reset_mode(struct otto_wdt_ctrl *ctrl)
const struct fwnode_handle *node = ctrl->dev->fwnode;
int mode_count;
u32 mode;
- u32 v;
if (!node)
return -ENXIO;
@@ -271,19 +260,25 @@ static int otto_wdt_probe_reset_mode(struct otto_wdt_ctrl *ctrl)
else
return -EINVAL;
- v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
- v &= ~OTTO_WDT_CTRL_RST_MODE;
- v |= FIELD_PREP(OTTO_WDT_CTRL_RST_MODE, mode);
- iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
-
+ regmap_update_bits(ctrl->regmap, OTTO_WDT_REG_CTRL,
+ OTTO_WDT_CTRL_RST_MODE,
+ FIELD_PREP(OTTO_WDT_CTRL_RST_MODE, mode));
return 0;
}
+static const struct regmap_config realtek_otto_wdt_regmap_config = {
+ .reg_bits = 32,
+ .reg_stride = 4,
+ .val_bits = 32,
+ .disable_locking = true,
+};
+
static int otto_wdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct otto_wdt_ctrl *ctrl;
unsigned int max_tick_ms;
+ void __iomem *base;
int ret;
ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
@@ -291,18 +286,25 @@ static int otto_wdt_probe(struct platform_device *pdev)
return -ENOMEM;
ctrl->dev = dev;
- ctrl->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(ctrl->base))
- return PTR_ERR(ctrl->base);
+ base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ ctrl->regmap = devm_regmap_init_mmio(dev, base,
+ &realtek_otto_wdt_regmap_config);
+ if (IS_ERR(ctrl->regmap)) {
+ dev_err(dev, "regmap init failed\n");
+ return PTR_ERR(ctrl->regmap);
+ }
ret = otto_wdt_probe_clk(ctrl);
if (ret)
return ret;
/* Clear any old interrupts and reset initial state */
- iowrite32(OTTO_WDT_INTR_PHASE_1 | OTTO_WDT_INTR_PHASE_2,
- ctrl->base + OTTO_WDT_REG_INTR);
- iowrite32(OTTO_WDT_CTRL_DEFAULT, ctrl->base + OTTO_WDT_REG_CTRL);
+ regmap_write(ctrl->regmap, OTTO_WDT_REG_INTR,
+ OTTO_WDT_INTR_PHASE_1 | OTTO_WDT_INTR_PHASE_2);
+ regmap_write(ctrl->regmap, OTTO_WDT_REG_CTRL, OTTO_WDT_CTRL_DEFAULT);
ctrl->irq_phase1 = platform_get_irq_byname(pdev, "phase1");
if (ctrl->irq_phase1 < 0)
--
2.55.0
next prev parent reply other threads:[~2026-07-10 7:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 7:43 [PATCH v3 0/1] watchdog: realtek-otto: Make use of regmap API Rustam Adilov
2026-07-10 7:43 ` Rustam Adilov [this message]
2026-07-10 7:58 ` [PATCH v3 1/1] watchdog: realtek-otto: Change to use " sashiko-bot
2026-07-10 8:13 ` [PATCH v3 0/1] watchdog: realtek-otto: Make use of " Rustam Adilov
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=20260710074316.46643-2-adilov@disroot.org \
--to=adilov@disroot.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=sander@svanheule.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.