uvcvideo.h 17 KB

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