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