[PATCH v3 1/1] media: imx: csi: Parse link configuration from fw_node
Mathis Foerst
mathis.foerst at mt.com
Fri Mar 14 08:01:08 PDT 2025
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 at mt.com>
---
drivers/staging/media/imx/imx-media-csi.c | 45 +++++++++++++++++++++--
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index 3edbc57be2ca..e642b4cc6182 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -158,6 +158,42 @@ 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 = V4L2_MBUS_UNKNOWN };
+ 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);
+ fwnode_handle_put(ep_node);
+ if (ret)
+ return ret;
+
+ mbus_cfg->type = ep.bus_type;
+ 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;
+ }
+ 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
@@ -211,9 +247,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
More information about the linux-arm-kernel
mailing list