uvcvideo.h 18 KB

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