Import 2.4.0-test5pre2
[davej-history.git] / drivers / usb / ov511.h
blobf4499b2bed8b9ef76b242714c794b8ac2f6d8179
2 #ifndef __LINUX_OV511_H
3 #define __LINUX_OV511_H
5 #include <asm/uaccess.h>
6 #include <linux/videodev.h>
7 #include <linux/smp_lock.h>
9 #define OV511_DEBUG /* Turn on debug messages */
11 #ifdef OV511_DEBUG
12 # define PDEBUG(level, fmt, args...) \
13 if (debug >= level) info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args)
14 #else
15 # define PDEBUG(level, fmt, args...) do {} while(0)
16 #endif
18 /* Camera interface register numbers */
19 #define OV511_REG_CAMERA_DELAY_MODE 0x10
20 #define OV511_REG_CAMERA_EDGE_MODE 0x11
21 #define OV511_REG_CAMERA_CLAMPED_PIXEL_NUM 0x12
22 #define OV511_REG_CAMERA_CLAMPED_LINE_NUM 0x13
23 #define OV511_REG_CAMERA_PIXEL_DIVISOR 0x14
24 #define OV511_REG_CAMERA_LINE_DIVISOR 0x15
25 #define OV511_REG_CAMERA_DATA_INPUT_SELECT 0x16
26 #define OV511_REG_CAMERA_RESERVED_LINE_MODE 0x17
27 #define OV511_REG_CAMERA_BITMASK 0x18
29 /* Snapshot mode camera interface register numbers */
30 #define OV511_REG_SNAP_CAPTURED_FRAME 0x19
31 #define OV511_REG_SNAP_CLAMPED_PIXEL_NUM 0x1A
32 #define OV511_REG_SNAP_CLAMPED_LINE_NUM 0x1B
33 #define OV511_REG_SNAP_PIXEL_DIVISOR 0x1C
34 #define OV511_REG_SNAP_LINE_DIVISOR 0x1D
35 #define OV511_REG_SNAP_DATA_INPUT_SELECT 0x1E
36 #define OV511_REG_SNAP_BITMASK 0x1F
38 /* DRAM register numbers */
39 #define OV511_REG_DRAM_ENABLE_FLOW_CONTROL 0x20
40 #define OV511_REG_DRAM_READ_CYCLE_PREDICT 0x21
41 #define OV511_REG_DRAM_MANUAL_READ_CYCLE 0x22
42 #define OV511_REG_DRAM_REFRESH_COUNTER 0x23
44 /* ISO FIFO register numbers */
45 #define OV511_REG_FIFO_PACKET_SIZE 0x30
46 #define OV511_REG_FIFO_BITMASK 0x31
48 /* PIO register numbers */
49 #define OV511_REG_PIO_BITMASK 0x38
50 #define OV511_REG_PIO_DATA_PORT 0x39
51 #define OV511_REG_PIO_BIST 0x3E
53 /* I2C register numbers */
54 #define OV511_REG_I2C_CONTROL 0x40
55 #define OV511_REG_I2C_SLAVE_ID_WRITE 0x41
56 #define OV511_REG_I2C_SUB_ADDRESS_3_BYTE 0x42
57 #define OV511_REG_I2C_SUB_ADDRESS_2_BYTE 0x43
58 #define OV511_REG_I2C_SLAVE_ID_READ 0x44
59 #define OV511_REG_I2C_DATA_PORT 0x45
60 #define OV511_REG_I2C_CLOCK_PRESCALER 0x46
61 #define OV511_REG_I2C_TIME_OUT_COUNTER 0x47
63 /* I2C snapshot register numbers */
64 #define OV511_REG_I2C_SNAP_SUB_ADDRESS 0x48
65 #define OV511_REG_I2C_SNAP_DATA_PORT 0x49
67 /* System control register numbers */
68 #define OV511_REG_SYSTEM_RESET 0x50
69 #define OV511_RESET_UDC 0x01
70 #define OV511_RESET_I2C 0x02
71 #define OV511_RESET_FIFO 0x04
72 #define OV511_RESET_OMNICE 0x08
73 #define OV511_RESET_DRAM_INTF 0x10
74 #define OV511_RESET_CAMERA_INTF 0x20
75 #define OV511_RESET_OV511 0x40
76 #define OV511_RESET_NOREGS 0x3F /* All but OV511 & regs */
77 #define OV511_RESET_ALL 0x7F
78 #define OV511_REG_SYSTEM_CLOCK_DIVISOR 0x51
79 #define OV511_REG_SYSTEM_SNAPSHOT 0x52
80 #define OV511_REG_SYSTEM_INIT 0x53
81 #define OV511_REG_SYSTEM_PWR_CLK 0x54 /* OV511+ only */
82 #define OV511_REG_SYSTEM_LED_CTL 0x55 /* OV511+ only */
83 #define OV511_REG_SYSTEM_USER_DEFINED 0x5E
84 #define OV511_REG_SYSTEM_CUSTOM_ID 0x5F
86 /* OmniCE register numbers */
87 #define OV511_OMNICE_PREDICTION_HORIZ_Y 0x70
88 #define OV511_OMNICE_PREDICTION_HORIZ_UV 0x71
89 #define OV511_OMNICE_PREDICTION_VERT_Y 0x72
90 #define OV511_OMNICE_PREDICTION_VERT_UV 0x73
91 #define OV511_OMNICE_QUANTIZATION_HORIZ_Y 0x74
92 #define OV511_OMNICE_QUANTIZATION_HORIZ_UV 0x75
93 #define OV511_OMNICE_QUANTIZATION_VERT_Y 0x76
94 #define OV511_OMNICE_QUANTIZATION_VERT_UV 0x77
95 #define OV511_OMNICE_ENABLE 0x78
96 #define OV511_OMNICE_LUT_ENABLE 0x79
97 #define OV511_OMNICE_Y_LUT_BEGIN 0x80
98 #define OV511_OMNICE_Y_LUT_END 0x9F
99 #define OV511_OMNICE_UV_LUT_BEGIN 0xA0
100 #define OV511_OMNICE_UV_LUT_END 0xBF
102 /* Alternate numbers for various max packet sizes (OV511 only) */
103 #define OV511_ALT_SIZE_992 0
104 #define OV511_ALT_SIZE_993 1
105 #define OV511_ALT_SIZE_768 2
106 #define OV511_ALT_SIZE_769 3
107 #define OV511_ALT_SIZE_512 4
108 #define OV511_ALT_SIZE_513 5
109 #define OV511_ALT_SIZE_257 6
110 #define OV511_ALT_SIZE_0 7
112 /* Alternate numbers for various max packet sizes (OV511+ only) */
113 #define OV511PLUS_ALT_SIZE_0 0
114 #define OV511PLUS_ALT_SIZE_33 1
115 #define OV511PLUS_ALT_SIZE_129 2
116 #define OV511PLUS_ALT_SIZE_257 3
117 #define OV511PLUS_ALT_SIZE_385 4
118 #define OV511PLUS_ALT_SIZE_513 5
119 #define OV511PLUS_ALT_SIZE_769 6
120 #define OV511PLUS_ALT_SIZE_961 7
122 /* OV7610 registers */
123 #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
124 #define OV7610_REG_BLUE 0x01 /* blue channel balance */
125 #define OV7610_REG_RED 0x02 /* red channel balance */
126 #define OV7610_REG_SAT 0x03 /* saturation */
127 /* 04 reserved */
128 #define OV7610_REG_CNT 0x05 /* Y contrast */
129 #define OV7610_REG_BRT 0x06 /* Y brightness */
130 /* 08-0b reserved */
131 #define OV7610_REG_BLUE_BIAS 0x0C /* blue channel bias (5:0) */
132 #define OV7610_REG_RED_BIAS 0x0D /* read channel bias (5:0) */
133 #define OV7610_REG_GAMMA_COEFF 0x0E /* gamma settings */
134 #define OV7610_REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
135 #define OV7610_REG_EXP 0x10 /* manual exposure setting */
136 #define OV7610_REG_CLOCK 0x11 /* polarity/clock prescaler */
137 #define OV7610_REG_COM_A 0x12 /* misc common regs */
138 #define OV7610_REG_COM_B 0x13 /* misc common regs */
139 #define OV7610_REG_COM_C 0x14 /* misc common regs */
140 #define OV7610_REG_COM_D 0x15 /* misc common regs */
141 #define OV7610_REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
142 #define OV7610_REG_HWIN_START 0x17 /* horizontal window start */
143 #define OV7610_REG_HWIN_END 0x18 /* horizontal window end */
144 #define OV7610_REG_VWIN_START 0x19 /* vertical window start */
145 #define OV7610_REG_VWIN_END 0x1A /* vertical window end */
146 #define OV7610_REG_PIXEL_SHIFT 0x1B /* pixel shift */
147 #define OV7610_REG_ID_HIGH 0x1C /* manufacturer ID MSB */
148 #define OV7610_REG_ID_LOW 0x1D /* manufacturer ID LSB */
149 /* 0e-0f reserved */
150 #define OV7610_REG_COM_E 0x20 /* misc common regs */
151 #define OV7610_REG_YOFFSET 0x21 /* Y channel offset */
152 #define OV7610_REG_UOFFSET 0x22 /* U channel offset */
153 /* 23 reserved */
154 #define OV7610_REG_ECW 0x24 /* Exposure white level for AEC */
155 #define OV7610_REG_ECB 0x25 /* Exposure black level for AEC */
156 #define OV7610_REG_COM_F 0x26 /* misc settings */
157 #define OV7610_REG_COM_G 0x27 /* misc settings */
158 #define OV7610_REG_COM_H 0x28 /* misc settings */
159 #define OV7610_REG_COM_I 0x29 /* misc settings */
160 #define OV7610_REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
161 #define OV7610_REG_FRAMERATE_L 0x2B /* frame rate LSB */
162 #define OV7610_REG_ALC 0x2C /* Auto Level Control settings */
163 #define OV7610_REG_COM_J 0x2D /* misc settings */
164 #define OV7610_REG_VOFFSET 0x2E /* V channel offset adjustment */
165 #define OV7610_REG_ARRAY_BIAS 0x2F /* Array bias -- don't change */
166 /* 30-32 reserved */
167 #define OV7610_REG_YGAMMA 0x33 /* misc gamma settings (7:6) */
168 #define OV7610_REG_BIAS_ADJUST 0x34 /* misc bias settings */
169 #define OV7610_REG_COM_L 0x35 /* misc settings */
170 /* 36-37 reserved */
171 #define OV7610_REG_COM_K 0x38 /* misc registers */
174 #define SCRATCH_BUF_SIZE 512
176 #define FRAMES_PER_DESC 10 /* FIXME - What should this be? */
177 #define FRAME_SIZE_PER_DESC 993 /* FIXME - Deprecated */
178 #define MAX_FRAME_SIZE_PER_DESC 993 /* For statically allocated stuff */
180 #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
182 // CAMERA SPECIFIC
183 // FIXME - these can vary between specific models
184 #define OV7610_I2C_WRITE_ID 0x42
185 #define OV7610_I2C_READ_ID 0x43
186 #define OV511_I2C_CLOCK_PRESCALER 0x03
188 /* Prototypes */
189 int usb_ov511_reg_read(struct usb_device *dev, unsigned char reg);
190 int usb_ov511_reg_write(struct usb_device *dev,
191 unsigned char reg,
192 unsigned char value);
194 /* Bridge types */
195 enum {
196 BRG_OV511,
197 BRG_OV511PLUS,
200 /* Sensor types */
201 enum {
202 SEN_UNKNOWN,
203 SEN_OV7610,
204 SEN_OV7620,
205 SEN_OV7620AE,
208 enum {
209 STATE_SCANNING, /* Scanning for start */
210 STATE_HEADER, /* Parsing header */
211 STATE_LINES, /* Parsing lines */
214 /* Buffer states */
215 enum {
216 BUF_NOT_ALLOCATED,
217 BUF_ALLOCATED,
218 BUF_PEND_DEALLOC, /* ov511->buf_timer is set */
221 struct usb_device;
223 struct ov511_sbuf {
224 char *data;
225 urb_t *urb;
228 enum {
229 FRAME_UNUSED, /* Unused (no MCAPTURE) */
230 FRAME_READY, /* Ready to start grabbing */
231 FRAME_GRABBING, /* In the process of being grabbed into */
232 FRAME_DONE, /* Finished grabbing, but not been synced yet */
233 FRAME_ERROR, /* Something bad happened while processing */
236 struct ov511_regvals {
237 enum {
238 OV511_DONE_BUS,
239 OV511_REG_BUS,
240 OV511_I2C_BUS,
241 } bus;
242 unsigned char reg;
243 unsigned char val;
246 struct ov511_frame {
247 char *data; /* Frame buffer */
249 int depth; /* Bytes per pixel */
250 int width; /* Width application is expecting */
251 int height; /* Height */
253 int hdrwidth; /* Width the frame actually is */
254 int hdrheight; /* Height */
256 int sub_flag; /* Sub-capture mode for this frame? */
257 int format; /* Format for this frame */
258 int segsize; /* How big is each segment from the camera? */
260 volatile int grabstate; /* State of grabbing */
261 int scanstate; /* State of scanning */
263 int curline; /* Line of frame we're working on */
264 int curpix;
265 int segment; /* Segment from the incoming data */
267 long scanlength; /* uncompressed, raw data length of frame */
268 long bytes_read; /* amount of scanlength that has been read from *data */
270 wait_queue_head_t wq; /* Processes waiting */
272 int snapshot; /* True if frame was a snapshot */
275 #define OV511_NUMFRAMES 2
276 #define OV511_NUMSBUF 2
278 struct usb_ov511 {
279 struct video_device vdev;
281 /* Device structure */
282 struct usb_device *dev;
284 int customid;
285 int desc;
286 unsigned char iface;
288 int brightness;
289 int colour;
290 int contrast;
291 int hue;
292 int whiteness;
294 struct semaphore lock;
295 int user; /* user count for exclusive use */
297 int streaming; /* Are we streaming Isochronous? */
298 int grabbing; /* Are we grabbing? */
300 int compress; /* Should the next frame be compressed? */
302 char *fbuf; /* Videodev buffer area */
304 int sub_flag; /* Pix Array subcapture on flag */
305 int subx; /* Pix Array subcapture x offset */
306 int suby; /* Pix Array subcapture y offset */
307 int subw; /* Pix Array subcapture width */
308 int subh; /* Pix Array subcapture height */
310 int curframe; /* Current receiving sbuf */
311 struct ov511_frame frame[OV511_NUMFRAMES];
313 int cursbuf; /* Current receiving sbuf */
314 struct ov511_sbuf sbuf[OV511_NUMSBUF];
316 /* Scratch space from the Isochronous pipe */
317 unsigned char scratch[SCRATCH_BUF_SIZE];
318 int scratchlen;
320 wait_queue_head_t wq; /* Processes waiting */
322 int snap_enabled; /* Snapshot mode enabled */
324 int bridge; /* Type of bridge (OV511 or OV511+) */
325 int sensor; /* Type of image sensor chip */
327 int packet_size; /* Frame size per isoc desc */
329 /* proc interface */
330 struct semaphore param_lock; /* params lock for this camera */
331 struct proc_dir_entry *proc_entry; /* /proc/ov511/videoX */
333 /* Framebuffer/sbuf management */
334 int buf_state;
335 struct semaphore buf_lock;
336 struct timer_list buf_timer;
339 struct cam_list {
340 int id;
341 char *description;
344 struct palette_list {
345 int num;
346 char *name;
349 struct mode_list {
350 int width;
351 int height;
352 int color; /* 0=grayscale, 1=color */
353 u8 pxcnt; /* pixel counter */
354 u8 lncnt; /* line counter */
355 u8 pxdv; /* pixel divisor */
356 u8 lndv; /* line divisor */
357 u8 m420;
358 u8 common_A;
359 u8 common_C;
360 u8 common_L;
363 #endif