Skip to contentSkip to conversation

watchdog: ma35d1: Add support for MA35D1 Watchdog

PATCH Superseded Zi-Yu Chen 3 participants 9 messages Jul 24 – Jul 29

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zi-Yu Chen

author
#0 lore raw

v2 cover watchdog: ma35d1: Add support for MA35D1 Watchdog

This patch series introduces watchdog timer support for the Nuvoton MA35D1 SoC platform.

The MA35D1 watchdog timer hardware provides a programmable countdown timer capable of triggering a system reset upon timeout expiration or generating an interrupt to wake up the system from low-power states.

Key features supported in this driver:
- Standard watchdog operations (start, stop, ping, set_timeout).
- Boot status detection to identify watchdog reset events (WDIOF_CARDRESET).
- Power management support including suspend/resume and wakeup functionality.

Series breakdown:
- Patch 1: Add DT binding documentation for Nuvoton MA35D1 watchdog.
- Patch 2: Add the watchdog driver implementation for MA35D1.
- Patch 3: Add the watchdog node in the MA35D1 SoC DeviceTree file.

Testing:
- Tested on the Nuvoton MA35D1 development board using standard watchdog test utilities (e.g., watchdog-test from tools/testing/selftests/watchdog).

---
Changes in v2:
- Added watchdog_stop_on_reboot() and watchdog_stop_on_unregister().
Addressed automated review feedback (Sashiko AI) and reviewer comments:
- Remove redundant 'struct device *dev' from driver private structure.
- Add ma35d1_wdt_wait_sync() after writing WDTEN to REG_WDT_CTL in ma35d1_wdt_start().
- Preserve wdt_dev->timeout when requested timeout exceeds hardware maximum.
- Replace dev_pm_set_wake_irq with devm_pm_set_wake_irq.
- Set WDOG_HW_RUNNING if watchdog was already enabled by bootloader.
- Fix IRQ variable type from u32 to int.
- Removed unnecessary select MFD_SYSCON from Kconfig.

Note: RMW operations on REG_WDT_CTL have no runtime side-effects on W1C
flags as IF/WKF are only utilized during PM suspend/resume window.

Zi-Yu Chen (3):
dt-bindings: watchdog: Add MA35D1 Watchdog binding
watchdog: Add Nuvoton MA35D1 watchdog driver support
arm64: dts: nuvoton: Add WDT node for MA35D1 SoC

 .../bindings/watchdog/nuvoton,ma35d1-wdt.yaml |  55 +++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       |   7 +
 drivers/watchdog/Kconfig                      |  10 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/ma35d1_wdt.c                 | 358 ++++++++++++++++++
 5 files changed, 431 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/nuvoton,ma35d1-wdt.yaml
 create mode 100644 drivers/watchdog/ma35d1_wdt.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/3 dt-bindings: watchdog: Add MA35D1 Watchdog binding

Add device tree binding documentation for the watchdog timer (WDT) controller found on Nuvoton MA35D1 SoC.

---
 .../bindings/watchdog/nuvoton,ma35d1-wdt.yaml | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/nuvoton,ma35d1-wdt.yaml
Documentation/devicetree/bindings/watchdog/nuvoton,ma35d1-wdt.yaml new file +55 -0
new file mode 100644
index 000000000000..aced7d77a7d3
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/nuvoton,ma35d1-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Watchdog Timer
+
+maintainers:
+  - Zi-Yu Chen <[email protected]>
+
+allOf:
+  - $ref: watchdog.yaml#
+
+properties:
+  compatible:
+    enum:
+      - nuvoton,ma35d1-wdt
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+        wdt1: watchdog@40440000 {
+          compatible = "nuvoton,ma35d1-wdt";
+          reg = <0x0 0x40440000 0x0 0x100>;
+          interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>;
+          clocks = <&clk WDT1_GATE>;
+        };
+    };
+...
Signature · 1 line
2.34.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] dt-bindings: watchdog: Add MA35D1 Watchdog binding

Quoted 4 lines · Zi-Yu Chen

Add device tree binding documentation for the watchdog timer (WDT) controller found on Nuvoton MA35D1 SoC.

A nit, subject: drop second/last, redundant "binding". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Best regards,
Krzysztof

author
#3 lore raw

Re: [PATCH v2 1/3] dt-bindings: watchdog: Add MA35D1 Watchdog binding

Krzysztof Kozlowski 於 2026/7/28 下午 07:47 寫道:

Quoted 11 lines · Zi-Yu Chen
Quoted 4 lines

Add device tree binding documentation for the watchdog timer (WDT) controller found on Nuvoton MA35D1 SoC.

A nit, subject: drop second/last, redundant "binding". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Quoted 5 lines

Best regards,
Krzysztof

Hi Krzysztof,

Thanks for the review and the Reviewed-by tag.
I'll drop the redundant "binding" from the subject in the next revision.

Thanks,
Zi-Yu Chen

author
#4 lore raw

PATCH v2 2/3 watchdog: Add Nuvoton MA35D1 watchdog driver support

In reply to Zi-Yu Chen

Add driver support for the Watchdog Timer (WDT) integrated in Nuvoton MA35D1 SoC. This driver provides standard watchdog functionality, including timeout configuration, ping, and system reset support via the watchdog framework.

---
 drivers/watchdog/Kconfig      |  10 +
 drivers/watchdog/Makefile     |   1 +
 drivers/watchdog/ma35d1_wdt.c | 358 ++++++++++++++++++++++++++++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/watchdog/ma35d1_wdt.c
drivers/watchdog/Kconfig +10 -0
index 08cb8612d41f..972740fd36a6 100644
@@ -720,6 +720,16 @@ config STMP3XXX_RTC_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called stmp3xxx_rtc_wdt.
 
+config MA35D1_WDT
+	tristate "Nuvoton MA35D1 Watchdog Timer"
+	depends on ARCH_MA35 || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  for the Nuvoton MA35D1 series microprosser.
+	  To compile this driver as a module, choose M here: the
+	  module will be called ma35d1_wdt.
+
 config TS4800_WATCHDOG
 	tristate "TS-4800 Watchdog"
 	depends on HAS_IOMEM && OF
drivers/watchdog/Makefile +1 -0
index bc1d52220f22..a7889eb48c7f 100644
@@ -104,6 +104,7 @@ obj-$(CONFIG_APPLE_WATCHDOG) += apple_wdt.o
 obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
 obj-$(CONFIG_MARVELL_GTI_WDT) += marvell_gti_wdt.o
 obj-$(CONFIG_GUNYAH_WATCHDOG) += gunyah_wdt.o
+obj-$(CONFIG_MA35D1_WDT) += ma35d1_wdt.o
 
 # X86 (i386 + ia64 + x86_64) Architecture
 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/ma35d1_wdt.c new file +358 -0

358 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v2 2/3] watchdog: Add Nuvoton MA35D1 watchdog driver support

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Writes to REG_WDT_CTL are missing required hardware synchronization waits (SYNC bit), risking…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Writes to REG_WDT_CTL are missing required hardware synchronization waits (SYNC bit), risking dropped writes and hardware state corruption.
- [High] The watchdog timer is not paused during system suspend if it was running from the bootloader but not yet opened by userspace, leading to unintended system resets.
- [High] Driver fails to synchronize the hardware timeout with the software configuration when inheriting a running watchdog during probe.
- [High] Read-modify-write operations on REG_WDT_CTL inadvertently clear W1C (Write-1-to-Clear) status flags, leading to lost interrupts and wakeup events.
- [Medium] In ma35d1_wdt_resume(), the driver writes to REG_WDT_RSTCNT before ensuring the control register changes have synchronized.
- [Low] Spelling mistake in Kconfig help text.
--

--- Patch [2]: [PATCH v2 2/3] watchdog: Add Nuvoton MA35D1 watchdog driver support --- commit 31ed5d4971c74d4f75935b7f98c40e226cdc3521
Author: Zi-Yu Chen <[email protected]>

watchdog: Add Nuvoton MA35D1 watchdog driver support

This commit adds a new watchdog driver for the Nuvoton MA35D1 SoC. It provides support for timeout configuration, ping, and system reset functionality via the standard watchdog framework.

Quoted 5 lines
drivers/watchdog/Kconfig +0 -0
index 08cb8612d41fe..972740fd36a69 100644

drivers/watchdog/Kconfig config STMP3XXX_RTC_WATCHDOG · line 729

Quoted 10 lines
drivers/watchdog/Kconfig +7 -0
@@ -720,6 +720,16 @@ config STMP3XXX_RTC_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called stmp3xxx_rtc_wdt.
 
+config MA35D1_WDT
+	tristate "Nuvoton MA35D1 Watchdog Timer"
+	depends on ARCH_MA35 || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  for the Nuvoton MA35D1 series microprosser.

[Severity: Low]
Is "microprosser" a typo here? Did you mean "microprocessor"?

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +0 -0
new file mode 100644
index 0000000000000..e5247e55dfee4

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 83

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+static int ma35d1_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	val &= ~WDTEN;
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);

[Severity: High]
Will this read-modify-write inadvertently clear Write-1-to-Clear (W1C) flags like IF, WKF, or RSTF?

Looking at ma35d1_wdt_isr(), it appears that reading a 1 and writing it back clears the flag. Should these W1C flags be explicitly masked out when doing read-modify-write operations on REG_WDT_CTL here, and similarly in other functions like ma35d1_wdt_set_timeout(), ma35d1_wdt_start(), and ma35d1_wdt_suspend()?

[ ... ]

Quoted 6 lines
drivers/watchdog/ma35d1_wdt.c new file +6 -0
+static int ma35d1_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				  unsigned int timeout)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned long target_ticks;
+	unsigned int val, i;

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 136

Quoted 9 lines
drivers/watchdog/ma35d1_wdt.c new file +9 -0
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	val &= ~TOUTSEL;
+	val |= FIELD_PREP(TOUTSEL, i);
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+
+	ma35d1_wdt_ping(wdt_dev);
+	return 0;
+}

[Severity: High]
Does this writel_relaxed() require a call to ma35d1_wdt_wait_sync() before proceeding?

Without waiting for the SYNC bit, could the immediate ping command be ignored by the hardware or cause hardware state corruption?

Quoted 6 lines
drivers/watchdog/ma35d1_wdt.c new file +6 -0
+static int ma35d1_wdt_start(struct watchdog_device *wdt_dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	void __iomem *wdt_base = ma35d1_wdt->wdt_base;
+	unsigned int val;
+	int ret;

drivers/watchdog/ma35d1_wdt.c line 153

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+
+	ret = ma35d1_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
+	if (ret < 0)
+		return ret;
+
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(wdt_base + REG_WDT_CTL);
+	val |= (WDTEN | RSTEN);
+
+	writel_relaxed(val, wdt_base + REG_WDT_CTL);

[Severity: High]
Because ma35d1_wdt_set_timeout() writes to REG_WDT_CTL without waiting for sync, and then ma35d1_wdt_start() immediately performs another read-modify-write on the same register, could this back-to-back unsynchronized access cause dropped writes and prevent the watchdog from starting properly?

[ ... ]

Quoted 4 lines
drivers/watchdog/ma35d1_wdt.c new file +4 -0
+static int ma35d1_wdt_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ma35d1_wdt_dev *ma35d1_wdt;

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 236

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	if (val & RSTF) {
+		ma35d1_wdt->wdt_dev.bootstatus = WDIOF_CARDRESET;
+		writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	}

[Severity: High]
Should there be a wait for hardware synchronization after this write clears the RSTF bit?

drivers/watchdog/ma35d1_wdt.c line 239

Quoted 3 lines
drivers/watchdog/ma35d1_wdt.c new file +3 -0
+
+	if (val & WDTEN)
+		set_bit(WDOG_HW_RUNNING, &ma35d1_wdt->wdt_dev.status);

[Severity: High]
If the bootloader left the watchdog running with a very short timeout, could the system reset before the core's ping worker can keep it alive?

Should this also call ma35d1_wdt_set_timeout() to ensure the hardware's timeout matches the software configuration when taking over a running watchdog?

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 274

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+static int ma35d1_wdt_suspend(struct device *dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&ma35d1_wdt->wdt_dev)) {

[Severity: High]
Does this need to check watchdog_hw_running() as well?

If the bootloader started the watchdog (WDOG_HW_RUNNING is set) but userspace hasn't opened the device yet (WDOG_ACTIVE is false), this check will skip pausing the hardware. Could the timer then expire and unexpectedly reset the system during sleep?

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 302

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+static int ma35d1_wdt_resume(struct device *dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&ma35d1_wdt->wdt_dev)) {

[Severity: High]
Similar to suspend, should this also check watchdog_hw_running() to ensure a hardware-running watchdog is properly resumed?

Quoted 6 lines
drivers/watchdog/ma35d1_wdt.c new file +6 -0
+		u32 val;
+		int ret;
+
+		guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+		val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+

drivers/watchdog/ma35d1_wdt.c line 318

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+		if (device_may_wakeup(dev)) {
+			val |= RSTEN;
+			val &= ~(INTEN | WKEN);
+		} else {
+			val |= (WDTEN | RSTEN);
+		}
+		writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+		writel_relaxed(RESET_COUNTER,
+			       ma35d1_wdt->wdt_base + REG_WDT_RSTCNT);
+		ret = ma35d1_wdt_wait_sync(ma35d1_wdt);

[Severity: Medium]
Is it safe to issue the ping command (writing to REG_WDT_RSTCNT) before waiting for the control register changes to synchronize?

In ma35d1_wdt_start(), the ping happens after ma35d1_wdt_wait_sync(). Could doing it before sync here cause the ping to be ignored by the hardware?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#6 lore raw

Re: [PATCH v2 2/3] watchdog: Add Nuvoton MA35D1 watchdog driver support

[email protected] 於 2026/7/24 下午 05:24 寫道:

Quoted 2 lines

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Writes to REG_WDT_CTL are missing required hardware synchronization waits (SYNC bit), risking dropped writes and hardware state corruption.

Not applicable. SYNC only used for the change of WDTEN.

Quoted 1 line

- [High] The watchdog timer is not paused during system suspend if it was running from the bootloader but not yet opened by userspace, leading to unintended system resets.

Fixed. Added a check for watchdog_hw_running.

Quoted 1 line

- [High] Driver fails to synchronize the hardware timeout with the software configuration when inheriting a running watchdog during probe.

Fixed. Added set_timeout() before devm_watchdog_register_device().

Quoted 1 line

- [High] Read-modify-write operations on REG_WDT_CTL inadvertently clear W1C (Write-1-to-Clear) status flags, leading to lost interrupts and wakeup events.

Not applicable. As noted in the cover letter, this does not affect the W1C flags.

Quoted 1 line

- [Medium] In ma35d1_wdt_resume(), the driver writes to REG_WDT_RSTCNT before ensuring the control register changes have synchronized.

Not applicable. These two operations work independently and do not affect each other.

Quoted 1 line

- [Low] Spelling mistake in Kconfig help text.

Fixed. Corrected the spelling mistake in the Kconfig help text.

Quoted 190 lines

--

--- Patch [2]: [PATCH v2 2/3] watchdog: Add Nuvoton MA35D1 watchdog driver support --- commit 31ed5d4971c74d4f75935b7f98c40e226cdc3521
Author: Zi-Yu Chen <[email protected]>

watchdog: Add Nuvoton MA35D1 watchdog driver support

This commit adds a new watchdog driver for the Nuvoton MA35D1 SoC. It provides support for timeout configuration, ping, and system reset functionality via the standard watchdog framework.

Quoted 5 lines
drivers/watchdog/Kconfig +0 -0
index 08cb8612d41fe..972740fd36a69 100644

drivers/watchdog/Kconfig config STMP3XXX_RTC_WATCHDOG · line 729

Quoted 10 lines
drivers/watchdog/Kconfig +7 -0
@@ -720,6 +720,16 @@ config STMP3XXX_RTC_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called stmp3xxx_rtc_wdt.
 
+config MA35D1_WDT
+	tristate "Nuvoton MA35D1 Watchdog Timer"
+	depends on ARCH_MA35 || COMPILE_TEST
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  for the Nuvoton MA35D1 series microprosser.

[Severity: Low]
Is "microprosser" a typo here? Did you mean "microprocessor"?

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +0 -0
new file mode 100644
index 0000000000000..e5247e55dfee4

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 83

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+static int ma35d1_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	val &= ~WDTEN;
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);

[Severity: High]
Will this read-modify-write inadvertently clear Write-1-to-Clear (W1C) flags like IF, WKF, or RSTF?

Looking at ma35d1_wdt_isr(), it appears that reading a 1 and writing it back clears the flag. Should these W1C flags be explicitly masked out when doing read-modify-write operations on REG_WDT_CTL here, and similarly in other functions like ma35d1_wdt_set_timeout(), ma35d1_wdt_start(), and ma35d1_wdt_suspend()?

[ ... ]

Quoted 6 lines
drivers/watchdog/ma35d1_wdt.c new file +6 -0
+static int ma35d1_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				  unsigned int timeout)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned long target_ticks;
+	unsigned int val, i;

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 136

Quoted 9 lines
drivers/watchdog/ma35d1_wdt.c new file +9 -0
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	val &= ~TOUTSEL;
+	val |= FIELD_PREP(TOUTSEL, i);
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+
+	ma35d1_wdt_ping(wdt_dev);
+	return 0;
+}

[Severity: High]
Does this writel_relaxed() require a call to ma35d1_wdt_wait_sync() before proceeding?

Without waiting for the SYNC bit, could the immediate ping command be ignored by the hardware or cause hardware state corruption?

Quoted 6 lines
drivers/watchdog/ma35d1_wdt.c new file +6 -0
+static int ma35d1_wdt_start(struct watchdog_device *wdt_dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	void __iomem *wdt_base = ma35d1_wdt->wdt_base;
+	unsigned int val;
+	int ret;

drivers/watchdog/ma35d1_wdt.c line 153

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+
+	ret = ma35d1_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
+	if (ret < 0)
+		return ret;
+
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(wdt_base + REG_WDT_CTL);
+	val |= (WDTEN | RSTEN);
+
+	writel_relaxed(val, wdt_base + REG_WDT_CTL);

[Severity: High]
Because ma35d1_wdt_set_timeout() writes to REG_WDT_CTL without waiting for sync, and then ma35d1_wdt_start() immediately performs another read-modify-write on the same register, could this back-to-back unsynchronized access cause dropped writes and prevent the watchdog from starting properly?

[ ... ]

Quoted 4 lines
drivers/watchdog/ma35d1_wdt.c new file +4 -0
+static int ma35d1_wdt_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ma35d1_wdt_dev *ma35d1_wdt;

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 236

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	if (val & RSTF) {
+		ma35d1_wdt->wdt_dev.bootstatus = WDIOF_CARDRESET;
+		writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	}

[Severity: High]
Should there be a wait for hardware synchronization after this write clears the RSTF bit?

drivers/watchdog/ma35d1_wdt.c line 239

Quoted 3 lines
drivers/watchdog/ma35d1_wdt.c new file +3 -0
+
+	if (val & WDTEN)
+		set_bit(WDOG_HW_RUNNING, &ma35d1_wdt->wdt_dev.status);

[Severity: High]
If the bootloader left the watchdog running with a very short timeout, could the system reset before the core's ping worker can keep it alive?

Should this also call ma35d1_wdt_set_timeout() to ensure the hardware's timeout matches the software configuration when taking over a running watchdog?

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 274

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+static int ma35d1_wdt_suspend(struct device *dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&ma35d1_wdt->wdt_dev)) {

[Severity: High]
Does this need to check watchdog_hw_running() as well?

If the bootloader started the watchdog (WDOG_HW_RUNNING is set) but userspace hasn't opened the device yet (WDOG_ACTIVE is false), this check will skip pausing the hardware. Could the timer then expire and unexpectedly reset the system during sleep?

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 302

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+static int ma35d1_wdt_resume(struct device *dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&ma35d1_wdt->wdt_dev)) {

[Severity: High]
Similar to suspend, should this also check watchdog_hw_running() to ensure a hardware-running watchdog is properly resumed?

Quoted 6 lines
drivers/watchdog/ma35d1_wdt.c new file +6 -0
+		u32 val;
+		int ret;
+
+		guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+		val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+

drivers/watchdog/ma35d1_wdt.c line 318

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+		if (device_may_wakeup(dev)) {
+			val |= RSTEN;
+			val &= ~(INTEN | WKEN);
+		} else {
+			val |= (WDTEN | RSTEN);
+		}
+		writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+		writel_relaxed(RESET_COUNTER,
+			       ma35d1_wdt->wdt_base + REG_WDT_RSTCNT);
+		ret = ma35d1_wdt_wait_sync(ma35d1_wdt);

[Severity: Medium]
Is it safe to issue the ping command (writing to REG_WDT_RSTCNT) before waiting for the control register changes to synchronize?

Quoted 3 lines

In ma35d1_wdt_start(), the ping happens after ma35d1_wdt_wait_sync(). Could doing it before sync here cause the ping to be ignored by the hardware?

Regards,
Zi-Yu Chen

author
#7 lore raw

PATCH v2 3/3 arm64: dts: nuvoton: Add WDT node for MA35D1 SoC

In reply to Zi-Yu Chen

Add Watchdog Timer (WDT) device node to ma35d1.dtsi.

---
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +7 -0
index 7228ad4735b5..14fd17cfdc5a 100644
@@ -82,6 +82,13 @@ soc {
 		#size-cells = <2>;
 		ranges;
 
+		wdt1: watchdog@40440000 {
+			compatible = "nuvoton,ma35d1-wdt";
+			reg = <0x0 0x40440000 0x0 0x100>;
+			interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk WDT1_GATE>;
+		};
+
 		sys: system-management@40460000 {
 			compatible = "nuvoton,ma35d1-reset", "syscon";
 			reg = <0x0 0x40460000 0x0 0x200>;
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v2 3/3] arm64: dts: nuvoton: Add WDT node for MA35D1 SoC

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Read-modify-write operations on REG_WDT_CTL do not mask write-1-to-clear (W1C) flags, leading to…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Read-modify-write operations on REG_WDT_CTL do not mask write-1-to-clear (W1C) flags, leading to unintentional clearing of pending interrupts or reset flags. --

--- Patch [3]: [PATCH v2 3/3] arm64: dts: nuvoton: Add WDT node for MA35D1 SoC --- commit a67dd4dd104040028c3121676f3993b8ca0f94db
Author: Zi-Yu Chen <[email protected]>

arm64: dts: nuvoton: Add WDT node for MA35D1 SoC

This commit adds the Watchdog Timer (WDT) device node to the Nuvoton MA35D1 device tree. It defines the register space, interrupt, and clock for the watchdog controller.

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +0 -0
new file mode 100644
index 0000000000000..e5247e55dfee4

[ ... ]

drivers/watchdog/ma35d1_wdt.c

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+static int ma35d1_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	val &= ~WDTEN;
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);

[Severity: High]
Does this read-modify-write clear pending write-1-to-clear (W1C) flags?

If IF, WKF, or RSTF bits are set when this reads REG_WDT_CTL, writing the value back without masking those bits will unintentionally clear them, which could result in dropped interrupts or wakeup events.

[ ... ]

Quoted 3 lines
drivers/watchdog/ma35d1_wdt.c new file +3 -0
+static int ma35d1_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				  unsigned int timeout)
+{

[ ... ]

drivers/watchdog/ma35d1_wdt.c

Quoted 5 lines
drivers/watchdog/ma35d1_wdt.c new file +5 -0
+	guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	val &= ~TOUTSEL;
+	val |= FIELD_PREP(TOUTSEL, i);
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);

[Severity: High]
Does this update silently drop pending interrupts?

By performing a read-modify-write without masking out the W1C bits (such as IF or WKF), any currently pending flags will be written back as 1s and cleared before they can be processed.

[ ... ]

Quoted 8 lines
drivers/watchdog/ma35d1_wdt.c new file +8 -0
+static int ma35d1_wdt_suspend(struct device *dev)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&ma35d1_wdt->wdt_dev)) {
+		u32 val;
+		int ret;
+

drivers/watchdog/ma35d1_wdt.c

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+		guard(spinlock_irqsave)(&ma35d1_wdt->lock);
+		val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+
+		if (device_may_wakeup(dev)) {
+			val &= ~RSTEN;
+			val |= (INTEN | WKEN);
+		} else {
+			val &= ~(WDTEN | RSTEN);
+		}
+		writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);

[Severity: High]
Could this lose a race with a wakeup event?

Writing back the modified control register without clearing the W1C bits first will unintentionally acknowledge and drop any wakeup or interrupt events that occurred just before the read.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3