[media] uvcvideo: Return -ENOTTY for unsupported ioctls
[deliverable/linux.git] / drivers / media / usb / uvc / uvc_driver.c
CommitLineData
c0efd232
LP
1/*
2 * uvc_driver.c -- USB Video Class driver
3 *
11fc5baf
LP
4 * Copyright (C) 2005-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
c0efd232
LP
6 *
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.
11 *
12 */
13
66ede038 14#include <linux/atomic.h>
c0efd232 15#include <linux/kernel.h>
c0efd232
LP
16#include <linux/list.h>
17#include <linux/module.h>
5a0e3ad6 18#include <linux/slab.h>
c0efd232
LP
19#include <linux/usb.h>
20#include <linux/videodev2.h>
21#include <linux/vmalloc.h>
22#include <linux/wait.h>
fd3e5824 23#include <linux/version.h>
9bc6218d 24#include <asm/unaligned.h>
c0efd232
LP
25
26#include <media/v4l2-common.h>
27
28#include "uvcvideo.h"
29
11fc5baf
LP
30#define DRIVER_AUTHOR "Laurent Pinchart " \
31 "<laurent.pinchart@ideasonboard.com>"
c0efd232 32#define DRIVER_DESC "USB Video Class driver"
c0efd232 33
310fe524 34unsigned int uvc_clock_param = CLOCK_MONOTONIC;
0fbd8ee6 35unsigned int uvc_no_drop_param;
73de3592 36static unsigned int uvc_quirks_param = -1;
c0efd232 37unsigned int uvc_trace_param;
b232a012 38unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
c0efd232
LP
39
40/* ------------------------------------------------------------------------
2c2d264b 41 * Video formats
c0efd232
LP
42 */
43
44static struct uvc_format_desc uvc_fmts[] = {
45 {
46 .name = "YUV 4:2:2 (YUYV)",
47 .guid = UVC_GUID_FORMAT_YUY2,
48 .fcc = V4L2_PIX_FMT_YUYV,
49 },
68f194e0
DR
50 {
51 .name = "YUV 4:2:2 (YUYV)",
52 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
53 .fcc = V4L2_PIX_FMT_YUYV,
54 },
c0efd232
LP
55 {
56 .name = "YUV 4:2:0 (NV12)",
57 .guid = UVC_GUID_FORMAT_NV12,
58 .fcc = V4L2_PIX_FMT_NV12,
59 },
60 {
61 .name = "MJPEG",
62 .guid = UVC_GUID_FORMAT_MJPEG,
63 .fcc = V4L2_PIX_FMT_MJPEG,
64 },
65 {
66 .name = "YVU 4:2:0 (YV12)",
67 .guid = UVC_GUID_FORMAT_YV12,
68 .fcc = V4L2_PIX_FMT_YVU420,
69 },
70 {
71 .name = "YUV 4:2:0 (I420)",
72 .guid = UVC_GUID_FORMAT_I420,
73 .fcc = V4L2_PIX_FMT_YUV420,
74 },
7225a1dc
HG
75 {
76 .name = "YUV 4:2:0 (M420)",
77 .guid = UVC_GUID_FORMAT_M420,
78 .fcc = V4L2_PIX_FMT_M420,
79 },
c0efd232
LP
80 {
81 .name = "YUV 4:2:2 (UYVY)",
82 .guid = UVC_GUID_FORMAT_UYVY,
83 .fcc = V4L2_PIX_FMT_UYVY,
84 },
85 {
ca47e719 86 .name = "Greyscale 8-bit (Y800)",
c0efd232
LP
87 .guid = UVC_GUID_FORMAT_Y800,
88 .fcc = V4L2_PIX_FMT_GREY,
89 },
61421206 90 {
ca47e719
SM
91 .name = "Greyscale 8-bit (Y8 )",
92 .guid = UVC_GUID_FORMAT_Y8,
93 .fcc = V4L2_PIX_FMT_GREY,
94 },
95 {
96 .name = "Greyscale 10-bit (Y10 )",
97 .guid = UVC_GUID_FORMAT_Y10,
98 .fcc = V4L2_PIX_FMT_Y10,
99 },
100 {
101 .name = "Greyscale 12-bit (Y12 )",
102 .guid = UVC_GUID_FORMAT_Y12,
103 .fcc = V4L2_PIX_FMT_Y12,
104 },
105 {
106 .name = "Greyscale 16-bit (Y16 )",
61421206
LP
107 .guid = UVC_GUID_FORMAT_Y16,
108 .fcc = V4L2_PIX_FMT_Y16,
109 },
c0efd232
LP
110 {
111 .name = "RGB Bayer",
112 .guid = UVC_GUID_FORMAT_BY8,
113 .fcc = V4L2_PIX_FMT_SBGGR8,
114 },
50791079
LP
115 {
116 .name = "RGB565",
117 .guid = UVC_GUID_FORMAT_RGBP,
118 .fcc = V4L2_PIX_FMT_RGB565,
119 },
25ad8a8d
SL
120 {
121 .name = "H.264",
122 .guid = UVC_GUID_FORMAT_H264,
123 .fcc = V4L2_PIX_FMT_H264,
124 },
c0efd232
LP
125};
126
127/* ------------------------------------------------------------------------
128 * Utility functions
129 */
130
131struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
132 __u8 epaddr)
133{
134 struct usb_host_endpoint *ep;
135 unsigned int i;
136
137 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
138 ep = &alts->endpoint[i];
139 if (ep->desc.bEndpointAddress == epaddr)
140 return ep;
141 }
142
143 return NULL;
144}
145
146static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
147{
148 unsigned int len = ARRAY_SIZE(uvc_fmts);
149 unsigned int i;
150
151 for (i = 0; i < len; ++i) {
152 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
153 return &uvc_fmts[i];
154 }
155
156 return NULL;
157}
158
159static __u32 uvc_colorspace(const __u8 primaries)
160{
161 static const __u8 colorprimaries[] = {
162 0,
163 V4L2_COLORSPACE_SRGB,
164 V4L2_COLORSPACE_470_SYSTEM_M,
165 V4L2_COLORSPACE_470_SYSTEM_BG,
166 V4L2_COLORSPACE_SMPTE170M,
167 V4L2_COLORSPACE_SMPTE240M,
168 };
169
170 if (primaries < ARRAY_SIZE(colorprimaries))
171 return colorprimaries[primaries];
172
173 return 0;
174}
175
176/* Simplify a fraction using a simple continued fraction decomposition. The
177 * idea here is to convert fractions such as 333333/10000000 to 1/30 using
178 * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
179 * arbitrary parameters to remove non-significative terms from the simple
180 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
181 * respectively seems to give nice results.
182 */
183void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
184 unsigned int n_terms, unsigned int threshold)
185{
186 uint32_t *an;
187 uint32_t x, y, r;
188 unsigned int i, n;
189
190 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
191 if (an == NULL)
192 return;
193
194 /* Convert the fraction to a simple continued fraction. See
195 * http://mathforum.org/dr.math/faq/faq.fractions.html
196 * Stop if the current term is bigger than or equal to the given
197 * threshold.
198 */
199 x = *numerator;
200 y = *denominator;
201
202 for (n = 0; n < n_terms && y != 0; ++n) {
203 an[n] = x / y;
204 if (an[n] >= threshold) {
205 if (n < 2)
206 n++;
207 break;
208 }
209
210 r = x - an[n] * y;
211 x = y;
212 y = r;
213 }
214
215 /* Expand the simple continued fraction back to an integer fraction. */
216 x = 0;
217 y = 1;
218
219 for (i = n; i > 0; --i) {
220 r = y;
221 y = an[i-1] * y + x;
222 x = r;
223 }
224
225 *numerator = y;
226 *denominator = x;
227 kfree(an);
228}
229
230/* Convert a fraction to a frame interval in 100ns multiples. The idea here is
231 * to compute numerator / denominator * 10000000 using 32 bit fixed point
232 * arithmetic only.
233 */
234uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
235{
236 uint32_t multiplier;
237
238 /* Saturate the result if the operation would overflow. */
239 if (denominator == 0 ||
240 numerator/denominator >= ((uint32_t)-1)/10000000)
241 return (uint32_t)-1;
242
243 /* Divide both the denominator and the multiplier by two until
244 * numerator * multiplier doesn't overflow. If anyone knows a better
245 * algorithm please let me know.
246 */
247 multiplier = 10000000;
248 while (numerator > ((uint32_t)-1)/multiplier) {
249 multiplier /= 2;
250 denominator /= 2;
251 }
252
253 return denominator ? numerator * multiplier / denominator : 0;
254}
255
256/* ------------------------------------------------------------------------
257 * Terminal and unit management
258 */
259
4ffc2d89 260struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
c0efd232
LP
261{
262 struct uvc_entity *entity;
263
264 list_for_each_entry(entity, &dev->entities, list) {
265 if (entity->id == id)
266 return entity;
267 }
268
269 return NULL;
270}
271
272static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
273 int id, struct uvc_entity *entity)
274{
275 unsigned int i;
276
277 if (entity == NULL)
278 entity = list_entry(&dev->entities, struct uvc_entity, list);
279
280 list_for_each_entry_continue(entity, &dev->entities, list) {
8ca5a639
LP
281 for (i = 0; i < entity->bNrInPins; ++i)
282 if (entity->baSourceID[i] == id)
c0efd232 283 return entity;
c0efd232
LP
284 }
285
286 return NULL;
287}
288
8e113595
LP
289static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
290{
291 struct uvc_streaming *stream;
292
293 list_for_each_entry(stream, &dev->streams, list) {
294 if (stream->header.bTerminalLink == id)
295 return stream;
296 }
297
298 return NULL;
299}
300
c0efd232 301/* ------------------------------------------------------------------------
8e113595 302 * Descriptors parsing
c0efd232
LP
303 */
304
305static int uvc_parse_format(struct uvc_device *dev,
306 struct uvc_streaming *streaming, struct uvc_format *format,
307 __u32 **intervals, unsigned char *buffer, int buflen)
308{
309 struct usb_interface *intf = streaming->intf;
310 struct usb_host_interface *alts = intf->cur_altsetting;
311 struct uvc_format_desc *fmtdesc;
312 struct uvc_frame *frame;
313 const unsigned char *start = buffer;
314 unsigned int interval;
315 unsigned int i, n;
316 __u8 ftype;
317
318 format->type = buffer[2];
319 format->index = buffer[3];
320
321 switch (buffer[2]) {
b482d923
LP
322 case UVC_VS_FORMAT_UNCOMPRESSED:
323 case UVC_VS_FORMAT_FRAME_BASED:
324 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
233548a2 325 if (buflen < n) {
b2d9cc42 326 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
327 "interface %d FORMAT error\n",
328 dev->udev->devnum,
329 alts->desc.bInterfaceNumber);
330 return -EINVAL;
331 }
332
333 /* Find the format descriptor from its GUID. */
334 fmtdesc = uvc_format_by_guid(&buffer[5]);
335
336 if (fmtdesc != NULL) {
d0ebf307 337 strlcpy(format->name, fmtdesc->name,
c0efd232
LP
338 sizeof format->name);
339 format->fcc = fmtdesc->fcc;
340 } else {
36bd883e
LP
341 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
342 &buffer[5]);
343 snprintf(format->name, sizeof(format->name), "%pUl\n",
344 &buffer[5]);
c0efd232
LP
345 format->fcc = 0;
346 }
347
348 format->bpp = buffer[21];
b482d923
LP
349 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
350 ftype = UVC_VS_FRAME_UNCOMPRESSED;
c0efd232 351 } else {
b482d923 352 ftype = UVC_VS_FRAME_FRAME_BASED;
c0efd232
LP
353 if (buffer[27])
354 format->flags = UVC_FMT_FLAG_COMPRESSED;
355 }
356 break;
357
b482d923 358 case UVC_VS_FORMAT_MJPEG:
c0efd232 359 if (buflen < 11) {
b2d9cc42 360 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
361 "interface %d FORMAT error\n",
362 dev->udev->devnum,
363 alts->desc.bInterfaceNumber);
364 return -EINVAL;
365 }
366
d0ebf307 367 strlcpy(format->name, "MJPEG", sizeof format->name);
c0efd232
LP
368 format->fcc = V4L2_PIX_FMT_MJPEG;
369 format->flags = UVC_FMT_FLAG_COMPRESSED;
370 format->bpp = 0;
b482d923 371 ftype = UVC_VS_FRAME_MJPEG;
c0efd232
LP
372 break;
373
b482d923 374 case UVC_VS_FORMAT_DV:
c0efd232 375 if (buflen < 9) {
b2d9cc42 376 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
377 "interface %d FORMAT error\n",
378 dev->udev->devnum,
379 alts->desc.bInterfaceNumber);
380 return -EINVAL;
381 }
382
383 switch (buffer[8] & 0x7f) {
384 case 0:
d0ebf307 385 strlcpy(format->name, "SD-DV", sizeof format->name);
c0efd232
LP
386 break;
387 case 1:
d0ebf307 388 strlcpy(format->name, "SDL-DV", sizeof format->name);
c0efd232
LP
389 break;
390 case 2:
d0ebf307 391 strlcpy(format->name, "HD-DV", sizeof format->name);
c0efd232
LP
392 break;
393 default:
b2d9cc42 394 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
395 "interface %d: unknown DV format %u\n",
396 dev->udev->devnum,
397 alts->desc.bInterfaceNumber, buffer[8]);
398 return -EINVAL;
399 }
400
d0ebf307 401 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
c0efd232
LP
402 sizeof format->name);
403
404 format->fcc = V4L2_PIX_FMT_DV;
405 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
406 format->bpp = 0;
407 ftype = 0;
408
409 /* Create a dummy frame descriptor. */
410 frame = &format->frame[0];
411 memset(&format->frame[0], 0, sizeof format->frame[0]);
412 frame->bFrameIntervalType = 1;
413 frame->dwDefaultFrameInterval = 1;
414 frame->dwFrameInterval = *intervals;
415 *(*intervals)++ = 1;
416 format->nframes = 1;
417 break;
418
b482d923
LP
419 case UVC_VS_FORMAT_MPEG2TS:
420 case UVC_VS_FORMAT_STREAM_BASED:
c0efd232
LP
421 /* Not supported yet. */
422 default:
b2d9cc42 423 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
424 "interface %d unsupported format %u\n",
425 dev->udev->devnum, alts->desc.bInterfaceNumber,
426 buffer[2]);
427 return -EINVAL;
428 }
429
430 uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
431
432 buflen -= buffer[0];
433 buffer += buffer[0];
434
435 /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
436 * based formats have frame descriptors.
437 */
c4ed8c66
LP
438 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
439 buffer[2] == ftype) {
078f8947 440 frame = &format->frame[format->nframes];
b482d923 441 if (ftype != UVC_VS_FRAME_FRAME_BASED)
c0efd232
LP
442 n = buflen > 25 ? buffer[25] : 0;
443 else
444 n = buflen > 21 ? buffer[21] : 0;
445
446 n = n ? n : 3;
447
448 if (buflen < 26 + 4*n) {
b2d9cc42 449 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
450 "interface %d FRAME error\n", dev->udev->devnum,
451 alts->desc.bInterfaceNumber);
452 return -EINVAL;
453 }
454
455 frame->bFrameIndex = buffer[3];
456 frame->bmCapabilities = buffer[4];
9bc6218d
MH
457 frame->wWidth = get_unaligned_le16(&buffer[5]);
458 frame->wHeight = get_unaligned_le16(&buffer[7]);
459 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
460 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
b482d923 461 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
c0efd232 462 frame->dwMaxVideoFrameBufferSize =
9bc6218d 463 get_unaligned_le32(&buffer[17]);
c0efd232 464 frame->dwDefaultFrameInterval =
9bc6218d 465 get_unaligned_le32(&buffer[21]);
c0efd232
LP
466 frame->bFrameIntervalType = buffer[25];
467 } else {
468 frame->dwMaxVideoFrameBufferSize = 0;
469 frame->dwDefaultFrameInterval =
9bc6218d 470 get_unaligned_le32(&buffer[17]);
c0efd232
LP
471 frame->bFrameIntervalType = buffer[21];
472 }
473 frame->dwFrameInterval = *intervals;
474
475 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
476 * completely. Observed behaviours range from setting the
2c2d264b 477 * value to 1.1x the actual frame size to hardwiring the
c0efd232
LP
478 * 16 low bits to 0. This results in a higher than necessary
479 * memory usage as well as a wrong image size information. For
480 * uncompressed formats this can be fixed by computing the
481 * value from the frame size.
482 */
483 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
484 frame->dwMaxVideoFrameBufferSize = format->bpp
485 * frame->wWidth * frame->wHeight / 8;
486
487 /* Some bogus devices report dwMinFrameInterval equal to
488 * dwMaxFrameInterval and have dwFrameIntervalStep set to
489 * zero. Setting all null intervals to 1 fixes the problem and
2c2d264b 490 * some other divisions by zero that could happen.
c0efd232
LP
491 */
492 for (i = 0; i < n; ++i) {
9bc6218d 493 interval = get_unaligned_le32(&buffer[26+4*i]);
c0efd232
LP
494 *(*intervals)++ = interval ? interval : 1;
495 }
496
497 /* Make sure that the default frame interval stays between
498 * the boundaries.
499 */
500 n -= frame->bFrameIntervalType ? 1 : 2;
501 frame->dwDefaultFrameInterval =
502 min(frame->dwFrameInterval[n],
503 max(frame->dwFrameInterval[0],
504 frame->dwDefaultFrameInterval));
505
86d8b6ab
LP
506 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
507 frame->bFrameIntervalType = 1;
508 frame->dwFrameInterval[0] =
509 frame->dwDefaultFrameInterval;
510 }
511
c0efd232
LP
512 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
513 frame->wWidth, frame->wHeight,
514 10000000/frame->dwDefaultFrameInterval,
515 (100000000/frame->dwDefaultFrameInterval)%10);
516
078f8947 517 format->nframes++;
c0efd232
LP
518 buflen -= buffer[0];
519 buffer += buffer[0];
520 }
521
c4ed8c66
LP
522 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
523 buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
c0efd232
LP
524 buflen -= buffer[0];
525 buffer += buffer[0];
526 }
527
c4ed8c66
LP
528 if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
529 buffer[2] == UVC_VS_COLORFORMAT) {
c0efd232 530 if (buflen < 6) {
b2d9cc42 531 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
c0efd232
LP
532 "interface %d COLORFORMAT error\n",
533 dev->udev->devnum,
534 alts->desc.bInterfaceNumber);
535 return -EINVAL;
536 }
537
538 format->colorspace = uvc_colorspace(buffer[3]);
539
540 buflen -= buffer[0];
541 buffer += buffer[0];
542 }
543
544 return buffer - start;
545}
546
547static int uvc_parse_streaming(struct uvc_device *dev,
548 struct usb_interface *intf)
549{
550 struct uvc_streaming *streaming = NULL;
551 struct uvc_format *format;
552 struct uvc_frame *frame;
553 struct usb_host_interface *alts = &intf->altsetting[0];
554 unsigned char *_buffer, *buffer = alts->extra;
555 int _buflen, buflen = alts->extralen;
556 unsigned int nformats = 0, nframes = 0, nintervals = 0;
557 unsigned int size, i, n, p;
558 __u32 *interval;
559 __u16 psize;
560 int ret = -EINVAL;
561
562 if (intf->cur_altsetting->desc.bInterfaceSubClass
b482d923 563 != UVC_SC_VIDEOSTREAMING) {
c0efd232
LP
564 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
565 "video streaming interface\n", dev->udev->devnum,
566 intf->altsetting[0].desc.bInterfaceNumber);
567 return -EINVAL;
568 }
569
570 if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
571 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
572 "claimed\n", dev->udev->devnum,
573 intf->altsetting[0].desc.bInterfaceNumber);
574 return -EINVAL;
575 }
576
577 streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
578 if (streaming == NULL) {
579 usb_driver_release_interface(&uvc_driver.driver, intf);
580 return -EINVAL;
581 }
582
583 mutex_init(&streaming->mutex);
35f02a68 584 streaming->dev = dev;
c0efd232
LP
585 streaming->intf = usb_get_intf(intf);
586 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
587
588 /* The Pico iMage webcam has its class-specific interface descriptors
589 * after the endpoint descriptors.
590 */
591 if (buflen == 0) {
592 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
593 struct usb_host_endpoint *ep = &alts->endpoint[i];
594
595 if (ep->extralen == 0)
596 continue;
597
598 if (ep->extralen > 2 &&
599 ep->extra[1] == USB_DT_CS_INTERFACE) {
600 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
601 "from endpoint %u.\n", i);
602 buffer = alts->endpoint[i].extra;
603 buflen = alts->endpoint[i].extralen;
604 break;
605 }
606 }
607 }
608
609 /* Skip the standard interface descriptors. */
610 while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
611 buflen -= buffer[0];
612 buffer += buffer[0];
613 }
614
615 if (buflen <= 2) {
616 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
617 "interface descriptors found.\n");
618 goto error;
619 }
620
621 /* Parse the header descriptor. */
ff924203 622 switch (buffer[2]) {
b482d923 623 case UVC_VS_OUTPUT_HEADER:
ff924203
LP
624 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
625 size = 9;
626 break;
627
b482d923 628 case UVC_VS_INPUT_HEADER:
ff924203
LP
629 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
630 size = 13;
631 break;
632
633 default:
c0efd232 634 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
ff924203
LP
635 "%d HEADER descriptor not found.\n", dev->udev->devnum,
636 alts->desc.bInterfaceNumber);
c0efd232 637 goto error;
ff924203 638 }
c0efd232 639
ff924203
LP
640 p = buflen >= 4 ? buffer[3] : 0;
641 n = buflen >= size ? buffer[size-1] : 0;
642
643 if (buflen < size + p*n) {
644 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
645 "interface %d HEADER descriptor is invalid.\n",
646 dev->udev->devnum, alts->desc.bInterfaceNumber);
647 goto error;
648 }
c0efd232 649
ff924203
LP
650 streaming->header.bNumFormats = p;
651 streaming->header.bEndpointAddress = buffer[6];
b482d923 652 if (buffer[2] == UVC_VS_INPUT_HEADER) {
c0efd232
LP
653 streaming->header.bmInfo = buffer[7];
654 streaming->header.bTerminalLink = buffer[8];
655 streaming->header.bStillCaptureMethod = buffer[9];
656 streaming->header.bTriggerSupport = buffer[10];
657 streaming->header.bTriggerUsage = buffer[11];
c0efd232 658 } else {
ff924203
LP
659 streaming->header.bTerminalLink = buffer[7];
660 }
661 streaming->header.bControlSize = n;
662
0b21d55f
JL
663 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
664 GFP_KERNEL);
ff924203
LP
665 if (streaming->header.bmaControls == NULL) {
666 ret = -ENOMEM;
c0efd232
LP
667 goto error;
668 }
669
670 buflen -= buffer[0];
671 buffer += buffer[0];
672
673 _buffer = buffer;
674 _buflen = buflen;
675
676 /* Count the format and frame descriptors. */
042e143e 677 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
c0efd232 678 switch (_buffer[2]) {
b482d923
LP
679 case UVC_VS_FORMAT_UNCOMPRESSED:
680 case UVC_VS_FORMAT_MJPEG:
681 case UVC_VS_FORMAT_FRAME_BASED:
c0efd232
LP
682 nformats++;
683 break;
684
b482d923 685 case UVC_VS_FORMAT_DV:
c0efd232
LP
686 /* DV format has no frame descriptor. We will create a
687 * dummy frame descriptor with a dummy frame interval.
688 */
689 nformats++;
690 nframes++;
691 nintervals++;
692 break;
693
b482d923
LP
694 case UVC_VS_FORMAT_MPEG2TS:
695 case UVC_VS_FORMAT_STREAM_BASED:
c0efd232
LP
696 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
697 "interface %d FORMAT %u is not supported.\n",
698 dev->udev->devnum,
699 alts->desc.bInterfaceNumber, _buffer[2]);
700 break;
701
b482d923
LP
702 case UVC_VS_FRAME_UNCOMPRESSED:
703 case UVC_VS_FRAME_MJPEG:
c0efd232
LP
704 nframes++;
705 if (_buflen > 25)
706 nintervals += _buffer[25] ? _buffer[25] : 3;
707 break;
708
b482d923 709 case UVC_VS_FRAME_FRAME_BASED:
c0efd232
LP
710 nframes++;
711 if (_buflen > 21)
712 nintervals += _buffer[21] ? _buffer[21] : 3;
713 break;
714 }
715
716 _buflen -= _buffer[0];
717 _buffer += _buffer[0];
718 }
719
720 if (nformats == 0) {
721 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
722 "%d has no supported formats defined.\n",
723 dev->udev->devnum, alts->desc.bInterfaceNumber);
724 goto error;
725 }
726
727 size = nformats * sizeof *format + nframes * sizeof *frame
728 + nintervals * sizeof *interval;
729 format = kzalloc(size, GFP_KERNEL);
730 if (format == NULL) {
731 ret = -ENOMEM;
732 goto error;
733 }
734
735 frame = (struct uvc_frame *)&format[nformats];
736 interval = (__u32 *)&frame[nframes];
737
738 streaming->format = format;
739 streaming->nformats = nformats;
740
741 /* Parse the format descriptors. */
042e143e 742 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
c0efd232 743 switch (buffer[2]) {
b482d923
LP
744 case UVC_VS_FORMAT_UNCOMPRESSED:
745 case UVC_VS_FORMAT_MJPEG:
746 case UVC_VS_FORMAT_DV:
747 case UVC_VS_FORMAT_FRAME_BASED:
c0efd232
LP
748 format->frame = frame;
749 ret = uvc_parse_format(dev, streaming, format,
750 &interval, buffer, buflen);
751 if (ret < 0)
752 goto error;
753
754 frame += format->nframes;
755 format++;
756
757 buflen -= ret;
758 buffer += ret;
759 continue;
760
761 default:
762 break;
763 }
764
765 buflen -= buffer[0];
766 buffer += buffer[0];
767 }
768
c4ed8c66
LP
769 if (buflen)
770 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
771 "%d has %u bytes of trailing descriptor garbage.\n",
772 dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
773
c0efd232
LP
774 /* Parse the alternate settings to find the maximum bandwidth. */
775 for (i = 0; i < intf->num_altsetting; ++i) {
776 struct usb_host_endpoint *ep;
777 alts = &intf->altsetting[i];
778 ep = uvc_find_endpoint(alts,
779 streaming->header.bEndpointAddress);
780 if (ep == NULL)
781 continue;
782
783 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
784 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
785 if (psize > streaming->maxpsize)
786 streaming->maxpsize = psize;
787 }
788
35f02a68 789 list_add_tail(&streaming->list, &dev->streams);
c0efd232
LP
790 return 0;
791
792error:
793 usb_driver_release_interface(&uvc_driver.driver, intf);
794 usb_put_intf(intf);
795 kfree(streaming->format);
796 kfree(streaming->header.bmaControls);
797 kfree(streaming);
798 return ret;
799}
800
8ca5a639
LP
801static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
802 unsigned int num_pads, unsigned int extra_size)
803{
804 struct uvc_entity *entity;
805 unsigned int num_inputs;
806 unsigned int size;
4ffc2d89 807 unsigned int i;
8ca5a639 808
4ffc2d89 809 extra_size = ALIGN(extra_size, sizeof(*entity->pads));
8ca5a639 810 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
4ffc2d89
LP
811 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
812 + num_inputs;
8ca5a639
LP
813 entity = kzalloc(size, GFP_KERNEL);
814 if (entity == NULL)
815 return NULL;
816
817 entity->id = id;
818 entity->type = type;
819
4ffc2d89
LP
820 entity->num_links = 0;
821 entity->num_pads = num_pads;
822 entity->pads = ((void *)(entity + 1)) + extra_size;
823
824 for (i = 0; i < num_inputs; ++i)
825 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
826 if (!UVC_ENTITY_IS_OTERM(entity))
827 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
828
8ca5a639 829 entity->bNrInPins = num_inputs;
4ffc2d89 830 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
8ca5a639
LP
831
832 return entity;
833}
834
c0efd232
LP
835/* Parse vendor-specific extensions. */
836static int uvc_parse_vendor_control(struct uvc_device *dev,
837 const unsigned char *buffer, int buflen)
838{
839 struct usb_device *udev = dev->udev;
840 struct usb_host_interface *alts = dev->intf->cur_altsetting;
841 struct uvc_entity *unit;
842 unsigned int n, p;
843 int handled = 0;
844
845 switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
846 case 0x046d: /* Logitech */
847 if (buffer[1] != 0x41 || buffer[2] != 0x01)
848 break;
849
850 /* Logitech implements several vendor specific functions
851 * through vendor specific extension units (LXU).
852 *
853 * The LXU descriptors are similar to XU descriptors
854 * (see "USB Device Video Class for Video Devices", section
855 * 3.7.2.6 "Extension Unit Descriptor") with the following
856 * differences:
857 *
858 * ----------------------------------------------------------
859 * 0 bLength 1 Number
860 * Size of this descriptor, in bytes: 24+p+n*2
861 * ----------------------------------------------------------
862 * 23+p+n bmControlsType N Bitmap
863 * Individual bits in the set are defined:
864 * 0: Absolute
865 * 1: Relative
866 *
867 * This bitset is mapped exactly the same as bmControls.
868 * ----------------------------------------------------------
869 * 23+p+n*2 bReserved 1 Boolean
870 * ----------------------------------------------------------
871 * 24+p+n*2 iExtension 1 Index
872 * Index of a string descriptor that describes this
873 * extension unit.
874 * ----------------------------------------------------------
875 */
876 p = buflen >= 22 ? buffer[21] : 0;
877 n = buflen >= 25 + p ? buffer[22+p] : 0;
878
879 if (buflen < 25 + p + 2*n) {
880 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
881 "interface %d EXTENSION_UNIT error\n",
882 udev->devnum, alts->desc.bInterfaceNumber);
883 break;
884 }
885
8ca5a639
LP
886 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
887 p + 1, 2*n);
c0efd232
LP
888 if (unit == NULL)
889 return -ENOMEM;
890
c0efd232
LP
891 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
892 unit->extension.bNumControls = buffer[20];
8ca5a639 893 memcpy(unit->baSourceID, &buffer[22], p);
c0efd232 894 unit->extension.bControlSize = buffer[22+p];
8ca5a639
LP
895 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
896 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
897 + n;
c0efd232
LP
898 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
899
900 if (buffer[24+p+2*n] != 0)
901 usb_string(udev, buffer[24+p+2*n], unit->name,
902 sizeof unit->name);
903 else
904 sprintf(unit->name, "Extension %u", buffer[3]);
905
906 list_add_tail(&unit->list, &dev->entities);
907 handled = 1;
908 break;
909 }
910
911 return handled;
912}
913
914static int uvc_parse_standard_control(struct uvc_device *dev,
915 const unsigned char *buffer, int buflen)
916{
917 struct usb_device *udev = dev->udev;
918 struct uvc_entity *unit, *term;
919 struct usb_interface *intf;
920 struct usb_host_interface *alts = dev->intf->cur_altsetting;
921 unsigned int i, n, p, len;
922 __u16 type;
923
924 switch (buffer[2]) {
b482d923 925 case UVC_VC_HEADER:
c0efd232
LP
926 n = buflen >= 12 ? buffer[11] : 0;
927
928 if (buflen < 12 || buflen < 12 + n) {
929 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
930 "interface %d HEADER error\n", udev->devnum,
931 alts->desc.bInterfaceNumber);
932 return -EINVAL;
933 }
934
9bc6218d
MH
935 dev->uvc_version = get_unaligned_le16(&buffer[3]);
936 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
c0efd232
LP
937
938 /* Parse all USB Video Streaming interfaces. */
939 for (i = 0; i < n; ++i) {
940 intf = usb_ifnum_to_if(udev, buffer[12+i]);
941 if (intf == NULL) {
942 uvc_trace(UVC_TRACE_DESCR, "device %d "
943 "interface %d doesn't exists\n",
944 udev->devnum, i);
945 continue;
946 }
947
948 uvc_parse_streaming(dev, intf);
949 }
950 break;
951
b482d923 952 case UVC_VC_INPUT_TERMINAL:
c0efd232
LP
953 if (buflen < 8) {
954 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
955 "interface %d INPUT_TERMINAL error\n",
956 udev->devnum, alts->desc.bInterfaceNumber);
957 return -EINVAL;
958 }
959
960 /* Make sure the terminal type MSB is not null, otherwise it
961 * could be confused with a unit.
962 */
9bc6218d 963 type = get_unaligned_le16(&buffer[4]);
c0efd232
LP
964 if ((type & 0xff00) == 0) {
965 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
966 "interface %d INPUT_TERMINAL %d has invalid "
967 "type 0x%04x, skipping\n", udev->devnum,
968 alts->desc.bInterfaceNumber,
969 buffer[3], type);
970 return 0;
971 }
972
973 n = 0;
974 p = 0;
975 len = 8;
976
b482d923 977 if (type == UVC_ITT_CAMERA) {
c0efd232
LP
978 n = buflen >= 15 ? buffer[14] : 0;
979 len = 15;
980
b482d923 981 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
c0efd232
LP
982 n = buflen >= 9 ? buffer[8] : 0;
983 p = buflen >= 10 + n ? buffer[9+n] : 0;
984 len = 10;
985 }
986
987 if (buflen < len + n + p) {
988 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
989 "interface %d INPUT_TERMINAL error\n",
990 udev->devnum, alts->desc.bInterfaceNumber);
991 return -EINVAL;
992 }
993
8ca5a639
LP
994 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
995 1, n + p);
c0efd232
LP
996 if (term == NULL)
997 return -ENOMEM;
998
b482d923 999 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
c0efd232
LP
1000 term->camera.bControlSize = n;
1001 term->camera.bmControls = (__u8 *)term + sizeof *term;
1002 term->camera.wObjectiveFocalLengthMin =
9bc6218d 1003 get_unaligned_le16(&buffer[8]);
c0efd232 1004 term->camera.wObjectiveFocalLengthMax =
9bc6218d 1005 get_unaligned_le16(&buffer[10]);
c0efd232 1006 term->camera.wOcularFocalLength =
9bc6218d 1007 get_unaligned_le16(&buffer[12]);
c0efd232 1008 memcpy(term->camera.bmControls, &buffer[15], n);
b482d923
LP
1009 } else if (UVC_ENTITY_TYPE(term) ==
1010 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
c0efd232
LP
1011 term->media.bControlSize = n;
1012 term->media.bmControls = (__u8 *)term + sizeof *term;
1013 term->media.bTransportModeSize = p;
1014 term->media.bmTransportModes = (__u8 *)term
1015 + sizeof *term + n;
1016 memcpy(term->media.bmControls, &buffer[9], n);
1017 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1018 }
1019
1020 if (buffer[7] != 0)
1021 usb_string(udev, buffer[7], term->name,
1022 sizeof term->name);
b482d923 1023 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
c0efd232 1024 sprintf(term->name, "Camera %u", buffer[3]);
b482d923 1025 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
c0efd232
LP
1026 sprintf(term->name, "Media %u", buffer[3]);
1027 else
1028 sprintf(term->name, "Input %u", buffer[3]);
1029
1030 list_add_tail(&term->list, &dev->entities);
1031 break;
1032
b482d923 1033 case UVC_VC_OUTPUT_TERMINAL:
c0efd232
LP
1034 if (buflen < 9) {
1035 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1036 "interface %d OUTPUT_TERMINAL error\n",
1037 udev->devnum, alts->desc.bInterfaceNumber);
1038 return -EINVAL;
1039 }
1040
1041 /* Make sure the terminal type MSB is not null, otherwise it
1042 * could be confused with a unit.
1043 */
9bc6218d 1044 type = get_unaligned_le16(&buffer[4]);
c0efd232
LP
1045 if ((type & 0xff00) == 0) {
1046 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1047 "interface %d OUTPUT_TERMINAL %d has invalid "
1048 "type 0x%04x, skipping\n", udev->devnum,
1049 alts->desc.bInterfaceNumber, buffer[3], type);
1050 return 0;
1051 }
1052
8ca5a639
LP
1053 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1054 1, 0);
c0efd232
LP
1055 if (term == NULL)
1056 return -ENOMEM;
1057
8ca5a639 1058 memcpy(term->baSourceID, &buffer[7], 1);
c0efd232
LP
1059
1060 if (buffer[8] != 0)
1061 usb_string(udev, buffer[8], term->name,
1062 sizeof term->name);
1063 else
1064 sprintf(term->name, "Output %u", buffer[3]);
1065
1066 list_add_tail(&term->list, &dev->entities);
1067 break;
1068
b482d923 1069 case UVC_VC_SELECTOR_UNIT:
c0efd232
LP
1070 p = buflen >= 5 ? buffer[4] : 0;
1071
1072 if (buflen < 5 || buflen < 6 + p) {
1073 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1074 "interface %d SELECTOR_UNIT error\n",
1075 udev->devnum, alts->desc.bInterfaceNumber);
1076 return -EINVAL;
1077 }
1078
8ca5a639 1079 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
c0efd232
LP
1080 if (unit == NULL)
1081 return -ENOMEM;
1082
8ca5a639 1083 memcpy(unit->baSourceID, &buffer[5], p);
c0efd232
LP
1084
1085 if (buffer[5+p] != 0)
1086 usb_string(udev, buffer[5+p], unit->name,
1087 sizeof unit->name);
1088 else
1089 sprintf(unit->name, "Selector %u", buffer[3]);
1090
1091 list_add_tail(&unit->list, &dev->entities);
1092 break;
1093
b482d923 1094 case UVC_VC_PROCESSING_UNIT:
c0efd232
LP
1095 n = buflen >= 8 ? buffer[7] : 0;
1096 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1097
1098 if (buflen < p + n) {
1099 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1100 "interface %d PROCESSING_UNIT error\n",
1101 udev->devnum, alts->desc.bInterfaceNumber);
1102 return -EINVAL;
1103 }
1104
8ca5a639 1105 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
c0efd232
LP
1106 if (unit == NULL)
1107 return -ENOMEM;
1108
8ca5a639 1109 memcpy(unit->baSourceID, &buffer[4], 1);
c0efd232 1110 unit->processing.wMaxMultiplier =
9bc6218d 1111 get_unaligned_le16(&buffer[5]);
c0efd232
LP
1112 unit->processing.bControlSize = buffer[7];
1113 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1114 memcpy(unit->processing.bmControls, &buffer[8], n);
1115 if (dev->uvc_version >= 0x0110)
1116 unit->processing.bmVideoStandards = buffer[9+n];
1117
1118 if (buffer[8+n] != 0)
1119 usb_string(udev, buffer[8+n], unit->name,
1120 sizeof unit->name);
1121 else
1122 sprintf(unit->name, "Processing %u", buffer[3]);
1123
1124 list_add_tail(&unit->list, &dev->entities);
1125 break;
1126
b482d923 1127 case UVC_VC_EXTENSION_UNIT:
c0efd232
LP
1128 p = buflen >= 22 ? buffer[21] : 0;
1129 n = buflen >= 24 + p ? buffer[22+p] : 0;
1130
1131 if (buflen < 24 + p + n) {
1132 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1133 "interface %d EXTENSION_UNIT error\n",
1134 udev->devnum, alts->desc.bInterfaceNumber);
1135 return -EINVAL;
1136 }
1137
8ca5a639 1138 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
c0efd232
LP
1139 if (unit == NULL)
1140 return -ENOMEM;
1141
c0efd232
LP
1142 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1143 unit->extension.bNumControls = buffer[20];
8ca5a639 1144 memcpy(unit->baSourceID, &buffer[22], p);
c0efd232 1145 unit->extension.bControlSize = buffer[22+p];
8ca5a639 1146 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
c0efd232
LP
1147 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1148
1149 if (buffer[23+p+n] != 0)
1150 usb_string(udev, buffer[23+p+n], unit->name,
1151 sizeof unit->name);
1152 else
1153 sprintf(unit->name, "Extension %u", buffer[3]);
1154
1155 list_add_tail(&unit->list, &dev->entities);
1156 break;
1157
1158 default:
1159 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1160 "descriptor (%u)\n", buffer[2]);
1161 break;
1162 }
1163
1164 return 0;
1165}
1166
1167static int uvc_parse_control(struct uvc_device *dev)
1168{
1169 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1170 unsigned char *buffer = alts->extra;
1171 int buflen = alts->extralen;
1172 int ret;
1173
1174 /* Parse the default alternate setting only, as the UVC specification
1175 * defines a single alternate setting, the default alternate setting
1176 * zero.
1177 */
1178
1179 while (buflen > 2) {
1180 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1181 buffer[1] != USB_DT_CS_INTERFACE)
1182 goto next_descriptor;
1183
1184 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1185 return ret;
1186
1187next_descriptor:
1188 buflen -= buffer[0];
1189 buffer += buffer[0];
1190 }
1191
538e7a00
LP
1192 /* Check if the optional status endpoint is present. Built-in iSight
1193 * webcams have an interrupt endpoint but spit proprietary data that
1194 * don't conform to the UVC status endpoint messages. Don't try to
1195 * handle the interrupt endpoint for those cameras.
1196 */
1197 if (alts->desc.bNumEndpoints == 1 &&
1198 !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
c0efd232
LP
1199 struct usb_host_endpoint *ep = &alts->endpoint[0];
1200 struct usb_endpoint_descriptor *desc = &ep->desc;
1201
1202 if (usb_endpoint_is_int_in(desc) &&
1203 le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1204 desc->bInterval != 0) {
1205 uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1206 "(addr %02x).\n", desc->bEndpointAddress);
1207 dev->int_ep = ep;
1208 }
1209 }
1210
1211 return 0;
1212}
1213
1214/* ------------------------------------------------------------------------
8e113595 1215 * UVC device scan
c0efd232
LP
1216 */
1217
c0efd232
LP
1218/*
1219 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1220 * and containing the following units:
1221 *
8e113595 1222 * - one or more Output Terminals (USB Streaming or Display)
c0efd232 1223 * - zero or one Processing Unit
8e113595 1224 * - zero, one or more single-input Selector Units
c0efd232
LP
1225 * - zero or one multiple-input Selector Units, provided all inputs are
1226 * connected to input terminals
1227 * - zero, one or mode single-input Extension Units
2c2d264b 1228 * - one or more Input Terminals (Camera, External or USB Streaming)
c0efd232 1229 *
8e113595
LP
1230 * The terminal and units must match on of the following structures:
1231 *
1232 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1233 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1234 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1235 *
1236 * +---------+ +---------+ -> OTT_*(0)
1237 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1238 * +---------+ +---------+ -> OTT_*(n)
1239 *
1240 * The Processing Unit and Extension Units can be in any order. Additional
1241 * Extension Units connected to the main chain as single-unit branches are
1242 * also supported. Single-input Selector Units are ignored.
c0efd232 1243 */
8e113595 1244static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
c0efd232
LP
1245 struct uvc_entity *entity)
1246{
1247 switch (UVC_ENTITY_TYPE(entity)) {
b482d923 1248 case UVC_VC_EXTENSION_UNIT:
c0efd232
LP
1249 if (uvc_trace_param & UVC_TRACE_PROBE)
1250 printk(" <- XU %d", entity->id);
1251
8ca5a639 1252 if (entity->bNrInPins != 1) {
c0efd232
LP
1253 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1254 "than 1 input pin.\n", entity->id);
1255 return -1;
1256 }
1257
c0efd232
LP
1258 break;
1259
b482d923 1260 case UVC_VC_PROCESSING_UNIT:
c0efd232
LP
1261 if (uvc_trace_param & UVC_TRACE_PROBE)
1262 printk(" <- PU %d", entity->id);
1263
8e113595 1264 if (chain->processing != NULL) {
c0efd232
LP
1265 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1266 "Processing Units in chain.\n");
1267 return -1;
1268 }
1269
8e113595 1270 chain->processing = entity;
c0efd232
LP
1271 break;
1272
b482d923 1273 case UVC_VC_SELECTOR_UNIT:
c0efd232
LP
1274 if (uvc_trace_param & UVC_TRACE_PROBE)
1275 printk(" <- SU %d", entity->id);
1276
1277 /* Single-input selector units are ignored. */
8ca5a639 1278 if (entity->bNrInPins == 1)
c0efd232
LP
1279 break;
1280
8e113595 1281 if (chain->selector != NULL) {
c0efd232
LP
1282 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1283 "Units in chain.\n");
1284 return -1;
1285 }
1286
8e113595 1287 chain->selector = entity;
c0efd232
LP
1288 break;
1289
b482d923
LP
1290 case UVC_ITT_VENDOR_SPECIFIC:
1291 case UVC_ITT_CAMERA:
1292 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
c0efd232
LP
1293 if (uvc_trace_param & UVC_TRACE_PROBE)
1294 printk(" <- IT %d\n", entity->id);
1295
c0efd232
LP
1296 break;
1297
4093a5c4
LP
1298 case UVC_OTT_VENDOR_SPECIFIC:
1299 case UVC_OTT_DISPLAY:
1300 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1301 if (uvc_trace_param & UVC_TRACE_PROBE)
1302 printk(" OT %d", entity->id);
1303
1304 break;
1305
b482d923 1306 case UVC_TT_STREAMING:
4057ac6c
LP
1307 if (UVC_ENTITY_IS_ITERM(entity)) {
1308 if (uvc_trace_param & UVC_TRACE_PROBE)
1309 printk(" <- IT %d\n", entity->id);
1310 } else {
1311 if (uvc_trace_param & UVC_TRACE_PROBE)
1312 printk(" OT %d", entity->id);
ff924203
LP
1313 }
1314
ff924203
LP
1315 break;
1316
c0efd232
LP
1317 default:
1318 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1319 "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1320 return -1;
1321 }
1322
6241d8ca 1323 list_add_tail(&entity->chain, &chain->entities);
c0efd232
LP
1324 return 0;
1325}
1326
8e113595 1327static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
c0efd232
LP
1328 struct uvc_entity *entity, struct uvc_entity *prev)
1329{
1330 struct uvc_entity *forward;
1331 int found;
1332
1333 /* Forward scan */
1334 forward = NULL;
1335 found = 0;
1336
1337 while (1) {
8e113595 1338 forward = uvc_entity_by_reference(chain->dev, entity->id,
c0efd232
LP
1339 forward);
1340 if (forward == NULL)
1341 break;
8e113595 1342 if (forward == prev)
c0efd232
LP
1343 continue;
1344
8e113595
LP
1345 switch (UVC_ENTITY_TYPE(forward)) {
1346 case UVC_VC_EXTENSION_UNIT:
8ca5a639 1347 if (forward->bNrInPins != 1) {
8e113595
LP
1348 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1349 "has more than 1 input pin.\n",
1350 entity->id);
1351 return -EINVAL;
1352 }
c0efd232 1353
6241d8ca 1354 list_add_tail(&forward->chain, &chain->entities);
8e113595
LP
1355 if (uvc_trace_param & UVC_TRACE_PROBE) {
1356 if (!found)
1357 printk(" (->");
1358
1359 printk(" XU %d", forward->id);
1360 found = 1;
1361 }
1362 break;
1363
1364 case UVC_OTT_VENDOR_SPECIFIC:
1365 case UVC_OTT_DISPLAY:
1366 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1367 case UVC_TT_STREAMING:
1368 if (UVC_ENTITY_IS_ITERM(forward)) {
1369 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1370 "terminal %u.\n", forward->id);
1371 return -EINVAL;
1372 }
c0efd232 1373
6241d8ca 1374 list_add_tail(&forward->chain, &chain->entities);
8e113595
LP
1375 if (uvc_trace_param & UVC_TRACE_PROBE) {
1376 if (!found)
1377 printk(" (->");
1378
1379 printk(" OT %d", forward->id);
1380 found = 1;
1381 }
1382 break;
c0efd232
LP
1383 }
1384 }
1385 if (found)
1386 printk(")");
1387
1388 return 0;
1389}
1390
8e113595 1391static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
4057ac6c 1392 struct uvc_entity **_entity)
c0efd232 1393{
4057ac6c 1394 struct uvc_entity *entity = *_entity;
c0efd232 1395 struct uvc_entity *term;
4057ac6c 1396 int id = -EINVAL, i;
c0efd232
LP
1397
1398 switch (UVC_ENTITY_TYPE(entity)) {
b482d923 1399 case UVC_VC_EXTENSION_UNIT:
b482d923 1400 case UVC_VC_PROCESSING_UNIT:
8ca5a639 1401 id = entity->baSourceID[0];
c0efd232
LP
1402 break;
1403
b482d923 1404 case UVC_VC_SELECTOR_UNIT:
c0efd232 1405 /* Single-input selector units are ignored. */
8ca5a639
LP
1406 if (entity->bNrInPins == 1) {
1407 id = entity->baSourceID[0];
c0efd232
LP
1408 break;
1409 }
1410
1411 if (uvc_trace_param & UVC_TRACE_PROBE)
1412 printk(" <- IT");
1413
8e113595 1414 chain->selector = entity;
8ca5a639
LP
1415 for (i = 0; i < entity->bNrInPins; ++i) {
1416 id = entity->baSourceID[i];
8e113595 1417 term = uvc_entity_by_id(chain->dev, id);
c0efd232
LP
1418 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1419 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1420 "input %d isn't connected to an "
1421 "input terminal\n", entity->id, i);
1422 return -1;
1423 }
1424
1425 if (uvc_trace_param & UVC_TRACE_PROBE)
1426 printk(" %d", term->id);
1427
6241d8ca 1428 list_add_tail(&term->chain, &chain->entities);
8e113595 1429 uvc_scan_chain_forward(chain, term, entity);
c0efd232
LP
1430 }
1431
1432 if (uvc_trace_param & UVC_TRACE_PROBE)
1433 printk("\n");
1434
1435 id = 0;
1436 break;
4057ac6c
LP
1437
1438 case UVC_ITT_VENDOR_SPECIFIC:
1439 case UVC_ITT_CAMERA:
1440 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1441 case UVC_OTT_VENDOR_SPECIFIC:
1442 case UVC_OTT_DISPLAY:
1443 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1444 case UVC_TT_STREAMING:
8ca5a639 1445 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
4057ac6c 1446 break;
c0efd232
LP
1447 }
1448
4057ac6c
LP
1449 if (id <= 0) {
1450 *_entity = NULL;
1451 return id;
1452 }
1453
1454 entity = uvc_entity_by_id(chain->dev, id);
1455 if (entity == NULL) {
1456 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1457 "unknown entity %d.\n", id);
1458 return -EINVAL;
1459 }
1460
1461 *_entity = entity;
1462 return 0;
c0efd232
LP
1463}
1464
8e113595 1465static int uvc_scan_chain(struct uvc_video_chain *chain,
4057ac6c 1466 struct uvc_entity *term)
c0efd232
LP
1467{
1468 struct uvc_entity *entity, *prev;
c0efd232 1469
4057ac6c 1470 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
ff924203 1471
4057ac6c
LP
1472 entity = term;
1473 prev = NULL;
8e113595 1474
4057ac6c
LP
1475 while (entity != NULL) {
1476 /* Entity must not be part of an existing chain */
8e113595
LP
1477 if (entity->chain.next || entity->chain.prev) {
1478 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
4057ac6c 1479 "entity %d already in chain.\n", entity->id);
8e113595 1480 return -EINVAL;
c0efd232
LP
1481 }
1482
1483 /* Process entity */
8e113595
LP
1484 if (uvc_scan_chain_entity(chain, entity) < 0)
1485 return -EINVAL;
c0efd232
LP
1486
1487 /* Forward scan */
8e113595
LP
1488 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1489 return -EINVAL;
c0efd232 1490
c0efd232 1491 /* Backward scan */
4057ac6c
LP
1492 prev = entity;
1493 if (uvc_scan_chain_backward(chain, &entity) < 0)
1494 return -EINVAL;
c0efd232
LP
1495 }
1496
8e113595
LP
1497 return 0;
1498}
1499
6241d8ca
LP
1500static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1501 char *buffer)
8e113595
LP
1502{
1503 struct uvc_entity *term;
1504 unsigned int nterms = 0;
1505 char *p = buffer;
1506
1507 list_for_each_entry(term, terms, chain) {
6241d8ca
LP
1508 if (!UVC_ENTITY_IS_TERM(term) ||
1509 UVC_TERM_DIRECTION(term) != dir)
1510 continue;
1511
1512 if (nterms)
8e113595 1513 p += sprintf(p, ",");
6241d8ca
LP
1514 if (++nterms >= 4) {
1515 p += sprintf(p, "...");
1516 break;
8e113595 1517 }
6241d8ca 1518 p += sprintf(p, "%u", term->id);
ff924203 1519 }
c0efd232 1520
8e113595
LP
1521 return p - buffer;
1522}
1523
1524static const char *uvc_print_chain(struct uvc_video_chain *chain)
1525{
1526 static char buffer[43];
1527 char *p = buffer;
1528
6241d8ca 1529 p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
8e113595 1530 p += sprintf(p, " -> ");
6241d8ca 1531 uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
8e113595
LP
1532
1533 return buffer;
c0efd232
LP
1534}
1535
1536/*
35f02a68 1537 * Scan the device for video chains and register video devices.
c0efd232 1538 *
8e113595 1539 * Chains are scanned starting at their output terminals and walked backwards.
c0efd232 1540 */
35f02a68 1541static int uvc_scan_device(struct uvc_device *dev)
c0efd232 1542{
8e113595 1543 struct uvc_video_chain *chain;
c0efd232 1544 struct uvc_entity *term;
c0efd232 1545
c0efd232 1546 list_for_each_entry(term, &dev->entities, list) {
8e113595 1547 if (!UVC_ENTITY_IS_OTERM(term))
c0efd232
LP
1548 continue;
1549
8e113595
LP
1550 /* If the terminal is already included in a chain, skip it.
1551 * This can happen for chains that have multiple output
1552 * terminals, where all output terminals beside the first one
1553 * will be inserted in the chain in forward scans.
1554 */
1555 if (term->chain.next || term->chain.prev)
c0efd232
LP
1556 continue;
1557
8e113595
LP
1558 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1559 if (chain == NULL)
1560 return -ENOMEM;
1561
6241d8ca 1562 INIT_LIST_HEAD(&chain->entities);
8e113595
LP
1563 mutex_init(&chain->ctrl_mutex);
1564 chain->dev = dev;
1565
1566 if (uvc_scan_chain(chain, term) < 0) {
1567 kfree(chain);
1568 continue;
c0efd232 1569 }
8e113595
LP
1570
1571 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1572 uvc_print_chain(chain));
1573
1574 list_add_tail(&chain->list, &dev->chains);
c0efd232
LP
1575 }
1576
8e113595 1577 if (list_empty(&dev->chains)) {
c0efd232
LP
1578 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1579 return -1;
1580 }
1581
c0efd232
LP
1582 return 0;
1583}
1584
8e113595
LP
1585/* ------------------------------------------------------------------------
1586 * Video device registration and unregistration
1587 */
1588
716fdee1
LP
1589/*
1590 * Delete the UVC device.
1591 *
1592 * Called by the kernel when the last reference to the uvc_device structure
1593 * is released.
1594 *
1595 * As this function is called after or during disconnect(), all URBs have
1596 * already been canceled by the USB core. There is no need to kill the
1597 * interrupt URB manually.
1598 */
1599static void uvc_delete(struct uvc_device *dev)
1600{
1601 struct list_head *p, *n;
1602
1603 usb_put_intf(dev->intf);
1604 usb_put_dev(dev->udev);
1605
1606 uvc_status_cleanup(dev);
1607 uvc_ctrl_cleanup_device(dev);
1608
5a254d75
LP
1609 if (dev->vdev.dev)
1610 v4l2_device_unregister(&dev->vdev);
1611#ifdef CONFIG_MEDIA_CONTROLLER
1612 if (media_devnode_is_registered(&dev->mdev.devnode))
1613 media_device_unregister(&dev->mdev);
1614#endif
1615
716fdee1
LP
1616 list_for_each_safe(p, n, &dev->chains) {
1617 struct uvc_video_chain *chain;
1618 chain = list_entry(p, struct uvc_video_chain, list);
1619 kfree(chain);
1620 }
1621
1622 list_for_each_safe(p, n, &dev->entities) {
1623 struct uvc_entity *entity;
1624 entity = list_entry(p, struct uvc_entity, list);
4ffc2d89
LP
1625#ifdef CONFIG_MEDIA_CONTROLLER
1626 uvc_mc_cleanup_entity(entity);
1627#endif
8a65a948
LP
1628 if (entity->vdev) {
1629 video_device_release(entity->vdev);
1630 entity->vdev = NULL;
1631 }
716fdee1
LP
1632 kfree(entity);
1633 }
1634
1635 list_for_each_safe(p, n, &dev->streams) {
1636 struct uvc_streaming *streaming;
1637 streaming = list_entry(p, struct uvc_streaming, list);
1638 usb_driver_release_interface(&uvc_driver.driver,
1639 streaming->intf);
1640 usb_put_intf(streaming->intf);
1641 kfree(streaming->format);
1642 kfree(streaming->header.bmaControls);
1643 kfree(streaming);
1644 }
1645
1646 kfree(dev);
1647}
1648
1649static void uvc_release(struct video_device *vdev)
1650{
1651 struct uvc_streaming *stream = video_get_drvdata(vdev);
1652 struct uvc_device *dev = stream->dev;
1653
716fdee1
LP
1654 /* Decrement the registered streams count and delete the device when it
1655 * reaches zero.
1656 */
1657 if (atomic_dec_and_test(&dev->nstreams))
1658 uvc_delete(dev);
1659}
1660
8e113595
LP
1661/*
1662 * Unregister the video devices.
1663 */
1664static void uvc_unregister_video(struct uvc_device *dev)
1665{
1666 struct uvc_streaming *stream;
1667
716fdee1
LP
1668 /* Unregistering all video devices might result in uvc_delete() being
1669 * called from inside the loop if there's no open file handle. To avoid
1670 * that, increment the stream count before iterating over the streams
1671 * and decrement it when done.
1672 */
1673 atomic_inc(&dev->nstreams);
1674
8e113595
LP
1675 list_for_each_entry(stream, &dev->streams, list) {
1676 if (stream->vdev == NULL)
1677 continue;
1678
716fdee1 1679 video_unregister_device(stream->vdev);
8e113595 1680 stream->vdev = NULL;
edbaa398
AF
1681
1682 uvc_debugfs_cleanup_stream(stream);
8e113595 1683 }
716fdee1
LP
1684
1685 /* Decrement the stream count and call uvc_delete explicitly if there
1686 * are no stream left.
1687 */
1688 if (atomic_dec_and_test(&dev->nstreams))
1689 uvc_delete(dev);
8e113595
LP
1690}
1691
1692static int uvc_register_video(struct uvc_device *dev,
1693 struct uvc_streaming *stream)
1694{
1695 struct video_device *vdev;
1696 int ret;
1697
1698 /* Initialize the streaming interface with default streaming
1699 * parameters.
1700 */
1701 ret = uvc_video_init(stream);
1702 if (ret < 0) {
1703 uvc_printk(KERN_ERR, "Failed to initialize the device "
1704 "(%d).\n", ret);
1705 return ret;
1706 }
1707
edbaa398
AF
1708 uvc_debugfs_init_stream(stream);
1709
8e113595
LP
1710 /* Register the device with V4L. */
1711 vdev = video_device_alloc();
1712 if (vdev == NULL) {
1713 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1714 ret);
1715 return -ENOMEM;
1716 }
1717
1718 /* We already hold a reference to dev->udev. The video device will be
1719 * unregistered before the reference is released, so we don't need to
1720 * get another one.
1721 */
5a254d75 1722 vdev->v4l2_dev = &dev->vdev;
8e113595 1723 vdev->fops = &uvc_fops;
716fdee1 1724 vdev->release = uvc_release;
954f340f
HV
1725 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1726 vdev->vfl_dir = VFL_DIR_TX;
8e113595
LP
1727 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1728
1729 /* Set the driver data before calling video_register_device, otherwise
1730 * uvc_v4l2_open might race us.
1731 */
1732 stream->vdev = vdev;
1733 video_set_drvdata(vdev, stream);
1734
1735 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1736 if (ret < 0) {
1737 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1738 ret);
1739 stream->vdev = NULL;
1740 video_device_release(vdev);
1741 return ret;
1742 }
1743
f887e99a
LP
1744 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1745 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1746 else
1747 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1748
716fdee1 1749 atomic_inc(&dev->nstreams);
8e113595
LP
1750 return 0;
1751}
1752
1753/*
1754 * Register all video devices in all chains.
1755 */
1756static int uvc_register_terms(struct uvc_device *dev,
6241d8ca 1757 struct uvc_video_chain *chain)
8e113595
LP
1758{
1759 struct uvc_streaming *stream;
1760 struct uvc_entity *term;
1761 int ret;
1762
6241d8ca 1763 list_for_each_entry(term, &chain->entities, chain) {
8e113595
LP
1764 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1765 continue;
1766
1767 stream = uvc_stream_by_id(dev, term->id);
1768 if (stream == NULL) {
1769 uvc_printk(KERN_INFO, "No streaming interface found "
1770 "for terminal %u.", term->id);
1771 continue;
1772 }
1773
1774 stream->chain = chain;
1775 ret = uvc_register_video(dev, stream);
1776 if (ret < 0)
1777 return ret;
8a65a948
LP
1778
1779 term->vdev = stream->vdev;
8e113595
LP
1780 }
1781
1782 return 0;
1783}
1784
1785static int uvc_register_chains(struct uvc_device *dev)
1786{
1787 struct uvc_video_chain *chain;
1788 int ret;
1789
1790 list_for_each_entry(chain, &dev->chains, list) {
6241d8ca 1791 ret = uvc_register_terms(dev, chain);
8e113595
LP
1792 if (ret < 0)
1793 return ret;
4ffc2d89
LP
1794
1795#ifdef CONFIG_MEDIA_CONTROLLER
1796 ret = uvc_mc_register_entities(chain);
1797 if (ret < 0) {
1798 uvc_printk(KERN_INFO, "Failed to register entites "
1799 "(%d).\n", ret);
1800 }
1801#endif
8e113595
LP
1802 }
1803
1804 return 0;
1805}
1806
1807/* ------------------------------------------------------------------------
1808 * USB probe, disconnect, suspend and resume
1809 */
1810
c0efd232
LP
1811static int uvc_probe(struct usb_interface *intf,
1812 const struct usb_device_id *id)
1813{
1814 struct usb_device *udev = interface_to_usbdev(intf);
1815 struct uvc_device *dev;
1816 int ret;
1817
1818 if (id->idVendor && id->idProduct)
1819 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1820 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1821 id->idProduct);
1822 else
1823 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1824 udev->devpath);
1825
2c2d264b 1826 /* Allocate memory for the device and initialize it. */
c0efd232
LP
1827 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1828 return -ENOMEM;
1829
1830 INIT_LIST_HEAD(&dev->entities);
8e113595 1831 INIT_LIST_HEAD(&dev->chains);
35f02a68 1832 INIT_LIST_HEAD(&dev->streams);
716fdee1 1833 atomic_set(&dev->nstreams, 0);
04a37e0f 1834 atomic_set(&dev->users, 0);
8fb91b33 1835 atomic_set(&dev->nmappings, 0);
c0efd232
LP
1836
1837 dev->udev = usb_get_dev(udev);
1838 dev->intf = usb_get_intf(intf);
1839 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
73de3592
LP
1840 dev->quirks = (uvc_quirks_param == -1)
1841 ? id->driver_info : uvc_quirks_param;
c0efd232
LP
1842
1843 if (udev->product != NULL)
d0ebf307 1844 strlcpy(dev->name, udev->product, sizeof dev->name);
c0efd232
LP
1845 else
1846 snprintf(dev->name, sizeof dev->name,
1847 "UVC Camera (%04x:%04x)",
1848 le16_to_cpu(udev->descriptor.idVendor),
1849 le16_to_cpu(udev->descriptor.idProduct));
1850
2c2d264b 1851 /* Parse the Video Class control descriptor. */
c0efd232
LP
1852 if (uvc_parse_control(dev) < 0) {
1853 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1854 "descriptors.\n");
1855 goto error;
1856 }
1857
fba4578e 1858 uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
c0efd232
LP
1859 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1860 udev->product ? udev->product : "<unnamed>",
1861 le16_to_cpu(udev->descriptor.idVendor),
1862 le16_to_cpu(udev->descriptor.idProduct));
1863
73de3592
LP
1864 if (dev->quirks != id->driver_info) {
1865 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1866 "parameter for testing purpose.\n", dev->quirks);
c0efd232
LP
1867 uvc_printk(KERN_INFO, "Please report required quirks to the "
1868 "linux-uvc-devel mailing list.\n");
1869 }
1870
5a254d75
LP
1871 /* Register the media and V4L2 devices. */
1872#ifdef CONFIG_MEDIA_CONTROLLER
1873 dev->mdev.dev = &intf->dev;
1874 strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
1875 if (udev->serial)
1876 strlcpy(dev->mdev.serial, udev->serial,
1877 sizeof(dev->mdev.serial));
1878 strcpy(dev->mdev.bus_info, udev->devpath);
1879 dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
fd3e5824 1880 dev->mdev.driver_version = LINUX_VERSION_CODE;
5a254d75
LP
1881 if (media_device_register(&dev->mdev) < 0)
1882 goto error;
1883
1884 dev->vdev.mdev = &dev->mdev;
1885#endif
1886 if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
1887 goto error;
1888
2c2d264b 1889 /* Initialize controls. */
c0efd232
LP
1890 if (uvc_ctrl_init_device(dev) < 0)
1891 goto error;
1892
8e113595 1893 /* Scan the device for video chains. */
35f02a68 1894 if (uvc_scan_device(dev) < 0)
c0efd232
LP
1895 goto error;
1896
5a254d75 1897 /* Register video device nodes. */
8e113595
LP
1898 if (uvc_register_chains(dev) < 0)
1899 goto error;
1900
2c2d264b 1901 /* Save our data pointer in the interface data. */
c0efd232
LP
1902 usb_set_intfdata(intf, dev);
1903
2c2d264b 1904 /* Initialize the interrupt URB. */
c0efd232
LP
1905 if ((ret = uvc_status_init(dev)) < 0) {
1906 uvc_printk(KERN_INFO, "Unable to initialize the status "
1907 "endpoint (%d), status interrupt will not be "
1908 "supported.\n", ret);
1909 }
1910
1911 uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
3dae8b41 1912 usb_enable_autosuspend(udev);
c0efd232
LP
1913 return 0;
1914
1915error:
716fdee1 1916 uvc_unregister_video(dev);
c0efd232
LP
1917 return -ENODEV;
1918}
1919
1920static void uvc_disconnect(struct usb_interface *intf)
1921{
1922 struct uvc_device *dev = usb_get_intfdata(intf);
1923
1924 /* Set the USB interface data to NULL. This can be done outside the
1925 * lock, as there's no other reader.
1926 */
1927 usb_set_intfdata(intf, NULL);
1928
b482d923
LP
1929 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1930 UVC_SC_VIDEOSTREAMING)
c0efd232
LP
1931 return;
1932
c0efd232 1933 dev->state |= UVC_DEV_DISCONNECTED;
a9e28585 1934
716fdee1 1935 uvc_unregister_video(dev);
c0efd232
LP
1936}
1937
1938static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1939{
1940 struct uvc_device *dev = usb_get_intfdata(intf);
35f02a68 1941 struct uvc_streaming *stream;
c0efd232
LP
1942
1943 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1944 intf->cur_altsetting->desc.bInterfaceNumber);
1945
1946 /* Controls are cached on the fly so they don't need to be saved. */
b482d923
LP
1947 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1948 UVC_SC_VIDEOCONTROL)
c0efd232
LP
1949 return uvc_status_suspend(dev);
1950
35f02a68
LP
1951 list_for_each_entry(stream, &dev->streams, list) {
1952 if (stream->intf == intf)
1953 return uvc_video_suspend(stream);
c0efd232
LP
1954 }
1955
35f02a68
LP
1956 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1957 "mismatch.\n");
1958 return -EINVAL;
c0efd232
LP
1959}
1960
9b0ae867 1961static int __uvc_resume(struct usb_interface *intf, int reset)
c0efd232
LP
1962{
1963 struct uvc_device *dev = usb_get_intfdata(intf);
35f02a68 1964 struct uvc_streaming *stream;
c0efd232
LP
1965
1966 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
1967 intf->cur_altsetting->desc.bInterfaceNumber);
1968
b482d923
LP
1969 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1970 UVC_SC_VIDEOCONTROL) {
7564f67d
HV
1971 if (reset) {
1972 int ret = uvc_ctrl_resume_device(dev);
1973
1974 if (ret < 0)
1975 return ret;
1976 }
c0efd232
LP
1977
1978 return uvc_status_resume(dev);
1979 }
1980
35f02a68
LP
1981 list_for_each_entry(stream, &dev->streams, list) {
1982 if (stream->intf == intf)
d59a7b1d 1983 return uvc_video_resume(stream, reset);
c0efd232
LP
1984 }
1985
35f02a68
LP
1986 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
1987 "mismatch.\n");
1988 return -EINVAL;
c0efd232
LP
1989}
1990
9b0ae867
LP
1991static int uvc_resume(struct usb_interface *intf)
1992{
1993 return __uvc_resume(intf, 0);
1994}
1995
1996static int uvc_reset_resume(struct usb_interface *intf)
1997{
1998 return __uvc_resume(intf, 1);
1999}
2000
310fe524
LP
2001/* ------------------------------------------------------------------------
2002 * Module parameters
2003 */
2004
2005static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
2006{
2007 if (uvc_clock_param == CLOCK_MONOTONIC)
2008 return sprintf(buffer, "CLOCK_MONOTONIC");
2009 else
2010 return sprintf(buffer, "CLOCK_REALTIME");
2011}
2012
2013static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
2014{
2015 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2016 val += strlen("clock_");
2017
2018 if (strcasecmp(val, "monotonic") == 0)
2019 uvc_clock_param = CLOCK_MONOTONIC;
2020 else if (strcasecmp(val, "realtime") == 0)
2021 uvc_clock_param = CLOCK_REALTIME;
2022 else
2023 return -EINVAL;
2024
2025 return 0;
2026}
2027
2028module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2029 &uvc_clock_param, S_IRUGO|S_IWUSR);
2030MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2031module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2032MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2033module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2034MODULE_PARM_DESC(quirks, "Forced device quirks");
2035module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2036MODULE_PARM_DESC(trace, "Trace level bitmask");
2037module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2038MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2039
c0efd232
LP
2040/* ------------------------------------------------------------------------
2041 * Driver initialization and cleanup
2042 */
2043
2044/*
2045 * The Logitech cameras listed below have their interface class set to
2046 * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2047 * though they are compliant.
2048 */
2049static struct usb_device_id uvc_ids[] = {
4eb2697e
LP
2050 /* LogiLink Wireless Webcam */
2051 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2052 | USB_DEVICE_ID_MATCH_INT_INFO,
2053 .idVendor = 0x0416,
2054 .idProduct = 0xa91a,
2055 .bInterfaceClass = USB_CLASS_VIDEO,
2056 .bInterfaceSubClass = 1,
2057 .bInterfaceProtocol = 0,
2058 .driver_info = UVC_QUIRK_PROBE_MINMAX },
bce039c0
LP
2059 /* Genius eFace 2025 */
2060 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2061 | USB_DEVICE_ID_MATCH_INT_INFO,
2062 .idVendor = 0x0458,
2063 .idProduct = 0x706e,
2064 .bInterfaceClass = USB_CLASS_VIDEO,
2065 .bInterfaceSubClass = 1,
2066 .bInterfaceProtocol = 0,
2067 .driver_info = UVC_QUIRK_PROBE_MINMAX },
c0efd232
LP
2068 /* Microsoft Lifecam NX-6000 */
2069 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2070 | USB_DEVICE_ID_MATCH_INT_INFO,
2071 .idVendor = 0x045e,
2072 .idProduct = 0x00f8,
2073 .bInterfaceClass = USB_CLASS_VIDEO,
2074 .bInterfaceSubClass = 1,
2075 .bInterfaceProtocol = 0,
2076 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2077 /* Microsoft Lifecam VX-7000 */
2078 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2079 | USB_DEVICE_ID_MATCH_INT_INFO,
2080 .idVendor = 0x045e,
2081 .idProduct = 0x0723,
2082 .bInterfaceClass = USB_CLASS_VIDEO,
2083 .bInterfaceSubClass = 1,
2084 .bInterfaceProtocol = 0,
2085 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2086 /* Logitech Quickcam Fusion */
2087 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2088 | USB_DEVICE_ID_MATCH_INT_INFO,
2089 .idVendor = 0x046d,
2090 .idProduct = 0x08c1,
2091 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2092 .bInterfaceSubClass = 1,
2093 .bInterfaceProtocol = 0 },
2094 /* Logitech Quickcam Orbit MP */
2095 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2096 | USB_DEVICE_ID_MATCH_INT_INFO,
2097 .idVendor = 0x046d,
2098 .idProduct = 0x08c2,
2099 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2100 .bInterfaceSubClass = 1,
2101 .bInterfaceProtocol = 0 },
2102 /* Logitech Quickcam Pro for Notebook */
2103 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2104 | USB_DEVICE_ID_MATCH_INT_INFO,
2105 .idVendor = 0x046d,
2106 .idProduct = 0x08c3,
2107 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2108 .bInterfaceSubClass = 1,
2109 .bInterfaceProtocol = 0 },
2110 /* Logitech Quickcam Pro 5000 */
2111 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2112 | USB_DEVICE_ID_MATCH_INT_INFO,
2113 .idVendor = 0x046d,
2114 .idProduct = 0x08c5,
2115 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2116 .bInterfaceSubClass = 1,
2117 .bInterfaceProtocol = 0 },
2118 /* Logitech Quickcam OEM Dell Notebook */
2119 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2120 | USB_DEVICE_ID_MATCH_INT_INFO,
2121 .idVendor = 0x046d,
2122 .idProduct = 0x08c6,
2123 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2124 .bInterfaceSubClass = 1,
2125 .bInterfaceProtocol = 0 },
2126 /* Logitech Quickcam OEM Cisco VT Camera II */
2127 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2128 | USB_DEVICE_ID_MATCH_INT_INFO,
2129 .idVendor = 0x046d,
2130 .idProduct = 0x08c7,
2131 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2132 .bInterfaceSubClass = 1,
2133 .bInterfaceProtocol = 0 },
86d8b6ab
LP
2134 /* Chicony CNF7129 (Asus EEE 100HE) */
2135 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2136 | USB_DEVICE_ID_MATCH_INT_INFO,
2137 .idVendor = 0x04f2,
2138 .idProduct = 0xb071,
2139 .bInterfaceClass = USB_CLASS_VIDEO,
2140 .bInterfaceSubClass = 1,
2141 .bInterfaceProtocol = 0,
2142 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
f61d1d8a
LP
2143 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2144 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2145 | USB_DEVICE_ID_MATCH_INT_INFO,
2146 .idVendor = 0x058f,
2147 .idProduct = 0x3820,
2148 .bInterfaceClass = USB_CLASS_VIDEO,
2149 .bInterfaceSubClass = 1,
2150 .bInterfaceProtocol = 0,
2151 .driver_info = UVC_QUIRK_PROBE_MINMAX },
3efe2f1b
LP
2152 /* Dell XPS m1530 */
2153 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2154 | USB_DEVICE_ID_MATCH_INT_INFO,
2155 .idVendor = 0x05a9,
2156 .idProduct = 0x2640,
2157 .bInterfaceClass = USB_CLASS_VIDEO,
2158 .bInterfaceSubClass = 1,
2159 .bInterfaceProtocol = 0,
2160 .driver_info = UVC_QUIRK_PROBE_DEF },
c0efd232 2161 /* Apple Built-In iSight */
2c2d264b 2162 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
c0efd232
LP
2163 | USB_DEVICE_ID_MATCH_INT_INFO,
2164 .idVendor = 0x05ac,
2165 .idProduct = 0x8501,
2c2d264b
LP
2166 .bInterfaceClass = USB_CLASS_VIDEO,
2167 .bInterfaceSubClass = 1,
2168 .bInterfaceProtocol = 0,
c0efd232
LP
2169 .driver_info = UVC_QUIRK_PROBE_MINMAX
2170 | UVC_QUIRK_BUILTIN_ISIGHT },
949d9264
KS
2171 /* Foxlink ("HP Webcam" on HP Mini 5103) */
2172 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2173 | USB_DEVICE_ID_MATCH_INT_INFO,
2174 .idVendor = 0x05c8,
2175 .idProduct = 0x0403,
2176 .bInterfaceClass = USB_CLASS_VIDEO,
2177 .bInterfaceSubClass = 1,
2178 .bInterfaceProtocol = 0,
2179 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
c0efd232 2180 /* Genesys Logic USB 2.0 PC Camera */
2c2d264b 2181 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
c0efd232 2182 | USB_DEVICE_ID_MATCH_INT_INFO,
2c2d264b
LP
2183 .idVendor = 0x05e3,
2184 .idProduct = 0x0505,
2185 .bInterfaceClass = USB_CLASS_VIDEO,
2186 .bInterfaceSubClass = 1,
2187 .bInterfaceProtocol = 0,
2188 .driver_info = UVC_QUIRK_STREAM_NO_FID },
e01a2344
LP
2189 /* Hercules Classic Silver */
2190 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2191 | USB_DEVICE_ID_MATCH_INT_INFO,
2192 .idVendor = 0x06f8,
2193 .idProduct = 0x300c,
2194 .bInterfaceClass = USB_CLASS_VIDEO,
2195 .bInterfaceSubClass = 1,
2196 .bInterfaceProtocol = 0,
2197 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
d79cd839
LP
2198 /* ViMicro Vega */
2199 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2200 | USB_DEVICE_ID_MATCH_INT_INFO,
2201 .idVendor = 0x0ac8,
2202 .idProduct = 0x332d,
2203 .bInterfaceClass = USB_CLASS_VIDEO,
2204 .bInterfaceSubClass = 1,
2205 .bInterfaceProtocol = 0,
2206 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2207 /* ViMicro - Minoru3D */
2208 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2209 | USB_DEVICE_ID_MATCH_INT_INFO,
2210 .idVendor = 0x0ac8,
2211 .idProduct = 0x3410,
2212 .bInterfaceClass = USB_CLASS_VIDEO,
2213 .bInterfaceSubClass = 1,
2214 .bInterfaceProtocol = 0,
2215 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
2216 /* ViMicro Venus - Minoru3D */
2217 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
50144aee
LP
2218 | USB_DEVICE_ID_MATCH_INT_INFO,
2219 .idVendor = 0x0ac8,
d79cd839 2220 .idProduct = 0x3420,
50144aee
LP
2221 .bInterfaceClass = USB_CLASS_VIDEO,
2222 .bInterfaceSubClass = 1,
2223 .bInterfaceProtocol = 0,
2224 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
d584b838
LP
2225 /* Ophir Optronics - SPCAM 620U */
2226 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2227 | USB_DEVICE_ID_MATCH_INT_INFO,
2228 .idVendor = 0x0bd3,
2229 .idProduct = 0x0555,
2230 .bInterfaceClass = USB_CLASS_VIDEO,
2231 .bInterfaceSubClass = 1,
2232 .bInterfaceProtocol = 0,
2233 .driver_info = UVC_QUIRK_PROBE_MINMAX },
c0efd232
LP
2234 /* MT6227 */
2235 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2236 | USB_DEVICE_ID_MATCH_INT_INFO,
2237 .idVendor = 0x0e8d,
2238 .idProduct = 0x0004,
2239 .bInterfaceClass = USB_CLASS_VIDEO,
2240 .bInterfaceSubClass = 1,
2241 .bInterfaceProtocol = 0,
bab6f66c
LP
2242 .driver_info = UVC_QUIRK_PROBE_MINMAX
2243 | UVC_QUIRK_PROBE_DEF },
9275b32b
LP
2244 /* IMC Networks (Medion Akoya) */
2245 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2246 | USB_DEVICE_ID_MATCH_INT_INFO,
2247 .idVendor = 0x13d3,
2248 .idProduct = 0x5103,
2249 .bInterfaceClass = USB_CLASS_VIDEO,
2250 .bInterfaceSubClass = 1,
2251 .bInterfaceProtocol = 0,
2252 .driver_info = UVC_QUIRK_STREAM_NO_FID },
d1787b1f
LP
2253 /* JMicron USB2.0 XGA WebCam */
2254 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2255 | USB_DEVICE_ID_MATCH_INT_INFO,
2256 .idVendor = 0x152d,
2257 .idProduct = 0x0310,
2258 .bInterfaceClass = USB_CLASS_VIDEO,
2259 .bInterfaceSubClass = 1,
2260 .bInterfaceProtocol = 0,
2261 .driver_info = UVC_QUIRK_PROBE_MINMAX },
c0efd232
LP
2262 /* Syntek (HP Spartan) */
2263 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2264 | USB_DEVICE_ID_MATCH_INT_INFO,
2265 .idVendor = 0x174f,
2266 .idProduct = 0x5212,
2267 .bInterfaceClass = USB_CLASS_VIDEO,
2268 .bInterfaceSubClass = 1,
2269 .bInterfaceProtocol = 0,
25e69850 2270 .driver_info = UVC_QUIRK_STREAM_NO_FID },
562f0fed
LP
2271 /* Syntek (Samsung Q310) */
2272 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2273 | USB_DEVICE_ID_MATCH_INT_INFO,
2274 .idVendor = 0x174f,
2275 .idProduct = 0x5931,
2276 .bInterfaceClass = USB_CLASS_VIDEO,
2277 .bInterfaceSubClass = 1,
2278 .bInterfaceProtocol = 0,
2279 .driver_info = UVC_QUIRK_STREAM_NO_FID },
f129b03b
LP
2280 /* Syntek (Packard Bell EasyNote MX52 */
2281 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2282 | USB_DEVICE_ID_MATCH_INT_INFO,
2283 .idVendor = 0x174f,
2284 .idProduct = 0x8a12,
2285 .bInterfaceClass = USB_CLASS_VIDEO,
2286 .bInterfaceSubClass = 1,
2287 .bInterfaceProtocol = 0,
2288 .driver_info = UVC_QUIRK_STREAM_NO_FID },
f61d1d8a 2289 /* Syntek (Asus F9SG) */
25e69850
LP
2290 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2291 | USB_DEVICE_ID_MATCH_INT_INFO,
2292 .idVendor = 0x174f,
2293 .idProduct = 0x8a31,
2294 .bInterfaceClass = USB_CLASS_VIDEO,
2295 .bInterfaceSubClass = 1,
2296 .bInterfaceProtocol = 0,
c0efd232
LP
2297 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2298 /* Syntek (Asus U3S) */
2299 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2300 | USB_DEVICE_ID_MATCH_INT_INFO,
2301 .idVendor = 0x174f,
2302 .idProduct = 0x8a33,
2303 .bInterfaceClass = USB_CLASS_VIDEO,
2304 .bInterfaceSubClass = 1,
2305 .bInterfaceProtocol = 0,
2306 .driver_info = UVC_QUIRK_STREAM_NO_FID },
0ce566da
LP
2307 /* Syntek (JAOtech Smart Terminal) */
2308 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2309 | USB_DEVICE_ID_MATCH_INT_INFO,
2310 .idVendor = 0x174f,
2311 .idProduct = 0x8a34,
2312 .bInterfaceClass = USB_CLASS_VIDEO,
2313 .bInterfaceSubClass = 1,
2314 .bInterfaceProtocol = 0,
2315 .driver_info = UVC_QUIRK_STREAM_NO_FID },
70092c26
LP
2316 /* Miricle 307K */
2317 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2318 | USB_DEVICE_ID_MATCH_INT_INFO,
2319 .idVendor = 0x17dc,
2320 .idProduct = 0x0202,
2321 .bInterfaceClass = USB_CLASS_VIDEO,
2322 .bInterfaceSubClass = 1,
2323 .bInterfaceProtocol = 0,
2324 .driver_info = UVC_QUIRK_STREAM_NO_FID },
849a3aba 2325 /* Lenovo Thinkpad SL400/SL500 */
2f38483b
LP
2326 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2327 | USB_DEVICE_ID_MATCH_INT_INFO,
2328 .idVendor = 0x17ef,
2329 .idProduct = 0x480b,
2330 .bInterfaceClass = USB_CLASS_VIDEO,
2331 .bInterfaceSubClass = 1,
2332 .bInterfaceProtocol = 0,
2333 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2d2bf2a3
LP
2334 /* Aveo Technology USB 2.0 Camera */
2335 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2336 | USB_DEVICE_ID_MATCH_INT_INFO,
2337 .idVendor = 0x1871,
2338 .idProduct = 0x0306,
2339 .bInterfaceClass = USB_CLASS_VIDEO,
2340 .bInterfaceSubClass = 1,
2341 .bInterfaceProtocol = 0,
5bdf1377
LP
2342 .driver_info = UVC_QUIRK_PROBE_MINMAX
2343 | UVC_QUIRK_PROBE_EXTRAFIELDS },
c0efd232
LP
2344 /* Ecamm Pico iMage */
2345 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2346 | USB_DEVICE_ID_MATCH_INT_INFO,
2347 .idVendor = 0x18cd,
2348 .idProduct = 0xcafe,
2349 .bInterfaceClass = USB_CLASS_VIDEO,
2350 .bInterfaceSubClass = 1,
2351 .bInterfaceProtocol = 0,
2352 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2bb00fe6
LP
2353 /* Manta MM-353 Plako */
2354 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2355 | USB_DEVICE_ID_MATCH_INT_INFO,
2356 .idVendor = 0x18ec,
2357 .idProduct = 0x3188,
2358 .bInterfaceClass = USB_CLASS_VIDEO,
2359 .bInterfaceSubClass = 1,
2360 .bInterfaceProtocol = 0,
2361 .driver_info = UVC_QUIRK_PROBE_MINMAX },
ca4a3456
LP
2362 /* FSC WebCam V30S */
2363 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2364 | USB_DEVICE_ID_MATCH_INT_INFO,
2365 .idVendor = 0x18ec,
2366 .idProduct = 0x3288,
2367 .bInterfaceClass = USB_CLASS_VIDEO,
2368 .bInterfaceSubClass = 1,
2369 .bInterfaceProtocol = 0,
2370 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1e4d05bc
LP
2371 /* Arkmicro unbranded */
2372 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2373 | USB_DEVICE_ID_MATCH_INT_INFO,
2374 .idVendor = 0x18ec,
2375 .idProduct = 0x3290,
2376 .bInterfaceClass = USB_CLASS_VIDEO,
2377 .bInterfaceSubClass = 1,
2378 .bInterfaceProtocol = 0,
2379 .driver_info = UVC_QUIRK_PROBE_DEF },
fd3e9f2f
AC
2380 /* The Imaging Source USB CCD cameras */
2381 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2382 | USB_DEVICE_ID_MATCH_INT_INFO,
2383 .idVendor = 0x199e,
2384 .idProduct = 0x8102,
2385 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2386 .bInterfaceSubClass = 1,
2387 .bInterfaceProtocol = 0 },
c0efd232
LP
2388 /* Bodelin ProScopeHR */
2389 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2390 | USB_DEVICE_ID_MATCH_DEV_HI
2391 | USB_DEVICE_ID_MATCH_INT_INFO,
2392 .idVendor = 0x19ab,
2393 .idProduct = 0x1000,
2394 .bcdDevice_hi = 0x0126,
2395 .bInterfaceClass = USB_CLASS_VIDEO,
2396 .bInterfaceSubClass = 1,
2397 .bInterfaceProtocol = 0,
2398 .driver_info = UVC_QUIRK_STATUS_INTERVAL },
3bc766ad
LP
2399 /* MSI StarCam 370i */
2400 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2401 | USB_DEVICE_ID_MATCH_INT_INFO,
2402 .idVendor = 0x1b3b,
2403 .idProduct = 0x2951,
2404 .bInterfaceClass = USB_CLASS_VIDEO,
2405 .bInterfaceSubClass = 1,
2406 .bInterfaceProtocol = 0,
2407 .driver_info = UVC_QUIRK_PROBE_MINMAX },
c0efd232
LP
2408 /* SiGma Micro USB Web Camera */
2409 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2410 | USB_DEVICE_ID_MATCH_INT_INFO,
2411 .idVendor = 0x1c4f,
2412 .idProduct = 0x3000,
2413 .bInterfaceClass = USB_CLASS_VIDEO,
2414 .bInterfaceSubClass = 1,
2415 .bInterfaceProtocol = 0,
2416 .driver_info = UVC_QUIRK_PROBE_MINMAX
d732c44c 2417 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
c0efd232
LP
2418 /* Generic USB Video Class */
2419 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2420 {}
2421};
2422
2423MODULE_DEVICE_TABLE(usb, uvc_ids);
2424
2425struct uvc_driver uvc_driver = {
2426 .driver = {
2427 .name = "uvcvideo",
2428 .probe = uvc_probe,
2429 .disconnect = uvc_disconnect,
2430 .suspend = uvc_suspend,
2431 .resume = uvc_resume,
9b0ae867 2432 .reset_resume = uvc_reset_resume,
c0efd232
LP
2433 .id_table = uvc_ids,
2434 .supports_autosuspend = 1,
2435 },
2436};
2437
2438static int __init uvc_init(void)
2439{
edbaa398 2440 int ret;
c0efd232 2441
edbaa398
AF
2442 uvc_debugfs_init();
2443
2444 ret = usb_register(&uvc_driver.driver);
2445 if (ret < 0) {
2446 uvc_debugfs_cleanup();
2447 return ret;
2448 }
2449
2450 printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2451 return 0;
c0efd232
LP
2452}
2453
2454static void __exit uvc_cleanup(void)
2455{
2456 usb_deregister(&uvc_driver.driver);
edbaa398 2457 uvc_debugfs_cleanup();
c0efd232
LP
2458}
2459
2460module_init(uvc_init);
2461module_exit(uvc_cleanup);
2462
c0efd232
LP
2463MODULE_AUTHOR(DRIVER_AUTHOR);
2464MODULE_DESCRIPTION(DRIVER_DESC);
2465MODULE_LICENSE("GPL");
2466MODULE_VERSION(DRIVER_VERSION);
f87086e3 2467
This page took 0.951583 seconds and 5 git commands to generate.