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 7468C3C9456 for ; Tue, 9 Jun 2026 06:08:21 +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=1780985303; cv=none; b=mFni6F4MJzk6OpKu5D5iSSfYblqr8srYNtPEn721Ag7rSTvhggcyt3pbzDBr+8/r36iLcLOOjvoymfkerGzgaOqkPBtg/i6L1dMMQEg8zGiy55iD4EVvdW8hTgp7NseYc9AzJMCCDqZV9ff9xpasAJu6FwSKMfINhkHpTyw/Pic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780985303; c=relaxed/simple; bh=xn9VE95j6IgwRIAZXt1AocqMGqbLrgbIE83SmeE9IbU=; h=Content-Type:MIME-Version:In-Reply-To:References:Subject:From:Cc: To:Date:Message-ID; b=dSVm/ZdbOPBxy6HmQmiygOouk4qSmgCgaElTXRhyo6pG50X1Upt6Kkzx6T8APUVs1keiNykQTWjOHXy2FX0M/frmJPQeesKx5RsoDBe1BebvbiLN22b48k1eOwXejHqJXTLypR5J6paUCpmbA3I7qZfH5HgBdgixYbz4wgJWMzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=fail (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=qS0YgMdI reason="signature verification failed"; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (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=fail reason="signature verification failed" (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qS0YgMdI" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c68:bcf2:9325:a9bd:32b:e71]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D7AED132; Tue, 9 Jun 2026 07:58:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1780984699; bh=xn9VE95j6IgwRIAZXt1AocqMGqbLrgbIE83SmeE9IbU=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=qS0YgMdIi0Q/SdA8J+NgGFAUP+N8czvI4z1ZJT+HGvaf0k44180wuBedO8S7cXkxr qpsilricnpOB4w3ZK8T1Iiu9+WDSKUFEcUmIsqqtsUiVFjN6lrybRCaiS+mMV6sR85 z21tCrgQIdem7Pxx3U5cGGGnXsdGl17pcDWy0hmM= Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20260608212856.GA944266@killaraus.ideasonboard.com> References: <20260607215356.842932-1-sakari.ailus@linux.intel.com> <20260607215356.842932-3-sakari.ailus@linux.intel.com> <20260608212856.GA944266@killaraus.ideasonboard.com> Subject: Re: [PATCH v5 02/10] media: imx219: Scale the vblank limits according to rate_factor From: Jai Luthra Cc: Sakari Ailus , linux-media@vger.kernel.org, hans@jjverkuil.nl, Prabhakar , Kate Hsuan , Tommaso Merciai , Benjamin Mugnier , Sylvain Petinot , Christophe JAILLET , Julien Massot , Naushir Patuck , "Yan, Dongcheng" , Stefan Klug , Mirela Rabulea , =?utf-8?q?Andr=C3=A9?= Apitzsch , Heimir Thor Sverrisson , Kieran Bingham , Mehdi Djait , Ricardo Ribalda Delgado , Hans de Goede , Jacopo Mondi , Tomi Valkeinen , David Plowman , "Yu, On g Hock" , "Ng, Khai Wen" , Rishikesh Donadkar To: Dave Stevenson , Laurent Pinchart Date: Tue, 09 Jun 2026 11:28:42 +0530 Message-ID: <178098472222.19620.1186662371886498871@freya> User-Agent: alot/0.13.dev35+g4a69c46ca Hi Laurent, Quoting Laurent Pinchart (2026-06-09 02:58:56) > Hi Dave, >=20 > Thanks a lot for taking the time to investigate and provide very > valuable insight. I really appreciate that. >=20 > On Mon, Jun 08, 2026 at 04:29:46PM +0100, Dave Stevenson wrote: > > On Sun, 7 Jun 2026 at 22:54, Sakari Ailus wrote: > > > > > > The limits for vertical blanking (and frame length in pixels) is rela= ted > > > to the properties of the hardware, it's not in half-line units the dr= iver > > > uses. Multiply the vertical blanking limits by the rate_factor to sat= isty > > > hardware requirements. > >=20 > > Whilst that would be a logical interpretation, it doesn't match with > > how the hardware performs, nor the docs. > >=20 > > The datasheet for register FRM_LENGTH_A 0x160 says > > frame_length_lines > > BINNING_MODE =3D 0,1,2 > > Unit: 1Lines > > BINNING_MODE =3D 3 > > Units: 2Lines > >=20 > > That's not units of 2 lines for active lines only, that is units of 2 > > lines for ALL lines. > >=20 > > I have tested it, and the sensor works fine with FRM_LENGTH_A being > > 0x278 in the 1640x1232 mode, and 0x100 in 640x480 modes with all the > > tests I've thrown at it. Drop them any lower and it does stall or give > > corrupt horizontal lines. >=20 > If I understand this correctly, it indicates that >=20 > - The frame length is expressed as a number of lines at the output of > the sensor (after binning). >=20 > - The minimum margin between the output height (after binning) and the > frame length is 32 lines. >=20 > - In special binning mode, the FRM_LENGTH_A register needs to be > programmed with frame_length_lines / 2. >=20 > The last constraint is device-specific, and as far as I understand it > can be handled directly in the driver without affecting the userspace > API by simply dividing the frame length value by 2 before writing it to > the register. >=20 > It's getting a bit late, I'll test the "regular" binning mode > (BINNING_MODE =3D 1) tomorrow to see how it compares (unless someone beats > me to it). Unless I get very unexpected results, it seems that the > existing implementation is correct and the patch should be dropped. >=20 > One thing that may not be implemented correctly is different binning > modes horizontally and vertically. imx219_get_rate_factor() will return > 2 only when both the horizontal and vertical binning modes are "special > analog binning". When used to scale the frame length and exposure time, > I wonder if only vertical binning should be taken into account. >=20 That does make sense. When I was working on the binning and related issues in this driver, I had decided to always keep `bin_h =3D=3D bin_v` everywhere after some brief tes= ts with different values for them: 1. Setting bin_h =3D 0x1 (normal x2 binning) and bin_v =3D 0x0 (or vice ver= sa) results in the output image being stretched/squeezed, which is expected but not a typical usecase 2. Setting bin_h =3D 0x3 (special x2 binning) and bin_v =3D 0x0 (or vice ve= rsa) results in both dimensions getting binned as opposed to only one, which is unexpected, and it might be breaking other things with the sensor timing too My analysis on the other sub-thread also suggests special x2 binning means analogue-domain averaging in both horzizontal and vertical dimensions.. which matches up with this behaviour, so maybe we can't really separate vertical and horizontal out for the "special" case even if the registers allow us to. Thanks, Jai > > (Please note that the sensor extends the frame length automatically to > > accommodate the exposure time requested, so do ensure the exposure > > time doesn't interact with the frame length if you're testing). > >=20 > > This patch drops the maximum frame rate from 81.07 to 79.07fps in > > 1640x1232 (2.5%), and 200.1 to 188.39fps in 640x480 (6%) for no good > > reason that I can see. > > Unless anyone can produce a genuine situation where they see the > > sensor behave incorrectly with the old setup, I'll be very sad to see > > this merged. > >=20 > > > Fixes: f513997119f4 ("media: i2c: imx219: Scale the pixel rate for an= alog binning") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Sakari Ailus > > > --- > > > drivers/media/i2c/imx219.c | 10 ++++++---- > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c > > > index 223d3753cc93..d8fe7db18b6c 100644 > > > --- a/drivers/media/i2c/imx219.c > > > +++ b/drivers/media/i2c/imx219.c > > > @@ -878,14 +878,17 @@ static int imx219_set_pad_format(struct v4l2_su= bdev *sd, > > > crop->top =3D (IMX219_NATIVE_HEIGHT - crop->height) / 2; > > > > > > if (fmt->which =3D=3D V4L2_SUBDEV_FORMAT_ACTIVE) { > > > + unsigned int rate_factor =3D imx219_get_rate_factor(s= tate); > > > int exposure_max; > > > int exposure_def; > > > int llp_min; > > > int pixel_rate; > > > > > > /* Update limits and set FPS to default */ > > > - ret =3D __v4l2_ctrl_modify_range(imx219->vblank, IMX2= 19_VBLANK_MIN, > > > - IMX219_FLL_MAX - mode-= >height, 1, > > > + ret =3D __v4l2_ctrl_modify_range(imx219->vblank, > > > + IMX219_VBLANK_MIN * ra= te_factor, > > > + (IMX219_FLL_MAX - mode= ->height) * > > > + rate_factor, rate_fact= or, > > > mode->fll_def - mode->= height); > > > if (ret) > > > return ret; > > > @@ -928,8 +931,7 @@ static int imx219_set_pad_format(struct v4l2_subd= ev *sd, > > > return ret; > > > > > > /* Scale the pixel rate based on the mode specific fa= ctor */ > > > - pixel_rate =3D imx219_get_pixel_rate(imx219) * > > > - imx219_get_rate_factor(state); > > > + pixel_rate =3D imx219_get_pixel_rate(imx219) * rate_f= actor; > > > ret =3D __v4l2_ctrl_modify_range(imx219->pixel_rate, = pixel_rate, > > > pixel_rate, 1, pixel_r= ate); > > > if (ret) >=20 > --=20 > Regards, >=20 > Laurent Pinchart