Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
428 giacomo 1
/*
2
    bttv - Bt848 frame grabber driver
3
 
4
    bttv's *private* header file  --  nobody other than bttv itself
5
    should ever include this file.
6
 
7
    (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
8
 
9
    This program is free software; you can redistribute it and/or modify
10
    it under the terms of the GNU General Public License as published by
11
    the Free Software Foundation; either version 2 of the License, or
12
    (at your option) any later version.
13
 
14
    This program is distributed in the hope that it will be useful,
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    GNU General Public License for more details.
18
 
19
    You should have received a copy of the GNU General Public License
20
    along with this program; if not, write to the Free Software
21
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
*/
23
 
24
#ifndef _BTTVP_H_
25
#define _BTTVP_H_
26
 
27
#include <linux/version.h>
28
#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,12)
29
 
30
#include <linux/types.h>
31
#include <linux/wait.h>
32
#include <linux/i2c.h>
33
#include <linux/i2c-algo-bit.h>
34
#include <linux/videodev.h>
35
#include <linux/pci.h>
36
#include <linux/input.h>
37
#include <asm/scatterlist.h>
38
#include <asm/io.h>
39
 
40
#include <linux/device.h>
41
#include <drivers/video-buf.h>
42
#include <drivers/audiochip.h>
43
#include <drivers/tuner.h>
44
 
45
#include "drivers/bt848.h"
46
#include "drivers/bttv.h"
47
#include "drivers/btcx-risc.h"
48
#ifdef CONFIG_VIDEO_IR
49
#include "ir-common.h"
50
#endif
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
        struct bttv_buffer     *vbi;       /* vbi buffer */
133
        unsigned int           irqflags;
134
        unsigned int           topirq;
135
};
136
 
137
struct bttv_overlay {
138
        int                    tvnorm;
139
        struct v4l2_rect       w;
140
        enum v4l2_field        field;
141
        struct v4l2_clip       *clips;
142
        int                    nclips;
143
        int                    setup_ok;
144
};
145
 
146
struct bttv_fh {
147
        struct bttv              *btv;
148
        int resources;
149
#ifdef VIDIOC_G_PRIORITY 
150
        enum v4l2_priority       prio;
151
#endif
152
        enum v4l2_buf_type       type;
153
 
154
        /* video capture */
155
        struct videobuf_queue    cap;
156
        const struct bttv_format *fmt;
157
        int                      width;
158
        int                      height;
159
 
160
        /* current settings */
161
        const struct bttv_format *ovfmt;
162
        struct bttv_overlay      ov;
163
 
164
        /* video overlay */
165
        struct videobuf_queue    vbi;
166
        int                      lines;
167
};
168
 
169
/* ---------------------------------------------------------- */
170
/* bttv-risc.c                                                */
171
 
172
/* risc code generators - capture */
173
int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
174
                     struct scatterlist *sglist,
175
                     unsigned int offset, unsigned int bpl,
176
                     unsigned int pitch, unsigned int lines);
177
int bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
178
                     struct scatterlist *sglist,
179
                     unsigned int yoffset,  unsigned int ybpl,
180
                     unsigned int ypadding, unsigned int ylines,
181
                     unsigned int uoffset,  unsigned int voffset,
182
                     unsigned int hshift,   unsigned int vshift,
183
                     unsigned int cpadding);
184
int bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
185
                      const struct bttv_format *fmt,
186
                      struct bttv_overlay *ov,
187
                      int skip_top, int skip_bottom);
188
 
189
/* calculate / apply geometry settings */
190
void bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
191
                   int width, int height, int interleaved, int norm);
192
void bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int top);
193
 
194
/* control dma register + risc main loop */
195
void bttv_set_dma(struct bttv *btv, int override, int irqflags);
196
int bttv_risc_init_main(struct bttv *btv);
197
int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
198
                   int irqflags);
199
 
200
/* capture buffer handling */
201
int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
202
int bttv_buffer_set_activate(struct bttv *btv,
203
                             struct bttv_buffer_set *set);
204
void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf);
205
 
206
/* overlay handling */
207
int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
208
                      const struct bttv_format *fmt,
209
                      struct bttv_buffer *buf);
210
 
211
 
212
/* ---------------------------------------------------------- */
213
/* bttv-vbi.c                                                 */
214
 
215
void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f);
216
void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f);
217
void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines);
218
 
219
extern struct videobuf_queue_ops bttv_vbi_qops;
220
 
221
/* ---------------------------------------------------------- */
222
/* bttv-input.c                                               */
223
 
224
int bttv_input_init(struct bttv *btv);
225
void bttv_input_fini(struct bttv *btv);
226
void bttv_input_irq(struct bttv *btv);
227
 
228
/* ---------------------------------------------------------- */
229
/* bttv-driver.c                                              */
230
 
231
/* insmod options */
232
extern unsigned int bttv_verbose;
233
extern unsigned int bttv_debug;
234
extern unsigned int bttv_gpio;
235
extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
236
extern int init_bttv_i2c(struct bttv *btv);
237
extern int fini_bttv_i2c(struct bttv *btv);
238
extern int pvr_boot(struct bttv *btv);
239
 
240
extern int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg);
241
extern void bttv_reinit_bt848(struct bttv *btv);
242
extern void bttv_field_count(struct bttv *btv);
243
 
244
#define vprintk  if (bttv_verbose) printk
245
#define dprintk  if (bttv_debug >= 1) printk
246
#define d2printk if (bttv_debug >= 2) printk
247
 
248
/* our devices */
249
#define BTTV_MAX 16
250
extern unsigned int bttv_num;
251
extern struct bttv bttvs[BTTV_MAX];
252
 
253
#define BTTV_MAX_FBUF   0x208000
254
#define VBIBUF_SIZE     (2048*VBI_MAXLINES*2)
255
#define BTTV_TIMEOUT    (HZ/2) /* 0.5 seconds */
256
#define BTTV_FREE_IDLE  (HZ)   /* one second */
257
 
258
 
259
struct bttv_pll_info {
260
        unsigned int pll_ifreq;    /* PLL input frequency        */
261
        unsigned int pll_ofreq;    /* PLL output frequency       */
262
        unsigned int pll_crystal;  /* Crystal used for input     */
263
        unsigned int pll_current;  /* Currently programmed ofreq */
264
};
265
 
266
#ifdef CONFIG_VIDEO_IR
267
/* for gpio-connected remote control */
268
struct bttv_input {
269
        struct input_dev      dev;
270
        struct ir_input_state ir;
271
        char                  name[32];
272
        char                  phys[32];
273
        u32                   mask_keycode;
274
        u32                   mask_keydown;
275
};
276
#endif
277
 
278
struct bttv {
279
        /* pci device config */
280
        struct pci_dev *dev;
281
        unsigned short id;
282
        unsigned char revision;
283
        unsigned char *bt848_mmio;   /* pointer to mmio */
284
 
285
        /* card configuration info */
286
        unsigned int nr;       /* dev nr (for printk("bttv%d: ...");  */
287
        char name[8];          /* dev name */
288
        unsigned int cardid;   /* pci subsystem id (bt878 based ones) */
289
        unsigned int type;     /* card type (pointer into tvcards[])  */
290
        unsigned int tuner_type;  /* tuner chip type */
291
        unsigned int pinnacle_id;
292
        unsigned int svhs;
293
        struct bttv_pll_info pll;
294
        int triton1;
295
 
296
        /* gpio interface */
297
        wait_queue_head_t gpioq;
298
        int shutdown;
299
        void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
300
 
301
        /* i2c layer */
302
        struct i2c_adapter         i2c_adap;
303
        struct i2c_algo_bit_data   i2c_algo;
304
        struct i2c_client          i2c_client;
305
        int                        i2c_state, i2c_rc;
306
 
307
        /* video4linux (1) */
308
        struct video_device *video_dev;
309
        struct video_device *radio_dev;
310
        struct video_device *vbi_dev;
311
 
312
        /* infrared remote */
313
        int has_remote;
314
#ifdef CONFIG_VIDEO_IR
315
        struct bttv_input *remote;
316
#endif
317
 
318
        /* locking */
319
        spinlock_t s_lock;
320
        struct semaphore lock;
321
        int resources;
322
        struct semaphore reslock;
323
#ifdef VIDIOC_G_PRIORITY 
324
        struct v4l2_prio_state prio;
325
#endif
326
 
327
        /* video state */
328
        unsigned int input;
329
        unsigned int audio;
330
        unsigned long freq;
331
        int tvnorm,hue,contrast,bright,saturation;
332
        struct v4l2_framebuffer fbuf;
333
        unsigned int field_count;
334
 
335
        /* various options */
336
        int opt_combfilter;
337
        int opt_lumafilter;
338
        int opt_automute;
339
        int opt_chroma_agc;
340
        int opt_adc_crush;
341
        int opt_vcr_hack;
342
 
343
        /* radio data/state */
344
        int has_radio;
345
        int radio_user;
346
 
347
        /* miro/pinnacle + Aimslab VHX
348
           philips matchbox (tea5757 radio tuner) support */
349
        int has_matchbox;
350
        int mbox_we;
351
        int mbox_data;
352
        int mbox_clk;
353
        int mbox_most;
354
        int mbox_mask;
355
 
356
        /* ISA stuff (Terratec Active Radio Upgrade) */
357
        int mbox_ior;
358
        int mbox_iow;
359
        int mbox_csel;
360
 
361
        /* risc memory management data
362
           - must aquire s_lock before changing these
363
           - only the irq handler is supported to touch top + bottom + vcurr */
364
        struct btcx_riscmem     main;
365
        struct bttv_buffer      *screen;    /* overlay             */
366
        struct list_head        capture;    /* video capture queue */
367
        struct list_head        vcapture;   /* vbi capture queue   */
368
        struct bttv_buffer_set  curr;       /* active buffers      */
369
        int                     new_input;
370
 
371
        unsigned long cap_ctl;
372
        unsigned long dma_on;
373
        struct timer_list timeout;
374
        unsigned int errors;
375
 
376
        unsigned int users;
377
        struct bttv_fh init;
378
};
379
 
380
/* private ioctls */
381
#define BTTV_VERSION            _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
382
#define BTTV_VBISIZE            _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
383
 
384
#endif
385
 
386
#define btwrite(dat,adr)    writel((dat), (char *) (btv->bt848_mmio+(adr)))
387
#define btread(adr)         readl(btv->bt848_mmio+(adr))
388
 
389
#define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
390
#define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
391
#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
392
 
393
#endif /* _BTTVP_H_ */
394
 
395
/*
396
 * Local variables:
397
 * c-basic-offset: 8
398
 * End:
399
 */