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