[PATCH] fixup! media: i2c: Add ST VD55G0 global shutter sensor driver

From: Sergey Lebedev

Date: Fri Nov 20 2026 - 10:25:28 EST


Sakari's review of v5 2/6:
- name the test patterns as the manual describes them, in the words
other sensor drivers use;
- keep the auto exposure cold start in the exposure controls' current
values, as vd55g1 does, rather than in a copy in the driver;
- no runtime PM reference across probe: autosuspend is set up after
registration, and pm_runtime_idle() ends probe;
- in remove, set the device suspended only when it was not.

Signed-off-by: Sergey Lebedev <lsa.uz@xxxxx>
---
Hi Sakari,

The fixup for v5 2/6, as you suggested. 3/6 to 6/6 do not touch the file.

- The test patterns are named after the manual's table, UM2829, in the
words vd55g1 and the CCS drivers use.
- The cold start is the exposure controls' cur.val now. The first stream
after probe therefore starts from their defaults, 200 lines, where v5's
copy started from 50.
- On the error path only pm_runtime_put_noidle() went:
pm_runtime_disable() and pm_runtime_set_suspended() stay, as in imx219,
since probe sets the device active. The autosuspend delay and
use_autosuspend() moved after registration too. With no reference
held, either call before it would suspend the sensor at once.

Tested on the Surface Pro 11, on 7.4.0-rc1 with KASAN and lockdep:
- probe powers the sensor off after registration, not before;
- v4l2-compliance 46/46, capture at 59.14 fps;
- in every stream the cold start registers equal the controls read
before it: the defaults after probe, then what the last stream left,
manual or auto;
- each test pattern writes v5's PATGEN_CTRL value;
- a failed registration, and unbind, leave the clock and supplies off
without a WARN.

Sergey

Tool use, per Documentation/process/generated-content.rst (Assisted-by
tags in commits were dropped in 7.4-rc1):

* My contributions to this series were prepared with Claude Code
(claude-opus-5-5); work by others in it is their own.
* This replaces any Assisted-by tags in earlier versions.

drivers/media/i2c/vd55g0.c | 65 ++++++++++++++++----------------------
1 file changed, 27 insertions(+), 38 deletions(-)

diff --git a/drivers/media/i2c/vd55g0.c b/drivers/media/i2c/vd55g0.c
index 99bfb05225d..dc1cf48bee6 100644
--- a/drivers/media/i2c/vd55g0.c
+++ b/drivers/media/i2c/vd55g0.c
@@ -726,13 +726,13 @@ static const struct vd55g0_patch vd55g0_patch_cut2 = {

static const char * const vd55g0_test_pattern_menu[] = {
"Disabled",
- "Solid",
- "Colorbar",
- "Gradbar",
- "Hgrey",
- "Vgrey",
- "Dgrey",
- "PN28",
+ "Solid Colour",
+ "Vertical Colour Bars",
+ "Colour Bars With Fade to Grey",
+ "Horizontal Grey Scale",
+ "Vertical Grey Scale",
+ "Diagonal Grey Scale",
+ "Pseudo-random Noise (PN28)",
};

static const s64 vd55g0_ev_bias_menu[] = {
@@ -863,12 +863,6 @@ struct vd55g0_dev {
struct v4l2_ctrl *dgain_ctrl;
};
struct v4l2_ctrl *ae_lock_ctrl;
- /* What the last stream applied, for the next one to start from */
- struct {
- u16 expo;
- u16 digital_gain;
- u8 analog_gain;
- } cold_start;
};

static inline struct vd55g0_dev *to_vd55g0_dev(struct v4l2_subdev *sd)
@@ -1161,16 +1155,20 @@ vd55g0_try_fmt(struct v4l2_mbus_framefmt *fmt)
return mode;
}

+/* The auto exposure starts from the exposure controls' current values */
static int vd55g0_apply_cold_start(struct vd55g0_dev *sensor)
{
+ /* A range change under auto exposure did not clamp it */
+ u32 expo = min_t(s64, sensor->expo_ctrl->cur.val,
+ sensor->expo_ctrl->maximum);
int ret = 0;

- vd55g0_write(sensor, VD55G0_REG_AE_COLDSTART_COARSE_EXPOSURE,
- sensor->cold_start.expo, &ret);
+ vd55g0_write(sensor, VD55G0_REG_AE_COLDSTART_COARSE_EXPOSURE, expo,
+ &ret);
vd55g0_write(sensor, VD55G0_REG_AE_COLDSTART_ANALOG_GAIN,
- sensor->cold_start.analog_gain, &ret);
+ sensor->again_ctrl->cur.val, &ret);
vd55g0_write(sensor, VD55G0_REG_AE_COLDSTART_DIGITAL_GAIN,
- sensor->cold_start.digital_gain, &ret);
+ sensor->dgain_ctrl->cur.val, &ret);

return ret;
}
@@ -1288,11 +1286,12 @@ static void vd55g0_save_exposure(struct vd55g0_dev *sensor)
/* On a read error, keep what the previous stream left */
if (!vd55g0_read(sensor, VD55G0_REG_APPLIED_COARSE_EXPOSURE, &val,
NULL))
- sensor->cold_start.expo = val;
+ sensor->expo_ctrl->cur.val = min_t(u64, val,
+ sensor->expo_ctrl->maximum);
if (!vd55g0_read(sensor, VD55G0_REG_APPLIED_DIGITAL_GAIN, &val, NULL))
- sensor->cold_start.digital_gain = val;
+ sensor->dgain_ctrl->cur.val = val;
if (!vd55g0_read(sensor, VD55G0_REG_APPLIED_ANALOG_GAIN, &val, NULL))
- sensor->cold_start.analog_gain = val;
+ sensor->again_ctrl->cur.val = val;
}

static void vd55g0_stream_disable(struct vd55g0_dev *sensor)
@@ -1693,14 +1692,9 @@ static int vd55g0_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
u64 expo, again, dgain;
int ret = 0;

- /* Unpowered: the last stream's values, the next one's start */
- if (!pm_runtime_get_if_in_use(dev)) {
- sensor->expo_ctrl->val = min_t(u32, sensor->cold_start.expo,
- sensor->expo_ctrl->maximum);
- sensor->again_ctrl->val = sensor->cold_start.analog_gain;
- sensor->dgain_ctrl->val = sensor->cold_start.digital_gain;
+ /* Unpowered: the current values, which the last stream left */
+ if (!pm_runtime_get_if_in_use(dev))
return 0;
- }

vd55g0_read(sensor, VD55G0_REG_APPLIED_COARSE_EXPOSURE, &expo, &ret);
vd55g0_read(sensor, VD55G0_REG_APPLIED_ANALOG_GAIN, &again, &ret);
@@ -2066,9 +2060,6 @@ static int vd55g0_probe(struct i2c_client *client)
if (IS_ERR(sensor->regmap))
return dev_err_probe(&client->dev, PTR_ERR(sensor->regmap),
"failed to init CCI\n");
- sensor->cold_start.expo = 0x32;
- sensor->cold_start.digital_gain = 256;
- sensor->cold_start.analog_gain = 0;

handle = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0);

@@ -2140,12 +2131,8 @@ static int vd55g0_probe(struct i2c_client *client)
goto error_media_entity;
}

- /* Held until registered, so that runtime PM cannot power it down */
pm_runtime_set_active(dev);
- pm_runtime_get_noresume(dev);
pm_runtime_enable(dev);
- pm_runtime_set_autosuspend_delay(dev, 1000);
- pm_runtime_use_autosuspend(dev);

ret = v4l2_async_register_subdev_sensor(&sensor->sd);
if (ret) {
@@ -2153,7 +2140,9 @@ static int vd55g0_probe(struct i2c_client *client)
goto error_pm_runtime;
}

- pm_runtime_put_autosuspend(dev);
+ pm_runtime_set_autosuspend_delay(dev, 1000);
+ pm_runtime_use_autosuspend(dev);
+ pm_runtime_idle(dev);

dev_dbg(&client->dev, "vd55g0 probe successfully\n");

@@ -2167,7 +2156,6 @@ static int vd55g0_probe(struct i2c_client *client)
error_pm_runtime:
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
- pm_runtime_put_noidle(dev);
v4l2_subdev_cleanup(&sensor->sd);
error_media_entity:
media_entity_cleanup(&sensor->sd.entity);
@@ -2190,9 +2178,10 @@ static void vd55g0_remove(struct i2c_client *client)
v4l2_ctrl_handler_free(sensor->sd.ctrl_handler);

pm_runtime_disable(&client->dev);
- if (!pm_runtime_status_suspended(&client->dev))
+ if (!pm_runtime_status_suspended(&client->dev)) {
vd55g0_power_off(&client->dev);
- pm_runtime_set_suspended(&client->dev);
+ pm_runtime_set_suspended(&client->dev);
+ }
}

static const struct of_device_id vd55g0_dt_ids[] = {
--
2.54.0