From patchwork Tue Sep 24 11:49:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 11158551 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20648912 for ; Tue, 24 Sep 2019 11:50:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3F2D2168B for ; Tue, 24 Sep 2019 11:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440809AbfIXLuK (ORCPT ); Tue, 24 Sep 2019 07:50:10 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:36217 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438941AbfIXLuK (ORCPT ); Tue, 24 Sep 2019 07:50:10 -0400 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1iCjKa-0002f6-UT; Tue, 24 Sep 2019 13:50:08 +0200 From: Philipp Zabel To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mats Randgaard , Steve Longerbeam , kernel@pengutronix.de Subject: [PATCH v4 1/3] media: v4l2-subdev: add g_csi_active_lanes() op Date: Tue, 24 Sep 2019 13:49:53 +0200 Message-Id: <20190924114955.13132-2-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190924114955.13132-1-p.zabel@pengutronix.de> References: <20190924114955.13132-1-p.zabel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a subdevice video operation that allows to query the number of data lanes a MIPI CSI-2 TX is actively transmitting on. Suggested-by: Hans Verkuil Signed-off-by: Philipp Zabel --- New in v4. --- include/media/v4l2-subdev.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 71f1f2f0da53..bb71eedc38f6 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -411,6 +411,8 @@ struct v4l2_mbus_frame_desc { * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev * can adjust @size to a lower value and must not write more data to the * buffer starting at @data than the original value of @size. + * + * @g_csi_active_lanes: Get number of currently active MIPI CSI-2 data lanes. */ struct v4l2_subdev_video_ops { int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config); @@ -441,6 +443,7 @@ struct v4l2_subdev_video_ops { const struct v4l2_mbus_config *cfg); int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf, unsigned int *size); + int (*g_csi_active_lanes)(struct v4l2_subdev *sd, u32 *lanes); }; /** From patchwork Tue Sep 24 11:49:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 11158553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F7A01668 for ; Tue, 24 Sep 2019 11:50:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05A1621655 for ; Tue, 24 Sep 2019 11:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440825AbfIXLuL (ORCPT ); Tue, 24 Sep 2019 07:50:11 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:44495 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395140AbfIXLuL (ORCPT ); Tue, 24 Sep 2019 07:50:11 -0400 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1iCjKb-0002f6-Nu; Tue, 24 Sep 2019 13:50:09 +0200 From: Philipp Zabel To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mats Randgaard , Steve Longerbeam , kernel@pengutronix.de Subject: [PATCH v4 2/3] media: tc358743: fix connected/active CSI-2 lane reporting Date: Tue, 24 Sep 2019 13:49:54 +0200 Message-Id: <20190924114955.13132-3-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190924114955.13132-1-p.zabel@pengutronix.de> References: <20190924114955.13132-1-p.zabel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org g_mbus_config was supposed to indicate all supported lane numbers, not only the number of those currently in active use. Since the TC358743 can dynamically reduce the number of active lanes if the required bandwidth allows for it, report all lane numbers up to the connected number of lanes as supported in pdata mode. In device tree mode, do not report lane count and clock mode at all, as the receiver driver can determine these from the device tree. To allow communicating the number of currently active lanes, use the newly added g_csi_active_lanes() video op. Signed-off-by: Philipp Zabel --- Changes since v3: - Use g_csi_active_lanes instead of storing the number of active lanes in mbus_config flags. --- drivers/media/i2c/tc358743.c | 44 ++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index dbbab75f135e..c2db6419a4b4 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -1607,23 +1607,31 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd, { struct tc358743_state *state = to_state(sd); + if (state->csi_lanes_in_use > state->bus.num_data_lanes) + return -EINVAL; + cfg->type = V4L2_MBUS_CSI2_DPHY; + cfg->flags = 0; - /* Support for non-continuous CSI-2 clock is missing in the driver */ - cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + /* In DT mode, there is no need to report the number of data lanes */ + if (sd->dev->of_node) + return 0; - switch (state->csi_lanes_in_use) { - case 1: - cfg->flags |= V4L2_MBUS_CSI2_1_LANE; - break; - case 2: - cfg->flags |= V4L2_MBUS_CSI2_2_LANE; - break; + /* Support for non-continuous CSI-2 clock is missing in pdata mode */ + cfg->flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + + switch (state->bus.num_data_lanes) { + case 4: + cfg->flags |= V4L2_MBUS_CSI2_LANES; + /* fallthrough */ case 3: cfg->flags |= V4L2_MBUS_CSI2_3_LANE; - break; - case 4: - cfg->flags |= V4L2_MBUS_CSI2_4_LANE; + /* fallthrough */ + case 2: + cfg->flags |= V4L2_MBUS_CSI2_2_LANE; + /* fallthrough */ + case 1: + cfg->flags |= V4L2_MBUS_CSI2_1_LANE; break; default: return -EINVAL; @@ -1632,6 +1640,16 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd, return 0; } +static int tc358743_g_csi_active_lanes(struct v4l2_subdev *sd, + u32 *lanes) +{ + struct tc358743_state *state = to_state(sd); + + *lanes = state->csi_lanes_in_use; + + return 0; +} + static int tc358743_s_stream(struct v4l2_subdev *sd, int enable) { enable_stream(sd, enable); @@ -1838,6 +1856,7 @@ static const struct v4l2_subdev_video_ops tc358743_video_ops = { .query_dv_timings = tc358743_query_dv_timings, .g_mbus_config = tc358743_g_mbus_config, .s_stream = tc358743_s_stream, + .g_csi_active_lanes = tc358743_g_csi_active_lanes, }; static const struct v4l2_subdev_pad_ops tc358743_pad_ops = { @@ -2052,6 +2071,7 @@ static int tc358743_probe(struct i2c_client *client) if (pdata) { state->pdata = *pdata; state->bus.flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + state->bus.num_data_lanes = 4; } else { err = tc358743_probe_of(state); if (err == -ENODEV) From patchwork Tue Sep 24 11:49:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 11158555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A6BF1668 for ; Tue, 24 Sep 2019 11:50:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68FEC2168B for ; Tue, 24 Sep 2019 11:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440843AbfIXLuM (ORCPT ); Tue, 24 Sep 2019 07:50:12 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:59921 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438941AbfIXLuM (ORCPT ); Tue, 24 Sep 2019 07:50:12 -0400 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1iCjKc-0002f6-FS; Tue, 24 Sep 2019 13:50:10 +0200 From: Philipp Zabel To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mats Randgaard , Steve Longerbeam , kernel@pengutronix.de Subject: [PATCH v4 3/3] media: imx: ask source subdevice for number of active data lanes Date: Tue, 24 Sep 2019 13:49:55 +0200 Message-Id: <20190924114955.13132-4-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190924114955.13132-1-p.zabel@pengutronix.de> References: <20190924114955.13132-1-p.zabel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use the newly added g_csi_active_lanes() video op to determine the number of active data lanes used by the transmitter. If this subdev call is not supported or does not return the number of active lanes, default to using all connected data lanes as before. Signed-off-by: Philipp Zabel --- Changes since v3: - Use g_csi_active_lanes instead of g_mbus_config. --- drivers/staging/media/imx/imx6-mipi-csi2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c index bfa4b254c4e4..aa4bf2f89695 100644 --- a/drivers/staging/media/imx/imx6-mipi-csi2.c +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c @@ -131,10 +131,8 @@ static void csi2_enable(struct csi2_dev *csi2, bool enable) } } -static void csi2_set_lanes(struct csi2_dev *csi2) +static void csi2_set_lanes(struct csi2_dev *csi2, int lanes) { - int lanes = csi2->bus.num_data_lanes; - writel(lanes - 1, csi2->base + CSI2_N_LANES); } @@ -295,6 +293,7 @@ static void csi2ipu_gasket_init(struct csi2_dev *csi2) static int csi2_start(struct csi2_dev *csi2) { + u32 lanes = 0; int ret; ret = clk_prepare_enable(csi2->pix_clk); @@ -310,7 +309,8 @@ static int csi2_start(struct csi2_dev *csi2) goto err_disable_clk; /* Step 4 */ - csi2_set_lanes(csi2); + v4l2_subdev_call(csi2->src_sd, video, g_csi_active_lanes, &lanes); + csi2_set_lanes(csi2, lanes ?: csi2->bus.num_data_lanes); csi2_enable(csi2, true); /* Step 5 */