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