File: /usr/src/linux/drivers/media/video/zoran.h

1     /* 
2         zoran - Iomega Buz driver
3     
4         Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
5     
6        based on
7     
8         zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
9     
10        and
11     
12         bttv - Bt848 frame grabber driver
13         Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de)
14     
15         This program is free software; you can redistribute it and/or modify
16         it under the terms of the GNU General Public License as published by
17         the Free Software Foundation; either version 2 of the License, or
18         (at your option) any later version.
19     
20         This program is distributed in the hope that it will be useful,
21         but WITHOUT ANY WARRANTY; without even the implied warranty of
22         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23         GNU General Public License for more details.
24     
25         You should have received a copy of the GNU General Public License
26         along with this program; if not, write to the Free Software
27         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28     */
29     
30     #ifndef _BUZ_H_
31     #define _BUZ_H_
32     
33     #include <linux/config.h>
34     
35     #if LINUX_VERSION_CODE < 0x20212
36     typedef struct wait_queue *wait_queue_head_t;
37     #endif
38     
39     /* The Buz only supports a maximum width of 720, but some V4L
40        applications (e.g. xawtv are more happy with 768).
41        If XAWTV_HACK is defined, we try to fake a device with bigger width */
42     
43     //#define XAWTV_HACK
44     
45     //#ifdef XAWTV_HACK
46     //#define   BUZ_MAX_WIDTH   768   /* never display more than 768 pixels */
47     #define   BUZ_MAX_WIDTH   (zr->timing->Wa)
48     //#else
49     //#define   BUZ_MAX_WIDTH   720   /* never display more than 720 pixels */
50     //#endif
51     //#define   BUZ_MAX_HEIGHT  576   /* never display more than 576 rows */
52     #define   BUZ_MAX_HEIGHT  (zr->timing->Ha)
53     #define   BUZ_MIN_WIDTH    32	/* never display less than 32 pixels */
54     #define   BUZ_MIN_HEIGHT   24	/* never display less than 24 rows */
55     
56     struct zoran_requestbuffers {
57     	unsigned long count;	/* Number of buffers for MJPEG grabbing */
58     	unsigned long size;	/* Size PER BUFFER in bytes */
59     };
60     
61     struct zoran_sync {
62     	unsigned long frame;	/* number of buffer that has been free'd */
63     	unsigned long length;	/* number of code bytes in buffer (capture only) */
64     	unsigned long seq;	/* frame sequence number */
65     	struct timeval timestamp;	/* timestamp */
66     };
67     
68     struct zoran_status {
69     	int input;		/* Input channel, has to be set prior to BUZIOC_G_STATUS */
70     	int signal;		/* Returned: 1 if valid video signal detected */
71     	int norm;		/* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
72     	int color;		/* Returned: 1 if color signal detected */
73     };
74     
75     struct zoran_params {
76     
77     	/* The following parameters can only be queried */
78     
79     	int major_version;	/* Major version number of driver */
80     	int minor_version;	/* Minor version number of driver */
81     
82     	/* Main control parameters */
83     
84     	int input;		/* Input channel: 0 = Composite, 1 = S-VHS */
85     	int norm;		/* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
86     	int decimation;		/* decimation of captured video,
87     				   enlargement of video played back.
88     				   Valid values are 1, 2, 4 or 0.
89     				   0 is a special value where the user
90     				   has full control over video scaling */
91     
92     	/* The following parameters only have to be set if decimation==0,
93     	   for other values of decimation they provide the data how the image is captured */
94     
95     	int HorDcm;		/* Horizontal decimation: 1, 2 or 4 */
96     	int VerDcm;		/* Vertical decimation: 1 or 2 */
97     	int TmpDcm;		/* Temporal decimation: 1 or 2,
98     				   if TmpDcm==2 in capture every second frame is dropped,
99     				   in playback every frame is played twice */
100     	int field_per_buff;	/* Number of fields per buffer: 1 or 2 */
101     	int img_x;		/* start of image in x direction */
102     	int img_y;		/* start of image in y direction */
103     	int img_width;		/* image width BEFORE decimation,
104     				   must be a multiple of HorDcm*16 */
105     	int img_height;		/* image height BEFORE decimation,
106     				   must be a multiple of VerDcm*8 */
107     
108     	/* --- End of parameters for decimation==0 only --- */
109     
110     	/* JPEG control parameters */
111     
112     	int quality;		/* Measure for quality of compressed images.
113     				   Scales linearly with the size of the compressed images.
114     				   Must be beetween 0 and 100, 100 is a compression
115     				   ratio of 1:4 */
116     
117     	int odd_even;		/* Which field should come first ??? */
118     
119     	int APPn;		/* Number of APP segment to be written, must be 0..15 */
120     	int APP_len;		/* Length of data in JPEG APPn segment */
121     	char APP_data[60];	/* Data in the JPEG APPn segment. */
122     
123     	int COM_len;		/* Length of data in JPEG COM segment */
124     	char COM_data[60];	/* Data in JPEG COM segment */
125     
126     	unsigned long jpeg_markers;	/* Which markers should go into the JPEG output.
127     					   Unless you exactly know what you do, leave them untouched.
128     					   Inluding less markers will make the resulting code
129     					   smaller, but there will be fewer aplications
130     					   which can read it.
131     					   The presence of the APP and COM marker is
132     					   influenced by APP0_len and COM_len ONLY! */
133     #define JPEG_MARKER_DHT (1<<3)	/* Define Huffman Tables */
134     #define JPEG_MARKER_DQT (1<<4)	/* Define Quantization Tables */
135     #define JPEG_MARKER_DRI (1<<5)	/* Define Restart Interval */
136     #define JPEG_MARKER_COM (1<<6)	/* Comment segment */
137     #define JPEG_MARKER_APP (1<<7)	/* App segment, driver will allways use APP0 */
138     
139     	int VFIFO_FB;		/* Flag for enabling Video Fifo Feedback.
140     				   If this flag is turned on and JPEG decompressing
141     				   is going to the screen, the decompress process
142     				   is stopped every time the Video Fifo is full.
143     				   This enables a smooth decompress to the screen
144     				   but the video output signal will get scrambled */
145     
146     	/* Misc */
147     
148     	char reserved[312];	/* Makes 512 bytes for this structure */
149     };
150     
151     /*
152     Private IOCTL to set up for displaying MJPEG
153     */
154     #define BUZIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0,  struct zoran_params)
155     #define BUZIOC_S_PARAMS       _IOWR('v', BASE_VIDIOCPRIVATE+1,  struct zoran_params)
156     #define BUZIOC_REQBUFS        _IOWR('v', BASE_VIDIOCPRIVATE+2,  struct zoran_requestbuffers)
157     #define BUZIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+3,  int)
158     #define BUZIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOCPRIVATE+4,  int)
159     #define BUZIOC_SYNC           _IOR ('v', BASE_VIDIOCPRIVATE+5,  struct zoran_sync)
160     #define BUZIOC_G_STATUS       _IOWR('v', BASE_VIDIOCPRIVATE+6,  struct zoran_status)
161     
162     
163     #ifdef __KERNEL__
164     
165     #define BUZ_NUM_STAT_COM    4
166     #define BUZ_MASK_STAT_COM   3
167     
168     #define BUZ_MAX_FRAME     256	/* Must be a power of 2 */
169     #define BUZ_MASK_FRAME    255	/* Must be BUZ_MAX_FRAME-1 */
170     
171     #if VIDEO_MAX_FRAME <= 32
172     #   define   V4L_MAX_FRAME   32
173     #elif VIDEO_MAX_FRAME <= 64
174     #   define   V4L_MAX_FRAME   64
175     #else
176     #   error   "Too many video frame buffers to handle"
177     #endif
178     #define   V4L_MASK_FRAME   (V4L_MAX_FRAME - 1)
179     
180     
181     #include "zr36057.h"
182     
183     enum card_type {
184             UNKNOWN = 0,
185             DC10,
186             DC10plus,
187             LML33,
188             BUZ
189     };
190     
191     enum zoran_codec_mode {
192     	BUZ_MODE_IDLE,		/* nothing going on */
193     	BUZ_MODE_MOTION_COMPRESS,	/* grabbing frames */
194     	BUZ_MODE_MOTION_DECOMPRESS,	/* playing frames */
195     	BUZ_MODE_STILL_COMPRESS,	/* still frame conversion */
196     	BUZ_MODE_STILL_DECOMPRESS	/* still frame conversion */
197     };
198     
199     enum zoran_buffer_state {
200     	BUZ_STATE_USER,		/* buffer is owned by application */
201     	BUZ_STATE_PEND,		/* buffer is queued in pend[] ready to feed to I/O */
202     	BUZ_STATE_DMA,		/* buffer is queued in dma[] for I/O */
203     	BUZ_STATE_DONE		/* buffer is ready to return to application */
204     };
205     
206     struct zoran_gbuffer {
207     	u32 *frag_tab;		/* addresses of frag table */
208     	u32 frag_tab_bus;	/* same value cached to save time in ISR */
209     	enum zoran_buffer_state state;	/* non-zero if corresponding buffer is in use in grab queue */
210     	struct zoran_sync bs;	/* DONE: info to return to application */
211     };
212     
213     struct v4l_gbuffer {
214     	char *fbuffer;			/* virtual  address of frame buffer */
215     	unsigned long fbuffer_phys;	/* physical address of frame buffer */
216     	unsigned long fbuffer_bus;	/* bus      address of frame buffer */
217     	enum zoran_buffer_state state;	/* state: unused/pending/done */
218     };
219     
220     struct tvnorm {
221     	u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
222     };
223     
224     struct zoran {
225     	struct video_device video_dev;
226     	struct i2c_bus i2c;
227     
228     	int initialized;		/* flag if zoran has been correctly initalized */
229     	int user;			/* number of current users (0 or 1) */
230             enum card_type card;
231             struct tvnorm *timing;
232     
233     	unsigned short id;		/* number of this device */
234     	char name[32];			/* name of this device */
235     	struct pci_dev *pci_dev;	/* PCI device */
236     	unsigned char revision;		/* revision of zr36057 */
237     	unsigned int zr36057_adr;	/* bus address of IO mem returned by PCI BIOS */
238     	unsigned char *zr36057_mem;	/* pointer to mapped IO memory */
239     
240     	int map_mjpeg_buffers;		/* Flag which bufferset will map by next mmap() */
241     
242     	spinlock_t lock;		/* Spinlock irq and hardware */
243     	struct semaphore sem;		/* Guard parallel ioctls and mmap */
244     
245     	/* Video for Linux parameters */
246     
247     	struct video_picture picture;	/* Current picture params */
248     	struct video_buffer buffer;	/* Current buffer params */
249     	struct video_window window;	/* Current window params */
250     	int buffer_set, window_set;	/* Flags if the above structures are set */
251     	int video_interlace;		/* Image on screen is interlaced */
252     
253     	u32 *overlay_mask;
254             wait_queue_head_t v4l_capq;
255     
256     	int v4l_overlay_active;		/* Overlay grab is activated */
257     	int v4l_memgrab_active;		/* Memory grab is activated */
258     
259     	int v4l_grab_frame;		/* Frame number being currently grabbed */
260     #define NO_GRAB_ACTIVE (-1)
261     	int v4l_grab_seq;		/* Number of frames grabbed */
262     	int gwidth;			/* Width of current memory capture */
263     	int gheight;			/* Height of current memory capture */
264     	int gformat;			/* Format of ... */
265     	int gbpl;			/* byte per line of ... */
266     
267     	/* V4L grab queue of frames pending */
268     
269     	unsigned v4l_pend_head;
270     	unsigned v4l_pend_tail;
271     	int v4l_pend[V4L_MAX_FRAME];
272     
273     	struct v4l_gbuffer v4l_gbuf[VIDEO_MAX_FRAME];	/* V4L   buffers' info */
274     
275     	/* Buz MJPEG parameters */
276     
277     	unsigned long jpg_nbufs;	/* Number of buffers */
278     	unsigned long jpg_bufsize;	/* Size of mjpeg buffers in bytes */
279     	int jpg_buffers_allocated;	/* Flag if buffers are allocated  */
280     	int need_contiguous;	/* Flag if contiguous buffers are needed */
281     
282     	enum zoran_codec_mode codec_mode;	/* status of codec */
283     	struct zoran_params params;	/* structure with a lot of things to play with */
284     
285     	wait_queue_head_t jpg_capq;	/* wait here for grab to finish */
286     
287     	/* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
288     	/* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
289     	/* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
290     	unsigned long jpg_que_head;	/* Index where to put next buffer which is queued */
291     	unsigned long jpg_dma_head;	/* Index of next buffer which goes into stat_com  */
292     	unsigned long jpg_dma_tail;	/* Index of last buffer in stat_com               */
293     	unsigned long jpg_que_tail;	/* Index of last buffer in queue                  */
294     	unsigned long jpg_seq_num;	/* count of frames since grab/play started        */
295     	unsigned long jpg_err_seq;	/* last seq_num before error                      */
296     	unsigned long jpg_err_shift;
297     	unsigned long jpg_queued_num;	/* count of frames queued since grab/play started */
298     
299     	/* zr36057's code buffer table */
300     	u32 *stat_com;			/* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
301     
302     	/* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
303     	int jpg_pend[BUZ_MAX_FRAME];
304     
305     	/* array indexed by frame number */
306     	struct zoran_gbuffer jpg_gbuf[BUZ_MAX_FRAME];	/* MJPEG buffers' info */
307     
308     	/* Additional stuff for testing */
309     	struct proc_dir_entry *zoran_proc;
310     
311     	int testing;
312     	int jpeg_error;
313     	int intr_counter_GIRQ1;
314     	int intr_counter_GIRQ0;
315     	int intr_counter_CodRepIRQ;
316     	int intr_counter_JPEGRepIRQ;
317     	int field_counter;
318     	int IRQ1_in;
319     	int IRQ1_out;
320     	int JPEG_in;
321     	int JPEG_out;
322     	int JPEG_0;
323     	int JPEG_1;
324     	int END_event_missed;
325     	int JPEG_missed;
326     	int JPEG_error;
327     	int num_errors;
328     	int JPEG_max_missed;
329     	int JPEG_min_missed;
330     
331     	u32 last_isr;
332     	unsigned long frame_num;
333     
334     	wait_queue_head_t test_q;
335     };
336     
337     #endif
338     
339     /*The following should be done in more portable way. It depends on define
340       of _ALPHA_BUZ in the Makefile.*/
341     
342     #ifdef _ALPHA_BUZ
343     #define btwrite(dat,adr)    writel((dat),(char *) (zr->zr36057_adr+(adr)))
344     #define btread(adr)         readl(zr->zr36057_adr+(adr))
345     #else
346     #define btwrite(dat,adr)    writel((dat), (char *) (zr->zr36057_mem+(adr)))
347     #define btread(adr)         readl(zr->zr36057_mem+(adr))
348     #endif
349     
350     #define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
351     #define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
352     #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
353     
354     #define I2C_TSA5522        0xc2
355     #define I2C_TDA9850        0xb6
356     #define I2C_HAUPEE         0xa0
357     #define I2C_STBEE          0xae
358     #define   I2C_SAA7111        0x48
359     #define   I2C_SAA7110        0x9c
360     #define   I2C_SAA7185        0x88
361     //#define   I2C_ADV7175        0xd4
362     #define   I2C_ADV7175        0x54
363     
364     #define TDA9850_CON1       0x04
365     #define TDA9850_CON2       0x05
366     #define TDA9850_CON3       0x06
367     #define TDA9850_CON4       0x07
368     #define TDA9850_ALI1       0x08
369     #define TDA9850_ALI2       0x09
370     #define TDA9850_ALI3       0x0a
371     
372     #endif
373