]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/media/video/uvc/uvcvideo.h
cc5023e09ca948f0d753043b9d1e6aa6292a257e
[linux-beck.git] / drivers / media / video / uvc / uvcvideo.h
1 #ifndef _USB_VIDEO_H_
2 #define _USB_VIDEO_H_
3
4 #include <linux/kernel.h>
5 #include <linux/videodev2.h>
6
7 /*
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
35 struct uvc_xu_control_info {
36         __u8 entity[16];
37         __u8 index;
38         __u8 selector;
39         __u16 size;
40         __u32 flags;
41 };
42
43 struct 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
55 struct 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
75 #define UVC_SC_UNDEFINED                                0x00
76 #define UVC_SC_VIDEOCONTROL                             0x01
77 #define UVC_SC_VIDEOSTREAMING                           0x02
78 #define UVC_SC_VIDEO_INTERFACE_COLLECTION               0x03
79
80 #define UVC_PC_PROTOCOL_UNDEFINED                       0x00
81
82 /* VideoControl class specific interface descriptor */
83 #define UVC_VC_DESCRIPTOR_UNDEFINED                     0x00
84 #define UVC_VC_HEADER                                   0x01
85 #define UVC_VC_INPUT_TERMINAL                           0x02
86 #define UVC_VC_OUTPUT_TERMINAL                          0x03
87 #define UVC_VC_SELECTOR_UNIT                            0x04
88 #define UVC_VC_PROCESSING_UNIT                          0x05
89 #define UVC_VC_EXTENSION_UNIT                           0x06
90
91 /* VideoStreaming class specific interface descriptor */
92 #define UVC_VS_UNDEFINED                                0x00
93 #define UVC_VS_INPUT_HEADER                             0x01
94 #define UVC_VS_OUTPUT_HEADER                            0x02
95 #define UVC_VS_STILL_IMAGE_FRAME                        0x03
96 #define UVC_VS_FORMAT_UNCOMPRESSED                      0x04
97 #define UVC_VS_FRAME_UNCOMPRESSED                       0x05
98 #define UVC_VS_FORMAT_MJPEG                             0x06
99 #define UVC_VS_FRAME_MJPEG                              0x07
100 #define UVC_VS_FORMAT_MPEG2TS                           0x0a
101 #define UVC_VS_FORMAT_DV                                0x0c
102 #define UVC_VS_COLORFORMAT                              0x0d
103 #define UVC_VS_FORMAT_FRAME_BASED                       0x10
104 #define UVC_VS_FRAME_FRAME_BASED                        0x11
105 #define UVC_VS_FORMAT_STREAM_BASED                      0x12
106
107 /* Endpoint type */
108 #define UVC_EP_UNDEFINED                                0x00
109 #define UVC_EP_GENERAL                                  0x01
110 #define UVC_EP_ENDPOINT                                 0x02
111 #define UVC_EP_INTERRUPT                                0x03
112
113 /* Request codes */
114 #define UVC_RC_UNDEFINED                                0x00
115 #define UVC_SET_CUR                                     0x01
116 #define UVC_GET_CUR                                     0x81
117 #define UVC_GET_MIN                                     0x82
118 #define UVC_GET_MAX                                     0x83
119 #define UVC_GET_RES                                     0x84
120 #define UVC_GET_LEN                                     0x85
121 #define UVC_GET_INFO                                    0x86
122 #define UVC_GET_DEF                                     0x87
123
124 /* VideoControl interface controls */
125 #define UVC_VC_CONTROL_UNDEFINED                        0x00
126 #define UVC_VC_VIDEO_POWER_MODE_CONTROL                 0x01
127 #define UVC_VC_REQUEST_ERROR_CODE_CONTROL               0x02
128
129 /* Terminal controls */
130 #define UVC_TE_CONTROL_UNDEFINED                        0x00
131
132 /* Selector Unit controls */
133 #define UVC_SU_CONTROL_UNDEFINED                        0x00
134 #define UVC_SU_INPUT_SELECT_CONTROL                     0x01
135
136 /* Camera Terminal controls */
137 #define UVC_CT_CONTROL_UNDEFINED                        0x00
138 #define UVC_CT_SCANNING_MODE_CONTROL                    0x01
139 #define UVC_CT_AE_MODE_CONTROL                          0x02
140 #define UVC_CT_AE_PRIORITY_CONTROL                      0x03
141 #define UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL           0x04
142 #define UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL           0x05
143 #define UVC_CT_FOCUS_ABSOLUTE_CONTROL                   0x06
144 #define UVC_CT_FOCUS_RELATIVE_CONTROL                   0x07
145 #define UVC_CT_FOCUS_AUTO_CONTROL                       0x08
146 #define UVC_CT_IRIS_ABSOLUTE_CONTROL                    0x09
147 #define UVC_CT_IRIS_RELATIVE_CONTROL                    0x0a
148 #define UVC_CT_ZOOM_ABSOLUTE_CONTROL                    0x0b
149 #define UVC_CT_ZOOM_RELATIVE_CONTROL                    0x0c
150 #define UVC_CT_PANTILT_ABSOLUTE_CONTROL                 0x0d
151 #define UVC_CT_PANTILT_RELATIVE_CONTROL                 0x0e
152 #define UVC_CT_ROLL_ABSOLUTE_CONTROL                    0x0f
153 #define UVC_CT_ROLL_RELATIVE_CONTROL                    0x10
154 #define UVC_CT_PRIVACY_CONTROL                          0x11
155
156 /* Processing Unit controls */
157 #define UVC_PU_CONTROL_UNDEFINED                        0x00
158 #define UVC_PU_BACKLIGHT_COMPENSATION_CONTROL           0x01
159 #define UVC_PU_BRIGHTNESS_CONTROL                       0x02
160 #define UVC_PU_CONTRAST_CONTROL                         0x03
161 #define UVC_PU_GAIN_CONTROL                             0x04
162 #define UVC_PU_POWER_LINE_FREQUENCY_CONTROL             0x05
163 #define UVC_PU_HUE_CONTROL                              0x06
164 #define UVC_PU_SATURATION_CONTROL                       0x07
165 #define UVC_PU_SHARPNESS_CONTROL                        0x08
166 #define UVC_PU_GAMMA_CONTROL                            0x09
167 #define UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL        0x0a
168 #define UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL   0x0b
169 #define UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL          0x0c
170 #define UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL     0x0d
171 #define UVC_PU_DIGITAL_MULTIPLIER_CONTROL               0x0e
172 #define UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL         0x0f
173 #define UVC_PU_HUE_AUTO_CONTROL                         0x10
174 #define UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL            0x11
175 #define UVC_PU_ANALOG_LOCK_STATUS_CONTROL               0x12
176
177 /* VideoStreaming interface controls */
178 #define UVC_VS_CONTROL_UNDEFINED                        0x00
179 #define UVC_VS_PROBE_CONTROL                            0x01
180 #define UVC_VS_COMMIT_CONTROL                           0x02
181 #define UVC_VS_STILL_PROBE_CONTROL                      0x03
182 #define UVC_VS_STILL_COMMIT_CONTROL                     0x04
183 #define UVC_VS_STILL_IMAGE_TRIGGER_CONTROL              0x05
184 #define UVC_VS_STREAM_ERROR_CODE_CONTROL                0x06
185 #define UVC_VS_GENERATE_KEY_FRAME_CONTROL               0x07
186 #define UVC_VS_UPDATE_FRAME_SEGMENT_CONTROL             0x08
187 #define UVC_VS_SYNC_DELAY_CONTROL                       0x09
188
189 #define UVC_TT_VENDOR_SPECIFIC                          0x0100
190 #define UVC_TT_STREAMING                                0x0101
191
192 /* Input Terminal types */
193 #define UVC_ITT_VENDOR_SPECIFIC                         0x0200
194 #define UVC_ITT_CAMERA                                  0x0201
195 #define UVC_ITT_MEDIA_TRANSPORT_INPUT                   0x0202
196
197 /* Output Terminal types */
198 #define UVC_OTT_VENDOR_SPECIFIC                         0x0300
199 #define UVC_OTT_DISPLAY                                 0x0301
200 #define UVC_OTT_MEDIA_TRANSPORT_OUTPUT                  0x0302
201
202 /* External Terminal types */
203 #define UVC_EXTERNAL_VENDOR_SPECIFIC                    0x0400
204 #define UVC_COMPOSITE_CONNECTOR                         0x0401
205 #define UVC_SVIDEO_CONNECTOR                            0x0402
206 #define UVC_COMPONENT_CONNECTOR                         0x0403
207
208 #define UVC_TERM_INPUT                  0x0000
209 #define UVC_TERM_OUTPUT                 0x8000
210
211 #define UVC_ENTITY_TYPE(entity)         ((entity)->type & 0x7fff)
212 #define UVC_ENTITY_IS_UNIT(entity)      (((entity)->type & 0xff00) == 0)
213 #define UVC_ENTITY_IS_TERM(entity)      (((entity)->type & 0xff00) != 0)
214 #define UVC_ENTITY_IS_ITERM(entity) \
215         (((entity)->type & 0x8000) == UVC_TERM_INPUT)
216 #define UVC_ENTITY_IS_OTERM(entity) \
217         (((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
218
219 #define UVC_STATUS_TYPE_CONTROL         1
220 #define UVC_STATUS_TYPE_STREAMING       2
221
222 /* ------------------------------------------------------------------------
223  * GUIDs
224  */
225 #define UVC_GUID_UVC_CAMERA \
226         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
227          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
228 #define UVC_GUID_UVC_OUTPUT \
229         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
230          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
231 #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
232         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
233          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
234 #define UVC_GUID_UVC_PROCESSING \
235         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
236          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
237 #define UVC_GUID_UVC_SELECTOR \
238         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
239          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
240
241 #define UVC_GUID_FORMAT_MJPEG \
242         { 'M',  'J',  'P',  'G', 0x00, 0x00, 0x10, 0x00, \
243          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
244 #define UVC_GUID_FORMAT_YUY2 \
245         { 'Y',  'U',  'Y',  '2', 0x00, 0x00, 0x10, 0x00, \
246          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
247 #define UVC_GUID_FORMAT_NV12 \
248         { 'N',  'V',  '1',  '2', 0x00, 0x00, 0x10, 0x00, \
249          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
250 #define UVC_GUID_FORMAT_YV12 \
251         { 'Y',  'V',  '1',  '2', 0x00, 0x00, 0x10, 0x00, \
252          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
253 #define UVC_GUID_FORMAT_I420 \
254         { 'I',  '4',  '2',  '0', 0x00, 0x00, 0x10, 0x00, \
255          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
256 #define UVC_GUID_FORMAT_UYVY \
257         { 'U',  'Y',  'V',  'Y', 0x00, 0x00, 0x10, 0x00, \
258          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
259 #define UVC_GUID_FORMAT_Y800 \
260         { 'Y',  '8',  '0',  '0', 0x00, 0x00, 0x10, 0x00, \
261          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
262 #define UVC_GUID_FORMAT_BY8 \
263         { 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
264          0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
265
266
267 /* ------------------------------------------------------------------------
268  * Driver specific constants.
269  */
270
271 #define DRIVER_VERSION_NUMBER   KERNEL_VERSION(0, 1, 0)
272
273 /* Number of isochronous URBs. */
274 #define UVC_URBS                5
275 /* Maximum number of packets per URB. */
276 #define UVC_MAX_PACKETS         32
277 /* Maximum number of video buffers. */
278 #define UVC_MAX_VIDEO_BUFFERS   32
279 /* Maximum status buffer size in bytes of interrupt URB. */
280 #define UVC_MAX_STATUS_SIZE     16
281
282 #define UVC_CTRL_CONTROL_TIMEOUT        300
283 #define UVC_CTRL_STREAMING_TIMEOUT      1000
284
285 /* Devices quirks */
286 #define UVC_QUIRK_STATUS_INTERVAL       0x00000001
287 #define UVC_QUIRK_PROBE_MINMAX          0x00000002
288 #define UVC_QUIRK_PROBE_EXTRAFIELDS     0x00000004
289 #define UVC_QUIRK_BUILTIN_ISIGHT        0x00000008
290 #define UVC_QUIRK_STREAM_NO_FID         0x00000010
291 #define UVC_QUIRK_IGNORE_SELECTOR_UNIT  0x00000020
292 #define UVC_QUIRK_FIX_BANDWIDTH         0x00000080
293
294 /* Format flags */
295 #define UVC_FMT_FLAG_COMPRESSED         0x00000001
296 #define UVC_FMT_FLAG_STREAM             0x00000002
297
298 /* ------------------------------------------------------------------------
299  * Structures.
300  */
301
302 struct uvc_device;
303
304 /* TODO: Put the most frequently accessed fields at the beginning of
305  * structures to maximize cache efficiency.
306  */
307 struct uvc_streaming_control {
308         __u16 bmHint;
309         __u8  bFormatIndex;
310         __u8  bFrameIndex;
311         __u32 dwFrameInterval;
312         __u16 wKeyFrameRate;
313         __u16 wPFrameRate;
314         __u16 wCompQuality;
315         __u16 wCompWindowSize;
316         __u16 wDelay;
317         __u32 dwMaxVideoFrameSize;
318         __u32 dwMaxPayloadTransferSize;
319         __u32 dwClockFrequency;
320         __u8  bmFramingInfo;
321         __u8  bPreferedVersion;
322         __u8  bMinVersion;
323         __u8  bMaxVersion;
324 };
325
326 struct uvc_menu_info {
327         __u32 value;
328         __u8 name[32];
329 };
330
331 struct uvc_control_info {
332         struct list_head list;
333         struct list_head mappings;
334
335         __u8 entity[16];
336         __u8 index;
337         __u8 selector;
338
339         __u16 size;
340         __u32 flags;
341 };
342
343 struct uvc_control_mapping {
344         struct list_head list;
345
346         struct uvc_control_info *ctrl;
347
348         __u32 id;
349         __u8 name[32];
350         __u8 entity[16];
351         __u8 selector;
352
353         __u8 size;
354         __u8 offset;
355         enum v4l2_ctrl_type v4l2_type;
356         __u32 data_type;
357
358         struct uvc_menu_info *menu_info;
359         __u32 menu_count;
360
361         __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
362                       const __u8 *data);
363         void (*set) (struct uvc_control_mapping *mapping, __s32 value,
364                      __u8 *data);
365 };
366
367 struct uvc_control {
368         struct uvc_entity *entity;
369         struct uvc_control_info *info;
370
371         __u8 index;     /* Used to match the uvc_control entry with a
372                            uvc_control_info. */
373         __u8 dirty : 1,
374              loaded : 1,
375              modified : 1;
376
377         __u8 *data;
378 };
379
380 struct uvc_format_desc {
381         char *name;
382         __u8 guid[16];
383         __u32 fcc;
384 };
385
386 /* The term 'entity' refers to both UVC units and UVC terminals.
387  *
388  * The type field is either the terminal type (wTerminalType in the terminal
389  * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
390  * As the bDescriptorSubtype field is one byte long, the type value will
391  * always have a null MSB for units. All terminal types defined by the UVC
392  * specification have a non-null MSB, so it is safe to use the MSB to
393  * differentiate between units and terminals as long as the descriptor parsing
394  * code makes sure terminal types have a non-null MSB.
395  *
396  * For terminals, the type's most significant bit stores the terminal
397  * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
398  * always be accessed with the UVC_ENTITY_* macros and never directly.
399  */
400
401 struct uvc_entity {
402         struct list_head list;          /* Entity as part of a UVC device. */
403         struct list_head chain;         /* Entity as part of a video device
404                                          * chain. */
405         __u8 id;
406         __u16 type;
407         char name[64];
408
409         union {
410                 struct {
411                         __u16 wObjectiveFocalLengthMin;
412                         __u16 wObjectiveFocalLengthMax;
413                         __u16 wOcularFocalLength;
414                         __u8  bControlSize;
415                         __u8  *bmControls;
416                 } camera;
417
418                 struct {
419                         __u8  bControlSize;
420                         __u8  *bmControls;
421                         __u8  bTransportModeSize;
422                         __u8  *bmTransportModes;
423                 } media;
424
425                 struct {
426                         __u8  bSourceID;
427                 } output;
428
429                 struct {
430                         __u8  bSourceID;
431                         __u16 wMaxMultiplier;
432                         __u8  bControlSize;
433                         __u8  *bmControls;
434                         __u8  bmVideoStandards;
435                 } processing;
436
437                 struct {
438                         __u8  bNrInPins;
439                         __u8  *baSourceID;
440                 } selector;
441
442                 struct {
443                         __u8  guidExtensionCode[16];
444                         __u8  bNumControls;
445                         __u8  bNrInPins;
446                         __u8  *baSourceID;
447                         __u8  bControlSize;
448                         __u8  *bmControls;
449                         __u8  *bmControlsType;
450                 } extension;
451         };
452
453         unsigned int ncontrols;
454         struct uvc_control *controls;
455 };
456
457 struct uvc_frame {
458         __u8  bFrameIndex;
459         __u8  bmCapabilities;
460         __u16 wWidth;
461         __u16 wHeight;
462         __u32 dwMinBitRate;
463         __u32 dwMaxBitRate;
464         __u32 dwMaxVideoFrameBufferSize;
465         __u8  bFrameIntervalType;
466         __u32 dwDefaultFrameInterval;
467         __u32 *dwFrameInterval;
468 };
469
470 struct uvc_format {
471         __u8 type;
472         __u8 index;
473         __u8 bpp;
474         __u8 colorspace;
475         __u32 fcc;
476         __u32 flags;
477
478         char name[32];
479
480         unsigned int nframes;
481         struct uvc_frame *frame;
482 };
483
484 struct uvc_streaming_header {
485         __u8 bNumFormats;
486         __u8 bEndpointAddress;
487         __u8 bTerminalLink;
488         __u8 bControlSize;
489         __u8 *bmaControls;
490         /* The following fields are used by input headers only. */
491         __u8 bmInfo;
492         __u8 bStillCaptureMethod;
493         __u8 bTriggerSupport;
494         __u8 bTriggerUsage;
495 };
496
497 struct uvc_streaming {
498         struct list_head list;
499
500         struct usb_interface *intf;
501         int intfnum;
502         __u16 maxpsize;
503
504         struct uvc_streaming_header header;
505         enum v4l2_buf_type type;
506
507         unsigned int nformats;
508         struct uvc_format *format;
509
510         struct uvc_streaming_control ctrl;
511         struct uvc_format *cur_format;
512         struct uvc_frame *cur_frame;
513
514         struct mutex mutex;
515 };
516
517 enum uvc_buffer_state {
518         UVC_BUF_STATE_IDLE      = 0,
519         UVC_BUF_STATE_QUEUED    = 1,
520         UVC_BUF_STATE_ACTIVE    = 2,
521         UVC_BUF_STATE_DONE      = 3,
522         UVC_BUF_STATE_ERROR     = 4,
523 };
524
525 struct uvc_buffer {
526         unsigned long vma_use_count;
527         struct list_head stream;
528
529         /* Touched by interrupt handler. */
530         struct v4l2_buffer buf;
531         struct list_head queue;
532         wait_queue_head_t wait;
533         enum uvc_buffer_state state;
534 };
535
536 #define UVC_QUEUE_STREAMING             (1 << 0)
537 #define UVC_QUEUE_DISCONNECTED          (1 << 1)
538 #define UVC_QUEUE_DROP_INCOMPLETE       (1 << 2)
539
540 struct uvc_video_queue {
541         enum v4l2_buf_type type;
542
543         void *mem;
544         unsigned int flags;
545         __u32 sequence;
546
547         unsigned int count;
548         unsigned int buf_size;
549         unsigned int buf_used;
550         struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
551         struct mutex mutex;     /* protects buffers and mainqueue */
552         spinlock_t irqlock;     /* protects irqqueue */
553
554         struct list_head mainqueue;
555         struct list_head irqqueue;
556 };
557
558 struct uvc_video_device {
559         struct uvc_device *dev;
560         struct video_device *vdev;
561         atomic_t active;
562         unsigned int frozen : 1;
563
564         struct list_head iterms;                /* Input terminals */
565         struct uvc_entity *oterm;               /* Output terminal */
566         struct uvc_entity *sterm;               /* USB streaming terminal */
567         struct uvc_entity *processing;
568         struct uvc_entity *selector;
569         struct list_head extensions;
570         struct mutex ctrl_mutex;
571
572         struct uvc_video_queue queue;
573
574         /* Video streaming object, must always be non-NULL. */
575         struct uvc_streaming *streaming;
576
577         void (*decode) (struct urb *urb, struct uvc_video_device *video,
578                         struct uvc_buffer *buf);
579
580         /* Context data used by the bulk completion handler. */
581         struct {
582                 __u8 header[256];
583                 unsigned int header_size;
584                 int skip_payload;
585                 __u32 payload_size;
586                 __u32 max_payload_size;
587         } bulk;
588
589         struct urb *urb[UVC_URBS];
590         char *urb_buffer[UVC_URBS];
591         dma_addr_t urb_dma[UVC_URBS];
592         unsigned int urb_size;
593
594         __u8 last_fid;
595 };
596
597 enum uvc_device_state {
598         UVC_DEV_DISCONNECTED = 1,
599 };
600
601 struct uvc_device {
602         struct usb_device *udev;
603         struct usb_interface *intf;
604         unsigned long warnings;
605         __u32 quirks;
606         int intfnum;
607         char name[32];
608
609         enum uvc_device_state state;
610         struct kref kref;
611         struct list_head list;
612         atomic_t users;
613
614         /* Video control interface */
615         __u16 uvc_version;
616         __u32 clock_frequency;
617
618         struct list_head entities;
619
620         struct uvc_video_device video;
621
622         /* Status Interrupt Endpoint */
623         struct usb_host_endpoint *int_ep;
624         struct urb *int_urb;
625         __u8 *status;
626         struct input_dev *input;
627         char input_phys[64];
628
629         /* Video Streaming interfaces */
630         struct list_head streaming;
631 };
632
633 enum uvc_handle_state {
634         UVC_HANDLE_PASSIVE      = 0,
635         UVC_HANDLE_ACTIVE       = 1,
636 };
637
638 struct uvc_fh {
639         struct uvc_video_device *device;
640         enum uvc_handle_state state;
641 };
642
643 struct uvc_driver {
644         struct usb_driver driver;
645
646         struct mutex open_mutex;        /* protects from open/disconnect race */
647
648         struct list_head devices;       /* struct uvc_device list */
649         struct list_head controls;      /* struct uvc_control_info list */
650         struct mutex ctrl_mutex;        /* protects controls and devices
651                                            lists */
652 };
653
654 /* ------------------------------------------------------------------------
655  * Debugging, printing and logging
656  */
657
658 #define UVC_TRACE_PROBE         (1 << 0)
659 #define UVC_TRACE_DESCR         (1 << 1)
660 #define UVC_TRACE_CONTROL       (1 << 2)
661 #define UVC_TRACE_FORMAT        (1 << 3)
662 #define UVC_TRACE_CAPTURE       (1 << 4)
663 #define UVC_TRACE_CALLS         (1 << 5)
664 #define UVC_TRACE_IOCTL         (1 << 6)
665 #define UVC_TRACE_FRAME         (1 << 7)
666 #define UVC_TRACE_SUSPEND       (1 << 8)
667 #define UVC_TRACE_STATUS        (1 << 9)
668
669 #define UVC_WARN_MINMAX         0
670 #define UVC_WARN_PROBE_DEF      1
671
672 extern unsigned int uvc_no_drop_param;
673 extern unsigned int uvc_trace_param;
674
675 #define uvc_trace(flag, msg...) \
676         do { \
677                 if (uvc_trace_param & flag) \
678                         printk(KERN_DEBUG "uvcvideo: " msg); \
679         } while (0)
680
681 #define uvc_warn_once(dev, warn, msg...) \
682         do { \
683                 if (!test_and_set_bit(warn, &dev->warnings)) \
684                         printk(KERN_INFO "uvcvideo: " msg); \
685         } while (0)
686
687 #define uvc_printk(level, msg...) \
688         printk(level "uvcvideo: " msg)
689
690 #define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
691                         "%02x%02x%02x%02x%02x%02x"
692 #define UVC_GUID_ARGS(guid) \
693         (guid)[3],  (guid)[2],  (guid)[1],  (guid)[0], \
694         (guid)[5],  (guid)[4], \
695         (guid)[7],  (guid)[6], \
696         (guid)[8],  (guid)[9], \
697         (guid)[10], (guid)[11], (guid)[12], \
698         (guid)[13], (guid)[14], (guid)[15]
699
700 /* --------------------------------------------------------------------------
701  * Internal functions.
702  */
703
704 /* Core driver */
705 extern struct uvc_driver uvc_driver;
706 extern void uvc_delete(struct kref *kref);
707
708 /* Video buffers queue management. */
709 extern void uvc_queue_init(struct uvc_video_queue *queue,
710                 enum v4l2_buf_type type);
711 extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
712                 unsigned int nbuffers, unsigned int buflength);
713 extern int uvc_free_buffers(struct uvc_video_queue *queue);
714 extern int uvc_query_buffer(struct uvc_video_queue *queue,
715                 struct v4l2_buffer *v4l2_buf);
716 extern int uvc_queue_buffer(struct uvc_video_queue *queue,
717                 struct v4l2_buffer *v4l2_buf);
718 extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
719                 struct v4l2_buffer *v4l2_buf, int nonblocking);
720 extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
721 extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
722 extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
723                 struct uvc_buffer *buf);
724 extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
725                 struct file *file, poll_table *wait);
726 extern int uvc_queue_allocated(struct uvc_video_queue *queue);
727 static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
728 {
729         return queue->flags & UVC_QUEUE_STREAMING;
730 }
731
732 /* V4L2 interface */
733 extern const struct v4l2_file_operations uvc_fops;
734
735 /* Video */
736 extern int uvc_video_init(struct uvc_video_device *video);
737 extern int uvc_video_suspend(struct uvc_video_device *video);
738 extern int uvc_video_resume(struct uvc_video_device *video);
739 extern int uvc_video_enable(struct uvc_video_device *video, int enable);
740 extern int uvc_probe_video(struct uvc_video_device *video,
741                 struct uvc_streaming_control *probe);
742 extern int uvc_commit_video(struct uvc_video_device *video,
743                 struct uvc_streaming_control *ctrl);
744 extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
745                 __u8 intfnum, __u8 cs, void *data, __u16 size);
746
747 /* Status */
748 extern int uvc_status_init(struct uvc_device *dev);
749 extern void uvc_status_cleanup(struct uvc_device *dev);
750 extern int uvc_status_start(struct uvc_device *dev);
751 extern void uvc_status_stop(struct uvc_device *dev);
752 extern int uvc_status_suspend(struct uvc_device *dev);
753 extern int uvc_status_resume(struct uvc_device *dev);
754
755 /* Controls */
756 extern struct uvc_control *uvc_find_control(struct uvc_video_device *video,
757                 __u32 v4l2_id, struct uvc_control_mapping **mapping);
758 extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
759                 struct v4l2_queryctrl *v4l2_ctrl);
760
761 extern int uvc_ctrl_add_info(struct uvc_control_info *info);
762 extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
763 extern int uvc_ctrl_init_device(struct uvc_device *dev);
764 extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
765 extern int uvc_ctrl_resume_device(struct uvc_device *dev);
766 extern void uvc_ctrl_init(void);
767
768 extern int uvc_ctrl_begin(struct uvc_video_device *video);
769 extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback);
770 static inline int uvc_ctrl_commit(struct uvc_video_device *video)
771 {
772         return __uvc_ctrl_commit(video, 0);
773 }
774 static inline int uvc_ctrl_rollback(struct uvc_video_device *video)
775 {
776         return __uvc_ctrl_commit(video, 1);
777 }
778
779 extern int uvc_ctrl_get(struct uvc_video_device *video,
780                 struct v4l2_ext_control *xctrl);
781 extern int uvc_ctrl_set(struct uvc_video_device *video,
782                 struct v4l2_ext_control *xctrl);
783
784 extern int uvc_xu_ctrl_query(struct uvc_video_device *video,
785                 struct uvc_xu_control *ctrl, int set);
786
787 /* Utility functions */
788 extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
789                 unsigned int n_terms, unsigned int threshold);
790 extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
791                 uint32_t denominator);
792 extern struct usb_host_endpoint *uvc_find_endpoint(
793                 struct usb_host_interface *alts, __u8 epaddr);
794
795 /* Quirks support */
796 void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
797                 struct uvc_buffer *buf);
798
799 #endif /* __KERNEL__ */
800
801 #endif
802