mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/7] watchdog: Allow multiple watchdogs
Date: Wed, 26 Aug 2015 13:17:11 +0200	[thread overview]
Message-ID: <1440587836-22105-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1440587836-22105-1-git-send-email-s.hauer@pengutronix.de>

Put watchdogs on a list to allow multiple watchdogs. Add a priority
field to be able to pick the highest priority watchdog.
This patch also provides a of_get_watchdog_priority() function to
allow configuring the watchdog priority from the device tree.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/watchdog/wd_core.c | 57 ++++++++++++++++++++++++++++++++++++----------
 include/watchdog.h         |  6 +++++
 2 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 3d0cfc6..b8473b7 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -11,6 +11,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
+#define pr_fmt(fmt) "watchdog: " fmt
 
 #include <common.h>
 #include <command.h>
@@ -18,40 +19,72 @@
 #include <linux/ctype.h>
 #include <watchdog.h>
 
-/*
- * Note: this simple framework supports one watchdog only.
- */
-static struct watchdog *watchdog;
+static LIST_HEAD(watchdog_list);
 
 int watchdog_register(struct watchdog *wd)
 {
-	if (watchdog != NULL)
-		return -EBUSY;
+	if (!wd->priority)
+		wd->priority = WATCHDOG_DEFAULT_PRIORITY;
+
+	list_add_tail(&wd->list, &watchdog_list);
+
+	pr_debug("registering watchdog with priority %d\n", wd->priority);
 
-	watchdog = wd;
 	return 0;
 }
 EXPORT_SYMBOL(watchdog_register);
 
 int watchdog_deregister(struct watchdog *wd)
 {
-	if (watchdog == NULL || wd != watchdog)
-		return -ENODEV;
+	list_del(&wd->list);
 
-	watchdog = NULL;
 	return 0;
 }
 EXPORT_SYMBOL(watchdog_deregister);
 
+static struct watchdog *watchdog_get_default(void)
+{
+	struct watchdog *tmp, *wd = NULL;
+	int priority = 0;
+
+	list_for_each_entry(tmp, &watchdog_list, list) {
+		if (tmp->priority > priority) {
+			priority = tmp->priority;
+			wd = tmp;
+		}
+	}
+
+	return wd;
+}
+
 /*
  * start, stop or retrigger the watchdog
  * timeout in [seconds]. timeout of '0' will disable the watchdog (if possible)
  */
 int watchdog_set_timeout(unsigned timeout)
 {
-	if (watchdog == NULL)
+	struct watchdog *wd;
+
+	wd = watchdog_get_default();
+
+	if (!wd)
 		return -ENODEV;
 
-	return watchdog->set_timeout(watchdog, timeout);
+	return wd->set_timeout(wd, timeout);
 }
 EXPORT_SYMBOL(watchdog_set_timeout);
+
+/**
+ * of_get_watchdog_priority() - get the desired watchdog priority from device tree
+ * @node:	The device_node to read the property from
+ *
+ * return: The priority
+ */
+unsigned int of_get_watchdog_priority(struct device_node *node)
+{
+	unsigned int priority = WATCHDOG_DEFAULT_PRIORITY;
+
+	of_property_read_u32(node, "watchdog-priority", &priority);
+
+	return priority;
+}
diff --git a/include/watchdog.h b/include/watchdog.h
index 7e37b7c..a833aea 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -15,6 +15,8 @@
 
 struct watchdog {
 	int (*set_timeout)(struct watchdog *, unsigned);
+	unsigned int priority;
+	struct list_head list;
 };
 
 #ifdef CONFIG_WATCHDOG
@@ -38,4 +40,8 @@ int watchdog_set_timeout(unsigned t)
 }
 #endif
 
+#define WATCHDOG_DEFAULT_PRIORITY 100
+
+unsigned int of_get_watchdog_priority(struct device_node *node);
+
 #endif /* INCLUDE_WATCHDOG_H */
-- 
2.5.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-08-26 11:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-26 11:17 Allow multiple restart/watchdog/reset-source handlers Sascha Hauer
2015-08-26 11:17 ` [PATCH 1/7] restart: replace reset_cpu with registered restart handlers Sascha Hauer
2015-08-26 11:17 ` Sascha Hauer [this message]
2015-08-26 11:17 ` [PATCH 3/7] watchdog: Give watchdogs a name Sascha Hauer
2015-08-26 11:17 ` [PATCH 4/7] reset-source: Use globalvar_add_simple_enum Sascha Hauer
2015-08-26 11:17 ` [PATCH 5/7] reset-source: Allow different priorities Sascha Hauer
2015-08-26 11:17 ` [PATCH 6/7] mfd: da9063: add da9063 watchdog and system restart driver Sascha Hauer
2015-08-26 11:17 ` [PATCH 7/7] mfd: da9053: add da9053 " 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=1440587836-22105-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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