summaryrefslogtreecommitdiff
path: root/drivers/core/uclass.c
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2025-04-03 09:39:03 +0200
committerFabio Estevam <festevam@gmail.com>2025-04-10 22:32:55 -0300
commit04fcddac28c9f28239f40c9b90e3e76ed5f5cb13 (patch)
treeb09be132bdcedb8705ea2946657ba02158bd8ad9 /drivers/core/uclass.c
parent9fe367bb60d377402617bb818796bff59e82e7c6 (diff)
dm: core: Add a helper to retrieve devices through graph endpoints
There are already several helpers to find a udevice based on its position in a device tree, like getting a child or a node pointed by a phandle, but there was no support for graph endpoints, which are very common in display pipelines. Add a new helper, named uclass_get_device_by_endpoint() which enters the child graph reprensentation, looks for a specific port, then follows the remote endpoint, and finally retrieves the first parent of the given uclass_id. This is a very handy and straightforward way to get a bridge or a panel handle. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Diffstat (limited to 'drivers/core/uclass.c')
-rw-r--r--drivers/core/uclass.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index f846a35d6b2..ce5e61bbaa6 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -16,6 +16,7 @@
#include <dm/device.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
+#include <dm/ofnode_graph.h>
#include <dm/uclass.h>
#include <dm/uclass-internal.h>
#include <dm/util.h>
@@ -582,6 +583,24 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
ret = uclass_find_device_by_phandle(id, parent, name, &dev);
return uclass_get_device_tail(dev, ret, devp);
}
+
+int uclass_get_device_by_endpoint(enum uclass_id class_id, struct udevice *dev,
+ int port_idx, int ep_idx, struct udevice **devp)
+{
+ ofnode node_source = dev_ofnode(dev);
+ ofnode node_dest = ofnode_graph_get_remote_node(node_source, port_idx, ep_idx);
+ struct udevice *target = NULL;
+ int ret;
+
+ if (!ofnode_valid(node_dest))
+ return -EINVAL;
+
+ ret = uclass_find_device_by_ofnode(class_id, node_dest, &target);
+ if (ret)
+ return -ENODEV;
+
+ return uclass_get_device_tail(target, 0, devp);
+}
#endif
/*