Commit | Line | Data |
---|---|---|
c0efd232 LP |
1 | #ifndef _USB_VIDEO_H_ |
2 | #define _USB_VIDEO_H_ | |
3 | ||
4 | #include <linux/kernel.h> | |
5 | #include <linux/videodev2.h> | |
6 | ||
5f708812 LP |
7 | #ifndef __KERNEL__ |
8 | /* | |
9 | * This header provides binary compatibility with applications using the private | |
10 | * uvcvideo API. This API is deprecated and will be removed in 2.6.42. | |
11 | * Applications should be recompiled against the public linux/uvcvideo.h header. | |
12 | */ | |
13 | #warn "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead." | |
14 | ||
c0efd232 LP |
15 | /* |
16 | * Dynamic controls | |
17 | */ | |
18 | ||
19 | /* Data types for UVC control data */ | |
20 | #define UVC_CTRL_DATA_TYPE_RAW 0 | |
21 | #define UVC_CTRL_DATA_TYPE_SIGNED 1 | |
22 | #define UVC_CTRL_DATA_TYPE_UNSIGNED 2 | |
23 | #define UVC_CTRL_DATA_TYPE_BOOLEAN 3 | |
24 | #define UVC_CTRL_DATA_TYPE_ENUM 4 | |
25 | #define UVC_CTRL_DATA_TYPE_BITMASK 5 | |
26 | ||
27 | /* Control flags */ | |
28 | #define UVC_CONTROL_SET_CUR (1 << 0) | |
29 | #define UVC_CONTROL_GET_CUR (1 << 1) | |
30 | #define UVC_CONTROL_GET_MIN (1 << 2) | |
31 | #define UVC_CONTROL_GET_MAX (1 << 3) | |
32 | #define UVC_CONTROL_GET_RES (1 << 4) | |
33 | #define UVC_CONTROL_GET_DEF (1 << 5) | |
c0efd232 | 34 | #define UVC_CONTROL_RESTORE (1 << 6) |
c0efd232 LP |
35 | #define UVC_CONTROL_AUTO_UPDATE (1 << 7) |
36 | ||
37 | #define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \ | |
38 | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \ | |
39 | UVC_CONTROL_GET_DEF) | |
40 | ||
561474c2 LP |
41 | struct uvc_menu_info { |
42 | __u32 value; | |
43 | __u8 name[32]; | |
44 | }; | |
45 | ||
c0efd232 LP |
46 | struct uvc_xu_control_mapping { |
47 | __u32 id; | |
48 | __u8 name[32]; | |
49 | __u8 entity[16]; | |
50 | __u8 selector; | |
51 | ||
52 | __u8 size; | |
53 | __u8 offset; | |
fe78d187 | 54 | __u32 v4l2_type; |
c0efd232 | 55 | __u32 data_type; |
561474c2 LP |
56 | |
57 | struct uvc_menu_info __user *menu_info; | |
58 | __u32 menu_count; | |
59 | ||
60 | __u32 reserved[4]; | |
c0efd232 LP |
61 | }; |
62 | ||
5f708812 LP |
63 | #endif |
64 | ||
65 | struct uvc_xu_control_info { | |
66 | __u8 entity[16]; | |
67 | __u8 index; | |
c0efd232 LP |
68 | __u8 selector; |
69 | __u16 size; | |
5f708812 | 70 | __u32 flags; |
c0efd232 LP |
71 | }; |
72 | ||
5f708812 LP |
73 | struct uvc_xu_control_mapping_old { |
74 | __u8 reserved[64]; | |
75 | }; | |
76 | ||
77 | struct uvc_xu_control { | |
fe78d187 MR |
78 | __u8 unit; |
79 | __u8 selector; | |
fe78d187 MR |
80 | __u16 size; |
81 | __u8 __user *data; | |
82 | }; | |
83 | ||
5f708812 | 84 | #ifndef __KERNEL__ |
c0efd232 | 85 | #define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) |
561474c2 | 86 | #define UVCIOC_CTRL_MAP_OLD _IOWR('U', 2, struct uvc_xu_control_mapping_old) |
c0efd232 LP |
87 | #define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) |
88 | #define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) | |
89 | #define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) | |
5f708812 LP |
90 | #else |
91 | #define __UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) | |
92 | #define __UVCIOC_CTRL_MAP_OLD _IOWR('U', 2, struct uvc_xu_control_mapping_old) | |
93 | #define __UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) | |
94 | #define __UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) | |
95 | #define __UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) | |
96 | #endif | |
c0efd232 LP |
97 | |
98 | #ifdef __KERNEL__ | |
99 | ||
100 | #include <linux/poll.h> | |
4ffc2d89 | 101 | #include <linux/usb.h> |
de05f634 | 102 | #include <linux/usb/video.h> |
5f708812 | 103 | #include <linux/uvcvideo.h> |
5a254d75 LP |
104 | #include <media/media-device.h> |
105 | #include <media/v4l2-device.h> | |
c0efd232 LP |
106 | |
107 | /* -------------------------------------------------------------------------- | |
108 | * UVC constants | |
109 | */ | |
110 | ||
c0efd232 LP |
111 | #define UVC_TERM_INPUT 0x0000 |
112 | #define UVC_TERM_OUTPUT 0x8000 | |
6241d8ca | 113 | #define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000) |
c0efd232 LP |
114 | |
115 | #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) | |
116 | #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) | |
117 | #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) | |
118 | #define UVC_ENTITY_IS_ITERM(entity) \ | |
8e113595 LP |
119 | (UVC_ENTITY_IS_TERM(entity) && \ |
120 | ((entity)->type & 0x8000) == UVC_TERM_INPUT) | |
c0efd232 | 121 | #define UVC_ENTITY_IS_OTERM(entity) \ |
8e113595 LP |
122 | (UVC_ENTITY_IS_TERM(entity) && \ |
123 | ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) | |
c0efd232 | 124 | |
c0efd232 LP |
125 | |
126 | /* ------------------------------------------------------------------------ | |
127 | * GUIDs | |
128 | */ | |
129 | #define UVC_GUID_UVC_CAMERA \ | |
130 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | |
131 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} | |
132 | #define UVC_GUID_UVC_OUTPUT \ | |
133 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | |
134 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} | |
135 | #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ | |
136 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | |
137 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} | |
138 | #define UVC_GUID_UVC_PROCESSING \ | |
139 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | |
140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} | |
141 | #define UVC_GUID_UVC_SELECTOR \ | |
142 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | |
143 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} | |
144 | ||
c0efd232 LP |
145 | #define UVC_GUID_FORMAT_MJPEG \ |
146 | { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ | |
147 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
148 | #define UVC_GUID_FORMAT_YUY2 \ | |
149 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ | |
150 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
68f194e0 DR |
151 | #define UVC_GUID_FORMAT_YUY2_ISIGHT \ |
152 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ | |
153 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71} | |
c0efd232 LP |
154 | #define UVC_GUID_FORMAT_NV12 \ |
155 | { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ | |
156 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
157 | #define UVC_GUID_FORMAT_YV12 \ | |
158 | { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ | |
159 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
160 | #define UVC_GUID_FORMAT_I420 \ | |
161 | { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ | |
162 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
163 | #define UVC_GUID_FORMAT_UYVY \ | |
164 | { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ | |
165 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
166 | #define UVC_GUID_FORMAT_Y800 \ | |
167 | { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ | |
168 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
61421206 LP |
169 | #define UVC_GUID_FORMAT_Y16 \ |
170 | { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ | |
171 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
c0efd232 LP |
172 | #define UVC_GUID_FORMAT_BY8 \ |
173 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ | |
174 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
50791079 LP |
175 | #define UVC_GUID_FORMAT_RGBP \ |
176 | { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ | |
177 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
7225a1dc HG |
178 | #define UVC_GUID_FORMAT_M420 \ |
179 | { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ | |
180 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | |
c0efd232 | 181 | |
c0efd232 LP |
182 | /* ------------------------------------------------------------------------ |
183 | * Driver specific constants. | |
184 | */ | |
185 | ||
5f708812 LP |
186 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(1, 1, 0) |
187 | #define DRIVER_VERSION "v1.1.0" | |
c0efd232 LP |
188 | |
189 | /* Number of isochronous URBs. */ | |
190 | #define UVC_URBS 5 | |
efdc8a95 LP |
191 | /* Maximum number of packets per URB. */ |
192 | #define UVC_MAX_PACKETS 32 | |
c0efd232 LP |
193 | /* Maximum number of video buffers. */ |
194 | #define UVC_MAX_VIDEO_BUFFERS 32 | |
a31a4055 ML |
195 | /* Maximum status buffer size in bytes of interrupt URB. */ |
196 | #define UVC_MAX_STATUS_SIZE 16 | |
c0efd232 LP |
197 | |
198 | #define UVC_CTRL_CONTROL_TIMEOUT 300 | |
56d15cd3 | 199 | #define UVC_CTRL_STREAMING_TIMEOUT 5000 |
c0efd232 | 200 | |
8fb91b33 MR |
201 | /* Maximum allowed number of control mappings per device */ |
202 | #define UVC_MAX_CONTROL_MAPPINGS 1024 | |
203 | ||
c0efd232 LP |
204 | /* Devices quirks */ |
205 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 | |
206 | #define UVC_QUIRK_PROBE_MINMAX 0x00000002 | |
207 | #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 | |
208 | #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 | |
209 | #define UVC_QUIRK_STREAM_NO_FID 0x00000010 | |
210 | #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 | |
50144aee | 211 | #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 |
bab6f66c | 212 | #define UVC_QUIRK_PROBE_DEF 0x00000100 |
86d8b6ab | 213 | #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 |
c0efd232 LP |
214 | |
215 | /* Format flags */ | |
216 | #define UVC_FMT_FLAG_COMPRESSED 0x00000001 | |
217 | #define UVC_FMT_FLAG_STREAM 0x00000002 | |
218 | ||
219 | /* ------------------------------------------------------------------------ | |
220 | * Structures. | |
221 | */ | |
222 | ||
223 | struct uvc_device; | |
224 | ||
225 | /* TODO: Put the most frequently accessed fields at the beginning of | |
226 | * structures to maximize cache efficiency. | |
227 | */ | |
c0efd232 | 228 | struct uvc_control_info { |
c0efd232 LP |
229 | struct list_head mappings; |
230 | ||
231 | __u8 entity[16]; | |
ba2fa996 | 232 | __u8 index; /* Bit index in bmControls */ |
c0efd232 LP |
233 | __u8 selector; |
234 | ||
235 | __u16 size; | |
236 | __u32 flags; | |
237 | }; | |
238 | ||
239 | struct uvc_control_mapping { | |
240 | struct list_head list; | |
241 | ||
242 | struct uvc_control_info *ctrl; | |
243 | ||
244 | __u32 id; | |
245 | __u8 name[32]; | |
246 | __u8 entity[16]; | |
247 | __u8 selector; | |
248 | ||
249 | __u8 size; | |
250 | __u8 offset; | |
251 | enum v4l2_ctrl_type v4l2_type; | |
252 | __u32 data_type; | |
253 | ||
254 | struct uvc_menu_info *menu_info; | |
255 | __u32 menu_count; | |
9768352a LP |
256 | |
257 | __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query, | |
258 | const __u8 *data); | |
259 | void (*set) (struct uvc_control_mapping *mapping, __s32 value, | |
260 | __u8 *data); | |
c0efd232 LP |
261 | }; |
262 | ||
263 | struct uvc_control { | |
264 | struct uvc_entity *entity; | |
071c8bb8 | 265 | struct uvc_control_info info; |
c0efd232 LP |
266 | |
267 | __u8 index; /* Used to match the uvc_control entry with a | |
268 | uvc_control_info. */ | |
071c8bb8 LP |
269 | __u8 dirty:1, |
270 | loaded:1, | |
271 | modified:1, | |
272 | cached:1, | |
273 | initialized:1; | |
c0efd232 | 274 | |
b30ece53 | 275 | __u8 *uvc_data; |
c0efd232 LP |
276 | }; |
277 | ||
278 | struct uvc_format_desc { | |
279 | char *name; | |
280 | __u8 guid[16]; | |
281 | __u32 fcc; | |
282 | }; | |
283 | ||
284 | /* The term 'entity' refers to both UVC units and UVC terminals. | |
285 | * | |
286 | * The type field is either the terminal type (wTerminalType in the terminal | |
287 | * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). | |
288 | * As the bDescriptorSubtype field is one byte long, the type value will | |
289 | * always have a null MSB for units. All terminal types defined by the UVC | |
290 | * specification have a non-null MSB, so it is safe to use the MSB to | |
291 | * differentiate between units and terminals as long as the descriptor parsing | |
292 | * code makes sure terminal types have a non-null MSB. | |
293 | * | |
294 | * For terminals, the type's most significant bit stores the terminal | |
295 | * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should | |
296 | * always be accessed with the UVC_ENTITY_* macros and never directly. | |
297 | */ | |
298 | ||
299 | struct uvc_entity { | |
300 | struct list_head list; /* Entity as part of a UVC device. */ | |
301 | struct list_head chain; /* Entity as part of a video device | |
302 | * chain. */ | |
303 | __u8 id; | |
304 | __u16 type; | |
305 | char name[64]; | |
306 | ||
4ffc2d89 | 307 | /* Media controller-related fields. */ |
8a65a948 | 308 | struct video_device *vdev; |
4ffc2d89 LP |
309 | struct v4l2_subdev subdev; |
310 | unsigned int num_pads; | |
311 | unsigned int num_links; | |
312 | struct media_pad *pads; | |
313 | ||
c0efd232 LP |
314 | union { |
315 | struct { | |
316 | __u16 wObjectiveFocalLengthMin; | |
317 | __u16 wObjectiveFocalLengthMax; | |
318 | __u16 wOcularFocalLength; | |
319 | __u8 bControlSize; | |
320 | __u8 *bmControls; | |
321 | } camera; | |
322 | ||
323 | struct { | |
324 | __u8 bControlSize; | |
325 | __u8 *bmControls; | |
326 | __u8 bTransportModeSize; | |
327 | __u8 *bmTransportModes; | |
328 | } media; | |
329 | ||
330 | struct { | |
c0efd232 LP |
331 | } output; |
332 | ||
333 | struct { | |
c0efd232 LP |
334 | __u16 wMaxMultiplier; |
335 | __u8 bControlSize; | |
336 | __u8 *bmControls; | |
337 | __u8 bmVideoStandards; | |
338 | } processing; | |
339 | ||
340 | struct { | |
c0efd232 LP |
341 | } selector; |
342 | ||
343 | struct { | |
344 | __u8 guidExtensionCode[16]; | |
345 | __u8 bNumControls; | |
c0efd232 LP |
346 | __u8 bControlSize; |
347 | __u8 *bmControls; | |
348 | __u8 *bmControlsType; | |
349 | } extension; | |
350 | }; | |
351 | ||
8ca5a639 LP |
352 | __u8 bNrInPins; |
353 | __u8 *baSourceID; | |
354 | ||
c0efd232 LP |
355 | unsigned int ncontrols; |
356 | struct uvc_control *controls; | |
357 | }; | |
358 | ||
359 | struct uvc_frame { | |
360 | __u8 bFrameIndex; | |
361 | __u8 bmCapabilities; | |
362 | __u16 wWidth; | |
363 | __u16 wHeight; | |
364 | __u32 dwMinBitRate; | |
365 | __u32 dwMaxBitRate; | |
366 | __u32 dwMaxVideoFrameBufferSize; | |
367 | __u8 bFrameIntervalType; | |
368 | __u32 dwDefaultFrameInterval; | |
369 | __u32 *dwFrameInterval; | |
370 | }; | |
371 | ||
372 | struct uvc_format { | |
373 | __u8 type; | |
374 | __u8 index; | |
375 | __u8 bpp; | |
376 | __u8 colorspace; | |
377 | __u32 fcc; | |
378 | __u32 flags; | |
379 | ||
380 | char name[32]; | |
381 | ||
382 | unsigned int nframes; | |
383 | struct uvc_frame *frame; | |
384 | }; | |
385 | ||
386 | struct uvc_streaming_header { | |
387 | __u8 bNumFormats; | |
388 | __u8 bEndpointAddress; | |
389 | __u8 bTerminalLink; | |
390 | __u8 bControlSize; | |
391 | __u8 *bmaControls; | |
392 | /* The following fields are used by input headers only. */ | |
393 | __u8 bmInfo; | |
394 | __u8 bStillCaptureMethod; | |
395 | __u8 bTriggerSupport; | |
396 | __u8 bTriggerUsage; | |
397 | }; | |
398 | ||
c0efd232 | 399 | enum uvc_buffer_state { |
2c2d264b LP |
400 | UVC_BUF_STATE_IDLE = 0, |
401 | UVC_BUF_STATE_QUEUED = 1, | |
402 | UVC_BUF_STATE_ACTIVE = 2, | |
d7c0d439 LP |
403 | UVC_BUF_STATE_READY = 3, |
404 | UVC_BUF_STATE_DONE = 4, | |
405 | UVC_BUF_STATE_ERROR = 5, | |
c0efd232 LP |
406 | }; |
407 | ||
408 | struct uvc_buffer { | |
409 | unsigned long vma_use_count; | |
410 | struct list_head stream; | |
411 | ||
412 | /* Touched by interrupt handler. */ | |
413 | struct v4l2_buffer buf; | |
414 | struct list_head queue; | |
415 | wait_queue_head_t wait; | |
416 | enum uvc_buffer_state state; | |
9bde9f26 | 417 | unsigned int error; |
c0efd232 LP |
418 | }; |
419 | ||
420 | #define UVC_QUEUE_STREAMING (1 << 0) | |
421 | #define UVC_QUEUE_DISCONNECTED (1 << 1) | |
9bde9f26 | 422 | #define UVC_QUEUE_DROP_CORRUPTED (1 << 2) |
c0efd232 LP |
423 | |
424 | struct uvc_video_queue { | |
ff924203 LP |
425 | enum v4l2_buf_type type; |
426 | ||
c0efd232 LP |
427 | void *mem; |
428 | unsigned int flags; | |
c0efd232 LP |
429 | |
430 | unsigned int count; | |
431 | unsigned int buf_size; | |
ff924203 | 432 | unsigned int buf_used; |
c0efd232 LP |
433 | struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS]; |
434 | struct mutex mutex; /* protects buffers and mainqueue */ | |
435 | spinlock_t irqlock; /* protects irqqueue */ | |
436 | ||
437 | struct list_head mainqueue; | |
438 | struct list_head irqqueue; | |
439 | }; | |
440 | ||
8e113595 LP |
441 | struct uvc_video_chain { |
442 | struct uvc_device *dev; | |
443 | struct list_head list; | |
444 | ||
6241d8ca | 445 | struct list_head entities; /* All entities */ |
8e113595 LP |
446 | struct uvc_entity *processing; /* Processing unit */ |
447 | struct uvc_entity *selector; /* Selector unit */ | |
8e113595 | 448 | |
27a61c13 | 449 | struct mutex ctrl_mutex; /* Protects ctrl.info */ |
8e113595 LP |
450 | }; |
451 | ||
35f02a68 LP |
452 | struct uvc_streaming { |
453 | struct list_head list; | |
c0efd232 LP |
454 | struct uvc_device *dev; |
455 | struct video_device *vdev; | |
8e113595 | 456 | struct uvc_video_chain *chain; |
c0efd232 | 457 | atomic_t active; |
c0efd232 | 458 | |
35f02a68 LP |
459 | struct usb_interface *intf; |
460 | int intfnum; | |
461 | __u16 maxpsize; | |
c0efd232 | 462 | |
35f02a68 LP |
463 | struct uvc_streaming_header header; |
464 | enum v4l2_buf_type type; | |
465 | ||
466 | unsigned int nformats; | |
467 | struct uvc_format *format; | |
c0efd232 | 468 | |
35f02a68 LP |
469 | struct uvc_streaming_control ctrl; |
470 | struct uvc_format *cur_format; | |
471 | struct uvc_frame *cur_frame; | |
6947756d LP |
472 | /* Protect access to ctrl, cur_format, cur_frame and hardware video |
473 | * probe control. | |
474 | */ | |
35f02a68 | 475 | struct mutex mutex; |
c0efd232 | 476 | |
35f02a68 LP |
477 | unsigned int frozen : 1; |
478 | struct uvc_video_queue queue; | |
479 | void (*decode) (struct urb *urb, struct uvc_streaming *video, | |
c0efd232 LP |
480 | struct uvc_buffer *buf); |
481 | ||
482 | /* Context data used by the bulk completion handler. */ | |
483 | struct { | |
484 | __u8 header[256]; | |
485 | unsigned int header_size; | |
486 | int skip_payload; | |
487 | __u32 payload_size; | |
488 | __u32 max_payload_size; | |
489 | } bulk; | |
490 | ||
491 | struct urb *urb[UVC_URBS]; | |
492 | char *urb_buffer[UVC_URBS]; | |
e01117c8 LP |
493 | dma_addr_t urb_dma[UVC_URBS]; |
494 | unsigned int urb_size; | |
c0efd232 | 495 | |
650b95fe | 496 | __u32 sequence; |
c0efd232 LP |
497 | __u8 last_fid; |
498 | }; | |
499 | ||
500 | enum uvc_device_state { | |
501 | UVC_DEV_DISCONNECTED = 1, | |
502 | }; | |
503 | ||
504 | struct uvc_device { | |
505 | struct usb_device *udev; | |
506 | struct usb_interface *intf; | |
44f0079e | 507 | unsigned long warnings; |
c0efd232 LP |
508 | __u32 quirks; |
509 | int intfnum; | |
510 | char name[32]; | |
511 | ||
512 | enum uvc_device_state state; | |
04a37e0f | 513 | atomic_t users; |
8fb91b33 | 514 | atomic_t nmappings; |
c0efd232 LP |
515 | |
516 | /* Video control interface */ | |
5a254d75 LP |
517 | #ifdef CONFIG_MEDIA_CONTROLLER |
518 | struct media_device mdev; | |
519 | #endif | |
520 | struct v4l2_device vdev; | |
c0efd232 LP |
521 | __u16 uvc_version; |
522 | __u32 clock_frequency; | |
523 | ||
524 | struct list_head entities; | |
8e113595 | 525 | struct list_head chains; |
c0efd232 | 526 | |
35f02a68 LP |
527 | /* Video Streaming interfaces */ |
528 | struct list_head streams; | |
716fdee1 | 529 | atomic_t nstreams; |
35f02a68 | 530 | |
c0efd232 LP |
531 | /* Status Interrupt Endpoint */ |
532 | struct usb_host_endpoint *int_ep; | |
533 | struct urb *int_urb; | |
a31a4055 | 534 | __u8 *status; |
c0efd232 | 535 | struct input_dev *input; |
f1801523 | 536 | char input_phys[64]; |
c0efd232 LP |
537 | }; |
538 | ||
539 | enum uvc_handle_state { | |
540 | UVC_HANDLE_PASSIVE = 0, | |
541 | UVC_HANDLE_ACTIVE = 1, | |
542 | }; | |
543 | ||
544 | struct uvc_fh { | |
8e113595 | 545 | struct uvc_video_chain *chain; |
35f02a68 | 546 | struct uvc_streaming *stream; |
c0efd232 LP |
547 | enum uvc_handle_state state; |
548 | }; | |
549 | ||
550 | struct uvc_driver { | |
551 | struct usb_driver driver; | |
c0efd232 LP |
552 | }; |
553 | ||
554 | /* ------------------------------------------------------------------------ | |
555 | * Debugging, printing and logging | |
556 | */ | |
557 | ||
558 | #define UVC_TRACE_PROBE (1 << 0) | |
559 | #define UVC_TRACE_DESCR (1 << 1) | |
560 | #define UVC_TRACE_CONTROL (1 << 2) | |
561 | #define UVC_TRACE_FORMAT (1 << 3) | |
562 | #define UVC_TRACE_CAPTURE (1 << 4) | |
563 | #define UVC_TRACE_CALLS (1 << 5) | |
564 | #define UVC_TRACE_IOCTL (1 << 6) | |
565 | #define UVC_TRACE_FRAME (1 << 7) | |
566 | #define UVC_TRACE_SUSPEND (1 << 8) | |
567 | #define UVC_TRACE_STATUS (1 << 9) | |
663a4192 | 568 | #define UVC_TRACE_VIDEO (1 << 10) |
c0efd232 | 569 | |
44f0079e LP |
570 | #define UVC_WARN_MINMAX 0 |
571 | #define UVC_WARN_PROBE_DEF 1 | |
572 | ||
310fe524 | 573 | extern unsigned int uvc_clock_param; |
0fbd8ee6 | 574 | extern unsigned int uvc_no_drop_param; |
c0efd232 | 575 | extern unsigned int uvc_trace_param; |
b232a012 | 576 | extern unsigned int uvc_timeout_param; |
c0efd232 LP |
577 | |
578 | #define uvc_trace(flag, msg...) \ | |
579 | do { \ | |
580 | if (uvc_trace_param & flag) \ | |
581 | printk(KERN_DEBUG "uvcvideo: " msg); \ | |
582 | } while (0) | |
583 | ||
44f0079e LP |
584 | #define uvc_warn_once(dev, warn, msg...) \ |
585 | do { \ | |
586 | if (!test_and_set_bit(warn, &dev->warnings)) \ | |
587 | printk(KERN_INFO "uvcvideo: " msg); \ | |
588 | } while (0) | |
589 | ||
c0efd232 LP |
590 | #define uvc_printk(level, msg...) \ |
591 | printk(level "uvcvideo: " msg) | |
592 | ||
c0efd232 LP |
593 | /* -------------------------------------------------------------------------- |
594 | * Internal functions. | |
595 | */ | |
596 | ||
597 | /* Core driver */ | |
598 | extern struct uvc_driver uvc_driver; | |
c0efd232 | 599 | |
4ffc2d89 LP |
600 | extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); |
601 | ||
c0efd232 | 602 | /* Video buffers queue management. */ |
ff924203 | 603 | extern void uvc_queue_init(struct uvc_video_queue *queue, |
9bde9f26 | 604 | enum v4l2_buf_type type, int drop_corrupted); |
c0efd232 LP |
605 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, |
606 | unsigned int nbuffers, unsigned int buflength); | |
607 | extern int uvc_free_buffers(struct uvc_video_queue *queue); | |
608 | extern int uvc_query_buffer(struct uvc_video_queue *queue, | |
609 | struct v4l2_buffer *v4l2_buf); | |
610 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, | |
611 | struct v4l2_buffer *v4l2_buf); | |
612 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, | |
613 | struct v4l2_buffer *v4l2_buf, int nonblocking); | |
614 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); | |
615 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); | |
616 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | |
617 | struct uvc_buffer *buf); | |
4aa27597 LP |
618 | extern int uvc_queue_mmap(struct uvc_video_queue *queue, |
619 | struct vm_area_struct *vma); | |
c0efd232 LP |
620 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, |
621 | struct file *file, poll_table *wait); | |
72969447 BL |
622 | #ifndef CONFIG_MMU |
623 | extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, | |
624 | unsigned long pgoff); | |
625 | #endif | |
23ff6043 | 626 | extern int uvc_queue_allocated(struct uvc_video_queue *queue); |
c0efd232 LP |
627 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
628 | { | |
629 | return queue->flags & UVC_QUEUE_STREAMING; | |
630 | } | |
631 | ||
632 | /* V4L2 interface */ | |
bec43661 | 633 | extern const struct v4l2_file_operations uvc_fops; |
c0efd232 | 634 | |
4ffc2d89 LP |
635 | /* Media controller */ |
636 | extern int uvc_mc_register_entities(struct uvc_video_chain *chain); | |
637 | extern void uvc_mc_cleanup_entity(struct uvc_entity *entity); | |
638 | ||
c0efd232 | 639 | /* Video */ |
35f02a68 LP |
640 | extern int uvc_video_init(struct uvc_streaming *stream); |
641 | extern int uvc_video_suspend(struct uvc_streaming *stream); | |
642 | extern int uvc_video_resume(struct uvc_streaming *stream); | |
643 | extern int uvc_video_enable(struct uvc_streaming *stream, int enable); | |
644 | extern int uvc_probe_video(struct uvc_streaming *stream, | |
c0efd232 | 645 | struct uvc_streaming_control *probe); |
35f02a68 | 646 | extern int uvc_commit_video(struct uvc_streaming *stream, |
44f0079e | 647 | struct uvc_streaming_control *ctrl); |
c0efd232 LP |
648 | extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, |
649 | __u8 intfnum, __u8 cs, void *data, __u16 size); | |
c0efd232 LP |
650 | |
651 | /* Status */ | |
652 | extern int uvc_status_init(struct uvc_device *dev); | |
653 | extern void uvc_status_cleanup(struct uvc_device *dev); | |
04a37e0f LP |
654 | extern int uvc_status_start(struct uvc_device *dev); |
655 | extern void uvc_status_stop(struct uvc_device *dev); | |
c0efd232 LP |
656 | extern int uvc_status_suspend(struct uvc_device *dev); |
657 | extern int uvc_status_resume(struct uvc_device *dev); | |
658 | ||
659 | /* Controls */ | |
8e113595 | 660 | extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, |
c0efd232 | 661 | struct v4l2_queryctrl *v4l2_ctrl); |
23d9f3ef LP |
662 | extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain, |
663 | struct v4l2_querymenu *query_menu); | |
c0efd232 | 664 | |
ba2fa996 LP |
665 | extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, |
666 | const struct uvc_control_mapping *mapping); | |
c0efd232 LP |
667 | extern int uvc_ctrl_init_device(struct uvc_device *dev); |
668 | extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); | |
669 | extern int uvc_ctrl_resume_device(struct uvc_device *dev); | |
c0efd232 | 670 | |
8e113595 LP |
671 | extern int uvc_ctrl_begin(struct uvc_video_chain *chain); |
672 | extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback); | |
673 | static inline int uvc_ctrl_commit(struct uvc_video_chain *chain) | |
c0efd232 | 674 | { |
8e113595 | 675 | return __uvc_ctrl_commit(chain, 0); |
c0efd232 | 676 | } |
8e113595 | 677 | static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain) |
c0efd232 | 678 | { |
8e113595 | 679 | return __uvc_ctrl_commit(chain, 1); |
c0efd232 LP |
680 | } |
681 | ||
8e113595 | 682 | extern int uvc_ctrl_get(struct uvc_video_chain *chain, |
c0efd232 | 683 | struct v4l2_ext_control *xctrl); |
8e113595 | 684 | extern int uvc_ctrl_set(struct uvc_video_chain *chain, |
c0efd232 LP |
685 | struct v4l2_ext_control *xctrl); |
686 | ||
8e113595 | 687 | extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain, |
fe78d187 | 688 | struct uvc_xu_control_query *xqry); |
c0efd232 LP |
689 | |
690 | /* Utility functions */ | |
691 | extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, | |
692 | unsigned int n_terms, unsigned int threshold); | |
693 | extern uint32_t uvc_fraction_to_interval(uint32_t numerator, | |
694 | uint32_t denominator); | |
695 | extern struct usb_host_endpoint *uvc_find_endpoint( | |
696 | struct usb_host_interface *alts, __u8 epaddr); | |
697 | ||
698 | /* Quirks support */ | |
35f02a68 | 699 | void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream, |
c0efd232 LP |
700 | struct uvc_buffer *buf); |
701 | ||
702 | #endif /* __KERNEL__ */ | |
703 | ||
704 | #endif |