xref: /openbmc/linux/drivers/media/usb/uvc/uvc_driver.c (revision 6d99a79c)
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 			strscpy(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 				strscpy(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 		strscpy(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 			strscpy(format->name, "SD-DV", sizeof(format->name));
493 			break;
494 		case 1:
495 			strscpy(format->name, "SDL-DV", sizeof(format->name));
496 			break;
497 		case 2:
498 			strscpy(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 = roundup(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 	strscpy(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,
2032 				   "Failed to register entities (%d).\n", ret);
2033 #endif
2034 	}
2035 
2036 	return 0;
2037 }
2038 
2039 /* ------------------------------------------------------------------------
2040  * USB probe, disconnect, suspend and resume
2041  */
2042 
2043 static const struct uvc_device_info uvc_quirk_none = { 0 };
2044 
2045 static int uvc_probe(struct usb_interface *intf,
2046 		     const struct usb_device_id *id)
2047 {
2048 	struct usb_device *udev = interface_to_usbdev(intf);
2049 	struct uvc_device *dev;
2050 	const struct uvc_device_info *info =
2051 		(const struct uvc_device_info *)id->driver_info;
2052 	int function;
2053 	int ret;
2054 
2055 	if (id->idVendor && id->idProduct)
2056 		uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
2057 				"(%04x:%04x)\n", udev->devpath, id->idVendor,
2058 				id->idProduct);
2059 	else
2060 		uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
2061 				udev->devpath);
2062 
2063 	/* Allocate memory for the device and initialize it. */
2064 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2065 	if (dev == NULL)
2066 		return -ENOMEM;
2067 
2068 	INIT_LIST_HEAD(&dev->entities);
2069 	INIT_LIST_HEAD(&dev->chains);
2070 	INIT_LIST_HEAD(&dev->streams);
2071 	kref_init(&dev->ref);
2072 	atomic_set(&dev->nmappings, 0);
2073 	mutex_init(&dev->lock);
2074 
2075 	dev->udev = usb_get_dev(udev);
2076 	dev->intf = usb_get_intf(intf);
2077 	dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
2078 	dev->info = info ? info : &uvc_quirk_none;
2079 	dev->quirks = uvc_quirks_param == -1
2080 		    ? dev->info->quirks : uvc_quirks_param;
2081 
2082 	if (udev->product != NULL)
2083 		strscpy(dev->name, udev->product, sizeof(dev->name));
2084 	else
2085 		snprintf(dev->name, sizeof(dev->name),
2086 			 "UVC Camera (%04x:%04x)",
2087 			 le16_to_cpu(udev->descriptor.idVendor),
2088 			 le16_to_cpu(udev->descriptor.idProduct));
2089 
2090 	/*
2091 	 * Add iFunction or iInterface to names when available as additional
2092 	 * distinguishers between interfaces. iFunction is prioritized over
2093 	 * iInterface which matches Windows behavior at the point of writing.
2094 	 */
2095 	if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
2096 		function = intf->intf_assoc->iFunction;
2097 	else
2098 		function = intf->cur_altsetting->desc.iInterface;
2099 	if (function != 0) {
2100 		size_t len;
2101 
2102 		strlcat(dev->name, ": ", sizeof(dev->name));
2103 		len = strlen(dev->name);
2104 		usb_string(udev, function, dev->name + len,
2105 			   sizeof(dev->name) - len);
2106 	}
2107 
2108 	/* Parse the Video Class control descriptor. */
2109 	if (uvc_parse_control(dev) < 0) {
2110 		uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
2111 			"descriptors.\n");
2112 		goto error;
2113 	}
2114 
2115 	uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
2116 		dev->uvc_version >> 8, dev->uvc_version & 0xff,
2117 		udev->product ? udev->product : "<unnamed>",
2118 		le16_to_cpu(udev->descriptor.idVendor),
2119 		le16_to_cpu(udev->descriptor.idProduct));
2120 
2121 	if (dev->quirks != dev->info->quirks) {
2122 		uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
2123 			"parameter for testing purpose.\n", dev->quirks);
2124 		uvc_printk(KERN_INFO, "Please report required quirks to the "
2125 			"linux-uvc-devel mailing list.\n");
2126 	}
2127 
2128 	/* Initialize the media device and register the V4L2 device. */
2129 #ifdef CONFIG_MEDIA_CONTROLLER
2130 	dev->mdev.dev = &intf->dev;
2131 	strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2132 	if (udev->serial)
2133 		strscpy(dev->mdev.serial, udev->serial,
2134 			sizeof(dev->mdev.serial));
2135 	strscpy(dev->mdev.bus_info, udev->devpath, sizeof(dev->mdev.bus_info));
2136 	dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2137 	media_device_init(&dev->mdev);
2138 
2139 	dev->vdev.mdev = &dev->mdev;
2140 #endif
2141 	if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2142 		goto error;
2143 
2144 	/* Initialize controls. */
2145 	if (uvc_ctrl_init_device(dev) < 0)
2146 		goto error;
2147 
2148 	/* Scan the device for video chains. */
2149 	if (uvc_scan_device(dev) < 0)
2150 		goto error;
2151 
2152 	/* Register video device nodes. */
2153 	if (uvc_register_chains(dev) < 0)
2154 		goto error;
2155 
2156 #ifdef CONFIG_MEDIA_CONTROLLER
2157 	/* Register the media device node */
2158 	if (media_device_register(&dev->mdev) < 0)
2159 		goto error;
2160 #endif
2161 	/* Save our data pointer in the interface data. */
2162 	usb_set_intfdata(intf, dev);
2163 
2164 	/* Initialize the interrupt URB. */
2165 	if ((ret = uvc_status_init(dev)) < 0) {
2166 		uvc_printk(KERN_INFO, "Unable to initialize the status "
2167 			"endpoint (%d), status interrupt will not be "
2168 			"supported.\n", ret);
2169 	}
2170 
2171 	uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
2172 	usb_enable_autosuspend(udev);
2173 	return 0;
2174 
2175 error:
2176 	uvc_unregister_video(dev);
2177 	kref_put(&dev->ref, uvc_delete);
2178 	return -ENODEV;
2179 }
2180 
2181 static void uvc_disconnect(struct usb_interface *intf)
2182 {
2183 	struct uvc_device *dev = usb_get_intfdata(intf);
2184 
2185 	/* Set the USB interface data to NULL. This can be done outside the
2186 	 * lock, as there's no other reader.
2187 	 */
2188 	usb_set_intfdata(intf, NULL);
2189 
2190 	if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2191 	    UVC_SC_VIDEOSTREAMING)
2192 		return;
2193 
2194 	uvc_unregister_video(dev);
2195 	kref_put(&dev->ref, uvc_delete);
2196 }
2197 
2198 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
2199 {
2200 	struct uvc_device *dev = usb_get_intfdata(intf);
2201 	struct uvc_streaming *stream;
2202 
2203 	uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
2204 		intf->cur_altsetting->desc.bInterfaceNumber);
2205 
2206 	/* Controls are cached on the fly so they don't need to be saved. */
2207 	if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2208 	    UVC_SC_VIDEOCONTROL) {
2209 		mutex_lock(&dev->lock);
2210 		if (dev->users)
2211 			uvc_status_stop(dev);
2212 		mutex_unlock(&dev->lock);
2213 		return 0;
2214 	}
2215 
2216 	list_for_each_entry(stream, &dev->streams, list) {
2217 		if (stream->intf == intf)
2218 			return uvc_video_suspend(stream);
2219 	}
2220 
2221 	uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
2222 			"mismatch.\n");
2223 	return -EINVAL;
2224 }
2225 
2226 static int __uvc_resume(struct usb_interface *intf, int reset)
2227 {
2228 	struct uvc_device *dev = usb_get_intfdata(intf);
2229 	struct uvc_streaming *stream;
2230 	int ret = 0;
2231 
2232 	uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2233 		intf->cur_altsetting->desc.bInterfaceNumber);
2234 
2235 	if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2236 	    UVC_SC_VIDEOCONTROL) {
2237 		if (reset) {
2238 			ret = uvc_ctrl_restore_values(dev);
2239 			if (ret < 0)
2240 				return ret;
2241 		}
2242 
2243 		mutex_lock(&dev->lock);
2244 		if (dev->users)
2245 			ret = uvc_status_start(dev, GFP_NOIO);
2246 		mutex_unlock(&dev->lock);
2247 
2248 		return ret;
2249 	}
2250 
2251 	list_for_each_entry(stream, &dev->streams, list) {
2252 		if (stream->intf == intf) {
2253 			ret = uvc_video_resume(stream, reset);
2254 			if (ret < 0)
2255 				uvc_queue_streamoff(&stream->queue,
2256 						    stream->queue.queue.type);
2257 			return ret;
2258 		}
2259 	}
2260 
2261 	uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2262 			"mismatch.\n");
2263 	return -EINVAL;
2264 }
2265 
2266 static int uvc_resume(struct usb_interface *intf)
2267 {
2268 	return __uvc_resume(intf, 0);
2269 }
2270 
2271 static int uvc_reset_resume(struct usb_interface *intf)
2272 {
2273 	return __uvc_resume(intf, 1);
2274 }
2275 
2276 /* ------------------------------------------------------------------------
2277  * Module parameters
2278  */
2279 
2280 static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
2281 {
2282 	if (uvc_clock_param == CLOCK_MONOTONIC)
2283 		return sprintf(buffer, "CLOCK_MONOTONIC");
2284 	else
2285 		return sprintf(buffer, "CLOCK_REALTIME");
2286 }
2287 
2288 static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
2289 {
2290 	if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2291 		val += strlen("clock_");
2292 
2293 	if (strcasecmp(val, "monotonic") == 0)
2294 		uvc_clock_param = CLOCK_MONOTONIC;
2295 	else if (strcasecmp(val, "realtime") == 0)
2296 		uvc_clock_param = CLOCK_REALTIME;
2297 	else
2298 		return -EINVAL;
2299 
2300 	return 0;
2301 }
2302 
2303 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2304 		  &uvc_clock_param, S_IRUGO|S_IWUSR);
2305 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2306 module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR);
2307 MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps");
2308 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2309 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2310 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2311 MODULE_PARM_DESC(quirks, "Forced device quirks");
2312 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2313 MODULE_PARM_DESC(trace, "Trace level bitmask");
2314 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2315 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2316 
2317 /* ------------------------------------------------------------------------
2318  * Driver initialization and cleanup
2319  */
2320 
2321 static const struct uvc_device_info uvc_quirk_probe_minmax = {
2322 	.quirks = UVC_QUIRK_PROBE_MINMAX,
2323 };
2324 
2325 static const struct uvc_device_info uvc_quirk_fix_bandwidth = {
2326 	.quirks = UVC_QUIRK_FIX_BANDWIDTH,
2327 };
2328 
2329 static const struct uvc_device_info uvc_quirk_probe_def = {
2330 	.quirks = UVC_QUIRK_PROBE_DEF,
2331 };
2332 
2333 static const struct uvc_device_info uvc_quirk_stream_no_fid = {
2334 	.quirks = UVC_QUIRK_STREAM_NO_FID,
2335 };
2336 
2337 static const struct uvc_device_info uvc_quirk_force_y8 = {
2338 	.quirks = UVC_QUIRK_FORCE_Y8,
2339 };
2340 
2341 #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q}
2342 #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \
2343 	{.meta_format = m}
2344 
2345 /*
2346  * The Logitech cameras listed below have their interface class set to
2347  * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2348  * though they are compliant.
2349  */
2350 static const struct usb_device_id uvc_ids[] = {
2351 	/* LogiLink Wireless Webcam */
2352 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2353 				| USB_DEVICE_ID_MATCH_INT_INFO,
2354 	  .idVendor		= 0x0416,
2355 	  .idProduct		= 0xa91a,
2356 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2357 	  .bInterfaceSubClass	= 1,
2358 	  .bInterfaceProtocol	= 0,
2359 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2360 	/* Genius eFace 2025 */
2361 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2362 				| USB_DEVICE_ID_MATCH_INT_INFO,
2363 	  .idVendor		= 0x0458,
2364 	  .idProduct		= 0x706e,
2365 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2366 	  .bInterfaceSubClass	= 1,
2367 	  .bInterfaceProtocol	= 0,
2368 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2369 	/* Microsoft Lifecam NX-6000 */
2370 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2371 				| USB_DEVICE_ID_MATCH_INT_INFO,
2372 	  .idVendor		= 0x045e,
2373 	  .idProduct		= 0x00f8,
2374 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2375 	  .bInterfaceSubClass	= 1,
2376 	  .bInterfaceProtocol	= 0,
2377 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2378 	/* Microsoft Lifecam NX-3000 */
2379 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2380 				| USB_DEVICE_ID_MATCH_INT_INFO,
2381 	  .idVendor		= 0x045e,
2382 	  .idProduct		= 0x0721,
2383 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2384 	  .bInterfaceSubClass	= 1,
2385 	  .bInterfaceProtocol	= 0,
2386 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2387 	/* Microsoft Lifecam VX-7000 */
2388 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2389 				| USB_DEVICE_ID_MATCH_INT_INFO,
2390 	  .idVendor		= 0x045e,
2391 	  .idProduct		= 0x0723,
2392 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2393 	  .bInterfaceSubClass	= 1,
2394 	  .bInterfaceProtocol	= 0,
2395 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2396 	/* Logitech Quickcam Fusion */
2397 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2398 				| USB_DEVICE_ID_MATCH_INT_INFO,
2399 	  .idVendor		= 0x046d,
2400 	  .idProduct		= 0x08c1,
2401 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2402 	  .bInterfaceSubClass	= 1,
2403 	  .bInterfaceProtocol	= 0 },
2404 	/* Logitech Quickcam Orbit MP */
2405 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2406 				| USB_DEVICE_ID_MATCH_INT_INFO,
2407 	  .idVendor		= 0x046d,
2408 	  .idProduct		= 0x08c2,
2409 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2410 	  .bInterfaceSubClass	= 1,
2411 	  .bInterfaceProtocol	= 0 },
2412 	/* Logitech Quickcam Pro for Notebook */
2413 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2414 				| USB_DEVICE_ID_MATCH_INT_INFO,
2415 	  .idVendor		= 0x046d,
2416 	  .idProduct		= 0x08c3,
2417 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2418 	  .bInterfaceSubClass	= 1,
2419 	  .bInterfaceProtocol	= 0 },
2420 	/* Logitech Quickcam Pro 5000 */
2421 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2422 				| USB_DEVICE_ID_MATCH_INT_INFO,
2423 	  .idVendor		= 0x046d,
2424 	  .idProduct		= 0x08c5,
2425 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2426 	  .bInterfaceSubClass	= 1,
2427 	  .bInterfaceProtocol	= 0 },
2428 	/* Logitech Quickcam OEM Dell Notebook */
2429 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2430 				| USB_DEVICE_ID_MATCH_INT_INFO,
2431 	  .idVendor		= 0x046d,
2432 	  .idProduct		= 0x08c6,
2433 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2434 	  .bInterfaceSubClass	= 1,
2435 	  .bInterfaceProtocol	= 0 },
2436 	/* Logitech Quickcam OEM Cisco VT Camera II */
2437 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2438 				| USB_DEVICE_ID_MATCH_INT_INFO,
2439 	  .idVendor		= 0x046d,
2440 	  .idProduct		= 0x08c7,
2441 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2442 	  .bInterfaceSubClass	= 1,
2443 	  .bInterfaceProtocol	= 0 },
2444 	/* Logitech HD Pro Webcam C920 */
2445 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2446 				| USB_DEVICE_ID_MATCH_INT_INFO,
2447 	  .idVendor		= 0x046d,
2448 	  .idProduct		= 0x082d,
2449 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2450 	  .bInterfaceSubClass	= 1,
2451 	  .bInterfaceProtocol	= 0,
2452 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT) },
2453 	/* Chicony CNF7129 (Asus EEE 100HE) */
2454 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2455 				| USB_DEVICE_ID_MATCH_INT_INFO,
2456 	  .idVendor		= 0x04f2,
2457 	  .idProduct		= 0xb071,
2458 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2459 	  .bInterfaceSubClass	= 1,
2460 	  .bInterfaceProtocol	= 0,
2461 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },
2462 	/* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2463 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2464 				| USB_DEVICE_ID_MATCH_INT_INFO,
2465 	  .idVendor		= 0x058f,
2466 	  .idProduct		= 0x3820,
2467 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2468 	  .bInterfaceSubClass	= 1,
2469 	  .bInterfaceProtocol	= 0,
2470 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2471 	/* Dell XPS m1530 */
2472 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2473 				| USB_DEVICE_ID_MATCH_INT_INFO,
2474 	  .idVendor		= 0x05a9,
2475 	  .idProduct		= 0x2640,
2476 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2477 	  .bInterfaceSubClass	= 1,
2478 	  .bInterfaceProtocol	= 0,
2479 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2480 	/* Dell SP2008WFP Monitor */
2481 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2482 				| USB_DEVICE_ID_MATCH_INT_INFO,
2483 	  .idVendor		= 0x05a9,
2484 	  .idProduct		= 0x2641,
2485 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2486 	  .bInterfaceSubClass	= 1,
2487 	  .bInterfaceProtocol	= 0,
2488 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2489 	/* Dell Alienware X51 */
2490 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2491 				| USB_DEVICE_ID_MATCH_INT_INFO,
2492 	  .idVendor		= 0x05a9,
2493 	  .idProduct		= 0x2643,
2494 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2495 	  .bInterfaceSubClass	= 1,
2496 	  .bInterfaceProtocol	= 0,
2497 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2498 	/* Dell Studio Hybrid 140g (OmniVision webcam) */
2499 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2500 				| USB_DEVICE_ID_MATCH_INT_INFO,
2501 	  .idVendor		= 0x05a9,
2502 	  .idProduct		= 0x264a,
2503 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2504 	  .bInterfaceSubClass	= 1,
2505 	  .bInterfaceProtocol	= 0,
2506 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2507 	/* Dell XPS M1330 (OmniVision OV7670 webcam) */
2508 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2509 				| USB_DEVICE_ID_MATCH_INT_INFO,
2510 	  .idVendor		= 0x05a9,
2511 	  .idProduct		= 0x7670,
2512 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2513 	  .bInterfaceSubClass	= 1,
2514 	  .bInterfaceProtocol	= 0,
2515 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2516 	/* Apple Built-In iSight */
2517 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2518 				| USB_DEVICE_ID_MATCH_INT_INFO,
2519 	  .idVendor		= 0x05ac,
2520 	  .idProduct		= 0x8501,
2521 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2522 	  .bInterfaceSubClass	= 1,
2523 	  .bInterfaceProtocol	= 0,
2524 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2525 					| UVC_QUIRK_BUILTIN_ISIGHT) },
2526 	/* Apple Built-In iSight via iBridge */
2527 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2528 				| USB_DEVICE_ID_MATCH_INT_INFO,
2529 	  .idVendor		= 0x05ac,
2530 	  .idProduct		= 0x8600,
2531 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2532 	  .bInterfaceSubClass	= 1,
2533 	  .bInterfaceProtocol	= 0,
2534 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2535 	/* Foxlink ("HP Webcam" on HP Mini 5103) */
2536 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2537 				| USB_DEVICE_ID_MATCH_INT_INFO,
2538 	  .idVendor		= 0x05c8,
2539 	  .idProduct		= 0x0403,
2540 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2541 	  .bInterfaceSubClass	= 1,
2542 	  .bInterfaceProtocol	= 0,
2543 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2544 	/* Genesys Logic USB 2.0 PC Camera */
2545 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2546 				| USB_DEVICE_ID_MATCH_INT_INFO,
2547 	  .idVendor		= 0x05e3,
2548 	  .idProduct		= 0x0505,
2549 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2550 	  .bInterfaceSubClass	= 1,
2551 	  .bInterfaceProtocol	= 0,
2552 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2553 	/* Hercules Classic Silver */
2554 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2555 				| USB_DEVICE_ID_MATCH_INT_INFO,
2556 	  .idVendor		= 0x06f8,
2557 	  .idProduct		= 0x300c,
2558 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2559 	  .bInterfaceSubClass	= 1,
2560 	  .bInterfaceProtocol	= 0,
2561 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2562 	/* ViMicro Vega */
2563 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2564 				| USB_DEVICE_ID_MATCH_INT_INFO,
2565 	  .idVendor		= 0x0ac8,
2566 	  .idProduct		= 0x332d,
2567 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2568 	  .bInterfaceSubClass	= 1,
2569 	  .bInterfaceProtocol	= 0,
2570 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2571 	/* ViMicro - Minoru3D */
2572 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2573 				| USB_DEVICE_ID_MATCH_INT_INFO,
2574 	  .idVendor		= 0x0ac8,
2575 	  .idProduct		= 0x3410,
2576 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2577 	  .bInterfaceSubClass	= 1,
2578 	  .bInterfaceProtocol	= 0,
2579 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2580 	/* ViMicro Venus - Minoru3D */
2581 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2582 				| USB_DEVICE_ID_MATCH_INT_INFO,
2583 	  .idVendor		= 0x0ac8,
2584 	  .idProduct		= 0x3420,
2585 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2586 	  .bInterfaceSubClass	= 1,
2587 	  .bInterfaceProtocol	= 0,
2588 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_fix_bandwidth },
2589 	/* Ophir Optronics - SPCAM 620U */
2590 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2591 				| USB_DEVICE_ID_MATCH_INT_INFO,
2592 	  .idVendor		= 0x0bd3,
2593 	  .idProduct		= 0x0555,
2594 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2595 	  .bInterfaceSubClass	= 1,
2596 	  .bInterfaceProtocol	= 0,
2597 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2598 	/* MT6227 */
2599 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2600 				| USB_DEVICE_ID_MATCH_INT_INFO,
2601 	  .idVendor		= 0x0e8d,
2602 	  .idProduct		= 0x0004,
2603 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2604 	  .bInterfaceSubClass	= 1,
2605 	  .bInterfaceProtocol	= 0,
2606 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2607 					| UVC_QUIRK_PROBE_DEF) },
2608 	/* IMC Networks (Medion Akoya) */
2609 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2610 				| USB_DEVICE_ID_MATCH_INT_INFO,
2611 	  .idVendor		= 0x13d3,
2612 	  .idProduct		= 0x5103,
2613 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2614 	  .bInterfaceSubClass	= 1,
2615 	  .bInterfaceProtocol	= 0,
2616 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2617 	/* JMicron USB2.0 XGA WebCam */
2618 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2619 				| USB_DEVICE_ID_MATCH_INT_INFO,
2620 	  .idVendor		= 0x152d,
2621 	  .idProduct		= 0x0310,
2622 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2623 	  .bInterfaceSubClass	= 1,
2624 	  .bInterfaceProtocol	= 0,
2625 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2626 	/* Syntek (HP Spartan) */
2627 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2628 				| USB_DEVICE_ID_MATCH_INT_INFO,
2629 	  .idVendor		= 0x174f,
2630 	  .idProduct		= 0x5212,
2631 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2632 	  .bInterfaceSubClass	= 1,
2633 	  .bInterfaceProtocol	= 0,
2634 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2635 	/* Syntek (Samsung Q310) */
2636 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2637 				| USB_DEVICE_ID_MATCH_INT_INFO,
2638 	  .idVendor		= 0x174f,
2639 	  .idProduct		= 0x5931,
2640 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2641 	  .bInterfaceSubClass	= 1,
2642 	  .bInterfaceProtocol	= 0,
2643 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2644 	/* Syntek (Packard Bell EasyNote MX52 */
2645 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2646 				| USB_DEVICE_ID_MATCH_INT_INFO,
2647 	  .idVendor		= 0x174f,
2648 	  .idProduct		= 0x8a12,
2649 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2650 	  .bInterfaceSubClass	= 1,
2651 	  .bInterfaceProtocol	= 0,
2652 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2653 	/* Syntek (Asus F9SG) */
2654 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2655 				| USB_DEVICE_ID_MATCH_INT_INFO,
2656 	  .idVendor		= 0x174f,
2657 	  .idProduct		= 0x8a31,
2658 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2659 	  .bInterfaceSubClass	= 1,
2660 	  .bInterfaceProtocol	= 0,
2661 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2662 	/* Syntek (Asus U3S) */
2663 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2664 				| USB_DEVICE_ID_MATCH_INT_INFO,
2665 	  .idVendor		= 0x174f,
2666 	  .idProduct		= 0x8a33,
2667 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2668 	  .bInterfaceSubClass	= 1,
2669 	  .bInterfaceProtocol	= 0,
2670 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2671 	/* Syntek (JAOtech Smart Terminal) */
2672 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2673 				| USB_DEVICE_ID_MATCH_INT_INFO,
2674 	  .idVendor		= 0x174f,
2675 	  .idProduct		= 0x8a34,
2676 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2677 	  .bInterfaceSubClass	= 1,
2678 	  .bInterfaceProtocol	= 0,
2679 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2680 	/* Miricle 307K */
2681 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2682 				| USB_DEVICE_ID_MATCH_INT_INFO,
2683 	  .idVendor		= 0x17dc,
2684 	  .idProduct		= 0x0202,
2685 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2686 	  .bInterfaceSubClass	= 1,
2687 	  .bInterfaceProtocol	= 0,
2688 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2689 	/* Lenovo Thinkpad SL400/SL500 */
2690 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2691 				| USB_DEVICE_ID_MATCH_INT_INFO,
2692 	  .idVendor		= 0x17ef,
2693 	  .idProduct		= 0x480b,
2694 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2695 	  .bInterfaceSubClass	= 1,
2696 	  .bInterfaceProtocol	= 0,
2697 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_stream_no_fid },
2698 	/* Aveo Technology USB 2.0 Camera */
2699 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2700 				| USB_DEVICE_ID_MATCH_INT_INFO,
2701 	  .idVendor		= 0x1871,
2702 	  .idProduct		= 0x0306,
2703 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2704 	  .bInterfaceSubClass	= 1,
2705 	  .bInterfaceProtocol	= 0,
2706 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2707 					| UVC_QUIRK_PROBE_EXTRAFIELDS) },
2708 	/* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2709 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2710 				| USB_DEVICE_ID_MATCH_INT_INFO,
2711 	  .idVendor		= 0x1871,
2712 	  .idProduct		= 0x0516,
2713 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2714 	  .bInterfaceSubClass	= 1,
2715 	  .bInterfaceProtocol	= 0 },
2716 	/* Ecamm Pico iMage */
2717 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2718 				| USB_DEVICE_ID_MATCH_INT_INFO,
2719 	  .idVendor		= 0x18cd,
2720 	  .idProduct		= 0xcafe,
2721 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2722 	  .bInterfaceSubClass	= 1,
2723 	  .bInterfaceProtocol	= 0,
2724 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) },
2725 	/* Manta MM-353 Plako */
2726 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2727 				| USB_DEVICE_ID_MATCH_INT_INFO,
2728 	  .idVendor		= 0x18ec,
2729 	  .idProduct		= 0x3188,
2730 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2731 	  .bInterfaceSubClass	= 1,
2732 	  .bInterfaceProtocol	= 0,
2733 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2734 	/* FSC WebCam V30S */
2735 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2736 				| USB_DEVICE_ID_MATCH_INT_INFO,
2737 	  .idVendor		= 0x18ec,
2738 	  .idProduct		= 0x3288,
2739 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2740 	  .bInterfaceSubClass	= 1,
2741 	  .bInterfaceProtocol	= 0,
2742 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2743 	/* Arkmicro unbranded */
2744 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2745 				| USB_DEVICE_ID_MATCH_INT_INFO,
2746 	  .idVendor		= 0x18ec,
2747 	  .idProduct		= 0x3290,
2748 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2749 	  .bInterfaceSubClass	= 1,
2750 	  .bInterfaceProtocol	= 0,
2751 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_def },
2752 	/* The Imaging Source USB CCD cameras */
2753 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2754 				| USB_DEVICE_ID_MATCH_INT_INFO,
2755 	  .idVendor		= 0x199e,
2756 	  .idProduct		= 0x8102,
2757 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2758 	  .bInterfaceSubClass	= 1,
2759 	  .bInterfaceProtocol	= 0 },
2760 	/* Bodelin ProScopeHR */
2761 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2762 				| USB_DEVICE_ID_MATCH_DEV_HI
2763 				| USB_DEVICE_ID_MATCH_INT_INFO,
2764 	  .idVendor		= 0x19ab,
2765 	  .idProduct		= 0x1000,
2766 	  .bcdDevice_hi		= 0x0126,
2767 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2768 	  .bInterfaceSubClass	= 1,
2769 	  .bInterfaceProtocol	= 0,
2770 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) },
2771 	/* MSI StarCam 370i */
2772 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2773 				| USB_DEVICE_ID_MATCH_INT_INFO,
2774 	  .idVendor		= 0x1b3b,
2775 	  .idProduct		= 0x2951,
2776 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2777 	  .bInterfaceSubClass	= 1,
2778 	  .bInterfaceProtocol	= 0,
2779 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2780 	/* Generalplus Technology Inc. 808 Camera */
2781 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2782 				| USB_DEVICE_ID_MATCH_INT_INFO,
2783 	  .idVendor		= 0x1b3f,
2784 	  .idProduct		= 0x2002,
2785 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2786 	  .bInterfaceSubClass	= 1,
2787 	  .bInterfaceProtocol	= 0,
2788 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_probe_minmax },
2789 	/* SiGma Micro USB Web Camera */
2790 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2791 				| USB_DEVICE_ID_MATCH_INT_INFO,
2792 	  .idVendor		= 0x1c4f,
2793 	  .idProduct		= 0x3000,
2794 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2795 	  .bInterfaceSubClass	= 1,
2796 	  .bInterfaceProtocol	= 0,
2797 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX
2798 					| UVC_QUIRK_IGNORE_SELECTOR_UNIT) },
2799 	/* Oculus VR Positional Tracker DK2 */
2800 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2801 				| USB_DEVICE_ID_MATCH_INT_INFO,
2802 	  .idVendor		= 0x2833,
2803 	  .idProduct		= 0x0201,
2804 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2805 	  .bInterfaceSubClass	= 1,
2806 	  .bInterfaceProtocol	= 0,
2807 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_force_y8 },
2808 	/* Oculus VR Rift Sensor */
2809 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2810 				| USB_DEVICE_ID_MATCH_INT_INFO,
2811 	  .idVendor		= 0x2833,
2812 	  .idProduct		= 0x0211,
2813 	  .bInterfaceClass	= USB_CLASS_VENDOR_SPEC,
2814 	  .bInterfaceSubClass	= 1,
2815 	  .bInterfaceProtocol	= 0,
2816 	  .driver_info		= (kernel_ulong_t)&uvc_quirk_force_y8 },
2817 	/* Intel RealSense D4M */
2818 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
2819 				| USB_DEVICE_ID_MATCH_INT_INFO,
2820 	  .idVendor		= 0x8086,
2821 	  .idProduct		= 0x0b03,
2822 	  .bInterfaceClass	= USB_CLASS_VIDEO,
2823 	  .bInterfaceSubClass	= 1,
2824 	  .bInterfaceProtocol	= 0,
2825 	  .driver_info		= UVC_INFO_META(V4L2_META_FMT_D4XX) },
2826 	/* Generic USB Video Class */
2827 	{ USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) },
2828 	{ USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) },
2829 	{}
2830 };
2831 
2832 MODULE_DEVICE_TABLE(usb, uvc_ids);
2833 
2834 struct uvc_driver uvc_driver = {
2835 	.driver = {
2836 		.name		= "uvcvideo",
2837 		.probe		= uvc_probe,
2838 		.disconnect	= uvc_disconnect,
2839 		.suspend	= uvc_suspend,
2840 		.resume		= uvc_resume,
2841 		.reset_resume	= uvc_reset_resume,
2842 		.id_table	= uvc_ids,
2843 		.supports_autosuspend = 1,
2844 	},
2845 };
2846 
2847 static int __init uvc_init(void)
2848 {
2849 	int ret;
2850 
2851 	uvc_debugfs_init();
2852 
2853 	ret = usb_register(&uvc_driver.driver);
2854 	if (ret < 0) {
2855 		uvc_debugfs_cleanup();
2856 		return ret;
2857 	}
2858 
2859 	printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2860 	return 0;
2861 }
2862 
2863 static void __exit uvc_cleanup(void)
2864 {
2865 	usb_deregister(&uvc_driver.driver);
2866 	uvc_debugfs_cleanup();
2867 }
2868 
2869 module_init(uvc_init);
2870 module_exit(uvc_cleanup);
2871 
2872 MODULE_AUTHOR(DRIVER_AUTHOR);
2873 MODULE_DESCRIPTION(DRIVER_DESC);
2874 MODULE_LICENSE("GPL");
2875 MODULE_VERSION(DRIVER_VERSION);
2876 
2877