bf6ac447b30d98ce782813ab0e2bc0987a8d034f
[linux-2.6.git] / drivers / media / video / bttvp.h
1 /*
2     $Id: bttvp.h,v 1.12 2004/10/25 11:26:36 kraxel Exp $
3
4     bttv - Bt848 frame grabber driver
5
6     bttv's *private* header file  --  nobody other than bttv itself
7     should ever include this file.
8
9     (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
10
11     This program is free software; you can redistribute it and/or modify
12     it under the terms of the GNU General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU General Public License for more details.
20
21     You should have received a copy of the GNU General Public License
22     along with this program; if not, write to the Free Software
23     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 #ifndef _BTTVP_H_
27 #define _BTTVP_H_
28
29 #include <linux/version.h>
30 #define BTTV_VERSION_CODE KERNEL_VERSION(0,9,15)
31
32 #include <linux/types.h>
33 #include <linux/wait.h>
34 #include <linux/i2c.h>
35 #include <linux/i2c-algo-bit.h>
36 #include <linux/videodev.h>
37 #include <linux/pci.h>
38 #include <linux/input.h>
39 #include <asm/scatterlist.h>
40 #include <asm/io.h>
41
42 #include <linux/device.h>
43 #include <media/video-buf.h>
44 #include <media/audiochip.h>
45 #include <media/tuner.h>
46 #include <media/ir-common.h>
47
48 #include "bt848.h"
49 #include "bttv.h"
50 #include "btcx-risc.h"
51
52 #ifdef __KERNEL__
53
54 #define FORMAT_FLAGS_DITHER       0x01
55 #define FORMAT_FLAGS_PACKED       0x02
56 #define FORMAT_FLAGS_PLANAR       0x04
57 #define FORMAT_FLAGS_RAW          0x08
58 #define FORMAT_FLAGS_CrCb         0x10
59
60 #define RISC_SLOT_O_VBI        4
61 #define RISC_SLOT_O_FIELD      6
62 #define RISC_SLOT_E_VBI       10
63 #define RISC_SLOT_E_FIELD     12
64 #define RISC_SLOT_LOOP        14
65
66 #define RESOURCE_OVERLAY       1
67 #define RESOURCE_VIDEO         2
68 #define RESOURCE_VBI           4
69
70 #define RAW_LINES            640
71 #define RAW_BPL             1024
72
73 #define UNSET (-1U)
74
75 /* ---------------------------------------------------------- */
76
77 struct bttv_tvnorm {
78         int   v4l2_id;
79         char  *name;
80         u32   Fsc;
81         u16   swidth, sheight; /* scaled standard width, height */
82         u16   totalwidth;
83         u8    adelay, bdelay, iform;
84         u32   scaledtwidth;
85         u16   hdelayx1, hactivex1;
86         u16   vdelay;
87         u8    vbipack;
88         u16   vtotal;
89         int   sram;
90 };
91 extern const struct bttv_tvnorm bttv_tvnorms[];
92 extern const unsigned int BTTV_TVNORMS;
93
94 struct bttv_format {
95         char *name;
96         int  palette;         /* video4linux 1      */
97         int  fourcc;          /* video4linux 2      */
98         int  btformat;        /* BT848_COLOR_FMT_*  */
99         int  btswap;          /* BT848_COLOR_CTL_*  */
100         int  depth;           /* bit/pixel          */
101         int  flags;
102         int  hshift,vshift;   /* for planar modes   */
103 };
104 extern const struct bttv_format bttv_formats[];
105 extern const unsigned int BTTV_FORMATS;
106
107 /* ---------------------------------------------------------- */
108
109 struct bttv_geometry {
110         u8  vtc,crop,comb;
111         u16 width,hscale,hdelay;
112         u16 sheight,vscale,vdelay,vtotal;
113 };
114
115 struct bttv_buffer {
116         /* common v4l buffer stuff -- must be first */
117         struct videobuf_buffer     vb;
118
119         /* bttv specific */
120         const struct bttv_format   *fmt;
121         int                        tvnorm;
122         int                        btformat;
123         int                        btswap;
124         struct bttv_geometry       geo;
125         struct btcx_riscmem        top;
126         struct btcx_riscmem        bottom;
127 };
128
129 struct bttv_buffer_set {
130         struct bttv_buffer     *top;       /* top field buffer    */
131         struct bttv_buffer     *bottom;    /* bottom field buffer */
132         unsigned int           top_irq;
133         unsigned int           frame_irq;
134 };
135
136 struct bttv_overlay {
137         int                    tvnorm;
138         struct v4l2_rect       w;
139         enum v4l2_field        field;
140         struct v4l2_clip       *clips;
141         int                    nclips;
142         int                    setup_ok;
143 };
144
145 struct bttv_fh {
146         struct bttv              *btv;
147         int resources;
148 #ifdef VIDIOC_G_PRIORITY
149         enum v4l2_priority       prio;
150 #endif
151         enum v4l2_buf_type       type;
152
153         /* video capture */
154         struct videobuf_queue    cap;
155         const struct bttv_format *fmt;
156         int                      width;
157         int                      height;
158
159         /* current settings */
160         const struct bttv_format *ovfmt;
161         struct bttv_overlay      ov;
162
163         /* video overlay */
164         struct videobuf_queue    vbi;
165         int                      lines;
166 };
167
168 /* ---------------------------------------------------------- */
169 /* bttv-risc.c                                                */
170
171 /* risc code generators - capture */
172 int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
173                      struct scatterlist *sglist,
174                      unsigned int offset, unsigned int bpl,
175                      unsigned int pitch, unsigned int lines);
176 int bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
177                      struct scatterlist *sglist,
178                      unsigned int yoffset,  unsigned int ybpl,
179                      unsigned int ypadding, unsigned int ylines,
180                      unsigned int uoffset,  unsigned int voffset,
181                      unsigned int hshift,   unsigned int vshift,
182                      unsigned int cpadding);
183 int bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
184                       const struct bttv_format *fmt,
185                       struct bttv_overlay *ov,
186                       int skip_top, int skip_bottom);
187
188 /* calculate / apply geometry settings */
189 void bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
190                    int width, int height, int interleaved, int norm);
191 void bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int top);
192
193 /* control dma register + risc main loop */
194 void bttv_set_dma(struct bttv *btv, int override);
195 int bttv_risc_init_main(struct bttv *btv);
196 int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
197                    int irqflags);
198
199 /* capture buffer handling */
200 int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
201 int bttv_buffer_activate_video(struct bttv *btv,
202                                struct bttv_buffer_set *set);
203 int bttv_buffer_activate_vbi(struct bttv *btv,
204                              struct bttv_buffer *vbi);
205 void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf);
206
207 /* overlay handling */
208 int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
209                       const struct bttv_format *fmt,
210                       struct bttv_buffer *buf);
211
212
213 /* ---------------------------------------------------------- */
214 /* bttv-vbi.c                                                 */
215
216 void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f);
217 void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f);
218 void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines);
219
220 extern struct videobuf_queue_ops bttv_vbi_qops;
221
222 /* ---------------------------------------------------------- */
223 /* bttv-gpio.c */
224
225
226 extern struct bus_type bttv_sub_bus_type;
227 int bttv_sub_add_device(struct bttv_core *core, char *name);
228 int bttv_sub_del_devices(struct bttv_core *core);
229 void bttv_gpio_irq(struct bttv_core *core);
230 void bttv_i2c_info(struct bttv_core *core, struct i2c_client *client, int attach);
231
232
233 /* ---------------------------------------------------------- */
234 /* bttv-driver.c                                              */
235
236 /* insmod options */
237 extern unsigned int bttv_verbose;
238 extern unsigned int bttv_debug;
239 extern unsigned int bttv_gpio;
240 extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
241 extern int init_bttv_i2c(struct bttv *btv);
242 extern int fini_bttv_i2c(struct bttv *btv);
243 extern int pvr_boot(struct bttv *btv);
244
245 extern int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg);
246 extern void bttv_reinit_bt848(struct bttv *btv);
247 extern void bttv_field_count(struct bttv *btv);
248
249 #define vprintk  if (bttv_verbose) printk
250 #define dprintk  if (bttv_debug >= 1) printk
251 #define d2printk if (bttv_debug >= 2) printk
252
253 /* our devices */
254 #define BTTV_MAX 16
255 extern unsigned int bttv_num;
256 extern struct bttv bttvs[BTTV_MAX];
257
258 #define BTTV_MAX_FBUF   0x208000
259 #define VBIBUF_SIZE     (2048*VBI_MAXLINES*2)
260 #define BTTV_TIMEOUT    (HZ/2) /* 0.5 seconds */
261 #define BTTV_FREE_IDLE  (HZ)   /* one second */
262
263
264 struct bttv_pll_info {
265         unsigned int pll_ifreq;    /* PLL input frequency        */
266         unsigned int pll_ofreq;    /* PLL output frequency       */
267         unsigned int pll_crystal;  /* Crystal used for input     */
268         unsigned int pll_current;  /* Currently programmed ofreq */
269 };
270
271 /* for gpio-connected remote control */
272 struct bttv_input {
273         struct input_dev      dev;
274         struct ir_input_state ir;
275         char                  name[32];
276         char                  phys[32];
277         u32                   mask_keycode;
278         u32                   mask_keydown;
279 };
280
281 struct bttv_suspend_state {
282         u32  gpio_enable;
283         u32  gpio_data;
284         int  disabled;
285         int  loop_irq;
286         struct bttv_buffer_set video;
287         struct bttv_buffer     *vbi;
288 };
289
290 struct bttv {
291         struct bttv_core c;
292
293         /* pci device config */
294         unsigned short id;
295         unsigned char revision;
296         unsigned char __iomem *bt848_mmio;   /* pointer to mmio */
297
298         /* card configuration info */
299         unsigned int cardid;   /* pci subsystem id (bt878 based ones) */
300         unsigned int tuner_type;  /* tuner chip type */
301         unsigned int pinnacle_id;
302         unsigned int svhs;
303         struct bttv_pll_info pll;
304         int triton1;
305         int gpioirq;
306         int use_i2c_hw;
307
308         /* old gpio interface */
309         wait_queue_head_t gpioq;
310         int shutdown;
311         void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
312
313         /* new gpio interface */
314         spinlock_t gpio_lock;
315
316         /* i2c layer */
317         struct i2c_algo_bit_data   i2c_algo;
318         struct i2c_client          i2c_client;
319         int                        i2c_state, i2c_rc;
320         int                        i2c_done;
321         wait_queue_head_t          i2c_queue;
322
323         /* video4linux (1) */
324         struct video_device *video_dev;
325         struct video_device *radio_dev;
326         struct video_device *vbi_dev;
327
328         /* infrared remote */
329         int has_remote;
330         struct bttv_input *remote;
331
332         /* locking */
333         spinlock_t s_lock;
334         struct semaphore lock;
335         int resources;
336         struct semaphore reslock;
337 #ifdef VIDIOC_G_PRIORITY
338         struct v4l2_prio_state prio;
339 #endif
340
341         /* video state */
342         unsigned int input;
343         unsigned int audio;
344         unsigned long freq;
345         int tvnorm,hue,contrast,bright,saturation;
346         struct v4l2_framebuffer fbuf;
347         unsigned int field_count;
348
349         /* various options */
350         int opt_combfilter;
351         int opt_lumafilter;
352         int opt_automute;
353         int opt_chroma_agc;
354         int opt_adc_crush;
355         int opt_vcr_hack;
356         int opt_whitecrush_upper;
357         int opt_whitecrush_lower;
358
359         /* radio data/state */
360         int has_radio;
361         int radio_user;
362
363         /* miro/pinnacle + Aimslab VHX
364            philips matchbox (tea5757 radio tuner) support */
365         int has_matchbox;
366         int mbox_we;
367         int mbox_data;
368         int mbox_clk;
369         int mbox_most;
370         int mbox_mask;
371
372         /* ISA stuff (Terratec Active Radio Upgrade) */
373         int mbox_ior;
374         int mbox_iow;
375         int mbox_csel;
376
377         /* risc memory management data
378            - must aquire s_lock before changing these
379            - only the irq handler is supported to touch top + bottom + vcurr */
380         struct btcx_riscmem     main;
381         struct bttv_buffer      *screen;    /* overlay             */
382         struct list_head        capture;    /* video capture queue */
383         struct list_head        vcapture;   /* vbi capture queue   */
384         struct bttv_buffer_set  curr;       /* active buffers      */
385         struct bttv_buffer      *cvbi;      /* active vbi buffer   */
386         int                     loop_irq;
387         int                     new_input;
388
389         unsigned long cap_ctl;
390         unsigned long dma_on;
391         struct timer_list timeout;
392         struct bttv_suspend_state state;
393
394         /* stats */
395         unsigned int errors;
396         unsigned int framedrop;
397         unsigned int irq_total;
398         unsigned int irq_me;
399
400         unsigned int users;
401         struct bttv_fh init;
402 };
403
404 /* private ioctls */
405 #define BTTV_VERSION            _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
406 #define BTTV_VBISIZE            _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
407
408 #endif
409
410 #define btwrite(dat,adr)    writel((dat), btv->bt848_mmio+(adr))
411 #define btread(adr)         readl(btv->bt848_mmio+(adr))
412
413 #define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
414 #define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
415 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
416
417 #endif /* _BTTVP_H_ */
418
419 /*
420  * Local variables:
421  * c-basic-offset: 8
422  * End:
423  */