1 /* SPDX-License-Identifier: GPL-2.0 */
6 #error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
7 #endif /* __KERNEL__ */
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 <media/media-device.h>
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-event.h>
18 #include <media/v4l2-fh.h>
19 #include <media/videobuf2-v4l2.h>
21 /* --------------------------------------------------------------------------
25 #define UVC_TERM_INPUT 0x0000
26 #define UVC_TERM_OUTPUT 0x8000
27 #define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
29 #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
30 #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
31 #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
32 #define UVC_ENTITY_IS_ITERM(entity) \
33 (UVC_ENTITY_IS_TERM(entity) && \
34 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
35 #define UVC_ENTITY_IS_OTERM(entity) \
36 (UVC_ENTITY_IS_TERM(entity) && \
37 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
40 /* ------------------------------------------------------------------------
43 #define UVC_GUID_UVC_CAMERA \
44 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
46 #define UVC_GUID_UVC_OUTPUT \
47 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
49 #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
50 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
52 #define UVC_GUID_UVC_PROCESSING \
53 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
55 #define UVC_GUID_UVC_SELECTOR \
56 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
59 #define UVC_GUID_FORMAT_MJPEG \
60 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
61 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
62 #define UVC_GUID_FORMAT_YUY2 \
63 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
64 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
65 #define UVC_GUID_FORMAT_YUY2_ISIGHT \
66 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
67 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
68 #define UVC_GUID_FORMAT_NV12 \
69 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
70 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
71 #define UVC_GUID_FORMAT_YV12 \
72 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
73 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
74 #define UVC_GUID_FORMAT_I420 \
75 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
76 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
77 #define UVC_GUID_FORMAT_UYVY \
78 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
79 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
80 #define UVC_GUID_FORMAT_Y800 \
81 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
82 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
83 #define UVC_GUID_FORMAT_Y8 \
84 { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \
85 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
86 #define UVC_GUID_FORMAT_Y10 \
87 { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \
88 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
89 #define UVC_GUID_FORMAT_Y12 \
90 { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \
91 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
92 #define UVC_GUID_FORMAT_Y16 \
93 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
94 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
95 #define UVC_GUID_FORMAT_BY8 \
96 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
97 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
98 #define UVC_GUID_FORMAT_BA81 \
99 { 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \
100 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
101 #define UVC_GUID_FORMAT_GBRG \
102 { 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \
103 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
104 #define UVC_GUID_FORMAT_GRBG \
105 { 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \
106 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
107 #define UVC_GUID_FORMAT_RGGB \
108 { 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \
109 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
110 #define UVC_GUID_FORMAT_BG16 \
111 { 'B', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \
112 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
113 #define UVC_GUID_FORMAT_GB16 \
114 { 'G', 'B', '1', '6', 0x00, 0x00, 0x10, 0x00, \
115 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
116 #define UVC_GUID_FORMAT_RG16 \
117 { 'R', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \
118 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
119 #define UVC_GUID_FORMAT_GR16 \
120 { 'G', 'R', '1', '6', 0x00, 0x00, 0x10, 0x00, \
121 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
122 #define UVC_GUID_FORMAT_RGBP \
123 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
124 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
125 #define UVC_GUID_FORMAT_BGR3 \
126 { 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \
127 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}
128 #define UVC_GUID_FORMAT_M420 \
129 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
130 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
132 #define UVC_GUID_FORMAT_H264 \
133 { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \
134 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
135 #define UVC_GUID_FORMAT_Y8I \
136 { 'Y', '8', 'I', ' ', 0x00, 0x00, 0x10, 0x00, \
137 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
138 #define UVC_GUID_FORMAT_Y12I \
139 { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \
140 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
141 #define UVC_GUID_FORMAT_Z16 \
142 { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
143 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
144 #define UVC_GUID_FORMAT_RW10 \
145 { 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \
146 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
147 #define UVC_GUID_FORMAT_INVZ \
148 { 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \
149 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b}
150 #define UVC_GUID_FORMAT_INZI \
151 { 'I', 'N', 'Z', 'I', 0x66, 0x1a, 0x42, 0xa2, \
152 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a}
153 #define UVC_GUID_FORMAT_INVI \
154 { 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \
155 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f}
157 /* ------------------------------------------------------------------------
158 * Driver specific constants.
161 #define DRIVER_VERSION "1.1.1"
163 /* Number of isochronous URBs. */
165 /* Maximum number of packets per URB. */
166 #define UVC_MAX_PACKETS 32
167 /* Maximum status buffer size in bytes of interrupt URB. */
168 #define UVC_MAX_STATUS_SIZE 16
170 #define UVC_CTRL_CONTROL_TIMEOUT 500
171 #define UVC_CTRL_STREAMING_TIMEOUT 5000
173 /* Maximum allowed number of control mappings per device */
174 #define UVC_MAX_CONTROL_MAPPINGS 1024
175 #define UVC_MAX_CONTROL_MENU_ENTRIES 32
178 #define UVC_QUIRK_STATUS_INTERVAL 0x00000001
179 #define UVC_QUIRK_PROBE_MINMAX 0x00000002
180 #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
181 #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
182 #define UVC_QUIRK_STREAM_NO_FID 0x00000010
183 #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
184 #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
185 #define UVC_QUIRK_PROBE_DEF 0x00000100
186 #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
187 #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400
188 #define UVC_QUIRK_FORCE_Y8 0x00000800
191 #define UVC_FMT_FLAG_COMPRESSED 0x00000001
192 #define UVC_FMT_FLAG_STREAM 0x00000002
194 /* ------------------------------------------------------------------------
200 /* TODO: Put the most frequently accessed fields at the beginning of
201 * structures to maximize cache efficiency.
203 struct uvc_control_info
{
204 struct list_head mappings
;
207 __u8 index
; /* Bit index in bmControls */
214 struct uvc_control_mapping
{
215 struct list_head list
;
216 struct list_head ev_subs
;
225 enum v4l2_ctrl_type v4l2_type
;
228 struct uvc_menu_info
*menu_info
;
235 __s32 (*get
) (struct uvc_control_mapping
*mapping
, __u8 query
,
237 void (*set
) (struct uvc_control_mapping
*mapping
, __s32 value
,
242 struct uvc_entity
*entity
;
243 struct uvc_control_info info
;
245 __u8 index
; /* Used to match the uvc_control entry with a
256 struct uvc_format_desc
{
262 /* The term 'entity' refers to both UVC units and UVC terminals.
264 * The type field is either the terminal type (wTerminalType in the terminal
265 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
266 * As the bDescriptorSubtype field is one byte long, the type value will
267 * always have a null MSB for units. All terminal types defined by the UVC
268 * specification have a non-null MSB, so it is safe to use the MSB to
269 * differentiate between units and terminals as long as the descriptor parsing
270 * code makes sure terminal types have a non-null MSB.
272 * For terminals, the type's most significant bit stores the terminal
273 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
274 * always be accessed with the UVC_ENTITY_* macros and never directly.
277 #define UVC_ENTITY_FLAG_DEFAULT (1 << 0)
280 struct list_head list
; /* Entity as part of a UVC device. */
281 struct list_head chain
; /* Entity as part of a video device
289 /* Media controller-related fields. */
290 struct video_device
*vdev
;
291 struct v4l2_subdev subdev
;
292 unsigned int num_pads
;
293 unsigned int num_links
;
294 struct media_pad
*pads
;
298 __u16 wObjectiveFocalLengthMin
;
299 __u16 wObjectiveFocalLengthMax
;
300 __u16 wOcularFocalLength
;
308 __u8 bTransportModeSize
;
309 __u8
*bmTransportModes
;
316 __u16 wMaxMultiplier
;
319 __u8 bmVideoStandards
;
326 __u8 guidExtensionCode
[16];
330 __u8
*bmControlsType
;
337 unsigned int ncontrols
;
338 struct uvc_control
*controls
;
348 __u32 dwMaxVideoFrameBufferSize
;
349 __u8 bFrameIntervalType
;
350 __u32 dwDefaultFrameInterval
;
351 __u32
*dwFrameInterval
;
364 unsigned int nframes
;
365 struct uvc_frame
*frame
;
368 struct uvc_streaming_header
{
370 __u8 bEndpointAddress
;
374 /* The following fields are used by input headers only. */
376 __u8 bStillCaptureMethod
;
377 __u8 bTriggerSupport
;
381 enum uvc_buffer_state
{
382 UVC_BUF_STATE_IDLE
= 0,
383 UVC_BUF_STATE_QUEUED
= 1,
384 UVC_BUF_STATE_ACTIVE
= 2,
385 UVC_BUF_STATE_READY
= 3,
386 UVC_BUF_STATE_DONE
= 4,
387 UVC_BUF_STATE_ERROR
= 5,
391 struct vb2_v4l2_buffer buf
;
392 struct list_head queue
;
394 enum uvc_buffer_state state
;
399 unsigned int bytesused
;
404 #define UVC_QUEUE_DISCONNECTED (1 << 0)
405 #define UVC_QUEUE_DROP_CORRUPTED (1 << 1)
407 struct uvc_video_queue
{
408 struct vb2_queue queue
;
409 struct mutex mutex
; /* Protects queue */
412 unsigned int buf_used
;
414 spinlock_t irqlock
; /* Protects irqqueue */
415 struct list_head irqqueue
;
418 struct uvc_video_chain
{
419 struct uvc_device
*dev
;
420 struct list_head list
;
422 struct list_head entities
; /* All entities */
423 struct uvc_entity
*processing
; /* Processing unit */
424 struct uvc_entity
*selector
; /* Selector unit */
426 struct mutex ctrl_mutex
; /* Protects ctrl.info */
428 struct v4l2_prio_state prio
; /* V4L2 priority state */
429 u32 caps
; /* V4L2 chain-wide caps */
432 struct uvc_stats_frame
{
433 unsigned int size
; /* Number of bytes captured */
434 unsigned int first_data
; /* Index of the first non-empty packet */
436 unsigned int nb_packets
; /* Number of packets */
437 unsigned int nb_empty
; /* Number of empty packets */
438 unsigned int nb_invalid
; /* Number of packets with an invalid header */
439 unsigned int nb_errors
; /* Number of packets with the error bit set */
441 unsigned int nb_pts
; /* Number of packets with a PTS timestamp */
442 unsigned int nb_pts_diffs
; /* Number of PTS differences inside a frame */
443 unsigned int last_pts_diff
; /* Index of the last PTS difference */
444 bool has_initial_pts
; /* Whether the first non-empty packet has a PTS */
445 bool has_early_pts
; /* Whether a PTS is present before the first non-empty packet */
446 u32 pts
; /* PTS of the last packet */
448 unsigned int nb_scr
; /* Number of packets with a SCR timestamp */
449 unsigned int nb_scr_diffs
; /* Number of SCR.STC differences inside a frame */
450 u16 scr_sof
; /* SCR.SOF of the last packet */
451 u32 scr_stc
; /* SCR.STC of the last packet */
454 struct uvc_stats_stream
{
455 struct timespec start_ts
; /* Stream start timestamp */
456 struct timespec stop_ts
; /* Stream stop timestamp */
458 unsigned int nb_frames
; /* Number of frames */
460 unsigned int nb_packets
; /* Number of packets */
461 unsigned int nb_empty
; /* Number of empty packets */
462 unsigned int nb_invalid
; /* Number of packets with an invalid header */
463 unsigned int nb_errors
; /* Number of packets with the error bit set */
465 unsigned int nb_pts_constant
; /* Number of frames with constant PTS */
466 unsigned int nb_pts_early
; /* Number of frames with early PTS */
467 unsigned int nb_pts_initial
; /* Number of frames with initial PTS */
469 unsigned int nb_scr_count_ok
; /* Number of frames with at least one SCR per non empty packet */
470 unsigned int nb_scr_diffs_ok
; /* Number of frames with varying SCR.STC */
471 unsigned int scr_sof_count
; /* STC.SOF counter accumulated since stream start */
472 unsigned int scr_sof
; /* STC.SOF of the last packet */
473 unsigned int min_sof
; /* Minimum STC.SOF value */
474 unsigned int max_sof
; /* Maximum STC.SOF value */
477 struct uvc_streaming
{
478 struct list_head list
;
479 struct uvc_device
*dev
;
480 struct video_device vdev
;
481 struct uvc_video_chain
*chain
;
484 struct usb_interface
*intf
;
488 struct uvc_streaming_header header
;
489 enum v4l2_buf_type type
;
491 unsigned int nformats
;
492 struct uvc_format
*format
;
494 struct uvc_streaming_control ctrl
;
495 struct uvc_format
*def_format
;
496 struct uvc_format
*cur_format
;
497 struct uvc_frame
*cur_frame
;
499 /* Protect access to ctrl, cur_format, cur_frame and hardware video
505 unsigned int frozen
: 1;
506 struct uvc_video_queue queue
;
507 void (*decode
) (struct urb
*urb
, struct uvc_streaming
*video
,
508 struct uvc_buffer
*buf
);
510 /* Context data used by the bulk completion handler. */
513 unsigned int header_size
;
516 __u32 max_payload_size
;
519 struct urb
*urb
[UVC_URBS
];
520 char *urb_buffer
[UVC_URBS
];
521 dma_addr_t urb_dma
[UVC_URBS
];
522 unsigned int urb_size
;
528 struct dentry
*debugfs_dir
;
530 struct uvc_stats_frame frame
;
531 struct uvc_stats_stream stream
;
534 /* Timestamps support. */
536 struct uvc_clock_sample
{
539 struct timespec host_ts
;
555 struct usb_device
*udev
;
556 struct usb_interface
*intf
;
557 unsigned long warnings
;
562 struct mutex lock
; /* Protects users */
566 /* Video control interface */
567 #ifdef CONFIG_MEDIA_CONTROLLER
568 struct media_device mdev
;
570 struct v4l2_device vdev
;
572 __u32 clock_frequency
;
574 struct list_head entities
;
575 struct list_head chains
;
577 /* Video Streaming interfaces */
578 struct list_head streams
;
581 /* Status Interrupt Endpoint */
582 struct usb_host_endpoint
*int_ep
;
585 struct input_dev
*input
;
589 enum uvc_handle_state
{
590 UVC_HANDLE_PASSIVE
= 0,
591 UVC_HANDLE_ACTIVE
= 1,
596 struct uvc_video_chain
*chain
;
597 struct uvc_streaming
*stream
;
598 enum uvc_handle_state state
;
602 struct usb_driver driver
;
605 /* ------------------------------------------------------------------------
606 * Debugging, printing and logging
609 #define UVC_TRACE_PROBE (1 << 0)
610 #define UVC_TRACE_DESCR (1 << 1)
611 #define UVC_TRACE_CONTROL (1 << 2)
612 #define UVC_TRACE_FORMAT (1 << 3)
613 #define UVC_TRACE_CAPTURE (1 << 4)
614 #define UVC_TRACE_CALLS (1 << 5)
615 #define UVC_TRACE_FRAME (1 << 7)
616 #define UVC_TRACE_SUSPEND (1 << 8)
617 #define UVC_TRACE_STATUS (1 << 9)
618 #define UVC_TRACE_VIDEO (1 << 10)
619 #define UVC_TRACE_STATS (1 << 11)
620 #define UVC_TRACE_CLOCK (1 << 12)
622 #define UVC_WARN_MINMAX 0
623 #define UVC_WARN_PROBE_DEF 1
624 #define UVC_WARN_XU_GET_RES 2
626 extern unsigned int uvc_clock_param
;
627 extern unsigned int uvc_no_drop_param
;
628 extern unsigned int uvc_trace_param
;
629 extern unsigned int uvc_timeout_param
;
630 extern unsigned int uvc_hw_timestamps_param
;
632 #define uvc_trace(flag, msg...) \
634 if (uvc_trace_param & flag) \
635 printk(KERN_DEBUG "uvcvideo: " msg); \
638 #define uvc_warn_once(dev, warn, msg...) \
640 if (!test_and_set_bit(warn, &dev->warnings)) \
641 printk(KERN_INFO "uvcvideo: " msg); \
644 #define uvc_printk(level, msg...) \
645 printk(level "uvcvideo: " msg)
647 /* --------------------------------------------------------------------------
648 * Internal functions.
652 extern struct uvc_driver uvc_driver
;
654 extern struct uvc_entity
*uvc_entity_by_id(struct uvc_device
*dev
, int id
);
656 /* Video buffers queue management. */
657 extern int uvc_queue_init(struct uvc_video_queue
*queue
,
658 enum v4l2_buf_type type
, int drop_corrupted
);
659 extern void uvc_queue_release(struct uvc_video_queue
*queue
);
660 extern int uvc_request_buffers(struct uvc_video_queue
*queue
,
661 struct v4l2_requestbuffers
*rb
);
662 extern int uvc_query_buffer(struct uvc_video_queue
*queue
,
663 struct v4l2_buffer
*v4l2_buf
);
664 extern int uvc_create_buffers(struct uvc_video_queue
*queue
,
665 struct v4l2_create_buffers
*v4l2_cb
);
666 extern int uvc_queue_buffer(struct uvc_video_queue
*queue
,
667 struct v4l2_buffer
*v4l2_buf
);
668 extern int uvc_export_buffer(struct uvc_video_queue
*queue
,
669 struct v4l2_exportbuffer
*exp
);
670 extern int uvc_dequeue_buffer(struct uvc_video_queue
*queue
,
671 struct v4l2_buffer
*v4l2_buf
, int nonblocking
);
672 extern int uvc_queue_streamon(struct uvc_video_queue
*queue
,
673 enum v4l2_buf_type type
);
674 extern int uvc_queue_streamoff(struct uvc_video_queue
*queue
,
675 enum v4l2_buf_type type
);
676 extern void uvc_queue_cancel(struct uvc_video_queue
*queue
, int disconnect
);
677 extern struct uvc_buffer
*uvc_queue_next_buffer(struct uvc_video_queue
*queue
,
678 struct uvc_buffer
*buf
);
679 extern int uvc_queue_mmap(struct uvc_video_queue
*queue
,
680 struct vm_area_struct
*vma
);
681 extern unsigned int uvc_queue_poll(struct uvc_video_queue
*queue
,
682 struct file
*file
, poll_table
*wait
);
684 extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue
*queue
,
685 unsigned long pgoff
);
687 extern int uvc_queue_allocated(struct uvc_video_queue
*queue
);
688 static inline int uvc_queue_streaming(struct uvc_video_queue
*queue
)
690 return vb2_is_streaming(&queue
->queue
);
694 extern const struct v4l2_ioctl_ops uvc_ioctl_ops
;
695 extern const struct v4l2_file_operations uvc_fops
;
697 /* Media controller */
698 extern int uvc_mc_register_entities(struct uvc_video_chain
*chain
);
699 extern void uvc_mc_cleanup_entity(struct uvc_entity
*entity
);
702 extern int uvc_video_init(struct uvc_streaming
*stream
);
703 extern int uvc_video_suspend(struct uvc_streaming
*stream
);
704 extern int uvc_video_resume(struct uvc_streaming
*stream
, int reset
);
705 extern int uvc_video_enable(struct uvc_streaming
*stream
, int enable
);
706 extern int uvc_probe_video(struct uvc_streaming
*stream
,
707 struct uvc_streaming_control
*probe
);
708 extern int uvc_query_ctrl(struct uvc_device
*dev
, __u8 query
, __u8 unit
,
709 __u8 intfnum
, __u8 cs
, void *data
, __u16 size
);
710 void uvc_video_clock_update(struct uvc_streaming
*stream
,
711 struct vb2_v4l2_buffer
*vbuf
,
712 struct uvc_buffer
*buf
);
715 extern int uvc_status_init(struct uvc_device
*dev
);
716 extern void uvc_status_cleanup(struct uvc_device
*dev
);
717 extern int uvc_status_start(struct uvc_device
*dev
, gfp_t flags
);
718 extern void uvc_status_stop(struct uvc_device
*dev
);
721 extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops
;
723 extern int uvc_query_v4l2_ctrl(struct uvc_video_chain
*chain
,
724 struct v4l2_queryctrl
*v4l2_ctrl
);
725 extern int uvc_query_v4l2_menu(struct uvc_video_chain
*chain
,
726 struct v4l2_querymenu
*query_menu
);
728 extern int uvc_ctrl_add_mapping(struct uvc_video_chain
*chain
,
729 const struct uvc_control_mapping
*mapping
);
730 extern int uvc_ctrl_init_device(struct uvc_device
*dev
);
731 extern void uvc_ctrl_cleanup_device(struct uvc_device
*dev
);
732 extern int uvc_ctrl_restore_values(struct uvc_device
*dev
);
734 extern int uvc_ctrl_begin(struct uvc_video_chain
*chain
);
735 extern int __uvc_ctrl_commit(struct uvc_fh
*handle
, int rollback
,
736 const struct v4l2_ext_control
*xctrls
,
737 unsigned int xctrls_count
);
738 static inline int uvc_ctrl_commit(struct uvc_fh
*handle
,
739 const struct v4l2_ext_control
*xctrls
,
740 unsigned int xctrls_count
)
742 return __uvc_ctrl_commit(handle
, 0, xctrls
, xctrls_count
);
744 static inline int uvc_ctrl_rollback(struct uvc_fh
*handle
)
746 return __uvc_ctrl_commit(handle
, 1, NULL
, 0);
749 extern int uvc_ctrl_get(struct uvc_video_chain
*chain
,
750 struct v4l2_ext_control
*xctrl
);
751 extern int uvc_ctrl_set(struct uvc_video_chain
*chain
,
752 struct v4l2_ext_control
*xctrl
);
754 extern int uvc_xu_ctrl_query(struct uvc_video_chain
*chain
,
755 struct uvc_xu_control_query
*xqry
);
757 /* Utility functions */
758 extern void uvc_simplify_fraction(uint32_t *numerator
, uint32_t *denominator
,
759 unsigned int n_terms
, unsigned int threshold
);
760 extern uint32_t uvc_fraction_to_interval(uint32_t numerator
,
761 uint32_t denominator
);
762 extern struct usb_host_endpoint
*uvc_find_endpoint(
763 struct usb_host_interface
*alts
, __u8 epaddr
);
766 void uvc_video_decode_isight(struct urb
*urb
, struct uvc_streaming
*stream
,
767 struct uvc_buffer
*buf
);
769 /* debugfs and statistics */
770 void uvc_debugfs_init(void);
771 void uvc_debugfs_cleanup(void);
772 void uvc_debugfs_init_stream(struct uvc_streaming
*stream
);
773 void uvc_debugfs_cleanup_stream(struct uvc_streaming
*stream
);
775 size_t uvc_video_stats_dump(struct uvc_streaming
*stream
, char *buf
,