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