From 0c2dc9ecc459d9977d4fbdd41f5fd5d42b4c7f5b Mon Sep 17 00:00:00 2001 From: Daniel Scally Date: Thu, 4 Nov 2021 21:46:27 +0000 Subject: [PATCH 1/2] media: i2c: Add integration time margin to ov8865 Without this integration margin to reduce the max exposure, it seems that we trip over a limit that results in the image being entirely black when max exposure is set. Add the margin to prevent this issue. With thanks to jhautbois for spotting and reporting. Signed-off-by: Daniel Scally --- drivers/media/i2c/ov8865.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index d5af8aedf5e8e..966487e32bfe3 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -143,6 +143,7 @@ #define OV8865_EXPOSURE_CTRL_L_REG 0x3502 #define OV8865_EXPOSURE_CTRL_L(v) ((v) & GENMASK(7, 0)) #define OV8865_EXPOSURE_GAIN_MANUAL_REG 0x3503 +#define OV8865_INTEGRATION_TIME_MARGIN 8 #define OV8865_GAIN_CTRL_H_REG 0x3508 #define OV8865_GAIN_CTRL_H(v) (((v) & GENMASK(12, 8)) >> 8) @@ -2462,7 +2463,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl) if (ctrl->id == V4L2_CID_VBLANK) { int exposure_max; - exposure_max = sensor->state.mode->output_size_y + ctrl->val; + exposure_max = sensor->state.mode->output_size_y + ctrl->val - + OV8865_INTEGRATION_TIME_MARGIN; __v4l2_ctrl_modify_range(sensor->ctrls.exposure, sensor->ctrls.exposure->minimum, exposure_max, From 24fe564730576ff884b8f1924c54be545b66824c Mon Sep 17 00:00:00 2001 From: Daniel Scally Date: Thu, 4 Nov 2021 21:48:38 +0000 Subject: [PATCH 2/2] media: i2c: Fix max gain in ov8865 The maximum gain figure in the v4l2 ctrl is wrong. The field is 12 bits wide, which is where the 8191 figure comes from, but the datasheet is specific that maximum gain is 16x (the low seven bits are fractional, so 16x gain is 2048) Signed-off-by: Daniel Scally --- drivers/media/i2c/ov8865.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index 966487e32bfe3..6c78edb65d1e9 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2535,7 +2535,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor) /* Gain */ - v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 8191, 128, + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 128, 128); /* White Balance */