uvcvideo.h 20 KB

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