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