Currently a watchdog has a timeout_cur device parameter which has a slightly confusing behaviour. The parameter has nothing to do with the currently configured watchdog timeout, instead it is merely used by the automatic watchdog feeder which configures the watchdog timeout with that value. Refine the semantics of the parameter by using it as the watchdog timeout as the name suggests. When read, it returns the currently configured timeout. When set, it configures the watchdog timeout and starts it (unless it's set to 0 in which case the watchdog will be disabled). Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- drivers/watchdog/wd_core.c | 23 +++++++++++------------ include/watchdog.h | 1 - 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c index d4de213fa5..663a6e5c75 100644 --- a/drivers/watchdog/wd_core.c +++ b/drivers/watchdog/wd_core.c @@ -71,17 +71,18 @@ static int watchdog_set_cur(struct param_d *param, void *priv) { struct watchdog *wd = priv; - if (wd->poller_timeout_cur > wd->timeout_max) - return -EINVAL; - - return 0; + return watchdog_set_timeout(wd, wd->timeout_cur); } static void watchdog_poller_cb(void *priv); static void watchdog_poller_start(struct watchdog *wd) { - watchdog_set_timeout(wd, wd->poller_timeout_cur); + unsigned int timeout_s; + + timeout_s = wd->timeout_cur ?: wd->timeout_max; + + watchdog_set_timeout(wd, timeout_s); poller_call_async(&wd->poller, 500 * MSECOND, watchdog_poller_cb, wd); @@ -201,16 +202,14 @@ int watchdog_register(struct watchdog *wd) dev_add_param_uint32_ro(&wd->dev, "timeout_max", &wd->timeout_max, "%u"); - if (IS_ENABLED(CONFIG_WATCHDOG_POLLER)) { - if (!wd->poller_timeout_cur || - wd->poller_timeout_cur > wd->timeout_max) - wd->poller_timeout_cur = wd->timeout_max; + if (wd->timeout_cur > wd->timeout_max) + wd->timeout_cur = wd->timeout_max; - dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur, - NULL, &wd->poller_timeout_cur, "%u", wd); + dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur, + NULL, &wd->timeout_cur, "%u", wd); + if (IS_ENABLED(CONFIG_WATCHDOG_POLLER)) watchdog_register_poller(wd); - } dev_add_param_uint32(&wd->dev, "seconds_to_expire", param_set_readonly, seconds_to_expire_get, &wd->seconds_to_expire, "%d", wd); diff --git a/include/watchdog.h b/include/watchdog.h index eaea07910c..8084f27596 100644 --- a/include/watchdog.h +++ b/include/watchdog.h @@ -23,7 +23,6 @@ struct watchdog { unsigned int priority; unsigned int timeout_max; unsigned int timeout_cur; - unsigned int poller_timeout_cur; unsigned int poller_enable; uint64_t last_ping; int seconds_to_expire; -- 2.39.5