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_entity(u16 type,u16 id,unsigned int num_pads,unsigned int extra_size)778 static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,
779 unsigned int num_pads, unsigned int extra_size)
780 {
781 struct uvc_entity *entity;
782 unsigned int num_inputs;
783 unsigned int size;
784 unsigned int i;
785
786 extra_size = roundup(extra_size, sizeof(*entity->pads));
787 if (num_pads)
788 num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
789 else
790 num_inputs = 0;
791 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
792 + num_inputs;
793 entity = kzalloc(size, GFP_KERNEL);
794 if (entity == NULL)
795 return NULL;
796
797 entity->id = id;
798 entity->type = type;
799
800 /*
801 * Set the GUID for standard entity types. For extension units, the GUID
802 * is initialized by the caller.
803 */
804 switch (type) {
805 case UVC_EXT_GPIO_UNIT:
806 memcpy(entity->guid, uvc_gpio_guid, 16);
807 break;
808 case UVC_ITT_CAMERA:
809 memcpy(entity->guid, uvc_camera_guid, 16);
810 break;
811 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
812 memcpy(entity->guid, uvc_media_transport_input_guid, 16);
813 break;
814 case UVC_VC_PROCESSING_UNIT:
815 memcpy(entity->guid, uvc_processing_guid, 16);
816 break;
817 }
818
819 entity->num_links = 0;
820 entity->num_pads = num_pads;
821 entity->pads = ((void *)(entity + 1)) + extra_size;
822
823 for (i = 0; i < num_inputs; ++i)
824 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
825 if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
826 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
827
828 entity->bNrInPins = num_inputs;
829 entity->baSourceID = (u8 *)(&entity->pads[num_pads]);
830
831 return entity;
832 }
833
uvc_entity_set_name(struct uvc_device * dev,struct uvc_entity * entity,const char * type_name,u8 string_id)834 static void uvc_entity_set_name(struct uvc_device *dev, struct uvc_entity *entity,
835 const char *type_name, u8 string_id)
836 {
837 int ret;
838
839 /*
840 * First attempt to read the entity name from the device. If the entity
841 * has no associated string, or if reading the string fails (most
842 * likely due to a buggy firmware), fall back to default names based on
843 * the entity type.
844 */
845 if (string_id) {
846 ret = usb_string(dev->udev, string_id, entity->name,
847 sizeof(entity->name));
848 if (!ret)
849 return;
850 }
851
852 sprintf(entity->name, "%s %u", type_name, entity->id);
853 }
854
855 /* Parse vendor-specific extensions. */
uvc_parse_vendor_control(struct uvc_device * dev,const unsigned char * buffer,int buflen)856 static int uvc_parse_vendor_control(struct uvc_device *dev,
857 const unsigned char *buffer, int buflen)
858 {
859 struct usb_device *udev = dev->udev;
860 struct usb_host_interface *alts = dev->intf->cur_altsetting;
861 struct uvc_entity *unit;
862 unsigned int n, p;
863 int handled = 0;
864
865 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
866 case 0x046d: /* Logitech */
867 if (buffer[1] != 0x41 || buffer[2] != 0x01)
868 break;
869
870 /*
871 * Logitech implements several vendor specific functions
872 * through vendor specific extension units (LXU).
873 *
874 * The LXU descriptors are similar to XU descriptors
875 * (see "USB Device Video Class for Video Devices", section
876 * 3.7.2.6 "Extension Unit Descriptor") with the following
877 * differences:
878 *
879 * ----------------------------------------------------------
880 * 0 bLength 1 Number
881 * Size of this descriptor, in bytes: 24+p+n*2
882 * ----------------------------------------------------------
883 * 23+p+n bmControlsType N Bitmap
884 * Individual bits in the set are defined:
885 * 0: Absolute
886 * 1: Relative
887 *
888 * This bitset is mapped exactly the same as bmControls.
889 * ----------------------------------------------------------
890 * 23+p+n*2 bReserved 1 Boolean
891 * ----------------------------------------------------------
892 * 24+p+n*2 iExtension 1 Index
893 * Index of a string descriptor that describes this
894 * extension unit.
895 * ----------------------------------------------------------
896 */
897 p = buflen >= 22 ? buffer[21] : 0;
898 n = buflen >= 25 + p ? buffer[22+p] : 0;
899
900 if (buflen < 25 + p + 2*n) {
901 uvc_dbg(dev, DESCR,
902 "device %d videocontrol interface %d EXTENSION_UNIT error\n",
903 udev->devnum, alts->desc.bInterfaceNumber);
904 break;
905 }
906
907 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
908 p + 1, 2*n);
909 if (unit == NULL)
910 return -ENOMEM;
911
912 memcpy(unit->guid, &buffer[4], 16);
913 unit->extension.bNumControls = buffer[20];
914 memcpy(unit->baSourceID, &buffer[22], p);
915 unit->extension.bControlSize = buffer[22+p];
916 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
917 unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit)
918 + n;
919 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
920
921 uvc_entity_set_name(dev, unit, "Extension", buffer[24+p+2*n]);
922
923 list_add_tail(&unit->list, &dev->entities);
924 handled = 1;
925 break;
926 }
927
928 return handled;
929 }
930
uvc_parse_standard_control(struct uvc_device * dev,const unsigned char * buffer,int buflen)931 static int uvc_parse_standard_control(struct uvc_device *dev,
932 const unsigned char *buffer, int buflen)
933 {
934 struct usb_device *udev = dev->udev;
935 struct uvc_entity *unit, *term;
936 struct usb_interface *intf;
937 struct usb_host_interface *alts = dev->intf->cur_altsetting;
938 unsigned int i, n, p, len;
939 const char *type_name;
940 u16 type;
941
942 switch (buffer[2]) {
943 case UVC_VC_HEADER:
944 n = buflen >= 12 ? buffer[11] : 0;
945
946 if (buflen < 12 + n) {
947 uvc_dbg(dev, DESCR,
948 "device %d videocontrol interface %d HEADER error\n",
949 udev->devnum, alts->desc.bInterfaceNumber);
950 return -EINVAL;
951 }
952
953 dev->uvc_version = get_unaligned_le16(&buffer[3]);
954 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
955
956 /* Parse all USB Video Streaming interfaces. */
957 for (i = 0; i < n; ++i) {
958 intf = usb_ifnum_to_if(udev, buffer[12+i]);
959 if (intf == NULL) {
960 uvc_dbg(dev, DESCR,
961 "device %d interface %d doesn't exists\n",
962 udev->devnum, i);
963 continue;
964 }
965
966 uvc_parse_streaming(dev, intf);
967 }
968 break;
969
970 case UVC_VC_INPUT_TERMINAL:
971 if (buflen < 8) {
972 uvc_dbg(dev, DESCR,
973 "device %d videocontrol interface %d INPUT_TERMINAL error\n",
974 udev->devnum, alts->desc.bInterfaceNumber);
975 return -EINVAL;
976 }
977
978 /*
979 * Reject invalid terminal types that would cause issues:
980 *
981 * - The high byte must be non-zero, otherwise it would be
982 * confused with a unit.
983 *
984 * - Bit 15 must be 0, as we use it internally as a terminal
985 * direction flag.
986 *
987 * Other unknown types are accepted.
988 */
989 type = get_unaligned_le16(&buffer[4]);
990 if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
991 uvc_dbg(dev, DESCR,
992 "device %d videocontrol interface %d INPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
993 udev->devnum, alts->desc.bInterfaceNumber,
994 buffer[3], type);
995 return 0;
996 }
997
998 n = 0;
999 p = 0;
1000 len = 8;
1001
1002 if (type == UVC_ITT_CAMERA) {
1003 n = buflen >= 15 ? buffer[14] : 0;
1004 len = 15;
1005
1006 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1007 n = buflen >= 9 ? buffer[8] : 0;
1008 p = buflen >= 10 + n ? buffer[9+n] : 0;
1009 len = 10;
1010 }
1011
1012 if (buflen < len + n + p) {
1013 uvc_dbg(dev, DESCR,
1014 "device %d videocontrol interface %d INPUT_TERMINAL error\n",
1015 udev->devnum, alts->desc.bInterfaceNumber);
1016 return -EINVAL;
1017 }
1018
1019 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1020 1, n + p);
1021 if (term == NULL)
1022 return -ENOMEM;
1023
1024 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1025 term->camera.bControlSize = n;
1026 term->camera.bmControls = (u8 *)term + sizeof(*term);
1027 term->camera.wObjectiveFocalLengthMin =
1028 get_unaligned_le16(&buffer[8]);
1029 term->camera.wObjectiveFocalLengthMax =
1030 get_unaligned_le16(&buffer[10]);
1031 term->camera.wOcularFocalLength =
1032 get_unaligned_le16(&buffer[12]);
1033 memcpy(term->camera.bmControls, &buffer[15], n);
1034 } else if (UVC_ENTITY_TYPE(term) ==
1035 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1036 term->media.bControlSize = n;
1037 term->media.bmControls = (u8 *)term + sizeof(*term);
1038 term->media.bTransportModeSize = p;
1039 term->media.bmTransportModes = (u8 *)term
1040 + sizeof(*term) + n;
1041 memcpy(term->media.bmControls, &buffer[9], n);
1042 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1043 }
1044
1045 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1046 type_name = "Camera";
1047 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1048 type_name = "Media";
1049 else
1050 type_name = "Input";
1051
1052 uvc_entity_set_name(dev, term, type_name, buffer[7]);
1053
1054 list_add_tail(&term->list, &dev->entities);
1055 break;
1056
1057 case UVC_VC_OUTPUT_TERMINAL:
1058 if (buflen < 9) {
1059 uvc_dbg(dev, DESCR,
1060 "device %d videocontrol interface %d OUTPUT_TERMINAL error\n",
1061 udev->devnum, alts->desc.bInterfaceNumber);
1062 return -EINVAL;
1063 }
1064
1065 /*
1066 * Make sure the terminal type MSB is not null, otherwise it
1067 * could be confused with a unit.
1068 */
1069 type = get_unaligned_le16(&buffer[4]);
1070 if ((type & 0xff00) == 0) {
1071 uvc_dbg(dev, DESCR,
1072 "device %d videocontrol interface %d OUTPUT_TERMINAL %d has invalid type 0x%04x, skipping\n",
1073 udev->devnum, alts->desc.bInterfaceNumber,
1074 buffer[3], type);
1075 return 0;
1076 }
1077
1078 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1079 1, 0);
1080 if (term == NULL)
1081 return -ENOMEM;
1082
1083 memcpy(term->baSourceID, &buffer[7], 1);
1084
1085 uvc_entity_set_name(dev, term, "Output", buffer[8]);
1086
1087 list_add_tail(&term->list, &dev->entities);
1088 break;
1089
1090 case UVC_VC_SELECTOR_UNIT:
1091 p = buflen >= 5 ? buffer[4] : 0;
1092
1093 if (buflen < 5 || buflen < 6 + p) {
1094 uvc_dbg(dev, DESCR,
1095 "device %d videocontrol interface %d SELECTOR_UNIT error\n",
1096 udev->devnum, alts->desc.bInterfaceNumber);
1097 return -EINVAL;
1098 }
1099
1100 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1101 if (unit == NULL)
1102 return -ENOMEM;
1103
1104 memcpy(unit->baSourceID, &buffer[5], p);
1105
1106 uvc_entity_set_name(dev, unit, "Selector", buffer[5+p]);
1107
1108 list_add_tail(&unit->list, &dev->entities);
1109 break;
1110
1111 case UVC_VC_PROCESSING_UNIT:
1112 n = buflen >= 8 ? buffer[7] : 0;
1113 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1114
1115 if (buflen < p + n) {
1116 uvc_dbg(dev, DESCR,
1117 "device %d videocontrol interface %d PROCESSING_UNIT error\n",
1118 udev->devnum, alts->desc.bInterfaceNumber);
1119 return -EINVAL;
1120 }
1121
1122 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1123 if (unit == NULL)
1124 return -ENOMEM;
1125
1126 memcpy(unit->baSourceID, &buffer[4], 1);
1127 unit->processing.wMaxMultiplier =
1128 get_unaligned_le16(&buffer[5]);
1129 unit->processing.bControlSize = buffer[7];
1130 unit->processing.bmControls = (u8 *)unit + sizeof(*unit);
1131 memcpy(unit->processing.bmControls, &buffer[8], n);
1132 if (dev->uvc_version >= 0x0110)
1133 unit->processing.bmVideoStandards = buffer[9+n];
1134
1135 uvc_entity_set_name(dev, unit, "Processing", buffer[8+n]);
1136
1137 list_add_tail(&unit->list, &dev->entities);
1138 break;
1139
1140 case UVC_VC_EXTENSION_UNIT:
1141 p = buflen >= 22 ? buffer[21] : 0;
1142 n = buflen >= 24 + p ? buffer[22+p] : 0;
1143
1144 if (buflen < 24 + p + n) {
1145 uvc_dbg(dev, DESCR,
1146 "device %d videocontrol interface %d EXTENSION_UNIT error\n",
1147 udev->devnum, alts->desc.bInterfaceNumber);
1148 return -EINVAL;
1149 }
1150
1151 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1152 if (unit == NULL)
1153 return -ENOMEM;
1154
1155 memcpy(unit->guid, &buffer[4], 16);
1156 unit->extension.bNumControls = buffer[20];
1157 memcpy(unit->baSourceID, &buffer[22], p);
1158 unit->extension.bControlSize = buffer[22+p];
1159 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1160 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1161
1162 uvc_entity_set_name(dev, unit, "Extension", buffer[23+p+n]);
1163
1164 list_add_tail(&unit->list, &dev->entities);
1165 break;
1166
1167 default:
1168 uvc_dbg(dev, DESCR,
1169 "Found an unknown CS_INTERFACE descriptor (%u)\n",
1170 buffer[2]);
1171 break;
1172 }
1173
1174 return 0;
1175 }
1176
uvc_parse_control(struct uvc_device * dev)1177 static int uvc_parse_control(struct uvc_device *dev)
1178 {
1179 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1180 const unsigned char *buffer = alts->extra;
1181 int buflen = alts->extralen;
1182 int ret;
1183
1184 /*
1185 * Parse the default alternate setting only, as the UVC specification
1186 * defines a single alternate setting, the default alternate setting
1187 * zero.
1188 */
1189
1190 while (buflen > 2) {
1191 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1192 buffer[1] != USB_DT_CS_INTERFACE)
1193 goto next_descriptor;
1194
1195 ret = uvc_parse_standard_control(dev, buffer, buflen);
1196 if (ret < 0)
1197 return ret;
1198
1199 next_descriptor:
1200 buflen -= buffer[0];
1201 buffer += buffer[0];
1202 }
1203
1204 /*
1205 * Check if the optional status endpoint is present. Built-in iSight
1206 * webcams have an interrupt endpoint but spit proprietary data that
1207 * don't conform to the UVC status endpoint messages. Don't try to
1208 * handle the interrupt endpoint for those cameras.
1209 */
1210 if (alts->desc.bNumEndpoints == 1 &&
1211 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1212 struct usb_host_endpoint *ep = &alts->endpoint[0];
1213 struct usb_endpoint_descriptor *desc = &ep->desc;
1214
1215 if (usb_endpoint_is_int_in(desc) &&
1216 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1217 desc->bInterval != 0) {
1218 uvc_dbg(dev, DESCR,
1219 "Found a Status endpoint (addr %02x)\n",
1220 desc->bEndpointAddress);
1221 dev->int_ep = ep;
1222 }
1223 }
1224
1225 return 0;
1226 }
1227
1228 /* -----------------------------------------------------------------------------
1229 * Privacy GPIO
1230 */
1231
uvc_gpio_event(struct uvc_device * dev)1232 static void uvc_gpio_event(struct uvc_device *dev)
1233 {
1234 struct uvc_entity *unit = dev->gpio_unit;
1235 struct uvc_video_chain *chain;
1236 u8 new_val;
1237
1238 if (!unit)
1239 return;
1240
1241 new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy);
1242
1243 /* GPIO entities are always on the first chain. */
1244 chain = list_first_entry(&dev->chains, struct uvc_video_chain, list);
1245 uvc_ctrl_status_event(chain, unit->controls, &new_val);
1246 }
1247
uvc_gpio_get_cur(struct uvc_device * dev,struct uvc_entity * entity,u8 cs,void * data,u16 size)1248 static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
1249 u8 cs, void *data, u16 size)
1250 {
1251 if (cs != UVC_CT_PRIVACY_CONTROL || size < 1)
1252 return -EINVAL;
1253
1254 *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy);
1255
1256 return 0;
1257 }
1258
uvc_gpio_get_info(struct uvc_device * dev,struct uvc_entity * entity,u8 cs,u8 * caps)1259 static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity,
1260 u8 cs, u8 *caps)
1261 {
1262 if (cs != UVC_CT_PRIVACY_CONTROL)
1263 return -EINVAL;
1264
1265 *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE;
1266 return 0;
1267 }
1268
uvc_gpio_irq(int irq,void * data)1269 static irqreturn_t uvc_gpio_irq(int irq, void *data)
1270 {
1271 struct uvc_device *dev = data;
1272
1273 uvc_gpio_event(dev);
1274 return IRQ_HANDLED;
1275 }
1276
uvc_gpio_parse(struct uvc_device * dev)1277 static int uvc_gpio_parse(struct uvc_device *dev)
1278 {
1279 struct uvc_entity *unit;
1280 struct gpio_desc *gpio_privacy;
1281 int irq;
1282
1283 gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy",
1284 GPIOD_IN);
1285 if (IS_ERR_OR_NULL(gpio_privacy))
1286 return PTR_ERR_OR_ZERO(gpio_privacy);
1287
1288 irq = gpiod_to_irq(gpio_privacy);
1289 if (irq < 0)
1290 return dev_err_probe(&dev->intf->dev, irq,
1291 "No IRQ for privacy GPIO\n");
1292
1293 unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1);
1294 if (!unit)
1295 return -ENOMEM;
1296
1297 unit->gpio.gpio_privacy = gpio_privacy;
1298 unit->gpio.irq = irq;
1299 unit->gpio.bControlSize = 1;
1300 unit->gpio.bmControls = (u8 *)unit + sizeof(*unit);
1301 unit->gpio.bmControls[0] = 1;
1302 unit->get_cur = uvc_gpio_get_cur;
1303 unit->get_info = uvc_gpio_get_info;
1304 strscpy(unit->name, "GPIO", sizeof(unit->name));
1305
1306 list_add_tail(&unit->list, &dev->entities);
1307
1308 dev->gpio_unit = unit;
1309
1310 return 0;
1311 }
1312
uvc_gpio_init_irq(struct uvc_device * dev)1313 static int uvc_gpio_init_irq(struct uvc_device *dev)
1314 {
1315 struct uvc_entity *unit = dev->gpio_unit;
1316 int ret;
1317
1318 if (!unit || unit->gpio.irq < 0)
1319 return 0;
1320
1321 ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq,
1322 IRQF_ONESHOT | IRQF_TRIGGER_FALLING |
1323 IRQF_TRIGGER_RISING,
1324 "uvc_privacy_gpio", dev);
1325
1326 unit->gpio.initialized = !ret;
1327
1328 return ret;
1329 }
1330
uvc_gpio_deinit(struct uvc_device * dev)1331 static void uvc_gpio_deinit(struct uvc_device *dev)
1332 {
1333 if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized)
1334 return;
1335
1336 free_irq(dev->gpio_unit->gpio.irq, dev);
1337 }
1338
1339 /* ------------------------------------------------------------------------
1340 * UVC device scan
1341 */
1342
1343 /*
1344 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1345 * and containing the following units:
1346 *
1347 * - one or more Output Terminals (USB Streaming or Display)
1348 * - zero or one Processing Unit
1349 * - zero, one or more single-input Selector Units
1350 * - zero or one multiple-input Selector Units, provided all inputs are
1351 * connected to input terminals
1352 * - zero, one or mode single-input Extension Units
1353 * - one or more Input Terminals (Camera, External or USB Streaming)
1354 *
1355 * The terminal and units must match on of the following structures:
1356 *
1357 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1358 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1359 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1360 *
1361 * +---------+ +---------+ -> OTT_*(0)
1362 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1363 * +---------+ +---------+ -> OTT_*(n)
1364 *
1365 * The Processing Unit and Extension Units can be in any order. Additional
1366 * Extension Units connected to the main chain as single-unit branches are
1367 * also supported. Single-input Selector Units are ignored.
1368 */
uvc_scan_chain_entity(struct uvc_video_chain * chain,struct uvc_entity * entity)1369 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1370 struct uvc_entity *entity)
1371 {
1372 switch (UVC_ENTITY_TYPE(entity)) {
1373 case UVC_VC_EXTENSION_UNIT:
1374 uvc_dbg_cont(PROBE, " <- XU %d", entity->id);
1375
1376 if (entity->bNrInPins != 1) {
1377 uvc_dbg(chain->dev, DESCR,
1378 "Extension unit %d has more than 1 input pin\n",
1379 entity->id);
1380 return -1;
1381 }
1382
1383 break;
1384
1385 case UVC_VC_PROCESSING_UNIT:
1386 uvc_dbg_cont(PROBE, " <- PU %d", entity->id);
1387
1388 if (chain->processing != NULL) {
1389 uvc_dbg(chain->dev, DESCR,
1390 "Found multiple Processing Units in chain\n");
1391 return -1;
1392 }
1393
1394 chain->processing = entity;
1395 break;
1396
1397 case UVC_VC_SELECTOR_UNIT:
1398 uvc_dbg_cont(PROBE, " <- SU %d", entity->id);
1399
1400 /* Single-input selector units are ignored. */
1401 if (entity->bNrInPins == 1)
1402 break;
1403
1404 if (chain->selector != NULL) {
1405 uvc_dbg(chain->dev, DESCR,
1406 "Found multiple Selector Units in chain\n");
1407 return -1;
1408 }
1409
1410 chain->selector = entity;
1411 break;
1412
1413 case UVC_ITT_VENDOR_SPECIFIC:
1414 case UVC_ITT_CAMERA:
1415 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1416 uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
1417
1418 break;
1419
1420 case UVC_OTT_VENDOR_SPECIFIC:
1421 case UVC_OTT_DISPLAY:
1422 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1423 uvc_dbg_cont(PROBE, " OT %d", entity->id);
1424
1425 break;
1426
1427 case UVC_TT_STREAMING:
1428 if (UVC_ENTITY_IS_ITERM(entity))
1429 uvc_dbg_cont(PROBE, " <- IT %d\n", entity->id);
1430 else
1431 uvc_dbg_cont(PROBE, " OT %d", entity->id);
1432
1433 break;
1434
1435 default:
1436 uvc_dbg(chain->dev, DESCR,
1437 "Unsupported entity type 0x%04x found in chain\n",
1438 UVC_ENTITY_TYPE(entity));
1439 return -1;
1440 }
1441
1442 list_add_tail(&entity->chain, &chain->entities);
1443 return 0;
1444 }
1445
uvc_scan_chain_forward(struct uvc_video_chain * chain,struct uvc_entity * entity,struct uvc_entity * prev)1446 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1447 struct uvc_entity *entity, struct uvc_entity *prev)
1448 {
1449 struct uvc_entity *forward;
1450 int found;
1451
1452 /* Forward scan */
1453 forward = NULL;
1454 found = 0;
1455
1456 while (1) {
1457 forward = uvc_entity_by_reference(chain->dev, entity->id,
1458 forward);
1459 if (forward == NULL)
1460 break;
1461 if (forward == prev)
1462 continue;
1463 if (forward->chain.next || forward->chain.prev) {
1464 uvc_dbg(chain->dev, DESCR,
1465 "Found reference to entity %d already in chain\n",
1466 forward->id);
1467 return -EINVAL;
1468 }
1469
1470 switch (UVC_ENTITY_TYPE(forward)) {
1471 case UVC_VC_EXTENSION_UNIT:
1472 if (forward->bNrInPins != 1) {
1473 uvc_dbg(chain->dev, DESCR,
1474 "Extension unit %d has more than 1 input pin\n",
1475 forward->id);
1476 return -EINVAL;
1477 }
1478
1479 /*
1480 * Some devices reference an output terminal as the
1481 * source of extension units. This is incorrect, as
1482 * output terminals only have an input pin, and thus
1483 * can't be connected to any entity in the forward
1484 * direction. The resulting topology would cause issues
1485 * when registering the media controller graph. To
1486 * avoid this problem, connect the extension unit to
1487 * the source of the output terminal instead.
1488 */
1489 if (UVC_ENTITY_IS_OTERM(entity)) {
1490 struct uvc_entity *source;
1491
1492 source = uvc_entity_by_id(chain->dev,
1493 entity->baSourceID[0]);
1494 if (!source) {
1495 uvc_dbg(chain->dev, DESCR,
1496 "Can't connect extension unit %u in chain\n",
1497 forward->id);
1498 break;
1499 }
1500
1501 forward->baSourceID[0] = source->id;
1502 }
1503
1504 list_add_tail(&forward->chain, &chain->entities);
1505 if (!found)
1506 uvc_dbg_cont(PROBE, " (->");
1507
1508 uvc_dbg_cont(PROBE, " XU %d", forward->id);
1509 found = 1;
1510 break;
1511
1512 case UVC_OTT_VENDOR_SPECIFIC:
1513 case UVC_OTT_DISPLAY:
1514 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1515 case UVC_TT_STREAMING:
1516 if (UVC_ENTITY_IS_ITERM(forward)) {
1517 uvc_dbg(chain->dev, DESCR,
1518 "Unsupported input terminal %u\n",
1519 forward->id);
1520 return -EINVAL;
1521 }
1522
1523 if (UVC_ENTITY_IS_OTERM(entity)) {
1524 uvc_dbg(chain->dev, DESCR,
1525 "Unsupported connection between output terminals %u and %u\n",
1526 entity->id, forward->id);
1527 break;
1528 }
1529
1530 list_add_tail(&forward->chain, &chain->entities);
1531 if (!found)
1532 uvc_dbg_cont(PROBE, " (->");
1533
1534 uvc_dbg_cont(PROBE, " OT %d", forward->id);
1535 found = 1;
1536 break;
1537 }
1538 }
1539 if (found)
1540 uvc_dbg_cont(PROBE, ")");
1541
1542 return 0;
1543 }
1544
uvc_scan_chain_backward(struct uvc_video_chain * chain,struct uvc_entity ** _entity)1545 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1546 struct uvc_entity **_entity)
1547 {
1548 struct uvc_entity *entity = *_entity;
1549 struct uvc_entity *term;
1550 int id = -EINVAL, i;
1551
1552 switch (UVC_ENTITY_TYPE(entity)) {
1553 case UVC_VC_EXTENSION_UNIT:
1554 case UVC_VC_PROCESSING_UNIT:
1555 id = entity->baSourceID[0];
1556 break;
1557
1558 case UVC_VC_SELECTOR_UNIT:
1559 /* Single-input selector units are ignored. */
1560 if (entity->bNrInPins == 1) {
1561 id = entity->baSourceID[0];
1562 break;
1563 }
1564
1565 uvc_dbg_cont(PROBE, " <- IT");
1566
1567 chain->selector = entity;
1568 for (i = 0; i < entity->bNrInPins; ++i) {
1569 id = entity->baSourceID[i];
1570 term = uvc_entity_by_id(chain->dev, id);
1571 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1572 uvc_dbg(chain->dev, DESCR,
1573 "Selector unit %d input %d isn't connected to an input terminal\n",
1574 entity->id, i);
1575 return -1;
1576 }
1577
1578 if (term->chain.next || term->chain.prev) {
1579 uvc_dbg(chain->dev, DESCR,
1580 "Found reference to entity %d already in chain\n",
1581 term->id);
1582 return -EINVAL;
1583 }
1584
1585 uvc_dbg_cont(PROBE, " %d", term->id);
1586
1587 list_add_tail(&term->chain, &chain->entities);
1588 uvc_scan_chain_forward(chain, term, entity);
1589 }
1590
1591 uvc_dbg_cont(PROBE, "\n");
1592
1593 id = 0;
1594 break;
1595
1596 case UVC_ITT_VENDOR_SPECIFIC:
1597 case UVC_ITT_CAMERA:
1598 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1599 case UVC_OTT_VENDOR_SPECIFIC:
1600 case UVC_OTT_DISPLAY:
1601 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1602 case UVC_TT_STREAMING:
1603 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1604 break;
1605 }
1606
1607 if (id <= 0) {
1608 *_entity = NULL;
1609 return id;
1610 }
1611
1612 entity = uvc_entity_by_id(chain->dev, id);
1613 if (entity == NULL) {
1614 uvc_dbg(chain->dev, DESCR,
1615 "Found reference to unknown entity %d\n", id);
1616 return -EINVAL;
1617 }
1618
1619 *_entity = entity;
1620 return 0;
1621 }
1622
uvc_scan_chain(struct uvc_video_chain * chain,struct uvc_entity * term)1623 static int uvc_scan_chain(struct uvc_video_chain *chain,
1624 struct uvc_entity *term)
1625 {
1626 struct uvc_entity *entity, *prev;
1627
1628 uvc_dbg(chain->dev, PROBE, "Scanning UVC chain:");
1629
1630 entity = term;
1631 prev = NULL;
1632
1633 while (entity != NULL) {
1634 /* Entity must not be part of an existing chain */
1635 if (entity->chain.next || entity->chain.prev) {
1636 uvc_dbg(chain->dev, DESCR,
1637 "Found reference to entity %d already in chain\n",
1638 entity->id);
1639 return -EINVAL;
1640 }
1641
1642 /* Process entity */
1643 if (uvc_scan_chain_entity(chain, entity) < 0)
1644 return -EINVAL;
1645
1646 /* Forward scan */
1647 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1648 return -EINVAL;
1649
1650 /* Backward scan */
1651 prev = entity;
1652 if (uvc_scan_chain_backward(chain, &entity) < 0)
1653 return -EINVAL;
1654 }
1655
1656 return 0;
1657 }
1658
uvc_print_terms(struct list_head * terms,u16 dir,char * buffer)1659 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1660 char *buffer)
1661 {
1662 struct uvc_entity *term;
1663 unsigned int nterms = 0;
1664 char *p = buffer;
1665
1666 list_for_each_entry(term, terms, chain) {
1667 if (!UVC_ENTITY_IS_TERM(term) ||
1668 UVC_TERM_DIRECTION(term) != dir)
1669 continue;
1670
1671 if (nterms)
1672 p += sprintf(p, ",");
1673 if (++nterms >= 4) {
1674 p += sprintf(p, "...");
1675 break;
1676 }
1677 p += sprintf(p, "%u", term->id);
1678 }
1679
1680 return p - buffer;
1681 }
1682
uvc_print_chain(struct uvc_video_chain * chain)1683 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1684 {
1685 static char buffer[43];
1686 char *p = buffer;
1687
1688 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1689 p += sprintf(p, " -> ");
1690 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1691
1692 return buffer;
1693 }
1694
uvc_alloc_chain(struct uvc_device * dev)1695 static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev)
1696 {
1697 struct uvc_video_chain *chain;
1698
1699 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1700 if (chain == NULL)
1701 return NULL;
1702
1703 INIT_LIST_HEAD(&chain->entities);
1704 mutex_init(&chain->ctrl_mutex);
1705 chain->dev = dev;
1706 v4l2_prio_init(&chain->prio);
1707
1708 return chain;
1709 }
1710
1711 /*
1712 * Fallback heuristic for devices that don't connect units and terminals in a
1713 * valid chain.
1714 *
1715 * Some devices have invalid baSourceID references, causing uvc_scan_chain()
1716 * to fail, but if we just take the entities we can find and put them together
1717 * in the most sensible chain we can think of, turns out they do work anyway.
1718 * Note: This heuristic assumes there is a single chain.
1719 *
1720 * At the time of writing, devices known to have such a broken chain are
1721 * - Acer Integrated Camera (5986:055a)
1722 * - Realtek rtl157a7 (0bda:57a7)
1723 */
uvc_scan_fallback(struct uvc_device * dev)1724 static int uvc_scan_fallback(struct uvc_device *dev)
1725 {
1726 struct uvc_video_chain *chain;
1727 struct uvc_entity *iterm = NULL;
1728 struct uvc_entity *oterm = NULL;
1729 struct uvc_entity *entity;
1730 struct uvc_entity *prev;
1731
1732 /*
1733 * Start by locating the input and output terminals. We only support
1734 * devices with exactly one of each for now.
1735 */
1736 list_for_each_entry(entity, &dev->entities, list) {
1737 if (UVC_ENTITY_IS_ITERM(entity)) {
1738 if (iterm)
1739 return -EINVAL;
1740 iterm = entity;
1741 }
1742
1743 if (UVC_ENTITY_IS_OTERM(entity)) {
1744 if (oterm)
1745 return -EINVAL;
1746 oterm = entity;
1747 }
1748 }
1749
1750 if (iterm == NULL || oterm == NULL)
1751 return -EINVAL;
1752
1753 /* Allocate the chain and fill it. */
1754 chain = uvc_alloc_chain(dev);
1755 if (chain == NULL)
1756 return -ENOMEM;
1757
1758 if (uvc_scan_chain_entity(chain, oterm) < 0)
1759 goto error;
1760
1761 prev = oterm;
1762
1763 /*
1764 * Add all Processing and Extension Units with two pads. The order
1765 * doesn't matter much, use reverse list traversal to connect units in
1766 * UVC descriptor order as we build the chain from output to input. This
1767 * leads to units appearing in the order meant by the manufacturer for
1768 * the cameras known to require this heuristic.
1769 */
1770 list_for_each_entry_reverse(entity, &dev->entities, list) {
1771 if (entity->type != UVC_VC_PROCESSING_UNIT &&
1772 entity->type != UVC_VC_EXTENSION_UNIT)
1773 continue;
1774
1775 if (entity->num_pads != 2)
1776 continue;
1777
1778 if (uvc_scan_chain_entity(chain, entity) < 0)
1779 goto error;
1780
1781 prev->baSourceID[0] = entity->id;
1782 prev = entity;
1783 }
1784
1785 if (uvc_scan_chain_entity(chain, iterm) < 0)
1786 goto error;
1787
1788 prev->baSourceID[0] = iterm->id;
1789
1790 list_add_tail(&chain->list, &dev->chains);
1791
1792 uvc_dbg(dev, PROBE, "Found a video chain by fallback heuristic (%s)\n",
1793 uvc_print_chain(chain));
1794
1795 return 0;
1796
1797 error:
1798 kfree(chain);
1799 return -EINVAL;
1800 }
1801
1802 /*
1803 * Scan the device for video chains and register video devices.
1804 *
1805 * Chains are scanned starting at their output terminals and walked backwards.
1806 */
uvc_scan_device(struct uvc_device * dev)1807 static int uvc_scan_device(struct uvc_device *dev)
1808 {
1809 struct uvc_video_chain *chain;
1810 struct uvc_entity *term;
1811
1812 list_for_each_entry(term, &dev->entities, list) {
1813 if (!UVC_ENTITY_IS_OTERM(term))
1814 continue;
1815
1816 /*
1817 * If the terminal is already included in a chain, skip it.
1818 * This can happen for chains that have multiple output
1819 * terminals, where all output terminals beside the first one
1820 * will be inserted in the chain in forward scans.
1821 */
1822 if (term->chain.next || term->chain.prev)
1823 continue;
1824
1825 chain = uvc_alloc_chain(dev);
1826 if (chain == NULL)
1827 return -ENOMEM;
1828
1829 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1830
1831 if (uvc_scan_chain(chain, term) < 0) {
1832 kfree(chain);
1833 continue;
1834 }
1835
1836 uvc_dbg(dev, PROBE, "Found a valid video chain (%s)\n",
1837 uvc_print_chain(chain));
1838
1839 list_add_tail(&chain->list, &dev->chains);
1840 }
1841
1842 if (list_empty(&dev->chains))
1843 uvc_scan_fallback(dev);
1844
1845 if (list_empty(&dev->chains)) {
1846 dev_info(&dev->udev->dev, "No valid video chain found.\n");
1847 return -1;
1848 }
1849
1850 /* Add GPIO entity to the first chain. */
1851 if (dev->gpio_unit) {
1852 chain = list_first_entry(&dev->chains,
1853 struct uvc_video_chain, list);
1854 list_add_tail(&dev->gpio_unit->chain, &chain->entities);
1855 }
1856
1857 return 0;
1858 }
1859
1860 /* ------------------------------------------------------------------------
1861 * Video device registration and unregistration
1862 */
1863
1864 /*
1865 * Delete the UVC device.
1866 *
1867 * Called by the kernel when the last reference to the uvc_device structure
1868 * is released.
1869 *
1870 * As this function is called after or during disconnect(), all URBs have
1871 * already been cancelled by the USB core. There is no need to kill the
1872 * interrupt URB manually.
1873 */
uvc_delete(struct kref * kref)1874 static void uvc_delete(struct kref *kref)
1875 {
1876 struct uvc_device *dev = container_of(kref, struct uvc_device, ref);
1877 struct list_head *p, *n;
1878
1879 uvc_status_cleanup(dev);
1880 uvc_ctrl_cleanup_device(dev);
1881
1882 usb_put_intf(dev->intf);
1883 usb_put_dev(dev->udev);
1884
1885 #ifdef CONFIG_MEDIA_CONTROLLER
1886 media_device_cleanup(&dev->mdev);
1887 #endif
1888
1889 list_for_each_safe(p, n, &dev->chains) {
1890 struct uvc_video_chain *chain;
1891
1892 chain = list_entry(p, struct uvc_video_chain, list);
1893 kfree(chain);
1894 }
1895
1896 list_for_each_safe(p, n, &dev->entities) {
1897 struct uvc_entity *entity;
1898
1899 entity = list_entry(p, struct uvc_entity, list);
1900 #ifdef CONFIG_MEDIA_CONTROLLER
1901 uvc_mc_cleanup_entity(entity);
1902 #endif
1903 kfree(entity);
1904 }
1905
1906 list_for_each_safe(p, n, &dev->streams) {
1907 struct uvc_streaming *streaming;
1908
1909 streaming = list_entry(p, struct uvc_streaming, list);
1910 usb_driver_release_interface(&uvc_driver.driver,
1911 streaming->intf);
1912 uvc_stream_delete(streaming);
1913 }
1914
1915 kfree(dev);
1916 }
1917
uvc_release(struct video_device * vdev)1918 static void uvc_release(struct video_device *vdev)
1919 {
1920 struct uvc_streaming *stream = video_get_drvdata(vdev);
1921 struct uvc_device *dev = stream->dev;
1922
1923 kref_put(&dev->ref, uvc_delete);
1924 }
1925
1926 /*
1927 * Unregister the video devices.
1928 */
uvc_unregister_video(struct uvc_device * dev)1929 static void uvc_unregister_video(struct uvc_device *dev)
1930 {
1931 struct uvc_streaming *stream;
1932
1933 uvc_gpio_deinit(dev);
1934
1935 list_for_each_entry(stream, &dev->streams, list) {
1936 /* Nothing to do here, continue. */
1937 if (!video_is_registered(&stream->vdev))
1938 continue;
1939
1940 /*
1941 * For stream->vdev we follow the same logic as:
1942 * vb2_video_unregister_device().
1943 */
1944
1945 /* 1. Take a reference to vdev */
1946 get_device(&stream->vdev.dev);
1947
1948 /* 2. Ensure that no new ioctls can be called. */
1949 video_unregister_device(&stream->vdev);
1950
1951 /* 3. Wait for old ioctls to finish. */
1952 mutex_lock(&stream->mutex);
1953
1954 /* 4. Stop streaming. */
1955 uvc_queue_release(&stream->queue);
1956
1957 mutex_unlock(&stream->mutex);
1958
1959 put_device(&stream->vdev.dev);
1960
1961 /*
1962 * For stream->meta.vdev we can directly call:
1963 * vb2_video_unregister_device().
1964 */
1965 vb2_video_unregister_device(&stream->meta.vdev);
1966
1967 /*
1968 * Now both vdevs are not streaming and all the ioctls will
1969 * return -ENODEV.
1970 */
1971
1972 uvc_debugfs_cleanup_stream(stream);
1973 }
1974
1975 uvc_status_unregister(dev);
1976
1977 if (dev->vdev.dev)
1978 v4l2_device_unregister(&dev->vdev);
1979 #ifdef CONFIG_MEDIA_CONTROLLER
1980 if (media_devnode_is_registered(dev->mdev.devnode))
1981 media_device_unregister(&dev->mdev);
1982 #endif
1983 }
1984
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)1985 int uvc_register_video_device(struct uvc_device *dev,
1986 struct uvc_streaming *stream,
1987 struct video_device *vdev,
1988 struct uvc_video_queue *queue,
1989 enum v4l2_buf_type type,
1990 const struct v4l2_file_operations *fops,
1991 const struct v4l2_ioctl_ops *ioctl_ops)
1992 {
1993 int ret;
1994
1995 /* Initialize the video buffers queue. */
1996 ret = uvc_queue_init(queue, type, !uvc_no_drop_param);
1997 if (ret)
1998 return ret;
1999
2000 /* Register the device with V4L. */
2001
2002 /*
2003 * We already hold a reference to dev->udev. The video device will be
2004 * unregistered before the reference is released, so we don't need to
2005 * get another one.
2006 */
2007 vdev->v4l2_dev = &dev->vdev;
2008 vdev->fops = fops;
2009 vdev->ioctl_ops = ioctl_ops;
2010 vdev->release = uvc_release;
2011 vdev->prio = &stream->chain->prio;
2012 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
2013 vdev->vfl_dir = VFL_DIR_TX;
2014 else
2015 vdev->vfl_dir = VFL_DIR_RX;
2016
2017 switch (type) {
2018 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2019 default:
2020 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
2021 break;
2022 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2023 vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
2024 break;
2025 case V4L2_BUF_TYPE_META_CAPTURE:
2026 vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING;
2027 break;
2028 }
2029
2030 strscpy(vdev->name, dev->name, sizeof(vdev->name));
2031
2032 /*
2033 * Set the driver data before calling video_register_device, otherwise
2034 * the file open() handler might race us.
2035 */
2036 video_set_drvdata(vdev, stream);
2037
2038 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
2039 if (ret < 0) {
2040 dev_err(&stream->intf->dev,
2041 "Failed to register %s device (%d).\n",
2042 v4l2_type_names[type], ret);
2043 return ret;
2044 }
2045
2046 kref_get(&dev->ref);
2047 return 0;
2048 }
2049
uvc_register_video(struct uvc_device * dev,struct uvc_streaming * stream)2050 static int uvc_register_video(struct uvc_device *dev,
2051 struct uvc_streaming *stream)
2052 {
2053 int ret;
2054
2055 /* Initialize the streaming interface with default parameters. */
2056 ret = uvc_video_init(stream);
2057 if (ret < 0) {
2058 dev_err(&stream->intf->dev,
2059 "Failed to initialize the device (%d).\n", ret);
2060 return ret;
2061 }
2062
2063 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2064 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE
2065 | V4L2_CAP_META_CAPTURE;
2066 else
2067 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
2068
2069 uvc_debugfs_init_stream(stream);
2070
2071 /* Register the device with V4L. */
2072 return uvc_register_video_device(dev, stream, &stream->vdev,
2073 &stream->queue, stream->type,
2074 &uvc_fops, &uvc_ioctl_ops);
2075 }
2076
2077 /*
2078 * Register all video devices in all chains.
2079 */
uvc_register_terms(struct uvc_device * dev,struct uvc_video_chain * chain)2080 static int uvc_register_terms(struct uvc_device *dev,
2081 struct uvc_video_chain *chain)
2082 {
2083 struct uvc_streaming *stream;
2084 struct uvc_entity *term;
2085 int ret;
2086
2087 list_for_each_entry(term, &chain->entities, chain) {
2088 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
2089 continue;
2090
2091 stream = uvc_stream_by_id(dev, term->id);
2092 if (stream == NULL) {
2093 dev_info(&dev->udev->dev,
2094 "No streaming interface found for terminal %u.",
2095 term->id);
2096 continue;
2097 }
2098
2099 stream->chain = chain;
2100 ret = uvc_register_video(dev, stream);
2101 if (ret < 0)
2102 return ret;
2103
2104 /*
2105 * Register a metadata node, but ignore a possible failure,
2106 * complete registration of video nodes anyway.
2107 */
2108 uvc_meta_register(stream);
2109
2110 term->vdev = &stream->vdev;
2111 }
2112
2113 return 0;
2114 }
2115
uvc_register_chains(struct uvc_device * dev)2116 static int uvc_register_chains(struct uvc_device *dev)
2117 {
2118 struct uvc_video_chain *chain;
2119 int ret;
2120
2121 list_for_each_entry(chain, &dev->chains, list) {
2122 ret = uvc_register_terms(dev, chain);
2123 if (ret < 0)
2124 return ret;
2125
2126 #ifdef CONFIG_MEDIA_CONTROLLER
2127 ret = uvc_mc_register_entities(chain);
2128 if (ret < 0)
2129 dev_info(&dev->udev->dev,
2130 "Failed to register entities (%d).\n", ret);
2131 #endif
2132 }
2133
2134 return 0;
2135 }
2136
2137 /* ------------------------------------------------------------------------
2138 * USB probe, disconnect, suspend and resume
2139 */
2140
2141 static const struct uvc_device_info uvc_quirk_none = { 0 };
2142
uvc_probe(struct usb_interface * intf,const struct usb_device_id * id)2143 static int uvc_probe(struct usb_interface *intf,
2144 const struct usb_device_id *id)
2145 {
2146 struct usb_device *udev = interface_to_usbdev(intf);
2147 struct uvc_device *dev;
2148 const struct uvc_device_info *info =
2149 (const struct uvc_device_info *)id->driver_info;
2150 int function;
2151 int ret;
2152
2153 /* Allocate memory for the device and initialize it. */
2154 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2155 if (dev == NULL)
2156 return -ENOMEM;
2157
2158 INIT_LIST_HEAD(&dev->entities);
2159 INIT_LIST_HEAD(&dev->chains);
2160 INIT_LIST_HEAD(&dev->streams);
2161 kref_init(&dev->ref);
2162 atomic_set(&dev->nmappings, 0);
2163 mutex_init(&dev->lock);
2164
2165 dev->udev = usb_get_dev(udev);
2166 dev->intf = usb_get_intf(intf);
2167 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2168 dev->info = info ? info : &uvc_quirk_none;
2169 dev->quirks = uvc_quirks_param == -1
2170 ? dev->info->quirks : uvc_quirks_param;
2171
2172 if (id->idVendor && id->idProduct)
2173 uvc_dbg(dev, PROBE, "Probing known UVC device %s (%04x:%04x)\n",
2174 udev->devpath, id->idVendor, id->idProduct);
2175 else
2176 uvc_dbg(dev, PROBE, "Probing generic UVC device %s\n",
2177 udev->devpath);
2178
2179 if (udev->product != NULL)
2180 strscpy(dev->name, udev->product, sizeof(dev->name));
2181 else
2182 snprintf(dev->name, sizeof(dev->name),
2183 "UVC Camera (%04x:%04x)",
2184 le16_to_cpu(udev->descriptor.idVendor),
2185 le16_to_cpu(udev->descriptor.idProduct));
2186
2187 /*
2188 * Add iFunction or iInterface to names when available as additional
2189 * distinguishers between interfaces. iFunction is prioritized over
2190 * iInterface which matches Windows behavior at the point of writing.
2191 */
2192 if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
2193 function = intf->intf_assoc->iFunction;
2194 else
2195 function = intf->cur_altsetting->desc.iInterface;
2196 if (function != 0) {
2197 size_t len;
2198
2199 strlcat(dev->name, ": ", sizeof(dev->name));
2200 len = strlen(dev->name);
2201 usb_string(udev, function, dev->name + len,
2202 sizeof(dev->name) - len);
2203 }
2204
2205 /* Initialize the media device. */
2206 #ifdef CONFIG_MEDIA_CONTROLLER
2207 dev->mdev.dev = &intf->dev;
2208 strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2209 if (udev->serial)
2210 strscpy(dev->mdev.serial, udev->serial,
2211 sizeof(dev->mdev.serial));
2212 usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2213 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2214 media_device_init(&dev->mdev);
2215
2216 dev->vdev.mdev = &dev->mdev;
2217 #endif
2218
2219 /* Parse the Video Class control descriptor. */
2220 if (uvc_parse_control(dev) < 0) {
2221 uvc_dbg(dev, PROBE, "Unable to parse UVC descriptors\n");
2222 goto error;
2223 }
2224
2225 /* Parse the associated GPIOs. */
2226 if (uvc_gpio_parse(dev) < 0) {
2227 uvc_dbg(dev, PROBE, "Unable to parse UVC GPIOs\n");
2228 goto error;
2229 }
2230
2231 dev_info(&dev->udev->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2232 dev->uvc_version >> 8, dev->uvc_version & 0xff,
2233 udev->product ? udev->product : "<unnamed>",
2234 le16_to_cpu(udev->descriptor.idVendor),
2235 le16_to_cpu(udev->descriptor.idProduct));
2236
2237 if (dev->quirks != dev->info->quirks) {
2238 dev_info(&dev->udev->dev,
2239 "Forcing device quirks to 0x%x by module parameter for testing purpose.\n",
2240 dev->quirks);
2241 dev_info(&dev->udev->dev,
2242 "Please report required quirks to the linux-media mailing list.\n");
2243 }
2244
2245 if (dev->info->uvc_version) {
2246 dev->uvc_version = dev->info->uvc_version;
2247 dev_info(&dev->udev->dev, "Forcing UVC version to %u.%02x\n",
2248 dev->uvc_version >> 8, dev->uvc_version & 0xff);
2249 }
2250
2251 /* Register the V4L2 device. */
2252 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2253 goto error;
2254
2255 /* Scan the device for video chains. */
2256 if (uvc_scan_device(dev) < 0)
2257 goto error;
2258
2259 /* Initialize controls. */
2260 if (uvc_ctrl_init_device(dev) < 0)
2261 goto error;
2262
2263 /* Register video device nodes. */
2264 if (uvc_register_chains(dev) < 0)
2265 goto error;
2266
2267 #ifdef CONFIG_MEDIA_CONTROLLER
2268 /* Register the media device node */
2269 if (media_device_register(&dev->mdev) < 0)
2270 goto error;
2271 #endif
2272 /* Save our data pointer in the interface data. */
2273 usb_set_intfdata(intf, dev);
2274
2275 /* Initialize the interrupt URB. */
2276 ret = uvc_status_init(dev);
2277 if (ret < 0) {
2278 dev_info(&dev->udev->dev,
2279 "Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n",
2280 ret);
2281 }
2282
2283 ret = uvc_gpio_init_irq(dev);
2284 if (ret < 0) {
2285 dev_err(&dev->udev->dev,
2286 "Unable to request privacy GPIO IRQ (%d)\n", ret);
2287 goto error;
2288 }
2289
2290 if (dev->quirks & UVC_QUIRK_NO_RESET_RESUME)
2291 udev->quirks &= ~USB_QUIRK_RESET_RESUME;
2292
2293 if (!(dev->quirks & UVC_QUIRK_DISABLE_AUTOSUSPEND))
2294 usb_enable_autosuspend(udev);
2295
2296 uvc_dbg(dev, PROBE, "UVC device initialized\n");
2297
2298 return 0;
2299
2300 error:
2301 uvc_unregister_video(dev);
2302 kref_put(&dev->ref, uvc_delete);
2303 return -ENODEV;
2304 }
2305
uvc_disconnect(struct usb_interface * intf)2306 static void uvc_disconnect(struct usb_interface *intf)
2307 {
2308 struct uvc_device *dev = usb_get_intfdata(intf);
2309
2310 /*
2311 * Set the USB interface data to NULL. This can be done outside the
2312 * lock, as there's no other reader.
2313 */
2314 usb_set_intfdata(intf, NULL);
2315
2316 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2317 UVC_SC_VIDEOSTREAMING)
2318 return;
2319
2320 uvc_unregister_video(dev);
2321 kref_put(&dev->ref, uvc_delete);
2322 }
2323
uvc_suspend(struct usb_interface * intf,pm_message_t message)2324 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2325 {
2326 struct uvc_device *dev = usb_get_intfdata(intf);
2327 struct uvc_streaming *stream;
2328
2329 uvc_dbg(dev, SUSPEND, "Suspending interface %u\n",
2330 intf->cur_altsetting->desc.bInterfaceNumber);
2331
2332 /* Controls are cached on the fly so they don't need to be saved. */
2333 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2334 UVC_SC_VIDEOCONTROL) {
2335 mutex_lock(&dev->lock);
2336 if (dev->users)
2337 uvc_status_stop(dev);
2338 mutex_unlock(&dev->lock);
2339 return 0;
2340 }
2341
2342 list_for_each_entry(stream, &dev->streams, list) {
2343 if (stream->intf == intf)
2344 return uvc_video_suspend(stream);
2345 }
2346
2347 uvc_dbg(dev, SUSPEND,
2348 "Suspend: video streaming USB interface mismatch\n");
2349 return -EINVAL;
2350 }
2351
__uvc_resume(struct usb_interface * intf,int reset)2352 static int __uvc_resume(struct usb_interface *intf, int reset)
2353 {
2354 struct uvc_device *dev = usb_get_intfdata(intf);
2355 struct uvc_streaming *stream;
2356 int ret = 0;
2357
2358 uvc_dbg(dev, SUSPEND, "Resuming interface %u\n",
2359 intf->cur_altsetting->desc.bInterfaceNumber);
2360
2361 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2362 UVC_SC_VIDEOCONTROL) {
2363 if (reset) {
2364 ret = uvc_ctrl_restore_values(dev);
2365 if (ret < 0)
2366 return ret;
2367 }
2368
2369 mutex_lock(&dev->lock);
2370 if (dev->users)
2371 ret = uvc_status_start(dev, GFP_NOIO);
2372 mutex_unlock(&dev->lock);
2373
2374 return ret;
2375 }
2376
2377 list_for_each_entry(stream, &dev->streams, list) {
2378 if (stream->intf == intf) {
2379 ret = uvc_video_resume(stream, reset);
2380 if (ret < 0)
2381 uvc_queue_streamoff(&stream->queue,
2382 stream->queue.queue.type);
2383 return ret;
2384 }
2385 }
2386
2387 uvc_dbg(dev, SUSPEND,
2388 "Resume: video streaming USB interface mismatch\n");
2389 return -EINVAL;
2390 }
2391
uvc_resume(struct usb_interface * intf)2392 static int uvc_resume(struct usb_interface *intf)
2393 {
2394 return __uvc_resume(intf, 0);
2395 }
2396
uvc_reset_resume(struct usb_interface * intf)2397 static int uvc_reset_resume(struct usb_interface *intf)
2398 {
2399 return __uvc_resume(intf, 1);
2400 }
2401
2402 /* ------------------------------------------------------------------------
2403 * Module parameters
2404 */
2405
uvc_clock_param_get(char * buffer,const struct kernel_param * kp)2406 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2407 {
2408 if (uvc_clock_param == CLOCK_MONOTONIC)
2409 return sprintf(buffer, "CLOCK_MONOTONIC");
2410 else
2411 return sprintf(buffer, "CLOCK_REALTIME");
2412 }
2413
uvc_clock_param_set(const char * val,const struct kernel_param * kp)2414 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2415 {
2416 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2417 val += strlen("clock_");
2418
2419 if (strcasecmp(val, "monotonic") == 0)
2420 uvc_clock_param = CLOCK_MONOTONIC;
2421 else if (strcasecmp(val, "realtime") == 0)
2422 uvc_clock_param = CLOCK_REALTIME;
2423 else
2424 return -EINVAL;
2425
2426 return 0;
2427 }
2428
2429 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2430 &uvc_clock_param, 0644);
2431 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2432 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, 0644);
2433 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2434 module_param_named(nodrop, uvc_no_drop_param, uint, 0644);
2435 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2436 module_param_named(quirks, uvc_quirks_param, uint, 0644);
2437 MODULE_PARM_DESC(quirks, "Forced device quirks");
2438 module_param_named(trace, uvc_dbg_param, uint, 0644);
2439 MODULE_PARM_DESC(trace, "Trace level bitmask");
2440 module_param_named(timeout, uvc_timeout_param, uint, 0644);
2441 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2442
2443 /* ------------------------------------------------------------------------
2444 * Driver initialization and cleanup
2445 */
2446
2447 static const struct uvc_device_info uvc_ctrl_power_line_limited = {
2448 .mappings = (const struct uvc_control_mapping *[]) {
2449 &uvc_ctrl_power_line_mapping_limited,
2450 NULL, /* Sentinel */
2451 },
2452 };
2453
2454 static const struct uvc_device_info uvc_ctrl_power_line_uvc11 = {
2455 .mappings = (const struct uvc_control_mapping *[]) {
2456 &uvc_ctrl_power_line_mapping_uvc11,
2457 NULL, /* Sentinel */
2458 },
2459 };
2460
2461 static const struct uvc_device_info uvc_quirk_probe_minmax = {
2462 .quirks = UVC_QUIRK_PROBE_MINMAX,
2463 };
2464
2465 static const struct uvc_device_info uvc_quirk_fix_bandwidth = {
2466 .quirks = UVC_QUIRK_FIX_BANDWIDTH,
2467 };
2468
2469 static const struct uvc_device_info uvc_quirk_probe_def = {
2470 .quirks = UVC_QUIRK_PROBE_DEF,
2471 };
2472
2473 static const struct uvc_device_info uvc_quirk_stream_no_fid = {
2474 .quirks = UVC_QUIRK_STREAM_NO_FID,
2475 };
2476
2477 static const struct uvc_device_info uvc_quirk_force_y8 = {
2478 .quirks = UVC_QUIRK_FORCE_Y8,
2479 };
2480
2481 #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q}
2482 #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \
2483 {.meta_format = m}
2484
2485 /*
2486 * The Logitech cameras listed below have their interface class set to
2487 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2488 * though they are compliant.
2489 *
2490 * Sort these by vendor/product ID.
2491 */
2492 static const struct usb_device_id uvc_ids[] = {
2493 /* Quanta USB2.0 HD UVC Webcam */
2494 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2495 | USB_DEVICE_ID_MATCH_INT_INFO,
2496 .idVendor = 0x0408,
2497 .idProduct = 0x3090,
2498 .bInterfaceClass = USB_CLASS_VIDEO,
2499 .bInterfaceSubClass = 1,
2500 .bInterfaceProtocol = 0,
2501 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2502 /* Quanta USB2.0 HD UVC Webcam */
2503 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2504 | USB_DEVICE_ID_MATCH_INT_INFO,
2505 .idVendor = 0x0408,
2506 .idProduct = 0x4030,
2507 .bInterfaceClass = USB_CLASS_VIDEO,
2508 .bInterfaceSubClass = 1,
2509 .bInterfaceProtocol = 0,
2510 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2511 /* Quanta USB2.0 HD UVC Webcam */
2512 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2513 | USB_DEVICE_ID_MATCH_INT_INFO,
2514 .idVendor = 0x0408,
2515 .idProduct = 0x4034,
2516 .bInterfaceClass = USB_CLASS_VIDEO,
2517 .bInterfaceSubClass = 1,
2518 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2519 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2520 /* Quanta ACER HD User Facing */
2521 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2522 | USB_DEVICE_ID_MATCH_INT_INFO,
2523 .idVendor = 0x0408,
2524 .idProduct = 0x4033,
2525 .bInterfaceClass = USB_CLASS_VIDEO,
2526 .bInterfaceSubClass = 1,
2527 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2528 .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
2529 .uvc_version = 0x010a,
2530 } },
2531 /* Quanta ACER HD User Facing */
2532 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2533 | USB_DEVICE_ID_MATCH_INT_INFO,
2534 .idVendor = 0x0408,
2535 .idProduct = 0x4035,
2536 .bInterfaceClass = USB_CLASS_VIDEO,
2537 .bInterfaceSubClass = 1,
2538 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2539 .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
2540 .uvc_version = 0x010a,
2541 } },
2542 /* LogiLink Wireless Webcam */
2543 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2544 | USB_DEVICE_ID_MATCH_INT_INFO,
2545 .idVendor = 0x0416,
2546 .idProduct = 0xa91a,
2547 .bInterfaceClass = USB_CLASS_VIDEO,
2548 .bInterfaceSubClass = 1,
2549 .bInterfaceProtocol = 0,
2550 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2551 /* Genius eFace 2025 */
2552 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2553 | USB_DEVICE_ID_MATCH_INT_INFO,
2554 .idVendor = 0x0458,
2555 .idProduct = 0x706e,
2556 .bInterfaceClass = USB_CLASS_VIDEO,
2557 .bInterfaceSubClass = 1,
2558 .bInterfaceProtocol = 0,
2559 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2560 /* Microsoft Lifecam NX-6000 */
2561 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2562 | USB_DEVICE_ID_MATCH_INT_INFO,
2563 .idVendor = 0x045e,
2564 .idProduct = 0x00f8,
2565 .bInterfaceClass = USB_CLASS_VIDEO,
2566 .bInterfaceSubClass = 1,
2567 .bInterfaceProtocol = 0,
2568 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2569 /* Microsoft Lifecam NX-3000 */
2570 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2571 | USB_DEVICE_ID_MATCH_INT_INFO,
2572 .idVendor = 0x045e,
2573 .idProduct = 0x0721,
2574 .bInterfaceClass = USB_CLASS_VIDEO,
2575 .bInterfaceSubClass = 1,
2576 .bInterfaceProtocol = 0,
2577 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2578 /* Microsoft Lifecam VX-7000 */
2579 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2580 | USB_DEVICE_ID_MATCH_INT_INFO,
2581 .idVendor = 0x045e,
2582 .idProduct = 0x0723,
2583 .bInterfaceClass = USB_CLASS_VIDEO,
2584 .bInterfaceSubClass = 1,
2585 .bInterfaceProtocol = 0,
2586 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2587 /* Logitech, Webcam C910 */
2588 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2589 | USB_DEVICE_ID_MATCH_INT_INFO,
2590 .idVendor = 0x046d,
2591 .idProduct = 0x0821,
2592 .bInterfaceClass = USB_CLASS_VIDEO,
2593 .bInterfaceSubClass = 1,
2594 .bInterfaceProtocol = 0,
2595 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
2596 /* Logitech, Webcam B910 */
2597 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2598 | USB_DEVICE_ID_MATCH_INT_INFO,
2599 .idVendor = 0x046d,
2600 .idProduct = 0x0823,
2601 .bInterfaceClass = USB_CLASS_VIDEO,
2602 .bInterfaceSubClass = 1,
2603 .bInterfaceProtocol = 0,
2604 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)},
2605 /* Logitech Quickcam Fusion */
2606 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2607 | USB_DEVICE_ID_MATCH_INT_INFO,
2608 .idVendor = 0x046d,
2609 .idProduct = 0x08c1,
2610 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2611 .bInterfaceSubClass = 1,
2612 .bInterfaceProtocol = 0 },
2613 /* Logitech Quickcam Orbit MP */
2614 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2615 | USB_DEVICE_ID_MATCH_INT_INFO,
2616 .idVendor = 0x046d,
2617 .idProduct = 0x08c2,
2618 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2619 .bInterfaceSubClass = 1,
2620 .bInterfaceProtocol = 0 },
2621 /* Logitech Quickcam Pro for Notebook */
2622 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2623 | USB_DEVICE_ID_MATCH_INT_INFO,
2624 .idVendor = 0x046d,
2625 .idProduct = 0x08c3,
2626 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2627 .bInterfaceSubClass = 1,
2628 .bInterfaceProtocol = 0 },
2629 /* Logitech Quickcam Pro 5000 */
2630 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2631 | USB_DEVICE_ID_MATCH_INT_INFO,
2632 .idVendor = 0x046d,
2633 .idProduct = 0x08c5,
2634 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2635 .bInterfaceSubClass = 1,
2636 .bInterfaceProtocol = 0 },
2637 /* Logitech Quickcam OEM Dell Notebook */
2638 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2639 | USB_DEVICE_ID_MATCH_INT_INFO,
2640 .idVendor = 0x046d,
2641 .idProduct = 0x08c6,
2642 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2643 .bInterfaceSubClass = 1,
2644 .bInterfaceProtocol = 0 },
2645 /* Logitech Quickcam OEM Cisco VT Camera II */
2646 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2647 | USB_DEVICE_ID_MATCH_INT_INFO,
2648 .idVendor = 0x046d,
2649 .idProduct = 0x08c7,
2650 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2651 .bInterfaceSubClass = 1,
2652 .bInterfaceProtocol = 0 },
2653 /* Logitech HD Pro Webcam C920 */
2654 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2655 | USB_DEVICE_ID_MATCH_INT_INFO,
2656 .idVendor = 0x046d,
2657 .idProduct = 0x082d,
2658 .bInterfaceClass = USB_CLASS_VIDEO,
2659 .bInterfaceSubClass = 1,
2660 .bInterfaceProtocol = 0,
2661 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT
2662 | UVC_QUIRK_INVALID_DEVICE_SOF) },
2663 /* Logitech HD Pro Webcam C922 */
2664 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2665 | USB_DEVICE_ID_MATCH_INT_INFO,
2666 .idVendor = 0x046d,
2667 .idProduct = 0x085c,
2668 .bInterfaceClass = USB_CLASS_VIDEO,
2669 .bInterfaceSubClass = 1,
2670 .bInterfaceProtocol = 0,
2671 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_INVALID_DEVICE_SOF) },
2672 /* Logitech Rally Bar Huddle */
2673 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2674 | USB_DEVICE_ID_MATCH_INT_INFO,
2675 .idVendor = 0x046d,
2676 .idProduct = 0x087c,
2677 .bInterfaceClass = USB_CLASS_VIDEO,
2678 .bInterfaceSubClass = 1,
2679 .bInterfaceProtocol = 0,
2680 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
2681 /* Logitech Rally Bar */
2682 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2683 | USB_DEVICE_ID_MATCH_INT_INFO,
2684 .idVendor = 0x046d,
2685 .idProduct = 0x089b,
2686 .bInterfaceClass = USB_CLASS_VIDEO,
2687 .bInterfaceSubClass = 1,
2688 .bInterfaceProtocol = 0,
2689 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
2690 /* Logitech Rally Bar Mini */
2691 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2692 | USB_DEVICE_ID_MATCH_INT_INFO,
2693 .idVendor = 0x046d,
2694 .idProduct = 0x08d3,
2695 .bInterfaceClass = USB_CLASS_VIDEO,
2696 .bInterfaceSubClass = 1,
2697 .bInterfaceProtocol = 0,
2698 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
2699 /* Chicony CNF7129 (Asus EEE 100HE) */
2700 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2701 | USB_DEVICE_ID_MATCH_INT_INFO,
2702 .idVendor = 0x04f2,
2703 .idProduct = 0xb071,
2704 .bInterfaceClass = USB_CLASS_VIDEO,
2705 .bInterfaceSubClass = 1,
2706 .bInterfaceProtocol = 0,
2707 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },
2708 /* Chicony EasyCamera */
2709 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2710 | USB_DEVICE_ID_MATCH_INT_INFO,
2711 .idVendor = 0x04f2,
2712 .idProduct = 0xb5eb,
2713 .bInterfaceClass = USB_CLASS_VIDEO,
2714 .bInterfaceSubClass = 1,
2715 .bInterfaceProtocol = 0,
2716 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2717 /* Chicony Electronics Co., Ltd Integrated Camera */
2718 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2719 | USB_DEVICE_ID_MATCH_INT_INFO,
2720 .idVendor = 0x04f2,
2721 .idProduct = 0xb67c,
2722 .bInterfaceClass = USB_CLASS_VIDEO,
2723 .bInterfaceSubClass = 1,
2724 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
2725 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 },
2726 /* Chicony EasyCamera */
2727 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2728 | USB_DEVICE_ID_MATCH_INT_INFO,
2729 .idVendor = 0x04f2,
2730 .idProduct = 0xb6ba,
2731 .bInterfaceClass = USB_CLASS_VIDEO,
2732 .bInterfaceSubClass = 1,
2733 .bInterfaceProtocol = 0,
2734 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2735 /* Chicony EasyCamera */
2736 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2737 | USB_DEVICE_ID_MATCH_INT_INFO,
2738 .idVendor = 0x04f2,
2739 .idProduct = 0xb746,
2740 .bInterfaceClass = USB_CLASS_VIDEO,
2741 .bInterfaceSubClass = 1,
2742 .bInterfaceProtocol = 0,
2743 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
2744 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2745 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2746 | USB_DEVICE_ID_MATCH_INT_INFO,
2747 .idVendor = 0x058f,
2748 .idProduct = 0x3820,
2749 .bInterfaceClass = USB_CLASS_VIDEO,
2750 .bInterfaceSubClass = 1,
2751 .bInterfaceProtocol = 0,
2752 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2753 /* Dell XPS m1530 */
2754 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2755 | USB_DEVICE_ID_MATCH_INT_INFO,
2756 .idVendor = 0x05a9,
2757 .idProduct = 0x2640,
2758 .bInterfaceClass = USB_CLASS_VIDEO,
2759 .bInterfaceSubClass = 1,
2760 .bInterfaceProtocol = 0,
2761 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2762 /* Dell SP2008WFP Monitor */
2763 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2764 | USB_DEVICE_ID_MATCH_INT_INFO,
2765 .idVendor = 0x05a9,
2766 .idProduct = 0x2641,
2767 .bInterfaceClass = USB_CLASS_VIDEO,
2768 .bInterfaceSubClass = 1,
2769 .bInterfaceProtocol = 0,
2770 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2771 /* Dell Alienware X51 */
2772 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2773 | USB_DEVICE_ID_MATCH_INT_INFO,
2774 .idVendor = 0x05a9,
2775 .idProduct = 0x2643,
2776 .bInterfaceClass = USB_CLASS_VIDEO,
2777 .bInterfaceSubClass = 1,
2778 .bInterfaceProtocol = 0,
2779 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2780 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2781 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2782 | USB_DEVICE_ID_MATCH_INT_INFO,
2783 .idVendor = 0x05a9,
2784 .idProduct = 0x264a,
2785 .bInterfaceClass = USB_CLASS_VIDEO,
2786 .bInterfaceSubClass = 1,
2787 .bInterfaceProtocol = 0,
2788 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2789 /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2790 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2791 | USB_DEVICE_ID_MATCH_INT_INFO,
2792 .idVendor = 0x05a9,
2793 .idProduct = 0x7670,
2794 .bInterfaceClass = USB_CLASS_VIDEO,
2795 .bInterfaceSubClass = 1,
2796 .bInterfaceProtocol = 0,
2797 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2798 /* Apple Built-In iSight */
2799 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2800 | USB_DEVICE_ID_MATCH_INT_INFO,
2801 .idVendor = 0x05ac,
2802 .idProduct = 0x8501,
2803 .bInterfaceClass = USB_CLASS_VIDEO,
2804 .bInterfaceSubClass = 1,
2805 .bInterfaceProtocol = 0,
2806 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2807 | UVC_QUIRK_BUILTIN_ISIGHT) },
2808 /* Apple FaceTime HD Camera (Built-In) */
2809 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2810 | USB_DEVICE_ID_MATCH_INT_INFO,
2811 .idVendor = 0x05ac,
2812 .idProduct = 0x8514,
2813 .bInterfaceClass = USB_CLASS_VIDEO,
2814 .bInterfaceSubClass = 1,
2815 .bInterfaceProtocol = 0,
2816 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2817 /* Apple Built-In iSight via iBridge */
2818 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2819 | USB_DEVICE_ID_MATCH_INT_INFO,
2820 .idVendor = 0x05ac,
2821 .idProduct = 0x8600,
2822 .bInterfaceClass = USB_CLASS_VIDEO,
2823 .bInterfaceSubClass = 1,
2824 .bInterfaceProtocol = 0,
2825 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
2826 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2827 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2828 | USB_DEVICE_ID_MATCH_INT_INFO,
2829 .idVendor = 0x05c8,
2830 .idProduct = 0x0403,
2831 .bInterfaceClass = USB_CLASS_VIDEO,
2832 .bInterfaceSubClass = 1,
2833 .bInterfaceProtocol = 0,
2834 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2835 /* Genesys Logic USB 2.0 PC Camera */
2836 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2837 | USB_DEVICE_ID_MATCH_INT_INFO,
2838 .idVendor = 0x05e3,
2839 .idProduct = 0x0505,
2840 .bInterfaceClass = USB_CLASS_VIDEO,
2841 .bInterfaceSubClass = 1,
2842 .bInterfaceProtocol = 0,
2843 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2844 /* Hercules Classic Silver */
2845 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2846 | USB_DEVICE_ID_MATCH_INT_INFO,
2847 .idVendor = 0x06f8,
2848 .idProduct = 0x300c,
2849 .bInterfaceClass = USB_CLASS_VIDEO,
2850 .bInterfaceSubClass = 1,
2851 .bInterfaceProtocol = 0,
2852 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2853 /* ViMicro Vega */
2854 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2855 | USB_DEVICE_ID_MATCH_INT_INFO,
2856 .idVendor = 0x0ac8,
2857 .idProduct = 0x332d,
2858 .bInterfaceClass = USB_CLASS_VIDEO,
2859 .bInterfaceSubClass = 1,
2860 .bInterfaceProtocol = 0,
2861 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2862 /* ViMicro - Minoru3D */
2863 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2864 | USB_DEVICE_ID_MATCH_INT_INFO,
2865 .idVendor = 0x0ac8,
2866 .idProduct = 0x3410,
2867 .bInterfaceClass = USB_CLASS_VIDEO,
2868 .bInterfaceSubClass = 1,
2869 .bInterfaceProtocol = 0,
2870 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2871 /* ViMicro Venus - Minoru3D */
2872 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2873 | USB_DEVICE_ID_MATCH_INT_INFO,
2874 .idVendor = 0x0ac8,
2875 .idProduct = 0x3420,
2876 .bInterfaceClass = USB_CLASS_VIDEO,
2877 .bInterfaceSubClass = 1,
2878 .bInterfaceProtocol = 0,
2879 .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2880 /* Ophir Optronics - SPCAM 620U */
2881 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2882 | USB_DEVICE_ID_MATCH_INT_INFO,
2883 .idVendor = 0x0bd3,
2884 .idProduct = 0x0555,
2885 .bInterfaceClass = USB_CLASS_VIDEO,
2886 .bInterfaceSubClass = 1,
2887 .bInterfaceProtocol = 0,
2888 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2889 /* Sonix Technology Co. Ltd. - 292A IPC AR0330 */
2890 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2891 | USB_DEVICE_ID_MATCH_INT_INFO,
2892 .idVendor = 0x0c45,
2893 .idProduct = 0x6366,
2894 .bInterfaceClass = USB_CLASS_VIDEO,
2895 .bInterfaceSubClass = 1,
2896 .bInterfaceProtocol = 0,
2897 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) },
2898 /* MT6227 */
2899 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2900 | USB_DEVICE_ID_MATCH_INT_INFO,
2901 .idVendor = 0x0e8d,
2902 .idProduct = 0x0004,
2903 .bInterfaceClass = USB_CLASS_VIDEO,
2904 .bInterfaceSubClass = 1,
2905 .bInterfaceProtocol = 0,
2906 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2907 | UVC_QUIRK_PROBE_DEF) },
2908 /* IMC Networks (Medion Akoya) */
2909 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2910 | USB_DEVICE_ID_MATCH_INT_INFO,
2911 .idVendor = 0x13d3,
2912 .idProduct = 0x5103,
2913 .bInterfaceClass = USB_CLASS_VIDEO,
2914 .bInterfaceSubClass = 1,
2915 .bInterfaceProtocol = 0,
2916 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2917 /* JMicron USB2.0 XGA WebCam */
2918 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2919 | USB_DEVICE_ID_MATCH_INT_INFO,
2920 .idVendor = 0x152d,
2921 .idProduct = 0x0310,
2922 .bInterfaceClass = USB_CLASS_VIDEO,
2923 .bInterfaceSubClass = 1,
2924 .bInterfaceProtocol = 0,
2925 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
2926 /* Kurokesu C1 PRO */
2927 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2928 | USB_DEVICE_ID_MATCH_INT_INFO,
2929 .idVendor = 0x16d0,
2930 .idProduct = 0x0ed1,
2931 .bInterfaceClass = USB_CLASS_VIDEO,
2932 .bInterfaceSubClass = 1,
2933 .bInterfaceProtocol = 0,
2934 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) },
2935 /* Syntek (HP Spartan) */
2936 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2937 | USB_DEVICE_ID_MATCH_INT_INFO,
2938 .idVendor = 0x174f,
2939 .idProduct = 0x5212,
2940 .bInterfaceClass = USB_CLASS_VIDEO,
2941 .bInterfaceSubClass = 1,
2942 .bInterfaceProtocol = 0,
2943 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2944 /* Syntek (Samsung Q310) */
2945 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2946 | USB_DEVICE_ID_MATCH_INT_INFO,
2947 .idVendor = 0x174f,
2948 .idProduct = 0x5931,
2949 .bInterfaceClass = USB_CLASS_VIDEO,
2950 .bInterfaceSubClass = 1,
2951 .bInterfaceProtocol = 0,
2952 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2953 /* Syntek (Packard Bell EasyNote MX52 */
2954 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2955 | USB_DEVICE_ID_MATCH_INT_INFO,
2956 .idVendor = 0x174f,
2957 .idProduct = 0x8a12,
2958 .bInterfaceClass = USB_CLASS_VIDEO,
2959 .bInterfaceSubClass = 1,
2960 .bInterfaceProtocol = 0,
2961 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2962 /* Syntek (Asus F9SG) */
2963 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2964 | USB_DEVICE_ID_MATCH_INT_INFO,
2965 .idVendor = 0x174f,
2966 .idProduct = 0x8a31,
2967 .bInterfaceClass = USB_CLASS_VIDEO,
2968 .bInterfaceSubClass = 1,
2969 .bInterfaceProtocol = 0,
2970 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2971 /* Syntek (Asus U3S) */
2972 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2973 | USB_DEVICE_ID_MATCH_INT_INFO,
2974 .idVendor = 0x174f,
2975 .idProduct = 0x8a33,
2976 .bInterfaceClass = USB_CLASS_VIDEO,
2977 .bInterfaceSubClass = 1,
2978 .bInterfaceProtocol = 0,
2979 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2980 /* Syntek (JAOtech Smart Terminal) */
2981 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2982 | USB_DEVICE_ID_MATCH_INT_INFO,
2983 .idVendor = 0x174f,
2984 .idProduct = 0x8a34,
2985 .bInterfaceClass = USB_CLASS_VIDEO,
2986 .bInterfaceSubClass = 1,
2987 .bInterfaceProtocol = 0,
2988 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2989 /* Miricle 307K */
2990 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2991 | USB_DEVICE_ID_MATCH_INT_INFO,
2992 .idVendor = 0x17dc,
2993 .idProduct = 0x0202,
2994 .bInterfaceClass = USB_CLASS_VIDEO,
2995 .bInterfaceSubClass = 1,
2996 .bInterfaceProtocol = 0,
2997 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2998 /* Lenovo Thinkpad SL400/SL500 */
2999 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3000 | USB_DEVICE_ID_MATCH_INT_INFO,
3001 .idVendor = 0x17ef,
3002 .idProduct = 0x480b,
3003 .bInterfaceClass = USB_CLASS_VIDEO,
3004 .bInterfaceSubClass = 1,
3005 .bInterfaceProtocol = 0,
3006 .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid },
3007 /* Aveo Technology USB 2.0 Camera */
3008 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3009 | USB_DEVICE_ID_MATCH_INT_INFO,
3010 .idVendor = 0x1871,
3011 .idProduct = 0x0306,
3012 .bInterfaceClass = USB_CLASS_VIDEO,
3013 .bInterfaceSubClass = 1,
3014 .bInterfaceProtocol = 0,
3015 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
3016 | UVC_QUIRK_PROBE_EXTRAFIELDS) },
3017 /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
3018 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3019 | USB_DEVICE_ID_MATCH_INT_INFO,
3020 .idVendor = 0x1871,
3021 .idProduct = 0x0516,
3022 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3023 .bInterfaceSubClass = 1,
3024 .bInterfaceProtocol = 0 },
3025 /* Ecamm Pico iMage */
3026 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3027 | USB_DEVICE_ID_MATCH_INT_INFO,
3028 .idVendor = 0x18cd,
3029 .idProduct = 0xcafe,
3030 .bInterfaceClass = USB_CLASS_VIDEO,
3031 .bInterfaceSubClass = 1,
3032 .bInterfaceProtocol = 0,
3033 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) },
3034 /* Manta MM-353 Plako */
3035 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3036 | USB_DEVICE_ID_MATCH_INT_INFO,
3037 .idVendor = 0x18ec,
3038 .idProduct = 0x3188,
3039 .bInterfaceClass = USB_CLASS_VIDEO,
3040 .bInterfaceSubClass = 1,
3041 .bInterfaceProtocol = 0,
3042 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3043 /* FSC WebCam V30S */
3044 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3045 | USB_DEVICE_ID_MATCH_INT_INFO,
3046 .idVendor = 0x18ec,
3047 .idProduct = 0x3288,
3048 .bInterfaceClass = USB_CLASS_VIDEO,
3049 .bInterfaceSubClass = 1,
3050 .bInterfaceProtocol = 0,
3051 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3052 /* Arkmicro unbranded */
3053 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3054 | USB_DEVICE_ID_MATCH_INT_INFO,
3055 .idVendor = 0x18ec,
3056 .idProduct = 0x3290,
3057 .bInterfaceClass = USB_CLASS_VIDEO,
3058 .bInterfaceSubClass = 1,
3059 .bInterfaceProtocol = 0,
3060 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def },
3061 /* The Imaging Source USB CCD cameras */
3062 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3063 | USB_DEVICE_ID_MATCH_INT_INFO,
3064 .idVendor = 0x199e,
3065 .idProduct = 0x8102,
3066 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3067 .bInterfaceSubClass = 1,
3068 .bInterfaceProtocol = 0 },
3069 /* Bodelin ProScopeHR */
3070 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3071 | USB_DEVICE_ID_MATCH_DEV_HI
3072 | USB_DEVICE_ID_MATCH_INT_INFO,
3073 .idVendor = 0x19ab,
3074 .idProduct = 0x1000,
3075 .bcdDevice_hi = 0x0126,
3076 .bInterfaceClass = USB_CLASS_VIDEO,
3077 .bInterfaceSubClass = 1,
3078 .bInterfaceProtocol = 0,
3079 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) },
3080 /* MSI StarCam 370i */
3081 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3082 | USB_DEVICE_ID_MATCH_INT_INFO,
3083 .idVendor = 0x1b3b,
3084 .idProduct = 0x2951,
3085 .bInterfaceClass = USB_CLASS_VIDEO,
3086 .bInterfaceSubClass = 1,
3087 .bInterfaceProtocol = 0,
3088 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3089 /* Generalplus Technology Inc. 808 Camera */
3090 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3091 | USB_DEVICE_ID_MATCH_INT_INFO,
3092 .idVendor = 0x1b3f,
3093 .idProduct = 0x2002,
3094 .bInterfaceClass = USB_CLASS_VIDEO,
3095 .bInterfaceSubClass = 1,
3096 .bInterfaceProtocol = 0,
3097 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3098 /* Shenzhen Aoni Electronic Co.,Ltd 2K FHD camera */
3099 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3100 | USB_DEVICE_ID_MATCH_INT_INFO,
3101 .idVendor = 0x1bcf,
3102 .idProduct = 0x0b40,
3103 .bInterfaceClass = USB_CLASS_VIDEO,
3104 .bInterfaceSubClass = 1,
3105 .bInterfaceProtocol = 0,
3106 .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){
3107 .uvc_version = 0x010a,
3108 } },
3109 /* SiGma Micro USB Web Camera */
3110 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3111 | USB_DEVICE_ID_MATCH_INT_INFO,
3112 .idVendor = 0x1c4f,
3113 .idProduct = 0x3000,
3114 .bInterfaceClass = USB_CLASS_VIDEO,
3115 .bInterfaceSubClass = 1,
3116 .bInterfaceProtocol = 0,
3117 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
3118 | UVC_QUIRK_IGNORE_SELECTOR_UNIT) },
3119 /* NXP Semiconductors IR VIDEO */
3120 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3121 | USB_DEVICE_ID_MATCH_INT_INFO,
3122 .idVendor = 0x1fc9,
3123 .idProduct = 0x009b,
3124 .bInterfaceClass = USB_CLASS_VIDEO,
3125 .bInterfaceSubClass = 1,
3126 .bInterfaceProtocol = 0,
3127 .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax },
3128 /* Oculus VR Positional Tracker DK2 */
3129 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3130 | USB_DEVICE_ID_MATCH_INT_INFO,
3131 .idVendor = 0x2833,
3132 .idProduct = 0x0201,
3133 .bInterfaceClass = USB_CLASS_VIDEO,
3134 .bInterfaceSubClass = 1,
3135 .bInterfaceProtocol = 0,
3136 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
3137 /* Oculus VR Rift Sensor */
3138 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3139 | USB_DEVICE_ID_MATCH_INT_INFO,
3140 .idVendor = 0x2833,
3141 .idProduct = 0x0211,
3142 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
3143 .bInterfaceSubClass = 1,
3144 .bInterfaceProtocol = 0,
3145 .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 },
3146 /* GEO Semiconductor GC6500 */
3147 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3148 | USB_DEVICE_ID_MATCH_INT_INFO,
3149 .idVendor = 0x29fe,
3150 .idProduct = 0x4d53,
3151 .bInterfaceClass = USB_CLASS_VIDEO,
3152 .bInterfaceSubClass = 1,
3153 .bInterfaceProtocol = 0,
3154 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) },
3155 /* SunplusIT Inc HD Camera */
3156 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3157 | USB_DEVICE_ID_MATCH_INT_INFO,
3158 .idVendor = 0x2b7e,
3159 .idProduct = 0xb752,
3160 .bInterfaceClass = USB_CLASS_VIDEO,
3161 .bInterfaceSubClass = 1,
3162 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
3163 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 },
3164 /* Insta360 Link */
3165 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3166 | USB_DEVICE_ID_MATCH_INT_INFO,
3167 .idVendor = 0x2e1a,
3168 .idProduct = 0x4c01,
3169 .bInterfaceClass = USB_CLASS_VIDEO,
3170 .bInterfaceSubClass = 1,
3171 .bInterfaceProtocol = 0,
3172 .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) },
3173 /* Lenovo Integrated Camera */
3174 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3175 | USB_DEVICE_ID_MATCH_INT_INFO,
3176 .idVendor = 0x30c9,
3177 .idProduct = 0x0093,
3178 .bInterfaceClass = USB_CLASS_VIDEO,
3179 .bInterfaceSubClass = 1,
3180 .bInterfaceProtocol = UVC_PC_PROTOCOL_15,
3181 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 },
3182 /* Sonix Technology USB 2.0 Camera */
3183 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3184 | USB_DEVICE_ID_MATCH_INT_INFO,
3185 .idVendor = 0x3277,
3186 .idProduct = 0x0072,
3187 .bInterfaceClass = USB_CLASS_VIDEO,
3188 .bInterfaceSubClass = 1,
3189 .bInterfaceProtocol = 0,
3190 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3191 /* Acer EasyCamera */
3192 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3193 | USB_DEVICE_ID_MATCH_INT_INFO,
3194 .idVendor = 0x5986,
3195 .idProduct = 0x1172,
3196 .bInterfaceClass = USB_CLASS_VIDEO,
3197 .bInterfaceSubClass = 1,
3198 .bInterfaceProtocol = 0,
3199 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3200 /* Acer EasyCamera */
3201 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3202 | USB_DEVICE_ID_MATCH_INT_INFO,
3203 .idVendor = 0x5986,
3204 .idProduct = 0x1180,
3205 .bInterfaceClass = USB_CLASS_VIDEO,
3206 .bInterfaceSubClass = 1,
3207 .bInterfaceProtocol = 0,
3208 .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },
3209 /* Intel D410/ASR depth camera */
3210 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3211 | USB_DEVICE_ID_MATCH_INT_INFO,
3212 .idVendor = 0x8086,
3213 .idProduct = 0x0ad2,
3214 .bInterfaceClass = USB_CLASS_VIDEO,
3215 .bInterfaceSubClass = 1,
3216 .bInterfaceProtocol = 0,
3217 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3218 /* Intel D415/ASRC depth camera */
3219 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3220 | USB_DEVICE_ID_MATCH_INT_INFO,
3221 .idVendor = 0x8086,
3222 .idProduct = 0x0ad3,
3223 .bInterfaceClass = USB_CLASS_VIDEO,
3224 .bInterfaceSubClass = 1,
3225 .bInterfaceProtocol = 0,
3226 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3227 /* Intel D430/AWG depth camera */
3228 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3229 | USB_DEVICE_ID_MATCH_INT_INFO,
3230 .idVendor = 0x8086,
3231 .idProduct = 0x0ad4,
3232 .bInterfaceClass = USB_CLASS_VIDEO,
3233 .bInterfaceSubClass = 1,
3234 .bInterfaceProtocol = 0,
3235 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3236 /* Intel RealSense D4M */
3237 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3238 | USB_DEVICE_ID_MATCH_INT_INFO,
3239 .idVendor = 0x8086,
3240 .idProduct = 0x0b03,
3241 .bInterfaceClass = USB_CLASS_VIDEO,
3242 .bInterfaceSubClass = 1,
3243 .bInterfaceProtocol = 0,
3244 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3245 /* Intel D435/AWGC depth camera */
3246 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3247 | USB_DEVICE_ID_MATCH_INT_INFO,
3248 .idVendor = 0x8086,
3249 .idProduct = 0x0b07,
3250 .bInterfaceClass = USB_CLASS_VIDEO,
3251 .bInterfaceSubClass = 1,
3252 .bInterfaceProtocol = 0,
3253 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3254 /* Intel D435i depth camera */
3255 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3256 | USB_DEVICE_ID_MATCH_INT_INFO,
3257 .idVendor = 0x8086,
3258 .idProduct = 0x0b3a,
3259 .bInterfaceClass = USB_CLASS_VIDEO,
3260 .bInterfaceSubClass = 1,
3261 .bInterfaceProtocol = 0,
3262 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3263 /* Intel D405 Depth Camera */
3264 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3265 | USB_DEVICE_ID_MATCH_INT_INFO,
3266 .idVendor = 0x8086,
3267 .idProduct = 0x0b5b,
3268 .bInterfaceClass = USB_CLASS_VIDEO,
3269 .bInterfaceSubClass = 1,
3270 .bInterfaceProtocol = 0,
3271 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3272 /* Intel D455 Depth Camera */
3273 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3274 | USB_DEVICE_ID_MATCH_INT_INFO,
3275 .idVendor = 0x8086,
3276 .idProduct = 0x0b5c,
3277 .bInterfaceClass = USB_CLASS_VIDEO,
3278 .bInterfaceSubClass = 1,
3279 .bInterfaceProtocol = 0,
3280 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3281 /* Intel D421 Depth Module */
3282 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
3283 | USB_DEVICE_ID_MATCH_INT_INFO,
3284 .idVendor = 0x8086,
3285 .idProduct = 0x1155,
3286 .bInterfaceClass = USB_CLASS_VIDEO,
3287 .bInterfaceSubClass = 1,
3288 .bInterfaceProtocol = 0,
3289 .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) },
3290 /* Generic USB Video Class */
3291 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
3292 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
3293 {}
3294 };
3295
3296 MODULE_DEVICE_TABLE(usb, uvc_ids);
3297
3298 struct uvc_driver uvc_driver = {
3299 .driver = {
3300 .name = "uvcvideo",
3301 .probe = uvc_probe,
3302 .disconnect = uvc_disconnect,
3303 .suspend = uvc_suspend,
3304 .resume = uvc_resume,
3305 .reset_resume = uvc_reset_resume,
3306 .id_table = uvc_ids,
3307 .supports_autosuspend = 1,
3308 },
3309 };
3310
uvc_init(void)3311 static int __init uvc_init(void)
3312 {
3313 int ret;
3314
3315 uvc_debugfs_init();
3316
3317 ret = usb_register(&uvc_driver.driver);
3318 if (ret < 0) {
3319 uvc_debugfs_cleanup();
3320 return ret;
3321 }
3322
3323 return 0;
3324 }
3325
uvc_cleanup(void)3326 static void __exit uvc_cleanup(void)
3327 {
3328 usb_deregister(&uvc_driver.driver);
3329 uvc_debugfs_cleanup();
3330 }
3331
3332 module_init(uvc_init);
3333 module_exit(uvc_cleanup);
3334
3335 MODULE_AUTHOR(DRIVER_AUTHOR);
3336 MODULE_DESCRIPTION(DRIVER_DESC);
3337 MODULE_LICENSE("GPL");
3338 MODULE_VERSION(DRIVER_VERSION);
3339
3340