diff options
author | Simon Glass | 2014-07-23 06:55:14 -0600 |
---|---|---|
committer | Simon Glass | 2014-07-23 14:07:25 +0100 |
commit | f4cdead24a1a0c39c29c04e107c2f98ba61c5da8 (patch) | |
tree | cbabf26d3f1df2d80529543f5a4bcfeeef4a34f3 /drivers | |
parent | b7d665705ebb29f06616b7f365ab8732e9779bf6 (diff) |
dm: Allow a device to be found by its FDT offset
Each device that was bound from a device tree has an node that caused it to
be bound. Add functions that find and return a device based on a device tree
offset.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/core/uclass.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index c28cf6795f0..a27f3d50275 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -187,6 +187,30 @@ int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, return -ENODEV; } +static int uclass_find_device_by_of_offset(enum uclass_id id, int node, + struct udevice **devp) +{ + struct uclass *uc; + struct udevice *dev; + int ret; + + *devp = NULL; + if (node < 0) + return -ENODEV; + ret = uclass_get(id, &uc); + if (ret) + return ret; + + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (dev->of_offset == node) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + /** * uclass_get_device_tail() - handle the end of a get_device call * @@ -239,6 +263,17 @@ int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) return uclass_get_device_tail(dev, ret, devp); } +int uclass_get_device_by_of_offset(enum uclass_id id, int node, + struct udevice **devp) +{ + struct udevice *dev; + int ret; + + *devp = NULL; + ret = uclass_find_device_by_of_offset(id, node, &dev); + return uclass_get_device_tail(dev, ret, devp); +} + int uclass_first_device(enum uclass_id id, struct udevice **devp) { struct uclass *uc; |