Commit ba2fa996 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] uvcvideo: Hardcode the index/selector relationship for XU controls

Devices advertise XU controls using a bitmask, in which each bit
corresponds to a control. The control selector, used to query the
control, isn't available in the USB descriptors.

All known UVC devices use control selectors equal to the control bit
index plus one. Hardcode that relationship in the driver, making the
UVCIOC_CTRL_ADD ioctl obsolete. All necessary information about XU
controls can be obtained by the driver at enumeration time.

The UVCIOC_CTRL_ADD ioctl is still supported for compatibility reasons,
but now always returns -EEXIST.

Finally, control mappings are now on a per-device basis and no longer
global.

As this changes the userspace interface, bump the driver version number
to 1.0.0 (it was about time).
Signed-off-by: default avatarMartin Rubli <martin_rubli@logitech.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 650b95fe
This diff is collapsed.
......@@ -41,9 +41,6 @@
#define DRIVER_AUTHOR "Laurent Pinchart " \
"<laurent.pinchart@ideasonboard.com>"
#define DRIVER_DESC "USB Video Class driver"
#ifndef DRIVER_VERSION
#define DRIVER_VERSION "v0.1.0"
#endif
unsigned int uvc_clock_param = CLOCK_MONOTONIC;
unsigned int uvc_no_drop_param;
......@@ -2289,12 +2286,6 @@ static int __init uvc_init(void)
{
int result;
INIT_LIST_HEAD(&uvc_driver.devices);
INIT_LIST_HEAD(&uvc_driver.controls);
mutex_init(&uvc_driver.ctrl_mutex);
uvc_ctrl_init();
result = usb_register(&uvc_driver.driver);
if (result == 0)
printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
......@@ -2304,7 +2295,6 @@ static int __init uvc_init(void)
static void __exit uvc_cleanup(void)
{
usb_deregister(&uvc_driver.driver);
uvc_ctrl_cleanup();
}
module_init(uvc_init);
......
......@@ -31,7 +31,8 @@
/* ------------------------------------------------------------------------
* UVC ioctls
*/
static int uvc_ioctl_ctrl_map(struct uvc_xu_control_mapping *xmap, int old)
static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
struct uvc_xu_control_mapping *xmap, int old)
{
struct uvc_control_mapping *map;
unsigned int size;
......@@ -58,6 +59,8 @@ static int uvc_ioctl_ctrl_map(struct uvc_xu_control_mapping *xmap, int old)
case V4L2_CTRL_TYPE_MENU:
if (old) {
uvc_trace(UVC_TRACE_CONTROL, "V4L2_CTRL_TYPE_MENU not "
"supported for UVCIOC_CTRL_MAP_OLD.\n");
ret = -EINVAL;
goto done;
}
......@@ -78,17 +81,17 @@ static int uvc_ioctl_ctrl_map(struct uvc_xu_control_mapping *xmap, int old)
break;
default:
uvc_trace(UVC_TRACE_CONTROL, "Unsupported V4L2 control type "
"%u.\n", xmap->v4l2_type);
ret = -EINVAL;
goto done;
}
ret = uvc_ctrl_add_mapping(map);
ret = uvc_ctrl_add_mapping(chain, map);
done:
if (ret < 0) {
kfree(map->menu_info);
kfree(map);
}
kfree(map->menu_info);
kfree(map);
return ret;
}
......@@ -1021,42 +1024,19 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
/* Dynamic controls. */
case UVCIOC_CTRL_ADD:
{
struct uvc_xu_control_info *xinfo = arg;
struct uvc_control_info *info;
/* Legacy ioctl, kept for API compatibility reasons */
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (xinfo->size == 0)
return -EINVAL;
info = kzalloc(sizeof *info, GFP_KERNEL);
if (info == NULL)
return -ENOMEM;
memcpy(info->entity, xinfo->entity, sizeof info->entity);
info->index = xinfo->index;
info->selector = xinfo->selector;
info->size = xinfo->size;
info->flags = xinfo->flags;
info->flags |= UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX |
UVC_CONTROL_GET_RES | UVC_CONTROL_GET_DEF |
UVC_CONTROL_EXTENSION;
ret = uvc_ctrl_add_info(info);
if (ret < 0)
kfree(info);
break;
}
return -EEXIST;
case UVCIOC_CTRL_MAP_OLD:
case UVCIOC_CTRL_MAP:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
return uvc_ioctl_ctrl_map(arg, cmd == UVCIOC_CTRL_MAP_OLD);
return uvc_ioctl_ctrl_map(chain, arg,
cmd == UVCIOC_CTRL_MAP_OLD);
case UVCIOC_CTRL_GET:
return uvc_xu_ctrl_query(chain, arg, 0);
......
......@@ -27,8 +27,6 @@
#define UVC_CONTROL_RESTORE (1 << 6)
/* Control can be updated by the camera. */
#define UVC_CONTROL_AUTO_UPDATE (1 << 7)
/* Control is an extension unit control. */
#define UVC_CONTROL_EXTENSION (1 << 8)
#define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \
UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \
......@@ -159,7 +157,8 @@ struct uvc_xu_control {
* Driver specific constants.
*/
#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
#define DRIVER_VERSION_NUMBER KERNEL_VERSION(1, 0, 0)
#define DRIVER_VERSION "v1.0.0"
/* Number of isochronous URBs. */
#define UVC_URBS 5
......@@ -198,11 +197,10 @@ struct uvc_device;
* structures to maximize cache efficiency.
*/
struct uvc_control_info {
struct list_head list;
struct list_head mappings;
__u8 entity[16];
__u8 index;
__u8 index; /* Bit index in bmControls */
__u8 selector;
__u16 size;
......@@ -245,7 +243,6 @@ struct uvc_control {
cached : 1;
__u8 *uvc_data;
__u8 *uvc_info;
};
struct uvc_format_desc {
......@@ -474,7 +471,6 @@ struct uvc_device {
char name[32];
enum uvc_device_state state;
struct list_head list;
atomic_t users;
/* Video control interface */
......@@ -509,11 +505,6 @@ struct uvc_fh {
struct uvc_driver {
struct usb_driver driver;
struct list_head devices; /* struct uvc_device list */
struct list_head controls; /* struct uvc_control_info list */
struct mutex ctrl_mutex; /* protects controls and devices
lists */
};
/* ------------------------------------------------------------------------
......@@ -615,13 +606,11 @@ extern struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
struct v4l2_queryctrl *v4l2_ctrl);
extern int uvc_ctrl_add_info(struct uvc_control_info *info);
extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
const struct uvc_control_mapping *mapping);
extern int uvc_ctrl_init_device(struct uvc_device *dev);
extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
extern int uvc_ctrl_resume_device(struct uvc_device *dev);
extern void uvc_ctrl_init(void);
extern void uvc_ctrl_cleanup(void);
extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
......
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