JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
uvc.h
Go to the documentation of this file.
1/*
2 * uvc_gadget.h -- USB Video Class Gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
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.
11 */
12
13// JEVOIS NOTE: This file is from the linux kernel. But it defines form data structures and definition values that used
14// in the userland portions of the gadget code. Thus, we need it when compiling userland code. We include this file in
15// the JeVois source tree to avoid a complex dependency onto the kernel. Make sure you keep this version in sync with
16// the version in the kernel.
17
18#ifndef _UVC_GADGET_H_
19#define _UVC_GADGET_H_
20
21#include <linux/ioctl.h>
22#include <linux/types.h>
23#include <linux/usb/ch9.h>
24
25#define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0)
26#define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0)
27#define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1)
28#define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2)
29#define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3)
30#define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4)
31#define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
32#define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
33
34// JEVOIS: when we have lots of video modes, the original value of 64 here was too small:
35#define UVC_MAX_REQUEST_SIZE 512
37{
38 __s32 length;
39 __u8 data[UVC_MAX_REQUEST_SIZE - sizeof(__s32)];
40};
41
43{
44 union {
45 enum usb_device_speed speed;
46 struct usb_ctrlrequest req;
48 };
49};
50
51#define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
52
53#define UVC_INTF_CONTROL 0
54#define UVC_INTF_STREAMING 1
55
56/* ------------------------------------------------------------------------
57 * Debugging, printing and logging
58 */
59
60#ifdef __KERNEL__
61
62#include <linux/usb.h> /* For usb_endpoint_* */
63#include <linux/usb/gadget.h>
64#include <linux/videodev2.h>
65#include <linux/version.h>
66#include <media/v4l2-fh.h>
67
68#include "uvc_queue.h"
69
70#define UVC_TRACE_PROBE (1 << 0)
71#define UVC_TRACE_DESCR (1 << 1)
72#define UVC_TRACE_CONTROL (1 << 2)
73#define UVC_TRACE_FORMAT (1 << 3)
74#define UVC_TRACE_CAPTURE (1 << 4)
75#define UVC_TRACE_CALLS (1 << 5)
76#define UVC_TRACE_IOCTL (1 << 6)
77#define UVC_TRACE_FRAME (1 << 7)
78#define UVC_TRACE_SUSPEND (1 << 8)
79#define UVC_TRACE_STATUS (1 << 9)
80
81#define UVC_WARN_MINMAX 0
82#define UVC_WARN_PROBE_DEF 1
83
84extern unsigned int uvc_gadget_trace_param;
85
86#define uvc_trace(flag, msg...) \
87 do { \
88 if (uvc_gadget_trace_param & flag) \
89 printk(KERN_DEBUG "uvcvideo: " msg); \
90 } while (0)
91
92#define uvc_warn_once(dev, warn, msg...) \
93 do { \
94 if (!test_and_set_bit(warn, &dev->warnings)) \
95 printk(KERN_INFO "uvcvideo: " msg); \
96 } while (0)
97
98#define uvc_printk(level, msg...) \
99 printk(level "uvcvideo: " msg)
100
101/* ------------------------------------------------------------------------
102 * Driver specific constants
103 */
104
105#define DRIVER_VERSION "0.1.0"
106#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
107
108#define DMA_ADDR_INVALID (~(dma_addr_t)0)
109
110#define UVC_NUM_REQUESTS 4
111#define UVC_MAX_EVENTS 4
112
113/* ------------------------------------------------------------------------
114 * Structures
115 */
116
117struct uvc_video
118{
119 struct usb_ep *ep;
120
121 /* Frame parameters */
122 u8 bpp;
123 u32 fcc;
124 unsigned int width;
125 unsigned int height;
126 unsigned int imagesize;
127
128 /* Requests */
129 unsigned int req_size;
130 struct usb_request *req[UVC_NUM_REQUESTS];
131 __u8 *req_buffer[UVC_NUM_REQUESTS];
132 struct list_head req_free;
133 spinlock_t req_lock;
134
135 void (*encode) (struct usb_request *req, struct uvc_video *video,
136 struct uvc_buffer *buf);
137
138 /* Context data used by the completion handler */
139 __u32 payload_size;
140 __u32 max_payload_size;
141
142 struct uvc_video_queue queue;
143 unsigned int fid;
144};
145
146enum uvc_state
147{
148 UVC_STATE_DISCONNECTED,
149 UVC_STATE_CONNECTED,
150 UVC_STATE_STREAMING,
151};
152
153struct uvc_device
154{
155 struct video_device *vdev;
156 enum uvc_state state;
157 struct usb_function func;
158 struct uvc_video video;
159
160 /* Descriptors */
161 struct {
162 const struct uvc_descriptor_header * const *control;
163 const struct uvc_descriptor_header * const *fs_streaming;
164 const struct uvc_descriptor_header * const *hs_streaming;
165 } desc;
166
167 unsigned int control_intf;
168 struct usb_ep *control_ep;
169 struct usb_request *control_req;
170 void *control_buf;
171
172 unsigned int streaming_intf;
173
174 /* Events */
175 unsigned int event_length;
176 unsigned int event_setup_out : 1;
177};
178
179static inline struct uvc_device *to_uvc(struct usb_function *f)
180{
181 return container_of(f, struct uvc_device, func);
182}
183
184struct uvc_file_handle
185{
186 struct v4l2_fh vfh;
187 struct uvc_video *device;
188};
189
190#define to_uvc_file_handle(handle) \
191 container_of(handle, struct uvc_file_handle, vfh)
192
193/* ------------------------------------------------------------------------
194 * Functions
195 */
196
197extern void uvc_endpoint_stream(struct uvc_device *dev);
198
199extern void uvc_function_connect(struct uvc_device *uvc);
200extern void uvc_function_disconnect(struct uvc_device *uvc);
201
202#endif /* __KERNEL__ */
203
204#endif /* _UVC_GADGET_H_ */
205
struct usb_ctrlrequest req
Definition uvc.h:46
enum usb_device_speed speed
Definition uvc.h:45
struct uvc_request_data data
Definition uvc.h:47
__u8 data[UVC_MAX_REQUEST_SIZE - sizeof(__s32)]
Definition uvc.h:39
__s32 length
Definition uvc.h:38
#define UVC_MAX_REQUEST_SIZE
Definition uvc.h:35