2022-01-09 11:41:31

by Alistair Francis

[permalink] [raw]
Subject: [PATCH 0/2] watchdog: imx_wdt2: Enable ping on suspend support

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



2022-01-09 11:41:39

by Alistair Francis

[permalink] [raw]
Subject: [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend

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 <[email protected]>
---
.../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


2022-01-09 11:41:47

by Alistair Francis

[permalink] [raw]
Subject: [PATCH 2/2] ARM: dts: imx7d: remarkable2: set ping-during-suspend for watchdog

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

Signed-off-by: Alistair Francis <[email protected]>
---
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


2022-01-13 18:56:33

by Stefan Wahren

[permalink] [raw]
Subject: Re: [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend

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 <[email protected]>
> ---
> .../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)) {
> /*


2022-01-13 19:43:15

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 1/2] watchdog: imx2_wdg: Alow ping on suspend

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