]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/media/video/zoran/zoran.h
Merge branch 'docs-next' of git://git.lwn.net/linux-2.6
[mirror_ubuntu-hirsute-kernel.git] / drivers / media / video / zoran / zoran.h
CommitLineData
d56410e0 1/*
1da177e4
LT
2 * 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
0ab6e1c3
HV
34#include <media/v4l2-device.h>
35
debff5a7
HV
36#define ZORAN_VIDMODE_PAL 0
37#define ZORAN_VIDMODE_NTSC 1
38#define ZORAN_VIDMODE_SECAM 2
39
1da177e4
LT
40struct zoran_requestbuffers {
41 unsigned long count; /* Number of buffers for MJPEG grabbing */
42 unsigned long size; /* Size PER BUFFER in bytes */
43};
44
45struct zoran_sync {
46 unsigned long frame; /* number of buffer that has been free'd */
47 unsigned long length; /* number of code bytes in buffer (capture only) */
48 unsigned long seq; /* frame sequence number */
49 struct timeval timestamp; /* timestamp */
50};
51
52struct zoran_status {
53 int input; /* Input channel, has to be set prior to BUZIOC_G_STATUS */
54 int signal; /* Returned: 1 if valid video signal detected */
debff5a7 55 int norm; /* Returned: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
1da177e4
LT
56 int color; /* Returned: 1 if color signal detected */
57};
58
59struct zoran_params {
60
61 /* The following parameters can only be queried */
62
63 int major_version; /* Major version number of driver */
64 int minor_version; /* Minor version number of driver */
65
66 /* Main control parameters */
67
68 int input; /* Input channel: 0 = Composite, 1 = S-VHS */
debff5a7 69 int norm; /* Norm: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
1da177e4
LT
70 int decimation; /* decimation of captured video,
71 * enlargement of video played back.
72 * Valid values are 1, 2, 4 or 0.
73 * 0 is a special value where the user
74 * has full control over video scaling */
75
76 /* The following parameters only have to be set if decimation==0,
77 * for other values of decimation they provide the data how the image is captured */
78
79 int HorDcm; /* Horizontal decimation: 1, 2 or 4 */
80 int VerDcm; /* Vertical decimation: 1 or 2 */
81 int TmpDcm; /* Temporal decimation: 1 or 2,
82 * if TmpDcm==2 in capture every second frame is dropped,
83 * in playback every frame is played twice */
84 int field_per_buff; /* Number of fields per buffer: 1 or 2 */
85 int img_x; /* start of image in x direction */
86 int img_y; /* start of image in y direction */
87 int img_width; /* image width BEFORE decimation,
88 * must be a multiple of HorDcm*16 */
89 int img_height; /* image height BEFORE decimation,
90 * must be a multiple of VerDcm*8 */
91
92 /* --- End of parameters for decimation==0 only --- */
93
94 /* JPEG control parameters */
95
96 int quality; /* Measure for quality of compressed images.
97 * Scales linearly with the size of the compressed images.
98 * Must be beetween 0 and 100, 100 is a compression
99 * ratio of 1:4 */
100
101 int odd_even; /* Which field should come first ??? */
102
103 int APPn; /* Number of APP segment to be written, must be 0..15 */
104 int APP_len; /* Length of data in JPEG APPn segment */
105 char APP_data[60]; /* Data in the JPEG APPn segment. */
106
107 int COM_len; /* Length of data in JPEG COM segment */
108 char COM_data[60]; /* Data in JPEG COM segment */
109
110 unsigned long jpeg_markers; /* Which markers should go into the JPEG output.
111 * Unless you exactly know what you do, leave them untouched.
112 * Inluding less markers will make the resulting code
af901ca1 113 * smaller, but there will be fewer applications
1da177e4
LT
114 * which can read it.
115 * The presence of the APP and COM marker is
116 * influenced by APP0_len and COM_len ONLY! */
117#define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
118#define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
119#define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
120#define JPEG_MARKER_COM (1<<6) /* Comment segment */
121#define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
122
123 int VFIFO_FB; /* Flag for enabling Video Fifo Feedback.
124 * If this flag is turned on and JPEG decompressing
125 * is going to the screen, the decompress process
126 * is stopped every time the Video Fifo is full.
127 * This enables a smooth decompress to the screen
128 * but the video output signal will get scrambled */
129
130 /* Misc */
131
132 char reserved[312]; /* Makes 512 bytes for this structure */
133};
134
135/*
136Private IOCTL to set up for displaying MJPEG
137*/
debff5a7
HV
138#define BUZIOC_G_PARAMS _IOR ('v', BASE_VIDIOC_PRIVATE+0, struct zoran_params)
139#define BUZIOC_S_PARAMS _IOWR('v', BASE_VIDIOC_PRIVATE+1, struct zoran_params)
140#define BUZIOC_REQBUFS _IOWR('v', BASE_VIDIOC_PRIVATE+2, struct zoran_requestbuffers)
141#define BUZIOC_QBUF_CAPT _IOW ('v', BASE_VIDIOC_PRIVATE+3, int)
142#define BUZIOC_QBUF_PLAY _IOW ('v', BASE_VIDIOC_PRIVATE+4, int)
143#define BUZIOC_SYNC _IOR ('v', BASE_VIDIOC_PRIVATE+5, struct zoran_sync)
144#define BUZIOC_G_STATUS _IOWR('v', BASE_VIDIOC_PRIVATE+6, struct zoran_status)
1da177e4
LT
145
146
147#ifdef __KERNEL__
148
149#define MAJOR_VERSION 0 /* driver major version */
3ff4ad81
HV
150#define MINOR_VERSION 10 /* driver minor version */
151#define RELEASE_VERSION 0 /* release version */
1da177e4
LT
152
153#define ZORAN_NAME "ZORAN" /* name of the device */
154
155#define ZR_DEVNAME(zr) ((zr)->name)
156
157#define BUZ_MAX_WIDTH (zr->timing->Wa)
158#define BUZ_MAX_HEIGHT (zr->timing->Ha)
159#define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
160#define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
161
162#define BUZ_NUM_STAT_COM 4
163#define BUZ_MASK_STAT_COM 3
164
165#define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
166#define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
167
fbe60daa 168#define BUZ_MAX_INPUT 16
1da177e4
LT
169
170#if VIDEO_MAX_FRAME <= 32
171# define V4L_MAX_FRAME 32
172#elif VIDEO_MAX_FRAME <= 64
173# define V4L_MAX_FRAME 64
174#else
175# error "Too many video frame buffers to handle"
176#endif
177#define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
178
1159b7f1
TP
179#define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
180
1da177e4
LT
181#include "zr36057.h"
182
183enum card_type {
184 UNKNOWN = -1,
185
186 /* Pinnacle/Miro */
187 DC10_old, /* DC30 like */
188 DC10_new, /* DC10plus like */
189 DC10plus,
190 DC30,
191 DC30plus,
192
193 /* Linux Media Labs */
194 LML33,
195 LML33R10,
196
197 /* Iomega */
198 BUZ,
199
fbe60daa
MS
200 /* AverMedia */
201 AVS6EYES,
202
1da177e4
LT
203 /* total number of cards */
204 NUM_CARDS
205};
206
207enum zoran_codec_mode {
208 BUZ_MODE_IDLE, /* nothing going on */
209 BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
210 BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
211 BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
212 BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
213};
214
215enum zoran_buffer_state {
216 BUZ_STATE_USER, /* buffer is owned by application */
217 BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */
218 BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */
219 BUZ_STATE_DONE /* buffer is ready to return to application */
220};
221
222enum zoran_map_mode {
223 ZORAN_MAP_MODE_RAW,
224 ZORAN_MAP_MODE_JPG_REC,
225#define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
226 ZORAN_MAP_MODE_JPG_PLAY,
227};
228
229enum gpio_type {
6165894f
MCC
230 ZR_GPIO_JPEG_SLEEP = 0,
231 ZR_GPIO_JPEG_RESET,
232 ZR_GPIO_JPEG_FRAME,
233 ZR_GPIO_VID_DIR,
234 ZR_GPIO_VID_EN,
235 ZR_GPIO_VID_RESET,
236 ZR_GPIO_CLK_SEL1,
237 ZR_GPIO_CLK_SEL2,
238 ZR_GPIO_MAX,
1da177e4
LT
239};
240
241enum gpcs_type {
242 GPCS_JPEG_RESET = 0,
243 GPCS_JPEG_START,
244 GPCS_MAX,
245};
246
247struct zoran_format {
248 char *name;
1da177e4
LT
249 __u32 fourcc;
250 int colorspace;
251 int depth;
252 __u32 flags;
603d6f2c 253 __u32 vfespfr;
1da177e4
LT
254};
255/* flags */
256#define ZORAN_FORMAT_COMPRESSED 1<<0
257#define ZORAN_FORMAT_OVERLAY 1<<1
258#define ZORAN_FORMAT_CAPTURE 1<<2
259#define ZORAN_FORMAT_PLAYBACK 1<<3
260
261/* overlay-settings */
262struct zoran_overlay_settings {
263 int is_set;
264 int x, y, width, height; /* position */
265 int clipcount; /* position and number of clips */
266 const struct zoran_format *format; /* overlay format */
267};
268
269/* v4l-capture settings */
270struct zoran_v4l_settings {
271 int width, height, bytesperline; /* capture size */
272 const struct zoran_format *format; /* capture format */
273};
274
1da177e4
LT
275/* jpg-capture/-playback settings */
276struct zoran_jpg_settings {
277 int decimation; /* this bit is used to set everything to default */
278 int HorDcm, VerDcm, TmpDcm; /* capture decimation settings (TmpDcm=1 means both fields) */
279 int field_per_buff, odd_even; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
280 int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
281 struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
282};
283
284struct zoran_mapping {
285 struct file *file;
286 int count;
287};
288
1159b7f1 289struct zoran_buffer {
1da177e4 290 struct zoran_mapping *map;
1159b7f1
TP
291 enum zoran_buffer_state state; /* state: unused/pending/dma/done */
292 struct zoran_sync bs; /* DONE: info to return to application */
293 union {
294 struct {
295 __le32 *frag_tab; /* addresses of frag table */
296 u32 frag_tab_bus; /* same value cached to save time in ISR */
297 } jpg;
298 struct {
299 char *fbuffer; /* virtual address of frame buffer */
300 unsigned long fbuffer_phys;/* physical address of frame buffer */
301 unsigned long fbuffer_bus;/* bus address of frame buffer */
302 } v4l;
303 };
1da177e4
LT
304};
305
306enum zoran_lock_activity {
307 ZORAN_FREE, /* free for use */
308 ZORAN_ACTIVE, /* active but unlocked */
309 ZORAN_LOCKED, /* locked */
310};
311
312/* buffer collections */
1159b7f1 313struct zoran_buffer_col {
1da177e4 314 enum zoran_lock_activity active; /* feature currently in use? */
1159b7f1
TP
315 unsigned int num_buffers, buffer_size;
316 struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
1da177e4 317 u8 allocated; /* Flag if buffers are allocated */
1da177e4 318 u8 need_contiguous; /* Flag if contiguous buffers are needed */
1159b7f1 319 /* only applies to jpg buffers, raw buffers are always contiguous */
1da177e4
LT
320};
321
322struct zoran;
323
324/* zoran_fh contains per-open() settings */
325struct zoran_fh {
326 struct zoran *zr;
327
1159b7f1 328 enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
1da177e4
LT
329
330 struct zoran_overlay_settings overlay_settings;
1159b7f1
TP
331 u32 *overlay_mask; /* overlay mask */
332 enum zoran_lock_activity overlay_active;/* feature currently in use? */
1da177e4 333
1159b7f1 334 struct zoran_buffer_col buffers; /* buffers' info */
1da177e4 335
1159b7f1 336 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
1da177e4 337 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
1da177e4
LT
338};
339
340struct card_info {
341 enum card_type type;
342 char name[32];
0ab6e1c3
HV
343 const char *i2c_decoder; /* i2c decoder device */
344 const char *mod_decoder; /* i2c decoder module */
345 const unsigned short *addrs_decoder;
346 const char *i2c_encoder; /* i2c encoder device */
347 const char *mod_encoder; /* i2c encoder module */
348 const unsigned short *addrs_encoder;
1da177e4
LT
349 u16 video_vfe, video_codec; /* videocodec types */
350 u16 audio_chip; /* audio type */
1da177e4
LT
351
352 int inputs; /* number of video inputs */
353 struct input {
354 int muxsel;
355 char name[32];
356 } input[BUZ_MAX_INPUT];
357
107063c6 358 v4l2_std_id norms;
1da177e4
LT
359 struct tvnorm *tvn[3]; /* supported TV norms */
360
361 u32 jpeg_int; /* JPEG interrupt */
362 u32 vsync_int; /* VSYNC interrupt */
6165894f 363 s8 gpio[ZR_GPIO_MAX];
1da177e4
LT
364 u8 gpcs[GPCS_MAX];
365
366 struct vfe_polarity vfe_pol;
6165894f 367 u8 gpio_pol[ZR_GPIO_MAX];
1da177e4
LT
368
369 /* is the /GWS line conected? */
370 u8 gws_not_connected;
371
fbe60daa
MS
372 /* avs6eyes mux setting */
373 u8 input_mux;
374
1da177e4
LT
375 void (*init) (struct zoran * zr);
376};
377
378struct zoran {
0ab6e1c3 379 struct v4l2_device v4l2_dev;
1da177e4
LT
380 struct video_device *video_dev;
381
382 struct i2c_adapter i2c_adapter; /* */
383 struct i2c_algo_bit_data i2c_algo; /* */
384 u32 i2cbr;
385
0ab6e1c3
HV
386 struct v4l2_subdev *decoder; /* video decoder sub-device */
387 struct v4l2_subdev *encoder; /* video encoder sub-device */
1da177e4
LT
388
389 struct videocodec *codec; /* video codec */
390 struct videocodec *vfe; /* video front end */
391
384c3689 392 struct mutex resource_lock; /* prevent evil stuff */
1da177e4
LT
393
394 u8 initialized; /* flag if zoran has been correctly initalized */
395 int user; /* number of current users */
396 struct card_info card;
397 struct tvnorm *timing;
398
399 unsigned short id; /* number of this device */
400 char name[32]; /* name of this device */
401 struct pci_dev *pci_dev; /* PCI device */
402 unsigned char revision; /* revision of zr36057 */
1da177e4
LT
403 unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
404
405 spinlock_t spinlock; /* Spinlock */
406
407 /* Video for Linux parameters */
debff5a7 408 int input; /* card's norm and input */
107063c6 409 v4l2_std_id norm;
7f6adeaf
HV
410
411 /* Current buffer params */
412 void *vbuf_base;
413 int vbuf_height, vbuf_width;
414 int vbuf_depth;
415 int vbuf_bytesperline;
416
1da177e4
LT
417 struct zoran_overlay_settings overlay_settings;
418 u32 *overlay_mask; /* overlay mask */
419 enum zoran_lock_activity overlay_active; /* feature currently in use? */
420
421 wait_queue_head_t v4l_capq;
422
423 int v4l_overlay_active; /* Overlay grab is activated */
424 int v4l_memgrab_active; /* Memory grab is activated */
425
426 int v4l_grab_frame; /* Frame number being currently grabbed */
427#define NO_GRAB_ACTIVE (-1)
428 unsigned long v4l_grab_seq; /* Number of frames grabbed */
429 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
430
431 /* V4L grab queue of frames pending */
432 unsigned long v4l_pend_head;
433 unsigned long v4l_pend_tail;
434 unsigned long v4l_sync_tail;
435 int v4l_pend[V4L_MAX_FRAME];
1159b7f1 436 struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
1da177e4
LT
437
438 /* Buz MJPEG parameters */
439 enum zoran_codec_mode codec_mode; /* status of codec */
440 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
441
442 wait_queue_head_t jpg_capq; /* wait here for grab to finish */
443
444 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
445 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
446 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
447 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
448 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
449 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
450 unsigned long jpg_que_tail; /* Index of last buffer in queue */
451 unsigned long jpg_seq_num; /* count of frames since grab/play started */
452 unsigned long jpg_err_seq; /* last seq_num before error */
453 unsigned long jpg_err_shift;
454 unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
455
456 /* zr36057's code buffer table */
581a7f1a 457 __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
1da177e4
LT
458
459 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
460 int jpg_pend[BUZ_MAX_FRAME];
461
462 /* array indexed by frame number */
1159b7f1 463 struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
1da177e4
LT
464
465 /* Additional stuff for testing */
466#ifdef CONFIG_PROC_FS
467 struct proc_dir_entry *zoran_proc;
468#else
469 void *zoran_proc;
470#endif
471 int testing;
472 int jpeg_error;
473 int intr_counter_GIRQ1;
474 int intr_counter_GIRQ0;
475 int intr_counter_CodRepIRQ;
476 int intr_counter_JPEGRepIRQ;
477 int field_counter;
478 int IRQ1_in;
479 int IRQ1_out;
480 int JPEG_in;
481 int JPEG_out;
482 int JPEG_0;
483 int JPEG_1;
484 int END_event_missed;
485 int JPEG_missed;
486 int JPEG_error;
487 int num_errors;
488 int JPEG_max_missed;
489 int JPEG_min_missed;
490
491 u32 last_isr;
492 unsigned long frame_num;
493
494 wait_queue_head_t test_q;
495};
496
0ab6e1c3
HV
497static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
498{
499 return container_of(v4l2_dev, struct zoran, v4l2_dev);
500}
501
5e098b66
TP
502/* There was something called _ALPHA_BUZ that used the PCI address instead of
503 * the kernel iomapped address for btread/btwrite. */
1da177e4
LT
504#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
505#define btread(adr) readl(zr->zr36057_mem+(adr))
1da177e4
LT
506
507#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
508#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
509#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
510
511#endif /* __kernel__ */
512
513#endif