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