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