blob: 4c1392ebcd4bd2634b245a23209f37c129e7be1f [file] [log] [blame]
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001#ifndef _USB_VIDEO_H_
2#define _USB_VIDEO_H_
3
Laurent Pinchart227bd5b2011-07-30 16:19:49 -03004#ifndef __KERNEL__
5#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
6#endif /* __KERNEL__ */
7
Laurent Pinchartc0efd232008-06-30 15:04:50 -03008#include <linux/kernel.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -03009#include <linux/poll.h>
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -030010#include <linux/usb.h>
Laurent Pinchartde05f632009-06-26 12:15:38 -030011#include <linux/usb/video.h>
Laurent Pinchart5f708812010-11-21 17:15:44 -030012#include <linux/uvcvideo.h>
Laurent Pinchart227bd5b2011-07-30 16:19:49 -030013#include <linux/videodev2.h>
Laurent Pinchart5a254d72010-01-21 05:39:47 -030014#include <media/media-device.h>
15#include <media/v4l2-device.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030016
17/* --------------------------------------------------------------------------
18 * UVC constants
19 */
20
Laurent Pinchartc0efd232008-06-30 15:04:50 -030021#define UVC_TERM_INPUT 0x0000
22#define UVC_TERM_OUTPUT 0x8000
Laurent Pinchart6241d8c2009-11-25 12:00:22 -030023#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030024
25#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
26#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
27#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
28#define UVC_ENTITY_IS_ITERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -030029 (UVC_ENTITY_IS_TERM(entity) && \
30 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030031#define UVC_ENTITY_IS_OTERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -030032 (UVC_ENTITY_IS_TERM(entity) && \
33 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030034
Laurent Pinchartc0efd232008-06-30 15:04:50 -030035
36/* ------------------------------------------------------------------------
37 * GUIDs
38 */
39#define UVC_GUID_UVC_CAMERA \
40 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
42#define UVC_GUID_UVC_OUTPUT \
43 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
45#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
46 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
48#define UVC_GUID_UVC_PROCESSING \
49 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
51#define UVC_GUID_UVC_SELECTOR \
52 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
54
Laurent Pinchartc0efd232008-06-30 15:04:50 -030055#define UVC_GUID_FORMAT_MJPEG \
56 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
57 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
58#define UVC_GUID_FORMAT_YUY2 \
59 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
60 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Daniel Ritz68f194e2009-12-12 14:57:17 -030061#define UVC_GUID_FORMAT_YUY2_ISIGHT \
62 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
63 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -030064#define UVC_GUID_FORMAT_NV12 \
65 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
66 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
67#define UVC_GUID_FORMAT_YV12 \
68 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
69 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
70#define UVC_GUID_FORMAT_I420 \
71 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
72 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
73#define UVC_GUID_FORMAT_UYVY \
74 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
75 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
76#define UVC_GUID_FORMAT_Y800 \
77 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
78 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart614212062010-04-12 10:41:22 -030079#define UVC_GUID_FORMAT_Y16 \
80 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
81 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -030082#define UVC_GUID_FORMAT_BY8 \
83 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
84 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart50791072011-03-06 08:32:04 -030085#define UVC_GUID_FORMAT_RGBP \
86 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
87 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Hans de Goede7225a1d2011-05-11 09:56:20 -030088#define UVC_GUID_FORMAT_M420 \
89 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
90 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -030091
Stephan Lachowsky25ad8a82011-01-28 16:38:58 -030092#define UVC_GUID_FORMAT_H264 \
93 { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \
94 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
95
Laurent Pinchartc0efd232008-06-30 15:04:50 -030096/* ------------------------------------------------------------------------
97 * Driver specific constants.
98 */
99
Mauro Carvalho Chehabfd3e5822011-06-25 13:50:37 -0300100#define DRIVER_VERSION "1.1.1"
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300101
102/* Number of isochronous URBs. */
103#define UVC_URBS 5
Laurent Pinchartefdc8a92009-01-18 17:46:30 -0300104/* Maximum number of packets per URB. */
105#define UVC_MAX_PACKETS 32
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300106/* Maximum number of video buffers. */
107#define UVC_MAX_VIDEO_BUFFERS 32
Ming Leia31a4052008-09-16 03:32:20 -0300108/* Maximum status buffer size in bytes of interrupt URB. */
109#define UVC_MAX_STATUS_SIZE 16
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300110
111#define UVC_CTRL_CONTROL_TIMEOUT 300
Laurent Pinchart56d15cd2010-01-19 08:59:21 -0300112#define UVC_CTRL_STREAMING_TIMEOUT 5000
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300113
Martin Rubli8fb91b32010-09-08 04:15:23 -0300114/* Maximum allowed number of control mappings per device */
115#define UVC_MAX_CONTROL_MAPPINGS 1024
116
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300117/* Devices quirks */
118#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
119#define UVC_QUIRK_PROBE_MINMAX 0x00000002
120#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
121#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
122#define UVC_QUIRK_STREAM_NO_FID 0x00000010
123#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
Laurent Pinchart50144ae2009-02-16 17:41:52 -0300124#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
Laurent Pinchartbab6f662009-07-19 18:39:56 -0300125#define UVC_QUIRK_PROBE_DEF 0x00000100
Laurent Pinchart86d8b6a2010-09-16 12:37:26 -0300126#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300127
128/* Format flags */
129#define UVC_FMT_FLAG_COMPRESSED 0x00000001
130#define UVC_FMT_FLAG_STREAM 0x00000002
131
132/* ------------------------------------------------------------------------
133 * Structures.
134 */
135
136struct uvc_device;
137
138/* TODO: Put the most frequently accessed fields at the beginning of
139 * structures to maximize cache efficiency.
140 */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300141struct uvc_control_info {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300142 struct list_head mappings;
143
144 __u8 entity[16];
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300145 __u8 index; /* Bit index in bmControls */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300146 __u8 selector;
147
148 __u16 size;
149 __u32 flags;
150};
151
152struct uvc_control_mapping {
153 struct list_head list;
154
155 struct uvc_control_info *ctrl;
156
157 __u32 id;
158 __u8 name[32];
159 __u8 entity[16];
160 __u8 selector;
161
162 __u8 size;
163 __u8 offset;
164 enum v4l2_ctrl_type v4l2_type;
165 __u32 data_type;
166
167 struct uvc_menu_info *menu_info;
168 __u32 menu_count;
Laurent Pinchart97683522008-12-16 06:46:32 -0300169
170 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
171 const __u8 *data);
172 void (*set) (struct uvc_control_mapping *mapping, __s32 value,
173 __u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300174};
175
176struct uvc_control {
177 struct uvc_entity *entity;
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300178 struct uvc_control_info info;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300179
180 __u8 index; /* Used to match the uvc_control entry with a
181 uvc_control_info. */
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300182 __u8 dirty:1,
183 loaded:1,
184 modified:1,
185 cached:1,
186 initialized:1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300187
Laurent Pinchartb30ece52010-06-18 11:31:24 -0300188 __u8 *uvc_data;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300189};
190
191struct uvc_format_desc {
192 char *name;
193 __u8 guid[16];
194 __u32 fcc;
195};
196
197/* The term 'entity' refers to both UVC units and UVC terminals.
198 *
199 * The type field is either the terminal type (wTerminalType in the terminal
200 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
201 * As the bDescriptorSubtype field is one byte long, the type value will
202 * always have a null MSB for units. All terminal types defined by the UVC
203 * specification have a non-null MSB, so it is safe to use the MSB to
204 * differentiate between units and terminals as long as the descriptor parsing
205 * code makes sure terminal types have a non-null MSB.
206 *
207 * For terminals, the type's most significant bit stores the terminal
208 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
209 * always be accessed with the UVC_ENTITY_* macros and never directly.
210 */
211
212struct uvc_entity {
213 struct list_head list; /* Entity as part of a UVC device. */
214 struct list_head chain; /* Entity as part of a video device
215 * chain. */
216 __u8 id;
217 __u16 type;
218 char name[64];
219
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300220 /* Media controller-related fields. */
Laurent Pinchart8a65a942010-01-21 08:56:19 -0300221 struct video_device *vdev;
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300222 struct v4l2_subdev subdev;
223 unsigned int num_pads;
224 unsigned int num_links;
225 struct media_pad *pads;
226
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300227 union {
228 struct {
229 __u16 wObjectiveFocalLengthMin;
230 __u16 wObjectiveFocalLengthMax;
231 __u16 wOcularFocalLength;
232 __u8 bControlSize;
233 __u8 *bmControls;
234 } camera;
235
236 struct {
237 __u8 bControlSize;
238 __u8 *bmControls;
239 __u8 bTransportModeSize;
240 __u8 *bmTransportModes;
241 } media;
242
243 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300244 } output;
245
246 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300247 __u16 wMaxMultiplier;
248 __u8 bControlSize;
249 __u8 *bmControls;
250 __u8 bmVideoStandards;
251 } processing;
252
253 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300254 } selector;
255
256 struct {
257 __u8 guidExtensionCode[16];
258 __u8 bNumControls;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300259 __u8 bControlSize;
260 __u8 *bmControls;
261 __u8 *bmControlsType;
262 } extension;
263 };
264
Laurent Pinchart8ca5a632009-11-25 12:00:30 -0300265 __u8 bNrInPins;
266 __u8 *baSourceID;
267
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300268 unsigned int ncontrols;
269 struct uvc_control *controls;
270};
271
272struct uvc_frame {
273 __u8 bFrameIndex;
274 __u8 bmCapabilities;
275 __u16 wWidth;
276 __u16 wHeight;
277 __u32 dwMinBitRate;
278 __u32 dwMaxBitRate;
279 __u32 dwMaxVideoFrameBufferSize;
280 __u8 bFrameIntervalType;
281 __u32 dwDefaultFrameInterval;
282 __u32 *dwFrameInterval;
283};
284
285struct uvc_format {
286 __u8 type;
287 __u8 index;
288 __u8 bpp;
289 __u8 colorspace;
290 __u32 fcc;
291 __u32 flags;
292
293 char name[32];
294
295 unsigned int nframes;
296 struct uvc_frame *frame;
297};
298
299struct uvc_streaming_header {
300 __u8 bNumFormats;
301 __u8 bEndpointAddress;
302 __u8 bTerminalLink;
303 __u8 bControlSize;
304 __u8 *bmaControls;
305 /* The following fields are used by input headers only. */
306 __u8 bmInfo;
307 __u8 bStillCaptureMethod;
308 __u8 bTriggerSupport;
309 __u8 bTriggerUsage;
310};
311
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300312enum uvc_buffer_state {
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300313 UVC_BUF_STATE_IDLE = 0,
314 UVC_BUF_STATE_QUEUED = 1,
315 UVC_BUF_STATE_ACTIVE = 2,
Laurent Pinchartd7c0d432009-12-16 21:20:45 -0300316 UVC_BUF_STATE_READY = 3,
317 UVC_BUF_STATE_DONE = 4,
318 UVC_BUF_STATE_ERROR = 5,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300319};
320
321struct uvc_buffer {
322 unsigned long vma_use_count;
323 struct list_head stream;
324
325 /* Touched by interrupt handler. */
326 struct v4l2_buffer buf;
327 struct list_head queue;
328 wait_queue_head_t wait;
329 enum uvc_buffer_state state;
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300330 unsigned int error;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300331};
332
333#define UVC_QUEUE_STREAMING (1 << 0)
334#define UVC_QUEUE_DISCONNECTED (1 << 1)
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300335#define UVC_QUEUE_DROP_CORRUPTED (1 << 2)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300336
337struct uvc_video_queue {
Laurent Pinchartff924202008-12-28 22:32:29 -0300338 enum v4l2_buf_type type;
339
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300340 void *mem;
341 unsigned int flags;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300342
343 unsigned int count;
344 unsigned int buf_size;
Laurent Pinchartff924202008-12-28 22:32:29 -0300345 unsigned int buf_used;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300346 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
347 struct mutex mutex; /* protects buffers and mainqueue */
348 spinlock_t irqlock; /* protects irqqueue */
349
350 struct list_head mainqueue;
351 struct list_head irqqueue;
352};
353
Laurent Pinchart8e113592009-07-01 20:24:47 -0300354struct uvc_video_chain {
355 struct uvc_device *dev;
356 struct list_head list;
357
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300358 struct list_head entities; /* All entities */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300359 struct uvc_entity *processing; /* Processing unit */
360 struct uvc_entity *selector; /* Selector unit */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300361
Laurent Pinchart27a61c12010-10-02 09:04:53 -0300362 struct mutex ctrl_mutex; /* Protects ctrl.info */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300363};
364
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300365struct uvc_streaming {
366 struct list_head list;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300367 struct uvc_device *dev;
368 struct video_device *vdev;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300369 struct uvc_video_chain *chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300370 atomic_t active;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300371
372 struct usb_interface *intf;
373 int intfnum;
374 __u16 maxpsize;
375
376 struct uvc_streaming_header header;
377 enum v4l2_buf_type type;
378
379 unsigned int nformats;
380 struct uvc_format *format;
381
382 struct uvc_streaming_control ctrl;
383 struct uvc_format *cur_format;
384 struct uvc_frame *cur_frame;
Laurent Pinchart69477562010-11-21 13:36:34 -0300385 /* Protect access to ctrl, cur_format, cur_frame and hardware video
386 * probe control.
387 */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300388 struct mutex mutex;
389
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300390 unsigned int frozen : 1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300391 struct uvc_video_queue queue;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300392 void (*decode) (struct urb *urb, struct uvc_streaming *video,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300393 struct uvc_buffer *buf);
394
395 /* Context data used by the bulk completion handler. */
396 struct {
397 __u8 header[256];
398 unsigned int header_size;
399 int skip_payload;
400 __u32 payload_size;
401 __u32 max_payload_size;
402 } bulk;
403
404 struct urb *urb[UVC_URBS];
405 char *urb_buffer[UVC_URBS];
Laurent Pincharte01117c2008-07-04 00:36:21 -0300406 dma_addr_t urb_dma[UVC_URBS];
407 unsigned int urb_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300408
Laurent Pinchart650b95f2010-10-02 11:06:05 -0300409 __u32 sequence;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300410 __u8 last_fid;
411};
412
413enum uvc_device_state {
414 UVC_DEV_DISCONNECTED = 1,
415};
416
417struct uvc_device {
418 struct usb_device *udev;
419 struct usb_interface *intf;
Laurent Pinchart44f00792008-11-08 19:14:50 -0300420 unsigned long warnings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300421 __u32 quirks;
422 int intfnum;
423 char name[32];
424
425 enum uvc_device_state state;
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300426 atomic_t users;
Martin Rubli8fb91b32010-09-08 04:15:23 -0300427 atomic_t nmappings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300428
429 /* Video control interface */
Laurent Pinchart5a254d72010-01-21 05:39:47 -0300430#ifdef CONFIG_MEDIA_CONTROLLER
431 struct media_device mdev;
432#endif
433 struct v4l2_device vdev;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300434 __u16 uvc_version;
435 __u32 clock_frequency;
436
437 struct list_head entities;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300438 struct list_head chains;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300439
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300440 /* Video Streaming interfaces */
441 struct list_head streams;
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300442 atomic_t nstreams;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300443
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300444 /* Status Interrupt Endpoint */
445 struct usb_host_endpoint *int_ep;
446 struct urb *int_urb;
Ming Leia31a4052008-09-16 03:32:20 -0300447 __u8 *status;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300448 struct input_dev *input;
Laurent Pinchartf1801522009-01-22 12:45:10 -0300449 char input_phys[64];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300450};
451
452enum uvc_handle_state {
453 UVC_HANDLE_PASSIVE = 0,
454 UVC_HANDLE_ACTIVE = 1,
455};
456
457struct uvc_fh {
Laurent Pinchart8e113592009-07-01 20:24:47 -0300458 struct uvc_video_chain *chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300459 struct uvc_streaming *stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300460 enum uvc_handle_state state;
461};
462
463struct uvc_driver {
464 struct usb_driver driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300465};
466
467/* ------------------------------------------------------------------------
468 * Debugging, printing and logging
469 */
470
471#define UVC_TRACE_PROBE (1 << 0)
472#define UVC_TRACE_DESCR (1 << 1)
473#define UVC_TRACE_CONTROL (1 << 2)
474#define UVC_TRACE_FORMAT (1 << 3)
475#define UVC_TRACE_CAPTURE (1 << 4)
476#define UVC_TRACE_CALLS (1 << 5)
477#define UVC_TRACE_IOCTL (1 << 6)
478#define UVC_TRACE_FRAME (1 << 7)
479#define UVC_TRACE_SUSPEND (1 << 8)
480#define UVC_TRACE_STATUS (1 << 9)
Laurent Pinchart663a4192009-08-06 11:41:17 -0300481#define UVC_TRACE_VIDEO (1 << 10)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300482
Laurent Pinchart44f00792008-11-08 19:14:50 -0300483#define UVC_WARN_MINMAX 0
484#define UVC_WARN_PROBE_DEF 1
485
Laurent Pinchart310fe522009-12-09 22:57:48 -0300486extern unsigned int uvc_clock_param;
Laurent Pinchart0fbd8ee2008-12-06 16:25:14 -0300487extern unsigned int uvc_no_drop_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300488extern unsigned int uvc_trace_param;
Laurent Pinchartb232a012009-10-09 20:55:23 -0300489extern unsigned int uvc_timeout_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300490
491#define uvc_trace(flag, msg...) \
492 do { \
493 if (uvc_trace_param & flag) \
494 printk(KERN_DEBUG "uvcvideo: " msg); \
495 } while (0)
496
Laurent Pinchart44f00792008-11-08 19:14:50 -0300497#define uvc_warn_once(dev, warn, msg...) \
498 do { \
499 if (!test_and_set_bit(warn, &dev->warnings)) \
500 printk(KERN_INFO "uvcvideo: " msg); \
501 } while (0)
502
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300503#define uvc_printk(level, msg...) \
504 printk(level "uvcvideo: " msg)
505
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300506/* --------------------------------------------------------------------------
507 * Internal functions.
508 */
509
510/* Core driver */
511extern struct uvc_driver uvc_driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300512
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300513extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
514
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300515/* Video buffers queue management. */
Laurent Pinchartff924202008-12-28 22:32:29 -0300516extern void uvc_queue_init(struct uvc_video_queue *queue,
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300517 enum v4l2_buf_type type, int drop_corrupted);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300518extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
519 unsigned int nbuffers, unsigned int buflength);
520extern int uvc_free_buffers(struct uvc_video_queue *queue);
521extern int uvc_query_buffer(struct uvc_video_queue *queue,
522 struct v4l2_buffer *v4l2_buf);
523extern int uvc_queue_buffer(struct uvc_video_queue *queue,
524 struct v4l2_buffer *v4l2_buf);
525extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
526 struct v4l2_buffer *v4l2_buf, int nonblocking);
527extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
528extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
529extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
530 struct uvc_buffer *buf);
Laurent Pinchart4aa27592010-11-21 15:18:08 -0300531extern int uvc_queue_mmap(struct uvc_video_queue *queue,
532 struct vm_area_struct *vma);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300533extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
534 struct file *file, poll_table *wait);
Bob Liu72969442011-04-29 07:11:35 -0300535#ifndef CONFIG_MMU
536extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
537 unsigned long pgoff);
538#endif
Laurent Pinchart23ff6042009-06-04 09:26:39 -0300539extern int uvc_queue_allocated(struct uvc_video_queue *queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300540static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
541{
542 return queue->flags & UVC_QUEUE_STREAMING;
543}
544
545/* V4L2 interface */
Hans Verkuilbec43662008-12-30 06:58:20 -0300546extern const struct v4l2_file_operations uvc_fops;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300547
Laurent Pinchart4ffc2d82010-01-21 05:39:52 -0300548/* Media controller */
549extern int uvc_mc_register_entities(struct uvc_video_chain *chain);
550extern void uvc_mc_cleanup_entity(struct uvc_entity *entity);
551
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300552/* Video */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300553extern int uvc_video_init(struct uvc_streaming *stream);
554extern int uvc_video_suspend(struct uvc_streaming *stream);
Ming Leid59a7b12011-07-16 00:51:00 -0300555extern int uvc_video_resume(struct uvc_streaming *stream, int reset);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300556extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
557extern int uvc_probe_video(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300558 struct uvc_streaming_control *probe);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300559extern int uvc_commit_video(struct uvc_streaming *stream,
Laurent Pinchart44f00792008-11-08 19:14:50 -0300560 struct uvc_streaming_control *ctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300561extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
562 __u8 intfnum, __u8 cs, void *data, __u16 size);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300563
564/* Status */
565extern int uvc_status_init(struct uvc_device *dev);
566extern void uvc_status_cleanup(struct uvc_device *dev);
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300567extern int uvc_status_start(struct uvc_device *dev);
568extern void uvc_status_stop(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300569extern int uvc_status_suspend(struct uvc_device *dev);
570extern int uvc_status_resume(struct uvc_device *dev);
571
572/* Controls */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300573extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300574 struct v4l2_queryctrl *v4l2_ctrl);
Laurent Pinchart23d9f3e2010-11-21 07:58:54 -0300575extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
576 struct v4l2_querymenu *query_menu);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300577
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300578extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
579 const struct uvc_control_mapping *mapping);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300580extern int uvc_ctrl_init_device(struct uvc_device *dev);
581extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
582extern int uvc_ctrl_resume_device(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300583
Laurent Pinchart8e113592009-07-01 20:24:47 -0300584extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
585extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
586static inline int uvc_ctrl_commit(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300587{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300588 return __uvc_ctrl_commit(chain, 0);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300589}
Laurent Pinchart8e113592009-07-01 20:24:47 -0300590static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300591{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300592 return __uvc_ctrl_commit(chain, 1);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300593}
594
Laurent Pinchart8e113592009-07-01 20:24:47 -0300595extern int uvc_ctrl_get(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300596 struct v4l2_ext_control *xctrl);
Laurent Pinchart8e113592009-07-01 20:24:47 -0300597extern int uvc_ctrl_set(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300598 struct v4l2_ext_control *xctrl);
599
Laurent Pinchart8e113592009-07-01 20:24:47 -0300600extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
Martin Rublife78d182010-10-02 19:10:16 -0300601 struct uvc_xu_control_query *xqry);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300602
603/* Utility functions */
604extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
605 unsigned int n_terms, unsigned int threshold);
606extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
607 uint32_t denominator);
608extern struct usb_host_endpoint *uvc_find_endpoint(
609 struct usb_host_interface *alts, __u8 epaddr);
610
611/* Quirks support */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300612void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300613 struct uvc_buffer *buf);
614
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300615#endif