Re: [PATCH] uclass: add uclass_find_device_by_phandle_id() helper

2023-04-28 Thread Simon Glass
On Thu, 13 Apr 2023 at 09:16, Rasmus Villemoes
 wrote:
>
> The functions uclass_find_device_by_phandle() and
> uclass_get_device_by_phandle_id() both loop over a given uclass
> looking for a device with a given phandle. Factor that out to a common
> helper.
>
> For now, there are no (known potential) users of the new helper
> outside uclass.c, so make it static.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  drivers/core/uclass.c | 42 ++
>  1 file changed, 18 insertions(+), 24 deletions(-)
>

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH] uclass: add uclass_find_device_by_phandle_id() helper

2023-04-18 Thread Simon Glass
On Thu, 13 Apr 2023 at 09:16, Rasmus Villemoes
 wrote:
>
> The functions uclass_find_device_by_phandle() and
> uclass_get_device_by_phandle_id() both loop over a given uclass
> looking for a device with a given phandle. Factor that out to a common
> helper.
>
> For now, there are no (known potential) users of the new helper
> outside uclass.c, so make it static.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  drivers/core/uclass.c | 42 ++
>  1 file changed, 18 insertions(+), 24 deletions(-)
>

Reviewed-by: Simon Glass 


[PATCH] uclass: add uclass_find_device_by_phandle_id() helper

2023-04-13 Thread Rasmus Villemoes
The functions uclass_find_device_by_phandle() and
uclass_get_device_by_phandle_id() both loop over a given uclass
looking for a device with a given phandle. Factor that out to a common
helper.

For now, there are no (known potential) users of the new helper
outside uclass.c, so make it static.

Signed-off-by: Rasmus Villemoes 
---
 drivers/core/uclass.c | 42 ++
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 1762a0796d..3a919104a6 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -411,18 +411,14 @@ done:
 }
 
 #if CONFIG_IS_ENABLED(OF_REAL)
-int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
- const char *name, struct udevice **devp)
+static int
+uclass_find_device_by_phandle_id(enum uclass_id id, uint find_phandle,
+struct udevice **devp)
 {
struct udevice *dev;
struct uclass *uc;
-   int find_phandle;
int ret;
 
-   *devp = NULL;
-   find_phandle = dev_read_u32_default(parent, name, -1);
-   if (find_phandle <= 0)
-   return -ENOENT;
ret = uclass_get(id, );
if (ret)
return ret;
@@ -440,6 +436,19 @@ int uclass_find_device_by_phandle(enum uclass_id id, 
struct udevice *parent,
 
return -ENODEV;
 }
+
+int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
+ const char *name, struct udevice **devp)
+{
+   int find_phandle;
+
+   *devp = NULL;
+   find_phandle = dev_read_u32_default(parent, name, -1);
+   if (find_phandle <= 0)
+   return -ENOENT;
+
+   return uclass_find_device_by_phandle_id(id, find_phandle, devp);
+}
 #endif
 
 int uclass_get_device_by_driver(enum uclass_id id,
@@ -540,26 +549,11 @@ int uclass_get_device_by_phandle_id(enum uclass_id id, 
uint phandle_id,
struct udevice **devp)
 {
struct udevice *dev;
-   struct uclass *uc;
int ret;
 
*devp = NULL;
-   ret = uclass_get(id, );
-   if (ret)
-   return ret;
-
-   uclass_foreach_dev(dev, uc) {
-   uint phandle;
-
-   phandle = dev_read_phandle(dev);
-
-   if (phandle == phandle_id) {
-   *devp = dev;
-   return uclass_get_device_tail(dev, ret, devp);
-   }
-   }
-
-   return -ENODEV;
+   ret = uclass_find_device_by_phandle_id(id, phandle_id, );
+   return uclass_get_device_tail(dev, ret, devp);
 }
 
 int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
-- 
2.37.2