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

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

To make it possible to select a specific i.MX watchdog by device name,
when multiple were registered, populate the new optional
struct restart_handler::dev member.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/watchdog/imxwd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 616248af3863..2ec9d0d59635 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -306,6 +306,7 @@ static int imx_wd_probe(struct device *dev)
 	priv->restart.name = "imxwd";
 	priv->restart.restart = imxwd_force_soc_reset;
 	priv->restart.priority = RESTART_DEFAULT_PRIORITY;
+	priv->restart.dev = &priv->wd.dev;
 
 	restart_handler_register(&priv->restart);
 
-- 
2.39.2




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

* Re: [PATCH 1/2] restart: allow selecting restart handler by device name
  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 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-07-30 10:19 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 29 Jul 2024 16:30:06 +0200, Ahmad Fatoum wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/2] restart: allow selecting restart handler by device name
      https://git.pengutronix.de/cgit/barebox/commit/?id=06030d65998c (link may not be stable)
[2/2] watchdog: imxwd: populate device pointer when registering restart handler
      https://git.pengutronix.de/cgit/barebox/commit/?id=da2ebe937655 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ 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