2022-11-03 10:34:22

by Andrej Picej

[permalink] [raw]
Subject: [PATCH v3 0/3] Suspending i.MX watchdog in WAIT mode

The i.MX6 watchdog can't be stopped once started. Additionally, watchdog
hardware configuration needs to be able to handle low-power modes of the
SoC. For low-power modes, there are two configuration bits in the TRM:
- WDZST bit disables the watchdog timer in "deeper" low power modes and
- WDW bit disables the watchdog timer in "WAIT" mode

WDZST bit support is already in place since 1a9c5efa576e ("watchdog: imx2_wdt: disable watchdog timer during low power mode").
On the other hand, handling of WDZST bit was omitted so far but now
these patch series bring support for it.

SoC's "WAIT" low-power mode corresponds to Linux's freeze or
Suspend-to-Idle (S0) mode which can be activated with:

$ echo freeze > /sys/power/state

Without these patches, board would be reset by the watchdog after
timeout of 128 seconds since watchdog would not be stopped when SoC
entered Suspend-to-Idle mode. With patches in place, boards using
imx2-wdt are able to stay in Suspend-to-Idle mode indefinitely.

Last but not least, WDW bit is not found on all imx2-wdt supported i.MX
devices, therefore a new device-tree property "fsl,suspend-in-wait" has
been introduced for this.

Here is v1: https://lore.kernel.org/lkml/[email protected]/

Here is v2: https://lore.kernel.org/all/[email protected]/#t

Change log in the corresponding patches.

Andrej Picej (3):
watchdog: imx2_wdg: suspend watchdog in WAIT mode
dt-bindings: watchdog: fsl-imx: document suspend in wait mode
ARM: dts: imx6ul/ull: suspend i.MX6UL watchdog in wait mode

.../bindings/watchdog/fsl-imx-wdt.yaml | 33 +++++++++++
.../boot/dts/imx6ul-phytec-phycore-som.dtsi | 4 ++
drivers/watchdog/imx2_wdt.c | 55 ++++++++++++++++++-
3 files changed, 89 insertions(+), 3 deletions(-)

--
2.25.1



2022-11-03 10:40:14

by Andrej Picej

[permalink] [raw]
Subject: [PATCH v3 3/3] ARM: dts: imx6ul/ull: suspend i.MX6UL watchdog in wait mode

It was discovered that the watchdog triggers when the device is put into
"Suspend-To-Idle"/"freeze" low-power mode. Setting WDW bit disables
watchdog when the device is put into WAIT mode.

Signed-off-by: Andrej Picej <[email protected]>
Reviewed-by: Fabio Estevam <[email protected]>
---
Changes in v3:
- no changes

Changes in v2:
- no changes
---
arch/arm/boot/dts/imx6ul-phytec-phycore-som.dtsi | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul-phytec-phycore-som.dtsi b/arch/arm/boot/dts/imx6ul-phytec-phycore-som.dtsi
index 3cddc68917a0..5168ed0ffec3 100644
--- a/arch/arm/boot/dts/imx6ul-phytec-phycore-som.dtsi
+++ b/arch/arm/boot/dts/imx6ul-phytec-phycore-som.dtsi
@@ -102,6 +102,10 @@ &usdhc2 {
status = "disabled";
};

+&wdog1 {
+ fsl,suspend-in-wait;
+};
+
&iomuxc {
pinctrl_enet1: enet1grp {
fsl,pins = <
--
2.25.1


2022-11-03 11:03:25

by Andrej Picej

[permalink] [raw]
Subject: [PATCH v3 1/3] watchdog: imx2_wdg: suspend watchdog in WAIT mode

Putting device into the "Suspend-To-Idle" mode causes watchdog to
trigger and resets the board after set watchdog timeout period elapses.

Introduce new device-tree property "fsl,suspend-in-wait" which suspends
watchdog in WAIT mode. This is done by setting WDW bit in WCR
(Watchdog Control Register). Watchdog operation is restored after
exiting WAIT mode as expected. WAIT mode corresponds with Linux's
"Suspend-To-Idle".

Signed-off-by: Andrej Picej <[email protected]>
Reviewed-by: Fabio Estevam <[email protected]>
---
Changes in v3:
- fix spelling in commit message,
- fix and simplify property handling in probe,
- add a comment about unknown interaction between imx7d no-ping
functionality and "fsl,suspend-in-wait",
- property support handled by of_device_id data pointer.

Changes in v2:
- validate the property with compatible string, as this functionality
is not supported by all devices.
---
drivers/watchdog/imx2_wdt.c | 55 +++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index d0c5d47ddede..19ab7b3d286b 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -27,6 +27,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/of_address.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/watchdog.h>
@@ -35,6 +36,7 @@

#define IMX2_WDT_WCR 0x00 /* Control Register */
#define IMX2_WDT_WCR_WT (0xFF << 8) /* -> Watchdog Timeout Field */
+#define IMX2_WDT_WCR_WDW BIT(7) /* -> Watchdog disable for WAIT */
#define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */
#define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */
#define IMX2_WDT_WCR_WRE BIT(3) /* -> WDOG Reset Enable */
@@ -60,13 +62,19 @@

#define WDOG_SEC_TO_COUNT(s) ((s * 2 - 1) << 8)

+struct imx2_wdt_data {
+ bool wdw_supported;
+};
+
struct imx2_wdt_device {
struct clk *clk;
struct regmap *regmap;
struct watchdog_device wdog;
+ const struct imx2_wdt_data *data;
bool ext_reset;
bool clk_is_on;
bool no_ping;
+ bool sleep_wait;
};

static bool nowayout = WATCHDOG_NOWAYOUT;
@@ -129,6 +137,9 @@ static inline void imx2_wdt_setup(struct watchdog_device *wdog)

/* Suspend timer in low power mode, write once-only */
val |= IMX2_WDT_WCR_WDZST;
+ /* Suspend timer in low power WAIT mode, write once-only */
+ if (wdev->sleep_wait)
+ val |= IMX2_WDT_WCR_WDW;
/* Strip the old watchdog Time-Out value */
val &= ~IMX2_WDT_WCR_WT;
/* Generate internal chip-level reset if WDOG times out */
@@ -292,6 +303,8 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
wdog->max_hw_heartbeat_ms = IMX2_WDT_MAX_TIME * 1000;
wdog->parent = dev;

+ wdev->data = of_device_get_match_data(dev);
+
ret = platform_get_irq(pdev, 0);
if (ret > 0)
if (!devm_request_irq(dev, ret, imx2_wdt_isr, 0,
@@ -313,9 +326,18 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)

wdev->ext_reset = of_property_read_bool(dev->of_node,
"fsl,ext-reset-output");
+
+ if (of_property_read_bool(dev->of_node, "fsl,suspend-in-wait")) {
+ if (!wdev->data->wdw_supported) {
+ dev_err(dev, "suspend-in-wait not supported\n");
+ return -EINVAL;
+ }
+ wdev->sleep_wait = true;
+ }
+
/*
* The i.MX7D doesn't support low power mode, so we need to ping the watchdog
- * during suspend.
+ * during suspend. Interaction with "fsl,suspend-in-wait" is unknown!
*/
wdev->no_ping = !of_device_is_compatible(dev->of_node, "fsl,imx7d-wdt");
platform_set_drvdata(pdev, wdog);
@@ -417,9 +439,36 @@ static int __maybe_unused imx2_wdt_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(imx2_wdt_pm_ops, imx2_wdt_suspend,
imx2_wdt_resume);

+struct imx2_wdt_data imx_wdt = {
+ .wdw_supported = true,
+};
+
+struct imx2_wdt_data imx_wdt_legacy = {
+ .wdw_supported = false,
+};
+
static const struct of_device_id imx2_wdt_dt_ids[] = {
- { .compatible = "fsl,imx21-wdt", },
- { .compatible = "fsl,imx7d-wdt", },
+ { .compatible = "fsl,imx21-wdt", .data = &imx_wdt_legacy },
+ { .compatible = "fsl,imx25-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx27-wdt", .data = &imx_wdt_legacy },
+ { .compatible = "fsl,imx31-wdt", .data = &imx_wdt_legacy },
+ { .compatible = "fsl,imx35-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx50-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx51-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx53-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx6q-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx6sl-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx6sll-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx6sx-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx6ul-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx7d-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx8mm-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx8mn-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx8mp-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,imx8mq-wdt", .data = &imx_wdt },
+ { .compatible = "fsl,ls1012a-wdt", .data = &imx_wdt_legacy },
+ { .compatible = "fsl,ls1043a-wdt", .data = &imx_wdt_legacy },
+ { .compatible = "fsl,vf610-wdt", .data = &imx_wdt },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, imx2_wdt_dt_ids);
--
2.25.1


2022-11-03 16:03:23

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/3] watchdog: imx2_wdg: suspend watchdog in WAIT mode

On Thu, Nov 03, 2022 at 11:03:56AM +0100, Andrej Picej wrote:
> Putting device into the "Suspend-To-Idle" mode causes watchdog to
> trigger and resets the board after set watchdog timeout period elapses.
>
> Introduce new device-tree property "fsl,suspend-in-wait" which suspends
> watchdog in WAIT mode. This is done by setting WDW bit in WCR
> (Watchdog Control Register). Watchdog operation is restored after
> exiting WAIT mode as expected. WAIT mode corresponds with Linux's
> "Suspend-To-Idle".
>
> Signed-off-by: Andrej Picej <[email protected]>
> Reviewed-by: Fabio Estevam <[email protected]>

For my reference:

Reviewed-by: Guenter Roeck <[email protected]>

This will have to wait for dt approval.

Thanks,
Guenter

> ---
> Changes in v3:
> - fix spelling in commit message,
> - fix and simplify property handling in probe,
> - add a comment about unknown interaction between imx7d no-ping
> functionality and "fsl,suspend-in-wait",
> - property support handled by of_device_id data pointer.
>
> Changes in v2:
> - validate the property with compatible string, as this functionality
> is not supported by all devices.
> ---
> drivers/watchdog/imx2_wdt.c | 55 +++++++++++++++++++++++++++++++++++--
> 1 file changed, 52 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
> index d0c5d47ddede..19ab7b3d286b 100644
> --- a/drivers/watchdog/imx2_wdt.c
> +++ b/drivers/watchdog/imx2_wdt.c
> @@ -27,6 +27,7 @@
> #include <linux/module.h>
> #include <linux/moduleparam.h>
> #include <linux/of_address.h>
> +#include <linux/of_device.h>
> #include <linux/platform_device.h>
> #include <linux/regmap.h>
> #include <linux/watchdog.h>
> @@ -35,6 +36,7 @@
>
> #define IMX2_WDT_WCR 0x00 /* Control Register */
> #define IMX2_WDT_WCR_WT (0xFF << 8) /* -> Watchdog Timeout Field */
> +#define IMX2_WDT_WCR_WDW BIT(7) /* -> Watchdog disable for WAIT */
> #define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */
> #define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */
> #define IMX2_WDT_WCR_WRE BIT(3) /* -> WDOG Reset Enable */
> @@ -60,13 +62,19 @@
>
> #define WDOG_SEC_TO_COUNT(s) ((s * 2 - 1) << 8)
>
> +struct imx2_wdt_data {
> + bool wdw_supported;
> +};
> +
> struct imx2_wdt_device {
> struct clk *clk;
> struct regmap *regmap;
> struct watchdog_device wdog;
> + const struct imx2_wdt_data *data;
> bool ext_reset;
> bool clk_is_on;
> bool no_ping;
> + bool sleep_wait;
> };
>
> static bool nowayout = WATCHDOG_NOWAYOUT;
> @@ -129,6 +137,9 @@ static inline void imx2_wdt_setup(struct watchdog_device *wdog)
>
> /* Suspend timer in low power mode, write once-only */
> val |= IMX2_WDT_WCR_WDZST;
> + /* Suspend timer in low power WAIT mode, write once-only */
> + if (wdev->sleep_wait)
> + val |= IMX2_WDT_WCR_WDW;
> /* Strip the old watchdog Time-Out value */
> val &= ~IMX2_WDT_WCR_WT;
> /* Generate internal chip-level reset if WDOG times out */
> @@ -292,6 +303,8 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
> wdog->max_hw_heartbeat_ms = IMX2_WDT_MAX_TIME * 1000;
> wdog->parent = dev;
>
> + wdev->data = of_device_get_match_data(dev);
> +
> ret = platform_get_irq(pdev, 0);
> if (ret > 0)
> if (!devm_request_irq(dev, ret, imx2_wdt_isr, 0,
> @@ -313,9 +326,18 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
>
> wdev->ext_reset = of_property_read_bool(dev->of_node,
> "fsl,ext-reset-output");
> +
> + if (of_property_read_bool(dev->of_node, "fsl,suspend-in-wait")) {
> + if (!wdev->data->wdw_supported) {
> + dev_err(dev, "suspend-in-wait not supported\n");
> + return -EINVAL;
> + }
> + wdev->sleep_wait = true;
> + }
> +
> /*
> * The i.MX7D doesn't support low power mode, so we need to ping the watchdog
> - * during suspend.
> + * during suspend. Interaction with "fsl,suspend-in-wait" is unknown!
> */
> wdev->no_ping = !of_device_is_compatible(dev->of_node, "fsl,imx7d-wdt");
> platform_set_drvdata(pdev, wdog);
> @@ -417,9 +439,36 @@ static int __maybe_unused imx2_wdt_resume(struct device *dev)
> static SIMPLE_DEV_PM_OPS(imx2_wdt_pm_ops, imx2_wdt_suspend,
> imx2_wdt_resume);
>
> +struct imx2_wdt_data imx_wdt = {
> + .wdw_supported = true,
> +};
> +
> +struct imx2_wdt_data imx_wdt_legacy = {
> + .wdw_supported = false,
> +};
> +
> static const struct of_device_id imx2_wdt_dt_ids[] = {
> - { .compatible = "fsl,imx21-wdt", },
> - { .compatible = "fsl,imx7d-wdt", },
> + { .compatible = "fsl,imx21-wdt", .data = &imx_wdt_legacy },
> + { .compatible = "fsl,imx25-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx27-wdt", .data = &imx_wdt_legacy },
> + { .compatible = "fsl,imx31-wdt", .data = &imx_wdt_legacy },
> + { .compatible = "fsl,imx35-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx50-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx51-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx53-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx6q-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx6sl-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx6sll-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx6sx-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx6ul-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx7d-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx8mm-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx8mn-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx8mp-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,imx8mq-wdt", .data = &imx_wdt },
> + { .compatible = "fsl,ls1012a-wdt", .data = &imx_wdt_legacy },
> + { .compatible = "fsl,ls1043a-wdt", .data = &imx_wdt_legacy },
> + { .compatible = "fsl,vf610-wdt", .data = &imx_wdt },
> { /* sentinel */ }
> };
> MODULE_DEVICE_TABLE(of, imx2_wdt_dt_ids);
> --
> 2.25.1
>