blob: a3f4d308358a543102bdf4297495d0c9ccd79267 [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 Pinchartc0efd232008-06-30 15:04:50 -03007/*
8 * Dynamic controls
9 */
10
11/* Data types for UVC control data */
12#define UVC_CTRL_DATA_TYPE_RAW 0
13#define UVC_CTRL_DATA_TYPE_SIGNED 1
14#define UVC_CTRL_DATA_TYPE_UNSIGNED 2
15#define UVC_CTRL_DATA_TYPE_BOOLEAN 3
16#define UVC_CTRL_DATA_TYPE_ENUM 4
17#define UVC_CTRL_DATA_TYPE_BITMASK 5
18
19/* Control flags */
20#define UVC_CONTROL_SET_CUR (1 << 0)
21#define UVC_CONTROL_GET_CUR (1 << 1)
22#define UVC_CONTROL_GET_MIN (1 << 2)
23#define UVC_CONTROL_GET_MAX (1 << 3)
24#define UVC_CONTROL_GET_RES (1 << 4)
25#define UVC_CONTROL_GET_DEF (1 << 5)
26/* Control should be saved at suspend and restored at resume. */
27#define UVC_CONTROL_RESTORE (1 << 6)
28/* Control can be updated by the camera. */
29#define UVC_CONTROL_AUTO_UPDATE (1 << 7)
30
31#define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \
32 UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \
33 UVC_CONTROL_GET_DEF)
34
35struct uvc_xu_control_info {
36 __u8 entity[16];
37 __u8 index;
38 __u8 selector;
39 __u16 size;
40 __u32 flags;
41};
42
Laurent Pinchart561474c2010-02-18 16:38:52 -030043struct uvc_menu_info {
44 __u32 value;
45 __u8 name[32];
46};
47
48struct uvc_xu_control_mapping_old {
49 __u8 reserved[64];
50};
51
Laurent Pinchartc0efd232008-06-30 15:04:50 -030052struct uvc_xu_control_mapping {
53 __u32 id;
54 __u8 name[32];
55 __u8 entity[16];
56 __u8 selector;
57
58 __u8 size;
59 __u8 offset;
Martin Rublife78d182010-10-02 19:10:16 -030060 __u32 v4l2_type;
Laurent Pinchartc0efd232008-06-30 15:04:50 -030061 __u32 data_type;
Laurent Pinchart561474c2010-02-18 16:38:52 -030062
63 struct uvc_menu_info __user *menu_info;
64 __u32 menu_count;
65
66 __u32 reserved[4];
Laurent Pinchartc0efd232008-06-30 15:04:50 -030067};
68
69struct uvc_xu_control {
70 __u8 unit;
71 __u8 selector;
72 __u16 size;
73 __u8 __user *data;
74};
75
Martin Rublife78d182010-10-02 19:10:16 -030076struct uvc_xu_control_query {
77 __u8 unit;
78 __u8 selector;
79 __u8 query;
80 __u16 size;
81 __u8 __user *data;
82};
83
Laurent Pinchartc0efd232008-06-30 15:04:50 -030084#define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info)
Laurent Pinchart561474c2010-02-18 16:38:52 -030085#define UVCIOC_CTRL_MAP_OLD _IOWR('U', 2, struct uvc_xu_control_mapping_old)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030086#define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping)
87#define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control)
88#define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control)
Martin Rublife78d182010-10-02 19:10:16 -030089#define UVCIOC_CTRL_QUERY _IOWR('U', 5, struct uvc_xu_control_query)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030090
91#ifdef __KERNEL__
92
93#include <linux/poll.h>
Laurent Pinchartde05f632009-06-26 12:15:38 -030094#include <linux/usb/video.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030095
96/* --------------------------------------------------------------------------
97 * UVC constants
98 */
99
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300100#define UVC_TERM_INPUT 0x0000
101#define UVC_TERM_OUTPUT 0x8000
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300102#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300103
104#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
105#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
106#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
107#define UVC_ENTITY_IS_ITERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -0300108 (UVC_ENTITY_IS_TERM(entity) && \
109 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300110#define UVC_ENTITY_IS_OTERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -0300111 (UVC_ENTITY_IS_TERM(entity) && \
112 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300113
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300114
115/* ------------------------------------------------------------------------
116 * GUIDs
117 */
118#define UVC_GUID_UVC_CAMERA \
119 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
121#define UVC_GUID_UVC_OUTPUT \
122 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
124#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
125 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
127#define UVC_GUID_UVC_PROCESSING \
128 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
130#define UVC_GUID_UVC_SELECTOR \
131 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
133
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300134#define UVC_GUID_FORMAT_MJPEG \
135 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
136 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
137#define UVC_GUID_FORMAT_YUY2 \
138 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
139 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Daniel Ritz68f194e2009-12-12 14:57:17 -0300140#define UVC_GUID_FORMAT_YUY2_ISIGHT \
141 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
142 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300143#define UVC_GUID_FORMAT_NV12 \
144 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
145 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
146#define UVC_GUID_FORMAT_YV12 \
147 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
148 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
149#define UVC_GUID_FORMAT_I420 \
150 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
151 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
152#define UVC_GUID_FORMAT_UYVY \
153 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
154 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
155#define UVC_GUID_FORMAT_Y800 \
156 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
157 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchart614212062010-04-12 10:41:22 -0300158#define UVC_GUID_FORMAT_Y16 \
159 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
160 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300161#define UVC_GUID_FORMAT_BY8 \
162 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
163 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
164
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300165/* ------------------------------------------------------------------------
166 * Driver specific constants.
167 */
168
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300169#define DRIVER_VERSION_NUMBER KERNEL_VERSION(1, 0, 0)
170#define DRIVER_VERSION "v1.0.0"
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300171
172/* Number of isochronous URBs. */
173#define UVC_URBS 5
Laurent Pinchartefdc8a92009-01-18 17:46:30 -0300174/* Maximum number of packets per URB. */
175#define UVC_MAX_PACKETS 32
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300176/* Maximum number of video buffers. */
177#define UVC_MAX_VIDEO_BUFFERS 32
Ming Leia31a4052008-09-16 03:32:20 -0300178/* Maximum status buffer size in bytes of interrupt URB. */
179#define UVC_MAX_STATUS_SIZE 16
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300180
181#define UVC_CTRL_CONTROL_TIMEOUT 300
Laurent Pinchart56d15cd2010-01-19 08:59:21 -0300182#define UVC_CTRL_STREAMING_TIMEOUT 5000
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300183
Martin Rubli8fb91b32010-09-08 04:15:23 -0300184/* Maximum allowed number of control mappings per device */
185#define UVC_MAX_CONTROL_MAPPINGS 1024
186
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300187/* Devices quirks */
188#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
189#define UVC_QUIRK_PROBE_MINMAX 0x00000002
190#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
191#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
192#define UVC_QUIRK_STREAM_NO_FID 0x00000010
193#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
Laurent Pinchart50144ae2009-02-16 17:41:52 -0300194#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
Laurent Pinchartbab6f662009-07-19 18:39:56 -0300195#define UVC_QUIRK_PROBE_DEF 0x00000100
Laurent Pinchart86d8b6a2010-09-16 12:37:26 -0300196#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300197
198/* Format flags */
199#define UVC_FMT_FLAG_COMPRESSED 0x00000001
200#define UVC_FMT_FLAG_STREAM 0x00000002
201
202/* ------------------------------------------------------------------------
203 * Structures.
204 */
205
206struct uvc_device;
207
208/* TODO: Put the most frequently accessed fields at the beginning of
209 * structures to maximize cache efficiency.
210 */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300211struct uvc_control_info {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300212 struct list_head mappings;
213
214 __u8 entity[16];
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300215 __u8 index; /* Bit index in bmControls */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300216 __u8 selector;
217
218 __u16 size;
219 __u32 flags;
220};
221
222struct uvc_control_mapping {
223 struct list_head list;
224
225 struct uvc_control_info *ctrl;
226
227 __u32 id;
228 __u8 name[32];
229 __u8 entity[16];
230 __u8 selector;
231
232 __u8 size;
233 __u8 offset;
234 enum v4l2_ctrl_type v4l2_type;
235 __u32 data_type;
236
237 struct uvc_menu_info *menu_info;
238 __u32 menu_count;
Laurent Pinchart97683522008-12-16 06:46:32 -0300239
240 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
241 const __u8 *data);
242 void (*set) (struct uvc_control_mapping *mapping, __s32 value,
243 __u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300244};
245
246struct uvc_control {
247 struct uvc_entity *entity;
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300248 struct uvc_control_info info;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300249
250 __u8 index; /* Used to match the uvc_control entry with a
251 uvc_control_info. */
Laurent Pinchart071c8bb2010-09-29 16:00:08 -0300252 __u8 dirty:1,
253 loaded:1,
254 modified:1,
255 cached:1,
256 initialized:1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300257
Laurent Pinchartb30ece52010-06-18 11:31:24 -0300258 __u8 *uvc_data;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300259};
260
261struct uvc_format_desc {
262 char *name;
263 __u8 guid[16];
264 __u32 fcc;
265};
266
267/* The term 'entity' refers to both UVC units and UVC terminals.
268 *
269 * The type field is either the terminal type (wTerminalType in the terminal
270 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
271 * As the bDescriptorSubtype field is one byte long, the type value will
272 * always have a null MSB for units. All terminal types defined by the UVC
273 * specification have a non-null MSB, so it is safe to use the MSB to
274 * differentiate between units and terminals as long as the descriptor parsing
275 * code makes sure terminal types have a non-null MSB.
276 *
277 * For terminals, the type's most significant bit stores the terminal
278 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
279 * always be accessed with the UVC_ENTITY_* macros and never directly.
280 */
281
282struct uvc_entity {
283 struct list_head list; /* Entity as part of a UVC device. */
284 struct list_head chain; /* Entity as part of a video device
285 * chain. */
286 __u8 id;
287 __u16 type;
288 char name[64];
289
290 union {
291 struct {
292 __u16 wObjectiveFocalLengthMin;
293 __u16 wObjectiveFocalLengthMax;
294 __u16 wOcularFocalLength;
295 __u8 bControlSize;
296 __u8 *bmControls;
297 } camera;
298
299 struct {
300 __u8 bControlSize;
301 __u8 *bmControls;
302 __u8 bTransportModeSize;
303 __u8 *bmTransportModes;
304 } media;
305
306 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300307 } output;
308
309 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300310 __u16 wMaxMultiplier;
311 __u8 bControlSize;
312 __u8 *bmControls;
313 __u8 bmVideoStandards;
314 } processing;
315
316 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300317 } selector;
318
319 struct {
320 __u8 guidExtensionCode[16];
321 __u8 bNumControls;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300322 __u8 bControlSize;
323 __u8 *bmControls;
324 __u8 *bmControlsType;
325 } extension;
326 };
327
Laurent Pinchart8ca5a632009-11-25 12:00:30 -0300328 __u8 bNrInPins;
329 __u8 *baSourceID;
330
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300331 unsigned int ncontrols;
332 struct uvc_control *controls;
333};
334
335struct uvc_frame {
336 __u8 bFrameIndex;
337 __u8 bmCapabilities;
338 __u16 wWidth;
339 __u16 wHeight;
340 __u32 dwMinBitRate;
341 __u32 dwMaxBitRate;
342 __u32 dwMaxVideoFrameBufferSize;
343 __u8 bFrameIntervalType;
344 __u32 dwDefaultFrameInterval;
345 __u32 *dwFrameInterval;
346};
347
348struct uvc_format {
349 __u8 type;
350 __u8 index;
351 __u8 bpp;
352 __u8 colorspace;
353 __u32 fcc;
354 __u32 flags;
355
356 char name[32];
357
358 unsigned int nframes;
359 struct uvc_frame *frame;
360};
361
362struct uvc_streaming_header {
363 __u8 bNumFormats;
364 __u8 bEndpointAddress;
365 __u8 bTerminalLink;
366 __u8 bControlSize;
367 __u8 *bmaControls;
368 /* The following fields are used by input headers only. */
369 __u8 bmInfo;
370 __u8 bStillCaptureMethod;
371 __u8 bTriggerSupport;
372 __u8 bTriggerUsage;
373};
374
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300375enum uvc_buffer_state {
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300376 UVC_BUF_STATE_IDLE = 0,
377 UVC_BUF_STATE_QUEUED = 1,
378 UVC_BUF_STATE_ACTIVE = 2,
Laurent Pinchartd7c0d432009-12-16 21:20:45 -0300379 UVC_BUF_STATE_READY = 3,
380 UVC_BUF_STATE_DONE = 4,
381 UVC_BUF_STATE_ERROR = 5,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300382};
383
384struct uvc_buffer {
385 unsigned long vma_use_count;
386 struct list_head stream;
387
388 /* Touched by interrupt handler. */
389 struct v4l2_buffer buf;
390 struct list_head queue;
391 wait_queue_head_t wait;
392 enum uvc_buffer_state state;
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300393 unsigned int error;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300394};
395
396#define UVC_QUEUE_STREAMING (1 << 0)
397#define UVC_QUEUE_DISCONNECTED (1 << 1)
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300398#define UVC_QUEUE_DROP_CORRUPTED (1 << 2)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300399
400struct uvc_video_queue {
Laurent Pinchartff924202008-12-28 22:32:29 -0300401 enum v4l2_buf_type type;
402
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300403 void *mem;
404 unsigned int flags;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300405
406 unsigned int count;
407 unsigned int buf_size;
Laurent Pinchartff924202008-12-28 22:32:29 -0300408 unsigned int buf_used;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300409 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
410 struct mutex mutex; /* protects buffers and mainqueue */
411 spinlock_t irqlock; /* protects irqqueue */
412
413 struct list_head mainqueue;
414 struct list_head irqqueue;
415};
416
Laurent Pinchart8e113592009-07-01 20:24:47 -0300417struct uvc_video_chain {
418 struct uvc_device *dev;
419 struct list_head list;
420
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300421 struct list_head entities; /* All entities */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300422 struct uvc_entity *processing; /* Processing unit */
423 struct uvc_entity *selector; /* Selector unit */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300424
Laurent Pinchart27a61c12010-10-02 09:04:53 -0300425 struct mutex ctrl_mutex; /* Protects ctrl.info */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300426};
427
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300428struct uvc_streaming {
429 struct list_head list;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300430 struct uvc_device *dev;
431 struct video_device *vdev;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300432 struct uvc_video_chain *chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300433 atomic_t active;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300434
435 struct usb_interface *intf;
436 int intfnum;
437 __u16 maxpsize;
438
439 struct uvc_streaming_header header;
440 enum v4l2_buf_type type;
441
442 unsigned int nformats;
443 struct uvc_format *format;
444
445 struct uvc_streaming_control ctrl;
446 struct uvc_format *cur_format;
447 struct uvc_frame *cur_frame;
Laurent Pinchart69477562010-11-21 13:36:34 -0300448 /* Protect access to ctrl, cur_format, cur_frame and hardware video
449 * probe control.
450 */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300451 struct mutex mutex;
452
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300453 unsigned int frozen : 1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300454 struct uvc_video_queue queue;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300455 void (*decode) (struct urb *urb, struct uvc_streaming *video,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300456 struct uvc_buffer *buf);
457
458 /* Context data used by the bulk completion handler. */
459 struct {
460 __u8 header[256];
461 unsigned int header_size;
462 int skip_payload;
463 __u32 payload_size;
464 __u32 max_payload_size;
465 } bulk;
466
467 struct urb *urb[UVC_URBS];
468 char *urb_buffer[UVC_URBS];
Laurent Pincharte01117c2008-07-04 00:36:21 -0300469 dma_addr_t urb_dma[UVC_URBS];
470 unsigned int urb_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300471
Laurent Pinchart650b95f2010-10-02 11:06:05 -0300472 __u32 sequence;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300473 __u8 last_fid;
474};
475
476enum uvc_device_state {
477 UVC_DEV_DISCONNECTED = 1,
478};
479
480struct uvc_device {
481 struct usb_device *udev;
482 struct usb_interface *intf;
Laurent Pinchart44f00792008-11-08 19:14:50 -0300483 unsigned long warnings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300484 __u32 quirks;
485 int intfnum;
486 char name[32];
487
488 enum uvc_device_state state;
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300489 atomic_t users;
Martin Rubli8fb91b32010-09-08 04:15:23 -0300490 atomic_t nmappings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300491
492 /* Video control interface */
493 __u16 uvc_version;
494 __u32 clock_frequency;
495
496 struct list_head entities;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300497 struct list_head chains;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300498
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300499 /* Video Streaming interfaces */
500 struct list_head streams;
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300501 atomic_t nstreams;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300502
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300503 /* Status Interrupt Endpoint */
504 struct usb_host_endpoint *int_ep;
505 struct urb *int_urb;
Ming Leia31a4052008-09-16 03:32:20 -0300506 __u8 *status;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300507 struct input_dev *input;
Laurent Pinchartf1801522009-01-22 12:45:10 -0300508 char input_phys[64];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300509};
510
511enum uvc_handle_state {
512 UVC_HANDLE_PASSIVE = 0,
513 UVC_HANDLE_ACTIVE = 1,
514};
515
516struct uvc_fh {
Laurent Pinchart8e113592009-07-01 20:24:47 -0300517 struct uvc_video_chain *chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300518 struct uvc_streaming *stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300519 enum uvc_handle_state state;
520};
521
522struct uvc_driver {
523 struct usb_driver driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300524};
525
526/* ------------------------------------------------------------------------
527 * Debugging, printing and logging
528 */
529
530#define UVC_TRACE_PROBE (1 << 0)
531#define UVC_TRACE_DESCR (1 << 1)
532#define UVC_TRACE_CONTROL (1 << 2)
533#define UVC_TRACE_FORMAT (1 << 3)
534#define UVC_TRACE_CAPTURE (1 << 4)
535#define UVC_TRACE_CALLS (1 << 5)
536#define UVC_TRACE_IOCTL (1 << 6)
537#define UVC_TRACE_FRAME (1 << 7)
538#define UVC_TRACE_SUSPEND (1 << 8)
539#define UVC_TRACE_STATUS (1 << 9)
Laurent Pinchart663a4192009-08-06 11:41:17 -0300540#define UVC_TRACE_VIDEO (1 << 10)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300541
Laurent Pinchart44f00792008-11-08 19:14:50 -0300542#define UVC_WARN_MINMAX 0
543#define UVC_WARN_PROBE_DEF 1
544
Laurent Pinchart310fe522009-12-09 22:57:48 -0300545extern unsigned int uvc_clock_param;
Laurent Pinchart0fbd8ee2008-12-06 16:25:14 -0300546extern unsigned int uvc_no_drop_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300547extern unsigned int uvc_trace_param;
Laurent Pinchartb232a012009-10-09 20:55:23 -0300548extern unsigned int uvc_timeout_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300549
550#define uvc_trace(flag, msg...) \
551 do { \
552 if (uvc_trace_param & flag) \
553 printk(KERN_DEBUG "uvcvideo: " msg); \
554 } while (0)
555
Laurent Pinchart44f00792008-11-08 19:14:50 -0300556#define uvc_warn_once(dev, warn, msg...) \
557 do { \
558 if (!test_and_set_bit(warn, &dev->warnings)) \
559 printk(KERN_INFO "uvcvideo: " msg); \
560 } while (0)
561
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300562#define uvc_printk(level, msg...) \
563 printk(level "uvcvideo: " msg)
564
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300565/* --------------------------------------------------------------------------
566 * Internal functions.
567 */
568
569/* Core driver */
570extern struct uvc_driver uvc_driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300571
572/* Video buffers queue management. */
Laurent Pinchartff924202008-12-28 22:32:29 -0300573extern void uvc_queue_init(struct uvc_video_queue *queue,
Laurent Pinchart9bde9f22010-06-17 06:52:37 -0300574 enum v4l2_buf_type type, int drop_corrupted);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300575extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
576 unsigned int nbuffers, unsigned int buflength);
577extern int uvc_free_buffers(struct uvc_video_queue *queue);
578extern int uvc_query_buffer(struct uvc_video_queue *queue,
579 struct v4l2_buffer *v4l2_buf);
580extern int uvc_queue_buffer(struct uvc_video_queue *queue,
581 struct v4l2_buffer *v4l2_buf);
582extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
583 struct v4l2_buffer *v4l2_buf, int nonblocking);
584extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
585extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
586extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
587 struct uvc_buffer *buf);
Laurent Pinchart4aa27592010-11-21 15:18:08 -0300588extern int uvc_queue_mmap(struct uvc_video_queue *queue,
589 struct vm_area_struct *vma);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300590extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
591 struct file *file, poll_table *wait);
Laurent Pinchart23ff6042009-06-04 09:26:39 -0300592extern int uvc_queue_allocated(struct uvc_video_queue *queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300593static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
594{
595 return queue->flags & UVC_QUEUE_STREAMING;
596}
597
598/* V4L2 interface */
Hans Verkuilbec43662008-12-30 06:58:20 -0300599extern const struct v4l2_file_operations uvc_fops;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300600
601/* Video */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300602extern int uvc_video_init(struct uvc_streaming *stream);
603extern int uvc_video_suspend(struct uvc_streaming *stream);
604extern int uvc_video_resume(struct uvc_streaming *stream);
605extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
606extern int uvc_probe_video(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300607 struct uvc_streaming_control *probe);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300608extern int uvc_commit_video(struct uvc_streaming *stream,
Laurent Pinchart44f00792008-11-08 19:14:50 -0300609 struct uvc_streaming_control *ctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300610extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
611 __u8 intfnum, __u8 cs, void *data, __u16 size);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300612
613/* Status */
614extern int uvc_status_init(struct uvc_device *dev);
615extern void uvc_status_cleanup(struct uvc_device *dev);
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300616extern int uvc_status_start(struct uvc_device *dev);
617extern void uvc_status_stop(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300618extern int uvc_status_suspend(struct uvc_device *dev);
619extern int uvc_status_resume(struct uvc_device *dev);
620
621/* Controls */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300622extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300623 struct v4l2_queryctrl *v4l2_ctrl);
Laurent Pinchart23d9f3e2010-11-21 07:58:54 -0300624extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
625 struct v4l2_querymenu *query_menu);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300626
Laurent Pinchartba2fa992010-09-20 05:53:21 -0300627extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
628 const struct uvc_control_mapping *mapping);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300629extern int uvc_ctrl_init_device(struct uvc_device *dev);
630extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
631extern int uvc_ctrl_resume_device(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300632
Laurent Pinchart8e113592009-07-01 20:24:47 -0300633extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
634extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
635static inline int uvc_ctrl_commit(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300636{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300637 return __uvc_ctrl_commit(chain, 0);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300638}
Laurent Pinchart8e113592009-07-01 20:24:47 -0300639static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300640{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300641 return __uvc_ctrl_commit(chain, 1);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300642}
643
Laurent Pinchart8e113592009-07-01 20:24:47 -0300644extern int uvc_ctrl_get(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300645 struct v4l2_ext_control *xctrl);
Laurent Pinchart8e113592009-07-01 20:24:47 -0300646extern int uvc_ctrl_set(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300647 struct v4l2_ext_control *xctrl);
648
Laurent Pinchart8e113592009-07-01 20:24:47 -0300649extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
Martin Rublife78d182010-10-02 19:10:16 -0300650 struct uvc_xu_control_query *xqry);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300651
652/* Utility functions */
653extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
654 unsigned int n_terms, unsigned int threshold);
655extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
656 uint32_t denominator);
657extern struct usb_host_endpoint *uvc_find_endpoint(
658 struct usb_host_interface *alts, __u8 epaddr);
659
660/* Quirks support */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300661void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300662 struct uvc_buffer *buf);
663
664#endif /* __KERNEL__ */
665
666#endif
Hans Verkuilf87086e2008-07-18 00:50:58 -0300667