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