1/*
2 * ov51x.h, part of ov51x driver
3 *
4 * Copyright (c) 1999-2003 Mark W. McClelland
5 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach <joerg@heckenbach-aw.de>
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 *    This program is distributed in the hope that it will be useful,
13 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *    GNU General Public License for more details.
16 *
17 *    You should have received a copy of the GNU General Public License
18 *    along with this program; if not, write to the Free Software
19 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23#ifndef __LINUX_OV51X_H
24#define __LINUX_OV51X_H
25
26#include <asm/uaccess.h>
27#include <linux/videodev.h>
28#include <linux/smp_lock.h>
29#include <linux/usb.h>
30
31#define OV511_DEBUG	/* Turn on debug messages */
32
33#ifdef OV511_DEBUG
34	#define PDEBUG(level, fmt, args...) \
35		if (debug >= (level)) info("[%s:%d] " fmt, \
36		__PRETTY_FUNCTION__, __LINE__ , ## args)
37#else
38	#define PDEBUG(level, fmt, args...) do {} while(0)
39#endif
40
41/* This macro restricts an int variable to an inclusive range */
42#define RESTRICT_TO_RANGE(v,mi,ma) { \
43	if ((v) < (mi)) (v) = (mi); \
44	else if ((v) > (ma)) (v) = (ma); \
45}
46
47/* --------------------------------- */
48/* DEFINES FOR OV511 AND OTHER CHIPS */
49/* --------------------------------- */
50
51/* USB IDs */
52#define VEND_OMNIVISION	0x05A9
53#define PROD_OV511		0x0511
54#define PROD_OV511PLUS	0xA511
55#define PROD_OV518		0x0518
56#define PROD_OV518PLUS	0xA518
57#define PROD_OV519		0x0519
58/* Alternate OV519 Products IDs. There are 14 of these. They will be given
59 * sequentially increasing letters (starting at 'A') as they are discovered */
60#define PROD_OV519A		0x8519
61
62#define VEND_MATTEL		0x0813
63#define PROD_ME2CAM		0x0002
64
65#define VEND_SONY		0x054c
66#define PROD_EYETOY		0x0155
67
68
69/* --------------------------------- */
70/*      DEVICE IMPLEMENTATIONS       */
71/* --------------------------------- */
72
73enum {
74	IMP_GENERIC,
75	IMP_EYETOY,
76};
77
78/* --------------------------------- */
79/*     OV51x REGISTER MNEMONICS      */
80/* --------------------------------- */
81
82/* Camera interface register numbers */
83#define R511_CAM_DELAY		0x10
84#define R511_CAM_EDGE		0x11
85#define R511_CAM_PXCNT		0x12
86#define R511_CAM_LNCNT		0x13
87#define R511_CAM_PXDIV		0x14
88#define R511_CAM_LNDIV		0x15
89#define R511_CAM_UV_EN		0x16
90#define R511_CAM_LINE_MODE	0x17
91#define R511_CAM_OPTS		0x18
92
93/* Snapshot mode camera interface register numbers */
94#define R511_SNAP_FRAME		0x19
95#define R511_SNAP_PXCNT		0x1A
96#define R511_SNAP_LNCNT		0x1B
97#define R511_SNAP_PXDIV		0x1C
98#define R511_SNAP_LNDIV		0x1D
99#define R511_SNAP_UV_EN		0x1E
100#define R511_SNAP_OPTS		0x1F
101
102/* DRAM register numbers */
103#define R511_DRAM_FLOW_CTL	0x20
104#define R511_DRAM_ARCP		0x21
105#define R511_DRAM_MRC		0x22
106#define R511_DRAM_RFC		0x23
107
108/* ISO FIFO register numbers */
109#define R51x_FIFO_PSIZE		0x30	/* 2 bytes wide w/ OV518(+) */
110#define R511_FIFO_OPTS		0x31
111
112/* Parallel IO register numbers */
113#define R511_PIO_OPTS		0x38
114#define R511_PIO_DATA		0x39
115#define R511_PIO_BIST		0x3E
116#define R518_GPIO_IN		0x55	/* OV518(+) only */
117#define R518_GPIO_OUT		0x56	/* OV518(+) only */
118#define R518_GPIO_CTL		0x57	/* OV518(+) only */
119#define R518_GPIO_PULSE_IN	0x58	/* OV518(+) only */
120#define R518_GPIO_PULSE_CLEAR	0x59	/* OV518(+) only */
121#define R518_GPIO_PULSE_POL	0x5a	/* OV518(+) only */
122#define R518_GPIO_PULSE_EN	0x5b	/* OV518(+) only */
123#define R518_GPIO_RESET		0x5c	/* OV518(+) only */
124
125/* I2C registers */
126#define R511_I2C_CTL		0x40
127#define R518_I2C_CTL		0x47	/* OV518(+) only */
128#define R51x_I2C_W_SID		0x41
129#define R51x_I2C_SADDR_3	0x42
130#define R51x_I2C_SADDR_2	0x43
131#define R51x_I2C_R_SID		0x44
132#define R51x_I2C_DATA		0x45
133#define R51x_I2C_CLOCK		0x46
134#define R51x_I2C_TIMEOUT	0x47
135
136/* I2C snapshot registers */
137#define R511_SI2C_SADDR_3	0x48
138#define R511_SI2C_DATA		0x49
139
140/* System control registers */
141#define R51x_SYS_RESET		0x50
142		/* Reset type definitions */
143#define	OV511_RESET_UDC		0x01
144#define	OV511_RESET_I2C		0x02
145#define	OV511_RESET_FIFO	0x04
146#define	OV511_RESET_OMNICE	0x08
147#define	OV511_RESET_DRAM	0x10
148#define	OV511_RESET_CAM_INT	0x20
149#define	OV511_RESET_OV511	0x40
150#define	OV511_RESET_NOREGS	0x3F /* All but OV511 & regs */
151#define	OV511_RESET_ALL		0x7F
152
153#define R511_SYS_CLOCK_DIV	0x51
154#define R51x_SYS_SNAP		0x52
155#define R51x_SYS_INIT         	0x53
156#define R511_SYS_PWR_CLK	0x54 /* OV511+/OV518(+) only */
157#define R511_SYS_LED_CTL	0x55 /* OV511+ only */
158#define R511_SYS_USER		0x5E
159#define R511_SYS_CUST_ID	0x5F
160
161/* OmniCE (compression) registers */
162#define R511_COMP_PHY		0x70
163#define R511_COMP_PHUV		0x71
164#define R511_COMP_PVY		0x72
165#define R511_COMP_PVUV		0x73
166#define R511_COMP_QHY		0x74
167#define R511_COMP_QHUV		0x75
168#define R511_COMP_QVY		0x76
169#define R511_COMP_QVUV		0x77
170#define R511_COMP_EN		0x78
171#define R511_COMP_LUT_EN	0x79
172#define R511_COMP_LUT_BEGIN	0x80
173
174// OV519 Camera interface register numbers
175#define OV519_CAM_H_SIZE		0x10
176#define OV519_CAM_V_SIZE		0x11
177#define OV519_CAM_X_OFFSETL		0x12
178#define OV519_CAM_X_OFFSETH		0x13
179#define OV519_CAM_Y_OFFSETL		0x14
180#define OV519_CAM_Y_OFFSETH		0x15
181#define OV519_CAM_DIVIDER		0x16
182#define OV519_CAM_DFR			0x20
183#define OV519_CAM_SR			0x21
184#define OV519_CAM_FRAR			0x22
185#define OV519_CAM_FORMAT		0x25
186
187// OV519 System Controller register numbers
188#define OV519_SYS_RESET0		0x50
189#define OV519_SYS_RESET1		0x51
190#define OV519_SYS_EN_CLK0		0x53
191#define OV519_SYS_EN_CLK1		0x54
192#define OV519_SYS_AUDIO_CLK		0x55
193#define OV519_SYS_SNAPSHOT		0x57
194#define OV519_SYS_PONOFF		0x58
195#define OV519_SYS_CAMERA_CLK	0x59
196#define OV519_SYS_CTRL1			0x5A
197#define OV519_SYS_DEB_CLK		0x5B
198#define OV519_SYS_CLK			0x5C
199#define OV519_SYS_PWDN			0x5D
200#define OV519_SYS_USR_DFN		0x5E
201#define OV519_SYS_CTRL2			0x5F
202#define OV519_SYS_INTERRUPT0	0x60
203#define OV519_SYS_INTERRUPT1	0x61
204#define OV519_SYS_MASK0			0x62
205#define OV519_SYS_MASK1			0x63
206#define OV519_SYS_VCI_R0		0x64
207#define OV519_SYS_VCI_R1		0x65
208#define OV519_SYS_ADC_CTRL		0x68
209#define OV519_SYS_UC_CTRL		0x6D
210
211/* OV519 GPIO register numbers */
212#define OV519_GPIO_DATA_OUT0		0x71
213#define OV519_GPIO_IO_CTRL0		0x72
214
215/* --------------------------------- */
216/*         ALTERNATE NUMBERS         */
217/* --------------------------------- */
218
219/* Alternate numbers for various max packet sizes (OV511 only) */
220#define OV511_ALT_SIZE_992	0
221#define OV511_ALT_SIZE_993	1
222#define OV511_ALT_SIZE_768	2
223#define OV511_ALT_SIZE_769	3
224#define OV511_ALT_SIZE_512	4
225#define OV511_ALT_SIZE_513	5
226#define OV511_ALT_SIZE_257	6
227#define OV511_ALT_SIZE_0	7
228
229/* Alternate numbers for various max packet sizes (OV511+ only) */
230#define OV511PLUS_ALT_SIZE_0	0
231#define OV511PLUS_ALT_SIZE_33	1
232#define OV511PLUS_ALT_SIZE_129	2
233#define OV511PLUS_ALT_SIZE_257	3
234#define OV511PLUS_ALT_SIZE_385	4
235#define OV511PLUS_ALT_SIZE_513	5
236#define OV511PLUS_ALT_SIZE_769	6
237#define OV511PLUS_ALT_SIZE_961	7
238
239/* Alternate numbers for various max packet sizes (OV518(+) only) */
240#define OV518_ALT_SIZE_0	0
241#define OV518_ALT_SIZE_128	1
242#define OV518_ALT_SIZE_256	2
243#define OV518_ALT_SIZE_384	3
244#define OV518_ALT_SIZE_512	4
245#define OV518_ALT_SIZE_640	5
246#define OV518_ALT_SIZE_768	6
247#define OV518_ALT_SIZE_896	7
248
249/* Alternate numbers for various max packet sizes (OV519 only) */
250#define OV519_ALT_SIZE_0	0
251#define OV519_ALT_SIZE_384	1
252#define OV519_ALT_SIZE_512	2
253#define OV519_ALT_SIZE_768	3
254#define OV519_ALT_SIZE_896	4
255
256/* --------------------------------- */
257/*     OV7610 REGISTER MNEMONICS     */
258/* --------------------------------- */
259
260/* OV7610 registers */
261#define OV7610_REG_GAIN          0x00	/* gain setting (5:0) */
262#define OV7610_REG_BLUE          0x01	/* blue channel balance */
263#define OV7610_REG_RED           0x02	/* red channel balance */
264#define OV7610_REG_SAT           0x03	/* saturation */
265#define OV8610_REG_HUE           0x04	/* 04 reserved */
266#define OV7610_REG_CNT           0x05	/* Y contrast */
267#define OV7610_REG_BRT           0x06	/* Y brightness */
268					/* 08-0b reserved */
269#define OV7610_REG_BLUE_BIAS     0x0C	/* blue channel bias (5:0) */
270#define OV7610_REG_RED_BIAS      0x0D	/* read channel bias (5:0) */
271#define OV7610_REG_GAMMA_COEFF   0x0E	/* gamma settings */
272#define OV7610_REG_WB_RANGE      0x0F	/* AEC/ALC/S-AWB settings */
273#define OV7610_REG_EXP           0x10	/* manual exposure setting */
274#define OV7610_REG_CLOCK         0x11	/* polarity/clock prescaler */
275#define OV7610_REG_COM_A         0x12	/* misc common regs */
276#define OV7610_REG_COM_B         0x13	/* misc common regs */
277#define OV7610_REG_COM_C         0x14	/* misc common regs */
278#define OV7610_REG_COM_D         0x15	/* misc common regs */
279#define OV7610_REG_FIELD_DIVIDE  0x16	/* field interval/mode settings */
280#define OV7610_REG_HWIN_START    0x17	/* horizontal window start */
281#define OV7610_REG_HWIN_END      0x18	/* horizontal window end */
282#define OV7610_REG_VWIN_START    0x19	/* vertical window start */
283#define OV7610_REG_VWIN_END      0x1A	/* vertical window end */
284#define OV7610_REG_PIXEL_SHIFT   0x1B	/* pixel shift */
285#define OV7610_REG_ID_HIGH       0x1C	/* manufacturer ID MSB */
286#define OV7610_REG_ID_LOW        0x1D	/* manufacturer ID LSB */
287					/* 0e-0f reserved */
288#define OV7610_REG_COM_E         0x20	/* misc common regs */
289#define OV7610_REG_YOFFSET       0x21	/* Y channel offset */
290#define OV7610_REG_UOFFSET       0x22	/* U channel offset */
291					/* 23 reserved */
292#define OV7610_REG_ECW           0x24	/* Exposure white level for AEC */
293#define OV7610_REG_ECB           0x25	/* Exposure black level for AEC */
294#define OV7610_REG_COM_F         0x26	/* misc settings */
295#define OV7610_REG_COM_G         0x27	/* misc settings */
296#define OV7610_REG_COM_H         0x28	/* misc settings */
297#define OV7610_REG_COM_I         0x29	/* misc settings */
298#define OV7610_REG_FRAMERATE_H   0x2A	/* frame rate MSB + misc */
299#define OV7610_REG_FRAMERATE_L   0x2B	/* frame rate LSB */
300#define OV7610_REG_ALC           0x2C	/* Auto Level Control settings */
301#define OV7610_REG_COM_J         0x2D	/* misc settings */
302#define OV7610_REG_VOFFSET       0x2E	/* V channel offset adjustment */
303#define OV7610_REG_ARRAY_BIAS	 0x2F	/* Array bias -- don't change */
304					/* 30-32 reserved */
305#define OV7610_REG_YGAMMA        0x33	/* misc gamma settings (7:6) */
306#define OV7610_REG_BIAS_ADJUST   0x34	/* misc bias settings */
307#define OV7610_REG_COM_L         0x35	/* misc settings */
308					/* 36-37 reserved */
309#define OV7610_REG_COM_K         0x38	/* misc registers */
310
311/* --------------------------------- */
312/*           I2C ADDRESSES           */
313/* --------------------------------- */
314
315#define OV7xx0_SID   0x42
316#define OV6xx0_SID   0xC0
317#define OV8xx0_SID   0xA0
318#define OV_HIRES_SID 0x60
319#define KS0127_SID   0xD8
320#define SAA7111A_SID 0x48
321
322/* --------------------------------- */
323/*       MISCELLANEOUS DEFINES       */
324/* --------------------------------- */
325
326#define FRAMES_PER_DESC		10	/* FIXME - What should this be? */
327#define MAX_FRAME_SIZE_PER_DESC	993	/* For statically allocated stuff */
328#define OV511_ENDPOINT_ADDRESS	1	/* Isoc endpoint number */
329#define OV511_NUMSBUF		2
330
331#define OV511_NUMFRAMES	2
332#if OV511_NUMFRAMES > VIDEO_MAX_FRAME
333	#error "OV511_NUMFRAMES is too high"
334#endif
335
336/* Control transfers use up to 4 bytes */
337#define OV511_CBUF_SIZE		4
338
339#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 20)
340	/* Size of usb_make_path() buffer */
341	#define OV511_USB_PATH_LEN	64
342#endif
343
344/* Bridge types */
345enum {
346	BRG_UNKNOWN,
347	BRG_OV511,
348	BRG_OV511PLUS,
349	BRG_OV518,
350	BRG_OV518PLUS,
351	BRG_OV519,
352};
353
354/* Bridge classes */
355enum {
356	BCL_UNKNOWN,
357	BCL_OV511,
358	BCL_OV518,
359	BCL_OV519,
360};
361
362/* Sensor types */
363enum {
364	SEN_UNKNOWN,
365	SEN_OV76BE,
366	SEN_OV7610,
367	SEN_OV7620,
368	SEN_OV7620AE,
369	SEN_OV7630,
370	SEN_OV7640,
371	SEN_OV6620,
372	SEN_OV6630,
373	SEN_OV6630AE,
374	SEN_OV6630AF,
375	SEN_OV8600,
376	SEN_OV8610,
377	SEN_KS0127,
378	SEN_KS0127B,
379	SEN_SAA7111A,
380};
381
382enum {
383	STATE_SCANNING,		/* Scanning for start */
384	STATE_HEADER,		/* Parsing header */
385	STATE_LINES,		/* Parsing lines */
386};
387
388/* Buffer states */
389enum {
390	BUF_NOT_ALLOCATED,
391	BUF_ALLOCATED,
392};
393
394/* --------- Definition of ioctl interface --------- */
395
396#define OV511_INTERFACE_VER 101
397
398/* LED options */
399enum {
400	LED_OFF,
401	LED_ON,
402	LED_AUTO,
403};
404
405/* Raw frame formats */
406enum {
407	RAWFMT_INVALID,
408	RAWFMT_YUV400,
409	RAWFMT_YUV420,
410	RAWFMT_YUV422,
411	RAWFMT_GBR422,
412};
413
414/* Unsigned short option numbers */
415enum {
416	OV511_USOPT_INVALID,
417	OV511_USOPT_BRIGHT,
418	OV511_USOPT_SAT,
419	OV511_USOPT_HUE,
420	OV511_USOPT_CONTRAST,
421};
422
423/* Unsigned int option numbers */
424enum {
425	OV511_UIOPT_INVALID,
426	OV511_UIOPT_POWER_FREQ,
427	OV511_UIOPT_BFILTER,
428	OV511_UIOPT_LED,
429	OV511_UIOPT_DEBUG,
430	OV511_UIOPT_COMPRESS,
431	OV511_UIOPT_LED2,
432};
433
434struct ov511_ushort_opt {
435	int optnum;		/* Specific option number */
436	unsigned short val;
437};
438
439struct ov511_uint_opt {
440	int optnum;		/* Specific option number */
441	unsigned int val;
442};
443
444struct ov511_i2c_struct {
445	unsigned char slave; /* Write slave ID (read ID - 1) */
446	unsigned char reg;   /* Index of register */
447	unsigned char value; /* User sets this w/ write, driver does w/ read */
448	unsigned char mask;  /* Bits to be changed. Not used with read ops */
449};
450
451/* ioctls */
452#define OV511IOC_GINTVER  _IOR('v', BASE_VIDIOCPRIVATE + 0, int)
453#define OV511IOC_GUSHORT _IOWR('v', BASE_VIDIOCPRIVATE + 1, \
454			       struct ov511_ushort_opt)
455#define OV511IOC_SUSHORT  _IOW('v', BASE_VIDIOCPRIVATE + 2, \
456			       struct ov511_ushort_opt)
457#define OV511IOC_GUINT   _IOWR('v', BASE_VIDIOCPRIVATE + 3, \
458			       struct ov511_uint_opt)
459#define OV511IOC_SUINT    _IOW('v', BASE_VIDIOCPRIVATE + 4, \
460			       struct ov511_uint_opt)
461#define OV511IOC_WI2C     _IOW('v', BASE_VIDIOCPRIVATE + 5, \
462			       struct ov511_i2c_struct)
463#define OV511IOC_RI2C    _IOWR('v', BASE_VIDIOCPRIVATE + 6, \
464			       struct ov511_i2c_struct)
465/* ------------- End IOCTL interface -------------- */
466
467struct usb_ov511;		/* Forward declaration */
468
469struct ov511_sbuf {
470	struct usb_ov511 *ov;
471	unsigned char *data;
472	struct urb *urb;
473	spinlock_t lock;
474	int n;
475};
476
477enum {
478	FRAME_UNUSED,		/* Unused (no MCAPTURE) */
479	FRAME_READY,		/* Ready to start grabbing */
480	FRAME_GRABBING,		/* In the process of being grabbed into */
481	FRAME_DONE,		/* Finished grabbing, but not been synced yet */
482	FRAME_ERROR,		/* Something bad happened while processing */
483};
484
485struct ov511_regvals {
486	enum {
487		OV511_DONE_BUS,
488		OV511_REG_BUS,
489		OV511_I2C_BUS,
490	} bus;
491	unsigned char reg;
492	unsigned char val;
493};
494
495struct ov511_frame {
496	int framenum;		/* Index of this frame */
497	unsigned char *data;	/* Frame buffer */
498	unsigned char *tempdata; /* Temp buffer for multi-stage conversions */
499	unsigned char *rawdata;	/* Raw camera data buffer */
500	unsigned char *compbuf;	/* Temp buffer for decompressor */
501
502	int depth;		/* Bytes per pixel */
503	int width;		/* Width application is expecting */
504	int height;		/* Height application is expecting */
505
506	int rawwidth;		/* Actual width of frame sent from camera */
507	int rawheight;		/* Actual height of frame sent from camera */
508
509	int sub_flag;		/* Sub-capture mode for this frame? */
510	unsigned int format;	/* Format for this frame */
511	int compressed;		/* Is frame compressed? */
512
513	volatile int grabstate;	/* State of grabbing */
514	int scanstate;		/* State of scanning */
515
516	int bytes_recvd;	/* Number of image bytes received from camera */
517
518	long bytes_read;	/* Amount that has been read() */
519
520	wait_queue_head_t wq;	/* Processes waiting */
521
522	int snapshot;		/* True if frame was a snapshot */
523};
524
525#define DECOMP_INTERFACE_VER 4
526
527/* Compression module operations */
528struct ov51x_decomp_ops {
529	int (*decomp_400)(unsigned char *, unsigned char *, unsigned char *,
530			  int, int, int);
531	int (*decomp_420)(unsigned char *, unsigned char *, unsigned char *,
532			  int, int, int);
533	int (*decomp_422)(unsigned char *, unsigned char *, unsigned char *,
534			  int, int, int);
535	struct module *owner;
536};
537
538struct usb_ov511 {
539	struct video_device vdev;
540
541	/* Device structure */
542	struct usb_device *dev;
543
544	int customid;
545	char *desc;
546	int imp;		/* Custom device implementation */
547	unsigned char iface;
548#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 20)
549	char usb_path[OV511_USB_PATH_LEN];
550#endif
551
552	/* Determined by sensor type */
553	int maxwidth;
554	int maxheight;
555	int minwidth;
556	int minheight;
557
558	int brightness;
559	int colour;
560	int contrast;
561	int hue;
562	int whiteness;
563	int exposure;
564	int auto_brt;		/* Auto brightness enabled flag */
565	int auto_gain;		/* Auto gain control enabled flag */
566	int auto_exp;		/* Auto exposure enabled flag */
567	int backlight;		/* Backlight exposure algorithm flag */
568	int mirror;		/* Image is reversed horizontally */
569
570	int led_policy;		/* LED: off|on|auto; OV511+ and later only */
571	int led2_policy;	/* LED 2: off|on|auto; EyeToy only */
572
573	struct semaphore lock;	/* Serializes user-accessible operations */
574	int user;		/* user count for exclusive use */
575
576	int streaming;		/* Are we streaming Isochronous? */
577	int grabbing;		/* Are we grabbing? */
578
579	int compress;		/* Should the next frame be compressed? */
580	int compress_inited;	/* Are compression params uploaded? */
581
582	int lightfreq;		/* Power (lighting) frequency */
583	int bandfilt;		/* Banding filter enabled flag */
584
585	unsigned char *fbuf;	/* Videodev buffer area */
586	unsigned char *tempfbuf; /* Temporary (intermediate) buffer area */
587	unsigned char *rawfbuf;	/* Raw camera data buffer area */
588
589	int sub_flag;		/* Pix Array subcapture on flag */
590	int subx;		/* Pix Array subcapture x offset */
591	int suby;		/* Pix Array subcapture y offset */
592	int subw;		/* Pix Array subcapture width */
593	int subh;		/* Pix Array subcapture height */
594
595	int framerate;		/* current Framerate (OV519 only) */
596	int clockdiv;		/* clockdiv override for OV519 only */
597	int curframe;		/* Frame currently being written to */
598	struct ov511_frame frame[OV511_NUMFRAMES];
599
600	struct ov511_sbuf sbuf[OV511_NUMSBUF];
601
602	wait_queue_head_t wq;	/* Processes waiting */
603
604	int snap_enabled;	/* Snapshot mode enabled */
605
606	int bridge;		/* Type of bridge (BRG_*) */
607	int bclass;		/* Class of bridge (BCL_*) */
608	int sensor;		/* Type of image sensor chip (SEN_*) */
609
610	int packet_size;	/* Frame size per isoc desc */
611	int packet_numbering;	/* Is ISO frame numbering enabled? */
612
613	struct semaphore param_lock;	/* params lock for this camera */
614
615	/* /proc entries, relative to /proc/video/ov511/ */
616	struct proc_dir_entry *proc_devdir;   /* Per-device proc directory */
617	struct proc_dir_entry *proc_info;     /* <minor#>/info entry */
618	struct proc_dir_entry *proc_button;   /* <minor#>/button entry */
619	struct proc_dir_entry *proc_control;  /* <minor#>/control entry */
620
621	/* Framebuffer/sbuf management */
622	int buf_state;
623	struct semaphore buf_lock;
624
625	struct ov51x_decomp_ops *decomp_ops;
626
627	/* Stop streaming while changing picture settings */
628	int stop_during_set;
629
630	int stopped;		/* Streaming is temporarily paused */
631
632	/* Video decoder stuff */
633	int input;		/* Composite, S-VIDEO, etc... */
634	int num_inputs;		/* Number of inputs */
635	int norm; 		/* NTSC / PAL / SECAM */
636	int has_decoder;	/* Device has a video decoder */
637	int pal;		/* Device is designed for PAL resolution */
638
639	/* I2C interface */
640	struct semaphore i2c_lock;	  /* Protect I2C controller regs */
641	unsigned char primary_i2c_slave;  /* I2C write id of sensor */
642
643	/* Control transaction stuff */
644	unsigned char *cbuf;		/* Buffer for payload */
645	struct semaphore cbuf_lock;
646};
647
648struct ovsensor_window {
649	int x;
650	int y;
651	int width;
652	int height;
653	int format;
654	int quarter;		/* Scale width and height down 2x */
655	int clockdiv;		/* Clock divisor setting */
656};
657
658/* Used to represent a list of values and their respective symbolic names */
659struct symbolic_list {
660	int num;
661	char *name;
662};
663
664#define NOT_DEFINED_STR "Unknown"
665
666/* Returns the name of the matching element in the symbolic_list array. The
667 * end of the list must be marked with an element that has a NULL name.
668 */
669static inline char *
670symbolic(struct symbolic_list list[], int num)
671{
672	int i;
673
674	for (i = 0; list[i].name != NULL; i++)
675			if (list[i].num == num)
676				return (list[i].name);
677
678	return (NOT_DEFINED_STR);
679}
680
681/* Compression stuff */
682
683#define OV511_QUANTABLESIZE	64
684#define OV518_QUANTABLESIZE	32
685
686#define OV511_YQUANTABLE { \
687	0, 1, 1, 2, 2, 3, 3, 4, \
688	1, 1, 1, 2, 2, 3, 4, 4, \
689	1, 1, 2, 2, 3, 4, 4, 4, \
690	2, 2, 2, 3, 4, 4, 4, 4, \
691	2, 2, 3, 4, 4, 5, 5, 5, \
692	3, 3, 4, 4, 5, 5, 5, 5, \
693	3, 4, 4, 4, 5, 5, 5, 5, \
694	4, 4, 4, 4, 5, 5, 5, 5  \
695}
696
697#define OV511_UVQUANTABLE { \
698	0, 2, 2, 3, 4, 4, 4, 4, \
699	2, 2, 2, 4, 4, 4, 4, 4, \
700	2, 2, 3, 4, 4, 4, 4, 4, \
701	3, 4, 4, 4, 4, 4, 4, 4, \
702	4, 4, 4, 4, 4, 4, 4, 4, \
703	4, 4, 4, 4, 4, 4, 4, 4, \
704	4, 4, 4, 4, 4, 4, 4, 4, \
705	4, 4, 4, 4, 4, 4, 4, 4  \
706}
707
708#define OV518_YQUANTABLE { \
709	5, 4, 5, 6, 6, 7, 7, 7, \
710	5, 5, 5, 5, 6, 7, 7, 7, \
711	6, 6, 6, 6, 7, 7, 7, 8, \
712	7, 7, 6, 7, 7, 7, 8, 8  \
713}
714
715#define OV518_UVQUANTABLE { \
716	6, 6, 6, 7, 7, 7, 7, 7, \
717	6, 6, 6, 7, 7, 7, 7, 7, \
718	6, 6, 6, 7, 7, 7, 7, 8, \
719	7, 7, 7, 7, 7, 7, 8, 8  \
720}
721
722#endif
723