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