diff options
author | Simon Glass <sjg@chromium.org> | 2018-11-18 08:14:31 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-11-29 09:30:05 -0700 |
commit | 3abe1115355900172a8681f5e6fa01ca71a9b916 (patch) | |
tree | 9c2aeebe14de6b7c227845d8b2df0372bc81cd8f /drivers/core/device.c | |
parent | d0b4f68d199c075f5d734cf184f7eaf1a642083d (diff) |
dm: core: Add a few more specific child-finding functions
Add two functions which can find a child device by uclass or by name.
The first is useful with Multi-Function-Devices (MFDs) to find one of a
particular type. The second is useful when only the name is known.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core/device.c')
-rw-r--r-- | drivers/core/device.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c index 47a697f3e5..836bcadced 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -699,6 +699,40 @@ int device_find_first_inactive_child(struct udevice *parent, return -ENODEV; } +int device_find_first_child_by_uclass(struct udevice *parent, + enum uclass_id uclass_id, + struct udevice **devp) +{ + struct udevice *dev; + + *devp = NULL; + list_for_each_entry(dev, &parent->child_head, sibling_node) { + if (device_get_uclass_id(dev) == uclass_id) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + +int device_find_child_by_name(struct udevice *parent, const char *name, + struct udevice **devp) +{ + struct udevice *dev; + + *devp = NULL; + + list_for_each_entry(dev, &parent->child_head, sibling_node) { + if (!strcmp(dev->name, name)) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + struct udevice *dev_get_parent(const struct udevice *child) { return child->parent; |