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