]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: atomisp: gc0310: Limit max exposure value to mode-height + vblank
authorHans de Goede <hansg@kernel.org>
Sun, 6 Jul 2025 09:53:53 +0000 (11:53 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 8 Jul 2025 06:43:30 +0000 (08:43 +0200)
When an exposure value > (mode-height + vblank) gets set the sensor will
automatically increase vblank, lowering the framerate.

This is not desirable, limit exposure the maximum exposure to mode-height +
vblank to avoid the unwanted framerate slowdown.

Signed-off-by: Hans de Goede <hansg@kernel.org>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20250517114106.43494-11-hdegoede@redhat.com
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c

index d0e7f0f8452b24e5fa816118910518561ae65870..3e94414be6c79778ad7d5d1fe9bebec912c6affb 100644 (file)
@@ -306,12 +306,27 @@ static int gc0310_gain_set(struct gc0310_device *sensor, u32 gain)
        return ret;
 }
 
+static int gc0310_exposure_update_range(struct gc0310_device *sensor)
+{
+       int exp_max = GC0310_NATIVE_HEIGHT + sensor->ctrls.vblank->val;
+
+       return __v4l2_ctrl_modify_range(sensor->ctrls.exposure, 0, exp_max,
+                                       1, exp_max);
+}
+
 static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl)
 {
        struct gc0310_device *sensor =
                container_of(ctrl->handler, struct gc0310_device, ctrls.handler);
        int ret;
 
+       /* Update exposure range on vblank changes */
+       if (ctrl->id == V4L2_CID_VBLANK) {
+               ret = gc0310_exposure_update_range(sensor);
+               if (ret)
+                       return ret;
+       }
+
        /* Only apply changes to the controls if the device is powered up */
        if (!pm_runtime_get_if_in_use(sensor->sd.dev))
                return 0;
@@ -584,7 +599,7 @@ static int gc0310_init_controls(struct gc0310_device *sensor)
        struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);
        struct v4l2_ctrl_handler *hdl = &sensor->ctrls.handler;
        struct v4l2_fwnode_device_properties props;
-       int ret;
+       int exp_max, ret;
 
        v4l2_ctrl_handler_init(hdl, 8);
 
@@ -592,8 +607,10 @@ static int gc0310_init_controls(struct gc0310_device *sensor)
        hdl->lock = &sensor->input_lock;
        sensor->sd.ctrl_handler = hdl;
 
+       exp_max = GC0310_NATIVE_HEIGHT + GC0310_V_BLANK_DEFAULT;
        sensor->ctrls.exposure =
-               v4l2_ctrl_new_std(hdl, &ctrl_ops, V4L2_CID_EXPOSURE, 0, 4095, 1, 1023);
+               v4l2_ctrl_new_std(hdl, &ctrl_ops, V4L2_CID_EXPOSURE, 0,
+                                 exp_max, 1, exp_max);
 
        /* 32 steps at base gain 1 + 64 half steps at base gain 2 */
        sensor->ctrls.gain =