mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] watchdog: add option to provide fall-back restart handler
Date: Mon, 31 May 2021 09:13:19 +0200	[thread overview]
Message-ID: <20210531071319.32459-1-a.fatoum@pengutronix.de> (raw)

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@pengutronix.de>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


             reply	other threads:[~2021-05-31  7:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31  7:13 Ahmad Fatoum [this message]
2021-05-31  9:50 ` Sascha Hauer
2021-05-31 10:17   ` Ahmad Fatoum

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=20210531071319.32459-1-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