blob: 38dd4e18a2caac1ba933757c5ff7f56c00f118dd [file] [log] [blame]
Laurent Pinchartc0efd232008-06-30 15:04:50 -03001#ifndef _USB_VIDEO_H_
2#define _USB_VIDEO_H_
3
4#include <linux/kernel.h>
5#include <linux/videodev2.h>
6
Laurent Pinchart5f708812010-11-21 17:15:44 -03007#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
Laurent Pinchartc0efd232008-06-30 15:04:50 -030015/*
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)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030034#define UVC_CONTROL_RESTORE (1 << 6)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030035#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
Laurent Pinchart561474c2010-02-18 16:38:52 -030041struct uvc_menu_info {
42 __u32 value;
43 __u8 name[32];
44};
45
Laurent Pinchartc0efd232008-06-30 15:04:50 -030046struct 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;
Martin Rublife78d182010-10-02 19:10:16 -030054 __u32 v4l2_type;
Laurent Pinchartc0efd232008-06-30 15:04:50 -030055 __u32 data_type;
Laurent Pinchart561474c2010-02-18 16:38:52 -030056
57 struct uvc_menu_info __user *menu_info;
58 __u32 menu_count;
59
60 __u32 reserved[4];
Laurent Pinchartc0efd232008-06-30 15:04:50 -030061};
62
Laurent Pinchart5f708812010-11-21 17:15:44 -030063#endif
64
65struct uvc_xu_control_info {
66 __u8 entity[16];
67 __u8 index;
68 __u8 selector;
69 __u16 size;
70 __u32 flags;
71};
72
73struct uvc_xu_control_mapping_old {
74 __u8 reserved[64];
75};
76
Laurent Pinchartc0efd232008-06-30 15:04:50 -030077struct uvc_xu_control {
78 __u8 unit;
79 __u8 selector;
80 __u16 size;
81 __u8 __user *data;
82};
83
Laurent Pinchart5f708812010-11-21 17:15:44 -030084#ifndef __KERNEL__
Laurent Pinchartc0efd232008-06-30 15:04:50 -030085#define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info)
Laurent Pinchart561474c2010-02-18 16:38:52 -030086#define UVCIOC_CTRL_MAP_OLD _IOWR('U', 2, struct uvc_xu_control_mapping_old)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030087#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)
Laurent Pinchart5f708812010-11-21 17:15:44 -030090#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
Laurent Pinchartc0efd232008-06-30 15:04:50 -030097
98#ifdef __KERNEL__
99
100#include <linux/poll.h>
Laurent Pinchartde05f632009-06-26 12:15:38 -0300101#include <linux/usb/video.h>
Laurent Pinchart5f708812010-11-21 17:15:44 -0300102#include <linux/uvcvideo.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300103
104/* --------------------------------------------------------------------------
105 * UVC constants
106 */
107
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300108#define UVC_TERM_INPUT 0x0000
109#define UVC_TERM_OUTPUT 0x8000
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300110#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300111
112#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
113#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
114#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
115#define UVC_ENTITY_IS_ITERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -0300116 (UVC_ENTITY_IS_TERM(entity) && \
117 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300118#define UVC_ENTITY_IS_OTERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -0300119 (UVC_ENTITY_IS_TERM(entity) && \
120 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300121
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300122
123/* ------------------------------------------------------------------------
124 * GUIDs
125 */
126#define UVC_GUID_UVC_CAMERA \
127 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
129#define UVC_GUID_UVC_OUTPUT \
130 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
132#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
133 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
135#define UVC_GUID_UVC_PROCESSING \
136 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
138#define UVC_GUID_UVC_SELECTOR \
139 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
141
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300142#define UVC_GUID_FORMAT_MJPEG \
143 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
144 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
145#define UVC_GUID_FORMAT_YUY2 \
146 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
147 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Daniel Ritz68f194e2009-12-12 14:57:17 -0300148#define UVC_GUID_FORMAT_YUY2_ISIGHT \
149 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
150 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300151#define UVC_GUID_FORMAT_NV12 \
152 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
153 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
154#define UVC_GUID_FORMAT_YV12 \
155 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
156 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
157#define UVC_GUID_FORMAT_I420 \
158 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
159 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
160#define UVC_GUID_FORMAT_UYVY \
161 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
162 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
163#define UVC_GUID_FORMAT_Y800 \
164 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
165 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart614212062010-04-12 10:41:22 -0300166#define UVC_GUID_FORMAT_Y16 \
167 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
168 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300169#define UVC_GUID_FORMAT_BY8 \
170 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
171 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart50791072011-03-06 08:32:04 -0300172#define UVC_GUID_FORMAT_RGBP \
173 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
174 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300175
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300176/* ------------------------------------------------------------------------
177 * Driver specific constants.
178 */
179
Laurent Pinchart5f708812010-11-21 17:15:44 -0300180#define DRIVER_VERSION_NUMBER KERNEL_VERSION(1, 1, 0)
181#define DRIVER_VERSION "v1.1.0"
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300182
183/* Number of isochronous URBs. */
184#define UVC_URBS 5
Laurent Pinchartefdc8a92009-01-18 17:46:30 -0300185/* Maximum number of packets per URB. */
186#define UVC_MAX_PACKETS 32
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300187/* Maximum number of video buffers. */
188#define UVC_MAX_VIDEO_BUFFERS 32
Ming Leia31a4052008-09-16 03:32:20 -0300189/* Maximum status buffer size in bytes of interrupt URB. */
190#define UVC_MAX_STATUS_SIZE 16
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300191
192#define UVC_CTRL_CONTROL_TIMEOUT 300
Laurent Pinchart56d15cd2010-01-19 08:59:21 -0300193#define UVC_CTRL_STREAMING_TIMEOUT 5000
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300194
Martin Rubli8fb91b32010-09-08 04:15:23 -0300195/* Maximum allowed number of control mappings per device */
196#define UVC_MAX_CONTROL_MAPPINGS 1024
197
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300198/* Devices quirks */
199#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
200#define UVC_QUIRK_PROBE_MINMAX 0x00000002
201#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
202#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
203#define UVC_QUIRK_STREAM_NO_FID 0x00000010
204#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
Laurent Pinchart50144ae2009-02-16 17:41:52 -0300205#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
Laurent Pinchartbab6f662009-07-19 18:39:56 -0300206#define UVC_QUIRK_PROBE_DEF 0x00000100
Laurent Pinchart86d8b6a2010-09-16 12:37:26 -0300207#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300208
209/* Format flags */
210#define UVC_FMT_FLAG_COMPRESSED 0x00000001
211#define UVC_FMT_FLAG_STREAM 0x00000002
212
213/* ------------------------------------------------------------------------
214 * Structures.
215 */
216
217struct uvc_device;
218
219/* TODO: Put the most frequently accessed fields at the beginning of
220 * structures to maximize cache efficiency.
221 */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300222struct uvc_control_info {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300223 struct list_head mappings;
224
225 __u8 entity[16];
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300226 __u8 index; /* Bit index in bmControls */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300227 __u8 selector;
228
229 __u16 size;
230 __u32 flags;
231};
232
233struct uvc_control_mapping {
234 struct list_head list;
235
236 struct uvc_control_info *ctrl;
237
238 __u32 id;
239 __u8 name[32];
240 __u8 entity[16];
241 __u8 selector;
242
243 __u8 size;
244 __u8 offset;
245 enum v4l2_ctrl_type v4l2_type;
246 __u32 data_type;
247
248 struct uvc_menu_info *menu_info;
249 __u32 menu_count;
Laurent Pinchart97683522008-12-16 06:46:32 -0300250
251 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
252 const __u8 *data);
253 void (*set) (struct uvc_control_mapping *mapping, __s32 value,
254 __u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300255};
256
257struct uvc_control {
258 struct uvc_entity *entity;
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300259 struct uvc_control_info info;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300260
261 __u8 index; /* Used to match the uvc_control entry with a
262 uvc_control_info. */
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300263 __u8 dirty:1,
264 loaded:1,
265 modified:1,
266 cached:1,
267 initialized:1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300268
Laurent Pinchartb30ece52010-06-18 11:31:24 -0300269 __u8 *uvc_data;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300270};
271
272struct uvc_format_desc {
273 char *name;
274 __u8 guid[16];
275 __u32 fcc;
276};
277
278/* The term 'entity' refers to both UVC units and UVC terminals.
279 *
280 * The type field is either the terminal type (wTerminalType in the terminal
281 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
282 * As the bDescriptorSubtype field is one byte long, the type value will
283 * always have a null MSB for units. All terminal types defined by the UVC
284 * specification have a non-null MSB, so it is safe to use the MSB to
285 * differentiate between units and terminals as long as the descriptor parsing
286 * code makes sure terminal types have a non-null MSB.
287 *
288 * For terminals, the type's most significant bit stores the terminal
289 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
290 * always be accessed with the UVC_ENTITY_* macros and never directly.
291 */
292
293struct uvc_entity {
294 struct list_head list; /* Entity as part of a UVC device. */
295 struct list_head chain; /* Entity as part of a video device
296 * chain. */
297 __u8 id;
298 __u16 type;
299 char name[64];
300
301 union {
302 struct {
303 __u16 wObjectiveFocalLengthMin;
304 __u16 wObjectiveFocalLengthMax;
305 __u16 wOcularFocalLength;
306 __u8 bControlSize;
307 __u8 *bmControls;
308 } camera;
309
310 struct {
311 __u8 bControlSize;
312 __u8 *bmControls;
313 __u8 bTransportModeSize;
314 __u8 *bmTransportModes;
315 } media;
316
317 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300318 } output;
319
320 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300321 __u16 wMaxMultiplier;
322 __u8 bControlSize;
323 __u8 *bmControls;
324 __u8 bmVideoStandards;
325 } processing;
326
327 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300328 } selector;
329
330 struct {
331 __u8 guidExtensionCode[16];
332 __u8 bNumControls;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300333 __u8 bControlSize;
334 __u8 *bmControls;
335 __u8 *bmControlsType;
336 } extension;
337 };
338
Laurent Pinchart8ca5a632009-11-25 12:00:30 -0300339 __u8 bNrInPins;
340 __u8 *baSourceID;
341
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300342 unsigned int ncontrols;
343 struct uvc_control *controls;
344};
345
346struct uvc_frame {
347 __u8 bFrameIndex;
348 __u8 bmCapabilities;
349 __u16 wWidth;
350 __u16 wHeight;
351 __u32 dwMinBitRate;
352 __u32 dwMaxBitRate;
353 __u32 dwMaxVideoFrameBufferSize;
354 __u8 bFrameIntervalType;
355 __u32 dwDefaultFrameInterval;
356 __u32 *dwFrameInterval;
357};
358
359struct uvc_format {
360 __u8 type;
361 __u8 index;
362 __u8 bpp;
363 __u8 colorspace;
364 __u32 fcc;
365 __u32 flags;
366
367 char name[32];
368
369 unsigned int nframes;
370 struct uvc_frame *frame;
371};
372
373struct uvc_streaming_header {
374 __u8 bNumFormats;
375 __u8 bEndpointAddress;
376 __u8 bTerminalLink;
377 __u8 bControlSize;
378 __u8 *bmaControls;
379 /* The following fields are used by input headers only. */
380 __u8 bmInfo;
381 __u8 bStillCaptureMethod;
382 __u8 bTriggerSupport;
383 __u8 bTriggerUsage;
384};
385
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300386enum uvc_buffer_state {
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300387 UVC_BUF_STATE_IDLE = 0,
388 UVC_BUF_STATE_QUEUED = 1,
389 UVC_BUF_STATE_ACTIVE = 2,
Laurent Pinchartd7c0d432009-12-16 21:20:45 -0300390 UVC_BUF_STATE_READY = 3,
391 UVC_BUF_STATE_DONE = 4,
392 UVC_BUF_STATE_ERROR = 5,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300393};
394
395struct uvc_buffer {
396 unsigned long vma_use_count;
397 struct list_head stream;
398
399 /* Touched by interrupt handler. */
400 struct v4l2_buffer buf;
401 struct list_head queue;
402 wait_queue_head_t wait;
403 enum uvc_buffer_state state;
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300404 unsigned int error;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300405};
406
407#define UVC_QUEUE_STREAMING (1 << 0)
408#define UVC_QUEUE_DISCONNECTED (1 << 1)
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300409#define UVC_QUEUE_DROP_CORRUPTED (1 << 2)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300410
411struct uvc_video_queue {
Laurent Pinchartff924202008-12-28 22:32:29 -0300412 enum v4l2_buf_type type;
413
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300414 void *mem;
415 unsigned int flags;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300416
417 unsigned int count;
418 unsigned int buf_size;
Laurent Pinchartff924202008-12-28 22:32:29 -0300419 unsigned int buf_used;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300420 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
421 struct mutex mutex; /* protects buffers and mainqueue */
422 spinlock_t irqlock; /* protects irqqueue */
423
424 struct list_head mainqueue;
425 struct list_head irqqueue;
426};
427
Laurent Pinchart8e113592009-07-01 20:24:47 -0300428struct uvc_video_chain {
429 struct uvc_device *dev;
430 struct list_head list;
431
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300432 struct list_head entities; /* All entities */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300433 struct uvc_entity *processing; /* Processing unit */
434 struct uvc_entity *selector; /* Selector unit */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300435
Laurent Pinchart27a61c12010-10-02 09:04:53 -0300436 struct mutex ctrl_mutex; /* Protects ctrl.info */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300437};
438
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300439struct uvc_streaming {
440 struct list_head list;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300441 struct uvc_device *dev;
442 struct video_device *vdev;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300443 struct uvc_video_chain *chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300444 atomic_t active;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300445
446 struct usb_interface *intf;
447 int intfnum;
448 __u16 maxpsize;
449
450 struct uvc_streaming_header header;
451 enum v4l2_buf_type type;
452
453 unsigned int nformats;
454 struct uvc_format *format;
455
456 struct uvc_streaming_control ctrl;
457 struct uvc_format *cur_format;
458 struct uvc_frame *cur_frame;
Laurent Pinchart69477562010-11-21 13:36:34 -0300459 /* Protect access to ctrl, cur_format, cur_frame and hardware video
460 * probe control.
461 */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300462 struct mutex mutex;
463
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300464 unsigned int frozen : 1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300465 struct uvc_video_queue queue;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300466 void (*decode) (struct urb *urb, struct uvc_streaming *video,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300467 struct uvc_buffer *buf);
468
469 /* Context data used by the bulk completion handler. */
470 struct {
471 __u8 header[256];
472 unsigned int header_size;
473 int skip_payload;
474 __u32 payload_size;
475 __u32 max_payload_size;
476 } bulk;
477
478 struct urb *urb[UVC_URBS];
479 char *urb_buffer[UVC_URBS];
Laurent Pincharte01117c2008-07-04 00:36:21 -0300480 dma_addr_t urb_dma[UVC_URBS];
481 unsigned int urb_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300482
Laurent Pinchart650b95f2010-10-02 11:06:05 -0300483 __u32 sequence;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300484 __u8 last_fid;
485};
486
487enum uvc_device_state {
488 UVC_DEV_DISCONNECTED = 1,
489};
490
491struct uvc_device {
492 struct usb_device *udev;
493 struct usb_interface *intf;
Laurent Pinchart44f00792008-11-08 19:14:50 -0300494 unsigned long warnings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300495 __u32 quirks;
496 int intfnum;
497 char name[32];
498
499 enum uvc_device_state state;
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300500 atomic_t users;
Martin Rubli8fb91b32010-09-08 04:15:23 -0300501 atomic_t nmappings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300502
503 /* Video control interface */
504 __u16 uvc_version;
505 __u32 clock_frequency;
506
507 struct list_head entities;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300508 struct list_head chains;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300509
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300510 /* Video Streaming interfaces */
511 struct list_head streams;
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300512 atomic_t nstreams;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300513
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300514 /* Status Interrupt Endpoint */
515 struct usb_host_endpoint *int_ep;
516 struct urb *int_urb;
Ming Leia31a4052008-09-16 03:32:20 -0300517 __u8 *status;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300518 struct input_dev *input;
Laurent Pinchartf1801522009-01-22 12:45:10 -0300519 char input_phys[64];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300520};
521
522enum uvc_handle_state {
523 UVC_HANDLE_PASSIVE = 0,
524 UVC_HANDLE_ACTIVE = 1,
525};
526
527struct uvc_fh {
Laurent Pinchart8e113592009-07-01 20:24:47 -0300528 struct uvc_video_chain *chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300529 struct uvc_streaming *stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300530 enum uvc_handle_state state;
531};
532
533struct uvc_driver {
534 struct usb_driver driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300535};
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)
Laurent Pinchart663a4192009-08-06 11:41:17 -0300551#define UVC_TRACE_VIDEO (1 << 10)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300552
Laurent Pinchart44f00792008-11-08 19:14:50 -0300553#define UVC_WARN_MINMAX 0
554#define UVC_WARN_PROBE_DEF 1
555
Laurent Pinchart310fe522009-12-09 22:57:48 -0300556extern unsigned int uvc_clock_param;
Laurent Pinchart0fbd8ee2008-12-06 16:25:14 -0300557extern unsigned int uvc_no_drop_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300558extern unsigned int uvc_trace_param;
Laurent Pinchartb232a012009-10-09 20:55:23 -0300559extern unsigned int uvc_timeout_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300560
561#define uvc_trace(flag, msg...) \
562 do { \
563 if (uvc_trace_param & flag) \
564 printk(KERN_DEBUG "uvcvideo: " msg); \
565 } while (0)
566
Laurent Pinchart44f00792008-11-08 19:14:50 -0300567#define uvc_warn_once(dev, warn, msg...) \
568 do { \
569 if (!test_and_set_bit(warn, &dev->warnings)) \
570 printk(KERN_INFO "uvcvideo: " msg); \
571 } while (0)
572
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300573#define uvc_printk(level, msg...) \
574 printk(level "uvcvideo: " msg)
575
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300576/* --------------------------------------------------------------------------
577 * Internal functions.
578 */
579
580/* Core driver */
581extern struct uvc_driver uvc_driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300582
583/* Video buffers queue management. */
Laurent Pinchartff924202008-12-28 22:32:29 -0300584extern void uvc_queue_init(struct uvc_video_queue *queue,
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300585 enum v4l2_buf_type type, int drop_corrupted);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300586extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
587 unsigned int nbuffers, unsigned int buflength);
588extern int uvc_free_buffers(struct uvc_video_queue *queue);
589extern int uvc_query_buffer(struct uvc_video_queue *queue,
590 struct v4l2_buffer *v4l2_buf);
591extern int uvc_queue_buffer(struct uvc_video_queue *queue,
592 struct v4l2_buffer *v4l2_buf);
593extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
594 struct v4l2_buffer *v4l2_buf, int nonblocking);
595extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
596extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
597extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
598 struct uvc_buffer *buf);
Laurent Pinchart4aa27592010-11-21 15:18:08 -0300599extern int uvc_queue_mmap(struct uvc_video_queue *queue,
600 struct vm_area_struct *vma);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300601extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
602 struct file *file, poll_table *wait);
Laurent Pinchart23ff6042009-06-04 09:26:39 -0300603extern int uvc_queue_allocated(struct uvc_video_queue *queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300604static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
605{
606 return queue->flags & UVC_QUEUE_STREAMING;
607}
608
609/* V4L2 interface */
Hans Verkuilbec43662008-12-30 06:58:20 -0300610extern const struct v4l2_file_operations uvc_fops;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300611
612/* Video */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300613extern int uvc_video_init(struct uvc_streaming *stream);
614extern int uvc_video_suspend(struct uvc_streaming *stream);
615extern int uvc_video_resume(struct uvc_streaming *stream);
616extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
617extern int uvc_probe_video(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300618 struct uvc_streaming_control *probe);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300619extern int uvc_commit_video(struct uvc_streaming *stream,
Laurent Pinchart44f00792008-11-08 19:14:50 -0300620 struct uvc_streaming_control *ctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300621extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
622 __u8 intfnum, __u8 cs, void *data, __u16 size);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300623
624/* Status */
625extern int uvc_status_init(struct uvc_device *dev);
626extern void uvc_status_cleanup(struct uvc_device *dev);
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300627extern int uvc_status_start(struct uvc_device *dev);
628extern void uvc_status_stop(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300629extern int uvc_status_suspend(struct uvc_device *dev);
630extern int uvc_status_resume(struct uvc_device *dev);
631
632/* Controls */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300633extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300634 struct v4l2_queryctrl *v4l2_ctrl);
Laurent Pinchart23d9f3e2010-11-21 07:58:54 -0300635extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
636 struct v4l2_querymenu *query_menu);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300637
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300638extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
639 const struct uvc_control_mapping *mapping);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300640extern int uvc_ctrl_init_device(struct uvc_device *dev);
641extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
642extern int uvc_ctrl_resume_device(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300643
Laurent Pinchart8e113592009-07-01 20:24:47 -0300644extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
645extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
646static inline int uvc_ctrl_commit(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300647{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300648 return __uvc_ctrl_commit(chain, 0);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300649}
Laurent Pinchart8e113592009-07-01 20:24:47 -0300650static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300651{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300652 return __uvc_ctrl_commit(chain, 1);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300653}
654
Laurent Pinchart8e113592009-07-01 20:24:47 -0300655extern int uvc_ctrl_get(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300656 struct v4l2_ext_control *xctrl);
Laurent Pinchart8e113592009-07-01 20:24:47 -0300657extern int uvc_ctrl_set(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300658 struct v4l2_ext_control *xctrl);
659
Laurent Pinchart8e113592009-07-01 20:24:47 -0300660extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
Martin Rublife78d182010-10-02 19:10:16 -0300661 struct uvc_xu_control_query *xqry);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300662
663/* Utility functions */
664extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
665 unsigned int n_terms, unsigned int threshold);
666extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
667 uint32_t denominator);
668extern struct usb_host_endpoint *uvc_find_endpoint(
669 struct usb_host_interface *alts, __u8 epaddr);
670
671/* Quirks support */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300672void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300673 struct uvc_buffer *buf);
674
675#endif /* __KERNEL__ */
676
677#endif