aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2023-04-13 17:17:03 +0200
committerSimon Glass <sjg@chromium.org>2023-04-28 11:48:59 -0600
commitca031c082700631264d1e058f2f705438c2be8c2 (patch)
treedae7ca73c20d0d4cc885d9bbc128224435f3a054
parent6ebb357a6a16fe4b61fae3866f80b967e8231f7e (diff)
downloadu-boot-ca031c082700631264d1e058f2f705438c2be8c2.zip
u-boot-ca031c082700631264d1e058f2f705438c2be8c2.tar.gz
u-boot-ca031c082700631264d1e058f2f705438c2be8c2.tar.bz2
dm: core: introduce uclass_get_device_by_of_path()
There's quite a few instances of board-specific code doing off = fdt_path_offset(gd->fdt_blob, ...); ... ret = uclass_get_device_by_of_offset(..., off, &dev); looking for an eeprom or a pmic via some alias. Such code can be simplified a little if we have a helper for directly getting a device via device tree path (including being given as an alias). Implement it in terms of ofnode rather than raw offsets so that this will work whether live tree is enabled or not. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
-rw-r--r--drivers/core/uclass.c6
-rw-r--r--include/dm/uclass.h17
2 files changed, 23 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 009de74..e46d571 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -545,6 +545,12 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
}
#if CONFIG_IS_ENABLED(OF_REAL)
+int uclass_get_device_by_of_path(enum uclass_id id, const char *path,
+ struct udevice **devp)
+{
+ return uclass_get_device_by_ofnode(id, ofnode_path(path), devp);
+}
+
int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id,
struct udevice **devp)
{
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index ee15c92..5c5fb9a 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -265,6 +265,23 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
struct udevice **devp);
/**
+ * uclass_get_device_by_of_path() - Get a uclass device by device tree path
+ *
+ * This searches the devices in the uclass for one attached to the
+ * device tree node corresponding to the given path (which may also be
+ * an alias).
+ *
+ * The device is probed to activate it ready for use.
+ *
+ * @id: ID to look up
+ * @node: Device tree path to search for (if no such path then -ENODEV is returned)
+ * @devp: Returns pointer to device (there is only one for each node)
+ * Return: 0 if OK, -ve on error
+ */
+int uclass_get_device_by_of_path(enum uclass_id id, const char *path,
+ struct udevice **devp);
+
+/**
* uclass_get_device_by_phandle_id() - Get a uclass device by phandle id
*
* This searches the devices in the uclass for one with the given phandle id.