summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-07-17 15:23:15 -0600
committerSimon Glass <sjg@chromium.org>2016-07-25 20:46:43 -0600
commitc57f806bf2e745c4273dc33c9827781cff46427c (patch)
treed0df31d54e5762a985d7c19768c2dfb37f693889 /drivers/core
parentc3f03ffbe31ae886f0eb670edf47fc208d667c19 (diff)
dm: core: Add a way to find a device by its driver
Some SoCs have a single clock device. Provide a way to find it given its driver name. This is handled by the linker so will fail if the name is not found, avoiding strange errors when names change and do not match. It is also faster than a string comparison. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/uclass.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 1141ce1ba3..de602ae52d 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -311,6 +311,26 @@ static int uclass_find_device_by_phandle(enum uclass_id id,
}
#endif
+int uclass_get_device_by_driver(enum uclass_id id,
+ const struct driver *find_drv,
+ struct udevice **devp)
+{
+ struct udevice *dev;
+ struct uclass *uc;
+ int ret;
+
+ ret = uclass_get(id, &uc);
+ if (ret)
+ return ret;
+
+ list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+ if (dev->driver == find_drv)
+ return uclass_get_device_tail(dev, 0, devp);
+ }
+
+ return -ENODEV;
+}
+
int uclass_get_device_tail(struct udevice *dev, int ret,
struct udevice **devp)
{