From patchwork Wed Apr 15 10:49:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11491075 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 E3EDE112C for ; Wed, 15 Apr 2020 10:47:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4B4620784 for ; Wed, 15 Apr 2020 10:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896626AbgDOKro (ORCPT ); Wed, 15 Apr 2020 06:47:44 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:52429 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896623AbgDOKre (ORCPT ); Wed, 15 Apr 2020 06:47:34 -0400 Received: from uno.homenet.telecomitalia.it (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 7BCAD240002; Wed, 15 Apr 2020 10:47:22 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 1/6] media: v4l2-subdv: Introduce get_mbus_config pad op Date: Wed, 15 Apr 2020 12:49:58 +0200 Message-Id: <20200415105004.2497356-2-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> References: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Introduce a new pad operation to allow retrieving the media bus configuration on a subdevice pad. The newly introduced operation reassembles the s/g_mbus_config video operation, which have been on their way to be deprecated since a long time. Signed-off-by: Jacopo Mondi --- include/media/v4l2-subdev.h | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a4848de59852..fc16af578471 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -350,6 +350,71 @@ struct v4l2_mbus_frame_desc { unsigned short num_entries; }; +/** + * struct v4l2_mbus_parallel_config - parallel mbus configuration + * @hsync_active: hsync active state: 1 for high, 0 for low + * @vsync_active: vsync active state: 1 for high, 0 for low + * @pclk_rising: pixel clock active edge: 1 for rising, 0 for falling + * @data_active: data lines active state: 1 for high, 0 for low + */ +struct v4l2_mbus_parallel_config { + unsigned int hsync_active : 1; + unsigned int vsync_active : 1; + unsigned int pclk_rising : 1; + unsigned int data_active : 1; +}; + +/** + * struct v4l2_mbus_csi2_dphy_config - MIPI CSI-2 DPHY mbus configuration + * @data_lanes: number of data lanes in use + * @clock_noncontinuous: non continuous clock enable flag: 1 for non + * continuous clock, 0 for continuous clock. + */ +struct v4l2_mbus_csi2_dphy_config { + unsigned int data_lanes : 3; + unsigned int clock_noncontinuous : 1; +}; + +/** + * struct v4l2_mbus_csi2_cphy_config - MIPI CSI-2 CPHY mbus configuration + * + * TODO + */ +struct v4l2_mbus_csi2_cphy_config { + /* TODO */ +}; + +/** + * struct v4l2_mbus_pad_config - media bus configuration + * + * Report the subdevice media bus information to inform the caller of the + * current bus configuration. The structure describes bus configuration + * parameters that might change in-between streaming sessions, in order to allow + * the caller to adjust its media bus configuration to match what is reported + * here. + * + * TODO: add '_pad_' to the name to distinguish this from the structure + * defined in v4l2_mediabus.h used for the same purpose by the g/s_mbus_config + * video operations. Reuse the there defined enum v4l2_mbus_type to define + * the bus type. + * + * @type: mbus type. See &enum v4l2_mbus_type + * @parallel: parallel bus configuration parameters. + * See &struct v4l2_mbus_parallel_config + * @csi2_dphy: MIPI CSI-2 DPHY configuration parameters + * See &struct v4l2_mbus_csi2_dphy_config + * @csi2_cphy: MIPI CSI-2 CPHY configuration parameters + * See &struct v4l2_mbus_csi2_cphy_config + */ +struct v4l2_mbus_pad_config { + enum v4l2_mbus_type type; + union { + struct v4l2_mbus_parallel_config parallel; + struct v4l2_mbus_csi2_dphy_config csi2_dphy; + struct v4l2_mbus_csi2_cphy_config csi2_cphy; + }; +}; + /** * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened * in video mode. @@ -670,6 +735,8 @@ struct v4l2_subdev_pad_config { * * @set_frame_desc: set the low level media bus frame parameters, @fd array * may be adjusted by the subdev driver to device capabilities. + * + * @get_mbus_config: get the current mbus configuration */ struct v4l2_subdev_pad_ops { int (*init_cfg)(struct v4l2_subdev *sd, @@ -710,6 +777,8 @@ struct v4l2_subdev_pad_ops { struct v4l2_mbus_frame_desc *fd); int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_frame_desc *fd); + int (*get_mbus_config)(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_pad_config *config); }; /** From patchwork Wed Apr 15 10:49:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11491085 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 E127F112C for ; Wed, 15 Apr 2020 10:48:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D335220784 for ; Wed, 15 Apr 2020 10:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896637AbgDOKsN (ORCPT ); Wed, 15 Apr 2020 06:48:13 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:57887 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896604AbgDOKrn (ORCPT ); Wed, 15 Apr 2020 06:47:43 -0400 Received: from uno.homenet.telecomitalia.it (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 9F29E240013; Wed, 15 Apr 2020 10:47:32 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 2/6] media: v4l2-subdev: Deprecate g_mbus_config video op Date: Wed, 15 Apr 2020 12:49:59 +0200 Message-Id: <20200415105004.2497356-3-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> References: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Deprecate 'g_mbus_config' video operation in favor of the newly introduced 'get_mbus_config' pad operation. Suggested-by: Sakari Ailus Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/media/v4l2-subdev.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index d1a5e9d1ea63..9bf14c41626d 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -466,7 +466,9 @@ struct v4l2_mbus_pad_config { * * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS() ioctl handler code. * - * @g_mbus_config: get supported mediabus configurations + * @g_mbus_config: get supported mediabus configurations. This operation is + * deprecated in favour of the get_mbus_config() pad operation + * and should not be used by new software. * * @s_mbus_config: set a certain mediabus configuration. This operation is added * for compatibility with soc-camera drivers and should not be used by new From patchwork Wed Apr 15 10:50:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11491081 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 C1023186E for ; Wed, 15 Apr 2020 10:48:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A93AB20857 for ; Wed, 15 Apr 2020 10:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896430AbgDOKsI (ORCPT ); Wed, 15 Apr 2020 06:48:08 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:47853 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896623AbgDOKrx (ORCPT ); Wed, 15 Apr 2020 06:47:53 -0400 Received: from uno.homenet.telecomitalia.it (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 74885240002; Wed, 15 Apr 2020 10:47:42 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 3/6] media: v4l2-subdev: Expand get_mbus_config doc Date: Wed, 15 Apr 2020 12:50:00 +0200 Message-Id: <20200415105004.2497356-4-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> References: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Expand documentation of the newly introduced get_mbus_config() pad operation. Signed-off-by: Jacopo Mondi --- Providing this as separate patch to ease review/discussion. Can be likely squashed in 1/6 --- include/media/v4l2-subdev.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 2.26.0 diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 9bf14c41626d..e95f44e778a6 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -737,7 +737,17 @@ struct v4l2_subdev_pad_config { * @set_frame_desc: set the low level media bus frame parameters, @fd array * may be adjusted by the subdev driver to device capabilities. * - * @get_mbus_config: get the current mbus configuration + * @get_mbus_config: get the current media bus configuration. This operation is + * intended to be used to synchronize the media bus + * configuration parameters between receivers and + * transmitters. The static bus configuration is usually + * received from the firmware interface, and updated + * dynamically using this operation to retrieve bus + * configuration parameters which could change at run-time. + * Callers should make sure they get the most up-to-date as + * possible configuration from the connected sub-device, + * likely calling this operation as close as possible to + * stream on time. */ struct v4l2_subdev_pad_ops { int (*init_cfg)(struct v4l2_subdev *sd, From patchwork Wed Apr 15 10:50:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11491087 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 9293C1392 for ; Wed, 15 Apr 2020 10:48:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F50D20784 for ; Wed, 15 Apr 2020 10:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896638AbgDOKsV (ORCPT ); Wed, 15 Apr 2020 06:48:21 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:37125 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896632AbgDOKsE (ORCPT ); Wed, 15 Apr 2020 06:48:04 -0400 Received: from uno.homenet.telecomitalia.it (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 1E1CC240005; Wed, 15 Apr 2020 10:47:51 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 4/6] media: i2c: adv748x: Adjust TXA data lanes number Date: Wed, 15 Apr 2020 12:50:01 +0200 Message-Id: <20200415105004.2497356-5-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> References: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When outputting SD-Core output through the TXA MIPI CSI-2 interface, the number of enabled data lanes should be reduced in order to guarantee the two video format produced by the SD-Core (480i and 576i) generate a MIPI CSI-2 link clock frequency compatible with the MIPI D-PHY specifications. Limit the number of enabled data lanes to 2, which is guaranteed to support 480i and 576i formats. Cache the number of enabled data lanes to be able to report it through the new get_mbus_config operation introduced in the following patches. Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/i2c/adv748x/adv748x-core.c | 31 ++++++++++++++++++------ drivers/media/i2c/adv748x/adv748x.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c index 23e02ff27b17..1fe7f97c6d52 100644 --- a/drivers/media/i2c/adv748x/adv748x-core.c +++ b/drivers/media/i2c/adv748x/adv748x-core.c @@ -241,10 +241,10 @@ static int adv748x_power_up_tx(struct adv748x_csi2 *tx) int ret = 0; /* Enable n-lane MIPI */ - adv748x_write_check(state, page, 0x00, 0x80 | tx->num_lanes, &ret); + adv748x_write_check(state, page, 0x00, 0x80 | tx->active_lanes, &ret); /* Set Auto DPHY Timing */ - adv748x_write_check(state, page, 0x00, 0xa0 | tx->num_lanes, &ret); + adv748x_write_check(state, page, 0x00, 0xa0 | tx->active_lanes, &ret); /* ADI Required Write */ if (tx->src == &state->hdmi.sd) { @@ -270,7 +270,7 @@ static int adv748x_power_up_tx(struct adv748x_csi2 *tx) usleep_range(2000, 2500); /* Power-up CSI-TX */ - adv748x_write_check(state, page, 0x00, 0x20 | tx->num_lanes, &ret); + adv748x_write_check(state, page, 0x00, 0x20 | tx->active_lanes, &ret); usleep_range(1000, 1500); /* ADI Required Writes */ @@ -292,7 +292,7 @@ static int adv748x_power_down_tx(struct adv748x_csi2 *tx) adv748x_write_check(state, page, 0x1e, 0x00, &ret); /* Enable n-lane MIPI */ - adv748x_write_check(state, page, 0x00, 0x80 | tx->num_lanes, &ret); + adv748x_write_check(state, page, 0x00, 0x80 | tx->active_lanes, &ret); /* i2c_mipi_pll_en - 1'b1 */ adv748x_write_check(state, page, 0xda, 0x01, &ret); @@ -357,14 +357,29 @@ static int adv748x_link_setup(struct media_entity *entity, if (state->afe.tx) { /* AFE Requires TXA enabled, even when output to TXB */ io10 |= ADV748X_IO_10_CSI4_EN; - if (is_txa(tx)) + if (is_txa(tx)) { + /* + * Output from the SD-core (480i and 576i) from the TXA + * interface requires reducing the number of enabled + * data lanes in order to guarantee a valid link + * frequency. + */ + tx->active_lanes = min(tx->num_lanes, 2U); io10 |= ADV748X_IO_10_CSI4_IN_SEL_AFE; - else + } else { + /* TXB has a single data lane, no need to adjust. */ io10 |= ADV748X_IO_10_CSI1_EN; + } } - if (state->hdmi.tx) + if (state->hdmi.tx) { + /* + * Restore the number of active lanes, in case we have gone + * through an AFE->TXA streaming sessions. + */ + tx->active_lanes = tx->num_lanes; io10 |= ADV748X_IO_10_CSI4_EN; + } return io_clrset(state, ADV748X_IO_10, io10_mask, io10); } @@ -596,6 +611,7 @@ static int adv748x_parse_csi2_lanes(struct adv748x_state *state, } state->txa.num_lanes = num_lanes; + state->txa.active_lanes = num_lanes; adv_dbg(state, "TXA: using %u lanes\n", state->txa.num_lanes); } @@ -607,6 +623,7 @@ static int adv748x_parse_csi2_lanes(struct adv748x_state *state, } state->txb.num_lanes = num_lanes; + state->txb.active_lanes = num_lanes; adv_dbg(state, "TXB: using %u lanes\n", state->txb.num_lanes); } diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h index fccb388ce179..1061f425ece5 100644 --- a/drivers/media/i2c/adv748x/adv748x.h +++ b/drivers/media/i2c/adv748x/adv748x.h @@ -79,6 +79,7 @@ struct adv748x_csi2 { unsigned int page; unsigned int port; unsigned int num_lanes; + unsigned int active_lanes; struct media_pad pads[ADV748X_CSI2_NR_PADS]; struct v4l2_ctrl_handler ctrl_hdl; From patchwork Wed Apr 15 10:50:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11491089 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 F3795186E for ; Wed, 15 Apr 2020 10:48:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDC1020784 for ; Wed, 15 Apr 2020 10:48:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896633AbgDOKs1 (ORCPT ); Wed, 15 Apr 2020 06:48:27 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:35473 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896636AbgDOKsO (ORCPT ); Wed, 15 Apr 2020 06:48:14 -0400 Received: from uno.homenet.telecomitalia.it (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 0E43A24000D; Wed, 15 Apr 2020 10:48:02 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 5/6] media: i2c: adv748x: Implement get_mbus_config Date: Wed, 15 Apr 2020 12:50:02 +0200 Message-Id: <20200415105004.2497356-6-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> References: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Implement the newly introduced get_mbus_config operation to report the number of currently used data lanes on the MIPI CSI-2 interface. Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/i2c/adv748x/adv748x-csi2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/media/i2c/adv748x/adv748x-csi2.c b/drivers/media/i2c/adv748x/adv748x-csi2.c index 2091cda50935..f13563da3ff3 100644 --- a/drivers/media/i2c/adv748x/adv748x-csi2.c +++ b/drivers/media/i2c/adv748x/adv748x-csi2.c @@ -214,9 +214,24 @@ static int adv748x_csi2_set_format(struct v4l2_subdev *sd, return ret; } +static int adv748x_csi2_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_pad_config *config) +{ + struct adv748x_csi2 *tx = adv748x_sd_to_csi2(sd); + + if (pad != ADV748X_CSI2_SOURCE) + return -EINVAL; + + config->type = V4L2_MBUS_CSI2_DPHY; + config->csi2_dphy.data_lanes = tx->active_lanes; + + return 0; +} + static const struct v4l2_subdev_pad_ops adv748x_csi2_pad_ops = { .get_fmt = adv748x_csi2_get_format, .set_fmt = adv748x_csi2_set_format, + .get_mbus_config = adv748x_csi2_get_mbus_config, }; /* ----------------------------------------------------------------------------- From patchwork Wed Apr 15 10:50:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11491093 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 731D8112C for ; Wed, 15 Apr 2020 10:48:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 624AC20784 for ; Wed, 15 Apr 2020 10:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896649AbgDOKsr (ORCPT ); Wed, 15 Apr 2020 06:48:47 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:57123 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896640AbgDOKsZ (ORCPT ); Wed, 15 Apr 2020 06:48:25 -0400 Received: from uno.homenet.telecomitalia.it (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 68D5A240003; Wed, 15 Apr 2020 10:48:13 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 6/6] media: rcar-csi2: Negotiate data lanes number Date: Wed, 15 Apr 2020 12:50:03 +0200 Message-Id: <20200415105004.2497356-7-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> References: <20200415105004.2497356-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use the newly introduced get_mbus_config() subdevice pad operation to retrieve the remote subdevice MIPI CSI-2 bus configuration and configure the number of active data lanes accordingly. In order to be able to call the remote subdevice operation cache the index of the remote pad connected to the single CSI-2 input port. Signed-off-by: Jacopo Mondi --- Niklas I've not been able to fully address comments as -ENOIOCTL command has to be handled separately as reported by email. --- drivers/media/platform/rcar-vin/rcar-csi2.c | 53 +++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) -- 2.26.0 diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index faa9fb23a2e9..0061d5ff37e3 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -363,6 +363,7 @@ struct rcar_csi2 { struct v4l2_async_notifier notifier; struct v4l2_async_subdev asd; struct v4l2_subdev *remote; + unsigned short remote_pad; struct v4l2_mbus_framefmt mf; @@ -371,6 +372,7 @@ struct rcar_csi2 { unsigned short lanes; unsigned char lane_swap[4]; + unsigned short active_lanes; }; static inline struct rcar_csi2 *sd_to_csi2(struct v4l2_subdev *sd) @@ -414,7 +416,7 @@ static int rcsi2_wait_phy_start(struct rcar_csi2 *priv) /* Wait for the clock and data lanes to enter LP-11 state. */ for (timeout = 0; timeout <= 20; timeout++) { - const u32 lane_mask = (1 << priv->lanes) - 1; + const u32 lane_mask = (1 << priv->active_lanes) - 1; if ((rcsi2_read(priv, PHCLM_REG) & PHCLM_STOPSTATECKL) && (rcsi2_read(priv, PHDLM_REG) & lane_mask) == lane_mask) @@ -471,11 +473,49 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp) * bps = link_freq * 2 */ mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * bpp; - do_div(mbps, priv->lanes * 1000000); + do_div(mbps, priv->active_lanes * 1000000); return mbps; } +static int rcsi2_config_active_lanes(struct rcar_csi2 *priv) +{ + struct v4l2_mbus_pad_config mbus_config; + int ret; + + priv->active_lanes = priv->lanes; + + memset(&mbus_config, 0, sizeof(mbus_config)); + ret = v4l2_subdev_call(priv->remote, pad, get_mbus_config, + priv->remote_pad, &mbus_config); + if (ret == -ENOIOCTLCMD) { + dev_dbg(priv->dev, "No remote mbus configuration available\n"); + return 0; + } + + if (ret) { + dev_err(priv->dev, "Failed to get remote mbus configuration\n"); + return ret; + } + + if (mbus_config.type != V4L2_MBUS_CSI2_DPHY) { + dev_err(priv->dev, "Unsupported mbus type %u\n", + mbus_config.type); + return -EINVAL; + } + + if (mbus_config.csi2_dphy.data_lanes > priv->lanes) { + dev_err(priv->dev, + "Unsupported mbus config: too many data lanes %u\n", + mbus_config.csi2_dphy.data_lanes); + return -EINVAL; + } + + priv->active_lanes = mbus_config.csi2_dphy.data_lanes; + + return 0; +} + static int rcsi2_start_receiver(struct rcar_csi2 *priv) { const struct rcar_csi2_format *format; @@ -490,6 +530,11 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv) /* Code is validated in set_fmt. */ format = rcsi2_code_to_fmt(priv->mf.code); + /* Get the remote mbus config to get the number of enabled lanes. */ + ret = rcsi2_config_active_lanes(priv); + if (ret) + return ret; + /* * Enable all supported CSI-2 channels with virtual channel and * data type matching. @@ -522,7 +567,7 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv) } phycnt = PHYCNT_ENABLECLK; - phycnt |= (1 << priv->lanes) - 1; + phycnt |= (1 << priv->active_lanes) - 1; mbps = rcsi2_calc_mbps(priv, format->bpp); if (mbps < 0) @@ -748,6 +793,7 @@ static int rcsi2_notify_bound(struct v4l2_async_notifier *notifier, } priv->remote = subdev; + priv->remote_pad = pad; dev_dbg(priv->dev, "Bound %s pad: %d\n", subdev->name, pad); @@ -793,6 +839,7 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv, priv->lanes); return -EINVAL; } + priv->active_lanes = priv->lanes; for (i = 0; i < ARRAY_SIZE(priv->lane_swap); i++) { priv->lane_swap[i] = i < priv->lanes ?