From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Jaehoon Chung <jh80.chung@samsung.com>,
Lukasz Majewski <lukma@denx.de>,
Sean Anderson <seanga2@gmail.com>,
Anatolij Gustschin <agust@denx.de>,
Fabio Estevm <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
Mario Six <mario.six@gdsys.cc>
Cc: Svyatoslav Ryhel <clamor95@gmail.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
u-boot@lists.denx.de, Ian Ray <ian.ray@gehealthcare.com>,
Michael Nazzareno Trimarchi <michael@amarulasolutions.com>,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Adam Ford <aford173@gmail.com>, Marek Vasut <marex@denx.de>,
Miquel Raynal <miquel.raynal@bootlin.com>
Subject: [PATCH v5 03/12] dm: core: Add a helper to retrieve devices through graph endpoints
Date: Wed, 26 Mar 2025 16:00:47 +0100 [thread overview]
Message-ID: <20250326-ge-mainline-display-support-v5-3-ea4bc3fc9bca@bootlin.com> (raw)
In-Reply-To: <20250326-ge-mainline-display-support-v5-0-ea4bc3fc9bca@bootlin.com>
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>
---
drivers/core/uclass.c | 19 +++++++++++++++++++
include/dm/uclass.h | 24 ++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index f846a35d6b2537bab56bca158cedfb134b37f477..ce5e61bbaa63a181a1ea6781ad6a7f06be67c7e0 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
/*
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index c279304092352200d5297ad2d17f527173ec506b..8fdd72725119aae6ad2b62f4b0c38866a910389c 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -333,6 +333,30 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv,
struct udevice **devp);
+/**
+ * uclass_get_device_by_endpoint() - Get a uclass device for a remote endpoint
+ *
+ * This searches through the parents of the specified remote endpoint
+ * for the first device matching the uclass. Said otherwise, this helper
+ * goes through the graph (endpoint) representation and searches for
+ * matching devices. Endpoints can be subnodes of the "port" node or
+ * subnodes of ports identified with a reg property, themselves in a
+ * "ports" container.
+ *
+ * The device is probed to activate it ready for use.
+ *
+ * @class_id: uclass ID to look up
+ * @dev: Device to start from
+ * @port_idx: Index of the port to follow, -1 if there is a single 'port'
+ * node without reg.
+ * @ep_idx: Index of the endpoint to follow, -1 if there is a single 'endpoint'
+ * node without reg.
+ * @target: Returns pointer to the first device matching the expected uclass.
+ * Return: 0 if OK, -ve on error
+ */
+int uclass_get_device_by_endpoint(enum uclass_id class_id, struct udevice *dev,
+ int port_idx, int ep_idx, struct udevice **target);
+
/**
* uclass_first_device() - Get the first device in a uclass
*
--
2.48.1
next prev parent reply other threads:[~2025-03-27 4:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 15:00 [PATCH v5 00/12] Add imx8mp video support Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 01/12] core: ofnode: Fix a comment Miquel Raynal
2025-03-26 16:31 ` Svyatoslav Ryhel
2025-03-26 16:47 ` Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 02/12] dm: doc: Fix example Miquel Raynal
2025-03-26 15:00 ` Miquel Raynal [this message]
2025-03-26 16:47 ` [PATCH v5 03/12] dm: core: Add a helper to retrieve devices through graph endpoints Svyatoslav Ryhel
2025-04-03 7:45 ` Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 04/12] test: dm: test-fdt: Add checks for uclass_get_device_by_endpoint() Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 05/12] power-domain: Add refcounting Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 06/12] clk: Ensure the parent clocks are enabled while reparenting Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 07/12] clk: imx8mp: Add media related clocks Miquel Raynal
2025-03-26 15:39 ` Adam Ford
2025-03-26 15:48 ` Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 08/12] imx: power-domain: Describe the i.MX8 MEDIAMIX domain Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 09/12] imx: power-domain: Add support for the MEDIAMIX control block Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 10/12] video: imx: Fix Makefile in order to be able to add other imx drivers Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 11/12] video: imx: Add LDB driver Miquel Raynal
2025-03-26 15:00 ` [PATCH v5 12/12] video: imx: Add LCDIF driver Miquel Raynal
2025-03-26 15:22 ` [PATCH v5 00/12] Add imx8mp video support Miquel Raynal
2025-03-28 13:59 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250326-ge-mainline-display-support-v5-3-ea4bc3fc9bca@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=aford173@gmail.com \
--cc=agust@denx.de \
--cc=clamor95@gmail.com \
--cc=dario.binacchi@amarulasolutions.com \
--cc=festevam@gmail.com \
--cc=ian.ray@gehealthcare.com \
--cc=jh80.chung@samsung.com \
--cc=lukma@denx.de \
--cc=marex@denx.de \
--cc=mario.six@gdsys.cc \
--cc=michael@amarulasolutions.com \
--cc=peng.fan@nxp.com \
--cc=seanga2@gmail.com \
--cc=sjg@chromium.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox