watchdog: pm8916_wdt: Add system sleep callbacks
authorLoic Poulain <loic.poulain@linaro.org>
Tue, 11 Feb 2020 15:38:03 +0000 (16:38 +0100)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Wed, 18 Mar 2020 10:10:09 +0000 (11:10 +0100)
Add suspend and resume pm operations.
Tested on dragonboard-410c.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/1581435483-6796-1-git-send-email-loic.poulain@linaro.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/pm8916_wdt.c

index 1213179f863c27405dca286393734a9c3e694111..0937b8d3310425b5a7efb81a7c091e711120a22b 100644 (file)
@@ -192,6 +192,7 @@ static int pm8916_wdt_probe(struct platform_device *pdev)
        wdt->wdev.timeout = PM8916_WDT_DEFAULT_TIMEOUT;
        wdt->wdev.pretimeout = 0;
        watchdog_set_drvdata(&wdt->wdev, wdt);
+       platform_set_drvdata(pdev, wdt);
 
        watchdog_init_timeout(&wdt->wdev, 0, dev);
        pm8916_wdt_configure_timers(&wdt->wdev);
@@ -199,6 +200,29 @@ static int pm8916_wdt_probe(struct platform_device *pdev)
        return devm_watchdog_register_device(dev, &wdt->wdev);
 }
 
+static int __maybe_unused pm8916_wdt_suspend(struct device *dev)
+{
+       struct pm8916_wdt *wdt = dev_get_drvdata(dev);
+
+       if (watchdog_active(&wdt->wdev))
+               return pm8916_wdt_stop(&wdt->wdev);
+
+       return 0;
+}
+
+static int __maybe_unused pm8916_wdt_resume(struct device *dev)
+{
+       struct pm8916_wdt *wdt = dev_get_drvdata(dev);
+
+       if (watchdog_active(&wdt->wdev))
+               return pm8916_wdt_start(&wdt->wdev);
+
+       return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(pm8916_wdt_pm_ops, pm8916_wdt_suspend,
+                        pm8916_wdt_resume);
+
 static const struct of_device_id pm8916_wdt_id_table[] = {
        { .compatible = "qcom,pm8916-wdt" },
        { }
@@ -210,6 +234,7 @@ static struct platform_driver pm8916_wdt_driver = {
        .driver = {
                .name = "pm8916-wdt",
                .of_match_table = of_match_ptr(pm8916_wdt_id_table),
+               .pm = &pm8916_wdt_pm_ops,
        },
 };
 module_platform_driver(pm8916_wdt_driver);