1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * uvc_driver.c -- USB Video Class driver
4 *
5 * Copyright (C) 2005-2010
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 */
8
9 #include <linux/atomic.h>
10 #include <linux/bits.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/kernel.h>
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/usb.h>
17 #include <linux/usb/quirks.h>
18 #include <linux/usb/uvc.h>
19 #include <linux/videodev2.h>
20 #include <linux/vmalloc.h>
21 #include <linux/wait.h>
22 #include <asm/unaligned.h>
23
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ioctl.h>
26
27 #include "uvcvideo.h"
28
29 #define DRIVER_AUTHOR "Laurent Pinchart " \
30 "<laurent.pinchart@ideasonboard.com>"
31 #define DRIVER_DESC "USB Video Class driver"
32
33 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
34 unsigned int uvc_hw_timestamps_param;
35 unsigned int uvc_no_drop_param;
36 static unsigned int uvc_quirks_param = -1;
37 unsigned int uvc_dbg_param;
38 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
39
40 /* ------------------------------------------------------------------------
41 * Utility functions
42 */
43
uvc_find_endpoint(struct usb_host_interface * alts,u8 epaddr)44 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
45 u8 epaddr)
46 {
47 struct usb_host_endpoint *ep;
48 unsigned int i;
49
50 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
51 ep = &alts->endpoint[i];
52 if (ep->desc.bEndpointAddress == epaddr)
53 return ep;
54 }
55
56 return NULL;
57 }
58
uvc_colorspace(const u8 primaries)59 static enum v4l2_colorspace uvc_colorspace(const u8 primaries)
60 {
61 static const enum v4l2_colorspace colorprimaries[] = {
62 V4L2_COLORSPACE_SRGB, /* Unspecified */
63 V4L2_COLORSPACE_SRGB,
64 V4L2_COLORSPACE_470_SYSTEM_M,
65 V4L2_COLORSPACE_470_SYSTEM_BG,
66 V4L2_COLORSPACE_SMPTE170M,
67 V4L2_COLORSPACE_SMPTE240M,
68 };
69
70 if (primaries < ARRAY_SIZE(colorprimaries))
71 return colorprimaries[primaries];
72
73 return V4L2_COLORSPACE_SRGB; /* Reserved */
74 }
75
uvc_xfer_func(const u8 transfer_characteristics)76 static enum v4l2_xfer_func uvc_xfer_func(const u8 transfer_characteristics)
77 {
78 /*
79 * V4L2 does not currently have definitions for all possible values of
80 * UVC transfer characteristics. If v4l2_xfer_func is extended with new
81 * values, the mapping below should be updated.
82 *
83 * Substitutions are taken from the mapping given for
84 * V4L2_XFER_FUNC_DEFAULT documented in videodev2.h.
85 */
86 static const enum v4l2_xfer_func xfer_funcs[] = {
87 V4L2_XFER_FUNC_DEFAULT, /* Unspecified */
88 V4L2_XFER_FUNC_709,
89 V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 M */
90 V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 B, G */
91 V4L2_XFER_FUNC_709, /* Substitution for SMPTE 170M */
92 V4L2_XFER_FUNC_SMPTE240M,
93 V4L2_XFER_FUNC_NONE,
94 V4L2_XFER_FUNC_SRGB,
95 };
96
97 if (transfer_characteristics < ARRAY_SIZE(xfer_funcs))
98 return xfer_funcs[transfer_characteristics];
99
100 return V4L2_XFER_FUNC_DEFAULT; /* Reserved */
101 }
102
uvc_ycbcr_enc(const u8 matrix_coefficients)103 static enum v4l2_ycbcr_encoding uvc_ycbcr_enc(const u8 matrix_coefficients)
104 {
105 /*
106 * V4L2 does not currently have definitions for all possible values of
107 * UVC matrix coefficients. If v4l2_ycbcr_encoding is extended with new
108 * values, the mapping below should be updated.
109 *
110 * Substitutions are taken from the mapping given for
111 * V4L2_YCBCR_ENC_DEFAULT documented in videodev2.h.
112 *
113 * FCC is assumed to be close enough to 601.
114 */
115 static const enum v4l2_ycbcr_encoding ycbcr_encs[] = {
116 V4L2_YCBCR_ENC_DEFAULT, /* Unspecified */
117 V4L2_YCBCR_ENC_709,
118 V4L2_YCBCR_ENC_601, /* Substitution for FCC */
119 V4L2_YCBCR_ENC_601, /* Substitution for BT.470-2 B, G */
120 V4L2_YCBCR_ENC_601,
121 V4L2_YCBCR_ENC_SMPTE240M,
122 };
123
124 if (matrix_coefficients < ARRAY_SIZE(ycbcr_encs))
125 return ycbcr_encs[matrix_coefficients];
126
127 return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */
128 }
129
130 /* ------------------------------------------------------------------------
131 * Terminal and unit management
132 */
133
uvc_entity_by_id(struct uvc_device * dev,int id)134 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
135 {
136 struct uvc_entity *entity;
137
138 list_for_each_entry(entity, &dev->entities, list) {
139 if (entity->id == id)
140 return entity;
141 }
142
143 return NULL;
144 }
145
uvc_entity_by_reference(struct uvc_device * dev,int id,struct uvc_entity * entity)146 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
147 int id, struct uvc_entity *entity)
148 {
149 unsigned int i;
150
151 if (entity == NULL)
152 entity = list_entry(&dev->entities, struct uvc_entity, list);
153
154 list_for_each_entry_continue(entity, &dev->entities, list) {
155 for (i = 0; i < entity->bNrInPins; ++i)
156 if (entity->baSourceID[i] == id)
157 return entity;
158 }
159
160 return NULL;
161 }
162
uvc_stream_by_id(struct uvc_device * dev,int id)163 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
164 {
165 struct uvc_streaming *stream;
166
167 list_for_each_entry(stream, &dev->streams, list) {
168 if (stream->header.bTerminalLink == id)
169 return stream;
170 }
171
172 return NULL;
173 }
174
175 /* ------------------------------------------------------------------------
176 * Streaming Object Management
177 */
178
uvc_stream_delete(struct uvc_streaming * stream)179 static void uvc_stream_delete(struct uvc_streaming *stream)
180 {
181 if (stream->async_wq)
182 destroy_workqueue(stream->async_wq);
183
184 mutex_destroy(&stream->mutex);
185
186 usb_put_intf(stream->intf);
187
188 kfree(stream->formats);
189 kfree(stream->header.bmaControls);
190 kfree(stream);
191 }
192
uvc_stream_new(struct uvc_device * dev,struct usb_interface * intf)193 static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev,
194 struct usb_interface *intf)
195 {
196 struct uvc_streaming *stream;
197
198 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
199 if (stream == NULL)
200 return NULL;
201
202 mutex_init(&stream->mutex);
203
204 stream->dev = dev;
205 stream->intf = usb_get_intf(intf);
206 stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
207
208 /* Allocate a stream specific work queue for asynchronous tasks. */
209 stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | WQ_HIGHPRI,
210 0);
211 if (!stream->async_wq) {
212 uvc_stream_delete(stream);
213 return NULL;
214 }
215
216 return stream;
217 }
218
219 /* ------------------------------------------------------------------------
220 * Descriptors parsing
221 */
222
uvc_parse_format(struct uvc_device * dev,struct uvc_streaming * streaming,struct uvc_format * format,struct uvc_frame * frames,u32 ** intervals,const unsigned char * buffer,int buflen)223 static int uvc_parse_format(struct uvc_device *dev,
224 struct uvc_streaming *streaming, struct uvc_format *format,
225 struct uvc_frame *frames, u32 **intervals, const unsigned char *buffer,
226 int buflen)
227 {
228 struct usb_interface *intf = streaming->intf;
229 struct usb_host_interface *alts = intf->cur_altsetting;
230 const struct uvc_format_desc *fmtdesc;
231 struct uvc_frame *frame;
232 const unsigned char *start = buffer;
233 unsigned int width_multiplier = 1;
234 unsigned int interval;
235 unsigned int i, n;
236 u8 ftype;
237
238 format->type = buffer[2];
239 format->index = buffer[3];
240 format->frames = frames;
241
242 switch (buffer[2]) {
243 case UVC_VS_FORMAT_UNCOMPRESSED:
244 case UVC_VS_FORMAT_FRAME_BASED:
245 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
246 if (buflen < n) {
247 uvc_dbg(dev, DESCR,
248 "device %d videostreaming interface %d FORMAT error\n",
249 dev->udev->devnum,
250 alts->desc.bInterfaceNumber);
251 return -EINVAL;
252 }
253
254 /* Find the format descriptor from its GUID. */
255 fmtdesc = uvc_format_by_guid(&buffer[5]);
256
257 if (!fmtdesc) {
258 /*
259 * Unknown video formats are not fatal errors, the
260 * caller will skip this descriptor.
261 */
262 dev_info(&streaming->intf->dev,
263 "Unknown video format %pUl\n", &buffer[5]);
264 return 0;
265 }
266
267 format->fcc = fmtdesc->fcc;
268 format->bpp = buffer[21];
269
270 /*
271 * Some devices report a format that doesn't match what they
272 * really send.
273 */
274 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
275 if (format->fcc == V4L2_PIX_FMT_YUYV) {
276 format->fcc = V4L2_PIX_FMT_GREY;
277 format->bpp = 8;
278 width_multiplier = 2;
279 }
280 }
281
282 /* Some devices report bpp that doesn't match the format. */
283 if (dev->quirks & UVC_QUIRK_FORCE_BPP) {
284 const struct v4l2_format_info *info =
285 v4l2_format_info(format->fcc);
286
287 if (info) {
288 unsigned int div = info->hdiv * info->vdiv;
289
290 n = info->bpp[0] * div;
291 for (i = 1; i < info->comp_planes; i++)
292 n += info->bpp[i];
293
294 format->bpp = DIV_ROUND_UP(8 * n, div);
295 }
296 }
297
298 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
299 ftype = UVC_VS_FRAME_UNCOMPRESSED;
300 } else {
301 ftype = UVC_VS_FRAME_FRAME_BASED;
302 if (buffer[27])
303 format->flags = UVC_FMT_FLAG_COMPRESSED;
304 }
305 break;
306
307 case UVC_VS_FORMAT_MJPEG:
308 if (buflen < 11) {
309 uvc_dbg(dev, DESCR,
310 "device %d videostreaming interface %d FORMAT error\n",
311 dev->udev->devnum,
312 alts->desc.bInterfaceNumber);
313 return -EINVAL;
314 }
315
316 format->fcc = V4L2_PIX_FMT_MJPEG;
317 format->flags = UVC_FMT_FLAG_COMPRESSED;
318 format->bpp = 0;
319 ftype = UVC_VS_FRAME_MJPEG;
320 break;
321
322 case UVC_VS_FORMAT_DV:
323 if (buflen < 9) {
324 uvc_dbg(dev, DESCR,
325 "device %d videostreaming interface %d FORMAT error\n",
326 dev->udev->devnum,
327 alts->desc.bInterfaceNumber);
328 return -EINVAL;
329 }
330
331 if ((buffer[8] & 0x7f) > 2) {
332 uvc_dbg(dev, DESCR,
333 "device %d videostreaming interface %d: unknown DV format %u\n",
334 dev->udev->devnum,
335 alts->desc.bInterfaceNumber, buffer[8]);
336 return -EINVAL;
337 }
338
339 format->fcc = V4L2_PIX_FMT_DV;
340 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
341 format->bpp = 0;
342 ftype = 0;
343
344 /* Create a dummy frame descriptor. */
345 frame = &frames[0];
346 memset(frame, 0, sizeof(*frame));
347 frame->bFrameIntervalType = 1;
348 frame->dwDefaultFrameInterval = 1;
349 frame->dwFrameInterval = *intervals;
350 *(*intervals)++ = 1;
351 format->nframes = 1;
352 break;
353
354 case UVC_VS_FORMAT_MPEG2TS:
355 case UVC_VS_FORMAT_STREAM_BASED:
356 /* Not supported yet. */
357 default:
358 uvc_dbg(dev, DESCR,
359 "device %d videostreaming interface %d unsupported format %u\n",
360 dev->udev->devnum, alts->desc.bInterfaceNumber,
361 buffer[2]);
362 return -EINVAL;
363 }
364
365 uvc_dbg(dev, DESCR, "Found format %p4cc", &format->fcc);
366
367 buflen -= buffer[0];
368 buffer += buffer[0];
369
370 /*
371 * Parse the frame descriptors. Only uncompressed, MJPEG and frame
372 * based formats have frame descriptors.
373 */
374 while (ftype && buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
375 buffer[2] == ftype) {
376 unsigned int maxIntervalIndex;
377
378 frame = &frames[format->nframes];
379 if (ftype != UVC_VS_FRAME_FRAME_BASED)
380 n = buflen > 25 ? buffer[25] : 0;
381 else
382 n = buflen > 21 ? buffer[21] : 0;
383
384 n = n ? n : 3;
385
386 if (buflen < 26 + 4*n) {
387 uvc_dbg(dev, DESCR,
388 "device %d videostreaming interface %d FRAME error\n",
389 dev->udev->devnum,
390 alts->desc.bInterfaceNumber);
391 return -EINVAL;
392 }
393
394 frame->bFrameIndex = buffer[3];
395 frame->bmCapabilities = buffer[4];
396 frame->wWidth = get_unaligned_le16(&buffer[5])
397 * width_multiplier;
398 frame->wHeight = get_unaligned_le16(&buffer[7]);
399 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
400 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
401 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
402 frame->dwMaxVideoFrameBufferSize =
403 get_unaligned_le32(&buffer[17]);
404 frame->dwDefaultFrameInterval =
405 get_unaligned_le32(&buffer[21]);
406 frame->bFrameIntervalType = buffer[25];
407 } else {
408 frame->dwMaxVideoFrameBufferSize = 0;
409 frame->dwDefaultFrameInterval =
410 get_unaligned_le32(&buffer[17]);
411 frame->bFrameIntervalType = buffer[21];
412 }
413
414 /*
415 * Copy the frame intervals.
416 *
417 * Some bogus devices report dwMinFrameInterval equal to
418 * dwMaxFrameInterval and have dwFrameIntervalStep set to
419 * zero. Setting all null intervals to 1 fixes the problem and
420 * some other divisions by zero that could happen.
421 */
422 frame->dwFrameInterval = *intervals;
423
424 for (i = 0; i < n; ++i) {
425 interval = get_unaligned_le32(&buffer[26+4*i]);
426 (*intervals)[i] = interval ? interval : 1;
427 }
428
429 /*
430 * Apply more fixes, quirks and workarounds to handle incorrect
431 * or broken descriptors.
432 */
433
434 /*
435 * Several UVC chipsets screw up dwMaxVideoFrameBufferSize
436 * completely. Observed behaviours range from setting the
437 * value to 1.1x the actual frame size to hardwiring the
438 * 16 low bits to 0. This results in a higher than necessary
439 * memory usage as well as a wrong image size information. For
440 * uncompressed formats this can be fixed by computing the
441 * value from the frame size.
442 */
443 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
444 frame->dwMaxVideoFrameBufferSize = format->bpp
445 * frame->wWidth * frame->wHeight / 8;
446
447 /*
448 * Clamp the default frame interval to the boundaries. A zero
449 * bFrameIntervalType value indicates a continuous frame
450 * interval range, with dwFrameInterval[0] storing the minimum
451 * value and dwFrameInterval[1] storing the maximum value.
452 */
453 maxIntervalIndex = frame->bFrameIntervalType ? n - 1 : 1;
454 frame->dwDefaultFrameInterval =
455 clamp(frame->dwDefaultFrameInterval,
456 frame->dwFrameInterval[0],
457 frame->dwFrameInterval[maxIntervalIndex]);
458
459 /*
460 * Some devices report frame intervals that are not functional.
461 * If the corresponding quirk is set, restrict operation to the
462 * first interval only.
463 */
464 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
465 frame->bFrameIntervalType = 1;
466 (*intervals)[0] = frame->dwDefaultFrameInterval;
467 }
468
469 uvc_dbg(dev, DESCR, "- %ux%u (%u.%u fps)\n",
470 frame->wWidth, frame->wHeight,
471 10000000 / frame->dwDefaultFrameInterval,
472 (100000000 / frame->dwDefaultFrameInterval) % 10);
473
474 format->nframes++;
475 *intervals += n;
476
477 buflen -= buffer[0];
478 buffer += buffer[0];
479 }
480
481 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
482 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
483 buflen -= buffer[0];
484 buffer += buffer[0];
485 }
486
487 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
488 buffer[2] == UVC_VS_COLORFORMAT) {
489 if (buflen < 6) {
490 uvc_dbg(dev, DESCR,
491 "device %d videostreaming interface %d COLORFORMAT error\n",
492 dev->udev->devnum,
493 alts->desc.bInterfaceNumber);
494 return -EINVAL;
495 }
496
497 format->colorspace = uvc_colorspace(buffer[3]);
498 format->xfer_func = uvc_xfer_func(buffer[4]);
499 format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]);
500
501 buflen -= buffer[0];
502 buffer += buffer[0];
503 } else {
504 format->colorspace = V4L2_COLORSPACE_SRGB;
505 }
506
507 return buffer - start;
508 }
509
uvc_parse_streaming(struct uvc_device * dev,struct usb_interface * intf)510 static int uvc_parse_streaming(struct uvc_device *dev,
511 struct usb_interface *intf)
512 {
513 struct uvc_streaming *streaming = NULL;
514 struct uvc_format *format;
515 struct uvc_frame *frame;
516 struct usb_host_interface *alts = &intf->altsetting[0];
517 const unsigned char *_buffer, *buffer = alts->extra;
518 int _buflen, buflen = alts->extralen;
519 unsigned int nformats = 0, nframes = 0, nintervals = 0;
520 unsigned int size, i, n, p;
521 u32 *interval;
522 u16 psize;
523 int ret = -EINVAL;
524
525 if (intf->cur_altsetting->desc.bInterfaceSubClass
526 != UVC_SC_VIDEOSTREAMING) {
527 uvc_dbg(dev, DESCR,
528 "device %d interface %d isn't a video streaming interface\n",
529 dev->udev->devnum,
530 intf->altsetting[0].desc.bInterfaceNumber);
531 return -EINVAL;
532 }
533
534 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
535 uvc_dbg(dev, DESCR,
536 "device %d interface %d is already claimed\n",
537 dev->udev->devnum,
538 intf->altsetting[0].desc.bInterfaceNumber);
539 return -EINVAL;
540 }
541
542 streaming = uvc_stream_new(dev, intf);
543 if (streaming == NULL) {
544 usb_driver_release_interface(&uvc_driver.driver, intf);
545 return -ENOMEM;
546 }
547
548 /*
549 * The Pico iMage webcam has its class-specific interface descriptors
550 * after the endpoint descriptors.
551 */
552 if (buflen == 0) {
553 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
554 struct usb_host_endpoint *ep = &alts->endpoint[i];
555
556 if (ep->extralen == 0)
557 continue;
558
559 if (ep->extralen > 2 &&
560 ep->extra[1] == USB_DT_CS_INTERFACE) {
561 uvc_dbg(dev, DESCR,
562 "trying extra data from endpoint %u\n",
563 i);
564 buffer = alts->endpoint[i].extra;
565 buflen = alts->endpoint[i].extralen;
566 break;
567 }
568 }
569 }
570
571 /* Skip the standard interface descriptors. */
572 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
573 buflen -= buffer[0];
574 buffer += buffer[0];
575 }
576
577 if (buflen <= 2) {
578 uvc_dbg(dev, DESCR,
579 "no class-specific streaming interface descriptors found\n");
580 goto error;
581 }
582
583 /* Parse the header descriptor. */
584 switch (buffer[2]) {
585 case UVC_VS_OUTPUT_HEADER:
586 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
587 size = 9;
588 break;
589
590 case UVC_VS_INPUT_HEADER:
591 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
592 size = 13;
593 break;
594
595 default:
596 uvc_dbg(dev, DESCR,
597 "device %d videostreaming interface %d HEADER descriptor not found\n",
598 dev->udev->devnum, alts->desc.bInterfaceNumber);
599 goto error;
600 }
601
602 p = buflen >= 4 ? buffer[3] : 0;
603 n = buflen >= size ? buffer[size-1] : 0;
604
605 if (buflen < size + p*n) {
606 uvc_dbg(dev, DESCR,
607 "device %d videostreaming interface %d HEADER descriptor is invalid\n",
608 dev->udev->devnum, alts->desc.bInterfaceNumber);
609 goto error;
610 }
611
612 streaming->header.bNumFormats = p;
613 streaming->header.bEndpointAddress = buffer[6];
614 if (buffer[2] == UVC_VS_INPUT_HEADER) {
615 streaming->header.bmInfo = buffer[7];
616 streaming->header.bTerminalLink = buffer[8];
617 streaming->header.bStillCaptureMethod = buffer[9];
618 streaming->header.bTriggerSupport = buffer[10];
619 streaming->header.bTriggerUsage = buffer[11];
620 } else {
621 streaming->header.bTerminalLink = buffer[7];
622 }
623 streaming->header.bControlSize = n;
624
625 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
626 GFP_KERNEL);
627 if (streaming->header.bmaControls == NULL) {
628 ret = -ENOMEM;
629 goto error;
630 }
631
632 buflen -= buffer[0];
633 buffer += buffer[0];
634
635 _buffer = buffer;
636 _buflen = buflen;
637
638 /* Count the format and frame descriptors. */
639 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
640 switch (_buffer[2]) {
641 case UVC_VS_FORMAT_UNCOMPRESSED:
642 case UVC_VS_FORMAT_MJPEG:
643 case UVC_VS_FORMAT_FRAME_BASED:
644 nformats++;
645 break;
646
647 case UVC_VS_FORMAT_DV:
648 /*
649 * DV format has no frame descriptor. We will create a
650 * dummy frame descriptor with a dummy frame interval.
651 */
652 nformats++;
653 nframes++;
654 nintervals++;
655 break;
656
657 case UVC_VS_FORMAT_MPEG2TS:
658 case UVC_VS_FORMAT_STREAM_BASED:
659 uvc_dbg(dev, DESCR,
660 "device %d videostreaming interface %d FORMAT %u is not supported\n",
661 dev->udev->devnum,
662 alts->desc.bInterfaceNumber, _buffer[2]);
663 break;
664
665 case UVC_VS_FRAME_UNCOMPRESSED:
666 case UVC_VS_FRAME_MJPEG:
667 nframes++;
668 if (_buflen > 25)
669 nintervals += _buffer[25] ? _buffer[25] : 3;
670 break;
671
672 case UVC_VS_FRAME_FRAME_BASED:
673 nframes++;
674 if (_buflen > 21)
675 nintervals += _buffer[21] ? _buffer[21] : 3;
676 break;
677 }
678
679 _buflen -= _buffer[0];
680 _buffer += _buffer[0];
681 }
682
683 if (nformats == 0) {
684 uvc_dbg(dev, DESCR,
685 "device %d videostreaming interface %d has no supported formats defined\n",
686 dev->udev->devnum, alts->desc.bInterfaceNumber);
687 goto error;
688 }
689
690 /*
691 * Allocate memory for the formats, the frames and the intervals,
692 * plus any required padding to guarantee that everything has the
693 * correct alignment.
694 */
695 size = nformats * sizeof(*format);
696 size = ALIGN(size, __alignof__(*frame)) + nframes * sizeof(*frame);
697 size = ALIGN(size, __alignof__(*interval))
698 + nintervals * sizeof(*interval);
699
700 format = kzalloc(size, GFP_KERNEL);
701 if (!format) {
702 ret = -ENOMEM;
703 goto error;
704 }
705
706 frame = (void *)format + nformats * sizeof(*format);
707 frame = PTR_ALIGN(frame, __alignof__(*frame));
708 interval = (void *)frame + nframes * sizeof(*frame);
709 interval = PTR_ALIGN(interval, __alignof__(*interval));
710
711 streaming->formats = format;
712 streaming->nformats = 0;
713
714 /* Parse the format descriptors. */
715 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
716 switch (buffer[2]) {
717 case UVC_VS_FORMAT_UNCOMPRESSED:
718 case UVC_VS_FORMAT_MJPEG:
719 case UVC_VS_FORMAT_DV:
720 case UVC_VS_FORMAT_FRAME_BASED:
721 ret = uvc_parse_format(dev, streaming, format, frame,
722 &interval, buffer, buflen);
723 if (ret < 0)
724 goto error;
725 if (!ret)
726 break;
727
728 streaming->nformats++;
729 frame += format->nframes;
730 format++;
731
732 buflen -= ret;
733 buffer += ret;
734 continue;
735
736 default:
737 break;
738 }
739
740 buflen -= buffer[0];
741 buffer += buffer[0];
742 }
743
744 if (buflen)
745 uvc_dbg(dev, DESCR,
746 "device %d videostreaming interface %d has %u bytes of trailing descriptor garbage\n",
747 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
748
749 /* Parse the alternate settings to find the maximum bandwidth. */
750 for (i = 0; i < intf->num_altsetting; ++i) {
751 struct usb_host_endpoint *ep;
752
753 alts = &intf->altsetting[i];
754 ep = uvc_find_endpoint(alts,
755 streaming->header.bEndpointAddress);
756 if (ep == NULL)
757 continue;
758 psize = uvc_endpoint_max_bpi(dev->udev, ep);
759 if (psize > streaming->maxpsize)
760 streaming->maxpsize = psize;
761 }
762
763 list_add_tail(&streaming->list, &dev->streams);
764 return 0;
765
766 error:
767 usb_driver_release_interface(&uvc_driver.driver, intf);
768 uvc_stream_delete(streaming);
769 return ret;
770 }
771
772 static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA;
773 static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER;
774 static const u8 uvc_media_transport_input_guid[16] =
775 UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT;
776 static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING;
777
uvc_alloc_new_entity(struct uvc_device * dev,u16 type,u16 id,unsigned int num_pads,unsigned int extra_size)778 static struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type,
779 u16 id, unsigned int num_pads,
780 unsigned int extra_size)
781 {
782 struct uvc_entity *entity;
783 unsigned int num_inputs;
784 unsigned int size;
785 unsigned int i;
786
787 /* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */
788 if (id == 0) {
789 dev_err(&dev->udev->dev, "Found Unit with invalid ID 0.\n");
790 return ERR_PTR(-EINVAL);
791 }
792
793 /* Per UVC 1.1+ spec 3.7.2, the ID is unique. */
794 if (uvc_entity_by_id(dev, id)) {
795 dev_err(&dev->udev->dev, "Found multiple Units with ID %u\n", id);
796 return ERR_PTR(-EINVAL);
797 }
798
799 extra_size = roundup(extra_size, sizeof(*entity->pads));
800 if (num_pads)
801 num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
802 else
803 num_inputs = 0;
804 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
805 + num_inputs;
806 entity = kzalloc(size, GFP_KERNEL);
807 if (entity == NULL)
808 return ERR_PTR(-ENOMEM);
809
810 entity->id = id;
811 entity->type = type;
812
813 /*
814 * Set the GUID for standard entity types. For extension units, the GUID
815 * is initialized by the caller.
816 */
817 switch (type) {
818 case UVC_EXT_GPIO_UNIT:
819 memcpy(entity->guid, uvc_gpio_guid, 16);
820 break;
821 case UVC_ITT_CAMERA:
822 memcpy(entity->guid, uvc_camera_guid, 16);
823 break;
824 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
825 memcpy(entity->guid, uvc_media_transport_input_guid, 16);
826 break;
827 case UVC_VC_PROCESSING_UNIT:
828 memcpy(entity->guid, uvc_processing_guid, 16);
829 break;
830 }
831
832 entity->num_links = 0;
833 entity->num_pads = num_pads;
834 entity->pads = ((void *)(entity + 1)) + extra_size;
835
836 for (i = 0; i < num_inputs; ++i)
837 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
838 if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
839 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
840
841 entity->bNrInPins = num_inputs;
842 entity->baSourceID = (u8 *)(&entity->pads[num_pads]);
843
844 return entity;
845 }
846
uvc_entity_set_name(struct uvc_device * dev,struct uvc_entity * entity,const char * type_name,u8 string_id)847 static void uvc_entity_set_name(struct uvc_device *dev, struct uvc_entity *entity,
848 const char *type_name, u8 string_id)
849 {
850 int ret;
851
852 /*
853 * First attempt to read the entity name from the device. If the entity
854 * has no associated string, or if reading the string fails (most
855 * likely due to a buggy firmware), fall back to default names based on
856 * the entity type.
857 */
858 if (string_id) {
859 ret = usb_string(dev->udev, string_id, entity->name,
860 sizeof(entity->name));
861 if (!ret)
862 return;
863 }
864
865 sprintf(entity->name, "%s %u", type_name, entity->id);
866 }
867
868 /* Parse vendor-specific extensions. */
uvc_parse_vendor_control(struct uvc_device * dev,const unsigned char * buffer,int buflen)869 static int uvc_parse_vendor_control(struct uvc_device *dev,
870 const unsigned char *buffer, int buflen)
871 {
872 struct usb_device *udev = dev->udev;
873 struct usb_host_interface *alts = dev->intf->cur_altsetting;
874 struct uvc_entity *unit;
875 unsigned int n, p;
876 int handled = 0;
877
878 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
879 case 0x046d: /* Logitech */
880 if (buffer[1] != 0x41 || buffer[2] != 0x01)
881 break;
882
883 /*
884 * Logitech implements several vendor specific functions
885 * through vendor specific extension units (LXU).
886 *
887 * The LXU descriptors are similar to XU descriptors
888 * (see "USB Device Video Class for Video Devices", section
889 * 3.7.2.6 "Extension Unit Descriptor") with the following
890 * differences:
891 *
892 * ----------------------------------------------------------
893 * 0 bLength 1 Number
894 * Size of this descriptor, in bytes: 24+p+n*2
895 * ----------------------------------------------------------
896 * 23+p+n bmControlsType N Bitmap
897 * Individual bits in the set are defined:
898 * 0: Absolute
899 * 1: Relative
900 *
901 * This bitset is mapped exactly the same as bmControls.
902 * ----------------------------------------------------------
903 * 23+p+n*2 bReserved 1 Boolean
904 * ----------------------------------------------------------
905 * 24+p+n*2 iExtension 1 Index
906 * Index of a string descriptor that describes this
907 * extension unit.
908 * ----------------------------------------------------------
909 */
910 p = buflen >= 22 ? buffer[21] : 0;
911 n = buflen >= 25 + p ? buffer[22+p] : 0;
912
913 if (buflen < 25 + p + 2*n) {
914 uvc_dbg(dev, DESCR,
915 "device %d videocontrol interface %d EXTENSION_UNIT error\n",
916 udev->devnum, alts->desc.bInterfaceNumber);
917 break;
918 }
919
920 unit = uvc_alloc_new_entity(dev, UVC_VC_EXTENSION_UNIT,
921 buffer[3], p + 1, 2 * n);
922 if (IS_ERR(unit))
923 return PTR_ERR(unit);
924
925 memcpy(unit->guid, &buffer[4], 16);
926 unit->extension.bNumControls = buffer[20];
927 memcpy(unit->baSourceID, &buffer[22], p);
928 unit->extension.bControlSize = buffer[22+p];
929 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
930 unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit)
931 + n;
932 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
933
934 uvc_entity_set_name(dev, unit, "Extension", buffer[24+p+2*n]);
935
936 list_add_tail(&unit->list, &dev->entities);
937 handled = 1;
938 break;
939 }
940
941 return handled;
942 }
943
uvc_parse_standard_control(struct uvc_device * dev,const unsigned char * buffer,int buflen)944 static int uvc_parse_standard_control(struct uvc_device *dev,
945 const unsigned char *buffer, int buflen)
946 {
947 struct usb_device *udev = dev->udev;
948 struct uvc_entity *unit, *term;
949 struct usb_interface *intf;
950 struct usb_host_interface *alts = dev->intf->cur_altsetting;
951 unsigned int i, n, p, len;
952 const char *type_name;
953 u16 type;
954
955 switch (buffer[2]) {
956 case UVC_VC_HEADER:
957 n = buflen >= 12 ? buffer[11] : 0;
958
959 if (buflen < 12 + n) {
960 uvc_dbg(dev, DESCR,
961 "device %d videocontrol interface %d HEADER error\n",
962 udev->devnum, alts->desc.bInterfaceNumber);
963 return -EINVAL;
964 }
965
966 dev->uvc_version = get_unaligned_le16(&buffer[3]);
967 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
968
969 /* Parse all USB Video Streaming interfaces. */
970 for (i = 0; i < n; ++i) {
971 intf = usb_ifnum_to_if(udev, buffer[12+i]);
972 if (intf == NULL) {
973 uvc_dbg(dev, DESCR,
974 "device %d interface %d doesn't exists\n",
975 udev->devnum, i);
976 continue;
977 }
978
979 uvc_parse_streaming(dev, intf);
980 }
981 break;
982
983 case UVC_VC_INPUT_TERMINAL:
984 if (buflen < 8) {
985 uvc_dbg(dev, DESCR,
986 "device %d videocontrol interface %d INPUT_TERMINAL error\n",
987 udev->devnum, alts->desc.bInterfaceNumber);
988 return -EINVAL;
989 }
990
991 /*
992 * Reject invalid terminal types that would cause issues:
993 *
994 * - The high byte must be non-zero, otherwise it would be
995 * confused with a unit.
996 *
997 * - Bit 15 must be 0, as we use it internally as a terminal
998 * direction flag.
999 *
1000 * Other unknown types are accepted.
1001 */
1002 type = get_unaligned_le16(&buffer[4]);
1003 if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
1004 uvc_dbg(dev, DESCR,
1005 "device %d videocontrol interface %d INPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
1006 udev->devnum, alts->desc.bInterfaceNumber,
1007 buffer[3], type);
1008 return 0;
1009 }
1010
1011 n = 0;
1012 p = 0;
1013 len = 8;
1014
1015 if (type == UVC_ITT_CAMERA) {
1016 n = buflen >= 15 ? buffer[14] : 0;
1017 len = 15;
1018
1019 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1020 n = buflen >= 9 ? buffer[8] : 0;
1021 p = buflen >= 10 + n ? buffer[9+n] : 0;
1022 len = 10;
1023 }
1024
1025 if (buflen < len + n + p) {
1026 uvc_dbg(dev, DESCR,
1027 "device %d videocontrol interface %d INPUT_TERMINAL error\n",
1028 udev->devnum, alts->desc.bInterfaceNumber);
1029 return -EINVAL;
1030 }
1031
1032 term = uvc_alloc_new_entity(dev, type | UVC_TERM_INPUT,
1033 buffer[3], 1, n + p);
1034 if (IS_ERR(term))
1035 return PTR_ERR(term);
1036
1037 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1038 term->camera.bControlSize = n;
1039 term->camera.bmControls = (u8 *)term + sizeof(*term);
1040 term->camera.wObjectiveFocalLengthMin =
1041 get_unaligned_le16(&buffer[8]);
1042 term->camera.wObjectiveFocalLengthMax =
1043 get_unaligned_le16(&buffer[10]);
1044 term->camera.wOcularFocalLength =
1045 get_unaligned_le16(&buffer[12]);
1046 memcpy(term->camera.bmControls, &buffer[15], n);
1047 } else if (UVC_ENTITY_TYPE(term) ==
1048 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1049 term->media.bControlSize = n;
1050 term->media.bmControls = (u8 *)term + sizeof(*term);
1051 term->media.bTransportModeSize = p;
1052 term->media.bmTransportModes = (u8 *)term
1053 + sizeof(*term) + n;
1054 memcpy(term->media.bmControls, &buffer[9], n);
1055 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1056 }
1057
1058 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1059 type_name = "Camera";
1060 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1061 type_name = "Media";
1062 else
1063 type_name = "Input";
1064
1065 uvc_entity_set_name(dev, term, type_name, buffer[7]);
1066
1067 list_add_tail(&term->list, &dev->entities);
1068 break;
1069
1070 case UVC_VC_OUTPUT_TERMINAL:
1071 if (buflen < 9) {
1072 uvc_dbg(dev, DESCR,
1073 "device %d videocontrol interface %d OUTPUT_TERMINAL error\n",
1074 udev->devnum, alts->desc.bInterfaceNumber);
1075 return -EINVAL;
1076 }
1077
1078 /*
1079 * Make sure the terminal type MSB is not null, otherwise it
1080 * could be confused with a unit.
1081 */
1082 type = get_unaligned_le16(&buffer[4]);
1083 if ((type & 0xff00) == 0) {
1084 uvc_dbg(dev, DESCR,
1085 "device %d videocontrol interface %d OUTPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
1086 udev->devnum, alts->desc.bInterfaceNumber,
1087 buffer[3], type);
1088 return 0;
1089 }
1090
1091 term = uvc_alloc_new_entity(dev, type | UVC_TERM_OUTPUT,
1092 buffer[3], 1, 0);
1093 if (IS_ERR(term))
1094 return PTR_ERR(term);
1095
1096 memcpy(term->baSourceID, &buffer[7], 1);
1097
1098 uvc_entity_set_name(dev, term, "Output", buffer[8]);
1099
1100 list_add_tail(&term->list, &dev->entities);
1101 break;
1102
1103 case UVC_VC_SELECTOR_UNIT:
1104 p = buflen >= 5 ? buffer[4] : 0;
1105
1106 if (buflen < 5 || buflen < 6 + p) {
1107 uvc_dbg(dev, DESCR,
1108 "device %d videocontrol interface %d SELECTOR_UNIT error\n",
1109 udev->devnum, alts->desc.bInterfaceNumber);
1110 return -EINVAL;
1111 }
1112
1113 unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3],
1114 p + 1, 0);
1115 if (IS_ERR(unit))
1116 return PTR_ERR(unit);
1117
1118 memcpy(unit->baSourceID, &buffer[5], p);
1119
1120 uvc_entity_set_name(dev, unit, "Selector", buffer[5+p]);
1121
1122 list_add_tail(&unit->list, &dev->entities);
1123 break;
1124
1125 case UVC_VC_PROCESSING_UNIT:
1126 n = buflen >= 8 ? buffer[7] : 0;
1127 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1128
1129 if (buflen < p + n) {
1130 uvc_dbg(dev, DESCR,
1131 "device %d videocontrol interface %d PROCESSING_UNIT error\n",
1132 udev->devnum, alts->desc.bInterfaceNumber);
1133 return -EINVAL;
1134 }
1135
1136 unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3], 2, n);
1137 if (IS_ERR(unit))
1138 return PTR_ERR(unit);
1139
1140 memcpy(unit->baSourceID, &buffer[4], 1);
1141 unit->processing.wMaxMultiplier =
1142 get_unaligned_le16(&buffer[5]);
1143 unit->processing.bControlSize = buffer[7];
1144 unit->processing.bmControls = (u8 *)unit + sizeof(*unit);
1145 memcpy(unit->processing.bmControls, &buffer[8], n);
1146 if (dev->uvc_version >= 0x0110)
1147 unit->processing.bmVideoStandards = buffer[9+n];
1148
1149 uvc_entity_set_name(dev, unit, "Processing", buffer[8+n]);
1150
1151 list_add_tail(&unit->list, &dev->entities);
1152 break;
1153
1154 case UVC_VC_EXTENSION_UNIT:
1155 p = buflen >= 22 ? buffer[21] : 0;
1156 n = buflen >= 24 + p ? buffer[22+p] : 0;
1157
1158 if (buflen < 24 + p + n) {
1159 uvc_dbg(dev, DESCR,
1160 "device %d videocontrol interface %d EXTENSION_UNIT error\n",
1161 udev->devnum, alts->desc.bInterfaceNumber);
1162 return -EINVAL;
1163 }
1164
1165 unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3],
1166 p + 1, n);
1167 if (IS_ERR(unit))
1168 return PTR_ERR(unit);
1169
1170 memcpy(unit->guid, &buffer[4], 16);
1171 unit->extension.bNumControls = buffer[20];
1172 memcpy(unit->baSourceID, &buffer[22], p);
1173 unit->extension.bControlSize = buffer[22+p];
1174 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1175 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1176
1177 uvc_entity_set_name(dev, unit, "Extension", buffer[23+p+n]);
1178
1179 list_add_tail(&unit->list, &dev->entities);
1180 break;
1181
1182 default:
1183 uvc_dbg(dev, DESCR,
1184 "Found an unknown CS_INTERFACE descriptor (%u)\n",
1185 buffer[2]);
1186 break;
1187 }
1188
1189 return 0;
1190 }
1191
uvc_parse_control(struct uvc_device * dev)1192 static int uvc_parse_control(struct uvc_device *dev)
1193 {
1194 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1195 const unsigned char *buffer = alts->extra;
1196 int buflen = alts->extralen;
1197 int ret;
1198
1199 /*
1200 * Parse the default alternate setting only, as the UVC specification
1201 * defines a single alternate setting, the default alternate setting
1202 * zero.
1203 */
1204
1205 while (buflen > 2) {
1206 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1207 buffer[1] != USB_DT_CS_INTERFACE)
1208 goto next_descriptor;
1209
1210 ret = uvc_parse_standard_control(dev, buffer, buflen);
1211 if (ret < 0)
1212 return ret;
1213
1214 next_descriptor:
1215 buflen -= buffer[0];
1216 buffer += buffer[0];
1217 }
1218
1219 /*
1220 * Check if the optional status endpoint is present. Built-in iSight
1221 * webcams have an interrupt endpoint but spit proprietary data that
1222 * don't conform to the UVC status endpoint messages. Don't try to
1223 * handle the interrupt endpoint for those cameras.
1224 */
1225 if (alts->desc.bNumEndpoints == 1 &&
1226 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1227 struct usb_host_endpoint *ep = &alts->endpoint[0];
1228 struct usb_endpoint_descriptor *desc = &ep->desc;
1229
1230 if (usb_endpoint_is_int_in(desc) &&
1231 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1232 desc->bInterval != 0) {
1233 uvc_dbg(dev, DESCR,
1234 "Found a Status endpoint (addr %02x)\n",
1235 desc->bEndpointAddress);
1236 dev->int_ep = ep;
1237 }
1238 }
1239
1240 return 0;
1241 }
1242
1243 /* -----------------------------------------------------------------------------
1244 * Privacy GPIO
1245 */
1246
uvc_gpio_event(struct uvc_device * dev)1247 static void uvc_gpio_event(struct uvc_device *dev)
1248 {
1249 struct uvc_entity *unit = dev->gpio_unit;
1250 struct uvc_video_chain *chain;
1251 u8 new_val;
1252
1253 if (!unit)
1254 return;
1255
1256 new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy);
1257
1258 /* GPIO entities are always on the first chain. */
1259 chain = list_first_entry(&dev->chains, struct uvc_video_chain, list);
1260 uvc_ctrl_status_event(chain, unit->controls, &new_val);
1261 }
1262
uvc_gpio_get_cur(struct uvc_device * dev,struct uvc_entity * entity,u8 cs,void * data,u16 size)1263 static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
1264 u8 cs, void *data, u16 size)
1265 {
1266 if (cs != UVC_CT_PRIVACY_CONTROL || size < 1)
1267 return -EINVAL;
1268
1269 *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy);
1270
1271 return 0;
1272 }
1273
uvc_gpio_get_info(struct uvc_device * dev,struct uvc_entity * entity,u8 cs,u8 * caps)1274 static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity,
1275 u8 cs, u8 *caps)
1276 {
1277 if (cs != UVC_CT_PRIVACY_CONTROL)
1278 return -EINVAL;
1279
1280 *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE;
1281 return 0;
1282 }
1283
uvc_gpio_irq(int irq,void * data)1284 static irqreturn_t uvc_gpio_irq(int irq, void *data)
1285 {
1286 struct uvc_device *dev = data;
1287
1288 uvc_gpio_event(dev);
1289 return IRQ_HANDLED;
1290 }
1291
uvc_gpio_parse(struct uvc_device * dev)1292 static int uvc_gpio_parse(struct uvc_device *dev)
1293 {
1294 struct uvc_entity *unit;
1295 struct gpio_desc *gpio_privacy;
1296 int irq;
1297
1298 gpio_privacy = devm_gpiod_get_optional(&dev->udev->dev, "privacy",
1299 GPIOD_IN);
1300 if (IS_ERR_OR_NULL(gpio_privacy))
1301 return PTR_ERR_OR_ZERO(gpio_privacy);
1302
1303 irq = gpiod_to_irq(gpio_privacy);
1304 if (irq < 0)
1305 return dev_err_probe(&dev->udev->dev, irq,
1306 "No IRQ for privacy GPIO\n");
1307
1308 unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT,
1309 UVC_EXT_GPIO_UNIT_ID, 0, 1);
1310 if (IS_ERR(unit))
1311 return PTR_ERR(unit);
1312
1313 unit->gpio.gpio_privacy = gpio_privacy;
1314 unit->gpio.irq = irq;
1315 unit->gpio.bControlSize = 1;
1316 unit->gpio.bmControls = (u8 *)unit + sizeof(*unit);
1317 unit->gpio.bmControls[0] = 1;
1318 unit->get_cur = uvc_gpio_get_cur;
1319 unit->get_info = uvc_gpio_get_info;
1320 strscpy(unit->name, "GPIO", sizeof(unit->name));
1321
1322 list_add_tail(&unit->list, &dev->entities);
1323
1324 dev->gpio_unit = unit;
1325
1326 return 0;
1327 }
1328
uvc_gpio_init_irq(struct uvc_device * dev)1329 static int uvc_gpio_init_irq(struct uvc_device *dev)
1330 {
1331 struct uvc_entity *unit = dev->gpio_unit;
1332
1333 if (!unit || unit->gpio.irq < 0)
1334 return 0;
1335
1336 return devm_request_threaded_irq(&dev->udev->dev, unit->gpio.irq, NULL,
1337 uvc_gpio_irq,
1338 IRQF_ONESHOT | IRQF_TRIGGER_FALLING |
1339 IRQF_TRIGGER_RISING,
1340 "uvc_privacy_gpio", dev);
1341 }
1342
1343 /* ------------------------------------------------------------------------
1344 * UVC device scan
1345 */
1346
1347 /*
1348 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1349 * and containing the following units:
1350 *
1351 * - one or more Output Terminals (USB Streaming or Display)
1352 * - zero or one Processing Unit
1353 * - zero, one or more single-input Selector Units
1354 * - zero or one multiple-input Selector Units, provided all inputs are
1355 * connected to input terminals
1356 * - zero, one or mode single-input Extension Units
1357 * - one or more Input Terminals (Camera, External or USB Streaming)
1358 *
1359 * The terminal and units must match on of the following structures:
1360 *
1361 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1362 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1363 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1364 *
1365 * +---------+ +---------+ -> OTT_*(0)
1366 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1367 * +---------+ +---------+ -> OTT_*(n)
1368 *
1369 * The Processing Unit and Extension Units can be in any order. Additional
1370 * Extension Units connected to the main chain as single-unit branches are
1371 * also supported. Single-input Selector Units are ignored.
1372 */
uvc_scan_chain_entity(struct uvc_video_chain * chain,struct uvc_entity * entity)1373 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1374 struct uvc_entity *entity)
1375 {
1376 switch (UVC_ENTITY_TYPE(entity)) {
1377 case UVC_VC_EXTENSION_UNIT:
1378 uvc_dbg_cont(PROBE, " <- XU %d", entity->id);
1379
1380 if (entity->bNrInPins != 1) {
1381 uvc_dbg(chain->dev, DESCR,
1382 "Extension unit %d has more than 1 input pin\n",
1383 entity->id);
1384 return -1;
1385 }
1386
1387 break;
1388
1389 case UVC_VC_PROCESSING_UNIT:
1390 uvc_dbg_cont(PROBE, " <- PU %d", entity->id);
1391
1392 if (chain->processing != NULL) {
1393 uvc_dbg(chain->dev, DESCR,
1394 "Found multiple Processing Units in chain\n");
1395 return -1;
1396 }
1397
1398 chain->processing = entity;
1399 break;
1400
1401 case UVC_VC_SELECTOR_UNIT:
1402 uvc_dbg_cont(PROBE, " <- SU %d", entity->id);
1403
1404 /* Single-input selector units are ignored. */
1405 if (entity->bNrInPins == 1)
1406 break;
1407
1408 if (chain->selector != NULL) {
1409 uvc_dbg(chain->dev, DESCR,
1410 "Found multiple Selector Units in chain\n");
1411 return -1;
1412 }
1413
1414 chain->selector = entity;
1415 break;
1416
1417 case UVC_ITT_VENDOR_SPECIFIC:
1418 case UVC_ITT_CAMERA:
1419 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1420 uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
1421
1422 break;
1423
1424 case UVC_OTT_VENDOR_SPECIFIC:
1425 case UVC_OTT_DISPLAY:
1426 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1427 uvc_dbg_cont(PROBE, " OT %d", entity->id);
1428
1429 break;
1430
1431 case UVC_TT_STREAMING:
1432 if (UVC_ENTITY_IS_ITERM(entity))
1433 uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
1434 else
1435 uvc_dbg_cont(PROBE, " OT %d", entity->id);
1436
1437 break;
1438
1439 default:
1440 uvc_dbg(chain->dev, DESCR,
1441 "Unsupported entity type 0x%04x found in chain\n",
1442 UVC_ENTITY_TYPE(entity));
1443 return -1;
1444 }
1445
1446 list_add_tail(&entity->chain, &chain->entities);
1447 return 0;
1448 }
1449
uvc_scan_chain_forward(struct uvc_video_chain * chain,struct uvc_entity * entity,struct uvc_entity * prev)1450 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1451 struct uvc_entity *entity, struct uvc_entity *prev)
1452 {
1453 struct uvc_entity *forward;
1454 int found;
1455
1456 /* Forward scan */
1457 forward = NULL;
1458 found = 0;
1459
1460 while (1) {
1461 forward = uvc_entity_by_reference(chain->dev, entity->id,
1462 forward);
1463 if (forward == NULL)
1464 break;
1465 if (forward == prev)
1466 continue;
1467 if (forward->chain.next || forward->chain.prev) {
1468 uvc_dbg(chain->dev, DESCR,
1469 "Found reference to entity %d already in chain\n",
1470 forward->id);
1471 return -EINVAL;
1472 }
1473
1474 switch (UVC_ENTITY_TYPE(forward)) {
1475 case UVC_VC_EXTENSION_UNIT:
1476 if (forward->bNrInPins != 1) {
1477 uvc_dbg(chain->dev, DESCR,
1478 "Extension unit %d has more than 1 input pin\n",
1479 forward->id);
1480 return -EINVAL;
1481 }
1482
1483 /*
1484 * Some devices reference an output terminal as the
1485 * source of extension units. This is incorrect, as
1486 * output terminals only have an input pin, and thus
1487 * can't be connected to any entity in the forward
1488 * direction. The resulting topology would cause issues
1489 * when registering the media controller graph. To
1490 * avoid this problem, connect the extension unit to
1491 * the source of the output terminal instead.
1492 */
1493 if (UVC_ENTITY_IS_OTERM(entity)) {
1494 struct uvc_entity *source;
1495
1496 source = uvc_entity_by_id(chain->dev,
1497 entity->baSourceID[0]);
1498 if (!source) {
1499 uvc_dbg(chain->dev, DESCR,
1500 "Can't connect extension unit %u in chain\n",
1501 forward->id);
1502 break;
1503 }
1504
1505 forward->baSourceID[0] = source->id;
1506 }
1507
1508 list_add_tail(&forward->chain, &chain->entities);
1509 if (!found)
1510 uvc_dbg_cont(PROBE, " (->");
1511
1512 uvc_dbg_cont(PROBE, " XU %d", forward->id);
1513 found = 1;
1514 break;
1515
1516 case UVC_OTT_VENDOR_SPECIFIC:
1517 case UVC_OTT_DISPLAY:
1518 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1519 case UVC_TT_STREAMING:
1520 if (UVC_ENTITY_IS_ITERM(forward)) {
1521 uvc_dbg(chain->dev, DESCR,
1522 "Unsupported input terminal %u\n",
1523 forward->id);
1524 return -EINVAL;
1525 }
1526
1527 if (UVC_ENTITY_IS_OTERM(entity)) {
1528 uvc_dbg(chain->dev, DESCR,
1529 "Unsupported connection between output terminals %u and %u\n",
1530 entity->id, forward->id);
1531 break;
1532 }
1533
1534 list_add_tail(&forward->chain, &chain->entities);
1535 if (!found)
1536 uvc_dbg_cont(PROBE, " (->");
1537
1538 uvc_dbg_cont(PROBE, " OT %d", forward->id);
1539 found = 1;
1540 break;
1541 }
1542 }
1543 if (found)
1544 uvc_dbg_cont(PROBE, ")");
1545
1546 return 0;
1547 }
1548
uvc_scan_chain_backward(struct uvc_video_chain * chain,struct uvc_entity ** _entity)1549 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1550 struct uvc_entity **_entity)
1551 {
1552 struct uvc_entity *entity = *_entity;
1553 struct uvc_entity *term;
1554 int id = -EINVAL, i;
1555
1556 switch (UVC_ENTITY_TYPE(entity)) {
1557 case UVC_VC_EXTENSION_UNIT:
1558 case UVC_VC_PROCESSING_UNIT:
1559 id = entity->baSourceID[0];
1560 break;
1561
1562 case UVC_VC_SELECTOR_UNIT:
1563 /* Single-input selector units are ignored. */
1564 if (entity->bNrInPins == 1) {
1565 id = entity->baSourceID[0];
1566 break;
1567 }
1568
1569 uvc_dbg_cont(PROBE, " <- IT");
1570
1571 chain->selector = entity;
1572 for (i = 0; i < entity->bNrInPins; ++i) {
1573 id = entity->baSourceID[i];
1574 term = uvc_entity_by_id(chain->dev, id);
1575 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1576 uvc_dbg(chain->dev, DESCR,
1577 "Selector unit %d input %d isn't connected to an input terminal\n",
1578 entity->id, i);
1579 return -1;
1580 }
1581
1582 if (term->chain.next || term->chain.prev) {
1583 uvc_dbg(chain->dev, DESCR,
1584 "Found reference to entity %d already in chain\n",
1585 term->id);
1586 return -EINVAL;
1587 }
1588
1589 uvc_dbg_cont(PROBE, " %d", term->id);
1590
1591 list_add_tail(&term->chain, &chain->entities);
1592 uvc_scan_chain_forward(chain, term, entity);
1593 }
1594
1595 uvc_dbg_cont(PROBE, "\n");
1596
1597 id = 0;
1598 break;
1599
1600 case UVC_ITT_VENDOR_SPECIFIC:
1601 case UVC_ITT_CAMERA:
1602 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1603 case UVC_OTT_VENDOR_SPECIFIC:
1604 case UVC_OTT_DISPLAY:
1605 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1606 case UVC_TT_STREAMING:
1607 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1608 break;
1609 }
1610
1611 if (id <= 0) {
1612 *_entity = NULL;
1613 return id;
1614 }
1615
1616 entity = uvc_entity_by_id(chain->dev, id);
1617 if (entity == NULL) {
1618 uvc_dbg(chain->dev, DESCR,
1619 "Found reference to unknown entity %d\n", id);
1620 return -EINVAL;
1621 }
1622
1623 *_entity = entity;
1624 return 0;
1625 }
1626
uvc_scan_chain(struct uvc_video_chain * chain,struct uvc_entity * term)1627 static int uvc_scan_chain(struct uvc_video_chain *chain,
1628 struct uvc_entity *term)
1629 {
1630 struct uvc_entity *entity, *prev;
1631
1632 uvc_dbg(chain->dev, PROBE, "Scanning UVC chain:");
1633
1634 entity = term;
1635 prev = NULL;
1636
1637 while (entity != NULL) {
1638 /* Entity must not be part of an existing chain */
1639 if (entity->chain.next || entity->chain.prev) {
1640 uvc_dbg(chain->dev, DESCR,
1641 "Found reference to entity %d already in chain\n",
1642 entity->id);
1643 return -EINVAL;
1644 }
1645
1646 /* Process entity */
1647 if (uvc_scan_chain_entity(chain, entity) < 0)
1648 return -EINVAL;
1649
1650 /* Forward scan */
1651 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1652 return -EINVAL;
1653
1654 /* Backward scan */
1655 prev = entity;
1656 if (uvc_scan_chain_backward(chain, &entity) < 0)
1657 return -EINVAL;
1658 }
1659
1660 return 0;
1661 }
1662
uvc_print_terms(struct list_head * terms,u16 dir,char * buffer)1663 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1664 char *buffer)
1665 {
1666 struct uvc_entity *term;
1667 unsigned int nterms = 0;
1668 char *p = buffer;
1669
1670 list_for_each_entry(term, terms, chain) {
1671 if (!UVC_ENTITY_IS_TERM(term) ||
1672 UVC_TERM_DIRECTION(term) != dir)
1673 continue;
1674
1675 if (nterms)
1676 p += sprintf(p, ",");
1677 if (++nterms >= 4) {
1678 p += sprintf(p, "...");
1679 break;
1680 }
1681 p += sprintf(p, "%u", term->id);
1682 }
1683
1684 return p - buffer;
1685 }
1686
uvc_print_chain(struct uvc_video_chain * chain)1687 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1688 {
1689 static char buffer[43];
1690 char *p = buffer;
1691
1692 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1693 p += sprintf(p, " -> ");
1694 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1695
1696 return buffer;
1697 }
1698
uvc_alloc_chain(struct uvc_device * dev)1699 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1700 {
1701 struct uvc_video_chain *chain;
1702
1703 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1704 if (chain == NULL)
1705 return NULL;
1706
1707 INIT_LIST_HEAD(&chain->entities);
1708 mutex_init(&chain->ctrl_mutex);
1709 chain->dev = dev;
1710 v4l2_prio_init(&chain->prio);
1711
1712 return chain;
1713 }
1714
1715 /*
1716 * Fallback heuristic for devices that don't connect units and terminals in a
1717 * valid chain.
1718 *
1719 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1720 * to fail, but if we just take the entities we can find and put them together
1721 * in the most sensible chain we can think of, turns out they do work anyway.
1722 * Note: This heuristic assumes there is a single chain.
1723 *
1724 * At the time of writing, devices known to have such a broken chain are
1725 * - Acer Integrated Camera (5986:055a)
1726 * - Realtek rtl157a7 (0bda:57a7)
1727 */
uvc_scan_fallback(struct uvc_device * dev)1728 static int uvc_scan_fallback(struct uvc_device *dev)
1729 {
1730 struct uvc_video_chain *chain;
1731 struct uvc_entity *iterm = NULL;
1732 struct uvc_entity *oterm = NULL;
1733 struct uvc_entity *entity;
1734 struct uvc_entity *prev;
1735
1736 /*
1737 * Start by locating the input and output terminals. We only support
1738 * devices with exactly one of each for now.
1739 */
1740 list_for_each_entry(entity, &dev->entities, list) {
1741 if (UVC_ENTITY_IS_ITERM(entity)) {
1742 if (iterm)
1743 return -EINVAL;
1744 iterm = entity;
1745 }
1746
1747 if (UVC_ENTITY_IS_OTERM(entity)) {
1748 if (oterm)
1749 return -EINVAL;
1750 oterm = entity;
1751 }
1752 }
1753
1754 if (iterm == NULL || oterm == NULL)
1755 return -EINVAL;
1756
1757 /* Allocate the chain and fill it. */
1758 chain = uvc_alloc_chain(dev);
1759 if (chain == NULL)
1760 return -ENOMEM;
1761
1762 if (uvc_scan_chain_entity(chain, oterm) < 0)
1763 goto error;
1764
1765 prev = oterm;
1766
1767 /*
1768 * Add all Processing and Extension Units with two pads. The order
1769 * doesn't matter much, use reverse list traversal to connect units in
1770 * UVC descriptor order as we build the chain from output to input. This
1771 * leads to units appearing in the order meant by the manufacturer for
1772 * the cameras known to require this heuristic.
1773 */
1774 list_for_each_entry_reverse(entity, &dev->entities, list) {
1775 if (entity->type != UVC_VC_PROCESSING_UNIT &&
1776 entity->type != UVC_VC_EXTENSION_UNIT)
1777 continue;
1778
1779 if (entity->num_pads != 2)
1780 continue;
1781
1782 if (uvc_scan_chain_entity(chain, entity) < 0)
1783 goto error;
1784
1785 prev->baSourceID[0] = entity->id;
1786 prev = entity;
1787 }
1788
1789 if (uvc_scan_chain_entity(chain, iterm) < 0)
1790 goto error;
1791
1792 prev->baSourceID[0] = iterm->id;
1793
1794 list_add_tail(&chain->list, &dev->chains);
1795
1796 uvc_dbg(dev, PROBE, "Found a video chain by fallback heuristic (%s)\n",
1797 uvc_print_chain(chain));
1798
1799 return 0;
1800
1801 error:
1802 kfree(chain);
1803 return -EINVAL;
1804 }
1805
1806 /*
1807 * Scan the device for video chains and register video devices.
1808 *
1809 * Chains are scanned starting at their output terminals and walked backwards.
1810 */
uvc_scan_device(struct uvc_device * dev)1811 static int uvc_scan_device(struct uvc_device *dev)
1812 {
1813 struct uvc_video_chain *chain;
1814 struct uvc_entity *term;
1815
1816 list_for_each_entry(term, &dev->entities, list) {
1817 if (!UVC_ENTITY_IS_OTERM(term))
1818 continue;
1819
1820 /*
1821 * If the terminal is already included in a chain, skip it.
1822 * This can happen for chains that have multiple output
1823 * terminals, where all output terminals beside the first one
1824 * will be inserted in the chain in forward scans.
1825 */
1826 if (term->chain.next || term->chain.prev)
1827 continue;
1828
1829 chain = uvc_alloc_chain(dev);
1830 if (chain == NULL)
1831 return -ENOMEM;
1832
1833 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1834
1835 if (uvc_scan_chain(chain, term) < 0) {
1836 kfree(chain);
1837 continue;
1838 }
1839
1840 uvc_dbg(dev, PROBE, "Found a valid video chain (%s)\n",
1841 uvc_print_chain(chain));
1842
1843 list_add_tail(&chain->list, &dev->chains);
1844 }
1845
1846 if (list_empty(&dev->chains))
1847 uvc_scan_fallback(dev);
1848
1849 if (list_empty(&dev->chains)) {
1850 dev_info(&dev->udev->dev, "No valid video chain found.\n");
1851 return -1;
1852 }
1853
1854 /* Add GPIO entity to the first chain. */
1855 if (dev->gpio_unit) {
1856 chain = list_first_entry(&dev->chains,
1857 struct uvc_video_chain, list);
1858 list_add_tail(&dev->gpio_unit->chain, &chain->entities);
1859 }
1860
1861 return 0;
1862 }
1863
1864 /* ------------------------------------------------------------------------
1865 * Video device registration and unregistration
1866 */
1867
1868 /*
1869 * Delete the UVC device.
1870 *
1871 * Called by the kernel when the last reference to the uvc_device structure
1872 * is released.
1873 *
1874 * As this function is called after or during disconnect(), all URBs have
1875 * already been cancelled by the USB core. There is no need to kill the
1876 * interrupt URB manually.
1877 */
uvc_delete(struct kref * kref)1878 static void uvc_delete(struct kref *kref)
1879 {
1880 struct uvc_device *dev = container_of(kref, struct uvc_device, ref);
1881 struct list_head *p, *n;
1882
1883 uvc_status_cleanup(dev);
1884 uvc_ctrl_cleanup_device(dev);
1885
1886 usb_put_intf(dev->intf);
1887 usb_put_dev(dev->udev);
1888
1889 #ifdef CONFIG_MEDIA_CONTROLLER
1890 media_device_cleanup(&dev->mdev);
1891 #endif
1892
1893 list_for_each_safe(p, n, &dev->chains) {
1894 struct uvc_video_chain *chain;
1895
1896 chain = list_entry(p, struct uvc_video_chain, list);
1897 kfree(chain);
1898 }
1899
1900 list_for_each_safe(p, n, &dev->entities) {
1901 struct uvc_entity *entity;
1902
1903 entity = list_entry(p, struct uvc_entity, list);
1904 #ifdef CONFIG_MEDIA_CONTROLLER
1905 uvc_mc_cleanup_entity(entity);
1906 #endif
1907 kfree(entity);
1908 }
1909
1910 list_for_each_safe(p, n, &dev->streams) {
1911 struct uvc_streaming *streaming;
1912
1913 streaming = list_entry(p, struct uvc_streaming, list);
1914 usb_driver_release_interface(&uvc_driver.driver,
1915 streaming->intf);
1916 uvc_stream_delete(streaming);
1917 }
1918
1919 kfree(dev);
1920 }
1921
uvc_release(struct video_device * vdev)1922 static void uvc_release(struct video_device *vdev)
1923 {
1924 struct uvc_streaming *stream = video_get_drvdata(vdev);
1925 struct uvc_device *dev = stream->dev;
1926
1927 kref_put(&dev->ref, uvc_delete);
1928 }
1929
1930 /*
1931 * Unregister the video devices.
1932 */
uvc_unregister_video(struct uvc_device * dev)1933 static void uvc_unregister_video(struct uvc_device *dev)
1934 {
1935 struct uvc_streaming *stream;
1936
1937 list_for_each_entry(stream, &dev->streams, list) {
1938 /* Nothing to do here, continue. */
1939 if (!video_is_registered(&stream->vdev))
1940 continue;
1941
1942 /*
1943 * For stream->vdev we follow the same logic as:
1944 * vb2_video_unregister_device().
1945 */
1946
1947 /* 1. Take a reference to vdev */
1948 get_device(&stream->vdev.dev);
1949
1950 /* 2. Ensure that no new ioctls can be called. */
1951 video_unregister_device(&stream->vdev);
1952
1953 /* 3. Wait for old ioctls to finish. */
1954 mutex_lock(&stream->mutex);
1955
1956 /* 4. Stop streaming. */
1957 uvc_queue_release(&stream->queue);
1958
1959 mutex_unlock(&stream->mutex);
1960
1961 put_device(&stream->vdev.dev);
1962
1963 /*
1964 * For stream->meta.vdev we can directly call:
1965 * vb2_video_unregister_device().
1966 */
1967 vb2_video_unregister_device(&stream->meta.vdev);
1968
1969 /*
1970 * Now both vdevs are not streaming and all the ioctls will
1971 * return -ENODEV.
1972 */
1973
1974 uvc_debugfs_cleanup_stream(stream);
1975 }
1976
1977 uvc_status_unregister(dev);
1978
1979 if (dev->vdev.dev)
1980 v4l2_device_unregister(&dev->vdev);
1981 #ifdef CONFIG_MEDIA_CONTROLLER
1982 if (media_devnode_is_registered(dev->mdev.devnode))
1983 media_device_unregister(&dev->mdev);
1984 #endif
1985 }
1986
uvc_register_video_device(struct uvc_device * dev,struct uvc_streaming * stream,struct video_device * vdev,struct uvc_video_queue * queue,enum v4l2_buf_type type,const struct v4l2_file_operations * fops,const struct v4l2_ioctl_ops * ioctl_ops)1987 int uvc_register_video_device(struct uvc_device *dev,
1988 struct uvc_streaming *stream,
1989 struct video_device *vdev,
1990 struct uvc_video_queue *queue,
1991 enum v4l2_buf_type type,
1992 const struct v4l2_file_operations *fops,
1993 const struct v4l2_ioctl_ops *ioctl_ops)
1994 {
1995 int ret;
1996
1997 /* Initialize the video buffers queue. */
1998 ret = uvc_queue_init(queue, type, !uvc_no_drop_param);
1999 if (ret)
2000 return ret;
2001
2002 /* Register the device with V4L. */
2003
2004 /*
2005 * We already hold a reference to dev->udev. The video device will be
2006 * unregistered before the reference is released, so we don't need to
2007 * get another one.
2008 */
2009 vdev->v4l2_dev = &dev->vdev;
2010 vdev->fops = fops;
2011 vdev->ioctl_ops = ioctl_ops;
2012 vdev->release = uvc_release;
2013 vdev->prio = &stream->chain->prio;
2014 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
2015 vdev->vfl_dir = VFL_DIR_TX;
2016 else
2017 vdev->vfl_dir = VFL_DIR_RX;
2018
2019 switch (type) {
2020 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2021 default:
2022 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
2023 break;
2024 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2025 vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
2026 break;
2027 case V4L2_BUF_TYPE_META_CAPTURE:
2028 vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING;
2029 break;
2030 }
2031
2032 strscpy(vdev->name, dev->name, sizeof(vdev->name));
2033
2034 /*
2035 * Set the driver data before calling video_register_device, otherwise
2036 * the file open() handler might race us.
2037 */
2038 video_set_drvdata(vdev, stream);
2039
2040 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
2041 if (ret < 0) {
2042 dev_err(&stream->intf->dev,
2043 "Failed to register %s device (%d).\n",
2044 v4l2_type_names[type], ret);
2045 return ret;
2046 }
2047
2048 kref_get(&dev->ref);
2049 return 0;
2050 }
2051
uvc_register_video(struct uvc_device * dev,struct uvc_streaming * stream)2052 static int uvc_register_video(struct uvc_device *dev,
2053 struct uvc_streaming *stream)
2054 {
2055 int ret;
2056
2057 /* Initialize the streaming interface with default parameters. */
2058 ret = uvc_video_init(stream);
2059 if (ret < 0) {
2060 dev_err(&stream->intf->dev,
2061 "Failed to initialize the device (%d).\n", ret);
2062 return ret;
2063 }
2064
2065 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2066 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE
2067 | V4L2_CAP_META_CAPTURE;
2068 else
2069 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
2070
2071 uvc_debugfs_init_stream(stream);
2072
2073 /* Register the device with V4L. */
2074 return uvc_register_video_device(dev, stream, &stream->vdev,
2075 &stream->queue, stream->type,
2076 &uvc_fops, &uvc_ioctl_ops);
2077 }
2078
2079 /*
2080 * Register all video devices in all chains.
2081 */
uvc_register_terms(struct uvc_device * dev,struct uvc_video_chain * chain)2082 static int uvc_register_terms(struct uvc_device *dev,
2083 struct uvc_video_chain *chain)
2084 {
2085 struct uvc_streaming *stream;
2086 struct uvc_entity *term;
2087 int ret;
2088
2089 list_for_each_entry(term, &chain->entities, chain) {
2090 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
2091 continue;
2092
2093 stream = uvc_stream_by_id(dev, term->id);
2094 if (stream == NULL) {
2095 dev_info(&dev->udev->dev,
2096 "No streaming interface found for terminal %u.",
2097 term->id);
2098 continue;
2099 }
2100
2101 stream->chain = chain;
2102 ret = uvc_register_video(dev, stream);
2103 if (ret < 0)
2104 return ret;
2105
2106 /*
2107 * Register a metadata node, but ignore a possible failure,
2108 * complete registration of video nodes anyway.
2109 */
2110 uvc_meta_register(stream);
2111
2112 term->vdev = &stream->vdev;
2113 }
2114
2115 return 0;
2116 }
2117
uvc_register_chains(struct uvc_device * dev)2118 static int uvc_register_chains(struct uvc_device *dev)
2119 {
2120 struct uvc_video_chain *chain;
2121 int ret;
2122
2123 list_for_each_entry(chain, &dev->chains, list) {
2124 ret = uvc_register_terms(dev, chain);
2125 if (ret < 0)
2126 return ret;
2127
2128 #ifdef CONFIG_MEDIA_CONTROLLER
2129 ret = uvc_mc_register_entities(chain);
2130 if (ret < 0)
2131 dev_info(&dev->udev->dev,
2132 "Failed to register entities (%d).\n", ret);
2133 #endif
2134 }
2135
2136 return 0;
2137 }
2138
2139 /* ------------------------------------------------------------------------
2140 * USB probe, disconnect, suspend and resume
2141 */
2142
2143 static const struct uvc_device_info uvc_quirk_none = { 0 };
2144
uvc_probe(struct usb_interface * intf,const struct usb_device_id * id)2145 static int uvc_probe(struct usb_interface *intf,
2146 const struct usb_device_id *id)
2147 {
2148 struct usb_device *udev = interface_to_usbdev(intf);
2149 struct uvc_device *dev;
2150 const struct uvc_device_info *info =
2151 (const struct uvc_device_info *)id->driver_info;
2152 int function;
2153 int ret;
2154
2155 /* Allocate memory for the device and initialize it. */
2156 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2157 if (dev == NULL)
2158 return -ENOMEM;
2159
2160 INIT_LIST_HEAD(&dev->entities);
2161 INIT_LIST_HEAD(&dev->chains);
2162 INIT_LIST_HEAD(&dev->streams);
2163 kref_init(&dev->ref);
2164 atomic_set(&dev->nmappings, 0);
2165 mutex_init(&dev->lock);
2166
2167 dev->udev = usb_get_dev(udev);
2168 dev->intf = usb_get_intf(intf);
2169 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2170 dev->info = info ? info : &uvc_quirk_none;
2171 dev->quirks = uvc_quirks_param == -1
2172 ? dev->info->quirks : uvc_quirks_param;
2173
2174 if (id->idVendor && id->idProduct)
2175 uvc_dbg(dev, PROBE, "Probing known UVC device %s (%04x:%04x)\n",
2176 udev->devpath, id->idVendor, id->idProduct);
2177 else
2178 uvc_dbg(dev, PROBE, "Probing generic UVC device %s\n",
2179 udev->devpath);
2180
2181 if (udev->product != NULL)
2182 strscpy(dev->name, udev->product, sizeof(dev->name));
2183 else
2184 snprintf(dev->name, sizeof(dev->name),
2185 "UVC Camera (%04x:%04x)",
2186 le16_to_cpu(udev->descriptor.idVendor),
2187 le16_to_cpu(udev->descriptor.idProduct));
2188
2189 /*
2190 * Add iFunction or iInterface to names when available as additional
2191 * distinguishers between interfaces. iFunction is prioritized over
2192 * iInterface which matches Windows behavior at the point of writing.
2193 */
2194 if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
2195 function = intf->intf_assoc->iFunction;
2196 else
2197 function = intf->cur_altsetting->desc.iInterface;
2198 if (function != 0) {
2199 size_t len;
2200
2201 strlcat(dev->name, ": ", sizeof(dev->name));
2202 len = strlen(dev->name);
2203 usb_string(udev, function, dev->name + len,
2204 sizeof(dev->name) - len);
2205 }
2206
2207 /* Initialize the media device. */
2208 #ifdef CONFIG_MEDIA_CONTROLLER
2209 dev->mdev.dev = &intf->dev;
2210 strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2211 if (udev->serial)
2212 strscpy(dev->mdev.serial, udev->serial,
2213 sizeof(dev->mdev.serial));
2214 usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2215 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2216 media_device_init(&dev->mdev);
2217
2218 dev->vdev.mdev = &dev->mdev;
2219 #endif
2220
2221 /* Parse the Video Class control descriptor. */
2222 if (uvc_parse_control(dev) < 0) {
2223 uvc_dbg(dev, PROBE, "Unable to parse UVC descriptors\n");
2224 goto error;
2225 }
2226
2227 /* Parse the associated GPIOs. */
2228 if (uvc_gpio_parse(dev) < 0) {
2229 uvc_dbg(dev, PROBE, "Unable to parse UVC GPIOs\n");
2230 goto error;
2231 }
2232
2233 dev_info(&dev->udev->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2234 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2235 udev->product ? udev->product : "<unnamed>",
2236 le16_to_cpu(udev->descriptor.idVendor),
2237 le16_to_cpu(udev->descriptor.idProduct));
2238
2239 if (dev->quirks != dev->info->quirks) {
2240 dev_info(&dev->udev->dev,
2241 "Forcing device quirks to 0x%x by module parameter for testing purpose.\n",
2242 dev->quirks);
2243 dev_info(&dev->udev->dev,
2244 "Please report required quirks to the linux-media mailing list.\n");
2245 }
2246
2247 if (dev->info->uvc_version) {
2248 dev->uvc_version = dev->info->uvc_version;
2249 dev_info(&dev->udev->dev, "Forcing UVC version to %u.%02x\n",
2250 dev->uvc_version >> 8, dev->uvc_version & 0xff);
2251 }
2252
2253 /* Register the V4L2 device. */
2254 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2255 goto error;
2256
2257 /* Scan the device for video chains. */
2258 if (uvc_scan_device(dev) < 0)
2259 goto error;
2260
2261 /* Initialize controls. */
2262 if (uvc_ctrl_init_device(dev) < 0)
2263 goto error;
2264
2265 /* Register video device nodes. */
2266 if (uvc_register_chains(dev) < 0)
2267 goto error;
2268
2269 #ifdef CONFIG_MEDIA_CONTROLLER
2270 /* Register the media device node */
2271 if (media_device_register(&dev->mdev) < 0)
2272 goto error;
2273 #endif
2274 /* Save our data pointer in the interface data. */
2275 usb_set_intfdata(intf, dev);
2276
2277 /* Initialize the interrupt URB. */
2278 ret = uvc_status_init(dev);
2279 if (ret < 0) {
2280 dev_info(&dev->udev->dev,
2281 "Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n",
2282 ret);
2283 }
2284
2285 ret = uvc_gpio_init_irq(dev);
2286 if (ret < 0) {
2287 dev_err(&dev->udev->dev,
2288 "Unable to request privacy GPIO IRQ (%d)\n", ret);
2289 goto error;
2290 }
2291
2292 if (dev->quirks & UVC_QUIRK_NO_RESET_RESUME)
2293 udev->quirks &= ~USB_QUIRK_RESET_RESUME;
2294
2295 if (!(dev->quirks & UVC_QUIRK_DISABLE_AUTOSUSPEND))
2296 usb_enable_autosuspend(udev);
2297
2298 uvc_dbg(dev, PROBE, "UVC device initialized\n");
2299
2300 return 0;
2301
2302 error:
2303 uvc_unregister_video(dev);
2304 kref_put(&dev->ref, uvc_delete);
2305 return -ENODEV;
2306 }
2307
uvc_disconnect(struct usb_interface * intf)2308 static void uvc_disconnect(struct usb_interface *intf)
2309 {
2310 struct uvc_device *dev = usb_get_intfdata(intf);
2311
2312 /*
2313 * Set the USB interface data to NULL. This can be done outside the
2314 * lock, as there's no other reader.
2315 */
2316 usb_set_intfdata(intf, NULL);
2317
2318 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2319 UVC_SC_VIDEOSTREAMING)
2320 return;
2321
2322 uvc_unregister_video(dev);
2323 kref_put(&dev->ref, uvc_delete);
2324 }
2325
uvc_suspend(struct usb_interface * intf,pm_message_t message)2326 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2327 {
2328 struct uvc_device *dev = usb_get_intfdata(intf);
2329 struct uvc_streaming *stream;
2330
2331 uvc_dbg(dev, SUSPEND, "Suspending interface %u\n",
2332 intf->cur_altsetting->desc.bInterfaceNumber);
2333
2334 /* Controls are cached on the fly so they don't need to be saved. */
2335 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2336 UVC_SC_VIDEOCONTROL) {
2337 mutex_lock(&dev->lock);
2338 if (dev->users)
2339 uvc_status_stop(dev);
2340 mutex_unlock(&dev->lock);
2341 return 0;
2342 }
2343
2344 list_for_each_entry(stream, &dev->streams, list) {
2345 if (stream->intf == intf)
2346 return uvc_video_suspend(stream);
2347 }
2348
2349 uvc_dbg(dev, SUSPEND,
2350 "Suspend: video streaming USB interface mismatch\n");
2351 return -EINVAL;
2352 }
2353
__uvc_resume(struct usb_interface * intf,int reset)2354 static int __uvc_resume(struct usb_interface *intf, int reset)
2355 {
2356 struct uvc_device *dev = usb_get_intfdata(intf);
2357 struct uvc_streaming *stream;
2358 int ret = 0;
2359
2360 uvc_dbg(dev, SUSPEND, "Resuming interface %u\n",
2361 intf->cur_altsetting->desc.bInterfaceNumber);
2362
2363 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2364 UVC_SC_VIDEOCONTROL) {
2365 if (reset) {
2366 ret = uvc_ctrl_restore_values(dev);
2367 if (ret < 0)
2368 return ret;
2369 }
2370
2371 mutex_lock(&dev->lock);
2372 if (dev->users)
2373 ret = uvc_status_start(dev, GFP_NOIO);
2374 mutex_unlock(&dev->lock);
2375
2376 return ret;
2377 }
2378
2379 list_for_each_entry(stream, &dev->streams, list) {
2380 if (stream->intf == intf) {
2381 ret = uvc_video_resume(stream, reset);
2382 if (ret < 0)
2383 uvc_queue_streamoff(&stream->queue,
2384 stream->queue.queue.type);
2385 return ret;
2386 }
2387 }
2388
2389 uvc_dbg(dev, SUSPEND,
2390 "Resume: video streaming USB interface mismatch\n");
2391 return -EINVAL;
2392 }
2393
uvc_resume(struct usb_interface * intf)2394 static int uvc_resume(struct usb_interface *intf)
2395 {
2396 return __uvc_resume(intf, 0);
2397 }
2398
uvc_reset_resume(struct usb_interface * intf)2399 static int uvc_reset_resume(struct usb_interface *intf)
2400 {
2401 return __uvc_resume(intf, 1);
2402 }
2403
2404 /* ------------------------------------------------------------------------
2405 * Module parameters
2406 */
2407
uvc_clock_param_get(char * buffer,const struct kernel_param * kp)2408 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2409 {
2410 if (uvc_clock_param == CLOCK_MONOTONIC)
2411 return sprintf(buffer, "CLOCK_MONOTONIC");
2412 else
2413 return sprintf(buffer, "CLOCK_REALTIME");
2414 }
2415
uvc_clock_param_set(const char * val,const struct kernel_param * kp)2416 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2417 {
2418 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2419 val += strlen("clock_");
2420
2421 if (strcasecmp(val, "monotonic") == 0)
2422 uvc_clock_param = CLOCK_MONOTONIC;
2423 else if (strcasecmp(val, "realtime") == 0)
2424 uvc_clock_param = CLOCK_REALTIME;
2425 else
2426 return -EINVAL;
2427
2428 return 0;
2429 }
2430
2431 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2432 &uvc_clock_param, 0644);
2433 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2434 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, 0644);
2435 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2436 module_param_named(nodrop, uvc_no_drop_param, uint, 0644);
2437 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2438 module_param_named(quirks, uvc_quirks_param, uint, 0644);
2439 MODULE_PARM_DESC(quirks, "Forced device quirks");
2440 module_param_named(trace, uvc_dbg_param, uint, 0644);
2441 MODULE_PARM_DESC(trace, "Trace level bitmask");
2442 module_param_named(timeout, uvc_timeout_param, uint, 0644);
2443 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2444
2445 /* ------------------------------------------------------------------------
2446 * Driver initialization and cleanup
2447 */
2448
2449 static const struct uvc_device_info uvc_ctrl_power_line_limited = {
2450 .mappings = (const struct uvc_control_mapping *[]) {
2451 &uvc_ctrl_power_line_mapping_limited,
2452 NULL, /* Sentinel */
2453 },
2454 };
2455
2456 static const struct uvc_device_info uvc_ctrl_power_line_uvc11 = {
2457 .mappings = (const struct uvc_control_mapping *[]) {
2458 &uvc_ctrl_power_line_mapping_uvc11,
2459 NULL, /* Sentinel */
2460 },
2461 };
2462
2463 static const struct uvc_device_info uvc_quirk_probe_minmax = {
2464 .quirks = UVC_QUIRK_PROBE_MINMAX,
2465 };
2466
2467 static const struct uvc_device_info uvc_quirk_fix_bandwidth = {
2468 .quirks = UVC_QUIRK_FIX_BANDWIDTH,
2469 };
2470
2471 static const struct uvc_device_info uvc_quirk_probe_def = {
2472 .quirks = UVC_QUIRK_PROBE_DEF,
2473 };
2474
2475 static const struct uvc_device_info uvc_quirk_stream_no_fid = {
2476 .quirks = UVC_QUIRK_STREAM_NO_FID,
2477 };
2478
2479 static const struct uvc_device_info uvc_quirk_force_y8 = {
2480 .quirks = UVC_QUIRK_FORCE_Y8,
2481 };
2482
2483 #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q}
2484 #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \
2485 {.meta_format = m}
2486
2487 /*
2488 * The Logitech cameras listed below have their interface class set to
2489 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2490 * though they are compliant.
2491 *
2492 * Sort these by vendor/product ID.
2493 */
2494 static const struct usb_device_id uvc_ids[] = {
2495 /* Quanta USB2.0 HD UVC Webcam */
2496 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2497 | USB_DEVICE_ID_MATCH_INT_INFO,
2498 .idVendor = 0x0408,
2499 .idProduct = 0x3090,
2500 .bInterfaceClass = USB_CLASS_VIDEO,
2501 .bInterfaceSubClass = 1,
2502 .bInterfaceProtocol = 0,
2503 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2504 /* Quanta USB2.0 HD UVC Webcam */
2505 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2506 | USB_DEVICE_ID_MATCH_INT_INFO,
2507 .idVendor = 0x0408,
2508 .idProduct = 0x4030,
2509 .bInterfaceClass = USB_CLASS_VIDEO,
2510 .bInterfaceSubClass = 1,
2511 .bInterfaceProtocol = 0,
2512 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2513 /* Quanta USB2.0 HD UVC Webcam */
2514 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2515 | USB_DEVICE_ID_MATCH_INT_INFO,
2516 .idVendor = 0x0408,
2517 .idProduct = 0x4034,
2518 .bInterfaceClass = USB_CLASS_VIDEO,
2519 .bInterfaceSubClass = 1,
2520 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2521 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2522 /* LogiLink Wireless Webcam */
2523 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2524 | USB_DEVICE_ID_MATCH_INT_INFO,
2525 .idVendor = 0x0416,
2526 .idProduct = 0xa91a,
2527 .bInterfaceClass = USB_CLASS_VIDEO,
2528 .bInterfaceSubClass = 1,
2529 .bInterfaceProtocol = 0,
2530 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2531 /* Genius eFace 2025 */
2532 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2533 | USB_DEVICE_ID_MATCH_INT_INFO,
2534 .idVendor = 0x0458,
2535 .idProduct = 0x706e,
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-6000 */
2541 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2542 | USB_DEVICE_ID_MATCH_INT_INFO,
2543 .idVendor = 0x045e,
2544 .idProduct = 0x00f8,
2545 .bInterfaceClass = USB_CLASS_VIDEO,
2546 .bInterfaceSubClass = 1,
2547 .bInterfaceProtocol = 0,
2548 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2549 /* Microsoft Lifecam NX-3000 */
2550 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2551 | USB_DEVICE_ID_MATCH_INT_INFO,
2552 .idVendor = 0x045e,
2553 .idProduct = 0x0721,
2554 .bInterfaceClass = USB_CLASS_VIDEO,
2555 .bInterfaceSubClass = 1,
2556 .bInterfaceProtocol = 0,
2557 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2558 /* Microsoft Lifecam VX-7000 */
2559 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2560 | USB_DEVICE_ID_MATCH_INT_INFO,
2561 .idVendor = 0x045e,
2562 .idProduct = 0x0723,
2563 .bInterfaceClass = USB_CLASS_VIDEO,
2564 .bInterfaceSubClass = 1,
2565 .bInterfaceProtocol = 0,
2566 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2567 /* Logitech, Webcam C910 */
2568 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2569 | USB_DEVICE_ID_MATCH_INT_INFO,
2570 .idVendor = 0x046d,
2571 .idProduct = 0x0821,
2572 .bInterfaceClass = USB_CLASS_VIDEO,
2573 .bInterfaceSubClass = 1,
2574 .bInterfaceProtocol = 0,
2575 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
2576 /* Logitech, Webcam B910 */
2577 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2578 | USB_DEVICE_ID_MATCH_INT_INFO,
2579 .idVendor = 0x046d,
2580 .idProduct = 0x0823,
2581 .bInterfaceClass = USB_CLASS_VIDEO,
2582 .bInterfaceSubClass = 1,
2583 .bInterfaceProtocol = 0,
2584 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
2585 /* Logitech Quickcam Fusion */
2586 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2587 | USB_DEVICE_ID_MATCH_INT_INFO,
2588 .idVendor = 0x046d,
2589 .idProduct = 0x08c1,
2590 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2591 .bInterfaceSubClass = 1,
2592 .bInterfaceProtocol = 0 },
2593 /* Logitech Quickcam Orbit MP */
2594 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2595 | USB_DEVICE_ID_MATCH_INT_INFO,
2596 .idVendor = 0x046d,
2597 .idProduct = 0x08c2,
2598 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2599 .bInterfaceSubClass = 1,
2600 .bInterfaceProtocol = 0 },
2601 /* Logitech Quickcam Pro for Notebook */
2602 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2603 | USB_DEVICE_ID_MATCH_INT_INFO,
2604 .idVendor = 0x046d,
2605 .idProduct = 0x08c3,
2606 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2607 .bInterfaceSubClass = 1,
2608 .bInterfaceProtocol = 0 },
2609 /* Logitech Quickcam Pro 5000 */
2610 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2611 | USB_DEVICE_ID_MATCH_INT_INFO,
2612 .idVendor = 0x046d,
2613 .idProduct = 0x08c5,
2614 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2615 .bInterfaceSubClass = 1,
2616 .bInterfaceProtocol = 0 },
2617 /* Logitech Quickcam OEM Dell Notebook */
2618 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2619 | USB_DEVICE_ID_MATCH_INT_INFO,
2620 .idVendor = 0x046d,
2621 .idProduct = 0x08c6,
2622 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2623 .bInterfaceSubClass = 1,
2624 .bInterfaceProtocol = 0 },
2625 /* Logitech Quickcam OEM Cisco VT Camera II */
2626 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2627 | USB_DEVICE_ID_MATCH_INT_INFO,
2628 .idVendor = 0x046d,
2629 .idProduct = 0x08c7,
2630 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2631 .bInterfaceSubClass = 1,
2632 .bInterfaceProtocol = 0 },
2633 /* Logitech HD Pro Webcam C920 */
2634 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2635 | USB_DEVICE_ID_MATCH_INT_INFO,
2636 .idVendor = 0x046d,
2637 .idProduct = 0x082d,
2638 .bInterfaceClass = USB_CLASS_VIDEO,
2639 .bInterfaceSubClass = 1,
2640 .bInterfaceProtocol = 0,
2641 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT
2642 | UVC_QUIRK_INVALID_DEVICE_SOF) },
2643 /* Logitech HD Pro Webcam C922 */
2644 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2645 | USB_DEVICE_ID_MATCH_INT_INFO,
2646 .idVendor = 0x046d,
2647 .idProduct = 0x085c,
2648 .bInterfaceClass = USB_CLASS_VIDEO,
2649 .bInterfaceSubClass = 1,
2650 .bInterfaceProtocol = 0,
2651 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_INVALID_DEVICE_SOF) },
2652 /* Logitech Rally Bar Huddle */
2653 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2654 | USB_DEVICE_ID_MATCH_INT_INFO,
2655 .idVendor = 0x046d,
2656 .idProduct = 0x087c,
2657 .bInterfaceClass = USB_CLASS_VIDEO,
2658 .bInterfaceSubClass = 1,
2659 .bInterfaceProtocol = 0,
2660 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
2661 /* Logitech Rally Bar */
2662 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2663 | USB_DEVICE_ID_MATCH_INT_INFO,
2664 .idVendor = 0x046d,
2665 .idProduct = 0x089b,
2666 .bInterfaceClass = USB_CLASS_VIDEO,
2667 .bInterfaceSubClass = 1,
2668 .bInterfaceProtocol = 0,
2669 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
2670 /* Logitech Rally Bar Mini */
2671 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2672 | USB_DEVICE_ID_MATCH_INT_INFO,
2673 .idVendor = 0x046d,
2674 .idProduct = 0x08d3,
2675 .bInterfaceClass = USB_CLASS_VIDEO,
2676 .bInterfaceSubClass = 1,
2677 .bInterfaceProtocol = 0,
2678 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
2679 /* Chicony CNF7129 (Asus EEE 100HE) */
2680 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2681 | USB_DEVICE_ID_MATCH_INT_INFO,
2682 .idVendor = 0x04f2,
2683 .idProduct = 0xb071,
2684 .bInterfaceClass = USB_CLASS_VIDEO,
2685 .bInterfaceSubClass = 1,
2686 .bInterfaceProtocol = 0,
2687 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },
2688 /* Chicony EasyCamera */
2689 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2690 | USB_DEVICE_ID_MATCH_INT_INFO,
2691 .idVendor = 0x04f2,
2692 .idProduct = 0xb5eb,
2693 .bInterfaceClass = USB_CLASS_VIDEO,
2694 .bInterfaceSubClass = 1,
2695 .bInterfaceProtocol = 0,
2696 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2697 /* Chicony Electronics Co., Ltd Integrated Camera */
2698 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2699 | USB_DEVICE_ID_MATCH_INT_INFO,
2700 .idVendor = 0x04f2,
2701 .idProduct = 0xb67c,
2702 .bInterfaceClass = USB_CLASS_VIDEO,
2703 .bInterfaceSubClass = 1,
2704 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2705 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 },
2706 /* Chicony EasyCamera */
2707 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2708 | USB_DEVICE_ID_MATCH_INT_INFO,
2709 .idVendor = 0x04f2,
2710 .idProduct = 0xb6ba,
2711 .bInterfaceClass = USB_CLASS_VIDEO,
2712 .bInterfaceSubClass = 1,
2713 .bInterfaceProtocol = 0,
2714 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2715 /* Chicony EasyCamera */
2716 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2717 | USB_DEVICE_ID_MATCH_INT_INFO,
2718 .idVendor = 0x04f2,
2719 .idProduct = 0xb746,
2720 .bInterfaceClass = USB_CLASS_VIDEO,
2721 .bInterfaceSubClass = 1,
2722 .bInterfaceProtocol = 0,
2723 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2724 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2725 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2726 | USB_DEVICE_ID_MATCH_INT_INFO,
2727 .idVendor = 0x058f,
2728 .idProduct = 0x3820,
2729 .bInterfaceClass = USB_CLASS_VIDEO,
2730 .bInterfaceSubClass = 1,
2731 .bInterfaceProtocol = 0,
2732 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2733 /* Dell XPS m1530 */
2734 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2735 | USB_DEVICE_ID_MATCH_INT_INFO,
2736 .idVendor = 0x05a9,
2737 .idProduct = 0x2640,
2738 .bInterfaceClass = USB_CLASS_VIDEO,
2739 .bInterfaceSubClass = 1,
2740 .bInterfaceProtocol = 0,
2741 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2742 /* Dell SP2008WFP Monitor */
2743 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2744 | USB_DEVICE_ID_MATCH_INT_INFO,
2745 .idVendor = 0x05a9,
2746 .idProduct = 0x2641,
2747 .bInterfaceClass = USB_CLASS_VIDEO,
2748 .bInterfaceSubClass = 1,
2749 .bInterfaceProtocol = 0,
2750 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2751 /* Dell Alienware X51 */
2752 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2753 | USB_DEVICE_ID_MATCH_INT_INFO,
2754 .idVendor = 0x05a9,
2755 .idProduct = 0x2643,
2756 .bInterfaceClass = USB_CLASS_VIDEO,
2757 .bInterfaceSubClass = 1,
2758 .bInterfaceProtocol = 0,
2759 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2760 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2761 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2762 | USB_DEVICE_ID_MATCH_INT_INFO,
2763 .idVendor = 0x05a9,
2764 .idProduct = 0x264a,
2765 .bInterfaceClass = USB_CLASS_VIDEO,
2766 .bInterfaceSubClass = 1,
2767 .bInterfaceProtocol = 0,
2768 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2769 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2770 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2771 | USB_DEVICE_ID_MATCH_INT_INFO,
2772 .idVendor = 0x05a9,
2773 .idProduct = 0x7670,
2774 .bInterfaceClass = USB_CLASS_VIDEO,
2775 .bInterfaceSubClass = 1,
2776 .bInterfaceProtocol = 0,
2777 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2778 /* Apple Built-In iSight */
2779 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2780 | USB_DEVICE_ID_MATCH_INT_INFO,
2781 .idVendor = 0x05ac,
2782 .idProduct = 0x8501,
2783 .bInterfaceClass = USB_CLASS_VIDEO,
2784 .bInterfaceSubClass = 1,
2785 .bInterfaceProtocol = 0,
2786 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2787 | UVC_QUIRK_BUILTIN_ISIGHT) },
2788 /* Apple FaceTime HD Camera (Built-In) */
2789 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2790 | USB_DEVICE_ID_MATCH_INT_INFO,
2791 .idVendor = 0x05ac,
2792 .idProduct = 0x8514,
2793 .bInterfaceClass = USB_CLASS_VIDEO,
2794 .bInterfaceSubClass = 1,
2795 .bInterfaceProtocol = 0,
2796 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2797 /* Apple Built-In iSight via iBridge */
2798 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2799 | USB_DEVICE_ID_MATCH_INT_INFO,
2800 .idVendor = 0x05ac,
2801 .idProduct = 0x8600,
2802 .bInterfaceClass = USB_CLASS_VIDEO,
2803 .bInterfaceSubClass = 1,
2804 .bInterfaceProtocol = 0,
2805 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2806 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2807 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2808 | USB_DEVICE_ID_MATCH_INT_INFO,
2809 .idVendor = 0x05c8,
2810 .idProduct = 0x0403,
2811 .bInterfaceClass = USB_CLASS_VIDEO,
2812 .bInterfaceSubClass = 1,
2813 .bInterfaceProtocol = 0,
2814 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2815 /* Genesys Logic USB 2.0 PC Camera */
2816 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2817 | USB_DEVICE_ID_MATCH_INT_INFO,
2818 .idVendor = 0x05e3,
2819 .idProduct = 0x0505,
2820 .bInterfaceClass = USB_CLASS_VIDEO,
2821 .bInterfaceSubClass = 1,
2822 .bInterfaceProtocol = 0,
2823 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2824 /* Hercules Classic Silver */
2825 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2826 | USB_DEVICE_ID_MATCH_INT_INFO,
2827 .idVendor = 0x06f8,
2828 .idProduct = 0x300c,
2829 .bInterfaceClass = USB_CLASS_VIDEO,
2830 .bInterfaceSubClass = 1,
2831 .bInterfaceProtocol = 0,
2832 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2833 /* ViMicro Vega */
2834 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2835 | USB_DEVICE_ID_MATCH_INT_INFO,
2836 .idVendor = 0x0ac8,
2837 .idProduct = 0x332d,
2838 .bInterfaceClass = USB_CLASS_VIDEO,
2839 .bInterfaceSubClass = 1,
2840 .bInterfaceProtocol = 0,
2841 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2842 /* ViMicro - Minoru3D */
2843 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2844 | USB_DEVICE_ID_MATCH_INT_INFO,
2845 .idVendor = 0x0ac8,
2846 .idProduct = 0x3410,
2847 .bInterfaceClass = USB_CLASS_VIDEO,
2848 .bInterfaceSubClass = 1,
2849 .bInterfaceProtocol = 0,
2850 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2851 /* ViMicro Venus - Minoru3D */
2852 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2853 | USB_DEVICE_ID_MATCH_INT_INFO,
2854 .idVendor = 0x0ac8,
2855 .idProduct = 0x3420,
2856 .bInterfaceClass = USB_CLASS_VIDEO,
2857 .bInterfaceSubClass = 1,
2858 .bInterfaceProtocol = 0,
2859 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2860 /* Ophir Optronics - SPCAM 620U */
2861 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2862 | USB_DEVICE_ID_MATCH_INT_INFO,
2863 .idVendor = 0x0bd3,
2864 .idProduct = 0x0555,
2865 .bInterfaceClass = USB_CLASS_VIDEO,
2866 .bInterfaceSubClass = 1,
2867 .bInterfaceProtocol = 0,
2868 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2869 /* MT6227 */
2870 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2871 | USB_DEVICE_ID_MATCH_INT_INFO,
2872 .idVendor = 0x0e8d,
2873 .idProduct = 0x0004,
2874 .bInterfaceClass = USB_CLASS_VIDEO,
2875 .bInterfaceSubClass = 1,
2876 .bInterfaceProtocol = 0,
2877 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2878 | UVC_QUIRK_PROBE_DEF) },
2879 /* IMC Networks (Medion Akoya) */
2880 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2881 | USB_DEVICE_ID_MATCH_INT_INFO,
2882 .idVendor = 0x13d3,
2883 .idProduct = 0x5103,
2884 .bInterfaceClass = USB_CLASS_VIDEO,
2885 .bInterfaceSubClass = 1,
2886 .bInterfaceProtocol = 0,
2887 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2888 /* JMicron USB2.0 XGA WebCam */
2889 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2890 | USB_DEVICE_ID_MATCH_INT_INFO,
2891 .idVendor = 0x152d,
2892 .idProduct = 0x0310,
2893 .bInterfaceClass = USB_CLASS_VIDEO,
2894 .bInterfaceSubClass = 1,
2895 .bInterfaceProtocol = 0,
2896 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2897 /* Syntek (HP Spartan) */
2898 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2899 | USB_DEVICE_ID_MATCH_INT_INFO,
2900 .idVendor = 0x174f,
2901 .idProduct = 0x5212,
2902 .bInterfaceClass = USB_CLASS_VIDEO,
2903 .bInterfaceSubClass = 1,
2904 .bInterfaceProtocol = 0,
2905 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2906 /* Syntek (Samsung Q310) */
2907 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2908 | USB_DEVICE_ID_MATCH_INT_INFO,
2909 .idVendor = 0x174f,
2910 .idProduct = 0x5931,
2911 .bInterfaceClass = USB_CLASS_VIDEO,
2912 .bInterfaceSubClass = 1,
2913 .bInterfaceProtocol = 0,
2914 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2915 /* Syntek (Packard Bell EasyNote MX52 */
2916 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2917 | USB_DEVICE_ID_MATCH_INT_INFO,
2918 .idVendor = 0x174f,
2919 .idProduct = 0x8a12,
2920 .bInterfaceClass = USB_CLASS_VIDEO,
2921 .bInterfaceSubClass = 1,
2922 .bInterfaceProtocol = 0,
2923 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2924 /* Syntek (Asus F9SG) */
2925 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2926 | USB_DEVICE_ID_MATCH_INT_INFO,
2927 .idVendor = 0x174f,
2928 .idProduct = 0x8a31,
2929 .bInterfaceClass = USB_CLASS_VIDEO,
2930 .bInterfaceSubClass = 1,
2931 .bInterfaceProtocol = 0,
2932 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2933 /* Syntek (Asus U3S) */
2934 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2935 | USB_DEVICE_ID_MATCH_INT_INFO,
2936 .idVendor = 0x174f,
2937 .idProduct = 0x8a33,
2938 .bInterfaceClass = USB_CLASS_VIDEO,
2939 .bInterfaceSubClass = 1,
2940 .bInterfaceProtocol = 0,
2941 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2942 /* Syntek (JAOtech Smart Terminal) */
2943 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2944 | USB_DEVICE_ID_MATCH_INT_INFO,
2945 .idVendor = 0x174f,
2946 .idProduct = 0x8a34,
2947 .bInterfaceClass = USB_CLASS_VIDEO,
2948 .bInterfaceSubClass = 1,
2949 .bInterfaceProtocol = 0,
2950 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2951 /* Miricle 307K */
2952 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2953 | USB_DEVICE_ID_MATCH_INT_INFO,
2954 .idVendor = 0x17dc,
2955 .idProduct = 0x0202,
2956 .bInterfaceClass = USB_CLASS_VIDEO,
2957 .bInterfaceSubClass = 1,
2958 .bInterfaceProtocol = 0,
2959 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2960 /* Lenovo Thinkpad SL400/SL500 */
2961 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2962 | USB_DEVICE_ID_MATCH_INT_INFO,
2963 .idVendor = 0x17ef,
2964 .idProduct = 0x480b,
2965 .bInterfaceClass = USB_CLASS_VIDEO,
2966 .bInterfaceSubClass = 1,
2967 .bInterfaceProtocol = 0,
2968 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2969 /* Aveo Technology USB 2.0 Camera */
2970 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2971 | USB_DEVICE_ID_MATCH_INT_INFO,
2972 .idVendor = 0x1871,
2973 .idProduct = 0x0306,
2974 .bInterfaceClass = USB_CLASS_VIDEO,
2975 .bInterfaceSubClass = 1,
2976 .bInterfaceProtocol = 0,
2977 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2978 | UVC_QUIRK_PROBE_EXTRAFIELDS) },
2979 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2980 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2981 | USB_DEVICE_ID_MATCH_INT_INFO,
2982 .idVendor = 0x1871,
2983 .idProduct = 0x0516,
2984 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2985 .bInterfaceSubClass = 1,
2986 .bInterfaceProtocol = 0 },
2987 /* Ecamm Pico iMage */
2988 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2989 | USB_DEVICE_ID_MATCH_INT_INFO,
2990 .idVendor = 0x18cd,
2991 .idProduct = 0xcafe,
2992 .bInterfaceClass = USB_CLASS_VIDEO,
2993 .bInterfaceSubClass = 1,
2994 .bInterfaceProtocol = 0,
2995 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) },
2996 /* Manta MM-353 Plako */
2997 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2998 | USB_DEVICE_ID_MATCH_INT_INFO,
2999 .idVendor = 0x18ec,
3000 .idProduct = 0x3188,
3001 .bInterfaceClass = USB_CLASS_VIDEO,
3002 .bInterfaceSubClass = 1,
3003 .bInterfaceProtocol = 0,
3004 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3005 /* FSC WebCam V30S */
3006 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3007 | USB_DEVICE_ID_MATCH_INT_INFO,
3008 .idVendor = 0x18ec,
3009 .idProduct = 0x3288,
3010 .bInterfaceClass = USB_CLASS_VIDEO,
3011 .bInterfaceSubClass = 1,
3012 .bInterfaceProtocol = 0,
3013 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3014 /* Arkmicro unbranded */
3015 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3016 | USB_DEVICE_ID_MATCH_INT_INFO,
3017 .idVendor = 0x18ec,
3018 .idProduct = 0x3290,
3019 .bInterfaceClass = USB_CLASS_VIDEO,
3020 .bInterfaceSubClass = 1,
3021 .bInterfaceProtocol = 0,
3022 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
3023 /* The Imaging Source USB CCD cameras */
3024 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3025 | USB_DEVICE_ID_MATCH_INT_INFO,
3026 .idVendor = 0x199e,
3027 .idProduct = 0x8102,
3028 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3029 .bInterfaceSubClass = 1,
3030 .bInterfaceProtocol = 0 },
3031 /* Bodelin ProScopeHR */
3032 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3033 | USB_DEVICE_ID_MATCH_DEV_HI
3034 | USB_DEVICE_ID_MATCH_INT_INFO,
3035 .idVendor = 0x19ab,
3036 .idProduct = 0x1000,
3037 .bcdDevice_hi = 0x0126,
3038 .bInterfaceClass = USB_CLASS_VIDEO,
3039 .bInterfaceSubClass = 1,
3040 .bInterfaceProtocol = 0,
3041 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) },
3042 /* MSI StarCam 370i */
3043 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3044 | USB_DEVICE_ID_MATCH_INT_INFO,
3045 .idVendor = 0x1b3b,
3046 .idProduct = 0x2951,
3047 .bInterfaceClass = USB_CLASS_VIDEO,
3048 .bInterfaceSubClass = 1,
3049 .bInterfaceProtocol = 0,
3050 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3051 /* Generalplus Technology Inc. 808 Camera */
3052 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3053 | USB_DEVICE_ID_MATCH_INT_INFO,
3054 .idVendor = 0x1b3f,
3055 .idProduct = 0x2002,
3056 .bInterfaceClass = USB_CLASS_VIDEO,
3057 .bInterfaceSubClass = 1,
3058 .bInterfaceProtocol = 0,
3059 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3060 /* Shenzhen Aoni Electronic Co.,Ltd 2K FHD camera */
3061 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3062 | USB_DEVICE_ID_MATCH_INT_INFO,
3063 .idVendor = 0x1bcf,
3064 .idProduct = 0x0b40,
3065 .bInterfaceClass = USB_CLASS_VIDEO,
3066 .bInterfaceSubClass = 1,
3067 .bInterfaceProtocol = 0,
3068 .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
3069 .uvc_version = 0x010a,
3070 } },
3071 /* SiGma Micro USB Web Camera */
3072 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3073 | USB_DEVICE_ID_MATCH_INT_INFO,
3074 .idVendor = 0x1c4f,
3075 .idProduct = 0x3000,
3076 .bInterfaceClass = USB_CLASS_VIDEO,
3077 .bInterfaceSubClass = 1,
3078 .bInterfaceProtocol = 0,
3079 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
3080 | UVC_QUIRK_IGNORE_SELECTOR_UNIT) },
3081 /* NXP Semiconductors IR VIDEO */
3082 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3083 | USB_DEVICE_ID_MATCH_INT_INFO,
3084 .idVendor = 0x1fc9,
3085 .idProduct = 0x009b,
3086 .bInterfaceClass = USB_CLASS_VIDEO,
3087 .bInterfaceSubClass = 1,
3088 .bInterfaceProtocol = 0,
3089 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3090 /* Oculus VR Positional Tracker DK2 */
3091 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3092 | USB_DEVICE_ID_MATCH_INT_INFO,
3093 .idVendor = 0x2833,
3094 .idProduct = 0x0201,
3095 .bInterfaceClass = USB_CLASS_VIDEO,
3096 .bInterfaceSubClass = 1,
3097 .bInterfaceProtocol = 0,
3098 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
3099 /* Oculus VR Rift Sensor */
3100 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3101 | USB_DEVICE_ID_MATCH_INT_INFO,
3102 .idVendor = 0x2833,
3103 .idProduct = 0x0211,
3104 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3105 .bInterfaceSubClass = 1,
3106 .bInterfaceProtocol = 0,
3107 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
3108 /* GEO Semiconductor GC6500 */
3109 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3110 | USB_DEVICE_ID_MATCH_INT_INFO,
3111 .idVendor = 0x29fe,
3112 .idProduct = 0x4d53,
3113 .bInterfaceClass = USB_CLASS_VIDEO,
3114 .bInterfaceSubClass = 1,
3115 .bInterfaceProtocol = 0,
3116 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) },
3117 /* SunplusIT Inc HD Camera */
3118 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3119 | USB_DEVICE_ID_MATCH_INT_INFO,
3120 .idVendor = 0x2b7e,
3121 .idProduct = 0xb752,
3122 .bInterfaceClass = USB_CLASS_VIDEO,
3123 .bInterfaceSubClass = 1,
3124 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
3125 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 },
3126 /* Insta360 Link */
3127 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3128 | USB_DEVICE_ID_MATCH_INT_INFO,
3129 .idVendor = 0x2e1a,
3130 .idProduct = 0x4c01,
3131 .bInterfaceClass = USB_CLASS_VIDEO,
3132 .bInterfaceSubClass = 1,
3133 .bInterfaceProtocol = 0,
3134 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) },
3135 /* Lenovo Integrated Camera */
3136 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3137 | USB_DEVICE_ID_MATCH_INT_INFO,
3138 .idVendor = 0x30c9,
3139 .idProduct = 0x0093,
3140 .bInterfaceClass = USB_CLASS_VIDEO,
3141 .bInterfaceSubClass = 1,
3142 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
3143 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 },
3144 /* Sonix Technology USB 2.0 Camera */
3145 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3146 | USB_DEVICE_ID_MATCH_INT_INFO,
3147 .idVendor = 0x3277,
3148 .idProduct = 0x0072,
3149 .bInterfaceClass = USB_CLASS_VIDEO,
3150 .bInterfaceSubClass = 1,
3151 .bInterfaceProtocol = 0,
3152 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3153 /* Acer EasyCamera */
3154 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3155 | USB_DEVICE_ID_MATCH_INT_INFO,
3156 .idVendor = 0x5986,
3157 .idProduct = 0x1172,
3158 .bInterfaceClass = USB_CLASS_VIDEO,
3159 .bInterfaceSubClass = 1,
3160 .bInterfaceProtocol = 0,
3161 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3162 /* Acer EasyCamera */
3163 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3164 | USB_DEVICE_ID_MATCH_INT_INFO,
3165 .idVendor = 0x5986,
3166 .idProduct = 0x1180,
3167 .bInterfaceClass = USB_CLASS_VIDEO,
3168 .bInterfaceSubClass = 1,
3169 .bInterfaceProtocol = 0,
3170 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3171 /* Intel D410/ASR depth camera */
3172 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3173 | USB_DEVICE_ID_MATCH_INT_INFO,
3174 .idVendor = 0x8086,
3175 .idProduct = 0x0ad2,
3176 .bInterfaceClass = USB_CLASS_VIDEO,
3177 .bInterfaceSubClass = 1,
3178 .bInterfaceProtocol = 0,
3179 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3180 /* Intel D415/ASRC depth camera */
3181 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3182 | USB_DEVICE_ID_MATCH_INT_INFO,
3183 .idVendor = 0x8086,
3184 .idProduct = 0x0ad3,
3185 .bInterfaceClass = USB_CLASS_VIDEO,
3186 .bInterfaceSubClass = 1,
3187 .bInterfaceProtocol = 0,
3188 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3189 /* Intel D430/AWG depth camera */
3190 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3191 | USB_DEVICE_ID_MATCH_INT_INFO,
3192 .idVendor = 0x8086,
3193 .idProduct = 0x0ad4,
3194 .bInterfaceClass = USB_CLASS_VIDEO,
3195 .bInterfaceSubClass = 1,
3196 .bInterfaceProtocol = 0,
3197 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3198 /* Intel RealSense D4M */
3199 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3200 | USB_DEVICE_ID_MATCH_INT_INFO,
3201 .idVendor = 0x8086,
3202 .idProduct = 0x0b03,
3203 .bInterfaceClass = USB_CLASS_VIDEO,
3204 .bInterfaceSubClass = 1,
3205 .bInterfaceProtocol = 0,
3206 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3207 /* Intel D435/AWGC depth camera */
3208 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3209 | USB_DEVICE_ID_MATCH_INT_INFO,
3210 .idVendor = 0x8086,
3211 .idProduct = 0x0b07,
3212 .bInterfaceClass = USB_CLASS_VIDEO,
3213 .bInterfaceSubClass = 1,
3214 .bInterfaceProtocol = 0,
3215 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3216 /* Intel D435i depth camera */
3217 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3218 | USB_DEVICE_ID_MATCH_INT_INFO,
3219 .idVendor = 0x8086,
3220 .idProduct = 0x0b3a,
3221 .bInterfaceClass = USB_CLASS_VIDEO,
3222 .bInterfaceSubClass = 1,
3223 .bInterfaceProtocol = 0,
3224 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3225 /* Intel D405 Depth Camera */
3226 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3227 | USB_DEVICE_ID_MATCH_INT_INFO,
3228 .idVendor = 0x8086,
3229 .idProduct = 0x0b5b,
3230 .bInterfaceClass = USB_CLASS_VIDEO,
3231 .bInterfaceSubClass = 1,
3232 .bInterfaceProtocol = 0,
3233 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3234 /* Intel D455 Depth Camera */
3235 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3236 | USB_DEVICE_ID_MATCH_INT_INFO,
3237 .idVendor = 0x8086,
3238 .idProduct = 0x0b5c,
3239 .bInterfaceClass = USB_CLASS_VIDEO,
3240 .bInterfaceSubClass = 1,
3241 .bInterfaceProtocol = 0,
3242 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3243 /* Intel D421 Depth Module */
3244 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3245 | USB_DEVICE_ID_MATCH_INT_INFO,
3246 .idVendor = 0x8086,
3247 .idProduct = 0x1155,
3248 .bInterfaceClass = USB_CLASS_VIDEO,
3249 .bInterfaceSubClass = 1,
3250 .bInterfaceProtocol = 0,
3251 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3252 /* Generic USB Video Class */
3253 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
3254 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
3255 {}
3256 };
3257
3258 MODULE_DEVICE_TABLE(usb, uvc_ids);
3259
3260 struct uvc_driver uvc_driver = {
3261 .driver = {
3262 .name = "uvcvideo",
3263 .probe = uvc_probe,
3264 .disconnect = uvc_disconnect,
3265 .suspend = uvc_suspend,
3266 .resume = uvc_resume,
3267 .reset_resume = uvc_reset_resume,
3268 .id_table = uvc_ids,
3269 .supports_autosuspend = 1,
3270 },
3271 };
3272
uvc_init(void)3273 static int __init uvc_init(void)
3274 {
3275 int ret;
3276
3277 uvc_debugfs_init();
3278
3279 ret = usb_register(&uvc_driver.driver);
3280 if (ret < 0) {
3281 uvc_debugfs_cleanup();
3282 return ret;
3283 }
3284
3285 return 0;
3286 }
3287
uvc_cleanup(void)3288 static void __exit uvc_cleanup(void)
3289 {
3290 usb_deregister(&uvc_driver.driver);
3291 uvc_debugfs_cleanup();
3292 }
3293
3294 module_init(uvc_init);
3295 module_exit(uvc_cleanup);
3296
3297 MODULE_AUTHOR(DRIVER_AUTHOR);
3298 MODULE_DESCRIPTION(DRIVER_DESC);
3299 MODULE_LICENSE("GPL");
3300 MODULE_VERSION(DRIVER_VERSION);
3301
3302