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 78 /* Format flags */ 79 #define UVC_FMT_FLAG_COMPRESSED 0x00000001 80 #define UVC_FMT_FLAG_STREAM 0x00000002 81 82 /* ------------------------------------------------------------------------ 83 * Structures. 84 */ 85 86 struct gpio_desc; 87 struct sg_table; 88 struct uvc_device; 89 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 uvc_control_info. */ 137 u8 dirty:1, 138 loaded:1, 139 modified:1, 140 cached:1, 141 initialized:1; 142 143 u8 *uvc_data; 144 145 struct uvc_fh *handle; /* File handle that last changed the control. */ 146 }; 147 148 /* 149 * The term 'entity' refers to both UVC units and UVC terminals. 150 * 151 * The type field is either the terminal type (wTerminalType in the terminal 152 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). 153 * As the bDescriptorSubtype field is one byte long, the type value will 154 * always have a null MSB for units. All terminal types defined by the UVC 155 * specification have a non-null MSB, so it is safe to use the MSB to 156 * differentiate between units and terminals as long as the descriptor parsing 157 * code makes sure terminal types have a non-null MSB. 158 * 159 * For terminals, the type's most significant bit stores the terminal 160 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should 161 * always be accessed with the UVC_ENTITY_* macros and never directly. 162 */ 163 164 #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) 165 166 struct uvc_entity { 167 struct list_head list; /* Entity as part of a UVC device. */ 168 struct list_head chain; /* Entity as part of a video device chain. */ 169 unsigned int flags; 170 171 /* 172 * Entities exposed by the UVC device use IDs 0-255, extra entities 173 * implemented by the driver (such as the GPIO entity) use IDs 256 and 174 * up. 175 */ 176 u16 id; 177 u16 type; 178 char name[64]; 179 u8 guid[16]; 180 181 /* Media controller-related fields. */ 182 struct video_device *vdev; 183 struct v4l2_subdev subdev; 184 unsigned int num_pads; 185 unsigned int num_links; 186 struct media_pad *pads; 187 188 union { 189 struct { 190 u16 wObjectiveFocalLengthMin; 191 u16 wObjectiveFocalLengthMax; 192 u16 wOcularFocalLength; 193 u8 bControlSize; 194 u8 *bmControls; 195 } camera; 196 197 struct { 198 u8 bControlSize; 199 u8 *bmControls; 200 u8 bTransportModeSize; 201 u8 *bmTransportModes; 202 } media; 203 204 struct { 205 } output; 206 207 struct { 208 u16 wMaxMultiplier; 209 u8 bControlSize; 210 u8 *bmControls; 211 u8 bmVideoStandards; 212 } processing; 213 214 struct { 215 } selector; 216 217 struct { 218 u8 bNumControls; 219 u8 bControlSize; 220 u8 *bmControls; 221 u8 *bmControlsType; 222 } extension; 223 224 struct { 225 u8 bControlSize; 226 u8 *bmControls; 227 struct gpio_desc *gpio_privacy; 228 int irq; 229 } gpio; 230 }; 231 232 u8 bNrInPins; 233 u8 *baSourceID; 234 235 int (*get_info)(struct uvc_device *dev, struct uvc_entity *entity, 236 u8 cs, u8 *caps); 237 int (*get_cur)(struct uvc_device *dev, struct uvc_entity *entity, 238 u8 cs, void *data, u16 size); 239 240 unsigned int ncontrols; 241 struct uvc_control *controls; 242 }; 243 244 struct uvc_frame { 245 u8 bFrameIndex; 246 u8 bmCapabilities; 247 u16 wWidth; 248 u16 wHeight; 249 u32 dwMinBitRate; 250 u32 dwMaxBitRate; 251 u32 dwMaxVideoFrameBufferSize; 252 u8 bFrameIntervalType; 253 u32 dwDefaultFrameInterval; 254 u32 *dwFrameInterval; 255 }; 256 257 struct uvc_format { 258 u8 type; 259 u8 index; 260 u8 bpp; 261 enum v4l2_colorspace colorspace; 262 enum v4l2_xfer_func xfer_func; 263 enum v4l2_ycbcr_encoding ycbcr_enc; 264 u32 fcc; 265 u32 flags; 266 267 char name[32]; 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 10240 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 /* 451 * Protect access to ctrl, cur_format, cur_frame and hardware video 452 * probe control. 453 */ 454 struct mutex mutex; 455 456 /* Buffers queue. */ 457 unsigned int frozen : 1; 458 struct uvc_video_queue queue; 459 struct workqueue_struct *async_wq; 460 void (*decode)(struct uvc_urb *uvc_urb, struct uvc_buffer *buf, 461 struct uvc_buffer *meta_buf); 462 463 struct { 464 struct video_device vdev; 465 struct uvc_video_queue queue; 466 u32 format; 467 } meta; 468 469 /* Context data used by the bulk completion handler. */ 470 struct { 471 u8 header[256]; 472 unsigned int header_size; 473 int skip_payload; 474 u32 payload_size; 475 u32 max_payload_size; 476 } bulk; 477 478 struct uvc_urb uvc_urb[UVC_URBS]; 479 unsigned int urb_size; 480 481 u32 sequence; 482 u8 last_fid; 483 484 /* debugfs */ 485 struct dentry *debugfs_dir; 486 struct { 487 struct uvc_stats_frame frame; 488 struct uvc_stats_stream stream; 489 } stats; 490 491 /* Timestamps support. */ 492 struct uvc_clock { 493 struct uvc_clock_sample { 494 u32 dev_stc; 495 u16 dev_sof; 496 u16 host_sof; 497 ktime_t host_time; 498 } *samples; 499 500 unsigned int head; 501 unsigned int count; 502 unsigned int size; 503 504 u16 last_sof; 505 u16 sof_offset; 506 507 u8 last_scr[6]; 508 509 spinlock_t lock; 510 } clock; 511 }; 512 513 #define for_each_uvc_urb(uvc_urb, uvc_streaming) \ 514 for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \ 515 (uvc_urb) < &(uvc_streaming)->uvc_urb[UVC_URBS]; \ 516 ++(uvc_urb)) 517 518 static inline u32 uvc_urb_index(const struct uvc_urb *uvc_urb) 519 { 520 return uvc_urb - &uvc_urb->stream->uvc_urb[0]; 521 } 522 523 struct uvc_device_info { 524 u32 quirks; 525 u32 meta_format; 526 u16 uvc_version; 527 const struct uvc_control_mapping **mappings; 528 }; 529 530 struct uvc_device { 531 struct usb_device *udev; 532 struct usb_interface *intf; 533 unsigned long warnings; 534 u32 quirks; 535 int intfnum; 536 char name[32]; 537 538 const struct uvc_device_info *info; 539 540 struct mutex lock; /* Protects users */ 541 unsigned int users; 542 atomic_t nmappings; 543 544 /* Video control interface */ 545 #ifdef CONFIG_MEDIA_CONTROLLER 546 struct media_device mdev; 547 #endif 548 struct v4l2_device vdev; 549 u16 uvc_version; 550 u32 clock_frequency; 551 552 struct list_head entities; 553 struct list_head chains; 554 555 /* Video Streaming interfaces */ 556 struct list_head streams; 557 struct kref ref; 558 559 /* Status Interrupt Endpoint */ 560 struct usb_host_endpoint *int_ep; 561 struct urb *int_urb; 562 u8 *status; 563 struct input_dev *input; 564 char input_phys[64]; 565 566 struct uvc_ctrl_work { 567 struct work_struct work; 568 struct urb *urb; 569 struct uvc_video_chain *chain; 570 struct uvc_control *ctrl; 571 const void *data; 572 } async_ctrl; 573 574 struct uvc_entity *gpio_unit; 575 }; 576 577 enum uvc_handle_state { 578 UVC_HANDLE_PASSIVE = 0, 579 UVC_HANDLE_ACTIVE = 1, 580 }; 581 582 struct uvc_fh { 583 struct v4l2_fh vfh; 584 struct uvc_video_chain *chain; 585 struct uvc_streaming *stream; 586 enum uvc_handle_state state; 587 }; 588 589 struct uvc_driver { 590 struct usb_driver driver; 591 }; 592 593 /* ------------------------------------------------------------------------ 594 * Debugging, printing and logging 595 */ 596 597 #define UVC_DBG_PROBE (1 << 0) 598 #define UVC_DBG_DESCR (1 << 1) 599 #define UVC_DBG_CONTROL (1 << 2) 600 #define UVC_DBG_FORMAT (1 << 3) 601 #define UVC_DBG_CAPTURE (1 << 4) 602 #define UVC_DBG_CALLS (1 << 5) 603 #define UVC_DBG_FRAME (1 << 7) 604 #define UVC_DBG_SUSPEND (1 << 8) 605 #define UVC_DBG_STATUS (1 << 9) 606 #define UVC_DBG_VIDEO (1 << 10) 607 #define UVC_DBG_STATS (1 << 11) 608 #define UVC_DBG_CLOCK (1 << 12) 609 610 #define UVC_WARN_MINMAX 0 611 #define UVC_WARN_PROBE_DEF 1 612 #define UVC_WARN_XU_GET_RES 2 613 614 extern unsigned int uvc_clock_param; 615 extern unsigned int uvc_no_drop_param; 616 extern unsigned int uvc_dbg_param; 617 extern unsigned int uvc_timeout_param; 618 extern unsigned int uvc_hw_timestamps_param; 619 620 #define uvc_dbg(_dev, flag, fmt, ...) \ 621 do { \ 622 if (uvc_dbg_param & UVC_DBG_##flag) \ 623 dev_printk(KERN_DEBUG, &(_dev)->udev->dev, fmt, \ 624 ##__VA_ARGS__); \ 625 } while (0) 626 627 #define uvc_dbg_cont(flag, fmt, ...) \ 628 do { \ 629 if (uvc_dbg_param & UVC_DBG_##flag) \ 630 pr_cont(fmt, ##__VA_ARGS__); \ 631 } while (0) 632 633 #define uvc_warn_once(_dev, warn, fmt, ...) \ 634 do { \ 635 if (!test_and_set_bit(warn, &(_dev)->warnings)) \ 636 dev_info(&(_dev)->udev->dev, fmt, ##__VA_ARGS__); \ 637 } while (0) 638 639 /* -------------------------------------------------------------------------- 640 * Internal functions. 641 */ 642 643 /* Core driver */ 644 extern struct uvc_driver uvc_driver; 645 646 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); 647 648 /* Video buffers queue management. */ 649 int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, 650 int drop_corrupted); 651 void uvc_queue_release(struct uvc_video_queue *queue); 652 int uvc_request_buffers(struct uvc_video_queue *queue, 653 struct v4l2_requestbuffers *rb); 654 int uvc_query_buffer(struct uvc_video_queue *queue, 655 struct v4l2_buffer *v4l2_buf); 656 int uvc_create_buffers(struct uvc_video_queue *queue, 657 struct v4l2_create_buffers *v4l2_cb); 658 int uvc_queue_buffer(struct uvc_video_queue *queue, 659 struct media_device *mdev, 660 struct v4l2_buffer *v4l2_buf); 661 int uvc_export_buffer(struct uvc_video_queue *queue, 662 struct v4l2_exportbuffer *exp); 663 int uvc_dequeue_buffer(struct uvc_video_queue *queue, 664 struct v4l2_buffer *v4l2_buf, int nonblocking); 665 int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type); 666 int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type); 667 void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); 668 struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, 669 struct uvc_buffer *buf); 670 struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue); 671 void uvc_queue_buffer_release(struct uvc_buffer *buf); 672 int uvc_queue_mmap(struct uvc_video_queue *queue, 673 struct vm_area_struct *vma); 674 __poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, 675 poll_table *wait); 676 #ifndef CONFIG_MMU 677 unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, 678 unsigned long pgoff); 679 #endif 680 int uvc_queue_allocated(struct uvc_video_queue *queue); 681 static inline int uvc_queue_streaming(struct uvc_video_queue *queue) 682 { 683 return vb2_is_streaming(&queue->queue); 684 } 685 686 static inline struct uvc_streaming * 687 uvc_queue_to_stream(struct uvc_video_queue *queue) 688 { 689 return container_of(queue, struct uvc_streaming, queue); 690 } 691 692 /* V4L2 interface */ 693 extern const struct v4l2_ioctl_ops uvc_ioctl_ops; 694 extern const struct v4l2_file_operations uvc_fops; 695 696 /* Media controller */ 697 int uvc_mc_register_entities(struct uvc_video_chain *chain); 698 void uvc_mc_cleanup_entity(struct uvc_entity *entity); 699 700 /* Video */ 701 int uvc_video_init(struct uvc_streaming *stream); 702 int uvc_video_suspend(struct uvc_streaming *stream); 703 int uvc_video_resume(struct uvc_streaming *stream, int reset); 704 int uvc_video_start_streaming(struct uvc_streaming *stream); 705 void uvc_video_stop_streaming(struct uvc_streaming *stream); 706 int uvc_probe_video(struct uvc_streaming *stream, 707 struct uvc_streaming_control *probe); 708 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); 713 int uvc_meta_register(struct uvc_streaming *stream); 714 715 int uvc_register_video_device(struct uvc_device *dev, 716 struct uvc_streaming *stream, 717 struct video_device *vdev, 718 struct uvc_video_queue *queue, 719 enum v4l2_buf_type type, 720 const struct v4l2_file_operations *fops, 721 const struct v4l2_ioctl_ops *ioctl_ops); 722 723 /* Status */ 724 int uvc_status_init(struct uvc_device *dev); 725 void uvc_status_unregister(struct uvc_device *dev); 726 void uvc_status_cleanup(struct uvc_device *dev); 727 int uvc_status_start(struct uvc_device *dev, gfp_t flags); 728 void uvc_status_stop(struct uvc_device *dev); 729 730 /* Controls */ 731 extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; 732 733 int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 734 struct v4l2_queryctrl *v4l2_ctrl); 735 int uvc_query_v4l2_menu(struct uvc_video_chain *chain, 736 struct v4l2_querymenu *query_menu); 737 738 int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, 739 const struct uvc_control_mapping *mapping); 740 int uvc_ctrl_init_device(struct uvc_device *dev); 741 void uvc_ctrl_cleanup_device(struct uvc_device *dev); 742 int uvc_ctrl_restore_values(struct uvc_device *dev); 743 bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain, 744 struct uvc_control *ctrl, const u8 *data); 745 void uvc_ctrl_status_event(struct uvc_video_chain *chain, 746 struct uvc_control *ctrl, const u8 *data); 747 748 int uvc_ctrl_begin(struct uvc_video_chain *chain); 749 int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, 750 struct v4l2_ext_controls *ctrls); 751 static inline int uvc_ctrl_commit(struct uvc_fh *handle, 752 struct v4l2_ext_controls *ctrls) 753 { 754 return __uvc_ctrl_commit(handle, 0, ctrls); 755 } 756 static inline int uvc_ctrl_rollback(struct uvc_fh *handle) 757 { 758 return __uvc_ctrl_commit(handle, 1, NULL); 759 } 760 761 int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); 762 int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); 763 int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, 764 bool read); 765 766 int uvc_xu_ctrl_query(struct uvc_video_chain *chain, 767 struct uvc_xu_control_query *xqry); 768 769 /* Utility functions */ 770 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, 771 u8 epaddr); 772 u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep); 773 774 /* Quirks support */ 775 void uvc_video_decode_isight(struct uvc_urb *uvc_urb, 776 struct uvc_buffer *buf, 777 struct uvc_buffer *meta_buf); 778 779 /* debugfs and statistics */ 780 void uvc_debugfs_init(void); 781 void uvc_debugfs_cleanup(void); 782 void uvc_debugfs_init_stream(struct uvc_streaming *stream); 783 void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream); 784 785 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, 786 size_t size); 787 788 #endif 789