Version:  2.0.40 2.2.26 2.4.37 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 4.2 4.3 4.4

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

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