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