mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] restart: allow selecting restart handler by device name
@ 2024-07-29 14:30 Ahmad Fatoum
  2024-07-29 14:30 ` [PATCH 2/2] watchdog: imxwd: populate device pointer when registering restart handler Ahmad Fatoum
  2024-07-30 10:19 ` [PATCH 1/2] restart: allow selecting restart handler by device name Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-29 14:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Many SoCs feature multiple instances of the same watchdog IP. For
example, the i.MX8MP has three watchdogs, which would be called wdog0,
wdog1, wdog2 in barebox, but they would all have imxwd as restart
handler name.

To be able to differentiate between them for restart purposes, add an
optional device member that's used as fallback when no exact restart
handler name was found.

To make this visible to the user, also change reset -l to list the
device name if it exists. Once we assign i.MX watchdog restart handlers
a device pointer, the reset -l output would look like this:

  watchdog-restart                              10
  imxwd-warm                                    90 W
  imxwd                wdog0                   100
  imxwd-warm                                    90 W
  imxwd                wdog1                   100
  imxwd-warm                                    90 W
  imxwd                wdog2                   100

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/restart.c  | 11 ++++++++---
 include/restart.h |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/common/restart.c b/common/restart.c
index 35cfb542519d..2bdee289831c 100644
--- a/common/restart.c
+++ b/common/restart.c
@@ -82,8 +82,12 @@ struct restart_handler *restart_handler_get_by_name(const char *name, int flags)
 	unsigned int priority = 0;
 
 	list_for_each_entry(tmp, &restart_handler_list, list) {
-		if (name && tmp->name && strcmp(name, tmp->name))
-			continue;
+		if (name) {
+			if ((tmp->name && strcmp(name, tmp->name)) &&
+			    (tmp->dev && strcmp(name, dev_name(tmp->dev))))
+				continue;
+		}
+
 		if (flags && (tmp->flags & flags) != flags)
 			continue;
 		if (tmp->priority > priority) {
@@ -120,7 +124,8 @@ void restart_handlers_print(void)
 	struct restart_handler *tmp;
 
 	list_for_each_entry(tmp, &restart_handler_list, list) {
-		printf("%-20s %6d ", tmp->name, tmp->priority);
+		printf("%-20s %-20s %6d ",
+		       tmp->name, tmp->dev ? dev_name(tmp->dev) : "", tmp->priority);
 		if (tmp->flags & RESTART_FLAG_WARM_BOOTROM)
 			putchar('W');
 		putchar('\n');
diff --git a/include/restart.h b/include/restart.h
index 15f30bb7ad4d..02db7915075e 100644
--- a/include/restart.h
+++ b/include/restart.h
@@ -21,6 +21,7 @@ struct restart_handler {
 	int flags;
 	struct device_node *of_node;
 	const char *name;
+	struct device *dev;
 	struct list_head list;
 };
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-30 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-29 14:30 [PATCH 1/2] restart: allow selecting restart handler by device name Ahmad Fatoum
2024-07-29 14:30 ` [PATCH 2/2] watchdog: imxwd: populate device pointer when registering restart handler Ahmad Fatoum
2024-07-30 10:19 ` [PATCH 1/2] restart: allow selecting restart handler by device name Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox