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 <linux/version.h>
35 #include <asm/atomic.h>
36 #include <asm/unaligned.h>
38 #include <media/v4l2-common.h>
42 #define DRIVER_AUTHOR "Laurent Pinchart " \
43 "<laurent.pinchart@ideasonboard.com>"
44 #define DRIVER_DESC "USB Video Class driver"
46 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
47 unsigned int uvc_no_drop_param;
48 static unsigned int uvc_quirks_param = -1;
49 unsigned int uvc_trace_param;
50 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
52 /* ------------------------------------------------------------------------
56 static struct uvc_format_desc uvc_fmts[] = {
58 .name = "YUV 4:2:2 (YUYV)",
59 .guid = UVC_GUID_FORMAT_YUY2,
60 .fcc = V4L2_PIX_FMT_YUYV,
63 .name = "YUV 4:2:2 (YUYV)",
64 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
65 .fcc = V4L2_PIX_FMT_YUYV,
68 .name = "YUV 4:2:0 (NV12)",
69 .guid = UVC_GUID_FORMAT_NV12,
70 .fcc = V4L2_PIX_FMT_NV12,
74 .guid = UVC_GUID_FORMAT_MJPEG,
75 .fcc = V4L2_PIX_FMT_MJPEG,
78 .name = "YVU 4:2:0 (YV12)",
79 .guid = UVC_GUID_FORMAT_YV12,
80 .fcc = V4L2_PIX_FMT_YVU420,
83 .name = "YUV 4:2:0 (I420)",
84 .guid = UVC_GUID_FORMAT_I420,
85 .fcc = V4L2_PIX_FMT_YUV420,
88 .name = "YUV 4:2:0 (M420)",
89 .guid = UVC_GUID_FORMAT_M420,
90 .fcc = V4L2_PIX_FMT_M420,
93 .name = "YUV 4:2:2 (UYVY)",
94 .guid = UVC_GUID_FORMAT_UYVY,
95 .fcc = V4L2_PIX_FMT_UYVY,
98 .name = "Greyscale (8-bit)",
99 .guid = UVC_GUID_FORMAT_Y800,
100 .fcc = V4L2_PIX_FMT_GREY,
103 .name = "Greyscale (16-bit)",
104 .guid = UVC_GUID_FORMAT_Y16,
105 .fcc = V4L2_PIX_FMT_Y16,
109 .guid = UVC_GUID_FORMAT_BY8,
110 .fcc = V4L2_PIX_FMT_SBGGR8,
114 .guid = UVC_GUID_FORMAT_RGBP,
115 .fcc = V4L2_PIX_FMT_RGB565,
119 /* ------------------------------------------------------------------------
123 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
126 struct usb_host_endpoint *ep;
129 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
130 ep = &alts->endpoint[i];
131 if (ep->desc.bEndpointAddress == epaddr)
138 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
140 unsigned int len = ARRAY_SIZE(uvc_fmts);
143 for (i = 0; i < len; ++i) {
144 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
151 static __u32 uvc_colorspace(const __u8 primaries)
153 static const __u8 colorprimaries[] = {
155 V4L2_COLORSPACE_SRGB,
156 V4L2_COLORSPACE_470_SYSTEM_M,
157 V4L2_COLORSPACE_470_SYSTEM_BG,
158 V4L2_COLORSPACE_SMPTE170M,
159 V4L2_COLORSPACE_SMPTE240M,
162 if (primaries < ARRAY_SIZE(colorprimaries))
163 return colorprimaries[primaries];
168 /* Simplify a fraction using a simple continued fraction decomposition. The
169 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
170 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
171 * arbitrary parameters to remove non-significative terms from the simple
172 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
173 * respectively seems to give nice results.
175 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
176 unsigned int n_terms, unsigned int threshold)
182 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
186 /* Convert the fraction to a simple continued fraction. See
187 * http://mathforum.org/dr.math/faq/faq.fractions.html
188 * Stop if the current term is bigger than or equal to the given
194 for (n = 0; n < n_terms && y != 0; ++n) {
196 if (an[n] >= threshold) {
207 /* Expand the simple continued fraction back to an integer fraction. */
211 for (i = n; i > 0; --i) {
222 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
223 * to compute numerator / denominator * 10000000 using 32 bit fixed point
226 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
230 /* Saturate the result if the operation would overflow. */
231 if (denominator == 0 ||
232 numerator/denominator >= ((uint32_t)-1)/10000000)
235 /* Divide both the denominator and the multiplier by two until
236 * numerator * multiplier doesn't overflow. If anyone knows a better
237 * algorithm please let me know.
239 multiplier = 10000000;
240 while (numerator > ((uint32_t)-1)/multiplier) {
245 return denominator ? numerator * multiplier / denominator : 0;
248 /* ------------------------------------------------------------------------
249 * Terminal and unit management
252 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
254 struct uvc_entity *entity;
256 list_for_each_entry(entity, &dev->entities, list) {
257 if (entity->id == id)
264 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
265 int id, struct uvc_entity *entity)
270 entity = list_entry(&dev->entities, struct uvc_entity, list);
272 list_for_each_entry_continue(entity, &dev->entities, list) {
273 for (i = 0; i < entity->bNrInPins; ++i)
274 if (entity->baSourceID[i] == id)
281 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
283 struct uvc_streaming *stream;
285 list_for_each_entry(stream, &dev->streams, list) {
286 if (stream->header.bTerminalLink == id)
293 /* ------------------------------------------------------------------------
294 * Descriptors parsing
297 static int uvc_parse_format(struct uvc_device *dev,
298 struct uvc_streaming *streaming, struct uvc_format *format,
299 __u32 **intervals, unsigned char *buffer, int buflen)
301 struct usb_interface *intf = streaming->intf;
302 struct usb_host_interface *alts = intf->cur_altsetting;
303 struct uvc_format_desc *fmtdesc;
304 struct uvc_frame *frame;
305 const unsigned char *start = buffer;
306 unsigned int interval;
310 format->type = buffer[2];
311 format->index = buffer[3];
314 case UVC_VS_FORMAT_UNCOMPRESSED:
315 case UVC_VS_FORMAT_FRAME_BASED:
316 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
318 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
319 "interface %d FORMAT error\n",
321 alts->desc.bInterfaceNumber);
325 /* Find the format descriptor from its GUID. */
326 fmtdesc = uvc_format_by_guid(&buffer[5]);
328 if (fmtdesc != NULL) {
329 strlcpy(format->name, fmtdesc->name,
330 sizeof format->name);
331 format->fcc = fmtdesc->fcc;
333 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
335 snprintf(format->name, sizeof(format->name), "%pUl\n",
340 format->bpp = buffer[21];
341 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
342 ftype = UVC_VS_FRAME_UNCOMPRESSED;
344 ftype = UVC_VS_FRAME_FRAME_BASED;
346 format->flags = UVC_FMT_FLAG_COMPRESSED;
350 case UVC_VS_FORMAT_MJPEG:
352 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
353 "interface %d FORMAT error\n",
355 alts->desc.bInterfaceNumber);
359 strlcpy(format->name, "MJPEG", sizeof format->name);
360 format->fcc = V4L2_PIX_FMT_MJPEG;
361 format->flags = UVC_FMT_FLAG_COMPRESSED;
363 ftype = UVC_VS_FRAME_MJPEG;
366 case UVC_VS_FORMAT_DV:
368 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
369 "interface %d FORMAT error\n",
371 alts->desc.bInterfaceNumber);
375 switch (buffer[8] & 0x7f) {
377 strlcpy(format->name, "SD-DV", sizeof format->name);
380 strlcpy(format->name, "SDL-DV", sizeof format->name);
383 strlcpy(format->name, "HD-DV", sizeof format->name);
386 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
387 "interface %d: unknown DV format %u\n",
389 alts->desc.bInterfaceNumber, buffer[8]);
393 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
394 sizeof format->name);
396 format->fcc = V4L2_PIX_FMT_DV;
397 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
401 /* Create a dummy frame descriptor. */
402 frame = &format->frame[0];
403 memset(&format->frame[0], 0, sizeof format->frame[0]);
404 frame->bFrameIntervalType = 1;
405 frame->dwDefaultFrameInterval = 1;
406 frame->dwFrameInterval = *intervals;
411 case UVC_VS_FORMAT_MPEG2TS:
412 case UVC_VS_FORMAT_STREAM_BASED:
413 /* Not supported yet. */
415 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
416 "interface %d unsupported format %u\n",
417 dev->udev->devnum, alts->desc.bInterfaceNumber,
422 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
427 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
428 * based formats have frame descriptors.
430 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
431 buffer[2] == ftype) {
432 frame = &format->frame[format->nframes];
433 if (ftype != UVC_VS_FRAME_FRAME_BASED)
434 n = buflen > 25 ? buffer[25] : 0;
436 n = buflen > 21 ? buffer[21] : 0;
440 if (buflen < 26 + 4*n) {
441 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
442 "interface %d FRAME error\n", dev->udev->devnum,
443 alts->desc.bInterfaceNumber);
447 frame->bFrameIndex = buffer[3];
448 frame->bmCapabilities = buffer[4];
449 frame->wWidth = get_unaligned_le16(&buffer[5]);
450 frame->wHeight = get_unaligned_le16(&buffer[7]);
451 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
452 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
453 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
454 frame->dwMaxVideoFrameBufferSize =
455 get_unaligned_le32(&buffer[17]);
456 frame->dwDefaultFrameInterval =
457 get_unaligned_le32(&buffer[21]);
458 frame->bFrameIntervalType = buffer[25];
460 frame->dwMaxVideoFrameBufferSize = 0;
461 frame->dwDefaultFrameInterval =
462 get_unaligned_le32(&buffer[17]);
463 frame->bFrameIntervalType = buffer[21];
465 frame->dwFrameInterval = *intervals;
467 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
468 * completely. Observed behaviours range from setting the
469 * value to 1.1x the actual frame size to hardwiring the
470 * 16 low bits to 0. This results in a higher than necessary
471 * memory usage as well as a wrong image size information. For
472 * uncompressed formats this can be fixed by computing the
473 * value from the frame size.
475 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
476 frame->dwMaxVideoFrameBufferSize = format->bpp
477 * frame->wWidth * frame->wHeight / 8;
479 /* Some bogus devices report dwMinFrameInterval equal to
480 * dwMaxFrameInterval and have dwFrameIntervalStep set to
481 * zero. Setting all null intervals to 1 fixes the problem and
482 * some other divisions by zero that could happen.
484 for (i = 0; i < n; ++i) {
485 interval = get_unaligned_le32(&buffer[26+4*i]);
486 *(*intervals)++ = interval ? interval : 1;
489 /* Make sure that the default frame interval stays between
492 n -= frame->bFrameIntervalType ? 1 : 2;
493 frame->dwDefaultFrameInterval =
494 min(frame->dwFrameInterval[n],
495 max(frame->dwFrameInterval[0],
496 frame->dwDefaultFrameInterval));
498 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
499 frame->bFrameIntervalType = 1;
500 frame->dwFrameInterval[0] =
501 frame->dwDefaultFrameInterval;
504 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
505 frame->wWidth, frame->wHeight,
506 10000000/frame->dwDefaultFrameInterval,
507 (100000000/frame->dwDefaultFrameInterval)%10);
514 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
515 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
520 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
521 buffer[2] == UVC_VS_COLORFORMAT) {
523 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
524 "interface %d COLORFORMAT error\n",
526 alts->desc.bInterfaceNumber);
530 format->colorspace = uvc_colorspace(buffer[3]);
536 return buffer - start;
539 static int uvc_parse_streaming(struct uvc_device *dev,
540 struct usb_interface *intf)
542 struct uvc_streaming *streaming = NULL;
543 struct uvc_format *format;
544 struct uvc_frame *frame;
545 struct usb_host_interface *alts = &intf->altsetting[0];
546 unsigned char *_buffer, *buffer = alts->extra;
547 int _buflen, buflen = alts->extralen;
548 unsigned int nformats = 0, nframes = 0, nintervals = 0;
549 unsigned int size, i, n, p;
554 if (intf->cur_altsetting->desc.bInterfaceSubClass
555 != UVC_SC_VIDEOSTREAMING) {
556 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
557 "video streaming interface\n", dev->udev->devnum,
558 intf->altsetting[0].desc.bInterfaceNumber);
562 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
563 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
564 "claimed\n", dev->udev->devnum,
565 intf->altsetting[0].desc.bInterfaceNumber);
569 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
570 if (streaming == NULL) {
571 usb_driver_release_interface(&uvc_driver.driver, intf);
575 mutex_init(&streaming->mutex);
576 streaming->dev = dev;
577 streaming->intf = usb_get_intf(intf);
578 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
580 /* The Pico iMage webcam has its class-specific interface descriptors
581 * after the endpoint descriptors.
584 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
585 struct usb_host_endpoint *ep = &alts->endpoint[i];
587 if (ep->extralen == 0)
590 if (ep->extralen > 2 &&
591 ep->extra[1] == USB_DT_CS_INTERFACE) {
592 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
593 "from endpoint %u.\n", i);
594 buffer = alts->endpoint[i].extra;
595 buflen = alts->endpoint[i].extralen;
601 /* Skip the standard interface descriptors. */
602 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
608 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
609 "interface descriptors found.\n");
613 /* Parse the header descriptor. */
615 case UVC_VS_OUTPUT_HEADER:
616 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
620 case UVC_VS_INPUT_HEADER:
621 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
626 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
627 "%d HEADER descriptor not found.\n", dev->udev->devnum,
628 alts->desc.bInterfaceNumber);
632 p = buflen >= 4 ? buffer[3] : 0;
633 n = buflen >= size ? buffer[size-1] : 0;
635 if (buflen < size + p*n) {
636 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
637 "interface %d HEADER descriptor is invalid.\n",
638 dev->udev->devnum, alts->desc.bInterfaceNumber);
642 streaming->header.bNumFormats = p;
643 streaming->header.bEndpointAddress = buffer[6];
644 if (buffer[2] == UVC_VS_INPUT_HEADER) {
645 streaming->header.bmInfo = buffer[7];
646 streaming->header.bTerminalLink = buffer[8];
647 streaming->header.bStillCaptureMethod = buffer[9];
648 streaming->header.bTriggerSupport = buffer[10];
649 streaming->header.bTriggerUsage = buffer[11];
651 streaming->header.bTerminalLink = buffer[7];
653 streaming->header.bControlSize = n;
655 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
657 if (streaming->header.bmaControls == NULL) {
668 /* Count the format and frame descriptors. */
669 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
670 switch (_buffer[2]) {
671 case UVC_VS_FORMAT_UNCOMPRESSED:
672 case UVC_VS_FORMAT_MJPEG:
673 case UVC_VS_FORMAT_FRAME_BASED:
677 case UVC_VS_FORMAT_DV:
678 /* DV format has no frame descriptor. We will create a
679 * dummy frame descriptor with a dummy frame interval.
686 case UVC_VS_FORMAT_MPEG2TS:
687 case UVC_VS_FORMAT_STREAM_BASED:
688 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
689 "interface %d FORMAT %u is not supported.\n",
691 alts->desc.bInterfaceNumber, _buffer[2]);
694 case UVC_VS_FRAME_UNCOMPRESSED:
695 case UVC_VS_FRAME_MJPEG:
698 nintervals += _buffer[25] ? _buffer[25] : 3;
701 case UVC_VS_FRAME_FRAME_BASED:
704 nintervals += _buffer[21] ? _buffer[21] : 3;
708 _buflen -= _buffer[0];
709 _buffer += _buffer[0];
713 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
714 "%d has no supported formats defined.\n",
715 dev->udev->devnum, alts->desc.bInterfaceNumber);
719 size = nformats * sizeof *format + nframes * sizeof *frame
720 + nintervals * sizeof *interval;
721 format = kzalloc(size, GFP_KERNEL);
722 if (format == NULL) {
727 frame = (struct uvc_frame *)&format[nformats];
728 interval = (__u32 *)&frame[nframes];
730 streaming->format = format;
731 streaming->nformats = nformats;
733 /* Parse the format descriptors. */
734 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
736 case UVC_VS_FORMAT_UNCOMPRESSED:
737 case UVC_VS_FORMAT_MJPEG:
738 case UVC_VS_FORMAT_DV:
739 case UVC_VS_FORMAT_FRAME_BASED:
740 format->frame = frame;
741 ret = uvc_parse_format(dev, streaming, format,
742 &interval, buffer, buflen);
746 frame += format->nframes;
762 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
763 "%d has %u bytes of trailing descriptor garbage.\n",
764 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
766 /* Parse the alternate settings to find the maximum bandwidth. */
767 for (i = 0; i < intf->num_altsetting; ++i) {
768 struct usb_host_endpoint *ep;
769 alts = &intf->altsetting[i];
770 ep = uvc_find_endpoint(alts,
771 streaming->header.bEndpointAddress);
775 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
776 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
777 if (psize > streaming->maxpsize)
778 streaming->maxpsize = psize;
781 list_add_tail(&streaming->list, &dev->streams);
785 usb_driver_release_interface(&uvc_driver.driver, intf);
787 kfree(streaming->format);
788 kfree(streaming->header.bmaControls);
793 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
794 unsigned int num_pads, unsigned int extra_size)
796 struct uvc_entity *entity;
797 unsigned int num_inputs;
801 extra_size = ALIGN(extra_size, sizeof(*entity->pads));
802 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
803 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
805 entity = kzalloc(size, GFP_KERNEL);
812 entity->num_links = 0;
813 entity->num_pads = num_pads;
814 entity->pads = ((void *)(entity + 1)) + extra_size;
816 for (i = 0; i < num_inputs; ++i)
817 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
818 if (!UVC_ENTITY_IS_OTERM(entity))
819 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
821 entity->bNrInPins = num_inputs;
822 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
827 /* Parse vendor-specific extensions. */
828 static int uvc_parse_vendor_control(struct uvc_device *dev,
829 const unsigned char *buffer, int buflen)
831 struct usb_device *udev = dev->udev;
832 struct usb_host_interface *alts = dev->intf->cur_altsetting;
833 struct uvc_entity *unit;
837 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
838 case 0x046d: /* Logitech */
839 if (buffer[1] != 0x41 || buffer[2] != 0x01)
842 /* Logitech implements several vendor specific functions
843 * through vendor specific extension units (LXU).
845 * The LXU descriptors are similar to XU descriptors
846 * (see "USB Device Video Class for Video Devices", section
847 * 3.7.2.6 "Extension Unit Descriptor") with the following
850 * ----------------------------------------------------------
852 * Size of this descriptor, in bytes: 24+p+n*2
853 * ----------------------------------------------------------
854 * 23+p+n bmControlsType N Bitmap
855 * Individual bits in the set are defined:
859 * This bitset is mapped exactly the same as bmControls.
860 * ----------------------------------------------------------
861 * 23+p+n*2 bReserved 1 Boolean
862 * ----------------------------------------------------------
863 * 24+p+n*2 iExtension 1 Index
864 * Index of a string descriptor that describes this
866 * ----------------------------------------------------------
868 p = buflen >= 22 ? buffer[21] : 0;
869 n = buflen >= 25 + p ? buffer[22+p] : 0;
871 if (buflen < 25 + p + 2*n) {
872 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
873 "interface %d EXTENSION_UNIT error\n",
874 udev->devnum, alts->desc.bInterfaceNumber);
878 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
883 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
884 unit->extension.bNumControls = buffer[20];
885 memcpy(unit->baSourceID, &buffer[22], p);
886 unit->extension.bControlSize = buffer[22+p];
887 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
888 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
890 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
892 if (buffer[24+p+2*n] != 0)
893 usb_string(udev, buffer[24+p+2*n], unit->name,
896 sprintf(unit->name, "Extension %u", buffer[3]);
898 list_add_tail(&unit->list, &dev->entities);
906 static int uvc_parse_standard_control(struct uvc_device *dev,
907 const unsigned char *buffer, int buflen)
909 struct usb_device *udev = dev->udev;
910 struct uvc_entity *unit, *term;
911 struct usb_interface *intf;
912 struct usb_host_interface *alts = dev->intf->cur_altsetting;
913 unsigned int i, n, p, len;
918 n = buflen >= 12 ? buffer[11] : 0;
920 if (buflen < 12 || buflen < 12 + n) {
921 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
922 "interface %d HEADER error\n", udev->devnum,
923 alts->desc.bInterfaceNumber);
927 dev->uvc_version = get_unaligned_le16(&buffer[3]);
928 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
930 /* Parse all USB Video Streaming interfaces. */
931 for (i = 0; i < n; ++i) {
932 intf = usb_ifnum_to_if(udev, buffer[12+i]);
934 uvc_trace(UVC_TRACE_DESCR, "device %d "
935 "interface %d doesn't exists\n",
940 uvc_parse_streaming(dev, intf);
944 case UVC_VC_INPUT_TERMINAL:
946 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
947 "interface %d INPUT_TERMINAL error\n",
948 udev->devnum, alts->desc.bInterfaceNumber);
952 /* Make sure the terminal type MSB is not null, otherwise it
953 * could be confused with a unit.
955 type = get_unaligned_le16(&buffer[4]);
956 if ((type & 0xff00) == 0) {
957 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
958 "interface %d INPUT_TERMINAL %d has invalid "
959 "type 0x%04x, skipping\n", udev->devnum,
960 alts->desc.bInterfaceNumber,
969 if (type == UVC_ITT_CAMERA) {
970 n = buflen >= 15 ? buffer[14] : 0;
973 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
974 n = buflen >= 9 ? buffer[8] : 0;
975 p = buflen >= 10 + n ? buffer[9+n] : 0;
979 if (buflen < len + n + p) {
980 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
981 "interface %d INPUT_TERMINAL error\n",
982 udev->devnum, alts->desc.bInterfaceNumber);
986 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
991 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
992 term->camera.bControlSize = n;
993 term->camera.bmControls = (__u8 *)term + sizeof *term;
994 term->camera.wObjectiveFocalLengthMin =
995 get_unaligned_le16(&buffer[8]);
996 term->camera.wObjectiveFocalLengthMax =
997 get_unaligned_le16(&buffer[10]);
998 term->camera.wOcularFocalLength =
999 get_unaligned_le16(&buffer[12]);
1000 memcpy(term->camera.bmControls, &buffer[15], n);
1001 } else if (UVC_ENTITY_TYPE(term) ==
1002 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1003 term->media.bControlSize = n;
1004 term->media.bmControls = (__u8 *)term + sizeof *term;
1005 term->media.bTransportModeSize = p;
1006 term->media.bmTransportModes = (__u8 *)term
1008 memcpy(term->media.bmControls, &buffer[9], n);
1009 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1013 usb_string(udev, buffer[7], term->name,
1015 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1016 sprintf(term->name, "Camera %u", buffer[3]);
1017 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1018 sprintf(term->name, "Media %u", buffer[3]);
1020 sprintf(term->name, "Input %u", buffer[3]);
1022 list_add_tail(&term->list, &dev->entities);
1025 case UVC_VC_OUTPUT_TERMINAL:
1027 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1028 "interface %d OUTPUT_TERMINAL error\n",
1029 udev->devnum, alts->desc.bInterfaceNumber);
1033 /* Make sure the terminal type MSB is not null, otherwise it
1034 * could be confused with a unit.
1036 type = get_unaligned_le16(&buffer[4]);
1037 if ((type & 0xff00) == 0) {
1038 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1039 "interface %d OUTPUT_TERMINAL %d has invalid "
1040 "type 0x%04x, skipping\n", udev->devnum,
1041 alts->desc.bInterfaceNumber, buffer[3], type);
1045 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1050 memcpy(term->baSourceID, &buffer[7], 1);
1053 usb_string(udev, buffer[8], term->name,
1056 sprintf(term->name, "Output %u", buffer[3]);
1058 list_add_tail(&term->list, &dev->entities);
1061 case UVC_VC_SELECTOR_UNIT:
1062 p = buflen >= 5 ? buffer[4] : 0;
1064 if (buflen < 5 || buflen < 6 + p) {
1065 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1066 "interface %d SELECTOR_UNIT error\n",
1067 udev->devnum, alts->desc.bInterfaceNumber);
1071 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1075 memcpy(unit->baSourceID, &buffer[5], p);
1077 if (buffer[5+p] != 0)
1078 usb_string(udev, buffer[5+p], unit->name,
1081 sprintf(unit->name, "Selector %u", buffer[3]);
1083 list_add_tail(&unit->list, &dev->entities);
1086 case UVC_VC_PROCESSING_UNIT:
1087 n = buflen >= 8 ? buffer[7] : 0;
1088 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1090 if (buflen < p + n) {
1091 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1092 "interface %d PROCESSING_UNIT error\n",
1093 udev->devnum, alts->desc.bInterfaceNumber);
1097 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1101 memcpy(unit->baSourceID, &buffer[4], 1);
1102 unit->processing.wMaxMultiplier =
1103 get_unaligned_le16(&buffer[5]);
1104 unit->processing.bControlSize = buffer[7];
1105 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1106 memcpy(unit->processing.bmControls, &buffer[8], n);
1107 if (dev->uvc_version >= 0x0110)
1108 unit->processing.bmVideoStandards = buffer[9+n];
1110 if (buffer[8+n] != 0)
1111 usb_string(udev, buffer[8+n], unit->name,
1114 sprintf(unit->name, "Processing %u", buffer[3]);
1116 list_add_tail(&unit->list, &dev->entities);
1119 case UVC_VC_EXTENSION_UNIT:
1120 p = buflen >= 22 ? buffer[21] : 0;
1121 n = buflen >= 24 + p ? buffer[22+p] : 0;
1123 if (buflen < 24 + p + n) {
1124 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1125 "interface %d EXTENSION_UNIT error\n",
1126 udev->devnum, alts->desc.bInterfaceNumber);
1130 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1134 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1135 unit->extension.bNumControls = buffer[20];
1136 memcpy(unit->baSourceID, &buffer[22], p);
1137 unit->extension.bControlSize = buffer[22+p];
1138 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1139 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1141 if (buffer[23+p+n] != 0)
1142 usb_string(udev, buffer[23+p+n], unit->name,
1145 sprintf(unit->name, "Extension %u", buffer[3]);
1147 list_add_tail(&unit->list, &dev->entities);
1151 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1152 "descriptor (%u)\n", buffer[2]);
1159 static int uvc_parse_control(struct uvc_device *dev)
1161 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1162 unsigned char *buffer = alts->extra;
1163 int buflen = alts->extralen;
1166 /* Parse the default alternate setting only, as the UVC specification
1167 * defines a single alternate setting, the default alternate setting
1171 while (buflen > 2) {
1172 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1173 buffer[1] != USB_DT_CS_INTERFACE)
1174 goto next_descriptor;
1176 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1180 buflen -= buffer[0];
1181 buffer += buffer[0];
1184 /* Check if the optional status endpoint is present. Built-in iSight
1185 * webcams have an interrupt endpoint but spit proprietary data that
1186 * don't conform to the UVC status endpoint messages. Don't try to
1187 * handle the interrupt endpoint for those cameras.
1189 if (alts->desc.bNumEndpoints == 1 &&
1190 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1191 struct usb_host_endpoint *ep = &alts->endpoint[0];
1192 struct usb_endpoint_descriptor *desc = &ep->desc;
1194 if (usb_endpoint_is_int_in(desc) &&
1195 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1196 desc->bInterval != 0) {
1197 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1198 "(addr %02x).\n", desc->bEndpointAddress);
1206 /* ------------------------------------------------------------------------
1211 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1212 * and containing the following units:
1214 * - one or more Output Terminals (USB Streaming or Display)
1215 * - zero or one Processing Unit
1216 * - zero, one or more single-input Selector Units
1217 * - zero or one multiple-input Selector Units, provided all inputs are
1218 * connected to input terminals
1219 * - zero, one or mode single-input Extension Units
1220 * - one or more Input Terminals (Camera, External or USB Streaming)
1222 * The terminal and units must match on of the following structures:
1224 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1225 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1226 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1228 * +---------+ +---------+ -> OTT_*(0)
1229 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1230 * +---------+ +---------+ -> OTT_*(n)
1232 * The Processing Unit and Extension Units can be in any order. Additional
1233 * Extension Units connected to the main chain as single-unit branches are
1234 * also supported. Single-input Selector Units are ignored.
1236 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1237 struct uvc_entity *entity)
1239 switch (UVC_ENTITY_TYPE(entity)) {
1240 case UVC_VC_EXTENSION_UNIT:
1241 if (uvc_trace_param & UVC_TRACE_PROBE)
1242 printk(" <- XU %d", entity->id);
1244 if (entity->bNrInPins != 1) {
1245 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1246 "than 1 input pin.\n", entity->id);
1252 case UVC_VC_PROCESSING_UNIT:
1253 if (uvc_trace_param & UVC_TRACE_PROBE)
1254 printk(" <- PU %d", entity->id);
1256 if (chain->processing != NULL) {
1257 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1258 "Processing Units in chain.\n");
1262 chain->processing = entity;
1265 case UVC_VC_SELECTOR_UNIT:
1266 if (uvc_trace_param & UVC_TRACE_PROBE)
1267 printk(" <- SU %d", entity->id);
1269 /* Single-input selector units are ignored. */
1270 if (entity->bNrInPins == 1)
1273 if (chain->selector != NULL) {
1274 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1275 "Units in chain.\n");
1279 chain->selector = entity;
1282 case UVC_ITT_VENDOR_SPECIFIC:
1283 case UVC_ITT_CAMERA:
1284 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1285 if (uvc_trace_param & UVC_TRACE_PROBE)
1286 printk(" <- IT %d\n", entity->id);
1290 case UVC_OTT_VENDOR_SPECIFIC:
1291 case UVC_OTT_DISPLAY:
1292 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1293 if (uvc_trace_param & UVC_TRACE_PROBE)
1294 printk(" OT %d", entity->id);
1298 case UVC_TT_STREAMING:
1299 if (UVC_ENTITY_IS_ITERM(entity)) {
1300 if (uvc_trace_param & UVC_TRACE_PROBE)
1301 printk(" <- IT %d\n", entity->id);
1303 if (uvc_trace_param & UVC_TRACE_PROBE)
1304 printk(" OT %d", entity->id);
1310 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1311 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1315 list_add_tail(&entity->chain, &chain->entities);
1319 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1320 struct uvc_entity *entity, struct uvc_entity *prev)
1322 struct uvc_entity *forward;
1330 forward = uvc_entity_by_reference(chain->dev, entity->id,
1332 if (forward == NULL)
1334 if (forward == prev)
1337 switch (UVC_ENTITY_TYPE(forward)) {
1338 case UVC_VC_EXTENSION_UNIT:
1339 if (forward->bNrInPins != 1) {
1340 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1341 "has more than 1 input pin.\n",
1346 list_add_tail(&forward->chain, &chain->entities);
1347 if (uvc_trace_param & UVC_TRACE_PROBE) {
1351 printk(" XU %d", forward->id);
1356 case UVC_OTT_VENDOR_SPECIFIC:
1357 case UVC_OTT_DISPLAY:
1358 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1359 case UVC_TT_STREAMING:
1360 if (UVC_ENTITY_IS_ITERM(forward)) {
1361 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1362 "terminal %u.\n", forward->id);
1366 list_add_tail(&forward->chain, &chain->entities);
1367 if (uvc_trace_param & UVC_TRACE_PROBE) {
1371 printk(" OT %d", forward->id);
1383 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1384 struct uvc_entity **_entity)
1386 struct uvc_entity *entity = *_entity;
1387 struct uvc_entity *term;
1388 int id = -EINVAL, i;
1390 switch (UVC_ENTITY_TYPE(entity)) {
1391 case UVC_VC_EXTENSION_UNIT:
1392 case UVC_VC_PROCESSING_UNIT:
1393 id = entity->baSourceID[0];
1396 case UVC_VC_SELECTOR_UNIT:
1397 /* Single-input selector units are ignored. */
1398 if (entity->bNrInPins == 1) {
1399 id = entity->baSourceID[0];
1403 if (uvc_trace_param & UVC_TRACE_PROBE)
1406 chain->selector = entity;
1407 for (i = 0; i < entity->bNrInPins; ++i) {
1408 id = entity->baSourceID[i];
1409 term = uvc_entity_by_id(chain->dev, id);
1410 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1411 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1412 "input %d isn't connected to an "
1413 "input terminal\n", entity->id, i);
1417 if (uvc_trace_param & UVC_TRACE_PROBE)
1418 printk(" %d", term->id);
1420 list_add_tail(&term->chain, &chain->entities);
1421 uvc_scan_chain_forward(chain, term, entity);
1424 if (uvc_trace_param & UVC_TRACE_PROBE)
1430 case UVC_ITT_VENDOR_SPECIFIC:
1431 case UVC_ITT_CAMERA:
1432 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1433 case UVC_OTT_VENDOR_SPECIFIC:
1434 case UVC_OTT_DISPLAY:
1435 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1436 case UVC_TT_STREAMING:
1437 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1446 entity = uvc_entity_by_id(chain->dev, id);
1447 if (entity == NULL) {
1448 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1449 "unknown entity %d.\n", id);
1457 static int uvc_scan_chain(struct uvc_video_chain *chain,
1458 struct uvc_entity *term)
1460 struct uvc_entity *entity, *prev;
1462 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1467 while (entity != NULL) {
1468 /* Entity must not be part of an existing chain */
1469 if (entity->chain.next || entity->chain.prev) {
1470 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1471 "entity %d already in chain.\n", entity->id);
1475 /* Process entity */
1476 if (uvc_scan_chain_entity(chain, entity) < 0)
1480 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1485 if (uvc_scan_chain_backward(chain, &entity) < 0)
1492 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1495 struct uvc_entity *term;
1496 unsigned int nterms = 0;
1499 list_for_each_entry(term, terms, chain) {
1500 if (!UVC_ENTITY_IS_TERM(term) ||
1501 UVC_TERM_DIRECTION(term) != dir)
1505 p += sprintf(p, ",");
1506 if (++nterms >= 4) {
1507 p += sprintf(p, "...");
1510 p += sprintf(p, "%u", term->id);
1516 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1518 static char buffer[43];
1521 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1522 p += sprintf(p, " -> ");
1523 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1529 * Scan the device for video chains and register video devices.
1531 * Chains are scanned starting at their output terminals and walked backwards.
1533 static int uvc_scan_device(struct uvc_device *dev)
1535 struct uvc_video_chain *chain;
1536 struct uvc_entity *term;
1538 list_for_each_entry(term, &dev->entities, list) {
1539 if (!UVC_ENTITY_IS_OTERM(term))
1542 /* If the terminal is already included in a chain, skip it.
1543 * This can happen for chains that have multiple output
1544 * terminals, where all output terminals beside the first one
1545 * will be inserted in the chain in forward scans.
1547 if (term->chain.next || term->chain.prev)
1550 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1554 INIT_LIST_HEAD(&chain->entities);
1555 mutex_init(&chain->ctrl_mutex);
1558 if (uvc_scan_chain(chain, term) < 0) {
1563 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1564 uvc_print_chain(chain));
1566 list_add_tail(&chain->list, &dev->chains);
1569 if (list_empty(&dev->chains)) {
1570 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1577 /* ------------------------------------------------------------------------
1578 * Video device registration and unregistration
1582 * Delete the UVC device.
1584 * Called by the kernel when the last reference to the uvc_device structure
1587 * As this function is called after or during disconnect(), all URBs have
1588 * already been canceled by the USB core. There is no need to kill the
1589 * interrupt URB manually.
1591 static void uvc_delete(struct uvc_device *dev)
1593 struct list_head *p, *n;
1595 usb_put_intf(dev->intf);
1596 usb_put_dev(dev->udev);
1598 uvc_status_cleanup(dev);
1599 uvc_ctrl_cleanup_device(dev);
1602 v4l2_device_unregister(&dev->vdev);
1603 #ifdef CONFIG_MEDIA_CONTROLLER
1604 if (media_devnode_is_registered(&dev->mdev.devnode))
1605 media_device_unregister(&dev->mdev);
1608 list_for_each_safe(p, n, &dev->chains) {
1609 struct uvc_video_chain *chain;
1610 chain = list_entry(p, struct uvc_video_chain, list);
1614 list_for_each_safe(p, n, &dev->entities) {
1615 struct uvc_entity *entity;
1616 entity = list_entry(p, struct uvc_entity, list);
1617 #ifdef CONFIG_MEDIA_CONTROLLER
1618 uvc_mc_cleanup_entity(entity);
1621 video_device_release(entity->vdev);
1622 entity->vdev = NULL;
1627 list_for_each_safe(p, n, &dev->streams) {
1628 struct uvc_streaming *streaming;
1629 streaming = list_entry(p, struct uvc_streaming, list);
1630 usb_driver_release_interface(&uvc_driver.driver,
1632 usb_put_intf(streaming->intf);
1633 kfree(streaming->format);
1634 kfree(streaming->header.bmaControls);
1641 static void uvc_release(struct video_device *vdev)
1643 struct uvc_streaming *stream = video_get_drvdata(vdev);
1644 struct uvc_device *dev = stream->dev;
1646 /* Decrement the registered streams count and delete the device when it
1649 if (atomic_dec_and_test(&dev->nstreams))
1654 * Unregister the video devices.
1656 static void uvc_unregister_video(struct uvc_device *dev)
1658 struct uvc_streaming *stream;
1660 /* Unregistering all video devices might result in uvc_delete() being
1661 * called from inside the loop if there's no open file handle. To avoid
1662 * that, increment the stream count before iterating over the streams
1663 * and decrement it when done.
1665 atomic_inc(&dev->nstreams);
1667 list_for_each_entry(stream, &dev->streams, list) {
1668 if (stream->vdev == NULL)
1671 video_unregister_device(stream->vdev);
1672 stream->vdev = NULL;
1675 /* Decrement the stream count and call uvc_delete explicitly if there
1676 * are no stream left.
1678 if (atomic_dec_and_test(&dev->nstreams))
1682 static int uvc_register_video(struct uvc_device *dev,
1683 struct uvc_streaming *stream)
1685 struct video_device *vdev;
1688 /* Initialize the streaming interface with default streaming
1691 ret = uvc_video_init(stream);
1693 uvc_printk(KERN_ERR, "Failed to initialize the device "
1698 /* Register the device with V4L. */
1699 vdev = video_device_alloc();
1701 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1706 /* We already hold a reference to dev->udev. The video device will be
1707 * unregistered before the reference is released, so we don't need to
1710 vdev->v4l2_dev = &dev->vdev;
1711 vdev->fops = &uvc_fops;
1712 vdev->release = uvc_release;
1713 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1715 /* Set the driver data before calling video_register_device, otherwise
1716 * uvc_v4l2_open might race us.
1718 stream->vdev = vdev;
1719 video_set_drvdata(vdev, stream);
1721 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1723 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1725 stream->vdev = NULL;
1726 video_device_release(vdev);
1730 atomic_inc(&dev->nstreams);
1735 * Register all video devices in all chains.
1737 static int uvc_register_terms(struct uvc_device *dev,
1738 struct uvc_video_chain *chain)
1740 struct uvc_streaming *stream;
1741 struct uvc_entity *term;
1744 list_for_each_entry(term, &chain->entities, chain) {
1745 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1748 stream = uvc_stream_by_id(dev, term->id);
1749 if (stream == NULL) {
1750 uvc_printk(KERN_INFO, "No streaming interface found "
1751 "for terminal %u.", term->id);
1755 stream->chain = chain;
1756 ret = uvc_register_video(dev, stream);
1760 term->vdev = stream->vdev;
1766 static int uvc_register_chains(struct uvc_device *dev)
1768 struct uvc_video_chain *chain;
1771 list_for_each_entry(chain, &dev->chains, list) {
1772 ret = uvc_register_terms(dev, chain);
1776 #ifdef CONFIG_MEDIA_CONTROLLER
1777 ret = uvc_mc_register_entities(chain);
1779 uvc_printk(KERN_INFO, "Failed to register entites "
1788 /* ------------------------------------------------------------------------
1789 * USB probe, disconnect, suspend and resume
1792 static int uvc_probe(struct usb_interface *intf,
1793 const struct usb_device_id *id)
1795 struct usb_device *udev = interface_to_usbdev(intf);
1796 struct uvc_device *dev;
1799 if (id->idVendor && id->idProduct)
1800 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1801 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1804 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1807 /* Allocate memory for the device and initialize it. */
1808 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1811 INIT_LIST_HEAD(&dev->entities);
1812 INIT_LIST_HEAD(&dev->chains);
1813 INIT_LIST_HEAD(&dev->streams);
1814 atomic_set(&dev->nstreams, 0);
1815 atomic_set(&dev->users, 0);
1816 atomic_set(&dev->nmappings, 0);
1818 dev->udev = usb_get_dev(udev);
1819 dev->intf = usb_get_intf(intf);
1820 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1821 dev->quirks = (uvc_quirks_param == -1)
1822 ? id->driver_info : uvc_quirks_param;
1824 if (udev->product != NULL)
1825 strlcpy(dev->name, udev->product, sizeof dev->name);
1827 snprintf(dev->name, sizeof dev->name,
1828 "UVC Camera (%04x:%04x)",
1829 le16_to_cpu(udev->descriptor.idVendor),
1830 le16_to_cpu(udev->descriptor.idProduct));
1832 /* Parse the Video Class control descriptor. */
1833 if (uvc_parse_control(dev) < 0) {
1834 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1839 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1840 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1841 udev->product ? udev->product : "<unnamed>",
1842 le16_to_cpu(udev->descriptor.idVendor),
1843 le16_to_cpu(udev->descriptor.idProduct));
1845 if (dev->quirks != id->driver_info) {
1846 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1847 "parameter for testing purpose.\n", dev->quirks);
1848 uvc_printk(KERN_INFO, "Please report required quirks to the "
1849 "linux-uvc-devel mailing list.\n");
1852 /* Register the media and V4L2 devices. */
1853 #ifdef CONFIG_MEDIA_CONTROLLER
1854 dev->mdev.dev = &intf->dev;
1855 strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
1857 strlcpy(dev->mdev.serial, udev->serial,
1858 sizeof(dev->mdev.serial));
1859 strcpy(dev->mdev.bus_info, udev->devpath);
1860 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
1861 dev->mdev.driver_version = LINUX_VERSION_CODE;
1862 if (media_device_register(&dev->mdev) < 0)
1865 dev->vdev.mdev = &dev->mdev;
1867 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
1870 /* Initialize controls. */
1871 if (uvc_ctrl_init_device(dev) < 0)
1874 /* Scan the device for video chains. */
1875 if (uvc_scan_device(dev) < 0)
1878 /* Register video device nodes. */
1879 if (uvc_register_chains(dev) < 0)
1882 /* Save our data pointer in the interface data. */
1883 usb_set_intfdata(intf, dev);
1885 /* Initialize the interrupt URB. */
1886 if ((ret = uvc_status_init(dev)) < 0) {
1887 uvc_printk(KERN_INFO, "Unable to initialize the status "
1888 "endpoint (%d), status interrupt will not be "
1889 "supported.\n", ret);
1892 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1893 usb_enable_autosuspend(udev);
1897 uvc_unregister_video(dev);
1901 static void uvc_disconnect(struct usb_interface *intf)
1903 struct uvc_device *dev = usb_get_intfdata(intf);
1905 /* Set the USB interface data to NULL. This can be done outside the
1906 * lock, as there's no other reader.
1908 usb_set_intfdata(intf, NULL);
1910 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1911 UVC_SC_VIDEOSTREAMING)
1914 dev->state |= UVC_DEV_DISCONNECTED;
1916 uvc_unregister_video(dev);
1919 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1921 struct uvc_device *dev = usb_get_intfdata(intf);
1922 struct uvc_streaming *stream;
1924 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1925 intf->cur_altsetting->desc.bInterfaceNumber);
1927 /* Controls are cached on the fly so they don't need to be saved. */
1928 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1929 UVC_SC_VIDEOCONTROL)
1930 return uvc_status_suspend(dev);
1932 list_for_each_entry(stream, &dev->streams, list) {
1933 if (stream->intf == intf)
1934 return uvc_video_suspend(stream);
1937 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1942 static int __uvc_resume(struct usb_interface *intf, int reset)
1944 struct uvc_device *dev = usb_get_intfdata(intf);
1945 struct uvc_streaming *stream;
1947 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
1948 intf->cur_altsetting->desc.bInterfaceNumber);
1950 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1951 UVC_SC_VIDEOCONTROL) {
1953 int ret = uvc_ctrl_resume_device(dev);
1959 return uvc_status_resume(dev);
1962 list_for_each_entry(stream, &dev->streams, list) {
1963 if (stream->intf == intf)
1964 return uvc_video_resume(stream);
1967 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
1972 static int uvc_resume(struct usb_interface *intf)
1974 return __uvc_resume(intf, 0);
1977 static int uvc_reset_resume(struct usb_interface *intf)
1979 return __uvc_resume(intf, 1);
1982 /* ------------------------------------------------------------------------
1986 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
1988 if (uvc_clock_param == CLOCK_MONOTONIC)
1989 return sprintf(buffer, "CLOCK_MONOTONIC");
1991 return sprintf(buffer, "CLOCK_REALTIME");
1994 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
1996 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
1997 val += strlen("clock_");
1999 if (strcasecmp(val, "monotonic") == 0)
2000 uvc_clock_param = CLOCK_MONOTONIC;
2001 else if (strcasecmp(val, "realtime") == 0)
2002 uvc_clock_param = CLOCK_REALTIME;
2009 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2010 &uvc_clock_param, S_IRUGO|S_IWUSR);
2011 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2012 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2013 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2014 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2015 MODULE_PARM_DESC(quirks, "Forced device quirks");
2016 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2017 MODULE_PARM_DESC(trace, "Trace level bitmask");
2018 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2019 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2021 /* ------------------------------------------------------------------------
2022 * Driver initialization and cleanup
2026 * The Logitech cameras listed below have their interface class set to
2027 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2028 * though they are compliant.
2030 static struct usb_device_id uvc_ids[] = {
2031 /* Genius eFace 2025 */
2032 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2033 | USB_DEVICE_ID_MATCH_INT_INFO,
2035 .idProduct = 0x706e,
2036 .bInterfaceClass = USB_CLASS_VIDEO,
2037 .bInterfaceSubClass = 1,
2038 .bInterfaceProtocol = 0,
2039 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2040 /* Microsoft Lifecam NX-6000 */
2041 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2042 | USB_DEVICE_ID_MATCH_INT_INFO,
2044 .idProduct = 0x00f8,
2045 .bInterfaceClass = USB_CLASS_VIDEO,
2046 .bInterfaceSubClass = 1,
2047 .bInterfaceProtocol = 0,
2048 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2049 /* Microsoft Lifecam VX-7000 */
2050 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2051 | USB_DEVICE_ID_MATCH_INT_INFO,
2053 .idProduct = 0x0723,
2054 .bInterfaceClass = USB_CLASS_VIDEO,
2055 .bInterfaceSubClass = 1,
2056 .bInterfaceProtocol = 0,
2057 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2058 /* Logitech Quickcam Fusion */
2059 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2060 | USB_DEVICE_ID_MATCH_INT_INFO,
2062 .idProduct = 0x08c1,
2063 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2064 .bInterfaceSubClass = 1,
2065 .bInterfaceProtocol = 0 },
2066 /* Logitech Quickcam Orbit MP */
2067 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2068 | USB_DEVICE_ID_MATCH_INT_INFO,
2070 .idProduct = 0x08c2,
2071 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2072 .bInterfaceSubClass = 1,
2073 .bInterfaceProtocol = 0 },
2074 /* Logitech Quickcam Pro for Notebook */
2075 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2076 | USB_DEVICE_ID_MATCH_INT_INFO,
2078 .idProduct = 0x08c3,
2079 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2080 .bInterfaceSubClass = 1,
2081 .bInterfaceProtocol = 0 },
2082 /* Logitech Quickcam Pro 5000 */
2083 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2084 | USB_DEVICE_ID_MATCH_INT_INFO,
2086 .idProduct = 0x08c5,
2087 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2088 .bInterfaceSubClass = 1,
2089 .bInterfaceProtocol = 0 },
2090 /* Logitech Quickcam OEM Dell Notebook */
2091 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2092 | USB_DEVICE_ID_MATCH_INT_INFO,
2094 .idProduct = 0x08c6,
2095 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2096 .bInterfaceSubClass = 1,
2097 .bInterfaceProtocol = 0 },
2098 /* Logitech Quickcam OEM Cisco VT Camera II */
2099 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2100 | USB_DEVICE_ID_MATCH_INT_INFO,
2102 .idProduct = 0x08c7,
2103 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2104 .bInterfaceSubClass = 1,
2105 .bInterfaceProtocol = 0 },
2106 /* Chicony CNF7129 (Asus EEE 100HE) */
2107 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2108 | USB_DEVICE_ID_MATCH_INT_INFO,
2110 .idProduct = 0xb071,
2111 .bInterfaceClass = USB_CLASS_VIDEO,
2112 .bInterfaceSubClass = 1,
2113 .bInterfaceProtocol = 0,
2114 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2115 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2116 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2117 | USB_DEVICE_ID_MATCH_INT_INFO,
2119 .idProduct = 0x3820,
2120 .bInterfaceClass = USB_CLASS_VIDEO,
2121 .bInterfaceSubClass = 1,
2122 .bInterfaceProtocol = 0,
2123 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2124 /* Apple Built-In iSight */
2125 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2126 | USB_DEVICE_ID_MATCH_INT_INFO,
2128 .idProduct = 0x8501,
2129 .bInterfaceClass = USB_CLASS_VIDEO,
2130 .bInterfaceSubClass = 1,
2131 .bInterfaceProtocol = 0,
2132 .driver_info = UVC_QUIRK_PROBE_MINMAX
2133 | UVC_QUIRK_BUILTIN_ISIGHT },
2134 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2135 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2136 | USB_DEVICE_ID_MATCH_INT_INFO,
2138 .idProduct = 0x0403,
2139 .bInterfaceClass = USB_CLASS_VIDEO,
2140 .bInterfaceSubClass = 1,
2141 .bInterfaceProtocol = 0,
2142 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2143 /* Genesys Logic USB 2.0 PC Camera */
2144 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2145 | USB_DEVICE_ID_MATCH_INT_INFO,
2147 .idProduct = 0x0505,
2148 .bInterfaceClass = USB_CLASS_VIDEO,
2149 .bInterfaceSubClass = 1,
2150 .bInterfaceProtocol = 0,
2151 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2152 /* Hercules Classic Silver */
2153 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2154 | USB_DEVICE_ID_MATCH_INT_INFO,
2156 .idProduct = 0x300c,
2157 .bInterfaceClass = USB_CLASS_VIDEO,
2158 .bInterfaceSubClass = 1,
2159 .bInterfaceProtocol = 0,
2160 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2162 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2163 | USB_DEVICE_ID_MATCH_INT_INFO,
2165 .idProduct = 0x332d,
2166 .bInterfaceClass = USB_CLASS_VIDEO,
2167 .bInterfaceSubClass = 1,
2168 .bInterfaceProtocol = 0,
2169 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2170 /* ViMicro - Minoru3D */
2171 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2172 | USB_DEVICE_ID_MATCH_INT_INFO,
2174 .idProduct = 0x3410,
2175 .bInterfaceClass = USB_CLASS_VIDEO,
2176 .bInterfaceSubClass = 1,
2177 .bInterfaceProtocol = 0,
2178 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2179 /* ViMicro Venus - Minoru3D */
2180 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2181 | USB_DEVICE_ID_MATCH_INT_INFO,
2183 .idProduct = 0x3420,
2184 .bInterfaceClass = USB_CLASS_VIDEO,
2185 .bInterfaceSubClass = 1,
2186 .bInterfaceProtocol = 0,
2187 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2189 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2190 | USB_DEVICE_ID_MATCH_INT_INFO,
2192 .idProduct = 0x0004,
2193 .bInterfaceClass = USB_CLASS_VIDEO,
2194 .bInterfaceSubClass = 1,
2195 .bInterfaceProtocol = 0,
2196 .driver_info = UVC_QUIRK_PROBE_MINMAX
2197 | UVC_QUIRK_PROBE_DEF },
2198 /* IMC Networks (Medion Akoya) */
2199 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2200 | USB_DEVICE_ID_MATCH_INT_INFO,
2202 .idProduct = 0x5103,
2203 .bInterfaceClass = USB_CLASS_VIDEO,
2204 .bInterfaceSubClass = 1,
2205 .bInterfaceProtocol = 0,
2206 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2207 /* JMicron USB2.0 XGA WebCam */
2208 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2209 | USB_DEVICE_ID_MATCH_INT_INFO,
2211 .idProduct = 0x0310,
2212 .bInterfaceClass = USB_CLASS_VIDEO,
2213 .bInterfaceSubClass = 1,
2214 .bInterfaceProtocol = 0,
2215 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2216 /* Syntek (HP Spartan) */
2217 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2218 | USB_DEVICE_ID_MATCH_INT_INFO,
2220 .idProduct = 0x5212,
2221 .bInterfaceClass = USB_CLASS_VIDEO,
2222 .bInterfaceSubClass = 1,
2223 .bInterfaceProtocol = 0,
2224 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2225 /* Syntek (Samsung Q310) */
2226 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2227 | USB_DEVICE_ID_MATCH_INT_INFO,
2229 .idProduct = 0x5931,
2230 .bInterfaceClass = USB_CLASS_VIDEO,
2231 .bInterfaceSubClass = 1,
2232 .bInterfaceProtocol = 0,
2233 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2234 /* Syntek (Packard Bell EasyNote MX52 */
2235 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2236 | USB_DEVICE_ID_MATCH_INT_INFO,
2238 .idProduct = 0x8a12,
2239 .bInterfaceClass = USB_CLASS_VIDEO,
2240 .bInterfaceSubClass = 1,
2241 .bInterfaceProtocol = 0,
2242 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2243 /* Syntek (Asus F9SG) */
2244 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2245 | USB_DEVICE_ID_MATCH_INT_INFO,
2247 .idProduct = 0x8a31,
2248 .bInterfaceClass = USB_CLASS_VIDEO,
2249 .bInterfaceSubClass = 1,
2250 .bInterfaceProtocol = 0,
2251 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2252 /* Syntek (Asus U3S) */
2253 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2254 | USB_DEVICE_ID_MATCH_INT_INFO,
2256 .idProduct = 0x8a33,
2257 .bInterfaceClass = USB_CLASS_VIDEO,
2258 .bInterfaceSubClass = 1,
2259 .bInterfaceProtocol = 0,
2260 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2261 /* Syntek (JAOtech Smart Terminal) */
2262 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2263 | USB_DEVICE_ID_MATCH_INT_INFO,
2265 .idProduct = 0x8a34,
2266 .bInterfaceClass = USB_CLASS_VIDEO,
2267 .bInterfaceSubClass = 1,
2268 .bInterfaceProtocol = 0,
2269 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2271 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2272 | USB_DEVICE_ID_MATCH_INT_INFO,
2274 .idProduct = 0x0202,
2275 .bInterfaceClass = USB_CLASS_VIDEO,
2276 .bInterfaceSubClass = 1,
2277 .bInterfaceProtocol = 0,
2278 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2279 /* Lenovo Thinkpad SL400/SL500 */
2280 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2281 | USB_DEVICE_ID_MATCH_INT_INFO,
2283 .idProduct = 0x480b,
2284 .bInterfaceClass = USB_CLASS_VIDEO,
2285 .bInterfaceSubClass = 1,
2286 .bInterfaceProtocol = 0,
2287 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2288 /* Aveo Technology USB 2.0 Camera */
2289 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2290 | USB_DEVICE_ID_MATCH_INT_INFO,
2292 .idProduct = 0x0306,
2293 .bInterfaceClass = USB_CLASS_VIDEO,
2294 .bInterfaceSubClass = 1,
2295 .bInterfaceProtocol = 0,
2296 .driver_info = UVC_QUIRK_PROBE_MINMAX
2297 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2298 /* Ecamm Pico iMage */
2299 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2300 | USB_DEVICE_ID_MATCH_INT_INFO,
2302 .idProduct = 0xcafe,
2303 .bInterfaceClass = USB_CLASS_VIDEO,
2304 .bInterfaceSubClass = 1,
2305 .bInterfaceProtocol = 0,
2306 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2307 /* Manta MM-353 Plako */
2308 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2309 | USB_DEVICE_ID_MATCH_INT_INFO,
2311 .idProduct = 0x3188,
2312 .bInterfaceClass = USB_CLASS_VIDEO,
2313 .bInterfaceSubClass = 1,
2314 .bInterfaceProtocol = 0,
2315 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2316 /* FSC WebCam V30S */
2317 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2318 | USB_DEVICE_ID_MATCH_INT_INFO,
2320 .idProduct = 0x3288,
2321 .bInterfaceClass = USB_CLASS_VIDEO,
2322 .bInterfaceSubClass = 1,
2323 .bInterfaceProtocol = 0,
2324 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2325 /* Arkmicro unbranded */
2326 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2327 | USB_DEVICE_ID_MATCH_INT_INFO,
2329 .idProduct = 0x3290,
2330 .bInterfaceClass = USB_CLASS_VIDEO,
2331 .bInterfaceSubClass = 1,
2332 .bInterfaceProtocol = 0,
2333 .driver_info = UVC_QUIRK_PROBE_DEF },
2334 /* Bodelin ProScopeHR */
2335 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2336 | USB_DEVICE_ID_MATCH_DEV_HI
2337 | USB_DEVICE_ID_MATCH_INT_INFO,
2339 .idProduct = 0x1000,
2340 .bcdDevice_hi = 0x0126,
2341 .bInterfaceClass = USB_CLASS_VIDEO,
2342 .bInterfaceSubClass = 1,
2343 .bInterfaceProtocol = 0,
2344 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2345 /* MSI StarCam 370i */
2346 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2347 | USB_DEVICE_ID_MATCH_INT_INFO,
2349 .idProduct = 0x2951,
2350 .bInterfaceClass = USB_CLASS_VIDEO,
2351 .bInterfaceSubClass = 1,
2352 .bInterfaceProtocol = 0,
2353 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2354 /* SiGma Micro USB Web Camera */
2355 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2356 | USB_DEVICE_ID_MATCH_INT_INFO,
2358 .idProduct = 0x3000,
2359 .bInterfaceClass = USB_CLASS_VIDEO,
2360 .bInterfaceSubClass = 1,
2361 .bInterfaceProtocol = 0,
2362 .driver_info = UVC_QUIRK_PROBE_MINMAX
2363 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2364 /* Generic USB Video Class */
2365 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2369 MODULE_DEVICE_TABLE(usb, uvc_ids);
2371 struct uvc_driver uvc_driver = {
2375 .disconnect = uvc_disconnect,
2376 .suspend = uvc_suspend,
2377 .resume = uvc_resume,
2378 .reset_resume = uvc_reset_resume,
2379 .id_table = uvc_ids,
2380 .supports_autosuspend = 1,
2384 static int __init uvc_init(void)
2388 result = usb_register(&uvc_driver.driver);
2390 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2394 static void __exit uvc_cleanup(void)
2396 usb_deregister(&uvc_driver.driver);
2399 module_init(uvc_init);
2400 module_exit(uvc_cleanup);
2402 MODULE_AUTHOR(DRIVER_AUTHOR);
2403 MODULE_DESCRIPTION(DRIVER_DESC);
2404 MODULE_LICENSE("GPL");
2405 MODULE_VERSION(DRIVER_VERSION);