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