diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-28 09:35:11 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-28 09:35:11 -0700 |
commit | 0851668fdd97e526b2a41f794b785c204dd3d3e0 (patch) | |
tree | 4ef7c20a8be8393006c6fe9627eb29dd30877d61 /drivers/media/video/uvc | |
parent | 00ebb6382b8d9c7c15b5f8ad230670d8161d38dd (diff) | |
parent | 7655e594945289b418af39f6669fea4666a7b520 (diff) |
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (505 commits)
[media] af9015: Fix max I2C message size when used with tda18271
[media] IR: initialize ir_raw_event in few more drivers
[media] Guard a divide in v4l1 compat layer
[media] imon: fix nomouse modprobe option
[media] imon: remove redundant change_protocol call
[media] imon: fix my egregious brown paper bag w/rdev/idev split
[media] cafe_ccic: Configure ov7670 correctly
[media] ov7670: allow configuration of image size, clock speed, and I/O method
[media] af9015: support for DigitalNow TinyTwin v3 [1f4d:9016]
[media] af9015: map DigitalNow TinyTwin v2 remote
[media] DigitalNow TinyTwin remote controller
[media] af9015: RC fixes and improvements
videodev2.h.xml: Update to reflect the latest changes at videodev2.h
[media] v4l: document new Bayer and monochrome pixel formats
[media] DocBook/v4l: Add missing formats used on gspca cpia1 and sn9c2028
[media] firedtv: add parameter to fake ca_system_ids in CA_INFO
[media] tm6000: fix a macro coding style issue
tm6000: Remove some ugly debug code
[media] Nova-S-Plus audio line input
[media] [RFC,1/1] V4L2: Use new CAP bits in existing RDS capable drivers
...
Diffstat (limited to 'drivers/media/video/uvc')
-rw-r--r-- | drivers/media/video/uvc/uvc_ctrl.c | 712 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_driver.c | 19 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_isight.c | 2 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_queue.c | 11 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_status.c | 4 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_v4l2.c | 56 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_video.c | 52 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvcvideo.h | 40 |
8 files changed, 504 insertions, 392 deletions
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c index a350fad0db4..f169f773667 100644 --- a/drivers/media/video/uvc/uvc_ctrl.c +++ b/drivers/media/video/uvc/uvc_ctrl.c @@ -1,8 +1,8 @@ /* * uvc_ctrl.c -- USB Video Class driver - Controls * - * Copyright (C) 2005-2009 - * Laurent Pinchart (laurent.pinchart@skynet.be) + * Copyright (C) 2005-2010 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -643,7 +643,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = { static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id) { - return ctrl->uvc_data + id * ctrl->info->size; + return ctrl->uvc_data + id * ctrl->info.size; } static inline int uvc_test_bit(const __u8 *data, int bit) @@ -727,7 +727,8 @@ static const __u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; static const __u8 uvc_media_transport_input_guid[16] = UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; -static int uvc_entity_match_guid(struct uvc_entity *entity, __u8 guid[16]) +static int uvc_entity_match_guid(const struct uvc_entity *entity, + const __u8 guid[16]) { switch (UVC_ENTITY_TYPE(entity)) { case UVC_ITT_CAMERA: @@ -765,10 +766,10 @@ static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id, for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; - if (ctrl->info == NULL) + if (!ctrl->initialized) continue; - list_for_each_entry(map, &ctrl->info->mappings, list) { + list_for_each_entry(map, &ctrl->info.mappings, list) { if ((map->id == v4l2_id) && !next) { *control = ctrl; *mapping = map; @@ -815,36 +816,36 @@ static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain, { int ret; - if (ctrl->info->flags & UVC_CONTROL_GET_DEF) { + if (ctrl->info.flags & UVC_CONTROL_GET_DEF) { ret = uvc_query_ctrl(chain->dev, UVC_GET_DEF, ctrl->entity->id, - chain->dev->intfnum, ctrl->info->selector, + chain->dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF), - ctrl->info->size); + ctrl->info.size); if (ret < 0) return ret; } - if (ctrl->info->flags & UVC_CONTROL_GET_MIN) { + if (ctrl->info.flags & UVC_CONTROL_GET_MIN) { ret = uvc_query_ctrl(chain->dev, UVC_GET_MIN, ctrl->entity->id, - chain->dev->intfnum, ctrl->info->selector, + chain->dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN), - ctrl->info->size); + ctrl->info.size); if (ret < 0) return ret; } - if (ctrl->info->flags & UVC_CONTROL_GET_MAX) { + if (ctrl->info.flags & UVC_CONTROL_GET_MAX) { ret = uvc_query_ctrl(chain->dev, UVC_GET_MAX, ctrl->entity->id, - chain->dev->intfnum, ctrl->info->selector, + chain->dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX), - ctrl->info->size); + ctrl->info.size); if (ret < 0) return ret; } - if (ctrl->info->flags & UVC_CONTROL_GET_RES) { + if (ctrl->info.flags & UVC_CONTROL_GET_RES) { ret = uvc_query_ctrl(chain->dev, UVC_GET_RES, ctrl->entity->id, - chain->dev->intfnum, ctrl->info->selector, + chain->dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES), - ctrl->info->size); + ctrl->info.size); if (ret < 0) return ret; } @@ -862,9 +863,15 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 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) - return -EINVAL; + if (ctrl == NULL) { + ret = -EINVAL; + goto done; + } memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl); v4l2_ctrl->id = mapping->id; @@ -872,18 +879,18 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, strlcpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name); v4l2_ctrl->flags = 0; - if (!(ctrl->info->flags & UVC_CONTROL_GET_CUR)) + if (!(ctrl->info.flags & UVC_CONTROL_GET_CUR)) v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; - if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR)) + if (!(ctrl->info.flags & UVC_CONTROL_SET_CUR)) v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; if (!ctrl->cached) { ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) - return ret; + goto done; } - if (ctrl->info->flags & UVC_CONTROL_GET_DEF) { + if (ctrl->info.flags & UVC_CONTROL_GET_DEF) { v4l2_ctrl->default_value = mapping->get(mapping, UVC_GET_DEF, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); } @@ -902,37 +909,39 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, } } - return 0; + goto done; case V4L2_CTRL_TYPE_BOOLEAN: v4l2_ctrl->minimum = 0; v4l2_ctrl->maximum = 1; v4l2_ctrl->step = 1; - return 0; + goto done; case V4L2_CTRL_TYPE_BUTTON: v4l2_ctrl->minimum = 0; v4l2_ctrl->maximum = 0; v4l2_ctrl->step = 0; - return 0; + goto done; default: break; } - if (ctrl->info->flags & UVC_CONTROL_GET_MIN) + if (ctrl->info.flags & UVC_CONTROL_GET_MIN) v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); - if (ctrl->info->flags & UVC_CONTROL_GET_MAX) + if (ctrl->info.flags & UVC_CONTROL_GET_MAX) v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); - if (ctrl->info->flags & UVC_CONTROL_GET_RES) + if (ctrl->info.flags & UVC_CONTROL_GET_RES) v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); - return 0; +done: + mutex_unlock(&chain->ctrl_mutex); + return ret; } @@ -977,14 +986,14 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; - if (ctrl->info == NULL) + if (!ctrl->initialized) continue; /* Reset the loaded flag for auto-update controls that were * marked as loaded in uvc_ctrl_get/uvc_ctrl_set to prevent * uvc_ctrl_get from using the cached value. */ - if (ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) + if (ctrl->info.flags & UVC_CONTROL_AUTO_UPDATE) ctrl->loaded = 0; if (!ctrl->dirty) @@ -992,16 +1001,16 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, if (!rollback) ret = uvc_query_ctrl(dev, UVC_SET_CUR, ctrl->entity->id, - dev->intfnum, ctrl->info->selector, + dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info->size); + ctrl->info.size); else ret = 0; if (rollback || ret < 0) memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), - ctrl->info->size); + ctrl->info.size); ctrl->dirty = 0; @@ -1039,14 +1048,14 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, int ret; ctrl = uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) + if (ctrl == NULL || (ctrl->info.flags & UVC_CONTROL_GET_CUR) == 0) return -EINVAL; if (!ctrl->loaded) { ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, - chain->dev->intfnum, ctrl->info->selector, + chain->dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info->size); + ctrl->info.size); if (ret < 0) return ret; @@ -1081,7 +1090,7 @@ int uvc_ctrl_set(struct uvc_video_chain *chain, int ret; ctrl = uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0) + if (ctrl == NULL || (ctrl->info.flags & UVC_CONTROL_SET_CUR) == 0) return -EINVAL; /* Clamp out of range values. */ @@ -1127,16 +1136,16 @@ int uvc_ctrl_set(struct uvc_video_chain *chain, * needs to be loaded from the device to perform the read-modify-write * operation. */ - if (!ctrl->loaded && (ctrl->info->size * 8) != mapping->size) { - if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) { + if (!ctrl->loaded && (ctrl->info.size * 8) != mapping->size) { + if ((ctrl->info.flags & UVC_CONTROL_GET_CUR) == 0) { memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - 0, ctrl->info->size); + 0, ctrl->info.size); } else { ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, chain->dev->intfnum, - ctrl->info->selector, + ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info->size); + ctrl->info.size); if (ret < 0) return ret; } @@ -1148,7 +1157,7 @@ int uvc_ctrl_set(struct uvc_video_chain *chain, if (!ctrl->dirty) { memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info->size); + ctrl->info.size); } mapping->set(mapping, value, @@ -1163,12 +1172,138 @@ int uvc_ctrl_set(struct uvc_video_chain *chain, * Dynamic controls */ +static void uvc_ctrl_fixup_xu_info(struct uvc_device *dev, + const struct uvc_control *ctrl, struct uvc_control_info *info) +{ + struct uvc_ctrl_fixup { + struct usb_device_id id; + u8 entity; + u8 selector; + u8 flags; + }; + + static const struct uvc_ctrl_fixup fixups[] = { + { { USB_DEVICE(0x046d, 0x08c2) }, 9, 1, + UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX | + UVC_CONTROL_GET_DEF | UVC_CONTROL_SET_CUR | + UVC_CONTROL_AUTO_UPDATE }, + { { USB_DEVICE(0x046d, 0x08cc) }, 9, 1, + UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX | + UVC_CONTROL_GET_DEF | UVC_CONTROL_SET_CUR | + UVC_CONTROL_AUTO_UPDATE }, + { { USB_DEVICE(0x046d, 0x0994) }, 9, 1, + UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX | + UVC_CONTROL_GET_DEF | UVC_CONTROL_SET_CUR | + UVC_CONTROL_AUTO_UPDATE }, + }; + + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(fixups); ++i) { + if (!usb_match_one_id(dev->intf, &fixups[i].id)) + continue; + + if (fixups[i].entity == ctrl->entity->id && + fixups[i].selector == info->selector) { + info->flags = fixups[i].flags; + return; + } + } +} + +/* + * Query control information (size and flags) for XU controls. + */ +static int uvc_ctrl_fill_xu_info(struct uvc_device *dev, + const struct uvc_control *ctrl, struct uvc_control_info *info) +{ + u8 *data; + int ret; + + data = kmalloc(2, GFP_KERNEL); + if (data == NULL) + return -ENOMEM; + + memcpy(info->entity, ctrl->entity->extension.guidExtensionCode, + sizeof(info->entity)); + info->index = ctrl->index; + info->selector = ctrl->index + 1; + + /* Query and verify the control length (GET_LEN) */ + ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id, dev->intfnum, + info->selector, data, 2); + if (ret < 0) { + uvc_trace(UVC_TRACE_CONTROL, + "GET_LEN failed on control %pUl/%u (%d).\n", + info->entity, info->selector, ret); + goto done; + } + + info->size = le16_to_cpup((__le16 *)data); + + /* Query the control information (GET_INFO) */ + ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, + info->selector, data, 1); + if (ret < 0) { + uvc_trace(UVC_TRACE_CONTROL, + "GET_INFO failed on control %pUl/%u (%d).\n", + info->entity, info->selector, ret); + goto done; + } + + info->flags = UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX + | UVC_CONTROL_GET_RES | UVC_CONTROL_GET_DEF + | (data[0] & UVC_CONTROL_CAP_GET ? UVC_CONTROL_GET_CUR : 0) + | (data[0] & UVC_CONTROL_CAP_SET ? UVC_CONTROL_SET_CUR : 0) + | (data[0] & UVC_CONTROL_CAP_AUTOUPDATE ? + UVC_CONTROL_AUTO_UPDATE : 0); + + uvc_ctrl_fixup_xu_info(dev, ctrl, info); + + uvc_trace(UVC_TRACE_CONTROL, "XU control %pUl/%u queried: len %u, " + "flags { get %u set %u auto %u }.\n", + info->entity, info->selector, info->size, + (info->flags & UVC_CONTROL_GET_CUR) ? 1 : 0, + (info->flags & UVC_CONTROL_SET_CUR) ? 1 : 0, + (info->flags & UVC_CONTROL_AUTO_UPDATE) ? 1 : 0); + +done: + kfree(data); + return ret; +} + +static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, + const struct uvc_control_info *info); + +static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev, + struct uvc_control *ctrl) +{ + struct uvc_control_info info; + int ret; + + if (ctrl->initialized) + return 0; + + ret = uvc_ctrl_fill_xu_info(dev, ctrl, &info); + if (ret < 0) + return ret; + + ret = uvc_ctrl_add_info(dev, ctrl, &info); + if (ret < 0) + uvc_trace(UVC_TRACE_CONTROL, "Failed to initialize control " + "%pUl/%u on device %s entity %u\n", info.entity, + info.selector, dev->udev->devpath, ctrl->entity->id); + + return ret; +} + int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control *xctrl, int set) { struct uvc_entity *entity; struct uvc_control *ctrl = NULL; unsigned int i, found = 0; + int restore = 0; __u8 *data; int ret; @@ -1185,13 +1320,10 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, return -EINVAL; } - /* Find the control. */ + /* Find the control and perform delayed initialization if needed. */ for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; - if (ctrl->info == NULL) - continue; - - if (ctrl->info->selector == xctrl->selector) { + if (ctrl->index == xctrl->selector - 1) { found = 1; break; } @@ -1203,40 +1335,48 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, return -EINVAL; } - /* Validate control data size. */ - if (ctrl->info->size != xctrl->size) - return -EINVAL; - - if ((set && !(ctrl->info->flags & UVC_CONTROL_SET_CUR)) || - (!set && !(ctrl->info->flags & UVC_CONTROL_GET_CUR))) - return -EINVAL; - if (mutex_lock_interruptible(&chain->ctrl_mutex)) return -ERESTARTSYS; + ret = uvc_ctrl_init_xu_ctrl(chain->dev, ctrl); + if (ret < 0) { + ret = -ENOENT; + goto done; + } + + /* Validate control data size. */ + if (ctrl->info.size != xctrl->size) { + ret = -EINVAL; + goto done; + } + + if ((set && !(ctrl->info.flags & UVC_CONTROL_SET_CUR)) || + (!set && !(ctrl->info.flags & UVC_CONTROL_GET_CUR))) { + ret = -EINVAL; + goto done; + } + memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - xctrl->size); + ctrl->info.size); data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT); + restore = set; if (set && copy_from_user(data, xctrl->data, xctrl->size)) { ret = -EFAULT; - goto out; + goto done; } ret = uvc_query_ctrl(chain->dev, set ? UVC_SET_CUR : UVC_GET_CUR, xctrl->unit, chain->dev->intfnum, xctrl->selector, data, xctrl->size); if (ret < 0) - goto out; + goto done; - if (!set && copy_to_user(xctrl->data, data, xctrl->size)) { + if (!set && copy_to_user(xctrl->data, data, xctrl->size)) ret = -EFAULT; - goto out; - } - -out: - if (ret) +done: + if (ret && restore) memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), xctrl->size); @@ -1271,13 +1411,13 @@ int uvc_ctrl_resume_device(struct uvc_device *dev) for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; - if (ctrl->info == NULL || !ctrl->modified || - (ctrl->info->flags & UVC_CONTROL_RESTORE) == 0) + if (!ctrl->initialized || !ctrl->modified || + (ctrl->info.flags & UVC_CONTROL_RESTORE) == 0) continue; printk(KERN_INFO "restoring control %pUl/%u/%u\n", - ctrl->info->entity, ctrl->info->index, - ctrl->info->selector); + ctrl->info.entity, ctrl->info.index, + ctrl->info.selector); ctrl->dirty = 1; } @@ -1293,201 +1433,150 @@ int uvc_ctrl_resume_device(struct uvc_device *dev) * Control and mapping handling */ -static int uvc_ctrl_add_ctrl(struct uvc_device *dev, - struct uvc_control_info *info) +/* + * Add control information to a given control. + */ +static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, + const struct uvc_control_info *info) { - struct uvc_entity *entity; - struct uvc_control *ctrl = NULL; - int ret = 0, found = 0; - unsigned int i; - u8 *uvc_info; - u8 *uvc_data; - - list_for_each_entry(entity, &dev->entities, list) { - if (!uvc_entity_match_guid(entity, info->entity)) - continue; - - for (i = 0; i < entity->ncontrols; ++i) { - ctrl = &entity->controls[i]; - if (ctrl->index == info->index) { - found = 1; - break; - } - } - - if (found) - break; - } - - if (!found) - return 0; - - uvc_data = kmalloc(info->size * UVC_CTRL_DATA_LAST + 1, GFP_KERNEL); - if (uvc_data == NULL) - return -ENOMEM; - - uvc_info = uvc_data + info->size * UVC_CTRL_DATA_LAST; - - if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) { - /* Check if the device control information and length match - * the user supplied information. - */ - ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id, - dev->intfnum, info->selector, uvc_data, 2); - if (ret < 0) { - uvc_trace(UVC_TRACE_CONTROL, - "GET_LEN failed on control %pUl/%u (%d).\n", - info->entity, info->selector, ret); - goto done; - } - - if (info->size != le16_to_cpu(*(__le16 *)uvc_data)) { - uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u size " - "doesn't match user supplied value.\n", - info->entity, info->selector); - ret = -EINVAL; - goto done; - } + int ret = 0; - ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, - dev->intfnum, info->selector, uvc_info, 1); - if (ret < 0) { - uvc_trace(UVC_TRACE_CONTROL, - "GET_INFO failed on control %pUl/%u (%d).\n", - info->entity, info->selector, ret); - goto done; - } + memcpy(&ctrl->info, info, sizeof(*info)); + INIT_LIST_HEAD(&ctrl->info.mappings); - if (((info->flags & UVC_CONTROL_GET_CUR) && - !(*uvc_info & UVC_CONTROL_CAP_GET)) || - ((info->flags & UVC_CONTROL_SET_CUR) && - !(*uvc_info & UVC_CONTROL_CAP_SET))) { - uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u flags " - "don't match supported operations.\n", - info->entity, info->selector); - ret = -EINVAL; - goto done; - } + /* Allocate an array to save control values (cur, def, max, etc.) */ + ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1, + GFP_KERNEL); + if (ctrl->uvc_data == NULL) { + ret = -ENOMEM; + goto done; } - ctrl->info = info; - ctrl->uvc_data = uvc_data; - ctrl->uvc_info = uvc_info; + ctrl->initialized = 1; uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s " - "entity %u\n", ctrl->info->entity, ctrl->info->selector, - dev->udev->devpath, entity->id); + "entity %u\n", ctrl->info.entity, ctrl->info.selector, + dev->udev->devpath, ctrl->entity->id); done: if (ret < 0) - kfree(uvc_data); - + kfree(ctrl->uvc_data); return ret; } /* - * Add an item to the UVC control information list, and instantiate a control - * structure for each device that supports the control. + * Add a control mapping to a given control. */ -int uvc_ctrl_add_info(struct uvc_control_info *info) +static int __uvc_ctrl_add_mapping(struct uvc_device *dev, + struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) { - struct uvc_control_info *ctrl; - struct uvc_device *dev; - int ret = 0; - - /* Find matching controls by walking the devices, entities and - * controls list. - */ - mutex_lock(&uvc_driver.ctrl_mutex); + struct uvc_control_mapping *map; + unsigned int size; - /* First check if the list contains a control matching the new one. - * Bail out if it does. + /* Most mappings come from static kernel data and need to be duplicated. + * Mappings that come from userspace will be unnecessarily duplicated, + * this could be optimized. */ - list_for_each_entry(ctrl, &uvc_driver.controls, list) { - if (memcmp(ctrl->entity, info->entity, 16)) - continue; + map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL); + if (map == NULL) + return -ENOMEM; - if (ctrl->selector == info->selector) { - uvc_trace(UVC_TRACE_CONTROL, - "Control %pUl/%u is already defined.\n", - info->entity, info->selector); - ret = -EEXIST; - goto end; - } - if (ctrl->index == info->index) { - uvc_trace(UVC_TRACE_CONTROL, - "Control %pUl/%u would overwrite index %d.\n", - info->entity, info->selector, info->index); - ret = -EEXIST; - goto end; - } + size = sizeof(*mapping->menu_info) * mapping->menu_count; + map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); + if (map->menu_info == NULL) { + kfree(map); + return -ENOMEM; } - list_for_each_entry(dev, &uvc_driver.devices, list) - uvc_ctrl_add_ctrl(dev, info); + if (map->get == NULL) + map->get = uvc_get_le_value; + if (map->set == NULL) + map->set = uvc_set_le_value; - INIT_LIST_HEAD(&info->mappings); - list_add_tail(&info->list, &uvc_driver.controls); -end: - mutex_unlock(&uvc_driver.ctrl_mutex); - return ret; + map->ctrl = &ctrl->info; + list_add_tail(&map->list, &ctrl->info.mappings); + uvc_trace(UVC_TRACE_CONTROL, + "Adding mapping '%s' to control %pUl/%u.\n", + map->name, ctrl->info.entity, ctrl->info.selector); + + return 0; } -int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping) +int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, + const struct uvc_control_mapping *mapping) { - struct uvc_control_info *info; + struct uvc_device *dev = chain->dev; struct uvc_control_mapping *map; - int ret = -EINVAL; - - if (mapping->get == NULL) - mapping->get = uvc_get_le_value; - if (mapping->set == NULL) - mapping->set = uvc_set_le_value; + struct uvc_entity *entity; + struct uvc_control *ctrl; + int found = 0; + int ret; if (mapping->id & ~V4L2_CTRL_ID_MASK) { - uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s' with " - "invalid control id 0x%08x\n", mapping->name, + uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', control " + "id 0x%08x is invalid.\n", mapping->name, mapping->id); return -EINVAL; } - mutex_lock(&uvc_driver.ctrl_mutex); - list_for_each_entry(info, &uvc_driver.controls, list) { - if (memcmp(info->entity, mapping->entity, 16) || - info->selector != mapping->selector) - continue; + /* Search for the matching (GUID/CS) control in the given device */ + list_for_each_entry(entity, &dev->entities, list) { + unsigned int i; - if (info->size * 8 < mapping->size + mapping->offset) { - uvc_trace(UVC_TRACE_CONTROL, - "Mapping '%s' would overflow control %pUl/%u\n", - mapping->name, info->entity, info->selector); - ret = -EOVERFLOW; - goto end; - } + if (UVC_ENTITY_TYPE(entity) != UVC_VC_EXTENSION_UNIT || + !uvc_entity_match_guid(entity, mapping->entity)) + continue; - /* Check if the list contains a mapping matching the new one. - * Bail out if it does. - */ - list_for_each_entry(map, &info->mappings, list) { - if (map->id == mapping->id) { - uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' is " - "already defined.\n", mapping->name); - ret = -EEXIST; - goto end; + for (i = 0; i < entity->ncontrols; ++i) { + ctrl = &entity->controls[i]; + if (ctrl->index == mapping->selector - 1) { + found = 1; + break; } } - mapping->ctrl = info; - list_add_tail(&mapping->list, &info->mappings); - uvc_trace(UVC_TRACE_CONTROL, - "Adding mapping %s to control %pUl/%u.\n", - mapping->name, info->entity, info->selector); + if (found) + break; + } + if (!found) + return -ENOENT; - ret = 0; - break; + if (mutex_lock_interruptible(&chain->ctrl_mutex)) + return -ERESTARTSYS; + + /* Perform delayed initialization of XU controls */ + ret = uvc_ctrl_init_xu_ctrl(dev, ctrl); + if (ret < 0) { + ret = -ENOENT; + goto done; } -end: - mutex_unlock(&uvc_driver.ctrl_mutex); + + list_for_each_entry(map, &ctrl->info.mappings, list) { + if (mapping->id == map->id) { + uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', " + "control id 0x%08x already exists.\n", + mapping->name, mapping->id); + ret = -EEXIST; + goto done; + } + } + + /* Prevent excess memory consumption */ + if (atomic_inc_return(&dev->nmappings) > UVC_MAX_CONTROL_MAPPINGS) { + atomic_dec(&dev->nmappings); + uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', maximum " + "mappings count (%u) exceeded.\n", mapping->name, + UVC_MAX_CONTROL_MAPPINGS); + ret = -ENOMEM; + goto done; + } + + ret = __uvc_ctrl_add_mapping(dev, ctrl, mapping); + if (ret < 0) + atomic_dec(&dev->nmappings); + +done: + mutex_unlock(&chain->ctrl_mutex); return ret; } @@ -1496,29 +1585,49 @@ end: * are currently the ones that crash the camera or unconditionally return an * error when queried. */ -static void -uvc_ctrl_prune_entity(struct uvc_device *dev, struct uvc_entity *entity) +static void uvc_ctrl_prune_entity(struct uvc_device *dev, + struct uvc_entity *entity) { - static const struct { + struct uvc_ctrl_blacklist { struct usb_device_id id; u8 index; - } blacklist[] = { + }; + + static const struct uvc_ctrl_blacklist processing_blacklist[] = { { { USB_DEVICE(0x13d3, 0x509b) }, 9 }, /* Gain */ { { USB_DEVICE(0x1c4f, 0x3000) }, 6 }, /* WB Temperature */ { { USB_DEVICE(0x5986, 0x0241) }, 2 }, /* Hue */ }; + static const struct uvc_ctrl_blacklist camera_blacklist[] = { + { { USB_DEVICE(0x06f8, 0x3005) }, 9 }, /* Zoom, Absolute */ + }; - u8 *controls; + const struct uvc_ctrl_blacklist *blacklist; unsigned int size; + unsigned int count; unsigned int i; + u8 *controls; - if (UVC_ENTITY_TYPE(entity) != UVC_VC_PROCESSING_UNIT) - return; + switch (UVC_ENTITY_TYPE(entity)) { + case UVC_VC_PROCESSING_UNIT: + blacklist = processing_blacklist; + count = ARRAY_SIZE(processing_blacklist); + controls = entity->processing.bmControls; + size = entity->processing.bControlSize; + break; - controls = entity->processing.bmControls; - size = entity->processing.bControlSize; + case UVC_ITT_CAMERA: + blacklist = camera_blacklist; + count = ARRAY_SIZE(camera_blacklist); + controls = entity->camera.bmControls; + size = entity->camera.bControlSize; + break; - for (i = 0; i < ARRAY_SIZE(blacklist); ++i) { + default: + return; + } + + for (i = 0; i < count; ++i) { if (!usb_match_one_id(dev->intf, &blacklist[i].id)) continue; @@ -1534,17 +1643,54 @@ uvc_ctrl_prune_entity(struct uvc_device *dev, struct uvc_entity *entity) } /* + * Add control information and hardcoded stock control mappings to the given + * device. + */ +static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) +{ + const struct uvc_control_info *info = uvc_ctrls; + const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); + const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; + const struct uvc_control_mapping *mend = + mapping + ARRAY_SIZE(uvc_ctrl_mappings); + + /* XU controls initialization requires querying the device for control + * information. As some buggy UVC devices will crash when queried + * repeatedly in a tight loop, delay XU controls initialization until + * first use. + */ + if (UVC_ENTITY_TYPE(ctrl->entity) == UVC_VC_EXTENSION_UNIT) + return; + + for (; info < iend; ++info) { + if (uvc_entity_match_guid(ctrl->entity, info->entity) && + ctrl->index == info->index) { + uvc_ctrl_add_info(dev, ctrl, info); + break; + } + } + + if (!ctrl->initialized) + return; + + for (; mapping < mend; ++mapping) { + if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && + ctrl->info.selector == mapping->selector) + __uvc_ctrl_add_mapping(dev, ctrl, mapping); + } +} + +/* * Initialize device controls. */ int uvc_ctrl_init_device(struct uvc_device *dev) { - struct uvc_control_info *info; - struct uvc_control *ctrl; struct uvc_entity *entity; unsigned int i; /* Walk the entities list and instantiate controls */ list_for_each_entry(entity, &dev->entities, list) { + struct uvc_control *ctrl; unsigned int bControlSize = 0, ncontrols = 0; __u8 *bmControls = NULL; @@ -1559,20 +1705,22 @@ int uvc_ctrl_init_device(struct uvc_device *dev) bControlSize = entity->camera.bControlSize; } + /* Remove bogus/blacklisted controls */ uvc_ctrl_prune_entity(dev, entity); + /* Count supported controls and allocate the controls array */ for (i = 0; i < bControlSize; ++i) ncontrols += hweight8(bmControls[i]); - if (ncontrols == 0) continue; - entity->controls = kzalloc(ncontrols*sizeof *ctrl, GFP_KERNEL); + entity->controls = kzalloc(ncontrols * sizeof(*ctrl), + GFP_KERNEL); if (entity->controls == NULL) return -ENOMEM; - entity->ncontrols = ncontrols; + /* Initialize all supported controls */ ctrl = entity->controls; for (i = 0; i < bControlSize * 8; ++i) { if (uvc_test_bit(bmControls, i) == 0) @@ -1580,81 +1728,47 @@ int uvc_ctrl_init_device(struct uvc_device *dev) ctrl->entity = entity; ctrl->index = i; + + uvc_ctrl_init_ctrl(dev, ctrl); ctrl++; } } - /* Walk the controls info list and associate them with the device - * controls, then add the device to the global device list. This has - * to be done while holding the controls lock, to make sure - * uvc_ctrl_add_info() will not get called in-between. - */ - mutex_lock(&uvc_driver.ctrl_mutex); - list_for_each_entry(info, &uvc_driver.controls, list) - uvc_ctrl_add_ctrl(dev, info); - - list_add_tail(&dev->list, &uvc_driver.devices); - mutex_unlock(&uvc_driver.ctrl_mutex); - return 0; } /* * Cleanup device controls. */ -void uvc_ctrl_cleanup_device(struct uvc_device *dev) +static void uvc_ctrl_cleanup_mappings(struct uvc_device *dev, + struct uvc_control *ctrl) { - struct uvc_entity *entity; - unsigned int i; + struct uvc_control_mapping *mapping, *nm; - /* Remove the device from the global devices list */ - mutex_lock(&uvc_driver.ctrl_mutex); - if (dev->list.next != NULL) - list_del(&dev->list); - mutex_unlock(&uvc_driver.ctrl_mutex); - - list_for_each_entry(entity, &dev->entities, list) { - for (i = 0; i < entity->ncontrols; ++i) - kfree(entity->controls[i].uvc_data); - - kfree(entity->controls); + list_for_each_entry_safe(mapping, nm, &ctrl->info.mappings, list) { + list_del(&mapping->list); + kfree(mapping->menu_info); + kfree(mapping); } } -void uvc_ctrl_cleanup(void) +void uvc_ctrl_cleanup_device(struct uvc_device *dev) { - struct uvc_control_info *info; - struct uvc_control_info *ni; - struct uvc_control_mapping *mapping; - struct uvc_control_mapping *nm; + struct uvc_entity *entity; + unsigned int i; - list_for_each_entry_safe(info, ni, &uvc_driver.controls, list) { - if (!(info->flags & UVC_CONTROL_EXTENSION)) - continue; + /* Free controls and control mappings for all entities. */ + list_for_each_entry(entity, &dev->entities, list) { + for (i = 0; i < entity->ncontrols; ++i) { + struct uvc_control *ctrl = &entity->controls[i]; - list_for_each_entry_safe(mapping, nm, &info->mappings, list) { - list_del(&mapping->list); - kfree(mapping->menu_info); - kfree(mapping); + if (!ctrl->initialized) + continue; + + uvc_ctrl_cleanup_mappings(dev, ctrl); + kfree(ctrl->uvc_data); } - list_del(&info->list); - kfree(info); + kfree(entity->controls); } } - -void uvc_ctrl_init(void) -{ - struct uvc_control_info *ctrl = uvc_ctrls; - struct uvc_control_info *cend = ctrl + ARRAY_SIZE(uvc_ctrls); - struct uvc_control_mapping *mapping = uvc_ctrl_mappings; - struct uvc_control_mapping *mend = - mapping + ARRAY_SIZE(uvc_ctrl_mappings); - - for (; ctrl < cend; ++ctrl) - uvc_ctrl_add_info(ctrl); - - for (; mapping < mend; ++mapping) - uvc_ctrl_add_mapping(mapping); -} - diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c index 2ac85d8984f..a1e9dfb52f6 100644 --- a/drivers/media/video/uvc/uvc_driver.c +++ b/drivers/media/video/uvc/uvc_driver.c @@ -1,8 +1,8 @@ /* * uvc_driver.c -- USB Video Class driver * - * Copyright (C) 2005-2009 - * Laurent Pinchart (laurent.pinchart@skynet.be) + * Copyright (C) 2005-2010 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,11 +38,9 @@ #include "uvcvideo.h" -#define DRIVER_AUTHOR "Laurent Pinchart <laurent.pinchart@skynet.be>" +#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; @@ -1762,6 +1760,7 @@ static int uvc_probe(struct usb_interface *intf, INIT_LIST_HEAD(&dev->streams); atomic_set(&dev->nstreams, 0); atomic_set(&dev->users, 0); + atomic_set(&dev->nmappings, 0); dev->udev = usb_get_dev(udev); dev->intf = usb_get_intf(intf); @@ -1820,6 +1819,7 @@ static int uvc_probe(struct usb_interface *intf, } uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n"); + usb_enable_autosuspend(udev); return 0; error: @@ -2287,12 +2287,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"); @@ -2302,7 +2296,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); diff --git a/drivers/media/video/uvc/uvc_isight.c b/drivers/media/video/uvc/uvc_isight.c index a9285b570db..74bbe8f18f3 100644 --- a/drivers/media/video/uvc/uvc_isight.c +++ b/drivers/media/video/uvc/uvc_isight.c @@ -4,7 +4,7 @@ * Copyright (C) 2006-2007 * Ivan N. Zlatev <contact@i-nz.net> * Copyright (C) 2008-2009 - * Laurent Pinchart <laurent.pinchart@skynet.be> + * Laurent Pinchart <laurent.pinchart@ideasonboard.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c index e9928a41508..ed6d5449741 100644 --- a/drivers/media/video/uvc/uvc_queue.c +++ b/drivers/media/video/uvc/uvc_queue.c @@ -1,8 +1,8 @@ /* * uvc_queue.c -- USB Video Class driver - Buffers management * - * Copyright (C) 2005-2009 - * Laurent Pinchart (laurent.pinchart@skynet.be) + * Copyright (C) 2005-2010 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -135,7 +135,6 @@ int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, queue->buffer[i].buf.m.offset = i * bufsize; queue->buffer[i].buf.length = buflength; queue->buffer[i].buf.type = queue->type; - queue->buffer[i].buf.sequence = 0; queue->buffer[i].buf.field = V4L2_FIELD_NONE; queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP; queue->buffer[i].buf.flags = 0; @@ -410,8 +409,7 @@ done: * state can be properly initialized before buffers are accessed from the * interrupt handler. * - * Enabling the video queue initializes parameters (such as sequence number, - * sync pattern, ...). If the queue is already enabled, return -EBUSY. + * Enabling the video queue returns -EBUSY if the queue is already enabled. * * Disabling the video queue cancels the queue and removes all buffers from * the main queue. @@ -430,7 +428,6 @@ int uvc_queue_enable(struct uvc_video_queue *queue, int enable) ret = -EBUSY; goto done; } - queue->sequence = 0; queue->flags |= UVC_QUEUE_STREAMING; queue->buf_used = 0; } else { @@ -510,8 +507,6 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, nextbuf = NULL; spin_unlock_irqrestore(&queue->irqlock, flags); - buf->buf.sequence = queue->sequence++; - wake_up(&buf->wait); return nextbuf; } diff --git a/drivers/media/video/uvc/uvc_status.c b/drivers/media/video/uvc/uvc_status.c index 85019bdacdf..b7492775e6a 100644 --- a/drivers/media/video/uvc/uvc_status.c +++ b/drivers/media/video/uvc/uvc_status.c @@ -1,8 +1,8 @@ /* * uvc_status.c -- USB Video Class driver - Status endpoint * - * Copyright (C) 2007-2009 - * Laurent Pinchart (laurent.pinchart@skynet.be) + * Copyright (C) 2005-2009 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c index 86db32697b8..6d15de9b520 100644 --- a/drivers/media/video/uvc/uvc_v4l2.c +++ b/drivers/media/video/uvc/uvc_v4l2.c @@ -1,8 +1,8 @@ /* * uvc_v4l2.c -- USB Video Class driver - V4L2 API * - * Copyright (C) 2005-2009 - * Laurent Pinchart (laurent.pinchart@skynet.be) + * Copyright (C) 2005-2010 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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,13 @@ 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; - - 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; - } + /* Legacy ioctl, kept for API compatibility reasons */ + 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); diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c index e27cf0d3b6d..5555f010283 100644 --- a/drivers/media/video/uvc/uvc_video.c +++ b/drivers/media/video/uvc/uvc_video.c @@ -1,8 +1,8 @@ /* * uvc_video.c -- USB Video Class driver - Video handling * - * Copyright (C) 2005-2009 - * Laurent Pinchart (laurent.pinchart@skynet.be) + * Copyright (C) 2005-2010 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,6 +45,30 @@ static int __uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, unit << 8 | intfnum, data, size, timeout); } +static const char *uvc_query_name(__u8 query) +{ + switch (query) { + case UVC_SET_CUR: + return "SET_CUR"; + case UVC_GET_CUR: + return "GET_CUR"; + case UVC_GET_MIN: + return "GET_MIN"; + case UVC_GET_MAX: + return "GET_MAX"; + case UVC_GET_RES: + return "GET_RES"; + case UVC_GET_LEN: + return "GET_LEN"; + case UVC_GET_INFO: + return "GET_INFO"; + case UVC_GET_DEF: + return "GET_DEF"; + default: + return "<invalid>"; + } +} + int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, __u8 intfnum, __u8 cs, void *data, __u16 size) { @@ -53,9 +77,9 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, ret = __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size, UVC_CTRL_CONTROL_TIMEOUT); if (ret != size) { - uvc_printk(KERN_ERR, "Failed to query (%u) UVC control %u " - "(unit %u) : %d (exp. %u).\n", query, cs, unit, ret, - size); + uvc_printk(KERN_ERR, "Failed to query (%s) UVC control %u on " + "unit %u: %d (exp. %u).\n", uvc_query_name(query), cs, + unit, ret, size); return -EIO; } @@ -114,6 +138,15 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, bandwidth /= 8; bandwidth += 12; + /* The bandwidth estimate is too low for many cameras. Don't use + * maximum packet sizes lower than 1024 bytes to try and work + * around the problem. According to measurements done on two + * different camera models, the value is high enough to get most + * resolutions working while not preventing two simultaneous + * VGA streams at 15 fps. + */ + bandwidth = max_t(u32, bandwidth, 1024); + ctrl->dwMaxPayloadTransferSize = bandwidth; } } @@ -394,6 +427,12 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, fid = data[1] & UVC_STREAM_FID; + /* Increase the sequence number regardless of any buffer states, so + * that discontinuous sequence numbers always indicate lost frames. + */ + if (stream->last_fid != fid) + stream->sequence++; + /* Store the payload FID bit and return immediately when the buffer is * NULL. */ @@ -427,6 +466,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, else ktime_get_real_ts(&ts); + buf->buf.sequence = stream->sequence; buf->buf.timestamp.tv_sec = ts.tv_sec; buf->buf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC; @@ -688,6 +728,7 @@ static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream, if (buf->buf.bytesused == stream->queue.buf_used) { stream->queue.buf_used = 0; buf->state = UVC_BUF_STATE_READY; + buf->buf.sequence = ++stream->sequence; uvc_queue_next_buffer(&stream->queue, buf); stream->last_fid ^= UVC_STREAM_FID; } @@ -946,6 +987,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) unsigned int i; int ret; + stream->sequence = -1; stream->last_fid = -1; stream->bulk.header_size = 0; stream->bulk.skip_payload = 0; diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h index 892e0e51916..d97cf6d6a4f 100644 --- a/drivers/media/video/uvc/uvcvideo.h +++ b/drivers/media/video/uvc/uvcvideo.h @@ -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 @@ -173,6 +172,9 @@ struct uvc_xu_control { #define UVC_CTRL_CONTROL_TIMEOUT 300 #define UVC_CTRL_STREAMING_TIMEOUT 5000 +/* Maximum allowed number of control mappings per device */ +#define UVC_MAX_CONTROL_MAPPINGS 1024 + /* Devices quirks */ #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 #define UVC_QUIRK_PROBE_MINMAX 0x00000002 @@ -198,11 +200,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; @@ -235,17 +236,17 @@ struct uvc_control_mapping { struct uvc_control { struct uvc_entity *entity; - struct uvc_control_info *info; + struct uvc_control_info info; __u8 index; /* Used to match the uvc_control entry with a uvc_control_info. */ - __u8 dirty : 1, - loaded : 1, - modified : 1, - cached : 1; + __u8 dirty:1, + loaded:1, + modified:1, + cached:1, + initialized:1; __u8 *uvc_data; - __u8 *uvc_info; }; struct uvc_format_desc { @@ -392,7 +393,6 @@ struct uvc_video_queue { void *mem; unsigned int flags; - __u32 sequence; unsigned int count; unsigned int buf_size; @@ -413,7 +413,7 @@ struct uvc_video_chain { struct uvc_entity *processing; /* Processing unit */ struct uvc_entity *selector; /* Selector unit */ - struct mutex ctrl_mutex; + struct mutex ctrl_mutex; /* Protects ctrl.info */ }; struct uvc_streaming { @@ -458,6 +458,7 @@ struct uvc_streaming { dma_addr_t urb_dma[UVC_URBS]; unsigned int urb_size; + __u32 sequence; __u8 last_fid; }; @@ -474,8 +475,8 @@ struct uvc_device { char name[32]; enum uvc_device_state state; - struct list_head list; atomic_t users; + atomic_t nmappings; /* Video control interface */ __u16 uvc_version; @@ -509,11 +510,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 +611,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); |