2 * uvc_gadget.h -- USB Video Class Gadget driver
4 * Copyright (C) 2009-2010
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
14 #ifndef _UVC_GADGET_H_
15 #define _UVC_GADGET_H_
17 #include <linux/ioctl.h>
18 #include <linux/types.h>
19 #include <linux/usb/ch9.h>
21 #define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0)
22 #define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0)
23 #define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1)
24 #define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2)
25 #define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3)
26 #define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4)
27 #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
28 #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
30 struct uvc_request_data
39 enum usb_device_speed speed;
40 struct usb_ctrlrequest req;
41 struct uvc_request_data data;
45 #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
47 #define UVC_INTF_CONTROL 0
48 #define UVC_INTF_STREAMING 1
50 /* ------------------------------------------------------------------------
51 * UVC constants & structures
54 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
55 #define UVC_STREAM_EOH (1 << 7)
56 #define UVC_STREAM_ERR (1 << 6)
57 #define UVC_STREAM_STI (1 << 5)
58 #define UVC_STREAM_RES (1 << 4)
59 #define UVC_STREAM_SCR (1 << 3)
60 #define UVC_STREAM_PTS (1 << 2)
61 #define UVC_STREAM_EOF (1 << 1)
62 #define UVC_STREAM_FID (1 << 0)
64 struct uvc_streaming_control {
68 __u32 dwFrameInterval;
72 __u16 wCompWindowSize;
74 __u32 dwMaxVideoFrameSize;
75 __u32 dwMaxPayloadTransferSize;
76 __u32 dwClockFrequency;
78 __u8 bPreferedVersion;
81 } __attribute__((__packed__));
83 /* ------------------------------------------------------------------------
84 * Debugging, printing and logging
89 #include <linux/usb.h> /* For usb_endpoint_* */
90 #include <linux/usb/gadget.h>
91 #include <linux/videodev2.h>
92 #include <media/v4l2-fh.h>
94 #include "uvc_queue.h"
96 #define UVC_TRACE_PROBE (1 << 0)
97 #define UVC_TRACE_DESCR (1 << 1)
98 #define UVC_TRACE_CONTROL (1 << 2)
99 #define UVC_TRACE_FORMAT (1 << 3)
100 #define UVC_TRACE_CAPTURE (1 << 4)
101 #define UVC_TRACE_CALLS (1 << 5)
102 #define UVC_TRACE_IOCTL (1 << 6)
103 #define UVC_TRACE_FRAME (1 << 7)
104 #define UVC_TRACE_SUSPEND (1 << 8)
105 #define UVC_TRACE_STATUS (1 << 9)
107 #define UVC_WARN_MINMAX 0
108 #define UVC_WARN_PROBE_DEF 1
110 extern unsigned int uvc_gadget_trace_param;
112 #define uvc_trace(flag, msg...) \
114 if (uvc_gadget_trace_param & flag) \
115 printk(KERN_DEBUG "uvcvideo: " msg); \
118 #define uvc_warn_once(dev, warn, msg...) \
120 if (!test_and_set_bit(warn, &dev->warnings)) \
121 printk(KERN_INFO "uvcvideo: " msg); \
124 #define uvc_printk(level, msg...) \
125 printk(level "uvcvideo: " msg)
127 /* ------------------------------------------------------------------------
128 * Driver specific constants
131 #define DRIVER_VERSION "0.1.0"
132 #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
134 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
136 #define UVC_NUM_REQUESTS 4
137 #define UVC_MAX_REQUEST_SIZE 64
138 #define UVC_MAX_EVENTS 4
140 #define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
141 #define USB_CLASS_MISC 0xef
143 /* ------------------------------------------------------------------------
151 /* Frame parameters */
156 unsigned int imagesize;
159 unsigned int req_size;
160 struct usb_request *req[UVC_NUM_REQUESTS];
161 __u8 *req_buffer[UVC_NUM_REQUESTS];
162 struct list_head req_free;
165 void (*encode) (struct usb_request *req, struct uvc_video *video,
166 struct uvc_buffer *buf);
168 /* Context data used by the completion handler */
170 __u32 max_payload_size;
172 struct uvc_video_queue queue;
178 UVC_STATE_DISCONNECTED,
185 struct video_device *vdev;
186 enum uvc_state state;
187 struct usb_function func;
188 struct uvc_video video;
192 const struct uvc_descriptor_header * const *control;
193 const struct uvc_descriptor_header * const *fs_streaming;
194 const struct uvc_descriptor_header * const *hs_streaming;
197 unsigned int control_intf;
198 struct usb_ep *control_ep;
199 struct usb_request *control_req;
202 unsigned int streaming_intf;
205 unsigned int event_length;
206 unsigned int event_setup_out : 1;
209 static inline struct uvc_device *to_uvc(struct usb_function *f)
211 return container_of(f, struct uvc_device, func);
214 struct uvc_file_handle
217 struct uvc_video *device;
220 #define to_uvc_file_handle(handle) \
221 container_of(handle, struct uvc_file_handle, vfh)
223 /* ------------------------------------------------------------------------
227 extern void uvc_endpoint_stream(struct uvc_device *dev);
229 extern void uvc_function_connect(struct uvc_device *uvc);
230 extern void uvc_function_disconnect(struct uvc_device *uvc);
232 #endif /* __KERNEL__ */
234 #endif /* _UVC_GADGET_H_ */