From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/6] watchdog: export API to configure watchdogs by name
Date: Wed, 23 Oct 2019 18:56:00 +0200 [thread overview]
Message-ID: <20191023165601.16441-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20191023165601.16441-1-a.fatoum@pengutronix.de>
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>
---
commands/wd.c | 2 +-
common/boot.c | 3 ++-
drivers/watchdog/wd_core.c | 40 +++++++++++++++++++++++---------------
include/watchdog.h | 18 +++++++++++++++--
4 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/commands/wd.c b/commands/wd.c
index 26823f869afb..f857291f0362 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 14d4fe9d6460..dcbe5cc2ec7d 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 ae29a76064aa..80bde82f7cdd 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 0db4263a31ce..1455cc923c2d 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;
+}
+
+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;
--
2.23.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-10-23 16:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-23 16:55 [PATCH 1/6] Documentation: efi: emphasize watchdog deactivation on ExitBootServices Ahmad Fatoum
2019-10-23 16:55 ` [PATCH 2/6] efi: efi-image: don't mask x86 interrupts on boot Ahmad Fatoum
2019-10-23 16:55 ` [PATCH 3/6] watchdog: efi: bump down priority below default Ahmad Fatoum
2019-10-23 16:55 ` [PATCH 4/6] watchdog: export priority as device parameter Ahmad Fatoum
2019-10-23 16:56 ` Ahmad Fatoum [this message]
2019-10-23 16:56 ` [PATCH 6/6] commands: wd: support configuring watchdog by name Ahmad Fatoum
2019-10-24 6:34 ` [PATCH 1/6] Documentation: efi: emphasize watchdog deactivation on ExitBootServices Oleksij Rempel
2019-10-24 7:59 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191023165601.16441-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox