diff options
author | Przemyslaw Marczak <p.marczak@samsung.com> | 2015-04-15 13:07:22 +0200 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-04-22 11:03:15 -0600 |
commit | e0735a4c60577fafdaed71c5ef046f04b0f53f09 (patch) | |
tree | 65faeeee6f0dc8db34e87921953116c5e05fa017 /drivers/core | |
parent | 9e85f13ddc47d253d90411a0645f9fbd8fa6e4b8 (diff) |
dm: core: uclass: add function: uclass_find_device_by_name()
This commit extends the driver model uclass's API by function:
- uclass_find_device_by_name()
And this function returns the device if:
- uclass with given ID, exists,
- device with exactly given name(dev->name), exists.
The returned device is not activated - need to be probed before use.
Note:
This function returns the first device, which name is equal
to the given one. This means, that using this function you must
assume, that the device name is unique in the given uclass's ID
device list.
uclass-internal.h: cleanup - move the uclass_find_device_by_seq()
declaration and description, near the other uclass_find*() functions.
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/uclass.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 21ab0d5245..61e96e9a42 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -186,6 +186,30 @@ int uclass_find_next_device(struct udevice **devp) return 0; } +int uclass_find_device_by_name(enum uclass_id id, const char *name, + struct udevice **devp) +{ + struct uclass *uc; + struct udevice *dev; + int ret; + + *devp = NULL; + if (!name) + return -EINVAL; + ret = uclass_get(id, &uc); + if (ret) + return ret; + + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (!strncmp(dev->name, name, strlen(name))) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { |