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