2 * uvc_driver.c -- USB Video Class driver
4 * Copyright (C) 2005-2009
5 * Laurent Pinchart (laurent.pinchart@skynet.be)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
15 * This driver aims to support video input and ouput devices compliant with the
16 * 'USB Video Class' specification.
18 * The driver doesn't support the deprecated v4l1 interface. It implements the
19 * mmap capture method only, and doesn't do any image format conversion in
20 * software. If your user-space application doesn't support YUYV or MJPEG, fix
21 * it :-). Please note that the MJPEG data have been stripped from their
22 * Huffman tables (DHT marker), you will need to add it back if your JPEG
23 * codec can't handle MJPEG data.
26 #include <linux/kernel.h>
27 #include <linux/list.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/usb.h>
31 #include <linux/videodev2.h>
32 #include <linux/vmalloc.h>
33 #include <linux/wait.h>
34 #include <asm/atomic.h>
35 #include <asm/unaligned.h>
37 #include <media/v4l2-common.h>
41 #define DRIVER_AUTHOR "Laurent Pinchart <laurent.pinchart@skynet.be>"
42 #define DRIVER_DESC "USB Video Class driver"
43 #ifndef DRIVER_VERSION
44 #define DRIVER_VERSION "v0.1.0"
47 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
48 unsigned int uvc_no_drop_param;
49 static unsigned int uvc_quirks_param = -1;
50 unsigned int uvc_trace_param;
51 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
53 /* ------------------------------------------------------------------------
57 static struct uvc_format_desc uvc_fmts[] = {
59 .name = "YUV 4:2:2 (YUYV)",
60 .guid = UVC_GUID_FORMAT_YUY2,
61 .fcc = V4L2_PIX_FMT_YUYV,
64 .name = "YUV 4:2:2 (YUYV)",
65 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
66 .fcc = V4L2_PIX_FMT_YUYV,
69 .name = "YUV 4:2:0 (NV12)",
70 .guid = UVC_GUID_FORMAT_NV12,
71 .fcc = V4L2_PIX_FMT_NV12,
75 .guid = UVC_GUID_FORMAT_MJPEG,
76 .fcc = V4L2_PIX_FMT_MJPEG,
79 .name = "YVU 4:2:0 (YV12)",
80 .guid = UVC_GUID_FORMAT_YV12,
81 .fcc = V4L2_PIX_FMT_YVU420,
84 .name = "YUV 4:2:0 (I420)",
85 .guid = UVC_GUID_FORMAT_I420,
86 .fcc = V4L2_PIX_FMT_YUV420,
89 .name = "YUV 4:2:2 (UYVY)",
90 .guid = UVC_GUID_FORMAT_UYVY,
91 .fcc = V4L2_PIX_FMT_UYVY,
94 .name = "Greyscale (8-bit)",
95 .guid = UVC_GUID_FORMAT_Y800,
96 .fcc = V4L2_PIX_FMT_GREY,
99 .name = "Greyscale (16-bit)",
100 .guid = UVC_GUID_FORMAT_Y16,
101 .fcc = V4L2_PIX_FMT_Y16,
105 .guid = UVC_GUID_FORMAT_BY8,
106 .fcc = V4L2_PIX_FMT_SBGGR8,
110 /* ------------------------------------------------------------------------
114 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
117 struct usb_host_endpoint *ep;
120 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
121 ep = &alts->endpoint[i];
122 if (ep->desc.bEndpointAddress == epaddr)
129 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
131 unsigned int len = ARRAY_SIZE(uvc_fmts);
134 for (i = 0; i < len; ++i) {
135 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
142 static __u32 uvc_colorspace(const __u8 primaries)
144 static const __u8 colorprimaries[] = {
146 V4L2_COLORSPACE_SRGB,
147 V4L2_COLORSPACE_470_SYSTEM_M,
148 V4L2_COLORSPACE_470_SYSTEM_BG,
149 V4L2_COLORSPACE_SMPTE170M,
150 V4L2_COLORSPACE_SMPTE240M,
153 if (primaries < ARRAY_SIZE(colorprimaries))
154 return colorprimaries[primaries];
159 /* Simplify a fraction using a simple continued fraction decomposition. The
160 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
161 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
162 * arbitrary parameters to remove non-significative terms from the simple
163 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
164 * respectively seems to give nice results.
166 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
167 unsigned int n_terms, unsigned int threshold)
173 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
177 /* Convert the fraction to a simple continued fraction. See
178 * http://mathforum.org/dr.math/faq/faq.fractions.html
179 * Stop if the current term is bigger than or equal to the given
185 for (n = 0; n < n_terms && y != 0; ++n) {
187 if (an[n] >= threshold) {
198 /* Expand the simple continued fraction back to an integer fraction. */
202 for (i = n; i > 0; --i) {
213 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
214 * to compute numerator / denominator * 10000000 using 32 bit fixed point
217 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
221 /* Saturate the result if the operation would overflow. */
222 if (denominator == 0 ||
223 numerator/denominator >= ((uint32_t)-1)/10000000)
226 /* Divide both the denominator and the multiplier by two until
227 * numerator * multiplier doesn't overflow. If anyone knows a better
228 * algorithm please let me know.
230 multiplier = 10000000;
231 while (numerator > ((uint32_t)-1)/multiplier) {
236 return denominator ? numerator * multiplier / denominator : 0;
239 /* ------------------------------------------------------------------------
240 * Terminal and unit management
243 static struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
245 struct uvc_entity *entity;
247 list_for_each_entry(entity, &dev->entities, list) {
248 if (entity->id == id)
255 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
256 int id, struct uvc_entity *entity)
261 entity = list_entry(&dev->entities, struct uvc_entity, list);
263 list_for_each_entry_continue(entity, &dev->entities, list) {
264 for (i = 0; i < entity->bNrInPins; ++i)
265 if (entity->baSourceID[i] == id)
272 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
274 struct uvc_streaming *stream;
276 list_for_each_entry(stream, &dev->streams, list) {
277 if (stream->header.bTerminalLink == id)
284 /* ------------------------------------------------------------------------
285 * Descriptors parsing
288 static int uvc_parse_format(struct uvc_device *dev,
289 struct uvc_streaming *streaming, struct uvc_format *format,
290 __u32 **intervals, unsigned char *buffer, int buflen)
292 struct usb_interface *intf = streaming->intf;
293 struct usb_host_interface *alts = intf->cur_altsetting;
294 struct uvc_format_desc *fmtdesc;
295 struct uvc_frame *frame;
296 const unsigned char *start = buffer;
297 unsigned int interval;
301 format->type = buffer[2];
302 format->index = buffer[3];
305 case UVC_VS_FORMAT_UNCOMPRESSED:
306 case UVC_VS_FORMAT_FRAME_BASED:
307 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
309 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
310 "interface %d FORMAT error\n",
312 alts->desc.bInterfaceNumber);
316 /* Find the format descriptor from its GUID. */
317 fmtdesc = uvc_format_by_guid(&buffer[5]);
319 if (fmtdesc != NULL) {
320 strlcpy(format->name, fmtdesc->name,
321 sizeof format->name);
322 format->fcc = fmtdesc->fcc;
324 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
326 snprintf(format->name, sizeof(format->name), "%pUl\n",
331 format->bpp = buffer[21];
332 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
333 ftype = UVC_VS_FRAME_UNCOMPRESSED;
335 ftype = UVC_VS_FRAME_FRAME_BASED;
337 format->flags = UVC_FMT_FLAG_COMPRESSED;
341 case UVC_VS_FORMAT_MJPEG:
343 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
344 "interface %d FORMAT error\n",
346 alts->desc.bInterfaceNumber);
350 strlcpy(format->name, "MJPEG", sizeof format->name);
351 format->fcc = V4L2_PIX_FMT_MJPEG;
352 format->flags = UVC_FMT_FLAG_COMPRESSED;
354 ftype = UVC_VS_FRAME_MJPEG;
357 case UVC_VS_FORMAT_DV:
359 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
360 "interface %d FORMAT error\n",
362 alts->desc.bInterfaceNumber);
366 switch (buffer[8] & 0x7f) {
368 strlcpy(format->name, "SD-DV", sizeof format->name);
371 strlcpy(format->name, "SDL-DV", sizeof format->name);
374 strlcpy(format->name, "HD-DV", sizeof format->name);
377 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
378 "interface %d: unknown DV format %u\n",
380 alts->desc.bInterfaceNumber, buffer[8]);
384 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
385 sizeof format->name);
387 format->fcc = V4L2_PIX_FMT_DV;
388 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
392 /* Create a dummy frame descriptor. */
393 frame = &format->frame[0];
394 memset(&format->frame[0], 0, sizeof format->frame[0]);
395 frame->bFrameIntervalType = 1;
396 frame->dwDefaultFrameInterval = 1;
397 frame->dwFrameInterval = *intervals;
402 case UVC_VS_FORMAT_MPEG2TS:
403 case UVC_VS_FORMAT_STREAM_BASED:
404 /* Not supported yet. */
406 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
407 "interface %d unsupported format %u\n",
408 dev->udev->devnum, alts->desc.bInterfaceNumber,
413 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
418 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
419 * based formats have frame descriptors.
421 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
422 buffer[2] == ftype) {
423 frame = &format->frame[format->nframes];
424 if (ftype != UVC_VS_FRAME_FRAME_BASED)
425 n = buflen > 25 ? buffer[25] : 0;
427 n = buflen > 21 ? buffer[21] : 0;
431 if (buflen < 26 + 4*n) {
432 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
433 "interface %d FRAME error\n", dev->udev->devnum,
434 alts->desc.bInterfaceNumber);
438 frame->bFrameIndex = buffer[3];
439 frame->bmCapabilities = buffer[4];
440 frame->wWidth = get_unaligned_le16(&buffer[5]);
441 frame->wHeight = get_unaligned_le16(&buffer[7]);
442 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
443 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
444 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
445 frame->dwMaxVideoFrameBufferSize =
446 get_unaligned_le32(&buffer[17]);
447 frame->dwDefaultFrameInterval =
448 get_unaligned_le32(&buffer[21]);
449 frame->bFrameIntervalType = buffer[25];
451 frame->dwMaxVideoFrameBufferSize = 0;
452 frame->dwDefaultFrameInterval =
453 get_unaligned_le32(&buffer[17]);
454 frame->bFrameIntervalType = buffer[21];
456 frame->dwFrameInterval = *intervals;
458 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
459 * completely. Observed behaviours range from setting the
460 * value to 1.1x the actual frame size to hardwiring the
461 * 16 low bits to 0. This results in a higher than necessary
462 * memory usage as well as a wrong image size information. For
463 * uncompressed formats this can be fixed by computing the
464 * value from the frame size.
466 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
467 frame->dwMaxVideoFrameBufferSize = format->bpp
468 * frame->wWidth * frame->wHeight / 8;
470 /* Some bogus devices report dwMinFrameInterval equal to
471 * dwMaxFrameInterval and have dwFrameIntervalStep set to
472 * zero. Setting all null intervals to 1 fixes the problem and
473 * some other divisions by zero that could happen.
475 for (i = 0; i < n; ++i) {
476 interval = get_unaligned_le32(&buffer[26+4*i]);
477 *(*intervals)++ = interval ? interval : 1;
480 /* Make sure that the default frame interval stays between
483 n -= frame->bFrameIntervalType ? 1 : 2;
484 frame->dwDefaultFrameInterval =
485 min(frame->dwFrameInterval[n],
486 max(frame->dwFrameInterval[0],
487 frame->dwDefaultFrameInterval));
489 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
490 frame->bFrameIntervalType = 1;
491 frame->dwFrameInterval[0] =
492 frame->dwDefaultFrameInterval;
495 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
496 frame->wWidth, frame->wHeight,
497 10000000/frame->dwDefaultFrameInterval,
498 (100000000/frame->dwDefaultFrameInterval)%10);
505 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
506 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
511 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
512 buffer[2] == UVC_VS_COLORFORMAT) {
514 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
515 "interface %d COLORFORMAT error\n",
517 alts->desc.bInterfaceNumber);
521 format->colorspace = uvc_colorspace(buffer[3]);
527 return buffer - start;
530 static int uvc_parse_streaming(struct uvc_device *dev,
531 struct usb_interface *intf)
533 struct uvc_streaming *streaming = NULL;
534 struct uvc_format *format;
535 struct uvc_frame *frame;
536 struct usb_host_interface *alts = &intf->altsetting[0];
537 unsigned char *_buffer, *buffer = alts->extra;
538 int _buflen, buflen = alts->extralen;
539 unsigned int nformats = 0, nframes = 0, nintervals = 0;
540 unsigned int size, i, n, p;
545 if (intf->cur_altsetting->desc.bInterfaceSubClass
546 != UVC_SC_VIDEOSTREAMING) {
547 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
548 "video streaming interface\n", dev->udev->devnum,
549 intf->altsetting[0].desc.bInterfaceNumber);
553 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
554 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
555 "claimed\n", dev->udev->devnum,
556 intf->altsetting[0].desc.bInterfaceNumber);
560 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
561 if (streaming == NULL) {
562 usb_driver_release_interface(&uvc_driver.driver, intf);
566 mutex_init(&streaming->mutex);
567 streaming->dev = dev;
568 streaming->intf = usb_get_intf(intf);
569 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
571 /* The Pico iMage webcam has its class-specific interface descriptors
572 * after the endpoint descriptors.
575 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
576 struct usb_host_endpoint *ep = &alts->endpoint[i];
578 if (ep->extralen == 0)
581 if (ep->extralen > 2 &&
582 ep->extra[1] == USB_DT_CS_INTERFACE) {
583 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
584 "from endpoint %u.\n", i);
585 buffer = alts->endpoint[i].extra;
586 buflen = alts->endpoint[i].extralen;
592 /* Skip the standard interface descriptors. */
593 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
599 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
600 "interface descriptors found.\n");
604 /* Parse the header descriptor. */
606 case UVC_VS_OUTPUT_HEADER:
607 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
611 case UVC_VS_INPUT_HEADER:
612 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
617 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
618 "%d HEADER descriptor not found.\n", dev->udev->devnum,
619 alts->desc.bInterfaceNumber);
623 p = buflen >= 4 ? buffer[3] : 0;
624 n = buflen >= size ? buffer[size-1] : 0;
626 if (buflen < size + p*n) {
627 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
628 "interface %d HEADER descriptor is invalid.\n",
629 dev->udev->devnum, alts->desc.bInterfaceNumber);
633 streaming->header.bNumFormats = p;
634 streaming->header.bEndpointAddress = buffer[6];
635 if (buffer[2] == UVC_VS_INPUT_HEADER) {
636 streaming->header.bmInfo = buffer[7];
637 streaming->header.bTerminalLink = buffer[8];
638 streaming->header.bStillCaptureMethod = buffer[9];
639 streaming->header.bTriggerSupport = buffer[10];
640 streaming->header.bTriggerUsage = buffer[11];
642 streaming->header.bTerminalLink = buffer[7];
644 streaming->header.bControlSize = n;
646 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
648 if (streaming->header.bmaControls == NULL) {
659 /* Count the format and frame descriptors. */
660 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
661 switch (_buffer[2]) {
662 case UVC_VS_FORMAT_UNCOMPRESSED:
663 case UVC_VS_FORMAT_MJPEG:
664 case UVC_VS_FORMAT_FRAME_BASED:
668 case UVC_VS_FORMAT_DV:
669 /* DV format has no frame descriptor. We will create a
670 * dummy frame descriptor with a dummy frame interval.
677 case UVC_VS_FORMAT_MPEG2TS:
678 case UVC_VS_FORMAT_STREAM_BASED:
679 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
680 "interface %d FORMAT %u is not supported.\n",
682 alts->desc.bInterfaceNumber, _buffer[2]);
685 case UVC_VS_FRAME_UNCOMPRESSED:
686 case UVC_VS_FRAME_MJPEG:
689 nintervals += _buffer[25] ? _buffer[25] : 3;
692 case UVC_VS_FRAME_FRAME_BASED:
695 nintervals += _buffer[21] ? _buffer[21] : 3;
699 _buflen -= _buffer[0];
700 _buffer += _buffer[0];
704 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
705 "%d has no supported formats defined.\n",
706 dev->udev->devnum, alts->desc.bInterfaceNumber);
710 size = nformats * sizeof *format + nframes * sizeof *frame
711 + nintervals * sizeof *interval;
712 format = kzalloc(size, GFP_KERNEL);
713 if (format == NULL) {
718 frame = (struct uvc_frame *)&format[nformats];
719 interval = (__u32 *)&frame[nframes];
721 streaming->format = format;
722 streaming->nformats = nformats;
724 /* Parse the format descriptors. */
725 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
727 case UVC_VS_FORMAT_UNCOMPRESSED:
728 case UVC_VS_FORMAT_MJPEG:
729 case UVC_VS_FORMAT_DV:
730 case UVC_VS_FORMAT_FRAME_BASED:
731 format->frame = frame;
732 ret = uvc_parse_format(dev, streaming, format,
733 &interval, buffer, buflen);
737 frame += format->nframes;
753 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
754 "%d has %u bytes of trailing descriptor garbage.\n",
755 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
757 /* Parse the alternate settings to find the maximum bandwidth. */
758 for (i = 0; i < intf->num_altsetting; ++i) {
759 struct usb_host_endpoint *ep;
760 alts = &intf->altsetting[i];
761 ep = uvc_find_endpoint(alts,
762 streaming->header.bEndpointAddress);
766 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
767 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
768 if (psize > streaming->maxpsize)
769 streaming->maxpsize = psize;
772 list_add_tail(&streaming->list, &dev->streams);
776 usb_driver_release_interface(&uvc_driver.driver, intf);
778 kfree(streaming->format);
779 kfree(streaming->header.bmaControls);
784 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
785 unsigned int num_pads, unsigned int extra_size)
787 struct uvc_entity *entity;
788 unsigned int num_inputs;
791 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
792 size = sizeof(*entity) + extra_size + num_inputs;
793 entity = kzalloc(size, GFP_KERNEL);
800 entity->bNrInPins = num_inputs;
801 entity->baSourceID = ((__u8 *)entity) + sizeof(*entity) + extra_size;
806 /* Parse vendor-specific extensions. */
807 static int uvc_parse_vendor_control(struct uvc_device *dev,
808 const unsigned char *buffer, int buflen)
810 struct usb_device *udev = dev->udev;
811 struct usb_host_interface *alts = dev->intf->cur_altsetting;
812 struct uvc_entity *unit;
816 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
817 case 0x046d: /* Logitech */
818 if (buffer[1] != 0x41 || buffer[2] != 0x01)
821 /* Logitech implements several vendor specific functions
822 * through vendor specific extension units (LXU).
824 * The LXU descriptors are similar to XU descriptors
825 * (see "USB Device Video Class for Video Devices", section
826 * 3.7.2.6 "Extension Unit Descriptor") with the following
829 * ----------------------------------------------------------
831 * Size of this descriptor, in bytes: 24+p+n*2
832 * ----------------------------------------------------------
833 * 23+p+n bmControlsType N Bitmap
834 * Individual bits in the set are defined:
838 * This bitset is mapped exactly the same as bmControls.
839 * ----------------------------------------------------------
840 * 23+p+n*2 bReserved 1 Boolean
841 * ----------------------------------------------------------
842 * 24+p+n*2 iExtension 1 Index
843 * Index of a string descriptor that describes this
845 * ----------------------------------------------------------
847 p = buflen >= 22 ? buffer[21] : 0;
848 n = buflen >= 25 + p ? buffer[22+p] : 0;
850 if (buflen < 25 + p + 2*n) {
851 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
852 "interface %d EXTENSION_UNIT error\n",
853 udev->devnum, alts->desc.bInterfaceNumber);
857 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
862 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
863 unit->extension.bNumControls = buffer[20];
864 memcpy(unit->baSourceID, &buffer[22], p);
865 unit->extension.bControlSize = buffer[22+p];
866 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
867 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
869 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
871 if (buffer[24+p+2*n] != 0)
872 usb_string(udev, buffer[24+p+2*n], unit->name,
875 sprintf(unit->name, "Extension %u", buffer[3]);
877 list_add_tail(&unit->list, &dev->entities);
885 static int uvc_parse_standard_control(struct uvc_device *dev,
886 const unsigned char *buffer, int buflen)
888 struct usb_device *udev = dev->udev;
889 struct uvc_entity *unit, *term;
890 struct usb_interface *intf;
891 struct usb_host_interface *alts = dev->intf->cur_altsetting;
892 unsigned int i, n, p, len;
897 n = buflen >= 12 ? buffer[11] : 0;
899 if (buflen < 12 || buflen < 12 + n) {
900 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
901 "interface %d HEADER error\n", udev->devnum,
902 alts->desc.bInterfaceNumber);
906 dev->uvc_version = get_unaligned_le16(&buffer[3]);
907 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
909 /* Parse all USB Video Streaming interfaces. */
910 for (i = 0; i < n; ++i) {
911 intf = usb_ifnum_to_if(udev, buffer[12+i]);
913 uvc_trace(UVC_TRACE_DESCR, "device %d "
914 "interface %d doesn't exists\n",
919 uvc_parse_streaming(dev, intf);
923 case UVC_VC_INPUT_TERMINAL:
925 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
926 "interface %d INPUT_TERMINAL error\n",
927 udev->devnum, alts->desc.bInterfaceNumber);
931 /* Make sure the terminal type MSB is not null, otherwise it
932 * could be confused with a unit.
934 type = get_unaligned_le16(&buffer[4]);
935 if ((type & 0xff00) == 0) {
936 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
937 "interface %d INPUT_TERMINAL %d has invalid "
938 "type 0x%04x, skipping\n", udev->devnum,
939 alts->desc.bInterfaceNumber,
948 if (type == UVC_ITT_CAMERA) {
949 n = buflen >= 15 ? buffer[14] : 0;
952 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
953 n = buflen >= 9 ? buffer[8] : 0;
954 p = buflen >= 10 + n ? buffer[9+n] : 0;
958 if (buflen < len + n + p) {
959 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
960 "interface %d INPUT_TERMINAL error\n",
961 udev->devnum, alts->desc.bInterfaceNumber);
965 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
970 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
971 term->camera.bControlSize = n;
972 term->camera.bmControls = (__u8 *)term + sizeof *term;
973 term->camera.wObjectiveFocalLengthMin =
974 get_unaligned_le16(&buffer[8]);
975 term->camera.wObjectiveFocalLengthMax =
976 get_unaligned_le16(&buffer[10]);
977 term->camera.wOcularFocalLength =
978 get_unaligned_le16(&buffer[12]);
979 memcpy(term->camera.bmControls, &buffer[15], n);
980 } else if (UVC_ENTITY_TYPE(term) ==
981 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
982 term->media.bControlSize = n;
983 term->media.bmControls = (__u8 *)term + sizeof *term;
984 term->media.bTransportModeSize = p;
985 term->media.bmTransportModes = (__u8 *)term
987 memcpy(term->media.bmControls, &buffer[9], n);
988 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
992 usb_string(udev, buffer[7], term->name,
994 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
995 sprintf(term->name, "Camera %u", buffer[3]);
996 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
997 sprintf(term->name, "Media %u", buffer[3]);
999 sprintf(term->name, "Input %u", buffer[3]);
1001 list_add_tail(&term->list, &dev->entities);
1004 case UVC_VC_OUTPUT_TERMINAL:
1006 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1007 "interface %d OUTPUT_TERMINAL error\n",
1008 udev->devnum, alts->desc.bInterfaceNumber);
1012 /* Make sure the terminal type MSB is not null, otherwise it
1013 * could be confused with a unit.
1015 type = get_unaligned_le16(&buffer[4]);
1016 if ((type & 0xff00) == 0) {
1017 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1018 "interface %d OUTPUT_TERMINAL %d has invalid "
1019 "type 0x%04x, skipping\n", udev->devnum,
1020 alts->desc.bInterfaceNumber, buffer[3], type);
1024 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1029 memcpy(term->baSourceID, &buffer[7], 1);
1032 usb_string(udev, buffer[8], term->name,
1035 sprintf(term->name, "Output %u", buffer[3]);
1037 list_add_tail(&term->list, &dev->entities);
1040 case UVC_VC_SELECTOR_UNIT:
1041 p = buflen >= 5 ? buffer[4] : 0;
1043 if (buflen < 5 || buflen < 6 + p) {
1044 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1045 "interface %d SELECTOR_UNIT error\n",
1046 udev->devnum, alts->desc.bInterfaceNumber);
1050 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1054 memcpy(unit->baSourceID, &buffer[5], p);
1056 if (buffer[5+p] != 0)
1057 usb_string(udev, buffer[5+p], unit->name,
1060 sprintf(unit->name, "Selector %u", buffer[3]);
1062 list_add_tail(&unit->list, &dev->entities);
1065 case UVC_VC_PROCESSING_UNIT:
1066 n = buflen >= 8 ? buffer[7] : 0;
1067 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1069 if (buflen < p + n) {
1070 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1071 "interface %d PROCESSING_UNIT error\n",
1072 udev->devnum, alts->desc.bInterfaceNumber);
1076 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1080 memcpy(unit->baSourceID, &buffer[4], 1);
1081 unit->processing.wMaxMultiplier =
1082 get_unaligned_le16(&buffer[5]);
1083 unit->processing.bControlSize = buffer[7];
1084 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1085 memcpy(unit->processing.bmControls, &buffer[8], n);
1086 if (dev->uvc_version >= 0x0110)
1087 unit->processing.bmVideoStandards = buffer[9+n];
1089 if (buffer[8+n] != 0)
1090 usb_string(udev, buffer[8+n], unit->name,
1093 sprintf(unit->name, "Processing %u", buffer[3]);
1095 list_add_tail(&unit->list, &dev->entities);
1098 case UVC_VC_EXTENSION_UNIT:
1099 p = buflen >= 22 ? buffer[21] : 0;
1100 n = buflen >= 24 + p ? buffer[22+p] : 0;
1102 if (buflen < 24 + p + n) {
1103 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1104 "interface %d EXTENSION_UNIT error\n",
1105 udev->devnum, alts->desc.bInterfaceNumber);
1109 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1113 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1114 unit->extension.bNumControls = buffer[20];
1115 memcpy(unit->baSourceID, &buffer[22], p);
1116 unit->extension.bControlSize = buffer[22+p];
1117 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1118 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1120 if (buffer[23+p+n] != 0)
1121 usb_string(udev, buffer[23+p+n], unit->name,
1124 sprintf(unit->name, "Extension %u", buffer[3]);
1126 list_add_tail(&unit->list, &dev->entities);
1130 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1131 "descriptor (%u)\n", buffer[2]);
1138 static int uvc_parse_control(struct uvc_device *dev)
1140 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1141 unsigned char *buffer = alts->extra;
1142 int buflen = alts->extralen;
1145 /* Parse the default alternate setting only, as the UVC specification
1146 * defines a single alternate setting, the default alternate setting
1150 while (buflen > 2) {
1151 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1152 buffer[1] != USB_DT_CS_INTERFACE)
1153 goto next_descriptor;
1155 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1159 buflen -= buffer[0];
1160 buffer += buffer[0];
1163 /* Check if the optional status endpoint is present. Built-in iSight
1164 * webcams have an interrupt endpoint but spit proprietary data that
1165 * don't conform to the UVC status endpoint messages. Don't try to
1166 * handle the interrupt endpoint for those cameras.
1168 if (alts->desc.bNumEndpoints == 1 &&
1169 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1170 struct usb_host_endpoint *ep = &alts->endpoint[0];
1171 struct usb_endpoint_descriptor *desc = &ep->desc;
1173 if (usb_endpoint_is_int_in(desc) &&
1174 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1175 desc->bInterval != 0) {
1176 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1177 "(addr %02x).\n", desc->bEndpointAddress);
1185 /* ------------------------------------------------------------------------
1190 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1191 * and containing the following units:
1193 * - one or more Output Terminals (USB Streaming or Display)
1194 * - zero or one Processing Unit
1195 * - zero, one or more single-input Selector Units
1196 * - zero or one multiple-input Selector Units, provided all inputs are
1197 * connected to input terminals
1198 * - zero, one or mode single-input Extension Units
1199 * - one or more Input Terminals (Camera, External or USB Streaming)
1201 * The terminal and units must match on of the following structures:
1203 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1204 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1205 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1207 * +---------+ +---------+ -> OTT_*(0)
1208 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1209 * +---------+ +---------+ -> OTT_*(n)
1211 * The Processing Unit and Extension Units can be in any order. Additional
1212 * Extension Units connected to the main chain as single-unit branches are
1213 * also supported. Single-input Selector Units are ignored.
1215 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1216 struct uvc_entity *entity)
1218 switch (UVC_ENTITY_TYPE(entity)) {
1219 case UVC_VC_EXTENSION_UNIT:
1220 if (uvc_trace_param & UVC_TRACE_PROBE)
1221 printk(" <- XU %d", entity->id);
1223 if (entity->bNrInPins != 1) {
1224 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1225 "than 1 input pin.\n", entity->id);
1231 case UVC_VC_PROCESSING_UNIT:
1232 if (uvc_trace_param & UVC_TRACE_PROBE)
1233 printk(" <- PU %d", entity->id);
1235 if (chain->processing != NULL) {
1236 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1237 "Processing Units in chain.\n");
1241 chain->processing = entity;
1244 case UVC_VC_SELECTOR_UNIT:
1245 if (uvc_trace_param & UVC_TRACE_PROBE)
1246 printk(" <- SU %d", entity->id);
1248 /* Single-input selector units are ignored. */
1249 if (entity->bNrInPins == 1)
1252 if (chain->selector != NULL) {
1253 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1254 "Units in chain.\n");
1258 chain->selector = entity;
1261 case UVC_ITT_VENDOR_SPECIFIC:
1262 case UVC_ITT_CAMERA:
1263 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1264 if (uvc_trace_param & UVC_TRACE_PROBE)
1265 printk(" <- IT %d\n", entity->id);
1269 case UVC_TT_STREAMING:
1270 if (UVC_ENTITY_IS_ITERM(entity)) {
1271 if (uvc_trace_param & UVC_TRACE_PROBE)
1272 printk(" <- IT %d\n", entity->id);
1274 if (uvc_trace_param & UVC_TRACE_PROBE)
1275 printk(" OT %d", entity->id);
1281 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1282 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1286 list_add_tail(&entity->chain, &chain->entities);
1290 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1291 struct uvc_entity *entity, struct uvc_entity *prev)
1293 struct uvc_entity *forward;
1301 forward = uvc_entity_by_reference(chain->dev, entity->id,
1303 if (forward == NULL)
1305 if (forward == prev)
1308 switch (UVC_ENTITY_TYPE(forward)) {
1309 case UVC_VC_EXTENSION_UNIT:
1310 if (forward->bNrInPins != 1) {
1311 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1312 "has more than 1 input pin.\n",
1317 list_add_tail(&forward->chain, &chain->entities);
1318 if (uvc_trace_param & UVC_TRACE_PROBE) {
1322 printk(" XU %d", forward->id);
1327 case UVC_OTT_VENDOR_SPECIFIC:
1328 case UVC_OTT_DISPLAY:
1329 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1330 case UVC_TT_STREAMING:
1331 if (UVC_ENTITY_IS_ITERM(forward)) {
1332 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1333 "terminal %u.\n", forward->id);
1337 list_add_tail(&forward->chain, &chain->entities);
1338 if (uvc_trace_param & UVC_TRACE_PROBE) {
1342 printk(" OT %d", forward->id);
1354 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1355 struct uvc_entity **_entity)
1357 struct uvc_entity *entity = *_entity;
1358 struct uvc_entity *term;
1359 int id = -EINVAL, i;
1361 switch (UVC_ENTITY_TYPE(entity)) {
1362 case UVC_VC_EXTENSION_UNIT:
1363 case UVC_VC_PROCESSING_UNIT:
1364 id = entity->baSourceID[0];
1367 case UVC_VC_SELECTOR_UNIT:
1368 /* Single-input selector units are ignored. */
1369 if (entity->bNrInPins == 1) {
1370 id = entity->baSourceID[0];
1374 if (uvc_trace_param & UVC_TRACE_PROBE)
1377 chain->selector = entity;
1378 for (i = 0; i < entity->bNrInPins; ++i) {
1379 id = entity->baSourceID[i];
1380 term = uvc_entity_by_id(chain->dev, id);
1381 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1382 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1383 "input %d isn't connected to an "
1384 "input terminal\n", entity->id, i);
1388 if (uvc_trace_param & UVC_TRACE_PROBE)
1389 printk(" %d", term->id);
1391 list_add_tail(&term->chain, &chain->entities);
1392 uvc_scan_chain_forward(chain, term, entity);
1395 if (uvc_trace_param & UVC_TRACE_PROBE)
1401 case UVC_ITT_VENDOR_SPECIFIC:
1402 case UVC_ITT_CAMERA:
1403 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1404 case UVC_OTT_VENDOR_SPECIFIC:
1405 case UVC_OTT_DISPLAY:
1406 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1407 case UVC_TT_STREAMING:
1408 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1417 entity = uvc_entity_by_id(chain->dev, id);
1418 if (entity == NULL) {
1419 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1420 "unknown entity %d.\n", id);
1428 static int uvc_scan_chain(struct uvc_video_chain *chain,
1429 struct uvc_entity *term)
1431 struct uvc_entity *entity, *prev;
1433 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1438 while (entity != NULL) {
1439 /* Entity must not be part of an existing chain */
1440 if (entity->chain.next || entity->chain.prev) {
1441 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1442 "entity %d already in chain.\n", entity->id);
1446 /* Process entity */
1447 if (uvc_scan_chain_entity(chain, entity) < 0)
1451 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1456 if (uvc_scan_chain_backward(chain, &entity) < 0)
1463 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1466 struct uvc_entity *term;
1467 unsigned int nterms = 0;
1470 list_for_each_entry(term, terms, chain) {
1471 if (!UVC_ENTITY_IS_TERM(term) ||
1472 UVC_TERM_DIRECTION(term) != dir)
1476 p += sprintf(p, ",");
1477 if (++nterms >= 4) {
1478 p += sprintf(p, "...");
1481 p += sprintf(p, "%u", term->id);
1487 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1489 static char buffer[43];
1492 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1493 p += sprintf(p, " -> ");
1494 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1500 * Scan the device for video chains and register video devices.
1502 * Chains are scanned starting at their output terminals and walked backwards.
1504 static int uvc_scan_device(struct uvc_device *dev)
1506 struct uvc_video_chain *chain;
1507 struct uvc_entity *term;
1509 list_for_each_entry(term, &dev->entities, list) {
1510 if (!UVC_ENTITY_IS_OTERM(term))
1513 /* If the terminal is already included in a chain, skip it.
1514 * This can happen for chains that have multiple output
1515 * terminals, where all output terminals beside the first one
1516 * will be inserted in the chain in forward scans.
1518 if (term->chain.next || term->chain.prev)
1521 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1525 INIT_LIST_HEAD(&chain->entities);
1526 mutex_init(&chain->ctrl_mutex);
1529 if (uvc_scan_chain(chain, term) < 0) {
1534 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1535 uvc_print_chain(chain));
1537 list_add_tail(&chain->list, &dev->chains);
1540 if (list_empty(&dev->chains)) {
1541 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1548 /* ------------------------------------------------------------------------
1549 * Video device registration and unregistration
1553 * Delete the UVC device.
1555 * Called by the kernel when the last reference to the uvc_device structure
1558 * As this function is called after or during disconnect(), all URBs have
1559 * already been canceled by the USB core. There is no need to kill the
1560 * interrupt URB manually.
1562 static void uvc_delete(struct uvc_device *dev)
1564 struct list_head *p, *n;
1566 usb_put_intf(dev->intf);
1567 usb_put_dev(dev->udev);
1569 uvc_status_cleanup(dev);
1570 uvc_ctrl_cleanup_device(dev);
1572 list_for_each_safe(p, n, &dev->chains) {
1573 struct uvc_video_chain *chain;
1574 chain = list_entry(p, struct uvc_video_chain, list);
1578 list_for_each_safe(p, n, &dev->entities) {
1579 struct uvc_entity *entity;
1580 entity = list_entry(p, struct uvc_entity, list);
1584 list_for_each_safe(p, n, &dev->streams) {
1585 struct uvc_streaming *streaming;
1586 streaming = list_entry(p, struct uvc_streaming, list);
1587 usb_driver_release_interface(&uvc_driver.driver,
1589 usb_put_intf(streaming->intf);
1590 kfree(streaming->format);
1591 kfree(streaming->header.bmaControls);
1598 static void uvc_release(struct video_device *vdev)
1600 struct uvc_streaming *stream = video_get_drvdata(vdev);
1601 struct uvc_device *dev = stream->dev;
1603 video_device_release(vdev);
1605 /* Decrement the registered streams count and delete the device when it
1608 if (atomic_dec_and_test(&dev->nstreams))
1613 * Unregister the video devices.
1615 static void uvc_unregister_video(struct uvc_device *dev)
1617 struct uvc_streaming *stream;
1619 /* Unregistering all video devices might result in uvc_delete() being
1620 * called from inside the loop if there's no open file handle. To avoid
1621 * that, increment the stream count before iterating over the streams
1622 * and decrement it when done.
1624 atomic_inc(&dev->nstreams);
1626 list_for_each_entry(stream, &dev->streams, list) {
1627 if (stream->vdev == NULL)
1630 video_unregister_device(stream->vdev);
1631 stream->vdev = NULL;
1634 /* Decrement the stream count and call uvc_delete explicitly if there
1635 * are no stream left.
1637 if (atomic_dec_and_test(&dev->nstreams))
1641 static int uvc_register_video(struct uvc_device *dev,
1642 struct uvc_streaming *stream)
1644 struct video_device *vdev;
1647 /* Initialize the streaming interface with default streaming
1650 ret = uvc_video_init(stream);
1652 uvc_printk(KERN_ERR, "Failed to initialize the device "
1657 /* Register the device with V4L. */
1658 vdev = video_device_alloc();
1660 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1665 /* We already hold a reference to dev->udev. The video device will be
1666 * unregistered before the reference is released, so we don't need to
1669 vdev->parent = &dev->intf->dev;
1670 vdev->fops = &uvc_fops;
1671 vdev->release = uvc_release;
1672 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1674 /* Set the driver data before calling video_register_device, otherwise
1675 * uvc_v4l2_open might race us.
1677 stream->vdev = vdev;
1678 video_set_drvdata(vdev, stream);
1680 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1682 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1684 stream->vdev = NULL;
1685 video_device_release(vdev);
1689 atomic_inc(&dev->nstreams);
1694 * Register all video devices in all chains.
1696 static int uvc_register_terms(struct uvc_device *dev,
1697 struct uvc_video_chain *chain)
1699 struct uvc_streaming *stream;
1700 struct uvc_entity *term;
1703 list_for_each_entry(term, &chain->entities, chain) {
1704 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1707 stream = uvc_stream_by_id(dev, term->id);
1708 if (stream == NULL) {
1709 uvc_printk(KERN_INFO, "No streaming interface found "
1710 "for terminal %u.", term->id);
1714 stream->chain = chain;
1715 ret = uvc_register_video(dev, stream);
1723 static int uvc_register_chains(struct uvc_device *dev)
1725 struct uvc_video_chain *chain;
1728 list_for_each_entry(chain, &dev->chains, list) {
1729 ret = uvc_register_terms(dev, chain);
1737 /* ------------------------------------------------------------------------
1738 * USB probe, disconnect, suspend and resume
1741 static int uvc_probe(struct usb_interface *intf,
1742 const struct usb_device_id *id)
1744 struct usb_device *udev = interface_to_usbdev(intf);
1745 struct uvc_device *dev;
1748 if (id->idVendor && id->idProduct)
1749 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1750 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1753 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1756 /* Allocate memory for the device and initialize it. */
1757 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1760 INIT_LIST_HEAD(&dev->entities);
1761 INIT_LIST_HEAD(&dev->chains);
1762 INIT_LIST_HEAD(&dev->streams);
1763 atomic_set(&dev->nstreams, 0);
1764 atomic_set(&dev->users, 0);
1766 dev->udev = usb_get_dev(udev);
1767 dev->intf = usb_get_intf(intf);
1768 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1769 dev->quirks = (uvc_quirks_param == -1)
1770 ? id->driver_info : uvc_quirks_param;
1772 if (udev->product != NULL)
1773 strlcpy(dev->name, udev->product, sizeof dev->name);
1775 snprintf(dev->name, sizeof dev->name,
1776 "UVC Camera (%04x:%04x)",
1777 le16_to_cpu(udev->descriptor.idVendor),
1778 le16_to_cpu(udev->descriptor.idProduct));
1780 /* Parse the Video Class control descriptor. */
1781 if (uvc_parse_control(dev) < 0) {
1782 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1787 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1788 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1789 udev->product ? udev->product : "<unnamed>",
1790 le16_to_cpu(udev->descriptor.idVendor),
1791 le16_to_cpu(udev->descriptor.idProduct));
1793 if (dev->quirks != id->driver_info) {
1794 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1795 "parameter for testing purpose.\n", dev->quirks);
1796 uvc_printk(KERN_INFO, "Please report required quirks to the "
1797 "linux-uvc-devel mailing list.\n");
1800 /* Initialize controls. */
1801 if (uvc_ctrl_init_device(dev) < 0)
1804 /* Scan the device for video chains. */
1805 if (uvc_scan_device(dev) < 0)
1808 /* Register video devices. */
1809 if (uvc_register_chains(dev) < 0)
1812 /* Save our data pointer in the interface data. */
1813 usb_set_intfdata(intf, dev);
1815 /* Initialize the interrupt URB. */
1816 if ((ret = uvc_status_init(dev)) < 0) {
1817 uvc_printk(KERN_INFO, "Unable to initialize the status "
1818 "endpoint (%d), status interrupt will not be "
1819 "supported.\n", ret);
1822 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1823 usb_enable_autosuspend(udev);
1827 uvc_unregister_video(dev);
1831 static void uvc_disconnect(struct usb_interface *intf)
1833 struct uvc_device *dev = usb_get_intfdata(intf);
1835 /* Set the USB interface data to NULL. This can be done outside the
1836 * lock, as there's no other reader.
1838 usb_set_intfdata(intf, NULL);
1840 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1841 UVC_SC_VIDEOSTREAMING)
1844 dev->state |= UVC_DEV_DISCONNECTED;
1846 uvc_unregister_video(dev);
1849 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1851 struct uvc_device *dev = usb_get_intfdata(intf);
1852 struct uvc_streaming *stream;
1854 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1855 intf->cur_altsetting->desc.bInterfaceNumber);
1857 /* Controls are cached on the fly so they don't need to be saved. */
1858 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1859 UVC_SC_VIDEOCONTROL)
1860 return uvc_status_suspend(dev);
1862 list_for_each_entry(stream, &dev->streams, list) {
1863 if (stream->intf == intf)
1864 return uvc_video_suspend(stream);
1867 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1872 static int __uvc_resume(struct usb_interface *intf, int reset)
1874 struct uvc_device *dev = usb_get_intfdata(intf);
1875 struct uvc_streaming *stream;
1877 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
1878 intf->cur_altsetting->desc.bInterfaceNumber);
1880 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1881 UVC_SC_VIDEOCONTROL) {
1883 int ret = uvc_ctrl_resume_device(dev);
1889 return uvc_status_resume(dev);
1892 list_for_each_entry(stream, &dev->streams, list) {
1893 if (stream->intf == intf)
1894 return uvc_video_resume(stream);
1897 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
1902 static int uvc_resume(struct usb_interface *intf)
1904 return __uvc_resume(intf, 0);
1907 static int uvc_reset_resume(struct usb_interface *intf)
1909 return __uvc_resume(intf, 1);
1912 /* ------------------------------------------------------------------------
1916 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
1918 if (uvc_clock_param == CLOCK_MONOTONIC)
1919 return sprintf(buffer, "CLOCK_MONOTONIC");
1921 return sprintf(buffer, "CLOCK_REALTIME");
1924 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
1926 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
1927 val += strlen("clock_");
1929 if (strcasecmp(val, "monotonic") == 0)
1930 uvc_clock_param = CLOCK_MONOTONIC;
1931 else if (strcasecmp(val, "realtime") == 0)
1932 uvc_clock_param = CLOCK_REALTIME;
1939 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
1940 &uvc_clock_param, S_IRUGO|S_IWUSR);
1941 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
1942 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
1943 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
1944 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
1945 MODULE_PARM_DESC(quirks, "Forced device quirks");
1946 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
1947 MODULE_PARM_DESC(trace, "Trace level bitmask");
1948 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
1949 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
1951 /* ------------------------------------------------------------------------
1952 * Driver initialization and cleanup
1956 * The Logitech cameras listed below have their interface class set to
1957 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
1958 * though they are compliant.
1960 static struct usb_device_id uvc_ids[] = {
1961 /* Genius eFace 2025 */
1962 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1963 | USB_DEVICE_ID_MATCH_INT_INFO,
1965 .idProduct = 0x706e,
1966 .bInterfaceClass = USB_CLASS_VIDEO,
1967 .bInterfaceSubClass = 1,
1968 .bInterfaceProtocol = 0,
1969 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1970 /* Microsoft Lifecam NX-6000 */
1971 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1972 | USB_DEVICE_ID_MATCH_INT_INFO,
1974 .idProduct = 0x00f8,
1975 .bInterfaceClass = USB_CLASS_VIDEO,
1976 .bInterfaceSubClass = 1,
1977 .bInterfaceProtocol = 0,
1978 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1979 /* Microsoft Lifecam VX-7000 */
1980 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1981 | USB_DEVICE_ID_MATCH_INT_INFO,
1983 .idProduct = 0x0723,
1984 .bInterfaceClass = USB_CLASS_VIDEO,
1985 .bInterfaceSubClass = 1,
1986 .bInterfaceProtocol = 0,
1987 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1988 /* Logitech Quickcam Fusion */
1989 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1990 | USB_DEVICE_ID_MATCH_INT_INFO,
1992 .idProduct = 0x08c1,
1993 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
1994 .bInterfaceSubClass = 1,
1995 .bInterfaceProtocol = 0 },
1996 /* Logitech Quickcam Orbit MP */
1997 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1998 | USB_DEVICE_ID_MATCH_INT_INFO,
2000 .idProduct = 0x08c2,
2001 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2002 .bInterfaceSubClass = 1,
2003 .bInterfaceProtocol = 0 },
2004 /* Logitech Quickcam Pro for Notebook */
2005 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2006 | USB_DEVICE_ID_MATCH_INT_INFO,
2008 .idProduct = 0x08c3,
2009 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2010 .bInterfaceSubClass = 1,
2011 .bInterfaceProtocol = 0 },
2012 /* Logitech Quickcam Pro 5000 */
2013 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2014 | USB_DEVICE_ID_MATCH_INT_INFO,
2016 .idProduct = 0x08c5,
2017 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2018 .bInterfaceSubClass = 1,
2019 .bInterfaceProtocol = 0 },
2020 /* Logitech Quickcam OEM Dell Notebook */
2021 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2022 | USB_DEVICE_ID_MATCH_INT_INFO,
2024 .idProduct = 0x08c6,
2025 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2026 .bInterfaceSubClass = 1,
2027 .bInterfaceProtocol = 0 },
2028 /* Logitech Quickcam OEM Cisco VT Camera II */
2029 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2030 | USB_DEVICE_ID_MATCH_INT_INFO,
2032 .idProduct = 0x08c7,
2033 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2034 .bInterfaceSubClass = 1,
2035 .bInterfaceProtocol = 0 },
2036 /* Chicony CNF7129 (Asus EEE 100HE) */
2037 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2038 | USB_DEVICE_ID_MATCH_INT_INFO,
2040 .idProduct = 0xb071,
2041 .bInterfaceClass = USB_CLASS_VIDEO,
2042 .bInterfaceSubClass = 1,
2043 .bInterfaceProtocol = 0,
2044 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2045 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2046 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2047 | USB_DEVICE_ID_MATCH_INT_INFO,
2049 .idProduct = 0x3820,
2050 .bInterfaceClass = USB_CLASS_VIDEO,
2051 .bInterfaceSubClass = 1,
2052 .bInterfaceProtocol = 0,
2053 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2054 /* Apple Built-In iSight */
2055 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2056 | USB_DEVICE_ID_MATCH_INT_INFO,
2058 .idProduct = 0x8501,
2059 .bInterfaceClass = USB_CLASS_VIDEO,
2060 .bInterfaceSubClass = 1,
2061 .bInterfaceProtocol = 0,
2062 .driver_info = UVC_QUIRK_PROBE_MINMAX
2063 | UVC_QUIRK_BUILTIN_ISIGHT },
2064 /* Genesys Logic USB 2.0 PC Camera */
2065 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2066 | USB_DEVICE_ID_MATCH_INT_INFO,
2068 .idProduct = 0x0505,
2069 .bInterfaceClass = USB_CLASS_VIDEO,
2070 .bInterfaceSubClass = 1,
2071 .bInterfaceProtocol = 0,
2072 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2074 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2075 | USB_DEVICE_ID_MATCH_INT_INFO,
2077 .idProduct = 0x332d,
2078 .bInterfaceClass = USB_CLASS_VIDEO,
2079 .bInterfaceSubClass = 1,
2080 .bInterfaceProtocol = 0,
2081 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2082 /* ViMicro - Minoru3D */
2083 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2084 | USB_DEVICE_ID_MATCH_INT_INFO,
2086 .idProduct = 0x3410,
2087 .bInterfaceClass = USB_CLASS_VIDEO,
2088 .bInterfaceSubClass = 1,
2089 .bInterfaceProtocol = 0,
2090 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2091 /* ViMicro Venus - Minoru3D */
2092 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2093 | USB_DEVICE_ID_MATCH_INT_INFO,
2095 .idProduct = 0x3420,
2096 .bInterfaceClass = USB_CLASS_VIDEO,
2097 .bInterfaceSubClass = 1,
2098 .bInterfaceProtocol = 0,
2099 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2101 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2102 | USB_DEVICE_ID_MATCH_INT_INFO,
2104 .idProduct = 0x0004,
2105 .bInterfaceClass = USB_CLASS_VIDEO,
2106 .bInterfaceSubClass = 1,
2107 .bInterfaceProtocol = 0,
2108 .driver_info = UVC_QUIRK_PROBE_MINMAX
2109 | UVC_QUIRK_PROBE_DEF },
2110 /* IMC Networks (Medion Akoya) */
2111 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2112 | USB_DEVICE_ID_MATCH_INT_INFO,
2114 .idProduct = 0x5103,
2115 .bInterfaceClass = USB_CLASS_VIDEO,
2116 .bInterfaceSubClass = 1,
2117 .bInterfaceProtocol = 0,
2118 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2119 /* Syntek (HP Spartan) */
2120 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2121 | USB_DEVICE_ID_MATCH_INT_INFO,
2123 .idProduct = 0x5212,
2124 .bInterfaceClass = USB_CLASS_VIDEO,
2125 .bInterfaceSubClass = 1,
2126 .bInterfaceProtocol = 0,
2127 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2128 /* Syntek (Samsung Q310) */
2129 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2130 | USB_DEVICE_ID_MATCH_INT_INFO,
2132 .idProduct = 0x5931,
2133 .bInterfaceClass = USB_CLASS_VIDEO,
2134 .bInterfaceSubClass = 1,
2135 .bInterfaceProtocol = 0,
2136 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2137 /* Syntek (Packard Bell EasyNote MX52 */
2138 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2139 | USB_DEVICE_ID_MATCH_INT_INFO,
2141 .idProduct = 0x8a12,
2142 .bInterfaceClass = USB_CLASS_VIDEO,
2143 .bInterfaceSubClass = 1,
2144 .bInterfaceProtocol = 0,
2145 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2146 /* Syntek (Asus F9SG) */
2147 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2148 | USB_DEVICE_ID_MATCH_INT_INFO,
2150 .idProduct = 0x8a31,
2151 .bInterfaceClass = USB_CLASS_VIDEO,
2152 .bInterfaceSubClass = 1,
2153 .bInterfaceProtocol = 0,
2154 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2155 /* Syntek (Asus U3S) */
2156 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2157 | USB_DEVICE_ID_MATCH_INT_INFO,
2159 .idProduct = 0x8a33,
2160 .bInterfaceClass = USB_CLASS_VIDEO,
2161 .bInterfaceSubClass = 1,
2162 .bInterfaceProtocol = 0,
2163 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2164 /* Syntek (JAOtech Smart Terminal) */
2165 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2166 | USB_DEVICE_ID_MATCH_INT_INFO,
2168 .idProduct = 0x8a34,
2169 .bInterfaceClass = USB_CLASS_VIDEO,
2170 .bInterfaceSubClass = 1,
2171 .bInterfaceProtocol = 0,
2172 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2174 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2175 | USB_DEVICE_ID_MATCH_INT_INFO,
2177 .idProduct = 0x0202,
2178 .bInterfaceClass = USB_CLASS_VIDEO,
2179 .bInterfaceSubClass = 1,
2180 .bInterfaceProtocol = 0,
2181 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2182 /* Lenovo Thinkpad SL400/SL500 */
2183 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2184 | USB_DEVICE_ID_MATCH_INT_INFO,
2186 .idProduct = 0x480b,
2187 .bInterfaceClass = USB_CLASS_VIDEO,
2188 .bInterfaceSubClass = 1,
2189 .bInterfaceProtocol = 0,
2190 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2191 /* Aveo Technology USB 2.0 Camera */
2192 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2193 | USB_DEVICE_ID_MATCH_INT_INFO,
2195 .idProduct = 0x0306,
2196 .bInterfaceClass = USB_CLASS_VIDEO,
2197 .bInterfaceSubClass = 1,
2198 .bInterfaceProtocol = 0,
2199 .driver_info = UVC_QUIRK_PROBE_MINMAX
2200 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2201 /* Ecamm Pico iMage */
2202 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2203 | USB_DEVICE_ID_MATCH_INT_INFO,
2205 .idProduct = 0xcafe,
2206 .bInterfaceClass = USB_CLASS_VIDEO,
2207 .bInterfaceSubClass = 1,
2208 .bInterfaceProtocol = 0,
2209 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2210 /* Manta MM-353 Plako */
2211 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2212 | USB_DEVICE_ID_MATCH_INT_INFO,
2214 .idProduct = 0x3188,
2215 .bInterfaceClass = USB_CLASS_VIDEO,
2216 .bInterfaceSubClass = 1,
2217 .bInterfaceProtocol = 0,
2218 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2219 /* FSC WebCam V30S */
2220 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2221 | USB_DEVICE_ID_MATCH_INT_INFO,
2223 .idProduct = 0x3288,
2224 .bInterfaceClass = USB_CLASS_VIDEO,
2225 .bInterfaceSubClass = 1,
2226 .bInterfaceProtocol = 0,
2227 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2228 /* Arkmicro unbranded */
2229 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2230 | USB_DEVICE_ID_MATCH_INT_INFO,
2232 .idProduct = 0x3290,
2233 .bInterfaceClass = USB_CLASS_VIDEO,
2234 .bInterfaceSubClass = 1,
2235 .bInterfaceProtocol = 0,
2236 .driver_info = UVC_QUIRK_PROBE_DEF },
2237 /* Bodelin ProScopeHR */
2238 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2239 | USB_DEVICE_ID_MATCH_DEV_HI
2240 | USB_DEVICE_ID_MATCH_INT_INFO,
2242 .idProduct = 0x1000,
2243 .bcdDevice_hi = 0x0126,
2244 .bInterfaceClass = USB_CLASS_VIDEO,
2245 .bInterfaceSubClass = 1,
2246 .bInterfaceProtocol = 0,
2247 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2248 /* MSI StarCam 370i */
2249 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2250 | USB_DEVICE_ID_MATCH_INT_INFO,
2252 .idProduct = 0x2951,
2253 .bInterfaceClass = USB_CLASS_VIDEO,
2254 .bInterfaceSubClass = 1,
2255 .bInterfaceProtocol = 0,
2256 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2257 /* SiGma Micro USB Web Camera */
2258 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2259 | USB_DEVICE_ID_MATCH_INT_INFO,
2261 .idProduct = 0x3000,
2262 .bInterfaceClass = USB_CLASS_VIDEO,
2263 .bInterfaceSubClass = 1,
2264 .bInterfaceProtocol = 0,
2265 .driver_info = UVC_QUIRK_PROBE_MINMAX
2266 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2267 /* Generic USB Video Class */
2268 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2272 MODULE_DEVICE_TABLE(usb, uvc_ids);
2274 struct uvc_driver uvc_driver = {
2278 .disconnect = uvc_disconnect,
2279 .suspend = uvc_suspend,
2280 .resume = uvc_resume,
2281 .reset_resume = uvc_reset_resume,
2282 .id_table = uvc_ids,
2283 .supports_autosuspend = 1,
2287 static int __init uvc_init(void)
2291 INIT_LIST_HEAD(&uvc_driver.devices);
2292 INIT_LIST_HEAD(&uvc_driver.controls);
2293 mutex_init(&uvc_driver.ctrl_mutex);
2297 result = usb_register(&uvc_driver.driver);
2299 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2303 static void __exit uvc_cleanup(void)
2305 usb_deregister(&uvc_driver.driver);
2309 module_init(uvc_init);
2310 module_exit(uvc_cleanup);
2312 MODULE_AUTHOR(DRIVER_AUTHOR);
2313 MODULE_DESCRIPTION(DRIVER_DESC);
2314 MODULE_LICENSE("GPL");
2315 MODULE_VERSION(DRIVER_VERSION);