Skip to contentSkip to conversation

clocksource/drivers/timer-vt8500: clean up and add watchdog function

PATCH Superseded Alexey Charkov 3 participants 8 messages Nov 12 – Nov 13

Subsystems (4)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Alexey Charkov

author maintainer
#0 lore raw

v6 cover clocksource/drivers/timer-vt8500: clean up and add watchdog function

Add named defines for the registers and bits in timer-vt8500. Move the system events timer from channel 0 to channel 1 when enough information is provided by the device tree (i.e. more than one IRQ). Use channel 0 for the system watchdog, and let the watchdog restart the SoC, which the machine's own restart hook fails to do on WM8950.

---
Changes in v6:
- Dropped the binding patch, which Rob has applied
- Rebased onto next-20261111
- Moved the shared header under include/clocksource (thanks Daniel)
- Pass the watchdog a single register base, and keep the watchdog
register offsets in its own driver (thanks Daniel)
- Build the watchdog driver in rather than as a module: the timer it
depends on is always built in, and the driver is tiny (thanks Daniel)
- kfree the correct structure upon aux child release (thanks Daniel)
- Return -ENODEV rather than -ENOMEM if the timer failed to initialize,
and drop the message on allocation failure (thanks Daniel)
- Unmap the timer registers if its interrupt is missing, so that no
watchdog gets created on a timer that never started
- Improved code comments and commit messages (thanks Daniel)
- Give the watchdog a default timeout, so that opening the device
before setting one no longer arms it for the next counter wraparound
- Wait for a pending match register write to settle before rewriting it,
as the clock event code does
- Honour the nowayout parameter, and disallow unbinding the watchdog,
which would leave it armed with nothing to ping it
- Added a restart handler, so that reboot works on WM8950
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Make sure the watchdog timeout value is clamped to hardware limits
before writing it to the registers (thanks Guenter)
- Add a comment about the watchdog match value (deadline) wrapping around
the U32_MAX boundary, which is expected behavior (thanks Guenter)
- Avoid moving register definitions to the shared header file to reduce
churn: the watchdog driver gets direct pointers to the two registers it
uses anyway, so it doesn't have to know all those offsets and bits
- Put the watchdog Kconfig entry with other ARM platforms where it belongs
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Changed the watchdog driver to use auxiliary bus instead of platform
(thanks Guenter)
- Split out the register definitions into a header file shared between
the clocksource driver and the watchdog driver
- Replaced -1UL with U32_MAX in watchdog max_heartbeat_ms to make builds
on non-32bit platforms happier
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Dropped the DTS patch already applied by Krzysztof
- Rebased onto v6.15-rc5 as requested by Daniel
- Split out the watchdog code into a dedicated platform driver, like
timer-gxp does (thanks Daniel)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Included the previously reviewed binding change that is directly related
to this series as the first patch here (thanks Krzysztof)
- Created a separate config symbol for the watchdog function to let users
build a kernel without forcing watchdog functionality upon them
(thanks Krzysztof)
- Link to the previous binding submission: https://lore.kernel.org/all/[email protected]/

---
Alexey Charkov (4):
clocksource/drivers/timer-vt8500: Add defines for magic constants clocksource/drivers/timer-vt8500: Prepare for watchdog functionality
watchdog: Add support for VIA/WonderMedia SoC watchdog functionality
watchdog: vt8500: Add a restart handler

 Documentation/watchdog/watchdog-parameters.rst |   7 +
 MAINTAINERS                                    |   2 +
 drivers/clocksource/Kconfig                    |   1 +
 drivers/clocksource/timer-vt8500.c             | 179 +++++++++++++++++++++----
 drivers/watchdog/Kconfig                       |  12 ++
 drivers/watchdog/Makefile                      |   1 +
 drivers/watchdog/vt8500-wdt.c                  | 145 ++++++++++++++++++++
 include/clocksource/vt8500-timer.h             |  22 +++
 8 files changed, 342 insertions(+), 27 deletions(-)

---
base-commit: aaa2f954c21b205a0bcd0961e5b2be4e82e58455
change-id: 20250506-vt8500-timer-updates-44a0d22cd720

Best regards,

Signature · 1 line
Alexey Charkov <[email protected]>
author maintainer
#1 lore raw

PATCH v6 1/4 clocksource/drivers/timer-vt8500: Add defines for magic constants

Add defines for the timer registers and their bits to make the code more self-explanatory. While at that, replace _VAL suffixes with more intuitive _REG suffixes on register offsets.

No functional changes.

---
 drivers/clocksource/timer-vt8500.c | 62 ++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 23 deletions(-)
drivers/clocksource/timer-vt8500.c +39 -23
index a469b1b5f972..c4694cf8bea6 100644
@@ -24,15 +24,28 @@
 
 #define VT8500_TIMER_OFFSET	0x0100
 #define VT8500_TIMER_HZ		3000000
-#define TIMER_MATCH_VAL		0x0000
-#define TIMER_COUNT_VAL		0x0010
-#define TIMER_STATUS_VAL	0x0014
-#define TIMER_IER_VAL		0x001c		/* interrupt enable */
-#define TIMER_CTRL_VAL		0x0020
-#define TIMER_AS_VAL		0x0024		/* access status */
-#define TIMER_COUNT_R_ACTIVE	(1 << 5)	/* not ready for read */
-#define TIMER_COUNT_W_ACTIVE	(1 << 4)	/* not ready for write */
-#define TIMER_MATCH_W_ACTIVE	(1 << 0)	/* not ready for write */
+
+#define TIMER_MATCH_REG(x)	(4 * (x))
+#define TIMER_COUNT_REG		0x0010	 /* clocksource counter */
+
+#define TIMER_STATUS_REG	0x0014
+#define TIMER_STATUS_MATCH(x)	BIT((x))
+#define TIMER_STATUS_CLEARALL	(TIMER_STATUS_MATCH(0) | \
+				 TIMER_STATUS_MATCH(1) | \
+				 TIMER_STATUS_MATCH(2) | \
+				 TIMER_STATUS_MATCH(3))
+
+#define TIMER_INT_EN_REG	0x001c	 /* interrupt enable */
+#define TIMER_INT_EN_MATCH(x)	BIT((x))
+
+#define TIMER_CTRL_REG		0x0020
+#define TIMER_CTRL_ENABLE	BIT(0)	 /* enable clocksource counter */
+#define TIMER_CTRL_RD_REQ	BIT(1)	 /* request counter read */
+
+#define TIMER_ACC_STS_REG	0x0024	 /* access status */
+#define TIMER_ACC_WR_MATCH(x)	BIT((x)) /* writing Match (x) value */
+#define TIMER_ACC_WR_COUNTER	BIT(4)	 /* writing clocksource counter */
+#define TIMER_ACC_RD_COUNTER	BIT(5)	 /* reading clocksource counter */
 
 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
 
@@ -43,11 +56,12 @@ static void __iomem *regbase;
 static u64 vt8500_timer_read(struct clocksource *cs)
 {
 	int loops = msecs_to_loops(10);
-	writel(3, regbase + TIMER_CTRL_VAL);
-	while ((readl((regbase + TIMER_AS_VAL)) & TIMER_COUNT_R_ACTIVE)
-						&& --loops)
+
+	writel(TIMER_CTRL_ENABLE | TIMER_CTRL_RD_REQ, regbase + TIMER_CTRL_REG);
+	while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_RD_COUNTER &&
+	       --loops)
 		cpu_relax();
-	return readl(regbase + TIMER_COUNT_VAL);
+	return readl(regbase + TIMER_COUNT_REG);
 }
 
 static struct clocksource clocksource = {
@@ -63,23 +77,25 @@ static int vt8500_timer_set_next_event(unsigned long cycles,
 {
 	int loops = msecs_to_loops(10);
 	u64 alarm = clocksource.read(&clocksource) + cycles;
-	while ((readl(regbase + TIMER_AS_VAL) & TIMER_MATCH_W_ACTIVE)
-						&& --loops)
+
+	while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_WR_MATCH(0) &&
+	       --loops)
 		cpu_relax();
-	writel((unsigned long)alarm, regbase + TIMER_MATCH_VAL);
+	writel((unsigned long)alarm, regbase + TIMER_MATCH_REG(0));
 
 	if ((signed)(alarm - clocksource.read(&clocksource)) <= MIN_OSCR_DELTA)
 		return -ETIME;
 
-	writel(1, regbase + TIMER_IER_VAL);
+	writel(TIMER_INT_EN_MATCH(0), regbase + TIMER_INT_EN_REG);
 
 	return 0;
 }
 
 static int vt8500_shutdown(struct clock_event_device *evt)
 {
-	writel(readl(regbase + TIMER_CTRL_VAL) | 1, regbase + TIMER_CTRL_VAL);
-	writel(0, regbase + TIMER_IER_VAL);
+	writel(readl(regbase + TIMER_CTRL_REG) | TIMER_CTRL_ENABLE,
+	       regbase + TIMER_CTRL_REG);
+	writel(0, regbase + TIMER_INT_EN_REG);
 	return 0;
 }
 
@@ -95,7 +111,7 @@ static struct clock_event_device clockevent = {
 static irqreturn_t vt8500_timer_interrupt(int irq, void *dev_id)
 {
 	struct clock_event_device *evt = dev_id;
-	writel(0xf, regbase + TIMER_STATUS_VAL);
+	writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG);
 	evt->event_handler(evt);
 
 	return IRQ_HANDLED;
@@ -119,9 +135,9 @@ static int __init vt8500_timer_init(struct device_node *np)
 		return -EINVAL;
 	}
 
-	writel(1, regbase + TIMER_CTRL_VAL);
-	writel(0xf, regbase + TIMER_STATUS_VAL);
-	writel(~0, regbase + TIMER_MATCH_VAL);
+	writel(TIMER_CTRL_ENABLE, regbase + TIMER_CTRL_REG);
+	writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG);
+	writel(~0, regbase + TIMER_MATCH_REG(0));
 
 	ret = clocksource_register_hz(&clocksource, VT8500_TIMER_HZ);
 	if (ret) {
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH v6 2/4 clocksource/drivers/timer-vt8500: Prepare for watchdog functionality

In reply to Alexey Charkov

VIA/WonderMedia system timer can generate a watchdog reset when its clocksource counter matches the value in the match register 0 and watchdog function is enabled. For this to work, obviously the clock event device must use a different match register (1~3) and respective interrupt.

Check if at least two interrupts are provided by the device tree, then use match register 1 for system clock events and reserve match register 0 for the watchdog. Keep match register 0 for clock events on device trees that list a single interrupt, and offer no watchdog there.

Instantiate the watchdog as an auxiliary device of the timer from a platform driver bound to the timer node, as the timer itself comes up too early to have a struct device. Share what the watchdog needs through a new header, include/clocksource/vt8500-timer.h.

Unmap the registers if the timer interrupt is missing, so that no watchdog gets created on a timer whose counter never started.

---
 MAINTAINERS                        |   1 +
 drivers/clocksource/Kconfig        |   1 +
 drivers/clocksource/timer-vt8500.c | 127 ++++++++++++++++++++++++++++++++++---
 include/clocksource/vt8500-timer.h |  22 +++++++
 4 files changed, 142 insertions(+), 9 deletions(-)
MAINTAINERS +1 -0
index 27461b2161a7..acc4d2915460 100644
@@ -4010,6 +4010,7 @@ F:	drivers/tty/serial/vt8500_serial.c
 F:	drivers/video/fbdev/vt8500lcdfb.*
 F:	drivers/video/fbdev/wm8505fb*
 F:	drivers/video/fbdev/wmt_ge_rops.*
+F:	include/clocksource/vt8500-timer.h
 
 ARM/ZTE ZX29 SOC SUPPORT
 M:	Stefan Dösinger <[email protected]>
drivers/clocksource/Kconfig +1 -0
index da83483296d5..d060863fcc07 100644
@@ -197,6 +197,7 @@ config TEGRA186_TIMER
 config VT8500_TIMER
 	bool "VT8500 timer driver" if COMPILE_TEST
 	depends on HAS_IOMEM
+	select AUXILIARY_BUS
 	help
 	  Enables support for the VT8500 driver.
 
drivers/clocksource/timer-vt8500.c +118 -9

180 lines not on this page · raw message

include/clocksource/vt8500-timer.h new file +22 -0
new file mode 100644
index 000000000000..956863d50d02
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CLOCKSOURCE_VT8500_TIMER_H_
+#define CLOCKSOURCE_VT8500_TIMER_H_
+
+#include <linux/auxiliary_bus.h>
+#include <linux/types.h>
+
+#define VT8500_TIMER_HZ		3000000
+
+/**
+ * struct vt8500_wdt_info - timer resources shared with the watchdog
+ * @auxdev: auxiliary device the watchdog driver binds to
+ * @timer_next: returns the clocksource counter value @cycles from now
+ * @regbase: timer register block; the watchdog uses match register 0
+ */
+struct vt8500_wdt_info {
+	struct auxiliary_device auxdev;
+	u64 (*timer_next)(u64 cycles);
+	void __iomem *regbase;
+};
+
+#endif /* CLOCKSOURCE_VT8500_TIMER_H_ */
Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH v6 3/4 watchdog: Add support for VIA/WonderMedia SoC watchdog functionality

In reply to Alexey Charkov

VIA/WonderMedia SoCs can use their system timer's first channel as a watchdog device which will reset the system if the clocksource counter matches the value given in its match register 0 and if the watchdog function is enabled.

Since the watchdog function is tightly coupled to the timer itself, it is implemented as an auxiliary device of the timer device. Build it in rather than as a module, as the timer it depends on is always built in and the driver is tiny.

Report a watchdog found running at probe, as one armed before a kexec would be, so that the core keeps it fed until userspace takes over.

---
 Documentation/watchdog/watchdog-parameters.rst |   7 ++
 MAINTAINERS                                    |   1 +
 drivers/watchdog/Kconfig                       |  12 +++
 drivers/watchdog/Makefile                      |   1 +
 drivers/watchdog/vt8500-wdt.c                  | 132 +++++++++++++++++++++++++
 5 files changed, 153 insertions(+)
Documentation/watchdog/watchdog-parameters.rst +7 -0
index 348229ffcb43..27453b659545 100644
@@ -637,6 +637,13 @@ uniphier_wdt:
 
 -------------------------------------------------
 
+vt8500_wdt:
+    nowayout:
+	Watchdog cannot be stopped once started
+	(default=kernel config parameter)
+
+-------------------------------------------------
+
 w83627hf_wdt:
     wdt_io:
 	w83627hf/thf WDT io port (default 0x2E)
MAINTAINERS +1 -0
index acc4d2915460..80aefe2f5481 100644
@@ -4010,6 +4010,7 @@ F:	drivers/tty/serial/vt8500_serial.c
 F:	drivers/video/fbdev/vt8500lcdfb.*
 F:	drivers/video/fbdev/wm8505fb*
 F:	drivers/video/fbdev/wmt_ge_rops.*
+F:	drivers/watchdog/vt8500-wdt.c
 F:	include/clocksource/vt8500-timer.h
 
 ARM/ZTE ZX29 SOC SUPPORT
drivers/watchdog/Kconfig +12 -0
index c884f86be4e3..a252f9c9c2c8 100644
@@ -1183,6 +1183,18 @@ config SUNPLUS_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called sunplus_wdt.
 
+config VT8500_WATCHDOG
+	bool "VIA/WonderMedia VT8500 watchdog support"
+	depends on ARCH_VT8500 || COMPILE_TEST
+	select WATCHDOG_CORE
+	select AUXILIARY_BUS
+	help
+	  VIA/WonderMedia SoCs can use their system timer as a hardware
+	  watchdog, as long as the first timer channel is free from other
+	  uses and respective function is enabled in its registers. To
+	  make use of it, say Y here and ensure that the device tree
+	  lists at least two interrupts for the VT8500 timer device.
+
 # X86 (i386 + ia64 + x86_64) Architecture
 
 config ACQUIRE_WDT
drivers/watchdog/Makefile +1 -0
index 19cb25f51624..5a5a111b4815 100644
@@ -106,6 +106,7 @@ 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
+obj-$(CONFIG_VT8500_WATCHDOG) += vt8500-wdt.o
 
 # X86 (i386 + ia64 + x86_64) Architecture
 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/vt8500-wdt.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.56.0
#4 lore raw

Re: [PATCH v6 3/4] watchdog: Add support for VIA/WonderMedia SoC watchdog functionality

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] watchdog: vt8500-wdt: missing kernel-parameters.txt entry for nowayout --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] watchdog: vt8500-wdt: missing kernel-parameters.txt entry for nowayout
--

commit a5067e39729d1dac5a691d15d6ebc0e129c1a8a6
Author: Alexey Charkov <[email protected]>

watchdog: Add support for VIA/WonderMedia SoC watchdog functionality

This commit adds a built-in auxiliary driver for the VIA/WonderMedia VT8500 hardware watchdog using the system timer's first match channel.

Quoted 6 lines
drivers/watchdog/vt8500-wdt.c new file +0 -0
new file mode 100644
index 0000000000000..e0f838fd1d507
@@ -0,0 +1,132 @@

[ ... ]

drivers/watchdog/vt8500-wdt.c line 31

Quoted 4 lines
drivers/watchdog/vt8500-wdt.c new file +4 -0
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+		 __stringify(WATCHDOG_NOWAYOUT) ")");

[Severity: Low]
Should vt8500_wdt.nowayout also be documented in
Documentation/admin-guide/kernel-parameters.txt?

Because CONFIG_VT8500_WATCHDOG is a bool Kconfig symbol and the driver is registered via builtin_driver(), module_param(nowayout, ...) only acts as a kernel command-line boot parameter rather than a loadable module parameter.

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

PATCH v6 4/4 watchdog: vt8500: Add a restart handler

In reply to Alexey Charkov

Reset the SoC through the watchdog when the machine's own restart hook leaves it running: the PMSR write in vt8500_restart() has no effect on WM8950, so a reboot there ends in "Reboot failed -- System halted" unless a watchdog armed from userspace happens to fire.

Arm the match a millisecond ahead of the current count, which leaves ample margin for the register writes to land.

Register at priority 128, the default for restart handlers and also the priority of the ARM machine restart hook. That hook is registered first, from setup_arch(), and handlers of equal priority run in registration order, so this one runs right after it and only matters where the hook fails to reset the SoC.

---
 drivers/watchdog/vt8500-wdt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/watchdog/vt8500-wdt.c +13 -0
index e0f838fd1d50..0ce1e2b06410 100644
@@ -25,6 +25,9 @@
 
 #define VT8500_WDT_DEFAULT_TIMEOUT	30	/* seconds */
 
+/* How far ahead of the current count to arm the match for a restart */
+#define VT8500_WDT_RESTART_TICKS	(VT8500_TIMER_HZ / 1000)	/* 1 ms */
+
 static bool nowayout = WATCHDOG_NOWAYOUT;
 module_param(nowayout, bool, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
@@ -75,9 +78,18 @@ static int vt8500_watchdog_stop(struct watchdog_device *wdd)
 	return 0;
 }
 
+static int vt8500_watchdog_restart(struct watchdog_device *wdd,
+				   unsigned long action, void *data)
+{
+	struct vt8500_wdt_info *info = watchdog_get_drvdata(wdd);
+
+	return vt8500_watchdog_arm(info, VT8500_WDT_RESTART_TICKS);
+}
+
 static const struct watchdog_ops vt8500_watchdog_ops = {
 	.start			= vt8500_watchdog_start,
 	.stop			= vt8500_watchdog_stop,
+	.restart		= vt8500_watchdog_restart,
 };
 
 static const struct watchdog_info vt8500_watchdog_info = {
@@ -107,6 +119,7 @@ static int vt8500_wdt_probe(struct auxiliary_device *auxdev,
 	info = container_of(auxdev, struct vt8500_wdt_info, auxdev);
 	watchdog_set_drvdata(wdd, info);
 	watchdog_set_nowayout(wdd, nowayout);
+	watchdog_set_restart_priority(wdd, 128);
 
 	/* Let the core feed a watchdog left running, e.g. across kexec */
 	if (readl(info->regbase + VT8500_WDT_EN_REG) & VT8500_WDT_EN)
Signature · 1 line
2.56.0
maintainer
#6 lore raw

Re: [PATCH v6 4/4] watchdog: vt8500: Add a restart handler

Quoted 5 lines · Alexey Charkov

Reset the SoC through the watchdog when the machine's own restart hook leaves it running: the PMSR write in vt8500_restart() has no effect on WM8950, so a reboot there ends in "Reboot failed -- System halted" unless a watchdog armed from userspace happens to fire.

Quoted 8 lines

Arm the match a millisecond ahead of the current count, which leaves ample margin for the register writes to land.

Register at priority 128, the default for restart handlers and also the priority of the ARM machine restart hook. That hook is registered first, from setup_arch(), and handlers of equal priority run in registration order, so this one runs right after it and only matters where the hook fails to reset the SoC.

This isn't really the idea of restart handlers. The sequence should be well defined. That is what the priorities are for. Why not give it a slightly lower priority ?

Quoted 21 lines
---
  drivers/watchdog/vt8500-wdt.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/watchdog/vt8500-wdt.c +3 -0
index e0f838fd1d50..0ce1e2b06410 100644
@@ -25,6 +25,9 @@
 
  #define VT8500_WDT_DEFAULT_TIMEOUT	30	/* seconds */
 
+/* How far ahead of the current count to arm the match for a restart */
+#define VT8500_WDT_RESTART_TICKS	(VT8500_TIMER_HZ / 1000)	/* 1 ms */
+
  static bool nowayout = WATCHDOG_NOWAYOUT;
  module_param(nowayout, bool, 0);
  MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="

drivers/watchdog/vt8500-wdt.c static int vt8500_watchdog_stop(struct watchdog_device *wdd) · line 86

Quoted 9 lines
drivers/watchdog/vt8500-wdt.c +6 -0
@@ -75,9 +78,18 @@ static int vt8500_watchdog_stop(struct watchdog_device *wdd)
  	return 0;
  }
 
+static int vt8500_watchdog_restart(struct watchdog_device *wdd,
+				   unsigned long action, void *data)
+{
+	struct vt8500_wdt_info *info = watchdog_get_drvdata(wdd);
+
+	return vt8500_watchdog_arm(info, VT8500_WDT_RESTART_TICKS);

This sets a 1-ms timer and doesn't wait for it to fire, so the next restart handler (if it exists) will be called. That seems odd, and may introduce unexpected behavior. Is this intentional ? If so, it should be explained.

Thanks,
Guenter

Quoted 18 lines
drivers/watchdog/vt8500-wdt.c +4 -0
+}
+
  static const struct watchdog_ops vt8500_watchdog_ops = {
  	.start			= vt8500_watchdog_start,
  	.stop			= vt8500_watchdog_stop,
+	.restart		= vt8500_watchdog_restart,
  };
 
  static const struct watchdog_info vt8500_watchdog_info = {
@@ -107,6 +119,7 @@ static int vt8500_wdt_probe(struct auxiliary_device *auxdev,
  	info = container_of(auxdev, struct vt8500_wdt_info, auxdev);
  	watchdog_set_drvdata(wdd, info);
  	watchdog_set_nowayout(wdd, nowayout);
+	watchdog_set_restart_priority(wdd, 128);
 
  	/* Let the core feed a watchdog left running, e.g. across kexec */
  	if (readl(info->regbase + VT8500_WDT_EN_REG) & VT8500_WDT_EN)
author maintainer
#7 lore raw

Re: [PATCH v6 4/4] watchdog: vt8500: Add a restart handler

Quoted 16 lines · Guenter Roeck
Quoted 5 lines · Alexey Charkov

Reset the SoC through the watchdog when the machine's own restart hook leaves it running: the PMSR write in vt8500_restart() has no effect on WM8950, so a reboot there ends in "Reboot failed -- System halted" unless a watchdog armed from userspace happens to fire.

Quoted 8 lines

Arm the match a millisecond ahead of the current count, which leaves ample margin for the register writes to land.

Register at priority 128, the default for restart handlers and also the priority of the ARM machine restart hook. That hook is registered first, from setup_arch(), and handlers of equal priority run in registration order, so this one runs right after it and only matters where the hook fails to reset the SoC.

Quoted 3 lines

This isn't really the idea of restart handlers. The sequence should be well defined. That is what the priorities are for. Why not give it a slightly lower priority ?

My thinking was along the lines of "I don't care who of you guys does the job, as long as it's done". But now that you've pointed it out, a watchdog reset is probably more rude than some other method, and also requires waiting for the timer to expire, so I'll probably switch it to 0 to make the "safety net" connotation explicit.

Quoted 23 lines
Quoted 23 lines
---
  drivers/watchdog/vt8500-wdt.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/watchdog/vt8500-wdt.c +3 -0
index e0f838fd1d50..0ce1e2b06410 100644
@@ -25,6 +25,9 @@
 
  #define VT8500_WDT_DEFAULT_TIMEOUT  30      /* seconds */
 
+/* How far ahead of the current count to arm the match for a restart */
+#define VT8500_WDT_RESTART_TICKS     (VT8500_TIMER_HZ / 1000)        /* 1 ms */
+
  static bool nowayout = WATCHDOG_NOWAYOUT;
  module_param(nowayout, bool, 0);
  MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
@@ -75,9 +78,18 @@ static int vt8500_watchdog_stop(struct watchdog_device *wdd)
      return 0;
  }
 
Quoted 11 lines

drivers/watchdog/vt8500-wdt.c static int vt8500_watchdog_stop(struct watchdog_device *wdd) · line 86

Quoted 6 lines
drivers/watchdog/vt8500-wdt.c +6 -0
+static int vt8500_watchdog_restart(struct watchdog_device *wdd,
+                                unsigned long action, void *data)
+{
+     struct vt8500_wdt_info *info = watchdog_get_drvdata(wdd);
+
+     return vt8500_watchdog_arm(info, VT8500_WDT_RESTART_TICKS);

This sets a 1-ms timer and doesn't wait for it to fire, so the next restart handler (if it exists) will be called. That seems odd, and may introduce unexpected behavior. Is this intentional ? If so, it should be explained.

Not intentional, thanks for pointing it out. I'll add a wait in the next version.

Thank you for the review!

Best regards,
Alexey