aboutsummaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorJean-Jacques Hiblot2018-08-09 16:17:42 +0200
committerMarek Vasut2018-08-21 16:21:37 +0200
commite7c865620e569df493e67d3772673108fce62064 (patch)
tree11a06f4f6941bc79c1caf7e20885772c73a6fa86 /drivers/core
parentc3211708cf721163733f03330bdb579d8c0f689b (diff)
uclass: Add dev_get_uclass_index() to get the uclass/index of a device
This function is the reciprocal of uclass_find_device(). It will be used to print the index information in dm tree dump. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/uclass.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index d609b170e1a..3113d6a56ba 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -171,6 +171,27 @@ enum uclass_id uclass_get_by_name(const char *name)
return UCLASS_INVALID;
}
+int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
+{
+ struct udevice *iter;
+ struct uclass *uc = dev->uclass;
+ int i = 0;
+
+ if (list_empty(&uc->dev_head))
+ return -ENODEV;
+
+ list_for_each_entry(iter, &uc->dev_head, uclass_node) {
+ if (iter == dev) {
+ if (ucp)
+ *ucp = uc;
+ return i;
+ }
+ i++;
+ }
+
+ return -ENODEV;
+}
+
int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
{
struct uclass *uc;