uvcvideo.h 18.9 KB
Newer Older
1 2 3 4 5 6
#ifndef _USB_VIDEO_H_
#define _USB_VIDEO_H_

#include <linux/kernel.h>
#include <linux/videodev2.h>

7 8 9 10 11 12 13 14
#ifndef __KERNEL__
/*
 * This header provides binary compatibility with applications using the private
 * uvcvideo API. This API is deprecated and will be removed in 2.6.42.
 * Applications should be recompiled against the public linux/uvcvideo.h header.
 */
#warn "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*
 * Dynamic controls
 */

/* Data types for UVC control data */
#define UVC_CTRL_DATA_TYPE_RAW		0
#define UVC_CTRL_DATA_TYPE_SIGNED	1
#define UVC_CTRL_DATA_TYPE_UNSIGNED	2
#define UVC_CTRL_DATA_TYPE_BOOLEAN	3
#define UVC_CTRL_DATA_TYPE_ENUM		4
#define UVC_CTRL_DATA_TYPE_BITMASK	5

/* Control flags */
#define UVC_CONTROL_SET_CUR	(1 << 0)
#define UVC_CONTROL_GET_CUR	(1 << 1)
#define UVC_CONTROL_GET_MIN	(1 << 2)
#define UVC_CONTROL_GET_MAX	(1 << 3)
#define UVC_CONTROL_GET_RES	(1 << 4)
#define UVC_CONTROL_GET_DEF	(1 << 5)
#define UVC_CONTROL_RESTORE	(1 << 6)
#define UVC_CONTROL_AUTO_UPDATE	(1 << 7)

#define UVC_CONTROL_GET_RANGE	(UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \
				 UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \
				 UVC_CONTROL_GET_DEF)

41 42 43 44 45
struct uvc_menu_info {
	__u32 value;
	__u8 name[32];
};

46 47 48 49 50 51 52 53
struct uvc_xu_control_mapping {
	__u32 id;
	__u8 name[32];
	__u8 entity[16];
	__u8 selector;

	__u8 size;
	__u8 offset;
54
	__u32 v4l2_type;
55
	__u32 data_type;
56 57 58 59 60

	struct uvc_menu_info __user *menu_info;
	__u32 menu_count;

	__u32 reserved[4];
61 62
};

63 64 65 66 67
#endif

struct uvc_xu_control_info {
	__u8 entity[16];
	__u8 index;
68 69
	__u8 selector;
	__u16 size;
70
	__u32 flags;
71 72
};

73 74 75 76 77
struct uvc_xu_control_mapping_old {
	__u8 reserved[64];
};

struct uvc_xu_control {
78 79 80 81 82 83
	__u8 unit;
	__u8 selector;
	__u16 size;
	__u8 __user *data;
};

84
#ifndef __KERNEL__
85
#define UVCIOC_CTRL_ADD		_IOW('U', 1, struct uvc_xu_control_info)
86
#define UVCIOC_CTRL_MAP_OLD	_IOWR('U', 2, struct uvc_xu_control_mapping_old)
87 88 89
#define UVCIOC_CTRL_MAP		_IOWR('U', 2, struct uvc_xu_control_mapping)
#define UVCIOC_CTRL_GET		_IOWR('U', 3, struct uvc_xu_control)
#define UVCIOC_CTRL_SET		_IOW('U', 4, struct uvc_xu_control)
90 91 92 93 94 95 96
#else
#define __UVCIOC_CTRL_ADD	_IOW('U', 1, struct uvc_xu_control_info)
#define __UVCIOC_CTRL_MAP_OLD	_IOWR('U', 2, struct uvc_xu_control_mapping_old)
#define __UVCIOC_CTRL_MAP	_IOWR('U', 2, struct uvc_xu_control_mapping)
#define __UVCIOC_CTRL_GET	_IOWR('U', 3, struct uvc_xu_control)
#define __UVCIOC_CTRL_SET	_IOW('U', 4, struct uvc_xu_control)
#endif
97 98 99 100

#ifdef __KERNEL__

#include <linux/poll.h>
101
#include <linux/usb.h>
102
#include <linux/usb/video.h>
103
#include <linux/uvcvideo.h>
104 105
#include <media/media-device.h>
#include <media/v4l2-device.h>
106 107 108 109 110 111 112

/* --------------------------------------------------------------------------
 * UVC constants
 */

#define UVC_TERM_INPUT			0x0000
#define UVC_TERM_OUTPUT			0x8000
113
#define UVC_TERM_DIRECTION(term)	((term)->type & 0x8000)
114 115 116 117 118

#define UVC_ENTITY_TYPE(entity)		((entity)->type & 0x7fff)
#define UVC_ENTITY_IS_UNIT(entity)	(((entity)->type & 0xff00) == 0)
#define UVC_ENTITY_IS_TERM(entity)	(((entity)->type & 0xff00) != 0)
#define UVC_ENTITY_IS_ITERM(entity) \
119 120
	(UVC_ENTITY_IS_TERM(entity) && \
	((entity)->type & 0x8000) == UVC_TERM_INPUT)
121
#define UVC_ENTITY_IS_OTERM(entity) \
122 123
	(UVC_ENTITY_IS_TERM(entity) && \
	((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150


/* ------------------------------------------------------------------------
 * GUIDs
 */
#define UVC_GUID_UVC_CAMERA \
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
#define UVC_GUID_UVC_OUTPUT \
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
#define UVC_GUID_UVC_PROCESSING \
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
#define UVC_GUID_UVC_SELECTOR \
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}

#define UVC_GUID_FORMAT_MJPEG \
	{ 'M',  'J',  'P',  'G', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
#define UVC_GUID_FORMAT_YUY2 \
	{ 'Y',  'U',  'Y',  '2', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
151 152 153
#define UVC_GUID_FORMAT_YUY2_ISIGHT \
	{ 'Y',  'U',  'Y',  '2', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
#define UVC_GUID_FORMAT_NV12 \
	{ 'N',  'V',  '1',  '2', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
#define UVC_GUID_FORMAT_YV12 \
	{ 'Y',  'V',  '1',  '2', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
#define UVC_GUID_FORMAT_I420 \
	{ 'I',  '4',  '2',  '0', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
#define UVC_GUID_FORMAT_UYVY \
	{ 'U',  'Y',  'V',  'Y', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
#define UVC_GUID_FORMAT_Y800 \
	{ 'Y',  '8',  '0',  '0', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
169 170 171
#define UVC_GUID_FORMAT_Y16 \
	{ 'Y',  '1',  '6',  ' ', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
172 173 174
#define UVC_GUID_FORMAT_BY8 \
	{ 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
175 176 177
#define UVC_GUID_FORMAT_RGBP \
	{ 'R',  'G',  'B',  'P', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
178 179 180
#define UVC_GUID_FORMAT_M420 \
	{ 'M',  '4',  '2',  '0', 0x00, 0x00, 0x10, 0x00, \
	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
181 182 183 184 185

/* ------------------------------------------------------------------------
 * Driver specific constants.
 */

186 187
#define DRIVER_VERSION_NUMBER	KERNEL_VERSION(1, 1, 0)
#define DRIVER_VERSION		"v1.1.0"
188 189 190

/* Number of isochronous URBs. */
#define UVC_URBS		5
191 192
/* Maximum number of packets per URB. */
#define UVC_MAX_PACKETS		32
193 194
/* Maximum number of video buffers. */
#define UVC_MAX_VIDEO_BUFFERS	32
195 196
/* Maximum status buffer size in bytes of interrupt URB. */
#define UVC_MAX_STATUS_SIZE	16
197 198

#define UVC_CTRL_CONTROL_TIMEOUT	300
199
#define UVC_CTRL_STREAMING_TIMEOUT	5000
200

201 202 203
/* Maximum allowed number of control mappings per device */
#define UVC_MAX_CONTROL_MAPPINGS	1024

204 205 206 207 208 209 210
/* Devices quirks */
#define UVC_QUIRK_STATUS_INTERVAL	0x00000001
#define UVC_QUIRK_PROBE_MINMAX		0x00000002
#define UVC_QUIRK_PROBE_EXTRAFIELDS	0x00000004
#define UVC_QUIRK_BUILTIN_ISIGHT	0x00000008
#define UVC_QUIRK_STREAM_NO_FID		0x00000010
#define UVC_QUIRK_IGNORE_SELECTOR_UNIT	0x00000020
211
#define UVC_QUIRK_FIX_BANDWIDTH		0x00000080
212
#define UVC_QUIRK_PROBE_DEF		0x00000100
213
#define UVC_QUIRK_RESTRICT_FRAME_RATE	0x00000200
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231

/* Format flags */
#define UVC_FMT_FLAG_COMPRESSED		0x00000001
#define UVC_FMT_FLAG_STREAM		0x00000002

/* ------------------------------------------------------------------------
 * Structures.
 */

struct uvc_device;

/* TODO: Put the most frequently accessed fields at the beginning of
 * structures to maximize cache efficiency.
 */
struct uvc_control_info {
	struct list_head mappings;

	__u8 entity[16];
232
	__u8 index;	/* Bit index in bmControls */
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
	__u8 selector;

	__u16 size;
	__u32 flags;
};

struct uvc_control_mapping {
	struct list_head list;

	struct uvc_control_info *ctrl;

	__u32 id;
	__u8 name[32];
	__u8 entity[16];
	__u8 selector;

	__u8 size;
	__u8 offset;
	enum v4l2_ctrl_type v4l2_type;
	__u32 data_type;

	struct uvc_menu_info *menu_info;
	__u32 menu_count;
256 257 258 259 260

	__s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
		      const __u8 *data);
	void (*set) (struct uvc_control_mapping *mapping, __s32 value,
		     __u8 *data);
261 262 263 264
};

struct uvc_control {
	struct uvc_entity *entity;
265
	struct uvc_control_info info;
266 267 268

	__u8 index;	/* Used to match the uvc_control entry with a
			   uvc_control_info. */
269 270 271 272 273
	__u8 dirty:1,
	     loaded:1,
	     modified:1,
	     cached:1,
	     initialized:1;
274

275
	__u8 *uvc_data;
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
};

struct uvc_format_desc {
	char *name;
	__u8 guid[16];
	__u32 fcc;
};

/* The term 'entity' refers to both UVC units and UVC terminals.
 *
 * The type field is either the terminal type (wTerminalType in the terminal
 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
 * As the bDescriptorSubtype field is one byte long, the type value will
 * always have a null MSB for units. All terminal types defined by the UVC
 * specification have a non-null MSB, so it is safe to use the MSB to
 * differentiate between units and terminals as long as the descriptor parsing
 * code makes sure terminal types have a non-null MSB.
 *
 * For terminals, the type's most significant bit stores the terminal
 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
 * always be accessed with the UVC_ENTITY_* macros and never directly.
 */

struct uvc_entity {
	struct list_head list;		/* Entity as part of a UVC device. */
	struct list_head chain;		/* Entity as part of a video device
					 * chain. */
	__u8 id;
	__u16 type;
	char name[64];

307 308 309 310 311 312
	/* Media controller-related fields. */
	struct v4l2_subdev subdev;
	unsigned int num_pads;
	unsigned int num_links;
	struct media_pad *pads;

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
	union {
		struct {
			__u16 wObjectiveFocalLengthMin;
			__u16 wObjectiveFocalLengthMax;
			__u16 wOcularFocalLength;
			__u8  bControlSize;
			__u8  *bmControls;
		} camera;

		struct {
			__u8  bControlSize;
			__u8  *bmControls;
			__u8  bTransportModeSize;
			__u8  *bmTransportModes;
		} media;

		struct {
		} output;

		struct {
			__u16 wMaxMultiplier;
			__u8  bControlSize;
			__u8  *bmControls;
			__u8  bmVideoStandards;
		} processing;

		struct {
		} selector;

		struct {
			__u8  guidExtensionCode[16];
			__u8  bNumControls;
			__u8  bControlSize;
			__u8  *bmControls;
			__u8  *bmControlsType;
		} extension;
	};

351 352 353
	__u8 bNrInPins;
	__u8 *baSourceID;

354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
	unsigned int ncontrols;
	struct uvc_control *controls;
};

struct uvc_frame {
	__u8  bFrameIndex;
	__u8  bmCapabilities;
	__u16 wWidth;
	__u16 wHeight;
	__u32 dwMinBitRate;
	__u32 dwMaxBitRate;
	__u32 dwMaxVideoFrameBufferSize;
	__u8  bFrameIntervalType;
	__u32 dwDefaultFrameInterval;
	__u32 *dwFrameInterval;
};

struct uvc_format {
	__u8 type;
	__u8 index;
	__u8 bpp;
	__u8 colorspace;
	__u32 fcc;
	__u32 flags;

	char name[32];

	unsigned int nframes;
	struct uvc_frame *frame;
};

struct uvc_streaming_header {
	__u8 bNumFormats;
	__u8 bEndpointAddress;
	__u8 bTerminalLink;
	__u8 bControlSize;
	__u8 *bmaControls;
	/* The following fields are used by input headers only. */
	__u8 bmInfo;
	__u8 bStillCaptureMethod;
	__u8 bTriggerSupport;
	__u8 bTriggerUsage;
};

enum uvc_buffer_state {
399 400 401
	UVC_BUF_STATE_IDLE	= 0,
	UVC_BUF_STATE_QUEUED	= 1,
	UVC_BUF_STATE_ACTIVE	= 2,
402 403 404
	UVC_BUF_STATE_READY	= 3,
	UVC_BUF_STATE_DONE	= 4,
	UVC_BUF_STATE_ERROR	= 5,
405 406 407 408 409 410 411 412 413 414 415
};

struct uvc_buffer {
	unsigned long vma_use_count;
	struct list_head stream;

	/* Touched by interrupt handler. */
	struct v4l2_buffer buf;
	struct list_head queue;
	wait_queue_head_t wait;
	enum uvc_buffer_state state;
416
	unsigned int error;
417 418 419 420
};

#define UVC_QUEUE_STREAMING		(1 << 0)
#define UVC_QUEUE_DISCONNECTED		(1 << 1)
421
#define UVC_QUEUE_DROP_CORRUPTED	(1 << 2)
422 423

struct uvc_video_queue {
424 425
	enum v4l2_buf_type type;

426 427 428 429 430
	void *mem;
	unsigned int flags;

	unsigned int count;
	unsigned int buf_size;
431
	unsigned int buf_used;
432 433 434 435 436 437 438 439
	struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
	struct mutex mutex;	/* protects buffers and mainqueue */
	spinlock_t irqlock;	/* protects irqqueue */

	struct list_head mainqueue;
	struct list_head irqqueue;
};

440 441 442 443
struct uvc_video_chain {
	struct uvc_device *dev;
	struct list_head list;

444
	struct list_head entities;		/* All entities */
445 446 447
	struct uvc_entity *processing;		/* Processing unit */
	struct uvc_entity *selector;		/* Selector unit */

448
	struct mutex ctrl_mutex;		/* Protects ctrl.info */
449 450
};

451 452
struct uvc_streaming {
	struct list_head list;
453 454
	struct uvc_device *dev;
	struct video_device *vdev;
455
	struct uvc_video_chain *chain;
456 457
	atomic_t active;

458 459 460
	struct usb_interface *intf;
	int intfnum;
	__u16 maxpsize;
461

462 463 464 465 466
	struct uvc_streaming_header header;
	enum v4l2_buf_type type;

	unsigned int nformats;
	struct uvc_format *format;
467

468 469 470
	struct uvc_streaming_control ctrl;
	struct uvc_format *cur_format;
	struct uvc_frame *cur_frame;
471 472 473
	/* Protect access to ctrl, cur_format, cur_frame and hardware video
	 * probe control.
	 */
474
	struct mutex mutex;
475

476 477 478
	unsigned int frozen : 1;
	struct uvc_video_queue queue;
	void (*decode) (struct urb *urb, struct uvc_streaming *video,
479 480 481 482 483 484 485 486 487 488 489 490 491
			struct uvc_buffer *buf);

	/* Context data used by the bulk completion handler. */
	struct {
		__u8 header[256];
		unsigned int header_size;
		int skip_payload;
		__u32 payload_size;
		__u32 max_payload_size;
	} bulk;

	struct urb *urb[UVC_URBS];
	char *urb_buffer[UVC_URBS];
492 493
	dma_addr_t urb_dma[UVC_URBS];
	unsigned int urb_size;
494

495
	__u32 sequence;
496 497 498 499 500 501 502 503 504 505
	__u8 last_fid;
};

enum uvc_device_state {
	UVC_DEV_DISCONNECTED = 1,
};

struct uvc_device {
	struct usb_device *udev;
	struct usb_interface *intf;
506
	unsigned long warnings;
507 508 509 510 511
	__u32 quirks;
	int intfnum;
	char name[32];

	enum uvc_device_state state;
512
	atomic_t users;
513
	atomic_t nmappings;
514 515

	/* Video control interface */
516 517 518 519
#ifdef CONFIG_MEDIA_CONTROLLER
	struct media_device mdev;
#endif
	struct v4l2_device vdev;
520 521 522 523
	__u16 uvc_version;
	__u32 clock_frequency;

	struct list_head entities;
524
	struct list_head chains;
525

526 527
	/* Video Streaming interfaces */
	struct list_head streams;
528
	atomic_t nstreams;
529

530 531 532
	/* Status Interrupt Endpoint */
	struct usb_host_endpoint *int_ep;
	struct urb *int_urb;
533
	__u8 *status;
534
	struct input_dev *input;
535
	char input_phys[64];
536 537 538 539 540 541 542 543
};

enum uvc_handle_state {
	UVC_HANDLE_PASSIVE	= 0,
	UVC_HANDLE_ACTIVE	= 1,
};

struct uvc_fh {
544
	struct uvc_video_chain *chain;
545
	struct uvc_streaming *stream;
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
	enum uvc_handle_state state;
};

struct uvc_driver {
	struct usb_driver driver;
};

/* ------------------------------------------------------------------------
 * Debugging, printing and logging
 */

#define UVC_TRACE_PROBE		(1 << 0)
#define UVC_TRACE_DESCR		(1 << 1)
#define UVC_TRACE_CONTROL	(1 << 2)
#define UVC_TRACE_FORMAT	(1 << 3)
#define UVC_TRACE_CAPTURE	(1 << 4)
#define UVC_TRACE_CALLS		(1 << 5)
#define UVC_TRACE_IOCTL		(1 << 6)
#define UVC_TRACE_FRAME		(1 << 7)
#define UVC_TRACE_SUSPEND	(1 << 8)
#define UVC_TRACE_STATUS	(1 << 9)
567
#define UVC_TRACE_VIDEO		(1 << 10)
568

569 570 571
#define UVC_WARN_MINMAX		0
#define UVC_WARN_PROBE_DEF	1

572
extern unsigned int uvc_clock_param;
573
extern unsigned int uvc_no_drop_param;
574
extern unsigned int uvc_trace_param;
575
extern unsigned int uvc_timeout_param;
576 577 578 579 580 581 582

#define uvc_trace(flag, msg...) \
	do { \
		if (uvc_trace_param & flag) \
			printk(KERN_DEBUG "uvcvideo: " msg); \
	} while (0)

583 584 585 586 587 588
#define uvc_warn_once(dev, warn, msg...) \
	do { \
		if (!test_and_set_bit(warn, &dev->warnings)) \
			printk(KERN_INFO "uvcvideo: " msg); \
	} while (0)

589 590 591 592 593 594 595 596 597 598
#define uvc_printk(level, msg...) \
	printk(level "uvcvideo: " msg)

/* --------------------------------------------------------------------------
 * Internal functions.
 */

/* Core driver */
extern struct uvc_driver uvc_driver;

599 600
extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);

601
/* Video buffers queue management. */
602
extern void uvc_queue_init(struct uvc_video_queue *queue,
603
		enum v4l2_buf_type type, int drop_corrupted);
604 605 606 607 608 609 610 611 612 613 614 615 616
extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
		unsigned int nbuffers, unsigned int buflength);
extern int uvc_free_buffers(struct uvc_video_queue *queue);
extern int uvc_query_buffer(struct uvc_video_queue *queue,
		struct v4l2_buffer *v4l2_buf);
extern int uvc_queue_buffer(struct uvc_video_queue *queue,
		struct v4l2_buffer *v4l2_buf);
extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
		struct v4l2_buffer *v4l2_buf, int nonblocking);
extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
		struct uvc_buffer *buf);
617 618
extern int uvc_queue_mmap(struct uvc_video_queue *queue,
		struct vm_area_struct *vma);
619 620
extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
		struct file *file, poll_table *wait);
621 622 623 624
#ifndef CONFIG_MMU
extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
		unsigned long pgoff);
#endif
625
extern int uvc_queue_allocated(struct uvc_video_queue *queue);
626 627 628 629 630 631
static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
{
	return queue->flags & UVC_QUEUE_STREAMING;
}

/* V4L2 interface */
632
extern const struct v4l2_file_operations uvc_fops;
633

634 635 636 637
/* Media controller */
extern int uvc_mc_register_entities(struct uvc_video_chain *chain);
extern void uvc_mc_cleanup_entity(struct uvc_entity *entity);

638
/* Video */
639 640 641 642 643
extern int uvc_video_init(struct uvc_streaming *stream);
extern int uvc_video_suspend(struct uvc_streaming *stream);
extern int uvc_video_resume(struct uvc_streaming *stream);
extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
extern int uvc_probe_video(struct uvc_streaming *stream,
644
		struct uvc_streaming_control *probe);
645
extern int uvc_commit_video(struct uvc_streaming *stream,
646
		struct uvc_streaming_control *ctrl);
647 648 649 650 651 652
extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
		__u8 intfnum, __u8 cs, void *data, __u16 size);

/* Status */
extern int uvc_status_init(struct uvc_device *dev);
extern void uvc_status_cleanup(struct uvc_device *dev);
653 654
extern int uvc_status_start(struct uvc_device *dev);
extern void uvc_status_stop(struct uvc_device *dev);
655 656 657 658
extern int uvc_status_suspend(struct uvc_device *dev);
extern int uvc_status_resume(struct uvc_device *dev);

/* Controls */
659
extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
660
		struct v4l2_queryctrl *v4l2_ctrl);
661 662
extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
		struct v4l2_querymenu *query_menu);
663

664 665
extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
		const struct uvc_control_mapping *mapping);
666 667 668 669
extern int uvc_ctrl_init_device(struct uvc_device *dev);
extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
extern int uvc_ctrl_resume_device(struct uvc_device *dev);

670 671 672
extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
static inline int uvc_ctrl_commit(struct uvc_video_chain *chain)
673
{
674
	return __uvc_ctrl_commit(chain, 0);
675
}
676
static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain)
677
{
678
	return __uvc_ctrl_commit(chain, 1);
679 680
}

681
extern int uvc_ctrl_get(struct uvc_video_chain *chain,
682
		struct v4l2_ext_control *xctrl);
683
extern int uvc_ctrl_set(struct uvc_video_chain *chain,
684 685
		struct v4l2_ext_control *xctrl);

686
extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
687
		struct uvc_xu_control_query *xqry);
688 689 690 691 692 693 694 695 696 697

/* Utility functions */
extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
		unsigned int n_terms, unsigned int threshold);
extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
		uint32_t denominator);
extern struct usb_host_endpoint *uvc_find_endpoint(
		struct usb_host_interface *alts, __u8 epaddr);

/* Quirks support */
698
void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
699 700 701 702 703
		struct uvc_buffer *buf);

#endif /* __KERNEL__ */

#endif