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