uvcvideo.h 22 KB

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