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