[PATCH v2] media: i2c: ov13858: cap analogue gain at 15.5x

From: Sergey Lebedev

Date: Fri Oct 02 2026 - 05:38:43 EST


The analogue gain control is advertised up to 0x1fff, but the gain only
follows it up to 0x7c0. Measured on raw Bayer at fixed exposure, on a
Surface Pro 11:

register requested measured
1984 15.5x 14.23x
2047 15.99x 13.71x
2048 16x 7.54x
8191 64x 14.28x

At 0x800 the gain halves, and above it the gain repeats values from below
0x800, so an auto exposure loop that raises the gain can get less signal
back. Cap the control at 0x7c0, as ov13b10 and ov08x40 do.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sergey Lebedev <lsa.uz@xxxxx>
---
v2:
- Commit message shortened.
- Assisted-by added, per Documentation/process/coding-assistants.rst.

The code is v1's, byte for byte. Tested on a Surface Pro 11 with
libcamera's software ISP: image quality is unchanged, since 0x7c0 and
0x1fff reach about the same gain.

v1: https://lore.kernel.org/all/20260831180746.68878-1-lsa.uz@xxxxx/

drivers/media/i2c/ov13858.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
index de2b79a9a0e..27273d589cb 100644
--- a/drivers/media/i2c/ov13858.c
+++ b/drivers/media/i2c/ov13858.c
@@ -63,7 +63,7 @@
/* Analog gain control */
#define OV13858_REG_ANALOG_GAIN 0x3508
#define OV13858_ANA_GAIN_MIN 0
-#define OV13858_ANA_GAIN_MAX 0x1fff
+#define OV13858_ANA_GAIN_MAX 0x07c0
#define OV13858_ANA_GAIN_STEP 1
#define OV13858_ANA_GAIN_DEFAULT 0x80

--
2.54.0 (Apple Git-157)