diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2019-10-23 18:56:00 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-10-29 10:23:43 +0100 |
commit | 9ba3943ce613c179740957e85405b4c832323ddb (patch) | |
tree | 079d2e75e55bb80dfa6e85d35491a13ff028b100 /drivers/watchdog | |
parent | c2d167823588708c9f8f68c7db111ce146e19e3f (diff) | |
download | barebox-9ba3943ce613c179740957e85405b4c832323ddb.tar.gz barebox-9ba3943ce613c179740957e85405b4c832323ddb.tar.xz |
watchdog: export API to configure watchdogs by name
So far watchdog users could only configure the watchdog with the highest
priority. In preparation for having the wd command configure a watchdog
by name, extend watchdog_set_timeout with a struct watchdog *parameter
and export functions to query default watchdog and to find watchdog by
name.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r-- | drivers/watchdog/wd_core.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c index ae29a76064..80bde82f7c 100644 --- a/drivers/watchdog/wd_core.c +++ b/drivers/watchdog/wd_core.c @@ -31,8 +31,15 @@ static const char *watchdog_name(struct watchdog *wd) return "unknown"; } -static int _watchdog_set_timeout(struct watchdog *wd, unsigned timeout) +/* + * start, stop or retrigger the watchdog + * timeout in [seconds]. timeout of '0' will disable the watchdog (if possible) + */ +int watchdog_set_timeout(struct watchdog *wd, unsigned timeout) { + if (!wd) + return -ENODEV; + if (timeout > wd->timeout_max) return -EINVAL; @@ -40,13 +47,14 @@ static int _watchdog_set_timeout(struct watchdog *wd, unsigned timeout) return wd->set_timeout(wd, timeout); } +EXPORT_SYMBOL(watchdog_set_timeout); static int watchdog_set_priority(struct param_d *param, void *priv) { struct watchdog *wd = priv; if (wd->priority == 0) - return _watchdog_set_timeout(wd, 0); + return watchdog_set_timeout(wd, 0); return 0; } @@ -65,7 +73,7 @@ static void watchdog_poller_cb(void *priv); static void watchdog_poller_start(struct watchdog *wd) { - _watchdog_set_timeout(wd, wd->timeout_cur); + watchdog_set_timeout(wd, wd->timeout_cur); poller_call_async(&wd->poller, 500 * MSECOND, watchdog_poller_cb, wd); @@ -192,7 +200,7 @@ int watchdog_deregister(struct watchdog *wd) } EXPORT_SYMBOL(watchdog_deregister); -static struct watchdog *watchdog_get_default(void) +struct watchdog *watchdog_get_default(void) { struct watchdog *tmp, *wd = NULL; int priority = 0; @@ -206,23 +214,23 @@ static struct watchdog *watchdog_get_default(void) return wd; } +EXPORT_SYMBOL(watchdog_get_default); -/* - * start, stop or retrigger the watchdog - * timeout in [seconds]. timeout of '0' will disable the watchdog (if possible) - */ -int watchdog_set_timeout(unsigned timeout) +struct watchdog *watchdog_get_by_name(const char *name) { - struct watchdog *wd; + struct watchdog *tmp; + struct device_d *dev = get_device_by_name(name); + if (!dev) + return NULL; - wd = watchdog_get_default(); - - if (!wd) - return -ENODEV; + list_for_each_entry(tmp, &watchdog_list, list) { + if (dev == tmp->hwdev || dev == &tmp->dev) + return tmp; + } - return _watchdog_set_timeout(wd, timeout); + return NULL; } -EXPORT_SYMBOL(watchdog_set_timeout); +EXPORT_SYMBOL(watchdog_get_by_name); /** * of_get_watchdog_priority() - get the desired watchdog priority from device tree |