2 zoran - Iomega Buz driver
4 Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
8 zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
12 bttv - Bt848 frame grabber driver
13 Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de)
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.
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.
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.
33 #include <linux/config.h>
35 #if LINUX_VERSION_CODE < 0x20212
36 typedef struct wait_queue *wait_queue_head_t;
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 */
46 //#define BUZ_MAX_WIDTH 768 /* never display more than 768 pixels */
47 #define BUZ_MAX_WIDTH (zr->timing->Wa)
49 //#define BUZ_MAX_WIDTH 720 /* never display more than 720 pixels */
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 */
56 struct zoran_requestbuffers {
57 unsigned long count; /* Number of buffers for MJPEG grabbing */
58 unsigned long size; /* Size PER BUFFER in bytes */
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 */
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 */
77 /* The following parameters can only be queried */
79 int major_version; /* Major version number of driver */
80 int minor_version; /* Minor version number of driver */
82 /* Main control parameters */
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 */
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 */
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 */
108 /* --- End of parameters for decimation==0 only --- */
110 /* JPEG control parameters */
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
117 int odd_even; /* Which field should come first ??? */
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. */
123 int COM_len; /* Length of data in JPEG COM segment */
124 char COM_data[60]; /* Data in JPEG COM segment */
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
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 */
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 */
148 char reserved[312]; /* Makes 512 bytes for this structure */
152 Private IOCTL to set up for displaying MJPEG
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)
165 #define BUZ_NUM_STAT_COM 4
166 #define BUZ_MASK_STAT_COM 3
168 #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
169 #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
171 #if VIDEO_MAX_FRAME <= 32
172 # define V4L_MAX_FRAME 32
173 #elif VIDEO_MAX_FRAME <= 64
174 # define V4L_MAX_FRAME 64
176 # error "Too many video frame buffers to handle"
178 #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
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 */
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 */
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 */
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 */
221 u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
225 struct video_device video_dev;
228 int initialized; /* flag if zoran has been correctly initalized */
229 int user; /* number of current users (0 or 1) */
231 struct tvnorm *timing;
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 */
240 int map_mjpeg_buffers; /* Flag which bufferset will map by next mmap() */
242 spinlock_t lock; /* Spinlock irq and hardware */
243 struct semaphore sem; /* Guard parallel ioctls and mmap */
245 /* Video for Linux parameters */
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 */
254 wait_queue_head_t v4l_capq;
256 int v4l_overlay_active; /* Overlay grab is activated */
257 int v4l_memgrab_active; /* Memory grab is activated */
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 ... */
267 /* V4L grab queue of frames pending */
269 unsigned v4l_pend_head;
270 unsigned v4l_pend_tail;
271 int v4l_pend[V4L_MAX_FRAME];
273 struct v4l_gbuffer v4l_gbuf[VIDEO_MAX_FRAME]; /* V4L buffers' info */
275 /* Buz MJPEG parameters */
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 */
282 enum zoran_codec_mode codec_mode; /* status of codec */
283 struct zoran_params params; /* structure with a lot of things to play with */
285 wait_queue_head_t jpg_capq; /* wait here for grab to finish */
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 */
299 /* zr36057's code buffer table */
300 u32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
302 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
303 int jpg_pend[BUZ_MAX_FRAME];
305 /* array indexed by frame number */
306 struct zoran_gbuffer jpg_gbuf[BUZ_MAX_FRAME]; /* MJPEG buffers' info */
308 /* Additional stuff for testing */
309 struct proc_dir_entry *zoran_proc;
313 int intr_counter_GIRQ1;
314 int intr_counter_GIRQ0;
315 int intr_counter_CodRepIRQ;
316 int intr_counter_JPEGRepIRQ;
324 int END_event_missed;
332 unsigned long frame_num;
334 wait_queue_head_t test_q;
339 /*The following should be done in more portable way. It depends on define
340 of _ALPHA_BUZ in the Makefile.*/
343 #define btwrite(dat,adr) writel((dat),(char *) (zr->zr36057_adr+(adr)))
344 #define btread(adr) readl(zr->zr36057_adr+(adr))
346 #define btwrite(dat,adr) writel((dat), (char *) (zr->zr36057_mem+(adr)))
347 #define btread(adr) readl(zr->zr36057_mem+(adr))
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)
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
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