mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH v2 10/16] video: vpl: add vpl_bridge abstraction
Date: Fri,  6 Jun 2025 07:57:42 +0200	[thread overview]
Message-ID: <20250606055748.1990383-11-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250606055748.1990383-1-a.fatoum@barebox.org>

Linux drivers can make use of devm_drm_of_get_bridge to get a handle on
the next bridge. Add similar functionality to barebox as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/vpl.c | 60 ++++++++++++++++++++++++++++++++++++++++++---
 include/video/vpl.h | 15 ++++++++++++
 2 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/drivers/video/vpl.c b/drivers/video/vpl.c
index da8bd93b7d6a..0235c1e790bd 100644
--- a/drivers/video/vpl.c
+++ b/drivers/video/vpl.c
@@ -53,14 +53,15 @@ struct vpl *of_vpl_get(struct device_node *node, int port)
 	return of_find_vpl(node);
 }
 
-static int vpl_foreach_endpoint(struct vpl *vpl, unsigned int port,
+static int vpl_foreach_endpoint(struct vpl *vpl, unsigned int port, int endpoint_id,
 				int (*fn)(struct vpl *, unsigned port, void *data),
 				void *data)
 {
 	struct device_node *node, *endpoint;
 	int ret;
 
-	pr_debug("%s: %pOF port %d\n", __func__, vpl->node, port);
+	pr_debug("%s: %pOF port %d endpoint %d\n", __func__, vpl->node,
+		 port, endpoint_id);
 
 	node = of_graph_get_port_by_id(vpl->node, port);
 	if (!node) {
@@ -73,6 +74,16 @@ static int vpl_foreach_endpoint(struct vpl *vpl, unsigned int port,
 		struct vpl *remote_vpl;
 		u32 remote_port_id = 0;
 
+		if (endpoint_id >= 0) {
+			u32 local_endpoint_id = 0;
+			of_property_read_u32(endpoint, "reg", &local_endpoint_id);
+			if (local_endpoint_id != endpoint_id) {
+				pr_debug("%s: skipping endpoint %pOF with id %d\n",
+					 __func__, endpoint, local_endpoint_id);
+				continue;
+			}
+		}
+
 		remote = of_graph_get_remote_port(endpoint);
 		if (!remote) {
 			pr_debug("%s: no remote for endpoint %pOF\n", __func__, endpoint);
@@ -128,5 +139,48 @@ int vpl_ioctl(struct vpl *vpl, unsigned int port,
 {
 	struct vpl_ioctl data = { .cmd = cmd, .ptr = ptr };
 
-	return vpl_foreach_endpoint(vpl, port, vpl_remote_ioctl, &data) ?: data.err;
+	return vpl_foreach_endpoint(vpl, port, -1, vpl_remote_ioctl, &data) ?: data.err;
+}
+
+static int vpl_alloc_bridge(struct vpl *vpl, unsigned port, void *_bridge)
+{
+	struct vpl_bridge **bridge = _bridge;
+
+	(*bridge) = malloc(sizeof(**bridge));
+	(*bridge)->vpl = vpl;
+	(*bridge)->port = port;
+
+	return 1;
+}
+
+struct vpl_bridge *devm_vpl_of_get_bridge(struct device *dev, struct device_node *np,
+					  unsigned int port, unsigned int endpoint)
+{
+	struct vpl_bridge *bridge = NULL;
+	struct vpl *vpl;
+	int ret;
+
+	vpl = of_find_vpl(np);
+	if (!vpl)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	ret = vpl_foreach_endpoint(vpl, port, endpoint, vpl_alloc_bridge, &bridge);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	return bridge ?: ERR_PTR(-EINVAL);
+}
+
+int vpl_bridge_ioctl(struct vpl_bridge *bridge, unsigned int cmd, void *ptr)
+{
+	struct vpl *vpl;
+
+	if (IS_ERR_OR_NULL(bridge))
+		return PTR_ERR_OR_ZERO(bridge);
+
+	vpl = bridge->vpl;
+	if (!vpl->ioctl)
+		return -EOPNOTSUPP;
+
+	return vpl->ioctl(vpl, bridge->port, cmd, ptr);
 }
diff --git a/include/video/vpl.h b/include/video/vpl.h
index 5ea3d6dcf202..a8fda3e6294b 100644
--- a/include/video/vpl.h
+++ b/include/video/vpl.h
@@ -20,9 +20,24 @@ struct vpl {
 	struct list_head list;
 };
 
+/**
+ * struct vpl_bridge - bridge control structure
+ */
+struct vpl_bridge {
+	/** @vpl: pointer to vpl instance of bridge */
+	struct vpl *vpl;
+	/** @port: remote input port on bridge */
+	int port;
+};
+
 int vpl_register(struct vpl *);
 int vpl_ioctl(struct vpl *, unsigned int port,
 		unsigned int cmd, void *ptr);
+struct vpl_bridge;
+int vpl_bridge_ioctl(struct vpl_bridge *,
+		     unsigned int cmd, void *ptr);
+struct vpl_bridge *devm_vpl_of_get_bridge(struct device *dev, struct device_node *np,
+					  unsigned int port, unsigned int endpoint);
 
 struct vpl *of_vpl_get(struct device_node *node, int port);
 
-- 
2.39.5




  parent reply	other threads:[~2025-06-06  5:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06  5:57 [PATCH v2 00/16] ARM: stm32mp: add MIPI DSI support Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 01/16] driver: bus: embed bus driver node into bus Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 02/16] driver: switch busses to device class Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 03/16] driver: factor out bus definitions into separate header Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 04/16] driver: bus: add helpers for finding devices in busses Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 05/16] drive: bus: make use of new bus_find_device helper Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 06/16] of: implement of_alias_from_compatible Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 07/16] video: vpl: fix potential read of uninitialized variable Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 08/16] video: vpl: factor out vpl_for_each Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 09/16] video: vpl: handle missing struct vpl::ioctl gracefully Ahmad Fatoum
2025-06-06  5:57 ` Ahmad Fatoum [this message]
2025-06-06  5:57 ` [PATCH v2 11/16] video: factor out drm_mode_vrefresh Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 12/16] video: add base MIPI DSI support Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 13/16] video: add Designware MIPI-DSI support Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 14/16] video: add STM32 MIPI DSI video driver Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 15/16] video: add support for Orise Technology otm8009a panel Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 16/16] ARM: stm32mp: dk2: enable MIPI-DSI display by default Ahmad Fatoum

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=20250606055748.1990383-11-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /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