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/gpio/consumer.h>
11 #include <linux/kernel.h>
12 #include <linux/list.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/usb.h>
16 #include <linux/videodev2.h>
17 #include <linux/vmalloc.h>
18 #include <linux/wait.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_dbg_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,
159 .guid = UVC_GUID_FORMAT_H265,
160 .fcc = V4L2_PIX_FMT_HEVC,
163 .name = "Greyscale 8 L/R (Y8I)",
164 .guid = UVC_GUID_FORMAT_Y8I,
165 .fcc = V4L2_PIX_FMT_Y8I,
168 .name = "Greyscale 12 L/R (Y12I)",
169 .guid = UVC_GUID_FORMAT_Y12I,
170 .fcc = V4L2_PIX_FMT_Y12I,
173 .name = "Depth data 16-bit (Z16)",
174 .guid = UVC_GUID_FORMAT_Z16,
175 .fcc = V4L2_PIX_FMT_Z16,
178 .name = "Bayer 10-bit (SRGGB10P)",
179 .guid = UVC_GUID_FORMAT_RW10,
180 .fcc = V4L2_PIX_FMT_SRGGB10P,
183 .name = "Bayer 16-bit (SBGGR16)",
184 .guid = UVC_GUID_FORMAT_BG16,
185 .fcc = V4L2_PIX_FMT_SBGGR16,
188 .name = "Bayer 16-bit (SGBRG16)",
189 .guid = UVC_GUID_FORMAT_GB16,
190 .fcc = V4L2_PIX_FMT_SGBRG16,
193 .name = "Bayer 16-bit (SRGGB16)",
194 .guid = UVC_GUID_FORMAT_RG16,
195 .fcc = V4L2_PIX_FMT_SRGGB16,
198 .name = "Bayer 16-bit (SGRBG16)",
199 .guid = UVC_GUID_FORMAT_GR16,
200 .fcc = V4L2_PIX_FMT_SGRBG16,
203 .name = "Depth data 16-bit (Z16)",
204 .guid = UVC_GUID_FORMAT_INVZ,
205 .fcc = V4L2_PIX_FMT_Z16,
208 .name = "Greyscale 10-bit (Y10 )",
209 .guid = UVC_GUID_FORMAT_INVI,
210 .fcc = V4L2_PIX_FMT_Y10,
213 .name = "IR:Depth 26-bit (INZI)",
214 .guid = UVC_GUID_FORMAT_INZI,
215 .fcc = V4L2_PIX_FMT_INZI,
218 .name = "4-bit Depth Confidence (Packed)",
219 .guid = UVC_GUID_FORMAT_CNF4,
220 .fcc = V4L2_PIX_FMT_CNF4,
224 .guid = UVC_GUID_FORMAT_HEVC,
225 .fcc = V4L2_PIX_FMT_HEVC,
229 /* ------------------------------------------------------------------------
233 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
236 struct usb_host_endpoint *ep;
239 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
240 ep = &alts->endpoint[i];
241 if (ep->desc.bEndpointAddress == epaddr)
248 static struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16])
250 unsigned int len = ARRAY_SIZE(uvc_fmts);
253 for (i = 0; i < len; ++i) {
254 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
261 static enum v4l2_colorspace uvc_colorspace(const u8 primaries)
263 static const enum v4l2_colorspace colorprimaries[] = {
264 V4L2_COLORSPACE_SRGB, /* Unspecified */
265 V4L2_COLORSPACE_SRGB,
266 V4L2_COLORSPACE_470_SYSTEM_M,
267 V4L2_COLORSPACE_470_SYSTEM_BG,
268 V4L2_COLORSPACE_SMPTE170M,
269 V4L2_COLORSPACE_SMPTE240M,
272 if (primaries < ARRAY_SIZE(colorprimaries))
273 return colorprimaries[primaries];
275 return V4L2_COLORSPACE_SRGB; /* Reserved */
278 static enum v4l2_xfer_func uvc_xfer_func(const u8 transfer_characteristics)
281 * V4L2 does not currently have definitions for all possible values of
282 * UVC transfer characteristics. If v4l2_xfer_func is extended with new
283 * values, the mapping below should be updated.
285 * Substitutions are taken from the mapping given for
286 * V4L2_XFER_FUNC_DEFAULT documented in videodev2.h.
288 static const enum v4l2_xfer_func xfer_funcs[] = {
289 V4L2_XFER_FUNC_DEFAULT, /* Unspecified */
291 V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 M */
292 V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 B, G */
293 V4L2_XFER_FUNC_709, /* Substitution for SMPTE 170M */
294 V4L2_XFER_FUNC_SMPTE240M,
299 if (transfer_characteristics < ARRAY_SIZE(xfer_funcs))
300 return xfer_funcs[transfer_characteristics];
302 return V4L2_XFER_FUNC_DEFAULT; /* Reserved */
305 static enum v4l2_ycbcr_encoding uvc_ycbcr_enc(const u8 matrix_coefficients)
308 * V4L2 does not currently have definitions for all possible values of
309 * UVC matrix coefficients. If v4l2_ycbcr_encoding is extended with new
310 * values, the mapping below should be updated.
312 * Substitutions are taken from the mapping given for
313 * V4L2_YCBCR_ENC_DEFAULT documented in videodev2.h.
315 * FCC is assumed to be close enough to 601.
317 static const enum v4l2_ycbcr_encoding ycbcr_encs[] = {
318 V4L2_YCBCR_ENC_DEFAULT, /* Unspecified */
320 V4L2_YCBCR_ENC_601, /* Substitution for FCC */
321 V4L2_YCBCR_ENC_601, /* Substitution for BT.470-2 B, G */
323 V4L2_YCBCR_ENC_SMPTE240M,
326 if (matrix_coefficients < ARRAY_SIZE(ycbcr_encs))
327 return ycbcr_encs[matrix_coefficients];
329 return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */
333 * Simplify a fraction using a simple continued fraction decomposition. The
334 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
335 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
336 * arbitrary parameters to remove non-significative terms from the simple
337 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
338 * respectively seems to give nice results.
340 void uvc_simplify_fraction(u32 *numerator, u32 *denominator,
341 unsigned int n_terms, unsigned int threshold)
347 an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL);
352 * Convert the fraction to a simple continued fraction. See
353 * https://en.wikipedia.org/wiki/Continued_fraction
354 * Stop if the current term is bigger than or equal to the given
360 for (n = 0; n < n_terms && y != 0; ++n) {
362 if (an[n] >= threshold) {
373 /* Expand the simple continued fraction back to an integer fraction. */
377 for (i = n; i > 0; --i) {
389 * Convert a fraction to a frame interval in 100ns multiples. The idea here is
390 * to compute numerator / denominator * 10000000 using 32 bit fixed point
393 u32 uvc_fraction_to_interval(u32 numerator, u32 denominator)
397 /* Saturate the result if the operation would overflow. */
398 if (denominator == 0 ||
399 numerator/denominator >= ((u32)-1)/10000000)
403 * Divide both the denominator and the multiplier by two until
404 * numerator * multiplier doesn't overflow. If anyone knows a better
405 * algorithm please let me know.
407 multiplier = 10000000;
408 while (numerator > ((u32)-1)/multiplier) {
413 return denominator ? numerator * multiplier / denominator : 0;
416 /* ------------------------------------------------------------------------
417 * Terminal and unit management
420 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
422 struct uvc_entity *entity;
424 list_for_each_entry(entity, &dev->entities, list) {
425 if (entity->id == id)
432 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
433 int id, struct uvc_entity *entity)
438 entity = list_entry(&dev->entities, struct uvc_entity, list);
440 list_for_each_entry_continue(entity, &dev->entities, list) {
441 for (i = 0; i < entity->bNrInPins; ++i)
442 if (entity->baSourceID[i] == id)
449 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
451 struct uvc_streaming *stream;
453 list_for_each_entry(stream, &dev->streams, list) {
454 if (stream->header.bTerminalLink == id)
461 /* ------------------------------------------------------------------------
462 * Streaming Object Management
465 static void uvc_stream_delete(struct uvc_streaming *stream)
467 if (stream->async_wq)
468 destroy_workqueue(stream->async_wq);
470 mutex_destroy(&stream->mutex);
472 usb_put_intf(stream->intf);
474 kfree(stream->format);
475 kfree(stream->header.bmaControls);
479 static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev,
480 struct usb_interface *intf)
482 struct uvc_streaming *stream;
484 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
488 mutex_init(&stream->mutex);
491 stream->intf = usb_get_intf(intf);
492 stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
494 /* Allocate a stream specific work queue for asynchronous tasks. */
495 stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | WQ_HIGHPRI,
497 if (!stream->async_wq) {
498 uvc_stream_delete(stream);
505 /* ------------------------------------------------------------------------
506 * Descriptors parsing
509 static int uvc_parse_format(struct uvc_device *dev,
510 struct uvc_streaming *streaming, struct uvc_format *format,
511 u32 **intervals, unsigned char *buffer, int buflen)
513 struct usb_interface *intf = streaming->intf;
514 struct usb_host_interface *alts = intf->cur_altsetting;
515 struct uvc_format_desc *fmtdesc;
516 struct uvc_frame *frame;
517 const unsigned char *start = buffer;
518 unsigned int width_multiplier = 1;
519 unsigned int interval;
523 format->type = buffer[2];
524 format->index = buffer[3];
527 case UVC_VS_FORMAT_UNCOMPRESSED:
528 case UVC_VS_FORMAT_FRAME_BASED:
529 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
532 "device %d videostreaming interface %d FORMAT error\n",
534 alts->desc.bInterfaceNumber);
538 /* Find the format descriptor from its GUID. */
539 fmtdesc = uvc_format_by_guid(&buffer[5]);
541 if (fmtdesc != NULL) {
542 strscpy(format->name, fmtdesc->name,
543 sizeof(format->name));
544 format->fcc = fmtdesc->fcc;
546 dev_info(&streaming->intf->dev,
547 "Unknown video format %pUl\n", &buffer[5]);
548 snprintf(format->name, sizeof(format->name), "%pUl\n",
553 format->bpp = buffer[21];
556 * Some devices report a format that doesn't match what they
559 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
560 if (format->fcc == V4L2_PIX_FMT_YUYV) {
561 strscpy(format->name, "Greyscale 8-bit (Y8 )",
562 sizeof(format->name));
563 format->fcc = V4L2_PIX_FMT_GREY;
565 width_multiplier = 2;
569 /* Some devices report bpp that doesn't match the format. */
570 if (dev->quirks & UVC_QUIRK_FORCE_BPP) {
571 const struct v4l2_format_info *info =
572 v4l2_format_info(format->fcc);
575 unsigned int div = info->hdiv * info->vdiv;
577 n = info->bpp[0] * div;
578 for (i = 1; i < info->comp_planes; i++)
581 format->bpp = DIV_ROUND_UP(8 * n, div);
585 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
586 ftype = UVC_VS_FRAME_UNCOMPRESSED;
588 ftype = UVC_VS_FRAME_FRAME_BASED;
590 format->flags = UVC_FMT_FLAG_COMPRESSED;
594 case UVC_VS_FORMAT_MJPEG:
597 "device %d videostreaming interface %d FORMAT error\n",
599 alts->desc.bInterfaceNumber);
603 strscpy(format->name, "MJPEG", sizeof(format->name));
604 format->fcc = V4L2_PIX_FMT_MJPEG;
605 format->flags = UVC_FMT_FLAG_COMPRESSED;
607 ftype = UVC_VS_FRAME_MJPEG;
610 case UVC_VS_FORMAT_DV:
613 "device %d videostreaming interface %d FORMAT error\n",
615 alts->desc.bInterfaceNumber);
619 switch (buffer[8] & 0x7f) {
621 strscpy(format->name, "SD-DV", sizeof(format->name));
624 strscpy(format->name, "SDL-DV", sizeof(format->name));
627 strscpy(format->name, "HD-DV", sizeof(format->name));
631 "device %d videostreaming interface %d: unknown DV format %u\n",
633 alts->desc.bInterfaceNumber, buffer[8]);
637 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
638 sizeof(format->name));
640 format->fcc = V4L2_PIX_FMT_DV;
641 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
645 /* Create a dummy frame descriptor. */
646 frame = &format->frame[0];
647 memset(&format->frame[0], 0, sizeof(format->frame[0]));
648 frame->bFrameIntervalType = 1;
649 frame->dwDefaultFrameInterval = 1;
650 frame->dwFrameInterval = *intervals;
655 case UVC_VS_FORMAT_MPEG2TS:
656 case UVC_VS_FORMAT_STREAM_BASED:
657 /* Not supported yet. */
660 "device %d videostreaming interface %d unsupported format %u\n",
661 dev->udev->devnum, alts->desc.bInterfaceNumber,
666 uvc_dbg(dev, DESCR, "Found format %s\n", format->name);
672 * Parse the frame descriptors. Only uncompressed, MJPEG and frame
673 * based formats have frame descriptors.
675 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
676 buffer[2] == ftype) {
677 frame = &format->frame[format->nframes];
678 if (ftype != UVC_VS_FRAME_FRAME_BASED)
679 n = buflen > 25 ? buffer[25] : 0;
681 n = buflen > 21 ? buffer[21] : 0;
685 if (buflen < 26 + 4*n) {
687 "device %d videostreaming interface %d FRAME error\n",
689 alts->desc.bInterfaceNumber);
693 frame->bFrameIndex = buffer[3];
694 frame->bmCapabilities = buffer[4];
695 frame->wWidth = get_unaligned_le16(&buffer[5])
697 frame->wHeight = get_unaligned_le16(&buffer[7]);
698 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
699 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
700 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
701 frame->dwMaxVideoFrameBufferSize =
702 get_unaligned_le32(&buffer[17]);
703 frame->dwDefaultFrameInterval =
704 get_unaligned_le32(&buffer[21]);
705 frame->bFrameIntervalType = buffer[25];
707 frame->dwMaxVideoFrameBufferSize = 0;
708 frame->dwDefaultFrameInterval =
709 get_unaligned_le32(&buffer[17]);
710 frame->bFrameIntervalType = buffer[21];
712 frame->dwFrameInterval = *intervals;
715 * Several UVC chipsets screw up dwMaxVideoFrameBufferSize
716 * completely. Observed behaviours range from setting the
717 * value to 1.1x the actual frame size to hardwiring the
718 * 16 low bits to 0. This results in a higher than necessary
719 * memory usage as well as a wrong image size information. For
720 * uncompressed formats this can be fixed by computing the
721 * value from the frame size.
723 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
724 frame->dwMaxVideoFrameBufferSize = format->bpp
725 * frame->wWidth * frame->wHeight / 8;
728 * Some bogus devices report dwMinFrameInterval equal to
729 * dwMaxFrameInterval and have dwFrameIntervalStep set to
730 * zero. Setting all null intervals to 1 fixes the problem and
731 * some other divisions by zero that could happen.
733 for (i = 0; i < n; ++i) {
734 interval = get_unaligned_le32(&buffer[26+4*i]);
735 *(*intervals)++ = interval ? interval : 1;
739 * Make sure that the default frame interval stays between
742 n -= frame->bFrameIntervalType ? 1 : 2;
743 frame->dwDefaultFrameInterval =
744 min(frame->dwFrameInterval[n],
745 max(frame->dwFrameInterval[0],
746 frame->dwDefaultFrameInterval));
748 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
749 frame->bFrameIntervalType = 1;
750 frame->dwFrameInterval[0] =
751 frame->dwDefaultFrameInterval;
754 uvc_dbg(dev, DESCR, "- %ux%u (%u.%u fps)\n",
755 frame->wWidth, frame->wHeight,
756 10000000 / frame->dwDefaultFrameInterval,
757 (100000000 / frame->dwDefaultFrameInterval) % 10);
764 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
765 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
770 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
771 buffer[2] == UVC_VS_COLORFORMAT) {
774 "device %d videostreaming interface %d COLORFORMAT error\n",
776 alts->desc.bInterfaceNumber);
780 format->colorspace = uvc_colorspace(buffer[3]);
781 format->xfer_func = uvc_xfer_func(buffer[4]);
782 format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
787 format->colorspace = V4L2_COLORSPACE_SRGB;
790 return buffer - start;
793 static int uvc_parse_streaming(struct uvc_device *dev,
794 struct usb_interface *intf)
796 struct uvc_streaming *streaming = NULL;
797 struct uvc_format *format;
798 struct uvc_frame *frame;
799 struct usb_host_interface *alts = &intf->altsetting[0];
800 unsigned char *_buffer, *buffer = alts->extra;
801 int _buflen, buflen = alts->extralen;
802 unsigned int nformats = 0, nframes = 0, nintervals = 0;
803 unsigned int size, i, n, p;
808 if (intf->cur_altsetting->desc.bInterfaceSubClass
809 != UVC_SC_VIDEOSTREAMING) {
811 "device %d interface %d isn't a video streaming interface\n",
813 intf->altsetting[0].desc.bInterfaceNumber);
817 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
819 "device %d interface %d is already claimed\n",
821 intf->altsetting[0].desc.bInterfaceNumber);
825 streaming = uvc_stream_new(dev, intf);
826 if (streaming == NULL) {
827 usb_driver_release_interface(&uvc_driver.driver, intf);
832 * The Pico iMage webcam has its class-specific interface descriptors
833 * after the endpoint descriptors.
836 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
837 struct usb_host_endpoint *ep = &alts->endpoint[i];
839 if (ep->extralen == 0)
842 if (ep->extralen > 2 &&
843 ep->extra[1] == USB_DT_CS_INTERFACE) {
845 "trying extra data from endpoint %u\n",
847 buffer = alts->endpoint[i].extra;
848 buflen = alts->endpoint[i].extralen;
854 /* Skip the standard interface descriptors. */
855 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
862 "no class-specific streaming interface descriptors found\n");
866 /* Parse the header descriptor. */
868 case UVC_VS_OUTPUT_HEADER:
869 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
873 case UVC_VS_INPUT_HEADER:
874 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
880 "device %d videostreaming interface %d HEADER descriptor not found\n",
881 dev->udev->devnum, alts->desc.bInterfaceNumber);
885 p = buflen >= 4 ? buffer[3] : 0;
886 n = buflen >= size ? buffer[size-1] : 0;
888 if (buflen < size + p*n) {
890 "device %d videostreaming interface %d HEADER descriptor is invalid\n",
891 dev->udev->devnum, alts->desc.bInterfaceNumber);
895 streaming->header.bNumFormats = p;
896 streaming->header.bEndpointAddress = buffer[6];
897 if (buffer[2] == UVC_VS_INPUT_HEADER) {
898 streaming->header.bmInfo = buffer[7];
899 streaming->header.bTerminalLink = buffer[8];
900 streaming->header.bStillCaptureMethod = buffer[9];
901 streaming->header.bTriggerSupport = buffer[10];
902 streaming->header.bTriggerUsage = buffer[11];
904 streaming->header.bTerminalLink = buffer[7];
906 streaming->header.bControlSize = n;
908 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
910 if (streaming->header.bmaControls == NULL) {
921 /* Count the format and frame descriptors. */
922 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
923 switch (_buffer[2]) {
924 case UVC_VS_FORMAT_UNCOMPRESSED:
925 case UVC_VS_FORMAT_MJPEG:
926 case UVC_VS_FORMAT_FRAME_BASED:
930 case UVC_VS_FORMAT_DV:
932 * DV format has no frame descriptor. We will create a
933 * dummy frame descriptor with a dummy frame interval.
940 case UVC_VS_FORMAT_MPEG2TS:
941 case UVC_VS_FORMAT_STREAM_BASED:
943 "device %d videostreaming interface %d FORMAT %u is not supported\n",
945 alts->desc.bInterfaceNumber, _buffer[2]);
948 case UVC_VS_FRAME_UNCOMPRESSED:
949 case UVC_VS_FRAME_MJPEG:
952 nintervals += _buffer[25] ? _buffer[25] : 3;
955 case UVC_VS_FRAME_FRAME_BASED:
958 nintervals += _buffer[21] ? _buffer[21] : 3;
962 _buflen -= _buffer[0];
963 _buffer += _buffer[0];
968 "device %d videostreaming interface %d has no supported formats defined\n",
969 dev->udev->devnum, alts->desc.bInterfaceNumber);
973 size = nformats * sizeof(*format) + nframes * sizeof(*frame)
974 + nintervals * sizeof(*interval);
975 format = kzalloc(size, GFP_KERNEL);
976 if (format == NULL) {
981 frame = (struct uvc_frame *)&format[nformats];
982 interval = (u32 *)&frame[nframes];
984 streaming->format = format;
985 streaming->nformats = nformats;
987 /* Parse the format descriptors. */
988 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
990 case UVC_VS_FORMAT_UNCOMPRESSED:
991 case UVC_VS_FORMAT_MJPEG:
992 case UVC_VS_FORMAT_DV:
993 case UVC_VS_FORMAT_FRAME_BASED:
994 format->frame = frame;
995 ret = uvc_parse_format(dev, streaming, format,
996 &interval, buffer, buflen);
1000 frame += format->nframes;
1011 buflen -= buffer[0];
1012 buffer += buffer[0];
1017 "device %d videostreaming interface %d has %u bytes of trailing descriptor garbage\n",
1018 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
1020 /* Parse the alternate settings to find the maximum bandwidth. */
1021 for (i = 0; i < intf->num_altsetting; ++i) {
1022 struct usb_host_endpoint *ep;
1023 alts = &intf->altsetting[i];
1024 ep = uvc_find_endpoint(alts,
1025 streaming->header.bEndpointAddress);
1028 psize = uvc_endpoint_max_bpi(dev->udev, ep);
1029 if (psize > streaming->maxpsize)
1030 streaming->maxpsize = psize;
1033 list_add_tail(&streaming->list, &dev->streams);
1037 usb_driver_release_interface(&uvc_driver.driver, intf);
1038 uvc_stream_delete(streaming);
1042 static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA;
1043 static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER;
1044 static const u8 uvc_media_transport_input_guid[16] =
1045 UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT;
1046 static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING;
1048 static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,
1049 unsigned int num_pads, unsigned int extra_size)
1051 struct uvc_entity *entity;
1052 unsigned int num_inputs;
1056 extra_size = roundup(extra_size, sizeof(*entity->pads));
1058 num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
1061 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
1063 entity = kzalloc(size, GFP_KERNEL);
1068 entity->type = type;
1071 * Set the GUID for standard entity types. For extension units, the GUID
1072 * is initialized by the caller.
1075 case UVC_EXT_GPIO_UNIT:
1076 memcpy(entity->guid, uvc_gpio_guid, 16);
1078 case UVC_ITT_CAMERA:
1079 memcpy(entity->guid, uvc_camera_guid, 16);
1081 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1082 memcpy(entity->guid, uvc_media_transport_input_guid, 16);
1084 case UVC_VC_PROCESSING_UNIT:
1085 memcpy(entity->guid, uvc_processing_guid, 16);
1089 entity->num_links = 0;
1090 entity->num_pads = num_pads;
1091 entity->pads = ((void *)(entity + 1)) + extra_size;
1093 for (i = 0; i < num_inputs; ++i)
1094 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
1095 if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
1096 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
1098 entity->bNrInPins = num_inputs;
1099 entity->baSourceID = (u8 *)(&entity->pads[num_pads]);
1104 /* Parse vendor-specific extensions. */
1105 static int uvc_parse_vendor_control(struct uvc_device *dev,
1106 const unsigned char *buffer, int buflen)
1108 struct usb_device *udev = dev->udev;
1109 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1110 struct uvc_entity *unit;
1114 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
1115 case 0x046d: /* Logitech */
1116 if (buffer[1] != 0x41 || buffer[2] != 0x01)
1120 * Logitech implements several vendor specific functions
1121 * through vendor specific extension units (LXU).
1123 * The LXU descriptors are similar to XU descriptors
1124 * (see "USB Device Video Class for Video Devices", section
1125 * 3.7.2.6 "Extension Unit Descriptor") with the following
1128 * ----------------------------------------------------------
1129 * 0 bLength 1 Number
1130 * Size of this descriptor, in bytes: 24+p+n*2
1131 * ----------------------------------------------------------
1132 * 23+p+n bmControlsType N Bitmap
1133 * Individual bits in the set are defined:
1137 * This bitset is mapped exactly the same as bmControls.
1138 * ----------------------------------------------------------
1139 * 23+p+n*2 bReserved 1 Boolean
1140 * ----------------------------------------------------------
1141 * 24+p+n*2 iExtension 1 Index
1142 * Index of a string descriptor that describes this
1144 * ----------------------------------------------------------
1146 p = buflen >= 22 ? buffer[21] : 0;
1147 n = buflen >= 25 + p ? buffer[22+p] : 0;
1149 if (buflen < 25 + p + 2*n) {
1151 "device %d videocontrol interface %d EXTENSION_UNIT error\n",
1152 udev->devnum, alts->desc.bInterfaceNumber);
1156 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
1161 memcpy(unit->guid, &buffer[4], 16);
1162 unit->extension.bNumControls = buffer[20];
1163 memcpy(unit->baSourceID, &buffer[22], p);
1164 unit->extension.bControlSize = buffer[22+p];
1165 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1166 unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit)
1168 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
1170 if (buffer[24+p+2*n] != 0)
1171 usb_string(udev, buffer[24+p+2*n], unit->name,
1172 sizeof(unit->name));
1174 sprintf(unit->name, "Extension %u", buffer[3]);
1176 list_add_tail(&unit->list, &dev->entities);
1184 static int uvc_parse_standard_control(struct uvc_device *dev,
1185 const unsigned char *buffer, int buflen)
1187 struct usb_device *udev = dev->udev;
1188 struct uvc_entity *unit, *term;
1189 struct usb_interface *intf;
1190 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1191 unsigned int i, n, p, len;
1194 switch (buffer[2]) {
1196 n = buflen >= 12 ? buffer[11] : 0;
1198 if (buflen < 12 + n) {
1200 "device %d videocontrol interface %d HEADER error\n",
1201 udev->devnum, alts->desc.bInterfaceNumber);
1205 dev->uvc_version = get_unaligned_le16(&buffer[3]);
1206 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
1208 /* Parse all USB Video Streaming interfaces. */
1209 for (i = 0; i < n; ++i) {
1210 intf = usb_ifnum_to_if(udev, buffer[12+i]);
1213 "device %d interface %d doesn't exists\n",
1218 uvc_parse_streaming(dev, intf);
1222 case UVC_VC_INPUT_TERMINAL:
1225 "device %d videocontrol interface %d INPUT_TERMINAL error\n",
1226 udev->devnum, alts->desc.bInterfaceNumber);
1231 * Reject invalid terminal types that would cause issues:
1233 * - The high byte must be non-zero, otherwise it would be
1234 * confused with a unit.
1236 * - Bit 15 must be 0, as we use it internally as a terminal
1239 * Other unknown types are accepted.
1241 type = get_unaligned_le16(&buffer[4]);
1242 if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
1244 "device %d videocontrol interface %d INPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
1245 udev->devnum, alts->desc.bInterfaceNumber,
1254 if (type == UVC_ITT_CAMERA) {
1255 n = buflen >= 15 ? buffer[14] : 0;
1258 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1259 n = buflen >= 9 ? buffer[8] : 0;
1260 p = buflen >= 10 + n ? buffer[9+n] : 0;
1264 if (buflen < len + n + p) {
1266 "device %d videocontrol interface %d INPUT_TERMINAL error\n",
1267 udev->devnum, alts->desc.bInterfaceNumber);
1271 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1276 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1277 term->camera.bControlSize = n;
1278 term->camera.bmControls = (u8 *)term + sizeof(*term);
1279 term->camera.wObjectiveFocalLengthMin =
1280 get_unaligned_le16(&buffer[8]);
1281 term->camera.wObjectiveFocalLengthMax =
1282 get_unaligned_le16(&buffer[10]);
1283 term->camera.wOcularFocalLength =
1284 get_unaligned_le16(&buffer[12]);
1285 memcpy(term->camera.bmControls, &buffer[15], n);
1286 } else if (UVC_ENTITY_TYPE(term) ==
1287 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1288 term->media.bControlSize = n;
1289 term->media.bmControls = (u8 *)term + sizeof(*term);
1290 term->media.bTransportModeSize = p;
1291 term->media.bmTransportModes = (u8 *)term
1292 + sizeof(*term) + n;
1293 memcpy(term->media.bmControls, &buffer[9], n);
1294 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1298 usb_string(udev, buffer[7], term->name,
1299 sizeof(term->name));
1300 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1301 sprintf(term->name, "Camera %u", buffer[3]);
1302 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1303 sprintf(term->name, "Media %u", buffer[3]);
1305 sprintf(term->name, "Input %u", buffer[3]);
1307 list_add_tail(&term->list, &dev->entities);
1310 case UVC_VC_OUTPUT_TERMINAL:
1313 "device %d videocontrol interface %d OUTPUT_TERMINAL error\n",
1314 udev->devnum, alts->desc.bInterfaceNumber);
1319 * Make sure the terminal type MSB is not null, otherwise it
1320 * could be confused with a unit.
1322 type = get_unaligned_le16(&buffer[4]);
1323 if ((type & 0xff00) == 0) {
1325 "device %d videocontrol interface %d OUTPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
1326 udev->devnum, alts->desc.bInterfaceNumber,
1331 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1336 memcpy(term->baSourceID, &buffer[7], 1);
1339 usb_string(udev, buffer[8], term->name,
1340 sizeof(term->name));
1342 sprintf(term->name, "Output %u", buffer[3]);
1344 list_add_tail(&term->list, &dev->entities);
1347 case UVC_VC_SELECTOR_UNIT:
1348 p = buflen >= 5 ? buffer[4] : 0;
1350 if (buflen < 5 || buflen < 6 + p) {
1352 "device %d videocontrol interface %d SELECTOR_UNIT error\n",
1353 udev->devnum, alts->desc.bInterfaceNumber);
1357 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1361 memcpy(unit->baSourceID, &buffer[5], p);
1363 if (buffer[5+p] != 0)
1364 usb_string(udev, buffer[5+p], unit->name,
1365 sizeof(unit->name));
1367 sprintf(unit->name, "Selector %u", buffer[3]);
1369 list_add_tail(&unit->list, &dev->entities);
1372 case UVC_VC_PROCESSING_UNIT:
1373 n = buflen >= 8 ? buffer[7] : 0;
1374 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1376 if (buflen < p + n) {
1378 "device %d videocontrol interface %d PROCESSING_UNIT error\n",
1379 udev->devnum, alts->desc.bInterfaceNumber);
1383 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1387 memcpy(unit->baSourceID, &buffer[4], 1);
1388 unit->processing.wMaxMultiplier =
1389 get_unaligned_le16(&buffer[5]);
1390 unit->processing.bControlSize = buffer[7];
1391 unit->processing.bmControls = (u8 *)unit + sizeof(*unit);
1392 memcpy(unit->processing.bmControls, &buffer[8], n);
1393 if (dev->uvc_version >= 0x0110)
1394 unit->processing.bmVideoStandards = buffer[9+n];
1396 if (buffer[8+n] != 0)
1397 usb_string(udev, buffer[8+n], unit->name,
1398 sizeof(unit->name));
1400 sprintf(unit->name, "Processing %u", buffer[3]);
1402 list_add_tail(&unit->list, &dev->entities);
1405 case UVC_VC_EXTENSION_UNIT:
1406 p = buflen >= 22 ? buffer[21] : 0;
1407 n = buflen >= 24 + p ? buffer[22+p] : 0;
1409 if (buflen < 24 + p + n) {
1411 "device %d videocontrol interface %d EXTENSION_UNIT error\n",
1412 udev->devnum, alts->desc.bInterfaceNumber);
1416 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1420 memcpy(unit->guid, &buffer[4], 16);
1421 unit->extension.bNumControls = buffer[20];
1422 memcpy(unit->baSourceID, &buffer[22], p);
1423 unit->extension.bControlSize = buffer[22+p];
1424 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1425 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1427 if (buffer[23+p+n] != 0)
1428 usb_string(udev, buffer[23+p+n], unit->name,
1429 sizeof(unit->name));
1431 sprintf(unit->name, "Extension %u", buffer[3]);
1433 list_add_tail(&unit->list, &dev->entities);
1438 "Found an unknown CS_INTERFACE descriptor (%u)\n",
1446 static int uvc_parse_control(struct uvc_device *dev)
1448 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1449 unsigned char *buffer = alts->extra;
1450 int buflen = alts->extralen;
1454 * Parse the default alternate setting only, as the UVC specification
1455 * defines a single alternate setting, the default alternate setting
1459 while (buflen > 2) {
1460 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1461 buffer[1] != USB_DT_CS_INTERFACE)
1462 goto next_descriptor;
1464 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1468 buflen -= buffer[0];
1469 buffer += buffer[0];
1473 * Check if the optional status endpoint is present. Built-in iSight
1474 * webcams have an interrupt endpoint but spit proprietary data that
1475 * don't conform to the UVC status endpoint messages. Don't try to
1476 * handle the interrupt endpoint for those cameras.
1478 if (alts->desc.bNumEndpoints == 1 &&
1479 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1480 struct usb_host_endpoint *ep = &alts->endpoint[0];
1481 struct usb_endpoint_descriptor *desc = &ep->desc;
1483 if (usb_endpoint_is_int_in(desc) &&
1484 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1485 desc->bInterval != 0) {
1487 "Found a Status endpoint (addr %02x)\n",
1488 desc->bEndpointAddress);
1496 /* -----------------------------------------------------------------------------
1500 static void uvc_gpio_event(struct uvc_device *dev)
1502 struct uvc_entity *unit = dev->gpio_unit;
1503 struct uvc_video_chain *chain;
1509 new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy);
1511 /* GPIO entities are always on the first chain. */
1512 chain = list_first_entry(&dev->chains, struct uvc_video_chain, list);
1513 uvc_ctrl_status_event(chain, unit->controls, &new_val);
1516 static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
1517 u8 cs, void *data, u16 size)
1519 if (cs != UVC_CT_PRIVACY_CONTROL || size < 1)
1522 *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy);
1527 static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity,
1530 if (cs != UVC_CT_PRIVACY_CONTROL)
1533 *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE;
1537 static irqreturn_t uvc_gpio_irq(int irq, void *data)
1539 struct uvc_device *dev = data;
1541 uvc_gpio_event(dev);
1545 static int uvc_gpio_parse(struct uvc_device *dev)
1547 struct uvc_entity *unit;
1548 struct gpio_desc *gpio_privacy;
1551 gpio_privacy = devm_gpiod_get_optional(&dev->udev->dev, "privacy",
1553 if (IS_ERR_OR_NULL(gpio_privacy))
1554 return PTR_ERR_OR_ZERO(gpio_privacy);
1556 irq = gpiod_to_irq(gpio_privacy);
1558 if (irq != EPROBE_DEFER)
1559 dev_err(&dev->udev->dev,
1560 "No IRQ for privacy GPIO (%d)\n", irq);
1564 unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1);
1568 unit->gpio.gpio_privacy = gpio_privacy;
1569 unit->gpio.irq = irq;
1570 unit->gpio.bControlSize = 1;
1571 unit->gpio.bmControls = (u8 *)unit + sizeof(*unit);
1572 unit->gpio.bmControls[0] = 1;
1573 unit->get_cur = uvc_gpio_get_cur;
1574 unit->get_info = uvc_gpio_get_info;
1575 strscpy(unit->name, "GPIO", sizeof(unit->name));
1577 list_add_tail(&unit->list, &dev->entities);
1579 dev->gpio_unit = unit;
1584 static int uvc_gpio_init_irq(struct uvc_device *dev)
1586 struct uvc_entity *unit = dev->gpio_unit;
1588 if (!unit || unit->gpio.irq < 0)
1591 return devm_request_threaded_irq(&dev->udev->dev, unit->gpio.irq, NULL,
1593 IRQF_ONESHOT | IRQF_TRIGGER_FALLING |
1594 IRQF_TRIGGER_RISING,
1595 "uvc_privacy_gpio", dev);
1598 /* ------------------------------------------------------------------------
1603 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1604 * and containing the following units:
1606 * - one or more Output Terminals (USB Streaming or Display)
1607 * - zero or one Processing Unit
1608 * - zero, one or more single-input Selector Units
1609 * - zero or one multiple-input Selector Units, provided all inputs are
1610 * connected to input terminals
1611 * - zero, one or mode single-input Extension Units
1612 * - one or more Input Terminals (Camera, External or USB Streaming)
1614 * The terminal and units must match on of the following structures:
1616 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1617 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1618 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1620 * +---------+ +---------+ -> OTT_*(0)
1621 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1622 * +---------+ +---------+ -> OTT_*(n)
1624 * The Processing Unit and Extension Units can be in any order. Additional
1625 * Extension Units connected to the main chain as single-unit branches are
1626 * also supported. Single-input Selector Units are ignored.
1628 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1629 struct uvc_entity *entity)
1631 switch (UVC_ENTITY_TYPE(entity)) {
1632 case UVC_VC_EXTENSION_UNIT:
1633 uvc_dbg_cont(PROBE, " <- XU %d", entity->id);
1635 if (entity->bNrInPins != 1) {
1636 uvc_dbg(chain->dev, DESCR,
1637 "Extension unit %d has more than 1 input pin\n",
1644 case UVC_VC_PROCESSING_UNIT:
1645 uvc_dbg_cont(PROBE, " <- PU %d", entity->id);
1647 if (chain->processing != NULL) {
1648 uvc_dbg(chain->dev, DESCR,
1649 "Found multiple Processing Units in chain\n");
1653 chain->processing = entity;
1656 case UVC_VC_SELECTOR_UNIT:
1657 uvc_dbg_cont(PROBE, " <- SU %d", entity->id);
1659 /* Single-input selector units are ignored. */
1660 if (entity->bNrInPins == 1)
1663 if (chain->selector != NULL) {
1664 uvc_dbg(chain->dev, DESCR,
1665 "Found multiple Selector Units in chain\n");
1669 chain->selector = entity;
1672 case UVC_ITT_VENDOR_SPECIFIC:
1673 case UVC_ITT_CAMERA:
1674 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1675 uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
1679 case UVC_OTT_VENDOR_SPECIFIC:
1680 case UVC_OTT_DISPLAY:
1681 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1682 uvc_dbg_cont(PROBE, " OT %d", entity->id);
1686 case UVC_TT_STREAMING:
1687 if (UVC_ENTITY_IS_ITERM(entity))
1688 uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
1690 uvc_dbg_cont(PROBE, " OT %d", entity->id);
1695 uvc_dbg(chain->dev, DESCR,
1696 "Unsupported entity type 0x%04x found in chain\n",
1697 UVC_ENTITY_TYPE(entity));
1701 list_add_tail(&entity->chain, &chain->entities);
1705 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1706 struct uvc_entity *entity, struct uvc_entity *prev)
1708 struct uvc_entity *forward;
1716 forward = uvc_entity_by_reference(chain->dev, entity->id,
1718 if (forward == NULL)
1720 if (forward == prev)
1722 if (forward->chain.next || forward->chain.prev) {
1723 uvc_dbg(chain->dev, DESCR,
1724 "Found reference to entity %d already in chain\n",
1729 switch (UVC_ENTITY_TYPE(forward)) {
1730 case UVC_VC_EXTENSION_UNIT:
1731 if (forward->bNrInPins != 1) {
1732 uvc_dbg(chain->dev, DESCR,
1733 "Extension unit %d has more than 1 input pin\n",
1739 * Some devices reference an output terminal as the
1740 * source of extension units. This is incorrect, as
1741 * output terminals only have an input pin, and thus
1742 * can't be connected to any entity in the forward
1743 * direction. The resulting topology would cause issues
1744 * when registering the media controller graph. To
1745 * avoid this problem, connect the extension unit to
1746 * the source of the output terminal instead.
1748 if (UVC_ENTITY_IS_OTERM(entity)) {
1749 struct uvc_entity *source;
1751 source = uvc_entity_by_id(chain->dev,
1752 entity->baSourceID[0]);
1754 uvc_dbg(chain->dev, DESCR,
1755 "Can't connect extension unit %u in chain\n",
1760 forward->baSourceID[0] = source->id;
1763 list_add_tail(&forward->chain, &chain->entities);
1765 uvc_dbg_cont(PROBE, " (->");
1767 uvc_dbg_cont(PROBE, " XU %d", forward->id);
1771 case UVC_OTT_VENDOR_SPECIFIC:
1772 case UVC_OTT_DISPLAY:
1773 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1774 case UVC_TT_STREAMING:
1775 if (UVC_ENTITY_IS_ITERM(forward)) {
1776 uvc_dbg(chain->dev, DESCR,
1777 "Unsupported input terminal %u\n",
1782 if (UVC_ENTITY_IS_OTERM(entity)) {
1783 uvc_dbg(chain->dev, DESCR,
1784 "Unsupported connection between output terminals %u and %u\n",
1785 entity->id, forward->id);
1789 list_add_tail(&forward->chain, &chain->entities);
1791 uvc_dbg_cont(PROBE, " (->");
1793 uvc_dbg_cont(PROBE, " OT %d", forward->id);
1799 uvc_dbg_cont(PROBE, ")");
1804 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1805 struct uvc_entity **_entity)
1807 struct uvc_entity *entity = *_entity;
1808 struct uvc_entity *term;
1809 int id = -EINVAL, i;
1811 switch (UVC_ENTITY_TYPE(entity)) {
1812 case UVC_VC_EXTENSION_UNIT:
1813 case UVC_VC_PROCESSING_UNIT:
1814 id = entity->baSourceID[0];
1817 case UVC_VC_SELECTOR_UNIT:
1818 /* Single-input selector units are ignored. */
1819 if (entity->bNrInPins == 1) {
1820 id = entity->baSourceID[0];
1824 uvc_dbg_cont(PROBE, " <- IT");
1826 chain->selector = entity;
1827 for (i = 0; i < entity->bNrInPins; ++i) {
1828 id = entity->baSourceID[i];
1829 term = uvc_entity_by_id(chain->dev, id);
1830 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1831 uvc_dbg(chain->dev, DESCR,
1832 "Selector unit %d input %d isn't connected to an input terminal\n",
1837 if (term->chain.next || term->chain.prev) {
1838 uvc_dbg(chain->dev, DESCR,
1839 "Found reference to entity %d already in chain\n",
1844 uvc_dbg_cont(PROBE, " %d", term->id);
1846 list_add_tail(&term->chain, &chain->entities);
1847 uvc_scan_chain_forward(chain, term, entity);
1850 uvc_dbg_cont(PROBE, "\n");
1855 case UVC_ITT_VENDOR_SPECIFIC:
1856 case UVC_ITT_CAMERA:
1857 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1858 case UVC_OTT_VENDOR_SPECIFIC:
1859 case UVC_OTT_DISPLAY:
1860 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1861 case UVC_TT_STREAMING:
1862 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1871 entity = uvc_entity_by_id(chain->dev, id);
1872 if (entity == NULL) {
1873 uvc_dbg(chain->dev, DESCR,
1874 "Found reference to unknown entity %d\n", id);
1882 static int uvc_scan_chain(struct uvc_video_chain *chain,
1883 struct uvc_entity *term)
1885 struct uvc_entity *entity, *prev;
1887 uvc_dbg(chain->dev, PROBE, "Scanning UVC chain:");
1892 while (entity != NULL) {
1893 /* Entity must not be part of an existing chain */
1894 if (entity->chain.next || entity->chain.prev) {
1895 uvc_dbg(chain->dev, DESCR,
1896 "Found reference to entity %d already in chain\n",
1901 /* Process entity */
1902 if (uvc_scan_chain_entity(chain, entity) < 0)
1906 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1911 if (uvc_scan_chain_backward(chain, &entity) < 0)
1918 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1921 struct uvc_entity *term;
1922 unsigned int nterms = 0;
1925 list_for_each_entry(term, terms, chain) {
1926 if (!UVC_ENTITY_IS_TERM(term) ||
1927 UVC_TERM_DIRECTION(term) != dir)
1931 p += sprintf(p, ",");
1932 if (++nterms >= 4) {
1933 p += sprintf(p, "...");
1936 p += sprintf(p, "%u", term->id);
1942 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1944 static char buffer[43];
1947 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1948 p += sprintf(p, " -> ");
1949 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1954 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1956 struct uvc_video_chain *chain;
1958 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1962 INIT_LIST_HEAD(&chain->entities);
1963 mutex_init(&chain->ctrl_mutex);
1965 v4l2_prio_init(&chain->prio);
1971 * Fallback heuristic for devices that don't connect units and terminals in a
1974 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1975 * to fail, but if we just take the entities we can find and put them together
1976 * in the most sensible chain we can think of, turns out they do work anyway.
1977 * Note: This heuristic assumes there is a single chain.
1979 * At the time of writing, devices known to have such a broken chain are
1980 * - Acer Integrated Camera (5986:055a)
1981 * - Realtek rtl157a7 (0bda:57a7)
1983 static int uvc_scan_fallback(struct uvc_device *dev)
1985 struct uvc_video_chain *chain;
1986 struct uvc_entity *iterm = NULL;
1987 struct uvc_entity *oterm = NULL;
1988 struct uvc_entity *entity;
1989 struct uvc_entity *prev;
1992 * Start by locating the input and output terminals. We only support
1993 * devices with exactly one of each for now.
1995 list_for_each_entry(entity, &dev->entities, list) {
1996 if (UVC_ENTITY_IS_ITERM(entity)) {
2002 if (UVC_ENTITY_IS_OTERM(entity)) {
2009 if (iterm == NULL || oterm == NULL)
2012 /* Allocate the chain and fill it. */
2013 chain = uvc_alloc_chain(dev);
2017 if (uvc_scan_chain_entity(chain, oterm) < 0)
2023 * Add all Processing and Extension Units with two pads. The order
2024 * doesn't matter much, use reverse list traversal to connect units in
2025 * UVC descriptor order as we build the chain from output to input. This
2026 * leads to units appearing in the order meant by the manufacturer for
2027 * the cameras known to require this heuristic.
2029 list_for_each_entry_reverse(entity, &dev->entities, list) {
2030 if (entity->type != UVC_VC_PROCESSING_UNIT &&
2031 entity->type != UVC_VC_EXTENSION_UNIT)
2034 if (entity->num_pads != 2)
2037 if (uvc_scan_chain_entity(chain, entity) < 0)
2040 prev->baSourceID[0] = entity->id;
2044 if (uvc_scan_chain_entity(chain, iterm) < 0)
2047 prev->baSourceID[0] = iterm->id;
2049 list_add_tail(&chain->list, &dev->chains);
2051 uvc_dbg(dev, PROBE, "Found a video chain by fallback heuristic (%s)\n",
2052 uvc_print_chain(chain));
2062 * Scan the device for video chains and register video devices.
2064 * Chains are scanned starting at their output terminals and walked backwards.
2066 static int uvc_scan_device(struct uvc_device *dev)
2068 struct uvc_video_chain *chain;
2069 struct uvc_entity *term;
2071 list_for_each_entry(term, &dev->entities, list) {
2072 if (!UVC_ENTITY_IS_OTERM(term))
2076 * If the terminal is already included in a chain, skip it.
2077 * This can happen for chains that have multiple output
2078 * terminals, where all output terminals beside the first one
2079 * will be inserted in the chain in forward scans.
2081 if (term->chain.next || term->chain.prev)
2084 chain = uvc_alloc_chain(dev);
2088 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
2090 if (uvc_scan_chain(chain, term) < 0) {
2095 uvc_dbg(dev, PROBE, "Found a valid video chain (%s)\n",
2096 uvc_print_chain(chain));
2098 list_add_tail(&chain->list, &dev->chains);
2101 if (list_empty(&dev->chains))
2102 uvc_scan_fallback(dev);
2104 if (list_empty(&dev->chains)) {
2105 dev_info(&dev->udev->dev, "No valid video chain found.\n");
2109 /* Add GPIO entity to the first chain. */
2110 if (dev->gpio_unit) {
2111 chain = list_first_entry(&dev->chains,
2112 struct uvc_video_chain, list);
2113 list_add_tail(&dev->gpio_unit->chain, &chain->entities);
2119 /* ------------------------------------------------------------------------
2120 * Video device registration and unregistration
2124 * Delete the UVC device.
2126 * Called by the kernel when the last reference to the uvc_device structure
2129 * As this function is called after or during disconnect(), all URBs have
2130 * already been cancelled by the USB core. There is no need to kill the
2131 * interrupt URB manually.
2133 static void uvc_delete(struct kref *kref)
2135 struct uvc_device *dev = container_of(kref, struct uvc_device, ref);
2136 struct list_head *p, *n;
2138 uvc_status_cleanup(dev);
2139 uvc_ctrl_cleanup_device(dev);
2141 usb_put_intf(dev->intf);
2142 usb_put_dev(dev->udev);
2144 #ifdef CONFIG_MEDIA_CONTROLLER
2145 media_device_cleanup(&dev->mdev);
2148 list_for_each_safe(p, n, &dev->chains) {
2149 struct uvc_video_chain *chain;
2150 chain = list_entry(p, struct uvc_video_chain, list);
2154 list_for_each_safe(p, n, &dev->entities) {
2155 struct uvc_entity *entity;
2156 entity = list_entry(p, struct uvc_entity, list);
2157 #ifdef CONFIG_MEDIA_CONTROLLER
2158 uvc_mc_cleanup_entity(entity);
2163 list_for_each_safe(p, n, &dev->streams) {
2164 struct uvc_streaming *streaming;
2165 streaming = list_entry(p, struct uvc_streaming, list);
2166 usb_driver_release_interface(&uvc_driver.driver,
2168 uvc_stream_delete(streaming);
2174 static void uvc_release(struct video_device *vdev)
2176 struct uvc_streaming *stream = video_get_drvdata(vdev);
2177 struct uvc_device *dev = stream->dev;
2179 kref_put(&dev->ref, uvc_delete);
2183 * Unregister the video devices.
2185 static void uvc_unregister_video(struct uvc_device *dev)
2187 struct uvc_streaming *stream;
2189 list_for_each_entry(stream, &dev->streams, list) {
2190 if (!video_is_registered(&stream->vdev))
2193 video_unregister_device(&stream->vdev);
2194 video_unregister_device(&stream->meta.vdev);
2196 uvc_debugfs_cleanup_stream(stream);
2199 uvc_status_unregister(dev);
2202 v4l2_device_unregister(&dev->vdev);
2203 #ifdef CONFIG_MEDIA_CONTROLLER
2204 if (media_devnode_is_registered(dev->mdev.devnode))
2205 media_device_unregister(&dev->mdev);
2209 int uvc_register_video_device(struct uvc_device *dev,
2210 struct uvc_streaming *stream,
2211 struct video_device *vdev,
2212 struct uvc_video_queue *queue,
2213 enum v4l2_buf_type type,
2214 const struct v4l2_file_operations *fops,
2215 const struct v4l2_ioctl_ops *ioctl_ops)
2219 /* Initialize the video buffers queue. */
2220 ret = uvc_queue_init(queue, type, !uvc_no_drop_param);
2224 /* Register the device with V4L. */
2227 * We already hold a reference to dev->udev. The video device will be
2228 * unregistered before the reference is released, so we don't need to
2231 vdev->v4l2_dev = &dev->vdev;
2233 vdev->ioctl_ops = ioctl_ops;
2234 vdev->release = uvc_release;
2235 vdev->prio = &stream->chain->prio;
2236 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
2237 vdev->vfl_dir = VFL_DIR_TX;
2239 vdev->vfl_dir = VFL_DIR_RX;
2242 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2244 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
2246 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2247 vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
2249 case V4L2_BUF_TYPE_META_CAPTURE:
2250 vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING;
2254 strscpy(vdev->name, dev->name, sizeof(vdev->name));
2257 * Set the driver data before calling video_register_device, otherwise
2258 * the file open() handler might race us.
2260 video_set_drvdata(vdev, stream);
2262 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
2264 dev_err(&stream->intf->dev,
2265 "Failed to register %s device (%d).\n",
2266 v4l2_type_names[type], ret);
2270 kref_get(&dev->ref);
2274 static int uvc_register_video(struct uvc_device *dev,
2275 struct uvc_streaming *stream)
2279 /* Initialize the streaming interface with default parameters. */
2280 ret = uvc_video_init(stream);
2282 dev_err(&stream->intf->dev,
2283 "Failed to initialize the device (%d).\n", ret);
2287 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2288 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE
2289 | V4L2_CAP_META_CAPTURE;
2291 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
2293 uvc_debugfs_init_stream(stream);
2295 /* Register the device with V4L. */
2296 return uvc_register_video_device(dev, stream, &stream->vdev,
2297 &stream->queue, stream->type,
2298 &uvc_fops, &uvc_ioctl_ops);
2302 * Register all video devices in all chains.
2304 static int uvc_register_terms(struct uvc_device *dev,
2305 struct uvc_video_chain *chain)
2307 struct uvc_streaming *stream;
2308 struct uvc_entity *term;
2311 list_for_each_entry(term, &chain->entities, chain) {
2312 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
2315 stream = uvc_stream_by_id(dev, term->id);
2316 if (stream == NULL) {
2317 dev_info(&dev->udev->dev,
2318 "No streaming interface found for terminal %u.",
2323 stream->chain = chain;
2324 ret = uvc_register_video(dev, stream);
2329 * Register a metadata node, but ignore a possible failure,
2330 * complete registration of video nodes anyway.
2332 uvc_meta_register(stream);
2334 term->vdev = &stream->vdev;
2340 static int uvc_register_chains(struct uvc_device *dev)
2342 struct uvc_video_chain *chain;
2345 list_for_each_entry(chain, &dev->chains, list) {
2346 ret = uvc_register_terms(dev, chain);
2350 #ifdef CONFIG_MEDIA_CONTROLLER
2351 ret = uvc_mc_register_entities(chain);
2353 dev_info(&dev->udev->dev,
2354 "Failed to register entities (%d).\n", ret);
2361 /* ------------------------------------------------------------------------
2362 * USB probe, disconnect, suspend and resume
2365 static const struct uvc_device_info uvc_quirk_none = { 0 };
2367 static int uvc_probe(struct usb_interface *intf,
2368 const struct usb_device_id *id)
2370 struct usb_device *udev = interface_to_usbdev(intf);
2371 struct uvc_device *dev;
2372 const struct uvc_device_info *info =
2373 (const struct uvc_device_info *)id->driver_info;
2377 /* Allocate memory for the device and initialize it. */
2378 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2382 INIT_LIST_HEAD(&dev->entities);
2383 INIT_LIST_HEAD(&dev->chains);
2384 INIT_LIST_HEAD(&dev->streams);
2385 kref_init(&dev->ref);
2386 atomic_set(&dev->nmappings, 0);
2387 mutex_init(&dev->lock);
2389 dev->udev = usb_get_dev(udev);
2390 dev->intf = usb_get_intf(intf);
2391 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2392 dev->info = info ? info : &uvc_quirk_none;
2393 dev->quirks = uvc_quirks_param == -1
2394 ? dev->info->quirks : uvc_quirks_param;
2396 if (id->idVendor && id->idProduct)
2397 uvc_dbg(dev, PROBE, "Probing known UVC device %s (%04x:%04x)\n",
2398 udev->devpath, id->idVendor, id->idProduct);
2400 uvc_dbg(dev, PROBE, "Probing generic UVC device %s\n",
2403 if (udev->product != NULL)
2404 strscpy(dev->name, udev->product, sizeof(dev->name));
2406 snprintf(dev->name, sizeof(dev->name),
2407 "UVC Camera (%04x:%04x)",
2408 le16_to_cpu(udev->descriptor.idVendor),
2409 le16_to_cpu(udev->descriptor.idProduct));
2412 * Add iFunction or iInterface to names when available as additional
2413 * distinguishers between interfaces. iFunction is prioritized over
2414 * iInterface which matches Windows behavior at the point of writing.
2416 if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
2417 function = intf->intf_assoc->iFunction;
2419 function = intf->cur_altsetting->desc.iInterface;
2420 if (function != 0) {
2423 strlcat(dev->name, ": ", sizeof(dev->name));
2424 len = strlen(dev->name);
2425 usb_string(udev, function, dev->name + len,
2426 sizeof(dev->name) - len);
2429 /* Initialize the media device. */
2430 #ifdef CONFIG_MEDIA_CONTROLLER
2431 dev->mdev.dev = &intf->dev;
2432 strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2434 strscpy(dev->mdev.serial, udev->serial,
2435 sizeof(dev->mdev.serial));
2436 usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2437 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2438 media_device_init(&dev->mdev);
2440 dev->vdev.mdev = &dev->mdev;
2443 /* Parse the Video Class control descriptor. */
2444 if (uvc_parse_control(dev) < 0) {
2445 uvc_dbg(dev, PROBE, "Unable to parse UVC descriptors\n");
2449 /* Parse the associated GPIOs. */
2450 if (uvc_gpio_parse(dev) < 0) {
2451 uvc_dbg(dev, PROBE, "Unable to parse UVC GPIOs\n");
2455 dev_info(&dev->udev->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2456 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2457 udev->product ? udev->product : "<unnamed>",
2458 le16_to_cpu(udev->descriptor.idVendor),
2459 le16_to_cpu(udev->descriptor.idProduct));
2461 if (dev->quirks != dev->info->quirks) {
2462 dev_info(&dev->udev->dev,
2463 "Forcing device quirks to 0x%x by module parameter for testing purpose.\n",
2465 dev_info(&dev->udev->dev,
2466 "Please report required quirks to the linux-media mailing list.\n");
2469 if (dev->info->uvc_version) {
2470 dev->uvc_version = dev->info->uvc_version;
2471 dev_info(&dev->udev->dev, "Forcing UVC version to %u.%02x\n",
2472 dev->uvc_version >> 8, dev->uvc_version & 0xff);
2475 /* Register the V4L2 device. */
2476 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2479 /* Scan the device for video chains. */
2480 if (uvc_scan_device(dev) < 0)
2483 /* Initialize controls. */
2484 if (uvc_ctrl_init_device(dev) < 0)
2487 /* Register video device nodes. */
2488 if (uvc_register_chains(dev) < 0)
2491 #ifdef CONFIG_MEDIA_CONTROLLER
2492 /* Register the media device node */
2493 if (media_device_register(&dev->mdev) < 0)
2496 /* Save our data pointer in the interface data. */
2497 usb_set_intfdata(intf, dev);
2499 /* Initialize the interrupt URB. */
2500 if ((ret = uvc_status_init(dev)) < 0) {
2501 dev_info(&dev->udev->dev,
2502 "Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n",
2506 ret = uvc_gpio_init_irq(dev);
2508 dev_err(&dev->udev->dev,
2509 "Unable to request privacy GPIO IRQ (%d)\n", ret);
2513 uvc_dbg(dev, PROBE, "UVC device initialized\n");
2514 usb_enable_autosuspend(udev);
2518 uvc_unregister_video(dev);
2519 kref_put(&dev->ref, uvc_delete);
2523 static void uvc_disconnect(struct usb_interface *intf)
2525 struct uvc_device *dev = usb_get_intfdata(intf);
2528 * Set the USB interface data to NULL. This can be done outside the
2529 * lock, as there's no other reader.
2531 usb_set_intfdata(intf, NULL);
2533 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2534 UVC_SC_VIDEOSTREAMING)
2537 uvc_unregister_video(dev);
2538 kref_put(&dev->ref, uvc_delete);
2541 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2543 struct uvc_device *dev = usb_get_intfdata(intf);
2544 struct uvc_streaming *stream;
2546 uvc_dbg(dev, SUSPEND, "Suspending interface %u\n",
2547 intf->cur_altsetting->desc.bInterfaceNumber);
2549 /* Controls are cached on the fly so they don't need to be saved. */
2550 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2551 UVC_SC_VIDEOCONTROL) {
2552 mutex_lock(&dev->lock);
2554 uvc_status_stop(dev);
2555 mutex_unlock(&dev->lock);
2559 list_for_each_entry(stream, &dev->streams, list) {
2560 if (stream->intf == intf)
2561 return uvc_video_suspend(stream);
2564 uvc_dbg(dev, SUSPEND,
2565 "Suspend: video streaming USB interface mismatch\n");
2569 static int __uvc_resume(struct usb_interface *intf, int reset)
2571 struct uvc_device *dev = usb_get_intfdata(intf);
2572 struct uvc_streaming *stream;
2575 uvc_dbg(dev, SUSPEND, "Resuming interface %u\n",
2576 intf->cur_altsetting->desc.bInterfaceNumber);
2578 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2579 UVC_SC_VIDEOCONTROL) {
2581 ret = uvc_ctrl_restore_values(dev);
2586 mutex_lock(&dev->lock);
2588 ret = uvc_status_start(dev, GFP_NOIO);
2589 mutex_unlock(&dev->lock);
2594 list_for_each_entry(stream, &dev->streams, list) {
2595 if (stream->intf == intf) {
2596 ret = uvc_video_resume(stream, reset);
2598 uvc_queue_streamoff(&stream->queue,
2599 stream->queue.queue.type);
2604 uvc_dbg(dev, SUSPEND,
2605 "Resume: video streaming USB interface mismatch\n");
2609 static int uvc_resume(struct usb_interface *intf)
2611 return __uvc_resume(intf, 0);
2614 static int uvc_reset_resume(struct usb_interface *intf)
2616 return __uvc_resume(intf, 1);
2619 /* ------------------------------------------------------------------------
2623 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2625 if (uvc_clock_param == CLOCK_MONOTONIC)
2626 return sprintf(buffer, "CLOCK_MONOTONIC");
2628 return sprintf(buffer, "CLOCK_REALTIME");
2631 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2633 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2634 val += strlen("clock_");
2636 if (strcasecmp(val, "monotonic") == 0)
2637 uvc_clock_param = CLOCK_MONOTONIC;
2638 else if (strcasecmp(val, "realtime") == 0)
2639 uvc_clock_param = CLOCK_REALTIME;
2646 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2647 &uvc_clock_param, S_IRUGO|S_IWUSR);
2648 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2649 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2650 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2651 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2652 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2653 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2654 MODULE_PARM_DESC(quirks, "Forced device quirks");
2655 module_param_named(trace, uvc_dbg_param, uint, S_IRUGO|S_IWUSR);
2656 MODULE_PARM_DESC(trace, "Trace level bitmask");
2657 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2658 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2660 /* ------------------------------------------------------------------------
2661 * Driver initialization and cleanup
2664 static const struct uvc_menu_info power_line_frequency_controls_limited[] = {
2669 static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = {
2670 .id = V4L2_CID_POWER_LINE_FREQUENCY,
2671 .entity = UVC_GUID_UVC_PROCESSING,
2672 .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
2675 .v4l2_type = V4L2_CTRL_TYPE_MENU,
2676 .data_type = UVC_CTRL_DATA_TYPE_ENUM,
2677 .menu_info = power_line_frequency_controls_limited,
2678 .menu_count = ARRAY_SIZE(power_line_frequency_controls_limited),
2681 static const struct uvc_device_info uvc_ctrl_power_line_limited = {
2682 .mappings = (const struct uvc_control_mapping *[]) {
2683 &uvc_ctrl_power_line_mapping_limited,
2684 NULL, /* Sentinel */
2688 static const struct uvc_device_info uvc_quirk_probe_minmax = {
2689 .quirks = UVC_QUIRK_PROBE_MINMAX,
2692 static const struct uvc_device_info uvc_quirk_fix_bandwidth = {
2693 .quirks = UVC_QUIRK_FIX_BANDWIDTH,
2696 static const struct uvc_device_info uvc_quirk_probe_def = {
2697 .quirks = UVC_QUIRK_PROBE_DEF,
2700 static const struct uvc_device_info uvc_quirk_stream_no_fid = {
2701 .quirks = UVC_QUIRK_STREAM_NO_FID,
2704 static const struct uvc_device_info uvc_quirk_force_y8 = {
2705 .quirks = UVC_QUIRK_FORCE_Y8,
2708 #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q}
2709 #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \
2713 * The Logitech cameras listed below have their interface class set to
2714 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2715 * though they are compliant.
2717 static const struct usb_device_id uvc_ids[] = {
2718 /* Quanta USB2.0 HD UVC Webcam */
2719 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2720 | USB_DEVICE_ID_MATCH_INT_INFO,
2722 .idProduct = 0x3090,
2723 .bInterfaceClass = USB_CLASS_VIDEO,
2724 .bInterfaceSubClass = 1,
2725 .bInterfaceProtocol = 0,
2726 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2727 /* Quanta USB2.0 HD UVC Webcam */
2728 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2729 | USB_DEVICE_ID_MATCH_INT_INFO,
2731 .idProduct = 0x4030,
2732 .bInterfaceClass = USB_CLASS_VIDEO,
2733 .bInterfaceSubClass = 1,
2734 .bInterfaceProtocol = 0,
2735 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2736 /* Quanta USB2.0 HD UVC Webcam */
2737 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2738 | USB_DEVICE_ID_MATCH_INT_INFO,
2740 .idProduct = 0x4034,
2741 .bInterfaceClass = USB_CLASS_VIDEO,
2742 .bInterfaceSubClass = 1,
2743 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2744 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2745 /* LogiLink Wireless Webcam */
2746 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2747 | USB_DEVICE_ID_MATCH_INT_INFO,
2749 .idProduct = 0xa91a,
2750 .bInterfaceClass = USB_CLASS_VIDEO,
2751 .bInterfaceSubClass = 1,
2752 .bInterfaceProtocol = 0,
2753 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2754 /* Genius eFace 2025 */
2755 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2756 | USB_DEVICE_ID_MATCH_INT_INFO,
2758 .idProduct = 0x706e,
2759 .bInterfaceClass = USB_CLASS_VIDEO,
2760 .bInterfaceSubClass = 1,
2761 .bInterfaceProtocol = 0,
2762 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2763 /* Microsoft Lifecam NX-6000 */
2764 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2765 | USB_DEVICE_ID_MATCH_INT_INFO,
2767 .idProduct = 0x00f8,
2768 .bInterfaceClass = USB_CLASS_VIDEO,
2769 .bInterfaceSubClass = 1,
2770 .bInterfaceProtocol = 0,
2771 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2772 /* Microsoft Lifecam NX-3000 */
2773 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2774 | USB_DEVICE_ID_MATCH_INT_INFO,
2776 .idProduct = 0x0721,
2777 .bInterfaceClass = USB_CLASS_VIDEO,
2778 .bInterfaceSubClass = 1,
2779 .bInterfaceProtocol = 0,
2780 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2781 /* Microsoft Lifecam VX-7000 */
2782 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2783 | USB_DEVICE_ID_MATCH_INT_INFO,
2785 .idProduct = 0x0723,
2786 .bInterfaceClass = USB_CLASS_VIDEO,
2787 .bInterfaceSubClass = 1,
2788 .bInterfaceProtocol = 0,
2789 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2790 /* Logitech Quickcam Fusion */
2791 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2792 | USB_DEVICE_ID_MATCH_INT_INFO,
2794 .idProduct = 0x08c1,
2795 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2796 .bInterfaceSubClass = 1,
2797 .bInterfaceProtocol = 0 },
2798 /* Logitech Quickcam Orbit MP */
2799 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2800 | USB_DEVICE_ID_MATCH_INT_INFO,
2802 .idProduct = 0x08c2,
2803 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2804 .bInterfaceSubClass = 1,
2805 .bInterfaceProtocol = 0 },
2806 /* Logitech Quickcam Pro for Notebook */
2807 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2808 | USB_DEVICE_ID_MATCH_INT_INFO,
2810 .idProduct = 0x08c3,
2811 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2812 .bInterfaceSubClass = 1,
2813 .bInterfaceProtocol = 0 },
2814 /* Logitech Quickcam Pro 5000 */
2815 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2816 | USB_DEVICE_ID_MATCH_INT_INFO,
2818 .idProduct = 0x08c5,
2819 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2820 .bInterfaceSubClass = 1,
2821 .bInterfaceProtocol = 0 },
2822 /* Logitech Quickcam OEM Dell Notebook */
2823 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2824 | USB_DEVICE_ID_MATCH_INT_INFO,
2826 .idProduct = 0x08c6,
2827 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2828 .bInterfaceSubClass = 1,
2829 .bInterfaceProtocol = 0 },
2830 /* Logitech Quickcam OEM Cisco VT Camera II */
2831 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2832 | USB_DEVICE_ID_MATCH_INT_INFO,
2834 .idProduct = 0x08c7,
2835 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2836 .bInterfaceSubClass = 1,
2837 .bInterfaceProtocol = 0 },
2838 /* Logitech HD Pro Webcam C920 */
2839 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2840 | USB_DEVICE_ID_MATCH_INT_INFO,
2842 .idProduct = 0x082d,
2843 .bInterfaceClass = USB_CLASS_VIDEO,
2844 .bInterfaceSubClass = 1,
2845 .bInterfaceProtocol = 0,
2846 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT) },
2847 /* Chicony CNF7129 (Asus EEE 100HE) */
2848 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2849 | USB_DEVICE_ID_MATCH_INT_INFO,
2851 .idProduct = 0xb071,
2852 .bInterfaceClass = USB_CLASS_VIDEO,
2853 .bInterfaceSubClass = 1,
2854 .bInterfaceProtocol = 0,
2855 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },
2856 /* Chicony EasyCamera */
2857 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2858 | USB_DEVICE_ID_MATCH_INT_INFO,
2860 .idProduct = 0xb5eb,
2861 .bInterfaceClass = USB_CLASS_VIDEO,
2862 .bInterfaceSubClass = 1,
2863 .bInterfaceProtocol = 0,
2864 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2865 /* Chicony EasyCamera */
2866 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2867 | USB_DEVICE_ID_MATCH_INT_INFO,
2869 .idProduct = 0xb6ba,
2870 .bInterfaceClass = USB_CLASS_VIDEO,
2871 .bInterfaceSubClass = 1,
2872 .bInterfaceProtocol = 0,
2873 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2874 /* Chicony EasyCamera */
2875 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2876 | USB_DEVICE_ID_MATCH_INT_INFO,
2878 .idProduct = 0xb746,
2879 .bInterfaceClass = USB_CLASS_VIDEO,
2880 .bInterfaceSubClass = 1,
2881 .bInterfaceProtocol = 0,
2882 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2883 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2884 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2885 | USB_DEVICE_ID_MATCH_INT_INFO,
2887 .idProduct = 0x3820,
2888 .bInterfaceClass = USB_CLASS_VIDEO,
2889 .bInterfaceSubClass = 1,
2890 .bInterfaceProtocol = 0,
2891 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2892 /* Dell XPS m1530 */
2893 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2894 | USB_DEVICE_ID_MATCH_INT_INFO,
2896 .idProduct = 0x2640,
2897 .bInterfaceClass = USB_CLASS_VIDEO,
2898 .bInterfaceSubClass = 1,
2899 .bInterfaceProtocol = 0,
2900 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2901 /* Dell SP2008WFP Monitor */
2902 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2903 | USB_DEVICE_ID_MATCH_INT_INFO,
2905 .idProduct = 0x2641,
2906 .bInterfaceClass = USB_CLASS_VIDEO,
2907 .bInterfaceSubClass = 1,
2908 .bInterfaceProtocol = 0,
2909 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2910 /* Dell Alienware X51 */
2911 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2912 | USB_DEVICE_ID_MATCH_INT_INFO,
2914 .idProduct = 0x2643,
2915 .bInterfaceClass = USB_CLASS_VIDEO,
2916 .bInterfaceSubClass = 1,
2917 .bInterfaceProtocol = 0,
2918 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2919 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2920 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2921 | USB_DEVICE_ID_MATCH_INT_INFO,
2923 .idProduct = 0x264a,
2924 .bInterfaceClass = USB_CLASS_VIDEO,
2925 .bInterfaceSubClass = 1,
2926 .bInterfaceProtocol = 0,
2927 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2928 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2929 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2930 | USB_DEVICE_ID_MATCH_INT_INFO,
2932 .idProduct = 0x7670,
2933 .bInterfaceClass = USB_CLASS_VIDEO,
2934 .bInterfaceSubClass = 1,
2935 .bInterfaceProtocol = 0,
2936 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2937 /* Apple Built-In iSight */
2938 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2939 | USB_DEVICE_ID_MATCH_INT_INFO,
2941 .idProduct = 0x8501,
2942 .bInterfaceClass = USB_CLASS_VIDEO,
2943 .bInterfaceSubClass = 1,
2944 .bInterfaceProtocol = 0,
2945 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2946 | UVC_QUIRK_BUILTIN_ISIGHT) },
2947 /* Apple FaceTime HD Camera (Built-In) */
2948 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2949 | USB_DEVICE_ID_MATCH_INT_INFO,
2951 .idProduct = 0x8514,
2952 .bInterfaceClass = USB_CLASS_VIDEO,
2953 .bInterfaceSubClass = 1,
2954 .bInterfaceProtocol = 0,
2955 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2956 /* Apple Built-In iSight via iBridge */
2957 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2958 | USB_DEVICE_ID_MATCH_INT_INFO,
2960 .idProduct = 0x8600,
2961 .bInterfaceClass = USB_CLASS_VIDEO,
2962 .bInterfaceSubClass = 1,
2963 .bInterfaceProtocol = 0,
2964 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2965 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2966 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2967 | USB_DEVICE_ID_MATCH_INT_INFO,
2969 .idProduct = 0x0403,
2970 .bInterfaceClass = USB_CLASS_VIDEO,
2971 .bInterfaceSubClass = 1,
2972 .bInterfaceProtocol = 0,
2973 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2974 /* Genesys Logic USB 2.0 PC Camera */
2975 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2976 | USB_DEVICE_ID_MATCH_INT_INFO,
2978 .idProduct = 0x0505,
2979 .bInterfaceClass = USB_CLASS_VIDEO,
2980 .bInterfaceSubClass = 1,
2981 .bInterfaceProtocol = 0,
2982 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2983 /* Hercules Classic Silver */
2984 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2985 | USB_DEVICE_ID_MATCH_INT_INFO,
2987 .idProduct = 0x300c,
2988 .bInterfaceClass = USB_CLASS_VIDEO,
2989 .bInterfaceSubClass = 1,
2990 .bInterfaceProtocol = 0,
2991 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2993 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2994 | USB_DEVICE_ID_MATCH_INT_INFO,
2996 .idProduct = 0x332d,
2997 .bInterfaceClass = USB_CLASS_VIDEO,
2998 .bInterfaceSubClass = 1,
2999 .bInterfaceProtocol = 0,
3000 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
3001 /* ViMicro - Minoru3D */
3002 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3003 | USB_DEVICE_ID_MATCH_INT_INFO,
3005 .idProduct = 0x3410,
3006 .bInterfaceClass = USB_CLASS_VIDEO,
3007 .bInterfaceSubClass = 1,
3008 .bInterfaceProtocol = 0,
3009 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
3010 /* ViMicro Venus - Minoru3D */
3011 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3012 | USB_DEVICE_ID_MATCH_INT_INFO,
3014 .idProduct = 0x3420,
3015 .bInterfaceClass = USB_CLASS_VIDEO,
3016 .bInterfaceSubClass = 1,
3017 .bInterfaceProtocol = 0,
3018 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
3019 /* Ophir Optronics - SPCAM 620U */
3020 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3021 | USB_DEVICE_ID_MATCH_INT_INFO,
3023 .idProduct = 0x0555,
3024 .bInterfaceClass = USB_CLASS_VIDEO,
3025 .bInterfaceSubClass = 1,
3026 .bInterfaceProtocol = 0,
3027 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3029 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3030 | USB_DEVICE_ID_MATCH_INT_INFO,
3032 .idProduct = 0x0004,
3033 .bInterfaceClass = USB_CLASS_VIDEO,
3034 .bInterfaceSubClass = 1,
3035 .bInterfaceProtocol = 0,
3036 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
3037 | UVC_QUIRK_PROBE_DEF) },
3038 /* IMC Networks (Medion Akoya) */
3039 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3040 | USB_DEVICE_ID_MATCH_INT_INFO,
3042 .idProduct = 0x5103,
3043 .bInterfaceClass = USB_CLASS_VIDEO,
3044 .bInterfaceSubClass = 1,
3045 .bInterfaceProtocol = 0,
3046 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3047 /* JMicron USB2.0 XGA WebCam */
3048 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3049 | USB_DEVICE_ID_MATCH_INT_INFO,
3051 .idProduct = 0x0310,
3052 .bInterfaceClass = USB_CLASS_VIDEO,
3053 .bInterfaceSubClass = 1,
3054 .bInterfaceProtocol = 0,
3055 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3056 /* Syntek (HP Spartan) */
3057 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3058 | USB_DEVICE_ID_MATCH_INT_INFO,
3060 .idProduct = 0x5212,
3061 .bInterfaceClass = USB_CLASS_VIDEO,
3062 .bInterfaceSubClass = 1,
3063 .bInterfaceProtocol = 0,
3064 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3065 /* Syntek (Samsung Q310) */
3066 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3067 | USB_DEVICE_ID_MATCH_INT_INFO,
3069 .idProduct = 0x5931,
3070 .bInterfaceClass = USB_CLASS_VIDEO,
3071 .bInterfaceSubClass = 1,
3072 .bInterfaceProtocol = 0,
3073 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3074 /* Syntek (Packard Bell EasyNote MX52 */
3075 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3076 | USB_DEVICE_ID_MATCH_INT_INFO,
3078 .idProduct = 0x8a12,
3079 .bInterfaceClass = USB_CLASS_VIDEO,
3080 .bInterfaceSubClass = 1,
3081 .bInterfaceProtocol = 0,
3082 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3083 /* Syntek (Asus F9SG) */
3084 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3085 | USB_DEVICE_ID_MATCH_INT_INFO,
3087 .idProduct = 0x8a31,
3088 .bInterfaceClass = USB_CLASS_VIDEO,
3089 .bInterfaceSubClass = 1,
3090 .bInterfaceProtocol = 0,
3091 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3092 /* Syntek (Asus U3S) */
3093 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3094 | USB_DEVICE_ID_MATCH_INT_INFO,
3096 .idProduct = 0x8a33,
3097 .bInterfaceClass = USB_CLASS_VIDEO,
3098 .bInterfaceSubClass = 1,
3099 .bInterfaceProtocol = 0,
3100 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3101 /* Syntek (JAOtech Smart Terminal) */
3102 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3103 | USB_DEVICE_ID_MATCH_INT_INFO,
3105 .idProduct = 0x8a34,
3106 .bInterfaceClass = USB_CLASS_VIDEO,
3107 .bInterfaceSubClass = 1,
3108 .bInterfaceProtocol = 0,
3109 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3111 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3112 | USB_DEVICE_ID_MATCH_INT_INFO,
3114 .idProduct = 0x0202,
3115 .bInterfaceClass = USB_CLASS_VIDEO,
3116 .bInterfaceSubClass = 1,
3117 .bInterfaceProtocol = 0,
3118 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3119 /* Lenovo Thinkpad SL400/SL500 */
3120 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3121 | USB_DEVICE_ID_MATCH_INT_INFO,
3123 .idProduct = 0x480b,
3124 .bInterfaceClass = USB_CLASS_VIDEO,
3125 .bInterfaceSubClass = 1,
3126 .bInterfaceProtocol = 0,
3127 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3128 /* Aveo Technology USB 2.0 Camera */
3129 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3130 | USB_DEVICE_ID_MATCH_INT_INFO,
3132 .idProduct = 0x0306,
3133 .bInterfaceClass = USB_CLASS_VIDEO,
3134 .bInterfaceSubClass = 1,
3135 .bInterfaceProtocol = 0,
3136 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
3137 | UVC_QUIRK_PROBE_EXTRAFIELDS) },
3138 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
3139 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3140 | USB_DEVICE_ID_MATCH_INT_INFO,
3142 .idProduct = 0x0516,
3143 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3144 .bInterfaceSubClass = 1,
3145 .bInterfaceProtocol = 0 },
3146 /* Ecamm Pico iMage */
3147 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3148 | USB_DEVICE_ID_MATCH_INT_INFO,
3150 .idProduct = 0xcafe,
3151 .bInterfaceClass = USB_CLASS_VIDEO,
3152 .bInterfaceSubClass = 1,
3153 .bInterfaceProtocol = 0,
3154 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) },
3155 /* Manta MM-353 Plako */
3156 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3157 | USB_DEVICE_ID_MATCH_INT_INFO,
3159 .idProduct = 0x3188,
3160 .bInterfaceClass = USB_CLASS_VIDEO,
3161 .bInterfaceSubClass = 1,
3162 .bInterfaceProtocol = 0,
3163 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3164 /* FSC WebCam V30S */
3165 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3166 | USB_DEVICE_ID_MATCH_INT_INFO,
3168 .idProduct = 0x3288,
3169 .bInterfaceClass = USB_CLASS_VIDEO,
3170 .bInterfaceSubClass = 1,
3171 .bInterfaceProtocol = 0,
3172 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3173 /* Arkmicro unbranded */
3174 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3175 | USB_DEVICE_ID_MATCH_INT_INFO,
3177 .idProduct = 0x3290,
3178 .bInterfaceClass = USB_CLASS_VIDEO,
3179 .bInterfaceSubClass = 1,
3180 .bInterfaceProtocol = 0,
3181 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
3182 /* The Imaging Source USB CCD cameras */
3183 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3184 | USB_DEVICE_ID_MATCH_INT_INFO,
3186 .idProduct = 0x8102,
3187 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3188 .bInterfaceSubClass = 1,
3189 .bInterfaceProtocol = 0 },
3190 /* Bodelin ProScopeHR */
3191 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3192 | USB_DEVICE_ID_MATCH_DEV_HI
3193 | USB_DEVICE_ID_MATCH_INT_INFO,
3195 .idProduct = 0x1000,
3196 .bcdDevice_hi = 0x0126,
3197 .bInterfaceClass = USB_CLASS_VIDEO,
3198 .bInterfaceSubClass = 1,
3199 .bInterfaceProtocol = 0,
3200 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) },
3201 /* MSI StarCam 370i */
3202 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3203 | USB_DEVICE_ID_MATCH_INT_INFO,
3205 .idProduct = 0x2951,
3206 .bInterfaceClass = USB_CLASS_VIDEO,
3207 .bInterfaceSubClass = 1,
3208 .bInterfaceProtocol = 0,
3209 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3210 /* Generalplus Technology Inc. 808 Camera */
3211 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3212 | USB_DEVICE_ID_MATCH_INT_INFO,
3214 .idProduct = 0x2002,
3215 .bInterfaceClass = USB_CLASS_VIDEO,
3216 .bInterfaceSubClass = 1,
3217 .bInterfaceProtocol = 0,
3218 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3219 /* Shenzhen Aoni Electronic Co.,Ltd 2K FHD camera */
3220 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3221 | USB_DEVICE_ID_MATCH_INT_INFO,
3223 .idProduct = 0x0b40,
3224 .bInterfaceClass = USB_CLASS_VIDEO,
3225 .bInterfaceSubClass = 1,
3226 .bInterfaceProtocol = 0,
3227 .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
3228 .uvc_version = 0x010a,
3230 /* SiGma Micro USB Web Camera */
3231 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3232 | USB_DEVICE_ID_MATCH_INT_INFO,
3234 .idProduct = 0x3000,
3235 .bInterfaceClass = USB_CLASS_VIDEO,
3236 .bInterfaceSubClass = 1,
3237 .bInterfaceProtocol = 0,
3238 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
3239 | UVC_QUIRK_IGNORE_SELECTOR_UNIT) },
3240 /* Oculus VR Positional Tracker DK2 */
3241 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3242 | USB_DEVICE_ID_MATCH_INT_INFO,
3244 .idProduct = 0x0201,
3245 .bInterfaceClass = USB_CLASS_VIDEO,
3246 .bInterfaceSubClass = 1,
3247 .bInterfaceProtocol = 0,
3248 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
3249 /* Oculus VR Rift Sensor */
3250 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3251 | USB_DEVICE_ID_MATCH_INT_INFO,
3253 .idProduct = 0x0211,
3254 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3255 .bInterfaceSubClass = 1,
3256 .bInterfaceProtocol = 0,
3257 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
3258 /* GEO Semiconductor GC6500 */
3259 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3260 | USB_DEVICE_ID_MATCH_INT_INFO,
3262 .idProduct = 0x4d53,
3263 .bInterfaceClass = USB_CLASS_VIDEO,
3264 .bInterfaceSubClass = 1,
3265 .bInterfaceProtocol = 0,
3266 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) },
3267 /* Sonix Technology USB 2.0 Camera */
3268 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3269 | USB_DEVICE_ID_MATCH_INT_INFO,
3271 .idProduct = 0x0072,
3272 .bInterfaceClass = USB_CLASS_VIDEO,
3273 .bInterfaceSubClass = 1,
3274 .bInterfaceProtocol = 0,
3275 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3276 /* Acer EasyCamera */
3277 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3278 | USB_DEVICE_ID_MATCH_INT_INFO,
3280 .idProduct = 0x1172,
3281 .bInterfaceClass = USB_CLASS_VIDEO,
3282 .bInterfaceSubClass = 1,
3283 .bInterfaceProtocol = 0,
3284 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3285 /* Intel RealSense D4M */
3286 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3287 | USB_DEVICE_ID_MATCH_INT_INFO,
3289 .idProduct = 0x0b03,
3290 .bInterfaceClass = USB_CLASS_VIDEO,
3291 .bInterfaceSubClass = 1,
3292 .bInterfaceProtocol = 0,
3293 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3294 /* Generic USB Video Class */
3295 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
3296 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
3300 MODULE_DEVICE_TABLE(usb, uvc_ids);
3302 struct uvc_driver uvc_driver = {
3306 .disconnect = uvc_disconnect,
3307 .suspend = uvc_suspend,
3308 .resume = uvc_resume,
3309 .reset_resume = uvc_reset_resume,
3310 .id_table = uvc_ids,
3311 .supports_autosuspend = 1,
3315 static int __init uvc_init(void)
3321 ret = usb_register(&uvc_driver.driver);
3323 uvc_debugfs_cleanup();
3330 static void __exit uvc_cleanup(void)
3332 usb_deregister(&uvc_driver.driver);
3333 uvc_debugfs_cleanup();
3336 module_init(uvc_init);
3337 module_exit(uvc_cleanup);
3339 MODULE_AUTHOR(DRIVER_AUTHOR);
3340 MODULE_DESCRIPTION(DRIVER_DESC);
3341 MODULE_LICENSE("GPL");
3342 MODULE_VERSION(DRIVER_VERSION);