Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1 | #ifndef _USB_VIDEO_H_ |
| 2 | #define _USB_VIDEO_H_ |
| 3 | |
Laurent Pinchart | 227bd5b | 2011-07-30 16:19:49 -0300 | [diff] [blame] | 4 | #ifndef __KERNEL__ |
| 5 | #error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead." |
| 6 | #endif /* __KERNEL__ */ |
| 7 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 8 | #include <linux/kernel.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 9 | #include <linux/poll.h> |
Laurent Pinchart | 4ffc2d8 | 2010-01-21 05:39:52 -0300 | [diff] [blame] | 10 | #include <linux/usb.h> |
Laurent Pinchart | de05f63 | 2009-06-26 12:15:38 -0300 | [diff] [blame] | 11 | #include <linux/usb/video.h> |
Laurent Pinchart | 5f70881 | 2010-11-21 17:15:44 -0300 | [diff] [blame] | 12 | #include <linux/uvcvideo.h> |
Laurent Pinchart | 227bd5b | 2011-07-30 16:19:49 -0300 | [diff] [blame] | 13 | #include <linux/videodev2.h> |
Laurent Pinchart | 5a254d7 | 2010-01-21 05:39:47 -0300 | [diff] [blame] | 14 | #include <media/media-device.h> |
| 15 | #include <media/v4l2-device.h> |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 16 | #include <media/v4l2-event.h> |
| 17 | #include <media/v4l2-fh.h> |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 18 | #include <media/videobuf2-core.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 19 | |
| 20 | /* -------------------------------------------------------------------------- |
| 21 | * UVC constants |
| 22 | */ |
| 23 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 24 | #define UVC_TERM_INPUT 0x0000 |
| 25 | #define UVC_TERM_OUTPUT 0x8000 |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 26 | #define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 27 | |
| 28 | #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) |
| 29 | #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) |
| 30 | #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) |
| 31 | #define UVC_ENTITY_IS_ITERM(entity) \ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 32 | (UVC_ENTITY_IS_TERM(entity) && \ |
| 33 | ((entity)->type & 0x8000) == UVC_TERM_INPUT) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 34 | #define UVC_ENTITY_IS_OTERM(entity) \ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 35 | (UVC_ENTITY_IS_TERM(entity) && \ |
| 36 | ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 37 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 38 | |
| 39 | /* ------------------------------------------------------------------------ |
| 40 | * GUIDs |
| 41 | */ |
| 42 | #define UVC_GUID_UVC_CAMERA \ |
| 43 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} |
| 45 | #define UVC_GUID_UVC_OUTPUT \ |
| 46 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} |
| 48 | #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ |
| 49 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} |
| 51 | #define UVC_GUID_UVC_PROCESSING \ |
| 52 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} |
| 54 | #define UVC_GUID_UVC_SELECTOR \ |
| 55 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} |
| 57 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 58 | #define UVC_GUID_FORMAT_MJPEG \ |
| 59 | { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ |
| 60 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 61 | #define UVC_GUID_FORMAT_YUY2 \ |
| 62 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 63 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Daniel Ritz | 68f194e | 2009-12-12 14:57:17 -0300 | [diff] [blame] | 64 | #define UVC_GUID_FORMAT_YUY2_ISIGHT \ |
| 65 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 66 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 67 | #define UVC_GUID_FORMAT_NV12 \ |
| 68 | { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 69 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 70 | #define UVC_GUID_FORMAT_YV12 \ |
| 71 | { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ |
| 72 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 73 | #define UVC_GUID_FORMAT_I420 \ |
| 74 | { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 75 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 76 | #define UVC_GUID_FORMAT_UYVY \ |
| 77 | { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ |
| 78 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 79 | #define UVC_GUID_FORMAT_Y800 \ |
| 80 | { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 81 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | 61421206 | 2010-04-12 10:41:22 -0300 | [diff] [blame] | 82 | #define UVC_GUID_FORMAT_Y16 \ |
| 83 | { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ |
| 84 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 85 | #define UVC_GUID_FORMAT_BY8 \ |
| 86 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ |
| 87 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | 5079107 | 2011-03-06 08:32:04 -0300 | [diff] [blame] | 88 | #define UVC_GUID_FORMAT_RGBP \ |
| 89 | { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ |
| 90 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Hans de Goede | 7225a1d | 2011-05-11 09:56:20 -0300 | [diff] [blame] | 91 | #define UVC_GUID_FORMAT_M420 \ |
| 92 | { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ |
| 93 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 94 | |
Stephan Lachowsky | 25ad8a8 | 2011-01-28 16:38:58 -0300 | [diff] [blame] | 95 | #define UVC_GUID_FORMAT_H264 \ |
| 96 | { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \ |
| 97 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} |
| 98 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 99 | /* ------------------------------------------------------------------------ |
| 100 | * Driver specific constants. |
| 101 | */ |
| 102 | |
Mauro Carvalho Chehab | fd3e582 | 2011-06-25 13:50:37 -0300 | [diff] [blame] | 103 | #define DRIVER_VERSION "1.1.1" |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 104 | |
| 105 | /* Number of isochronous URBs. */ |
| 106 | #define UVC_URBS 5 |
Laurent Pinchart | efdc8a9 | 2009-01-18 17:46:30 -0300 | [diff] [blame] | 107 | /* Maximum number of packets per URB. */ |
| 108 | #define UVC_MAX_PACKETS 32 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 109 | /* Maximum number of video buffers. */ |
| 110 | #define UVC_MAX_VIDEO_BUFFERS 32 |
Ming Lei | a31a405 | 2008-09-16 03:32:20 -0300 | [diff] [blame] | 111 | /* Maximum status buffer size in bytes of interrupt URB. */ |
| 112 | #define UVC_MAX_STATUS_SIZE 16 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 113 | |
| 114 | #define UVC_CTRL_CONTROL_TIMEOUT 300 |
Laurent Pinchart | 56d15cd | 2010-01-19 08:59:21 -0300 | [diff] [blame] | 115 | #define UVC_CTRL_STREAMING_TIMEOUT 5000 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 116 | |
Martin Rubli | 8fb91b3 | 2010-09-08 04:15:23 -0300 | [diff] [blame] | 117 | /* Maximum allowed number of control mappings per device */ |
| 118 | #define UVC_MAX_CONTROL_MAPPINGS 1024 |
Haogang Chen | 806e23e | 2011-11-29 18:32:25 -0300 | [diff] [blame] | 119 | #define UVC_MAX_CONTROL_MENU_ENTRIES 32 |
Martin Rubli | 8fb91b3 | 2010-09-08 04:15:23 -0300 | [diff] [blame] | 120 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 121 | /* Devices quirks */ |
| 122 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 |
| 123 | #define UVC_QUIRK_PROBE_MINMAX 0x00000002 |
| 124 | #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 |
| 125 | #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 |
| 126 | #define UVC_QUIRK_STREAM_NO_FID 0x00000010 |
| 127 | #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 |
Laurent Pinchart | 50144ae | 2009-02-16 17:41:52 -0300 | [diff] [blame] | 128 | #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 |
Laurent Pinchart | bab6f66 | 2009-07-19 18:39:56 -0300 | [diff] [blame] | 129 | #define UVC_QUIRK_PROBE_DEF 0x00000100 |
Laurent Pinchart | 86d8b6a | 2010-09-16 12:37:26 -0300 | [diff] [blame] | 130 | #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 131 | |
| 132 | /* Format flags */ |
| 133 | #define UVC_FMT_FLAG_COMPRESSED 0x00000001 |
| 134 | #define UVC_FMT_FLAG_STREAM 0x00000002 |
| 135 | |
| 136 | /* ------------------------------------------------------------------------ |
| 137 | * Structures. |
| 138 | */ |
| 139 | |
| 140 | struct uvc_device; |
| 141 | |
| 142 | /* TODO: Put the most frequently accessed fields at the beginning of |
| 143 | * structures to maximize cache efficiency. |
| 144 | */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 145 | struct uvc_control_info { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 146 | struct list_head mappings; |
| 147 | |
| 148 | __u8 entity[16]; |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 149 | __u8 index; /* Bit index in bmControls */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 150 | __u8 selector; |
| 151 | |
| 152 | __u16 size; |
| 153 | __u32 flags; |
| 154 | }; |
| 155 | |
| 156 | struct uvc_control_mapping { |
| 157 | struct list_head list; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 158 | struct list_head ev_subs; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 159 | |
| 160 | struct uvc_control_info *ctrl; |
| 161 | |
| 162 | __u32 id; |
| 163 | __u8 name[32]; |
| 164 | __u8 entity[16]; |
| 165 | __u8 selector; |
| 166 | |
| 167 | __u8 size; |
| 168 | __u8 offset; |
| 169 | enum v4l2_ctrl_type v4l2_type; |
| 170 | __u32 data_type; |
| 171 | |
| 172 | struct uvc_menu_info *menu_info; |
| 173 | __u32 menu_count; |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 174 | |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame^] | 175 | __u32 master_id; |
| 176 | __s32 master_manual; |
| 177 | __u32 slave_ids[2]; |
| 178 | |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 179 | __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query, |
| 180 | const __u8 *data); |
| 181 | void (*set) (struct uvc_control_mapping *mapping, __s32 value, |
| 182 | __u8 *data); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | struct uvc_control { |
| 186 | struct uvc_entity *entity; |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 187 | struct uvc_control_info info; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 188 | |
| 189 | __u8 index; /* Used to match the uvc_control entry with a |
| 190 | uvc_control_info. */ |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 191 | __u8 dirty:1, |
| 192 | loaded:1, |
| 193 | modified:1, |
| 194 | cached:1, |
| 195 | initialized:1; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 196 | |
Laurent Pinchart | b30ece5 | 2010-06-18 11:31:24 -0300 | [diff] [blame] | 197 | __u8 *uvc_data; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | struct uvc_format_desc { |
| 201 | char *name; |
| 202 | __u8 guid[16]; |
| 203 | __u32 fcc; |
| 204 | }; |
| 205 | |
| 206 | /* The term 'entity' refers to both UVC units and UVC terminals. |
| 207 | * |
| 208 | * The type field is either the terminal type (wTerminalType in the terminal |
| 209 | * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). |
| 210 | * As the bDescriptorSubtype field is one byte long, the type value will |
| 211 | * always have a null MSB for units. All terminal types defined by the UVC |
| 212 | * specification have a non-null MSB, so it is safe to use the MSB to |
| 213 | * differentiate between units and terminals as long as the descriptor parsing |
| 214 | * code makes sure terminal types have a non-null MSB. |
| 215 | * |
| 216 | * For terminals, the type's most significant bit stores the terminal |
| 217 | * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should |
| 218 | * always be accessed with the UVC_ENTITY_* macros and never directly. |
| 219 | */ |
| 220 | |
| 221 | struct uvc_entity { |
| 222 | struct list_head list; /* Entity as part of a UVC device. */ |
| 223 | struct list_head chain; /* Entity as part of a video device |
| 224 | * chain. */ |
| 225 | __u8 id; |
| 226 | __u16 type; |
| 227 | char name[64]; |
| 228 | |
Laurent Pinchart | 4ffc2d8 | 2010-01-21 05:39:52 -0300 | [diff] [blame] | 229 | /* Media controller-related fields. */ |
Laurent Pinchart | 8a65a94 | 2010-01-21 08:56:19 -0300 | [diff] [blame] | 230 | struct video_device *vdev; |
Laurent Pinchart | 4ffc2d8 | 2010-01-21 05:39:52 -0300 | [diff] [blame] | 231 | struct v4l2_subdev subdev; |
| 232 | unsigned int num_pads; |
| 233 | unsigned int num_links; |
| 234 | struct media_pad *pads; |
| 235 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 236 | union { |
| 237 | struct { |
| 238 | __u16 wObjectiveFocalLengthMin; |
| 239 | __u16 wObjectiveFocalLengthMax; |
| 240 | __u16 wOcularFocalLength; |
| 241 | __u8 bControlSize; |
| 242 | __u8 *bmControls; |
| 243 | } camera; |
| 244 | |
| 245 | struct { |
| 246 | __u8 bControlSize; |
| 247 | __u8 *bmControls; |
| 248 | __u8 bTransportModeSize; |
| 249 | __u8 *bmTransportModes; |
| 250 | } media; |
| 251 | |
| 252 | struct { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 253 | } output; |
| 254 | |
| 255 | struct { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 256 | __u16 wMaxMultiplier; |
| 257 | __u8 bControlSize; |
| 258 | __u8 *bmControls; |
| 259 | __u8 bmVideoStandards; |
| 260 | } processing; |
| 261 | |
| 262 | struct { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 263 | } selector; |
| 264 | |
| 265 | struct { |
| 266 | __u8 guidExtensionCode[16]; |
| 267 | __u8 bNumControls; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 268 | __u8 bControlSize; |
| 269 | __u8 *bmControls; |
| 270 | __u8 *bmControlsType; |
| 271 | } extension; |
| 272 | }; |
| 273 | |
Laurent Pinchart | 8ca5a63 | 2009-11-25 12:00:30 -0300 | [diff] [blame] | 274 | __u8 bNrInPins; |
| 275 | __u8 *baSourceID; |
| 276 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 277 | unsigned int ncontrols; |
| 278 | struct uvc_control *controls; |
| 279 | }; |
| 280 | |
| 281 | struct uvc_frame { |
| 282 | __u8 bFrameIndex; |
| 283 | __u8 bmCapabilities; |
| 284 | __u16 wWidth; |
| 285 | __u16 wHeight; |
| 286 | __u32 dwMinBitRate; |
| 287 | __u32 dwMaxBitRate; |
| 288 | __u32 dwMaxVideoFrameBufferSize; |
| 289 | __u8 bFrameIntervalType; |
| 290 | __u32 dwDefaultFrameInterval; |
| 291 | __u32 *dwFrameInterval; |
| 292 | }; |
| 293 | |
| 294 | struct uvc_format { |
| 295 | __u8 type; |
| 296 | __u8 index; |
| 297 | __u8 bpp; |
| 298 | __u8 colorspace; |
| 299 | __u32 fcc; |
| 300 | __u32 flags; |
| 301 | |
| 302 | char name[32]; |
| 303 | |
| 304 | unsigned int nframes; |
| 305 | struct uvc_frame *frame; |
| 306 | }; |
| 307 | |
| 308 | struct uvc_streaming_header { |
| 309 | __u8 bNumFormats; |
| 310 | __u8 bEndpointAddress; |
| 311 | __u8 bTerminalLink; |
| 312 | __u8 bControlSize; |
| 313 | __u8 *bmaControls; |
| 314 | /* The following fields are used by input headers only. */ |
| 315 | __u8 bmInfo; |
| 316 | __u8 bStillCaptureMethod; |
| 317 | __u8 bTriggerSupport; |
| 318 | __u8 bTriggerUsage; |
| 319 | }; |
| 320 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 321 | enum uvc_buffer_state { |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 322 | UVC_BUF_STATE_IDLE = 0, |
| 323 | UVC_BUF_STATE_QUEUED = 1, |
| 324 | UVC_BUF_STATE_ACTIVE = 2, |
Laurent Pinchart | d7c0d43 | 2009-12-16 21:20:45 -0300 | [diff] [blame] | 325 | UVC_BUF_STATE_READY = 3, |
| 326 | UVC_BUF_STATE_DONE = 4, |
| 327 | UVC_BUF_STATE_ERROR = 5, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | struct uvc_buffer { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 331 | struct vb2_buffer buf; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 332 | struct list_head queue; |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 333 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 334 | enum uvc_buffer_state state; |
Laurent Pinchart | 9bde9f2 | 2010-06-17 06:52:37 -0300 | [diff] [blame] | 335 | unsigned int error; |
Laurent Pinchart | 3d95e93 | 2011-10-24 11:49:19 -0300 | [diff] [blame] | 336 | |
| 337 | void *mem; |
| 338 | unsigned int length; |
| 339 | unsigned int bytesused; |
Laurent Pinchart | 66847ef | 2011-09-24 10:46:55 -0300 | [diff] [blame] | 340 | |
| 341 | u32 pts; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 342 | }; |
| 343 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 344 | #define UVC_QUEUE_DISCONNECTED (1 << 0) |
| 345 | #define UVC_QUEUE_DROP_CORRUPTED (1 << 1) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 346 | |
| 347 | struct uvc_video_queue { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 348 | struct vb2_queue queue; |
| 349 | struct mutex mutex; /* Protects queue */ |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 350 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 351 | unsigned int flags; |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 352 | unsigned int buf_used; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 353 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 354 | spinlock_t irqlock; /* Protects irqqueue */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 355 | struct list_head irqqueue; |
| 356 | }; |
| 357 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 358 | struct uvc_video_chain { |
| 359 | struct uvc_device *dev; |
| 360 | struct list_head list; |
| 361 | |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 362 | struct list_head entities; /* All entities */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 363 | struct uvc_entity *processing; /* Processing unit */ |
| 364 | struct uvc_entity *selector; /* Selector unit */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 365 | |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 366 | struct mutex ctrl_mutex; /* Protects ctrl.info */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 367 | }; |
| 368 | |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 369 | struct uvc_stats_frame { |
| 370 | unsigned int size; /* Number of bytes captured */ |
| 371 | unsigned int first_data; /* Index of the first non-empty packet */ |
| 372 | |
| 373 | unsigned int nb_packets; /* Number of packets */ |
| 374 | unsigned int nb_empty; /* Number of empty packets */ |
| 375 | unsigned int nb_invalid; /* Number of packets with an invalid header */ |
| 376 | unsigned int nb_errors; /* Number of packets with the error bit set */ |
Laurent Pinchart | 25738cb | 2011-11-03 12:30:17 -0300 | [diff] [blame] | 377 | |
| 378 | unsigned int nb_pts; /* Number of packets with a PTS timestamp */ |
| 379 | unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */ |
| 380 | unsigned int last_pts_diff; /* Index of the last PTS difference */ |
| 381 | bool has_initial_pts; /* Whether the first non-empty packet has a PTS */ |
| 382 | bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */ |
| 383 | u32 pts; /* PTS of the last packet */ |
| 384 | |
| 385 | unsigned int nb_scr; /* Number of packets with a SCR timestamp */ |
| 386 | unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */ |
| 387 | u16 scr_sof; /* SCR.SOF of the last packet */ |
| 388 | u32 scr_stc; /* SCR.STC of the last packet */ |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | struct uvc_stats_stream { |
| 392 | struct timespec start_ts; /* Stream start timestamp */ |
| 393 | struct timespec stop_ts; /* Stream stop timestamp */ |
| 394 | |
| 395 | unsigned int nb_frames; /* Number of frames */ |
| 396 | |
| 397 | unsigned int nb_packets; /* Number of packets */ |
| 398 | unsigned int nb_empty; /* Number of empty packets */ |
| 399 | unsigned int nb_invalid; /* Number of packets with an invalid header */ |
| 400 | unsigned int nb_errors; /* Number of packets with the error bit set */ |
Laurent Pinchart | 25738cb | 2011-11-03 12:30:17 -0300 | [diff] [blame] | 401 | |
| 402 | unsigned int nb_pts_constant; /* Number of frames with constant PTS */ |
| 403 | unsigned int nb_pts_early; /* Number of frames with early PTS */ |
| 404 | unsigned int nb_pts_initial; /* Number of frames with initial PTS */ |
| 405 | |
| 406 | unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */ |
| 407 | unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */ |
| 408 | unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */ |
| 409 | unsigned int scr_sof; /* STC.SOF of the last packet */ |
| 410 | unsigned int min_sof; /* Minimum STC.SOF value */ |
| 411 | unsigned int max_sof; /* Maximum STC.SOF value */ |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 412 | }; |
| 413 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 414 | struct uvc_streaming { |
| 415 | struct list_head list; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 416 | struct uvc_device *dev; |
| 417 | struct video_device *vdev; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 418 | struct uvc_video_chain *chain; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 419 | atomic_t active; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 420 | |
| 421 | struct usb_interface *intf; |
| 422 | int intfnum; |
| 423 | __u16 maxpsize; |
| 424 | |
| 425 | struct uvc_streaming_header header; |
| 426 | enum v4l2_buf_type type; |
| 427 | |
| 428 | unsigned int nformats; |
| 429 | struct uvc_format *format; |
| 430 | |
| 431 | struct uvc_streaming_control ctrl; |
| 432 | struct uvc_format *cur_format; |
| 433 | struct uvc_frame *cur_frame; |
Laurent Pinchart | 6947756 | 2010-11-21 13:36:34 -0300 | [diff] [blame] | 434 | /* Protect access to ctrl, cur_format, cur_frame and hardware video |
| 435 | * probe control. |
| 436 | */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 437 | struct mutex mutex; |
| 438 | |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 439 | /* Buffers queue. */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 440 | unsigned int frozen : 1; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 441 | struct uvc_video_queue queue; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 442 | void (*decode) (struct urb *urb, struct uvc_streaming *video, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 443 | struct uvc_buffer *buf); |
| 444 | |
| 445 | /* Context data used by the bulk completion handler. */ |
| 446 | struct { |
| 447 | __u8 header[256]; |
| 448 | unsigned int header_size; |
| 449 | int skip_payload; |
| 450 | __u32 payload_size; |
| 451 | __u32 max_payload_size; |
| 452 | } bulk; |
| 453 | |
| 454 | struct urb *urb[UVC_URBS]; |
| 455 | char *urb_buffer[UVC_URBS]; |
Laurent Pinchart | e01117c | 2008-07-04 00:36:21 -0300 | [diff] [blame] | 456 | dma_addr_t urb_dma[UVC_URBS]; |
| 457 | unsigned int urb_size; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 458 | |
Laurent Pinchart | 650b95f | 2010-10-02 11:06:05 -0300 | [diff] [blame] | 459 | __u32 sequence; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 460 | __u8 last_fid; |
Alexey Fisher | edbaa39 | 2011-11-03 09:39:37 -0300 | [diff] [blame] | 461 | |
| 462 | /* debugfs */ |
| 463 | struct dentry *debugfs_dir; |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 464 | struct { |
| 465 | struct uvc_stats_frame frame; |
| 466 | struct uvc_stats_stream stream; |
| 467 | } stats; |
Laurent Pinchart | 66847ef | 2011-09-24 10:46:55 -0300 | [diff] [blame] | 468 | |
| 469 | /* Timestamps support. */ |
| 470 | struct uvc_clock { |
| 471 | struct uvc_clock_sample { |
| 472 | u32 dev_stc; |
| 473 | u16 dev_sof; |
| 474 | struct timespec host_ts; |
| 475 | u16 host_sof; |
| 476 | } *samples; |
| 477 | |
| 478 | unsigned int head; |
| 479 | unsigned int count; |
| 480 | unsigned int size; |
| 481 | |
| 482 | u16 last_sof; |
| 483 | u16 sof_offset; |
| 484 | |
| 485 | spinlock_t lock; |
| 486 | } clock; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | enum uvc_device_state { |
| 490 | UVC_DEV_DISCONNECTED = 1, |
| 491 | }; |
| 492 | |
| 493 | struct uvc_device { |
| 494 | struct usb_device *udev; |
| 495 | struct usb_interface *intf; |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 496 | unsigned long warnings; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 497 | __u32 quirks; |
| 498 | int intfnum; |
| 499 | char name[32]; |
| 500 | |
| 501 | enum uvc_device_state state; |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 502 | atomic_t users; |
Martin Rubli | 8fb91b3 | 2010-09-08 04:15:23 -0300 | [diff] [blame] | 503 | atomic_t nmappings; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 504 | |
| 505 | /* Video control interface */ |
Laurent Pinchart | 5a254d7 | 2010-01-21 05:39:47 -0300 | [diff] [blame] | 506 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 507 | struct media_device mdev; |
| 508 | #endif |
| 509 | struct v4l2_device vdev; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 510 | __u16 uvc_version; |
| 511 | __u32 clock_frequency; |
| 512 | |
| 513 | struct list_head entities; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 514 | struct list_head chains; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 515 | |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 516 | /* Video Streaming interfaces */ |
| 517 | struct list_head streams; |
Laurent Pinchart | 716fdee | 2009-09-29 21:07:19 -0300 | [diff] [blame] | 518 | atomic_t nstreams; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 519 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 520 | /* Status Interrupt Endpoint */ |
| 521 | struct usb_host_endpoint *int_ep; |
| 522 | struct urb *int_urb; |
Ming Lei | a31a405 | 2008-09-16 03:32:20 -0300 | [diff] [blame] | 523 | __u8 *status; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 524 | struct input_dev *input; |
Laurent Pinchart | f180152 | 2009-01-22 12:45:10 -0300 | [diff] [blame] | 525 | char input_phys[64]; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 526 | }; |
| 527 | |
| 528 | enum uvc_handle_state { |
| 529 | UVC_HANDLE_PASSIVE = 0, |
| 530 | UVC_HANDLE_ACTIVE = 1, |
| 531 | }; |
| 532 | |
| 533 | struct uvc_fh { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 534 | struct v4l2_fh vfh; |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 535 | struct uvc_video_chain *chain; |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 536 | struct uvc_streaming *stream; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 537 | enum uvc_handle_state state; |
| 538 | }; |
| 539 | |
| 540 | struct uvc_driver { |
| 541 | struct usb_driver driver; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 542 | }; |
| 543 | |
| 544 | /* ------------------------------------------------------------------------ |
| 545 | * Debugging, printing and logging |
| 546 | */ |
| 547 | |
| 548 | #define UVC_TRACE_PROBE (1 << 0) |
| 549 | #define UVC_TRACE_DESCR (1 << 1) |
| 550 | #define UVC_TRACE_CONTROL (1 << 2) |
| 551 | #define UVC_TRACE_FORMAT (1 << 3) |
| 552 | #define UVC_TRACE_CAPTURE (1 << 4) |
| 553 | #define UVC_TRACE_CALLS (1 << 5) |
| 554 | #define UVC_TRACE_IOCTL (1 << 6) |
| 555 | #define UVC_TRACE_FRAME (1 << 7) |
| 556 | #define UVC_TRACE_SUSPEND (1 << 8) |
| 557 | #define UVC_TRACE_STATUS (1 << 9) |
Laurent Pinchart | 663a419 | 2009-08-06 11:41:17 -0300 | [diff] [blame] | 558 | #define UVC_TRACE_VIDEO (1 << 10) |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 559 | #define UVC_TRACE_STATS (1 << 11) |
Laurent Pinchart | 66847ef | 2011-09-24 10:46:55 -0300 | [diff] [blame] | 560 | #define UVC_TRACE_CLOCK (1 << 12) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 561 | |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 562 | #define UVC_WARN_MINMAX 0 |
| 563 | #define UVC_WARN_PROBE_DEF 1 |
Laurent Pinchart | c4d99f8 | 2010-09-30 09:04:03 -0300 | [diff] [blame] | 564 | #define UVC_WARN_XU_GET_RES 2 |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 565 | |
Laurent Pinchart | 310fe52 | 2009-12-09 22:57:48 -0300 | [diff] [blame] | 566 | extern unsigned int uvc_clock_param; |
Laurent Pinchart | 0fbd8ee | 2008-12-06 16:25:14 -0300 | [diff] [blame] | 567 | extern unsigned int uvc_no_drop_param; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 568 | extern unsigned int uvc_trace_param; |
Laurent Pinchart | b232a01 | 2009-10-09 20:55:23 -0300 | [diff] [blame] | 569 | extern unsigned int uvc_timeout_param; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 570 | |
| 571 | #define uvc_trace(flag, msg...) \ |
| 572 | do { \ |
| 573 | if (uvc_trace_param & flag) \ |
| 574 | printk(KERN_DEBUG "uvcvideo: " msg); \ |
| 575 | } while (0) |
| 576 | |
Laurent Pinchart | 44f0079 | 2008-11-08 19:14:50 -0300 | [diff] [blame] | 577 | #define uvc_warn_once(dev, warn, msg...) \ |
| 578 | do { \ |
| 579 | if (!test_and_set_bit(warn, &dev->warnings)) \ |
| 580 | printk(KERN_INFO "uvcvideo: " msg); \ |
| 581 | } while (0) |
| 582 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 583 | #define uvc_printk(level, msg...) \ |
| 584 | printk(level "uvcvideo: " msg) |
| 585 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 586 | /* -------------------------------------------------------------------------- |
| 587 | * Internal functions. |
| 588 | */ |
| 589 | |
| 590 | /* Core driver */ |
| 591 | extern struct uvc_driver uvc_driver; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 592 | |
Laurent Pinchart | 4ffc2d8 | 2010-01-21 05:39:52 -0300 | [diff] [blame] | 593 | extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); |
| 594 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 595 | /* Video buffers queue management. */ |
Laurent Pinchart | ff92420 | 2008-12-28 22:32:29 -0300 | [diff] [blame] | 596 | extern void uvc_queue_init(struct uvc_video_queue *queue, |
Laurent Pinchart | 9bde9f2 | 2010-06-17 06:52:37 -0300 | [diff] [blame] | 597 | enum v4l2_buf_type type, int drop_corrupted); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 598 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 599 | struct v4l2_requestbuffers *rb); |
| 600 | extern void uvc_free_buffers(struct uvc_video_queue *queue); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 601 | extern int uvc_query_buffer(struct uvc_video_queue *queue, |
| 602 | struct v4l2_buffer *v4l2_buf); |
| 603 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, |
| 604 | struct v4l2_buffer *v4l2_buf); |
| 605 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, |
| 606 | struct v4l2_buffer *v4l2_buf, int nonblocking); |
| 607 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); |
| 608 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); |
| 609 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, |
| 610 | struct uvc_buffer *buf); |
Laurent Pinchart | 4aa2759 | 2010-11-21 15:18:08 -0300 | [diff] [blame] | 611 | extern int uvc_queue_mmap(struct uvc_video_queue *queue, |
| 612 | struct vm_area_struct *vma); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 613 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, |
| 614 | struct file *file, poll_table *wait); |
Bob Liu | 7296944 | 2011-04-29 07:11:35 -0300 | [diff] [blame] | 615 | #ifndef CONFIG_MMU |
| 616 | extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, |
| 617 | unsigned long pgoff); |
| 618 | #endif |
Laurent Pinchart | 23ff604 | 2009-06-04 09:26:39 -0300 | [diff] [blame] | 619 | extern int uvc_queue_allocated(struct uvc_video_queue *queue); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 620 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
| 621 | { |
Laurent Pinchart | 6998b6f | 2011-10-24 11:53:59 -0300 | [diff] [blame] | 622 | return vb2_is_streaming(&queue->queue); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* V4L2 interface */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 626 | extern const struct v4l2_file_operations uvc_fops; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 627 | |
Laurent Pinchart | 4ffc2d8 | 2010-01-21 05:39:52 -0300 | [diff] [blame] | 628 | /* Media controller */ |
| 629 | extern int uvc_mc_register_entities(struct uvc_video_chain *chain); |
| 630 | extern void uvc_mc_cleanup_entity(struct uvc_entity *entity); |
| 631 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 632 | /* Video */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 633 | extern int uvc_video_init(struct uvc_streaming *stream); |
| 634 | extern int uvc_video_suspend(struct uvc_streaming *stream); |
Ming Lei | d59a7b1 | 2011-07-16 00:51:00 -0300 | [diff] [blame] | 635 | extern int uvc_video_resume(struct uvc_streaming *stream, int reset); |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 636 | extern int uvc_video_enable(struct uvc_streaming *stream, int enable); |
| 637 | extern int uvc_probe_video(struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 638 | struct uvc_streaming_control *probe); |
| 639 | extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, |
| 640 | __u8 intfnum, __u8 cs, void *data, __u16 size); |
Laurent Pinchart | 66847ef | 2011-09-24 10:46:55 -0300 | [diff] [blame] | 641 | void uvc_video_clock_update(struct uvc_streaming *stream, |
| 642 | struct v4l2_buffer *v4l2_buf, |
| 643 | struct uvc_buffer *buf); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 644 | |
| 645 | /* Status */ |
| 646 | extern int uvc_status_init(struct uvc_device *dev); |
| 647 | extern void uvc_status_cleanup(struct uvc_device *dev); |
Laurent Pinchart | 04a37e0 | 2009-05-19 10:08:03 -0300 | [diff] [blame] | 648 | extern int uvc_status_start(struct uvc_device *dev); |
| 649 | extern void uvc_status_stop(struct uvc_device *dev); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 650 | extern int uvc_status_suspend(struct uvc_device *dev); |
| 651 | extern int uvc_status_resume(struct uvc_device *dev); |
| 652 | |
| 653 | /* Controls */ |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 654 | extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; |
| 655 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 656 | extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 657 | struct v4l2_queryctrl *v4l2_ctrl); |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 658 | extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain, |
| 659 | struct v4l2_querymenu *query_menu); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 660 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 661 | extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, |
| 662 | const struct uvc_control_mapping *mapping); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 663 | extern int uvc_ctrl_init_device(struct uvc_device *dev); |
| 664 | extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); |
| 665 | extern int uvc_ctrl_resume_device(struct uvc_device *dev); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 666 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 667 | extern int uvc_ctrl_begin(struct uvc_video_chain *chain); |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 668 | extern int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, |
| 669 | const struct v4l2_ext_control *xctrls, |
| 670 | unsigned int xctrls_count); |
| 671 | static inline int uvc_ctrl_commit(struct uvc_fh *handle, |
| 672 | const struct v4l2_ext_control *xctrls, |
| 673 | unsigned int xctrls_count) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 674 | { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 675 | return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 676 | } |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 677 | static inline int uvc_ctrl_rollback(struct uvc_fh *handle) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 678 | { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 679 | return __uvc_ctrl_commit(handle, 1, NULL, 0); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 680 | } |
| 681 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 682 | extern int uvc_ctrl_get(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 683 | struct v4l2_ext_control *xctrl); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 684 | extern int uvc_ctrl_set(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 685 | struct v4l2_ext_control *xctrl); |
| 686 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 687 | extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain, |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 688 | struct uvc_xu_control_query *xqry); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 689 | |
| 690 | /* Utility functions */ |
| 691 | extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, |
| 692 | unsigned int n_terms, unsigned int threshold); |
| 693 | extern uint32_t uvc_fraction_to_interval(uint32_t numerator, |
| 694 | uint32_t denominator); |
| 695 | extern struct usb_host_endpoint *uvc_find_endpoint( |
| 696 | struct usb_host_interface *alts, __u8 epaddr); |
| 697 | |
| 698 | /* Quirks support */ |
Laurent Pinchart | 35f02a6 | 2009-06-28 08:37:50 -0300 | [diff] [blame] | 699 | void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 700 | struct uvc_buffer *buf); |
| 701 | |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 702 | /* debugfs and statistics */ |
Alexey Fisher | edbaa39 | 2011-11-03 09:39:37 -0300 | [diff] [blame] | 703 | int uvc_debugfs_init(void); |
| 704 | void uvc_debugfs_cleanup(void); |
| 705 | int uvc_debugfs_init_stream(struct uvc_streaming *stream); |
| 706 | void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream); |
| 707 | |
Alexey Fisher | 7bc5edb | 2011-11-03 11:40:08 -0300 | [diff] [blame] | 708 | size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, |
| 709 | size_t size); |
| 710 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 711 | #endif |