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.
14 #include <linux/atomic.h>
15 #include <linux/kernel.h>
16 #include <linux/list.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/usb.h>
20 #include <linux/videodev2.h>
21 #include <linux/vmalloc.h>
22 #include <linux/wait.h>
23 #include <linux/version.h>
24 #include <asm/unaligned.h>
26 #include <media/v4l2-common.h>
30 #define DRIVER_AUTHOR "Laurent Pinchart " \
31 "<laurent.pinchart@ideasonboard.com>"
32 #define DRIVER_DESC "USB Video Class driver"
34 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
35 unsigned int uvc_hw_timestamps_param;
36 unsigned int uvc_no_drop_param;
37 static unsigned int uvc_quirks_param = -1;
38 unsigned int uvc_trace_param;
39 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
41 /* ------------------------------------------------------------------------
45 static struct uvc_format_desc uvc_fmts[] = {
47 .name = "YUV 4:2:2 (YUYV)",
48 .guid = UVC_GUID_FORMAT_YUY2,
49 .fcc = V4L2_PIX_FMT_YUYV,
52 .name = "YUV 4:2:2 (YUYV)",
53 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
54 .fcc = V4L2_PIX_FMT_YUYV,
57 .name = "YUV 4:2:0 (NV12)",
58 .guid = UVC_GUID_FORMAT_NV12,
59 .fcc = V4L2_PIX_FMT_NV12,
63 .guid = UVC_GUID_FORMAT_MJPEG,
64 .fcc = V4L2_PIX_FMT_MJPEG,
67 .name = "YVU 4:2:0 (YV12)",
68 .guid = UVC_GUID_FORMAT_YV12,
69 .fcc = V4L2_PIX_FMT_YVU420,
72 .name = "YUV 4:2:0 (I420)",
73 .guid = UVC_GUID_FORMAT_I420,
74 .fcc = V4L2_PIX_FMT_YUV420,
77 .name = "YUV 4:2:0 (M420)",
78 .guid = UVC_GUID_FORMAT_M420,
79 .fcc = V4L2_PIX_FMT_M420,
82 .name = "YUV 4:2:2 (UYVY)",
83 .guid = UVC_GUID_FORMAT_UYVY,
84 .fcc = V4L2_PIX_FMT_UYVY,
87 .name = "Greyscale 8-bit (Y800)",
88 .guid = UVC_GUID_FORMAT_Y800,
89 .fcc = V4L2_PIX_FMT_GREY,
92 .name = "Greyscale 8-bit (Y8 )",
93 .guid = UVC_GUID_FORMAT_Y8,
94 .fcc = V4L2_PIX_FMT_GREY,
97 .name = "Greyscale 10-bit (Y10 )",
98 .guid = UVC_GUID_FORMAT_Y10,
99 .fcc = V4L2_PIX_FMT_Y10,
102 .name = "Greyscale 12-bit (Y12 )",
103 .guid = UVC_GUID_FORMAT_Y12,
104 .fcc = V4L2_PIX_FMT_Y12,
107 .name = "Greyscale 16-bit (Y16 )",
108 .guid = UVC_GUID_FORMAT_Y16,
109 .fcc = V4L2_PIX_FMT_Y16,
112 .name = "BGGR Bayer (BY8 )",
113 .guid = UVC_GUID_FORMAT_BY8,
114 .fcc = V4L2_PIX_FMT_SBGGR8,
117 .name = "BGGR Bayer (BA81)",
118 .guid = UVC_GUID_FORMAT_BA81,
119 .fcc = V4L2_PIX_FMT_SBGGR8,
122 .name = "GBRG Bayer (GBRG)",
123 .guid = UVC_GUID_FORMAT_GBRG,
124 .fcc = V4L2_PIX_FMT_SGBRG8,
127 .name = "GRBG Bayer (GRBG)",
128 .guid = UVC_GUID_FORMAT_GRBG,
129 .fcc = V4L2_PIX_FMT_SGRBG8,
132 .name = "RGGB Bayer (RGGB)",
133 .guid = UVC_GUID_FORMAT_RGGB,
134 .fcc = V4L2_PIX_FMT_SRGGB8,
138 .guid = UVC_GUID_FORMAT_RGBP,
139 .fcc = V4L2_PIX_FMT_RGB565,
142 .name = "BGR 8:8:8 (BGR3)",
143 .guid = UVC_GUID_FORMAT_BGR3,
144 .fcc = V4L2_PIX_FMT_BGR24,
148 .guid = UVC_GUID_FORMAT_H264,
149 .fcc = V4L2_PIX_FMT_H264,
152 .name = "Greyscale 8 L/R (Y8I)",
153 .guid = UVC_GUID_FORMAT_Y8I,
154 .fcc = V4L2_PIX_FMT_Y8I,
157 .name = "Greyscale 12 L/R (Y12I)",
158 .guid = UVC_GUID_FORMAT_Y12I,
159 .fcc = V4L2_PIX_FMT_Y12I,
162 .name = "Depth data 16-bit (Z16)",
163 .guid = UVC_GUID_FORMAT_Z16,
164 .fcc = V4L2_PIX_FMT_Z16,
167 .name = "Bayer 10-bit (SRGGB10P)",
168 .guid = UVC_GUID_FORMAT_RW10,
169 .fcc = V4L2_PIX_FMT_SRGGB10P,
173 /* ------------------------------------------------------------------------
177 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
180 struct usb_host_endpoint *ep;
183 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
184 ep = &alts->endpoint[i];
185 if (ep->desc.bEndpointAddress == epaddr)
192 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
194 unsigned int len = ARRAY_SIZE(uvc_fmts);
197 for (i = 0; i < len; ++i) {
198 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
205 static __u32 uvc_colorspace(const __u8 primaries)
207 static const __u8 colorprimaries[] = {
209 V4L2_COLORSPACE_SRGB,
210 V4L2_COLORSPACE_470_SYSTEM_M,
211 V4L2_COLORSPACE_470_SYSTEM_BG,
212 V4L2_COLORSPACE_SMPTE170M,
213 V4L2_COLORSPACE_SMPTE240M,
216 if (primaries < ARRAY_SIZE(colorprimaries))
217 return colorprimaries[primaries];
222 /* Simplify a fraction using a simple continued fraction decomposition. The
223 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
224 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
225 * arbitrary parameters to remove non-significative terms from the simple
226 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
227 * respectively seems to give nice results.
229 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
230 unsigned int n_terms, unsigned int threshold)
236 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
240 /* Convert the fraction to a simple continued fraction. See
241 * http://mathforum.org/dr.math/faq/faq.fractions.html
242 * Stop if the current term is bigger than or equal to the given
248 for (n = 0; n < n_terms && y != 0; ++n) {
250 if (an[n] >= threshold) {
261 /* Expand the simple continued fraction back to an integer fraction. */
265 for (i = n; i > 0; --i) {
276 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
277 * to compute numerator / denominator * 10000000 using 32 bit fixed point
280 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
284 /* Saturate the result if the operation would overflow. */
285 if (denominator == 0 ||
286 numerator/denominator >= ((uint32_t)-1)/10000000)
289 /* Divide both the denominator and the multiplier by two until
290 * numerator * multiplier doesn't overflow. If anyone knows a better
291 * algorithm please let me know.
293 multiplier = 10000000;
294 while (numerator > ((uint32_t)-1)/multiplier) {
299 return denominator ? numerator * multiplier / denominator : 0;
302 /* ------------------------------------------------------------------------
303 * Terminal and unit management
306 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
308 struct uvc_entity *entity;
310 list_for_each_entry(entity, &dev->entities, list) {
311 if (entity->id == id)
318 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
319 int id, struct uvc_entity *entity)
324 entity = list_entry(&dev->entities, struct uvc_entity, list);
326 list_for_each_entry_continue(entity, &dev->entities, list) {
327 for (i = 0; i < entity->bNrInPins; ++i)
328 if (entity->baSourceID[i] == id)
335 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
337 struct uvc_streaming *stream;
339 list_for_each_entry(stream, &dev->streams, list) {
340 if (stream->header.bTerminalLink == id)
347 /* ------------------------------------------------------------------------
348 * Descriptors parsing
351 static int uvc_parse_format(struct uvc_device *dev,
352 struct uvc_streaming *streaming, struct uvc_format *format,
353 __u32 **intervals, unsigned char *buffer, int buflen)
355 struct usb_interface *intf = streaming->intf;
356 struct usb_host_interface *alts = intf->cur_altsetting;
357 struct uvc_format_desc *fmtdesc;
358 struct uvc_frame *frame;
359 const unsigned char *start = buffer;
360 unsigned int width_multiplier = 1;
361 unsigned int interval;
365 format->type = buffer[2];
366 format->index = buffer[3];
369 case UVC_VS_FORMAT_UNCOMPRESSED:
370 case UVC_VS_FORMAT_FRAME_BASED:
371 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
373 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
374 "interface %d FORMAT error\n",
376 alts->desc.bInterfaceNumber);
380 /* Find the format descriptor from its GUID. */
381 fmtdesc = uvc_format_by_guid(&buffer[5]);
383 if (fmtdesc != NULL) {
384 strlcpy(format->name, fmtdesc->name,
385 sizeof format->name);
386 format->fcc = fmtdesc->fcc;
388 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
390 snprintf(format->name, sizeof(format->name), "%pUl\n",
395 format->bpp = buffer[21];
397 /* Some devices report a format that doesn't match what they
400 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
401 if (format->fcc == V4L2_PIX_FMT_YUYV) {
402 strlcpy(format->name, "Greyscale 8-bit (Y8 )",
403 sizeof(format->name));
404 format->fcc = V4L2_PIX_FMT_GREY;
406 width_multiplier = 2;
410 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
411 ftype = UVC_VS_FRAME_UNCOMPRESSED;
413 ftype = UVC_VS_FRAME_FRAME_BASED;
415 format->flags = UVC_FMT_FLAG_COMPRESSED;
419 case UVC_VS_FORMAT_MJPEG:
421 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
422 "interface %d FORMAT error\n",
424 alts->desc.bInterfaceNumber);
428 strlcpy(format->name, "MJPEG", sizeof format->name);
429 format->fcc = V4L2_PIX_FMT_MJPEG;
430 format->flags = UVC_FMT_FLAG_COMPRESSED;
432 ftype = UVC_VS_FRAME_MJPEG;
435 case UVC_VS_FORMAT_DV:
437 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
438 "interface %d FORMAT error\n",
440 alts->desc.bInterfaceNumber);
444 switch (buffer[8] & 0x7f) {
446 strlcpy(format->name, "SD-DV", sizeof format->name);
449 strlcpy(format->name, "SDL-DV", sizeof format->name);
452 strlcpy(format->name, "HD-DV", sizeof format->name);
455 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
456 "interface %d: unknown DV format %u\n",
458 alts->desc.bInterfaceNumber, buffer[8]);
462 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
463 sizeof format->name);
465 format->fcc = V4L2_PIX_FMT_DV;
466 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
470 /* Create a dummy frame descriptor. */
471 frame = &format->frame[0];
472 memset(&format->frame[0], 0, sizeof format->frame[0]);
473 frame->bFrameIntervalType = 1;
474 frame->dwDefaultFrameInterval = 1;
475 frame->dwFrameInterval = *intervals;
480 case UVC_VS_FORMAT_MPEG2TS:
481 case UVC_VS_FORMAT_STREAM_BASED:
482 /* Not supported yet. */
484 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
485 "interface %d unsupported format %u\n",
486 dev->udev->devnum, alts->desc.bInterfaceNumber,
491 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
496 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
497 * based formats have frame descriptors.
499 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
500 buffer[2] == ftype) {
501 frame = &format->frame[format->nframes];
502 if (ftype != UVC_VS_FRAME_FRAME_BASED)
503 n = buflen > 25 ? buffer[25] : 0;
505 n = buflen > 21 ? buffer[21] : 0;
509 if (buflen < 26 + 4*n) {
510 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
511 "interface %d FRAME error\n", dev->udev->devnum,
512 alts->desc.bInterfaceNumber);
516 frame->bFrameIndex = buffer[3];
517 frame->bmCapabilities = buffer[4];
518 frame->wWidth = get_unaligned_le16(&buffer[5])
520 frame->wHeight = get_unaligned_le16(&buffer[7]);
521 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
522 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
523 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
524 frame->dwMaxVideoFrameBufferSize =
525 get_unaligned_le32(&buffer[17]);
526 frame->dwDefaultFrameInterval =
527 get_unaligned_le32(&buffer[21]);
528 frame->bFrameIntervalType = buffer[25];
530 frame->dwMaxVideoFrameBufferSize = 0;
531 frame->dwDefaultFrameInterval =
532 get_unaligned_le32(&buffer[17]);
533 frame->bFrameIntervalType = buffer[21];
535 frame->dwFrameInterval = *intervals;
537 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
538 * completely. Observed behaviours range from setting the
539 * value to 1.1x the actual frame size to hardwiring the
540 * 16 low bits to 0. This results in a higher than necessary
541 * memory usage as well as a wrong image size information. For
542 * uncompressed formats this can be fixed by computing the
543 * value from the frame size.
545 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
546 frame->dwMaxVideoFrameBufferSize = format->bpp
547 * frame->wWidth * frame->wHeight / 8;
549 /* Some bogus devices report dwMinFrameInterval equal to
550 * dwMaxFrameInterval and have dwFrameIntervalStep set to
551 * zero. Setting all null intervals to 1 fixes the problem and
552 * some other divisions by zero that could happen.
554 for (i = 0; i < n; ++i) {
555 interval = get_unaligned_le32(&buffer[26+4*i]);
556 *(*intervals)++ = interval ? interval : 1;
559 /* Make sure that the default frame interval stays between
562 n -= frame->bFrameIntervalType ? 1 : 2;
563 frame->dwDefaultFrameInterval =
564 min(frame->dwFrameInterval[n],
565 max(frame->dwFrameInterval[0],
566 frame->dwDefaultFrameInterval));
568 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
569 frame->bFrameIntervalType = 1;
570 frame->dwFrameInterval[0] =
571 frame->dwDefaultFrameInterval;
574 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
575 frame->wWidth, frame->wHeight,
576 10000000/frame->dwDefaultFrameInterval,
577 (100000000/frame->dwDefaultFrameInterval)%10);
584 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
585 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
590 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
591 buffer[2] == UVC_VS_COLORFORMAT) {
593 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
594 "interface %d COLORFORMAT error\n",
596 alts->desc.bInterfaceNumber);
600 format->colorspace = uvc_colorspace(buffer[3]);
606 return buffer - start;
609 static int uvc_parse_streaming(struct uvc_device *dev,
610 struct usb_interface *intf)
612 struct uvc_streaming *streaming = NULL;
613 struct uvc_format *format;
614 struct uvc_frame *frame;
615 struct usb_host_interface *alts = &intf->altsetting[0];
616 unsigned char *_buffer, *buffer = alts->extra;
617 int _buflen, buflen = alts->extralen;
618 unsigned int nformats = 0, nframes = 0, nintervals = 0;
619 unsigned int size, i, n, p;
624 if (intf->cur_altsetting->desc.bInterfaceSubClass
625 != UVC_SC_VIDEOSTREAMING) {
626 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
627 "video streaming interface\n", dev->udev->devnum,
628 intf->altsetting[0].desc.bInterfaceNumber);
632 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
633 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
634 "claimed\n", dev->udev->devnum,
635 intf->altsetting[0].desc.bInterfaceNumber);
639 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
640 if (streaming == NULL) {
641 usb_driver_release_interface(&uvc_driver.driver, intf);
645 mutex_init(&streaming->mutex);
646 streaming->dev = dev;
647 streaming->intf = usb_get_intf(intf);
648 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
650 /* The Pico iMage webcam has its class-specific interface descriptors
651 * after the endpoint descriptors.
654 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
655 struct usb_host_endpoint *ep = &alts->endpoint[i];
657 if (ep->extralen == 0)
660 if (ep->extralen > 2 &&
661 ep->extra[1] == USB_DT_CS_INTERFACE) {
662 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
663 "from endpoint %u.\n", i);
664 buffer = alts->endpoint[i].extra;
665 buflen = alts->endpoint[i].extralen;
671 /* Skip the standard interface descriptors. */
672 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
678 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
679 "interface descriptors found.\n");
683 /* Parse the header descriptor. */
685 case UVC_VS_OUTPUT_HEADER:
686 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
690 case UVC_VS_INPUT_HEADER:
691 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
696 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
697 "%d HEADER descriptor not found.\n", dev->udev->devnum,
698 alts->desc.bInterfaceNumber);
702 p = buflen >= 4 ? buffer[3] : 0;
703 n = buflen >= size ? buffer[size-1] : 0;
705 if (buflen < size + p*n) {
706 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
707 "interface %d HEADER descriptor is invalid.\n",
708 dev->udev->devnum, alts->desc.bInterfaceNumber);
712 streaming->header.bNumFormats = p;
713 streaming->header.bEndpointAddress = buffer[6];
714 if (buffer[2] == UVC_VS_INPUT_HEADER) {
715 streaming->header.bmInfo = buffer[7];
716 streaming->header.bTerminalLink = buffer[8];
717 streaming->header.bStillCaptureMethod = buffer[9];
718 streaming->header.bTriggerSupport = buffer[10];
719 streaming->header.bTriggerUsage = buffer[11];
721 streaming->header.bTerminalLink = buffer[7];
723 streaming->header.bControlSize = n;
725 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
727 if (streaming->header.bmaControls == NULL) {
738 /* Count the format and frame descriptors. */
739 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
740 switch (_buffer[2]) {
741 case UVC_VS_FORMAT_UNCOMPRESSED:
742 case UVC_VS_FORMAT_MJPEG:
743 case UVC_VS_FORMAT_FRAME_BASED:
747 case UVC_VS_FORMAT_DV:
748 /* DV format has no frame descriptor. We will create a
749 * dummy frame descriptor with a dummy frame interval.
756 case UVC_VS_FORMAT_MPEG2TS:
757 case UVC_VS_FORMAT_STREAM_BASED:
758 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
759 "interface %d FORMAT %u is not supported.\n",
761 alts->desc.bInterfaceNumber, _buffer[2]);
764 case UVC_VS_FRAME_UNCOMPRESSED:
765 case UVC_VS_FRAME_MJPEG:
768 nintervals += _buffer[25] ? _buffer[25] : 3;
771 case UVC_VS_FRAME_FRAME_BASED:
774 nintervals += _buffer[21] ? _buffer[21] : 3;
778 _buflen -= _buffer[0];
779 _buffer += _buffer[0];
783 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
784 "%d has no supported formats defined.\n",
785 dev->udev->devnum, alts->desc.bInterfaceNumber);
789 size = nformats * sizeof *format + nframes * sizeof *frame
790 + nintervals * sizeof *interval;
791 format = kzalloc(size, GFP_KERNEL);
792 if (format == NULL) {
797 frame = (struct uvc_frame *)&format[nformats];
798 interval = (__u32 *)&frame[nframes];
800 streaming->format = format;
801 streaming->nformats = nformats;
803 /* Parse the format descriptors. */
804 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
806 case UVC_VS_FORMAT_UNCOMPRESSED:
807 case UVC_VS_FORMAT_MJPEG:
808 case UVC_VS_FORMAT_DV:
809 case UVC_VS_FORMAT_FRAME_BASED:
810 format->frame = frame;
811 ret = uvc_parse_format(dev, streaming, format,
812 &interval, buffer, buflen);
816 frame += format->nframes;
832 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
833 "%d has %u bytes of trailing descriptor garbage.\n",
834 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
836 /* Parse the alternate settings to find the maximum bandwidth. */
837 for (i = 0; i < intf->num_altsetting; ++i) {
838 struct usb_host_endpoint *ep;
839 alts = &intf->altsetting[i];
840 ep = uvc_find_endpoint(alts,
841 streaming->header.bEndpointAddress);
845 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
846 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
847 if (psize > streaming->maxpsize)
848 streaming->maxpsize = psize;
851 list_add_tail(&streaming->list, &dev->streams);
855 usb_driver_release_interface(&uvc_driver.driver, intf);
857 kfree(streaming->format);
858 kfree(streaming->header.bmaControls);
863 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
864 unsigned int num_pads, unsigned int extra_size)
866 struct uvc_entity *entity;
867 unsigned int num_inputs;
871 extra_size = roundup(extra_size, sizeof(*entity->pads));
873 num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
876 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
878 entity = kzalloc(size, GFP_KERNEL);
885 entity->num_links = 0;
886 entity->num_pads = num_pads;
887 entity->pads = ((void *)(entity + 1)) + extra_size;
889 for (i = 0; i < num_inputs; ++i)
890 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
891 if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
892 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
894 entity->bNrInPins = num_inputs;
895 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
900 /* Parse vendor-specific extensions. */
901 static int uvc_parse_vendor_control(struct uvc_device *dev,
902 const unsigned char *buffer, int buflen)
904 struct usb_device *udev = dev->udev;
905 struct usb_host_interface *alts = dev->intf->cur_altsetting;
906 struct uvc_entity *unit;
910 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
911 case 0x046d: /* Logitech */
912 if (buffer[1] != 0x41 || buffer[2] != 0x01)
915 /* Logitech implements several vendor specific functions
916 * through vendor specific extension units (LXU).
918 * The LXU descriptors are similar to XU descriptors
919 * (see "USB Device Video Class for Video Devices", section
920 * 3.7.2.6 "Extension Unit Descriptor") with the following
923 * ----------------------------------------------------------
925 * Size of this descriptor, in bytes: 24+p+n*2
926 * ----------------------------------------------------------
927 * 23+p+n bmControlsType N Bitmap
928 * Individual bits in the set are defined:
932 * This bitset is mapped exactly the same as bmControls.
933 * ----------------------------------------------------------
934 * 23+p+n*2 bReserved 1 Boolean
935 * ----------------------------------------------------------
936 * 24+p+n*2 iExtension 1 Index
937 * Index of a string descriptor that describes this
939 * ----------------------------------------------------------
941 p = buflen >= 22 ? buffer[21] : 0;
942 n = buflen >= 25 + p ? buffer[22+p] : 0;
944 if (buflen < 25 + p + 2*n) {
945 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
946 "interface %d EXTENSION_UNIT error\n",
947 udev->devnum, alts->desc.bInterfaceNumber);
951 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
956 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
957 unit->extension.bNumControls = buffer[20];
958 memcpy(unit->baSourceID, &buffer[22], p);
959 unit->extension.bControlSize = buffer[22+p];
960 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
961 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
963 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
965 if (buffer[24+p+2*n] != 0)
966 usb_string(udev, buffer[24+p+2*n], unit->name,
969 sprintf(unit->name, "Extension %u", buffer[3]);
971 list_add_tail(&unit->list, &dev->entities);
979 static int uvc_parse_standard_control(struct uvc_device *dev,
980 const unsigned char *buffer, int buflen)
982 struct usb_device *udev = dev->udev;
983 struct uvc_entity *unit, *term;
984 struct usb_interface *intf;
985 struct usb_host_interface *alts = dev->intf->cur_altsetting;
986 unsigned int i, n, p, len;
991 n = buflen >= 12 ? buffer[11] : 0;
993 if (buflen < 12 + n) {
994 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
995 "interface %d HEADER error\n", udev->devnum,
996 alts->desc.bInterfaceNumber);
1000 dev->uvc_version = get_unaligned_le16(&buffer[3]);
1001 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
1003 /* Parse all USB Video Streaming interfaces. */
1004 for (i = 0; i < n; ++i) {
1005 intf = usb_ifnum_to_if(udev, buffer[12+i]);
1007 uvc_trace(UVC_TRACE_DESCR, "device %d "
1008 "interface %d doesn't exists\n",
1013 uvc_parse_streaming(dev, intf);
1017 case UVC_VC_INPUT_TERMINAL:
1019 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1020 "interface %d INPUT_TERMINAL error\n",
1021 udev->devnum, alts->desc.bInterfaceNumber);
1026 * Reject invalid terminal types that would cause issues:
1028 * - The high byte must be non-zero, otherwise it would be
1029 * confused with a unit.
1031 * - Bit 15 must be 0, as we use it internally as a terminal
1034 * Other unknown types are accepted.
1036 type = get_unaligned_le16(&buffer[4]);
1037 if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
1038 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1039 "interface %d INPUT_TERMINAL %d has invalid "
1040 "type 0x%04x, skipping\n", udev->devnum,
1041 alts->desc.bInterfaceNumber,
1050 if (type == UVC_ITT_CAMERA) {
1051 n = buflen >= 15 ? buffer[14] : 0;
1054 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1055 n = buflen >= 9 ? buffer[8] : 0;
1056 p = buflen >= 10 + n ? buffer[9+n] : 0;
1060 if (buflen < len + n + p) {
1061 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1062 "interface %d INPUT_TERMINAL error\n",
1063 udev->devnum, alts->desc.bInterfaceNumber);
1067 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1072 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1073 term->camera.bControlSize = n;
1074 term->camera.bmControls = (__u8 *)term + sizeof *term;
1075 term->camera.wObjectiveFocalLengthMin =
1076 get_unaligned_le16(&buffer[8]);
1077 term->camera.wObjectiveFocalLengthMax =
1078 get_unaligned_le16(&buffer[10]);
1079 term->camera.wOcularFocalLength =
1080 get_unaligned_le16(&buffer[12]);
1081 memcpy(term->camera.bmControls, &buffer[15], n);
1082 } else if (UVC_ENTITY_TYPE(term) ==
1083 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1084 term->media.bControlSize = n;
1085 term->media.bmControls = (__u8 *)term + sizeof *term;
1086 term->media.bTransportModeSize = p;
1087 term->media.bmTransportModes = (__u8 *)term
1089 memcpy(term->media.bmControls, &buffer[9], n);
1090 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1094 usb_string(udev, buffer[7], term->name,
1096 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1097 sprintf(term->name, "Camera %u", buffer[3]);
1098 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1099 sprintf(term->name, "Media %u", buffer[3]);
1101 sprintf(term->name, "Input %u", buffer[3]);
1103 list_add_tail(&term->list, &dev->entities);
1106 case UVC_VC_OUTPUT_TERMINAL:
1108 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1109 "interface %d OUTPUT_TERMINAL error\n",
1110 udev->devnum, alts->desc.bInterfaceNumber);
1114 /* Make sure the terminal type MSB is not null, otherwise it
1115 * could be confused with a unit.
1117 type = get_unaligned_le16(&buffer[4]);
1118 if ((type & 0xff00) == 0) {
1119 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1120 "interface %d OUTPUT_TERMINAL %d has invalid "
1121 "type 0x%04x, skipping\n", udev->devnum,
1122 alts->desc.bInterfaceNumber, buffer[3], type);
1126 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1131 memcpy(term->baSourceID, &buffer[7], 1);
1134 usb_string(udev, buffer[8], term->name,
1137 sprintf(term->name, "Output %u", buffer[3]);
1139 list_add_tail(&term->list, &dev->entities);
1142 case UVC_VC_SELECTOR_UNIT:
1143 p = buflen >= 5 ? buffer[4] : 0;
1145 if (buflen < 5 || buflen < 6 + p) {
1146 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1147 "interface %d SELECTOR_UNIT error\n",
1148 udev->devnum, alts->desc.bInterfaceNumber);
1152 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1156 memcpy(unit->baSourceID, &buffer[5], p);
1158 if (buffer[5+p] != 0)
1159 usb_string(udev, buffer[5+p], unit->name,
1162 sprintf(unit->name, "Selector %u", buffer[3]);
1164 list_add_tail(&unit->list, &dev->entities);
1167 case UVC_VC_PROCESSING_UNIT:
1168 n = buflen >= 8 ? buffer[7] : 0;
1169 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1171 if (buflen < p + n) {
1172 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1173 "interface %d PROCESSING_UNIT error\n",
1174 udev->devnum, alts->desc.bInterfaceNumber);
1178 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1182 memcpy(unit->baSourceID, &buffer[4], 1);
1183 unit->processing.wMaxMultiplier =
1184 get_unaligned_le16(&buffer[5]);
1185 unit->processing.bControlSize = buffer[7];
1186 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1187 memcpy(unit->processing.bmControls, &buffer[8], n);
1188 if (dev->uvc_version >= 0x0110)
1189 unit->processing.bmVideoStandards = buffer[9+n];
1191 if (buffer[8+n] != 0)
1192 usb_string(udev, buffer[8+n], unit->name,
1195 sprintf(unit->name, "Processing %u", buffer[3]);
1197 list_add_tail(&unit->list, &dev->entities);
1200 case UVC_VC_EXTENSION_UNIT:
1201 p = buflen >= 22 ? buffer[21] : 0;
1202 n = buflen >= 24 + p ? buffer[22+p] : 0;
1204 if (buflen < 24 + p + n) {
1205 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1206 "interface %d EXTENSION_UNIT error\n",
1207 udev->devnum, alts->desc.bInterfaceNumber);
1211 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1215 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1216 unit->extension.bNumControls = buffer[20];
1217 memcpy(unit->baSourceID, &buffer[22], p);
1218 unit->extension.bControlSize = buffer[22+p];
1219 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1220 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1222 if (buffer[23+p+n] != 0)
1223 usb_string(udev, buffer[23+p+n], unit->name,
1226 sprintf(unit->name, "Extension %u", buffer[3]);
1228 list_add_tail(&unit->list, &dev->entities);
1232 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1233 "descriptor (%u)\n", buffer[2]);
1240 static int uvc_parse_control(struct uvc_device *dev)
1242 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1243 unsigned char *buffer = alts->extra;
1244 int buflen = alts->extralen;
1247 /* Parse the default alternate setting only, as the UVC specification
1248 * defines a single alternate setting, the default alternate setting
1252 while (buflen > 2) {
1253 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1254 buffer[1] != USB_DT_CS_INTERFACE)
1255 goto next_descriptor;
1257 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1261 buflen -= buffer[0];
1262 buffer += buffer[0];
1265 /* Check if the optional status endpoint is present. Built-in iSight
1266 * webcams have an interrupt endpoint but spit proprietary data that
1267 * don't conform to the UVC status endpoint messages. Don't try to
1268 * handle the interrupt endpoint for those cameras.
1270 if (alts->desc.bNumEndpoints == 1 &&
1271 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1272 struct usb_host_endpoint *ep = &alts->endpoint[0];
1273 struct usb_endpoint_descriptor *desc = &ep->desc;
1275 if (usb_endpoint_is_int_in(desc) &&
1276 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1277 desc->bInterval != 0) {
1278 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1279 "(addr %02x).\n", desc->bEndpointAddress);
1287 /* ------------------------------------------------------------------------
1292 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1293 * and containing the following units:
1295 * - one or more Output Terminals (USB Streaming or Display)
1296 * - zero or one Processing Unit
1297 * - zero, one or more single-input Selector Units
1298 * - zero or one multiple-input Selector Units, provided all inputs are
1299 * connected to input terminals
1300 * - zero, one or mode single-input Extension Units
1301 * - one or more Input Terminals (Camera, External or USB Streaming)
1303 * The terminal and units must match on of the following structures:
1305 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1306 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1307 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1309 * +---------+ +---------+ -> OTT_*(0)
1310 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1311 * +---------+ +---------+ -> OTT_*(n)
1313 * The Processing Unit and Extension Units can be in any order. Additional
1314 * Extension Units connected to the main chain as single-unit branches are
1315 * also supported. Single-input Selector Units are ignored.
1317 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1318 struct uvc_entity *entity)
1320 switch (UVC_ENTITY_TYPE(entity)) {
1321 case UVC_VC_EXTENSION_UNIT:
1322 if (uvc_trace_param & UVC_TRACE_PROBE)
1323 printk(" <- XU %d", entity->id);
1325 if (entity->bNrInPins != 1) {
1326 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1327 "than 1 input pin.\n", entity->id);
1333 case UVC_VC_PROCESSING_UNIT:
1334 if (uvc_trace_param & UVC_TRACE_PROBE)
1335 printk(" <- PU %d", entity->id);
1337 if (chain->processing != NULL) {
1338 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1339 "Processing Units in chain.\n");
1343 chain->processing = entity;
1346 case UVC_VC_SELECTOR_UNIT:
1347 if (uvc_trace_param & UVC_TRACE_PROBE)
1348 printk(" <- SU %d", entity->id);
1350 /* Single-input selector units are ignored. */
1351 if (entity->bNrInPins == 1)
1354 if (chain->selector != NULL) {
1355 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1356 "Units in chain.\n");
1360 chain->selector = entity;
1363 case UVC_ITT_VENDOR_SPECIFIC:
1364 case UVC_ITT_CAMERA:
1365 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1366 if (uvc_trace_param & UVC_TRACE_PROBE)
1367 printk(" <- IT %d\n", entity->id);
1371 case UVC_OTT_VENDOR_SPECIFIC:
1372 case UVC_OTT_DISPLAY:
1373 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1374 if (uvc_trace_param & UVC_TRACE_PROBE)
1375 printk(" OT %d", entity->id);
1379 case UVC_TT_STREAMING:
1380 if (UVC_ENTITY_IS_ITERM(entity)) {
1381 if (uvc_trace_param & UVC_TRACE_PROBE)
1382 printk(" <- IT %d\n", entity->id);
1384 if (uvc_trace_param & UVC_TRACE_PROBE)
1385 printk(" OT %d", entity->id);
1391 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1392 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1396 list_add_tail(&entity->chain, &chain->entities);
1400 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1401 struct uvc_entity *entity, struct uvc_entity *prev)
1403 struct uvc_entity *forward;
1411 forward = uvc_entity_by_reference(chain->dev, entity->id,
1413 if (forward == NULL)
1415 if (forward == prev)
1417 if (forward->chain.next || forward->chain.prev) {
1418 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1419 "entity %d already in chain.\n", forward->id);
1423 switch (UVC_ENTITY_TYPE(forward)) {
1424 case UVC_VC_EXTENSION_UNIT:
1425 if (forward->bNrInPins != 1) {
1426 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1427 "has more than 1 input pin.\n",
1432 list_add_tail(&forward->chain, &chain->entities);
1433 if (uvc_trace_param & UVC_TRACE_PROBE) {
1437 printk(" XU %d", forward->id);
1442 case UVC_OTT_VENDOR_SPECIFIC:
1443 case UVC_OTT_DISPLAY:
1444 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1445 case UVC_TT_STREAMING:
1446 if (UVC_ENTITY_IS_ITERM(forward)) {
1447 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1448 "terminal %u.\n", forward->id);
1452 list_add_tail(&forward->chain, &chain->entities);
1453 if (uvc_trace_param & UVC_TRACE_PROBE) {
1457 printk(" OT %d", forward->id);
1469 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1470 struct uvc_entity **_entity)
1472 struct uvc_entity *entity = *_entity;
1473 struct uvc_entity *term;
1474 int id = -EINVAL, i;
1476 switch (UVC_ENTITY_TYPE(entity)) {
1477 case UVC_VC_EXTENSION_UNIT:
1478 case UVC_VC_PROCESSING_UNIT:
1479 id = entity->baSourceID[0];
1482 case UVC_VC_SELECTOR_UNIT:
1483 /* Single-input selector units are ignored. */
1484 if (entity->bNrInPins == 1) {
1485 id = entity->baSourceID[0];
1489 if (uvc_trace_param & UVC_TRACE_PROBE)
1492 chain->selector = entity;
1493 for (i = 0; i < entity->bNrInPins; ++i) {
1494 id = entity->baSourceID[i];
1495 term = uvc_entity_by_id(chain->dev, id);
1496 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1497 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1498 "input %d isn't connected to an "
1499 "input terminal\n", entity->id, i);
1503 if (term->chain.next || term->chain.prev) {
1504 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1505 "entity %d already in chain.\n",
1510 if (uvc_trace_param & UVC_TRACE_PROBE)
1511 printk(" %d", term->id);
1513 list_add_tail(&term->chain, &chain->entities);
1514 uvc_scan_chain_forward(chain, term, entity);
1517 if (uvc_trace_param & UVC_TRACE_PROBE)
1523 case UVC_ITT_VENDOR_SPECIFIC:
1524 case UVC_ITT_CAMERA:
1525 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1526 case UVC_OTT_VENDOR_SPECIFIC:
1527 case UVC_OTT_DISPLAY:
1528 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1529 case UVC_TT_STREAMING:
1530 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1539 entity = uvc_entity_by_id(chain->dev, id);
1540 if (entity == NULL) {
1541 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1542 "unknown entity %d.\n", id);
1550 static int uvc_scan_chain(struct uvc_video_chain *chain,
1551 struct uvc_entity *term)
1553 struct uvc_entity *entity, *prev;
1555 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1560 while (entity != NULL) {
1561 /* Entity must not be part of an existing chain */
1562 if (entity->chain.next || entity->chain.prev) {
1563 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1564 "entity %d already in chain.\n", entity->id);
1568 /* Process entity */
1569 if (uvc_scan_chain_entity(chain, entity) < 0)
1573 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1578 if (uvc_scan_chain_backward(chain, &entity) < 0)
1585 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1588 struct uvc_entity *term;
1589 unsigned int nterms = 0;
1592 list_for_each_entry(term, terms, chain) {
1593 if (!UVC_ENTITY_IS_TERM(term) ||
1594 UVC_TERM_DIRECTION(term) != dir)
1598 p += sprintf(p, ",");
1599 if (++nterms >= 4) {
1600 p += sprintf(p, "...");
1603 p += sprintf(p, "%u", term->id);
1609 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1611 static char buffer[43];
1614 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1615 p += sprintf(p, " -> ");
1616 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1621 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1623 struct uvc_video_chain *chain;
1625 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1629 INIT_LIST_HEAD(&chain->entities);
1630 mutex_init(&chain->ctrl_mutex);
1632 v4l2_prio_init(&chain->prio);
1638 * Fallback heuristic for devices that don't connect units and terminals in a
1641 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1642 * to fail, but if we just take the entities we can find and put them together
1643 * in the most sensible chain we can think of, turns out they do work anyway.
1644 * Note: This heuristic assumes there is a single chain.
1646 * At the time of writing, devices known to have such a broken chain are
1647 * - Acer Integrated Camera (5986:055a)
1648 * - Realtek rtl157a7 (0bda:57a7)
1650 static int uvc_scan_fallback(struct uvc_device *dev)
1652 struct uvc_video_chain *chain;
1653 struct uvc_entity *iterm = NULL;
1654 struct uvc_entity *oterm = NULL;
1655 struct uvc_entity *entity;
1656 struct uvc_entity *prev;
1659 * Start by locating the input and output terminals. We only support
1660 * devices with exactly one of each for now.
1662 list_for_each_entry(entity, &dev->entities, list) {
1663 if (UVC_ENTITY_IS_ITERM(entity)) {
1669 if (UVC_ENTITY_IS_OTERM(entity)) {
1676 if (iterm == NULL || oterm == NULL)
1679 /* Allocate the chain and fill it. */
1680 chain = uvc_alloc_chain(dev);
1684 if (uvc_scan_chain_entity(chain, oterm) < 0)
1690 * Add all Processing and Extension Units with two pads. The order
1691 * doesn't matter much, use reverse list traversal to connect units in
1692 * UVC descriptor order as we build the chain from output to input. This
1693 * leads to units appearing in the order meant by the manufacturer for
1694 * the cameras known to require this heuristic.
1696 list_for_each_entry_reverse(entity, &dev->entities, list) {
1697 if (entity->type != UVC_VC_PROCESSING_UNIT &&
1698 entity->type != UVC_VC_EXTENSION_UNIT)
1701 if (entity->num_pads != 2)
1704 if (uvc_scan_chain_entity(chain, entity) < 0)
1707 prev->baSourceID[0] = entity->id;
1711 if (uvc_scan_chain_entity(chain, iterm) < 0)
1714 prev->baSourceID[0] = iterm->id;
1716 list_add_tail(&chain->list, &dev->chains);
1718 uvc_trace(UVC_TRACE_PROBE,
1719 "Found a video chain by fallback heuristic (%s).\n",
1720 uvc_print_chain(chain));
1730 * Scan the device for video chains and register video devices.
1732 * Chains are scanned starting at their output terminals and walked backwards.
1734 static int uvc_scan_device(struct uvc_device *dev)
1736 struct uvc_video_chain *chain;
1737 struct uvc_entity *term;
1739 list_for_each_entry(term, &dev->entities, list) {
1740 if (!UVC_ENTITY_IS_OTERM(term))
1743 /* If the terminal is already included in a chain, skip it.
1744 * This can happen for chains that have multiple output
1745 * terminals, where all output terminals beside the first one
1746 * will be inserted in the chain in forward scans.
1748 if (term->chain.next || term->chain.prev)
1751 chain = uvc_alloc_chain(dev);
1755 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1757 if (uvc_scan_chain(chain, term) < 0) {
1762 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1763 uvc_print_chain(chain));
1765 list_add_tail(&chain->list, &dev->chains);
1768 if (list_empty(&dev->chains))
1769 uvc_scan_fallback(dev);
1771 if (list_empty(&dev->chains)) {
1772 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1779 /* ------------------------------------------------------------------------
1780 * Video device registration and unregistration
1784 * Delete the UVC device.
1786 * Called by the kernel when the last reference to the uvc_device structure
1789 * As this function is called after or during disconnect(), all URBs have
1790 * already been canceled by the USB core. There is no need to kill the
1791 * interrupt URB manually.
1793 static void uvc_delete(struct uvc_device *dev)
1795 struct list_head *p, *n;
1797 uvc_status_cleanup(dev);
1798 uvc_ctrl_cleanup_device(dev);
1800 usb_put_intf(dev->intf);
1801 usb_put_dev(dev->udev);
1804 v4l2_device_unregister(&dev->vdev);
1805 #ifdef CONFIG_MEDIA_CONTROLLER
1806 if (media_devnode_is_registered(dev->mdev.devnode))
1807 media_device_unregister(&dev->mdev);
1808 media_device_cleanup(&dev->mdev);
1811 list_for_each_safe(p, n, &dev->chains) {
1812 struct uvc_video_chain *chain;
1813 chain = list_entry(p, struct uvc_video_chain, list);
1817 list_for_each_safe(p, n, &dev->entities) {
1818 struct uvc_entity *entity;
1819 entity = list_entry(p, struct uvc_entity, list);
1820 #ifdef CONFIG_MEDIA_CONTROLLER
1821 uvc_mc_cleanup_entity(entity);
1826 list_for_each_safe(p, n, &dev->streams) {
1827 struct uvc_streaming *streaming;
1828 streaming = list_entry(p, struct uvc_streaming, list);
1829 usb_driver_release_interface(&uvc_driver.driver,
1831 usb_put_intf(streaming->intf);
1832 kfree(streaming->format);
1833 kfree(streaming->header.bmaControls);
1840 static void uvc_release(struct video_device *vdev)
1842 struct uvc_streaming *stream = video_get_drvdata(vdev);
1843 struct uvc_device *dev = stream->dev;
1845 /* Decrement the registered streams count and delete the device when it
1848 if (atomic_dec_and_test(&dev->nstreams))
1853 * Unregister the video devices.
1855 static void uvc_unregister_video(struct uvc_device *dev)
1857 struct uvc_streaming *stream;
1859 /* Unregistering all video devices might result in uvc_delete() being
1860 * called from inside the loop if there's no open file handle. To avoid
1861 * that, increment the stream count before iterating over the streams
1862 * and decrement it when done.
1864 atomic_inc(&dev->nstreams);
1866 list_for_each_entry(stream, &dev->streams, list) {
1867 if (!video_is_registered(&stream->vdev))
1870 video_unregister_device(&stream->vdev);
1872 uvc_debugfs_cleanup_stream(stream);
1875 /* Decrement the stream count and call uvc_delete explicitly if there
1876 * are no stream left.
1878 if (atomic_dec_and_test(&dev->nstreams))
1882 static int uvc_register_video(struct uvc_device *dev,
1883 struct uvc_streaming *stream)
1885 struct video_device *vdev = &stream->vdev;
1888 /* Initialize the video buffers queue. */
1889 ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1893 /* Initialize the streaming interface with default streaming
1896 ret = uvc_video_init(stream);
1898 uvc_printk(KERN_ERR, "Failed to initialize the device "
1903 uvc_debugfs_init_stream(stream);
1905 /* Register the device with V4L. */
1907 /* We already hold a reference to dev->udev. The video device will be
1908 * unregistered before the reference is released, so we don't need to
1911 vdev->v4l2_dev = &dev->vdev;
1912 vdev->fops = &uvc_fops;
1913 vdev->ioctl_ops = &uvc_ioctl_ops;
1914 vdev->release = uvc_release;
1915 vdev->prio = &stream->chain->prio;
1916 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1917 vdev->vfl_dir = VFL_DIR_TX;
1918 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1920 /* Set the driver data before calling video_register_device, otherwise
1921 * uvc_v4l2_open might race us.
1923 video_set_drvdata(vdev, stream);
1925 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1927 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1932 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1933 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1935 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1937 atomic_inc(&dev->nstreams);
1942 * Register all video devices in all chains.
1944 static int uvc_register_terms(struct uvc_device *dev,
1945 struct uvc_video_chain *chain)
1947 struct uvc_streaming *stream;
1948 struct uvc_entity *term;
1951 list_for_each_entry(term, &chain->entities, chain) {
1952 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1955 stream = uvc_stream_by_id(dev, term->id);
1956 if (stream == NULL) {
1957 uvc_printk(KERN_INFO, "No streaming interface found "
1958 "for terminal %u.", term->id);
1962 stream->chain = chain;
1963 ret = uvc_register_video(dev, stream);
1967 term->vdev = &stream->vdev;
1973 static int uvc_register_chains(struct uvc_device *dev)
1975 struct uvc_video_chain *chain;
1978 list_for_each_entry(chain, &dev->chains, list) {
1979 ret = uvc_register_terms(dev, chain);
1983 #ifdef CONFIG_MEDIA_CONTROLLER
1984 ret = uvc_mc_register_entities(chain);
1986 uvc_printk(KERN_INFO, "Failed to register entites "
1995 /* ------------------------------------------------------------------------
1996 * USB probe, disconnect, suspend and resume
1999 static int uvc_probe(struct usb_interface *intf,
2000 const struct usb_device_id *id)
2002 struct usb_device *udev = interface_to_usbdev(intf);
2003 struct uvc_device *dev;
2006 if (id->idVendor && id->idProduct)
2007 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
2008 "(%04x:%04x)\n", udev->devpath, id->idVendor,
2011 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
2014 /* Allocate memory for the device and initialize it. */
2015 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
2018 INIT_LIST_HEAD(&dev->entities);
2019 INIT_LIST_HEAD(&dev->chains);
2020 INIT_LIST_HEAD(&dev->streams);
2021 atomic_set(&dev->nstreams, 0);
2022 atomic_set(&dev->nmappings, 0);
2023 mutex_init(&dev->lock);
2025 dev->udev = usb_get_dev(udev);
2026 dev->intf = usb_get_intf(intf);
2027 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2028 dev->quirks = (uvc_quirks_param == -1)
2029 ? id->driver_info : uvc_quirks_param;
2031 if (udev->product != NULL)
2032 strlcpy(dev->name, udev->product, sizeof dev->name);
2034 snprintf(dev->name, sizeof dev->name,
2035 "UVC Camera (%04x:%04x)",
2036 le16_to_cpu(udev->descriptor.idVendor),
2037 le16_to_cpu(udev->descriptor.idProduct));
2039 /* Initialize the media device. */
2040 #ifdef CONFIG_MEDIA_CONTROLLER
2041 dev->mdev.dev = &intf->dev;
2042 strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2044 strscpy(dev->mdev.serial, udev->serial,
2045 sizeof(dev->mdev.serial));
2046 usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2047 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2048 dev->mdev.driver_version = LINUX_VERSION_CODE;
2049 media_device_init(&dev->mdev);
2051 dev->vdev.mdev = &dev->mdev;
2054 /* Parse the Video Class control descriptor. */
2055 if (uvc_parse_control(dev) < 0) {
2056 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
2061 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2062 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2063 udev->product ? udev->product : "<unnamed>",
2064 le16_to_cpu(udev->descriptor.idVendor),
2065 le16_to_cpu(udev->descriptor.idProduct));
2067 if (dev->quirks != id->driver_info) {
2068 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
2069 "parameter for testing purpose.\n", dev->quirks);
2070 uvc_printk(KERN_INFO, "Please report required quirks to the "
2071 "linux-uvc-devel mailing list.\n");
2074 /* Register the V4L2 device. */
2075 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2078 /* Initialize controls. */
2079 if (uvc_ctrl_init_device(dev) < 0)
2082 /* Scan the device for video chains. */
2083 if (uvc_scan_device(dev) < 0)
2086 /* Register video device nodes. */
2087 if (uvc_register_chains(dev) < 0)
2090 #ifdef CONFIG_MEDIA_CONTROLLER
2091 /* Register the media device node */
2092 if (media_device_register(&dev->mdev) < 0)
2095 /* Save our data pointer in the interface data. */
2096 usb_set_intfdata(intf, dev);
2098 /* Initialize the interrupt URB. */
2099 if ((ret = uvc_status_init(dev)) < 0) {
2100 uvc_printk(KERN_INFO, "Unable to initialize the status "
2101 "endpoint (%d), status interrupt will not be "
2102 "supported.\n", ret);
2105 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
2106 usb_enable_autosuspend(udev);
2110 uvc_unregister_video(dev);
2114 static void uvc_disconnect(struct usb_interface *intf)
2116 struct uvc_device *dev = usb_get_intfdata(intf);
2118 /* Set the USB interface data to NULL. This can be done outside the
2119 * lock, as there's no other reader.
2121 usb_set_intfdata(intf, NULL);
2123 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2124 UVC_SC_VIDEOSTREAMING)
2127 uvc_unregister_video(dev);
2130 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2132 struct uvc_device *dev = usb_get_intfdata(intf);
2133 struct uvc_streaming *stream;
2135 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2136 intf->cur_altsetting->desc.bInterfaceNumber);
2138 /* Controls are cached on the fly so they don't need to be saved. */
2139 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2140 UVC_SC_VIDEOCONTROL) {
2141 mutex_lock(&dev->lock);
2143 uvc_status_stop(dev);
2144 mutex_unlock(&dev->lock);
2148 list_for_each_entry(stream, &dev->streams, list) {
2149 if (stream->intf == intf)
2150 return uvc_video_suspend(stream);
2153 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2158 static int __uvc_resume(struct usb_interface *intf, int reset)
2160 struct uvc_device *dev = usb_get_intfdata(intf);
2161 struct uvc_streaming *stream;
2164 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2165 intf->cur_altsetting->desc.bInterfaceNumber);
2167 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2168 UVC_SC_VIDEOCONTROL) {
2170 ret = uvc_ctrl_restore_values(dev);
2175 mutex_lock(&dev->lock);
2177 ret = uvc_status_start(dev, GFP_NOIO);
2178 mutex_unlock(&dev->lock);
2183 list_for_each_entry(stream, &dev->streams, list) {
2184 if (stream->intf == intf) {
2185 ret = uvc_video_resume(stream, reset);
2187 uvc_queue_streamoff(&stream->queue,
2188 stream->queue.queue.type);
2193 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2198 static int uvc_resume(struct usb_interface *intf)
2200 return __uvc_resume(intf, 0);
2203 static int uvc_reset_resume(struct usb_interface *intf)
2205 return __uvc_resume(intf, 1);
2208 /* ------------------------------------------------------------------------
2212 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
2214 if (uvc_clock_param == CLOCK_MONOTONIC)
2215 return sprintf(buffer, "CLOCK_MONOTONIC");
2217 return sprintf(buffer, "CLOCK_REALTIME");
2220 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
2222 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2223 val += strlen("clock_");
2225 if (strcasecmp(val, "monotonic") == 0)
2226 uvc_clock_param = CLOCK_MONOTONIC;
2227 else if (strcasecmp(val, "realtime") == 0)
2228 uvc_clock_param = CLOCK_REALTIME;
2235 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2236 &uvc_clock_param, S_IRUGO|S_IWUSR);
2237 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2238 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2239 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2240 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2241 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2242 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2243 MODULE_PARM_DESC(quirks, "Forced device quirks");
2244 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2245 MODULE_PARM_DESC(trace, "Trace level bitmask");
2246 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2247 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2249 /* ------------------------------------------------------------------------
2250 * Driver initialization and cleanup
2254 * The Logitech cameras listed below have their interface class set to
2255 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2256 * though they are compliant.
2258 static struct usb_device_id uvc_ids[] = {
2259 /* LogiLink Wireless Webcam */
2260 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2261 | USB_DEVICE_ID_MATCH_INT_INFO,
2263 .idProduct = 0xa91a,
2264 .bInterfaceClass = USB_CLASS_VIDEO,
2265 .bInterfaceSubClass = 1,
2266 .bInterfaceProtocol = 0,
2267 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2268 /* Genius eFace 2025 */
2269 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2270 | USB_DEVICE_ID_MATCH_INT_INFO,
2272 .idProduct = 0x706e,
2273 .bInterfaceClass = USB_CLASS_VIDEO,
2274 .bInterfaceSubClass = 1,
2275 .bInterfaceProtocol = 0,
2276 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2277 /* Microsoft Lifecam NX-6000 */
2278 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2279 | USB_DEVICE_ID_MATCH_INT_INFO,
2281 .idProduct = 0x00f8,
2282 .bInterfaceClass = USB_CLASS_VIDEO,
2283 .bInterfaceSubClass = 1,
2284 .bInterfaceProtocol = 0,
2285 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2286 /* Microsoft Lifecam NX-3000 */
2287 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2288 | USB_DEVICE_ID_MATCH_INT_INFO,
2290 .idProduct = 0x0721,
2291 .bInterfaceClass = USB_CLASS_VIDEO,
2292 .bInterfaceSubClass = 1,
2293 .bInterfaceProtocol = 0,
2294 .driver_info = UVC_QUIRK_PROBE_DEF },
2295 /* Microsoft Lifecam VX-7000 */
2296 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2297 | USB_DEVICE_ID_MATCH_INT_INFO,
2299 .idProduct = 0x0723,
2300 .bInterfaceClass = USB_CLASS_VIDEO,
2301 .bInterfaceSubClass = 1,
2302 .bInterfaceProtocol = 0,
2303 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2304 /* Logitech Quickcam Fusion */
2305 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2306 | USB_DEVICE_ID_MATCH_INT_INFO,
2308 .idProduct = 0x08c1,
2309 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2310 .bInterfaceSubClass = 1,
2311 .bInterfaceProtocol = 0 },
2312 /* Logitech Quickcam Orbit MP */
2313 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2314 | USB_DEVICE_ID_MATCH_INT_INFO,
2316 .idProduct = 0x08c2,
2317 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2318 .bInterfaceSubClass = 1,
2319 .bInterfaceProtocol = 0 },
2320 /* Logitech Quickcam Pro for Notebook */
2321 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2322 | USB_DEVICE_ID_MATCH_INT_INFO,
2324 .idProduct = 0x08c3,
2325 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2326 .bInterfaceSubClass = 1,
2327 .bInterfaceProtocol = 0 },
2328 /* Logitech Quickcam Pro 5000 */
2329 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2330 | USB_DEVICE_ID_MATCH_INT_INFO,
2332 .idProduct = 0x08c5,
2333 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2334 .bInterfaceSubClass = 1,
2335 .bInterfaceProtocol = 0 },
2336 /* Logitech Quickcam OEM Dell Notebook */
2337 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2338 | USB_DEVICE_ID_MATCH_INT_INFO,
2340 .idProduct = 0x08c6,
2341 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2342 .bInterfaceSubClass = 1,
2343 .bInterfaceProtocol = 0 },
2344 /* Logitech Quickcam OEM Cisco VT Camera II */
2345 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2346 | USB_DEVICE_ID_MATCH_INT_INFO,
2348 .idProduct = 0x08c7,
2349 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2350 .bInterfaceSubClass = 1,
2351 .bInterfaceProtocol = 0 },
2352 /* Logitech HD Pro Webcam C920 */
2353 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2354 | USB_DEVICE_ID_MATCH_INT_INFO,
2356 .idProduct = 0x082d,
2357 .bInterfaceClass = USB_CLASS_VIDEO,
2358 .bInterfaceSubClass = 1,
2359 .bInterfaceProtocol = 0,
2360 .driver_info = UVC_QUIRK_RESTORE_CTRLS_ON_INIT },
2361 /* Chicony CNF7129 (Asus EEE 100HE) */
2362 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2363 | USB_DEVICE_ID_MATCH_INT_INFO,
2365 .idProduct = 0xb071,
2366 .bInterfaceClass = USB_CLASS_VIDEO,
2367 .bInterfaceSubClass = 1,
2368 .bInterfaceProtocol = 0,
2369 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2370 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2371 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2372 | USB_DEVICE_ID_MATCH_INT_INFO,
2374 .idProduct = 0x3820,
2375 .bInterfaceClass = USB_CLASS_VIDEO,
2376 .bInterfaceSubClass = 1,
2377 .bInterfaceProtocol = 0,
2378 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2379 /* Dell XPS m1530 */
2380 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2381 | USB_DEVICE_ID_MATCH_INT_INFO,
2383 .idProduct = 0x2640,
2384 .bInterfaceClass = USB_CLASS_VIDEO,
2385 .bInterfaceSubClass = 1,
2386 .bInterfaceProtocol = 0,
2387 .driver_info = UVC_QUIRK_PROBE_DEF },
2388 /* Dell SP2008WFP Monitor */
2389 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2390 | USB_DEVICE_ID_MATCH_INT_INFO,
2392 .idProduct = 0x2641,
2393 .bInterfaceClass = USB_CLASS_VIDEO,
2394 .bInterfaceSubClass = 1,
2395 .bInterfaceProtocol = 0,
2396 .driver_info = UVC_QUIRK_PROBE_DEF },
2397 /* Dell Alienware X51 */
2398 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2399 | USB_DEVICE_ID_MATCH_INT_INFO,
2401 .idProduct = 0x2643,
2402 .bInterfaceClass = USB_CLASS_VIDEO,
2403 .bInterfaceSubClass = 1,
2404 .bInterfaceProtocol = 0,
2405 .driver_info = UVC_QUIRK_PROBE_DEF },
2406 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2407 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2408 | USB_DEVICE_ID_MATCH_INT_INFO,
2410 .idProduct = 0x264a,
2411 .bInterfaceClass = USB_CLASS_VIDEO,
2412 .bInterfaceSubClass = 1,
2413 .bInterfaceProtocol = 0,
2414 .driver_info = UVC_QUIRK_PROBE_DEF },
2415 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2416 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2417 | USB_DEVICE_ID_MATCH_INT_INFO,
2419 .idProduct = 0x7670,
2420 .bInterfaceClass = USB_CLASS_VIDEO,
2421 .bInterfaceSubClass = 1,
2422 .bInterfaceProtocol = 0,
2423 .driver_info = UVC_QUIRK_PROBE_DEF },
2424 /* Apple Built-In iSight */
2425 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2426 | USB_DEVICE_ID_MATCH_INT_INFO,
2428 .idProduct = 0x8501,
2429 .bInterfaceClass = USB_CLASS_VIDEO,
2430 .bInterfaceSubClass = 1,
2431 .bInterfaceProtocol = 0,
2432 .driver_info = UVC_QUIRK_PROBE_MINMAX
2433 | UVC_QUIRK_BUILTIN_ISIGHT },
2434 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2435 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2436 | USB_DEVICE_ID_MATCH_INT_INFO,
2438 .idProduct = 0x0403,
2439 .bInterfaceClass = USB_CLASS_VIDEO,
2440 .bInterfaceSubClass = 1,
2441 .bInterfaceProtocol = 0,
2442 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2443 /* Genesys Logic USB 2.0 PC Camera */
2444 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2445 | USB_DEVICE_ID_MATCH_INT_INFO,
2447 .idProduct = 0x0505,
2448 .bInterfaceClass = USB_CLASS_VIDEO,
2449 .bInterfaceSubClass = 1,
2450 .bInterfaceProtocol = 0,
2451 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2452 /* Hercules Classic Silver */
2453 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2454 | USB_DEVICE_ID_MATCH_INT_INFO,
2456 .idProduct = 0x300c,
2457 .bInterfaceClass = USB_CLASS_VIDEO,
2458 .bInterfaceSubClass = 1,
2459 .bInterfaceProtocol = 0,
2460 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2462 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2463 | USB_DEVICE_ID_MATCH_INT_INFO,
2465 .idProduct = 0x332d,
2466 .bInterfaceClass = USB_CLASS_VIDEO,
2467 .bInterfaceSubClass = 1,
2468 .bInterfaceProtocol = 0,
2469 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2470 /* ViMicro - Minoru3D */
2471 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2472 | USB_DEVICE_ID_MATCH_INT_INFO,
2474 .idProduct = 0x3410,
2475 .bInterfaceClass = USB_CLASS_VIDEO,
2476 .bInterfaceSubClass = 1,
2477 .bInterfaceProtocol = 0,
2478 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2479 /* ViMicro Venus - Minoru3D */
2480 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2481 | USB_DEVICE_ID_MATCH_INT_INFO,
2483 .idProduct = 0x3420,
2484 .bInterfaceClass = USB_CLASS_VIDEO,
2485 .bInterfaceSubClass = 1,
2486 .bInterfaceProtocol = 0,
2487 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2488 /* Ophir Optronics - SPCAM 620U */
2489 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2490 | USB_DEVICE_ID_MATCH_INT_INFO,
2492 .idProduct = 0x0555,
2493 .bInterfaceClass = USB_CLASS_VIDEO,
2494 .bInterfaceSubClass = 1,
2495 .bInterfaceProtocol = 0,
2496 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2498 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2499 | USB_DEVICE_ID_MATCH_INT_INFO,
2501 .idProduct = 0x0004,
2502 .bInterfaceClass = USB_CLASS_VIDEO,
2503 .bInterfaceSubClass = 1,
2504 .bInterfaceProtocol = 0,
2505 .driver_info = UVC_QUIRK_PROBE_MINMAX
2506 | UVC_QUIRK_PROBE_DEF },
2507 /* IMC Networks (Medion Akoya) */
2508 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2509 | USB_DEVICE_ID_MATCH_INT_INFO,
2511 .idProduct = 0x5103,
2512 .bInterfaceClass = USB_CLASS_VIDEO,
2513 .bInterfaceSubClass = 1,
2514 .bInterfaceProtocol = 0,
2515 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2516 /* JMicron USB2.0 XGA WebCam */
2517 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2518 | USB_DEVICE_ID_MATCH_INT_INFO,
2520 .idProduct = 0x0310,
2521 .bInterfaceClass = USB_CLASS_VIDEO,
2522 .bInterfaceSubClass = 1,
2523 .bInterfaceProtocol = 0,
2524 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2525 /* Syntek (HP Spartan) */
2526 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2527 | USB_DEVICE_ID_MATCH_INT_INFO,
2529 .idProduct = 0x5212,
2530 .bInterfaceClass = USB_CLASS_VIDEO,
2531 .bInterfaceSubClass = 1,
2532 .bInterfaceProtocol = 0,
2533 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2534 /* Syntek (Samsung Q310) */
2535 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2536 | USB_DEVICE_ID_MATCH_INT_INFO,
2538 .idProduct = 0x5931,
2539 .bInterfaceClass = USB_CLASS_VIDEO,
2540 .bInterfaceSubClass = 1,
2541 .bInterfaceProtocol = 0,
2542 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2543 /* Syntek (Packard Bell EasyNote MX52 */
2544 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2545 | USB_DEVICE_ID_MATCH_INT_INFO,
2547 .idProduct = 0x8a12,
2548 .bInterfaceClass = USB_CLASS_VIDEO,
2549 .bInterfaceSubClass = 1,
2550 .bInterfaceProtocol = 0,
2551 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2552 /* Syntek (Asus F9SG) */
2553 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2554 | USB_DEVICE_ID_MATCH_INT_INFO,
2556 .idProduct = 0x8a31,
2557 .bInterfaceClass = USB_CLASS_VIDEO,
2558 .bInterfaceSubClass = 1,
2559 .bInterfaceProtocol = 0,
2560 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2561 /* Syntek (Asus U3S) */
2562 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2563 | USB_DEVICE_ID_MATCH_INT_INFO,
2565 .idProduct = 0x8a33,
2566 .bInterfaceClass = USB_CLASS_VIDEO,
2567 .bInterfaceSubClass = 1,
2568 .bInterfaceProtocol = 0,
2569 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2570 /* Syntek (JAOtech Smart Terminal) */
2571 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2572 | USB_DEVICE_ID_MATCH_INT_INFO,
2574 .idProduct = 0x8a34,
2575 .bInterfaceClass = USB_CLASS_VIDEO,
2576 .bInterfaceSubClass = 1,
2577 .bInterfaceProtocol = 0,
2578 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2580 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2581 | USB_DEVICE_ID_MATCH_INT_INFO,
2583 .idProduct = 0x0202,
2584 .bInterfaceClass = USB_CLASS_VIDEO,
2585 .bInterfaceSubClass = 1,
2586 .bInterfaceProtocol = 0,
2587 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2588 /* Lenovo Thinkpad SL400/SL500 */
2589 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2590 | USB_DEVICE_ID_MATCH_INT_INFO,
2592 .idProduct = 0x480b,
2593 .bInterfaceClass = USB_CLASS_VIDEO,
2594 .bInterfaceSubClass = 1,
2595 .bInterfaceProtocol = 0,
2596 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2597 /* Aveo Technology USB 2.0 Camera */
2598 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2599 | USB_DEVICE_ID_MATCH_INT_INFO,
2601 .idProduct = 0x0306,
2602 .bInterfaceClass = USB_CLASS_VIDEO,
2603 .bInterfaceSubClass = 1,
2604 .bInterfaceProtocol = 0,
2605 .driver_info = UVC_QUIRK_PROBE_MINMAX
2606 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2607 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2608 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2609 | USB_DEVICE_ID_MATCH_INT_INFO,
2611 .idProduct = 0x0516,
2612 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2613 .bInterfaceSubClass = 1,
2614 .bInterfaceProtocol = 0 },
2615 /* Ecamm Pico iMage */
2616 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2617 | USB_DEVICE_ID_MATCH_INT_INFO,
2619 .idProduct = 0xcafe,
2620 .bInterfaceClass = USB_CLASS_VIDEO,
2621 .bInterfaceSubClass = 1,
2622 .bInterfaceProtocol = 0,
2623 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2624 /* Manta MM-353 Plako */
2625 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2626 | USB_DEVICE_ID_MATCH_INT_INFO,
2628 .idProduct = 0x3188,
2629 .bInterfaceClass = USB_CLASS_VIDEO,
2630 .bInterfaceSubClass = 1,
2631 .bInterfaceProtocol = 0,
2632 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2633 /* FSC WebCam V30S */
2634 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2635 | USB_DEVICE_ID_MATCH_INT_INFO,
2637 .idProduct = 0x3288,
2638 .bInterfaceClass = USB_CLASS_VIDEO,
2639 .bInterfaceSubClass = 1,
2640 .bInterfaceProtocol = 0,
2641 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2642 /* Arkmicro unbranded */
2643 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2644 | USB_DEVICE_ID_MATCH_INT_INFO,
2646 .idProduct = 0x3290,
2647 .bInterfaceClass = USB_CLASS_VIDEO,
2648 .bInterfaceSubClass = 1,
2649 .bInterfaceProtocol = 0,
2650 .driver_info = UVC_QUIRK_PROBE_DEF },
2651 /* The Imaging Source USB CCD cameras */
2652 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2653 | USB_DEVICE_ID_MATCH_INT_INFO,
2655 .idProduct = 0x8102,
2656 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2657 .bInterfaceSubClass = 1,
2658 .bInterfaceProtocol = 0 },
2659 /* Bodelin ProScopeHR */
2660 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2661 | USB_DEVICE_ID_MATCH_DEV_HI
2662 | USB_DEVICE_ID_MATCH_INT_INFO,
2664 .idProduct = 0x1000,
2665 .bcdDevice_hi = 0x0126,
2666 .bInterfaceClass = USB_CLASS_VIDEO,
2667 .bInterfaceSubClass = 1,
2668 .bInterfaceProtocol = 0,
2669 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2670 /* MSI StarCam 370i */
2671 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2672 | USB_DEVICE_ID_MATCH_INT_INFO,
2674 .idProduct = 0x2951,
2675 .bInterfaceClass = USB_CLASS_VIDEO,
2676 .bInterfaceSubClass = 1,
2677 .bInterfaceProtocol = 0,
2678 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2679 /* SiGma Micro USB Web Camera */
2680 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2681 | USB_DEVICE_ID_MATCH_INT_INFO,
2683 .idProduct = 0x3000,
2684 .bInterfaceClass = USB_CLASS_VIDEO,
2685 .bInterfaceSubClass = 1,
2686 .bInterfaceProtocol = 0,
2687 .driver_info = UVC_QUIRK_PROBE_MINMAX
2688 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2689 /* Oculus VR Positional Tracker DK2 */
2690 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2691 | USB_DEVICE_ID_MATCH_INT_INFO,
2693 .idProduct = 0x0201,
2694 .bInterfaceClass = USB_CLASS_VIDEO,
2695 .bInterfaceSubClass = 1,
2696 .bInterfaceProtocol = 0,
2697 .driver_info = UVC_QUIRK_FORCE_Y8 },
2698 /* Generic USB Video Class */
2699 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
2700 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
2704 MODULE_DEVICE_TABLE(usb, uvc_ids);
2706 struct uvc_driver uvc_driver = {
2710 .disconnect = uvc_disconnect,
2711 .suspend = uvc_suspend,
2712 .resume = uvc_resume,
2713 .reset_resume = uvc_reset_resume,
2714 .id_table = uvc_ids,
2715 .supports_autosuspend = 1,
2719 static int __init uvc_init(void)
2725 ret = usb_register(&uvc_driver.driver);
2727 uvc_debugfs_cleanup();
2731 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2735 static void __exit uvc_cleanup(void)
2737 usb_deregister(&uvc_driver.driver);
2738 uvc_debugfs_cleanup();
2741 module_init(uvc_init);
2742 module_exit(uvc_cleanup);
2744 MODULE_AUTHOR(DRIVER_AUTHOR);
2745 MODULE_DESCRIPTION(DRIVER_DESC);
2746 MODULE_LICENSE("GPL");
2747 MODULE_VERSION(DRIVER_VERSION);