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