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