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