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