[PATCH 2/3] media: i2c: ov8865: Reset VBLANK on mode change

From: Marco Ziliani

Date: Thu Dec 03 2026 - 12:55:23 EST


set_fmt() updates the VBLANK range and default for the new mode but
keeps the current value when it is still in range. A value left over
from the previous mode then keeps that mode's frame length: after the
full-size mode (VBLANK 22) the 800x600 mode runs faster than its nominal
90 fps, and the VTS a previous user set stays on the sensor for users
that never set VBLANK themselves. On a Surface Book 2, after one run of
libcamera master, which sets VBLANK, a libcamera 0.7.2 run kept that
frame length and ran at 18.8 fps instead of 91 fps.

Set VBLANK to the mode default on every format change on the active
state, as other sensor drivers do.

Fixes: 9293aafe3745 ("media: i2c: Add vblank control to ov8865")
Link: https://github.com/linux-surface/kernel/pull/181#issuecomment-7234331346
Signed-off-by: Marco Ziliani <rylos78@xxxxxxxxx>
---
drivers/media/i2c/ov8865.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index 855da1d04..e85e4c974 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -2756,6 +2756,14 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
OV8865_TIMING_MAX_VTS - mode->output_size_y,
1, mode->vts - mode->output_size_y);

+ /*
+ * Start every mode from its default frame length: a VBLANK value left
+ * over from the previous mode would keep that mode's timing.
+ */
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+ __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank,
+ mode->vts - mode->output_size_y);
+
hblank = mode->hts - mode->output_size_x;
__v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1,
hblank);

--
2.56.1