12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 20c0d06caSMauro Carvalho Chehab /* 30c0d06caSMauro Carvalho Chehab * uvc_driver.c -- USB Video Class driver 40c0d06caSMauro Carvalho Chehab * 50c0d06caSMauro Carvalho Chehab * Copyright (C) 2005-2010 60c0d06caSMauro Carvalho Chehab * Laurent Pinchart (laurent.pinchart@ideasonboard.com) 70c0d06caSMauro Carvalho Chehab */ 80c0d06caSMauro Carvalho Chehab 90c0d06caSMauro Carvalho Chehab #include <linux/atomic.h> 10*2886477fSRicardo Ribalda #include <linux/gpio/consumer.h> 110c0d06caSMauro Carvalho Chehab #include <linux/kernel.h> 120c0d06caSMauro Carvalho Chehab #include <linux/list.h> 130c0d06caSMauro Carvalho Chehab #include <linux/module.h> 140c0d06caSMauro Carvalho Chehab #include <linux/slab.h> 150c0d06caSMauro Carvalho Chehab #include <linux/usb.h> 160c0d06caSMauro Carvalho Chehab #include <linux/videodev2.h> 170c0d06caSMauro Carvalho Chehab #include <linux/vmalloc.h> 180c0d06caSMauro Carvalho Chehab #include <linux/wait.h> 190c0d06caSMauro Carvalho Chehab #include <linux/version.h> 200c0d06caSMauro Carvalho Chehab #include <asm/unaligned.h> 210c0d06caSMauro Carvalho Chehab 220c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h> 2331a96f4cSLaurent Pinchart #include <media/v4l2-ioctl.h> 240c0d06caSMauro Carvalho Chehab 250c0d06caSMauro Carvalho Chehab #include "uvcvideo.h" 260c0d06caSMauro Carvalho Chehab 270c0d06caSMauro Carvalho Chehab #define DRIVER_AUTHOR "Laurent Pinchart " \ 280c0d06caSMauro Carvalho Chehab "<laurent.pinchart@ideasonboard.com>" 290c0d06caSMauro Carvalho Chehab #define DRIVER_DESC "USB Video Class driver" 300c0d06caSMauro Carvalho Chehab 310c0d06caSMauro Carvalho Chehab unsigned int uvc_clock_param = CLOCK_MONOTONIC; 325d0fd3c8SLaurent Pinchart unsigned int uvc_hw_timestamps_param; 330c0d06caSMauro Carvalho Chehab unsigned int uvc_no_drop_param; 340c0d06caSMauro Carvalho Chehab static unsigned int uvc_quirks_param = -1; 350c0d06caSMauro Carvalho Chehab unsigned int uvc_trace_param; 360c0d06caSMauro Carvalho Chehab unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT; 370c0d06caSMauro Carvalho Chehab 380c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 390c0d06caSMauro Carvalho Chehab * Video formats 400c0d06caSMauro Carvalho Chehab */ 410c0d06caSMauro Carvalho Chehab 420c0d06caSMauro Carvalho Chehab static struct uvc_format_desc uvc_fmts[] = { 430c0d06caSMauro Carvalho Chehab { 440c0d06caSMauro Carvalho Chehab .name = "YUV 4:2:2 (YUYV)", 450c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_YUY2, 460c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_YUYV, 470c0d06caSMauro Carvalho Chehab }, 480c0d06caSMauro Carvalho Chehab { 490c0d06caSMauro Carvalho Chehab .name = "YUV 4:2:2 (YUYV)", 500c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_YUY2_ISIGHT, 510c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_YUYV, 520c0d06caSMauro Carvalho Chehab }, 530c0d06caSMauro Carvalho Chehab { 540c0d06caSMauro Carvalho Chehab .name = "YUV 4:2:0 (NV12)", 550c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_NV12, 560c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_NV12, 570c0d06caSMauro Carvalho Chehab }, 580c0d06caSMauro Carvalho Chehab { 590c0d06caSMauro Carvalho Chehab .name = "MJPEG", 600c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_MJPEG, 610c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_MJPEG, 620c0d06caSMauro Carvalho Chehab }, 630c0d06caSMauro Carvalho Chehab { 640c0d06caSMauro Carvalho Chehab .name = "YVU 4:2:0 (YV12)", 650c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_YV12, 660c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_YVU420, 670c0d06caSMauro Carvalho Chehab }, 680c0d06caSMauro Carvalho Chehab { 690c0d06caSMauro Carvalho Chehab .name = "YUV 4:2:0 (I420)", 700c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_I420, 710c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_YUV420, 720c0d06caSMauro Carvalho Chehab }, 730c0d06caSMauro Carvalho Chehab { 740c0d06caSMauro Carvalho Chehab .name = "YUV 4:2:0 (M420)", 750c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_M420, 760c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_M420, 770c0d06caSMauro Carvalho Chehab }, 780c0d06caSMauro Carvalho Chehab { 790c0d06caSMauro Carvalho Chehab .name = "YUV 4:2:2 (UYVY)", 800c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_UYVY, 810c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_UYVY, 820c0d06caSMauro Carvalho Chehab }, 830c0d06caSMauro Carvalho Chehab { 840c0d06caSMauro Carvalho Chehab .name = "Greyscale 8-bit (Y800)", 850c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_Y800, 860c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_GREY, 870c0d06caSMauro Carvalho Chehab }, 880c0d06caSMauro Carvalho Chehab { 890c0d06caSMauro Carvalho Chehab .name = "Greyscale 8-bit (Y8 )", 900c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_Y8, 910c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_GREY, 920c0d06caSMauro Carvalho Chehab }, 930c0d06caSMauro Carvalho Chehab { 94e96cdc9aSNicolas Dufresne .name = "Greyscale 8-bit (D3DFMT_L8)", 95e96cdc9aSNicolas Dufresne .guid = UVC_GUID_FORMAT_D3DFMT_L8, 96e96cdc9aSNicolas Dufresne .fcc = V4L2_PIX_FMT_GREY, 97e96cdc9aSNicolas Dufresne }, 98e96cdc9aSNicolas Dufresne { 99557a5c7fSLaurent Pinchart .name = "IR 8-bit (L8_IR)", 100557a5c7fSLaurent Pinchart .guid = UVC_GUID_FORMAT_KSMEDIA_L8_IR, 101557a5c7fSLaurent Pinchart .fcc = V4L2_PIX_FMT_GREY, 102557a5c7fSLaurent Pinchart }, 103557a5c7fSLaurent Pinchart { 1040c0d06caSMauro Carvalho Chehab .name = "Greyscale 10-bit (Y10 )", 1050c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_Y10, 1060c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_Y10, 1070c0d06caSMauro Carvalho Chehab }, 1080c0d06caSMauro Carvalho Chehab { 1090c0d06caSMauro Carvalho Chehab .name = "Greyscale 12-bit (Y12 )", 1100c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_Y12, 1110c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_Y12, 1120c0d06caSMauro Carvalho Chehab }, 1130c0d06caSMauro Carvalho Chehab { 1140c0d06caSMauro Carvalho Chehab .name = "Greyscale 16-bit (Y16 )", 1150c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_Y16, 1160c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_Y16, 1170c0d06caSMauro Carvalho Chehab }, 1180c0d06caSMauro Carvalho Chehab { 119e72ed08eSEdgar Thier .name = "BGGR Bayer (BY8 )", 1200c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_BY8, 1210c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_SBGGR8, 1220c0d06caSMauro Carvalho Chehab }, 1230c0d06caSMauro Carvalho Chehab { 124e72ed08eSEdgar Thier .name = "BGGR Bayer (BA81)", 125e72ed08eSEdgar Thier .guid = UVC_GUID_FORMAT_BA81, 126e72ed08eSEdgar Thier .fcc = V4L2_PIX_FMT_SBGGR8, 127e72ed08eSEdgar Thier }, 128e72ed08eSEdgar Thier { 129e72ed08eSEdgar Thier .name = "GBRG Bayer (GBRG)", 130e72ed08eSEdgar Thier .guid = UVC_GUID_FORMAT_GBRG, 131e72ed08eSEdgar Thier .fcc = V4L2_PIX_FMT_SGBRG8, 132e72ed08eSEdgar Thier }, 133e72ed08eSEdgar Thier { 134e72ed08eSEdgar Thier .name = "GRBG Bayer (GRBG)", 135e72ed08eSEdgar Thier .guid = UVC_GUID_FORMAT_GRBG, 136e72ed08eSEdgar Thier .fcc = V4L2_PIX_FMT_SGRBG8, 137e72ed08eSEdgar Thier }, 138e72ed08eSEdgar Thier { 139e72ed08eSEdgar Thier .name = "RGGB Bayer (RGGB)", 140e72ed08eSEdgar Thier .guid = UVC_GUID_FORMAT_RGGB, 141e72ed08eSEdgar Thier .fcc = V4L2_PIX_FMT_SRGGB8, 142e72ed08eSEdgar Thier }, 143e72ed08eSEdgar Thier { 1440c0d06caSMauro Carvalho Chehab .name = "RGB565", 1450c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_RGBP, 1460c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_RGB565, 1470c0d06caSMauro Carvalho Chehab }, 1480c0d06caSMauro Carvalho Chehab { 1491b8dc322SWilliam Manley .name = "BGR 8:8:8 (BGR3)", 1501b8dc322SWilliam Manley .guid = UVC_GUID_FORMAT_BGR3, 1511b8dc322SWilliam Manley .fcc = V4L2_PIX_FMT_BGR24, 1521b8dc322SWilliam Manley }, 1531b8dc322SWilliam Manley { 1540c0d06caSMauro Carvalho Chehab .name = "H.264", 1550c0d06caSMauro Carvalho Chehab .guid = UVC_GUID_FORMAT_H264, 1560c0d06caSMauro Carvalho Chehab .fcc = V4L2_PIX_FMT_H264, 1570c0d06caSMauro Carvalho Chehab }, 1585d8d8db8SAviv Greenberg { 1595d8d8db8SAviv Greenberg .name = "Greyscale 8 L/R (Y8I)", 1605d8d8db8SAviv Greenberg .guid = UVC_GUID_FORMAT_Y8I, 1615d8d8db8SAviv Greenberg .fcc = V4L2_PIX_FMT_Y8I, 1625d8d8db8SAviv Greenberg }, 1635d8d8db8SAviv Greenberg { 1645d8d8db8SAviv Greenberg .name = "Greyscale 12 L/R (Y12I)", 1655d8d8db8SAviv Greenberg .guid = UVC_GUID_FORMAT_Y12I, 1665d8d8db8SAviv Greenberg .fcc = V4L2_PIX_FMT_Y12I, 1675d8d8db8SAviv Greenberg }, 1685d8d8db8SAviv Greenberg { 1695d8d8db8SAviv Greenberg .name = "Depth data 16-bit (Z16)", 1705d8d8db8SAviv Greenberg .guid = UVC_GUID_FORMAT_Z16, 1715d8d8db8SAviv Greenberg .fcc = V4L2_PIX_FMT_Z16, 1725d8d8db8SAviv Greenberg }, 1735d8d8db8SAviv Greenberg { 1745d8d8db8SAviv Greenberg .name = "Bayer 10-bit (SRGGB10P)", 1755d8d8db8SAviv Greenberg .guid = UVC_GUID_FORMAT_RW10, 1765d8d8db8SAviv Greenberg .fcc = V4L2_PIX_FMT_SRGGB10P, 1775d8d8db8SAviv Greenberg }, 178eb165a20SEdgar Thier { 179eb165a20SEdgar Thier .name = "Bayer 16-bit (SBGGR16)", 180eb165a20SEdgar Thier .guid = UVC_GUID_FORMAT_BG16, 181eb165a20SEdgar Thier .fcc = V4L2_PIX_FMT_SBGGR16, 182eb165a20SEdgar Thier }, 183eb165a20SEdgar Thier { 184eb165a20SEdgar Thier .name = "Bayer 16-bit (SGBRG16)", 185eb165a20SEdgar Thier .guid = UVC_GUID_FORMAT_GB16, 186eb165a20SEdgar Thier .fcc = V4L2_PIX_FMT_SGBRG16, 187eb165a20SEdgar Thier }, 188eb165a20SEdgar Thier { 189eb165a20SEdgar Thier .name = "Bayer 16-bit (SRGGB16)", 190eb165a20SEdgar Thier .guid = UVC_GUID_FORMAT_RG16, 191eb165a20SEdgar Thier .fcc = V4L2_PIX_FMT_SRGGB16, 192eb165a20SEdgar Thier }, 193eb165a20SEdgar Thier { 194eb165a20SEdgar Thier .name = "Bayer 16-bit (SGRBG16)", 195eb165a20SEdgar Thier .guid = UVC_GUID_FORMAT_GR16, 196eb165a20SEdgar Thier .fcc = V4L2_PIX_FMT_SGRBG16, 197eb165a20SEdgar Thier }, 198c4a0968aSDaniel Patrick Johnson { 199c4a0968aSDaniel Patrick Johnson .name = "Depth data 16-bit (Z16)", 200c4a0968aSDaniel Patrick Johnson .guid = UVC_GUID_FORMAT_INVZ, 201c4a0968aSDaniel Patrick Johnson .fcc = V4L2_PIX_FMT_Z16, 202c4a0968aSDaniel Patrick Johnson }, 203c4a0968aSDaniel Patrick Johnson { 204c4a0968aSDaniel Patrick Johnson .name = "Greyscale 10-bit (Y10 )", 205c4a0968aSDaniel Patrick Johnson .guid = UVC_GUID_FORMAT_INVI, 206c4a0968aSDaniel Patrick Johnson .fcc = V4L2_PIX_FMT_Y10, 207c4a0968aSDaniel Patrick Johnson }, 208c4a0968aSDaniel Patrick Johnson { 209c4a0968aSDaniel Patrick Johnson .name = "IR:Depth 26-bit (INZI)", 210c4a0968aSDaniel Patrick Johnson .guid = UVC_GUID_FORMAT_INZI, 211c4a0968aSDaniel Patrick Johnson .fcc = V4L2_PIX_FMT_INZI, 212c4a0968aSDaniel Patrick Johnson }, 21338e9b928SSergey Dorodnicov { 21438e9b928SSergey Dorodnicov .name = "4-bit Depth Confidence (Packed)", 21538e9b928SSergey Dorodnicov .guid = UVC_GUID_FORMAT_CNF4, 21638e9b928SSergey Dorodnicov .fcc = V4L2_PIX_FMT_CNF4, 21738e9b928SSergey Dorodnicov }, 21840b222b5SDmitry Buzdyk { 21940b222b5SDmitry Buzdyk .name = "HEVC", 22040b222b5SDmitry Buzdyk .guid = UVC_GUID_FORMAT_HEVC, 22140b222b5SDmitry Buzdyk .fcc = V4L2_PIX_FMT_HEVC, 22240b222b5SDmitry Buzdyk }, 2230c0d06caSMauro Carvalho Chehab }; 2240c0d06caSMauro Carvalho Chehab 2250c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 2260c0d06caSMauro Carvalho Chehab * Utility functions 2270c0d06caSMauro Carvalho Chehab */ 2280c0d06caSMauro Carvalho Chehab 2290c0d06caSMauro Carvalho Chehab struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, 2302c6b222cSLaurent Pinchart u8 epaddr) 2310c0d06caSMauro Carvalho Chehab { 2320c0d06caSMauro Carvalho Chehab struct usb_host_endpoint *ep; 2330c0d06caSMauro Carvalho Chehab unsigned int i; 2340c0d06caSMauro Carvalho Chehab 2350c0d06caSMauro Carvalho Chehab for (i = 0; i < alts->desc.bNumEndpoints; ++i) { 2360c0d06caSMauro Carvalho Chehab ep = &alts->endpoint[i]; 2370c0d06caSMauro Carvalho Chehab if (ep->desc.bEndpointAddress == epaddr) 2380c0d06caSMauro Carvalho Chehab return ep; 2390c0d06caSMauro Carvalho Chehab } 2400c0d06caSMauro Carvalho Chehab 2410c0d06caSMauro Carvalho Chehab return NULL; 2420c0d06caSMauro Carvalho Chehab } 2430c0d06caSMauro Carvalho Chehab 2442c6b222cSLaurent Pinchart static struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16]) 2450c0d06caSMauro Carvalho Chehab { 2460c0d06caSMauro Carvalho Chehab unsigned int len = ARRAY_SIZE(uvc_fmts); 2470c0d06caSMauro Carvalho Chehab unsigned int i; 2480c0d06caSMauro Carvalho Chehab 2490c0d06caSMauro Carvalho Chehab for (i = 0; i < len; ++i) { 2500c0d06caSMauro Carvalho Chehab if (memcmp(guid, uvc_fmts[i].guid, 16) == 0) 2510c0d06caSMauro Carvalho Chehab return &uvc_fmts[i]; 2520c0d06caSMauro Carvalho Chehab } 2530c0d06caSMauro Carvalho Chehab 2540c0d06caSMauro Carvalho Chehab return NULL; 2550c0d06caSMauro Carvalho Chehab } 2560c0d06caSMauro Carvalho Chehab 257ec2c23f6SAdam Goode static enum v4l2_colorspace uvc_colorspace(const u8 primaries) 2580c0d06caSMauro Carvalho Chehab { 259ec2c23f6SAdam Goode static const enum v4l2_colorspace colorprimaries[] = { 260ec2c23f6SAdam Goode V4L2_COLORSPACE_DEFAULT, /* Unspecified */ 2610c0d06caSMauro Carvalho Chehab V4L2_COLORSPACE_SRGB, 2620c0d06caSMauro Carvalho Chehab V4L2_COLORSPACE_470_SYSTEM_M, 2630c0d06caSMauro Carvalho Chehab V4L2_COLORSPACE_470_SYSTEM_BG, 2640c0d06caSMauro Carvalho Chehab V4L2_COLORSPACE_SMPTE170M, 2650c0d06caSMauro Carvalho Chehab V4L2_COLORSPACE_SMPTE240M, 2660c0d06caSMauro Carvalho Chehab }; 2670c0d06caSMauro Carvalho Chehab 2680c0d06caSMauro Carvalho Chehab if (primaries < ARRAY_SIZE(colorprimaries)) 2690c0d06caSMauro Carvalho Chehab return colorprimaries[primaries]; 2700c0d06caSMauro Carvalho Chehab 271ec2c23f6SAdam Goode return V4L2_COLORSPACE_DEFAULT; /* Reserved */ 272ec2c23f6SAdam Goode } 273ec2c23f6SAdam Goode 274ec2c23f6SAdam Goode static enum v4l2_xfer_func uvc_xfer_func(const u8 transfer_characteristics) 275ec2c23f6SAdam Goode { 276ec2c23f6SAdam Goode /* 277ec2c23f6SAdam Goode * V4L2 does not currently have definitions for all possible values of 278ec2c23f6SAdam Goode * UVC transfer characteristics. If v4l2_xfer_func is extended with new 279ec2c23f6SAdam Goode * values, the mapping below should be updated. 280ec2c23f6SAdam Goode * 281ec2c23f6SAdam Goode * Substitutions are taken from the mapping given for 282ec2c23f6SAdam Goode * V4L2_XFER_FUNC_DEFAULT documented in videodev2.h. 283ec2c23f6SAdam Goode */ 284ec2c23f6SAdam Goode static const enum v4l2_xfer_func xfer_funcs[] = { 285ec2c23f6SAdam Goode V4L2_XFER_FUNC_DEFAULT, /* Unspecified */ 286ec2c23f6SAdam Goode V4L2_XFER_FUNC_709, 287ec2c23f6SAdam Goode V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 M */ 288ec2c23f6SAdam Goode V4L2_XFER_FUNC_709, /* Substitution for BT.470-2 B, G */ 289ec2c23f6SAdam Goode V4L2_XFER_FUNC_709, /* Substitution for SMPTE 170M */ 290ec2c23f6SAdam Goode V4L2_XFER_FUNC_SMPTE240M, 291ec2c23f6SAdam Goode V4L2_XFER_FUNC_NONE, 292ec2c23f6SAdam Goode V4L2_XFER_FUNC_SRGB, 293ec2c23f6SAdam Goode }; 294ec2c23f6SAdam Goode 295ec2c23f6SAdam Goode if (transfer_characteristics < ARRAY_SIZE(xfer_funcs)) 296ec2c23f6SAdam Goode return xfer_funcs[transfer_characteristics]; 297ec2c23f6SAdam Goode 298ec2c23f6SAdam Goode return V4L2_XFER_FUNC_DEFAULT; /* Reserved */ 299ec2c23f6SAdam Goode } 300ec2c23f6SAdam Goode 301ec2c23f6SAdam Goode static enum v4l2_ycbcr_encoding uvc_ycbcr_enc(const u8 matrix_coefficients) 302ec2c23f6SAdam Goode { 303ec2c23f6SAdam Goode /* 304ec2c23f6SAdam Goode * V4L2 does not currently have definitions for all possible values of 305ec2c23f6SAdam Goode * UVC matrix coefficients. If v4l2_ycbcr_encoding is extended with new 306ec2c23f6SAdam Goode * values, the mapping below should be updated. 307ec2c23f6SAdam Goode * 308ec2c23f6SAdam Goode * Substitutions are taken from the mapping given for 309ec2c23f6SAdam Goode * V4L2_YCBCR_ENC_DEFAULT documented in videodev2.h. 310ec2c23f6SAdam Goode * 311ec2c23f6SAdam Goode * FCC is assumed to be close enough to 601. 312ec2c23f6SAdam Goode */ 313ec2c23f6SAdam Goode static const enum v4l2_ycbcr_encoding ycbcr_encs[] = { 314ec2c23f6SAdam Goode V4L2_YCBCR_ENC_DEFAULT, /* Unspecified */ 315ec2c23f6SAdam Goode V4L2_YCBCR_ENC_709, 316ec2c23f6SAdam Goode V4L2_YCBCR_ENC_601, /* Substitution for FCC */ 317ec2c23f6SAdam Goode V4L2_YCBCR_ENC_601, /* Substitution for BT.470-2 B, G */ 318ec2c23f6SAdam Goode V4L2_YCBCR_ENC_601, 319ec2c23f6SAdam Goode V4L2_YCBCR_ENC_SMPTE240M, 320ec2c23f6SAdam Goode }; 321ec2c23f6SAdam Goode 322ec2c23f6SAdam Goode if (matrix_coefficients < ARRAY_SIZE(ycbcr_encs)) 323ec2c23f6SAdam Goode return ycbcr_encs[matrix_coefficients]; 324ec2c23f6SAdam Goode 325ec2c23f6SAdam Goode return V4L2_YCBCR_ENC_DEFAULT; /* Reserved */ 3260c0d06caSMauro Carvalho Chehab } 3270c0d06caSMauro Carvalho Chehab 3280c0d06caSMauro Carvalho Chehab /* Simplify a fraction using a simple continued fraction decomposition. The 3290c0d06caSMauro Carvalho Chehab * idea here is to convert fractions such as 333333/10000000 to 1/30 using 3300c0d06caSMauro Carvalho Chehab * 32 bit arithmetic only. The algorithm is not perfect and relies upon two 3310c0d06caSMauro Carvalho Chehab * arbitrary parameters to remove non-significative terms from the simple 3320c0d06caSMauro Carvalho Chehab * continued fraction decomposition. Using 8 and 333 for n_terms and threshold 3330c0d06caSMauro Carvalho Chehab * respectively seems to give nice results. 3340c0d06caSMauro Carvalho Chehab */ 3351e304c47SLaurent Pinchart void uvc_simplify_fraction(u32 *numerator, u32 *denominator, 3360c0d06caSMauro Carvalho Chehab unsigned int n_terms, unsigned int threshold) 3370c0d06caSMauro Carvalho Chehab { 3381e304c47SLaurent Pinchart u32 *an; 3391e304c47SLaurent Pinchart u32 x, y, r; 3400c0d06caSMauro Carvalho Chehab unsigned int i, n; 3410c0d06caSMauro Carvalho Chehab 342f14d4988SLaurent Pinchart an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL); 3430c0d06caSMauro Carvalho Chehab if (an == NULL) 3440c0d06caSMauro Carvalho Chehab return; 3450c0d06caSMauro Carvalho Chehab 3460c0d06caSMauro Carvalho Chehab /* Convert the fraction to a simple continued fraction. See 347f5a3048aSAlexander A. Klimov * https://mathforum.org/dr.math/faq/faq.fractions.html 3480c0d06caSMauro Carvalho Chehab * Stop if the current term is bigger than or equal to the given 3490c0d06caSMauro Carvalho Chehab * threshold. 3500c0d06caSMauro Carvalho Chehab */ 3510c0d06caSMauro Carvalho Chehab x = *numerator; 3520c0d06caSMauro Carvalho Chehab y = *denominator; 3530c0d06caSMauro Carvalho Chehab 3540c0d06caSMauro Carvalho Chehab for (n = 0; n < n_terms && y != 0; ++n) { 3550c0d06caSMauro Carvalho Chehab an[n] = x / y; 3560c0d06caSMauro Carvalho Chehab if (an[n] >= threshold) { 3570c0d06caSMauro Carvalho Chehab if (n < 2) 3580c0d06caSMauro Carvalho Chehab n++; 3590c0d06caSMauro Carvalho Chehab break; 3600c0d06caSMauro Carvalho Chehab } 3610c0d06caSMauro Carvalho Chehab 3620c0d06caSMauro Carvalho Chehab r = x - an[n] * y; 3630c0d06caSMauro Carvalho Chehab x = y; 3640c0d06caSMauro Carvalho Chehab y = r; 3650c0d06caSMauro Carvalho Chehab } 3660c0d06caSMauro Carvalho Chehab 3670c0d06caSMauro Carvalho Chehab /* Expand the simple continued fraction back to an integer fraction. */ 3680c0d06caSMauro Carvalho Chehab x = 0; 3690c0d06caSMauro Carvalho Chehab y = 1; 3700c0d06caSMauro Carvalho Chehab 3710c0d06caSMauro Carvalho Chehab for (i = n; i > 0; --i) { 3720c0d06caSMauro Carvalho Chehab r = y; 3730c0d06caSMauro Carvalho Chehab y = an[i-1] * y + x; 3740c0d06caSMauro Carvalho Chehab x = r; 3750c0d06caSMauro Carvalho Chehab } 3760c0d06caSMauro Carvalho Chehab 3770c0d06caSMauro Carvalho Chehab *numerator = y; 3780c0d06caSMauro Carvalho Chehab *denominator = x; 3790c0d06caSMauro Carvalho Chehab kfree(an); 3800c0d06caSMauro Carvalho Chehab } 3810c0d06caSMauro Carvalho Chehab 3820c0d06caSMauro Carvalho Chehab /* Convert a fraction to a frame interval in 100ns multiples. The idea here is 3830c0d06caSMauro Carvalho Chehab * to compute numerator / denominator * 10000000 using 32 bit fixed point 3840c0d06caSMauro Carvalho Chehab * arithmetic only. 3850c0d06caSMauro Carvalho Chehab */ 3861e304c47SLaurent Pinchart u32 uvc_fraction_to_interval(u32 numerator, u32 denominator) 3870c0d06caSMauro Carvalho Chehab { 3881e304c47SLaurent Pinchart u32 multiplier; 3890c0d06caSMauro Carvalho Chehab 3900c0d06caSMauro Carvalho Chehab /* Saturate the result if the operation would overflow. */ 3910c0d06caSMauro Carvalho Chehab if (denominator == 0 || 3921e304c47SLaurent Pinchart numerator/denominator >= ((u32)-1)/10000000) 3931e304c47SLaurent Pinchart return (u32)-1; 3940c0d06caSMauro Carvalho Chehab 3950c0d06caSMauro Carvalho Chehab /* Divide both the denominator and the multiplier by two until 3960c0d06caSMauro Carvalho Chehab * numerator * multiplier doesn't overflow. If anyone knows a better 3970c0d06caSMauro Carvalho Chehab * algorithm please let me know. 3980c0d06caSMauro Carvalho Chehab */ 3990c0d06caSMauro Carvalho Chehab multiplier = 10000000; 4001e304c47SLaurent Pinchart while (numerator > ((u32)-1)/multiplier) { 4010c0d06caSMauro Carvalho Chehab multiplier /= 2; 4020c0d06caSMauro Carvalho Chehab denominator /= 2; 4030c0d06caSMauro Carvalho Chehab } 4040c0d06caSMauro Carvalho Chehab 4050c0d06caSMauro Carvalho Chehab return denominator ? numerator * multiplier / denominator : 0; 4060c0d06caSMauro Carvalho Chehab } 4070c0d06caSMauro Carvalho Chehab 4080c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 4090c0d06caSMauro Carvalho Chehab * Terminal and unit management 4100c0d06caSMauro Carvalho Chehab */ 4110c0d06caSMauro Carvalho Chehab 4120c0d06caSMauro Carvalho Chehab struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) 4130c0d06caSMauro Carvalho Chehab { 4140c0d06caSMauro Carvalho Chehab struct uvc_entity *entity; 4150c0d06caSMauro Carvalho Chehab 4160c0d06caSMauro Carvalho Chehab list_for_each_entry(entity, &dev->entities, list) { 4170c0d06caSMauro Carvalho Chehab if (entity->id == id) 4180c0d06caSMauro Carvalho Chehab return entity; 4190c0d06caSMauro Carvalho Chehab } 4200c0d06caSMauro Carvalho Chehab 4210c0d06caSMauro Carvalho Chehab return NULL; 4220c0d06caSMauro Carvalho Chehab } 4230c0d06caSMauro Carvalho Chehab 4240c0d06caSMauro Carvalho Chehab static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev, 4250c0d06caSMauro Carvalho Chehab int id, struct uvc_entity *entity) 4260c0d06caSMauro Carvalho Chehab { 4270c0d06caSMauro Carvalho Chehab unsigned int i; 4280c0d06caSMauro Carvalho Chehab 4290c0d06caSMauro Carvalho Chehab if (entity == NULL) 4300c0d06caSMauro Carvalho Chehab entity = list_entry(&dev->entities, struct uvc_entity, list); 4310c0d06caSMauro Carvalho Chehab 4320c0d06caSMauro Carvalho Chehab list_for_each_entry_continue(entity, &dev->entities, list) { 4330c0d06caSMauro Carvalho Chehab for (i = 0; i < entity->bNrInPins; ++i) 4340c0d06caSMauro Carvalho Chehab if (entity->baSourceID[i] == id) 4350c0d06caSMauro Carvalho Chehab return entity; 4360c0d06caSMauro Carvalho Chehab } 4370c0d06caSMauro Carvalho Chehab 4380c0d06caSMauro Carvalho Chehab return NULL; 4390c0d06caSMauro Carvalho Chehab } 4400c0d06caSMauro Carvalho Chehab 4410c0d06caSMauro Carvalho Chehab static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id) 4420c0d06caSMauro Carvalho Chehab { 4430c0d06caSMauro Carvalho Chehab struct uvc_streaming *stream; 4440c0d06caSMauro Carvalho Chehab 4450c0d06caSMauro Carvalho Chehab list_for_each_entry(stream, &dev->streams, list) { 4460c0d06caSMauro Carvalho Chehab if (stream->header.bTerminalLink == id) 4470c0d06caSMauro Carvalho Chehab return stream; 4480c0d06caSMauro Carvalho Chehab } 4490c0d06caSMauro Carvalho Chehab 4500c0d06caSMauro Carvalho Chehab return NULL; 4510c0d06caSMauro Carvalho Chehab } 4520c0d06caSMauro Carvalho Chehab 4530c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 454ece41454SKieran Bingham * Streaming Object Management 455ece41454SKieran Bingham */ 456ece41454SKieran Bingham 457ece41454SKieran Bingham static void uvc_stream_delete(struct uvc_streaming *stream) 458ece41454SKieran Bingham { 459b012186aSKieran Bingham if (stream->async_wq) 460b012186aSKieran Bingham destroy_workqueue(stream->async_wq); 461b012186aSKieran Bingham 462ece41454SKieran Bingham mutex_destroy(&stream->mutex); 463ece41454SKieran Bingham 464ece41454SKieran Bingham usb_put_intf(stream->intf); 465ece41454SKieran Bingham 466ece41454SKieran Bingham kfree(stream->format); 467ece41454SKieran Bingham kfree(stream->header.bmaControls); 468ece41454SKieran Bingham kfree(stream); 469ece41454SKieran Bingham } 470ece41454SKieran Bingham 471ece41454SKieran Bingham static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev, 472ece41454SKieran Bingham struct usb_interface *intf) 473ece41454SKieran Bingham { 474ece41454SKieran Bingham struct uvc_streaming *stream; 475ece41454SKieran Bingham 476ece41454SKieran Bingham stream = kzalloc(sizeof(*stream), GFP_KERNEL); 477ece41454SKieran Bingham if (stream == NULL) 478ece41454SKieran Bingham return NULL; 479ece41454SKieran Bingham 480ece41454SKieran Bingham mutex_init(&stream->mutex); 481ece41454SKieran Bingham 482ece41454SKieran Bingham stream->dev = dev; 483ece41454SKieran Bingham stream->intf = usb_get_intf(intf); 484ece41454SKieran Bingham stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; 485ece41454SKieran Bingham 486b012186aSKieran Bingham /* Allocate a stream specific work queue for asynchronous tasks. */ 487b012186aSKieran Bingham stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | WQ_HIGHPRI, 488b012186aSKieran Bingham 0); 489b012186aSKieran Bingham if (!stream->async_wq) { 490b012186aSKieran Bingham uvc_stream_delete(stream); 491b012186aSKieran Bingham return NULL; 492b012186aSKieran Bingham } 493b012186aSKieran Bingham 494ece41454SKieran Bingham return stream; 495ece41454SKieran Bingham } 496ece41454SKieran Bingham 497ece41454SKieran Bingham /* ------------------------------------------------------------------------ 4980c0d06caSMauro Carvalho Chehab * Descriptors parsing 4990c0d06caSMauro Carvalho Chehab */ 5000c0d06caSMauro Carvalho Chehab 5010c0d06caSMauro Carvalho Chehab static int uvc_parse_format(struct uvc_device *dev, 5020c0d06caSMauro Carvalho Chehab struct uvc_streaming *streaming, struct uvc_format *format, 5032c6b222cSLaurent Pinchart u32 **intervals, unsigned char *buffer, int buflen) 5040c0d06caSMauro Carvalho Chehab { 5050c0d06caSMauro Carvalho Chehab struct usb_interface *intf = streaming->intf; 5060c0d06caSMauro Carvalho Chehab struct usb_host_interface *alts = intf->cur_altsetting; 5070c0d06caSMauro Carvalho Chehab struct uvc_format_desc *fmtdesc; 5080c0d06caSMauro Carvalho Chehab struct uvc_frame *frame; 5090c0d06caSMauro Carvalho Chehab const unsigned char *start = buffer; 510e1b78a33SPhilipp Zabel unsigned int width_multiplier = 1; 5110c0d06caSMauro Carvalho Chehab unsigned int interval; 5120c0d06caSMauro Carvalho Chehab unsigned int i, n; 5132c6b222cSLaurent Pinchart u8 ftype; 5140c0d06caSMauro Carvalho Chehab 5150c0d06caSMauro Carvalho Chehab format->type = buffer[2]; 5160c0d06caSMauro Carvalho Chehab format->index = buffer[3]; 5170c0d06caSMauro Carvalho Chehab 5180c0d06caSMauro Carvalho Chehab switch (buffer[2]) { 5190c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_UNCOMPRESSED: 5200c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_FRAME_BASED: 5210c0d06caSMauro Carvalho Chehab n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28; 5220c0d06caSMauro Carvalho Chehab if (buflen < n) { 5230c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 5240c0d06caSMauro Carvalho Chehab "interface %d FORMAT error\n", 5250c0d06caSMauro Carvalho Chehab dev->udev->devnum, 5260c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 5270c0d06caSMauro Carvalho Chehab return -EINVAL; 5280c0d06caSMauro Carvalho Chehab } 5290c0d06caSMauro Carvalho Chehab 5300c0d06caSMauro Carvalho Chehab /* Find the format descriptor from its GUID. */ 5310c0d06caSMauro Carvalho Chehab fmtdesc = uvc_format_by_guid(&buffer[5]); 5320c0d06caSMauro Carvalho Chehab 5330c0d06caSMauro Carvalho Chehab if (fmtdesc != NULL) { 534c0decac1SMauro Carvalho Chehab strscpy(format->name, fmtdesc->name, 535f14d4988SLaurent Pinchart sizeof(format->name)); 5360c0d06caSMauro Carvalho Chehab format->fcc = fmtdesc->fcc; 5370c0d06caSMauro Carvalho Chehab } else { 5380c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "Unknown video format %pUl\n", 5390c0d06caSMauro Carvalho Chehab &buffer[5]); 5400c0d06caSMauro Carvalho Chehab snprintf(format->name, sizeof(format->name), "%pUl\n", 5410c0d06caSMauro Carvalho Chehab &buffer[5]); 5420c0d06caSMauro Carvalho Chehab format->fcc = 0; 5430c0d06caSMauro Carvalho Chehab } 5440c0d06caSMauro Carvalho Chehab 5450c0d06caSMauro Carvalho Chehab format->bpp = buffer[21]; 546e1b78a33SPhilipp Zabel 547e1b78a33SPhilipp Zabel /* Some devices report a format that doesn't match what they 548e1b78a33SPhilipp Zabel * really send. 549e1b78a33SPhilipp Zabel */ 550e1b78a33SPhilipp Zabel if (dev->quirks & UVC_QUIRK_FORCE_Y8) { 551e1b78a33SPhilipp Zabel if (format->fcc == V4L2_PIX_FMT_YUYV) { 552c0decac1SMauro Carvalho Chehab strscpy(format->name, "Greyscale 8-bit (Y8 )", 553e1b78a33SPhilipp Zabel sizeof(format->name)); 554e1b78a33SPhilipp Zabel format->fcc = V4L2_PIX_FMT_GREY; 555e1b78a33SPhilipp Zabel format->bpp = 8; 556e1b78a33SPhilipp Zabel width_multiplier = 2; 557e1b78a33SPhilipp Zabel } 558e1b78a33SPhilipp Zabel } 559e1b78a33SPhilipp Zabel 5601dd2e8f9SSergey Zakharchenko /* Some devices report bpp that doesn't match the format. */ 5611dd2e8f9SSergey Zakharchenko if (dev->quirks & UVC_QUIRK_FORCE_BPP) { 5621dd2e8f9SSergey Zakharchenko const struct v4l2_format_info *info = 5631dd2e8f9SSergey Zakharchenko v4l2_format_info(format->fcc); 5641dd2e8f9SSergey Zakharchenko 5651dd2e8f9SSergey Zakharchenko if (info) { 5661dd2e8f9SSergey Zakharchenko unsigned int div = info->hdiv * info->vdiv; 5671dd2e8f9SSergey Zakharchenko 5681dd2e8f9SSergey Zakharchenko n = info->bpp[0] * div; 5691dd2e8f9SSergey Zakharchenko for (i = 1; i < info->comp_planes; i++) 5701dd2e8f9SSergey Zakharchenko n += info->bpp[i]; 5711dd2e8f9SSergey Zakharchenko 5721dd2e8f9SSergey Zakharchenko format->bpp = DIV_ROUND_UP(8 * n, div); 5731dd2e8f9SSergey Zakharchenko } 5741dd2e8f9SSergey Zakharchenko } 5751dd2e8f9SSergey Zakharchenko 5760c0d06caSMauro Carvalho Chehab if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) { 5770c0d06caSMauro Carvalho Chehab ftype = UVC_VS_FRAME_UNCOMPRESSED; 5780c0d06caSMauro Carvalho Chehab } else { 5790c0d06caSMauro Carvalho Chehab ftype = UVC_VS_FRAME_FRAME_BASED; 5800c0d06caSMauro Carvalho Chehab if (buffer[27]) 5810c0d06caSMauro Carvalho Chehab format->flags = UVC_FMT_FLAG_COMPRESSED; 5820c0d06caSMauro Carvalho Chehab } 5830c0d06caSMauro Carvalho Chehab break; 5840c0d06caSMauro Carvalho Chehab 5850c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_MJPEG: 5860c0d06caSMauro Carvalho Chehab if (buflen < 11) { 5870c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 5880c0d06caSMauro Carvalho Chehab "interface %d FORMAT error\n", 5890c0d06caSMauro Carvalho Chehab dev->udev->devnum, 5900c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 5910c0d06caSMauro Carvalho Chehab return -EINVAL; 5920c0d06caSMauro Carvalho Chehab } 5930c0d06caSMauro Carvalho Chehab 594c0decac1SMauro Carvalho Chehab strscpy(format->name, "MJPEG", sizeof(format->name)); 5950c0d06caSMauro Carvalho Chehab format->fcc = V4L2_PIX_FMT_MJPEG; 5960c0d06caSMauro Carvalho Chehab format->flags = UVC_FMT_FLAG_COMPRESSED; 5970c0d06caSMauro Carvalho Chehab format->bpp = 0; 5980c0d06caSMauro Carvalho Chehab ftype = UVC_VS_FRAME_MJPEG; 5990c0d06caSMauro Carvalho Chehab break; 6000c0d06caSMauro Carvalho Chehab 6010c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_DV: 6020c0d06caSMauro Carvalho Chehab if (buflen < 9) { 6030c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 6040c0d06caSMauro Carvalho Chehab "interface %d FORMAT error\n", 6050c0d06caSMauro Carvalho Chehab dev->udev->devnum, 6060c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 6070c0d06caSMauro Carvalho Chehab return -EINVAL; 6080c0d06caSMauro Carvalho Chehab } 6090c0d06caSMauro Carvalho Chehab 6100c0d06caSMauro Carvalho Chehab switch (buffer[8] & 0x7f) { 6110c0d06caSMauro Carvalho Chehab case 0: 612c0decac1SMauro Carvalho Chehab strscpy(format->name, "SD-DV", sizeof(format->name)); 6130c0d06caSMauro Carvalho Chehab break; 6140c0d06caSMauro Carvalho Chehab case 1: 615c0decac1SMauro Carvalho Chehab strscpy(format->name, "SDL-DV", sizeof(format->name)); 6160c0d06caSMauro Carvalho Chehab break; 6170c0d06caSMauro Carvalho Chehab case 2: 618c0decac1SMauro Carvalho Chehab strscpy(format->name, "HD-DV", sizeof(format->name)); 6190c0d06caSMauro Carvalho Chehab break; 6200c0d06caSMauro Carvalho Chehab default: 6210c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 6220c0d06caSMauro Carvalho Chehab "interface %d: unknown DV format %u\n", 6230c0d06caSMauro Carvalho Chehab dev->udev->devnum, 6240c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber, buffer[8]); 6250c0d06caSMauro Carvalho Chehab return -EINVAL; 6260c0d06caSMauro Carvalho Chehab } 6270c0d06caSMauro Carvalho Chehab 6280c0d06caSMauro Carvalho Chehab strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz", 629f14d4988SLaurent Pinchart sizeof(format->name)); 6300c0d06caSMauro Carvalho Chehab 6310c0d06caSMauro Carvalho Chehab format->fcc = V4L2_PIX_FMT_DV; 6320c0d06caSMauro Carvalho Chehab format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM; 6330c0d06caSMauro Carvalho Chehab format->bpp = 0; 6340c0d06caSMauro Carvalho Chehab ftype = 0; 6350c0d06caSMauro Carvalho Chehab 6360c0d06caSMauro Carvalho Chehab /* Create a dummy frame descriptor. */ 6370c0d06caSMauro Carvalho Chehab frame = &format->frame[0]; 638f14d4988SLaurent Pinchart memset(&format->frame[0], 0, sizeof(format->frame[0])); 6390c0d06caSMauro Carvalho Chehab frame->bFrameIntervalType = 1; 6400c0d06caSMauro Carvalho Chehab frame->dwDefaultFrameInterval = 1; 6410c0d06caSMauro Carvalho Chehab frame->dwFrameInterval = *intervals; 6420c0d06caSMauro Carvalho Chehab *(*intervals)++ = 1; 6430c0d06caSMauro Carvalho Chehab format->nframes = 1; 6440c0d06caSMauro Carvalho Chehab break; 6450c0d06caSMauro Carvalho Chehab 6460c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_MPEG2TS: 6470c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_STREAM_BASED: 6480c0d06caSMauro Carvalho Chehab /* Not supported yet. */ 6490c0d06caSMauro Carvalho Chehab default: 6500c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 6510c0d06caSMauro Carvalho Chehab "interface %d unsupported format %u\n", 6520c0d06caSMauro Carvalho Chehab dev->udev->devnum, alts->desc.bInterfaceNumber, 6530c0d06caSMauro Carvalho Chehab buffer[2]); 6540c0d06caSMauro Carvalho Chehab return -EINVAL; 6550c0d06caSMauro Carvalho Chehab } 6560c0d06caSMauro Carvalho Chehab 6570c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name); 6580c0d06caSMauro Carvalho Chehab 6590c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 6600c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 6610c0d06caSMauro Carvalho Chehab 6620c0d06caSMauro Carvalho Chehab /* Parse the frame descriptors. Only uncompressed, MJPEG and frame 6630c0d06caSMauro Carvalho Chehab * based formats have frame descriptors. 6640c0d06caSMauro Carvalho Chehab */ 6650c0d06caSMauro Carvalho Chehab while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE && 6660c0d06caSMauro Carvalho Chehab buffer[2] == ftype) { 6670c0d06caSMauro Carvalho Chehab frame = &format->frame[format->nframes]; 6680c0d06caSMauro Carvalho Chehab if (ftype != UVC_VS_FRAME_FRAME_BASED) 6690c0d06caSMauro Carvalho Chehab n = buflen > 25 ? buffer[25] : 0; 6700c0d06caSMauro Carvalho Chehab else 6710c0d06caSMauro Carvalho Chehab n = buflen > 21 ? buffer[21] : 0; 6720c0d06caSMauro Carvalho Chehab 6730c0d06caSMauro Carvalho Chehab n = n ? n : 3; 6740c0d06caSMauro Carvalho Chehab 6750c0d06caSMauro Carvalho Chehab if (buflen < 26 + 4*n) { 6760c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 6770c0d06caSMauro Carvalho Chehab "interface %d FRAME error\n", dev->udev->devnum, 6780c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 6790c0d06caSMauro Carvalho Chehab return -EINVAL; 6800c0d06caSMauro Carvalho Chehab } 6810c0d06caSMauro Carvalho Chehab 6820c0d06caSMauro Carvalho Chehab frame->bFrameIndex = buffer[3]; 6830c0d06caSMauro Carvalho Chehab frame->bmCapabilities = buffer[4]; 684e1b78a33SPhilipp Zabel frame->wWidth = get_unaligned_le16(&buffer[5]) 685e1b78a33SPhilipp Zabel * width_multiplier; 6860c0d06caSMauro Carvalho Chehab frame->wHeight = get_unaligned_le16(&buffer[7]); 6870c0d06caSMauro Carvalho Chehab frame->dwMinBitRate = get_unaligned_le32(&buffer[9]); 6880c0d06caSMauro Carvalho Chehab frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]); 6890c0d06caSMauro Carvalho Chehab if (ftype != UVC_VS_FRAME_FRAME_BASED) { 6900c0d06caSMauro Carvalho Chehab frame->dwMaxVideoFrameBufferSize = 6910c0d06caSMauro Carvalho Chehab get_unaligned_le32(&buffer[17]); 6920c0d06caSMauro Carvalho Chehab frame->dwDefaultFrameInterval = 6930c0d06caSMauro Carvalho Chehab get_unaligned_le32(&buffer[21]); 6940c0d06caSMauro Carvalho Chehab frame->bFrameIntervalType = buffer[25]; 6950c0d06caSMauro Carvalho Chehab } else { 6960c0d06caSMauro Carvalho Chehab frame->dwMaxVideoFrameBufferSize = 0; 6970c0d06caSMauro Carvalho Chehab frame->dwDefaultFrameInterval = 6980c0d06caSMauro Carvalho Chehab get_unaligned_le32(&buffer[17]); 6990c0d06caSMauro Carvalho Chehab frame->bFrameIntervalType = buffer[21]; 7000c0d06caSMauro Carvalho Chehab } 7010c0d06caSMauro Carvalho Chehab frame->dwFrameInterval = *intervals; 7020c0d06caSMauro Carvalho Chehab 7030c0d06caSMauro Carvalho Chehab /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize 7040c0d06caSMauro Carvalho Chehab * completely. Observed behaviours range from setting the 7050c0d06caSMauro Carvalho Chehab * value to 1.1x the actual frame size to hardwiring the 7060c0d06caSMauro Carvalho Chehab * 16 low bits to 0. This results in a higher than necessary 7070c0d06caSMauro Carvalho Chehab * memory usage as well as a wrong image size information. For 7080c0d06caSMauro Carvalho Chehab * uncompressed formats this can be fixed by computing the 7090c0d06caSMauro Carvalho Chehab * value from the frame size. 7100c0d06caSMauro Carvalho Chehab */ 7110c0d06caSMauro Carvalho Chehab if (!(format->flags & UVC_FMT_FLAG_COMPRESSED)) 7120c0d06caSMauro Carvalho Chehab frame->dwMaxVideoFrameBufferSize = format->bpp 7130c0d06caSMauro Carvalho Chehab * frame->wWidth * frame->wHeight / 8; 7140c0d06caSMauro Carvalho Chehab 7150c0d06caSMauro Carvalho Chehab /* Some bogus devices report dwMinFrameInterval equal to 7160c0d06caSMauro Carvalho Chehab * dwMaxFrameInterval and have dwFrameIntervalStep set to 7170c0d06caSMauro Carvalho Chehab * zero. Setting all null intervals to 1 fixes the problem and 7180c0d06caSMauro Carvalho Chehab * some other divisions by zero that could happen. 7190c0d06caSMauro Carvalho Chehab */ 7200c0d06caSMauro Carvalho Chehab for (i = 0; i < n; ++i) { 7210c0d06caSMauro Carvalho Chehab interval = get_unaligned_le32(&buffer[26+4*i]); 7220c0d06caSMauro Carvalho Chehab *(*intervals)++ = interval ? interval : 1; 7230c0d06caSMauro Carvalho Chehab } 7240c0d06caSMauro Carvalho Chehab 7250c0d06caSMauro Carvalho Chehab /* Make sure that the default frame interval stays between 7260c0d06caSMauro Carvalho Chehab * the boundaries. 7270c0d06caSMauro Carvalho Chehab */ 7280c0d06caSMauro Carvalho Chehab n -= frame->bFrameIntervalType ? 1 : 2; 7290c0d06caSMauro Carvalho Chehab frame->dwDefaultFrameInterval = 7300c0d06caSMauro Carvalho Chehab min(frame->dwFrameInterval[n], 7310c0d06caSMauro Carvalho Chehab max(frame->dwFrameInterval[0], 7320c0d06caSMauro Carvalho Chehab frame->dwDefaultFrameInterval)); 7330c0d06caSMauro Carvalho Chehab 7340c0d06caSMauro Carvalho Chehab if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) { 7350c0d06caSMauro Carvalho Chehab frame->bFrameIntervalType = 1; 7360c0d06caSMauro Carvalho Chehab frame->dwFrameInterval[0] = 7370c0d06caSMauro Carvalho Chehab frame->dwDefaultFrameInterval; 7380c0d06caSMauro Carvalho Chehab } 7390c0d06caSMauro Carvalho Chehab 7400c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n", 7410c0d06caSMauro Carvalho Chehab frame->wWidth, frame->wHeight, 7420c0d06caSMauro Carvalho Chehab 10000000/frame->dwDefaultFrameInterval, 7430c0d06caSMauro Carvalho Chehab (100000000/frame->dwDefaultFrameInterval)%10); 7440c0d06caSMauro Carvalho Chehab 7450c0d06caSMauro Carvalho Chehab format->nframes++; 7460c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 7470c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 7480c0d06caSMauro Carvalho Chehab } 7490c0d06caSMauro Carvalho Chehab 7500c0d06caSMauro Carvalho Chehab if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE && 7510c0d06caSMauro Carvalho Chehab buffer[2] == UVC_VS_STILL_IMAGE_FRAME) { 7520c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 7530c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 7540c0d06caSMauro Carvalho Chehab } 7550c0d06caSMauro Carvalho Chehab 7560c0d06caSMauro Carvalho Chehab if (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE && 7570c0d06caSMauro Carvalho Chehab buffer[2] == UVC_VS_COLORFORMAT) { 7580c0d06caSMauro Carvalho Chehab if (buflen < 6) { 7590c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 7600c0d06caSMauro Carvalho Chehab "interface %d COLORFORMAT error\n", 7610c0d06caSMauro Carvalho Chehab dev->udev->devnum, 7620c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 7630c0d06caSMauro Carvalho Chehab return -EINVAL; 7640c0d06caSMauro Carvalho Chehab } 7650c0d06caSMauro Carvalho Chehab 7660c0d06caSMauro Carvalho Chehab format->colorspace = uvc_colorspace(buffer[3]); 767ec2c23f6SAdam Goode format->xfer_func = uvc_xfer_func(buffer[4]); 768ec2c23f6SAdam Goode format->ycbcr_enc = uvc_ycbcr_enc(buffer[5]); 7690c0d06caSMauro Carvalho Chehab 7700c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 7710c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 7720c0d06caSMauro Carvalho Chehab } 7730c0d06caSMauro Carvalho Chehab 7740c0d06caSMauro Carvalho Chehab return buffer - start; 7750c0d06caSMauro Carvalho Chehab } 7760c0d06caSMauro Carvalho Chehab 7770c0d06caSMauro Carvalho Chehab static int uvc_parse_streaming(struct uvc_device *dev, 7780c0d06caSMauro Carvalho Chehab struct usb_interface *intf) 7790c0d06caSMauro Carvalho Chehab { 7800c0d06caSMauro Carvalho Chehab struct uvc_streaming *streaming = NULL; 7810c0d06caSMauro Carvalho Chehab struct uvc_format *format; 7820c0d06caSMauro Carvalho Chehab struct uvc_frame *frame; 7830c0d06caSMauro Carvalho Chehab struct usb_host_interface *alts = &intf->altsetting[0]; 7840c0d06caSMauro Carvalho Chehab unsigned char *_buffer, *buffer = alts->extra; 7850c0d06caSMauro Carvalho Chehab int _buflen, buflen = alts->extralen; 7860c0d06caSMauro Carvalho Chehab unsigned int nformats = 0, nframes = 0, nintervals = 0; 7870c0d06caSMauro Carvalho Chehab unsigned int size, i, n, p; 7882c6b222cSLaurent Pinchart u32 *interval; 7892c6b222cSLaurent Pinchart u16 psize; 7900c0d06caSMauro Carvalho Chehab int ret = -EINVAL; 7910c0d06caSMauro Carvalho Chehab 7920c0d06caSMauro Carvalho Chehab if (intf->cur_altsetting->desc.bInterfaceSubClass 7930c0d06caSMauro Carvalho Chehab != UVC_SC_VIDEOSTREAMING) { 7940c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a " 7950c0d06caSMauro Carvalho Chehab "video streaming interface\n", dev->udev->devnum, 7960c0d06caSMauro Carvalho Chehab intf->altsetting[0].desc.bInterfaceNumber); 7970c0d06caSMauro Carvalho Chehab return -EINVAL; 7980c0d06caSMauro Carvalho Chehab } 7990c0d06caSMauro Carvalho Chehab 8000c0d06caSMauro Carvalho Chehab if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) { 8010c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already " 8020c0d06caSMauro Carvalho Chehab "claimed\n", dev->udev->devnum, 8030c0d06caSMauro Carvalho Chehab intf->altsetting[0].desc.bInterfaceNumber); 8040c0d06caSMauro Carvalho Chehab return -EINVAL; 8050c0d06caSMauro Carvalho Chehab } 8060c0d06caSMauro Carvalho Chehab 807ece41454SKieran Bingham streaming = uvc_stream_new(dev, intf); 8080c0d06caSMauro Carvalho Chehab if (streaming == NULL) { 8090c0d06caSMauro Carvalho Chehab usb_driver_release_interface(&uvc_driver.driver, intf); 810ece41454SKieran Bingham return -ENOMEM; 8110c0d06caSMauro Carvalho Chehab } 8120c0d06caSMauro Carvalho Chehab 8130c0d06caSMauro Carvalho Chehab /* The Pico iMage webcam has its class-specific interface descriptors 8140c0d06caSMauro Carvalho Chehab * after the endpoint descriptors. 8150c0d06caSMauro Carvalho Chehab */ 8160c0d06caSMauro Carvalho Chehab if (buflen == 0) { 8170c0d06caSMauro Carvalho Chehab for (i = 0; i < alts->desc.bNumEndpoints; ++i) { 8180c0d06caSMauro Carvalho Chehab struct usb_host_endpoint *ep = &alts->endpoint[i]; 8190c0d06caSMauro Carvalho Chehab 8200c0d06caSMauro Carvalho Chehab if (ep->extralen == 0) 8210c0d06caSMauro Carvalho Chehab continue; 8220c0d06caSMauro Carvalho Chehab 8230c0d06caSMauro Carvalho Chehab if (ep->extralen > 2 && 8240c0d06caSMauro Carvalho Chehab ep->extra[1] == USB_DT_CS_INTERFACE) { 8250c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "trying extra data " 8260c0d06caSMauro Carvalho Chehab "from endpoint %u.\n", i); 8270c0d06caSMauro Carvalho Chehab buffer = alts->endpoint[i].extra; 8280c0d06caSMauro Carvalho Chehab buflen = alts->endpoint[i].extralen; 8290c0d06caSMauro Carvalho Chehab break; 8300c0d06caSMauro Carvalho Chehab } 8310c0d06caSMauro Carvalho Chehab } 8320c0d06caSMauro Carvalho Chehab } 8330c0d06caSMauro Carvalho Chehab 8340c0d06caSMauro Carvalho Chehab /* Skip the standard interface descriptors. */ 8350c0d06caSMauro Carvalho Chehab while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) { 8360c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 8370c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 8380c0d06caSMauro Carvalho Chehab } 8390c0d06caSMauro Carvalho Chehab 8400c0d06caSMauro Carvalho Chehab if (buflen <= 2) { 8410c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming " 8420c0d06caSMauro Carvalho Chehab "interface descriptors found.\n"); 8430c0d06caSMauro Carvalho Chehab goto error; 8440c0d06caSMauro Carvalho Chehab } 8450c0d06caSMauro Carvalho Chehab 8460c0d06caSMauro Carvalho Chehab /* Parse the header descriptor. */ 8470c0d06caSMauro Carvalho Chehab switch (buffer[2]) { 8480c0d06caSMauro Carvalho Chehab case UVC_VS_OUTPUT_HEADER: 8490c0d06caSMauro Carvalho Chehab streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 8500c0d06caSMauro Carvalho Chehab size = 9; 8510c0d06caSMauro Carvalho Chehab break; 8520c0d06caSMauro Carvalho Chehab 8530c0d06caSMauro Carvalho Chehab case UVC_VS_INPUT_HEADER: 8540c0d06caSMauro Carvalho Chehab streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 8550c0d06caSMauro Carvalho Chehab size = 13; 8560c0d06caSMauro Carvalho Chehab break; 8570c0d06caSMauro Carvalho Chehab 8580c0d06caSMauro Carvalho Chehab default: 8590c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface " 8600c0d06caSMauro Carvalho Chehab "%d HEADER descriptor not found.\n", dev->udev->devnum, 8610c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 8620c0d06caSMauro Carvalho Chehab goto error; 8630c0d06caSMauro Carvalho Chehab } 8640c0d06caSMauro Carvalho Chehab 8650c0d06caSMauro Carvalho Chehab p = buflen >= 4 ? buffer[3] : 0; 8660c0d06caSMauro Carvalho Chehab n = buflen >= size ? buffer[size-1] : 0; 8670c0d06caSMauro Carvalho Chehab 8680c0d06caSMauro Carvalho Chehab if (buflen < size + p*n) { 8690c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 8700c0d06caSMauro Carvalho Chehab "interface %d HEADER descriptor is invalid.\n", 8710c0d06caSMauro Carvalho Chehab dev->udev->devnum, alts->desc.bInterfaceNumber); 8720c0d06caSMauro Carvalho Chehab goto error; 8730c0d06caSMauro Carvalho Chehab } 8740c0d06caSMauro Carvalho Chehab 8750c0d06caSMauro Carvalho Chehab streaming->header.bNumFormats = p; 8760c0d06caSMauro Carvalho Chehab streaming->header.bEndpointAddress = buffer[6]; 8770c0d06caSMauro Carvalho Chehab if (buffer[2] == UVC_VS_INPUT_HEADER) { 8780c0d06caSMauro Carvalho Chehab streaming->header.bmInfo = buffer[7]; 8790c0d06caSMauro Carvalho Chehab streaming->header.bTerminalLink = buffer[8]; 8800c0d06caSMauro Carvalho Chehab streaming->header.bStillCaptureMethod = buffer[9]; 8810c0d06caSMauro Carvalho Chehab streaming->header.bTriggerSupport = buffer[10]; 8820c0d06caSMauro Carvalho Chehab streaming->header.bTriggerUsage = buffer[11]; 8830c0d06caSMauro Carvalho Chehab } else { 8840c0d06caSMauro Carvalho Chehab streaming->header.bTerminalLink = buffer[7]; 8850c0d06caSMauro Carvalho Chehab } 8860c0d06caSMauro Carvalho Chehab streaming->header.bControlSize = n; 8870c0d06caSMauro Carvalho Chehab 8880c0d06caSMauro Carvalho Chehab streaming->header.bmaControls = kmemdup(&buffer[size], p * n, 8890c0d06caSMauro Carvalho Chehab GFP_KERNEL); 8900c0d06caSMauro Carvalho Chehab if (streaming->header.bmaControls == NULL) { 8910c0d06caSMauro Carvalho Chehab ret = -ENOMEM; 8920c0d06caSMauro Carvalho Chehab goto error; 8930c0d06caSMauro Carvalho Chehab } 8940c0d06caSMauro Carvalho Chehab 8950c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 8960c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 8970c0d06caSMauro Carvalho Chehab 8980c0d06caSMauro Carvalho Chehab _buffer = buffer; 8990c0d06caSMauro Carvalho Chehab _buflen = buflen; 9000c0d06caSMauro Carvalho Chehab 9010c0d06caSMauro Carvalho Chehab /* Count the format and frame descriptors. */ 9020c0d06caSMauro Carvalho Chehab while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) { 9030c0d06caSMauro Carvalho Chehab switch (_buffer[2]) { 9040c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_UNCOMPRESSED: 9050c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_MJPEG: 9060c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_FRAME_BASED: 9070c0d06caSMauro Carvalho Chehab nformats++; 9080c0d06caSMauro Carvalho Chehab break; 9090c0d06caSMauro Carvalho Chehab 9100c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_DV: 9110c0d06caSMauro Carvalho Chehab /* DV format has no frame descriptor. We will create a 9120c0d06caSMauro Carvalho Chehab * dummy frame descriptor with a dummy frame interval. 9130c0d06caSMauro Carvalho Chehab */ 9140c0d06caSMauro Carvalho Chehab nformats++; 9150c0d06caSMauro Carvalho Chehab nframes++; 9160c0d06caSMauro Carvalho Chehab nintervals++; 9170c0d06caSMauro Carvalho Chehab break; 9180c0d06caSMauro Carvalho Chehab 9190c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_MPEG2TS: 9200c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_STREAM_BASED: 9210c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 9220c0d06caSMauro Carvalho Chehab "interface %d FORMAT %u is not supported.\n", 9230c0d06caSMauro Carvalho Chehab dev->udev->devnum, 9240c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber, _buffer[2]); 9250c0d06caSMauro Carvalho Chehab break; 9260c0d06caSMauro Carvalho Chehab 9270c0d06caSMauro Carvalho Chehab case UVC_VS_FRAME_UNCOMPRESSED: 9280c0d06caSMauro Carvalho Chehab case UVC_VS_FRAME_MJPEG: 9290c0d06caSMauro Carvalho Chehab nframes++; 9300c0d06caSMauro Carvalho Chehab if (_buflen > 25) 9310c0d06caSMauro Carvalho Chehab nintervals += _buffer[25] ? _buffer[25] : 3; 9320c0d06caSMauro Carvalho Chehab break; 9330c0d06caSMauro Carvalho Chehab 9340c0d06caSMauro Carvalho Chehab case UVC_VS_FRAME_FRAME_BASED: 9350c0d06caSMauro Carvalho Chehab nframes++; 9360c0d06caSMauro Carvalho Chehab if (_buflen > 21) 9370c0d06caSMauro Carvalho Chehab nintervals += _buffer[21] ? _buffer[21] : 3; 9380c0d06caSMauro Carvalho Chehab break; 9390c0d06caSMauro Carvalho Chehab } 9400c0d06caSMauro Carvalho Chehab 9410c0d06caSMauro Carvalho Chehab _buflen -= _buffer[0]; 9420c0d06caSMauro Carvalho Chehab _buffer += _buffer[0]; 9430c0d06caSMauro Carvalho Chehab } 9440c0d06caSMauro Carvalho Chehab 9450c0d06caSMauro Carvalho Chehab if (nformats == 0) { 9460c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface " 9470c0d06caSMauro Carvalho Chehab "%d has no supported formats defined.\n", 9480c0d06caSMauro Carvalho Chehab dev->udev->devnum, alts->desc.bInterfaceNumber); 9490c0d06caSMauro Carvalho Chehab goto error; 9500c0d06caSMauro Carvalho Chehab } 9510c0d06caSMauro Carvalho Chehab 952f14d4988SLaurent Pinchart size = nformats * sizeof(*format) + nframes * sizeof(*frame) 953f14d4988SLaurent Pinchart + nintervals * sizeof(*interval); 9540c0d06caSMauro Carvalho Chehab format = kzalloc(size, GFP_KERNEL); 9550c0d06caSMauro Carvalho Chehab if (format == NULL) { 9560c0d06caSMauro Carvalho Chehab ret = -ENOMEM; 9570c0d06caSMauro Carvalho Chehab goto error; 9580c0d06caSMauro Carvalho Chehab } 9590c0d06caSMauro Carvalho Chehab 9600c0d06caSMauro Carvalho Chehab frame = (struct uvc_frame *)&format[nformats]; 9612c6b222cSLaurent Pinchart interval = (u32 *)&frame[nframes]; 9620c0d06caSMauro Carvalho Chehab 9630c0d06caSMauro Carvalho Chehab streaming->format = format; 9640c0d06caSMauro Carvalho Chehab streaming->nformats = nformats; 9650c0d06caSMauro Carvalho Chehab 9660c0d06caSMauro Carvalho Chehab /* Parse the format descriptors. */ 9670c0d06caSMauro Carvalho Chehab while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) { 9680c0d06caSMauro Carvalho Chehab switch (buffer[2]) { 9690c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_UNCOMPRESSED: 9700c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_MJPEG: 9710c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_DV: 9720c0d06caSMauro Carvalho Chehab case UVC_VS_FORMAT_FRAME_BASED: 9730c0d06caSMauro Carvalho Chehab format->frame = frame; 9740c0d06caSMauro Carvalho Chehab ret = uvc_parse_format(dev, streaming, format, 9750c0d06caSMauro Carvalho Chehab &interval, buffer, buflen); 9760c0d06caSMauro Carvalho Chehab if (ret < 0) 9770c0d06caSMauro Carvalho Chehab goto error; 9780c0d06caSMauro Carvalho Chehab 9790c0d06caSMauro Carvalho Chehab frame += format->nframes; 9800c0d06caSMauro Carvalho Chehab format++; 9810c0d06caSMauro Carvalho Chehab 9820c0d06caSMauro Carvalho Chehab buflen -= ret; 9830c0d06caSMauro Carvalho Chehab buffer += ret; 9840c0d06caSMauro Carvalho Chehab continue; 9850c0d06caSMauro Carvalho Chehab 9860c0d06caSMauro Carvalho Chehab default: 9870c0d06caSMauro Carvalho Chehab break; 9880c0d06caSMauro Carvalho Chehab } 9890c0d06caSMauro Carvalho Chehab 9900c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 9910c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 9920c0d06caSMauro Carvalho Chehab } 9930c0d06caSMauro Carvalho Chehab 9940c0d06caSMauro Carvalho Chehab if (buflen) 9950c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface " 9960c0d06caSMauro Carvalho Chehab "%d has %u bytes of trailing descriptor garbage.\n", 9970c0d06caSMauro Carvalho Chehab dev->udev->devnum, alts->desc.bInterfaceNumber, buflen); 9980c0d06caSMauro Carvalho Chehab 9990c0d06caSMauro Carvalho Chehab /* Parse the alternate settings to find the maximum bandwidth. */ 10000c0d06caSMauro Carvalho Chehab for (i = 0; i < intf->num_altsetting; ++i) { 10010c0d06caSMauro Carvalho Chehab struct usb_host_endpoint *ep; 10020c0d06caSMauro Carvalho Chehab alts = &intf->altsetting[i]; 10030c0d06caSMauro Carvalho Chehab ep = uvc_find_endpoint(alts, 10040c0d06caSMauro Carvalho Chehab streaming->header.bEndpointAddress); 10050c0d06caSMauro Carvalho Chehab if (ep == NULL) 10060c0d06caSMauro Carvalho Chehab continue; 10070c0d06caSMauro Carvalho Chehab 10080c0d06caSMauro Carvalho Chehab psize = le16_to_cpu(ep->desc.wMaxPacketSize); 10090c0d06caSMauro Carvalho Chehab psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); 10100c0d06caSMauro Carvalho Chehab if (psize > streaming->maxpsize) 10110c0d06caSMauro Carvalho Chehab streaming->maxpsize = psize; 10120c0d06caSMauro Carvalho Chehab } 10130c0d06caSMauro Carvalho Chehab 10140c0d06caSMauro Carvalho Chehab list_add_tail(&streaming->list, &dev->streams); 10150c0d06caSMauro Carvalho Chehab return 0; 10160c0d06caSMauro Carvalho Chehab 10170c0d06caSMauro Carvalho Chehab error: 10180c0d06caSMauro Carvalho Chehab usb_driver_release_interface(&uvc_driver.driver, intf); 1019ece41454SKieran Bingham uvc_stream_delete(streaming); 10200c0d06caSMauro Carvalho Chehab return ret; 10210c0d06caSMauro Carvalho Chehab } 10220c0d06caSMauro Carvalho Chehab 1023351509c6SRicardo Ribalda static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; 1024*2886477fSRicardo Ribalda static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER; 1025351509c6SRicardo Ribalda static const u8 uvc_media_transport_input_guid[16] = 1026351509c6SRicardo Ribalda UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; 1027351509c6SRicardo Ribalda static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; 1028351509c6SRicardo Ribalda 1029cae79e50SRicardo Ribalda static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, 10300c0d06caSMauro Carvalho Chehab unsigned int num_pads, unsigned int extra_size) 10310c0d06caSMauro Carvalho Chehab { 10320c0d06caSMauro Carvalho Chehab struct uvc_entity *entity; 10330c0d06caSMauro Carvalho Chehab unsigned int num_inputs; 10340c0d06caSMauro Carvalho Chehab unsigned int size; 10350c0d06caSMauro Carvalho Chehab unsigned int i; 10360c0d06caSMauro Carvalho Chehab 103789dd34caSNadav Amit extra_size = roundup(extra_size, sizeof(*entity->pads)); 10387532dad6SRicardo Ribalda if (num_pads) 10397532dad6SRicardo Ribalda num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1; 10407532dad6SRicardo Ribalda else 10417532dad6SRicardo Ribalda num_inputs = 0; 10420c0d06caSMauro Carvalho Chehab size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads 10430c0d06caSMauro Carvalho Chehab + num_inputs; 10440c0d06caSMauro Carvalho Chehab entity = kzalloc(size, GFP_KERNEL); 10450c0d06caSMauro Carvalho Chehab if (entity == NULL) 10460c0d06caSMauro Carvalho Chehab return NULL; 10470c0d06caSMauro Carvalho Chehab 10480c0d06caSMauro Carvalho Chehab entity->id = id; 10490c0d06caSMauro Carvalho Chehab entity->type = type; 10500c0d06caSMauro Carvalho Chehab 1051351509c6SRicardo Ribalda /* 1052351509c6SRicardo Ribalda * Set the GUID for standard entity types. For extension units, the GUID 1053351509c6SRicardo Ribalda * is initialized by the caller. 1054351509c6SRicardo Ribalda */ 1055351509c6SRicardo Ribalda switch (type) { 1056*2886477fSRicardo Ribalda case UVC_EXT_GPIO_UNIT: 1057*2886477fSRicardo Ribalda memcpy(entity->guid, uvc_gpio_guid, 16); 1058*2886477fSRicardo Ribalda break; 1059351509c6SRicardo Ribalda case UVC_ITT_CAMERA: 1060351509c6SRicardo Ribalda memcpy(entity->guid, uvc_camera_guid, 16); 1061351509c6SRicardo Ribalda break; 1062351509c6SRicardo Ribalda case UVC_ITT_MEDIA_TRANSPORT_INPUT: 1063351509c6SRicardo Ribalda memcpy(entity->guid, uvc_media_transport_input_guid, 16); 1064351509c6SRicardo Ribalda break; 1065351509c6SRicardo Ribalda case UVC_VC_PROCESSING_UNIT: 1066351509c6SRicardo Ribalda memcpy(entity->guid, uvc_processing_guid, 16); 1067351509c6SRicardo Ribalda break; 1068351509c6SRicardo Ribalda } 1069351509c6SRicardo Ribalda 10700c0d06caSMauro Carvalho Chehab entity->num_links = 0; 10710c0d06caSMauro Carvalho Chehab entity->num_pads = num_pads; 10720c0d06caSMauro Carvalho Chehab entity->pads = ((void *)(entity + 1)) + extra_size; 10730c0d06caSMauro Carvalho Chehab 10740c0d06caSMauro Carvalho Chehab for (i = 0; i < num_inputs; ++i) 10750c0d06caSMauro Carvalho Chehab entity->pads[i].flags = MEDIA_PAD_FL_SINK; 10767532dad6SRicardo Ribalda if (!UVC_ENTITY_IS_OTERM(entity) && num_pads) 10770c0d06caSMauro Carvalho Chehab entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE; 10780c0d06caSMauro Carvalho Chehab 10790c0d06caSMauro Carvalho Chehab entity->bNrInPins = num_inputs; 10802c6b222cSLaurent Pinchart entity->baSourceID = (u8 *)(&entity->pads[num_pads]); 10810c0d06caSMauro Carvalho Chehab 10820c0d06caSMauro Carvalho Chehab return entity; 10830c0d06caSMauro Carvalho Chehab } 10840c0d06caSMauro Carvalho Chehab 10850c0d06caSMauro Carvalho Chehab /* Parse vendor-specific extensions. */ 10860c0d06caSMauro Carvalho Chehab static int uvc_parse_vendor_control(struct uvc_device *dev, 10870c0d06caSMauro Carvalho Chehab const unsigned char *buffer, int buflen) 10880c0d06caSMauro Carvalho Chehab { 10890c0d06caSMauro Carvalho Chehab struct usb_device *udev = dev->udev; 10900c0d06caSMauro Carvalho Chehab struct usb_host_interface *alts = dev->intf->cur_altsetting; 10910c0d06caSMauro Carvalho Chehab struct uvc_entity *unit; 10920c0d06caSMauro Carvalho Chehab unsigned int n, p; 10930c0d06caSMauro Carvalho Chehab int handled = 0; 10940c0d06caSMauro Carvalho Chehab 10950c0d06caSMauro Carvalho Chehab switch (le16_to_cpu(dev->udev->descriptor.idVendor)) { 10960c0d06caSMauro Carvalho Chehab case 0x046d: /* Logitech */ 10970c0d06caSMauro Carvalho Chehab if (buffer[1] != 0x41 || buffer[2] != 0x01) 10980c0d06caSMauro Carvalho Chehab break; 10990c0d06caSMauro Carvalho Chehab 11000c0d06caSMauro Carvalho Chehab /* Logitech implements several vendor specific functions 11010c0d06caSMauro Carvalho Chehab * through vendor specific extension units (LXU). 11020c0d06caSMauro Carvalho Chehab * 11030c0d06caSMauro Carvalho Chehab * The LXU descriptors are similar to XU descriptors 11040c0d06caSMauro Carvalho Chehab * (see "USB Device Video Class for Video Devices", section 11050c0d06caSMauro Carvalho Chehab * 3.7.2.6 "Extension Unit Descriptor") with the following 11060c0d06caSMauro Carvalho Chehab * differences: 11070c0d06caSMauro Carvalho Chehab * 11080c0d06caSMauro Carvalho Chehab * ---------------------------------------------------------- 11090c0d06caSMauro Carvalho Chehab * 0 bLength 1 Number 11100c0d06caSMauro Carvalho Chehab * Size of this descriptor, in bytes: 24+p+n*2 11110c0d06caSMauro Carvalho Chehab * ---------------------------------------------------------- 11120c0d06caSMauro Carvalho Chehab * 23+p+n bmControlsType N Bitmap 11130c0d06caSMauro Carvalho Chehab * Individual bits in the set are defined: 11140c0d06caSMauro Carvalho Chehab * 0: Absolute 11150c0d06caSMauro Carvalho Chehab * 1: Relative 11160c0d06caSMauro Carvalho Chehab * 11170c0d06caSMauro Carvalho Chehab * This bitset is mapped exactly the same as bmControls. 11180c0d06caSMauro Carvalho Chehab * ---------------------------------------------------------- 11190c0d06caSMauro Carvalho Chehab * 23+p+n*2 bReserved 1 Boolean 11200c0d06caSMauro Carvalho Chehab * ---------------------------------------------------------- 11210c0d06caSMauro Carvalho Chehab * 24+p+n*2 iExtension 1 Index 11220c0d06caSMauro Carvalho Chehab * Index of a string descriptor that describes this 11230c0d06caSMauro Carvalho Chehab * extension unit. 11240c0d06caSMauro Carvalho Chehab * ---------------------------------------------------------- 11250c0d06caSMauro Carvalho Chehab */ 11260c0d06caSMauro Carvalho Chehab p = buflen >= 22 ? buffer[21] : 0; 11270c0d06caSMauro Carvalho Chehab n = buflen >= 25 + p ? buffer[22+p] : 0; 11280c0d06caSMauro Carvalho Chehab 11290c0d06caSMauro Carvalho Chehab if (buflen < 25 + p + 2*n) { 11300c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 11310c0d06caSMauro Carvalho Chehab "interface %d EXTENSION_UNIT error\n", 11320c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 11330c0d06caSMauro Carvalho Chehab break; 11340c0d06caSMauro Carvalho Chehab } 11350c0d06caSMauro Carvalho Chehab 11360c0d06caSMauro Carvalho Chehab unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3], 11370c0d06caSMauro Carvalho Chehab p + 1, 2*n); 11380c0d06caSMauro Carvalho Chehab if (unit == NULL) 11390c0d06caSMauro Carvalho Chehab return -ENOMEM; 11400c0d06caSMauro Carvalho Chehab 1141351509c6SRicardo Ribalda memcpy(unit->guid, &buffer[4], 16); 11420c0d06caSMauro Carvalho Chehab unit->extension.bNumControls = buffer[20]; 11430c0d06caSMauro Carvalho Chehab memcpy(unit->baSourceID, &buffer[22], p); 11440c0d06caSMauro Carvalho Chehab unit->extension.bControlSize = buffer[22+p]; 11452c6b222cSLaurent Pinchart unit->extension.bmControls = (u8 *)unit + sizeof(*unit); 11462c6b222cSLaurent Pinchart unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit) 11470c0d06caSMauro Carvalho Chehab + n; 11480c0d06caSMauro Carvalho Chehab memcpy(unit->extension.bmControls, &buffer[23+p], 2*n); 11490c0d06caSMauro Carvalho Chehab 11500c0d06caSMauro Carvalho Chehab if (buffer[24+p+2*n] != 0) 11510c0d06caSMauro Carvalho Chehab usb_string(udev, buffer[24+p+2*n], unit->name, 1152f14d4988SLaurent Pinchart sizeof(unit->name)); 11530c0d06caSMauro Carvalho Chehab else 11540c0d06caSMauro Carvalho Chehab sprintf(unit->name, "Extension %u", buffer[3]); 11550c0d06caSMauro Carvalho Chehab 11560c0d06caSMauro Carvalho Chehab list_add_tail(&unit->list, &dev->entities); 11570c0d06caSMauro Carvalho Chehab handled = 1; 11580c0d06caSMauro Carvalho Chehab break; 11590c0d06caSMauro Carvalho Chehab } 11600c0d06caSMauro Carvalho Chehab 11610c0d06caSMauro Carvalho Chehab return handled; 11620c0d06caSMauro Carvalho Chehab } 11630c0d06caSMauro Carvalho Chehab 11640c0d06caSMauro Carvalho Chehab static int uvc_parse_standard_control(struct uvc_device *dev, 11650c0d06caSMauro Carvalho Chehab const unsigned char *buffer, int buflen) 11660c0d06caSMauro Carvalho Chehab { 11670c0d06caSMauro Carvalho Chehab struct usb_device *udev = dev->udev; 11680c0d06caSMauro Carvalho Chehab struct uvc_entity *unit, *term; 11690c0d06caSMauro Carvalho Chehab struct usb_interface *intf; 11700c0d06caSMauro Carvalho Chehab struct usb_host_interface *alts = dev->intf->cur_altsetting; 11710c0d06caSMauro Carvalho Chehab unsigned int i, n, p, len; 11722c6b222cSLaurent Pinchart u16 type; 11730c0d06caSMauro Carvalho Chehab 11740c0d06caSMauro Carvalho Chehab switch (buffer[2]) { 11750c0d06caSMauro Carvalho Chehab case UVC_VC_HEADER: 11760c0d06caSMauro Carvalho Chehab n = buflen >= 12 ? buffer[11] : 0; 11770c0d06caSMauro Carvalho Chehab 1178daf41ac2SOliver Neukum if (buflen < 12 + n) { 11790c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 11800c0d06caSMauro Carvalho Chehab "interface %d HEADER error\n", udev->devnum, 11810c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber); 11820c0d06caSMauro Carvalho Chehab return -EINVAL; 11830c0d06caSMauro Carvalho Chehab } 11840c0d06caSMauro Carvalho Chehab 11850c0d06caSMauro Carvalho Chehab dev->uvc_version = get_unaligned_le16(&buffer[3]); 11860c0d06caSMauro Carvalho Chehab dev->clock_frequency = get_unaligned_le32(&buffer[7]); 11870c0d06caSMauro Carvalho Chehab 11880c0d06caSMauro Carvalho Chehab /* Parse all USB Video Streaming interfaces. */ 11890c0d06caSMauro Carvalho Chehab for (i = 0; i < n; ++i) { 11900c0d06caSMauro Carvalho Chehab intf = usb_ifnum_to_if(udev, buffer[12+i]); 11910c0d06caSMauro Carvalho Chehab if (intf == NULL) { 11920c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d " 11930c0d06caSMauro Carvalho Chehab "interface %d doesn't exists\n", 11940c0d06caSMauro Carvalho Chehab udev->devnum, i); 11950c0d06caSMauro Carvalho Chehab continue; 11960c0d06caSMauro Carvalho Chehab } 11970c0d06caSMauro Carvalho Chehab 11980c0d06caSMauro Carvalho Chehab uvc_parse_streaming(dev, intf); 11990c0d06caSMauro Carvalho Chehab } 12000c0d06caSMauro Carvalho Chehab break; 12010c0d06caSMauro Carvalho Chehab 12020c0d06caSMauro Carvalho Chehab case UVC_VC_INPUT_TERMINAL: 12030c0d06caSMauro Carvalho Chehab if (buflen < 8) { 12040c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 12050c0d06caSMauro Carvalho Chehab "interface %d INPUT_TERMINAL error\n", 12060c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 12070c0d06caSMauro Carvalho Chehab return -EINVAL; 12080c0d06caSMauro Carvalho Chehab } 12090c0d06caSMauro Carvalho Chehab 121047bb1179SAlistair Strachan /* 121147bb1179SAlistair Strachan * Reject invalid terminal types that would cause issues: 121247bb1179SAlistair Strachan * 121347bb1179SAlistair Strachan * - The high byte must be non-zero, otherwise it would be 121447bb1179SAlistair Strachan * confused with a unit. 121547bb1179SAlistair Strachan * 121647bb1179SAlistair Strachan * - Bit 15 must be 0, as we use it internally as a terminal 121747bb1179SAlistair Strachan * direction flag. 121847bb1179SAlistair Strachan * 121947bb1179SAlistair Strachan * Other unknown types are accepted. 12200c0d06caSMauro Carvalho Chehab */ 12210c0d06caSMauro Carvalho Chehab type = get_unaligned_le16(&buffer[4]); 122247bb1179SAlistair Strachan if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) { 12230c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 12240c0d06caSMauro Carvalho Chehab "interface %d INPUT_TERMINAL %d has invalid " 12250c0d06caSMauro Carvalho Chehab "type 0x%04x, skipping\n", udev->devnum, 12260c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber, 12270c0d06caSMauro Carvalho Chehab buffer[3], type); 12280c0d06caSMauro Carvalho Chehab return 0; 12290c0d06caSMauro Carvalho Chehab } 12300c0d06caSMauro Carvalho Chehab 12310c0d06caSMauro Carvalho Chehab n = 0; 12320c0d06caSMauro Carvalho Chehab p = 0; 12330c0d06caSMauro Carvalho Chehab len = 8; 12340c0d06caSMauro Carvalho Chehab 12350c0d06caSMauro Carvalho Chehab if (type == UVC_ITT_CAMERA) { 12360c0d06caSMauro Carvalho Chehab n = buflen >= 15 ? buffer[14] : 0; 12370c0d06caSMauro Carvalho Chehab len = 15; 12380c0d06caSMauro Carvalho Chehab 12390c0d06caSMauro Carvalho Chehab } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) { 12400c0d06caSMauro Carvalho Chehab n = buflen >= 9 ? buffer[8] : 0; 12410c0d06caSMauro Carvalho Chehab p = buflen >= 10 + n ? buffer[9+n] : 0; 12420c0d06caSMauro Carvalho Chehab len = 10; 12430c0d06caSMauro Carvalho Chehab } 12440c0d06caSMauro Carvalho Chehab 12450c0d06caSMauro Carvalho Chehab if (buflen < len + n + p) { 12460c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 12470c0d06caSMauro Carvalho Chehab "interface %d INPUT_TERMINAL error\n", 12480c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 12490c0d06caSMauro Carvalho Chehab return -EINVAL; 12500c0d06caSMauro Carvalho Chehab } 12510c0d06caSMauro Carvalho Chehab 12520c0d06caSMauro Carvalho Chehab term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3], 12530c0d06caSMauro Carvalho Chehab 1, n + p); 12540c0d06caSMauro Carvalho Chehab if (term == NULL) 12550c0d06caSMauro Carvalho Chehab return -ENOMEM; 12560c0d06caSMauro Carvalho Chehab 12570c0d06caSMauro Carvalho Chehab if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) { 12580c0d06caSMauro Carvalho Chehab term->camera.bControlSize = n; 1259f14d4988SLaurent Pinchart term->camera.bmControls = (u8 *)term + sizeof(*term); 12600c0d06caSMauro Carvalho Chehab term->camera.wObjectiveFocalLengthMin = 12610c0d06caSMauro Carvalho Chehab get_unaligned_le16(&buffer[8]); 12620c0d06caSMauro Carvalho Chehab term->camera.wObjectiveFocalLengthMax = 12630c0d06caSMauro Carvalho Chehab get_unaligned_le16(&buffer[10]); 12640c0d06caSMauro Carvalho Chehab term->camera.wOcularFocalLength = 12650c0d06caSMauro Carvalho Chehab get_unaligned_le16(&buffer[12]); 12660c0d06caSMauro Carvalho Chehab memcpy(term->camera.bmControls, &buffer[15], n); 12670c0d06caSMauro Carvalho Chehab } else if (UVC_ENTITY_TYPE(term) == 12680c0d06caSMauro Carvalho Chehab UVC_ITT_MEDIA_TRANSPORT_INPUT) { 12690c0d06caSMauro Carvalho Chehab term->media.bControlSize = n; 1270f14d4988SLaurent Pinchart term->media.bmControls = (u8 *)term + sizeof(*term); 12710c0d06caSMauro Carvalho Chehab term->media.bTransportModeSize = p; 12722c6b222cSLaurent Pinchart term->media.bmTransportModes = (u8 *)term 1273f14d4988SLaurent Pinchart + sizeof(*term) + n; 12740c0d06caSMauro Carvalho Chehab memcpy(term->media.bmControls, &buffer[9], n); 12750c0d06caSMauro Carvalho Chehab memcpy(term->media.bmTransportModes, &buffer[10+n], p); 12760c0d06caSMauro Carvalho Chehab } 12770c0d06caSMauro Carvalho Chehab 12780c0d06caSMauro Carvalho Chehab if (buffer[7] != 0) 12790c0d06caSMauro Carvalho Chehab usb_string(udev, buffer[7], term->name, 1280f14d4988SLaurent Pinchart sizeof(term->name)); 12810c0d06caSMauro Carvalho Chehab else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) 12820c0d06caSMauro Carvalho Chehab sprintf(term->name, "Camera %u", buffer[3]); 12830c0d06caSMauro Carvalho Chehab else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT) 12840c0d06caSMauro Carvalho Chehab sprintf(term->name, "Media %u", buffer[3]); 12850c0d06caSMauro Carvalho Chehab else 12860c0d06caSMauro Carvalho Chehab sprintf(term->name, "Input %u", buffer[3]); 12870c0d06caSMauro Carvalho Chehab 12880c0d06caSMauro Carvalho Chehab list_add_tail(&term->list, &dev->entities); 12890c0d06caSMauro Carvalho Chehab break; 12900c0d06caSMauro Carvalho Chehab 12910c0d06caSMauro Carvalho Chehab case UVC_VC_OUTPUT_TERMINAL: 12920c0d06caSMauro Carvalho Chehab if (buflen < 9) { 12930c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 12940c0d06caSMauro Carvalho Chehab "interface %d OUTPUT_TERMINAL error\n", 12950c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 12960c0d06caSMauro Carvalho Chehab return -EINVAL; 12970c0d06caSMauro Carvalho Chehab } 12980c0d06caSMauro Carvalho Chehab 12990c0d06caSMauro Carvalho Chehab /* Make sure the terminal type MSB is not null, otherwise it 13000c0d06caSMauro Carvalho Chehab * could be confused with a unit. 13010c0d06caSMauro Carvalho Chehab */ 13020c0d06caSMauro Carvalho Chehab type = get_unaligned_le16(&buffer[4]); 13030c0d06caSMauro Carvalho Chehab if ((type & 0xff00) == 0) { 13040c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 13050c0d06caSMauro Carvalho Chehab "interface %d OUTPUT_TERMINAL %d has invalid " 13060c0d06caSMauro Carvalho Chehab "type 0x%04x, skipping\n", udev->devnum, 13070c0d06caSMauro Carvalho Chehab alts->desc.bInterfaceNumber, buffer[3], type); 13080c0d06caSMauro Carvalho Chehab return 0; 13090c0d06caSMauro Carvalho Chehab } 13100c0d06caSMauro Carvalho Chehab 13110c0d06caSMauro Carvalho Chehab term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3], 13120c0d06caSMauro Carvalho Chehab 1, 0); 13130c0d06caSMauro Carvalho Chehab if (term == NULL) 13140c0d06caSMauro Carvalho Chehab return -ENOMEM; 13150c0d06caSMauro Carvalho Chehab 13160c0d06caSMauro Carvalho Chehab memcpy(term->baSourceID, &buffer[7], 1); 13170c0d06caSMauro Carvalho Chehab 13180c0d06caSMauro Carvalho Chehab if (buffer[8] != 0) 13190c0d06caSMauro Carvalho Chehab usb_string(udev, buffer[8], term->name, 1320f14d4988SLaurent Pinchart sizeof(term->name)); 13210c0d06caSMauro Carvalho Chehab else 13220c0d06caSMauro Carvalho Chehab sprintf(term->name, "Output %u", buffer[3]); 13230c0d06caSMauro Carvalho Chehab 13240c0d06caSMauro Carvalho Chehab list_add_tail(&term->list, &dev->entities); 13250c0d06caSMauro Carvalho Chehab break; 13260c0d06caSMauro Carvalho Chehab 13270c0d06caSMauro Carvalho Chehab case UVC_VC_SELECTOR_UNIT: 13280c0d06caSMauro Carvalho Chehab p = buflen >= 5 ? buffer[4] : 0; 13290c0d06caSMauro Carvalho Chehab 13300c0d06caSMauro Carvalho Chehab if (buflen < 5 || buflen < 6 + p) { 13310c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 13320c0d06caSMauro Carvalho Chehab "interface %d SELECTOR_UNIT error\n", 13330c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 13340c0d06caSMauro Carvalho Chehab return -EINVAL; 13350c0d06caSMauro Carvalho Chehab } 13360c0d06caSMauro Carvalho Chehab 13370c0d06caSMauro Carvalho Chehab unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0); 13380c0d06caSMauro Carvalho Chehab if (unit == NULL) 13390c0d06caSMauro Carvalho Chehab return -ENOMEM; 13400c0d06caSMauro Carvalho Chehab 13410c0d06caSMauro Carvalho Chehab memcpy(unit->baSourceID, &buffer[5], p); 13420c0d06caSMauro Carvalho Chehab 13430c0d06caSMauro Carvalho Chehab if (buffer[5+p] != 0) 13440c0d06caSMauro Carvalho Chehab usb_string(udev, buffer[5+p], unit->name, 1345f14d4988SLaurent Pinchart sizeof(unit->name)); 13460c0d06caSMauro Carvalho Chehab else 13470c0d06caSMauro Carvalho Chehab sprintf(unit->name, "Selector %u", buffer[3]); 13480c0d06caSMauro Carvalho Chehab 13490c0d06caSMauro Carvalho Chehab list_add_tail(&unit->list, &dev->entities); 13500c0d06caSMauro Carvalho Chehab break; 13510c0d06caSMauro Carvalho Chehab 13520c0d06caSMauro Carvalho Chehab case UVC_VC_PROCESSING_UNIT: 13530c0d06caSMauro Carvalho Chehab n = buflen >= 8 ? buffer[7] : 0; 13540c0d06caSMauro Carvalho Chehab p = dev->uvc_version >= 0x0110 ? 10 : 9; 13550c0d06caSMauro Carvalho Chehab 13560c0d06caSMauro Carvalho Chehab if (buflen < p + n) { 13570c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 13580c0d06caSMauro Carvalho Chehab "interface %d PROCESSING_UNIT error\n", 13590c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 13600c0d06caSMauro Carvalho Chehab return -EINVAL; 13610c0d06caSMauro Carvalho Chehab } 13620c0d06caSMauro Carvalho Chehab 13630c0d06caSMauro Carvalho Chehab unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n); 13640c0d06caSMauro Carvalho Chehab if (unit == NULL) 13650c0d06caSMauro Carvalho Chehab return -ENOMEM; 13660c0d06caSMauro Carvalho Chehab 13670c0d06caSMauro Carvalho Chehab memcpy(unit->baSourceID, &buffer[4], 1); 13680c0d06caSMauro Carvalho Chehab unit->processing.wMaxMultiplier = 13690c0d06caSMauro Carvalho Chehab get_unaligned_le16(&buffer[5]); 13700c0d06caSMauro Carvalho Chehab unit->processing.bControlSize = buffer[7]; 1371f14d4988SLaurent Pinchart unit->processing.bmControls = (u8 *)unit + sizeof(*unit); 13720c0d06caSMauro Carvalho Chehab memcpy(unit->processing.bmControls, &buffer[8], n); 13730c0d06caSMauro Carvalho Chehab if (dev->uvc_version >= 0x0110) 13740c0d06caSMauro Carvalho Chehab unit->processing.bmVideoStandards = buffer[9+n]; 13750c0d06caSMauro Carvalho Chehab 13760c0d06caSMauro Carvalho Chehab if (buffer[8+n] != 0) 13770c0d06caSMauro Carvalho Chehab usb_string(udev, buffer[8+n], unit->name, 1378f14d4988SLaurent Pinchart sizeof(unit->name)); 13790c0d06caSMauro Carvalho Chehab else 13800c0d06caSMauro Carvalho Chehab sprintf(unit->name, "Processing %u", buffer[3]); 13810c0d06caSMauro Carvalho Chehab 13820c0d06caSMauro Carvalho Chehab list_add_tail(&unit->list, &dev->entities); 13830c0d06caSMauro Carvalho Chehab break; 13840c0d06caSMauro Carvalho Chehab 13850c0d06caSMauro Carvalho Chehab case UVC_VC_EXTENSION_UNIT: 13860c0d06caSMauro Carvalho Chehab p = buflen >= 22 ? buffer[21] : 0; 13870c0d06caSMauro Carvalho Chehab n = buflen >= 24 + p ? buffer[22+p] : 0; 13880c0d06caSMauro Carvalho Chehab 13890c0d06caSMauro Carvalho Chehab if (buflen < 24 + p + n) { 13900c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 13910c0d06caSMauro Carvalho Chehab "interface %d EXTENSION_UNIT error\n", 13920c0d06caSMauro Carvalho Chehab udev->devnum, alts->desc.bInterfaceNumber); 13930c0d06caSMauro Carvalho Chehab return -EINVAL; 13940c0d06caSMauro Carvalho Chehab } 13950c0d06caSMauro Carvalho Chehab 13960c0d06caSMauro Carvalho Chehab unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n); 13970c0d06caSMauro Carvalho Chehab if (unit == NULL) 13980c0d06caSMauro Carvalho Chehab return -ENOMEM; 13990c0d06caSMauro Carvalho Chehab 1400351509c6SRicardo Ribalda memcpy(unit->guid, &buffer[4], 16); 14010c0d06caSMauro Carvalho Chehab unit->extension.bNumControls = buffer[20]; 14020c0d06caSMauro Carvalho Chehab memcpy(unit->baSourceID, &buffer[22], p); 14030c0d06caSMauro Carvalho Chehab unit->extension.bControlSize = buffer[22+p]; 1404f14d4988SLaurent Pinchart unit->extension.bmControls = (u8 *)unit + sizeof(*unit); 14050c0d06caSMauro Carvalho Chehab memcpy(unit->extension.bmControls, &buffer[23+p], n); 14060c0d06caSMauro Carvalho Chehab 14070c0d06caSMauro Carvalho Chehab if (buffer[23+p+n] != 0) 14080c0d06caSMauro Carvalho Chehab usb_string(udev, buffer[23+p+n], unit->name, 1409f14d4988SLaurent Pinchart sizeof(unit->name)); 14100c0d06caSMauro Carvalho Chehab else 14110c0d06caSMauro Carvalho Chehab sprintf(unit->name, "Extension %u", buffer[3]); 14120c0d06caSMauro Carvalho Chehab 14130c0d06caSMauro Carvalho Chehab list_add_tail(&unit->list, &dev->entities); 14140c0d06caSMauro Carvalho Chehab break; 14150c0d06caSMauro Carvalho Chehab 14160c0d06caSMauro Carvalho Chehab default: 14170c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE " 14180c0d06caSMauro Carvalho Chehab "descriptor (%u)\n", buffer[2]); 14190c0d06caSMauro Carvalho Chehab break; 14200c0d06caSMauro Carvalho Chehab } 14210c0d06caSMauro Carvalho Chehab 14220c0d06caSMauro Carvalho Chehab return 0; 14230c0d06caSMauro Carvalho Chehab } 14240c0d06caSMauro Carvalho Chehab 14250c0d06caSMauro Carvalho Chehab static int uvc_parse_control(struct uvc_device *dev) 14260c0d06caSMauro Carvalho Chehab { 14270c0d06caSMauro Carvalho Chehab struct usb_host_interface *alts = dev->intf->cur_altsetting; 14280c0d06caSMauro Carvalho Chehab unsigned char *buffer = alts->extra; 14290c0d06caSMauro Carvalho Chehab int buflen = alts->extralen; 14300c0d06caSMauro Carvalho Chehab int ret; 14310c0d06caSMauro Carvalho Chehab 14320c0d06caSMauro Carvalho Chehab /* Parse the default alternate setting only, as the UVC specification 14330c0d06caSMauro Carvalho Chehab * defines a single alternate setting, the default alternate setting 14340c0d06caSMauro Carvalho Chehab * zero. 14350c0d06caSMauro Carvalho Chehab */ 14360c0d06caSMauro Carvalho Chehab 14370c0d06caSMauro Carvalho Chehab while (buflen > 2) { 14380c0d06caSMauro Carvalho Chehab if (uvc_parse_vendor_control(dev, buffer, buflen) || 14390c0d06caSMauro Carvalho Chehab buffer[1] != USB_DT_CS_INTERFACE) 14400c0d06caSMauro Carvalho Chehab goto next_descriptor; 14410c0d06caSMauro Carvalho Chehab 14420c0d06caSMauro Carvalho Chehab if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0) 14430c0d06caSMauro Carvalho Chehab return ret; 14440c0d06caSMauro Carvalho Chehab 14450c0d06caSMauro Carvalho Chehab next_descriptor: 14460c0d06caSMauro Carvalho Chehab buflen -= buffer[0]; 14470c0d06caSMauro Carvalho Chehab buffer += buffer[0]; 14480c0d06caSMauro Carvalho Chehab } 14490c0d06caSMauro Carvalho Chehab 14500c0d06caSMauro Carvalho Chehab /* Check if the optional status endpoint is present. Built-in iSight 14510c0d06caSMauro Carvalho Chehab * webcams have an interrupt endpoint but spit proprietary data that 14520c0d06caSMauro Carvalho Chehab * don't conform to the UVC status endpoint messages. Don't try to 14530c0d06caSMauro Carvalho Chehab * handle the interrupt endpoint for those cameras. 14540c0d06caSMauro Carvalho Chehab */ 14550c0d06caSMauro Carvalho Chehab if (alts->desc.bNumEndpoints == 1 && 14560c0d06caSMauro Carvalho Chehab !(dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)) { 14570c0d06caSMauro Carvalho Chehab struct usb_host_endpoint *ep = &alts->endpoint[0]; 14580c0d06caSMauro Carvalho Chehab struct usb_endpoint_descriptor *desc = &ep->desc; 14590c0d06caSMauro Carvalho Chehab 14600c0d06caSMauro Carvalho Chehab if (usb_endpoint_is_int_in(desc) && 14610c0d06caSMauro Carvalho Chehab le16_to_cpu(desc->wMaxPacketSize) >= 8 && 14620c0d06caSMauro Carvalho Chehab desc->bInterval != 0) { 14630c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint " 14640c0d06caSMauro Carvalho Chehab "(addr %02x).\n", desc->bEndpointAddress); 14650c0d06caSMauro Carvalho Chehab dev->int_ep = ep; 14660c0d06caSMauro Carvalho Chehab } 14670c0d06caSMauro Carvalho Chehab } 14680c0d06caSMauro Carvalho Chehab 14690c0d06caSMauro Carvalho Chehab return 0; 14700c0d06caSMauro Carvalho Chehab } 14710c0d06caSMauro Carvalho Chehab 1472*2886477fSRicardo Ribalda /* ----------------------------------------------------------------------------- 1473*2886477fSRicardo Ribalda * Privacy GPIO 1474*2886477fSRicardo Ribalda */ 1475*2886477fSRicardo Ribalda 1476*2886477fSRicardo Ribalda static void uvc_gpio_event(struct uvc_device *dev) 1477*2886477fSRicardo Ribalda { 1478*2886477fSRicardo Ribalda struct uvc_entity *unit = dev->gpio_unit; 1479*2886477fSRicardo Ribalda struct uvc_video_chain *chain; 1480*2886477fSRicardo Ribalda u8 new_val; 1481*2886477fSRicardo Ribalda 1482*2886477fSRicardo Ribalda if (!unit) 1483*2886477fSRicardo Ribalda return; 1484*2886477fSRicardo Ribalda 1485*2886477fSRicardo Ribalda new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); 1486*2886477fSRicardo Ribalda 1487*2886477fSRicardo Ribalda /* GPIO entities are always on the first chain. */ 1488*2886477fSRicardo Ribalda chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); 1489*2886477fSRicardo Ribalda uvc_ctrl_status_event(chain, unit->controls, &new_val); 1490*2886477fSRicardo Ribalda } 1491*2886477fSRicardo Ribalda 1492*2886477fSRicardo Ribalda static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity, 1493*2886477fSRicardo Ribalda u8 cs, void *data, u16 size) 1494*2886477fSRicardo Ribalda { 1495*2886477fSRicardo Ribalda if (cs != UVC_CT_PRIVACY_CONTROL || size < 1) 1496*2886477fSRicardo Ribalda return -EINVAL; 1497*2886477fSRicardo Ribalda 1498*2886477fSRicardo Ribalda *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy); 1499*2886477fSRicardo Ribalda 1500*2886477fSRicardo Ribalda return 0; 1501*2886477fSRicardo Ribalda } 1502*2886477fSRicardo Ribalda 1503*2886477fSRicardo Ribalda static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity, 1504*2886477fSRicardo Ribalda u8 cs, u8 *caps) 1505*2886477fSRicardo Ribalda { 1506*2886477fSRicardo Ribalda if (cs != UVC_CT_PRIVACY_CONTROL) 1507*2886477fSRicardo Ribalda return -EINVAL; 1508*2886477fSRicardo Ribalda 1509*2886477fSRicardo Ribalda *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; 1510*2886477fSRicardo Ribalda return 0; 1511*2886477fSRicardo Ribalda } 1512*2886477fSRicardo Ribalda 1513*2886477fSRicardo Ribalda static irqreturn_t uvc_gpio_irq(int irq, void *data) 1514*2886477fSRicardo Ribalda { 1515*2886477fSRicardo Ribalda struct uvc_device *dev = data; 1516*2886477fSRicardo Ribalda 1517*2886477fSRicardo Ribalda uvc_gpio_event(dev); 1518*2886477fSRicardo Ribalda return IRQ_HANDLED; 1519*2886477fSRicardo Ribalda } 1520*2886477fSRicardo Ribalda 1521*2886477fSRicardo Ribalda static int uvc_gpio_parse(struct uvc_device *dev) 1522*2886477fSRicardo Ribalda { 1523*2886477fSRicardo Ribalda struct uvc_entity *unit; 1524*2886477fSRicardo Ribalda struct gpio_desc *gpio_privacy; 1525*2886477fSRicardo Ribalda int irq; 1526*2886477fSRicardo Ribalda 1527*2886477fSRicardo Ribalda gpio_privacy = devm_gpiod_get_optional(&dev->udev->dev, "privacy", 1528*2886477fSRicardo Ribalda GPIOD_IN); 1529*2886477fSRicardo Ribalda if (IS_ERR_OR_NULL(gpio_privacy)) 1530*2886477fSRicardo Ribalda return PTR_ERR_OR_ZERO(gpio_privacy); 1531*2886477fSRicardo Ribalda 1532*2886477fSRicardo Ribalda unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1); 1533*2886477fSRicardo Ribalda if (!unit) 1534*2886477fSRicardo Ribalda return -ENOMEM; 1535*2886477fSRicardo Ribalda 1536*2886477fSRicardo Ribalda irq = gpiod_to_irq(gpio_privacy); 1537*2886477fSRicardo Ribalda if (irq < 0) { 1538*2886477fSRicardo Ribalda if (irq != EPROBE_DEFER) 1539*2886477fSRicardo Ribalda dev_err(&dev->udev->dev, 1540*2886477fSRicardo Ribalda "No IRQ for privacy GPIO (%d)\n", irq); 1541*2886477fSRicardo Ribalda return irq; 1542*2886477fSRicardo Ribalda } 1543*2886477fSRicardo Ribalda 1544*2886477fSRicardo Ribalda unit->gpio.gpio_privacy = gpio_privacy; 1545*2886477fSRicardo Ribalda unit->gpio.irq = irq; 1546*2886477fSRicardo Ribalda unit->gpio.bControlSize = 1; 1547*2886477fSRicardo Ribalda unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); 1548*2886477fSRicardo Ribalda unit->gpio.bmControls[0] = 1; 1549*2886477fSRicardo Ribalda unit->get_cur = uvc_gpio_get_cur; 1550*2886477fSRicardo Ribalda unit->get_info = uvc_gpio_get_info; 1551*2886477fSRicardo Ribalda strncpy(unit->name, "GPIO", sizeof(unit->name) - 1); 1552*2886477fSRicardo Ribalda 1553*2886477fSRicardo Ribalda list_add_tail(&unit->list, &dev->entities); 1554*2886477fSRicardo Ribalda 1555*2886477fSRicardo Ribalda dev->gpio_unit = unit; 1556*2886477fSRicardo Ribalda 1557*2886477fSRicardo Ribalda return 0; 1558*2886477fSRicardo Ribalda } 1559*2886477fSRicardo Ribalda 1560*2886477fSRicardo Ribalda static int uvc_gpio_init_irq(struct uvc_device *dev) 1561*2886477fSRicardo Ribalda { 1562*2886477fSRicardo Ribalda struct uvc_entity *unit = dev->gpio_unit; 1563*2886477fSRicardo Ribalda 1564*2886477fSRicardo Ribalda if (!unit || unit->gpio.irq < 0) 1565*2886477fSRicardo Ribalda return 0; 1566*2886477fSRicardo Ribalda 1567*2886477fSRicardo Ribalda return devm_request_threaded_irq(&dev->udev->dev, unit->gpio.irq, NULL, 1568*2886477fSRicardo Ribalda uvc_gpio_irq, 1569*2886477fSRicardo Ribalda IRQF_ONESHOT | IRQF_TRIGGER_FALLING | 1570*2886477fSRicardo Ribalda IRQF_TRIGGER_RISING, 1571*2886477fSRicardo Ribalda "uvc_privacy_gpio", dev); 1572*2886477fSRicardo Ribalda } 1573*2886477fSRicardo Ribalda 15740c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 15750c0d06caSMauro Carvalho Chehab * UVC device scan 15760c0d06caSMauro Carvalho Chehab */ 15770c0d06caSMauro Carvalho Chehab 15780c0d06caSMauro Carvalho Chehab /* 15790c0d06caSMauro Carvalho Chehab * Scan the UVC descriptors to locate a chain starting at an Output Terminal 15800c0d06caSMauro Carvalho Chehab * and containing the following units: 15810c0d06caSMauro Carvalho Chehab * 15820c0d06caSMauro Carvalho Chehab * - one or more Output Terminals (USB Streaming or Display) 15830c0d06caSMauro Carvalho Chehab * - zero or one Processing Unit 15840c0d06caSMauro Carvalho Chehab * - zero, one or more single-input Selector Units 15850c0d06caSMauro Carvalho Chehab * - zero or one multiple-input Selector Units, provided all inputs are 15860c0d06caSMauro Carvalho Chehab * connected to input terminals 15870c0d06caSMauro Carvalho Chehab * - zero, one or mode single-input Extension Units 15880c0d06caSMauro Carvalho Chehab * - one or more Input Terminals (Camera, External or USB Streaming) 15890c0d06caSMauro Carvalho Chehab * 15900c0d06caSMauro Carvalho Chehab * The terminal and units must match on of the following structures: 15910c0d06caSMauro Carvalho Chehab * 15920c0d06caSMauro Carvalho Chehab * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0) 15930c0d06caSMauro Carvalho Chehab * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ... 15940c0d06caSMauro Carvalho Chehab * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n) 15950c0d06caSMauro Carvalho Chehab * 15960c0d06caSMauro Carvalho Chehab * +---------+ +---------+ -> OTT_*(0) 15970c0d06caSMauro Carvalho Chehab * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ... 15980c0d06caSMauro Carvalho Chehab * +---------+ +---------+ -> OTT_*(n) 15990c0d06caSMauro Carvalho Chehab * 16000c0d06caSMauro Carvalho Chehab * The Processing Unit and Extension Units can be in any order. Additional 16010c0d06caSMauro Carvalho Chehab * Extension Units connected to the main chain as single-unit branches are 16020c0d06caSMauro Carvalho Chehab * also supported. Single-input Selector Units are ignored. 16030c0d06caSMauro Carvalho Chehab */ 16040c0d06caSMauro Carvalho Chehab static int uvc_scan_chain_entity(struct uvc_video_chain *chain, 16050c0d06caSMauro Carvalho Chehab struct uvc_entity *entity) 16060c0d06caSMauro Carvalho Chehab { 16070c0d06caSMauro Carvalho Chehab switch (UVC_ENTITY_TYPE(entity)) { 16080c0d06caSMauro Carvalho Chehab case UVC_VC_EXTENSION_UNIT: 16090c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 161069396c4eSMauro Carvalho Chehab printk(KERN_CONT " <- XU %d", entity->id); 16110c0d06caSMauro Carvalho Chehab 16120c0d06caSMauro Carvalho Chehab if (entity->bNrInPins != 1) { 16130c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more " 16140c0d06caSMauro Carvalho Chehab "than 1 input pin.\n", entity->id); 16150c0d06caSMauro Carvalho Chehab return -1; 16160c0d06caSMauro Carvalho Chehab } 16170c0d06caSMauro Carvalho Chehab 16180c0d06caSMauro Carvalho Chehab break; 16190c0d06caSMauro Carvalho Chehab 16200c0d06caSMauro Carvalho Chehab case UVC_VC_PROCESSING_UNIT: 16210c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 162269396c4eSMauro Carvalho Chehab printk(KERN_CONT " <- PU %d", entity->id); 16230c0d06caSMauro Carvalho Chehab 16240c0d06caSMauro Carvalho Chehab if (chain->processing != NULL) { 16250c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found multiple " 16260c0d06caSMauro Carvalho Chehab "Processing Units in chain.\n"); 16270c0d06caSMauro Carvalho Chehab return -1; 16280c0d06caSMauro Carvalho Chehab } 16290c0d06caSMauro Carvalho Chehab 16300c0d06caSMauro Carvalho Chehab chain->processing = entity; 16310c0d06caSMauro Carvalho Chehab break; 16320c0d06caSMauro Carvalho Chehab 16330c0d06caSMauro Carvalho Chehab case UVC_VC_SELECTOR_UNIT: 16340c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 163569396c4eSMauro Carvalho Chehab printk(KERN_CONT " <- SU %d", entity->id); 16360c0d06caSMauro Carvalho Chehab 16370c0d06caSMauro Carvalho Chehab /* Single-input selector units are ignored. */ 16380c0d06caSMauro Carvalho Chehab if (entity->bNrInPins == 1) 16390c0d06caSMauro Carvalho Chehab break; 16400c0d06caSMauro Carvalho Chehab 16410c0d06caSMauro Carvalho Chehab if (chain->selector != NULL) { 16420c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector " 16430c0d06caSMauro Carvalho Chehab "Units in chain.\n"); 16440c0d06caSMauro Carvalho Chehab return -1; 16450c0d06caSMauro Carvalho Chehab } 16460c0d06caSMauro Carvalho Chehab 16470c0d06caSMauro Carvalho Chehab chain->selector = entity; 16480c0d06caSMauro Carvalho Chehab break; 16490c0d06caSMauro Carvalho Chehab 16500c0d06caSMauro Carvalho Chehab case UVC_ITT_VENDOR_SPECIFIC: 16510c0d06caSMauro Carvalho Chehab case UVC_ITT_CAMERA: 16520c0d06caSMauro Carvalho Chehab case UVC_ITT_MEDIA_TRANSPORT_INPUT: 16530c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 165469396c4eSMauro Carvalho Chehab printk(KERN_CONT " <- IT %d\n", entity->id); 16550c0d06caSMauro Carvalho Chehab 16560c0d06caSMauro Carvalho Chehab break; 16570c0d06caSMauro Carvalho Chehab 16580c0d06caSMauro Carvalho Chehab case UVC_OTT_VENDOR_SPECIFIC: 16590c0d06caSMauro Carvalho Chehab case UVC_OTT_DISPLAY: 16600c0d06caSMauro Carvalho Chehab case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: 16610c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 166269396c4eSMauro Carvalho Chehab printk(KERN_CONT " OT %d", entity->id); 16630c0d06caSMauro Carvalho Chehab 16640c0d06caSMauro Carvalho Chehab break; 16650c0d06caSMauro Carvalho Chehab 16660c0d06caSMauro Carvalho Chehab case UVC_TT_STREAMING: 16670c0d06caSMauro Carvalho Chehab if (UVC_ENTITY_IS_ITERM(entity)) { 16680c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 166969396c4eSMauro Carvalho Chehab printk(KERN_CONT " <- IT %d\n", entity->id); 16700c0d06caSMauro Carvalho Chehab } else { 16710c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 167269396c4eSMauro Carvalho Chehab printk(KERN_CONT " OT %d", entity->id); 16730c0d06caSMauro Carvalho Chehab } 16740c0d06caSMauro Carvalho Chehab 16750c0d06caSMauro Carvalho Chehab break; 16760c0d06caSMauro Carvalho Chehab 16770c0d06caSMauro Carvalho Chehab default: 16780c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type " 16790c0d06caSMauro Carvalho Chehab "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity)); 16800c0d06caSMauro Carvalho Chehab return -1; 16810c0d06caSMauro Carvalho Chehab } 16820c0d06caSMauro Carvalho Chehab 16830c0d06caSMauro Carvalho Chehab list_add_tail(&entity->chain, &chain->entities); 16840c0d06caSMauro Carvalho Chehab return 0; 16850c0d06caSMauro Carvalho Chehab } 16860c0d06caSMauro Carvalho Chehab 16870c0d06caSMauro Carvalho Chehab static int uvc_scan_chain_forward(struct uvc_video_chain *chain, 16880c0d06caSMauro Carvalho Chehab struct uvc_entity *entity, struct uvc_entity *prev) 16890c0d06caSMauro Carvalho Chehab { 16900c0d06caSMauro Carvalho Chehab struct uvc_entity *forward; 16910c0d06caSMauro Carvalho Chehab int found; 16920c0d06caSMauro Carvalho Chehab 16930c0d06caSMauro Carvalho Chehab /* Forward scan */ 16940c0d06caSMauro Carvalho Chehab forward = NULL; 16950c0d06caSMauro Carvalho Chehab found = 0; 16960c0d06caSMauro Carvalho Chehab 16970c0d06caSMauro Carvalho Chehab while (1) { 16980c0d06caSMauro Carvalho Chehab forward = uvc_entity_by_reference(chain->dev, entity->id, 16990c0d06caSMauro Carvalho Chehab forward); 17000c0d06caSMauro Carvalho Chehab if (forward == NULL) 17010c0d06caSMauro Carvalho Chehab break; 17020c0d06caSMauro Carvalho Chehab if (forward == prev) 17030c0d06caSMauro Carvalho Chehab continue; 170468035c80SWill Deacon if (forward->chain.next || forward->chain.prev) { 170568035c80SWill Deacon uvc_trace(UVC_TRACE_DESCR, "Found reference to " 170668035c80SWill Deacon "entity %d already in chain.\n", forward->id); 170768035c80SWill Deacon return -EINVAL; 170868035c80SWill Deacon } 17090c0d06caSMauro Carvalho Chehab 17100c0d06caSMauro Carvalho Chehab switch (UVC_ENTITY_TYPE(forward)) { 17110c0d06caSMauro Carvalho Chehab case UVC_VC_EXTENSION_UNIT: 17120c0d06caSMauro Carvalho Chehab if (forward->bNrInPins != 1) { 17130c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Extension unit %d " 17140c0d06caSMauro Carvalho Chehab "has more than 1 input pin.\n", 17150c0d06caSMauro Carvalho Chehab entity->id); 17160c0d06caSMauro Carvalho Chehab return -EINVAL; 17170c0d06caSMauro Carvalho Chehab } 17180c0d06caSMauro Carvalho Chehab 17190c0d06caSMauro Carvalho Chehab list_add_tail(&forward->chain, &chain->entities); 17200c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) { 17210c0d06caSMauro Carvalho Chehab if (!found) 172269396c4eSMauro Carvalho Chehab printk(KERN_CONT " (->"); 17230c0d06caSMauro Carvalho Chehab 172469396c4eSMauro Carvalho Chehab printk(KERN_CONT " XU %d", forward->id); 17250c0d06caSMauro Carvalho Chehab found = 1; 17260c0d06caSMauro Carvalho Chehab } 17270c0d06caSMauro Carvalho Chehab break; 17280c0d06caSMauro Carvalho Chehab 17290c0d06caSMauro Carvalho Chehab case UVC_OTT_VENDOR_SPECIFIC: 17300c0d06caSMauro Carvalho Chehab case UVC_OTT_DISPLAY: 17310c0d06caSMauro Carvalho Chehab case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: 17320c0d06caSMauro Carvalho Chehab case UVC_TT_STREAMING: 17330c0d06caSMauro Carvalho Chehab if (UVC_ENTITY_IS_ITERM(forward)) { 17340c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Unsupported input " 17350c0d06caSMauro Carvalho Chehab "terminal %u.\n", forward->id); 17360c0d06caSMauro Carvalho Chehab return -EINVAL; 17370c0d06caSMauro Carvalho Chehab } 17380c0d06caSMauro Carvalho Chehab 17390c0d06caSMauro Carvalho Chehab list_add_tail(&forward->chain, &chain->entities); 17400c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) { 17410c0d06caSMauro Carvalho Chehab if (!found) 174269396c4eSMauro Carvalho Chehab printk(KERN_CONT " (->"); 17430c0d06caSMauro Carvalho Chehab 174469396c4eSMauro Carvalho Chehab printk(KERN_CONT " OT %d", forward->id); 17450c0d06caSMauro Carvalho Chehab found = 1; 17460c0d06caSMauro Carvalho Chehab } 17470c0d06caSMauro Carvalho Chehab break; 17480c0d06caSMauro Carvalho Chehab } 17490c0d06caSMauro Carvalho Chehab } 17500c0d06caSMauro Carvalho Chehab if (found) 175169396c4eSMauro Carvalho Chehab printk(KERN_CONT ")"); 17520c0d06caSMauro Carvalho Chehab 17530c0d06caSMauro Carvalho Chehab return 0; 17540c0d06caSMauro Carvalho Chehab } 17550c0d06caSMauro Carvalho Chehab 17560c0d06caSMauro Carvalho Chehab static int uvc_scan_chain_backward(struct uvc_video_chain *chain, 17570c0d06caSMauro Carvalho Chehab struct uvc_entity **_entity) 17580c0d06caSMauro Carvalho Chehab { 17590c0d06caSMauro Carvalho Chehab struct uvc_entity *entity = *_entity; 17600c0d06caSMauro Carvalho Chehab struct uvc_entity *term; 17610c0d06caSMauro Carvalho Chehab int id = -EINVAL, i; 17620c0d06caSMauro Carvalho Chehab 17630c0d06caSMauro Carvalho Chehab switch (UVC_ENTITY_TYPE(entity)) { 17640c0d06caSMauro Carvalho Chehab case UVC_VC_EXTENSION_UNIT: 17650c0d06caSMauro Carvalho Chehab case UVC_VC_PROCESSING_UNIT: 17660c0d06caSMauro Carvalho Chehab id = entity->baSourceID[0]; 17670c0d06caSMauro Carvalho Chehab break; 17680c0d06caSMauro Carvalho Chehab 17690c0d06caSMauro Carvalho Chehab case UVC_VC_SELECTOR_UNIT: 17700c0d06caSMauro Carvalho Chehab /* Single-input selector units are ignored. */ 17710c0d06caSMauro Carvalho Chehab if (entity->bNrInPins == 1) { 17720c0d06caSMauro Carvalho Chehab id = entity->baSourceID[0]; 17730c0d06caSMauro Carvalho Chehab break; 17740c0d06caSMauro Carvalho Chehab } 17750c0d06caSMauro Carvalho Chehab 17760c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 177769396c4eSMauro Carvalho Chehab printk(KERN_CONT " <- IT"); 17780c0d06caSMauro Carvalho Chehab 17790c0d06caSMauro Carvalho Chehab chain->selector = entity; 17800c0d06caSMauro Carvalho Chehab for (i = 0; i < entity->bNrInPins; ++i) { 17810c0d06caSMauro Carvalho Chehab id = entity->baSourceID[i]; 17820c0d06caSMauro Carvalho Chehab term = uvc_entity_by_id(chain->dev, id); 17830c0d06caSMauro Carvalho Chehab if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) { 17840c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Selector unit %d " 17850c0d06caSMauro Carvalho Chehab "input %d isn't connected to an " 17860c0d06caSMauro Carvalho Chehab "input terminal\n", entity->id, i); 17870c0d06caSMauro Carvalho Chehab return -1; 17880c0d06caSMauro Carvalho Chehab } 17890c0d06caSMauro Carvalho Chehab 179068035c80SWill Deacon if (term->chain.next || term->chain.prev) { 179168035c80SWill Deacon uvc_trace(UVC_TRACE_DESCR, "Found reference to " 179268035c80SWill Deacon "entity %d already in chain.\n", 179368035c80SWill Deacon term->id); 179468035c80SWill Deacon return -EINVAL; 179568035c80SWill Deacon } 179668035c80SWill Deacon 17970c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 179869396c4eSMauro Carvalho Chehab printk(KERN_CONT " %d", term->id); 17990c0d06caSMauro Carvalho Chehab 18000c0d06caSMauro Carvalho Chehab list_add_tail(&term->chain, &chain->entities); 18010c0d06caSMauro Carvalho Chehab uvc_scan_chain_forward(chain, term, entity); 18020c0d06caSMauro Carvalho Chehab } 18030c0d06caSMauro Carvalho Chehab 18040c0d06caSMauro Carvalho Chehab if (uvc_trace_param & UVC_TRACE_PROBE) 180569396c4eSMauro Carvalho Chehab printk(KERN_CONT "\n"); 18060c0d06caSMauro Carvalho Chehab 18070c0d06caSMauro Carvalho Chehab id = 0; 18080c0d06caSMauro Carvalho Chehab break; 18090c0d06caSMauro Carvalho Chehab 18100c0d06caSMauro Carvalho Chehab case UVC_ITT_VENDOR_SPECIFIC: 18110c0d06caSMauro Carvalho Chehab case UVC_ITT_CAMERA: 18120c0d06caSMauro Carvalho Chehab case UVC_ITT_MEDIA_TRANSPORT_INPUT: 18130c0d06caSMauro Carvalho Chehab case UVC_OTT_VENDOR_SPECIFIC: 18140c0d06caSMauro Carvalho Chehab case UVC_OTT_DISPLAY: 18150c0d06caSMauro Carvalho Chehab case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: 18160c0d06caSMauro Carvalho Chehab case UVC_TT_STREAMING: 18170c0d06caSMauro Carvalho Chehab id = UVC_ENTITY_IS_OTERM(entity) ? entity->baSourceID[0] : 0; 18180c0d06caSMauro Carvalho Chehab break; 18190c0d06caSMauro Carvalho Chehab } 18200c0d06caSMauro Carvalho Chehab 18210c0d06caSMauro Carvalho Chehab if (id <= 0) { 18220c0d06caSMauro Carvalho Chehab *_entity = NULL; 18230c0d06caSMauro Carvalho Chehab return id; 18240c0d06caSMauro Carvalho Chehab } 18250c0d06caSMauro Carvalho Chehab 18260c0d06caSMauro Carvalho Chehab entity = uvc_entity_by_id(chain->dev, id); 18270c0d06caSMauro Carvalho Chehab if (entity == NULL) { 18280c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found reference to " 18290c0d06caSMauro Carvalho Chehab "unknown entity %d.\n", id); 18300c0d06caSMauro Carvalho Chehab return -EINVAL; 18310c0d06caSMauro Carvalho Chehab } 18320c0d06caSMauro Carvalho Chehab 18330c0d06caSMauro Carvalho Chehab *_entity = entity; 18340c0d06caSMauro Carvalho Chehab return 0; 18350c0d06caSMauro Carvalho Chehab } 18360c0d06caSMauro Carvalho Chehab 18370c0d06caSMauro Carvalho Chehab static int uvc_scan_chain(struct uvc_video_chain *chain, 18380c0d06caSMauro Carvalho Chehab struct uvc_entity *term) 18390c0d06caSMauro Carvalho Chehab { 18400c0d06caSMauro Carvalho Chehab struct uvc_entity *entity, *prev; 18410c0d06caSMauro Carvalho Chehab 18420c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain:"); 18430c0d06caSMauro Carvalho Chehab 18440c0d06caSMauro Carvalho Chehab entity = term; 18450c0d06caSMauro Carvalho Chehab prev = NULL; 18460c0d06caSMauro Carvalho Chehab 18470c0d06caSMauro Carvalho Chehab while (entity != NULL) { 18480c0d06caSMauro Carvalho Chehab /* Entity must not be part of an existing chain */ 18490c0d06caSMauro Carvalho Chehab if (entity->chain.next || entity->chain.prev) { 18500c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_DESCR, "Found reference to " 18510c0d06caSMauro Carvalho Chehab "entity %d already in chain.\n", entity->id); 18520c0d06caSMauro Carvalho Chehab return -EINVAL; 18530c0d06caSMauro Carvalho Chehab } 18540c0d06caSMauro Carvalho Chehab 18550c0d06caSMauro Carvalho Chehab /* Process entity */ 18560c0d06caSMauro Carvalho Chehab if (uvc_scan_chain_entity(chain, entity) < 0) 18570c0d06caSMauro Carvalho Chehab return -EINVAL; 18580c0d06caSMauro Carvalho Chehab 18590c0d06caSMauro Carvalho Chehab /* Forward scan */ 18600c0d06caSMauro Carvalho Chehab if (uvc_scan_chain_forward(chain, entity, prev) < 0) 18610c0d06caSMauro Carvalho Chehab return -EINVAL; 18620c0d06caSMauro Carvalho Chehab 18630c0d06caSMauro Carvalho Chehab /* Backward scan */ 18640c0d06caSMauro Carvalho Chehab prev = entity; 18650c0d06caSMauro Carvalho Chehab if (uvc_scan_chain_backward(chain, &entity) < 0) 18660c0d06caSMauro Carvalho Chehab return -EINVAL; 18670c0d06caSMauro Carvalho Chehab } 18680c0d06caSMauro Carvalho Chehab 18690c0d06caSMauro Carvalho Chehab return 0; 18700c0d06caSMauro Carvalho Chehab } 18710c0d06caSMauro Carvalho Chehab 18720c0d06caSMauro Carvalho Chehab static unsigned int uvc_print_terms(struct list_head *terms, u16 dir, 18730c0d06caSMauro Carvalho Chehab char *buffer) 18740c0d06caSMauro Carvalho Chehab { 18750c0d06caSMauro Carvalho Chehab struct uvc_entity *term; 18760c0d06caSMauro Carvalho Chehab unsigned int nterms = 0; 18770c0d06caSMauro Carvalho Chehab char *p = buffer; 18780c0d06caSMauro Carvalho Chehab 18790c0d06caSMauro Carvalho Chehab list_for_each_entry(term, terms, chain) { 18800c0d06caSMauro Carvalho Chehab if (!UVC_ENTITY_IS_TERM(term) || 18810c0d06caSMauro Carvalho Chehab UVC_TERM_DIRECTION(term) != dir) 18820c0d06caSMauro Carvalho Chehab continue; 18830c0d06caSMauro Carvalho Chehab 18840c0d06caSMauro Carvalho Chehab if (nterms) 18850c0d06caSMauro Carvalho Chehab p += sprintf(p, ","); 18860c0d06caSMauro Carvalho Chehab if (++nterms >= 4) { 18870c0d06caSMauro Carvalho Chehab p += sprintf(p, "..."); 18880c0d06caSMauro Carvalho Chehab break; 18890c0d06caSMauro Carvalho Chehab } 18900c0d06caSMauro Carvalho Chehab p += sprintf(p, "%u", term->id); 18910c0d06caSMauro Carvalho Chehab } 18920c0d06caSMauro Carvalho Chehab 18930c0d06caSMauro Carvalho Chehab return p - buffer; 18940c0d06caSMauro Carvalho Chehab } 18950c0d06caSMauro Carvalho Chehab 18960c0d06caSMauro Carvalho Chehab static const char *uvc_print_chain(struct uvc_video_chain *chain) 18970c0d06caSMauro Carvalho Chehab { 18980c0d06caSMauro Carvalho Chehab static char buffer[43]; 18990c0d06caSMauro Carvalho Chehab char *p = buffer; 19000c0d06caSMauro Carvalho Chehab 19010c0d06caSMauro Carvalho Chehab p += uvc_print_terms(&chain->entities, UVC_TERM_INPUT, p); 19020c0d06caSMauro Carvalho Chehab p += sprintf(p, " -> "); 19030c0d06caSMauro Carvalho Chehab uvc_print_terms(&chain->entities, UVC_TERM_OUTPUT, p); 19040c0d06caSMauro Carvalho Chehab 19050c0d06caSMauro Carvalho Chehab return buffer; 19060c0d06caSMauro Carvalho Chehab } 19070c0d06caSMauro Carvalho Chehab 1908e950267aSHenrik Ingo static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev) 1909e950267aSHenrik Ingo { 1910e950267aSHenrik Ingo struct uvc_video_chain *chain; 1911e950267aSHenrik Ingo 1912e950267aSHenrik Ingo chain = kzalloc(sizeof(*chain), GFP_KERNEL); 1913e950267aSHenrik Ingo if (chain == NULL) 1914e950267aSHenrik Ingo return NULL; 1915e950267aSHenrik Ingo 1916e950267aSHenrik Ingo INIT_LIST_HEAD(&chain->entities); 1917e950267aSHenrik Ingo mutex_init(&chain->ctrl_mutex); 1918e950267aSHenrik Ingo chain->dev = dev; 1919e950267aSHenrik Ingo v4l2_prio_init(&chain->prio); 1920e950267aSHenrik Ingo 1921e950267aSHenrik Ingo return chain; 1922e950267aSHenrik Ingo } 1923e950267aSHenrik Ingo 1924e950267aSHenrik Ingo /* 1925e950267aSHenrik Ingo * Fallback heuristic for devices that don't connect units and terminals in a 1926e950267aSHenrik Ingo * valid chain. 1927e950267aSHenrik Ingo * 1928e950267aSHenrik Ingo * Some devices have invalid baSourceID references, causing uvc_scan_chain() 1929e950267aSHenrik Ingo * to fail, but if we just take the entities we can find and put them together 1930e950267aSHenrik Ingo * in the most sensible chain we can think of, turns out they do work anyway. 1931e950267aSHenrik Ingo * Note: This heuristic assumes there is a single chain. 1932e950267aSHenrik Ingo * 1933e950267aSHenrik Ingo * At the time of writing, devices known to have such a broken chain are 1934e950267aSHenrik Ingo * - Acer Integrated Camera (5986:055a) 1935e950267aSHenrik Ingo * - Realtek rtl157a7 (0bda:57a7) 1936e950267aSHenrik Ingo */ 1937e950267aSHenrik Ingo static int uvc_scan_fallback(struct uvc_device *dev) 1938e950267aSHenrik Ingo { 1939e950267aSHenrik Ingo struct uvc_video_chain *chain; 1940e950267aSHenrik Ingo struct uvc_entity *iterm = NULL; 1941e950267aSHenrik Ingo struct uvc_entity *oterm = NULL; 1942e950267aSHenrik Ingo struct uvc_entity *entity; 1943e950267aSHenrik Ingo struct uvc_entity *prev; 1944e950267aSHenrik Ingo 1945e950267aSHenrik Ingo /* 1946e950267aSHenrik Ingo * Start by locating the input and output terminals. We only support 1947e950267aSHenrik Ingo * devices with exactly one of each for now. 1948e950267aSHenrik Ingo */ 1949e950267aSHenrik Ingo list_for_each_entry(entity, &dev->entities, list) { 1950e950267aSHenrik Ingo if (UVC_ENTITY_IS_ITERM(entity)) { 1951e950267aSHenrik Ingo if (iterm) 1952e950267aSHenrik Ingo return -EINVAL; 1953e950267aSHenrik Ingo iterm = entity; 1954e950267aSHenrik Ingo } 1955e950267aSHenrik Ingo 1956e950267aSHenrik Ingo if (UVC_ENTITY_IS_OTERM(entity)) { 1957e950267aSHenrik Ingo if (oterm) 1958e950267aSHenrik Ingo return -EINVAL; 1959e950267aSHenrik Ingo oterm = entity; 1960e950267aSHenrik Ingo } 1961e950267aSHenrik Ingo } 1962e950267aSHenrik Ingo 1963e950267aSHenrik Ingo if (iterm == NULL || oterm == NULL) 1964e950267aSHenrik Ingo return -EINVAL; 1965e950267aSHenrik Ingo 1966e950267aSHenrik Ingo /* Allocate the chain and fill it. */ 1967e950267aSHenrik Ingo chain = uvc_alloc_chain(dev); 1968e950267aSHenrik Ingo if (chain == NULL) 1969e950267aSHenrik Ingo return -ENOMEM; 1970e950267aSHenrik Ingo 1971e950267aSHenrik Ingo if (uvc_scan_chain_entity(chain, oterm) < 0) 1972e950267aSHenrik Ingo goto error; 1973e950267aSHenrik Ingo 1974e950267aSHenrik Ingo prev = oterm; 1975e950267aSHenrik Ingo 1976e950267aSHenrik Ingo /* 1977e950267aSHenrik Ingo * Add all Processing and Extension Units with two pads. The order 1978e950267aSHenrik Ingo * doesn't matter much, use reverse list traversal to connect units in 1979e950267aSHenrik Ingo * UVC descriptor order as we build the chain from output to input. This 1980e950267aSHenrik Ingo * leads to units appearing in the order meant by the manufacturer for 1981e950267aSHenrik Ingo * the cameras known to require this heuristic. 1982e950267aSHenrik Ingo */ 1983e950267aSHenrik Ingo list_for_each_entry_reverse(entity, &dev->entities, list) { 1984e950267aSHenrik Ingo if (entity->type != UVC_VC_PROCESSING_UNIT && 1985e950267aSHenrik Ingo entity->type != UVC_VC_EXTENSION_UNIT) 1986e950267aSHenrik Ingo continue; 1987e950267aSHenrik Ingo 1988e950267aSHenrik Ingo if (entity->num_pads != 2) 1989e950267aSHenrik Ingo continue; 1990e950267aSHenrik Ingo 1991e950267aSHenrik Ingo if (uvc_scan_chain_entity(chain, entity) < 0) 1992e950267aSHenrik Ingo goto error; 1993e950267aSHenrik Ingo 1994e950267aSHenrik Ingo prev->baSourceID[0] = entity->id; 1995e950267aSHenrik Ingo prev = entity; 1996e950267aSHenrik Ingo } 1997e950267aSHenrik Ingo 1998e950267aSHenrik Ingo if (uvc_scan_chain_entity(chain, iterm) < 0) 1999e950267aSHenrik Ingo goto error; 2000e950267aSHenrik Ingo 2001e950267aSHenrik Ingo prev->baSourceID[0] = iterm->id; 2002e950267aSHenrik Ingo 2003e950267aSHenrik Ingo list_add_tail(&chain->list, &dev->chains); 2004e950267aSHenrik Ingo 2005e950267aSHenrik Ingo uvc_trace(UVC_TRACE_PROBE, 2006e950267aSHenrik Ingo "Found a video chain by fallback heuristic (%s).\n", 2007e950267aSHenrik Ingo uvc_print_chain(chain)); 2008e950267aSHenrik Ingo 2009e950267aSHenrik Ingo return 0; 2010e950267aSHenrik Ingo 2011e950267aSHenrik Ingo error: 2012e950267aSHenrik Ingo kfree(chain); 2013e950267aSHenrik Ingo return -EINVAL; 2014e950267aSHenrik Ingo } 2015e950267aSHenrik Ingo 20160c0d06caSMauro Carvalho Chehab /* 20170c0d06caSMauro Carvalho Chehab * Scan the device for video chains and register video devices. 20180c0d06caSMauro Carvalho Chehab * 20190c0d06caSMauro Carvalho Chehab * Chains are scanned starting at their output terminals and walked backwards. 20200c0d06caSMauro Carvalho Chehab */ 20210c0d06caSMauro Carvalho Chehab static int uvc_scan_device(struct uvc_device *dev) 20220c0d06caSMauro Carvalho Chehab { 20230c0d06caSMauro Carvalho Chehab struct uvc_video_chain *chain; 20240c0d06caSMauro Carvalho Chehab struct uvc_entity *term; 20250c0d06caSMauro Carvalho Chehab 20260c0d06caSMauro Carvalho Chehab list_for_each_entry(term, &dev->entities, list) { 20270c0d06caSMauro Carvalho Chehab if (!UVC_ENTITY_IS_OTERM(term)) 20280c0d06caSMauro Carvalho Chehab continue; 20290c0d06caSMauro Carvalho Chehab 20300c0d06caSMauro Carvalho Chehab /* If the terminal is already included in a chain, skip it. 20310c0d06caSMauro Carvalho Chehab * This can happen for chains that have multiple output 20320c0d06caSMauro Carvalho Chehab * terminals, where all output terminals beside the first one 20330c0d06caSMauro Carvalho Chehab * will be inserted in the chain in forward scans. 20340c0d06caSMauro Carvalho Chehab */ 20350c0d06caSMauro Carvalho Chehab if (term->chain.next || term->chain.prev) 20360c0d06caSMauro Carvalho Chehab continue; 20370c0d06caSMauro Carvalho Chehab 2038e950267aSHenrik Ingo chain = uvc_alloc_chain(dev); 20390c0d06caSMauro Carvalho Chehab if (chain == NULL) 20400c0d06caSMauro Carvalho Chehab return -ENOMEM; 20410c0d06caSMauro Carvalho Chehab 20428be8ec6eSLaurent Pinchart term->flags |= UVC_ENTITY_FLAG_DEFAULT; 20438be8ec6eSLaurent Pinchart 20440c0d06caSMauro Carvalho Chehab if (uvc_scan_chain(chain, term) < 0) { 20450c0d06caSMauro Carvalho Chehab kfree(chain); 20460c0d06caSMauro Carvalho Chehab continue; 20470c0d06caSMauro Carvalho Chehab } 20480c0d06caSMauro Carvalho Chehab 20490c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n", 20500c0d06caSMauro Carvalho Chehab uvc_print_chain(chain)); 20510c0d06caSMauro Carvalho Chehab 20520c0d06caSMauro Carvalho Chehab list_add_tail(&chain->list, &dev->chains); 20530c0d06caSMauro Carvalho Chehab } 20540c0d06caSMauro Carvalho Chehab 2055e950267aSHenrik Ingo if (list_empty(&dev->chains)) 2056e950267aSHenrik Ingo uvc_scan_fallback(dev); 2057e950267aSHenrik Ingo 20580c0d06caSMauro Carvalho Chehab if (list_empty(&dev->chains)) { 20590c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "No valid video chain found.\n"); 20600c0d06caSMauro Carvalho Chehab return -1; 20610c0d06caSMauro Carvalho Chehab } 20620c0d06caSMauro Carvalho Chehab 2063*2886477fSRicardo Ribalda /* Add GPIO entity to the first chain. */ 2064*2886477fSRicardo Ribalda if (dev->gpio_unit) { 2065*2886477fSRicardo Ribalda chain = list_first_entry(&dev->chains, 2066*2886477fSRicardo Ribalda struct uvc_video_chain, list); 2067*2886477fSRicardo Ribalda list_add_tail(&dev->gpio_unit->chain, &chain->entities); 2068*2886477fSRicardo Ribalda } 2069*2886477fSRicardo Ribalda 20700c0d06caSMauro Carvalho Chehab return 0; 20710c0d06caSMauro Carvalho Chehab } 20720c0d06caSMauro Carvalho Chehab 20730c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 20740c0d06caSMauro Carvalho Chehab * Video device registration and unregistration 20750c0d06caSMauro Carvalho Chehab */ 20760c0d06caSMauro Carvalho Chehab 20770c0d06caSMauro Carvalho Chehab /* 20780c0d06caSMauro Carvalho Chehab * Delete the UVC device. 20790c0d06caSMauro Carvalho Chehab * 20800c0d06caSMauro Carvalho Chehab * Called by the kernel when the last reference to the uvc_device structure 20810c0d06caSMauro Carvalho Chehab * is released. 20820c0d06caSMauro Carvalho Chehab * 20830c0d06caSMauro Carvalho Chehab * As this function is called after or during disconnect(), all URBs have 2084ece41454SKieran Bingham * already been cancelled by the USB core. There is no need to kill the 20850c0d06caSMauro Carvalho Chehab * interrupt URB manually. 20860c0d06caSMauro Carvalho Chehab */ 20879d15cd95SGuennadi Liakhovetski static void uvc_delete(struct kref *kref) 20880c0d06caSMauro Carvalho Chehab { 20899d15cd95SGuennadi Liakhovetski struct uvc_device *dev = container_of(kref, struct uvc_device, ref); 20900c0d06caSMauro Carvalho Chehab struct list_head *p, *n; 20910c0d06caSMauro Carvalho Chehab 20920c0d06caSMauro Carvalho Chehab uvc_status_cleanup(dev); 20930c0d06caSMauro Carvalho Chehab uvc_ctrl_cleanup_device(dev); 20940c0d06caSMauro Carvalho Chehab 20952228d80dSTakashi Iwai usb_put_intf(dev->intf); 20962228d80dSTakashi Iwai usb_put_dev(dev->udev); 20972228d80dSTakashi Iwai 20980c0d06caSMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER 20999832e155SJavier Martinez Canillas media_device_cleanup(&dev->mdev); 21000c0d06caSMauro Carvalho Chehab #endif 21010c0d06caSMauro Carvalho Chehab 21020c0d06caSMauro Carvalho Chehab list_for_each_safe(p, n, &dev->chains) { 21030c0d06caSMauro Carvalho Chehab struct uvc_video_chain *chain; 21040c0d06caSMauro Carvalho Chehab chain = list_entry(p, struct uvc_video_chain, list); 21050c0d06caSMauro Carvalho Chehab kfree(chain); 21060c0d06caSMauro Carvalho Chehab } 21070c0d06caSMauro Carvalho Chehab 21080c0d06caSMauro Carvalho Chehab list_for_each_safe(p, n, &dev->entities) { 21090c0d06caSMauro Carvalho Chehab struct uvc_entity *entity; 21100c0d06caSMauro Carvalho Chehab entity = list_entry(p, struct uvc_entity, list); 21110c0d06caSMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER 21120c0d06caSMauro Carvalho Chehab uvc_mc_cleanup_entity(entity); 21130c0d06caSMauro Carvalho Chehab #endif 21140c0d06caSMauro Carvalho Chehab kfree(entity); 21150c0d06caSMauro Carvalho Chehab } 21160c0d06caSMauro Carvalho Chehab 21170c0d06caSMauro Carvalho Chehab list_for_each_safe(p, n, &dev->streams) { 21180c0d06caSMauro Carvalho Chehab struct uvc_streaming *streaming; 21190c0d06caSMauro Carvalho Chehab streaming = list_entry(p, struct uvc_streaming, list); 21200c0d06caSMauro Carvalho Chehab usb_driver_release_interface(&uvc_driver.driver, 21210c0d06caSMauro Carvalho Chehab streaming->intf); 2122ece41454SKieran Bingham uvc_stream_delete(streaming); 21230c0d06caSMauro Carvalho Chehab } 21240c0d06caSMauro Carvalho Chehab 21250c0d06caSMauro Carvalho Chehab kfree(dev); 21260c0d06caSMauro Carvalho Chehab } 21270c0d06caSMauro Carvalho Chehab 21280c0d06caSMauro Carvalho Chehab static void uvc_release(struct video_device *vdev) 21290c0d06caSMauro Carvalho Chehab { 21300c0d06caSMauro Carvalho Chehab struct uvc_streaming *stream = video_get_drvdata(vdev); 21310c0d06caSMauro Carvalho Chehab struct uvc_device *dev = stream->dev; 21320c0d06caSMauro Carvalho Chehab 21339d15cd95SGuennadi Liakhovetski kref_put(&dev->ref, uvc_delete); 21340c0d06caSMauro Carvalho Chehab } 21350c0d06caSMauro Carvalho Chehab 21360c0d06caSMauro Carvalho Chehab /* 21370c0d06caSMauro Carvalho Chehab * Unregister the video devices. 21380c0d06caSMauro Carvalho Chehab */ 21390c0d06caSMauro Carvalho Chehab static void uvc_unregister_video(struct uvc_device *dev) 21400c0d06caSMauro Carvalho Chehab { 21410c0d06caSMauro Carvalho Chehab struct uvc_streaming *stream; 21420c0d06caSMauro Carvalho Chehab 21430c0d06caSMauro Carvalho Chehab list_for_each_entry(stream, &dev->streams, list) { 2144d8da7513SHans Verkuil if (!video_is_registered(&stream->vdev)) 21450c0d06caSMauro Carvalho Chehab continue; 21460c0d06caSMauro Carvalho Chehab 2147d8da7513SHans Verkuil video_unregister_device(&stream->vdev); 2148088ead25SGuennadi Liakhovetski video_unregister_device(&stream->meta.vdev); 21490c0d06caSMauro Carvalho Chehab 21500c0d06caSMauro Carvalho Chehab uvc_debugfs_cleanup_stream(stream); 21510c0d06caSMauro Carvalho Chehab } 215210e1fdb9SDaniel Axtens 215310e1fdb9SDaniel Axtens uvc_status_unregister(dev); 215410e1fdb9SDaniel Axtens 215510e1fdb9SDaniel Axtens if (dev->vdev.dev) 215610e1fdb9SDaniel Axtens v4l2_device_unregister(&dev->vdev); 215710e1fdb9SDaniel Axtens #ifdef CONFIG_MEDIA_CONTROLLER 215810e1fdb9SDaniel Axtens if (media_devnode_is_registered(dev->mdev.devnode)) 215910e1fdb9SDaniel Axtens media_device_unregister(&dev->mdev); 216010e1fdb9SDaniel Axtens #endif 21610c0d06caSMauro Carvalho Chehab } 21620c0d06caSMauro Carvalho Chehab 216331a96f4cSLaurent Pinchart int uvc_register_video_device(struct uvc_device *dev, 216431a96f4cSLaurent Pinchart struct uvc_streaming *stream, 216531a96f4cSLaurent Pinchart struct video_device *vdev, 216631a96f4cSLaurent Pinchart struct uvc_video_queue *queue, 216731a96f4cSLaurent Pinchart enum v4l2_buf_type type, 216831a96f4cSLaurent Pinchart const struct v4l2_file_operations *fops, 216931a96f4cSLaurent Pinchart const struct v4l2_ioctl_ops *ioctl_ops) 21700c0d06caSMauro Carvalho Chehab { 21710c0d06caSMauro Carvalho Chehab int ret; 21720c0d06caSMauro Carvalho Chehab 2173b83bba24SLaurent Pinchart /* Initialize the video buffers queue. */ 217431a96f4cSLaurent Pinchart ret = uvc_queue_init(queue, type, !uvc_no_drop_param); 2175b83bba24SLaurent Pinchart if (ret) 2176b83bba24SLaurent Pinchart return ret; 2177b83bba24SLaurent Pinchart 21780c0d06caSMauro Carvalho Chehab /* Register the device with V4L. */ 21790c0d06caSMauro Carvalho Chehab 218031a96f4cSLaurent Pinchart /* 218131a96f4cSLaurent Pinchart * We already hold a reference to dev->udev. The video device will be 21820c0d06caSMauro Carvalho Chehab * unregistered before the reference is released, so we don't need to 21830c0d06caSMauro Carvalho Chehab * get another one. 21840c0d06caSMauro Carvalho Chehab */ 21850c0d06caSMauro Carvalho Chehab vdev->v4l2_dev = &dev->vdev; 218631a96f4cSLaurent Pinchart vdev->fops = fops; 218731a96f4cSLaurent Pinchart vdev->ioctl_ops = ioctl_ops; 21880c0d06caSMauro Carvalho Chehab vdev->release = uvc_release; 21890550513cSLaurent Pinchart vdev->prio = &stream->chain->prio; 219031a96f4cSLaurent Pinchart if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT) 2191954f340fSHans Verkuil vdev->vfl_dir = VFL_DIR_TX; 219231a96f4cSLaurent Pinchart else 219331a96f4cSLaurent Pinchart vdev->vfl_dir = VFL_DIR_RX; 219494c53e26SLaurent Pinchart 219594c53e26SLaurent Pinchart switch (type) { 219694c53e26SLaurent Pinchart case V4L2_BUF_TYPE_VIDEO_CAPTURE: 219794c53e26SLaurent Pinchart default: 219894c53e26SLaurent Pinchart vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 219994c53e26SLaurent Pinchart break; 220094c53e26SLaurent Pinchart case V4L2_BUF_TYPE_VIDEO_OUTPUT: 220194c53e26SLaurent Pinchart vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 220294c53e26SLaurent Pinchart break; 2203088ead25SGuennadi Liakhovetski case V4L2_BUF_TYPE_META_CAPTURE: 2204088ead25SGuennadi Liakhovetski vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING; 2205088ead25SGuennadi Liakhovetski break; 220694c53e26SLaurent Pinchart } 220794c53e26SLaurent Pinchart 2208c0decac1SMauro Carvalho Chehab strscpy(vdev->name, dev->name, sizeof(vdev->name)); 22090c0d06caSMauro Carvalho Chehab 221031a96f4cSLaurent Pinchart /* 221131a96f4cSLaurent Pinchart * Set the driver data before calling video_register_device, otherwise 221231a96f4cSLaurent Pinchart * the file open() handler might race us. 22130c0d06caSMauro Carvalho Chehab */ 22140c0d06caSMauro Carvalho Chehab video_set_drvdata(vdev, stream); 22150c0d06caSMauro Carvalho Chehab 22167fbbbc78SHans Verkuil ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); 22170c0d06caSMauro Carvalho Chehab if (ret < 0) { 221831a96f4cSLaurent Pinchart uvc_printk(KERN_ERR, "Failed to register %s device (%d).\n", 221931a96f4cSLaurent Pinchart v4l2_type_names[type], ret); 222031a96f4cSLaurent Pinchart return ret; 222131a96f4cSLaurent Pinchart } 222231a96f4cSLaurent Pinchart 222331a96f4cSLaurent Pinchart kref_get(&dev->ref); 222431a96f4cSLaurent Pinchart return 0; 222531a96f4cSLaurent Pinchart } 222631a96f4cSLaurent Pinchart 222731a96f4cSLaurent Pinchart static int uvc_register_video(struct uvc_device *dev, 222831a96f4cSLaurent Pinchart struct uvc_streaming *stream) 222931a96f4cSLaurent Pinchart { 223031a96f4cSLaurent Pinchart int ret; 223131a96f4cSLaurent Pinchart 223231a96f4cSLaurent Pinchart /* Initialize the streaming interface with default parameters. */ 223331a96f4cSLaurent Pinchart ret = uvc_video_init(stream); 223431a96f4cSLaurent Pinchart if (ret < 0) { 223531a96f4cSLaurent Pinchart uvc_printk(KERN_ERR, "Failed to initialize the device (%d).\n", 22360c0d06caSMauro Carvalho Chehab ret); 22370c0d06caSMauro Carvalho Chehab return ret; 22380c0d06caSMauro Carvalho Chehab } 22390c0d06caSMauro Carvalho Chehab 2240f887e99aSLaurent Pinchart if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 2241088ead25SGuennadi Liakhovetski stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE 2242088ead25SGuennadi Liakhovetski | V4L2_CAP_META_CAPTURE; 2243f887e99aSLaurent Pinchart else 2244f887e99aSLaurent Pinchart stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT; 2245f887e99aSLaurent Pinchart 224631a96f4cSLaurent Pinchart uvc_debugfs_init_stream(stream); 224731a96f4cSLaurent Pinchart 224831a96f4cSLaurent Pinchart /* Register the device with V4L. */ 224931a96f4cSLaurent Pinchart return uvc_register_video_device(dev, stream, &stream->vdev, 225031a96f4cSLaurent Pinchart &stream->queue, stream->type, 225131a96f4cSLaurent Pinchart &uvc_fops, &uvc_ioctl_ops); 22520c0d06caSMauro Carvalho Chehab } 22530c0d06caSMauro Carvalho Chehab 22540c0d06caSMauro Carvalho Chehab /* 22550c0d06caSMauro Carvalho Chehab * Register all video devices in all chains. 22560c0d06caSMauro Carvalho Chehab */ 22570c0d06caSMauro Carvalho Chehab static int uvc_register_terms(struct uvc_device *dev, 22580c0d06caSMauro Carvalho Chehab struct uvc_video_chain *chain) 22590c0d06caSMauro Carvalho Chehab { 22600c0d06caSMauro Carvalho Chehab struct uvc_streaming *stream; 22610c0d06caSMauro Carvalho Chehab struct uvc_entity *term; 22620c0d06caSMauro Carvalho Chehab int ret; 22630c0d06caSMauro Carvalho Chehab 22640c0d06caSMauro Carvalho Chehab list_for_each_entry(term, &chain->entities, chain) { 22650c0d06caSMauro Carvalho Chehab if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING) 22660c0d06caSMauro Carvalho Chehab continue; 22670c0d06caSMauro Carvalho Chehab 22680c0d06caSMauro Carvalho Chehab stream = uvc_stream_by_id(dev, term->id); 22690c0d06caSMauro Carvalho Chehab if (stream == NULL) { 22700c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "No streaming interface found " 22710c0d06caSMauro Carvalho Chehab "for terminal %u.", term->id); 22720c0d06caSMauro Carvalho Chehab continue; 22730c0d06caSMauro Carvalho Chehab } 22740c0d06caSMauro Carvalho Chehab 22750c0d06caSMauro Carvalho Chehab stream->chain = chain; 22760c0d06caSMauro Carvalho Chehab ret = uvc_register_video(dev, stream); 22770c0d06caSMauro Carvalho Chehab if (ret < 0) 22780c0d06caSMauro Carvalho Chehab return ret; 22790c0d06caSMauro Carvalho Chehab 2280088ead25SGuennadi Liakhovetski /* Register a metadata node, but ignore a possible failure, 2281088ead25SGuennadi Liakhovetski * complete registration of video nodes anyway. 2282088ead25SGuennadi Liakhovetski */ 2283088ead25SGuennadi Liakhovetski uvc_meta_register(stream); 2284088ead25SGuennadi Liakhovetski 2285d8da7513SHans Verkuil term->vdev = &stream->vdev; 22860c0d06caSMauro Carvalho Chehab } 22870c0d06caSMauro Carvalho Chehab 22880c0d06caSMauro Carvalho Chehab return 0; 22890c0d06caSMauro Carvalho Chehab } 22900c0d06caSMauro Carvalho Chehab 22910c0d06caSMauro Carvalho Chehab static int uvc_register_chains(struct uvc_device *dev) 22920c0d06caSMauro Carvalho Chehab { 22930c0d06caSMauro Carvalho Chehab struct uvc_video_chain *chain; 22940c0d06caSMauro Carvalho Chehab int ret; 22950c0d06caSMauro Carvalho Chehab 22960c0d06caSMauro Carvalho Chehab list_for_each_entry(chain, &dev->chains, list) { 22970c0d06caSMauro Carvalho Chehab ret = uvc_register_terms(dev, chain); 22980c0d06caSMauro Carvalho Chehab if (ret < 0) 22990c0d06caSMauro Carvalho Chehab return ret; 23000c0d06caSMauro Carvalho Chehab 23010c0d06caSMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER 23020c0d06caSMauro Carvalho Chehab ret = uvc_mc_register_entities(chain); 23036689df06SColin Ian King if (ret < 0) 23046689df06SColin Ian King uvc_printk(KERN_INFO, 23056689df06SColin Ian King "Failed to register entities (%d).\n", ret); 23060c0d06caSMauro Carvalho Chehab #endif 23070c0d06caSMauro Carvalho Chehab } 23080c0d06caSMauro Carvalho Chehab 23090c0d06caSMauro Carvalho Chehab return 0; 23100c0d06caSMauro Carvalho Chehab } 23110c0d06caSMauro Carvalho Chehab 23120c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 23130c0d06caSMauro Carvalho Chehab * USB probe, disconnect, suspend and resume 23140c0d06caSMauro Carvalho Chehab */ 23150c0d06caSMauro Carvalho Chehab 23163a03284dSLaurent Pinchart static const struct uvc_device_info uvc_quirk_none = { 0 }; 23173bc85817SGuennadi Liakhovetski 23180c0d06caSMauro Carvalho Chehab static int uvc_probe(struct usb_interface *intf, 23190c0d06caSMauro Carvalho Chehab const struct usb_device_id *id) 23200c0d06caSMauro Carvalho Chehab { 23210c0d06caSMauro Carvalho Chehab struct usb_device *udev = interface_to_usbdev(intf); 23220c0d06caSMauro Carvalho Chehab struct uvc_device *dev; 23233bc85817SGuennadi Liakhovetski const struct uvc_device_info *info = 23243bc85817SGuennadi Liakhovetski (const struct uvc_device_info *)id->driver_info; 2325e7b09f18SPeter Boström int function; 23260c0d06caSMauro Carvalho Chehab int ret; 23270c0d06caSMauro Carvalho Chehab 23280c0d06caSMauro Carvalho Chehab if (id->idVendor && id->idProduct) 23290c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s " 23300c0d06caSMauro Carvalho Chehab "(%04x:%04x)\n", udev->devpath, id->idVendor, 23310c0d06caSMauro Carvalho Chehab id->idProduct); 23320c0d06caSMauro Carvalho Chehab else 23330c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n", 23340c0d06caSMauro Carvalho Chehab udev->devpath); 23350c0d06caSMauro Carvalho Chehab 23360c0d06caSMauro Carvalho Chehab /* Allocate memory for the device and initialize it. */ 2337f14d4988SLaurent Pinchart dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2338f14d4988SLaurent Pinchart if (dev == NULL) 23390c0d06caSMauro Carvalho Chehab return -ENOMEM; 23400c0d06caSMauro Carvalho Chehab 23410c0d06caSMauro Carvalho Chehab INIT_LIST_HEAD(&dev->entities); 23420c0d06caSMauro Carvalho Chehab INIT_LIST_HEAD(&dev->chains); 23430c0d06caSMauro Carvalho Chehab INIT_LIST_HEAD(&dev->streams); 23449d15cd95SGuennadi Liakhovetski kref_init(&dev->ref); 23450c0d06caSMauro Carvalho Chehab atomic_set(&dev->nmappings, 0); 234617706f56SLaurent Pinchart mutex_init(&dev->lock); 23470c0d06caSMauro Carvalho Chehab 23480c0d06caSMauro Carvalho Chehab dev->udev = usb_get_dev(udev); 23490c0d06caSMauro Carvalho Chehab dev->intf = usb_get_intf(intf); 23500c0d06caSMauro Carvalho Chehab dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; 23513a03284dSLaurent Pinchart dev->info = info ? info : &uvc_quirk_none; 23523a03284dSLaurent Pinchart dev->quirks = uvc_quirks_param == -1 23533a03284dSLaurent Pinchart ? dev->info->quirks : uvc_quirks_param; 23540c0d06caSMauro Carvalho Chehab 23550c0d06caSMauro Carvalho Chehab if (udev->product != NULL) 2356c0decac1SMauro Carvalho Chehab strscpy(dev->name, udev->product, sizeof(dev->name)); 23570c0d06caSMauro Carvalho Chehab else 2358f14d4988SLaurent Pinchart snprintf(dev->name, sizeof(dev->name), 23590c0d06caSMauro Carvalho Chehab "UVC Camera (%04x:%04x)", 23600c0d06caSMauro Carvalho Chehab le16_to_cpu(udev->descriptor.idVendor), 23610c0d06caSMauro Carvalho Chehab le16_to_cpu(udev->descriptor.idProduct)); 23620c0d06caSMauro Carvalho Chehab 2363e7b09f18SPeter Boström /* 2364e7b09f18SPeter Boström * Add iFunction or iInterface to names when available as additional 2365e7b09f18SPeter Boström * distinguishers between interfaces. iFunction is prioritized over 2366e7b09f18SPeter Boström * iInterface which matches Windows behavior at the point of writing. 2367e7b09f18SPeter Boström */ 2368e7b09f18SPeter Boström if (intf->intf_assoc && intf->intf_assoc->iFunction != 0) 2369e7b09f18SPeter Boström function = intf->intf_assoc->iFunction; 2370e7b09f18SPeter Boström else 2371e7b09f18SPeter Boström function = intf->cur_altsetting->desc.iInterface; 2372e7b09f18SPeter Boström if (function != 0) { 2373e7b09f18SPeter Boström size_t len; 2374e7b09f18SPeter Boström 2375e7b09f18SPeter Boström strlcat(dev->name, ": ", sizeof(dev->name)); 2376e7b09f18SPeter Boström len = strlen(dev->name); 2377e7b09f18SPeter Boström usb_string(udev, function, dev->name + len, 2378e7b09f18SPeter Boström sizeof(dev->name) - len); 2379e7b09f18SPeter Boström } 2380e7b09f18SPeter Boström 23818c279e93SLaurent Pinchart /* Initialize the media device. */ 23828c279e93SLaurent Pinchart #ifdef CONFIG_MEDIA_CONTROLLER 23838c279e93SLaurent Pinchart dev->mdev.dev = &intf->dev; 23848c279e93SLaurent Pinchart strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model)); 23858c279e93SLaurent Pinchart if (udev->serial) 23868c279e93SLaurent Pinchart strscpy(dev->mdev.serial, udev->serial, 23878c279e93SLaurent Pinchart sizeof(dev->mdev.serial)); 23888c279e93SLaurent Pinchart usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info)); 23898c279e93SLaurent Pinchart dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice); 23908c279e93SLaurent Pinchart media_device_init(&dev->mdev); 23918c279e93SLaurent Pinchart 23928c279e93SLaurent Pinchart dev->vdev.mdev = &dev->mdev; 23938c279e93SLaurent Pinchart #endif 23948c279e93SLaurent Pinchart 23950c0d06caSMauro Carvalho Chehab /* Parse the Video Class control descriptor. */ 23960c0d06caSMauro Carvalho Chehab if (uvc_parse_control(dev) < 0) { 23970c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC " 23980c0d06caSMauro Carvalho Chehab "descriptors.\n"); 23990c0d06caSMauro Carvalho Chehab goto error; 24000c0d06caSMauro Carvalho Chehab } 24010c0d06caSMauro Carvalho Chehab 2402*2886477fSRicardo Ribalda /* Parse the associated GPIOs. */ 2403*2886477fSRicardo Ribalda if (uvc_gpio_parse(dev) < 0) { 2404*2886477fSRicardo Ribalda uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC GPIOs\n"); 2405*2886477fSRicardo Ribalda goto error; 2406*2886477fSRicardo Ribalda } 2407*2886477fSRicardo Ribalda 24080c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n", 24090c0d06caSMauro Carvalho Chehab dev->uvc_version >> 8, dev->uvc_version & 0xff, 24100c0d06caSMauro Carvalho Chehab udev->product ? udev->product : "<unnamed>", 24110c0d06caSMauro Carvalho Chehab le16_to_cpu(udev->descriptor.idVendor), 24120c0d06caSMauro Carvalho Chehab le16_to_cpu(udev->descriptor.idProduct)); 24130c0d06caSMauro Carvalho Chehab 24143a03284dSLaurent Pinchart if (dev->quirks != dev->info->quirks) { 24150c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module " 24160c0d06caSMauro Carvalho Chehab "parameter for testing purpose.\n", dev->quirks); 24170c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "Please report required quirks to the " 24180c0d06caSMauro Carvalho Chehab "linux-uvc-devel mailing list.\n"); 24190c0d06caSMauro Carvalho Chehab } 24200c0d06caSMauro Carvalho Chehab 2421b400b6f2SLaurent Pinchart if (dev->info->uvc_version) { 2422b400b6f2SLaurent Pinchart dev->uvc_version = dev->info->uvc_version; 2423b400b6f2SLaurent Pinchart uvc_printk(KERN_INFO, "Forcing UVC version to %u.%02x\n", 2424b400b6f2SLaurent Pinchart dev->uvc_version >> 8, dev->uvc_version & 0xff); 2425b400b6f2SLaurent Pinchart } 2426b400b6f2SLaurent Pinchart 24278c279e93SLaurent Pinchart /* Register the V4L2 device. */ 24280c0d06caSMauro Carvalho Chehab if (v4l2_device_register(&intf->dev, &dev->vdev) < 0) 24290c0d06caSMauro Carvalho Chehab goto error; 24300c0d06caSMauro Carvalho Chehab 24310c0d06caSMauro Carvalho Chehab /* Initialize controls. */ 24320c0d06caSMauro Carvalho Chehab if (uvc_ctrl_init_device(dev) < 0) 24330c0d06caSMauro Carvalho Chehab goto error; 24340c0d06caSMauro Carvalho Chehab 24350c0d06caSMauro Carvalho Chehab /* Scan the device for video chains. */ 24360c0d06caSMauro Carvalho Chehab if (uvc_scan_device(dev) < 0) 24370c0d06caSMauro Carvalho Chehab goto error; 24380c0d06caSMauro Carvalho Chehab 24390c0d06caSMauro Carvalho Chehab /* Register video device nodes. */ 24400c0d06caSMauro Carvalho Chehab if (uvc_register_chains(dev) < 0) 24410c0d06caSMauro Carvalho Chehab goto error; 24420c0d06caSMauro Carvalho Chehab 24439832e155SJavier Martinez Canillas #ifdef CONFIG_MEDIA_CONTROLLER 24449832e155SJavier Martinez Canillas /* Register the media device node */ 24459832e155SJavier Martinez Canillas if (media_device_register(&dev->mdev) < 0) 24469832e155SJavier Martinez Canillas goto error; 24479832e155SJavier Martinez Canillas #endif 24480c0d06caSMauro Carvalho Chehab /* Save our data pointer in the interface data. */ 24490c0d06caSMauro Carvalho Chehab usb_set_intfdata(intf, dev); 24500c0d06caSMauro Carvalho Chehab 24510c0d06caSMauro Carvalho Chehab /* Initialize the interrupt URB. */ 24520c0d06caSMauro Carvalho Chehab if ((ret = uvc_status_init(dev)) < 0) { 24530c0d06caSMauro Carvalho Chehab uvc_printk(KERN_INFO, "Unable to initialize the status " 24540c0d06caSMauro Carvalho Chehab "endpoint (%d), status interrupt will not be " 24550c0d06caSMauro Carvalho Chehab "supported.\n", ret); 24560c0d06caSMauro Carvalho Chehab } 24570c0d06caSMauro Carvalho Chehab 2458*2886477fSRicardo Ribalda ret = uvc_gpio_init_irq(dev); 2459*2886477fSRicardo Ribalda if (ret < 0) { 2460*2886477fSRicardo Ribalda dev_err(&dev->udev->dev, 2461*2886477fSRicardo Ribalda "Unable to request privacy GPIO IRQ (%d)\n", ret); 2462*2886477fSRicardo Ribalda goto error; 2463*2886477fSRicardo Ribalda } 2464*2886477fSRicardo Ribalda 24650c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n"); 24660c0d06caSMauro Carvalho Chehab usb_enable_autosuspend(udev); 24670c0d06caSMauro Carvalho Chehab return 0; 24680c0d06caSMauro Carvalho Chehab 24690c0d06caSMauro Carvalho Chehab error: 24700c0d06caSMauro Carvalho Chehab uvc_unregister_video(dev); 2471f9ffcb0aSPhilipp Zabel kref_put(&dev->ref, uvc_delete); 24720c0d06caSMauro Carvalho Chehab return -ENODEV; 24730c0d06caSMauro Carvalho Chehab } 24740c0d06caSMauro Carvalho Chehab 24750c0d06caSMauro Carvalho Chehab static void uvc_disconnect(struct usb_interface *intf) 24760c0d06caSMauro Carvalho Chehab { 24770c0d06caSMauro Carvalho Chehab struct uvc_device *dev = usb_get_intfdata(intf); 24780c0d06caSMauro Carvalho Chehab 24790c0d06caSMauro Carvalho Chehab /* Set the USB interface data to NULL. This can be done outside the 24800c0d06caSMauro Carvalho Chehab * lock, as there's no other reader. 24810c0d06caSMauro Carvalho Chehab */ 24820c0d06caSMauro Carvalho Chehab usb_set_intfdata(intf, NULL); 24830c0d06caSMauro Carvalho Chehab 24840c0d06caSMauro Carvalho Chehab if (intf->cur_altsetting->desc.bInterfaceSubClass == 24850c0d06caSMauro Carvalho Chehab UVC_SC_VIDEOSTREAMING) 24860c0d06caSMauro Carvalho Chehab return; 24870c0d06caSMauro Carvalho Chehab 24880c0d06caSMauro Carvalho Chehab uvc_unregister_video(dev); 2489f9ffcb0aSPhilipp Zabel kref_put(&dev->ref, uvc_delete); 24900c0d06caSMauro Carvalho Chehab } 24910c0d06caSMauro Carvalho Chehab 24920c0d06caSMauro Carvalho Chehab static int uvc_suspend(struct usb_interface *intf, pm_message_t message) 24930c0d06caSMauro Carvalho Chehab { 24940c0d06caSMauro Carvalho Chehab struct uvc_device *dev = usb_get_intfdata(intf); 24950c0d06caSMauro Carvalho Chehab struct uvc_streaming *stream; 24960c0d06caSMauro Carvalho Chehab 24970c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n", 24980c0d06caSMauro Carvalho Chehab intf->cur_altsetting->desc.bInterfaceNumber); 24990c0d06caSMauro Carvalho Chehab 25000c0d06caSMauro Carvalho Chehab /* Controls are cached on the fly so they don't need to be saved. */ 25010c0d06caSMauro Carvalho Chehab if (intf->cur_altsetting->desc.bInterfaceSubClass == 250217706f56SLaurent Pinchart UVC_SC_VIDEOCONTROL) { 250317706f56SLaurent Pinchart mutex_lock(&dev->lock); 250417706f56SLaurent Pinchart if (dev->users) 250517706f56SLaurent Pinchart uvc_status_stop(dev); 250617706f56SLaurent Pinchart mutex_unlock(&dev->lock); 250717706f56SLaurent Pinchart return 0; 250817706f56SLaurent Pinchart } 25090c0d06caSMauro Carvalho Chehab 25100c0d06caSMauro Carvalho Chehab list_for_each_entry(stream, &dev->streams, list) { 25110c0d06caSMauro Carvalho Chehab if (stream->intf == intf) 25120c0d06caSMauro Carvalho Chehab return uvc_video_suspend(stream); 25130c0d06caSMauro Carvalho Chehab } 25140c0d06caSMauro Carvalho Chehab 25150c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface " 25160c0d06caSMauro Carvalho Chehab "mismatch.\n"); 25170c0d06caSMauro Carvalho Chehab return -EINVAL; 25180c0d06caSMauro Carvalho Chehab } 25190c0d06caSMauro Carvalho Chehab 25200c0d06caSMauro Carvalho Chehab static int __uvc_resume(struct usb_interface *intf, int reset) 25210c0d06caSMauro Carvalho Chehab { 25220c0d06caSMauro Carvalho Chehab struct uvc_device *dev = usb_get_intfdata(intf); 25230c0d06caSMauro Carvalho Chehab struct uvc_streaming *stream; 2524b83bba24SLaurent Pinchart int ret = 0; 25250c0d06caSMauro Carvalho Chehab 25260c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n", 25270c0d06caSMauro Carvalho Chehab intf->cur_altsetting->desc.bInterfaceNumber); 25280c0d06caSMauro Carvalho Chehab 25290c0d06caSMauro Carvalho Chehab if (intf->cur_altsetting->desc.bInterfaceSubClass == 25300c0d06caSMauro Carvalho Chehab UVC_SC_VIDEOCONTROL) { 253117706f56SLaurent Pinchart if (reset) { 253217e1319fSWilliam Manley ret = uvc_ctrl_restore_values(dev); 25330c0d06caSMauro Carvalho Chehab if (ret < 0) 25340c0d06caSMauro Carvalho Chehab return ret; 25350c0d06caSMauro Carvalho Chehab } 25360c0d06caSMauro Carvalho Chehab 253717706f56SLaurent Pinchart mutex_lock(&dev->lock); 253817706f56SLaurent Pinchart if (dev->users) 253917706f56SLaurent Pinchart ret = uvc_status_start(dev, GFP_NOIO); 254017706f56SLaurent Pinchart mutex_unlock(&dev->lock); 254117706f56SLaurent Pinchart 254217706f56SLaurent Pinchart return ret; 25430c0d06caSMauro Carvalho Chehab } 25440c0d06caSMauro Carvalho Chehab 25450c0d06caSMauro Carvalho Chehab list_for_each_entry(stream, &dev->streams, list) { 2546b83bba24SLaurent Pinchart if (stream->intf == intf) { 2547b83bba24SLaurent Pinchart ret = uvc_video_resume(stream, reset); 2548b83bba24SLaurent Pinchart if (ret < 0) 25490da4ab98SLaurent Pinchart uvc_queue_streamoff(&stream->queue, 25500da4ab98SLaurent Pinchart stream->queue.queue.type); 2551b83bba24SLaurent Pinchart return ret; 2552b83bba24SLaurent Pinchart } 25530c0d06caSMauro Carvalho Chehab } 25540c0d06caSMauro Carvalho Chehab 25550c0d06caSMauro Carvalho Chehab uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface " 25560c0d06caSMauro Carvalho Chehab "mismatch.\n"); 25570c0d06caSMauro Carvalho Chehab return -EINVAL; 25580c0d06caSMauro Carvalho Chehab } 25590c0d06caSMauro Carvalho Chehab 25600c0d06caSMauro Carvalho Chehab static int uvc_resume(struct usb_interface *intf) 25610c0d06caSMauro Carvalho Chehab { 25620c0d06caSMauro Carvalho Chehab return __uvc_resume(intf, 0); 25630c0d06caSMauro Carvalho Chehab } 25640c0d06caSMauro Carvalho Chehab 25650c0d06caSMauro Carvalho Chehab static int uvc_reset_resume(struct usb_interface *intf) 25660c0d06caSMauro Carvalho Chehab { 25670c0d06caSMauro Carvalho Chehab return __uvc_resume(intf, 1); 25680c0d06caSMauro Carvalho Chehab } 25690c0d06caSMauro Carvalho Chehab 25700c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 25710c0d06caSMauro Carvalho Chehab * Module parameters 25720c0d06caSMauro Carvalho Chehab */ 25730c0d06caSMauro Carvalho Chehab 2574e4dca7b7SKees Cook static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp) 25750c0d06caSMauro Carvalho Chehab { 25760c0d06caSMauro Carvalho Chehab if (uvc_clock_param == CLOCK_MONOTONIC) 25770c0d06caSMauro Carvalho Chehab return sprintf(buffer, "CLOCK_MONOTONIC"); 25780c0d06caSMauro Carvalho Chehab else 25790c0d06caSMauro Carvalho Chehab return sprintf(buffer, "CLOCK_REALTIME"); 25800c0d06caSMauro Carvalho Chehab } 25810c0d06caSMauro Carvalho Chehab 2582e4dca7b7SKees Cook static int uvc_clock_param_set(const char *val, const struct kernel_param *kp) 25830c0d06caSMauro Carvalho Chehab { 25840c0d06caSMauro Carvalho Chehab if (strncasecmp(val, "clock_", strlen("clock_")) == 0) 25850c0d06caSMauro Carvalho Chehab val += strlen("clock_"); 25860c0d06caSMauro Carvalho Chehab 25870c0d06caSMauro Carvalho Chehab if (strcasecmp(val, "monotonic") == 0) 25880c0d06caSMauro Carvalho Chehab uvc_clock_param = CLOCK_MONOTONIC; 25890c0d06caSMauro Carvalho Chehab else if (strcasecmp(val, "realtime") == 0) 25900c0d06caSMauro Carvalho Chehab uvc_clock_param = CLOCK_REALTIME; 25910c0d06caSMauro Carvalho Chehab else 25920c0d06caSMauro Carvalho Chehab return -EINVAL; 25930c0d06caSMauro Carvalho Chehab 25940c0d06caSMauro Carvalho Chehab return 0; 25950c0d06caSMauro Carvalho Chehab } 25960c0d06caSMauro Carvalho Chehab 25970c0d06caSMauro Carvalho Chehab module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get, 25980c0d06caSMauro Carvalho Chehab &uvc_clock_param, S_IRUGO|S_IWUSR); 25990c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(clock, "Video buffers timestamp clock"); 26005d0fd3c8SLaurent Pinchart module_param_named(hwtimestamps, uvc_hw_timestamps_param, uint, S_IRUGO|S_IWUSR); 26015d0fd3c8SLaurent Pinchart MODULE_PARM_DESC(hwtimestamps, "Use hardware timestamps"); 26020c0d06caSMauro Carvalho Chehab module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR); 26030c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames"); 26040c0d06caSMauro Carvalho Chehab module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR); 26050c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(quirks, "Forced device quirks"); 26060c0d06caSMauro Carvalho Chehab module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR); 26070c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(trace, "Trace level bitmask"); 26080c0d06caSMauro Carvalho Chehab module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR); 26090c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(timeout, "Streaming control requests timeout"); 26100c0d06caSMauro Carvalho Chehab 26110c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------------ 26120c0d06caSMauro Carvalho Chehab * Driver initialization and cleanup 26130c0d06caSMauro Carvalho Chehab */ 26140c0d06caSMauro Carvalho Chehab 26153bc85817SGuennadi Liakhovetski static const struct uvc_device_info uvc_quirk_probe_minmax = { 26163bc85817SGuennadi Liakhovetski .quirks = UVC_QUIRK_PROBE_MINMAX, 26173bc85817SGuennadi Liakhovetski }; 26183bc85817SGuennadi Liakhovetski 26193bc85817SGuennadi Liakhovetski static const struct uvc_device_info uvc_quirk_fix_bandwidth = { 26203bc85817SGuennadi Liakhovetski .quirks = UVC_QUIRK_FIX_BANDWIDTH, 26213bc85817SGuennadi Liakhovetski }; 26223bc85817SGuennadi Liakhovetski 26233bc85817SGuennadi Liakhovetski static const struct uvc_device_info uvc_quirk_probe_def = { 26243bc85817SGuennadi Liakhovetski .quirks = UVC_QUIRK_PROBE_DEF, 26253bc85817SGuennadi Liakhovetski }; 26263bc85817SGuennadi Liakhovetski 26273bc85817SGuennadi Liakhovetski static const struct uvc_device_info uvc_quirk_stream_no_fid = { 26283bc85817SGuennadi Liakhovetski .quirks = UVC_QUIRK_STREAM_NO_FID, 26293bc85817SGuennadi Liakhovetski }; 26303bc85817SGuennadi Liakhovetski 26313bc85817SGuennadi Liakhovetski static const struct uvc_device_info uvc_quirk_force_y8 = { 26323bc85817SGuennadi Liakhovetski .quirks = UVC_QUIRK_FORCE_Y8, 26333bc85817SGuennadi Liakhovetski }; 26343bc85817SGuennadi Liakhovetski 263588d8034cSGuennadi Liakhovetski #define UVC_INFO_QUIRK(q) (kernel_ulong_t)&(struct uvc_device_info){.quirks = q} 26366ea0d588SGuennadi Liakhovetski #define UVC_INFO_META(m) (kernel_ulong_t)&(struct uvc_device_info) \ 26376ea0d588SGuennadi Liakhovetski {.meta_format = m} 26383bc85817SGuennadi Liakhovetski 26390c0d06caSMauro Carvalho Chehab /* 26400c0d06caSMauro Carvalho Chehab * The Logitech cameras listed below have their interface class set to 26410c0d06caSMauro Carvalho Chehab * VENDOR_SPEC because they don't announce themselves as UVC devices, even 26420c0d06caSMauro Carvalho Chehab * though they are compliant. 26430c0d06caSMauro Carvalho Chehab */ 26447fb2e072SArvind Yadav static const struct usb_device_id uvc_ids[] = { 26450c0d06caSMauro Carvalho Chehab /* LogiLink Wireless Webcam */ 26460c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 26470c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 26480c0d06caSMauro Carvalho Chehab .idVendor = 0x0416, 26490c0d06caSMauro Carvalho Chehab .idProduct = 0xa91a, 26500c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 26510c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 26520c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 26533bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 26540c0d06caSMauro Carvalho Chehab /* Genius eFace 2025 */ 26550c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 26560c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 26570c0d06caSMauro Carvalho Chehab .idVendor = 0x0458, 26580c0d06caSMauro Carvalho Chehab .idProduct = 0x706e, 26590c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 26600c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 26610c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 26623bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 26630c0d06caSMauro Carvalho Chehab /* Microsoft Lifecam NX-6000 */ 26640c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 26650c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 26660c0d06caSMauro Carvalho Chehab .idVendor = 0x045e, 26670c0d06caSMauro Carvalho Chehab .idProduct = 0x00f8, 26680c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 26690c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 26700c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 26713bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 26721558ec83SLaurent Pinchart /* Microsoft Lifecam NX-3000 */ 26731558ec83SLaurent Pinchart { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 26741558ec83SLaurent Pinchart | USB_DEVICE_ID_MATCH_INT_INFO, 26751558ec83SLaurent Pinchart .idVendor = 0x045e, 26761558ec83SLaurent Pinchart .idProduct = 0x0721, 26771558ec83SLaurent Pinchart .bInterfaceClass = USB_CLASS_VIDEO, 26781558ec83SLaurent Pinchart .bInterfaceSubClass = 1, 26791558ec83SLaurent Pinchart .bInterfaceProtocol = 0, 26803bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 26810c0d06caSMauro Carvalho Chehab /* Microsoft Lifecam VX-7000 */ 26820c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 26830c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 26840c0d06caSMauro Carvalho Chehab .idVendor = 0x045e, 26850c0d06caSMauro Carvalho Chehab .idProduct = 0x0723, 26860c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 26870c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 26880c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 26893bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 26900c0d06caSMauro Carvalho Chehab /* Logitech Quickcam Fusion */ 26910c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 26920c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 26930c0d06caSMauro Carvalho Chehab .idVendor = 0x046d, 26940c0d06caSMauro Carvalho Chehab .idProduct = 0x08c1, 26950c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 26960c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 26970c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 26980c0d06caSMauro Carvalho Chehab /* Logitech Quickcam Orbit MP */ 26990c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27000c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27010c0d06caSMauro Carvalho Chehab .idVendor = 0x046d, 27020c0d06caSMauro Carvalho Chehab .idProduct = 0x08c2, 27030c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 27040c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27050c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 27060c0d06caSMauro Carvalho Chehab /* Logitech Quickcam Pro for Notebook */ 27070c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27080c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27090c0d06caSMauro Carvalho Chehab .idVendor = 0x046d, 27100c0d06caSMauro Carvalho Chehab .idProduct = 0x08c3, 27110c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 27120c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27130c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 27140c0d06caSMauro Carvalho Chehab /* Logitech Quickcam Pro 5000 */ 27150c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27160c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27170c0d06caSMauro Carvalho Chehab .idVendor = 0x046d, 27180c0d06caSMauro Carvalho Chehab .idProduct = 0x08c5, 27190c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 27200c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27210c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 27220c0d06caSMauro Carvalho Chehab /* Logitech Quickcam OEM Dell Notebook */ 27230c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27240c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27250c0d06caSMauro Carvalho Chehab .idVendor = 0x046d, 27260c0d06caSMauro Carvalho Chehab .idProduct = 0x08c6, 27270c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 27280c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27290c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 27300c0d06caSMauro Carvalho Chehab /* Logitech Quickcam OEM Cisco VT Camera II */ 27310c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27320c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27330c0d06caSMauro Carvalho Chehab .idVendor = 0x046d, 27340c0d06caSMauro Carvalho Chehab .idProduct = 0x08c7, 27350c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 27360c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27370c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 273817e1319fSWilliam Manley /* Logitech HD Pro Webcam C920 */ 273917e1319fSWilliam Manley { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 274017e1319fSWilliam Manley | USB_DEVICE_ID_MATCH_INT_INFO, 274117e1319fSWilliam Manley .idVendor = 0x046d, 274217e1319fSWilliam Manley .idProduct = 0x082d, 274317e1319fSWilliam Manley .bInterfaceClass = USB_CLASS_VIDEO, 274417e1319fSWilliam Manley .bInterfaceSubClass = 1, 274517e1319fSWilliam Manley .bInterfaceProtocol = 0, 274688d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT) }, 27470c0d06caSMauro Carvalho Chehab /* Chicony CNF7129 (Asus EEE 100HE) */ 27480c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27490c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27500c0d06caSMauro Carvalho Chehab .idVendor = 0x04f2, 27510c0d06caSMauro Carvalho Chehab .idProduct = 0xb071, 27520c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 27530c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27540c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 275588d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) }, 27560c0d06caSMauro Carvalho Chehab /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */ 27570c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27580c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27590c0d06caSMauro Carvalho Chehab .idVendor = 0x058f, 27600c0d06caSMauro Carvalho Chehab .idProduct = 0x3820, 27610c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 27620c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27630c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 27643bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 27650c0d06caSMauro Carvalho Chehab /* Dell XPS m1530 */ 27660c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 27670c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 27680c0d06caSMauro Carvalho Chehab .idVendor = 0x05a9, 27690c0d06caSMauro Carvalho Chehab .idProduct = 0x2640, 27700c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 27710c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 27720c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 27733bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 277489e0f248SJoseph Salisbury /* Dell SP2008WFP Monitor */ 277589e0f248SJoseph Salisbury { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 277689e0f248SJoseph Salisbury | USB_DEVICE_ID_MATCH_INT_INFO, 277789e0f248SJoseph Salisbury .idVendor = 0x05a9, 277889e0f248SJoseph Salisbury .idProduct = 0x2641, 277989e0f248SJoseph Salisbury .bInterfaceClass = USB_CLASS_VIDEO, 278089e0f248SJoseph Salisbury .bInterfaceSubClass = 1, 278189e0f248SJoseph Salisbury .bInterfaceProtocol = 0, 27823bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 2783c2a273b2SJoseph Salisbury /* Dell Alienware X51 */ 2784c2a273b2SJoseph Salisbury { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2785c2a273b2SJoseph Salisbury | USB_DEVICE_ID_MATCH_INT_INFO, 2786c2a273b2SJoseph Salisbury .idVendor = 0x05a9, 2787c2a273b2SJoseph Salisbury .idProduct = 0x2643, 2788c2a273b2SJoseph Salisbury .bInterfaceClass = USB_CLASS_VIDEO, 2789c2a273b2SJoseph Salisbury .bInterfaceSubClass = 1, 2790c2a273b2SJoseph Salisbury .bInterfaceProtocol = 0, 27913bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 2792afcf44c7SKamal Mostafa /* Dell Studio Hybrid 140g (OmniVision webcam) */ 2793afcf44c7SKamal Mostafa { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2794afcf44c7SKamal Mostafa | USB_DEVICE_ID_MATCH_INT_INFO, 2795afcf44c7SKamal Mostafa .idVendor = 0x05a9, 2796afcf44c7SKamal Mostafa .idProduct = 0x264a, 2797afcf44c7SKamal Mostafa .bInterfaceClass = USB_CLASS_VIDEO, 2798afcf44c7SKamal Mostafa .bInterfaceSubClass = 1, 2799afcf44c7SKamal Mostafa .bInterfaceProtocol = 0, 28003bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 280162ea864fSPaul Fertser /* Dell XPS M1330 (OmniVision OV7670 webcam) */ 280262ea864fSPaul Fertser { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 280362ea864fSPaul Fertser | USB_DEVICE_ID_MATCH_INT_INFO, 280462ea864fSPaul Fertser .idVendor = 0x05a9, 280562ea864fSPaul Fertser .idProduct = 0x7670, 280662ea864fSPaul Fertser .bInterfaceClass = USB_CLASS_VIDEO, 280762ea864fSPaul Fertser .bInterfaceSubClass = 1, 280862ea864fSPaul Fertser .bInterfaceProtocol = 0, 28093bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 28100c0d06caSMauro Carvalho Chehab /* Apple Built-In iSight */ 28110c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28120c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28130c0d06caSMauro Carvalho Chehab .idVendor = 0x05ac, 28140c0d06caSMauro Carvalho Chehab .idProduct = 0x8501, 28150c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28160c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28170c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 281888d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX 28193bc85817SGuennadi Liakhovetski | UVC_QUIRK_BUILTIN_ISIGHT) }, 28207b848ed6SDaniel Roschka /* Apple Built-In iSight via iBridge */ 28217b848ed6SDaniel Roschka { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28227b848ed6SDaniel Roschka | USB_DEVICE_ID_MATCH_INT_INFO, 28237b848ed6SDaniel Roschka .idVendor = 0x05ac, 28247b848ed6SDaniel Roschka .idProduct = 0x8600, 28257b848ed6SDaniel Roschka .bInterfaceClass = USB_CLASS_VIDEO, 28267b848ed6SDaniel Roschka .bInterfaceSubClass = 1, 28277b848ed6SDaniel Roschka .bInterfaceProtocol = 0, 28283bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 28290c0d06caSMauro Carvalho Chehab /* Foxlink ("HP Webcam" on HP Mini 5103) */ 28300c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28310c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28320c0d06caSMauro Carvalho Chehab .idVendor = 0x05c8, 28330c0d06caSMauro Carvalho Chehab .idProduct = 0x0403, 28340c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28350c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28360c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28373bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, 28380c0d06caSMauro Carvalho Chehab /* Genesys Logic USB 2.0 PC Camera */ 28390c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28400c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28410c0d06caSMauro Carvalho Chehab .idVendor = 0x05e3, 28420c0d06caSMauro Carvalho Chehab .idProduct = 0x0505, 28430c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28440c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28450c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28463bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 28470c0d06caSMauro Carvalho Chehab /* Hercules Classic Silver */ 28480c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28490c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28500c0d06caSMauro Carvalho Chehab .idVendor = 0x06f8, 28510c0d06caSMauro Carvalho Chehab .idProduct = 0x300c, 28520c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28530c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28540c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28553bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, 28560c0d06caSMauro Carvalho Chehab /* ViMicro Vega */ 28570c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28580c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28590c0d06caSMauro Carvalho Chehab .idVendor = 0x0ac8, 28600c0d06caSMauro Carvalho Chehab .idProduct = 0x332d, 28610c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28620c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28630c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28643bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, 28650c0d06caSMauro Carvalho Chehab /* ViMicro - Minoru3D */ 28660c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28670c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28680c0d06caSMauro Carvalho Chehab .idVendor = 0x0ac8, 28690c0d06caSMauro Carvalho Chehab .idProduct = 0x3410, 28700c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28710c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28720c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28733bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, 28740c0d06caSMauro Carvalho Chehab /* ViMicro Venus - Minoru3D */ 28750c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28760c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28770c0d06caSMauro Carvalho Chehab .idVendor = 0x0ac8, 28780c0d06caSMauro Carvalho Chehab .idProduct = 0x3420, 28790c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28800c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28810c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28823bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, 28830c0d06caSMauro Carvalho Chehab /* Ophir Optronics - SPCAM 620U */ 28840c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28850c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28860c0d06caSMauro Carvalho Chehab .idVendor = 0x0bd3, 28870c0d06caSMauro Carvalho Chehab .idProduct = 0x0555, 28880c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28890c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28900c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 28913bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 28920c0d06caSMauro Carvalho Chehab /* MT6227 */ 28930c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 28940c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 28950c0d06caSMauro Carvalho Chehab .idVendor = 0x0e8d, 28960c0d06caSMauro Carvalho Chehab .idProduct = 0x0004, 28970c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 28980c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 28990c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 290088d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX 29013bc85817SGuennadi Liakhovetski | UVC_QUIRK_PROBE_DEF) }, 29020c0d06caSMauro Carvalho Chehab /* IMC Networks (Medion Akoya) */ 29030c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29040c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29050c0d06caSMauro Carvalho Chehab .idVendor = 0x13d3, 29060c0d06caSMauro Carvalho Chehab .idProduct = 0x5103, 29070c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29080c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29090c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29103bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29110c0d06caSMauro Carvalho Chehab /* JMicron USB2.0 XGA WebCam */ 29120c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29130c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29140c0d06caSMauro Carvalho Chehab .idVendor = 0x152d, 29150c0d06caSMauro Carvalho Chehab .idProduct = 0x0310, 29160c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29170c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29180c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29193bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 29200c0d06caSMauro Carvalho Chehab /* Syntek (HP Spartan) */ 29210c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29220c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29230c0d06caSMauro Carvalho Chehab .idVendor = 0x174f, 29240c0d06caSMauro Carvalho Chehab .idProduct = 0x5212, 29250c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29260c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29270c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29283bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29290c0d06caSMauro Carvalho Chehab /* Syntek (Samsung Q310) */ 29300c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29310c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29320c0d06caSMauro Carvalho Chehab .idVendor = 0x174f, 29330c0d06caSMauro Carvalho Chehab .idProduct = 0x5931, 29340c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29350c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29360c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29373bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29380c0d06caSMauro Carvalho Chehab /* Syntek (Packard Bell EasyNote MX52 */ 29390c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29400c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29410c0d06caSMauro Carvalho Chehab .idVendor = 0x174f, 29420c0d06caSMauro Carvalho Chehab .idProduct = 0x8a12, 29430c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29440c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29450c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29463bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29470c0d06caSMauro Carvalho Chehab /* Syntek (Asus F9SG) */ 29480c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29490c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29500c0d06caSMauro Carvalho Chehab .idVendor = 0x174f, 29510c0d06caSMauro Carvalho Chehab .idProduct = 0x8a31, 29520c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29530c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29540c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29553bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29560c0d06caSMauro Carvalho Chehab /* Syntek (Asus U3S) */ 29570c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29580c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29590c0d06caSMauro Carvalho Chehab .idVendor = 0x174f, 29600c0d06caSMauro Carvalho Chehab .idProduct = 0x8a33, 29610c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29620c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29630c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29643bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29650c0d06caSMauro Carvalho Chehab /* Syntek (JAOtech Smart Terminal) */ 29660c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29670c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29680c0d06caSMauro Carvalho Chehab .idVendor = 0x174f, 29690c0d06caSMauro Carvalho Chehab .idProduct = 0x8a34, 29700c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29710c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29720c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29733bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29740c0d06caSMauro Carvalho Chehab /* Miricle 307K */ 29750c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29760c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29770c0d06caSMauro Carvalho Chehab .idVendor = 0x17dc, 29780c0d06caSMauro Carvalho Chehab .idProduct = 0x0202, 29790c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29800c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29810c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29823bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29830c0d06caSMauro Carvalho Chehab /* Lenovo Thinkpad SL400/SL500 */ 29840c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29850c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29860c0d06caSMauro Carvalho Chehab .idVendor = 0x17ef, 29870c0d06caSMauro Carvalho Chehab .idProduct = 0x480b, 29880c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29890c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29900c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 29913bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_stream_no_fid }, 29920c0d06caSMauro Carvalho Chehab /* Aveo Technology USB 2.0 Camera */ 29930c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 29940c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 29950c0d06caSMauro Carvalho Chehab .idVendor = 0x1871, 29960c0d06caSMauro Carvalho Chehab .idProduct = 0x0306, 29970c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 29980c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 29990c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 300088d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX 30013bc85817SGuennadi Liakhovetski | UVC_QUIRK_PROBE_EXTRAFIELDS) }, 3002fe652471SLaurent Pinchart /* Aveo Technology USB 2.0 Camera (Tasco USB Microscope) */ 3003fe652471SLaurent Pinchart { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 3004fe652471SLaurent Pinchart | USB_DEVICE_ID_MATCH_INT_INFO, 3005fe652471SLaurent Pinchart .idVendor = 0x1871, 3006fe652471SLaurent Pinchart .idProduct = 0x0516, 3007fe652471SLaurent Pinchart .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 3008fe652471SLaurent Pinchart .bInterfaceSubClass = 1, 3009fe652471SLaurent Pinchart .bInterfaceProtocol = 0 }, 30100c0d06caSMauro Carvalho Chehab /* Ecamm Pico iMage */ 30110c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30120c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30130c0d06caSMauro Carvalho Chehab .idVendor = 0x18cd, 30140c0d06caSMauro Carvalho Chehab .idProduct = 0xcafe, 30150c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 30160c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30170c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 301888d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_EXTRAFIELDS) }, 30190c0d06caSMauro Carvalho Chehab /* Manta MM-353 Plako */ 30200c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30210c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30220c0d06caSMauro Carvalho Chehab .idVendor = 0x18ec, 30230c0d06caSMauro Carvalho Chehab .idProduct = 0x3188, 30240c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 30250c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30260c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 30273bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 30280c0d06caSMauro Carvalho Chehab /* FSC WebCam V30S */ 30290c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30300c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30310c0d06caSMauro Carvalho Chehab .idVendor = 0x18ec, 30320c0d06caSMauro Carvalho Chehab .idProduct = 0x3288, 30330c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 30340c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30350c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 30363bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 30370c0d06caSMauro Carvalho Chehab /* Arkmicro unbranded */ 30380c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30390c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30400c0d06caSMauro Carvalho Chehab .idVendor = 0x18ec, 30410c0d06caSMauro Carvalho Chehab .idProduct = 0x3290, 30420c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 30430c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30440c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 30453bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_def }, 30460c0d06caSMauro Carvalho Chehab /* The Imaging Source USB CCD cameras */ 30470c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30480c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30490c0d06caSMauro Carvalho Chehab .idVendor = 0x199e, 30500c0d06caSMauro Carvalho Chehab .idProduct = 0x8102, 30510c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 30520c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30530c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0 }, 30540c0d06caSMauro Carvalho Chehab /* Bodelin ProScopeHR */ 30550c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30560c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_DEV_HI 30570c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30580c0d06caSMauro Carvalho Chehab .idVendor = 0x19ab, 30590c0d06caSMauro Carvalho Chehab .idProduct = 0x1000, 30600c0d06caSMauro Carvalho Chehab .bcdDevice_hi = 0x0126, 30610c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 30620c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30630c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 306488d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_STATUS_INTERVAL) }, 30650c0d06caSMauro Carvalho Chehab /* MSI StarCam 370i */ 30660c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30670c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30680c0d06caSMauro Carvalho Chehab .idVendor = 0x1b3b, 30690c0d06caSMauro Carvalho Chehab .idProduct = 0x2951, 30700c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 30710c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 30720c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 30733bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 3074589266bdSNeil Armstrong /* Generalplus Technology Inc. 808 Camera */ 3075589266bdSNeil Armstrong { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 3076589266bdSNeil Armstrong | USB_DEVICE_ID_MATCH_INT_INFO, 3077589266bdSNeil Armstrong .idVendor = 0x1b3f, 3078589266bdSNeil Armstrong .idProduct = 0x2002, 3079589266bdSNeil Armstrong .bInterfaceClass = USB_CLASS_VIDEO, 3080589266bdSNeil Armstrong .bInterfaceSubClass = 1, 3081589266bdSNeil Armstrong .bInterfaceProtocol = 0, 3082589266bdSNeil Armstrong .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, 3083b400b6f2SLaurent Pinchart /* Shenzhen Aoni Electronic Co.,Ltd 2K FHD camera */ 3084b400b6f2SLaurent Pinchart { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 3085b400b6f2SLaurent Pinchart | USB_DEVICE_ID_MATCH_INT_INFO, 3086b400b6f2SLaurent Pinchart .idVendor = 0x1bcf, 3087b400b6f2SLaurent Pinchart .idProduct = 0x0b40, 3088b400b6f2SLaurent Pinchart .bInterfaceClass = USB_CLASS_VIDEO, 3089b400b6f2SLaurent Pinchart .bInterfaceSubClass = 1, 3090b400b6f2SLaurent Pinchart .bInterfaceProtocol = 0, 3091b400b6f2SLaurent Pinchart .driver_info = (kernel_ulong_t)&(const struct uvc_device_info){ 3092b400b6f2SLaurent Pinchart .uvc_version = 0x010a, 3093b400b6f2SLaurent Pinchart } }, 30940c0d06caSMauro Carvalho Chehab /* SiGma Micro USB Web Camera */ 30950c0d06caSMauro Carvalho Chehab { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 30960c0d06caSMauro Carvalho Chehab | USB_DEVICE_ID_MATCH_INT_INFO, 30970c0d06caSMauro Carvalho Chehab .idVendor = 0x1c4f, 30980c0d06caSMauro Carvalho Chehab .idProduct = 0x3000, 30990c0d06caSMauro Carvalho Chehab .bInterfaceClass = USB_CLASS_VIDEO, 31000c0d06caSMauro Carvalho Chehab .bInterfaceSubClass = 1, 31010c0d06caSMauro Carvalho Chehab .bInterfaceProtocol = 0, 310288d8034cSGuennadi Liakhovetski .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_PROBE_MINMAX 31033bc85817SGuennadi Liakhovetski | UVC_QUIRK_IGNORE_SELECTOR_UNIT) }, 3104e1b78a33SPhilipp Zabel /* Oculus VR Positional Tracker DK2 */ 3105e1b78a33SPhilipp Zabel { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 3106e1b78a33SPhilipp Zabel | USB_DEVICE_ID_MATCH_INT_INFO, 3107e1b78a33SPhilipp Zabel .idVendor = 0x2833, 3108e1b78a33SPhilipp Zabel .idProduct = 0x0201, 3109e1b78a33SPhilipp Zabel .bInterfaceClass = USB_CLASS_VIDEO, 3110e1b78a33SPhilipp Zabel .bInterfaceSubClass = 1, 3111e1b78a33SPhilipp Zabel .bInterfaceProtocol = 0, 31123bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 }, 311303c47aaeSPhilipp Zabel /* Oculus VR Rift Sensor */ 311403c47aaeSPhilipp Zabel { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 311503c47aaeSPhilipp Zabel | USB_DEVICE_ID_MATCH_INT_INFO, 311603c47aaeSPhilipp Zabel .idVendor = 0x2833, 311703c47aaeSPhilipp Zabel .idProduct = 0x0211, 311803c47aaeSPhilipp Zabel .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 311903c47aaeSPhilipp Zabel .bInterfaceSubClass = 1, 312003c47aaeSPhilipp Zabel .bInterfaceProtocol = 0, 31213bc85817SGuennadi Liakhovetski .driver_info = (kernel_ulong_t)&uvc_quirk_force_y8 }, 31221dd2e8f9SSergey Zakharchenko /* GEO Semiconductor GC6500 */ 31231dd2e8f9SSergey Zakharchenko { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 31241dd2e8f9SSergey Zakharchenko | USB_DEVICE_ID_MATCH_INT_INFO, 31251dd2e8f9SSergey Zakharchenko .idVendor = 0x29fe, 31261dd2e8f9SSergey Zakharchenko .idProduct = 0x4d53, 31271dd2e8f9SSergey Zakharchenko .bInterfaceClass = USB_CLASS_VIDEO, 31281dd2e8f9SSergey Zakharchenko .bInterfaceSubClass = 1, 31291dd2e8f9SSergey Zakharchenko .bInterfaceProtocol = 0, 31301dd2e8f9SSergey Zakharchenko .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) }, 31316ea0d588SGuennadi Liakhovetski /* Intel RealSense D4M */ 31326ea0d588SGuennadi Liakhovetski { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 31336ea0d588SGuennadi Liakhovetski | USB_DEVICE_ID_MATCH_INT_INFO, 31346ea0d588SGuennadi Liakhovetski .idVendor = 0x8086, 31356ea0d588SGuennadi Liakhovetski .idProduct = 0x0b03, 31366ea0d588SGuennadi Liakhovetski .bInterfaceClass = USB_CLASS_VIDEO, 31376ea0d588SGuennadi Liakhovetski .bInterfaceSubClass = 1, 31386ea0d588SGuennadi Liakhovetski .bInterfaceProtocol = 0, 31396ea0d588SGuennadi Liakhovetski .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, 31400c0d06caSMauro Carvalho Chehab /* Generic USB Video Class */ 31418afe97beSLaurent Pinchart { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) }, 31428afe97beSLaurent Pinchart { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) }, 31430c0d06caSMauro Carvalho Chehab {} 31440c0d06caSMauro Carvalho Chehab }; 31450c0d06caSMauro Carvalho Chehab 31460c0d06caSMauro Carvalho Chehab MODULE_DEVICE_TABLE(usb, uvc_ids); 31470c0d06caSMauro Carvalho Chehab 31480c0d06caSMauro Carvalho Chehab struct uvc_driver uvc_driver = { 31490c0d06caSMauro Carvalho Chehab .driver = { 31500c0d06caSMauro Carvalho Chehab .name = "uvcvideo", 31510c0d06caSMauro Carvalho Chehab .probe = uvc_probe, 31520c0d06caSMauro Carvalho Chehab .disconnect = uvc_disconnect, 31530c0d06caSMauro Carvalho Chehab .suspend = uvc_suspend, 31540c0d06caSMauro Carvalho Chehab .resume = uvc_resume, 31550c0d06caSMauro Carvalho Chehab .reset_resume = uvc_reset_resume, 31560c0d06caSMauro Carvalho Chehab .id_table = uvc_ids, 31570c0d06caSMauro Carvalho Chehab .supports_autosuspend = 1, 31580c0d06caSMauro Carvalho Chehab }, 31590c0d06caSMauro Carvalho Chehab }; 31600c0d06caSMauro Carvalho Chehab 31610c0d06caSMauro Carvalho Chehab static int __init uvc_init(void) 31620c0d06caSMauro Carvalho Chehab { 31630c0d06caSMauro Carvalho Chehab int ret; 31640c0d06caSMauro Carvalho Chehab 31650c0d06caSMauro Carvalho Chehab uvc_debugfs_init(); 31660c0d06caSMauro Carvalho Chehab 31670c0d06caSMauro Carvalho Chehab ret = usb_register(&uvc_driver.driver); 31680c0d06caSMauro Carvalho Chehab if (ret < 0) { 31690c0d06caSMauro Carvalho Chehab uvc_debugfs_cleanup(); 31700c0d06caSMauro Carvalho Chehab return ret; 31710c0d06caSMauro Carvalho Chehab } 31720c0d06caSMauro Carvalho Chehab 31730c0d06caSMauro Carvalho Chehab printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n"); 31740c0d06caSMauro Carvalho Chehab return 0; 31750c0d06caSMauro Carvalho Chehab } 31760c0d06caSMauro Carvalho Chehab 31770c0d06caSMauro Carvalho Chehab static void __exit uvc_cleanup(void) 31780c0d06caSMauro Carvalho Chehab { 31790c0d06caSMauro Carvalho Chehab usb_deregister(&uvc_driver.driver); 31800c0d06caSMauro Carvalho Chehab uvc_debugfs_cleanup(); 31810c0d06caSMauro Carvalho Chehab } 31820c0d06caSMauro Carvalho Chehab 31830c0d06caSMauro Carvalho Chehab module_init(uvc_init); 31840c0d06caSMauro Carvalho Chehab module_exit(uvc_cleanup); 31850c0d06caSMauro Carvalho Chehab 31860c0d06caSMauro Carvalho Chehab MODULE_AUTHOR(DRIVER_AUTHOR); 31870c0d06caSMauro Carvalho Chehab MODULE_DESCRIPTION(DRIVER_DESC); 31880c0d06caSMauro Carvalho Chehab MODULE_LICENSE("GPL"); 31890c0d06caSMauro Carvalho Chehab MODULE_VERSION(DRIVER_VERSION); 31900c0d06caSMauro Carvalho Chehab 3191