linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] watchdog: imx_wdt2: Enable ping on suspend support
@ 2022-01-09 11:41 Alistair Francis
  2022-01-09 11:41 ` [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend Alistair Francis
  2022-01-09 11:41 ` [PATCH 2/2] ARM: dts: imx7d: remarkable2: set ping-during-suspend for watchdog Alistair Francis
  0 siblings, 2 replies; 5+ messages in thread
From: Alistair Francis @ 2022-01-09 11:41 UTC (permalink / raw)
  To: linux-kernel, linux, shawnguo, wim, linux-watchdog, s.hauer,
	linux-arm-kernel
  Cc: linux-imx, kernel, festevam, devicetree, robh+dt, Alistair Francis

When running Linux on the reMarkable2 tablet the device reboots two
minutes after suspend. This is because we don't go into low power
mode so the watchdog timer is still running and triggers a reboot.

This series adds optional support for ping on suspend for the
i.MX watchdog timer and then enables it for the reMarkable2 tablet.

Alistair Francis (2):
  watchdog: imx2_wdg: Alow ping on suspend
  ARM: dts: imx7d: remarkable2: set ping-during-suspend for watchdog

 .../bindings/watchdog/fsl-imx-wdt.yaml        |  7 ++++++
 arch/arm/boot/dts/imx7d-remarkable2.dts       |  1 +
 drivers/watchdog/imx2_wdt.c                   | 22 +++++++++++++------
 3 files changed, 23 insertions(+), 7 deletions(-)

-- 
2.31.1


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

* [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend
  2022-01-09 11:41 [PATCH 0/2] watchdog: imx_wdt2: Enable ping on suspend support Alistair Francis
@ 2022-01-09 11:41 ` Alistair Francis
  2022-01-13 18:55   ` Stefan Wahren
  2022-01-09 11:41 ` [PATCH 2/2] ARM: dts: imx7d: remarkable2: set ping-during-suspend for watchdog Alistair Francis
  1 sibling, 1 reply; 5+ messages in thread
From: Alistair Francis @ 2022-01-09 11:41 UTC (permalink / raw)
  To: linux-kernel, linux, shawnguo, wim, linux-watchdog, s.hauer,
	linux-arm-kernel
  Cc: linux-imx, kernel, festevam, devicetree, robh+dt, Alistair Francis

The i.MX watchdog cannot be disabled by softwrae once it has been
enabled. This means that it can't be stopped before suspend.

For systems that enter low power mode this is fine, as the watchdog will
be automatically stopped by hardwrae in low power mode. Not all i.MX
platforms support low power mode in the mainline kernel. For example the
i.MX7D does not enter low power mode and so will be rebooted 2 minutes
after entering freeze or mem sleep states.

This patch introduces a device tree property "fsl,ping-during-suspend"
that can be used to enable ping on suspend support for these systems.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 .../bindings/watchdog/fsl-imx-wdt.yaml        |  7 ++++++
 drivers/watchdog/imx2_wdt.c                   | 22 +++++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml b/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml
index fb7695515be1..b8660a3c456c 100644
--- a/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml
+++ b/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml
@@ -55,6 +55,13 @@ properties:
       If present, the watchdog device is configured to assert its
       external reset (WDOG_B) instead of issuing a software reset.
 
+  fsl,ping-during-suspend:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: |
+      If present, the kernel will ping the watchdog during suspend.
+      This should be used on platforms that don't enter low power mode
+      during suspend.
+
 required:
   - compatible
   - interrupts
diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 51bfb796898b..9a5fdb3173a8 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -66,6 +66,7 @@ struct imx2_wdt_device {
 	struct watchdog_device wdog;
 	bool ext_reset;
 	bool clk_is_on;
+	bool no_ping;
 };
 
 static bool nowayout = WATCHDOG_NOWAYOUT;
@@ -312,12 +313,14 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
 
 	wdev->ext_reset = of_property_read_bool(dev->of_node,
 						"fsl,ext-reset-output");
+	wdev->no_ping = !of_property_read_bool(dev->of_node, "fsl,ping-during-suspend");
 	platform_set_drvdata(pdev, wdog);
 	watchdog_set_drvdata(wdog, wdev);
 	watchdog_set_nowayout(wdog, nowayout);
 	watchdog_set_restart_priority(wdog, 128);
 	watchdog_init_timeout(wdog, timeout, dev);
-	watchdog_stop_ping_on_suspend(wdog);
+	if (wdev->no_ping)
+		watchdog_stop_ping_on_suspend(wdog);
 
 	if (imx2_wdt_is_running(wdev)) {
 		imx2_wdt_set_timeout(wdog, wdog->timeout);
@@ -366,9 +369,11 @@ static int __maybe_unused imx2_wdt_suspend(struct device *dev)
 		imx2_wdt_ping(wdog);
 	}
 
-	clk_disable_unprepare(wdev->clk);
+	if (wdev->no_ping) {
+		clk_disable_unprepare(wdev->clk);
 
-	wdev->clk_is_on = false;
+		wdev->clk_is_on = false;
+	}
 
 	return 0;
 }
@@ -380,11 +385,14 @@ static int __maybe_unused imx2_wdt_resume(struct device *dev)
 	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
 	int ret;
 
-	ret = clk_prepare_enable(wdev->clk);
-	if (ret)
-		return ret;
+	if (wdev->no_ping) {
+		ret = clk_prepare_enable(wdev->clk);
 
-	wdev->clk_is_on = true;
+		if (ret)
+			return ret;
+
+		wdev->clk_is_on = true;
+	}
 
 	if (watchdog_active(wdog) && !imx2_wdt_is_running(wdev)) {
 		/*
-- 
2.31.1


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

* [PATCH 2/2] ARM: dts: imx7d: remarkable2: set ping-during-suspend for watchdog
  2022-01-09 11:41 [PATCH 0/2] watchdog: imx_wdt2: Enable ping on suspend support Alistair Francis
  2022-01-09 11:41 ` [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend Alistair Francis
@ 2022-01-09 11:41 ` Alistair Francis
  1 sibling, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2022-01-09 11:41 UTC (permalink / raw)
  To: linux-kernel, linux, shawnguo, wim, linux-watchdog, s.hauer,
	linux-arm-kernel
  Cc: linux-imx, kernel, festevam, devicetree, robh+dt, Alistair Francis

Set ping-during-suspend for the reMarkable watchdog timer to avoid the
device rebooting when asleep.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 arch/arm/boot/dts/imx7d-remarkable2.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/imx7d-remarkable2.dts b/arch/arm/boot/dts/imx7d-remarkable2.dts
index 89cbf13097a4..99a453108af7 100644
--- a/arch/arm/boot/dts/imx7d-remarkable2.dts
+++ b/arch/arm/boot/dts/imx7d-remarkable2.dts
@@ -115,6 +115,7 @@ &wdog1 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_wdog>;
 	fsl,ext-reset-output;
+	fsl,ping-during-suspend;
 };
 
 &iomuxc {
-- 
2.31.1


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

* Re: [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend
  2022-01-09 11:41 ` [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend Alistair Francis
@ 2022-01-13 18:55   ` Stefan Wahren
  2022-01-13 19:43     ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Wahren @ 2022-01-13 18:55 UTC (permalink / raw)
  To: Alistair Francis, linux-kernel, linux, shawnguo, wim,
	linux-watchdog, s.hauer, linux-arm-kernel
  Cc: linux-imx, kernel, festevam, devicetree, robh+dt

Hi,

Am 09.01.22 um 12:41 schrieb Alistair Francis:
> The i.MX watchdog cannot be disabled by softwrae once it has been
s/softwrae/software/
> enabled. This means that it can't be stopped before suspend.
>
> For systems that enter low power mode this is fine, as the watchdog will
> be automatically stopped by hardwrae in low power mode. Not all i.MX
s/hardwrae/hardware/
> platforms support low power mode in the mainline kernel. For example the
> i.MX7D does not enter low power mode and so will be rebooted 2 minutes
> after entering freeze or mem sleep states.
>
> This patch introduces a device tree property "fsl,ping-during-suspend"
> that can be used to enable ping on suspend support for these systems.

Introducing vendor specific properties for Linux behavior should be
avoided. The DT should describe just the hardware.

In case i.mx7d is affected, how about enabling this workaround for
compatible fsl,imx7d-wdt? This has the advantage that in case low power
mode will be implemented
<https://elixir.bootlin.com/linux/latest/B/ident/fsl%2Cimx7d-wdt>, we
don't have to care about DTB files.

Best regards

>
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
>  .../bindings/watchdog/fsl-imx-wdt.yaml        |  7 ++++++
>  drivers/watchdog/imx2_wdt.c                   | 22 +++++++++++++------
>  2 files changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml b/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml
> index fb7695515be1..b8660a3c456c 100644
> --- a/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml
> +++ b/Documentation/devicetree/bindings/watchdog/fsl-imx-wdt.yaml
> @@ -55,6 +55,13 @@ properties:
>        If present, the watchdog device is configured to assert its
>        external reset (WDOG_B) instead of issuing a software reset.
>  
> +  fsl,ping-during-suspend:
> +    $ref: /schemas/types.yaml#/definitions/flag
> +    description: |
> +      If present, the kernel will ping the watchdog during suspend.
> +      This should be used on platforms that don't enter low power mode
> +      during suspend.
> +
>  required:
>    - compatible
>    - interrupts
> diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
> index 51bfb796898b..9a5fdb3173a8 100644
> --- a/drivers/watchdog/imx2_wdt.c
> +++ b/drivers/watchdog/imx2_wdt.c
> @@ -66,6 +66,7 @@ struct imx2_wdt_device {
>  	struct watchdog_device wdog;
>  	bool ext_reset;
>  	bool clk_is_on;
> +	bool no_ping;
>  };
>  
>  static bool nowayout = WATCHDOG_NOWAYOUT;
> @@ -312,12 +313,14 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
>  
>  	wdev->ext_reset = of_property_read_bool(dev->of_node,
>  						"fsl,ext-reset-output");
> +	wdev->no_ping = !of_property_read_bool(dev->of_node, "fsl,ping-during-suspend");
>  	platform_set_drvdata(pdev, wdog);
>  	watchdog_set_drvdata(wdog, wdev);
>  	watchdog_set_nowayout(wdog, nowayout);
>  	watchdog_set_restart_priority(wdog, 128);
>  	watchdog_init_timeout(wdog, timeout, dev);
> -	watchdog_stop_ping_on_suspend(wdog);
> +	if (wdev->no_ping)
> +		watchdog_stop_ping_on_suspend(wdog);
>  
>  	if (imx2_wdt_is_running(wdev)) {
>  		imx2_wdt_set_timeout(wdog, wdog->timeout);
> @@ -366,9 +369,11 @@ static int __maybe_unused imx2_wdt_suspend(struct device *dev)
>  		imx2_wdt_ping(wdog);
>  	}
>  
> -	clk_disable_unprepare(wdev->clk);
> +	if (wdev->no_ping) {
> +		clk_disable_unprepare(wdev->clk);
>  
> -	wdev->clk_is_on = false;
> +		wdev->clk_is_on = false;
> +	}
>  
>  	return 0;
>  }
> @@ -380,11 +385,14 @@ static int __maybe_unused imx2_wdt_resume(struct device *dev)
>  	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
>  	int ret;
>  
> -	ret = clk_prepare_enable(wdev->clk);
> -	if (ret)
> -		return ret;
> +	if (wdev->no_ping) {
> +		ret = clk_prepare_enable(wdev->clk);
>  
> -	wdev->clk_is_on = true;
> +		if (ret)
> +			return ret;
> +
> +		wdev->clk_is_on = true;
> +	}
>  
>  	if (watchdog_active(wdog) && !imx2_wdt_is_running(wdev)) {
>  		/*


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

* Re: [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend
  2022-01-13 18:55   ` Stefan Wahren
@ 2022-01-13 19:43     ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2022-01-13 19:43 UTC (permalink / raw)
  To: Stefan Wahren, Alistair Francis, linux-kernel, shawnguo, wim,
	linux-watchdog, s.hauer, linux-arm-kernel
  Cc: linux-imx, kernel, festevam, devicetree, robh+dt

On 1/13/22 10:55 AM, Stefan Wahren wrote:
> Hi,
> 
> Am 09.01.22 um 12:41 schrieb Alistair Francis:
>> The i.MX watchdog cannot be disabled by softwrae once it has been
> s/softwrae/software/
>> enabled. This means that it can't be stopped before suspend.
>>
>> For systems that enter low power mode this is fine, as the watchdog will
>> be automatically stopped by hardwrae in low power mode. Not all i.MX
> s/hardwrae/hardware/
>> platforms support low power mode in the mainline kernel. For example the
>> i.MX7D does not enter low power mode and so will be rebooted 2 minutes
>> after entering freeze or mem sleep states.
>>
>> This patch introduces a device tree property "fsl,ping-during-suspend"
>> that can be used to enable ping on suspend support for these systems.
> 
> Introducing vendor specific properties for Linux behavior should be
> avoided. The DT should describe just the hardware.
> 
> In case i.mx7d is affected, how about enabling this workaround for
> compatible fsl,imx7d-wdt? This has the advantage that in case low power
> mode will be implemented
> <https://elixir.bootlin.com/linux/latest/B/ident/fsl%2Cimx7d-wdt>, we
> don't have to care about DTB files.
> 

Agreed.

Guenter

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

end of thread, other threads:[~2022-01-13 19:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-09 11:41 [PATCH 0/2] watchdog: imx_wdt2: Enable ping on suspend support Alistair Francis
2022-01-09 11:41 ` [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend Alistair Francis
2022-01-13 18:55   ` Stefan Wahren
2022-01-13 19:43     ` Guenter Roeck
2022-01-09 11:41 ` [PATCH 2/2] ARM: dts: imx7d: remarkable2: set ping-during-suspend for watchdog Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).