From patchwork Sat Mar 16 15:47:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10855925 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CCDB1823 for ; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BB172A099 for ; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D77729F63; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C13EA29F63 for ; Sat, 16 Mar 2019 15:47:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726629AbfCPPri (ORCPT ); Sat, 16 Mar 2019 11:47:38 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:48871 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbfCPPrh (ORCPT ); Sat, 16 Mar 2019 11:47:37 -0400 X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 899351BF209; Sat, 16 Mar 2019 15:47:34 +0000 (UTC) From: Jacopo Mondi To: sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com Cc: Jacopo Mondi , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, dave.stevenson@raspberrypi.org Subject: [RFC 1/5] v4l: subdev: Add MIPI CSI-2 PHY to frame desc Date: Sat, 16 Mar 2019 16:47:57 +0100 Message-Id: <20190316154801.20460-2-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190316154801.20460-1-jacopo+renesas@jmondi.org> References: <20190316154801.20460-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add PHY-specific parameters to MIPI CSI-2 frame descriptor. Signed-off-by: Jacopo Mondi --- include/media/v4l2-subdev.h | 42 +++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 6311f670de3c..eca9633c83bf 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -317,11 +317,33 @@ struct v4l2_subdev_audio_ops { int (*s_stream)(struct v4l2_subdev *sd, int enable); }; +#define V4L2_FRAME_DESC_ENTRY_DPHY_DATA_LANES 4 + +/** + * struct v4l2_mbus_frame_desc_entry_csi2_dphy - MIPI D-PHY bus configuration + * + * @clock_lane: physical lane index of the clock lane + * @data_lanes: an array of physical data lane indexes + * @num_data_lanes: number of data lanes + */ +struct v4l2_mbus_frame_desc_entry_csi2_dphy { + u8 clock_lane; + u8 data_lanes[V4L2_FRAME_DESC_ENTRY_DPHY_DATA_LANES]; + u8 num_data_lanes; +}; + +/** + * struct v4l2_mbus_frame_desc_entry_csi2_cphy - MIPI C-PHY bus configuration + */ +struct v4l2_mbus_frame_desc_entry_csi2_cphy { + /* TODO */ +}; + /** * struct v4l2_mbus_frame_desc_entry_csi2 * - * @channel: CSI-2 virtual channel - * @data_type: CSI-2 data type ID + * @channel: CSI-2 virtual channel + * @data_type: CSI-2 data type ID */ struct v4l2_mbus_frame_desc_entry_csi2 { u8 channel; @@ -371,18 +393,26 @@ enum v4l2_mbus_frame_desc_type { V4L2_MBUS_FRAME_DESC_TYPE_PLATFORM, V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL, V4L2_MBUS_FRAME_DESC_TYPE_CCP2, - V4L2_MBUS_FRAME_DESC_TYPE_CSI2, + V4L2_MBUS_FRAME_DESC_TYPE_CSI2_DPHY, + V4L2_MBUS_FRAME_DESC_TYPE_CSI2_CPHY, }; /** * struct v4l2_mbus_frame_desc - media bus data frame description - * @type: type of the bus (enum v4l2_mbus_frame_desc_type) - * @entry: frame descriptors array - * @num_entries: number of entries in @entry array + * @type: type of the bus (enum v4l2_mbus_frame_desc_type) + * @entry: frame descriptors array + * @phy: PHY specific parameters + * @phy.dphy: MIPI D-PHY specific bus configurations + * @phy.cphy: MIPI C-PHY specific bus configurations + * @num_entries: number of entries in @entry array */ struct v4l2_mbus_frame_desc { enum v4l2_mbus_frame_desc_type type; struct v4l2_mbus_frame_desc_entry entry[V4L2_FRAME_DESC_ENTRY_MAX]; + union { + struct v4l2_mbus_frame_desc_entry_csi2_dphy csi2_dphy; + struct v4l2_mbus_frame_desc_entry_csi2_cphy csi2_cphy; + } phy; unsigned short num_entries; }; From patchwork Sat Mar 16 15:47:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10855929 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E8241575 for ; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 815DB2966F for ; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 758E02A099; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E193329FCE for ; Sat, 16 Mar 2019 15:47:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbfCPPrk (ORCPT ); Sat, 16 Mar 2019 11:47:40 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:49297 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbfCPPrk (ORCPT ); Sat, 16 Mar 2019 11:47:40 -0400 X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 3610B1BF20B; Sat, 16 Mar 2019 15:47:36 +0000 (UTC) From: Jacopo Mondi To: sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com Cc: Jacopo Mondi , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, dave.stevenson@raspberrypi.org Subject: [RFC 2/5] media: adv748x: Post-pone IO10 write to power up Date: Sat, 16 Mar 2019 16:47:58 +0100 Message-Id: <20190316154801.20460-3-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190316154801.20460-1-jacopo+renesas@jmondi.org> References: <20190316154801.20460-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Post-pone the write of the ADV748X_IO_10 register that controls the active routing between the CP and AFE cores to the 4-lanes CSI-2 TXA at TX power-up time. While at there, use the 'csi4_in_sel' name, which matches the register field description in the manual, in place of 'io_10' which is the full register name. Fixes: 9423ca350df7 ("media: adv748x: Implement TX link_setup callback") Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- drivers/media/i2c/adv748x/adv748x-core.c | 53 ++++++++++++++---------- drivers/media/i2c/adv748x/adv748x.h | 2 + 2 files changed, 33 insertions(+), 22 deletions(-) -- 2.21.0 diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c index 0e5a75eb6d75..02135741b1a6 100644 --- a/drivers/media/i2c/adv748x/adv748x-core.c +++ b/drivers/media/i2c/adv748x/adv748x-core.c @@ -305,23 +305,35 @@ static int adv748x_power_down_tx(struct adv748x_csi2 *tx) int adv748x_tx_power(struct adv748x_csi2 *tx, bool on) { - int val; + u8 io10_mask = ADV748X_IO_10_CSI1_EN | ADV748X_IO_10_CSI4_EN | + ADV748X_IO_10_CSI4_IN_SEL_AFE; + struct adv748x_state *state = tx->state; + int ret; if (!is_tx_enabled(tx)) return 0; - val = tx_read(tx, ADV748X_CSI_FS_AS_LS); - if (val < 0) - return val; + ret = tx_read(tx, ADV748X_CSI_FS_AS_LS); + if (ret < 0) + return ret; /* * This test against BIT(6) is not documented by the datasheet, but was * specified in the downstream driver. * Track with a WARN_ONCE to determine if it is ever set by HW. */ - WARN_ONCE((on && val & ADV748X_CSI_FS_AS_LS_UNKNOWN), + WARN_ONCE((on && ret & ADV748X_CSI_FS_AS_LS_UNKNOWN), "Enabling with unknown bit set"); + /* Configure TXA routing. */ + if (on) { + ret = io_clrset(state, ADV748X_IO_10, io10_mask, + state->csi4_in_sel); + if (ret) + return ret; + } + + return on ? adv748x_power_up_tx(tx) : adv748x_power_down_tx(tx); } @@ -337,10 +349,7 @@ static int adv748x_link_setup(struct media_entity *entity, struct adv748x_state *state = v4l2_get_subdevdata(sd); struct adv748x_csi2 *tx = adv748x_sd_to_csi2(sd); bool enable = flags & MEDIA_LNK_FL_ENABLED; - u8 io10_mask = ADV748X_IO_10_CSI1_EN | - ADV748X_IO_10_CSI4_EN | - ADV748X_IO_10_CSI4_IN_SEL_AFE; - u8 io10 = 0; + u8 csi4_in_sel = 0; /* Refuse to enable multiple links to the same TX at the same time. */ if (enable && tx->src) @@ -359,17 +368,19 @@ 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; + csi4_in_sel |= ADV748X_IO_10_CSI4_EN; if (is_txa(tx)) - io10 |= ADV748X_IO_10_CSI4_IN_SEL_AFE; + csi4_in_sel |= ADV748X_IO_10_CSI4_IN_SEL_AFE; else - io10 |= ADV748X_IO_10_CSI1_EN; + csi4_in_sel |= ADV748X_IO_10_CSI1_EN; } if (state->hdmi.tx) - io10 |= ADV748X_IO_10_CSI4_EN; + csi4_in_sel |= ADV748X_IO_10_CSI4_EN; - return io_clrset(state, ADV748X_IO_10, io10_mask, io10); + state->csi4_in_sel = csi4_in_sel; + + return 0; } static const struct media_entity_operations adv748x_tx_media_ops = { @@ -485,7 +496,6 @@ static int adv748x_sw_reset(struct adv748x_state *state) static int adv748x_reset(struct adv748x_state *state) { int ret; - u8 regval = 0; ret = adv748x_sw_reset(state); if (ret < 0) @@ -504,6 +514,12 @@ static int adv748x_reset(struct adv748x_state *state) if (ret) return ret; + /* Conditionally enable TXa and TXb. */ + if (is_tx_enabled(&state->txa)) + state->csi4_in_sel |= ADV748X_IO_10_CSI4_EN; + if (is_tx_enabled(&state->txb)) + state->csi4_in_sel |= ADV748X_IO_10_CSI1_EN; + /* Reset TXA and TXB */ adv748x_tx_power(&state->txa, 1); adv748x_tx_power(&state->txa, 0); @@ -513,13 +529,6 @@ static int adv748x_reset(struct adv748x_state *state) /* Disable chip powerdown & Enable HDMI Rx block */ io_write(state, ADV748X_IO_PD, ADV748X_IO_PD_RX_EN); - /* Conditionally enable TXa and TXb. */ - if (is_tx_enabled(&state->txa)) - regval |= ADV748X_IO_10_CSI4_EN; - if (is_tx_enabled(&state->txb)) - regval |= ADV748X_IO_10_CSI1_EN; - io_write(state, ADV748X_IO_10, regval); - /* Use vid_std and v_freq as freerun resolution for CP */ cp_clrset(state, ADV748X_CP_CLMP_POS, ADV748X_CP_CLMP_POS_DIS_AUTO, ADV748X_CP_CLMP_POS_DIS_AUTO); diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h index 4a5a6445604f..27c116d09284 100644 --- a/drivers/media/i2c/adv748x/adv748x.h +++ b/drivers/media/i2c/adv748x/adv748x.h @@ -196,6 +196,8 @@ struct adv748x_state { struct adv748x_afe afe; struct adv748x_csi2 txa; struct adv748x_csi2 txb; + + unsigned int csi4_in_sel; }; #define adv748x_hdmi_to_state(h) container_of(h, struct adv748x_state, hdmi) From patchwork Sat Mar 16 15:47:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10855931 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 535251823 for ; Sat, 16 Mar 2019 15:47:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A1F32966F for ; Sat, 16 Mar 2019 15:47:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E6E92A024; Sat, 16 Mar 2019 15:47:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1A612966F for ; Sat, 16 Mar 2019 15:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726735AbfCPPrl (ORCPT ); Sat, 16 Mar 2019 11:47:41 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:35781 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbfCPPrl (ORCPT ); Sat, 16 Mar 2019 11:47:41 -0400 X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id E6F9C1BF20E; Sat, 16 Mar 2019 15:47:37 +0000 (UTC) From: Jacopo Mondi To: sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com Cc: Jacopo Mondi , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, dave.stevenson@raspberrypi.org Subject: [RFC 3/5] media: adv748x: Make lanes number depend on routing Date: Sat, 16 Mar 2019 16:47:59 +0100 Message-Id: <20190316154801.20460-4-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190316154801.20460-1-jacopo+renesas@jmondi.org> References: <20190316154801.20460-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the TXA routing information to configure the number of active CSI-2 data lanes. When routing AFE through TXA limit the number of data lanes to 1, while in the canonical HDMI->TXA routing use all the physically available ones. The number of lanes collected from the 'data-lanes' DT property is now used as a the number of physically available data lanes, while the 'num_lanes' variable contains the number of active ones. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/adv748x/adv748x-core.c | 19 ++++++++++++++++++- drivers/media/i2c/adv748x/adv748x.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c index 02135741b1a6..f91c7b83f1bf 100644 --- a/drivers/media/i2c/adv748x/adv748x-core.c +++ b/drivers/media/i2c/adv748x/adv748x-core.c @@ -350,6 +350,8 @@ static int adv748x_link_setup(struct media_entity *entity, struct adv748x_csi2 *tx = adv748x_sd_to_csi2(sd); bool enable = flags & MEDIA_LNK_FL_ENABLED; u8 csi4_in_sel = 0; + u8 num_lanes; + int ret; /* Refuse to enable multiple links to the same TX at the same time. */ if (enable && tx->src) @@ -373,10 +375,23 @@ static int adv748x_link_setup(struct media_entity *entity, csi4_in_sel |= ADV748X_IO_10_CSI4_IN_SEL_AFE; else csi4_in_sel |= ADV748X_IO_10_CSI1_EN; + + num_lanes = 1; } - if (state->hdmi.tx) + if (state->hdmi.tx) { csi4_in_sel |= ADV748X_IO_10_CSI4_EN; + num_lanes = tx->available_lanes; + } + + /* Update the number of active lanes if it has changed. */ + if (num_lanes != tx->num_lanes) { + tx->num_lanes = num_lanes; + ret = adv748x_write(state, tx->page, 0x00, + 0x80 | tx->num_lanes); + if (ret) + return ret; + } state->csi4_in_sel = csi4_in_sel; @@ -608,6 +623,7 @@ static int adv748x_parse_csi2_lanes(struct adv748x_state *state, } state->txa.num_lanes = num_lanes; + state->txa.available_lanes = num_lanes; adv_dbg(state, "TXA: using %u lanes\n", state->txa.num_lanes); } @@ -619,6 +635,7 @@ static int adv748x_parse_csi2_lanes(struct adv748x_state *state, } state->txb.num_lanes = num_lanes; + state->txb.available_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 27c116d09284..6e5c2cb421fe 100644 --- a/drivers/media/i2c/adv748x/adv748x.h +++ b/drivers/media/i2c/adv748x/adv748x.h @@ -80,6 +80,7 @@ struct adv748x_csi2 { unsigned int page; unsigned int port; unsigned int num_lanes; + unsigned int available_lanes; struct media_pad pads[ADV748X_CSI2_NR_PADS]; struct v4l2_ctrl_handler ctrl_hdl; From patchwork Sat Mar 16 15:48:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10855935 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F037C1823 for ; Sat, 16 Mar 2019 15:47:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D79622966F for ; Sat, 16 Mar 2019 15:47:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBE742A024; Sat, 16 Mar 2019 15:47:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C4B429FCE for ; Sat, 16 Mar 2019 15:47:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726835AbfCPPrm (ORCPT ); Sat, 16 Mar 2019 11:47:42 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:49297 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbfCPPrm (ORCPT ); Sat, 16 Mar 2019 11:47:42 -0400 X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 807761BF207; Sat, 16 Mar 2019 15:47:39 +0000 (UTC) From: Jacopo Mondi To: sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com Cc: Jacopo Mondi , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, dave.stevenson@raspberrypi.org Subject: [RFC 4/5] media: adv748x: Report D-PHY configuration Date: Sat, 16 Mar 2019 16:48:00 +0100 Message-Id: <20190316154801.20460-5-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190316154801.20460-1-jacopo+renesas@jmondi.org> References: <20190316154801.20460-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extend the media bus frame description to report the D-PHY bus configuration. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/adv748x/adv748x-csi2.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/adv748x/adv748x-csi2.c b/drivers/media/i2c/adv748x/adv748x-csi2.c index 13454af72c6e..c733c7ab8247 100644 --- a/drivers/media/i2c/adv748x/adv748x-csi2.c +++ b/drivers/media/i2c/adv748x/adv748x-csi2.c @@ -231,8 +231,12 @@ static int adv748x_csi2_set_format(struct v4l2_subdev *sd, static int adv748x_csi2_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_frame_desc *fd) { + struct v4l2_mbus_frame_desc_entry_csi2_dphy *dphy; struct adv748x_csi2 *tx = adv748x_sd_to_csi2(sd); + struct v4l2_mbus_frame_desc_entry_csi2 *csi2; struct v4l2_mbus_framefmt *mbusformat; + unsigned int i; + memset(fd, 0, sizeof(*fd)); @@ -244,13 +248,20 @@ static int adv748x_csi2_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, if (!mbusformat) return -EINVAL; + fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2_DPHY; + fd->num_entries = 1; + fd->entry->stream = tx->vc; - fd->entry->bus.csi2.channel = tx->vc; - fd->entry->bus.csi2.data_type = - adv748x_csi2_code_to_datatype(mbusformat->code); - fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; - fd->num_entries = 1; + csi2 = &fd->entry->bus.csi2; + csi2->channel = tx->vc; + csi2->data_type = adv748x_csi2_code_to_datatype(mbusformat->code); + + dphy = &fd->phy.csi2_dphy; + dphy->clock_lane = 0; + for (i = 0; i < tx->num_lanes; ++i) + dphy->data_lanes[i] = i + 1; + dphy->num_data_lanes = tx->num_lanes; return 0; } From patchwork Sat Mar 16 15:48:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10855939 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2BB496C2 for ; Sat, 16 Mar 2019 15:47:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 119CC2966F for ; Sat, 16 Mar 2019 15:47:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05AC62A024; Sat, 16 Mar 2019 15:47:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FCC52966F for ; Sat, 16 Mar 2019 15:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726461AbfCPPro (ORCPT ); Sat, 16 Mar 2019 11:47:44 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:35781 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726815AbfCPPro (ORCPT ); Sat, 16 Mar 2019 11:47:44 -0400 X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 273201BF209; Sat, 16 Mar 2019 15:47:40 +0000 (UTC) From: Jacopo Mondi To: sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, kieran.bingham@ideasonboard.com Cc: Jacopo Mondi , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, dave.stevenson@raspberrypi.org Subject: [RFC 5/5] media: rcar-csi2: Configure CSI-2 with frame desc Date: Sat, 16 Mar 2019 16:48:01 +0100 Message-Id: <20190316154801.20460-6-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190316154801.20460-1-jacopo+renesas@jmondi.org> References: <20190316154801.20460-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the D-PHY configuration reported by the remote subdevice in its frame descriptor to configure the interface. Store the number of lanes reported through the 'data-lanes' DT property as the number of phyisically available lanes, which might not correspond to the number of lanes actually in use. Signed-off-by: Jacopo Mondi --- drivers/media/platform/rcar-vin/rcar-csi2.c | 71 +++++++++++++-------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index 6c46bcc0ee83..70b9a8165a6e 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -375,8 +375,8 @@ struct rcar_csi2 { struct mutex lock; int stream_count; - unsigned short lanes; - unsigned char lane_swap[4]; + unsigned short available_data_lanes; + unsigned short num_data_lanes; }; static inline struct rcar_csi2 *sd_to_csi2(struct v4l2_subdev *sd) @@ -424,7 +424,7 @@ static int rcsi2_get_remote_frame_desc(struct rcar_csi2 *priv, if (ret) return -ENODEV; - if (fd->type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2) { + if (fd->type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2_DPHY) { dev_err(priv->dev, "Frame desc do not describe CSI-2 link"); return -EINVAL; } @@ -438,7 +438,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->num_data_lanes) - 1; if ((rcsi2_read(priv, PHCLM_REG) & PHCLM_STOPSTATECKL) && (rcsi2_read(priv, PHDLM_REG) & lane_mask) == lane_mask) @@ -511,14 +511,15 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, * bps = link_freq * 2 */ mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * bpp; - do_div(mbps, priv->lanes * 1000000); + do_div(mbps, priv->num_data_lanes * 1000000); return mbps; } static int rcsi2_start(struct rcar_csi2 *priv) { - u32 phycnt, vcdt = 0, vcdt2 = 0; + struct v4l2_mbus_frame_desc_entry_csi2_dphy *dphy; + u32 phycnt, vcdt = 0, vcdt2 = 0, lswap = 0; struct v4l2_mbus_frame_desc fd; unsigned int i; int mbps, ret; @@ -548,8 +549,26 @@ static int rcsi2_start(struct rcar_csi2 *priv) entry->bus.csi2.channel, entry->bus.csi2.data_type); } + /* Get description of the D-PHY media bus configuration. */ + dphy = &fd.phy.csi2_dphy; + if (dphy->clock_lane != 0) { + dev_err(priv->dev, + "CSI-2 configuration not supported: clock at index %u", + dphy->clock_lane); + return -EINVAL; + } + + if (dphy->num_data_lanes > priv->available_data_lanes || + dphy->num_data_lanes == 3) { + dev_err(priv->dev, + "Number of CSI-2 data lanes not supported: %u", + dphy->num_data_lanes); + return -EINVAL; + } + priv->num_data_lanes = dphy->num_data_lanes; + phycnt = PHYCNT_ENABLECLK; - phycnt |= (1 << priv->lanes) - 1; + phycnt |= (1 << priv->num_data_lanes) - 1; mbps = rcsi2_calc_mbps(priv, &fd); if (mbps < 0) @@ -566,12 +585,11 @@ static int rcsi2_start(struct rcar_csi2 *priv) rcsi2_write(priv, VCDT_REG, vcdt); if (vcdt2) rcsi2_write(priv, VCDT2_REG, vcdt2); + /* Lanes are zero indexed. */ - rcsi2_write(priv, LSWAP_REG, - LSWAP_L0SEL(priv->lane_swap[0] - 1) | - LSWAP_L1SEL(priv->lane_swap[1] - 1) | - LSWAP_L2SEL(priv->lane_swap[2] - 1) | - LSWAP_L3SEL(priv->lane_swap[3] - 1)); + for (i = 0; i < priv->num_data_lanes; ++i) + lswap |= (dphy->data_lanes[i] - 1) << (i * 2); + rcsi2_write(priv, LSWAP_REG, lswap); /* Start */ if (priv->info->init_phtw) { @@ -822,7 +840,7 @@ static const struct v4l2_async_notifier_operations rcar_csi2_notify_ops = { static int rcsi2_parse_v4l2(struct rcar_csi2 *priv, struct v4l2_fwnode_endpoint *vep) { - unsigned int i; + unsigned int num_data_lanes; /* Only port 0 endpoint 0 is valid. */ if (vep->base.port || vep->base.id) @@ -833,24 +851,21 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv, return -EINVAL; } - priv->lanes = vep->bus.mipi_csi2.num_data_lanes; - if (priv->lanes != 1 && priv->lanes != 2 && priv->lanes != 4) { + num_data_lanes = vep->bus.mipi_csi2.num_data_lanes; + switch (num_data_lanes) { + case 1: + /* fallthrough */ + case 2: + /* fallthrough */ + case 4: + priv->available_data_lanes = num_data_lanes; + break; + default: dev_err(priv->dev, "Unsupported number of data-lanes: %u\n", - priv->lanes); + num_data_lanes); return -EINVAL; } - for (i = 0; i < ARRAY_SIZE(priv->lane_swap); i++) { - priv->lane_swap[i] = i < priv->lanes ? - vep->bus.mipi_csi2.data_lanes[i] : i; - - /* Check for valid lane number. */ - if (priv->lane_swap[i] < 1 || priv->lane_swap[i] > 4) { - dev_err(priv->dev, "data-lanes must be in 1-4 range\n"); - return -EINVAL; - } - } - return 0; } @@ -1235,7 +1250,7 @@ static int rcsi2_probe(struct platform_device *pdev) if (ret < 0) goto error; - dev_info(priv->dev, "%d lanes found\n", priv->lanes); + dev_info(priv->dev, "%d lanes found\n", priv->available_data_lanes); return 0;