From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-media@vger.kernel.org, hans@jjverkuil.nl,
laurent.pinchart@ideasonboard.com,
Prabhakar <prabhakar.csengg@gmail.com>,
"Kate Hsuan" <hpa@redhat.com>,
"Dave Stevenson" <dave.stevenson@raspberrypi.com>,
"Tommaso Merciai" <tomm.merciai@gmail.com>,
"Benjamin Mugnier" <benjamin.mugnier@foss.st.com>,
"Sylvain Petinot" <sylvain.petinot@foss.st.com>,
"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
"Julien Massot" <julien.massot@collabora.com>,
"Naushir Patuck" <naush@raspberrypi.com>,
"Yan, Dongcheng" <dongcheng.yan@intel.com>,
"Stefan Klug" <stefan.klug@ideasonboard.com>,
"Mirela Rabulea" <mirela.rabulea@nxp.com>,
"André Apitzsch" <git@apitzsch.eu>,
"Heimir Thor Sverrisson" <heimir.sverrisson@gmail.com>,
"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
"Mehdi Djait" <mehdi.djait@linux.intel.com>,
"Ricardo Ribalda Delgado" <ribalda@kernel.org>,
"Hans de Goede" <hansg@kernel.org>,
"Jacopo Mondi" <jacopo.mondi@ideasonboard.com>,
"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>,
"David Plowman" <david.plowman@raspberrypi.com>,
"Yu, Ong Hock" <ong.hock.yu@intel.com>,
"Ng, Khai Wen" <khai.wen.ng@intel.com>,
"Jai Luthra" <jai.luthra@ideasonboard.com>,
"Rishikesh Donadkar" <r-donadkar@ti.com>
Subject: Re: [PATCH v5 06/10] media: imx219: Fix vertical blanking and exposure for analogue binning
Date: Mon, 8 Jun 2026 08:58:46 +0200 [thread overview]
Message-ID: <aiZnQgyEBkZH7er0@zed> (raw)
In-Reply-To: <20260607215356.842932-7-sakari.ailus@linux.intel.com>
Hi Sakari
On Mon, Jun 08, 2026 at 12:53:52AM +0300, Sakari Ailus wrote:
> When vertical analogue binning is in use, the minimum frame length in
> lines decreases to around half of the normal. In relation to the sensor's
> output size this means vertical blanking can be negative but that's not an
> issue as control values are signed. Remove the workaround for this
Didn't we just discussed two weeks ago in media summit how negative
blankings are a bad idea, and of all drivers one could decide to play
with imx219 is probably the worse due it's large use base and the fact
libcamera doesn't support negative blankings ?
Have I missed something ?
> non-issue that doubled the pixel rate, frame length in lines and exposure
> time.
>
> The resulting change also fixes the minimum, the maximum and the step
> values for the control.
>
> Fixes: f513997119f4 ("media: i2c: imx219: Scale the pixel rate for analog binning")
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> drivers/media/i2c/imx219.c | 37 ++++++++++++++-----------------------
> 1 file changed, 14 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index 3aebcbaa3fcd..3cee31758b7e 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -420,15 +420,6 @@ static void imx219_get_binning(struct v4l2_subdev_state *state, u8 *bin_h,
>
> }
>
> -static inline u32 imx219_get_rate_factor(struct v4l2_subdev_state *state)
> -{
> - u8 bin_h, bin_v;
> -
> - imx219_get_binning(state, &bin_h, &bin_v);
> -
> - return (bin_h & bin_v) == IMX219_BINNING_X2_ANALOG ? 2 : 1;
> -}
> -
> /* -----------------------------------------------------------------------------
> * Controls
> */
> @@ -440,19 +431,17 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
> struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
> const struct v4l2_mbus_framefmt *format;
> struct v4l2_subdev_state *state;
> - u32 rate_factor;
> int ret = 0;
>
> state = v4l2_subdev_get_locked_active_state(&imx219->sd);
> format = v4l2_subdev_state_get_format(state, 0);
> - rate_factor = imx219_get_rate_factor(state);
>
> if (ctrl->id == V4L2_CID_VBLANK) {
> int exposure_max, exposure_def;
>
> /* Update max exposure while meeting expected vblanking */
> exposure_max = format->height + ctrl->val -
> - IMX219_EXPOSURE_OFFSET * rate_factor;
> + IMX219_EXPOSURE_OFFSET;
> exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
> exposure_max : IMX219_EXPOSURE_DEFAULT;
> ret = __v4l2_ctrl_modify_range(imx219->exposure,
> @@ -479,7 +468,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
> break;
> case V4L2_CID_EXPOSURE:
> cci_write(imx219->regmap, IMX219_REG_EXPOSURE,
> - ctrl->val / rate_factor, &ret);
> + ctrl->val, &ret);
> break;
> case V4L2_CID_DIGITAL_GAIN:
> cci_write(imx219->regmap, IMX219_REG_DIGITAL_GAIN,
> @@ -496,7 +485,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
> break;
> case V4L2_CID_VBLANK:
> cci_write(imx219->regmap, IMX219_REG_FRM_LENGTH_A,
> - (format->height + ctrl->val) / rate_factor, &ret);
> + format->height + ctrl->val, &ret);
> break;
> case V4L2_CID_HBLANK:
> cci_write(imx219->regmap, IMX219_REG_LINE_LENGTH_A,
> @@ -837,8 +826,8 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
> const struct imx219_mode *mode;
> struct v4l2_mbus_framefmt *format;
> struct v4l2_rect *crop;
> - u8 bin_h, bin_v, bin_hv;
> - int ret;
> + u8 bin_h, bin_v;
> + int ret, bin_hv;
>
> format = v4l2_subdev_state_get_format(state, 0);
>
> @@ -879,23 +868,25 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
> crop->top = (IMX219_NATIVE_HEIGHT - crop->height) / 2;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> - unsigned int rate_factor = imx219_get_rate_factor(state);
> int exposure_max;
> int exposure_def;
> int llp_min;
> int pixel_rate;
>
> /* Update limits and set FPS to default */
> + int vblank_min = ((int)mode->height * (1 - bin_hv) / bin_hv) +
> + IMX219_VBLANK_MIN;
> ret = __v4l2_ctrl_modify_range(imx219->vblank,
> - IMX219_VBLANK_MIN * rate_factor,
> - (IMX219_FLL_MAX - mode->height) *
> - rate_factor, rate_factor,
> - mode->fll_def - mode->height);
> + vblank_min,
> + IMX219_FLL_MAX - mode->height, 1,
> + (int)(mode->fll_def / bin_hv) -
> + (int)mode->height);
> if (ret)
> return ret;
>
> ret = __v4l2_ctrl_s_ctrl(imx219->vblank,
> - mode->fll_def - mode->height);
> + (int)(mode->fll_def / bin_hv) -
> + (int)mode->height);
> if (ret)
> return ret;
>
> @@ -932,7 +923,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
> return ret;
>
> /* Scale the pixel rate based on the mode specific factor */
> - pixel_rate = imx219_get_pixel_rate(imx219) * rate_factor;
> + pixel_rate = imx219_get_pixel_rate(imx219);
> ret = __v4l2_ctrl_modify_range(imx219->pixel_rate, pixel_rate,
> pixel_rate, 1, pixel_rate);
> if (ret)
> --
> 2.47.3
>
>
next prev parent reply other threads:[~2026-06-08 6:58 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-07 21:53 [PATCH v5 00/10] Metadata series preparation Sakari Ailus
2026-06-07 21:53 ` [PATCH v5 01/10] media: Documentation: Improve pixel rate calculation documentation Sakari Ailus
2026-06-07 21:53 ` [PATCH v5 02/10] media: imx219: Scale the vblank limits according to rate_factor Sakari Ailus
2026-06-08 7:26 ` Laurent Pinchart
2026-06-08 15:29 ` Dave Stevenson
2026-06-07 21:53 ` [PATCH v5 03/10] media: imx219: Account rate_factor in setting upper exposure limit Sakari Ailus
2026-06-07 22:05 ` sashiko-bot
2026-06-08 9:06 ` Laurent Pinchart
2026-06-08 13:44 ` Sakari Ailus
2026-06-08 15:42 ` Dave Stevenson
2026-06-07 21:53 ` [PATCH v5 04/10] media: imx219: Make control handler ops for PIXEL_RATE NULL Sakari Ailus
2026-06-08 7:36 ` Laurent Pinchart
2026-06-08 7:53 ` Jacopo Mondi
2026-06-08 8:03 ` Laurent Pinchart
2026-06-08 8:14 ` Sakari Ailus
2026-06-08 8:24 ` Laurent Pinchart
2026-06-08 10:21 ` Sakari Ailus
2026-06-08 10:27 ` Laurent Pinchart
2026-06-08 13:47 ` Sakari Ailus
2026-06-08 14:42 ` Laurent Pinchart
2026-06-07 21:53 ` [PATCH v5 05/10] media: imx219: Rename "binning" as "bin_hv" in imx219_set_pad_format Sakari Ailus
2026-06-08 15:45 ` Dave Stevenson
2026-06-07 21:53 ` [PATCH v5 06/10] media: imx219: Fix vertical blanking and exposure for analogue binning Sakari Ailus
2026-06-07 22:07 ` sashiko-bot
2026-06-08 6:58 ` Jacopo Mondi [this message]
2026-06-08 9:10 ` Laurent Pinchart
2026-06-08 14:07 ` Sakari Ailus
2026-06-08 10:31 ` Jai Luthra
2026-06-08 11:19 ` Jai Luthra
2026-06-07 21:53 ` [PATCH v5 07/10] media: Improve enable_streams and disable_streams documentation Sakari Ailus
2026-06-08 9:29 ` Laurent Pinchart
2026-06-08 14:28 ` Sakari Ailus
2026-06-07 21:53 ` [PATCH v5 08/10] media: v4l2-subdev: Move subdev client capabilities into a new struct Sakari Ailus
2026-06-08 9:34 ` Laurent Pinchart
2026-06-08 14:35 ` Sakari Ailus
2026-06-07 21:53 ` [PATCH v5 09/10] media: v4l2-subdev: Add v4l2_subdev_get_fmt_ci() Sakari Ailus
2026-06-08 7:48 ` Laurent Pinchart
2026-06-07 21:53 ` [PATCH v5 10/10] media: v4l2-subdev: Add struct v4l2_subdev_client_info pointer to pad ops Sakari Ailus
2026-06-08 10:16 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aiZnQgyEBkZH7er0@zed \
--to=jacopo.mondi@ideasonboard.com \
--cc=benjamin.mugnier@foss.st.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dave.stevenson@raspberrypi.com \
--cc=david.plowman@raspberrypi.com \
--cc=dongcheng.yan@intel.com \
--cc=git@apitzsch.eu \
--cc=hans@jjverkuil.nl \
--cc=hansg@kernel.org \
--cc=heimir.sverrisson@gmail.com \
--cc=hpa@redhat.com \
--cc=jai.luthra@ideasonboard.com \
--cc=julien.massot@collabora.com \
--cc=khai.wen.ng@intel.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mehdi.djait@linux.intel.com \
--cc=mirela.rabulea@nxp.com \
--cc=naush@raspberrypi.com \
--cc=ong.hock.yu@intel.com \
--cc=prabhakar.csengg@gmail.com \
--cc=r-donadkar@ti.com \
--cc=ribalda@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=stefan.klug@ideasonboard.com \
--cc=sylvain.petinot@foss.st.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tomm.merciai@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox