USB: mxc: gadget: remove 60mhz clock requirement for freescale mx51 usb core
[linux-2.6.git] / drivers / usb / gadget / uvc.h
blob0a705e63c9365fe1e8f3960c4a214a13d55747cb
1 /*
2 * uvc_gadget.h -- USB Video Class Gadget driver
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
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
32 unsigned int length;
33 __u8 data[60];
36 struct uvc_event
38 union {
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 {
65 __u16 bmHint;
66 __u8 bFormatIndex;
67 __u8 bFrameIndex;
68 __u32 dwFrameInterval;
69 __u16 wKeyFrameRate;
70 __u16 wPFrameRate;
71 __u16 wCompQuality;
72 __u16 wCompWindowSize;
73 __u16 wDelay;
74 __u32 dwMaxVideoFrameSize;
75 __u32 dwMaxPayloadTransferSize;
76 __u32 dwClockFrequency;
77 __u8 bmFramingInfo;
78 __u8 bPreferedVersion;
79 __u8 bMinVersion;
80 __u8 bMaxVersion;
81 } __attribute__((__packed__));
83 /* ------------------------------------------------------------------------
84 * Debugging, printing and logging
87 #ifdef __KERNEL__
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_trace_param;
112 #define uvc_trace(flag, msg...) \
113 do { \
114 if (uvc_trace_param & flag) \
115 printk(KERN_DEBUG "uvcvideo: " msg); \
116 } while (0)
118 #define uvc_warn_once(dev, warn, msg...) \
119 do { \
120 if (!test_and_set_bit(warn, &dev->warnings)) \
121 printk(KERN_INFO "uvcvideo: " msg); \
122 } while (0)
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 /* ------------------------------------------------------------------------
144 * Structures
147 struct uvc_video
149 struct usb_ep *ep;
151 /* Frame parameters */
152 u8 bpp;
153 u32 fcc;
154 unsigned int width;
155 unsigned int height;
156 unsigned int imagesize;
158 /* Requests */
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;
163 spinlock_t req_lock;
165 void (*encode) (struct usb_request *req, struct uvc_video *video,
166 struct uvc_buffer *buf);
168 /* Context data used by the completion handler */
169 __u32 payload_size;
170 __u32 max_payload_size;
172 struct uvc_video_queue queue;
173 unsigned int fid;
176 enum uvc_state
178 UVC_STATE_DISCONNECTED,
179 UVC_STATE_CONNECTED,
180 UVC_STATE_STREAMING,
183 struct uvc_device
185 struct video_device *vdev;
186 enum uvc_state state;
187 struct usb_function func;
188 struct uvc_video video;
190 /* Descriptors */
191 struct {
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;
195 } desc;
197 unsigned int control_intf;
198 struct usb_ep *control_ep;
199 struct usb_request *control_req;
200 void *control_buf;
202 unsigned int streaming_intf;
204 /* Events */
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
216 struct v4l2_fh vfh;
217 struct uvc_video *device;
220 #define to_uvc_file_handle(handle) \
221 container_of(handle, struct uvc_file_handle, vfh)
223 extern struct v4l2_file_operations uvc_v4l2_fops;
225 /* ------------------------------------------------------------------------
226 * Functions
229 extern int uvc_video_enable(struct uvc_video *video, int enable);
230 extern int uvc_video_init(struct uvc_video *video);
231 extern int uvc_video_pump(struct uvc_video *video);
233 extern void uvc_endpoint_stream(struct uvc_device *dev);
235 extern void uvc_function_connect(struct uvc_device *uvc);
236 extern void uvc_function_disconnect(struct uvc_device *uvc);
238 #endif /* __KERNEL__ */
240 #endif /* _UVC_GADGET_H_ */