From: Xiaolei Wang <xiaolei.wang@windriver.com>
To: sakari.ailus@linux.intel.com, tarang.raval@siliconsignals.io,
laurent.pinchart@ideasonboard.com,
dave.stevenson@raspberrypi.com, jacopo@jmondi.org,
mchehab@kernel.org, prabhakar.mahadev-lad.rj@bp.renesas.com,
hverkuil+cisco@kernel.org, johannes.goede@oss.qualcomm.com,
hverkuil-cisco@xs4all.nl, jai.luthra@ideasonboard.com,
Xiaolei.Wang@windriver.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v5 2/3] media: i2c: ov5647: Switch to using the sub-device state lock
Date: Thu, 8 Jan 2026 13:21:58 +0800 [thread overview]
Message-ID: <20260108052159.3879884-3-xiaolei.wang@windriver.com> (raw)
In-Reply-To: <20260108052159.3879884-1-xiaolei.wang@windriver.com>
Switch to using the sub-device state lock and properly call
v4l2_subdev_init_finalize() / v4l2_subdev_cleanup() on probe() /
remove().
Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
Reviewed-by: Tarang Raval <tarang.raval@siliconsignals.io>
---
drivers/media/i2c/ov5647.c | 40 +++++++++++++++++---------------------
1 file changed, 18 insertions(+), 22 deletions(-)
diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 47c0d4485..4660c06de 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -118,7 +118,6 @@ struct ov5647 {
struct v4l2_subdev sd;
struct regmap *regmap;
struct media_pad pad;
- struct mutex lock;
struct clk *xclk;
struct gpio_desc *pwdn;
struct regulator_bulk_data supplies[OV5647_NUM_SUPPLIES];
@@ -686,10 +685,10 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,
static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct ov5647 *sensor = to_sensor(sd);
+ struct v4l2_subdev_state *state;
int ret;
- mutex_lock(&sensor->lock);
+ state = v4l2_subdev_lock_and_get_active_state(sd);
if (enable) {
ret = pm_runtime_resume_and_get(&client->dev);
@@ -710,14 +709,14 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
pm_runtime_put(&client->dev);
}
- mutex_unlock(&sensor->lock);
+ v4l2_subdev_unlock_state(state);
return 0;
error_pm:
pm_runtime_put(&client->dev);
error_unlock:
- mutex_unlock(&sensor->lock);
+ v4l2_subdev_unlock_state(state);
return ret;
}
@@ -785,7 +784,6 @@ static int ov5647_get_pad_fmt(struct v4l2_subdev *sd,
const struct v4l2_mbus_framefmt *sensor_format;
struct ov5647 *sensor = to_sensor(sd);
- mutex_lock(&sensor->lock);
switch (format->which) {
case V4L2_SUBDEV_FORMAT_TRY:
sensor_format = v4l2_subdev_state_get_format(sd_state,
@@ -799,7 +797,6 @@ static int ov5647_get_pad_fmt(struct v4l2_subdev *sd,
*fmt = *sensor_format;
/* The code we pass back must reflect the current h/vflips. */
fmt->code = ov5647_get_mbus_code(sd);
- mutex_unlock(&sensor->lock);
return 0;
}
@@ -817,7 +814,6 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
fmt->width, fmt->height);
/* Update the sensor mode and apply at it at streamon time. */
- mutex_lock(&sensor->lock);
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
*v4l2_subdev_state_get_format(sd_state, format->pad) = mode->format;
} else {
@@ -851,7 +847,6 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
*fmt = mode->format;
/* The code we pass back must reflect the current h/vflips. */
fmt->code = ov5647_get_mbus_code(sd);
- mutex_unlock(&sensor->lock);
return 0;
}
@@ -864,10 +859,8 @@ static int ov5647_get_selection(struct v4l2_subdev *sd,
case V4L2_SEL_TGT_CROP: {
struct ov5647 *sensor = to_sensor(sd);
- mutex_lock(&sensor->lock);
sel->r = *__ov5647_get_pad_crop(sensor, sd_state, sel->pad,
sel->which);
- mutex_unlock(&sensor->lock);
return 0;
}
@@ -960,9 +953,6 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = 0;
-
- /* v4l2_ctrl_lock() locks our own mutex */
-
if (ctrl->id == V4L2_CID_VBLANK) {
int exposure_max, exposure_def;
@@ -1218,8 +1208,6 @@ static int ov5647_probe(struct i2c_client *client)
if (ret)
dev_err_probe(dev, ret, "Failed to get power regulators\n");
- mutex_init(&sensor->lock);
-
sensor->mode = OV5647_DEFAULT_MODE;
sd = &sensor->sd;
@@ -1229,7 +1217,7 @@ static int ov5647_probe(struct i2c_client *client)
ret = ov5647_init_controls(sensor);
if (ret)
- goto mutex_destroy;
+ return ret;
sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
@@ -1252,27 +1240,35 @@ static int ov5647_probe(struct i2c_client *client)
if (ret < 0)
goto power_off;
- ret = v4l2_async_register_subdev_sensor(sd);
- if (ret < 0)
+ sd->state_lock = sensor->ctrls.lock;
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret < 0) {
+ ret = dev_err_probe(dev, ret, "failed to init subdev\n");
goto power_off;
+ }
/* Enable runtime PM and turn off the device */
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
+
+ ret = v4l2_async_register_subdev_sensor(sd);
+ if (ret < 0)
+ goto v4l2_subdev_cleanup;
+
pm_runtime_idle(dev);
dev_dbg(dev, "OmniVision OV5647 camera driver probed\n");
return 0;
+v4l2_subdev_cleanup:
+ v4l2_subdev_cleanup(sd);
power_off:
ov5647_power_off(dev);
entity_cleanup:
media_entity_cleanup(&sd->entity);
ctrl_handler_free:
v4l2_ctrl_handler_free(&sensor->ctrls);
-mutex_destroy:
- mutex_destroy(&sensor->lock);
return ret;
}
@@ -1283,11 +1279,11 @@ static void ov5647_remove(struct i2c_client *client)
struct ov5647 *sensor = to_sensor(sd);
v4l2_async_unregister_subdev(&sensor->sd);
+ v4l2_subdev_cleanup(sd);
media_entity_cleanup(&sensor->sd.entity);
v4l2_ctrl_handler_free(&sensor->ctrls);
v4l2_device_unregister_subdev(sd);
pm_runtime_disable(&client->dev);
- mutex_destroy(&sensor->lock);
}
static const struct dev_pm_ops ov5647_pm_ops = {
--
2.43.0
next prev parent reply other threads:[~2026-01-08 5:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 5:21 [PATCH v5 0/3] media: i2c: ov5647: Modernize driver with CCI and new stream APIs Xiaolei Wang
2026-01-08 5:21 ` [PATCH v5 1/3] media: i2c: ov5647: Convert to CCI register access helpers Xiaolei Wang
2026-01-08 5:21 ` Xiaolei Wang [this message]
2026-01-08 5:21 ` [PATCH v5 3/3] media: i2c: ov5647: switch to {enable,disable}_streams Xiaolei Wang
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=20260108052159.3879884-3-xiaolei.wang@windriver.com \
--to=xiaolei.wang@windriver.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=hverkuil+cisco@kernel.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jacopo@jmondi.org \
--cc=jai.luthra@ideasonboard.com \
--cc=johannes.goede@oss.qualcomm.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=sakari.ailus@linux.intel.com \
--cc=tarang.raval@siliconsignals.io \
/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®