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