diff options
-rw-r--r-- | drivers/core/device.c | 25 | ||||
-rw-r--r-- | include/dm/device.h | 14 |
2 files changed, 39 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c index 85fd1fc735..43aff54059 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -470,6 +470,31 @@ int device_get_child_by_of_offset(struct udevice *parent, int seq, return device_get_device_tail(dev, ret, devp); } +static struct udevice *_device_find_global_by_of_offset(struct udevice *parent, + int of_offset) +{ + struct udevice *dev, *found; + + if (parent->of_offset == of_offset) + return parent; + + list_for_each_entry(dev, &parent->child_head, sibling_node) { + found = _device_find_global_by_of_offset(dev, of_offset); + if (found) + return found; + } + + return NULL; +} + +int device_get_global_by_of_offset(int of_offset, struct udevice **devp) +{ + struct udevice *dev; + + dev = _device_find_global_by_of_offset(gd->dm_root, of_offset); + return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); +} + int device_find_first_child(struct udevice *parent, struct udevice **devp) { if (list_empty(&parent->child_head)) { diff --git a/include/dm/device.h b/include/dm/device.h index 18296bb686..9a94ee19d9 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -390,6 +390,20 @@ int device_get_child_by_of_offset(struct udevice *parent, int seq, struct udevice **devp); /** + * device_get_global_by_of_offset() - Get a device based on FDT offset + * + * Locates a device by its device tree offset, searching globally throughout + * the all driver model devices. + * + * The device is probed to activate it ready for use. + * + * @of_offset: Device tree offset to find + * @devp: Returns pointer to device if found, otherwise this is set to NULL + * @return 0 if OK, -ve on error + */ +int device_get_global_by_of_offset(int of_offset, struct udevice **devp); + +/** * device_find_first_child() - Find the first child of a device * * @parent: Parent device to search |