Skip to content

Commit 8aea4ff

Browse files
committed
media: imx355: Use subdev active state
commit df3ef05b51e02ef9386346288c1e63f366372f5b 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 <[email protected]> Signed-off-by: Jai Luthra <[email protected]> Signed-off-by: Sakari Ailus <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent fad7b2a commit 8aea4ff

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
}
@@ -1139,7 +1102,7 @@ static const struct v4l2_subdev_pad_ops imx335_pad_ops = {
11391102
.enum_frame_size = imx335_enum_frame_size,
11401103
.get_selection = imx335_get_selection,
11411104
.set_selection = imx335_get_selection,
1142-
.get_fmt = imx335_get_pad_format,
1105+
.get_fmt = v4l2_subdev_get_fmt,
11431106
.set_fmt = imx335_set_pad_format,
11441107
};
11451108

@@ -1234,9 +1197,6 @@ static int imx335_init_controls(struct imx335 *imx335)
12341197
if (ret)
12351198
return ret;
12361199

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

1359-
mutex_init(&imx335->mutex);
1360-
13611319
ret = imx335_power_on(imx335->dev);
13621320
if (ret) {
13631321
dev_err(imx335->dev, "failed to power-on the sensor\n");
1364-
goto error_mutex_destroy;
1322+
return ret;
13651323
}
13661324

13671325
/* Check module identity */
@@ -1394,11 +1352,18 @@ static int imx335_probe(struct i2c_client *client)
13941352
goto error_handler_free;
13951353
}
13961354

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

14041369
pm_runtime_set_active(imx335->dev);
@@ -1407,14 +1372,14 @@ static int imx335_probe(struct i2c_client *client)
14071372

14081373
return 0;
14091374

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

14191384
return ret;
14201385
}
@@ -1428,18 +1393,16 @@ static int imx335_probe(struct i2c_client *client)
14281393
static void imx335_remove(struct i2c_client *client)
14291394
{
14301395
struct v4l2_subdev *sd = i2c_get_clientdata(client);
1431-
struct imx335 *imx335 = to_imx335(sd);
14321396

14331397
v4l2_async_unregister_subdev(sd);
1398+
v4l2_subdev_cleanup(sd);
14341399
media_entity_cleanup(&sd->entity);
14351400
v4l2_ctrl_handler_free(sd->ctrl_handler);
14361401

14371402
pm_runtime_disable(&client->dev);
14381403
if (!pm_runtime_status_suspended(&client->dev))
14391404
imx335_power_off(&client->dev);
14401405
pm_runtime_set_suspended(&client->dev);
1441-
1442-
mutex_destroy(&imx335->mutex);
14431406
}
14441407

14451408
static const struct dev_pm_ops imx335_pm_ops = {

0 commit comments

Comments
 (0)