[U-Boot] [PATCH v2 07/18] core: device: Add dev_get_by_ofname function

Mario Six mario.six at gdsys.cc
Wed Jan 11 16:00:51 CET 2017


On boards that use DM, it is sometimes convenient and quicker to get a device
via its device tree path, since the devices used in the board initialization
routines are usually known beforehand.

This patch adds such a convenience function.

Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
Changes in v2:

New in v2
---
 drivers/core/device.c | 7 +++++++
 include/dm/device.h   | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index ed553d7..39d30b3 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -627,6 +627,13 @@ const char *dev_get_uclass_name(struct udevice *dev)
 	return dev->uclass->uc_drv->name;
 }

+void dev_get_by_ofname(char *ofname, struct udevice *dev)
+{
+	int offset = fdt_path_offset(gd->fdt_blob, ofname);
+
+	device_get_global_by_of_offset(offset, &dev);
+}
+
 fdt_addr_t dev_get_addr_index(struct udevice *dev, int index)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
diff --git a/include/dm/device.h b/include/dm/device.h
index 9948bd4..402482c 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -340,6 +340,14 @@ enum uclass_id device_get_uclass_id(struct udevice *dev);
 const char *dev_get_uclass_name(struct udevice *dev);

 /**
+ * dev_get_by_ofname() - find a device via its device tree path
+ *
+ * @ofname: Device tree path to use ("/path1/path2/...")
+ * @dev:    The found device or NULL
+ */
+void dev_get_by_ofname(char *ofname, struct udevice *dev);
+
+/**
  * device_get_child() - Get the child of a device by index
  *
  * Returns the numbered child, 0 being the first. This does not use
--
2.9.0



More information about the U-Boot mailing list