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 = ALIGN(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);
1022 /* Make sure the terminal type MSB is not null, otherwise it
1023 * could be confused with a unit.
1025 type = get_unaligned_le16(&buffer[4]);
1026 if ((type & 0xff00) == 0) {
1027 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1028 "interface %d INPUT_TERMINAL %d has invalid "
1029 "type 0x%04x, skipping\n", udev->devnum,
1030 alts->desc.bInterfaceNumber,
1039 if (type == UVC_ITT_CAMERA) {
1040 n = buflen >= 15 ? buffer[14] : 0;
1043 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1044 n = buflen >= 9 ? buffer[8] : 0;
1045 p = buflen >= 10 + n ? buffer[9+n] : 0;
1049 if (buflen < len + n + p) {
1050 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1051 "interface %d INPUT_TERMINAL error\n",
1052 udev->devnum, alts->desc.bInterfaceNumber);
1056 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1061 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1062 term->camera.bControlSize = n;
1063 term->camera.bmControls = (__u8 *)term + sizeof *term;
1064 term->camera.wObjectiveFocalLengthMin =
1065 get_unaligned_le16(&buffer[8]);
1066 term->camera.wObjectiveFocalLengthMax =
1067 get_unaligned_le16(&buffer[10]);
1068 term->camera.wOcularFocalLength =
1069 get_unaligned_le16(&buffer[12]);
1070 memcpy(term->camera.bmControls, &buffer[15], n);
1071 } else if (UVC_ENTITY_TYPE(term) ==
1072 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1073 term->media.bControlSize = n;
1074 term->media.bmControls = (__u8 *)term + sizeof *term;
1075 term->media.bTransportModeSize = p;
1076 term->media.bmTransportModes = (__u8 *)term
1078 memcpy(term->media.bmControls, &buffer[9], n);
1079 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1083 usb_string(udev, buffer[7], term->name,
1085 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1086 sprintf(term->name, "Camera %u", buffer[3]);
1087 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1088 sprintf(term->name, "Media %u", buffer[3]);
1090 sprintf(term->name, "Input %u", buffer[3]);
1092 list_add_tail(&term->list, &dev->entities);
1095 case UVC_VC_OUTPUT_TERMINAL:
1097 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1098 "interface %d OUTPUT_TERMINAL error\n",
1099 udev->devnum, alts->desc.bInterfaceNumber);
1103 /* Make sure the terminal type MSB is not null, otherwise it
1104 * could be confused with a unit.
1106 type = get_unaligned_le16(&buffer[4]);
1107 if ((type & 0xff00) == 0) {
1108 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1109 "interface %d OUTPUT_TERMINAL %d has invalid "
1110 "type 0x%04x, skipping\n", udev->devnum,
1111 alts->desc.bInterfaceNumber, buffer[3], type);
1115 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1120 memcpy(term->baSourceID, &buffer[7], 1);
1123 usb_string(udev, buffer[8], term->name,
1126 sprintf(term->name, "Output %u", buffer[3]);
1128 list_add_tail(&term->list, &dev->entities);
1131 case UVC_VC_SELECTOR_UNIT:
1132 p = buflen >= 5 ? buffer[4] : 0;
1134 if (buflen < 5 || buflen < 6 + p) {
1135 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1136 "interface %d SELECTOR_UNIT error\n",
1137 udev->devnum, alts->desc.bInterfaceNumber);
1141 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1145 memcpy(unit->baSourceID, &buffer[5], p);
1147 if (buffer[5+p] != 0)
1148 usb_string(udev, buffer[5+p], unit->name,
1151 sprintf(unit->name, "Selector %u", buffer[3]);
1153 list_add_tail(&unit->list, &dev->entities);
1156 case UVC_VC_PROCESSING_UNIT:
1157 n = buflen >= 8 ? buffer[7] : 0;
1158 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1160 if (buflen < p + n) {
1161 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1162 "interface %d PROCESSING_UNIT error\n",
1163 udev->devnum, alts->desc.bInterfaceNumber);
1167 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1171 memcpy(unit->baSourceID, &buffer[4], 1);
1172 unit->processing.wMaxMultiplier =
1173 get_unaligned_le16(&buffer[5]);
1174 unit->processing.bControlSize = buffer[7];
1175 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1176 memcpy(unit->processing.bmControls, &buffer[8], n);
1177 if (dev->uvc_version >= 0x0110)
1178 unit->processing.bmVideoStandards = buffer[9+n];
1180 if (buffer[8+n] != 0)
1181 usb_string(udev, buffer[8+n], unit->name,
1184 sprintf(unit->name, "Processing %u", buffer[3]);
1186 list_add_tail(&unit->list, &dev->entities);
1189 case UVC_VC_EXTENSION_UNIT:
1190 p = buflen >= 22 ? buffer[21] : 0;
1191 n = buflen >= 24 + p ? buffer[22+p] : 0;
1193 if (buflen < 24 + p + n) {
1194 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1195 "interface %d EXTENSION_UNIT error\n",
1196 udev->devnum, alts->desc.bInterfaceNumber);
1200 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1204 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1205 unit->extension.bNumControls = buffer[20];
1206 memcpy(unit->baSourceID, &buffer[22], p);
1207 unit->extension.bControlSize = buffer[22+p];
1208 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1209 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1211 if (buffer[23+p+n] != 0)
1212 usb_string(udev, buffer[23+p+n], unit->name,
1215 sprintf(unit->name, "Extension %u", buffer[3]);
1217 list_add_tail(&unit->list, &dev->entities);
1221 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1222 "descriptor (%u)\n", buffer[2]);
1229 static int uvc_parse_control(struct uvc_device *dev)
1231 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1232 unsigned char *buffer = alts->extra;
1233 int buflen = alts->extralen;
1236 /* Parse the default alternate setting only, as the UVC specification
1237 * defines a single alternate setting, the default alternate setting
1241 while (buflen > 2) {
1242 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1243 buffer[1] != USB_DT_CS_INTERFACE)
1244 goto next_descriptor;
1246 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1250 buflen -= buffer[0];
1251 buffer += buffer[0];
1254 /* Check if the optional status endpoint is present. Built-in iSight
1255 * webcams have an interrupt endpoint but spit proprietary data that
1256 * don't conform to the UVC status endpoint messages. Don't try to
1257 * handle the interrupt endpoint for those cameras.
1259 if (alts->desc.bNumEndpoints == 1 &&
1260 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1261 struct usb_host_endpoint *ep = &alts->endpoint[0];
1262 struct usb_endpoint_descriptor *desc = &ep->desc;
1264 if (usb_endpoint_is_int_in(desc) &&
1265 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1266 desc->bInterval != 0) {
1267 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1268 "(addr %02x).\n", desc->bEndpointAddress);
1276 /* ------------------------------------------------------------------------
1281 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1282 * and containing the following units:
1284 * - one or more Output Terminals (USB Streaming or Display)
1285 * - zero or one Processing Unit
1286 * - zero, one or more single-input Selector Units
1287 * - zero or one multiple-input Selector Units, provided all inputs are
1288 * connected to input terminals
1289 * - zero, one or mode single-input Extension Units
1290 * - one or more Input Terminals (Camera, External or USB Streaming)
1292 * The terminal and units must match on of the following structures:
1294 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1295 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1296 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1298 * +---------+ +---------+ -> OTT_*(0)
1299 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1300 * +---------+ +---------+ -> OTT_*(n)
1302 * The Processing Unit and Extension Units can be in any order. Additional
1303 * Extension Units connected to the main chain as single-unit branches are
1304 * also supported. Single-input Selector Units are ignored.
1306 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1307 struct uvc_entity *entity)
1309 switch (UVC_ENTITY_TYPE(entity)) {
1310 case UVC_VC_EXTENSION_UNIT:
1311 if (uvc_trace_param & UVC_TRACE_PROBE)
1312 printk(" <- XU %d", entity->id);
1314 if (entity->bNrInPins != 1) {
1315 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1316 "than 1 input pin.\n", entity->id);
1322 case UVC_VC_PROCESSING_UNIT:
1323 if (uvc_trace_param & UVC_TRACE_PROBE)
1324 printk(" <- PU %d", entity->id);
1326 if (chain->processing != NULL) {
1327 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1328 "Processing Units in chain.\n");
1332 chain->processing = entity;
1335 case UVC_VC_SELECTOR_UNIT:
1336 if (uvc_trace_param & UVC_TRACE_PROBE)
1337 printk(" <- SU %d", entity->id);
1339 /* Single-input selector units are ignored. */
1340 if (entity->bNrInPins == 1)
1343 if (chain->selector != NULL) {
1344 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1345 "Units in chain.\n");
1349 chain->selector = entity;
1352 case UVC_ITT_VENDOR_SPECIFIC:
1353 case UVC_ITT_CAMERA:
1354 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1355 if (uvc_trace_param & UVC_TRACE_PROBE)
1356 printk(" <- IT %d\n", entity->id);
1360 case UVC_OTT_VENDOR_SPECIFIC:
1361 case UVC_OTT_DISPLAY:
1362 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1363 if (uvc_trace_param & UVC_TRACE_PROBE)
1364 printk(" OT %d", entity->id);
1368 case UVC_TT_STREAMING:
1369 if (UVC_ENTITY_IS_ITERM(entity)) {
1370 if (uvc_trace_param & UVC_TRACE_PROBE)
1371 printk(" <- IT %d\n", entity->id);
1373 if (uvc_trace_param & UVC_TRACE_PROBE)
1374 printk(" OT %d", entity->id);
1380 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1381 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1385 list_add_tail(&entity->chain, &chain->entities);
1389 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1390 struct uvc_entity *entity, struct uvc_entity *prev)
1392 struct uvc_entity *forward;
1400 forward = uvc_entity_by_reference(chain->dev, entity->id,
1402 if (forward == NULL)
1404 if (forward == prev)
1407 switch (UVC_ENTITY_TYPE(forward)) {
1408 case UVC_VC_EXTENSION_UNIT:
1409 if (forward->bNrInPins != 1) {
1410 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1411 "has more than 1 input pin.\n",
1416 list_add_tail(&forward->chain, &chain->entities);
1417 if (uvc_trace_param & UVC_TRACE_PROBE) {
1421 printk(" XU %d", forward->id);
1426 case UVC_OTT_VENDOR_SPECIFIC:
1427 case UVC_OTT_DISPLAY:
1428 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1429 case UVC_TT_STREAMING:
1430 if (UVC_ENTITY_IS_ITERM(forward)) {
1431 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1432 "terminal %u.\n", forward->id);
1436 list_add_tail(&forward->chain, &chain->entities);
1437 if (uvc_trace_param & UVC_TRACE_PROBE) {
1441 printk(" OT %d", forward->id);
1453 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1454 struct uvc_entity **_entity)
1456 struct uvc_entity *entity = *_entity;
1457 struct uvc_entity *term;
1458 int id = -EINVAL, i;
1460 switch (UVC_ENTITY_TYPE(entity)) {
1461 case UVC_VC_EXTENSION_UNIT:
1462 case UVC_VC_PROCESSING_UNIT:
1463 id = entity->baSourceID[0];
1466 case UVC_VC_SELECTOR_UNIT:
1467 /* Single-input selector units are ignored. */
1468 if (entity->bNrInPins == 1) {
1469 id = entity->baSourceID[0];
1473 if (uvc_trace_param & UVC_TRACE_PROBE)
1476 chain->selector = entity;
1477 for (i = 0; i < entity->bNrInPins; ++i) {
1478 id = entity->baSourceID[i];
1479 term = uvc_entity_by_id(chain->dev, id);
1480 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1481 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1482 "input %d isn't connected to an "
1483 "input terminal\n", entity->id, i);
1487 if (uvc_trace_param & UVC_TRACE_PROBE)
1488 printk(" %d", term->id);
1490 list_add_tail(&term->chain, &chain->entities);
1491 uvc_scan_chain_forward(chain, term, entity);
1494 if (uvc_trace_param & UVC_TRACE_PROBE)
1500 case UVC_ITT_VENDOR_SPECIFIC:
1501 case UVC_ITT_CAMERA:
1502 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1503 case UVC_OTT_VENDOR_SPECIFIC:
1504 case UVC_OTT_DISPLAY:
1505 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1506 case UVC_TT_STREAMING:
1507 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1516 entity = uvc_entity_by_id(chain->dev, id);
1517 if (entity == NULL) {
1518 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1519 "unknown entity %d.\n", id);
1527 static int uvc_scan_chain(struct uvc_video_chain *chain,
1528 struct uvc_entity *term)
1530 struct uvc_entity *entity, *prev;
1532 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1537 while (entity != NULL) {
1538 /* Entity must not be part of an existing chain */
1539 if (entity->chain.next || entity->chain.prev) {
1540 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1541 "entity %d already in chain.\n", entity->id);
1545 /* Process entity */
1546 if (uvc_scan_chain_entity(chain, entity) < 0)
1550 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1555 if (uvc_scan_chain_backward(chain, &entity) < 0)
1562 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1565 struct uvc_entity *term;
1566 unsigned int nterms = 0;
1569 list_for_each_entry(term, terms, chain) {
1570 if (!UVC_ENTITY_IS_TERM(term) ||
1571 UVC_TERM_DIRECTION(term) != dir)
1575 p += sprintf(p, ",");
1576 if (++nterms >= 4) {
1577 p += sprintf(p, "...");
1580 p += sprintf(p, "%u", term->id);
1586 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1588 static char buffer[43];
1591 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1592 p += sprintf(p, " -> ");
1593 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1598 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1600 struct uvc_video_chain *chain;
1602 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1606 INIT_LIST_HEAD(&chain->entities);
1607 mutex_init(&chain->ctrl_mutex);
1609 v4l2_prio_init(&chain->prio);
1615 * Fallback heuristic for devices that don't connect units and terminals in a
1618 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1619 * to fail, but if we just take the entities we can find and put them together
1620 * in the most sensible chain we can think of, turns out they do work anyway.
1621 * Note: This heuristic assumes there is a single chain.
1623 * At the time of writing, devices known to have such a broken chain are
1624 * - Acer Integrated Camera (5986:055a)
1625 * - Realtek rtl157a7 (0bda:57a7)
1627 static int uvc_scan_fallback(struct uvc_device *dev)
1629 struct uvc_video_chain *chain;
1630 struct uvc_entity *iterm = NULL;
1631 struct uvc_entity *oterm = NULL;
1632 struct uvc_entity *entity;
1633 struct uvc_entity *prev;
1636 * Start by locating the input and output terminals. We only support
1637 * devices with exactly one of each for now.
1639 list_for_each_entry(entity, &dev->entities, list) {
1640 if (UVC_ENTITY_IS_ITERM(entity)) {
1646 if (UVC_ENTITY_IS_OTERM(entity)) {
1653 if (iterm == NULL || oterm == NULL)
1656 /* Allocate the chain and fill it. */
1657 chain = uvc_alloc_chain(dev);
1661 if (uvc_scan_chain_entity(chain, oterm) < 0)
1667 * Add all Processing and Extension Units with two pads. The order
1668 * doesn't matter much, use reverse list traversal to connect units in
1669 * UVC descriptor order as we build the chain from output to input. This
1670 * leads to units appearing in the order meant by the manufacturer for
1671 * the cameras known to require this heuristic.
1673 list_for_each_entry_reverse(entity, &dev->entities, list) {
1674 if (entity->type != UVC_VC_PROCESSING_UNIT &&
1675 entity->type != UVC_VC_EXTENSION_UNIT)
1678 if (entity->num_pads != 2)
1681 if (uvc_scan_chain_entity(chain, entity) < 0)
1684 prev->baSourceID[0] = entity->id;
1688 if (uvc_scan_chain_entity(chain, iterm) < 0)
1691 prev->baSourceID[0] = iterm->id;
1693 list_add_tail(&chain->list, &dev->chains);
1695 uvc_trace(UVC_TRACE_PROBE,
1696 "Found a video chain by fallback heuristic (%s).\n",
1697 uvc_print_chain(chain));
1707 * Scan the device for video chains and register video devices.
1709 * Chains are scanned starting at their output terminals and walked backwards.
1711 static int uvc_scan_device(struct uvc_device *dev)
1713 struct uvc_video_chain *chain;
1714 struct uvc_entity *term;
1716 list_for_each_entry(term, &dev->entities, list) {
1717 if (!UVC_ENTITY_IS_OTERM(term))
1720 /* If the terminal is already included in a chain, skip it.
1721 * This can happen for chains that have multiple output
1722 * terminals, where all output terminals beside the first one
1723 * will be inserted in the chain in forward scans.
1725 if (term->chain.next || term->chain.prev)
1728 chain = uvc_alloc_chain(dev);
1732 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1734 if (uvc_scan_chain(chain, term) < 0) {
1739 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1740 uvc_print_chain(chain));
1742 list_add_tail(&chain->list, &dev->chains);
1745 if (list_empty(&dev->chains))
1746 uvc_scan_fallback(dev);
1748 if (list_empty(&dev->chains)) {
1749 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1756 /* ------------------------------------------------------------------------
1757 * Video device registration and unregistration
1761 * Delete the UVC device.
1763 * Called by the kernel when the last reference to the uvc_device structure
1766 * As this function is called after or during disconnect(), all URBs have
1767 * already been canceled by the USB core. There is no need to kill the
1768 * interrupt URB manually.
1770 static void uvc_delete(struct uvc_device *dev)
1772 struct list_head *p, *n;
1774 uvc_status_cleanup(dev);
1775 uvc_ctrl_cleanup_device(dev);
1777 usb_put_intf(dev->intf);
1778 usb_put_dev(dev->udev);
1781 v4l2_device_unregister(&dev->vdev);
1782 #ifdef CONFIG_MEDIA_CONTROLLER
1783 if (media_devnode_is_registered(dev->mdev.devnode))
1784 media_device_unregister(&dev->mdev);
1785 media_device_cleanup(&dev->mdev);
1788 list_for_each_safe(p, n, &dev->chains) {
1789 struct uvc_video_chain *chain;
1790 chain = list_entry(p, struct uvc_video_chain, list);
1794 list_for_each_safe(p, n, &dev->entities) {
1795 struct uvc_entity *entity;
1796 entity = list_entry(p, struct uvc_entity, list);
1797 #ifdef CONFIG_MEDIA_CONTROLLER
1798 uvc_mc_cleanup_entity(entity);
1803 list_for_each_safe(p, n, &dev->streams) {
1804 struct uvc_streaming *streaming;
1805 streaming = list_entry(p, struct uvc_streaming, list);
1806 usb_driver_release_interface(&uvc_driver.driver,
1808 usb_put_intf(streaming->intf);
1809 kfree(streaming->format);
1810 kfree(streaming->header.bmaControls);
1817 static void uvc_release(struct video_device *vdev)
1819 struct uvc_streaming *stream = video_get_drvdata(vdev);
1820 struct uvc_device *dev = stream->dev;
1822 /* Decrement the registered streams count and delete the device when it
1825 if (atomic_dec_and_test(&dev->nstreams))
1830 * Unregister the video devices.
1832 static void uvc_unregister_video(struct uvc_device *dev)
1834 struct uvc_streaming *stream;
1836 /* Unregistering all video devices might result in uvc_delete() being
1837 * called from inside the loop if there's no open file handle. To avoid
1838 * that, increment the stream count before iterating over the streams
1839 * and decrement it when done.
1841 atomic_inc(&dev->nstreams);
1843 list_for_each_entry(stream, &dev->streams, list) {
1844 if (!video_is_registered(&stream->vdev))
1847 video_unregister_device(&stream->vdev);
1849 uvc_debugfs_cleanup_stream(stream);
1852 /* Decrement the stream count and call uvc_delete explicitly if there
1853 * are no stream left.
1855 if (atomic_dec_and_test(&dev->nstreams))
1859 static int uvc_register_video(struct uvc_device *dev,
1860 struct uvc_streaming *stream)
1862 struct video_device *vdev = &stream->vdev;
1865 /* Initialize the video buffers queue. */
1866 ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1870 /* Initialize the streaming interface with default streaming
1873 ret = uvc_video_init(stream);
1875 uvc_printk(KERN_ERR, "Failed to initialize the device "
1880 uvc_debugfs_init_stream(stream);
1882 /* Register the device with V4L. */
1884 /* We already hold a reference to dev->udev. The video device will be
1885 * unregistered before the reference is released, so we don't need to
1888 vdev->v4l2_dev = &dev->vdev;
1889 vdev->fops = &uvc_fops;
1890 vdev->ioctl_ops = &uvc_ioctl_ops;
1891 vdev->release = uvc_release;
1892 vdev->prio = &stream->chain->prio;
1893 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1894 vdev->vfl_dir = VFL_DIR_TX;
1895 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1897 /* Set the driver data before calling video_register_device, otherwise
1898 * uvc_v4l2_open might race us.
1900 video_set_drvdata(vdev, stream);
1902 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1904 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1909 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1910 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1912 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1914 atomic_inc(&dev->nstreams);
1919 * Register all video devices in all chains.
1921 static int uvc_register_terms(struct uvc_device *dev,
1922 struct uvc_video_chain *chain)
1924 struct uvc_streaming *stream;
1925 struct uvc_entity *term;
1928 list_for_each_entry(term, &chain->entities, chain) {
1929 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1932 stream = uvc_stream_by_id(dev, term->id);
1933 if (stream == NULL) {
1934 uvc_printk(KERN_INFO, "No streaming interface found "
1935 "for terminal %u.", term->id);
1939 stream->chain = chain;
1940 ret = uvc_register_video(dev, stream);
1944 term->vdev = &stream->vdev;
1950 static int uvc_register_chains(struct uvc_device *dev)
1952 struct uvc_video_chain *chain;
1955 list_for_each_entry(chain, &dev->chains, list) {
1956 ret = uvc_register_terms(dev, chain);
1960 #ifdef CONFIG_MEDIA_CONTROLLER
1961 ret = uvc_mc_register_entities(chain);
1963 uvc_printk(KERN_INFO, "Failed to register entites "
1972 /* ------------------------------------------------------------------------
1973 * USB probe, disconnect, suspend and resume
1976 static int uvc_probe(struct usb_interface *intf,
1977 const struct usb_device_id *id)
1979 struct usb_device *udev = interface_to_usbdev(intf);
1980 struct uvc_device *dev;
1983 if (id->idVendor && id->idProduct)
1984 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1985 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1988 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1991 /* Allocate memory for the device and initialize it. */
1992 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1995 INIT_LIST_HEAD(&dev->entities);
1996 INIT_LIST_HEAD(&dev->chains);
1997 INIT_LIST_HEAD(&dev->streams);
1998 atomic_set(&dev->nstreams, 0);
1999 atomic_set(&dev->nmappings, 0);
2000 mutex_init(&dev->lock);
2002 dev->udev = usb_get_dev(udev);
2003 dev->intf = usb_get_intf(intf);
2004 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2005 dev->quirks = (uvc_quirks_param == -1)
2006 ? id->driver_info : uvc_quirks_param;
2008 if (udev->product != NULL)
2009 strlcpy(dev->name, udev->product, sizeof dev->name);
2011 snprintf(dev->name, sizeof dev->name,
2012 "UVC Camera (%04x:%04x)",
2013 le16_to_cpu(udev->descriptor.idVendor),
2014 le16_to_cpu(udev->descriptor.idProduct));
2016 /* Parse the Video Class control descriptor. */
2017 if (uvc_parse_control(dev) < 0) {
2018 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
2023 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2024 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2025 udev->product ? udev->product : "<unnamed>",
2026 le16_to_cpu(udev->descriptor.idVendor),
2027 le16_to_cpu(udev->descriptor.idProduct));
2029 if (dev->quirks != id->driver_info) {
2030 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
2031 "parameter for testing purpose.\n", dev->quirks);
2032 uvc_printk(KERN_INFO, "Please report required quirks to the "
2033 "linux-uvc-devel mailing list.\n");
2036 /* Initialize the media device and register the V4L2 device. */
2037 #ifdef CONFIG_MEDIA_CONTROLLER
2038 dev->mdev.dev = &intf->dev;
2039 strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2041 strlcpy(dev->mdev.serial, udev->serial,
2042 sizeof(dev->mdev.serial));
2043 strcpy(dev->mdev.bus_info, udev->devpath);
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;
2050 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2053 /* Initialize controls. */
2054 if (uvc_ctrl_init_device(dev) < 0)
2057 /* Scan the device for video chains. */
2058 if (uvc_scan_device(dev) < 0)
2061 /* Register video device nodes. */
2062 if (uvc_register_chains(dev) < 0)
2065 #ifdef CONFIG_MEDIA_CONTROLLER
2066 /* Register the media device node */
2067 if (media_device_register(&dev->mdev) < 0)
2070 /* Save our data pointer in the interface data. */
2071 usb_set_intfdata(intf, dev);
2073 /* Initialize the interrupt URB. */
2074 if ((ret = uvc_status_init(dev)) < 0) {
2075 uvc_printk(KERN_INFO, "Unable to initialize the status "
2076 "endpoint (%d), status interrupt will not be "
2077 "supported.\n", ret);
2080 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
2081 usb_enable_autosuspend(udev);
2085 uvc_unregister_video(dev);
2089 static void uvc_disconnect(struct usb_interface *intf)
2091 struct uvc_device *dev = usb_get_intfdata(intf);
2093 /* Set the USB interface data to NULL. This can be done outside the
2094 * lock, as there's no other reader.
2096 usb_set_intfdata(intf, NULL);
2098 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2099 UVC_SC_VIDEOSTREAMING)
2102 uvc_unregister_video(dev);
2105 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2107 struct uvc_device *dev = usb_get_intfdata(intf);
2108 struct uvc_streaming *stream;
2110 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2111 intf->cur_altsetting->desc.bInterfaceNumber);
2113 /* Controls are cached on the fly so they don't need to be saved. */
2114 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2115 UVC_SC_VIDEOCONTROL) {
2116 mutex_lock(&dev->lock);
2118 uvc_status_stop(dev);
2119 mutex_unlock(&dev->lock);
2123 list_for_each_entry(stream, &dev->streams, list) {
2124 if (stream->intf == intf)
2125 return uvc_video_suspend(stream);
2128 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2133 static int __uvc_resume(struct usb_interface *intf, int reset)
2135 struct uvc_device *dev = usb_get_intfdata(intf);
2136 struct uvc_streaming *stream;
2139 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2140 intf->cur_altsetting->desc.bInterfaceNumber);
2142 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2143 UVC_SC_VIDEOCONTROL) {
2145 ret = uvc_ctrl_restore_values(dev);
2150 mutex_lock(&dev->lock);
2152 ret = uvc_status_start(dev, GFP_NOIO);
2153 mutex_unlock(&dev->lock);
2158 list_for_each_entry(stream, &dev->streams, list) {
2159 if (stream->intf == intf) {
2160 ret = uvc_video_resume(stream, reset);
2162 uvc_queue_streamoff(&stream->queue,
2163 stream->queue.queue.type);
2168 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2173 static int uvc_resume(struct usb_interface *intf)
2175 return __uvc_resume(intf, 0);
2178 static int uvc_reset_resume(struct usb_interface *intf)
2180 return __uvc_resume(intf, 1);
2183 /* ------------------------------------------------------------------------
2187 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2189 if (uvc_clock_param == CLOCK_MONOTONIC)
2190 return sprintf(buffer, "CLOCK_MONOTONIC");
2192 return sprintf(buffer, "CLOCK_REALTIME");
2195 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2197 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2198 val += strlen("clock_");
2200 if (strcasecmp(val, "monotonic") == 0)
2201 uvc_clock_param = CLOCK_MONOTONIC;
2202 else if (strcasecmp(val, "realtime") == 0)
2203 uvc_clock_param = CLOCK_REALTIME;
2210 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2211 &uvc_clock_param, S_IRUGO|S_IWUSR);
2212 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2213 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2214 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2215 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2216 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2217 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2218 MODULE_PARM_DESC(quirks, "Forced device quirks");
2219 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2220 MODULE_PARM_DESC(trace, "Trace level bitmask");
2221 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2222 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2224 /* ------------------------------------------------------------------------
2225 * Driver initialization and cleanup
2229 * The Logitech cameras listed below have their interface class set to
2230 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2231 * though they are compliant.
2233 static struct usb_device_id uvc_ids[] = {
2234 /* LogiLink Wireless Webcam */
2235 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2236 | USB_DEVICE_ID_MATCH_INT_INFO,
2238 .idProduct = 0xa91a,
2239 .bInterfaceClass = USB_CLASS_VIDEO,
2240 .bInterfaceSubClass = 1,
2241 .bInterfaceProtocol = 0,
2242 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2243 /* Genius eFace 2025 */
2244 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2245 | USB_DEVICE_ID_MATCH_INT_INFO,
2247 .idProduct = 0x706e,
2248 .bInterfaceClass = USB_CLASS_VIDEO,
2249 .bInterfaceSubClass = 1,
2250 .bInterfaceProtocol = 0,
2251 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2252 /* Microsoft Lifecam NX-6000 */
2253 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2254 | USB_DEVICE_ID_MATCH_INT_INFO,
2256 .idProduct = 0x00f8,
2257 .bInterfaceClass = USB_CLASS_VIDEO,
2258 .bInterfaceSubClass = 1,
2259 .bInterfaceProtocol = 0,
2260 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2261 /* Microsoft Lifecam NX-3000 */
2262 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2263 | USB_DEVICE_ID_MATCH_INT_INFO,
2265 .idProduct = 0x0721,
2266 .bInterfaceClass = USB_CLASS_VIDEO,
2267 .bInterfaceSubClass = 1,
2268 .bInterfaceProtocol = 0,
2269 .driver_info = UVC_QUIRK_PROBE_DEF },
2270 /* Microsoft Lifecam VX-7000 */
2271 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2272 | USB_DEVICE_ID_MATCH_INT_INFO,
2274 .idProduct = 0x0723,
2275 .bInterfaceClass = USB_CLASS_VIDEO,
2276 .bInterfaceSubClass = 1,
2277 .bInterfaceProtocol = 0,
2278 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2279 /* Logitech Quickcam Fusion */
2280 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2281 | USB_DEVICE_ID_MATCH_INT_INFO,
2283 .idProduct = 0x08c1,
2284 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2285 .bInterfaceSubClass = 1,
2286 .bInterfaceProtocol = 0 },
2287 /* Logitech Quickcam Orbit MP */
2288 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2289 | USB_DEVICE_ID_MATCH_INT_INFO,
2291 .idProduct = 0x08c2,
2292 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2293 .bInterfaceSubClass = 1,
2294 .bInterfaceProtocol = 0 },
2295 /* Logitech Quickcam Pro for Notebook */
2296 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2297 | USB_DEVICE_ID_MATCH_INT_INFO,
2299 .idProduct = 0x08c3,
2300 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2301 .bInterfaceSubClass = 1,
2302 .bInterfaceProtocol = 0 },
2303 /* Logitech Quickcam Pro 5000 */
2304 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2305 | USB_DEVICE_ID_MATCH_INT_INFO,
2307 .idProduct = 0x08c5,
2308 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2309 .bInterfaceSubClass = 1,
2310 .bInterfaceProtocol = 0 },
2311 /* Logitech Quickcam OEM Dell Notebook */
2312 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2313 | USB_DEVICE_ID_MATCH_INT_INFO,
2315 .idProduct = 0x08c6,
2316 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2317 .bInterfaceSubClass = 1,
2318 .bInterfaceProtocol = 0 },
2319 /* Logitech Quickcam OEM Cisco VT Camera II */
2320 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2321 | USB_DEVICE_ID_MATCH_INT_INFO,
2323 .idProduct = 0x08c7,
2324 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2325 .bInterfaceSubClass = 1,
2326 .bInterfaceProtocol = 0 },
2327 /* Logitech HD Pro Webcam C920 */
2328 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2329 | USB_DEVICE_ID_MATCH_INT_INFO,
2331 .idProduct = 0x082d,
2332 .bInterfaceClass = USB_CLASS_VIDEO,
2333 .bInterfaceSubClass = 1,
2334 .bInterfaceProtocol = 0,
2335 .driver_info = UVC_QUIRK_RESTORE_CTRLS_ON_INIT },
2336 /* Chicony CNF7129 (Asus EEE 100HE) */
2337 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2338 | USB_DEVICE_ID_MATCH_INT_INFO,
2340 .idProduct = 0xb071,
2341 .bInterfaceClass = USB_CLASS_VIDEO,
2342 .bInterfaceSubClass = 1,
2343 .bInterfaceProtocol = 0,
2344 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2345 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2346 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2347 | USB_DEVICE_ID_MATCH_INT_INFO,
2349 .idProduct = 0x3820,
2350 .bInterfaceClass = USB_CLASS_VIDEO,
2351 .bInterfaceSubClass = 1,
2352 .bInterfaceProtocol = 0,
2353 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2354 /* Dell XPS m1530 */
2355 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2356 | USB_DEVICE_ID_MATCH_INT_INFO,
2358 .idProduct = 0x2640,
2359 .bInterfaceClass = USB_CLASS_VIDEO,
2360 .bInterfaceSubClass = 1,
2361 .bInterfaceProtocol = 0,
2362 .driver_info = UVC_QUIRK_PROBE_DEF },
2363 /* Dell SP2008WFP Monitor */
2364 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2365 | USB_DEVICE_ID_MATCH_INT_INFO,
2367 .idProduct = 0x2641,
2368 .bInterfaceClass = USB_CLASS_VIDEO,
2369 .bInterfaceSubClass = 1,
2370 .bInterfaceProtocol = 0,
2371 .driver_info = UVC_QUIRK_PROBE_DEF },
2372 /* Dell Alienware X51 */
2373 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2374 | USB_DEVICE_ID_MATCH_INT_INFO,
2376 .idProduct = 0x2643,
2377 .bInterfaceClass = USB_CLASS_VIDEO,
2378 .bInterfaceSubClass = 1,
2379 .bInterfaceProtocol = 0,
2380 .driver_info = UVC_QUIRK_PROBE_DEF },
2381 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2382 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2383 | USB_DEVICE_ID_MATCH_INT_INFO,
2385 .idProduct = 0x264a,
2386 .bInterfaceClass = USB_CLASS_VIDEO,
2387 .bInterfaceSubClass = 1,
2388 .bInterfaceProtocol = 0,
2389 .driver_info = UVC_QUIRK_PROBE_DEF },
2390 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2391 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2392 | USB_DEVICE_ID_MATCH_INT_INFO,
2394 .idProduct = 0x7670,
2395 .bInterfaceClass = USB_CLASS_VIDEO,
2396 .bInterfaceSubClass = 1,
2397 .bInterfaceProtocol = 0,
2398 .driver_info = UVC_QUIRK_PROBE_DEF },
2399 /* Apple Built-In iSight */
2400 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2401 | USB_DEVICE_ID_MATCH_INT_INFO,
2403 .idProduct = 0x8501,
2404 .bInterfaceClass = USB_CLASS_VIDEO,
2405 .bInterfaceSubClass = 1,
2406 .bInterfaceProtocol = 0,
2407 .driver_info = UVC_QUIRK_PROBE_MINMAX
2408 | UVC_QUIRK_BUILTIN_ISIGHT },
2409 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2410 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2411 | USB_DEVICE_ID_MATCH_INT_INFO,
2413 .idProduct = 0x0403,
2414 .bInterfaceClass = USB_CLASS_VIDEO,
2415 .bInterfaceSubClass = 1,
2416 .bInterfaceProtocol = 0,
2417 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2418 /* Genesys Logic USB 2.0 PC Camera */
2419 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2420 | USB_DEVICE_ID_MATCH_INT_INFO,
2422 .idProduct = 0x0505,
2423 .bInterfaceClass = USB_CLASS_VIDEO,
2424 .bInterfaceSubClass = 1,
2425 .bInterfaceProtocol = 0,
2426 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2427 /* Hercules Classic Silver */
2428 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2429 | USB_DEVICE_ID_MATCH_INT_INFO,
2431 .idProduct = 0x300c,
2432 .bInterfaceClass = USB_CLASS_VIDEO,
2433 .bInterfaceSubClass = 1,
2434 .bInterfaceProtocol = 0,
2435 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2437 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2438 | USB_DEVICE_ID_MATCH_INT_INFO,
2440 .idProduct = 0x332d,
2441 .bInterfaceClass = USB_CLASS_VIDEO,
2442 .bInterfaceSubClass = 1,
2443 .bInterfaceProtocol = 0,
2444 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2445 /* ViMicro - Minoru3D */
2446 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2447 | USB_DEVICE_ID_MATCH_INT_INFO,
2449 .idProduct = 0x3410,
2450 .bInterfaceClass = USB_CLASS_VIDEO,
2451 .bInterfaceSubClass = 1,
2452 .bInterfaceProtocol = 0,
2453 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2454 /* ViMicro Venus - Minoru3D */
2455 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2456 | USB_DEVICE_ID_MATCH_INT_INFO,
2458 .idProduct = 0x3420,
2459 .bInterfaceClass = USB_CLASS_VIDEO,
2460 .bInterfaceSubClass = 1,
2461 .bInterfaceProtocol = 0,
2462 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2463 /* Ophir Optronics - SPCAM 620U */
2464 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2465 | USB_DEVICE_ID_MATCH_INT_INFO,
2467 .idProduct = 0x0555,
2468 .bInterfaceClass = USB_CLASS_VIDEO,
2469 .bInterfaceSubClass = 1,
2470 .bInterfaceProtocol = 0,
2471 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2473 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2474 | USB_DEVICE_ID_MATCH_INT_INFO,
2476 .idProduct = 0x0004,
2477 .bInterfaceClass = USB_CLASS_VIDEO,
2478 .bInterfaceSubClass = 1,
2479 .bInterfaceProtocol = 0,
2480 .driver_info = UVC_QUIRK_PROBE_MINMAX
2481 | UVC_QUIRK_PROBE_DEF },
2482 /* IMC Networks (Medion Akoya) */
2483 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2484 | USB_DEVICE_ID_MATCH_INT_INFO,
2486 .idProduct = 0x5103,
2487 .bInterfaceClass = USB_CLASS_VIDEO,
2488 .bInterfaceSubClass = 1,
2489 .bInterfaceProtocol = 0,
2490 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2491 /* JMicron USB2.0 XGA WebCam */
2492 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2493 | USB_DEVICE_ID_MATCH_INT_INFO,
2495 .idProduct = 0x0310,
2496 .bInterfaceClass = USB_CLASS_VIDEO,
2497 .bInterfaceSubClass = 1,
2498 .bInterfaceProtocol = 0,
2499 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2500 /* Syntek (HP Spartan) */
2501 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2502 | USB_DEVICE_ID_MATCH_INT_INFO,
2504 .idProduct = 0x5212,
2505 .bInterfaceClass = USB_CLASS_VIDEO,
2506 .bInterfaceSubClass = 1,
2507 .bInterfaceProtocol = 0,
2508 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2509 /* Syntek (Samsung Q310) */
2510 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2511 | USB_DEVICE_ID_MATCH_INT_INFO,
2513 .idProduct = 0x5931,
2514 .bInterfaceClass = USB_CLASS_VIDEO,
2515 .bInterfaceSubClass = 1,
2516 .bInterfaceProtocol = 0,
2517 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2518 /* Syntek (Packard Bell EasyNote MX52 */
2519 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2520 | USB_DEVICE_ID_MATCH_INT_INFO,
2522 .idProduct = 0x8a12,
2523 .bInterfaceClass = USB_CLASS_VIDEO,
2524 .bInterfaceSubClass = 1,
2525 .bInterfaceProtocol = 0,
2526 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2527 /* Syntek (Asus F9SG) */
2528 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2529 | USB_DEVICE_ID_MATCH_INT_INFO,
2531 .idProduct = 0x8a31,
2532 .bInterfaceClass = USB_CLASS_VIDEO,
2533 .bInterfaceSubClass = 1,
2534 .bInterfaceProtocol = 0,
2535 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2536 /* Syntek (Asus U3S) */
2537 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2538 | USB_DEVICE_ID_MATCH_INT_INFO,
2540 .idProduct = 0x8a33,
2541 .bInterfaceClass = USB_CLASS_VIDEO,
2542 .bInterfaceSubClass = 1,
2543 .bInterfaceProtocol = 0,
2544 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2545 /* Syntek (JAOtech Smart Terminal) */
2546 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2547 | USB_DEVICE_ID_MATCH_INT_INFO,
2549 .idProduct = 0x8a34,
2550 .bInterfaceClass = USB_CLASS_VIDEO,
2551 .bInterfaceSubClass = 1,
2552 .bInterfaceProtocol = 0,
2553 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2555 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2556 | USB_DEVICE_ID_MATCH_INT_INFO,
2558 .idProduct = 0x0202,
2559 .bInterfaceClass = USB_CLASS_VIDEO,
2560 .bInterfaceSubClass = 1,
2561 .bInterfaceProtocol = 0,
2562 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2563 /* Lenovo Thinkpad SL400/SL500 */
2564 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2565 | USB_DEVICE_ID_MATCH_INT_INFO,
2567 .idProduct = 0x480b,
2568 .bInterfaceClass = USB_CLASS_VIDEO,
2569 .bInterfaceSubClass = 1,
2570 .bInterfaceProtocol = 0,
2571 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2572 /* Aveo Technology USB 2.0 Camera */
2573 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2574 | USB_DEVICE_ID_MATCH_INT_INFO,
2576 .idProduct = 0x0306,
2577 .bInterfaceClass = USB_CLASS_VIDEO,
2578 .bInterfaceSubClass = 1,
2579 .bInterfaceProtocol = 0,
2580 .driver_info = UVC_QUIRK_PROBE_MINMAX
2581 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2582 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2583 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2584 | USB_DEVICE_ID_MATCH_INT_INFO,
2586 .idProduct = 0x0516,
2587 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2588 .bInterfaceSubClass = 1,
2589 .bInterfaceProtocol = 0 },
2590 /* Ecamm Pico iMage */
2591 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2592 | USB_DEVICE_ID_MATCH_INT_INFO,
2594 .idProduct = 0xcafe,
2595 .bInterfaceClass = USB_CLASS_VIDEO,
2596 .bInterfaceSubClass = 1,
2597 .bInterfaceProtocol = 0,
2598 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2599 /* Manta MM-353 Plako */
2600 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2601 | USB_DEVICE_ID_MATCH_INT_INFO,
2603 .idProduct = 0x3188,
2604 .bInterfaceClass = USB_CLASS_VIDEO,
2605 .bInterfaceSubClass = 1,
2606 .bInterfaceProtocol = 0,
2607 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2608 /* FSC WebCam V30S */
2609 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2610 | USB_DEVICE_ID_MATCH_INT_INFO,
2612 .idProduct = 0x3288,
2613 .bInterfaceClass = USB_CLASS_VIDEO,
2614 .bInterfaceSubClass = 1,
2615 .bInterfaceProtocol = 0,
2616 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2617 /* Arkmicro unbranded */
2618 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2619 | USB_DEVICE_ID_MATCH_INT_INFO,
2621 .idProduct = 0x3290,
2622 .bInterfaceClass = USB_CLASS_VIDEO,
2623 .bInterfaceSubClass = 1,
2624 .bInterfaceProtocol = 0,
2625 .driver_info = UVC_QUIRK_PROBE_DEF },
2626 /* The Imaging Source USB CCD cameras */
2627 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2628 | USB_DEVICE_ID_MATCH_INT_INFO,
2630 .idProduct = 0x8102,
2631 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2632 .bInterfaceSubClass = 1,
2633 .bInterfaceProtocol = 0 },
2634 /* Bodelin ProScopeHR */
2635 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2636 | USB_DEVICE_ID_MATCH_DEV_HI
2637 | USB_DEVICE_ID_MATCH_INT_INFO,
2639 .idProduct = 0x1000,
2640 .bcdDevice_hi = 0x0126,
2641 .bInterfaceClass = USB_CLASS_VIDEO,
2642 .bInterfaceSubClass = 1,
2643 .bInterfaceProtocol = 0,
2644 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2645 /* MSI StarCam 370i */
2646 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2647 | USB_DEVICE_ID_MATCH_INT_INFO,
2649 .idProduct = 0x2951,
2650 .bInterfaceClass = USB_CLASS_VIDEO,
2651 .bInterfaceSubClass = 1,
2652 .bInterfaceProtocol = 0,
2653 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2654 /* SiGma Micro USB Web Camera */
2655 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2656 | USB_DEVICE_ID_MATCH_INT_INFO,
2658 .idProduct = 0x3000,
2659 .bInterfaceClass = USB_CLASS_VIDEO,
2660 .bInterfaceSubClass = 1,
2661 .bInterfaceProtocol = 0,
2662 .driver_info = UVC_QUIRK_PROBE_MINMAX
2663 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2664 /* Oculus VR Positional Tracker DK2 */
2665 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2666 | USB_DEVICE_ID_MATCH_INT_INFO,
2668 .idProduct = 0x0201,
2669 .bInterfaceClass = USB_CLASS_VIDEO,
2670 .bInterfaceSubClass = 1,
2671 .bInterfaceProtocol = 0,
2672 .driver_info = UVC_QUIRK_FORCE_Y8 },
2673 /* Generic USB Video Class */
2674 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
2675 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
2679 MODULE_DEVICE_TABLE(usb, uvc_ids);
2681 struct uvc_driver uvc_driver = {
2685 .disconnect = uvc_disconnect,
2686 .suspend = uvc_suspend,
2687 .resume = uvc_resume,
2688 .reset_resume = uvc_reset_resume,
2689 .id_table = uvc_ids,
2690 .supports_autosuspend = 1,
2694 static int __init uvc_init(void)
2700 ret = usb_register(&uvc_driver.driver);
2702 uvc_debugfs_cleanup();
2706 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2710 static void __exit uvc_cleanup(void)
2712 usb_deregister(&uvc_driver.driver);
2713 uvc_debugfs_cleanup();
2716 module_init(uvc_init);
2717 module_exit(uvc_cleanup);
2719 MODULE_AUTHOR(DRIVER_AUTHOR);
2720 MODULE_DESCRIPTION(DRIVER_DESC);
2721 MODULE_LICENSE("GPL");
2722 MODULE_VERSION(DRIVER_VERSION);