diff mbox series

[RFC,2/5] dm: core: introduce uclass_id_on_reset()

Message ID 20240507100431.206670-3-robert.marko@sartura.hr
State RFC
Delegated to: Dario Binacchi
Headers show
Series Implement exiting 4-byte adressing mode before reset | expand

Commit Message

Robert Marko May 7, 2024, 10:03 a.m. UTC
Implement a helper to call .on_reset method for every device in a
certain uclass.

Intention is to use this helper for UCLASS_SPI_FLASH before board
reset to exit 4-byte adressing mode.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>
---
 drivers/core/uclass.c | 13 +++++++++++++
 include/dm/uclass.h   |  8 ++++++++
 2 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index e46d5717aa..bed5553d5e 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -831,6 +831,19 @@  int uclass_id_count(enum uclass_id id)
 	return count;
 }
 
+int uclass_id_on_reset(enum uclass_id id)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+
+	uclass_id_foreach_dev(id, dev, uc) {
+		if (dev->driver->on_reset)
+			return dev->driver->on_reset(dev);
+	}
+
+	return 0;
+}
+
 UCLASS_DRIVER(nop) = {
 	.id		= UCLASS_NOP,
 	.name		= "nop",
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 456eef7f2f..57eb1b144f 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -454,6 +454,14 @@  int uclass_probe_all(enum uclass_id id);
  */
 int uclass_id_count(enum uclass_id id);
 
+/**
+ * uclass_id_on_reset() - call on_reset for devices of a given uclass ID
+ *
+ * @id: uclass ID to look up
+ * Return: 0 if OK, other -ve on error
+ */
+int uclass_id_on_reset(enum uclass_id id);
+
 /**
  * uclass_id_foreach_dev() - iterate through devices of a given uclass ID
  *