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

Robert Marko robert.marko at sartura.hr
Tue May 7 12:03:50 CEST 2024


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 at sartura.hr>
---
 drivers/core/uclass.c | 13 +++++++++++++
 include/dm/uclass.h   |  8 ++++++++
 2 files changed, 21 insertions(+)

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
  *
-- 
2.45.0



More information about the U-Boot mailing list