1
2
3
4
5
6
7
8
9#ifndef _UVC_GADGET_H_
10#define _UVC_GADGET_H_
11
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/spinlock.h>
15#include <linux/usb/composite.h>
16#include <linux/videodev2.h>
17
18#include <media/v4l2-device.h>
19#include <media/v4l2-dev.h>
20#include <media/v4l2-fh.h>
21
22#include "uvc_queue.h"
23
24struct usb_ep;
25struct usb_request;
26struct uvc_descriptor_header;
27struct uvc_device;
28
29
30
31
32
33#define UVC_TRACE_PROBE (1 << 0)
34#define UVC_TRACE_DESCR (1 << 1)
35#define UVC_TRACE_CONTROL (1 << 2)
36#define UVC_TRACE_FORMAT (1 << 3)
37#define UVC_TRACE_CAPTURE (1 << 4)
38#define UVC_TRACE_CALLS (1 << 5)
39#define UVC_TRACE_IOCTL (1 << 6)
40#define UVC_TRACE_FRAME (1 << 7)
41#define UVC_TRACE_SUSPEND (1 << 8)
42#define UVC_TRACE_STATUS (1 << 9)
43
44#define UVC_WARN_MINMAX 0
45#define UVC_WARN_PROBE_DEF 1
46
47extern unsigned int uvc_gadget_trace_param;
48
49#define uvc_trace(flag, msg...) \
50 do { \
51 if (uvc_gadget_trace_param & flag) \
52 printk(KERN_DEBUG "uvcvideo: " msg); \
53 } while (0)
54
55#define uvcg_dbg(f, fmt, args...) \
56 dev_dbg(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
57#define uvcg_info(f, fmt, args...) \
58 dev_info(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
59#define uvcg_warn(f, fmt, args...) \
60 dev_warn(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
61#define uvcg_err(f, fmt, args...) \
62 dev_err(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
63
64
65
66
67
68#define UVC_MAX_REQUEST_SIZE 64
69#define UVC_MAX_EVENTS 4
70
71
72
73
74struct uvc_request {
75 struct usb_request *req;
76 u8 *req_buffer;
77 struct uvc_video *video;
78 struct sg_table sgt;
79 u8 header[2];
80};
81
82struct uvc_video {
83 struct uvc_device *uvc;
84 struct usb_ep *ep;
85
86 struct work_struct pump;
87
88
89 u8 bpp;
90 u32 fcc;
91 unsigned int width;
92 unsigned int height;
93 unsigned int imagesize;
94 struct mutex mutex;
95
96 unsigned int uvc_num_requests;
97
98
99 unsigned int req_size;
100 struct uvc_request *ureq;
101 struct list_head req_free;
102 spinlock_t req_lock;
103
104 unsigned int req_int_count;
105
106 void (*encode) (struct usb_request *req, struct uvc_video *video,
107 struct uvc_buffer *buf);
108
109
110 __u32 payload_size;
111 __u32 max_payload_size;
112
113 struct uvc_video_queue queue;
114 unsigned int fid;
115};
116
117enum uvc_state {
118 UVC_STATE_DISCONNECTED,
119 UVC_STATE_CONNECTED,
120 UVC_STATE_STREAMING,
121};
122
123struct uvc_device {
124 struct video_device vdev;
125 struct v4l2_device v4l2_dev;
126 enum uvc_state state;
127 struct usb_function func;
128 struct uvc_video video;
129
130
131 struct {
132 const struct uvc_descriptor_header * const *fs_control;
133 const struct uvc_descriptor_header * const *ss_control;
134 const struct uvc_descriptor_header * const *fs_streaming;
135 const struct uvc_descriptor_header * const *hs_streaming;
136 const struct uvc_descriptor_header * const *ss_streaming;
137 } desc;
138
139 unsigned int control_intf;
140 struct usb_ep *control_ep;
141 struct usb_request *control_req;
142 void *control_buf;
143
144 unsigned int streaming_intf;
145
146
147 unsigned int event_length;
148 unsigned int event_setup_out : 1;
149};
150
151static inline struct uvc_device *to_uvc(struct usb_function *f)
152{
153 return container_of(f, struct uvc_device, func);
154}
155
156struct uvc_file_handle {
157 struct v4l2_fh vfh;
158 struct uvc_video *device;
159};
160
161#define to_uvc_file_handle(handle) \
162 container_of(handle, struct uvc_file_handle, vfh)
163
164
165
166
167
168extern void uvc_function_setup_continue(struct uvc_device *uvc);
169extern void uvc_endpoint_stream(struct uvc_device *dev);
170
171extern void uvc_function_connect(struct uvc_device *uvc);
172extern void uvc_function_disconnect(struct uvc_device *uvc);
173
174#endif
175