2 * uvc_driver.c -- USB Video Class driver
4 * Copyright (C) 2005-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
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>
26 #include <media/v4l2-common.h>
30 #define DRIVER_AUTHOR "Laurent Pinchart " \
31 "<laurent.pinchart@ideasonboard.com>"
32 #define DRIVER_DESC "USB Video Class driver"
34 unsigned int uvc_clock_param
= CLOCK_MONOTONIC
;
35 unsigned int uvc_no_drop_param
;
36 static unsigned int uvc_quirks_param
= -1;
37 unsigned int uvc_trace_param
;
38 unsigned int uvc_timeout_param
= UVC_CTRL_STREAMING_TIMEOUT
;
40 /* ------------------------------------------------------------------------
44 static struct uvc_format_desc uvc_fmts
[] = {
46 .name
= "YUV 4:2:2 (YUYV)",
47 .guid
= UVC_GUID_FORMAT_YUY2
,
48 .fcc
= V4L2_PIX_FMT_YUYV
,
51 .name
= "YUV 4:2:2 (YUYV)",
52 .guid
= UVC_GUID_FORMAT_YUY2_ISIGHT
,
53 .fcc
= V4L2_PIX_FMT_YUYV
,
56 .name
= "YUV 4:2:0 (NV12)",
57 .guid
= UVC_GUID_FORMAT_NV12
,
58 .fcc
= V4L2_PIX_FMT_NV12
,
62 .guid
= UVC_GUID_FORMAT_MJPEG
,
63 .fcc
= V4L2_PIX_FMT_MJPEG
,
66 .name
= "YVU 4:2:0 (YV12)",
67 .guid
= UVC_GUID_FORMAT_YV12
,
68 .fcc
= V4L2_PIX_FMT_YVU420
,
71 .name
= "YUV 4:2:0 (I420)",
72 .guid
= UVC_GUID_FORMAT_I420
,
73 .fcc
= V4L2_PIX_FMT_YUV420
,
76 .name
= "YUV 4:2:0 (M420)",
77 .guid
= UVC_GUID_FORMAT_M420
,
78 .fcc
= V4L2_PIX_FMT_M420
,
81 .name
= "YUV 4:2:2 (UYVY)",
82 .guid
= UVC_GUID_FORMAT_UYVY
,
83 .fcc
= V4L2_PIX_FMT_UYVY
,
86 .name
= "Greyscale 8-bit (Y800)",
87 .guid
= UVC_GUID_FORMAT_Y800
,
88 .fcc
= V4L2_PIX_FMT_GREY
,
91 .name
= "Greyscale 8-bit (Y8 )",
92 .guid
= UVC_GUID_FORMAT_Y8
,
93 .fcc
= V4L2_PIX_FMT_GREY
,
96 .name
= "Greyscale 10-bit (Y10 )",
97 .guid
= UVC_GUID_FORMAT_Y10
,
98 .fcc
= V4L2_PIX_FMT_Y10
,
101 .name
= "Greyscale 12-bit (Y12 )",
102 .guid
= UVC_GUID_FORMAT_Y12
,
103 .fcc
= V4L2_PIX_FMT_Y12
,
106 .name
= "Greyscale 16-bit (Y16 )",
107 .guid
= UVC_GUID_FORMAT_Y16
,
108 .fcc
= V4L2_PIX_FMT_Y16
,
112 .guid
= UVC_GUID_FORMAT_BY8
,
113 .fcc
= V4L2_PIX_FMT_SBGGR8
,
117 .guid
= UVC_GUID_FORMAT_RGBP
,
118 .fcc
= V4L2_PIX_FMT_RGB565
,
122 .guid
= UVC_GUID_FORMAT_H264
,
123 .fcc
= V4L2_PIX_FMT_H264
,
127 /* ------------------------------------------------------------------------
131 struct usb_host_endpoint
*uvc_find_endpoint(struct usb_host_interface
*alts
,
134 struct usb_host_endpoint
*ep
;
137 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
138 ep
= &alts
->endpoint
[i
];
139 if (ep
->desc
.bEndpointAddress
== epaddr
)
146 static struct uvc_format_desc
*uvc_format_by_guid(const __u8 guid
[16])
148 unsigned int len
= ARRAY_SIZE(uvc_fmts
);
151 for (i
= 0; i
< len
; ++i
) {
152 if (memcmp(guid
, uvc_fmts
[i
].guid
, 16) == 0)
159 static __u32
uvc_colorspace(const __u8 primaries
)
161 static const __u8 colorprimaries
[] = {
163 V4L2_COLORSPACE_SRGB
,
164 V4L2_COLORSPACE_470_SYSTEM_M
,
165 V4L2_COLORSPACE_470_SYSTEM_BG
,
166 V4L2_COLORSPACE_SMPTE170M
,
167 V4L2_COLORSPACE_SMPTE240M
,
170 if (primaries
< ARRAY_SIZE(colorprimaries
))
171 return colorprimaries
[primaries
];
176 /* Simplify a fraction using a simple continued fraction decomposition. The
177 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
178 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
179 * arbitrary parameters to remove non-significative terms from the simple
180 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
181 * respectively seems to give nice results.
183 void uvc_simplify_fraction(uint32_t *numerator
, uint32_t *denominator
,
184 unsigned int n_terms
, unsigned int threshold
)
190 an
= kmalloc(n_terms
* sizeof *an
, GFP_KERNEL
);
194 /* Convert the fraction to a simple continued fraction. See
195 * http://mathforum.org/dr.math/faq/faq.fractions.html
196 * Stop if the current term is bigger than or equal to the given
202 for (n
= 0; n
< n_terms
&& y
!= 0; ++n
) {
204 if (an
[n
] >= threshold
) {
215 /* Expand the simple continued fraction back to an integer fraction. */
219 for (i
= n
; i
> 0; --i
) {
230 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
231 * to compute numerator / denominator * 10000000 using 32 bit fixed point
234 uint32_t uvc_fraction_to_interval(uint32_t numerator
, uint32_t denominator
)
238 /* Saturate the result if the operation would overflow. */
239 if (denominator
== 0 ||
240 numerator
/denominator
>= ((uint32_t)-1)/10000000)
243 /* Divide both the denominator and the multiplier by two until
244 * numerator * multiplier doesn't overflow. If anyone knows a better
245 * algorithm please let me know.
247 multiplier
= 10000000;
248 while (numerator
> ((uint32_t)-1)/multiplier
) {
253 return denominator
? numerator
* multiplier
/ denominator
: 0;
256 /* ------------------------------------------------------------------------
257 * Terminal and unit management
260 struct uvc_entity
*uvc_entity_by_id(struct uvc_device
*dev
, int id
)
262 struct uvc_entity
*entity
;
264 list_for_each_entry(entity
, &dev
->entities
, list
) {
265 if (entity
->id
== id
)
272 static struct uvc_entity
*uvc_entity_by_reference(struct uvc_device
*dev
,
273 int id
, struct uvc_entity
*entity
)
278 entity
= list_entry(&dev
->entities
, struct uvc_entity
, list
);
280 list_for_each_entry_continue(entity
, &dev
->entities
, list
) {
281 for (i
= 0; i
< entity
->bNrInPins
; ++i
)
282 if (entity
->baSourceID
[i
] == id
)
289 static struct uvc_streaming
*uvc_stream_by_id(struct uvc_device
*dev
, int id
)
291 struct uvc_streaming
*stream
;
293 list_for_each_entry(stream
, &dev
->streams
, list
) {
294 if (stream
->header
.bTerminalLink
== id
)
301 /* ------------------------------------------------------------------------
302 * Descriptors parsing
305 static int uvc_parse_format(struct uvc_device
*dev
,
306 struct uvc_streaming
*streaming
, struct uvc_format
*format
,
307 __u32
**intervals
, unsigned char *buffer
, int buflen
)
309 struct usb_interface
*intf
= streaming
->intf
;
310 struct usb_host_interface
*alts
= intf
->cur_altsetting
;
311 struct uvc_format_desc
*fmtdesc
;
312 struct uvc_frame
*frame
;
313 const unsigned char *start
= buffer
;
314 unsigned int interval
;
318 format
->type
= buffer
[2];
319 format
->index
= buffer
[3];
322 case UVC_VS_FORMAT_UNCOMPRESSED
:
323 case UVC_VS_FORMAT_FRAME_BASED
:
324 n
= buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
? 27 : 28;
326 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
327 "interface %d FORMAT error\n",
329 alts
->desc
.bInterfaceNumber
);
333 /* Find the format descriptor from its GUID. */
334 fmtdesc
= uvc_format_by_guid(&buffer
[5]);
336 if (fmtdesc
!= NULL
) {
337 strlcpy(format
->name
, fmtdesc
->name
,
338 sizeof format
->name
);
339 format
->fcc
= fmtdesc
->fcc
;
341 uvc_printk(KERN_INFO
, "Unknown video format %pUl\n",
343 snprintf(format
->name
, sizeof(format
->name
), "%pUl\n",
348 format
->bpp
= buffer
[21];
349 if (buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
) {
350 ftype
= UVC_VS_FRAME_UNCOMPRESSED
;
352 ftype
= UVC_VS_FRAME_FRAME_BASED
;
354 format
->flags
= UVC_FMT_FLAG_COMPRESSED
;
358 case UVC_VS_FORMAT_MJPEG
:
360 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
361 "interface %d FORMAT error\n",
363 alts
->desc
.bInterfaceNumber
);
367 strlcpy(format
->name
, "MJPEG", sizeof format
->name
);
368 format
->fcc
= V4L2_PIX_FMT_MJPEG
;
369 format
->flags
= UVC_FMT_FLAG_COMPRESSED
;
371 ftype
= UVC_VS_FRAME_MJPEG
;
374 case UVC_VS_FORMAT_DV
:
376 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
377 "interface %d FORMAT error\n",
379 alts
->desc
.bInterfaceNumber
);
383 switch (buffer
[8] & 0x7f) {
385 strlcpy(format
->name
, "SD-DV", sizeof format
->name
);
388 strlcpy(format
->name
, "SDL-DV", sizeof format
->name
);
391 strlcpy(format
->name
, "HD-DV", sizeof format
->name
);
394 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
395 "interface %d: unknown DV format %u\n",
397 alts
->desc
.bInterfaceNumber
, buffer
[8]);
401 strlcat(format
->name
, buffer
[8] & (1 << 7) ? " 60Hz" : " 50Hz",
402 sizeof format
->name
);
404 format
->fcc
= V4L2_PIX_FMT_DV
;
405 format
->flags
= UVC_FMT_FLAG_COMPRESSED
| UVC_FMT_FLAG_STREAM
;
409 /* Create a dummy frame descriptor. */
410 frame
= &format
->frame
[0];
411 memset(&format
->frame
[0], 0, sizeof format
->frame
[0]);
412 frame
->bFrameIntervalType
= 1;
413 frame
->dwDefaultFrameInterval
= 1;
414 frame
->dwFrameInterval
= *intervals
;
419 case UVC_VS_FORMAT_MPEG2TS
:
420 case UVC_VS_FORMAT_STREAM_BASED
:
421 /* Not supported yet. */
423 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
424 "interface %d unsupported format %u\n",
425 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
,
430 uvc_trace(UVC_TRACE_DESCR
, "Found format %s.\n", format
->name
);
435 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
436 * based formats have frame descriptors.
438 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
439 buffer
[2] == ftype
) {
440 frame
= &format
->frame
[format
->nframes
];
441 if (ftype
!= UVC_VS_FRAME_FRAME_BASED
)
442 n
= buflen
> 25 ? buffer
[25] : 0;
444 n
= buflen
> 21 ? buffer
[21] : 0;
448 if (buflen
< 26 + 4*n
) {
449 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
450 "interface %d FRAME error\n", dev
->udev
->devnum
,
451 alts
->desc
.bInterfaceNumber
);
455 frame
->bFrameIndex
= buffer
[3];
456 frame
->bmCapabilities
= buffer
[4];
457 frame
->wWidth
= get_unaligned_le16(&buffer
[5]);
458 frame
->wHeight
= get_unaligned_le16(&buffer
[7]);
459 frame
->dwMinBitRate
= get_unaligned_le32(&buffer
[9]);
460 frame
->dwMaxBitRate
= get_unaligned_le32(&buffer
[13]);
461 if (ftype
!= UVC_VS_FRAME_FRAME_BASED
) {
462 frame
->dwMaxVideoFrameBufferSize
=
463 get_unaligned_le32(&buffer
[17]);
464 frame
->dwDefaultFrameInterval
=
465 get_unaligned_le32(&buffer
[21]);
466 frame
->bFrameIntervalType
= buffer
[25];
468 frame
->dwMaxVideoFrameBufferSize
= 0;
469 frame
->dwDefaultFrameInterval
=
470 get_unaligned_le32(&buffer
[17]);
471 frame
->bFrameIntervalType
= buffer
[21];
473 frame
->dwFrameInterval
= *intervals
;
475 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
476 * completely. Observed behaviours range from setting the
477 * value to 1.1x the actual frame size to hardwiring the
478 * 16 low bits to 0. This results in a higher than necessary
479 * memory usage as well as a wrong image size information. For
480 * uncompressed formats this can be fixed by computing the
481 * value from the frame size.
483 if (!(format
->flags
& UVC_FMT_FLAG_COMPRESSED
))
484 frame
->dwMaxVideoFrameBufferSize
= format
->bpp
485 * frame
->wWidth
* frame
->wHeight
/ 8;
487 /* Some bogus devices report dwMinFrameInterval equal to
488 * dwMaxFrameInterval and have dwFrameIntervalStep set to
489 * zero. Setting all null intervals to 1 fixes the problem and
490 * some other divisions by zero that could happen.
492 for (i
= 0; i
< n
; ++i
) {
493 interval
= get_unaligned_le32(&buffer
[26+4*i
]);
494 *(*intervals
)++ = interval
? interval
: 1;
497 /* Make sure that the default frame interval stays between
500 n
-= frame
->bFrameIntervalType
? 1 : 2;
501 frame
->dwDefaultFrameInterval
=
502 min(frame
->dwFrameInterval
[n
],
503 max(frame
->dwFrameInterval
[0],
504 frame
->dwDefaultFrameInterval
));
506 if (dev
->quirks
& UVC_QUIRK_RESTRICT_FRAME_RATE
) {
507 frame
->bFrameIntervalType
= 1;
508 frame
->dwFrameInterval
[0] =
509 frame
->dwDefaultFrameInterval
;
512 uvc_trace(UVC_TRACE_DESCR
, "- %ux%u (%u.%u fps)\n",
513 frame
->wWidth
, frame
->wHeight
,
514 10000000/frame
->dwDefaultFrameInterval
,
515 (100000000/frame
->dwDefaultFrameInterval
)%10);
522 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
523 buffer
[2] == UVC_VS_STILL_IMAGE_FRAME
) {
528 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
529 buffer
[2] == UVC_VS_COLORFORMAT
) {
531 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
532 "interface %d COLORFORMAT error\n",
534 alts
->desc
.bInterfaceNumber
);
538 format
->colorspace
= uvc_colorspace(buffer
[3]);
544 return buffer
- start
;
547 static int uvc_parse_streaming(struct uvc_device
*dev
,
548 struct usb_interface
*intf
)
550 struct uvc_streaming
*streaming
= NULL
;
551 struct uvc_format
*format
;
552 struct uvc_frame
*frame
;
553 struct usb_host_interface
*alts
= &intf
->altsetting
[0];
554 unsigned char *_buffer
, *buffer
= alts
->extra
;
555 int _buflen
, buflen
= alts
->extralen
;
556 unsigned int nformats
= 0, nframes
= 0, nintervals
= 0;
557 unsigned int size
, i
, n
, p
;
562 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
563 != UVC_SC_VIDEOSTREAMING
) {
564 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d isn't a "
565 "video streaming interface\n", dev
->udev
->devnum
,
566 intf
->altsetting
[0].desc
.bInterfaceNumber
);
570 if (usb_driver_claim_interface(&uvc_driver
.driver
, intf
, dev
)) {
571 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d is already "
572 "claimed\n", dev
->udev
->devnum
,
573 intf
->altsetting
[0].desc
.bInterfaceNumber
);
577 streaming
= kzalloc(sizeof *streaming
, GFP_KERNEL
);
578 if (streaming
== NULL
) {
579 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
583 mutex_init(&streaming
->mutex
);
584 streaming
->dev
= dev
;
585 streaming
->intf
= usb_get_intf(intf
);
586 streaming
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
588 /* The Pico iMage webcam has its class-specific interface descriptors
589 * after the endpoint descriptors.
592 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
593 struct usb_host_endpoint
*ep
= &alts
->endpoint
[i
];
595 if (ep
->extralen
== 0)
598 if (ep
->extralen
> 2 &&
599 ep
->extra
[1] == USB_DT_CS_INTERFACE
) {
600 uvc_trace(UVC_TRACE_DESCR
, "trying extra data "
601 "from endpoint %u.\n", i
);
602 buffer
= alts
->endpoint
[i
].extra
;
603 buflen
= alts
->endpoint
[i
].extralen
;
609 /* Skip the standard interface descriptors. */
610 while (buflen
> 2 && buffer
[1] != USB_DT_CS_INTERFACE
) {
616 uvc_trace(UVC_TRACE_DESCR
, "no class-specific streaming "
617 "interface descriptors found.\n");
621 /* Parse the header descriptor. */
623 case UVC_VS_OUTPUT_HEADER
:
624 streaming
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
628 case UVC_VS_INPUT_HEADER
:
629 streaming
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
634 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
635 "%d HEADER descriptor not found.\n", dev
->udev
->devnum
,
636 alts
->desc
.bInterfaceNumber
);
640 p
= buflen
>= 4 ? buffer
[3] : 0;
641 n
= buflen
>= size
? buffer
[size
-1] : 0;
643 if (buflen
< size
+ p
*n
) {
644 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
645 "interface %d HEADER descriptor is invalid.\n",
646 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
650 streaming
->header
.bNumFormats
= p
;
651 streaming
->header
.bEndpointAddress
= buffer
[6];
652 if (buffer
[2] == UVC_VS_INPUT_HEADER
) {
653 streaming
->header
.bmInfo
= buffer
[7];
654 streaming
->header
.bTerminalLink
= buffer
[8];
655 streaming
->header
.bStillCaptureMethod
= buffer
[9];
656 streaming
->header
.bTriggerSupport
= buffer
[10];
657 streaming
->header
.bTriggerUsage
= buffer
[11];
659 streaming
->header
.bTerminalLink
= buffer
[7];
661 streaming
->header
.bControlSize
= n
;
663 streaming
->header
.bmaControls
= kmemdup(&buffer
[size
], p
* n
,
665 if (streaming
->header
.bmaControls
== NULL
) {
676 /* Count the format and frame descriptors. */
677 while (_buflen
> 2 && _buffer
[1] == USB_DT_CS_INTERFACE
) {
678 switch (_buffer
[2]) {
679 case UVC_VS_FORMAT_UNCOMPRESSED
:
680 case UVC_VS_FORMAT_MJPEG
:
681 case UVC_VS_FORMAT_FRAME_BASED
:
685 case UVC_VS_FORMAT_DV
:
686 /* DV format has no frame descriptor. We will create a
687 * dummy frame descriptor with a dummy frame interval.
694 case UVC_VS_FORMAT_MPEG2TS
:
695 case UVC_VS_FORMAT_STREAM_BASED
:
696 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
697 "interface %d FORMAT %u is not supported.\n",
699 alts
->desc
.bInterfaceNumber
, _buffer
[2]);
702 case UVC_VS_FRAME_UNCOMPRESSED
:
703 case UVC_VS_FRAME_MJPEG
:
706 nintervals
+= _buffer
[25] ? _buffer
[25] : 3;
709 case UVC_VS_FRAME_FRAME_BASED
:
712 nintervals
+= _buffer
[21] ? _buffer
[21] : 3;
716 _buflen
-= _buffer
[0];
717 _buffer
+= _buffer
[0];
721 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
722 "%d has no supported formats defined.\n",
723 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
727 size
= nformats
* sizeof *format
+ nframes
* sizeof *frame
728 + nintervals
* sizeof *interval
;
729 format
= kzalloc(size
, GFP_KERNEL
);
730 if (format
== NULL
) {
735 frame
= (struct uvc_frame
*)&format
[nformats
];
736 interval
= (__u32
*)&frame
[nframes
];
738 streaming
->format
= format
;
739 streaming
->nformats
= nformats
;
741 /* Parse the format descriptors. */
742 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
) {
744 case UVC_VS_FORMAT_UNCOMPRESSED
:
745 case UVC_VS_FORMAT_MJPEG
:
746 case UVC_VS_FORMAT_DV
:
747 case UVC_VS_FORMAT_FRAME_BASED
:
748 format
->frame
= frame
;
749 ret
= uvc_parse_format(dev
, streaming
, format
,
750 &interval
, buffer
, buflen
);
754 frame
+= format
->nframes
;
770 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
771 "%d has %u bytes of trailing descriptor garbage.\n",
772 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
, buflen
);
774 /* Parse the alternate settings to find the maximum bandwidth. */
775 for (i
= 0; i
< intf
->num_altsetting
; ++i
) {
776 struct usb_host_endpoint
*ep
;
777 alts
= &intf
->altsetting
[i
];
778 ep
= uvc_find_endpoint(alts
,
779 streaming
->header
.bEndpointAddress
);
783 psize
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
784 psize
= (psize
& 0x07ff) * (1 + ((psize
>> 11) & 3));
785 if (psize
> streaming
->maxpsize
)
786 streaming
->maxpsize
= psize
;
789 list_add_tail(&streaming
->list
, &dev
->streams
);
793 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
795 kfree(streaming
->format
);
796 kfree(streaming
->header
.bmaControls
);
801 static struct uvc_entity
*uvc_alloc_entity(u16 type
, u8 id
,
802 unsigned int num_pads
, unsigned int extra_size
)
804 struct uvc_entity
*entity
;
805 unsigned int num_inputs
;
809 extra_size
= ALIGN(extra_size
, sizeof(*entity
->pads
));
810 num_inputs
= (type
& UVC_TERM_OUTPUT
) ? num_pads
: num_pads
- 1;
811 size
= sizeof(*entity
) + extra_size
+ sizeof(*entity
->pads
) * num_pads
813 entity
= kzalloc(size
, GFP_KERNEL
);
820 entity
->num_links
= 0;
821 entity
->num_pads
= num_pads
;
822 entity
->pads
= ((void *)(entity
+ 1)) + extra_size
;
824 for (i
= 0; i
< num_inputs
; ++i
)
825 entity
->pads
[i
].flags
= MEDIA_PAD_FL_SINK
;
826 if (!UVC_ENTITY_IS_OTERM(entity
))
827 entity
->pads
[num_pads
-1].flags
= MEDIA_PAD_FL_SOURCE
;
829 entity
->bNrInPins
= num_inputs
;
830 entity
->baSourceID
= (__u8
*)(&entity
->pads
[num_pads
]);
835 /* Parse vendor-specific extensions. */
836 static int uvc_parse_vendor_control(struct uvc_device
*dev
,
837 const unsigned char *buffer
, int buflen
)
839 struct usb_device
*udev
= dev
->udev
;
840 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
841 struct uvc_entity
*unit
;
845 switch (le16_to_cpu(dev
->udev
->descriptor
.idVendor
)) {
846 case 0x046d: /* Logitech */
847 if (buffer
[1] != 0x41 || buffer
[2] != 0x01)
850 /* Logitech implements several vendor specific functions
851 * through vendor specific extension units (LXU).
853 * The LXU descriptors are similar to XU descriptors
854 * (see "USB Device Video Class for Video Devices", section
855 * 3.7.2.6 "Extension Unit Descriptor") with the following
858 * ----------------------------------------------------------
860 * Size of this descriptor, in bytes: 24+p+n*2
861 * ----------------------------------------------------------
862 * 23+p+n bmControlsType N Bitmap
863 * Individual bits in the set are defined:
867 * This bitset is mapped exactly the same as bmControls.
868 * ----------------------------------------------------------
869 * 23+p+n*2 bReserved 1 Boolean
870 * ----------------------------------------------------------
871 * 24+p+n*2 iExtension 1 Index
872 * Index of a string descriptor that describes this
874 * ----------------------------------------------------------
876 p
= buflen
>= 22 ? buffer
[21] : 0;
877 n
= buflen
>= 25 + p
? buffer
[22+p
] : 0;
879 if (buflen
< 25 + p
+ 2*n
) {
880 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
881 "interface %d EXTENSION_UNIT error\n",
882 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
886 unit
= uvc_alloc_entity(UVC_VC_EXTENSION_UNIT
, buffer
[3],
891 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
892 unit
->extension
.bNumControls
= buffer
[20];
893 memcpy(unit
->baSourceID
, &buffer
[22], p
);
894 unit
->extension
.bControlSize
= buffer
[22+p
];
895 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof(*unit
);
896 unit
->extension
.bmControlsType
= (__u8
*)unit
+ sizeof(*unit
)
898 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], 2*n
);
900 if (buffer
[24+p
+2*n
] != 0)
901 usb_string(udev
, buffer
[24+p
+2*n
], unit
->name
,
904 sprintf(unit
->name
, "Extension %u", buffer
[3]);
906 list_add_tail(&unit
->list
, &dev
->entities
);
914 static int uvc_parse_standard_control(struct uvc_device
*dev
,
915 const unsigned char *buffer
, int buflen
)
917 struct usb_device
*udev
= dev
->udev
;
918 struct uvc_entity
*unit
, *term
;
919 struct usb_interface
*intf
;
920 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
921 unsigned int i
, n
, p
, len
;
926 n
= buflen
>= 12 ? buffer
[11] : 0;
928 if (buflen
< 12 || buflen
< 12 + n
) {
929 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
930 "interface %d HEADER error\n", udev
->devnum
,
931 alts
->desc
.bInterfaceNumber
);
935 dev
->uvc_version
= get_unaligned_le16(&buffer
[3]);
936 dev
->clock_frequency
= get_unaligned_le32(&buffer
[7]);
938 /* Parse all USB Video Streaming interfaces. */
939 for (i
= 0; i
< n
; ++i
) {
940 intf
= usb_ifnum_to_if(udev
, buffer
[12+i
]);
942 uvc_trace(UVC_TRACE_DESCR
, "device %d "
943 "interface %d doesn't exists\n",
948 uvc_parse_streaming(dev
, intf
);
952 case UVC_VC_INPUT_TERMINAL
:
954 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
955 "interface %d INPUT_TERMINAL error\n",
956 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
960 /* Make sure the terminal type MSB is not null, otherwise it
961 * could be confused with a unit.
963 type
= get_unaligned_le16(&buffer
[4]);
964 if ((type
& 0xff00) == 0) {
965 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
966 "interface %d INPUT_TERMINAL %d has invalid "
967 "type 0x%04x, skipping\n", udev
->devnum
,
968 alts
->desc
.bInterfaceNumber
,
977 if (type
== UVC_ITT_CAMERA
) {
978 n
= buflen
>= 15 ? buffer
[14] : 0;
981 } else if (type
== UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
982 n
= buflen
>= 9 ? buffer
[8] : 0;
983 p
= buflen
>= 10 + n
? buffer
[9+n
] : 0;
987 if (buflen
< len
+ n
+ p
) {
988 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
989 "interface %d INPUT_TERMINAL error\n",
990 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
994 term
= uvc_alloc_entity(type
| UVC_TERM_INPUT
, buffer
[3],
999 if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
) {
1000 term
->camera
.bControlSize
= n
;
1001 term
->camera
.bmControls
= (__u8
*)term
+ sizeof *term
;
1002 term
->camera
.wObjectiveFocalLengthMin
=
1003 get_unaligned_le16(&buffer
[8]);
1004 term
->camera
.wObjectiveFocalLengthMax
=
1005 get_unaligned_le16(&buffer
[10]);
1006 term
->camera
.wOcularFocalLength
=
1007 get_unaligned_le16(&buffer
[12]);
1008 memcpy(term
->camera
.bmControls
, &buffer
[15], n
);
1009 } else if (UVC_ENTITY_TYPE(term
) ==
1010 UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
1011 term
->media
.bControlSize
= n
;
1012 term
->media
.bmControls
= (__u8
*)term
+ sizeof *term
;
1013 term
->media
.bTransportModeSize
= p
;
1014 term
->media
.bmTransportModes
= (__u8
*)term
1016 memcpy(term
->media
.bmControls
, &buffer
[9], n
);
1017 memcpy(term
->media
.bmTransportModes
, &buffer
[10+n
], p
);
1021 usb_string(udev
, buffer
[7], term
->name
,
1023 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
)
1024 sprintf(term
->name
, "Camera %u", buffer
[3]);
1025 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_MEDIA_TRANSPORT_INPUT
)
1026 sprintf(term
->name
, "Media %u", buffer
[3]);
1028 sprintf(term
->name
, "Input %u", buffer
[3]);
1030 list_add_tail(&term
->list
, &dev
->entities
);
1033 case UVC_VC_OUTPUT_TERMINAL
:
1035 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1036 "interface %d OUTPUT_TERMINAL error\n",
1037 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1041 /* Make sure the terminal type MSB is not null, otherwise it
1042 * could be confused with a unit.
1044 type
= get_unaligned_le16(&buffer
[4]);
1045 if ((type
& 0xff00) == 0) {
1046 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1047 "interface %d OUTPUT_TERMINAL %d has invalid "
1048 "type 0x%04x, skipping\n", udev
->devnum
,
1049 alts
->desc
.bInterfaceNumber
, buffer
[3], type
);
1053 term
= uvc_alloc_entity(type
| UVC_TERM_OUTPUT
, buffer
[3],
1058 memcpy(term
->baSourceID
, &buffer
[7], 1);
1061 usb_string(udev
, buffer
[8], term
->name
,
1064 sprintf(term
->name
, "Output %u", buffer
[3]);
1066 list_add_tail(&term
->list
, &dev
->entities
);
1069 case UVC_VC_SELECTOR_UNIT
:
1070 p
= buflen
>= 5 ? buffer
[4] : 0;
1072 if (buflen
< 5 || buflen
< 6 + p
) {
1073 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1074 "interface %d SELECTOR_UNIT error\n",
1075 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1079 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], p
+ 1, 0);
1083 memcpy(unit
->baSourceID
, &buffer
[5], p
);
1085 if (buffer
[5+p
] != 0)
1086 usb_string(udev
, buffer
[5+p
], unit
->name
,
1089 sprintf(unit
->name
, "Selector %u", buffer
[3]);
1091 list_add_tail(&unit
->list
, &dev
->entities
);
1094 case UVC_VC_PROCESSING_UNIT
:
1095 n
= buflen
>= 8 ? buffer
[7] : 0;
1096 p
= dev
->uvc_version
>= 0x0110 ? 10 : 9;
1098 if (buflen
< p
+ n
) {
1099 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1100 "interface %d PROCESSING_UNIT error\n",
1101 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1105 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], 2, n
);
1109 memcpy(unit
->baSourceID
, &buffer
[4], 1);
1110 unit
->processing
.wMaxMultiplier
=
1111 get_unaligned_le16(&buffer
[5]);
1112 unit
->processing
.bControlSize
= buffer
[7];
1113 unit
->processing
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1114 memcpy(unit
->processing
.bmControls
, &buffer
[8], n
);
1115 if (dev
->uvc_version
>= 0x0110)
1116 unit
->processing
.bmVideoStandards
= buffer
[9+n
];
1118 if (buffer
[8+n
] != 0)
1119 usb_string(udev
, buffer
[8+n
], unit
->name
,
1122 sprintf(unit
->name
, "Processing %u", buffer
[3]);
1124 list_add_tail(&unit
->list
, &dev
->entities
);
1127 case UVC_VC_EXTENSION_UNIT
:
1128 p
= buflen
>= 22 ? buffer
[21] : 0;
1129 n
= buflen
>= 24 + p
? buffer
[22+p
] : 0;
1131 if (buflen
< 24 + p
+ n
) {
1132 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1133 "interface %d EXTENSION_UNIT error\n",
1134 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1138 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], p
+ 1, n
);
1142 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
1143 unit
->extension
.bNumControls
= buffer
[20];
1144 memcpy(unit
->baSourceID
, &buffer
[22], p
);
1145 unit
->extension
.bControlSize
= buffer
[22+p
];
1146 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1147 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], n
);
1149 if (buffer
[23+p
+n
] != 0)
1150 usb_string(udev
, buffer
[23+p
+n
], unit
->name
,
1153 sprintf(unit
->name
, "Extension %u", buffer
[3]);
1155 list_add_tail(&unit
->list
, &dev
->entities
);
1159 uvc_trace(UVC_TRACE_DESCR
, "Found an unknown CS_INTERFACE "
1160 "descriptor (%u)\n", buffer
[2]);
1167 static int uvc_parse_control(struct uvc_device
*dev
)
1169 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
1170 unsigned char *buffer
= alts
->extra
;
1171 int buflen
= alts
->extralen
;
1174 /* Parse the default alternate setting only, as the UVC specification
1175 * defines a single alternate setting, the default alternate setting
1179 while (buflen
> 2) {
1180 if (uvc_parse_vendor_control(dev
, buffer
, buflen
) ||
1181 buffer
[1] != USB_DT_CS_INTERFACE
)
1182 goto next_descriptor
;
1184 if ((ret
= uvc_parse_standard_control(dev
, buffer
, buflen
)) < 0)
1188 buflen
-= buffer
[0];
1189 buffer
+= buffer
[0];
1192 /* Check if the optional status endpoint is present. Built-in iSight
1193 * webcams have an interrupt endpoint but spit proprietary data that
1194 * don't conform to the UVC status endpoint messages. Don't try to
1195 * handle the interrupt endpoint for those cameras.
1197 if (alts
->desc
.bNumEndpoints
== 1 &&
1198 !(dev
->quirks
& UVC_QUIRK_BUILTIN_ISIGHT
)) {
1199 struct usb_host_endpoint
*ep
= &alts
->endpoint
[0];
1200 struct usb_endpoint_descriptor
*desc
= &ep
->desc
;
1202 if (usb_endpoint_is_int_in(desc
) &&
1203 le16_to_cpu(desc
->wMaxPacketSize
) >= 8 &&
1204 desc
->bInterval
!= 0) {
1205 uvc_trace(UVC_TRACE_DESCR
, "Found a Status endpoint "
1206 "(addr %02x).\n", desc
->bEndpointAddress
);
1214 /* ------------------------------------------------------------------------
1219 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1220 * and containing the following units:
1222 * - one or more Output Terminals (USB Streaming or Display)
1223 * - zero or one Processing Unit
1224 * - zero, one or more single-input Selector Units
1225 * - zero or one multiple-input Selector Units, provided all inputs are
1226 * connected to input terminals
1227 * - zero, one or mode single-input Extension Units
1228 * - one or more Input Terminals (Camera, External or USB Streaming)
1230 * The terminal and units must match on of the following structures:
1232 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1233 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1234 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1236 * +---------+ +---------+ -> OTT_*(0)
1237 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1238 * +---------+ +---------+ -> OTT_*(n)
1240 * The Processing Unit and Extension Units can be in any order. Additional
1241 * Extension Units connected to the main chain as single-unit branches are
1242 * also supported. Single-input Selector Units are ignored.
1244 static int uvc_scan_chain_entity(struct uvc_video_chain
*chain
,
1245 struct uvc_entity
*entity
)
1247 switch (UVC_ENTITY_TYPE(entity
)) {
1248 case UVC_VC_EXTENSION_UNIT
:
1249 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1250 printk(" <- XU %d", entity
->id
);
1252 if (entity
->bNrInPins
!= 1) {
1253 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d has more "
1254 "than 1 input pin.\n", entity
->id
);
1260 case UVC_VC_PROCESSING_UNIT
:
1261 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1262 printk(" <- PU %d", entity
->id
);
1264 if (chain
->processing
!= NULL
) {
1265 uvc_trace(UVC_TRACE_DESCR
, "Found multiple "
1266 "Processing Units in chain.\n");
1270 chain
->processing
= entity
;
1273 case UVC_VC_SELECTOR_UNIT
:
1274 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1275 printk(" <- SU %d", entity
->id
);
1277 /* Single-input selector units are ignored. */
1278 if (entity
->bNrInPins
== 1)
1281 if (chain
->selector
!= NULL
) {
1282 uvc_trace(UVC_TRACE_DESCR
, "Found multiple Selector "
1283 "Units in chain.\n");
1287 chain
->selector
= entity
;
1290 case UVC_ITT_VENDOR_SPECIFIC
:
1291 case UVC_ITT_CAMERA
:
1292 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1293 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1294 printk(" <- IT %d\n", entity
->id
);
1298 case UVC_OTT_VENDOR_SPECIFIC
:
1299 case UVC_OTT_DISPLAY
:
1300 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1301 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1302 printk(" OT %d", entity
->id
);
1306 case UVC_TT_STREAMING
:
1307 if (UVC_ENTITY_IS_ITERM(entity
)) {
1308 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1309 printk(" <- IT %d\n", entity
->id
);
1311 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1312 printk(" OT %d", entity
->id
);
1318 uvc_trace(UVC_TRACE_DESCR
, "Unsupported entity type "
1319 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity
));
1323 list_add_tail(&entity
->chain
, &chain
->entities
);
1327 static int uvc_scan_chain_forward(struct uvc_video_chain
*chain
,
1328 struct uvc_entity
*entity
, struct uvc_entity
*prev
)
1330 struct uvc_entity
*forward
;
1338 forward
= uvc_entity_by_reference(chain
->dev
, entity
->id
,
1340 if (forward
== NULL
)
1342 if (forward
== prev
)
1345 switch (UVC_ENTITY_TYPE(forward
)) {
1346 case UVC_VC_EXTENSION_UNIT
:
1347 if (forward
->bNrInPins
!= 1) {
1348 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d "
1349 "has more than 1 input pin.\n",
1354 list_add_tail(&forward
->chain
, &chain
->entities
);
1355 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1359 printk(" XU %d", forward
->id
);
1364 case UVC_OTT_VENDOR_SPECIFIC
:
1365 case UVC_OTT_DISPLAY
:
1366 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1367 case UVC_TT_STREAMING
:
1368 if (UVC_ENTITY_IS_ITERM(forward
)) {
1369 uvc_trace(UVC_TRACE_DESCR
, "Unsupported input "
1370 "terminal %u.\n", forward
->id
);
1374 list_add_tail(&forward
->chain
, &chain
->entities
);
1375 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1379 printk(" OT %d", forward
->id
);
1391 static int uvc_scan_chain_backward(struct uvc_video_chain
*chain
,
1392 struct uvc_entity
**_entity
)
1394 struct uvc_entity
*entity
= *_entity
;
1395 struct uvc_entity
*term
;
1396 int id
= -EINVAL
, i
;
1398 switch (UVC_ENTITY_TYPE(entity
)) {
1399 case UVC_VC_EXTENSION_UNIT
:
1400 case UVC_VC_PROCESSING_UNIT
:
1401 id
= entity
->baSourceID
[0];
1404 case UVC_VC_SELECTOR_UNIT
:
1405 /* Single-input selector units are ignored. */
1406 if (entity
->bNrInPins
== 1) {
1407 id
= entity
->baSourceID
[0];
1411 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1414 chain
->selector
= entity
;
1415 for (i
= 0; i
< entity
->bNrInPins
; ++i
) {
1416 id
= entity
->baSourceID
[i
];
1417 term
= uvc_entity_by_id(chain
->dev
, id
);
1418 if (term
== NULL
|| !UVC_ENTITY_IS_ITERM(term
)) {
1419 uvc_trace(UVC_TRACE_DESCR
, "Selector unit %d "
1420 "input %d isn't connected to an "
1421 "input terminal\n", entity
->id
, i
);
1425 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1426 printk(" %d", term
->id
);
1428 list_add_tail(&term
->chain
, &chain
->entities
);
1429 uvc_scan_chain_forward(chain
, term
, entity
);
1432 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1438 case UVC_ITT_VENDOR_SPECIFIC
:
1439 case UVC_ITT_CAMERA
:
1440 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1441 case UVC_OTT_VENDOR_SPECIFIC
:
1442 case UVC_OTT_DISPLAY
:
1443 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1444 case UVC_TT_STREAMING
:
1445 id
= UVC_ENTITY_IS_OTERM(entity
) ? entity
->baSourceID
[0] : 0;
1454 entity
= uvc_entity_by_id(chain
->dev
, id
);
1455 if (entity
== NULL
) {
1456 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1457 "unknown entity %d.\n", id
);
1465 static int uvc_scan_chain(struct uvc_video_chain
*chain
,
1466 struct uvc_entity
*term
)
1468 struct uvc_entity
*entity
, *prev
;
1470 uvc_trace(UVC_TRACE_PROBE
, "Scanning UVC chain:");
1475 while (entity
!= NULL
) {
1476 /* Entity must not be part of an existing chain */
1477 if (entity
->chain
.next
|| entity
->chain
.prev
) {
1478 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1479 "entity %d already in chain.\n", entity
->id
);
1483 /* Process entity */
1484 if (uvc_scan_chain_entity(chain
, entity
) < 0)
1488 if (uvc_scan_chain_forward(chain
, entity
, prev
) < 0)
1493 if (uvc_scan_chain_backward(chain
, &entity
) < 0)
1500 static unsigned int uvc_print_terms(struct list_head
*terms
, u16 dir
,
1503 struct uvc_entity
*term
;
1504 unsigned int nterms
= 0;
1507 list_for_each_entry(term
, terms
, chain
) {
1508 if (!UVC_ENTITY_IS_TERM(term
) ||
1509 UVC_TERM_DIRECTION(term
) != dir
)
1513 p
+= sprintf(p
, ",");
1514 if (++nterms
>= 4) {
1515 p
+= sprintf(p
, "...");
1518 p
+= sprintf(p
, "%u", term
->id
);
1524 static const char *uvc_print_chain(struct uvc_video_chain
*chain
)
1526 static char buffer
[43];
1529 p
+= uvc_print_terms(&chain
->entities
, UVC_TERM_INPUT
, p
);
1530 p
+= sprintf(p
, " -> ");
1531 uvc_print_terms(&chain
->entities
, UVC_TERM_OUTPUT
, p
);
1537 * Scan the device for video chains and register video devices.
1539 * Chains are scanned starting at their output terminals and walked backwards.
1541 static int uvc_scan_device(struct uvc_device
*dev
)
1543 struct uvc_video_chain
*chain
;
1544 struct uvc_entity
*term
;
1546 list_for_each_entry(term
, &dev
->entities
, list
) {
1547 if (!UVC_ENTITY_IS_OTERM(term
))
1550 /* If the terminal is already included in a chain, skip it.
1551 * This can happen for chains that have multiple output
1552 * terminals, where all output terminals beside the first one
1553 * will be inserted in the chain in forward scans.
1555 if (term
->chain
.next
|| term
->chain
.prev
)
1558 chain
= kzalloc(sizeof(*chain
), GFP_KERNEL
);
1562 INIT_LIST_HEAD(&chain
->entities
);
1563 mutex_init(&chain
->ctrl_mutex
);
1565 v4l2_prio_init(&chain
->prio
);
1567 term
->flags
|= UVC_ENTITY_FLAG_DEFAULT
;
1569 if (uvc_scan_chain(chain
, term
) < 0) {
1574 uvc_trace(UVC_TRACE_PROBE
, "Found a valid video chain (%s).\n",
1575 uvc_print_chain(chain
));
1577 list_add_tail(&chain
->list
, &dev
->chains
);
1580 if (list_empty(&dev
->chains
)) {
1581 uvc_printk(KERN_INFO
, "No valid video chain found.\n");
1588 /* ------------------------------------------------------------------------
1589 * Video device registration and unregistration
1593 * Delete the UVC device.
1595 * Called by the kernel when the last reference to the uvc_device structure
1598 * As this function is called after or during disconnect(), all URBs have
1599 * already been canceled by the USB core. There is no need to kill the
1600 * interrupt URB manually.
1602 static void uvc_delete(struct uvc_device
*dev
)
1604 struct list_head
*p
, *n
;
1606 usb_put_intf(dev
->intf
);
1607 usb_put_dev(dev
->udev
);
1609 uvc_status_cleanup(dev
);
1610 uvc_ctrl_cleanup_device(dev
);
1613 v4l2_device_unregister(&dev
->vdev
);
1614 #ifdef CONFIG_MEDIA_CONTROLLER
1615 if (media_devnode_is_registered(&dev
->mdev
.devnode
))
1616 media_device_unregister(&dev
->mdev
);
1619 list_for_each_safe(p
, n
, &dev
->chains
) {
1620 struct uvc_video_chain
*chain
;
1621 chain
= list_entry(p
, struct uvc_video_chain
, list
);
1625 list_for_each_safe(p
, n
, &dev
->entities
) {
1626 struct uvc_entity
*entity
;
1627 entity
= list_entry(p
, struct uvc_entity
, list
);
1628 #ifdef CONFIG_MEDIA_CONTROLLER
1629 uvc_mc_cleanup_entity(entity
);
1632 video_device_release(entity
->vdev
);
1633 entity
->vdev
= NULL
;
1638 list_for_each_safe(p
, n
, &dev
->streams
) {
1639 struct uvc_streaming
*streaming
;
1640 streaming
= list_entry(p
, struct uvc_streaming
, list
);
1641 usb_driver_release_interface(&uvc_driver
.driver
,
1643 usb_put_intf(streaming
->intf
);
1644 kfree(streaming
->format
);
1645 kfree(streaming
->header
.bmaControls
);
1652 static void uvc_release(struct video_device
*vdev
)
1654 struct uvc_streaming
*stream
= video_get_drvdata(vdev
);
1655 struct uvc_device
*dev
= stream
->dev
;
1657 /* Decrement the registered streams count and delete the device when it
1660 if (atomic_dec_and_test(&dev
->nstreams
))
1665 * Unregister the video devices.
1667 static void uvc_unregister_video(struct uvc_device
*dev
)
1669 struct uvc_streaming
*stream
;
1671 /* Unregistering all video devices might result in uvc_delete() being
1672 * called from inside the loop if there's no open file handle. To avoid
1673 * that, increment the stream count before iterating over the streams
1674 * and decrement it when done.
1676 atomic_inc(&dev
->nstreams
);
1678 list_for_each_entry(stream
, &dev
->streams
, list
) {
1679 if (stream
->vdev
== NULL
)
1682 video_unregister_device(stream
->vdev
);
1683 stream
->vdev
= NULL
;
1685 uvc_debugfs_cleanup_stream(stream
);
1688 /* Decrement the stream count and call uvc_delete explicitly if there
1689 * are no stream left.
1691 if (atomic_dec_and_test(&dev
->nstreams
))
1695 static int uvc_register_video(struct uvc_device
*dev
,
1696 struct uvc_streaming
*stream
)
1698 struct video_device
*vdev
;
1701 /* Initialize the streaming interface with default streaming
1704 ret
= uvc_video_init(stream
);
1706 uvc_printk(KERN_ERR
, "Failed to initialize the device "
1711 uvc_debugfs_init_stream(stream
);
1713 /* Register the device with V4L. */
1714 vdev
= video_device_alloc();
1716 uvc_printk(KERN_ERR
, "Failed to allocate video device (%d).\n",
1721 /* We already hold a reference to dev->udev. The video device will be
1722 * unregistered before the reference is released, so we don't need to
1725 vdev
->v4l2_dev
= &dev
->vdev
;
1726 vdev
->fops
= &uvc_fops
;
1727 vdev
->release
= uvc_release
;
1728 vdev
->prio
= &stream
->chain
->prio
;
1729 set_bit(V4L2_FL_USE_FH_PRIO
, &vdev
->flags
);
1730 if (stream
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1731 vdev
->vfl_dir
= VFL_DIR_TX
;
1732 strlcpy(vdev
->name
, dev
->name
, sizeof vdev
->name
);
1734 /* Set the driver data before calling video_register_device, otherwise
1735 * uvc_v4l2_open might race us.
1737 stream
->vdev
= vdev
;
1738 video_set_drvdata(vdev
, stream
);
1740 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1742 uvc_printk(KERN_ERR
, "Failed to register video device (%d).\n",
1744 stream
->vdev
= NULL
;
1745 video_device_release(vdev
);
1749 if (stream
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1750 stream
->chain
->caps
|= V4L2_CAP_VIDEO_CAPTURE
;
1752 stream
->chain
->caps
|= V4L2_CAP_VIDEO_OUTPUT
;
1754 atomic_inc(&dev
->nstreams
);
1759 * Register all video devices in all chains.
1761 static int uvc_register_terms(struct uvc_device
*dev
,
1762 struct uvc_video_chain
*chain
)
1764 struct uvc_streaming
*stream
;
1765 struct uvc_entity
*term
;
1768 list_for_each_entry(term
, &chain
->entities
, chain
) {
1769 if (UVC_ENTITY_TYPE(term
) != UVC_TT_STREAMING
)
1772 stream
= uvc_stream_by_id(dev
, term
->id
);
1773 if (stream
== NULL
) {
1774 uvc_printk(KERN_INFO
, "No streaming interface found "
1775 "for terminal %u.", term
->id
);
1779 stream
->chain
= chain
;
1780 ret
= uvc_register_video(dev
, stream
);
1784 term
->vdev
= stream
->vdev
;
1790 static int uvc_register_chains(struct uvc_device
*dev
)
1792 struct uvc_video_chain
*chain
;
1795 list_for_each_entry(chain
, &dev
->chains
, list
) {
1796 ret
= uvc_register_terms(dev
, chain
);
1800 #ifdef CONFIG_MEDIA_CONTROLLER
1801 ret
= uvc_mc_register_entities(chain
);
1803 uvc_printk(KERN_INFO
, "Failed to register entites "
1812 /* ------------------------------------------------------------------------
1813 * USB probe, disconnect, suspend and resume
1816 static int uvc_probe(struct usb_interface
*intf
,
1817 const struct usb_device_id
*id
)
1819 struct usb_device
*udev
= interface_to_usbdev(intf
);
1820 struct uvc_device
*dev
;
1823 if (id
->idVendor
&& id
->idProduct
)
1824 uvc_trace(UVC_TRACE_PROBE
, "Probing known UVC device %s "
1825 "(%04x:%04x)\n", udev
->devpath
, id
->idVendor
,
1828 uvc_trace(UVC_TRACE_PROBE
, "Probing generic UVC device %s\n",
1831 /* Allocate memory for the device and initialize it. */
1832 if ((dev
= kzalloc(sizeof *dev
, GFP_KERNEL
)) == NULL
)
1835 INIT_LIST_HEAD(&dev
->entities
);
1836 INIT_LIST_HEAD(&dev
->chains
);
1837 INIT_LIST_HEAD(&dev
->streams
);
1838 atomic_set(&dev
->nstreams
, 0);
1839 atomic_set(&dev
->nmappings
, 0);
1840 mutex_init(&dev
->lock
);
1842 dev
->udev
= usb_get_dev(udev
);
1843 dev
->intf
= usb_get_intf(intf
);
1844 dev
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
1845 dev
->quirks
= (uvc_quirks_param
== -1)
1846 ? id
->driver_info
: uvc_quirks_param
;
1848 if (udev
->product
!= NULL
)
1849 strlcpy(dev
->name
, udev
->product
, sizeof dev
->name
);
1851 snprintf(dev
->name
, sizeof dev
->name
,
1852 "UVC Camera (%04x:%04x)",
1853 le16_to_cpu(udev
->descriptor
.idVendor
),
1854 le16_to_cpu(udev
->descriptor
.idProduct
));
1856 /* Parse the Video Class control descriptor. */
1857 if (uvc_parse_control(dev
) < 0) {
1858 uvc_trace(UVC_TRACE_PROBE
, "Unable to parse UVC "
1863 uvc_printk(KERN_INFO
, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1864 dev
->uvc_version
>> 8, dev
->uvc_version
& 0xff,
1865 udev
->product
? udev
->product
: "<unnamed>",
1866 le16_to_cpu(udev
->descriptor
.idVendor
),
1867 le16_to_cpu(udev
->descriptor
.idProduct
));
1869 if (dev
->quirks
!= id
->driver_info
) {
1870 uvc_printk(KERN_INFO
, "Forcing device quirks to 0x%x by module "
1871 "parameter for testing purpose.\n", dev
->quirks
);
1872 uvc_printk(KERN_INFO
, "Please report required quirks to the "
1873 "linux-uvc-devel mailing list.\n");
1876 /* Register the media and V4L2 devices. */
1877 #ifdef CONFIG_MEDIA_CONTROLLER
1878 dev
->mdev
.dev
= &intf
->dev
;
1879 strlcpy(dev
->mdev
.model
, dev
->name
, sizeof(dev
->mdev
.model
));
1881 strlcpy(dev
->mdev
.serial
, udev
->serial
,
1882 sizeof(dev
->mdev
.serial
));
1883 strcpy(dev
->mdev
.bus_info
, udev
->devpath
);
1884 dev
->mdev
.hw_revision
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
1885 dev
->mdev
.driver_version
= LINUX_VERSION_CODE
;
1886 if (media_device_register(&dev
->mdev
) < 0)
1889 dev
->vdev
.mdev
= &dev
->mdev
;
1891 if (v4l2_device_register(&intf
->dev
, &dev
->vdev
) < 0)
1894 /* Initialize controls. */
1895 if (uvc_ctrl_init_device(dev
) < 0)
1898 /* Scan the device for video chains. */
1899 if (uvc_scan_device(dev
) < 0)
1902 /* Register video device nodes. */
1903 if (uvc_register_chains(dev
) < 0)
1906 /* Save our data pointer in the interface data. */
1907 usb_set_intfdata(intf
, dev
);
1909 /* Initialize the interrupt URB. */
1910 if ((ret
= uvc_status_init(dev
)) < 0) {
1911 uvc_printk(KERN_INFO
, "Unable to initialize the status "
1912 "endpoint (%d), status interrupt will not be "
1913 "supported.\n", ret
);
1916 uvc_trace(UVC_TRACE_PROBE
, "UVC device initialized.\n");
1917 usb_enable_autosuspend(udev
);
1921 uvc_unregister_video(dev
);
1925 static void uvc_disconnect(struct usb_interface
*intf
)
1927 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1929 /* Set the USB interface data to NULL. This can be done outside the
1930 * lock, as there's no other reader.
1932 usb_set_intfdata(intf
, NULL
);
1934 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1935 UVC_SC_VIDEOSTREAMING
)
1938 dev
->state
|= UVC_DEV_DISCONNECTED
;
1940 uvc_unregister_video(dev
);
1943 static int uvc_suspend(struct usb_interface
*intf
, pm_message_t message
)
1945 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1946 struct uvc_streaming
*stream
;
1948 uvc_trace(UVC_TRACE_SUSPEND
, "Suspending interface %u\n",
1949 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1951 /* Controls are cached on the fly so they don't need to be saved. */
1952 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1953 UVC_SC_VIDEOCONTROL
) {
1954 mutex_lock(&dev
->lock
);
1956 uvc_status_stop(dev
);
1957 mutex_unlock(&dev
->lock
);
1961 list_for_each_entry(stream
, &dev
->streams
, list
) {
1962 if (stream
->intf
== intf
)
1963 return uvc_video_suspend(stream
);
1966 uvc_trace(UVC_TRACE_SUSPEND
, "Suspend: video streaming USB interface "
1971 static int __uvc_resume(struct usb_interface
*intf
, int reset
)
1973 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1974 struct uvc_streaming
*stream
;
1976 uvc_trace(UVC_TRACE_SUSPEND
, "Resuming interface %u\n",
1977 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1979 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1980 UVC_SC_VIDEOCONTROL
) {
1984 ret
= uvc_ctrl_resume_device(dev
);
1989 mutex_lock(&dev
->lock
);
1991 ret
= uvc_status_start(dev
, GFP_NOIO
);
1992 mutex_unlock(&dev
->lock
);
1997 list_for_each_entry(stream
, &dev
->streams
, list
) {
1998 if (stream
->intf
== intf
)
1999 return uvc_video_resume(stream
, reset
);
2002 uvc_trace(UVC_TRACE_SUSPEND
, "Resume: video streaming USB interface "
2007 static int uvc_resume(struct usb_interface
*intf
)
2009 return __uvc_resume(intf
, 0);
2012 static int uvc_reset_resume(struct usb_interface
*intf
)
2014 return __uvc_resume(intf
, 1);
2017 /* ------------------------------------------------------------------------
2021 static int uvc_clock_param_get(char *buffer
, struct kernel_param
*kp
)
2023 if (uvc_clock_param
== CLOCK_MONOTONIC
)
2024 return sprintf(buffer
, "CLOCK_MONOTONIC");
2026 return sprintf(buffer
, "CLOCK_REALTIME");
2029 static int uvc_clock_param_set(const char *val
, struct kernel_param
*kp
)
2031 if (strncasecmp(val
, "clock_", strlen("clock_")) == 0)
2032 val
+= strlen("clock_");
2034 if (strcasecmp(val
, "monotonic") == 0)
2035 uvc_clock_param
= CLOCK_MONOTONIC
;
2036 else if (strcasecmp(val
, "realtime") == 0)
2037 uvc_clock_param
= CLOCK_REALTIME
;
2044 module_param_call(clock
, uvc_clock_param_set
, uvc_clock_param_get
,
2045 &uvc_clock_param
, S_IRUGO
|S_IWUSR
);
2046 MODULE_PARM_DESC(clock
, "Video buffers timestamp clock");
2047 module_param_named(nodrop
, uvc_no_drop_param
, uint
, S_IRUGO
|S_IWUSR
);
2048 MODULE_PARM_DESC(nodrop
, "Don't drop incomplete frames");
2049 module_param_named(quirks
, uvc_quirks_param
, uint
, S_IRUGO
|S_IWUSR
);
2050 MODULE_PARM_DESC(quirks
, "Forced device quirks");
2051 module_param_named(trace
, uvc_trace_param
, uint
, S_IRUGO
|S_IWUSR
);
2052 MODULE_PARM_DESC(trace
, "Trace level bitmask");
2053 module_param_named(timeout
, uvc_timeout_param
, uint
, S_IRUGO
|S_IWUSR
);
2054 MODULE_PARM_DESC(timeout
, "Streaming control requests timeout");
2056 /* ------------------------------------------------------------------------
2057 * Driver initialization and cleanup
2061 * The Logitech cameras listed below have their interface class set to
2062 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2063 * though they are compliant.
2065 static struct usb_device_id uvc_ids
[] = {
2066 /* LogiLink Wireless Webcam */
2067 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2068 | USB_DEVICE_ID_MATCH_INT_INFO
,
2070 .idProduct
= 0xa91a,
2071 .bInterfaceClass
= USB_CLASS_VIDEO
,
2072 .bInterfaceSubClass
= 1,
2073 .bInterfaceProtocol
= 0,
2074 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2075 /* Genius eFace 2025 */
2076 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2077 | USB_DEVICE_ID_MATCH_INT_INFO
,
2079 .idProduct
= 0x706e,
2080 .bInterfaceClass
= USB_CLASS_VIDEO
,
2081 .bInterfaceSubClass
= 1,
2082 .bInterfaceProtocol
= 0,
2083 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2084 /* Microsoft Lifecam NX-6000 */
2085 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2086 | USB_DEVICE_ID_MATCH_INT_INFO
,
2088 .idProduct
= 0x00f8,
2089 .bInterfaceClass
= USB_CLASS_VIDEO
,
2090 .bInterfaceSubClass
= 1,
2091 .bInterfaceProtocol
= 0,
2092 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2093 /* Microsoft Lifecam VX-7000 */
2094 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2095 | USB_DEVICE_ID_MATCH_INT_INFO
,
2097 .idProduct
= 0x0723,
2098 .bInterfaceClass
= USB_CLASS_VIDEO
,
2099 .bInterfaceSubClass
= 1,
2100 .bInterfaceProtocol
= 0,
2101 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2102 /* Logitech Quickcam Fusion */
2103 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2104 | USB_DEVICE_ID_MATCH_INT_INFO
,
2106 .idProduct
= 0x08c1,
2107 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2108 .bInterfaceSubClass
= 1,
2109 .bInterfaceProtocol
= 0 },
2110 /* Logitech Quickcam Orbit MP */
2111 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2112 | USB_DEVICE_ID_MATCH_INT_INFO
,
2114 .idProduct
= 0x08c2,
2115 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2116 .bInterfaceSubClass
= 1,
2117 .bInterfaceProtocol
= 0 },
2118 /* Logitech Quickcam Pro for Notebook */
2119 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2120 | USB_DEVICE_ID_MATCH_INT_INFO
,
2122 .idProduct
= 0x08c3,
2123 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2124 .bInterfaceSubClass
= 1,
2125 .bInterfaceProtocol
= 0 },
2126 /* Logitech Quickcam Pro 5000 */
2127 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2128 | USB_DEVICE_ID_MATCH_INT_INFO
,
2130 .idProduct
= 0x08c5,
2131 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2132 .bInterfaceSubClass
= 1,
2133 .bInterfaceProtocol
= 0 },
2134 /* Logitech Quickcam OEM Dell Notebook */
2135 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2136 | USB_DEVICE_ID_MATCH_INT_INFO
,
2138 .idProduct
= 0x08c6,
2139 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2140 .bInterfaceSubClass
= 1,
2141 .bInterfaceProtocol
= 0 },
2142 /* Logitech Quickcam OEM Cisco VT Camera II */
2143 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2144 | USB_DEVICE_ID_MATCH_INT_INFO
,
2146 .idProduct
= 0x08c7,
2147 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2148 .bInterfaceSubClass
= 1,
2149 .bInterfaceProtocol
= 0 },
2150 /* Chicony CNF7129 (Asus EEE 100HE) */
2151 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2152 | USB_DEVICE_ID_MATCH_INT_INFO
,
2154 .idProduct
= 0xb071,
2155 .bInterfaceClass
= USB_CLASS_VIDEO
,
2156 .bInterfaceSubClass
= 1,
2157 .bInterfaceProtocol
= 0,
2158 .driver_info
= UVC_QUIRK_RESTRICT_FRAME_RATE
},
2159 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2160 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2161 | USB_DEVICE_ID_MATCH_INT_INFO
,
2163 .idProduct
= 0x3820,
2164 .bInterfaceClass
= USB_CLASS_VIDEO
,
2165 .bInterfaceSubClass
= 1,
2166 .bInterfaceProtocol
= 0,
2167 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2168 /* Dell XPS m1530 */
2169 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2170 | USB_DEVICE_ID_MATCH_INT_INFO
,
2172 .idProduct
= 0x2640,
2173 .bInterfaceClass
= USB_CLASS_VIDEO
,
2174 .bInterfaceSubClass
= 1,
2175 .bInterfaceProtocol
= 0,
2176 .driver_info
= UVC_QUIRK_PROBE_DEF
},
2177 /* Dell Alienware X51 */
2178 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2179 | USB_DEVICE_ID_MATCH_INT_INFO
,
2181 .idProduct
= 0x2643,
2182 .bInterfaceClass
= USB_CLASS_VIDEO
,
2183 .bInterfaceSubClass
= 1,
2184 .bInterfaceProtocol
= 0,
2185 .driver_info
= UVC_QUIRK_PROBE_DEF
},
2186 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2187 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2188 | USB_DEVICE_ID_MATCH_INT_INFO
,
2190 .idProduct
= 0x264a,
2191 .bInterfaceClass
= USB_CLASS_VIDEO
,
2192 .bInterfaceSubClass
= 1,
2193 .bInterfaceProtocol
= 0,
2194 .driver_info
= UVC_QUIRK_PROBE_DEF
},
2195 /* Apple Built-In iSight */
2196 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2197 | USB_DEVICE_ID_MATCH_INT_INFO
,
2199 .idProduct
= 0x8501,
2200 .bInterfaceClass
= USB_CLASS_VIDEO
,
2201 .bInterfaceSubClass
= 1,
2202 .bInterfaceProtocol
= 0,
2203 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2204 | UVC_QUIRK_BUILTIN_ISIGHT
},
2205 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2206 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2207 | USB_DEVICE_ID_MATCH_INT_INFO
,
2209 .idProduct
= 0x0403,
2210 .bInterfaceClass
= USB_CLASS_VIDEO
,
2211 .bInterfaceSubClass
= 1,
2212 .bInterfaceProtocol
= 0,
2213 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2214 /* Genesys Logic USB 2.0 PC Camera */
2215 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2216 | USB_DEVICE_ID_MATCH_INT_INFO
,
2218 .idProduct
= 0x0505,
2219 .bInterfaceClass
= USB_CLASS_VIDEO
,
2220 .bInterfaceSubClass
= 1,
2221 .bInterfaceProtocol
= 0,
2222 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2223 /* Hercules Classic Silver */
2224 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2225 | USB_DEVICE_ID_MATCH_INT_INFO
,
2227 .idProduct
= 0x300c,
2228 .bInterfaceClass
= USB_CLASS_VIDEO
,
2229 .bInterfaceSubClass
= 1,
2230 .bInterfaceProtocol
= 0,
2231 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2233 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2234 | USB_DEVICE_ID_MATCH_INT_INFO
,
2236 .idProduct
= 0x332d,
2237 .bInterfaceClass
= USB_CLASS_VIDEO
,
2238 .bInterfaceSubClass
= 1,
2239 .bInterfaceProtocol
= 0,
2240 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2241 /* ViMicro - Minoru3D */
2242 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2243 | USB_DEVICE_ID_MATCH_INT_INFO
,
2245 .idProduct
= 0x3410,
2246 .bInterfaceClass
= USB_CLASS_VIDEO
,
2247 .bInterfaceSubClass
= 1,
2248 .bInterfaceProtocol
= 0,
2249 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2250 /* ViMicro Venus - Minoru3D */
2251 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2252 | USB_DEVICE_ID_MATCH_INT_INFO
,
2254 .idProduct
= 0x3420,
2255 .bInterfaceClass
= USB_CLASS_VIDEO
,
2256 .bInterfaceSubClass
= 1,
2257 .bInterfaceProtocol
= 0,
2258 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2259 /* Ophir Optronics - SPCAM 620U */
2260 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2261 | USB_DEVICE_ID_MATCH_INT_INFO
,
2263 .idProduct
= 0x0555,
2264 .bInterfaceClass
= USB_CLASS_VIDEO
,
2265 .bInterfaceSubClass
= 1,
2266 .bInterfaceProtocol
= 0,
2267 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2269 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2270 | USB_DEVICE_ID_MATCH_INT_INFO
,
2272 .idProduct
= 0x0004,
2273 .bInterfaceClass
= USB_CLASS_VIDEO
,
2274 .bInterfaceSubClass
= 1,
2275 .bInterfaceProtocol
= 0,
2276 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2277 | UVC_QUIRK_PROBE_DEF
},
2278 /* IMC Networks (Medion Akoya) */
2279 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2280 | USB_DEVICE_ID_MATCH_INT_INFO
,
2282 .idProduct
= 0x5103,
2283 .bInterfaceClass
= USB_CLASS_VIDEO
,
2284 .bInterfaceSubClass
= 1,
2285 .bInterfaceProtocol
= 0,
2286 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2287 /* JMicron USB2.0 XGA WebCam */
2288 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2289 | USB_DEVICE_ID_MATCH_INT_INFO
,
2291 .idProduct
= 0x0310,
2292 .bInterfaceClass
= USB_CLASS_VIDEO
,
2293 .bInterfaceSubClass
= 1,
2294 .bInterfaceProtocol
= 0,
2295 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2296 /* Syntek (HP Spartan) */
2297 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2298 | USB_DEVICE_ID_MATCH_INT_INFO
,
2300 .idProduct
= 0x5212,
2301 .bInterfaceClass
= USB_CLASS_VIDEO
,
2302 .bInterfaceSubClass
= 1,
2303 .bInterfaceProtocol
= 0,
2304 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2305 /* Syntek (Samsung Q310) */
2306 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2307 | USB_DEVICE_ID_MATCH_INT_INFO
,
2309 .idProduct
= 0x5931,
2310 .bInterfaceClass
= USB_CLASS_VIDEO
,
2311 .bInterfaceSubClass
= 1,
2312 .bInterfaceProtocol
= 0,
2313 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2314 /* Syntek (Packard Bell EasyNote MX52 */
2315 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2316 | USB_DEVICE_ID_MATCH_INT_INFO
,
2318 .idProduct
= 0x8a12,
2319 .bInterfaceClass
= USB_CLASS_VIDEO
,
2320 .bInterfaceSubClass
= 1,
2321 .bInterfaceProtocol
= 0,
2322 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2323 /* Syntek (Asus F9SG) */
2324 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2325 | USB_DEVICE_ID_MATCH_INT_INFO
,
2327 .idProduct
= 0x8a31,
2328 .bInterfaceClass
= USB_CLASS_VIDEO
,
2329 .bInterfaceSubClass
= 1,
2330 .bInterfaceProtocol
= 0,
2331 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2332 /* Syntek (Asus U3S) */
2333 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2334 | USB_DEVICE_ID_MATCH_INT_INFO
,
2336 .idProduct
= 0x8a33,
2337 .bInterfaceClass
= USB_CLASS_VIDEO
,
2338 .bInterfaceSubClass
= 1,
2339 .bInterfaceProtocol
= 0,
2340 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2341 /* Syntek (JAOtech Smart Terminal) */
2342 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2343 | USB_DEVICE_ID_MATCH_INT_INFO
,
2345 .idProduct
= 0x8a34,
2346 .bInterfaceClass
= USB_CLASS_VIDEO
,
2347 .bInterfaceSubClass
= 1,
2348 .bInterfaceProtocol
= 0,
2349 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2351 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2352 | USB_DEVICE_ID_MATCH_INT_INFO
,
2354 .idProduct
= 0x0202,
2355 .bInterfaceClass
= USB_CLASS_VIDEO
,
2356 .bInterfaceSubClass
= 1,
2357 .bInterfaceProtocol
= 0,
2358 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2359 /* Lenovo Thinkpad SL400/SL500 */
2360 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2361 | USB_DEVICE_ID_MATCH_INT_INFO
,
2363 .idProduct
= 0x480b,
2364 .bInterfaceClass
= USB_CLASS_VIDEO
,
2365 .bInterfaceSubClass
= 1,
2366 .bInterfaceProtocol
= 0,
2367 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2368 /* Aveo Technology USB 2.0 Camera */
2369 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2370 | USB_DEVICE_ID_MATCH_INT_INFO
,
2372 .idProduct
= 0x0306,
2373 .bInterfaceClass
= USB_CLASS_VIDEO
,
2374 .bInterfaceSubClass
= 1,
2375 .bInterfaceProtocol
= 0,
2376 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2377 | UVC_QUIRK_PROBE_EXTRAFIELDS
},
2378 /* Ecamm Pico iMage */
2379 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2380 | USB_DEVICE_ID_MATCH_INT_INFO
,
2382 .idProduct
= 0xcafe,
2383 .bInterfaceClass
= USB_CLASS_VIDEO
,
2384 .bInterfaceSubClass
= 1,
2385 .bInterfaceProtocol
= 0,
2386 .driver_info
= UVC_QUIRK_PROBE_EXTRAFIELDS
},
2387 /* Manta MM-353 Plako */
2388 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2389 | USB_DEVICE_ID_MATCH_INT_INFO
,
2391 .idProduct
= 0x3188,
2392 .bInterfaceClass
= USB_CLASS_VIDEO
,
2393 .bInterfaceSubClass
= 1,
2394 .bInterfaceProtocol
= 0,
2395 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2396 /* FSC WebCam V30S */
2397 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2398 | USB_DEVICE_ID_MATCH_INT_INFO
,
2400 .idProduct
= 0x3288,
2401 .bInterfaceClass
= USB_CLASS_VIDEO
,
2402 .bInterfaceSubClass
= 1,
2403 .bInterfaceProtocol
= 0,
2404 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2405 /* Arkmicro unbranded */
2406 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2407 | USB_DEVICE_ID_MATCH_INT_INFO
,
2409 .idProduct
= 0x3290,
2410 .bInterfaceClass
= USB_CLASS_VIDEO
,
2411 .bInterfaceSubClass
= 1,
2412 .bInterfaceProtocol
= 0,
2413 .driver_info
= UVC_QUIRK_PROBE_DEF
},
2414 /* The Imaging Source USB CCD cameras */
2415 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2416 | USB_DEVICE_ID_MATCH_INT_INFO
,
2418 .idProduct
= 0x8102,
2419 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2420 .bInterfaceSubClass
= 1,
2421 .bInterfaceProtocol
= 0 },
2422 /* Bodelin ProScopeHR */
2423 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2424 | USB_DEVICE_ID_MATCH_DEV_HI
2425 | USB_DEVICE_ID_MATCH_INT_INFO
,
2427 .idProduct
= 0x1000,
2428 .bcdDevice_hi
= 0x0126,
2429 .bInterfaceClass
= USB_CLASS_VIDEO
,
2430 .bInterfaceSubClass
= 1,
2431 .bInterfaceProtocol
= 0,
2432 .driver_info
= UVC_QUIRK_STATUS_INTERVAL
},
2433 /* MSI StarCam 370i */
2434 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2435 | USB_DEVICE_ID_MATCH_INT_INFO
,
2437 .idProduct
= 0x2951,
2438 .bInterfaceClass
= USB_CLASS_VIDEO
,
2439 .bInterfaceSubClass
= 1,
2440 .bInterfaceProtocol
= 0,
2441 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2442 /* SiGma Micro USB Web Camera */
2443 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2444 | USB_DEVICE_ID_MATCH_INT_INFO
,
2446 .idProduct
= 0x3000,
2447 .bInterfaceClass
= USB_CLASS_VIDEO
,
2448 .bInterfaceSubClass
= 1,
2449 .bInterfaceProtocol
= 0,
2450 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2451 | UVC_QUIRK_IGNORE_SELECTOR_UNIT
},
2452 /* Generic USB Video Class */
2453 { USB_INTERFACE_INFO(USB_CLASS_VIDEO
, 1, 0) },
2457 MODULE_DEVICE_TABLE(usb
, uvc_ids
);
2459 struct uvc_driver uvc_driver
= {
2463 .disconnect
= uvc_disconnect
,
2464 .suspend
= uvc_suspend
,
2465 .resume
= uvc_resume
,
2466 .reset_resume
= uvc_reset_resume
,
2467 .id_table
= uvc_ids
,
2468 .supports_autosuspend
= 1,
2472 static int __init
uvc_init(void)
2478 ret
= usb_register(&uvc_driver
.driver
);
2480 uvc_debugfs_cleanup();
2484 printk(KERN_INFO DRIVER_DESC
" (" DRIVER_VERSION
")\n");
2488 static void __exit
uvc_cleanup(void)
2490 usb_deregister(&uvc_driver
.driver
);
2491 uvc_debugfs_cleanup();
2494 module_init(uvc_init
);
2495 module_exit(uvc_cleanup
);
2497 MODULE_AUTHOR(DRIVER_AUTHOR
);
2498 MODULE_DESCRIPTION(DRIVER_DESC
);
2499 MODULE_LICENSE("GPL");
2500 MODULE_VERSION(DRIVER_VERSION
);