Subversion Repositories shark

Rev

Rev 428 | Details | Compare with Previous | 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
 
252
#define BTTV_MAX_FBUF   0x208000
253
#define VBIBUF_SIZE     (2048*VBI_MAXLINES*2)
254
#define BTTV_TIMEOUT    (HZ/2) /* 0.5 seconds */
255
#define BTTV_FREE_IDLE  (HZ)   /* one second */
256
 
257
 
258
struct bttv_pll_info {
259
        unsigned int pll_ifreq;    /* PLL input frequency        */
260
        unsigned int pll_ofreq;    /* PLL output frequency       */
261
        unsigned int pll_crystal;  /* Crystal used for input     */
262
        unsigned int pll_current;  /* Currently programmed ofreq */
263
};
264
 
265
#ifdef CONFIG_VIDEO_IR
266
/* for gpio-connected remote control */
267
struct bttv_input {
268
        struct input_dev      dev;
269
        struct ir_input_state ir;
270
        char                  name[32];
271
        char                  phys[32];
272
        u32                   mask_keycode;
273
        u32                   mask_keydown;
274
};
275
#endif
276
 
277
struct bttv {
278
        /* pci device config */
279
        struct pci_dev *dev;
280
        unsigned short id;
281
        unsigned char revision;
282
        unsigned char *bt848_mmio;   /* pointer to mmio */
283
 
284
        /* card configuration info */
285
        unsigned int nr;       /* dev nr (for printk("bttv%d: ...");  */
286
        char name[8];          /* dev name */
287
        unsigned int cardid;   /* pci subsystem id (bt878 based ones) */
288
        unsigned int type;     /* card type (pointer into tvcards[])  */
289
        unsigned int tuner_type;  /* tuner chip type */
290
        unsigned int pinnacle_id;
291
        unsigned int svhs;
292
        struct bttv_pll_info pll;
293
        int triton1;
294
 
295
        /* gpio interface */
296
        wait_queue_head_t gpioq;
297
        int shutdown;
298
        void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
299
 
300
        /* i2c layer */
301
        struct i2c_adapter         i2c_adap;
302
        struct i2c_algo_bit_data   i2c_algo;
303
        struct i2c_client          i2c_client;
304
        int                        i2c_state, i2c_rc;
305
 
306
        /* video4linux (1) */
307
        struct video_device *video_dev;
308
        struct video_device *radio_dev;
309
        struct video_device *vbi_dev;
310
 
311
        /* infrared remote */
312
        int has_remote;
313
#ifdef CONFIG_VIDEO_IR
314
        struct bttv_input *remote;
315
#endif
316
 
317
        /* locking */
318
        spinlock_t s_lock;
319
        struct semaphore lock;
320
        int resources;
321
        struct semaphore reslock;
322
#ifdef VIDIOC_G_PRIORITY 
323
        struct v4l2_prio_state prio;
324
#endif
325
 
326
        /* video state */
327
        unsigned int input;
328
        unsigned int audio;
329
        unsigned long freq;
330
        int tvnorm,hue,contrast,bright,saturation;
331
        struct v4l2_framebuffer fbuf;
332
        unsigned int field_count;
333
 
334
        /* various options */
335
        int opt_combfilter;
336
        int opt_lumafilter;
337
        int opt_automute;
338
        int opt_chroma_agc;
339
        int opt_adc_crush;
340
        int opt_vcr_hack;
341
 
342
        /* radio data/state */
343
        int has_radio;
344
        int radio_user;
345
 
346
        /* miro/pinnacle + Aimslab VHX
347
           philips matchbox (tea5757 radio tuner) support */
348
        int has_matchbox;
349
        int mbox_we;
350
        int mbox_data;
351
        int mbox_clk;
352
        int mbox_most;
353
        int mbox_mask;
354
 
355
        /* ISA stuff (Terratec Active Radio Upgrade) */
356
        int mbox_ior;
357
        int mbox_iow;
358
        int mbox_csel;
359
 
360
        /* risc memory management data
361
           - must aquire s_lock before changing these
362
           - only the irq handler is supported to touch top + bottom + vcurr */
363
        struct btcx_riscmem     main;
364
        struct bttv_buffer      *screen;    /* overlay             */
365
        struct list_head        capture;    /* video capture queue */
366
        struct list_head        vcapture;   /* vbi capture queue   */
367
        struct bttv_buffer_set  curr;       /* active buffers      */
368
        int                     new_input;
369
 
370
        unsigned long cap_ctl;
371
        unsigned long dma_on;
372
        struct timer_list timeout;
373
        unsigned int errors;
374
 
375
        unsigned int users;
376
        struct bttv_fh init;
377
};
378
 
1056 tullio 379
// moved here for gcc4 compatibility
380
extern struct bttv bttvs[BTTV_MAX];
381
 
428 giacomo 382
/* private ioctls */
383
#define BTTV_VERSION            _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
384
#define BTTV_VBISIZE            _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
385
 
386
#endif
387
 
388
#define btwrite(dat,adr)    writel((dat), (char *) (btv->bt848_mmio+(adr)))
389
#define btread(adr)         readl(btv->bt848_mmio+(adr))
390
 
391
#define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
392
#define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
393
#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
394
 
395
#endif /* _BTTVP_H_ */
396
 
397
/*
398
 * Local variables:
399
 * c-basic-offset: 8
400
 * End:
401
 */