[PATCH] watchdog: add option to provide fall-back restart handler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some barebox ports may have a watchdog, but no restart handler, e.g.
reset happens via PMIC, which has no driver yet, but watchdog controls
reset line going to PMIC. Accommodate such setups by allowing
registration of watchdog as fall back restart handler.

As reset handling can't be disabled, this is made a default n option
to conserve binary size unless explicitly enabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 drivers/watchdog/Kconfig   |  7 +++++++
 drivers/watchdog/wd_core.c | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b785181c59db..542659825045 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -16,6 +16,13 @@ config WATCHDOG_POLLER
 	help
 	  Provides support for periodic watchdog feeder.
 
+config WATCHDOG_RESTART_FALLBACK
+	bool "Use Watchdog as fall-back restart handler"
+	help
+	  Say y here if you have a system without a restart handler, but which
+	  has a functional watchdog. Note that $global.system.reset will most
+	  probably not indicate RST when using this handler.
+
 config WATCHDOG_AR9344
 	bool "QCA AR9344"
 	depends on SOC_QCA_AR9344 || SOC_QCA_AR9331 || COMPILE_TEST
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 4b0ee31d5b35..55ab023d8368 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <linux/ctype.h>
 #include <watchdog.h>
+#include <restart.h>
 
 static LIST_HEAD(watchdog_list);
 
@@ -177,6 +178,24 @@ static int seconds_to_expire_get(struct param_d *p, void *priv)
 	return 0;
 }
 
+static void __noreturn watchdog_restart_handle(struct restart_handler *this)
+{
+	struct watchdog *wd = watchdog_get_default();
+	int ret = -ENODEV;
+
+	if (wd)
+		ret = watchdog_set_timeout(wd, 1);
+
+	BUG_ON(ret);
+	mdelay(2000);
+	__builtin_unreachable();
+}
+
+static struct restart_handler restart_handler = {
+	.restart = watchdog_restart_handle,
+	.name = "watchdog-restart",
+};
+
 int watchdog_register(struct watchdog *wd)
 {
 	struct param_d *p;
@@ -247,6 +266,13 @@ int watchdog_register(struct watchdog *wd)
 		goto error_unregister;
 	}
 
+	if (IS_ENABLED(CONFIG_WATCHDOG_RESTART_FALLBACK) && !restart_handler.priority) {
+		restart_handler.priority = 10; /* don't override others */
+		ret = restart_handler_register(&restart_handler);
+		if (ret)
+			dev_warn(&wd->dev, "failed to register restart handler\n");
+	}
+
 	list_add_tail(&wd->list, &watchdog_list);
 
 	pr_debug("registering watchdog %s with priority %d\n", watchdog_name(wd),
-- 
2.29.2


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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux