blob: d0d3e25e1c0922c9eabe76d01b6db6bef79af5ed [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
43struct uvc_xu_control_mapping {
44 __u32 id;
45 __u8 name[32];
46 __u8 entity[16];
47 __u8 selector;
48
49 __u8 size;
50 __u8 offset;
51 enum v4l2_ctrl_type v4l2_type;
52 __u32 data_type;
53};
54
55struct uvc_xu_control {
56 __u8 unit;
57 __u8 selector;
58 __u16 size;
59 __u8 __user *data;
60};
61
62#define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info)
63#define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping)
64#define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control)
65#define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control)
66
67#ifdef __KERNEL__
68
69#include <linux/poll.h>
Laurent Pinchartde05f632009-06-26 12:15:38 -030070#include <linux/usb/video.h>
Laurent Pinchartc0efd232008-06-30 15:04:50 -030071
72/* --------------------------------------------------------------------------
73 * UVC constants
74 */
75
Laurent Pinchartc0efd232008-06-30 15:04:50 -030076#define UVC_TERM_INPUT 0x0000
77#define UVC_TERM_OUTPUT 0x8000
Laurent Pinchart6241d8c2009-11-25 12:00:22 -030078#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030079
80#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
81#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
82#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
83#define UVC_ENTITY_IS_ITERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -030084 (UVC_ENTITY_IS_TERM(entity) && \
85 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030086#define UVC_ENTITY_IS_OTERM(entity) \
Laurent Pinchart8e113592009-07-01 20:24:47 -030087 (UVC_ENTITY_IS_TERM(entity) && \
88 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
Laurent Pinchartc0efd232008-06-30 15:04:50 -030089
Laurent Pinchartc0efd232008-06-30 15:04:50 -030090
91/* ------------------------------------------------------------------------
92 * GUIDs
93 */
94#define UVC_GUID_UVC_CAMERA \
95 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
97#define UVC_GUID_UVC_OUTPUT \
98 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
100#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
101 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
103#define UVC_GUID_UVC_PROCESSING \
104 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
106#define UVC_GUID_UVC_SELECTOR \
107 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
109
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300110#define UVC_GUID_FORMAT_MJPEG \
111 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
112 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
113#define UVC_GUID_FORMAT_YUY2 \
114 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
115 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
Daniel Ritz68f194e2009-12-12 14:57:17 -0300116#define UVC_GUID_FORMAT_YUY2_ISIGHT \
117 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
118 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300119#define UVC_GUID_FORMAT_NV12 \
120 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
121 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
122#define UVC_GUID_FORMAT_YV12 \
123 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
124 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
125#define UVC_GUID_FORMAT_I420 \
126 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
127 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
128#define UVC_GUID_FORMAT_UYVY \
129 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
130 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
131#define UVC_GUID_FORMAT_Y800 \
132 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
133 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
134#define UVC_GUID_FORMAT_BY8 \
135 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
136 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
137
138
139/* ------------------------------------------------------------------------
140 * Driver specific constants.
141 */
142
143#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
144
145/* Number of isochronous URBs. */
146#define UVC_URBS 5
Laurent Pinchartefdc8a92009-01-18 17:46:30 -0300147/* Maximum number of packets per URB. */
148#define UVC_MAX_PACKETS 32
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300149/* Maximum number of video buffers. */
150#define UVC_MAX_VIDEO_BUFFERS 32
Ming Leia31a4052008-09-16 03:32:20 -0300151/* Maximum status buffer size in bytes of interrupt URB. */
152#define UVC_MAX_STATUS_SIZE 16
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300153
154#define UVC_CTRL_CONTROL_TIMEOUT 300
Laurent Pinchart56d15cd2010-01-19 08:59:21 -0300155#define UVC_CTRL_STREAMING_TIMEOUT 5000
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300156
157/* Devices quirks */
158#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
159#define UVC_QUIRK_PROBE_MINMAX 0x00000002
160#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
161#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
162#define UVC_QUIRK_STREAM_NO_FID 0x00000010
163#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
Laurent Pinchart50144ae2009-02-16 17:41:52 -0300164#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
Laurent Pinchartbab6f662009-07-19 18:39:56 -0300165#define UVC_QUIRK_PROBE_DEF 0x00000100
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300166
167/* Format flags */
168#define UVC_FMT_FLAG_COMPRESSED 0x00000001
169#define UVC_FMT_FLAG_STREAM 0x00000002
170
171/* ------------------------------------------------------------------------
172 * Structures.
173 */
174
175struct uvc_device;
176
177/* TODO: Put the most frequently accessed fields at the beginning of
178 * structures to maximize cache efficiency.
179 */
180struct uvc_streaming_control {
181 __u16 bmHint;
182 __u8 bFormatIndex;
183 __u8 bFrameIndex;
184 __u32 dwFrameInterval;
185 __u16 wKeyFrameRate;
186 __u16 wPFrameRate;
187 __u16 wCompQuality;
188 __u16 wCompWindowSize;
189 __u16 wDelay;
190 __u32 dwMaxVideoFrameSize;
191 __u32 dwMaxPayloadTransferSize;
192 __u32 dwClockFrequency;
193 __u8 bmFramingInfo;
194 __u8 bPreferedVersion;
195 __u8 bMinVersion;
196 __u8 bMaxVersion;
197};
198
199struct uvc_menu_info {
200 __u32 value;
201 __u8 name[32];
202};
203
204struct uvc_control_info {
205 struct list_head list;
206 struct list_head mappings;
207
208 __u8 entity[16];
209 __u8 index;
210 __u8 selector;
211
212 __u16 size;
213 __u32 flags;
214};
215
216struct uvc_control_mapping {
217 struct list_head list;
218
219 struct uvc_control_info *ctrl;
220
221 __u32 id;
222 __u8 name[32];
223 __u8 entity[16];
224 __u8 selector;
225
226 __u8 size;
227 __u8 offset;
228 enum v4l2_ctrl_type v4l2_type;
229 __u32 data_type;
230
231 struct uvc_menu_info *menu_info;
232 __u32 menu_count;
Laurent Pinchart97683522008-12-16 06:46:32 -0300233
234 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
235 const __u8 *data);
236 void (*set) (struct uvc_control_mapping *mapping, __s32 value,
237 __u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300238};
239
240struct uvc_control {
241 struct uvc_entity *entity;
242 struct uvc_control_info *info;
243
244 __u8 index; /* Used to match the uvc_control entry with a
245 uvc_control_info. */
246 __u8 dirty : 1,
247 loaded : 1,
248 modified : 1;
249
250 __u8 *data;
251};
252
253struct uvc_format_desc {
254 char *name;
255 __u8 guid[16];
256 __u32 fcc;
257};
258
259/* The term 'entity' refers to both UVC units and UVC terminals.
260 *
261 * The type field is either the terminal type (wTerminalType in the terminal
262 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
263 * As the bDescriptorSubtype field is one byte long, the type value will
264 * always have a null MSB for units. All terminal types defined by the UVC
265 * specification have a non-null MSB, so it is safe to use the MSB to
266 * differentiate between units and terminals as long as the descriptor parsing
267 * code makes sure terminal types have a non-null MSB.
268 *
269 * For terminals, the type's most significant bit stores the terminal
270 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
271 * always be accessed with the UVC_ENTITY_* macros and never directly.
272 */
273
274struct uvc_entity {
275 struct list_head list; /* Entity as part of a UVC device. */
276 struct list_head chain; /* Entity as part of a video device
277 * chain. */
278 __u8 id;
279 __u16 type;
280 char name[64];
281
282 union {
283 struct {
284 __u16 wObjectiveFocalLengthMin;
285 __u16 wObjectiveFocalLengthMax;
286 __u16 wOcularFocalLength;
287 __u8 bControlSize;
288 __u8 *bmControls;
289 } camera;
290
291 struct {
292 __u8 bControlSize;
293 __u8 *bmControls;
294 __u8 bTransportModeSize;
295 __u8 *bmTransportModes;
296 } media;
297
298 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300299 } output;
300
301 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300302 __u16 wMaxMultiplier;
303 __u8 bControlSize;
304 __u8 *bmControls;
305 __u8 bmVideoStandards;
306 } processing;
307
308 struct {
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300309 } selector;
310
311 struct {
312 __u8 guidExtensionCode[16];
313 __u8 bNumControls;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300314 __u8 bControlSize;
315 __u8 *bmControls;
316 __u8 *bmControlsType;
317 } extension;
318 };
319
Laurent Pinchart8ca5a632009-11-25 12:00:30 -0300320 __u8 bNrInPins;
321 __u8 *baSourceID;
322
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300323 unsigned int ncontrols;
324 struct uvc_control *controls;
325};
326
327struct uvc_frame {
328 __u8 bFrameIndex;
329 __u8 bmCapabilities;
330 __u16 wWidth;
331 __u16 wHeight;
332 __u32 dwMinBitRate;
333 __u32 dwMaxBitRate;
334 __u32 dwMaxVideoFrameBufferSize;
335 __u8 bFrameIntervalType;
336 __u32 dwDefaultFrameInterval;
337 __u32 *dwFrameInterval;
338};
339
340struct uvc_format {
341 __u8 type;
342 __u8 index;
343 __u8 bpp;
344 __u8 colorspace;
345 __u32 fcc;
346 __u32 flags;
347
348 char name[32];
349
350 unsigned int nframes;
351 struct uvc_frame *frame;
352};
353
354struct uvc_streaming_header {
355 __u8 bNumFormats;
356 __u8 bEndpointAddress;
357 __u8 bTerminalLink;
358 __u8 bControlSize;
359 __u8 *bmaControls;
360 /* The following fields are used by input headers only. */
361 __u8 bmInfo;
362 __u8 bStillCaptureMethod;
363 __u8 bTriggerSupport;
364 __u8 bTriggerUsage;
365};
366
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300367enum uvc_buffer_state {
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300368 UVC_BUF_STATE_IDLE = 0,
369 UVC_BUF_STATE_QUEUED = 1,
370 UVC_BUF_STATE_ACTIVE = 2,
Laurent Pinchartd7c0d432009-12-16 21:20:45 -0300371 UVC_BUF_STATE_READY = 3,
372 UVC_BUF_STATE_DONE = 4,
373 UVC_BUF_STATE_ERROR = 5,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300374};
375
376struct uvc_buffer {
377 unsigned long vma_use_count;
378 struct list_head stream;
379
380 /* Touched by interrupt handler. */
381 struct v4l2_buffer buf;
382 struct list_head queue;
383 wait_queue_head_t wait;
384 enum uvc_buffer_state state;
385};
386
387#define UVC_QUEUE_STREAMING (1 << 0)
388#define UVC_QUEUE_DISCONNECTED (1 << 1)
389#define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
390
391struct uvc_video_queue {
Laurent Pinchartff924202008-12-28 22:32:29 -0300392 enum v4l2_buf_type type;
393
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300394 void *mem;
395 unsigned int flags;
396 __u32 sequence;
397
398 unsigned int count;
399 unsigned int buf_size;
Laurent Pinchartff924202008-12-28 22:32:29 -0300400 unsigned int buf_used;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300401 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
402 struct mutex mutex; /* protects buffers and mainqueue */
403 spinlock_t irqlock; /* protects irqqueue */
404
405 struct list_head mainqueue;
406 struct list_head irqqueue;
407};
408
Laurent Pinchart8e113592009-07-01 20:24:47 -0300409struct uvc_video_chain {
410 struct uvc_device *dev;
411 struct list_head list;
412
Laurent Pinchart6241d8c2009-11-25 12:00:22 -0300413 struct list_head entities; /* All entities */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300414 struct uvc_entity *processing; /* Processing unit */
415 struct uvc_entity *selector; /* Selector unit */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300416
417 struct mutex ctrl_mutex;
418};
419
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300420struct uvc_streaming {
421 struct list_head list;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300422 struct uvc_device *dev;
423 struct video_device *vdev;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300424 struct uvc_video_chain *chain;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300425 atomic_t active;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300426
427 struct usb_interface *intf;
428 int intfnum;
429 __u16 maxpsize;
430
431 struct uvc_streaming_header header;
432 enum v4l2_buf_type type;
433
434 unsigned int nformats;
435 struct uvc_format *format;
436
437 struct uvc_streaming_control ctrl;
438 struct uvc_format *cur_format;
439 struct uvc_frame *cur_frame;
440
441 struct mutex mutex;
442
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300443 unsigned int frozen : 1;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300444 struct uvc_video_queue queue;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300445 void (*decode) (struct urb *urb, struct uvc_streaming *video,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300446 struct uvc_buffer *buf);
447
448 /* Context data used by the bulk completion handler. */
449 struct {
450 __u8 header[256];
451 unsigned int header_size;
452 int skip_payload;
453 __u32 payload_size;
454 __u32 max_payload_size;
455 } bulk;
456
457 struct urb *urb[UVC_URBS];
458 char *urb_buffer[UVC_URBS];
Laurent Pincharte01117c2008-07-04 00:36:21 -0300459 dma_addr_t urb_dma[UVC_URBS];
460 unsigned int urb_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300461
462 __u8 last_fid;
463};
464
465enum uvc_device_state {
466 UVC_DEV_DISCONNECTED = 1,
467};
468
469struct uvc_device {
470 struct usb_device *udev;
471 struct usb_interface *intf;
Laurent Pinchart44f00792008-11-08 19:14:50 -0300472 unsigned long warnings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300473 __u32 quirks;
474 int intfnum;
475 char name[32];
476
477 enum uvc_device_state state;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300478 struct list_head list;
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300479 atomic_t users;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300480
481 /* Video control interface */
482 __u16 uvc_version;
483 __u32 clock_frequency;
484
485 struct list_head entities;
Laurent Pinchart8e113592009-07-01 20:24:47 -0300486 struct list_head chains;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300487
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300488 /* Video Streaming interfaces */
489 struct list_head streams;
Laurent Pinchart716fdee2009-09-29 21:07:19 -0300490 atomic_t nstreams;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300491
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300492 /* Status Interrupt Endpoint */
493 struct usb_host_endpoint *int_ep;
494 struct urb *int_urb;
Ming Leia31a4052008-09-16 03:32:20 -0300495 __u8 *status;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300496 struct input_dev *input;
Laurent Pinchartf1801522009-01-22 12:45:10 -0300497 char input_phys[64];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300498};
499
500enum uvc_handle_state {
501 UVC_HANDLE_PASSIVE = 0,
502 UVC_HANDLE_ACTIVE = 1,
503};
504
505struct uvc_fh {
Laurent Pinchart8e113592009-07-01 20:24:47 -0300506 struct uvc_video_chain *chain;
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300507 struct uvc_streaming *stream;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300508 enum uvc_handle_state state;
509};
510
511struct uvc_driver {
512 struct usb_driver driver;
513
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300514 struct list_head devices; /* struct uvc_device list */
515 struct list_head controls; /* struct uvc_control_info list */
516 struct mutex ctrl_mutex; /* protects controls and devices
517 lists */
518};
519
520/* ------------------------------------------------------------------------
521 * Debugging, printing and logging
522 */
523
524#define UVC_TRACE_PROBE (1 << 0)
525#define UVC_TRACE_DESCR (1 << 1)
526#define UVC_TRACE_CONTROL (1 << 2)
527#define UVC_TRACE_FORMAT (1 << 3)
528#define UVC_TRACE_CAPTURE (1 << 4)
529#define UVC_TRACE_CALLS (1 << 5)
530#define UVC_TRACE_IOCTL (1 << 6)
531#define UVC_TRACE_FRAME (1 << 7)
532#define UVC_TRACE_SUSPEND (1 << 8)
533#define UVC_TRACE_STATUS (1 << 9)
Laurent Pinchart663a4192009-08-06 11:41:17 -0300534#define UVC_TRACE_VIDEO (1 << 10)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300535
Laurent Pinchart44f00792008-11-08 19:14:50 -0300536#define UVC_WARN_MINMAX 0
537#define UVC_WARN_PROBE_DEF 1
538
Laurent Pinchart310fe522009-12-09 22:57:48 -0300539extern unsigned int uvc_clock_param;
Laurent Pinchart0fbd8ee2008-12-06 16:25:14 -0300540extern unsigned int uvc_no_drop_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300541extern unsigned int uvc_trace_param;
Laurent Pinchartb232a012009-10-09 20:55:23 -0300542extern unsigned int uvc_timeout_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300543
544#define uvc_trace(flag, msg...) \
545 do { \
546 if (uvc_trace_param & flag) \
547 printk(KERN_DEBUG "uvcvideo: " msg); \
548 } while (0)
549
Laurent Pinchart44f00792008-11-08 19:14:50 -0300550#define uvc_warn_once(dev, warn, msg...) \
551 do { \
552 if (!test_and_set_bit(warn, &dev->warnings)) \
553 printk(KERN_INFO "uvcvideo: " msg); \
554 } while (0)
555
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300556#define uvc_printk(level, msg...) \
557 printk(level "uvcvideo: " msg)
558
559#define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
560 "%02x%02x%02x%02x%02x%02x"
561#define UVC_GUID_ARGS(guid) \
562 (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
563 (guid)[5], (guid)[4], \
564 (guid)[7], (guid)[6], \
565 (guid)[8], (guid)[9], \
566 (guid)[10], (guid)[11], (guid)[12], \
567 (guid)[13], (guid)[14], (guid)[15]
568
569/* --------------------------------------------------------------------------
570 * Internal functions.
571 */
572
573/* Core driver */
574extern struct uvc_driver uvc_driver;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300575
576/* Video buffers queue management. */
Laurent Pinchartff924202008-12-28 22:32:29 -0300577extern void uvc_queue_init(struct uvc_video_queue *queue,
578 enum v4l2_buf_type type);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300579extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
580 unsigned int nbuffers, unsigned int buflength);
581extern int uvc_free_buffers(struct uvc_video_queue *queue);
582extern int uvc_query_buffer(struct uvc_video_queue *queue,
583 struct v4l2_buffer *v4l2_buf);
584extern int uvc_queue_buffer(struct uvc_video_queue *queue,
585 struct v4l2_buffer *v4l2_buf);
586extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
587 struct v4l2_buffer *v4l2_buf, int nonblocking);
588extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
589extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
590extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
591 struct uvc_buffer *buf);
592extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
593 struct file *file, poll_table *wait);
Laurent Pinchart23ff6042009-06-04 09:26:39 -0300594extern int uvc_queue_allocated(struct uvc_video_queue *queue);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300595static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
596{
597 return queue->flags & UVC_QUEUE_STREAMING;
598}
599
600/* V4L2 interface */
Hans Verkuilbec43662008-12-30 06:58:20 -0300601extern const struct v4l2_file_operations uvc_fops;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300602
603/* Video */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300604extern int uvc_video_init(struct uvc_streaming *stream);
605extern int uvc_video_suspend(struct uvc_streaming *stream);
606extern int uvc_video_resume(struct uvc_streaming *stream);
607extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
608extern int uvc_probe_video(struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300609 struct uvc_streaming_control *probe);
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300610extern int uvc_commit_video(struct uvc_streaming *stream,
Laurent Pinchart44f00792008-11-08 19:14:50 -0300611 struct uvc_streaming_control *ctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300612extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
613 __u8 intfnum, __u8 cs, void *data, __u16 size);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300614
615/* Status */
616extern int uvc_status_init(struct uvc_device *dev);
617extern void uvc_status_cleanup(struct uvc_device *dev);
Laurent Pinchart04a37e02009-05-19 10:08:03 -0300618extern int uvc_status_start(struct uvc_device *dev);
619extern void uvc_status_stop(struct uvc_device *dev);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300620extern int uvc_status_suspend(struct uvc_device *dev);
621extern int uvc_status_resume(struct uvc_device *dev);
622
623/* Controls */
Laurent Pinchart8e113592009-07-01 20:24:47 -0300624extern struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300625 __u32 v4l2_id, struct uvc_control_mapping **mapping);
Laurent Pinchart8e113592009-07-01 20:24:47 -0300626extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300627 struct v4l2_queryctrl *v4l2_ctrl);
628
629extern int uvc_ctrl_add_info(struct uvc_control_info *info);
630extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
631extern int uvc_ctrl_init_device(struct uvc_device *dev);
632extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
633extern int uvc_ctrl_resume_device(struct uvc_device *dev);
634extern void uvc_ctrl_init(void);
635
Laurent Pinchart8e113592009-07-01 20:24:47 -0300636extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
637extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
638static inline int uvc_ctrl_commit(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300639{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300640 return __uvc_ctrl_commit(chain, 0);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300641}
Laurent Pinchart8e113592009-07-01 20:24:47 -0300642static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain)
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300643{
Laurent Pinchart8e113592009-07-01 20:24:47 -0300644 return __uvc_ctrl_commit(chain, 1);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300645}
646
Laurent Pinchart8e113592009-07-01 20:24:47 -0300647extern int uvc_ctrl_get(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300648 struct v4l2_ext_control *xctrl);
Laurent Pinchart8e113592009-07-01 20:24:47 -0300649extern int uvc_ctrl_set(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300650 struct v4l2_ext_control *xctrl);
651
Laurent Pinchart8e113592009-07-01 20:24:47 -0300652extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300653 struct uvc_xu_control *ctrl, int set);
654
655/* Utility functions */
656extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
657 unsigned int n_terms, unsigned int threshold);
658extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
659 uint32_t denominator);
660extern struct usb_host_endpoint *uvc_find_endpoint(
661 struct usb_host_interface *alts, __u8 epaddr);
662
663/* Quirks support */
Laurent Pinchart35f02a62009-06-28 08:37:50 -0300664void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300665 struct uvc_buffer *buf);
666
667#endif /* __KERNEL__ */
668
669#endif
Hans Verkuilf87086e2008-07-18 00:50:58 -0300670