USB: g_ffs: the FunctionFS gadget driver
[linux-2.6/libata-dev.git] / drivers / usb / gadget / uvc_queue.h
blob7f5a33fe7ae212a0f68a20a98ffb31c4c9d0dd47
1 #ifndef _UVC_QUEUE_H_
2 #define _UVC_QUEUE_H_
4 #ifdef __KERNEL__
6 #include <linux/kernel.h>
7 #include <linux/poll.h>
8 #include <linux/videodev2.h>
10 /* Maximum frame size in bytes, for sanity checking. */
11 #define UVC_MAX_FRAME_SIZE (16*1024*1024)
12 /* Maximum number of video buffers. */
13 #define UVC_MAX_VIDEO_BUFFERS 32
15 /* ------------------------------------------------------------------------
16 * Structures.
19 enum uvc_buffer_state {
20 UVC_BUF_STATE_IDLE = 0,
21 UVC_BUF_STATE_QUEUED = 1,
22 UVC_BUF_STATE_ACTIVE = 2,
23 UVC_BUF_STATE_DONE = 3,
24 UVC_BUF_STATE_ERROR = 4,
27 struct uvc_buffer {
28 unsigned long vma_use_count;
29 struct list_head stream;
31 /* Touched by interrupt handler. */
32 struct v4l2_buffer buf;
33 struct list_head queue;
34 wait_queue_head_t wait;
35 enum uvc_buffer_state state;
38 #define UVC_QUEUE_STREAMING (1 << 0)
39 #define UVC_QUEUE_DISCONNECTED (1 << 1)
40 #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
41 #define UVC_QUEUE_PAUSED (1 << 3)
43 struct uvc_video_queue {
44 enum v4l2_buf_type type;
46 void *mem;
47 unsigned int flags;
48 __u32 sequence;
50 unsigned int count;
51 unsigned int buf_size;
52 unsigned int buf_used;
53 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
54 struct mutex mutex; /* protects buffers and mainqueue */
55 spinlock_t irqlock; /* protects irqqueue */
57 struct list_head mainqueue;
58 struct list_head irqqueue;
61 extern void uvc_queue_init(struct uvc_video_queue *queue,
62 enum v4l2_buf_type type);
63 extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
64 unsigned int nbuffers, unsigned int buflength);
65 extern int uvc_free_buffers(struct uvc_video_queue *queue);
66 extern int uvc_query_buffer(struct uvc_video_queue *queue,
67 struct v4l2_buffer *v4l2_buf);
68 extern int uvc_queue_buffer(struct uvc_video_queue *queue,
69 struct v4l2_buffer *v4l2_buf);
70 extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
71 struct v4l2_buffer *v4l2_buf, int nonblocking);
72 extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
73 extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
74 extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
75 struct uvc_buffer *buf);
76 extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
77 struct file *file, poll_table *wait);
78 extern int uvc_queue_mmap(struct uvc_video_queue *queue,
79 struct vm_area_struct *vma);
80 static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
82 return queue->flags & UVC_QUEUE_STREAMING;
84 extern struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue);
86 #endif /* __KERNEL__ */
88 #endif /* _UVC_QUEUE_H_ */