1 #ifndef __LINUX_OV511_H
2 #define __LINUX_OV511_H
4 #include <asm/uaccess.h>
5 #include <linux/videodev.h>
6 #include <media/v4l2-common.h>
7 #include <linux/smp_lock.h>
9 #include <linux/mutex.h>
11 #define OV511_DEBUG /* Turn on debug messages */
14 #define PDEBUG(level, fmt, args...) \
15 if (debug >= (level)) info("[%s:%d] " fmt, \
16 __FUNCTION__, __LINE__ , ## args)
18 #define PDEBUG(level, fmt, args...) do {} while(0)
21 /* This macro restricts an int variable to an inclusive range */
22 #define RESTRICT_TO_RANGE(v,mi,ma) { \
23 if ((v) < (mi)) (v) = (mi); \
24 else if ((v) > (ma)) (v) = (ma); \
27 /* --------------------------------- */
28 /* DEFINES FOR OV511 AND OTHER CHIPS */
29 /* --------------------------------- */
32 #define VEND_OMNIVISION 0x05A9
33 #define PROD_OV511 0x0511
34 #define PROD_OV511PLUS 0xA511
35 #define PROD_OV518 0x0518
36 #define PROD_OV518PLUS 0xA518
38 #define VEND_MATTEL 0x0813
39 #define PROD_ME2CAM 0x0002
41 /* --------------------------------- */
42 /* OV51x REGISTER MNEMONICS */
43 /* --------------------------------- */
45 /* Camera interface register numbers */
46 #define R511_CAM_DELAY 0x10
47 #define R511_CAM_EDGE 0x11
48 #define R511_CAM_PXCNT 0x12
49 #define R511_CAM_LNCNT 0x13
50 #define R511_CAM_PXDIV 0x14
51 #define R511_CAM_LNDIV 0x15
52 #define R511_CAM_UV_EN 0x16
53 #define R511_CAM_LINE_MODE 0x17
54 #define R511_CAM_OPTS 0x18
56 /* Snapshot mode camera interface register numbers */
57 #define R511_SNAP_FRAME 0x19
58 #define R511_SNAP_PXCNT 0x1A
59 #define R511_SNAP_LNCNT 0x1B
60 #define R511_SNAP_PXDIV 0x1C
61 #define R511_SNAP_LNDIV 0x1D
62 #define R511_SNAP_UV_EN 0x1E
63 #define R511_SNAP_OPTS 0x1F
65 /* DRAM register numbers */
66 #define R511_DRAM_FLOW_CTL 0x20
67 #define R511_DRAM_ARCP 0x21
68 #define R511_DRAM_MRC 0x22
69 #define R511_DRAM_RFC 0x23
71 /* ISO FIFO register numbers */
72 #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
73 #define R511_FIFO_OPTS 0x31
75 /* Parallel IO register numbers */
76 #define R511_PIO_OPTS 0x38
77 #define R511_PIO_DATA 0x39
78 #define R511_PIO_BIST 0x3E
79 #define R518_GPIO_IN 0x55 /* OV518(+) only */
80 #define R518_GPIO_OUT 0x56 /* OV518(+) only */
81 #define R518_GPIO_CTL 0x57 /* OV518(+) only */
82 #define R518_GPIO_PULSE_IN 0x58 /* OV518(+) only */
83 #define R518_GPIO_PULSE_CLEAR 0x59 /* OV518(+) only */
84 #define R518_GPIO_PULSE_POL 0x5a /* OV518(+) only */
85 #define R518_GPIO_PULSE_EN 0x5b /* OV518(+) only */
86 #define R518_GPIO_RESET 0x5c /* OV518(+) only */
89 #define R511_I2C_CTL 0x40
90 #define R518_I2C_CTL 0x47 /* OV518(+) only */
91 #define R51x_I2C_W_SID 0x41
92 #define R51x_I2C_SADDR_3 0x42
93 #define R51x_I2C_SADDR_2 0x43
94 #define R51x_I2C_R_SID 0x44
95 #define R51x_I2C_DATA 0x45
96 #define R51x_I2C_CLOCK 0x46
97 #define R51x_I2C_TIMEOUT 0x47
99 /* I2C snapshot registers */
100 #define R511_SI2C_SADDR_3 0x48
101 #define R511_SI2C_DATA 0x49
103 /* System control registers */
104 #define R51x_SYS_RESET 0x50
105 /* Reset type definitions */
106 #define OV511_RESET_UDC 0x01
107 #define OV511_RESET_I2C 0x02
108 #define OV511_RESET_FIFO 0x04
109 #define OV511_RESET_OMNICE 0x08
110 #define OV511_RESET_DRAM 0x10
111 #define OV511_RESET_CAM_INT 0x20
112 #define OV511_RESET_OV511 0x40
113 #define OV511_RESET_NOREGS 0x3F /* All but OV511 & regs */
114 #define OV511_RESET_ALL 0x7F
116 #define R511_SYS_CLOCK_DIV 0x51
117 #define R51x_SYS_SNAP 0x52
118 #define R51x_SYS_INIT 0x53
119 #define R511_SYS_PWR_CLK 0x54 /* OV511+/OV518(+) only */
120 #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
121 #define R511_SYS_USER 0x5E
122 #define R511_SYS_CUST_ID 0x5F
124 /* OmniCE (compression) registers */
125 #define R511_COMP_PHY 0x70
126 #define R511_COMP_PHUV 0x71
127 #define R511_COMP_PVY 0x72
128 #define R511_COMP_PVUV 0x73
129 #define R511_COMP_QHY 0x74
130 #define R511_COMP_QHUV 0x75
131 #define R511_COMP_QVY 0x76
132 #define R511_COMP_QVUV 0x77
133 #define R511_COMP_EN 0x78
134 #define R511_COMP_LUT_EN 0x79
135 #define R511_COMP_LUT_BEGIN 0x80
137 /* --------------------------------- */
138 /* ALTERNATE NUMBERS */
139 /* --------------------------------- */
141 /* Alternate numbers for various max packet sizes (OV511 only) */
142 #define OV511_ALT_SIZE_992 0
143 #define OV511_ALT_SIZE_993 1
144 #define OV511_ALT_SIZE_768 2
145 #define OV511_ALT_SIZE_769 3
146 #define OV511_ALT_SIZE_512 4
147 #define OV511_ALT_SIZE_513 5
148 #define OV511_ALT_SIZE_257 6
149 #define OV511_ALT_SIZE_0 7
151 /* Alternate numbers for various max packet sizes (OV511+ only) */
152 #define OV511PLUS_ALT_SIZE_0 0
153 #define OV511PLUS_ALT_SIZE_33 1
154 #define OV511PLUS_ALT_SIZE_129 2
155 #define OV511PLUS_ALT_SIZE_257 3
156 #define OV511PLUS_ALT_SIZE_385 4
157 #define OV511PLUS_ALT_SIZE_513 5
158 #define OV511PLUS_ALT_SIZE_769 6
159 #define OV511PLUS_ALT_SIZE_961 7
161 /* Alternate numbers for various max packet sizes (OV518(+) only) */
162 #define OV518_ALT_SIZE_0 0
163 #define OV518_ALT_SIZE_128 1
164 #define OV518_ALT_SIZE_256 2
165 #define OV518_ALT_SIZE_384 3
166 #define OV518_ALT_SIZE_512 4
167 #define OV518_ALT_SIZE_640 5
168 #define OV518_ALT_SIZE_768 6
169 #define OV518_ALT_SIZE_896 7
171 /* --------------------------------- */
172 /* OV7610 REGISTER MNEMONICS */
173 /* --------------------------------- */
175 /* OV7610 registers */
176 #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
177 #define OV7610_REG_BLUE 0x01 /* blue channel balance */
178 #define OV7610_REG_RED 0x02 /* red channel balance */
179 #define OV7610_REG_SAT 0x03 /* saturation */
181 #define OV7610_REG_CNT 0x05 /* Y contrast */
182 #define OV7610_REG_BRT 0x06 /* Y brightness */
184 #define OV7610_REG_BLUE_BIAS 0x0C /* blue channel bias (5:0) */
185 #define OV7610_REG_RED_BIAS 0x0D /* read channel bias (5:0) */
186 #define OV7610_REG_GAMMA_COEFF 0x0E /* gamma settings */
187 #define OV7610_REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
188 #define OV7610_REG_EXP 0x10 /* manual exposure setting */
189 #define OV7610_REG_CLOCK 0x11 /* polarity/clock prescaler */
190 #define OV7610_REG_COM_A 0x12 /* misc common regs */
191 #define OV7610_REG_COM_B 0x13 /* misc common regs */
192 #define OV7610_REG_COM_C 0x14 /* misc common regs */
193 #define OV7610_REG_COM_D 0x15 /* misc common regs */
194 #define OV7610_REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
195 #define OV7610_REG_HWIN_START 0x17 /* horizontal window start */
196 #define OV7610_REG_HWIN_END 0x18 /* horizontal window end */
197 #define OV7610_REG_VWIN_START 0x19 /* vertical window start */
198 #define OV7610_REG_VWIN_END 0x1A /* vertical window end */
199 #define OV7610_REG_PIXEL_SHIFT 0x1B /* pixel shift */
200 #define OV7610_REG_ID_HIGH 0x1C /* manufacturer ID MSB */
201 #define OV7610_REG_ID_LOW 0x1D /* manufacturer ID LSB */
203 #define OV7610_REG_COM_E 0x20 /* misc common regs */
204 #define OV7610_REG_YOFFSET 0x21 /* Y channel offset */
205 #define OV7610_REG_UOFFSET 0x22 /* U channel offset */
207 #define OV7610_REG_ECW 0x24 /* Exposure white level for AEC */
208 #define OV7610_REG_ECB 0x25 /* Exposure black level for AEC */
209 #define OV7610_REG_COM_F 0x26 /* misc settings */
210 #define OV7610_REG_COM_G 0x27 /* misc settings */
211 #define OV7610_REG_COM_H 0x28 /* misc settings */
212 #define OV7610_REG_COM_I 0x29 /* misc settings */
213 #define OV7610_REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
214 #define OV7610_REG_FRAMERATE_L 0x2B /* frame rate LSB */
215 #define OV7610_REG_ALC 0x2C /* Auto Level Control settings */
216 #define OV7610_REG_COM_J 0x2D /* misc settings */
217 #define OV7610_REG_VOFFSET 0x2E /* V channel offset adjustment */
218 #define OV7610_REG_ARRAY_BIAS 0x2F /* Array bias -- don't change */
220 #define OV7610_REG_YGAMMA 0x33 /* misc gamma settings (7:6) */
221 #define OV7610_REG_BIAS_ADJUST 0x34 /* misc bias settings */
222 #define OV7610_REG_COM_L 0x35 /* misc settings */
224 #define OV7610_REG_COM_K 0x38 /* misc registers */
226 /* --------------------------------- */
228 /* --------------------------------- */
230 #define OV7xx0_SID 0x42
231 #define OV6xx0_SID 0xC0
232 #define OV8xx0_SID 0xA0
233 #define KS0127_SID 0xD8
234 #define SAA7111A_SID 0x48
236 /* --------------------------------- */
237 /* MISCELLANEOUS DEFINES */
238 /* --------------------------------- */
240 #define I2C_CLOCK_PRESCALER 0x03
242 #define FRAMES_PER_DESC 10 /* FIXME - What should this be? */
243 #define MAX_FRAME_SIZE_PER_DESC 993 /* For statically allocated stuff */
244 #define PIXELS_PER_SEG 256 /* Pixels per segment */
246 #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
248 #define OV511_NUMFRAMES 2
249 #if OV511_NUMFRAMES > VIDEO_MAX_FRAME
250 #error "OV511_NUMFRAMES is too high"
253 #define OV511_NUMSBUF 2
255 /* Control transfers use up to 4 bytes */
256 #define OV511_CBUF_SIZE 4
258 /* Size of usb_make_path() buffer */
259 #define OV511_USB_PATH_LEN 64
295 STATE_SCANNING, /* Scanning for start */
296 STATE_HEADER, /* Parsing header */
297 STATE_LINES, /* Parsing lines */
306 /* --------- Definition of ioctl interface --------- */
308 #define OV511_INTERFACE_VER 101
317 /* Raw frame formats */
326 struct ov511_i2c_struct {
327 unsigned char slave; /* Write slave ID (read ID - 1) */
328 unsigned char reg; /* Index of register */
329 unsigned char value; /* User sets this w/ write, driver does w/ read */
330 unsigned char mask; /* Bits to be changed. Not used with read ops */
334 #define OV511IOC_WI2C _IOW('v', BASE_VIDIOCPRIVATE + 5, \
335 struct ov511_i2c_struct)
336 #define OV511IOC_RI2C _IOWR('v', BASE_VIDIOCPRIVATE + 6, \
337 struct ov511_i2c_struct)
338 /* ------------- End IOCTL interface -------------- */
340 struct usb_ov511; /* Forward declaration */
343 struct usb_ov511 *ov;
351 FRAME_UNUSED, /* Unused (no MCAPTURE) */
352 FRAME_READY, /* Ready to start grabbing */
353 FRAME_GRABBING, /* In the process of being grabbed into */
354 FRAME_DONE, /* Finished grabbing, but not been synced yet */
355 FRAME_ERROR, /* Something bad happened while processing */
358 struct ov511_regvals {
369 int framenum; /* Index of this frame */
370 unsigned char *data; /* Frame buffer */
371 unsigned char *tempdata; /* Temp buffer for multi-stage conversions */
372 unsigned char *rawdata; /* Raw camera data buffer */
373 unsigned char *compbuf; /* Temp buffer for decompressor */
375 int depth; /* Bytes per pixel */
376 int width; /* Width application is expecting */
377 int height; /* Height application is expecting */
379 int rawwidth; /* Actual width of frame sent from camera */
380 int rawheight; /* Actual height of frame sent from camera */
382 int sub_flag; /* Sub-capture mode for this frame? */
383 unsigned int format; /* Format for this frame */
384 int compressed; /* Is frame compressed? */
386 volatile int grabstate; /* State of grabbing */
387 int scanstate; /* State of scanning */
389 int bytes_recvd; /* Number of image bytes received from camera */
391 long bytes_read; /* Amount that has been read() */
393 wait_queue_head_t wq; /* Processes waiting */
395 int snapshot; /* True if frame was a snapshot */
398 #define DECOMP_INTERFACE_VER 4
400 /* Compression module operations */
401 struct ov51x_decomp_ops {
402 int (*decomp_400)(unsigned char *, unsigned char *, unsigned char *,
404 int (*decomp_420)(unsigned char *, unsigned char *, unsigned char *,
406 int (*decomp_422)(unsigned char *, unsigned char *, unsigned char *,
408 struct module *owner;
412 struct video_device *vdev;
413 struct usb_device *dev;
418 char usb_path[OV511_USB_PATH_LEN];
420 /* Determined by sensor type */
432 int auto_brt; /* Auto brightness enabled flag */
433 int auto_gain; /* Auto gain control enabled flag */
434 int auto_exp; /* Auto exposure enabled flag */
435 int backlight; /* Backlight exposure algorithm flag */
436 int mirror; /* Image is reversed horizontally */
438 int led_policy; /* LED: off|on|auto; OV511+ only */
440 struct mutex lock; /* Serializes user-accessible operations */
441 int user; /* user count for exclusive use */
443 int streaming; /* Are we streaming Isochronous? */
444 int grabbing; /* Are we grabbing? */
446 int compress; /* Should the next frame be compressed? */
447 int compress_inited; /* Are compression params uploaded? */
449 int lightfreq; /* Power (lighting) frequency */
450 int bandfilt; /* Banding filter enabled flag */
452 unsigned char *fbuf; /* Videodev buffer area */
453 unsigned char *tempfbuf; /* Temporary (intermediate) buffer area */
454 unsigned char *rawfbuf; /* Raw camera data buffer area */
456 int sub_flag; /* Pix Array subcapture on flag */
457 int subx; /* Pix Array subcapture x offset */
458 int suby; /* Pix Array subcapture y offset */
459 int subw; /* Pix Array subcapture width */
460 int subh; /* Pix Array subcapture height */
462 int curframe; /* Current receiving sbuf */
463 struct ov511_frame frame[OV511_NUMFRAMES];
465 struct ov511_sbuf sbuf[OV511_NUMSBUF];
467 wait_queue_head_t wq; /* Processes waiting */
469 int snap_enabled; /* Snapshot mode enabled */
471 int bridge; /* Type of bridge (BRG_*) */
472 int bclass; /* Class of bridge (BCL_*) */
473 int sensor; /* Type of image sensor chip (SEN_*) */
475 int packet_size; /* Frame size per isoc desc */
476 int packet_numbering; /* Is ISO frame numbering enabled? */
478 /* Framebuffer/sbuf management */
480 struct mutex buf_lock;
482 struct ov51x_decomp_ops *decomp_ops;
484 /* Stop streaming while changing picture settings */
487 int stopped; /* Streaming is temporarily paused */
489 /* Video decoder stuff */
490 int input; /* Composite, S-VIDEO, etc... */
491 int num_inputs; /* Number of inputs */
492 int norm; /* NTSC / PAL / SECAM */
493 int has_decoder; /* Device has a video decoder */
494 int pal; /* Device is designed for PAL resolution */
497 struct mutex i2c_lock; /* Protect I2C controller regs */
498 unsigned char primary_i2c_slave; /* I2C write id of sensor */
500 /* Control transaction stuff */
501 unsigned char *cbuf; /* Buffer for payload */
502 struct mutex cbuf_lock;
505 /* Used to represent a list of values and their respective symbolic names */
506 struct symbolic_list {
511 #define NOT_DEFINED_STR "Unknown"
513 /* Returns the name of the matching element in the symbolic_list array. The
514 * end of the list must be marked with an element that has a NULL name.
517 symbolic(struct symbolic_list list[], int num)
521 for (i = 0; list[i].name != NULL; i++)
522 if (list[i].num == num)
523 return (list[i].name);
525 return (NOT_DEFINED_STR);
528 /* Compression stuff */
530 #define OV511_QUANTABLESIZE 64
531 #define OV518_QUANTABLESIZE 32
533 #define OV511_YQUANTABLE { \
534 0, 1, 1, 2, 2, 3, 3, 4, \
535 1, 1, 1, 2, 2, 3, 4, 4, \
536 1, 1, 2, 2, 3, 4, 4, 4, \
537 2, 2, 2, 3, 4, 4, 4, 4, \
538 2, 2, 3, 4, 4, 5, 5, 5, \
539 3, 3, 4, 4, 5, 5, 5, 5, \
540 3, 4, 4, 4, 5, 5, 5, 5, \
541 4, 4, 4, 4, 5, 5, 5, 5 \
544 #define OV511_UVQUANTABLE { \
545 0, 2, 2, 3, 4, 4, 4, 4, \
546 2, 2, 2, 4, 4, 4, 4, 4, \
547 2, 2, 3, 4, 4, 4, 4, 4, \
548 3, 4, 4, 4, 4, 4, 4, 4, \
549 4, 4, 4, 4, 4, 4, 4, 4, \
550 4, 4, 4, 4, 4, 4, 4, 4, \
551 4, 4, 4, 4, 4, 4, 4, 4, \
552 4, 4, 4, 4, 4, 4, 4, 4 \
555 #define OV518_YQUANTABLE { \
556 5, 4, 5, 6, 6, 7, 7, 7, \
557 5, 5, 5, 5, 6, 7, 7, 7, \
558 6, 6, 6, 6, 7, 7, 7, 8, \
559 7, 7, 6, 7, 7, 7, 8, 8 \
562 #define OV518_UVQUANTABLE { \
563 6, 6, 6, 7, 7, 7, 7, 7, \
564 6, 6, 6, 7, 7, 7, 7, 7, \
565 6, 6, 6, 7, 7, 7, 7, 8, \
566 7, 7, 7, 7, 7, 7, 8, 8 \