uvcvideo.h 19 KB

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