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