Skip to contentSkip to conversation

watchdog: ma35d1: Add support for MA35D1 Watchdog

PATCH Applied Zi-Yu Chen 3 participants 8 messages Aug 4 – Aug 6

Subsystems (4)
lore
Share & tools
lore

Zi-Yu Chen

author
#0 lore raw

v3 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 v3:
- Added check for watchdog_hw_running in suspend/resume.
- Add set_timeout in probe before devm_watchdog_register_device.
- fix spelling mistake in Kconfig help text.
- Drop redundant "binding" wording from patch 1 subject.

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
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                 | 363 ++++++++++++++++++
 5 files changed, 436 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 v3 1/3 dt-bindings: watchdog: Add MA35D1 Watchdog

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
author
#3 lore raw

PATCH v3 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 | 363 ++++++++++++++++++++++++++++++++++
 3 files changed, 374 insertions(+)
 create mode 100644 drivers/watchdog/ma35d1_wdt.c
drivers/watchdog/Kconfig +10 -0
index 08cb8612d41f..e9b32f8cb9b5 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 microprocessor.
+	  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 +363 -0

363 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

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

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Missing wait for hardware synchronization (`SYNC` bit) after writing to `REG_WDT_CTL` leads to…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing wait for hardware synchronization (SYNC bit) after writing to REG_WDT_CTL leads to dropped writes and hardware races.
- [High] Read-modify-write operations on REG_WDT_CTL inadvertently clear Write-1-to-Clear (W1C) status flags.
- [Medium] The interrupt handler unconditionally clears all flags and returns IRQ_HANDLED without verifying the interrupt source. --

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

watchdog: Add Nuvoton MA35D1 watchdog driver support

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.

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

[ ... ]

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 line 132

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 read-modify-write of REG_WDT_CTL inadvertently clear W1C flags?

If bits like IF, WKF, and RSTF are write-1-to-clear, writing back a value that has them set will unintentionally clear pending interrupts, wakeups, or reset status. Should these W1C bits be masked out from val before it is written back?

Also, should there be a call to ma35d1_wdt_wait_sync() here?

When ma35d1_wdt_start() calls this function, it modifies REG_WDT_CTL, returns, and then immediately modifies REG_WDT_CTL again. Could this second write overlap with the clock domain synchronization of the first write and cause hardware races?

Quoted 11 lines
drivers/watchdog/ma35d1_wdt.c new file +11 -0
+
+	ma35d1_wdt_ping(wdt_dev);
+	return 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]
This read-modify-write shares the same potential W1C flag clearing issue mentioned in ma35d1_wdt_set_timeout().

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+	ret = ma35d1_wdt_wait_sync(ma35d1_wdt);
+	if (ret) {
+		dev_err(wdt_dev->parent, "Wait for WDTEN SYNC timeout!\n");
+		return ret;
+	}
+
+	writel_relaxed(RESET_COUNTER, wdt_base + REG_WDT_RSTCNT);
+
+	return 0;
+}

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 190

Quoted 12 lines
drivers/watchdog/ma35d1_wdt.c new file +12 -0
+static irqreturn_t ma35d1_wdt_isr(int irq, void *dev_id)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_id;
+	unsigned int val;
+
+	/* Clear the flag if set */
+	guard(spinlock)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+
+	return IRQ_HANDLED;
+}

[Severity: Medium]
Does this interrupt handler need to verify the interrupt source before returning IRQ_HANDLED?

As written, this unconditionally claims the interrupt, which bypasses the kernel's spurious interrupt detection if the interrupt was actually generated by another device sharing the line.

Additionally, would writing back the unmodified value of REG_WDT_CTL clear all W1C flags at once, including RSTF, which might destroy status information needed elsewhere?

[ ... ]

Quoted 2 lines
drivers/watchdog/ma35d1_wdt.c new file +2 -0
+static int ma35d1_wdt_probe(struct platform_device *pdev)
+{

[ ... ]

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]
Does this write to clear RSTF also require a call to ma35d1_wdt_wait_sync()?

The code proceeds to call ma35d1_wdt_set_timeout() shortly after this, which will write to REG_WDT_CTL again. Could this lead to dropped writes or hardware races if the synchronization from this first write isn't complete?

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+
+	if (val & WDTEN)
+		set_bit(WDOG_HW_RUNNING, &ma35d1_wdt->wdt_dev.status);
+
+	watchdog_set_drvdata(&ma35d1_wdt->wdt_dev, ma35d1_wdt);
+	watchdog_set_nowayout(&ma35d1_wdt->wdt_dev, nowayout);
+	watchdog_init_timeout(&ma35d1_wdt->wdt_dev, timeout, &pdev->dev);
+
+	ma35d1_wdt_set_timeout(&ma35d1_wdt->wdt_dev,
+			       ma35d1_wdt->wdt_dev.timeout);

[ ... ]

Quoted 9 lines
drivers/watchdog/ma35d1_wdt.c new file +9 -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) ||
+	    watchdog_hw_running(&ma35d1_wdt->wdt_dev)) {
+		u32 val;
+		int ret;
+

drivers/watchdog/ma35d1_wdt.c line 291

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]
This read-modify-write shares the same potential W1C flag clearing issue.

If a pending wakeup flag is set during the read, could it be inadvertently cleared right before the system sleeps?

Quoted 9 lines
drivers/watchdog/ma35d1_wdt.c new file +9 -0
+		ret = ma35d1_wdt_wait_sync(ma35d1_wdt);
+		if (ret) {
+			dev_err(dev, "Wait for WDTEN SYNC timeout!\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#5 lore raw

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

[email protected] 於 2026/8/4 下午 03:15 寫道:

Quoted 2 lines

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing wait for hardware synchronization (SYNC bit) after writing to REG_WDT_CTL leads to dropped writes and hardware races.

Not applicable.
According to the MA35D1 TRM, hardware synchronization (SYNC bit) is only required when the WDTEN (Watchdog Enable) bit status is toggled. Other control bit updates do not require waiting for SYNC."

Quoted 1 line

- [High] Read-modify-write operations on REG_WDT_CTL inadvertently clear Write-1-to-Clear (W1C) status flags.

Not applicable.
INTEN and WKEN are only enabled during PM suspend when watchdog wakeup is configured. During normal runtime, INTEN and WKEN are disabled, so IF and WKF remain 0. Therefore, read-modify-write operations during runtime will not inadvertently clear active flags.

Quoted 1 line

- [Medium] The interrupt handler unconditionally clears all flags and returns IRQ_HANDLED without verifying the interrupt source.

Not applicable.
The WDT interrupt line is dedicated (non-shared) and strictly utilized as a wakeup source during PM suspend. Unconditionally clearing the flags upon interrupt entry ensures the wakeup/interrupt state is properly reset when exiting sleep.

Quoted 171 lines

--

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

watchdog: Add Nuvoton MA35D1 watchdog driver support

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.

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

[ ... ]

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 line 132

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 read-modify-write of REG_WDT_CTL inadvertently clear W1C flags?

If bits like IF, WKF, and RSTF are write-1-to-clear, writing back a value that has them set will unintentionally clear pending interrupts, wakeups, or reset status. Should these W1C bits be masked out from val before it is written back?

Also, should there be a call to ma35d1_wdt_wait_sync() here?

When ma35d1_wdt_start() calls this function, it modifies REG_WDT_CTL, returns, and then immediately modifies REG_WDT_CTL again. Could this second write overlap with the clock domain synchronization of the first write and cause hardware races?

Quoted 11 lines
drivers/watchdog/ma35d1_wdt.c new file +11 -0
+
+	ma35d1_wdt_ping(wdt_dev);
+	return 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]
This read-modify-write shares the same potential W1C flag clearing issue mentioned in ma35d1_wdt_set_timeout().

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+	ret = ma35d1_wdt_wait_sync(ma35d1_wdt);
+	if (ret) {
+		dev_err(wdt_dev->parent, "Wait for WDTEN SYNC timeout!\n");
+		return ret;
+	}
+
+	writel_relaxed(RESET_COUNTER, wdt_base + REG_WDT_RSTCNT);
+
+	return 0;
+}

[ ... ]

drivers/watchdog/ma35d1_wdt.c line 190

Quoted 12 lines
drivers/watchdog/ma35d1_wdt.c new file +12 -0
+static irqreturn_t ma35d1_wdt_isr(int irq, void *dev_id)
+{
+	struct ma35d1_wdt_dev *ma35d1_wdt = dev_id;
+	unsigned int val;
+
+	/* Clear the flag if set */
+	guard(spinlock)(&ma35d1_wdt->lock);
+	val = readl_relaxed(ma35d1_wdt->wdt_base + REG_WDT_CTL);
+	writel_relaxed(val, ma35d1_wdt->wdt_base + REG_WDT_CTL);
+
+	return IRQ_HANDLED;
+}

[Severity: Medium]
Does this interrupt handler need to verify the interrupt source before returning IRQ_HANDLED?

As written, this unconditionally claims the interrupt, which bypasses the kernel's spurious interrupt detection if the interrupt was actually generated by another device sharing the line.

Additionally, would writing back the unmodified value of REG_WDT_CTL clear all W1C flags at once, including RSTF, which might destroy status information needed elsewhere?

[ ... ]

Quoted 2 lines
drivers/watchdog/ma35d1_wdt.c new file +2 -0
+static int ma35d1_wdt_probe(struct platform_device *pdev)
+{

[ ... ]

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]
Does this write to clear RSTF also require a call to ma35d1_wdt_wait_sync()?

The code proceeds to call ma35d1_wdt_set_timeout() shortly after this, which will write to REG_WDT_CTL again. Could this lead to dropped writes or hardware races if the synchronization from this first write isn't complete?

Quoted 10 lines
drivers/watchdog/ma35d1_wdt.c new file +10 -0
+
+	if (val & WDTEN)
+		set_bit(WDOG_HW_RUNNING, &ma35d1_wdt->wdt_dev.status);
+
+	watchdog_set_drvdata(&ma35d1_wdt->wdt_dev, ma35d1_wdt);
+	watchdog_set_nowayout(&ma35d1_wdt->wdt_dev, nowayout);
+	watchdog_init_timeout(&ma35d1_wdt->wdt_dev, timeout, &pdev->dev);
+
+	ma35d1_wdt_set_timeout(&ma35d1_wdt->wdt_dev,
+			       ma35d1_wdt->wdt_dev.timeout);

[ ... ]

Quoted 9 lines
drivers/watchdog/ma35d1_wdt.c new file +9 -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) ||
+	    watchdog_hw_running(&ma35d1_wdt->wdt_dev)) {
+		u32 val;
+		int ret;
+

drivers/watchdog/ma35d1_wdt.c line 291

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]
This read-modify-write shares the same potential W1C flag clearing issue.

If a pending wakeup flag is set during the read, could it be inadvertently cleared right before the system sleeps?

Quoted 10 lines

drivers/watchdog/ma35d1_wdt.c line 300

Quoted 9 lines
drivers/watchdog/ma35d1_wdt.c new file +9 -0
+		ret = ma35d1_wdt_wait_sync(ma35d1_wdt);
+		if (ret) {
+			dev_err(dev, "Wait for WDTEN SYNC timeout!\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}

Regards,
Zi-Yu Chen

maintainer Applied
#6 lore raw

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

In reply to Zi-Yu Chen
Quoted 6 lines · 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.

Applied.

Thanks,
Guenter

author
#7 lore raw

PATCH v3 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