| 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * uvc_driver.c -- USB Video Class driver |
| 4 | * |
| 5 | * Copyright (C) 2005-2010 |
| 6 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
| 7 | */ |
| 8 | |
| 9 | #include <linux/atomic.h> |
| 10 | #include <linux/bits.h> |
| 11 | #include <linux/gpio/consumer.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/usb.h> |
| 17 | #include <linux/usb/quirks.h> |
| 18 | #include <linux/usb/uvc.h> |
| 19 | #include <linux/videodev2.h> |
| 20 | #include <linux/vmalloc.h> |
| 21 | #include <linux/wait.h> |
| 22 | #include <linux/unaligned.h> |
| 23 | |
| 24 | #include <media/v4l2-common.h> |
| 25 | #include <media/v4l2-ioctl.h> |
| 26 | |
| 27 | #include "uvcvideo.h" |
| 28 | |
| 29 | #define DRIVER_AUTHOR "Laurent Pinchart " \ |
| 30 | "<laurent.pinchart@ideasonboard.com>" |
| 31 | #define DRIVER_DESC "USB Video Class driver" |
| 32 | |
| 33 | unsigned int uvc_clock_param = CLOCK_MONOTONIC; |
| 34 | unsigned int uvc_hw_timestamps_param; |
| 35 | unsigned int uvc_no_drop_param = 1; |
| 36 | static unsigned int uvc_quirks_param = -1; |
| 37 | unsigned int uvc_dbg_param; |
| 38 | unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT; |
| 39 | |
| 40 | static struct usb_driver uvc_driver; |
| 41 | |
| 42 | /* ------------------------------------------------------------------------ |
| 43 | * Utility functions |
| 44 | */ |
| 45 | |
| 46 | struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, |
| 47 | u8 epaddr) |
| 48 | { |
| 49 | struct usb_host_endpoint *ep; |
| 50 | unsigned int i; |
| 51 | |
| 52 | for (i = 0; i < alts->desc.bNumEndpoints; ++i) { |
| 53 | ep = &alts->endpoint[i]; |
| 54 | if (ep->desc.bEndpointAddress == epaddr) |
| 55 | return ep; |
| 56 | } |
| 57 | |
| 58 | return NULL; |
| 59 | } |
| 60 | |
| 61 | static enum v4l2_colorspace uvc_colorspace(const u8 primaries) |
| 62 | { |
| 63 | static const enum v4l2_colorspace colorprimaries[] = { |
| 64 | V4L2_COLORSPACE_SRGB, /* Unspecified */ |
| 65 | V4L2_COLORSPACE_SRGB, |
| 66 | V4L2_COLORSPACE_470_SYSTEM_M, |
| 67 | V4L2_COLORSPACE_470_SYSTEM_BG, |
| 68 | V4L2_COLORSPACE_SMPTE170M, |
| 69 | V4L2_COLORSPACE_SMPTE240M, |
| 70 | }; |
| 71 | |
| 72 | if (primaries < ARRAY_SIZE(colorprimaries)) |
| 73 | return colorprimaries[primaries]; |
| 74 | |
| 75 | return V4L2_COLORSPACE_SRGB; /* Reserved */ |
| 76 | } |
| 77 | |
| 78 | static enum v4l2_xfer_func uvc_xfer_func(const u8 transfer_characteristics) |
| 79 | { |
| 80 | /* |
| 81 | * V4L2 does not currently have definitions for all possible values of |
| 82 | * UVC transfer characteristics. If v4l2_xfer_func is extended with new |
| 83 | * values, the mapping below should be updated. |
| 84 | * |
| 85 | * Substitutions are taken from the mapping given for |
| 86 | * V4L2_XFER_FUNC_DEFAULT documented in videodev2.h. |
| 87 | */ |
| 88 | static const enum v4l2_xfer_func xfer_funcs[] = { |
| 89 | V4L2_XFER_FUNC_DEFAULT, /* Unspecified */ |
| 90 | V4L2_XFER_FUNC_709, |
| 91 | V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 M */ |
| 92 | V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 B, G */ |
| 93 | V4L2_XFER_FUNC_709, /* Substitution for SMPTE 170M */ |
| 94 | V4L2_XFER_FUNC_SMPTE240M, |
| 95 | V4L2_XFER_FUNC_NONE, |
| 96 | V4L2_XFER_FUNC_SRGB, |
| 97 | }; |
| 98 | |
| 99 | if (transfer_characteristics < ARRAY_SIZE(xfer_funcs)) |
| 100 | return xfer_funcs[transfer_characteristics]; |
| 101 | |
| 102 | return V4L2_XFER_FUNC_DEFAULT; /* Reserved */ |
| 103 | } |
| 104 | |
| 105 | static enum v4l2_ycbcr_encoding uvc_ycbcr_enc(const u8 matrix_coefficients) |
| 106 | { |
| 107 | /* |
| 108 | * V4L2 does not currently have definitions for all possible values of |
| 109 | * UVC matrix coefficients. If v4l2_ycbcr_encoding is extended with new |
| 110 | * values, the mapping below should be updated. |
| 111 | * |
| 112 | * Substitutions are taken from the mapping given for |
| 113 | * V4L2_YCBCR_ENC_DEFAULT documented in videodev2.h. |
| 114 | * |
| 115 | * FCC is assumed to be close enough to 601. |
| 116 | */ |
| 117 | static const enum v4l2_ycbcr_encoding ycbcr_encs[] = { |
| 118 | V4L2_YCBCR_ENC_DEFAULT, /* Unspecified */ |
| 119 | V4L2_YCBCR_ENC_709, |
| 120 | V4L2_YCBCR_ENC_601, /* Substitution for FCC */ |
| 121 | V4L2_YCBCR_ENC_601, /* Substitution for BT.470-2 B, G */ |
| 122 | V4L2_YCBCR_ENC_601, |
| 123 | V4L2_YCBCR_ENC_SMPTE240M, |
| 124 | }; |
| 125 | |
| 126 | if (matrix_coefficients < ARRAY_SIZE(ycbcr_encs)) |
| 127 | return ycbcr_encs[matrix_coefficients]; |
| 128 | |
| 129 | return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */ |
| 130 | } |
| 131 | |
| 132 | /* ------------------------------------------------------------------------ |
| 133 | * Terminal and unit management |
| 134 | */ |
| 135 | |
| 136 | struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) |
| 137 | { |
| 138 | struct uvc_entity *entity; |
| 139 | |
| 140 | list_for_each_entry(entity, &dev->entities, list) { |
| 141 | if (entity->id == id) |
| 142 | return entity; |
| 143 | } |
| 144 | |
| 145 | return NULL; |
| 146 | } |
| 147 | |
| 148 | static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev, |
| 149 | int id, struct uvc_entity *entity) |
| 150 | { |
| 151 | unsigned int i; |
| 152 | |
| 153 | if (entity == NULL) |
| 154 | entity = list_entry(&dev->entities, struct uvc_entity, list); |
| 155 | |
| 156 | list_for_each_entry_continue(entity, &dev->entities, list) { |
| 157 | for (i = 0; i < entity->bNrInPins; ++i) |
| 158 | if (entity->baSourceID[i] == id) |
| 159 | return entity; |
| 160 | } |
| 161 | |
| 162 | return NULL; |
| 163 | } |
| 164 | |
| 165 | static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id) |
| 166 | { |
| 167 | struct uvc_streaming *stream; |
| 168 | |
| 169 | list_for_each_entry(stream, &dev->streams, list) { |
| 170 | if (stream->header.bTerminalLink == id) |
| 171 | return stream; |
| 172 | } |
| 173 | |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | /* ------------------------------------------------------------------------ |
| 178 | * Streaming Object Management |
| 179 | */ |
| 180 | |
| 181 | static void uvc_stream_delete(struct uvc_streaming *stream) |
| 182 | { |
| 183 | if (stream->async_wq) |
| 184 | destroy_workqueue(wq: stream->async_wq); |
| 185 | |
| 186 | mutex_destroy(lock: &stream->mutex); |
| 187 | |
| 188 | usb_put_intf(intf: stream->intf); |
| 189 | |
| 190 | kfree(objp: stream->formats); |
| 191 | kfree(objp: stream->header.bmaControls); |
| 192 | kfree(objp: stream); |
| 193 | } |
| 194 | |
| 195 | static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev, |
| 196 | struct usb_interface *intf) |
| 197 | { |
| 198 | struct uvc_streaming *stream; |
| 199 | |
| 200 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
| 201 | if (stream == NULL) |
| 202 | return NULL; |
| 203 | |
| 204 | mutex_init(&stream->mutex); |
| 205 | |
| 206 | stream->dev = dev; |
| 207 | stream->intf = usb_get_intf(intf); |
| 208 | stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; |
| 209 | |
| 210 | /* Allocate a stream specific work queue for asynchronous tasks. */ |
| 211 | stream->async_wq = alloc_workqueue(fmt: "uvcvideo" , flags: WQ_UNBOUND | WQ_HIGHPRI, |
| 212 | max_active: 0); |
| 213 | if (!stream->async_wq) { |
| 214 | uvc_stream_delete(stream); |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | return stream; |
| 219 | } |
| 220 | |
| 221 | /* ------------------------------------------------------------------------ |
| 222 | * Descriptors parsing |
| 223 | */ |
| 224 | |
| 225 | static int uvc_parse_frame(struct uvc_device *dev, |
| 226 | struct uvc_streaming *streaming, |
| 227 | struct uvc_format *format, struct uvc_frame *frame, |
| 228 | u32 **intervals, u8 ftype, int width_multiplier, |
| 229 | const unsigned char *buffer, int buflen) |
| 230 | { |
| 231 | struct usb_host_interface *alts = streaming->intf->cur_altsetting; |
| 232 | unsigned int maxIntervalIndex; |
| 233 | unsigned int interval; |
| 234 | unsigned int i, n; |
| 235 | |
| 236 | if (ftype != UVC_VS_FRAME_FRAME_BASED) |
| 237 | n = buflen > 25 ? buffer[25] : 0; |
| 238 | else |
| 239 | n = buflen > 21 ? buffer[21] : 0; |
| 240 | |
| 241 | n = n ? n : 3; |
| 242 | |
| 243 | if (buflen < 26 + 4 * n) { |
| 244 | uvc_dbg(dev, DESCR, |
| 245 | "device %d videostreaming interface %d FRAME error\n" , |
| 246 | dev->udev->devnum, alts->desc.bInterfaceNumber); |
| 247 | return -EINVAL; |
| 248 | } |
| 249 | |
| 250 | frame->bFrameIndex = buffer[3]; |
| 251 | frame->bmCapabilities = buffer[4]; |
| 252 | frame->wWidth = get_unaligned_le16(p: &buffer[5]) * width_multiplier; |
| 253 | frame->wHeight = get_unaligned_le16(p: &buffer[7]); |
| 254 | frame->dwMinBitRate = get_unaligned_le32(p: &buffer[9]); |
| 255 | frame->dwMaxBitRate = get_unaligned_le32(p: &buffer[13]); |
| 256 | if (ftype != UVC_VS_FRAME_FRAME_BASED) { |
| 257 | frame->dwMaxVideoFrameBufferSize = |
| 258 | get_unaligned_le32(p: &buffer[17]); |
| 259 | frame->dwDefaultFrameInterval = |
| 260 | get_unaligned_le32(p: &buffer[21]); |
| 261 | frame->bFrameIntervalType = buffer[25]; |
| 262 | } else { |
| 263 | frame->dwMaxVideoFrameBufferSize = 0; |
| 264 | frame->dwDefaultFrameInterval = |
| 265 | get_unaligned_le32(p: &buffer[17]); |
| 266 | frame->bFrameIntervalType = buffer[21]; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Copy the frame intervals. |
| 271 | * |
| 272 | * Some bogus devices report dwMinFrameInterval equal to |
| 273 | * dwMaxFrameInterval and have dwFrameIntervalStep set to zero. Setting |
| 274 | * all null intervals to 1 fixes the problem and some other divisions |
| 275 | * by zero that could happen. |
| 276 | */ |
| 277 | frame->dwFrameInterval = *intervals; |
| 278 | |
| 279 | for (i = 0; i < n; ++i) { |
| 280 | interval = get_unaligned_le32(p: &buffer[26 + 4 * i]); |
| 281 | (*intervals)[i] = interval ? interval : 1; |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Apply more fixes, quirks and workarounds to handle incorrect or |
| 286 | * broken descriptors. |
| 287 | */ |
| 288 | |
| 289 | /* |
| 290 | * Several UVC chipsets screw up dwMaxVideoFrameBufferSize completely. |
| 291 | * Observed behaviours range from setting the value to 1.1x the actual |
| 292 | * frame size to hardwiring the 16 low bits to 0. This results in a |
| 293 | * higher than necessary memory usage as well as a wrong image size |
| 294 | * information. For uncompressed formats this can be fixed by computing |
| 295 | * the value from the frame size. |
| 296 | */ |
| 297 | if (!(format->flags & UVC_FMT_FLAG_COMPRESSED)) |
| 298 | frame->dwMaxVideoFrameBufferSize = format->bpp * frame->wWidth |
| 299 | * frame->wHeight / 8; |
| 300 | |
| 301 | /* |
| 302 | * Clamp the default frame interval to the boundaries. A zero |
| 303 | * bFrameIntervalType value indicates a continuous frame interval |
| 304 | * range, with dwFrameInterval[0] storing the minimum value and |
| 305 | * dwFrameInterval[1] storing the maximum value. |
| 306 | */ |
| 307 | maxIntervalIndex = frame->bFrameIntervalType ? n - 1 : 1; |
| 308 | frame->dwDefaultFrameInterval = |
| 309 | clamp(frame->dwDefaultFrameInterval, |
| 310 | frame->dwFrameInterval[0], |
| 311 | frame->dwFrameInterval[maxIntervalIndex]); |
| 312 | |
| 313 | /* |
| 314 | * Some devices report frame intervals that are not functional. If the |
| 315 | * corresponding quirk is set, restrict operation to the first interval |
| 316 | * only. |
| 317 | */ |
| 318 | if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) { |
| 319 | frame->bFrameIntervalType = 1; |
| 320 | (*intervals)[0] = frame->dwDefaultFrameInterval; |
| 321 | } |
| 322 | |
| 323 | uvc_dbg(dev, DESCR, "- %ux%u (%u.%u fps)\n" , |
| 324 | frame->wWidth, frame->wHeight, |
| 325 | 10000000 / frame->dwDefaultFrameInterval, |
| 326 | (100000000 / frame->dwDefaultFrameInterval) % 10); |
| 327 | |
| 328 | *intervals += n; |
| 329 | |
| 330 | return buffer[0]; |
| 331 | } |
| 332 | |
| 333 | static int uvc_parse_format(struct uvc_device *dev, |
| 334 | struct uvc_streaming *streaming, struct uvc_format *format, |
| 335 | struct uvc_frame *frames, u32 **intervals, const unsigned char *buffer, |
| 336 | int buflen) |
| 337 | { |
| 338 | struct usb_host_interface *alts = streaming->intf->cur_altsetting; |
| 339 | const struct uvc_format_desc *fmtdesc; |
| 340 | struct uvc_frame *frame; |
| 341 | const unsigned char *start = buffer; |
| 342 | unsigned int width_multiplier = 1; |
| 343 | unsigned int i, n; |
| 344 | u8 ftype; |
| 345 | int ret; |
| 346 | |
| 347 | format->type = buffer[2]; |
| 348 | format->index = buffer[3]; |
| 349 | format->frames = frames; |
| 350 | |
| 351 | switch (buffer[2]) { |
| 352 | case UVC_VS_FORMAT_UNCOMPRESSED: |
| 353 | case UVC_VS_FORMAT_FRAME_BASED: |
| 354 | n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28; |
| 355 | if (buflen < n) { |
| 356 | uvc_dbg(dev, DESCR, |
| 357 | "device %d videostreaming interface %d FORMAT error\n" , |
| 358 | dev->udev->devnum, |
| 359 | alts->desc.bInterfaceNumber); |
| 360 | return -EINVAL; |
| 361 | } |
| 362 | |
| 363 | /* Find the format descriptor from its GUID. */ |
| 364 | fmtdesc = uvc_format_by_guid(guid: &buffer[5]); |
| 365 | |
| 366 | if (!fmtdesc) { |
| 367 | /* |
| 368 | * Unknown video formats are not fatal errors, the |
| 369 | * caller will skip this descriptor. |
| 370 | */ |
| 371 | dev_info(&streaming->intf->dev, |
| 372 | "Unknown video format %pUl\n" , &buffer[5]); |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | format->fcc = fmtdesc->fcc; |
| 377 | format->bpp = buffer[21]; |
| 378 | |
| 379 | /* |
| 380 | * Some devices report a format that doesn't match what they |
| 381 | * really send. |
| 382 | */ |
| 383 | if (dev->quirks & UVC_QUIRK_FORCE_Y8) { |
| 384 | if (format->fcc == V4L2_PIX_FMT_YUYV) { |
| 385 | format->fcc = V4L2_PIX_FMT_GREY; |
| 386 | format->bpp = 8; |
| 387 | width_multiplier = 2; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /* Some devices report bpp that doesn't match the format. */ |
| 392 | if (dev->quirks & UVC_QUIRK_FORCE_BPP) { |
| 393 | const struct v4l2_format_info *info = |
| 394 | v4l2_format_info(format: format->fcc); |
| 395 | |
| 396 | if (info) { |
| 397 | unsigned int div = info->hdiv * info->vdiv; |
| 398 | |
| 399 | n = info->bpp[0] * div; |
| 400 | for (i = 1; i < info->comp_planes; i++) |
| 401 | n += info->bpp[i]; |
| 402 | |
| 403 | format->bpp = DIV_ROUND_UP(8 * n, div); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) { |
| 408 | ftype = UVC_VS_FRAME_UNCOMPRESSED; |
| 409 | } else { |
| 410 | ftype = UVC_VS_FRAME_FRAME_BASED; |
| 411 | if (buffer[27]) |
| 412 | format->flags = UVC_FMT_FLAG_COMPRESSED; |
| 413 | } |
| 414 | break; |
| 415 | |
| 416 | case UVC_VS_FORMAT_MJPEG: |
| 417 | if (buflen < 11) { |
| 418 | uvc_dbg(dev, DESCR, |
| 419 | "device %d videostreaming interface %d FORMAT error\n" , |
| 420 | dev->udev->devnum, |
| 421 | alts->desc.bInterfaceNumber); |
| 422 | return -EINVAL; |
| 423 | } |
| 424 | |
| 425 | format->fcc = V4L2_PIX_FMT_MJPEG; |
| 426 | format->flags = UVC_FMT_FLAG_COMPRESSED; |
| 427 | format->bpp = 0; |
| 428 | ftype = UVC_VS_FRAME_MJPEG; |
| 429 | break; |
| 430 | |
| 431 | case UVC_VS_FORMAT_DV: |
| 432 | if (buflen < 9) { |
| 433 | uvc_dbg(dev, DESCR, |
| 434 | "device %d videostreaming interface %d FORMAT error\n" , |
| 435 | dev->udev->devnum, |
| 436 | alts->desc.bInterfaceNumber); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
| 440 | if ((buffer[8] & 0x7f) > 2) { |
| 441 | uvc_dbg(dev, DESCR, |
| 442 | "device %d videostreaming interface %d: unknown DV format %u\n" , |
| 443 | dev->udev->devnum, |
| 444 | alts->desc.bInterfaceNumber, buffer[8]); |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | |
| 448 | format->fcc = V4L2_PIX_FMT_DV; |
| 449 | format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM; |
| 450 | format->bpp = 0; |
| 451 | ftype = 0; |
| 452 | |
| 453 | /* Create a dummy frame descriptor. */ |
| 454 | frame = &frames[0]; |
| 455 | memset(frame, 0, sizeof(*frame)); |
| 456 | frame->bFrameIntervalType = 1; |
| 457 | frame->dwDefaultFrameInterval = 1; |
| 458 | frame->dwFrameInterval = *intervals; |
| 459 | *(*intervals)++ = 1; |
| 460 | format->nframes = 1; |
| 461 | break; |
| 462 | |
| 463 | case UVC_VS_FORMAT_MPEG2TS: |
| 464 | case UVC_VS_FORMAT_STREAM_BASED: |
| 465 | /* Not supported yet. */ |
| 466 | default: |
| 467 | uvc_dbg(dev, DESCR, |
| 468 | "device %d videostreaming interface %d unsupported format %u\n" , |
| 469 | dev->udev->devnum, alts->desc.bInterfaceNumber, |
| 470 | buffer[2]); |
| 471 | return -EINVAL; |
| 472 | } |
| 473 | |
| 474 | uvc_dbg(dev, DESCR, "Found format %p4cc" , &format->fcc); |
| 475 | |
| 476 | buflen -= buffer[0]; |
| 477 | buffer += buffer[0]; |
| 478 | |
| 479 | /* |
| 480 | * Parse the frame descriptors. Only uncompressed, MJPEG and frame |
| 481 | * based formats have frame descriptors. |
| 482 | */ |
| 483 | if (ftype) { |
| 484 | while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE && |
| 485 | buffer[2] == ftype) { |
| 486 | frame = &frames[format->nframes]; |
| 487 | ret = uvc_parse_frame(dev, streaming, format, frame, |
| 488 | intervals, ftype, width_multiplier, |
| 489 | buffer, buflen); |
| 490 | if (ret < 0) |
| 491 | return ret; |
| 492 | format->nframes++; |
| 493 | buflen -= ret; |
| 494 | buffer += ret; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE && |
| 499 | buffer[2] == UVC_VS_STILL_IMAGE_FRAME) { |
| 500 | buflen -= buffer[0]; |
| 501 | buffer += buffer[0]; |
| 502 | } |
| 503 | |
| 504 | if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE && |
| 505 | buffer[2] == UVC_VS_COLORFORMAT) { |
| 506 | if (buflen < 6) { |
| 507 | uvc_dbg(dev, DESCR, |
| 508 | "device %d videostreaming interface %d COLORFORMAT error\n" , |
| 509 | dev->udev->devnum, |
| 510 | alts->desc.bInterfaceNumber); |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | |
| 514 | format->colorspace = uvc_colorspace(primaries: buffer[3]); |
| 515 | format->xfer_func = uvc_xfer_func(transfer_characteristics: buffer[4]); |
| 516 | format->ycbcr_enc = uvc_ycbcr_enc(matrix_coefficients: buffer[5]); |
| 517 | |
| 518 | buflen -= buffer[0]; |
| 519 | buffer += buffer[0]; |
| 520 | } else { |
| 521 | format->colorspace = V4L2_COLORSPACE_SRGB; |
| 522 | } |
| 523 | |
| 524 | return buffer - start; |
| 525 | } |
| 526 | |
| 527 | static int uvc_parse_streaming(struct uvc_device *dev, |
| 528 | struct usb_interface *intf) |
| 529 | { |
| 530 | struct uvc_streaming *streaming = NULL; |
| 531 | struct uvc_format *format; |
| 532 | struct uvc_frame *frame; |
| 533 | struct usb_host_interface *alts = &intf->altsetting[0]; |
| 534 | const unsigned char *_buffer, *buffer = alts->extra; |
| 535 | int _buflen, buflen = alts->extralen; |
| 536 | unsigned int nformats = 0, nframes = 0, nintervals = 0; |
| 537 | unsigned int size, i, n, p; |
| 538 | u32 *interval; |
| 539 | u16 psize; |
| 540 | int ret = -EINVAL; |
| 541 | |
| 542 | if (intf->cur_altsetting->desc.bInterfaceSubClass |
| 543 | != UVC_SC_VIDEOSTREAMING) { |
| 544 | uvc_dbg(dev, DESCR, |
| 545 | "device %d interface %d isn't a video streaming interface\n" , |
| 546 | dev->udev->devnum, |
| 547 | intf->altsetting[0].desc.bInterfaceNumber); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
| 551 | if (usb_driver_claim_interface(driver: &uvc_driver, iface: intf, data: dev)) { |
| 552 | uvc_dbg(dev, DESCR, |
| 553 | "device %d interface %d is already claimed\n" , |
| 554 | dev->udev->devnum, |
| 555 | intf->altsetting[0].desc.bInterfaceNumber); |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | streaming = uvc_stream_new(dev, intf); |
| 560 | if (streaming == NULL) { |
| 561 | usb_driver_release_interface(driver: &uvc_driver, iface: intf); |
| 562 | return -ENOMEM; |
| 563 | } |
| 564 | |
| 565 | /* |
| 566 | * The Pico iMage webcam has its class-specific interface descriptors |
| 567 | * after the endpoint descriptors. |
| 568 | */ |
| 569 | if (buflen == 0) { |
| 570 | for (i = 0; i < alts->desc.bNumEndpoints; ++i) { |
| 571 | struct usb_host_endpoint *ep = &alts->endpoint[i]; |
| 572 | |
| 573 | if (ep->extralen == 0) |
| 574 | continue; |
| 575 | |
| 576 | if (ep->extralen > 2 && |
| 577 | ep->extra[1] == USB_DT_CS_INTERFACE) { |
| 578 | uvc_dbg(dev, DESCR, |
| 579 | "trying extra data from endpoint %u\n" , |
| 580 | i); |
| 581 | buffer = alts->endpoint[i].extra; |
| 582 | buflen = alts->endpoint[i].extralen; |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | /* Skip the standard interface descriptors. */ |
| 589 | while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) { |
| 590 | buflen -= buffer[0]; |
| 591 | buffer += buffer[0]; |
| 592 | } |
| 593 | |
| 594 | if (buflen <= 2) { |
| 595 | uvc_dbg(dev, DESCR, |
| 596 | "no class-specific streaming interface descriptors found\n" ); |
| 597 | goto error; |
| 598 | } |
| 599 | |
| 600 | /* Parse the header descriptor. */ |
| 601 | switch (buffer[2]) { |
| 602 | case UVC_VS_OUTPUT_HEADER: |
| 603 | streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 604 | size = 9; |
| 605 | break; |
| 606 | |
| 607 | case UVC_VS_INPUT_HEADER: |
| 608 | streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 609 | size = 13; |
| 610 | break; |
| 611 | |
| 612 | default: |
| 613 | uvc_dbg(dev, DESCR, |
| 614 | "device %d videostreaming interface %d HEADER descriptor not found\n" , |
| 615 | dev->udev->devnum, alts->desc.bInterfaceNumber); |
| 616 | goto error; |
| 617 | } |
| 618 | |
| 619 | p = buflen >= 4 ? buffer[3] : 0; |
| 620 | n = buflen >= size ? buffer[size-1] : 0; |
| 621 | |
| 622 | if (buflen < size + p*n) { |
| 623 | uvc_dbg(dev, DESCR, |
| 624 | "device %d videostreaming interface %d HEADER descriptor is invalid\n" , |
| 625 | dev->udev->devnum, alts->desc.bInterfaceNumber); |
| 626 | goto error; |
| 627 | } |
| 628 | |
| 629 | streaming->header.bNumFormats = p; |
| 630 | streaming->header.bEndpointAddress = buffer[6]; |
| 631 | if (buffer[2] == UVC_VS_INPUT_HEADER) { |
| 632 | streaming->header.bmInfo = buffer[7]; |
| 633 | streaming->header.bTerminalLink = buffer[8]; |
| 634 | streaming->header.bStillCaptureMethod = buffer[9]; |
| 635 | streaming->header.bTriggerSupport = buffer[10]; |
| 636 | streaming->header.bTriggerUsage = buffer[11]; |
| 637 | } else { |
| 638 | streaming->header.bTerminalLink = buffer[7]; |
| 639 | } |
| 640 | streaming->header.bControlSize = n; |
| 641 | |
| 642 | streaming->header.bmaControls = kmemdup(&buffer[size], p * n, |
| 643 | GFP_KERNEL); |
| 644 | if (streaming->header.bmaControls == NULL) { |
| 645 | ret = -ENOMEM; |
| 646 | goto error; |
| 647 | } |
| 648 | |
| 649 | buflen -= buffer[0]; |
| 650 | buffer += buffer[0]; |
| 651 | |
| 652 | _buffer = buffer; |
| 653 | _buflen = buflen; |
| 654 | |
| 655 | /* Count the format and frame descriptors. */ |
| 656 | while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) { |
| 657 | switch (_buffer[2]) { |
| 658 | case UVC_VS_FORMAT_UNCOMPRESSED: |
| 659 | case UVC_VS_FORMAT_MJPEG: |
| 660 | case UVC_VS_FORMAT_FRAME_BASED: |
| 661 | nformats++; |
| 662 | break; |
| 663 | |
| 664 | case UVC_VS_FORMAT_DV: |
| 665 | /* |
| 666 | * DV format has no frame descriptor. We will create a |
| 667 | * dummy frame descriptor with a dummy frame interval. |
| 668 | */ |
| 669 | nformats++; |
| 670 | nframes++; |
| 671 | nintervals++; |
| 672 | break; |
| 673 | |
| 674 | case UVC_VS_FORMAT_MPEG2TS: |
| 675 | case UVC_VS_FORMAT_STREAM_BASED: |
| 676 | uvc_dbg(dev, DESCR, |
| 677 | "device %d videostreaming interface %d FORMAT %u is not supported\n" , |
| 678 | dev->udev->devnum, |
| 679 | alts->desc.bInterfaceNumber, _buffer[2]); |
| 680 | break; |
| 681 | |
| 682 | case UVC_VS_FRAME_UNCOMPRESSED: |
| 683 | case UVC_VS_FRAME_MJPEG: |
| 684 | nframes++; |
| 685 | if (_buflen > 25) |
| 686 | nintervals += _buffer[25] ? _buffer[25] : 3; |
| 687 | break; |
| 688 | |
| 689 | case UVC_VS_FRAME_FRAME_BASED: |
| 690 | nframes++; |
| 691 | if (_buflen > 21) |
| 692 | nintervals += _buffer[21] ? _buffer[21] : 3; |
| 693 | break; |
| 694 | } |
| 695 | |
| 696 | _buflen -= _buffer[0]; |
| 697 | _buffer += _buffer[0]; |
| 698 | } |
| 699 | |
| 700 | if (nformats == 0) { |
| 701 | uvc_dbg(dev, DESCR, |
| 702 | "device %d videostreaming interface %d has no supported formats defined\n" , |
| 703 | dev->udev->devnum, alts->desc.bInterfaceNumber); |
| 704 | goto error; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * Allocate memory for the formats, the frames and the intervals, |
| 709 | * plus any required padding to guarantee that everything has the |
| 710 | * correct alignment. |
| 711 | */ |
| 712 | size = nformats * sizeof(*format); |
| 713 | size = ALIGN(size, __alignof__(*frame)) + nframes * sizeof(*frame); |
| 714 | size = ALIGN(size, __alignof__(*interval)) |
| 715 | + nintervals * sizeof(*interval); |
| 716 | |
| 717 | format = kzalloc(size, GFP_KERNEL); |
| 718 | if (!format) { |
| 719 | ret = -ENOMEM; |
| 720 | goto error; |
| 721 | } |
| 722 | |
| 723 | frame = (void *)format + nformats * sizeof(*format); |
| 724 | frame = PTR_ALIGN(frame, __alignof__(*frame)); |
| 725 | interval = (void *)frame + nframes * sizeof(*frame); |
| 726 | interval = PTR_ALIGN(interval, __alignof__(*interval)); |
| 727 | |
| 728 | streaming->formats = format; |
| 729 | streaming->nformats = 0; |
| 730 | |
| 731 | /* Parse the format descriptors. */ |
| 732 | while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) { |
| 733 | switch (buffer[2]) { |
| 734 | case UVC_VS_FORMAT_UNCOMPRESSED: |
| 735 | case UVC_VS_FORMAT_MJPEG: |
| 736 | case UVC_VS_FORMAT_DV: |
| 737 | case UVC_VS_FORMAT_FRAME_BASED: |
| 738 | ret = uvc_parse_format(dev, streaming, format, frames: frame, |
| 739 | intervals: &interval, buffer, buflen); |
| 740 | if (ret < 0) |
| 741 | goto error; |
| 742 | if (!ret) |
| 743 | break; |
| 744 | |
| 745 | streaming->nformats++; |
| 746 | frame += format->nframes; |
| 747 | format++; |
| 748 | |
| 749 | buflen -= ret; |
| 750 | buffer += ret; |
| 751 | continue; |
| 752 | |
| 753 | default: |
| 754 | break; |
| 755 | } |
| 756 | |
| 757 | buflen -= buffer[0]; |
| 758 | buffer += buffer[0]; |
| 759 | } |
| 760 | |
| 761 | if (buflen) |
| 762 | uvc_dbg(dev, DESCR, |
| 763 | "device %d videostreaming interface %d has %u bytes of trailing descriptor garbage\n" , |
| 764 | dev->udev->devnum, alts->desc.bInterfaceNumber, buflen); |
| 765 | |
| 766 | /* Parse the alternate settings to find the maximum bandwidth. */ |
| 767 | for (i = 0; i < intf->num_altsetting; ++i) { |
| 768 | struct usb_host_endpoint *ep; |
| 769 | |
| 770 | alts = &intf->altsetting[i]; |
| 771 | ep = uvc_find_endpoint(alts, |
| 772 | epaddr: streaming->header.bEndpointAddress); |
| 773 | if (ep == NULL) |
| 774 | continue; |
| 775 | psize = uvc_endpoint_max_bpi(dev: dev->udev, ep); |
| 776 | if (psize > streaming->maxpsize) |
| 777 | streaming->maxpsize = psize; |
| 778 | } |
| 779 | |
| 780 | list_add_tail(new: &streaming->list, head: &dev->streams); |
| 781 | return 0; |
| 782 | |
| 783 | error: |
| 784 | usb_driver_release_interface(driver: &uvc_driver, iface: intf); |
| 785 | uvc_stream_delete(stream: streaming); |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; |
| 790 | static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER; |
| 791 | static const u8 uvc_media_transport_input_guid[16] = |
| 792 | UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; |
| 793 | static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; |
| 794 | |
| 795 | static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, |
| 796 | unsigned int num_pads, unsigned int ) |
| 797 | { |
| 798 | struct uvc_entity *entity; |
| 799 | unsigned int num_inputs; |
| 800 | unsigned int size; |
| 801 | unsigned int i; |
| 802 | |
| 803 | extra_size = roundup(extra_size, sizeof(*entity->pads)); |
| 804 | if (num_pads) |
| 805 | num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1; |
| 806 | else |
| 807 | num_inputs = 0; |
| 808 | size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads |
| 809 | + num_inputs; |
| 810 | entity = kzalloc(size, GFP_KERNEL); |
| 811 | if (entity == NULL) |
| 812 | return NULL; |
| 813 | |
| 814 | entity->id = id; |
| 815 | entity->type = type; |
| 816 | |
| 817 | /* |
| 818 | * Set the GUID for standard entity types. For extension units, the GUID |
| 819 | * is initialized by the caller. |
| 820 | */ |
| 821 | switch (type) { |
| 822 | case UVC_EXT_GPIO_UNIT: |
| 823 | memcpy(entity->guid, uvc_gpio_guid, 16); |
| 824 | break; |
| 825 | case UVC_ITT_CAMERA: |
| 826 | memcpy(entity->guid, uvc_camera_guid, 16); |
| 827 | break; |
| 828 | case UVC_ITT_MEDIA_TRANSPORT_INPUT: |
| 829 | memcpy(entity->guid, uvc_media_transport_input_guid, 16); |
| 830 | break; |
| 831 | case UVC_VC_PROCESSING_UNIT: |
| 832 | memcpy(entity->guid, uvc_processing_guid, 16); |
| 833 | break; |
| 834 | } |
| 835 | |
| 836 | entity->num_links = 0; |
| 837 | entity->num_pads = num_pads; |
| 838 | entity->pads = ((void *)(entity + 1)) + extra_size; |
| 839 | |
| 840 | for (i = 0; i < num_inputs; ++i) |
| 841 | entity->pads[i].flags = MEDIA_PAD_FL_SINK; |
| 842 | if (!UVC_ENTITY_IS_OTERM(entity) && num_pads) |
| 843 | entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE; |
| 844 | |
| 845 | entity->bNrInPins = num_inputs; |
| 846 | entity->baSourceID = (u8 *)(&entity->pads[num_pads]); |
| 847 | |
| 848 | return entity; |
| 849 | } |
| 850 | |
| 851 | static void uvc_entity_set_name(struct uvc_device *dev, struct uvc_entity *entity, |
| 852 | const char *type_name, u8 string_id) |
| 853 | { |
| 854 | int ret; |
| 855 | |
| 856 | /* |
| 857 | * First attempt to read the entity name from the device. If the entity |
| 858 | * has no associated string, or if reading the string fails (most |
| 859 | * likely due to a buggy firmware), fall back to default names based on |
| 860 | * the entity type. |
| 861 | */ |
| 862 | if (string_id) { |
| 863 | ret = usb_string(dev: dev->udev, index: string_id, buf: entity->name, |
| 864 | size: sizeof(entity->name)); |
| 865 | if (!ret) |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | sprintf(buf: entity->name, fmt: "%s %u" , type_name, entity->id); |
| 870 | } |
| 871 | |
| 872 | /* Parse vendor-specific extensions. */ |
| 873 | static int uvc_parse_vendor_control(struct uvc_device *dev, |
| 874 | const unsigned char *buffer, int buflen) |
| 875 | { |
| 876 | struct usb_device *udev = dev->udev; |
| 877 | struct usb_host_interface *alts = dev->intf->cur_altsetting; |
| 878 | struct uvc_entity *unit; |
| 879 | unsigned int n, p; |
| 880 | int handled = 0; |
| 881 | |
| 882 | switch (le16_to_cpu(dev->udev->descriptor.idVendor)) { |
| 883 | case 0x046d: /* Logitech */ |
| 884 | if (buffer[1] != 0x41 || buffer[2] != 0x01) |
| 885 | break; |
| 886 | |
| 887 | /* |
| 888 | * Logitech implements several vendor specific functions |
| 889 | * through vendor specific extension units (LXU). |
| 890 | * |
| 891 | * The LXU descriptors are similar to XU descriptors |
| 892 | * (see "USB Device Video Class for Video Devices", section |
| 893 | * 3.7.2.6 "Extension Unit Descriptor") with the following |
| 894 | * differences: |
| 895 | * |
| 896 | * ---------------------------------------------------------- |
| 897 | * 0 bLength 1 Number |
| 898 | * Size of this descriptor, in bytes: 24+p+n*2 |
| 899 | * ---------------------------------------------------------- |
| 900 | * 23+p+n bmControlsType N Bitmap |
| 901 | * Individual bits in the set are defined: |
| 902 | * 0: Absolute |
| 903 | * 1: Relative |
| 904 | * |
| 905 | * This bitset is mapped exactly the same as bmControls. |
| 906 | * ---------------------------------------------------------- |
| 907 | * 23+p+n*2 bReserved 1 Boolean |
| 908 | * ---------------------------------------------------------- |
| 909 | * 24+p+n*2 iExtension 1 Index |
| 910 | * Index of a string descriptor that describes this |
| 911 | * extension unit. |
| 912 | * ---------------------------------------------------------- |
| 913 | */ |
| 914 | p = buflen >= 22 ? buffer[21] : 0; |
| 915 | n = buflen >= 25 + p ? buffer[22+p] : 0; |
| 916 | |
| 917 | if (buflen < 25 + p + 2*n) { |
| 918 | uvc_dbg(dev, DESCR, |
| 919 | "device %d videocontrol interface %d EXTENSION_UNIT error\n" , |
| 920 | udev->devnum, alts->desc.bInterfaceNumber); |
| 921 | break; |
| 922 | } |
| 923 | |
| 924 | unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, id: buffer[3], |
| 925 | num_pads: p + 1, extra_size: 2*n); |
| 926 | if (unit == NULL) |
| 927 | return -ENOMEM; |
| 928 | |
| 929 | memcpy(unit->guid, &buffer[4], 16); |
| 930 | unit->extension.bNumControls = buffer[20]; |
| 931 | memcpy(unit->baSourceID, &buffer[22], p); |
| 932 | unit->extension.bControlSize = buffer[22+p]; |
| 933 | unit->extension.bmControls = (u8 *)unit + sizeof(*unit); |
| 934 | unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit) |
| 935 | + n; |
| 936 | memcpy(unit->extension.bmControls, &buffer[23+p], 2*n); |
| 937 | |
| 938 | uvc_entity_set_name(dev, entity: unit, type_name: "Extension" , string_id: buffer[24+p+2*n]); |
| 939 | |
| 940 | list_add_tail(new: &unit->list, head: &dev->entities); |
| 941 | handled = 1; |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | return handled; |
| 946 | } |
| 947 | |
| 948 | static int uvc_parse_standard_control(struct uvc_device *dev, |
| 949 | const unsigned char *buffer, int buflen) |
| 950 | { |
| 951 | struct usb_device *udev = dev->udev; |
| 952 | struct uvc_entity *unit, *term; |
| 953 | struct usb_interface *intf; |
| 954 | struct usb_host_interface *alts = dev->intf->cur_altsetting; |
| 955 | unsigned int i, n, p, len; |
| 956 | const char *type_name; |
| 957 | u16 type; |
| 958 | |
| 959 | switch (buffer[2]) { |
| 960 | case UVC_VC_HEADER: |
| 961 | n = buflen >= 12 ? buffer[11] : 0; |
| 962 | |
| 963 | if (buflen < 12 + n) { |
| 964 | uvc_dbg(dev, DESCR, |
| 965 | "device %d videocontrol interface %d HEADER error\n" , |
| 966 | udev->devnum, alts->desc.bInterfaceNumber); |
| 967 | return -EINVAL; |
| 968 | } |
| 969 | |
| 970 | dev->uvc_version = get_unaligned_le16(p: &buffer[3]); |
| 971 | dev->clock_frequency = get_unaligned_le32(p: &buffer[7]); |
| 972 | |
| 973 | /* Parse all USB Video Streaming interfaces. */ |
| 974 | for (i = 0; i < n; ++i) { |
| 975 | intf = usb_ifnum_to_if(dev: udev, ifnum: buffer[12+i]); |
| 976 | if (intf == NULL) { |
| 977 | uvc_dbg(dev, DESCR, |
| 978 | "device %d interface %d doesn't exists\n" , |
| 979 | udev->devnum, i); |
| 980 | continue; |
| 981 | } |
| 982 | |
| 983 | uvc_parse_streaming(dev, intf); |
| 984 | } |
| 985 | break; |
| 986 | |
| 987 | case UVC_VC_INPUT_TERMINAL: |
| 988 | if (buflen < 8) { |
| 989 | uvc_dbg(dev, DESCR, |
| 990 | "device %d videocontrol interface %d INPUT_TERMINAL error\n" , |
| 991 | udev->devnum, alts->desc.bInterfaceNumber); |
| 992 | return -EINVAL; |
| 993 | } |
| 994 | |
| 995 | /* |
| 996 | * Reject invalid terminal types that would cause issues: |
| 997 | * |
| 998 | * - The high byte must be non-zero, otherwise it would be |
| 999 | * confused with a unit. |
| 1000 | * |
| 1001 | * - Bit 15 must be 0, as we use it internally as a terminal |
| 1002 | * direction flag. |
| 1003 | * |
| 1004 | * Other unknown types are accepted. |
| 1005 | */ |
| 1006 | type = get_unaligned_le16(p: &buffer[4]); |
| 1007 | if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) { |
| 1008 | uvc_dbg(dev, DESCR, |
| 1009 | "device %d videocontrol interface %d INPUT_TERMINAL %d has invalid type 0x%04x, skipping\n" , |
| 1010 | udev->devnum, alts->desc.bInterfaceNumber, |
| 1011 | buffer[3], type); |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | n = 0; |
| 1016 | p = 0; |
| 1017 | len = 8; |
| 1018 | |
| 1019 | if (type == UVC_ITT_CAMERA) { |
| 1020 | n = buflen >= 15 ? buffer[14] : 0; |
| 1021 | len = 15; |
| 1022 | |
| 1023 | } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) { |
| 1024 | n = buflen >= 9 ? buffer[8] : 0; |
| 1025 | p = buflen >= 10 + n ? buffer[9+n] : 0; |
| 1026 | len = 10; |
| 1027 | } |
| 1028 | |
| 1029 | if (buflen < len + n + p) { |
| 1030 | uvc_dbg(dev, DESCR, |
| 1031 | "device %d videocontrol interface %d INPUT_TERMINAL error\n" , |
| 1032 | udev->devnum, alts->desc.bInterfaceNumber); |
| 1033 | return -EINVAL; |
| 1034 | } |
| 1035 | |
| 1036 | term = uvc_alloc_entity(type: type | UVC_TERM_INPUT, id: buffer[3], |
| 1037 | num_pads: 1, extra_size: n + p); |
| 1038 | if (term == NULL) |
| 1039 | return -ENOMEM; |
| 1040 | |
| 1041 | if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) { |
| 1042 | term->camera.bControlSize = n; |
| 1043 | term->camera.bmControls = (u8 *)term + sizeof(*term); |
| 1044 | term->camera.wObjectiveFocalLengthMin = |
| 1045 | get_unaligned_le16(p: &buffer[8]); |
| 1046 | term->camera.wObjectiveFocalLengthMax = |
| 1047 | get_unaligned_le16(p: &buffer[10]); |
| 1048 | term->camera.wOcularFocalLength = |
| 1049 | get_unaligned_le16(p: &buffer[12]); |
| 1050 | memcpy(term->camera.bmControls, &buffer[15], n); |
| 1051 | } else if (UVC_ENTITY_TYPE(term) == |
| 1052 | UVC_ITT_MEDIA_TRANSPORT_INPUT) { |
| 1053 | term->media.bControlSize = n; |
| 1054 | term->media.bmControls = (u8 *)term + sizeof(*term); |
| 1055 | term->media.bTransportModeSize = p; |
| 1056 | term->media.bmTransportModes = (u8 *)term |
| 1057 | + sizeof(*term) + n; |
| 1058 | memcpy(term->media.bmControls, &buffer[9], n); |
| 1059 | memcpy(term->media.bmTransportModes, &buffer[10+n], p); |
| 1060 | } |
| 1061 | |
| 1062 | if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) |
| 1063 | type_name = "Camera" ; |
| 1064 | else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT) |
| 1065 | type_name = "Media" ; |
| 1066 | else |
| 1067 | type_name = "Input" ; |
| 1068 | |
| 1069 | uvc_entity_set_name(dev, entity: term, type_name, string_id: buffer[7]); |
| 1070 | |
| 1071 | list_add_tail(new: &term->list, head: &dev->entities); |
| 1072 | break; |
| 1073 | |
| 1074 | case UVC_VC_OUTPUT_TERMINAL: |
| 1075 | if (buflen < 9) { |
| 1076 | uvc_dbg(dev, DESCR, |
| 1077 | "device %d videocontrol interface %d OUTPUT_TERMINAL error\n" , |
| 1078 | udev->devnum, alts->desc.bInterfaceNumber); |
| 1079 | return -EINVAL; |
| 1080 | } |
| 1081 | |
| 1082 | /* |
| 1083 | * Make sure the terminal type MSB is not null, otherwise it |
| 1084 | * could be confused with a unit. |
| 1085 | */ |
| 1086 | type = get_unaligned_le16(p: &buffer[4]); |
| 1087 | if ((type & 0xff00) == 0) { |
| 1088 | uvc_dbg(dev, DESCR, |
| 1089 | "device %d videocontrol interface %d OUTPUT_TERMINAL %d has invalid type 0x%04x, skipping\n" , |
| 1090 | udev->devnum, alts->desc.bInterfaceNumber, |
| 1091 | buffer[3], type); |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | term = uvc_alloc_entity(type: type | UVC_TERM_OUTPUT, id: buffer[3], |
| 1096 | num_pads: 1, extra_size: 0); |
| 1097 | if (term == NULL) |
| 1098 | return -ENOMEM; |
| 1099 | |
| 1100 | memcpy(term->baSourceID, &buffer[7], 1); |
| 1101 | |
| 1102 | uvc_entity_set_name(dev, entity: term, type_name: "Output" , string_id: buffer[8]); |
| 1103 | |
| 1104 | list_add_tail(new: &term->list, head: &dev->entities); |
| 1105 | break; |
| 1106 | |
| 1107 | case UVC_VC_SELECTOR_UNIT: |
| 1108 | p = buflen >= 5 ? buffer[4] : 0; |
| 1109 | |
| 1110 | if (buflen < 5 || buflen < 6 + p) { |
| 1111 | uvc_dbg(dev, DESCR, |
| 1112 | "device %d videocontrol interface %d SELECTOR_UNIT error\n" , |
| 1113 | udev->devnum, alts->desc.bInterfaceNumber); |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | |
| 1117 | unit = uvc_alloc_entity(type: buffer[2], id: buffer[3], num_pads: p + 1, extra_size: 0); |
| 1118 | if (unit == NULL) |
| 1119 | return -ENOMEM; |
| 1120 | |
| 1121 | memcpy(unit->baSourceID, &buffer[5], p); |
| 1122 | |
| 1123 | uvc_entity_set_name(dev, entity: unit, type_name: "Selector" , string_id: buffer[5+p]); |
| 1124 | |
| 1125 | list_add_tail(new: &unit->list, head: &dev->entities); |
| 1126 | break; |
| 1127 | |
| 1128 | case UVC_VC_PROCESSING_UNIT: |
| 1129 | n = buflen >= 8 ? buffer[7] : 0; |
| 1130 | p = dev->uvc_version >= 0x0110 ? 10 : 9; |
| 1131 | |
| 1132 | if (buflen < p + n) { |
| 1133 | uvc_dbg(dev, DESCR, |
| 1134 | "device %d videocontrol interface %d PROCESSING_UNIT error\n" , |
| 1135 | udev->devnum, alts->desc.bInterfaceNumber); |
| 1136 | return -EINVAL; |
| 1137 | } |
| 1138 | |
| 1139 | unit = uvc_alloc_entity(type: buffer[2], id: buffer[3], num_pads: 2, extra_size: n); |
| 1140 | if (unit == NULL) |
| 1141 | return -ENOMEM; |
| 1142 | |
| 1143 | memcpy(unit->baSourceID, &buffer[4], 1); |
| 1144 | unit->processing.wMaxMultiplier = |
| 1145 | get_unaligned_le16(p: &buffer[5]); |
| 1146 | unit->processing.bControlSize = buffer[7]; |
| 1147 | unit->processing.bmControls = (u8 *)unit + sizeof(*unit); |
| 1148 | memcpy(unit->processing.bmControls, &buffer[8], n); |
| 1149 | if (dev->uvc_version >= 0x0110) |
| 1150 | unit->processing.bmVideoStandards = buffer[9+n]; |
| 1151 | |
| 1152 | uvc_entity_set_name(dev, entity: unit, type_name: "Processing" , string_id: buffer[8+n]); |
| 1153 | |
| 1154 | list_add_tail(new: &unit->list, head: &dev->entities); |
| 1155 | break; |
| 1156 | |
| 1157 | case UVC_VC_EXTENSION_UNIT: |
| 1158 | p = buflen >= 22 ? buffer[21] : 0; |
| 1159 | n = buflen >= 24 + p ? buffer[22+p] : 0; |
| 1160 | |
| 1161 | if (buflen < 24 + p + n) { |
| 1162 | uvc_dbg(dev, DESCR, |
| 1163 | "device %d videocontrol interface %d EXTENSION_UNIT error\n" , |
| 1164 | udev->devnum, alts->desc.bInterfaceNumber); |
| 1165 | return -EINVAL; |
| 1166 | } |
| 1167 | |
| 1168 | unit = uvc_alloc_entity(type: buffer[2], id: buffer[3], num_pads: p + 1, extra_size: n); |
| 1169 | if (unit == NULL) |
| 1170 | return -ENOMEM; |
| 1171 | |
| 1172 | memcpy(unit->guid, &buffer[4], 16); |
| 1173 | unit->extension.bNumControls = buffer[20]; |
| 1174 | memcpy(unit->baSourceID, &buffer[22], p); |
| 1175 | unit->extension.bControlSize = buffer[22+p]; |
| 1176 | unit->extension.bmControls = (u8 *)unit + sizeof(*unit); |
| 1177 | memcpy(unit->extension.bmControls, &buffer[23+p], n); |
| 1178 | |
| 1179 | uvc_entity_set_name(dev, entity: unit, type_name: "Extension" , string_id: buffer[23+p+n]); |
| 1180 | |
| 1181 | list_add_tail(new: &unit->list, head: &dev->entities); |
| 1182 | break; |
| 1183 | |
| 1184 | default: |
| 1185 | uvc_dbg(dev, DESCR, |
| 1186 | "Found an unknown CS_INTERFACE descriptor (%u)\n" , |
| 1187 | buffer[2]); |
| 1188 | break; |
| 1189 | } |
| 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | static int uvc_parse_control(struct uvc_device *dev) |
| 1195 | { |
| 1196 | struct usb_host_interface *alts = dev->intf->cur_altsetting; |
| 1197 | const unsigned char *buffer = alts->extra; |
| 1198 | int buflen = alts->extralen; |
| 1199 | int ret; |
| 1200 | |
| 1201 | /* |
| 1202 | * Parse the default alternate setting only, as the UVC specification |
| 1203 | * defines a single alternate setting, the default alternate setting |
| 1204 | * zero. |
| 1205 | */ |
| 1206 | |
| 1207 | while (buflen > 2) { |
| 1208 | if (uvc_parse_vendor_control(dev, buffer, buflen) || |
| 1209 | buffer[1] != USB_DT_CS_INTERFACE) |
| 1210 | goto next_descriptor; |
| 1211 | |
| 1212 | ret = uvc_parse_standard_control(dev, buffer, buflen); |
| 1213 | if (ret < 0) |
| 1214 | return ret; |
| 1215 | |
| 1216 | next_descriptor: |
| 1217 | buflen -= buffer[0]; |
| 1218 | buffer += buffer[0]; |
| 1219 | } |
| 1220 | |
| 1221 | /* |
| 1222 | * Check if the optional status endpoint is present. Built-in iSight |
| 1223 | * webcams have an interrupt endpoint but spit proprietary data that |
| 1224 | * don't conform to the UVC status endpoint messages. Don't try to |
| 1225 | * handle the interrupt endpoint for those cameras. |
| 1226 | */ |
| 1227 | if (alts->desc.bNumEndpoints == 1 && |
| 1228 | !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) { |
| 1229 | struct usb_host_endpoint *ep = &alts->endpoint[0]; |
| 1230 | struct usb_endpoint_descriptor *desc = &ep->desc; |
| 1231 | |
| 1232 | if (usb_endpoint_is_int_in(epd: desc) && |
| 1233 | le16_to_cpu(desc->wMaxPacketSize) >= 8 && |
| 1234 | desc->bInterval != 0) { |
| 1235 | uvc_dbg(dev, DESCR, |
| 1236 | "Found a Status endpoint (addr %02x)\n" , |
| 1237 | desc->bEndpointAddress); |
| 1238 | dev->int_ep = ep; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
| 1245 | /* ----------------------------------------------------------------------------- |
| 1246 | * Privacy GPIO |
| 1247 | */ |
| 1248 | |
| 1249 | static void uvc_gpio_event(struct uvc_device *dev) |
| 1250 | { |
| 1251 | struct uvc_entity *unit = dev->gpio_unit; |
| 1252 | struct uvc_video_chain *chain; |
| 1253 | u8 new_val; |
| 1254 | |
| 1255 | if (!unit) |
| 1256 | return; |
| 1257 | |
| 1258 | new_val = gpiod_get_value_cansleep(desc: unit->gpio.gpio_privacy); |
| 1259 | |
| 1260 | /* GPIO entities are always on the first chain. */ |
| 1261 | chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); |
| 1262 | uvc_ctrl_status_event(chain, ctrl: unit->controls, data: &new_val); |
| 1263 | } |
| 1264 | |
| 1265 | static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity, |
| 1266 | u8 cs, void *data, u16 size) |
| 1267 | { |
| 1268 | if (cs != UVC_CT_PRIVACY_CONTROL || size < 1) |
| 1269 | return -EINVAL; |
| 1270 | |
| 1271 | *(u8 *)data = gpiod_get_value_cansleep(desc: entity->gpio.gpio_privacy); |
| 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity, |
| 1277 | u8 cs, u8 *caps) |
| 1278 | { |
| 1279 | if (cs != UVC_CT_PRIVACY_CONTROL) |
| 1280 | return -EINVAL; |
| 1281 | |
| 1282 | *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | static irqreturn_t uvc_gpio_irq(int irq, void *data) |
| 1287 | { |
| 1288 | struct uvc_device *dev = data; |
| 1289 | |
| 1290 | uvc_gpio_event(dev); |
| 1291 | return IRQ_HANDLED; |
| 1292 | } |
| 1293 | |
| 1294 | static int uvc_gpio_parse(struct uvc_device *dev) |
| 1295 | { |
| 1296 | struct uvc_entity *unit; |
| 1297 | struct gpio_desc *gpio_privacy; |
| 1298 | int irq; |
| 1299 | |
| 1300 | gpio_privacy = devm_gpiod_get_optional(dev: &dev->intf->dev, con_id: "privacy" , |
| 1301 | flags: GPIOD_IN); |
| 1302 | if (!gpio_privacy) |
| 1303 | return 0; |
| 1304 | |
| 1305 | if (IS_ERR(ptr: gpio_privacy)) |
| 1306 | return dev_err_probe(dev: &dev->intf->dev, |
| 1307 | err: PTR_ERR(ptr: gpio_privacy), |
| 1308 | fmt: "Can't get privacy GPIO\n" ); |
| 1309 | |
| 1310 | irq = gpiod_to_irq(desc: gpio_privacy); |
| 1311 | if (irq < 0) |
| 1312 | return dev_err_probe(dev: &dev->intf->dev, err: irq, |
| 1313 | fmt: "No IRQ for privacy GPIO\n" ); |
| 1314 | |
| 1315 | unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, num_pads: 0, extra_size: 1); |
| 1316 | if (!unit) |
| 1317 | return -ENOMEM; |
| 1318 | |
| 1319 | unit->gpio.gpio_privacy = gpio_privacy; |
| 1320 | unit->gpio.irq = irq; |
| 1321 | unit->gpio.bControlSize = 1; |
| 1322 | unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); |
| 1323 | unit->gpio.bmControls[0] = 1; |
| 1324 | unit->get_cur = uvc_gpio_get_cur; |
| 1325 | unit->get_info = uvc_gpio_get_info; |
| 1326 | strscpy(unit->name, "GPIO" , sizeof(unit->name)); |
| 1327 | |
| 1328 | list_add_tail(new: &unit->list, head: &dev->entities); |
| 1329 | |
| 1330 | dev->gpio_unit = unit; |
| 1331 | |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | static int uvc_gpio_init_irq(struct uvc_device *dev) |
| 1336 | { |
| 1337 | struct uvc_entity *unit = dev->gpio_unit; |
| 1338 | int ret; |
| 1339 | |
| 1340 | if (!unit || unit->gpio.irq < 0) |
| 1341 | return 0; |
| 1342 | |
| 1343 | ret = request_threaded_irq(irq: unit->gpio.irq, NULL, thread_fn: uvc_gpio_irq, |
| 1344 | IRQF_ONESHOT | IRQF_TRIGGER_FALLING | |
| 1345 | IRQF_TRIGGER_RISING, |
| 1346 | name: "uvc_privacy_gpio" , dev); |
| 1347 | |
| 1348 | unit->gpio.initialized = !ret; |
| 1349 | |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
| 1353 | static void uvc_gpio_deinit(struct uvc_device *dev) |
| 1354 | { |
| 1355 | if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) |
| 1356 | return; |
| 1357 | |
| 1358 | free_irq(dev->gpio_unit->gpio.irq, dev); |
| 1359 | } |
| 1360 | |
| 1361 | /* ------------------------------------------------------------------------ |
| 1362 | * UVC device scan |
| 1363 | */ |
| 1364 | |
| 1365 | /* |
| 1366 | * Scan the UVC descriptors to locate a chain starting at an Output Terminal |
| 1367 | * and containing the following units: |
| 1368 | * |
| 1369 | * - one or more Output Terminals (USB Streaming or Display) |
| 1370 | * - zero or one Processing Unit |
| 1371 | * - zero, one or more single-input Selector Units |
| 1372 | * - zero or one multiple-input Selector Units, provided all inputs are |
| 1373 | * connected to input terminals |
| 1374 | * - zero, one or mode single-input Extension Units |
| 1375 | * - one or more Input Terminals (Camera, External or USB Streaming) |
| 1376 | * |
| 1377 | * The terminal and units must match on of the following structures: |
| 1378 | * |
| 1379 | * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0) |
| 1380 | * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ... |
| 1381 | * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n) |
| 1382 | * |
| 1383 | * +---------+ +---------+ -> OTT_*(0) |
| 1384 | * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ... |
| 1385 | * +---------+ +---------+ -> OTT_*(n) |
| 1386 | * |
| 1387 | * The Processing Unit and Extension Units can be in any order. Additional |
| 1388 | * Extension Units connected to the main chain as single-unit branches are |
| 1389 | * also supported. Single-input Selector Units are ignored. |
| 1390 | */ |
| 1391 | static int uvc_scan_chain_entity(struct uvc_video_chain *chain, |
| 1392 | struct uvc_entity *entity) |
| 1393 | { |
| 1394 | switch (UVC_ENTITY_TYPE(entity)) { |
| 1395 | case UVC_VC_EXTENSION_UNIT: |
| 1396 | uvc_dbg_cont(PROBE, " <- XU %d" , entity->id); |
| 1397 | |
| 1398 | if (entity->bNrInPins != 1) { |
| 1399 | uvc_dbg(chain->dev, DESCR, |
| 1400 | "Extension unit %d has more than 1 input pin\n" , |
| 1401 | entity->id); |
| 1402 | return -1; |
| 1403 | } |
| 1404 | |
| 1405 | break; |
| 1406 | |
| 1407 | case UVC_VC_PROCESSING_UNIT: |
| 1408 | uvc_dbg_cont(PROBE, " <- PU %d" , entity->id); |
| 1409 | |
| 1410 | if (chain->processing != NULL) { |
| 1411 | uvc_dbg(chain->dev, DESCR, |
| 1412 | "Found multiple Processing Units in chain\n" ); |
| 1413 | return -1; |
| 1414 | } |
| 1415 | |
| 1416 | chain->processing = entity; |
| 1417 | break; |
| 1418 | |
| 1419 | case UVC_VC_SELECTOR_UNIT: |
| 1420 | uvc_dbg_cont(PROBE, " <- SU %d" , entity->id); |
| 1421 | |
| 1422 | /* Single-input selector units are ignored. */ |
| 1423 | if (entity->bNrInPins == 1) |
| 1424 | break; |
| 1425 | |
| 1426 | if (chain->selector != NULL) { |
| 1427 | uvc_dbg(chain->dev, DESCR, |
| 1428 | "Found multiple Selector Units in chain\n" ); |
| 1429 | return -1; |
| 1430 | } |
| 1431 | |
| 1432 | chain->selector = entity; |
| 1433 | break; |
| 1434 | |
| 1435 | case UVC_ITT_VENDOR_SPECIFIC: |
| 1436 | case UVC_ITT_CAMERA: |
| 1437 | case UVC_ITT_MEDIA_TRANSPORT_INPUT: |
| 1438 | uvc_dbg_cont(PROBE, " <- IT %d\n" , entity->id); |
| 1439 | |
| 1440 | break; |
| 1441 | |
| 1442 | case UVC_OTT_VENDOR_SPECIFIC: |
| 1443 | case UVC_OTT_DISPLAY: |
| 1444 | case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: |
| 1445 | uvc_dbg_cont(PROBE, " OT %d" , entity->id); |
| 1446 | |
| 1447 | break; |
| 1448 | |
| 1449 | case UVC_TT_STREAMING: |
| 1450 | if (UVC_ENTITY_IS_ITERM(entity)) |
| 1451 | uvc_dbg_cont(PROBE, " <- IT %d\n" , entity->id); |
| 1452 | else |
| 1453 | uvc_dbg_cont(PROBE, " OT %d" , entity->id); |
| 1454 | |
| 1455 | break; |
| 1456 | |
| 1457 | default: |
| 1458 | uvc_dbg(chain->dev, DESCR, |
| 1459 | "Unsupported entity type 0x%04x found in chain\n" , |
| 1460 | UVC_ENTITY_TYPE(entity)); |
| 1461 | return -1; |
| 1462 | } |
| 1463 | |
| 1464 | list_add_tail(new: &entity->chain, head: &chain->entities); |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
| 1468 | static int uvc_scan_chain_forward(struct uvc_video_chain *chain, |
| 1469 | struct uvc_entity *entity, struct uvc_entity *prev) |
| 1470 | { |
| 1471 | struct uvc_entity *forward; |
| 1472 | int found; |
| 1473 | |
| 1474 | /* Forward scan */ |
| 1475 | forward = NULL; |
| 1476 | found = 0; |
| 1477 | |
| 1478 | while (1) { |
| 1479 | forward = uvc_entity_by_reference(dev: chain->dev, id: entity->id, |
| 1480 | entity: forward); |
| 1481 | if (forward == NULL) |
| 1482 | break; |
| 1483 | if (forward == prev) |
| 1484 | continue; |
| 1485 | if (forward->chain.next || forward->chain.prev) { |
| 1486 | uvc_dbg(chain->dev, DESCR, |
| 1487 | "Found reference to entity %d already in chain\n" , |
| 1488 | forward->id); |
| 1489 | return -EINVAL; |
| 1490 | } |
| 1491 | |
| 1492 | switch (UVC_ENTITY_TYPE(forward)) { |
| 1493 | case UVC_VC_EXTENSION_UNIT: |
| 1494 | if (forward->bNrInPins != 1) { |
| 1495 | uvc_dbg(chain->dev, DESCR, |
| 1496 | "Extension unit %d has more than 1 input pin\n" , |
| 1497 | forward->id); |
| 1498 | return -EINVAL; |
| 1499 | } |
| 1500 | |
| 1501 | /* |
| 1502 | * Some devices reference an output terminal as the |
| 1503 | * source of extension units. This is incorrect, as |
| 1504 | * output terminals only have an input pin, and thus |
| 1505 | * can't be connected to any entity in the forward |
| 1506 | * direction. The resulting topology would cause issues |
| 1507 | * when registering the media controller graph. To |
| 1508 | * avoid this problem, connect the extension unit to |
| 1509 | * the source of the output terminal instead. |
| 1510 | */ |
| 1511 | if (UVC_ENTITY_IS_OTERM(entity)) { |
| 1512 | struct uvc_entity *source; |
| 1513 | |
| 1514 | source = uvc_entity_by_id(dev: chain->dev, |
| 1515 | id: entity->baSourceID[0]); |
| 1516 | if (!source) { |
| 1517 | uvc_dbg(chain->dev, DESCR, |
| 1518 | "Can't connect extension unit %u in chain\n" , |
| 1519 | forward->id); |
| 1520 | break; |
| 1521 | } |
| 1522 | |
| 1523 | forward->baSourceID[0] = source->id; |
| 1524 | } |
| 1525 | |
| 1526 | list_add_tail(new: &forward->chain, head: &chain->entities); |
| 1527 | if (!found) |
| 1528 | uvc_dbg_cont(PROBE, " (->" ); |
| 1529 | |
| 1530 | uvc_dbg_cont(PROBE, " XU %d" , forward->id); |
| 1531 | found = 1; |
| 1532 | break; |
| 1533 | |
| 1534 | case UVC_OTT_VENDOR_SPECIFIC: |
| 1535 | case UVC_OTT_DISPLAY: |
| 1536 | case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: |
| 1537 | case UVC_TT_STREAMING: |
| 1538 | if (UVC_ENTITY_IS_ITERM(forward)) { |
| 1539 | uvc_dbg(chain->dev, DESCR, |
| 1540 | "Unsupported input terminal %u\n" , |
| 1541 | forward->id); |
| 1542 | return -EINVAL; |
| 1543 | } |
| 1544 | |
| 1545 | if (UVC_ENTITY_IS_OTERM(entity)) { |
| 1546 | uvc_dbg(chain->dev, DESCR, |
| 1547 | "Unsupported connection between output terminals %u and %u\n" , |
| 1548 | entity->id, forward->id); |
| 1549 | break; |
| 1550 | } |
| 1551 | |
| 1552 | list_add_tail(new: &forward->chain, head: &chain->entities); |
| 1553 | if (!found) |
| 1554 | uvc_dbg_cont(PROBE, " (->" ); |
| 1555 | |
| 1556 | uvc_dbg_cont(PROBE, " OT %d" , forward->id); |
| 1557 | found = 1; |
| 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | if (found) |
| 1562 | uvc_dbg_cont(PROBE, ")" ); |
| 1563 | |
| 1564 | return 0; |
| 1565 | } |
| 1566 | |
| 1567 | static int uvc_scan_chain_backward(struct uvc_video_chain *chain, |
| 1568 | struct uvc_entity **_entity) |
| 1569 | { |
| 1570 | struct uvc_entity *entity = *_entity; |
| 1571 | struct uvc_entity *term; |
| 1572 | int id = -EINVAL, i; |
| 1573 | |
| 1574 | switch (UVC_ENTITY_TYPE(entity)) { |
| 1575 | case UVC_VC_EXTENSION_UNIT: |
| 1576 | case UVC_VC_PROCESSING_UNIT: |
| 1577 | id = entity->baSourceID[0]; |
| 1578 | break; |
| 1579 | |
| 1580 | case UVC_VC_SELECTOR_UNIT: |
| 1581 | /* Single-input selector units are ignored. */ |
| 1582 | if (entity->bNrInPins == 1) { |
| 1583 | id = entity->baSourceID[0]; |
| 1584 | break; |
| 1585 | } |
| 1586 | |
| 1587 | uvc_dbg_cont(PROBE, " <- IT" ); |
| 1588 | |
| 1589 | chain->selector = entity; |
| 1590 | for (i = 0; i < entity->bNrInPins; ++i) { |
| 1591 | id = entity->baSourceID[i]; |
| 1592 | term = uvc_entity_by_id(dev: chain->dev, id); |
| 1593 | if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) { |
| 1594 | uvc_dbg(chain->dev, DESCR, |
| 1595 | "Selector unit %d input %d isn't connected to an input terminal\n" , |
| 1596 | entity->id, i); |
| 1597 | return -1; |
| 1598 | } |
| 1599 | |
| 1600 | if (term->chain.next || term->chain.prev) { |
| 1601 | uvc_dbg(chain->dev, DESCR, |
| 1602 | "Found reference to entity %d already in chain\n" , |
| 1603 | term->id); |
| 1604 | return -EINVAL; |
| 1605 | } |
| 1606 | |
| 1607 | uvc_dbg_cont(PROBE, " %d" , term->id); |
| 1608 | |
| 1609 | list_add_tail(new: &term->chain, head: &chain->entities); |
| 1610 | uvc_scan_chain_forward(chain, entity: term, prev: entity); |
| 1611 | } |
| 1612 | |
| 1613 | uvc_dbg_cont(PROBE, "\n" ); |
| 1614 | |
| 1615 | id = 0; |
| 1616 | break; |
| 1617 | |
| 1618 | case UVC_ITT_VENDOR_SPECIFIC: |
| 1619 | case UVC_ITT_CAMERA: |
| 1620 | case UVC_ITT_MEDIA_TRANSPORT_INPUT: |
| 1621 | case UVC_OTT_VENDOR_SPECIFIC: |
| 1622 | case UVC_OTT_DISPLAY: |
| 1623 | case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: |
| 1624 | case UVC_TT_STREAMING: |
| 1625 | id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0; |
| 1626 | break; |
| 1627 | } |
| 1628 | |
| 1629 | if (id <= 0) { |
| 1630 | *_entity = NULL; |
| 1631 | return id; |
| 1632 | } |
| 1633 | |
| 1634 | entity = uvc_entity_by_id(dev: chain->dev, id); |
| 1635 | if (entity == NULL) { |
| 1636 | uvc_dbg(chain->dev, DESCR, |
| 1637 | "Found reference to unknown entity %d\n" , id); |
| 1638 | return -EINVAL; |
| 1639 | } |
| 1640 | |
| 1641 | *_entity = entity; |
| 1642 | return 0; |
| 1643 | } |
| 1644 | |
| 1645 | static int uvc_scan_chain(struct uvc_video_chain *chain, |
| 1646 | struct uvc_entity *term) |
| 1647 | { |
| 1648 | struct uvc_entity *entity, *prev; |
| 1649 | |
| 1650 | uvc_dbg(chain->dev, PROBE, "Scanning UVC chain:" ); |
| 1651 | |
| 1652 | entity = term; |
| 1653 | prev = NULL; |
| 1654 | |
| 1655 | while (entity != NULL) { |
| 1656 | /* Entity must not be part of an existing chain */ |
| 1657 | if (entity->chain.next || entity->chain.prev) { |
| 1658 | uvc_dbg(chain->dev, DESCR, |
| 1659 | "Found reference to entity %d already in chain\n" , |
| 1660 | entity->id); |
| 1661 | return -EINVAL; |
| 1662 | } |
| 1663 | |
| 1664 | /* Process entity */ |
| 1665 | if (uvc_scan_chain_entity(chain, entity) < 0) |
| 1666 | return -EINVAL; |
| 1667 | |
| 1668 | /* Forward scan */ |
| 1669 | if (uvc_scan_chain_forward(chain, entity, prev) < 0) |
| 1670 | return -EINVAL; |
| 1671 | |
| 1672 | /* Backward scan */ |
| 1673 | prev = entity; |
| 1674 | if (uvc_scan_chain_backward(chain, entity: &entity) < 0) |
| 1675 | return -EINVAL; |
| 1676 | } |
| 1677 | |
| 1678 | return 0; |
| 1679 | } |
| 1680 | |
| 1681 | static unsigned int uvc_print_terms(struct list_head *terms, u16 dir, |
| 1682 | char *buffer) |
| 1683 | { |
| 1684 | struct uvc_entity *term; |
| 1685 | unsigned int nterms = 0; |
| 1686 | char *p = buffer; |
| 1687 | |
| 1688 | list_for_each_entry(term, terms, chain) { |
| 1689 | if (!UVC_ENTITY_IS_TERM(term) || |
| 1690 | UVC_TERM_DIRECTION(term) != dir) |
| 1691 | continue; |
| 1692 | |
| 1693 | if (nterms) |
| 1694 | p += sprintf(buf: p, fmt: "," ); |
| 1695 | if (++nterms >= 4) { |
| 1696 | p += sprintf(buf: p, fmt: "..." ); |
| 1697 | break; |
| 1698 | } |
| 1699 | p += sprintf(buf: p, fmt: "%u" , term->id); |
| 1700 | } |
| 1701 | |
| 1702 | return p - buffer; |
| 1703 | } |
| 1704 | |
| 1705 | static const char *uvc_print_chain(struct uvc_video_chain *chain) |
| 1706 | { |
| 1707 | static char buffer[43]; |
| 1708 | char *p = buffer; |
| 1709 | |
| 1710 | p += uvc_print_terms(terms: &chain->entities, UVC_TERM_INPUT, buffer: p); |
| 1711 | p += sprintf(buf: p, fmt: " -> " ); |
| 1712 | uvc_print_terms(terms: &chain->entities, UVC_TERM_OUTPUT, buffer: p); |
| 1713 | |
| 1714 | return buffer; |
| 1715 | } |
| 1716 | |
| 1717 | static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev) |
| 1718 | { |
| 1719 | struct uvc_video_chain *chain; |
| 1720 | |
| 1721 | chain = kzalloc(sizeof(*chain), GFP_KERNEL); |
| 1722 | if (chain == NULL) |
| 1723 | return NULL; |
| 1724 | |
| 1725 | INIT_LIST_HEAD(list: &chain->entities); |
| 1726 | mutex_init(&chain->ctrl_mutex); |
| 1727 | chain->dev = dev; |
| 1728 | v4l2_prio_init(global: &chain->prio); |
| 1729 | |
| 1730 | return chain; |
| 1731 | } |
| 1732 | |
| 1733 | /* |
| 1734 | * Fallback heuristic for devices that don't connect units and terminals in a |
| 1735 | * valid chain. |
| 1736 | * |
| 1737 | * Some devices have invalid baSourceID references, causing uvc_scan_chain() |
| 1738 | * to fail, but if we just take the entities we can find and put them together |
| 1739 | * in the most sensible chain we can think of, turns out they do work anyway. |
| 1740 | * Note: This heuristic assumes there is a single chain. |
| 1741 | * |
| 1742 | * At the time of writing, devices known to have such a broken chain are |
| 1743 | * - Acer Integrated Camera (5986:055a) |
| 1744 | * - Realtek rtl157a7 (0bda:57a7) |
| 1745 | */ |
| 1746 | static int uvc_scan_fallback(struct uvc_device *dev) |
| 1747 | { |
| 1748 | struct uvc_video_chain *chain; |
| 1749 | struct uvc_entity *iterm = NULL; |
| 1750 | struct uvc_entity *oterm = NULL; |
| 1751 | struct uvc_entity *entity; |
| 1752 | struct uvc_entity *prev; |
| 1753 | |
| 1754 | /* |
| 1755 | * Start by locating the input and output terminals. We only support |
| 1756 | * devices with exactly one of each for now. |
| 1757 | */ |
| 1758 | list_for_each_entry(entity, &dev->entities, list) { |
| 1759 | if (UVC_ENTITY_IS_ITERM(entity)) { |
| 1760 | if (iterm) |
| 1761 | return -EINVAL; |
| 1762 | iterm = entity; |
| 1763 | } |
| 1764 | |
| 1765 | if (UVC_ENTITY_IS_OTERM(entity)) { |
| 1766 | if (oterm) |
| 1767 | return -EINVAL; |
| 1768 | oterm = entity; |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | if (iterm == NULL || oterm == NULL) |
| 1773 | return -EINVAL; |
| 1774 | |
| 1775 | /* Allocate the chain and fill it. */ |
| 1776 | chain = uvc_alloc_chain(dev); |
| 1777 | if (chain == NULL) |
| 1778 | return -ENOMEM; |
| 1779 | |
| 1780 | if (uvc_scan_chain_entity(chain, entity: oterm) < 0) |
| 1781 | goto error; |
| 1782 | |
| 1783 | prev = oterm; |
| 1784 | |
| 1785 | /* |
| 1786 | * Add all Processing and Extension Units with two pads. The order |
| 1787 | * doesn't matter much, use reverse list traversal to connect units in |
| 1788 | * UVC descriptor order as we build the chain from output to input. This |
| 1789 | * leads to units appearing in the order meant by the manufacturer for |
| 1790 | * the cameras known to require this heuristic. |
| 1791 | */ |
| 1792 | list_for_each_entry_reverse(entity, &dev->entities, list) { |
| 1793 | if (entity->type != UVC_VC_PROCESSING_UNIT && |
| 1794 | entity->type != UVC_VC_EXTENSION_UNIT) |
| 1795 | continue; |
| 1796 | |
| 1797 | if (entity->num_pads != 2) |
| 1798 | continue; |
| 1799 | |
| 1800 | if (uvc_scan_chain_entity(chain, entity) < 0) |
| 1801 | goto error; |
| 1802 | |
| 1803 | prev->baSourceID[0] = entity->id; |
| 1804 | prev = entity; |
| 1805 | } |
| 1806 | |
| 1807 | if (uvc_scan_chain_entity(chain, entity: iterm) < 0) |
| 1808 | goto error; |
| 1809 | |
| 1810 | prev->baSourceID[0] = iterm->id; |
| 1811 | |
| 1812 | list_add_tail(new: &chain->list, head: &dev->chains); |
| 1813 | |
| 1814 | uvc_dbg(dev, PROBE, "Found a video chain by fallback heuristic (%s)\n" , |
| 1815 | uvc_print_chain(chain)); |
| 1816 | |
| 1817 | return 0; |
| 1818 | |
| 1819 | error: |
| 1820 | kfree(objp: chain); |
| 1821 | return -EINVAL; |
| 1822 | } |
| 1823 | |
| 1824 | /* |
| 1825 | * Scan the device for video chains and register video devices. |
| 1826 | * |
| 1827 | * Chains are scanned starting at their output terminals and walked backwards. |
| 1828 | */ |
| 1829 | static int uvc_scan_device(struct uvc_device *dev) |
| 1830 | { |
| 1831 | struct uvc_video_chain *chain; |
| 1832 | struct uvc_entity *term; |
| 1833 | |
| 1834 | list_for_each_entry(term, &dev->entities, list) { |
| 1835 | if (!UVC_ENTITY_IS_OTERM(term)) |
| 1836 | continue; |
| 1837 | |
| 1838 | /* |
| 1839 | * If the terminal is already included in a chain, skip it. |
| 1840 | * This can happen for chains that have multiple output |
| 1841 | * terminals, where all output terminals beside the first one |
| 1842 | * will be inserted in the chain in forward scans. |
| 1843 | */ |
| 1844 | if (term->chain.next || term->chain.prev) |
| 1845 | continue; |
| 1846 | |
| 1847 | chain = uvc_alloc_chain(dev); |
| 1848 | if (chain == NULL) |
| 1849 | return -ENOMEM; |
| 1850 | |
| 1851 | term->flags |= UVC_ENTITY_FLAG_DEFAULT; |
| 1852 | |
| 1853 | if (uvc_scan_chain(chain, term) < 0) { |
| 1854 | kfree(objp: chain); |
| 1855 | continue; |
| 1856 | } |
| 1857 | |
| 1858 | uvc_dbg(dev, PROBE, "Found a valid video chain (%s)\n" , |
| 1859 | uvc_print_chain(chain)); |
| 1860 | |
| 1861 | list_add_tail(new: &chain->list, head: &dev->chains); |
| 1862 | } |
| 1863 | |
| 1864 | if (list_empty(head: &dev->chains)) |
| 1865 | uvc_scan_fallback(dev); |
| 1866 | |
| 1867 | if (list_empty(head: &dev->chains)) { |
| 1868 | dev_info(&dev->udev->dev, "No valid video chain found.\n" ); |
| 1869 | return -1; |
| 1870 | } |
| 1871 | |
| 1872 | /* Add GPIO entity to the first chain. */ |
| 1873 | if (dev->gpio_unit) { |
| 1874 | chain = list_first_entry(&dev->chains, |
| 1875 | struct uvc_video_chain, list); |
| 1876 | list_add_tail(new: &dev->gpio_unit->chain, head: &chain->entities); |
| 1877 | } |
| 1878 | |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | /* ------------------------------------------------------------------------ |
| 1883 | * Video device registration and unregistration |
| 1884 | */ |
| 1885 | |
| 1886 | /* |
| 1887 | * Delete the UVC device. |
| 1888 | * |
| 1889 | * Called by the kernel when the last reference to the uvc_device structure |
| 1890 | * is released. |
| 1891 | * |
| 1892 | * As this function is called after or during disconnect(), all URBs have |
| 1893 | * already been cancelled by the USB core. There is no need to kill the |
| 1894 | * interrupt URB manually. |
| 1895 | */ |
| 1896 | static void uvc_delete(struct kref *kref) |
| 1897 | { |
| 1898 | struct uvc_device *dev = container_of(kref, struct uvc_device, ref); |
| 1899 | struct list_head *p, *n; |
| 1900 | |
| 1901 | uvc_status_cleanup(dev); |
| 1902 | uvc_ctrl_cleanup_device(dev); |
| 1903 | |
| 1904 | usb_put_intf(intf: dev->intf); |
| 1905 | usb_put_dev(dev: dev->udev); |
| 1906 | |
| 1907 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1908 | media_device_cleanup(mdev: &dev->mdev); |
| 1909 | #endif |
| 1910 | |
| 1911 | list_for_each_safe(p, n, &dev->chains) { |
| 1912 | struct uvc_video_chain *chain; |
| 1913 | |
| 1914 | chain = list_entry(p, struct uvc_video_chain, list); |
| 1915 | kfree(objp: chain); |
| 1916 | } |
| 1917 | |
| 1918 | list_for_each_safe(p, n, &dev->entities) { |
| 1919 | struct uvc_entity *entity; |
| 1920 | |
| 1921 | entity = list_entry(p, struct uvc_entity, list); |
| 1922 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1923 | uvc_mc_cleanup_entity(entity); |
| 1924 | #endif |
| 1925 | kfree(objp: entity); |
| 1926 | } |
| 1927 | |
| 1928 | list_for_each_safe(p, n, &dev->streams) { |
| 1929 | struct uvc_streaming *streaming; |
| 1930 | |
| 1931 | streaming = list_entry(p, struct uvc_streaming, list); |
| 1932 | usb_driver_release_interface(driver: &uvc_driver, iface: streaming->intf); |
| 1933 | uvc_stream_delete(stream: streaming); |
| 1934 | } |
| 1935 | |
| 1936 | kfree(objp: dev); |
| 1937 | } |
| 1938 | |
| 1939 | static void uvc_release(struct video_device *vdev) |
| 1940 | { |
| 1941 | struct uvc_streaming *stream = video_get_drvdata(vdev); |
| 1942 | struct uvc_device *dev = stream->dev; |
| 1943 | |
| 1944 | kref_put(kref: &dev->ref, release: uvc_delete); |
| 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | * Unregister the video devices. |
| 1949 | */ |
| 1950 | static void uvc_unregister_video(struct uvc_device *dev) |
| 1951 | { |
| 1952 | struct uvc_streaming *stream; |
| 1953 | |
| 1954 | uvc_gpio_deinit(dev); |
| 1955 | |
| 1956 | list_for_each_entry(stream, &dev->streams, list) { |
| 1957 | /* Nothing to do here, continue. */ |
| 1958 | if (!video_is_registered(vdev: &stream->vdev)) |
| 1959 | continue; |
| 1960 | |
| 1961 | /* |
| 1962 | * For stream->vdev we follow the same logic as: |
| 1963 | * vb2_video_unregister_device(). |
| 1964 | */ |
| 1965 | |
| 1966 | /* 1. Take a reference to vdev */ |
| 1967 | get_device(dev: &stream->vdev.dev); |
| 1968 | |
| 1969 | /* 2. Ensure that no new ioctls can be called. */ |
| 1970 | video_unregister_device(vdev: &stream->vdev); |
| 1971 | |
| 1972 | /* 3. Wait for old ioctls to finish. */ |
| 1973 | mutex_lock(&stream->mutex); |
| 1974 | |
| 1975 | /* 4. Stop streaming. */ |
| 1976 | uvc_queue_release(queue: &stream->queue); |
| 1977 | |
| 1978 | mutex_unlock(lock: &stream->mutex); |
| 1979 | |
| 1980 | put_device(dev: &stream->vdev.dev); |
| 1981 | |
| 1982 | /* |
| 1983 | * For stream->meta.vdev we can directly call: |
| 1984 | * vb2_video_unregister_device(). |
| 1985 | */ |
| 1986 | vb2_video_unregister_device(vdev: &stream->meta.vdev); |
| 1987 | |
| 1988 | /* |
| 1989 | * Now both vdevs are not streaming and all the ioctls will |
| 1990 | * return -ENODEV. |
| 1991 | */ |
| 1992 | |
| 1993 | uvc_debugfs_cleanup_stream(stream); |
| 1994 | } |
| 1995 | |
| 1996 | uvc_status_unregister(dev); |
| 1997 | |
| 1998 | if (dev->vdev.dev) |
| 1999 | v4l2_device_unregister(v4l2_dev: &dev->vdev); |
| 2000 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 2001 | if (media_devnode_is_registered(devnode: dev->mdev.devnode)) |
| 2002 | media_device_unregister(mdev: &dev->mdev); |
| 2003 | #endif |
| 2004 | } |
| 2005 | |
| 2006 | int uvc_register_video_device(struct uvc_device *dev, |
| 2007 | struct uvc_streaming *stream, |
| 2008 | struct video_device *vdev, |
| 2009 | struct uvc_video_queue *queue, |
| 2010 | enum v4l2_buf_type type, |
| 2011 | const struct v4l2_file_operations *fops, |
| 2012 | const struct v4l2_ioctl_ops *ioctl_ops) |
| 2013 | { |
| 2014 | int ret; |
| 2015 | |
| 2016 | /* Initialize the video buffers queue. */ |
| 2017 | ret = uvc_queue_init(queue, type); |
| 2018 | if (ret) |
| 2019 | return ret; |
| 2020 | |
| 2021 | /* Register the device with V4L. */ |
| 2022 | |
| 2023 | /* |
| 2024 | * We already hold a reference to dev->udev. The video device will be |
| 2025 | * unregistered before the reference is released, so we don't need to |
| 2026 | * get another one. |
| 2027 | */ |
| 2028 | vdev->v4l2_dev = &dev->vdev; |
| 2029 | vdev->fops = fops; |
| 2030 | vdev->ioctl_ops = ioctl_ops; |
| 2031 | vdev->release = uvc_release; |
| 2032 | vdev->prio = &stream->chain->prio; |
| 2033 | if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 2034 | vdev->vfl_dir = VFL_DIR_TX; |
| 2035 | else |
| 2036 | vdev->vfl_dir = VFL_DIR_RX; |
| 2037 | |
| 2038 | switch (type) { |
| 2039 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 2040 | default: |
| 2041 | vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
| 2042 | break; |
| 2043 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 2044 | vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; |
| 2045 | break; |
| 2046 | case V4L2_BUF_TYPE_META_CAPTURE: |
| 2047 | vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING; |
| 2048 | break; |
| 2049 | } |
| 2050 | |
| 2051 | strscpy(vdev->name, dev->name, sizeof(vdev->name)); |
| 2052 | |
| 2053 | /* |
| 2054 | * Set the driver data before calling video_register_device, otherwise |
| 2055 | * the file open() handler might race us. |
| 2056 | */ |
| 2057 | video_set_drvdata(vdev, data: stream); |
| 2058 | |
| 2059 | ret = video_register_device(vdev, type: VFL_TYPE_VIDEO, nr: -1); |
| 2060 | if (ret < 0) { |
| 2061 | dev_err(&stream->intf->dev, |
| 2062 | "Failed to register %s device (%d).\n" , |
| 2063 | v4l2_type_names[type], ret); |
| 2064 | return ret; |
| 2065 | } |
| 2066 | |
| 2067 | kref_get(kref: &dev->ref); |
| 2068 | return 0; |
| 2069 | } |
| 2070 | |
| 2071 | static int uvc_register_video(struct uvc_device *dev, |
| 2072 | struct uvc_streaming *stream) |
| 2073 | { |
| 2074 | int ret; |
| 2075 | |
| 2076 | /* Initialize the streaming interface with default parameters. */ |
| 2077 | ret = uvc_video_init(stream); |
| 2078 | if (ret < 0) { |
| 2079 | dev_err(&stream->intf->dev, |
| 2080 | "Failed to initialize the device (%d).\n" , ret); |
| 2081 | return ret; |
| 2082 | } |
| 2083 | |
| 2084 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 2085 | stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE |
| 2086 | | V4L2_CAP_META_CAPTURE; |
| 2087 | else |
| 2088 | stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT; |
| 2089 | |
| 2090 | uvc_debugfs_init_stream(stream); |
| 2091 | |
| 2092 | /* Register the device with V4L. */ |
| 2093 | return uvc_register_video_device(dev, stream, vdev: &stream->vdev, |
| 2094 | queue: &stream->queue, type: stream->type, |
| 2095 | fops: &uvc_fops, ioctl_ops: &uvc_ioctl_ops); |
| 2096 | } |
| 2097 | |
| 2098 | /* |
| 2099 | * Register all video devices in all chains. |
| 2100 | */ |
| 2101 | static int uvc_register_terms(struct uvc_device *dev, |
| 2102 | struct uvc_video_chain *chain) |
| 2103 | { |
| 2104 | struct uvc_streaming *stream; |
| 2105 | struct uvc_entity *term; |
| 2106 | int ret; |
| 2107 | |
| 2108 | list_for_each_entry(term, &chain->entities, chain) { |
| 2109 | if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING) |
| 2110 | continue; |
| 2111 | |
| 2112 | stream = uvc_stream_by_id(dev, id: term->id); |
| 2113 | if (stream == NULL) { |
| 2114 | dev_info(&dev->udev->dev, |
| 2115 | "No streaming interface found for terminal %u." , |
| 2116 | term->id); |
| 2117 | continue; |
| 2118 | } |
| 2119 | |
| 2120 | stream->chain = chain; |
| 2121 | ret = uvc_register_video(dev, stream); |
| 2122 | if (ret < 0) |
| 2123 | return ret; |
| 2124 | |
| 2125 | /* |
| 2126 | * Register a metadata node, but ignore a possible failure, |
| 2127 | * complete registration of video nodes anyway. |
| 2128 | */ |
| 2129 | uvc_meta_register(stream); |
| 2130 | |
| 2131 | term->vdev = &stream->vdev; |
| 2132 | } |
| 2133 | |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
| 2137 | static int uvc_register_chains(struct uvc_device *dev) |
| 2138 | { |
| 2139 | struct uvc_video_chain *chain; |
| 2140 | int ret; |
| 2141 | |
| 2142 | list_for_each_entry(chain, &dev->chains, list) { |
| 2143 | ret = uvc_register_terms(dev, chain); |
| 2144 | if (ret < 0) |
| 2145 | return ret; |
| 2146 | |
| 2147 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 2148 | ret = uvc_mc_register_entities(chain); |
| 2149 | if (ret < 0) |
| 2150 | dev_info(&dev->udev->dev, |
| 2151 | "Failed to register entities (%d).\n" , ret); |
| 2152 | #endif |
| 2153 | } |
| 2154 | |
| 2155 | return 0; |
| 2156 | } |
| 2157 | |
| 2158 | /* ------------------------------------------------------------------------ |
| 2159 | * USB probe, disconnect, suspend and resume |
| 2160 | */ |
| 2161 | |
| 2162 | static const struct uvc_device_info uvc_quirk_none = { 0 }; |
| 2163 | |
| 2164 | static int uvc_probe(struct usb_interface *intf, |
| 2165 | const struct usb_device_id *id) |
| 2166 | { |
| 2167 | struct usb_device *udev = interface_to_usbdev(intf); |
| 2168 | struct uvc_device *dev; |
| 2169 | const struct uvc_device_info *info = |
| 2170 | (const struct uvc_device_info *)id->driver_info; |
| 2171 | int function; |
| 2172 | int ret; |
| 2173 | |
| 2174 | /* Allocate memory for the device and initialize it. */ |
| 2175 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 2176 | if (dev == NULL) |
| 2177 | return -ENOMEM; |
| 2178 | |
| 2179 | INIT_LIST_HEAD(list: &dev->entities); |
| 2180 | INIT_LIST_HEAD(list: &dev->chains); |
| 2181 | INIT_LIST_HEAD(list: &dev->streams); |
| 2182 | kref_init(kref: &dev->ref); |
| 2183 | atomic_set(v: &dev->nmappings, i: 0); |
| 2184 | |
| 2185 | dev->udev = usb_get_dev(dev: udev); |
| 2186 | dev->intf = usb_get_intf(intf); |
| 2187 | dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; |
| 2188 | dev->info = info ? info : &uvc_quirk_none; |
| 2189 | dev->quirks = uvc_quirks_param == -1 |
| 2190 | ? dev->info->quirks : uvc_quirks_param; |
| 2191 | |
| 2192 | if (id->idVendor && id->idProduct) |
| 2193 | uvc_dbg(dev, PROBE, "Probing known UVC device %s (%04x:%04x)\n" , |
| 2194 | udev->devpath, id->idVendor, id->idProduct); |
| 2195 | else |
| 2196 | uvc_dbg(dev, PROBE, "Probing generic UVC device %s\n" , |
| 2197 | udev->devpath); |
| 2198 | |
| 2199 | if (udev->product != NULL) |
| 2200 | strscpy(dev->name, udev->product, sizeof(dev->name)); |
| 2201 | else |
| 2202 | snprintf(buf: dev->name, size: sizeof(dev->name), |
| 2203 | fmt: "UVC Camera (%04x:%04x)" , |
| 2204 | le16_to_cpu(udev->descriptor.idVendor), |
| 2205 | le16_to_cpu(udev->descriptor.idProduct)); |
| 2206 | |
| 2207 | /* |
| 2208 | * Add iFunction or iInterface to names when available as additional |
| 2209 | * distinguishers between interfaces. iFunction is prioritized over |
| 2210 | * iInterface which matches Windows behavior at the point of writing. |
| 2211 | */ |
| 2212 | if (intf->intf_assoc && intf->intf_assoc->iFunction != 0) |
| 2213 | function = intf->intf_assoc->iFunction; |
| 2214 | else |
| 2215 | function = intf->cur_altsetting->desc.iInterface; |
| 2216 | if (function != 0) { |
| 2217 | size_t len; |
| 2218 | |
| 2219 | strlcat(p: dev->name, q: ": " , avail: sizeof(dev->name)); |
| 2220 | len = strlen(dev->name); |
| 2221 | usb_string(dev: udev, index: function, buf: dev->name + len, |
| 2222 | size: sizeof(dev->name) - len); |
| 2223 | } |
| 2224 | |
| 2225 | /* Initialize the media device. */ |
| 2226 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 2227 | dev->mdev.dev = &intf->dev; |
| 2228 | strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model)); |
| 2229 | if (udev->serial) |
| 2230 | strscpy(dev->mdev.serial, udev->serial, |
| 2231 | sizeof(dev->mdev.serial)); |
| 2232 | usb_make_path(dev: udev, buf: dev->mdev.bus_info, size: sizeof(dev->mdev.bus_info)); |
| 2233 | dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice); |
| 2234 | media_device_init(mdev: &dev->mdev); |
| 2235 | |
| 2236 | dev->vdev.mdev = &dev->mdev; |
| 2237 | #endif |
| 2238 | |
| 2239 | /* Parse the Video Class control descriptor. */ |
| 2240 | ret = uvc_parse_control(dev); |
| 2241 | if (ret < 0) { |
| 2242 | ret = -ENODEV; |
| 2243 | uvc_dbg(dev, PROBE, "Unable to parse UVC descriptors\n" ); |
| 2244 | goto error; |
| 2245 | } |
| 2246 | |
| 2247 | /* Parse the associated GPIOs. */ |
| 2248 | ret = uvc_gpio_parse(dev); |
| 2249 | if (ret < 0) |
| 2250 | goto error; |
| 2251 | |
| 2252 | dev_info(&dev->udev->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n" , |
| 2253 | dev->uvc_version >> 8, dev->uvc_version & 0xff, |
| 2254 | udev->product ? udev->product : "<unnamed>" , |
| 2255 | le16_to_cpu(udev->descriptor.idVendor), |
| 2256 | le16_to_cpu(udev->descriptor.idProduct)); |
| 2257 | |
| 2258 | if (dev->quirks != dev->info->quirks) { |
| 2259 | dev_info(&dev->udev->dev, |
| 2260 | "Forcing device quirks to 0x%x by module parameter for testing purpose.\n" , |
| 2261 | dev->quirks); |
| 2262 | dev_info(&dev->udev->dev, |
| 2263 | "Please report required quirks to the linux-media mailing list.\n" ); |
| 2264 | } |
| 2265 | |
| 2266 | if (dev->info->uvc_version) { |
| 2267 | dev->uvc_version = dev->info->uvc_version; |
| 2268 | dev_info(&dev->udev->dev, "Forcing UVC version to %u.%02x\n" , |
| 2269 | dev->uvc_version >> 8, dev->uvc_version & 0xff); |
| 2270 | } |
| 2271 | |
| 2272 | /* Register the V4L2 device. */ |
| 2273 | ret = v4l2_device_register(dev: &intf->dev, v4l2_dev: &dev->vdev); |
| 2274 | if (ret < 0) |
| 2275 | goto error; |
| 2276 | |
| 2277 | /* Scan the device for video chains. */ |
| 2278 | if (uvc_scan_device(dev) < 0) { |
| 2279 | ret = -ENODEV; |
| 2280 | goto error; |
| 2281 | } |
| 2282 | |
| 2283 | /* Initialize controls. */ |
| 2284 | if (uvc_ctrl_init_device(dev) < 0) { |
| 2285 | ret = -ENODEV; |
| 2286 | goto error; |
| 2287 | } |
| 2288 | |
| 2289 | /* Register video device nodes. */ |
| 2290 | if (uvc_register_chains(dev) < 0) { |
| 2291 | ret = -ENODEV; |
| 2292 | goto error; |
| 2293 | } |
| 2294 | |
| 2295 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 2296 | /* Register the media device node */ |
| 2297 | ret = media_device_register(&dev->mdev); |
| 2298 | if (ret < 0) |
| 2299 | goto error; |
| 2300 | #endif |
| 2301 | /* Save our data pointer in the interface data. */ |
| 2302 | usb_set_intfdata(intf, data: dev); |
| 2303 | |
| 2304 | /* Initialize the interrupt URB. */ |
| 2305 | ret = uvc_status_init(dev); |
| 2306 | if (ret < 0) { |
| 2307 | dev_info(&dev->udev->dev, |
| 2308 | "Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n" , |
| 2309 | ret); |
| 2310 | } |
| 2311 | |
| 2312 | ret = uvc_gpio_init_irq(dev); |
| 2313 | if (ret < 0) { |
| 2314 | dev_err(&dev->udev->dev, |
| 2315 | "Unable to request privacy GPIO IRQ (%d)\n" , ret); |
| 2316 | goto error; |
| 2317 | } |
| 2318 | |
| 2319 | if (dev->quirks & UVC_QUIRK_NO_RESET_RESUME) |
| 2320 | udev->quirks &= ~USB_QUIRK_RESET_RESUME; |
| 2321 | |
| 2322 | if (!(dev->quirks & UVC_QUIRK_DISABLE_AUTOSUSPEND)) |
| 2323 | usb_enable_autosuspend(udev); |
| 2324 | |
| 2325 | uvc_dbg(dev, PROBE, "UVC device initialized\n" ); |
| 2326 | |
| 2327 | return 0; |
| 2328 | |
| 2329 | error: |
| 2330 | uvc_unregister_video(dev); |
| 2331 | kref_put(kref: &dev->ref, release: uvc_delete); |
| 2332 | return ret; |
| 2333 | } |
| 2334 | |
| 2335 | static void uvc_disconnect(struct usb_interface *intf) |
| 2336 | { |
| 2337 | struct uvc_device *dev = usb_get_intfdata(intf); |
| 2338 | |
| 2339 | /* |
| 2340 | * Set the USB interface data to NULL. This can be done outside the |
| 2341 | * lock, as there's no other reader. |
| 2342 | */ |
| 2343 | usb_set_intfdata(intf, NULL); |
| 2344 | |
| 2345 | if (intf->cur_altsetting->desc.bInterfaceSubClass == |
| 2346 | UVC_SC_VIDEOSTREAMING) |
| 2347 | return; |
| 2348 | |
| 2349 | uvc_unregister_video(dev); |
| 2350 | kref_put(kref: &dev->ref, release: uvc_delete); |
| 2351 | } |
| 2352 | |
| 2353 | static int uvc_suspend(struct usb_interface *intf, pm_message_t message) |
| 2354 | { |
| 2355 | struct uvc_device *dev = usb_get_intfdata(intf); |
| 2356 | struct uvc_streaming *stream; |
| 2357 | |
| 2358 | uvc_dbg(dev, SUSPEND, "Suspending interface %u\n" , |
| 2359 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 2360 | |
| 2361 | /* Controls are cached on the fly so they don't need to be saved. */ |
| 2362 | if (intf->cur_altsetting->desc.bInterfaceSubClass == |
| 2363 | UVC_SC_VIDEOCONTROL) { |
| 2364 | uvc_status_suspend(dev); |
| 2365 | return 0; |
| 2366 | } |
| 2367 | |
| 2368 | list_for_each_entry(stream, &dev->streams, list) { |
| 2369 | if (stream->intf == intf) |
| 2370 | return uvc_video_suspend(stream); |
| 2371 | } |
| 2372 | |
| 2373 | uvc_dbg(dev, SUSPEND, |
| 2374 | "Suspend: video streaming USB interface mismatch\n" ); |
| 2375 | return -EINVAL; |
| 2376 | } |
| 2377 | |
| 2378 | static int __uvc_resume(struct usb_interface *intf, int reset) |
| 2379 | { |
| 2380 | struct uvc_device *dev = usb_get_intfdata(intf); |
| 2381 | struct uvc_streaming *stream; |
| 2382 | int ret = 0; |
| 2383 | |
| 2384 | uvc_dbg(dev, SUSPEND, "Resuming interface %u\n" , |
| 2385 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 2386 | |
| 2387 | if (intf->cur_altsetting->desc.bInterfaceSubClass == |
| 2388 | UVC_SC_VIDEOCONTROL) { |
| 2389 | if (reset) { |
| 2390 | ret = uvc_ctrl_restore_values(dev); |
| 2391 | if (ret < 0) |
| 2392 | return ret; |
| 2393 | } |
| 2394 | |
| 2395 | return uvc_status_resume(dev); |
| 2396 | } |
| 2397 | |
| 2398 | list_for_each_entry(stream, &dev->streams, list) { |
| 2399 | if (stream->intf == intf) { |
| 2400 | ret = uvc_video_resume(stream, reset); |
| 2401 | if (ret < 0) |
| 2402 | uvc_queue_streamoff(queue: &stream->queue, |
| 2403 | type: stream->queue.queue.type); |
| 2404 | return ret; |
| 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | uvc_dbg(dev, SUSPEND, |
| 2409 | "Resume: video streaming USB interface mismatch\n" ); |
| 2410 | return -EINVAL; |
| 2411 | } |
| 2412 | |
| 2413 | static int uvc_resume(struct usb_interface *intf) |
| 2414 | { |
| 2415 | return __uvc_resume(intf, reset: 0); |
| 2416 | } |
| 2417 | |
| 2418 | static int uvc_reset_resume(struct usb_interface *intf) |
| 2419 | { |
| 2420 | return __uvc_resume(intf, reset: 1); |
| 2421 | } |
| 2422 | |
| 2423 | /* ------------------------------------------------------------------------ |
| 2424 | * Module parameters |
| 2425 | */ |
| 2426 | |
| 2427 | static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp) |
| 2428 | { |
| 2429 | if (uvc_clock_param == CLOCK_MONOTONIC) |
| 2430 | return sprintf(buf: buffer, fmt: "CLOCK_MONOTONIC" ); |
| 2431 | else |
| 2432 | return sprintf(buf: buffer, fmt: "CLOCK_REALTIME" ); |
| 2433 | } |
| 2434 | |
| 2435 | static int uvc_clock_param_set(const char *val, const struct kernel_param *kp) |
| 2436 | { |
| 2437 | if (strncasecmp(s1: val, s2: "clock_" , strlen("clock_" )) == 0) |
| 2438 | val += strlen("clock_" ); |
| 2439 | |
| 2440 | if (strcasecmp(s1: val, s2: "monotonic" ) == 0) |
| 2441 | uvc_clock_param = CLOCK_MONOTONIC; |
| 2442 | else if (strcasecmp(s1: val, s2: "realtime" ) == 0) |
| 2443 | uvc_clock_param = CLOCK_REALTIME; |
| 2444 | else |
| 2445 | return -EINVAL; |
| 2446 | |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
| 2450 | module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get, |
| 2451 | &uvc_clock_param, 0644); |
| 2452 | MODULE_PARM_DESC(clock, "Video buffers timestamp clock" ); |
| 2453 | module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, 0644); |
| 2454 | MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps" ); |
| 2455 | |
| 2456 | static int param_set_nodrop(const char *val, const struct kernel_param *kp) |
| 2457 | { |
| 2458 | pr_warn_once("uvcvideo: " |
| 2459 | DEPRECATED |
| 2460 | "nodrop parameter will be eventually removed.\n" ); |
| 2461 | return param_set_bool(val, kp); |
| 2462 | } |
| 2463 | |
| 2464 | static const struct kernel_param_ops param_ops_nodrop = { |
| 2465 | .set = param_set_nodrop, |
| 2466 | .get = param_get_uint, |
| 2467 | }; |
| 2468 | |
| 2469 | param_check_uint(nodrop, &uvc_no_drop_param); |
| 2470 | module_param_cb(nodrop, ¶m_ops_nodrop, &uvc_no_drop_param, 0644); |
| 2471 | __MODULE_PARM_TYPE(nodrop, "uint" ); |
| 2472 | MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames" ); |
| 2473 | |
| 2474 | module_param_named(quirks, uvc_quirks_param, uint, 0644); |
| 2475 | MODULE_PARM_DESC(quirks, "Forced device quirks" ); |
| 2476 | module_param_named(trace, uvc_dbg_param, uint, 0644); |
| 2477 | MODULE_PARM_DESC(trace, "Trace level bitmask" ); |
| 2478 | module_param_named(timeout, uvc_timeout_param, uint, 0644); |
| 2479 | MODULE_PARM_DESC(timeout, "Streaming control requests timeout" ); |
| 2480 | |
| 2481 | /* ------------------------------------------------------------------------ |
| 2482 | * Driver initialization and cleanup |
| 2483 | */ |
| 2484 | |
| 2485 | static const struct uvc_device_info uvc_quirk_probe_minmax = { |
| 2486 | .quirks = UVC_QUIRK_PROBE_MINMAX, |
| 2487 | }; |
| 2488 | |
| 2489 | static const struct uvc_device_info uvc_quirk_fix_bandwidth = { |
| 2490 | .quirks = UVC_QUIRK_FIX_BANDWIDTH, |
| 2491 | }; |
| 2492 | |
| 2493 | static const struct uvc_device_info uvc_quirk_probe_def = { |
| 2494 | .quirks = UVC_QUIRK_PROBE_DEF, |
| 2495 | }; |
| 2496 | |
| 2497 | static const struct uvc_device_info uvc_quirk_stream_no_fid = { |
| 2498 | .quirks = UVC_QUIRK_STREAM_NO_FID, |
| 2499 | }; |
| 2500 | |
| 2501 | static const struct uvc_device_info uvc_quirk_force_y8 = { |
| 2502 | .quirks = UVC_QUIRK_FORCE_Y8, |
| 2503 | }; |
| 2504 | |
| 2505 | #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q} |
| 2506 | #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \ |
| 2507 | {.meta_format = m} |
| 2508 | |
| 2509 | /* |
| 2510 | * The Logitech cameras listed below have their interface class set to |
| 2511 | * VENDOR_SPEC because they don't announce themselves as UVC devices, even |
| 2512 | * though they are compliant. |
| 2513 | * |
| 2514 | * Sort these by vendor/product ID. |
| 2515 | */ |
| 2516 | static const struct usb_device_id uvc_ids[] = { |
| 2517 | /* Quanta ACER HD User Facing */ |
| 2518 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2519 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2520 | .idVendor = 0x0408, |
| 2521 | .idProduct = 0x4033, |
| 2522 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2523 | .bInterfaceSubClass = 1, |
| 2524 | .bInterfaceProtocol = UVC_PC_PROTOCOL_15, |
| 2525 | .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){ |
| 2526 | .uvc_version = 0x010a, |
| 2527 | } }, |
| 2528 | /* Quanta ACER HD User Facing */ |
| 2529 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2530 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2531 | .idVendor = 0x0408, |
| 2532 | .idProduct = 0x4035, |
| 2533 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2534 | .bInterfaceSubClass = 1, |
| 2535 | .bInterfaceProtocol = UVC_PC_PROTOCOL_15, |
| 2536 | .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){ |
| 2537 | .uvc_version = 0x010a, |
| 2538 | } }, |
| 2539 | /* LogiLink Wireless Webcam */ |
| 2540 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2541 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2542 | .idVendor = 0x0416, |
| 2543 | .idProduct = 0xa91a, |
| 2544 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2545 | .bInterfaceSubClass = 1, |
| 2546 | .bInterfaceProtocol = 0, |
| 2547 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2548 | /* Genius eFace 2025 */ |
| 2549 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2550 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2551 | .idVendor = 0x0458, |
| 2552 | .idProduct = 0x706e, |
| 2553 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2554 | .bInterfaceSubClass = 1, |
| 2555 | .bInterfaceProtocol = 0, |
| 2556 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2557 | /* Microsoft Lifecam NX-6000 */ |
| 2558 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2559 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2560 | .idVendor = 0x045e, |
| 2561 | .idProduct = 0x00f8, |
| 2562 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2563 | .bInterfaceSubClass = 1, |
| 2564 | .bInterfaceProtocol = 0, |
| 2565 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2566 | /* Microsoft Lifecam NX-3000 */ |
| 2567 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2568 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2569 | .idVendor = 0x045e, |
| 2570 | .idProduct = 0x0721, |
| 2571 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2572 | .bInterfaceSubClass = 1, |
| 2573 | .bInterfaceProtocol = 0, |
| 2574 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2575 | /* Microsoft Lifecam VX-7000 */ |
| 2576 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2577 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2578 | .idVendor = 0x045e, |
| 2579 | .idProduct = 0x0723, |
| 2580 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2581 | .bInterfaceSubClass = 1, |
| 2582 | .bInterfaceProtocol = 0, |
| 2583 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2584 | /* Logitech, Webcam C910 */ |
| 2585 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2586 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2587 | .idVendor = 0x046d, |
| 2588 | .idProduct = 0x0821, |
| 2589 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2590 | .bInterfaceSubClass = 1, |
| 2591 | .bInterfaceProtocol = 0, |
| 2592 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)}, |
| 2593 | /* Logitech, Webcam B910 */ |
| 2594 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2595 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2596 | .idVendor = 0x046d, |
| 2597 | .idProduct = 0x0823, |
| 2598 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2599 | .bInterfaceSubClass = 1, |
| 2600 | .bInterfaceProtocol = 0, |
| 2601 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)}, |
| 2602 | /* Logitech Quickcam Fusion */ |
| 2603 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2604 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2605 | .idVendor = 0x046d, |
| 2606 | .idProduct = 0x08c1, |
| 2607 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2608 | .bInterfaceSubClass = 1, |
| 2609 | .bInterfaceProtocol = 0 }, |
| 2610 | /* Logitech Quickcam Orbit MP */ |
| 2611 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2612 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2613 | .idVendor = 0x046d, |
| 2614 | .idProduct = 0x08c2, |
| 2615 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2616 | .bInterfaceSubClass = 1, |
| 2617 | .bInterfaceProtocol = 0 }, |
| 2618 | /* Logitech Quickcam Pro for Notebook */ |
| 2619 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2620 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2621 | .idVendor = 0x046d, |
| 2622 | .idProduct = 0x08c3, |
| 2623 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2624 | .bInterfaceSubClass = 1, |
| 2625 | .bInterfaceProtocol = 0 }, |
| 2626 | /* Logitech Quickcam Pro 5000 */ |
| 2627 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2628 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2629 | .idVendor = 0x046d, |
| 2630 | .idProduct = 0x08c5, |
| 2631 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2632 | .bInterfaceSubClass = 1, |
| 2633 | .bInterfaceProtocol = 0 }, |
| 2634 | /* Logitech Quickcam OEM Dell Notebook */ |
| 2635 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2636 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2637 | .idVendor = 0x046d, |
| 2638 | .idProduct = 0x08c6, |
| 2639 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2640 | .bInterfaceSubClass = 1, |
| 2641 | .bInterfaceProtocol = 0 }, |
| 2642 | /* Logitech Quickcam OEM Cisco VT Camera II */ |
| 2643 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2644 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2645 | .idVendor = 0x046d, |
| 2646 | .idProduct = 0x08c7, |
| 2647 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2648 | .bInterfaceSubClass = 1, |
| 2649 | .bInterfaceProtocol = 0 }, |
| 2650 | /* Logitech HD Pro Webcam C920 */ |
| 2651 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2652 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2653 | .idVendor = 0x046d, |
| 2654 | .idProduct = 0x082d, |
| 2655 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2656 | .bInterfaceSubClass = 1, |
| 2657 | .bInterfaceProtocol = 0, |
| 2658 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT |
| 2659 | | UVC_QUIRK_INVALID_DEVICE_SOF) }, |
| 2660 | /* Logitech HD Pro Webcam C922 */ |
| 2661 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2662 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2663 | .idVendor = 0x046d, |
| 2664 | .idProduct = 0x085c, |
| 2665 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2666 | .bInterfaceSubClass = 1, |
| 2667 | .bInterfaceProtocol = 0, |
| 2668 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_INVALID_DEVICE_SOF) }, |
| 2669 | /* Logitech Rally Bar Huddle */ |
| 2670 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2671 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2672 | .idVendor = 0x046d, |
| 2673 | .idProduct = 0x087c, |
| 2674 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2675 | .bInterfaceSubClass = 1, |
| 2676 | .bInterfaceProtocol = 0, |
| 2677 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) }, |
| 2678 | /* Logitech Rally Bar */ |
| 2679 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2680 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2681 | .idVendor = 0x046d, |
| 2682 | .idProduct = 0x089b, |
| 2683 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2684 | .bInterfaceSubClass = 1, |
| 2685 | .bInterfaceProtocol = 0, |
| 2686 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) }, |
| 2687 | /* Logitech Rally Bar Mini */ |
| 2688 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2689 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2690 | .idVendor = 0x046d, |
| 2691 | .idProduct = 0x08d3, |
| 2692 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2693 | .bInterfaceSubClass = 1, |
| 2694 | .bInterfaceProtocol = 0, |
| 2695 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) }, |
| 2696 | /* Chicony CNF7129 (Asus EEE 100HE) */ |
| 2697 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2698 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2699 | .idVendor = 0x04f2, |
| 2700 | .idProduct = 0xb071, |
| 2701 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2702 | .bInterfaceSubClass = 1, |
| 2703 | .bInterfaceProtocol = 0, |
| 2704 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) }, |
| 2705 | /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */ |
| 2706 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2707 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2708 | .idVendor = 0x058f, |
| 2709 | .idProduct = 0x3820, |
| 2710 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2711 | .bInterfaceSubClass = 1, |
| 2712 | .bInterfaceProtocol = 0, |
| 2713 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2714 | /* Dell XPS m1530 */ |
| 2715 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2716 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2717 | .idVendor = 0x05a9, |
| 2718 | .idProduct = 0x2640, |
| 2719 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2720 | .bInterfaceSubClass = 1, |
| 2721 | .bInterfaceProtocol = 0, |
| 2722 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2723 | /* Dell SP2008WFP Monitor */ |
| 2724 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2725 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2726 | .idVendor = 0x05a9, |
| 2727 | .idProduct = 0x2641, |
| 2728 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2729 | .bInterfaceSubClass = 1, |
| 2730 | .bInterfaceProtocol = 0, |
| 2731 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2732 | /* Dell Alienware X51 */ |
| 2733 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2734 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2735 | .idVendor = 0x05a9, |
| 2736 | .idProduct = 0x2643, |
| 2737 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2738 | .bInterfaceSubClass = 1, |
| 2739 | .bInterfaceProtocol = 0, |
| 2740 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2741 | /* Dell Studio Hybrid 140g (OmniVision webcam) */ |
| 2742 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2743 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2744 | .idVendor = 0x05a9, |
| 2745 | .idProduct = 0x264a, |
| 2746 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2747 | .bInterfaceSubClass = 1, |
| 2748 | .bInterfaceProtocol = 0, |
| 2749 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2750 | /* Dell XPS M1330 (OmniVision OV7670 webcam) */ |
| 2751 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2752 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2753 | .idVendor = 0x05a9, |
| 2754 | .idProduct = 0x7670, |
| 2755 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2756 | .bInterfaceSubClass = 1, |
| 2757 | .bInterfaceProtocol = 0, |
| 2758 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2759 | /* Apple Built-In iSight */ |
| 2760 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2761 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2762 | .idVendor = 0x05ac, |
| 2763 | .idProduct = 0x8501, |
| 2764 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2765 | .bInterfaceSubClass = 1, |
| 2766 | .bInterfaceProtocol = 0, |
| 2767 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX |
| 2768 | | UVC_QUIRK_BUILTIN_ISIGHT) }, |
| 2769 | /* Apple FaceTime HD Camera (Built-In) */ |
| 2770 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2771 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2772 | .idVendor = 0x05ac, |
| 2773 | .idProduct = 0x8514, |
| 2774 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2775 | .bInterfaceSubClass = 1, |
| 2776 | .bInterfaceProtocol = 0, |
| 2777 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2778 | /* Apple Built-In iSight via iBridge */ |
| 2779 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2780 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2781 | .idVendor = 0x05ac, |
| 2782 | .idProduct = 0x8600, |
| 2783 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2784 | .bInterfaceSubClass = 1, |
| 2785 | .bInterfaceProtocol = 0, |
| 2786 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 2787 | /* Foxlink ("HP Webcam" on HP Mini 5103) */ |
| 2788 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2789 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2790 | .idVendor = 0x05c8, |
| 2791 | .idProduct = 0x0403, |
| 2792 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2793 | .bInterfaceSubClass = 1, |
| 2794 | .bInterfaceProtocol = 0, |
| 2795 | .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, |
| 2796 | /* Genesys Logic USB 2.0 PC Camera */ |
| 2797 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2798 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2799 | .idVendor = 0x05e3, |
| 2800 | .idProduct = 0x0505, |
| 2801 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2802 | .bInterfaceSubClass = 1, |
| 2803 | .bInterfaceProtocol = 0, |
| 2804 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2805 | /* Hercules Classic Silver */ |
| 2806 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2807 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2808 | .idVendor = 0x06f8, |
| 2809 | .idProduct = 0x300c, |
| 2810 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2811 | .bInterfaceSubClass = 1, |
| 2812 | .bInterfaceProtocol = 0, |
| 2813 | .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, |
| 2814 | /* ViMicro Vega */ |
| 2815 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2816 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2817 | .idVendor = 0x0ac8, |
| 2818 | .idProduct = 0x332d, |
| 2819 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2820 | .bInterfaceSubClass = 1, |
| 2821 | .bInterfaceProtocol = 0, |
| 2822 | .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, |
| 2823 | /* ViMicro - Minoru3D */ |
| 2824 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2825 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2826 | .idVendor = 0x0ac8, |
| 2827 | .idProduct = 0x3410, |
| 2828 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2829 | .bInterfaceSubClass = 1, |
| 2830 | .bInterfaceProtocol = 0, |
| 2831 | .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, |
| 2832 | /* ViMicro Venus - Minoru3D */ |
| 2833 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2834 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2835 | .idVendor = 0x0ac8, |
| 2836 | .idProduct = 0x3420, |
| 2837 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2838 | .bInterfaceSubClass = 1, |
| 2839 | .bInterfaceProtocol = 0, |
| 2840 | .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, |
| 2841 | /* Ophir Optronics - SPCAM 620U */ |
| 2842 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2843 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2844 | .idVendor = 0x0bd3, |
| 2845 | .idProduct = 0x0555, |
| 2846 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2847 | .bInterfaceSubClass = 1, |
| 2848 | .bInterfaceProtocol = 0, |
| 2849 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2850 | /* Sonix Technology Co. Ltd. - 292A IPC AR0330 */ |
| 2851 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2852 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2853 | .idVendor = 0x0c45, |
| 2854 | .idProduct = 0x6366, |
| 2855 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2856 | .bInterfaceSubClass = 1, |
| 2857 | .bInterfaceProtocol = 0, |
| 2858 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) }, |
| 2859 | /* MT6227 */ |
| 2860 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2861 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2862 | .idVendor = 0x0e8d, |
| 2863 | .idProduct = 0x0004, |
| 2864 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2865 | .bInterfaceSubClass = 1, |
| 2866 | .bInterfaceProtocol = 0, |
| 2867 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX |
| 2868 | | UVC_QUIRK_PROBE_DEF) }, |
| 2869 | /* IMC Networks (Medion Akoya) */ |
| 2870 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2871 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2872 | .idVendor = 0x13d3, |
| 2873 | .idProduct = 0x5103, |
| 2874 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2875 | .bInterfaceSubClass = 1, |
| 2876 | .bInterfaceProtocol = 0, |
| 2877 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2878 | /* JMicron USB2.0 XGA WebCam */ |
| 2879 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2880 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2881 | .idVendor = 0x152d, |
| 2882 | .idProduct = 0x0310, |
| 2883 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2884 | .bInterfaceSubClass = 1, |
| 2885 | .bInterfaceProtocol = 0, |
| 2886 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 2887 | /* Kurokesu C1 PRO */ |
| 2888 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2889 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2890 | .idVendor = 0x16d0, |
| 2891 | .idProduct = 0x0ed1, |
| 2892 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2893 | .bInterfaceSubClass = 1, |
| 2894 | .bInterfaceProtocol = 0, |
| 2895 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) }, |
| 2896 | /* Syntek (HP Spartan) */ |
| 2897 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2898 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2899 | .idVendor = 0x174f, |
| 2900 | .idProduct = 0x5212, |
| 2901 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2902 | .bInterfaceSubClass = 1, |
| 2903 | .bInterfaceProtocol = 0, |
| 2904 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2905 | /* Syntek (Samsung Q310) */ |
| 2906 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2907 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2908 | .idVendor = 0x174f, |
| 2909 | .idProduct = 0x5931, |
| 2910 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2911 | .bInterfaceSubClass = 1, |
| 2912 | .bInterfaceProtocol = 0, |
| 2913 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2914 | /* Syntek (Packard Bell EasyNote MX52 */ |
| 2915 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2916 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2917 | .idVendor = 0x174f, |
| 2918 | .idProduct = 0x8a12, |
| 2919 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2920 | .bInterfaceSubClass = 1, |
| 2921 | .bInterfaceProtocol = 0, |
| 2922 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2923 | /* Syntek (Asus F9SG) */ |
| 2924 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2925 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2926 | .idVendor = 0x174f, |
| 2927 | .idProduct = 0x8a31, |
| 2928 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2929 | .bInterfaceSubClass = 1, |
| 2930 | .bInterfaceProtocol = 0, |
| 2931 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2932 | /* Syntek (Asus U3S) */ |
| 2933 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2934 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2935 | .idVendor = 0x174f, |
| 2936 | .idProduct = 0x8a33, |
| 2937 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2938 | .bInterfaceSubClass = 1, |
| 2939 | .bInterfaceProtocol = 0, |
| 2940 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2941 | /* Syntek (JAOtech Smart Terminal) */ |
| 2942 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2943 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2944 | .idVendor = 0x174f, |
| 2945 | .idProduct = 0x8a34, |
| 2946 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2947 | .bInterfaceSubClass = 1, |
| 2948 | .bInterfaceProtocol = 0, |
| 2949 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2950 | /* Miricle 307K */ |
| 2951 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2952 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2953 | .idVendor = 0x17dc, |
| 2954 | .idProduct = 0x0202, |
| 2955 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2956 | .bInterfaceSubClass = 1, |
| 2957 | .bInterfaceProtocol = 0, |
| 2958 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2959 | /* Lenovo Thinkpad SL400/SL500 */ |
| 2960 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2961 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2962 | .idVendor = 0x17ef, |
| 2963 | .idProduct = 0x480b, |
| 2964 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2965 | .bInterfaceSubClass = 1, |
| 2966 | .bInterfaceProtocol = 0, |
| 2967 | .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, |
| 2968 | /* Aveo Technology USB 2.0 Camera */ |
| 2969 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2970 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2971 | .idVendor = 0x1871, |
| 2972 | .idProduct = 0x0306, |
| 2973 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2974 | .bInterfaceSubClass = 1, |
| 2975 | .bInterfaceProtocol = 0, |
| 2976 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX |
| 2977 | | UVC_QUIRK_PROBE_EXTRAFIELDS) }, |
| 2978 | /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */ |
| 2979 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2980 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2981 | .idVendor = 0x1871, |
| 2982 | .idProduct = 0x0516, |
| 2983 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 2984 | .bInterfaceSubClass = 1, |
| 2985 | .bInterfaceProtocol = 0 }, |
| 2986 | /* Ecamm Pico iMage */ |
| 2987 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2988 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2989 | .idVendor = 0x18cd, |
| 2990 | .idProduct = 0xcafe, |
| 2991 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 2992 | .bInterfaceSubClass = 1, |
| 2993 | .bInterfaceProtocol = 0, |
| 2994 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) }, |
| 2995 | /* Manta MM-353 Plako */ |
| 2996 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 2997 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 2998 | .idVendor = 0x18ec, |
| 2999 | .idProduct = 0x3188, |
| 3000 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3001 | .bInterfaceSubClass = 1, |
| 3002 | .bInterfaceProtocol = 0, |
| 3003 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 3004 | /* FSC WebCam V30S */ |
| 3005 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3006 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3007 | .idVendor = 0x18ec, |
| 3008 | .idProduct = 0x3288, |
| 3009 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3010 | .bInterfaceSubClass = 1, |
| 3011 | .bInterfaceProtocol = 0, |
| 3012 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 3013 | /* Arkmicro unbranded */ |
| 3014 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3015 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3016 | .idVendor = 0x18ec, |
| 3017 | .idProduct = 0x3290, |
| 3018 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3019 | .bInterfaceSubClass = 1, |
| 3020 | .bInterfaceProtocol = 0, |
| 3021 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, |
| 3022 | /* The Imaging Source USB CCD cameras */ |
| 3023 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3024 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3025 | .idVendor = 0x199e, |
| 3026 | .idProduct = 0x8102, |
| 3027 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 3028 | .bInterfaceSubClass = 1, |
| 3029 | .bInterfaceProtocol = 0 }, |
| 3030 | /* Bodelin ProScopeHR */ |
| 3031 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3032 | | USB_DEVICE_ID_MATCH_DEV_HI |
| 3033 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3034 | .idVendor = 0x19ab, |
| 3035 | .idProduct = 0x1000, |
| 3036 | .bcdDevice_hi = 0x0126, |
| 3037 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3038 | .bInterfaceSubClass = 1, |
| 3039 | .bInterfaceProtocol = 0, |
| 3040 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) }, |
| 3041 | /* MSI StarCam 370i */ |
| 3042 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3043 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3044 | .idVendor = 0x1b3b, |
| 3045 | .idProduct = 0x2951, |
| 3046 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3047 | .bInterfaceSubClass = 1, |
| 3048 | .bInterfaceProtocol = 0, |
| 3049 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 3050 | /* Generalplus Technology Inc. 808 Camera */ |
| 3051 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3052 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3053 | .idVendor = 0x1b3f, |
| 3054 | .idProduct = 0x2002, |
| 3055 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3056 | .bInterfaceSubClass = 1, |
| 3057 | .bInterfaceProtocol = 0, |
| 3058 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 3059 | /* Shenzhen Aoni Electronic Co.,Ltd 2K FHD camera */ |
| 3060 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3061 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3062 | .idVendor = 0x1bcf, |
| 3063 | .idProduct = 0x0b40, |
| 3064 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3065 | .bInterfaceSubClass = 1, |
| 3066 | .bInterfaceProtocol = 0, |
| 3067 | .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){ |
| 3068 | .uvc_version = 0x010a, |
| 3069 | } }, |
| 3070 | /* SiGma Micro USB Web Camera */ |
| 3071 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3072 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3073 | .idVendor = 0x1c4f, |
| 3074 | .idProduct = 0x3000, |
| 3075 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3076 | .bInterfaceSubClass = 1, |
| 3077 | .bInterfaceProtocol = 0, |
| 3078 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX |
| 3079 | | UVC_QUIRK_IGNORE_SELECTOR_UNIT) }, |
| 3080 | /* Actions Microelectronics Co. Display capture-UVC05 */ |
| 3081 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3082 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3083 | .idVendor = 0x1de1, |
| 3084 | .idProduct = 0xf105, |
| 3085 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3086 | .bInterfaceSubClass = 1, |
| 3087 | .bInterfaceProtocol = 0, |
| 3088 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) }, |
| 3089 | /* NXP Semiconductors IR VIDEO */ |
| 3090 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3091 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3092 | .idVendor = 0x1fc9, |
| 3093 | .idProduct = 0x009b, |
| 3094 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3095 | .bInterfaceSubClass = 1, |
| 3096 | .bInterfaceProtocol = 0, |
| 3097 | .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, |
| 3098 | /* Oculus VR Positional Tracker DK2 */ |
| 3099 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3100 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3101 | .idVendor = 0x2833, |
| 3102 | .idProduct = 0x0201, |
| 3103 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3104 | .bInterfaceSubClass = 1, |
| 3105 | .bInterfaceProtocol = 0, |
| 3106 | .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 }, |
| 3107 | /* Oculus VR Rift Sensor */ |
| 3108 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3109 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3110 | .idVendor = 0x2833, |
| 3111 | .idProduct = 0x0211, |
| 3112 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 3113 | .bInterfaceSubClass = 1, |
| 3114 | .bInterfaceProtocol = 0, |
| 3115 | .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 }, |
| 3116 | /* GEO Semiconductor GC6500 */ |
| 3117 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3118 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3119 | .idVendor = 0x29fe, |
| 3120 | .idProduct = 0x4d53, |
| 3121 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3122 | .bInterfaceSubClass = 1, |
| 3123 | .bInterfaceProtocol = 0, |
| 3124 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) }, |
| 3125 | /* Insta360 Link */ |
| 3126 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3127 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3128 | .idVendor = 0x2e1a, |
| 3129 | .idProduct = 0x4c01, |
| 3130 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3131 | .bInterfaceSubClass = 1, |
| 3132 | .bInterfaceProtocol = 0, |
| 3133 | .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) }, |
| 3134 | /* Intel D410/ASR depth camera */ |
| 3135 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3136 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3137 | .idVendor = 0x8086, |
| 3138 | .idProduct = 0x0ad2, |
| 3139 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3140 | .bInterfaceSubClass = 1, |
| 3141 | .bInterfaceProtocol = 0, |
| 3142 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3143 | /* Intel D415/ASRC depth camera */ |
| 3144 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3145 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3146 | .idVendor = 0x8086, |
| 3147 | .idProduct = 0x0ad3, |
| 3148 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3149 | .bInterfaceSubClass = 1, |
| 3150 | .bInterfaceProtocol = 0, |
| 3151 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3152 | /* Intel D430/AWG depth camera */ |
| 3153 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3154 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3155 | .idVendor = 0x8086, |
| 3156 | .idProduct = 0x0ad4, |
| 3157 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3158 | .bInterfaceSubClass = 1, |
| 3159 | .bInterfaceProtocol = 0, |
| 3160 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3161 | /* Intel RealSense D4M */ |
| 3162 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3163 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3164 | .idVendor = 0x8086, |
| 3165 | .idProduct = 0x0b03, |
| 3166 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3167 | .bInterfaceSubClass = 1, |
| 3168 | .bInterfaceProtocol = 0, |
| 3169 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3170 | /* Intel D435/AWGC depth camera */ |
| 3171 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3172 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3173 | .idVendor = 0x8086, |
| 3174 | .idProduct = 0x0b07, |
| 3175 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3176 | .bInterfaceSubClass = 1, |
| 3177 | .bInterfaceProtocol = 0, |
| 3178 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3179 | /* Intel D435i depth camera */ |
| 3180 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3181 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3182 | .idVendor = 0x8086, |
| 3183 | .idProduct = 0x0b3a, |
| 3184 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3185 | .bInterfaceSubClass = 1, |
| 3186 | .bInterfaceProtocol = 0, |
| 3187 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3188 | /* Intel D405 Depth Camera */ |
| 3189 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3190 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3191 | .idVendor = 0x8086, |
| 3192 | .idProduct = 0x0b5b, |
| 3193 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3194 | .bInterfaceSubClass = 1, |
| 3195 | .bInterfaceProtocol = 0, |
| 3196 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3197 | /* Intel D455 Depth Camera */ |
| 3198 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3199 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3200 | .idVendor = 0x8086, |
| 3201 | .idProduct = 0x0b5c, |
| 3202 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3203 | .bInterfaceSubClass = 1, |
| 3204 | .bInterfaceProtocol = 0, |
| 3205 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3206 | /* Intel D421 Depth Module */ |
| 3207 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
| 3208 | | USB_DEVICE_ID_MATCH_INT_INFO, |
| 3209 | .idVendor = 0x8086, |
| 3210 | .idProduct = 0x1155, |
| 3211 | .bInterfaceClass = USB_CLASS_VIDEO, |
| 3212 | .bInterfaceSubClass = 1, |
| 3213 | .bInterfaceProtocol = 0, |
| 3214 | .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, |
| 3215 | /* Generic USB Video Class */ |
| 3216 | { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) }, |
| 3217 | { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) }, |
| 3218 | {} |
| 3219 | }; |
| 3220 | |
| 3221 | MODULE_DEVICE_TABLE(usb, uvc_ids); |
| 3222 | |
| 3223 | static struct usb_driver uvc_driver = { |
| 3224 | .name = "uvcvideo" , |
| 3225 | .probe = uvc_probe, |
| 3226 | .disconnect = uvc_disconnect, |
| 3227 | .suspend = uvc_suspend, |
| 3228 | .resume = uvc_resume, |
| 3229 | .reset_resume = uvc_reset_resume, |
| 3230 | .id_table = uvc_ids, |
| 3231 | .supports_autosuspend = 1, |
| 3232 | }; |
| 3233 | |
| 3234 | static int __init uvc_init(void) |
| 3235 | { |
| 3236 | int ret; |
| 3237 | |
| 3238 | uvc_debugfs_init(); |
| 3239 | |
| 3240 | ret = usb_register(&uvc_driver); |
| 3241 | if (ret < 0) { |
| 3242 | uvc_debugfs_cleanup(); |
| 3243 | return ret; |
| 3244 | } |
| 3245 | |
| 3246 | return 0; |
| 3247 | } |
| 3248 | |
| 3249 | static void __exit uvc_cleanup(void) |
| 3250 | { |
| 3251 | usb_deregister(&uvc_driver); |
| 3252 | uvc_debugfs_cleanup(); |
| 3253 | } |
| 3254 | |
| 3255 | module_init(uvc_init); |
| 3256 | module_exit(uvc_cleanup); |
| 3257 | |
| 3258 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 3259 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 3260 | MODULE_LICENSE("GPL" ); |
| 3261 | MODULE_VERSION(DRIVER_VERSION); |
| 3262 | |
| 3263 | |