Skip to content

Commit aefbaf3

Browse files
Xiubo LiWim Van Sebroeck
authored andcommitted
watchdog: imx2_wdt: Add power management support.
Add power management operations(suspend and resume) as part of dev_pm_ops for IMX2 watchdog driver. Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
1 parent 44e8967 commit aefbaf3

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎drivers/watchdog/imx2_wdt.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,52 @@ static void imx2_wdt_shutdown(struct platform_device *pdev)
326326
}
327327
}
328328

329+
#ifdef CONFIG_PM_SLEEP
330+
/* Disable watchdog if it is active during suspend */
331+
static int imx2_wdt_suspend(struct device *dev)
332+
{
333+
struct watchdog_device *wdog = dev_get_drvdata(dev);
334+
struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
335+
336+
imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
337+
imx2_wdt_ping(wdog);
338+
339+
/* Watchdog has been stopped but IP block is still running */
340+
if (!watchdog_active(&wdog) && imx2_wdt_is_running(wdev))
341+
del_timer_sync(&wdev->timer);
342+
343+
clk_disable_unprepare(wdev->clk);
344+
345+
return 0;
346+
}
347+
348+
/* Enable watchdog and configure it if necessary */
349+
static int imx2_wdt_resume(struct device *dev)
350+
{
351+
struct watchdog_device *wdog = dev_get_drvdata(dev);
352+
struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
353+
354+
clk_prepare_enable(wdev->clk);
355+
356+
if (watchdog_active(wdog) && !imx2_wdt_is_running(wdev)) {
357+
/* Resumes from deep sleep we need restart
358+
* the watchdog again.
359+
*/
360+
imx2_wdt_setup(wdog);
361+
imx2_wdt_set_timeout(wdog, wdog->timeout);
362+
imx2_wdt_ping(wdog);
363+
} else if (imx2_wdt_is_running(wdev)) {
364+
imx2_wdt_ping(wdog);
365+
mod_timer(&wdev->timer, jiffies + wdog->timeout * HZ / 2);
366+
}
367+
368+
return 0;
369+
}
370+
#endif
371+
372+
static SIMPLE_DEV_PM_OPS(imx2_wdt_pm_ops, imx2_wdt_suspend,
373+
imx2_wdt_resume);
374+
329375
static const struct of_device_id imx2_wdt_dt_ids[] = {
330376
{ .compatible = "fsl,imx21-wdt", },
331377
{ /* sentinel */ }
@@ -337,6 +383,7 @@ static struct platform_driver imx2_wdt_driver = {
337383
.shutdown = imx2_wdt_shutdown,
338384
.driver = {
339385
.name = DRIVER_NAME,
386+
.pm = &imx2_wdt_pm_ops,
340387
.of_match_table = imx2_wdt_dt_ids,
341388
},
342389
};

0 commit comments

Comments
 (0)