summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2019-10-23 18:56:00 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-10-29 10:23:43 +0100
commit9ba3943ce613c179740957e85405b4c832323ddb (patch)
tree079d2e75e55bb80dfa6e85d35491a13ff028b100
parentc2d167823588708c9f8f68c7db111ce146e19e3f (diff)
downloadbarebox-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>
-rw-r--r--commands/wd.c2
-rw-r--r--common/boot.c3
-rw-r--r--drivers/watchdog/wd_core.c40
-rw-r--r--include/watchdog.h18
4 files changed, 43 insertions, 20 deletions
diff --git a/commands/wd.c b/commands/wd.c
index 26823f869a..f857291f03 100644
--- a/commands/wd.c
+++ b/commands/wd.c
@@ -34,7 +34,7 @@ static int do_wd(int argc, char *argv[])
}
}
- 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 14d4fe9d64..dcbe5cc2ec 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -146,7 +146,8 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
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 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
diff --git a/include/watchdog.h b/include/watchdog.h
index 0db4263a31..891a0920e4 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -14,6 +14,7 @@
# define INCLUDE_WATCHDOG_H
#include <poller.h>
+#include <driver.h>
struct watchdog {
int (*set_timeout)(struct watchdog *, unsigned);
@@ -31,7 +32,9 @@ struct watchdog {
#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 @@ static inline int watchdog_deregister(struct watchdog *w)
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;