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