2 * uvc_driver.c -- USB Video Class driver
4 * Copyright (C) 2005-2009
5 * Laurent Pinchart (laurent.pinchart@skynet.be)
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/usb.h>
30 #include <linux/videodev2.h>
31 #include <linux/vmalloc.h>
32 #include <linux/wait.h>
33 #include <asm/atomic.h>
34 #include <asm/unaligned.h>
36 #include <media/v4l2-common.h>
40 #define DRIVER_AUTHOR "Laurent Pinchart <laurent.pinchart@skynet.be>"
41 #define DRIVER_DESC "USB Video Class driver"
42 #ifndef DRIVER_VERSION
43 #define DRIVER_VERSION "v0.1.0"
46 unsigned int uvc_no_drop_param
;
47 static unsigned int uvc_quirks_param
;
48 unsigned int uvc_trace_param
;
50 /* ------------------------------------------------------------------------
54 static struct uvc_format_desc uvc_fmts
[] = {
56 .name
= "YUV 4:2:2 (YUYV)",
57 .guid
= UVC_GUID_FORMAT_YUY2
,
58 .fcc
= V4L2_PIX_FMT_YUYV
,
61 .name
= "YUV 4:2:0 (NV12)",
62 .guid
= UVC_GUID_FORMAT_NV12
,
63 .fcc
= V4L2_PIX_FMT_NV12
,
67 .guid
= UVC_GUID_FORMAT_MJPEG
,
68 .fcc
= V4L2_PIX_FMT_MJPEG
,
71 .name
= "YVU 4:2:0 (YV12)",
72 .guid
= UVC_GUID_FORMAT_YV12
,
73 .fcc
= V4L2_PIX_FMT_YVU420
,
76 .name
= "YUV 4:2:0 (I420)",
77 .guid
= UVC_GUID_FORMAT_I420
,
78 .fcc
= V4L2_PIX_FMT_YUV420
,
81 .name
= "YUV 4:2:2 (UYVY)",
82 .guid
= UVC_GUID_FORMAT_UYVY
,
83 .fcc
= V4L2_PIX_FMT_UYVY
,
87 .guid
= UVC_GUID_FORMAT_Y800
,
88 .fcc
= V4L2_PIX_FMT_GREY
,
92 .guid
= UVC_GUID_FORMAT_BY8
,
93 .fcc
= V4L2_PIX_FMT_SBGGR8
,
97 /* ------------------------------------------------------------------------
101 struct usb_host_endpoint
*uvc_find_endpoint(struct usb_host_interface
*alts
,
104 struct usb_host_endpoint
*ep
;
107 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
108 ep
= &alts
->endpoint
[i
];
109 if (ep
->desc
.bEndpointAddress
== epaddr
)
116 static struct uvc_format_desc
*uvc_format_by_guid(const __u8 guid
[16])
118 unsigned int len
= ARRAY_SIZE(uvc_fmts
);
121 for (i
= 0; i
< len
; ++i
) {
122 if (memcmp(guid
, uvc_fmts
[i
].guid
, 16) == 0)
129 static __u32
uvc_colorspace(const __u8 primaries
)
131 static const __u8 colorprimaries
[] = {
133 V4L2_COLORSPACE_SRGB
,
134 V4L2_COLORSPACE_470_SYSTEM_M
,
135 V4L2_COLORSPACE_470_SYSTEM_BG
,
136 V4L2_COLORSPACE_SMPTE170M
,
137 V4L2_COLORSPACE_SMPTE240M
,
140 if (primaries
< ARRAY_SIZE(colorprimaries
))
141 return colorprimaries
[primaries
];
146 /* Simplify a fraction using a simple continued fraction decomposition. The
147 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
148 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
149 * arbitrary parameters to remove non-significative terms from the simple
150 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
151 * respectively seems to give nice results.
153 void uvc_simplify_fraction(uint32_t *numerator
, uint32_t *denominator
,
154 unsigned int n_terms
, unsigned int threshold
)
160 an
= kmalloc(n_terms
* sizeof *an
, GFP_KERNEL
);
164 /* Convert the fraction to a simple continued fraction. See
165 * http://mathforum.org/dr.math/faq/faq.fractions.html
166 * Stop if the current term is bigger than or equal to the given
172 for (n
= 0; n
< n_terms
&& y
!= 0; ++n
) {
174 if (an
[n
] >= threshold
) {
185 /* Expand the simple continued fraction back to an integer fraction. */
189 for (i
= n
; i
> 0; --i
) {
200 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
201 * to compute numerator / denominator * 10000000 using 32 bit fixed point
204 uint32_t uvc_fraction_to_interval(uint32_t numerator
, uint32_t denominator
)
208 /* Saturate the result if the operation would overflow. */
209 if (denominator
== 0 ||
210 numerator
/denominator
>= ((uint32_t)-1)/10000000)
213 /* Divide both the denominator and the multiplier by two until
214 * numerator * multiplier doesn't overflow. If anyone knows a better
215 * algorithm please let me know.
217 multiplier
= 10000000;
218 while (numerator
> ((uint32_t)-1)/multiplier
) {
223 return denominator
? numerator
* multiplier
/ denominator
: 0;
226 /* ------------------------------------------------------------------------
227 * Terminal and unit management
230 static struct uvc_entity
*uvc_entity_by_id(struct uvc_device
*dev
, int id
)
232 struct uvc_entity
*entity
;
234 list_for_each_entry(entity
, &dev
->entities
, list
) {
235 if (entity
->id
== id
)
242 static struct uvc_entity
*uvc_entity_by_reference(struct uvc_device
*dev
,
243 int id
, struct uvc_entity
*entity
)
248 entity
= list_entry(&dev
->entities
, struct uvc_entity
, list
);
250 list_for_each_entry_continue(entity
, &dev
->entities
, list
) {
251 switch (UVC_ENTITY_TYPE(entity
)) {
252 case UVC_TT_STREAMING
:
253 if (entity
->output
.bSourceID
== id
)
257 case UVC_VC_PROCESSING_UNIT
:
258 if (entity
->processing
.bSourceID
== id
)
262 case UVC_VC_SELECTOR_UNIT
:
263 for (i
= 0; i
< entity
->selector
.bNrInPins
; ++i
)
264 if (entity
->selector
.baSourceID
[i
] == id
)
268 case UVC_VC_EXTENSION_UNIT
:
269 for (i
= 0; i
< entity
->extension
.bNrInPins
; ++i
)
270 if (entity
->extension
.baSourceID
[i
] == id
)
279 static struct uvc_streaming
*uvc_stream_by_id(struct uvc_device
*dev
, int id
)
281 struct uvc_streaming
*stream
;
283 list_for_each_entry(stream
, &dev
->streams
, list
) {
284 if (stream
->header
.bTerminalLink
== id
)
291 /* ------------------------------------------------------------------------
292 * Descriptors parsing
295 static int uvc_parse_format(struct uvc_device
*dev
,
296 struct uvc_streaming
*streaming
, struct uvc_format
*format
,
297 __u32
**intervals
, unsigned char *buffer
, int buflen
)
299 struct usb_interface
*intf
= streaming
->intf
;
300 struct usb_host_interface
*alts
= intf
->cur_altsetting
;
301 struct uvc_format_desc
*fmtdesc
;
302 struct uvc_frame
*frame
;
303 const unsigned char *start
= buffer
;
304 unsigned int interval
;
308 format
->type
= buffer
[2];
309 format
->index
= buffer
[3];
312 case UVC_VS_FORMAT_UNCOMPRESSED
:
313 case UVC_VS_FORMAT_FRAME_BASED
:
314 n
= buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
? 27 : 28;
316 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
317 "interface %d FORMAT error\n",
319 alts
->desc
.bInterfaceNumber
);
323 /* Find the format descriptor from its GUID. */
324 fmtdesc
= uvc_format_by_guid(&buffer
[5]);
326 if (fmtdesc
!= NULL
) {
327 strlcpy(format
->name
, fmtdesc
->name
,
328 sizeof format
->name
);
329 format
->fcc
= fmtdesc
->fcc
;
331 uvc_printk(KERN_INFO
, "Unknown video format "
332 UVC_GUID_FORMAT
"\n",
333 UVC_GUID_ARGS(&buffer
[5]));
334 snprintf(format
->name
, sizeof format
->name
,
335 UVC_GUID_FORMAT
, UVC_GUID_ARGS(&buffer
[5]));
339 format
->bpp
= buffer
[21];
340 if (buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
) {
341 ftype
= UVC_VS_FRAME_UNCOMPRESSED
;
343 ftype
= UVC_VS_FRAME_FRAME_BASED
;
345 format
->flags
= UVC_FMT_FLAG_COMPRESSED
;
349 case UVC_VS_FORMAT_MJPEG
:
351 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
352 "interface %d FORMAT error\n",
354 alts
->desc
.bInterfaceNumber
);
358 strlcpy(format
->name
, "MJPEG", sizeof format
->name
);
359 format
->fcc
= V4L2_PIX_FMT_MJPEG
;
360 format
->flags
= UVC_FMT_FLAG_COMPRESSED
;
362 ftype
= UVC_VS_FRAME_MJPEG
;
365 case UVC_VS_FORMAT_DV
:
367 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
368 "interface %d FORMAT error\n",
370 alts
->desc
.bInterfaceNumber
);
374 switch (buffer
[8] & 0x7f) {
376 strlcpy(format
->name
, "SD-DV", sizeof format
->name
);
379 strlcpy(format
->name
, "SDL-DV", sizeof format
->name
);
382 strlcpy(format
->name
, "HD-DV", sizeof format
->name
);
385 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
386 "interface %d: unknown DV format %u\n",
388 alts
->desc
.bInterfaceNumber
, buffer
[8]);
392 strlcat(format
->name
, buffer
[8] & (1 << 7) ? " 60Hz" : " 50Hz",
393 sizeof format
->name
);
395 format
->fcc
= V4L2_PIX_FMT_DV
;
396 format
->flags
= UVC_FMT_FLAG_COMPRESSED
| UVC_FMT_FLAG_STREAM
;
400 /* Create a dummy frame descriptor. */
401 frame
= &format
->frame
[0];
402 memset(&format
->frame
[0], 0, sizeof format
->frame
[0]);
403 frame
->bFrameIntervalType
= 1;
404 frame
->dwDefaultFrameInterval
= 1;
405 frame
->dwFrameInterval
= *intervals
;
410 case UVC_VS_FORMAT_MPEG2TS
:
411 case UVC_VS_FORMAT_STREAM_BASED
:
412 /* Not supported yet. */
414 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
415 "interface %d unsupported format %u\n",
416 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
,
421 uvc_trace(UVC_TRACE_DESCR
, "Found format %s.\n", format
->name
);
426 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
427 * based formats have frame descriptors.
429 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
430 buffer
[2] == ftype
) {
431 frame
= &format
->frame
[format
->nframes
];
432 if (ftype
!= UVC_VS_FRAME_FRAME_BASED
)
433 n
= buflen
> 25 ? buffer
[25] : 0;
435 n
= buflen
> 21 ? buffer
[21] : 0;
439 if (buflen
< 26 + 4*n
) {
440 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
441 "interface %d FRAME error\n", dev
->udev
->devnum
,
442 alts
->desc
.bInterfaceNumber
);
446 frame
->bFrameIndex
= buffer
[3];
447 frame
->bmCapabilities
= buffer
[4];
448 frame
->wWidth
= get_unaligned_le16(&buffer
[5]);
449 frame
->wHeight
= get_unaligned_le16(&buffer
[7]);
450 frame
->dwMinBitRate
= get_unaligned_le32(&buffer
[9]);
451 frame
->dwMaxBitRate
= get_unaligned_le32(&buffer
[13]);
452 if (ftype
!= UVC_VS_FRAME_FRAME_BASED
) {
453 frame
->dwMaxVideoFrameBufferSize
=
454 get_unaligned_le32(&buffer
[17]);
455 frame
->dwDefaultFrameInterval
=
456 get_unaligned_le32(&buffer
[21]);
457 frame
->bFrameIntervalType
= buffer
[25];
459 frame
->dwMaxVideoFrameBufferSize
= 0;
460 frame
->dwDefaultFrameInterval
=
461 get_unaligned_le32(&buffer
[17]);
462 frame
->bFrameIntervalType
= buffer
[21];
464 frame
->dwFrameInterval
= *intervals
;
466 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
467 * completely. Observed behaviours range from setting the
468 * value to 1.1x the actual frame size to hardwiring the
469 * 16 low bits to 0. This results in a higher than necessary
470 * memory usage as well as a wrong image size information. For
471 * uncompressed formats this can be fixed by computing the
472 * value from the frame size.
474 if (!(format
->flags
& UVC_FMT_FLAG_COMPRESSED
))
475 frame
->dwMaxVideoFrameBufferSize
= format
->bpp
476 * frame
->wWidth
* frame
->wHeight
/ 8;
478 /* Some bogus devices report dwMinFrameInterval equal to
479 * dwMaxFrameInterval and have dwFrameIntervalStep set to
480 * zero. Setting all null intervals to 1 fixes the problem and
481 * some other divisions by zero that could happen.
483 for (i
= 0; i
< n
; ++i
) {
484 interval
= get_unaligned_le32(&buffer
[26+4*i
]);
485 *(*intervals
)++ = interval
? interval
: 1;
488 /* Make sure that the default frame interval stays between
491 n
-= frame
->bFrameIntervalType
? 1 : 2;
492 frame
->dwDefaultFrameInterval
=
493 min(frame
->dwFrameInterval
[n
],
494 max(frame
->dwFrameInterval
[0],
495 frame
->dwDefaultFrameInterval
));
497 uvc_trace(UVC_TRACE_DESCR
, "- %ux%u (%u.%u fps)\n",
498 frame
->wWidth
, frame
->wHeight
,
499 10000000/frame
->dwDefaultFrameInterval
,
500 (100000000/frame
->dwDefaultFrameInterval
)%10);
507 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
508 buffer
[2] == UVC_VS_STILL_IMAGE_FRAME
) {
513 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
514 buffer
[2] == UVC_VS_COLORFORMAT
) {
516 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
517 "interface %d COLORFORMAT error\n",
519 alts
->desc
.bInterfaceNumber
);
523 format
->colorspace
= uvc_colorspace(buffer
[3]);
529 return buffer
- start
;
532 static int uvc_parse_streaming(struct uvc_device
*dev
,
533 struct usb_interface
*intf
)
535 struct uvc_streaming
*streaming
= NULL
;
536 struct uvc_format
*format
;
537 struct uvc_frame
*frame
;
538 struct usb_host_interface
*alts
= &intf
->altsetting
[0];
539 unsigned char *_buffer
, *buffer
= alts
->extra
;
540 int _buflen
, buflen
= alts
->extralen
;
541 unsigned int nformats
= 0, nframes
= 0, nintervals
= 0;
542 unsigned int size
, i
, n
, p
;
547 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
548 != UVC_SC_VIDEOSTREAMING
) {
549 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d isn't a "
550 "video streaming interface\n", dev
->udev
->devnum
,
551 intf
->altsetting
[0].desc
.bInterfaceNumber
);
555 if (usb_driver_claim_interface(&uvc_driver
.driver
, intf
, dev
)) {
556 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d is already "
557 "claimed\n", dev
->udev
->devnum
,
558 intf
->altsetting
[0].desc
.bInterfaceNumber
);
562 streaming
= kzalloc(sizeof *streaming
, GFP_KERNEL
);
563 if (streaming
== NULL
) {
564 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
568 mutex_init(&streaming
->mutex
);
569 streaming
->dev
= dev
;
570 streaming
->intf
= usb_get_intf(intf
);
571 streaming
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
573 /* The Pico iMage webcam has its class-specific interface descriptors
574 * after the endpoint descriptors.
577 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
578 struct usb_host_endpoint
*ep
= &alts
->endpoint
[i
];
580 if (ep
->extralen
== 0)
583 if (ep
->extralen
> 2 &&
584 ep
->extra
[1] == USB_DT_CS_INTERFACE
) {
585 uvc_trace(UVC_TRACE_DESCR
, "trying extra data "
586 "from endpoint %u.\n", i
);
587 buffer
= alts
->endpoint
[i
].extra
;
588 buflen
= alts
->endpoint
[i
].extralen
;
594 /* Skip the standard interface descriptors. */
595 while (buflen
> 2 && buffer
[1] != USB_DT_CS_INTERFACE
) {
601 uvc_trace(UVC_TRACE_DESCR
, "no class-specific streaming "
602 "interface descriptors found.\n");
606 /* Parse the header descriptor. */
608 case UVC_VS_OUTPUT_HEADER
:
609 streaming
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
613 case UVC_VS_INPUT_HEADER
:
614 streaming
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
619 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
620 "%d HEADER descriptor not found.\n", dev
->udev
->devnum
,
621 alts
->desc
.bInterfaceNumber
);
625 p
= buflen
>= 4 ? buffer
[3] : 0;
626 n
= buflen
>= size
? buffer
[size
-1] : 0;
628 if (buflen
< size
+ p
*n
) {
629 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
630 "interface %d HEADER descriptor is invalid.\n",
631 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
635 streaming
->header
.bNumFormats
= p
;
636 streaming
->header
.bEndpointAddress
= buffer
[6];
637 if (buffer
[2] == UVC_VS_INPUT_HEADER
) {
638 streaming
->header
.bmInfo
= buffer
[7];
639 streaming
->header
.bTerminalLink
= buffer
[8];
640 streaming
->header
.bStillCaptureMethod
= buffer
[9];
641 streaming
->header
.bTriggerSupport
= buffer
[10];
642 streaming
->header
.bTriggerUsage
= buffer
[11];
644 streaming
->header
.bTerminalLink
= buffer
[7];
646 streaming
->header
.bControlSize
= n
;
648 streaming
->header
.bmaControls
= kmalloc(p
*n
, GFP_KERNEL
);
649 if (streaming
->header
.bmaControls
== NULL
) {
654 memcpy(streaming
->header
.bmaControls
, &buffer
[size
], p
*n
);
662 /* Count the format and frame descriptors. */
663 while (_buflen
> 2 && _buffer
[1] == USB_DT_CS_INTERFACE
) {
664 switch (_buffer
[2]) {
665 case UVC_VS_FORMAT_UNCOMPRESSED
:
666 case UVC_VS_FORMAT_MJPEG
:
667 case UVC_VS_FORMAT_FRAME_BASED
:
671 case UVC_VS_FORMAT_DV
:
672 /* DV format has no frame descriptor. We will create a
673 * dummy frame descriptor with a dummy frame interval.
680 case UVC_VS_FORMAT_MPEG2TS
:
681 case UVC_VS_FORMAT_STREAM_BASED
:
682 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
683 "interface %d FORMAT %u is not supported.\n",
685 alts
->desc
.bInterfaceNumber
, _buffer
[2]);
688 case UVC_VS_FRAME_UNCOMPRESSED
:
689 case UVC_VS_FRAME_MJPEG
:
692 nintervals
+= _buffer
[25] ? _buffer
[25] : 3;
695 case UVC_VS_FRAME_FRAME_BASED
:
698 nintervals
+= _buffer
[21] ? _buffer
[21] : 3;
702 _buflen
-= _buffer
[0];
703 _buffer
+= _buffer
[0];
707 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
708 "%d has no supported formats defined.\n",
709 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
713 size
= nformats
* sizeof *format
+ nframes
* sizeof *frame
714 + nintervals
* sizeof *interval
;
715 format
= kzalloc(size
, GFP_KERNEL
);
716 if (format
== NULL
) {
721 frame
= (struct uvc_frame
*)&format
[nformats
];
722 interval
= (__u32
*)&frame
[nframes
];
724 streaming
->format
= format
;
725 streaming
->nformats
= nformats
;
727 /* Parse the format descriptors. */
728 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
) {
730 case UVC_VS_FORMAT_UNCOMPRESSED
:
731 case UVC_VS_FORMAT_MJPEG
:
732 case UVC_VS_FORMAT_DV
:
733 case UVC_VS_FORMAT_FRAME_BASED
:
734 format
->frame
= frame
;
735 ret
= uvc_parse_format(dev
, streaming
, format
,
736 &interval
, buffer
, buflen
);
740 frame
+= format
->nframes
;
756 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
757 "%d has %u bytes of trailing descriptor garbage.\n",
758 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
, buflen
);
760 /* Parse the alternate settings to find the maximum bandwidth. */
761 for (i
= 0; i
< intf
->num_altsetting
; ++i
) {
762 struct usb_host_endpoint
*ep
;
763 alts
= &intf
->altsetting
[i
];
764 ep
= uvc_find_endpoint(alts
,
765 streaming
->header
.bEndpointAddress
);
769 psize
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
770 psize
= (psize
& 0x07ff) * (1 + ((psize
>> 11) & 3));
771 if (psize
> streaming
->maxpsize
)
772 streaming
->maxpsize
= psize
;
775 list_add_tail(&streaming
->list
, &dev
->streams
);
779 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
781 kfree(streaming
->format
);
782 kfree(streaming
->header
.bmaControls
);
787 /* Parse vendor-specific extensions. */
788 static int uvc_parse_vendor_control(struct uvc_device
*dev
,
789 const unsigned char *buffer
, int buflen
)
791 struct usb_device
*udev
= dev
->udev
;
792 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
793 struct uvc_entity
*unit
;
797 switch (le16_to_cpu(dev
->udev
->descriptor
.idVendor
)) {
798 case 0x046d: /* Logitech */
799 if (buffer
[1] != 0x41 || buffer
[2] != 0x01)
802 /* Logitech implements several vendor specific functions
803 * through vendor specific extension units (LXU).
805 * The LXU descriptors are similar to XU descriptors
806 * (see "USB Device Video Class for Video Devices", section
807 * 3.7.2.6 "Extension Unit Descriptor") with the following
810 * ----------------------------------------------------------
812 * Size of this descriptor, in bytes: 24+p+n*2
813 * ----------------------------------------------------------
814 * 23+p+n bmControlsType N Bitmap
815 * Individual bits in the set are defined:
819 * This bitset is mapped exactly the same as bmControls.
820 * ----------------------------------------------------------
821 * 23+p+n*2 bReserved 1 Boolean
822 * ----------------------------------------------------------
823 * 24+p+n*2 iExtension 1 Index
824 * Index of a string descriptor that describes this
826 * ----------------------------------------------------------
828 p
= buflen
>= 22 ? buffer
[21] : 0;
829 n
= buflen
>= 25 + p
? buffer
[22+p
] : 0;
831 if (buflen
< 25 + p
+ 2*n
) {
832 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
833 "interface %d EXTENSION_UNIT error\n",
834 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
838 unit
= kzalloc(sizeof *unit
+ p
+ 2*n
, GFP_KERNEL
);
842 unit
->id
= buffer
[3];
843 unit
->type
= UVC_VC_EXTENSION_UNIT
;
844 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
845 unit
->extension
.bNumControls
= buffer
[20];
846 unit
->extension
.bNrInPins
= get_unaligned_le16(&buffer
[21]);
847 unit
->extension
.baSourceID
= (__u8
*)unit
+ sizeof *unit
;
848 memcpy(unit
->extension
.baSourceID
, &buffer
[22], p
);
849 unit
->extension
.bControlSize
= buffer
[22+p
];
850 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof *unit
+ p
;
851 unit
->extension
.bmControlsType
= (__u8
*)unit
+ sizeof *unit
853 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], 2*n
);
855 if (buffer
[24+p
+2*n
] != 0)
856 usb_string(udev
, buffer
[24+p
+2*n
], unit
->name
,
859 sprintf(unit
->name
, "Extension %u", buffer
[3]);
861 list_add_tail(&unit
->list
, &dev
->entities
);
869 static int uvc_parse_standard_control(struct uvc_device
*dev
,
870 const unsigned char *buffer
, int buflen
)
872 struct usb_device
*udev
= dev
->udev
;
873 struct uvc_entity
*unit
, *term
;
874 struct usb_interface
*intf
;
875 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
876 unsigned int i
, n
, p
, len
;
881 n
= buflen
>= 12 ? buffer
[11] : 0;
883 if (buflen
< 12 || buflen
< 12 + n
) {
884 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
885 "interface %d HEADER error\n", udev
->devnum
,
886 alts
->desc
.bInterfaceNumber
);
890 dev
->uvc_version
= get_unaligned_le16(&buffer
[3]);
891 dev
->clock_frequency
= get_unaligned_le32(&buffer
[7]);
893 /* Parse all USB Video Streaming interfaces. */
894 for (i
= 0; i
< n
; ++i
) {
895 intf
= usb_ifnum_to_if(udev
, buffer
[12+i
]);
897 uvc_trace(UVC_TRACE_DESCR
, "device %d "
898 "interface %d doesn't exists\n",
903 uvc_parse_streaming(dev
, intf
);
907 case UVC_VC_INPUT_TERMINAL
:
909 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
910 "interface %d INPUT_TERMINAL error\n",
911 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
915 /* Make sure the terminal type MSB is not null, otherwise it
916 * could be confused with a unit.
918 type
= get_unaligned_le16(&buffer
[4]);
919 if ((type
& 0xff00) == 0) {
920 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
921 "interface %d INPUT_TERMINAL %d has invalid "
922 "type 0x%04x, skipping\n", udev
->devnum
,
923 alts
->desc
.bInterfaceNumber
,
932 if (type
== UVC_ITT_CAMERA
) {
933 n
= buflen
>= 15 ? buffer
[14] : 0;
936 } else if (type
== UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
937 n
= buflen
>= 9 ? buffer
[8] : 0;
938 p
= buflen
>= 10 + n
? buffer
[9+n
] : 0;
942 if (buflen
< len
+ n
+ p
) {
943 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
944 "interface %d INPUT_TERMINAL error\n",
945 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
949 term
= kzalloc(sizeof *term
+ n
+ p
, GFP_KERNEL
);
953 term
->id
= buffer
[3];
954 term
->type
= type
| UVC_TERM_INPUT
;
956 if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
) {
957 term
->camera
.bControlSize
= n
;
958 term
->camera
.bmControls
= (__u8
*)term
+ sizeof *term
;
959 term
->camera
.wObjectiveFocalLengthMin
=
960 get_unaligned_le16(&buffer
[8]);
961 term
->camera
.wObjectiveFocalLengthMax
=
962 get_unaligned_le16(&buffer
[10]);
963 term
->camera
.wOcularFocalLength
=
964 get_unaligned_le16(&buffer
[12]);
965 memcpy(term
->camera
.bmControls
, &buffer
[15], n
);
966 } else if (UVC_ENTITY_TYPE(term
) ==
967 UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
968 term
->media
.bControlSize
= n
;
969 term
->media
.bmControls
= (__u8
*)term
+ sizeof *term
;
970 term
->media
.bTransportModeSize
= p
;
971 term
->media
.bmTransportModes
= (__u8
*)term
973 memcpy(term
->media
.bmControls
, &buffer
[9], n
);
974 memcpy(term
->media
.bmTransportModes
, &buffer
[10+n
], p
);
978 usb_string(udev
, buffer
[7], term
->name
,
980 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
)
981 sprintf(term
->name
, "Camera %u", buffer
[3]);
982 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_MEDIA_TRANSPORT_INPUT
)
983 sprintf(term
->name
, "Media %u", buffer
[3]);
985 sprintf(term
->name
, "Input %u", buffer
[3]);
987 list_add_tail(&term
->list
, &dev
->entities
);
990 case UVC_VC_OUTPUT_TERMINAL
:
992 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
993 "interface %d OUTPUT_TERMINAL error\n",
994 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
998 /* Make sure the terminal type MSB is not null, otherwise it
999 * could be confused with a unit.
1001 type
= get_unaligned_le16(&buffer
[4]);
1002 if ((type
& 0xff00) == 0) {
1003 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1004 "interface %d OUTPUT_TERMINAL %d has invalid "
1005 "type 0x%04x, skipping\n", udev
->devnum
,
1006 alts
->desc
.bInterfaceNumber
, buffer
[3], type
);
1010 term
= kzalloc(sizeof *term
, GFP_KERNEL
);
1014 term
->id
= buffer
[3];
1015 term
->type
= type
| UVC_TERM_OUTPUT
;
1016 term
->output
.bSourceID
= buffer
[7];
1019 usb_string(udev
, buffer
[8], term
->name
,
1022 sprintf(term
->name
, "Output %u", buffer
[3]);
1024 list_add_tail(&term
->list
, &dev
->entities
);
1027 case UVC_VC_SELECTOR_UNIT
:
1028 p
= buflen
>= 5 ? buffer
[4] : 0;
1030 if (buflen
< 5 || buflen
< 6 + p
) {
1031 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1032 "interface %d SELECTOR_UNIT error\n",
1033 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1037 unit
= kzalloc(sizeof *unit
+ p
, GFP_KERNEL
);
1041 unit
->id
= buffer
[3];
1042 unit
->type
= buffer
[2];
1043 unit
->selector
.bNrInPins
= buffer
[4];
1044 unit
->selector
.baSourceID
= (__u8
*)unit
+ sizeof *unit
;
1045 memcpy(unit
->selector
.baSourceID
, &buffer
[5], p
);
1047 if (buffer
[5+p
] != 0)
1048 usb_string(udev
, buffer
[5+p
], unit
->name
,
1051 sprintf(unit
->name
, "Selector %u", buffer
[3]);
1053 list_add_tail(&unit
->list
, &dev
->entities
);
1056 case UVC_VC_PROCESSING_UNIT
:
1057 n
= buflen
>= 8 ? buffer
[7] : 0;
1058 p
= dev
->uvc_version
>= 0x0110 ? 10 : 9;
1060 if (buflen
< p
+ n
) {
1061 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1062 "interface %d PROCESSING_UNIT error\n",
1063 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1067 unit
= kzalloc(sizeof *unit
+ n
, GFP_KERNEL
);
1071 unit
->id
= buffer
[3];
1072 unit
->type
= buffer
[2];
1073 unit
->processing
.bSourceID
= buffer
[4];
1074 unit
->processing
.wMaxMultiplier
=
1075 get_unaligned_le16(&buffer
[5]);
1076 unit
->processing
.bControlSize
= buffer
[7];
1077 unit
->processing
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1078 memcpy(unit
->processing
.bmControls
, &buffer
[8], n
);
1079 if (dev
->uvc_version
>= 0x0110)
1080 unit
->processing
.bmVideoStandards
= buffer
[9+n
];
1082 if (buffer
[8+n
] != 0)
1083 usb_string(udev
, buffer
[8+n
], unit
->name
,
1086 sprintf(unit
->name
, "Processing %u", buffer
[3]);
1088 list_add_tail(&unit
->list
, &dev
->entities
);
1091 case UVC_VC_EXTENSION_UNIT
:
1092 p
= buflen
>= 22 ? buffer
[21] : 0;
1093 n
= buflen
>= 24 + p
? buffer
[22+p
] : 0;
1095 if (buflen
< 24 + p
+ n
) {
1096 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1097 "interface %d EXTENSION_UNIT error\n",
1098 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1102 unit
= kzalloc(sizeof *unit
+ p
+ n
, GFP_KERNEL
);
1106 unit
->id
= buffer
[3];
1107 unit
->type
= buffer
[2];
1108 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
1109 unit
->extension
.bNumControls
= buffer
[20];
1110 unit
->extension
.bNrInPins
= get_unaligned_le16(&buffer
[21]);
1111 unit
->extension
.baSourceID
= (__u8
*)unit
+ sizeof *unit
;
1112 memcpy(unit
->extension
.baSourceID
, &buffer
[22], p
);
1113 unit
->extension
.bControlSize
= buffer
[22+p
];
1114 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof *unit
+ p
;
1115 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], n
);
1117 if (buffer
[23+p
+n
] != 0)
1118 usb_string(udev
, buffer
[23+p
+n
], unit
->name
,
1121 sprintf(unit
->name
, "Extension %u", buffer
[3]);
1123 list_add_tail(&unit
->list
, &dev
->entities
);
1127 uvc_trace(UVC_TRACE_DESCR
, "Found an unknown CS_INTERFACE "
1128 "descriptor (%u)\n", buffer
[2]);
1135 static int uvc_parse_control(struct uvc_device
*dev
)
1137 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
1138 unsigned char *buffer
= alts
->extra
;
1139 int buflen
= alts
->extralen
;
1142 /* Parse the default alternate setting only, as the UVC specification
1143 * defines a single alternate setting, the default alternate setting
1147 while (buflen
> 2) {
1148 if (uvc_parse_vendor_control(dev
, buffer
, buflen
) ||
1149 buffer
[1] != USB_DT_CS_INTERFACE
)
1150 goto next_descriptor
;
1152 if ((ret
= uvc_parse_standard_control(dev
, buffer
, buflen
)) < 0)
1156 buflen
-= buffer
[0];
1157 buffer
+= buffer
[0];
1160 /* Check if the optional status endpoint is present. Built-in iSight
1161 * webcams have an interrupt endpoint but spit proprietary data that
1162 * don't conform to the UVC status endpoint messages. Don't try to
1163 * handle the interrupt endpoint for those cameras.
1165 if (alts
->desc
.bNumEndpoints
== 1 &&
1166 !(dev
->quirks
& UVC_QUIRK_BUILTIN_ISIGHT
)) {
1167 struct usb_host_endpoint
*ep
= &alts
->endpoint
[0];
1168 struct usb_endpoint_descriptor
*desc
= &ep
->desc
;
1170 if (usb_endpoint_is_int_in(desc
) &&
1171 le16_to_cpu(desc
->wMaxPacketSize
) >= 8 &&
1172 desc
->bInterval
!= 0) {
1173 uvc_trace(UVC_TRACE_DESCR
, "Found a Status endpoint "
1174 "(addr %02x).\n", desc
->bEndpointAddress
);
1182 /* ------------------------------------------------------------------------
1187 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1188 * and containing the following units:
1190 * - one or more Output Terminals (USB Streaming or Display)
1191 * - zero or one Processing Unit
1192 * - zero, one or more single-input Selector Units
1193 * - zero or one multiple-input Selector Units, provided all inputs are
1194 * connected to input terminals
1195 * - zero, one or mode single-input Extension Units
1196 * - one or more Input Terminals (Camera, External or USB Streaming)
1198 * The terminal and units must match on of the following structures:
1200 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1201 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1202 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1204 * +---------+ +---------+ -> OTT_*(0)
1205 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1206 * +---------+ +---------+ -> OTT_*(n)
1208 * The Processing Unit and Extension Units can be in any order. Additional
1209 * Extension Units connected to the main chain as single-unit branches are
1210 * also supported. Single-input Selector Units are ignored.
1212 static int uvc_scan_chain_entity(struct uvc_video_chain
*chain
,
1213 struct uvc_entity
*entity
)
1215 switch (UVC_ENTITY_TYPE(entity
)) {
1216 case UVC_VC_EXTENSION_UNIT
:
1217 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1218 printk(" <- XU %d", entity
->id
);
1220 if (entity
->extension
.bNrInPins
!= 1) {
1221 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d has more "
1222 "than 1 input pin.\n", entity
->id
);
1226 list_add_tail(&entity
->chain
, &chain
->extensions
);
1229 case UVC_VC_PROCESSING_UNIT
:
1230 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1231 printk(" <- PU %d", entity
->id
);
1233 if (chain
->processing
!= NULL
) {
1234 uvc_trace(UVC_TRACE_DESCR
, "Found multiple "
1235 "Processing Units in chain.\n");
1239 chain
->processing
= entity
;
1242 case UVC_VC_SELECTOR_UNIT
:
1243 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1244 printk(" <- SU %d", entity
->id
);
1246 /* Single-input selector units are ignored. */
1247 if (entity
->selector
.bNrInPins
== 1)
1250 if (chain
->selector
!= NULL
) {
1251 uvc_trace(UVC_TRACE_DESCR
, "Found multiple Selector "
1252 "Units in chain.\n");
1256 chain
->selector
= entity
;
1259 case UVC_ITT_VENDOR_SPECIFIC
:
1260 case UVC_ITT_CAMERA
:
1261 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1262 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1263 printk(" <- IT %d\n", entity
->id
);
1265 list_add_tail(&entity
->chain
, &chain
->iterms
);
1268 case UVC_TT_STREAMING
:
1269 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1270 printk(" <- IT %d\n", entity
->id
);
1272 if (!UVC_ENTITY_IS_ITERM(entity
)) {
1273 uvc_trace(UVC_TRACE_DESCR
, "Unsupported input "
1274 "terminal %u.\n", entity
->id
);
1278 list_add_tail(&entity
->chain
, &chain
->iterms
);
1282 uvc_trace(UVC_TRACE_DESCR
, "Unsupported entity type "
1283 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity
));
1290 static int uvc_scan_chain_forward(struct uvc_video_chain
*chain
,
1291 struct uvc_entity
*entity
, struct uvc_entity
*prev
)
1293 struct uvc_entity
*forward
;
1301 forward
= uvc_entity_by_reference(chain
->dev
, entity
->id
,
1303 if (forward
== NULL
)
1305 if (forward
== prev
)
1308 switch (UVC_ENTITY_TYPE(forward
)) {
1309 case UVC_VC_EXTENSION_UNIT
:
1310 if (forward
->extension
.bNrInPins
!= 1) {
1311 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d "
1312 "has more than 1 input pin.\n",
1317 list_add_tail(&forward
->chain
, &chain
->extensions
);
1318 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1322 printk(" XU %d", forward
->id
);
1327 case UVC_OTT_VENDOR_SPECIFIC
:
1328 case UVC_OTT_DISPLAY
:
1329 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1330 case UVC_TT_STREAMING
:
1331 if (UVC_ENTITY_IS_ITERM(forward
)) {
1332 uvc_trace(UVC_TRACE_DESCR
, "Unsupported input "
1333 "terminal %u.\n", forward
->id
);
1337 list_add_tail(&forward
->chain
, &chain
->oterms
);
1338 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1342 printk(" OT %d", forward
->id
);
1354 static int uvc_scan_chain_backward(struct uvc_video_chain
*chain
,
1355 struct uvc_entity
*entity
)
1357 struct uvc_entity
*term
;
1360 switch (UVC_ENTITY_TYPE(entity
)) {
1361 case UVC_VC_EXTENSION_UNIT
:
1362 id
= entity
->extension
.baSourceID
[0];
1365 case UVC_VC_PROCESSING_UNIT
:
1366 id
= entity
->processing
.bSourceID
;
1369 case UVC_VC_SELECTOR_UNIT
:
1370 /* Single-input selector units are ignored. */
1371 if (entity
->selector
.bNrInPins
== 1) {
1372 id
= entity
->selector
.baSourceID
[0];
1376 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1379 chain
->selector
= entity
;
1380 for (i
= 0; i
< entity
->selector
.bNrInPins
; ++i
) {
1381 id
= entity
->selector
.baSourceID
[i
];
1382 term
= uvc_entity_by_id(chain
->dev
, id
);
1383 if (term
== NULL
|| !UVC_ENTITY_IS_ITERM(term
)) {
1384 uvc_trace(UVC_TRACE_DESCR
, "Selector unit %d "
1385 "input %d isn't connected to an "
1386 "input terminal\n", entity
->id
, i
);
1390 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1391 printk(" %d", term
->id
);
1393 list_add_tail(&term
->chain
, &chain
->iterms
);
1394 uvc_scan_chain_forward(chain
, term
, entity
);
1397 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1407 static int uvc_scan_chain(struct uvc_video_chain
*chain
,
1408 struct uvc_entity
*oterm
)
1410 struct uvc_entity
*entity
, *prev
;
1414 list_add_tail(&entity
->chain
, &chain
->oterms
);
1415 uvc_trace(UVC_TRACE_PROBE
, "Scanning UVC chain: OT %d", entity
->id
);
1417 id
= entity
->output
.bSourceID
;
1420 entity
= uvc_entity_by_id(chain
->dev
, id
);
1421 if (entity
== NULL
) {
1422 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1423 "unknown entity %d.\n", id
);
1427 if (entity
->chain
.next
|| entity
->chain
.prev
) {
1428 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1429 "entity %d already in chain.\n", id
);
1433 /* Process entity */
1434 if (uvc_scan_chain_entity(chain
, entity
) < 0)
1438 if (uvc_scan_chain_forward(chain
, entity
, prev
) < 0)
1441 /* Stop when a terminal is found. */
1442 if (UVC_ENTITY_IS_TERM(entity
))
1446 id
= uvc_scan_chain_backward(chain
, entity
);
1454 static unsigned int uvc_print_terms(struct list_head
*terms
, char *buffer
)
1456 struct uvc_entity
*term
;
1457 unsigned int nterms
= 0;
1460 list_for_each_entry(term
, terms
, chain
) {
1461 p
+= sprintf(p
, "%u", term
->id
);
1462 if (term
->chain
.next
!= terms
) {
1463 p
+= sprintf(p
, ",");
1464 if (++nterms
>= 4) {
1465 p
+= sprintf(p
, "...");
1474 static const char *uvc_print_chain(struct uvc_video_chain
*chain
)
1476 static char buffer
[43];
1479 p
+= uvc_print_terms(&chain
->iterms
, p
);
1480 p
+= sprintf(p
, " -> ");
1481 uvc_print_terms(&chain
->oterms
, p
);
1487 * Scan the device for video chains and register video devices.
1489 * Chains are scanned starting at their output terminals and walked backwards.
1491 static int uvc_scan_device(struct uvc_device
*dev
)
1493 struct uvc_video_chain
*chain
;
1494 struct uvc_entity
*term
;
1496 list_for_each_entry(term
, &dev
->entities
, list
) {
1497 if (!UVC_ENTITY_IS_OTERM(term
))
1500 /* If the terminal is already included in a chain, skip it.
1501 * This can happen for chains that have multiple output
1502 * terminals, where all output terminals beside the first one
1503 * will be inserted in the chain in forward scans.
1505 if (term
->chain
.next
|| term
->chain
.prev
)
1508 chain
= kzalloc(sizeof(*chain
), GFP_KERNEL
);
1512 INIT_LIST_HEAD(&chain
->iterms
);
1513 INIT_LIST_HEAD(&chain
->oterms
);
1514 INIT_LIST_HEAD(&chain
->extensions
);
1515 mutex_init(&chain
->ctrl_mutex
);
1518 if (uvc_scan_chain(chain
, term
) < 0) {
1523 uvc_trace(UVC_TRACE_PROBE
, "Found a valid video chain (%s).\n",
1524 uvc_print_chain(chain
));
1526 list_add_tail(&chain
->list
, &dev
->chains
);
1529 if (list_empty(&dev
->chains
)) {
1530 uvc_printk(KERN_INFO
, "No valid video chain found.\n");
1537 /* ------------------------------------------------------------------------
1538 * Video device registration and unregistration
1542 * Delete the UVC device.
1544 * Called by the kernel when the last reference to the uvc_device structure
1547 * As this function is called after or during disconnect(), all URBs have
1548 * already been canceled by the USB core. There is no need to kill the
1549 * interrupt URB manually.
1551 static void uvc_delete(struct uvc_device
*dev
)
1553 struct list_head
*p
, *n
;
1555 usb_put_intf(dev
->intf
);
1556 usb_put_dev(dev
->udev
);
1558 uvc_status_cleanup(dev
);
1559 uvc_ctrl_cleanup_device(dev
);
1561 list_for_each_safe(p
, n
, &dev
->chains
) {
1562 struct uvc_video_chain
*chain
;
1563 chain
= list_entry(p
, struct uvc_video_chain
, list
);
1567 list_for_each_safe(p
, n
, &dev
->entities
) {
1568 struct uvc_entity
*entity
;
1569 entity
= list_entry(p
, struct uvc_entity
, list
);
1573 list_for_each_safe(p
, n
, &dev
->streams
) {
1574 struct uvc_streaming
*streaming
;
1575 streaming
= list_entry(p
, struct uvc_streaming
, list
);
1576 usb_driver_release_interface(&uvc_driver
.driver
,
1578 usb_put_intf(streaming
->intf
);
1579 kfree(streaming
->format
);
1580 kfree(streaming
->header
.bmaControls
);
1587 static void uvc_release(struct video_device
*vdev
)
1589 struct uvc_streaming
*stream
= video_get_drvdata(vdev
);
1590 struct uvc_device
*dev
= stream
->dev
;
1592 video_device_release(vdev
);
1594 /* Decrement the registered streams count and delete the device when it
1597 if (atomic_dec_and_test(&dev
->nstreams
))
1602 * Unregister the video devices.
1604 static void uvc_unregister_video(struct uvc_device
*dev
)
1606 struct uvc_streaming
*stream
;
1608 /* Unregistering all video devices might result in uvc_delete() being
1609 * called from inside the loop if there's no open file handle. To avoid
1610 * that, increment the stream count before iterating over the streams
1611 * and decrement it when done.
1613 atomic_inc(&dev
->nstreams
);
1615 list_for_each_entry(stream
, &dev
->streams
, list
) {
1616 if (stream
->vdev
== NULL
)
1619 video_unregister_device(stream
->vdev
);
1620 stream
->vdev
= NULL
;
1623 /* Decrement the stream count and call uvc_delete explicitly if there
1624 * are no stream left.
1626 if (atomic_dec_and_test(&dev
->nstreams
))
1630 static int uvc_register_video(struct uvc_device
*dev
,
1631 struct uvc_streaming
*stream
)
1633 struct video_device
*vdev
;
1636 /* Initialize the streaming interface with default streaming
1639 ret
= uvc_video_init(stream
);
1641 uvc_printk(KERN_ERR
, "Failed to initialize the device "
1646 /* Register the device with V4L. */
1647 vdev
= video_device_alloc();
1649 uvc_printk(KERN_ERR
, "Failed to allocate video device (%d).\n",
1654 /* We already hold a reference to dev->udev. The video device will be
1655 * unregistered before the reference is released, so we don't need to
1658 vdev
->parent
= &dev
->intf
->dev
;
1660 vdev
->fops
= &uvc_fops
;
1661 vdev
->release
= uvc_release
;
1662 strlcpy(vdev
->name
, dev
->name
, sizeof vdev
->name
);
1664 /* Set the driver data before calling video_register_device, otherwise
1665 * uvc_v4l2_open might race us.
1667 stream
->vdev
= vdev
;
1668 video_set_drvdata(vdev
, stream
);
1670 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1672 uvc_printk(KERN_ERR
, "Failed to register video device (%d).\n",
1674 stream
->vdev
= NULL
;
1675 video_device_release(vdev
);
1679 atomic_inc(&dev
->nstreams
);
1684 * Register all video devices in all chains.
1686 static int uvc_register_terms(struct uvc_device
*dev
,
1687 struct uvc_video_chain
*chain
, struct list_head
*terms
)
1689 struct uvc_streaming
*stream
;
1690 struct uvc_entity
*term
;
1693 list_for_each_entry(term
, terms
, chain
) {
1694 if (UVC_ENTITY_TYPE(term
) != UVC_TT_STREAMING
)
1697 stream
= uvc_stream_by_id(dev
, term
->id
);
1698 if (stream
== NULL
) {
1699 uvc_printk(KERN_INFO
, "No streaming interface found "
1700 "for terminal %u.", term
->id
);
1704 stream
->chain
= chain
;
1705 ret
= uvc_register_video(dev
, stream
);
1713 static int uvc_register_chains(struct uvc_device
*dev
)
1715 struct uvc_video_chain
*chain
;
1718 list_for_each_entry(chain
, &dev
->chains
, list
) {
1719 ret
= uvc_register_terms(dev
, chain
, &chain
->iterms
);
1723 ret
= uvc_register_terms(dev
, chain
, &chain
->oterms
);
1731 /* ------------------------------------------------------------------------
1732 * USB probe, disconnect, suspend and resume
1735 static int uvc_probe(struct usb_interface
*intf
,
1736 const struct usb_device_id
*id
)
1738 struct usb_device
*udev
= interface_to_usbdev(intf
);
1739 struct uvc_device
*dev
;
1742 if (id
->idVendor
&& id
->idProduct
)
1743 uvc_trace(UVC_TRACE_PROBE
, "Probing known UVC device %s "
1744 "(%04x:%04x)\n", udev
->devpath
, id
->idVendor
,
1747 uvc_trace(UVC_TRACE_PROBE
, "Probing generic UVC device %s\n",
1750 /* Allocate memory for the device and initialize it. */
1751 if ((dev
= kzalloc(sizeof *dev
, GFP_KERNEL
)) == NULL
)
1754 INIT_LIST_HEAD(&dev
->entities
);
1755 INIT_LIST_HEAD(&dev
->chains
);
1756 INIT_LIST_HEAD(&dev
->streams
);
1757 atomic_set(&dev
->nstreams
, 0);
1758 atomic_set(&dev
->users
, 0);
1760 dev
->udev
= usb_get_dev(udev
);
1761 dev
->intf
= usb_get_intf(intf
);
1762 dev
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
1763 dev
->quirks
= id
->driver_info
| uvc_quirks_param
;
1765 if (udev
->product
!= NULL
)
1766 strlcpy(dev
->name
, udev
->product
, sizeof dev
->name
);
1768 snprintf(dev
->name
, sizeof dev
->name
,
1769 "UVC Camera (%04x:%04x)",
1770 le16_to_cpu(udev
->descriptor
.idVendor
),
1771 le16_to_cpu(udev
->descriptor
.idProduct
));
1773 /* Parse the Video Class control descriptor. */
1774 if (uvc_parse_control(dev
) < 0) {
1775 uvc_trace(UVC_TRACE_PROBE
, "Unable to parse UVC "
1780 uvc_printk(KERN_INFO
, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1781 dev
->uvc_version
>> 8, dev
->uvc_version
& 0xff,
1782 udev
->product
? udev
->product
: "<unnamed>",
1783 le16_to_cpu(udev
->descriptor
.idVendor
),
1784 le16_to_cpu(udev
->descriptor
.idProduct
));
1786 if (uvc_quirks_param
!= 0) {
1787 uvc_printk(KERN_INFO
, "Forcing device quirks 0x%x by module "
1788 "parameter for testing purpose.\n", uvc_quirks_param
);
1789 uvc_printk(KERN_INFO
, "Please report required quirks to the "
1790 "linux-uvc-devel mailing list.\n");
1793 /* Initialize controls. */
1794 if (uvc_ctrl_init_device(dev
) < 0)
1797 /* Scan the device for video chains. */
1798 if (uvc_scan_device(dev
) < 0)
1801 /* Register video devices. */
1802 if (uvc_register_chains(dev
) < 0)
1805 /* Save our data pointer in the interface data. */
1806 usb_set_intfdata(intf
, dev
);
1808 /* Initialize the interrupt URB. */
1809 if ((ret
= uvc_status_init(dev
)) < 0) {
1810 uvc_printk(KERN_INFO
, "Unable to initialize the status "
1811 "endpoint (%d), status interrupt will not be "
1812 "supported.\n", ret
);
1815 uvc_trace(UVC_TRACE_PROBE
, "UVC device initialized.\n");
1819 uvc_unregister_video(dev
);
1823 static void uvc_disconnect(struct usb_interface
*intf
)
1825 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1827 /* Set the USB interface data to NULL. This can be done outside the
1828 * lock, as there's no other reader.
1830 usb_set_intfdata(intf
, NULL
);
1832 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1833 UVC_SC_VIDEOSTREAMING
)
1836 dev
->state
|= UVC_DEV_DISCONNECTED
;
1838 uvc_unregister_video(dev
);
1841 static int uvc_suspend(struct usb_interface
*intf
, pm_message_t message
)
1843 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1844 struct uvc_streaming
*stream
;
1846 uvc_trace(UVC_TRACE_SUSPEND
, "Suspending interface %u\n",
1847 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1849 /* Controls are cached on the fly so they don't need to be saved. */
1850 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1851 UVC_SC_VIDEOCONTROL
)
1852 return uvc_status_suspend(dev
);
1854 list_for_each_entry(stream
, &dev
->streams
, list
) {
1855 if (stream
->intf
== intf
)
1856 return uvc_video_suspend(stream
);
1859 uvc_trace(UVC_TRACE_SUSPEND
, "Suspend: video streaming USB interface "
1864 static int __uvc_resume(struct usb_interface
*intf
, int reset
)
1866 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1867 struct uvc_streaming
*stream
;
1869 uvc_trace(UVC_TRACE_SUSPEND
, "Resuming interface %u\n",
1870 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1872 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1873 UVC_SC_VIDEOCONTROL
) {
1875 int ret
= uvc_ctrl_resume_device(dev
);
1881 return uvc_status_resume(dev
);
1884 list_for_each_entry(stream
, &dev
->streams
, list
) {
1885 if (stream
->intf
== intf
)
1886 return uvc_video_resume(stream
);
1889 uvc_trace(UVC_TRACE_SUSPEND
, "Resume: video streaming USB interface "
1894 static int uvc_resume(struct usb_interface
*intf
)
1896 return __uvc_resume(intf
, 0);
1899 static int uvc_reset_resume(struct usb_interface
*intf
)
1901 return __uvc_resume(intf
, 1);
1904 /* ------------------------------------------------------------------------
1905 * Driver initialization and cleanup
1909 * The Logitech cameras listed below have their interface class set to
1910 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
1911 * though they are compliant.
1913 static struct usb_device_id uvc_ids
[] = {
1914 /* Microsoft Lifecam NX-6000 */
1915 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1916 | USB_DEVICE_ID_MATCH_INT_INFO
,
1918 .idProduct
= 0x00f8,
1919 .bInterfaceClass
= USB_CLASS_VIDEO
,
1920 .bInterfaceSubClass
= 1,
1921 .bInterfaceProtocol
= 0,
1922 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
1923 /* Microsoft Lifecam VX-7000 */
1924 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1925 | USB_DEVICE_ID_MATCH_INT_INFO
,
1927 .idProduct
= 0x0723,
1928 .bInterfaceClass
= USB_CLASS_VIDEO
,
1929 .bInterfaceSubClass
= 1,
1930 .bInterfaceProtocol
= 0,
1931 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
1932 /* Logitech Quickcam Fusion */
1933 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1934 | USB_DEVICE_ID_MATCH_INT_INFO
,
1936 .idProduct
= 0x08c1,
1937 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
1938 .bInterfaceSubClass
= 1,
1939 .bInterfaceProtocol
= 0 },
1940 /* Logitech Quickcam Orbit MP */
1941 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1942 | USB_DEVICE_ID_MATCH_INT_INFO
,
1944 .idProduct
= 0x08c2,
1945 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
1946 .bInterfaceSubClass
= 1,
1947 .bInterfaceProtocol
= 0 },
1948 /* Logitech Quickcam Pro for Notebook */
1949 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1950 | USB_DEVICE_ID_MATCH_INT_INFO
,
1952 .idProduct
= 0x08c3,
1953 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
1954 .bInterfaceSubClass
= 1,
1955 .bInterfaceProtocol
= 0 },
1956 /* Logitech Quickcam Pro 5000 */
1957 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1958 | USB_DEVICE_ID_MATCH_INT_INFO
,
1960 .idProduct
= 0x08c5,
1961 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
1962 .bInterfaceSubClass
= 1,
1963 .bInterfaceProtocol
= 0 },
1964 /* Logitech Quickcam OEM Dell Notebook */
1965 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1966 | USB_DEVICE_ID_MATCH_INT_INFO
,
1968 .idProduct
= 0x08c6,
1969 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
1970 .bInterfaceSubClass
= 1,
1971 .bInterfaceProtocol
= 0 },
1972 /* Logitech Quickcam OEM Cisco VT Camera II */
1973 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1974 | USB_DEVICE_ID_MATCH_INT_INFO
,
1976 .idProduct
= 0x08c7,
1977 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
1978 .bInterfaceSubClass
= 1,
1979 .bInterfaceProtocol
= 0 },
1980 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
1981 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1982 | USB_DEVICE_ID_MATCH_INT_INFO
,
1984 .idProduct
= 0x3820,
1985 .bInterfaceClass
= USB_CLASS_VIDEO
,
1986 .bInterfaceSubClass
= 1,
1987 .bInterfaceProtocol
= 0,
1988 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
1989 /* Apple Built-In iSight */
1990 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
1991 | USB_DEVICE_ID_MATCH_INT_INFO
,
1993 .idProduct
= 0x8501,
1994 .bInterfaceClass
= USB_CLASS_VIDEO
,
1995 .bInterfaceSubClass
= 1,
1996 .bInterfaceProtocol
= 0,
1997 .driver_info
= UVC_QUIRK_PROBE_MINMAX
1998 | UVC_QUIRK_BUILTIN_ISIGHT
},
1999 /* Genesys Logic USB 2.0 PC Camera */
2000 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2001 | USB_DEVICE_ID_MATCH_INT_INFO
,
2003 .idProduct
= 0x0505,
2004 .bInterfaceClass
= USB_CLASS_VIDEO
,
2005 .bInterfaceSubClass
= 1,
2006 .bInterfaceProtocol
= 0,
2007 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2009 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2010 | USB_DEVICE_ID_MATCH_INT_INFO
,
2012 .idProduct
= 0x332d,
2013 .bInterfaceClass
= USB_CLASS_VIDEO
,
2014 .bInterfaceSubClass
= 1,
2015 .bInterfaceProtocol
= 0,
2016 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2017 /* ViMicro - Minoru3D */
2018 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2019 | USB_DEVICE_ID_MATCH_INT_INFO
,
2021 .idProduct
= 0x3410,
2022 .bInterfaceClass
= USB_CLASS_VIDEO
,
2023 .bInterfaceSubClass
= 1,
2024 .bInterfaceProtocol
= 0,
2025 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2026 /* ViMicro Venus - Minoru3D */
2027 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2028 | USB_DEVICE_ID_MATCH_INT_INFO
,
2030 .idProduct
= 0x3420,
2031 .bInterfaceClass
= USB_CLASS_VIDEO
,
2032 .bInterfaceSubClass
= 1,
2033 .bInterfaceProtocol
= 0,
2034 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2036 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2037 | USB_DEVICE_ID_MATCH_INT_INFO
,
2039 .idProduct
= 0x0004,
2040 .bInterfaceClass
= USB_CLASS_VIDEO
,
2041 .bInterfaceSubClass
= 1,
2042 .bInterfaceProtocol
= 0,
2043 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2044 | UVC_QUIRK_PROBE_DEF
},
2045 /* Syntek (HP Spartan) */
2046 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2047 | USB_DEVICE_ID_MATCH_INT_INFO
,
2049 .idProduct
= 0x5212,
2050 .bInterfaceClass
= USB_CLASS_VIDEO
,
2051 .bInterfaceSubClass
= 1,
2052 .bInterfaceProtocol
= 0,
2053 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2054 /* Syntek (Samsung Q310) */
2055 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2056 | USB_DEVICE_ID_MATCH_INT_INFO
,
2058 .idProduct
= 0x5931,
2059 .bInterfaceClass
= USB_CLASS_VIDEO
,
2060 .bInterfaceSubClass
= 1,
2061 .bInterfaceProtocol
= 0,
2062 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2063 /* Syntek (Asus F9SG) */
2064 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2065 | USB_DEVICE_ID_MATCH_INT_INFO
,
2067 .idProduct
= 0x8a31,
2068 .bInterfaceClass
= USB_CLASS_VIDEO
,
2069 .bInterfaceSubClass
= 1,
2070 .bInterfaceProtocol
= 0,
2071 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2072 /* Syntek (Asus U3S) */
2073 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2074 | USB_DEVICE_ID_MATCH_INT_INFO
,
2076 .idProduct
= 0x8a33,
2077 .bInterfaceClass
= USB_CLASS_VIDEO
,
2078 .bInterfaceSubClass
= 1,
2079 .bInterfaceProtocol
= 0,
2080 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2081 /* Syntek (JAOtech Smart Terminal) */
2082 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2083 | USB_DEVICE_ID_MATCH_INT_INFO
,
2085 .idProduct
= 0x8a34,
2086 .bInterfaceClass
= USB_CLASS_VIDEO
,
2087 .bInterfaceSubClass
= 1,
2088 .bInterfaceProtocol
= 0,
2089 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2090 /* Lenovo Thinkpad SL400/SL500 */
2091 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2092 | USB_DEVICE_ID_MATCH_INT_INFO
,
2094 .idProduct
= 0x480b,
2095 .bInterfaceClass
= USB_CLASS_VIDEO
,
2096 .bInterfaceSubClass
= 1,
2097 .bInterfaceProtocol
= 0,
2098 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2099 /* Aveo Technology USB 2.0 Camera */
2100 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2101 | USB_DEVICE_ID_MATCH_INT_INFO
,
2103 .idProduct
= 0x0306,
2104 .bInterfaceClass
= USB_CLASS_VIDEO
,
2105 .bInterfaceSubClass
= 1,
2106 .bInterfaceProtocol
= 0,
2107 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2108 | UVC_QUIRK_PROBE_EXTRAFIELDS
},
2109 /* Ecamm Pico iMage */
2110 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2111 | USB_DEVICE_ID_MATCH_INT_INFO
,
2113 .idProduct
= 0xcafe,
2114 .bInterfaceClass
= USB_CLASS_VIDEO
,
2115 .bInterfaceSubClass
= 1,
2116 .bInterfaceProtocol
= 0,
2117 .driver_info
= UVC_QUIRK_PROBE_EXTRAFIELDS
},
2118 /* FSC WebCam V30S */
2119 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2120 | USB_DEVICE_ID_MATCH_INT_INFO
,
2122 .idProduct
= 0x3288,
2123 .bInterfaceClass
= USB_CLASS_VIDEO
,
2124 .bInterfaceSubClass
= 1,
2125 .bInterfaceProtocol
= 0,
2126 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2127 /* Bodelin ProScopeHR */
2128 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2129 | USB_DEVICE_ID_MATCH_DEV_HI
2130 | USB_DEVICE_ID_MATCH_INT_INFO
,
2132 .idProduct
= 0x1000,
2133 .bcdDevice_hi
= 0x0126,
2134 .bInterfaceClass
= USB_CLASS_VIDEO
,
2135 .bInterfaceSubClass
= 1,
2136 .bInterfaceProtocol
= 0,
2137 .driver_info
= UVC_QUIRK_STATUS_INTERVAL
},
2138 /* SiGma Micro USB Web Camera */
2139 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2140 | USB_DEVICE_ID_MATCH_INT_INFO
,
2142 .idProduct
= 0x3000,
2143 .bInterfaceClass
= USB_CLASS_VIDEO
,
2144 .bInterfaceSubClass
= 1,
2145 .bInterfaceProtocol
= 0,
2146 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2147 | UVC_QUIRK_IGNORE_SELECTOR_UNIT
},
2148 /* Generic USB Video Class */
2149 { USB_INTERFACE_INFO(USB_CLASS_VIDEO
, 1, 0) },
2153 MODULE_DEVICE_TABLE(usb
, uvc_ids
);
2155 struct uvc_driver uvc_driver
= {
2159 .disconnect
= uvc_disconnect
,
2160 .suspend
= uvc_suspend
,
2161 .resume
= uvc_resume
,
2162 .reset_resume
= uvc_reset_resume
,
2163 .id_table
= uvc_ids
,
2164 .supports_autosuspend
= 1,
2168 static int __init
uvc_init(void)
2172 INIT_LIST_HEAD(&uvc_driver
.devices
);
2173 INIT_LIST_HEAD(&uvc_driver
.controls
);
2174 mutex_init(&uvc_driver
.ctrl_mutex
);
2178 result
= usb_register(&uvc_driver
.driver
);
2180 printk(KERN_INFO DRIVER_DESC
" (" DRIVER_VERSION
")\n");
2184 static void __exit
uvc_cleanup(void)
2186 usb_deregister(&uvc_driver
.driver
);
2189 module_init(uvc_init
);
2190 module_exit(uvc_cleanup
);
2192 module_param_named(nodrop
, uvc_no_drop_param
, uint
, S_IRUGO
|S_IWUSR
);
2193 MODULE_PARM_DESC(nodrop
, "Don't drop incomplete frames");
2194 module_param_named(quirks
, uvc_quirks_param
, uint
, S_IRUGO
|S_IWUSR
);
2195 MODULE_PARM_DESC(quirks
, "Forced device quirks");
2196 module_param_named(trace
, uvc_trace_param
, uint
, S_IRUGO
|S_IWUSR
);
2197 MODULE_PARM_DESC(trace
, "Trace level bitmask");
2199 MODULE_AUTHOR(DRIVER_AUTHOR
);
2200 MODULE_DESCRIPTION(DRIVER_DESC
);
2201 MODULE_LICENSE("GPL");
2202 MODULE_VERSION(DRIVER_VERSION
);