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