Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F152283FCB for ; Mon, 19 May 2025 14:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747664887; cv=none; b=JvQopcLv8BFzV5K9pO8H5ttF12AbA+2/kJ4lpb23UC7n3ltLk4fK4rn4TwJck1l5MdMnxE/wjuKh3Su3m/eZVy1uv1nYyEBSfaVMQomODkbb//cks7fY2kNDaKAgyIE2eKyU5CbdZhAEjZBFpa130Hc7ZoREG27gBeXHnrvueZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747664887; c=relaxed/simple; bh=V2823Yv3k/9YA7miv4s/MSaVT3FTEW77wxkBfJCYmzc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=J9pWENQLubTQLIsCDv1rKhq0gTDzpVruo79/02HyxTfbI6TFEmYGhRU3perywiOazRil8bK55mcaHfqfipmRKr8OEg74c8F+uyovIEM4zDYi4OQTxFDejx1xRFVBHuhjFkQvMu1GTsUFsYuSP8gjBV4MWU5QUMGC/eK92rUBlhY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=laUYHjai; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="laUYHjai" Received: from [192.168.0.43] (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0016C83D; Mon, 19 May 2025 16:27:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1747664862; bh=V2823Yv3k/9YA7miv4s/MSaVT3FTEW77wxkBfJCYmzc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=laUYHjai4GT9h15rKJcDVGC9XXLEIvCrA7dwJxKI9/0wjbScFZlbZF6/YRdl5Ss/b LoDxtLkdHKiwjL65XthqRwUJ3Ar8ZPads0BnK+TqhTKSn9zSD+enfAYvr7CXt5CRp6 U8Qd4cMN2lSLunlV7yfl4PadIrgcnenBC15Fr3tc= Message-ID: <04a5f332-2e76-4ccd-9f3c-9ddd51ae2dfa@ideasonboard.com> Date: Mon, 19 May 2025 15:27:58 +0100 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq() To: Jacopo Mondi Cc: "Lad, Prabhakar" , Tommaso Merciai , linux-media@vger.kernel.org, hverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, prabhakar.mahadev-lad.rj@bp.renesas.com, Daniel Scally , Laurent Pinchart References: <20250506125015.567746-1-dan.scally@ideasonboard.com> <20250506125015.567746-4-dan.scally@ideasonboard.com> <3eb69cea-b511-412e-a126-ce246c2491df@bp.renesas.com> Content-Language: en-US From: Dan Scally Autocrypt: addr=dan.scally@ideasonboard.com; keydata= xsFNBGLydlEBEADa5O2s0AbUguprfvXOQun/0a8y2Vk6BqkQALgeD6KnXSWwaoCULp18etYW B31bfgrdphXQ5kUQibB0ADK8DERB4wrzrU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MAEQEAAcLBfAQYAQgAJhYhBLHbbfDlj+/vEjX0HpIkLofy/hjEBQJi8nZT BQkFo5qAAhsMAAoJEJIkLofy/hjEXPcQAMIPNqiWiz/HKu9W4QIf1OMUpKn3YkVIj3p3gvfM Res4fGX94Ji599uLNrPoxKyaytC4R6BTxVriTJjWK8mbo9jZIRM4vkwkZZ2bu98EweSucxbp vjESsvMXGgxniqV/RQ/3T7LABYRoIUutARYq58p5HwSP0frF0fdFHYdTa2g7MYZl1ur2JzOC FHRpGadlNzKDE3fEdoMobxHB3Lm6FDml5GyBAA8+dQYVI0oDwJ3gpZPZ0J5Vx9RbqXe8RDuR du90hvCJkq7/tzSQ0GeD3BwXb9/R/A4dVXhaDd91Q1qQXidI+2jwhx8iqiYxbT+DoAUkQRQy xBtoCM1CxH7u45URUgD//fxYr3D4B1SlonA6vdaEdHZOGwECnDpTxecENMbz/Bx7qfrmd901 D+N9SjIwrbVhhSyUXYnSUb8F+9g2RDY42Sk7GcYxIeON4VzKqWM7hpkXZ47pkK0YodO+dRKM yMcoUWrTK0Uz6UzUGKoJVbxmSW/EJLEGoI5p3NWxWtScEVv8mO49gqQdrRIOheZycDmHnItt 9Qjv00uFhEwv2YfiyGk6iGF2W40s2pH2t6oeuGgmiZ7g6d0MEK8Ql/4zPItvr1c1rpwpXUC1 u1kQWgtnNjFHX3KiYdqjcZeRBiry1X0zY+4Y24wUU0KsEewJwjhmCKAsju1RpdlPg2kC In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Jacopo On 19/05/2025 15:09, Jacopo Mondi wrote: > Hi Dan > > On Mon, May 19, 2025 at 02:07:04PM +0100, Dan Scally wrote: >> Hi again >> >> On 15/05/2025 12:59, Lad, Prabhakar wrote: >>> Hi Tommaso, >>> >>> On Fri, May 9, 2025 at 4:41 PM Tommaso Merciai >>> wrote: >>>> Hi Jacopo, >>>> Thanks for your comment. >>>> >>>> On 09/05/25 16:50, Jacopo Mondi wrote: >>>>> Hi Tommaso >>>>> >>>>> On Fri, May 09, 2025 at 04:17:34PM +0200, Tommaso Merciai wrote: >>>>>> Hi Daniel, >>>>>> Thanks for your patch. >>>>>> >>>>>> On Tue, May 06, 2025 at 01:50:12PM +0100, Daniel Scally wrote: >>>>>>> From: Daniel Scally >>>>>>> >>>>>>> The rzg2l_csi2_calc_mbps() function currently tries to calculate the >>>>>>> link frequency for a CSI2 bus using the V4L2_CID_PIXEL_RATE control >>>>>>> of the remote subdevice. Switch the function to v4l2_get_link_freq() >>>>>>> which correctly targets V4L2_CID_LINK_FREQ before falling back on >>>>>>> V4L2_CID_PIXEL_RATE if the former is unavailable. >>>>>>> >>>>>>> Reviewed-by: Jacopo Mondi >>>>>>> Reviewed-by: Laurent Pinchart >>>>>>> Reviewed-by: Lad Prabhakar >>>>>>> Tested-by: Lad Prabhakar >>>>>>> Signed-off-by: Daniel Scally >>>>>>> --- >>>>>>> Changes in v4: >>>>>>> >>>>>>> - Used separate s64 variable as return value for v4l2_get_link_freq() >>>>>>> and as the mbps variable for do_div() to avoid compilation warnings. >>>>>>> >>>>>>> Changes in v3: >>>>>>> >>>>>>> - Fixed mbps sign >>>>>>> >>>>>>> Changes in v2: >>>>>>> >>>>>>> - None >>>>>>> >>>>>>> .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- >>>>>>> 1 file changed, 12 insertions(+), 15 deletions(-) >>>>>>> >>>>>>> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c >>>>>>> index 9243306e2aa9..8870c2cb8104 100644 >>>>>>> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c >>>>>>> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c >>>>>>> @@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) >>>>>>> const struct rzg2l_csi2_format *format; >>>>>>> const struct v4l2_mbus_framefmt *fmt; >>>>>>> struct v4l2_subdev_state *state; >>>>>>> - struct v4l2_ctrl *ctrl; >>>>>>> u64 mbps; >>>>>>> - >>>>>>> - /* Read the pixel rate control from remote. */ >>>>>>> - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); >>>>>>> - if (!ctrl) { >>>>>>> - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", >>>>>>> - source->name); >>>>>>> - return -EINVAL; >>>>>>> - } >>>>>>> + s64 ret; >>>>>>> >>>>>>> state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); >>>>>>> fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); >>>>>>> format = rzg2l_csi2_code_to_fmt(fmt->code); >>>>>>> v4l2_subdev_unlock_state(state); >>>>>>> >>>>>>> - /* >>>>>>> - * Calculate hsfreq in Mbps >>>>>>> - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes >>>>>>> - */ >>>>>>> - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; >>>>>>> - do_div(mbps, csi2->lanes * 1000000); >>>>>>> + /* Read the link frequency from remote subdevice. */ >>>>>>> + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, >>>>>>> + csi2->lanes); >>> div needs to be updated in v4l2_get_link_freq() as below so that when >>> subdev has only V4L2_CID_PIXEL_RATE we get the correct value. >>> >>> ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, >>> - csi2->lanes); >>> + csi2->lanes * 2); >>> >>>>>>> + if (ret < 0) { >>>>>>> + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", >>>>>>> + source->name); >>>>>>> + return -EINVAL; >>>>>>> + } >>>>>>> + >>>>>>> + mbps = ret; >>>>>>> + do_div(mbps, 1000000); >>>>>>> >>>>>>> return mbps; >>>>>>> } >>>>>> I tested this series with an imx219 image sensor connected to the CSI-2 >>>>>> RX IP of RZ/G3E: >>>>>> >>>>>> Some notes: >>>>>> >>>>>> - pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample >>>>>> - hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes >>>>>> >>>>>> Then hsfreq should be: >>>>> The old code seems to call 'hsfreq' the per-lane bandwidth >>>>> >>>>> - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes >>>>> >>>>> And not the per-lane frequency as the variable name and the commit message >>>>> suggest >>>>> >>>>>> - hsfreq = link_freq * 2 >>>>> if that's the intention, due to CSI-2 DDR, then you're correct I >>>>> think ? >>>>> >>>>> Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder >>>>> if we all have missed that the original code didn't have a / 2 >>> I agree the orignal code missed a / 2. I think we need a fixup patch >>> (so that this can be backported) and then this change to use >>> v4l2_get_link_freq(). >>> >>>>> Dan, did you ever notice issues during your testing ? >>>>> >>>>> Also, with the introduction of 15f0035bfd0a ("media: v4l: Support >>>>> passing media pad argument to v4l2_get_link_freq()") it's probably now >>>>> better to pass the source's pad to v4l2_get_link_freq() ? >>>>> >>>>>> Please correct me if I'm wrong. >>>>>> >>>>>> >>>>>> After applying this series. I'm getting the following issue testing the >>>>>> imx219 sensor with SRGGB8_1X8 and SGRBG10_1X10 color format. >>>>> Does the error go away if you multiply the link_freq by 2 ? >>>> Yes the error goes away on my side using: >>>> >>>> mbps = ret * 2; >>>> >>> I tested the above with an OV5645 sensor and see no issues. >> >> Actually, I'm missing something here. Tommaso, you're using an imx219? So >> V4L2_CID_LINK_FREQ should be 456000000 and V4L2_CID_PIXEL_RATE should be >> 182400000. The original calculation (assuming a 10-bit format and 2 lanes) >> is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in >> Mbps (456) so I understand that the / 2 was missing...but the function with >> this patch applied should return 456 already...so if that's the correct >> value then I'm confused as to why you'd be seeing errors and why multiplying >> the return by 2 would fix them. What am I missing? > It's the other way around actually. > > The function needs to calculate the lane bandwidth not the linke frequency (*), > and as you confirmed the original code returned 912 Mbps. > > - /* > - * Calculate hsfreq in Mbps > - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes > - */ > - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; > - do_div(mbps, csi2->lanes * 1000000); > > > The new code returns the link frequency instead > > + /* Read the link frequency from remote subdevice. */ > + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, > + csi2->lanes); > + > + mbps = ret; > + do_div(mbps, 1000000); > > Maybe I confused you when I've said "the original code didn't have a > / 2" but what I meant is that the original code should have had a / 2 > to behave like the new version (but what we actually want is the new > code to behave like the old one, not the other way around :) > > so the new code should do > > mbps = ret * 2; > > if it uses > > ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, > csi2->lanes * 2); > > Does it make sense ? That part makes sense - thank you - but then do we actually want a separate patch that "fixes" the original function to add the / 2, if the existing behaviour is what we want? > > > > (*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, > but given that all values are in Mbps and not in MHz, and the old code > calculaates the bandwidth and not link frequency, it's fair to assume this > I guess... > >> >> Thanks >> >> Dan >> >>> Cheers, >>> Prabhakar