]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/watchdog/twl4030_wdt.c
net: dsa: lan9303: fix broken backpressure in .port_fdb_dump
[mirror_ubuntu-hirsute-kernel.git] / drivers / watchdog / twl4030_wdt.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
80e45b1e
TK
2/*
3 * Copyright (C) Nokia Corporation
4 *
5 * Written by Timo Kokkonen <timo.t.kokkonen at nokia.com>
80e45b1e
TK
6 */
7
8#include <linux/module.h>
9#include <linux/types.h>
5a0e3ad6 10#include <linux/slab.h>
80e45b1e 11#include <linux/kernel.h>
80e45b1e
TK
12#include <linux/watchdog.h>
13#include <linux/platform_device.h>
a2054256 14#include <linux/mfd/twl.h>
80e45b1e
TK
15
16#define TWL4030_WATCHDOG_CFG_REG_OFFS 0x3
17
86a1e189
WVS
18static bool nowayout = WATCHDOG_NOWAYOUT;
19module_param(nowayout, bool, 0);
80e45b1e
TK
20MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
21 "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
22
23static int twl4030_wdt_write(unsigned char val)
24{
2bc3f62f 25 return twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, val,
80e45b1e
TK
26 TWL4030_WATCHDOG_CFG_REG_OFFS);
27}
28
b2c4e4b2 29static int twl4030_wdt_start(struct watchdog_device *wdt)
80e45b1e 30{
b2c4e4b2 31 return twl4030_wdt_write(wdt->timeout + 1);
80e45b1e
TK
32}
33
b2c4e4b2 34static int twl4030_wdt_stop(struct watchdog_device *wdt)
80e45b1e
TK
35{
36 return twl4030_wdt_write(0);
37}
38
b2c4e4b2
JN
39static int twl4030_wdt_set_timeout(struct watchdog_device *wdt,
40 unsigned int timeout)
80e45b1e 41{
b2c4e4b2 42 wdt->timeout = timeout;
80e45b1e
TK
43 return 0;
44}
45
b2c4e4b2 46static const struct watchdog_info twl4030_wdt_info = {
fb1cbeae 47 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
b2c4e4b2
JN
48 .identity = "TWL4030 Watchdog",
49};
80e45b1e 50
b2c4e4b2 51static const struct watchdog_ops twl4030_wdt_ops = {
80e45b1e 52 .owner = THIS_MODULE,
b2c4e4b2
JN
53 .start = twl4030_wdt_start,
54 .stop = twl4030_wdt_stop,
55 .set_timeout = twl4030_wdt_set_timeout,
80e45b1e
TK
56};
57
2d991a16 58static int twl4030_wdt_probe(struct platform_device *pdev)
80e45b1e 59{
b42488bc 60 struct device *dev = &pdev->dev;
b2c4e4b2 61 struct watchdog_device *wdt;
80e45b1e 62
b42488bc 63 wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
80e45b1e
TK
64 if (!wdt)
65 return -ENOMEM;
66
b2c4e4b2
JN
67 wdt->info = &twl4030_wdt_info;
68 wdt->ops = &twl4030_wdt_ops;
69 wdt->status = 0;
70 wdt->timeout = 30;
71 wdt->min_timeout = 1;
72 wdt->max_timeout = 30;
b42488bc 73 wdt->parent = dev;
80e45b1e 74
b2c4e4b2 75 watchdog_set_nowayout(wdt, nowayout);
80e45b1e
TK
76 platform_set_drvdata(pdev, wdt);
77
b2c4e4b2 78 twl4030_wdt_stop(wdt);
80e45b1e 79
b42488bc 80 return devm_watchdog_register_device(dev, wdt);
80e45b1e
TK
81}
82
83#ifdef CONFIG_PM
84static int twl4030_wdt_suspend(struct platform_device *pdev, pm_message_t state)
85{
b2c4e4b2
JN
86 struct watchdog_device *wdt = platform_get_drvdata(pdev);
87 if (watchdog_active(wdt))
88 return twl4030_wdt_stop(wdt);
80e45b1e
TK
89
90 return 0;
91}
92
93static int twl4030_wdt_resume(struct platform_device *pdev)
94{
b2c4e4b2
JN
95 struct watchdog_device *wdt = platform_get_drvdata(pdev);
96 if (watchdog_active(wdt))
97 return twl4030_wdt_start(wdt);
80e45b1e
TK
98
99 return 0;
100}
101#else
102#define twl4030_wdt_suspend NULL
103#define twl4030_wdt_resume NULL
104#endif
105
8899b8d9
AK
106static const struct of_device_id twl_wdt_of_match[] = {
107 { .compatible = "ti,twl4030-wdt", },
108 { },
109};
110MODULE_DEVICE_TABLE(of, twl_wdt_of_match);
111
80e45b1e
TK
112static struct platform_driver twl4030_wdt_driver = {
113 .probe = twl4030_wdt_probe,
80e45b1e
TK
114 .suspend = twl4030_wdt_suspend,
115 .resume = twl4030_wdt_resume,
116 .driver = {
8899b8d9
AK
117 .name = "twl4030_wdt",
118 .of_match_table = twl_wdt_of_match,
80e45b1e
TK
119 },
120};
121
b8ec6118 122module_platform_driver(twl4030_wdt_driver);
80e45b1e
TK
123
124MODULE_AUTHOR("Nokia Corporation");
125MODULE_LICENSE("GPL");
80e45b1e
TK
126MODULE_ALIAS("platform:twl4030_wdt");
127