2 * uvc_driver.c -- USB Video Class driver
4 * Copyright (C) 2005-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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 " \
42 "<laurent.pinchart@ideasonboard.com>"
43 #define DRIVER_DESC "USB Video Class driver"
45 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
46 unsigned int uvc_no_drop_param;
47 static unsigned int uvc_quirks_param = -1;
48 unsigned int uvc_trace_param;
49 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
51 /* ------------------------------------------------------------------------
55 static struct uvc_format_desc uvc_fmts[] = {
57 .name = "YUV 4:2:2 (YUYV)",
58 .guid = UVC_GUID_FORMAT_YUY2,
59 .fcc = V4L2_PIX_FMT_YUYV,
62 .name = "YUV 4:2:2 (YUYV)",
63 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
64 .fcc = V4L2_PIX_FMT_YUYV,
67 .name = "YUV 4:2:0 (NV12)",
68 .guid = UVC_GUID_FORMAT_NV12,
69 .fcc = V4L2_PIX_FMT_NV12,
73 .guid = UVC_GUID_FORMAT_MJPEG,
74 .fcc = V4L2_PIX_FMT_MJPEG,
77 .name = "YVU 4:2:0 (YV12)",
78 .guid = UVC_GUID_FORMAT_YV12,
79 .fcc = V4L2_PIX_FMT_YVU420,
82 .name = "YUV 4:2:0 (I420)",
83 .guid = UVC_GUID_FORMAT_I420,
84 .fcc = V4L2_PIX_FMT_YUV420,
87 .name = "YUV 4:2:2 (UYVY)",
88 .guid = UVC_GUID_FORMAT_UYVY,
89 .fcc = V4L2_PIX_FMT_UYVY,
92 .name = "Greyscale (8-bit)",
93 .guid = UVC_GUID_FORMAT_Y800,
94 .fcc = V4L2_PIX_FMT_GREY,
97 .name = "Greyscale (16-bit)",
98 .guid = UVC_GUID_FORMAT_Y16,
99 .fcc = V4L2_PIX_FMT_Y16,
103 .guid = UVC_GUID_FORMAT_BY8,
104 .fcc = V4L2_PIX_FMT_SBGGR8,
108 /* ------------------------------------------------------------------------
112 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
115 struct usb_host_endpoint *ep;
118 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
119 ep = &alts->endpoint[i];
120 if (ep->desc.bEndpointAddress == epaddr)
127 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
129 unsigned int len = ARRAY_SIZE(uvc_fmts);
132 for (i = 0; i < len; ++i) {
133 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
140 static __u32 uvc_colorspace(const __u8 primaries)
142 static const __u8 colorprimaries[] = {
144 V4L2_COLORSPACE_SRGB,
145 V4L2_COLORSPACE_470_SYSTEM_M,
146 V4L2_COLORSPACE_470_SYSTEM_BG,
147 V4L2_COLORSPACE_SMPTE170M,
148 V4L2_COLORSPACE_SMPTE240M,
151 if (primaries < ARRAY_SIZE(colorprimaries))
152 return colorprimaries[primaries];
157 /* Simplify a fraction using a simple continued fraction decomposition. The
158 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
159 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
160 * arbitrary parameters to remove non-significative terms from the simple
161 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
162 * respectively seems to give nice results.
164 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
165 unsigned int n_terms, unsigned int threshold)
171 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
175 /* Convert the fraction to a simple continued fraction. See
176 * http://mathforum.org/dr.math/faq/faq.fractions.html
177 * Stop if the current term is bigger than or equal to the given
183 for (n = 0; n < n_terms && y != 0; ++n) {
185 if (an[n] >= threshold) {
196 /* Expand the simple continued fraction back to an integer fraction. */
200 for (i = n; i > 0; --i) {
211 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
212 * to compute numerator / denominator * 10000000 using 32 bit fixed point
215 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
219 /* Saturate the result if the operation would overflow. */
220 if (denominator == 0 ||
221 numerator/denominator >= ((uint32_t)-1)/10000000)
224 /* Divide both the denominator and the multiplier by two until
225 * numerator * multiplier doesn't overflow. If anyone knows a better
226 * algorithm please let me know.
228 multiplier = 10000000;
229 while (numerator > ((uint32_t)-1)/multiplier) {
234 return denominator ? numerator * multiplier / denominator : 0;
237 /* ------------------------------------------------------------------------
238 * Terminal and unit management
241 static struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
243 struct uvc_entity *entity;
245 list_for_each_entry(entity, &dev->entities, list) {
246 if (entity->id == id)
253 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
254 int id, struct uvc_entity *entity)
259 entity = list_entry(&dev->entities, struct uvc_entity, list);
261 list_for_each_entry_continue(entity, &dev->entities, list) {
262 for (i = 0; i < entity->bNrInPins; ++i)
263 if (entity->baSourceID[i] == id)
270 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
272 struct uvc_streaming *stream;
274 list_for_each_entry(stream, &dev->streams, list) {
275 if (stream->header.bTerminalLink == id)
282 /* ------------------------------------------------------------------------
283 * Descriptors parsing
286 static int uvc_parse_format(struct uvc_device *dev,
287 struct uvc_streaming *streaming, struct uvc_format *format,
288 __u32 **intervals, unsigned char *buffer, int buflen)
290 struct usb_interface *intf = streaming->intf;
291 struct usb_host_interface *alts = intf->cur_altsetting;
292 struct uvc_format_desc *fmtdesc;
293 struct uvc_frame *frame;
294 const unsigned char *start = buffer;
295 unsigned int interval;
299 format->type = buffer[2];
300 format->index = buffer[3];
303 case UVC_VS_FORMAT_UNCOMPRESSED:
304 case UVC_VS_FORMAT_FRAME_BASED:
305 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
307 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
308 "interface %d FORMAT error\n",
310 alts->desc.bInterfaceNumber);
314 /* Find the format descriptor from its GUID. */
315 fmtdesc = uvc_format_by_guid(&buffer[5]);
317 if (fmtdesc != NULL) {
318 strlcpy(format->name, fmtdesc->name,
319 sizeof format->name);
320 format->fcc = fmtdesc->fcc;
322 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
324 snprintf(format->name, sizeof(format->name), "%pUl\n",
329 format->bpp = buffer[21];
330 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
331 ftype = UVC_VS_FRAME_UNCOMPRESSED;
333 ftype = UVC_VS_FRAME_FRAME_BASED;
335 format->flags = UVC_FMT_FLAG_COMPRESSED;
339 case UVC_VS_FORMAT_MJPEG:
341 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
342 "interface %d FORMAT error\n",
344 alts->desc.bInterfaceNumber);
348 strlcpy(format->name, "MJPEG", sizeof format->name);
349 format->fcc = V4L2_PIX_FMT_MJPEG;
350 format->flags = UVC_FMT_FLAG_COMPRESSED;
352 ftype = UVC_VS_FRAME_MJPEG;
355 case UVC_VS_FORMAT_DV:
357 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
358 "interface %d FORMAT error\n",
360 alts->desc.bInterfaceNumber);
364 switch (buffer[8] & 0x7f) {
366 strlcpy(format->name, "SD-DV", sizeof format->name);
369 strlcpy(format->name, "SDL-DV", sizeof format->name);
372 strlcpy(format->name, "HD-DV", sizeof format->name);
375 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
376 "interface %d: unknown DV format %u\n",
378 alts->desc.bInterfaceNumber, buffer[8]);
382 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
383 sizeof format->name);
385 format->fcc = V4L2_PIX_FMT_DV;
386 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
390 /* Create a dummy frame descriptor. */
391 frame = &format->frame[0];
392 memset(&format->frame[0], 0, sizeof format->frame[0]);
393 frame->bFrameIntervalType = 1;
394 frame->dwDefaultFrameInterval = 1;
395 frame->dwFrameInterval = *intervals;
400 case UVC_VS_FORMAT_MPEG2TS:
401 case UVC_VS_FORMAT_STREAM_BASED:
402 /* Not supported yet. */
404 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
405 "interface %d unsupported format %u\n",
406 dev->udev->devnum, alts->desc.bInterfaceNumber,
411 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
416 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
417 * based formats have frame descriptors.
419 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
420 buffer[2] == ftype) {
421 frame = &format->frame[format->nframes];
422 if (ftype != UVC_VS_FRAME_FRAME_BASED)
423 n = buflen > 25 ? buffer[25] : 0;
425 n = buflen > 21 ? buffer[21] : 0;
429 if (buflen < 26 + 4*n) {
430 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
431 "interface %d FRAME error\n", dev->udev->devnum,
432 alts->desc.bInterfaceNumber);
436 frame->bFrameIndex = buffer[3];
437 frame->bmCapabilities = buffer[4];
438 frame->wWidth = get_unaligned_le16(&buffer[5]);
439 frame->wHeight = get_unaligned_le16(&buffer[7]);
440 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
441 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
442 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
443 frame->dwMaxVideoFrameBufferSize =
444 get_unaligned_le32(&buffer[17]);
445 frame->dwDefaultFrameInterval =
446 get_unaligned_le32(&buffer[21]);
447 frame->bFrameIntervalType = buffer[25];
449 frame->dwMaxVideoFrameBufferSize = 0;
450 frame->dwDefaultFrameInterval =
451 get_unaligned_le32(&buffer[17]);
452 frame->bFrameIntervalType = buffer[21];
454 frame->dwFrameInterval = *intervals;
456 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
457 * completely. Observed behaviours range from setting the
458 * value to 1.1x the actual frame size to hardwiring the
459 * 16 low bits to 0. This results in a higher than necessary
460 * memory usage as well as a wrong image size information. For
461 * uncompressed formats this can be fixed by computing the
462 * value from the frame size.
464 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
465 frame->dwMaxVideoFrameBufferSize = format->bpp
466 * frame->wWidth * frame->wHeight / 8;
468 /* Some bogus devices report dwMinFrameInterval equal to
469 * dwMaxFrameInterval and have dwFrameIntervalStep set to
470 * zero. Setting all null intervals to 1 fixes the problem and
471 * some other divisions by zero that could happen.
473 for (i = 0; i < n; ++i) {
474 interval = get_unaligned_le32(&buffer[26+4*i]);
475 *(*intervals)++ = interval ? interval : 1;
478 /* Make sure that the default frame interval stays between
481 n -= frame->bFrameIntervalType ? 1 : 2;
482 frame->dwDefaultFrameInterval =
483 min(frame->dwFrameInterval[n],
484 max(frame->dwFrameInterval[0],
485 frame->dwDefaultFrameInterval));
487 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
488 frame->bFrameIntervalType = 1;
489 frame->dwFrameInterval[0] =
490 frame->dwDefaultFrameInterval;
493 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
494 frame->wWidth, frame->wHeight,
495 10000000/frame->dwDefaultFrameInterval,
496 (100000000/frame->dwDefaultFrameInterval)%10);
503 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
504 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
509 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
510 buffer[2] == UVC_VS_COLORFORMAT) {
512 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
513 "interface %d COLORFORMAT error\n",
515 alts->desc.bInterfaceNumber);
519 format->colorspace = uvc_colorspace(buffer[3]);
525 return buffer - start;
528 static int uvc_parse_streaming(struct uvc_device *dev,
529 struct usb_interface *intf)
531 struct uvc_streaming *streaming = NULL;
532 struct uvc_format *format;
533 struct uvc_frame *frame;
534 struct usb_host_interface *alts = &intf->altsetting[0];
535 unsigned char *_buffer, *buffer = alts->extra;
536 int _buflen, buflen = alts->extralen;
537 unsigned int nformats = 0, nframes = 0, nintervals = 0;
538 unsigned int size, i, n, p;
543 if (intf->cur_altsetting->desc.bInterfaceSubClass
544 != UVC_SC_VIDEOSTREAMING) {
545 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
546 "video streaming interface\n", dev->udev->devnum,
547 intf->altsetting[0].desc.bInterfaceNumber);
551 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
552 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
553 "claimed\n", dev->udev->devnum,
554 intf->altsetting[0].desc.bInterfaceNumber);
558 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
559 if (streaming == NULL) {
560 usb_driver_release_interface(&uvc_driver.driver, intf);
564 mutex_init(&streaming->mutex);
565 streaming->dev = dev;
566 streaming->intf = usb_get_intf(intf);
567 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
569 /* The Pico iMage webcam has its class-specific interface descriptors
570 * after the endpoint descriptors.
573 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
574 struct usb_host_endpoint *ep = &alts->endpoint[i];
576 if (ep->extralen == 0)
579 if (ep->extralen > 2 &&
580 ep->extra[1] == USB_DT_CS_INTERFACE) {
581 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
582 "from endpoint %u.\n", i);
583 buffer = alts->endpoint[i].extra;
584 buflen = alts->endpoint[i].extralen;
590 /* Skip the standard interface descriptors. */
591 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
597 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
598 "interface descriptors found.\n");
602 /* Parse the header descriptor. */
604 case UVC_VS_OUTPUT_HEADER:
605 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
609 case UVC_VS_INPUT_HEADER:
610 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
615 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
616 "%d HEADER descriptor not found.\n", dev->udev->devnum,
617 alts->desc.bInterfaceNumber);
621 p = buflen >= 4 ? buffer[3] : 0;
622 n = buflen >= size ? buffer[size-1] : 0;
624 if (buflen < size + p*n) {
625 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
626 "interface %d HEADER descriptor is invalid.\n",
627 dev->udev->devnum, alts->desc.bInterfaceNumber);
631 streaming->header.bNumFormats = p;
632 streaming->header.bEndpointAddress = buffer[6];
633 if (buffer[2] == UVC_VS_INPUT_HEADER) {
634 streaming->header.bmInfo = buffer[7];
635 streaming->header.bTerminalLink = buffer[8];
636 streaming->header.bStillCaptureMethod = buffer[9];
637 streaming->header.bTriggerSupport = buffer[10];
638 streaming->header.bTriggerUsage = buffer[11];
640 streaming->header.bTerminalLink = buffer[7];
642 streaming->header.bControlSize = n;
644 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
646 if (streaming->header.bmaControls == NULL) {
657 /* Count the format and frame descriptors. */
658 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
659 switch (_buffer[2]) {
660 case UVC_VS_FORMAT_UNCOMPRESSED:
661 case UVC_VS_FORMAT_MJPEG:
662 case UVC_VS_FORMAT_FRAME_BASED:
666 case UVC_VS_FORMAT_DV:
667 /* DV format has no frame descriptor. We will create a
668 * dummy frame descriptor with a dummy frame interval.
675 case UVC_VS_FORMAT_MPEG2TS:
676 case UVC_VS_FORMAT_STREAM_BASED:
677 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
678 "interface %d FORMAT %u is not supported.\n",
680 alts->desc.bInterfaceNumber, _buffer[2]);
683 case UVC_VS_FRAME_UNCOMPRESSED:
684 case UVC_VS_FRAME_MJPEG:
687 nintervals += _buffer[25] ? _buffer[25] : 3;
690 case UVC_VS_FRAME_FRAME_BASED:
693 nintervals += _buffer[21] ? _buffer[21] : 3;
697 _buflen -= _buffer[0];
698 _buffer += _buffer[0];
702 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
703 "%d has no supported formats defined.\n",
704 dev->udev->devnum, alts->desc.bInterfaceNumber);
708 size = nformats * sizeof *format + nframes * sizeof *frame
709 + nintervals * sizeof *interval;
710 format = kzalloc(size, GFP_KERNEL);
711 if (format == NULL) {
716 frame = (struct uvc_frame *)&format[nformats];
717 interval = (__u32 *)&frame[nframes];
719 streaming->format = format;
720 streaming->nformats = nformats;
722 /* Parse the format descriptors. */
723 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
725 case UVC_VS_FORMAT_UNCOMPRESSED:
726 case UVC_VS_FORMAT_MJPEG:
727 case UVC_VS_FORMAT_DV:
728 case UVC_VS_FORMAT_FRAME_BASED:
729 format->frame = frame;
730 ret = uvc_parse_format(dev, streaming, format,
731 &interval, buffer, buflen);
735 frame += format->nframes;
751 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
752 "%d has %u bytes of trailing descriptor garbage.\n",
753 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
755 /* Parse the alternate settings to find the maximum bandwidth. */
756 for (i = 0; i < intf->num_altsetting; ++i) {
757 struct usb_host_endpoint *ep;
758 alts = &intf->altsetting[i];
759 ep = uvc_find_endpoint(alts,
760 streaming->header.bEndpointAddress);
764 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
765 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
766 if (psize > streaming->maxpsize)
767 streaming->maxpsize = psize;
770 list_add_tail(&streaming->list, &dev->streams);
774 usb_driver_release_interface(&uvc_driver.driver, intf);
776 kfree(streaming->format);
777 kfree(streaming->header.bmaControls);
782 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
783 unsigned int num_pads, unsigned int extra_size)
785 struct uvc_entity *entity;
786 unsigned int num_inputs;
789 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
790 size = sizeof(*entity) + extra_size + num_inputs;
791 entity = kzalloc(size, GFP_KERNEL);
798 entity->bNrInPins = num_inputs;
799 entity->baSourceID = ((__u8 *)entity) + sizeof(*entity) + extra_size;
804 /* Parse vendor-specific extensions. */
805 static int uvc_parse_vendor_control(struct uvc_device *dev,
806 const unsigned char *buffer, int buflen)
808 struct usb_device *udev = dev->udev;
809 struct usb_host_interface *alts = dev->intf->cur_altsetting;
810 struct uvc_entity *unit;
814 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
815 case 0x046d: /* Logitech */
816 if (buffer[1] != 0x41 || buffer[2] != 0x01)
819 /* Logitech implements several vendor specific functions
820 * through vendor specific extension units (LXU).
822 * The LXU descriptors are similar to XU descriptors
823 * (see "USB Device Video Class for Video Devices", section
824 * 3.7.2.6 "Extension Unit Descriptor") with the following
827 * ----------------------------------------------------------
829 * Size of this descriptor, in bytes: 24+p+n*2
830 * ----------------------------------------------------------
831 * 23+p+n bmControlsType N Bitmap
832 * Individual bits in the set are defined:
836 * This bitset is mapped exactly the same as bmControls.
837 * ----------------------------------------------------------
838 * 23+p+n*2 bReserved 1 Boolean
839 * ----------------------------------------------------------
840 * 24+p+n*2 iExtension 1 Index
841 * Index of a string descriptor that describes this
843 * ----------------------------------------------------------
845 p = buflen >= 22 ? buffer[21] : 0;
846 n = buflen >= 25 + p ? buffer[22+p] : 0;
848 if (buflen < 25 + p + 2*n) {
849 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
850 "interface %d EXTENSION_UNIT error\n",
851 udev->devnum, alts->desc.bInterfaceNumber);
855 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
860 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
861 unit->extension.bNumControls = buffer[20];
862 memcpy(unit->baSourceID, &buffer[22], p);
863 unit->extension.bControlSize = buffer[22+p];
864 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
865 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
867 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
869 if (buffer[24+p+2*n] != 0)
870 usb_string(udev, buffer[24+p+2*n], unit->name,
873 sprintf(unit->name, "Extension %u", buffer[3]);
875 list_add_tail(&unit->list, &dev->entities);
883 static int uvc_parse_standard_control(struct uvc_device *dev,
884 const unsigned char *buffer, int buflen)
886 struct usb_device *udev = dev->udev;
887 struct uvc_entity *unit, *term;
888 struct usb_interface *intf;
889 struct usb_host_interface *alts = dev->intf->cur_altsetting;
890 unsigned int i, n, p, len;
895 n = buflen >= 12 ? buffer[11] : 0;
897 if (buflen < 12 || buflen < 12 + n) {
898 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
899 "interface %d HEADER error\n", udev->devnum,
900 alts->desc.bInterfaceNumber);
904 dev->uvc_version = get_unaligned_le16(&buffer[3]);
905 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
907 /* Parse all USB Video Streaming interfaces. */
908 for (i = 0; i < n; ++i) {
909 intf = usb_ifnum_to_if(udev, buffer[12+i]);
911 uvc_trace(UVC_TRACE_DESCR, "device %d "
912 "interface %d doesn't exists\n",
917 uvc_parse_streaming(dev, intf);
921 case UVC_VC_INPUT_TERMINAL:
923 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
924 "interface %d INPUT_TERMINAL error\n",
925 udev->devnum, alts->desc.bInterfaceNumber);
929 /* Make sure the terminal type MSB is not null, otherwise it
930 * could be confused with a unit.
932 type = get_unaligned_le16(&buffer[4]);
933 if ((type & 0xff00) == 0) {
934 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
935 "interface %d INPUT_TERMINAL %d has invalid "
936 "type 0x%04x, skipping\n", udev->devnum,
937 alts->desc.bInterfaceNumber,
946 if (type == UVC_ITT_CAMERA) {
947 n = buflen >= 15 ? buffer[14] : 0;
950 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
951 n = buflen >= 9 ? buffer[8] : 0;
952 p = buflen >= 10 + n ? buffer[9+n] : 0;
956 if (buflen < len + n + p) {
957 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
958 "interface %d INPUT_TERMINAL error\n",
959 udev->devnum, alts->desc.bInterfaceNumber);
963 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
968 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
969 term->camera.bControlSize = n;
970 term->camera.bmControls = (__u8 *)term + sizeof *term;
971 term->camera.wObjectiveFocalLengthMin =
972 get_unaligned_le16(&buffer[8]);
973 term->camera.wObjectiveFocalLengthMax =
974 get_unaligned_le16(&buffer[10]);
975 term->camera.wOcularFocalLength =
976 get_unaligned_le16(&buffer[12]);
977 memcpy(term->camera.bmControls, &buffer[15], n);
978 } else if (UVC_ENTITY_TYPE(term) ==
979 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
980 term->media.bControlSize = n;
981 term->media.bmControls = (__u8 *)term + sizeof *term;
982 term->media.bTransportModeSize = p;
983 term->media.bmTransportModes = (__u8 *)term
985 memcpy(term->media.bmControls, &buffer[9], n);
986 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
990 usb_string(udev, buffer[7], term->name,
992 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
993 sprintf(term->name, "Camera %u", buffer[3]);
994 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
995 sprintf(term->name, "Media %u", buffer[3]);
997 sprintf(term->name, "Input %u", buffer[3]);
999 list_add_tail(&term->list, &dev->entities);
1002 case UVC_VC_OUTPUT_TERMINAL:
1004 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1005 "interface %d OUTPUT_TERMINAL error\n",
1006 udev->devnum, alts->desc.bInterfaceNumber);
1010 /* Make sure the terminal type MSB is not null, otherwise it
1011 * could be confused with a unit.
1013 type = get_unaligned_le16(&buffer[4]);
1014 if ((type & 0xff00) == 0) {
1015 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1016 "interface %d OUTPUT_TERMINAL %d has invalid "
1017 "type 0x%04x, skipping\n", udev->devnum,
1018 alts->desc.bInterfaceNumber, buffer[3], type);
1022 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1027 memcpy(term->baSourceID, &buffer[7], 1);
1030 usb_string(udev, buffer[8], term->name,
1033 sprintf(term->name, "Output %u", buffer[3]);
1035 list_add_tail(&term->list, &dev->entities);
1038 case UVC_VC_SELECTOR_UNIT:
1039 p = buflen >= 5 ? buffer[4] : 0;
1041 if (buflen < 5 || buflen < 6 + p) {
1042 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1043 "interface %d SELECTOR_UNIT error\n",
1044 udev->devnum, alts->desc.bInterfaceNumber);
1048 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1052 memcpy(unit->baSourceID, &buffer[5], p);
1054 if (buffer[5+p] != 0)
1055 usb_string(udev, buffer[5+p], unit->name,
1058 sprintf(unit->name, "Selector %u", buffer[3]);
1060 list_add_tail(&unit->list, &dev->entities);
1063 case UVC_VC_PROCESSING_UNIT:
1064 n = buflen >= 8 ? buffer[7] : 0;
1065 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1067 if (buflen < p + n) {
1068 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1069 "interface %d PROCESSING_UNIT error\n",
1070 udev->devnum, alts->desc.bInterfaceNumber);
1074 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1078 memcpy(unit->baSourceID, &buffer[4], 1);
1079 unit->processing.wMaxMultiplier =
1080 get_unaligned_le16(&buffer[5]);
1081 unit->processing.bControlSize = buffer[7];
1082 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1083 memcpy(unit->processing.bmControls, &buffer[8], n);
1084 if (dev->uvc_version >= 0x0110)
1085 unit->processing.bmVideoStandards = buffer[9+n];
1087 if (buffer[8+n] != 0)
1088 usb_string(udev, buffer[8+n], unit->name,
1091 sprintf(unit->name, "Processing %u", buffer[3]);
1093 list_add_tail(&unit->list, &dev->entities);
1096 case UVC_VC_EXTENSION_UNIT:
1097 p = buflen >= 22 ? buffer[21] : 0;
1098 n = buflen >= 24 + p ? buffer[22+p] : 0;
1100 if (buflen < 24 + p + n) {
1101 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1102 "interface %d EXTENSION_UNIT error\n",
1103 udev->devnum, alts->desc.bInterfaceNumber);
1107 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1111 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1112 unit->extension.bNumControls = buffer[20];
1113 memcpy(unit->baSourceID, &buffer[22], p);
1114 unit->extension.bControlSize = buffer[22+p];
1115 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1116 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1118 if (buffer[23+p+n] != 0)
1119 usb_string(udev, buffer[23+p+n], unit->name,
1122 sprintf(unit->name, "Extension %u", buffer[3]);
1124 list_add_tail(&unit->list, &dev->entities);
1128 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1129 "descriptor (%u)\n", buffer[2]);
1136 static int uvc_parse_control(struct uvc_device *dev)
1138 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1139 unsigned char *buffer = alts->extra;
1140 int buflen = alts->extralen;
1143 /* Parse the default alternate setting only, as the UVC specification
1144 * defines a single alternate setting, the default alternate setting
1148 while (buflen > 2) {
1149 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1150 buffer[1] != USB_DT_CS_INTERFACE)
1151 goto next_descriptor;
1153 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1157 buflen -= buffer[0];
1158 buffer += buffer[0];
1161 /* Check if the optional status endpoint is present. Built-in iSight
1162 * webcams have an interrupt endpoint but spit proprietary data that
1163 * don't conform to the UVC status endpoint messages. Don't try to
1164 * handle the interrupt endpoint for those cameras.
1166 if (alts->desc.bNumEndpoints == 1 &&
1167 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1168 struct usb_host_endpoint *ep = &alts->endpoint[0];
1169 struct usb_endpoint_descriptor *desc = &ep->desc;
1171 if (usb_endpoint_is_int_in(desc) &&
1172 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1173 desc->bInterval != 0) {
1174 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1175 "(addr %02x).\n", desc->bEndpointAddress);
1183 /* ------------------------------------------------------------------------
1188 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1189 * and containing the following units:
1191 * - one or more Output Terminals (USB Streaming or Display)
1192 * - zero or one Processing Unit
1193 * - zero, one or more single-input Selector Units
1194 * - zero or one multiple-input Selector Units, provided all inputs are
1195 * connected to input terminals
1196 * - zero, one or mode single-input Extension Units
1197 * - one or more Input Terminals (Camera, External or USB Streaming)
1199 * The terminal and units must match on of the following structures:
1201 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1202 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1203 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1205 * +---------+ +---------+ -> OTT_*(0)
1206 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1207 * +---------+ +---------+ -> OTT_*(n)
1209 * The Processing Unit and Extension Units can be in any order. Additional
1210 * Extension Units connected to the main chain as single-unit branches are
1211 * also supported. Single-input Selector Units are ignored.
1213 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1214 struct uvc_entity *entity)
1216 switch (UVC_ENTITY_TYPE(entity)) {
1217 case UVC_VC_EXTENSION_UNIT:
1218 if (uvc_trace_param & UVC_TRACE_PROBE)
1219 printk(" <- XU %d", entity->id);
1221 if (entity->bNrInPins != 1) {
1222 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1223 "than 1 input pin.\n", entity->id);
1229 case UVC_VC_PROCESSING_UNIT:
1230 if (uvc_trace_param & UVC_TRACE_PROBE)
1231 printk(" <- PU %d", entity->id);
1233 if (chain->processing != NULL) {
1234 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1235 "Processing Units in chain.\n");
1239 chain->processing = entity;
1242 case UVC_VC_SELECTOR_UNIT:
1243 if (uvc_trace_param & UVC_TRACE_PROBE)
1244 printk(" <- SU %d", entity->id);
1246 /* Single-input selector units are ignored. */
1247 if (entity->bNrInPins == 1)
1250 if (chain->selector != NULL) {
1251 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1252 "Units in chain.\n");
1256 chain->selector = entity;
1259 case UVC_ITT_VENDOR_SPECIFIC:
1260 case UVC_ITT_CAMERA:
1261 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1262 if (uvc_trace_param & UVC_TRACE_PROBE)
1263 printk(" <- IT %d\n", entity->id);
1267 case UVC_TT_STREAMING:
1268 if (UVC_ENTITY_IS_ITERM(entity)) {
1269 if (uvc_trace_param & UVC_TRACE_PROBE)
1270 printk(" <- IT %d\n", entity->id);
1272 if (uvc_trace_param & UVC_TRACE_PROBE)
1273 printk(" OT %d", entity->id);
1279 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1280 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1284 list_add_tail(&entity->chain, &chain->entities);
1288 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1289 struct uvc_entity *entity, struct uvc_entity *prev)
1291 struct uvc_entity *forward;
1299 forward = uvc_entity_by_reference(chain->dev, entity->id,
1301 if (forward == NULL)
1303 if (forward == prev)
1306 switch (UVC_ENTITY_TYPE(forward)) {
1307 case UVC_VC_EXTENSION_UNIT:
1308 if (forward->bNrInPins != 1) {
1309 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1310 "has more than 1 input pin.\n",
1315 list_add_tail(&forward->chain, &chain->entities);
1316 if (uvc_trace_param & UVC_TRACE_PROBE) {
1320 printk(" XU %d", forward->id);
1325 case UVC_OTT_VENDOR_SPECIFIC:
1326 case UVC_OTT_DISPLAY:
1327 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1328 case UVC_TT_STREAMING:
1329 if (UVC_ENTITY_IS_ITERM(forward)) {
1330 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1331 "terminal %u.\n", forward->id);
1335 list_add_tail(&forward->chain, &chain->entities);
1336 if (uvc_trace_param & UVC_TRACE_PROBE) {
1340 printk(" OT %d", forward->id);
1352 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1353 struct uvc_entity **_entity)
1355 struct uvc_entity *entity = *_entity;
1356 struct uvc_entity *term;
1357 int id = -EINVAL, i;
1359 switch (UVC_ENTITY_TYPE(entity)) {
1360 case UVC_VC_EXTENSION_UNIT:
1361 case UVC_VC_PROCESSING_UNIT:
1362 id = entity->baSourceID[0];
1365 case UVC_VC_SELECTOR_UNIT:
1366 /* Single-input selector units are ignored. */
1367 if (entity->bNrInPins == 1) {
1368 id = entity->baSourceID[0];
1372 if (uvc_trace_param & UVC_TRACE_PROBE)
1375 chain->selector = entity;
1376 for (i = 0; i < entity->bNrInPins; ++i) {
1377 id = entity->baSourceID[i];
1378 term = uvc_entity_by_id(chain->dev, id);
1379 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1380 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1381 "input %d isn't connected to an "
1382 "input terminal\n", entity->id, i);
1386 if (uvc_trace_param & UVC_TRACE_PROBE)
1387 printk(" %d", term->id);
1389 list_add_tail(&term->chain, &chain->entities);
1390 uvc_scan_chain_forward(chain, term, entity);
1393 if (uvc_trace_param & UVC_TRACE_PROBE)
1399 case UVC_ITT_VENDOR_SPECIFIC:
1400 case UVC_ITT_CAMERA:
1401 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1402 case UVC_OTT_VENDOR_SPECIFIC:
1403 case UVC_OTT_DISPLAY:
1404 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1405 case UVC_TT_STREAMING:
1406 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1415 entity = uvc_entity_by_id(chain->dev, id);
1416 if (entity == NULL) {
1417 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1418 "unknown entity %d.\n", id);
1426 static int uvc_scan_chain(struct uvc_video_chain *chain,
1427 struct uvc_entity *term)
1429 struct uvc_entity *entity, *prev;
1431 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1436 while (entity != NULL) {
1437 /* Entity must not be part of an existing chain */
1438 if (entity->chain.next || entity->chain.prev) {
1439 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1440 "entity %d already in chain.\n", entity->id);
1444 /* Process entity */
1445 if (uvc_scan_chain_entity(chain, entity) < 0)
1449 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1454 if (uvc_scan_chain_backward(chain, &entity) < 0)
1461 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1464 struct uvc_entity *term;
1465 unsigned int nterms = 0;
1468 list_for_each_entry(term, terms, chain) {
1469 if (!UVC_ENTITY_IS_TERM(term) ||
1470 UVC_TERM_DIRECTION(term) != dir)
1474 p += sprintf(p, ",");
1475 if (++nterms >= 4) {
1476 p += sprintf(p, "...");
1479 p += sprintf(p, "%u", term->id);
1485 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1487 static char buffer[43];
1490 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1491 p += sprintf(p, " -> ");
1492 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1498 * Scan the device for video chains and register video devices.
1500 * Chains are scanned starting at their output terminals and walked backwards.
1502 static int uvc_scan_device(struct uvc_device *dev)
1504 struct uvc_video_chain *chain;
1505 struct uvc_entity *term;
1507 list_for_each_entry(term, &dev->entities, list) {
1508 if (!UVC_ENTITY_IS_OTERM(term))
1511 /* If the terminal is already included in a chain, skip it.
1512 * This can happen for chains that have multiple output
1513 * terminals, where all output terminals beside the first one
1514 * will be inserted in the chain in forward scans.
1516 if (term->chain.next || term->chain.prev)
1519 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1523 INIT_LIST_HEAD(&chain->entities);
1524 mutex_init(&chain->ctrl_mutex);
1527 if (uvc_scan_chain(chain, term) < 0) {
1532 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1533 uvc_print_chain(chain));
1535 list_add_tail(&chain->list, &dev->chains);
1538 if (list_empty(&dev->chains)) {
1539 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1546 /* ------------------------------------------------------------------------
1547 * Video device registration and unregistration
1551 * Delete the UVC device.
1553 * Called by the kernel when the last reference to the uvc_device structure
1556 * As this function is called after or during disconnect(), all URBs have
1557 * already been canceled by the USB core. There is no need to kill the
1558 * interrupt URB manually.
1560 static void uvc_delete(struct uvc_device *dev)
1562 struct list_head *p, *n;
1564 usb_put_intf(dev->intf);
1565 usb_put_dev(dev->udev);
1567 uvc_status_cleanup(dev);
1568 uvc_ctrl_cleanup_device(dev);
1570 list_for_each_safe(p, n, &dev->chains) {
1571 struct uvc_video_chain *chain;
1572 chain = list_entry(p, struct uvc_video_chain, list);
1576 list_for_each_safe(p, n, &dev->entities) {
1577 struct uvc_entity *entity;
1578 entity = list_entry(p, struct uvc_entity, list);
1582 list_for_each_safe(p, n, &dev->streams) {
1583 struct uvc_streaming *streaming;
1584 streaming = list_entry(p, struct uvc_streaming, list);
1585 usb_driver_release_interface(&uvc_driver.driver,
1587 usb_put_intf(streaming->intf);
1588 kfree(streaming->format);
1589 kfree(streaming->header.bmaControls);
1596 static void uvc_release(struct video_device *vdev)
1598 struct uvc_streaming *stream = video_get_drvdata(vdev);
1599 struct uvc_device *dev = stream->dev;
1601 video_device_release(vdev);
1603 /* Decrement the registered streams count and delete the device when it
1606 if (atomic_dec_and_test(&dev->nstreams))
1611 * Unregister the video devices.
1613 static void uvc_unregister_video(struct uvc_device *dev)
1615 struct uvc_streaming *stream;
1617 /* Unregistering all video devices might result in uvc_delete() being
1618 * called from inside the loop if there's no open file handle. To avoid
1619 * that, increment the stream count before iterating over the streams
1620 * and decrement it when done.
1622 atomic_inc(&dev->nstreams);
1624 list_for_each_entry(stream, &dev->streams, list) {
1625 if (stream->vdev == NULL)
1628 video_unregister_device(stream->vdev);
1629 stream->vdev = NULL;
1632 /* Decrement the stream count and call uvc_delete explicitly if there
1633 * are no stream left.
1635 if (atomic_dec_and_test(&dev->nstreams))
1639 static int uvc_register_video(struct uvc_device *dev,
1640 struct uvc_streaming *stream)
1642 struct video_device *vdev;
1645 /* Initialize the streaming interface with default streaming
1648 ret = uvc_video_init(stream);
1650 uvc_printk(KERN_ERR, "Failed to initialize the device "
1655 /* Register the device with V4L. */
1656 vdev = video_device_alloc();
1658 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1663 /* We already hold a reference to dev->udev. The video device will be
1664 * unregistered before the reference is released, so we don't need to
1667 vdev->parent = &dev->intf->dev;
1668 vdev->fops = &uvc_fops;
1669 vdev->release = uvc_release;
1670 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1672 /* Set the driver data before calling video_register_device, otherwise
1673 * uvc_v4l2_open might race us.
1675 stream->vdev = vdev;
1676 video_set_drvdata(vdev, stream);
1678 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1680 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1682 stream->vdev = NULL;
1683 video_device_release(vdev);
1687 atomic_inc(&dev->nstreams);
1692 * Register all video devices in all chains.
1694 static int uvc_register_terms(struct uvc_device *dev,
1695 struct uvc_video_chain *chain)
1697 struct uvc_streaming *stream;
1698 struct uvc_entity *term;
1701 list_for_each_entry(term, &chain->entities, chain) {
1702 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1705 stream = uvc_stream_by_id(dev, term->id);
1706 if (stream == NULL) {
1707 uvc_printk(KERN_INFO, "No streaming interface found "
1708 "for terminal %u.", term->id);
1712 stream->chain = chain;
1713 ret = uvc_register_video(dev, stream);
1721 static int uvc_register_chains(struct uvc_device *dev)
1723 struct uvc_video_chain *chain;
1726 list_for_each_entry(chain, &dev->chains, list) {
1727 ret = uvc_register_terms(dev, chain);
1735 /* ------------------------------------------------------------------------
1736 * USB probe, disconnect, suspend and resume
1739 static int uvc_probe(struct usb_interface *intf,
1740 const struct usb_device_id *id)
1742 struct usb_device *udev = interface_to_usbdev(intf);
1743 struct uvc_device *dev;
1746 if (id->idVendor && id->idProduct)
1747 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1748 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1751 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1754 /* Allocate memory for the device and initialize it. */
1755 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1758 INIT_LIST_HEAD(&dev->entities);
1759 INIT_LIST_HEAD(&dev->chains);
1760 INIT_LIST_HEAD(&dev->streams);
1761 atomic_set(&dev->nstreams, 0);
1762 atomic_set(&dev->users, 0);
1763 atomic_set(&dev->nmappings, 0);
1765 dev->udev = usb_get_dev(udev);
1766 dev->intf = usb_get_intf(intf);
1767 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1768 dev->quirks = (uvc_quirks_param == -1)
1769 ? id->driver_info : uvc_quirks_param;
1771 if (udev->product != NULL)
1772 strlcpy(dev->name, udev->product, sizeof dev->name);
1774 snprintf(dev->name, sizeof dev->name,
1775 "UVC Camera (%04x:%04x)",
1776 le16_to_cpu(udev->descriptor.idVendor),
1777 le16_to_cpu(udev->descriptor.idProduct));
1779 /* Parse the Video Class control descriptor. */
1780 if (uvc_parse_control(dev) < 0) {
1781 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1786 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1787 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1788 udev->product ? udev->product : "<unnamed>",
1789 le16_to_cpu(udev->descriptor.idVendor),
1790 le16_to_cpu(udev->descriptor.idProduct));
1792 if (dev->quirks != id->driver_info) {
1793 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1794 "parameter for testing purpose.\n", dev->quirks);
1795 uvc_printk(KERN_INFO, "Please report required quirks to the "
1796 "linux-uvc-devel mailing list.\n");
1799 /* Initialize controls. */
1800 if (uvc_ctrl_init_device(dev) < 0)
1803 /* Scan the device for video chains. */
1804 if (uvc_scan_device(dev) < 0)
1807 /* Register video devices. */
1808 if (uvc_register_chains(dev) < 0)
1811 /* Save our data pointer in the interface data. */
1812 usb_set_intfdata(intf, dev);
1814 /* Initialize the interrupt URB. */
1815 if ((ret = uvc_status_init(dev)) < 0) {
1816 uvc_printk(KERN_INFO, "Unable to initialize the status "
1817 "endpoint (%d), status interrupt will not be "
1818 "supported.\n", ret);
1821 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1822 usb_enable_autosuspend(udev);
1826 uvc_unregister_video(dev);
1830 static void uvc_disconnect(struct usb_interface *intf)
1832 struct uvc_device *dev = usb_get_intfdata(intf);
1834 /* Set the USB interface data to NULL. This can be done outside the
1835 * lock, as there's no other reader.
1837 usb_set_intfdata(intf, NULL);
1839 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1840 UVC_SC_VIDEOSTREAMING)
1843 dev->state |= UVC_DEV_DISCONNECTED;
1845 uvc_unregister_video(dev);
1848 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1850 struct uvc_device *dev = usb_get_intfdata(intf);
1851 struct uvc_streaming *stream;
1853 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1854 intf->cur_altsetting->desc.bInterfaceNumber);
1856 /* Controls are cached on the fly so they don't need to be saved. */
1857 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1858 UVC_SC_VIDEOCONTROL)
1859 return uvc_status_suspend(dev);
1861 list_for_each_entry(stream, &dev->streams, list) {
1862 if (stream->intf == intf)
1863 return uvc_video_suspend(stream);
1866 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1871 static int __uvc_resume(struct usb_interface *intf, int reset)
1873 struct uvc_device *dev = usb_get_intfdata(intf);
1874 struct uvc_streaming *stream;
1876 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
1877 intf->cur_altsetting->desc.bInterfaceNumber);
1879 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1880 UVC_SC_VIDEOCONTROL) {
1882 int ret = uvc_ctrl_resume_device(dev);
1888 return uvc_status_resume(dev);
1891 list_for_each_entry(stream, &dev->streams, list) {
1892 if (stream->intf == intf)
1893 return uvc_video_resume(stream);
1896 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
1901 static int uvc_resume(struct usb_interface *intf)
1903 return __uvc_resume(intf, 0);
1906 static int uvc_reset_resume(struct usb_interface *intf)
1908 return __uvc_resume(intf, 1);
1911 /* ------------------------------------------------------------------------
1915 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
1917 if (uvc_clock_param == CLOCK_MONOTONIC)
1918 return sprintf(buffer, "CLOCK_MONOTONIC");
1920 return sprintf(buffer, "CLOCK_REALTIME");
1923 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
1925 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
1926 val += strlen("clock_");
1928 if (strcasecmp(val, "monotonic") == 0)
1929 uvc_clock_param = CLOCK_MONOTONIC;
1930 else if (strcasecmp(val, "realtime") == 0)
1931 uvc_clock_param = CLOCK_REALTIME;
1938 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
1939 &uvc_clock_param, S_IRUGO|S_IWUSR);
1940 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
1941 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
1942 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
1943 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
1944 MODULE_PARM_DESC(quirks, "Forced device quirks");
1945 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
1946 MODULE_PARM_DESC(trace, "Trace level bitmask");
1947 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
1948 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
1950 /* ------------------------------------------------------------------------
1951 * Driver initialization and cleanup
1955 * The Logitech cameras listed below have their interface class set to
1956 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
1957 * though they are compliant.
1959 static struct usb_device_id uvc_ids[] = {
1960 /* Genius eFace 2025 */
1961 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1962 | USB_DEVICE_ID_MATCH_INT_INFO,
1964 .idProduct = 0x706e,
1965 .bInterfaceClass = USB_CLASS_VIDEO,
1966 .bInterfaceSubClass = 1,
1967 .bInterfaceProtocol = 0,
1968 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1969 /* Microsoft Lifecam NX-6000 */
1970 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1971 | USB_DEVICE_ID_MATCH_INT_INFO,
1973 .idProduct = 0x00f8,
1974 .bInterfaceClass = USB_CLASS_VIDEO,
1975 .bInterfaceSubClass = 1,
1976 .bInterfaceProtocol = 0,
1977 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1978 /* Microsoft Lifecam VX-7000 */
1979 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1980 | USB_DEVICE_ID_MATCH_INT_INFO,
1982 .idProduct = 0x0723,
1983 .bInterfaceClass = USB_CLASS_VIDEO,
1984 .bInterfaceSubClass = 1,
1985 .bInterfaceProtocol = 0,
1986 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1987 /* Logitech Quickcam Fusion */
1988 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1989 | USB_DEVICE_ID_MATCH_INT_INFO,
1991 .idProduct = 0x08c1,
1992 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
1993 .bInterfaceSubClass = 1,
1994 .bInterfaceProtocol = 0 },
1995 /* Logitech Quickcam Orbit MP */
1996 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1997 | USB_DEVICE_ID_MATCH_INT_INFO,
1999 .idProduct = 0x08c2,
2000 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2001 .bInterfaceSubClass = 1,
2002 .bInterfaceProtocol = 0 },
2003 /* Logitech Quickcam Pro for Notebook */
2004 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2005 | USB_DEVICE_ID_MATCH_INT_INFO,
2007 .idProduct = 0x08c3,
2008 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2009 .bInterfaceSubClass = 1,
2010 .bInterfaceProtocol = 0 },
2011 /* Logitech Quickcam Pro 5000 */
2012 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2013 | USB_DEVICE_ID_MATCH_INT_INFO,
2015 .idProduct = 0x08c5,
2016 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2017 .bInterfaceSubClass = 1,
2018 .bInterfaceProtocol = 0 },
2019 /* Logitech Quickcam OEM Dell Notebook */
2020 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2021 | USB_DEVICE_ID_MATCH_INT_INFO,
2023 .idProduct = 0x08c6,
2024 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2025 .bInterfaceSubClass = 1,
2026 .bInterfaceProtocol = 0 },
2027 /* Logitech Quickcam OEM Cisco VT Camera II */
2028 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2029 | USB_DEVICE_ID_MATCH_INT_INFO,
2031 .idProduct = 0x08c7,
2032 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2033 .bInterfaceSubClass = 1,
2034 .bInterfaceProtocol = 0 },
2035 /* Chicony CNF7129 (Asus EEE 100HE) */
2036 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2037 | USB_DEVICE_ID_MATCH_INT_INFO,
2039 .idProduct = 0xb071,
2040 .bInterfaceClass = USB_CLASS_VIDEO,
2041 .bInterfaceSubClass = 1,
2042 .bInterfaceProtocol = 0,
2043 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2044 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2045 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2046 | USB_DEVICE_ID_MATCH_INT_INFO,
2048 .idProduct = 0x3820,
2049 .bInterfaceClass = USB_CLASS_VIDEO,
2050 .bInterfaceSubClass = 1,
2051 .bInterfaceProtocol = 0,
2052 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2053 /* Apple Built-In iSight */
2054 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2055 | USB_DEVICE_ID_MATCH_INT_INFO,
2057 .idProduct = 0x8501,
2058 .bInterfaceClass = USB_CLASS_VIDEO,
2059 .bInterfaceSubClass = 1,
2060 .bInterfaceProtocol = 0,
2061 .driver_info = UVC_QUIRK_PROBE_MINMAX
2062 | UVC_QUIRK_BUILTIN_ISIGHT },
2063 /* Genesys Logic USB 2.0 PC Camera */
2064 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2065 | USB_DEVICE_ID_MATCH_INT_INFO,
2067 .idProduct = 0x0505,
2068 .bInterfaceClass = USB_CLASS_VIDEO,
2069 .bInterfaceSubClass = 1,
2070 .bInterfaceProtocol = 0,
2071 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2073 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2074 | USB_DEVICE_ID_MATCH_INT_INFO,
2076 .idProduct = 0x332d,
2077 .bInterfaceClass = USB_CLASS_VIDEO,
2078 .bInterfaceSubClass = 1,
2079 .bInterfaceProtocol = 0,
2080 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2081 /* ViMicro - Minoru3D */
2082 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2083 | USB_DEVICE_ID_MATCH_INT_INFO,
2085 .idProduct = 0x3410,
2086 .bInterfaceClass = USB_CLASS_VIDEO,
2087 .bInterfaceSubClass = 1,
2088 .bInterfaceProtocol = 0,
2089 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2090 /* ViMicro Venus - Minoru3D */
2091 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2092 | USB_DEVICE_ID_MATCH_INT_INFO,
2094 .idProduct = 0x3420,
2095 .bInterfaceClass = USB_CLASS_VIDEO,
2096 .bInterfaceSubClass = 1,
2097 .bInterfaceProtocol = 0,
2098 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2100 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2101 | USB_DEVICE_ID_MATCH_INT_INFO,
2103 .idProduct = 0x0004,
2104 .bInterfaceClass = USB_CLASS_VIDEO,
2105 .bInterfaceSubClass = 1,
2106 .bInterfaceProtocol = 0,
2107 .driver_info = UVC_QUIRK_PROBE_MINMAX
2108 | UVC_QUIRK_PROBE_DEF },
2109 /* IMC Networks (Medion Akoya) */
2110 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2111 | USB_DEVICE_ID_MATCH_INT_INFO,
2113 .idProduct = 0x5103,
2114 .bInterfaceClass = USB_CLASS_VIDEO,
2115 .bInterfaceSubClass = 1,
2116 .bInterfaceProtocol = 0,
2117 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2118 /* Syntek (HP Spartan) */
2119 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2120 | USB_DEVICE_ID_MATCH_INT_INFO,
2122 .idProduct = 0x5212,
2123 .bInterfaceClass = USB_CLASS_VIDEO,
2124 .bInterfaceSubClass = 1,
2125 .bInterfaceProtocol = 0,
2126 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2127 /* Syntek (Samsung Q310) */
2128 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2129 | USB_DEVICE_ID_MATCH_INT_INFO,
2131 .idProduct = 0x5931,
2132 .bInterfaceClass = USB_CLASS_VIDEO,
2133 .bInterfaceSubClass = 1,
2134 .bInterfaceProtocol = 0,
2135 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2136 /* Syntek (Packard Bell EasyNote MX52 */
2137 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2138 | USB_DEVICE_ID_MATCH_INT_INFO,
2140 .idProduct = 0x8a12,
2141 .bInterfaceClass = USB_CLASS_VIDEO,
2142 .bInterfaceSubClass = 1,
2143 .bInterfaceProtocol = 0,
2144 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2145 /* Syntek (Asus F9SG) */
2146 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2147 | USB_DEVICE_ID_MATCH_INT_INFO,
2149 .idProduct = 0x8a31,
2150 .bInterfaceClass = USB_CLASS_VIDEO,
2151 .bInterfaceSubClass = 1,
2152 .bInterfaceProtocol = 0,
2153 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2154 /* Syntek (Asus U3S) */
2155 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2156 | USB_DEVICE_ID_MATCH_INT_INFO,
2158 .idProduct = 0x8a33,
2159 .bInterfaceClass = USB_CLASS_VIDEO,
2160 .bInterfaceSubClass = 1,
2161 .bInterfaceProtocol = 0,
2162 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2163 /* Syntek (JAOtech Smart Terminal) */
2164 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2165 | USB_DEVICE_ID_MATCH_INT_INFO,
2167 .idProduct = 0x8a34,
2168 .bInterfaceClass = USB_CLASS_VIDEO,
2169 .bInterfaceSubClass = 1,
2170 .bInterfaceProtocol = 0,
2171 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2173 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2174 | USB_DEVICE_ID_MATCH_INT_INFO,
2176 .idProduct = 0x0202,
2177 .bInterfaceClass = USB_CLASS_VIDEO,
2178 .bInterfaceSubClass = 1,
2179 .bInterfaceProtocol = 0,
2180 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2181 /* Lenovo Thinkpad SL400/SL500 */
2182 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2183 | USB_DEVICE_ID_MATCH_INT_INFO,
2185 .idProduct = 0x480b,
2186 .bInterfaceClass = USB_CLASS_VIDEO,
2187 .bInterfaceSubClass = 1,
2188 .bInterfaceProtocol = 0,
2189 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2190 /* Aveo Technology USB 2.0 Camera */
2191 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2192 | USB_DEVICE_ID_MATCH_INT_INFO,
2194 .idProduct = 0x0306,
2195 .bInterfaceClass = USB_CLASS_VIDEO,
2196 .bInterfaceSubClass = 1,
2197 .bInterfaceProtocol = 0,
2198 .driver_info = UVC_QUIRK_PROBE_MINMAX
2199 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2200 /* Ecamm Pico iMage */
2201 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2202 | USB_DEVICE_ID_MATCH_INT_INFO,
2204 .idProduct = 0xcafe,
2205 .bInterfaceClass = USB_CLASS_VIDEO,
2206 .bInterfaceSubClass = 1,
2207 .bInterfaceProtocol = 0,
2208 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2209 /* Manta MM-353 Plako */
2210 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2211 | USB_DEVICE_ID_MATCH_INT_INFO,
2213 .idProduct = 0x3188,
2214 .bInterfaceClass = USB_CLASS_VIDEO,
2215 .bInterfaceSubClass = 1,
2216 .bInterfaceProtocol = 0,
2217 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2218 /* FSC WebCam V30S */
2219 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2220 | USB_DEVICE_ID_MATCH_INT_INFO,
2222 .idProduct = 0x3288,
2223 .bInterfaceClass = USB_CLASS_VIDEO,
2224 .bInterfaceSubClass = 1,
2225 .bInterfaceProtocol = 0,
2226 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2227 /* Arkmicro unbranded */
2228 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2229 | USB_DEVICE_ID_MATCH_INT_INFO,
2231 .idProduct = 0x3290,
2232 .bInterfaceClass = USB_CLASS_VIDEO,
2233 .bInterfaceSubClass = 1,
2234 .bInterfaceProtocol = 0,
2235 .driver_info = UVC_QUIRK_PROBE_DEF },
2236 /* Bodelin ProScopeHR */
2237 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2238 | USB_DEVICE_ID_MATCH_DEV_HI
2239 | USB_DEVICE_ID_MATCH_INT_INFO,
2241 .idProduct = 0x1000,
2242 .bcdDevice_hi = 0x0126,
2243 .bInterfaceClass = USB_CLASS_VIDEO,
2244 .bInterfaceSubClass = 1,
2245 .bInterfaceProtocol = 0,
2246 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2247 /* MSI StarCam 370i */
2248 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2249 | USB_DEVICE_ID_MATCH_INT_INFO,
2251 .idProduct = 0x2951,
2252 .bInterfaceClass = USB_CLASS_VIDEO,
2253 .bInterfaceSubClass = 1,
2254 .bInterfaceProtocol = 0,
2255 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2256 /* SiGma Micro USB Web Camera */
2257 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2258 | USB_DEVICE_ID_MATCH_INT_INFO,
2260 .idProduct = 0x3000,
2261 .bInterfaceClass = USB_CLASS_VIDEO,
2262 .bInterfaceSubClass = 1,
2263 .bInterfaceProtocol = 0,
2264 .driver_info = UVC_QUIRK_PROBE_MINMAX
2265 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2266 /* Generic USB Video Class */
2267 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2271 MODULE_DEVICE_TABLE(usb, uvc_ids);
2273 struct uvc_driver uvc_driver = {
2277 .disconnect = uvc_disconnect,
2278 .suspend = uvc_suspend,
2279 .resume = uvc_resume,
2280 .reset_resume = uvc_reset_resume,
2281 .id_table = uvc_ids,
2282 .supports_autosuspend = 1,
2286 static int __init uvc_init(void)
2290 result = usb_register(&uvc_driver.driver);
2292 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2296 static void __exit uvc_cleanup(void)
2298 usb_deregister(&uvc_driver.driver);
2301 module_init(uvc_init);
2302 module_exit(uvc_cleanup);
2304 MODULE_AUTHOR(DRIVER_AUTHOR);
2305 MODULE_DESCRIPTION(DRIVER_DESC);
2306 MODULE_LICENSE("GPL");
2307 MODULE_VERSION(DRIVER_VERSION);