All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: imx2_wdt: restore previous timeout after suspend+resume
@ 2017-12-29 13:59 Martin Kaiser
  2017-12-29 16:10 ` Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Martin Kaiser @ 2017-12-29 13:59 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck, linux-watchdog, linux-kernel
  Cc: Xiubo Li, kernel, Fabio Estevam, Martin Kaiser, stable

When the watchdog device is suspended, its timeout is set to the maximum
value. During resume, the previously set timeout should be restored.
This does not work at the moment.

The suspend function calls

imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);

and resume reverts this by calling

imx2_wdt_set_timeout(wdog, wdog->timeout);

However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
function.

Fix this by setting wdog->timeout to the previous value at the end of
the suspend function. This manual update makes wdog->timeout different
from the actual setting in the hardware. This should be ok in our case
as kernel code is not running while we're suspended.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Cc: stable@vger.kernel.org
---
 drivers/watchdog/imx2_wdt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 4874b0f..66efcc0 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -368,6 +368,7 @@ static int imx2_wdt_suspend(struct device *dev)
 {
 	struct watchdog_device *wdog = dev_get_drvdata(dev);
 	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
+	unsigned int resume_timeout = wdog->timeout;
 
 	/* The watchdog IP block is running */
 	if (imx2_wdt_is_running(wdev)) {
@@ -377,6 +378,7 @@ static int imx2_wdt_suspend(struct device *dev)
 
 	clk_disable_unprepare(wdev->clk);
 
+	wdog->timeout = resume_timeout;
 	return 0;
 }
 
-- 
2.1.4

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

* Re: [PATCH] watchdog: imx2_wdt: restore previous timeout after suspend+resume
  2017-12-29 13:59 [PATCH] watchdog: imx2_wdt: restore previous timeout after suspend+resume Martin Kaiser
@ 2017-12-29 16:10 ` Guenter Roeck
  2017-12-31 11:17 ` [PATCH v2] " Martin Kaiser
  2018-01-01 17:26 ` [PATCH v3] " Martin Kaiser
  2 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2017-12-29 16:10 UTC (permalink / raw)
  To: Martin Kaiser, Wim Van Sebroeck, linux-watchdog, linux-kernel
  Cc: Xiubo Li, kernel, Fabio Estevam, stable

On 12/29/2017 05:59 AM, Martin Kaiser wrote:
> When the watchdog device is suspended, its timeout is set to the maximum
> value. During resume, the previously set timeout should be restored.
> This does not work at the moment.
> 
> The suspend function calls
> 
> imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
> 
> and resume reverts this by calling
> 
> imx2_wdt_set_timeout(wdog, wdog->timeout);
> 
> However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
> wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
> function.
> 
> Fix this by setting wdog->timeout to the previous value at the end of
> the suspend function. This manual update makes wdog->timeout different
> from the actual setting in the hardware. This should be ok in our case
> as kernel code is not running while we're suspended.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> Cc: stable@vger.kernel.org

That works, though it is a bit hackish. Better would be to have a function
such as _imx2_wdt_set_timeout() which doesn't actually update wdt->timeout
and could be called from all the other places doing the same.
Separate patch, maybe.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/watchdog/imx2_wdt.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
> index 4874b0f..66efcc0 100644
> --- a/drivers/watchdog/imx2_wdt.c
> +++ b/drivers/watchdog/imx2_wdt.c
> @@ -368,6 +368,7 @@ static int imx2_wdt_suspend(struct device *dev)
>   {
>   	struct watchdog_device *wdog = dev_get_drvdata(dev);
>   	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
> +	unsigned int resume_timeout = wdog->timeout;
>   
>   	/* The watchdog IP block is running */
>   	if (imx2_wdt_is_running(wdev)) {
> @@ -377,6 +378,7 @@ static int imx2_wdt_suspend(struct device *dev)
>   
>   	clk_disable_unprepare(wdev->clk);
>   
> +	wdog->timeout = resume_timeout;
>   	return 0;
>   }
>   
> 

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

* [PATCH v2] watchdog: imx2_wdt: restore previous timeout after suspend+resume
  2017-12-29 13:59 [PATCH] watchdog: imx2_wdt: restore previous timeout after suspend+resume Martin Kaiser
  2017-12-29 16:10 ` Guenter Roeck
@ 2017-12-31 11:17 ` Martin Kaiser
  2017-12-31 14:43   ` Guenter Roeck
  2018-01-01 17:26 ` [PATCH v3] " Martin Kaiser
  2 siblings, 1 reply; 6+ messages in thread
From: Martin Kaiser @ 2017-12-31 11:17 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck, linux-watchdog, linux-kernel
  Cc: kernel, Fabio Estevam, Martin Kaiser, stable

When the watchdog device is suspended, its timeout is set to the maximum
value. During resume, the previously set timeout should be restored.
This does not work at the moment.

The suspend function calls

imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);

and resume reverts this by calling

imx2_wdt_set_timeout(wdog, wdog->timeout);

However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
function.

Fix this by adding a new function __imx2_wdt_set_timeout() which
only updates the hardware settings. imx2_wdt_set_timeout() now calls
__imx2_wdt_set_timeout() and then saves the new timeout to
wdog->timeout.

During suspend, we call __imx2_wdt_set_timeout() directly so that
wdog->timeout won't be updated and we can restore the previous value
during resume. This approach makes wdog->timeout different from the
actual setting in the hardware which is usually not a good thing.
However, the two differ only while we're suspended and no kernel code is
running, so it should be ok in this case.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Cc: stable@vger.kernel.org
---
changes in v2:
 helper function that updates the hw settings, as per Guenter's proposal

 drivers/watchdog/imx2_wdt.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 4874b0f..b0c2bca 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -169,18 +169,29 @@ static int imx2_wdt_ping(struct watchdog_device *wdog)
 	return 0;
 }
 
-static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
+static int __imx2_wdt_set_timeout(struct watchdog_device *wdog,
 				unsigned int new_timeout)
 {
 	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
 
-	wdog->timeout = new_timeout;
-
 	regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT,
 			   WDOG_SEC_TO_COUNT(new_timeout));
 	return 0;
 }
 
+static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
+				unsigned int new_timeout)
+{
+	int ret;
+
+	ret = __imx2_wdt_set_timeout(wdog, new_timeout);
+	if (ret < 0)
+		return ret;
+
+	wdog->timeout = new_timeout;
+	return 0;
+}
+
 static int imx2_wdt_set_pretimeout(struct watchdog_device *wdog,
 				   unsigned int new_pretimeout)
 {
@@ -371,7 +382,11 @@ static int imx2_wdt_suspend(struct device *dev)
 
 	/* The watchdog IP block is running */
 	if (imx2_wdt_is_running(wdev)) {
-		imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
+		/*
+		 * Don't update wdog->timeout, we'll restore the current value
+		 * during resume.
+		 */
+		__imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
 		imx2_wdt_ping(wdog);
 	}
 
-- 
2.1.4

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

* Re: [PATCH v2] watchdog: imx2_wdt: restore previous timeout after suspend+resume
  2017-12-31 11:17 ` [PATCH v2] " Martin Kaiser
@ 2017-12-31 14:43   ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2017-12-31 14:43 UTC (permalink / raw)
  To: Martin Kaiser, Wim Van Sebroeck, linux-watchdog, linux-kernel
  Cc: kernel, Fabio Estevam, stable

Hi Martin,

On 12/31/2017 03:17 AM, Martin Kaiser wrote:
> When the watchdog device is suspended, its timeout is set to the maximum
> value. During resume, the previously set timeout should be restored.
> This does not work at the moment.
> 
> The suspend function calls
> 
> imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
> 
> and resume reverts this by calling
> 
> imx2_wdt_set_timeout(wdog, wdog->timeout);
> 
> However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
> wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
> function.
> 
> Fix this by adding a new function __imx2_wdt_set_timeout() which
> only updates the hardware settings. imx2_wdt_set_timeout() now calls
> __imx2_wdt_set_timeout() and then saves the new timeout to
> wdog->timeout.
> 
> During suspend, we call __imx2_wdt_set_timeout() directly so that
> wdog->timeout won't be updated and we can restore the previous value
> during resume. This approach makes wdog->timeout different from the
> actual setting in the hardware which is usually not a good thing.
> However, the two differ only while we're suspended and no kernel code is
> running, so it should be ok in this case.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> Cc: stable@vger.kernel.org
> ---
> changes in v2:
>   helper function that updates the hw settings, as per Guenter's proposal
> 
>   drivers/watchdog/imx2_wdt.c | 23 +++++++++++++++++++----
>   1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
> index 4874b0f..b0c2bca 100644
> --- a/drivers/watchdog/imx2_wdt.c
> +++ b/drivers/watchdog/imx2_wdt.c
> @@ -169,18 +169,29 @@ static int imx2_wdt_ping(struct watchdog_device *wdog)
>   	return 0;
>   }
>   
> -static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
> +static int __imx2_wdt_set_timeout(struct watchdog_device *wdog,
>   				unsigned int new_timeout)

Please align the continuation line with '('.
Also, the function type should be void (always returning 0 and checking
that return value does not add any value).

Thanks,
Guenter

>   {
>   	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
>   
> -	wdog->timeout = new_timeout;
> -
>   	regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT,
>   			   WDOG_SEC_TO_COUNT(new_timeout));
>   	return 0;
>   }
>   
> +static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
> +				unsigned int new_timeout)
> +{
> +	int ret;
> +
> +	ret = __imx2_wdt_set_timeout(wdog, new_timeout);
> +	if (ret < 0)
> +		return ret;
> +
> +	wdog->timeout = new_timeout;
> +	return 0;
> +}
> +
>   static int imx2_wdt_set_pretimeout(struct watchdog_device *wdog,
>   				   unsigned int new_pretimeout)
>   {
> @@ -371,7 +382,11 @@ static int imx2_wdt_suspend(struct device *dev)
>   
>   	/* The watchdog IP block is running */
>   	if (imx2_wdt_is_running(wdev)) {
> -		imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
> +		/*
> +		 * Don't update wdog->timeout, we'll restore the current value
> +		 * during resume.
> +		 */
> +		__imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
>   		imx2_wdt_ping(wdog);
>   	}
>   
> 

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

* [PATCH v3] watchdog: imx2_wdt: restore previous timeout after suspend+resume
  2017-12-29 13:59 [PATCH] watchdog: imx2_wdt: restore previous timeout after suspend+resume Martin Kaiser
  2017-12-29 16:10 ` Guenter Roeck
  2017-12-31 11:17 ` [PATCH v2] " Martin Kaiser
@ 2018-01-01 17:26 ` Martin Kaiser
  2018-01-01 18:14   ` Guenter Roeck
  2 siblings, 1 reply; 6+ messages in thread
From: Martin Kaiser @ 2018-01-01 17:26 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck, linux-watchdog, linux-kernel
  Cc: kernel, Fabio Estevam, Martin Kaiser, stable

When the watchdog device is suspended, its timeout is set to the maximum
value. During resume, the previously set timeout should be restored.
This does not work at the moment.

The suspend function calls

imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);

and resume reverts this by calling

imx2_wdt_set_timeout(wdog, wdog->timeout);

However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
function.

Fix this by adding a new function __imx2_wdt_set_timeout() which
only updates the hardware settings. imx2_wdt_set_timeout() now calls
__imx2_wdt_set_timeout() and then saves the new timeout to
wdog->timeout.

During suspend, we call __imx2_wdt_set_timeout() directly so that
wdog->timeout won't be updated and we can restore the previous value
during resume. This approach makes wdog->timeout different from the
actual setting in the hardware which is usually not a good thing.
However, the two differ only while we're suspended and no kernel code is
running, so it should be ok in this case.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Cc: stable@vger.kernel.org
---
changes in v3:
 reformat
 remove return value of __imx2_wdt_set_timeout()

changes in v2:
 helper function that updates the hw settings, as per Guenter's proposal

 drivers/watchdog/imx2_wdt.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 4874b0f..518dfa1 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -169,15 +169,21 @@ static int imx2_wdt_ping(struct watchdog_device *wdog)
 	return 0;
 }
 
-static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
-				unsigned int new_timeout)
+static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,
+				   unsigned int new_timeout)
 {
 	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
 
-	wdog->timeout = new_timeout;
-
 	regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT,
 			   WDOG_SEC_TO_COUNT(new_timeout));
+}
+
+static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
+				unsigned int new_timeout)
+{
+	__imx2_wdt_set_timeout(wdog, new_timeout);
+
+	wdog->timeout = new_timeout;
 	return 0;
 }
 
@@ -371,7 +377,11 @@ static int imx2_wdt_suspend(struct device *dev)
 
 	/* The watchdog IP block is running */
 	if (imx2_wdt_is_running(wdev)) {
-		imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
+		/*
+		 * Don't update wdog->timeout, we'll restore the current value
+		 * during resume.
+		 */
+		__imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
 		imx2_wdt_ping(wdog);
 	}
 
-- 
2.1.4

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

* Re: [PATCH v3] watchdog: imx2_wdt: restore previous timeout after suspend+resume
  2018-01-01 17:26 ` [PATCH v3] " Martin Kaiser
@ 2018-01-01 18:14   ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2018-01-01 18:14 UTC (permalink / raw)
  To: Martin Kaiser, Wim Van Sebroeck, linux-watchdog, linux-kernel
  Cc: kernel, Fabio Estevam, stable

On 01/01/2018 09:26 AM, Martin Kaiser wrote:
> When the watchdog device is suspended, its timeout is set to the maximum
> value. During resume, the previously set timeout should be restored.
> This does not work at the moment.
> 
> The suspend function calls
> 
> imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
> 
> and resume reverts this by calling
> 
> imx2_wdt_set_timeout(wdog, wdog->timeout);
> 
> However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore,
> wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume
> function.
> 
> Fix this by adding a new function __imx2_wdt_set_timeout() which
> only updates the hardware settings. imx2_wdt_set_timeout() now calls
> __imx2_wdt_set_timeout() and then saves the new timeout to
> wdog->timeout.
> 
> During suspend, we call __imx2_wdt_set_timeout() directly so that
> wdog->timeout won't be updated and we can restore the previous value
> during resume. This approach makes wdog->timeout different from the
> actual setting in the hardware which is usually not a good thing.
> However, the two differ only while we're suspended and no kernel code is
> running, so it should be ok in this case.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> Cc: stable@vger.kernel.org

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> changes in v3:
>   reformat
>   remove return value of __imx2_wdt_set_timeout()
> 
> changes in v2:
>   helper function that updates the hw settings, as per Guenter's proposal
> 
>   drivers/watchdog/imx2_wdt.c | 20 +++++++++++++++-----
>   1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
> index 4874b0f..518dfa1 100644
> --- a/drivers/watchdog/imx2_wdt.c
> +++ b/drivers/watchdog/imx2_wdt.c
> @@ -169,15 +169,21 @@ static int imx2_wdt_ping(struct watchdog_device *wdog)
>   	return 0;
>   }
>   
> -static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
> -				unsigned int new_timeout)
> +static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,
> +				   unsigned int new_timeout)
>   {
>   	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
>   
> -	wdog->timeout = new_timeout;
> -
>   	regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT,
>   			   WDOG_SEC_TO_COUNT(new_timeout));
> +}
> +
> +static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
> +				unsigned int new_timeout)
> +{
> +	__imx2_wdt_set_timeout(wdog, new_timeout);
> +
> +	wdog->timeout = new_timeout;
>   	return 0;
>   }
>   
> @@ -371,7 +377,11 @@ static int imx2_wdt_suspend(struct device *dev)
>   
>   	/* The watchdog IP block is running */
>   	if (imx2_wdt_is_running(wdev)) {
> -		imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
> +		/*
> +		 * Don't update wdog->timeout, we'll restore the current value
> +		 * during resume.
> +		 */
> +		__imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
>   		imx2_wdt_ping(wdog);
>   	}
>   
> 

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

end of thread, other threads:[~2018-01-01 18:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-29 13:59 [PATCH] watchdog: imx2_wdt: restore previous timeout after suspend+resume Martin Kaiser
2017-12-29 16:10 ` Guenter Roeck
2017-12-31 11:17 ` [PATCH v2] " Martin Kaiser
2017-12-31 14:43   ` Guenter Roeck
2018-01-01 17:26 ` [PATCH v3] " Martin Kaiser
2018-01-01 18:14   ` 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.