blob: d7166afc255edf06ea7396b6efc12b91da92fca3 [file] [log] [blame]
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -03001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
14 * & Marcus Metzler (mocm@thp.uni-koeln.de)
15 *
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.
20 *
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.
25 *
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.
29 */
30
31#ifndef _BUZ_H_
32#define _BUZ_H_
33
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -030034#include <media/v4l2-device.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036struct zoran_sync {
37 unsigned long frame; /* number of buffer that has been free'd */
38 unsigned long length; /* number of code bytes in buffer (capture only) */
39 unsigned long seq; /* frame sequence number */
40 struct timeval timestamp; /* timestamp */
41};
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define ZORAN_NAME "ZORAN" /* name of the device */
45
46#define ZR_DEVNAME(zr) ((zr)->name)
47
48#define BUZ_MAX_WIDTH (zr->timing->Wa)
49#define BUZ_MAX_HEIGHT (zr->timing->Ha)
50#define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
51#define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
52
53#define BUZ_NUM_STAT_COM 4
54#define BUZ_MASK_STAT_COM 3
55
56#define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
57#define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
58
Martin Samuelssonfbe60da2006-04-27 10:17:00 -030059#define BUZ_MAX_INPUT 16
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#if VIDEO_MAX_FRAME <= 32
62# define V4L_MAX_FRAME 32
63#elif VIDEO_MAX_FRAME <= 64
64# define V4L_MAX_FRAME 64
65#else
66# error "Too many video frame buffers to handle"
67#endif
68#define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
69
Trent Piepho1159b7f2009-03-10 23:28:16 -030070#define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "zr36057.h"
73
74enum card_type {
75 UNKNOWN = -1,
76
77 /* Pinnacle/Miro */
78 DC10_old, /* DC30 like */
79 DC10_new, /* DC10plus like */
80 DC10plus,
81 DC30,
82 DC30plus,
83
84 /* Linux Media Labs */
85 LML33,
86 LML33R10,
87
88 /* Iomega */
89 BUZ,
90
Martin Samuelssonfbe60da2006-04-27 10:17:00 -030091 /* AverMedia */
92 AVS6EYES,
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 /* total number of cards */
95 NUM_CARDS
96};
97
98enum zoran_codec_mode {
99 BUZ_MODE_IDLE, /* nothing going on */
100 BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
101 BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
102 BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
103 BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
104};
105
106enum zoran_buffer_state {
107 BUZ_STATE_USER, /* buffer is owned by application */
108 BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */
109 BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */
110 BUZ_STATE_DONE /* buffer is ready to return to application */
111};
112
113enum zoran_map_mode {
114 ZORAN_MAP_MODE_RAW,
115 ZORAN_MAP_MODE_JPG_REC,
116#define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
117 ZORAN_MAP_MODE_JPG_PLAY,
118};
119
120enum gpio_type {
Mauro Carvalho Chehab61658942008-02-15 18:41:06 -0300121 ZR_GPIO_JPEG_SLEEP = 0,
122 ZR_GPIO_JPEG_RESET,
123 ZR_GPIO_JPEG_FRAME,
124 ZR_GPIO_VID_DIR,
125 ZR_GPIO_VID_EN,
126 ZR_GPIO_VID_RESET,
127 ZR_GPIO_CLK_SEL1,
128 ZR_GPIO_CLK_SEL2,
129 ZR_GPIO_MAX,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
132enum gpcs_type {
133 GPCS_JPEG_RESET = 0,
134 GPCS_JPEG_START,
135 GPCS_MAX,
136};
137
138struct zoran_format {
139 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 __u32 fourcc;
141 int colorspace;
142 int depth;
143 __u32 flags;
Trent Piepho603d6f22007-07-17 18:29:44 -0300144 __u32 vfespfr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146/* flags */
147#define ZORAN_FORMAT_COMPRESSED 1<<0
148#define ZORAN_FORMAT_OVERLAY 1<<1
149#define ZORAN_FORMAT_CAPTURE 1<<2
150#define ZORAN_FORMAT_PLAYBACK 1<<3
151
152/* overlay-settings */
153struct zoran_overlay_settings {
154 int is_set;
155 int x, y, width, height; /* position */
156 int clipcount; /* position and number of clips */
157 const struct zoran_format *format; /* overlay format */
158};
159
160/* v4l-capture settings */
161struct zoran_v4l_settings {
162 int width, height, bytesperline; /* capture size */
163 const struct zoran_format *format; /* capture format */
164};
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* jpg-capture/-playback settings */
167struct zoran_jpg_settings {
168 int decimation; /* this bit is used to set everything to default */
169 int HorDcm, VerDcm, TmpDcm; /* capture decimation settings (TmpDcm=1 means both fields) */
170 int field_per_buff, odd_even; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
171 int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
172 struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
173};
174
175struct zoran_mapping {
176 struct file *file;
177 int count;
178};
179
Trent Piepho1159b7f2009-03-10 23:28:16 -0300180struct zoran_buffer {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 struct zoran_mapping *map;
Trent Piepho1159b7f2009-03-10 23:28:16 -0300182 enum zoran_buffer_state state; /* state: unused/pending/dma/done */
183 struct zoran_sync bs; /* DONE: info to return to application */
184 union {
185 struct {
186 __le32 *frag_tab; /* addresses of frag table */
187 u32 frag_tab_bus; /* same value cached to save time in ISR */
188 } jpg;
189 struct {
190 char *fbuffer; /* virtual address of frame buffer */
191 unsigned long fbuffer_phys;/* physical address of frame buffer */
192 unsigned long fbuffer_bus;/* bus address of frame buffer */
193 } v4l;
194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195};
196
197enum zoran_lock_activity {
198 ZORAN_FREE, /* free for use */
199 ZORAN_ACTIVE, /* active but unlocked */
200 ZORAN_LOCKED, /* locked */
201};
202
203/* buffer collections */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300204struct zoran_buffer_col {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 enum zoran_lock_activity active; /* feature currently in use? */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300206 unsigned int num_buffers, buffer_size;
207 struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 u8 allocated; /* Flag if buffers are allocated */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 u8 need_contiguous; /* Flag if contiguous buffers are needed */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300210 /* only applies to jpg buffers, raw buffers are always contiguous */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211};
212
213struct zoran;
214
215/* zoran_fh contains per-open() settings */
216struct zoran_fh {
217 struct zoran *zr;
218
Trent Piepho1159b7f2009-03-10 23:28:16 -0300219 enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 struct zoran_overlay_settings overlay_settings;
Trent Piepho1159b7f2009-03-10 23:28:16 -0300222 u32 *overlay_mask; /* overlay mask */
223 enum zoran_lock_activity overlay_active;/* feature currently in use? */
224
225 struct zoran_buffer_col buffers; /* buffers' info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229};
230
231struct card_info {
232 enum card_type type;
233 char name[32];
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300234 const char *i2c_decoder; /* i2c decoder device */
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300235 const unsigned short *addrs_decoder;
236 const char *i2c_encoder; /* i2c encoder device */
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300237 const unsigned short *addrs_encoder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 u16 video_vfe, video_codec; /* videocodec types */
239 u16 audio_chip; /* audio type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 int inputs; /* number of video inputs */
242 struct input {
243 int muxsel;
244 char name[32];
245 } input[BUZ_MAX_INPUT];
246
Hans Verkuil107063c2009-02-18 17:26:06 -0300247 v4l2_std_id norms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 struct tvnorm *tvn[3]; /* supported TV norms */
249
250 u32 jpeg_int; /* JPEG interrupt */
251 u32 vsync_int; /* VSYNC interrupt */
Mauro Carvalho Chehab61658942008-02-15 18:41:06 -0300252 s8 gpio[ZR_GPIO_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 u8 gpcs[GPCS_MAX];
254
255 struct vfe_polarity vfe_pol;
Mauro Carvalho Chehab61658942008-02-15 18:41:06 -0300256 u8 gpio_pol[ZR_GPIO_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300258 /* is the /GWS line connected? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 u8 gws_not_connected;
260
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300261 /* avs6eyes mux setting */
262 u8 input_mux;
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 void (*init) (struct zoran * zr);
265};
266
267struct zoran {
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300268 struct v4l2_device v4l2_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 struct video_device *video_dev;
270
271 struct i2c_adapter i2c_adapter; /* */
272 struct i2c_algo_bit_data i2c_algo; /* */
273 u32 i2cbr;
274
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300275 struct v4l2_subdev *decoder; /* video decoder sub-device */
276 struct v4l2_subdev *encoder; /* video encoder sub-device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 struct videocodec *codec; /* video codec */
279 struct videocodec *vfe; /* video front end */
280
Ingo Molnar384c3682006-03-22 03:54:16 -0300281 struct mutex resource_lock; /* prevent evil stuff */
Arnd Bergmann0edf2e52010-10-27 09:30:32 -0300282 struct mutex other_lock; /* please merge with above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Uwe Kleine-König421f91d2010-06-11 12:17:00 +0200284 u8 initialized; /* flag if zoran has been correctly initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 int user; /* number of current users */
286 struct card_info card;
287 struct tvnorm *timing;
288
289 unsigned short id; /* number of this device */
290 char name[32]; /* name of this device */
291 struct pci_dev *pci_dev; /* PCI device */
292 unsigned char revision; /* revision of zr36057 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
294
295 spinlock_t spinlock; /* Spinlock */
296
297 /* Video for Linux parameters */
Hans Verkuildebff5a2010-03-22 05:25:46 -0300298 int input; /* card's norm and input */
Hans Verkuil107063c2009-02-18 17:26:06 -0300299 v4l2_std_id norm;
Hans Verkuil7f6adea2009-02-19 17:31:17 -0300300
301 /* Current buffer params */
302 void *vbuf_base;
303 int vbuf_height, vbuf_width;
304 int vbuf_depth;
305 int vbuf_bytesperline;
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 struct zoran_overlay_settings overlay_settings;
308 u32 *overlay_mask; /* overlay mask */
309 enum zoran_lock_activity overlay_active; /* feature currently in use? */
310
311 wait_queue_head_t v4l_capq;
312
313 int v4l_overlay_active; /* Overlay grab is activated */
314 int v4l_memgrab_active; /* Memory grab is activated */
315
316 int v4l_grab_frame; /* Frame number being currently grabbed */
317#define NO_GRAB_ACTIVE (-1)
318 unsigned long v4l_grab_seq; /* Number of frames grabbed */
319 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
320
321 /* V4L grab queue of frames pending */
322 unsigned long v4l_pend_head;
323 unsigned long v4l_pend_tail;
324 unsigned long v4l_sync_tail;
325 int v4l_pend[V4L_MAX_FRAME];
Trent Piepho1159b7f2009-03-10 23:28:16 -0300326 struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Buz MJPEG parameters */
329 enum zoran_codec_mode codec_mode; /* status of codec */
330 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
331
332 wait_queue_head_t jpg_capq; /* wait here for grab to finish */
333
334 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
335 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
336 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
337 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
338 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
339 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
340 unsigned long jpg_que_tail; /* Index of last buffer in queue */
341 unsigned long jpg_seq_num; /* count of frames since grab/play started */
342 unsigned long jpg_err_seq; /* last seq_num before error */
343 unsigned long jpg_err_shift;
344 unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
345
346 /* zr36057's code buffer table */
Al Viro581a7f12008-05-21 00:32:31 -0300347 __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
350 int jpg_pend[BUZ_MAX_FRAME];
351
352 /* array indexed by frame number */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300353 struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 /* Additional stuff for testing */
356#ifdef CONFIG_PROC_FS
357 struct proc_dir_entry *zoran_proc;
358#else
359 void *zoran_proc;
360#endif
361 int testing;
362 int jpeg_error;
363 int intr_counter_GIRQ1;
364 int intr_counter_GIRQ0;
365 int intr_counter_CodRepIRQ;
366 int intr_counter_JPEGRepIRQ;
367 int field_counter;
368 int IRQ1_in;
369 int IRQ1_out;
370 int JPEG_in;
371 int JPEG_out;
372 int JPEG_0;
373 int JPEG_1;
374 int END_event_missed;
375 int JPEG_missed;
376 int JPEG_error;
377 int num_errors;
378 int JPEG_max_missed;
379 int JPEG_min_missed;
380
381 u32 last_isr;
382 unsigned long frame_num;
383
384 wait_queue_head_t test_q;
385};
386
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300387static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
388{
389 return container_of(v4l2_dev, struct zoran, v4l2_dev);
390}
391
Trent Piepho5e098b62009-01-12 13:09:46 -0300392/* There was something called _ALPHA_BUZ that used the PCI address instead of
393 * the kernel iomapped address for btread/btwrite. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
395#define btread(adr) readl(zr->zr36057_mem+(adr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
398#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
399#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#endif