blob: 6f55c4d49cf408007c4730a4a416bc2341a50243 [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>
70
71/* --------------------------------------------------------------------------
72 * UVC constants
73 */
74
Laurent Pinchart2c2d2642009-01-03 19:12:40 -030075#define SC_UNDEFINED 0x00
76#define SC_VIDEOCONTROL 0x01
77#define SC_VIDEOSTREAMING 0x02
78#define SC_VIDEO_INTERFACE_COLLECTION 0x03
Laurent Pinchartc0efd232008-06-30 15:04:50 -030079
Laurent Pinchart2c2d2642009-01-03 19:12:40 -030080#define PC_PROTOCOL_UNDEFINED 0x00
Laurent Pinchartc0efd232008-06-30 15:04:50 -030081
Laurent Pinchart2c2d2642009-01-03 19:12:40 -030082#define CS_UNDEFINED 0x20
83#define CS_DEVICE 0x21
84#define CS_CONFIGURATION 0x22
85#define CS_STRING 0x23
86#define CS_INTERFACE 0x24
87#define CS_ENDPOINT 0x25
Laurent Pinchartc0efd232008-06-30 15:04:50 -030088
89/* VideoControl class specific interface descriptor */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -030090#define VC_DESCRIPTOR_UNDEFINED 0x00
91#define VC_HEADER 0x01
92#define VC_INPUT_TERMINAL 0x02
93#define VC_OUTPUT_TERMINAL 0x03
94#define VC_SELECTOR_UNIT 0x04
95#define VC_PROCESSING_UNIT 0x05
96#define VC_EXTENSION_UNIT 0x06
Laurent Pinchartc0efd232008-06-30 15:04:50 -030097
98/* VideoStreaming class specific interface descriptor */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -030099#define VS_UNDEFINED 0x00
100#define VS_INPUT_HEADER 0x01
101#define VS_OUTPUT_HEADER 0x02
102#define VS_STILL_IMAGE_FRAME 0x03
103#define VS_FORMAT_UNCOMPRESSED 0x04
104#define VS_FRAME_UNCOMPRESSED 0x05
105#define VS_FORMAT_MJPEG 0x06
106#define VS_FRAME_MJPEG 0x07
107#define VS_FORMAT_MPEG2TS 0x0a
108#define VS_FORMAT_DV 0x0c
109#define VS_COLORFORMAT 0x0d
110#define VS_FORMAT_FRAME_BASED 0x10
111#define VS_FRAME_FRAME_BASED 0x11
112#define VS_FORMAT_STREAM_BASED 0x12
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300113
114/* Endpoint type */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300115#define EP_UNDEFINED 0x00
116#define EP_GENERAL 0x01
117#define EP_ENDPOINT 0x02
118#define EP_INTERRUPT 0x03
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300119
120/* Request codes */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300121#define RC_UNDEFINED 0x00
122#define SET_CUR 0x01
123#define GET_CUR 0x81
124#define GET_MIN 0x82
125#define GET_MAX 0x83
126#define GET_RES 0x84
127#define GET_LEN 0x85
128#define GET_INFO 0x86
129#define GET_DEF 0x87
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300130
131/* VideoControl interface controls */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300132#define VC_CONTROL_UNDEFINED 0x00
133#define VC_VIDEO_POWER_MODE_CONTROL 0x01
134#define VC_REQUEST_ERROR_CODE_CONTROL 0x02
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300135
136/* Terminal controls */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300137#define TE_CONTROL_UNDEFINED 0x00
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300138
139/* Selector Unit controls */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300140#define SU_CONTROL_UNDEFINED 0x00
141#define SU_INPUT_SELECT_CONTROL 0x01
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300142
143/* Camera Terminal controls */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300144#define CT_CONTROL_UNDEFINED 0x00
145#define CT_SCANNING_MODE_CONTROL 0x01
146#define CT_AE_MODE_CONTROL 0x02
147#define CT_AE_PRIORITY_CONTROL 0x03
148#define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04
149#define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05
150#define CT_FOCUS_ABSOLUTE_CONTROL 0x06
151#define CT_FOCUS_RELATIVE_CONTROL 0x07
152#define CT_FOCUS_AUTO_CONTROL 0x08
153#define CT_IRIS_ABSOLUTE_CONTROL 0x09
154#define CT_IRIS_RELATIVE_CONTROL 0x0a
155#define CT_ZOOM_ABSOLUTE_CONTROL 0x0b
156#define CT_ZOOM_RELATIVE_CONTROL 0x0c
157#define CT_PANTILT_ABSOLUTE_CONTROL 0x0d
158#define CT_PANTILT_RELATIVE_CONTROL 0x0e
159#define CT_ROLL_ABSOLUTE_CONTROL 0x0f
160#define CT_ROLL_RELATIVE_CONTROL 0x10
161#define CT_PRIVACY_CONTROL 0x11
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300162
163/* Processing Unit controls */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300164#define PU_CONTROL_UNDEFINED 0x00
165#define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01
166#define PU_BRIGHTNESS_CONTROL 0x02
167#define PU_CONTRAST_CONTROL 0x03
168#define PU_GAIN_CONTROL 0x04
169#define PU_POWER_LINE_FREQUENCY_CONTROL 0x05
170#define PU_HUE_CONTROL 0x06
171#define PU_SATURATION_CONTROL 0x07
172#define PU_SHARPNESS_CONTROL 0x08
173#define PU_GAMMA_CONTROL 0x09
174#define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a
175#define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b
176#define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c
177#define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d
178#define PU_DIGITAL_MULTIPLIER_CONTROL 0x0e
179#define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f
180#define PU_HUE_AUTO_CONTROL 0x10
181#define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11
182#define PU_ANALOG_LOCK_STATUS_CONTROL 0x12
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300183
184#define LXU_MOTOR_PANTILT_RELATIVE_CONTROL 0x01
185#define LXU_MOTOR_PANTILT_RESET_CONTROL 0x02
186#define LXU_MOTOR_FOCUS_MOTOR_CONTROL 0x03
187
188/* VideoStreaming interface controls */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300189#define VS_CONTROL_UNDEFINED 0x00
190#define VS_PROBE_CONTROL 0x01
191#define VS_COMMIT_CONTROL 0x02
192#define VS_STILL_PROBE_CONTROL 0x03
193#define VS_STILL_COMMIT_CONTROL 0x04
194#define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05
195#define VS_STREAM_ERROR_CODE_CONTROL 0x06
196#define VS_GENERATE_KEY_FRAME_CONTROL 0x07
197#define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08
198#define VS_SYNC_DELAY_CONTROL 0x09
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300199
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300200#define TT_VENDOR_SPECIFIC 0x0100
201#define TT_STREAMING 0x0101
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300202
203/* Input Terminal types */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300204#define ITT_VENDOR_SPECIFIC 0x0200
205#define ITT_CAMERA 0x0201
206#define ITT_MEDIA_TRANSPORT_INPUT 0x0202
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300207
208/* Output Terminal types */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300209#define OTT_VENDOR_SPECIFIC 0x0300
210#define OTT_DISPLAY 0x0301
211#define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300212
213/* External Terminal types */
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300214#define EXTERNAL_VENDOR_SPECIFIC 0x0400
215#define COMPOSITE_CONNECTOR 0x0401
216#define SVIDEO_CONNECTOR 0x0402
217#define COMPONENT_CONNECTOR 0x0403
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300218
219#define UVC_TERM_INPUT 0x0000
220#define UVC_TERM_OUTPUT 0x8000
221
222#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
223#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
224#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
225#define UVC_ENTITY_IS_ITERM(entity) \
226 (((entity)->type & 0x8000) == UVC_TERM_INPUT)
227#define UVC_ENTITY_IS_OTERM(entity) \
228 (((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
229
230#define UVC_STATUS_TYPE_CONTROL 1
231#define UVC_STATUS_TYPE_STREAMING 2
232
233/* ------------------------------------------------------------------------
234 * GUIDs
235 */
236#define UVC_GUID_UVC_CAMERA \
237 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
239#define UVC_GUID_UVC_OUTPUT \
240 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
242#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
243 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
245#define UVC_GUID_UVC_PROCESSING \
246 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
248#define UVC_GUID_UVC_SELECTOR \
249 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
251
252#define UVC_GUID_LOGITECH_DEV_INFO \
253 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
254 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1e}
255#define UVC_GUID_LOGITECH_USER_HW \
256 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
257 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1f}
258#define UVC_GUID_LOGITECH_VIDEO \
259 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
260 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50}
261#define UVC_GUID_LOGITECH_MOTOR \
262 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
263 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56}
264
265#define UVC_GUID_FORMAT_MJPEG \
266 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
267 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
268#define UVC_GUID_FORMAT_YUY2 \
269 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
270 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
271#define UVC_GUID_FORMAT_NV12 \
272 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
273 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
274#define UVC_GUID_FORMAT_YV12 \
275 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
276 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
277#define UVC_GUID_FORMAT_I420 \
278 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
279 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
280#define UVC_GUID_FORMAT_UYVY \
281 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
282 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
283#define UVC_GUID_FORMAT_Y800 \
284 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
285 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
286#define UVC_GUID_FORMAT_BY8 \
287 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
288 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
289
290
291/* ------------------------------------------------------------------------
292 * Driver specific constants.
293 */
294
295#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
296
297/* Number of isochronous URBs. */
298#define UVC_URBS 5
Laurent Pinchartefdc8a92009-01-18 17:46:30 -0300299/* Maximum number of packets per URB. */
300#define UVC_MAX_PACKETS 32
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300301/* Maximum number of video buffers. */
302#define UVC_MAX_VIDEO_BUFFERS 32
Ming Leia31a4052008-09-16 03:32:20 -0300303/* Maximum status buffer size in bytes of interrupt URB. */
304#define UVC_MAX_STATUS_SIZE 16
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300305
306#define UVC_CTRL_CONTROL_TIMEOUT 300
307#define UVC_CTRL_STREAMING_TIMEOUT 1000
308
309/* Devices quirks */
310#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
311#define UVC_QUIRK_PROBE_MINMAX 0x00000002
312#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
313#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
314#define UVC_QUIRK_STREAM_NO_FID 0x00000010
315#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
Laurent Pinchart2bdd29c2008-12-06 17:43:40 -0300316#define UVC_QUIRK_PRUNE_CONTROLS 0x00000040
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300317
318/* Format flags */
319#define UVC_FMT_FLAG_COMPRESSED 0x00000001
320#define UVC_FMT_FLAG_STREAM 0x00000002
321
322/* ------------------------------------------------------------------------
323 * Structures.
324 */
325
326struct uvc_device;
327
328/* TODO: Put the most frequently accessed fields at the beginning of
329 * structures to maximize cache efficiency.
330 */
331struct uvc_streaming_control {
332 __u16 bmHint;
333 __u8 bFormatIndex;
334 __u8 bFrameIndex;
335 __u32 dwFrameInterval;
336 __u16 wKeyFrameRate;
337 __u16 wPFrameRate;
338 __u16 wCompQuality;
339 __u16 wCompWindowSize;
340 __u16 wDelay;
341 __u32 dwMaxVideoFrameSize;
342 __u32 dwMaxPayloadTransferSize;
343 __u32 dwClockFrequency;
344 __u8 bmFramingInfo;
345 __u8 bPreferedVersion;
346 __u8 bMinVersion;
347 __u8 bMaxVersion;
348};
349
350struct uvc_menu_info {
351 __u32 value;
352 __u8 name[32];
353};
354
355struct uvc_control_info {
356 struct list_head list;
357 struct list_head mappings;
358
359 __u8 entity[16];
360 __u8 index;
361 __u8 selector;
362
363 __u16 size;
364 __u32 flags;
365};
366
367struct uvc_control_mapping {
368 struct list_head list;
369
370 struct uvc_control_info *ctrl;
371
372 __u32 id;
373 __u8 name[32];
374 __u8 entity[16];
375 __u8 selector;
376
377 __u8 size;
378 __u8 offset;
379 enum v4l2_ctrl_type v4l2_type;
380 __u32 data_type;
381
382 struct uvc_menu_info *menu_info;
383 __u32 menu_count;
Laurent Pinchart97683522008-12-16 06:46:32 -0300384
385 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
386 const __u8 *data);
387 void (*set) (struct uvc_control_mapping *mapping, __s32 value,
388 __u8 *data);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300389};
390
391struct uvc_control {
392 struct uvc_entity *entity;
393 struct uvc_control_info *info;
394
395 __u8 index; /* Used to match the uvc_control entry with a
396 uvc_control_info. */
397 __u8 dirty : 1,
398 loaded : 1,
399 modified : 1;
400
401 __u8 *data;
402};
403
404struct uvc_format_desc {
405 char *name;
406 __u8 guid[16];
407 __u32 fcc;
408};
409
410/* The term 'entity' refers to both UVC units and UVC terminals.
411 *
412 * The type field is either the terminal type (wTerminalType in the terminal
413 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
414 * As the bDescriptorSubtype field is one byte long, the type value will
415 * always have a null MSB for units. All terminal types defined by the UVC
416 * specification have a non-null MSB, so it is safe to use the MSB to
417 * differentiate between units and terminals as long as the descriptor parsing
418 * code makes sure terminal types have a non-null MSB.
419 *
420 * For terminals, the type's most significant bit stores the terminal
421 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
422 * always be accessed with the UVC_ENTITY_* macros and never directly.
423 */
424
425struct uvc_entity {
426 struct list_head list; /* Entity as part of a UVC device. */
427 struct list_head chain; /* Entity as part of a video device
428 * chain. */
429 __u8 id;
430 __u16 type;
431 char name[64];
432
433 union {
434 struct {
435 __u16 wObjectiveFocalLengthMin;
436 __u16 wObjectiveFocalLengthMax;
437 __u16 wOcularFocalLength;
438 __u8 bControlSize;
439 __u8 *bmControls;
440 } camera;
441
442 struct {
443 __u8 bControlSize;
444 __u8 *bmControls;
445 __u8 bTransportModeSize;
446 __u8 *bmTransportModes;
447 } media;
448
449 struct {
450 __u8 bSourceID;
451 } output;
452
453 struct {
454 __u8 bSourceID;
455 __u16 wMaxMultiplier;
456 __u8 bControlSize;
457 __u8 *bmControls;
458 __u8 bmVideoStandards;
459 } processing;
460
461 struct {
462 __u8 bNrInPins;
463 __u8 *baSourceID;
464 } selector;
465
466 struct {
467 __u8 guidExtensionCode[16];
468 __u8 bNumControls;
469 __u8 bNrInPins;
470 __u8 *baSourceID;
471 __u8 bControlSize;
472 __u8 *bmControls;
473 __u8 *bmControlsType;
474 } extension;
475 };
476
477 unsigned int ncontrols;
478 struct uvc_control *controls;
479};
480
481struct uvc_frame {
482 __u8 bFrameIndex;
483 __u8 bmCapabilities;
484 __u16 wWidth;
485 __u16 wHeight;
486 __u32 dwMinBitRate;
487 __u32 dwMaxBitRate;
488 __u32 dwMaxVideoFrameBufferSize;
489 __u8 bFrameIntervalType;
490 __u32 dwDefaultFrameInterval;
491 __u32 *dwFrameInterval;
492};
493
494struct uvc_format {
495 __u8 type;
496 __u8 index;
497 __u8 bpp;
498 __u8 colorspace;
499 __u32 fcc;
500 __u32 flags;
501
502 char name[32];
503
504 unsigned int nframes;
505 struct uvc_frame *frame;
506};
507
508struct uvc_streaming_header {
509 __u8 bNumFormats;
510 __u8 bEndpointAddress;
511 __u8 bTerminalLink;
512 __u8 bControlSize;
513 __u8 *bmaControls;
514 /* The following fields are used by input headers only. */
515 __u8 bmInfo;
516 __u8 bStillCaptureMethod;
517 __u8 bTriggerSupport;
518 __u8 bTriggerUsage;
519};
520
521struct uvc_streaming {
522 struct list_head list;
523
524 struct usb_interface *intf;
525 int intfnum;
526 __u16 maxpsize;
527
528 struct uvc_streaming_header header;
Laurent Pinchartff924202008-12-28 22:32:29 -0300529 enum v4l2_buf_type type;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300530
531 unsigned int nformats;
532 struct uvc_format *format;
533
534 struct uvc_streaming_control ctrl;
535 struct uvc_format *cur_format;
536 struct uvc_frame *cur_frame;
537
538 struct mutex mutex;
539};
540
541enum uvc_buffer_state {
Laurent Pinchart2c2d2642009-01-03 19:12:40 -0300542 UVC_BUF_STATE_IDLE = 0,
543 UVC_BUF_STATE_QUEUED = 1,
544 UVC_BUF_STATE_ACTIVE = 2,
545 UVC_BUF_STATE_DONE = 3,
546 UVC_BUF_STATE_ERROR = 4,
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300547};
548
549struct uvc_buffer {
550 unsigned long vma_use_count;
551 struct list_head stream;
552
553 /* Touched by interrupt handler. */
554 struct v4l2_buffer buf;
555 struct list_head queue;
556 wait_queue_head_t wait;
557 enum uvc_buffer_state state;
558};
559
560#define UVC_QUEUE_STREAMING (1 << 0)
561#define UVC_QUEUE_DISCONNECTED (1 << 1)
562#define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
563
564struct uvc_video_queue {
Laurent Pinchartff924202008-12-28 22:32:29 -0300565 enum v4l2_buf_type type;
566
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300567 void *mem;
568 unsigned int flags;
569 __u32 sequence;
570
571 unsigned int count;
572 unsigned int buf_size;
Laurent Pinchartff924202008-12-28 22:32:29 -0300573 unsigned int buf_used;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300574 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
575 struct mutex mutex; /* protects buffers and mainqueue */
576 spinlock_t irqlock; /* protects irqqueue */
577
578 struct list_head mainqueue;
579 struct list_head irqqueue;
580};
581
582struct uvc_video_device {
583 struct uvc_device *dev;
584 struct video_device *vdev;
585 atomic_t active;
586 unsigned int frozen : 1;
587
Laurent Pinchartff924202008-12-28 22:32:29 -0300588 struct list_head iterms; /* Input terminals */
589 struct uvc_entity *oterm; /* Output terminal */
590 struct uvc_entity *sterm; /* USB streaming terminal */
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300591 struct uvc_entity *processing;
592 struct uvc_entity *selector;
593 struct list_head extensions;
594 struct mutex ctrl_mutex;
595
596 struct uvc_video_queue queue;
597
598 /* Video streaming object, must always be non-NULL. */
599 struct uvc_streaming *streaming;
600
601 void (*decode) (struct urb *urb, struct uvc_video_device *video,
602 struct uvc_buffer *buf);
603
604 /* Context data used by the bulk completion handler. */
605 struct {
606 __u8 header[256];
607 unsigned int header_size;
608 int skip_payload;
609 __u32 payload_size;
610 __u32 max_payload_size;
611 } bulk;
612
613 struct urb *urb[UVC_URBS];
614 char *urb_buffer[UVC_URBS];
Laurent Pincharte01117c2008-07-04 00:36:21 -0300615 dma_addr_t urb_dma[UVC_URBS];
616 unsigned int urb_size;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300617
618 __u8 last_fid;
619};
620
621enum uvc_device_state {
622 UVC_DEV_DISCONNECTED = 1,
623};
624
625struct uvc_device {
626 struct usb_device *udev;
627 struct usb_interface *intf;
Laurent Pinchart44f00792008-11-08 19:14:50 -0300628 unsigned long warnings;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300629 __u32 quirks;
630 int intfnum;
631 char name[32];
632
633 enum uvc_device_state state;
634 struct kref kref;
635 struct list_head list;
636
637 /* Video control interface */
638 __u16 uvc_version;
639 __u32 clock_frequency;
640
641 struct list_head entities;
642
643 struct uvc_video_device video;
644
645 /* Status Interrupt Endpoint */
646 struct usb_host_endpoint *int_ep;
647 struct urb *int_urb;
Ming Leia31a4052008-09-16 03:32:20 -0300648 __u8 *status;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300649 struct input_dev *input;
Laurent Pinchartf1801522009-01-22 12:45:10 -0300650 char input_phys[64];
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300651
652 /* Video Streaming interfaces */
653 struct list_head streaming;
654};
655
656enum uvc_handle_state {
657 UVC_HANDLE_PASSIVE = 0,
658 UVC_HANDLE_ACTIVE = 1,
659};
660
661struct uvc_fh {
662 struct uvc_video_device *device;
663 enum uvc_handle_state state;
664};
665
666struct uvc_driver {
667 struct usb_driver driver;
668
669 struct mutex open_mutex; /* protects from open/disconnect race */
670
671 struct list_head devices; /* struct uvc_device list */
672 struct list_head controls; /* struct uvc_control_info list */
673 struct mutex ctrl_mutex; /* protects controls and devices
674 lists */
675};
676
677/* ------------------------------------------------------------------------
678 * Debugging, printing and logging
679 */
680
681#define UVC_TRACE_PROBE (1 << 0)
682#define UVC_TRACE_DESCR (1 << 1)
683#define UVC_TRACE_CONTROL (1 << 2)
684#define UVC_TRACE_FORMAT (1 << 3)
685#define UVC_TRACE_CAPTURE (1 << 4)
686#define UVC_TRACE_CALLS (1 << 5)
687#define UVC_TRACE_IOCTL (1 << 6)
688#define UVC_TRACE_FRAME (1 << 7)
689#define UVC_TRACE_SUSPEND (1 << 8)
690#define UVC_TRACE_STATUS (1 << 9)
691
Laurent Pinchart44f00792008-11-08 19:14:50 -0300692#define UVC_WARN_MINMAX 0
693#define UVC_WARN_PROBE_DEF 1
694
Laurent Pinchart0fbd8ee2008-12-06 16:25:14 -0300695extern unsigned int uvc_no_drop_param;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300696extern unsigned int uvc_trace_param;
697
698#define uvc_trace(flag, msg...) \
699 do { \
700 if (uvc_trace_param & flag) \
701 printk(KERN_DEBUG "uvcvideo: " msg); \
702 } while (0)
703
Laurent Pinchart44f00792008-11-08 19:14:50 -0300704#define uvc_warn_once(dev, warn, msg...) \
705 do { \
706 if (!test_and_set_bit(warn, &dev->warnings)) \
707 printk(KERN_INFO "uvcvideo: " msg); \
708 } while (0)
709
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300710#define uvc_printk(level, msg...) \
711 printk(level "uvcvideo: " msg)
712
713#define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
714 "%02x%02x%02x%02x%02x%02x"
715#define UVC_GUID_ARGS(guid) \
716 (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
717 (guid)[5], (guid)[4], \
718 (guid)[7], (guid)[6], \
719 (guid)[8], (guid)[9], \
720 (guid)[10], (guid)[11], (guid)[12], \
721 (guid)[13], (guid)[14], (guid)[15]
722
723/* --------------------------------------------------------------------------
724 * Internal functions.
725 */
726
727/* Core driver */
728extern struct uvc_driver uvc_driver;
729extern void uvc_delete(struct kref *kref);
730
731/* Video buffers queue management. */
Laurent Pinchartff924202008-12-28 22:32:29 -0300732extern void uvc_queue_init(struct uvc_video_queue *queue,
733 enum v4l2_buf_type type);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300734extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
735 unsigned int nbuffers, unsigned int buflength);
736extern int uvc_free_buffers(struct uvc_video_queue *queue);
737extern int uvc_query_buffer(struct uvc_video_queue *queue,
738 struct v4l2_buffer *v4l2_buf);
739extern int uvc_queue_buffer(struct uvc_video_queue *queue,
740 struct v4l2_buffer *v4l2_buf);
741extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
742 struct v4l2_buffer *v4l2_buf, int nonblocking);
743extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
744extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
745extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
746 struct uvc_buffer *buf);
747extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
748 struct file *file, poll_table *wait);
749static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
750{
751 return queue->flags & UVC_QUEUE_STREAMING;
752}
753
754/* V4L2 interface */
Hans Verkuilbec43662008-12-30 06:58:20 -0300755extern const struct v4l2_file_operations uvc_fops;
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300756
757/* Video */
758extern int uvc_video_init(struct uvc_video_device *video);
759extern int uvc_video_suspend(struct uvc_video_device *video);
760extern int uvc_video_resume(struct uvc_video_device *video);
761extern int uvc_video_enable(struct uvc_video_device *video, int enable);
762extern int uvc_probe_video(struct uvc_video_device *video,
763 struct uvc_streaming_control *probe);
Laurent Pinchart44f00792008-11-08 19:14:50 -0300764extern int uvc_commit_video(struct uvc_video_device *video,
765 struct uvc_streaming_control *ctrl);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300766extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
767 __u8 intfnum, __u8 cs, void *data, __u16 size);
Laurent Pinchartc0efd232008-06-30 15:04:50 -0300768
769/* Status */
770extern int uvc_status_init(struct uvc_device *dev);
771extern void uvc_status_cleanup(struct uvc_device *dev);
772extern int uvc_status_suspend(struct uvc_device *dev);
773extern int uvc_status_resume(struct uvc_device *dev);
774
775/* Controls */
776extern struct uvc_control *uvc_find_control(struct uvc_video_device *video,
777 __u32 v4l2_id, struct uvc_control_mapping **mapping);
778extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
779 struct v4l2_queryctrl *v4l2_ctrl);
780
781extern int uvc_ctrl_add_info(struct uvc_control_info *info);
782extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
783extern int uvc_ctrl_init_device(struct uvc_device *dev);
784extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
785extern int uvc_ctrl_resume_device(struct uvc_device *dev);
786extern void uvc_ctrl_init(void);
787
788extern int uvc_ctrl_begin(struct uvc_video_device *video);
789extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback);
790static inline int uvc_ctrl_commit(struct uvc_video_device *video)
791{
792 return __uvc_ctrl_commit(video, 0);
793}
794static inline int uvc_ctrl_rollback(struct uvc_video_device *video)
795{
796 return __uvc_ctrl_commit(video, 1);
797}
798
799extern int uvc_ctrl_get(struct uvc_video_device *video,
800 struct v4l2_ext_control *xctrl);
801extern int uvc_ctrl_set(struct uvc_video_device *video,
802 struct v4l2_ext_control *xctrl);
803
804extern int uvc_xu_ctrl_query(struct uvc_video_device *video,
805 struct uvc_xu_control *ctrl, int set);
806
807/* Utility functions */
808extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
809 unsigned int n_terms, unsigned int threshold);
810extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
811 uint32_t denominator);
812extern struct usb_host_endpoint *uvc_find_endpoint(
813 struct usb_host_interface *alts, __u8 epaddr);
814
815/* Quirks support */
816void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
817 struct uvc_buffer *buf);
818
819#endif /* __KERNEL__ */
820
821#endif
Hans Verkuilf87086e2008-07-18 00:50:58 -0300822