Skip to content

Commit a7ceca4

Browse files
pfiserWim Van Sebroeck
authored andcommitted
watchdog: da9063: optionally disable watchdog during suspend
Optionally disable watchdog during suspend (if enabled) and re-enable it upon resume. This enables boards to sleep without being interrupted by the watchdog. This patch is based on commit f6c98b0 ("watchdog: da9062: add power management ops") and commit 8541673 ("watchdog: da9062: fix power management ops") and brings the same functionality to DA9063. Signed-off-by: Primoz Fiser <[email protected]> Reviewed-by: Adam Thomson <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent b191287 commit a7ceca4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/watchdog/da9063_wdt.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/delay.h>
1919
#include <linux/mfd/da9063/registers.h>
2020
#include <linux/mfd/da9063/core.h>
21+
#include <linux/property.h>
2122
#include <linux/regmap.h>
2223

2324
/*
@@ -26,6 +27,8 @@
2627
* others: timeout = 2048 ms * 2^(TWDSCALE-1).
2728
*/
2829
static const unsigned int wdt_timeout[] = { 0, 2, 4, 8, 16, 32, 65, 131 };
30+
static bool use_sw_pm;
31+
2932
#define DA9063_TWDSCALE_DISABLE 0
3033
#define DA9063_TWDSCALE_MIN 1
3134
#define DA9063_TWDSCALE_MAX (ARRAY_SIZE(wdt_timeout) - 1)
@@ -218,6 +221,8 @@ static int da9063_wdt_probe(struct platform_device *pdev)
218221
if (!wdd)
219222
return -ENOMEM;
220223

224+
use_sw_pm = device_property_present(dev, "dlg,use-sw-pm");
225+
221226
wdd->info = &da9063_watchdog_info;
222227
wdd->ops = &da9063_watchdog_ops;
223228
wdd->min_timeout = DA9063_WDT_MIN_TIMEOUT;
@@ -228,6 +233,7 @@ static int da9063_wdt_probe(struct platform_device *pdev)
228233

229234
watchdog_set_restart_priority(wdd, 128);
230235
watchdog_set_drvdata(wdd, da9063);
236+
dev_set_drvdata(dev, wdd);
231237

232238
wdd->timeout = DA9063_WDG_TIMEOUT;
233239

@@ -249,10 +255,40 @@ static int da9063_wdt_probe(struct platform_device *pdev)
249255
return devm_watchdog_register_device(dev, wdd);
250256
}
251257

258+
static int __maybe_unused da9063_wdt_suspend(struct device *dev)
259+
{
260+
struct watchdog_device *wdd = dev_get_drvdata(dev);
261+
262+
if (!use_sw_pm)
263+
return 0;
264+
265+
if (watchdog_active(wdd))
266+
return da9063_wdt_stop(wdd);
267+
268+
return 0;
269+
}
270+
271+
static int __maybe_unused da9063_wdt_resume(struct device *dev)
272+
{
273+
struct watchdog_device *wdd = dev_get_drvdata(dev);
274+
275+
if (!use_sw_pm)
276+
return 0;
277+
278+
if (watchdog_active(wdd))
279+
return da9063_wdt_start(wdd);
280+
281+
return 0;
282+
}
283+
284+
static SIMPLE_DEV_PM_OPS(da9063_wdt_pm_ops,
285+
da9063_wdt_suspend, da9063_wdt_resume);
286+
252287
static struct platform_driver da9063_wdt_driver = {
253288
.probe = da9063_wdt_probe,
254289
.driver = {
255290
.name = DA9063_DRVNAME_WATCHDOG,
291+
.pm = &da9063_wdt_pm_ops,
256292
},
257293
};
258294
module_platform_driver(da9063_wdt_driver);

0 commit comments

Comments
 (0)