Version:  2.0.40 2.2.26 2.4.37 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1

Linux/drivers/media/usb/uvc/uvc_driver.c

  1 /*
  2  *      uvc_driver.c  --  USB Video Class driver
  3  *
  4  *      Copyright (C) 2005-2010
  5  *          Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  6  *
  7  *      This program is free software; you can redistribute it and/or modify
  8  *      it under the terms of the GNU General Public License as published by
  9  *      the Free Software Foundation; either version 2 of the License, or
 10  *      (at your option) any later version.
 11  *
 12  */
 13 
 14 #include <linux/atomic.h>
 15 #include <linux/kernel.h>
 16 #include <linux/list.h>
 17 #include <linux/module.h>
 18 #include <linux/slab.h>
 19 #include <linux/usb.h>
 20 #include <linux/videodev2.h>
 21 #include <linux/vmalloc.h>
 22 #include <linux/wait.h>
 23 #include <linux/version.h>
 24 #include <asm/unaligned.h>
 25 
 26 #include <media/v4l2-common.h>
 27 
 28 #include "uvcvideo.h"
 29 
 30 #define DRIVER_AUTHOR           "Laurent Pinchart " \
 31                                 "<laurent.pinchart@ideasonboard.com>"
 32 #define DRIVER_DESC             "USB Video Class driver"
 33 
 34 unsigned int uvc_clock_param = CLOCK_MONOTONIC;
 35 unsigned int uvc_no_drop_param;
 36 static unsigned int uvc_quirks_param = -1;
 37 unsigned int uvc_trace_param;
 38 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
 39 
 40 /* ------------------------------------------------------------------------
 41  * Video formats
 42  */
 43 
 44 static struct uvc_format_desc uvc_fmts[] = {
 45         {
 46                 .name           = "YUV 4:2:2 (YUYV)",
 47                 .guid           = UVC_GUID_FORMAT_YUY2,
 48                 .fcc            = V4L2_PIX_FMT_YUYV,
 49         },
 50         {
 51                 .name           = "YUV 4:2:2 (YUYV)",
 52                 .guid           = UVC_GUID_FORMAT_YUY2_ISIGHT,
 53                 .fcc            = V4L2_PIX_FMT_YUYV,
 54         },
 55         {
 56                 .name           = "YUV 4:2:0 (NV12)",
 57                 .guid           = UVC_GUID_FORMAT_NV12,
 58                 .fcc            = V4L2_PIX_FMT_NV12,
 59         },
 60         {
 61                 .name           = "MJPEG",
 62                 .guid           = UVC_GUID_FORMAT_MJPEG,
 63                 .fcc            = V4L2_PIX_FMT_MJPEG,
 64         },
 65         {
 66                 .name           = "YVU 4:2:0 (YV12)",
 67                 .guid           = UVC_GUID_FORMAT_YV12,
 68                 .fcc            = V4L2_PIX_FMT_YVU420,
 69         },
 70         {
 71                 .name           = "YUV 4:2:0 (I420)",
 72                 .guid           = UVC_GUID_FORMAT_I420,
 73                 .fcc            = V4L2_PIX_FMT_YUV420,
 74         },
 75         {
 76                 .name           = "YUV 4:2:0 (M420)",
 77                 .guid           = UVC_GUID_FORMAT_M420,
 78                 .fcc            = V4L2_PIX_FMT_M420,
 79         },
 80         {
 81                 .name           = "YUV 4:2:2 (UYVY)",
 82                 .guid           = UVC_GUID_FORMAT_UYVY,
 83                 .fcc            = V4L2_PIX_FMT_UYVY,
 84         },
 85         {
 86                 .name           = "Greyscale 8-bit (Y800)",
 87                 .guid           = UVC_GUID_FORMAT_Y800,
 88                 .fcc            = V4L2_PIX_FMT_GREY,
 89         },
 90         {
 91                 .name           = "Greyscale 8-bit (Y8  )",
 92                 .guid           = UVC_GUID_FORMAT_Y8,
 93                 .fcc            = V4L2_PIX_FMT_GREY,
 94         },
 95         {
 96                 .name           = "Greyscale 10-bit (Y10 )",
 97                 .guid           = UVC_GUID_FORMAT_Y10,
 98                 .fcc            = V4L2_PIX_FMT_Y10,
 99         },
100         {
101                 .name           = "Greyscale 12-bit (Y12 )",
102                 .guid           = UVC_GUID_FORMAT_Y12,
103                 .fcc            = V4L2_PIX_FMT_Y12,
104         },
105         {
106                 .name           = "Greyscale 16-bit (Y16 )",
107                 .guid           = UVC_GUID_FORMAT_Y16,
108                 .fcc            = V4L2_PIX_FMT_Y16,
109         },
110         {
111                 .name           = "BGGR Bayer (BY8 )",
112                 .guid           = UVC_GUID_FORMAT_BY8,
113                 .fcc            = V4L2_PIX_FMT_SBGGR8,
114         },
115         {
116                 .name           = "BGGR Bayer (BA81)",
117                 .guid           = UVC_GUID_FORMAT_BA81,
118                 .fcc            = V4L2_PIX_FMT_SBGGR8,
119         },
120         {
121                 .name           = "GBRG Bayer (GBRG)",
122                 .guid           = UVC_GUID_FORMAT_GBRG,
123                 .fcc            = V4L2_PIX_FMT_SGBRG8,
124         },
125         {
126                 .name           = "GRBG Bayer (GRBG)",
127                 .guid           = UVC_GUID_FORMAT_GRBG,
128                 .fcc            = V4L2_PIX_FMT_SGRBG8,
129         },
130         {
131                 .name           = "RGGB Bayer (RGGB)",
132                 .guid           = UVC_GUID_FORMAT_RGGB,
133                 .fcc            = V4L2_PIX_FMT_SRGGB8,
134         },
135         {
136                 .name           = "RGB565",
137                 .guid           = UVC_GUID_FORMAT_RGBP,
138                 .fcc            = V4L2_PIX_FMT_RGB565,
139         },
140         {
141                 .name           = "BGR 8:8:8 (BGR3)",
142                 .guid           = UVC_GUID_FORMAT_BGR3,
143                 .fcc            = V4L2_PIX_FMT_BGR24,
144         },
145         {
146                 .name           = "H.264",
147                 .guid           = UVC_GUID_FORMAT_H264,
148                 .fcc            = V4L2_PIX_FMT_H264,
149         },
150 };
151 
152 /* ------------------------------------------------------------------------
153  * Utility functions
154  */
155 
156 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
157                 __u8 epaddr)
158 {
159         struct usb_host_endpoint *ep;
160         unsigned int i;
161 
162         for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
163                 ep = &alts->endpoint[i];
164                 if (ep->desc.bEndpointAddress == epaddr)
165                         return ep;
166         }
167 
168         return NULL;
169 }
170 
171 static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
172 {
173         unsigned int len = ARRAY_SIZE(uvc_fmts);
174         unsigned int i;
175 
176         for (i = 0; i < len; ++i) {
177                 if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
178                         return &uvc_fmts[i];
179         }
180 
181         return NULL;
182 }
183 
184 static __u32 uvc_colorspace(const __u8 primaries)
185 {
186         static const __u8 colorprimaries[] = {
187                 0,
188                 V4L2_COLORSPACE_SRGB,
189                 V4L2_COLORSPACE_470_SYSTEM_M,
190                 V4L2_COLORSPACE_470_SYSTEM_BG,
191                 V4L2_COLORSPACE_SMPTE170M,
192                 V4L2_COLORSPACE_SMPTE240M,
193         };
194 
195         if (primaries < ARRAY_SIZE(colorprimaries))
196                 return colorprimaries[primaries];
197 
198         return 0;
199 }
200 
201 /* Simplify a fraction using a simple continued fraction decomposition. The
202  * idea here is to convert fractions such as 333333/10000000 to 1/30 using
203  * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
204  * arbitrary parameters to remove non-significative terms from the simple
205  * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
206  * respectively seems to give nice results.
207  */
208 void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
209                 unsigned int n_terms, unsigned int threshold)
210 {
211         uint32_t *an;
212         uint32_t x, y, r;
213         unsigned int i, n;
214 
215         an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
216         if (an == NULL)
217                 return;
218 
219         /* Convert the fraction to a simple continued fraction. See
220          * http://mathforum.org/dr.math/faq/faq.fractions.html
221          * Stop if the current term is bigger than or equal to the given
222          * threshold.
223          */
224         x = *numerator;
225         y = *denominator;
226 
227         for (n = 0; n < n_terms && y != 0; ++n) {
228                 an[n] = x / y;
229                 if (an[n] >= threshold) {
230                         if (n < 2)
231                                 n++;
232                         break;
233                 }
234 
235                 r = x - an[n] * y;
236                 x = y;
237                 y = r;
238         }
239 
240         /* Expand the simple continued fraction back to an integer fraction. */
241         x = 0;
242         y = 1;
243 
244         for (i = n; i > 0; --i) {
245                 r = y;
246                 y = an[i-1] * y + x;
247                 x = r;
248         }
249 
250         *numerator = y;
251         *denominator = x;
252         kfree(an);
253 }
254 
255 /* Convert a fraction to a frame interval in 100ns multiples. The idea here is
256  * to compute numerator / denominator * 10000000 using 32 bit fixed point
257  * arithmetic only.
258  */
259 uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
260 {
261         uint32_t multiplier;
262 
263         /* Saturate the result if the operation would overflow. */
264         if (denominator == 0 ||
265             numerator/denominator >= ((uint32_t)-1)/10000000)
266                 return (uint32_t)-1;
267 
268         /* Divide both the denominator and the multiplier by two until
269          * numerator * multiplier doesn't overflow. If anyone knows a better
270          * algorithm please let me know.
271          */
272         multiplier = 10000000;
273         while (numerator > ((uint32_t)-1)/multiplier) {
274                 multiplier /= 2;
275                 denominator /= 2;
276         }
277 
278         return denominator ? numerator * multiplier / denominator : 0;
279 }
280 
281 /* ------------------------------------------------------------------------
282  * Terminal and unit management
283  */
284 
285 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
286 {
287         struct uvc_entity *entity;
288 
289         list_for_each_entry(entity, &dev->entities, list) {
290                 if (entity->id == id)
291                         return entity;
292         }
293 
294         return NULL;
295 }
296 
297 static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
298         int id, struct uvc_entity *entity)
299 {
300         unsigned int i;
301 
302         if (entity == NULL)
303                 entity = list_entry(&dev->entities, struct uvc_entity, list);
304 
305         list_for_each_entry_continue(entity, &dev->entities, list) {
306                 for (i = 0; i < entity->bNrInPins; ++i)
307                         if (entity->baSourceID[i] == id)
308                                 return entity;
309         }
310 
311         return NULL;
312 }
313 
314 static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
315 {
316         struct uvc_streaming *stream;
317 
318         list_for_each_entry(stream, &dev->streams, list) {
319                 if (stream->header.bTerminalLink == id)
320                         return stream;
321         }
322 
323         return NULL;
324 }
325 
326 /* ------------------------------------------------------------------------
327  * Descriptors parsing
328  */
329 
330 static int uvc_parse_format(struct uvc_device *dev,
331         struct uvc_streaming *streaming, struct uvc_format *format,
332         __u32 **intervals, unsigned char *buffer, int buflen)
333 {
334         struct usb_interface *intf = streaming->intf;
335         struct usb_host_interface *alts = intf->cur_altsetting;
336         struct uvc_format_desc *fmtdesc;
337         struct uvc_frame *frame;
338         const unsigned char *start = buffer;
339         unsigned int width_multiplier = 1;
340         unsigned int interval;
341         unsigned int i, n;
342         __u8 ftype;
343 
344         format->type = buffer[2];
345         format->index = buffer[3];
346 
347         switch (buffer[2]) {
348         case UVC_VS_FORMAT_UNCOMPRESSED:
349         case UVC_VS_FORMAT_FRAME_BASED:
350                 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
351                 if (buflen < n) {
352                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
353                                "interface %d FORMAT error\n",
354                                dev->udev->devnum,
355                                alts->desc.bInterfaceNumber);
356                         return -EINVAL;
357                 }
358 
359                 /* Find the format descriptor from its GUID. */
360                 fmtdesc = uvc_format_by_guid(&buffer[5]);
361 
362                 if (fmtdesc != NULL) {
363                         strlcpy(format->name, fmtdesc->name,
364                                 sizeof format->name);
365                         format->fcc = fmtdesc->fcc;
366                 } else {
367                         uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
368                                 &buffer[5]);
369                         snprintf(format->name, sizeof(format->name), "%pUl\n",
370                                 &buffer[5]);
371                         format->fcc = 0;
372                 }
373 
374                 format->bpp = buffer[21];
375 
376                 /* Some devices report a format that doesn't match what they
377                  * really send.
378                  */
379                 if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
380                         if (format->fcc == V4L2_PIX_FMT_YUYV) {
381                                 strlcpy(format->name, "Greyscale 8-bit (Y8  )",
382                                         sizeof(format->name));
383                                 format->fcc = V4L2_PIX_FMT_GREY;
384                                 format->bpp = 8;
385                                 width_multiplier = 2;
386                         }
387                 }
388 
389                 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
390                         ftype = UVC_VS_FRAME_UNCOMPRESSED;
391                 } else {
392                         ftype = UVC_VS_FRAME_FRAME_BASED;
393                         if (buffer[27])
394                                 format->flags = UVC_FMT_FLAG_COMPRESSED;
395                 }
396                 break;
397 
398         case UVC_VS_FORMAT_MJPEG:
399                 if (buflen < 11) {
400                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
401                                "interface %d FORMAT error\n",
402                                dev->udev->devnum,
403                                alts->desc.bInterfaceNumber);
404                         return -EINVAL;
405                 }
406 
407                 strlcpy(format->name, "MJPEG", sizeof format->name);
408                 format->fcc = V4L2_PIX_FMT_MJPEG;
409                 format->flags = UVC_FMT_FLAG_COMPRESSED;
410                 format->bpp = 0;
411                 ftype = UVC_VS_FRAME_MJPEG;
412                 break;
413 
414         case UVC_VS_FORMAT_DV:
415                 if (buflen < 9) {
416                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
417                                "interface %d FORMAT error\n",
418                                dev->udev->devnum,
419                                alts->desc.bInterfaceNumber);
420                         return -EINVAL;
421                 }
422 
423                 switch (buffer[8] & 0x7f) {
424                 case 0:
425                         strlcpy(format->name, "SD-DV", sizeof format->name);
426                         break;
427                 case 1:
428                         strlcpy(format->name, "SDL-DV", sizeof format->name);
429                         break;
430                 case 2:
431                         strlcpy(format->name, "HD-DV", sizeof format->name);
432                         break;
433                 default:
434                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
435                                "interface %d: unknown DV format %u\n",
436                                dev->udev->devnum,
437                                alts->desc.bInterfaceNumber, buffer[8]);
438                         return -EINVAL;
439                 }
440 
441                 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
442                         sizeof format->name);
443 
444                 format->fcc = V4L2_PIX_FMT_DV;
445                 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
446                 format->bpp = 0;
447                 ftype = 0;
448 
449                 /* Create a dummy frame descriptor. */
450                 frame = &format->frame[0];
451                 memset(&format->frame[0], 0, sizeof format->frame[0]);
452                 frame->bFrameIntervalType = 1;
453                 frame->dwDefaultFrameInterval = 1;
454                 frame->dwFrameInterval = *intervals;
455                 *(*intervals)++ = 1;
456                 format->nframes = 1;
457                 break;
458 
459         case UVC_VS_FORMAT_MPEG2TS:
460         case UVC_VS_FORMAT_STREAM_BASED:
461                 /* Not supported yet. */
462         default:
463                 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
464                        "interface %d unsupported format %u\n",
465                        dev->udev->devnum, alts->desc.bInterfaceNumber,
466                        buffer[2]);
467                 return -EINVAL;
468         }
469 
470         uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
471 
472         buflen -= buffer[0];
473         buffer += buffer[0];
474 
475         /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
476          * based formats have frame descriptors.
477          */
478         while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
479                buffer[2] == ftype) {
480                 frame = &format->frame[format->nframes];
481                 if (ftype != UVC_VS_FRAME_FRAME_BASED)
482                         n = buflen > 25 ? buffer[25] : 0;
483                 else
484                         n = buflen > 21 ? buffer[21] : 0;
485 
486                 n = n ? n : 3;
487 
488                 if (buflen < 26 + 4*n) {
489                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
490                                "interface %d FRAME error\n", dev->udev->devnum,
491                                alts->desc.bInterfaceNumber);
492                         return -EINVAL;
493                 }
494 
495                 frame->bFrameIndex = buffer[3];
496                 frame->bmCapabilities = buffer[4];
497                 frame->wWidth = get_unaligned_le16(&buffer[5])
498                               * width_multiplier;
499                 frame->wHeight = get_unaligned_le16(&buffer[7]);
500                 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
501                 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
502                 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
503                         frame->dwMaxVideoFrameBufferSize =
504                                 get_unaligned_le32(&buffer[17]);
505                         frame->dwDefaultFrameInterval =
506                                 get_unaligned_le32(&buffer[21]);
507                         frame->bFrameIntervalType = buffer[25];
508                 } else {
509                         frame->dwMaxVideoFrameBufferSize = 0;
510                         frame->dwDefaultFrameInterval =
511                                 get_unaligned_le32(&buffer[17]);
512                         frame->bFrameIntervalType = buffer[21];
513                 }
514                 frame->dwFrameInterval = *intervals;
515 
516                 /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
517                  * completely. Observed behaviours range from setting the
518                  * value to 1.1x the actual frame size to hardwiring the
519                  * 16 low bits to 0. This results in a higher than necessary
520                  * memory usage as well as a wrong image size information. For
521                  * uncompressed formats this can be fixed by computing the
522                  * value from the frame size.
523                  */
524                 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
525                         frame->dwMaxVideoFrameBufferSize = format->bpp
526                                 * frame->wWidth * frame->wHeight / 8;
527 
528                 /* Some bogus devices report dwMinFrameInterval equal to
529                  * dwMaxFrameInterval and have dwFrameIntervalStep set to
530                  * zero. Setting all null intervals to 1 fixes the problem and
531                  * some other divisions by zero that could happen.
532                  */
533                 for (i = 0; i < n; ++i) {
534                         interval = get_unaligned_le32(&buffer[26+4*i]);
535                         *(*intervals)++ = interval ? interval : 1;
536                 }
537 
538                 /* Make sure that the default frame interval stays between
539                  * the boundaries.
540                  */
541                 n -= frame->bFrameIntervalType ? 1 : 2;
542                 frame->dwDefaultFrameInterval =
543                         min(frame->dwFrameInterval[n],
544                             max(frame->dwFrameInterval[0],
545                                 frame->dwDefaultFrameInterval));
546 
547                 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
548                         frame->bFrameIntervalType = 1;
549                         frame->dwFrameInterval[0] =
550                                 frame->dwDefaultFrameInterval;
551                 }
552 
553                 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
554                         frame->wWidth, frame->wHeight,
555                         10000000/frame->dwDefaultFrameInterval,
556                         (100000000/frame->dwDefaultFrameInterval)%10);
557 
558                 format->nframes++;
559                 buflen -= buffer[0];
560                 buffer += buffer[0];
561         }
562 
563         if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
564             buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
565                 buflen -= buffer[0];
566                 buffer += buffer[0];
567         }
568 
569         if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE &&
570             buffer[2] == UVC_VS_COLORFORMAT) {
571                 if (buflen < 6) {
572                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
573                                "interface %d COLORFORMAT error\n",
574                                dev->udev->devnum,
575                                alts->desc.bInterfaceNumber);
576                         return -EINVAL;
577                 }
578 
579                 format->colorspace = uvc_colorspace(buffer[3]);
580 
581                 buflen -= buffer[0];
582                 buffer += buffer[0];
583         }
584 
585         return buffer - start;
586 }
587 
588 static int uvc_parse_streaming(struct uvc_device *dev,
589         struct usb_interface *intf)
590 {
591         struct uvc_streaming *streaming = NULL;
592         struct uvc_format *format;
593         struct uvc_frame *frame;
594         struct usb_host_interface *alts = &intf->altsetting[0];
595         unsigned char *_buffer, *buffer = alts->extra;
596         int _buflen, buflen = alts->extralen;
597         unsigned int nformats = 0, nframes = 0, nintervals = 0;
598         unsigned int size, i, n, p;
599         __u32 *interval;
600         __u16 psize;
601         int ret = -EINVAL;
602 
603         if (intf->cur_altsetting->desc.bInterfaceSubClass
604                 != UVC_SC_VIDEOSTREAMING) {
605                 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
606                         "video streaming interface\n", dev->udev->devnum,
607                         intf->altsetting[0].desc.bInterfaceNumber);
608                 return -EINVAL;
609         }
610 
611         if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
612                 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
613                         "claimed\n", dev->udev->devnum,
614                         intf->altsetting[0].desc.bInterfaceNumber);
615                 return -EINVAL;
616         }
617 
618         streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
619         if (streaming == NULL) {
620                 usb_driver_release_interface(&uvc_driver.driver, intf);
621                 return -EINVAL;
622         }
623 
624         mutex_init(&streaming->mutex);
625         streaming->dev = dev;
626         streaming->intf = usb_get_intf(intf);
627         streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
628 
629         /* The Pico iMage webcam has its class-specific interface descriptors
630          * after the endpoint descriptors.
631          */
632         if (buflen == 0) {
633                 for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
634                         struct usb_host_endpoint *ep = &alts->endpoint[i];
635 
636                         if (ep->extralen == 0)
637                                 continue;
638 
639                         if (ep->extralen > 2 &&
640                             ep->extra[1] == USB_DT_CS_INTERFACE) {
641                                 uvc_trace(UVC_TRACE_DESCR, "trying extra data "
642                                         "from endpoint %u.\n", i);
643                                 buffer = alts->endpoint[i].extra;
644                                 buflen = alts->endpoint[i].extralen;
645                                 break;
646                         }
647                 }
648         }
649 
650         /* Skip the standard interface descriptors. */
651         while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
652                 buflen -= buffer[0];
653                 buffer += buffer[0];
654         }
655 
656         if (buflen <= 2) {
657                 uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
658                         "interface descriptors found.\n");
659                 goto error;
660         }
661 
662         /* Parse the header descriptor. */
663         switch (buffer[2]) {
664         case UVC_VS_OUTPUT_HEADER:
665                 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
666                 size = 9;
667                 break;
668 
669         case UVC_VS_INPUT_HEADER:
670                 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
671                 size = 13;
672                 break;
673 
674         default:
675                 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
676                         "%d HEADER descriptor not found.\n", dev->udev->devnum,
677                         alts->desc.bInterfaceNumber);
678                 goto error;
679         }
680 
681         p = buflen >= 4 ? buffer[3] : 0;
682         n = buflen >= size ? buffer[size-1] : 0;
683 
684         if (buflen < size + p*n) {
685                 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
686                         "interface %d HEADER descriptor is invalid.\n",
687                         dev->udev->devnum, alts->desc.bInterfaceNumber);
688                 goto error;
689         }
690 
691         streaming->header.bNumFormats = p;
692         streaming->header.bEndpointAddress = buffer[6];
693         if (buffer[2] == UVC_VS_INPUT_HEADER) {
694                 streaming->header.bmInfo = buffer[7];
695                 streaming->header.bTerminalLink = buffer[8];
696                 streaming->header.bStillCaptureMethod = buffer[9];
697                 streaming->header.bTriggerSupport = buffer[10];
698                 streaming->header.bTriggerUsage = buffer[11];
699         } else {
700                 streaming->header.bTerminalLink = buffer[7];
701         }
702         streaming->header.bControlSize = n;
703 
704         streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
705                                                 GFP_KERNEL);
706         if (streaming->header.bmaControls == NULL) {
707                 ret = -ENOMEM;
708                 goto error;
709         }
710 
711         buflen -= buffer[0];
712         buffer += buffer[0];
713 
714         _buffer = buffer;
715         _buflen = buflen;
716 
717         /* Count the format and frame descriptors. */
718         while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
719                 switch (_buffer[2]) {
720                 case UVC_VS_FORMAT_UNCOMPRESSED:
721                 case UVC_VS_FORMAT_MJPEG:
722                 case UVC_VS_FORMAT_FRAME_BASED:
723                         nformats++;
724                         break;
725 
726                 case UVC_VS_FORMAT_DV:
727                         /* DV format has no frame descriptor. We will create a
728                          * dummy frame descriptor with a dummy frame interval.
729                          */
730                         nformats++;
731                         nframes++;
732                         nintervals++;
733                         break;
734 
735                 case UVC_VS_FORMAT_MPEG2TS:
736                 case UVC_VS_FORMAT_STREAM_BASED:
737                         uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
738                                 "interface %d FORMAT %u is not supported.\n",
739                                 dev->udev->devnum,
740                                 alts->desc.bInterfaceNumber, _buffer[2]);
741                         break;
742 
743                 case UVC_VS_FRAME_UNCOMPRESSED:
744                 case UVC_VS_FRAME_MJPEG:
745                         nframes++;
746                         if (_buflen > 25)
747                                 nintervals += _buffer[25] ? _buffer[25] : 3;
748                         break;
749 
750                 case UVC_VS_FRAME_FRAME_BASED:
751                         nframes++;
752                         if (_buflen > 21)
753                                 nintervals += _buffer[21] ? _buffer[21] : 3;
754                         break;
755                 }
756 
757                 _buflen -= _buffer[0];
758                 _buffer += _buffer[0];
759         }
760 
761         if (nformats == 0) {
762                 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
763                         "%d has no supported formats defined.\n",
764                         dev->udev->devnum, alts->desc.bInterfaceNumber);
765                 goto error;
766         }
767 
768         size = nformats * sizeof *format + nframes * sizeof *frame
769              + nintervals * sizeof *interval;
770         format = kzalloc(size, GFP_KERNEL);
771         if (format == NULL) {
772                 ret = -ENOMEM;
773                 goto error;
774         }
775 
776         frame = (struct uvc_frame *)&format[nformats];
777         interval = (__u32 *)&frame[nframes];
778 
779         streaming->format = format;
780         streaming->nformats = nformats;
781 
782         /* Parse the format descriptors. */
783         while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
784                 switch (buffer[2]) {
785                 case UVC_VS_FORMAT_UNCOMPRESSED:
786                 case UVC_VS_FORMAT_MJPEG:
787                 case UVC_VS_FORMAT_DV:
788                 case UVC_VS_FORMAT_FRAME_BASED:
789                         format->frame = frame;
790                         ret = uvc_parse_format(dev, streaming, format,
791                                 &interval, buffer, buflen);
792                         if (ret < 0)
793                                 goto error;
794 
795                         frame += format->nframes;
796                         format++;
797 
798                         buflen -= ret;
799                         buffer += ret;
800                         continue;
801 
802                 default:
803                         break;
804                 }
805 
806                 buflen -= buffer[0];
807                 buffer += buffer[0];
808         }
809 
810         if (buflen)
811                 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
812                         "%d has %u bytes of trailing descriptor garbage.\n",
813                         dev->udev->devnum, alts->desc.bInterfaceNumber, buflen);
814 
815         /* Parse the alternate settings to find the maximum bandwidth. */
816         for (i = 0; i < intf->num_altsetting; ++i) {
817                 struct usb_host_endpoint *ep;
818                 alts = &intf->altsetting[i];
819                 ep = uvc_find_endpoint(alts,
820                                 streaming->header.bEndpointAddress);
821                 if (ep == NULL)
822                         continue;
823 
824                 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
825                 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
826                 if (psize > streaming->maxpsize)
827                         streaming->maxpsize = psize;
828         }
829 
830         list_add_tail(&streaming->list, &dev->streams);
831         return 0;
832 
833 error:
834         usb_driver_release_interface(&uvc_driver.driver, intf);
835         usb_put_intf(intf);
836         kfree(streaming->format);
837         kfree(streaming->header.bmaControls);
838         kfree(streaming);
839         return ret;
840 }
841 
842 static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
843                 unsigned int num_pads, unsigned int extra_size)
844 {
845         struct uvc_entity *entity;
846         unsigned int num_inputs;
847         unsigned int size;
848         unsigned int i;
849 
850         extra_size = ALIGN(extra_size, sizeof(*entity->pads));
851         num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
852         size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
853              + num_inputs;
854         entity = kzalloc(size, GFP_KERNEL);
855         if (entity == NULL)
856                 return NULL;
857 
858         entity->id = id;
859         entity->type = type;
860 
861         entity->num_links = 0;
862         entity->num_pads = num_pads;
863         entity->pads = ((void *)(entity + 1)) + extra_size;
864 
865         for (i = 0; i < num_inputs; ++i)
866                 entity->pads[i].flags = MEDIA_PAD_FL_SINK;
867         if (!UVC_ENTITY_IS_OTERM(entity))
868                 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
869 
870         entity->bNrInPins = num_inputs;
871         entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
872 
873         return entity;
874 }
875 
876 /* Parse vendor-specific extensions. */
877 static int uvc_parse_vendor_control(struct uvc_device *dev,
878         const unsigned char *buffer, int buflen)
879 {
880         struct usb_device *udev = dev->udev;
881         struct usb_host_interface *alts = dev->intf->cur_altsetting;
882         struct uvc_entity *unit;
883         unsigned int n, p;
884         int handled = 0;
885 
886         switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
887         case 0x046d:            /* Logitech */
888                 if (buffer[1] != 0x41 || buffer[2] != 0x01)
889                         break;
890 
891                 /* Logitech implements several vendor specific functions
892                  * through vendor specific extension units (LXU).
893                  *
894                  * The LXU descriptors are similar to XU descriptors
895                  * (see "USB Device Video Class for Video Devices", section
896                  * 3.7.2.6 "Extension Unit Descriptor") with the following
897                  * differences:
898                  *
899                  * ----------------------------------------------------------
900                  * 0            bLength         1        Number
901                  *      Size of this descriptor, in bytes: 24+p+n*2
902                  * ----------------------------------------------------------
903                  * 23+p+n       bmControlsType  N       Bitmap
904                  *      Individual bits in the set are defined:
905                  *      0: Absolute
906                  *      1: Relative
907                  *
908                  *      This bitset is mapped exactly the same as bmControls.
909                  * ----------------------------------------------------------
910                  * 23+p+n*2     bReserved       1       Boolean
911                  * ----------------------------------------------------------
912                  * 24+p+n*2     iExtension      1       Index
913                  *      Index of a string descriptor that describes this
914                  *      extension unit.
915                  * ----------------------------------------------------------
916                  */
917                 p = buflen >= 22 ? buffer[21] : 0;
918                 n = buflen >= 25 + p ? buffer[22+p] : 0;
919 
920                 if (buflen < 25 + p + 2*n) {
921                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
922                                 "interface %d EXTENSION_UNIT error\n",
923                                 udev->devnum, alts->desc.bInterfaceNumber);
924                         break;
925                 }
926 
927                 unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
928                                         p + 1, 2*n);
929                 if (unit == NULL)
930                         return -ENOMEM;
931 
932                 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
933                 unit->extension.bNumControls = buffer[20];
934                 memcpy(unit->baSourceID, &buffer[22], p);
935                 unit->extension.bControlSize = buffer[22+p];
936                 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit);
937                 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit)
938                                                + n;
939                 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
940 
941                 if (buffer[24+p+2*n] != 0)
942                         usb_string(udev, buffer[24+p+2*n], unit->name,
943                                    sizeof unit->name);
944                 else
945                         sprintf(unit->name, "Extension %u", buffer[3]);
946 
947                 list_add_tail(&unit->list, &dev->entities);
948                 handled = 1;
949                 break;
950         }
951 
952         return handled;
953 }
954 
955 static int uvc_parse_standard_control(struct uvc_device *dev,
956         const unsigned char *buffer, int buflen)
957 {
958         struct usb_device *udev = dev->udev;
959         struct uvc_entity *unit, *term;
960         struct usb_interface *intf;
961         struct usb_host_interface *alts = dev->intf->cur_altsetting;
962         unsigned int i, n, p, len;
963         __u16 type;
964 
965         switch (buffer[2]) {
966         case UVC_VC_HEADER:
967                 n = buflen >= 12 ? buffer[11] : 0;
968 
969                 if (buflen < 12 + n) {
970                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
971                                 "interface %d HEADER error\n", udev->devnum,
972                                 alts->desc.bInterfaceNumber);
973                         return -EINVAL;
974                 }
975 
976                 dev->uvc_version = get_unaligned_le16(&buffer[3]);
977                 dev->clock_frequency = get_unaligned_le32(&buffer[7]);
978 
979                 /* Parse all USB Video Streaming interfaces. */
980                 for (i = 0; i < n; ++i) {
981                         intf = usb_ifnum_to_if(udev, buffer[12+i]);
982                         if (intf == NULL) {
983                                 uvc_trace(UVC_TRACE_DESCR, "device %d "
984                                         "interface %d doesn't exists\n",
985                                         udev->devnum, i);
986                                 continue;
987                         }
988 
989                         uvc_parse_streaming(dev, intf);
990                 }
991                 break;
992 
993         case UVC_VC_INPUT_TERMINAL:
994                 if (buflen < 8) {
995                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
996                                 "interface %d INPUT_TERMINAL error\n",
997                                 udev->devnum, alts->desc.bInterfaceNumber);
998                         return -EINVAL;
999                 }
1000 
1001                 /* Make sure the terminal type MSB is not null, otherwise it
1002                  * could be confused with a unit.
1003                  */
1004                 type = get_unaligned_le16(&buffer[4]);
1005                 if ((type & 0xff00) == 0) {
1006                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1007                                 "interface %d INPUT_TERMINAL %d has invalid "
1008                                 "type 0x%04x, skipping\n", udev->devnum,
1009                                 alts->desc.bInterfaceNumber,
1010                                 buffer[3], type);
1011                         return 0;
1012                 }
1013 
1014                 n = 0;
1015                 p = 0;
1016                 len = 8;
1017 
1018                 if (type == UVC_ITT_CAMERA) {
1019                         n = buflen >= 15 ? buffer[14] : 0;
1020                         len = 15;
1021 
1022                 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1023                         n = buflen >= 9 ? buffer[8] : 0;
1024                         p = buflen >= 10 + n ? buffer[9+n] : 0;
1025                         len = 10;
1026                 }
1027 
1028                 if (buflen < len + n + p) {
1029                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1030                                 "interface %d INPUT_TERMINAL error\n",
1031                                 udev->devnum, alts->desc.bInterfaceNumber);
1032                         return -EINVAL;
1033                 }
1034 
1035                 term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1036                                         1, n + p);
1037                 if (term == NULL)
1038                         return -ENOMEM;
1039 
1040                 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1041                         term->camera.bControlSize = n;
1042                         term->camera.bmControls = (__u8 *)term + sizeof *term;
1043                         term->camera.wObjectiveFocalLengthMin =
1044                                 get_unaligned_le16(&buffer[8]);
1045                         term->camera.wObjectiveFocalLengthMax =
1046                                 get_unaligned_le16(&buffer[10]);
1047                         term->camera.wOcularFocalLength =
1048                                 get_unaligned_le16(&buffer[12]);
1049                         memcpy(term->camera.bmControls, &buffer[15], n);
1050                 } else if (UVC_ENTITY_TYPE(term) ==
1051                            UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1052                         term->media.bControlSize = n;
1053                         term->media.bmControls = (__u8 *)term + sizeof *term;
1054                         term->media.bTransportModeSize = p;
1055                         term->media.bmTransportModes = (__u8 *)term
1056                                                      + sizeof *term + n;
1057                         memcpy(term->media.bmControls, &buffer[9], n);
1058                         memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1059                 }
1060 
1061                 if (buffer[7] != 0)
1062                         usb_string(udev, buffer[7], term->name,
1063                                    sizeof term->name);
1064                 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1065                         sprintf(term->name, "Camera %u", buffer[3]);
1066                 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
1067                         sprintf(term->name, "Media %u", buffer[3]);
1068                 else
1069                         sprintf(term->name, "Input %u", buffer[3]);
1070 
1071                 list_add_tail(&term->list, &dev->entities);
1072                 break;
1073 
1074         case UVC_VC_OUTPUT_TERMINAL:
1075                 if (buflen < 9) {
1076                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1077                                 "interface %d OUTPUT_TERMINAL error\n",
1078                                 udev->devnum, alts->desc.bInterfaceNumber);
1079                         return -EINVAL;
1080                 }
1081 
1082                 /* Make sure the terminal type MSB is not null, otherwise it
1083                  * could be confused with a unit.
1084                  */
1085                 type = get_unaligned_le16(&buffer[4]);
1086                 if ((type & 0xff00) == 0) {
1087                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1088                                 "interface %d OUTPUT_TERMINAL %d has invalid "
1089                                 "type 0x%04x, skipping\n", udev->devnum,
1090                                 alts->desc.bInterfaceNumber, buffer[3], type);
1091                         return 0;
1092                 }
1093 
1094                 term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1095                                         1, 0);
1096                 if (term == NULL)
1097                         return -ENOMEM;
1098 
1099                 memcpy(term->baSourceID, &buffer[7], 1);
1100 
1101                 if (buffer[8] != 0)
1102                         usb_string(udev, buffer[8], term->name,
1103                                    sizeof term->name);
1104                 else
1105                         sprintf(term->name, "Output %u", buffer[3]);
1106 
1107                 list_add_tail(&term->list, &dev->entities);
1108                 break;
1109 
1110         case UVC_VC_SELECTOR_UNIT:
1111                 p = buflen >= 5 ? buffer[4] : 0;
1112 
1113                 if (buflen < 5 || buflen < 6 + p) {
1114                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1115                                 "interface %d SELECTOR_UNIT error\n",
1116                                 udev->devnum, alts->desc.bInterfaceNumber);
1117                         return -EINVAL;
1118                 }
1119 
1120                 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1121                 if (unit == NULL)
1122                         return -ENOMEM;
1123 
1124                 memcpy(unit->baSourceID, &buffer[5], p);
1125 
1126                 if (buffer[5+p] != 0)
1127                         usb_string(udev, buffer[5+p], unit->name,
1128                                    sizeof unit->name);
1129                 else
1130                         sprintf(unit->name, "Selector %u", buffer[3]);
1131 
1132                 list_add_tail(&unit->list, &dev->entities);
1133                 break;
1134 
1135         case UVC_VC_PROCESSING_UNIT:
1136                 n = buflen >= 8 ? buffer[7] : 0;
1137                 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1138 
1139                 if (buflen < p + n) {
1140                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1141                                 "interface %d PROCESSING_UNIT error\n",
1142                                 udev->devnum, alts->desc.bInterfaceNumber);
1143                         return -EINVAL;
1144                 }
1145 
1146                 unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1147                 if (unit == NULL)
1148                         return -ENOMEM;
1149 
1150                 memcpy(unit->baSourceID, &buffer[4], 1);
1151                 unit->processing.wMaxMultiplier =
1152                         get_unaligned_le16(&buffer[5]);
1153                 unit->processing.bControlSize = buffer[7];
1154                 unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
1155                 memcpy(unit->processing.bmControls, &buffer[8], n);
1156                 if (dev->uvc_version >= 0x0110)
1157                         unit->processing.bmVideoStandards = buffer[9+n];
1158 
1159                 if (buffer[8+n] != 0)
1160                         usb_string(udev, buffer[8+n], unit->name,
1161                                    sizeof unit->name);
1162                 else
1163                         sprintf(unit->name, "Processing %u", buffer[3]);
1164 
1165                 list_add_tail(&unit->list, &dev->entities);
1166                 break;
1167 
1168         case UVC_VC_EXTENSION_UNIT:
1169                 p = buflen >= 22 ? buffer[21] : 0;
1170                 n = buflen >= 24 + p ? buffer[22+p] : 0;
1171 
1172                 if (buflen < 24 + p + n) {
1173                         uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1174                                 "interface %d EXTENSION_UNIT error\n",
1175                                 udev->devnum, alts->desc.bInterfaceNumber);
1176                         return -EINVAL;
1177                 }
1178 
1179                 unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1180                 if (unit == NULL)
1181                         return -ENOMEM;
1182 
1183                 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
1184                 unit->extension.bNumControls = buffer[20];
1185                 memcpy(unit->baSourceID, &buffer[22], p);
1186                 unit->extension.bControlSize = buffer[22+p];
1187                 unit->extension.bmControls = (__u8 *)unit + sizeof *unit;
1188                 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1189 
1190                 if (buffer[23+p+n] != 0)
1191                         usb_string(udev, buffer[23+p+n], unit->name,
1192                                    sizeof unit->name);
1193                 else
1194                         sprintf(unit->name, "Extension %u", buffer[3]);
1195 
1196                 list_add_tail(&unit->list, &dev->entities);
1197                 break;
1198 
1199         default:
1200                 uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
1201                         "descriptor (%u)\n", buffer[2]);
1202                 break;
1203         }
1204 
1205         return 0;
1206 }
1207 
1208 static int uvc_parse_control(struct uvc_device *dev)
1209 {
1210         struct usb_host_interface *alts = dev->intf->cur_altsetting;
1211         unsigned char *buffer = alts->extra;
1212         int buflen = alts->extralen;
1213         int ret;
1214 
1215         /* Parse the default alternate setting only, as the UVC specification
1216          * defines a single alternate setting, the default alternate setting
1217          * zero.
1218          */
1219 
1220         while (buflen > 2) {
1221                 if (uvc_parse_vendor_control(dev, buffer, buflen) ||
1222                     buffer[1] != USB_DT_CS_INTERFACE)
1223                         goto next_descriptor;
1224 
1225                 if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
1226                         return ret;
1227 
1228 next_descriptor:
1229                 buflen -= buffer[0];
1230                 buffer += buffer[0];
1231         }
1232 
1233         /* Check if the optional status endpoint is present. Built-in iSight
1234          * webcams have an interrupt endpoint but spit proprietary data that
1235          * don't conform to the UVC status endpoint messages. Don't try to
1236          * handle the interrupt endpoint for those cameras.
1237          */
1238         if (alts->desc.bNumEndpoints == 1 &&
1239             !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) {
1240                 struct usb_host_endpoint *ep = &alts->endpoint[0];
1241                 struct usb_endpoint_descriptor *desc = &ep->desc;
1242 
1243                 if (usb_endpoint_is_int_in(desc) &&
1244                     le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
1245                     desc->bInterval != 0) {
1246                         uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
1247                                 "(addr %02x).\n", desc->bEndpointAddress);
1248                         dev->int_ep = ep;
1249                 }
1250         }
1251 
1252         return 0;
1253 }
1254 
1255 /* ------------------------------------------------------------------------
1256  * UVC device scan
1257  */
1258 
1259 /*
1260  * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1261  * and containing the following units:
1262  *
1263  * - one or more Output Terminals (USB Streaming or Display)
1264  * - zero or one Processing Unit
1265  * - zero, one or more single-input Selector Units
1266  * - zero or one multiple-input Selector Units, provided all inputs are
1267  *   connected to input terminals
1268  * - zero, one or mode single-input Extension Units
1269  * - one or more Input Terminals (Camera, External or USB Streaming)
1270  *
1271  * The terminal and units must match on of the following structures:
1272  *
1273  * ITT_*(0) -> +---------+    +---------+    +---------+ -> TT_STREAMING(0)
1274  * ...         | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} |    ...
1275  * ITT_*(n) -> +---------+    +---------+    +---------+ -> TT_STREAMING(n)
1276  *
1277  *                 +---------+    +---------+ -> OTT_*(0)
1278  * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} |    ...
1279  *                 +---------+    +---------+ -> OTT_*(n)
1280  *
1281  * The Processing Unit and Extension Units can be in any order. Additional
1282  * Extension Units connected to the main chain as single-unit branches are
1283  * also supported. Single-input Selector Units are ignored.
1284  */
1285 static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1286         struct uvc_entity *entity)
1287 {
1288         switch (UVC_ENTITY_TYPE(entity)) {
1289         case UVC_VC_EXTENSION_UNIT:
1290                 if (uvc_trace_param & UVC_TRACE_PROBE)
1291                         printk(" <- XU %d", entity->id);
1292 
1293                 if (entity->bNrInPins != 1) {
1294                         uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
1295                                 "than 1 input pin.\n", entity->id);
1296                         return -1;
1297                 }
1298 
1299                 break;
1300 
1301         case UVC_VC_PROCESSING_UNIT:
1302                 if (uvc_trace_param & UVC_TRACE_PROBE)
1303                         printk(" <- PU %d", entity->id);
1304 
1305                 if (chain->processing != NULL) {
1306                         uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1307                                 "Processing Units in chain.\n");
1308                         return -1;
1309                 }
1310 
1311                 chain->processing = entity;
1312                 break;
1313 
1314         case UVC_VC_SELECTOR_UNIT:
1315                 if (uvc_trace_param & UVC_TRACE_PROBE)
1316                         printk(" <- SU %d", entity->id);
1317 
1318                 /* Single-input selector units are ignored. */
1319                 if (entity->bNrInPins == 1)
1320                         break;
1321 
1322                 if (chain->selector != NULL) {
1323                         uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1324                                 "Units in chain.\n");
1325                         return -1;
1326                 }
1327 
1328                 chain->selector = entity;
1329                 break;
1330 
1331         case UVC_ITT_VENDOR_SPECIFIC:
1332         case UVC_ITT_CAMERA:
1333         case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1334                 if (uvc_trace_param & UVC_TRACE_PROBE)
1335                         printk(" <- IT %d\n", entity->id);
1336 
1337                 break;
1338 
1339         case UVC_OTT_VENDOR_SPECIFIC:
1340         case UVC_OTT_DISPLAY:
1341         case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1342                 if (uvc_trace_param & UVC_TRACE_PROBE)
1343                         printk(" OT %d", entity->id);
1344 
1345                 break;
1346 
1347         case UVC_TT_STREAMING:
1348                 if (UVC_ENTITY_IS_ITERM(entity)) {
1349                         if (uvc_trace_param & UVC_TRACE_PROBE)
1350                                 printk(" <- IT %d\n", entity->id);
1351                 } else {
1352                         if (uvc_trace_param & UVC_TRACE_PROBE)
1353                                 printk(" OT %d", entity->id);
1354                 }
1355 
1356                 break;
1357 
1358         default:
1359                 uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
1360                         "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
1361                 return -1;
1362         }
1363 
1364         list_add_tail(&entity->chain, &chain->entities);
1365         return 0;
1366 }
1367 
1368 static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1369         struct uvc_entity *entity, struct uvc_entity *prev)
1370 {
1371         struct uvc_entity *forward;
1372         int found;
1373 
1374         /* Forward scan */
1375         forward = NULL;
1376         found = 0;
1377 
1378         while (1) {
1379                 forward = uvc_entity_by_reference(chain->dev, entity->id,
1380                         forward);
1381                 if (forward == NULL)
1382                         break;
1383                 if (forward == prev)
1384                         continue;
1385 
1386                 switch (UVC_ENTITY_TYPE(forward)) {
1387                 case UVC_VC_EXTENSION_UNIT:
1388                         if (forward->bNrInPins != 1) {
1389                                 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1390                                           "has more than 1 input pin.\n",
1391                                           entity->id);
1392                                 return -EINVAL;
1393                         }
1394 
1395                         list_add_tail(&forward->chain, &chain->entities);
1396                         if (uvc_trace_param & UVC_TRACE_PROBE) {
1397                                 if (!found)
1398                                         printk(" (->");
1399 
1400                                 printk(" XU %d", forward->id);
1401                                 found = 1;
1402                         }
1403                         break;
1404 
1405                 case UVC_OTT_VENDOR_SPECIFIC:
1406                 case UVC_OTT_DISPLAY:
1407                 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1408                 case UVC_TT_STREAMING:
1409                         if (UVC_ENTITY_IS_ITERM(forward)) {
1410                                 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1411                                         "terminal %u.\n", forward->id);
1412                                 return -EINVAL;
1413                         }
1414 
1415                         list_add_tail(&forward->chain, &chain->entities);
1416                         if (uvc_trace_param & UVC_TRACE_PROBE) {
1417                                 if (!found)
1418                                         printk(" (->");
1419 
1420                                 printk(" OT %d", forward->id);
1421                                 found = 1;
1422                         }
1423                         break;
1424                 }
1425         }
1426         if (found)
1427                 printk(")");
1428 
1429         return 0;
1430 }
1431 
1432 static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1433         struct uvc_entity **_entity)
1434 {
1435         struct uvc_entity *entity = *_entity;
1436         struct uvc_entity *term;
1437         int id = -EINVAL, i;
1438 
1439         switch (UVC_ENTITY_TYPE(entity)) {
1440         case UVC_VC_EXTENSION_UNIT:
1441         case UVC_VC_PROCESSING_UNIT:
1442                 id = entity->baSourceID[0];
1443                 break;
1444 
1445         case UVC_VC_SELECTOR_UNIT:
1446                 /* Single-input selector units are ignored. */
1447                 if (entity->bNrInPins == 1) {
1448                         id = entity->baSourceID[0];
1449                         break;
1450                 }
1451 
1452                 if (uvc_trace_param & UVC_TRACE_PROBE)
1453                         printk(" <- IT");
1454 
1455                 chain->selector = entity;
1456                 for (i = 0; i < entity->bNrInPins; ++i) {
1457                         id = entity->baSourceID[i];
1458                         term = uvc_entity_by_id(chain->dev, id);
1459                         if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1460                                 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1461                                         "input %d isn't connected to an "
1462                                         "input terminal\n", entity->id, i);
1463                                 return -1;
1464                         }
1465 
1466                         if (uvc_trace_param & UVC_TRACE_PROBE)
1467                                 printk(" %d", term->id);
1468 
1469                         list_add_tail(&term->chain, &chain->entities);
1470                         uvc_scan_chain_forward(chain, term, entity);
1471                 }
1472 
1473                 if (uvc_trace_param & UVC_TRACE_PROBE)
1474                         printk("\n");
1475 
1476                 id = 0;
1477                 break;
1478 
1479         case UVC_ITT_VENDOR_SPECIFIC:
1480         case UVC_ITT_CAMERA:
1481         case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1482         case UVC_OTT_VENDOR_SPECIFIC:
1483         case UVC_OTT_DISPLAY:
1484         case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1485         case UVC_TT_STREAMING:
1486                 id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0;
1487                 break;
1488         }
1489 
1490         if (id <= 0) {
1491                 *_entity = NULL;
1492                 return id;
1493         }
1494 
1495         entity = uvc_entity_by_id(chain->dev, id);
1496         if (entity == NULL) {
1497                 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1498                         "unknown entity %d.\n", id);
1499                 return -EINVAL;
1500         }
1501 
1502         *_entity = entity;
1503         return 0;
1504 }
1505 
1506 static int uvc_scan_chain(struct uvc_video_chain *chain,
1507                           struct uvc_entity *term)
1508 {
1509         struct uvc_entity *entity, *prev;
1510 
1511         uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:");
1512 
1513         entity = term;
1514         prev = NULL;
1515 
1516         while (entity != NULL) {
1517                 /* Entity must not be part of an existing chain */
1518                 if (entity->chain.next || entity->chain.prev) {
1519                         uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1520                                 "entity %d already in chain.\n", entity->id);
1521                         return -EINVAL;
1522                 }
1523 
1524                 /* Process entity */
1525                 if (uvc_scan_chain_entity(chain, entity) < 0)
1526                         return -EINVAL;
1527 
1528                 /* Forward scan */
1529                 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1530                         return -EINVAL;
1531 
1532                 /* Backward scan */
1533                 prev = entity;
1534                 if (uvc_scan_chain_backward(chain, &entity) < 0)
1535                         return -EINVAL;
1536         }
1537 
1538         return 0;
1539 }
1540 
1541 static unsigned int uvc_print_terms(struct list_head *terms, u16 dir,
1542                 char *buffer)
1543 {
1544         struct uvc_entity *term;
1545         unsigned int nterms = 0;
1546         char *p = buffer;
1547 
1548         list_for_each_entry(term, terms, chain) {
1549                 if (!UVC_ENTITY_IS_TERM(term) ||
1550                     UVC_TERM_DIRECTION(term) != dir)
1551                         continue;
1552 
1553                 if (nterms)
1554                         p += sprintf(p, ",");
1555                 if (++nterms >= 4) {
1556                         p += sprintf(p, "...");
1557                         break;
1558                 }
1559                 p += sprintf(p, "%u", term->id);
1560         }
1561 
1562         return p - buffer;
1563 }
1564 
1565 static const char *uvc_print_chain(struct uvc_video_chain *chain)
1566 {
1567         static char buffer[43];
1568         char *p = buffer;
1569 
1570         p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p);
1571         p += sprintf(p, " -> ");
1572         uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p);
1573 
1574         return buffer;
1575 }
1576 
1577 /*
1578  * Scan the device for video chains and register video devices.
1579  *
1580  * Chains are scanned starting at their output terminals and walked backwards.
1581  */
1582 static int uvc_scan_device(struct uvc_device *dev)
1583 {
1584         struct uvc_video_chain *chain;
1585         struct uvc_entity *term;
1586 
1587         list_for_each_entry(term, &dev->entities, list) {
1588                 if (!UVC_ENTITY_IS_OTERM(term))
1589                         continue;
1590 
1591                 /* If the terminal is already included in a chain, skip it.
1592                  * This can happen for chains that have multiple output
1593                  * terminals, where all output terminals beside the first one
1594                  * will be inserted in the chain in forward scans.
1595                  */
1596                 if (term->chain.next || term->chain.prev)
1597                         continue;
1598 
1599                 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1600                 if (chain == NULL)
1601                         return -ENOMEM;
1602 
1603                 INIT_LIST_HEAD(&chain->entities);
1604                 mutex_init(&chain->ctrl_mutex);
1605                 chain->dev = dev;
1606                 v4l2_prio_init(&chain->prio);
1607 
1608                 term->flags |= UVC_ENTITY_FLAG_DEFAULT;
1609 
1610                 if (uvc_scan_chain(chain, term) < 0) {
1611                         kfree(chain);
1612                         continue;
1613                 }
1614 
1615                 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1616                           uvc_print_chain(chain));
1617 
1618                 list_add_tail(&chain->list, &dev->chains);
1619         }
1620 
1621         if (list_empty(&dev->chains)) {
1622                 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1623                 return -1;
1624         }
1625 
1626         return 0;
1627 }
1628 
1629 /* ------------------------------------------------------------------------
1630  * Video device registration and unregistration
1631  */
1632 
1633 /*
1634  * Delete the UVC device.
1635  *
1636  * Called by the kernel when the last reference to the uvc_device structure
1637  * is released.
1638  *
1639  * As this function is called after or during disconnect(), all URBs have
1640  * already been canceled by the USB core. There is no need to kill the
1641  * interrupt URB manually.
1642  */
1643 static void uvc_delete(struct uvc_device *dev)
1644 {
1645         struct list_head *p, *n;
1646 
1647         uvc_status_cleanup(dev);
1648         uvc_ctrl_cleanup_device(dev);
1649 
1650         usb_put_intf(dev->intf);
1651         usb_put_dev(dev->udev);
1652 
1653         if (dev->vdev.dev)
1654                 v4l2_device_unregister(&dev->vdev);
1655 #ifdef CONFIG_MEDIA_CONTROLLER
1656         if (media_devnode_is_registered(&dev->mdev.devnode))
1657                 media_device_unregister(&dev->mdev);
1658 #endif
1659 
1660         list_for_each_safe(p, n, &dev->chains) {
1661                 struct uvc_video_chain *chain;
1662                 chain = list_entry(p, struct uvc_video_chain, list);
1663                 kfree(chain);
1664         }
1665 
1666         list_for_each_safe(p, n, &dev->entities) {
1667                 struct uvc_entity *entity;
1668                 entity = list_entry(p, struct uvc_entity, list);
1669 #ifdef CONFIG_MEDIA_CONTROLLER
1670                 uvc_mc_cleanup_entity(entity);
1671 #endif
1672                 kfree(entity);
1673         }
1674 
1675         list_for_each_safe(p, n, &dev->streams) {
1676                 struct uvc_streaming *streaming;
1677                 streaming = list_entry(p, struct uvc_streaming, list);
1678                 usb_driver_release_interface(&uvc_driver.driver,
1679                         streaming->intf);
1680                 usb_put_intf(streaming->intf);
1681                 kfree(streaming->format);
1682                 kfree(streaming->header.bmaControls);
1683                 kfree(streaming);
1684         }
1685 
1686         kfree(dev);
1687 }
1688 
1689 static void uvc_release(struct video_device *vdev)
1690 {
1691         struct uvc_streaming *stream = video_get_drvdata(vdev);
1692         struct uvc_device *dev = stream->dev;
1693 
1694         /* Decrement the registered streams count and delete the device when it
1695          * reaches zero.
1696          */
1697         if (atomic_dec_and_test(&dev->nstreams))
1698                 uvc_delete(dev);
1699 }
1700 
1701 /*
1702  * Unregister the video devices.
1703  */
1704 static void uvc_unregister_video(struct uvc_device *dev)
1705 {
1706         struct uvc_streaming *stream;
1707 
1708         /* Unregistering all video devices might result in uvc_delete() being
1709          * called from inside the loop if there's no open file handle. To avoid
1710          * that, increment the stream count before iterating over the streams
1711          * and decrement it when done.
1712          */
1713         atomic_inc(&dev->nstreams);
1714 
1715         list_for_each_entry(stream, &dev->streams, list) {
1716                 if (!video_is_registered(&stream->vdev))
1717                         continue;
1718 
1719                 video_unregister_device(&stream->vdev);
1720 
1721                 uvc_debugfs_cleanup_stream(stream);
1722         }
1723 
1724         /* Decrement the stream count and call uvc_delete explicitly if there
1725          * are no stream left.
1726          */
1727         if (atomic_dec_and_test(&dev->nstreams))
1728                 uvc_delete(dev);
1729 }
1730 
1731 static int uvc_register_video(struct uvc_device *dev,
1732                 struct uvc_streaming *stream)
1733 {
1734         struct video_device *vdev = &stream->vdev;
1735         int ret;
1736 
1737         /* Initialize the video buffers queue. */
1738         ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1739         if (ret)
1740                 return ret;
1741 
1742         /* Initialize the streaming interface with default streaming
1743          * parameters.
1744          */
1745         ret = uvc_video_init(stream);
1746         if (ret < 0) {
1747                 uvc_printk(KERN_ERR, "Failed to initialize the device "
1748                         "(%d).\n", ret);
1749                 return ret;
1750         }
1751 
1752         uvc_debugfs_init_stream(stream);
1753 
1754         /* Register the device with V4L. */
1755 
1756         /* We already hold a reference to dev->udev. The video device will be
1757          * unregistered before the reference is released, so we don't need to
1758          * get another one.
1759          */
1760         vdev->v4l2_dev = &dev->vdev;
1761         vdev->fops = &uvc_fops;
1762         vdev->ioctl_ops = &uvc_ioctl_ops;
1763         vdev->release = uvc_release;
1764         vdev->prio = &stream->chain->prio;
1765         if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1766                 vdev->vfl_dir = VFL_DIR_TX;
1767         strlcpy(vdev->name, dev->name, sizeof vdev->name);
1768 
1769         /* Set the driver data before calling video_register_device, otherwise
1770          * uvc_v4l2_open might race us.
1771          */
1772         video_set_drvdata(vdev, stream);
1773 
1774         ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1775         if (ret < 0) {
1776                 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1777                            ret);
1778                 return ret;
1779         }
1780 
1781         if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1782                 stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
1783         else
1784                 stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
1785 
1786         atomic_inc(&dev->nstreams);
1787         return 0;
1788 }
1789 
1790 /*
1791  * Register all video devices in all chains.
1792  */
1793 static int uvc_register_terms(struct uvc_device *dev,
1794         struct uvc_video_chain *chain)
1795 {
1796         struct uvc_streaming *stream;
1797         struct uvc_entity *term;
1798         int ret;
1799 
1800         list_for_each_entry(term, &chain->entities, chain) {
1801                 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1802                         continue;
1803 
1804                 stream = uvc_stream_by_id(dev, term->id);
1805                 if (stream == NULL) {
1806                         uvc_printk(KERN_INFO, "No streaming interface found "
1807                                    "for terminal %u.", term->id);
1808                         continue;
1809                 }
1810 
1811                 stream->chain = chain;
1812                 ret = uvc_register_video(dev, stream);
1813                 if (ret < 0)
1814                         return ret;
1815 
1816                 term->vdev = &stream->vdev;
1817         }
1818 
1819         return 0;
1820 }
1821 
1822 static int uvc_register_chains(struct uvc_device *dev)
1823 {
1824         struct uvc_video_chain *chain;
1825         int ret;
1826 
1827         list_for_each_entry(chain, &dev->chains, list) {
1828                 ret = uvc_register_terms(dev, chain);
1829                 if (ret < 0)
1830                         return ret;
1831 
1832 #ifdef CONFIG_MEDIA_CONTROLLER
1833                 ret = uvc_mc_register_entities(chain);
1834                 if (ret < 0) {
1835                         uvc_printk(KERN_INFO, "Failed to register entites "
1836                                 "(%d).\n", ret);
1837                 }
1838 #endif
1839         }
1840 
1841         return 0;
1842 }
1843 
1844 /* ------------------------------------------------------------------------
1845  * USB probe, disconnect, suspend and resume
1846  */
1847 
1848 static int uvc_probe(struct usb_interface *intf,
1849                      const struct usb_device_id *id)
1850 {
1851         struct usb_device *udev = interface_to_usbdev(intf);
1852         struct uvc_device *dev;
1853         int ret;
1854 
1855         if (id->idVendor && id->idProduct)
1856                 uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
1857                                 "(%04x:%04x)\n", udev->devpath, id->idVendor,
1858                                 id->idProduct);
1859         else
1860                 uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
1861                                 udev->devpath);
1862 
1863         /* Allocate memory for the device and initialize it. */
1864         if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
1865                 return -ENOMEM;
1866 
1867         INIT_LIST_HEAD(&dev->entities);
1868         INIT_LIST_HEAD(&dev->chains);
1869         INIT_LIST_HEAD(&dev->streams);
1870         atomic_set(&dev->nstreams, 0);
1871         atomic_set(&dev->nmappings, 0);
1872         mutex_init(&dev->lock);
1873 
1874         dev->udev = usb_get_dev(udev);
1875         dev->intf = usb_get_intf(intf);
1876         dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1877         dev->quirks = (uvc_quirks_param == -1)
1878                     ? id->driver_info : uvc_quirks_param;
1879 
1880         if (udev->product != NULL)
1881                 strlcpy(dev->name, udev->product, sizeof dev->name);
1882         else
1883                 snprintf(dev->name, sizeof dev->name,
1884                         "UVC Camera (%04x:%04x)",
1885                         le16_to_cpu(udev->descriptor.idVendor),
1886                         le16_to_cpu(udev->descriptor.idProduct));
1887 
1888         /* Parse the Video Class control descriptor. */
1889         if (uvc_parse_control(dev) < 0) {
1890                 uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
1891                         "descriptors.\n");
1892                 goto error;
1893         }
1894 
1895         uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
1896                 dev->uvc_version >> 8, dev->uvc_version & 0xff,
1897                 udev->product ? udev->product : "<unnamed>",
1898                 le16_to_cpu(udev->descriptor.idVendor),
1899                 le16_to_cpu(udev->descriptor.idProduct));
1900 
1901         if (dev->quirks != id->driver_info) {
1902                 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1903                         "parameter for testing purpose.\n", dev->quirks);
1904                 uvc_printk(KERN_INFO, "Please report required quirks to the "
1905                         "linux-uvc-devel mailing list.\n");
1906         }
1907 
1908         /* Register the media and V4L2 devices. */
1909 #ifdef CONFIG_MEDIA_CONTROLLER
1910         dev->mdev.dev = &intf->dev;
1911         strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
1912         if (udev->serial)
1913                 strlcpy(dev->mdev.serial, udev->serial,
1914                         sizeof(dev->mdev.serial));
1915         strcpy(dev->mdev.bus_info, udev->devpath);
1916         dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
1917         dev->mdev.driver_version = LINUX_VERSION_CODE;
1918         if (media_device_register(&dev->mdev) < 0)
1919                 goto error;
1920 
1921         dev->vdev.mdev = &dev->mdev;
1922 #endif
1923         if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
1924                 goto error;
1925 
1926         /* Initialize controls. */
1927         if (uvc_ctrl_init_device(dev) < 0)
1928                 goto error;
1929 
1930         /* Scan the device for video chains. */
1931         if (uvc_scan_device(dev) < 0)
1932                 goto error;
1933 
1934         /* Register video device nodes. */
1935         if (uvc_register_chains(dev) < 0)
1936                 goto error;
1937 
1938         /* Save our data pointer in the interface data. */
1939         usb_set_intfdata(intf, dev);
1940 
1941         /* Initialize the interrupt URB. */
1942         if ((ret = uvc_status_init(dev)) < 0) {
1943                 uvc_printk(KERN_INFO, "Unable to initialize the status "
1944                         "endpoint (%d), status interrupt will not be "
1945                         "supported.\n", ret);
1946         }
1947 
1948         uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
1949         usb_enable_autosuspend(udev);
1950         return 0;
1951 
1952 error:
1953         uvc_unregister_video(dev);
1954         return -ENODEV;
1955 }
1956 
1957 static void uvc_disconnect(struct usb_interface *intf)
1958 {
1959         struct uvc_device *dev = usb_get_intfdata(intf);
1960 
1961         /* Set the USB interface data to NULL. This can be done outside the
1962          * lock, as there's no other reader.
1963          */
1964         usb_set_intfdata(intf, NULL);
1965 
1966         if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1967             UVC_SC_VIDEOSTREAMING)
1968                 return;
1969 
1970         dev->state |= UVC_DEV_DISCONNECTED;
1971 
1972         uvc_unregister_video(dev);
1973 }
1974 
1975 static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1976 {
1977         struct uvc_device *dev = usb_get_intfdata(intf);
1978         struct uvc_streaming *stream;
1979 
1980         uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1981                 intf->cur_altsetting->desc.bInterfaceNumber);
1982 
1983         /* Controls are cached on the fly so they don't need to be saved. */
1984         if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1985             UVC_SC_VIDEOCONTROL) {
1986                 mutex_lock(&dev->lock);
1987                 if (dev->users)
1988                         uvc_status_stop(dev);
1989                 mutex_unlock(&dev->lock);
1990                 return 0;
1991         }
1992 
1993         list_for_each_entry(stream, &dev->streams, list) {
1994                 if (stream->intf == intf)
1995                         return uvc_video_suspend(stream);
1996         }
1997 
1998         uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1999                         "mismatch.\n");
2000         return -EINVAL;
2001 }
2002 
2003 static int __uvc_resume(struct usb_interface *intf, int reset)
2004 {
2005         struct uvc_device *dev = usb_get_intfdata(intf);
2006         struct uvc_streaming *stream;
2007         int ret = 0;
2008 
2009         uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
2010                 intf->cur_altsetting->desc.bInterfaceNumber);
2011 
2012         if (intf->cur_altsetting->desc.bInterfaceSubClass ==
2013             UVC_SC_VIDEOCONTROL) {
2014                 if (reset) {
2015                         ret = uvc_ctrl_restore_values(dev);
2016                         if (ret < 0)
2017                                 return ret;
2018                 }
2019 
2020                 mutex_lock(&dev->lock);
2021                 if (dev->users)
2022                         ret = uvc_status_start(dev, GFP_NOIO);
2023                 mutex_unlock(&dev->lock);
2024 
2025                 return ret;
2026         }
2027 
2028         list_for_each_entry(stream, &dev->streams, list) {
2029                 if (stream->intf == intf) {
2030                         ret = uvc_video_resume(stream, reset);
2031                         if (ret < 0)
2032                                 uvc_queue_streamoff(&stream->queue,
2033                                                     stream->queue.queue.type);
2034                         return ret;
2035                 }
2036         }
2037 
2038         uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
2039                         "mismatch.\n");
2040         return -EINVAL;
2041 }
2042 
2043 static int uvc_resume(struct usb_interface *intf)
2044 {
2045         return __uvc_resume(intf, 0);
2046 }
2047 
2048 static int uvc_reset_resume(struct usb_interface *intf)
2049 {
2050         return __uvc_resume(intf, 1);
2051 }
2052 
2053 /* ------------------------------------------------------------------------
2054  * Module parameters
2055  */
2056 
2057 static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
2058 {
2059         if (uvc_clock_param == CLOCK_MONOTONIC)
2060                 return sprintf(buffer, "CLOCK_MONOTONIC");
2061         else
2062                 return sprintf(buffer, "CLOCK_REALTIME");
2063 }
2064 
2065 static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
2066 {
2067         if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
2068                 val += strlen("clock_");
2069 
2070         if (strcasecmp(val, "monotonic") == 0)
2071                 uvc_clock_param = CLOCK_MONOTONIC;
2072         else if (strcasecmp(val, "realtime") == 0)
2073                 uvc_clock_param = CLOCK_REALTIME;
2074         else
2075                 return -EINVAL;
2076 
2077         return 0;
2078 }
2079 
2080 module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
2081                   &uvc_clock_param, S_IRUGO|S_IWUSR);
2082 MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
2083 module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2084 MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2085 module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2086 MODULE_PARM_DESC(quirks, "Forced device quirks");
2087 module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2088 MODULE_PARM_DESC(trace, "Trace level bitmask");
2089 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2090 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2091 
2092 /* ------------------------------------------------------------------------
2093  * Driver initialization and cleanup
2094  */
2095 
2096 /*
2097  * The Logitech cameras listed below have their interface class set to
2098  * VENDOR_SPEC because they don't announce themselves as UVC devices, even
2099  * though they are compliant.
2100  */
2101 static struct usb_device_id uvc_ids[] = {
2102         /* LogiLink Wireless Webcam */
2103         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2104                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2105           .idVendor             = 0x0416,
2106           .idProduct            = 0xa91a,
2107           .bInterfaceClass      = USB_CLASS_VIDEO,
2108           .bInterfaceSubClass   = 1,
2109           .bInterfaceProtocol   = 0,
2110           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2111         /* Genius eFace 2025 */
2112         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2113                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2114           .idVendor             = 0x0458,
2115           .idProduct            = 0x706e,
2116           .bInterfaceClass      = USB_CLASS_VIDEO,
2117           .bInterfaceSubClass   = 1,
2118           .bInterfaceProtocol   = 0,
2119           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2120         /* Microsoft Lifecam NX-6000 */
2121         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2122                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2123           .idVendor             = 0x045e,
2124           .idProduct            = 0x00f8,
2125           .bInterfaceClass      = USB_CLASS_VIDEO,
2126           .bInterfaceSubClass   = 1,
2127           .bInterfaceProtocol   = 0,
2128           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2129         /* Microsoft Lifecam NX-3000 */
2130         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2131                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2132           .idVendor             = 0x045e,
2133           .idProduct            = 0x0721,
2134           .bInterfaceClass      = USB_CLASS_VIDEO,
2135           .bInterfaceSubClass   = 1,
2136           .bInterfaceProtocol   = 0,
2137           .driver_info          = UVC_QUIRK_PROBE_DEF },
2138         /* Microsoft Lifecam VX-7000 */
2139         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2140                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2141           .idVendor             = 0x045e,
2142           .idProduct            = 0x0723,
2143           .bInterfaceClass      = USB_CLASS_VIDEO,
2144           .bInterfaceSubClass   = 1,
2145           .bInterfaceProtocol   = 0,
2146           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2147         /* Logitech Quickcam Fusion */
2148         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2149                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2150           .idVendor             = 0x046d,
2151           .idProduct            = 0x08c1,
2152           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2153           .bInterfaceSubClass   = 1,
2154           .bInterfaceProtocol   = 0 },
2155         /* Logitech Quickcam Orbit MP */
2156         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2157                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2158           .idVendor             = 0x046d,
2159           .idProduct            = 0x08c2,
2160           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2161           .bInterfaceSubClass   = 1,
2162           .bInterfaceProtocol   = 0 },
2163         /* Logitech Quickcam Pro for Notebook */
2164         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2165                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2166           .idVendor             = 0x046d,
2167           .idProduct            = 0x08c3,
2168           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2169           .bInterfaceSubClass   = 1,
2170           .bInterfaceProtocol   = 0 },
2171         /* Logitech Quickcam Pro 5000 */
2172         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2173                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2174           .idVendor             = 0x046d,
2175           .idProduct            = 0x08c5,
2176           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2177           .bInterfaceSubClass   = 1,
2178           .bInterfaceProtocol   = 0 },
2179         /* Logitech Quickcam OEM Dell Notebook */
2180         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2181                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2182           .idVendor             = 0x046d,
2183           .idProduct            = 0x08c6,
2184           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2185           .bInterfaceSubClass   = 1,
2186           .bInterfaceProtocol   = 0 },
2187         /* Logitech Quickcam OEM Cisco VT Camera II */
2188         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2189                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2190           .idVendor             = 0x046d,
2191           .idProduct            = 0x08c7,
2192           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2193           .bInterfaceSubClass   = 1,
2194           .bInterfaceProtocol   = 0 },
2195         /* Logitech HD Pro Webcam C920 */
2196         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2197                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2198           .idVendor             = 0x046d,
2199           .idProduct            = 0x082d,
2200           .bInterfaceClass      = USB_CLASS_VIDEO,
2201           .bInterfaceSubClass   = 1,
2202           .bInterfaceProtocol   = 0,
2203           .driver_info          = UVC_QUIRK_RESTORE_CTRLS_ON_INIT },
2204         /* Chicony CNF7129 (Asus EEE 100HE) */
2205         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2206                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2207           .idVendor             = 0x04f2,
2208           .idProduct            = 0xb071,
2209           .bInterfaceClass      = USB_CLASS_VIDEO,
2210           .bInterfaceSubClass   = 1,
2211           .bInterfaceProtocol   = 0,
2212           .driver_info          = UVC_QUIRK_RESTRICT_FRAME_RATE },
2213         /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2214         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2215                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2216           .idVendor             = 0x058f,
2217           .idProduct            = 0x3820,
2218           .bInterfaceClass      = USB_CLASS_VIDEO,
2219           .bInterfaceSubClass   = 1,
2220           .bInterfaceProtocol   = 0,
2221           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2222         /* Dell XPS m1530 */
2223         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2224                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2225           .idVendor             = 0x05a9,
2226           .idProduct            = 0x2640,
2227           .bInterfaceClass      = USB_CLASS_VIDEO,
2228           .bInterfaceSubClass   = 1,
2229           .bInterfaceProtocol   = 0,
2230           .driver_info          = UVC_QUIRK_PROBE_DEF },
2231         /* Dell SP2008WFP Monitor */
2232         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2233                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2234           .idVendor             = 0x05a9,
2235           .idProduct            = 0x2641,
2236           .bInterfaceClass      = USB_CLASS_VIDEO,
2237           .bInterfaceSubClass   = 1,
2238           .bInterfaceProtocol   = 0,
2239           .driver_info          = UVC_QUIRK_PROBE_DEF },
2240         /* Dell Alienware X51 */
2241         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2242                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2243           .idVendor             = 0x05a9,
2244           .idProduct            = 0x2643,
2245           .bInterfaceClass      = USB_CLASS_VIDEO,
2246           .bInterfaceSubClass   = 1,
2247           .bInterfaceProtocol   = 0,
2248           .driver_info  = UVC_QUIRK_PROBE_DEF },
2249         /* Dell Studio Hybrid 140g (OmniVision webcam) */
2250         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2251                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2252           .idVendor             = 0x05a9,
2253           .idProduct            = 0x264a,
2254           .bInterfaceClass      = USB_CLASS_VIDEO,
2255           .bInterfaceSubClass   = 1,
2256           .bInterfaceProtocol   = 0,
2257           .driver_info          = UVC_QUIRK_PROBE_DEF },
2258         /* Dell XPS M1330 (OmniVision OV7670 webcam) */
2259         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2260                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2261           .idVendor             = 0x05a9,
2262           .idProduct            = 0x7670,
2263           .bInterfaceClass      = USB_CLASS_VIDEO,
2264           .bInterfaceSubClass   = 1,
2265           .bInterfaceProtocol   = 0,
2266           .driver_info          = UVC_QUIRK_PROBE_DEF },
2267         /* Apple Built-In iSight */
2268         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2269                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2270           .idVendor             = 0x05ac,
2271           .idProduct            = 0x8501,
2272           .bInterfaceClass      = USB_CLASS_VIDEO,
2273           .bInterfaceSubClass   = 1,
2274           .bInterfaceProtocol   = 0,
2275           .driver_info          = UVC_QUIRK_PROBE_MINMAX
2276                                 | UVC_QUIRK_BUILTIN_ISIGHT },
2277         /* Foxlink ("HP Webcam" on HP Mini 5103) */
2278         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2279                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2280           .idVendor             = 0x05c8,
2281           .idProduct            = 0x0403,
2282           .bInterfaceClass      = USB_CLASS_VIDEO,
2283           .bInterfaceSubClass   = 1,
2284           .bInterfaceProtocol   = 0,
2285           .driver_info          = UVC_QUIRK_FIX_BANDWIDTH },
2286         /* Genesys Logic USB 2.0 PC Camera */
2287         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2288                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2289           .idVendor             = 0x05e3,
2290           .idProduct            = 0x0505,
2291           .bInterfaceClass      = USB_CLASS_VIDEO,
2292           .bInterfaceSubClass   = 1,
2293           .bInterfaceProtocol   = 0,
2294           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2295         /* Hercules Classic Silver */
2296         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2297                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2298           .idVendor             = 0x06f8,
2299           .idProduct            = 0x300c,
2300           .bInterfaceClass      = USB_CLASS_VIDEO,
2301           .bInterfaceSubClass   = 1,
2302           .bInterfaceProtocol   = 0,
2303           .driver_info          = UVC_QUIRK_FIX_BANDWIDTH },
2304         /* ViMicro Vega */
2305         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2306                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2307           .idVendor             = 0x0ac8,
2308           .idProduct            = 0x332d,
2309           .bInterfaceClass      = USB_CLASS_VIDEO,
2310           .bInterfaceSubClass   = 1,
2311           .bInterfaceProtocol   = 0,
2312           .driver_info          = UVC_QUIRK_FIX_BANDWIDTH },
2313         /* ViMicro - Minoru3D */
2314         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2315                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2316           .idVendor             = 0x0ac8,
2317           .idProduct            = 0x3410,
2318           .bInterfaceClass      = USB_CLASS_VIDEO,
2319           .bInterfaceSubClass   = 1,
2320           .bInterfaceProtocol   = 0,
2321           .driver_info          = UVC_QUIRK_FIX_BANDWIDTH },
2322         /* ViMicro Venus - Minoru3D */
2323         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2324                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2325           .idVendor             = 0x0ac8,
2326           .idProduct            = 0x3420,
2327           .bInterfaceClass      = USB_CLASS_VIDEO,
2328           .bInterfaceSubClass   = 1,
2329           .bInterfaceProtocol   = 0,
2330           .driver_info          = UVC_QUIRK_FIX_BANDWIDTH },
2331         /* Ophir Optronics - SPCAM 620U */
2332         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2333                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2334           .idVendor             = 0x0bd3,
2335           .idProduct            = 0x0555,
2336           .bInterfaceClass      = USB_CLASS_VIDEO,
2337           .bInterfaceSubClass   = 1,
2338           .bInterfaceProtocol   = 0,
2339           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2340         /* MT6227 */
2341         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2342                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2343           .idVendor             = 0x0e8d,
2344           .idProduct            = 0x0004,
2345           .bInterfaceClass      = USB_CLASS_VIDEO,
2346           .bInterfaceSubClass   = 1,
2347           .bInterfaceProtocol   = 0,
2348           .driver_info          = UVC_QUIRK_PROBE_MINMAX
2349                                 | UVC_QUIRK_PROBE_DEF },
2350         /* IMC Networks (Medion Akoya) */
2351         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2352                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2353           .idVendor             = 0x13d3,
2354           .idProduct            = 0x5103,
2355           .bInterfaceClass      = USB_CLASS_VIDEO,
2356           .bInterfaceSubClass   = 1,
2357           .bInterfaceProtocol   = 0,
2358           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2359         /* JMicron USB2.0 XGA WebCam */
2360         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2361                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2362           .idVendor             = 0x152d,
2363           .idProduct            = 0x0310,
2364           .bInterfaceClass      = USB_CLASS_VIDEO,
2365           .bInterfaceSubClass   = 1,
2366           .bInterfaceProtocol   = 0,
2367           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2368         /* Syntek (HP Spartan) */
2369         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2370                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2371           .idVendor             = 0x174f,
2372           .idProduct            = 0x5212,
2373           .bInterfaceClass      = USB_CLASS_VIDEO,
2374           .bInterfaceSubClass   = 1,
2375           .bInterfaceProtocol   = 0,
2376           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2377         /* Syntek (Samsung Q310) */
2378         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2379                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2380           .idVendor             = 0x174f,
2381           .idProduct            = 0x5931,
2382           .bInterfaceClass      = USB_CLASS_VIDEO,
2383           .bInterfaceSubClass   = 1,
2384           .bInterfaceProtocol   = 0,
2385           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2386         /* Syntek (Packard Bell EasyNote MX52 */
2387         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2388                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2389           .idVendor             = 0x174f,
2390           .idProduct            = 0x8a12,
2391           .bInterfaceClass      = USB_CLASS_VIDEO,
2392           .bInterfaceSubClass   = 1,
2393           .bInterfaceProtocol   = 0,
2394           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2395         /* Syntek (Asus F9SG) */
2396         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2397                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2398           .idVendor             = 0x174f,
2399           .idProduct            = 0x8a31,
2400           .bInterfaceClass      = USB_CLASS_VIDEO,
2401           .bInterfaceSubClass   = 1,
2402           .bInterfaceProtocol   = 0,
2403           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2404         /* Syntek (Asus U3S) */
2405         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2406                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2407           .idVendor             = 0x174f,
2408           .idProduct            = 0x8a33,
2409           .bInterfaceClass      = USB_CLASS_VIDEO,
2410           .bInterfaceSubClass   = 1,
2411           .bInterfaceProtocol   = 0,
2412           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2413         /* Syntek (JAOtech Smart Terminal) */
2414         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2415                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2416           .idVendor             = 0x174f,
2417           .idProduct            = 0x8a34,
2418           .bInterfaceClass      = USB_CLASS_VIDEO,
2419           .bInterfaceSubClass   = 1,
2420           .bInterfaceProtocol   = 0,
2421           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2422         /* Miricle 307K */
2423         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2424                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2425           .idVendor             = 0x17dc,
2426           .idProduct            = 0x0202,
2427           .bInterfaceClass      = USB_CLASS_VIDEO,
2428           .bInterfaceSubClass   = 1,
2429           .bInterfaceProtocol   = 0,
2430           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2431         /* Lenovo Thinkpad SL400/SL500 */
2432         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2433                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2434           .idVendor             = 0x17ef,
2435           .idProduct            = 0x480b,
2436           .bInterfaceClass      = USB_CLASS_VIDEO,
2437           .bInterfaceSubClass   = 1,
2438           .bInterfaceProtocol   = 0,
2439           .driver_info          = UVC_QUIRK_STREAM_NO_FID },
2440         /* Aveo Technology USB 2.0 Camera */
2441         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2442                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2443           .idVendor             = 0x1871,
2444           .idProduct            = 0x0306,
2445           .bInterfaceClass      = USB_CLASS_VIDEO,
2446           .bInterfaceSubClass   = 1,
2447           .bInterfaceProtocol   = 0,
2448           .driver_info          = UVC_QUIRK_PROBE_MINMAX
2449                                 | UVC_QUIRK_PROBE_EXTRAFIELDS },
2450         /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */
2451         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2452                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2453           .idVendor             = 0x1871,
2454           .idProduct            = 0x0516,
2455           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2456           .bInterfaceSubClass   = 1,
2457           .bInterfaceProtocol   = 0 },
2458         /* Ecamm Pico iMage */
2459         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2460                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2461           .idVendor             = 0x18cd,
2462           .idProduct            = 0xcafe,
2463           .bInterfaceClass      = USB_CLASS_VIDEO,
2464           .bInterfaceSubClass   = 1,
2465           .bInterfaceProtocol   = 0,
2466           .driver_info          = UVC_QUIRK_PROBE_EXTRAFIELDS },
2467         /* Manta MM-353 Plako */
2468         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2469                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2470           .idVendor             = 0x18ec,
2471           .idProduct            = 0x3188,
2472           .bInterfaceClass      = USB_CLASS_VIDEO,
2473           .bInterfaceSubClass   = 1,
2474           .bInterfaceProtocol   = 0,
2475           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2476         /* FSC WebCam V30S */
2477         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2478                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2479           .idVendor             = 0x18ec,
2480           .idProduct            = 0x3288,
2481           .bInterfaceClass      = USB_CLASS_VIDEO,
2482           .bInterfaceSubClass   = 1,
2483           .bInterfaceProtocol   = 0,
2484           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2485         /* Arkmicro unbranded */
2486         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2487                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2488           .idVendor             = 0x18ec,
2489           .idProduct            = 0x3290,
2490           .bInterfaceClass      = USB_CLASS_VIDEO,
2491           .bInterfaceSubClass   = 1,
2492           .bInterfaceProtocol   = 0,
2493           .driver_info          = UVC_QUIRK_PROBE_DEF },
2494         /* The Imaging Source USB CCD cameras */
2495         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2496                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2497           .idVendor             = 0x199e,
2498           .idProduct            = 0x8102,
2499           .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
2500           .bInterfaceSubClass   = 1,
2501           .bInterfaceProtocol   = 0 },
2502         /* Bodelin ProScopeHR */
2503         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2504                                 | USB_DEVICE_ID_MATCH_DEV_HI
2505                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2506           .idVendor             = 0x19ab,
2507           .idProduct            = 0x1000,
2508           .bcdDevice_hi         = 0x0126,
2509           .bInterfaceClass      = USB_CLASS_VIDEO,
2510           .bInterfaceSubClass   = 1,
2511           .bInterfaceProtocol   = 0,
2512           .driver_info          = UVC_QUIRK_STATUS_INTERVAL },
2513         /* MSI StarCam 370i */
2514         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2515                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2516           .idVendor             = 0x1b3b,
2517           .idProduct            = 0x2951,
2518           .bInterfaceClass      = USB_CLASS_VIDEO,
2519           .bInterfaceSubClass   = 1,
2520           .bInterfaceProtocol   = 0,
2521           .driver_info          = UVC_QUIRK_PROBE_MINMAX },
2522         /* SiGma Micro USB Web Camera */
2523         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2524                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2525           .idVendor             = 0x1c4f,
2526           .idProduct            = 0x3000,
2527           .bInterfaceClass      = USB_CLASS_VIDEO,
2528           .bInterfaceSubClass   = 1,
2529           .bInterfaceProtocol   = 0,
2530           .driver_info          = UVC_QUIRK_PROBE_MINMAX
2531                                 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
2532         /* Oculus VR Positional Tracker DK2 */
2533         { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
2534                                 | USB_DEVICE_ID_MATCH_INT_INFO,
2535           .idVendor             = 0x2833,
2536           .idProduct            = 0x0201,
2537           .bInterfaceClass      = USB_CLASS_VIDEO,
2538           .bInterfaceSubClass   = 1,
2539           .bInterfaceProtocol   = 0,
2540           .driver_info          = UVC_QUIRK_FORCE_Y8 },
2541         /* Generic USB Video Class */
2542         { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
2543         {}
2544 };
2545 
2546 MODULE_DEVICE_TABLE(usb, uvc_ids);
2547 
2548 struct uvc_driver uvc_driver = {
2549         .driver = {
2550                 .name           = "uvcvideo",
2551                 .probe          = uvc_probe,
2552                 .disconnect     = uvc_disconnect,
2553                 .suspend        = uvc_suspend,
2554                 .resume         = uvc_resume,
2555                 .reset_resume   = uvc_reset_resume,
2556                 .id_table       = uvc_ids,
2557                 .supports_autosuspend = 1,
2558         },
2559 };
2560 
2561 static int __init uvc_init(void)
2562 {
2563         int ret;
2564 
2565         uvc_debugfs_init();
2566 
2567         ret = usb_register(&uvc_driver.driver);
2568         if (ret < 0) {
2569                 uvc_debugfs_cleanup();
2570                 return ret;
2571         }
2572 
2573         printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
2574         return 0;
2575 }
2576 
2577 static void __exit uvc_cleanup(void)
2578 {
2579         usb_deregister(&uvc_driver.driver);
2580         uvc_debugfs_cleanup();
2581 }
2582 
2583 module_init(uvc_init);
2584 module_exit(uvc_cleanup);
2585 
2586 MODULE_AUTHOR(DRIVER_AUTHOR);
2587 MODULE_DESCRIPTION(DRIVER_DESC);
2588 MODULE_LICENSE("GPL");
2589 MODULE_VERSION(DRIVER_VERSION);
2590 
2591 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us