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: uvcvideo: refactor uvc_ioctl_g_ext_ctrls

We want to support fetching the min and max values with g_ext_ctrls,
this patch is a preparation for that.

Instead of abusing uvc_query_v4l2_ctrl(), add an extra parameter to
uvc_ctrl_get, so it can support fetching the default value.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Yunke Cao <yunkec@google.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Link: https://lore.kernel.org/r/20250203-uvc-roi-v17-6-5900a9fed613@chromium.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>

authored by

Ricardo Ribalda and committed by
Hans Verkuil
2002ce44 7f1556a5

+31 -21
+18 -3
drivers/media/usb/uvc/uvc_ctrl.c
··· 1951 1951 return ret; 1952 1952 } 1953 1953 1954 - int uvc_ctrl_get(struct uvc_video_chain *chain, 1955 - struct v4l2_ext_control *xctrl) 1954 + int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, 1955 + struct v4l2_ext_control *xctrl) 1956 1956 { 1957 1957 struct uvc_control *ctrl; 1958 1958 struct uvc_control_mapping *mapping; ··· 1964 1964 if (ctrl == NULL) 1965 1965 return -EINVAL; 1966 1966 1967 - return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); 1967 + switch (which) { 1968 + case V4L2_CTRL_WHICH_CUR_VAL: 1969 + return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); 1970 + case V4L2_CTRL_WHICH_DEF_VAL: 1971 + if (!ctrl->cached) { 1972 + int ret = uvc_ctrl_populate_cache(chain, ctrl); 1973 + 1974 + if (ret < 0) 1975 + return ret; 1976 + } 1977 + xctrl->value = mapping->get(mapping, UVC_GET_DEF, 1978 + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); 1979 + return 0; 1980 + } 1981 + 1982 + return -EINVAL; 1968 1983 } 1969 1984 1970 1985 int uvc_ctrl_set(struct uvc_fh *handle,
+11 -17
drivers/media/usb/uvc/uvc_v4l2.c
··· 1027 1027 struct uvc_video_chain *chain = handle->chain; 1028 1028 struct v4l2_ext_control *ctrl = ctrls->controls; 1029 1029 unsigned int i; 1030 + u32 which; 1030 1031 int ret; 1032 + 1033 + switch (ctrls->which) { 1034 + case V4L2_CTRL_WHICH_DEF_VAL: 1035 + case V4L2_CTRL_WHICH_CUR_VAL: 1036 + which = ctrls->which; 1037 + break; 1038 + default: 1039 + which = V4L2_CTRL_WHICH_CUR_VAL; 1040 + } 1031 1041 1032 1042 ret = uvc_ctrl_check_access(chain, ctrls, VIDIOC_G_EXT_CTRLS); 1033 1043 if (ret < 0) 1034 1044 return ret; 1035 - 1036 - if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) { 1037 - for (i = 0; i < ctrls->count; ++ctrl, ++i) { 1038 - struct v4l2_queryctrl qc = { .id = ctrl->id }; 1039 - 1040 - ret = uvc_query_v4l2_ctrl(chain, &qc); 1041 - if (ret < 0) { 1042 - ctrls->error_idx = i; 1043 - return ret; 1044 - } 1045 - 1046 - ctrl->value = qc.default_value; 1047 - } 1048 - 1049 - return 0; 1050 - } 1051 1045 1052 1046 ret = uvc_ctrl_begin(chain); 1053 1047 if (ret < 0) 1054 1048 return ret; 1055 1049 1056 1050 for (i = 0; i < ctrls->count; ++ctrl, ++i) { 1057 - ret = uvc_ctrl_get(chain, ctrl); 1051 + ret = uvc_ctrl_get(chain, which, ctrl); 1058 1052 if (ret < 0) { 1059 1053 uvc_ctrl_rollback(handle); 1060 1054 ctrls->error_idx = i;
+2 -1
drivers/media/usb/uvc/uvcvideo.h
··· 793 793 return __uvc_ctrl_commit(handle, 1, NULL); 794 794 } 795 795 796 - int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); 796 + int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, 797 + struct v4l2_ext_control *xctrl); 797 798 int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); 798 799 int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, 799 800 const struct v4l2_ext_controls *ctrls,