diff --git a/commands/wd.c b/commands/wd.c index 26823f8..f857291 100644 --- a/commands/wd.c +++ b/commands/wd.c @@ -34,7 +34,7 @@ } } - rc = watchdog_set_timeout(timeout); + rc = watchdog_set_timeout(watchdog_get_default(), timeout); if (rc < 0) { switch (rc) { case -EINVAL: diff --git a/common/boot.c b/common/boot.c index 14d4fe9..dcbe5cc 100644 --- a/common/boot.c +++ b/common/boot.c @@ -146,7 +146,8 @@ printf("Booting entry '%s'\n", be->title); if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) { - ret = watchdog_set_timeout(boot_watchdog_timeout); + ret = watchdog_set_timeout(watchdog_get_default(), + boot_watchdog_timeout); if (ret) pr_warn("Failed to enable watchdog: %s\n", strerror(-ret)); } diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c index ae29a76..80bde82 100644 --- a/drivers/watchdog/wd_core.c +++ b/drivers/watchdog/wd_core.c @@ -31,8 +31,15 @@ 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 @@ 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_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 @@ } 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 @@ 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(); + list_for_each_entry(tmp, &watchdog_list, list) { + if (dev == tmp->hwdev || dev == &tmp->dev) + return tmp; + } - if (!wd) - return -ENODEV; - - 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 diff --git a/include/watchdog.h b/include/watchdog.h index 0db4263..891a092 100644 --- a/include/watchdog.h +++ b/include/watchdog.h @@ -14,6 +14,7 @@ # define INCLUDE_WATCHDOG_H #include +#include struct watchdog { int (*set_timeout)(struct watchdog *, unsigned); @@ -31,7 +32,9 @@ #ifdef CONFIG_WATCHDOG int watchdog_register(struct watchdog *); int watchdog_deregister(struct watchdog *); -int watchdog_set_timeout(unsigned); +struct watchdog *watchdog_get_default(void); +struct watchdog *watchdog_get_by_name(const char *name); +int watchdog_set_timeout(struct watchdog*, unsigned); unsigned int of_get_watchdog_priority(struct device_node *node); #else static inline int watchdog_register(struct watchdog *w) @@ -44,11 +47,22 @@ return 0; } -static inline int watchdog_set_timeout(unsigned t) +static inline struct watchdog *watchdog_get_default(void) +{ + return NULL; +} + +static inline struct watchdog *watchdog_get_by_name(const char *name) +{ + return NULL; +} + +static inline int watchdog_set_timeout(struct watchdog*w, unsigned t) { return 0; } + static inline unsigned int of_get_watchdog_priority(struct device_node *node) { return 0;