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 77 /* Format flags */ 78 #define UVC_FMT_FLAG_COMPRESSED 0x00000001 79 #define UVC_FMT_FLAG_STREAM 0x00000002 80 81 /* ------------------------------------------------------------------------ 82 * Structures. 83 */ 84 85 struct gpio_desc; 86 struct sg_table; 87 struct uvc_device; 88 89 /* 90 * TODO: Put the most frequently accessed fields at the beginning of 91 * structures to maximize cache efficiency. 92 */ 93 struct uvc_control_info { 94 struct list_head mappings; 95 96 u8 entity[16]; 97 u8 index; /* Bit index in bmControls */ 98 u8 selector; 99 100 u16 size; 101 u32 flags; 102 }; 103 104 struct uvc_control_mapping { 105 struct list_head list; 106 struct list_head ev_subs; 107 108 u32 id; 109 char *name; 110 u8 entity[16]; 111 u8 selector; 112 113 u8 size; 114 u8 offset; 115 enum v4l2_ctrl_type v4l2_type; 116 u32 data_type; 117 118 const u32 *menu_mapping; 119 const char (*menu_names)[UVC_MENU_NAME_LEN]; 120 unsigned long menu_mask; 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 unsigned int nframes; 268 struct uvc_frame *frame; 269 }; 270 271 struct uvc_streaming_header { 272 u8 bNumFormats; 273 u8 bEndpointAddress; 274 u8 bTerminalLink; 275 u8 bControlSize; 276 u8 *bmaControls; 277 /* The following fields are used by input headers only. */ 278 u8 bmInfo; 279 u8 bStillCaptureMethod; 280 u8 bTriggerSupport; 281 u8 bTriggerUsage; 282 }; 283 284 enum uvc_buffer_state { 285 UVC_BUF_STATE_IDLE = 0, 286 UVC_BUF_STATE_QUEUED = 1, 287 UVC_BUF_STATE_ACTIVE = 2, 288 UVC_BUF_STATE_READY = 3, 289 UVC_BUF_STATE_DONE = 4, 290 UVC_BUF_STATE_ERROR = 5, 291 }; 292 293 struct uvc_buffer { 294 struct vb2_v4l2_buffer buf; 295 struct list_head queue; 296 297 enum uvc_buffer_state state; 298 unsigned int error; 299 300 void *mem; 301 unsigned int length; 302 unsigned int bytesused; 303 304 u32 pts; 305 306 /* Asynchronous buffer handling. */ 307 struct kref ref; 308 }; 309 310 #define UVC_QUEUE_DISCONNECTED (1 << 0) 311 #define UVC_QUEUE_DROP_CORRUPTED (1 << 1) 312 313 struct uvc_video_queue { 314 struct vb2_queue queue; 315 struct mutex mutex; /* Protects queue */ 316 317 unsigned int flags; 318 unsigned int buf_used; 319 320 spinlock_t irqlock; /* Protects irqqueue */ 321 struct list_head irqqueue; 322 }; 323 324 struct uvc_video_chain { 325 struct uvc_device *dev; 326 struct list_head list; 327 328 struct list_head entities; /* All entities */ 329 struct uvc_entity *processing; /* Processing unit */ 330 struct uvc_entity *selector; /* Selector unit */ 331 332 struct mutex ctrl_mutex; /* Protects ctrl.info */ 333 334 struct v4l2_prio_state prio; /* V4L2 priority state */ 335 u32 caps; /* V4L2 chain-wide caps */ 336 u8 ctrl_class_bitmap; /* Bitmap of valid classes */ 337 }; 338 339 struct uvc_stats_frame { 340 unsigned int size; /* Number of bytes captured */ 341 unsigned int first_data; /* Index of the first non-empty packet */ 342 343 unsigned int nb_packets; /* Number of packets */ 344 unsigned int nb_empty; /* Number of empty packets */ 345 unsigned int nb_invalid; /* Number of packets with an invalid header */ 346 unsigned int nb_errors; /* Number of packets with the error bit set */ 347 348 unsigned int nb_pts; /* Number of packets with a PTS timestamp */ 349 unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */ 350 unsigned int last_pts_diff; /* Index of the last PTS difference */ 351 bool has_initial_pts; /* Whether the first non-empty packet has a PTS */ 352 bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */ 353 u32 pts; /* PTS of the last packet */ 354 355 unsigned int nb_scr; /* Number of packets with a SCR timestamp */ 356 unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */ 357 u16 scr_sof; /* SCR.SOF of the last packet */ 358 u32 scr_stc; /* SCR.STC of the last packet */ 359 }; 360 361 struct uvc_stats_stream { 362 ktime_t start_ts; /* Stream start timestamp */ 363 ktime_t stop_ts; /* Stream stop timestamp */ 364 365 unsigned int nb_frames; /* Number of frames */ 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_constant; /* Number of frames with constant PTS */ 373 unsigned int nb_pts_early; /* Number of frames with early PTS */ 374 unsigned int nb_pts_initial; /* Number of frames with initial PTS */ 375 376 unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */ 377 unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */ 378 unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */ 379 unsigned int scr_sof; /* STC.SOF of the last packet */ 380 unsigned int min_sof; /* Minimum STC.SOF value */ 381 unsigned int max_sof; /* Maximum STC.SOF value */ 382 }; 383 384 #define UVC_METADATA_BUF_SIZE 10240 385 386 /** 387 * struct uvc_copy_op: Context structure to schedule asynchronous memcpy 388 * 389 * @buf: active buf object for this operation 390 * @dst: copy destination address 391 * @src: copy source address 392 * @len: copy length 393 */ 394 struct uvc_copy_op { 395 struct uvc_buffer *buf; 396 void *dst; 397 const __u8 *src; 398 size_t len; 399 }; 400 401 /** 402 * struct uvc_urb - URB context management structure 403 * 404 * @urb: the URB described by this context structure 405 * @stream: UVC streaming context 406 * @buffer: memory storage for the URB 407 * @dma: Allocated DMA handle 408 * @sgt: sgt_table with the urb locations in memory 409 * @async_operations: counter to indicate the number of copy operations 410 * @copy_operations: work descriptors for asynchronous copy operations 411 * @work: work queue entry for asynchronous decode 412 */ 413 struct uvc_urb { 414 struct urb *urb; 415 struct uvc_streaming *stream; 416 417 char *buffer; 418 dma_addr_t dma; 419 struct sg_table *sgt; 420 421 unsigned int async_operations; 422 struct uvc_copy_op copy_operations[UVC_MAX_PACKETS]; 423 struct work_struct work; 424 }; 425 426 struct uvc_streaming { 427 struct list_head list; 428 struct uvc_device *dev; 429 struct video_device vdev; 430 struct uvc_video_chain *chain; 431 atomic_t active; 432 433 struct usb_interface *intf; 434 int intfnum; 435 u16 maxpsize; 436 437 struct uvc_streaming_header header; 438 enum v4l2_buf_type type; 439 440 unsigned int nformats; 441 struct uvc_format *format; 442 443 struct uvc_streaming_control ctrl; 444 struct uvc_format *def_format; 445 struct uvc_format *cur_format; 446 struct uvc_frame *cur_frame; 447 448 /* 449 * Protect access to ctrl, cur_format, cur_frame and hardware video 450 * probe control. 451 */ 452 struct mutex mutex; 453 454 /* Buffers queue. */ 455 unsigned int frozen : 1; 456 struct uvc_video_queue queue; 457 struct workqueue_struct *async_wq; 458 void (*decode)(struct uvc_urb *uvc_urb, struct uvc_buffer *buf, 459 struct uvc_buffer *meta_buf); 460 461 struct { 462 struct video_device vdev; 463 struct uvc_video_queue queue; 464 u32 format; 465 } meta; 466 467 /* Context data used by the bulk completion handler. */ 468 struct { 469 u8 header[256]; 470 unsigned int header_size; 471 int skip_payload; 472 u32 payload_size; 473 u32 max_payload_size; 474 } bulk; 475 476 struct uvc_urb uvc_urb[UVC_URBS]; 477 unsigned int urb_size; 478 479 u32 sequence; 480 u8 last_fid; 481 482 /* debugfs */ 483 struct dentry *debugfs_dir; 484 struct { 485 struct uvc_stats_frame frame; 486 struct uvc_stats_stream stream; 487 } stats; 488 489 /* Timestamps support. */ 490 struct uvc_clock { 491 struct uvc_clock_sample { 492 u32 dev_stc; 493 u16 dev_sof; 494 u16 host_sof; 495 ktime_t host_time; 496 } *samples; 497 498 unsigned int head; 499 unsigned int count; 500 unsigned int size; 501 502 u16 last_sof; 503 u16 sof_offset; 504 505 u8 last_scr[6]; 506 507 spinlock_t lock; 508 } clock; 509 }; 510 511 #define for_each_uvc_urb(uvc_urb, uvc_streaming) \ 512 for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \ 513 (uvc_urb) < &(uvc_streaming)->uvc_urb[UVC_URBS]; \ 514 ++(uvc_urb)) 515 516 static inline u32 uvc_urb_index(const struct uvc_urb *uvc_urb) 517 { 518 return uvc_urb - &uvc_urb->stream->uvc_urb[0]; 519 } 520 521 struct uvc_device_info { 522 u32 quirks; 523 u32 meta_format; 524 u16 uvc_version; 525 const struct uvc_control_mapping **mappings; 526 }; 527 528 struct uvc_status_streaming { 529 u8 button; 530 } __packed; 531 532 struct uvc_status_control { 533 u8 bSelector; 534 u8 bAttribute; 535 u8 bValue[11]; 536 } __packed; 537 538 struct uvc_status { 539 u8 bStatusType; 540 u8 bOriginator; 541 u8 bEvent; 542 union { 543 struct uvc_status_control control; 544 struct uvc_status_streaming streaming; 545 }; 546 } __packed; 547 548 struct uvc_device { 549 struct usb_device *udev; 550 struct usb_interface *intf; 551 unsigned long warnings; 552 u32 quirks; 553 int intfnum; 554 char name[32]; 555 556 const struct uvc_device_info *info; 557 558 struct mutex lock; /* Protects users */ 559 unsigned int users; 560 atomic_t nmappings; 561 562 /* Video control interface */ 563 #ifdef CONFIG_MEDIA_CONTROLLER 564 struct media_device mdev; 565 #endif 566 struct v4l2_device vdev; 567 u16 uvc_version; 568 u32 clock_frequency; 569 570 struct list_head entities; 571 struct list_head chains; 572 573 /* Video Streaming interfaces */ 574 struct list_head streams; 575 struct kref ref; 576 577 /* Status Interrupt Endpoint */ 578 struct usb_host_endpoint *int_ep; 579 struct urb *int_urb; 580 struct uvc_status *status; 581 bool flush_status; 582 583 struct input_dev *input; 584 char input_phys[64]; 585 586 struct uvc_ctrl_work { 587 struct work_struct work; 588 struct urb *urb; 589 struct uvc_video_chain *chain; 590 struct uvc_control *ctrl; 591 const void *data; 592 } async_ctrl; 593 594 struct uvc_entity *gpio_unit; 595 }; 596 597 enum uvc_handle_state { 598 UVC_HANDLE_PASSIVE = 0, 599 UVC_HANDLE_ACTIVE = 1, 600 }; 601 602 struct uvc_fh { 603 struct v4l2_fh vfh; 604 struct uvc_video_chain *chain; 605 struct uvc_streaming *stream; 606 enum uvc_handle_state state; 607 }; 608 609 struct uvc_driver { 610 struct usb_driver driver; 611 }; 612 613 /* ------------------------------------------------------------------------ 614 * Debugging, printing and logging 615 */ 616 617 #define UVC_DBG_PROBE (1 << 0) 618 #define UVC_DBG_DESCR (1 << 1) 619 #define UVC_DBG_CONTROL (1 << 2) 620 #define UVC_DBG_FORMAT (1 << 3) 621 #define UVC_DBG_CAPTURE (1 << 4) 622 #define UVC_DBG_CALLS (1 << 5) 623 #define UVC_DBG_FRAME (1 << 7) 624 #define UVC_DBG_SUSPEND (1 << 8) 625 #define UVC_DBG_STATUS (1 << 9) 626 #define UVC_DBG_VIDEO (1 << 10) 627 #define UVC_DBG_STATS (1 << 11) 628 #define UVC_DBG_CLOCK (1 << 12) 629 630 #define UVC_WARN_MINMAX 0 631 #define UVC_WARN_PROBE_DEF 1 632 #define UVC_WARN_XU_GET_RES 2 633 634 extern unsigned int uvc_clock_param; 635 extern unsigned int uvc_no_drop_param; 636 extern unsigned int uvc_dbg_param; 637 extern unsigned int uvc_timeout_param; 638 extern unsigned int uvc_hw_timestamps_param; 639 640 #define uvc_dbg(_dev, flag, fmt, ...) \ 641 do { \ 642 if (uvc_dbg_param & UVC_DBG_##flag) \ 643 dev_printk(KERN_DEBUG, &(_dev)->udev->dev, fmt, \ 644 ##__VA_ARGS__); \ 645 } while (0) 646 647 #define uvc_dbg_cont(flag, fmt, ...) \ 648 do { \ 649 if (uvc_dbg_param & UVC_DBG_##flag) \ 650 pr_cont(fmt, ##__VA_ARGS__); \ 651 } while (0) 652 653 #define uvc_warn_once(_dev, warn, fmt, ...) \ 654 do { \ 655 if (!test_and_set_bit(warn, &(_dev)->warnings)) \ 656 dev_info(&(_dev)->udev->dev, fmt, ##__VA_ARGS__); \ 657 } while (0) 658 659 /* -------------------------------------------------------------------------- 660 * Internal functions. 661 */ 662 663 /* Core driver */ 664 extern struct uvc_driver uvc_driver; 665 666 struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); 667 668 /* Video buffers queue management. */ 669 int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, 670 int drop_corrupted); 671 void uvc_queue_release(struct uvc_video_queue *queue); 672 int uvc_request_buffers(struct uvc_video_queue *queue, 673 struct v4l2_requestbuffers *rb); 674 int uvc_query_buffer(struct uvc_video_queue *queue, 675 struct v4l2_buffer *v4l2_buf); 676 int uvc_create_buffers(struct uvc_video_queue *queue, 677 struct v4l2_create_buffers *v4l2_cb); 678 int uvc_queue_buffer(struct uvc_video_queue *queue, 679 struct media_device *mdev, 680 struct v4l2_buffer *v4l2_buf); 681 int uvc_export_buffer(struct uvc_video_queue *queue, 682 struct v4l2_exportbuffer *exp); 683 int uvc_dequeue_buffer(struct uvc_video_queue *queue, 684 struct v4l2_buffer *v4l2_buf, int nonblocking); 685 int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type); 686 int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type); 687 void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); 688 struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, 689 struct uvc_buffer *buf); 690 struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue); 691 void uvc_queue_buffer_release(struct uvc_buffer *buf); 692 int uvc_queue_mmap(struct uvc_video_queue *queue, 693 struct vm_area_struct *vma); 694 __poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, 695 poll_table *wait); 696 #ifndef CONFIG_MMU 697 unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, 698 unsigned long pgoff); 699 #endif 700 int uvc_queue_allocated(struct uvc_video_queue *queue); 701 static inline int uvc_queue_streaming(struct uvc_video_queue *queue) 702 { 703 return vb2_is_streaming(&queue->queue); 704 } 705 706 static inline struct uvc_streaming * 707 uvc_queue_to_stream(struct uvc_video_queue *queue) 708 { 709 return container_of(queue, struct uvc_streaming, queue); 710 } 711 712 /* V4L2 interface */ 713 extern const struct v4l2_ioctl_ops uvc_ioctl_ops; 714 extern const struct v4l2_file_operations uvc_fops; 715 716 /* Media controller */ 717 int uvc_mc_register_entities(struct uvc_video_chain *chain); 718 void uvc_mc_cleanup_entity(struct uvc_entity *entity); 719 720 /* Video */ 721 int uvc_video_init(struct uvc_streaming *stream); 722 int uvc_video_suspend(struct uvc_streaming *stream); 723 int uvc_video_resume(struct uvc_streaming *stream, int reset); 724 int uvc_video_start_streaming(struct uvc_streaming *stream); 725 void uvc_video_stop_streaming(struct uvc_streaming *stream); 726 int uvc_probe_video(struct uvc_streaming *stream, 727 struct uvc_streaming_control *probe); 728 int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, 729 u8 intfnum, u8 cs, void *data, u16 size); 730 void uvc_video_clock_update(struct uvc_streaming *stream, 731 struct vb2_v4l2_buffer *vbuf, 732 struct uvc_buffer *buf); 733 int uvc_meta_register(struct uvc_streaming *stream); 734 735 int uvc_register_video_device(struct uvc_device *dev, 736 struct uvc_streaming *stream, 737 struct video_device *vdev, 738 struct uvc_video_queue *queue, 739 enum v4l2_buf_type type, 740 const struct v4l2_file_operations *fops, 741 const struct v4l2_ioctl_ops *ioctl_ops); 742 743 /* Status */ 744 int uvc_status_init(struct uvc_device *dev); 745 void uvc_status_unregister(struct uvc_device *dev); 746 void uvc_status_cleanup(struct uvc_device *dev); 747 int uvc_status_start(struct uvc_device *dev, gfp_t flags); 748 void uvc_status_stop(struct uvc_device *dev); 749 750 /* Controls */ 751 extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited; 752 extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11; 753 extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; 754 755 int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 756 struct v4l2_queryctrl *v4l2_ctrl); 757 int uvc_query_v4l2_menu(struct uvc_video_chain *chain, 758 struct v4l2_querymenu *query_menu); 759 760 int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, 761 const struct uvc_control_mapping *mapping); 762 int uvc_ctrl_init_device(struct uvc_device *dev); 763 void uvc_ctrl_cleanup_device(struct uvc_device *dev); 764 int uvc_ctrl_restore_values(struct uvc_device *dev); 765 bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain, 766 struct uvc_control *ctrl, const u8 *data); 767 void uvc_ctrl_status_event(struct uvc_video_chain *chain, 768 struct uvc_control *ctrl, const u8 *data); 769 770 int uvc_ctrl_begin(struct uvc_video_chain *chain); 771 int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, 772 struct v4l2_ext_controls *ctrls); 773 static inline int uvc_ctrl_commit(struct uvc_fh *handle, 774 struct v4l2_ext_controls *ctrls) 775 { 776 return __uvc_ctrl_commit(handle, 0, ctrls); 777 } 778 static inline int uvc_ctrl_rollback(struct uvc_fh *handle) 779 { 780 return __uvc_ctrl_commit(handle, 1, NULL); 781 } 782 783 int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); 784 int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); 785 int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, 786 const struct v4l2_ext_controls *ctrls, 787 unsigned long ioctl); 788 789 int uvc_xu_ctrl_query(struct uvc_video_chain *chain, 790 struct uvc_xu_control_query *xqry); 791 792 /* Utility functions */ 793 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, 794 u8 epaddr); 795 u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep); 796 797 /* Quirks support */ 798 void uvc_video_decode_isight(struct uvc_urb *uvc_urb, 799 struct uvc_buffer *buf, 800 struct uvc_buffer *meta_buf); 801 802 /* debugfs and statistics */ 803 void uvc_debugfs_init(void); 804 void uvc_debugfs_cleanup(void); 805 void uvc_debugfs_init_stream(struct uvc_streaming *stream); 806 void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream); 807 808 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, 809 size_t size); 810 811 #endif 812