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