uvcvideo.h 22 KB

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