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