summaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/wd_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/watchdog/wd_core.c')
-rw-r--r--drivers/watchdog/wd_core.c73
1 files changed, 49 insertions, 24 deletions
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index e6e5dde..8b13950 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,12 +47,23 @@ 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 0;
+}
static int watchdog_set_cur(struct param_d *param, void *priv)
{
struct watchdog *wd = priv;
- if (wd->timeout_cur > wd->timeout_max)
+ if (wd->poller_timeout_cur > wd->timeout_max)
return -EINVAL;
return 0;
@@ -55,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->poller_timeout_cur);
poller_call_async(&wd->poller, 500 * MSECOND,
watchdog_poller_cb, wd);
@@ -130,24 +148,31 @@ int watchdog_register(struct watchdog *wd)
if (!wd->priority)
wd->priority = WATCHDOG_DEFAULT_PRIORITY;
+ p = dev_add_param_uint32(&wd->dev, "priority",
+ watchdog_set_priority, NULL,
+ &wd->priority, "%u", wd);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
/* set some default sane value */
if (!wd->timeout_max)
wd->timeout_max = 60 * 60 * 24;
- if (!wd->timeout_cur || wd->timeout_cur > wd->timeout_max)
- wd->timeout_cur = wd->timeout_max;
-
p = dev_add_param_uint32_ro(&wd->dev, "timeout_max",
&wd->timeout_max, "%u");
if (IS_ERR(p))
return PTR_ERR(p);
- p = dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur, NULL,
- &wd->timeout_cur, "%u", wd);
- if (IS_ERR(p))
- return PTR_ERR(p);
-
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;
+
+ p = dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur,
+ NULL, &wd->poller_timeout_cur, "%u", wd);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
ret = watchdog_register_poller(wd);
if (ret)
return ret;
@@ -176,7 +201,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;
@@ -190,23 +215,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