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