1 /*
2     bttv - Bt848 frame grabber driver
3 
4     bttv's *private* header file  --  nobody else than bttv itself
5     should ever include this file.
6 
7     Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de)
8     (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
9 
10     This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14 
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19 
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24 
25 #ifndef _BTTVP_H_
26 #define _BTTVP_H_
27 
28 #include <linux/version.h>
29 #define BTTV_VERSION_CODE KERNEL_VERSION(0,7,108)
30 
31 #include <linux/types.h>
32 #include <linux/wait.h>
33 #include <linux/i2c.h>
34 #include <linux/i2c-algo-bit.h>
35 
36 #include "bt848.h"
37 #include "bttv.h"
38 #include "audiochip.h"
39 #include "tuner.h"
40 #include "i2c-compat.h"
41 
42 #ifdef __KERNEL__
43 
44 /* ---------------------------------------------------------- */
45 /* bttv-driver.c                                              */
46 
47 /* insmod options / kernel args */
48 extern unsigned int no_overlay;
49 extern unsigned int bttv_verbose;
50 extern unsigned int bttv_debug;
51 extern unsigned int bttv_gpio;
52 extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
53 extern int init_bttv_i2c(struct bttv *btv);
54 extern int pvr_boot(struct bttv *btv);
55 
56 #define dprintk		if (bttv_debug)   printk
57 #define vprintk		if (bttv_verbose) printk
58 
59 #define BTTV_MAX 16
60 extern unsigned int bttv_num;			/* number of Bt848s in use */
61 
62 #define UNSET -1U
63 
64 #ifdef VIDEODAT_HACK
65 # define VBI_MAXLINES   19
66 #else
67 # define VBI_MAXLINES   16
68 #endif
69 #define VBIBUF_SIZE     (2048*VBI_MAXLINES*2)
70 #define MAX_GBUFFERS	64
71 #define RISCMEM_LEN	(32744*2)
72 
73 #define BTTV_MAX_FBUF	0x208000
74 
75 struct bttv_window
76 {
77 	int x, y;
78 	ushort width, height;
79 	ushort bpp, bpl;
80 	ushort swidth, sheight;
81 	unsigned long vidadr;
82 	ushort freq;
83 	int norm;
84 	int interlace;
85 	int color_fmt;
86 	ushort depth;
87 };
88 
89 struct bttv_pll_info {
90 	unsigned int pll_ifreq;	   /* PLL input frequency 	 */
91 	unsigned int pll_ofreq;	   /* PLL output frequency       */
92 	unsigned int pll_crystal;  /* Crystal used for input     */
93 	unsigned int pll_current;  /* Currently programmed ofreq */
94 };
95 
96 struct bttv_gbuf {
97 	int stat;
98 #define GBUFFER_UNUSED       0
99 #define GBUFFER_GRABBING     1
100 #define GBUFFER_DONE         2
101 #define GBUFFER_ERROR        3
102 	struct timeval tv;
103 
104 	u16 width;
105 	u16 height;
106 	u16 fmt;
107 
108 	u32 *risc;
109 	unsigned long ro;
110 	unsigned long re;
111 };
112 
113 struct bttv {
114 	struct video_device video_dev;
115 	struct video_device radio_dev;
116 	struct video_device vbi_dev;
117 	struct video_picture picture;		/* Current picture params */
118 	struct video_audio audio_dev;		/* Current audio params */
119 
120 	spinlock_t s_lock;
121         struct semaphore lock;
122 	unsigned int user;
123 
124 	/* i2c */
125 	struct i2c_adapter         i2c_adap;
126 	struct i2c_algo_bit_data   i2c_algo;
127 	struct i2c_client          i2c_client;
128 	int                        i2c_state, i2c_rc;
129 
130         unsigned int tuner_type;
131         unsigned int pinnacle_id;
132         unsigned int channel;
133 	unsigned int svhs;
134 
135         unsigned int nr;
136 	unsigned short id;
137 	struct pci_dev *dev;
138 	unsigned char revision;
139 	unsigned long bt848_adr;      /* bus address of IO mem returned by PCI BIOS */
140 	unsigned char *bt848_mem;   /* pointer to mapped IO memory */
141 	unsigned long busriscmem;
142 	u32 *riscmem;
143 
144 	unsigned char *vbibuf;
145 	struct bttv_window win;
146 	int fb_color_ctl;
147 	int type;            /* card type  */
148 	unsigned int cardid;
149 	int audio;           /* audio mode */
150 	int audio_chip;      /* set to one of the chips supported by bttv.c */
151 	int radio;
152 	int has_radio;
153 	int has_remote;
154 
155 	/* miro/pinnacle + Aimslab VHX
156 	   philips matchbox (tea5757 radio tuner) support */
157 	int has_matchbox;
158 	int mbox_we;
159 	int mbox_data;
160 	int mbox_clk;
161 	int mbox_most;
162 	int mbox_mask;
163 
164 	/* ISA stuff (Terratec Active Radio Upgrade) */
165 	int mbox_ior;
166 	int mbox_iow;
167 	int mbox_csel;
168 
169 	u32 *risc_jmp;
170 	u32 *vbi_odd;
171 	u32 *vbi_even;
172 	u32 bus_vbi_even;
173 	u32 bus_vbi_odd;
174         wait_queue_head_t vbiq;
175 	wait_queue_head_t capq;
176 	unsigned int vbip;
177 
178 	u32 *risc_scr_odd;
179 	u32 *risc_scr_even;
180 	u32 risc_cap_odd;
181 	u32 risc_cap_even;
182 	int scr_on;
183 	int vbi_on;
184 	struct video_clip *cliprecs;
185 
186 	struct bttv_gbuf *gbuf;
187 	int gqueue[MAX_GBUFFERS];
188 	int gq_in,gq_out,gq_grab,gq_start;
189         char *fbuffer;
190 
191 	struct bttv_pll_info pll;
192 	unsigned int Fsc;
193 	unsigned int field;
194 	unsigned int last_field; /* number of last grabbed field */
195 	int i2c_command;
196 	int triton1;
197 
198 	int errors;
199 	int needs_restart;
200 
201 	wait_queue_head_t gpioq;
202 	int shutdown;
203         void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
204 };
205 
206 extern struct bttv bttvs[BTTV_MAX];
207 #endif
208 
209 #define btwrite(dat,adr)    writel((dat), (char *) (btv->bt848_mem+(adr)))
210 #define btread(adr)         readl(btv->bt848_mem+(adr))
211 
212 #define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
213 #define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
214 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
215 
216 /* bttv ioctls */
217 
218 #define BTTV_READEE		_IOW('v',  BASE_VIDIOCPRIVATE+0, char [256])
219 #define BTTV_WRITEE		_IOR('v',  BASE_VIDIOCPRIVATE+1, char [256])
220 #define BTTV_FIELDNR		_IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int)
221 #define BTTV_PLLSET		_IOW('v' , BASE_VIDIOCPRIVATE+3, struct bttv_pll_info)
222 #define BTTV_BURST_ON      	_IOR('v' , BASE_VIDIOCPRIVATE+4, int)
223 #define BTTV_BURST_OFF     	_IOR('v' , BASE_VIDIOCPRIVATE+5, int)
224 #define BTTV_VERSION  	        _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
225 #define BTTV_PICNR		_IOR('v' , BASE_VIDIOCPRIVATE+7, int)
226 #define BTTV_VBISIZE            _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
227 
228 #define TDA9850            0x01
229 #define TDA9840            0x02
230 #define TDA8425            0x03
231 #define TEA6300            0x04
232 
233 #endif /* _BTTVP_H_ */
234 
235 /*
236  * Local variables:
237  * c-basic-offset: 8
238  * End:
239  */
240