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,31)
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"
40 /* returns card type + card ID (for bt878-based ones)
41 for possible values see lines below beginning with #define BTTV_UNKNOWN
42 returns negative value if error ocurred
44 extern int bttv_get_cardinfo(unsigned int card
, int *type
, int *cardid
);
46 /* obsolete, use bttv_get_cardinfo instead */
47 extern int bttv_get_id(unsigned int card
);
49 /* sets GPOE register (BT848_GPIO_OUT_EN) to new value:
50 data | (current_GPOE_value & ~mask)
51 returns negative value if error ocurred
53 extern int bttv_gpio_enable(unsigned int card
,
54 unsigned long mask
, unsigned long data
);
56 /* fills data with GPDATA register contents
57 returns negative value if error ocurred
59 extern int bttv_read_gpio(unsigned int card
, unsigned long *data
);
61 /* sets GPDATA register to new value:
62 (data & mask) | (current_GPDATA_value & ~mask)
63 returns negative value if error ocurred
65 extern int bttv_write_gpio(unsigned int card
,
66 unsigned long mask
, unsigned long data
);
68 /* returns pointer to task queue which can be used as parameter to
69 interruptible_sleep_on
70 in interrupt handler if BT848_INT_GPINT bit is set - this queue is activated
71 (wake_up_interruptible) and following call to the function bttv_read_gpio
72 should return new value of GPDATA,
73 returns NULL value if error ocurred or queue is not available
74 WARNING: because there is no buffer for GPIO data, one MUST
77 extern wait_queue_head_t
* bttv_get_gpio_queue(unsigned int card
);
81 #define O_NONCAP O_TRUNC
84 #define MAX_GBUFFERS 64
85 #define RISCMEM_LEN (32744*2)
86 #define VBI_MAXLINES 16
87 #define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
89 #define BTTV_MAX_FBUF 0x208000
90 #define I2C_CLIENTS_MAX 8
99 ushort swidth
, sheight
;
100 unsigned long vidadr
;
108 struct bttv_pll_info
{
109 unsigned int pll_ifreq
; /* PLL input frequency */
110 unsigned int pll_ofreq
; /* PLL output frequency */
111 unsigned int pll_crystal
; /* Crystal used for input */
112 unsigned int pll_current
; /* Currently programmed ofreq */
117 #define GBUFFER_UNUSED 0
118 #define GBUFFER_GRABBING 1
119 #define GBUFFER_DONE 2
120 #define GBUFFER_ERROR 3
133 struct video_device video_dev
;
134 struct video_device radio_dev
;
135 struct video_device vbi_dev
;
136 struct video_picture picture
; /* Current picture params */
137 struct video_audio audio_dev
; /* Current audio params */
140 struct semaphore lock
;
145 struct i2c_adapter i2c_adap
;
146 struct i2c_algo_bit_data i2c_algo
;
147 struct i2c_client i2c_client
;
148 int i2c_state
, i2c_ok
;
149 struct i2c_client
*i2c_clients
[I2C_CLIENTS_MAX
];
157 unsigned int irq
; /* IRQ used by Bt848 card */
158 unsigned char revision
;
159 unsigned long bt848_adr
; /* bus address of IO mem returned by PCI BIOS */
160 unsigned char *bt848_mem
; /* pointer to mapped IO memory */
161 unsigned long busriscmem
;
164 unsigned char *vbibuf
;
165 struct bttv_window win
;
167 int type
; /* card type */
169 int audio
; /* audio mode */
170 int audio_chip
; /* set to one of the chips supported by bttv.c */
178 wait_queue_head_t vbiq
;
179 wait_queue_head_t capq
;
188 struct video_clip
*cliprecs
;
190 struct bttv_gbuf
*gbuf
;
191 int gqueue
[MAX_GBUFFERS
];
192 int gq_in
,gq_out
,gq_grab
,gq_start
;
195 struct bttv_pll_info pll
;
198 unsigned int last_field
; /* number of last grabbed field */
205 wait_queue_head_t gpioq
;
210 #if defined(__powerpc__) /* big-endian */
211 extern __inline__
void io_st_le32(volatile unsigned *addr
, unsigned val
)
213 __asm__
__volatile__ ("stwbrx %1,0,%2" : \
214 "=m" (*addr
) : "r" (val
), "r" (addr
));
215 __asm__
__volatile__ ("eieio" : : : "memory");
218 #define btwrite(dat,adr) io_st_le32((unsigned *)(btv->bt848_mem+(adr)),(dat))
219 #define btread(adr) ld_le32((unsigned *)(btv->bt848_mem+(adr)))
221 #define btwrite(dat,adr) writel((dat), (char *) (btv->bt848_mem+(adr)))
222 #define btread(adr) readl(btv->bt848_mem+(adr))
225 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
226 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
227 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
231 #define BTTV_READEE _IOW('v', BASE_VIDIOCPRIVATE+0, char [256])
232 #define BTTV_WRITEE _IOR('v', BASE_VIDIOCPRIVATE+1, char [256])
233 #define BTTV_FIELDNR _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int)
234 #define BTTV_PLLSET _IOW('v' , BASE_VIDIOCPRIVATE+3, struct bttv_pll_info)
235 #define BTTV_BURST_ON _IOR('v' , BASE_VIDIOCPRIVATE+4, int)
236 #define BTTV_BURST_OFF _IOR('v' , BASE_VIDIOCPRIVATE+5, int)
237 #define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
238 #define BTTV_PICNR _IOR('v' , BASE_VIDIOCPRIVATE+7, int)
239 #define BTTV_VBISIZE _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
241 #define BTTV_UNKNOWN 0x00
242 #define BTTV_MIRO 0x01
243 #define BTTV_HAUPPAUGE 0x02
244 #define BTTV_STB 0x03
245 #define BTTV_INTEL 0x04
246 #define BTTV_DIAMOND 0x05
247 #define BTTV_AVERMEDIA 0x06
248 #define BTTV_MATRIX_VISION 0x07
249 #define BTTV_FLYVIDEO 0x08
250 #define BTTV_TURBOTV 0x09
251 #define BTTV_HAUPPAUGE878 0x0a
252 #define BTTV_MIROPRO 0x0b
253 #define BTTV_ADSTECH_TV 0x0c
254 #define BTTV_AVERMEDIA98 0x0d
255 #define BTTV_VHX 0x0e
256 #define BTTV_ZOLTRIX 0x0f
257 #define BTTV_PIXVIEWPLAYTV 0x10
258 #define BTTV_WINVIEW_601 0x11
259 #define BTTV_AVEC_INTERCAP 0x12
260 #define BTTV_LIFE_FLYKIT 0x13
261 #define BTTV_CEI_RAFFLES 0x14
262 #define BTTV_CONFERENCETV 0x15
263 #define BTTV_PHOEBE_TVMAS 0x16
264 #define BTTV_MODTEC_205 0x17
265 #define BTTV_MAGICTVIEW061 0x18
266 #define BTTV_VOBIS_BOOSTAR 0x19
267 #define BTTV_HAUPPAUG_WCAM 0x1a
268 #define BTTV_MAXI 0x1b
269 #define BTTV_TERRATV 0x1c
270 #define BTTV_PXC200 0x1d
271 #define BTTV_FLYVIDEO_98 0x1e
272 #define BTTV_IPROTV 0x1f
273 #define BTTV_INTEL_C_S_PCI 0x20
274 #define BTTV_TERRATVALUE 0x21
275 #define BTTV_WINFAST2000 0x22
276 #define BTTV_CHRONOS_VS2 0x23
277 #define BTTV_TYPHOON_TVIEW 0x24
278 #define BTTV_PXELVWPLTVPRO 0x25
279 #define BTTV_MAGICTVIEW063 0x26
280 #define BTTV_PINNACLERAVE 0x27
281 #define BTTV_STB2 0x28
282 #define BTTV_AVPHONE98 0x29
283 #define BTTV_PV951 0x2a
284 #define BTTV_ONAIR_TV 0x2b
285 #define BTTV_SIGMA_TVII_FM 0x2c
291 #define AUDIO_TUNER 0x00
292 #define AUDIO_RADIO 0x01
293 #define AUDIO_EXTERN 0x02
294 #define AUDIO_INTERN 0x03
295 #define AUDIO_OFF 0x04
296 #define AUDIO_ON 0x05
297 #define AUDIO_MUTE 0x80
298 #define AUDIO_UNMUTE 0x81
305 #define I2C_TSA5522 0xc2
306 #define I2C_TDA7432 0x8a
307 #define I2C_TDA8425 0x82
308 #define I2C_TDA9840 0x84
309 #define I2C_TDA9850 0xb6
310 #define I2C_TDA9875 0xb0
311 #define I2C_HAUPEE 0xa0
312 #define I2C_STBEE 0xae
314 #define I2C_MSP3400 0x80
315 #define I2C_TEA6300 0x80
316 #define I2C_DPL3518 0x84
318 #define TDA9840_SW 0x00
319 #define TDA9840_LVADJ 0x02
320 #define TDA9840_STADJ 0x03
321 #define TDA9840_TEST 0x04
323 #define PT2254_L_CHANEL 0x10
324 #define PT2254_R_CHANEL 0x08
325 #define PT2254_DBS_IN_2 0x400
326 #define PT2254_DBS_IN_10 0x20000
327 #define WINVIEW_PT2254_CLK 0x40
328 #define WINVIEW_PT2254_DATA 0x20
329 #define WINVIEW_PT2254_STROBE 0x80