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));
872 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
873 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
875 entity = kzalloc(size, GFP_KERNEL);
882 entity->num_links = 0;
883 entity->num_pads = num_pads;
884 entity->pads = ((void *)(entity + 1)) + extra_size;
886 for (i = 0; i < num_inputs; ++i)
887 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
888 if (!UVC_ENTITY_IS_OTERM(entity))
889 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
891 entity->bNrInPins = num_inputs;
892 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
897 /* Parse vendor-specific extensions. */
898 static int uvc_parse_vendor_control(struct uvc_device *dev,
899 const unsigned char *buffer, int buflen)
901 struct usb_device *udev = dev->udev;
902 struct usb_host_interface *alts = dev->intf->cur_altsetting;
903 struct uvc_entity *unit;
907 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
908 case 0x046d: /* Logitech */
909 if (buffer[1] != 0x41 || buffer[2] != 0x01)
912 /* Logitech implements several vendor specific functions
913 * through vendor specific extension units (LXU).
915 * The LXU descriptors are similar to XU descriptors
916 * (see "USB Device Video Class for Video Devices", section
917 * 3.7.2.6 "Extension Unit Descriptor") with the following
920 * ----------------------------------------------------------
922 * Size of this descriptor, in bytes: 24+p+n*2
923 * ----------------------------------------------------------
924 * 23+p+n bmControlsType N Bitmap
925 * Individual bits in the set are defined:
929 * This bitset is mapped exactly the same as bmControls.
930 * ----------------------------------------------------------
931 * 23+p+n*2 bReserved 1 Boolean
932 * ----------------------------------------------------------
933 * 24+p+n*2 iExtension 1 Index
934 * Index of a string descriptor that describes this
936 * ----------------------------------------------------------
938 p = buflen >= 22 ? buffer[21] : 0;
939 n = buflen >= 25 + p ? buffer[22+p] : 0;
941 if (buflen < 25 + p + 2*n) {
942 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
943 "interface %d EXTENSION_UNIT error\n",
944 udev->devnum, alts->desc.bInterfaceNumber);
948 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
953 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
954 unit->extension.bNumControls = buffer[20];
955 memcpy(unit->baSourceID, &buffer[22], p);
956 unit->extension.bControlSize = buffer[22+p];
957 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
958 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
960 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
962 if (buffer[24+p+2*n] != 0)
963 usb_string(udev, buffer[24+p+2*n], unit->name,
966 sprintf(unit->name, "Extension %u", buffer[3]);
968 list_add_tail(&unit->list, &dev->entities);
976 static int uvc_parse_standard_control(struct uvc_device *dev,
977 const unsigned char *buffer, int buflen)
979 struct usb_device *udev = dev->udev;
980 struct uvc_entity *unit, *term;
981 struct usb_interface *intf;
982 struct usb_host_interface *alts = dev->intf->cur_altsetting;
983 unsigned int i, n, p, len;
988 n = buflen >= 12 ? buffer[11] : 0;
990 if (buflen < 12 + n) {
991 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
992 "interface %d HEADER error\n", udev->devnum,
993 alts->desc.bInterfaceNumber);
997 dev->uvc_version = get_unaligned_le16(&buffer[3]);
998 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
1000 /* Parse all USB Video Streaming interfaces. */
1001 for (i = 0; i < n; ++i) {
1002 intf = usb_ifnum_to_if(udev, buffer[12+i]);
1004 uvc_trace(UVC_TRACE_DESCR, "device %d "
1005 "interface %d doesn't exists\n",
1010 uvc_parse_streaming(dev, intf);
1014 case UVC_VC_INPUT_TERMINAL:
1016 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1017 "interface %d INPUT_TERMINAL error\n",
1018 udev->devnum, alts->desc.bInterfaceNumber);
1023 * Reject invalid terminal types that would cause issues:
1025 * - The high byte must be non-zero, otherwise it would be
1026 * confused with a unit.
1028 * - Bit 15 must be 0, as we use it internally as a terminal
1031 * Other unknown types are accepted.
1033 type = get_unaligned_le16(&buffer[4]);
1034 if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
1035 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1036 "interface %d INPUT_TERMINAL %d has invalid "
1037 "type 0x%04x, skipping\n", udev->devnum,
1038 alts->desc.bInterfaceNumber,
1047 if (type == UVC_ITT_CAMERA) {
1048 n = buflen >= 15 ? buffer[14] : 0;
1051 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1052 n = buflen >= 9 ? buffer[8] : 0;
1053 p = buflen >= 10 + n ? buffer[9+n] : 0;
1057 if (buflen < len + n + p) {
1058 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1059 "interface %d INPUT_TERMINAL error\n",
1060 udev->devnum, alts->desc.bInterfaceNumber);
1064 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1069 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1070 term->camera.bControlSize = n;
1071 term->camera.bmControls = (__u8 *)term + sizeof *term;
1072 term->camera.wObjectiveFocalLengthMin =
1073 get_unaligned_le16(&buffer[8]);
1074 term->camera.wObjectiveFocalLengthMax =
1075 get_unaligned_le16(&buffer[10]);
1076 term->camera.wOcularFocalLength =
1077 get_unaligned_le16(&buffer[12]);
1078 memcpy(term->camera.bmControls, &buffer[15], n);
1079 } else if (UVC_ENTITY_TYPE(term) ==
1080 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1081 term->media.bControlSize = n;
1082 term->media.bmControls = (__u8 *)term + sizeof *term;
1083 term->media.bTransportModeSize = p;
1084 term->media.bmTransportModes = (__u8 *)term
1086 memcpy(term->media.bmControls, &buffer[9], n);
1087 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1091 usb_string(udev, buffer[7], term->name,
1093 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1094 sprintf(term->name, "Camera %u", buffer[3]);
1095 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1096 sprintf(term->name, "Media %u", buffer[3]);
1098 sprintf(term->name, "Input %u", buffer[3]);
1100 list_add_tail(&term->list, &dev->entities);
1103 case UVC_VC_OUTPUT_TERMINAL:
1105 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1106 "interface %d OUTPUT_TERMINAL error\n",
1107 udev->devnum, alts->desc.bInterfaceNumber);
1111 /* Make sure the terminal type MSB is not null, otherwise it
1112 * could be confused with a unit.
1114 type = get_unaligned_le16(&buffer[4]);
1115 if ((type & 0xff00) == 0) {
1116 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1117 "interface %d OUTPUT_TERMINAL %d has invalid "
1118 "type 0x%04x, skipping\n", udev->devnum,
1119 alts->desc.bInterfaceNumber, buffer[3], type);
1123 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1128 memcpy(term->baSourceID, &buffer[7], 1);
1131 usb_string(udev, buffer[8], term->name,
1134 sprintf(term->name, "Output %u", buffer[3]);
1136 list_add_tail(&term->list, &dev->entities);
1139 case UVC_VC_SELECTOR_UNIT:
1140 p = buflen >= 5 ? buffer[4] : 0;
1142 if (buflen < 5 || buflen < 6 + p) {
1143 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1144 "interface %d SELECTOR_UNIT error\n",
1145 udev->devnum, alts->desc.bInterfaceNumber);
1149 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1153 memcpy(unit->baSourceID, &buffer[5], p);
1155 if (buffer[5+p] != 0)
1156 usb_string(udev, buffer[5+p], unit->name,
1159 sprintf(unit->name, "Selector %u", buffer[3]);
1161 list_add_tail(&unit->list, &dev->entities);
1164 case UVC_VC_PROCESSING_UNIT:
1165 n = buflen >= 8 ? buffer[7] : 0;
1166 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1168 if (buflen < p + n) {
1169 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1170 "interface %d PROCESSING_UNIT error\n",
1171 udev->devnum, alts->desc.bInterfaceNumber);
1175 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1179 memcpy(unit->baSourceID, &buffer[4], 1);
1180 unit->processing.wMaxMultiplier =
1181 get_unaligned_le16(&buffer[5]);
1182 unit->processing.bControlSize = buffer[7];
1183 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1184 memcpy(unit->processing.bmControls, &buffer[8], n);
1185 if (dev->uvc_version >= 0x0110)
1186 unit->processing.bmVideoStandards = buffer[9+n];
1188 if (buffer[8+n] != 0)
1189 usb_string(udev, buffer[8+n], unit->name,
1192 sprintf(unit->name, "Processing %u", buffer[3]);
1194 list_add_tail(&unit->list, &dev->entities);
1197 case UVC_VC_EXTENSION_UNIT:
1198 p = buflen >= 22 ? buffer[21] : 0;
1199 n = buflen >= 24 + p ? buffer[22+p] : 0;
1201 if (buflen < 24 + p + n) {
1202 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1203 "interface %d EXTENSION_UNIT error\n",
1204 udev->devnum, alts->desc.bInterfaceNumber);
1208 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1212 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1213 unit->extension.bNumControls = buffer[20];
1214 memcpy(unit->baSourceID, &buffer[22], p);
1215 unit->extension.bControlSize = buffer[22+p];
1216 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1217 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1219 if (buffer[23+p+n] != 0)
1220 usb_string(udev, buffer[23+p+n], unit->name,
1223 sprintf(unit->name, "Extension %u", buffer[3]);
1225 list_add_tail(&unit->list, &dev->entities);
1229 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1230 "descriptor (%u)\n", buffer[2]);
1237 static int uvc_parse_control(struct uvc_device *dev)
1239 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1240 unsigned char *buffer = alts->extra;
1241 int buflen = alts->extralen;
1244 /* Parse the default alternate setting only, as the UVC specification
1245 * defines a single alternate setting, the default alternate setting
1249 while (buflen > 2) {
1250 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1251 buffer[1] != USB_DT_CS_INTERFACE)
1252 goto next_descriptor;
1254 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1258 buflen -= buffer[0];
1259 buffer += buffer[0];
1262 /* Check if the optional status endpoint is present. Built-in iSight
1263 * webcams have an interrupt endpoint but spit proprietary data that
1264 * don't conform to the UVC status endpoint messages. Don't try to
1265 * handle the interrupt endpoint for those cameras.
1267 if (alts->desc.bNumEndpoints == 1 &&
1268 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1269 struct usb_host_endpoint *ep = &alts->endpoint[0];
1270 struct usb_endpoint_descriptor *desc = &ep->desc;
1272 if (usb_endpoint_is_int_in(desc) &&
1273 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1274 desc->bInterval != 0) {
1275 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1276 "(addr %02x).\n", desc->bEndpointAddress);
1284 /* ------------------------------------------------------------------------
1289 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1290 * and containing the following units:
1292 * - one or more Output Terminals (USB Streaming or Display)
1293 * - zero or one Processing Unit
1294 * - zero, one or more single-input Selector Units
1295 * - zero or one multiple-input Selector Units, provided all inputs are
1296 * connected to input terminals
1297 * - zero, one or mode single-input Extension Units
1298 * - one or more Input Terminals (Camera, External or USB Streaming)
1300 * The terminal and units must match on of the following structures:
1302 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1303 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1304 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1306 * +---------+ +---------+ -> OTT_*(0)
1307 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1308 * +---------+ +---------+ -> OTT_*(n)
1310 * The Processing Unit and Extension Units can be in any order. Additional
1311 * Extension Units connected to the main chain as single-unit branches are
1312 * also supported. Single-input Selector Units are ignored.
1314 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1315 struct uvc_entity *entity)
1317 switch (UVC_ENTITY_TYPE(entity)) {
1318 case UVC_VC_EXTENSION_UNIT:
1319 if (uvc_trace_param & UVC_TRACE_PROBE)
1320 printk(" <- XU %d", entity->id);
1322 if (entity->bNrInPins != 1) {
1323 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1324 "than 1 input pin.\n", entity->id);
1330 case UVC_VC_PROCESSING_UNIT:
1331 if (uvc_trace_param & UVC_TRACE_PROBE)
1332 printk(" <- PU %d", entity->id);
1334 if (chain->processing != NULL) {
1335 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1336 "Processing Units in chain.\n");
1340 chain->processing = entity;
1343 case UVC_VC_SELECTOR_UNIT:
1344 if (uvc_trace_param & UVC_TRACE_PROBE)
1345 printk(" <- SU %d", entity->id);
1347 /* Single-input selector units are ignored. */
1348 if (entity->bNrInPins == 1)
1351 if (chain->selector != NULL) {
1352 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1353 "Units in chain.\n");
1357 chain->selector = entity;
1360 case UVC_ITT_VENDOR_SPECIFIC:
1361 case UVC_ITT_CAMERA:
1362 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1363 if (uvc_trace_param & UVC_TRACE_PROBE)
1364 printk(" <- IT %d\n", entity->id);
1368 case UVC_OTT_VENDOR_SPECIFIC:
1369 case UVC_OTT_DISPLAY:
1370 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1371 if (uvc_trace_param & UVC_TRACE_PROBE)
1372 printk(" OT %d", entity->id);
1376 case UVC_TT_STREAMING:
1377 if (UVC_ENTITY_IS_ITERM(entity)) {
1378 if (uvc_trace_param & UVC_TRACE_PROBE)
1379 printk(" <- IT %d\n", entity->id);
1381 if (uvc_trace_param & UVC_TRACE_PROBE)
1382 printk(" OT %d", entity->id);
1388 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1389 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1393 list_add_tail(&entity->chain, &chain->entities);
1397 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1398 struct uvc_entity *entity, struct uvc_entity *prev)
1400 struct uvc_entity *forward;
1408 forward = uvc_entity_by_reference(chain->dev, entity->id,
1410 if (forward == NULL)
1412 if (forward == prev)
1414 if (forward->chain.next || forward->chain.prev) {
1415 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1416 "entity %d already in chain.\n", forward->id);
1420 switch (UVC_ENTITY_TYPE(forward)) {
1421 case UVC_VC_EXTENSION_UNIT:
1422 if (forward->bNrInPins != 1) {
1423 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1424 "has more than 1 input pin.\n",
1429 list_add_tail(&forward->chain, &chain->entities);
1430 if (uvc_trace_param & UVC_TRACE_PROBE) {
1434 printk(" XU %d", forward->id);
1439 case UVC_OTT_VENDOR_SPECIFIC:
1440 case UVC_OTT_DISPLAY:
1441 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1442 case UVC_TT_STREAMING:
1443 if (UVC_ENTITY_IS_ITERM(forward)) {
1444 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1445 "terminal %u.\n", forward->id);
1449 list_add_tail(&forward->chain, &chain->entities);
1450 if (uvc_trace_param & UVC_TRACE_PROBE) {
1454 printk(" OT %d", forward->id);
1466 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1467 struct uvc_entity **_entity)
1469 struct uvc_entity *entity = *_entity;
1470 struct uvc_entity *term;
1471 int id = -EINVAL, i;
1473 switch (UVC_ENTITY_TYPE(entity)) {
1474 case UVC_VC_EXTENSION_UNIT:
1475 case UVC_VC_PROCESSING_UNIT:
1476 id = entity->baSourceID[0];
1479 case UVC_VC_SELECTOR_UNIT:
1480 /* Single-input selector units are ignored. */
1481 if (entity->bNrInPins == 1) {
1482 id = entity->baSourceID[0];
1486 if (uvc_trace_param & UVC_TRACE_PROBE)
1489 chain->selector = entity;
1490 for (i = 0; i < entity->bNrInPins; ++i) {
1491 id = entity->baSourceID[i];
1492 term = uvc_entity_by_id(chain->dev, id);
1493 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1494 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1495 "input %d isn't connected to an "
1496 "input terminal\n", entity->id, i);
1500 if (term->chain.next || term->chain.prev) {
1501 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1502 "entity %d already in chain.\n",
1507 if (uvc_trace_param & UVC_TRACE_PROBE)
1508 printk(" %d", term->id);
1510 list_add_tail(&term->chain, &chain->entities);
1511 uvc_scan_chain_forward(chain, term, entity);
1514 if (uvc_trace_param & UVC_TRACE_PROBE)
1520 case UVC_ITT_VENDOR_SPECIFIC:
1521 case UVC_ITT_CAMERA:
1522 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1523 case UVC_OTT_VENDOR_SPECIFIC:
1524 case UVC_OTT_DISPLAY:
1525 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1526 case UVC_TT_STREAMING:
1527 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1536 entity = uvc_entity_by_id(chain->dev, id);
1537 if (entity == NULL) {
1538 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1539 "unknown entity %d.\n", id);
1547 static int uvc_scan_chain(struct uvc_video_chain *chain,
1548 struct uvc_entity *term)
1550 struct uvc_entity *entity, *prev;
1552 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1557 while (entity != NULL) {
1558 /* Entity must not be part of an existing chain */
1559 if (entity->chain.next || entity->chain.prev) {
1560 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1561 "entity %d already in chain.\n", entity->id);
1565 /* Process entity */
1566 if (uvc_scan_chain_entity(chain, entity) < 0)
1570 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1575 if (uvc_scan_chain_backward(chain, &entity) < 0)
1582 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1585 struct uvc_entity *term;
1586 unsigned int nterms = 0;
1589 list_for_each_entry(term, terms, chain) {
1590 if (!UVC_ENTITY_IS_TERM(term) ||
1591 UVC_TERM_DIRECTION(term) != dir)
1595 p += sprintf(p, ",");
1596 if (++nterms >= 4) {
1597 p += sprintf(p, "...");
1600 p += sprintf(p, "%u", term->id);
1606 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1608 static char buffer[43];
1611 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1612 p += sprintf(p, " -> ");
1613 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1618 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1620 struct uvc_video_chain *chain;
1622 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1626 INIT_LIST_HEAD(&chain->entities);
1627 mutex_init(&chain->ctrl_mutex);
1629 v4l2_prio_init(&chain->prio);
1635 * Fallback heuristic for devices that don't connect units and terminals in a
1638 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1639 * to fail, but if we just take the entities we can find and put them together
1640 * in the most sensible chain we can think of, turns out they do work anyway.
1641 * Note: This heuristic assumes there is a single chain.
1643 * At the time of writing, devices known to have such a broken chain are
1644 * - Acer Integrated Camera (5986:055a)
1645 * - Realtek rtl157a7 (0bda:57a7)
1647 static int uvc_scan_fallback(struct uvc_device *dev)
1649 struct uvc_video_chain *chain;
1650 struct uvc_entity *iterm = NULL;
1651 struct uvc_entity *oterm = NULL;
1652 struct uvc_entity *entity;
1653 struct uvc_entity *prev;
1656 * Start by locating the input and output terminals. We only support
1657 * devices with exactly one of each for now.
1659 list_for_each_entry(entity, &dev->entities, list) {
1660 if (UVC_ENTITY_IS_ITERM(entity)) {
1666 if (UVC_ENTITY_IS_OTERM(entity)) {
1673 if (iterm == NULL || oterm == NULL)
1676 /* Allocate the chain and fill it. */
1677 chain = uvc_alloc_chain(dev);
1681 if (uvc_scan_chain_entity(chain, oterm) < 0)
1687 * Add all Processing and Extension Units with two pads. The order
1688 * doesn't matter much, use reverse list traversal to connect units in
1689 * UVC descriptor order as we build the chain from output to input. This
1690 * leads to units appearing in the order meant by the manufacturer for
1691 * the cameras known to require this heuristic.
1693 list_for_each_entry_reverse(entity, &dev->entities, list) {
1694 if (entity->type != UVC_VC_PROCESSING_UNIT &&
1695 entity->type != UVC_VC_EXTENSION_UNIT)
1698 if (entity->num_pads != 2)
1701 if (uvc_scan_chain_entity(chain, entity) < 0)
1704 prev->baSourceID[0] = entity->id;
1708 if (uvc_scan_chain_entity(chain, iterm) < 0)
1711 prev->baSourceID[0] = iterm->id;
1713 list_add_tail(&chain->list, &dev->chains);
1715 uvc_trace(UVC_TRACE_PROBE,
1716 "Found a video chain by fallback heuristic (%s).\n",
1717 uvc_print_chain(chain));
1727 * Scan the device for video chains and register video devices.
1729 * Chains are scanned starting at their output terminals and walked backwards.
1731 static int uvc_scan_device(struct uvc_device *dev)
1733 struct uvc_video_chain *chain;
1734 struct uvc_entity *term;
1736 list_for_each_entry(term, &dev->entities, list) {
1737 if (!UVC_ENTITY_IS_OTERM(term))
1740 /* If the terminal is already included in a chain, skip it.
1741 * This can happen for chains that have multiple output
1742 * terminals, where all output terminals beside the first one
1743 * will be inserted in the chain in forward scans.
1745 if (term->chain.next || term->chain.prev)
1748 chain = uvc_alloc_chain(dev);
1752 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1754 if (uvc_scan_chain(chain, term) < 0) {
1759 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1760 uvc_print_chain(chain));
1762 list_add_tail(&chain->list, &dev->chains);
1765 if (list_empty(&dev->chains))
1766 uvc_scan_fallback(dev);
1768 if (list_empty(&dev->chains)) {
1769 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1776 /* ------------------------------------------------------------------------
1777 * Video device registration and unregistration
1781 * Delete the UVC device.
1783 * Called by the kernel when the last reference to the uvc_device structure
1786 * As this function is called after or during disconnect(), all URBs have
1787 * already been canceled by the USB core. There is no need to kill the
1788 * interrupt URB manually.
1790 static void uvc_delete(struct uvc_device *dev)
1792 struct list_head *p, *n;
1794 uvc_status_cleanup(dev);
1795 uvc_ctrl_cleanup_device(dev);
1797 usb_put_intf(dev->intf);
1798 usb_put_dev(dev->udev);
1801 v4l2_device_unregister(&dev->vdev);
1802 #ifdef CONFIG_MEDIA_CONTROLLER
1803 if (media_devnode_is_registered(dev->mdev.devnode))
1804 media_device_unregister(&dev->mdev);
1805 media_device_cleanup(&dev->mdev);
1808 list_for_each_safe(p, n, &dev->chains) {
1809 struct uvc_video_chain *chain;
1810 chain = list_entry(p, struct uvc_video_chain, list);
1814 list_for_each_safe(p, n, &dev->entities) {
1815 struct uvc_entity *entity;
1816 entity = list_entry(p, struct uvc_entity, list);
1817 #ifdef CONFIG_MEDIA_CONTROLLER
1818 uvc_mc_cleanup_entity(entity);
1823 list_for_each_safe(p, n, &dev->streams) {
1824 struct uvc_streaming *streaming;
1825 streaming = list_entry(p, struct uvc_streaming, list);
1826 usb_driver_release_interface(&uvc_driver.driver,
1828 usb_put_intf(streaming->intf);
1829 kfree(streaming->format);
1830 kfree(streaming->header.bmaControls);
1837 static void uvc_release(struct video_device *vdev)
1839 struct uvc_streaming *stream = video_get_drvdata(vdev);
1840 struct uvc_device *dev = stream->dev;
1842 /* Decrement the registered streams count and delete the device when it
1845 if (atomic_dec_and_test(&dev->nstreams))
1850 * Unregister the video devices.
1852 static void uvc_unregister_video(struct uvc_device *dev)
1854 struct uvc_streaming *stream;
1856 /* Unregistering all video devices might result in uvc_delete() being
1857 * called from inside the loop if there's no open file handle. To avoid
1858 * that, increment the stream count before iterating over the streams
1859 * and decrement it when done.
1861 atomic_inc(&dev->nstreams);
1863 list_for_each_entry(stream, &dev->streams, list) {
1864 if (!video_is_registered(&stream->vdev))
1867 video_unregister_device(&stream->vdev);
1869 uvc_debugfs_cleanup_stream(stream);
1872 /* Decrement the stream count and call uvc_delete explicitly if there
1873 * are no stream left.
1875 if (atomic_dec_and_test(&dev->nstreams))
1879 static int uvc_register_video(struct uvc_device *dev,
1880 struct uvc_streaming *stream)
1882 struct video_device *vdev = &stream->vdev;
1885 /* Initialize the video buffers queue. */
1886 ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1890 /* Initialize the streaming interface with default streaming
1893 ret = uvc_video_init(stream);
1895 uvc_printk(KERN_ERR, "Failed to initialize the device "
1900 uvc_debugfs_init_stream(stream);
1902 /* Register the device with V4L. */
1904 /* We already hold a reference to dev->udev. The video device will be
1905 * unregistered before the reference is released, so we don't need to
1908 vdev->v4l2_dev = &dev->vdev;
1909 vdev->fops = &uvc_fops;
1910 vdev->ioctl_ops = &uvc_ioctl_ops;
1911 vdev->release = uvc_release;
1912 vdev->prio = &stream->chain->prio;
1913 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1914 vdev->vfl_dir = VFL_DIR_TX;
1915 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1917 /* Set the driver data before calling video_register_device, otherwise
1918 * uvc_v4l2_open might race us.
1920 video_set_drvdata(vdev, stream);
1922 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1924 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1929 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1930 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1932 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1934 atomic_inc(&dev->nstreams);
1939 * Register all video devices in all chains.
1941 static int uvc_register_terms(struct uvc_device *dev,
1942 struct uvc_video_chain *chain)
1944 struct uvc_streaming *stream;
1945 struct uvc_entity *term;
1948 list_for_each_entry(term, &chain->entities, chain) {
1949 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1952 stream = uvc_stream_by_id(dev, term->id);
1953 if (stream == NULL) {
1954 uvc_printk(KERN_INFO, "No streaming interface found "
1955 "for terminal %u.", term->id);
1959 stream->chain = chain;
1960 ret = uvc_register_video(dev, stream);
1964 term->vdev = &stream->vdev;
1970 static int uvc_register_chains(struct uvc_device *dev)
1972 struct uvc_video_chain *chain;
1975 list_for_each_entry(chain, &dev->chains, list) {
1976 ret = uvc_register_terms(dev, chain);
1980 #ifdef CONFIG_MEDIA_CONTROLLER
1981 ret = uvc_mc_register_entities(chain);
1983 uvc_printk(KERN_INFO, "Failed to register entites "
1992 /* ------------------------------------------------------------------------
1993 * USB probe, disconnect, suspend and resume
1996 static int uvc_probe(struct usb_interface *intf,
1997 const struct usb_device_id *id)
1999 struct usb_device *udev = interface_to_usbdev(intf);
2000 struct uvc_device *dev;
2003 if (id->idVendor && id->idProduct)
2004 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
2005 "(%04x:%04x)\n", udev->devpath, id->idVendor,
2008 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
2011 /* Allocate memory for the device and initialize it. */
2012 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
2015 INIT_LIST_HEAD(&dev->entities);
2016 INIT_LIST_HEAD(&dev->chains);
2017 INIT_LIST_HEAD(&dev->streams);
2018 atomic_set(&dev->nstreams, 0);
2019 atomic_set(&dev->nmappings, 0);
2020 mutex_init(&dev->lock);
2022 dev->udev = usb_get_dev(udev);
2023 dev->intf = usb_get_intf(intf);
2024 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2025 dev->quirks = (uvc_quirks_param == -1)
2026 ? id->driver_info : uvc_quirks_param;
2028 if (udev->product != NULL)
2029 strlcpy(dev->name, udev->product, sizeof dev->name);
2031 snprintf(dev->name, sizeof dev->name,
2032 "UVC Camera (%04x:%04x)",
2033 le16_to_cpu(udev->descriptor.idVendor),
2034 le16_to_cpu(udev->descriptor.idProduct));
2036 /* Initialize the media device. */
2037 #ifdef CONFIG_MEDIA_CONTROLLER
2038 dev->mdev.dev = &intf->dev;
2039 strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2041 strscpy(dev->mdev.serial, udev->serial,
2042 sizeof(dev->mdev.serial));
2043 usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2044 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2045 dev->mdev.driver_version = LINUX_VERSION_CODE;
2046 media_device_init(&dev->mdev);
2048 dev->vdev.mdev = &dev->mdev;
2051 /* Parse the Video Class control descriptor. */
2052 if (uvc_parse_control(dev) < 0) {
2053 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
2058 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2059 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2060 udev->product ? udev->product : "<unnamed>",
2061 le16_to_cpu(udev->descriptor.idVendor),
2062 le16_to_cpu(udev->descriptor.idProduct));
2064 if (dev->quirks != id->driver_info) {
2065 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
2066 "parameter for testing purpose.\n", dev->quirks);
2067 uvc_printk(KERN_INFO, "Please report required quirks to the "
2068 "linux-uvc-devel mailing list.\n");
2071 /* Register the V4L2 device. */
2072 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2075 /* Initialize controls. */
2076 if (uvc_ctrl_init_device(dev) < 0)
2079 /* Scan the device for video chains. */
2080 if (uvc_scan_device(dev) < 0)
2083 /* Register video device nodes. */
2084 if (uvc_register_chains(dev) < 0)
2087 #ifdef CONFIG_MEDIA_CONTROLLER
2088 /* Register the media device node */
2089 if (media_device_register(&dev->mdev) < 0)
2092 /* Save our data pointer in the interface data. */
2093 usb_set_intfdata(intf, dev);
2095 /* Initialize the interrupt URB. */
2096 if ((ret = uvc_status_init(dev)) < 0) {
2097 uvc_printk(KERN_INFO, "Unable to initialize the status "
2098 "endpoint (%d), status interrupt will not be "
2099 "supported.\n", ret);
2102 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
2103 usb_enable_autosuspend(udev);
2107 uvc_unregister_video(dev);
2111 static void uvc_disconnect(struct usb_interface *intf)
2113 struct uvc_device *dev = usb_get_intfdata(intf);
2115 /* Set the USB interface data to NULL. This can be done outside the
2116 * lock, as there's no other reader.
2118 usb_set_intfdata(intf, NULL);
2120 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2121 UVC_SC_VIDEOSTREAMING)
2124 uvc_unregister_video(dev);
2127 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2129 struct uvc_device *dev = usb_get_intfdata(intf);
2130 struct uvc_streaming *stream;
2132 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2133 intf->cur_altsetting->desc.bInterfaceNumber);
2135 /* Controls are cached on the fly so they don't need to be saved. */
2136 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2137 UVC_SC_VIDEOCONTROL) {
2138 mutex_lock(&dev->lock);
2140 uvc_status_stop(dev);
2141 mutex_unlock(&dev->lock);
2145 list_for_each_entry(stream, &dev->streams, list) {
2146 if (stream->intf == intf)
2147 return uvc_video_suspend(stream);
2150 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2155 static int __uvc_resume(struct usb_interface *intf, int reset)
2157 struct uvc_device *dev = usb_get_intfdata(intf);
2158 struct uvc_streaming *stream;
2161 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2162 intf->cur_altsetting->desc.bInterfaceNumber);
2164 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2165 UVC_SC_VIDEOCONTROL) {
2167 ret = uvc_ctrl_restore_values(dev);
2172 mutex_lock(&dev->lock);
2174 ret = uvc_status_start(dev, GFP_NOIO);
2175 mutex_unlock(&dev->lock);
2180 list_for_each_entry(stream, &dev->streams, list) {
2181 if (stream->intf == intf) {
2182 ret = uvc_video_resume(stream, reset);
2184 uvc_queue_streamoff(&stream->queue,
2185 stream->queue.queue.type);
2190 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2195 static int uvc_resume(struct usb_interface *intf)
2197 return __uvc_resume(intf, 0);
2200 static int uvc_reset_resume(struct usb_interface *intf)
2202 return __uvc_resume(intf, 1);
2205 /* ------------------------------------------------------------------------
2209 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2211 if (uvc_clock_param == CLOCK_MONOTONIC)
2212 return sprintf(buffer, "CLOCK_MONOTONIC");
2214 return sprintf(buffer, "CLOCK_REALTIME");
2217 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2219 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2220 val += strlen("clock_");
2222 if (strcasecmp(val, "monotonic") == 0)
2223 uvc_clock_param = CLOCK_MONOTONIC;
2224 else if (strcasecmp(val, "realtime") == 0)
2225 uvc_clock_param = CLOCK_REALTIME;
2232 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2233 &uvc_clock_param, S_IRUGO|S_IWUSR);
2234 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2235 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2236 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2237 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2238 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2239 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2240 MODULE_PARM_DESC(quirks, "Forced device quirks");
2241 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2242 MODULE_PARM_DESC(trace, "Trace level bitmask");
2243 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2244 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2246 /* ------------------------------------------------------------------------
2247 * Driver initialization and cleanup
2251 * The Logitech cameras listed below have their interface class set to
2252 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2253 * though they are compliant.
2255 static struct usb_device_id uvc_ids[] = {
2256 /* LogiLink Wireless Webcam */
2257 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2258 | USB_DEVICE_ID_MATCH_INT_INFO,
2260 .idProduct = 0xa91a,
2261 .bInterfaceClass = USB_CLASS_VIDEO,
2262 .bInterfaceSubClass = 1,
2263 .bInterfaceProtocol = 0,
2264 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2265 /* Genius eFace 2025 */
2266 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2267 | USB_DEVICE_ID_MATCH_INT_INFO,
2269 .idProduct = 0x706e,
2270 .bInterfaceClass = USB_CLASS_VIDEO,
2271 .bInterfaceSubClass = 1,
2272 .bInterfaceProtocol = 0,
2273 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2274 /* Microsoft Lifecam NX-6000 */
2275 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2276 | USB_DEVICE_ID_MATCH_INT_INFO,
2278 .idProduct = 0x00f8,
2279 .bInterfaceClass = USB_CLASS_VIDEO,
2280 .bInterfaceSubClass = 1,
2281 .bInterfaceProtocol = 0,
2282 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2283 /* Microsoft Lifecam NX-3000 */
2284 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2285 | USB_DEVICE_ID_MATCH_INT_INFO,
2287 .idProduct = 0x0721,
2288 .bInterfaceClass = USB_CLASS_VIDEO,
2289 .bInterfaceSubClass = 1,
2290 .bInterfaceProtocol = 0,
2291 .driver_info = UVC_QUIRK_PROBE_DEF },
2292 /* Microsoft Lifecam VX-7000 */
2293 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2294 | USB_DEVICE_ID_MATCH_INT_INFO,
2296 .idProduct = 0x0723,
2297 .bInterfaceClass = USB_CLASS_VIDEO,
2298 .bInterfaceSubClass = 1,
2299 .bInterfaceProtocol = 0,
2300 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2301 /* Logitech Quickcam Fusion */
2302 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2303 | USB_DEVICE_ID_MATCH_INT_INFO,
2305 .idProduct = 0x08c1,
2306 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2307 .bInterfaceSubClass = 1,
2308 .bInterfaceProtocol = 0 },
2309 /* Logitech Quickcam Orbit MP */
2310 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2311 | USB_DEVICE_ID_MATCH_INT_INFO,
2313 .idProduct = 0x08c2,
2314 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2315 .bInterfaceSubClass = 1,
2316 .bInterfaceProtocol = 0 },
2317 /* Logitech Quickcam Pro for Notebook */
2318 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2319 | USB_DEVICE_ID_MATCH_INT_INFO,
2321 .idProduct = 0x08c3,
2322 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2323 .bInterfaceSubClass = 1,
2324 .bInterfaceProtocol = 0 },
2325 /* Logitech Quickcam Pro 5000 */
2326 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2327 | USB_DEVICE_ID_MATCH_INT_INFO,
2329 .idProduct = 0x08c5,
2330 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2331 .bInterfaceSubClass = 1,
2332 .bInterfaceProtocol = 0 },
2333 /* Logitech Quickcam OEM Dell Notebook */
2334 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2335 | USB_DEVICE_ID_MATCH_INT_INFO,
2337 .idProduct = 0x08c6,
2338 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2339 .bInterfaceSubClass = 1,
2340 .bInterfaceProtocol = 0 },
2341 /* Logitech Quickcam OEM Cisco VT Camera II */
2342 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2343 | USB_DEVICE_ID_MATCH_INT_INFO,
2345 .idProduct = 0x08c7,
2346 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2347 .bInterfaceSubClass = 1,
2348 .bInterfaceProtocol = 0 },
2349 /* Logitech HD Pro Webcam C920 */
2350 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2351 | USB_DEVICE_ID_MATCH_INT_INFO,
2353 .idProduct = 0x082d,
2354 .bInterfaceClass = USB_CLASS_VIDEO,
2355 .bInterfaceSubClass = 1,
2356 .bInterfaceProtocol = 0,
2357 .driver_info = UVC_QUIRK_RESTORE_CTRLS_ON_INIT },
2358 /* Chicony CNF7129 (Asus EEE 100HE) */
2359 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2360 | USB_DEVICE_ID_MATCH_INT_INFO,
2362 .idProduct = 0xb071,
2363 .bInterfaceClass = USB_CLASS_VIDEO,
2364 .bInterfaceSubClass = 1,
2365 .bInterfaceProtocol = 0,
2366 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2367 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2368 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2369 | USB_DEVICE_ID_MATCH_INT_INFO,
2371 .idProduct = 0x3820,
2372 .bInterfaceClass = USB_CLASS_VIDEO,
2373 .bInterfaceSubClass = 1,
2374 .bInterfaceProtocol = 0,
2375 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2376 /* Dell XPS m1530 */
2377 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2378 | USB_DEVICE_ID_MATCH_INT_INFO,
2380 .idProduct = 0x2640,
2381 .bInterfaceClass = USB_CLASS_VIDEO,
2382 .bInterfaceSubClass = 1,
2383 .bInterfaceProtocol = 0,
2384 .driver_info = UVC_QUIRK_PROBE_DEF },
2385 /* Dell SP2008WFP Monitor */
2386 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2387 | USB_DEVICE_ID_MATCH_INT_INFO,
2389 .idProduct = 0x2641,
2390 .bInterfaceClass = USB_CLASS_VIDEO,
2391 .bInterfaceSubClass = 1,
2392 .bInterfaceProtocol = 0,
2393 .driver_info = UVC_QUIRK_PROBE_DEF },
2394 /* Dell Alienware X51 */
2395 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2396 | USB_DEVICE_ID_MATCH_INT_INFO,
2398 .idProduct = 0x2643,
2399 .bInterfaceClass = USB_CLASS_VIDEO,
2400 .bInterfaceSubClass = 1,
2401 .bInterfaceProtocol = 0,
2402 .driver_info = UVC_QUIRK_PROBE_DEF },
2403 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2404 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2405 | USB_DEVICE_ID_MATCH_INT_INFO,
2407 .idProduct = 0x264a,
2408 .bInterfaceClass = USB_CLASS_VIDEO,
2409 .bInterfaceSubClass = 1,
2410 .bInterfaceProtocol = 0,
2411 .driver_info = UVC_QUIRK_PROBE_DEF },
2412 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2413 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2414 | USB_DEVICE_ID_MATCH_INT_INFO,
2416 .idProduct = 0x7670,
2417 .bInterfaceClass = USB_CLASS_VIDEO,
2418 .bInterfaceSubClass = 1,
2419 .bInterfaceProtocol = 0,
2420 .driver_info = UVC_QUIRK_PROBE_DEF },
2421 /* Apple Built-In iSight */
2422 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2423 | USB_DEVICE_ID_MATCH_INT_INFO,
2425 .idProduct = 0x8501,
2426 .bInterfaceClass = USB_CLASS_VIDEO,
2427 .bInterfaceSubClass = 1,
2428 .bInterfaceProtocol = 0,
2429 .driver_info = UVC_QUIRK_PROBE_MINMAX
2430 | UVC_QUIRK_BUILTIN_ISIGHT },
2431 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2432 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2433 | USB_DEVICE_ID_MATCH_INT_INFO,
2435 .idProduct = 0x0403,
2436 .bInterfaceClass = USB_CLASS_VIDEO,
2437 .bInterfaceSubClass = 1,
2438 .bInterfaceProtocol = 0,
2439 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2440 /* Genesys Logic USB 2.0 PC Camera */
2441 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2442 | USB_DEVICE_ID_MATCH_INT_INFO,
2444 .idProduct = 0x0505,
2445 .bInterfaceClass = USB_CLASS_VIDEO,
2446 .bInterfaceSubClass = 1,
2447 .bInterfaceProtocol = 0,
2448 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2449 /* Hercules Classic Silver */
2450 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2451 | USB_DEVICE_ID_MATCH_INT_INFO,
2453 .idProduct = 0x300c,
2454 .bInterfaceClass = USB_CLASS_VIDEO,
2455 .bInterfaceSubClass = 1,
2456 .bInterfaceProtocol = 0,
2457 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2459 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2460 | USB_DEVICE_ID_MATCH_INT_INFO,
2462 .idProduct = 0x332d,
2463 .bInterfaceClass = USB_CLASS_VIDEO,
2464 .bInterfaceSubClass = 1,
2465 .bInterfaceProtocol = 0,
2466 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2467 /* ViMicro - Minoru3D */
2468 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2469 | USB_DEVICE_ID_MATCH_INT_INFO,
2471 .idProduct = 0x3410,
2472 .bInterfaceClass = USB_CLASS_VIDEO,
2473 .bInterfaceSubClass = 1,
2474 .bInterfaceProtocol = 0,
2475 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2476 /* ViMicro Venus - Minoru3D */
2477 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2478 | USB_DEVICE_ID_MATCH_INT_INFO,
2480 .idProduct = 0x3420,
2481 .bInterfaceClass = USB_CLASS_VIDEO,
2482 .bInterfaceSubClass = 1,
2483 .bInterfaceProtocol = 0,
2484 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2485 /* Ophir Optronics - SPCAM 620U */
2486 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2487 | USB_DEVICE_ID_MATCH_INT_INFO,
2489 .idProduct = 0x0555,
2490 .bInterfaceClass = USB_CLASS_VIDEO,
2491 .bInterfaceSubClass = 1,
2492 .bInterfaceProtocol = 0,
2493 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2495 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2496 | USB_DEVICE_ID_MATCH_INT_INFO,
2498 .idProduct = 0x0004,
2499 .bInterfaceClass = USB_CLASS_VIDEO,
2500 .bInterfaceSubClass = 1,
2501 .bInterfaceProtocol = 0,
2502 .driver_info = UVC_QUIRK_PROBE_MINMAX
2503 | UVC_QUIRK_PROBE_DEF },
2504 /* IMC Networks (Medion Akoya) */
2505 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2506 | USB_DEVICE_ID_MATCH_INT_INFO,
2508 .idProduct = 0x5103,
2509 .bInterfaceClass = USB_CLASS_VIDEO,
2510 .bInterfaceSubClass = 1,
2511 .bInterfaceProtocol = 0,
2512 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2513 /* JMicron USB2.0 XGA WebCam */
2514 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2515 | USB_DEVICE_ID_MATCH_INT_INFO,
2517 .idProduct = 0x0310,
2518 .bInterfaceClass = USB_CLASS_VIDEO,
2519 .bInterfaceSubClass = 1,
2520 .bInterfaceProtocol = 0,
2521 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2522 /* Syntek (HP Spartan) */
2523 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2524 | USB_DEVICE_ID_MATCH_INT_INFO,
2526 .idProduct = 0x5212,
2527 .bInterfaceClass = USB_CLASS_VIDEO,
2528 .bInterfaceSubClass = 1,
2529 .bInterfaceProtocol = 0,
2530 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2531 /* Syntek (Samsung Q310) */
2532 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2533 | USB_DEVICE_ID_MATCH_INT_INFO,
2535 .idProduct = 0x5931,
2536 .bInterfaceClass = USB_CLASS_VIDEO,
2537 .bInterfaceSubClass = 1,
2538 .bInterfaceProtocol = 0,
2539 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2540 /* Syntek (Packard Bell EasyNote MX52 */
2541 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2542 | USB_DEVICE_ID_MATCH_INT_INFO,
2544 .idProduct = 0x8a12,
2545 .bInterfaceClass = USB_CLASS_VIDEO,
2546 .bInterfaceSubClass = 1,
2547 .bInterfaceProtocol = 0,
2548 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2549 /* Syntek (Asus F9SG) */
2550 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2551 | USB_DEVICE_ID_MATCH_INT_INFO,
2553 .idProduct = 0x8a31,
2554 .bInterfaceClass = USB_CLASS_VIDEO,
2555 .bInterfaceSubClass = 1,
2556 .bInterfaceProtocol = 0,
2557 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2558 /* Syntek (Asus U3S) */
2559 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2560 | USB_DEVICE_ID_MATCH_INT_INFO,
2562 .idProduct = 0x8a33,
2563 .bInterfaceClass = USB_CLASS_VIDEO,
2564 .bInterfaceSubClass = 1,
2565 .bInterfaceProtocol = 0,
2566 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2567 /* Syntek (JAOtech Smart Terminal) */
2568 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2569 | USB_DEVICE_ID_MATCH_INT_INFO,
2571 .idProduct = 0x8a34,
2572 .bInterfaceClass = USB_CLASS_VIDEO,
2573 .bInterfaceSubClass = 1,
2574 .bInterfaceProtocol = 0,
2575 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2577 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2578 | USB_DEVICE_ID_MATCH_INT_INFO,
2580 .idProduct = 0x0202,
2581 .bInterfaceClass = USB_CLASS_VIDEO,
2582 .bInterfaceSubClass = 1,
2583 .bInterfaceProtocol = 0,
2584 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2585 /* Lenovo Thinkpad SL400/SL500 */
2586 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2587 | USB_DEVICE_ID_MATCH_INT_INFO,
2589 .idProduct = 0x480b,
2590 .bInterfaceClass = USB_CLASS_VIDEO,
2591 .bInterfaceSubClass = 1,
2592 .bInterfaceProtocol = 0,
2593 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2594 /* Aveo Technology USB 2.0 Camera */
2595 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2596 | USB_DEVICE_ID_MATCH_INT_INFO,
2598 .idProduct = 0x0306,
2599 .bInterfaceClass = USB_CLASS_VIDEO,
2600 .bInterfaceSubClass = 1,
2601 .bInterfaceProtocol = 0,
2602 .driver_info = UVC_QUIRK_PROBE_MINMAX
2603 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2604 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2605 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2606 | USB_DEVICE_ID_MATCH_INT_INFO,
2608 .idProduct = 0x0516,
2609 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2610 .bInterfaceSubClass = 1,
2611 .bInterfaceProtocol = 0 },
2612 /* Ecamm Pico iMage */
2613 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2614 | USB_DEVICE_ID_MATCH_INT_INFO,
2616 .idProduct = 0xcafe,
2617 .bInterfaceClass = USB_CLASS_VIDEO,
2618 .bInterfaceSubClass = 1,
2619 .bInterfaceProtocol = 0,
2620 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2621 /* Manta MM-353 Plako */
2622 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2623 | USB_DEVICE_ID_MATCH_INT_INFO,
2625 .idProduct = 0x3188,
2626 .bInterfaceClass = USB_CLASS_VIDEO,
2627 .bInterfaceSubClass = 1,
2628 .bInterfaceProtocol = 0,
2629 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2630 /* FSC WebCam V30S */
2631 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2632 | USB_DEVICE_ID_MATCH_INT_INFO,
2634 .idProduct = 0x3288,
2635 .bInterfaceClass = USB_CLASS_VIDEO,
2636 .bInterfaceSubClass = 1,
2637 .bInterfaceProtocol = 0,
2638 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2639 /* Arkmicro unbranded */
2640 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2641 | USB_DEVICE_ID_MATCH_INT_INFO,
2643 .idProduct = 0x3290,
2644 .bInterfaceClass = USB_CLASS_VIDEO,
2645 .bInterfaceSubClass = 1,
2646 .bInterfaceProtocol = 0,
2647 .driver_info = UVC_QUIRK_PROBE_DEF },
2648 /* The Imaging Source USB CCD cameras */
2649 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2650 | USB_DEVICE_ID_MATCH_INT_INFO,
2652 .idProduct = 0x8102,
2653 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2654 .bInterfaceSubClass = 1,
2655 .bInterfaceProtocol = 0 },
2656 /* Bodelin ProScopeHR */
2657 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2658 | USB_DEVICE_ID_MATCH_DEV_HI
2659 | USB_DEVICE_ID_MATCH_INT_INFO,
2661 .idProduct = 0x1000,
2662 .bcdDevice_hi = 0x0126,
2663 .bInterfaceClass = USB_CLASS_VIDEO,
2664 .bInterfaceSubClass = 1,
2665 .bInterfaceProtocol = 0,
2666 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2667 /* MSI StarCam 370i */
2668 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2669 | USB_DEVICE_ID_MATCH_INT_INFO,
2671 .idProduct = 0x2951,
2672 .bInterfaceClass = USB_CLASS_VIDEO,
2673 .bInterfaceSubClass = 1,
2674 .bInterfaceProtocol = 0,
2675 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2676 /* SiGma Micro USB Web Camera */
2677 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2678 | USB_DEVICE_ID_MATCH_INT_INFO,
2680 .idProduct = 0x3000,
2681 .bInterfaceClass = USB_CLASS_VIDEO,
2682 .bInterfaceSubClass = 1,
2683 .bInterfaceProtocol = 0,
2684 .driver_info = UVC_QUIRK_PROBE_MINMAX
2685 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2686 /* Oculus VR Positional Tracker DK2 */
2687 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2688 | USB_DEVICE_ID_MATCH_INT_INFO,
2690 .idProduct = 0x0201,
2691 .bInterfaceClass = USB_CLASS_VIDEO,
2692 .bInterfaceSubClass = 1,
2693 .bInterfaceProtocol = 0,
2694 .driver_info = UVC_QUIRK_FORCE_Y8 },
2695 /* Generic USB Video Class */
2696 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
2697 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
2701 MODULE_DEVICE_TABLE(usb, uvc_ids);
2703 struct uvc_driver uvc_driver = {
2707 .disconnect = uvc_disconnect,
2708 .suspend = uvc_suspend,
2709 .resume = uvc_resume,
2710 .reset_resume = uvc_reset_resume,
2711 .id_table = uvc_ids,
2712 .supports_autosuspend = 1,
2716 static int __init uvc_init(void)
2722 ret = usb_register(&uvc_driver.driver);
2724 uvc_debugfs_cleanup();
2728 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2732 static void __exit uvc_cleanup(void)
2734 usb_deregister(&uvc_driver.driver);
2735 uvc_debugfs_cleanup();
2738 module_init(uvc_init);
2739 module_exit(uvc_cleanup);
2741 MODULE_AUTHOR(DRIVER_AUTHOR);
2742 MODULE_DESCRIPTION(DRIVER_DESC);
2743 MODULE_LICENSE("GPL");
2744 MODULE_VERSION(DRIVER_VERSION);