linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 RESEND 0/1] media: imx: csi: Parse link configuration from fw_node
@ 2025-07-14  8:19 Mathis Foerst
  2025-07-14  8:19 ` [PATCH v5 RESEND 1/1] " Mathis Foerst
  0 siblings, 1 reply; 2+ messages in thread
From: Mathis Foerst @ 2025-07-14  8:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mathis Foerst, Steve Longerbeam, Philipp Zabel,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, linux-media,
	linux-staging, imx, linux-arm-kernel, manuel.traut, mathis.foerst

Hi,

this patch fixes the imx-media-csi driver to work with camera drivers that
do not implement the subdev-pad-operation "get_mbus_format".

It's the follow up of this discussion:
https://lore.kernel.org/linux-media/Z8AoA6WjbXQufqR6@kekkonen.localdomain/

Changelog:
v3 -> v4:
- Determine the expected mbus_type based on the link topology. If the
  parallel port is used, try to parse the endpoint as V4L2_MBUS_PARALLEL
  and as V4L2_MBUS_BT656.

v2 -> v3:
- Factor out the function "csi_parse_upstream_fw_link_config" for better
  readability.

v1 -> v2:
- No changes (I submitted the wrong patch. I'm sorry for that)

Link to v1 discussion:
https://lore.kernel.org/linux-media/20250305113802.897087-1-mathis.foerst@mt.com/

I tested the changes successfully on an i.MX6DL with an MT9M114 and an
MT9V032 camera. They both use the parallel camera interface.
Sadly, I don't have the hardware to test with a MIPI CSI-2 camera.

Best regards,
Mathis Foerst


Mathis Foerst (1):
  media: imx: csi: Parse link configuration from fw_node

 drivers/staging/media/imx/imx-media-csi.c | 62 +++++++++++++++++++++--
 1 file changed, 58 insertions(+), 4 deletions(-)


base-commit: a8598c7de1bcd94461ca54c972efa9b4ea501fb9
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v5 RESEND 1/1] media: imx: csi: Parse link configuration from fw_node
  2025-07-14  8:19 [PATCH v5 RESEND 0/1] media: imx: csi: Parse link configuration from fw_node Mathis Foerst
@ 2025-07-14  8:19 ` Mathis Foerst
  0 siblings, 0 replies; 2+ messages in thread
From: Mathis Foerst @ 2025-07-14  8:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mathis Foerst, Steve Longerbeam, Philipp Zabel,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, linux-media,
	linux-staging, imx, linux-arm-kernel, manuel.traut, mathis.foerst

The imx-media-csi driver requires upstream camera drivers to implement
the subdev-pad-op "get_mbus_config" [0]. Camera drivers that don't
implement this function are not usable on the i.MX6.

The docs for get_mbus_config [1] say:
@get_mbus_config: get the media bus configuration of a remote sub-device.
            The media bus configuration is usually retrieved from the
            firmware interface at sub-device probe time, immediately
            applied to the hardware and eventually adjusted by the
            driver.

Currently, the imx-media-csi driver is not incorporating the information
from the firmware interface and therefore relies on the implementation of
get_mbus_config by the camera driver.

To be compatible with camera drivers not implementing get_mbus_config
(which is the usual case), use the bus information from the fw interface:

The camera does not necessarily has a direct media bus link to the CSI as
the video-mux and/or the MIPI CSI-2 receiver of the i.MX6 might be in
between them on the media pipeline.
The CSI driver already implements the functionality to find the connected
camera sub-device to call get_mbus_config on it.

At this point the driver is modified as follows:
In the case that get_mbus_config is not implemented by the upstream
camera, try to get its endpoint configuration from the firmware interface
usign v4l2_fwnode_endpoint_parse.
For the supported mbus_types (V4L2_MBUS_PARALLEL, V4L2_MBUS_BT656 and
V4L2_MBUS_CSI2_DPHY), extract the mbus_config from the endpoint
configuration.
For all other mbus_types, return an error.

Note that parsing the mbus_config from the fw interface is not done during
probing because the camera that's connected to the CSI can change based on
the selected input of the video-mux at runtime.

[0] drivers/staging/media/imx/imx-media-csi.c - line 211..216
[1] include/media/v4l2-subdev.h - line 814

Signed-off-by: Mathis Foerst <mathis.foerst@mt.com>
---
 drivers/staging/media/imx/imx-media-csi.c | 62 +++++++++++++++++++++--
 1 file changed, 58 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index a7cd3ef95fc3..5c2f197ae961 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -158,6 +158,50 @@ static inline bool requires_passthrough(struct v4l2_mbus_config *mbus_cfg,
 		 infmt->code != MEDIA_BUS_FMT_YUYV8_2X8);
 }
 
+static int csi_parse_upstream_fw_link_config(struct csi_priv *priv,
+					     struct v4l2_subdev *remote_sd,
+					     struct v4l2_mbus_config *mbus_cfg)
+{
+	struct fwnode_handle *ep_node;
+	struct v4l2_fwnode_endpoint ep = { .bus_type = mbus_cfg->type };
+	int ret;
+
+	ep_node = fwnode_graph_get_endpoint_by_id(dev_fwnode(remote_sd->dev),
+						  0, 0,
+						  FWNODE_GRAPH_ENDPOINT_NEXT);
+	if (!ep_node)
+		return -ENOTCONN;
+
+	ret = v4l2_fwnode_endpoint_parse(ep_node, &ep);
+	/*
+	 * Retry with V4L2_MBUS_BT656 if parsing fails with V4L2_MBUS_PARALLEL
+	 * as the parallel interface supports both MBUS types.
+	 */
+	if (ret == -ENXIO && mbus_cfg->type == V4L2_MBUS_PARALLEL) {
+		ep.bus_type = V4L2_MBUS_BT656;
+		ret = v4l2_fwnode_endpoint_parse(ep_node, &ep);
+	}
+	fwnode_handle_put(ep_node);
+	if (ret)
+		return ret;
+
+	switch (ep.bus_type) {
+	case V4L2_MBUS_PARALLEL:
+	case V4L2_MBUS_BT656:
+		mbus_cfg->bus.parallel = ep.bus.parallel;
+		break;
+	case V4L2_MBUS_CSI2_DPHY:
+		mbus_cfg->bus.mipi_csi2 = ep.bus.mipi_csi2;
+		break;
+	default:
+		v4l2_err(&priv->sd, "Unsupported mbus_type: %i\n",
+			 ep.bus_type);
+		return -EINVAL;
+	}
+	mbus_cfg->type = ep.bus_type;
+	return 0;
+}
+
 /*
  * Queries the media bus config of the upstream entity that provides data to
  * the CSI. This will either be the entity directly upstream from the CSI-2
@@ -175,6 +219,7 @@ static int csi_get_upstream_mbus_config(struct csi_priv *priv,
 		return -EPIPE;
 
 	sd = priv->src_sd;
+	mbus_cfg->type = V4L2_MBUS_CSI2_DPHY;
 
 	switch (sd->grp_id) {
 	case IMX_MEDIA_GRP_ID_CSI_MUX:
@@ -186,8 +231,14 @@ static int csi_get_upstream_mbus_config(struct csi_priv *priv,
 		sd = imx_media_pipeline_subdev(&sd->entity,
 					       IMX_MEDIA_GRP_ID_CSI2,
 					       true);
-		if (IS_ERR(sd))
+		if (IS_ERR(sd)) {
 			sd = priv->src_sd;
+			/*
+			 * If the CSI-2 receiver is not on the path, the
+			 * parallel port is in use.
+			 */
+			mbus_cfg->type = V4L2_MBUS_PARALLEL;
+		}
 		break;
 	case IMX_MEDIA_GRP_ID_CSI2:
 		break;
@@ -211,9 +262,12 @@ static int csi_get_upstream_mbus_config(struct csi_priv *priv,
 	ret = v4l2_subdev_call(remote_sd, pad, get_mbus_config,
 			       remote_pad->index, mbus_cfg);
 	if (ret == -ENOIOCTLCMD)
-		v4l2_err(&priv->sd,
-			 "entity %s does not implement get_mbus_config()\n",
-			 remote_pad->entity->name);
+		/*
+		 * If the upstream sd does not implement get_mbus_config,
+		 * try to parse the link configuration from its fw_node
+		 */
+		ret = csi_parse_upstream_fw_link_config(priv, remote_sd,
+							mbus_cfg);
 
 	return ret;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-14  8:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14  8:19 [PATCH v5 RESEND 0/1] media: imx: csi: Parse link configuration from fw_node Mathis Foerst
2025-07-14  8:19 ` [PATCH v5 RESEND 1/1] " Mathis Foerst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).