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