Skip to contentSkip to conversation

media: i2c: ov5693: Fix mode changes, flips and autosuspend

PATCH In review Marco Ziliani 2 participants 7 messages Nov 27 – Dec 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover media: i2c: ov5693: Fix mode changes, flips and autosuspend

Fixes for the ov5693, found while getting the front camera of the Microsoft Surface Pro 5 (IPU3) to work, and since tested on IPU6 and IPU4P Surfaces as well.

Patch 1 drops the registers that the driver programs itself from the global register list, as Sakari asked in the v2 review: the low byte of the analogue gain and the FORMAT1/FORMAT2 registers. The driver now writes the non-flip bits of FORMAT1/FORMAT2 in full.

Patch 2 writes format and crop changes to the sensor when it is powered, on top of the write at power-on, so that a format change also reaches a sensor that stays powered between streams (autosuspend delay, runtime PM disabled). Changes on the active state are refused with -EBUSY while streaming.

Patch 3 keeps the reported SBGGR10 order when a single flip is enabled at full resolution: each flip moves the Bayer phase by one column, so the output window is shifted by one column when hflip XOR vflip.

Patch 4 drops the usage count at stream stop with pm_runtime_put_autosuspend(), so that the autosuspend delay counts from stream stop rather than from the last resume.

The patches come from the linux-surface tree [1]. This version was tested on a Surface Pro 5 (IPU3), with the media next driver plus this series built for the running kernel: the full-resolution Bayer order is stable with all four flip combinations, 16 changes between 2592x1944 and a 1920x1080 crop with the sensor kept powered all stream the new format, a format set during the autosuspend delay reaches the sensor at once (OUTPUT_SIZE_X read back over I2C), set_fmt() while streaming returns -EBUSY, and the sensor suspends 1.16 s after stream stop with the default 1 s delay.

I used an AI coding assistant to draft these patches and the changelogs; I reviewed them and can answer for them.

[1] https://github.com/linux-surface/kernel/pull/181

---
Changes in v3:
- New patch 1: keep the registers the driver programs out of the global register list (Sakari)
- Patch 2 (was 1): write the mode registers on power-on as before and
from set_fmt()/set_selection() when the sensor is powered, instead of
on every stream start; return -EBUSY for active format and crop
changes while streaming (Sakari). Tested-by tags dropped, since the
code changed
- Patch 3 (was 2): unchanged; the window offset vs V4L2_CTRL_FLAG_MODIFY_LAYOUT question from v1 is still open (Dan)
- Patch 4 (was 3): changelog updated for the new patch 2
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Patch 1: move ov5693_mode_configure() from ov5693_sensor_init() to ov5693_s_stream() rather than calling it in both, and shorten the
commit message (Dan)
- Patch 1: Tested-by tags not carried over, since the code changed
- Patch 2: unchanged; whether to shift the window or to use V4L2_CTRL_FLAG_MODIFY_LAYOUT is still being discussed on v1, happy
to switch if that is preferred (Dan)
- Patches 2 and 3: collected Reviewed-by and Tested-by tags
- Retested the series on the Surface Pro 5 (IPU3)
- Link to v1: https://patch.msgid.link/[email protected]

---
Marco Ziliani (4):
media: i2c: ov5693: Keep driver-managed registers out of the global list
media: i2c: ov5693: Write format and crop changes to a powered sensor
media: i2c: ov5693: Keep the Bayer order when flipping at full resolution
media: i2c: ov5693: Use autosuspend when stopping the stream

 drivers/media/i2c/ov5693.c | 131 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 106 insertions(+), 25 deletions(-)

---
base-commit: d7e7bca7169873b46e857c025c10f3336c1258d8
change-id: 20261027-ov5693-fixes-8ec29752893a

Best regards,

Signature · 1 line
Marco Ziliani <[email protected]>
#1 lore raw

PATCH v3 1/4 media: i2c: ov5693: Keep driver-managed registers out of the global list

ov5693_global_regs writes three registers that the driver also programs:
0x350b, the low byte of the analogue gain set by the gain control, and FORMAT1/FORMAT2 (0x3820/0x3821), whose binning and flip bits follow the format and the flip controls. The values from the list are overwritten anyway, so the overlap only hides which code owns those registers.

Drop the three entries. Program the FORMAT registers in full from ov5693_mode_configure() instead, except for the flip bits, which stay with the flip controls. That keeps the values the list used to write:
0x00 for FORMAT1, and bits 4:3 of FORMAT2, which the vendor sequence sets and whose purpose isn't documented.

---
 drivers/media/i2c/ov5693.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/media/i2c/ov5693.c +16 -11
index 56599f9ca..d221f7951 100644
@@ -94,11 +94,17 @@
 #define OV5693_FORMAT1_FLIP_VERT_ISP_EN		BIT(6)
 #define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN	BIT(1)
 #define OV5693_FORMAT1_VBIN_EN			BIT(0)
+#define OV5693_FORMAT1_FLIP_VERT_MASK		(OV5693_FORMAT1_FLIP_VERT_ISP_EN | \
+						 OV5693_FORMAT1_FLIP_VERT_SENSOR_EN)
 #define OV5693_FORMAT2_REG			CCI_REG8(0x3821)
 #define OV5693_FORMAT2_HDR_EN			BIT(7)
 #define OV5693_FORMAT2_FLIP_HORZ_ISP_EN		BIT(2)
 #define OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN	BIT(1)
 #define OV5693_FORMAT2_HBIN_EN			BIT(0)
+#define OV5693_FORMAT2_FLIP_HORZ_MASK		(OV5693_FORMAT2_FLIP_HORZ_ISP_EN | \
+						 OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN)
+/* Set by the vendor initialisation sequence, purpose undocumented */
+#define OV5693_FORMAT2_VENDOR_BITS		GENMASK(4, 3)
 
 #define OV5693_ISP_CTRL2_REG			CCI_REG8(0x5002)
 #define OV5693_ISP_SCALE_ENABLE			BIT(7)
@@ -203,7 +209,6 @@ static const struct cci_reg_sequence ov5693_global_regs[] = {
 	{CCI_REG8(0x3106), 0x00},
 	{CCI_REG8(0x3406), 0x01},
 	{CCI_REG8(0x3503), 0x07},
-	{CCI_REG8(0x350b), 0x40},
 	{CCI_REG8(0x3601), 0x0a},
 	{CCI_REG8(0x3602), 0x38},
 	{CCI_REG8(0x3612), 0x80},
@@ -322,8 +327,6 @@ static const struct cci_reg_sequence ov5693_global_regs[] = {
 	{CCI_REG8(0x5848), 0x01},
 	{CCI_REG8(0x5849), 0x0c},
 	{CCI_REG8(0x5e10), 0x0c},
-	{CCI_REG8(0x3820), 0x00},
-	{CCI_REG8(0x3821), 0x1e},
 	{CCI_REG8(0x5041), 0x14}
 };
 
@@ -364,8 +367,7 @@ static const u8 ov5693_test_pattern_bits[] = {
 static int ov5693_flip_vert_configure(struct ov5693_device *ov5693,
 				      bool enable)
 {
-	u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN |
-		  OV5693_FORMAT1_FLIP_VERT_SENSOR_EN;
+	u8 bits = OV5693_FORMAT1_FLIP_VERT_MASK;
 	int ret;
 
 	ret = cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, bits,
@@ -379,8 +381,7 @@ static int ov5693_flip_vert_configure(struct ov5693_device *ov5693,
 static int ov5693_flip_horz_configure(struct ov5693_device *ov5693,
 				      bool enable)
 {
-	u8 bits = OV5693_FORMAT2_FLIP_HORZ_ISP_EN |
-		  OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN;
+	u8 bits = OV5693_FORMAT2_FLIP_HORZ_MASK;
 	int ret;
 
 	ret = cci_update_bits(ov5693->regmap, OV5693_FORMAT2_REG, bits,
@@ -603,14 +604,18 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693)
 	cci_write(ov5693->regmap, OV5693_SUB_INC_Y_REG,
 		  ((mode->inc_y_odd << 4) & 0xf0) | 0x01, &ret);
 
-	/* Binning */
+	/*
+	 * Binning. Program all the bits of the FORMAT registers except the
+	 * flips, which follow the flip controls.
+	 */
 	cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG,
-			OV5693_FORMAT1_VBIN_EN,
+			GENMASK(7, 0) & ~OV5693_FORMAT1_FLIP_VERT_MASK,
 			mode->binning_y ? OV5693_FORMAT1_VBIN_EN : 0, &ret);
 
 	cci_update_bits(ov5693->regmap, OV5693_FORMAT2_REG,
-			OV5693_FORMAT2_HBIN_EN,
-			mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0, &ret);
+			GENMASK(7, 0) & ~OV5693_FORMAT2_FLIP_HORZ_MASK,
+			OV5693_FORMAT2_VENDOR_BITS |
+			(mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0), &ret);
 
 	return ret;
 }
Signature · 1 line
2.56.1
#2 lore raw

PATCH v3 2/4 media: i2c: ov5693: Write format and crop changes to a powered sensor

In reply to Marco Ziliani

ov5693_mode_configure() is only called on power-on, from ov5693_sensor_init(). If the sensor stays powered between two streams with different formats, for instance during the runtime PM autosuspend delay or with runtime PM disabled, the registers for the second format are never written and the sensor keeps streaming the first one.

Keep writing the mode registers on power-on, and also write them from set_fmt() and set_selection() on the active state when the sensor is powered. pm_runtime_get_if_active() is used rather than pm_runtime_get_if_in_use() so that a change made during the autosuspend delay is written too.

Writing them while streaming would change the readout under the receiver, so refuse format and crop changes on the active state with -EBUSY while the sensor streams. set_fmt() and set_selection() now take the driver lock for the whole operation.

Fixes 89aef879cb53 ("media: i2c: Add support for ov5693 sensor")
---
 drivers/media/i2c/ov5693.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 5 deletions(-)
drivers/media/i2c/ov5693.c +41 -5
index d221f7951..3cab73b89 100644
@@ -168,6 +168,9 @@ struct ov5693_device {
 		unsigned int vts;
 	} mode;
 
+	/* Protected by lock */
+	bool streaming;
+
 	struct v4l2_subdev sd;
 	struct media_pad pad;
 
@@ -832,6 +835,27 @@ static int ov5693_get_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
+/*
+ * Program a new format or crop rectangle on a powered sensor. A sensor that is
+ * powered off gets it at the next power-on, from ov5693_sensor_init().
+ */
+static int ov5693_mode_update(struct ov5693_device *ov5693)
+{
+	int pm, ret;
+
+	pm = pm_runtime_get_if_active(ov5693->dev);
+	if (!pm)
+		return 0;
+
+	ret = ov5693_mode_configure(ov5693);
+
+	/* A negative value means runtime PM is disabled, with the sensor on */
+	if (pm > 0)
+		pm_runtime_put(ov5693->dev);
+
+	return ret;
+}
+
 static int ov5693_set_fmt(struct v4l2_subdev *sd,
 			  const struct v4l2_subdev_client_info *ci,
 			  struct v4l2_subdev_state *state,
@@ -845,6 +869,11 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
 	unsigned int hblank;
 	int exposure_max;
 
+	guard(mutex)(&ov5693->lock);
+
+	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE && ov5693->streaming)
+		return -EBUSY;
+
 	crop = __ov5693_get_pad_crop(ov5693, state, format->pad, format->which);
 
 	/*
@@ -877,8 +906,6 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
 	if (format->which == V4L2_SUBDEV_FORMAT_TRY)
 		return 0;
 
-	mutex_lock(&ov5693->lock);
-
 	ov5693->mode.binning_x = hratio > 1;
 	ov5693->mode.inc_x_odd = hratio > 1 ? 3 : 1;
 	ov5693->mode.binning_y = vratio > 1;
@@ -904,8 +931,7 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
 				 min(ov5693->ctrls.exposure->val,
 				     exposure_max));
 
-	mutex_unlock(&ov5693->lock);
-	return 0;
+	return ov5693_mode_update(ov5693);
 }
 
 static int ov5693_get_selection(struct v4l2_subdev *sd,
@@ -955,6 +981,11 @@ static int ov5693_set_selection(struct v4l2_subdev *sd,
 	if (sel->target != V4L2_SEL_TGT_CROP)
 		return -EINVAL;
 
+	guard(mutex)(&ov5693->lock);
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE && ov5693->streaming)
+		return -EBUSY;
+
 	/*
 	 * Clamp the boundaries of the crop rectangle to the size of the sensor
 	 * pixel array. Align to multiples of 2 to ensure Bayer pattern isn't
@@ -991,7 +1022,10 @@ static int ov5693_set_selection(struct v4l2_subdev *sd,
 	*__crop = rect;
 	sel->r = rect;
 
-	return 0;
+	if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
+		return 0;
+
+	return ov5693_mode_update(ov5693);
 }
 
 static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
@@ -1012,10 +1046,12 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
 		}
 
 		ret = ov5693_enable_streaming(ov5693, true);
+		ov5693->streaming = !ret;
 		mutex_unlock(&ov5693->lock);
 	} else {
 		mutex_lock(&ov5693->lock);
 		ret = ov5693_enable_streaming(ov5693, false);
+		ov5693->streaming = false;
 		mutex_unlock(&ov5693->lock);
 	}
 	if (ret)
Signature · 1 line
2.56.1
#3 lore raw

PATCH v3 3/4 media: i2c: ov5693: Keep the Bayer order when flipping at full resolution

In reply to Marco Ziliani

In the full (unbinned) readout each of the horizontal and vertical flips moves the Bayer phase by one column. With exactly one flip enabled the CSI-2 receiver gets GBRG instead of the SBGGR10 the driver reports, which gives a magenta and green image; with both enabled the two shifts cancel out.

The crop start is only honoured in steps of two pixels, so compensate by shifting the output window by one column when hflip XOR vflip, and widen the crop by two columns, within the pixel array, so that the window still fits. Reprogram the window when either flip changes. The binned readout is left unchanged.

With this change, raw 2592x1944 frames come out BGGR at all four hflip/vflip settings on the Surface Pro 5 (IPU3); the same change in the linux-surface tree gave BGGR at all four settings on a Surface Pro 7 (IPU4P) and a Surface Pro 9 (IPU6). Without it, the order is only right with both flips off or both on.

Fixes 89aef879cb53 ("media: i2c: Add support for ov5693 sensor")
---
 drivers/media/i2c/ov5693.c | 56 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 8 deletions(-)
drivers/media/i2c/ov5693.c +48 -8
index 3cab73b89..6e76e289f 100644
@@ -367,6 +367,49 @@ static const u8 ov5693_test_pattern_bits[] = {
 
 /* V4L2 Controls Functions */
 
+/*
+ * In the full (unbinned) readout each flip moves the Bayer phase by one
+ * column, so with exactly one of them enabled the CSI-2 receiver gets GBRG
+ * instead of the SBGGR10 the driver reports; with both enabled the two shifts
+ * cancel out. The crop start is only honoured in steps of two pixels, so
+ * compensate by shifting the output window by one column instead, and widen
+ * the crop so that the window still fits.
+ */
+static bool ov5693_bayer_shift(struct ov5693_device *ov5693)
+{
+	const struct ov5693_mode *mode = &ov5693->mode;
+	bool hflip, vflip;
+
+	if (mode->binning_x || mode->binning_y)
+		return false;
+
+	hflip = ov5693->ctrls.hflip && ov5693->ctrls.hflip->val;
+	vflip = ov5693->ctrls.vflip && ov5693->ctrls.vflip->val;
+
+	return hflip ^ vflip;
+}
+
+static int ov5693_window_x_configure(struct ov5693_device *ov5693)
+{
+	const struct ov5693_mode *mode = &ov5693->mode;
+	bool shift = ov5693_bayer_shift(ov5693);
+	u32 crop_end = mode->crop.left + mode->crop.width;
+	int ret = 0;
+
+	/* Widen the crop for the shifted window, within the pixel array */
+	if (shift)
+		crop_end = min(crop_end + 2,
+			       max_t(u32, crop_end, OV5693_NATIVE_WIDTH - 1));
+
+	/* Offset X */
+	cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, shift, &ret);
+
+	/* Crop End X */
+	cci_write(ov5693->regmap, OV5693_CROP_END_X_REG, crop_end, &ret);
+
+	return ret;
+}
+
 static int ov5693_flip_vert_configure(struct ov5693_device *ov5693,
 				      bool enable)
 {
@@ -378,7 +421,7 @@ static int ov5693_flip_vert_configure(struct ov5693_device *ov5693,
 	if (ret)
 		return ret;
 
-	return 0;
+	return ov5693_window_x_configure(ov5693);
 }
 
 static int ov5693_flip_horz_configure(struct ov5693_device *ov5693,
@@ -392,7 +435,7 @@ static int ov5693_flip_horz_configure(struct ov5693_device *ov5693,
 	if (ret)
 		return ret;
 
-	return 0;
+	return ov5693_window_x_configure(ov5693);
 }
 
 static int ov5693_get_exposure(struct ov5693_device *ov5693, s32 *value)
@@ -570,16 +613,13 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693)
 	cci_write(ov5693->regmap, OV5693_CROP_START_X_REG, mode->crop.left,
 		  &ret);
 
-	/* Offset X */
-	cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, 0, &ret);
-
 	/* Output Size X */
 	cci_write(ov5693->regmap, OV5693_OUTPUT_SIZE_X_REG, mode->format.width,
 		  &ret);
 
-	/* Crop End X */
-	cci_write(ov5693->regmap, OV5693_CROP_END_X_REG,
-		  mode->crop.left + mode->crop.width, &ret);
+	/* Offset X and Crop End X follow the flips, see ov5693_bayer_shift() */
+	if (!ret)
+		ret = ov5693_window_x_configure(ov5693);
 
 	/* Horizontal Total Size */
 	cci_write(ov5693->regmap, OV5693_TIMING_HTS_REG, OV5693_FIXED_PPL,
Signature · 1 line
2.56.1
#4 lore raw

PATCH v3 4/4 media: i2c: ov5693: Use autosuspend when stopping the stream

In reply to Marco Ziliani

The driver enables runtime PM autosuspend with a 1 second delay at probe, but drops the usage count at stream stop with pm_runtime_put(), which doesn't update the device's last busy time. The autosuspend delay is then counted from the runtime resume at stream start rather than from stream stop, so after any stream longer than the delay the sensor is powered off right away.

Use pm_runtime_put_autosuspend(), which marks the device busy, so that the delay counts from stream stop as intended, and a following stream started within it doesn't power the sensor up from scratch again. Now that format changes are written to a powered sensor, keeping it powered between streams no longer leaves it in a stale mode.

On a Surface Pro 9 (IPU6) with autosuspend_delay_ms set to 3000, the sensor suspended 1-2 ms after a 5 s stream stopped; with this change, 3.7 s after it, i.e. the delay plus the autosuspend timer slack. On a Surface Pro 5 (IPU3) with the default 1 s delay, the sensor suspended as soon as a 2 s stream stopped; with this change, 1.1 s after it.

---
 drivers/media/i2c/ov5693.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov5693.c +1 -1
index 6e76e289f..5c64ae063 100644
@@ -1098,7 +1098,7 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
 		goto err_power_down;
 
 	if (!enable)
-		pm_runtime_put(ov5693->dev);
+		pm_runtime_put_autosuspend(ov5693->dev);
 
 	return 0;
 err_power_down:
Signature · 1 line
2.56.1
Tested-by on the v3 series
#5 lore raw
In reply to Marco Ziliani

Hi Marco,

Tested v3 on a Surface Pro 7 (Ice Lake). Its front OV5693 sits behind an IPU4P, which I run with ruslanbay's IPU4P-on-IPU6 RFC series on linux-surface 7.3.0-rc7. The four patches were applied to the 7.3 ov5693.c. One hunk of patch 2 needed a context-only fix, because set_fmt() has no client_info argument on 7.3; the added ov5693_mode_update() is unchanged and the diff is still 106+/25-. Raw capture from the ISYS video node with v4l2-ctl, frames saved and checked buffer by buffer, no libcamera. Each of the tests below was also run on the unpatched 7.3 driver as a control.

Patch 2, format changes on a powered sensor: with the sensor held powered (power/control=on), 8 changes from 2592x1944 to a centred 1920x1080 crop and 8 back. OUTPUT_SIZE_X/Y (0x3808/0x380a) read over I2C during each stream matched 16 of 16 times and all 16 streams delivered frames. Unpatched: 0x3808 stayed at 2592 after each of 3 changes to the crop and none of those streams produced a frame.

Patch 2, during the autosuspend delay: with autosuspend_delay_ms set to 3000, I set the other format on the sensor pad right after a stream stopped and read 0x3808/0x380a about 50 ms later, with no stream running. 6 of 6 showed the new size, the sensor active before and after. Unpatched, same test: 0 of 6, the registers kept the old size.

Patch 2, -EBUSY: 1 s into a 90-frame stream, VIDIOC_SUBDEV_S_FMT (1296x972) and VIDIOC_SUBDEV_S_SELECTION (the 1920x1080 crop) on the active state both failed with EBUSY, 3 of 3 runs. The active format and crop were unchanged and the streams carried on normally. Unpatched, both calls returned 0 and the stream broke up (CSI-2 FIFO overflow and frame sync errors).

Patch 3, flips: 2592x1944 at all four hflip/vflip settings. The sensor reported SBGGR10 and the 2x2 sub-plane test found the green pair on the BGGR/RGGB diagonal in all four. Unpatched it moved to the GBRG/GRBG diagonal at both single-flip settings. Image profiles against hflip=0/vflip=0 confirmed the three flipped settings really mirrored the image. One caveat: the room was dark, so I raised exposure and gain for this, and I couldn't check the blue/red order this time as I did on v1.

Patch 4, autosuspend at stream stop: after a 60-frame stream the sensor was suspended at the 1.1 s sample in one run and the 1.3 s sample in two (100 ms sampling, default 1 s delay). Unpatched it was already suspended at the first sample, 3 of 3.

Patch 1 has no test of its own, but everything above ran with it applied. The first buffer of a stream was often partly empty, with and without the series, so that's not from these patches.

One more thing I ran into, which is not caused by this series:
VIDIOC_SUBDEV_S_FMT with which=TRY oopses with a divide error in ov5693_set_fmt(), e.g. "v4l2-ctl -d /dev/v4l-subdevN --try-subdev-fmt pad=0,width=1296,height=972". I hit it with this series and also with the 7.3 driver I normally run, which doesn't have patch 2. I didn't run it on the pure stock build, but the code there is the same. The driver has no init_state, so I think the TRY crop is 0x0, width gets clamped to 0 and DIV_ROUND_CLOSEST(crop->width, width) divides by it. It matters a bit more with patch 2 though: set_fmt() now holds the lock through guard(mutex) when the oops hits, so afterwards stream stop and get_selection hang and the module can't be unloaded until a reboot. With my usual driver the camera kept working after the oops. Since you're in this function anyway, an init_state that sets the default crop and format might fit in v4. Happy to test it.

The tests were scripted and run on my Surface Pro 7 by an AI coding assistant (Claude) at my direction, and it drafted this summary.

For the series, on the Surface Pro 7 (IPU4P):

#6 lore raw

Hi Tony,

Quoted 3 lines · Tony Garcia

VIDIOC_SUBDEV_S_FMT with which=TRY oopses with a divide error in ov5693_set_fmt(), e.g. "v4l2-ctl -d /dev/v4l-subdevN --try-subdev-fmt pad=0,width=1296,height=972".

Thanks a lot for testing v3 so thoroughly, and for this one. Your analysis is right: with no init_state the try crop is 0x0. v4 will add an init_state that sets the default crop and format, as a separate patch at the start of the series with your Reported-by, so it can also go to stable on its own. With it, --try-subdev-fmt returns the clamped format here on the Surface Pro 5 instead of oopsing.

v4 will also fix one edge case in patch 3: with a full-width crop that already reaches the right edge of the pixel array and a single flip, the window couldn't be widened and the stream broke. It now moves the crop start two columns to the left instead.

I'll send v4 once Sakari and Dan have had a chance to look at v3.

Thanks,
Marco