uvcvideo.h 20 KB

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