Skip to content

Commit e06f7b6

Browse files
martin-kaisergregkh
authored andcommitted
watchdog: imx2_wdt: restore previous timeout after suspend+resume
commit 0be2672 upstream. 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> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b897f1d commit e06f7b6

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎drivers/watchdog/imx2_wdt.c‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,21 @@ static int imx2_wdt_ping(struct watchdog_device *wdog)
169169
return 0;
170170
}
171171

172-
static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
173-
unsigned int new_timeout)
172+
static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,
173+
unsigned int new_timeout)
174174
{
175175
struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
176176

177-
wdog->timeout = new_timeout;
178-
179177
regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT,
180178
WDOG_SEC_TO_COUNT(new_timeout));
179+
}
180+
181+
static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
182+
unsigned int new_timeout)
183+
{
184+
__imx2_wdt_set_timeout(wdog, new_timeout);
185+
186+
wdog->timeout = new_timeout;
181187
return 0;
182188
}
183189

@@ -371,7 +377,11 @@ static int imx2_wdt_suspend(struct device *dev)
371377

372378
/* The watchdog IP block is running */
373379
if (imx2_wdt_is_running(wdev)) {
374-
imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
380+
/*
381+
* Don't update wdog->timeout, we'll restore the current value
382+
* during resume.
383+
*/
384+
__imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
375385
imx2_wdt_ping(wdog);
376386
}
377387

0 commit comments

Comments
 (0)