tree-wide: fix comment/printk typos
[deliverable/linux.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.
b595076a 98 * Must be between 0 and 100, 100 is a compression
1da177e4
LT
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 343 const char *i2c_decoder; /* i2c decoder device */
0ab6e1c3
HV
344 const unsigned short *addrs_decoder;
345 const char *i2c_encoder; /* i2c encoder device */
0ab6e1c3 346 const unsigned short *addrs_encoder;
1da177e4
LT
347 u16 video_vfe, video_codec; /* videocodec types */
348 u16 audio_chip; /* audio type */
1da177e4
LT
349
350 int inputs; /* number of video inputs */
351 struct input {
352 int muxsel;
353 char name[32];
354 } input[BUZ_MAX_INPUT];
355
107063c6 356 v4l2_std_id norms;
1da177e4
LT
357 struct tvnorm *tvn[3]; /* supported TV norms */
358
359 u32 jpeg_int; /* JPEG interrupt */
360 u32 vsync_int; /* VSYNC interrupt */
6165894f 361 s8 gpio[ZR_GPIO_MAX];
1da177e4
LT
362 u8 gpcs[GPCS_MAX];
363
364 struct vfe_polarity vfe_pol;
6165894f 365 u8 gpio_pol[ZR_GPIO_MAX];
1da177e4
LT
366
367 /* is the /GWS line conected? */
368 u8 gws_not_connected;
369
fbe60daa
MS
370 /* avs6eyes mux setting */
371 u8 input_mux;
372
1da177e4
LT
373 void (*init) (struct zoran * zr);
374};
375
376struct zoran {
0ab6e1c3 377 struct v4l2_device v4l2_dev;
1da177e4
LT
378 struct video_device *video_dev;
379
380 struct i2c_adapter i2c_adapter; /* */
381 struct i2c_algo_bit_data i2c_algo; /* */
382 u32 i2cbr;
383
0ab6e1c3
HV
384 struct v4l2_subdev *decoder; /* video decoder sub-device */
385 struct v4l2_subdev *encoder; /* video encoder sub-device */
1da177e4
LT
386
387 struct videocodec *codec; /* video codec */
388 struct videocodec *vfe; /* video front end */
389
384c3689 390 struct mutex resource_lock; /* prevent evil stuff */
1da177e4 391
421f91d2 392 u8 initialized; /* flag if zoran has been correctly initialized */
1da177e4
LT
393 int user; /* number of current users */
394 struct card_info card;
395 struct tvnorm *timing;
396
397 unsigned short id; /* number of this device */
398 char name[32]; /* name of this device */
399 struct pci_dev *pci_dev; /* PCI device */
400 unsigned char revision; /* revision of zr36057 */
1da177e4
LT
401 unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
402
403 spinlock_t spinlock; /* Spinlock */
404
405 /* Video for Linux parameters */
debff5a7 406 int input; /* card's norm and input */
107063c6 407 v4l2_std_id norm;
7f6adeaf
HV
408
409 /* Current buffer params */
410 void *vbuf_base;
411 int vbuf_height, vbuf_width;
412 int vbuf_depth;
413 int vbuf_bytesperline;
414
1da177e4
LT
415 struct zoran_overlay_settings overlay_settings;
416 u32 *overlay_mask; /* overlay mask */
417 enum zoran_lock_activity overlay_active; /* feature currently in use? */
418
419 wait_queue_head_t v4l_capq;
420
421 int v4l_overlay_active; /* Overlay grab is activated */
422 int v4l_memgrab_active; /* Memory grab is activated */
423
424 int v4l_grab_frame; /* Frame number being currently grabbed */
425#define NO_GRAB_ACTIVE (-1)
426 unsigned long v4l_grab_seq; /* Number of frames grabbed */
427 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
428
429 /* V4L grab queue of frames pending */
430 unsigned long v4l_pend_head;
431 unsigned long v4l_pend_tail;
432 unsigned long v4l_sync_tail;
433 int v4l_pend[V4L_MAX_FRAME];
1159b7f1 434 struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
1da177e4
LT
435
436 /* Buz MJPEG parameters */
437 enum zoran_codec_mode codec_mode; /* status of codec */
438 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
439
440 wait_queue_head_t jpg_capq; /* wait here for grab to finish */
441
442 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
443 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
444 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
445 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
446 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
447 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
448 unsigned long jpg_que_tail; /* Index of last buffer in queue */
449 unsigned long jpg_seq_num; /* count of frames since grab/play started */
450 unsigned long jpg_err_seq; /* last seq_num before error */
451 unsigned long jpg_err_shift;
452 unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
453
454 /* zr36057's code buffer table */
581a7f1a 455 __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
1da177e4
LT
456
457 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
458 int jpg_pend[BUZ_MAX_FRAME];
459
460 /* array indexed by frame number */
1159b7f1 461 struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
1da177e4
LT
462
463 /* Additional stuff for testing */
464#ifdef CONFIG_PROC_FS
465 struct proc_dir_entry *zoran_proc;
466#else
467 void *zoran_proc;
468#endif
469 int testing;
470 int jpeg_error;
471 int intr_counter_GIRQ1;
472 int intr_counter_GIRQ0;
473 int intr_counter_CodRepIRQ;
474 int intr_counter_JPEGRepIRQ;
475 int field_counter;
476 int IRQ1_in;
477 int IRQ1_out;
478 int JPEG_in;
479 int JPEG_out;
480 int JPEG_0;
481 int JPEG_1;
482 int END_event_missed;
483 int JPEG_missed;
484 int JPEG_error;
485 int num_errors;
486 int JPEG_max_missed;
487 int JPEG_min_missed;
488
489 u32 last_isr;
490 unsigned long frame_num;
491
492 wait_queue_head_t test_q;
493};
494
0ab6e1c3
HV
495static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
496{
497 return container_of(v4l2_dev, struct zoran, v4l2_dev);
498}
499
5e098b66
TP
500/* There was something called _ALPHA_BUZ that used the PCI address instead of
501 * the kernel iomapped address for btread/btwrite. */
1da177e4
LT
502#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
503#define btread(adr) readl(zr->zr36057_mem+(adr))
1da177e4
LT
504
505#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
506#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
507#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
508
509#endif /* __kernel__ */
510
511#endif
This page took 0.603434 seconds and 5 git commands to generate.