blob: 6ab972c643e37a95bec5ff0c26b53dfb77c28fc8 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Laurent Pinchartc0efd232008-06-30 15:04:50 -03002#ifndef _USB_VIDEO_H_
3#define _USB_VIDEO_H_
4
Laurent Pinchart227bd5b2011-07-30 16:19:49 -03005#ifndef __KERNEL__
6#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
7#endif /* __KERNEL__ */
8
Laurent Pinchartc0efd232008-06-30 15:04:50 -03009#include <linux/kernel.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030010#include <linux/poll.h>
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -030011#include <linux/usb.h>
Laurent Pinchartde05f632009-06-26 12:15:38 -030012#include <linux/usb/video.h>
Laurent Pinchart5f708812010-11-21 17:15:44 -030013#include <linux/uvcvideo.h>
Laurent Pinchart227bd5b2011-07-30 16:19:49 -030014#include <linux/videodev2.h>
Guennadi Liakhovetskie5225c82018-07-26 04:17:53 -040015#include <linux/workqueue.h>
Laurent Pinchart5a254d72010-01-21 05:39:47 -030016#include <media/media-device.h>
17#include <media/v4l2-device.h>
Hans de Goedeb4012002012-04-08 12:59:51 -030018#include <media/v4l2-event.h>
19#include <media/v4l2-fh.h>
Junghak Sungc1399902015-09-22 10:30:29 -030020#include <media/videobuf2-v4l2.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030021
22/* --------------------------------------------------------------------------
23 * UVC constants
24 */
25
Laurent Pinchartc0efd232008-06-30 15:04:50 -030026#define UVC_TERM_INPUT 0x0000
27#define UVC_TERM_OUTPUT 0x8000
Laurent Pinchart6241d8c2009-11-25 12:00:22 -030028#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030029
30#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
31#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
32#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
33#define UVC_ENTITY_IS_ITERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -030034 (UVC_ENTITY_IS_TERM(entity) && \
35 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030036#define UVC_ENTITY_IS_OTERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -030037 (UVC_ENTITY_IS_TERM(entity) && \
38 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030039
Laurent Pinchartc0efd232008-06-30 15:04:50 -030040
41/* ------------------------------------------------------------------------
42 * GUIDs
43 */
44#define UVC_GUID_UVC_CAMERA \
45 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
47#define UVC_GUID_UVC_OUTPUT \
48 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
50#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
51 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
53#define UVC_GUID_UVC_PROCESSING \
54 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
56#define UVC_GUID_UVC_SELECTOR \
57 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
59
Laurent Pinchartc0efd232008-06-30 15:04:50 -030060#define UVC_GUID_FORMAT_MJPEG \
61 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
62 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
63#define UVC_GUID_FORMAT_YUY2 \
64 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
65 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Daniel Ritz68f194e2009-12-12 14:57:17 -030066#define UVC_GUID_FORMAT_YUY2_ISIGHT \
67 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
68 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -030069#define UVC_GUID_FORMAT_NV12 \
70 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
71 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
72#define UVC_GUID_FORMAT_YV12 \
73 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
74 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
75#define UVC_GUID_FORMAT_I420 \
76 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
77 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
78#define UVC_GUID_FORMAT_UYVY \
79 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
80 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
81#define UVC_GUID_FORMAT_Y800 \
82 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
83 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Stefan Muenzelca47e712012-07-28 19:49:14 -030084#define UVC_GUID_FORMAT_Y8 \
85 { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \
86 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
87#define UVC_GUID_FORMAT_Y10 \
88 { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \
89 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
90#define UVC_GUID_FORMAT_Y12 \
91 { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \
92 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart614212062010-04-12 10:41:22 -030093#define UVC_GUID_FORMAT_Y16 \
94 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
95 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -030096#define UVC_GUID_FORMAT_BY8 \
97 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
98 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Edgar Thiere72ed082014-02-20 04:12:51 -030099#define UVC_GUID_FORMAT_BA81 \
100 { 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \
101 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
102#define UVC_GUID_FORMAT_GBRG \
103 { 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \
104 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
105#define UVC_GUID_FORMAT_GRBG \
106 { 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \
107 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
108#define UVC_GUID_FORMAT_RGGB \
109 { 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \
110 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Edgar Thiereb165a22016-11-15 03:33:10 -0200111#define UVC_GUID_FORMAT_BG16 \
112 { 'B', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \
113 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
114#define UVC_GUID_FORMAT_GB16 \
115 { 'G', 'B', '1', '6', 0x00, 0x00, 0x10, 0x00, \
116 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
117#define UVC_GUID_FORMAT_RG16 \
118 { 'R', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \
119 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
120#define UVC_GUID_FORMAT_GR16 \
121 { 'G', 'R', '1', '6', 0x00, 0x00, 0x10, 0x00, \
122 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart50791072011-03-06 08:32:04 -0300123#define UVC_GUID_FORMAT_RGBP \
124 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
125 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
William Manley1b8dc322014-12-08 15:57:58 -0300126#define UVC_GUID_FORMAT_BGR3 \
127 { 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \
128 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}
Hans de Goede7225a1d2011-05-11 09:56:20 -0300129#define UVC_GUID_FORMAT_M420 \
130 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
131 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300132
Stephan Lachowsky25ad8a82011-01-28 16:38:58 -0300133#define UVC_GUID_FORMAT_H264 \
134 { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \
135 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Aviv Greenberg5d8d8db2016-02-03 15:08:52 -0200136#define UVC_GUID_FORMAT_Y8I \
137 { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \
138 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
139#define UVC_GUID_FORMAT_Y12I \
140 { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \
141 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
142#define UVC_GUID_FORMAT_Z16 \
143 { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
144 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
145#define UVC_GUID_FORMAT_RW10 \
146 { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \
147 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Daniel Patrick Johnsonc4a09682017-03-02 20:43:20 -0300148#define UVC_GUID_FORMAT_INVZ \
149 { 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \
150 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
151#define UVC_GUID_FORMAT_INZI \
152 { 'I', 'N', 'Z', 'I', 0x66, 0x1a, 0x42, 0xa2, \
153 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a}
154#define UVC_GUID_FORMAT_INVI \
155 { 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \
156 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f}
Sergey Dorodnicov38e9b922018-09-12 02:42:07 -0400157#define UVC_GUID_FORMAT_CNF4 \
158 { 'C', ' ', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \
159 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Stephan Lachowsky25ad8a82011-01-28 16:38:58 -0300160
Nicolas Dufresnee96cdc92017-11-06 15:13:28 -0500161#define UVC_GUID_FORMAT_D3DFMT_L8 \
162 {0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, \
163 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart557a5c72018-03-21 05:16:40 -0400164#define UVC_GUID_FORMAT_KSMEDIA_L8_IR \
165 {0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, \
166 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Nicolas Dufresnee96cdc92017-11-06 15:13:28 -0500167
168
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300169/* ------------------------------------------------------------------------
170 * Driver specific constants.
171 */
172
Mauro Carvalho Chehabfd3e5822011-06-25 13:50:37 -0300173#define DRIVER_VERSION "1.1.1"
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300174
175/* Number of isochronous URBs. */
176#define UVC_URBS 5
Laurent Pinchartefdc8a92009-01-18 17:46:30 -0300177/* Maximum number of packets per URB. */
178#define UVC_MAX_PACKETS 32
Ming Leia31a4052008-09-16 03:32:20 -0300179/* Maximum status buffer size in bytes of interrupt URB. */
180#define UVC_MAX_STATUS_SIZE 16
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300181
Jim Linda6df1c2017-08-08 08:56:20 -0400182#define UVC_CTRL_CONTROL_TIMEOUT 500
Laurent Pinchart56d15cd2010-01-19 08:59:21 -0300183#define UVC_CTRL_STREAMING_TIMEOUT 5000
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300184
Martin Rubli8fb91b32010-09-08 04:15:23 -0300185/* Maximum allowed number of control mappings per device */
186#define UVC_MAX_CONTROL_MAPPINGS 1024
Haogang Chen806e23e2011-11-29 18:32:25 -0300187#define UVC_MAX_CONTROL_MENU_ENTRIES 32
Martin Rubli8fb91b32010-09-08 04:15:23 -0300188
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300189/* Devices quirks */
190#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
191#define UVC_QUIRK_PROBE_MINMAX 0x00000002
192#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
193#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
194#define UVC_QUIRK_STREAM_NO_FID 0x00000010
195#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
Laurent Pinchart50144ae2009-02-16 17:41:52 -0300196#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
Laurent Pinchartbab6f662009-07-19 18:39:56 -0300197#define UVC_QUIRK_PROBE_DEF 0x00000100
Laurent Pinchart86d8b6a2010-09-16 12:37:26 -0300198#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
William Manley17e13192014-03-13 09:38:48 -0300199#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400
Philipp Zabele1b78a32014-08-06 17:50:49 -0300200#define UVC_QUIRK_FORCE_Y8 0x00000800
Sergey Zakharchenko1dd2e8f2019-10-03 11:31:23 +0200201#define UVC_QUIRK_FORCE_BPP 0x00001000
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300202
203/* Format flags */
204#define UVC_FMT_FLAG_COMPRESSED 0x00000001
205#define UVC_FMT_FLAG_STREAM 0x00000002
206
207/* ------------------------------------------------------------------------
208 * Structures.
209 */
210
211struct uvc_device;
212
213/* TODO: Put the most frequently accessed fields at the beginning of
214 * structures to maximize cache efficiency.
215 */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300216struct uvc_control_info {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300217 struct list_head mappings;
218
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500219 u8 entity[16];
220 u8 index; /* Bit index in bmControls */
221 u8 selector;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300222
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500223 u16 size;
224 u32 flags;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300225};
226
227struct uvc_control_mapping {
228 struct list_head list;
Hans de Goedeb4012002012-04-08 12:59:51 -0300229 struct list_head ev_subs;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300230
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500231 u32 id;
232 u8 name[32];
233 u8 entity[16];
234 u8 selector;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300235
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500236 u8 size;
237 u8 offset;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300238 enum v4l2_ctrl_type v4l2_type;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500239 u32 data_type;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300240
Laurent Pinchart52a4eb32018-08-06 18:25:33 -0400241 const struct uvc_menu_info *menu_info;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500242 u32 menu_count;
Laurent Pinchart97683522008-12-16 06:46:32 -0300243
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500244 u32 master_id;
245 s32 master_manual;
246 u32 slave_ids[2];
Hans de Goede55afeb82012-04-08 12:59:52 -0300247
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500248 s32 (*get)(struct uvc_control_mapping *mapping, u8 query,
249 const u8 *data);
250 void (*set)(struct uvc_control_mapping *mapping, s32 value,
251 u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300252};
253
254struct uvc_control {
255 struct uvc_entity *entity;
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300256 struct uvc_control_info info;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300257
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500258 u8 index; /* Used to match the uvc_control entry with a
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300259 uvc_control_info. */
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500260 u8 dirty:1,
261 loaded:1,
262 modified:1,
263 cached:1,
264 initialized:1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300265
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500266 u8 *uvc_data;
Guennadi Liakhovetskie5225c82018-07-26 04:17:53 -0400267
268 struct uvc_fh *handle; /* File handle that last changed the control. */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300269};
270
271struct uvc_format_desc {
272 char *name;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500273 u8 guid[16];
274 u32 fcc;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300275};
276
277/* The term 'entity' refers to both UVC units and UVC terminals.
278 *
279 * The type field is either the terminal type (wTerminalType in the terminal
280 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
281 * As the bDescriptorSubtype field is one byte long, the type value will
282 * always have a null MSB for units. All terminal types defined by the UVC
283 * specification have a non-null MSB, so it is safe to use the MSB to
284 * differentiate between units and terminals as long as the descriptor parsing
285 * code makes sure terminal types have a non-null MSB.
286 *
287 * For terminals, the type's most significant bit stores the terminal
288 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
289 * always be accessed with the UVC_ENTITY_* macros and never directly.
290 */
291
Laurent Pinchart8be8ec62012-08-03 04:35:10 -0300292#define UVC_ENTITY_FLAG_DEFAULT (1 << 0)
293
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300294struct uvc_entity {
295 struct list_head list; /* Entity as part of a UVC device. */
296 struct list_head chain; /* Entity as part of a video device
297 * chain. */
Laurent Pinchart8be8ec62012-08-03 04:35:10 -0300298 unsigned int flags;
299
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500300 u8 id;
301 u16 type;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300302 char name[64];
303
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300304 /* Media controller-related fields. */
Laurent Pinchart8a65a942010-01-21 08:56:19 -0300305 struct video_device *vdev;
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300306 struct v4l2_subdev subdev;
307 unsigned int num_pads;
308 unsigned int num_links;
309 struct media_pad *pads;
310
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300311 union {
312 struct {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500313 u16 wObjectiveFocalLengthMin;
314 u16 wObjectiveFocalLengthMax;
315 u16 wOcularFocalLength;
316 u8 bControlSize;
317 u8 *bmControls;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300318 } camera;
319
320 struct {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500321 u8 bControlSize;
322 u8 *bmControls;
323 u8 bTransportModeSize;
324 u8 *bmTransportModes;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300325 } media;
326
327 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300328 } output;
329
330 struct {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500331 u16 wMaxMultiplier;
332 u8 bControlSize;
333 u8 *bmControls;
334 u8 bmVideoStandards;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300335 } processing;
336
337 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300338 } selector;
339
340 struct {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500341 u8 guidExtensionCode[16];
342 u8 bNumControls;
343 u8 bControlSize;
344 u8 *bmControls;
345 u8 *bmControlsType;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300346 } extension;
347 };
348
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500349 u8 bNrInPins;
350 u8 *baSourceID;
Laurent Pinchart8ca5a632009-11-25 12:00:30 -0300351
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300352 unsigned int ncontrols;
353 struct uvc_control *controls;
354};
355
356struct uvc_frame {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500357 u8 bFrameIndex;
358 u8 bmCapabilities;
359 u16 wWidth;
360 u16 wHeight;
361 u32 dwMinBitRate;
362 u32 dwMaxBitRate;
363 u32 dwMaxVideoFrameBufferSize;
364 u8 bFrameIntervalType;
365 u32 dwDefaultFrameInterval;
366 u32 *dwFrameInterval;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300367};
368
369struct uvc_format {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500370 u8 type;
371 u8 index;
372 u8 bpp;
373 u8 colorspace;
374 u32 fcc;
375 u32 flags;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300376
377 char name[32];
378
379 unsigned int nframes;
380 struct uvc_frame *frame;
381};
382
383struct uvc_streaming_header {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500384 u8 bNumFormats;
385 u8 bEndpointAddress;
386 u8 bTerminalLink;
387 u8 bControlSize;
388 u8 *bmaControls;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300389 /* The following fields are used by input headers only. */
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500390 u8 bmInfo;
391 u8 bStillCaptureMethod;
392 u8 bTriggerSupport;
393 u8 bTriggerUsage;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300394};
395
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300396enum uvc_buffer_state {
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300397 UVC_BUF_STATE_IDLE = 0,
398 UVC_BUF_STATE_QUEUED = 1,
399 UVC_BUF_STATE_ACTIVE = 2,
Laurent Pinchartd7c0d432009-12-16 21:20:45 -0300400 UVC_BUF_STATE_READY = 3,
401 UVC_BUF_STATE_DONE = 4,
402 UVC_BUF_STATE_ERROR = 5,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300403};
404
405struct uvc_buffer {
Junghak Sung2d700712015-09-22 10:30:30 -0300406 struct vb2_v4l2_buffer buf;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300407 struct list_head queue;
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300408
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300409 enum uvc_buffer_state state;
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300410 unsigned int error;
Laurent Pinchart3d95e932011-10-24 11:49:19 -0300411
412 void *mem;
413 unsigned int length;
414 unsigned int bytesused;
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300415
416 u32 pts;
Kieran Bingham01e90462017-03-16 09:33:05 -0400417
418 /* Asynchronous buffer handling. */
419 struct kref ref;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300420};
421
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300422#define UVC_QUEUE_DISCONNECTED (1 << 0)
423#define UVC_QUEUE_DROP_CORRUPTED (1 << 1)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300424
425struct uvc_video_queue {
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300426 struct vb2_queue queue;
427 struct mutex mutex; /* Protects queue */
Laurent Pinchartff924202008-12-28 22:32:29 -0300428
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300429 unsigned int flags;
Laurent Pinchartff924202008-12-28 22:32:29 -0300430 unsigned int buf_used;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300431
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300432 spinlock_t irqlock; /* Protects irqqueue */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300433 struct list_head irqqueue;
434};
435
Laurent Pinchart8e113592009-07-01 20:24:47 -0300436struct uvc_video_chain {
437 struct uvc_device *dev;
438 struct list_head list;
439
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300440 struct list_head entities; /* All entities */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300441 struct uvc_entity *processing; /* Processing unit */
442 struct uvc_entity *selector; /* Selector unit */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300443
Laurent Pinchart27a61c12010-10-02 09:04:53 -0300444 struct mutex ctrl_mutex; /* Protects ctrl.info */
Laurent Pinchartf887e992012-08-28 18:38:58 -0300445
Laurent Pinchart05505132012-08-28 20:29:56 -0300446 struct v4l2_prio_state prio; /* V4L2 priority state */
Laurent Pinchartf887e992012-08-28 18:38:58 -0300447 u32 caps; /* V4L2 chain-wide caps */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300448};
449
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300450struct uvc_stats_frame {
451 unsigned int size; /* Number of bytes captured */
452 unsigned int first_data; /* Index of the first non-empty packet */
453
454 unsigned int nb_packets; /* Number of packets */
455 unsigned int nb_empty; /* Number of empty packets */
456 unsigned int nb_invalid; /* Number of packets with an invalid header */
457 unsigned int nb_errors; /* Number of packets with the error bit set */
Laurent Pinchart25738cb2011-11-03 12:30:17 -0300458
459 unsigned int nb_pts; /* Number of packets with a PTS timestamp */
460 unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */
461 unsigned int last_pts_diff; /* Index of the last PTS difference */
462 bool has_initial_pts; /* Whether the first non-empty packet has a PTS */
463 bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */
464 u32 pts; /* PTS of the last packet */
465
466 unsigned int nb_scr; /* Number of packets with a SCR timestamp */
467 unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */
468 u16 scr_sof; /* SCR.SOF of the last packet */
469 u32 scr_stc; /* SCR.STC of the last packet */
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300470};
471
472struct uvc_stats_stream {
Arnd Bergmanna70b8b22017-11-27 08:19:53 -0500473 ktime_t start_ts; /* Stream start timestamp */
474 ktime_t stop_ts; /* Stream stop timestamp */
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300475
476 unsigned int nb_frames; /* Number of frames */
477
478 unsigned int nb_packets; /* Number of packets */
479 unsigned int nb_empty; /* Number of empty packets */
480 unsigned int nb_invalid; /* Number of packets with an invalid header */
481 unsigned int nb_errors; /* Number of packets with the error bit set */
Laurent Pinchart25738cb2011-11-03 12:30:17 -0300482
483 unsigned int nb_pts_constant; /* Number of frames with constant PTS */
484 unsigned int nb_pts_early; /* Number of frames with early PTS */
485 unsigned int nb_pts_initial; /* Number of frames with initial PTS */
486
487 unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */
488 unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */
489 unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */
490 unsigned int scr_sof; /* STC.SOF of the last packet */
491 unsigned int min_sof; /* Minimum STC.SOF value */
492 unsigned int max_sof; /* Maximum STC.SOF value */
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300493};
494
Christophe JAILLETac7dabf2019-07-24 01:56:12 -0300495#define UVC_METADATA_BUF_SIZE 1024
Guennadi Liakhovetski088ead22017-12-06 10:15:40 -0500496
Kieran Bingham811496c2017-03-14 18:03:23 -0400497/**
Kieran Binghamb0121862017-03-22 05:42:52 -0400498 * struct uvc_copy_op: Context structure to schedule asynchronous memcpy
499 *
500 * @buf: active buf object for this operation
501 * @dst: copy destination address
502 * @src: copy source address
503 * @len: copy length
504 */
505struct uvc_copy_op {
506 struct uvc_buffer *buf;
507 void *dst;
508 const __u8 *src;
509 size_t len;
510};
511
512/**
Kieran Bingham811496c2017-03-14 18:03:23 -0400513 * struct uvc_urb - URB context management structure
514 *
515 * @urb: the URB described by this context structure
Kieran Binghamc6d664f2017-03-15 05:39:14 -0400516 * @stream: UVC streaming context
Kieran Bingham811496c2017-03-14 18:03:23 -0400517 * @buffer: memory storage for the URB
518 * @dma: DMA coherent addressing for the urb_buffer
Kieran Binghamb0121862017-03-22 05:42:52 -0400519 * @async_operations: counter to indicate the number of copy operations
520 * @copy_operations: work descriptors for asynchronous copy operations
521 * @work: work queue entry for asynchronous decode
Kieran Bingham811496c2017-03-14 18:03:23 -0400522 */
523struct uvc_urb {
524 struct urb *urb;
Kieran Binghamc6d664f2017-03-15 05:39:14 -0400525 struct uvc_streaming *stream;
Kieran Bingham811496c2017-03-14 18:03:23 -0400526
527 char *buffer;
528 dma_addr_t dma;
Kieran Binghamb0121862017-03-22 05:42:52 -0400529
530 unsigned int async_operations;
531 struct uvc_copy_op copy_operations[UVC_MAX_PACKETS];
532 struct work_struct work;
Kieran Bingham811496c2017-03-14 18:03:23 -0400533};
534
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300535struct uvc_streaming {
536 struct list_head list;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300537 struct uvc_device *dev;
Hans Verkuild8da7512015-03-09 13:34:11 -0300538 struct video_device vdev;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300539 struct uvc_video_chain *chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300540 atomic_t active;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300541
542 struct usb_interface *intf;
543 int intfnum;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500544 u16 maxpsize;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300545
546 struct uvc_streaming_header header;
547 enum v4l2_buf_type type;
548
549 unsigned int nformats;
550 struct uvc_format *format;
551
552 struct uvc_streaming_control ctrl;
Laurent Pinchart815adc42012-08-28 18:38:58 -0300553 struct uvc_format *def_format;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300554 struct uvc_format *cur_format;
555 struct uvc_frame *cur_frame;
Guennadi Liakhovetskie93e7fd2014-09-09 04:42:43 -0300556
Laurent Pinchart69477562010-11-21 13:36:34 -0300557 /* Protect access to ctrl, cur_format, cur_frame and hardware video
558 * probe control.
559 */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300560 struct mutex mutex;
561
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300562 /* Buffers queue. */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300563 unsigned int frozen : 1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300564 struct uvc_video_queue queue;
Kieran Binghamb0121862017-03-22 05:42:52 -0400565 struct workqueue_struct *async_wq;
Kieran Binghamc6d664f2017-03-15 05:39:14 -0400566 void (*decode)(struct uvc_urb *uvc_urb, struct uvc_buffer *buf,
567 struct uvc_buffer *meta_buf);
Guennadi Liakhovetski088ead22017-12-06 10:15:40 -0500568
569 struct {
570 struct video_device vdev;
571 struct uvc_video_queue queue;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500572 u32 format;
Guennadi Liakhovetski088ead22017-12-06 10:15:40 -0500573 } meta;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300574
575 /* Context data used by the bulk completion handler. */
576 struct {
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500577 u8 header[256];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300578 unsigned int header_size;
579 int skip_payload;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500580 u32 payload_size;
581 u32 max_payload_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300582 } bulk;
583
Kieran Bingham811496c2017-03-14 18:03:23 -0400584 struct uvc_urb uvc_urb[UVC_URBS];
Laurent Pincharte01117c2008-07-04 00:36:21 -0300585 unsigned int urb_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300586
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500587 u32 sequence;
588 u8 last_fid;
Alexey Fisheredbaa392011-11-03 09:39:37 -0300589
590 /* debugfs */
591 struct dentry *debugfs_dir;
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300592 struct {
593 struct uvc_stats_frame frame;
594 struct uvc_stats_stream stream;
595 } stats;
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300596
597 /* Timestamps support. */
598 struct uvc_clock {
599 struct uvc_clock_sample {
600 u32 dev_stc;
601 u16 dev_sof;
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300602 u16 host_sof;
Arnd Bergmann828ee8c2017-11-27 08:19:54 -0500603 ktime_t host_time;
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300604 } *samples;
605
606 unsigned int head;
607 unsigned int count;
608 unsigned int size;
609
610 u16 last_sof;
611 u16 sof_offset;
612
Guennadi Liakhovetski088ead22017-12-06 10:15:40 -0500613 u8 last_scr[6];
614
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300615 spinlock_t lock;
616 } clock;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300617};
618
Kieran Binghamb0121862017-03-22 05:42:52 -0400619#define for_each_uvc_urb(uvc_urb, uvc_streaming) \
620 for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \
621 (uvc_urb) < &(uvc_streaming)->uvc_urb[UVC_URBS]; \
622 ++(uvc_urb))
623
Hans Verkuil45602f72019-02-07 04:13:35 -0500624static inline u32 uvc_urb_index(const struct uvc_urb *uvc_urb)
625{
626 return uvc_urb - &uvc_urb->stream->uvc_urb[0];
627}
Kieran Bingham30eb9092018-01-27 18:43:01 -0500628
Laurent Pinchart3a032842018-08-17 04:50:02 -0400629struct uvc_device_info {
630 u32 quirks;
631 u32 meta_format;
632};
633
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300634struct uvc_device {
635 struct usb_device *udev;
636 struct usb_interface *intf;
Laurent Pinchart44f00792008-11-08 19:14:50 -0300637 unsigned long warnings;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500638 u32 quirks;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300639 int intfnum;
640 char name[32];
641
Laurent Pinchart3a032842018-08-17 04:50:02 -0400642 const struct uvc_device_info *info;
643
Laurent Pinchart17706f52013-04-25 22:28:51 -0300644 struct mutex lock; /* Protects users */
645 unsigned int users;
Martin Rubli8fb91b32010-09-08 04:15:23 -0300646 atomic_t nmappings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300647
648 /* Video control interface */
Laurent Pinchart5a254d72010-01-21 05:39:47 -0300649#ifdef CONFIG_MEDIA_CONTROLLER
650 struct media_device mdev;
651#endif
652 struct v4l2_device vdev;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500653 u16 uvc_version;
654 u32 clock_frequency;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300655
656 struct list_head entities;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300657 struct list_head chains;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300658
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300659 /* Video Streaming interfaces */
660 struct list_head streams;
Guennadi Liakhovetski9d15cd92017-08-08 08:56:23 -0400661 struct kref ref;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300662
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300663 /* Status Interrupt Endpoint */
664 struct usb_host_endpoint *int_ep;
665 struct urb *int_urb;
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500666 u8 *status;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300667 struct input_dev *input;
Laurent Pinchartf1801522009-01-22 12:45:10 -0300668 char input_phys[64];
Guennadi Liakhovetskie5225c82018-07-26 04:17:53 -0400669
670 struct uvc_ctrl_work {
671 struct work_struct work;
672 struct urb *urb;
673 struct uvc_video_chain *chain;
674 struct uvc_control *ctrl;
675 const void *data;
676 } async_ctrl;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300677};
678
679enum uvc_handle_state {
680 UVC_HANDLE_PASSIVE = 0,
681 UVC_HANDLE_ACTIVE = 1,
682};
683
684struct uvc_fh {
Hans de Goedeb4012002012-04-08 12:59:51 -0300685 struct v4l2_fh vfh;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300686 struct uvc_video_chain *chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300687 struct uvc_streaming *stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300688 enum uvc_handle_state state;
689};
690
691struct uvc_driver {
692 struct usb_driver driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300693};
694
695/* ------------------------------------------------------------------------
696 * Debugging, printing and logging
697 */
698
699#define UVC_TRACE_PROBE (1 << 0)
700#define UVC_TRACE_DESCR (1 << 1)
701#define UVC_TRACE_CONTROL (1 << 2)
702#define UVC_TRACE_FORMAT (1 << 3)
703#define UVC_TRACE_CAPTURE (1 << 4)
704#define UVC_TRACE_CALLS (1 << 5)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300705#define UVC_TRACE_FRAME (1 << 7)
706#define UVC_TRACE_SUSPEND (1 << 8)
707#define UVC_TRACE_STATUS (1 << 9)
Laurent Pinchart663a4192009-08-06 11:41:17 -0300708#define UVC_TRACE_VIDEO (1 << 10)
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300709#define UVC_TRACE_STATS (1 << 11)
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300710#define UVC_TRACE_CLOCK (1 << 12)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300711
Laurent Pinchart44f00792008-11-08 19:14:50 -0300712#define UVC_WARN_MINMAX 0
713#define UVC_WARN_PROBE_DEF 1
Laurent Pinchartc4d99f82010-09-30 09:04:03 -0300714#define UVC_WARN_XU_GET_RES 2
Laurent Pinchart44f00792008-11-08 19:14:50 -0300715
Laurent Pinchart310fe522009-12-09 22:57:48 -0300716extern unsigned int uvc_clock_param;
Laurent Pinchart0fbd8ee2008-12-06 16:25:14 -0300717extern unsigned int uvc_no_drop_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300718extern unsigned int uvc_trace_param;
Laurent Pinchartb232a012009-10-09 20:55:23 -0300719extern unsigned int uvc_timeout_param;
Laurent Pinchart5d0fd3c2015-07-27 11:06:48 -0300720extern unsigned int uvc_hw_timestamps_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300721
722#define uvc_trace(flag, msg...) \
723 do { \
724 if (uvc_trace_param & flag) \
725 printk(KERN_DEBUG "uvcvideo: " msg); \
726 } while (0)
727
Laurent Pinchart44f00792008-11-08 19:14:50 -0300728#define uvc_warn_once(dev, warn, msg...) \
729 do { \
730 if (!test_and_set_bit(warn, &dev->warnings)) \
731 printk(KERN_INFO "uvcvideo: " msg); \
732 } while (0)
733
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300734#define uvc_printk(level, msg...) \
735 printk(level "uvcvideo: " msg)
736
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300737/* --------------------------------------------------------------------------
738 * Internal functions.
739 */
740
741/* Core driver */
742extern struct uvc_driver uvc_driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300743
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500744struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300745
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300746/* Video buffers queue management. */
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500747int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
748 int drop_corrupted);
749void uvc_queue_release(struct uvc_video_queue *queue);
750int uvc_request_buffers(struct uvc_video_queue *queue,
751 struct v4l2_requestbuffers *rb);
752int uvc_query_buffer(struct uvc_video_queue *queue,
753 struct v4l2_buffer *v4l2_buf);
754int uvc_create_buffers(struct uvc_video_queue *queue,
755 struct v4l2_create_buffers *v4l2_cb);
756int uvc_queue_buffer(struct uvc_video_queue *queue,
Hans Verkuil394dc582018-05-30 02:46:22 -0400757 struct media_device *mdev,
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500758 struct v4l2_buffer *v4l2_buf);
759int uvc_export_buffer(struct uvc_video_queue *queue,
760 struct v4l2_exportbuffer *exp);
761int uvc_dequeue_buffer(struct uvc_video_queue *queue,
762 struct v4l2_buffer *v4l2_buf, int nonblocking);
763int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type);
764int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type);
765void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
766struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
767 struct uvc_buffer *buf);
Kieran Binghame829b262017-03-23 08:25:14 -0400768struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue);
Kieran Bingham01e90462017-03-16 09:33:05 -0400769void uvc_queue_buffer_release(struct uvc_buffer *buf);
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500770int uvc_queue_mmap(struct uvc_video_queue *queue,
771 struct vm_area_struct *vma);
772__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
773 poll_table *wait);
Bob Liu72969442011-04-29 07:11:35 -0300774#ifndef CONFIG_MMU
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500775unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
776 unsigned long pgoff);
Bob Liu72969442011-04-29 07:11:35 -0300777#endif
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500778int uvc_queue_allocated(struct uvc_video_queue *queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300779static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
780{
Laurent Pinchart6998b6f2011-10-24 11:53:59 -0300781 return vb2_is_streaming(&queue->queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300782}
783
784/* V4L2 interface */
Laurent Pinchartd5e90b72010-09-30 10:17:54 -0300785extern const struct v4l2_ioctl_ops uvc_ioctl_ops;
Hans Verkuilbec43662008-12-30 06:58:20 -0300786extern const struct v4l2_file_operations uvc_fops;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300787
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300788/* Media controller */
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500789int uvc_mc_register_entities(struct uvc_video_chain *chain);
790void uvc_mc_cleanup_entity(struct uvc_entity *entity);
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300791
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300792/* Video */
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500793int uvc_video_init(struct uvc_streaming *stream);
794int uvc_video_suspend(struct uvc_streaming *stream);
795int uvc_video_resume(struct uvc_streaming *stream, int reset);
Kieran Bingham571e70d2018-11-05 10:28:24 -0500796int uvc_video_start_streaming(struct uvc_streaming *stream);
797void uvc_video_stop_streaming(struct uvc_streaming *stream);
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500798int uvc_probe_video(struct uvc_streaming *stream,
799 struct uvc_streaming_control *probe);
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500800int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
801 u8 intfnum, u8 cs, void *data, u16 size);
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300802void uvc_video_clock_update(struct uvc_streaming *stream,
Junghak Sung2d700712015-09-22 10:30:30 -0300803 struct vb2_v4l2_buffer *vbuf,
Laurent Pinchart66847ef2011-09-24 10:46:55 -0300804 struct uvc_buffer *buf);
Guennadi Liakhovetski088ead22017-12-06 10:15:40 -0500805int uvc_meta_register(struct uvc_streaming *stream);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300806
Laurent Pinchart31a96f42017-12-04 18:05:17 -0500807int uvc_register_video_device(struct uvc_device *dev,
808 struct uvc_streaming *stream,
809 struct video_device *vdev,
810 struct uvc_video_queue *queue,
811 enum v4l2_buf_type type,
812 const struct v4l2_file_operations *fops,
813 const struct v4l2_ioctl_ops *ioctl_ops);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300814
815/* Status */
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500816int uvc_status_init(struct uvc_device *dev);
Daniel Axtens10e1fdb2017-04-23 00:53:49 -0400817void uvc_status_unregister(struct uvc_device *dev);
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500818void uvc_status_cleanup(struct uvc_device *dev);
819int uvc_status_start(struct uvc_device *dev, gfp_t flags);
820void uvc_status_stop(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300821
822/* Controls */
Hans de Goedeb4012002012-04-08 12:59:51 -0300823extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
824
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500825int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
826 struct v4l2_queryctrl *v4l2_ctrl);
827int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
828 struct v4l2_querymenu *query_menu);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300829
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500830int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
831 const struct uvc_control_mapping *mapping);
832int uvc_ctrl_init_device(struct uvc_device *dev);
833void uvc_ctrl_cleanup_device(struct uvc_device *dev);
834int uvc_ctrl_restore_values(struct uvc_device *dev);
Guennadi Liakhovetskie5225c82018-07-26 04:17:53 -0400835bool uvc_ctrl_status_event(struct urb *urb, struct uvc_video_chain *chain,
836 struct uvc_control *ctrl, const u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300837
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500838int uvc_ctrl_begin(struct uvc_video_chain *chain);
839int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
840 const struct v4l2_ext_control *xctrls,
841 unsigned int xctrls_count);
Hans de Goedeb4012002012-04-08 12:59:51 -0300842static inline int uvc_ctrl_commit(struct uvc_fh *handle,
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500843 const struct v4l2_ext_control *xctrls,
844 unsigned int xctrls_count)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300845{
Hans de Goedeb4012002012-04-08 12:59:51 -0300846 return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300847}
Hans de Goedeb4012002012-04-08 12:59:51 -0300848static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300849{
Hans de Goedeb4012002012-04-08 12:59:51 -0300850 return __uvc_ctrl_commit(handle, 1, NULL, 0);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300851}
852
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500853int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl);
Guennadi Liakhovetskie5225c82018-07-26 04:17:53 -0400854int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300855
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500856int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
857 struct uvc_xu_control_query *xqry);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300858
859/* Utility functions */
Laurent Pinchart1e304c42018-01-16 12:35:17 -0500860void uvc_simplify_fraction(u32 *numerator, u32 *denominator,
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500861 unsigned int n_terms, unsigned int threshold);
Laurent Pinchart1e304c42018-01-16 12:35:17 -0500862u32 uvc_fraction_to_interval(u32 numerator, u32 denominator);
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500863struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
Laurent Pinchart2c6b2222018-01-16 12:45:36 -0500864 u8 epaddr);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300865
866/* Quirks support */
Kieran Binghamc6d664f2017-03-15 05:39:14 -0400867void uvc_video_decode_isight(struct uvc_urb *uvc_urb,
Laurent Pinchartcb9cd6c2018-01-16 12:32:54 -0500868 struct uvc_buffer *buf,
869 struct uvc_buffer *meta_buf);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300870
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300871/* debugfs and statistics */
Jaejoong Kim39dc3aa2017-01-11 23:31:21 -0200872void uvc_debugfs_init(void);
Alexey Fisheredbaa392011-11-03 09:39:37 -0300873void uvc_debugfs_cleanup(void);
Jaejoong Kim39dc3aa2017-01-11 23:31:21 -0200874void uvc_debugfs_init_stream(struct uvc_streaming *stream);
Alexey Fisheredbaa392011-11-03 09:39:37 -0300875void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream);
876
Alexey Fisher7bc5edb2011-11-03 11:40:08 -0300877size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf,
878 size_t size);
879
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300880#endif