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,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
14 * & Marcus Metzler (mocm@thp.uni-koeln.de)
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <media/v4l2-device.h>
35 #include <media/v4l2-ctrls.h>
36 #include <media/v4l2-fh.h>
39 unsigned long frame
; /* number of buffer that has been free'd */
40 unsigned long length
; /* number of code bytes in buffer (capture only) */
41 unsigned long seq
; /* frame sequence number */
42 struct timeval timestamp
; /* timestamp */
46 #define ZORAN_NAME "ZORAN" /* name of the device */
48 #define ZR_DEVNAME(zr) ((zr)->name)
50 #define BUZ_MAX_WIDTH (zr->timing->Wa)
51 #define BUZ_MAX_HEIGHT (zr->timing->Ha)
52 #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
53 #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
55 #define BUZ_NUM_STAT_COM 4
56 #define BUZ_MASK_STAT_COM 3
58 #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
59 #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
61 #define BUZ_MAX_INPUT 16
63 #if VIDEO_MAX_FRAME <= 32
64 # define V4L_MAX_FRAME 32
65 #elif VIDEO_MAX_FRAME <= 64
66 # define V4L_MAX_FRAME 64
68 # error "Too many video frame buffers to handle"
70 #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
72 #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
80 DC10_old
, /* DC30 like */
81 DC10_new
, /* DC10plus like */
86 /* Linux Media Labs */
96 /* total number of cards */
100 enum zoran_codec_mode
{
101 BUZ_MODE_IDLE
, /* nothing going on */
102 BUZ_MODE_MOTION_COMPRESS
, /* grabbing frames */
103 BUZ_MODE_MOTION_DECOMPRESS
, /* playing frames */
104 BUZ_MODE_STILL_COMPRESS
, /* still frame conversion */
105 BUZ_MODE_STILL_DECOMPRESS
/* still frame conversion */
108 enum zoran_buffer_state
{
109 BUZ_STATE_USER
, /* buffer is owned by application */
110 BUZ_STATE_PEND
, /* buffer is queued in pend[] ready to feed to I/O */
111 BUZ_STATE_DMA
, /* buffer is queued in dma[] for I/O */
112 BUZ_STATE_DONE
/* buffer is ready to return to application */
115 enum zoran_map_mode
{
117 ZORAN_MAP_MODE_JPG_REC
,
118 #define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
119 ZORAN_MAP_MODE_JPG_PLAY
,
123 ZR_GPIO_JPEG_SLEEP
= 0,
140 struct zoran_format
{
149 #define ZORAN_FORMAT_COMPRESSED 1<<0
150 #define ZORAN_FORMAT_OVERLAY 1<<1
151 #define ZORAN_FORMAT_CAPTURE 1<<2
152 #define ZORAN_FORMAT_PLAYBACK 1<<3
154 /* overlay-settings */
155 struct zoran_overlay_settings
{
157 int x
, y
, width
, height
; /* position */
158 int clipcount
; /* position and number of clips */
159 const struct zoran_format
*format
; /* overlay format */
162 /* v4l-capture settings */
163 struct zoran_v4l_settings
{
164 int width
, height
, bytesperline
; /* capture size */
165 const struct zoran_format
*format
; /* capture format */
168 /* jpg-capture/-playback settings */
169 struct zoran_jpg_settings
{
170 int decimation
; /* this bit is used to set everything to default */
171 int HorDcm
, VerDcm
, TmpDcm
; /* capture decimation settings (TmpDcm=1 means both fields) */
172 int field_per_buff
, odd_even
; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
173 int img_x
, img_y
, img_width
, img_height
; /* crop settings (subframe capture) */
174 struct v4l2_jpegcompression jpg_comp
; /* JPEG-specific capture settings */
179 struct zoran_mapping
{
184 struct zoran_buffer
{
185 struct zoran_mapping
*map
;
186 enum zoran_buffer_state state
; /* state: unused/pending/dma/done */
187 struct zoran_sync bs
; /* DONE: info to return to application */
190 __le32
*frag_tab
; /* addresses of frag table */
191 u32 frag_tab_bus
; /* same value cached to save time in ISR */
194 char *fbuffer
; /* virtual address of frame buffer */
195 unsigned long fbuffer_phys
;/* physical address of frame buffer */
196 unsigned long fbuffer_bus
;/* bus address of frame buffer */
201 enum zoran_lock_activity
{
202 ZORAN_FREE
, /* free for use */
203 ZORAN_ACTIVE
, /* active but unlocked */
204 ZORAN_LOCKED
, /* locked */
207 /* buffer collections */
208 struct zoran_buffer_col
{
209 enum zoran_lock_activity active
; /* feature currently in use? */
210 unsigned int num_buffers
, buffer_size
;
211 struct zoran_buffer buffer
[MAX_FRAME
]; /* buffers */
212 u8 allocated
; /* Flag if buffers are allocated */
213 u8 need_contiguous
; /* Flag if contiguous buffers are needed */
214 /* only applies to jpg buffers, raw buffers are always contiguous */
219 /* zoran_fh contains per-open() settings */
224 enum zoran_map_mode map_mode
; /* Flag which bufferset will map by next mmap() */
226 struct zoran_overlay_settings overlay_settings
;
227 u32
*overlay_mask
; /* overlay mask */
228 enum zoran_lock_activity overlay_active
;/* feature currently in use? */
230 struct zoran_buffer_col buffers
; /* buffers' info */
232 struct zoran_v4l_settings v4l_settings
; /* structure with a lot of things to play with */
233 struct zoran_jpg_settings jpg_settings
; /* structure with a lot of things to play with */
239 const char *i2c_decoder
; /* i2c decoder device */
240 const unsigned short *addrs_decoder
;
241 const char *i2c_encoder
; /* i2c encoder device */
242 const unsigned short *addrs_encoder
;
243 u16 video_vfe
, video_codec
; /* videocodec types */
244 u16 audio_chip
; /* audio type */
246 int inputs
; /* number of video inputs */
250 } input
[BUZ_MAX_INPUT
];
253 struct tvnorm
*tvn
[3]; /* supported TV norms */
255 u32 jpeg_int
; /* JPEG interrupt */
256 u32 vsync_int
; /* VSYNC interrupt */
257 s8 gpio
[ZR_GPIO_MAX
];
260 struct vfe_polarity vfe_pol
;
261 u8 gpio_pol
[ZR_GPIO_MAX
];
263 /* is the /GWS line connected? */
264 u8 gws_not_connected
;
266 /* avs6eyes mux setting */
269 void (*init
) (struct zoran
* zr
);
273 struct v4l2_device v4l2_dev
;
274 struct v4l2_ctrl_handler hdl
;
275 struct video_device
*video_dev
;
277 struct i2c_adapter i2c_adapter
; /* */
278 struct i2c_algo_bit_data i2c_algo
; /* */
281 struct v4l2_subdev
*decoder
; /* video decoder sub-device */
282 struct v4l2_subdev
*encoder
; /* video encoder sub-device */
284 struct videocodec
*codec
; /* video codec */
285 struct videocodec
*vfe
; /* video front end */
287 struct mutex lock
; /* file ops serialize lock */
289 u8 initialized
; /* flag if zoran has been correctly initialized */
290 int user
; /* number of current users */
291 struct card_info card
;
292 struct tvnorm
*timing
;
294 unsigned short id
; /* number of this device */
295 char name
[32]; /* name of this device */
296 struct pci_dev
*pci_dev
; /* PCI device */
297 unsigned char revision
; /* revision of zr36057 */
298 unsigned char __iomem
*zr36057_mem
;/* pointer to mapped IO memory */
300 spinlock_t spinlock
; /* Spinlock */
302 /* Video for Linux parameters */
303 int input
; /* card's norm and input */
306 /* Current buffer params */
308 int vbuf_height
, vbuf_width
;
310 int vbuf_bytesperline
;
312 struct zoran_overlay_settings overlay_settings
;
313 u32
*overlay_mask
; /* overlay mask */
314 enum zoran_lock_activity overlay_active
; /* feature currently in use? */
316 wait_queue_head_t v4l_capq
;
318 int v4l_overlay_active
; /* Overlay grab is activated */
319 int v4l_memgrab_active
; /* Memory grab is activated */
321 int v4l_grab_frame
; /* Frame number being currently grabbed */
322 #define NO_GRAB_ACTIVE (-1)
323 unsigned long v4l_grab_seq
; /* Number of frames grabbed */
324 struct zoran_v4l_settings v4l_settings
; /* structure with a lot of things to play with */
326 /* V4L grab queue of frames pending */
327 unsigned long v4l_pend_head
;
328 unsigned long v4l_pend_tail
;
329 unsigned long v4l_sync_tail
;
330 int v4l_pend
[V4L_MAX_FRAME
];
331 struct zoran_buffer_col v4l_buffers
; /* V4L buffers' info */
333 /* Buz MJPEG parameters */
334 enum zoran_codec_mode codec_mode
; /* status of codec */
335 struct zoran_jpg_settings jpg_settings
; /* structure with a lot of things to play with */
337 wait_queue_head_t jpg_capq
; /* wait here for grab to finish */
339 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
340 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
341 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
342 unsigned long jpg_que_head
; /* Index where to put next buffer which is queued */
343 unsigned long jpg_dma_head
; /* Index of next buffer which goes into stat_com */
344 unsigned long jpg_dma_tail
; /* Index of last buffer in stat_com */
345 unsigned long jpg_que_tail
; /* Index of last buffer in queue */
346 unsigned long jpg_seq_num
; /* count of frames since grab/play started */
347 unsigned long jpg_err_seq
; /* last seq_num before error */
348 unsigned long jpg_err_shift
;
349 unsigned long jpg_queued_num
; /* count of frames queued since grab/play started */
351 /* zr36057's code buffer table */
352 __le32
*stat_com
; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
354 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
355 int jpg_pend
[BUZ_MAX_FRAME
];
357 /* array indexed by frame number */
358 struct zoran_buffer_col jpg_buffers
; /* MJPEG buffers' info */
360 /* Additional stuff for testing */
361 #ifdef CONFIG_PROC_FS
362 struct proc_dir_entry
*zoran_proc
;
368 int intr_counter_GIRQ1
;
369 int intr_counter_GIRQ0
;
370 int intr_counter_CodRepIRQ
;
371 int intr_counter_JPEGRepIRQ
;
379 int END_event_missed
;
387 unsigned long frame_num
;
389 wait_queue_head_t test_q
;
392 static inline struct zoran
*to_zoran(struct v4l2_device
*v4l2_dev
)
394 return container_of(v4l2_dev
, struct zoran
, v4l2_dev
);
397 /* There was something called _ALPHA_BUZ that used the PCI address instead of
398 * the kernel iomapped address for btread/btwrite. */
399 #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
400 #define btread(adr) readl(zr->zr36057_mem+(adr))
402 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
403 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
404 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)