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 <asm/atomic.h>
35 #include <asm/unaligned.h>
37 #include <media/v4l2-common.h>
41 #define DRIVER_AUTHOR "Laurent Pinchart " \
42 "<laurent.pinchart@ideasonboard.com>"
43 #define DRIVER_DESC "USB Video Class driver"
45 unsigned int uvc_clock_param
= CLOCK_MONOTONIC
;
46 unsigned int uvc_no_drop_param
;
47 static unsigned int uvc_quirks_param
= -1;
48 unsigned int uvc_trace_param
;
49 unsigned int uvc_timeout_param
= UVC_CTRL_STREAMING_TIMEOUT
;
51 /* ------------------------------------------------------------------------
55 static struct uvc_format_desc uvc_fmts
[] = {
57 .name
= "YUV 4:2:2 (YUYV)",
58 .guid
= UVC_GUID_FORMAT_YUY2
,
59 .fcc
= V4L2_PIX_FMT_YUYV
,
62 .name
= "YUV 4:2:2 (YUYV)",
63 .guid
= UVC_GUID_FORMAT_YUY2_ISIGHT
,
64 .fcc
= V4L2_PIX_FMT_YUYV
,
67 .name
= "YUV 4:2:0 (NV12)",
68 .guid
= UVC_GUID_FORMAT_NV12
,
69 .fcc
= V4L2_PIX_FMT_NV12
,
73 .guid
= UVC_GUID_FORMAT_MJPEG
,
74 .fcc
= V4L2_PIX_FMT_MJPEG
,
77 .name
= "YVU 4:2:0 (YV12)",
78 .guid
= UVC_GUID_FORMAT_YV12
,
79 .fcc
= V4L2_PIX_FMT_YVU420
,
82 .name
= "YUV 4:2:0 (I420)",
83 .guid
= UVC_GUID_FORMAT_I420
,
84 .fcc
= V4L2_PIX_FMT_YUV420
,
87 .name
= "YUV 4:2:0 (M420)",
88 .guid
= UVC_GUID_FORMAT_M420
,
89 .fcc
= V4L2_PIX_FMT_M420
,
92 .name
= "YUV 4:2:2 (UYVY)",
93 .guid
= UVC_GUID_FORMAT_UYVY
,
94 .fcc
= V4L2_PIX_FMT_UYVY
,
97 .name
= "Greyscale (8-bit)",
98 .guid
= UVC_GUID_FORMAT_Y800
,
99 .fcc
= V4L2_PIX_FMT_GREY
,
102 .name
= "Greyscale (16-bit)",
103 .guid
= UVC_GUID_FORMAT_Y16
,
104 .fcc
= V4L2_PIX_FMT_Y16
,
108 .guid
= UVC_GUID_FORMAT_BY8
,
109 .fcc
= V4L2_PIX_FMT_SBGGR8
,
113 .guid
= UVC_GUID_FORMAT_RGBP
,
114 .fcc
= V4L2_PIX_FMT_RGB565
,
118 /* ------------------------------------------------------------------------
122 struct usb_host_endpoint
*uvc_find_endpoint(struct usb_host_interface
*alts
,
125 struct usb_host_endpoint
*ep
;
128 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
129 ep
= &alts
->endpoint
[i
];
130 if (ep
->desc
.bEndpointAddress
== epaddr
)
137 static struct uvc_format_desc
*uvc_format_by_guid(const __u8 guid
[16])
139 unsigned int len
= ARRAY_SIZE(uvc_fmts
);
142 for (i
= 0; i
< len
; ++i
) {
143 if (memcmp(guid
, uvc_fmts
[i
].guid
, 16) == 0)
150 static __u32
uvc_colorspace(const __u8 primaries
)
152 static const __u8 colorprimaries
[] = {
154 V4L2_COLORSPACE_SRGB
,
155 V4L2_COLORSPACE_470_SYSTEM_M
,
156 V4L2_COLORSPACE_470_SYSTEM_BG
,
157 V4L2_COLORSPACE_SMPTE170M
,
158 V4L2_COLORSPACE_SMPTE240M
,
161 if (primaries
< ARRAY_SIZE(colorprimaries
))
162 return colorprimaries
[primaries
];
167 /* Simplify a fraction using a simple continued fraction decomposition. The
168 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
169 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
170 * arbitrary parameters to remove non-significative terms from the simple
171 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
172 * respectively seems to give nice results.
174 void uvc_simplify_fraction(uint32_t *numerator
, uint32_t *denominator
,
175 unsigned int n_terms
, unsigned int threshold
)
181 an
= kmalloc(n_terms
* sizeof *an
, GFP_KERNEL
);
185 /* Convert the fraction to a simple continued fraction. See
186 * http://mathforum.org/dr.math/faq/faq.fractions.html
187 * Stop if the current term is bigger than or equal to the given
193 for (n
= 0; n
< n_terms
&& y
!= 0; ++n
) {
195 if (an
[n
] >= threshold
) {
206 /* Expand the simple continued fraction back to an integer fraction. */
210 for (i
= n
; i
> 0; --i
) {
221 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
222 * to compute numerator / denominator * 10000000 using 32 bit fixed point
225 uint32_t uvc_fraction_to_interval(uint32_t numerator
, uint32_t denominator
)
229 /* Saturate the result if the operation would overflow. */
230 if (denominator
== 0 ||
231 numerator
/denominator
>= ((uint32_t)-1)/10000000)
234 /* Divide both the denominator and the multiplier by two until
235 * numerator * multiplier doesn't overflow. If anyone knows a better
236 * algorithm please let me know.
238 multiplier
= 10000000;
239 while (numerator
> ((uint32_t)-1)/multiplier
) {
244 return denominator
? numerator
* multiplier
/ denominator
: 0;
247 /* ------------------------------------------------------------------------
248 * Terminal and unit management
251 struct uvc_entity
*uvc_entity_by_id(struct uvc_device
*dev
, int id
)
253 struct uvc_entity
*entity
;
255 list_for_each_entry(entity
, &dev
->entities
, list
) {
256 if (entity
->id
== id
)
263 static struct uvc_entity
*uvc_entity_by_reference(struct uvc_device
*dev
,
264 int id
, struct uvc_entity
*entity
)
269 entity
= list_entry(&dev
->entities
, struct uvc_entity
, list
);
271 list_for_each_entry_continue(entity
, &dev
->entities
, list
) {
272 for (i
= 0; i
< entity
->bNrInPins
; ++i
)
273 if (entity
->baSourceID
[i
] == id
)
280 static struct uvc_streaming
*uvc_stream_by_id(struct uvc_device
*dev
, int id
)
282 struct uvc_streaming
*stream
;
284 list_for_each_entry(stream
, &dev
->streams
, list
) {
285 if (stream
->header
.bTerminalLink
== id
)
292 /* ------------------------------------------------------------------------
293 * Descriptors parsing
296 static int uvc_parse_format(struct uvc_device
*dev
,
297 struct uvc_streaming
*streaming
, struct uvc_format
*format
,
298 __u32
**intervals
, unsigned char *buffer
, int buflen
)
300 struct usb_interface
*intf
= streaming
->intf
;
301 struct usb_host_interface
*alts
= intf
->cur_altsetting
;
302 struct uvc_format_desc
*fmtdesc
;
303 struct uvc_frame
*frame
;
304 const unsigned char *start
= buffer
;
305 unsigned int interval
;
309 format
->type
= buffer
[2];
310 format
->index
= buffer
[3];
313 case UVC_VS_FORMAT_UNCOMPRESSED
:
314 case UVC_VS_FORMAT_FRAME_BASED
:
315 n
= buffer
[2] == UVC_VS_FORMAT_UNCOMPRESSED
? 27 : 28;
317 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
318 "interface %d FORMAT error\n",
320 alts
->desc
.bInterfaceNumber
);
324 /* Find the format descriptor from its GUID. */
325 fmtdesc
= uvc_format_by_guid(&buffer
[5]);
327 if (fmtdesc
!= NULL
) {
328 strlcpy(format
->name
, fmtdesc
->name
,
329 sizeof format
->name
);
330 format
->fcc
= fmtdesc
->fcc
;
332 uvc_printk(KERN_INFO
, "Unknown video format %pUl\n",
334 snprintf(format
->name
, sizeof(format
->name
), "%pUl\n",
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 if (dev
->quirks
& UVC_QUIRK_RESTRICT_FRAME_RATE
) {
498 frame
->bFrameIntervalType
= 1;
499 frame
->dwFrameInterval
[0] =
500 frame
->dwDefaultFrameInterval
;
503 uvc_trace(UVC_TRACE_DESCR
, "- %ux%u (%u.%u fps)\n",
504 frame
->wWidth
, frame
->wHeight
,
505 10000000/frame
->dwDefaultFrameInterval
,
506 (100000000/frame
->dwDefaultFrameInterval
)%10);
513 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
514 buffer
[2] == UVC_VS_STILL_IMAGE_FRAME
) {
519 if (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
&&
520 buffer
[2] == UVC_VS_COLORFORMAT
) {
522 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
523 "interface %d COLORFORMAT error\n",
525 alts
->desc
.bInterfaceNumber
);
529 format
->colorspace
= uvc_colorspace(buffer
[3]);
535 return buffer
- start
;
538 static int uvc_parse_streaming(struct uvc_device
*dev
,
539 struct usb_interface
*intf
)
541 struct uvc_streaming
*streaming
= NULL
;
542 struct uvc_format
*format
;
543 struct uvc_frame
*frame
;
544 struct usb_host_interface
*alts
= &intf
->altsetting
[0];
545 unsigned char *_buffer
, *buffer
= alts
->extra
;
546 int _buflen
, buflen
= alts
->extralen
;
547 unsigned int nformats
= 0, nframes
= 0, nintervals
= 0;
548 unsigned int size
, i
, n
, p
;
553 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
554 != UVC_SC_VIDEOSTREAMING
) {
555 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d isn't a "
556 "video streaming interface\n", dev
->udev
->devnum
,
557 intf
->altsetting
[0].desc
.bInterfaceNumber
);
561 if (usb_driver_claim_interface(&uvc_driver
.driver
, intf
, dev
)) {
562 uvc_trace(UVC_TRACE_DESCR
, "device %d interface %d is already "
563 "claimed\n", dev
->udev
->devnum
,
564 intf
->altsetting
[0].desc
.bInterfaceNumber
);
568 streaming
= kzalloc(sizeof *streaming
, GFP_KERNEL
);
569 if (streaming
== NULL
) {
570 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
574 mutex_init(&streaming
->mutex
);
575 streaming
->dev
= dev
;
576 streaming
->intf
= usb_get_intf(intf
);
577 streaming
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
579 /* The Pico iMage webcam has its class-specific interface descriptors
580 * after the endpoint descriptors.
583 for (i
= 0; i
< alts
->desc
.bNumEndpoints
; ++i
) {
584 struct usb_host_endpoint
*ep
= &alts
->endpoint
[i
];
586 if (ep
->extralen
== 0)
589 if (ep
->extralen
> 2 &&
590 ep
->extra
[1] == USB_DT_CS_INTERFACE
) {
591 uvc_trace(UVC_TRACE_DESCR
, "trying extra data "
592 "from endpoint %u.\n", i
);
593 buffer
= alts
->endpoint
[i
].extra
;
594 buflen
= alts
->endpoint
[i
].extralen
;
600 /* Skip the standard interface descriptors. */
601 while (buflen
> 2 && buffer
[1] != USB_DT_CS_INTERFACE
) {
607 uvc_trace(UVC_TRACE_DESCR
, "no class-specific streaming "
608 "interface descriptors found.\n");
612 /* Parse the header descriptor. */
614 case UVC_VS_OUTPUT_HEADER
:
615 streaming
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
619 case UVC_VS_INPUT_HEADER
:
620 streaming
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
625 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
626 "%d HEADER descriptor not found.\n", dev
->udev
->devnum
,
627 alts
->desc
.bInterfaceNumber
);
631 p
= buflen
>= 4 ? buffer
[3] : 0;
632 n
= buflen
>= size
? buffer
[size
-1] : 0;
634 if (buflen
< size
+ p
*n
) {
635 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
636 "interface %d HEADER descriptor is invalid.\n",
637 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
641 streaming
->header
.bNumFormats
= p
;
642 streaming
->header
.bEndpointAddress
= buffer
[6];
643 if (buffer
[2] == UVC_VS_INPUT_HEADER
) {
644 streaming
->header
.bmInfo
= buffer
[7];
645 streaming
->header
.bTerminalLink
= buffer
[8];
646 streaming
->header
.bStillCaptureMethod
= buffer
[9];
647 streaming
->header
.bTriggerSupport
= buffer
[10];
648 streaming
->header
.bTriggerUsage
= buffer
[11];
650 streaming
->header
.bTerminalLink
= buffer
[7];
652 streaming
->header
.bControlSize
= n
;
654 streaming
->header
.bmaControls
= kmemdup(&buffer
[size
], p
* n
,
656 if (streaming
->header
.bmaControls
== NULL
) {
667 /* Count the format and frame descriptors. */
668 while (_buflen
> 2 && _buffer
[1] == USB_DT_CS_INTERFACE
) {
669 switch (_buffer
[2]) {
670 case UVC_VS_FORMAT_UNCOMPRESSED
:
671 case UVC_VS_FORMAT_MJPEG
:
672 case UVC_VS_FORMAT_FRAME_BASED
:
676 case UVC_VS_FORMAT_DV
:
677 /* DV format has no frame descriptor. We will create a
678 * dummy frame descriptor with a dummy frame interval.
685 case UVC_VS_FORMAT_MPEG2TS
:
686 case UVC_VS_FORMAT_STREAM_BASED
:
687 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming "
688 "interface %d FORMAT %u is not supported.\n",
690 alts
->desc
.bInterfaceNumber
, _buffer
[2]);
693 case UVC_VS_FRAME_UNCOMPRESSED
:
694 case UVC_VS_FRAME_MJPEG
:
697 nintervals
+= _buffer
[25] ? _buffer
[25] : 3;
700 case UVC_VS_FRAME_FRAME_BASED
:
703 nintervals
+= _buffer
[21] ? _buffer
[21] : 3;
707 _buflen
-= _buffer
[0];
708 _buffer
+= _buffer
[0];
712 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
713 "%d has no supported formats defined.\n",
714 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
);
718 size
= nformats
* sizeof *format
+ nframes
* sizeof *frame
719 + nintervals
* sizeof *interval
;
720 format
= kzalloc(size
, GFP_KERNEL
);
721 if (format
== NULL
) {
726 frame
= (struct uvc_frame
*)&format
[nformats
];
727 interval
= (__u32
*)&frame
[nframes
];
729 streaming
->format
= format
;
730 streaming
->nformats
= nformats
;
732 /* Parse the format descriptors. */
733 while (buflen
> 2 && buffer
[1] == USB_DT_CS_INTERFACE
) {
735 case UVC_VS_FORMAT_UNCOMPRESSED
:
736 case UVC_VS_FORMAT_MJPEG
:
737 case UVC_VS_FORMAT_DV
:
738 case UVC_VS_FORMAT_FRAME_BASED
:
739 format
->frame
= frame
;
740 ret
= uvc_parse_format(dev
, streaming
, format
,
741 &interval
, buffer
, buflen
);
745 frame
+= format
->nframes
;
761 uvc_trace(UVC_TRACE_DESCR
, "device %d videostreaming interface "
762 "%d has %u bytes of trailing descriptor garbage.\n",
763 dev
->udev
->devnum
, alts
->desc
.bInterfaceNumber
, buflen
);
765 /* Parse the alternate settings to find the maximum bandwidth. */
766 for (i
= 0; i
< intf
->num_altsetting
; ++i
) {
767 struct usb_host_endpoint
*ep
;
768 alts
= &intf
->altsetting
[i
];
769 ep
= uvc_find_endpoint(alts
,
770 streaming
->header
.bEndpointAddress
);
774 psize
= le16_to_cpu(ep
->desc
.wMaxPacketSize
);
775 psize
= (psize
& 0x07ff) * (1 + ((psize
>> 11) & 3));
776 if (psize
> streaming
->maxpsize
)
777 streaming
->maxpsize
= psize
;
780 list_add_tail(&streaming
->list
, &dev
->streams
);
784 usb_driver_release_interface(&uvc_driver
.driver
, intf
);
786 kfree(streaming
->format
);
787 kfree(streaming
->header
.bmaControls
);
792 static struct uvc_entity
*uvc_alloc_entity(u16 type
, u8 id
,
793 unsigned int num_pads
, unsigned int extra_size
)
795 struct uvc_entity
*entity
;
796 unsigned int num_inputs
;
800 extra_size
= ALIGN(extra_size
, sizeof(*entity
->pads
));
801 num_inputs
= (type
& UVC_TERM_OUTPUT
) ? num_pads
: num_pads
- 1;
802 size
= sizeof(*entity
) + extra_size
+ sizeof(*entity
->pads
) * num_pads
804 entity
= kzalloc(size
, GFP_KERNEL
);
811 entity
->num_links
= 0;
812 entity
->num_pads
= num_pads
;
813 entity
->pads
= ((void *)(entity
+ 1)) + extra_size
;
815 for (i
= 0; i
< num_inputs
; ++i
)
816 entity
->pads
[i
].flags
= MEDIA_PAD_FL_SINK
;
817 if (!UVC_ENTITY_IS_OTERM(entity
))
818 entity
->pads
[num_pads
-1].flags
= MEDIA_PAD_FL_SOURCE
;
820 entity
->bNrInPins
= num_inputs
;
821 entity
->baSourceID
= (__u8
*)(&entity
->pads
[num_pads
]);
826 /* Parse vendor-specific extensions. */
827 static int uvc_parse_vendor_control(struct uvc_device
*dev
,
828 const unsigned char *buffer
, int buflen
)
830 struct usb_device
*udev
= dev
->udev
;
831 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
832 struct uvc_entity
*unit
;
836 switch (le16_to_cpu(dev
->udev
->descriptor
.idVendor
)) {
837 case 0x046d: /* Logitech */
838 if (buffer
[1] != 0x41 || buffer
[2] != 0x01)
841 /* Logitech implements several vendor specific functions
842 * through vendor specific extension units (LXU).
844 * The LXU descriptors are similar to XU descriptors
845 * (see "USB Device Video Class for Video Devices", section
846 * 3.7.2.6 "Extension Unit Descriptor") with the following
849 * ----------------------------------------------------------
851 * Size of this descriptor, in bytes: 24+p+n*2
852 * ----------------------------------------------------------
853 * 23+p+n bmControlsType N Bitmap
854 * Individual bits in the set are defined:
858 * This bitset is mapped exactly the same as bmControls.
859 * ----------------------------------------------------------
860 * 23+p+n*2 bReserved 1 Boolean
861 * ----------------------------------------------------------
862 * 24+p+n*2 iExtension 1 Index
863 * Index of a string descriptor that describes this
865 * ----------------------------------------------------------
867 p
= buflen
>= 22 ? buffer
[21] : 0;
868 n
= buflen
>= 25 + p
? buffer
[22+p
] : 0;
870 if (buflen
< 25 + p
+ 2*n
) {
871 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
872 "interface %d EXTENSION_UNIT error\n",
873 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
877 unit
= uvc_alloc_entity(UVC_VC_EXTENSION_UNIT
, buffer
[3],
882 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
883 unit
->extension
.bNumControls
= buffer
[20];
884 memcpy(unit
->baSourceID
, &buffer
[22], p
);
885 unit
->extension
.bControlSize
= buffer
[22+p
];
886 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof(*unit
);
887 unit
->extension
.bmControlsType
= (__u8
*)unit
+ sizeof(*unit
)
889 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], 2*n
);
891 if (buffer
[24+p
+2*n
] != 0)
892 usb_string(udev
, buffer
[24+p
+2*n
], unit
->name
,
895 sprintf(unit
->name
, "Extension %u", buffer
[3]);
897 list_add_tail(&unit
->list
, &dev
->entities
);
905 static int uvc_parse_standard_control(struct uvc_device
*dev
,
906 const unsigned char *buffer
, int buflen
)
908 struct usb_device
*udev
= dev
->udev
;
909 struct uvc_entity
*unit
, *term
;
910 struct usb_interface
*intf
;
911 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
912 unsigned int i
, n
, p
, len
;
917 n
= buflen
>= 12 ? buffer
[11] : 0;
919 if (buflen
< 12 || buflen
< 12 + n
) {
920 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
921 "interface %d HEADER error\n", udev
->devnum
,
922 alts
->desc
.bInterfaceNumber
);
926 dev
->uvc_version
= get_unaligned_le16(&buffer
[3]);
927 dev
->clock_frequency
= get_unaligned_le32(&buffer
[7]);
929 /* Parse all USB Video Streaming interfaces. */
930 for (i
= 0; i
< n
; ++i
) {
931 intf
= usb_ifnum_to_if(udev
, buffer
[12+i
]);
933 uvc_trace(UVC_TRACE_DESCR
, "device %d "
934 "interface %d doesn't exists\n",
939 uvc_parse_streaming(dev
, intf
);
943 case UVC_VC_INPUT_TERMINAL
:
945 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
946 "interface %d INPUT_TERMINAL error\n",
947 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
951 /* Make sure the terminal type MSB is not null, otherwise it
952 * could be confused with a unit.
954 type
= get_unaligned_le16(&buffer
[4]);
955 if ((type
& 0xff00) == 0) {
956 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
957 "interface %d INPUT_TERMINAL %d has invalid "
958 "type 0x%04x, skipping\n", udev
->devnum
,
959 alts
->desc
.bInterfaceNumber
,
968 if (type
== UVC_ITT_CAMERA
) {
969 n
= buflen
>= 15 ? buffer
[14] : 0;
972 } else if (type
== UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
973 n
= buflen
>= 9 ? buffer
[8] : 0;
974 p
= buflen
>= 10 + n
? buffer
[9+n
] : 0;
978 if (buflen
< len
+ n
+ p
) {
979 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
980 "interface %d INPUT_TERMINAL error\n",
981 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
985 term
= uvc_alloc_entity(type
| UVC_TERM_INPUT
, buffer
[3],
990 if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
) {
991 term
->camera
.bControlSize
= n
;
992 term
->camera
.bmControls
= (__u8
*)term
+ sizeof *term
;
993 term
->camera
.wObjectiveFocalLengthMin
=
994 get_unaligned_le16(&buffer
[8]);
995 term
->camera
.wObjectiveFocalLengthMax
=
996 get_unaligned_le16(&buffer
[10]);
997 term
->camera
.wOcularFocalLength
=
998 get_unaligned_le16(&buffer
[12]);
999 memcpy(term
->camera
.bmControls
, &buffer
[15], n
);
1000 } else if (UVC_ENTITY_TYPE(term
) ==
1001 UVC_ITT_MEDIA_TRANSPORT_INPUT
) {
1002 term
->media
.bControlSize
= n
;
1003 term
->media
.bmControls
= (__u8
*)term
+ sizeof *term
;
1004 term
->media
.bTransportModeSize
= p
;
1005 term
->media
.bmTransportModes
= (__u8
*)term
1007 memcpy(term
->media
.bmControls
, &buffer
[9], n
);
1008 memcpy(term
->media
.bmTransportModes
, &buffer
[10+n
], p
);
1012 usb_string(udev
, buffer
[7], term
->name
,
1014 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_CAMERA
)
1015 sprintf(term
->name
, "Camera %u", buffer
[3]);
1016 else if (UVC_ENTITY_TYPE(term
) == UVC_ITT_MEDIA_TRANSPORT_INPUT
)
1017 sprintf(term
->name
, "Media %u", buffer
[3]);
1019 sprintf(term
->name
, "Input %u", buffer
[3]);
1021 list_add_tail(&term
->list
, &dev
->entities
);
1024 case UVC_VC_OUTPUT_TERMINAL
:
1026 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1027 "interface %d OUTPUT_TERMINAL error\n",
1028 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1032 /* Make sure the terminal type MSB is not null, otherwise it
1033 * could be confused with a unit.
1035 type
= get_unaligned_le16(&buffer
[4]);
1036 if ((type
& 0xff00) == 0) {
1037 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1038 "interface %d OUTPUT_TERMINAL %d has invalid "
1039 "type 0x%04x, skipping\n", udev
->devnum
,
1040 alts
->desc
.bInterfaceNumber
, buffer
[3], type
);
1044 term
= uvc_alloc_entity(type
| UVC_TERM_OUTPUT
, buffer
[3],
1049 memcpy(term
->baSourceID
, &buffer
[7], 1);
1052 usb_string(udev
, buffer
[8], term
->name
,
1055 sprintf(term
->name
, "Output %u", buffer
[3]);
1057 list_add_tail(&term
->list
, &dev
->entities
);
1060 case UVC_VC_SELECTOR_UNIT
:
1061 p
= buflen
>= 5 ? buffer
[4] : 0;
1063 if (buflen
< 5 || buflen
< 6 + p
) {
1064 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1065 "interface %d SELECTOR_UNIT error\n",
1066 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1070 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], p
+ 1, 0);
1074 memcpy(unit
->baSourceID
, &buffer
[5], p
);
1076 if (buffer
[5+p
] != 0)
1077 usb_string(udev
, buffer
[5+p
], unit
->name
,
1080 sprintf(unit
->name
, "Selector %u", buffer
[3]);
1082 list_add_tail(&unit
->list
, &dev
->entities
);
1085 case UVC_VC_PROCESSING_UNIT
:
1086 n
= buflen
>= 8 ? buffer
[7] : 0;
1087 p
= dev
->uvc_version
>= 0x0110 ? 10 : 9;
1089 if (buflen
< p
+ n
) {
1090 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1091 "interface %d PROCESSING_UNIT error\n",
1092 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1096 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], 2, n
);
1100 memcpy(unit
->baSourceID
, &buffer
[4], 1);
1101 unit
->processing
.wMaxMultiplier
=
1102 get_unaligned_le16(&buffer
[5]);
1103 unit
->processing
.bControlSize
= buffer
[7];
1104 unit
->processing
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1105 memcpy(unit
->processing
.bmControls
, &buffer
[8], n
);
1106 if (dev
->uvc_version
>= 0x0110)
1107 unit
->processing
.bmVideoStandards
= buffer
[9+n
];
1109 if (buffer
[8+n
] != 0)
1110 usb_string(udev
, buffer
[8+n
], unit
->name
,
1113 sprintf(unit
->name
, "Processing %u", buffer
[3]);
1115 list_add_tail(&unit
->list
, &dev
->entities
);
1118 case UVC_VC_EXTENSION_UNIT
:
1119 p
= buflen
>= 22 ? buffer
[21] : 0;
1120 n
= buflen
>= 24 + p
? buffer
[22+p
] : 0;
1122 if (buflen
< 24 + p
+ n
) {
1123 uvc_trace(UVC_TRACE_DESCR
, "device %d videocontrol "
1124 "interface %d EXTENSION_UNIT error\n",
1125 udev
->devnum
, alts
->desc
.bInterfaceNumber
);
1129 unit
= uvc_alloc_entity(buffer
[2], buffer
[3], p
+ 1, n
);
1133 memcpy(unit
->extension
.guidExtensionCode
, &buffer
[4], 16);
1134 unit
->extension
.bNumControls
= buffer
[20];
1135 memcpy(unit
->baSourceID
, &buffer
[22], p
);
1136 unit
->extension
.bControlSize
= buffer
[22+p
];
1137 unit
->extension
.bmControls
= (__u8
*)unit
+ sizeof *unit
;
1138 memcpy(unit
->extension
.bmControls
, &buffer
[23+p
], n
);
1140 if (buffer
[23+p
+n
] != 0)
1141 usb_string(udev
, buffer
[23+p
+n
], unit
->name
,
1144 sprintf(unit
->name
, "Extension %u", buffer
[3]);
1146 list_add_tail(&unit
->list
, &dev
->entities
);
1150 uvc_trace(UVC_TRACE_DESCR
, "Found an unknown CS_INTERFACE "
1151 "descriptor (%u)\n", buffer
[2]);
1158 static int uvc_parse_control(struct uvc_device
*dev
)
1160 struct usb_host_interface
*alts
= dev
->intf
->cur_altsetting
;
1161 unsigned char *buffer
= alts
->extra
;
1162 int buflen
= alts
->extralen
;
1165 /* Parse the default alternate setting only, as the UVC specification
1166 * defines a single alternate setting, the default alternate setting
1170 while (buflen
> 2) {
1171 if (uvc_parse_vendor_control(dev
, buffer
, buflen
) ||
1172 buffer
[1] != USB_DT_CS_INTERFACE
)
1173 goto next_descriptor
;
1175 if ((ret
= uvc_parse_standard_control(dev
, buffer
, buflen
)) < 0)
1179 buflen
-= buffer
[0];
1180 buffer
+= buffer
[0];
1183 /* Check if the optional status endpoint is present. Built-in iSight
1184 * webcams have an interrupt endpoint but spit proprietary data that
1185 * don't conform to the UVC status endpoint messages. Don't try to
1186 * handle the interrupt endpoint for those cameras.
1188 if (alts
->desc
.bNumEndpoints
== 1 &&
1189 !(dev
->quirks
& UVC_QUIRK_BUILTIN_ISIGHT
)) {
1190 struct usb_host_endpoint
*ep
= &alts
->endpoint
[0];
1191 struct usb_endpoint_descriptor
*desc
= &ep
->desc
;
1193 if (usb_endpoint_is_int_in(desc
) &&
1194 le16_to_cpu(desc
->wMaxPacketSize
) >= 8 &&
1195 desc
->bInterval
!= 0) {
1196 uvc_trace(UVC_TRACE_DESCR
, "Found a Status endpoint "
1197 "(addr %02x).\n", desc
->bEndpointAddress
);
1205 /* ------------------------------------------------------------------------
1210 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1211 * and containing the following units:
1213 * - one or more Output Terminals (USB Streaming or Display)
1214 * - zero or one Processing Unit
1215 * - zero, one or more single-input Selector Units
1216 * - zero or one multiple-input Selector Units, provided all inputs are
1217 * connected to input terminals
1218 * - zero, one or mode single-input Extension Units
1219 * - one or more Input Terminals (Camera, External or USB Streaming)
1221 * The terminal and units must match on of the following structures:
1223 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1224 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1225 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1227 * +---------+ +---------+ -> OTT_*(0)
1228 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1229 * +---------+ +---------+ -> OTT_*(n)
1231 * The Processing Unit and Extension Units can be in any order. Additional
1232 * Extension Units connected to the main chain as single-unit branches are
1233 * also supported. Single-input Selector Units are ignored.
1235 static int uvc_scan_chain_entity(struct uvc_video_chain
*chain
,
1236 struct uvc_entity
*entity
)
1238 switch (UVC_ENTITY_TYPE(entity
)) {
1239 case UVC_VC_EXTENSION_UNIT
:
1240 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1241 printk(" <- XU %d", entity
->id
);
1243 if (entity
->bNrInPins
!= 1) {
1244 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d has more "
1245 "than 1 input pin.\n", entity
->id
);
1251 case UVC_VC_PROCESSING_UNIT
:
1252 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1253 printk(" <- PU %d", entity
->id
);
1255 if (chain
->processing
!= NULL
) {
1256 uvc_trace(UVC_TRACE_DESCR
, "Found multiple "
1257 "Processing Units in chain.\n");
1261 chain
->processing
= entity
;
1264 case UVC_VC_SELECTOR_UNIT
:
1265 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1266 printk(" <- SU %d", entity
->id
);
1268 /* Single-input selector units are ignored. */
1269 if (entity
->bNrInPins
== 1)
1272 if (chain
->selector
!= NULL
) {
1273 uvc_trace(UVC_TRACE_DESCR
, "Found multiple Selector "
1274 "Units in chain.\n");
1278 chain
->selector
= entity
;
1281 case UVC_ITT_VENDOR_SPECIFIC
:
1282 case UVC_ITT_CAMERA
:
1283 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1284 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1285 printk(" <- IT %d\n", entity
->id
);
1289 case UVC_OTT_VENDOR_SPECIFIC
:
1290 case UVC_OTT_DISPLAY
:
1291 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1292 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1293 printk(" OT %d", entity
->id
);
1297 case UVC_TT_STREAMING
:
1298 if (UVC_ENTITY_IS_ITERM(entity
)) {
1299 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1300 printk(" <- IT %d\n", entity
->id
);
1302 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1303 printk(" OT %d", entity
->id
);
1309 uvc_trace(UVC_TRACE_DESCR
, "Unsupported entity type "
1310 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity
));
1314 list_add_tail(&entity
->chain
, &chain
->entities
);
1318 static int uvc_scan_chain_forward(struct uvc_video_chain
*chain
,
1319 struct uvc_entity
*entity
, struct uvc_entity
*prev
)
1321 struct uvc_entity
*forward
;
1329 forward
= uvc_entity_by_reference(chain
->dev
, entity
->id
,
1331 if (forward
== NULL
)
1333 if (forward
== prev
)
1336 switch (UVC_ENTITY_TYPE(forward
)) {
1337 case UVC_VC_EXTENSION_UNIT
:
1338 if (forward
->bNrInPins
!= 1) {
1339 uvc_trace(UVC_TRACE_DESCR
, "Extension unit %d "
1340 "has more than 1 input pin.\n",
1345 list_add_tail(&forward
->chain
, &chain
->entities
);
1346 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1350 printk(" XU %d", forward
->id
);
1355 case UVC_OTT_VENDOR_SPECIFIC
:
1356 case UVC_OTT_DISPLAY
:
1357 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1358 case UVC_TT_STREAMING
:
1359 if (UVC_ENTITY_IS_ITERM(forward
)) {
1360 uvc_trace(UVC_TRACE_DESCR
, "Unsupported input "
1361 "terminal %u.\n", forward
->id
);
1365 list_add_tail(&forward
->chain
, &chain
->entities
);
1366 if (uvc_trace_param
& UVC_TRACE_PROBE
) {
1370 printk(" OT %d", forward
->id
);
1382 static int uvc_scan_chain_backward(struct uvc_video_chain
*chain
,
1383 struct uvc_entity
**_entity
)
1385 struct uvc_entity
*entity
= *_entity
;
1386 struct uvc_entity
*term
;
1387 int id
= -EINVAL
, i
;
1389 switch (UVC_ENTITY_TYPE(entity
)) {
1390 case UVC_VC_EXTENSION_UNIT
:
1391 case UVC_VC_PROCESSING_UNIT
:
1392 id
= entity
->baSourceID
[0];
1395 case UVC_VC_SELECTOR_UNIT
:
1396 /* Single-input selector units are ignored. */
1397 if (entity
->bNrInPins
== 1) {
1398 id
= entity
->baSourceID
[0];
1402 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1405 chain
->selector
= entity
;
1406 for (i
= 0; i
< entity
->bNrInPins
; ++i
) {
1407 id
= entity
->baSourceID
[i
];
1408 term
= uvc_entity_by_id(chain
->dev
, id
);
1409 if (term
== NULL
|| !UVC_ENTITY_IS_ITERM(term
)) {
1410 uvc_trace(UVC_TRACE_DESCR
, "Selector unit %d "
1411 "input %d isn't connected to an "
1412 "input terminal\n", entity
->id
, i
);
1416 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1417 printk(" %d", term
->id
);
1419 list_add_tail(&term
->chain
, &chain
->entities
);
1420 uvc_scan_chain_forward(chain
, term
, entity
);
1423 if (uvc_trace_param
& UVC_TRACE_PROBE
)
1429 case UVC_ITT_VENDOR_SPECIFIC
:
1430 case UVC_ITT_CAMERA
:
1431 case UVC_ITT_MEDIA_TRANSPORT_INPUT
:
1432 case UVC_OTT_VENDOR_SPECIFIC
:
1433 case UVC_OTT_DISPLAY
:
1434 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT
:
1435 case UVC_TT_STREAMING
:
1436 id
= UVC_ENTITY_IS_OTERM(entity
) ? entity
->baSourceID
[0] : 0;
1445 entity
= uvc_entity_by_id(chain
->dev
, id
);
1446 if (entity
== NULL
) {
1447 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1448 "unknown entity %d.\n", id
);
1456 static int uvc_scan_chain(struct uvc_video_chain
*chain
,
1457 struct uvc_entity
*term
)
1459 struct uvc_entity
*entity
, *prev
;
1461 uvc_trace(UVC_TRACE_PROBE
, "Scanning UVC chain:");
1466 while (entity
!= NULL
) {
1467 /* Entity must not be part of an existing chain */
1468 if (entity
->chain
.next
|| entity
->chain
.prev
) {
1469 uvc_trace(UVC_TRACE_DESCR
, "Found reference to "
1470 "entity %d already in chain.\n", entity
->id
);
1474 /* Process entity */
1475 if (uvc_scan_chain_entity(chain
, entity
) < 0)
1479 if (uvc_scan_chain_forward(chain
, entity
, prev
) < 0)
1484 if (uvc_scan_chain_backward(chain
, &entity
) < 0)
1491 static unsigned int uvc_print_terms(struct list_head
*terms
, u16 dir
,
1494 struct uvc_entity
*term
;
1495 unsigned int nterms
= 0;
1498 list_for_each_entry(term
, terms
, chain
) {
1499 if (!UVC_ENTITY_IS_TERM(term
) ||
1500 UVC_TERM_DIRECTION(term
) != dir
)
1504 p
+= sprintf(p
, ",");
1505 if (++nterms
>= 4) {
1506 p
+= sprintf(p
, "...");
1509 p
+= sprintf(p
, "%u", term
->id
);
1515 static const char *uvc_print_chain(struct uvc_video_chain
*chain
)
1517 static char buffer
[43];
1520 p
+= uvc_print_terms(&chain
->entities
, UVC_TERM_INPUT
, p
);
1521 p
+= sprintf(p
, " -> ");
1522 uvc_print_terms(&chain
->entities
, UVC_TERM_OUTPUT
, p
);
1528 * Scan the device for video chains and register video devices.
1530 * Chains are scanned starting at their output terminals and walked backwards.
1532 static int uvc_scan_device(struct uvc_device
*dev
)
1534 struct uvc_video_chain
*chain
;
1535 struct uvc_entity
*term
;
1537 list_for_each_entry(term
, &dev
->entities
, list
) {
1538 if (!UVC_ENTITY_IS_OTERM(term
))
1541 /* If the terminal is already included in a chain, skip it.
1542 * This can happen for chains that have multiple output
1543 * terminals, where all output terminals beside the first one
1544 * will be inserted in the chain in forward scans.
1546 if (term
->chain
.next
|| term
->chain
.prev
)
1549 chain
= kzalloc(sizeof(*chain
), GFP_KERNEL
);
1553 INIT_LIST_HEAD(&chain
->entities
);
1554 mutex_init(&chain
->ctrl_mutex
);
1557 if (uvc_scan_chain(chain
, term
) < 0) {
1562 uvc_trace(UVC_TRACE_PROBE
, "Found a valid video chain (%s).\n",
1563 uvc_print_chain(chain
));
1565 list_add_tail(&chain
->list
, &dev
->chains
);
1568 if (list_empty(&dev
->chains
)) {
1569 uvc_printk(KERN_INFO
, "No valid video chain found.\n");
1576 /* ------------------------------------------------------------------------
1577 * Video device registration and unregistration
1581 * Delete the UVC device.
1583 * Called by the kernel when the last reference to the uvc_device structure
1586 * As this function is called after or during disconnect(), all URBs have
1587 * already been canceled by the USB core. There is no need to kill the
1588 * interrupt URB manually.
1590 static void uvc_delete(struct uvc_device
*dev
)
1592 struct list_head
*p
, *n
;
1594 usb_put_intf(dev
->intf
);
1595 usb_put_dev(dev
->udev
);
1597 uvc_status_cleanup(dev
);
1598 uvc_ctrl_cleanup_device(dev
);
1601 v4l2_device_unregister(&dev
->vdev
);
1602 #ifdef CONFIG_MEDIA_CONTROLLER
1603 if (media_devnode_is_registered(&dev
->mdev
.devnode
))
1604 media_device_unregister(&dev
->mdev
);
1607 list_for_each_safe(p
, n
, &dev
->chains
) {
1608 struct uvc_video_chain
*chain
;
1609 chain
= list_entry(p
, struct uvc_video_chain
, list
);
1613 list_for_each_safe(p
, n
, &dev
->entities
) {
1614 struct uvc_entity
*entity
;
1615 entity
= list_entry(p
, struct uvc_entity
, list
);
1616 #ifdef CONFIG_MEDIA_CONTROLLER
1617 uvc_mc_cleanup_entity(entity
);
1620 video_device_release(entity
->vdev
);
1621 entity
->vdev
= NULL
;
1626 list_for_each_safe(p
, n
, &dev
->streams
) {
1627 struct uvc_streaming
*streaming
;
1628 streaming
= list_entry(p
, struct uvc_streaming
, list
);
1629 usb_driver_release_interface(&uvc_driver
.driver
,
1631 usb_put_intf(streaming
->intf
);
1632 kfree(streaming
->format
);
1633 kfree(streaming
->header
.bmaControls
);
1640 static void uvc_release(struct video_device
*vdev
)
1642 struct uvc_streaming
*stream
= video_get_drvdata(vdev
);
1643 struct uvc_device
*dev
= stream
->dev
;
1645 /* Decrement the registered streams count and delete the device when it
1648 if (atomic_dec_and_test(&dev
->nstreams
))
1653 * Unregister the video devices.
1655 static void uvc_unregister_video(struct uvc_device
*dev
)
1657 struct uvc_streaming
*stream
;
1659 /* Unregistering all video devices might result in uvc_delete() being
1660 * called from inside the loop if there's no open file handle. To avoid
1661 * that, increment the stream count before iterating over the streams
1662 * and decrement it when done.
1664 atomic_inc(&dev
->nstreams
);
1666 list_for_each_entry(stream
, &dev
->streams
, list
) {
1667 if (stream
->vdev
== NULL
)
1670 video_unregister_device(stream
->vdev
);
1671 stream
->vdev
= NULL
;
1674 /* Decrement the stream count and call uvc_delete explicitly if there
1675 * are no stream left.
1677 if (atomic_dec_and_test(&dev
->nstreams
))
1681 static int uvc_register_video(struct uvc_device
*dev
,
1682 struct uvc_streaming
*stream
)
1684 struct video_device
*vdev
;
1687 /* Initialize the streaming interface with default streaming
1690 ret
= uvc_video_init(stream
);
1692 uvc_printk(KERN_ERR
, "Failed to initialize the device "
1697 /* Register the device with V4L. */
1698 vdev
= video_device_alloc();
1700 uvc_printk(KERN_ERR
, "Failed to allocate video device (%d).\n",
1705 /* We already hold a reference to dev->udev. The video device will be
1706 * unregistered before the reference is released, so we don't need to
1709 vdev
->v4l2_dev
= &dev
->vdev
;
1710 vdev
->fops
= &uvc_fops
;
1711 vdev
->release
= uvc_release
;
1712 strlcpy(vdev
->name
, dev
->name
, sizeof vdev
->name
);
1714 /* Set the driver data before calling video_register_device, otherwise
1715 * uvc_v4l2_open might race us.
1717 stream
->vdev
= vdev
;
1718 video_set_drvdata(vdev
, stream
);
1720 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1722 uvc_printk(KERN_ERR
, "Failed to register video device (%d).\n",
1724 stream
->vdev
= NULL
;
1725 video_device_release(vdev
);
1729 atomic_inc(&dev
->nstreams
);
1734 * Register all video devices in all chains.
1736 static int uvc_register_terms(struct uvc_device
*dev
,
1737 struct uvc_video_chain
*chain
)
1739 struct uvc_streaming
*stream
;
1740 struct uvc_entity
*term
;
1743 list_for_each_entry(term
, &chain
->entities
, chain
) {
1744 if (UVC_ENTITY_TYPE(term
) != UVC_TT_STREAMING
)
1747 stream
= uvc_stream_by_id(dev
, term
->id
);
1748 if (stream
== NULL
) {
1749 uvc_printk(KERN_INFO
, "No streaming interface found "
1750 "for terminal %u.", term
->id
);
1754 stream
->chain
= chain
;
1755 ret
= uvc_register_video(dev
, stream
);
1759 term
->vdev
= stream
->vdev
;
1765 static int uvc_register_chains(struct uvc_device
*dev
)
1767 struct uvc_video_chain
*chain
;
1770 list_for_each_entry(chain
, &dev
->chains
, list
) {
1771 ret
= uvc_register_terms(dev
, chain
);
1775 #ifdef CONFIG_MEDIA_CONTROLLER
1776 ret
= uvc_mc_register_entities(chain
);
1778 uvc_printk(KERN_INFO
, "Failed to register entites "
1787 /* ------------------------------------------------------------------------
1788 * USB probe, disconnect, suspend and resume
1791 static int uvc_probe(struct usb_interface
*intf
,
1792 const struct usb_device_id
*id
)
1794 struct usb_device
*udev
= interface_to_usbdev(intf
);
1795 struct uvc_device
*dev
;
1798 if (id
->idVendor
&& id
->idProduct
)
1799 uvc_trace(UVC_TRACE_PROBE
, "Probing known UVC device %s "
1800 "(%04x:%04x)\n", udev
->devpath
, id
->idVendor
,
1803 uvc_trace(UVC_TRACE_PROBE
, "Probing generic UVC device %s\n",
1806 /* Allocate memory for the device and initialize it. */
1807 if ((dev
= kzalloc(sizeof *dev
, GFP_KERNEL
)) == NULL
)
1810 INIT_LIST_HEAD(&dev
->entities
);
1811 INIT_LIST_HEAD(&dev
->chains
);
1812 INIT_LIST_HEAD(&dev
->streams
);
1813 atomic_set(&dev
->nstreams
, 0);
1814 atomic_set(&dev
->users
, 0);
1815 atomic_set(&dev
->nmappings
, 0);
1817 dev
->udev
= usb_get_dev(udev
);
1818 dev
->intf
= usb_get_intf(intf
);
1819 dev
->intfnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
1820 dev
->quirks
= (uvc_quirks_param
== -1)
1821 ? id
->driver_info
: uvc_quirks_param
;
1823 if (udev
->product
!= NULL
)
1824 strlcpy(dev
->name
, udev
->product
, sizeof dev
->name
);
1826 snprintf(dev
->name
, sizeof dev
->name
,
1827 "UVC Camera (%04x:%04x)",
1828 le16_to_cpu(udev
->descriptor
.idVendor
),
1829 le16_to_cpu(udev
->descriptor
.idProduct
));
1831 /* Parse the Video Class control descriptor. */
1832 if (uvc_parse_control(dev
) < 0) {
1833 uvc_trace(UVC_TRACE_PROBE
, "Unable to parse UVC "
1838 uvc_printk(KERN_INFO
, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1839 dev
->uvc_version
>> 8, dev
->uvc_version
& 0xff,
1840 udev
->product
? udev
->product
: "<unnamed>",
1841 le16_to_cpu(udev
->descriptor
.idVendor
),
1842 le16_to_cpu(udev
->descriptor
.idProduct
));
1844 if (dev
->quirks
!= id
->driver_info
) {
1845 uvc_printk(KERN_INFO
, "Forcing device quirks to 0x%x by module "
1846 "parameter for testing purpose.\n", dev
->quirks
);
1847 uvc_printk(KERN_INFO
, "Please report required quirks to the "
1848 "linux-uvc-devel mailing list.\n");
1851 /* Register the media and V4L2 devices. */
1852 #ifdef CONFIG_MEDIA_CONTROLLER
1853 dev
->mdev
.dev
= &intf
->dev
;
1854 strlcpy(dev
->mdev
.model
, dev
->name
, sizeof(dev
->mdev
.model
));
1856 strlcpy(dev
->mdev
.serial
, udev
->serial
,
1857 sizeof(dev
->mdev
.serial
));
1858 strcpy(dev
->mdev
.bus_info
, udev
->devpath
);
1859 dev
->mdev
.hw_revision
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
1860 dev
->mdev
.driver_version
= DRIVER_VERSION_NUMBER
;
1861 if (media_device_register(&dev
->mdev
) < 0)
1864 dev
->vdev
.mdev
= &dev
->mdev
;
1866 if (v4l2_device_register(&intf
->dev
, &dev
->vdev
) < 0)
1869 /* Initialize controls. */
1870 if (uvc_ctrl_init_device(dev
) < 0)
1873 /* Scan the device for video chains. */
1874 if (uvc_scan_device(dev
) < 0)
1877 /* Register video device nodes. */
1878 if (uvc_register_chains(dev
) < 0)
1881 /* Save our data pointer in the interface data. */
1882 usb_set_intfdata(intf
, dev
);
1884 /* Initialize the interrupt URB. */
1885 if ((ret
= uvc_status_init(dev
)) < 0) {
1886 uvc_printk(KERN_INFO
, "Unable to initialize the status "
1887 "endpoint (%d), status interrupt will not be "
1888 "supported.\n", ret
);
1891 uvc_trace(UVC_TRACE_PROBE
, "UVC device initialized.\n");
1892 usb_enable_autosuspend(udev
);
1896 uvc_unregister_video(dev
);
1900 static void uvc_disconnect(struct usb_interface
*intf
)
1902 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1904 /* Set the USB interface data to NULL. This can be done outside the
1905 * lock, as there's no other reader.
1907 usb_set_intfdata(intf
, NULL
);
1909 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1910 UVC_SC_VIDEOSTREAMING
)
1913 dev
->state
|= UVC_DEV_DISCONNECTED
;
1915 uvc_unregister_video(dev
);
1918 static int uvc_suspend(struct usb_interface
*intf
, pm_message_t message
)
1920 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1921 struct uvc_streaming
*stream
;
1923 uvc_trace(UVC_TRACE_SUSPEND
, "Suspending interface %u\n",
1924 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1926 /* Controls are cached on the fly so they don't need to be saved. */
1927 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1928 UVC_SC_VIDEOCONTROL
)
1929 return uvc_status_suspend(dev
);
1931 list_for_each_entry(stream
, &dev
->streams
, list
) {
1932 if (stream
->intf
== intf
)
1933 return uvc_video_suspend(stream
);
1936 uvc_trace(UVC_TRACE_SUSPEND
, "Suspend: video streaming USB interface "
1941 static int __uvc_resume(struct usb_interface
*intf
, int reset
)
1943 struct uvc_device
*dev
= usb_get_intfdata(intf
);
1944 struct uvc_streaming
*stream
;
1946 uvc_trace(UVC_TRACE_SUSPEND
, "Resuming interface %u\n",
1947 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1949 if (intf
->cur_altsetting
->desc
.bInterfaceSubClass
==
1950 UVC_SC_VIDEOCONTROL
) {
1952 int ret
= uvc_ctrl_resume_device(dev
);
1958 return uvc_status_resume(dev
);
1961 list_for_each_entry(stream
, &dev
->streams
, list
) {
1962 if (stream
->intf
== intf
)
1963 return uvc_video_resume(stream
);
1966 uvc_trace(UVC_TRACE_SUSPEND
, "Resume: video streaming USB interface "
1971 static int uvc_resume(struct usb_interface
*intf
)
1973 return __uvc_resume(intf
, 0);
1976 static int uvc_reset_resume(struct usb_interface
*intf
)
1978 return __uvc_resume(intf
, 1);
1981 /* ------------------------------------------------------------------------
1985 static int uvc_clock_param_get(char *buffer
, struct kernel_param
*kp
)
1987 if (uvc_clock_param
== CLOCK_MONOTONIC
)
1988 return sprintf(buffer
, "CLOCK_MONOTONIC");
1990 return sprintf(buffer
, "CLOCK_REALTIME");
1993 static int uvc_clock_param_set(const char *val
, struct kernel_param
*kp
)
1995 if (strncasecmp(val
, "clock_", strlen("clock_")) == 0)
1996 val
+= strlen("clock_");
1998 if (strcasecmp(val
, "monotonic") == 0)
1999 uvc_clock_param
= CLOCK_MONOTONIC
;
2000 else if (strcasecmp(val
, "realtime") == 0)
2001 uvc_clock_param
= CLOCK_REALTIME
;
2008 module_param_call(clock
, uvc_clock_param_set
, uvc_clock_param_get
,
2009 &uvc_clock_param
, S_IRUGO
|S_IWUSR
);
2010 MODULE_PARM_DESC(clock
, "Video buffers timestamp clock");
2011 module_param_named(nodrop
, uvc_no_drop_param
, uint
, S_IRUGO
|S_IWUSR
);
2012 MODULE_PARM_DESC(nodrop
, "Don't drop incomplete frames");
2013 module_param_named(quirks
, uvc_quirks_param
, uint
, S_IRUGO
|S_IWUSR
);
2014 MODULE_PARM_DESC(quirks
, "Forced device quirks");
2015 module_param_named(trace
, uvc_trace_param
, uint
, S_IRUGO
|S_IWUSR
);
2016 MODULE_PARM_DESC(trace
, "Trace level bitmask");
2017 module_param_named(timeout
, uvc_timeout_param
, uint
, S_IRUGO
|S_IWUSR
);
2018 MODULE_PARM_DESC(timeout
, "Streaming control requests timeout");
2020 /* ------------------------------------------------------------------------
2021 * Driver initialization and cleanup
2025 * The Logitech cameras listed below have their interface class set to
2026 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2027 * though they are compliant.
2029 static struct usb_device_id uvc_ids
[] = {
2030 /* Genius eFace 2025 */
2031 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2032 | USB_DEVICE_ID_MATCH_INT_INFO
,
2034 .idProduct
= 0x706e,
2035 .bInterfaceClass
= USB_CLASS_VIDEO
,
2036 .bInterfaceSubClass
= 1,
2037 .bInterfaceProtocol
= 0,
2038 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2039 /* Microsoft Lifecam NX-6000 */
2040 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2041 | USB_DEVICE_ID_MATCH_INT_INFO
,
2043 .idProduct
= 0x00f8,
2044 .bInterfaceClass
= USB_CLASS_VIDEO
,
2045 .bInterfaceSubClass
= 1,
2046 .bInterfaceProtocol
= 0,
2047 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2048 /* Microsoft Lifecam VX-7000 */
2049 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2050 | USB_DEVICE_ID_MATCH_INT_INFO
,
2052 .idProduct
= 0x0723,
2053 .bInterfaceClass
= USB_CLASS_VIDEO
,
2054 .bInterfaceSubClass
= 1,
2055 .bInterfaceProtocol
= 0,
2056 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2057 /* Logitech Quickcam Fusion */
2058 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2059 | USB_DEVICE_ID_MATCH_INT_INFO
,
2061 .idProduct
= 0x08c1,
2062 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2063 .bInterfaceSubClass
= 1,
2064 .bInterfaceProtocol
= 0 },
2065 /* Logitech Quickcam Orbit MP */
2066 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2067 | USB_DEVICE_ID_MATCH_INT_INFO
,
2069 .idProduct
= 0x08c2,
2070 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2071 .bInterfaceSubClass
= 1,
2072 .bInterfaceProtocol
= 0 },
2073 /* Logitech Quickcam Pro for Notebook */
2074 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2075 | USB_DEVICE_ID_MATCH_INT_INFO
,
2077 .idProduct
= 0x08c3,
2078 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2079 .bInterfaceSubClass
= 1,
2080 .bInterfaceProtocol
= 0 },
2081 /* Logitech Quickcam Pro 5000 */
2082 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2083 | USB_DEVICE_ID_MATCH_INT_INFO
,
2085 .idProduct
= 0x08c5,
2086 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2087 .bInterfaceSubClass
= 1,
2088 .bInterfaceProtocol
= 0 },
2089 /* Logitech Quickcam OEM Dell Notebook */
2090 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2091 | USB_DEVICE_ID_MATCH_INT_INFO
,
2093 .idProduct
= 0x08c6,
2094 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2095 .bInterfaceSubClass
= 1,
2096 .bInterfaceProtocol
= 0 },
2097 /* Logitech Quickcam OEM Cisco VT Camera II */
2098 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2099 | USB_DEVICE_ID_MATCH_INT_INFO
,
2101 .idProduct
= 0x08c7,
2102 .bInterfaceClass
= USB_CLASS_VENDOR_SPEC
,
2103 .bInterfaceSubClass
= 1,
2104 .bInterfaceProtocol
= 0 },
2105 /* Chicony CNF7129 (Asus EEE 100HE) */
2106 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2107 | USB_DEVICE_ID_MATCH_INT_INFO
,
2109 .idProduct
= 0xb071,
2110 .bInterfaceClass
= USB_CLASS_VIDEO
,
2111 .bInterfaceSubClass
= 1,
2112 .bInterfaceProtocol
= 0,
2113 .driver_info
= UVC_QUIRK_RESTRICT_FRAME_RATE
},
2114 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2115 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2116 | USB_DEVICE_ID_MATCH_INT_INFO
,
2118 .idProduct
= 0x3820,
2119 .bInterfaceClass
= USB_CLASS_VIDEO
,
2120 .bInterfaceSubClass
= 1,
2121 .bInterfaceProtocol
= 0,
2122 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2123 /* Apple Built-In iSight */
2124 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2125 | USB_DEVICE_ID_MATCH_INT_INFO
,
2127 .idProduct
= 0x8501,
2128 .bInterfaceClass
= USB_CLASS_VIDEO
,
2129 .bInterfaceSubClass
= 1,
2130 .bInterfaceProtocol
= 0,
2131 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2132 | UVC_QUIRK_BUILTIN_ISIGHT
},
2133 /* Genesys Logic USB 2.0 PC Camera */
2134 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2135 | USB_DEVICE_ID_MATCH_INT_INFO
,
2137 .idProduct
= 0x0505,
2138 .bInterfaceClass
= USB_CLASS_VIDEO
,
2139 .bInterfaceSubClass
= 1,
2140 .bInterfaceProtocol
= 0,
2141 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2142 /* Hercules Classic Silver */
2143 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2144 | USB_DEVICE_ID_MATCH_INT_INFO
,
2146 .idProduct
= 0x300c,
2147 .bInterfaceClass
= USB_CLASS_VIDEO
,
2148 .bInterfaceSubClass
= 1,
2149 .bInterfaceProtocol
= 0,
2150 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2152 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2153 | USB_DEVICE_ID_MATCH_INT_INFO
,
2155 .idProduct
= 0x332d,
2156 .bInterfaceClass
= USB_CLASS_VIDEO
,
2157 .bInterfaceSubClass
= 1,
2158 .bInterfaceProtocol
= 0,
2159 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2160 /* ViMicro - Minoru3D */
2161 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2162 | USB_DEVICE_ID_MATCH_INT_INFO
,
2164 .idProduct
= 0x3410,
2165 .bInterfaceClass
= USB_CLASS_VIDEO
,
2166 .bInterfaceSubClass
= 1,
2167 .bInterfaceProtocol
= 0,
2168 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2169 /* ViMicro Venus - Minoru3D */
2170 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2171 | USB_DEVICE_ID_MATCH_INT_INFO
,
2173 .idProduct
= 0x3420,
2174 .bInterfaceClass
= USB_CLASS_VIDEO
,
2175 .bInterfaceSubClass
= 1,
2176 .bInterfaceProtocol
= 0,
2177 .driver_info
= UVC_QUIRK_FIX_BANDWIDTH
},
2179 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2180 | USB_DEVICE_ID_MATCH_INT_INFO
,
2182 .idProduct
= 0x0004,
2183 .bInterfaceClass
= USB_CLASS_VIDEO
,
2184 .bInterfaceSubClass
= 1,
2185 .bInterfaceProtocol
= 0,
2186 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2187 | UVC_QUIRK_PROBE_DEF
},
2188 /* IMC Networks (Medion Akoya) */
2189 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2190 | USB_DEVICE_ID_MATCH_INT_INFO
,
2192 .idProduct
= 0x5103,
2193 .bInterfaceClass
= USB_CLASS_VIDEO
,
2194 .bInterfaceSubClass
= 1,
2195 .bInterfaceProtocol
= 0,
2196 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2197 /* JMicron USB2.0 XGA WebCam */
2198 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2199 | USB_DEVICE_ID_MATCH_INT_INFO
,
2201 .idProduct
= 0x0310,
2202 .bInterfaceClass
= USB_CLASS_VIDEO
,
2203 .bInterfaceSubClass
= 1,
2204 .bInterfaceProtocol
= 0,
2205 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2206 /* Syntek (HP Spartan) */
2207 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2208 | USB_DEVICE_ID_MATCH_INT_INFO
,
2210 .idProduct
= 0x5212,
2211 .bInterfaceClass
= USB_CLASS_VIDEO
,
2212 .bInterfaceSubClass
= 1,
2213 .bInterfaceProtocol
= 0,
2214 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2215 /* Syntek (Samsung Q310) */
2216 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2217 | USB_DEVICE_ID_MATCH_INT_INFO
,
2219 .idProduct
= 0x5931,
2220 .bInterfaceClass
= USB_CLASS_VIDEO
,
2221 .bInterfaceSubClass
= 1,
2222 .bInterfaceProtocol
= 0,
2223 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2224 /* Syntek (Packard Bell EasyNote MX52 */
2225 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2226 | USB_DEVICE_ID_MATCH_INT_INFO
,
2228 .idProduct
= 0x8a12,
2229 .bInterfaceClass
= USB_CLASS_VIDEO
,
2230 .bInterfaceSubClass
= 1,
2231 .bInterfaceProtocol
= 0,
2232 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2233 /* Syntek (Asus F9SG) */
2234 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2235 | USB_DEVICE_ID_MATCH_INT_INFO
,
2237 .idProduct
= 0x8a31,
2238 .bInterfaceClass
= USB_CLASS_VIDEO
,
2239 .bInterfaceSubClass
= 1,
2240 .bInterfaceProtocol
= 0,
2241 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2242 /* Syntek (Asus U3S) */
2243 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2244 | USB_DEVICE_ID_MATCH_INT_INFO
,
2246 .idProduct
= 0x8a33,
2247 .bInterfaceClass
= USB_CLASS_VIDEO
,
2248 .bInterfaceSubClass
= 1,
2249 .bInterfaceProtocol
= 0,
2250 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2251 /* Syntek (JAOtech Smart Terminal) */
2252 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2253 | USB_DEVICE_ID_MATCH_INT_INFO
,
2255 .idProduct
= 0x8a34,
2256 .bInterfaceClass
= USB_CLASS_VIDEO
,
2257 .bInterfaceSubClass
= 1,
2258 .bInterfaceProtocol
= 0,
2259 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2261 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2262 | USB_DEVICE_ID_MATCH_INT_INFO
,
2264 .idProduct
= 0x0202,
2265 .bInterfaceClass
= USB_CLASS_VIDEO
,
2266 .bInterfaceSubClass
= 1,
2267 .bInterfaceProtocol
= 0,
2268 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2269 /* Lenovo Thinkpad SL400/SL500 */
2270 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2271 | USB_DEVICE_ID_MATCH_INT_INFO
,
2273 .idProduct
= 0x480b,
2274 .bInterfaceClass
= USB_CLASS_VIDEO
,
2275 .bInterfaceSubClass
= 1,
2276 .bInterfaceProtocol
= 0,
2277 .driver_info
= UVC_QUIRK_STREAM_NO_FID
},
2278 /* Aveo Technology USB 2.0 Camera */
2279 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2280 | USB_DEVICE_ID_MATCH_INT_INFO
,
2282 .idProduct
= 0x0306,
2283 .bInterfaceClass
= USB_CLASS_VIDEO
,
2284 .bInterfaceSubClass
= 1,
2285 .bInterfaceProtocol
= 0,
2286 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2287 | UVC_QUIRK_PROBE_EXTRAFIELDS
},
2288 /* Ecamm Pico iMage */
2289 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2290 | USB_DEVICE_ID_MATCH_INT_INFO
,
2292 .idProduct
= 0xcafe,
2293 .bInterfaceClass
= USB_CLASS_VIDEO
,
2294 .bInterfaceSubClass
= 1,
2295 .bInterfaceProtocol
= 0,
2296 .driver_info
= UVC_QUIRK_PROBE_EXTRAFIELDS
},
2297 /* Manta MM-353 Plako */
2298 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2299 | USB_DEVICE_ID_MATCH_INT_INFO
,
2301 .idProduct
= 0x3188,
2302 .bInterfaceClass
= USB_CLASS_VIDEO
,
2303 .bInterfaceSubClass
= 1,
2304 .bInterfaceProtocol
= 0,
2305 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2306 /* FSC WebCam V30S */
2307 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2308 | USB_DEVICE_ID_MATCH_INT_INFO
,
2310 .idProduct
= 0x3288,
2311 .bInterfaceClass
= USB_CLASS_VIDEO
,
2312 .bInterfaceSubClass
= 1,
2313 .bInterfaceProtocol
= 0,
2314 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2315 /* Arkmicro unbranded */
2316 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2317 | USB_DEVICE_ID_MATCH_INT_INFO
,
2319 .idProduct
= 0x3290,
2320 .bInterfaceClass
= USB_CLASS_VIDEO
,
2321 .bInterfaceSubClass
= 1,
2322 .bInterfaceProtocol
= 0,
2323 .driver_info
= UVC_QUIRK_PROBE_DEF
},
2324 /* Bodelin ProScopeHR */
2325 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2326 | USB_DEVICE_ID_MATCH_DEV_HI
2327 | USB_DEVICE_ID_MATCH_INT_INFO
,
2329 .idProduct
= 0x1000,
2330 .bcdDevice_hi
= 0x0126,
2331 .bInterfaceClass
= USB_CLASS_VIDEO
,
2332 .bInterfaceSubClass
= 1,
2333 .bInterfaceProtocol
= 0,
2334 .driver_info
= UVC_QUIRK_STATUS_INTERVAL
},
2335 /* MSI StarCam 370i */
2336 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2337 | USB_DEVICE_ID_MATCH_INT_INFO
,
2339 .idProduct
= 0x2951,
2340 .bInterfaceClass
= USB_CLASS_VIDEO
,
2341 .bInterfaceSubClass
= 1,
2342 .bInterfaceProtocol
= 0,
2343 .driver_info
= UVC_QUIRK_PROBE_MINMAX
},
2344 /* SiGma Micro USB Web Camera */
2345 { .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
2346 | USB_DEVICE_ID_MATCH_INT_INFO
,
2348 .idProduct
= 0x3000,
2349 .bInterfaceClass
= USB_CLASS_VIDEO
,
2350 .bInterfaceSubClass
= 1,
2351 .bInterfaceProtocol
= 0,
2352 .driver_info
= UVC_QUIRK_PROBE_MINMAX
2353 | UVC_QUIRK_IGNORE_SELECTOR_UNIT
},
2354 /* Generic USB Video Class */
2355 { USB_INTERFACE_INFO(USB_CLASS_VIDEO
, 1, 0) },
2359 MODULE_DEVICE_TABLE(usb
, uvc_ids
);
2361 struct uvc_driver uvc_driver
= {
2365 .disconnect
= uvc_disconnect
,
2366 .suspend
= uvc_suspend
,
2367 .resume
= uvc_resume
,
2368 .reset_resume
= uvc_reset_resume
,
2369 .id_table
= uvc_ids
,
2370 .supports_autosuspend
= 1,
2374 static int __init
uvc_init(void)
2378 result
= usb_register(&uvc_driver
.driver
);
2380 printk(KERN_INFO DRIVER_DESC
" (" DRIVER_VERSION
")\n");
2384 static void __exit
uvc_cleanup(void)
2386 usb_deregister(&uvc_driver
.driver
);
2389 module_init(uvc_init
);
2390 module_exit(uvc_cleanup
);
2392 MODULE_AUTHOR(DRIVER_AUTHOR
);
2393 MODULE_DESCRIPTION(DRIVER_DESC
);
2394 MODULE_LICENSE("GPL");
2395 MODULE_VERSION(DRIVER_VERSION
);