4 #include <linux/kernel.h> 21 #define UVC_CONTROL_SET_CUR (1 << 0) 22 #define UVC_CONTROL_GET_CUR (1 << 1) 23 #define UVC_CONTROL_GET_MIN (1 << 2) 24 #define UVC_CONTROL_GET_MAX (1 << 3) 25 #define UVC_CONTROL_GET_RES (1 << 4) 26 #define UVC_CONTROL_GET_DEF (1 << 5) 28 #define UVC_CONTROL_RESTORE (1 << 6) 30 #define UVC_CONTROL_AUTO_UPDATE (1 << 7) 32 #define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \ 33 UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \ 52 enum v4l2_ctrl_type v4l2_type;
63 #define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) 64 #define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) 65 #define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) 66 #define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) 70 #include <linux/poll.h> 76 #define SC_UNDEFINED 0x00 77 #define SC_VIDEOCONTROL 0x01 78 #define SC_VIDEOSTREAMING 0x02 79 #define SC_VIDEO_INTERFACE_COLLECTION 0x03 81 #define PC_PROTOCOL_UNDEFINED 0x00 83 #define CS_UNDEFINED 0x20 84 #define CS_DEVICE 0x21 85 #define CS_CONFIGURATION 0x22 86 #define CS_STRING 0x23 87 #define CS_INTERFACE 0x24 88 #define CS_ENDPOINT 0x25 91 #define VC_DESCRIPTOR_UNDEFINED 0x00 92 #define VC_HEADER 0x01 93 #define VC_INPUT_TERMINAL 0x02 94 #define VC_OUTPUT_TERMINAL 0x03 95 #define VC_SELECTOR_UNIT 0x04 96 #define VC_PROCESSING_UNIT 0x05 97 #define VC_EXTENSION_UNIT 0x06 100 #define VS_UNDEFINED 0x00 101 #define VS_INPUT_HEADER 0x01 102 #define VS_OUTPUT_HEADER 0x02 103 #define VS_STILL_IMAGE_FRAME 0x03 104 #define VS_FORMAT_UNCOMPRESSED 0x04 105 #define VS_FRAME_UNCOMPRESSED 0x05 106 #define VS_FORMAT_MJPEG 0x06 107 #define VS_FRAME_MJPEG 0x07 108 #define VS_FORMAT_MPEG2TS 0x0a 109 #define VS_FORMAT_DV 0x0c 110 #define VS_COLORFORMAT 0x0d 111 #define VS_FORMAT_FRAME_BASED 0x10 112 #define VS_FRAME_FRAME_BASED 0x11 113 #define VS_FORMAT_STREAM_BASED 0x12 116 #define EP_UNDEFINED 0x00 117 #define EP_GENERAL 0x01 118 #define EP_ENDPOINT 0x02 119 #define EP_INTERRUPT 0x03 122 #define RC_UNDEFINED 0x00 129 #define GET_INFO 0x86 133 #define VC_CONTROL_UNDEFINED 0x00 134 #define VC_VIDEO_POWER_MODE_CONTROL 0x01 135 #define VC_REQUEST_ERROR_CODE_CONTROL 0x02 138 #define TE_CONTROL_UNDEFINED 0x00 141 #define SU_CONTROL_UNDEFINED 0x00 142 #define SU_INPUT_SELECT_CONTROL 0x01 145 #define CT_CONTROL_UNDEFINED 0x00 146 #define CT_SCANNING_MODE_CONTROL 0x01 147 #define CT_AE_MODE_CONTROL 0x02 148 #define CT_AE_PRIORITY_CONTROL 0x03 149 #define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04 150 #define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05 151 #define CT_FOCUS_ABSOLUTE_CONTROL 0x06 152 #define CT_FOCUS_RELATIVE_CONTROL 0x07 153 #define CT_FOCUS_AUTO_CONTROL 0x08 154 #define CT_IRIS_ABSOLUTE_CONTROL 0x09 155 #define CT_IRIS_RELATIVE_CONTROL 0x0a 156 #define CT_ZOOM_ABSOLUTE_CONTROL 0x0b 157 #define CT_ZOOM_RELATIVE_CONTROL 0x0c 158 #define CT_PANTILT_ABSOLUTE_CONTROL 0x0d 159 #define CT_PANTILT_RELATIVE_CONTROL 0x0e 160 #define CT_ROLL_ABSOLUTE_CONTROL 0x0f 161 #define CT_ROLL_RELATIVE_CONTROL 0x10 162 #define CT_PRIVACY_CONTROL 0x11 165 #define PU_CONTROL_UNDEFINED 0x00 166 #define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01 167 #define PU_BRIGHTNESS_CONTROL 0x02 168 #define PU_CONTRAST_CONTROL 0x03 169 #define PU_GAIN_CONTROL 0x04 170 #define PU_POWER_LINE_FREQUENCY_CONTROL 0x05 171 #define PU_HUE_CONTROL 0x06 172 #define PU_SATURATION_CONTROL 0x07 173 #define PU_SHARPNESS_CONTROL 0x08 174 #define PU_GAMMA_CONTROL 0x09 175 #define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a 176 #define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b 177 #define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c 178 #define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d 179 #define PU_DIGITAL_MULTIPLIER_CONTROL 0x0e 180 #define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f 181 #define PU_HUE_AUTO_CONTROL 0x10 182 #define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11 183 #define PU_ANALOG_LOCK_STATUS_CONTROL 0x12 185 #define LXU_MOTOR_PANTILT_RELATIVE_CONTROL 0x01 186 #define LXU_MOTOR_PANTILT_RESET_CONTROL 0x02 187 #define LXU_MOTOR_FOCUS_MOTOR_CONTROL 0x03 190 #define VS_CONTROL_UNDEFINED 0x00 191 #define VS_PROBE_CONTROL 0x01 192 #define VS_COMMIT_CONTROL 0x02 193 #define VS_STILL_PROBE_CONTROL 0x03 194 #define VS_STILL_COMMIT_CONTROL 0x04 195 #define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05 196 #define VS_STREAM_ERROR_CODE_CONTROL 0x06 197 #define VS_GENERATE_KEY_FRAME_CONTROL 0x07 198 #define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08 199 #define VS_SYNC_DELAY_CONTROL 0x09 201 #define TT_VENDOR_SPECIFIC 0x0100 202 #define TT_STREAMING 0x0101 205 #define ITT_VENDOR_SPECIFIC 0x0200 206 #define ITT_CAMERA 0x0201 207 #define ITT_MEDIA_TRANSPORT_INPUT 0x0202 210 #define OTT_VENDOR_SPECIFIC 0x0300 211 #define OTT_DISPLAY 0x0301 212 #define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302 215 #define EXTERNAL_VENDOR_SPECIFIC 0x0400 216 #define COMPOSITE_CONNECTOR 0x0401 217 #define SVIDEO_CONNECTOR 0x0402 218 #define COMPONENT_CONNECTOR 0x0403 220 #define UVC_TERM_INPUT 0x0000 221 #define UVC_TERM_OUTPUT 0x8000 223 #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) 224 #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) 225 #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) 226 #define UVC_ENTITY_IS_ITERM(entity) \ 227 (((entity)->type & 0x8000) == UVC_TERM_INPUT) 228 #define UVC_ENTITY_IS_OTERM(entity) \ 229 (((entity)->type & 0x8000) == UVC_TERM_OUTPUT) 231 #define UVC_STATUS_TYPE_CONTROL 1 232 #define UVC_STATUS_TYPE_STREAMING 2 237 #define UVC_GUID_UVC_CAMERA \ 238 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} 240 #define UVC_GUID_UVC_OUTPUT \ 241 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} 243 #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ 244 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} 246 #define UVC_GUID_UVC_PROCESSING \ 247 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} 249 #define UVC_GUID_UVC_SELECTOR \ 250 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} 253 #define UVC_GUID_LOGITECH_DEV_INFO \ 254 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ 255 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1e} 256 #define UVC_GUID_LOGITECH_USER_HW \ 257 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ 258 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1f} 259 #define UVC_GUID_LOGITECH_VIDEO \ 260 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ 261 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50} 262 #define UVC_GUID_LOGITECH_MOTOR \ 263 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ 264 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56} 266 #define UVC_GUID_FORMAT_MJPEG \ 267 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ 268 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 269 #define UVC_GUID_FORMAT_YUY2 \ 270 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 271 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 272 #define UVC_GUID_FORMAT_NV12 \ 273 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 274 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 275 #define UVC_GUID_FORMAT_YV12 \ 276 { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 277 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 278 #define UVC_GUID_FORMAT_I420 \ 279 { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 280 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 281 #define UVC_GUID_FORMAT_UYVY \ 282 { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ 283 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 284 #define UVC_GUID_FORMAT_Y800 \ 285 { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ 286 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 287 #define UVC_GUID_FORMAT_BY8 \ 288 { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ 289 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 296 #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) 301 #define UVC_MAX_ISO_PACKETS 40 303 #define UVC_MAX_FRAME_SIZE (16*1024*1024) 305 #define UVC_MAX_VIDEO_BUFFERS 32 307 #define UVC_CTRL_CONTROL_TIMEOUT 300 308 #define UVC_CTRL_STREAMING_TIMEOUT 1000 311 #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 312 #define UVC_QUIRK_PROBE_MINMAX 0x00000002 313 #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 314 #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 315 #define UVC_QUIRK_STREAM_NO_FID 0x00000010 318 #define UVC_FMT_FLAG_COMPRESSED 0x00000001 319 #define UVC_FMT_FLAG_STREAM 0x00000002 330 struct uvc_streaming_control {
334 __u32 dwFrameInterval;
338 __u16 wCompWindowSize;
340 __u32 dwMaxVideoFrameSize;
341 __u32 dwMaxPayloadTransferSize;
342 __u32 dwClockFrequency;
344 __u8 bPreferedVersion;
349 struct uvc_menu_info {
354 struct uvc_control_info {
355 struct list_head list;
356 struct list_head mappings;
366 struct uvc_control_mapping {
367 struct list_head list;
369 struct uvc_control_info *ctrl;
378 enum v4l2_ctrl_type v4l2_type;
381 struct uvc_menu_info *menu_info;
386 struct uvc_entity *
entity;
387 struct uvc_control_info *
info;
398 struct uvc_format_desc {
420 struct list_head list;
421 struct list_head chain;
429 __u16 wObjectiveFocalLengthMin;
430 __u16 wObjectiveFocalLengthMax;
431 __u16 wOcularFocalLength;
439 __u8 bTransportModeSize;
440 __u8 *bmTransportModes;
449 __u16 wMaxMultiplier;
452 __u8 bmVideoStandards;
461 __u8 guidExtensionCode[16];
467 __u8 *bmControlsType;
471 unsigned int ncontrols;
472 struct uvc_control *controls;
482 __u32 dwMaxVideoFrameBufferSize;
483 __u8 bFrameIntervalType;
484 __u32 dwDefaultFrameInterval;
485 __u32 *dwFrameInterval;
498 unsigned int nframes;
499 struct uvc_frame *frame;
502 struct uvc_streaming_header {
504 __u8 bEndpointAddress;
510 __u8 bStillCaptureMethod;
511 __u8 bTriggerSupport;
515 struct uvc_streaming {
516 struct list_head list;
518 struct usb_interface *intf;
522 struct uvc_streaming_header header;
524 unsigned int nformats;
525 struct uvc_format *format;
527 struct uvc_streaming_control ctrl;
528 struct uvc_format *cur_format;
529 struct uvc_frame *cur_frame;
534 enum uvc_buffer_state {
535 UVC_BUF_STATE_IDLE = 0,
536 UVC_BUF_STATE_QUEUED = 1,
537 UVC_BUF_STATE_ACTIVE = 2,
538 UVC_BUF_STATE_DONE = 3,
539 UVC_BUF_STATE_ERROR = 4,
543 unsigned long vma_use_count;
544 struct list_head stream;
547 struct v4l2_buffer buf;
548 struct list_head queue;
549 wait_queue_head_t
wait;
550 enum uvc_buffer_state state;
553 struct uvc_video_queue {
555 unsigned int streaming : 1,
561 unsigned int buf_size;
562 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
566 struct list_head mainqueue;
567 struct list_head irqqueue;
570 struct uvc_video_device {
571 struct uvc_device *dev;
572 struct video_device *vdev;
575 struct list_head iterms;
576 struct uvc_entity *oterm;
577 struct uvc_entity *processing;
579 struct list_head extensions;
580 struct mutex ctrl_mutex;
582 struct uvc_video_queue queue;
585 struct uvc_streaming *streaming;
587 void (*decode) (
struct urb *urb,
struct uvc_video_device *video,
588 struct uvc_buffer *buf);
593 unsigned int header_size;
596 __u32 max_payload_size;
599 struct urb *urb[UVC_URBS];
600 char *urb_buffer[UVC_URBS];
605 enum uvc_device_state {
606 UVC_DEV_DISCONNECTED = 1,
610 struct usb_device *udev;
611 struct usb_interface *intf;
616 enum uvc_device_state state;
618 struct list_head list;
622 __u32 clock_frequency;
624 struct list_head entities;
626 struct uvc_video_device video;
629 struct usb_host_endpoint *int_ep;
632 struct input_dev *input;
635 struct list_head streaming;
638 enum uvc_handle_state {
639 UVC_HANDLE_PASSIVE = 0,
640 UVC_HANDLE_ACTIVE = 1,
644 struct uvc_video_device *device;
645 enum uvc_handle_state state;
649 struct usb_driver driver;
651 struct mutex open_mutex;
653 struct list_head devices;
654 struct list_head controls;
655 struct mutex ctrl_mutex;
663 #define UVC_TRACE_PROBE (1 << 0) 664 #define UVC_TRACE_DESCR (1 << 1) 665 #define UVC_TRACE_CONTROL (1 << 2) 666 #define UVC_TRACE_FORMAT (1 << 3) 667 #define UVC_TRACE_CAPTURE (1 << 4) 668 #define UVC_TRACE_CALLS (1 << 5) 669 #define UVC_TRACE_IOCTL (1 << 6) 670 #define UVC_TRACE_FRAME (1 << 7) 671 #define UVC_TRACE_SUSPEND (1 << 8) 672 #define UVC_TRACE_STATUS (1 << 9) 674 extern unsigned int uvc_trace_param;
676 #define uvc_trace(flag, msg...) \ 678 if (uvc_trace_param & flag) \ 679 printk(KERN_DEBUG "uvcvideo: " msg); \ 682 #define uvc_printk(level, msg...) \ 683 printk(level "uvcvideo: " msg) 685 #define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \ 686 "%02x%02x%02x%02x%02x%02x" 687 #define UVC_GUID_ARGS(guid) \ 688 (guid)[3], (guid)[2], (guid)[1], (guid)[0], \ 689 (guid)[5], (guid)[4], \ 690 (guid)[7], (guid)[6], \ 691 (guid)[8], (guid)[9], \ 692 (guid)[10], (guid)[11], (guid)[12], \ 693 (guid)[13], (guid)[14], (guid)[15] 700 extern struct uvc_driver uvc_driver;
701 extern void uvc_delete(
struct kref *kref);
704 extern void uvc_queue_init(
struct uvc_video_queue *queue);
705 extern int uvc_alloc_buffers(
struct uvc_video_queue *queue,
706 unsigned int nbuffers,
unsigned int buflength);
707 extern int uvc_free_buffers(
struct uvc_video_queue *queue);
708 extern int uvc_query_buffer(
struct uvc_video_queue *queue,
709 struct v4l2_buffer *v4l2_buf);
710 extern int uvc_queue_buffer(
struct uvc_video_queue *queue,
711 struct v4l2_buffer *v4l2_buf);
712 extern int uvc_dequeue_buffer(
struct uvc_video_queue *queue,
713 struct v4l2_buffer *v4l2_buf,
int nonblocking);
714 extern int uvc_queue_enable(
struct uvc_video_queue *queue,
int enable);
715 extern void uvc_queue_cancel(
struct uvc_video_queue *queue);
716 extern struct uvc_buffer *uvc_queue_next_buffer(
struct uvc_video_queue *queue,
717 struct uvc_buffer *buf);
718 extern unsigned int uvc_queue_poll(
struct uvc_video_queue *queue,
719 struct file *file, poll_table *wait);
722 extern struct file_operations uvc_fops;
725 extern int uvc_video_init(
struct uvc_video_device *video);
726 extern int uvc_video_suspend(
struct uvc_video_device *video);
727 extern int uvc_video_resume(
struct uvc_video_device *video);
728 extern int uvc_video_enable(
struct uvc_video_device *video,
int enable);
729 extern int uvc_probe_video(
struct uvc_video_device *video,
730 struct uvc_streaming_control *probe);
731 extern int uvc_query_ctrl(
struct uvc_device *dev, __u8 query, __u8 unit,
732 __u8 intfnum, __u8 cs,
void *data, __u16
size);
733 extern int uvc_set_video_ctrl(
struct uvc_video_device *video,
734 struct uvc_streaming_control *ctrl,
int probe);
737 extern int uvc_status_init(
struct uvc_device *dev);
738 extern void uvc_status_cleanup(
struct uvc_device *dev);
739 extern int uvc_status_suspend(
struct uvc_device *dev);
740 extern int uvc_status_resume(
struct uvc_device *dev);
743 extern struct uvc_control *uvc_find_control(
struct uvc_video_device *video,
744 __u32 v4l2_id,
struct uvc_control_mapping **mapping);
745 extern int uvc_query_v4l2_ctrl(
struct uvc_video_device *video,
746 struct v4l2_queryctrl *v4l2_ctrl);
748 extern int uvc_ctrl_add_info(
struct uvc_control_info *
info);
749 extern int uvc_ctrl_add_mapping(
struct uvc_control_mapping *mapping);
750 extern int uvc_ctrl_init_device(
struct uvc_device *dev);
751 extern void uvc_ctrl_cleanup_device(
struct uvc_device *dev);
752 extern int uvc_ctrl_resume_device(
struct uvc_device *dev);
753 extern void uvc_ctrl_init(
void);
755 extern int uvc_ctrl_begin(
struct uvc_video_device *video);
756 extern int __uvc_ctrl_commit(
struct uvc_video_device *video,
int rollback);
757 static inline int uvc_ctrl_commit(
struct uvc_video_device *video)
759 return __uvc_ctrl_commit(video, 0);
761 static inline int uvc_ctrl_rollback(
struct uvc_video_device *video)
763 return __uvc_ctrl_commit(video, 1);
766 extern int uvc_ctrl_get(
struct uvc_video_device *video,
767 struct v4l2_ext_control *xctrl);
768 extern int uvc_ctrl_set(
struct uvc_video_device *video,
769 struct v4l2_ext_control *xctrl);
771 extern int uvc_xu_ctrl_query(
struct uvc_video_device *video,
775 extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
776 unsigned int n_terms,
unsigned int threshold);
777 extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
778 uint32_t denominator);
779 extern struct usb_host_endpoint *uvc_find_endpoint(
780 struct usb_host_interface *alts, __u8 epaddr);
783 void uvc_video_decode_isight(
struct urb *urb,
struct uvc_video_device *video,
784 struct uvc_buffer *buf);
static struct jpginfo info