blob: 2e5846f1eb2044acffb5c16da7777bd825528121 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2#ifndef __LINUX_se401_H
3#define __LINUX_se401_H
4
5#include <asm/uaccess.h>
6#include <linux/videodev.h>
7#include <linux/smp_lock.h>
8
9#define se401_DEBUG /* Turn on debug messages */
10
11#ifdef se401_DEBUG
12# define PDEBUG(level, fmt, args...) \
13if (debug >= level) info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args)
14#else
15# define PDEBUG(level, fmt, args...) do {} while(0)
16#endif
17
18/* An almost drop-in replacement for sleep_on_interruptible */
19#define wait_interruptible(test, queue, wait) \
20{ \
21 add_wait_queue(queue, wait); \
22 set_current_state(TASK_INTERRUPTIBLE); \
23 if (test) \
24 schedule(); \
25 remove_wait_queue(queue, wait); \
26 set_current_state(TASK_RUNNING); \
27 if (signal_pending(current)) \
28 break; \
29}
30
31#define SE401_REQ_GET_CAMERA_DESCRIPTOR 0x06
32#define SE401_REQ_START_CONTINUOUS_CAPTURE 0x41
33#define SE401_REQ_STOP_CONTINUOUS_CAPTURE 0x42
34#define SE401_REQ_CAPTURE_FRAME 0x43
35#define SE401_REQ_GET_BRT 0x44
36#define SE401_REQ_SET_BRT 0x45
37#define SE401_REQ_GET_WIDTH 0x4c
38#define SE401_REQ_SET_WIDTH 0x4d
39#define SE401_REQ_GET_HEIGHT 0x4e
40#define SE401_REQ_SET_HEIGHT 0x4f
41#define SE401_REQ_GET_OUTPUT_MODE 0x50
42#define SE401_REQ_SET_OUTPUT_MODE 0x51
43#define SE401_REQ_GET_EXT_FEATURE 0x52
44#define SE401_REQ_SET_EXT_FEATURE 0x53
45#define SE401_REQ_CAMERA_POWER 0x56
46#define SE401_REQ_LED_CONTROL 0x57
47#define SE401_REQ_BIOS 0xff
48
49#define SE401_BIOS_READ 0x07
50
51#define SE401_FORMAT_BAYER 0x40
52
53/* Hyundai hv7131b registers
54 7121 and 7141 should be the same (haven't really checked...) */
55/* Mode registers: */
56#define HV7131_REG_MODE_A 0x00
57#define HV7131_REG_MODE_B 0x01
58#define HV7131_REG_MODE_C 0x02
59/* Frame registers: */
60#define HV7131_REG_FRSU 0x10
61#define HV7131_REG_FRSL 0x11
62#define HV7131_REG_FCSU 0x12
63#define HV7131_REG_FCSL 0x13
64#define HV7131_REG_FWHU 0x14
65#define HV7131_REG_FWHL 0x15
66#define HV7131_REG_FWWU 0x16
67#define HV7131_REG_FWWL 0x17
68/* Timing registers: */
69#define HV7131_REG_THBU 0x20
70#define HV7131_REG_THBL 0x21
71#define HV7131_REG_TVBU 0x22
72#define HV7131_REG_TVBL 0x23
73#define HV7131_REG_TITU 0x25
74#define HV7131_REG_TITM 0x26
75#define HV7131_REG_TITL 0x27
76#define HV7131_REG_TMCD 0x28
77/* Adjust Registers: */
78#define HV7131_REG_ARLV 0x30
79#define HV7131_REG_ARCG 0x31
80#define HV7131_REG_AGCG 0x32
81#define HV7131_REG_ABCG 0x33
82#define HV7131_REG_APBV 0x34
83#define HV7131_REG_ASLP 0x54
84/* Offset Registers: */
85#define HV7131_REG_OFSR 0x50
86#define HV7131_REG_OFSG 0x51
87#define HV7131_REG_OFSB 0x52
88/* REset level statistics registers: */
89#define HV7131_REG_LOREFNOH 0x57
90#define HV7131_REG_LOREFNOL 0x58
91#define HV7131_REG_HIREFNOH 0x59
92#define HV7131_REG_HIREFNOL 0x5a
93
94/* se401 registers */
95#define SE401_OPERATINGMODE 0x2000
96
97
98/* size of usb transfers */
99#define SE401_PACKETSIZE 4096
100/* number of queued bulk transfers to use, should be about 8 */
101#define SE401_NUMSBUF 1
102/* read the usb specs for this one :) */
103#define SE401_VIDEO_ENDPOINT 1
104#define SE401_BUTTON_ENDPOINT 2
105/* number of frames supported by the v4l part */
106#define SE401_NUMFRAMES 2
107/* scratch buffers for passing data to the decoders */
108#define SE401_NUMSCRATCH 32
109/* maximum amount of data in a JangGu packet */
110#define SE401_VLCDATALEN 1024
111/* number of nul sized packets to receive before kicking the camera */
112#define SE401_MAX_NULLPACKETS 4000
113/* number of decoding errors before kicking the camera */
114#define SE401_MAX_ERRORS 200
115
116struct usb_device;
117
118struct se401_sbuf {
119 unsigned char *data;
120};
121
122enum {
123 FRAME_UNUSED, /* Unused (no MCAPTURE) */
124 FRAME_READY, /* Ready to start grabbing */
125 FRAME_GRABBING, /* In the process of being grabbed into */
126 FRAME_DONE, /* Finished grabbing, but not been synced yet */
127 FRAME_ERROR, /* Something bad happened while processing */
128};
129
130enum {
131 FMT_BAYER,
132 FMT_JANGGU,
133};
134
135enum {
136 BUFFER_UNUSED,
137 BUFFER_READY,
138 BUFFER_BUSY,
139 BUFFER_DONE,
140};
141
142struct se401_scratch {
143 unsigned char *data;
144 volatile int state;
145 int offset;
146 int length;
147};
148
149struct se401_frame {
150 unsigned char *data; /* Frame buffer */
151
152 volatile int grabstate; /* State of grabbing */
153
154 unsigned char *curline;
155 int curlinepix;
156 int curpix;
157};
158
159struct usb_se401 {
160 struct video_device vdev;
161
162 /* Device structure */
163 struct usb_device *dev;
164
165 unsigned char iface;
166
167 char *camera_name;
168
169 int change;
170 int brightness;
171 int hue;
172 int rgain;
173 int ggain;
174 int bgain;
175 int expose_h;
176 int expose_m;
177 int expose_l;
178 int resetlevel;
179
180 int enhance;
181
182 int format;
183 int sizes;
184 int *width;
185 int *height;
186 int cwidth; /* current width */
187 int cheight; /* current height */
188 int palette;
189 int maxframesize;
190 int cframesize; /* current framesize */
191
192 struct semaphore lock;
193 int user; /* user count for exclusive use */
194 int removed; /* device disconnected */
195
196 int streaming; /* Are we streaming video? */
197
198 char *fbuf; /* Videodev buffer area */
199
200 struct urb *urb[SE401_NUMSBUF];
201 struct urb *inturb;
202
203 int button;
204 int buttonpressed;
205
206 int curframe; /* Current receiving frame */
207 struct se401_frame frame[SE401_NUMFRAMES];
208 int readcount;
209 int framecount;
210 int error;
211 int dropped;
212
213 int scratch_next;
214 int scratch_use;
215 int scratch_overflow;
216 struct se401_scratch scratch[SE401_NUMSCRATCH];
217
218 /* Decoder specific data: */
219 unsigned char vlcdata[SE401_VLCDATALEN];
220 int vlcdatapos;
221 int bayeroffset;
222
223 struct se401_sbuf sbuf[SE401_NUMSBUF];
224
225 wait_queue_head_t wq; /* Processes waiting */
226
227 int nullpackets;
228};
229
230
231
232#endif
233