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