]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/usb/uvc/uvcvideo.h
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / media / usb / uvc / uvcvideo.h
CommitLineData
c0efd232
LP
1#ifndef _USB_VIDEO_H_
2#define _USB_VIDEO_H_
3
5f708812 4#ifndef __KERNEL__
227bd5b3
LP
5#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
6#endif /* __KERNEL__ */
c0efd232 7
227bd5b3 8#include <linux/kernel.h>
c0efd232 9#include <linux/poll.h>
4ffc2d89 10#include <linux/usb.h>
de05f634 11#include <linux/usb/video.h>
5f708812 12#include <linux/uvcvideo.h>
227bd5b3 13#include <linux/videodev2.h>
5a254d75
LP
14#include <media/media-device.h>
15#include <media/v4l2-device.h>
b4012002
HG
16#include <media/v4l2-event.h>
17#include <media/v4l2-fh.h>
c139990e 18#include <media/videobuf2-v4l2.h>
c0efd232
LP
19
20/* --------------------------------------------------------------------------
21 * UVC constants
22 */
23
c0efd232
LP
24#define UVC_TERM_INPUT 0x0000
25#define UVC_TERM_OUTPUT 0x8000
6241d8ca 26#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
c0efd232
LP
27
28#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
29#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
30#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
31#define UVC_ENTITY_IS_ITERM(entity) \
8e113595
LP
32 (UVC_ENTITY_IS_TERM(entity) && \
33 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
c0efd232 34#define UVC_ENTITY_IS_OTERM(entity) \
8e113595
LP
35 (UVC_ENTITY_IS_TERM(entity) && \
36 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
c0efd232 37
c0efd232
LP
38
39/* ------------------------------------------------------------------------
40 * GUIDs
41 */
42#define UVC_GUID_UVC_CAMERA \
43 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
45#define UVC_GUID_UVC_OUTPUT \
46 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
48#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
49 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
51#define UVC_GUID_UVC_PROCESSING \
52 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
54#define UVC_GUID_UVC_SELECTOR \
55 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
57
c0efd232
LP
58#define UVC_GUID_FORMAT_MJPEG \
59 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
60 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
61#define UVC_GUID_FORMAT_YUY2 \
62 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
63 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
68f194e0
DR
64#define UVC_GUID_FORMAT_YUY2_ISIGHT \
65 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
66 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
c0efd232
LP
67#define UVC_GUID_FORMAT_NV12 \
68 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
69 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
70#define UVC_GUID_FORMAT_YV12 \
71 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
72 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
73#define UVC_GUID_FORMAT_I420 \
74 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
75 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
76#define UVC_GUID_FORMAT_UYVY \
77 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
78 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
79#define UVC_GUID_FORMAT_Y800 \
80 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
ca47e719
SM
81 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
82#define UVC_GUID_FORMAT_Y8 \
83 { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \
84 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
85#define UVC_GUID_FORMAT_Y10 \
86 { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \
87 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
88#define UVC_GUID_FORMAT_Y12 \
89 { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \
c0efd232 90 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
61421206
LP
91#define UVC_GUID_FORMAT_Y16 \
92 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
93 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
c0efd232
LP
94#define UVC_GUID_FORMAT_BY8 \
95 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
96 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
e72ed08e
ET
97#define UVC_GUID_FORMAT_BA81 \
98 { 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \
99 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
100#define UVC_GUID_FORMAT_GBRG \
101 { 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \
102 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
103#define UVC_GUID_FORMAT_GRBG \
104 { 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \
105 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
106#define UVC_GUID_FORMAT_RGGB \
107 { 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \
108 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
eb165a20
ET
109#define UVC_GUID_FORMAT_BG16 \
110 { 'B', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \
111 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
112#define UVC_GUID_FORMAT_GB16 \
113 { 'G', 'B', '1', '6', 0x00, 0x00, 0x10, 0x00, \
114 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
115#define UVC_GUID_FORMAT_RG16 \
116 { 'R', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \
117 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
118#define UVC_GUID_FORMAT_GR16 \
119 { 'G', 'R', '1', '6', 0x00, 0x00, 0x10, 0x00, \
120 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
50791079
LP
121#define UVC_GUID_FORMAT_RGBP \
122 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
123 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
1b8dc322
WM
124#define UVC_GUID_FORMAT_BGR3 \
125 { 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \
126 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}
7225a1dc
HG
127#define UVC_GUID_FORMAT_M420 \
128 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
129 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
c0efd232 130
25ad8a8d
SL
131#define UVC_GUID_FORMAT_H264 \
132 { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \
133 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
5d8d8db8
AG
134#define UVC_GUID_FORMAT_Y8I \
135 { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \
136 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
137#define UVC_GUID_FORMAT_Y12I \
138 { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \
139 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
140#define UVC_GUID_FORMAT_Z16 \
141 { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
142 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
143#define UVC_GUID_FORMAT_RW10 \
144 { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \
145 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
25ad8a8d 146
c0efd232
LP
147/* ------------------------------------------------------------------------
148 * Driver specific constants.
149 */
150
fd3e5824 151#define DRIVER_VERSION "1.1.1"
c0efd232
LP
152
153/* Number of isochronous URBs. */
154#define UVC_URBS 5
efdc8a95
LP
155/* Maximum number of packets per URB. */
156#define UVC_MAX_PACKETS 32
a31a4055
ML
157/* Maximum status buffer size in bytes of interrupt URB. */
158#define UVC_MAX_STATUS_SIZE 16
c0efd232
LP
159
160#define UVC_CTRL_CONTROL_TIMEOUT 300
56d15cd3 161#define UVC_CTRL_STREAMING_TIMEOUT 5000
c0efd232 162
8fb91b33
MR
163/* Maximum allowed number of control mappings per device */
164#define UVC_MAX_CONTROL_MAPPINGS 1024
806e23e9 165#define UVC_MAX_CONTROL_MENU_ENTRIES 32
8fb91b33 166
c0efd232
LP
167/* Devices quirks */
168#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
169#define UVC_QUIRK_PROBE_MINMAX 0x00000002
170#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
171#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
172#define UVC_QUIRK_STREAM_NO_FID 0x00000010
173#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
50144aee 174#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
bab6f66c 175#define UVC_QUIRK_PROBE_DEF 0x00000100
86d8b6ab 176#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
17e1319f 177#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400
e1b78a33 178#define UVC_QUIRK_FORCE_Y8 0x00000800
c0efd232
LP
179
180/* Format flags */
181#define UVC_FMT_FLAG_COMPRESSED 0x00000001
182#define UVC_FMT_FLAG_STREAM 0x00000002
183
184/* ------------------------------------------------------------------------
185 * Structures.
186 */
187
188struct uvc_device;
189
190/* TODO: Put the most frequently accessed fields at the beginning of
191 * structures to maximize cache efficiency.
192 */
c0efd232 193struct uvc_control_info {
c0efd232
LP
194 struct list_head mappings;
195
196 __u8 entity[16];
ba2fa996 197 __u8 index; /* Bit index in bmControls */
c0efd232
LP
198 __u8 selector;
199
200 __u16 size;
201 __u32 flags;
202};
203
204struct uvc_control_mapping {
205 struct list_head list;
b4012002 206 struct list_head ev_subs;
c0efd232 207
c0efd232
LP
208 __u32 id;
209 __u8 name[32];
210 __u8 entity[16];
211 __u8 selector;
212
213 __u8 size;
214 __u8 offset;
215 enum v4l2_ctrl_type v4l2_type;
216 __u32 data_type;
217
218 struct uvc_menu_info *menu_info;
219 __u32 menu_count;
9768352a 220
55afeb8a
HG
221 __u32 master_id;
222 __s32 master_manual;
223 __u32 slave_ids[2];
224
9768352a
LP
225 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
226 const __u8 *data);
227 void (*set) (struct uvc_control_mapping *mapping, __s32 value,
228 __u8 *data);
c0efd232
LP
229};
230
231struct uvc_control {
232 struct uvc_entity *entity;
071c8bb8 233 struct uvc_control_info info;
c0efd232
LP
234
235 __u8 index; /* Used to match the uvc_control entry with a
236 uvc_control_info. */
071c8bb8
LP
237 __u8 dirty:1,
238 loaded:1,
239 modified:1,
240 cached:1,
241 initialized:1;
c0efd232 242
b30ece53 243 __u8 *uvc_data;
c0efd232
LP
244};
245
246struct uvc_format_desc {
247 char *name;
248 __u8 guid[16];
249 __u32 fcc;
250};
251
252/* The term 'entity' refers to both UVC units and UVC terminals.
253 *
254 * The type field is either the terminal type (wTerminalType in the terminal
255 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
256 * As the bDescriptorSubtype field is one byte long, the type value will
257 * always have a null MSB for units. All terminal types defined by the UVC
258 * specification have a non-null MSB, so it is safe to use the MSB to
259 * differentiate between units and terminals as long as the descriptor parsing
260 * code makes sure terminal types have a non-null MSB.
261 *
262 * For terminals, the type's most significant bit stores the terminal
263 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
264 * always be accessed with the UVC_ENTITY_* macros and never directly.
265 */
266
8be8ec6e
LP
267#define UVC_ENTITY_FLAG_DEFAULT (1 << 0)
268
c0efd232
LP
269struct uvc_entity {
270 struct list_head list; /* Entity as part of a UVC device. */
271 struct list_head chain; /* Entity as part of a video device
272 * chain. */
8be8ec6e
LP
273 unsigned int flags;
274
c0efd232
LP
275 __u8 id;
276 __u16 type;
277 char name[64];
278
4ffc2d89 279 /* Media controller-related fields. */
8a65a948 280 struct video_device *vdev;
4ffc2d89
LP
281 struct v4l2_subdev subdev;
282 unsigned int num_pads;
283 unsigned int num_links;
284 struct media_pad *pads;
285
c0efd232
LP
286 union {
287 struct {
288 __u16 wObjectiveFocalLengthMin;
289 __u16 wObjectiveFocalLengthMax;
290 __u16 wOcularFocalLength;
291 __u8 bControlSize;
292 __u8 *bmControls;
293 } camera;
294
295 struct {
296 __u8 bControlSize;
297 __u8 *bmControls;
298 __u8 bTransportModeSize;
299 __u8 *bmTransportModes;
300 } media;
301
302 struct {
c0efd232
LP
303 } output;
304
305 struct {
c0efd232
LP
306 __u16 wMaxMultiplier;
307 __u8 bControlSize;
308 __u8 *bmControls;
309 __u8 bmVideoStandards;
310 } processing;
311
312 struct {
c0efd232
LP
313 } selector;
314
315 struct {
316 __u8 guidExtensionCode[16];
317 __u8 bNumControls;
c0efd232
LP
318 __u8 bControlSize;
319 __u8 *bmControls;
320 __u8 *bmControlsType;
321 } extension;
322 };
323
8ca5a639
LP
324 __u8 bNrInPins;
325 __u8 *baSourceID;
326
c0efd232
LP
327 unsigned int ncontrols;
328 struct uvc_control *controls;
329};
330
331struct uvc_frame {
332 __u8 bFrameIndex;
333 __u8 bmCapabilities;
334 __u16 wWidth;
335 __u16 wHeight;
336 __u32 dwMinBitRate;
337 __u32 dwMaxBitRate;
338 __u32 dwMaxVideoFrameBufferSize;
339 __u8 bFrameIntervalType;
340 __u32 dwDefaultFrameInterval;
341 __u32 *dwFrameInterval;
342};
343
344struct uvc_format {
345 __u8 type;
346 __u8 index;
347 __u8 bpp;
348 __u8 colorspace;
349 __u32 fcc;
350 __u32 flags;
351
352 char name[32];
353
354 unsigned int nframes;
355 struct uvc_frame *frame;
356};
357
358struct uvc_streaming_header {
359 __u8 bNumFormats;
360 __u8 bEndpointAddress;
361 __u8 bTerminalLink;
362 __u8 bControlSize;
363 __u8 *bmaControls;
364 /* The following fields are used by input headers only. */
365 __u8 bmInfo;
366 __u8 bStillCaptureMethod;
367 __u8 bTriggerSupport;
368 __u8 bTriggerUsage;
369};
370
c0efd232 371enum uvc_buffer_state {
2c2d264b
LP
372 UVC_BUF_STATE_IDLE = 0,
373 UVC_BUF_STATE_QUEUED = 1,
374 UVC_BUF_STATE_ACTIVE = 2,
d7c0d439
LP
375 UVC_BUF_STATE_READY = 3,
376 UVC_BUF_STATE_DONE = 4,
377 UVC_BUF_STATE_ERROR = 5,
c0efd232
LP
378};
379
380struct uvc_buffer {
2d700715 381 struct vb2_v4l2_buffer buf;
c0efd232 382 struct list_head queue;
6998b6fb 383
c0efd232 384 enum uvc_buffer_state state;
9bde9f26 385 unsigned int error;
3d95e932
LP
386
387 void *mem;
388 unsigned int length;
389 unsigned int bytesused;
66847ef0
LP
390
391 u32 pts;
c0efd232
LP
392};
393
6998b6fb
LP
394#define UVC_QUEUE_DISCONNECTED (1 << 0)
395#define UVC_QUEUE_DROP_CORRUPTED (1 << 1)
c0efd232
LP
396
397struct uvc_video_queue {
6998b6fb
LP
398 struct vb2_queue queue;
399 struct mutex mutex; /* Protects queue */
ff924203 400
c0efd232 401 unsigned int flags;
ff924203 402 unsigned int buf_used;
c0efd232 403
6998b6fb 404 spinlock_t irqlock; /* Protects irqqueue */
c0efd232
LP
405 struct list_head irqqueue;
406};
407
8e113595
LP
408struct uvc_video_chain {
409 struct uvc_device *dev;
410 struct list_head list;
411
6241d8ca 412 struct list_head entities; /* All entities */
8e113595
LP
413 struct uvc_entity *processing; /* Processing unit */
414 struct uvc_entity *selector; /* Selector unit */
8e113595 415
27a61c13 416 struct mutex ctrl_mutex; /* Protects ctrl.info */
f887e99a 417
0550513c 418 struct v4l2_prio_state prio; /* V4L2 priority state */
f887e99a 419 u32 caps; /* V4L2 chain-wide caps */
8e113595
LP
420};
421
7bc5edb0
AF
422struct uvc_stats_frame {
423 unsigned int size; /* Number of bytes captured */
424 unsigned int first_data; /* Index of the first non-empty packet */
425
426 unsigned int nb_packets; /* Number of packets */
427 unsigned int nb_empty; /* Number of empty packets */
428 unsigned int nb_invalid; /* Number of packets with an invalid header */
429 unsigned int nb_errors; /* Number of packets with the error bit set */
25738cbd
LP
430
431 unsigned int nb_pts; /* Number of packets with a PTS timestamp */
432 unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */
433 unsigned int last_pts_diff; /* Index of the last PTS difference */
434 bool has_initial_pts; /* Whether the first non-empty packet has a PTS */
435 bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */
436 u32 pts; /* PTS of the last packet */
437
438 unsigned int nb_scr; /* Number of packets with a SCR timestamp */
439 unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */
440 u16 scr_sof; /* SCR.SOF of the last packet */
441 u32 scr_stc; /* SCR.STC of the last packet */
7bc5edb0
AF
442};
443
444struct uvc_stats_stream {
445 struct timespec start_ts; /* Stream start timestamp */
446 struct timespec stop_ts; /* Stream stop timestamp */
447
448 unsigned int nb_frames; /* Number of frames */
449
450 unsigned int nb_packets; /* Number of packets */
451 unsigned int nb_empty; /* Number of empty packets */
452 unsigned int nb_invalid; /* Number of packets with an invalid header */
453 unsigned int nb_errors; /* Number of packets with the error bit set */
25738cbd
LP
454
455 unsigned int nb_pts_constant; /* Number of frames with constant PTS */
456 unsigned int nb_pts_early; /* Number of frames with early PTS */
457 unsigned int nb_pts_initial; /* Number of frames with initial PTS */
458
459 unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */
460 unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */
461 unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */
462 unsigned int scr_sof; /* STC.SOF of the last packet */
463 unsigned int min_sof; /* Minimum STC.SOF value */
464 unsigned int max_sof; /* Maximum STC.SOF value */
7bc5edb0
AF
465};
466
35f02a68
LP
467struct uvc_streaming {
468 struct list_head list;
c0efd232 469 struct uvc_device *dev;
d8da7513 470 struct video_device vdev;
8e113595 471 struct uvc_video_chain *chain;
c0efd232 472 atomic_t active;
c0efd232 473
35f02a68
LP
474 struct usb_interface *intf;
475 int intfnum;
476 __u16 maxpsize;
c0efd232 477
35f02a68
LP
478 struct uvc_streaming_header header;
479 enum v4l2_buf_type type;
480
481 unsigned int nformats;
482 struct uvc_format *format;
c0efd232 483
35f02a68 484 struct uvc_streaming_control ctrl;
815adc46 485 struct uvc_format *def_format;
35f02a68
LP
486 struct uvc_format *cur_format;
487 struct uvc_frame *cur_frame;
e93e7fd9 488
6947756d
LP
489 /* Protect access to ctrl, cur_format, cur_frame and hardware video
490 * probe control.
491 */
35f02a68 492 struct mutex mutex;
c0efd232 493
6998b6fb 494 /* Buffers queue. */
35f02a68
LP
495 unsigned int frozen : 1;
496 struct uvc_video_queue queue;
497 void (*decode) (struct urb *urb, struct uvc_streaming *video,
c0efd232
LP
498 struct uvc_buffer *buf);
499
500 /* Context data used by the bulk completion handler. */
501 struct {
502 __u8 header[256];
503 unsigned int header_size;
504 int skip_payload;
505 __u32 payload_size;
506 __u32 max_payload_size;
507 } bulk;
508
509 struct urb *urb[UVC_URBS];
510 char *urb_buffer[UVC_URBS];
e01117c8
LP
511 dma_addr_t urb_dma[UVC_URBS];
512 unsigned int urb_size;
c0efd232 513
650b95fe 514 __u32 sequence;
c0efd232 515 __u8 last_fid;
edbaa398
AF
516
517 /* debugfs */
518 struct dentry *debugfs_dir;
7bc5edb0
AF
519 struct {
520 struct uvc_stats_frame frame;
521 struct uvc_stats_stream stream;
522 } stats;
66847ef0
LP
523
524 /* Timestamps support. */
525 struct uvc_clock {
526 struct uvc_clock_sample {
527 u32 dev_stc;
528 u16 dev_sof;
529 struct timespec host_ts;
530 u16 host_sof;
531 } *samples;
532
533 unsigned int head;
534 unsigned int count;
535 unsigned int size;
536
537 u16 last_sof;
538 u16 sof_offset;
539
540 spinlock_t lock;
541 } clock;
c0efd232
LP
542};
543
c0efd232
LP
544struct uvc_device {
545 struct usb_device *udev;
546 struct usb_interface *intf;
44f0079e 547 unsigned long warnings;
c0efd232
LP
548 __u32 quirks;
549 int intfnum;
550 char name[32];
551
17706f56
LP
552 struct mutex lock; /* Protects users */
553 unsigned int users;
8fb91b33 554 atomic_t nmappings;
c0efd232
LP
555
556 /* Video control interface */
5a254d75
LP
557#ifdef CONFIG_MEDIA_CONTROLLER
558 struct media_device mdev;
559#endif
560 struct v4l2_device vdev;
c0efd232
LP
561 __u16 uvc_version;
562 __u32 clock_frequency;
563
564 struct list_head entities;
8e113595 565 struct list_head chains;
c0efd232 566
35f02a68
LP
567 /* Video Streaming interfaces */
568 struct list_head streams;
716fdee1 569 atomic_t nstreams;
35f02a68 570
c0efd232
LP
571 /* Status Interrupt Endpoint */
572 struct usb_host_endpoint *int_ep;
573 struct urb *int_urb;
a31a4055 574 __u8 *status;
c0efd232 575 struct input_dev *input;
f1801523 576 char input_phys[64];
c0efd232
LP
577};
578
579enum uvc_handle_state {
580 UVC_HANDLE_PASSIVE = 0,
581 UVC_HANDLE_ACTIVE = 1,
582};
583
584struct uvc_fh {
b4012002 585 struct v4l2_fh vfh;
8e113595 586 struct uvc_video_chain *chain;
35f02a68 587 struct uvc_streaming *stream;
c0efd232
LP
588 enum uvc_handle_state state;
589};
590
591struct uvc_driver {
592 struct usb_driver driver;
c0efd232
LP
593};
594
595/* ------------------------------------------------------------------------
596 * Debugging, printing and logging
597 */
598
599#define UVC_TRACE_PROBE (1 << 0)
600#define UVC_TRACE_DESCR (1 << 1)
601#define UVC_TRACE_CONTROL (1 << 2)
602#define UVC_TRACE_FORMAT (1 << 3)
603#define UVC_TRACE_CAPTURE (1 << 4)
604#define UVC_TRACE_CALLS (1 << 5)
c0efd232
LP
605#define UVC_TRACE_FRAME (1 << 7)
606#define UVC_TRACE_SUSPEND (1 << 8)
607#define UVC_TRACE_STATUS (1 << 9)
663a4192 608#define UVC_TRACE_VIDEO (1 << 10)
7bc5edb0 609#define UVC_TRACE_STATS (1 << 11)
66847ef0 610#define UVC_TRACE_CLOCK (1 << 12)
c0efd232 611
44f0079e
LP
612#define UVC_WARN_MINMAX 0
613#define UVC_WARN_PROBE_DEF 1
c4d99f89 614#define UVC_WARN_XU_GET_RES 2
44f0079e 615
310fe524 616extern unsigned int uvc_clock_param;
0fbd8ee6 617extern unsigned int uvc_no_drop_param;
c0efd232 618extern unsigned int uvc_trace_param;
b232a012 619extern unsigned int uvc_timeout_param;
5d0fd3c8 620extern unsigned int uvc_hw_timestamps_param;
c0efd232
LP
621
622#define uvc_trace(flag, msg...) \
623 do { \
624 if (uvc_trace_param & flag) \
625 printk(KERN_DEBUG "uvcvideo: " msg); \
626 } while (0)
627
44f0079e
LP
628#define uvc_warn_once(dev, warn, msg...) \
629 do { \
630 if (!test_and_set_bit(warn, &dev->warnings)) \
631 printk(KERN_INFO "uvcvideo: " msg); \
632 } while (0)
633
c0efd232
LP
634#define uvc_printk(level, msg...) \
635 printk(level "uvcvideo: " msg)
636
c0efd232
LP
637/* --------------------------------------------------------------------------
638 * Internal functions.
639 */
640
641/* Core driver */
642extern struct uvc_driver uvc_driver;
c0efd232 643
4ffc2d89
LP
644extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
645
c0efd232 646/* Video buffers queue management. */
5712661d 647extern int uvc_queue_init(struct uvc_video_queue *queue,
9bde9f26 648 enum v4l2_buf_type type, int drop_corrupted);
3f02de27 649extern void uvc_queue_release(struct uvc_video_queue *queue);
1b7f9c98 650extern int uvc_request_buffers(struct uvc_video_queue *queue,
6998b6fb 651 struct v4l2_requestbuffers *rb);
c0efd232
LP
652extern int uvc_query_buffer(struct uvc_video_queue *queue,
653 struct v4l2_buffer *v4l2_buf);
6e9179e2
PZ
654extern int uvc_create_buffers(struct uvc_video_queue *queue,
655 struct v4l2_create_buffers *v4l2_cb);
c0efd232
LP
656extern int uvc_queue_buffer(struct uvc_video_queue *queue,
657 struct v4l2_buffer *v4l2_buf);
7195f61b
LP
658extern int uvc_export_buffer(struct uvc_video_queue *queue,
659 struct v4l2_exportbuffer *exp);
c0efd232
LP
660extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
661 struct v4l2_buffer *v4l2_buf, int nonblocking);
0da4ab98
LP
662extern int uvc_queue_streamon(struct uvc_video_queue *queue,
663 enum v4l2_buf_type type);
664extern int uvc_queue_streamoff(struct uvc_video_queue *queue,
665 enum v4l2_buf_type type);
c0efd232
LP
666extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
667extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
668 struct uvc_buffer *buf);
4aa27597
LP
669extern int uvc_queue_mmap(struct uvc_video_queue *queue,
670 struct vm_area_struct *vma);
c0efd232
LP
671extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
672 struct file *file, poll_table *wait);
72969447
BL
673#ifndef CONFIG_MMU
674extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
675 unsigned long pgoff);
676#endif
23ff6043 677extern int uvc_queue_allocated(struct uvc_video_queue *queue);
c0efd232
LP
678static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
679{
6998b6fb 680 return vb2_is_streaming(&queue->queue);
c0efd232
LP
681}
682
683/* V4L2 interface */
d5e90b7a 684extern const struct v4l2_ioctl_ops uvc_ioctl_ops;
bec43661 685extern const struct v4l2_file_operations uvc_fops;
c0efd232 686
4ffc2d89
LP
687/* Media controller */
688extern int uvc_mc_register_entities(struct uvc_video_chain *chain);
689extern void uvc_mc_cleanup_entity(struct uvc_entity *entity);
690
c0efd232 691/* Video */
35f02a68
LP
692extern int uvc_video_init(struct uvc_streaming *stream);
693extern int uvc_video_suspend(struct uvc_streaming *stream);
d59a7b1d 694extern int uvc_video_resume(struct uvc_streaming *stream, int reset);
35f02a68
LP
695extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
696extern int uvc_probe_video(struct uvc_streaming *stream,
c0efd232
LP
697 struct uvc_streaming_control *probe);
698extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
699 __u8 intfnum, __u8 cs, void *data, __u16 size);
66847ef0 700void uvc_video_clock_update(struct uvc_streaming *stream,
2d700715 701 struct vb2_v4l2_buffer *vbuf,
66847ef0 702 struct uvc_buffer *buf);
c0efd232
LP
703
704/* Status */
705extern int uvc_status_init(struct uvc_device *dev);
706extern void uvc_status_cleanup(struct uvc_device *dev);
17706f56 707extern int uvc_status_start(struct uvc_device *dev, gfp_t flags);
04a37e0f 708extern void uvc_status_stop(struct uvc_device *dev);
c0efd232
LP
709
710/* Controls */
b4012002
HG
711extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
712
8e113595 713extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
c0efd232 714 struct v4l2_queryctrl *v4l2_ctrl);
23d9f3ef
LP
715extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
716 struct v4l2_querymenu *query_menu);
c0efd232 717
ba2fa996
LP
718extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
719 const struct uvc_control_mapping *mapping);
c0efd232
LP
720extern int uvc_ctrl_init_device(struct uvc_device *dev);
721extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
17e1319f 722extern int uvc_ctrl_restore_values(struct uvc_device *dev);
c0efd232 723
8e113595 724extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
b4012002
HG
725extern int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
726 const struct v4l2_ext_control *xctrls,
727 unsigned int xctrls_count);
728static inline int uvc_ctrl_commit(struct uvc_fh *handle,
729 const struct v4l2_ext_control *xctrls,
730 unsigned int xctrls_count)
c0efd232 731{
b4012002 732 return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count);
c0efd232 733}
b4012002 734static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
c0efd232 735{
b4012002 736 return __uvc_ctrl_commit(handle, 1, NULL, 0);
c0efd232
LP
737}
738
8e113595 739extern int uvc_ctrl_get(struct uvc_video_chain *chain,
c0efd232 740 struct v4l2_ext_control *xctrl);
8e113595 741extern int uvc_ctrl_set(struct uvc_video_chain *chain,
c0efd232
LP
742 struct v4l2_ext_control *xctrl);
743
8e113595 744extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
fe78d187 745 struct uvc_xu_control_query *xqry);
c0efd232
LP
746
747/* Utility functions */
748extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
749 unsigned int n_terms, unsigned int threshold);
750extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
751 uint32_t denominator);
752extern struct usb_host_endpoint *uvc_find_endpoint(
753 struct usb_host_interface *alts, __u8 epaddr);
754
755/* Quirks support */
35f02a68 756void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
c0efd232
LP
757 struct uvc_buffer *buf);
758
7bc5edb0 759/* debugfs and statistics */
39dc3aae 760void uvc_debugfs_init(void);
edbaa398 761void uvc_debugfs_cleanup(void);
39dc3aae 762void uvc_debugfs_init_stream(struct uvc_streaming *stream);
edbaa398
AF
763void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream);
764
7bc5edb0
AF
765size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf,
766 size_t size);
767
c0efd232 768#endif