2 buz - Iomega Buz driver
4 Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
8 buz.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 /* The Buz only supports a maximum width of 720, but some V4L
34 applications (e.g. xawtv are more happy with 768).
35 If XAWTV_HACK is defined, we try to fake a device with bigger width */
40 //#define BUZ_MAX_WIDTH 768 /* never display more than 768 pixels */
41 #define BUZ_MAX_WIDTH (tvnorms[btv->params.norm].Wa)
43 //#define BUZ_MAX_WIDTH 720 /* never display more than 720 pixels */
45 //#define BUZ_MAX_HEIGHT 576 /* never display more than 576 rows */
46 #define BUZ_MAX_HEIGHT (tvnorms[btv->params.norm].Ha)
47 #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
48 #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
50 struct buz_requestbuffers
52 unsigned long count
; /* Number of buffers for MJPEG grabbing */
53 unsigned long size
; /* Size PER BUFFER in bytes */
58 unsigned long frame
; /* number of buffer that has been free'd */
59 unsigned long length
; /* number of code bytes in buffer (capture only) */
60 unsigned long seq
; /* frame sequence number */
61 struct timeval timestamp
; /* timestamp */
66 int input
; /* Input channel, has to be set prior to BUZIOC_G_STATUS */
67 int signal
; /* Returned: 1 if valid video signal detected */
68 int norm
; /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
69 int color
; /* Returned: 1 if color signal detected */
75 /* The following parameters can only be queried */
77 int major_version
; /* Major version number of driver */
78 int minor_version
; /* Minor version number of driver */
80 /* Main control parameters */
82 int input
; /* Input channel: 0 = Composite, 1 = S-VHS */
83 int norm
; /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
84 int decimation
; /* decimation of captured video,
85 enlargement of video played back.
86 Valid values are 1, 2, 4 or 0.
87 0 is a special value where the user
88 has full control over video scaling */
90 /* The following parameters only have to be set if decimation==0,
91 for other values of decimation they provide the data how the image is captured */
93 int HorDcm
; /* Horizontal decimation: 1, 2 or 4 */
94 int VerDcm
; /* Vertical decimation: 1 or 2 */
95 int TmpDcm
; /* Temporal decimation: 1 or 2,
96 if TmpDcm==2 in capture every second frame is dropped,
97 in playback every frame is played twice */
98 int field_per_buff
; /* Number of fields per buffer: 1 or 2 */
99 int img_x
; /* start of image in x direction */
100 int img_y
; /* start of image in y direction */
101 int img_width
; /* image width BEFORE decimation,
102 must be a multiple of HorDcm*16 */
103 int img_height
; /* image height BEFORE decimation,
104 must be a multiple of VerDcm*8 */
106 /* --- End of parameters for decimation==0 only --- */
108 /* JPEG control parameters */
110 int quality
; /* Measure for quality of compressed images.
111 Scales linearly with the size of the compressed images.
112 Must be beetween 0 and 100, 100 is a compression
115 int odd_even
; /* Which field should come first ??? */
117 int APPn
; /* Number of APP segment to be written, must be 0..15 */
118 int APP_len
; /* Length of data in JPEG APPn segment */
119 char APP_data
[60]; /* Data in the JPEG APPn segment. */
121 int COM_len
; /* Length of data in JPEG COM segment */
122 char COM_data
[60]; /* Data in JPEG COM segment */
124 unsigned long jpeg_markers
; /* Which markers should go into the JPEG output.
125 Unless you exactly know what you do, leave them untouched.
126 Inluding less markers will make the resulting code
127 smaller, but there will be fewer aplications
129 The presence of the APP and COM marker is
130 influenced by APP0_len and COM_len ONLY! */
131 #define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
132 #define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
133 #define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
134 #define JPEG_MARKER_COM (1<<6) /* Comment segment */
135 #define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
137 int VFIFO_FB
; /* Flag for enabling Video Fifo Feedback.
138 If this flag is turned on and JPEG decompressing
139 is going to the screen, the decompress process
140 is stopped every time the Video Fifo is full.
141 This enables a smooth decompress to the screen
142 but the video output signal will get scrambled */
146 char reserved
[312]; /* Makes 512 bytes for this structure */
150 Private IOCTL to set up for displaying MJPEG
152 #define BUZIOC_G_PARAMS _IOR ('v', BASE_VIDIOCPRIVATE+0, struct buz_params)
153 #define BUZIOC_S_PARAMS _IOWR('v', BASE_VIDIOCPRIVATE+1, struct buz_params)
154 #define BUZIOC_REQBUFS _IOWR('v', BASE_VIDIOCPRIVATE+2, struct buz_requestbuffers)
155 #define BUZIOC_QBUF_CAPT _IOW ('v', BASE_VIDIOCPRIVATE+3, int)
156 #define BUZIOC_QBUF_PLAY _IOW ('v', BASE_VIDIOCPRIVATE+4, int)
157 #define BUZIOC_SYNC _IOR ('v', BASE_VIDIOCPRIVATE+5, struct buz_sync)
158 #define BUZIOC_G_STATUS _IOWR('v', BASE_VIDIOCPRIVATE+6, struct buz_status)
163 #define BUZ_NUM_STAT_COM 4
164 #define BUZ_MASK_STAT_COM 3
166 #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
167 #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
169 #if VIDEO_MAX_FRAME <= 32
170 # define V4L_MAX_FRAME 32
171 #elif VIDEO_MAX_FRAME <= 64
172 # define V4L_MAX_FRAME 64
174 # error "Too many video frame buffers to handle"
176 #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
183 BUZ_MODE_IDLE
, /* nothing going on */
184 BUZ_MODE_MOTION_COMPRESS
, /* grabbing frames */
185 BUZ_MODE_MOTION_DECOMPRESS
, /* playing frames */
186 BUZ_MODE_STILL_COMPRESS
, /* still frame conversion */
187 BUZ_MODE_STILL_DECOMPRESS
/* still frame conversion */
190 enum buz_buffer_state
192 BUZ_STATE_USER
, /* buffer is owned by application */
193 BUZ_STATE_PEND
, /* buffer is queued in pend[] ready to feed to I/O */
194 BUZ_STATE_DMA
, /* buffer is queued in dma[] for I/O */
195 BUZ_STATE_DONE
/* buffer is ready to return to application */
200 u32
* frag_tab
; /* addresses of frag table */
201 u32 frag_tab_bus
; /* same value cached to save time in ISR */
202 enum buz_buffer_state state
; /* non-zero if corresponding buffer is in use in grab queue */
203 struct buz_sync bs
; /* DONE: info to return to application */
208 char * fbuffer
; /* virtual address of frame buffer */
209 unsigned long fbuffer_phys
; /* physical address of frame buffer */
210 unsigned long fbuffer_bus
; /* bus address of frame buffer */
211 enum buz_buffer_state state
; /* state: unused/pending/done */
216 struct video_device video_dev
;
219 int initialized
; /* flag if buz has been correctly initalized */
220 int user
; /* number of current users (0 or 1) */
222 unsigned short id
; /* number of this device */
223 char name
[32]; /* name of this device */
224 struct pci_dev
*pci_dev
; /* PCI device */
225 unsigned char revision
; /* revision of zr36057 */
226 unsigned int zr36057_adr
; /* bus address of IO mem returned by PCI BIOS */
227 unsigned char *zr36057_mem
; /* pointer to mapped IO memory */
229 int map_mjpeg_buffers
; /* Flag which bufferset will map by next mmap() */
231 spinlock_t lock
; /* Spinlock */
233 /* Video for Linux parameters */
235 struct video_picture picture
; /* Current picture params */
236 struct video_buffer buffer
; /* Current buffer params */
237 struct video_window window
; /* Current window params */
238 int buffer_set
, window_set
; /* Flags if the above structures are set */
239 int video_interlace
; /* Image on screen is interlaced */
243 struct wait_queue
* v4l_capq
; /* wait here for grab to finish */
245 int v4l_overlay_active
; /* Overlay grab is activated */
246 int v4l_memgrab_active
; /* Memory grab is activated */
248 int v4l_grab_frame
; /* Frame number being currently grabbed */
249 #define NO_GRAB_ACTIVE (-1)
250 int v4l_grab_seq
; /* Number of frames grabbed */
251 int gwidth
; /* Width of current memory capture */
252 int gheight
; /* Height of current memory capture */
253 int gformat
; /* Format of ... */
254 int gbpl
; /* byte per line of ... */
256 /* V4L grab queue of frames pending */
258 unsigned v4l_pend_head
;
259 unsigned v4l_pend_tail
;
260 int v4l_pend
[V4L_MAX_FRAME
];
262 struct v4l_gbuffer v4l_gbuf
[VIDEO_MAX_FRAME
]; /* V4L buffers' info */
264 /* Buz MJPEG parameters */
266 unsigned long jpg_nbufs
; /* Number of buffers */
267 unsigned long jpg_bufsize
; /* Size of mjpeg buffers in bytes */
268 int jpg_buffers_allocated
; /* Flag if buffers are allocated */
269 int need_contiguous
; /* Flag if contiguous buffers are needed */
271 enum buz_codec_mode codec_mode
; /* status of codec */
272 struct buz_params params
; /* structure with a lot of things to play with */
274 struct wait_queue
* jpg_capq
; /* wait here for grab to finish */
276 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
277 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
278 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
279 unsigned long jpg_que_head
; /* Index where to put next buffer which is queued */
280 unsigned long jpg_dma_head
; /* Index of next buffer which goes into stat_com */
281 unsigned long jpg_dma_tail
; /* Index of last buffer in stat_com */
282 unsigned long jpg_que_tail
; /* Index of last buffer in queue */
283 unsigned long jpg_seq_num
; /* count of frames since grab/play started */
285 /* zr36057's code buffer table */
286 u32
* stat_com
; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
288 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
289 int jpg_pend
[BUZ_MAX_FRAME
];
291 /* array indexed by frame number */
292 struct buz_gbuffer jpg_gbuf
[BUZ_MAX_FRAME
]; /* MJPEG buffers' info */
294 /* Additional stuff for testing */
295 #ifdef CONFIG_PROC_FS
297 struct proc_dir_entry
*buz_proc
;
302 int intr_counter_GIRQ1
;
303 int intr_counter_GIRQ0
;
304 int intr_counter_CodRepIRQ
;
305 int intr_counter_JPEGRepIRQ
;
318 unsigned long frame_num
;
320 struct wait_queue
*test_q
;
325 /*The following should be done in more portable way. It depends on define
326 of _ALPHA_BUZ in the Makefile.*/
329 #define btwrite(dat,adr) writel((dat),(char *) (btv->zr36057_adr+(adr)))
330 #define btread(adr) readl(btv->zr36057_adr+(adr))
332 #define btwrite(dat,adr) writel((dat), (char *) (btv->zr36057_mem+(adr)))
333 #define btread(adr) readl(btv->zr36057_mem+(adr))
336 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
337 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
338 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
340 #define I2C_TSA5522 0xc2
341 #define I2C_TDA9850 0xb6
342 #define I2C_HAUPEE 0xa0
343 #define I2C_STBEE 0xae
344 #define I2C_SAA7111 0x48
345 #define I2C_SAA7110 0x9c
346 #define I2C_SAA7185 0x88
347 //#define I2C_ADV7175 0xd4
348 #define I2C_ADV7175 0x54
350 #define TDA9850_CON1 0x04
351 #define TDA9850_CON2 0x05
352 #define TDA9850_CON3 0x06
353 #define TDA9850_CON4 0x07
354 #define TDA9850_ALI1 0x08
355 #define TDA9850_ALI2 0x09
356 #define TDA9850_ALI3 0x0a