blob: ca2754a3cd63d83eefb8927ae072f6732e852716 [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
Al Viro3b6456d2012-07-14 13:49:40 +0400175struct zoran_fh;
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177struct zoran_mapping {
Al Viro3b6456d2012-07-14 13:49:40 +0400178 struct zoran_fh *fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 int count;
180};
181
Trent Piepho1159b7f2009-03-10 23:28:16 -0300182struct zoran_buffer {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 struct zoran_mapping *map;
Trent Piepho1159b7f2009-03-10 23:28:16 -0300184 enum zoran_buffer_state state; /* state: unused/pending/dma/done */
185 struct zoran_sync bs; /* DONE: info to return to application */
186 union {
187 struct {
188 __le32 *frag_tab; /* addresses of frag table */
189 u32 frag_tab_bus; /* same value cached to save time in ISR */
190 } jpg;
191 struct {
192 char *fbuffer; /* virtual address of frame buffer */
193 unsigned long fbuffer_phys;/* physical address of frame buffer */
194 unsigned long fbuffer_bus;/* bus address of frame buffer */
195 } v4l;
196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
199enum zoran_lock_activity {
200 ZORAN_FREE, /* free for use */
201 ZORAN_ACTIVE, /* active but unlocked */
202 ZORAN_LOCKED, /* locked */
203};
204
205/* buffer collections */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300206struct zoran_buffer_col {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 enum zoran_lock_activity active; /* feature currently in use? */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300208 unsigned int num_buffers, buffer_size;
209 struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 u8 allocated; /* Flag if buffers are allocated */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 u8 need_contiguous; /* Flag if contiguous buffers are needed */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300212 /* only applies to jpg buffers, raw buffers are always contiguous */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213};
214
215struct zoran;
216
217/* zoran_fh contains per-open() settings */
218struct zoran_fh {
219 struct zoran *zr;
220
Trent Piepho1159b7f2009-03-10 23:28:16 -0300221 enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 struct zoran_overlay_settings overlay_settings;
Trent Piepho1159b7f2009-03-10 23:28:16 -0300224 u32 *overlay_mask; /* overlay mask */
225 enum zoran_lock_activity overlay_active;/* feature currently in use? */
226
227 struct zoran_buffer_col buffers; /* buffers' info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233struct card_info {
234 enum card_type type;
235 char name[32];
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300236 const char *i2c_decoder; /* i2c decoder device */
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300237 const unsigned short *addrs_decoder;
238 const char *i2c_encoder; /* i2c encoder device */
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300239 const unsigned short *addrs_encoder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 u16 video_vfe, video_codec; /* videocodec types */
241 u16 audio_chip; /* audio type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 int inputs; /* number of video inputs */
244 struct input {
245 int muxsel;
246 char name[32];
247 } input[BUZ_MAX_INPUT];
248
Hans Verkuil107063c2009-02-18 17:26:06 -0300249 v4l2_std_id norms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 struct tvnorm *tvn[3]; /* supported TV norms */
251
252 u32 jpeg_int; /* JPEG interrupt */
253 u32 vsync_int; /* VSYNC interrupt */
Mauro Carvalho Chehab61658942008-02-15 18:41:06 -0300254 s8 gpio[ZR_GPIO_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 u8 gpcs[GPCS_MAX];
256
257 struct vfe_polarity vfe_pol;
Mauro Carvalho Chehab61658942008-02-15 18:41:06 -0300258 u8 gpio_pol[ZR_GPIO_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300260 /* is the /GWS line connected? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 u8 gws_not_connected;
262
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300263 /* avs6eyes mux setting */
264 u8 input_mux;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 void (*init) (struct zoran * zr);
267};
268
269struct zoran {
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300270 struct v4l2_device v4l2_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 struct video_device *video_dev;
272
273 struct i2c_adapter i2c_adapter; /* */
274 struct i2c_algo_bit_data i2c_algo; /* */
275 u32 i2cbr;
276
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300277 struct v4l2_subdev *decoder; /* video decoder sub-device */
278 struct v4l2_subdev *encoder; /* video encoder sub-device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 struct videocodec *codec; /* video codec */
281 struct videocodec *vfe; /* video front end */
282
Ingo Molnar384c3682006-03-22 03:54:16 -0300283 struct mutex resource_lock; /* prevent evil stuff */
Arnd Bergmann0edf2e52010-10-27 09:30:32 -0300284 struct mutex other_lock; /* please merge with above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Uwe Kleine-König421f91d2010-06-11 12:17:00 +0200286 u8 initialized; /* flag if zoran has been correctly initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 int user; /* number of current users */
288 struct card_info card;
289 struct tvnorm *timing;
290
291 unsigned short id; /* number of this device */
292 char name[32]; /* name of this device */
293 struct pci_dev *pci_dev; /* PCI device */
294 unsigned char revision; /* revision of zr36057 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
296
297 spinlock_t spinlock; /* Spinlock */
298
299 /* Video for Linux parameters */
Hans Verkuildebff5a2010-03-22 05:25:46 -0300300 int input; /* card's norm and input */
Hans Verkuil107063c2009-02-18 17:26:06 -0300301 v4l2_std_id norm;
Hans Verkuil7f6adea2009-02-19 17:31:17 -0300302
303 /* Current buffer params */
304 void *vbuf_base;
305 int vbuf_height, vbuf_width;
306 int vbuf_depth;
307 int vbuf_bytesperline;
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 struct zoran_overlay_settings overlay_settings;
310 u32 *overlay_mask; /* overlay mask */
311 enum zoran_lock_activity overlay_active; /* feature currently in use? */
312
313 wait_queue_head_t v4l_capq;
314
315 int v4l_overlay_active; /* Overlay grab is activated */
316 int v4l_memgrab_active; /* Memory grab is activated */
317
318 int v4l_grab_frame; /* Frame number being currently grabbed */
319#define NO_GRAB_ACTIVE (-1)
320 unsigned long v4l_grab_seq; /* Number of frames grabbed */
321 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
322
323 /* V4L grab queue of frames pending */
324 unsigned long v4l_pend_head;
325 unsigned long v4l_pend_tail;
326 unsigned long v4l_sync_tail;
327 int v4l_pend[V4L_MAX_FRAME];
Trent Piepho1159b7f2009-03-10 23:28:16 -0300328 struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /* Buz MJPEG parameters */
331 enum zoran_codec_mode codec_mode; /* status of codec */
332 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
333
334 wait_queue_head_t jpg_capq; /* wait here for grab to finish */
335
336 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
337 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
338 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
339 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
340 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
341 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
342 unsigned long jpg_que_tail; /* Index of last buffer in queue */
343 unsigned long jpg_seq_num; /* count of frames since grab/play started */
344 unsigned long jpg_err_seq; /* last seq_num before error */
345 unsigned long jpg_err_shift;
346 unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
347
348 /* zr36057's code buffer table */
Al Viro581a7f12008-05-21 00:32:31 -0300349 __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
352 int jpg_pend[BUZ_MAX_FRAME];
353
354 /* array indexed by frame number */
Trent Piepho1159b7f2009-03-10 23:28:16 -0300355 struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 /* Additional stuff for testing */
358#ifdef CONFIG_PROC_FS
359 struct proc_dir_entry *zoran_proc;
360#else
361 void *zoran_proc;
362#endif
363 int testing;
364 int jpeg_error;
365 int intr_counter_GIRQ1;
366 int intr_counter_GIRQ0;
367 int intr_counter_CodRepIRQ;
368 int intr_counter_JPEGRepIRQ;
369 int field_counter;
370 int IRQ1_in;
371 int IRQ1_out;
372 int JPEG_in;
373 int JPEG_out;
374 int JPEG_0;
375 int JPEG_1;
376 int END_event_missed;
377 int JPEG_missed;
378 int JPEG_error;
379 int num_errors;
380 int JPEG_max_missed;
381 int JPEG_min_missed;
382
383 u32 last_isr;
384 unsigned long frame_num;
385
386 wait_queue_head_t test_q;
387};
388
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300389static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
390{
391 return container_of(v4l2_dev, struct zoran, v4l2_dev);
392}
393
Trent Piepho5e098b62009-01-12 13:09:46 -0300394/* There was something called _ALPHA_BUZ that used the PCI address instead of
395 * the kernel iomapped address for btread/btwrite. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
397#define btread(adr) readl(zr->zr36057_mem+(adr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
400#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
401#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#endif