diff options
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/uclass.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 04fb45b..630b2e7 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -8,6 +8,7 @@ */ #include <common.h> +#include <dm.h> #include <errno.h> #include <malloc.h> #include <dm/device.h> @@ -287,6 +288,30 @@ int uclass_find_device_by_of_offset(enum uclass_id id, int node, return -ENODEV; } +int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, + struct udevice **devp) +{ + struct uclass *uc; + struct udevice *dev; + int ret; + + *devp = NULL; + if (!ofnode_valid(node)) + return -ENODEV; + ret = uclass_get(id, &uc); + if (ret) + return ret; + + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (ofnode_equal(dev_ofnode(dev), node)) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + #if CONFIG_IS_ENABLED(OF_CONTROL) static int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, @@ -407,6 +432,18 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node, return uclass_get_device_tail(dev, ret, devp); } +int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, + struct udevice **devp) +{ + struct udevice *dev; + int ret; + + *devp = NULL; + ret = uclass_find_device_by_ofnode(id, node, &dev); + + return uclass_get_device_tail(dev, ret, devp); +} + #if CONFIG_IS_ENABLED(OF_CONTROL) int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, const char *name, struct udevice **devp) |