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