summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-09-05 12:35:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-09-13 12:07:55 +0200
commit3f26660186b41c55538c4abb62c77d8541adc738 (patch)
tree6186db9e061e48ef9f94d7e4095d5d060477cb86 /drivers
parent8f3057d381d48adc26701231a8c78d918a91a57c (diff)
downloadbarebox-3f26660186b41c55538c4abb62c77d8541adc738.tar.gz
barebox-3f26660186b41c55538c4abb62c77d8541adc738.tar.xz
driver: implement find_device() helper
For use in commands like done in the follow-up commits, it can be useful to have a best effort find_device, that not only finds by device name, but also by device tree path or alias. Add such a helper. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220905103546.1476277-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/driver.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 072870bea4..cbe1c974f4 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -46,6 +46,22 @@ LIST_HEAD(active_device_list);
EXPORT_SYMBOL(active_device_list);
static LIST_HEAD(deferred);
+struct device_d *find_device(const char *str)
+{
+ struct device_d *dev;
+ struct device_node *np;
+
+ dev = get_device_by_name(str);
+ if (dev)
+ return dev;
+
+ np = of_find_node_by_path_or_alias(NULL, str);
+ if (np)
+ return of_find_device_by_node(np);
+
+ return NULL;
+}
+
struct device_d *get_device_by_name(const char *name)
{
struct device_d *dev;