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