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