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:0 (M420)",
88 .guid = UVC_GUID_FORMAT_M420,
89 .fcc = V4L2_PIX_FMT_M420,
92 .name = "YUV 4:2:2 (UYVY)",
93 .guid = UVC_GUID_FORMAT_UYVY,
94 .fcc = V4L2_PIX_FMT_UYVY,
97 .name = "Greyscale (8-bit)",
98 .guid = UVC_GUID_FORMAT_Y800,
99 .fcc = V4L2_PIX_FMT_GREY,
102 .name = "Greyscale (16-bit)",
103 .guid = UVC_GUID_FORMAT_Y16,
104 .fcc = V4L2_PIX_FMT_Y16,
108 .guid = UVC_GUID_FORMAT_BY8,
109 .fcc = V4L2_PIX_FMT_SBGGR8,
113 .guid = UVC_GUID_FORMAT_RGBP,
114 .fcc = V4L2_PIX_FMT_RGB565,
118 /* ------------------------------------------------------------------------
122 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
125 struct usb_host_endpoint *ep;
128 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
129 ep = &alts->endpoint[i];
130 if (ep->desc.bEndpointAddress == epaddr)
137 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
139 unsigned int len = ARRAY_SIZE(uvc_fmts);
142 for (i = 0; i < len; ++i) {
143 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
150 static __u32 uvc_colorspace(const __u8 primaries)
152 static const __u8 colorprimaries[] = {
154 V4L2_COLORSPACE_SRGB,
155 V4L2_COLORSPACE_470_SYSTEM_M,
156 V4L2_COLORSPACE_470_SYSTEM_BG,
157 V4L2_COLORSPACE_SMPTE170M,
158 V4L2_COLORSPACE_SMPTE240M,
161 if (primaries < ARRAY_SIZE(colorprimaries))
162 return colorprimaries[primaries];
167 /* Simplify a fraction using a simple continued fraction decomposition. The
168 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
169 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
170 * arbitrary parameters to remove non-significative terms from the simple
171 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
172 * respectively seems to give nice results.
174 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
175 unsigned int n_terms, unsigned int threshold)
181 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
185 /* Convert the fraction to a simple continued fraction. See
186 * http://mathforum.org/dr.math/faq/faq.fractions.html
187 * Stop if the current term is bigger than or equal to the given
193 for (n = 0; n < n_terms && y != 0; ++n) {
195 if (an[n] >= threshold) {
206 /* Expand the simple continued fraction back to an integer fraction. */
210 for (i = n; i > 0; --i) {
221 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
222 * to compute numerator / denominator * 10000000 using 32 bit fixed point
225 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
229 /* Saturate the result if the operation would overflow. */
230 if (denominator == 0 ||
231 numerator/denominator >= ((uint32_t)-1)/10000000)
234 /* Divide both the denominator and the multiplier by two until
235 * numerator * multiplier doesn't overflow. If anyone knows a better
236 * algorithm please let me know.
238 multiplier = 10000000;
239 while (numerator > ((uint32_t)-1)/multiplier) {
244 return denominator ? numerator * multiplier / denominator : 0;
247 /* ------------------------------------------------------------------------
248 * Terminal and unit management
251 static struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
253 struct uvc_entity *entity;
255 list_for_each_entry(entity, &dev->entities, list) {
256 if (entity->id == id)
263 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
264 int id, struct uvc_entity *entity)
269 entity = list_entry(&dev->entities, struct uvc_entity, list);
271 list_for_each_entry_continue(entity, &dev->entities, list) {
272 for (i = 0; i < entity->bNrInPins; ++i)
273 if (entity->baSourceID[i] == id)
280 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
282 struct uvc_streaming *stream;
284 list_for_each_entry(stream, &dev->streams, list) {
285 if (stream->header.bTerminalLink == id)
292 /* ------------------------------------------------------------------------
293 * Descriptors parsing
296 static int uvc_parse_format(struct uvc_device *dev,
297 struct uvc_streaming *streaming, struct uvc_format *format,
298 __u32 **intervals, unsigned char *buffer, int buflen)
300 struct usb_interface *intf = streaming->intf;
301 struct usb_host_interface *alts = intf->cur_altsetting;
302 struct uvc_format_desc *fmtdesc;
303 struct uvc_frame *frame;
304 const unsigned char *start = buffer;
305 unsigned int interval;
309 format->type = buffer[2];
310 format->index = buffer[3];
313 case UVC_VS_FORMAT_UNCOMPRESSED:
314 case UVC_VS_FORMAT_FRAME_BASED:
315 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
317 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
318 "interface %d FORMAT error\n",
320 alts->desc.bInterfaceNumber);
324 /* Find the format descriptor from its GUID. */
325 fmtdesc = uvc_format_by_guid(&buffer[5]);
327 if (fmtdesc != NULL) {
328 strlcpy(format->name, fmtdesc->name,
329 sizeof format->name);
330 format->fcc = fmtdesc->fcc;
332 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
334 snprintf(format->name, sizeof(format->name), "%pUl\n",
339 format->bpp = buffer[21];
340 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
341 ftype = UVC_VS_FRAME_UNCOMPRESSED;
343 ftype = UVC_VS_FRAME_FRAME_BASED;
345 format->flags = UVC_FMT_FLAG_COMPRESSED;
349 case UVC_VS_FORMAT_MJPEG:
351 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
352 "interface %d FORMAT error\n",
354 alts->desc.bInterfaceNumber);
358 strlcpy(format->name, "MJPEG", sizeof format->name);
359 format->fcc = V4L2_PIX_FMT_MJPEG;
360 format->flags = UVC_FMT_FLAG_COMPRESSED;
362 ftype = UVC_VS_FRAME_MJPEG;
365 case UVC_VS_FORMAT_DV:
367 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
368 "interface %d FORMAT error\n",
370 alts->desc.bInterfaceNumber);
374 switch (buffer[8] & 0x7f) {
376 strlcpy(format->name, "SD-DV", sizeof format->name);
379 strlcpy(format->name, "SDL-DV", sizeof format->name);
382 strlcpy(format->name, "HD-DV", sizeof format->name);
385 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
386 "interface %d: unknown DV format %u\n",
388 alts->desc.bInterfaceNumber, buffer[8]);
392 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
393 sizeof format->name);
395 format->fcc = V4L2_PIX_FMT_DV;
396 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
400 /* Create a dummy frame descriptor. */
401 frame = &format->frame[0];
402 memset(&format->frame[0], 0, sizeof format->frame[0]);
403 frame->bFrameIntervalType = 1;
404 frame->dwDefaultFrameInterval = 1;
405 frame->dwFrameInterval = *intervals;
410 case UVC_VS_FORMAT_MPEG2TS:
411 case UVC_VS_FORMAT_STREAM_BASED:
412 /* Not supported yet. */
414 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
415 "interface %d unsupported format %u\n",
416 dev->udev->devnum, alts->desc.bInterfaceNumber,
421 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
426 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
427 * based formats have frame descriptors.
429 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
430 buffer[2] == ftype) {
431 frame = &format->frame[format->nframes];
432 if (ftype != UVC_VS_FRAME_FRAME_BASED)
433 n = buflen > 25 ? buffer[25] : 0;
435 n = buflen > 21 ? buffer[21] : 0;
439 if (buflen < 26 + 4*n) {
440 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
441 "interface %d FRAME error\n", dev->udev->devnum,
442 alts->desc.bInterfaceNumber);
446 frame->bFrameIndex = buffer[3];
447 frame->bmCapabilities = buffer[4];
448 frame->wWidth = get_unaligned_le16(&buffer[5]);
449 frame->wHeight = get_unaligned_le16(&buffer[7]);
450 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
451 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
452 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
453 frame->dwMaxVideoFrameBufferSize =
454 get_unaligned_le32(&buffer[17]);
455 frame->dwDefaultFrameInterval =
456 get_unaligned_le32(&buffer[21]);
457 frame->bFrameIntervalType = buffer[25];
459 frame->dwMaxVideoFrameBufferSize = 0;
460 frame->dwDefaultFrameInterval =
461 get_unaligned_le32(&buffer[17]);
462 frame->bFrameIntervalType = buffer[21];
464 frame->dwFrameInterval = *intervals;
466 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
467 * completely. Observed behaviours range from setting the
468 * value to 1.1x the actual frame size to hardwiring the
469 * 16 low bits to 0. This results in a higher than necessary
470 * memory usage as well as a wrong image size information. For
471 * uncompressed formats this can be fixed by computing the
472 * value from the frame size.
474 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
475 frame->dwMaxVideoFrameBufferSize = format->bpp
476 * frame->wWidth * frame->wHeight / 8;
478 /* Some bogus devices report dwMinFrameInterval equal to
479 * dwMaxFrameInterval and have dwFrameIntervalStep set to
480 * zero. Setting all null intervals to 1 fixes the problem and
481 * some other divisions by zero that could happen.
483 for (i = 0; i < n; ++i) {
484 interval = get_unaligned_le32(&buffer[26+4*i]);
485 *(*intervals)++ = interval ? interval : 1;
488 /* Make sure that the default frame interval stays between
491 n -= frame->bFrameIntervalType ? 1 : 2;
492 frame->dwDefaultFrameInterval =
493 min(frame->dwFrameInterval[n],
494 max(frame->dwFrameInterval[0],
495 frame->dwDefaultFrameInterval));
497 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
498 frame->bFrameIntervalType = 1;
499 frame->dwFrameInterval[0] =
500 frame->dwDefaultFrameInterval;
503 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
504 frame->wWidth, frame->wHeight,
505 10000000/frame->dwDefaultFrameInterval,
506 (100000000/frame->dwDefaultFrameInterval)%10);
513 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
514 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
519 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
520 buffer[2] == UVC_VS_COLORFORMAT) {
522 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
523 "interface %d COLORFORMAT error\n",
525 alts->desc.bInterfaceNumber);
529 format->colorspace = uvc_colorspace(buffer[3]);
535 return buffer - start;
538 static int uvc_parse_streaming(struct uvc_device *dev,
539 struct usb_interface *intf)
541 struct uvc_streaming *streaming = NULL;
542 struct uvc_format *format;
543 struct uvc_frame *frame;
544 struct usb_host_interface *alts = &intf->altsetting[0];
545 unsigned char *_buffer, *buffer = alts->extra;
546 int _buflen, buflen = alts->extralen;
547 unsigned int nformats = 0, nframes = 0, nintervals = 0;
548 unsigned int size, i, n, p;
553 if (intf->cur_altsetting->desc.bInterfaceSubClass
554 != UVC_SC_VIDEOSTREAMING) {
555 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
556 "video streaming interface\n", dev->udev->devnum,
557 intf->altsetting[0].desc.bInterfaceNumber);
561 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
562 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
563 "claimed\n", dev->udev->devnum,
564 intf->altsetting[0].desc.bInterfaceNumber);
568 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
569 if (streaming == NULL) {
570 usb_driver_release_interface(&uvc_driver.driver, intf);
574 mutex_init(&streaming->mutex);
575 streaming->dev = dev;
576 streaming->intf = usb_get_intf(intf);
577 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
579 /* The Pico iMage webcam has its class-specific interface descriptors
580 * after the endpoint descriptors.
583 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
584 struct usb_host_endpoint *ep = &alts->endpoint[i];
586 if (ep->extralen == 0)
589 if (ep->extralen > 2 &&
590 ep->extra[1] == USB_DT_CS_INTERFACE) {
591 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
592 "from endpoint %u.\n", i);
593 buffer = alts->endpoint[i].extra;
594 buflen = alts->endpoint[i].extralen;
600 /* Skip the standard interface descriptors. */
601 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
607 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
608 "interface descriptors found.\n");
612 /* Parse the header descriptor. */
614 case UVC_VS_OUTPUT_HEADER:
615 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
619 case UVC_VS_INPUT_HEADER:
620 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
625 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
626 "%d HEADER descriptor not found.\n", dev->udev->devnum,
627 alts->desc.bInterfaceNumber);
631 p = buflen >= 4 ? buffer[3] : 0;
632 n = buflen >= size ? buffer[size-1] : 0;
634 if (buflen < size + p*n) {
635 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
636 "interface %d HEADER descriptor is invalid.\n",
637 dev->udev->devnum, alts->desc.bInterfaceNumber);
641 streaming->header.bNumFormats = p;
642 streaming->header.bEndpointAddress = buffer[6];
643 if (buffer[2] == UVC_VS_INPUT_HEADER) {
644 streaming->header.bmInfo = buffer[7];
645 streaming->header.bTerminalLink = buffer[8];
646 streaming->header.bStillCaptureMethod = buffer[9];
647 streaming->header.bTriggerSupport = buffer[10];
648 streaming->header.bTriggerUsage = buffer[11];
650 streaming->header.bTerminalLink = buffer[7];
652 streaming->header.bControlSize = n;
654 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
656 if (streaming->header.bmaControls == NULL) {
667 /* Count the format and frame descriptors. */
668 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
669 switch (_buffer[2]) {
670 case UVC_VS_FORMAT_UNCOMPRESSED:
671 case UVC_VS_FORMAT_MJPEG:
672 case UVC_VS_FORMAT_FRAME_BASED:
676 case UVC_VS_FORMAT_DV:
677 /* DV format has no frame descriptor. We will create a
678 * dummy frame descriptor with a dummy frame interval.
685 case UVC_VS_FORMAT_MPEG2TS:
686 case UVC_VS_FORMAT_STREAM_BASED:
687 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
688 "interface %d FORMAT %u is not supported.\n",
690 alts->desc.bInterfaceNumber, _buffer[2]);
693 case UVC_VS_FRAME_UNCOMPRESSED:
694 case UVC_VS_FRAME_MJPEG:
697 nintervals += _buffer[25] ? _buffer[25] : 3;
700 case UVC_VS_FRAME_FRAME_BASED:
703 nintervals += _buffer[21] ? _buffer[21] : 3;
707 _buflen -= _buffer[0];
708 _buffer += _buffer[0];
712 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
713 "%d has no supported formats defined.\n",
714 dev->udev->devnum, alts->desc.bInterfaceNumber);
718 size = nformats * sizeof *format + nframes * sizeof *frame
719 + nintervals * sizeof *interval;
720 format = kzalloc(size, GFP_KERNEL);
721 if (format == NULL) {
726 frame = (struct uvc_frame *)&format[nformats];
727 interval = (__u32 *)&frame[nframes];
729 streaming->format = format;
730 streaming->nformats = nformats;
732 /* Parse the format descriptors. */
733 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
735 case UVC_VS_FORMAT_UNCOMPRESSED:
736 case UVC_VS_FORMAT_MJPEG:
737 case UVC_VS_FORMAT_DV:
738 case UVC_VS_FORMAT_FRAME_BASED:
739 format->frame = frame;
740 ret = uvc_parse_format(dev, streaming, format,
741 &interval, buffer, buflen);
745 frame += format->nframes;
761 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
762 "%d has %u bytes of trailing descriptor garbage.\n",
763 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
765 /* Parse the alternate settings to find the maximum bandwidth. */
766 for (i = 0; i < intf->num_altsetting; ++i) {
767 struct usb_host_endpoint *ep;
768 alts = &intf->altsetting[i];
769 ep = uvc_find_endpoint(alts,
770 streaming->header.bEndpointAddress);
774 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
775 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
776 if (psize > streaming->maxpsize)
777 streaming->maxpsize = psize;
780 list_add_tail(&streaming->list, &dev->streams);
784 usb_driver_release_interface(&uvc_driver.driver, intf);
786 kfree(streaming->format);
787 kfree(streaming->header.bmaControls);
792 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
793 unsigned int num_pads, unsigned int extra_size)
795 struct uvc_entity *entity;
796 unsigned int num_inputs;
799 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
800 size = sizeof(*entity) + extra_size + num_inputs;
801 entity = kzalloc(size, GFP_KERNEL);
808 entity->bNrInPins = num_inputs;
809 entity->baSourceID = ((__u8 *)entity) + sizeof(*entity) + extra_size;
814 /* Parse vendor-specific extensions. */
815 static int uvc_parse_vendor_control(struct uvc_device *dev,
816 const unsigned char *buffer, int buflen)
818 struct usb_device *udev = dev->udev;
819 struct usb_host_interface *alts = dev->intf->cur_altsetting;
820 struct uvc_entity *unit;
824 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
825 case 0x046d: /* Logitech */
826 if (buffer[1] != 0x41 || buffer[2] != 0x01)
829 /* Logitech implements several vendor specific functions
830 * through vendor specific extension units (LXU).
832 * The LXU descriptors are similar to XU descriptors
833 * (see "USB Device Video Class for Video Devices", section
834 * 3.7.2.6 "Extension Unit Descriptor") with the following
837 * ----------------------------------------------------------
839 * Size of this descriptor, in bytes: 24+p+n*2
840 * ----------------------------------------------------------
841 * 23+p+n bmControlsType N Bitmap
842 * Individual bits in the set are defined:
846 * This bitset is mapped exactly the same as bmControls.
847 * ----------------------------------------------------------
848 * 23+p+n*2 bReserved 1 Boolean
849 * ----------------------------------------------------------
850 * 24+p+n*2 iExtension 1 Index
851 * Index of a string descriptor that describes this
853 * ----------------------------------------------------------
855 p = buflen >= 22 ? buffer[21] : 0;
856 n = buflen >= 25 + p ? buffer[22+p] : 0;
858 if (buflen < 25 + p + 2*n) {
859 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
860 "interface %d EXTENSION_UNIT error\n",
861 udev->devnum, alts->desc.bInterfaceNumber);
865 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
870 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
871 unit->extension.bNumControls = buffer[20];
872 memcpy(unit->baSourceID, &buffer[22], p);
873 unit->extension.bControlSize = buffer[22+p];
874 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
875 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
877 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
879 if (buffer[24+p+2*n] != 0)
880 usb_string(udev, buffer[24+p+2*n], unit->name,
883 sprintf(unit->name, "Extension %u", buffer[3]);
885 list_add_tail(&unit->list, &dev->entities);
893 static int uvc_parse_standard_control(struct uvc_device *dev,
894 const unsigned char *buffer, int buflen)
896 struct usb_device *udev = dev->udev;
897 struct uvc_entity *unit, *term;
898 struct usb_interface *intf;
899 struct usb_host_interface *alts = dev->intf->cur_altsetting;
900 unsigned int i, n, p, len;
905 n = buflen >= 12 ? buffer[11] : 0;
907 if (buflen < 12 || buflen < 12 + n) {
908 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
909 "interface %d HEADER error\n", udev->devnum,
910 alts->desc.bInterfaceNumber);
914 dev->uvc_version = get_unaligned_le16(&buffer[3]);
915 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
917 /* Parse all USB Video Streaming interfaces. */
918 for (i = 0; i < n; ++i) {
919 intf = usb_ifnum_to_if(udev, buffer[12+i]);
921 uvc_trace(UVC_TRACE_DESCR, "device %d "
922 "interface %d doesn't exists\n",
927 uvc_parse_streaming(dev, intf);
931 case UVC_VC_INPUT_TERMINAL:
933 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
934 "interface %d INPUT_TERMINAL error\n",
935 udev->devnum, alts->desc.bInterfaceNumber);
939 /* Make sure the terminal type MSB is not null, otherwise it
940 * could be confused with a unit.
942 type = get_unaligned_le16(&buffer[4]);
943 if ((type & 0xff00) == 0) {
944 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
945 "interface %d INPUT_TERMINAL %d has invalid "
946 "type 0x%04x, skipping\n", udev->devnum,
947 alts->desc.bInterfaceNumber,
956 if (type == UVC_ITT_CAMERA) {
957 n = buflen >= 15 ? buffer[14] : 0;
960 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
961 n = buflen >= 9 ? buffer[8] : 0;
962 p = buflen >= 10 + n ? buffer[9+n] : 0;
966 if (buflen < len + n + p) {
967 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
968 "interface %d INPUT_TERMINAL error\n",
969 udev->devnum, alts->desc.bInterfaceNumber);
973 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
978 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
979 term->camera.bControlSize = n;
980 term->camera.bmControls = (__u8 *)term + sizeof *term;
981 term->camera.wObjectiveFocalLengthMin =
982 get_unaligned_le16(&buffer[8]);
983 term->camera.wObjectiveFocalLengthMax =
984 get_unaligned_le16(&buffer[10]);
985 term->camera.wOcularFocalLength =
986 get_unaligned_le16(&buffer[12]);
987 memcpy(term->camera.bmControls, &buffer[15], n);
988 } else if (UVC_ENTITY_TYPE(term) ==
989 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
990 term->media.bControlSize = n;
991 term->media.bmControls = (__u8 *)term + sizeof *term;
992 term->media.bTransportModeSize = p;
993 term->media.bmTransportModes = (__u8 *)term
995 memcpy(term->media.bmControls, &buffer[9], n);
996 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1000 usb_string(udev, buffer[7], term->name,
1002 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1003 sprintf(term->name, "Camera %u", buffer[3]);
1004 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1005 sprintf(term->name, "Media %u", buffer[3]);
1007 sprintf(term->name, "Input %u", buffer[3]);
1009 list_add_tail(&term->list, &dev->entities);
1012 case UVC_VC_OUTPUT_TERMINAL:
1014 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1015 "interface %d OUTPUT_TERMINAL error\n",
1016 udev->devnum, alts->desc.bInterfaceNumber);
1020 /* Make sure the terminal type MSB is not null, otherwise it
1021 * could be confused with a unit.
1023 type = get_unaligned_le16(&buffer[4]);
1024 if ((type & 0xff00) == 0) {
1025 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1026 "interface %d OUTPUT_TERMINAL %d has invalid "
1027 "type 0x%04x, skipping\n", udev->devnum,
1028 alts->desc.bInterfaceNumber, buffer[3], type);
1032 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1037 memcpy(term->baSourceID, &buffer[7], 1);
1040 usb_string(udev, buffer[8], term->name,
1043 sprintf(term->name, "Output %u", buffer[3]);
1045 list_add_tail(&term->list, &dev->entities);
1048 case UVC_VC_SELECTOR_UNIT:
1049 p = buflen >= 5 ? buffer[4] : 0;
1051 if (buflen < 5 || buflen < 6 + p) {
1052 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1053 "interface %d SELECTOR_UNIT error\n",
1054 udev->devnum, alts->desc.bInterfaceNumber);
1058 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1062 memcpy(unit->baSourceID, &buffer[5], p);
1064 if (buffer[5+p] != 0)
1065 usb_string(udev, buffer[5+p], unit->name,
1068 sprintf(unit->name, "Selector %u", buffer[3]);
1070 list_add_tail(&unit->list, &dev->entities);
1073 case UVC_VC_PROCESSING_UNIT:
1074 n = buflen >= 8 ? buffer[7] : 0;
1075 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1077 if (buflen < p + n) {
1078 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1079 "interface %d PROCESSING_UNIT error\n",
1080 udev->devnum, alts->desc.bInterfaceNumber);
1084 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1088 memcpy(unit->baSourceID, &buffer[4], 1);
1089 unit->processing.wMaxMultiplier =
1090 get_unaligned_le16(&buffer[5]);
1091 unit->processing.bControlSize = buffer[7];
1092 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1093 memcpy(unit->processing.bmControls, &buffer[8], n);
1094 if (dev->uvc_version >= 0x0110)
1095 unit->processing.bmVideoStandards = buffer[9+n];
1097 if (buffer[8+n] != 0)
1098 usb_string(udev, buffer[8+n], unit->name,
1101 sprintf(unit->name, "Processing %u", buffer[3]);
1103 list_add_tail(&unit->list, &dev->entities);
1106 case UVC_VC_EXTENSION_UNIT:
1107 p = buflen >= 22 ? buffer[21] : 0;
1108 n = buflen >= 24 + p ? buffer[22+p] : 0;
1110 if (buflen < 24 + p + n) {
1111 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1112 "interface %d EXTENSION_UNIT error\n",
1113 udev->devnum, alts->desc.bInterfaceNumber);
1117 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1121 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1122 unit->extension.bNumControls = buffer[20];
1123 memcpy(unit->baSourceID, &buffer[22], p);
1124 unit->extension.bControlSize = buffer[22+p];
1125 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1126 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1128 if (buffer[23+p+n] != 0)
1129 usb_string(udev, buffer[23+p+n], unit->name,
1132 sprintf(unit->name, "Extension %u", buffer[3]);
1134 list_add_tail(&unit->list, &dev->entities);
1138 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1139 "descriptor (%u)\n", buffer[2]);
1146 static int uvc_parse_control(struct uvc_device *dev)
1148 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1149 unsigned char *buffer = alts->extra;
1150 int buflen = alts->extralen;
1153 /* Parse the default alternate setting only, as the UVC specification
1154 * defines a single alternate setting, the default alternate setting
1158 while (buflen > 2) {
1159 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1160 buffer[1] != USB_DT_CS_INTERFACE)
1161 goto next_descriptor;
1163 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1167 buflen -= buffer[0];
1168 buffer += buffer[0];
1171 /* Check if the optional status endpoint is present. Built-in iSight
1172 * webcams have an interrupt endpoint but spit proprietary data that
1173 * don't conform to the UVC status endpoint messages. Don't try to
1174 * handle the interrupt endpoint for those cameras.
1176 if (alts->desc.bNumEndpoints == 1 &&
1177 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1178 struct usb_host_endpoint *ep = &alts->endpoint[0];
1179 struct usb_endpoint_descriptor *desc = &ep->desc;
1181 if (usb_endpoint_is_int_in(desc) &&
1182 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1183 desc->bInterval != 0) {
1184 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1185 "(addr %02x).\n", desc->bEndpointAddress);
1193 /* ------------------------------------------------------------------------
1198 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1199 * and containing the following units:
1201 * - one or more Output Terminals (USB Streaming or Display)
1202 * - zero or one Processing Unit
1203 * - zero, one or more single-input Selector Units
1204 * - zero or one multiple-input Selector Units, provided all inputs are
1205 * connected to input terminals
1206 * - zero, one or mode single-input Extension Units
1207 * - one or more Input Terminals (Camera, External or USB Streaming)
1209 * The terminal and units must match on of the following structures:
1211 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1212 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1213 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1215 * +---------+ +---------+ -> OTT_*(0)
1216 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1217 * +---------+ +---------+ -> OTT_*(n)
1219 * The Processing Unit and Extension Units can be in any order. Additional
1220 * Extension Units connected to the main chain as single-unit branches are
1221 * also supported. Single-input Selector Units are ignored.
1223 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1224 struct uvc_entity *entity)
1226 switch (UVC_ENTITY_TYPE(entity)) {
1227 case UVC_VC_EXTENSION_UNIT:
1228 if (uvc_trace_param & UVC_TRACE_PROBE)
1229 printk(" <- XU %d", entity->id);
1231 if (entity->bNrInPins != 1) {
1232 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1233 "than 1 input pin.\n", entity->id);
1239 case UVC_VC_PROCESSING_UNIT:
1240 if (uvc_trace_param & UVC_TRACE_PROBE)
1241 printk(" <- PU %d", entity->id);
1243 if (chain->processing != NULL) {
1244 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1245 "Processing Units in chain.\n");
1249 chain->processing = entity;
1252 case UVC_VC_SELECTOR_UNIT:
1253 if (uvc_trace_param & UVC_TRACE_PROBE)
1254 printk(" <- SU %d", entity->id);
1256 /* Single-input selector units are ignored. */
1257 if (entity->bNrInPins == 1)
1260 if (chain->selector != NULL) {
1261 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1262 "Units in chain.\n");
1266 chain->selector = entity;
1269 case UVC_ITT_VENDOR_SPECIFIC:
1270 case UVC_ITT_CAMERA:
1271 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1272 if (uvc_trace_param & UVC_TRACE_PROBE)
1273 printk(" <- IT %d\n", entity->id);
1277 case UVC_OTT_VENDOR_SPECIFIC:
1278 case UVC_OTT_DISPLAY:
1279 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1280 if (uvc_trace_param & UVC_TRACE_PROBE)
1281 printk(" OT %d", entity->id);
1285 case UVC_TT_STREAMING:
1286 if (UVC_ENTITY_IS_ITERM(entity)) {
1287 if (uvc_trace_param & UVC_TRACE_PROBE)
1288 printk(" <- IT %d\n", entity->id);
1290 if (uvc_trace_param & UVC_TRACE_PROBE)
1291 printk(" OT %d", entity->id);
1297 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1298 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1302 list_add_tail(&entity->chain, &chain->entities);
1306 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1307 struct uvc_entity *entity, struct uvc_entity *prev)
1309 struct uvc_entity *forward;
1317 forward = uvc_entity_by_reference(chain->dev, entity->id,
1319 if (forward == NULL)
1321 if (forward == prev)
1324 switch (UVC_ENTITY_TYPE(forward)) {
1325 case UVC_VC_EXTENSION_UNIT:
1326 if (forward->bNrInPins != 1) {
1327 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1328 "has more than 1 input pin.\n",
1333 list_add_tail(&forward->chain, &chain->entities);
1334 if (uvc_trace_param & UVC_TRACE_PROBE) {
1338 printk(" XU %d", forward->id);
1343 case UVC_OTT_VENDOR_SPECIFIC:
1344 case UVC_OTT_DISPLAY:
1345 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1346 case UVC_TT_STREAMING:
1347 if (UVC_ENTITY_IS_ITERM(forward)) {
1348 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1349 "terminal %u.\n", forward->id);
1353 list_add_tail(&forward->chain, &chain->entities);
1354 if (uvc_trace_param & UVC_TRACE_PROBE) {
1358 printk(" OT %d", forward->id);
1370 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1371 struct uvc_entity **_entity)
1373 struct uvc_entity *entity = *_entity;
1374 struct uvc_entity *term;
1375 int id = -EINVAL, i;
1377 switch (UVC_ENTITY_TYPE(entity)) {
1378 case UVC_VC_EXTENSION_UNIT:
1379 case UVC_VC_PROCESSING_UNIT:
1380 id = entity->baSourceID[0];
1383 case UVC_VC_SELECTOR_UNIT:
1384 /* Single-input selector units are ignored. */
1385 if (entity->bNrInPins == 1) {
1386 id = entity->baSourceID[0];
1390 if (uvc_trace_param & UVC_TRACE_PROBE)
1393 chain->selector = entity;
1394 for (i = 0; i < entity->bNrInPins; ++i) {
1395 id = entity->baSourceID[i];
1396 term = uvc_entity_by_id(chain->dev, id);
1397 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1398 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1399 "input %d isn't connected to an "
1400 "input terminal\n", entity->id, i);
1404 if (uvc_trace_param & UVC_TRACE_PROBE)
1405 printk(" %d", term->id);
1407 list_add_tail(&term->chain, &chain->entities);
1408 uvc_scan_chain_forward(chain, term, entity);
1411 if (uvc_trace_param & UVC_TRACE_PROBE)
1417 case UVC_ITT_VENDOR_SPECIFIC:
1418 case UVC_ITT_CAMERA:
1419 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1420 case UVC_OTT_VENDOR_SPECIFIC:
1421 case UVC_OTT_DISPLAY:
1422 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1423 case UVC_TT_STREAMING:
1424 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1433 entity = uvc_entity_by_id(chain->dev, id);
1434 if (entity == NULL) {
1435 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1436 "unknown entity %d.\n", id);
1444 static int uvc_scan_chain(struct uvc_video_chain *chain,
1445 struct uvc_entity *term)
1447 struct uvc_entity *entity, *prev;
1449 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1454 while (entity != NULL) {
1455 /* Entity must not be part of an existing chain */
1456 if (entity->chain.next || entity->chain.prev) {
1457 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1458 "entity %d already in chain.\n", entity->id);
1462 /* Process entity */
1463 if (uvc_scan_chain_entity(chain, entity) < 0)
1467 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1472 if (uvc_scan_chain_backward(chain, &entity) < 0)
1479 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1482 struct uvc_entity *term;
1483 unsigned int nterms = 0;
1486 list_for_each_entry(term, terms, chain) {
1487 if (!UVC_ENTITY_IS_TERM(term) ||
1488 UVC_TERM_DIRECTION(term) != dir)
1492 p += sprintf(p, ",");
1493 if (++nterms >= 4) {
1494 p += sprintf(p, "...");
1497 p += sprintf(p, "%u", term->id);
1503 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1505 static char buffer[43];
1508 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1509 p += sprintf(p, " -> ");
1510 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1516 * Scan the device for video chains and register video devices.
1518 * Chains are scanned starting at their output terminals and walked backwards.
1520 static int uvc_scan_device(struct uvc_device *dev)
1522 struct uvc_video_chain *chain;
1523 struct uvc_entity *term;
1525 list_for_each_entry(term, &dev->entities, list) {
1526 if (!UVC_ENTITY_IS_OTERM(term))
1529 /* If the terminal is already included in a chain, skip it.
1530 * This can happen for chains that have multiple output
1531 * terminals, where all output terminals beside the first one
1532 * will be inserted in the chain in forward scans.
1534 if (term->chain.next || term->chain.prev)
1537 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1541 INIT_LIST_HEAD(&chain->entities);
1542 mutex_init(&chain->ctrl_mutex);
1545 if (uvc_scan_chain(chain, term) < 0) {
1550 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1551 uvc_print_chain(chain));
1553 list_add_tail(&chain->list, &dev->chains);
1556 if (list_empty(&dev->chains)) {
1557 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1564 /* ------------------------------------------------------------------------
1565 * Video device registration and unregistration
1569 * Delete the UVC device.
1571 * Called by the kernel when the last reference to the uvc_device structure
1574 * As this function is called after or during disconnect(), all URBs have
1575 * already been canceled by the USB core. There is no need to kill the
1576 * interrupt URB manually.
1578 static void uvc_delete(struct uvc_device *dev)
1580 struct list_head *p, *n;
1582 usb_put_intf(dev->intf);
1583 usb_put_dev(dev->udev);
1585 uvc_status_cleanup(dev);
1586 uvc_ctrl_cleanup_device(dev);
1588 list_for_each_safe(p, n, &dev->chains) {
1589 struct uvc_video_chain *chain;
1590 chain = list_entry(p, struct uvc_video_chain, list);
1594 list_for_each_safe(p, n, &dev->entities) {
1595 struct uvc_entity *entity;
1596 entity = list_entry(p, struct uvc_entity, list);
1600 list_for_each_safe(p, n, &dev->streams) {
1601 struct uvc_streaming *streaming;
1602 streaming = list_entry(p, struct uvc_streaming, list);
1603 usb_driver_release_interface(&uvc_driver.driver,
1605 usb_put_intf(streaming->intf);
1606 kfree(streaming->format);
1607 kfree(streaming->header.bmaControls);
1614 static void uvc_release(struct video_device *vdev)
1616 struct uvc_streaming *stream = video_get_drvdata(vdev);
1617 struct uvc_device *dev = stream->dev;
1619 video_device_release(vdev);
1621 /* Decrement the registered streams count and delete the device when it
1624 if (atomic_dec_and_test(&dev->nstreams))
1629 * Unregister the video devices.
1631 static void uvc_unregister_video(struct uvc_device *dev)
1633 struct uvc_streaming *stream;
1635 /* Unregistering all video devices might result in uvc_delete() being
1636 * called from inside the loop if there's no open file handle. To avoid
1637 * that, increment the stream count before iterating over the streams
1638 * and decrement it when done.
1640 atomic_inc(&dev->nstreams);
1642 list_for_each_entry(stream, &dev->streams, list) {
1643 if (stream->vdev == NULL)
1646 video_unregister_device(stream->vdev);
1647 stream->vdev = NULL;
1650 /* Decrement the stream count and call uvc_delete explicitly if there
1651 * are no stream left.
1653 if (atomic_dec_and_test(&dev->nstreams))
1657 static int uvc_register_video(struct uvc_device *dev,
1658 struct uvc_streaming *stream)
1660 struct video_device *vdev;
1663 /* Initialize the streaming interface with default streaming
1666 ret = uvc_video_init(stream);
1668 uvc_printk(KERN_ERR, "Failed to initialize the device "
1673 /* Register the device with V4L. */
1674 vdev = video_device_alloc();
1676 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1681 /* We already hold a reference to dev->udev. The video device will be
1682 * unregistered before the reference is released, so we don't need to
1685 vdev->parent = &dev->intf->dev;
1686 vdev->fops = &uvc_fops;
1687 vdev->release = uvc_release;
1688 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1690 /* Set the driver data before calling video_register_device, otherwise
1691 * uvc_v4l2_open might race us.
1693 stream->vdev = vdev;
1694 video_set_drvdata(vdev, stream);
1696 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1698 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1700 stream->vdev = NULL;
1701 video_device_release(vdev);
1705 atomic_inc(&dev->nstreams);
1710 * Register all video devices in all chains.
1712 static int uvc_register_terms(struct uvc_device *dev,
1713 struct uvc_video_chain *chain)
1715 struct uvc_streaming *stream;
1716 struct uvc_entity *term;
1719 list_for_each_entry(term, &chain->entities, chain) {
1720 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1723 stream = uvc_stream_by_id(dev, term->id);
1724 if (stream == NULL) {
1725 uvc_printk(KERN_INFO, "No streaming interface found "
1726 "for terminal %u.", term->id);
1730 stream->chain = chain;
1731 ret = uvc_register_video(dev, stream);
1739 static int uvc_register_chains(struct uvc_device *dev)
1741 struct uvc_video_chain *chain;
1744 list_for_each_entry(chain, &dev->chains, list) {
1745 ret = uvc_register_terms(dev, chain);
1753 /* ------------------------------------------------------------------------
1754 * USB probe, disconnect, suspend and resume
1757 static int uvc_probe(struct usb_interface *intf,
1758 const struct usb_device_id *id)
1760 struct usb_device *udev = interface_to_usbdev(intf);
1761 struct uvc_device *dev;
1764 if (id->idVendor && id->idProduct)
1765 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1766 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1769 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1772 /* Allocate memory for the device and initialize it. */
1773 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1776 INIT_LIST_HEAD(&dev->entities);
1777 INIT_LIST_HEAD(&dev->chains);
1778 INIT_LIST_HEAD(&dev->streams);
1779 atomic_set(&dev->nstreams, 0);
1780 atomic_set(&dev->users, 0);
1781 atomic_set(&dev->nmappings, 0);
1783 dev->udev = usb_get_dev(udev);
1784 dev->intf = usb_get_intf(intf);
1785 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1786 dev->quirks = (uvc_quirks_param == -1)
1787 ? id->driver_info : uvc_quirks_param;
1789 if (udev->product != NULL)
1790 strlcpy(dev->name, udev->product, sizeof dev->name);
1792 snprintf(dev->name, sizeof dev->name,
1793 "UVC Camera (%04x:%04x)",
1794 le16_to_cpu(udev->descriptor.idVendor),
1795 le16_to_cpu(udev->descriptor.idProduct));
1797 /* Parse the Video Class control descriptor. */
1798 if (uvc_parse_control(dev) < 0) {
1799 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1804 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1805 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1806 udev->product ? udev->product : "<unnamed>",
1807 le16_to_cpu(udev->descriptor.idVendor),
1808 le16_to_cpu(udev->descriptor.idProduct));
1810 if (dev->quirks != id->driver_info) {
1811 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1812 "parameter for testing purpose.\n", dev->quirks);
1813 uvc_printk(KERN_INFO, "Please report required quirks to the "
1814 "linux-uvc-devel mailing list.\n");
1817 /* Initialize controls. */
1818 if (uvc_ctrl_init_device(dev) < 0)
1821 /* Scan the device for video chains. */
1822 if (uvc_scan_device(dev) < 0)
1825 /* Register video devices. */
1826 if (uvc_register_chains(dev) < 0)
1829 /* Save our data pointer in the interface data. */
1830 usb_set_intfdata(intf, dev);
1832 /* Initialize the interrupt URB. */
1833 if ((ret = uvc_status_init(dev)) < 0) {
1834 uvc_printk(KERN_INFO, "Unable to initialize the status "
1835 "endpoint (%d), status interrupt will not be "
1836 "supported.\n", ret);
1839 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1840 usb_enable_autosuspend(udev);
1844 uvc_unregister_video(dev);
1848 static void uvc_disconnect(struct usb_interface *intf)
1850 struct uvc_device *dev = usb_get_intfdata(intf);
1852 /* Set the USB interface data to NULL. This can be done outside the
1853 * lock, as there's no other reader.
1855 usb_set_intfdata(intf, NULL);
1857 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1858 UVC_SC_VIDEOSTREAMING)
1861 dev->state |= UVC_DEV_DISCONNECTED;
1863 uvc_unregister_video(dev);
1866 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1868 struct uvc_device *dev = usb_get_intfdata(intf);
1869 struct uvc_streaming *stream;
1871 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1872 intf->cur_altsetting->desc.bInterfaceNumber);
1874 /* Controls are cached on the fly so they don't need to be saved. */
1875 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1876 UVC_SC_VIDEOCONTROL)
1877 return uvc_status_suspend(dev);
1879 list_for_each_entry(stream, &dev->streams, list) {
1880 if (stream->intf == intf)
1881 return uvc_video_suspend(stream);
1884 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1889 static int __uvc_resume(struct usb_interface *intf, int reset)
1891 struct uvc_device *dev = usb_get_intfdata(intf);
1892 struct uvc_streaming *stream;
1894 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
1895 intf->cur_altsetting->desc.bInterfaceNumber);
1897 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1898 UVC_SC_VIDEOCONTROL) {
1900 int ret = uvc_ctrl_resume_device(dev);
1906 return uvc_status_resume(dev);
1909 list_for_each_entry(stream, &dev->streams, list) {
1910 if (stream->intf == intf)
1911 return uvc_video_resume(stream);
1914 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
1919 static int uvc_resume(struct usb_interface *intf)
1921 return __uvc_resume(intf, 0);
1924 static int uvc_reset_resume(struct usb_interface *intf)
1926 return __uvc_resume(intf, 1);
1929 /* ------------------------------------------------------------------------
1933 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
1935 if (uvc_clock_param == CLOCK_MONOTONIC)
1936 return sprintf(buffer, "CLOCK_MONOTONIC");
1938 return sprintf(buffer, "CLOCK_REALTIME");
1941 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
1943 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
1944 val += strlen("clock_");
1946 if (strcasecmp(val, "monotonic") == 0)
1947 uvc_clock_param = CLOCK_MONOTONIC;
1948 else if (strcasecmp(val, "realtime") == 0)
1949 uvc_clock_param = CLOCK_REALTIME;
1956 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
1957 &uvc_clock_param, S_IRUGO|S_IWUSR);
1958 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
1959 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
1960 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
1961 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
1962 MODULE_PARM_DESC(quirks, "Forced device quirks");
1963 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
1964 MODULE_PARM_DESC(trace, "Trace level bitmask");
1965 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
1966 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
1968 /* ------------------------------------------------------------------------
1969 * Driver initialization and cleanup
1973 * The Logitech cameras listed below have their interface class set to
1974 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
1975 * though they are compliant.
1977 static struct usb_device_id uvc_ids[] = {
1978 /* Genius eFace 2025 */
1979 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1980 | USB_DEVICE_ID_MATCH_INT_INFO,
1982 .idProduct = 0x706e,
1983 .bInterfaceClass = USB_CLASS_VIDEO,
1984 .bInterfaceSubClass = 1,
1985 .bInterfaceProtocol = 0,
1986 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1987 /* Microsoft Lifecam NX-6000 */
1988 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1989 | USB_DEVICE_ID_MATCH_INT_INFO,
1991 .idProduct = 0x00f8,
1992 .bInterfaceClass = USB_CLASS_VIDEO,
1993 .bInterfaceSubClass = 1,
1994 .bInterfaceProtocol = 0,
1995 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1996 /* Microsoft Lifecam VX-7000 */
1997 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1998 | USB_DEVICE_ID_MATCH_INT_INFO,
2000 .idProduct = 0x0723,
2001 .bInterfaceClass = USB_CLASS_VIDEO,
2002 .bInterfaceSubClass = 1,
2003 .bInterfaceProtocol = 0,
2004 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2005 /* Logitech Quickcam Fusion */
2006 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2007 | USB_DEVICE_ID_MATCH_INT_INFO,
2009 .idProduct = 0x08c1,
2010 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2011 .bInterfaceSubClass = 1,
2012 .bInterfaceProtocol = 0 },
2013 /* Logitech Quickcam Orbit MP */
2014 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2015 | USB_DEVICE_ID_MATCH_INT_INFO,
2017 .idProduct = 0x08c2,
2018 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2019 .bInterfaceSubClass = 1,
2020 .bInterfaceProtocol = 0 },
2021 /* Logitech Quickcam Pro for Notebook */
2022 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2023 | USB_DEVICE_ID_MATCH_INT_INFO,
2025 .idProduct = 0x08c3,
2026 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2027 .bInterfaceSubClass = 1,
2028 .bInterfaceProtocol = 0 },
2029 /* Logitech Quickcam Pro 5000 */
2030 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2031 | USB_DEVICE_ID_MATCH_INT_INFO,
2033 .idProduct = 0x08c5,
2034 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2035 .bInterfaceSubClass = 1,
2036 .bInterfaceProtocol = 0 },
2037 /* Logitech Quickcam OEM Dell Notebook */
2038 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2039 | USB_DEVICE_ID_MATCH_INT_INFO,
2041 .idProduct = 0x08c6,
2042 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2043 .bInterfaceSubClass = 1,
2044 .bInterfaceProtocol = 0 },
2045 /* Logitech Quickcam OEM Cisco VT Camera II */
2046 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2047 | USB_DEVICE_ID_MATCH_INT_INFO,
2049 .idProduct = 0x08c7,
2050 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2051 .bInterfaceSubClass = 1,
2052 .bInterfaceProtocol = 0 },
2053 /* Chicony CNF7129 (Asus EEE 100HE) */
2054 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2055 | USB_DEVICE_ID_MATCH_INT_INFO,
2057 .idProduct = 0xb071,
2058 .bInterfaceClass = USB_CLASS_VIDEO,
2059 .bInterfaceSubClass = 1,
2060 .bInterfaceProtocol = 0,
2061 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2062 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2063 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2064 | USB_DEVICE_ID_MATCH_INT_INFO,
2066 .idProduct = 0x3820,
2067 .bInterfaceClass = USB_CLASS_VIDEO,
2068 .bInterfaceSubClass = 1,
2069 .bInterfaceProtocol = 0,
2070 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2071 /* Apple Built-In iSight */
2072 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2073 | USB_DEVICE_ID_MATCH_INT_INFO,
2075 .idProduct = 0x8501,
2076 .bInterfaceClass = USB_CLASS_VIDEO,
2077 .bInterfaceSubClass = 1,
2078 .bInterfaceProtocol = 0,
2079 .driver_info = UVC_QUIRK_PROBE_MINMAX
2080 | UVC_QUIRK_BUILTIN_ISIGHT },
2081 /* Genesys Logic USB 2.0 PC Camera */
2082 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2083 | USB_DEVICE_ID_MATCH_INT_INFO,
2085 .idProduct = 0x0505,
2086 .bInterfaceClass = USB_CLASS_VIDEO,
2087 .bInterfaceSubClass = 1,
2088 .bInterfaceProtocol = 0,
2089 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2090 /* Hercules Classic Silver */
2091 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2092 | USB_DEVICE_ID_MATCH_INT_INFO,
2094 .idProduct = 0x300c,
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 = 0x332d,
2104 .bInterfaceClass = USB_CLASS_VIDEO,
2105 .bInterfaceSubClass = 1,
2106 .bInterfaceProtocol = 0,
2107 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2108 /* ViMicro - Minoru3D */
2109 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2110 | USB_DEVICE_ID_MATCH_INT_INFO,
2112 .idProduct = 0x3410,
2113 .bInterfaceClass = USB_CLASS_VIDEO,
2114 .bInterfaceSubClass = 1,
2115 .bInterfaceProtocol = 0,
2116 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2117 /* ViMicro Venus - Minoru3D */
2118 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2119 | USB_DEVICE_ID_MATCH_INT_INFO,
2121 .idProduct = 0x3420,
2122 .bInterfaceClass = USB_CLASS_VIDEO,
2123 .bInterfaceSubClass = 1,
2124 .bInterfaceProtocol = 0,
2125 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2127 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2128 | USB_DEVICE_ID_MATCH_INT_INFO,
2130 .idProduct = 0x0004,
2131 .bInterfaceClass = USB_CLASS_VIDEO,
2132 .bInterfaceSubClass = 1,
2133 .bInterfaceProtocol = 0,
2134 .driver_info = UVC_QUIRK_PROBE_MINMAX
2135 | UVC_QUIRK_PROBE_DEF },
2136 /* IMC Networks (Medion Akoya) */
2137 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2138 | USB_DEVICE_ID_MATCH_INT_INFO,
2140 .idProduct = 0x5103,
2141 .bInterfaceClass = USB_CLASS_VIDEO,
2142 .bInterfaceSubClass = 1,
2143 .bInterfaceProtocol = 0,
2144 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2145 /* JMicron USB2.0 XGA WebCam */
2146 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2147 | USB_DEVICE_ID_MATCH_INT_INFO,
2149 .idProduct = 0x0310,
2150 .bInterfaceClass = USB_CLASS_VIDEO,
2151 .bInterfaceSubClass = 1,
2152 .bInterfaceProtocol = 0,
2153 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2154 /* Syntek (HP Spartan) */
2155 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2156 | USB_DEVICE_ID_MATCH_INT_INFO,
2158 .idProduct = 0x5212,
2159 .bInterfaceClass = USB_CLASS_VIDEO,
2160 .bInterfaceSubClass = 1,
2161 .bInterfaceProtocol = 0,
2162 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2163 /* Syntek (Samsung Q310) */
2164 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2165 | USB_DEVICE_ID_MATCH_INT_INFO,
2167 .idProduct = 0x5931,
2168 .bInterfaceClass = USB_CLASS_VIDEO,
2169 .bInterfaceSubClass = 1,
2170 .bInterfaceProtocol = 0,
2171 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2172 /* Syntek (Packard Bell EasyNote MX52 */
2173 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2174 | USB_DEVICE_ID_MATCH_INT_INFO,
2176 .idProduct = 0x8a12,
2177 .bInterfaceClass = USB_CLASS_VIDEO,
2178 .bInterfaceSubClass = 1,
2179 .bInterfaceProtocol = 0,
2180 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2181 /* Syntek (Asus F9SG) */
2182 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2183 | USB_DEVICE_ID_MATCH_INT_INFO,
2185 .idProduct = 0x8a31,
2186 .bInterfaceClass = USB_CLASS_VIDEO,
2187 .bInterfaceSubClass = 1,
2188 .bInterfaceProtocol = 0,
2189 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2190 /* Syntek (Asus U3S) */
2191 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2192 | USB_DEVICE_ID_MATCH_INT_INFO,
2194 .idProduct = 0x8a33,
2195 .bInterfaceClass = USB_CLASS_VIDEO,
2196 .bInterfaceSubClass = 1,
2197 .bInterfaceProtocol = 0,
2198 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2199 /* Syntek (JAOtech Smart Terminal) */
2200 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2201 | USB_DEVICE_ID_MATCH_INT_INFO,
2203 .idProduct = 0x8a34,
2204 .bInterfaceClass = USB_CLASS_VIDEO,
2205 .bInterfaceSubClass = 1,
2206 .bInterfaceProtocol = 0,
2207 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2209 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2210 | USB_DEVICE_ID_MATCH_INT_INFO,
2212 .idProduct = 0x0202,
2213 .bInterfaceClass = USB_CLASS_VIDEO,
2214 .bInterfaceSubClass = 1,
2215 .bInterfaceProtocol = 0,
2216 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2217 /* Lenovo Thinkpad SL400/SL500 */
2218 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2219 | USB_DEVICE_ID_MATCH_INT_INFO,
2221 .idProduct = 0x480b,
2222 .bInterfaceClass = USB_CLASS_VIDEO,
2223 .bInterfaceSubClass = 1,
2224 .bInterfaceProtocol = 0,
2225 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2226 /* Aveo Technology USB 2.0 Camera */
2227 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2228 | USB_DEVICE_ID_MATCH_INT_INFO,
2230 .idProduct = 0x0306,
2231 .bInterfaceClass = USB_CLASS_VIDEO,
2232 .bInterfaceSubClass = 1,
2233 .bInterfaceProtocol = 0,
2234 .driver_info = UVC_QUIRK_PROBE_MINMAX
2235 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2236 /* Ecamm Pico iMage */
2237 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2238 | USB_DEVICE_ID_MATCH_INT_INFO,
2240 .idProduct = 0xcafe,
2241 .bInterfaceClass = USB_CLASS_VIDEO,
2242 .bInterfaceSubClass = 1,
2243 .bInterfaceProtocol = 0,
2244 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2245 /* Manta MM-353 Plako */
2246 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2247 | USB_DEVICE_ID_MATCH_INT_INFO,
2249 .idProduct = 0x3188,
2250 .bInterfaceClass = USB_CLASS_VIDEO,
2251 .bInterfaceSubClass = 1,
2252 .bInterfaceProtocol = 0,
2253 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2254 /* FSC WebCam V30S */
2255 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2256 | USB_DEVICE_ID_MATCH_INT_INFO,
2258 .idProduct = 0x3288,
2259 .bInterfaceClass = USB_CLASS_VIDEO,
2260 .bInterfaceSubClass = 1,
2261 .bInterfaceProtocol = 0,
2262 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2263 /* Arkmicro unbranded */
2264 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2265 | USB_DEVICE_ID_MATCH_INT_INFO,
2267 .idProduct = 0x3290,
2268 .bInterfaceClass = USB_CLASS_VIDEO,
2269 .bInterfaceSubClass = 1,
2270 .bInterfaceProtocol = 0,
2271 .driver_info = UVC_QUIRK_PROBE_DEF },
2272 /* Bodelin ProScopeHR */
2273 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2274 | USB_DEVICE_ID_MATCH_DEV_HI
2275 | USB_DEVICE_ID_MATCH_INT_INFO,
2277 .idProduct = 0x1000,
2278 .bcdDevice_hi = 0x0126,
2279 .bInterfaceClass = USB_CLASS_VIDEO,
2280 .bInterfaceSubClass = 1,
2281 .bInterfaceProtocol = 0,
2282 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2283 /* MSI StarCam 370i */
2284 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2285 | USB_DEVICE_ID_MATCH_INT_INFO,
2287 .idProduct = 0x2951,
2288 .bInterfaceClass = USB_CLASS_VIDEO,
2289 .bInterfaceSubClass = 1,
2290 .bInterfaceProtocol = 0,
2291 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2292 /* SiGma Micro USB Web Camera */
2293 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2294 | USB_DEVICE_ID_MATCH_INT_INFO,
2296 .idProduct = 0x3000,
2297 .bInterfaceClass = USB_CLASS_VIDEO,
2298 .bInterfaceSubClass = 1,
2299 .bInterfaceProtocol = 0,
2300 .driver_info = UVC_QUIRK_PROBE_MINMAX
2301 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2302 /* Generic USB Video Class */
2303 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2307 MODULE_DEVICE_TABLE(usb, uvc_ids);
2309 struct uvc_driver uvc_driver = {
2313 .disconnect = uvc_disconnect,
2314 .suspend = uvc_suspend,
2315 .resume = uvc_resume,
2316 .reset_resume = uvc_reset_resume,
2317 .id_table = uvc_ids,
2318 .supports_autosuspend = 1,
2322 static int __init uvc_init(void)
2326 result = usb_register(&uvc_driver.driver);
2328 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2332 static void __exit uvc_cleanup(void)
2334 usb_deregister(&uvc_driver.driver);
2337 module_init(uvc_init);
2338 module_exit(uvc_cleanup);
2340 MODULE_AUTHOR(DRIVER_AUTHOR);
2341 MODULE_DESCRIPTION(DRIVER_DESC);
2342 MODULE_LICENSE("GPL");
2343 MODULE_VERSION(DRIVER_VERSION);