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