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