[PATCH 1/3] media: i2c: ov8865: Fix the VTS high byte mask
From: Marco Ziliani
Date: Thu Dec 03 2026 - 12:55:21 EST
OV8865_VTS_H() keeps only bits 11:8 of the frame length, while the VBLANK
control allows frame lengths up to 0xffff lines. Any frame length above
4095 lines therefore wraps around: the sensor gets a much shorter frame
than the driver and userspace believe, and an exposure that can be far
longer than the frame. The frame then stretches to the exposure and the
image is black, or the frame ends up shorter than the active lines and
the stream stalls.
libcamera now sets VBLANK on the IPU3 pipeline and its AGC raises the
exposure up to the frame length, so this is hit in practice: on a
Surface Book 2, with the 800x600 mode, VBLANK 14760 (VTS 15360, 0x3c00)
reached the sensor as 0x0c00 (3072 lines) with an exposure of 15352
lines, and the rear camera went black at 3.75 fps. In the 1632x1224
mode, VBLANK 3769 (VTS 4993) reached it as 897 lines, shorter than the
1224 active lines, and the stream stalled with CSI-2 errors.
The VTS register is 15 bits wide (0x380e bits 6:0 and 0x380f). Keep
bits 14:8 in the high byte and limit the frame length to 0x7fff.
Fixes: 9293aafe3745 ("media: i2c: Add vblank control to ov8865")
Reported-by: irishchug <75328733+irishchug@xxxxxxxxxxxxxxxxxxxxxxxx>
Closes: https://github.com/linux-surface/kernel/pull/181#issuecomment-7234331346
Tested-by: irishchug <75328733+irishchug@xxxxxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Marco Ziliani <rylos78@xxxxxxxxx>
---
drivers/media/i2c/ov8865.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index 5a59cca8e..855da1d04 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -180,10 +180,10 @@
#define OV8865_HTS_L_REG 0x380d
#define OV8865_HTS_L(v) ((v) & GENMASK(7, 0))
#define OV8865_VTS_H_REG 0x380e
-#define OV8865_VTS_H(v) (((v) & GENMASK(11, 8)) >> 8)
+#define OV8865_VTS_H(v) (((v) & GENMASK(14, 8)) >> 8)
#define OV8865_VTS_L_REG 0x380f
#define OV8865_VTS_L(v) ((v) & GENMASK(7, 0))
-#define OV8865_TIMING_MAX_VTS 0xffff
+#define OV8865_TIMING_MAX_VTS 0x7fff
#define OV8865_TIMING_MIN_VTS 0x04
#define OV8865_OFFSET_X_H_REG 0x3810
#define OV8865_OFFSET_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
--
2.56.1