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_no_drop_param;
36 static unsigned int uvc_quirks_param = -1;
37 unsigned int uvc_trace_param;
38 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
40 /* ------------------------------------------------------------------------
44 static struct uvc_format_desc uvc_fmts[] = {
46 .name = "YUV 4:2:2 (YUYV)",
47 .guid = UVC_GUID_FORMAT_YUY2,
48 .fcc = V4L2_PIX_FMT_YUYV,
51 .name = "YUV 4:2:2 (YUYV)",
52 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
53 .fcc = V4L2_PIX_FMT_YUYV,
56 .name = "YUV 4:2:0 (NV12)",
57 .guid = UVC_GUID_FORMAT_NV12,
58 .fcc = V4L2_PIX_FMT_NV12,
62 .guid = UVC_GUID_FORMAT_MJPEG,
63 .fcc = V4L2_PIX_FMT_MJPEG,
66 .name = "YVU 4:2:0 (YV12)",
67 .guid = UVC_GUID_FORMAT_YV12,
68 .fcc = V4L2_PIX_FMT_YVU420,
71 .name = "YUV 4:2:0 (I420)",
72 .guid = UVC_GUID_FORMAT_I420,
73 .fcc = V4L2_PIX_FMT_YUV420,
76 .name = "YUV 4:2:0 (M420)",
77 .guid = UVC_GUID_FORMAT_M420,
78 .fcc = V4L2_PIX_FMT_M420,
81 .name = "YUV 4:2:2 (UYVY)",
82 .guid = UVC_GUID_FORMAT_UYVY,
83 .fcc = V4L2_PIX_FMT_UYVY,
86 .name = "Greyscale 8-bit (Y800)",
87 .guid = UVC_GUID_FORMAT_Y800,
88 .fcc = V4L2_PIX_FMT_GREY,
91 .name = "Greyscale 8-bit (Y8 )",
92 .guid = UVC_GUID_FORMAT_Y8,
93 .fcc = V4L2_PIX_FMT_GREY,
96 .name = "Greyscale 10-bit (Y10 )",
97 .guid = UVC_GUID_FORMAT_Y10,
98 .fcc = V4L2_PIX_FMT_Y10,
101 .name = "Greyscale 12-bit (Y12 )",
102 .guid = UVC_GUID_FORMAT_Y12,
103 .fcc = V4L2_PIX_FMT_Y12,
106 .name = "Greyscale 16-bit (Y16 )",
107 .guid = UVC_GUID_FORMAT_Y16,
108 .fcc = V4L2_PIX_FMT_Y16,
111 .name = "BGGR Bayer (BY8 )",
112 .guid = UVC_GUID_FORMAT_BY8,
113 .fcc = V4L2_PIX_FMT_SBGGR8,
116 .name = "BGGR Bayer (BA81)",
117 .guid = UVC_GUID_FORMAT_BA81,
118 .fcc = V4L2_PIX_FMT_SBGGR8,
121 .name = "GBRG Bayer (GBRG)",
122 .guid = UVC_GUID_FORMAT_GBRG,
123 .fcc = V4L2_PIX_FMT_SGBRG8,
126 .name = "GRBG Bayer (GRBG)",
127 .guid = UVC_GUID_FORMAT_GRBG,
128 .fcc = V4L2_PIX_FMT_SGRBG8,
131 .name = "RGGB Bayer (RGGB)",
132 .guid = UVC_GUID_FORMAT_RGGB,
133 .fcc = V4L2_PIX_FMT_SRGGB8,
137 .guid = UVC_GUID_FORMAT_RGBP,
138 .fcc = V4L2_PIX_FMT_RGB565,
141 .name = "BGR 8:8:8 (BGR3)",
142 .guid = UVC_GUID_FORMAT_BGR3,
143 .fcc = V4L2_PIX_FMT_BGR24,
147 .guid = UVC_GUID_FORMAT_H264,
148 .fcc = V4L2_PIX_FMT_H264,
152 /* ------------------------------------------------------------------------
156 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
159 struct usb_host_endpoint *ep;
162 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
163 ep = &alts->endpoint[i];
164 if (ep->desc.bEndpointAddress == epaddr)
171 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
173 unsigned int len = ARRAY_SIZE(uvc_fmts);
176 for (i = 0; i < len; ++i) {
177 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
184 static __u32 uvc_colorspace(const __u8 primaries)
186 static const __u8 colorprimaries[] = {
188 V4L2_COLORSPACE_SRGB,
189 V4L2_COLORSPACE_470_SYSTEM_M,
190 V4L2_COLORSPACE_470_SYSTEM_BG,
191 V4L2_COLORSPACE_SMPTE170M,
192 V4L2_COLORSPACE_SMPTE240M,
195 if (primaries < ARRAY_SIZE(colorprimaries))
196 return colorprimaries[primaries];
201 /* Simplify a fraction using a simple continued fraction decomposition. The
202 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
203 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
204 * arbitrary parameters to remove non-significative terms from the simple
205 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
206 * respectively seems to give nice results.
208 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
209 unsigned int n_terms, unsigned int threshold)
215 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
219 /* Convert the fraction to a simple continued fraction. See
220 * http://mathforum.org/dr.math/faq/faq.fractions.html
221 * Stop if the current term is bigger than or equal to the given
227 for (n = 0; n < n_terms && y != 0; ++n) {
229 if (an[n] >= threshold) {
240 /* Expand the simple continued fraction back to an integer fraction. */
244 for (i = n; i > 0; --i) {
255 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
256 * to compute numerator / denominator * 10000000 using 32 bit fixed point
259 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
263 /* Saturate the result if the operation would overflow. */
264 if (denominator == 0 ||
265 numerator/denominator >= ((uint32_t)-1)/10000000)
268 /* Divide both the denominator and the multiplier by two until
269 * numerator * multiplier doesn't overflow. If anyone knows a better
270 * algorithm please let me know.
272 multiplier = 10000000;
273 while (numerator > ((uint32_t)-1)/multiplier) {
278 return denominator ? numerator * multiplier / denominator : 0;
281 /* ------------------------------------------------------------------------
282 * Terminal and unit management
285 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
287 struct uvc_entity *entity;
289 list_for_each_entry(entity, &dev->entities, list) {
290 if (entity->id == id)
297 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
298 int id, struct uvc_entity *entity)
303 entity = list_entry(&dev->entities, struct uvc_entity, list);
305 list_for_each_entry_continue(entity, &dev->entities, list) {
306 for (i = 0; i < entity->bNrInPins; ++i)
307 if (entity->baSourceID[i] == id)
314 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
316 struct uvc_streaming *stream;
318 list_for_each_entry(stream, &dev->streams, list) {
319 if (stream->header.bTerminalLink == id)
326 /* ------------------------------------------------------------------------
327 * Descriptors parsing
330 static int uvc_parse_format(struct uvc_device *dev,
331 struct uvc_streaming *streaming, struct uvc_format *format,
332 __u32 **intervals, unsigned char *buffer, int buflen)
334 struct usb_interface *intf = streaming->intf;
335 struct usb_host_interface *alts = intf->cur_altsetting;
336 struct uvc_format_desc *fmtdesc;
337 struct uvc_frame *frame;
338 const unsigned char *start = buffer;
339 unsigned int width_multiplier = 1;
340 unsigned int interval;
344 format->type = buffer[2];
345 format->index = buffer[3];
348 case UVC_VS_FORMAT_UNCOMPRESSED:
349 case UVC_VS_FORMAT_FRAME_BASED:
350 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
352 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
353 "interface %d FORMAT error\n",
355 alts->desc.bInterfaceNumber);
359 /* Find the format descriptor from its GUID. */
360 fmtdesc = uvc_format_by_guid(&buffer[5]);
362 if (fmtdesc != NULL) {
363 strlcpy(format->name, fmtdesc->name,
364 sizeof format->name);
365 format->fcc = fmtdesc->fcc;
367 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
369 snprintf(format->name, sizeof(format->name), "%pUl\n",
374 format->bpp = buffer[21];
376 /* Some devices report a format that doesn't match what they
379 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
380 if (format->fcc == V4L2_PIX_FMT_YUYV) {
381 strlcpy(format->name, "Greyscale 8-bit (Y8 )",
382 sizeof(format->name));
383 format->fcc = V4L2_PIX_FMT_GREY;
385 width_multiplier = 2;
389 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
390 ftype = UVC_VS_FRAME_UNCOMPRESSED;
392 ftype = UVC_VS_FRAME_FRAME_BASED;
394 format->flags = UVC_FMT_FLAG_COMPRESSED;
398 case UVC_VS_FORMAT_MJPEG:
400 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
401 "interface %d FORMAT error\n",
403 alts->desc.bInterfaceNumber);
407 strlcpy(format->name, "MJPEG", sizeof format->name);
408 format->fcc = V4L2_PIX_FMT_MJPEG;
409 format->flags = UVC_FMT_FLAG_COMPRESSED;
411 ftype = UVC_VS_FRAME_MJPEG;
414 case UVC_VS_FORMAT_DV:
416 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
417 "interface %d FORMAT error\n",
419 alts->desc.bInterfaceNumber);
423 switch (buffer[8] & 0x7f) {
425 strlcpy(format->name, "SD-DV", sizeof format->name);
428 strlcpy(format->name, "SDL-DV", sizeof format->name);
431 strlcpy(format->name, "HD-DV", sizeof format->name);
434 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
435 "interface %d: unknown DV format %u\n",
437 alts->desc.bInterfaceNumber, buffer[8]);
441 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
442 sizeof format->name);
444 format->fcc = V4L2_PIX_FMT_DV;
445 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
449 /* Create a dummy frame descriptor. */
450 frame = &format->frame[0];
451 memset(&format->frame[0], 0, sizeof format->frame[0]);
452 frame->bFrameIntervalType = 1;
453 frame->dwDefaultFrameInterval = 1;
454 frame->dwFrameInterval = *intervals;
459 case UVC_VS_FORMAT_MPEG2TS:
460 case UVC_VS_FORMAT_STREAM_BASED:
461 /* Not supported yet. */
463 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
464 "interface %d unsupported format %u\n",
465 dev->udev->devnum, alts->desc.bInterfaceNumber,
470 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
475 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
476 * based formats have frame descriptors.
478 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
479 buffer[2] == ftype) {
480 frame = &format->frame[format->nframes];
481 if (ftype != UVC_VS_FRAME_FRAME_BASED)
482 n = buflen > 25 ? buffer[25] : 0;
484 n = buflen > 21 ? buffer[21] : 0;
488 if (buflen < 26 + 4*n) {
489 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
490 "interface %d FRAME error\n", dev->udev->devnum,
491 alts->desc.bInterfaceNumber);
495 frame->bFrameIndex = buffer[3];
496 frame->bmCapabilities = buffer[4];
497 frame->wWidth = get_unaligned_le16(&buffer[5])
499 frame->wHeight = get_unaligned_le16(&buffer[7]);
500 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
501 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
502 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
503 frame->dwMaxVideoFrameBufferSize =
504 get_unaligned_le32(&buffer[17]);
505 frame->dwDefaultFrameInterval =
506 get_unaligned_le32(&buffer[21]);
507 frame->bFrameIntervalType = buffer[25];
509 frame->dwMaxVideoFrameBufferSize = 0;
510 frame->dwDefaultFrameInterval =
511 get_unaligned_le32(&buffer[17]);
512 frame->bFrameIntervalType = buffer[21];
514 frame->dwFrameInterval = *intervals;
516 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
517 * completely. Observed behaviours range from setting the
518 * value to 1.1x the actual frame size to hardwiring the
519 * 16 low bits to 0. This results in a higher than necessary
520 * memory usage as well as a wrong image size information. For
521 * uncompressed formats this can be fixed by computing the
522 * value from the frame size.
524 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
525 frame->dwMaxVideoFrameBufferSize = format->bpp
526 * frame->wWidth * frame->wHeight / 8;
528 /* Some bogus devices report dwMinFrameInterval equal to
529 * dwMaxFrameInterval and have dwFrameIntervalStep set to
530 * zero. Setting all null intervals to 1 fixes the problem and
531 * some other divisions by zero that could happen.
533 for (i = 0; i < n; ++i) {
534 interval = get_unaligned_le32(&buffer[26+4*i]);
535 *(*intervals)++ = interval ? interval : 1;
538 /* Make sure that the default frame interval stays between
541 n -= frame->bFrameIntervalType ? 1 : 2;
542 frame->dwDefaultFrameInterval =
543 min(frame->dwFrameInterval[n],
544 max(frame->dwFrameInterval[0],
545 frame->dwDefaultFrameInterval));
547 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
548 frame->bFrameIntervalType = 1;
549 frame->dwFrameInterval[0] =
550 frame->dwDefaultFrameInterval;
553 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
554 frame->wWidth, frame->wHeight,
555 10000000/frame->dwDefaultFrameInterval,
556 (100000000/frame->dwDefaultFrameInterval)%10);
563 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
564 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
569 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
570 buffer[2] == UVC_VS_COLORFORMAT) {
572 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
573 "interface %d COLORFORMAT error\n",
575 alts->desc.bInterfaceNumber);
579 format->colorspace = uvc_colorspace(buffer[3]);
585 return buffer - start;
588 static int uvc_parse_streaming(struct uvc_device *dev,
589 struct usb_interface *intf)
591 struct uvc_streaming *streaming = NULL;
592 struct uvc_format *format;
593 struct uvc_frame *frame;
594 struct usb_host_interface *alts = &intf->altsetting[0];
595 unsigned char *_buffer, *buffer = alts->extra;
596 int _buflen, buflen = alts->extralen;
597 unsigned int nformats = 0, nframes = 0, nintervals = 0;
598 unsigned int size, i, n, p;
603 if (intf->cur_altsetting->desc.bInterfaceSubClass
604 != UVC_SC_VIDEOSTREAMING) {
605 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
606 "video streaming interface\n", dev->udev->devnum,
607 intf->altsetting[0].desc.bInterfaceNumber);
611 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
612 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
613 "claimed\n", dev->udev->devnum,
614 intf->altsetting[0].desc.bInterfaceNumber);
618 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
619 if (streaming == NULL) {
620 usb_driver_release_interface(&uvc_driver.driver, intf);
624 mutex_init(&streaming->mutex);
625 streaming->dev = dev;
626 streaming->intf = usb_get_intf(intf);
627 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
629 /* The Pico iMage webcam has its class-specific interface descriptors
630 * after the endpoint descriptors.
633 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
634 struct usb_host_endpoint *ep = &alts->endpoint[i];
636 if (ep->extralen == 0)
639 if (ep->extralen > 2 &&
640 ep->extra[1] == USB_DT_CS_INTERFACE) {
641 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
642 "from endpoint %u.\n", i);
643 buffer = alts->endpoint[i].extra;
644 buflen = alts->endpoint[i].extralen;
650 /* Skip the standard interface descriptors. */
651 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
657 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
658 "interface descriptors found.\n");
662 /* Parse the header descriptor. */
664 case UVC_VS_OUTPUT_HEADER:
665 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
669 case UVC_VS_INPUT_HEADER:
670 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
675 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
676 "%d HEADER descriptor not found.\n", dev->udev->devnum,
677 alts->desc.bInterfaceNumber);
681 p = buflen >= 4 ? buffer[3] : 0;
682 n = buflen >= size ? buffer[size-1] : 0;
684 if (buflen < size + p*n) {
685 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
686 "interface %d HEADER descriptor is invalid.\n",
687 dev->udev->devnum, alts->desc.bInterfaceNumber);
691 streaming->header.bNumFormats = p;
692 streaming->header.bEndpointAddress = buffer[6];
693 if (buffer[2] == UVC_VS_INPUT_HEADER) {
694 streaming->header.bmInfo = buffer[7];
695 streaming->header.bTerminalLink = buffer[8];
696 streaming->header.bStillCaptureMethod = buffer[9];
697 streaming->header.bTriggerSupport = buffer[10];
698 streaming->header.bTriggerUsage = buffer[11];
700 streaming->header.bTerminalLink = buffer[7];
702 streaming->header.bControlSize = n;
704 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
706 if (streaming->header.bmaControls == NULL) {
717 /* Count the format and frame descriptors. */
718 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
719 switch (_buffer[2]) {
720 case UVC_VS_FORMAT_UNCOMPRESSED:
721 case UVC_VS_FORMAT_MJPEG:
722 case UVC_VS_FORMAT_FRAME_BASED:
726 case UVC_VS_FORMAT_DV:
727 /* DV format has no frame descriptor. We will create a
728 * dummy frame descriptor with a dummy frame interval.
735 case UVC_VS_FORMAT_MPEG2TS:
736 case UVC_VS_FORMAT_STREAM_BASED:
737 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
738 "interface %d FORMAT %u is not supported.\n",
740 alts->desc.bInterfaceNumber, _buffer[2]);
743 case UVC_VS_FRAME_UNCOMPRESSED:
744 case UVC_VS_FRAME_MJPEG:
747 nintervals += _buffer[25] ? _buffer[25] : 3;
750 case UVC_VS_FRAME_FRAME_BASED:
753 nintervals += _buffer[21] ? _buffer[21] : 3;
757 _buflen -= _buffer[0];
758 _buffer += _buffer[0];
762 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
763 "%d has no supported formats defined.\n",
764 dev->udev->devnum, alts->desc.bInterfaceNumber);
768 size = nformats * sizeof *format + nframes * sizeof *frame
769 + nintervals * sizeof *interval;
770 format = kzalloc(size, GFP_KERNEL);
771 if (format == NULL) {
776 frame = (struct uvc_frame *)&format[nformats];
777 interval = (__u32 *)&frame[nframes];
779 streaming->format = format;
780 streaming->nformats = nformats;
782 /* Parse the format descriptors. */
783 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
785 case UVC_VS_FORMAT_UNCOMPRESSED:
786 case UVC_VS_FORMAT_MJPEG:
787 case UVC_VS_FORMAT_DV:
788 case UVC_VS_FORMAT_FRAME_BASED:
789 format->frame = frame;
790 ret = uvc_parse_format(dev, streaming, format,
791 &interval, buffer, buflen);
795 frame += format->nframes;
811 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
812 "%d has %u bytes of trailing descriptor garbage.\n",
813 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
815 /* Parse the alternate settings to find the maximum bandwidth. */
816 for (i = 0; i < intf->num_altsetting; ++i) {
817 struct usb_host_endpoint *ep;
818 alts = &intf->altsetting[i];
819 ep = uvc_find_endpoint(alts,
820 streaming->header.bEndpointAddress);
824 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
825 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
826 if (psize > streaming->maxpsize)
827 streaming->maxpsize = psize;
830 list_add_tail(&streaming->list, &dev->streams);
834 usb_driver_release_interface(&uvc_driver.driver, intf);
836 kfree(streaming->format);
837 kfree(streaming->header.bmaControls);
842 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
843 unsigned int num_pads, unsigned int extra_size)
845 struct uvc_entity *entity;
846 unsigned int num_inputs;
850 extra_size = ALIGN(extra_size, sizeof(*entity->pads));
851 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
852 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
854 entity = kzalloc(size, GFP_KERNEL);
861 entity->num_links = 0;
862 entity->num_pads = num_pads;
863 entity->pads = ((void *)(entity + 1)) + extra_size;
865 for (i = 0; i < num_inputs; ++i)
866 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
867 if (!UVC_ENTITY_IS_OTERM(entity))
868 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
870 entity->bNrInPins = num_inputs;
871 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
876 /* Parse vendor-specific extensions. */
877 static int uvc_parse_vendor_control(struct uvc_device *dev,
878 const unsigned char *buffer, int buflen)
880 struct usb_device *udev = dev->udev;
881 struct usb_host_interface *alts = dev->intf->cur_altsetting;
882 struct uvc_entity *unit;
886 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
887 case 0x046d: /* Logitech */
888 if (buffer[1] != 0x41 || buffer[2] != 0x01)
891 /* Logitech implements several vendor specific functions
892 * through vendor specific extension units (LXU).
894 * The LXU descriptors are similar to XU descriptors
895 * (see "USB Device Video Class for Video Devices", section
896 * 3.7.2.6 "Extension Unit Descriptor") with the following
899 * ----------------------------------------------------------
901 * Size of this descriptor, in bytes: 24+p+n*2
902 * ----------------------------------------------------------
903 * 23+p+n bmControlsType N Bitmap
904 * Individual bits in the set are defined:
908 * This bitset is mapped exactly the same as bmControls.
909 * ----------------------------------------------------------
910 * 23+p+n*2 bReserved 1 Boolean
911 * ----------------------------------------------------------
912 * 24+p+n*2 iExtension 1 Index
913 * Index of a string descriptor that describes this
915 * ----------------------------------------------------------
917 p = buflen >= 22 ? buffer[21] : 0;
918 n = buflen >= 25 + p ? buffer[22+p] : 0;
920 if (buflen < 25 + p + 2*n) {
921 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
922 "interface %d EXTENSION_UNIT error\n",
923 udev->devnum, alts->desc.bInterfaceNumber);
927 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
932 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
933 unit->extension.bNumControls = buffer[20];
934 memcpy(unit->baSourceID, &buffer[22], p);
935 unit->extension.bControlSize = buffer[22+p];
936 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
937 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
939 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
941 if (buffer[24+p+2*n] != 0)
942 usb_string(udev, buffer[24+p+2*n], unit->name,
945 sprintf(unit->name, "Extension %u", buffer[3]);
947 list_add_tail(&unit->list, &dev->entities);
955 static int uvc_parse_standard_control(struct uvc_device *dev,
956 const unsigned char *buffer, int buflen)
958 struct usb_device *udev = dev->udev;
959 struct uvc_entity *unit, *term;
960 struct usb_interface *intf;
961 struct usb_host_interface *alts = dev->intf->cur_altsetting;
962 unsigned int i, n, p, len;
967 n = buflen >= 12 ? buffer[11] : 0;
969 if (buflen < 12 + n) {
970 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
971 "interface %d HEADER error\n", udev->devnum,
972 alts->desc.bInterfaceNumber);
976 dev->uvc_version = get_unaligned_le16(&buffer[3]);
977 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
979 /* Parse all USB Video Streaming interfaces. */
980 for (i = 0; i < n; ++i) {
981 intf = usb_ifnum_to_if(udev, buffer[12+i]);
983 uvc_trace(UVC_TRACE_DESCR, "device %d "
984 "interface %d doesn't exists\n",
989 uvc_parse_streaming(dev, intf);
993 case UVC_VC_INPUT_TERMINAL:
995 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
996 "interface %d INPUT_TERMINAL error\n",
997 udev->devnum, alts->desc.bInterfaceNumber);
1001 /* Make sure the terminal type MSB is not null, otherwise it
1002 * could be confused with a unit.
1004 type = get_unaligned_le16(&buffer[4]);
1005 if ((type & 0xff00) == 0) {
1006 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1007 "interface %d INPUT_TERMINAL %d has invalid "
1008 "type 0x%04x, skipping\n", udev->devnum,
1009 alts->desc.bInterfaceNumber,
1018 if (type == UVC_ITT_CAMERA) {
1019 n = buflen >= 15 ? buffer[14] : 0;
1022 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1023 n = buflen >= 9 ? buffer[8] : 0;
1024 p = buflen >= 10 + n ? buffer[9+n] : 0;
1028 if (buflen < len + n + p) {
1029 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1030 "interface %d INPUT_TERMINAL error\n",
1031 udev->devnum, alts->desc.bInterfaceNumber);
1035 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1040 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1041 term->camera.bControlSize = n;
1042 term->camera.bmControls = (__u8 *)term + sizeof *term;
1043 term->camera.wObjectiveFocalLengthMin =
1044 get_unaligned_le16(&buffer[8]);
1045 term->camera.wObjectiveFocalLengthMax =
1046 get_unaligned_le16(&buffer[10]);
1047 term->camera.wOcularFocalLength =
1048 get_unaligned_le16(&buffer[12]);
1049 memcpy(term->camera.bmControls, &buffer[15], n);
1050 } else if (UVC_ENTITY_TYPE(term) ==
1051 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1052 term->media.bControlSize = n;
1053 term->media.bmControls = (__u8 *)term + sizeof *term;
1054 term->media.bTransportModeSize = p;
1055 term->media.bmTransportModes = (__u8 *)term
1057 memcpy(term->media.bmControls, &buffer[9], n);
1058 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1062 usb_string(udev, buffer[7], term->name,
1064 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1065 sprintf(term->name, "Camera %u", buffer[3]);
1066 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1067 sprintf(term->name, "Media %u", buffer[3]);
1069 sprintf(term->name, "Input %u", buffer[3]);
1071 list_add_tail(&term->list, &dev->entities);
1074 case UVC_VC_OUTPUT_TERMINAL:
1076 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1077 "interface %d OUTPUT_TERMINAL error\n",
1078 udev->devnum, alts->desc.bInterfaceNumber);
1082 /* Make sure the terminal type MSB is not null, otherwise it
1083 * could be confused with a unit.
1085 type = get_unaligned_le16(&buffer[4]);
1086 if ((type & 0xff00) == 0) {
1087 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1088 "interface %d OUTPUT_TERMINAL %d has invalid "
1089 "type 0x%04x, skipping\n", udev->devnum,
1090 alts->desc.bInterfaceNumber, buffer[3], type);
1094 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1099 memcpy(term->baSourceID, &buffer[7], 1);
1102 usb_string(udev, buffer[8], term->name,
1105 sprintf(term->name, "Output %u", buffer[3]);
1107 list_add_tail(&term->list, &dev->entities);
1110 case UVC_VC_SELECTOR_UNIT:
1111 p = buflen >= 5 ? buffer[4] : 0;
1113 if (buflen < 5 || buflen < 6 + p) {
1114 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1115 "interface %d SELECTOR_UNIT error\n",
1116 udev->devnum, alts->desc.bInterfaceNumber);
1120 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1124 memcpy(unit->baSourceID, &buffer[5], p);
1126 if (buffer[5+p] != 0)
1127 usb_string(udev, buffer[5+p], unit->name,
1130 sprintf(unit->name, "Selector %u", buffer[3]);
1132 list_add_tail(&unit->list, &dev->entities);
1135 case UVC_VC_PROCESSING_UNIT:
1136 n = buflen >= 8 ? buffer[7] : 0;
1137 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1139 if (buflen < p + n) {
1140 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1141 "interface %d PROCESSING_UNIT error\n",
1142 udev->devnum, alts->desc.bInterfaceNumber);
1146 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1150 memcpy(unit->baSourceID, &buffer[4], 1);
1151 unit->processing.wMaxMultiplier =
1152 get_unaligned_le16(&buffer[5]);
1153 unit->processing.bControlSize = buffer[7];
1154 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1155 memcpy(unit->processing.bmControls, &buffer[8], n);
1156 if (dev->uvc_version >= 0x0110)
1157 unit->processing.bmVideoStandards = buffer[9+n];
1159 if (buffer[8+n] != 0)
1160 usb_string(udev, buffer[8+n], unit->name,
1163 sprintf(unit->name, "Processing %u", buffer[3]);
1165 list_add_tail(&unit->list, &dev->entities);
1168 case UVC_VC_EXTENSION_UNIT:
1169 p = buflen >= 22 ? buffer[21] : 0;
1170 n = buflen >= 24 + p ? buffer[22+p] : 0;
1172 if (buflen < 24 + p + n) {
1173 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1174 "interface %d EXTENSION_UNIT error\n",
1175 udev->devnum, alts->desc.bInterfaceNumber);
1179 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1183 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1184 unit->extension.bNumControls = buffer[20];
1185 memcpy(unit->baSourceID, &buffer[22], p);
1186 unit->extension.bControlSize = buffer[22+p];
1187 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1188 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1190 if (buffer[23+p+n] != 0)
1191 usb_string(udev, buffer[23+p+n], unit->name,
1194 sprintf(unit->name, "Extension %u", buffer[3]);
1196 list_add_tail(&unit->list, &dev->entities);
1200 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1201 "descriptor (%u)\n", buffer[2]);
1208 static int uvc_parse_control(struct uvc_device *dev)
1210 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1211 unsigned char *buffer = alts->extra;
1212 int buflen = alts->extralen;
1215 /* Parse the default alternate setting only, as the UVC specification
1216 * defines a single alternate setting, the default alternate setting
1220 while (buflen > 2) {
1221 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1222 buffer[1] != USB_DT_CS_INTERFACE)
1223 goto next_descriptor;
1225 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1229 buflen -= buffer[0];
1230 buffer += buffer[0];
1233 /* Check if the optional status endpoint is present. Built-in iSight
1234 * webcams have an interrupt endpoint but spit proprietary data that
1235 * don't conform to the UVC status endpoint messages. Don't try to
1236 * handle the interrupt endpoint for those cameras.
1238 if (alts->desc.bNumEndpoints == 1 &&
1239 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1240 struct usb_host_endpoint *ep = &alts->endpoint[0];
1241 struct usb_endpoint_descriptor *desc = &ep->desc;
1243 if (usb_endpoint_is_int_in(desc) &&
1244 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1245 desc->bInterval != 0) {
1246 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1247 "(addr %02x).\n", desc->bEndpointAddress);
1255 /* ------------------------------------------------------------------------
1260 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1261 * and containing the following units:
1263 * - one or more Output Terminals (USB Streaming or Display)
1264 * - zero or one Processing Unit
1265 * - zero, one or more single-input Selector Units
1266 * - zero or one multiple-input Selector Units, provided all inputs are
1267 * connected to input terminals
1268 * - zero, one or mode single-input Extension Units
1269 * - one or more Input Terminals (Camera, External or USB Streaming)
1271 * The terminal and units must match on of the following structures:
1273 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1274 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1275 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1277 * +---------+ +---------+ -> OTT_*(0)
1278 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1279 * +---------+ +---------+ -> OTT_*(n)
1281 * The Processing Unit and Extension Units can be in any order. Additional
1282 * Extension Units connected to the main chain as single-unit branches are
1283 * also supported. Single-input Selector Units are ignored.
1285 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1286 struct uvc_entity *entity)
1288 switch (UVC_ENTITY_TYPE(entity)) {
1289 case UVC_VC_EXTENSION_UNIT:
1290 if (uvc_trace_param & UVC_TRACE_PROBE)
1291 printk(" <- XU %d", entity->id);
1293 if (entity->bNrInPins != 1) {
1294 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1295 "than 1 input pin.\n", entity->id);
1301 case UVC_VC_PROCESSING_UNIT:
1302 if (uvc_trace_param & UVC_TRACE_PROBE)
1303 printk(" <- PU %d", entity->id);
1305 if (chain->processing != NULL) {
1306 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1307 "Processing Units in chain.\n");
1311 chain->processing = entity;
1314 case UVC_VC_SELECTOR_UNIT:
1315 if (uvc_trace_param & UVC_TRACE_PROBE)
1316 printk(" <- SU %d", entity->id);
1318 /* Single-input selector units are ignored. */
1319 if (entity->bNrInPins == 1)
1322 if (chain->selector != NULL) {
1323 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1324 "Units in chain.\n");
1328 chain->selector = entity;
1331 case UVC_ITT_VENDOR_SPECIFIC:
1332 case UVC_ITT_CAMERA:
1333 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1334 if (uvc_trace_param & UVC_TRACE_PROBE)
1335 printk(" <- IT %d\n", entity->id);
1339 case UVC_OTT_VENDOR_SPECIFIC:
1340 case UVC_OTT_DISPLAY:
1341 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1342 if (uvc_trace_param & UVC_TRACE_PROBE)
1343 printk(" OT %d", entity->id);
1347 case UVC_TT_STREAMING:
1348 if (UVC_ENTITY_IS_ITERM(entity)) {
1349 if (uvc_trace_param & UVC_TRACE_PROBE)
1350 printk(" <- IT %d\n", entity->id);
1352 if (uvc_trace_param & UVC_TRACE_PROBE)
1353 printk(" OT %d", entity->id);
1359 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1360 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1364 list_add_tail(&entity->chain, &chain->entities);
1368 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1369 struct uvc_entity *entity, struct uvc_entity *prev)
1371 struct uvc_entity *forward;
1379 forward = uvc_entity_by_reference(chain->dev, entity->id,
1381 if (forward == NULL)
1383 if (forward == prev)
1386 switch (UVC_ENTITY_TYPE(forward)) {
1387 case UVC_VC_EXTENSION_UNIT:
1388 if (forward->bNrInPins != 1) {
1389 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1390 "has more than 1 input pin.\n",
1395 list_add_tail(&forward->chain, &chain->entities);
1396 if (uvc_trace_param & UVC_TRACE_PROBE) {
1400 printk(" XU %d", forward->id);
1405 case UVC_OTT_VENDOR_SPECIFIC:
1406 case UVC_OTT_DISPLAY:
1407 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1408 case UVC_TT_STREAMING:
1409 if (UVC_ENTITY_IS_ITERM(forward)) {
1410 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1411 "terminal %u.\n", forward->id);
1415 list_add_tail(&forward->chain, &chain->entities);
1416 if (uvc_trace_param & UVC_TRACE_PROBE) {
1420 printk(" OT %d", forward->id);
1432 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1433 struct uvc_entity **_entity)
1435 struct uvc_entity *entity = *_entity;
1436 struct uvc_entity *term;
1437 int id = -EINVAL, i;
1439 switch (UVC_ENTITY_TYPE(entity)) {
1440 case UVC_VC_EXTENSION_UNIT:
1441 case UVC_VC_PROCESSING_UNIT:
1442 id = entity->baSourceID[0];
1445 case UVC_VC_SELECTOR_UNIT:
1446 /* Single-input selector units are ignored. */
1447 if (entity->bNrInPins == 1) {
1448 id = entity->baSourceID[0];
1452 if (uvc_trace_param & UVC_TRACE_PROBE)
1455 chain->selector = entity;
1456 for (i = 0; i < entity->bNrInPins; ++i) {
1457 id = entity->baSourceID[i];
1458 term = uvc_entity_by_id(chain->dev, id);
1459 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1460 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1461 "input %d isn't connected to an "
1462 "input terminal\n", entity->id, i);
1466 if (uvc_trace_param & UVC_TRACE_PROBE)
1467 printk(" %d", term->id);
1469 list_add_tail(&term->chain, &chain->entities);
1470 uvc_scan_chain_forward(chain, term, entity);
1473 if (uvc_trace_param & UVC_TRACE_PROBE)
1479 case UVC_ITT_VENDOR_SPECIFIC:
1480 case UVC_ITT_CAMERA:
1481 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1482 case UVC_OTT_VENDOR_SPECIFIC:
1483 case UVC_OTT_DISPLAY:
1484 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1485 case UVC_TT_STREAMING:
1486 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1495 entity = uvc_entity_by_id(chain->dev, id);
1496 if (entity == NULL) {
1497 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1498 "unknown entity %d.\n", id);
1506 static int uvc_scan_chain(struct uvc_video_chain *chain,
1507 struct uvc_entity *term)
1509 struct uvc_entity *entity, *prev;
1511 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1516 while (entity != NULL) {
1517 /* Entity must not be part of an existing chain */
1518 if (entity->chain.next || entity->chain.prev) {
1519 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1520 "entity %d already in chain.\n", entity->id);
1524 /* Process entity */
1525 if (uvc_scan_chain_entity(chain, entity) < 0)
1529 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1534 if (uvc_scan_chain_backward(chain, &entity) < 0)
1541 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1544 struct uvc_entity *term;
1545 unsigned int nterms = 0;
1548 list_for_each_entry(term, terms, chain) {
1549 if (!UVC_ENTITY_IS_TERM(term) ||
1550 UVC_TERM_DIRECTION(term) != dir)
1554 p += sprintf(p, ",");
1555 if (++nterms >= 4) {
1556 p += sprintf(p, "...");
1559 p += sprintf(p, "%u", term->id);
1565 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1567 static char buffer[43];
1570 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1571 p += sprintf(p, " -> ");
1572 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1578 * Scan the device for video chains and register video devices.
1580 * Chains are scanned starting at their output terminals and walked backwards.
1582 static int uvc_scan_device(struct uvc_device *dev)
1584 struct uvc_video_chain *chain;
1585 struct uvc_entity *term;
1587 list_for_each_entry(term, &dev->entities, list) {
1588 if (!UVC_ENTITY_IS_OTERM(term))
1591 /* If the terminal is already included in a chain, skip it.
1592 * This can happen for chains that have multiple output
1593 * terminals, where all output terminals beside the first one
1594 * will be inserted in the chain in forward scans.
1596 if (term->chain.next || term->chain.prev)
1599 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1603 INIT_LIST_HEAD(&chain->entities);
1604 mutex_init(&chain->ctrl_mutex);
1606 v4l2_prio_init(&chain->prio);
1608 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1610 if (uvc_scan_chain(chain, term) < 0) {
1615 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1616 uvc_print_chain(chain));
1618 list_add_tail(&chain->list, &dev->chains);
1621 if (list_empty(&dev->chains)) {
1622 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1629 /* ------------------------------------------------------------------------
1630 * Video device registration and unregistration
1634 * Delete the UVC device.
1636 * Called by the kernel when the last reference to the uvc_device structure
1639 * As this function is called after or during disconnect(), all URBs have
1640 * already been canceled by the USB core. There is no need to kill the
1641 * interrupt URB manually.
1643 static void uvc_delete(struct uvc_device *dev)
1645 struct list_head *p, *n;
1647 uvc_status_cleanup(dev);
1648 uvc_ctrl_cleanup_device(dev);
1650 usb_put_intf(dev->intf);
1651 usb_put_dev(dev->udev);
1654 v4l2_device_unregister(&dev->vdev);
1655 #ifdef CONFIG_MEDIA_CONTROLLER
1656 if (media_devnode_is_registered(&dev->mdev.devnode))
1657 media_device_unregister(&dev->mdev);
1660 list_for_each_safe(p, n, &dev->chains) {
1661 struct uvc_video_chain *chain;
1662 chain = list_entry(p, struct uvc_video_chain, list);
1666 list_for_each_safe(p, n, &dev->entities) {
1667 struct uvc_entity *entity;
1668 entity = list_entry(p, struct uvc_entity, list);
1669 #ifdef CONFIG_MEDIA_CONTROLLER
1670 uvc_mc_cleanup_entity(entity);
1675 list_for_each_safe(p, n, &dev->streams) {
1676 struct uvc_streaming *streaming;
1677 streaming = list_entry(p, struct uvc_streaming, list);
1678 usb_driver_release_interface(&uvc_driver.driver,
1680 usb_put_intf(streaming->intf);
1681 kfree(streaming->format);
1682 kfree(streaming->header.bmaControls);
1689 static void uvc_release(struct video_device *vdev)
1691 struct uvc_streaming *stream = video_get_drvdata(vdev);
1692 struct uvc_device *dev = stream->dev;
1694 /* Decrement the registered streams count and delete the device when it
1697 if (atomic_dec_and_test(&dev->nstreams))
1702 * Unregister the video devices.
1704 static void uvc_unregister_video(struct uvc_device *dev)
1706 struct uvc_streaming *stream;
1708 /* Unregistering all video devices might result in uvc_delete() being
1709 * called from inside the loop if there's no open file handle. To avoid
1710 * that, increment the stream count before iterating over the streams
1711 * and decrement it when done.
1713 atomic_inc(&dev->nstreams);
1715 list_for_each_entry(stream, &dev->streams, list) {
1716 if (!video_is_registered(&stream->vdev))
1719 video_unregister_device(&stream->vdev);
1721 uvc_debugfs_cleanup_stream(stream);
1724 /* Decrement the stream count and call uvc_delete explicitly if there
1725 * are no stream left.
1727 if (atomic_dec_and_test(&dev->nstreams))
1731 static int uvc_register_video(struct uvc_device *dev,
1732 struct uvc_streaming *stream)
1734 struct video_device *vdev = &stream->vdev;
1737 /* Initialize the video buffers queue. */
1738 ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1742 /* Initialize the streaming interface with default streaming
1745 ret = uvc_video_init(stream);
1747 uvc_printk(KERN_ERR, "Failed to initialize the device "
1752 uvc_debugfs_init_stream(stream);
1754 /* Register the device with V4L. */
1756 /* We already hold a reference to dev->udev. The video device will be
1757 * unregistered before the reference is released, so we don't need to
1760 vdev->v4l2_dev = &dev->vdev;
1761 vdev->fops = &uvc_fops;
1762 vdev->ioctl_ops = &uvc_ioctl_ops;
1763 vdev->release = uvc_release;
1764 vdev->prio = &stream->chain->prio;
1765 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1766 vdev->vfl_dir = VFL_DIR_TX;
1767 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1769 /* Set the driver data before calling video_register_device, otherwise
1770 * uvc_v4l2_open might race us.
1772 video_set_drvdata(vdev, stream);
1774 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1776 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1781 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1782 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1784 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1786 atomic_inc(&dev->nstreams);
1791 * Register all video devices in all chains.
1793 static int uvc_register_terms(struct uvc_device *dev,
1794 struct uvc_video_chain *chain)
1796 struct uvc_streaming *stream;
1797 struct uvc_entity *term;
1800 list_for_each_entry(term, &chain->entities, chain) {
1801 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1804 stream = uvc_stream_by_id(dev, term->id);
1805 if (stream == NULL) {
1806 uvc_printk(KERN_INFO, "No streaming interface found "
1807 "for terminal %u.", term->id);
1811 stream->chain = chain;
1812 ret = uvc_register_video(dev, stream);
1816 term->vdev = &stream->vdev;
1822 static int uvc_register_chains(struct uvc_device *dev)
1824 struct uvc_video_chain *chain;
1827 list_for_each_entry(chain, &dev->chains, list) {
1828 ret = uvc_register_terms(dev, chain);
1832 #ifdef CONFIG_MEDIA_CONTROLLER
1833 ret = uvc_mc_register_entities(chain);
1835 uvc_printk(KERN_INFO, "Failed to register entites "
1844 /* ------------------------------------------------------------------------
1845 * USB probe, disconnect, suspend and resume
1848 static int uvc_probe(struct usb_interface *intf,
1849 const struct usb_device_id *id)
1851 struct usb_device *udev = interface_to_usbdev(intf);
1852 struct uvc_device *dev;
1855 if (id->idVendor && id->idProduct)
1856 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1857 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1860 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1863 /* Allocate memory for the device and initialize it. */
1864 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1867 INIT_LIST_HEAD(&dev->entities);
1868 INIT_LIST_HEAD(&dev->chains);
1869 INIT_LIST_HEAD(&dev->streams);
1870 atomic_set(&dev->nstreams, 0);
1871 atomic_set(&dev->nmappings, 0);
1872 mutex_init(&dev->lock);
1874 dev->udev = usb_get_dev(udev);
1875 dev->intf = usb_get_intf(intf);
1876 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1877 dev->quirks = (uvc_quirks_param == -1)
1878 ? id->driver_info : uvc_quirks_param;
1880 if (udev->product != NULL)
1881 strlcpy(dev->name, udev->product, sizeof dev->name);
1883 snprintf(dev->name, sizeof dev->name,
1884 "UVC Camera (%04x:%04x)",
1885 le16_to_cpu(udev->descriptor.idVendor),
1886 le16_to_cpu(udev->descriptor.idProduct));
1888 /* Parse the Video Class control descriptor. */
1889 if (uvc_parse_control(dev) < 0) {
1890 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1895 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1896 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1897 udev->product ? udev->product : "<unnamed>",
1898 le16_to_cpu(udev->descriptor.idVendor),
1899 le16_to_cpu(udev->descriptor.idProduct));
1901 if (dev->quirks != id->driver_info) {
1902 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1903 "parameter for testing purpose.\n", dev->quirks);
1904 uvc_printk(KERN_INFO, "Please report required quirks to the "
1905 "linux-uvc-devel mailing list.\n");
1908 /* Register the media and V4L2 devices. */
1909 #ifdef CONFIG_MEDIA_CONTROLLER
1910 dev->mdev.dev = &intf->dev;
1911 strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
1913 strlcpy(dev->mdev.serial, udev->serial,
1914 sizeof(dev->mdev.serial));
1915 strcpy(dev->mdev.bus_info, udev->devpath);
1916 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
1917 dev->mdev.driver_version = LINUX_VERSION_CODE;
1918 if (media_device_register(&dev->mdev) < 0)
1921 dev->vdev.mdev = &dev->mdev;
1923 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
1926 /* Initialize controls. */
1927 if (uvc_ctrl_init_device(dev) < 0)
1930 /* Scan the device for video chains. */
1931 if (uvc_scan_device(dev) < 0)
1934 /* Register video device nodes. */
1935 if (uvc_register_chains(dev) < 0)
1938 /* Save our data pointer in the interface data. */
1939 usb_set_intfdata(intf, dev);
1941 /* Initialize the interrupt URB. */
1942 if ((ret = uvc_status_init(dev)) < 0) {
1943 uvc_printk(KERN_INFO, "Unable to initialize the status "
1944 "endpoint (%d), status interrupt will not be "
1945 "supported.\n", ret);
1948 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1949 usb_enable_autosuspend(udev);
1953 uvc_unregister_video(dev);
1957 static void uvc_disconnect(struct usb_interface *intf)
1959 struct uvc_device *dev = usb_get_intfdata(intf);
1961 /* Set the USB interface data to NULL. This can be done outside the
1962 * lock, as there's no other reader.
1964 usb_set_intfdata(intf, NULL);
1966 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1967 UVC_SC_VIDEOSTREAMING)
1970 uvc_unregister_video(dev);
1973 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1975 struct uvc_device *dev = usb_get_intfdata(intf);
1976 struct uvc_streaming *stream;
1978 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1979 intf->cur_altsetting->desc.bInterfaceNumber);
1981 /* Controls are cached on the fly so they don't need to be saved. */
1982 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1983 UVC_SC_VIDEOCONTROL) {
1984 mutex_lock(&dev->lock);
1986 uvc_status_stop(dev);
1987 mutex_unlock(&dev->lock);
1991 list_for_each_entry(stream, &dev->streams, list) {
1992 if (stream->intf == intf)
1993 return uvc_video_suspend(stream);
1996 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2001 static int __uvc_resume(struct usb_interface *intf, int reset)
2003 struct uvc_device *dev = usb_get_intfdata(intf);
2004 struct uvc_streaming *stream;
2007 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2008 intf->cur_altsetting->desc.bInterfaceNumber);
2010 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2011 UVC_SC_VIDEOCONTROL) {
2013 ret = uvc_ctrl_restore_values(dev);
2018 mutex_lock(&dev->lock);
2020 ret = uvc_status_start(dev, GFP_NOIO);
2021 mutex_unlock(&dev->lock);
2026 list_for_each_entry(stream, &dev->streams, list) {
2027 if (stream->intf == intf) {
2028 ret = uvc_video_resume(stream, reset);
2030 uvc_queue_streamoff(&stream->queue,
2031 stream->queue.queue.type);
2036 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2041 static int uvc_resume(struct usb_interface *intf)
2043 return __uvc_resume(intf, 0);
2046 static int uvc_reset_resume(struct usb_interface *intf)
2048 return __uvc_resume(intf, 1);
2051 /* ------------------------------------------------------------------------
2055 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
2057 if (uvc_clock_param == CLOCK_MONOTONIC)
2058 return sprintf(buffer, "CLOCK_MONOTONIC");
2060 return sprintf(buffer, "CLOCK_REALTIME");
2063 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
2065 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2066 val += strlen("clock_");
2068 if (strcasecmp(val, "monotonic") == 0)
2069 uvc_clock_param = CLOCK_MONOTONIC;
2070 else if (strcasecmp(val, "realtime") == 0)
2071 uvc_clock_param = CLOCK_REALTIME;
2078 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2079 &uvc_clock_param, S_IRUGO|S_IWUSR);
2080 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2081 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2082 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2083 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2084 MODULE_PARM_DESC(quirks, "Forced device quirks");
2085 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2086 MODULE_PARM_DESC(trace, "Trace level bitmask");
2087 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2088 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2090 /* ------------------------------------------------------------------------
2091 * Driver initialization and cleanup
2095 * The Logitech cameras listed below have their interface class set to
2096 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2097 * though they are compliant.
2099 static struct usb_device_id uvc_ids[] = {
2100 /* LogiLink Wireless Webcam */
2101 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2102 | USB_DEVICE_ID_MATCH_INT_INFO,
2104 .idProduct = 0xa91a,
2105 .bInterfaceClass = USB_CLASS_VIDEO,
2106 .bInterfaceSubClass = 1,
2107 .bInterfaceProtocol = 0,
2108 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2109 /* Genius eFace 2025 */
2110 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2111 | USB_DEVICE_ID_MATCH_INT_INFO,
2113 .idProduct = 0x706e,
2114 .bInterfaceClass = USB_CLASS_VIDEO,
2115 .bInterfaceSubClass = 1,
2116 .bInterfaceProtocol = 0,
2117 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2118 /* Microsoft Lifecam NX-6000 */
2119 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2120 | USB_DEVICE_ID_MATCH_INT_INFO,
2122 .idProduct = 0x00f8,
2123 .bInterfaceClass = USB_CLASS_VIDEO,
2124 .bInterfaceSubClass = 1,
2125 .bInterfaceProtocol = 0,
2126 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2127 /* Microsoft Lifecam NX-3000 */
2128 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2129 | USB_DEVICE_ID_MATCH_INT_INFO,
2131 .idProduct = 0x0721,
2132 .bInterfaceClass = USB_CLASS_VIDEO,
2133 .bInterfaceSubClass = 1,
2134 .bInterfaceProtocol = 0,
2135 .driver_info = UVC_QUIRK_PROBE_DEF },
2136 /* Microsoft Lifecam VX-7000 */
2137 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2138 | USB_DEVICE_ID_MATCH_INT_INFO,
2140 .idProduct = 0x0723,
2141 .bInterfaceClass = USB_CLASS_VIDEO,
2142 .bInterfaceSubClass = 1,
2143 .bInterfaceProtocol = 0,
2144 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2145 /* Logitech Quickcam Fusion */
2146 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2147 | USB_DEVICE_ID_MATCH_INT_INFO,
2149 .idProduct = 0x08c1,
2150 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2151 .bInterfaceSubClass = 1,
2152 .bInterfaceProtocol = 0 },
2153 /* Logitech Quickcam Orbit MP */
2154 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2155 | USB_DEVICE_ID_MATCH_INT_INFO,
2157 .idProduct = 0x08c2,
2158 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2159 .bInterfaceSubClass = 1,
2160 .bInterfaceProtocol = 0 },
2161 /* Logitech Quickcam Pro for Notebook */
2162 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2163 | USB_DEVICE_ID_MATCH_INT_INFO,
2165 .idProduct = 0x08c3,
2166 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2167 .bInterfaceSubClass = 1,
2168 .bInterfaceProtocol = 0 },
2169 /* Logitech Quickcam Pro 5000 */
2170 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2171 | USB_DEVICE_ID_MATCH_INT_INFO,
2173 .idProduct = 0x08c5,
2174 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2175 .bInterfaceSubClass = 1,
2176 .bInterfaceProtocol = 0 },
2177 /* Logitech Quickcam OEM Dell Notebook */
2178 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2179 | USB_DEVICE_ID_MATCH_INT_INFO,
2181 .idProduct = 0x08c6,
2182 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2183 .bInterfaceSubClass = 1,
2184 .bInterfaceProtocol = 0 },
2185 /* Logitech Quickcam OEM Cisco VT Camera II */
2186 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2187 | USB_DEVICE_ID_MATCH_INT_INFO,
2189 .idProduct = 0x08c7,
2190 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2191 .bInterfaceSubClass = 1,
2192 .bInterfaceProtocol = 0 },
2193 /* Logitech HD Pro Webcam C920 */
2194 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2195 | USB_DEVICE_ID_MATCH_INT_INFO,
2197 .idProduct = 0x082d,
2198 .bInterfaceClass = USB_CLASS_VIDEO,
2199 .bInterfaceSubClass = 1,
2200 .bInterfaceProtocol = 0,
2201 .driver_info = UVC_QUIRK_RESTORE_CTRLS_ON_INIT },
2202 /* Chicony CNF7129 (Asus EEE 100HE) */
2203 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2204 | USB_DEVICE_ID_MATCH_INT_INFO,
2206 .idProduct = 0xb071,
2207 .bInterfaceClass = USB_CLASS_VIDEO,
2208 .bInterfaceSubClass = 1,
2209 .bInterfaceProtocol = 0,
2210 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2211 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2212 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2213 | USB_DEVICE_ID_MATCH_INT_INFO,
2215 .idProduct = 0x3820,
2216 .bInterfaceClass = USB_CLASS_VIDEO,
2217 .bInterfaceSubClass = 1,
2218 .bInterfaceProtocol = 0,
2219 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2220 /* Dell XPS m1530 */
2221 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2222 | USB_DEVICE_ID_MATCH_INT_INFO,
2224 .idProduct = 0x2640,
2225 .bInterfaceClass = USB_CLASS_VIDEO,
2226 .bInterfaceSubClass = 1,
2227 .bInterfaceProtocol = 0,
2228 .driver_info = UVC_QUIRK_PROBE_DEF },
2229 /* Dell SP2008WFP Monitor */
2230 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2231 | USB_DEVICE_ID_MATCH_INT_INFO,
2233 .idProduct = 0x2641,
2234 .bInterfaceClass = USB_CLASS_VIDEO,
2235 .bInterfaceSubClass = 1,
2236 .bInterfaceProtocol = 0,
2237 .driver_info = UVC_QUIRK_PROBE_DEF },
2238 /* Dell Alienware X51 */
2239 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2240 | USB_DEVICE_ID_MATCH_INT_INFO,
2242 .idProduct = 0x2643,
2243 .bInterfaceClass = USB_CLASS_VIDEO,
2244 .bInterfaceSubClass = 1,
2245 .bInterfaceProtocol = 0,
2246 .driver_info = UVC_QUIRK_PROBE_DEF },
2247 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2248 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2249 | USB_DEVICE_ID_MATCH_INT_INFO,
2251 .idProduct = 0x264a,
2252 .bInterfaceClass = USB_CLASS_VIDEO,
2253 .bInterfaceSubClass = 1,
2254 .bInterfaceProtocol = 0,
2255 .driver_info = UVC_QUIRK_PROBE_DEF },
2256 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2257 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2258 | USB_DEVICE_ID_MATCH_INT_INFO,
2260 .idProduct = 0x7670,
2261 .bInterfaceClass = USB_CLASS_VIDEO,
2262 .bInterfaceSubClass = 1,
2263 .bInterfaceProtocol = 0,
2264 .driver_info = UVC_QUIRK_PROBE_DEF },
2265 /* Apple Built-In iSight */
2266 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2267 | USB_DEVICE_ID_MATCH_INT_INFO,
2269 .idProduct = 0x8501,
2270 .bInterfaceClass = USB_CLASS_VIDEO,
2271 .bInterfaceSubClass = 1,
2272 .bInterfaceProtocol = 0,
2273 .driver_info = UVC_QUIRK_PROBE_MINMAX
2274 | UVC_QUIRK_BUILTIN_ISIGHT },
2275 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2276 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2277 | USB_DEVICE_ID_MATCH_INT_INFO,
2279 .idProduct = 0x0403,
2280 .bInterfaceClass = USB_CLASS_VIDEO,
2281 .bInterfaceSubClass = 1,
2282 .bInterfaceProtocol = 0,
2283 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2284 /* Genesys Logic USB 2.0 PC Camera */
2285 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2286 | USB_DEVICE_ID_MATCH_INT_INFO,
2288 .idProduct = 0x0505,
2289 .bInterfaceClass = USB_CLASS_VIDEO,
2290 .bInterfaceSubClass = 1,
2291 .bInterfaceProtocol = 0,
2292 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2293 /* Hercules Classic Silver */
2294 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2295 | USB_DEVICE_ID_MATCH_INT_INFO,
2297 .idProduct = 0x300c,
2298 .bInterfaceClass = USB_CLASS_VIDEO,
2299 .bInterfaceSubClass = 1,
2300 .bInterfaceProtocol = 0,
2301 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2303 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2304 | USB_DEVICE_ID_MATCH_INT_INFO,
2306 .idProduct = 0x332d,
2307 .bInterfaceClass = USB_CLASS_VIDEO,
2308 .bInterfaceSubClass = 1,
2309 .bInterfaceProtocol = 0,
2310 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2311 /* ViMicro - Minoru3D */
2312 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2313 | USB_DEVICE_ID_MATCH_INT_INFO,
2315 .idProduct = 0x3410,
2316 .bInterfaceClass = USB_CLASS_VIDEO,
2317 .bInterfaceSubClass = 1,
2318 .bInterfaceProtocol = 0,
2319 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2320 /* ViMicro Venus - Minoru3D */
2321 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2322 | USB_DEVICE_ID_MATCH_INT_INFO,
2324 .idProduct = 0x3420,
2325 .bInterfaceClass = USB_CLASS_VIDEO,
2326 .bInterfaceSubClass = 1,
2327 .bInterfaceProtocol = 0,
2328 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2329 /* Ophir Optronics - SPCAM 620U */
2330 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2331 | USB_DEVICE_ID_MATCH_INT_INFO,
2333 .idProduct = 0x0555,
2334 .bInterfaceClass = USB_CLASS_VIDEO,
2335 .bInterfaceSubClass = 1,
2336 .bInterfaceProtocol = 0,
2337 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2339 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2340 | USB_DEVICE_ID_MATCH_INT_INFO,
2342 .idProduct = 0x0004,
2343 .bInterfaceClass = USB_CLASS_VIDEO,
2344 .bInterfaceSubClass = 1,
2345 .bInterfaceProtocol = 0,
2346 .driver_info = UVC_QUIRK_PROBE_MINMAX
2347 | UVC_QUIRK_PROBE_DEF },
2348 /* IMC Networks (Medion Akoya) */
2349 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2350 | USB_DEVICE_ID_MATCH_INT_INFO,
2352 .idProduct = 0x5103,
2353 .bInterfaceClass = USB_CLASS_VIDEO,
2354 .bInterfaceSubClass = 1,
2355 .bInterfaceProtocol = 0,
2356 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2357 /* JMicron USB2.0 XGA WebCam */
2358 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2359 | USB_DEVICE_ID_MATCH_INT_INFO,
2361 .idProduct = 0x0310,
2362 .bInterfaceClass = USB_CLASS_VIDEO,
2363 .bInterfaceSubClass = 1,
2364 .bInterfaceProtocol = 0,
2365 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2366 /* Syntek (HP Spartan) */
2367 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2368 | USB_DEVICE_ID_MATCH_INT_INFO,
2370 .idProduct = 0x5212,
2371 .bInterfaceClass = USB_CLASS_VIDEO,
2372 .bInterfaceSubClass = 1,
2373 .bInterfaceProtocol = 0,
2374 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2375 /* Syntek (Samsung Q310) */
2376 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2377 | USB_DEVICE_ID_MATCH_INT_INFO,
2379 .idProduct = 0x5931,
2380 .bInterfaceClass = USB_CLASS_VIDEO,
2381 .bInterfaceSubClass = 1,
2382 .bInterfaceProtocol = 0,
2383 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2384 /* Syntek (Packard Bell EasyNote MX52 */
2385 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2386 | USB_DEVICE_ID_MATCH_INT_INFO,
2388 .idProduct = 0x8a12,
2389 .bInterfaceClass = USB_CLASS_VIDEO,
2390 .bInterfaceSubClass = 1,
2391 .bInterfaceProtocol = 0,
2392 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2393 /* Syntek (Asus F9SG) */
2394 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2395 | USB_DEVICE_ID_MATCH_INT_INFO,
2397 .idProduct = 0x8a31,
2398 .bInterfaceClass = USB_CLASS_VIDEO,
2399 .bInterfaceSubClass = 1,
2400 .bInterfaceProtocol = 0,
2401 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2402 /* Syntek (Asus U3S) */
2403 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2404 | USB_DEVICE_ID_MATCH_INT_INFO,
2406 .idProduct = 0x8a33,
2407 .bInterfaceClass = USB_CLASS_VIDEO,
2408 .bInterfaceSubClass = 1,
2409 .bInterfaceProtocol = 0,
2410 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2411 /* Syntek (JAOtech Smart Terminal) */
2412 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2413 | USB_DEVICE_ID_MATCH_INT_INFO,
2415 .idProduct = 0x8a34,
2416 .bInterfaceClass = USB_CLASS_VIDEO,
2417 .bInterfaceSubClass = 1,
2418 .bInterfaceProtocol = 0,
2419 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2421 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2422 | USB_DEVICE_ID_MATCH_INT_INFO,
2424 .idProduct = 0x0202,
2425 .bInterfaceClass = USB_CLASS_VIDEO,
2426 .bInterfaceSubClass = 1,
2427 .bInterfaceProtocol = 0,
2428 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2429 /* Lenovo Thinkpad SL400/SL500 */
2430 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2431 | USB_DEVICE_ID_MATCH_INT_INFO,
2433 .idProduct = 0x480b,
2434 .bInterfaceClass = USB_CLASS_VIDEO,
2435 .bInterfaceSubClass = 1,
2436 .bInterfaceProtocol = 0,
2437 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2438 /* Aveo Technology USB 2.0 Camera */
2439 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2440 | USB_DEVICE_ID_MATCH_INT_INFO,
2442 .idProduct = 0x0306,
2443 .bInterfaceClass = USB_CLASS_VIDEO,
2444 .bInterfaceSubClass = 1,
2445 .bInterfaceProtocol = 0,
2446 .driver_info = UVC_QUIRK_PROBE_MINMAX
2447 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2448 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2449 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2450 | USB_DEVICE_ID_MATCH_INT_INFO,
2452 .idProduct = 0x0516,
2453 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2454 .bInterfaceSubClass = 1,
2455 .bInterfaceProtocol = 0 },
2456 /* Ecamm Pico iMage */
2457 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2458 | USB_DEVICE_ID_MATCH_INT_INFO,
2460 .idProduct = 0xcafe,
2461 .bInterfaceClass = USB_CLASS_VIDEO,
2462 .bInterfaceSubClass = 1,
2463 .bInterfaceProtocol = 0,
2464 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2465 /* Manta MM-353 Plako */
2466 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2467 | USB_DEVICE_ID_MATCH_INT_INFO,
2469 .idProduct = 0x3188,
2470 .bInterfaceClass = USB_CLASS_VIDEO,
2471 .bInterfaceSubClass = 1,
2472 .bInterfaceProtocol = 0,
2473 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2474 /* FSC WebCam V30S */
2475 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2476 | USB_DEVICE_ID_MATCH_INT_INFO,
2478 .idProduct = 0x3288,
2479 .bInterfaceClass = USB_CLASS_VIDEO,
2480 .bInterfaceSubClass = 1,
2481 .bInterfaceProtocol = 0,
2482 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2483 /* Arkmicro unbranded */
2484 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2485 | USB_DEVICE_ID_MATCH_INT_INFO,
2487 .idProduct = 0x3290,
2488 .bInterfaceClass = USB_CLASS_VIDEO,
2489 .bInterfaceSubClass = 1,
2490 .bInterfaceProtocol = 0,
2491 .driver_info = UVC_QUIRK_PROBE_DEF },
2492 /* The Imaging Source USB CCD cameras */
2493 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2494 | USB_DEVICE_ID_MATCH_INT_INFO,
2496 .idProduct = 0x8102,
2497 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2498 .bInterfaceSubClass = 1,
2499 .bInterfaceProtocol = 0 },
2500 /* Bodelin ProScopeHR */
2501 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2502 | USB_DEVICE_ID_MATCH_DEV_HI
2503 | USB_DEVICE_ID_MATCH_INT_INFO,
2505 .idProduct = 0x1000,
2506 .bcdDevice_hi = 0x0126,
2507 .bInterfaceClass = USB_CLASS_VIDEO,
2508 .bInterfaceSubClass = 1,
2509 .bInterfaceProtocol = 0,
2510 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2511 /* MSI StarCam 370i */
2512 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2513 | USB_DEVICE_ID_MATCH_INT_INFO,
2515 .idProduct = 0x2951,
2516 .bInterfaceClass = USB_CLASS_VIDEO,
2517 .bInterfaceSubClass = 1,
2518 .bInterfaceProtocol = 0,
2519 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2520 /* SiGma Micro USB Web Camera */
2521 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2522 | USB_DEVICE_ID_MATCH_INT_INFO,
2524 .idProduct = 0x3000,
2525 .bInterfaceClass = USB_CLASS_VIDEO,
2526 .bInterfaceSubClass = 1,
2527 .bInterfaceProtocol = 0,
2528 .driver_info = UVC_QUIRK_PROBE_MINMAX
2529 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2530 /* Oculus VR Positional Tracker DK2 */
2531 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2532 | USB_DEVICE_ID_MATCH_INT_INFO,
2534 .idProduct = 0x0201,
2535 .bInterfaceClass = USB_CLASS_VIDEO,
2536 .bInterfaceSubClass = 1,
2537 .bInterfaceProtocol = 0,
2538 .driver_info = UVC_QUIRK_FORCE_Y8 },
2539 /* Generic USB Video Class */
2540 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2544 MODULE_DEVICE_TABLE(usb, uvc_ids);
2546 struct uvc_driver uvc_driver = {
2550 .disconnect = uvc_disconnect,
2551 .suspend = uvc_suspend,
2552 .resume = uvc_resume,
2553 .reset_resume = uvc_reset_resume,
2554 .id_table = uvc_ids,
2555 .supports_autosuspend = 1,
2559 static int __init uvc_init(void)
2565 ret = usb_register(&uvc_driver.driver);
2567 uvc_debugfs_cleanup();
2571 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2575 static void __exit uvc_cleanup(void)
2577 usb_deregister(&uvc_driver.driver);
2578 uvc_debugfs_cleanup();
2581 module_init(uvc_init);
2582 module_exit(uvc_cleanup);
2584 MODULE_AUTHOR(DRIVER_AUTHOR);
2585 MODULE_DESCRIPTION(DRIVER_DESC);
2586 MODULE_LICENSE("GPL");
2587 MODULE_VERSION(DRIVER_VERSION);