[PATCH v3 01/12] media: ov8858: Extract digital gain programming

From: Maurizio Casciano

Date: Thu Aug 27 2026 - 19:18:07 EST


Move the existing packed digital-gain register programming into a helper so
clock-specific gain handling can be added separately.

Assisted-by: Codex:gpt-5.6-sol sparse
Signed-off-by: Maurizio Casciano <mauriziocasciano7@xxxxxxxxx>
---
drivers/media/i2c/ov8858.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c
index 3f45f7fab833..d95f034de752 100644
--- a/drivers/media/i2c/ov8858.c
+++ b/drivers/media/i2c/ov8858.c
@@ -1523,6 +1523,23 @@ static int ov8858_enable_test_pattern(struct ov8858 *ov8858, u32 pattern)
return ov8858_write(ov8858, OV8858_REG_TEST_PATTERN, val, NULL);
}

+static int ov8858_set_long_digital_gain(struct ov8858 *ov8858, u32 gain)
+{
+ u16 long_gain;
+
+ /*
+ * Digital gain is assembled as:
+ * 0x350a[7:0] = dgain[13:6]
+ * 0x350b[5:0] = dgain[5:0]
+ * Reassemble the control value to write it in one go.
+ */
+ long_gain = (gain & OV8858_LONG_DIGIGAIN_L_MASK) |
+ ((gain & OV8858_LONG_DIGIGAIN_H_MASK) <<
+ OV8858_LONG_DIGIGAIN_H_SHIFT);
+
+ return ov8858_write(ov8858, OV8858_REG_LONG_DIGIGAIN, long_gain, NULL);
+}
+
static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
{
struct ov8858 *ov8858 = container_of(ctrl->handler,
@@ -1531,7 +1548,6 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
struct v4l2_mbus_framefmt *format;
struct v4l2_subdev_state *state;
- u16 digi_gain;
s64 max_exp;
int ret;

@@ -1570,17 +1586,7 @@ static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
ctrl->val, NULL);
break;
case V4L2_CID_DIGITAL_GAIN:
- /*
- * Digital gain is assembled as:
- * 0x350a[7:0] = dgain[13:6]
- * 0x350b[5:0] = dgain[5:0]
- * Reassemble the control value to write it in one go.
- */
- digi_gain = (ctrl->val & OV8858_LONG_DIGIGAIN_L_MASK)
- | ((ctrl->val & OV8858_LONG_DIGIGAIN_H_MASK) <<
- OV8858_LONG_DIGIGAIN_H_SHIFT);
- ret = ov8858_write(ov8858, OV8858_REG_LONG_DIGIGAIN,
- digi_gain, NULL);
+ ret = ov8858_set_long_digital_gain(ov8858, ctrl->val);
break;
case V4L2_CID_VBLANK:
ret = ov8858_write(ov8858, OV8858_REG_VTS,
--
2.53.0