Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: imx355: Use subdev active state

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>

authored by

Jai Luthra and committed by
Hans Verkuil
df3ef05b 34af620e

+21 -58
+21 -58
drivers/media/i2c/imx335.c
··· 204 204 * @vblank: Vertical blanking in lines 205 205 * @lane_mode: Mode for number of connected data lanes 206 206 * @cur_mode: Pointer to current selected sensor mode 207 - * @mutex: Mutex for serializing sensor controls 208 207 * @link_freq_bitmap: Menu bitmap for link_freq_ctrl 209 208 * @cur_mbus_code: Currently selected media bus format code 210 209 */ ··· 230 231 u32 vblank; 231 232 u32 lane_mode; 232 233 const struct imx335_mode *cur_mode; 233 - struct mutex mutex; 234 234 unsigned long link_freq_bitmap; 235 235 u32 cur_mbus_code; 236 236 }; ··· 758 760 } 759 761 760 762 /** 761 - * imx335_get_pad_format() - Get subdevice pad format 762 - * @sd: pointer to imx335 V4L2 sub-device structure 763 - * @sd_state: V4L2 sub-device configuration 764 - * @fmt: V4L2 sub-device format need to be set 765 - * 766 - * Return: 0 if successful, error code otherwise. 767 - */ 768 - static int imx335_get_pad_format(struct v4l2_subdev *sd, 769 - struct v4l2_subdev_state *sd_state, 770 - struct v4l2_subdev_format *fmt) 771 - { 772 - struct imx335 *imx335 = to_imx335(sd); 773 - 774 - mutex_lock(&imx335->mutex); 775 - 776 - if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 777 - struct v4l2_mbus_framefmt *framefmt; 778 - 779 - framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad); 780 - fmt->format = *framefmt; 781 - } else { 782 - imx335_fill_pad_format(imx335, imx335->cur_mode, fmt); 783 - } 784 - 785 - mutex_unlock(&imx335->mutex); 786 - 787 - return 0; 788 - } 789 - 790 - /** 791 763 * imx335_set_pad_format() - Set subdevice pad format 792 764 * @sd: pointer to imx335 V4L2 sub-device structure 793 765 * @sd_state: V4L2 sub-device configuration ··· 770 802 struct v4l2_subdev_format *fmt) 771 803 { 772 804 struct imx335 *imx335 = to_imx335(sd); 805 + struct v4l2_mbus_framefmt *format; 773 806 const struct imx335_mode *mode; 774 807 int i, ret = 0; 775 808 776 - mutex_lock(&imx335->mutex); 777 - 778 809 mode = &supported_mode; 810 + 779 811 for (i = 0; i < ARRAY_SIZE(imx335_mbus_codes); i++) { 780 812 if (imx335_mbus_codes[i] == fmt->format.code) 781 813 imx335->cur_mbus_code = imx335_mbus_codes[i]; ··· 783 815 784 816 imx335_fill_pad_format(imx335, mode, fmt); 785 817 786 - if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 787 - struct v4l2_mbus_framefmt *framefmt; 818 + format = v4l2_subdev_state_get_format(sd_state, fmt->pad); 819 + *format = fmt->format; 788 820 789 - framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad); 790 - *framefmt = fmt->format; 791 - } else { 821 + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { 792 822 ret = imx335_update_controls(imx335, mode); 793 823 if (!ret) 794 824 imx335->cur_mode = mode; 795 825 } 796 - 797 - mutex_unlock(&imx335->mutex); 798 826 799 827 return ret; 800 828 } ··· 811 847 fmt.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE; 812 848 imx335_fill_pad_format(imx335, &supported_mode, &fmt); 813 849 814 - mutex_lock(&imx335->mutex); 815 850 __v4l2_ctrl_modify_range(imx335->link_freq_ctrl, 0, 816 851 __fls(imx335->link_freq_bitmap), 817 852 ~(imx335->link_freq_bitmap), 818 853 __ffs(imx335->link_freq_bitmap)); 819 - mutex_unlock(&imx335->mutex); 820 854 821 855 return imx335_set_pad_format(sd, sd_state, &fmt); 822 856 } ··· 956 994 static int imx335_set_stream(struct v4l2_subdev *sd, int enable) 957 995 { 958 996 struct imx335 *imx335 = to_imx335(sd); 997 + struct v4l2_subdev_state *state; 959 998 int ret = 0; 960 999 961 - mutex_lock(&imx335->mutex); 1000 + state = v4l2_subdev_lock_and_get_active_state(sd); 962 1001 963 1002 if (enable) 964 1003 ret = imx335_start_streaming(imx335); 965 1004 else 966 1005 imx335_stop_streaming(imx335); 967 1006 968 - mutex_unlock(&imx335->mutex); 1007 + v4l2_subdev_unlock_state(state); 969 1008 970 1009 return ret; 971 1010 } ··· 1094 1131 .enum_frame_size = imx335_enum_frame_size, 1095 1132 .get_selection = imx335_get_selection, 1096 1133 .set_selection = imx335_get_selection, 1097 - .get_fmt = imx335_get_pad_format, 1134 + .get_fmt = v4l2_subdev_get_fmt, 1098 1135 .set_fmt = imx335_set_pad_format, 1099 1136 }; 1100 1137 ··· 1188 1225 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10); 1189 1226 if (ret) 1190 1227 return ret; 1191 - 1192 - /* Serialize controls with sensor device */ 1193 - ctrl_hdlr->lock = &imx335->mutex; 1194 1228 1195 1229 /* Initialize exposure and gain */ 1196 1230 lpfr = mode->vblank + mode->height; ··· 1308 1348 return ret; 1309 1349 } 1310 1350 1311 - mutex_init(&imx335->mutex); 1312 - 1313 1351 ret = imx335_power_on(imx335->dev); 1314 1352 if (ret) { 1315 1353 dev_err(imx335->dev, "failed to power-on the sensor\n"); 1316 - goto error_mutex_destroy; 1354 + return ret; 1317 1355 } 1318 1356 1319 1357 /* Check module identity */ ··· 1344 1386 goto error_handler_free; 1345 1387 } 1346 1388 1389 + imx335->sd.state_lock = imx335->ctrl_handler.lock; 1390 + ret = v4l2_subdev_init_finalize(&imx335->sd); 1391 + if (ret < 0) { 1392 + dev_err(imx335->dev, "subdev init error\n"); 1393 + goto error_media_entity; 1394 + } 1395 + 1347 1396 ret = v4l2_async_register_subdev_sensor(&imx335->sd); 1348 1397 if (ret < 0) { 1349 1398 dev_err(imx335->dev, 1350 1399 "failed to register async subdev: %d\n", ret); 1351 - goto error_media_entity; 1400 + goto error_subdev_cleanup; 1352 1401 } 1353 1402 1354 1403 pm_runtime_set_active(imx335->dev); ··· 1364 1399 1365 1400 return 0; 1366 1401 1402 + error_subdev_cleanup: 1403 + v4l2_subdev_cleanup(&imx335->sd); 1367 1404 error_media_entity: 1368 1405 media_entity_cleanup(&imx335->sd.entity); 1369 1406 error_handler_free: 1370 1407 v4l2_ctrl_handler_free(imx335->sd.ctrl_handler); 1371 1408 error_power_off: 1372 1409 imx335_power_off(imx335->dev); 1373 - error_mutex_destroy: 1374 - mutex_destroy(&imx335->mutex); 1375 1410 1376 1411 return ret; 1377 1412 } ··· 1385 1420 static void imx335_remove(struct i2c_client *client) 1386 1421 { 1387 1422 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1388 - struct imx335 *imx335 = to_imx335(sd); 1389 1423 1390 1424 v4l2_async_unregister_subdev(sd); 1425 + v4l2_subdev_cleanup(sd); 1391 1426 media_entity_cleanup(&sd->entity); 1392 1427 v4l2_ctrl_handler_free(sd->ctrl_handler); 1393 1428 ··· 1395 1430 if (!pm_runtime_status_suspended(&client->dev)) 1396 1431 imx335_power_off(&client->dev); 1397 1432 pm_runtime_set_suspended(&client->dev); 1398 - 1399 - mutex_destroy(&imx335->mutex); 1400 1433 } 1401 1434 1402 1435 static const struct dev_pm_ops imx335_pm_ops = {