uvcvideo.h 20 KB

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