uvcvideo.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
  275. /* Format flags */
  276. #define UVC_FMT_FLAG_COMPRESSED 0x00000001
  277. #define UVC_FMT_FLAG_STREAM 0x00000002
  278. /* ------------------------------------------------------------------------
  279. * Structures.
  280. */
  281. struct uvc_device;
  282. /* TODO: Put the most frequently accessed fields at the beginning of
  283. * structures to maximize cache efficiency.
  284. */
  285. struct uvc_streaming_control {
  286. __u16 bmHint;
  287. __u8 bFormatIndex;
  288. __u8 bFrameIndex;
  289. __u32 dwFrameInterval;
  290. __u16 wKeyFrameRate;
  291. __u16 wPFrameRate;
  292. __u16 wCompQuality;
  293. __u16 wCompWindowSize;
  294. __u16 wDelay;
  295. __u32 dwMaxVideoFrameSize;
  296. __u32 dwMaxPayloadTransferSize;
  297. __u32 dwClockFrequency;
  298. __u8 bmFramingInfo;
  299. __u8 bPreferedVersion;
  300. __u8 bMinVersion;
  301. __u8 bMaxVersion;
  302. };
  303. struct uvc_menu_info {
  304. __u32 value;
  305. __u8 name[32];
  306. };
  307. struct uvc_control_info {
  308. struct list_head list;
  309. struct list_head mappings;
  310. __u8 entity[16];
  311. __u8 index;
  312. __u8 selector;
  313. __u16 size;
  314. __u32 flags;
  315. };
  316. struct uvc_control_mapping {
  317. struct list_head list;
  318. struct uvc_control_info *ctrl;
  319. __u32 id;
  320. __u8 name[32];
  321. __u8 entity[16];
  322. __u8 selector;
  323. __u8 size;
  324. __u8 offset;
  325. enum v4l2_ctrl_type v4l2_type;
  326. __u32 data_type;
  327. struct uvc_menu_info *menu_info;
  328. __u32 menu_count;
  329. __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
  330. const __u8 *data);
  331. void (*set) (struct uvc_control_mapping *mapping, __s32 value,
  332. __u8 *data);
  333. };
  334. struct uvc_control {
  335. struct uvc_entity *entity;
  336. struct uvc_control_info *info;
  337. __u8 index; /* Used to match the uvc_control entry with a
  338. uvc_control_info. */
  339. __u8 dirty : 1,
  340. loaded : 1,
  341. modified : 1;
  342. __u8 *data;
  343. };
  344. struct uvc_format_desc {
  345. char *name;
  346. __u8 guid[16];
  347. __u32 fcc;
  348. };
  349. /* The term 'entity' refers to both UVC units and UVC terminals.
  350. *
  351. * The type field is either the terminal type (wTerminalType in the terminal
  352. * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
  353. * As the bDescriptorSubtype field is one byte long, the type value will
  354. * always have a null MSB for units. All terminal types defined by the UVC
  355. * specification have a non-null MSB, so it is safe to use the MSB to
  356. * differentiate between units and terminals as long as the descriptor parsing
  357. * code makes sure terminal types have a non-null MSB.
  358. *
  359. * For terminals, the type's most significant bit stores the terminal
  360. * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
  361. * always be accessed with the UVC_ENTITY_* macros and never directly.
  362. */
  363. struct uvc_entity {
  364. struct list_head list; /* Entity as part of a UVC device. */
  365. struct list_head chain; /* Entity as part of a video device
  366. * chain. */
  367. __u8 id;
  368. __u16 type;
  369. char name[64];
  370. union {
  371. struct {
  372. __u16 wObjectiveFocalLengthMin;
  373. __u16 wObjectiveFocalLengthMax;
  374. __u16 wOcularFocalLength;
  375. __u8 bControlSize;
  376. __u8 *bmControls;
  377. } camera;
  378. struct {
  379. __u8 bControlSize;
  380. __u8 *bmControls;
  381. __u8 bTransportModeSize;
  382. __u8 *bmTransportModes;
  383. } media;
  384. struct {
  385. __u8 bSourceID;
  386. } output;
  387. struct {
  388. __u8 bSourceID;
  389. __u16 wMaxMultiplier;
  390. __u8 bControlSize;
  391. __u8 *bmControls;
  392. __u8 bmVideoStandards;
  393. } processing;
  394. struct {
  395. __u8 bNrInPins;
  396. __u8 *baSourceID;
  397. } selector;
  398. struct {
  399. __u8 guidExtensionCode[16];
  400. __u8 bNumControls;
  401. __u8 bNrInPins;
  402. __u8 *baSourceID;
  403. __u8 bControlSize;
  404. __u8 *bmControls;
  405. __u8 *bmControlsType;
  406. } extension;
  407. };
  408. unsigned int ncontrols;
  409. struct uvc_control *controls;
  410. };
  411. struct uvc_frame {
  412. __u8 bFrameIndex;
  413. __u8 bmCapabilities;
  414. __u16 wWidth;
  415. __u16 wHeight;
  416. __u32 dwMinBitRate;
  417. __u32 dwMaxBitRate;
  418. __u32 dwMaxVideoFrameBufferSize;
  419. __u8 bFrameIntervalType;
  420. __u32 dwDefaultFrameInterval;
  421. __u32 *dwFrameInterval;
  422. };
  423. struct uvc_format {
  424. __u8 type;
  425. __u8 index;
  426. __u8 bpp;
  427. __u8 colorspace;
  428. __u32 fcc;
  429. __u32 flags;
  430. char name[32];
  431. unsigned int nframes;
  432. struct uvc_frame *frame;
  433. };
  434. struct uvc_streaming_header {
  435. __u8 bNumFormats;
  436. __u8 bEndpointAddress;
  437. __u8 bTerminalLink;
  438. __u8 bControlSize;
  439. __u8 *bmaControls;
  440. /* The following fields are used by input headers only. */
  441. __u8 bmInfo;
  442. __u8 bStillCaptureMethod;
  443. __u8 bTriggerSupport;
  444. __u8 bTriggerUsage;
  445. };
  446. struct uvc_streaming {
  447. struct list_head list;
  448. struct usb_interface *intf;
  449. int intfnum;
  450. __u16 maxpsize;
  451. struct uvc_streaming_header header;
  452. enum v4l2_buf_type type;
  453. unsigned int nformats;
  454. struct uvc_format *format;
  455. struct uvc_streaming_control ctrl;
  456. struct uvc_format *cur_format;
  457. struct uvc_frame *cur_frame;
  458. struct mutex mutex;
  459. };
  460. enum uvc_buffer_state {
  461. UVC_BUF_STATE_IDLE = 0,
  462. UVC_BUF_STATE_QUEUED = 1,
  463. UVC_BUF_STATE_ACTIVE = 2,
  464. UVC_BUF_STATE_DONE = 3,
  465. UVC_BUF_STATE_ERROR = 4,
  466. };
  467. struct uvc_buffer {
  468. unsigned long vma_use_count;
  469. struct list_head stream;
  470. /* Touched by interrupt handler. */
  471. struct v4l2_buffer buf;
  472. struct list_head queue;
  473. wait_queue_head_t wait;
  474. enum uvc_buffer_state state;
  475. };
  476. #define UVC_QUEUE_STREAMING (1 << 0)
  477. #define UVC_QUEUE_DISCONNECTED (1 << 1)
  478. #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
  479. struct uvc_video_queue {
  480. enum v4l2_buf_type type;
  481. void *mem;
  482. unsigned int flags;
  483. __u32 sequence;
  484. unsigned int count;
  485. unsigned int buf_size;
  486. unsigned int buf_used;
  487. struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
  488. struct mutex mutex; /* protects buffers and mainqueue */
  489. spinlock_t irqlock; /* protects irqqueue */
  490. struct list_head mainqueue;
  491. struct list_head irqqueue;
  492. };
  493. struct uvc_video_device {
  494. struct uvc_device *dev;
  495. struct video_device *vdev;
  496. atomic_t active;
  497. unsigned int frozen : 1;
  498. struct list_head iterms; /* Input terminals */
  499. struct uvc_entity *oterm; /* Output terminal */
  500. struct uvc_entity *sterm; /* USB streaming terminal */
  501. struct uvc_entity *processing;
  502. struct uvc_entity *selector;
  503. struct list_head extensions;
  504. struct mutex ctrl_mutex;
  505. struct uvc_video_queue queue;
  506. /* Video streaming object, must always be non-NULL. */
  507. struct uvc_streaming *streaming;
  508. void (*decode) (struct urb *urb, struct uvc_video_device *video,
  509. struct uvc_buffer *buf);
  510. /* Context data used by the bulk completion handler. */
  511. struct {
  512. __u8 header[256];
  513. unsigned int header_size;
  514. int skip_payload;
  515. __u32 payload_size;
  516. __u32 max_payload_size;
  517. } bulk;
  518. struct urb *urb[UVC_URBS];
  519. char *urb_buffer[UVC_URBS];
  520. dma_addr_t urb_dma[UVC_URBS];
  521. unsigned int urb_size;
  522. __u8 last_fid;
  523. };
  524. enum uvc_device_state {
  525. UVC_DEV_DISCONNECTED = 1,
  526. };
  527. struct uvc_device {
  528. struct usb_device *udev;
  529. struct usb_interface *intf;
  530. unsigned long warnings;
  531. __u32 quirks;
  532. int intfnum;
  533. char name[32];
  534. enum uvc_device_state state;
  535. struct kref kref;
  536. struct list_head list;
  537. /* Video control interface */
  538. __u16 uvc_version;
  539. __u32 clock_frequency;
  540. struct list_head entities;
  541. struct uvc_video_device video;
  542. /* Status Interrupt Endpoint */
  543. struct usb_host_endpoint *int_ep;
  544. struct urb *int_urb;
  545. __u8 *status;
  546. struct input_dev *input;
  547. char input_phys[64];
  548. /* Video Streaming interfaces */
  549. struct list_head streaming;
  550. };
  551. enum uvc_handle_state {
  552. UVC_HANDLE_PASSIVE = 0,
  553. UVC_HANDLE_ACTIVE = 1,
  554. };
  555. struct uvc_fh {
  556. struct uvc_video_device *device;
  557. enum uvc_handle_state state;
  558. };
  559. struct uvc_driver {
  560. struct usb_driver driver;
  561. struct mutex open_mutex; /* protects from open/disconnect race */
  562. struct list_head devices; /* struct uvc_device list */
  563. struct list_head controls; /* struct uvc_control_info list */
  564. struct mutex ctrl_mutex; /* protects controls and devices
  565. lists */
  566. };
  567. /* ------------------------------------------------------------------------
  568. * Debugging, printing and logging
  569. */
  570. #define UVC_TRACE_PROBE (1 << 0)
  571. #define UVC_TRACE_DESCR (1 << 1)
  572. #define UVC_TRACE_CONTROL (1 << 2)
  573. #define UVC_TRACE_FORMAT (1 << 3)
  574. #define UVC_TRACE_CAPTURE (1 << 4)
  575. #define UVC_TRACE_CALLS (1 << 5)
  576. #define UVC_TRACE_IOCTL (1 << 6)
  577. #define UVC_TRACE_FRAME (1 << 7)
  578. #define UVC_TRACE_SUSPEND (1 << 8)
  579. #define UVC_TRACE_STATUS (1 << 9)
  580. #define UVC_WARN_MINMAX 0
  581. #define UVC_WARN_PROBE_DEF 1
  582. extern unsigned int uvc_no_drop_param;
  583. extern unsigned int uvc_trace_param;
  584. #define uvc_trace(flag, msg...) \
  585. do { \
  586. if (uvc_trace_param & flag) \
  587. printk(KERN_DEBUG "uvcvideo: " msg); \
  588. } while (0)
  589. #define uvc_warn_once(dev, warn, msg...) \
  590. do { \
  591. if (!test_and_set_bit(warn, &dev->warnings)) \
  592. printk(KERN_INFO "uvcvideo: " msg); \
  593. } while (0)
  594. #define uvc_printk(level, msg...) \
  595. printk(level "uvcvideo: " msg)
  596. #define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
  597. "%02x%02x%02x%02x%02x%02x"
  598. #define UVC_GUID_ARGS(guid) \
  599. (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
  600. (guid)[5], (guid)[4], \
  601. (guid)[7], (guid)[6], \
  602. (guid)[8], (guid)[9], \
  603. (guid)[10], (guid)[11], (guid)[12], \
  604. (guid)[13], (guid)[14], (guid)[15]
  605. /* --------------------------------------------------------------------------
  606. * Internal functions.
  607. */
  608. /* Core driver */
  609. extern struct uvc_driver uvc_driver;
  610. extern void uvc_delete(struct kref *kref);
  611. /* Video buffers queue management. */
  612. extern void uvc_queue_init(struct uvc_video_queue *queue,
  613. enum v4l2_buf_type type);
  614. extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
  615. unsigned int nbuffers, unsigned int buflength);
  616. extern int uvc_free_buffers(struct uvc_video_queue *queue);
  617. extern int uvc_query_buffer(struct uvc_video_queue *queue,
  618. struct v4l2_buffer *v4l2_buf);
  619. extern int uvc_queue_buffer(struct uvc_video_queue *queue,
  620. struct v4l2_buffer *v4l2_buf);
  621. extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
  622. struct v4l2_buffer *v4l2_buf, int nonblocking);
  623. extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
  624. extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
  625. extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
  626. struct uvc_buffer *buf);
  627. extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
  628. struct file *file, poll_table *wait);
  629. static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
  630. {
  631. return queue->flags & UVC_QUEUE_STREAMING;
  632. }
  633. /* V4L2 interface */
  634. extern const struct v4l2_file_operations uvc_fops;
  635. /* Video */
  636. extern int uvc_video_init(struct uvc_video_device *video);
  637. extern int uvc_video_suspend(struct uvc_video_device *video);
  638. extern int uvc_video_resume(struct uvc_video_device *video);
  639. extern int uvc_video_enable(struct uvc_video_device *video, int enable);
  640. extern int uvc_probe_video(struct uvc_video_device *video,
  641. struct uvc_streaming_control *probe);
  642. extern int uvc_commit_video(struct uvc_video_device *video,
  643. struct uvc_streaming_control *ctrl);
  644. extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
  645. __u8 intfnum, __u8 cs, void *data, __u16 size);
  646. /* Status */
  647. extern int uvc_status_init(struct uvc_device *dev);
  648. extern void uvc_status_cleanup(struct uvc_device *dev);
  649. extern int uvc_status_suspend(struct uvc_device *dev);
  650. extern int uvc_status_resume(struct uvc_device *dev);
  651. /* Controls */
  652. extern struct uvc_control *uvc_find_control(struct uvc_video_device *video,
  653. __u32 v4l2_id, struct uvc_control_mapping **mapping);
  654. extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
  655. struct v4l2_queryctrl *v4l2_ctrl);
  656. extern int uvc_ctrl_add_info(struct uvc_control_info *info);
  657. extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
  658. extern int uvc_ctrl_init_device(struct uvc_device *dev);
  659. extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
  660. extern int uvc_ctrl_resume_device(struct uvc_device *dev);
  661. extern void uvc_ctrl_init(void);
  662. extern int uvc_ctrl_begin(struct uvc_video_device *video);
  663. extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback);
  664. static inline int uvc_ctrl_commit(struct uvc_video_device *video)
  665. {
  666. return __uvc_ctrl_commit(video, 0);
  667. }
  668. static inline int uvc_ctrl_rollback(struct uvc_video_device *video)
  669. {
  670. return __uvc_ctrl_commit(video, 1);
  671. }
  672. extern int uvc_ctrl_get(struct uvc_video_device *video,
  673. struct v4l2_ext_control *xctrl);
  674. extern int uvc_ctrl_set(struct uvc_video_device *video,
  675. struct v4l2_ext_control *xctrl);
  676. extern int uvc_xu_ctrl_query(struct uvc_video_device *video,
  677. struct uvc_xu_control *ctrl, int set);
  678. /* Utility functions */
  679. extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
  680. unsigned int n_terms, unsigned int threshold);
  681. extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
  682. uint32_t denominator);
  683. extern struct usb_host_endpoint *uvc_find_endpoint(
  684. struct usb_host_interface *alts, __u8 epaddr);
  685. /* Quirks support */
  686. void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
  687. struct uvc_buffer *buf);
  688. #endif /* __KERNEL__ */
  689. #endif