Linux 2.4.0-test7-pre6
[davej-history.git] / drivers / char / bttv.h
blob6b35d23e5c20edc22d32d8fc2d4860a2acc4f2a9
1 /*
2 bttv - Bt848 frame grabber driver
4 Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef _BTTV_H_
22 #define _BTTV_H_
24 #define BTTV_VERSION_CODE KERNEL_VERSION(0,7,38)
26 #ifndef PCI_GET_DRIVER_DATA
27 # define PCI_GET_DRIVER_DATA(pdev) ((pdev)->driver_data)
28 # define PCI_SET_DRIVER_DATA(pdev,data) (((pdev)->driver_data) = (data))
29 #endif /* PCI_GET_DRIVER_DATA */
31 #include <linux/types.h>
32 #include <linux/wait.h>
33 #include <linux/videodev.h>
34 #include <linux/i2c.h>
35 #include <linux/i2c-algo-bit.h>
37 #include "audiochip.h"
38 #include "bt848.h"
40 #ifdef __KERNEL__
42 /* fwd decl */
43 struct bttv;
46 /* ---------------------------------------------------------- */
47 /* exported by bttv-cards.c */
49 #define BTTV_UNKNOWN 0x00
50 #define BTTV_MIRO 0x01
51 #define BTTV_HAUPPAUGE 0x02
52 #define BTTV_STB 0x03
53 #define BTTV_INTEL 0x04
54 #define BTTV_DIAMOND 0x05
55 #define BTTV_AVERMEDIA 0x06
56 #define BTTV_MATRIX_VISION 0x07
57 #define BTTV_FLYVIDEO 0x08
58 #define BTTV_TURBOTV 0x09
59 #define BTTV_HAUPPAUGE878 0x0a
60 #define BTTV_MIROPRO 0x0b
61 #define BTTV_ADSTECH_TV 0x0c
62 #define BTTV_AVERMEDIA98 0x0d
63 #define BTTV_VHX 0x0e
64 #define BTTV_ZOLTRIX 0x0f
65 #define BTTV_PIXVIEWPLAYTV 0x10
66 #define BTTV_WINVIEW_601 0x11
67 #define BTTV_AVEC_INTERCAP 0x12
68 #define BTTV_LIFE_FLYKIT 0x13
69 #define BTTV_CEI_RAFFLES 0x14
70 #define BTTV_CONFERENCETV 0x15
71 #define BTTV_PHOEBE_TVMAS 0x16
72 #define BTTV_MODTEC_205 0x17
73 #define BTTV_MAGICTVIEW061 0x18
74 #define BTTV_VOBIS_BOOSTAR 0x19
75 #define BTTV_HAUPPAUG_WCAM 0x1a
76 #define BTTV_MAXI 0x1b
77 #define BTTV_TERRATV 0x1c
78 #define BTTV_PXC200 0x1d
79 #define BTTV_FLYVIDEO_98 0x1e
80 #define BTTV_IPROTV 0x1f
81 #define BTTV_INTEL_C_S_PCI 0x20
82 #define BTTV_TERRATVALUE 0x21
83 #define BTTV_WINFAST2000 0x22
84 #define BTTV_CHRONOS_VS2 0x23
85 #define BTTV_TYPHOON_TVIEW 0x24
86 #define BTTV_PXELVWPLTVPRO 0x25
87 #define BTTV_MAGICTVIEW063 0x26
88 #define BTTV_PINNACLERAVE 0x27
89 #define BTTV_STB2 0x28
90 #define BTTV_AVPHONE98 0x29
91 #define BTTV_PV951 0x2a
92 #define BTTV_ONAIR_TV 0x2b
93 #define BTTV_SIGMA_TVII_FM 0x2c
94 #define BTTV_MATRIX_VISION2 0x2d
95 #define BTTV_ZOLTRIX_GENIE 0x2e
96 #define BTTV_TERRATVRADIO 0x2f
97 #define BTTV_DYNALINK 0x30
99 struct tvcard
101 char *name;
102 int video_inputs;
103 int audio_inputs;
104 int tuner;
105 int svhs;
106 u32 gpiomask;
107 u32 muxsel[8];
108 u32 audiomux[6]; /* Tuner, Radio, external, internal, mute, stereo */
109 u32 gpiomask2; /* GPIO MUX mask */
111 /* look for these i2c audio chips */
112 int msp34xx:1;
113 int tda8425:1;
114 int tda9840:1;
115 int tda985x:1;
116 int tea63xx:1;
117 int tea64xx:1;
118 int tda7432:1;
119 int tda9875:1;
121 /* other settings */
122 int pll;
123 #define PLL_NONE 0
124 #define PLL_28 1
125 #define PLL_35 2
127 int tuner_type;
130 extern struct tvcard bttv_tvcards[];
131 extern const int bttv_num_tvcards;
133 /* identification / initialization of the card */
134 extern void bttv_idcard(struct bttv *btv);
136 /* card-specific funtions */
137 extern void tea5757_set_freq(struct bttv *btv, unsigned short freq);
138 extern void winview_setvol(struct bttv *btv, struct video_audio *v);
140 /* ---------------------------------------------------------- */
141 /* exported by bttv-if.c */
142 /* interface for gpio access by other modules */
144 /* returns card type + card ID (for bt878-based ones)
145 for possible values see lines below beginning with #define BTTV_UNKNOWN
146 returns negative value if error ocurred
148 extern int bttv_get_cardinfo(unsigned int card, int *type, int *cardid);
150 /* obsolete, use bttv_get_cardinfo instead */
151 extern int bttv_get_id(unsigned int card);
153 /* sets GPOE register (BT848_GPIO_OUT_EN) to new value:
154 data | (current_GPOE_value & ~mask)
155 returns negative value if error ocurred
157 extern int bttv_gpio_enable(unsigned int card,
158 unsigned long mask, unsigned long data);
160 /* fills data with GPDATA register contents
161 returns negative value if error ocurred
163 extern int bttv_read_gpio(unsigned int card, unsigned long *data);
165 /* sets GPDATA register to new value:
166 (data & mask) | (current_GPDATA_value & ~mask)
167 returns negative value if error ocurred
169 extern int bttv_write_gpio(unsigned int card,
170 unsigned long mask, unsigned long data);
172 /* returns pointer to task queue which can be used as parameter to
173 interruptible_sleep_on
174 in interrupt handler if BT848_INT_GPINT bit is set - this queue is activated
175 (wake_up_interruptible) and following call to the function bttv_read_gpio
176 should return new value of GPDATA,
177 returns NULL value if error ocurred or queue is not available
178 WARNING: because there is no buffer for GPIO data, one MUST
179 process data ASAP
181 extern wait_queue_head_t* bttv_get_gpio_queue(unsigned int card);
183 /* i2c */
184 struct i2c_algo_bit_data bttv_i2c_algo_template;
185 struct i2c_adapter bttv_i2c_adap_template;
186 struct i2c_client bttv_i2c_client_template;
187 void bttv_bit_setscl(void *data, int state);
188 void bttv_bit_setsda(void *data, int state);
189 void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg);
190 int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for);
191 int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
192 unsigned char b2, int both);
193 void bttv_readee(struct bttv *btv, unsigned char *eedata, int addr);
196 /* ---------------------------------------------------------- */
197 /* bttv-driver.c */
199 /* insmod options */
200 extern unsigned int bttv_verbose;
201 extern unsigned int bttv_debug;
203 /* Anybody who uses more than four? */
204 #define BTTV_MAX 4
205 extern int bttv_num; /* number of Bt848s in use */
206 extern struct bttv bttvs[BTTV_MAX];
209 #ifndef O_NONCAP
210 #define O_NONCAP O_TRUNC
211 #endif
213 #define MAX_GBUFFERS 64
214 #define RISCMEM_LEN (32744*2)
215 #define VBI_MAXLINES 16
216 #define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
218 #define BTTV_MAX_FBUF 0x208000
219 #define I2C_CLIENTS_MAX 8
221 struct bttv_window
223 int x, y;
224 ushort width, height;
225 ushort bpp, bpl;
226 ushort swidth, sheight;
227 unsigned long vidadr;
228 ushort freq;
229 int norm;
230 int interlace;
231 int color_fmt;
232 ushort depth;
235 struct bttv_pll_info {
236 unsigned int pll_ifreq; /* PLL input frequency */
237 unsigned int pll_ofreq; /* PLL output frequency */
238 unsigned int pll_crystal; /* Crystal used for input */
239 unsigned int pll_current; /* Currently programmed ofreq */
242 struct bttv_gbuf {
243 int stat;
244 #define GBUFFER_UNUSED 0
245 #define GBUFFER_GRABBING 1
246 #define GBUFFER_DONE 2
247 #define GBUFFER_ERROR 3
248 struct timeval tv;
250 u16 width;
251 u16 height;
252 u16 fmt;
254 u32 *risc;
255 unsigned long ro;
256 unsigned long re;
259 struct bttv {
260 struct video_device video_dev;
261 struct video_device radio_dev;
262 struct video_device vbi_dev;
263 struct video_picture picture; /* Current picture params */
264 struct video_audio audio_dev; /* Current audio params */
266 spinlock_t s_lock;
267 struct semaphore lock;
268 int user;
269 int capuser;
271 /* i2c */
272 struct i2c_adapter i2c_adap;
273 struct i2c_algo_bit_data i2c_algo;
274 struct i2c_client i2c_client;
275 int i2c_state, i2c_ok;
276 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];
278 int tuner_type;
279 int channel;
281 unsigned int nr;
282 unsigned short id;
283 struct pci_dev *dev;
284 unsigned int irq; /* IRQ used by Bt848 card */
285 unsigned char revision;
286 unsigned long bt848_adr; /* bus address of IO mem returned by PCI BIOS */
287 unsigned char *bt848_mem; /* pointer to mapped IO memory */
288 unsigned long busriscmem;
289 u32 *riscmem;
291 unsigned char *vbibuf;
292 struct bttv_window win;
293 int fb_color_ctl;
294 int type; /* card type */
295 int cardid;
296 int audio; /* audio mode */
297 int audio_chip; /* set to one of the chips supported by bttv.c */
298 int radio;
300 u32 *risc_jmp;
301 u32 *vbi_odd;
302 u32 *vbi_even;
303 u32 bus_vbi_even;
304 u32 bus_vbi_odd;
305 wait_queue_head_t vbiq;
306 wait_queue_head_t capq;
307 int vbip;
309 u32 *risc_scr_odd;
310 u32 *risc_scr_even;
311 u32 risc_cap_odd;
312 u32 risc_cap_even;
313 int scr_on;
314 int vbi_on;
315 struct video_clip *cliprecs;
317 struct bttv_gbuf *gbuf;
318 int gqueue[MAX_GBUFFERS];
319 int gq_in,gq_out,gq_grab,gq_start;
320 char *fbuffer;
322 struct bttv_pll_info pll;
323 unsigned int Fsc;
324 unsigned int field;
325 unsigned int last_field; /* number of last grabbed field */
326 int i2c_command;
327 int triton1;
329 int errors;
330 int needs_restart;
332 wait_queue_head_t gpioq;
333 int shutdown;
335 #endif
337 #if defined(__powerpc__) /* big-endian */
338 extern __inline__ void io_st_le32(volatile unsigned *addr, unsigned val)
340 __asm__ __volatile__ ("stwbrx %1,0,%2" : \
341 "=m" (*addr) : "r" (val), "r" (addr));
342 __asm__ __volatile__ ("eieio" : : : "memory");
345 #define btwrite(dat,adr) io_st_le32((unsigned *)(btv->bt848_mem+(adr)),(dat))
346 #define btread(adr) ld_le32((unsigned *)(btv->bt848_mem+(adr)))
347 #else
348 #define btwrite(dat,adr) writel((dat), (char *) (btv->bt848_mem+(adr)))
349 #define btread(adr) readl(btv->bt848_mem+(adr))
350 #endif
352 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
353 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
354 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
356 /* bttv ioctls */
358 #define BTTV_READEE _IOW('v', BASE_VIDIOCPRIVATE+0, char [256])
359 #define BTTV_WRITEE _IOR('v', BASE_VIDIOCPRIVATE+1, char [256])
360 #define BTTV_FIELDNR _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int)
361 #define BTTV_PLLSET _IOW('v' , BASE_VIDIOCPRIVATE+3, struct bttv_pll_info)
362 #define BTTV_BURST_ON _IOR('v' , BASE_VIDIOCPRIVATE+4, int)
363 #define BTTV_BURST_OFF _IOR('v' , BASE_VIDIOCPRIVATE+5, int)
364 #define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
365 #define BTTV_PICNR _IOR('v' , BASE_VIDIOCPRIVATE+7, int)
366 #define BTTV_VBISIZE _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
368 #define AUDIO_TUNER 0x00
369 #define AUDIO_RADIO 0x01
370 #define AUDIO_EXTERN 0x02
371 #define AUDIO_INTERN 0x03
372 #define AUDIO_OFF 0x04
373 #define AUDIO_ON 0x05
374 #define AUDIO_MUTE 0x80
375 #define AUDIO_UNMUTE 0x81
377 #define TDA9850 0x01
378 #define TDA9840 0x02
379 #define TDA8425 0x03
380 #define TEA6300 0x04
382 #define I2C_TSA5522 0xc2
383 #define I2C_TDA7432 0x8a
384 #define I2C_TDA8425 0x82
385 #define I2C_TDA9840 0x84
386 #define I2C_TDA9850 0xb6 /* also used by 9855,9873 */
387 #define I2C_TDA9875 0xb0
388 #define I2C_HAUPEE 0xa0
389 #define I2C_STBEE 0xae
390 #define I2C_VHX 0xc0
391 #define I2C_MSP3400 0x80
392 #define I2C_TEA6300 0x80
393 #define I2C_DPL3518 0x84
395 #ifndef HAVE_TVAUDIO
396 #define TDA9840_SW 0x00
397 #define TDA9840_LVADJ 0x02
398 #define TDA9840_STADJ 0x03
399 #define TDA9840_TEST 0x04
400 #endif
402 #define PT2254_L_CHANEL 0x10
403 #define PT2254_R_CHANEL 0x08
404 #define PT2254_DBS_IN_2 0x400
405 #define PT2254_DBS_IN_10 0x20000
406 #define WINVIEW_PT2254_CLK 0x40
407 #define WINVIEW_PT2254_DATA 0x20
408 #define WINVIEW_PT2254_STROBE 0x80
410 struct bttv_just_hacking {
411 int height,width; /* size */
412 unsigned int format; /* should be VIDEO_PALETTE_* */
413 long buf;
414 int len;
417 #define BTTV_JUST_HACKING _IOR('v' , BASE_VIDIOCPRIVATE+31,struct bttv_just_hacking)
419 #endif
422 * Local variables:
423 * c-basic-offset: 8
424 * End: