Skip to content

Commit cf72adb

Browse files
jailuthrapelwell
authored andcommitted
media: imx355: Use subdev active state
commit df3ef05 upstream. Port the driver to use the subdev active state. This simplifies locking, and makes it easier to support different crop sizes for binned modes, by storing the crop rectangle inside the subdev state. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
1 parent c7bef75 commit cf72adb

File tree

1 file changed

+21
-58
lines changed

1 file changed

+21
-58
lines changed

drivers/media/i2c/imx335.c

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ struct imx335_mode {
204204
* @vblank: Vertical blanking in lines
205205
* @lane_mode: Mode for number of connected data lanes
206206
* @cur_mode: Pointer to current selected sensor mode
207-
* @mutex: Mutex for serializing sensor controls
208207
* @link_freq_bitmap: Menu bitmap for link_freq_ctrl
209208
* @cur_mbus_code: Currently selected media bus format code
210209
*/
@@ -231,7 +230,6 @@ struct imx335 {
231230
u32 vblank;
232231
u32 lane_mode;
233232
const struct imx335_mode *cur_mode;
234-
struct mutex mutex;
235233
unsigned long link_freq_bitmap;
236234
u32 cur_mbus_code;
237235
};
@@ -766,36 +764,6 @@ static void imx335_fill_pad_format(struct imx335 *imx335,
766764
fmt->format.xfer_func = V4L2_XFER_FUNC_NONE;
767765
}
768766

769-
/**
770-
* imx335_get_pad_format() - Get subdevice pad format
771-
* @sd: pointer to imx335 V4L2 sub-device structure
772-
* @sd_state: V4L2 sub-device configuration
773-
* @fmt: V4L2 sub-device format need to be set
774-
*
775-
* Return: 0 if successful, error code otherwise.
776-
*/
777-
static int imx335_get_pad_format(struct v4l2_subdev *sd,
778-
struct v4l2_subdev_state *sd_state,
779-
struct v4l2_subdev_format *fmt)
780-
{
781-
struct imx335 *imx335 = to_imx335(sd);
782-
783-
mutex_lock(&imx335->mutex);
784-
785-
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
786-
struct v4l2_mbus_framefmt *framefmt;
787-
788-
framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
789-
fmt->format = *framefmt;
790-
} else {
791-
imx335_fill_pad_format(imx335, imx335->cur_mode, fmt);
792-
}
793-
794-
mutex_unlock(&imx335->mutex);
795-
796-
return 0;
797-
}
798-
799767
/**
800768
* imx335_set_pad_format() - Set subdevice pad format
801769
* @sd: pointer to imx335 V4L2 sub-device structure
@@ -809,32 +777,28 @@ static int imx335_set_pad_format(struct v4l2_subdev *sd,
809777
struct v4l2_subdev_format *fmt)
810778
{
811779
struct imx335 *imx335 = to_imx335(sd);
780+
struct v4l2_mbus_framefmt *format;
812781
const struct imx335_mode *mode;
813782
int i, ret = 0;
814783

815-
mutex_lock(&imx335->mutex);
816-
817784
mode = &supported_mode;
785+
818786
for (i = 0; i < ARRAY_SIZE(imx335_mbus_codes); i++) {
819787
if (imx335_mbus_codes[i] == fmt->format.code)
820788
imx335->cur_mbus_code = imx335_mbus_codes[i];
821789
}
822790

823791
imx335_fill_pad_format(imx335, mode, fmt);
824792

825-
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
826-
struct v4l2_mbus_framefmt *framefmt;
793+
format = v4l2_subdev_state_get_format(sd_state, fmt->pad);
794+
*format = fmt->format;
827795

828-
framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
829-
*framefmt = fmt->format;
830-
} else {
796+
if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
831797
ret = imx335_update_controls(imx335, mode);
832798
if (!ret)
833799
imx335->cur_mode = mode;
834800
}
835801

836-
mutex_unlock(&imx335->mutex);
837-
838802
return ret;
839803
}
840804

@@ -854,12 +818,10 @@ static int imx335_init_state(struct v4l2_subdev *sd,
854818
fmt.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
855819
imx335_fill_pad_format(imx335, &supported_mode, &fmt);
856820

857-
mutex_lock(&imx335->mutex);
858821
__v4l2_ctrl_modify_range(imx335->link_freq_ctrl, 0,
859822
__fls(imx335->link_freq_bitmap),
860823
~(imx335->link_freq_bitmap),
861824
__ffs(imx335->link_freq_bitmap));
862-
mutex_unlock(&imx335->mutex);
863825

864826
return imx335_set_pad_format(sd, sd_state, &fmt);
865827
}
@@ -1001,16 +963,17 @@ static void imx335_stop_streaming(struct imx335 *imx335)
1001963
static int imx335_set_stream(struct v4l2_subdev *sd, int enable)
1002964
{
1003965
struct imx335 *imx335 = to_imx335(sd);
966+
struct v4l2_subdev_state *state;
1004967
int ret = 0;
1005968

1006-
mutex_lock(&imx335->mutex);
969+
state = v4l2_subdev_lock_and_get_active_state(sd);
1007970

1008971
if (enable)
1009972
ret = imx335_start_streaming(imx335);
1010973
else
1011974
imx335_stop_streaming(imx335);
1012975

1013-
mutex_unlock(&imx335->mutex);
976+
v4l2_subdev_unlock_state(state);
1014977

1015978
return ret;
1016979
}
@@ -1138,7 +1101,7 @@ static const struct v4l2_subdev_pad_ops imx335_pad_ops = {
11381101
.enum_frame_size = imx335_enum_frame_size,
11391102
.get_selection = imx335_get_selection,
11401103
.set_selection = imx335_get_selection,
1141-
.get_fmt = imx335_get_pad_format,
1104+
.get_fmt = v4l2_subdev_get_fmt,
11421105
.set_fmt = imx335_set_pad_format,
11431106
};
11441107

@@ -1233,9 +1196,6 @@ static int imx335_init_controls(struct imx335 *imx335)
12331196
if (ret)
12341197
return ret;
12351198

1236-
/* Serialize controls with sensor device */
1237-
ctrl_hdlr->lock = &imx335->mutex;
1238-
12391199
/* Initialize exposure and gain */
12401200
lpfr = mode->vblank + mode->height;
12411201
imx335->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr,
@@ -1355,12 +1315,10 @@ static int imx335_probe(struct i2c_client *client)
13551315
return ret;
13561316
}
13571317

1358-
mutex_init(&imx335->mutex);
1359-
13601318
ret = imx335_power_on(imx335->dev);
13611319
if (ret) {
13621320
dev_err(imx335->dev, "failed to power-on the sensor\n");
1363-
goto error_mutex_destroy;
1321+
return ret;
13641322
}
13651323

13661324
/* Check module identity */
@@ -1393,11 +1351,18 @@ static int imx335_probe(struct i2c_client *client)
13931351
goto error_handler_free;
13941352
}
13951353

1354+
imx335->sd.state_lock = imx335->ctrl_handler.lock;
1355+
ret = v4l2_subdev_init_finalize(&imx335->sd);
1356+
if (ret < 0) {
1357+
dev_err(imx335->dev, "subdev init error\n");
1358+
goto error_media_entity;
1359+
}
1360+
13961361
ret = v4l2_async_register_subdev_sensor(&imx335->sd);
13971362
if (ret < 0) {
13981363
dev_err(imx335->dev,
13991364
"failed to register async subdev: %d\n", ret);
1400-
goto error_media_entity;
1365+
goto error_subdev_cleanup;
14011366
}
14021367

14031368
pm_runtime_set_active(imx335->dev);
@@ -1406,14 +1371,14 @@ static int imx335_probe(struct i2c_client *client)
14061371

14071372
return 0;
14081373

1374+
error_subdev_cleanup:
1375+
v4l2_subdev_cleanup(&imx335->sd);
14091376
error_media_entity:
14101377
media_entity_cleanup(&imx335->sd.entity);
14111378
error_handler_free:
14121379
v4l2_ctrl_handler_free(imx335->sd.ctrl_handler);
14131380
error_power_off:
14141381
imx335_power_off(imx335->dev);
1415-
error_mutex_destroy:
1416-
mutex_destroy(&imx335->mutex);
14171382

14181383
return ret;
14191384
}
@@ -1427,18 +1392,16 @@ static int imx335_probe(struct i2c_client *client)
14271392
static void imx335_remove(struct i2c_client *client)
14281393
{
14291394
struct v4l2_subdev *sd = i2c_get_clientdata(client);
1430-
struct imx335 *imx335 = to_imx335(sd);
14311395

14321396
v4l2_async_unregister_subdev(sd);
1397+
v4l2_subdev_cleanup(sd);
14331398
media_entity_cleanup(&sd->entity);
14341399
v4l2_ctrl_handler_free(sd->ctrl_handler);
14351400

14361401
pm_runtime_disable(&client->dev);
14371402
if (!pm_runtime_status_suspended(&client->dev))
14381403
imx335_power_off(&client->dev);
14391404
pm_runtime_set_suspended(&client->dev);
1440-
1441-
mutex_destroy(&imx335->mutex);
14421405
}
14431406

14441407
static const struct dev_pm_ops imx335_pm_ops = {

0 commit comments

Comments
 (0)