uvcvideo.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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 UVC_SC_UNDEFINED 0x00
  62. #define UVC_SC_VIDEOCONTROL 0x01
  63. #define UVC_SC_VIDEOSTREAMING 0x02
  64. #define UVC_SC_VIDEO_INTERFACE_COLLECTION 0x03
  65. #define UVC_PC_PROTOCOL_UNDEFINED 0x00
  66. /* VideoControl class specific interface descriptor */
  67. #define UVC_VC_DESCRIPTOR_UNDEFINED 0x00
  68. #define UVC_VC_HEADER 0x01
  69. #define UVC_VC_INPUT_TERMINAL 0x02
  70. #define UVC_VC_OUTPUT_TERMINAL 0x03
  71. #define UVC_VC_SELECTOR_UNIT 0x04
  72. #define UVC_VC_PROCESSING_UNIT 0x05
  73. #define UVC_VC_EXTENSION_UNIT 0x06
  74. /* VideoStreaming class specific interface descriptor */
  75. #define UVC_VS_UNDEFINED 0x00
  76. #define UVC_VS_INPUT_HEADER 0x01
  77. #define UVC_VS_OUTPUT_HEADER 0x02
  78. #define UVC_VS_STILL_IMAGE_FRAME 0x03
  79. #define UVC_VS_FORMAT_UNCOMPRESSED 0x04
  80. #define UVC_VS_FRAME_UNCOMPRESSED 0x05
  81. #define UVC_VS_FORMAT_MJPEG 0x06
  82. #define UVC_VS_FRAME_MJPEG 0x07
  83. #define UVC_VS_FORMAT_MPEG2TS 0x0a
  84. #define UVC_VS_FORMAT_DV 0x0c
  85. #define UVC_VS_COLORFORMAT 0x0d
  86. #define UVC_VS_FORMAT_FRAME_BASED 0x10
  87. #define UVC_VS_FRAME_FRAME_BASED 0x11
  88. #define UVC_VS_FORMAT_STREAM_BASED 0x12
  89. /* Endpoint type */
  90. #define UVC_EP_UNDEFINED 0x00
  91. #define UVC_EP_GENERAL 0x01
  92. #define UVC_EP_ENDPOINT 0x02
  93. #define UVC_EP_INTERRUPT 0x03
  94. /* Request codes */
  95. #define UVC_RC_UNDEFINED 0x00
  96. #define UVC_SET_CUR 0x01
  97. #define UVC_GET_CUR 0x81
  98. #define UVC_GET_MIN 0x82
  99. #define UVC_GET_MAX 0x83
  100. #define UVC_GET_RES 0x84
  101. #define UVC_GET_LEN 0x85
  102. #define UVC_GET_INFO 0x86
  103. #define UVC_GET_DEF 0x87
  104. /* VideoControl interface controls */
  105. #define UVC_VC_CONTROL_UNDEFINED 0x00
  106. #define UVC_VC_VIDEO_POWER_MODE_CONTROL 0x01
  107. #define UVC_VC_REQUEST_ERROR_CODE_CONTROL 0x02
  108. /* Terminal controls */
  109. #define UVC_TE_CONTROL_UNDEFINED 0x00
  110. /* Selector Unit controls */
  111. #define UVC_SU_CONTROL_UNDEFINED 0x00
  112. #define UVC_SU_INPUT_SELECT_CONTROL 0x01
  113. /* Camera Terminal controls */
  114. #define UVC_CT_CONTROL_UNDEFINED 0x00
  115. #define UVC_CT_SCANNING_MODE_CONTROL 0x01
  116. #define UVC_CT_AE_MODE_CONTROL 0x02
  117. #define UVC_CT_AE_PRIORITY_CONTROL 0x03
  118. #define UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04
  119. #define UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05
  120. #define UVC_CT_FOCUS_ABSOLUTE_CONTROL 0x06
  121. #define UVC_CT_FOCUS_RELATIVE_CONTROL 0x07
  122. #define UVC_CT_FOCUS_AUTO_CONTROL 0x08
  123. #define UVC_CT_IRIS_ABSOLUTE_CONTROL 0x09
  124. #define UVC_CT_IRIS_RELATIVE_CONTROL 0x0a
  125. #define UVC_CT_ZOOM_ABSOLUTE_CONTROL 0x0b
  126. #define UVC_CT_ZOOM_RELATIVE_CONTROL 0x0c
  127. #define UVC_CT_PANTILT_ABSOLUTE_CONTROL 0x0d
  128. #define UVC_CT_PANTILT_RELATIVE_CONTROL 0x0e
  129. #define UVC_CT_ROLL_ABSOLUTE_CONTROL 0x0f
  130. #define UVC_CT_ROLL_RELATIVE_CONTROL 0x10
  131. #define UVC_CT_PRIVACY_CONTROL 0x11
  132. /* Processing Unit controls */
  133. #define UVC_PU_CONTROL_UNDEFINED 0x00
  134. #define UVC_PU_BACKLIGHT_COMPENSATION_CONTROL 0x01
  135. #define UVC_PU_BRIGHTNESS_CONTROL 0x02
  136. #define UVC_PU_CONTRAST_CONTROL 0x03
  137. #define UVC_PU_GAIN_CONTROL 0x04
  138. #define UVC_PU_POWER_LINE_FREQUENCY_CONTROL 0x05
  139. #define UVC_PU_HUE_CONTROL 0x06
  140. #define UVC_PU_SATURATION_CONTROL 0x07
  141. #define UVC_PU_SHARPNESS_CONTROL 0x08
  142. #define UVC_PU_GAMMA_CONTROL 0x09
  143. #define UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a
  144. #define UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b
  145. #define UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c
  146. #define UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d
  147. #define UVC_PU_DIGITAL_MULTIPLIER_CONTROL 0x0e
  148. #define UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f
  149. #define UVC_PU_HUE_AUTO_CONTROL 0x10
  150. #define UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11
  151. #define UVC_PU_ANALOG_LOCK_STATUS_CONTROL 0x12
  152. /* VideoStreaming interface controls */
  153. #define UVC_VS_CONTROL_UNDEFINED 0x00
  154. #define UVC_VS_PROBE_CONTROL 0x01
  155. #define UVC_VS_COMMIT_CONTROL 0x02
  156. #define UVC_VS_STILL_PROBE_CONTROL 0x03
  157. #define UVC_VS_STILL_COMMIT_CONTROL 0x04
  158. #define UVC_VS_STILL_IMAGE_TRIGGER_CONTROL 0x05
  159. #define UVC_VS_STREAM_ERROR_CODE_CONTROL 0x06
  160. #define UVC_VS_GENERATE_KEY_FRAME_CONTROL 0x07
  161. #define UVC_VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08
  162. #define UVC_VS_SYNC_DELAY_CONTROL 0x09
  163. #define UVC_TT_VENDOR_SPECIFIC 0x0100
  164. #define UVC_TT_STREAMING 0x0101
  165. /* Input Terminal types */
  166. #define UVC_ITT_VENDOR_SPECIFIC 0x0200
  167. #define UVC_ITT_CAMERA 0x0201
  168. #define UVC_ITT_MEDIA_TRANSPORT_INPUT 0x0202
  169. /* Output Terminal types */
  170. #define UVC_OTT_VENDOR_SPECIFIC 0x0300
  171. #define UVC_OTT_DISPLAY 0x0301
  172. #define UVC_OTT_MEDIA_TRANSPORT_OUTPUT 0x0302
  173. /* External Terminal types */
  174. #define UVC_EXTERNAL_VENDOR_SPECIFIC 0x0400
  175. #define UVC_COMPOSITE_CONNECTOR 0x0401
  176. #define UVC_SVIDEO_CONNECTOR 0x0402
  177. #define UVC_COMPONENT_CONNECTOR 0x0403
  178. #define UVC_TERM_INPUT 0x0000
  179. #define UVC_TERM_OUTPUT 0x8000
  180. #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
  181. #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
  182. #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
  183. #define UVC_ENTITY_IS_ITERM(entity) \
  184. (((entity)->type & 0x8000) == UVC_TERM_INPUT)
  185. #define UVC_ENTITY_IS_OTERM(entity) \
  186. (((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
  187. #define UVC_STATUS_TYPE_CONTROL 1
  188. #define UVC_STATUS_TYPE_STREAMING 2
  189. /* ------------------------------------------------------------------------
  190. * GUIDs
  191. */
  192. #define UVC_GUID_UVC_CAMERA \
  193. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  194. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
  195. #define UVC_GUID_UVC_OUTPUT \
  196. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  197. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
  198. #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
  199. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  200. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  201. #define UVC_GUID_UVC_PROCESSING \
  202. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  203. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
  204. #define UVC_GUID_UVC_SELECTOR \
  205. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  206. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
  207. #define UVC_GUID_FORMAT_MJPEG \
  208. { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
  209. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  210. #define UVC_GUID_FORMAT_YUY2 \
  211. { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
  212. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  213. #define UVC_GUID_FORMAT_NV12 \
  214. { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
  215. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  216. #define UVC_GUID_FORMAT_YV12 \
  217. { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
  218. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  219. #define UVC_GUID_FORMAT_I420 \
  220. { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
  221. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  222. #define UVC_GUID_FORMAT_UYVY \
  223. { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
  224. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  225. #define UVC_GUID_FORMAT_Y800 \
  226. { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
  227. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  228. #define UVC_GUID_FORMAT_BY8 \
  229. { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
  230. 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
  231. /* ------------------------------------------------------------------------
  232. * Driver specific constants.
  233. */
  234. #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
  235. /* Number of isochronous URBs. */
  236. #define UVC_URBS 5
  237. /* Maximum number of packets per URB. */
  238. #define UVC_MAX_PACKETS 32
  239. /* Maximum number of video buffers. */
  240. #define UVC_MAX_VIDEO_BUFFERS 32
  241. /* Maximum status buffer size in bytes of interrupt URB. */
  242. #define UVC_MAX_STATUS_SIZE 16
  243. #define UVC_CTRL_CONTROL_TIMEOUT 300
  244. #define UVC_CTRL_STREAMING_TIMEOUT 1000
  245. /* Devices quirks */
  246. #define UVC_QUIRK_STATUS_INTERVAL 0x00000001
  247. #define UVC_QUIRK_PROBE_MINMAX 0x00000002
  248. #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
  249. #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
  250. #define UVC_QUIRK_STREAM_NO_FID 0x00000010
  251. #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
  252. #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
  253. /* Format flags */
  254. #define UVC_FMT_FLAG_COMPRESSED 0x00000001
  255. #define UVC_FMT_FLAG_STREAM 0x00000002
  256. /* ------------------------------------------------------------------------
  257. * Structures.
  258. */
  259. struct uvc_device;
  260. /* TODO: Put the most frequently accessed fields at the beginning of
  261. * structures to maximize cache efficiency.
  262. */
  263. struct uvc_streaming_control {
  264. __u16 bmHint;
  265. __u8 bFormatIndex;
  266. __u8 bFrameIndex;
  267. __u32 dwFrameInterval;
  268. __u16 wKeyFrameRate;
  269. __u16 wPFrameRate;
  270. __u16 wCompQuality;
  271. __u16 wCompWindowSize;
  272. __u16 wDelay;
  273. __u32 dwMaxVideoFrameSize;
  274. __u32 dwMaxPayloadTransferSize;
  275. __u32 dwClockFrequency;
  276. __u8 bmFramingInfo;
  277. __u8 bPreferedVersion;
  278. __u8 bMinVersion;
  279. __u8 bMaxVersion;
  280. };
  281. struct uvc_menu_info {
  282. __u32 value;
  283. __u8 name[32];
  284. };
  285. struct uvc_control_info {
  286. struct list_head list;
  287. struct list_head mappings;
  288. __u8 entity[16];
  289. __u8 index;
  290. __u8 selector;
  291. __u16 size;
  292. __u32 flags;
  293. };
  294. struct uvc_control_mapping {
  295. struct list_head list;
  296. struct uvc_control_info *ctrl;
  297. __u32 id;
  298. __u8 name[32];
  299. __u8 entity[16];
  300. __u8 selector;
  301. __u8 size;
  302. __u8 offset;
  303. enum v4l2_ctrl_type v4l2_type;
  304. __u32 data_type;
  305. struct uvc_menu_info *menu_info;
  306. __u32 menu_count;
  307. __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
  308. const __u8 *data);
  309. void (*set) (struct uvc_control_mapping *mapping, __s32 value,
  310. __u8 *data);
  311. };
  312. struct uvc_control {
  313. struct uvc_entity *entity;
  314. struct uvc_control_info *info;
  315. __u8 index; /* Used to match the uvc_control entry with a
  316. uvc_control_info. */
  317. __u8 dirty : 1,
  318. loaded : 1,
  319. modified : 1;
  320. __u8 *data;
  321. };
  322. struct uvc_format_desc {
  323. char *name;
  324. __u8 guid[16];
  325. __u32 fcc;
  326. };
  327. /* The term 'entity' refers to both UVC units and UVC terminals.
  328. *
  329. * The type field is either the terminal type (wTerminalType in the terminal
  330. * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
  331. * As the bDescriptorSubtype field is one byte long, the type value will
  332. * always have a null MSB for units. All terminal types defined by the UVC
  333. * specification have a non-null MSB, so it is safe to use the MSB to
  334. * differentiate between units and terminals as long as the descriptor parsing
  335. * code makes sure terminal types have a non-null MSB.
  336. *
  337. * For terminals, the type's most significant bit stores the terminal
  338. * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
  339. * always be accessed with the UVC_ENTITY_* macros and never directly.
  340. */
  341. struct uvc_entity {
  342. struct list_head list; /* Entity as part of a UVC device. */
  343. struct list_head chain; /* Entity as part of a video device
  344. * chain. */
  345. __u8 id;
  346. __u16 type;
  347. char name[64];
  348. union {
  349. struct {
  350. __u16 wObjectiveFocalLengthMin;
  351. __u16 wObjectiveFocalLengthMax;
  352. __u16 wOcularFocalLength;
  353. __u8 bControlSize;
  354. __u8 *bmControls;
  355. } camera;
  356. struct {
  357. __u8 bControlSize;
  358. __u8 *bmControls;
  359. __u8 bTransportModeSize;
  360. __u8 *bmTransportModes;
  361. } media;
  362. struct {
  363. __u8 bSourceID;
  364. } output;
  365. struct {
  366. __u8 bSourceID;
  367. __u16 wMaxMultiplier;
  368. __u8 bControlSize;
  369. __u8 *bmControls;
  370. __u8 bmVideoStandards;
  371. } processing;
  372. struct {
  373. __u8 bNrInPins;
  374. __u8 *baSourceID;
  375. } selector;
  376. struct {
  377. __u8 guidExtensionCode[16];
  378. __u8 bNumControls;
  379. __u8 bNrInPins;
  380. __u8 *baSourceID;
  381. __u8 bControlSize;
  382. __u8 *bmControls;
  383. __u8 *bmControlsType;
  384. } extension;
  385. };
  386. unsigned int ncontrols;
  387. struct uvc_control *controls;
  388. };
  389. struct uvc_frame {
  390. __u8 bFrameIndex;
  391. __u8 bmCapabilities;
  392. __u16 wWidth;
  393. __u16 wHeight;
  394. __u32 dwMinBitRate;
  395. __u32 dwMaxBitRate;
  396. __u32 dwMaxVideoFrameBufferSize;
  397. __u8 bFrameIntervalType;
  398. __u32 dwDefaultFrameInterval;
  399. __u32 *dwFrameInterval;
  400. };
  401. struct uvc_format {
  402. __u8 type;
  403. __u8 index;
  404. __u8 bpp;
  405. __u8 colorspace;
  406. __u32 fcc;
  407. __u32 flags;
  408. char name[32];
  409. unsigned int nframes;
  410. struct uvc_frame *frame;
  411. };
  412. struct uvc_streaming_header {
  413. __u8 bNumFormats;
  414. __u8 bEndpointAddress;
  415. __u8 bTerminalLink;
  416. __u8 bControlSize;
  417. __u8 *bmaControls;
  418. /* The following fields are used by input headers only. */
  419. __u8 bmInfo;
  420. __u8 bStillCaptureMethod;
  421. __u8 bTriggerSupport;
  422. __u8 bTriggerUsage;
  423. };
  424. struct uvc_streaming {
  425. struct list_head list;
  426. struct usb_interface *intf;
  427. int intfnum;
  428. __u16 maxpsize;
  429. struct uvc_streaming_header header;
  430. enum v4l2_buf_type type;
  431. unsigned int nformats;
  432. struct uvc_format *format;
  433. struct uvc_streaming_control ctrl;
  434. struct uvc_format *cur_format;
  435. struct uvc_frame *cur_frame;
  436. struct mutex mutex;
  437. };
  438. enum uvc_buffer_state {
  439. UVC_BUF_STATE_IDLE = 0,
  440. UVC_BUF_STATE_QUEUED = 1,
  441. UVC_BUF_STATE_ACTIVE = 2,
  442. UVC_BUF_STATE_DONE = 3,
  443. UVC_BUF_STATE_ERROR = 4,
  444. };
  445. struct uvc_buffer {
  446. unsigned long vma_use_count;
  447. struct list_head stream;
  448. /* Touched by interrupt handler. */
  449. struct v4l2_buffer buf;
  450. struct list_head queue;
  451. wait_queue_head_t wait;
  452. enum uvc_buffer_state state;
  453. };
  454. #define UVC_QUEUE_STREAMING (1 << 0)
  455. #define UVC_QUEUE_DISCONNECTED (1 << 1)
  456. #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
  457. struct uvc_video_queue {
  458. enum v4l2_buf_type type;
  459. void *mem;
  460. unsigned int flags;
  461. __u32 sequence;
  462. unsigned int count;
  463. unsigned int buf_size;
  464. unsigned int buf_used;
  465. struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
  466. struct mutex mutex; /* protects buffers and mainqueue */
  467. spinlock_t irqlock; /* protects irqqueue */
  468. struct list_head mainqueue;
  469. struct list_head irqqueue;
  470. };
  471. struct uvc_video_device {
  472. struct uvc_device *dev;
  473. struct video_device *vdev;
  474. atomic_t active;
  475. unsigned int frozen : 1;
  476. struct list_head iterms; /* Input terminals */
  477. struct uvc_entity *oterm; /* Output terminal */
  478. struct uvc_entity *sterm; /* USB streaming terminal */
  479. struct uvc_entity *processing;
  480. struct uvc_entity *selector;
  481. struct list_head extensions;
  482. struct mutex ctrl_mutex;
  483. struct uvc_video_queue queue;
  484. /* Video streaming object, must always be non-NULL. */
  485. struct uvc_streaming *streaming;
  486. void (*decode) (struct urb *urb, struct uvc_video_device *video,
  487. struct uvc_buffer *buf);
  488. /* Context data used by the bulk completion handler. */
  489. struct {
  490. __u8 header[256];
  491. unsigned int header_size;
  492. int skip_payload;
  493. __u32 payload_size;
  494. __u32 max_payload_size;
  495. } bulk;
  496. struct urb *urb[UVC_URBS];
  497. char *urb_buffer[UVC_URBS];
  498. dma_addr_t urb_dma[UVC_URBS];
  499. unsigned int urb_size;
  500. __u8 last_fid;
  501. };
  502. enum uvc_device_state {
  503. UVC_DEV_DISCONNECTED = 1,
  504. };
  505. struct uvc_device {
  506. struct usb_device *udev;
  507. struct usb_interface *intf;
  508. unsigned long warnings;
  509. __u32 quirks;
  510. int intfnum;
  511. char name[32];
  512. enum uvc_device_state state;
  513. struct kref kref;
  514. struct list_head list;
  515. atomic_t users;
  516. /* Video control interface */
  517. __u16 uvc_version;
  518. __u32 clock_frequency;
  519. struct list_head entities;
  520. struct uvc_video_device video;
  521. /* Status Interrupt Endpoint */
  522. struct usb_host_endpoint *int_ep;
  523. struct urb *int_urb;
  524. __u8 *status;
  525. struct input_dev *input;
  526. char input_phys[64];
  527. /* Video Streaming interfaces */
  528. struct list_head streaming;
  529. };
  530. enum uvc_handle_state {
  531. UVC_HANDLE_PASSIVE = 0,
  532. UVC_HANDLE_ACTIVE = 1,
  533. };
  534. struct uvc_fh {
  535. struct uvc_video_device *device;
  536. enum uvc_handle_state state;
  537. };
  538. struct uvc_driver {
  539. struct usb_driver driver;
  540. struct mutex open_mutex; /* protects from open/disconnect race */
  541. struct list_head devices; /* struct uvc_device list */
  542. struct list_head controls; /* struct uvc_control_info list */
  543. struct mutex ctrl_mutex; /* protects controls and devices
  544. lists */
  545. };
  546. /* ------------------------------------------------------------------------
  547. * Debugging, printing and logging
  548. */
  549. #define UVC_TRACE_PROBE (1 << 0)
  550. #define UVC_TRACE_DESCR (1 << 1)
  551. #define UVC_TRACE_CONTROL (1 << 2)
  552. #define UVC_TRACE_FORMAT (1 << 3)
  553. #define UVC_TRACE_CAPTURE (1 << 4)
  554. #define UVC_TRACE_CALLS (1 << 5)
  555. #define UVC_TRACE_IOCTL (1 << 6)
  556. #define UVC_TRACE_FRAME (1 << 7)
  557. #define UVC_TRACE_SUSPEND (1 << 8)
  558. #define UVC_TRACE_STATUS (1 << 9)
  559. #define UVC_WARN_MINMAX 0
  560. #define UVC_WARN_PROBE_DEF 1
  561. extern unsigned int uvc_no_drop_param;
  562. extern unsigned int uvc_trace_param;
  563. #define uvc_trace(flag, msg...) \
  564. do { \
  565. if (uvc_trace_param & flag) \
  566. printk(KERN_DEBUG "uvcvideo: " msg); \
  567. } while (0)
  568. #define uvc_warn_once(dev, warn, msg...) \
  569. do { \
  570. if (!test_and_set_bit(warn, &dev->warnings)) \
  571. printk(KERN_INFO "uvcvideo: " msg); \
  572. } while (0)
  573. #define uvc_printk(level, msg...) \
  574. printk(level "uvcvideo: " msg)
  575. #define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
  576. "%02x%02x%02x%02x%02x%02x"
  577. #define UVC_GUID_ARGS(guid) \
  578. (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
  579. (guid)[5], (guid)[4], \
  580. (guid)[7], (guid)[6], \
  581. (guid)[8], (guid)[9], \
  582. (guid)[10], (guid)[11], (guid)[12], \
  583. (guid)[13], (guid)[14], (guid)[15]
  584. /* --------------------------------------------------------------------------
  585. * Internal functions.
  586. */
  587. /* Core driver */
  588. extern struct uvc_driver uvc_driver;
  589. extern void uvc_delete(struct kref *kref);
  590. /* Video buffers queue management. */
  591. extern void uvc_queue_init(struct uvc_video_queue *queue,
  592. enum v4l2_buf_type type);
  593. extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
  594. unsigned int nbuffers, unsigned int buflength);
  595. extern int uvc_free_buffers(struct uvc_video_queue *queue);
  596. extern int uvc_query_buffer(struct uvc_video_queue *queue,
  597. struct v4l2_buffer *v4l2_buf);
  598. extern int uvc_queue_buffer(struct uvc_video_queue *queue,
  599. struct v4l2_buffer *v4l2_buf);
  600. extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
  601. struct v4l2_buffer *v4l2_buf, int nonblocking);
  602. extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
  603. extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
  604. extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
  605. struct uvc_buffer *buf);
  606. extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
  607. struct file *file, poll_table *wait);
  608. extern int uvc_queue_allocated(struct uvc_video_queue *queue);
  609. static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
  610. {
  611. return queue->flags & UVC_QUEUE_STREAMING;
  612. }
  613. /* V4L2 interface */
  614. extern const struct v4l2_file_operations uvc_fops;
  615. /* Video */
  616. extern int uvc_video_init(struct uvc_video_device *video);
  617. extern int uvc_video_suspend(struct uvc_video_device *video);
  618. extern int uvc_video_resume(struct uvc_video_device *video);
  619. extern int uvc_video_enable(struct uvc_video_device *video, int enable);
  620. extern int uvc_probe_video(struct uvc_video_device *video,
  621. struct uvc_streaming_control *probe);
  622. extern int uvc_commit_video(struct uvc_video_device *video,
  623. struct uvc_streaming_control *ctrl);
  624. extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
  625. __u8 intfnum, __u8 cs, void *data, __u16 size);
  626. /* Status */
  627. extern int uvc_status_init(struct uvc_device *dev);
  628. extern void uvc_status_cleanup(struct uvc_device *dev);
  629. extern int uvc_status_start(struct uvc_device *dev);
  630. extern void uvc_status_stop(struct uvc_device *dev);
  631. extern int uvc_status_suspend(struct uvc_device *dev);
  632. extern int uvc_status_resume(struct uvc_device *dev);
  633. /* Controls */
  634. extern struct uvc_control *uvc_find_control(struct uvc_video_device *video,
  635. __u32 v4l2_id, struct uvc_control_mapping **mapping);
  636. extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
  637. struct v4l2_queryctrl *v4l2_ctrl);
  638. extern int uvc_ctrl_add_info(struct uvc_control_info *info);
  639. extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
  640. extern int uvc_ctrl_init_device(struct uvc_device *dev);
  641. extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
  642. extern int uvc_ctrl_resume_device(struct uvc_device *dev);
  643. extern void uvc_ctrl_init(void);
  644. extern int uvc_ctrl_begin(struct uvc_video_device *video);
  645. extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback);
  646. static inline int uvc_ctrl_commit(struct uvc_video_device *video)
  647. {
  648. return __uvc_ctrl_commit(video, 0);
  649. }
  650. static inline int uvc_ctrl_rollback(struct uvc_video_device *video)
  651. {
  652. return __uvc_ctrl_commit(video, 1);
  653. }
  654. extern int uvc_ctrl_get(struct uvc_video_device *video,
  655. struct v4l2_ext_control *xctrl);
  656. extern int uvc_ctrl_set(struct uvc_video_device *video,
  657. struct v4l2_ext_control *xctrl);
  658. extern int uvc_xu_ctrl_query(struct uvc_video_device *video,
  659. struct uvc_xu_control *ctrl, int set);
  660. /* Utility functions */
  661. extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
  662. unsigned int n_terms, unsigned int threshold);
  663. extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
  664. uint32_t denominator);
  665. extern struct usb_host_endpoint *uvc_find_endpoint(
  666. struct usb_host_interface *alts, __u8 epaddr);
  667. /* Quirks support */
  668. void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
  669. struct uvc_buffer *buf);
  670. #endif /* __KERNEL__ */
  671. #endif