Skip to content

Commit

Permalink
watchdog: imx2_wdt: Add power management support.
Browse files Browse the repository at this point in the history
Add power management operations(suspend and resume) as part of
dev_pm_ops for IMX2 watchdog driver.

Signed-off-by: Xiubo Li <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
Signed-off-by: Wim Van Sebroeck <[email protected]>
  • Loading branch information
Xiubo Li authored and Wim Van Sebroeck committed Dec 18, 2014
1 parent 44e8967 commit aefbaf3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions drivers/watchdog/imx2_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,52 @@ static void imx2_wdt_shutdown(struct platform_device *pdev)
}
}

#ifdef CONFIG_PM_SLEEP
/* Disable watchdog if it is active during suspend */
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);

imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
imx2_wdt_ping(wdog);

/* Watchdog has been stopped but IP block is still running */
if (!watchdog_active(&wdog) && imx2_wdt_is_running(wdev))
del_timer_sync(&wdev->timer);

clk_disable_unprepare(wdev->clk);

return 0;
}

/* Enable watchdog and configure it if necessary */
static int imx2_wdt_resume(struct device *dev)
{
struct watchdog_device *wdog = dev_get_drvdata(dev);
struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);

clk_prepare_enable(wdev->clk);

if (watchdog_active(wdog) && !imx2_wdt_is_running(wdev)) {
/* Resumes from deep sleep we need restart
* the watchdog again.
*/
imx2_wdt_setup(wdog);
imx2_wdt_set_timeout(wdog, wdog->timeout);
imx2_wdt_ping(wdog);
} else if (imx2_wdt_is_running(wdev)) {
imx2_wdt_ping(wdog);
mod_timer(&wdev->timer, jiffies + wdog->timeout * HZ / 2);
}

return 0;
}
#endif

static SIMPLE_DEV_PM_OPS(imx2_wdt_pm_ops, imx2_wdt_suspend,
imx2_wdt_resume);

static const struct of_device_id imx2_wdt_dt_ids[] = {
{ .compatible = "fsl,imx21-wdt", },
{ /* sentinel */ }
Expand All @@ -337,6 +383,7 @@ static struct platform_driver imx2_wdt_driver = {
.shutdown = imx2_wdt_shutdown,
.driver = {
.name = DRIVER_NAME,
.pm = &imx2_wdt_pm_ops,
.of_match_table = imx2_wdt_dt_ids,
},
};
Expand Down

0 comments on commit aefbaf3

Please sign in to comment.