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