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