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 2/8] restart: do restart-priority OF parsing in restart_handler_register
Date: Mon, 17 Oct 2022 09:09:54 +0200	[thread overview]
Message-ID: <20221017071000.1458292-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20221017071000.1458292-1-a.fatoum@pengutronix.de>

The restart-priority OF property is parsed for a number of MFDs, but
there is no reason really not to parse it for every restart handler that
has a device tree node like we already do for watchdogs.
Add a new struct restart_handler::of_node field and look into it if
populated. With this of_get_restart_priority, is no longer used, so drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 .../devicetree/bindings/power/restart.rst     | 10 ++++++++++
 common/restart.c                              | 20 +++++--------------
 drivers/mfd/da9053.c                          |  2 +-
 drivers/mfd/da9063.c                          |  2 +-
 drivers/mfd/rn5t568.c                         |  2 +-
 include/restart.h                             |  5 +++--
 6 files changed, 21 insertions(+), 20 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/restart.rst

diff --git a/Documentation/devicetree/bindings/power/restart.rst b/Documentation/devicetree/bindings/power/restart.rst
new file mode 100644
index 000000000000..8c866f6e0ded
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/restart.rst
@@ -0,0 +1,10 @@
+System Restart Controllers
+==========================
+
+In addition to upstream bindings, following properties are understood:
+
+Optional properties:
+
+- ``restart-priority`` : Overrides the priority set by the driver. Normally,
+  the device with the biggest reach should reset the system.
+  See :ref:`_system_reset` for more information.
diff --git a/common/restart.c b/common/restart.c
index b6f2bbf25b10..9e988838bc60 100644
--- a/common/restart.c
+++ b/common/restart.c
@@ -27,6 +27,11 @@ int restart_handler_register(struct restart_handler *rst)
 	if (!rst->priority)
 		rst->priority = RESTART_DEFAULT_PRIORITY;
 
+	if (rst->of_node) {
+		of_property_read_u32(rst->of_node, "restart-priority",
+				     &rst->priority);
+	}
+
 	list_add_tail(&rst->list, &restart_handler_list);
 
 	pr_debug("registering restart handler \"%s\" with priority %d\n",
@@ -102,21 +107,6 @@ void __noreturn restart_machine(void)
 	hang();
 }
 
-/**
- * of_get_restart_priority() - get the desired restart priority from device tree
- * @node:	The device_node to read the property from
- *
- * return: The priority
- */
-unsigned int of_get_restart_priority(struct device_node *node)
-{
-	unsigned int priority = RESTART_DEFAULT_PRIORITY;
-
-	of_property_read_u32(node, "restart-priority", &priority);
-
-	return priority;
-}
-
 /*
  * restart_handlers_print - print informations about all restart handlers
  */
diff --git a/drivers/mfd/da9053.c b/drivers/mfd/da9053.c
index 99827c968922..693c0ca606f7 100644
--- a/drivers/mfd/da9053.c
+++ b/drivers/mfd/da9053.c
@@ -272,7 +272,7 @@ static int da9053_probe(struct device_d *dev)
 
 	da9053_detect_reset_source(da9053);
 
-	da9053->restart.priority = of_get_restart_priority(dev->device_node);
+	da9053->restart.of_node = dev->device_node;
 	da9053->restart.name = "da9063";
 	da9053->restart.restart = &da9053_force_system_reset;
 
diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c
index a4e5226f3c98..4627dd1aa5a2 100644
--- a/drivers/mfd/da9063.c
+++ b/drivers/mfd/da9063.c
@@ -383,7 +383,7 @@ static int da9063_probe(struct device_d *dev)
 
 	da9063_detect_reset_source(priv);
 
-	priv->restart.priority = of_get_restart_priority(dev->device_node);
+	priv->restart.of_node = dev->device_node;
 	priv->restart.name = "da9063";
 	priv->restart.restart = &da9063_restart;
 
diff --git a/drivers/mfd/rn5t568.c b/drivers/mfd/rn5t568.c
index c1c792cbecf0..4bbab54fe48b 100644
--- a/drivers/mfd/rn5t568.c
+++ b/drivers/mfd/rn5t568.c
@@ -138,7 +138,7 @@ static int __init rn5t568_i2c_probe(struct device_d *dev)
 	regmap_write(pmic_instance->regmap, RN5T568_REPCNT, RN5T568_REPCNT_OFF_RESETO_16MS |
 		     RN5T568_REPCNT_OFF_REPWRTIM_1000MS | RN5T568_REPCNT_OFF_REPWRON);
 
-	pmic_instance->restart.priority = of_get_restart_priority(dev->device_node);
+	pmic_instance->restart.of_node = dev->device_node;
 	pmic_instance->restart.name = "RN5T568";
 	pmic_instance->restart.restart = &rn5t568_restart;
 	restart_handler_register(&pmic_instance->restart);
diff --git a/include/restart.h b/include/restart.h
index 27fab1b80dfb..330b50a53ab2 100644
--- a/include/restart.h
+++ b/include/restart.h
@@ -11,9 +11,12 @@ void restart_handlers_print(void);
 void __noreturn restart_machine(void);
 struct restart_handler *restart_handler_get_by_name(const char *name);
 
+struct device_node;
+
 struct restart_handler {
 	void (*restart)(struct restart_handler *);
 	int priority;
+	struct device_node *of_node;
 	const char *name;
 	struct list_head list;
 };
@@ -24,6 +27,4 @@ int restart_handler_register_fn(const char *name,
 
 #define RESTART_DEFAULT_PRIORITY 100
 
-unsigned int of_get_restart_priority(struct device_node *node);
-
 #endif /* __INCLUDE_RESTART_H */
-- 
2.30.2




  parent reply	other threads:[~2022-10-17  7:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17  7:09 [PATCH 0/8] ARM: i.MX7: add serial download reboot mode Ahmad Fatoum
2022-10-17  7:09 ` [PATCH 1/8] restart: make restart.h header self-contained Ahmad Fatoum
2022-10-17  7:09 ` Ahmad Fatoum [this message]
2022-10-17  7:09 ` [PATCH 3/8] restart: add reset -w for warm bootrom reset Ahmad Fatoum
2022-10-17  7:09 ` [PATCH 4/8] watchdog: imxwd: don't register broken imxwd-warm for i.MX7 Ahmad Fatoum
2022-10-17  7:09 ` [PATCH 5/8] watchdog: imxwd: set imxwd-warm as reboot mode default handler Ahmad Fatoum
2022-10-17  7:09 ` [PATCH 6/8] Documentations: devicetree: bindings: document watchdog-priority Ahmad Fatoum
2022-10-17  7:09 ` [PATCH 7/8] ARM: i.MX7: describe USB serial download boot mode Ahmad Fatoum
2022-10-17  7:10 ` [PATCH 8/8] ARM: stm32mp: mark iwdg2 with barebox,restart-warm-bootrom Ahmad Fatoum
2022-10-18  9:13 ` [PATCH 0/8] ARM: i.MX7: add serial download reboot mode 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=20221017071000.1458292-3-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