diff mbox series

[U-Boot,v3,3/7] uclass: Add dev_get_uclass_index() to get the uclass/index of a device

Message ID 1529670334-21974-4-git-send-email-jjhiblot@ti.com
State Superseded
Delegated to: Lukasz Majewski
Headers show
Series Fixes/Addition to use the USB Ethernet gadget with the DWC3 gadget controller | expand

Commit Message

Jean-Jacques Hiblot June 22, 2018, 12:25 p.m. UTC
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>

---

Changes in v3:
- update commit log
- fixed problem with the function name

Changes in v2: None

 drivers/core/uclass.c        | 21 +++++++++++++++++++++
 include/dm/uclass-internal.h | 11 +++++++++++
 2 files changed, 32 insertions(+)

Comments

Simon Glass June 30, 2018, 4:19 a.m. UTC | #1
Hi Jean-Jacques,

On 22 June 2018 at 05:25, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
>
> 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>
>
> ---
>
> Changes in v3:
> - update commit log
> - fixed problem with the function name
>
> Changes in v2: None
>
>  drivers/core/uclass.c        | 21 +++++++++++++++++++++
>  include/dm/uclass-internal.h | 11 +++++++++++
>  2 files changed, 32 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

But this does need a sandbox test in test/dm/ofnode.c.
Jean-Jacques Hiblot July 4, 2018, 1:10 p.m. UTC | #2
On 30/06/2018 06:19, Simon Glass wrote:
> Hi Jean-Jacques,
>
> On 22 June 2018 at 05:25, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
>> 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>
>>
>> ---
>>
>> Changes in v3:
>> - update commit log
>> - fixed problem with the function name
>>
>> Changes in v2: None
>>
>>   drivers/core/uclass.c        | 21 +++++++++++++++++++++
>>   include/dm/uclass-internal.h | 11 +++++++++++
>>   2 files changed, 32 insertions(+)
>>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> But this does need a sandbox test in test/dm/ofnode.c.
I will not be able to add one before a few weeks.

JJ
>
diff mbox series

Patch

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 0085d3f..3af973c 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;
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index 7ba064b..30d5a4f 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -24,6 +24,17 @@ 
 int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
 
 /**
+ * dev_get_uclass_index() - Get uclass and index of device
+ * @dev:	- in - Device that we want the uclass/index of
+ * @ucp:	- out - A pointer to the uclass the device belongs to
+ *
+ * The device is not prepared for use - this is an internal function.
+ *
+ * @return the index of the device in the uclass list or -ENODEV if not found.
+ */
+int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
+
+/**
  * uclass_find_device() - Return n-th child of uclass
  * @id:		Id number of the uclass
  * @index:	Position of the child in uclass's list