1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/atomic.h>
15#include <linux/kernel.h>
16#include <linux/list.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/usb.h>
20#include <linux/videodev2.h>
21#include <linux/vmalloc.h>
22#include <linux/wait.h>
23#include <linux/version.h>
24#include <asm/unaligned.h>
25
26#include <media/v4l2-common.h>
27
28#include "uvcvideo.h"
29
30#define DRIVER_AUTHOR "Laurent Pinchart " \
31 "<laurent.pinchart@ideasonboard.com>"
32#define DRIVER_DESC "USB Video Class driver"
33
34unsigned int uvc_clock_param = CLOCK_MONOTONIC;
35unsigned int uvc_hw_timestamps_param;
36unsigned int uvc_no_drop_param;
37static unsigned int uvc_quirks_param = -1;
38unsigned int uvc_trace_param;
39unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
40
41
42
43
44
45static struct uvc_format_desc uvc_fmts[] = {
46 {
47 .name = "YUV 4:2:2 (YUYV)",
48 .guid = UVC_GUID_FORMAT_YUY2,
49 .fcc = V4L2_PIX_FMT_YUYV,
50 },
51 {
52 .name = "YUV 4:2:2 (YUYV)",
53 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
54 .fcc = V4L2_PIX_FMT_YUYV,
55 },
56 {
57 .name = "YUV 4:2:0 (NV12)",
58 .guid = UVC_GUID_FORMAT_NV12,
59 .fcc = V4L2_PIX_FMT_NV12,
60 },
61 {
62 .name = "MJPEG",
63 .guid = UVC_GUID_FORMAT_MJPEG,
64 .fcc = V4L2_PIX_FMT_MJPEG,
65 },
66 {
67 .name = "YVU 4:2:0 (YV12)",
68 .guid = UVC_GUID_FORMAT_YV12,
69 .fcc = V4L2_PIX_FMT_YVU420,
70 },
71 {
72 .name = "YUV 4:2:0 (I420)",
73 .guid = UVC_GUID_FORMAT_I420,
74 .fcc = V4L2_PIX_FMT_YUV420,
75 },
76 {
77 .name = "YUV 4:2:0 (M420)",
78 .guid = UVC_GUID_FORMAT_M420,
79 .fcc = V4L2_PIX_FMT_M420,
80 },
81 {
82 .name = "YUV 4:2:2 (UYVY)",
83 .guid = UVC_GUID_FORMAT_UYVY,
84 .fcc = V4L2_PIX_FMT_UYVY,
85 },
86 {
87 .name = "Greyscale 8-bit (Y800)",
88 .guid = UVC_GUID_FORMAT_Y800,
89 .fcc = V4L2_PIX_FMT_GREY,
90 },
91 {
92 .name = "Greyscale 8-bit (Y8 )",
93 .guid = UVC_GUID_FORMAT_Y8,
94 .fcc = V4L2_PIX_FMT_GREY,
95 },
96 {
97 .name = "Greyscale 10-bit (Y10 )",
98 .guid = UVC_GUID_FORMAT_Y10,
99 .fcc = V4L2_PIX_FMT_Y10,
100 },
101 {
102 .name = "Greyscale 12-bit (Y12 )",
103 .guid = UVC_GUID_FORMAT_Y12,
104 .fcc = V4L2_PIX_FMT_Y12,
105 },
106 {
107 .name = "Greyscale 16-bit (Y16 )",
108 .guid = UVC_GUID_FORMAT_Y16,
109 .fcc = V4L2_PIX_FMT_Y16,
110 },
111 {
112 .name = "BGGR Bayer (BY8 )",
113 .guid = UVC_GUID_FORMAT_BY8,
114 .fcc = V4L2_PIX_FMT_SBGGR8,
115 },
116 {
117 .name = "BGGR Bayer (BA81)",
118 .guid = UVC_GUID_FORMAT_BA81,
119 .fcc = V4L2_PIX_FMT_SBGGR8,
120 },
121 {
122 .name = "GBRG Bayer (GBRG)",
123 .guid = UVC_GUID_FORMAT_GBRG,
124 .fcc = V4L2_PIX_FMT_SGBRG8,
125 },
126 {
127 .name = "GRBG Bayer (GRBG)",
128 .guid = UVC_GUID_FORMAT_GRBG,
129 .fcc = V4L2_PIX_FMT_SGRBG8,
130 },
131 {
132 .name = "RGGB Bayer (RGGB)",
133 .guid = UVC_GUID_FORMAT_RGGB,
134 .fcc = V4L2_PIX_FMT_SRGGB8,
135 },
136 {
137 .name = "RGB565",
138 .guid = UVC_GUID_FORMAT_RGBP,
139 .fcc = V4L2_PIX_FMT_RGB565,
140 },
141 {
142 .name = "BGR 8:8:8 (BGR3)",
143 .guid = UVC_GUID_FORMAT_BGR3,
144 .fcc = V4L2_PIX_FMT_BGR24,
145 },
146 {
147 .name = "H.264",
148 .guid = UVC_GUID_FORMAT_H264,
149 .fcc = V4L2_PIX_FMT_H264,
150 },
151 {
152 .name = "Greyscale 8 L/R (Y8I)",
153 .guid = UVC_GUID_FORMAT_Y8I,
154 .fcc = V4L2_PIX_FMT_Y8I,
155 },
156 {
157 .name = "Greyscale 12 L/R (Y12I)",
158 .guid = UVC_GUID_FORMAT_Y12I,
159 .fcc = V4L2_PIX_FMT_Y12I,
160 },
161 {
162 .name = "Depth data 16-bit (Z16)",
163 .guid = UVC_GUID_FORMAT_Z16,
164 .fcc = V4L2_PIX_FMT_Z16,
165 },
166 {
167 .name = "Bayer 10-bit (SRGGB10P)",
168 .guid = UVC_GUID_FORMAT_RW10,
169 .fcc = V4L2_PIX_FMT_SRGGB10P,
170 },
171};
172
173
174
175
176
177struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
178 __u8 epaddr)
179{
180 struct usb_host_endpoint *ep;
181 unsigned int i;
182
183 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
184 ep = &alts->endpoint[i];
185 if (ep->desc.bEndpointAddress == epaddr)
186 return ep;
187 }
188
189 return NULL;
190}
191
192static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
193{
194 unsigned int len = ARRAY_SIZE(uvc_fmts);
195 unsigned int i;
196
197 for (i = 0; i < len; ++i) {
198 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
199 return &uvc_fmts[i];
200 }
201
202 return NULL;
203}
204
205static __u32 uvc_colorspace(const __u8 primaries)
206{
207 static const __u8 colorprimaries[] = {
208 0,
209 V4L2_COLORSPACE_SRGB,
210 V4L2_COLORSPACE_470_SYSTEM_M,
211 V4L2_COLORSPACE_470_SYSTEM_BG,
212 V4L2_COLORSPACE_SMPTE170M,
213 V4L2_COLORSPACE_SMPTE240M,
214 };
215
216 if (primaries < ARRAY_SIZE(colorprimaries))
217 return colorprimaries[primaries];
218
219 return 0;
220}
221
222
223
224
225
226
227
228
229void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
230 unsigned int n_terms, unsigned int threshold)
231{
232 uint32_t *an;
233 uint32_t x, y, r;
234 unsigned int i, n;
235
236 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
237 if (an == NULL)
238 return;
239
240
241
242
243
244
245 x = *numerator;
246 y = *denominator;
247
248 for (n = 0; n < n_terms && y != 0; ++n) {
249 an[n] = x / y;
250 if (an[n] >= threshold) {
251 if (n < 2)
252 n++;
253 break;
254 }
255
256 r = x - an[n] * y;
257 x = y;
258 y = r;
259 }
260
261
262 x = 0;
263 y = 1;
264
265 for (i = n; i > 0; --i) {
266 r = y;
267 y = an[i-1] * y + x;
268 x = r;
269 }
270
271 *numerator = y;
272 *denominator = x;
273 kfree(an);
274}
275
276
277
278
279
280uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
281{
282 uint32_t multiplier;
283
284
285 if (denominator == 0 ||
286 numerator/denominator >= ((uint32_t)-1)/10000000)
287 return (uint32_t)-1;
288
289
290
291
292
293 multiplier = 10000000;
294 while (numerator > ((uint32_t)-1)/multiplier) {
295 multiplier /= 2;
296 denominator /= 2;
297 }
298
299 return denominator ? numerator * multiplier / denominator : 0;
300}
301
302
303
304
305
306struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
307{
308 struct uvc_entity *entity;
309
310 list_for_each_entry(entity, &dev->entities, list) {
311 if (entity->id == id)
312 return entity;
313 }
314
315 return NULL;
316}
317
318static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
319 int id, struct uvc_entity *entity)
320{
321 unsigned int i;
322
323 if (entity == NULL)
324 entity = list_entry(&dev->entities, struct uvc_entity, list);
325
326 list_for_each_entry_continue(entity, &dev->entities, list) {
327 for (i = 0; i < entity->bNrInPins; ++i)
328 if (entity->baSourceID[i] == id)
329 return entity;
330 }
331
332 return NULL;
333}
334
335static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
336{
337 struct uvc_streaming *stream;
338
339 list_for_each_entry(stream, &dev->streams, list) {
340 if (stream->header.bTerminalLink == id)
341 return stream;
342 }
343
344 return NULL;
345}
346
347
348
349
350
351static int uvc_parse_format(struct uvc_device *dev,
352 struct uvc_streaming *streaming, struct uvc_format *format,
353 __u32 **intervals, unsigned char *buffer, int buflen)
354{
355 struct usb_interface *intf = streaming->intf;
356 struct usb_host_interface *alts = intf->cur_altsetting;
357 struct uvc_format_desc *fmtdesc;
358 struct uvc_frame *frame;
359 const unsigned char *start = buffer;
360 unsigned int width_multiplier = 1;
361 unsigned int interval;
362 unsigned int i, n;
363 __u8 ftype;
364
365 format->type = buffer[2];
366 format->index = buffer[3];
367
368 switch (buffer[2]) {
369 case UVC_VS_FORMAT_UNCOMPRESSED:
370 case UVC_VS_FORMAT_FRAME_BASED:
371 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
372 if (buflen < n) {
373 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
374 "interface %d FORMAT error\n",
375 dev->udev->devnum,
376 alts->desc.bInterfaceNumber);
377 return -EINVAL;
378 }
379
380
381 fmtdesc = uvc_format_by_guid(&buffer[5]);
382
383 if (fmtdesc != NULL) {
384 strlcpy(format->name, fmtdesc->name,
385 sizeof format->name);
386 format->fcc = fmtdesc->fcc;
387 } else {
388 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
389 &buffer[5]);
390 snprintf(format->name, sizeof(format->name), "%pUl\n",
391 &buffer[5]);
392 format->fcc = 0;
393 }
394
395 format->bpp = buffer[21];
396
397
398
399
400 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
401 if (format->fcc == V4L2_PIX_FMT_YUYV) {
402 strlcpy(format->name, "Greyscale 8-bit (Y8 )",
403 sizeof(format->name));
404 format->fcc = V4L2_PIX_FMT_GREY;
405 format->bpp = 8;
406 width_multiplier = 2;
407 }
408 }
409
410 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
411 ftype = UVC_VS_FRAME_UNCOMPRESSED;
412 } else {
413 ftype = UVC_VS_FRAME_FRAME_BASED;
414 if (buffer[27])
415 format->flags = UVC_FMT_FLAG_COMPRESSED;
416 }
417 break;
418
419 case UVC_VS_FORMAT_MJPEG:
420 if (buflen < 11) {
421 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
422 "interface %d FORMAT error\n",
423 dev->udev->devnum,
424 alts->desc.bInterfaceNumber);
425 return -EINVAL;
426 }
427
428 strlcpy(format->name, "MJPEG", sizeof format->name);
429 format->fcc = V4L2_PIX_FMT_MJPEG;
430 format->flags = UVC_FMT_FLAG_COMPRESSED;
431 format->bpp = 0;
432 ftype = UVC_VS_FRAME_MJPEG;
433 break;
434
435 case UVC_VS_FORMAT_DV:
436 if (buflen < 9) {
437 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
438 "interface %d FORMAT error\n",
439 dev->udev->devnum,
440 alts->desc.bInterfaceNumber);
441 return -EINVAL;
442 }
443
444 switch (buffer[8] & 0x7f) {
445 case 0:
446 strlcpy(format->name, "SD-DV", sizeof format->name);
447 break;
448 case 1:
449 strlcpy(format->name, "SDL-DV", sizeof format->name);
450 break;
451 case 2:
452 strlcpy(format->name, "HD-DV", sizeof format->name);
453 break;
454 default:
455 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
456 "interface %d: unknown DV format %u\n",
457 dev->udev->devnum,
458 alts->desc.bInterfaceNumber, buffer[8]);
459 return -EINVAL;
460 }
461
462 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
463 sizeof format->name);
464
465 format->fcc = V4L2_PIX_FMT_DV;
466 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
467 format->bpp = 0;
468 ftype = 0;
469
470
471 frame = &format->frame[0];
472 memset(&format->frame[0], 0, sizeof format->frame[0]);
473 frame->bFrameIntervalType = 1;
474 frame->dwDefaultFrameInterval = 1;
475 frame->dwFrameInterval = *intervals;
476 *(*intervals)++ = 1;
477 format->nframes = 1;
478 break;
479
480 case UVC_VS_FORMAT_MPEG2TS:
481 case UVC_VS_FORMAT_STREAM_BASED:
482
483 default:
484 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
485 "interface %d unsupported format %u\n",
486 dev->udev->devnum, alts->desc.bInterfaceNumber,
487 buffer[2]);
488 return -EINVAL;
489 }
490
491 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
492
493 buflen -= buffer[0];
494 buffer += buffer[0];
495
496
497
498
499 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
500 buffer[2] == ftype) {
501 frame = &format->frame[format->nframes];
502 if (ftype != UVC_VS_FRAME_FRAME_BASED)
503 n = buflen > 25 ? buffer[25] : 0;
504 else
505 n = buflen > 21 ? buffer[21] : 0;
506
507 n = n ? n : 3;
508
509 if (buflen < 26 + 4*n) {
510 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
511 "interface %d FRAME error\n", dev->udev->devnum,
512 alts->desc.bInterfaceNumber);
513 return -EINVAL;
514 }
515
516 frame->bFrameIndex = buffer[3];
517 frame->bmCapabilities = buffer[4];
518 frame->wWidth = get_unaligned_le16(&buffer[5])
519 * width_multiplier;
520 frame->wHeight = get_unaligned_le16(&buffer[7]);
521 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
522 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
523 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
524 frame->dwMaxVideoFrameBufferSize =
525 get_unaligned_le32(&buffer[17]);
526 frame->dwDefaultFrameInterval =
527 get_unaligned_le32(&buffer[21]);
528 frame->bFrameIntervalType = buffer[25];
529 } else {
530 frame->dwMaxVideoFrameBufferSize = 0;
531 frame->dwDefaultFrameInterval =
532 get_unaligned_le32(&buffer[17]);
533 frame->bFrameIntervalType = buffer[21];
534 }
535 frame->dwFrameInterval = *intervals;
536
537
538
539
540
541
542
543
544
545 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
546 frame->dwMaxVideoFrameBufferSize = format->bpp
547 * frame->wWidth * frame->wHeight / 8;
548
549
550
551
552
553
554 for (i = 0; i < n; ++i) {
555 interval = get_unaligned_le32(&buffer[26+4*i]);
556 *(*intervals)++ = interval ? interval : 1;
557 }
558
559
560
561
562 n -= frame->bFrameIntervalType ? 1 : 2;
563 frame->dwDefaultFrameInterval =
564 min(frame->dwFrameInterval[n],
565 max(frame->dwFrameInterval[0],
566 frame->dwDefaultFrameInterval));
567
568 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
569 frame->bFrameIntervalType = 1;
570 frame->dwFrameInterval[0] =
571 frame->dwDefaultFrameInterval;
572 }
573
574 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
575 frame->wWidth, frame->wHeight,
576 10000000/frame->dwDefaultFrameInterval,
577 (100000000/frame->dwDefaultFrameInterval)%10);
578
579 format->nframes++;
580 buflen -= buffer[0];
581 buffer += buffer[0];
582 }
583
584 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
585 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
586 buflen -= buffer[0];
587 buffer += buffer[0];
588 }
589
590 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
591 buffer[2] == UVC_VS_COLORFORMAT) {
592 if (buflen < 6) {
593 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
594 "interface %d COLORFORMAT error\n",
595 dev->udev->devnum,
596 alts->desc.bInterfaceNumber);
597 return -EINVAL;
598 }
599
600 format->colorspace = uvc_colorspace(buffer[3]);
601
602 buflen -= buffer[0];
603 buffer += buffer[0];
604 }
605
606 return buffer - start;
607}
608
609static int uvc_parse_streaming(struct uvc_device *dev,
610 struct usb_interface *intf)
611{
612 struct uvc_streaming *streaming = NULL;
613 struct uvc_format *format;
614 struct uvc_frame *frame;
615 struct usb_host_interface *alts = &intf->altsetting[0];
616 unsigned char *_buffer, *buffer = alts->extra;
617 int _buflen, buflen = alts->extralen;
618 unsigned int nformats = 0, nframes = 0, nintervals = 0;
619 unsigned int size, i, n, p;
620 __u32 *interval;
621 __u16 psize;
622 int ret = -EINVAL;
623
624 if (intf->cur_altsetting->desc.bInterfaceSubClass
625 != UVC_SC_VIDEOSTREAMING) {
626 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
627 "video streaming interface\n", dev->udev->devnum,
628 intf->altsetting[0].desc.bInterfaceNumber);
629 return -EINVAL;
630 }
631
632 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
633 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
634 "claimed\n", dev->udev->devnum,
635 intf->altsetting[0].desc.bInterfaceNumber);
636 return -EINVAL;
637 }
638
639 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
640 if (streaming == NULL) {
641 usb_driver_release_interface(&uvc_driver.driver, intf);
642 return -EINVAL;
643 }
644
645 mutex_init(&streaming->mutex);
646 streaming->dev = dev;
647 streaming->intf = usb_get_intf(intf);
648 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
649
650
651
652
653 if (buflen == 0) {
654 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
655 struct usb_host_endpoint *ep = &alts->endpoint[i];
656
657 if (ep->extralen == 0)
658 continue;
659
660 if (ep->extralen > 2 &&
661 ep->extra[1] == USB_DT_CS_INTERFACE) {
662 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
663 "from endpoint %u.\n", i);
664 buffer = alts->endpoint[i].extra;
665 buflen = alts->endpoint[i].extralen;
666 break;
667 }
668 }
669 }
670
671
672 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
673 buflen -= buffer[0];
674 buffer += buffer[0];
675 }
676
677 if (buflen <= 2) {
678 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
679 "interface descriptors found.\n");
680 goto error;
681 }
682
683
684 switch (buffer[2]) {
685 case UVC_VS_OUTPUT_HEADER:
686 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
687 size = 9;
688 break;
689
690 case UVC_VS_INPUT_HEADER:
691 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
692 size = 13;
693 break;
694
695 default:
696 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
697 "%d HEADER descriptor not found.\n", dev->udev->devnum,
698 alts->desc.bInterfaceNumber);
699 goto error;
700 }
701
702 p = buflen >= 4 ? buffer[3] : 0;
703 n = buflen >= size ? buffer[size-1] : 0;
704
705 if (buflen < size + p*n) {
706 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
707 "interface %d HEADER descriptor is invalid.\n",
708 dev->udev->devnum, alts->desc.bInterfaceNumber);
709 goto error;
710 }
711
712 streaming->header.bNumFormats = p;
713 streaming->header.bEndpointAddress = buffer[6];
714 if (buffer[2] == UVC_VS_INPUT_HEADER) {
715 streaming->header.bmInfo = buffer[7];
716 streaming->header.bTerminalLink = buffer[8];
717 streaming->header.bStillCaptureMethod = buffer[9];
718 streaming->header.bTriggerSupport = buffer[10];
719 streaming->header.bTriggerUsage = buffer[11];
720 } else {
721 streaming->header.bTerminalLink = buffer[7];
722 }
723 streaming->header.bControlSize = n;
724
725 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
726 GFP_KERNEL);
727 if (streaming->header.bmaControls == NULL) {
728 ret = -ENOMEM;
729 goto error;
730 }
731
732 buflen -= buffer[0];
733 buffer += buffer[0];
734
735 _buffer = buffer;
736 _buflen = buflen;
737
738
739 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
740 switch (_buffer[2]) {
741 case UVC_VS_FORMAT_UNCOMPRESSED:
742 case UVC_VS_FORMAT_MJPEG:
743 case UVC_VS_FORMAT_FRAME_BASED:
744 nformats++;
745 break;
746
747 case UVC_VS_FORMAT_DV:
748
749
750
751 nformats++;
752 nframes++;
753 nintervals++;
754 break;
755
756 case UVC_VS_FORMAT_MPEG2TS:
757 case UVC_VS_FORMAT_STREAM_BASED:
758 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
759 "interface %d FORMAT %u is not supported.\n",
760 dev->udev->devnum,
761 alts->desc.bInterfaceNumber, _buffer[2]);
762 break;
763
764 case UVC_VS_FRAME_UNCOMPRESSED:
765 case UVC_VS_FRAME_MJPEG:
766 nframes++;
767 if (_buflen > 25)
768 nintervals += _buffer[25] ? _buffer[25] : 3;
769 break;
770
771 case UVC_VS_FRAME_FRAME_BASED:
772 nframes++;
773 if (_buflen > 21)
774 nintervals += _buffer[21] ? _buffer[21] : 3;
775 break;
776 }
777
778 _buflen -= _buffer[0];
779 _buffer += _buffer[0];
780 }
781
782 if (nformats == 0) {
783 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
784 "%d has no supported formats defined.\n",
785 dev->udev->devnum, alts->desc.bInterfaceNumber);
786 goto error;
787 }
788
789 size = nformats * sizeof *format + nframes * sizeof *frame
790 + nintervals * sizeof *interval;
791 format = kzalloc(size, GFP_KERNEL);
792 if (format == NULL) {
793 ret = -ENOMEM;
794 goto error;
795 }
796
797 frame = (struct uvc_frame *)&format[nformats];
798 interval = (__u32 *)&frame[nframes];
799
800 streaming->format = format;
801 streaming->nformats = nformats;
802
803
804 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
805 switch (buffer[2]) {
806 case UVC_VS_FORMAT_UNCOMPRESSED:
807 case UVC_VS_FORMAT_MJPEG:
808 case UVC_VS_FORMAT_DV:
809 case UVC_VS_FORMAT_FRAME_BASED:
810 format->frame = frame;
811 ret = uvc_parse_format(dev, streaming, format,
812 &interval, buffer, buflen);
813 if (ret < 0)
814 goto error;
815
816 frame += format->nframes;
817 format++;
818
819 buflen -= ret;
820 buffer += ret;
821 continue;
822
823 default:
824 break;
825 }
826
827 buflen -= buffer[0];
828 buffer += buffer[0];
829 }
830
831 if (buflen)
832 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
833 "%d has %u bytes of trailing descriptor garbage.\n",
834 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
835
836
837 for (i = 0; i < intf->num_altsetting; ++i) {
838 struct usb_host_endpoint *ep;
839 alts = &intf->altsetting[i];
840 ep = uvc_find_endpoint(alts,
841 streaming->header.bEndpointAddress);
842 if (ep == NULL)
843 continue;
844
845 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
846 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
847 if (psize > streaming->maxpsize)
848 streaming->maxpsize = psize;
849 }
850
851 list_add_tail(&streaming->list, &dev->streams);
852 return 0;
853
854error:
855 usb_driver_release_interface(&uvc_driver.driver, intf);
856 usb_put_intf(intf);
857 kfree(streaming->format);
858 kfree(streaming->header.bmaControls);
859 kfree(streaming);
860 return ret;
861}
862
863static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
864 unsigned int num_pads, unsigned int extra_size)
865{
866 struct uvc_entity *entity;
867 unsigned int num_inputs;
868 unsigned int size;
869 unsigned int i;
870
871 extra_size = ALIGN(extra_size, sizeof(*entity->pads));
872 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
873 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
874 + num_inputs;
875 entity = kzalloc(size, GFP_KERNEL);
876 if (entity == NULL)
877 return NULL;
878
879 entity->id = id;
880 entity->type = type;
881
882 entity->num_links = 0;
883 entity->num_pads = num_pads;
884 entity->pads = ((void *)(entity + 1)) + extra_size;
885
886 for (i = 0; i < num_inputs; ++i)
887 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
888 if (!UVC_ENTITY_IS_OTERM(entity))
889 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
890
891 entity->bNrInPins = num_inputs;
892 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
893
894 return entity;
895}
896
897
898static int uvc_parse_vendor_control(struct uvc_device *dev,
899 const unsigned char *buffer, int buflen)
900{
901 struct usb_device *udev = dev->udev;
902 struct usb_host_interface *alts = dev->intf->cur_altsetting;
903 struct uvc_entity *unit;
904 unsigned int n, p;
905 int handled = 0;
906
907 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
908 case 0x046d:
909 if (buffer[1] != 0x41 || buffer[2] != 0x01)
910 break;
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938 p = buflen >= 22 ? buffer[21] : 0;
939 n = buflen >= 25 + p ? buffer[22+p] : 0;
940
941 if (buflen < 25 + p + 2*n) {
942 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
943 "interface %d EXTENSION_UNIT error\n",
944 udev->devnum, alts->desc.bInterfaceNumber);
945 break;
946 }
947
948 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
949 p + 1, 2*n);
950 if (unit == NULL)
951 return -ENOMEM;
952
953 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
954 unit->extension.bNumControls = buffer[20];
955 memcpy(unit->baSourceID, &buffer[22], p);
956 unit->extension.bControlSize = buffer[22+p];
957 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
958 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
959 + n;
960 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
961
962 if (buffer[24+p+2*n] != 0)
963 usb_string(udev, buffer[24+p+2*n], unit->name,
964 sizeof unit->name);
965 else
966 sprintf(unit->name, "Extension %u", buffer[3]);
967
968 list_add_tail(&unit->list, &dev->entities);
969 handled = 1;
970 break;
971 }
972
973 return handled;
974}
975
976static int uvc_parse_standard_control(struct uvc_device *dev,
977 const unsigned char *buffer, int buflen)
978{
979 struct usb_device *udev = dev->udev;
980 struct uvc_entity *unit, *term;
981 struct usb_interface *intf;
982 struct usb_host_interface *alts = dev->intf->cur_altsetting;
983 unsigned int i, n, p, len;
984 __u16 type;
985
986 switch (buffer[2]) {
987 case UVC_VC_HEADER:
988 n = buflen >= 12 ? buffer[11] : 0;
989
990 if (buflen < 12 + n) {
991 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
992 "interface %d HEADER error\n", udev->devnum,
993 alts->desc.bInterfaceNumber);
994 return -EINVAL;
995 }
996
997 dev->uvc_version = get_unaligned_le16(&buffer[3]);
998 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
999
1000
1001 for (i = 0; i < n; ++i) {
1002 intf = usb_ifnum_to_if(udev, buffer[12+i]);
1003 if (intf == NULL) {
1004 uvc_trace(UVC_TRACE_DESCR, "device %d "
1005 "interface %d doesn't exists\n",
1006 udev->devnum, i);
1007 continue;
1008 }
1009
1010 uvc_parse_streaming(dev, intf);
1011 }
1012 break;
1013
1014 case UVC_VC_INPUT_TERMINAL:
1015 if (buflen < 8) {
1016 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1017 "interface %d INPUT_TERMINAL error\n",
1018 udev->devnum, alts->desc.bInterfaceNumber);
1019 return -EINVAL;
1020 }
1021
1022
1023
1024
1025 type = get_unaligned_le16(&buffer[4]);
1026 if ((type & 0xff00) == 0) {
1027 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1028 "interface %d INPUT_TERMINAL %d has invalid "
1029 "type 0x%04x, skipping\n", udev->devnum,
1030 alts->desc.bInterfaceNumber,
1031 buffer[3], type);
1032 return 0;
1033 }
1034
1035 n = 0;
1036 p = 0;
1037 len = 8;
1038
1039 if (type == UVC_ITT_CAMERA) {
1040 n = buflen >= 15 ? buffer[14] : 0;
1041 len = 15;
1042
1043 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1044 n = buflen >= 9 ? buffer[8] : 0;
1045 p = buflen >= 10 + n ? buffer[9+n] : 0;
1046 len = 10;
1047 }
1048
1049 if (buflen < len + n + p) {
1050 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1051 "interface %d INPUT_TERMINAL error\n",
1052 udev->devnum, alts->desc.bInterfaceNumber);
1053 return -EINVAL;
1054 }
1055
1056 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1057 1, n + p);
1058 if (term == NULL)
1059 return -ENOMEM;
1060
1061 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1062 term->camera.bControlSize = n;
1063 term->camera.bmControls = (__u8 *)term + sizeof *term;
1064 term->camera.wObjectiveFocalLengthMin =
1065 get_unaligned_le16(&buffer[8]);
1066 term->camera.wObjectiveFocalLengthMax =
1067 get_unaligned_le16(&buffer[10]);
1068 term->camera.wOcularFocalLength =
1069 get_unaligned_le16(&buffer[12]);
1070 memcpy(term->camera.bmControls, &buffer[15], n);
1071 } else if (UVC_ENTITY_TYPE(term) ==
1072 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1073 term->media.bControlSize = n;
1074 term->media.bmControls = (__u8 *)term + sizeof *term;
1075 term->media.bTransportModeSize = p;
1076 term->media.bmTransportModes = (__u8 *)term
1077 + sizeof *term + n;
1078 memcpy(term->media.bmControls, &buffer[9], n);
1079 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1080 }
1081
1082 if (buffer[7] != 0)
1083 usb_string(udev, buffer[7], term->name,
1084 sizeof term->name);
1085 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1086 sprintf(term->name, "Camera %u", buffer[3]);
1087 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1088 sprintf(term->name, "Media %u", buffer[3]);
1089 else
1090 sprintf(term->name, "Input %u", buffer[3]);
1091
1092 list_add_tail(&term->list, &dev->entities);
1093 break;
1094
1095 case UVC_VC_OUTPUT_TERMINAL:
1096 if (buflen < 9) {
1097 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1098 "interface %d OUTPUT_TERMINAL error\n",
1099 udev->devnum, alts->desc.bInterfaceNumber);
1100 return -EINVAL;
1101 }
1102
1103
1104
1105
1106 type = get_unaligned_le16(&buffer[4]);
1107 if ((type & 0xff00) == 0) {
1108 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1109 "interface %d OUTPUT_TERMINAL %d has invalid "
1110 "type 0x%04x, skipping\n", udev->devnum,
1111 alts->desc.bInterfaceNumber, buffer[3], type);
1112 return 0;
1113 }
1114
1115 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1116 1, 0);
1117 if (term == NULL)
1118 return -ENOMEM;
1119
1120 memcpy(term->baSourceID, &buffer[7], 1);
1121
1122 if (buffer[8] != 0)
1123 usb_string(udev, buffer[8], term->name,
1124 sizeof term->name);
1125 else
1126 sprintf(term->name, "Output %u", buffer[3]);
1127
1128 list_add_tail(&term->list, &dev->entities);
1129 break;
1130
1131 case UVC_VC_SELECTOR_UNIT:
1132 p = buflen >= 5 ? buffer[4] : 0;
1133
1134 if (buflen < 5 || buflen < 6 + p) {
1135 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1136 "interface %d SELECTOR_UNIT error\n",
1137 udev->devnum, alts->desc.bInterfaceNumber);
1138 return -EINVAL;
1139 }
1140
1141 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1142 if (unit == NULL)
1143 return -ENOMEM;
1144
1145 memcpy(unit->baSourceID, &buffer[5], p);
1146
1147 if (buffer[5+p] != 0)
1148 usb_string(udev, buffer[5+p], unit->name,
1149 sizeof unit->name);
1150 else
1151 sprintf(unit->name, "Selector %u", buffer[3]);
1152
1153 list_add_tail(&unit->list, &dev->entities);
1154 break;
1155
1156 case UVC_VC_PROCESSING_UNIT:
1157 n = buflen >= 8 ? buffer[7] : 0;
1158 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1159
1160 if (buflen < p + n) {
1161 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1162 "interface %d PROCESSING_UNIT error\n",
1163 udev->devnum, alts->desc.bInterfaceNumber);
1164 return -EINVAL;
1165 }
1166
1167 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1168 if (unit == NULL)
1169 return -ENOMEM;
1170
1171 memcpy(unit->baSourceID, &buffer[4], 1);
1172 unit->processing.wMaxMultiplier =
1173 get_unaligned_le16(&buffer[5]);
1174 unit->processing.bControlSize = buffer[7];
1175 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1176 memcpy(unit->processing.bmControls, &buffer[8], n);
1177 if (dev->uvc_version >= 0x0110)
1178 unit->processing.bmVideoStandards = buffer[9+n];
1179
1180 if (buffer[8+n] != 0)
1181 usb_string(udev, buffer[8+n], unit->name,
1182 sizeof unit->name);
1183 else
1184 sprintf(unit->name, "Processing %u", buffer[3]);
1185
1186 list_add_tail(&unit->list, &dev->entities);
1187 break;
1188
1189 case UVC_VC_EXTENSION_UNIT:
1190 p = buflen >= 22 ? buffer[21] : 0;
1191 n = buflen >= 24 + p ? buffer[22+p] : 0;
1192
1193 if (buflen < 24 + p + n) {
1194 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1195 "interface %d EXTENSION_UNIT error\n",
1196 udev->devnum, alts->desc.bInterfaceNumber);
1197 return -EINVAL;
1198 }
1199
1200 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1201 if (unit == NULL)
1202 return -ENOMEM;
1203
1204 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1205 unit->extension.bNumControls = buffer[20];
1206 memcpy(unit->baSourceID, &buffer[22], p);
1207 unit->extension.bControlSize = buffer[22+p];
1208 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1209 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1210
1211 if (buffer[23+p+n] != 0)
1212 usb_string(udev, buffer[23+p+n], unit->name,
1213 sizeof unit->name);
1214 else
1215 sprintf(unit->name, "Extension %u", buffer[3]);
1216
1217 list_add_tail(&unit->list, &dev->entities);
1218 break;
1219
1220 default:
1221 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1222 "descriptor (%u)\n", buffer[2]);
1223 break;
1224 }
1225
1226 return 0;
1227}
1228
1229static int uvc_parse_control(struct uvc_device *dev)
1230{
1231 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1232 unsigned char *buffer = alts->extra;
1233 int buflen = alts->extralen;
1234 int ret;
1235
1236
1237
1238
1239
1240
1241 while (buflen > 2) {
1242 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1243 buffer[1] != USB_DT_CS_INTERFACE)
1244 goto next_descriptor;
1245
1246 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1247 return ret;
1248
1249next_descriptor:
1250 buflen -= buffer[0];
1251 buffer += buffer[0];
1252 }
1253
1254
1255
1256
1257
1258
1259 if (alts->desc.bNumEndpoints == 1 &&
1260 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1261 struct usb_host_endpoint *ep = &alts->endpoint[0];
1262 struct usb_endpoint_descriptor *desc = &ep->desc;
1263
1264 if (usb_endpoint_is_int_in(desc) &&
1265 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1266 desc->bInterval != 0) {
1267 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1268 "(addr %02x).\n", desc->bEndpointAddress);
1269 dev->int_ep = ep;
1270 }
1271 }
1272
1273 return 0;
1274}
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306static 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 if (uvc_trace_param & UVC_TRACE_PROBE)
1312 printk(" <- XU %d", entity->id);
1313
1314 if (entity->bNrInPins != 1) {
1315 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1316 "than 1 input pin.\n", entity->id);
1317 return -1;
1318 }
1319
1320 break;
1321
1322 case UVC_VC_PROCESSING_UNIT:
1323 if (uvc_trace_param & UVC_TRACE_PROBE)
1324 printk(" <- PU %d", entity->id);
1325
1326 if (chain->processing != NULL) {
1327 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1328 "Processing Units in chain.\n");
1329 return -1;
1330 }
1331
1332 chain->processing = entity;
1333 break;
1334
1335 case UVC_VC_SELECTOR_UNIT:
1336 if (uvc_trace_param & UVC_TRACE_PROBE)
1337 printk(" <- SU %d", entity->id);
1338
1339
1340 if (entity->bNrInPins == 1)
1341 break;
1342
1343 if (chain->selector != NULL) {
1344 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1345 "Units in chain.\n");
1346 return -1;
1347 }
1348
1349 chain->selector = entity;
1350 break;
1351
1352 case UVC_ITT_VENDOR_SPECIFIC:
1353 case UVC_ITT_CAMERA:
1354 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1355 if (uvc_trace_param & UVC_TRACE_PROBE)
1356 printk(" <- IT %d\n", entity->id);
1357
1358 break;
1359
1360 case UVC_OTT_VENDOR_SPECIFIC:
1361 case UVC_OTT_DISPLAY:
1362 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1363 if (uvc_trace_param & UVC_TRACE_PROBE)
1364 printk(" OT %d", entity->id);
1365
1366 break;
1367
1368 case UVC_TT_STREAMING:
1369 if (UVC_ENTITY_IS_ITERM(entity)) {
1370 if (uvc_trace_param & UVC_TRACE_PROBE)
1371 printk(" <- IT %d\n", entity->id);
1372 } else {
1373 if (uvc_trace_param & UVC_TRACE_PROBE)
1374 printk(" OT %d", entity->id);
1375 }
1376
1377 break;
1378
1379 default:
1380 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1381 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1382 return -1;
1383 }
1384
1385 list_add_tail(&entity->chain, &chain->entities);
1386 return 0;
1387}
1388
1389static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1390 struct uvc_entity *entity, struct uvc_entity *prev)
1391{
1392 struct uvc_entity *forward;
1393 int found;
1394
1395
1396 forward = NULL;
1397 found = 0;
1398
1399 while (1) {
1400 forward = uvc_entity_by_reference(chain->dev, entity->id,
1401 forward);
1402 if (forward == NULL)
1403 break;
1404 if (forward == prev)
1405 continue;
1406
1407 switch (UVC_ENTITY_TYPE(forward)) {
1408 case UVC_VC_EXTENSION_UNIT:
1409 if (forward->bNrInPins != 1) {
1410 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1411 "has more than 1 input pin.\n",
1412 entity->id);
1413 return -EINVAL;
1414 }
1415
1416 list_add_tail(&forward->chain, &chain->entities);
1417 if (uvc_trace_param & UVC_TRACE_PROBE) {
1418 if (!found)
1419 printk(" (->");
1420
1421 printk(" XU %d", forward->id);
1422 found = 1;
1423 }
1424 break;
1425
1426 case UVC_OTT_VENDOR_SPECIFIC:
1427 case UVC_OTT_DISPLAY:
1428 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1429 case UVC_TT_STREAMING:
1430 if (UVC_ENTITY_IS_ITERM(forward)) {
1431 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1432 "terminal %u.\n", forward->id);
1433 return -EINVAL;
1434 }
1435
1436 list_add_tail(&forward->chain, &chain->entities);
1437 if (uvc_trace_param & UVC_TRACE_PROBE) {
1438 if (!found)
1439 printk(" (->");
1440
1441 printk(" OT %d", forward->id);
1442 found = 1;
1443 }
1444 break;
1445 }
1446 }
1447 if (found)
1448 printk(")");
1449
1450 return 0;
1451}
1452
1453static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1454 struct uvc_entity **_entity)
1455{
1456 struct uvc_entity *entity = *_entity;
1457 struct uvc_entity *term;
1458 int id = -EINVAL, i;
1459
1460 switch (UVC_ENTITY_TYPE(entity)) {
1461 case UVC_VC_EXTENSION_UNIT:
1462 case UVC_VC_PROCESSING_UNIT:
1463 id = entity->baSourceID[0];
1464 break;
1465
1466 case UVC_VC_SELECTOR_UNIT:
1467
1468 if (entity->bNrInPins == 1) {
1469 id = entity->baSourceID[0];
1470 break;
1471 }
1472
1473 if (uvc_trace_param & UVC_TRACE_PROBE)
1474 printk(" <- IT");
1475
1476 chain->selector = entity;
1477 for (i = 0; i < entity->bNrInPins; ++i) {
1478 id = entity->baSourceID[i];
1479 term = uvc_entity_by_id(chain->dev, id);
1480 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1481 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1482 "input %d isn't connected to an "
1483 "input terminal\n", entity->id, i);
1484 return -1;
1485 }
1486
1487 if (uvc_trace_param & UVC_TRACE_PROBE)
1488 printk(" %d", term->id);
1489
1490 list_add_tail(&term->chain, &chain->entities);
1491 uvc_scan_chain_forward(chain, term, entity);
1492 }
1493
1494 if (uvc_trace_param & UVC_TRACE_PROBE)
1495 printk("\n");
1496
1497 id = 0;
1498 break;
1499
1500 case UVC_ITT_VENDOR_SPECIFIC:
1501 case UVC_ITT_CAMERA:
1502 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1503 case UVC_OTT_VENDOR_SPECIFIC:
1504 case UVC_OTT_DISPLAY:
1505 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1506 case UVC_TT_STREAMING:
1507 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1508 break;
1509 }
1510
1511 if (id <= 0) {
1512 *_entity = NULL;
1513 return id;
1514 }
1515
1516 entity = uvc_entity_by_id(chain->dev, id);
1517 if (entity == NULL) {
1518 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1519 "unknown entity %d.\n", id);
1520 return -EINVAL;
1521 }
1522
1523 *_entity = entity;
1524 return 0;
1525}
1526
1527static int uvc_scan_chain(struct uvc_video_chain *chain,
1528 struct uvc_entity *term)
1529{
1530 struct uvc_entity *entity, *prev;
1531
1532 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1533
1534 entity = term;
1535 prev = NULL;
1536
1537 while (entity != NULL) {
1538
1539 if (entity->chain.next || entity->chain.prev) {
1540 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1541 "entity %d already in chain.\n", entity->id);
1542 return -EINVAL;
1543 }
1544
1545
1546 if (uvc_scan_chain_entity(chain, entity) < 0)
1547 return -EINVAL;
1548
1549
1550 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1551 return -EINVAL;
1552
1553
1554 prev = entity;
1555 if (uvc_scan_chain_backward(chain, &entity) < 0)
1556 return -EINVAL;
1557 }
1558
1559 return 0;
1560}
1561
1562static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1563 char *buffer)
1564{
1565 struct uvc_entity *term;
1566 unsigned int nterms = 0;
1567 char *p = buffer;
1568
1569 list_for_each_entry(term, terms, chain) {
1570 if (!UVC_ENTITY_IS_TERM(term) ||
1571 UVC_TERM_DIRECTION(term) != dir)
1572 continue;
1573
1574 if (nterms)
1575 p += sprintf(p, ",");
1576 if (++nterms >= 4) {
1577 p += sprintf(p, "...");
1578 break;
1579 }
1580 p += sprintf(p, "%u", term->id);
1581 }
1582
1583 return p - buffer;
1584}
1585
1586static const char *uvc_print_chain(struct uvc_video_chain *chain)
1587{
1588 static char buffer[43];
1589 char *p = buffer;
1590
1591 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1592 p += sprintf(p, " -> ");
1593 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1594
1595 return buffer;
1596}
1597
1598
1599
1600
1601
1602
1603static int uvc_scan_device(struct uvc_device *dev)
1604{
1605 struct uvc_video_chain *chain;
1606 struct uvc_entity *term;
1607
1608 list_for_each_entry(term, &dev->entities, list) {
1609 if (!UVC_ENTITY_IS_OTERM(term))
1610 continue;
1611
1612
1613
1614
1615
1616
1617 if (term->chain.next || term->chain.prev)
1618 continue;
1619
1620 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1621 if (chain == NULL)
1622 return -ENOMEM;
1623
1624 INIT_LIST_HEAD(&chain->entities);
1625 mutex_init(&chain->ctrl_mutex);
1626 chain->dev = dev;
1627 v4l2_prio_init(&chain->prio);
1628
1629 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1630
1631 if (uvc_scan_chain(chain, term) < 0) {
1632 kfree(chain);
1633 continue;
1634 }
1635
1636 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1637 uvc_print_chain(chain));
1638
1639 list_add_tail(&chain->list, &dev->chains);
1640 }
1641
1642 if (list_empty(&dev->chains)) {
1643 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1644 return -1;
1645 }
1646
1647 return 0;
1648}
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664static void uvc_delete(struct uvc_device *dev)
1665{
1666 struct list_head *p, *n;
1667
1668 uvc_status_cleanup(dev);
1669 uvc_ctrl_cleanup_device(dev);
1670
1671 usb_put_intf(dev->intf);
1672 usb_put_dev(dev->udev);
1673
1674 if (dev->vdev.dev)
1675 v4l2_device_unregister(&dev->vdev);
1676#ifdef CONFIG_MEDIA_CONTROLLER
1677 if (media_devnode_is_registered(&dev->mdev.devnode))
1678 media_device_unregister(&dev->mdev);
1679 media_device_cleanup(&dev->mdev);
1680#endif
1681
1682 list_for_each_safe(p, n, &dev->chains) {
1683 struct uvc_video_chain *chain;
1684 chain = list_entry(p, struct uvc_video_chain, list);
1685 kfree(chain);
1686 }
1687
1688 list_for_each_safe(p, n, &dev->entities) {
1689 struct uvc_entity *entity;
1690 entity = list_entry(p, struct uvc_entity, list);
1691#ifdef CONFIG_MEDIA_CONTROLLER
1692 uvc_mc_cleanup_entity(entity);
1693#endif
1694 kfree(entity);
1695 }
1696
1697 list_for_each_safe(p, n, &dev->streams) {
1698 struct uvc_streaming *streaming;
1699 streaming = list_entry(p, struct uvc_streaming, list);
1700 usb_driver_release_interface(&uvc_driver.driver,
1701 streaming->intf);
1702 usb_put_intf(streaming->intf);
1703 kfree(streaming->format);
1704 kfree(streaming->header.bmaControls);
1705 kfree(streaming);
1706 }
1707
1708 kfree(dev);
1709}
1710
1711static void uvc_release(struct video_device *vdev)
1712{
1713 struct uvc_streaming *stream = video_get_drvdata(vdev);
1714 struct uvc_device *dev = stream->dev;
1715
1716
1717
1718
1719 if (atomic_dec_and_test(&dev->nstreams))
1720 uvc_delete(dev);
1721}
1722
1723
1724
1725
1726static void uvc_unregister_video(struct uvc_device *dev)
1727{
1728 struct uvc_streaming *stream;
1729
1730
1731
1732
1733
1734
1735 atomic_inc(&dev->nstreams);
1736
1737 list_for_each_entry(stream, &dev->streams, list) {
1738 if (!video_is_registered(&stream->vdev))
1739 continue;
1740
1741 video_unregister_device(&stream->vdev);
1742
1743 uvc_debugfs_cleanup_stream(stream);
1744 }
1745
1746
1747
1748
1749 if (atomic_dec_and_test(&dev->nstreams))
1750 uvc_delete(dev);
1751}
1752
1753static int uvc_register_video(struct uvc_device *dev,
1754 struct uvc_streaming *stream)
1755{
1756 struct video_device *vdev = &stream->vdev;
1757 int ret;
1758
1759
1760 ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1761 if (ret)
1762 return ret;
1763
1764
1765
1766
1767 ret = uvc_video_init(stream);
1768 if (ret < 0) {
1769 uvc_printk(KERN_ERR, "Failed to initialize the device "
1770 "(%d).\n", ret);
1771 return ret;
1772 }
1773
1774 uvc_debugfs_init_stream(stream);
1775
1776
1777
1778
1779
1780
1781
1782 vdev->v4l2_dev = &dev->vdev;
1783 vdev->fops = &uvc_fops;
1784 vdev->ioctl_ops = &uvc_ioctl_ops;
1785 vdev->release = uvc_release;
1786 vdev->prio = &stream->chain->prio;
1787 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1788 vdev->vfl_dir = VFL_DIR_TX;
1789 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1790
1791
1792
1793
1794 video_set_drvdata(vdev, stream);
1795
1796 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1797 if (ret < 0) {
1798 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1799 ret);
1800 return ret;
1801 }
1802
1803 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1804 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1805 else
1806 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1807
1808 atomic_inc(&dev->nstreams);
1809 return 0;
1810}
1811
1812
1813
1814
1815static int uvc_register_terms(struct uvc_device *dev,
1816 struct uvc_video_chain *chain)
1817{
1818 struct uvc_streaming *stream;
1819 struct uvc_entity *term;
1820 int ret;
1821
1822 list_for_each_entry(term, &chain->entities, chain) {
1823 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1824 continue;
1825
1826 stream = uvc_stream_by_id(dev, term->id);
1827 if (stream == NULL) {
1828 uvc_printk(KERN_INFO, "No streaming interface found "
1829 "for terminal %u.", term->id);
1830 continue;
1831 }
1832
1833 stream->chain = chain;
1834 ret = uvc_register_video(dev, stream);
1835 if (ret < 0)
1836 return ret;
1837
1838 term->vdev = &stream->vdev;
1839 }
1840
1841 return 0;
1842}
1843
1844static int uvc_register_chains(struct uvc_device *dev)
1845{
1846 struct uvc_video_chain *chain;
1847 int ret;
1848
1849 list_for_each_entry(chain, &dev->chains, list) {
1850 ret = uvc_register_terms(dev, chain);
1851 if (ret < 0)
1852 return ret;
1853
1854#ifdef CONFIG_MEDIA_CONTROLLER
1855 ret = uvc_mc_register_entities(chain);
1856 if (ret < 0) {
1857 uvc_printk(KERN_INFO, "Failed to register entites "
1858 "(%d).\n", ret);
1859 }
1860#endif
1861 }
1862
1863 return 0;
1864}
1865
1866
1867
1868
1869
1870static int uvc_probe(struct usb_interface *intf,
1871 const struct usb_device_id *id)
1872{
1873 struct usb_device *udev = interface_to_usbdev(intf);
1874 struct uvc_device *dev;
1875 int ret;
1876
1877 if (id->idVendor && id->idProduct)
1878 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1879 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1880 id->idProduct);
1881 else
1882 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1883 udev->devpath);
1884
1885
1886 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1887 return -ENOMEM;
1888
1889 INIT_LIST_HEAD(&dev->entities);
1890 INIT_LIST_HEAD(&dev->chains);
1891 INIT_LIST_HEAD(&dev->streams);
1892 atomic_set(&dev->nstreams, 0);
1893 atomic_set(&dev->nmappings, 0);
1894 mutex_init(&dev->lock);
1895
1896 dev->udev = usb_get_dev(udev);
1897 dev->intf = usb_get_intf(intf);
1898 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1899 dev->quirks = (uvc_quirks_param == -1)
1900 ? id->driver_info : uvc_quirks_param;
1901
1902 if (udev->product != NULL)
1903 strlcpy(dev->name, udev->product, sizeof dev->name);
1904 else
1905 snprintf(dev->name, sizeof dev->name,
1906 "UVC Camera (%04x:%04x)",
1907 le16_to_cpu(udev->descriptor.idVendor),
1908 le16_to_cpu(udev->descriptor.idProduct));
1909
1910
1911 if (uvc_parse_control(dev) < 0) {
1912 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1913 "descriptors.\n");
1914 goto error;
1915 }
1916
1917 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1918 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1919 udev->product ? udev->product : "<unnamed>",
1920 le16_to_cpu(udev->descriptor.idVendor),
1921 le16_to_cpu(udev->descriptor.idProduct));
1922
1923 if (dev->quirks != id->driver_info) {
1924 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1925 "parameter for testing purpose.\n", dev->quirks);
1926 uvc_printk(KERN_INFO, "Please report required quirks to the "
1927 "linux-uvc-devel mailing list.\n");
1928 }
1929
1930
1931#ifdef CONFIG_MEDIA_CONTROLLER
1932 dev->mdev.dev = &intf->dev;
1933 strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
1934 if (udev->serial)
1935 strlcpy(dev->mdev.serial, udev->serial,
1936 sizeof(dev->mdev.serial));
1937 strcpy(dev->mdev.bus_info, udev->devpath);
1938 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
1939 dev->mdev.driver_version = LINUX_VERSION_CODE;
1940 media_device_init(&dev->mdev);
1941
1942 dev->vdev.mdev = &dev->mdev;
1943#endif
1944 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
1945 goto error;
1946
1947
1948 if (uvc_ctrl_init_device(dev) < 0)
1949 goto error;
1950
1951
1952 if (uvc_scan_device(dev) < 0)
1953 goto error;
1954
1955
1956 if (uvc_register_chains(dev) < 0)
1957 goto error;
1958
1959#ifdef CONFIG_MEDIA_CONTROLLER
1960
1961 if (media_device_register(&dev->mdev) < 0)
1962 goto error;
1963#endif
1964
1965 usb_set_intfdata(intf, dev);
1966
1967
1968 if ((ret = uvc_status_init(dev)) < 0) {
1969 uvc_printk(KERN_INFO, "Unable to initialize the status "
1970 "endpoint (%d), status interrupt will not be "
1971 "supported.\n", ret);
1972 }
1973
1974 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1975 usb_enable_autosuspend(udev);
1976 return 0;
1977
1978error:
1979 uvc_unregister_video(dev);
1980 return -ENODEV;
1981}
1982
1983static void uvc_disconnect(struct usb_interface *intf)
1984{
1985 struct uvc_device *dev = usb_get_intfdata(intf);
1986
1987
1988
1989
1990 usb_set_intfdata(intf, NULL);
1991
1992 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1993 UVC_SC_VIDEOSTREAMING)
1994 return;
1995
1996 uvc_unregister_video(dev);
1997}
1998
1999static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2000{
2001 struct uvc_device *dev = usb_get_intfdata(intf);
2002 struct uvc_streaming *stream;
2003
2004 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2005 intf->cur_altsetting->desc.bInterfaceNumber);
2006
2007
2008 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2009 UVC_SC_VIDEOCONTROL) {
2010 mutex_lock(&dev->lock);
2011 if (dev->users)
2012 uvc_status_stop(dev);
2013 mutex_unlock(&dev->lock);
2014 return 0;
2015 }
2016
2017 list_for_each_entry(stream, &dev->streams, list) {
2018 if (stream->intf == intf)
2019 return uvc_video_suspend(stream);
2020 }
2021
2022 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2023 "mismatch.\n");
2024 return -EINVAL;
2025}
2026
2027static int __uvc_resume(struct usb_interface *intf, int reset)
2028{
2029 struct uvc_device *dev = usb_get_intfdata(intf);
2030 struct uvc_streaming *stream;
2031 int ret = 0;
2032
2033 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2034 intf->cur_altsetting->desc.bInterfaceNumber);
2035
2036 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2037 UVC_SC_VIDEOCONTROL) {
2038 if (reset) {
2039 ret = uvc_ctrl_restore_values(dev);
2040 if (ret < 0)
2041 return ret;
2042 }
2043
2044 mutex_lock(&dev->lock);
2045 if (dev->users)
2046 ret = uvc_status_start(dev, GFP_NOIO);
2047 mutex_unlock(&dev->lock);
2048
2049 return ret;
2050 }
2051
2052 list_for_each_entry(stream, &dev->streams, list) {
2053 if (stream->intf == intf) {
2054 ret = uvc_video_resume(stream, reset);
2055 if (ret < 0)
2056 uvc_queue_streamoff(&stream->queue,
2057 stream->queue.queue.type);
2058 return ret;
2059 }
2060 }
2061
2062 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2063 "mismatch.\n");
2064 return -EINVAL;
2065}
2066
2067static int uvc_resume(struct usb_interface *intf)
2068{
2069 return __uvc_resume(intf, 0);
2070}
2071
2072static int uvc_reset_resume(struct usb_interface *intf)
2073{
2074 return __uvc_resume(intf, 1);
2075}
2076
2077
2078
2079
2080
2081static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
2082{
2083 if (uvc_clock_param == CLOCK_MONOTONIC)
2084 return sprintf(buffer, "CLOCK_MONOTONIC");
2085 else
2086 return sprintf(buffer, "CLOCK_REALTIME");
2087}
2088
2089static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
2090{
2091 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2092 val += strlen("clock_");
2093
2094 if (strcasecmp(val, "monotonic") == 0)
2095 uvc_clock_param = CLOCK_MONOTONIC;
2096 else if (strcasecmp(val, "realtime") == 0)
2097 uvc_clock_param = CLOCK_REALTIME;
2098 else
2099 return -EINVAL;
2100
2101 return 0;
2102}
2103
2104module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2105 &uvc_clock_param, S_IRUGO|S_IWUSR);
2106MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2107module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2108MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2109module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2110MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2111module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2112MODULE_PARM_DESC(quirks, "Forced device quirks");
2113module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2114MODULE_PARM_DESC(trace, "Trace level bitmask");
2115module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2116MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127static struct usb_device_id uvc_ids[] = {
2128
2129 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2130 | USB_DEVICE_ID_MATCH_INT_INFO,
2131 .idVendor = 0x0416,
2132 .idProduct = 0xa91a,
2133 .bInterfaceClass = USB_CLASS_VIDEO,
2134 .bInterfaceSubClass = 1,
2135 .bInterfaceProtocol = 0,
2136 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2137
2138 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2139 | USB_DEVICE_ID_MATCH_INT_INFO,
2140 .idVendor = 0x0458,
2141 .idProduct = 0x706e,
2142 .bInterfaceClass = USB_CLASS_VIDEO,
2143 .bInterfaceSubClass = 1,
2144 .bInterfaceProtocol = 0,
2145 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2146
2147 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2148 | USB_DEVICE_ID_MATCH_INT_INFO,
2149 .idVendor = 0x045e,
2150 .idProduct = 0x00f8,
2151 .bInterfaceClass = USB_CLASS_VIDEO,
2152 .bInterfaceSubClass = 1,
2153 .bInterfaceProtocol = 0,
2154 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2155
2156 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2157 | USB_DEVICE_ID_MATCH_INT_INFO,
2158 .idVendor = 0x045e,
2159 .idProduct = 0x0721,
2160 .bInterfaceClass = USB_CLASS_VIDEO,
2161 .bInterfaceSubClass = 1,
2162 .bInterfaceProtocol = 0,
2163 .driver_info = UVC_QUIRK_PROBE_DEF },
2164
2165 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2166 | USB_DEVICE_ID_MATCH_INT_INFO,
2167 .idVendor = 0x045e,
2168 .idProduct = 0x0723,
2169 .bInterfaceClass = USB_CLASS_VIDEO,
2170 .bInterfaceSubClass = 1,
2171 .bInterfaceProtocol = 0,
2172 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2173
2174 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2175 | USB_DEVICE_ID_MATCH_INT_INFO,
2176 .idVendor = 0x046d,
2177 .idProduct = 0x08c1,
2178 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2179 .bInterfaceSubClass = 1,
2180 .bInterfaceProtocol = 0 },
2181
2182 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2183 | USB_DEVICE_ID_MATCH_INT_INFO,
2184 .idVendor = 0x046d,
2185 .idProduct = 0x08c2,
2186 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2187 .bInterfaceSubClass = 1,
2188 .bInterfaceProtocol = 0 },
2189
2190 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2191 | USB_DEVICE_ID_MATCH_INT_INFO,
2192 .idVendor = 0x046d,
2193 .idProduct = 0x08c3,
2194 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2195 .bInterfaceSubClass = 1,
2196 .bInterfaceProtocol = 0 },
2197
2198 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2199 | USB_DEVICE_ID_MATCH_INT_INFO,
2200 .idVendor = 0x046d,
2201 .idProduct = 0x08c5,
2202 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2203 .bInterfaceSubClass = 1,
2204 .bInterfaceProtocol = 0 },
2205
2206 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2207 | USB_DEVICE_ID_MATCH_INT_INFO,
2208 .idVendor = 0x046d,
2209 .idProduct = 0x08c6,
2210 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2211 .bInterfaceSubClass = 1,
2212 .bInterfaceProtocol = 0 },
2213
2214 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2215 | USB_DEVICE_ID_MATCH_INT_INFO,
2216 .idVendor = 0x046d,
2217 .idProduct = 0x08c7,
2218 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2219 .bInterfaceSubClass = 1,
2220 .bInterfaceProtocol = 0 },
2221
2222 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2223 | USB_DEVICE_ID_MATCH_INT_INFO,
2224 .idVendor = 0x046d,
2225 .idProduct = 0x082d,
2226 .bInterfaceClass = USB_CLASS_VIDEO,
2227 .bInterfaceSubClass = 1,
2228 .bInterfaceProtocol = 0,
2229 .driver_info = UVC_QUIRK_RESTORE_CTRLS_ON_INIT },
2230
2231 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2232 | USB_DEVICE_ID_MATCH_INT_INFO,
2233 .idVendor = 0x04f2,
2234 .idProduct = 0xb071,
2235 .bInterfaceClass = USB_CLASS_VIDEO,
2236 .bInterfaceSubClass = 1,
2237 .bInterfaceProtocol = 0,
2238 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2239
2240 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2241 | USB_DEVICE_ID_MATCH_INT_INFO,
2242 .idVendor = 0x058f,
2243 .idProduct = 0x3820,
2244 .bInterfaceClass = USB_CLASS_VIDEO,
2245 .bInterfaceSubClass = 1,
2246 .bInterfaceProtocol = 0,
2247 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2248
2249 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2250 | USB_DEVICE_ID_MATCH_INT_INFO,
2251 .idVendor = 0x05a9,
2252 .idProduct = 0x2640,
2253 .bInterfaceClass = USB_CLASS_VIDEO,
2254 .bInterfaceSubClass = 1,
2255 .bInterfaceProtocol = 0,
2256 .driver_info = UVC_QUIRK_PROBE_DEF },
2257
2258 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2259 | USB_DEVICE_ID_MATCH_INT_INFO,
2260 .idVendor = 0x05a9,
2261 .idProduct = 0x2641,
2262 .bInterfaceClass = USB_CLASS_VIDEO,
2263 .bInterfaceSubClass = 1,
2264 .bInterfaceProtocol = 0,
2265 .driver_info = UVC_QUIRK_PROBE_DEF },
2266
2267 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2268 | USB_DEVICE_ID_MATCH_INT_INFO,
2269 .idVendor = 0x05a9,
2270 .idProduct = 0x2643,
2271 .bInterfaceClass = USB_CLASS_VIDEO,
2272 .bInterfaceSubClass = 1,
2273 .bInterfaceProtocol = 0,
2274 .driver_info = UVC_QUIRK_PROBE_DEF },
2275
2276 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2277 | USB_DEVICE_ID_MATCH_INT_INFO,
2278 .idVendor = 0x05a9,
2279 .idProduct = 0x264a,
2280 .bInterfaceClass = USB_CLASS_VIDEO,
2281 .bInterfaceSubClass = 1,
2282 .bInterfaceProtocol = 0,
2283 .driver_info = UVC_QUIRK_PROBE_DEF },
2284
2285 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2286 | USB_DEVICE_ID_MATCH_INT_INFO,
2287 .idVendor = 0x05a9,
2288 .idProduct = 0x7670,
2289 .bInterfaceClass = USB_CLASS_VIDEO,
2290 .bInterfaceSubClass = 1,
2291 .bInterfaceProtocol = 0,
2292 .driver_info = UVC_QUIRK_PROBE_DEF },
2293
2294 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2295 | USB_DEVICE_ID_MATCH_INT_INFO,
2296 .idVendor = 0x05ac,
2297 .idProduct = 0x8501,
2298 .bInterfaceClass = USB_CLASS_VIDEO,
2299 .bInterfaceSubClass = 1,
2300 .bInterfaceProtocol = 0,
2301 .driver_info = UVC_QUIRK_PROBE_MINMAX
2302 | UVC_QUIRK_BUILTIN_ISIGHT },
2303
2304 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2305 | USB_DEVICE_ID_MATCH_INT_INFO,
2306 .idVendor = 0x05c8,
2307 .idProduct = 0x0403,
2308 .bInterfaceClass = USB_CLASS_VIDEO,
2309 .bInterfaceSubClass = 1,
2310 .bInterfaceProtocol = 0,
2311 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2312
2313 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2314 | USB_DEVICE_ID_MATCH_INT_INFO,
2315 .idVendor = 0x05e3,
2316 .idProduct = 0x0505,
2317 .bInterfaceClass = USB_CLASS_VIDEO,
2318 .bInterfaceSubClass = 1,
2319 .bInterfaceProtocol = 0,
2320 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2321
2322 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2323 | USB_DEVICE_ID_MATCH_INT_INFO,
2324 .idVendor = 0x06f8,
2325 .idProduct = 0x300c,
2326 .bInterfaceClass = USB_CLASS_VIDEO,
2327 .bInterfaceSubClass = 1,
2328 .bInterfaceProtocol = 0,
2329 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2330
2331 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2332 | USB_DEVICE_ID_MATCH_INT_INFO,
2333 .idVendor = 0x0ac8,
2334 .idProduct = 0x332d,
2335 .bInterfaceClass = USB_CLASS_VIDEO,
2336 .bInterfaceSubClass = 1,
2337 .bInterfaceProtocol = 0,
2338 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2339
2340 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2341 | USB_DEVICE_ID_MATCH_INT_INFO,
2342 .idVendor = 0x0ac8,
2343 .idProduct = 0x3410,
2344 .bInterfaceClass = USB_CLASS_VIDEO,
2345 .bInterfaceSubClass = 1,
2346 .bInterfaceProtocol = 0,
2347 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2348
2349 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2350 | USB_DEVICE_ID_MATCH_INT_INFO,
2351 .idVendor = 0x0ac8,
2352 .idProduct = 0x3420,
2353 .bInterfaceClass = USB_CLASS_VIDEO,
2354 .bInterfaceSubClass = 1,
2355 .bInterfaceProtocol = 0,
2356 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2357
2358 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2359 | USB_DEVICE_ID_MATCH_INT_INFO,
2360 .idVendor = 0x0bd3,
2361 .idProduct = 0x0555,
2362 .bInterfaceClass = USB_CLASS_VIDEO,
2363 .bInterfaceSubClass = 1,
2364 .bInterfaceProtocol = 0,
2365 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2366
2367 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2368 | USB_DEVICE_ID_MATCH_INT_INFO,
2369 .idVendor = 0x0e8d,
2370 .idProduct = 0x0004,
2371 .bInterfaceClass = USB_CLASS_VIDEO,
2372 .bInterfaceSubClass = 1,
2373 .bInterfaceProtocol = 0,
2374 .driver_info = UVC_QUIRK_PROBE_MINMAX
2375 | UVC_QUIRK_PROBE_DEF },
2376
2377 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2378 | USB_DEVICE_ID_MATCH_INT_INFO,
2379 .idVendor = 0x13d3,
2380 .idProduct = 0x5103,
2381 .bInterfaceClass = USB_CLASS_VIDEO,
2382 .bInterfaceSubClass = 1,
2383 .bInterfaceProtocol = 0,
2384 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2385
2386 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2387 | USB_DEVICE_ID_MATCH_INT_INFO,
2388 .idVendor = 0x152d,
2389 .idProduct = 0x0310,
2390 .bInterfaceClass = USB_CLASS_VIDEO,
2391 .bInterfaceSubClass = 1,
2392 .bInterfaceProtocol = 0,
2393 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2394
2395 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2396 | USB_DEVICE_ID_MATCH_INT_INFO,
2397 .idVendor = 0x174f,
2398 .idProduct = 0x5212,
2399 .bInterfaceClass = USB_CLASS_VIDEO,
2400 .bInterfaceSubClass = 1,
2401 .bInterfaceProtocol = 0,
2402 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2403
2404 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2405 | USB_DEVICE_ID_MATCH_INT_INFO,
2406 .idVendor = 0x174f,
2407 .idProduct = 0x5931,
2408 .bInterfaceClass = USB_CLASS_VIDEO,
2409 .bInterfaceSubClass = 1,
2410 .bInterfaceProtocol = 0,
2411 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2412
2413 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2414 | USB_DEVICE_ID_MATCH_INT_INFO,
2415 .idVendor = 0x174f,
2416 .idProduct = 0x8a12,
2417 .bInterfaceClass = USB_CLASS_VIDEO,
2418 .bInterfaceSubClass = 1,
2419 .bInterfaceProtocol = 0,
2420 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2421
2422 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2423 | USB_DEVICE_ID_MATCH_INT_INFO,
2424 .idVendor = 0x174f,
2425 .idProduct = 0x8a31,
2426 .bInterfaceClass = USB_CLASS_VIDEO,
2427 .bInterfaceSubClass = 1,
2428 .bInterfaceProtocol = 0,
2429 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2430
2431 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2432 | USB_DEVICE_ID_MATCH_INT_INFO,
2433 .idVendor = 0x174f,
2434 .idProduct = 0x8a33,
2435 .bInterfaceClass = USB_CLASS_VIDEO,
2436 .bInterfaceSubClass = 1,
2437 .bInterfaceProtocol = 0,
2438 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2439
2440 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2441 | USB_DEVICE_ID_MATCH_INT_INFO,
2442 .idVendor = 0x174f,
2443 .idProduct = 0x8a34,
2444 .bInterfaceClass = USB_CLASS_VIDEO,
2445 .bInterfaceSubClass = 1,
2446 .bInterfaceProtocol = 0,
2447 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2448
2449 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2450 | USB_DEVICE_ID_MATCH_INT_INFO,
2451 .idVendor = 0x17dc,
2452 .idProduct = 0x0202,
2453 .bInterfaceClass = USB_CLASS_VIDEO,
2454 .bInterfaceSubClass = 1,
2455 .bInterfaceProtocol = 0,
2456 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2457
2458 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2459 | USB_DEVICE_ID_MATCH_INT_INFO,
2460 .idVendor = 0x17ef,
2461 .idProduct = 0x480b,
2462 .bInterfaceClass = USB_CLASS_VIDEO,
2463 .bInterfaceSubClass = 1,
2464 .bInterfaceProtocol = 0,
2465 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2466
2467 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2468 | USB_DEVICE_ID_MATCH_INT_INFO,
2469 .idVendor = 0x1871,
2470 .idProduct = 0x0306,
2471 .bInterfaceClass = USB_CLASS_VIDEO,
2472 .bInterfaceSubClass = 1,
2473 .bInterfaceProtocol = 0,
2474 .driver_info = UVC_QUIRK_PROBE_MINMAX
2475 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2476
2477 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2478 | USB_DEVICE_ID_MATCH_INT_INFO,
2479 .idVendor = 0x1871,
2480 .idProduct = 0x0516,
2481 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2482 .bInterfaceSubClass = 1,
2483 .bInterfaceProtocol = 0 },
2484
2485 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2486 | USB_DEVICE_ID_MATCH_INT_INFO,
2487 .idVendor = 0x18cd,
2488 .idProduct = 0xcafe,
2489 .bInterfaceClass = USB_CLASS_VIDEO,
2490 .bInterfaceSubClass = 1,
2491 .bInterfaceProtocol = 0,
2492 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2493
2494 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2495 | USB_DEVICE_ID_MATCH_INT_INFO,
2496 .idVendor = 0x18ec,
2497 .idProduct = 0x3188,
2498 .bInterfaceClass = USB_CLASS_VIDEO,
2499 .bInterfaceSubClass = 1,
2500 .bInterfaceProtocol = 0,
2501 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2502
2503 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2504 | USB_DEVICE_ID_MATCH_INT_INFO,
2505 .idVendor = 0x18ec,
2506 .idProduct = 0x3288,
2507 .bInterfaceClass = USB_CLASS_VIDEO,
2508 .bInterfaceSubClass = 1,
2509 .bInterfaceProtocol = 0,
2510 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2511
2512 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2513 | USB_DEVICE_ID_MATCH_INT_INFO,
2514 .idVendor = 0x18ec,
2515 .idProduct = 0x3290,
2516 .bInterfaceClass = USB_CLASS_VIDEO,
2517 .bInterfaceSubClass = 1,
2518 .bInterfaceProtocol = 0,
2519 .driver_info = UVC_QUIRK_PROBE_DEF },
2520
2521 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2522 | USB_DEVICE_ID_MATCH_INT_INFO,
2523 .idVendor = 0x199e,
2524 .idProduct = 0x8102,
2525 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2526 .bInterfaceSubClass = 1,
2527 .bInterfaceProtocol = 0 },
2528
2529 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2530 | USB_DEVICE_ID_MATCH_DEV_HI
2531 | USB_DEVICE_ID_MATCH_INT_INFO,
2532 .idVendor = 0x19ab,
2533 .idProduct = 0x1000,
2534 .bcdDevice_hi = 0x0126,
2535 .bInterfaceClass = USB_CLASS_VIDEO,
2536 .bInterfaceSubClass = 1,
2537 .bInterfaceProtocol = 0,
2538 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
2539
2540 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2541 | USB_DEVICE_ID_MATCH_INT_INFO,
2542 .idVendor = 0x1b3b,
2543 .idProduct = 0x2951,
2544 .bInterfaceClass = USB_CLASS_VIDEO,
2545 .bInterfaceSubClass = 1,
2546 .bInterfaceProtocol = 0,
2547 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2548
2549 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2550 | USB_DEVICE_ID_MATCH_INT_INFO,
2551 .idVendor = 0x1c4f,
2552 .idProduct = 0x3000,
2553 .bInterfaceClass = USB_CLASS_VIDEO,
2554 .bInterfaceSubClass = 1,
2555 .bInterfaceProtocol = 0,
2556 .driver_info = UVC_QUIRK_PROBE_MINMAX
2557 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2558
2559 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2560 | USB_DEVICE_ID_MATCH_INT_INFO,
2561 .idVendor = 0x2833,
2562 .idProduct = 0x0201,
2563 .bInterfaceClass = USB_CLASS_VIDEO,
2564 .bInterfaceSubClass = 1,
2565 .bInterfaceProtocol = 0,
2566 .driver_info = UVC_QUIRK_FORCE_Y8 },
2567
2568 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
2569 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
2570 {}
2571};
2572
2573MODULE_DEVICE_TABLE(usb, uvc_ids);
2574
2575struct uvc_driver uvc_driver = {
2576 .driver = {
2577 .name = "uvcvideo",
2578 .probe = uvc_probe,
2579 .disconnect = uvc_disconnect,
2580 .suspend = uvc_suspend,
2581 .resume = uvc_resume,
2582 .reset_resume = uvc_reset_resume,
2583 .id_table = uvc_ids,
2584 .supports_autosuspend = 1,
2585 },
2586};
2587
2588static int __init uvc_init(void)
2589{
2590 int ret;
2591
2592 uvc_debugfs_init();
2593
2594 ret = usb_register(&uvc_driver.driver);
2595 if (ret < 0) {
2596 uvc_debugfs_cleanup();
2597 return ret;
2598 }
2599
2600 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2601 return 0;
2602}
2603
2604static void __exit uvc_cleanup(void)
2605{
2606 usb_deregister(&uvc_driver.driver);
2607 uvc_debugfs_cleanup();
2608}
2609
2610module_init(uvc_init);
2611module_exit(uvc_cleanup);
2612
2613MODULE_AUTHOR(DRIVER_AUTHOR);
2614MODULE_DESCRIPTION(DRIVER_DESC);
2615MODULE_LICENSE("GPL");
2616MODULE_VERSION(DRIVER_VERSION);
2617
2618