From: Isaac Scott <isaac.scott@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: rmfrfs@gmail.com, laurent.pinchart@ideasonboard.com,
martink@posteo.de, kernel@puri.sm, mchehab@kernel.org,
shawnguo@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Isaac Scott <isaac.scott@ideasonboard.com>
Subject: [PATCH] imx-mipi-csis: Get the number of active lanes from mbus_config
Date: Thu, 14 Aug 2025 12:37:01 +0100 [thread overview]
Message-ID: <20250814113701.165644-1-isaac.scott@ideasonboard.com> (raw)
Although 4 lanes may be physically available, we may not be using all of
them. Get the number of configured lanes in the case a driver has
implemented the get_mbus_config op.
Signed-off-by: Isaac Scott <isaac.scott@ideasonboard.com>
---
Currently, the imx-mipi-csis driver parses the device tree to determine
the number of configured lanes for the CSI receiver. This may be
incorrect in the case that the connected device only uses a subset of
lanes, for example. Allow the drivers for these cameras to create a
mbus_config to configure the number of lanes that are actually being
used.
If the driver does not support the get_mbus_config op, this patch will
have no functional change.
Compile tested against media-master (v6.17-rc1)
---
drivers/media/platform/nxp/imx-mipi-csis.c | 41 ++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/media/platform/nxp/imx-mipi-csis.c b/drivers/media/platform/nxp/imx-mipi-csis.c
index 2beb5f43c2c0..efe4e2ad0382 100644
--- a/drivers/media/platform/nxp/imx-mipi-csis.c
+++ b/drivers/media/platform/nxp/imx-mipi-csis.c
@@ -939,6 +939,43 @@ static struct mipi_csis_device *sd_to_mipi_csis_device(struct v4l2_subdev *sdev)
return container_of(sdev, struct mipi_csis_device, sd);
}
+static int mipi_csis_get_active_lanes(struct v4l2_subdev *sd)
+{
+ struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd);
+ struct v4l2_mbus_config mbus_config = { 0 };
+ int ret;
+
+ ret = v4l2_subdev_call(csis->source.sd, pad, get_mbus_config,
+ 0, &mbus_config);
+ if (ret == -ENOIOCTLCMD) {
+ dev_dbg(csis->dev, "No remote mbus configuration available\n");
+ return 0;
+ }
+
+ if (ret) {
+ dev_err(csis->dev, "Failed to get remote mbus configuration\n");
+ return ret;
+ }
+
+ if (mbus_config.type != V4L2_MBUS_CSI2_DPHY) {
+ dev_err(csis->dev, "Unsupported media bus type %u\n",
+ mbus_config.type);
+ return -EINVAL;
+ }
+
+ if (mbus_config.bus.mipi_csi2.num_data_lanes > csis->bus.num_data_lanes) {
+ dev_err(csis->dev,
+ "Unsupported mbus config: too many data lanes %u\n",
+ mbus_config.bus.mipi_csi2.num_data_lanes);
+ return -EINVAL;
+ }
+
+ csis->bus.num_data_lanes = mbus_config.bus.mipi_csi2.num_data_lanes;
+ dev_dbg(csis->dev, "Number of lanes: %d\n", csis->bus.num_data_lanes);
+
+ return 0;
+}
+
static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable)
{
struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd);
@@ -965,6 +1002,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable)
format = v4l2_subdev_state_get_format(state, CSIS_PAD_SINK);
csis_fmt = find_csis_format(format->code);
+ ret = mipi_csis_get_active_lanes(sd);
+ if (ret < 0)
+ dev_dbg(csis->dev, "Failed to get active lanes: %d", ret);
+
ret = mipi_csis_calculate_params(csis, csis_fmt);
if (ret < 0)
goto err_unlock;
--
2.43.0
next reply other threads:[~2025-08-14 13:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 11:37 Isaac Scott [this message]
2025-08-15 9:18 ` [PATCH] imx-mipi-csis: Get the number of active lanes from mbus_config Sakari Ailus
2025-08-15 10:32 ` Laurent Pinchart
2025-08-15 11:25 ` Sakari Ailus
2025-08-15 11:36 ` Laurent Pinchart
2025-08-15 12:33 ` Sakari Ailus
2025-08-19 2:44 ` Laurent Pinchart
2025-09-02 12:28 ` Isaac Scott
2025-09-02 12:38 ` Laurent Pinchart
2025-09-02 12:48 ` Sakari Ailus
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=20250814113701.165644-1-isaac.scott@ideasonboard.com \
--to=isaac.scott@ideasonboard.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=kernel@puri.sm \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=martink@posteo.de \
--cc=mchehab@kernel.org \
--cc=rmfrfs@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.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