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