From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4531FC433E0 for ; Mon, 15 Jun 2020 08:39:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 214AC20739 for ; Mon, 15 Jun 2020 08:39:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lYTW8sKS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729057AbgFOIjp (ORCPT ); Mon, 15 Jun 2020 04:39:45 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:41318 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728861AbgFOIjo (ORCPT ); Mon, 15 Jun 2020 04:39:44 -0400 Received: from [192.168.0.20] (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 65F8FF9; Mon, 15 Jun 2020 10:39:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592210380; bh=OQuxOxUugB22RVEMDsxJG53hsZDgMZT3WcFW0EbW/qo=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=lYTW8sKSm/oaZn3v1fRs14G9dgFepSPyJdJ8RMd+7Seio64C0cqhOgGcE6u4FrsQA O+iQe46cDnXtSS8mqMurcvvnizTPhyce/ZaIC8DkkB3tpRqx+s1n1z9Y57X4se3dGI UBlwWVytpxfi4Wj1nonK8zpEUmgAikPtz999Jxs0= Reply-To: kieran.bingham@ideasonboard.com Subject: Re: [PATCH v4 9/9] media: rcar-csi2: Negotiate data lanes number To: Sakari Ailus , Jacopo Mondi Cc: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, laurent.pinchart@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, dave.stevenson@raspberrypi.com, hyun.kwon@xilinx.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org References: <20200611161651.264633-1-jacopo+renesas@jmondi.org> <20200611161651.264633-10-jacopo+renesas@jmondi.org> <20200615083405.GP16711@paasikivi.fi.intel.com> From: Kieran Bingham Autocrypt: addr=kieran.bingham@ideasonboard.com; keydata= mQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat V/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC rRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C potzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ cSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf Kr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8 RXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko lPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoA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8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j sbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8 pQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc MW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU AfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4 WZw01QYHU/GUV/zHJSFk Organization: Ideas on Board Message-ID: Date: Mon, 15 Jun 2020 09:39:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200615083405.GP16711@paasikivi.fi.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Hi Jacopo, Sakari, On 15/06/2020 09:34, Sakari Ailus wrote: > Hi Jacopo, > > On Thu, Jun 11, 2020 at 06:16:51PM +0200, Jacopo Mondi wrote: >> 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 >> --- >> drivers/media/platform/rcar-vin/rcar-csi2.c | 61 ++++++++++++++++++++- >> 1 file changed, 58 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c >> index 151e6a90c5fb..11769f004fd8 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 int 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; > > Do you need this? I.e. should you not always request this from the > transmitter device? > >> }; >> >> 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,57 @@ 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_config mbus_config = { 0 }; >> + unsigned int num_lanes = (-1U); >> + int ret; >> + >> + priv->active_lanes = priv->lanes; >> + 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 media bus type %u\n", >> + mbus_config.type); >> + return -EINVAL; >> + } >> + >> + if (mbus_config.flags & V4L2_MBUS_CSI2_1_LANE) >> + num_lanes = 1; >> + else if (mbus_config.flags & V4L2_MBUS_CSI2_2_LANE) >> + num_lanes = 2; >> + else if (mbus_config.flags & V4L2_MBUS_CSI2_3_LANE) >> + num_lanes = 3; >> + else if (mbus_config.flags & V4L2_MBUS_CSI2_4_LANE) >> + num_lanes = 4; > > This is the downside of using flags... Anyway, I guess this is certainly > fine now. Given that the mbus_config has a .type, can't we easily extend struct v4l2_mbus_config to contain a type specific union ? Or is that something to do on top of this series instead? I mean, it could even go after the flags, and keep the flags as a common attribute - so that no other changes are needed to other components... -- Kieran > >> + >> + if (num_lanes > priv->lanes) { >> + dev_err(priv->dev, >> + "Unsupported mbus config: too many data lanes %u\n", >> + num_lanes); >> + return -EINVAL; >> + } >> + >> + priv->active_lanes = num_lanes; >> + >> + return 0; >> +} >> + >> static int rcsi2_start_receiver(struct rcar_csi2 *priv) >> { >> const struct rcar_csi2_format *format; >> @@ -490,6 +538,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 +575,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 +801,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 +847,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 ? > -- Regards -- Kieran