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) |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 30 | /* Control is an extension unit control. */ |
| 31 | #define UVC_CONTROL_EXTENSION (1 << 8) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 32 | |
| 33 | #define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \ |
| 34 | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \ |
| 35 | UVC_CONTROL_GET_DEF) |
| 36 | |
| 37 | struct uvc_xu_control_info { |
| 38 | __u8 entity[16]; |
| 39 | __u8 index; |
| 40 | __u8 selector; |
| 41 | __u16 size; |
| 42 | __u32 flags; |
| 43 | }; |
| 44 | |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 45 | struct uvc_menu_info { |
| 46 | __u32 value; |
| 47 | __u8 name[32]; |
| 48 | }; |
| 49 | |
| 50 | struct uvc_xu_control_mapping_old { |
| 51 | __u8 reserved[64]; |
| 52 | }; |
| 53 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 54 | struct uvc_xu_control_mapping { |
| 55 | __u32 id; |
| 56 | __u8 name[32]; |
| 57 | __u8 entity[16]; |
| 58 | __u8 selector; |
| 59 | |
| 60 | __u8 size; |
| 61 | __u8 offset; |
| 62 | enum v4l2_ctrl_type v4l2_type; |
| 63 | __u32 data_type; |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 64 | |
| 65 | struct uvc_menu_info __user *menu_info; |
| 66 | __u32 menu_count; |
| 67 | |
| 68 | __u32 reserved[4]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | struct uvc_xu_control { |
| 72 | __u8 unit; |
| 73 | __u8 selector; |
| 74 | __u16 size; |
| 75 | __u8 __user *data; |
| 76 | }; |
| 77 | |
| 78 | #define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 79 | #define UVCIOC_CTRL_MAP_OLD _IOWR('U', 2, struct uvc_xu_control_mapping_old) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 80 | #define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) |
| 81 | #define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) |
| 82 | #define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) |
| 83 | |
| 84 | #ifdef __KERNEL__ |
| 85 | |
| 86 | #include <linux/poll.h> |
Laurent Pinchart | de05f63 | 2009-06-26 12:15:38 -0300 | [diff] [blame] | 87 | #include <linux/usb/video.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 88 | |
| 89 | /* -------------------------------------------------------------------------- |
| 90 | * UVC constants |
| 91 | */ |
| 92 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 93 | #define UVC_TERM_INPUT 0x0000 |
| 94 | #define UVC_TERM_OUTPUT 0x8000 |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 95 | #define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 96 | |
| 97 | #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) |
| 98 | #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) |
| 99 | #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) |
| 100 | #define UVC_ENTITY_IS_ITERM(entity) \ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 101 | (UVC_ENTITY_IS_TERM(entity) && \ |
| 102 | ((entity)->type & 0x8000) == UVC_TERM_INPUT) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 103 | #define UVC_ENTITY_IS_OTERM(entity) \ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 104 | (UVC_ENTITY_IS_TERM(entity) && \ |
| 105 | ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 106 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 107 | |
| 108 | /* ------------------------------------------------------------------------ |
| 109 | * GUIDs |
| 110 | */ |
| 111 | #define UVC_GUID_UVC_CAMERA \ |
| 112 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 113 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} |
| 114 | #define UVC_GUID_UVC_OUTPUT \ |
| 115 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 116 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} |
| 117 | #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ |
| 118 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} |
| 120 | #define UVC_GUID_UVC_PROCESSING \ |
| 121 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} |
| 123 | #define UVC_GUID_UVC_SELECTOR \ |
| 124 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 125 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} |
| 126 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 127 | #define UVC_GUID_FORMAT_MJPEG \ |
| 128 | { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ |
| 129 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 130 | #define UVC_GUID_FORMAT_YUY2 \ |
| 131 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 132 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Daniel Ritz | 68f194e | 2009-12-12 14:57:17 -0300 | [diff] [blame] | 133 | #define UVC_GUID_FORMAT_YUY2_ISIGHT \ |
| 134 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 135 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 136 | #define UVC_GUID_FORMAT_NV12 \ |
| 137 | { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 138 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 139 | #define UVC_GUID_FORMAT_YV12 \ |
| 140 | { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 141 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 142 | #define UVC_GUID_FORMAT_I420 \ |
| 143 | { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 144 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 145 | #define UVC_GUID_FORMAT_UYVY \ |
| 146 | { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ |
| 147 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 148 | #define UVC_GUID_FORMAT_Y800 \ |
| 149 | { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 150 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | 61421206 | 2010-04-12 10:41:22 -0300 | [diff] [blame] | 151 | #define UVC_GUID_FORMAT_Y16 \ |
| 152 | { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ |
| 153 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 154 | #define UVC_GUID_FORMAT_BY8 \ |
| 155 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ |
| 156 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 157 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 158 | /* ------------------------------------------------------------------------ |
| 159 | * Driver specific constants. |
| 160 | */ |
| 161 | |
| 162 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) |
| 163 | |
| 164 | /* Number of isochronous URBs. */ |
| 165 | #define UVC_URBS 5 |
Laurent Pinchart | efdc8a9 | 2009-01-18 17:46:30 -0300 | [diff] [blame] | 166 | /* Maximum number of packets per URB. */ |
| 167 | #define UVC_MAX_PACKETS 32 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 168 | /* Maximum number of video buffers. */ |
| 169 | #define UVC_MAX_VIDEO_BUFFERS 32 |
Ming Lei | a31a405 | 2008-09-16 03:32:20 -0300 | [diff] [blame] | 170 | /* Maximum status buffer size in bytes of interrupt URB. */ |
| 171 | #define UVC_MAX_STATUS_SIZE 16 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 172 | |
| 173 | #define UVC_CTRL_CONTROL_TIMEOUT 300 |
Laurent Pinchart | 56d15cd | 2010-01-19 08:59:21 -0300 | [diff] [blame] | 174 | #define UVC_CTRL_STREAMING_TIMEOUT 5000 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 175 | |
| 176 | /* Devices quirks */ |
| 177 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 |
| 178 | #define UVC_QUIRK_PROBE_MINMAX 0x00000002 |
| 179 | #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 |
| 180 | #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 |
| 181 | #define UVC_QUIRK_STREAM_NO_FID 0x00000010 |
| 182 | #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 |
Laurent Pinchart | 50144ae | 2009-02-16 17:41:52 -0300 | [diff] [blame] | 183 | #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 |
Laurent Pinchart | bab6f66 | 2009-07-19 18:39:56 -0300 | [diff] [blame] | 184 | #define UVC_QUIRK_PROBE_DEF 0x00000100 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 185 | |
| 186 | /* Format flags */ |
| 187 | #define UVC_FMT_FLAG_COMPRESSED 0x00000001 |
| 188 | #define UVC_FMT_FLAG_STREAM 0x00000002 |
| 189 | |
| 190 | /* ------------------------------------------------------------------------ |
| 191 | * Structures. |
| 192 | */ |
| 193 | |
| 194 | struct uvc_device; |
| 195 | |
| 196 | /* TODO: Put the most frequently accessed fields at the beginning of |
| 197 | * structures to maximize cache efficiency. |
| 198 | */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 199 | struct uvc_control_info { |
| 200 | struct list_head list; |
| 201 | struct list_head mappings; |
| 202 | |
| 203 | __u8 entity[16]; |
| 204 | __u8 index; |
| 205 | __u8 selector; |
| 206 | |
| 207 | __u16 size; |
| 208 | __u32 flags; |
| 209 | }; |
| 210 | |
| 211 | struct uvc_control_mapping { |
| 212 | struct list_head list; |
| 213 | |
| 214 | struct uvc_control_info *ctrl; |
| 215 | |
| 216 | __u32 id; |
| 217 | __u8 name[32]; |
| 218 | __u8 entity[16]; |
| 219 | __u8 selector; |
| 220 | |
| 221 | __u8 size; |
| 222 | __u8 offset; |
| 223 | enum v4l2_ctrl_type v4l2_type; |
| 224 | __u32 data_type; |
| 225 | |
| 226 | struct uvc_menu_info *menu_info; |
| 227 | __u32 menu_count; |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 228 | |
| 229 | __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query, |
| 230 | const __u8 *data); |
| 231 | void (*set) (struct uvc_control_mapping *mapping, __s32 value, |
| 232 | __u8 *data); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | struct uvc_control { |
| 236 | struct uvc_entity *entity; |
| 237 | struct uvc_control_info *info; |
| 238 | |
| 239 | __u8 index; /* Used to match the uvc_control entry with a |
| 240 | uvc_control_info. */ |
| 241 | __u8 dirty : 1, |
| 242 | loaded : 1, |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 243 | modified : 1, |
| 244 | cached : 1; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 245 | |
Laurent Pinchart | b30ece5 | 2010-06-18 11:31:24 -0300 | [diff] [blame] | 246 | __u8 *uvc_data; |
| 247 | __u8 *uvc_info; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | struct uvc_format_desc { |
| 251 | char *name; |
| 252 | __u8 guid[16]; |
| 253 | __u32 fcc; |
| 254 | }; |
| 255 | |
| 256 | /* The term 'entity' refers to both UVC units and UVC terminals. |
| 257 | * |
| 258 | * The type field is either the terminal type (wTerminalType in the terminal |
| 259 | * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). |
| 260 | * As the bDescriptorSubtype field is one byte long, the type value will |
| 261 | * always have a null MSB for units. All terminal types defined by the UVC |
| 262 | * specification have a non-null MSB, so it is safe to use the MSB to |
| 263 | * differentiate between units and terminals as long as the descriptor parsing |
| 264 | * code makes sure terminal types have a non-null MSB. |
| 265 | * |
| 266 | * For terminals, the type's most significant bit stores the terminal |
| 267 | * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should |
| 268 | * always be accessed with the UVC_ENTITY_* macros and never directly. |
| 269 | */ |
| 270 | |
| 271 | struct uvc_entity { |
| 272 | struct list_head list; /* Entity as part of a UVC device. */ |
| 273 | struct list_head chain; /* Entity as part of a video device |
| 274 | * chain. */ |
| 275 | __u8 id; |
| 276 | __u16 type; |
| 277 | char name[64]; |
| 278 | |
| 279 | union { |
| 280 | struct { |
| 281 | __u16 wObjectiveFocalLengthMin; |
| 282 | __u16 wObjectiveFocalLengthMax; |
| 283 | __u16 wOcularFocalLength; |
| 284 | __u8 bControlSize; |
| 285 | __u8 *bmControls; |
| 286 | } camera; |
| 287 | |
| 288 | struct { |
| 289 | __u8 bControlSize; |
| 290 | __u8 *bmControls; |
| 291 | __u8 bTransportModeSize; |
| 292 | __u8 *bmTransportModes; |
| 293 | } media; |
| 294 | |
| 295 | struct { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 296 | } output; |
| 297 | |
| 298 | struct { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 299 | __u16 wMaxMultiplier; |
| 300 | __u8 bControlSize; |
| 301 | __u8 *bmControls; |
| 302 | __u8 bmVideoStandards; |
| 303 | } processing; |
| 304 | |
| 305 | struct { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 306 | } selector; |
| 307 | |
| 308 | struct { |
| 309 | __u8 guidExtensionCode[16]; |
| 310 | __u8 bNumControls; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 311 | __u8 bControlSize; |
| 312 | __u8 *bmControls; |
| 313 | __u8 *bmControlsType; |
| 314 | } extension; |
| 315 | }; |
| 316 | |
Laurent Pinchart | 8ca5a63 | 2009-11-25 12:00:30 -0300 | [diff] [blame] | 317 | __u8 bNrInPins; |
| 318 | __u8 *baSourceID; |
| 319 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 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 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 364 | enum uvc_buffer_state { |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 365 | UVC_BUF_STATE_IDLE = 0, |
| 366 | UVC_BUF_STATE_QUEUED = 1, |
| 367 | UVC_BUF_STATE_ACTIVE = 2, |
Laurent Pinchart | d7c0d43 | 2009-12-16 21:20:45 -0300 | [diff] [blame] | 368 | UVC_BUF_STATE_READY = 3, |
| 369 | UVC_BUF_STATE_DONE = 4, |
| 370 | UVC_BUF_STATE_ERROR = 5, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | struct uvc_buffer { |
| 374 | unsigned long vma_use_count; |
| 375 | struct list_head stream; |
| 376 | |
| 377 | /* Touched by interrupt handler. */ |
| 378 | struct v4l2_buffer buf; |
| 379 | struct list_head queue; |
| 380 | wait_queue_head_t wait; |
| 381 | enum uvc_buffer_state state; |
Laurent Pinchart | 9bde9f2 | 2010-06-17 06:52:37 -0300 | [diff] [blame] | 382 | unsigned int error; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | #define UVC_QUEUE_STREAMING (1 << 0) |
| 386 | #define UVC_QUEUE_DISCONNECTED (1 << 1) |
Laurent Pinchart | 9bde9f2 | 2010-06-17 06:52:37 -0300 | [diff] [blame] | 387 | #define UVC_QUEUE_DROP_CORRUPTED (1 << 2) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 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 | |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 411 | struct list_head entities; /* All entities */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 412 | struct uvc_entity *processing; /* Processing unit */ |
| 413 | struct uvc_entity *selector; /* Selector unit */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 414 | |
| 415 | struct mutex ctrl_mutex; |
| 416 | }; |
| 417 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 418 | struct uvc_streaming { |
| 419 | struct list_head list; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 420 | struct uvc_device *dev; |
| 421 | struct video_device *vdev; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 422 | struct uvc_video_chain *chain; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 423 | atomic_t active; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 424 | |
| 425 | struct usb_interface *intf; |
| 426 | int intfnum; |
| 427 | __u16 maxpsize; |
| 428 | |
| 429 | struct uvc_streaming_header header; |
| 430 | enum v4l2_buf_type type; |
| 431 | |
| 432 | unsigned int nformats; |
| 433 | struct uvc_format *format; |
| 434 | |
| 435 | struct uvc_streaming_control ctrl; |
| 436 | struct uvc_format *cur_format; |
| 437 | struct uvc_frame *cur_frame; |
| 438 | |
| 439 | struct mutex mutex; |
| 440 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 441 | unsigned int frozen : 1; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 442 | struct uvc_video_queue queue; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 443 | void (*decode) (struct urb *urb, struct uvc_streaming *video, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 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]; |
Laurent Pinchart | e01117c | 2008-07-04 00:36:21 -0300 | [diff] [blame] | 457 | dma_addr_t urb_dma[UVC_URBS]; |
| 458 | unsigned int urb_size; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 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; |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 470 | unsigned long warnings; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 471 | __u32 quirks; |
| 472 | int intfnum; |
| 473 | char name[32]; |
| 474 | |
| 475 | enum uvc_device_state state; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 476 | struct list_head list; |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 477 | atomic_t users; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 478 | |
| 479 | /* Video control interface */ |
| 480 | __u16 uvc_version; |
| 481 | __u32 clock_frequency; |
| 482 | |
| 483 | struct list_head entities; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 484 | struct list_head chains; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 485 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 486 | /* Video Streaming interfaces */ |
| 487 | struct list_head streams; |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 488 | atomic_t nstreams; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 489 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 490 | /* Status Interrupt Endpoint */ |
| 491 | struct usb_host_endpoint *int_ep; |
| 492 | struct urb *int_urb; |
Ming Lei | a31a405 | 2008-09-16 03:32:20 -0300 | [diff] [blame] | 493 | __u8 *status; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 494 | struct input_dev *input; |
Laurent Pinchart | f180152 | 2009-01-22 12:45:10 -0300 | [diff] [blame] | 495 | char input_phys[64]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | enum uvc_handle_state { |
| 499 | UVC_HANDLE_PASSIVE = 0, |
| 500 | UVC_HANDLE_ACTIVE = 1, |
| 501 | }; |
| 502 | |
| 503 | struct uvc_fh { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 504 | struct uvc_video_chain *chain; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 505 | struct uvc_streaming *stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 506 | enum uvc_handle_state state; |
| 507 | }; |
| 508 | |
| 509 | struct uvc_driver { |
| 510 | struct usb_driver driver; |
| 511 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 512 | struct list_head devices; /* struct uvc_device list */ |
| 513 | struct list_head controls; /* struct uvc_control_info list */ |
| 514 | struct mutex ctrl_mutex; /* protects controls and devices |
| 515 | lists */ |
| 516 | }; |
| 517 | |
| 518 | /* ------------------------------------------------------------------------ |
| 519 | * Debugging, printing and logging |
| 520 | */ |
| 521 | |
| 522 | #define UVC_TRACE_PROBE (1 << 0) |
| 523 | #define UVC_TRACE_DESCR (1 << 1) |
| 524 | #define UVC_TRACE_CONTROL (1 << 2) |
| 525 | #define UVC_TRACE_FORMAT (1 << 3) |
| 526 | #define UVC_TRACE_CAPTURE (1 << 4) |
| 527 | #define UVC_TRACE_CALLS (1 << 5) |
| 528 | #define UVC_TRACE_IOCTL (1 << 6) |
| 529 | #define UVC_TRACE_FRAME (1 << 7) |
| 530 | #define UVC_TRACE_SUSPEND (1 << 8) |
| 531 | #define UVC_TRACE_STATUS (1 << 9) |
Laurent Pinchart | 663a419 | 2009-08-06 11:41:17 -0300 | [diff] [blame] | 532 | #define UVC_TRACE_VIDEO (1 << 10) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 533 | |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 534 | #define UVC_WARN_MINMAX 0 |
| 535 | #define UVC_WARN_PROBE_DEF 1 |
| 536 | |
Laurent Pinchart | 310fe52 | 2009-12-09 22:57:48 -0300 | [diff] [blame] | 537 | extern unsigned int uvc_clock_param; |
Laurent Pinchart | 0fbd8ee | 2008-12-06 16:25:14 -0300 | [diff] [blame] | 538 | extern unsigned int uvc_no_drop_param; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 539 | extern unsigned int uvc_trace_param; |
Laurent Pinchart | b232a01 | 2009-10-09 20:55:23 -0300 | [diff] [blame] | 540 | extern unsigned int uvc_timeout_param; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 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 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 557 | /* -------------------------------------------------------------------------- |
| 558 | * Internal functions. |
| 559 | */ |
| 560 | |
| 561 | /* Core driver */ |
| 562 | extern struct uvc_driver uvc_driver; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 563 | |
| 564 | /* Video buffers queue management. */ |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 565 | extern void uvc_queue_init(struct uvc_video_queue *queue, |
Laurent Pinchart | 9bde9f2 | 2010-06-17 06:52:37 -0300 | [diff] [blame] | 566 | enum v4l2_buf_type type, int drop_corrupted); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 567 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, |
| 568 | unsigned int nbuffers, unsigned int buflength); |
| 569 | extern int uvc_free_buffers(struct uvc_video_queue *queue); |
| 570 | extern int uvc_query_buffer(struct uvc_video_queue *queue, |
| 571 | struct v4l2_buffer *v4l2_buf); |
| 572 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, |
| 573 | struct v4l2_buffer *v4l2_buf); |
| 574 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, |
| 575 | struct v4l2_buffer *v4l2_buf, int nonblocking); |
| 576 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); |
| 577 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); |
| 578 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, |
| 579 | struct uvc_buffer *buf); |
| 580 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, |
| 581 | struct file *file, poll_table *wait); |
Laurent Pinchart | 23ff604 | 2009-06-04 09:26:39 -0300 | [diff] [blame] | 582 | extern int uvc_queue_allocated(struct uvc_video_queue *queue); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 583 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
| 584 | { |
| 585 | return queue->flags & UVC_QUEUE_STREAMING; |
| 586 | } |
| 587 | |
| 588 | /* V4L2 interface */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 589 | extern const struct v4l2_file_operations uvc_fops; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 590 | |
| 591 | /* Video */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 592 | extern int uvc_video_init(struct uvc_streaming *stream); |
| 593 | extern int uvc_video_suspend(struct uvc_streaming *stream); |
| 594 | extern int uvc_video_resume(struct uvc_streaming *stream); |
| 595 | extern int uvc_video_enable(struct uvc_streaming *stream, int enable); |
| 596 | extern int uvc_probe_video(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 597 | struct uvc_streaming_control *probe); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 598 | extern int uvc_commit_video(struct uvc_streaming *stream, |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 599 | struct uvc_streaming_control *ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 600 | extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, |
| 601 | __u8 intfnum, __u8 cs, void *data, __u16 size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 602 | |
| 603 | /* Status */ |
| 604 | extern int uvc_status_init(struct uvc_device *dev); |
| 605 | extern void uvc_status_cleanup(struct uvc_device *dev); |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 606 | extern int uvc_status_start(struct uvc_device *dev); |
| 607 | extern void uvc_status_stop(struct uvc_device *dev); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 608 | extern int uvc_status_suspend(struct uvc_device *dev); |
| 609 | extern int uvc_status_resume(struct uvc_device *dev); |
| 610 | |
| 611 | /* Controls */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 612 | extern struct uvc_control *uvc_find_control(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 613 | __u32 v4l2_id, struct uvc_control_mapping **mapping); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 614 | extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 615 | struct v4l2_queryctrl *v4l2_ctrl); |
| 616 | |
| 617 | extern int uvc_ctrl_add_info(struct uvc_control_info *info); |
| 618 | extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping); |
| 619 | extern int uvc_ctrl_init_device(struct uvc_device *dev); |
| 620 | extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); |
| 621 | extern int uvc_ctrl_resume_device(struct uvc_device *dev); |
| 622 | extern void uvc_ctrl_init(void); |
Laurent Pinchart | 561474c2 | 2010-02-18 16:38:52 -0300 | [diff] [blame] | 623 | extern void uvc_ctrl_cleanup(void); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 624 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 625 | extern int uvc_ctrl_begin(struct uvc_video_chain *chain); |
| 626 | extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback); |
| 627 | static inline int uvc_ctrl_commit(struct uvc_video_chain *chain) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 628 | { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 629 | return __uvc_ctrl_commit(chain, 0); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 630 | } |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 631 | static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 632 | { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 633 | return __uvc_ctrl_commit(chain, 1); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 634 | } |
| 635 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 636 | extern int uvc_ctrl_get(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 637 | struct v4l2_ext_control *xctrl); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 638 | extern int uvc_ctrl_set(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 639 | struct v4l2_ext_control *xctrl); |
| 640 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 641 | extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 642 | struct uvc_xu_control *ctrl, int set); |
| 643 | |
| 644 | /* Utility functions */ |
| 645 | extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, |
| 646 | unsigned int n_terms, unsigned int threshold); |
| 647 | extern uint32_t uvc_fraction_to_interval(uint32_t numerator, |
| 648 | uint32_t denominator); |
| 649 | extern struct usb_host_endpoint *uvc_find_endpoint( |
| 650 | struct usb_host_interface *alts, __u8 epaddr); |
| 651 | |
| 652 | /* Quirks support */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 653 | void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 654 | struct uvc_buffer *buf); |
| 655 | |
| 656 | #endif /* __KERNEL__ */ |
| 657 | |
| 658 | #endif |
Hans Verkuil | f87086e | 2008-07-18 00:50:58 -0300 | [diff] [blame] | 659 | |