summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-06-23 15:38:37 -0600
committerSimon Glass <sjg@chromium.org>2015-07-21 17:39:22 -0600
commit2693047acdcdae20b066715d0da4937814347935 (patch)
tree26da337c474cd8485f03b4088512fc832c0dd73a /drivers/core
parent3039811e6584d55c6a330a7cf409f4dcea13ee31 (diff)
downloadu-boot-imx-2693047acdcdae20b066715d0da4937814347935.zip
u-boot-imx-2693047acdcdae20b066715d0da4937814347935.tar.gz
u-boot-imx-2693047acdcdae20b066715d0da4937814347935.tar.bz2
dm: core: Add a function to find any device from device tree
In some rare cases it is useful to be able to locate a device given a device tree node offset. An example is when you have an alias that points to a node and you want to find the associated device. The device may be SPI, MMC or something else, but you don't need to know the uclass to find it. Add a function to do a global search for a device, given its device tree offset. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/device.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 85fd1fc..43aff54 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)) {