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.
15 * This driver aims to support video input and ouput devices compliant with the
16 * 'USB Video Class' specification.
18 * The driver doesn't support the deprecated v4l1 interface. It implements the
19 * mmap capture method only, and doesn't do any image format conversion in
20 * software. If your user-space application doesn't support YUYV or MJPEG, fix
21 * it :-). Please note that the MJPEG data have been stripped from their
22 * Huffman tables (DHT marker), you will need to add it back if your JPEG
23 * codec can't handle MJPEG data.
26 #include <linux/kernel.h>
27 #include <linux/list.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/usb.h>
31 #include <linux/videodev2.h>
32 #include <linux/vmalloc.h>
33 #include <linux/wait.h>
34 #include <linux/version.h>
35 #include <asm/atomic.h>
36 #include <asm/unaligned.h>
38 #include <media/v4l2-common.h>
42 #define DRIVER_AUTHOR "Laurent Pinchart " \
43 "<laurent.pinchart@ideasonboard.com>"
44 #define DRIVER_DESC "USB Video Class driver"
46 unsigned int uvc_clock_param
= CLOCK_MONOTONIC
;
47 unsigned int uvc_no_drop_param
;
48 static unsigned int uvc_quirks_param
= -1;
49 unsigned int uvc_trace_param
;
50 unsigned int uvc_timeout_param
= UVC_CTRL_STREAMING_TIMEOUT
;
52 /* ------------------------------------------------------------------------
56 static struct uvc_format_desc uvc_fmts
[] = {
58 .name
= "YUV 4:2:2 (YUYV)",
59 .guid
= UVC_GUID_FORMAT_YUY2
,
60 .fcc
= V4L2_PIX_FMT_YUYV
,
63 .name
= "YUV 4:2:2 (YUYV)",
64 .guid
= UVC_GUID_FORMAT_YUY2_ISIGHT
,
65 .fcc
= V4L2_PIX_FMT_YUYV
,
68 .name
= "YUV 4:2:0 (NV12)",
69 .guid
= UVC_GUID_FORMAT_NV12
,
70 .fcc
= V4L2_PIX_FMT_NV12
,
74 .guid
= UVC_GUID_FORMAT_MJPEG
,
75 .fcc
= V4L2_PIX_FMT_MJPEG
,
78 .name
= "YVU 4:2:0 (YV12)",
79 .guid
= UVC_GUID_FORMAT_YV12
,
80 .fcc
= V4L2_PIX_FMT_YVU420
,
83 .name
= "YUV 4:2:0 (I420)",
84 .guid
= UVC_GUID_FORMAT_I420
,
85 .fcc
= V4L2_PIX_FMT_YUV420
,
88 .name
= "YUV 4:2:0 (M420)",
89 .guid
= UVC_GUID_FORMAT_M420
,
90 .fcc
= V4L2_PIX_FMT_M420
,
93 .name
= "YUV 4:2:2 (UYVY)",
94 .guid
= UVC_GUID_FORMAT_UYVY
,
95 .fcc
= V4L2_PIX_FMT_UYVY
,
98 .name
= "Greyscale (8-bit)",
99 .guid
= UVC_GUID_FORMAT_Y800
,
100 .fcc
= V4L2_PIX_FMT_GREY
,
103 .name
= "Greyscale (16-bit)",
104 .guid
= UVC_GUID_FORMAT_Y16
,
105 .fcc
= V4L2_PIX_FMT_Y16
,
109 .guid
= UVC_GUID_FORMAT_BY8
,
110 .fcc
= V4L2_PIX_FMT_SBGGR8
,
114 .guid
= UVC_GUID_FORMAT_RGBP
,
115 .fcc
= V4L2_PIX_FMT_RGB565
,
119 .guid
= UVC_GUID_FORMAT_H264
,
120 .fcc
= V4L2_PIX_FMT_H264
,
124 /* ------------------------------------------------------------------------
128 struct usb_host_endpoint
*uvc_find_endpoint(struct usb_host_interface
*alts
,
131 struct usb_host_endpoint
*ep
;
134 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
135 ep
= &alts
->endpoint
[i
];
136 if (ep
->desc
.bEndpointAddress
== epaddr
)
143 static struct uvc_format_desc
*uvc_format_by_guid(const __u8 guid
[16])
145 unsigned int len
= ARRAY_SIZE(uvc_fmts
);
148 for (i
= 0; i
< len
; ++i
) {
149 if (memcmp(guid
, uvc_fmts
[i
].guid
, 16) == 0)
156 static __u32
uvc_colorspace(const __u8 primaries
)
158 static const __u8 colorprimaries
[] = {
160 V4L2_COLORSPACE_SRGB
,
161 V4L2_COLORSPACE_470_SYSTEM_M
,
162 V4L2_COLORSPACE_470_SYSTEM_BG
,
163 V4L2_COLORSPACE_SMPTE170M
,
164 V4L2_COLORSPACE_SMPTE240M
,
167 if (primaries
< ARRAY_SIZE(colorprimaries
))
168 return colorprimaries
[primaries
];
173 /* Simplify a fraction using a simple continued fraction decomposition. The
174 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
175 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
176 * arbitrary parameters to remove non-significative terms from the simple
177 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
178 * respectively seems to give nice results.
180 void uvc_simplify_fraction(uint32_t *numerator
, uint32_t *denominator
,
181 unsigned int n_terms
, unsigned int threshold
)
187 an
= kmalloc(n_terms
* sizeof *an
, GFP_KERNEL
);
191 /* Convert the fraction to a simple continued fraction. See
192 * http://mathforum.org/dr.math/faq/faq.fractions.html
193 * Stop if the current term is bigger than or equal to the given
199 for (n
= 0; n
< n_terms
&& y
!= 0; ++n
) {
201 if (an
[n
] >= threshold
) {
212 /* Expand the simple continued fraction back to an integer fraction. */
216 for (i
= n
; i
> 0; --i
) {
227 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
228 * to compute numerator / denominator * 10000000 using 32 bit fixed point
231 uint32_t uvc_fraction_to_interval(uint32_t numerator
, uint32_t denominator
)
235 /* Saturate the result if the operation would overflow. */
236 if (denominator
== 0 ||
237 numerator
/denominator
>= ((uint32_t)-1)/10000000)
240 /* Divide both the denominator and the multiplier by two until
241 * numerator * multiplier doesn't overflow. If anyone knows a better
242 * algorithm please let me know.
244 multiplier
= 10000000;
245 while (numerator
> ((uint32_t)-1)/multiplier
) {
250 return denominator
? numerator
* multiplier
/ denominator
: 0;
253 /* ------------------------------------------------------------------------
254 * Terminal and unit management
257 struct uvc_entity
*uvc_entity_by_id(struct uvc_device
*dev
, int id
)
259 struct uvc_entity
*entity
;
261 list_for_each_entry(entity
, &dev
->entities
, list
) {
262 if (entity
->id
== id
)
269 static struct uvc_entity
*uvc_entity_by_reference(struct uvc_device
*dev
,
270 int id
, struct uvc_entity
*entity
)
275 entity
= list_entry(&dev
->entities
, struct uvc_entity
, list
);
277 list_for_each_entry_continue(entity
, &dev
->entities
, list
) {
278 for (i
= 0; i
< entity
->bNrInPins
; ++i
)
279 if (entity
->baSourceID
[i
] == id
)
286 static struct uvc_streaming
*uvc_stream_by_id(struct uvc_device
*dev
, int id
)
288 struct uvc_streaming
*stream
;
290 list_for_each_entry(stream
, &dev
->streams
, list
) {
291 if (stream
->header
.bTerminalLink
== id
)
298 /* ------------------------------------------------------------------------
299 * Descriptors parsing
302 static int uvc_parse_format(struct uvc_device
*dev
,
303 struct uvc_streaming
*streaming
, struct uvc_format
*format
,
304 __u32
**intervals
, unsigned char *buffer
, int buflen
)
306 struct usb_interface
*intf
= streaming
->intf
;
307 struct usb_host_interface
*alts
= intf
->cur_altsetting
;
308 struct uvc_format_desc
*fmtdesc
;
309 struct uvc_frame
*frame
;
310 const unsigned char *start
= buffer
;
311 unsigned int interval
;
315 format
->type
= buffer
[2];
316 format
->index
= buffer
[3];
319 case UVC_VS_FORMAT_UNCOMPRESSED
:
320 case UVC_VS_FORMAT_FRAME_BASED
:
321 n
= buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
? 27 : 28;
323 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
324 "interface %d FORMAT error\n",
326 alts
->desc
.bInterfaceNumber
);
330 /* Find the format descriptor from its GUID. */
331 fmtdesc
= uvc_format_by_guid(&buffer
[5]);
333 if (fmtdesc
!= NULL
) {
334 strlcpy(format
->name
, fmtdesc
->name
,
335 sizeof format
->name
);
336 format
->fcc
= fmtdesc
->fcc
;
338 uvc_printk(KERN_INFO
, "Unknown video format %pUl\n",
340 snprintf(format
->name
, sizeof(format
->name
), "%pUl\n",
345 format
->bpp
= buffer
[21];
346 if (buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
) {
347 ftype
= UVC_VS_FRAME_UNCOMPRESSED
;
349 ftype
= UVC_VS_FRAME_FRAME_BASED
;
351 format
->flags
= UVC_FMT_FLAG_COMPRESSED
;
355 case UVC_VS_FORMAT_MJPEG
:
357 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
358 "interface %d FORMAT error\n",
360 alts
->desc
.bInterfaceNumber
);
364 strlcpy(format
->name
, "MJPEG", sizeof format
->name
);
365 format
->fcc
= V4L2_PIX_FMT_MJPEG
;
366 format
->flags
= UVC_FMT_FLAG_COMPRESSED
;
368 ftype
= UVC_VS_FRAME_MJPEG
;
371 case UVC_VS_FORMAT_DV
:
373 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
374 "interface %d FORMAT error\n",
376 alts
->desc
.bInterfaceNumber
);
380 switch (buffer
[8] & 0x7f) {
382 strlcpy(format
->name
, "SD-DV", sizeof format
->name
);
385 strlcpy(format
->name
, "SDL-DV", sizeof format
->name
);
388 strlcpy(format
->name
, "HD-DV", sizeof format
->name
);
391 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
392 "interface %d: unknown DV format %u\n",
394 alts
->desc
.bInterfaceNumber
, buffer
[8]);
398 strlcat(format
->name
, buffer
[8] & (1 << 7) ? " 60Hz" : " 50Hz",
399 sizeof format
->name
);
401 format
->fcc
= V4L2_PIX_FMT_DV
;
402 format
->flags
= UVC_FMT_FLAG_COMPRESSED
| UVC_FMT_FLAG_STREAM
;
406 /* Create a dummy frame descriptor. */
407 frame
= &format
->frame
[0];
408 memset(&format
->frame
[0], 0, sizeof format
->frame
[0]);
409 frame
->bFrameIntervalType
= 1;
410 frame
->dwDefaultFrameInterval
= 1;
411 frame
->dwFrameInterval
= *intervals
;
416 case UVC_VS_FORMAT_MPEG2TS
:
417 case UVC_VS_FORMAT_STREAM_BASED
:
418 /* Not supported yet. */
420 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
421 "interface %d unsupported format %u\n",
422 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
,
427 uvc_trace(UVC_TRACE_DESCR
, "Found format %s.\n", format
->name
);
432 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
433 * based formats have frame descriptors.
435 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
436 buffer
[2] == ftype
) {
437 frame
= &format
->frame
[format
->nframes
];
438 if (ftype
!= UVC_VS_FRAME_FRAME_BASED
)
439 n
= buflen
> 25 ? buffer
[25] : 0;
441 n
= buflen
> 21 ? buffer
[21] : 0;
445 if (buflen
< 26 + 4*n
) {
446 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
447 "interface %d FRAME error\n", dev
->udev
->devnum
,
448 alts
->desc
.bInterfaceNumber
);
452 frame
->bFrameIndex
= buffer
[3];
453 frame
->bmCapabilities
= buffer
[4];
454 frame
->wWidth
= get_unaligned_le16(&buffer
[5]);
455 frame
->wHeight
= get_unaligned_le16(&buffer
[7]);
456 frame
->dwMinBitRate
= get_unaligned_le32(&buffer
[9]);
457 frame
->dwMaxBitRate
= get_unaligned_le32(&buffer
[13]);
458 if (ftype
!= UVC_VS_FRAME_FRAME_BASED
) {
459 frame
->dwMaxVideoFrameBufferSize
=
460 get_unaligned_le32(&buffer
[17]);
461 frame
->dwDefaultFrameInterval
=
462 get_unaligned_le32(&buffer
[21]);
463 frame
->bFrameIntervalType
= buffer
[25];
465 frame
->dwMaxVideoFrameBufferSize
= 0;
466 frame
->dwDefaultFrameInterval
=
467 get_unaligned_le32(&buffer
[17]);
468 frame
->bFrameIntervalType
= buffer
[21];
470 frame
->dwFrameInterval
= *intervals
;
472 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
473 * completely. Observed behaviours range from setting the
474 * value to 1.1x the actual frame size to hardwiring the
475 * 16 low bits to 0. This results in a higher than necessary
476 * memory usage as well as a wrong image size information. For
477 * uncompressed formats this can be fixed by computing the
478 * value from the frame size.
480 if (!(format
->flags
& UVC_FMT_FLAG_COMPRESSED
))
481 frame
->dwMaxVideoFrameBufferSize
= format
->bpp
482 * frame
->wWidth
* frame
->wHeight
/ 8;
484 /* Some bogus devices report dwMinFrameInterval equal to
485 * dwMaxFrameInterval and have dwFrameIntervalStep set to
486 * zero. Setting all null intervals to 1 fixes the problem and
487 * some other divisions by zero that could happen.
489 for (i
= 0; i
< n
; ++i
) {
490 interval
= get_unaligned_le32(&buffer
[26+4*i
]);
491 *(*intervals
)++ = interval
? interval
: 1;
494 /* Make sure that the default frame interval stays between
497 n
-= frame
->bFrameIntervalType
? 1 : 2;
498 frame
->dwDefaultFrameInterval
=
499 min(frame
->dwFrameInterval
[n
],
500 max(frame
->dwFrameInterval
[0],
501 frame
->dwDefaultFrameInterval
));
503 if (dev
->quirks
& UVC_QUIRK_RESTRICT_FRAME_RATE
) {
504 frame
->bFrameIntervalType
= 1;
505 frame
->dwFrameInterval
[0] =
506 frame
->dwDefaultFrameInterval
;
509 uvc_trace(UVC_TRACE_DESCR
, "- %ux%u (%u.%u fps)\n",
510 frame
->wWidth
, frame
->wHeight
,
511 10000000/frame
->dwDefaultFrameInterval
,
512 (100000000/frame
->dwDefaultFrameInterval
)%10);
519 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
520 buffer
[2] == UVC_VS_STILL_IMAGE_FRAME
) {
525 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
526 buffer
[2] == UVC_VS_COLORFORMAT
) {
528 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
529 "interface %d COLORFORMAT error\n",
531 alts
->desc
.bInterfaceNumber
);
535 format
->colorspace
= uvc_colorspace(buffer
[3]);
541 return buffer
- start
;
544 static int uvc_parse_streaming(struct uvc_device
*dev
,
545 struct usb_interface
*intf
)
547 struct uvc_streaming
*streaming
= NULL
;
548 struct uvc_format
*format
;
549 struct uvc_frame
*frame
;
550 struct usb_host_interface
*alts
= &intf
->altsetting
[0];
551 unsigned char *_buffer
, *buffer
= alts
->extra
;
552 int _buflen
, buflen
= alts
->extralen
;
553 unsigned int nformats
= 0, nframes
= 0, nintervals
= 0;
554 unsigned int size
, i
, n
, p
;
559 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
560 != UVC_SC_VIDEOSTREAMING
) {
561 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d isn't a "
562 "video streaming interface\n", dev
->udev
->devnum
,
563 intf
->altsetting
[0].desc
.bInterfaceNumber
);
567 if (usb_driver_claim_interface(&uvc_driver
.driver
, intf
, dev
)) {
568 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d is already "
569 "claimed\n", dev
->udev
->devnum
,
570 intf
->altsetting
[0].desc
.bInterfaceNumber
);
574 streaming
= kzalloc(sizeof *streaming
, GFP_KERNEL
);
575 if (streaming
== NULL
) {
576 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
580 mutex_init(&streaming
->mutex
);
581 streaming
->dev
= dev
;
582 streaming
->intf
= usb_get_intf(intf
);
583 streaming
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
585 /* The Pico iMage webcam has its class-specific interface descriptors
586 * after the endpoint descriptors.
589 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
590 struct usb_host_endpoint
*ep
= &alts
->endpoint
[i
];
592 if (ep
->extralen
== 0)
595 if (ep
->extralen
> 2 &&
596 ep
->extra
[1] == USB_DT_CS_INTERFACE
) {
597 uvc_trace(UVC_TRACE_DESCR
, "trying extra data "
598 "from endpoint %u.\n", i
);
599 buffer
= alts
->endpoint
[i
].extra
;
600 buflen
= alts
->endpoint
[i
].extralen
;
606 /* Skip the standard interface descriptors. */
607 while (buflen
> 2 && buffer
[1] != USB_DT_CS_INTERFACE
) {
613 uvc_trace(UVC_TRACE_DESCR
, "no class-specific streaming "
614 "interface descriptors found.\n");
618 /* Parse the header descriptor. */
620 case UVC_VS_OUTPUT_HEADER
:
621 streaming
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
625 case UVC_VS_INPUT_HEADER
:
626 streaming
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
631 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
632 "%d HEADER descriptor not found.\n", dev
->udev
->devnum
,
633 alts
->desc
.bInterfaceNumber
);
637 p
= buflen
>= 4 ? buffer
[3] : 0;
638 n
= buflen
>= size
? buffer
[size
-1] : 0;
640 if (buflen
< size
+ p
*n
) {
641 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
642 "interface %d HEADER descriptor is invalid.\n",
643 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
647 streaming
->header
.bNumFormats
= p
;
648 streaming
->header
.bEndpointAddress
= buffer
[6];
649 if (buffer
[2] == UVC_VS_INPUT_HEADER
) {
650 streaming
->header
.bmInfo
= buffer
[7];
651 streaming
->header
.bTerminalLink
= buffer
[8];
652 streaming
->header
.bStillCaptureMethod
= buffer
[9];
653 streaming
->header
.bTriggerSupport
= buffer
[10];
654 streaming
->header
.bTriggerUsage
= buffer
[11];
656 streaming
->header
.bTerminalLink
= buffer
[7];
658 streaming
->header
.bControlSize
= n
;
660 streaming
->header
.bmaControls
= kmemdup(&buffer
[size
], p
* n
,
662 if (streaming
->header
.bmaControls
== NULL
) {
673 /* Count the format and frame descriptors. */
674 while (_buflen
> 2 && _buffer
[1] == USB_DT_CS_INTERFACE
) {
675 switch (_buffer
[2]) {
676 case UVC_VS_FORMAT_UNCOMPRESSED
:
677 case UVC_VS_FORMAT_MJPEG
:
678 case UVC_VS_FORMAT_FRAME_BASED
:
682 case UVC_VS_FORMAT_DV
:
683 /* DV format has no frame descriptor. We will create a
684 * dummy frame descriptor with a dummy frame interval.
691 case UVC_VS_FORMAT_MPEG2TS
:
692 case UVC_VS_FORMAT_STREAM_BASED
:
693 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
694 "interface %d FORMAT %u is not supported.\n",
696 alts
->desc
.bInterfaceNumber
, _buffer
[2]);
699 case UVC_VS_FRAME_UNCOMPRESSED
:
700 case UVC_VS_FRAME_MJPEG
:
703 nintervals
+= _buffer
[25] ? _buffer
[25] : 3;
706 case UVC_VS_FRAME_FRAME_BASED
:
709 nintervals
+= _buffer
[21] ? _buffer
[21] : 3;
713 _buflen
-= _buffer
[0];
714 _buffer
+= _buffer
[0];
718 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
719 "%d has no supported formats defined.\n",
720 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
724 size
= nformats
* sizeof *format
+ nframes
* sizeof *frame
725 + nintervals
* sizeof *interval
;
726 format
= kzalloc(size
, GFP_KERNEL
);
727 if (format
== NULL
) {
732 frame
= (struct uvc_frame
*)&format
[nformats
];
733 interval
= (__u32
*)&frame
[nframes
];
735 streaming
->format
= format
;
736 streaming
->nformats
= nformats
;
738 /* Parse the format descriptors. */
739 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
) {
741 case UVC_VS_FORMAT_UNCOMPRESSED
:
742 case UVC_VS_FORMAT_MJPEG
:
743 case UVC_VS_FORMAT_DV
:
744 case UVC_VS_FORMAT_FRAME_BASED
:
745 format
->frame
= frame
;
746 ret
= uvc_parse_format(dev
, streaming
, format
,
747 &interval
, buffer
, buflen
);
751 frame
+= format
->nframes
;
767 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
768 "%d has %u bytes of trailing descriptor garbage.\n",
769 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
, buflen
);
771 /* Parse the alternate settings to find the maximum bandwidth. */
772 for (i
= 0; i
< intf
->num_altsetting
; ++i
) {
773 struct usb_host_endpoint
*ep
;
774 alts
= &intf
->altsetting
[i
];
775 ep
= uvc_find_endpoint(alts
,
776 streaming
->header
.bEndpointAddress
);
780 psize
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
781 psize
= (psize
& 0x07ff) * (1 + ((psize
>> 11) & 3));
782 if (psize
> streaming
->maxpsize
)
783 streaming
->maxpsize
= psize
;
786 list_add_tail(&streaming
->list
, &dev
->streams
);
790 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
792 kfree(streaming
->format
);
793 kfree(streaming
->header
.bmaControls
);
798 static struct uvc_entity
*uvc_alloc_entity(u16 type
, u8 id
,
799 unsigned int num_pads
, unsigned int extra_size
)
801 struct uvc_entity
*entity
;
802 unsigned int num_inputs
;
806 extra_size
= ALIGN(extra_size
, sizeof(*entity
->pads
));
807 num_inputs
= (type
& UVC_TERM_OUTPUT
) ? num_pads
: num_pads
- 1;
808 size
= sizeof(*entity
) + extra_size
+ sizeof(*entity
->pads
) * num_pads
810 entity
= kzalloc(size
, GFP_KERNEL
);
817 entity
->num_links
= 0;
818 entity
->num_pads
= num_pads
;
819 entity
->pads
= ((void *)(entity
+ 1)) + extra_size
;
821 for (i
= 0; i
< num_inputs
; ++i
)
822 entity
->pads
[i
].flags
= MEDIA_PAD_FL_SINK
;
823 if (!UVC_ENTITY_IS_OTERM(entity
))
824 entity
->pads
[num_pads
-1].flags
= MEDIA_PAD_FL_SOURCE
;
826 entity
->bNrInPins
= num_inputs
;
827 entity
->baSourceID
= (__u8
*)(&entity
->pads
[num_pads
]);
832 /* Parse vendor-specific extensions. */
833 static int uvc_parse_vendor_control(struct uvc_device
*dev
,
834 const unsigned char *buffer
, int buflen
)
836 struct usb_device
*udev
= dev
->udev
;
837 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
838 struct uvc_entity
*unit
;
842 switch (le16_to_cpu(dev
->udev
->descriptor
.idVendor
)) {
843 case 0x046d: /* Logitech */
844 if (buffer
[1] != 0x41 || buffer
[2] != 0x01)
847 /* Logitech implements several vendor specific functions
848 * through vendor specific extension units (LXU).
850 * The LXU descriptors are similar to XU descriptors
851 * (see "USB Device Video Class for Video Devices", section
852 * 3.7.2.6 "Extension Unit Descriptor") with the following
855 * ----------------------------------------------------------
857 * Size of this descriptor, in bytes: 24+p+n*2
858 * ----------------------------------------------------------
859 * 23+p+n bmControlsType N Bitmap
860 * Individual bits in the set are defined:
864 * This bitset is mapped exactly the same as bmControls.
865 * ----------------------------------------------------------
866 * 23+p+n*2 bReserved 1 Boolean
867 * ----------------------------------------------------------
868 * 24+p+n*2 iExtension 1 Index
869 * Index of a string descriptor that describes this
871 * ----------------------------------------------------------
873 p
= buflen
>= 22 ? buffer
[21] : 0;
874 n
= buflen
>= 25 + p
? buffer
[22+p
] : 0;
876 if (buflen
< 25 + p
+ 2*n
) {
877 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
878 "interface %d EXTENSION_UNIT error\n",
879 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
883 unit
= uvc_alloc_entity(UVC_VC_EXTENSION_UNIT
, buffer
[3],
888 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
889 unit
->extension
.bNumControls
= buffer
[20];
890 memcpy(unit
->baSourceID
, &buffer
[22], p
);
891 unit
->extension
.bControlSize
= buffer
[22+p
];
892 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof(*unit
);
893 unit
->extension
.bmControlsType
= (__u8
*)unit
+ sizeof(*unit
)
895 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], 2*n
);
897 if (buffer
[24+p
+2*n
] != 0)
898 usb_string(udev
, buffer
[24+p
+2*n
], unit
->name
,
901 sprintf(unit
->name
, "Extension %u", buffer
[3]);
903 list_add_tail(&unit
->list
, &dev
->entities
);
911 static int uvc_parse_standard_control(struct uvc_device
*dev
,
912 const unsigned char *buffer
, int buflen
)
914 struct usb_device
*udev
= dev
->udev
;
915 struct uvc_entity
*unit
, *term
;
916 struct usb_interface
*intf
;
917 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
918 unsigned int i
, n
, p
, len
;
923 n
= buflen
>= 12 ? buffer
[11] : 0;
925 if (buflen
< 12 || buflen
< 12 + n
) {
926 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
927 "interface %d HEADER error\n", udev
->devnum
,
928 alts
->desc
.bInterfaceNumber
);
932 dev
->uvc_version
= get_unaligned_le16(&buffer
[3]);
933 dev
->clock_frequency
= get_unaligned_le32(&buffer
[7]);
935 /* Parse all USB Video Streaming interfaces. */
936 for (i
= 0; i
< n
; ++i
) {
937 intf
= usb_ifnum_to_if(udev
, buffer
[12+i
]);
939 uvc_trace(UVC_TRACE_DESCR
, "device %d "
940 "interface %d doesn't exists\n",
945 uvc_parse_streaming(dev
, intf
);
949 case UVC_VC_INPUT_TERMINAL
:
951 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
952 "interface %d INPUT_TERMINAL error\n",
953 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
957 /* Make sure the terminal type MSB is not null, otherwise it
958 * could be confused with a unit.
960 type
= get_unaligned_le16(&buffer
[4]);
961 if ((type
& 0xff00) == 0) {
962 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
963 "interface %d INPUT_TERMINAL %d has invalid "
964 "type 0x%04x, skipping\n", udev
->devnum
,
965 alts
->desc
.bInterfaceNumber
,
974 if (type
== UVC_ITT_CAMERA
) {
975 n
= buflen
>= 15 ? buffer
[14] : 0;
978 } else if (type
== UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
979 n
= buflen
>= 9 ? buffer
[8] : 0;
980 p
= buflen
>= 10 + n
? buffer
[9+n
] : 0;
984 if (buflen
< len
+ n
+ p
) {
985 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
986 "interface %d INPUT_TERMINAL error\n",
987 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
991 term
= uvc_alloc_entity(type
| UVC_TERM_INPUT
, buffer
[3],
996 if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
) {
997 term
->camera
.bControlSize
= n
;
998 term
->camera
.bmControls
= (__u8
*)term
+ sizeof *term
;
999 term
->camera
.wObjectiveFocalLengthMin
=
1000 get_unaligned_le16(&buffer
[8]);
1001 term
->camera
.wObjectiveFocalLengthMax
=
1002 get_unaligned_le16(&buffer
[10]);
1003 term
->camera
.wOcularFocalLength
=
1004 get_unaligned_le16(&buffer
[12]);
1005 memcpy(term
->camera
.bmControls
, &buffer
[15], n
);
1006 } else if (UVC_ENTITY_TYPE(term
) ==
1007 UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
1008 term
->media
.bControlSize
= n
;
1009 term
->media
.bmControls
= (__u8
*)term
+ sizeof *term
;
1010 term
->media
.bTransportModeSize
= p
;
1011 term
->media
.bmTransportModes
= (__u8
*)term
1013 memcpy(term
->media
.bmControls
, &buffer
[9], n
);
1014 memcpy(term
->media
.bmTransportModes
, &buffer
[10+n
], p
);
1018 usb_string(udev
, buffer
[7], term
->name
,
1020 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
)
1021 sprintf(term
->name
, "Camera %u", buffer
[3]);
1022 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_MEDIA_TRANSPORT_INPUT
)
1023 sprintf(term
->name
, "Media %u", buffer
[3]);
1025 sprintf(term
->name
, "Input %u", buffer
[3]);
1027 list_add_tail(&term
->list
, &dev
->entities
);
1030 case UVC_VC_OUTPUT_TERMINAL
:
1032 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1033 "interface %d OUTPUT_TERMINAL error\n",
1034 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1038 /* Make sure the terminal type MSB is not null, otherwise it
1039 * could be confused with a unit.
1041 type
= get_unaligned_le16(&buffer
[4]);
1042 if ((type
& 0xff00) == 0) {
1043 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1044 "interface %d OUTPUT_TERMINAL %d has invalid "
1045 "type 0x%04x, skipping\n", udev
->devnum
,
1046 alts
->desc
.bInterfaceNumber
, buffer
[3], type
);
1050 term
= uvc_alloc_entity(type
| UVC_TERM_OUTPUT
, buffer
[3],
1055 memcpy(term
->baSourceID
, &buffer
[7], 1);
1058 usb_string(udev
, buffer
[8], term
->name
,
1061 sprintf(term
->name
, "Output %u", buffer
[3]);
1063 list_add_tail(&term
->list
, &dev
->entities
);
1066 case UVC_VC_SELECTOR_UNIT
:
1067 p
= buflen
>= 5 ? buffer
[4] : 0;
1069 if (buflen
< 5 || buflen
< 6 + p
) {
1070 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1071 "interface %d SELECTOR_UNIT error\n",
1072 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1076 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], p
+ 1, 0);
1080 memcpy(unit
->baSourceID
, &buffer
[5], p
);
1082 if (buffer
[5+p
] != 0)
1083 usb_string(udev
, buffer
[5+p
], unit
->name
,
1086 sprintf(unit
->name
, "Selector %u", buffer
[3]);
1088 list_add_tail(&unit
->list
, &dev
->entities
);
1091 case UVC_VC_PROCESSING_UNIT
:
1092 n
= buflen
>= 8 ? buffer
[7] : 0;
1093 p
= dev
->uvc_version
>= 0x0110 ? 10 : 9;
1095 if (buflen
< p
+ n
) {
1096 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1097 "interface %d PROCESSING_UNIT error\n",
1098 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1102 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], 2, n
);
1106 memcpy(unit
->baSourceID
, &buffer
[4], 1);
1107 unit
->processing
.wMaxMultiplier
=
1108 get_unaligned_le16(&buffer
[5]);
1109 unit
->processing
.bControlSize
= buffer
[7];
1110 unit
->processing
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1111 memcpy(unit
->processing
.bmControls
, &buffer
[8], n
);
1112 if (dev
->uvc_version
>= 0x0110)
1113 unit
->processing
.bmVideoStandards
= buffer
[9+n
];
1115 if (buffer
[8+n
] != 0)
1116 usb_string(udev
, buffer
[8+n
], unit
->name
,
1119 sprintf(unit
->name
, "Processing %u", buffer
[3]);
1121 list_add_tail(&unit
->list
, &dev
->entities
);
1124 case UVC_VC_EXTENSION_UNIT
:
1125 p
= buflen
>= 22 ? buffer
[21] : 0;
1126 n
= buflen
>= 24 + p
? buffer
[22+p
] : 0;
1128 if (buflen
< 24 + p
+ n
) {
1129 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1130 "interface %d EXTENSION_UNIT error\n",
1131 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1135 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], p
+ 1, n
);
1139 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
1140 unit
->extension
.bNumControls
= buffer
[20];
1141 memcpy(unit
->baSourceID
, &buffer
[22], p
);
1142 unit
->extension
.bControlSize
= buffer
[22+p
];
1143 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1144 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], n
);
1146 if (buffer
[23+p
+n
] != 0)
1147 usb_string(udev
, buffer
[23+p
+n
], unit
->name
,
1150 sprintf(unit
->name
, "Extension %u", buffer
[3]);
1152 list_add_tail(&unit
->list
, &dev
->entities
);
1156 uvc_trace(UVC_TRACE_DESCR
, "Found an unknown CS_INTERFACE "
1157 "descriptor (%u)\n", buffer
[2]);
1164 static int uvc_parse_control(struct uvc_device
*dev
)
1166 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
1167 unsigned char *buffer
= alts
->extra
;
1168 int buflen
= alts
->extralen
;
1171 /* Parse the default alternate setting only, as the UVC specification
1172 * defines a single alternate setting, the default alternate setting
1176 while (buflen
> 2) {
1177 if (uvc_parse_vendor_control(dev
, buffer
, buflen
) ||
1178 buffer
[1] != USB_DT_CS_INTERFACE
)
1179 goto next_descriptor
;
1181 if ((ret
= uvc_parse_standard_control(dev
, buffer
, buflen
)) < 0)
1185 buflen
-= buffer
[0];
1186 buffer
+= buffer
[0];
1189 /* Check if the optional status endpoint is present. Built-in iSight
1190 * webcams have an interrupt endpoint but spit proprietary data that
1191 * don't conform to the UVC status endpoint messages. Don't try to
1192 * handle the interrupt endpoint for those cameras.
1194 if (alts
->desc
.bNumEndpoints
== 1 &&
1195 !(dev
->quirks
& UVC_QUIRK_BUILTIN_ISIGHT
)) {
1196 struct usb_host_endpoint
*ep
= &alts
->endpoint
[0];
1197 struct usb_endpoint_descriptor
*desc
= &ep
->desc
;
1199 if (usb_endpoint_is_int_in(desc
) &&
1200 le16_to_cpu(desc
->wMaxPacketSize
) >= 8 &&
1201 desc
->bInterval
!= 0) {
1202 uvc_trace(UVC_TRACE_DESCR
, "Found a Status endpoint "
1203 "(addr %02x).\n", desc
->bEndpointAddress
);
1211 /* ------------------------------------------------------------------------
1216 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1217 * and containing the following units:
1219 * - one or more Output Terminals (USB Streaming or Display)
1220 * - zero or one Processing Unit
1221 * - zero, one or more single-input Selector Units
1222 * - zero or one multiple-input Selector Units, provided all inputs are
1223 * connected to input terminals
1224 * - zero, one or mode single-input Extension Units
1225 * - one or more Input Terminals (Camera, External or USB Streaming)
1227 * The terminal and units must match on of the following structures:
1229 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1230 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1231 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1233 * +---------+ +---------+ -> OTT_*(0)
1234 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1235 * +---------+ +---------+ -> OTT_*(n)
1237 * The Processing Unit and Extension Units can be in any order. Additional
1238 * Extension Units connected to the main chain as single-unit branches are
1239 * also supported. Single-input Selector Units are ignored.
1241 static int uvc_scan_chain_entity(struct uvc_video_chain
*chain
,
1242 struct uvc_entity
*entity
)
1244 switch (UVC_ENTITY_TYPE(entity
)) {
1245 case UVC_VC_EXTENSION_UNIT
:
1246 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1247 printk(" <- XU %d", entity
->id
);
1249 if (entity
->bNrInPins
!= 1) {
1250 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d has more "
1251 "than 1 input pin.\n", entity
->id
);
1257 case UVC_VC_PROCESSING_UNIT
:
1258 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1259 printk(" <- PU %d", entity
->id
);
1261 if (chain
->processing
!= NULL
) {
1262 uvc_trace(UVC_TRACE_DESCR
, "Found multiple "
1263 "Processing Units in chain.\n");
1267 chain
->processing
= entity
;
1270 case UVC_VC_SELECTOR_UNIT
:
1271 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1272 printk(" <- SU %d", entity
->id
);
1274 /* Single-input selector units are ignored. */
1275 if (entity
->bNrInPins
== 1)
1278 if (chain
->selector
!= NULL
) {
1279 uvc_trace(UVC_TRACE_DESCR
, "Found multiple Selector "
1280 "Units in chain.\n");
1284 chain
->selector
= entity
;
1287 case UVC_ITT_VENDOR_SPECIFIC
:
1288 case UVC_ITT_CAMERA
:
1289 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1290 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1291 printk(" <- IT %d\n", entity
->id
);
1295 case UVC_OTT_VENDOR_SPECIFIC
:
1296 case UVC_OTT_DISPLAY
:
1297 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1298 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1299 printk(" OT %d", entity
->id
);
1303 case UVC_TT_STREAMING
:
1304 if (UVC_ENTITY_IS_ITERM(entity
)) {
1305 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1306 printk(" <- IT %d\n", entity
->id
);
1308 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1309 printk(" OT %d", entity
->id
);
1315 uvc_trace(UVC_TRACE_DESCR
, "Unsupported entity type "
1316 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity
));
1320 list_add_tail(&entity
->chain
, &chain
->entities
);
1324 static int uvc_scan_chain_forward(struct uvc_video_chain
*chain
,
1325 struct uvc_entity
*entity
, struct uvc_entity
*prev
)
1327 struct uvc_entity
*forward
;
1335 forward
= uvc_entity_by_reference(chain
->dev
, entity
->id
,
1337 if (forward
== NULL
)
1339 if (forward
== prev
)
1342 switch (UVC_ENTITY_TYPE(forward
)) {
1343 case UVC_VC_EXTENSION_UNIT
:
1344 if (forward
->bNrInPins
!= 1) {
1345 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d "
1346 "has more than 1 input pin.\n",
1351 list_add_tail(&forward
->chain
, &chain
->entities
);
1352 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1356 printk(" XU %d", forward
->id
);
1361 case UVC_OTT_VENDOR_SPECIFIC
:
1362 case UVC_OTT_DISPLAY
:
1363 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1364 case UVC_TT_STREAMING
:
1365 if (UVC_ENTITY_IS_ITERM(forward
)) {
1366 uvc_trace(UVC_TRACE_DESCR
, "Unsupported input "
1367 "terminal %u.\n", forward
->id
);
1371 list_add_tail(&forward
->chain
, &chain
->entities
);
1372 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1376 printk(" OT %d", forward
->id
);
1388 static int uvc_scan_chain_backward(struct uvc_video_chain
*chain
,
1389 struct uvc_entity
**_entity
)
1391 struct uvc_entity
*entity
= *_entity
;
1392 struct uvc_entity
*term
;
1393 int id
= -EINVAL
, i
;
1395 switch (UVC_ENTITY_TYPE(entity
)) {
1396 case UVC_VC_EXTENSION_UNIT
:
1397 case UVC_VC_PROCESSING_UNIT
:
1398 id
= entity
->baSourceID
[0];
1401 case UVC_VC_SELECTOR_UNIT
:
1402 /* Single-input selector units are ignored. */
1403 if (entity
->bNrInPins
== 1) {
1404 id
= entity
->baSourceID
[0];
1408 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1411 chain
->selector
= entity
;
1412 for (i
= 0; i
< entity
->bNrInPins
; ++i
) {
1413 id
= entity
->baSourceID
[i
];
1414 term
= uvc_entity_by_id(chain
->dev
, id
);
1415 if (term
== NULL
|| !UVC_ENTITY_IS_ITERM(term
)) {
1416 uvc_trace(UVC_TRACE_DESCR
, "Selector unit %d "
1417 "input %d isn't connected to an "
1418 "input terminal\n", entity
->id
, i
);
1422 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1423 printk(" %d", term
->id
);
1425 list_add_tail(&term
->chain
, &chain
->entities
);
1426 uvc_scan_chain_forward(chain
, term
, entity
);
1429 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1435 case UVC_ITT_VENDOR_SPECIFIC
:
1436 case UVC_ITT_CAMERA
:
1437 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1438 case UVC_OTT_VENDOR_SPECIFIC
:
1439 case UVC_OTT_DISPLAY
:
1440 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1441 case UVC_TT_STREAMING
:
1442 id
= UVC_ENTITY_IS_OTERM(entity
) ? entity
->baSourceID
[0] : 0;
1451 entity
= uvc_entity_by_id(chain
->dev
, id
);
1452 if (entity
== NULL
) {
1453 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1454 "unknown entity %d.\n", id
);
1462 static int uvc_scan_chain(struct uvc_video_chain
*chain
,
1463 struct uvc_entity
*term
)
1465 struct uvc_entity
*entity
, *prev
;
1467 uvc_trace(UVC_TRACE_PROBE
, "Scanning UVC chain:");
1472 while (entity
!= NULL
) {
1473 /* Entity must not be part of an existing chain */
1474 if (entity
->chain
.next
|| entity
->chain
.prev
) {
1475 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1476 "entity %d already in chain.\n", entity
->id
);
1480 /* Process entity */
1481 if (uvc_scan_chain_entity(chain
, entity
) < 0)
1485 if (uvc_scan_chain_forward(chain
, entity
, prev
) < 0)
1490 if (uvc_scan_chain_backward(chain
, &entity
) < 0)
1497 static unsigned int uvc_print_terms(struct list_head
*terms
, u16 dir
,
1500 struct uvc_entity
*term
;
1501 unsigned int nterms
= 0;
1504 list_for_each_entry(term
, terms
, chain
) {
1505 if (!UVC_ENTITY_IS_TERM(term
) ||
1506 UVC_TERM_DIRECTION(term
) != dir
)
1510 p
+= sprintf(p
, ",");
1511 if (++nterms
>= 4) {
1512 p
+= sprintf(p
, "...");
1515 p
+= sprintf(p
, "%u", term
->id
);
1521 static const char *uvc_print_chain(struct uvc_video_chain
*chain
)
1523 static char buffer
[43];
1526 p
+= uvc_print_terms(&chain
->entities
, UVC_TERM_INPUT
, p
);
1527 p
+= sprintf(p
, " -> ");
1528 uvc_print_terms(&chain
->entities
, UVC_TERM_OUTPUT
, p
);
1534 * Scan the device for video chains and register video devices.
1536 * Chains are scanned starting at their output terminals and walked backwards.
1538 static int uvc_scan_device(struct uvc_device
*dev
)
1540 struct uvc_video_chain
*chain
;
1541 struct uvc_entity
*term
;
1543 list_for_each_entry(term
, &dev
->entities
, list
) {
1544 if (!UVC_ENTITY_IS_OTERM(term
))
1547 /* If the terminal is already included in a chain, skip it.
1548 * This can happen for chains that have multiple output
1549 * terminals, where all output terminals beside the first one
1550 * will be inserted in the chain in forward scans.
1552 if (term
->chain
.next
|| term
->chain
.prev
)
1555 chain
= kzalloc(sizeof(*chain
), GFP_KERNEL
);
1559 INIT_LIST_HEAD(&chain
->entities
);
1560 mutex_init(&chain
->ctrl_mutex
);
1563 if (uvc_scan_chain(chain
, term
) < 0) {
1568 uvc_trace(UVC_TRACE_PROBE
, "Found a valid video chain (%s).\n",
1569 uvc_print_chain(chain
));
1571 list_add_tail(&chain
->list
, &dev
->chains
);
1574 if (list_empty(&dev
->chains
)) {
1575 uvc_printk(KERN_INFO
, "No valid video chain found.\n");
1582 /* ------------------------------------------------------------------------
1583 * Video device registration and unregistration
1587 * Delete the UVC device.
1589 * Called by the kernel when the last reference to the uvc_device structure
1592 * As this function is called after or during disconnect(), all URBs have
1593 * already been canceled by the USB core. There is no need to kill the
1594 * interrupt URB manually.
1596 static void uvc_delete(struct uvc_device
*dev
)
1598 struct list_head
*p
, *n
;
1600 usb_put_intf(dev
->intf
);
1601 usb_put_dev(dev
->udev
);
1603 uvc_status_cleanup(dev
);
1604 uvc_ctrl_cleanup_device(dev
);
1607 v4l2_device_unregister(&dev
->vdev
);
1608 #ifdef CONFIG_MEDIA_CONTROLLER
1609 if (media_devnode_is_registered(&dev
->mdev
.devnode
))
1610 media_device_unregister(&dev
->mdev
);
1613 list_for_each_safe(p
, n
, &dev
->chains
) {
1614 struct uvc_video_chain
*chain
;
1615 chain
= list_entry(p
, struct uvc_video_chain
, list
);
1619 list_for_each_safe(p
, n
, &dev
->entities
) {
1620 struct uvc_entity
*entity
;
1621 entity
= list_entry(p
, struct uvc_entity
, list
);
1622 #ifdef CONFIG_MEDIA_CONTROLLER
1623 uvc_mc_cleanup_entity(entity
);
1626 video_device_release(entity
->vdev
);
1627 entity
->vdev
= NULL
;
1632 list_for_each_safe(p
, n
, &dev
->streams
) {
1633 struct uvc_streaming
*streaming
;
1634 streaming
= list_entry(p
, struct uvc_streaming
, list
);
1635 usb_driver_release_interface(&uvc_driver
.driver
,
1637 usb_put_intf(streaming
->intf
);
1638 kfree(streaming
->format
);
1639 kfree(streaming
->header
.bmaControls
);
1646 static void uvc_release(struct video_device
*vdev
)
1648 struct uvc_streaming
*stream
= video_get_drvdata(vdev
);
1649 struct uvc_device
*dev
= stream
->dev
;
1651 /* Decrement the registered streams count and delete the device when it
1654 if (atomic_dec_and_test(&dev
->nstreams
))
1659 * Unregister the video devices.
1661 static void uvc_unregister_video(struct uvc_device
*dev
)
1663 struct uvc_streaming
*stream
;
1665 /* Unregistering all video devices might result in uvc_delete() being
1666 * called from inside the loop if there's no open file handle. To avoid
1667 * that, increment the stream count before iterating over the streams
1668 * and decrement it when done.
1670 atomic_inc(&dev
->nstreams
);
1672 list_for_each_entry(stream
, &dev
->streams
, list
) {
1673 if (stream
->vdev
== NULL
)
1676 video_unregister_device(stream
->vdev
);
1677 stream
->vdev
= NULL
;
1679 uvc_debugfs_cleanup_stream(stream
);
1682 /* Decrement the stream count and call uvc_delete explicitly if there
1683 * are no stream left.
1685 if (atomic_dec_and_test(&dev
->nstreams
))
1689 static int uvc_register_video(struct uvc_device
*dev
,
1690 struct uvc_streaming
*stream
)
1692 struct video_device
*vdev
;
1695 /* Initialize the streaming interface with default streaming
1698 ret
= uvc_video_init(stream
);
1700 uvc_printk(KERN_ERR
, "Failed to initialize the device "
1705 uvc_debugfs_init_stream(stream
);
1707 /* Register the device with V4L. */
1708 vdev
= video_device_alloc();
1710 uvc_printk(KERN_ERR
, "Failed to allocate video device (%d).\n",
1715 /* We already hold a reference to dev->udev. The video device will be
1716 * unregistered before the reference is released, so we don't need to
1719 vdev
->v4l2_dev
= &dev
->vdev
;
1720 vdev
->fops
= &uvc_fops
;
1721 vdev
->release
= uvc_release
;
1722 strlcpy(vdev
->name
, dev
->name
, sizeof vdev
->name
);
1724 /* Set the driver data before calling video_register_device, otherwise
1725 * uvc_v4l2_open might race us.
1727 stream
->vdev
= vdev
;
1728 video_set_drvdata(vdev
, stream
);
1730 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1732 uvc_printk(KERN_ERR
, "Failed to register video device (%d).\n",
1734 stream
->vdev
= NULL
;
1735 video_device_release(vdev
);
1739 atomic_inc(&dev
->nstreams
);
1744 * Register all video devices in all chains.
1746 static int uvc_register_terms(struct uvc_device
*dev
,
1747 struct uvc_video_chain
*chain
)
1749 struct uvc_streaming
*stream
;
1750 struct uvc_entity
*term
;
1753 list_for_each_entry(term
, &chain
->entities
, chain
) {
1754 if (UVC_ENTITY_TYPE(term
) != UVC_TT_STREAMING
)
1757 stream
= uvc_stream_by_id(dev
, term
->id
);
1758 if (stream
== NULL
) {
1759 uvc_printk(KERN_INFO
, "No streaming interface found "
1760 "for terminal %u.", term
->id
);
1764 stream
->chain
= chain
;
1765 ret
= uvc_register_video(dev
, stream
);
1769 term
->vdev
= stream
->vdev
;
1775 static int uvc_register_chains(struct uvc_device
*dev
)
1777 struct uvc_video_chain
*chain
;
1780 list_for_each_entry(chain
, &dev
->chains
, list
) {
1781 ret
= uvc_register_terms(dev
, chain
);
1785 #ifdef CONFIG_MEDIA_CONTROLLER
1786 ret
= uvc_mc_register_entities(chain
);
1788 uvc_printk(KERN_INFO
, "Failed to register entites "
1797 /* ------------------------------------------------------------------------
1798 * USB probe, disconnect, suspend and resume
1801 static int uvc_probe(struct usb_interface
*intf
,
1802 const struct usb_device_id
*id
)
1804 struct usb_device
*udev
= interface_to_usbdev(intf
);
1805 struct uvc_device
*dev
;
1808 if (id
->idVendor
&& id
->idProduct
)
1809 uvc_trace(UVC_TRACE_PROBE
, "Probing known UVC device %s "
1810 "(%04x:%04x)\n", udev
->devpath
, id
->idVendor
,
1813 uvc_trace(UVC_TRACE_PROBE
, "Probing generic UVC device %s\n",
1816 /* Allocate memory for the device and initialize it. */
1817 if ((dev
= kzalloc(sizeof *dev
, GFP_KERNEL
)) == NULL
)
1820 INIT_LIST_HEAD(&dev
->entities
);
1821 INIT_LIST_HEAD(&dev
->chains
);
1822 INIT_LIST_HEAD(&dev
->streams
);
1823 atomic_set(&dev
->nstreams
, 0);
1824 atomic_set(&dev
->users
, 0);
1825 atomic_set(&dev
->nmappings
, 0);
1827 dev
->udev
= usb_get_dev(udev
);
1828 dev
->intf
= usb_get_intf(intf
);
1829 dev
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
1830 dev
->quirks
= (uvc_quirks_param
== -1)
1831 ? id
->driver_info
: uvc_quirks_param
;
1833 if (udev
->product
!= NULL
)
1834 strlcpy(dev
->name
, udev
->product
, sizeof dev
->name
);
1836 snprintf(dev
->name
, sizeof dev
->name
,
1837 "UVC Camera (%04x:%04x)",
1838 le16_to_cpu(udev
->descriptor
.idVendor
),
1839 le16_to_cpu(udev
->descriptor
.idProduct
));
1841 /* Parse the Video Class control descriptor. */
1842 if (uvc_parse_control(dev
) < 0) {
1843 uvc_trace(UVC_TRACE_PROBE
, "Unable to parse UVC "
1848 uvc_printk(KERN_INFO
, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1849 dev
->uvc_version
>> 8, dev
->uvc_version
& 0xff,
1850 udev
->product
? udev
->product
: "<unnamed>",
1851 le16_to_cpu(udev
->descriptor
.idVendor
),
1852 le16_to_cpu(udev
->descriptor
.idProduct
));
1854 if (dev
->quirks
!= id
->driver_info
) {
1855 uvc_printk(KERN_INFO
, "Forcing device quirks to 0x%x by module "
1856 "parameter for testing purpose.\n", dev
->quirks
);
1857 uvc_printk(KERN_INFO
, "Please report required quirks to the "
1858 "linux-uvc-devel mailing list.\n");
1861 /* Register the media and V4L2 devices. */
1862 #ifdef CONFIG_MEDIA_CONTROLLER
1863 dev
->mdev
.dev
= &intf
->dev
;
1864 strlcpy(dev
->mdev
.model
, dev
->name
, sizeof(dev
->mdev
.model
));
1866 strlcpy(dev
->mdev
.serial
, udev
->serial
,
1867 sizeof(dev
->mdev
.serial
));
1868 strcpy(dev
->mdev
.bus_info
, udev
->devpath
);
1869 dev
->mdev
.hw_revision
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
1870 dev
->mdev
.driver_version
= LINUX_VERSION_CODE
;
1871 if (media_device_register(&dev
->mdev
) < 0)
1874 dev
->vdev
.mdev
= &dev
->mdev
;
1876 if (v4l2_device_register(&intf
->dev
, &dev
->vdev
) < 0)
1879 /* Initialize controls. */
1880 if (uvc_ctrl_init_device(dev
) < 0)
1883 /* Scan the device for video chains. */
1884 if (uvc_scan_device(dev
) < 0)
1887 /* Register video device nodes. */
1888 if (uvc_register_chains(dev
) < 0)
1891 /* Save our data pointer in the interface data. */
1892 usb_set_intfdata(intf
, dev
);
1894 /* Initialize the interrupt URB. */
1895 if ((ret
= uvc_status_init(dev
)) < 0) {
1896 uvc_printk(KERN_INFO
, "Unable to initialize the status "
1897 "endpoint (%d), status interrupt will not be "
1898 "supported.\n", ret
);
1901 uvc_trace(UVC_TRACE_PROBE
, "UVC device initialized.\n");
1902 usb_enable_autosuspend(udev
);
1906 uvc_unregister_video(dev
);
1910 static void uvc_disconnect(struct usb_interface
*intf
)
1912 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1914 /* Set the USB interface data to NULL. This can be done outside the
1915 * lock, as there's no other reader.
1917 usb_set_intfdata(intf
, NULL
);
1919 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1920 UVC_SC_VIDEOSTREAMING
)
1923 dev
->state
|= UVC_DEV_DISCONNECTED
;
1925 uvc_unregister_video(dev
);
1928 static int uvc_suspend(struct usb_interface
*intf
, pm_message_t message
)
1930 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1931 struct uvc_streaming
*stream
;
1933 uvc_trace(UVC_TRACE_SUSPEND
, "Suspending interface %u\n",
1934 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1936 /* Controls are cached on the fly so they don't need to be saved. */
1937 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1938 UVC_SC_VIDEOCONTROL
)
1939 return uvc_status_suspend(dev
);
1941 list_for_each_entry(stream
, &dev
->streams
, list
) {
1942 if (stream
->intf
== intf
)
1943 return uvc_video_suspend(stream
);
1946 uvc_trace(UVC_TRACE_SUSPEND
, "Suspend: video streaming USB interface "
1951 static int __uvc_resume(struct usb_interface
*intf
, int reset
)
1953 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1954 struct uvc_streaming
*stream
;
1956 uvc_trace(UVC_TRACE_SUSPEND
, "Resuming interface %u\n",
1957 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1959 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1960 UVC_SC_VIDEOCONTROL
) {
1962 int ret
= uvc_ctrl_resume_device(dev
);
1968 return uvc_status_resume(dev
);
1971 list_for_each_entry(stream
, &dev
->streams
, list
) {
1972 if (stream
->intf
== intf
)
1973 return uvc_video_resume(stream
, reset
);
1976 uvc_trace(UVC_TRACE_SUSPEND
, "Resume: video streaming USB interface "
1981 static int uvc_resume(struct usb_interface
*intf
)
1983 return __uvc_resume(intf
, 0);
1986 static int uvc_reset_resume(struct usb_interface
*intf
)
1988 return __uvc_resume(intf
, 1);
1991 /* ------------------------------------------------------------------------
1995 static int uvc_clock_param_get(char *buffer
, struct kernel_param
*kp
)
1997 if (uvc_clock_param
== CLOCK_MONOTONIC
)
1998 return sprintf(buffer
, "CLOCK_MONOTONIC");
2000 return sprintf(buffer
, "CLOCK_REALTIME");
2003 static int uvc_clock_param_set(const char *val
, struct kernel_param
*kp
)
2005 if (strncasecmp(val
, "clock_", strlen("clock_")) == 0)
2006 val
+= strlen("clock_");
2008 if (strcasecmp(val
, "monotonic") == 0)
2009 uvc_clock_param
= CLOCK_MONOTONIC
;
2010 else if (strcasecmp(val
, "realtime") == 0)
2011 uvc_clock_param
= CLOCK_REALTIME
;
2018 module_param_call(clock
, uvc_clock_param_set
, uvc_clock_param_get
,
2019 &uvc_clock_param
, S_IRUGO
|S_IWUSR
);
2020 MODULE_PARM_DESC(clock
, "Video buffers timestamp clock");
2021 module_param_named(nodrop
, uvc_no_drop_param
, uint
, S_IRUGO
|S_IWUSR
);
2022 MODULE_PARM_DESC(nodrop
, "Don't drop incomplete frames");
2023 module_param_named(quirks
, uvc_quirks_param
, uint
, S_IRUGO
|S_IWUSR
);
2024 MODULE_PARM_DESC(quirks
, "Forced device quirks");
2025 module_param_named(trace
, uvc_trace_param
, uint
, S_IRUGO
|S_IWUSR
);
2026 MODULE_PARM_DESC(trace
, "Trace level bitmask");
2027 module_param_named(timeout
, uvc_timeout_param
, uint
, S_IRUGO
|S_IWUSR
);
2028 MODULE_PARM_DESC(timeout
, "Streaming control requests timeout");
2030 /* ------------------------------------------------------------------------
2031 * Driver initialization and cleanup
2035 * The Logitech cameras listed below have their interface class set to
2036 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2037 * though they are compliant.
2039 static struct usb_device_id uvc_ids
[] = {
2040 /* LogiLink Wireless Webcam */
2041 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2042 | USB_DEVICE_ID_MATCH_INT_INFO
,
2044 .idProduct
= 0xa91a,
2045 .bInterfaceClass
= USB_CLASS_VIDEO
,
2046 .bInterfaceSubClass
= 1,
2047 .bInterfaceProtocol
= 0,
2048 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2049 /* Genius eFace 2025 */
2050 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2051 | USB_DEVICE_ID_MATCH_INT_INFO
,
2053 .idProduct
= 0x706e,
2054 .bInterfaceClass
= USB_CLASS_VIDEO
,
2055 .bInterfaceSubClass
= 1,
2056 .bInterfaceProtocol
= 0,
2057 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2058 /* Microsoft Lifecam NX-6000 */
2059 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2060 | USB_DEVICE_ID_MATCH_INT_INFO
,
2062 .idProduct
= 0x00f8,
2063 .bInterfaceClass
= USB_CLASS_VIDEO
,
2064 .bInterfaceSubClass
= 1,
2065 .bInterfaceProtocol
= 0,
2066 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2067 /* Microsoft Lifecam VX-7000 */
2068 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2069 | USB_DEVICE_ID_MATCH_INT_INFO
,
2071 .idProduct
= 0x0723,
2072 .bInterfaceClass
= USB_CLASS_VIDEO
,
2073 .bInterfaceSubClass
= 1,
2074 .bInterfaceProtocol
= 0,
2075 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2076 /* Logitech Quickcam Fusion */
2077 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2078 | USB_DEVICE_ID_MATCH_INT_INFO
,
2080 .idProduct
= 0x08c1,
2081 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2082 .bInterfaceSubClass
= 1,
2083 .bInterfaceProtocol
= 0 },
2084 /* Logitech Quickcam Orbit MP */
2085 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2086 | USB_DEVICE_ID_MATCH_INT_INFO
,
2088 .idProduct
= 0x08c2,
2089 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2090 .bInterfaceSubClass
= 1,
2091 .bInterfaceProtocol
= 0 },
2092 /* Logitech Quickcam Pro for Notebook */
2093 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2094 | USB_DEVICE_ID_MATCH_INT_INFO
,
2096 .idProduct
= 0x08c3,
2097 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2098 .bInterfaceSubClass
= 1,
2099 .bInterfaceProtocol
= 0 },
2100 /* Logitech Quickcam Pro 5000 */
2101 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2102 | USB_DEVICE_ID_MATCH_INT_INFO
,
2104 .idProduct
= 0x08c5,
2105 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2106 .bInterfaceSubClass
= 1,
2107 .bInterfaceProtocol
= 0 },
2108 /* Logitech Quickcam OEM Dell Notebook */
2109 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2110 | USB_DEVICE_ID_MATCH_INT_INFO
,
2112 .idProduct
= 0x08c6,
2113 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2114 .bInterfaceSubClass
= 1,
2115 .bInterfaceProtocol
= 0 },
2116 /* Logitech Quickcam OEM Cisco VT Camera II */
2117 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2118 | USB_DEVICE_ID_MATCH_INT_INFO
,
2120 .idProduct
= 0x08c7,
2121 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2122 .bInterfaceSubClass
= 1,
2123 .bInterfaceProtocol
= 0 },
2124 /* Chicony CNF7129 (Asus EEE 100HE) */
2125 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2126 | USB_DEVICE_ID_MATCH_INT_INFO
,
2128 .idProduct
= 0xb071,
2129 .bInterfaceClass
= USB_CLASS_VIDEO
,
2130 .bInterfaceSubClass
= 1,
2131 .bInterfaceProtocol
= 0,
2132 .driver_info
= UVC_QUIRK_RESTRICT_FRAME_RATE
},
2133 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2134 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2135 | USB_DEVICE_ID_MATCH_INT_INFO
,
2137 .idProduct
= 0x3820,
2138 .bInterfaceClass
= USB_CLASS_VIDEO
,
2139 .bInterfaceSubClass
= 1,
2140 .bInterfaceProtocol
= 0,
2141 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2142 /* Apple Built-In iSight */
2143 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2144 | USB_DEVICE_ID_MATCH_INT_INFO
,
2146 .idProduct
= 0x8501,
2147 .bInterfaceClass
= USB_CLASS_VIDEO
,
2148 .bInterfaceSubClass
= 1,
2149 .bInterfaceProtocol
= 0,
2150 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2151 | UVC_QUIRK_BUILTIN_ISIGHT
},
2152 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2153 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2154 | USB_DEVICE_ID_MATCH_INT_INFO
,
2156 .idProduct
= 0x0403,
2157 .bInterfaceClass
= USB_CLASS_VIDEO
,
2158 .bInterfaceSubClass
= 1,
2159 .bInterfaceProtocol
= 0,
2160 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2161 /* Genesys Logic USB 2.0 PC Camera */
2162 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2163 | USB_DEVICE_ID_MATCH_INT_INFO
,
2165 .idProduct
= 0x0505,
2166 .bInterfaceClass
= USB_CLASS_VIDEO
,
2167 .bInterfaceSubClass
= 1,
2168 .bInterfaceProtocol
= 0,
2169 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2170 /* Hercules Classic Silver */
2171 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2172 | USB_DEVICE_ID_MATCH_INT_INFO
,
2174 .idProduct
= 0x300c,
2175 .bInterfaceClass
= USB_CLASS_VIDEO
,
2176 .bInterfaceSubClass
= 1,
2177 .bInterfaceProtocol
= 0,
2178 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2180 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2181 | USB_DEVICE_ID_MATCH_INT_INFO
,
2183 .idProduct
= 0x332d,
2184 .bInterfaceClass
= USB_CLASS_VIDEO
,
2185 .bInterfaceSubClass
= 1,
2186 .bInterfaceProtocol
= 0,
2187 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2188 /* ViMicro - Minoru3D */
2189 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2190 | USB_DEVICE_ID_MATCH_INT_INFO
,
2192 .idProduct
= 0x3410,
2193 .bInterfaceClass
= USB_CLASS_VIDEO
,
2194 .bInterfaceSubClass
= 1,
2195 .bInterfaceProtocol
= 0,
2196 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2197 /* ViMicro Venus - Minoru3D */
2198 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2199 | USB_DEVICE_ID_MATCH_INT_INFO
,
2201 .idProduct
= 0x3420,
2202 .bInterfaceClass
= USB_CLASS_VIDEO
,
2203 .bInterfaceSubClass
= 1,
2204 .bInterfaceProtocol
= 0,
2205 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2207 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2208 | USB_DEVICE_ID_MATCH_INT_INFO
,
2210 .idProduct
= 0x0004,
2211 .bInterfaceClass
= USB_CLASS_VIDEO
,
2212 .bInterfaceSubClass
= 1,
2213 .bInterfaceProtocol
= 0,
2214 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2215 | UVC_QUIRK_PROBE_DEF
},
2216 /* IMC Networks (Medion Akoya) */
2217 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2218 | USB_DEVICE_ID_MATCH_INT_INFO
,
2220 .idProduct
= 0x5103,
2221 .bInterfaceClass
= USB_CLASS_VIDEO
,
2222 .bInterfaceSubClass
= 1,
2223 .bInterfaceProtocol
= 0,
2224 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2225 /* JMicron USB2.0 XGA WebCam */
2226 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2227 | USB_DEVICE_ID_MATCH_INT_INFO
,
2229 .idProduct
= 0x0310,
2230 .bInterfaceClass
= USB_CLASS_VIDEO
,
2231 .bInterfaceSubClass
= 1,
2232 .bInterfaceProtocol
= 0,
2233 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2234 /* Syntek (HP Spartan) */
2235 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2236 | USB_DEVICE_ID_MATCH_INT_INFO
,
2238 .idProduct
= 0x5212,
2239 .bInterfaceClass
= USB_CLASS_VIDEO
,
2240 .bInterfaceSubClass
= 1,
2241 .bInterfaceProtocol
= 0,
2242 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2243 /* Syntek (Samsung Q310) */
2244 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2245 | USB_DEVICE_ID_MATCH_INT_INFO
,
2247 .idProduct
= 0x5931,
2248 .bInterfaceClass
= USB_CLASS_VIDEO
,
2249 .bInterfaceSubClass
= 1,
2250 .bInterfaceProtocol
= 0,
2251 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2252 /* Syntek (Packard Bell EasyNote MX52 */
2253 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2254 | USB_DEVICE_ID_MATCH_INT_INFO
,
2256 .idProduct
= 0x8a12,
2257 .bInterfaceClass
= USB_CLASS_VIDEO
,
2258 .bInterfaceSubClass
= 1,
2259 .bInterfaceProtocol
= 0,
2260 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2261 /* Syntek (Asus F9SG) */
2262 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2263 | USB_DEVICE_ID_MATCH_INT_INFO
,
2265 .idProduct
= 0x8a31,
2266 .bInterfaceClass
= USB_CLASS_VIDEO
,
2267 .bInterfaceSubClass
= 1,
2268 .bInterfaceProtocol
= 0,
2269 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2270 /* Syntek (Asus U3S) */
2271 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2272 | USB_DEVICE_ID_MATCH_INT_INFO
,
2274 .idProduct
= 0x8a33,
2275 .bInterfaceClass
= USB_CLASS_VIDEO
,
2276 .bInterfaceSubClass
= 1,
2277 .bInterfaceProtocol
= 0,
2278 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2279 /* Syntek (JAOtech Smart Terminal) */
2280 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2281 | USB_DEVICE_ID_MATCH_INT_INFO
,
2283 .idProduct
= 0x8a34,
2284 .bInterfaceClass
= USB_CLASS_VIDEO
,
2285 .bInterfaceSubClass
= 1,
2286 .bInterfaceProtocol
= 0,
2287 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2289 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2290 | USB_DEVICE_ID_MATCH_INT_INFO
,
2292 .idProduct
= 0x0202,
2293 .bInterfaceClass
= USB_CLASS_VIDEO
,
2294 .bInterfaceSubClass
= 1,
2295 .bInterfaceProtocol
= 0,
2296 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2297 /* Lenovo Thinkpad SL400/SL500 */
2298 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2299 | USB_DEVICE_ID_MATCH_INT_INFO
,
2301 .idProduct
= 0x480b,
2302 .bInterfaceClass
= USB_CLASS_VIDEO
,
2303 .bInterfaceSubClass
= 1,
2304 .bInterfaceProtocol
= 0,
2305 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2306 /* Aveo Technology USB 2.0 Camera */
2307 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2308 | USB_DEVICE_ID_MATCH_INT_INFO
,
2310 .idProduct
= 0x0306,
2311 .bInterfaceClass
= USB_CLASS_VIDEO
,
2312 .bInterfaceSubClass
= 1,
2313 .bInterfaceProtocol
= 0,
2314 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2315 | UVC_QUIRK_PROBE_EXTRAFIELDS
},
2316 /* Ecamm Pico iMage */
2317 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2318 | USB_DEVICE_ID_MATCH_INT_INFO
,
2320 .idProduct
= 0xcafe,
2321 .bInterfaceClass
= USB_CLASS_VIDEO
,
2322 .bInterfaceSubClass
= 1,
2323 .bInterfaceProtocol
= 0,
2324 .driver_info
= UVC_QUIRK_PROBE_EXTRAFIELDS
},
2325 /* Manta MM-353 Plako */
2326 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2327 | USB_DEVICE_ID_MATCH_INT_INFO
,
2329 .idProduct
= 0x3188,
2330 .bInterfaceClass
= USB_CLASS_VIDEO
,
2331 .bInterfaceSubClass
= 1,
2332 .bInterfaceProtocol
= 0,
2333 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2334 /* FSC WebCam V30S */
2335 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2336 | USB_DEVICE_ID_MATCH_INT_INFO
,
2338 .idProduct
= 0x3288,
2339 .bInterfaceClass
= USB_CLASS_VIDEO
,
2340 .bInterfaceSubClass
= 1,
2341 .bInterfaceProtocol
= 0,
2342 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2343 /* Arkmicro unbranded */
2344 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2345 | USB_DEVICE_ID_MATCH_INT_INFO
,
2347 .idProduct
= 0x3290,
2348 .bInterfaceClass
= USB_CLASS_VIDEO
,
2349 .bInterfaceSubClass
= 1,
2350 .bInterfaceProtocol
= 0,
2351 .driver_info
= UVC_QUIRK_PROBE_DEF
},
2352 /* The Imaging Source USB CCD cameras */
2353 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2354 | USB_DEVICE_ID_MATCH_INT_INFO
,
2356 .idProduct
= 0x8102,
2357 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2358 .bInterfaceSubClass
= 1,
2359 .bInterfaceProtocol
= 0 },
2360 /* Bodelin ProScopeHR */
2361 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2362 | USB_DEVICE_ID_MATCH_DEV_HI
2363 | USB_DEVICE_ID_MATCH_INT_INFO
,
2365 .idProduct
= 0x1000,
2366 .bcdDevice_hi
= 0x0126,
2367 .bInterfaceClass
= USB_CLASS_VIDEO
,
2368 .bInterfaceSubClass
= 1,
2369 .bInterfaceProtocol
= 0,
2370 .driver_info
= UVC_QUIRK_STATUS_INTERVAL
},
2371 /* MSI StarCam 370i */
2372 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2373 | USB_DEVICE_ID_MATCH_INT_INFO
,
2375 .idProduct
= 0x2951,
2376 .bInterfaceClass
= USB_CLASS_VIDEO
,
2377 .bInterfaceSubClass
= 1,
2378 .bInterfaceProtocol
= 0,
2379 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2380 /* SiGma Micro USB Web Camera */
2381 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2382 | USB_DEVICE_ID_MATCH_INT_INFO
,
2384 .idProduct
= 0x3000,
2385 .bInterfaceClass
= USB_CLASS_VIDEO
,
2386 .bInterfaceSubClass
= 1,
2387 .bInterfaceProtocol
= 0,
2388 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2389 | UVC_QUIRK_IGNORE_SELECTOR_UNIT
},
2390 /* Generic USB Video Class */
2391 { USB_INTERFACE_INFO(USB_CLASS_VIDEO
, 1, 0) },
2395 MODULE_DEVICE_TABLE(usb
, uvc_ids
);
2397 struct uvc_driver uvc_driver
= {
2401 .disconnect
= uvc_disconnect
,
2402 .suspend
= uvc_suspend
,
2403 .resume
= uvc_resume
,
2404 .reset_resume
= uvc_reset_resume
,
2405 .id_table
= uvc_ids
,
2406 .supports_autosuspend
= 1,
2410 static int __init
uvc_init(void)
2416 ret
= usb_register(&uvc_driver
.driver
);
2418 uvc_debugfs_cleanup();
2422 printk(KERN_INFO DRIVER_DESC
" (" DRIVER_VERSION
")\n");
2426 static void __exit
uvc_cleanup(void)
2428 usb_deregister(&uvc_driver
.driver
);
2429 uvc_debugfs_cleanup();
2432 module_init(uvc_init
);
2433 module_exit(uvc_cleanup
);
2435 MODULE_AUTHOR(DRIVER_AUTHOR
);
2436 MODULE_DESCRIPTION(DRIVER_DESC
);
2437 MODULE_LICENSE("GPL");
2438 MODULE_VERSION(DRIVER_VERSION
);