• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _USB_VIDEO_H_
3 #define _USB_VIDEO_H_
4 
5 #ifndef __KERNEL__
6 #error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
7 #endif /* __KERNEL__ */
8 
9 #include <linux/kernel.h>
10 #include <linux/poll.h>
11 #include <linux/usb.h>
12 #include <linux/usb/video.h>
13 #include <linux/uvcvideo.h>
14 #include <linux/videodev2.h>
15 #include <linux/workqueue.h>
16 #include <media/media-device.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-event.h>
19 #include <media/v4l2-fh.h>
20 #include <media/videobuf2-v4l2.h>
21 
22 /* --------------------------------------------------------------------------
23  * UVC constants
24  */
25 
26 #define UVC_TERM_INPUT			0x0000
27 #define UVC_TERM_OUTPUT			0x8000
28 #define UVC_TERM_DIRECTION(term)	((term)->type & 0x8000)
29 
30 #define UVC_ENTITY_TYPE(entity)		((entity)->type & 0x7fff)
31 #define UVC_ENTITY_IS_UNIT(entity)	(((entity)->type & 0xff00) == 0)
32 #define UVC_ENTITY_IS_TERM(entity)	(((entity)->type & 0xff00) != 0)
33 #define UVC_ENTITY_IS_ITERM(entity) \
34 	(UVC_ENTITY_IS_TERM(entity) && \
35 	((entity)->type & 0x8000) == UVC_TERM_INPUT)
36 #define UVC_ENTITY_IS_OTERM(entity) \
37 	(UVC_ENTITY_IS_TERM(entity) && \
38 	((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
39 
40 
41 /* ------------------------------------------------------------------------
42  * Driver specific constants.
43  */
44 
45 #define DRIVER_VERSION		"1.1.1"
46 
47 /* Number of isochronous URBs. */
48 #define UVC_URBS		5
49 /* Maximum number of packets per URB. */
50 #define UVC_MAX_PACKETS		32
51 /* Maximum status buffer size in bytes of interrupt URB. */
52 #define UVC_MAX_STATUS_SIZE	16
53 
54 #define UVC_CTRL_CONTROL_TIMEOUT	5000
55 #define UVC_CTRL_STREAMING_TIMEOUT	5000
56 
57 /* Maximum allowed number of control mappings per device */
58 #define UVC_MAX_CONTROL_MAPPINGS	1024
59 #define UVC_MAX_CONTROL_MENU_ENTRIES	32
60 
61 /* Devices quirks */
62 #define UVC_QUIRK_STATUS_INTERVAL	0x00000001
63 #define UVC_QUIRK_PROBE_MINMAX		0x00000002
64 #define UVC_QUIRK_PROBE_EXTRAFIELDS	0x00000004
65 #define UVC_QUIRK_BUILTIN_ISIGHT	0x00000008
66 #define UVC_QUIRK_STREAM_NO_FID		0x00000010
67 #define UVC_QUIRK_IGNORE_SELECTOR_UNIT	0x00000020
68 #define UVC_QUIRK_FIX_BANDWIDTH		0x00000080
69 #define UVC_QUIRK_PROBE_DEF		0x00000100
70 #define UVC_QUIRK_RESTRICT_FRAME_RATE	0x00000200
71 #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT	0x00000400
72 #define UVC_QUIRK_FORCE_Y8		0x00000800
73 #define UVC_QUIRK_FORCE_BPP		0x00001000
74 #define UVC_QUIRK_WAKE_AUTOSUSPEND	0x00002000
75 
76 /* Format flags */
77 #define UVC_FMT_FLAG_COMPRESSED		0x00000001
78 #define UVC_FMT_FLAG_STREAM		0x00000002
79 
80 /* ------------------------------------------------------------------------
81  * Structures.
82  */
83 
84 struct uvc_device;
85 
86 /* TODO: Put the most frequently accessed fields at the beginning of
87  * structures to maximize cache efficiency.
88  */
89 struct uvc_control_info {
90 	struct list_head mappings;
91 
92 	u8 entity[16];
93 	u8 index;	/* Bit index in bmControls */
94 	u8 selector;
95 
96 	u16 size;
97 	u32 flags;
98 };
99 
100 struct uvc_control_mapping {
101 	struct list_head list;
102 	struct list_head ev_subs;
103 
104 	u32 id;
105 	u8 name[32];
106 	u8 entity[16];
107 	u8 selector;
108 
109 	u8 size;
110 	u8 offset;
111 	enum v4l2_ctrl_type v4l2_type;
112 	u32 data_type;
113 
114 	const struct uvc_menu_info *menu_info;
115 	u32 menu_count;
116 
117 	u32 master_id;
118 	s32 master_manual;
119 	u32 slave_ids[2];
120 
121 	s32 (*get)(struct uvc_control_mapping *mapping, u8 query,
122 		   const u8 *data);
123 	void (*set)(struct uvc_control_mapping *mapping, s32 value,
124 		    u8 *data);
125 };
126 
127 struct uvc_control {
128 	struct uvc_entity *entity;
129 	struct uvc_control_info info;
130 
131 	u8 index;	/* Used to match the uvc_control entry with a
132 			   uvc_control_info. */
133 	u8 dirty:1,
134 	   loaded:1,
135 	   modified:1,
136 	   cached:1,
137 	   initialized:1;
138 
139 	u8 *uvc_data;
140 
141 	struct uvc_fh *handle;	/* File handle that last changed the control. */
142 };
143 
144 /*
145  * The term 'entity' refers to both UVC units and UVC terminals.
146  *
147  * The type field is either the terminal type (wTerminalType in the terminal
148  * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
149  * As the bDescriptorSubtype field is one byte long, the type value will
150  * always have a null MSB for units. All terminal types defined by the UVC
151  * specification have a non-null MSB, so it is safe to use the MSB to
152  * differentiate between units and terminals as long as the descriptor parsing
153  * code makes sure terminal types have a non-null MSB.
154  *
155  * For terminals, the type's most significant bit stores the terminal
156  * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
157  * always be accessed with the UVC_ENTITY_* macros and never directly.
158  */
159 
160 #define UVC_ENTITY_FLAG_DEFAULT		(1 << 0)
161 
162 struct uvc_entity {
163 	struct list_head list;		/* Entity as part of a UVC device. */
164 	struct list_head chain;		/* Entity as part of a video device
165 					 * chain. */
166 	unsigned int flags;
167 
168 	u8 id;
169 	u16 type;
170 	char name[64];
171 
172 	/* Media controller-related fields. */
173 	struct video_device *vdev;
174 	struct v4l2_subdev subdev;
175 	unsigned int num_pads;
176 	unsigned int num_links;
177 	struct media_pad *pads;
178 
179 	union {
180 		struct {
181 			u16 wObjectiveFocalLengthMin;
182 			u16 wObjectiveFocalLengthMax;
183 			u16 wOcularFocalLength;
184 			u8  bControlSize;
185 			u8  *bmControls;
186 		} camera;
187 
188 		struct {
189 			u8  bControlSize;
190 			u8  *bmControls;
191 			u8  bTransportModeSize;
192 			u8  *bmTransportModes;
193 		} media;
194 
195 		struct {
196 		} output;
197 
198 		struct {
199 			u16 wMaxMultiplier;
200 			u8  bControlSize;
201 			u8  *bmControls;
202 			u8  bmVideoStandards;
203 		} processing;
204 
205 		struct {
206 		} selector;
207 
208 		struct {
209 			u8  guidExtensionCode[16];
210 			u8  bNumControls;
211 			u8  bControlSize;
212 			u8  *bmControls;
213 			u8  *bmControlsType;
214 		} extension;
215 	};
216 
217 	u8 bNrInPins;
218 	u8 *baSourceID;
219 
220 	unsigned int ncontrols;
221 	struct uvc_control *controls;
222 };
223 
224 struct uvc_frame {
225 	u8  bFrameIndex;
226 	u8  bmCapabilities;
227 	u16 wWidth;
228 	u16 wHeight;
229 	u32 dwMinBitRate;
230 	u32 dwMaxBitRate;
231 	u32 dwMaxVideoFrameBufferSize;
232 	u8  bFrameIntervalType;
233 	u32 dwDefaultFrameInterval;
234 	u32 *dwFrameInterval;
235 };
236 
237 struct uvc_format {
238 	u8 type;
239 	u8 index;
240 	u8 bpp;
241 	enum v4l2_colorspace colorspace;
242 	enum v4l2_xfer_func xfer_func;
243 	enum v4l2_ycbcr_encoding ycbcr_enc;
244 	u32 fcc;
245 	u32 flags;
246 
247 	char name[32];
248 
249 	unsigned int nframes;
250 	struct uvc_frame *frame;
251 };
252 
253 struct uvc_streaming_header {
254 	u8 bNumFormats;
255 	u8 bEndpointAddress;
256 	u8 bTerminalLink;
257 	u8 bControlSize;
258 	u8 *bmaControls;
259 	/* The following fields are used by input headers only. */
260 	u8 bmInfo;
261 	u8 bStillCaptureMethod;
262 	u8 bTriggerSupport;
263 	u8 bTriggerUsage;
264 };
265 
266 enum uvc_buffer_state {
267 	UVC_BUF_STATE_IDLE	= 0,
268 	UVC_BUF_STATE_QUEUED	= 1,
269 	UVC_BUF_STATE_ACTIVE	= 2,
270 	UVC_BUF_STATE_READY	= 3,
271 	UVC_BUF_STATE_DONE	= 4,
272 	UVC_BUF_STATE_ERROR	= 5,
273 };
274 
275 struct uvc_buffer {
276 	struct vb2_v4l2_buffer buf;
277 	struct list_head queue;
278 
279 	enum uvc_buffer_state state;
280 	unsigned int error;
281 
282 	void *mem;
283 	unsigned int length;
284 	unsigned int bytesused;
285 
286 	u32 pts;
287 
288 	/* Asynchronous buffer handling. */
289 	struct kref ref;
290 };
291 
292 #define UVC_QUEUE_DISCONNECTED		(1 << 0)
293 #define UVC_QUEUE_DROP_CORRUPTED	(1 << 1)
294 
295 struct uvc_video_queue {
296 	struct vb2_queue queue;
297 	struct mutex mutex;			/* Protects queue */
298 
299 	unsigned int flags;
300 	unsigned int buf_used;
301 
302 	spinlock_t irqlock;			/* Protects irqqueue */
303 	struct list_head irqqueue;
304 };
305 
306 struct uvc_video_chain {
307 	struct uvc_device *dev;
308 	struct list_head list;
309 
310 	struct list_head entities;		/* All entities */
311 	struct uvc_entity *processing;		/* Processing unit */
312 	struct uvc_entity *selector;		/* Selector unit */
313 
314 	struct mutex ctrl_mutex;		/* Protects ctrl.info */
315 
316 	struct v4l2_prio_state prio;		/* V4L2 priority state */
317 	u32 caps;				/* V4L2 chain-wide caps */
318 };
319 
320 struct uvc_stats_frame {
321 	unsigned int size;		/* Number of bytes captured */
322 	unsigned int first_data;	/* Index of the first non-empty packet */
323 
324 	unsigned int nb_packets;	/* Number of packets */
325 	unsigned int nb_empty;		/* Number of empty packets */
326 	unsigned int nb_invalid;	/* Number of packets with an invalid header */
327 	unsigned int nb_errors;		/* Number of packets with the error bit set */
328 
329 	unsigned int nb_pts;		/* Number of packets with a PTS timestamp */
330 	unsigned int nb_pts_diffs;	/* Number of PTS differences inside a frame */
331 	unsigned int last_pts_diff;	/* Index of the last PTS difference */
332 	bool has_initial_pts;		/* Whether the first non-empty packet has a PTS */
333 	bool has_early_pts;		/* Whether a PTS is present before the first non-empty packet */
334 	u32 pts;			/* PTS of the last packet */
335 
336 	unsigned int nb_scr;		/* Number of packets with a SCR timestamp */
337 	unsigned int nb_scr_diffs;	/* Number of SCR.STC differences inside a frame */
338 	u16 scr_sof;			/* SCR.SOF of the last packet */
339 	u32 scr_stc;			/* SCR.STC of the last packet */
340 };
341 
342 struct uvc_stats_stream {
343 	ktime_t start_ts;		/* Stream start timestamp */
344 	ktime_t stop_ts;		/* Stream stop timestamp */
345 
346 	unsigned int nb_frames;		/* Number of frames */
347 
348 	unsigned int nb_packets;	/* Number of packets */
349 	unsigned int nb_empty;		/* Number of empty packets */
350 	unsigned int nb_invalid;	/* Number of packets with an invalid header */
351 	unsigned int nb_errors;		/* Number of packets with the error bit set */
352 
353 	unsigned int nb_pts_constant;	/* Number of frames with constant PTS */
354 	unsigned int nb_pts_early;	/* Number of frames with early PTS */
355 	unsigned int nb_pts_initial;	/* Number of frames with initial PTS */
356 
357 	unsigned int nb_scr_count_ok;	/* Number of frames with at least one SCR per non empty packet */
358 	unsigned int nb_scr_diffs_ok;	/* Number of frames with varying SCR.STC */
359 	unsigned int scr_sof_count;	/* STC.SOF counter accumulated since stream start */
360 	unsigned int scr_sof;		/* STC.SOF of the last packet */
361 	unsigned int min_sof;		/* Minimum STC.SOF value */
362 	unsigned int max_sof;		/* Maximum STC.SOF value */
363 };
364 
365 #define UVC_METADATA_BUF_SIZE 1024
366 
367 /**
368  * struct uvc_copy_op: Context structure to schedule asynchronous memcpy
369  *
370  * @buf: active buf object for this operation
371  * @dst: copy destination address
372  * @src: copy source address
373  * @len: copy length
374  */
375 struct uvc_copy_op {
376 	struct uvc_buffer *buf;
377 	void *dst;
378 	const __u8 *src;
379 	size_t len;
380 };
381 
382 /**
383  * struct uvc_urb - URB context management structure
384  *
385  * @urb: the URB described by this context structure
386  * @stream: UVC streaming context
387  * @buffer: memory storage for the URB
388  * @dma: DMA coherent addressing for the urb_buffer
389  * @async_operations: counter to indicate the number of copy operations
390  * @copy_operations: work descriptors for asynchronous copy operations
391  * @work: work queue entry for asynchronous decode
392  */
393 struct uvc_urb {
394 	struct urb *urb;
395 	struct uvc_streaming *stream;
396 
397 	char *buffer;
398 	dma_addr_t dma;
399 
400 	unsigned int async_operations;
401 	struct uvc_copy_op copy_operations[UVC_MAX_PACKETS];
402 	struct work_struct work;
403 };
404 
405 struct uvc_streaming {
406 	struct list_head list;
407 	struct uvc_device *dev;
408 	struct video_device vdev;
409 	struct uvc_video_chain *chain;
410 	atomic_t active;
411 
412 	struct usb_interface *intf;
413 	int intfnum;
414 	u16 maxpsize;
415 
416 	struct uvc_streaming_header header;
417 	enum v4l2_buf_type type;
418 
419 	unsigned int nformats;
420 	struct uvc_format *format;
421 
422 	struct uvc_streaming_control ctrl;
423 	struct uvc_format *def_format;
424 	struct uvc_format *cur_format;
425 	struct uvc_frame *cur_frame;
426 
427 	/* Protect access to ctrl, cur_format, cur_frame and hardware video
428 	 * probe control.
429 	 */
430 	struct mutex mutex;
431 
432 	/* Buffers queue. */
433 	unsigned int frozen : 1;
434 	struct uvc_video_queue queue;
435 	struct workqueue_struct *async_wq;
436 	void (*decode)(struct uvc_urb *uvc_urb, struct uvc_buffer *buf,
437 		       struct uvc_buffer *meta_buf);
438 
439 	struct {
440 		struct video_device vdev;
441 		struct uvc_video_queue queue;
442 		u32 format;
443 	} meta;
444 
445 	/* Context data used by the bulk completion handler. */
446 	struct {
447 		u8 header[256];
448 		unsigned int header_size;
449 		int skip_payload;
450 		u32 payload_size;
451 		u32 max_payload_size;
452 	} bulk;
453 
454 	struct uvc_urb uvc_urb[UVC_URBS];
455 	unsigned int urb_size;
456 
457 	u32 sequence;
458 	u8 last_fid;
459 
460 	/* debugfs */
461 	struct dentry *debugfs_dir;
462 	struct {
463 		struct uvc_stats_frame frame;
464 		struct uvc_stats_stream stream;
465 	} stats;
466 
467 	/* Timestamps support. */
468 	struct uvc_clock {
469 		struct uvc_clock_sample {
470 			u32 dev_stc;
471 			u16 dev_sof;
472 			u16 host_sof;
473 			ktime_t host_time;
474 		} *samples;
475 
476 		unsigned int head;
477 		unsigned int count;
478 		unsigned int size;
479 
480 		u16 last_sof;
481 		u16 sof_offset;
482 
483 		u8 last_scr[6];
484 
485 		spinlock_t lock;
486 	} clock;
487 };
488 
489 #define for_each_uvc_urb(uvc_urb, uvc_streaming) \
490 	for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \
491 	     (uvc_urb) < &(uvc_streaming)->uvc_urb[UVC_URBS]; \
492 	     ++(uvc_urb))
493 
uvc_urb_index(const struct uvc_urb * uvc_urb)494 static inline u32 uvc_urb_index(const struct uvc_urb *uvc_urb)
495 {
496 	return uvc_urb - &uvc_urb->stream->uvc_urb[0];
497 }
498 
499 struct uvc_device_info {
500 	u32	quirks;
501 	u32	meta_format;
502 };
503 
504 struct uvc_device {
505 	struct usb_device *udev;
506 	struct usb_interface *intf;
507 	unsigned long warnings;
508 	u32 quirks;
509 	int intfnum;
510 	char name[32];
511 
512 	const struct uvc_device_info *info;
513 
514 	struct mutex lock;		/* Protects users */
515 	unsigned int users;
516 	atomic_t nmappings;
517 
518 	/* Video control interface */
519 #ifdef CONFIG_MEDIA_CONTROLLER
520 	struct media_device mdev;
521 #endif
522 	struct v4l2_device vdev;
523 	u16 uvc_version;
524 	u32 clock_frequency;
525 
526 	struct list_head entities;
527 	struct list_head chains;
528 
529 	/* Video Streaming interfaces */
530 	struct list_head streams;
531 	struct kref ref;
532 
533 	/* Status Interrupt Endpoint */
534 	struct usb_host_endpoint *int_ep;
535 	struct urb *int_urb;
536 	bool flush_status;
537 	u8 *status;
538 	struct input_dev *input;
539 	char input_phys[64];
540 
541 	struct uvc_ctrl_work {
542 		struct work_struct work;
543 		struct urb *urb;
544 		struct uvc_video_chain *chain;
545 		struct uvc_control *ctrl;
546 		const void *data;
547 	} async_ctrl;
548 };
549 
550 enum uvc_handle_state {
551 	UVC_HANDLE_PASSIVE	= 0,
552 	UVC_HANDLE_ACTIVE	= 1,
553 };
554 
555 struct uvc_fh {
556 	struct v4l2_fh vfh;
557 	struct uvc_video_chain *chain;
558 	struct uvc_streaming *stream;
559 	enum uvc_handle_state state;
560 };
561 
562 struct uvc_driver {
563 	struct usb_driver driver;
564 };
565 
566 /* ------------------------------------------------------------------------
567  * Debugging, printing and logging
568  */
569 
570 #define UVC_TRACE_PROBE		(1 << 0)
571 #define UVC_TRACE_DESCR		(1 << 1)
572 #define UVC_TRACE_CONTROL	(1 << 2)
573 #define UVC_TRACE_FORMAT	(1 << 3)
574 #define UVC_TRACE_CAPTURE	(1 << 4)
575 #define UVC_TRACE_CALLS		(1 << 5)
576 #define UVC_TRACE_FRAME		(1 << 7)
577 #define UVC_TRACE_SUSPEND	(1 << 8)
578 #define UVC_TRACE_STATUS	(1 << 9)
579 #define UVC_TRACE_VIDEO		(1 << 10)
580 #define UVC_TRACE_STATS		(1 << 11)
581 #define UVC_TRACE_CLOCK		(1 << 12)
582 
583 #define UVC_WARN_MINMAX		0
584 #define UVC_WARN_PROBE_DEF	1
585 #define UVC_WARN_XU_GET_RES	2
586 
587 extern unsigned int uvc_clock_param;
588 extern unsigned int uvc_no_drop_param;
589 extern unsigned int uvc_trace_param;
590 extern unsigned int uvc_timeout_param;
591 extern unsigned int uvc_hw_timestamps_param;
592 
593 #define uvc_trace(flag, msg...) \
594 	do { \
595 		if (uvc_trace_param & flag) \
596 			printk(KERN_DEBUG "uvcvideo: " msg); \
597 	} while (0)
598 
599 #define uvc_warn_once(dev, warn, msg...) \
600 	do { \
601 		if (!test_and_set_bit(warn, &dev->warnings)) \
602 			printk(KERN_INFO "uvcvideo: " msg); \
603 	} while (0)
604 
605 #define uvc_printk(level, msg...) \
606 	printk(level "uvcvideo: " msg)
607 
608 /* --------------------------------------------------------------------------
609  * Internal functions.
610  */
611 
612 /* Core driver */
613 extern struct uvc_driver uvc_driver;
614 
615 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
616 
617 /* Video buffers queue management. */
618 int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
619 		   int drop_corrupted);
620 void uvc_queue_release(struct uvc_video_queue *queue);
621 int uvc_request_buffers(struct uvc_video_queue *queue,
622 			struct v4l2_requestbuffers *rb);
623 int uvc_query_buffer(struct uvc_video_queue *queue,
624 		     struct v4l2_buffer *v4l2_buf);
625 int uvc_create_buffers(struct uvc_video_queue *queue,
626 		       struct v4l2_create_buffers *v4l2_cb);
627 int uvc_queue_buffer(struct uvc_video_queue *queue,
628 		     struct media_device *mdev,
629 		     struct v4l2_buffer *v4l2_buf);
630 int uvc_export_buffer(struct uvc_video_queue *queue,
631 		      struct v4l2_exportbuffer *exp);
632 int uvc_dequeue_buffer(struct uvc_video_queue *queue,
633 		       struct v4l2_buffer *v4l2_buf, int nonblocking);
634 int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type);
635 int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type);
636 void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
637 struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
638 					 struct uvc_buffer *buf);
639 struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue);
640 void uvc_queue_buffer_release(struct uvc_buffer *buf);
641 int uvc_queue_mmap(struct uvc_video_queue *queue,
642 		   struct vm_area_struct *vma);
643 __poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
644 			poll_table *wait);
645 #ifndef CONFIG_MMU
646 unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
647 					  unsigned long pgoff);
648 #endif
649 int uvc_queue_allocated(struct uvc_video_queue *queue);
uvc_queue_streaming(struct uvc_video_queue * queue)650 static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
651 {
652 	return vb2_is_streaming(&queue->queue);
653 }
654 
655 /* V4L2 interface */
656 extern const struct v4l2_ioctl_ops uvc_ioctl_ops;
657 extern const struct v4l2_file_operations uvc_fops;
658 
659 /* Media controller */
660 int uvc_mc_register_entities(struct uvc_video_chain *chain);
661 void uvc_mc_cleanup_entity(struct uvc_entity *entity);
662 
663 /* Video */
664 int uvc_video_init(struct uvc_streaming *stream);
665 int uvc_video_suspend(struct uvc_streaming *stream);
666 int uvc_video_resume(struct uvc_streaming *stream, int reset);
667 int uvc_video_start_streaming(struct uvc_streaming *stream);
668 void uvc_video_stop_streaming(struct uvc_streaming *stream);
669 int uvc_probe_video(struct uvc_streaming *stream,
670 		    struct uvc_streaming_control *probe);
671 int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
672 		   u8 intfnum, u8 cs, void *data, u16 size);
673 void uvc_video_clock_update(struct uvc_streaming *stream,
674 			    struct vb2_v4l2_buffer *vbuf,
675 			    struct uvc_buffer *buf);
676 int uvc_meta_register(struct uvc_streaming *stream);
677 
678 int uvc_register_video_device(struct uvc_device *dev,
679 			      struct uvc_streaming *stream,
680 			      struct video_device *vdev,
681 			      struct uvc_video_queue *queue,
682 			      enum v4l2_buf_type type,
683 			      const struct v4l2_file_operations *fops,
684 			      const struct v4l2_ioctl_ops *ioctl_ops);
685 
686 /* Status */
687 int uvc_status_init(struct uvc_device *dev);
688 void uvc_status_unregister(struct uvc_device *dev);
689 void uvc_status_cleanup(struct uvc_device *dev);
690 int uvc_status_start(struct uvc_device *dev, gfp_t flags);
691 void uvc_status_stop(struct uvc_device *dev);
692 
693 /* Controls */
694 extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
695 
696 int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
697 			struct v4l2_queryctrl *v4l2_ctrl);
698 int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
699 			struct v4l2_querymenu *query_menu);
700 
701 int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
702 			 const struct uvc_control_mapping *mapping);
703 int uvc_ctrl_init_device(struct uvc_device *dev);
704 void uvc_ctrl_cleanup_device(struct uvc_device *dev);
705 int uvc_ctrl_restore_values(struct uvc_device *dev);
706 bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain,
707 				 struct uvc_control *ctrl, const u8 *data);
708 void uvc_ctrl_status_event(struct uvc_video_chain *chain,
709 			   struct uvc_control *ctrl, const u8 *data);
710 
711 int uvc_ctrl_begin(struct uvc_video_chain *chain);
712 int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
713 		      const struct v4l2_ext_control *xctrls,
714 		      unsigned int xctrls_count);
uvc_ctrl_commit(struct uvc_fh * handle,const struct v4l2_ext_control * xctrls,unsigned int xctrls_count)715 static inline int uvc_ctrl_commit(struct uvc_fh *handle,
716 				  const struct v4l2_ext_control *xctrls,
717 				  unsigned int xctrls_count)
718 {
719 	return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count);
720 }
uvc_ctrl_rollback(struct uvc_fh * handle)721 static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
722 {
723 	return __uvc_ctrl_commit(handle, 1, NULL, 0);
724 }
725 
726 int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl);
727 int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
728 
729 int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
730 		      struct uvc_xu_control_query *xqry);
731 
732 /* Utility functions */
733 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
734 					    u8 epaddr);
735 
736 /* Quirks support */
737 void uvc_video_decode_isight(struct uvc_urb *uvc_urb,
738 			     struct uvc_buffer *buf,
739 			     struct uvc_buffer *meta_buf);
740 
741 /* debugfs and statistics */
742 void uvc_debugfs_init(void);
743 void uvc_debugfs_cleanup(void);
744 void uvc_debugfs_init_stream(struct uvc_streaming *stream);
745 void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream);
746 
747 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf,
748 			    size_t size);
749 
750 #endif
751