All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend
@ 2026-11-17  9:20 Yang Siyuan
  2026-11-17  9:36 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Yang Siyuan @ 2026-11-17  9:20 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: linux-watchdog, linux-arm-kernel, linux-sunxi, linux-kernel

The H616 watchdog has a maximum timeout of 16 seconds.  systemd keeps
/dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system
suspend all userspace is frozen and the watchdog core only cancels its
ping worker; it does not stop the hardware.  A suspend longer than the
timeout therefore resets the board before it can resume.

Add system sleep PM ops to stop the watchdog before suspend and restart
it after resume if it was running.  The driver did not store its private
data in the platform device, so add platform_set_drvdata() for the PM
callbacks.

Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes
without the 16-second watchdog reset, and /dev/watchdog0 keeps working
afterwards.

Signed-off-by: Yang Siyuan <hsyysy@163.com>
---
 drivers/watchdog/sunxi_wdt.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index a6500eb..23b50cb 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -55,6 +55,7 @@ struct sunxi_wdt_dev {
 	struct watchdog_device wdt_dev;
 	void __iomem *wdt_base;
 	const struct sunxi_wdt_reg *wdt_regs;
+	bool running_at_suspend;
 };
 
 /*
@@ -225,6 +226,36 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)
 	return 0;
 }
 
+/*
+ * The hardware watchdog has a maximum timeout of 16 seconds.  A system
+ * suspend easily lasts longer than that, and the watchdog core only cancels
+ * its ping worker during suspend; it does not stop the timer.  Stop the
+ * watchdog explicitly while suspended and re-arm it on resume.
+ */
+static int sunxi_wdt_suspend(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	sunxi_wdt->running_at_suspend = sunxi_wdt_is_running(&sunxi_wdt->wdt_dev);
+	sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static int sunxi_wdt_resume(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (sunxi_wdt->running_at_suspend)
+		sunxi_wdt_start(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static const struct dev_pm_ops sunxi_wdt_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(sunxi_wdt_suspend, sunxi_wdt_resume)
+};
+
 static const struct watchdog_info sunxi_wdt_info = {
 	.identity	= DRV_NAME,
 	.options	= WDIOF_SETTIMEOUT |
@@ -307,6 +338,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(sunxi_wdt->wdt_base))
 		return PTR_ERR(sunxi_wdt->wdt_base);
 
+	platform_set_drvdata(pdev, sunxi_wdt);
+
 	sunxi_wdt->wdt_dev.info = &sunxi_wdt_info;
 	sunxi_wdt->wdt_dev.ops = &sunxi_wdt_ops;
 	sunxi_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
@@ -348,6 +381,7 @@ static struct platform_driver sunxi_wdt_driver = {
 	.driver		= {
 		.name		= DRV_NAME,
 		.of_match_table	= sunxi_wdt_dt_ids,
+		.pm		= &sunxi_wdt_pm_ops,
 	},
 };
 

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-17  9:20 [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend Yang Siyuan
@ 2026-11-17  9:36 ` sashiko-bot
  2026-11-17 10:40 ` [PATCH v2] " Yang Siyuan
  2026-11-17 15:51 ` [PATCH] " kernel test robot
  2 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-17  9:36 UTC (permalink / raw)
  To: Yang Siyuan; +Cc: linux-watchdog, linux-sunxi

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] watchdog: sunxi_wdt: unused function warnings when
  CONFIG_PM_SLEEP=n
- [Low] watchdog: sunxi_wdt: redundant running_at_suspend state in
  sunxi_wdt_suspend()
--

commit 5093f8c201de1c0caf9e3ec2bb9831935e62dd95
Author: Yang Siyuan <hsyysy@163.com>

watchdog: sunxi_wdt: stop the watchdog across system suspend

This commit adds system sleep PM callbacks to stop the Allwinner watchdog
before suspend and restart it on resume if it was running.

> diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
> index a6500ebf24bad..23b50cb8d3ebc 100644
> --- a/drivers/watchdog/sunxi_wdt.c
> +++ b/drivers/watchdog/sunxi_wdt.c
> @@ -55,6 +55,7 @@ struct sunxi_wdt_dev {
>  	struct watchdog_device wdt_dev;
>  	void __iomem *wdt_base;
>  	const struct sunxi_wdt_reg *wdt_regs;
> +	bool running_at_suspend;
>  };
>  
>  /*
> @@ -225,6 +226,36 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)
>  	return 0;
>  }
>  
> +/*
> + * The hardware watchdog has a maximum timeout of 16 seconds.  A system
> + * suspend easily lasts longer than that, and the watchdog core only cancels
> + * its ping worker during suspend; it does not stop the timer.  Stop the
> + * watchdog explicitly while suspended and re-arm it on resume.
> + */
> +static int sunxi_wdt_suspend(struct device *dev)
> +{
> +	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
> +
> +	sunxi_wdt->running_at_suspend = sunxi_wdt_is_running(&sunxi_wdt->wdt_dev);
> +	sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
> +
> +	return 0;
> +}
> +
> +static int sunxi_wdt_resume(struct device *dev)
> +{
> +	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
> +
> +	if (sunxi_wdt->running_at_suspend)
> +		sunxi_wdt_start(&sunxi_wdt->wdt_dev);
> +
> +	return 0;
> +}

[Severity: Low]
Could sunxi_wdt_suspend() and sunxi_wdt_resume() check
watchdog_hw_running(&sunxi_wdt->wdt_dev) instead of tracking
running_at_suspend?  Both sunxi_wdt_probe() and the watchdog core already
maintain WDOG_HW_RUNNING in wdt_dev.status, and guarding sunxi_wdt_stop()
with watchdog_hw_running() also avoids reading and writing wdt_mode on
suspend when the watchdog is inactive.

Also, this driver neither sets max_hw_heartbeat_ms nor calls
watchdog_stop_ping_on_suspend(), so the comment's reference to the
watchdog core cancelling its ping worker during suspend does not apply
here.

> +
> +static const struct dev_pm_ops sunxi_wdt_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(sunxi_wdt_suspend, sunxi_wdt_resume)
> +};
> +
>  static const struct watchdog_info sunxi_wdt_info = {

[ ... ]

> @@ -348,6 +381,7 @@ static struct platform_driver sunxi_wdt_driver = {
>  	.driver		= {
>  		.name		= DRV_NAME,
>  		.of_match_table	= sunxi_wdt_dt_ids,
> +		.pm		= &sunxi_wdt_pm_ops,
>  	},
>  };

[Severity: Medium]
Does building with CONFIG_PM_SLEEP=n warn about unused functions for
sunxi_wdt_suspend() and sunxi_wdt_resume()?  SET_SYSTEM_SLEEP_PM_OPS()
expands to nothing when CONFIG_PM_SLEEP is disabled, leaving both static
functions unreferenced.  Using DEFINE_SIMPLE_DEV_PM_OPS() with
pm_sleep_ptr(&sunxi_wdt_pm_ops) lets the compiler drop the callbacks and
PM ops structure without warnings.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117092036.12192-1-hsyysy@163.com?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-17  9:20 [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend Yang Siyuan
  2026-11-17  9:36 ` sashiko-bot
@ 2026-11-17 10:40 ` Yang Siyuan
  2026-11-17 15:51 ` [PATCH] " kernel test robot
  2 siblings, 0 replies; 8+ messages in thread
From: Yang Siyuan @ 2026-11-17 10:40 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: linux-watchdog, linux-arm-kernel, linux-sunxi, linux-kernel

The H616 watchdog has a maximum timeout of 16 seconds.  systemd keeps
/dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system
suspend all userspace is frozen and the watchdog core does not stop the
hardware.  A suspend longer than the timeout therefore resets the board
before it can resume.

Add system sleep PM ops to stop the watchdog before suspend and restart
it after resume if it was running.  The driver did not store its private
data in the platform device, so add platform_set_drvdata() for the PM
callbacks.

Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() so the callbacks are
still referenced when CONFIG_PM_SLEEP is disabled, and use
watchdog_hw_running() instead of a private flag to decide whether the
hardware needs to be stopped and restarted.

Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes
without the 16-second watchdog reset, and /dev/watchdog0 keeps working
afterwards.

Signed-off-by: Yang Siyuan <hsyysy@163.com>
---
Changes in v2:
- Use DEFINE_SIMPLE_DEV_PM_OPS()/pm_sleep_ptr() to avoid unused-function
  warnings with CONFIG_PM_SLEEP=n.
- Use watchdog_hw_running() instead of tracking running_at_suspend.
- Drop the inaccurate ping-worker reference from the comment.

 drivers/watchdog/sunxi_wdt.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index a6500eb..3fdc7bf 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -225,6 +225,35 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)
 	return 0;
 }
 
+/*
+ * The hardware watchdog has a maximum timeout of 16 seconds.  A system
+ * suspend easily lasts longer than that, and the watchdog core does not
+ * stop the hardware during system sleep.  Stop the watchdog explicitly
+ * while suspended and re-arm it on resume if it was running.
+ */
+static int sunxi_wdt_suspend(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+		sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static int sunxi_wdt_resume(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+		sunxi_wdt_start(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(sunxi_wdt_pm_ops,
+				sunxi_wdt_suspend, sunxi_wdt_resume);
+
 static const struct watchdog_info sunxi_wdt_info = {
 	.identity	= DRV_NAME,
 	.options	= WDIOF_SETTIMEOUT |
@@ -307,6 +336,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(sunxi_wdt->wdt_base))
 		return PTR_ERR(sunxi_wdt->wdt_base);
 
+	platform_set_drvdata(pdev, sunxi_wdt);
+
 	sunxi_wdt->wdt_dev.info = &sunxi_wdt_info;
 	sunxi_wdt->wdt_dev.ops = &sunxi_wdt_ops;
 	sunxi_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
@@ -348,6 +379,7 @@ static struct platform_driver sunxi_wdt_driver = {
 	.driver		= {
 		.name		= DRV_NAME,
 		.of_match_table	= sunxi_wdt_dt_ids,
+		.pm		= pm_sleep_ptr(&sunxi_wdt_pm_ops),
 	},
 };
 

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-17  9:20 [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend Yang Siyuan
  2026-11-17  9:36 ` sashiko-bot
  2026-11-17 10:40 ` [PATCH v2] " Yang Siyuan
@ 2026-11-17 15:51 ` kernel test robot
  2026-11-17 23:18   ` [PATCH v3] " Yang Siyuan
  2 siblings, 1 reply; 8+ messages in thread
From: kernel test robot @ 2026-11-17 15:51 UTC (permalink / raw)
  To: Yang Siyuan, Wim Van Sebroeck, Guenter Roeck
  Cc: oe-kbuild-all, linux-watchdog, linux-arm-kernel, linux-sunxi,
	linux-kernel

Hi Yang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on aebb7274476403040d582c61478df8f4a7bf9cd3]

url:    https://github.com/intel-lab-lkp/linux/commits/Yang-Siyuan/watchdog-sunxi_wdt-stop-the-watchdog-across-system-suspend/20261117-172036
base:   aebb7274476403040d582c61478df8f4a7bf9cd3
patch link:    https://lore.kernel.org/r/20261117092036.12192-1-hsyysy%40163.com
patch subject: [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend
config: csky-randconfig-1001-20261117 (https://download.01.org/0day-ci/archive/20261117/202611172344.RbQl66xu-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 13.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261117/202611172344.RbQl66xu-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611172344.RbQl66xu-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/watchdog/sunxi_wdt.c:245:12: warning: 'sunxi_wdt_resume' defined but not used [-Wunused-function]
     245 | static int sunxi_wdt_resume(struct device *dev)
         |            ^~~~~~~~~~~~~~~~
>> drivers/watchdog/sunxi_wdt.c:235:12: warning: 'sunxi_wdt_suspend' defined but not used [-Wunused-function]
     235 | static int sunxi_wdt_suspend(struct device *dev)
         |            ^~~~~~~~~~~~~~~~~


vim +/sunxi_wdt_resume +245 drivers/watchdog/sunxi_wdt.c

   228	
   229	/*
   230	 * The hardware watchdog has a maximum timeout of 16 seconds.  A system
   231	 * suspend easily lasts longer than that, and the watchdog core only cancels
   232	 * its ping worker during suspend; it does not stop the timer.  Stop the
   233	 * watchdog explicitly while suspended and re-arm it on resume.
   234	 */
 > 235	static int sunxi_wdt_suspend(struct device *dev)
   236	{
   237		struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
   238	
   239		sunxi_wdt->running_at_suspend = sunxi_wdt_is_running(&sunxi_wdt->wdt_dev);
   240		sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
   241	
   242		return 0;
   243	}
   244	
 > 245	static int sunxi_wdt_resume(struct device *dev)
   246	{
   247		struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
   248	
   249		if (sunxi_wdt->running_at_suspend)
   250			sunxi_wdt_start(&sunxi_wdt->wdt_dev);
   251	
   252		return 0;
   253	}
   254	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-17 15:51 ` [PATCH] " kernel test robot
@ 2026-11-17 23:18   ` Yang Siyuan
  2026-11-18  0:28     ` Guenter Roeck
  0 siblings, 1 reply; 8+ messages in thread
From: Yang Siyuan @ 2026-11-17 23:18 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: linux-watchdog, linux-arm-kernel, linux-sunxi, linux-kernel

The H616 watchdog has a maximum timeout of 16 seconds.  systemd keeps
/dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system
suspend all userspace is frozen and the watchdog core does not stop the
hardware.  A suspend longer than the timeout therefore resets the board
before it can resume.

Add system sleep PM ops to stop the watchdog before suspend and restart
it after resume if it was running.  The driver did not store its private
data in the platform device, so add platform_set_drvdata() for the PM
callbacks.

Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr(), and use
watchdog_hw_running() instead of a private flag to decide whether the
hardware needs to be stopped and restarted.

Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes
without the 16-second watchdog reset, and /dev/watchdog0 keeps working
afterwards.

Signed-off-by: Yang Siyuan <hsyysy@163.com>
---
Changes in v3:
- Mark the PM callbacks __maybe_unused.  With CONFIG_PM_SLEEP=n the
  pm_sleep_ptr() references expand to NULL, so both callbacks were unused
  and a W=1 build warned about them.  Reported by the kernel test robot:
  https://lore.kernel.org/oe-kbuild-all/202611172344.RbQl66xu-lkp@intel.com/
- Reword the v2 changelog entry: pm_sleep_ptr() alone does not keep the
  callbacks referenced when CONFIG_PM_SLEEP is disabled.

Changes in v2:
- Use DEFINE_SIMPLE_DEV_PM_OPS()/pm_sleep_ptr() to avoid unused-function
  warnings with CONFIG_PM_SLEEP=n.
- Use watchdog_hw_running() instead of tracking running_at_suspend.
- Drop the inaccurate ping-worker reference from the comment.

 drivers/watchdog/sunxi_wdt.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index a6500eb..3fdc7bf 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -225,6 +225,35 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)
 	return 0;
 }
 
+/*
+ * The hardware watchdog has a maximum timeout of 16 seconds.  A system
+ * suspend easily lasts longer than that, and the watchdog core does not
+ * stop the hardware during system sleep.  Stop the watchdog explicitly
+ * while suspended and re-arm it on resume if it was running.
+ */
+static int __maybe_unused sunxi_wdt_suspend(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+		sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static int __maybe_unused sunxi_wdt_resume(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+		sunxi_wdt_start(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(sunxi_wdt_pm_ops,
+				sunxi_wdt_suspend, sunxi_wdt_resume);
+
 static const struct watchdog_info sunxi_wdt_info = {
 	.identity	= DRV_NAME,
 	.options	= WDIOF_SETTIMEOUT |
@@ -307,6 +336,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(sunxi_wdt->wdt_base))
 		return PTR_ERR(sunxi_wdt->wdt_base);
 
+	platform_set_drvdata(pdev, sunxi_wdt);
+
 	sunxi_wdt->wdt_dev.info = &sunxi_wdt_info;
 	sunxi_wdt->wdt_dev.ops = &sunxi_wdt_ops;
 	sunxi_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
@@ -348,6 +379,7 @@ static struct platform_driver sunxi_wdt_driver = {
 	.driver		= {
 		.name		= DRV_NAME,
 		.of_match_table	= sunxi_wdt_dt_ids,
+		.pm		= pm_sleep_ptr(&sunxi_wdt_pm_ops),
 	},
 };
 

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.56.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-17 23:18   ` [PATCH v3] " Yang Siyuan
@ 2026-11-18  0:28     ` Guenter Roeck
  2026-11-18  0:50       ` [PATCH v4] " Yang Siyuan
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2026-11-18  0:28 UTC (permalink / raw)
  To: Yang Siyuan, Wim Van Sebroeck
  Cc: linux-watchdog, linux-arm-kernel, linux-sunxi, linux-kernel

On 11/17/26 15:18, Yang Siyuan wrote:
> The H616 watchdog has a maximum timeout of 16 seconds.  systemd keeps
> /dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system
> suspend all userspace is frozen and the watchdog core does not stop the
> hardware.  A suspend longer than the timeout therefore resets the board
> before it can resume.
> 
> Add system sleep PM ops to stop the watchdog before suspend and restart
> it after resume if it was running.  The driver did not store its private
> data in the platform device, so add platform_set_drvdata() for the PM
> callbacks.
> 
> Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr(), and use
> watchdog_hw_running() instead of a private flag to decide whether the
> hardware needs to be stopped and restarted.
> 
> Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes
> without the 16-second watchdog reset, and /dev/watchdog0 keeps working
> afterwards.
> 
> Signed-off-by: Yang Siyuan <hsyysy@163.com>
> ---
> Changes in v3:
> - Mark the PM callbacks __maybe_unused.  With CONFIG_PM_SLEEP=n the
>    pm_sleep_ptr() references expand to NULL, so both callbacks were unused
>    and a W=1 build warned about them.  Reported by the kernel test robot:
>    https://lore.kernel.org/oe-kbuild-all/202611172344.RbQl66xu-lkp@intel.com/

That build report was for v1 of the patch. __maybe_unused is unnecessary
with DEFINE_SIMPLE_DEV_PM_OPS.

Guenter


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-18  0:28     ` Guenter Roeck
@ 2026-11-18  0:50       ` Yang Siyuan
  2026-11-18  4:24         ` Guenter Roeck
  0 siblings, 1 reply; 8+ messages in thread
From: Yang Siyuan @ 2026-11-18  0:50 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: linux-watchdog, linux-arm-kernel, linux-sunxi, linux-kernel

The H616 watchdog has a maximum timeout of 16 seconds.  systemd keeps
/dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system
suspend all userspace is frozen and the watchdog core does not stop the
hardware.  A suspend longer than the timeout therefore resets the board
before it can resume.

Add system sleep PM ops to stop the watchdog before suspend and restart
it after resume if it was running.  The driver did not store its private
data in the platform device, so add platform_set_drvdata() for the PM
callbacks.

Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr(), and use
watchdog_hw_running() instead of a private flag to decide whether the
hardware needs to be stopped and restarted.

Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes
without the 16-second watchdog reset, and /dev/watchdog0 keeps working
afterwards.

Signed-off-by: Yang Siyuan <hsyysy@163.com>
---
Changes in v4:
- Drop __maybe_unused again.  The W=1 report was against v1, which used
  SET_SYSTEM_SLEEP_PM_OPS(); that macro expands to nothing when
  CONFIG_PM_SLEEP=n, so the callbacks were unused.  v2 already replaced it
  with DEFINE_SIMPLE_DEV_PM_OPS(), whose SYSTEM_SLEEP_PM_OPS() takes the
  callback addresses through pm_sleep_ptr() even with CONFIG_PM_SLEEP=n,
  so the functions are never unused.  The v3 change is reverted in v4.

Changes in v3:
- Mark the PM callbacks __maybe_unused, in response to a W=1 report that
  turned out to be against v1.  Reverted in v4.

Changes in v2:
- Use DEFINE_SIMPLE_DEV_PM_OPS()/pm_sleep_ptr() to avoid unused-function
  warnings with CONFIG_PM_SLEEP=n.
- Use watchdog_hw_running() instead of tracking running_at_suspend.
- Drop the inaccurate ping-worker reference from the comment.

 drivers/watchdog/sunxi_wdt.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index a6500eb..3fdc7bf 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -225,6 +225,35 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev)
 	return 0;
 }
 
+/*
+ * The hardware watchdog has a maximum timeout of 16 seconds.  A system
+ * suspend easily lasts longer than that, and the watchdog core does not
+ * stop the hardware during system sleep.  Stop the watchdog explicitly
+ * while suspended and re-arm it on resume if it was running.
+ */
+static int sunxi_wdt_suspend(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+		sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static int sunxi_wdt_resume(struct device *dev)
+{
+	struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev);
+
+	if (watchdog_hw_running(&sunxi_wdt->wdt_dev))
+		sunxi_wdt_start(&sunxi_wdt->wdt_dev);
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(sunxi_wdt_pm_ops,
+				sunxi_wdt_suspend, sunxi_wdt_resume);
+
 static const struct watchdog_info sunxi_wdt_info = {
 	.identity	= DRV_NAME,
 	.options	= WDIOF_SETTIMEOUT |
@@ -307,6 +336,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(sunxi_wdt->wdt_base))
 		return PTR_ERR(sunxi_wdt->wdt_base);
 
+	platform_set_drvdata(pdev, sunxi_wdt);
+
 	sunxi_wdt->wdt_dev.info = &sunxi_wdt_info;
 	sunxi_wdt->wdt_dev.ops = &sunxi_wdt_ops;
 	sunxi_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
@@ -348,6 +379,7 @@ static struct platform_driver sunxi_wdt_driver = {
 	.driver		= {
 		.name		= DRV_NAME,
 		.of_match_table	= sunxi_wdt_dt_ids,
+		.pm		= pm_sleep_ptr(&sunxi_wdt_pm_ops),
 	},
 };
 

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4] watchdog: sunxi_wdt: stop the watchdog across system suspend
  2026-11-18  0:50       ` [PATCH v4] " Yang Siyuan
@ 2026-11-18  4:24         ` Guenter Roeck
  0 siblings, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2026-11-18  4:24 UTC (permalink / raw)
  To: Yang Siyuan
  Cc: Wim Van Sebroeck, linux-watchdog, linux-arm-kernel, linux-sunxi,
	linux-kernel

On Wed, Nov 18, 2026 at 08:50:48AM +0800, Yang Siyuan wrote:
> The H616 watchdog has a maximum timeout of 16 seconds.  systemd keeps
> /dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system
> suspend all userspace is frozen and the watchdog core does not stop the
> hardware.  A suspend longer than the timeout therefore resets the board
> before it can resume.
> 
> Add system sleep PM ops to stop the watchdog before suspend and restart
> it after resume if it was running.  The driver did not store its private
> data in the platform device, so add platform_set_drvdata() for the PM
> callbacks.
> 
> Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr(), and use
> watchdog_hw_running() instead of a private flag to decide whether the
> hardware needs to be stopped and restarted.
> 
> Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes
> without the 16-second watchdog reset, and /dev/watchdog0 keeps working
> afterwards.
> 
> Signed-off-by: Yang Siyuan <hsyysy@163.com>

Applied.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-18  4:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  9:20 [PATCH] watchdog: sunxi_wdt: stop the watchdog across system suspend Yang Siyuan
2026-11-17  9:36 ` sashiko-bot
2026-11-17 10:40 ` [PATCH v2] " Yang Siyuan
2026-11-17 15:51 ` [PATCH] " kernel test robot
2026-11-17 23:18   ` [PATCH v3] " Yang Siyuan
2026-11-18  0:28     ` Guenter Roeck
2026-11-18  0:50       ` [PATCH v4] " Yang Siyuan
2026-11-18  4:24         ` Guenter Roeck

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.