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 | |
| 7 | |
| 8 | /* |
| 9 | * Dynamic controls |
| 10 | */ |
| 11 | |
| 12 | /* Data types for UVC control data */ |
| 13 | #define UVC_CTRL_DATA_TYPE_RAW 0 |
| 14 | #define UVC_CTRL_DATA_TYPE_SIGNED 1 |
| 15 | #define UVC_CTRL_DATA_TYPE_UNSIGNED 2 |
| 16 | #define UVC_CTRL_DATA_TYPE_BOOLEAN 3 |
| 17 | #define UVC_CTRL_DATA_TYPE_ENUM 4 |
| 18 | #define UVC_CTRL_DATA_TYPE_BITMASK 5 |
| 19 | |
| 20 | /* Control flags */ |
| 21 | #define UVC_CONTROL_SET_CUR (1 << 0) |
| 22 | #define UVC_CONTROL_GET_CUR (1 << 1) |
| 23 | #define UVC_CONTROL_GET_MIN (1 << 2) |
| 24 | #define UVC_CONTROL_GET_MAX (1 << 3) |
| 25 | #define UVC_CONTROL_GET_RES (1 << 4) |
| 26 | #define UVC_CONTROL_GET_DEF (1 << 5) |
| 27 | /* Control should be saved at suspend and restored at resume. */ |
| 28 | #define UVC_CONTROL_RESTORE (1 << 6) |
| 29 | /* Control can be updated by the camera. */ |
| 30 | #define UVC_CONTROL_AUTO_UPDATE (1 << 7) |
| 31 | |
| 32 | #define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \ |
| 33 | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \ |
| 34 | UVC_CONTROL_GET_DEF) |
| 35 | |
| 36 | struct uvc_xu_control_info { |
| 37 | __u8 entity[16]; |
| 38 | __u8 index; |
| 39 | __u8 selector; |
| 40 | __u16 size; |
| 41 | __u32 flags; |
| 42 | }; |
| 43 | |
| 44 | struct uvc_xu_control_mapping { |
| 45 | __u32 id; |
| 46 | __u8 name[32]; |
| 47 | __u8 entity[16]; |
| 48 | __u8 selector; |
| 49 | |
| 50 | __u8 size; |
| 51 | __u8 offset; |
| 52 | enum v4l2_ctrl_type v4l2_type; |
| 53 | __u32 data_type; |
| 54 | }; |
| 55 | |
| 56 | struct uvc_xu_control { |
| 57 | __u8 unit; |
| 58 | __u8 selector; |
| 59 | __u16 size; |
| 60 | __u8 __user *data; |
| 61 | }; |
| 62 | |
| 63 | #define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) |
| 64 | #define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) |
| 65 | #define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) |
| 66 | #define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) |
| 67 | |
| 68 | #ifdef __KERNEL__ |
| 69 | |
| 70 | #include <linux/poll.h> |
| 71 | |
| 72 | /* -------------------------------------------------------------------------- |
| 73 | * UVC constants |
| 74 | */ |
| 75 | |
| 76 | #define SC_UNDEFINED 0x00 |
| 77 | #define SC_VIDEOCONTROL 0x01 |
| 78 | #define SC_VIDEOSTREAMING 0x02 |
| 79 | #define SC_VIDEO_INTERFACE_COLLECTION 0x03 |
| 80 | |
| 81 | #define PC_PROTOCOL_UNDEFINED 0x00 |
| 82 | |
| 83 | #define CS_UNDEFINED 0x20 |
| 84 | #define CS_DEVICE 0x21 |
| 85 | #define CS_CONFIGURATION 0x22 |
| 86 | #define CS_STRING 0x23 |
| 87 | #define CS_INTERFACE 0x24 |
| 88 | #define CS_ENDPOINT 0x25 |
| 89 | |
| 90 | /* VideoControl class specific interface descriptor */ |
| 91 | #define VC_DESCRIPTOR_UNDEFINED 0x00 |
| 92 | #define VC_HEADER 0x01 |
| 93 | #define VC_INPUT_TERMINAL 0x02 |
| 94 | #define VC_OUTPUT_TERMINAL 0x03 |
| 95 | #define VC_SELECTOR_UNIT 0x04 |
| 96 | #define VC_PROCESSING_UNIT 0x05 |
| 97 | #define VC_EXTENSION_UNIT 0x06 |
| 98 | |
| 99 | /* VideoStreaming class specific interface descriptor */ |
| 100 | #define VS_UNDEFINED 0x00 |
| 101 | #define VS_INPUT_HEADER 0x01 |
| 102 | #define VS_OUTPUT_HEADER 0x02 |
| 103 | #define VS_STILL_IMAGE_FRAME 0x03 |
| 104 | #define VS_FORMAT_UNCOMPRESSED 0x04 |
| 105 | #define VS_FRAME_UNCOMPRESSED 0x05 |
| 106 | #define VS_FORMAT_MJPEG 0x06 |
| 107 | #define VS_FRAME_MJPEG 0x07 |
| 108 | #define VS_FORMAT_MPEG2TS 0x0a |
| 109 | #define VS_FORMAT_DV 0x0c |
| 110 | #define VS_COLORFORMAT 0x0d |
| 111 | #define VS_FORMAT_FRAME_BASED 0x10 |
| 112 | #define VS_FRAME_FRAME_BASED 0x11 |
| 113 | #define VS_FORMAT_STREAM_BASED 0x12 |
| 114 | |
| 115 | /* Endpoint type */ |
| 116 | #define EP_UNDEFINED 0x00 |
| 117 | #define EP_GENERAL 0x01 |
| 118 | #define EP_ENDPOINT 0x02 |
| 119 | #define EP_INTERRUPT 0x03 |
| 120 | |
| 121 | /* Request codes */ |
| 122 | #define RC_UNDEFINED 0x00 |
| 123 | #define SET_CUR 0x01 |
| 124 | #define GET_CUR 0x81 |
| 125 | #define GET_MIN 0x82 |
| 126 | #define GET_MAX 0x83 |
| 127 | #define GET_RES 0x84 |
| 128 | #define GET_LEN 0x85 |
| 129 | #define GET_INFO 0x86 |
| 130 | #define GET_DEF 0x87 |
| 131 | |
| 132 | /* VideoControl interface controls */ |
| 133 | #define VC_CONTROL_UNDEFINED 0x00 |
| 134 | #define VC_VIDEO_POWER_MODE_CONTROL 0x01 |
| 135 | #define VC_REQUEST_ERROR_CODE_CONTROL 0x02 |
| 136 | |
| 137 | /* Terminal controls */ |
| 138 | #define TE_CONTROL_UNDEFINED 0x00 |
| 139 | |
| 140 | /* Selector Unit controls */ |
| 141 | #define SU_CONTROL_UNDEFINED 0x00 |
| 142 | #define SU_INPUT_SELECT_CONTROL 0x01 |
| 143 | |
| 144 | /* Camera Terminal controls */ |
| 145 | #define CT_CONTROL_UNDEFINED 0x00 |
| 146 | #define CT_SCANNING_MODE_CONTROL 0x01 |
| 147 | #define CT_AE_MODE_CONTROL 0x02 |
| 148 | #define CT_AE_PRIORITY_CONTROL 0x03 |
| 149 | #define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04 |
| 150 | #define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05 |
| 151 | #define CT_FOCUS_ABSOLUTE_CONTROL 0x06 |
| 152 | #define CT_FOCUS_RELATIVE_CONTROL 0x07 |
| 153 | #define CT_FOCUS_AUTO_CONTROL 0x08 |
| 154 | #define CT_IRIS_ABSOLUTE_CONTROL 0x09 |
| 155 | #define CT_IRIS_RELATIVE_CONTROL 0x0a |
| 156 | #define CT_ZOOM_ABSOLUTE_CONTROL 0x0b |
| 157 | #define CT_ZOOM_RELATIVE_CONTROL 0x0c |
| 158 | #define CT_PANTILT_ABSOLUTE_CONTROL 0x0d |
| 159 | #define CT_PANTILT_RELATIVE_CONTROL 0x0e |
| 160 | #define CT_ROLL_ABSOLUTE_CONTROL 0x0f |
| 161 | #define CT_ROLL_RELATIVE_CONTROL 0x10 |
| 162 | #define CT_PRIVACY_CONTROL 0x11 |
| 163 | |
| 164 | /* Processing Unit controls */ |
| 165 | #define PU_CONTROL_UNDEFINED 0x00 |
| 166 | #define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01 |
| 167 | #define PU_BRIGHTNESS_CONTROL 0x02 |
| 168 | #define PU_CONTRAST_CONTROL 0x03 |
| 169 | #define PU_GAIN_CONTROL 0x04 |
| 170 | #define PU_POWER_LINE_FREQUENCY_CONTROL 0x05 |
| 171 | #define PU_HUE_CONTROL 0x06 |
| 172 | #define PU_SATURATION_CONTROL 0x07 |
| 173 | #define PU_SHARPNESS_CONTROL 0x08 |
| 174 | #define PU_GAMMA_CONTROL 0x09 |
| 175 | #define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a |
| 176 | #define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b |
| 177 | #define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c |
| 178 | #define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d |
| 179 | #define PU_DIGITAL_MULTIPLIER_CONTROL 0x0e |
| 180 | #define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f |
| 181 | #define PU_HUE_AUTO_CONTROL 0x10 |
| 182 | #define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11 |
| 183 | #define PU_ANALOG_LOCK_STATUS_CONTROL 0x12 |
| 184 | |
| 185 | #define LXU_MOTOR_PANTILT_RELATIVE_CONTROL 0x01 |
| 186 | #define LXU_MOTOR_PANTILT_RESET_CONTROL 0x02 |
| 187 | #define LXU_MOTOR_FOCUS_MOTOR_CONTROL 0x03 |
| 188 | |
| 189 | /* VideoStreaming interface controls */ |
| 190 | #define VS_CONTROL_UNDEFINED 0x00 |
| 191 | #define VS_PROBE_CONTROL 0x01 |
| 192 | #define VS_COMMIT_CONTROL 0x02 |
| 193 | #define VS_STILL_PROBE_CONTROL 0x03 |
| 194 | #define VS_STILL_COMMIT_CONTROL 0x04 |
| 195 | #define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05 |
| 196 | #define VS_STREAM_ERROR_CODE_CONTROL 0x06 |
| 197 | #define VS_GENERATE_KEY_FRAME_CONTROL 0x07 |
| 198 | #define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08 |
| 199 | #define VS_SYNC_DELAY_CONTROL 0x09 |
| 200 | |
| 201 | #define TT_VENDOR_SPECIFIC 0x0100 |
| 202 | #define TT_STREAMING 0x0101 |
| 203 | |
| 204 | /* Input Terminal types */ |
| 205 | #define ITT_VENDOR_SPECIFIC 0x0200 |
| 206 | #define ITT_CAMERA 0x0201 |
| 207 | #define ITT_MEDIA_TRANSPORT_INPUT 0x0202 |
| 208 | |
| 209 | /* Output Terminal types */ |
| 210 | #define OTT_VENDOR_SPECIFIC 0x0300 |
| 211 | #define OTT_DISPLAY 0x0301 |
| 212 | #define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302 |
| 213 | |
| 214 | /* External Terminal types */ |
| 215 | #define EXTERNAL_VENDOR_SPECIFIC 0x0400 |
| 216 | #define COMPOSITE_CONNECTOR 0x0401 |
| 217 | #define SVIDEO_CONNECTOR 0x0402 |
| 218 | #define COMPONENT_CONNECTOR 0x0403 |
| 219 | |
| 220 | #define UVC_TERM_INPUT 0x0000 |
| 221 | #define UVC_TERM_OUTPUT 0x8000 |
| 222 | |
| 223 | #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) |
| 224 | #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) |
| 225 | #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) |
| 226 | #define UVC_ENTITY_IS_ITERM(entity) \ |
| 227 | (((entity)->type & 0x8000) == UVC_TERM_INPUT) |
| 228 | #define UVC_ENTITY_IS_OTERM(entity) \ |
| 229 | (((entity)->type & 0x8000) == UVC_TERM_OUTPUT) |
| 230 | |
| 231 | #define UVC_STATUS_TYPE_CONTROL 1 |
| 232 | #define UVC_STATUS_TYPE_STREAMING 2 |
| 233 | |
| 234 | /* ------------------------------------------------------------------------ |
| 235 | * GUIDs |
| 236 | */ |
| 237 | #define UVC_GUID_UVC_CAMERA \ |
| 238 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 239 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} |
| 240 | #define UVC_GUID_UVC_OUTPUT \ |
| 241 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 242 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} |
| 243 | #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ |
| 244 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 245 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} |
| 246 | #define UVC_GUID_UVC_PROCESSING \ |
| 247 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} |
| 249 | #define UVC_GUID_UVC_SELECTOR \ |
| 250 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 251 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} |
| 252 | |
| 253 | #define UVC_GUID_LOGITECH_DEV_INFO \ |
| 254 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ |
| 255 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1e} |
| 256 | #define UVC_GUID_LOGITECH_USER_HW \ |
| 257 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ |
| 258 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1f} |
| 259 | #define UVC_GUID_LOGITECH_VIDEO \ |
| 260 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ |
| 261 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50} |
| 262 | #define UVC_GUID_LOGITECH_MOTOR \ |
| 263 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ |
| 264 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56} |
| 265 | |
| 266 | #define UVC_GUID_FORMAT_MJPEG \ |
| 267 | { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ |
| 268 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 269 | #define UVC_GUID_FORMAT_YUY2 \ |
| 270 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 271 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 272 | #define UVC_GUID_FORMAT_NV12 \ |
| 273 | { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 274 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 275 | #define UVC_GUID_FORMAT_YV12 \ |
| 276 | { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 277 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 278 | #define UVC_GUID_FORMAT_I420 \ |
| 279 | { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 280 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 281 | #define UVC_GUID_FORMAT_UYVY \ |
| 282 | { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ |
| 283 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 284 | #define UVC_GUID_FORMAT_Y800 \ |
| 285 | { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 286 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 287 | #define UVC_GUID_FORMAT_BY8 \ |
| 288 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ |
| 289 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 290 | |
| 291 | |
| 292 | /* ------------------------------------------------------------------------ |
| 293 | * Driver specific constants. |
| 294 | */ |
| 295 | |
| 296 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) |
| 297 | |
| 298 | /* Number of isochronous URBs. */ |
| 299 | #define UVC_URBS 5 |
| 300 | /* Maximum number of packets per isochronous URB. */ |
| 301 | #define UVC_MAX_ISO_PACKETS 40 |
| 302 | /* Maximum frame size in bytes, for sanity checking. */ |
| 303 | #define UVC_MAX_FRAME_SIZE (16*1024*1024) |
| 304 | /* Maximum number of video buffers. */ |
| 305 | #define UVC_MAX_VIDEO_BUFFERS 32 |
Ming Lei | a31a405 | 2008-09-16 03:32:20 -0300 | [diff] [blame] | 306 | /* Maximum status buffer size in bytes of interrupt URB. */ |
| 307 | #define UVC_MAX_STATUS_SIZE 16 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 308 | |
| 309 | #define UVC_CTRL_CONTROL_TIMEOUT 300 |
| 310 | #define UVC_CTRL_STREAMING_TIMEOUT 1000 |
| 311 | |
| 312 | /* Devices quirks */ |
| 313 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 |
| 314 | #define UVC_QUIRK_PROBE_MINMAX 0x00000002 |
| 315 | #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 |
| 316 | #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 |
| 317 | #define UVC_QUIRK_STREAM_NO_FID 0x00000010 |
| 318 | #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 319 | #define UVC_QUIRK_PRUNE_CONTROLS 0x00000040 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 320 | |
| 321 | /* Format flags */ |
| 322 | #define UVC_FMT_FLAG_COMPRESSED 0x00000001 |
| 323 | #define UVC_FMT_FLAG_STREAM 0x00000002 |
| 324 | |
| 325 | /* ------------------------------------------------------------------------ |
| 326 | * Structures. |
| 327 | */ |
| 328 | |
| 329 | struct uvc_device; |
| 330 | |
| 331 | /* TODO: Put the most frequently accessed fields at the beginning of |
| 332 | * structures to maximize cache efficiency. |
| 333 | */ |
| 334 | struct uvc_streaming_control { |
| 335 | __u16 bmHint; |
| 336 | __u8 bFormatIndex; |
| 337 | __u8 bFrameIndex; |
| 338 | __u32 dwFrameInterval; |
| 339 | __u16 wKeyFrameRate; |
| 340 | __u16 wPFrameRate; |
| 341 | __u16 wCompQuality; |
| 342 | __u16 wCompWindowSize; |
| 343 | __u16 wDelay; |
| 344 | __u32 dwMaxVideoFrameSize; |
| 345 | __u32 dwMaxPayloadTransferSize; |
| 346 | __u32 dwClockFrequency; |
| 347 | __u8 bmFramingInfo; |
| 348 | __u8 bPreferedVersion; |
| 349 | __u8 bMinVersion; |
| 350 | __u8 bMaxVersion; |
| 351 | }; |
| 352 | |
| 353 | struct uvc_menu_info { |
| 354 | __u32 value; |
| 355 | __u8 name[32]; |
| 356 | }; |
| 357 | |
| 358 | struct uvc_control_info { |
| 359 | struct list_head list; |
| 360 | struct list_head mappings; |
| 361 | |
| 362 | __u8 entity[16]; |
| 363 | __u8 index; |
| 364 | __u8 selector; |
| 365 | |
| 366 | __u16 size; |
| 367 | __u32 flags; |
| 368 | }; |
| 369 | |
| 370 | struct uvc_control_mapping { |
| 371 | struct list_head list; |
| 372 | |
| 373 | struct uvc_control_info *ctrl; |
| 374 | |
| 375 | __u32 id; |
| 376 | __u8 name[32]; |
| 377 | __u8 entity[16]; |
| 378 | __u8 selector; |
| 379 | |
| 380 | __u8 size; |
| 381 | __u8 offset; |
| 382 | enum v4l2_ctrl_type v4l2_type; |
| 383 | __u32 data_type; |
| 384 | |
| 385 | struct uvc_menu_info *menu_info; |
| 386 | __u32 menu_count; |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame^] | 387 | |
| 388 | __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query, |
| 389 | const __u8 *data); |
| 390 | void (*set) (struct uvc_control_mapping *mapping, __s32 value, |
| 391 | __u8 *data); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 392 | }; |
| 393 | |
| 394 | struct uvc_control { |
| 395 | struct uvc_entity *entity; |
| 396 | struct uvc_control_info *info; |
| 397 | |
| 398 | __u8 index; /* Used to match the uvc_control entry with a |
| 399 | uvc_control_info. */ |
| 400 | __u8 dirty : 1, |
| 401 | loaded : 1, |
| 402 | modified : 1; |
| 403 | |
| 404 | __u8 *data; |
| 405 | }; |
| 406 | |
| 407 | struct uvc_format_desc { |
| 408 | char *name; |
| 409 | __u8 guid[16]; |
| 410 | __u32 fcc; |
| 411 | }; |
| 412 | |
| 413 | /* The term 'entity' refers to both UVC units and UVC terminals. |
| 414 | * |
| 415 | * The type field is either the terminal type (wTerminalType in the terminal |
| 416 | * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). |
| 417 | * As the bDescriptorSubtype field is one byte long, the type value will |
| 418 | * always have a null MSB for units. All terminal types defined by the UVC |
| 419 | * specification have a non-null MSB, so it is safe to use the MSB to |
| 420 | * differentiate between units and terminals as long as the descriptor parsing |
| 421 | * code makes sure terminal types have a non-null MSB. |
| 422 | * |
| 423 | * For terminals, the type's most significant bit stores the terminal |
| 424 | * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should |
| 425 | * always be accessed with the UVC_ENTITY_* macros and never directly. |
| 426 | */ |
| 427 | |
| 428 | struct uvc_entity { |
| 429 | struct list_head list; /* Entity as part of a UVC device. */ |
| 430 | struct list_head chain; /* Entity as part of a video device |
| 431 | * chain. */ |
| 432 | __u8 id; |
| 433 | __u16 type; |
| 434 | char name[64]; |
| 435 | |
| 436 | union { |
| 437 | struct { |
| 438 | __u16 wObjectiveFocalLengthMin; |
| 439 | __u16 wObjectiveFocalLengthMax; |
| 440 | __u16 wOcularFocalLength; |
| 441 | __u8 bControlSize; |
| 442 | __u8 *bmControls; |
| 443 | } camera; |
| 444 | |
| 445 | struct { |
| 446 | __u8 bControlSize; |
| 447 | __u8 *bmControls; |
| 448 | __u8 bTransportModeSize; |
| 449 | __u8 *bmTransportModes; |
| 450 | } media; |
| 451 | |
| 452 | struct { |
| 453 | __u8 bSourceID; |
| 454 | } output; |
| 455 | |
| 456 | struct { |
| 457 | __u8 bSourceID; |
| 458 | __u16 wMaxMultiplier; |
| 459 | __u8 bControlSize; |
| 460 | __u8 *bmControls; |
| 461 | __u8 bmVideoStandards; |
| 462 | } processing; |
| 463 | |
| 464 | struct { |
| 465 | __u8 bNrInPins; |
| 466 | __u8 *baSourceID; |
| 467 | } selector; |
| 468 | |
| 469 | struct { |
| 470 | __u8 guidExtensionCode[16]; |
| 471 | __u8 bNumControls; |
| 472 | __u8 bNrInPins; |
| 473 | __u8 *baSourceID; |
| 474 | __u8 bControlSize; |
| 475 | __u8 *bmControls; |
| 476 | __u8 *bmControlsType; |
| 477 | } extension; |
| 478 | }; |
| 479 | |
| 480 | unsigned int ncontrols; |
| 481 | struct uvc_control *controls; |
| 482 | }; |
| 483 | |
| 484 | struct uvc_frame { |
| 485 | __u8 bFrameIndex; |
| 486 | __u8 bmCapabilities; |
| 487 | __u16 wWidth; |
| 488 | __u16 wHeight; |
| 489 | __u32 dwMinBitRate; |
| 490 | __u32 dwMaxBitRate; |
| 491 | __u32 dwMaxVideoFrameBufferSize; |
| 492 | __u8 bFrameIntervalType; |
| 493 | __u32 dwDefaultFrameInterval; |
| 494 | __u32 *dwFrameInterval; |
| 495 | }; |
| 496 | |
| 497 | struct uvc_format { |
| 498 | __u8 type; |
| 499 | __u8 index; |
| 500 | __u8 bpp; |
| 501 | __u8 colorspace; |
| 502 | __u32 fcc; |
| 503 | __u32 flags; |
| 504 | |
| 505 | char name[32]; |
| 506 | |
| 507 | unsigned int nframes; |
| 508 | struct uvc_frame *frame; |
| 509 | }; |
| 510 | |
| 511 | struct uvc_streaming_header { |
| 512 | __u8 bNumFormats; |
| 513 | __u8 bEndpointAddress; |
| 514 | __u8 bTerminalLink; |
| 515 | __u8 bControlSize; |
| 516 | __u8 *bmaControls; |
| 517 | /* The following fields are used by input headers only. */ |
| 518 | __u8 bmInfo; |
| 519 | __u8 bStillCaptureMethod; |
| 520 | __u8 bTriggerSupport; |
| 521 | __u8 bTriggerUsage; |
| 522 | }; |
| 523 | |
| 524 | struct uvc_streaming { |
| 525 | struct list_head list; |
| 526 | |
| 527 | struct usb_interface *intf; |
| 528 | int intfnum; |
| 529 | __u16 maxpsize; |
| 530 | |
| 531 | struct uvc_streaming_header header; |
| 532 | |
| 533 | unsigned int nformats; |
| 534 | struct uvc_format *format; |
| 535 | |
| 536 | struct uvc_streaming_control ctrl; |
| 537 | struct uvc_format *cur_format; |
| 538 | struct uvc_frame *cur_frame; |
| 539 | |
| 540 | struct mutex mutex; |
| 541 | }; |
| 542 | |
| 543 | enum uvc_buffer_state { |
| 544 | UVC_BUF_STATE_IDLE = 0, |
| 545 | UVC_BUF_STATE_QUEUED = 1, |
| 546 | UVC_BUF_STATE_ACTIVE = 2, |
| 547 | UVC_BUF_STATE_DONE = 3, |
| 548 | UVC_BUF_STATE_ERROR = 4, |
| 549 | }; |
| 550 | |
| 551 | struct uvc_buffer { |
| 552 | unsigned long vma_use_count; |
| 553 | struct list_head stream; |
| 554 | |
| 555 | /* Touched by interrupt handler. */ |
| 556 | struct v4l2_buffer buf; |
| 557 | struct list_head queue; |
| 558 | wait_queue_head_t wait; |
| 559 | enum uvc_buffer_state state; |
| 560 | }; |
| 561 | |
| 562 | #define UVC_QUEUE_STREAMING (1 << 0) |
| 563 | #define UVC_QUEUE_DISCONNECTED (1 << 1) |
| 564 | #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2) |
| 565 | |
| 566 | struct uvc_video_queue { |
| 567 | void *mem; |
| 568 | unsigned int flags; |
| 569 | __u32 sequence; |
| 570 | |
| 571 | unsigned int count; |
| 572 | unsigned int buf_size; |
| 573 | struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS]; |
| 574 | struct mutex mutex; /* protects buffers and mainqueue */ |
| 575 | spinlock_t irqlock; /* protects irqqueue */ |
| 576 | |
| 577 | struct list_head mainqueue; |
| 578 | struct list_head irqqueue; |
| 579 | }; |
| 580 | |
| 581 | struct uvc_video_device { |
| 582 | struct uvc_device *dev; |
| 583 | struct video_device *vdev; |
| 584 | atomic_t active; |
| 585 | unsigned int frozen : 1; |
| 586 | |
| 587 | struct list_head iterms; |
| 588 | struct uvc_entity *oterm; |
| 589 | struct uvc_entity *processing; |
| 590 | struct uvc_entity *selector; |
| 591 | struct list_head extensions; |
| 592 | struct mutex ctrl_mutex; |
| 593 | |
| 594 | struct uvc_video_queue queue; |
| 595 | |
| 596 | /* Video streaming object, must always be non-NULL. */ |
| 597 | struct uvc_streaming *streaming; |
| 598 | |
| 599 | void (*decode) (struct urb *urb, struct uvc_video_device *video, |
| 600 | struct uvc_buffer *buf); |
| 601 | |
| 602 | /* Context data used by the bulk completion handler. */ |
| 603 | struct { |
| 604 | __u8 header[256]; |
| 605 | unsigned int header_size; |
| 606 | int skip_payload; |
| 607 | __u32 payload_size; |
| 608 | __u32 max_payload_size; |
| 609 | } bulk; |
| 610 | |
| 611 | struct urb *urb[UVC_URBS]; |
| 612 | char *urb_buffer[UVC_URBS]; |
Laurent Pinchart | e01117c | 2008-07-04 00:36:21 -0300 | [diff] [blame] | 613 | dma_addr_t urb_dma[UVC_URBS]; |
| 614 | unsigned int urb_size; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 615 | |
| 616 | __u8 last_fid; |
| 617 | }; |
| 618 | |
| 619 | enum uvc_device_state { |
| 620 | UVC_DEV_DISCONNECTED = 1, |
| 621 | }; |
| 622 | |
| 623 | struct uvc_device { |
| 624 | struct usb_device *udev; |
| 625 | struct usb_interface *intf; |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 626 | unsigned long warnings; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 627 | __u32 quirks; |
| 628 | int intfnum; |
| 629 | char name[32]; |
| 630 | |
| 631 | enum uvc_device_state state; |
| 632 | struct kref kref; |
| 633 | struct list_head list; |
| 634 | |
| 635 | /* Video control interface */ |
| 636 | __u16 uvc_version; |
| 637 | __u32 clock_frequency; |
| 638 | |
| 639 | struct list_head entities; |
| 640 | |
| 641 | struct uvc_video_device video; |
| 642 | |
| 643 | /* Status Interrupt Endpoint */ |
| 644 | struct usb_host_endpoint *int_ep; |
| 645 | struct urb *int_urb; |
Ming Lei | a31a405 | 2008-09-16 03:32:20 -0300 | [diff] [blame] | 646 | __u8 *status; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 647 | struct input_dev *input; |
| 648 | |
| 649 | /* Video Streaming interfaces */ |
| 650 | struct list_head streaming; |
| 651 | }; |
| 652 | |
| 653 | enum uvc_handle_state { |
| 654 | UVC_HANDLE_PASSIVE = 0, |
| 655 | UVC_HANDLE_ACTIVE = 1, |
| 656 | }; |
| 657 | |
| 658 | struct uvc_fh { |
| 659 | struct uvc_video_device *device; |
| 660 | enum uvc_handle_state state; |
| 661 | }; |
| 662 | |
| 663 | struct uvc_driver { |
| 664 | struct usb_driver driver; |
| 665 | |
| 666 | struct mutex open_mutex; /* protects from open/disconnect race */ |
| 667 | |
| 668 | struct list_head devices; /* struct uvc_device list */ |
| 669 | struct list_head controls; /* struct uvc_control_info list */ |
| 670 | struct mutex ctrl_mutex; /* protects controls and devices |
| 671 | lists */ |
| 672 | }; |
| 673 | |
| 674 | /* ------------------------------------------------------------------------ |
| 675 | * Debugging, printing and logging |
| 676 | */ |
| 677 | |
| 678 | #define UVC_TRACE_PROBE (1 << 0) |
| 679 | #define UVC_TRACE_DESCR (1 << 1) |
| 680 | #define UVC_TRACE_CONTROL (1 << 2) |
| 681 | #define UVC_TRACE_FORMAT (1 << 3) |
| 682 | #define UVC_TRACE_CAPTURE (1 << 4) |
| 683 | #define UVC_TRACE_CALLS (1 << 5) |
| 684 | #define UVC_TRACE_IOCTL (1 << 6) |
| 685 | #define UVC_TRACE_FRAME (1 << 7) |
| 686 | #define UVC_TRACE_SUSPEND (1 << 8) |
| 687 | #define UVC_TRACE_STATUS (1 << 9) |
| 688 | |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 689 | #define UVC_WARN_MINMAX 0 |
| 690 | #define UVC_WARN_PROBE_DEF 1 |
| 691 | |
Laurent Pinchart | 0fbd8ee | 2008-12-06 16:25:14 -0300 | [diff] [blame] | 692 | extern unsigned int uvc_no_drop_param; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 693 | extern unsigned int uvc_trace_param; |
| 694 | |
| 695 | #define uvc_trace(flag, msg...) \ |
| 696 | do { \ |
| 697 | if (uvc_trace_param & flag) \ |
| 698 | printk(KERN_DEBUG "uvcvideo: " msg); \ |
| 699 | } while (0) |
| 700 | |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 701 | #define uvc_warn_once(dev, warn, msg...) \ |
| 702 | do { \ |
| 703 | if (!test_and_set_bit(warn, &dev->warnings)) \ |
| 704 | printk(KERN_INFO "uvcvideo: " msg); \ |
| 705 | } while (0) |
| 706 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 707 | #define uvc_printk(level, msg...) \ |
| 708 | printk(level "uvcvideo: " msg) |
| 709 | |
| 710 | #define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \ |
| 711 | "%02x%02x%02x%02x%02x%02x" |
| 712 | #define UVC_GUID_ARGS(guid) \ |
| 713 | (guid)[3], (guid)[2], (guid)[1], (guid)[0], \ |
| 714 | (guid)[5], (guid)[4], \ |
| 715 | (guid)[7], (guid)[6], \ |
| 716 | (guid)[8], (guid)[9], \ |
| 717 | (guid)[10], (guid)[11], (guid)[12], \ |
| 718 | (guid)[13], (guid)[14], (guid)[15] |
| 719 | |
| 720 | /* -------------------------------------------------------------------------- |
| 721 | * Internal functions. |
| 722 | */ |
| 723 | |
| 724 | /* Core driver */ |
| 725 | extern struct uvc_driver uvc_driver; |
| 726 | extern void uvc_delete(struct kref *kref); |
| 727 | |
| 728 | /* Video buffers queue management. */ |
| 729 | extern void uvc_queue_init(struct uvc_video_queue *queue); |
| 730 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, |
| 731 | unsigned int nbuffers, unsigned int buflength); |
| 732 | extern int uvc_free_buffers(struct uvc_video_queue *queue); |
| 733 | extern int uvc_query_buffer(struct uvc_video_queue *queue, |
| 734 | struct v4l2_buffer *v4l2_buf); |
| 735 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, |
| 736 | struct v4l2_buffer *v4l2_buf); |
| 737 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, |
| 738 | struct v4l2_buffer *v4l2_buf, int nonblocking); |
| 739 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); |
| 740 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); |
| 741 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, |
| 742 | struct uvc_buffer *buf); |
| 743 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, |
| 744 | struct file *file, poll_table *wait); |
| 745 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
| 746 | { |
| 747 | return queue->flags & UVC_QUEUE_STREAMING; |
| 748 | } |
| 749 | |
| 750 | /* V4L2 interface */ |
| 751 | extern struct file_operations uvc_fops; |
| 752 | |
| 753 | /* Video */ |
| 754 | extern int uvc_video_init(struct uvc_video_device *video); |
| 755 | extern int uvc_video_suspend(struct uvc_video_device *video); |
| 756 | extern int uvc_video_resume(struct uvc_video_device *video); |
| 757 | extern int uvc_video_enable(struct uvc_video_device *video, int enable); |
| 758 | extern int uvc_probe_video(struct uvc_video_device *video, |
| 759 | struct uvc_streaming_control *probe); |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 760 | extern int uvc_commit_video(struct uvc_video_device *video, |
| 761 | struct uvc_streaming_control *ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 762 | extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, |
| 763 | __u8 intfnum, __u8 cs, void *data, __u16 size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 764 | |
| 765 | /* Status */ |
| 766 | extern int uvc_status_init(struct uvc_device *dev); |
| 767 | extern void uvc_status_cleanup(struct uvc_device *dev); |
| 768 | extern int uvc_status_suspend(struct uvc_device *dev); |
| 769 | extern int uvc_status_resume(struct uvc_device *dev); |
| 770 | |
| 771 | /* Controls */ |
| 772 | extern struct uvc_control *uvc_find_control(struct uvc_video_device *video, |
| 773 | __u32 v4l2_id, struct uvc_control_mapping **mapping); |
| 774 | extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video, |
| 775 | struct v4l2_queryctrl *v4l2_ctrl); |
| 776 | |
| 777 | extern int uvc_ctrl_add_info(struct uvc_control_info *info); |
| 778 | extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping); |
| 779 | extern int uvc_ctrl_init_device(struct uvc_device *dev); |
| 780 | extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); |
| 781 | extern int uvc_ctrl_resume_device(struct uvc_device *dev); |
| 782 | extern void uvc_ctrl_init(void); |
| 783 | |
| 784 | extern int uvc_ctrl_begin(struct uvc_video_device *video); |
| 785 | extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback); |
| 786 | static inline int uvc_ctrl_commit(struct uvc_video_device *video) |
| 787 | { |
| 788 | return __uvc_ctrl_commit(video, 0); |
| 789 | } |
| 790 | static inline int uvc_ctrl_rollback(struct uvc_video_device *video) |
| 791 | { |
| 792 | return __uvc_ctrl_commit(video, 1); |
| 793 | } |
| 794 | |
| 795 | extern int uvc_ctrl_get(struct uvc_video_device *video, |
| 796 | struct v4l2_ext_control *xctrl); |
| 797 | extern int uvc_ctrl_set(struct uvc_video_device *video, |
| 798 | struct v4l2_ext_control *xctrl); |
| 799 | |
| 800 | extern int uvc_xu_ctrl_query(struct uvc_video_device *video, |
| 801 | struct uvc_xu_control *ctrl, int set); |
| 802 | |
| 803 | /* Utility functions */ |
| 804 | extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, |
| 805 | unsigned int n_terms, unsigned int threshold); |
| 806 | extern uint32_t uvc_fraction_to_interval(uint32_t numerator, |
| 807 | uint32_t denominator); |
| 808 | extern struct usb_host_endpoint *uvc_find_endpoint( |
| 809 | struct usb_host_interface *alts, __u8 epaddr); |
| 810 | |
| 811 | /* Quirks support */ |
| 812 | void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video, |
| 813 | struct uvc_buffer *buf); |
| 814 | |
| 815 | #endif /* __KERNEL__ */ |
| 816 | |
| 817 | #endif |
Hans Verkuil | f87086e | 2008-07-18 00:50:58 -0300 | [diff] [blame] | 818 | |