From: Marco Ziliani <rylos78@gmail.com>
To: Daniel Scally <dan.scally@ideasonboard.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, Chris Simpson <chris@nilk.net>,
Tony Garcia <tony@loafecho.com>,
Simon Kruse <simon0x+git@proton.me>,
"D. Manresa" <dmanresa@gmail.com>,
linux-kernel@vger.kernel.org, Marco Ziliani <rylos78@gmail.com>
Subject: [PATCH v3 2/4] media: i2c: ov5693: Write format and crop changes to a powered sensor
Date: Sat, 28 Nov 2026 00:11:34 +0100 [thread overview]
Message-ID: <20261128-ov5693-fixes-v3-2-bcdd169958b6@gmail.com> (raw)
In-Reply-To: <20261128-ov5693-fixes-v3-0-bcdd169958b6@gmail.com>
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")
Link: https://github.com/linux-surface/kernel/pull/181
Signed-off-by: Marco Ziliani <rylos78@gmail.com>
---
drivers/media/i2c/ov5693.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
index d221f7951..3cab73b89 100644
--- a/drivers/media/i2c/ov5693.c
+++ b/drivers/media/i2c/ov5693.c
@@ -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)
--
2.56.1
next prev parent reply other threads:[~2026-11-27 23:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 23:11 [PATCH v3 0/4] media: i2c: ov5693: Fix mode changes, flips and autosuspend Marco Ziliani
2026-11-27 23:11 ` [PATCH v3 1/4] media: i2c: ov5693: Keep driver-managed registers out of the global list Marco Ziliani
2026-11-27 23:11 ` Marco Ziliani [this message]
2026-11-27 23:11 ` [PATCH v3 3/4] media: i2c: ov5693: Keep the Bayer order when flipping at full resolution Marco Ziliani
2026-11-27 23:11 ` [PATCH v3 4/4] media: i2c: ov5693: Use autosuspend when stopping the stream Marco Ziliani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128-ov5693-fixes-v3-2-bcdd169958b6@gmail.com \
--to=rylos78@gmail.com \
--cc=chris@nilk.net \
--cc=dan.scally@ideasonboard.com \
--cc=dmanresa@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=simon0x+git@proton.me \
--cc=tony@loafecho.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®