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.
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"
46 /* ---------------------------------------------------------- */
47 /* exported by bttv-cards.c */
49 #define BTTV_UNKNOWN 0x00
50 #define BTTV_MIRO 0x01
51 #define BTTV_HAUPPAUGE 0x02
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
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
108 u32 audiomux
[6]; /* Tuner, Radio, external, internal, mute, stereo */
109 u32 gpiomask2
; /* GPIO MUX mask */
111 /* look for these i2c audio chips */
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
181 extern wait_queue_head_t
* bttv_get_gpio_queue(unsigned int card
);
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 /* ---------------------------------------------------------- */
200 extern unsigned int bttv_verbose
;
201 extern unsigned int bttv_debug
;
203 /* Anybody who uses more than four? */
205 extern int bttv_num
; /* number of Bt848s in use */
206 extern struct bttv bttvs
[BTTV_MAX
];
210 #define O_NONCAP O_TRUNC
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
224 ushort width
, height
;
226 ushort swidth
, sheight
;
227 unsigned long vidadr
;
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 */
244 #define GBUFFER_UNUSED 0
245 #define GBUFFER_GRABBING 1
246 #define GBUFFER_DONE 2
247 #define GBUFFER_ERROR 3
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 */
267 struct semaphore lock
;
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
];
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
;
291 unsigned char *vbibuf
;
292 struct bttv_window win
;
294 int type
; /* card type */
296 int audio
; /* audio mode */
297 int audio_chip
; /* set to one of the chips supported by bttv.c */
305 wait_queue_head_t vbiq
;
306 wait_queue_head_t capq
;
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
;
322 struct bttv_pll_info pll
;
325 unsigned int last_field
; /* number of last grabbed field */
332 wait_queue_head_t gpioq
;
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)))
348 #define btwrite(dat,adr) writel((dat), (char *) (btv->bt848_mem+(adr)))
349 #define btread(adr) readl(btv->bt848_mem+(adr))
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)
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
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
391 #define I2C_MSP3400 0x80
392 #define I2C_TEA6300 0x80
393 #define I2C_DPL3518 0x84
396 #define TDA9840_SW 0x00
397 #define TDA9840_LVADJ 0x02
398 #define TDA9840_STADJ 0x03
399 #define TDA9840_TEST 0x04
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_* */
417 #define BTTV_JUST_HACKING _IOR('v' , BASE_VIDIOCPRIVATE+31,struct bttv_just_hacking)