1 #ifndef _USB_VIDEO_H_ 2 #define _USB_VIDEO_H_ 3 4 #ifndef __KERNEL__ 5 #error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead." 6 #endif /* __KERNEL__ */ 7 8 #include <linux/kernel.h> 9 #include <linux/poll.h> 10 #include <linux/usb.h> 11 #include <linux/usb/video.h> 12 #include <linux/uvcvideo.h> 13 #include <linux/videodev2.h> 14 #include <media/media-device.h> 15 #include <media/v4l2-device.h> 16 #include <media/v4l2-event.h> 17 #include <media/v4l2-fh.h> 18 #include <media/videobuf2-core.h> 19 20 /* -------------------------------------------------------------------------- 21 * UVC constants 22 */ 23 24 #define UVC_TERM_INPUT 0x0000 25 #define UVC_TERM_OUTPUT 0x8000 26 #define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000) 27 28 #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) 29 #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) 30 #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) 31 #define UVC_ENTITY_IS_ITERM(entity) \ 32 (UVC_ENTITY_IS_TERM(entity) && \ 33 ((entity)->type & 0x8000) == UVC_TERM_INPUT) 34 #define UVC_ENTITY_IS_OTERM(entity) \ 35 (UVC_ENTITY_IS_TERM(entity) && \ 36 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) 37 38 39 /* ------------------------------------------------------------------------ 40 * GUIDs 41 */ 42 #define UVC_GUID_UVC_CAMERA \ 43 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} 45 #define UVC_GUID_UVC_OUTPUT \ 46 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} 48 #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ 49 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} 51 #define UVC_GUID_UVC_PROCESSING \ 52 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} 54 #define UVC_GUID_UVC_SELECTOR \ 55 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} 57 58 #define UVC_GUID_FORMAT_MJPEG \ 59 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ 60 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 61 #define UVC_GUID_FORMAT_YUY2 \ 62 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 63 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 64 #define UVC_GUID_FORMAT_YUY2_ISIGHT \ 65 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 66 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71} 67 #define UVC_GUID_FORMAT_NV12 \ 68 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 69 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 70 #define UVC_GUID_FORMAT_YV12 \ 71 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 72 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 73 #define UVC_GUID_FORMAT_I420 \ 74 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 75 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 76 #define UVC_GUID_FORMAT_UYVY \ 77 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ 78 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 79 #define UVC_GUID_FORMAT_Y800 \ 80 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ 81 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 82 #define UVC_GUID_FORMAT_Y8 \ 83 { 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \ 84 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 85 #define UVC_GUID_FORMAT_Y10 \ 86 { 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \ 87 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 88 #define UVC_GUID_FORMAT_Y12 \ 89 { 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \ 90 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 91 #define UVC_GUID_FORMAT_Y16 \ 92 { 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ 93 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 94 #define UVC_GUID_FORMAT_BY8 \ 95 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ 96 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 97 #define UVC_GUID_FORMAT_BA81 \ 98 { 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \ 99 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 100 #define UVC_GUID_FORMAT_GBRG \ 101 { 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \ 102 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 103 #define UVC_GUID_FORMAT_GRBG \ 104 { 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \ 105 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 106 #define UVC_GUID_FORMAT_RGGB \ 107 { 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \ 108 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 109 #define UVC_GUID_FORMAT_RGBP \ 110 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ 111 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 112 #define UVC_GUID_FORMAT_M420 \ 113 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 114 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 115 116 #define UVC_GUID_FORMAT_H264 \ 117 { 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \ 118 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 119 120 /* ------------------------------------------------------------------------ 121 * Driver specific constants. 122 */ 123 124 #define DRIVER_VERSION "1.1.1" 125 126 /* Number of isochronous URBs. */ 127 #define UVC_URBS 5 128 /* Maximum number of packets per URB. */ 129 #define UVC_MAX_PACKETS 32 130 /* Maximum status buffer size in bytes of interrupt URB. */ 131 #define UVC_MAX_STATUS_SIZE 16 132 133 #define UVC_CTRL_CONTROL_TIMEOUT 300 134 #define UVC_CTRL_STREAMING_TIMEOUT 5000 135 136 /* Maximum allowed number of control mappings per device */ 137 #define UVC_MAX_CONTROL_MAPPINGS 1024 138 #define UVC_MAX_CONTROL_MENU_ENTRIES 32 139 140 /* Devices quirks */ 141 #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 142 #define UVC_QUIRK_PROBE_MINMAX 0x00000002 143 #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 144 #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 145 #define UVC_QUIRK_STREAM_NO_FID 0x00000010 146 #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 147 #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 148 #define UVC_QUIRK_PROBE_DEF 0x00000100 149 #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 150 #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 151 152 /* Format flags */ 153 #define UVC_FMT_FLAG_COMPRESSED 0x00000001 154 #define UVC_FMT_FLAG_STREAM 0x00000002 155 156 /* ------------------------------------------------------------------------ 157 * Structures. 158 */ 159 160 struct uvc_device; 161 162 /* TODO: Put the most frequently accessed fields at the beginning of 163 * structures to maximize cache efficiency. 164 */ 165 struct uvc_control_info { 166 struct list_head mappings; 167 168 __u8 entity[16]; 169 __u8 index; /* Bit index in bmControls */ 170 __u8 selector; 171 172 __u16 size; 173 __u32 flags; 174 }; 175 176 struct uvc_control_mapping { 177 struct list_head list; 178 struct list_head ev_subs; 179 180 __u32 id; 181 __u8 name[32]; 182 __u8 entity[16]; 183 __u8 selector; 184 185 __u8 size; 186 __u8 offset; 187 enum v4l2_ctrl_type v4l2_type; 188 __u32 data_type; 189 190 struct uvc_menu_info *menu_info; 191 __u32 menu_count; 192 193 __u32 master_id; 194 __s32 master_manual; 195 __u32 slave_ids[2]; 196 197 __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query, 198 const __u8 *data); 199 void (*set) (struct uvc_control_mapping *mapping, __s32 value, 200 __u8 *data); 201 }; 202 203 struct uvc_control { 204 struct uvc_entity *entity; 205 struct uvc_control_info info; 206 207 __u8 index; /* Used to match the uvc_control entry with a 208 uvc_control_info. */ 209 __u8 dirty:1, 210 loaded:1, 211 modified:1, 212 cached:1, 213 initialized:1; 214 215 __u8 *uvc_data; 216 }; 217 218 struct uvc_format_desc { 219 char *name; 220 __u8 guid[16]; 221 __u32 fcc; 222 }; 223 224 /* The term 'entity' refers to both UVC units and UVC terminals. 225 * 226 * The type field is either the terminal type (wTerminalType in the terminal 227 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). 228 * As the bDescriptorSubtype field is one byte long, the type value will 229 * always have a null MSB for units. All terminal types defined by the UVC 230 * specification have a non-null MSB, so it is safe to use the MSB to 231 * differentiate between units and terminals as long as the descriptor parsing 232 * code makes sure terminal types have a non-null MSB. 233 * 234 * For terminals, the type's most significant bit stores the terminal 235 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should 236 * always be accessed with the UVC_ENTITY_* macros and never directly. 237 */ 238 239 #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) 240 241 struct uvc_entity { 242 struct list_head list; /* Entity as part of a UVC device. */ 243 struct list_head chain; /* Entity as part of a video device 244 * chain. */ 245 unsigned int flags; 246 247 __u8 id; 248 __u16 type; 249 char name[64]; 250 251 /* Media controller-related fields. */ 252 struct video_device *vdev; 253 struct v4l2_subdev subdev; 254 unsigned int num_pads; 255 unsigned int num_links; 256 struct media_pad *pads; 257 258 union { 259 struct { 260 __u16 wObjectiveFocalLengthMin; 261 __u16 wObjectiveFocalLengthMax; 262 __u16 wOcularFocalLength; 263 __u8 bControlSize; 264 __u8 *bmControls; 265 } camera; 266 267 struct { 268 __u8 bControlSize; 269 __u8 *bmControls; 270 __u8 bTransportModeSize; 271 __u8 *bmTransportModes; 272 } media; 273 274 struct { 275 } output; 276 277 struct { 278 __u16 wMaxMultiplier; 279 __u8 bControlSize; 280 __u8 *bmControls; 281 __u8 bmVideoStandards; 282 } processing; 283 284 struct { 285 } selector; 286 287 struct { 288 __u8 guidExtensionCode[16]; 289 __u8 bNumControls; 290 __u8 bControlSize; 291 __u8 *bmControls; 292 __u8 *bmControlsType; 293 } extension; 294 }; 295 296 __u8 bNrInPins; 297 __u8 *baSourceID; 298 299 unsigned int ncontrols; 300 struct uvc_control *controls; 301 }; 302 303 struct uvc_frame { 304 __u8 bFrameIndex; 305 __u8 bmCapabilities; 306 __u16 wWidth; 307 __u16 wHeight; 308 __u32 dwMinBitRate; 309 __u32 dwMaxBitRate; 310 __u32 dwMaxVideoFrameBufferSize; 311 __u8 bFrameIntervalType; 312 __u32 dwDefaultFrameInterval; 313 __u32 *dwFrameInterval; 314 }; 315 316 struct uvc_format { 317 __u8 type; 318 __u8 index; 319 __u8 bpp; 320 __u8 colorspace; 321 __u32 fcc; 322 __u32 flags; 323 324 char name[32]; 325 326 unsigned int nframes; 327 struct uvc_frame *frame; 328 }; 329 330 struct uvc_streaming_header { 331 __u8 bNumFormats; 332 __u8 bEndpointAddress; 333 __u8 bTerminalLink; 334 __u8 bControlSize; 335 __u8 *bmaControls; 336 /* The following fields are used by input headers only. */ 337 __u8 bmInfo; 338 __u8 bStillCaptureMethod; 339 __u8 bTriggerSupport; 340 __u8 bTriggerUsage; 341 }; 342 343 enum uvc_buffer_state { 344 UVC_BUF_STATE_IDLE = 0, 345 UVC_BUF_STATE_QUEUED = 1, 346 UVC_BUF_STATE_ACTIVE = 2, 347 UVC_BUF_STATE_READY = 3, 348 UVC_BUF_STATE_DONE = 4, 349 UVC_BUF_STATE_ERROR = 5, 350 }; 351 352 struct uvc_buffer { 353 struct vb2_buffer buf; 354 struct list_head queue; 355 356 enum uvc_buffer_state state; 357 unsigned int error; 358 359 void *mem; 360 unsigned int length; 361 unsigned int bytesused; 362 363 u32 pts; 364 }; 365 366 #define UVC_QUEUE_DISCONNECTED (1 << 0) 367 #define UVC_QUEUE_DROP_CORRUPTED (1 << 1) 368 369 struct uvc_video_queue { 370 struct vb2_queue queue; 371 struct mutex mutex; /* Protects queue */ 372 373 unsigned int flags; 374 unsigned int buf_used; 375 376 spinlock_t irqlock; /* Protects irqqueue */ 377 struct list_head irqqueue; 378 }; 379 380 struct uvc_video_chain { 381 struct uvc_device *dev; 382 struct list_head list; 383 384 struct list_head entities; /* All entities */ 385 struct uvc_entity *processing; /* Processing unit */ 386 struct uvc_entity *selector; /* Selector unit */ 387 388 struct mutex ctrl_mutex; /* Protects ctrl.info */ 389 390 struct v4l2_prio_state prio; /* V4L2 priority state */ 391 u32 caps; /* V4L2 chain-wide caps */ 392 }; 393 394 struct uvc_stats_frame { 395 unsigned int size; /* Number of bytes captured */ 396 unsigned int first_data; /* Index of the first non-empty packet */ 397 398 unsigned int nb_packets; /* Number of packets */ 399 unsigned int nb_empty; /* Number of empty packets */ 400 unsigned int nb_invalid; /* Number of packets with an invalid header */ 401 unsigned int nb_errors; /* Number of packets with the error bit set */ 402 403 unsigned int nb_pts; /* Number of packets with a PTS timestamp */ 404 unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */ 405 unsigned int last_pts_diff; /* Index of the last PTS difference */ 406 bool has_initial_pts; /* Whether the first non-empty packet has a PTS */ 407 bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */ 408 u32 pts; /* PTS of the last packet */ 409 410 unsigned int nb_scr; /* Number of packets with a SCR timestamp */ 411 unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */ 412 u16 scr_sof; /* SCR.SOF of the last packet */ 413 u32 scr_stc; /* SCR.STC of the last packet */ 414 }; 415 416 struct uvc_stats_stream { 417 struct timespec start_ts; /* Stream start timestamp */ 418 struct timespec stop_ts; /* Stream stop timestamp */ 419 420 unsigned int nb_frames; /* Number of frames */ 421 422 unsigned int nb_packets; /* Number of packets */ 423 unsigned int nb_empty; /* Number of empty packets */ 424 unsigned int nb_invalid; /* Number of packets with an invalid header */ 425 unsigned int nb_errors; /* Number of packets with the error bit set */ 426 427 unsigned int nb_pts_constant; /* Number of frames with constant PTS */ 428 unsigned int nb_pts_early; /* Number of frames with early PTS */ 429 unsigned int nb_pts_initial; /* Number of frames with initial PTS */ 430 431 unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */ 432 unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */ 433 unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */ 434 unsigned int scr_sof; /* STC.SOF of the last packet */ 435 unsigned int min_sof; /* Minimum STC.SOF value */ 436 unsigned int max_sof; /* Maximum STC.SOF value */ 437 }; 438 439 struct uvc_streaming { 440 struct list_head list; 441 struct uvc_device *dev; 442 struct video_device *vdev; 443 struct uvc_video_chain *chain; 444 atomic_t active; 445 446 struct usb_interface *intf; 447 int intfnum; 448 __u16 maxpsize; 449 450 struct uvc_streaming_header header; 451 enum v4l2_buf_type type; 452 453 unsigned int nformats; 454 struct uvc_format *format; 455 456 struct uvc_streaming_control ctrl; 457 struct uvc_format *def_format; 458 struct uvc_format *cur_format; 459 struct uvc_frame *cur_frame; 460 size_t frame_size; 461 462 /* Protect access to ctrl, cur_format, cur_frame and hardware video 463 * probe control. 464 */ 465 struct mutex mutex; 466 467 /* Buffers queue. */ 468 unsigned int frozen : 1; 469 struct uvc_video_queue queue; 470 void (*decode) (struct urb *urb, struct uvc_streaming *video, 471 struct uvc_buffer *buf); 472 473 /* Context data used by the bulk completion handler. */ 474 struct { 475 __u8 header[256]; 476 unsigned int header_size; 477 int skip_payload; 478 __u32 payload_size; 479 __u32 max_payload_size; 480 } bulk; 481 482 struct urb *urb[UVC_URBS]; 483 char *urb_buffer[UVC_URBS]; 484 dma_addr_t urb_dma[UVC_URBS]; 485 unsigned int urb_size; 486 487 __u32 sequence; 488 __u8 last_fid; 489 490 /* debugfs */ 491 struct dentry *debugfs_dir; 492 struct { 493 struct uvc_stats_frame frame; 494 struct uvc_stats_stream stream; 495 } stats; 496 497 /* Timestamps support. */ 498 struct uvc_clock { 499 struct uvc_clock_sample { 500 u32 dev_stc; 501 u16 dev_sof; 502 struct timespec host_ts; 503 u16 host_sof; 504 } *samples; 505 506 unsigned int head; 507 unsigned int count; 508 unsigned int size; 509 510 u16 last_sof; 511 u16 sof_offset; 512 513 spinlock_t lock; 514 } clock; 515 }; 516 517 enum uvc_device_state { 518 UVC_DEV_DISCONNECTED = 1, 519 }; 520 521 struct uvc_device { 522 struct usb_device *udev; 523 struct usb_interface *intf; 524 unsigned long warnings; 525 __u32 quirks; 526 int intfnum; 527 char name[32]; 528 529 enum uvc_device_state state; 530 struct mutex lock; /* Protects users */ 531 unsigned int users; 532 atomic_t nmappings; 533 534 /* Video control interface */ 535 #ifdef CONFIG_MEDIA_CONTROLLER 536 struct media_device mdev; 537 #endif 538 struct v4l2_device vdev; 539 __u16 uvc_version; 540 __u32 clock_frequency; 541 542 struct list_head entities; 543 struct list_head chains; 544 545 /* Video Streaming interfaces */ 546 struct list_head streams; 547 atomic_t nstreams; 548 549 /* Status Interrupt Endpoint */ 550 struct usb_host_endpoint *int_ep; 551 struct urb *int_urb; 552 __u8 *status; 553 struct input_dev *input; 554 char input_phys[64]; 555 }; 556 557 enum uvc_handle_state { 558 UVC_HANDLE_PASSIVE = 0, 559 UVC_HANDLE_ACTIVE = 1, 560 }; 561 562 struct uvc_fh { 563 struct v4l2_fh vfh; 564 struct uvc_video_chain *chain; 565 struct uvc_streaming *stream; 566 enum uvc_handle_state state; 567 }; 568 569 struct uvc_driver { 570 struct usb_driver driver; 571 }; 572 573 /* ------------------------------------------------------------------------ 574 * Debugging, printing and logging 575 */ 576 577 #define UVC_TRACE_PROBE (1 << 0) 578 #define UVC_TRACE_DESCR (1 << 1) 579 #define UVC_TRACE_CONTROL (1 << 2) 580 #define UVC_TRACE_FORMAT (1 << 3) 581 #define UVC_TRACE_CAPTURE (1 << 4) 582 #define UVC_TRACE_CALLS (1 << 5) 583 #define UVC_TRACE_IOCTL (1 << 6) 584 #define UVC_TRACE_FRAME (1 << 7) 585 #define UVC_TRACE_SUSPEND (1 << 8) 586 #define UVC_TRACE_STATUS (1 << 9) 587 #define UVC_TRACE_VIDEO (1 << 10) 588 #define UVC_TRACE_STATS (1 << 11) 589 #define UVC_TRACE_CLOCK (1 << 12) 590 591 #define UVC_WARN_MINMAX 0 592 #define UVC_WARN_PROBE_DEF 1 593 #define UVC_WARN_XU_GET_RES 2 594 595 extern unsigned int uvc_clock_param; 596 extern unsigned int uvc_no_drop_param; 597 extern unsigned int uvc_trace_param; 598 extern unsigned int uvc_timeout_param; 599 600 #define uvc_trace(flag, msg...) \ 601 do { \ 602 if (uvc_trace_param & flag) \ 603 printk(KERN_DEBUG "uvcvideo: " msg); \ 604 } while (0) 605 606 #define uvc_warn_once(dev, warn, msg...) \ 607 do { \ 608 if (!test_and_set_bit(warn, &dev->warnings)) \ 609 printk(KERN_INFO "uvcvideo: " msg); \ 610 } while (0) 611 612 #define uvc_printk(level, msg...) \ 613 printk(level "uvcvideo: " msg) 614 615 /* -------------------------------------------------------------------------- 616 * Internal functions. 617 */ 618 619 /* Core driver */ 620 extern struct uvc_driver uvc_driver; 621 622 extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); 623 624 /* Video buffers queue management. */ 625 extern int uvc_queue_init(struct uvc_video_queue *queue, 626 enum v4l2_buf_type type, int drop_corrupted); 627 extern int uvc_alloc_buffers(struct uvc_video_queue *queue, 628 struct v4l2_requestbuffers *rb); 629 extern void uvc_free_buffers(struct uvc_video_queue *queue); 630 extern int uvc_query_buffer(struct uvc_video_queue *queue, 631 struct v4l2_buffer *v4l2_buf); 632 extern int uvc_create_buffers(struct uvc_video_queue *queue, 633 struct v4l2_create_buffers *v4l2_cb); 634 extern int uvc_queue_buffer(struct uvc_video_queue *queue, 635 struct v4l2_buffer *v4l2_buf); 636 extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, 637 struct v4l2_buffer *v4l2_buf, int nonblocking); 638 extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); 639 extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); 640 extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, 641 struct uvc_buffer *buf); 642 extern int uvc_queue_mmap(struct uvc_video_queue *queue, 643 struct vm_area_struct *vma); 644 extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, 645 struct file *file, poll_table *wait); 646 #ifndef CONFIG_MMU 647 extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, 648 unsigned long pgoff); 649 #endif 650 extern int uvc_queue_allocated(struct uvc_video_queue *queue); 651 static inline int uvc_queue_streaming(struct uvc_video_queue *queue) 652 { 653 return vb2_is_streaming(&queue->queue); 654 } 655 656 /* V4L2 interface */ 657 extern const struct v4l2_file_operations uvc_fops; 658 659 /* Media controller */ 660 extern int uvc_mc_register_entities(struct uvc_video_chain *chain); 661 extern void uvc_mc_cleanup_entity(struct uvc_entity *entity); 662 663 /* Video */ 664 extern int uvc_video_init(struct uvc_streaming *stream); 665 extern int uvc_video_suspend(struct uvc_streaming *stream); 666 extern int uvc_video_resume(struct uvc_streaming *stream, int reset); 667 extern int uvc_video_enable(struct uvc_streaming *stream, int enable); 668 extern int uvc_probe_video(struct uvc_streaming *stream, 669 struct uvc_streaming_control *probe); 670 extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, 671 __u8 intfnum, __u8 cs, void *data, __u16 size); 672 void uvc_video_clock_update(struct uvc_streaming *stream, 673 struct v4l2_buffer *v4l2_buf, 674 struct uvc_buffer *buf); 675 676 /* Status */ 677 extern int uvc_status_init(struct uvc_device *dev); 678 extern void uvc_status_cleanup(struct uvc_device *dev); 679 extern int uvc_status_start(struct uvc_device *dev, gfp_t flags); 680 extern void uvc_status_stop(struct uvc_device *dev); 681 682 /* Controls */ 683 extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; 684 685 extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 686 struct v4l2_queryctrl *v4l2_ctrl); 687 extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain, 688 struct v4l2_querymenu *query_menu); 689 690 extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, 691 const struct uvc_control_mapping *mapping); 692 extern int uvc_ctrl_init_device(struct uvc_device *dev); 693 extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); 694 extern int uvc_ctrl_restore_values(struct uvc_device *dev); 695 696 extern int uvc_ctrl_begin(struct uvc_video_chain *chain); 697 extern int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, 698 const struct v4l2_ext_control *xctrls, 699 unsigned int xctrls_count); 700 static inline int uvc_ctrl_commit(struct uvc_fh *handle, 701 const struct v4l2_ext_control *xctrls, 702 unsigned int xctrls_count) 703 { 704 return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count); 705 } 706 static inline int uvc_ctrl_rollback(struct uvc_fh *handle) 707 { 708 return __uvc_ctrl_commit(handle, 1, NULL, 0); 709 } 710 711 extern int uvc_ctrl_get(struct uvc_video_chain *chain, 712 struct v4l2_ext_control *xctrl); 713 extern int uvc_ctrl_set(struct uvc_video_chain *chain, 714 struct v4l2_ext_control *xctrl); 715 716 extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain, 717 struct uvc_xu_control_query *xqry); 718 719 /* Utility functions */ 720 extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, 721 unsigned int n_terms, unsigned int threshold); 722 extern uint32_t uvc_fraction_to_interval(uint32_t numerator, 723 uint32_t denominator); 724 extern struct usb_host_endpoint *uvc_find_endpoint( 725 struct usb_host_interface *alts, __u8 epaddr); 726 727 /* Quirks support */ 728 void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream, 729 struct uvc_buffer *buf); 730 731 /* debugfs and statistics */ 732 int uvc_debugfs_init(void); 733 void uvc_debugfs_cleanup(void); 734 int uvc_debugfs_init_stream(struct uvc_streaming *stream); 735 void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream); 736 737 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, 738 size_t size); 739 740 #endif 741