Commit 35f16741 authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

[media] uvcvideo: Refactor uvc_ctrl_get and query

This is a preparation patch for adding ctrl event support.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 57fb4a48
...@@ -899,24 +899,13 @@ static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain, ...@@ -899,24 +899,13 @@ static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain,
return 0; return 0;
} }
int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
struct uvc_control *ctrl,
struct uvc_control_mapping *mapping,
struct v4l2_queryctrl *v4l2_ctrl) struct v4l2_queryctrl *v4l2_ctrl)
{ {
struct uvc_control *ctrl;
struct uvc_control_mapping *mapping;
struct uvc_menu_info *menu; struct uvc_menu_info *menu;
unsigned int i; unsigned int i;
int ret;
ret = mutex_lock_interruptible(&chain->ctrl_mutex);
if (ret < 0)
return -ERESTARTSYS;
ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
if (ctrl == NULL) {
ret = -EINVAL;
goto done;
}
memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl); memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
v4l2_ctrl->id = mapping->id; v4l2_ctrl->id = mapping->id;
...@@ -930,9 +919,9 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, ...@@ -930,9 +919,9 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
if (!ctrl->cached) { if (!ctrl->cached) {
ret = uvc_ctrl_populate_cache(chain, ctrl); int ret = uvc_ctrl_populate_cache(chain, ctrl);
if (ret < 0) if (ret < 0)
goto done; return ret;
} }
if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) { if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) {
...@@ -954,19 +943,19 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, ...@@ -954,19 +943,19 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
} }
} }
goto done; return 0;
case V4L2_CTRL_TYPE_BOOLEAN: case V4L2_CTRL_TYPE_BOOLEAN:
v4l2_ctrl->minimum = 0; v4l2_ctrl->minimum = 0;
v4l2_ctrl->maximum = 1; v4l2_ctrl->maximum = 1;
v4l2_ctrl->step = 1; v4l2_ctrl->step = 1;
goto done; return 0;
case V4L2_CTRL_TYPE_BUTTON: case V4L2_CTRL_TYPE_BUTTON:
v4l2_ctrl->minimum = 0; v4l2_ctrl->minimum = 0;
v4l2_ctrl->maximum = 0; v4l2_ctrl->maximum = 0;
v4l2_ctrl->step = 0; v4l2_ctrl->step = 0;
goto done; return 0;
default: default:
break; break;
...@@ -984,6 +973,27 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, ...@@ -984,6 +973,27 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES,
uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
return 0;
}
int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
struct v4l2_queryctrl *v4l2_ctrl)
{
struct uvc_control *ctrl;
struct uvc_control_mapping *mapping;
int ret;
ret = mutex_lock_interruptible(&chain->ctrl_mutex);
if (ret < 0)
return -ERESTARTSYS;
ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
if (ctrl == NULL) {
ret = -EINVAL;
goto done;
}
ret = __uvc_query_v4l2_ctrl(chain, ctrl, mapping, v4l2_ctrl);
done: done:
mutex_unlock(&chain->ctrl_mutex); mutex_unlock(&chain->ctrl_mutex);
return ret; return ret;
...@@ -1148,17 +1158,15 @@ int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback) ...@@ -1148,17 +1158,15 @@ int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback)
return ret; return ret;
} }
int uvc_ctrl_get(struct uvc_video_chain *chain, static int __uvc_ctrl_get(struct uvc_video_chain *chain,
struct v4l2_ext_control *xctrl) struct uvc_control *ctrl, struct uvc_control_mapping *mapping,
s32 *value)
{ {
struct uvc_control *ctrl;
struct uvc_control_mapping *mapping;
struct uvc_menu_info *menu; struct uvc_menu_info *menu;
unsigned int i; unsigned int i;
int ret; int ret;
ctrl = uvc_find_control(chain, xctrl->id, &mapping); if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0)
if (ctrl == NULL || (ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0)
return -EINVAL; return -EINVAL;
if (!ctrl->loaded) { if (!ctrl->loaded) {
...@@ -1172,14 +1180,14 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, ...@@ -1172,14 +1180,14 @@ int uvc_ctrl_get(struct uvc_video_chain *chain,
ctrl->loaded = 1; ctrl->loaded = 1;
} }
xctrl->value = mapping->get(mapping, UVC_GET_CUR, *value = mapping->get(mapping, UVC_GET_CUR,
uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
menu = mapping->menu_info; menu = mapping->menu_info;
for (i = 0; i < mapping->menu_count; ++i, ++menu) { for (i = 0; i < mapping->menu_count; ++i, ++menu) {
if (menu->value == xctrl->value) { if (menu->value == *value) {
xctrl->value = i; *value = i;
break; break;
} }
} }
...@@ -1188,6 +1196,19 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, ...@@ -1188,6 +1196,19 @@ int uvc_ctrl_get(struct uvc_video_chain *chain,
return 0; return 0;
} }
int uvc_ctrl_get(struct uvc_video_chain *chain,
struct v4l2_ext_control *xctrl)
{
struct uvc_control *ctrl;
struct uvc_control_mapping *mapping;
ctrl = uvc_find_control(chain, xctrl->id, &mapping);
if (ctrl == NULL)
return -EINVAL;
return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value);
}
int uvc_ctrl_set(struct uvc_video_chain *chain, int uvc_ctrl_set(struct uvc_video_chain *chain,
struct v4l2_ext_control *xctrl) struct v4l2_ext_control *xctrl)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment