1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * uvc_driver.c -- USB Video Class driver
5 * Copyright (C) 2005-2010
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
9 #include <linux/atomic.h>
10 #include <linux/kernel.h>
11 #include <linux/list.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/usb.h>
15 #include <linux/videodev2.h>
16 #include <linux/vmalloc.h>
17 #include <linux/wait.h>
18 #include <linux/version.h>
19 #include <asm/unaligned.h>
21 #include <media/v4l2-common.h>
22 #include <media/v4l2-ioctl.h>
26 #define DRIVER_AUTHOR "Laurent Pinchart " \
27 "<laurent.pinchart@ideasonboard.com>"
28 #define DRIVER_DESC "USB Video Class driver"
30 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
31 unsigned int uvc_hw_timestamps_param;
32 unsigned int uvc_no_drop_param;
33 static unsigned int uvc_quirks_param = -1;
34 unsigned int uvc_trace_param;
35 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
37 /* ------------------------------------------------------------------------
41 static struct uvc_format_desc uvc_fmts[] = {
43 .name = "YUV 4:2:2 (YUYV)",
44 .guid = UVC_GUID_FORMAT_YUY2,
45 .fcc = V4L2_PIX_FMT_YUYV,
48 .name = "YUV 4:2:2 (YUYV)",
49 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
50 .fcc = V4L2_PIX_FMT_YUYV,
53 .name = "YUV 4:2:0 (NV12)",
54 .guid = UVC_GUID_FORMAT_NV12,
55 .fcc = V4L2_PIX_FMT_NV12,
59 .guid = UVC_GUID_FORMAT_MJPEG,
60 .fcc = V4L2_PIX_FMT_MJPEG,
63 .name = "YVU 4:2:0 (YV12)",
64 .guid = UVC_GUID_FORMAT_YV12,
65 .fcc = V4L2_PIX_FMT_YVU420,
68 .name = "YUV 4:2:0 (I420)",
69 .guid = UVC_GUID_FORMAT_I420,
70 .fcc = V4L2_PIX_FMT_YUV420,
73 .name = "YUV 4:2:0 (M420)",
74 .guid = UVC_GUID_FORMAT_M420,
75 .fcc = V4L2_PIX_FMT_M420,
78 .name = "YUV 4:2:2 (UYVY)",
79 .guid = UVC_GUID_FORMAT_UYVY,
80 .fcc = V4L2_PIX_FMT_UYVY,
83 .name = "Greyscale 8-bit (Y800)",
84 .guid = UVC_GUID_FORMAT_Y800,
85 .fcc = V4L2_PIX_FMT_GREY,
88 .name = "Greyscale 8-bit (Y8 )",
89 .guid = UVC_GUID_FORMAT_Y8,
90 .fcc = V4L2_PIX_FMT_GREY,
93 .name = "Greyscale 8-bit (D3DFMT_L8)",
94 .guid = UVC_GUID_FORMAT_D3DFMT_L8,
95 .fcc = V4L2_PIX_FMT_GREY,
98 .name = "IR 8-bit (L8_IR)",
99 .guid = UVC_GUID_FORMAT_KSMEDIA_L8_IR,
100 .fcc = V4L2_PIX_FMT_GREY,
103 .name = "Greyscale 10-bit (Y10 )",
104 .guid = UVC_GUID_FORMAT_Y10,
105 .fcc = V4L2_PIX_FMT_Y10,
108 .name = "Greyscale 12-bit (Y12 )",
109 .guid = UVC_GUID_FORMAT_Y12,
110 .fcc = V4L2_PIX_FMT_Y12,
113 .name = "Greyscale 16-bit (Y16 )",
114 .guid = UVC_GUID_FORMAT_Y16,
115 .fcc = V4L2_PIX_FMT_Y16,
118 .name = "BGGR Bayer (BY8 )",
119 .guid = UVC_GUID_FORMAT_BY8,
120 .fcc = V4L2_PIX_FMT_SBGGR8,
123 .name = "BGGR Bayer (BA81)",
124 .guid = UVC_GUID_FORMAT_BA81,
125 .fcc = V4L2_PIX_FMT_SBGGR8,
128 .name = "GBRG Bayer (GBRG)",
129 .guid = UVC_GUID_FORMAT_GBRG,
130 .fcc = V4L2_PIX_FMT_SGBRG8,
133 .name = "GRBG Bayer (GRBG)",
134 .guid = UVC_GUID_FORMAT_GRBG,
135 .fcc = V4L2_PIX_FMT_SGRBG8,
138 .name = "RGGB Bayer (RGGB)",
139 .guid = UVC_GUID_FORMAT_RGGB,
140 .fcc = V4L2_PIX_FMT_SRGGB8,
144 .guid = UVC_GUID_FORMAT_RGBP,
145 .fcc = V4L2_PIX_FMT_RGB565,
148 .name = "BGR 8:8:8 (BGR3)",
149 .guid = UVC_GUID_FORMAT_BGR3,
150 .fcc = V4L2_PIX_FMT_BGR24,
154 .guid = UVC_GUID_FORMAT_H264,
155 .fcc = V4L2_PIX_FMT_H264,
158 .name = "Greyscale 8 L/R (Y8I)",
159 .guid = UVC_GUID_FORMAT_Y8I,
160 .fcc = V4L2_PIX_FMT_Y8I,
163 .name = "Greyscale 12 L/R (Y12I)",
164 .guid = UVC_GUID_FORMAT_Y12I,
165 .fcc = V4L2_PIX_FMT_Y12I,
168 .name = "Depth data 16-bit (Z16)",
169 .guid = UVC_GUID_FORMAT_Z16,
170 .fcc = V4L2_PIX_FMT_Z16,
173 .name = "Bayer 10-bit (SRGGB10P)",
174 .guid = UVC_GUID_FORMAT_RW10,
175 .fcc = V4L2_PIX_FMT_SRGGB10P,
178 .name = "Bayer 16-bit (SBGGR16)",
179 .guid = UVC_GUID_FORMAT_BG16,
180 .fcc = V4L2_PIX_FMT_SBGGR16,
183 .name = "Bayer 16-bit (SGBRG16)",
184 .guid = UVC_GUID_FORMAT_GB16,
185 .fcc = V4L2_PIX_FMT_SGBRG16,
188 .name = "Bayer 16-bit (SRGGB16)",
189 .guid = UVC_GUID_FORMAT_RG16,
190 .fcc = V4L2_PIX_FMT_SRGGB16,
193 .name = "Bayer 16-bit (SGRBG16)",
194 .guid = UVC_GUID_FORMAT_GR16,
195 .fcc = V4L2_PIX_FMT_SGRBG16,
198 .name = "Depth data 16-bit (Z16)",
199 .guid = UVC_GUID_FORMAT_INVZ,
200 .fcc = V4L2_PIX_FMT_Z16,
203 .name = "Greyscale 10-bit (Y10 )",
204 .guid = UVC_GUID_FORMAT_INVI,
205 .fcc = V4L2_PIX_FMT_Y10,
208 .name = "IR:Depth 26-bit (INZI)",
209 .guid = UVC_GUID_FORMAT_INZI,
210 .fcc = V4L2_PIX_FMT_INZI,
213 .name = "4-bit Depth Confidence (Packed)",
214 .guid = UVC_GUID_FORMAT_CNF4,
215 .fcc = V4L2_PIX_FMT_CNF4,
219 .guid = UVC_GUID_FORMAT_HEVC,
220 .fcc = V4L2_PIX_FMT_HEVC,
224 /* ------------------------------------------------------------------------
228 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
231 struct usb_host_endpoint *ep;
234 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
235 ep = &alts->endpoint[i];
236 if (ep->desc.bEndpointAddress == epaddr)
243 static struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16])
245 unsigned int len = ARRAY_SIZE(uvc_fmts);
248 for (i = 0; i < len; ++i) {
249 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
256 static enum v4l2_colorspace uvc_colorspace(const u8 primaries)
258 static const enum v4l2_colorspace colorprimaries[] = {
259 V4L2_COLORSPACE_DEFAULT, /* Unspecified */
260 V4L2_COLORSPACE_SRGB,
261 V4L2_COLORSPACE_470_SYSTEM_M,
262 V4L2_COLORSPACE_470_SYSTEM_BG,
263 V4L2_COLORSPACE_SMPTE170M,
264 V4L2_COLORSPACE_SMPTE240M,
267 if (primaries < ARRAY_SIZE(colorprimaries))
268 return colorprimaries[primaries];
270 return V4L2_COLORSPACE_DEFAULT; /* Reserved */
273 static enum v4l2_xfer_func uvc_xfer_func(const u8 transfer_characteristics)
276 * V4L2 does not currently have definitions for all possible values of
277 * UVC transfer characteristics. If v4l2_xfer_func is extended with new
278 * values, the mapping below should be updated.
280 * Substitutions are taken from the mapping given for
281 * V4L2_XFER_FUNC_DEFAULT documented in videodev2.h.
283 static const enum v4l2_xfer_func xfer_funcs[] = {
284 V4L2_XFER_FUNC_DEFAULT, /* Unspecified */
286 V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 M */
287 V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 B, G */
288 V4L2_XFER_FUNC_709, /* Substitution for SMPTE 170M */
289 V4L2_XFER_FUNC_SMPTE240M,
294 if (transfer_characteristics < ARRAY_SIZE(xfer_funcs))
295 return xfer_funcs[transfer_characteristics];
297 return V4L2_XFER_FUNC_DEFAULT; /* Reserved */
300 static enum v4l2_ycbcr_encoding uvc_ycbcr_enc(const u8 matrix_coefficients)
303 * V4L2 does not currently have definitions for all possible values of
304 * UVC matrix coefficients. If v4l2_ycbcr_encoding is extended with new
305 * values, the mapping below should be updated.
307 * Substitutions are taken from the mapping given for
308 * V4L2_YCBCR_ENC_DEFAULT documented in videodev2.h.
310 * FCC is assumed to be close enough to 601.
312 static const enum v4l2_ycbcr_encoding ycbcr_encs[] = {
313 V4L2_YCBCR_ENC_DEFAULT, /* Unspecified */
315 V4L2_YCBCR_ENC_601, /* Substitution for FCC */
316 V4L2_YCBCR_ENC_601, /* Substitution for BT.470-2 B, G */
318 V4L2_YCBCR_ENC_SMPTE240M,
321 if (matrix_coefficients < ARRAY_SIZE(ycbcr_encs))
322 return ycbcr_encs[matrix_coefficients];
324 return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */
327 /* Simplify a fraction using a simple continued fraction decomposition. The
328 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
329 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
330 * arbitrary parameters to remove non-significative terms from the simple
331 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
332 * respectively seems to give nice results.
334 void uvc_simplify_fraction(u32 *numerator, u32 *denominator,
335 unsigned int n_terms, unsigned int threshold)
341 an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL);
345 /* Convert the fraction to a simple continued fraction. See
346 * https://mathforum.org/dr.math/faq/faq.fractions.html
347 * Stop if the current term is bigger than or equal to the given
353 for (n = 0; n < n_terms && y != 0; ++n) {
355 if (an[n] >= threshold) {
366 /* Expand the simple continued fraction back to an integer fraction. */
370 for (i = n; i > 0; --i) {
381 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
382 * to compute numerator / denominator * 10000000 using 32 bit fixed point
385 u32 uvc_fraction_to_interval(u32 numerator, u32 denominator)
389 /* Saturate the result if the operation would overflow. */
390 if (denominator == 0 ||
391 numerator/denominator >= ((u32)-1)/10000000)
394 /* Divide both the denominator and the multiplier by two until
395 * numerator * multiplier doesn't overflow. If anyone knows a better
396 * algorithm please let me know.
398 multiplier = 10000000;
399 while (numerator > ((u32)-1)/multiplier) {
404 return denominator ? numerator * multiplier / denominator : 0;
407 /* ------------------------------------------------------------------------
408 * Terminal and unit management
411 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
413 struct uvc_entity *entity;
415 list_for_each_entry(entity, &dev->entities, list) {
416 if (entity->id == id)
423 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
424 int id, struct uvc_entity *entity)
429 entity = list_entry(&dev->entities, struct uvc_entity, list);
431 list_for_each_entry_continue(entity, &dev->entities, list) {
432 for (i = 0; i < entity->bNrInPins; ++i)
433 if (entity->baSourceID[i] == id)
440 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
442 struct uvc_streaming *stream;
444 list_for_each_entry(stream, &dev->streams, list) {
445 if (stream->header.bTerminalLink == id)
452 /* ------------------------------------------------------------------------
453 * Streaming Object Management
456 static void uvc_stream_delete(struct uvc_streaming *stream)
458 if (stream->async_wq)
459 destroy_workqueue(stream->async_wq);
461 mutex_destroy(&stream->mutex);
463 usb_put_intf(stream->intf);
465 kfree(stream->format);
466 kfree(stream->header.bmaControls);
470 static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev,
471 struct usb_interface *intf)
473 struct uvc_streaming *stream;
475 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
479 mutex_init(&stream->mutex);
482 stream->intf = usb_get_intf(intf);
483 stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
485 /* Allocate a stream specific work queue for asynchronous tasks. */
486 stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | WQ_HIGHPRI,
488 if (!stream->async_wq) {
489 uvc_stream_delete(stream);
496 /* ------------------------------------------------------------------------
497 * Descriptors parsing
500 static int uvc_parse_format(struct uvc_device *dev,
501 struct uvc_streaming *streaming, struct uvc_format *format,
502 u32 **intervals, unsigned char *buffer, int buflen)
504 struct usb_interface *intf = streaming->intf;
505 struct usb_host_interface *alts = intf->cur_altsetting;
506 struct uvc_format_desc *fmtdesc;
507 struct uvc_frame *frame;
508 const unsigned char *start = buffer;
509 unsigned int width_multiplier = 1;
510 unsigned int interval;
514 format->type = buffer[2];
515 format->index = buffer[3];
518 case UVC_VS_FORMAT_UNCOMPRESSED:
519 case UVC_VS_FORMAT_FRAME_BASED:
520 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
522 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
523 "interface %d FORMAT error\n",
525 alts->desc.bInterfaceNumber);
529 /* Find the format descriptor from its GUID. */
530 fmtdesc = uvc_format_by_guid(&buffer[5]);
532 if (fmtdesc != NULL) {
533 strscpy(format->name, fmtdesc->name,
534 sizeof(format->name));
535 format->fcc = fmtdesc->fcc;
537 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
539 snprintf(format->name, sizeof(format->name), "%pUl\n",
544 format->bpp = buffer[21];
546 /* Some devices report a format that doesn't match what they
549 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
550 if (format->fcc == V4L2_PIX_FMT_YUYV) {
551 strscpy(format->name, "Greyscale 8-bit (Y8 )",
552 sizeof(format->name));
553 format->fcc = V4L2_PIX_FMT_GREY;
555 width_multiplier = 2;
559 /* Some devices report bpp that doesn't match the format. */
560 if (dev->quirks & UVC_QUIRK_FORCE_BPP) {
561 const struct v4l2_format_info *info =
562 v4l2_format_info(format->fcc);
565 unsigned int div = info->hdiv * info->vdiv;
567 n = info->bpp[0] * div;
568 for (i = 1; i < info->comp_planes; i++)
571 format->bpp = DIV_ROUND_UP(8 * n, div);
575 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
576 ftype = UVC_VS_FRAME_UNCOMPRESSED;
578 ftype = UVC_VS_FRAME_FRAME_BASED;
580 format->flags = UVC_FMT_FLAG_COMPRESSED;
584 case UVC_VS_FORMAT_MJPEG:
586 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
587 "interface %d FORMAT error\n",
589 alts->desc.bInterfaceNumber);
593 strscpy(format->name, "MJPEG", sizeof(format->name));
594 format->fcc = V4L2_PIX_FMT_MJPEG;
595 format->flags = UVC_FMT_FLAG_COMPRESSED;
597 ftype = UVC_VS_FRAME_MJPEG;
600 case UVC_VS_FORMAT_DV:
602 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
603 "interface %d FORMAT error\n",
605 alts->desc.bInterfaceNumber);
609 switch (buffer[8] & 0x7f) {
611 strscpy(format->name, "SD-DV", sizeof(format->name));
614 strscpy(format->name, "SDL-DV", sizeof(format->name));
617 strscpy(format->name, "HD-DV", sizeof(format->name));
620 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
621 "interface %d: unknown DV format %u\n",
623 alts->desc.bInterfaceNumber, buffer[8]);
627 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
628 sizeof(format->name));
630 format->fcc = V4L2_PIX_FMT_DV;
631 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
635 /* Create a dummy frame descriptor. */
636 frame = &format->frame[0];
637 memset(&format->frame[0], 0, sizeof(format->frame[0]));
638 frame->bFrameIntervalType = 1;
639 frame->dwDefaultFrameInterval = 1;
640 frame->dwFrameInterval = *intervals;
645 case UVC_VS_FORMAT_MPEG2TS:
646 case UVC_VS_FORMAT_STREAM_BASED:
647 /* Not supported yet. */
649 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
650 "interface %d unsupported format %u\n",
651 dev->udev->devnum, alts->desc.bInterfaceNumber,
656 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
661 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
662 * based formats have frame descriptors.
664 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
665 buffer[2] == ftype) {
666 frame = &format->frame[format->nframes];
667 if (ftype != UVC_VS_FRAME_FRAME_BASED)
668 n = buflen > 25 ? buffer[25] : 0;
670 n = buflen > 21 ? buffer[21] : 0;
674 if (buflen < 26 + 4*n) {
675 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
676 "interface %d FRAME error\n", dev->udev->devnum,
677 alts->desc.bInterfaceNumber);
681 frame->bFrameIndex = buffer[3];
682 frame->bmCapabilities = buffer[4];
683 frame->wWidth = get_unaligned_le16(&buffer[5])
685 frame->wHeight = get_unaligned_le16(&buffer[7]);
686 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
687 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
688 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
689 frame->dwMaxVideoFrameBufferSize =
690 get_unaligned_le32(&buffer[17]);
691 frame->dwDefaultFrameInterval =
692 get_unaligned_le32(&buffer[21]);
693 frame->bFrameIntervalType = buffer[25];
695 frame->dwMaxVideoFrameBufferSize = 0;
696 frame->dwDefaultFrameInterval =
697 get_unaligned_le32(&buffer[17]);
698 frame->bFrameIntervalType = buffer[21];
700 frame->dwFrameInterval = *intervals;
702 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
703 * completely. Observed behaviours range from setting the
704 * value to 1.1x the actual frame size to hardwiring the
705 * 16 low bits to 0. This results in a higher than necessary
706 * memory usage as well as a wrong image size information. For
707 * uncompressed formats this can be fixed by computing the
708 * value from the frame size.
710 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
711 frame->dwMaxVideoFrameBufferSize = format->bpp
712 * frame->wWidth * frame->wHeight / 8;
714 /* Some bogus devices report dwMinFrameInterval equal to
715 * dwMaxFrameInterval and have dwFrameIntervalStep set to
716 * zero. Setting all null intervals to 1 fixes the problem and
717 * some other divisions by zero that could happen.
719 for (i = 0; i < n; ++i) {
720 interval = get_unaligned_le32(&buffer[26+4*i]);
721 *(*intervals)++ = interval ? interval : 1;
724 /* Make sure that the default frame interval stays between
727 n -= frame->bFrameIntervalType ? 1 : 2;
728 frame->dwDefaultFrameInterval =
729 min(frame->dwFrameInterval[n],
730 max(frame->dwFrameInterval[0],
731 frame->dwDefaultFrameInterval));
733 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
734 frame->bFrameIntervalType = 1;
735 frame->dwFrameInterval[0] =
736 frame->dwDefaultFrameInterval;
739 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
740 frame->wWidth, frame->wHeight,
741 10000000/frame->dwDefaultFrameInterval,
742 (100000000/frame->dwDefaultFrameInterval)%10);
749 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
750 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
755 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
756 buffer[2] == UVC_VS_COLORFORMAT) {
758 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
759 "interface %d COLORFORMAT error\n",
761 alts->desc.bInterfaceNumber);
765 format->colorspace = uvc_colorspace(buffer[3]);
766 format->xfer_func = uvc_xfer_func(buffer[4]);
767 format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
773 return buffer - start;
776 static int uvc_parse_streaming(struct uvc_device *dev,
777 struct usb_interface *intf)
779 struct uvc_streaming *streaming = NULL;
780 struct uvc_format *format;
781 struct uvc_frame *frame;
782 struct usb_host_interface *alts = &intf->altsetting[0];
783 unsigned char *_buffer, *buffer = alts->extra;
784 int _buflen, buflen = alts->extralen;
785 unsigned int nformats = 0, nframes = 0, nintervals = 0;
786 unsigned int size, i, n, p;
791 if (intf->cur_altsetting->desc.bInterfaceSubClass
792 != UVC_SC_VIDEOSTREAMING) {
793 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
794 "video streaming interface\n", dev->udev->devnum,
795 intf->altsetting[0].desc.bInterfaceNumber);
799 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
800 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
801 "claimed\n", dev->udev->devnum,
802 intf->altsetting[0].desc.bInterfaceNumber);
806 streaming = uvc_stream_new(dev, intf);
807 if (streaming == NULL) {
808 usb_driver_release_interface(&uvc_driver.driver, intf);
812 /* The Pico iMage webcam has its class-specific interface descriptors
813 * after the endpoint descriptors.
816 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
817 struct usb_host_endpoint *ep = &alts->endpoint[i];
819 if (ep->extralen == 0)
822 if (ep->extralen > 2 &&
823 ep->extra[1] == USB_DT_CS_INTERFACE) {
824 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
825 "from endpoint %u.\n", i);
826 buffer = alts->endpoint[i].extra;
827 buflen = alts->endpoint[i].extralen;
833 /* Skip the standard interface descriptors. */
834 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
840 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
841 "interface descriptors found.\n");
845 /* Parse the header descriptor. */
847 case UVC_VS_OUTPUT_HEADER:
848 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
852 case UVC_VS_INPUT_HEADER:
853 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
858 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
859 "%d HEADER descriptor not found.\n", dev->udev->devnum,
860 alts->desc.bInterfaceNumber);
864 p = buflen >= 4 ? buffer[3] : 0;
865 n = buflen >= size ? buffer[size-1] : 0;
867 if (buflen < size + p*n) {
868 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
869 "interface %d HEADER descriptor is invalid.\n",
870 dev->udev->devnum, alts->desc.bInterfaceNumber);
874 streaming->header.bNumFormats = p;
875 streaming->header.bEndpointAddress = buffer[6];
876 if (buffer[2] == UVC_VS_INPUT_HEADER) {
877 streaming->header.bmInfo = buffer[7];
878 streaming->header.bTerminalLink = buffer[8];
879 streaming->header.bStillCaptureMethod = buffer[9];
880 streaming->header.bTriggerSupport = buffer[10];
881 streaming->header.bTriggerUsage = buffer[11];
883 streaming->header.bTerminalLink = buffer[7];
885 streaming->header.bControlSize = n;
887 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
889 if (streaming->header.bmaControls == NULL) {
900 /* Count the format and frame descriptors. */
901 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
902 switch (_buffer[2]) {
903 case UVC_VS_FORMAT_UNCOMPRESSED:
904 case UVC_VS_FORMAT_MJPEG:
905 case UVC_VS_FORMAT_FRAME_BASED:
909 case UVC_VS_FORMAT_DV:
910 /* DV format has no frame descriptor. We will create a
911 * dummy frame descriptor with a dummy frame interval.
918 case UVC_VS_FORMAT_MPEG2TS:
919 case UVC_VS_FORMAT_STREAM_BASED:
920 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
921 "interface %d FORMAT %u is not supported.\n",
923 alts->desc.bInterfaceNumber, _buffer[2]);
926 case UVC_VS_FRAME_UNCOMPRESSED:
927 case UVC_VS_FRAME_MJPEG:
930 nintervals += _buffer[25] ? _buffer[25] : 3;
933 case UVC_VS_FRAME_FRAME_BASED:
936 nintervals += _buffer[21] ? _buffer[21] : 3;
940 _buflen -= _buffer[0];
941 _buffer += _buffer[0];
945 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
946 "%d has no supported formats defined.\n",
947 dev->udev->devnum, alts->desc.bInterfaceNumber);
951 size = nformats * sizeof(*format) + nframes * sizeof(*frame)
952 + nintervals * sizeof(*interval);
953 format = kzalloc(size, GFP_KERNEL);
954 if (format == NULL) {
959 frame = (struct uvc_frame *)&format[nformats];
960 interval = (u32 *)&frame[nframes];
962 streaming->format = format;
963 streaming->nformats = nformats;
965 /* Parse the format descriptors. */
966 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
968 case UVC_VS_FORMAT_UNCOMPRESSED:
969 case UVC_VS_FORMAT_MJPEG:
970 case UVC_VS_FORMAT_DV:
971 case UVC_VS_FORMAT_FRAME_BASED:
972 format->frame = frame;
973 ret = uvc_parse_format(dev, streaming, format,
974 &interval, buffer, buflen);
978 frame += format->nframes;
994 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
995 "%d has %u bytes of trailing descriptor garbage.\n",
996 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
998 /* Parse the alternate settings to find the maximum bandwidth. */
999 for (i = 0; i < intf->num_altsetting; ++i) {
1000 struct usb_host_endpoint *ep;
1001 alts = &intf->altsetting[i];
1002 ep = uvc_find_endpoint(alts,
1003 streaming->header.bEndpointAddress);
1007 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
1008 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
1009 if (psize > streaming->maxpsize)
1010 streaming->maxpsize = psize;
1013 list_add_tail(&streaming->list, &dev->streams);
1017 usb_driver_release_interface(&uvc_driver.driver, intf);
1018 uvc_stream_delete(streaming);
1022 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
1023 unsigned int num_pads, unsigned int extra_size)
1025 struct uvc_entity *entity;
1026 unsigned int num_inputs;
1030 extra_size = roundup(extra_size, sizeof(*entity->pads));
1032 num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
1035 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
1037 entity = kzalloc(size, GFP_KERNEL);
1042 entity->type = type;
1044 entity->num_links = 0;
1045 entity->num_pads = num_pads;
1046 entity->pads = ((void *)(entity + 1)) + extra_size;
1048 for (i = 0; i < num_inputs; ++i)
1049 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
1050 if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
1051 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
1053 entity->bNrInPins = num_inputs;
1054 entity->baSourceID = (u8 *)(&entity->pads[num_pads]);
1059 /* Parse vendor-specific extensions. */
1060 static int uvc_parse_vendor_control(struct uvc_device *dev,
1061 const unsigned char *buffer, int buflen)
1063 struct usb_device *udev = dev->udev;
1064 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1065 struct uvc_entity *unit;
1069 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
1070 case 0x046d: /* Logitech */
1071 if (buffer[1] != 0x41 || buffer[2] != 0x01)
1074 /* Logitech implements several vendor specific functions
1075 * through vendor specific extension units (LXU).
1077 * The LXU descriptors are similar to XU descriptors
1078 * (see "USB Device Video Class for Video Devices", section
1079 * 3.7.2.6 "Extension Unit Descriptor") with the following
1082 * ----------------------------------------------------------
1083 * 0 bLength 1 Number
1084 * Size of this descriptor, in bytes: 24+p+n*2
1085 * ----------------------------------------------------------
1086 * 23+p+n bmControlsType N Bitmap
1087 * Individual bits in the set are defined:
1091 * This bitset is mapped exactly the same as bmControls.
1092 * ----------------------------------------------------------
1093 * 23+p+n*2 bReserved 1 Boolean
1094 * ----------------------------------------------------------
1095 * 24+p+n*2 iExtension 1 Index
1096 * Index of a string descriptor that describes this
1098 * ----------------------------------------------------------
1100 p = buflen >= 22 ? buffer[21] : 0;
1101 n = buflen >= 25 + p ? buffer[22+p] : 0;
1103 if (buflen < 25 + p + 2*n) {
1104 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1105 "interface %d EXTENSION_UNIT error\n",
1106 udev->devnum, alts->desc.bInterfaceNumber);
1110 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
1115 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1116 unit->extension.bNumControls = buffer[20];
1117 memcpy(unit->baSourceID, &buffer[22], p);
1118 unit->extension.bControlSize = buffer[22+p];
1119 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1120 unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit)
1122 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
1124 if (buffer[24+p+2*n] == 0 ||
1125 usb_string(udev, buffer[24+p+2*n], unit->name, sizeof(unit->name)) < 0)
1126 sprintf(unit->name, "Extension %u", buffer[3]);
1128 list_add_tail(&unit->list, &dev->entities);
1136 static int uvc_parse_standard_control(struct uvc_device *dev,
1137 const unsigned char *buffer, int buflen)
1139 struct usb_device *udev = dev->udev;
1140 struct uvc_entity *unit, *term;
1141 struct usb_interface *intf;
1142 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1143 unsigned int i, n, p, len;
1146 switch (buffer[2]) {
1148 n = buflen >= 12 ? buffer[11] : 0;
1150 if (buflen < 12 + n) {
1151 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1152 "interface %d HEADER error\n", udev->devnum,
1153 alts->desc.bInterfaceNumber);
1157 dev->uvc_version = get_unaligned_le16(&buffer[3]);
1158 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
1160 /* Parse all USB Video Streaming interfaces. */
1161 for (i = 0; i < n; ++i) {
1162 intf = usb_ifnum_to_if(udev, buffer[12+i]);
1164 uvc_trace(UVC_TRACE_DESCR, "device %d "
1165 "interface %d doesn't exists\n",
1170 uvc_parse_streaming(dev, intf);
1174 case UVC_VC_INPUT_TERMINAL:
1176 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1177 "interface %d INPUT_TERMINAL error\n",
1178 udev->devnum, alts->desc.bInterfaceNumber);
1183 * Reject invalid terminal types that would cause issues:
1185 * - The high byte must be non-zero, otherwise it would be
1186 * confused with a unit.
1188 * - Bit 15 must be 0, as we use it internally as a terminal
1191 * Other unknown types are accepted.
1193 type = get_unaligned_le16(&buffer[4]);
1194 if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
1195 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1196 "interface %d INPUT_TERMINAL %d has invalid "
1197 "type 0x%04x, skipping\n", udev->devnum,
1198 alts->desc.bInterfaceNumber,
1207 if (type == UVC_ITT_CAMERA) {
1208 n = buflen >= 15 ? buffer[14] : 0;
1211 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1212 n = buflen >= 9 ? buffer[8] : 0;
1213 p = buflen >= 10 + n ? buffer[9+n] : 0;
1217 if (buflen < len + n + p) {
1218 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1219 "interface %d INPUT_TERMINAL error\n",
1220 udev->devnum, alts->desc.bInterfaceNumber);
1224 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1229 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1230 term->camera.bControlSize = n;
1231 term->camera.bmControls = (u8 *)term + sizeof(*term);
1232 term->camera.wObjectiveFocalLengthMin =
1233 get_unaligned_le16(&buffer[8]);
1234 term->camera.wObjectiveFocalLengthMax =
1235 get_unaligned_le16(&buffer[10]);
1236 term->camera.wOcularFocalLength =
1237 get_unaligned_le16(&buffer[12]);
1238 memcpy(term->camera.bmControls, &buffer[15], n);
1239 } else if (UVC_ENTITY_TYPE(term) ==
1240 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1241 term->media.bControlSize = n;
1242 term->media.bmControls = (u8 *)term + sizeof(*term);
1243 term->media.bTransportModeSize = p;
1244 term->media.bmTransportModes = (u8 *)term
1245 + sizeof(*term) + n;
1246 memcpy(term->media.bmControls, &buffer[9], n);
1247 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1250 if (buffer[7] == 0 ||
1251 usb_string(udev, buffer[7], term->name, sizeof(term->name)) < 0) {
1252 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1253 sprintf(term->name, "Camera %u", buffer[3]);
1254 if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1255 sprintf(term->name, "Media %u", buffer[3]);
1257 sprintf(term->name, "Input %u", buffer[3]);
1260 list_add_tail(&term->list, &dev->entities);
1263 case UVC_VC_OUTPUT_TERMINAL:
1265 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1266 "interface %d OUTPUT_TERMINAL error\n",
1267 udev->devnum, alts->desc.bInterfaceNumber);
1271 /* Make sure the terminal type MSB is not null, otherwise it
1272 * could be confused with a unit.
1274 type = get_unaligned_le16(&buffer[4]);
1275 if ((type & 0xff00) == 0) {
1276 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1277 "interface %d OUTPUT_TERMINAL %d has invalid "
1278 "type 0x%04x, skipping\n", udev->devnum,
1279 alts->desc.bInterfaceNumber, buffer[3], type);
1283 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1288 memcpy(term->baSourceID, &buffer[7], 1);
1290 if (buffer[8] == 0 ||
1291 usb_string(udev, buffer[8], term->name, sizeof(term->name)) < 0)
1292 sprintf(term->name, "Output %u", buffer[3]);
1294 list_add_tail(&term->list, &dev->entities);
1297 case UVC_VC_SELECTOR_UNIT:
1298 p = buflen >= 5 ? buffer[4] : 0;
1300 if (buflen < 5 || buflen < 6 + p) {
1301 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1302 "interface %d SELECTOR_UNIT error\n",
1303 udev->devnum, alts->desc.bInterfaceNumber);
1307 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1311 memcpy(unit->baSourceID, &buffer[5], p);
1313 if (buffer[5+p] == 0 ||
1314 usb_string(udev, buffer[5+p], unit->name, sizeof(unit->name)) < 0)
1315 sprintf(unit->name, "Selector %u", buffer[3]);
1317 list_add_tail(&unit->list, &dev->entities);
1320 case UVC_VC_PROCESSING_UNIT:
1321 n = buflen >= 8 ? buffer[7] : 0;
1322 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1324 if (buflen < p + n) {
1325 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1326 "interface %d PROCESSING_UNIT error\n",
1327 udev->devnum, alts->desc.bInterfaceNumber);
1331 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1335 memcpy(unit->baSourceID, &buffer[4], 1);
1336 unit->processing.wMaxMultiplier =
1337 get_unaligned_le16(&buffer[5]);
1338 unit->processing.bControlSize = buffer[7];
1339 unit->processing.bmControls = (u8 *)unit + sizeof(*unit);
1340 memcpy(unit->processing.bmControls, &buffer[8], n);
1341 if (dev->uvc_version >= 0x0110)
1342 unit->processing.bmVideoStandards = buffer[9+n];
1344 if (buffer[8+n] == 0 ||
1345 usb_string(udev, buffer[8+n], unit->name, sizeof(unit->name)) < 0)
1346 sprintf(unit->name, "Processing %u", buffer[3]);
1348 list_add_tail(&unit->list, &dev->entities);
1351 case UVC_VC_EXTENSION_UNIT:
1352 p = buflen >= 22 ? buffer[21] : 0;
1353 n = buflen >= 24 + p ? buffer[22+p] : 0;
1355 if (buflen < 24 + p + n) {
1356 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1357 "interface %d EXTENSION_UNIT error\n",
1358 udev->devnum, alts->desc.bInterfaceNumber);
1362 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1366 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1367 unit->extension.bNumControls = buffer[20];
1368 memcpy(unit->baSourceID, &buffer[22], p);
1369 unit->extension.bControlSize = buffer[22+p];
1370 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1371 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1373 if (buffer[23+p+n] == 0 ||
1374 usb_string(udev, buffer[23+p+n], unit->name, sizeof(unit->name)) < 0)
1375 sprintf(unit->name, "Extension %u", buffer[3]);
1377 list_add_tail(&unit->list, &dev->entities);
1381 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1382 "descriptor (%u)\n", buffer[2]);
1389 static int uvc_parse_control(struct uvc_device *dev)
1391 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1392 unsigned char *buffer = alts->extra;
1393 int buflen = alts->extralen;
1396 /* Parse the default alternate setting only, as the UVC specification
1397 * defines a single alternate setting, the default alternate setting
1401 while (buflen > 2) {
1402 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1403 buffer[1] != USB_DT_CS_INTERFACE)
1404 goto next_descriptor;
1406 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1410 buflen -= buffer[0];
1411 buffer += buffer[0];
1414 /* Check if the optional status endpoint is present. Built-in iSight
1415 * webcams have an interrupt endpoint but spit proprietary data that
1416 * don't conform to the UVC status endpoint messages. Don't try to
1417 * handle the interrupt endpoint for those cameras.
1419 if (alts->desc.bNumEndpoints == 1 &&
1420 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1421 struct usb_host_endpoint *ep = &alts->endpoint[0];
1422 struct usb_endpoint_descriptor *desc = &ep->desc;
1424 if (usb_endpoint_is_int_in(desc) &&
1425 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1426 desc->bInterval != 0) {
1427 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1428 "(addr %02x).\n", desc->bEndpointAddress);
1436 /* ------------------------------------------------------------------------
1441 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1442 * and containing the following units:
1444 * - one or more Output Terminals (USB Streaming or Display)
1445 * - zero or one Processing Unit
1446 * - zero, one or more single-input Selector Units
1447 * - zero or one multiple-input Selector Units, provided all inputs are
1448 * connected to input terminals
1449 * - zero, one or mode single-input Extension Units
1450 * - one or more Input Terminals (Camera, External or USB Streaming)
1452 * The terminal and units must match on of the following structures:
1454 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1455 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1456 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1458 * +---------+ +---------+ -> OTT_*(0)
1459 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1460 * +---------+ +---------+ -> OTT_*(n)
1462 * The Processing Unit and Extension Units can be in any order. Additional
1463 * Extension Units connected to the main chain as single-unit branches are
1464 * also supported. Single-input Selector Units are ignored.
1466 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1467 struct uvc_entity *entity)
1469 switch (UVC_ENTITY_TYPE(entity)) {
1470 case UVC_VC_EXTENSION_UNIT:
1471 if (uvc_trace_param & UVC_TRACE_PROBE)
1472 printk(KERN_CONT " <- XU %d", entity->id);
1474 if (entity->bNrInPins != 1) {
1475 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1476 "than 1 input pin.\n", entity->id);
1482 case UVC_VC_PROCESSING_UNIT:
1483 if (uvc_trace_param & UVC_TRACE_PROBE)
1484 printk(KERN_CONT " <- PU %d", entity->id);
1486 if (chain->processing != NULL) {
1487 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1488 "Processing Units in chain.\n");
1492 chain->processing = entity;
1495 case UVC_VC_SELECTOR_UNIT:
1496 if (uvc_trace_param & UVC_TRACE_PROBE)
1497 printk(KERN_CONT " <- SU %d", entity->id);
1499 /* Single-input selector units are ignored. */
1500 if (entity->bNrInPins == 1)
1503 if (chain->selector != NULL) {
1504 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1505 "Units in chain.\n");
1509 chain->selector = entity;
1512 case UVC_ITT_VENDOR_SPECIFIC:
1513 case UVC_ITT_CAMERA:
1514 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1515 if (uvc_trace_param & UVC_TRACE_PROBE)
1516 printk(KERN_CONT " <- IT %d\n", entity->id);
1520 case UVC_OTT_VENDOR_SPECIFIC:
1521 case UVC_OTT_DISPLAY:
1522 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1523 if (uvc_trace_param & UVC_TRACE_PROBE)
1524 printk(KERN_CONT " OT %d", entity->id);
1528 case UVC_TT_STREAMING:
1529 if (UVC_ENTITY_IS_ITERM(entity)) {
1530 if (uvc_trace_param & UVC_TRACE_PROBE)
1531 printk(KERN_CONT " <- IT %d\n", entity->id);
1533 if (uvc_trace_param & UVC_TRACE_PROBE)
1534 printk(KERN_CONT " OT %d", entity->id);
1540 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1541 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1545 list_add_tail(&entity->chain, &chain->entities);
1549 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1550 struct uvc_entity *entity, struct uvc_entity *prev)
1552 struct uvc_entity *forward;
1560 forward = uvc_entity_by_reference(chain->dev, entity->id,
1562 if (forward == NULL)
1564 if (forward == prev)
1566 if (forward->chain.next || forward->chain.prev) {
1567 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1568 "entity %d already in chain.\n", forward->id);
1572 switch (UVC_ENTITY_TYPE(forward)) {
1573 case UVC_VC_EXTENSION_UNIT:
1574 if (forward->bNrInPins != 1) {
1575 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1576 "has more than 1 input pin.\n",
1582 * Some devices reference an output terminal as the
1583 * source of extension units. This is incorrect, as
1584 * output terminals only have an input pin, and thus
1585 * can't be connected to any entity in the forward
1586 * direction. The resulting topology would cause issues
1587 * when registering the media controller graph. To
1588 * avoid this problem, connect the extension unit to
1589 * the source of the output terminal instead.
1591 if (UVC_ENTITY_IS_OTERM(entity)) {
1592 struct uvc_entity *source;
1594 source = uvc_entity_by_id(chain->dev,
1595 entity->baSourceID[0]);
1597 uvc_trace(UVC_TRACE_DESCR,
1598 "Can't connect extension unit %u in chain\n",
1603 forward->baSourceID[0] = source->id;
1606 list_add_tail(&forward->chain, &chain->entities);
1607 if (uvc_trace_param & UVC_TRACE_PROBE) {
1609 printk(KERN_CONT " (->");
1611 printk(KERN_CONT " XU %d", forward->id);
1616 case UVC_OTT_VENDOR_SPECIFIC:
1617 case UVC_OTT_DISPLAY:
1618 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1619 case UVC_TT_STREAMING:
1620 if (UVC_ENTITY_IS_ITERM(forward)) {
1621 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1622 "terminal %u.\n", forward->id);
1626 if (UVC_ENTITY_IS_OTERM(entity)) {
1627 uvc_trace(UVC_TRACE_DESCR,
1628 "Unsupported connection between output terminals %u and %u\n",
1629 entity->id, forward->id);
1633 list_add_tail(&forward->chain, &chain->entities);
1634 if (uvc_trace_param & UVC_TRACE_PROBE) {
1636 printk(KERN_CONT " (->");
1638 printk(KERN_CONT " OT %d", forward->id);
1645 printk(KERN_CONT ")");
1650 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1651 struct uvc_entity **_entity)
1653 struct uvc_entity *entity = *_entity;
1654 struct uvc_entity *term;
1655 int id = -EINVAL, i;
1657 switch (UVC_ENTITY_TYPE(entity)) {
1658 case UVC_VC_EXTENSION_UNIT:
1659 case UVC_VC_PROCESSING_UNIT:
1660 id = entity->baSourceID[0];
1663 case UVC_VC_SELECTOR_UNIT:
1664 /* Single-input selector units are ignored. */
1665 if (entity->bNrInPins == 1) {
1666 id = entity->baSourceID[0];
1670 if (uvc_trace_param & UVC_TRACE_PROBE)
1671 printk(KERN_CONT " <- IT");
1673 chain->selector = entity;
1674 for (i = 0; i < entity->bNrInPins; ++i) {
1675 id = entity->baSourceID[i];
1676 term = uvc_entity_by_id(chain->dev, id);
1677 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1678 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1679 "input %d isn't connected to an "
1680 "input terminal\n", entity->id, i);
1684 if (term->chain.next || term->chain.prev) {
1685 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1686 "entity %d already in chain.\n",
1691 if (uvc_trace_param & UVC_TRACE_PROBE)
1692 printk(KERN_CONT " %d", term->id);
1694 list_add_tail(&term->chain, &chain->entities);
1695 uvc_scan_chain_forward(chain, term, entity);
1698 if (uvc_trace_param & UVC_TRACE_PROBE)
1699 printk(KERN_CONT "\n");
1704 case UVC_ITT_VENDOR_SPECIFIC:
1705 case UVC_ITT_CAMERA:
1706 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1707 case UVC_OTT_VENDOR_SPECIFIC:
1708 case UVC_OTT_DISPLAY:
1709 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1710 case UVC_TT_STREAMING:
1711 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1720 entity = uvc_entity_by_id(chain->dev, id);
1721 if (entity == NULL) {
1722 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1723 "unknown entity %d.\n", id);
1731 static int uvc_scan_chain(struct uvc_video_chain *chain,
1732 struct uvc_entity *term)
1734 struct uvc_entity *entity, *prev;
1736 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1741 while (entity != NULL) {
1742 /* Entity must not be part of an existing chain */
1743 if (entity->chain.next || entity->chain.prev) {
1744 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1745 "entity %d already in chain.\n", entity->id);
1749 /* Process entity */
1750 if (uvc_scan_chain_entity(chain, entity) < 0)
1754 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1759 if (uvc_scan_chain_backward(chain, &entity) < 0)
1766 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1769 struct uvc_entity *term;
1770 unsigned int nterms = 0;
1773 list_for_each_entry(term, terms, chain) {
1774 if (!UVC_ENTITY_IS_TERM(term) ||
1775 UVC_TERM_DIRECTION(term) != dir)
1779 p += sprintf(p, ",");
1780 if (++nterms >= 4) {
1781 p += sprintf(p, "...");
1784 p += sprintf(p, "%u", term->id);
1790 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1792 static char buffer[43];
1795 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1796 p += sprintf(p, " -> ");
1797 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1802 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1804 struct uvc_video_chain *chain;
1806 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1810 INIT_LIST_HEAD(&chain->entities);
1811 mutex_init(&chain->ctrl_mutex);
1813 v4l2_prio_init(&chain->prio);
1819 * Fallback heuristic for devices that don't connect units and terminals in a
1822 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1823 * to fail, but if we just take the entities we can find and put them together
1824 * in the most sensible chain we can think of, turns out they do work anyway.
1825 * Note: This heuristic assumes there is a single chain.
1827 * At the time of writing, devices known to have such a broken chain are
1828 * - Acer Integrated Camera (5986:055a)
1829 * - Realtek rtl157a7 (0bda:57a7)
1831 static int uvc_scan_fallback(struct uvc_device *dev)
1833 struct uvc_video_chain *chain;
1834 struct uvc_entity *iterm = NULL;
1835 struct uvc_entity *oterm = NULL;
1836 struct uvc_entity *entity;
1837 struct uvc_entity *prev;
1840 * Start by locating the input and output terminals. We only support
1841 * devices with exactly one of each for now.
1843 list_for_each_entry(entity, &dev->entities, list) {
1844 if (UVC_ENTITY_IS_ITERM(entity)) {
1850 if (UVC_ENTITY_IS_OTERM(entity)) {
1857 if (iterm == NULL || oterm == NULL)
1860 /* Allocate the chain and fill it. */
1861 chain = uvc_alloc_chain(dev);
1865 if (uvc_scan_chain_entity(chain, oterm) < 0)
1871 * Add all Processing and Extension Units with two pads. The order
1872 * doesn't matter much, use reverse list traversal to connect units in
1873 * UVC descriptor order as we build the chain from output to input. This
1874 * leads to units appearing in the order meant by the manufacturer for
1875 * the cameras known to require this heuristic.
1877 list_for_each_entry_reverse(entity, &dev->entities, list) {
1878 if (entity->type != UVC_VC_PROCESSING_UNIT &&
1879 entity->type != UVC_VC_EXTENSION_UNIT)
1882 if (entity->num_pads != 2)
1885 if (uvc_scan_chain_entity(chain, entity) < 0)
1888 prev->baSourceID[0] = entity->id;
1892 if (uvc_scan_chain_entity(chain, iterm) < 0)
1895 prev->baSourceID[0] = iterm->id;
1897 list_add_tail(&chain->list, &dev->chains);
1899 uvc_trace(UVC_TRACE_PROBE,
1900 "Found a video chain by fallback heuristic (%s).\n",
1901 uvc_print_chain(chain));
1911 * Scan the device for video chains and register video devices.
1913 * Chains are scanned starting at their output terminals and walked backwards.
1915 static int uvc_scan_device(struct uvc_device *dev)
1917 struct uvc_video_chain *chain;
1918 struct uvc_entity *term;
1920 list_for_each_entry(term, &dev->entities, list) {
1921 if (!UVC_ENTITY_IS_OTERM(term))
1924 /* If the terminal is already included in a chain, skip it.
1925 * This can happen for chains that have multiple output
1926 * terminals, where all output terminals beside the first one
1927 * will be inserted in the chain in forward scans.
1929 if (term->chain.next || term->chain.prev)
1932 chain = uvc_alloc_chain(dev);
1936 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1938 if (uvc_scan_chain(chain, term) < 0) {
1943 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1944 uvc_print_chain(chain));
1946 list_add_tail(&chain->list, &dev->chains);
1949 if (list_empty(&dev->chains))
1950 uvc_scan_fallback(dev);
1952 if (list_empty(&dev->chains)) {
1953 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1960 /* ------------------------------------------------------------------------
1961 * Video device registration and unregistration
1965 * Delete the UVC device.
1967 * Called by the kernel when the last reference to the uvc_device structure
1970 * As this function is called after or during disconnect(), all URBs have
1971 * already been cancelled by the USB core. There is no need to kill the
1972 * interrupt URB manually.
1974 static void uvc_delete(struct kref *kref)
1976 struct uvc_device *dev = container_of(kref, struct uvc_device, ref);
1977 struct list_head *p, *n;
1979 uvc_status_cleanup(dev);
1980 uvc_ctrl_cleanup_device(dev);
1982 usb_put_intf(dev->intf);
1983 usb_put_dev(dev->udev);
1985 #ifdef CONFIG_MEDIA_CONTROLLER
1986 media_device_cleanup(&dev->mdev);
1989 list_for_each_safe(p, n, &dev->chains) {
1990 struct uvc_video_chain *chain;
1991 chain = list_entry(p, struct uvc_video_chain, list);
1995 list_for_each_safe(p, n, &dev->entities) {
1996 struct uvc_entity *entity;
1997 entity = list_entry(p, struct uvc_entity, list);
1998 #ifdef CONFIG_MEDIA_CONTROLLER
1999 uvc_mc_cleanup_entity(entity);
2004 list_for_each_safe(p, n, &dev->streams) {
2005 struct uvc_streaming *streaming;
2006 streaming = list_entry(p, struct uvc_streaming, list);
2007 usb_driver_release_interface(&uvc_driver.driver,
2009 uvc_stream_delete(streaming);
2015 static void uvc_release(struct video_device *vdev)
2017 struct uvc_streaming *stream = video_get_drvdata(vdev);
2018 struct uvc_device *dev = stream->dev;
2020 kref_put(&dev->ref, uvc_delete);
2024 * Unregister the video devices.
2026 static void uvc_unregister_video(struct uvc_device *dev)
2028 struct uvc_streaming *stream;
2030 list_for_each_entry(stream, &dev->streams, list) {
2031 if (!video_is_registered(&stream->vdev))
2034 video_unregister_device(&stream->vdev);
2035 video_unregister_device(&stream->meta.vdev);
2037 uvc_debugfs_cleanup_stream(stream);
2040 uvc_status_unregister(dev);
2043 v4l2_device_unregister(&dev->vdev);
2044 #ifdef CONFIG_MEDIA_CONTROLLER
2045 if (media_devnode_is_registered(dev->mdev.devnode))
2046 media_device_unregister(&dev->mdev);
2050 int uvc_register_video_device(struct uvc_device *dev,
2051 struct uvc_streaming *stream,
2052 struct video_device *vdev,
2053 struct uvc_video_queue *queue,
2054 enum v4l2_buf_type type,
2055 const struct v4l2_file_operations *fops,
2056 const struct v4l2_ioctl_ops *ioctl_ops)
2060 /* Initialize the video buffers queue. */
2061 ret = uvc_queue_init(queue, type, !uvc_no_drop_param);
2065 /* Register the device with V4L. */
2068 * We already hold a reference to dev->udev. The video device will be
2069 * unregistered before the reference is released, so we don't need to
2072 vdev->v4l2_dev = &dev->vdev;
2074 vdev->ioctl_ops = ioctl_ops;
2075 vdev->release = uvc_release;
2076 vdev->prio = &stream->chain->prio;
2077 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
2078 vdev->vfl_dir = VFL_DIR_TX;
2080 vdev->vfl_dir = VFL_DIR_RX;
2083 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2085 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
2087 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2088 vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
2090 case V4L2_BUF_TYPE_META_CAPTURE:
2091 vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING;
2095 strscpy(vdev->name, dev->name, sizeof(vdev->name));
2098 * Set the driver data before calling video_register_device, otherwise
2099 * the file open() handler might race us.
2101 video_set_drvdata(vdev, stream);
2103 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
2105 uvc_printk(KERN_ERR, "Failed to register %s device (%d).\n",
2106 v4l2_type_names[type], ret);
2110 kref_get(&dev->ref);
2114 static int uvc_register_video(struct uvc_device *dev,
2115 struct uvc_streaming *stream)
2119 /* Initialize the streaming interface with default parameters. */
2120 ret = uvc_video_init(stream);
2122 uvc_printk(KERN_ERR, "Failed to initialize the device (%d).\n",
2127 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2128 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE
2129 | V4L2_CAP_META_CAPTURE;
2131 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
2133 uvc_debugfs_init_stream(stream);
2135 /* Register the device with V4L. */
2136 return uvc_register_video_device(dev, stream, &stream->vdev,
2137 &stream->queue, stream->type,
2138 &uvc_fops, &uvc_ioctl_ops);
2142 * Register all video devices in all chains.
2144 static int uvc_register_terms(struct uvc_device *dev,
2145 struct uvc_video_chain *chain)
2147 struct uvc_streaming *stream;
2148 struct uvc_entity *term;
2151 list_for_each_entry(term, &chain->entities, chain) {
2152 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
2155 stream = uvc_stream_by_id(dev, term->id);
2156 if (stream == NULL) {
2157 uvc_printk(KERN_INFO, "No streaming interface found "
2158 "for terminal %u.", term->id);
2162 stream->chain = chain;
2163 ret = uvc_register_video(dev, stream);
2167 /* Register a metadata node, but ignore a possible failure,
2168 * complete registration of video nodes anyway.
2170 uvc_meta_register(stream);
2172 term->vdev = &stream->vdev;
2178 static int uvc_register_chains(struct uvc_device *dev)
2180 struct uvc_video_chain *chain;
2183 list_for_each_entry(chain, &dev->chains, list) {
2184 ret = uvc_register_terms(dev, chain);
2188 #ifdef CONFIG_MEDIA_CONTROLLER
2189 ret = uvc_mc_register_entities(chain);
2191 uvc_printk(KERN_INFO,
2192 "Failed to register entities (%d).\n", ret);
2199 /* ------------------------------------------------------------------------
2200 * USB probe, disconnect, suspend and resume
2203 static const struct uvc_device_info uvc_quirk_none = { 0 };
2205 static int uvc_probe(struct usb_interface *intf,
2206 const struct usb_device_id *id)
2208 struct usb_device *udev = interface_to_usbdev(intf);
2209 struct uvc_device *dev;
2210 const struct uvc_device_info *info =
2211 (const struct uvc_device_info *)id->driver_info;
2215 if (id->idVendor && id->idProduct)
2216 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
2217 "(%04x:%04x)\n", udev->devpath, id->idVendor,
2220 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
2223 /* Allocate memory for the device and initialize it. */
2224 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2228 INIT_LIST_HEAD(&dev->entities);
2229 INIT_LIST_HEAD(&dev->chains);
2230 INIT_LIST_HEAD(&dev->streams);
2231 kref_init(&dev->ref);
2232 atomic_set(&dev->nmappings, 0);
2233 mutex_init(&dev->lock);
2235 dev->udev = usb_get_dev(udev);
2236 dev->intf = usb_get_intf(intf);
2237 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2238 dev->info = info ? info : &uvc_quirk_none;
2239 dev->quirks = uvc_quirks_param == -1
2240 ? dev->info->quirks : uvc_quirks_param;
2242 if (udev->product != NULL)
2243 strscpy(dev->name, udev->product, sizeof(dev->name));
2245 snprintf(dev->name, sizeof(dev->name),
2246 "UVC Camera (%04x:%04x)",
2247 le16_to_cpu(udev->descriptor.idVendor),
2248 le16_to_cpu(udev->descriptor.idProduct));
2251 * Add iFunction or iInterface to names when available as additional
2252 * distinguishers between interfaces. iFunction is prioritized over
2253 * iInterface which matches Windows behavior at the point of writing.
2255 if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
2256 function = intf->intf_assoc->iFunction;
2258 function = intf->cur_altsetting->desc.iInterface;
2259 if (function != 0) {
2262 strlcat(dev->name, ": ", sizeof(dev->name));
2263 len = strlen(dev->name);
2264 usb_string(udev, function, dev->name + len,
2265 sizeof(dev->name) - len);
2268 /* Initialize the media device. */
2269 #ifdef CONFIG_MEDIA_CONTROLLER
2270 dev->mdev.dev = &intf->dev;
2271 strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2273 strscpy(dev->mdev.serial, udev->serial,
2274 sizeof(dev->mdev.serial));
2275 usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2276 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2277 media_device_init(&dev->mdev);
2279 dev->vdev.mdev = &dev->mdev;
2282 /* Parse the Video Class control descriptor. */
2283 if (uvc_parse_control(dev) < 0) {
2284 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
2289 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2290 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2291 udev->product ? udev->product : "<unnamed>",
2292 le16_to_cpu(udev->descriptor.idVendor),
2293 le16_to_cpu(udev->descriptor.idProduct));
2295 if (dev->quirks != dev->info->quirks) {
2296 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
2297 "parameter for testing purpose.\n", dev->quirks);
2298 uvc_printk(KERN_INFO, "Please report required quirks to the "
2299 "linux-uvc-devel mailing list.\n");
2302 /* Register the V4L2 device. */
2303 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2306 /* Initialize controls. */
2307 if (uvc_ctrl_init_device(dev) < 0)
2310 /* Scan the device for video chains. */
2311 if (uvc_scan_device(dev) < 0)
2314 /* Register video device nodes. */
2315 if (uvc_register_chains(dev) < 0)
2318 #ifdef CONFIG_MEDIA_CONTROLLER
2319 /* Register the media device node */
2320 if (media_device_register(&dev->mdev) < 0)
2323 /* Save our data pointer in the interface data. */
2324 usb_set_intfdata(intf, dev);
2326 /* Initialize the interrupt URB. */
2327 if ((ret = uvc_status_init(dev)) < 0) {
2328 uvc_printk(KERN_INFO, "Unable to initialize the status "
2329 "endpoint (%d), status interrupt will not be "
2330 "supported.\n", ret);
2333 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
2334 usb_enable_autosuspend(udev);
2338 uvc_unregister_video(dev);
2339 kref_put(&dev->ref, uvc_delete);
2343 static void uvc_disconnect(struct usb_interface *intf)
2345 struct uvc_device *dev = usb_get_intfdata(intf);
2347 /* Set the USB interface data to NULL. This can be done outside the
2348 * lock, as there's no other reader.
2350 usb_set_intfdata(intf, NULL);
2352 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2353 UVC_SC_VIDEOSTREAMING)
2356 uvc_unregister_video(dev);
2357 kref_put(&dev->ref, uvc_delete);
2360 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2362 struct uvc_device *dev = usb_get_intfdata(intf);
2363 struct uvc_streaming *stream;
2365 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2366 intf->cur_altsetting->desc.bInterfaceNumber);
2368 /* Controls are cached on the fly so they don't need to be saved. */
2369 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2370 UVC_SC_VIDEOCONTROL) {
2371 mutex_lock(&dev->lock);
2373 uvc_status_stop(dev);
2374 mutex_unlock(&dev->lock);
2378 list_for_each_entry(stream, &dev->streams, list) {
2379 if (stream->intf == intf)
2380 return uvc_video_suspend(stream);
2383 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2388 static int __uvc_resume(struct usb_interface *intf, int reset)
2390 struct uvc_device *dev = usb_get_intfdata(intf);
2391 struct uvc_streaming *stream;
2394 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2395 intf->cur_altsetting->desc.bInterfaceNumber);
2397 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2398 UVC_SC_VIDEOCONTROL) {
2400 ret = uvc_ctrl_restore_values(dev);
2405 mutex_lock(&dev->lock);
2407 ret = uvc_status_start(dev, GFP_NOIO);
2408 mutex_unlock(&dev->lock);
2413 list_for_each_entry(stream, &dev->streams, list) {
2414 if (stream->intf == intf) {
2415 ret = uvc_video_resume(stream, reset);
2417 uvc_queue_streamoff(&stream->queue,
2418 stream->queue.queue.type);
2423 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2428 static int uvc_resume(struct usb_interface *intf)
2430 return __uvc_resume(intf, 0);
2433 static int uvc_reset_resume(struct usb_interface *intf)
2435 return __uvc_resume(intf, 1);
2438 /* ------------------------------------------------------------------------
2442 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2444 if (uvc_clock_param == CLOCK_MONOTONIC)
2445 return sprintf(buffer, "CLOCK_MONOTONIC");
2447 return sprintf(buffer, "CLOCK_REALTIME");
2450 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2452 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2453 val += strlen("clock_");
2455 if (strcasecmp(val, "monotonic") == 0)
2456 uvc_clock_param = CLOCK_MONOTONIC;
2457 else if (strcasecmp(val, "realtime") == 0)
2458 uvc_clock_param = CLOCK_REALTIME;
2465 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2466 &uvc_clock_param, S_IRUGO|S_IWUSR);
2467 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2468 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2469 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2470 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2471 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2472 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2473 MODULE_PARM_DESC(quirks, "Forced device quirks");
2474 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2475 MODULE_PARM_DESC(trace, "Trace level bitmask");
2476 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2477 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2479 /* ------------------------------------------------------------------------
2480 * Driver initialization and cleanup
2483 static const struct uvc_device_info uvc_quirk_probe_minmax = {
2484 .quirks = UVC_QUIRK_PROBE_MINMAX,
2487 static const struct uvc_device_info uvc_quirk_fix_bandwidth = {
2488 .quirks = UVC_QUIRK_FIX_BANDWIDTH,
2491 static const struct uvc_device_info uvc_quirk_probe_def = {
2492 .quirks = UVC_QUIRK_PROBE_DEF,
2495 static const struct uvc_device_info uvc_quirk_stream_no_fid = {
2496 .quirks = UVC_QUIRK_STREAM_NO_FID,
2499 static const struct uvc_device_info uvc_quirk_force_y8 = {
2500 .quirks = UVC_QUIRK_FORCE_Y8,
2503 #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q}
2504 #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \
2508 * The Logitech cameras listed below have their interface class set to
2509 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2510 * though they are compliant.
2512 static const struct usb_device_id uvc_ids[] = {
2513 /* LogiLink Wireless Webcam */
2514 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2515 | USB_DEVICE_ID_MATCH_INT_INFO,
2517 .idProduct = 0xa91a,
2518 .bInterfaceClass = USB_CLASS_VIDEO,
2519 .bInterfaceSubClass = 1,
2520 .bInterfaceProtocol = 0,
2521 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2522 /* Genius eFace 2025 */
2523 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2524 | USB_DEVICE_ID_MATCH_INT_INFO,
2526 .idProduct = 0x706e,
2527 .bInterfaceClass = USB_CLASS_VIDEO,
2528 .bInterfaceSubClass = 1,
2529 .bInterfaceProtocol = 0,
2530 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2531 /* Microsoft Lifecam NX-6000 */
2532 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2533 | USB_DEVICE_ID_MATCH_INT_INFO,
2535 .idProduct = 0x00f8,
2536 .bInterfaceClass = USB_CLASS_VIDEO,
2537 .bInterfaceSubClass = 1,
2538 .bInterfaceProtocol = 0,
2539 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2540 /* Microsoft Lifecam NX-3000 */
2541 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2542 | USB_DEVICE_ID_MATCH_INT_INFO,
2544 .idProduct = 0x0721,
2545 .bInterfaceClass = USB_CLASS_VIDEO,
2546 .bInterfaceSubClass = 1,
2547 .bInterfaceProtocol = 0,
2548 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2549 /* Microsoft Lifecam VX-7000 */
2550 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2551 | USB_DEVICE_ID_MATCH_INT_INFO,
2553 .idProduct = 0x0723,
2554 .bInterfaceClass = USB_CLASS_VIDEO,
2555 .bInterfaceSubClass = 1,
2556 .bInterfaceProtocol = 0,
2557 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2558 /* Logitech, Webcam C910 */
2559 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2560 | USB_DEVICE_ID_MATCH_INT_INFO,
2562 .idProduct = 0x0821,
2563 .bInterfaceClass = USB_CLASS_VIDEO,
2564 .bInterfaceSubClass = 1,
2565 .bInterfaceProtocol = 0,
2566 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
2567 /* Logitech, Webcam B910 */
2568 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2569 | USB_DEVICE_ID_MATCH_INT_INFO,
2571 .idProduct = 0x0823,
2572 .bInterfaceClass = USB_CLASS_VIDEO,
2573 .bInterfaceSubClass = 1,
2574 .bInterfaceProtocol = 0,
2575 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
2576 /* Logitech Quickcam Fusion */
2577 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2578 | USB_DEVICE_ID_MATCH_INT_INFO,
2580 .idProduct = 0x08c1,
2581 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2582 .bInterfaceSubClass = 1,
2583 .bInterfaceProtocol = 0 },
2584 /* Logitech Quickcam Orbit MP */
2585 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2586 | USB_DEVICE_ID_MATCH_INT_INFO,
2588 .idProduct = 0x08c2,
2589 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2590 .bInterfaceSubClass = 1,
2591 .bInterfaceProtocol = 0 },
2592 /* Logitech Quickcam Pro for Notebook */
2593 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2594 | USB_DEVICE_ID_MATCH_INT_INFO,
2596 .idProduct = 0x08c3,
2597 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2598 .bInterfaceSubClass = 1,
2599 .bInterfaceProtocol = 0 },
2600 /* Logitech Quickcam Pro 5000 */
2601 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2602 | USB_DEVICE_ID_MATCH_INT_INFO,
2604 .idProduct = 0x08c5,
2605 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2606 .bInterfaceSubClass = 1,
2607 .bInterfaceProtocol = 0 },
2608 /* Logitech Quickcam OEM Dell Notebook */
2609 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2610 | USB_DEVICE_ID_MATCH_INT_INFO,
2612 .idProduct = 0x08c6,
2613 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2614 .bInterfaceSubClass = 1,
2615 .bInterfaceProtocol = 0 },
2616 /* Logitech Quickcam OEM Cisco VT Camera II */
2617 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2618 | USB_DEVICE_ID_MATCH_INT_INFO,
2620 .idProduct = 0x08c7,
2621 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2622 .bInterfaceSubClass = 1,
2623 .bInterfaceProtocol = 0 },
2624 /* Logitech HD Pro Webcam C920 */
2625 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2626 | USB_DEVICE_ID_MATCH_INT_INFO,
2628 .idProduct = 0x082d,
2629 .bInterfaceClass = USB_CLASS_VIDEO,
2630 .bInterfaceSubClass = 1,
2631 .bInterfaceProtocol = 0,
2632 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT) },
2633 /* Chicony CNF7129 (Asus EEE 100HE) */
2634 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2635 | USB_DEVICE_ID_MATCH_INT_INFO,
2637 .idProduct = 0xb071,
2638 .bInterfaceClass = USB_CLASS_VIDEO,
2639 .bInterfaceSubClass = 1,
2640 .bInterfaceProtocol = 0,
2641 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },
2642 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2643 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2644 | USB_DEVICE_ID_MATCH_INT_INFO,
2646 .idProduct = 0x3820,
2647 .bInterfaceClass = USB_CLASS_VIDEO,
2648 .bInterfaceSubClass = 1,
2649 .bInterfaceProtocol = 0,
2650 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2651 /* Dell XPS m1530 */
2652 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2653 | USB_DEVICE_ID_MATCH_INT_INFO,
2655 .idProduct = 0x2640,
2656 .bInterfaceClass = USB_CLASS_VIDEO,
2657 .bInterfaceSubClass = 1,
2658 .bInterfaceProtocol = 0,
2659 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2660 /* Dell SP2008WFP Monitor */
2661 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2662 | USB_DEVICE_ID_MATCH_INT_INFO,
2664 .idProduct = 0x2641,
2665 .bInterfaceClass = USB_CLASS_VIDEO,
2666 .bInterfaceSubClass = 1,
2667 .bInterfaceProtocol = 0,
2668 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2669 /* Dell Alienware X51 */
2670 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2671 | USB_DEVICE_ID_MATCH_INT_INFO,
2673 .idProduct = 0x2643,
2674 .bInterfaceClass = USB_CLASS_VIDEO,
2675 .bInterfaceSubClass = 1,
2676 .bInterfaceProtocol = 0,
2677 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2678 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2679 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2680 | USB_DEVICE_ID_MATCH_INT_INFO,
2682 .idProduct = 0x264a,
2683 .bInterfaceClass = USB_CLASS_VIDEO,
2684 .bInterfaceSubClass = 1,
2685 .bInterfaceProtocol = 0,
2686 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2687 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2688 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2689 | USB_DEVICE_ID_MATCH_INT_INFO,
2691 .idProduct = 0x7670,
2692 .bInterfaceClass = USB_CLASS_VIDEO,
2693 .bInterfaceSubClass = 1,
2694 .bInterfaceProtocol = 0,
2695 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2696 /* Apple Built-In iSight */
2697 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2698 | USB_DEVICE_ID_MATCH_INT_INFO,
2700 .idProduct = 0x8501,
2701 .bInterfaceClass = USB_CLASS_VIDEO,
2702 .bInterfaceSubClass = 1,
2703 .bInterfaceProtocol = 0,
2704 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2705 | UVC_QUIRK_BUILTIN_ISIGHT) },
2706 /* Apple Built-In iSight via iBridge */
2707 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2708 | USB_DEVICE_ID_MATCH_INT_INFO,
2710 .idProduct = 0x8600,
2711 .bInterfaceClass = USB_CLASS_VIDEO,
2712 .bInterfaceSubClass = 1,
2713 .bInterfaceProtocol = 0,
2714 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2715 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2716 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2717 | USB_DEVICE_ID_MATCH_INT_INFO,
2719 .idProduct = 0x0403,
2720 .bInterfaceClass = USB_CLASS_VIDEO,
2721 .bInterfaceSubClass = 1,
2722 .bInterfaceProtocol = 0,
2723 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2724 /* Genesys Logic USB 2.0 PC Camera */
2725 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2726 | USB_DEVICE_ID_MATCH_INT_INFO,
2728 .idProduct = 0x0505,
2729 .bInterfaceClass = USB_CLASS_VIDEO,
2730 .bInterfaceSubClass = 1,
2731 .bInterfaceProtocol = 0,
2732 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2733 /* Hercules Classic Silver */
2734 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2735 | USB_DEVICE_ID_MATCH_INT_INFO,
2737 .idProduct = 0x300c,
2738 .bInterfaceClass = USB_CLASS_VIDEO,
2739 .bInterfaceSubClass = 1,
2740 .bInterfaceProtocol = 0,
2741 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2743 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2744 | USB_DEVICE_ID_MATCH_INT_INFO,
2746 .idProduct = 0x332d,
2747 .bInterfaceClass = USB_CLASS_VIDEO,
2748 .bInterfaceSubClass = 1,
2749 .bInterfaceProtocol = 0,
2750 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2751 /* ViMicro - Minoru3D */
2752 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2753 | USB_DEVICE_ID_MATCH_INT_INFO,
2755 .idProduct = 0x3410,
2756 .bInterfaceClass = USB_CLASS_VIDEO,
2757 .bInterfaceSubClass = 1,
2758 .bInterfaceProtocol = 0,
2759 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2760 /* ViMicro Venus - Minoru3D */
2761 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2762 | USB_DEVICE_ID_MATCH_INT_INFO,
2764 .idProduct = 0x3420,
2765 .bInterfaceClass = USB_CLASS_VIDEO,
2766 .bInterfaceSubClass = 1,
2767 .bInterfaceProtocol = 0,
2768 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2769 /* Ophir Optronics - SPCAM 620U */
2770 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2771 | USB_DEVICE_ID_MATCH_INT_INFO,
2773 .idProduct = 0x0555,
2774 .bInterfaceClass = USB_CLASS_VIDEO,
2775 .bInterfaceSubClass = 1,
2776 .bInterfaceProtocol = 0,
2777 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2779 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2780 | USB_DEVICE_ID_MATCH_INT_INFO,
2782 .idProduct = 0x0004,
2783 .bInterfaceClass = USB_CLASS_VIDEO,
2784 .bInterfaceSubClass = 1,
2785 .bInterfaceProtocol = 0,
2786 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2787 | UVC_QUIRK_PROBE_DEF) },
2788 /* IMC Networks (Medion Akoya) */
2789 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2790 | USB_DEVICE_ID_MATCH_INT_INFO,
2792 .idProduct = 0x5103,
2793 .bInterfaceClass = USB_CLASS_VIDEO,
2794 .bInterfaceSubClass = 1,
2795 .bInterfaceProtocol = 0,
2796 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2797 /* JMicron USB2.0 XGA WebCam */
2798 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2799 | USB_DEVICE_ID_MATCH_INT_INFO,
2801 .idProduct = 0x0310,
2802 .bInterfaceClass = USB_CLASS_VIDEO,
2803 .bInterfaceSubClass = 1,
2804 .bInterfaceProtocol = 0,
2805 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2806 /* Syntek (HP Spartan) */
2807 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2808 | USB_DEVICE_ID_MATCH_INT_INFO,
2810 .idProduct = 0x5212,
2811 .bInterfaceClass = USB_CLASS_VIDEO,
2812 .bInterfaceSubClass = 1,
2813 .bInterfaceProtocol = 0,
2814 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2815 /* Syntek (Samsung Q310) */
2816 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2817 | USB_DEVICE_ID_MATCH_INT_INFO,
2819 .idProduct = 0x5931,
2820 .bInterfaceClass = USB_CLASS_VIDEO,
2821 .bInterfaceSubClass = 1,
2822 .bInterfaceProtocol = 0,
2823 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2824 /* Syntek (Packard Bell EasyNote MX52 */
2825 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2826 | USB_DEVICE_ID_MATCH_INT_INFO,
2828 .idProduct = 0x8a12,
2829 .bInterfaceClass = USB_CLASS_VIDEO,
2830 .bInterfaceSubClass = 1,
2831 .bInterfaceProtocol = 0,
2832 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2833 /* Syntek (Asus F9SG) */
2834 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2835 | USB_DEVICE_ID_MATCH_INT_INFO,
2837 .idProduct = 0x8a31,
2838 .bInterfaceClass = USB_CLASS_VIDEO,
2839 .bInterfaceSubClass = 1,
2840 .bInterfaceProtocol = 0,
2841 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2842 /* Syntek (Asus U3S) */
2843 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2844 | USB_DEVICE_ID_MATCH_INT_INFO,
2846 .idProduct = 0x8a33,
2847 .bInterfaceClass = USB_CLASS_VIDEO,
2848 .bInterfaceSubClass = 1,
2849 .bInterfaceProtocol = 0,
2850 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2851 /* Syntek (JAOtech Smart Terminal) */
2852 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2853 | USB_DEVICE_ID_MATCH_INT_INFO,
2855 .idProduct = 0x8a34,
2856 .bInterfaceClass = USB_CLASS_VIDEO,
2857 .bInterfaceSubClass = 1,
2858 .bInterfaceProtocol = 0,
2859 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2861 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2862 | USB_DEVICE_ID_MATCH_INT_INFO,
2864 .idProduct = 0x0202,
2865 .bInterfaceClass = USB_CLASS_VIDEO,
2866 .bInterfaceSubClass = 1,
2867 .bInterfaceProtocol = 0,
2868 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2869 /* Lenovo Thinkpad SL400/SL500 */
2870 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2871 | USB_DEVICE_ID_MATCH_INT_INFO,
2873 .idProduct = 0x480b,
2874 .bInterfaceClass = USB_CLASS_VIDEO,
2875 .bInterfaceSubClass = 1,
2876 .bInterfaceProtocol = 0,
2877 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2878 /* Aveo Technology USB 2.0 Camera */
2879 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2880 | USB_DEVICE_ID_MATCH_INT_INFO,
2882 .idProduct = 0x0306,
2883 .bInterfaceClass = USB_CLASS_VIDEO,
2884 .bInterfaceSubClass = 1,
2885 .bInterfaceProtocol = 0,
2886 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2887 | UVC_QUIRK_PROBE_EXTRAFIELDS) },
2888 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2889 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2890 | USB_DEVICE_ID_MATCH_INT_INFO,
2892 .idProduct = 0x0516,
2893 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2894 .bInterfaceSubClass = 1,
2895 .bInterfaceProtocol = 0 },
2896 /* Ecamm Pico iMage */
2897 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2898 | USB_DEVICE_ID_MATCH_INT_INFO,
2900 .idProduct = 0xcafe,
2901 .bInterfaceClass = USB_CLASS_VIDEO,
2902 .bInterfaceSubClass = 1,
2903 .bInterfaceProtocol = 0,
2904 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) },
2905 /* Manta MM-353 Plako */
2906 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2907 | USB_DEVICE_ID_MATCH_INT_INFO,
2909 .idProduct = 0x3188,
2910 .bInterfaceClass = USB_CLASS_VIDEO,
2911 .bInterfaceSubClass = 1,
2912 .bInterfaceProtocol = 0,
2913 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2914 /* FSC WebCam V30S */
2915 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2916 | USB_DEVICE_ID_MATCH_INT_INFO,
2918 .idProduct = 0x3288,
2919 .bInterfaceClass = USB_CLASS_VIDEO,
2920 .bInterfaceSubClass = 1,
2921 .bInterfaceProtocol = 0,
2922 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2923 /* Arkmicro unbranded */
2924 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2925 | USB_DEVICE_ID_MATCH_INT_INFO,
2927 .idProduct = 0x3290,
2928 .bInterfaceClass = USB_CLASS_VIDEO,
2929 .bInterfaceSubClass = 1,
2930 .bInterfaceProtocol = 0,
2931 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2932 /* The Imaging Source USB CCD cameras */
2933 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2934 | USB_DEVICE_ID_MATCH_INT_INFO,
2936 .idProduct = 0x8102,
2937 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2938 .bInterfaceSubClass = 1,
2939 .bInterfaceProtocol = 0 },
2940 /* Bodelin ProScopeHR */
2941 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2942 | USB_DEVICE_ID_MATCH_DEV_HI
2943 | USB_DEVICE_ID_MATCH_INT_INFO,
2945 .idProduct = 0x1000,
2946 .bcdDevice_hi = 0x0126,
2947 .bInterfaceClass = USB_CLASS_VIDEO,
2948 .bInterfaceSubClass = 1,
2949 .bInterfaceProtocol = 0,
2950 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) },
2951 /* MSI StarCam 370i */
2952 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2953 | USB_DEVICE_ID_MATCH_INT_INFO,
2955 .idProduct = 0x2951,
2956 .bInterfaceClass = USB_CLASS_VIDEO,
2957 .bInterfaceSubClass = 1,
2958 .bInterfaceProtocol = 0,
2959 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2960 /* Generalplus Technology Inc. 808 Camera */
2961 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2962 | USB_DEVICE_ID_MATCH_INT_INFO,
2964 .idProduct = 0x2002,
2965 .bInterfaceClass = USB_CLASS_VIDEO,
2966 .bInterfaceSubClass = 1,
2967 .bInterfaceProtocol = 0,
2968 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2969 /* SiGma Micro USB Web Camera */
2970 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2971 | USB_DEVICE_ID_MATCH_INT_INFO,
2973 .idProduct = 0x3000,
2974 .bInterfaceClass = USB_CLASS_VIDEO,
2975 .bInterfaceSubClass = 1,
2976 .bInterfaceProtocol = 0,
2977 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2978 | UVC_QUIRK_IGNORE_SELECTOR_UNIT) },
2979 /* Oculus VR Positional Tracker DK2 */
2980 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2981 | USB_DEVICE_ID_MATCH_INT_INFO,
2983 .idProduct = 0x0201,
2984 .bInterfaceClass = USB_CLASS_VIDEO,
2985 .bInterfaceSubClass = 1,
2986 .bInterfaceProtocol = 0,
2987 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
2988 /* Oculus VR Rift Sensor */
2989 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2990 | USB_DEVICE_ID_MATCH_INT_INFO,
2992 .idProduct = 0x0211,
2993 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2994 .bInterfaceSubClass = 1,
2995 .bInterfaceProtocol = 0,
2996 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
2997 /* GEO Semiconductor GC6500 */
2998 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2999 | USB_DEVICE_ID_MATCH_INT_INFO,
3001 .idProduct = 0x4d53,
3002 .bInterfaceClass = USB_CLASS_VIDEO,
3003 .bInterfaceSubClass = 1,
3004 .bInterfaceProtocol = 0,
3005 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) },
3006 /* Intel RealSense D4M */
3007 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3008 | USB_DEVICE_ID_MATCH_INT_INFO,
3010 .idProduct = 0x0b03,
3011 .bInterfaceClass = USB_CLASS_VIDEO,
3012 .bInterfaceSubClass = 1,
3013 .bInterfaceProtocol = 0,
3014 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3015 /* Generic USB Video Class */
3016 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
3017 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
3021 MODULE_DEVICE_TABLE(usb, uvc_ids);
3023 struct uvc_driver uvc_driver = {
3027 .disconnect = uvc_disconnect,
3028 .suspend = uvc_suspend,
3029 .resume = uvc_resume,
3030 .reset_resume = uvc_reset_resume,
3031 .id_table = uvc_ids,
3032 .supports_autosuspend = 1,
3036 static int __init uvc_init(void)
3042 ret = usb_register(&uvc_driver.driver);
3044 uvc_debugfs_cleanup();
3048 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
3052 static void __exit uvc_cleanup(void)
3054 usb_deregister(&uvc_driver.driver);
3055 uvc_debugfs_cleanup();
3058 module_init(uvc_init);
3059 module_exit(uvc_cleanup);
3061 MODULE_AUTHOR(DRIVER_AUTHOR);
3062 MODULE_DESCRIPTION(DRIVER_DESC);
3063 MODULE_LICENSE("GPL");
3064 MODULE_VERSION(DRIVER_VERSION);