Skip to content

Commit

Permalink
watchdog: apple: Support suspend and resume
Browse files Browse the repository at this point in the history
With working s2idle the watchdog has to be disarmed on suspend and
re-armed on resume to prevent spuries resets after the timeout expires
in suspend.

Signed-off-by: Janne Grunau <j@jannau.net>
  • Loading branch information
jannau committed Apr 26, 2023
1 parent e75a8b8 commit 5ec32cd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions drivers/watchdog/apple_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ static int apple_wdt_probe(struct platform_device *pdev)
if (!wdt->clk_rate)
return -EINVAL;

platform_set_drvdata(pdev, wdt);

wdt->wdd.ops = &apple_wdt_ops;
wdt->wdd.info = &apple_wdt_info;
wdt->wdd.max_timeout = U32_MAX / wdt->clk_rate;
Expand All @@ -190,6 +192,28 @@ static int apple_wdt_probe(struct platform_device *pdev)
return devm_watchdog_register_device(dev, &wdt->wdd);
}

static int __maybe_unused apple_wdt_resume(struct device *dev)
{
struct apple_wdt *wdt = dev_get_drvdata(dev);

if (watchdog_active(&wdt->wdd) || watchdog_hw_running(&wdt->wdd))
apple_wdt_start(&wdt->wdd);

return 0;
}

static int __maybe_unused apple_wdt_suspend(struct device *dev)
{
struct apple_wdt *wdt = dev_get_drvdata(dev);

if (watchdog_active(&wdt->wdd) || watchdog_hw_running(&wdt->wdd))
apple_wdt_stop(&wdt->wdd);

return 0;
}

static SIMPLE_DEV_PM_OPS(apple_wdt_pm_ops, apple_wdt_suspend, apple_wdt_resume);

static const struct of_device_id apple_wdt_of_match[] = {
{ .compatible = "apple,wdt" },
{},
Expand All @@ -200,6 +224,7 @@ static struct platform_driver apple_wdt_driver = {
.driver = {
.name = "apple-watchdog",
.of_match_table = apple_wdt_of_match,
.pm = pm_sleep_ptr(&apple_wdt_pm_ops),
},
.probe = apple_wdt_probe,
};
Expand Down

0 comments on commit 5ec32cd

Please sign in to comment.