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