aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/bt8xx
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/bt8xx')
-rw-r--r--drivers/media/video/bt8xx/Kconfig27
-rw-r--r--drivers/media/video/bt8xx/Makefile13
-rw-r--r--drivers/media/video/bt8xx/bt848.h366
-rw-r--r--drivers/media/video/bt8xx/bttv-audio-hook.c382
-rw-r--r--drivers/media/video/bt8xx/bttv-audio-hook.h23
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c4916
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c4626
-rw-r--r--drivers/media/video/bt8xx/bttv-gpio.c187
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c391
-rw-r--r--drivers/media/video/bt8xx/bttv-if.c121
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c588
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c910
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c454
-rw-r--r--drivers/media/video/bt8xx/bttv.h376
-rw-r--r--drivers/media/video/bt8xx/bttvp.h522
15 files changed, 13902 insertions, 0 deletions
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
new file mode 100644
index 00000000000..7da5c2e1fc1
--- /dev/null
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -0,0 +1,27 @@
1config VIDEO_BT848
2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2
4 select I2C_ALGOBIT
5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG
7 depends on RC_CORE
8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
11 select VIDEO_TVAUDIO if VIDEO_HELPER_CHIPS_AUTO
12 select VIDEO_TDA7432 if VIDEO_HELPER_CHIPS_AUTO
13 select VIDEO_SAA6588 if VIDEO_HELPER_CHIPS_AUTO
14 ---help---
15 Support for BT848 based frame grabber/overlay boards. This includes
16 the Miro, Hauppauge and STB boards. Please read the material in
17 <file:Documentation/video4linux/bttv/> for more information.
18
19 To compile this driver as a module, choose M here: the
20 module will be called bttv.
21
22config VIDEO_BT848_DVB
23 bool "DVB/ATSC Support for bt878 based TV cards"
24 depends on VIDEO_BT848 && DVB_CORE
25 select DVB_BT8XX
26 ---help---
27 This adds support for DVB/ATSC cards based on the BT878 chip.
diff --git a/drivers/media/video/bt8xx/Makefile b/drivers/media/video/bt8xx/Makefile
new file mode 100644
index 00000000000..e415f6fc447
--- /dev/null
+++ b/drivers/media/video/bt8xx/Makefile
@@ -0,0 +1,13 @@
1#
2# Makefile for the video capture/playback device drivers.
3#
4
5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \
7 bttv-input.o bttv-audio-hook.o
8
9obj-$(CONFIG_VIDEO_BT848) += bttv.o
10
11EXTRA_CFLAGS += -Idrivers/media/video
12EXTRA_CFLAGS += -Idrivers/media/common/tuners
13EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
diff --git a/drivers/media/video/bt8xx/bt848.h b/drivers/media/video/bt8xx/bt848.h
new file mode 100644
index 00000000000..0bcd95303bb
--- /dev/null
+++ b/drivers/media/video/bt8xx/bt848.h
@@ -0,0 +1,366 @@
1/*
2 bt848.h - Bt848 register offsets
3
4 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
5
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.
10
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.
15
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.
19*/
20
21#ifndef _BT848_H_
22#define _BT848_H_
23
24#ifndef PCI_VENDOR_ID_BROOKTREE
25#define PCI_VENDOR_ID_BROOKTREE 0x109e
26#endif
27#ifndef PCI_DEVICE_ID_BT848
28#define PCI_DEVICE_ID_BT848 0x350
29#endif
30#ifndef PCI_DEVICE_ID_BT849
31#define PCI_DEVICE_ID_BT849 0x351
32#endif
33#ifndef PCI_DEVICE_ID_BT878
34#define PCI_DEVICE_ID_BT878 0x36e
35#endif
36#ifndef PCI_DEVICE_ID_BT879
37#define PCI_DEVICE_ID_BT879 0x36f
38#endif
39
40
41/* Brooktree 848 registers */
42
43#define BT848_DSTATUS 0x000
44#define BT848_DSTATUS_PRES (1<<7)
45#define BT848_DSTATUS_HLOC (1<<6)
46#define BT848_DSTATUS_FIELD (1<<5)
47#define BT848_DSTATUS_NUML (1<<4)
48#define BT848_DSTATUS_CSEL (1<<3)
49#define BT848_DSTATUS_PLOCK (1<<2)
50#define BT848_DSTATUS_LOF (1<<1)
51#define BT848_DSTATUS_COF (1<<0)
52
53#define BT848_IFORM 0x004
54#define BT848_IFORM_HACTIVE (1<<7)
55#define BT848_IFORM_MUXSEL (3<<5)
56#define BT848_IFORM_MUX0 (2<<5)
57#define BT848_IFORM_MUX1 (3<<5)
58#define BT848_IFORM_MUX2 (1<<5)
59#define BT848_IFORM_XTSEL (3<<3)
60#define BT848_IFORM_XT0 (1<<3)
61#define BT848_IFORM_XT1 (2<<3)
62#define BT848_IFORM_XTAUTO (3<<3)
63#define BT848_IFORM_XTBOTH (3<<3)
64#define BT848_IFORM_NTSC 1
65#define BT848_IFORM_NTSC_J 2
66#define BT848_IFORM_PAL_BDGHI 3
67#define BT848_IFORM_PAL_M 4
68#define BT848_IFORM_PAL_N 5
69#define BT848_IFORM_SECAM 6
70#define BT848_IFORM_PAL_NC 7
71#define BT848_IFORM_AUTO 0
72#define BT848_IFORM_NORM 7
73
74#define BT848_TDEC 0x008
75#define BT848_TDEC_DEC_FIELD (1<<7)
76#define BT848_TDEC_FLDALIGN (1<<6)
77#define BT848_TDEC_DEC_RAT (0x1f)
78
79#define BT848_E_CROP 0x00C
80#define BT848_O_CROP 0x08C
81
82#define BT848_E_VDELAY_LO 0x010
83#define BT848_O_VDELAY_LO 0x090
84
85#define BT848_E_VACTIVE_LO 0x014
86#define BT848_O_VACTIVE_LO 0x094
87
88#define BT848_E_HDELAY_LO 0x018
89#define BT848_O_HDELAY_LO 0x098
90
91#define BT848_E_HACTIVE_LO 0x01C
92#define BT848_O_HACTIVE_LO 0x09C
93
94#define BT848_E_HSCALE_HI 0x020
95#define BT848_O_HSCALE_HI 0x0A0
96
97#define BT848_E_HSCALE_LO 0x024
98#define BT848_O_HSCALE_LO 0x0A4
99
100#define BT848_BRIGHT 0x028
101
102#define BT848_E_CONTROL 0x02C
103#define BT848_O_CONTROL 0x0AC
104#define BT848_CONTROL_LNOTCH (1<<7)
105#define BT848_CONTROL_COMP (1<<6)
106#define BT848_CONTROL_LDEC (1<<5)
107#define BT848_CONTROL_CBSENSE (1<<4)
108#define BT848_CONTROL_CON_MSB (1<<2)
109#define BT848_CONTROL_SAT_U_MSB (1<<1)
110#define BT848_CONTROL_SAT_V_MSB (1<<0)
111
112#define BT848_CONTRAST_LO 0x030
113#define BT848_SAT_U_LO 0x034
114#define BT848_SAT_V_LO 0x038
115#define BT848_HUE 0x03C
116
117#define BT848_E_SCLOOP 0x040
118#define BT848_O_SCLOOP 0x0C0
119#define BT848_SCLOOP_CAGC (1<<6)
120#define BT848_SCLOOP_CKILL (1<<5)
121#define BT848_SCLOOP_HFILT_AUTO (0<<3)
122#define BT848_SCLOOP_HFILT_CIF (1<<3)
123#define BT848_SCLOOP_HFILT_QCIF (2<<3)
124#define BT848_SCLOOP_HFILT_ICON (3<<3)
125
126#define BT848_SCLOOP_PEAK (1<<7)
127#define BT848_SCLOOP_HFILT_MINP (1<<3)
128#define BT848_SCLOOP_HFILT_MEDP (2<<3)
129#define BT848_SCLOOP_HFILT_MAXP (3<<3)
130
131
132#define BT848_OFORM 0x048
133#define BT848_OFORM_RANGE (1<<7)
134#define BT848_OFORM_CORE0 (0<<5)
135#define BT848_OFORM_CORE8 (1<<5)
136#define BT848_OFORM_CORE16 (2<<5)
137#define BT848_OFORM_CORE32 (3<<5)
138
139#define BT848_E_VSCALE_HI 0x04C
140#define BT848_O_VSCALE_HI 0x0CC
141#define BT848_VSCALE_YCOMB (1<<7)
142#define BT848_VSCALE_COMB (1<<6)
143#define BT848_VSCALE_INT (1<<5)
144#define BT848_VSCALE_HI 15
145
146#define BT848_E_VSCALE_LO 0x050
147#define BT848_O_VSCALE_LO 0x0D0
148#define BT848_TEST 0x054
149#define BT848_ADELAY 0x060
150#define BT848_BDELAY 0x064
151
152#define BT848_ADC 0x068
153#define BT848_ADC_RESERVED (2<<6)
154#define BT848_ADC_SYNC_T (1<<5)
155#define BT848_ADC_AGC_EN (1<<4)
156#define BT848_ADC_CLK_SLEEP (1<<3)
157#define BT848_ADC_Y_SLEEP (1<<2)
158#define BT848_ADC_C_SLEEP (1<<1)
159#define BT848_ADC_CRUSH (1<<0)
160
161#define BT848_WC_UP 0x044
162#define BT848_WC_DOWN 0x078
163
164#define BT848_E_VTC 0x06C
165#define BT848_O_VTC 0x0EC
166#define BT848_VTC_HSFMT (1<<7)
167#define BT848_VTC_VFILT_2TAP 0
168#define BT848_VTC_VFILT_3TAP 1
169#define BT848_VTC_VFILT_4TAP 2
170#define BT848_VTC_VFILT_5TAP 3
171
172#define BT848_SRESET 0x07C
173
174#define BT848_COLOR_FMT 0x0D4
175#define BT848_COLOR_FMT_O_RGB32 (0<<4)
176#define BT848_COLOR_FMT_O_RGB24 (1<<4)
177#define BT848_COLOR_FMT_O_RGB16 (2<<4)
178#define BT848_COLOR_FMT_O_RGB15 (3<<4)
179#define BT848_COLOR_FMT_O_YUY2 (4<<4)
180#define BT848_COLOR_FMT_O_BtYUV (5<<4)
181#define BT848_COLOR_FMT_O_Y8 (6<<4)
182#define BT848_COLOR_FMT_O_RGB8 (7<<4)
183#define BT848_COLOR_FMT_O_YCrCb422 (8<<4)
184#define BT848_COLOR_FMT_O_YCrCb411 (9<<4)
185#define BT848_COLOR_FMT_O_RAW (14<<4)
186#define BT848_COLOR_FMT_E_RGB32 0
187#define BT848_COLOR_FMT_E_RGB24 1
188#define BT848_COLOR_FMT_E_RGB16 2
189#define BT848_COLOR_FMT_E_RGB15 3
190#define BT848_COLOR_FMT_E_YUY2 4
191#define BT848_COLOR_FMT_E_BtYUV 5
192#define BT848_COLOR_FMT_E_Y8 6
193#define BT848_COLOR_FMT_E_RGB8 7
194#define BT848_COLOR_FMT_E_YCrCb422 8
195#define BT848_COLOR_FMT_E_YCrCb411 9
196#define BT848_COLOR_FMT_E_RAW 14
197
198#define BT848_COLOR_FMT_RGB32 0x00
199#define BT848_COLOR_FMT_RGB24 0x11
200#define BT848_COLOR_FMT_RGB16 0x22
201#define BT848_COLOR_FMT_RGB15 0x33
202#define BT848_COLOR_FMT_YUY2 0x44
203#define BT848_COLOR_FMT_BtYUV 0x55
204#define BT848_COLOR_FMT_Y8 0x66
205#define BT848_COLOR_FMT_RGB8 0x77
206#define BT848_COLOR_FMT_YCrCb422 0x88
207#define BT848_COLOR_FMT_YCrCb411 0x99
208#define BT848_COLOR_FMT_RAW 0xee
209
210#define BT848_VTOTAL_LO 0xB0
211#define BT848_VTOTAL_HI 0xB4
212
213#define BT848_COLOR_CTL 0x0D8
214#define BT848_COLOR_CTL_EXT_FRMRATE (1<<7)
215#define BT848_COLOR_CTL_COLOR_BARS (1<<6)
216#define BT848_COLOR_CTL_RGB_DED (1<<5)
217#define BT848_COLOR_CTL_GAMMA (1<<4)
218#define BT848_COLOR_CTL_WSWAP_ODD (1<<3)
219#define BT848_COLOR_CTL_WSWAP_EVEN (1<<2)
220#define BT848_COLOR_CTL_BSWAP_ODD (1<<1)
221#define BT848_COLOR_CTL_BSWAP_EVEN (1<<0)
222
223#define BT848_CAP_CTL 0x0DC
224#define BT848_CAP_CTL_DITH_FRAME (1<<4)
225#define BT848_CAP_CTL_CAPTURE_VBI_ODD (1<<3)
226#define BT848_CAP_CTL_CAPTURE_VBI_EVEN (1<<2)
227#define BT848_CAP_CTL_CAPTURE_ODD (1<<1)
228#define BT848_CAP_CTL_CAPTURE_EVEN (1<<0)
229
230#define BT848_VBI_PACK_SIZE 0x0E0
231
232#define BT848_VBI_PACK_DEL 0x0E4
233#define BT848_VBI_PACK_DEL_VBI_HDELAY 0xfc
234#define BT848_VBI_PACK_DEL_EXT_FRAME 2
235#define BT848_VBI_PACK_DEL_VBI_PKT_HI 1
236
237
238#define BT848_INT_STAT 0x100
239#define BT848_INT_MASK 0x104
240
241#define BT848_INT_ETBF (1<<23)
242
243#define BT848_INT_RISCS (0xf<<28)
244#define BT848_INT_RISC_EN (1<<27)
245#define BT848_INT_RACK (1<<25)
246#define BT848_INT_FIELD (1<<24)
247#define BT848_INT_SCERR (1<<19)
248#define BT848_INT_OCERR (1<<18)
249#define BT848_INT_PABORT (1<<17)
250#define BT848_INT_RIPERR (1<<16)
251#define BT848_INT_PPERR (1<<15)
252#define BT848_INT_FDSR (1<<14)
253#define BT848_INT_FTRGT (1<<13)
254#define BT848_INT_FBUS (1<<12)
255#define BT848_INT_RISCI (1<<11)
256#define BT848_INT_GPINT (1<<9)
257#define BT848_INT_I2CDONE (1<<8)
258#define BT848_INT_VPRES (1<<5)
259#define BT848_INT_HLOCK (1<<4)
260#define BT848_INT_OFLOW (1<<3)
261#define BT848_INT_HSYNC (1<<2)
262#define BT848_INT_VSYNC (1<<1)
263#define BT848_INT_FMTCHG (1<<0)
264
265
266#define BT848_GPIO_DMA_CTL 0x10C
267#define BT848_GPIO_DMA_CTL_GPINTC (1<<15)
268#define BT848_GPIO_DMA_CTL_GPINTI (1<<14)
269#define BT848_GPIO_DMA_CTL_GPWEC (1<<13)
270#define BT848_GPIO_DMA_CTL_GPIOMODE (3<<11)
271#define BT848_GPIO_DMA_CTL_GPCLKMODE (1<<10)
272#define BT848_GPIO_DMA_CTL_PLTP23_4 (0<<6)
273#define BT848_GPIO_DMA_CTL_PLTP23_8 (1<<6)
274#define BT848_GPIO_DMA_CTL_PLTP23_16 (2<<6)
275#define BT848_GPIO_DMA_CTL_PLTP23_32 (3<<6)
276#define BT848_GPIO_DMA_CTL_PLTP1_4 (0<<4)
277#define BT848_GPIO_DMA_CTL_PLTP1_8 (1<<4)
278#define BT848_GPIO_DMA_CTL_PLTP1_16 (2<<4)
279#define BT848_GPIO_DMA_CTL_PLTP1_32 (3<<4)
280#define BT848_GPIO_DMA_CTL_PKTP_4 (0<<2)
281#define BT848_GPIO_DMA_CTL_PKTP_8 (1<<2)
282#define BT848_GPIO_DMA_CTL_PKTP_16 (2<<2)
283#define BT848_GPIO_DMA_CTL_PKTP_32 (3<<2)
284#define BT848_GPIO_DMA_CTL_RISC_ENABLE (1<<1)
285#define BT848_GPIO_DMA_CTL_FIFO_ENABLE (1<<0)
286
287#define BT848_I2C 0x110
288#define BT878_I2C_MODE (1<<7)
289#define BT878_I2C_RATE (1<<6)
290#define BT878_I2C_NOSTOP (1<<5)
291#define BT878_I2C_NOSTART (1<<4)
292#define BT848_I2C_DIV (0xf<<4)
293#define BT848_I2C_SYNC (1<<3)
294#define BT848_I2C_W3B (1<<2)
295#define BT848_I2C_SCL (1<<1)
296#define BT848_I2C_SDA (1<<0)
297
298#define BT848_RISC_STRT_ADD 0x114
299#define BT848_GPIO_OUT_EN 0x118
300#define BT848_GPIO_REG_INP 0x11C
301#define BT848_RISC_COUNT 0x120
302#define BT848_GPIO_DATA 0x200
303
304
305/* Bt848 RISC commands */
306
307/* only for the SYNC RISC command */
308#define BT848_FIFO_STATUS_FM1 0x06
309#define BT848_FIFO_STATUS_FM3 0x0e
310#define BT848_FIFO_STATUS_SOL 0x02
311#define BT848_FIFO_STATUS_EOL4 0x01
312#define BT848_FIFO_STATUS_EOL3 0x0d
313#define BT848_FIFO_STATUS_EOL2 0x09
314#define BT848_FIFO_STATUS_EOL1 0x05
315#define BT848_FIFO_STATUS_VRE 0x04
316#define BT848_FIFO_STATUS_VRO 0x0c
317#define BT848_FIFO_STATUS_PXV 0x00
318
319#define BT848_RISC_RESYNC (1<<15)
320
321/* WRITE and SKIP */
322/* disable which bytes of each DWORD */
323#define BT848_RISC_BYTE0 (1U<<12)
324#define BT848_RISC_BYTE1 (1U<<13)
325#define BT848_RISC_BYTE2 (1U<<14)
326#define BT848_RISC_BYTE3 (1U<<15)
327#define BT848_RISC_BYTE_ALL (0x0fU<<12)
328#define BT848_RISC_BYTE_NONE 0
329/* cause RISCI */
330#define BT848_RISC_IRQ (1U<<24)
331/* RISC command is last one in this line */
332#define BT848_RISC_EOL (1U<<26)
333/* RISC command is first one in this line */
334#define BT848_RISC_SOL (1U<<27)
335
336#define BT848_RISC_WRITE (0x01U<<28)
337#define BT848_RISC_SKIP (0x02U<<28)
338#define BT848_RISC_WRITEC (0x05U<<28)
339#define BT848_RISC_JUMP (0x07U<<28)
340#define BT848_RISC_SYNC (0x08U<<28)
341
342#define BT848_RISC_WRITE123 (0x09U<<28)
343#define BT848_RISC_SKIP123 (0x0aU<<28)
344#define BT848_RISC_WRITE1S23 (0x0bU<<28)
345
346
347/* Bt848A and higher only !! */
348#define BT848_TGLB 0x080
349#define BT848_TGCTRL 0x084
350#define BT848_FCAP 0x0E8
351#define BT848_PLL_F_LO 0x0F0
352#define BT848_PLL_F_HI 0x0F4
353
354#define BT848_PLL_XCI 0x0F8
355#define BT848_PLL_X (1<<7)
356#define BT848_PLL_C (1<<6)
357
358#define BT848_DVSIF 0x0FC
359
360/* Bt878 register */
361
362#define BT878_DEVCTRL 0x40
363#define BT878_EN_TBFX 0x02
364#define BT878_EN_VSFX 0x04
365
366#endif
diff --git a/drivers/media/video/bt8xx/bttv-audio-hook.c b/drivers/media/video/bt8xx/bttv-audio-hook.c
new file mode 100644
index 00000000000..2364d16586b
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-audio-hook.c
@@ -0,0 +1,382 @@
1/*
2 * Handlers for board audio hooks, splitted from bttv-cards
3 *
4 * Copyright (c) 2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License
6 */
7
8#include "bttv-audio-hook.h"
9
10#include <linux/delay.h>
11
12/* ----------------------------------------------------------------------- */
13/* winview */
14
15void winview_volume(struct bttv *btv, __u16 volume)
16{
17 /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
18 int bits_out, loops, vol, data;
19
20 /* 32 levels logarithmic */
21 vol = 32 - ((volume>>11));
22 /* units */
23 bits_out = (PT2254_DBS_IN_2>>(vol%5));
24 /* tens */
25 bits_out |= (PT2254_DBS_IN_10>>(vol/5));
26 bits_out |= PT2254_L_CHANNEL | PT2254_R_CHANNEL;
27 data = gpio_read();
28 data &= ~(WINVIEW_PT2254_CLK| WINVIEW_PT2254_DATA|
29 WINVIEW_PT2254_STROBE);
30 for (loops = 17; loops >= 0 ; loops--) {
31 if (bits_out & (1<<loops))
32 data |= WINVIEW_PT2254_DATA;
33 else
34 data &= ~WINVIEW_PT2254_DATA;
35 gpio_write(data);
36 udelay(5);
37 data |= WINVIEW_PT2254_CLK;
38 gpio_write(data);
39 udelay(5);
40 data &= ~WINVIEW_PT2254_CLK;
41 gpio_write(data);
42 }
43 data |= WINVIEW_PT2254_STROBE;
44 data &= ~WINVIEW_PT2254_DATA;
45 gpio_write(data);
46 udelay(10);
47 data &= ~WINVIEW_PT2254_STROBE;
48 gpio_write(data);
49}
50
51/* ----------------------------------------------------------------------- */
52/* mono/stereo control for various cards (which don't use i2c chips but */
53/* connect something to the GPIO pins */
54
55void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
56{
57 unsigned int con = 0;
58
59 if (set) {
60 gpio_inout(0x300, 0x300);
61 if (t->audmode & V4L2_TUNER_MODE_LANG1)
62 con = 0x000;
63 if (t->audmode & V4L2_TUNER_MODE_LANG2)
64 con = 0x300;
65 if (t->audmode & V4L2_TUNER_MODE_STEREO)
66 con = 0x200;
67/* if (t->audmode & V4L2_TUNER_MODE_MONO)
68 * con = 0x100; */
69 gpio_bits(0x300, con);
70 } else {
71 t->audmode = V4L2_TUNER_MODE_STEREO |
72 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
73 }
74}
75
76void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
77{
78 unsigned int val, con;
79
80 if (btv->radio_user)
81 return;
82
83 val = gpio_read();
84 if (set) {
85 con = 0x000;
86 if (t->audmode & V4L2_TUNER_MODE_LANG2) {
87 if (t->audmode & V4L2_TUNER_MODE_LANG1) {
88 /* LANG1 + LANG2 */
89 con = 0x100;
90 }
91 else {
92 /* LANG2 */
93 con = 0x300;
94 }
95 }
96 if (con != (val & 0x300)) {
97 gpio_bits(0x300, con);
98 if (bttv_gpio)
99 bttv_gpio_tracking(btv,"gvbctv5pci");
100 }
101 } else {
102 switch (val & 0x70) {
103 case 0x10:
104 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
105 break;
106 case 0x30:
107 t->rxsubchans = V4L2_TUNER_SUB_LANG2;
108 break;
109 case 0x50:
110 t->rxsubchans = V4L2_TUNER_SUB_LANG1;
111 break;
112 case 0x60:
113 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
114 break;
115 case 0x70:
116 t->rxsubchans = V4L2_TUNER_SUB_MONO;
117 break;
118 default:
119 t->rxsubchans = V4L2_TUNER_SUB_MONO |
120 V4L2_TUNER_SUB_STEREO |
121 V4L2_TUNER_SUB_LANG1 |
122 V4L2_TUNER_SUB_LANG2;
123 }
124 t->audmode = V4L2_TUNER_MODE_STEREO |
125 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
126 }
127}
128
129/*
130 * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
131 * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
132 * 0xdde enables mono and 0xccd enables sap
133 *
134 * Petr Vandrovec <VANDROVE@vc.cvut.cz>
135 * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
136 * input/output sound connection, so both must be set for output mode.
137 *
138 * Looks like it's needed only for the "tvphone", the "tvphone 98"
139 * handles this with a tda9840
140 *
141 */
142
143void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
144{
145 int val = 0;
146
147 if (set) {
148 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
149 val = 0x02;
150 if (t->audmode & V4L2_TUNER_MODE_STEREO)
151 val = 0x01;
152 if (val) {
153 gpio_bits(0x03,val);
154 if (bttv_gpio)
155 bttv_gpio_tracking(btv,"avermedia");
156 }
157 } else {
158 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
159 V4L2_TUNER_MODE_LANG1;
160 return;
161 }
162}
163
164
165void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
166{
167 int val = 0;
168
169 if (set) {
170 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
171 val = 0x01;
172 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */
173 val = 0x02;
174 btaor(val, ~0x03, BT848_GPIO_DATA);
175 if (bttv_gpio)
176 bttv_gpio_tracking(btv,"avermedia");
177 } else {
178 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
179 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
180 return;
181 }
182}
183
184/* Lifetec 9415 handling */
185
186void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
187{
188 int val = 0;
189
190 if (gpio_read() & 0x4000) {
191 t->audmode = V4L2_TUNER_MODE_MONO;
192 return;
193 }
194
195 if (set) {
196 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */
197 val = 0x0080;
198 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */
199 val = 0x0880;
200 if ((t->audmode & V4L2_TUNER_MODE_LANG1) ||
201 (t->audmode & V4L2_TUNER_MODE_MONO))
202 val = 0;
203 gpio_bits(0x0880, val);
204 if (bttv_gpio)
205 bttv_gpio_tracking(btv,"lt9415");
206 } else {
207 /* autodetect doesn't work with this card :-( */
208 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
209 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
210 return;
211 }
212}
213
214/* TDA9821 on TerraTV+ Bt848, Bt878 */
215void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
216{
217 unsigned int con = 0;
218
219 if (set) {
220 gpio_inout(0x180000,0x180000);
221 if (t->audmode & V4L2_TUNER_MODE_LANG2)
222 con = 0x080000;
223 if (t->audmode & V4L2_TUNER_MODE_STEREO)
224 con = 0x180000;
225 gpio_bits(0x180000, con);
226 if (bttv_gpio)
227 bttv_gpio_tracking(btv,"terratv");
228 } else {
229 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
230 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
231 }
232}
233
234
235void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
236{
237 unsigned long val = 0;
238
239 if (set) {
240 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
241 if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */
242 val = 0x420000;
243 if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */
244 val = 0x420000;
245 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
246 val = 0x410000;
247 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */
248 val = 0x020000;
249 if (val) {
250 gpio_bits(0x430000, val);
251 if (bttv_gpio)
252 bttv_gpio_tracking(btv,"winfast2000");
253 }
254 } else {
255 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
256 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
257 }
258}
259
260/*
261 * Dariusz Kowalewski <darekk@automex.pl>
262 * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
263 * revision 9B has on-board TDA9874A sound decoder).
264 *
265 * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
266 * will mute this cards.
267 */
268void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
269{
270 unsigned int val = 0;
271
272 if (btv->radio_user)
273 return;
274
275 if (set) {
276 if (t->audmode & V4L2_TUNER_MODE_MONO) {
277 val = 0x01;
278 }
279 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
280 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
281 val = 0x02;
282 }
283 if (val) {
284 gpio_bits(0x03,val);
285 if (bttv_gpio)
286 bttv_gpio_tracking(btv,"pvbt878p9b");
287 }
288 } else {
289 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
290 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
291 }
292}
293
294/*
295 * Dariusz Kowalewski <darekk@automex.pl>
296 * sound control for FlyVideo 2000S (with tda9874 decoder)
297 * based on pvbt878p9b_audio() - this is not tested, please fix!!!
298 */
299void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
300{
301 unsigned int val = 0xffff;
302
303 if (btv->radio_user)
304 return;
305
306 if (set) {
307 if (t->audmode & V4L2_TUNER_MODE_MONO) {
308 val = 0x0000;
309 }
310 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
311 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
312 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
313 }
314 if (val != 0xffff) {
315 gpio_bits(0x1800, val);
316 if (bttv_gpio)
317 bttv_gpio_tracking(btv,"fv2000s");
318 }
319 } else {
320 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
321 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
322 }
323}
324
325/*
326 * sound control for Canopus WinDVR PCI
327 * Masaki Suzuki <masaki@btree.org>
328 */
329void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
330{
331 unsigned long val = 0;
332
333 if (set) {
334 if (t->audmode & V4L2_TUNER_MODE_MONO)
335 val = 0x040000;
336 if (t->audmode & V4L2_TUNER_MODE_LANG1)
337 val = 0;
338 if (t->audmode & V4L2_TUNER_MODE_LANG2)
339 val = 0x100000;
340 if (t->audmode & V4L2_TUNER_MODE_STEREO)
341 val = 0;
342 if (val) {
343 gpio_bits(0x140000, val);
344 if (bttv_gpio)
345 bttv_gpio_tracking(btv,"windvr");
346 }
347 } else {
348 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
349 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
350 }
351}
352
353/*
354 * sound control for AD-TVK503
355 * Hiroshi Takekawa <sian@big.or.jp>
356 */
357void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
358{
359 unsigned int con = 0xffffff;
360
361 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
362
363 if (set) {
364 /* btor(***, BT848_GPIO_OUT_EN); */
365 if (t->audmode & V4L2_TUNER_MODE_LANG1)
366 con = 0x00000000;
367 if (t->audmode & V4L2_TUNER_MODE_LANG2)
368 con = 0x00180000;
369 if (t->audmode & V4L2_TUNER_MODE_STEREO)
370 con = 0x00000000;
371 if (t->audmode & V4L2_TUNER_MODE_MONO)
372 con = 0x00060000;
373 if (con != 0xffffff) {
374 gpio_bits(0x1e0000,con);
375 if (bttv_gpio)
376 bttv_gpio_tracking(btv, "adtvk503");
377 }
378 } else {
379 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
380 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
381 }
382}
diff --git a/drivers/media/video/bt8xx/bttv-audio-hook.h b/drivers/media/video/bt8xx/bttv-audio-hook.h
new file mode 100644
index 00000000000..159d07adeff
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-audio-hook.h
@@ -0,0 +1,23 @@
1/*
2 * Handlers for board audio hooks, splitted from bttv-cards
3 *
4 * Copyright (c) 2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License
6 */
7
8#include "bttvp.h"
9
10void winview_volume (struct bttv *btv, __u16 volume);
11
12void lt9415_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
13void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
14void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
15void terratv_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
16void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
17void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
18void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
19void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
20void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
21void windvr_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
22void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
23
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
new file mode 100644
index 00000000000..5b15f63bf06
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -0,0 +1,4916 @@
1/*
2
3 bttv-cards.c
4
5 this file has configuration informations - card-specific stuff
6 like the big tvcards array for the most part
7
8 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
9 & Marcus Metzler (mocm@thp.uni-koeln.de)
10 (c) 1999-2001 Gerd Knorr <kraxel@goldbach.in-berlin.de>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26*/
27
28#include <linux/delay.h>
29#include <linux/module.h>
30#include <linux/kmod.h>
31#include <linux/init.h>
32#include <linux/pci.h>
33#include <linux/vmalloc.h>
34#include <linux/firmware.h>
35#include <net/checksum.h>
36
37#include <asm/unaligned.h>
38#include <asm/io.h>
39
40#include "bttvp.h"
41#include <media/v4l2-common.h>
42#include <media/tvaudio.h>
43#include "bttv-audio-hook.h"
44
45/* fwd decl */
46static void boot_msp34xx(struct bttv *btv, int pin);
47static void hauppauge_eeprom(struct bttv *btv);
48static void avermedia_eeprom(struct bttv *btv);
49static void osprey_eeprom(struct bttv *btv, const u8 ee[256]);
50static void modtec_eeprom(struct bttv *btv);
51static void init_PXC200(struct bttv *btv);
52static void init_RTV24(struct bttv *btv);
53
54static void rv605_muxsel(struct bttv *btv, unsigned int input);
55static void eagle_muxsel(struct bttv *btv, unsigned int input);
56static void xguard_muxsel(struct bttv *btv, unsigned int input);
57static void ivc120_muxsel(struct bttv *btv, unsigned int input);
58static void gvc1100_muxsel(struct bttv *btv, unsigned int input);
59
60static void PXC200_muxsel(struct bttv *btv, unsigned int input);
61
62static void picolo_tetra_muxsel(struct bttv *btv, unsigned int input);
63static void picolo_tetra_init(struct bttv *btv);
64
65static void tibetCS16_muxsel(struct bttv *btv, unsigned int input);
66static void tibetCS16_init(struct bttv *btv);
67
68static void kodicom4400r_muxsel(struct bttv *btv, unsigned int input);
69static void kodicom4400r_init(struct bttv *btv);
70
71static void sigmaSLC_muxsel(struct bttv *btv, unsigned int input);
72static void sigmaSQ_muxsel(struct bttv *btv, unsigned int input);
73
74static void geovision_muxsel(struct bttv *btv, unsigned int input);
75
76static void phytec_muxsel(struct bttv *btv, unsigned int input);
77
78static void gv800s_muxsel(struct bttv *btv, unsigned int input);
79static void gv800s_init(struct bttv *btv);
80
81static int terratec_active_radio_upgrade(struct bttv *btv);
82static int tea5757_read(struct bttv *btv);
83static int tea5757_write(struct bttv *btv, int value);
84static void identify_by_eeprom(struct bttv *btv,
85 unsigned char eeprom_data[256]);
86static int __devinit pvr_boot(struct bttv *btv);
87
88/* config variables */
89static unsigned int triton1;
90static unsigned int vsfx;
91static unsigned int latency = UNSET;
92int no_overlay=-1;
93
94static unsigned int card[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
95static unsigned int pll[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
96static unsigned int tuner[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
97static unsigned int svhs[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
98static unsigned int remote[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
99static unsigned int audiodev[BTTV_MAX];
100static unsigned int saa6588[BTTV_MAX];
101static struct bttv *master[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = NULL };
102static unsigned int autoload = UNSET;
103static unsigned int gpiomask = UNSET;
104static unsigned int audioall = UNSET;
105static unsigned int audiomux[5] = { [ 0 ... 4 ] = UNSET };
106
107/* insmod options */
108module_param(triton1, int, 0444);
109module_param(vsfx, int, 0444);
110module_param(no_overlay, int, 0444);
111module_param(latency, int, 0444);
112module_param(gpiomask, int, 0444);
113module_param(audioall, int, 0444);
114module_param(autoload, int, 0444);
115
116module_param_array(card, int, NULL, 0444);
117module_param_array(pll, int, NULL, 0444);
118module_param_array(tuner, int, NULL, 0444);
119module_param_array(svhs, int, NULL, 0444);
120module_param_array(remote, int, NULL, 0444);
121module_param_array(audiodev, int, NULL, 0444);
122module_param_array(audiomux, int, NULL, 0444);
123
124MODULE_PARM_DESC(triton1,"set ETBF pci config bit "
125 "[enable bug compatibility for triton1 + others]");
126MODULE_PARM_DESC(vsfx,"set VSFX pci config bit "
127 "[yet another chipset flaw workaround]");
128MODULE_PARM_DESC(latency,"pci latency timer");
129MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a list");
130MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)");
131MODULE_PARM_DESC(tuner,"specify installed tuner type");
132MODULE_PARM_DESC(autoload, "obsolete option, please do not use anymore");
133MODULE_PARM_DESC(audiodev, "specify audio device:\n"
134 "\t\t-1 = no audio\n"
135 "\t\t 0 = autodetect (default)\n"
136 "\t\t 1 = msp3400\n"
137 "\t\t 2 = tda7432\n"
138 "\t\t 3 = tvaudio");
139MODULE_PARM_DESC(saa6588, "if 1, then load the saa6588 RDS module, default (0) is to use the card definition.");
140MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)"
141 " [some VIA/SIS chipsets are known to have problem with overlay]");
142
143/* ----------------------------------------------------------------------- */
144/* list of card IDs for bt878+ cards */
145
146static struct CARD {
147 unsigned id;
148 int cardnr;
149 char *name;
150} cards[] __devinitdata = {
151 { 0x13eb0070, BTTV_BOARD_HAUPPAUGE878, "Hauppauge WinTV" },
152 { 0x39000070, BTTV_BOARD_HAUPPAUGE878, "Hauppauge WinTV-D" },
153 { 0x45000070, BTTV_BOARD_HAUPPAUGEPVR, "Hauppauge WinTV/PVR" },
154 { 0xff000070, BTTV_BOARD_OSPREY1x0, "Osprey-100" },
155 { 0xff010070, BTTV_BOARD_OSPREY2x0_SVID,"Osprey-200" },
156 { 0xff020070, BTTV_BOARD_OSPREY500, "Osprey-500" },
157 { 0xff030070, BTTV_BOARD_OSPREY2000, "Osprey-2000" },
158 { 0xff040070, BTTV_BOARD_OSPREY540, "Osprey-540" },
159 { 0xff070070, BTTV_BOARD_OSPREY440, "Osprey-440" },
160
161 { 0x00011002, BTTV_BOARD_ATI_TVWONDER, "ATI TV Wonder" },
162 { 0x00031002, BTTV_BOARD_ATI_TVWONDERVE,"ATI TV Wonder/VE" },
163
164 { 0x6606107d, BTTV_BOARD_WINFAST2000, "Leadtek WinFast TV 2000" },
165 { 0x6607107d, BTTV_BOARD_WINFASTVC100, "Leadtek WinFast VC 100" },
166 { 0x6609107d, BTTV_BOARD_WINFAST2000, "Leadtek TV 2000 XP" },
167 { 0x263610b4, BTTV_BOARD_STB2, "STB TV PCI FM, Gateway P/N 6000704" },
168 { 0x264510b4, BTTV_BOARD_STB2, "STB TV PCI FM, Gateway P/N 6000704" },
169 { 0x402010fc, BTTV_BOARD_GVBCTV3PCI, "I-O Data Co. GV-BCTV3/PCI" },
170 { 0x405010fc, BTTV_BOARD_GVBCTV4PCI, "I-O Data Co. GV-BCTV4/PCI" },
171 { 0x407010fc, BTTV_BOARD_GVBCTV5PCI, "I-O Data Co. GV-BCTV5/PCI" },
172 { 0xd01810fc, BTTV_BOARD_GVBCTV5PCI, "I-O Data Co. GV-BCTV5/PCI" },
173
174 { 0x001211bd, BTTV_BOARD_PINNACLE, "Pinnacle PCTV" },
175 /* some cards ship with byteswapped IDs ... */
176 { 0x1200bd11, BTTV_BOARD_PINNACLE, "Pinnacle PCTV [bswap]" },
177 { 0xff00bd11, BTTV_BOARD_PINNACLE, "Pinnacle PCTV [bswap]" },
178 /* this seems to happen as well ... */
179 { 0xff1211bd, BTTV_BOARD_PINNACLE, "Pinnacle PCTV" },
180
181 { 0x3000121a, BTTV_BOARD_VOODOOTV_200, "3Dfx VoodooTV 200" },
182 { 0x263710b4, BTTV_BOARD_VOODOOTV_FM, "3Dfx VoodooTV FM" },
183 { 0x3060121a, BTTV_BOARD_STB2, "3Dfx VoodooTV 100/ STB OEM" },
184
185 { 0x3000144f, BTTV_BOARD_MAGICTVIEW063, "(Askey Magic/others) TView99 CPH06x" },
186 { 0xa005144f, BTTV_BOARD_MAGICTVIEW063, "CPH06X TView99-Card" },
187 { 0x3002144f, BTTV_BOARD_MAGICTVIEW061, "(Askey Magic/others) TView99 CPH05x" },
188 { 0x3005144f, BTTV_BOARD_MAGICTVIEW061, "(Askey Magic/others) TView99 CPH061/06L (T1/LC)" },
189 { 0x5000144f, BTTV_BOARD_MAGICTVIEW061, "Askey CPH050" },
190 { 0x300014ff, BTTV_BOARD_MAGICTVIEW061, "TView 99 (CPH061)" },
191 { 0x300214ff, BTTV_BOARD_PHOEBE_TVMAS, "Phoebe TV Master (CPH060)" },
192
193 { 0x00011461, BTTV_BOARD_AVPHONE98, "AVerMedia TVPhone98" },
194 { 0x00021461, BTTV_BOARD_AVERMEDIA98, "AVermedia TVCapture 98" },
195 { 0x00031461, BTTV_BOARD_AVPHONE98, "AVerMedia TVPhone98" },
196 { 0x00041461, BTTV_BOARD_AVERMEDIA98, "AVerMedia TVCapture 98" },
197 { 0x03001461, BTTV_BOARD_AVERMEDIA98, "VDOMATE TV TUNER CARD" },
198
199 { 0x1117153b, BTTV_BOARD_TERRATVALUE, "Terratec TValue (Philips PAL B/G)" },
200 { 0x1118153b, BTTV_BOARD_TERRATVALUE, "Terratec TValue (Temic PAL B/G)" },
201 { 0x1119153b, BTTV_BOARD_TERRATVALUE, "Terratec TValue (Philips PAL I)" },
202 { 0x111a153b, BTTV_BOARD_TERRATVALUE, "Terratec TValue (Temic PAL I)" },
203
204 { 0x1123153b, BTTV_BOARD_TERRATVRADIO, "Terratec TV Radio+" },
205 { 0x1127153b, BTTV_BOARD_TERRATV, "Terratec TV+ (V1.05)" },
206 /* clashes with FlyVideo
207 *{ 0x18521852, BTTV_BOARD_TERRATV, "Terratec TV+ (V1.10)" }, */
208 { 0x1134153b, BTTV_BOARD_TERRATVALUE, "Terratec TValue (LR102)" },
209 { 0x1135153b, BTTV_BOARD_TERRATVALUER, "Terratec TValue Radio" }, /* LR102 */
210 { 0x5018153b, BTTV_BOARD_TERRATVALUE, "Terratec TValue" }, /* ?? */
211 { 0xff3b153b, BTTV_BOARD_TERRATVALUER, "Terratec TValue Radio" }, /* ?? */
212
213 { 0x400015b0, BTTV_BOARD_ZOLTRIX_GENIE, "Zoltrix Genie TV" },
214 { 0x400a15b0, BTTV_BOARD_ZOLTRIX_GENIE, "Zoltrix Genie TV" },
215 { 0x400d15b0, BTTV_BOARD_ZOLTRIX_GENIE, "Zoltrix Genie TV / Radio" },
216 { 0x401015b0, BTTV_BOARD_ZOLTRIX_GENIE, "Zoltrix Genie TV / Radio" },
217 { 0x401615b0, BTTV_BOARD_ZOLTRIX_GENIE, "Zoltrix Genie TV / Radio" },
218
219 { 0x1430aa00, BTTV_BOARD_PV143, "Provideo PV143A" },
220 { 0x1431aa00, BTTV_BOARD_PV143, "Provideo PV143B" },
221 { 0x1432aa00, BTTV_BOARD_PV143, "Provideo PV143C" },
222 { 0x1433aa00, BTTV_BOARD_PV143, "Provideo PV143D" },
223 { 0x1433aa03, BTTV_BOARD_PV143, "Security Eyes" },
224
225 { 0x1460aa00, BTTV_BOARD_PV150, "Provideo PV150A-1" },
226 { 0x1461aa01, BTTV_BOARD_PV150, "Provideo PV150A-2" },
227 { 0x1462aa02, BTTV_BOARD_PV150, "Provideo PV150A-3" },
228 { 0x1463aa03, BTTV_BOARD_PV150, "Provideo PV150A-4" },
229
230 { 0x1464aa04, BTTV_BOARD_PV150, "Provideo PV150B-1" },
231 { 0x1465aa05, BTTV_BOARD_PV150, "Provideo PV150B-2" },
232 { 0x1466aa06, BTTV_BOARD_PV150, "Provideo PV150B-3" },
233 { 0x1467aa07, BTTV_BOARD_PV150, "Provideo PV150B-4" },
234
235 { 0xa132ff00, BTTV_BOARD_IVC100, "IVC-100" },
236 { 0xa1550000, BTTV_BOARD_IVC200, "IVC-200" },
237 { 0xa1550001, BTTV_BOARD_IVC200, "IVC-200" },
238 { 0xa1550002, BTTV_BOARD_IVC200, "IVC-200" },
239 { 0xa1550003, BTTV_BOARD_IVC200, "IVC-200" },
240 { 0xa1550100, BTTV_BOARD_IVC200, "IVC-200G" },
241 { 0xa1550101, BTTV_BOARD_IVC200, "IVC-200G" },
242 { 0xa1550102, BTTV_BOARD_IVC200, "IVC-200G" },
243 { 0xa1550103, BTTV_BOARD_IVC200, "IVC-200G" },
244 { 0xa1550800, BTTV_BOARD_IVC200, "IVC-200" },
245 { 0xa1550801, BTTV_BOARD_IVC200, "IVC-200" },
246 { 0xa1550802, BTTV_BOARD_IVC200, "IVC-200" },
247 { 0xa1550803, BTTV_BOARD_IVC200, "IVC-200" },
248 { 0xa182ff00, BTTV_BOARD_IVC120, "IVC-120G" },
249 { 0xa182ff01, BTTV_BOARD_IVC120, "IVC-120G" },
250 { 0xa182ff02, BTTV_BOARD_IVC120, "IVC-120G" },
251 { 0xa182ff03, BTTV_BOARD_IVC120, "IVC-120G" },
252 { 0xa182ff04, BTTV_BOARD_IVC120, "IVC-120G" },
253 { 0xa182ff05, BTTV_BOARD_IVC120, "IVC-120G" },
254 { 0xa182ff06, BTTV_BOARD_IVC120, "IVC-120G" },
255 { 0xa182ff07, BTTV_BOARD_IVC120, "IVC-120G" },
256 { 0xa182ff08, BTTV_BOARD_IVC120, "IVC-120G" },
257 { 0xa182ff09, BTTV_BOARD_IVC120, "IVC-120G" },
258 { 0xa182ff0a, BTTV_BOARD_IVC120, "IVC-120G" },
259 { 0xa182ff0b, BTTV_BOARD_IVC120, "IVC-120G" },
260 { 0xa182ff0c, BTTV_BOARD_IVC120, "IVC-120G" },
261 { 0xa182ff0d, BTTV_BOARD_IVC120, "IVC-120G" },
262 { 0xa182ff0e, BTTV_BOARD_IVC120, "IVC-120G" },
263 { 0xa182ff0f, BTTV_BOARD_IVC120, "IVC-120G" },
264 { 0xf0500000, BTTV_BOARD_IVCE8784, "IVCE-8784" },
265 { 0xf0500001, BTTV_BOARD_IVCE8784, "IVCE-8784" },
266 { 0xf0500002, BTTV_BOARD_IVCE8784, "IVCE-8784" },
267 { 0xf0500003, BTTV_BOARD_IVCE8784, "IVCE-8784" },
268
269 { 0x41424344, BTTV_BOARD_GRANDTEC, "GrandTec Multi Capture" },
270 { 0x01020304, BTTV_BOARD_XGUARD, "Grandtec Grand X-Guard" },
271
272 { 0x18501851, BTTV_BOARD_CHRONOS_VS2, "FlyVideo 98 (LR50)/ Chronos Video Shuttle II" },
273 { 0xa0501851, BTTV_BOARD_CHRONOS_VS2, "FlyVideo 98 (LR50)/ Chronos Video Shuttle II" },
274 { 0x18511851, BTTV_BOARD_FLYVIDEO98EZ, "FlyVideo 98EZ (LR51)/ CyberMail AV" },
275 { 0x18521852, BTTV_BOARD_TYPHOON_TVIEW, "FlyVideo 98FM (LR50)/ Typhoon TView TV/FM Tuner" },
276 { 0x41a0a051, BTTV_BOARD_FLYVIDEO_98FM, "Lifeview FlyVideo 98 LR50 Rev Q" },
277 { 0x18501f7f, BTTV_BOARD_FLYVIDEO_98, "Lifeview Flyvideo 98" },
278
279 { 0x010115cb, BTTV_BOARD_GMV1, "AG GMV1" },
280 { 0x010114c7, BTTV_BOARD_MODTEC_205, "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV" },
281
282 { 0x10b42636, BTTV_BOARD_HAUPPAUGE878, "STB ???" },
283 { 0x217d6606, BTTV_BOARD_WINFAST2000, "Leadtek WinFast TV 2000" },
284 { 0xfff6f6ff, BTTV_BOARD_WINFAST2000, "Leadtek WinFast TV 2000" },
285 { 0x03116000, BTTV_BOARD_SENSORAY311, "Sensoray 311" },
286 { 0x00790e11, BTTV_BOARD_WINDVR, "Canopus WinDVR PCI" },
287 { 0xa0fca1a0, BTTV_BOARD_ZOLTRIX, "Face to Face Tvmax" },
288 { 0x82b2aa6a, BTTV_BOARD_SIMUS_GVC1100, "SIMUS GVC1100" },
289 { 0x146caa0c, BTTV_BOARD_PV951, "ituner spectra8" },
290 { 0x200a1295, BTTV_BOARD_PXC200, "ImageNation PXC200A" },
291
292 { 0x40111554, BTTV_BOARD_PV_BT878P_9B, "Prolink Pixelview PV-BT" },
293 { 0x17de0a01, BTTV_BOARD_KWORLD, "Mecer TV/FM/Video Tuner" },
294
295 { 0x01051805, BTTV_BOARD_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #1" },
296 { 0x01061805, BTTV_BOARD_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #2" },
297 { 0x01071805, BTTV_BOARD_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #3" },
298 { 0x01081805, BTTV_BOARD_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #4" },
299
300 { 0x15409511, BTTV_BOARD_ACORP_Y878F, "Acorp Y878F" },
301
302 { 0x53534149, BTTV_BOARD_SSAI_SECURITY, "SSAI Security Video Interface" },
303 { 0x5353414a, BTTV_BOARD_SSAI_ULTRASOUND, "SSAI Ultrasound Video Interface" },
304
305 /* likely broken, vendor id doesn't match the other magic views ...
306 * { 0xa0fca04f, BTTV_BOARD_MAGICTVIEW063, "Guillemot Maxi TV Video 3" }, */
307
308 /* Duplicate PCI ID, reconfigure for this board during the eeprom read.
309 * { 0x13eb0070, BTTV_BOARD_HAUPPAUGE_IMPACTVCB, "Hauppauge ImpactVCB" }, */
310
311 { 0x109e036e, BTTV_BOARD_CONCEPTRONIC_CTVFMI2, "Conceptronic CTVFMi v2"},
312
313 /* DVB cards (using pci function .1 for mpeg data xfer) */
314 { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" },
315 { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" },
316 { 0x20007063, BTTV_BOARD_PC_HDTV, "pcHDTV HD-2000 TV"},
317 { 0x002611bd, BTTV_BOARD_TWINHAN_DST, "Pinnacle PCTV SAT CI" },
318 { 0x00011822, BTTV_BOARD_TWINHAN_DST, "Twinhan VisionPlus DVB" },
319 { 0xfc00270f, BTTV_BOARD_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" },
320 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" },
321 { 0x07611461, BTTV_BOARD_AVDVBT_761, "AverMedia AverTV DVB-T 761" },
322 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" },
323 { 0xdb1118ac, BTTV_BOARD_DVICO_DVBT_LITE, "Ultraview DVB-T Lite" },
324 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" },
325 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "},
326 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" },
327 { 0x763c008a, BTTV_BOARD_GEOVISION_GV600, "GeoVision GV-600" },
328 { 0x18011000, BTTV_BOARD_ENLTV_FM_2, "Encore ENL TV-FM-2" },
329 { 0x763d800a, BTTV_BOARD_GEOVISION_GV800S, "GeoVision GV-800(S) (master)" },
330 { 0x763d800b, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" },
331 { 0x763d800c, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" },
332 { 0x763d800d, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" },
333
334 { 0x15401830, BTTV_BOARD_PV183, "Provideo PV183-1" },
335 { 0x15401831, BTTV_BOARD_PV183, "Provideo PV183-2" },
336 { 0x15401832, BTTV_BOARD_PV183, "Provideo PV183-3" },
337 { 0x15401833, BTTV_BOARD_PV183, "Provideo PV183-4" },
338 { 0x15401834, BTTV_BOARD_PV183, "Provideo PV183-5" },
339 { 0x15401835, BTTV_BOARD_PV183, "Provideo PV183-6" },
340 { 0x15401836, BTTV_BOARD_PV183, "Provideo PV183-7" },
341 { 0x15401837, BTTV_BOARD_PV183, "Provideo PV183-8" },
342
343 { 0, -1, NULL }
344};
345
346/* ----------------------------------------------------------------------- */
347/* array with description for bt848 / bt878 tv/grabber cards */
348
349struct tvcard bttv_tvcards[] = {
350 /* ---- card 0x00 ---------------------------------- */
351 [BTTV_BOARD_UNKNOWN] = {
352 .name = " *** UNKNOWN/GENERIC *** ",
353 .video_inputs = 4,
354 .svhs = 2,
355 .muxsel = MUXSEL(2, 3, 1, 0),
356 .tuner_type = UNSET,
357 .tuner_addr = ADDR_UNSET,
358 },
359 [BTTV_BOARD_MIRO] = {
360 .name = "MIRO PCTV",
361 .video_inputs = 4,
362 /* .audio_inputs= 1, */
363 .svhs = 2,
364 .gpiomask = 15,
365 .muxsel = MUXSEL(2, 3, 1, 1),
366 .gpiomux = { 2, 0, 0, 0 },
367 .gpiomute = 10,
368 .needs_tvaudio = 1,
369 .tuner_type = UNSET,
370 .tuner_addr = ADDR_UNSET,
371 },
372 [BTTV_BOARD_HAUPPAUGE] = {
373 .name = "Hauppauge (bt848)",
374 .video_inputs = 4,
375 /* .audio_inputs= 1, */
376 .svhs = 2,
377 .gpiomask = 7,
378 .muxsel = MUXSEL(2, 3, 1, 1),
379 .gpiomux = { 0, 1, 2, 3 },
380 .gpiomute = 4,
381 .needs_tvaudio = 1,
382 .tuner_type = UNSET,
383 .tuner_addr = ADDR_UNSET,
384 },
385 [BTTV_BOARD_STB] = {
386 .name = "STB, Gateway P/N 6000699 (bt848)",
387 .video_inputs = 3,
388 /* .audio_inputs= 1, */
389 .svhs = 2,
390 .gpiomask = 7,
391 .muxsel = MUXSEL(2, 3, 1, 1),
392 .gpiomux = { 4, 0, 2, 3 },
393 .gpiomute = 1,
394 .no_msp34xx = 1,
395 .needs_tvaudio = 1,
396 .tuner_type = TUNER_PHILIPS_NTSC,
397 .tuner_addr = ADDR_UNSET,
398 .pll = PLL_28,
399 .has_radio = 1,
400 },
401
402 /* ---- card 0x04 ---------------------------------- */
403 [BTTV_BOARD_INTEL] = {
404 .name = "Intel Create and Share PCI/ Smart Video Recorder III",
405 .video_inputs = 4,
406 /* .audio_inputs= 0, */
407 .svhs = 2,
408 .gpiomask = 0,
409 .muxsel = MUXSEL(2, 3, 1, 1),
410 .gpiomux = { 0 },
411 .needs_tvaudio = 0,
412 .tuner_type = TUNER_ABSENT,
413 .tuner_addr = ADDR_UNSET,
414 },
415 [BTTV_BOARD_DIAMOND] = {
416 .name = "Diamond DTV2000",
417 .video_inputs = 4,
418 /* .audio_inputs= 1, */
419 .svhs = 2,
420 .gpiomask = 3,
421 .muxsel = MUXSEL(2, 3, 1, 0),
422 .gpiomux = { 0, 1, 0, 1 },
423 .gpiomute = 3,
424 .needs_tvaudio = 1,
425 .tuner_type = UNSET,
426 .tuner_addr = ADDR_UNSET,
427 },
428 [BTTV_BOARD_AVERMEDIA] = {
429 .name = "AVerMedia TVPhone",
430 .video_inputs = 3,
431 /* .audio_inputs= 1, */
432 .svhs = 3,
433 .muxsel = MUXSEL(2, 3, 1, 1),
434 .gpiomask = 0x0f,
435 .gpiomux = { 0x0c, 0x04, 0x08, 0x04 },
436 /* 0x04 for some cards ?? */
437 .needs_tvaudio = 1,
438 .tuner_type = UNSET,
439 .tuner_addr = ADDR_UNSET,
440 .audio_mode_gpio= avermedia_tvphone_audio,
441 .has_remote = 1,
442 },
443 [BTTV_BOARD_MATRIX_VISION] = {
444 .name = "MATRIX-Vision MV-Delta",
445 .video_inputs = 5,
446 /* .audio_inputs= 1, */
447 .svhs = 3,
448 .gpiomask = 0,
449 .muxsel = MUXSEL(2, 3, 1, 0, 0),
450 .gpiomux = { 0 },
451 .needs_tvaudio = 1,
452 .tuner_type = TUNER_ABSENT,
453 .tuner_addr = ADDR_UNSET,
454 },
455
456 /* ---- card 0x08 ---------------------------------- */
457 [BTTV_BOARD_FLYVIDEO] = {
458 .name = "Lifeview FlyVideo II (Bt848) LR26 / MAXI TV Video PCI2 LR26",
459 .video_inputs = 4,
460 /* .audio_inputs= 1, */
461 .svhs = 2,
462 .gpiomask = 0xc00,
463 .muxsel = MUXSEL(2, 3, 1, 1),
464 .gpiomux = { 0, 0xc00, 0x800, 0x400 },
465 .gpiomute = 0xc00,
466 .needs_tvaudio = 1,
467 .pll = PLL_28,
468 .tuner_type = UNSET,
469 .tuner_addr = ADDR_UNSET,
470 },
471 [BTTV_BOARD_TURBOTV] = {
472 .name = "IMS/IXmicro TurboTV",
473 .video_inputs = 3,
474 /* .audio_inputs= 1, */
475 .svhs = 2,
476 .gpiomask = 3,
477 .muxsel = MUXSEL(2, 3, 1, 1),
478 .gpiomux = { 1, 1, 2, 3 },
479 .needs_tvaudio = 0,
480 .pll = PLL_28,
481 .tuner_type = TUNER_TEMIC_PAL,
482 .tuner_addr = ADDR_UNSET,
483 },
484 [BTTV_BOARD_HAUPPAUGE878] = {
485 .name = "Hauppauge (bt878)",
486 .video_inputs = 4,
487 /* .audio_inputs= 1, */
488 .svhs = 2,
489 .gpiomask = 0x0f, /* old: 7 */
490 .muxsel = MUXSEL(2, 0, 1, 1),
491 .gpiomux = { 0, 1, 2, 3 },
492 .gpiomute = 4,
493 .needs_tvaudio = 1,
494 .pll = PLL_28,
495 .tuner_type = UNSET,
496 .tuner_addr = ADDR_UNSET,
497 },
498 [BTTV_BOARD_MIROPRO] = {
499 .name = "MIRO PCTV pro",
500 .video_inputs = 3,
501 /* .audio_inputs= 1, */
502 .svhs = 2,
503 .gpiomask = 0x3014f,
504 .muxsel = MUXSEL(2, 3, 1, 1),
505 .gpiomux = { 0x20001,0x10001, 0, 0 },
506 .gpiomute = 10,
507 .needs_tvaudio = 1,
508 .tuner_type = UNSET,
509 .tuner_addr = ADDR_UNSET,
510 },
511
512 /* ---- card 0x0c ---------------------------------- */
513 [BTTV_BOARD_ADSTECH_TV] = {
514 .name = "ADS Technologies Channel Surfer TV (bt848)",
515 .video_inputs = 3,
516 /* .audio_inputs= 1, */
517 .svhs = 2,
518 .gpiomask = 15,
519 .muxsel = MUXSEL(2, 3, 1, 1),
520 .gpiomux = { 13, 14, 11, 7 },
521 .needs_tvaudio = 1,
522 .tuner_type = UNSET,
523 .tuner_addr = ADDR_UNSET,
524 },
525 [BTTV_BOARD_AVERMEDIA98] = {
526 .name = "AVerMedia TVCapture 98",
527 .video_inputs = 3,
528 /* .audio_inputs= 4, */
529 .svhs = 2,
530 .gpiomask = 15,
531 .muxsel = MUXSEL(2, 3, 1, 1),
532 .gpiomux = { 13, 14, 11, 7 },
533 .needs_tvaudio = 1,
534 .msp34xx_alt = 1,
535 .pll = PLL_28,
536 .tuner_type = TUNER_PHILIPS_PAL,
537 .tuner_addr = ADDR_UNSET,
538 .audio_mode_gpio= avermedia_tv_stereo_audio,
539 .no_gpioirq = 1,
540 },
541 [BTTV_BOARD_VHX] = {
542 .name = "Aimslab Video Highway Xtreme (VHX)",
543 .video_inputs = 3,
544 /* .audio_inputs= 1, */
545 .svhs = 2,
546 .gpiomask = 7,
547 .muxsel = MUXSEL(2, 3, 1, 1),
548 .gpiomux = { 0, 2, 1, 3 }, /* old: {0, 1, 2, 3, 4} */
549 .gpiomute = 4,
550 .needs_tvaudio = 1,
551 .pll = PLL_28,
552 .tuner_type = UNSET,
553 .tuner_addr = ADDR_UNSET,
554 },
555 [BTTV_BOARD_ZOLTRIX] = {
556 .name = "Zoltrix TV-Max",
557 .video_inputs = 3,
558 /* .audio_inputs= 1, */
559 .svhs = 2,
560 .gpiomask = 15,
561 .muxsel = MUXSEL(2, 3, 1, 1),
562 .gpiomux = { 0, 0, 1, 0 },
563 .gpiomute = 10,
564 .needs_tvaudio = 1,
565 .tuner_type = UNSET,
566 .tuner_addr = ADDR_UNSET,
567 },
568
569 /* ---- card 0x10 ---------------------------------- */
570 [BTTV_BOARD_PIXVIEWPLAYTV] = {
571 .name = "Prolink Pixelview PlayTV (bt878)",
572 .video_inputs = 3,
573 /* .audio_inputs= 1, */
574 .svhs = 2,
575 .gpiomask = 0x01fe00,
576 .muxsel = MUXSEL(2, 3, 1, 1),
577 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */
578 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
579 .gpiomute = 0x002000,
580 .needs_tvaudio = 1,
581 .pll = PLL_28,
582 .tuner_type = UNSET,
583 .tuner_addr = ADDR_UNSET,
584 },
585 [BTTV_BOARD_WINVIEW_601] = {
586 .name = "Leadtek WinView 601",
587 .video_inputs = 3,
588 /* .audio_inputs= 1, */
589 .svhs = 2,
590 .gpiomask = 0x8300f8,
591 .muxsel = MUXSEL(2, 3, 1, 1, 0),
592 .gpiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007 },
593 .gpiomute = 0xcfa007,
594 .needs_tvaudio = 1,
595 .tuner_type = UNSET,
596 .tuner_addr = ADDR_UNSET,
597 .volume_gpio = winview_volume,
598 .has_radio = 1,
599 },
600 [BTTV_BOARD_AVEC_INTERCAP] = {
601 .name = "AVEC Intercapture",
602 .video_inputs = 3,
603 /* .audio_inputs= 2, */
604 .svhs = 2,
605 .gpiomask = 0,
606 .muxsel = MUXSEL(2, 3, 1, 1),
607 .gpiomux = { 1, 0, 0, 0 },
608 .needs_tvaudio = 1,
609 .tuner_type = UNSET,
610 .tuner_addr = ADDR_UNSET,
611 },
612 [BTTV_BOARD_LIFE_FLYKIT] = {
613 .name = "Lifeview FlyVideo II EZ /FlyKit LR38 Bt848 (capture only)",
614 .video_inputs = 4,
615 /* .audio_inputs= 1, */
616 .svhs = NO_SVHS,
617 .gpiomask = 0x8dff00,
618 .muxsel = MUXSEL(2, 3, 1, 1),
619 .gpiomux = { 0 },
620 .no_msp34xx = 1,
621 .tuner_type = TUNER_ABSENT,
622 .tuner_addr = ADDR_UNSET,
623 },
624
625 /* ---- card 0x14 ---------------------------------- */
626 [BTTV_BOARD_CEI_RAFFLES] = {
627 .name = "CEI Raffles Card",
628 .video_inputs = 3,
629 /* .audio_inputs= 3, */
630 .svhs = 2,
631 .muxsel = MUXSEL(2, 3, 1, 1),
632 .tuner_type = UNSET,
633 .tuner_addr = ADDR_UNSET,
634 },
635 [BTTV_BOARD_CONFERENCETV] = {
636 .name = "Lifeview FlyVideo 98/ Lucky Star Image World ConferenceTV LR50",
637 .video_inputs = 4,
638 /* .audio_inputs= 2, tuner, line in */
639 .svhs = 2,
640 .gpiomask = 0x1800,
641 .muxsel = MUXSEL(2, 3, 1, 1),
642 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
643 .gpiomute = 0x1800,
644 .pll = PLL_28,
645 .tuner_type = TUNER_PHILIPS_PAL_I,
646 .tuner_addr = ADDR_UNSET,
647 },
648 [BTTV_BOARD_PHOEBE_TVMAS] = {
649 .name = "Askey CPH050/ Phoebe Tv Master + FM",
650 .video_inputs = 3,
651 /* .audio_inputs= 1, */
652 .svhs = 2,
653 .gpiomask = 0xc00,
654 .muxsel = MUXSEL(2, 3, 1, 1),
655 .gpiomux = { 0, 1, 0x800, 0x400 },
656 .gpiomute = 0xc00,
657 .needs_tvaudio = 1,
658 .pll = PLL_28,
659 .tuner_type = UNSET,
660 .tuner_addr = ADDR_UNSET,
661 },
662 [BTTV_BOARD_MODTEC_205] = {
663 .name = "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV, bt878",
664 .video_inputs = 3,
665 /* .audio_inputs= 1, */
666 .svhs = NO_SVHS,
667 .has_dig_in = 1,
668 .gpiomask = 7,
669 .muxsel = MUXSEL(2, 3, 0), /* input 2 is digital */
670 /* .digital_mode= DIGITAL_MODE_CAMERA, */
671 .gpiomux = { 0, 0, 0, 0 },
672 .no_msp34xx = 1,
673 .pll = PLL_28,
674 .tuner_type = TUNER_ALPS_TSBB5_PAL_I,
675 .tuner_addr = ADDR_UNSET,
676 },
677
678 /* ---- card 0x18 ---------------------------------- */
679 [BTTV_BOARD_MAGICTVIEW061] = {
680 .name = "Askey CPH05X/06X (bt878) [many vendors]",
681 .video_inputs = 3,
682 /* .audio_inputs= 1, */
683 .svhs = 2,
684 .gpiomask = 0xe00,
685 .muxsel = MUXSEL(2, 3, 1, 1),
686 .gpiomux = {0x400, 0x400, 0x400, 0x400 },
687 .gpiomute = 0xc00,
688 .needs_tvaudio = 1,
689 .pll = PLL_28,
690 .tuner_type = UNSET,
691 .tuner_addr = ADDR_UNSET,
692 .has_remote = 1,
693 },
694 [BTTV_BOARD_VOBIS_BOOSTAR] = {
695 .name = "Terratec TerraTV+ Version 1.0 (Bt848)/ Terra TValue Version 1.0/ Vobis TV-Boostar",
696 .video_inputs = 3,
697 /* .audio_inputs= 1, */
698 .svhs = 2,
699 .gpiomask = 0x1f0fff,
700 .muxsel = MUXSEL(2, 3, 1, 1),
701 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 },
702 .gpiomute = 0x40000,
703 .needs_tvaudio = 0,
704 .tuner_type = TUNER_PHILIPS_PAL,
705 .tuner_addr = ADDR_UNSET,
706 .audio_mode_gpio= terratv_audio,
707 },
708 [BTTV_BOARD_HAUPPAUG_WCAM] = {
709 .name = "Hauppauge WinCam newer (bt878)",
710 .video_inputs = 4,
711 /* .audio_inputs= 1, */
712 .svhs = 3,
713 .gpiomask = 7,
714 .muxsel = MUXSEL(2, 0, 1, 1),
715 .gpiomux = { 0, 1, 2, 3 },
716 .gpiomute = 4,
717 .needs_tvaudio = 1,
718 .tuner_type = UNSET,
719 .tuner_addr = ADDR_UNSET,
720 },
721 [BTTV_BOARD_MAXI] = {
722 .name = "Lifeview FlyVideo 98/ MAXI TV Video PCI2 LR50",
723 .video_inputs = 4,
724 /* .audio_inputs= 2, */
725 .svhs = 2,
726 .gpiomask = 0x1800,
727 .muxsel = MUXSEL(2, 3, 1, 1),
728 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
729 .gpiomute = 0x1800,
730 .pll = PLL_28,
731 .tuner_type = TUNER_PHILIPS_SECAM,
732 .tuner_addr = ADDR_UNSET,
733 },
734
735 /* ---- card 0x1c ---------------------------------- */
736 [BTTV_BOARD_TERRATV] = {
737 .name = "Terratec TerraTV+ Version 1.1 (bt878)",
738 .video_inputs = 3,
739 /* .audio_inputs= 1, */
740 .svhs = 2,
741 .gpiomask = 0x1f0fff,
742 .muxsel = MUXSEL(2, 3, 1, 1),
743 .gpiomux = { 0x20000, 0x30000, 0x10000, 0x00000 },
744 .gpiomute = 0x40000,
745 .needs_tvaudio = 0,
746 .tuner_type = TUNER_PHILIPS_PAL,
747 .tuner_addr = ADDR_UNSET,
748 .audio_mode_gpio= terratv_audio,
749 /* GPIO wiring:
750 External 20 pin connector (for Active Radio Upgrade board)
751 gpio00: i2c-sda
752 gpio01: i2c-scl
753 gpio02: om5610-data
754 gpio03: om5610-clk
755 gpio04: om5610-wre
756 gpio05: om5610-stereo
757 gpio06: rds6588-davn
758 gpio07: Pin 7 n.c.
759 gpio08: nIOW
760 gpio09+10: nIOR, nSEL ?? (bt878)
761 gpio09: nIOR (bt848)
762 gpio10: nSEL (bt848)
763 Sound Routing:
764 gpio16: u2-A0 (1st 4052bt)
765 gpio17: u2-A1
766 gpio18: u2-nEN
767 gpio19: u4-A0 (2nd 4052)
768 gpio20: u4-A1
769 u4-nEN - GND
770 Btspy:
771 00000 : Cdrom (internal audio input)
772 10000 : ext. Video audio input
773 20000 : TV Mono
774 a0000 : TV Mono/2
775 1a0000 : TV Stereo
776 30000 : Radio
777 40000 : Mute
778 */
779
780 },
781 [BTTV_BOARD_PXC200] = {
782 /* Jannik Fritsch <jannik@techfak.uni-bielefeld.de> */
783 .name = "Imagenation PXC200",
784 .video_inputs = 5,
785 /* .audio_inputs= 1, */
786 .svhs = 1, /* was: 4 */
787 .gpiomask = 0,
788 .muxsel = MUXSEL(2, 3, 1, 0, 0),
789 .gpiomux = { 0 },
790 .needs_tvaudio = 1,
791 .tuner_type = TUNER_ABSENT,
792 .tuner_addr = ADDR_UNSET,
793 .muxsel_hook = PXC200_muxsel,
794
795 },
796 [BTTV_BOARD_FLYVIDEO_98] = {
797 .name = "Lifeview FlyVideo 98 LR50",
798 .video_inputs = 4,
799 /* .audio_inputs= 1, */
800 .svhs = 2,
801 .gpiomask = 0x1800, /* 0x8dfe00 */
802 .muxsel = MUXSEL(2, 3, 1, 1),
803 .gpiomux = { 0, 0x0800, 0x1000, 0x1000 },
804 .gpiomute = 0x1800,
805 .pll = PLL_28,
806 .tuner_type = UNSET,
807 .tuner_addr = ADDR_UNSET,
808 },
809 [BTTV_BOARD_IPROTV] = {
810 .name = "Formac iProTV, Formac ProTV I (bt848)",
811 .video_inputs = 4,
812 /* .audio_inputs= 1, */
813 .svhs = 3,
814 .gpiomask = 1,
815 .muxsel = MUXSEL(2, 3, 1, 1),
816 .gpiomux = { 1, 0, 0, 0 },
817 .pll = PLL_28,
818 .tuner_type = TUNER_PHILIPS_PAL,
819 .tuner_addr = ADDR_UNSET,
820 },
821
822 /* ---- card 0x20 ---------------------------------- */
823 [BTTV_BOARD_INTEL_C_S_PCI] = {
824 .name = "Intel Create and Share PCI/ Smart Video Recorder III",
825 .video_inputs = 4,
826 /* .audio_inputs= 0, */
827 .svhs = 2,
828 .gpiomask = 0,
829 .muxsel = MUXSEL(2, 3, 1, 1),
830 .gpiomux = { 0 },
831 .needs_tvaudio = 0,
832 .tuner_type = TUNER_ABSENT,
833 .tuner_addr = ADDR_UNSET,
834 },
835 [BTTV_BOARD_TERRATVALUE] = {
836 .name = "Terratec TerraTValue Version Bt878",
837 .video_inputs = 3,
838 /* .audio_inputs= 1, */
839 .svhs = 2,
840 .gpiomask = 0xffff00,
841 .muxsel = MUXSEL(2, 3, 1, 1),
842 .gpiomux = { 0x500, 0, 0x300, 0x900 },
843 .gpiomute = 0x900,
844 .needs_tvaudio = 1,
845 .pll = PLL_28,
846 .tuner_type = TUNER_PHILIPS_PAL,
847 .tuner_addr = ADDR_UNSET,
848 },
849 [BTTV_BOARD_WINFAST2000] = {
850 .name = "Leadtek WinFast 2000/ WinFast 2000 XP",
851 .video_inputs = 4,
852 /* .audio_inputs= 1, */
853 .svhs = 2,
854 /* TV, CVid, SVid, CVid over SVid connector */
855 .muxsel = MUXSEL(2, 3, 1, 1, 0),
856 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
857 .gpiomask = 0xb33000,
858 .gpiomux = { 0x122000,0x1000,0x0000,0x620000 },
859 .gpiomute = 0x800000,
860 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
861 gpio23 -- hef4052:nEnable (0x800000)
862 gpio12 -- hef4052:A1
863 gpio13 -- hef4052:A0
864 0x0000: external audio
865 0x1000: FM
866 0x2000: TV
867 0x3000: n.c.
868 Note: There exists another variant "Winfast 2000" with tv stereo !?
869 Note: eeprom only contains FF and pci subsystem id 107d:6606
870 */
871 .needs_tvaudio = 0,
872 .pll = PLL_28,
873 .has_radio = 1,
874 .tuner_type = TUNER_PHILIPS_PAL, /* default for now, gpio reads BFFF06 for Pal bg+dk */
875 .tuner_addr = ADDR_UNSET,
876 .audio_mode_gpio= winfast2000_audio,
877 .has_remote = 1,
878 },
879 [BTTV_BOARD_CHRONOS_VS2] = {
880 .name = "Lifeview FlyVideo 98 LR50 / Chronos Video Shuttle II",
881 .video_inputs = 4,
882 /* .audio_inputs= 3, */
883 .svhs = 2,
884 .gpiomask = 0x1800,
885 .muxsel = MUXSEL(2, 3, 1, 1),
886 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
887 .gpiomute = 0x1800,
888 .pll = PLL_28,
889 .tuner_type = UNSET,
890 .tuner_addr = ADDR_UNSET,
891 },
892
893 /* ---- card 0x24 ---------------------------------- */
894 [BTTV_BOARD_TYPHOON_TVIEW] = {
895 .name = "Lifeview FlyVideo 98FM LR50 / Typhoon TView TV/FM Tuner",
896 .video_inputs = 4,
897 /* .audio_inputs= 3, */
898 .svhs = 2,
899 .gpiomask = 0x1800,
900 .muxsel = MUXSEL(2, 3, 1, 1),
901 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
902 .gpiomute = 0x1800,
903 .pll = PLL_28,
904 .tuner_type = UNSET,
905 .tuner_addr = ADDR_UNSET,
906 .has_radio = 1,
907 },
908 [BTTV_BOARD_PXELVWPLTVPRO] = {
909 .name = "Prolink PixelView PlayTV pro",
910 .video_inputs = 3,
911 /* .audio_inputs= 1, */
912 .svhs = 2,
913 .gpiomask = 0xff,
914 .muxsel = MUXSEL(2, 3, 1, 1),
915 .gpiomux = { 0x21, 0x20, 0x24, 0x2c },
916 .gpiomute = 0x29,
917 .no_msp34xx = 1,
918 .pll = PLL_28,
919 .tuner_type = UNSET,
920 .tuner_addr = ADDR_UNSET,
921 },
922 [BTTV_BOARD_MAGICTVIEW063] = {
923 .name = "Askey CPH06X TView99",
924 .video_inputs = 4,
925 /* .audio_inputs= 1, */
926 .svhs = 2,
927 .gpiomask = 0x551e00,
928 .muxsel = MUXSEL(2, 3, 1, 0),
929 .gpiomux = { 0x551400, 0x551200, 0, 0 },
930 .gpiomute = 0x551c00,
931 .needs_tvaudio = 1,
932 .pll = PLL_28,
933 .tuner_type = TUNER_PHILIPS_PAL_I,
934 .tuner_addr = ADDR_UNSET,
935 .has_remote = 1,
936 },
937 [BTTV_BOARD_PINNACLE] = {
938 .name = "Pinnacle PCTV Studio/Rave",
939 .video_inputs = 3,
940 /* .audio_inputs= 1, */
941 .svhs = 2,
942 .gpiomask = 0x03000F,
943 .muxsel = MUXSEL(2, 3, 1, 1),
944 .gpiomux = { 2, 0xd0001, 0, 0 },
945 .gpiomute = 1,
946 .needs_tvaudio = 0,
947 .pll = PLL_28,
948 .tuner_type = UNSET,
949 .tuner_addr = ADDR_UNSET,
950 },
951
952 /* ---- card 0x28 ---------------------------------- */
953 [BTTV_BOARD_STB2] = {
954 .name = "STB TV PCI FM, Gateway P/N 6000704 (bt878), 3Dfx VoodooTV 100",
955 .video_inputs = 3,
956 /* .audio_inputs= 1, */
957 .svhs = 2,
958 .gpiomask = 7,
959 .muxsel = MUXSEL(2, 3, 1, 1),
960 .gpiomux = { 4, 0, 2, 3 },
961 .gpiomute = 1,
962 .no_msp34xx = 1,
963 .needs_tvaudio = 1,
964 .tuner_type = TUNER_PHILIPS_NTSC,
965 .tuner_addr = ADDR_UNSET,
966 .pll = PLL_28,
967 .has_radio = 1,
968 },
969 [BTTV_BOARD_AVPHONE98] = {
970 .name = "AVerMedia TVPhone 98",
971 .video_inputs = 3,
972 /* .audio_inputs= 4, */
973 .svhs = 2,
974 .gpiomask = 15,
975 .muxsel = MUXSEL(2, 3, 1, 1),
976 .gpiomux = { 13, 4, 11, 7 },
977 .needs_tvaudio = 1,
978 .pll = PLL_28,
979 .tuner_type = UNSET,
980 .tuner_addr = ADDR_UNSET,
981 .has_radio = 1,
982 .audio_mode_gpio= avermedia_tvphone_audio,
983 },
984 [BTTV_BOARD_PV951] = {
985 .name = "ProVideo PV951", /* pic16c54 */
986 .video_inputs = 3,
987 /* .audio_inputs= 1, */
988 .svhs = 2,
989 .gpiomask = 0,
990 .muxsel = MUXSEL(2, 3, 1, 1),
991 .gpiomux = { 0, 0, 0, 0},
992 .needs_tvaudio = 1,
993 .no_msp34xx = 1,
994 .pll = PLL_28,
995 .tuner_type = TUNER_PHILIPS_PAL_I,
996 .tuner_addr = ADDR_UNSET,
997 },
998 [BTTV_BOARD_ONAIR_TV] = {
999 .name = "Little OnAir TV",
1000 .video_inputs = 3,
1001 /* .audio_inputs= 1, */
1002 .svhs = 2,
1003 .gpiomask = 0xe00b,
1004 .muxsel = MUXSEL(2, 3, 1, 1),
1005 .gpiomux = { 0xff9ff6, 0xff9ff6, 0xff1ff7, 0 },
1006 .gpiomute = 0xff3ffc,
1007 .no_msp34xx = 1,
1008 .tuner_type = UNSET,
1009 .tuner_addr = ADDR_UNSET,
1010 },
1011
1012 /* ---- card 0x2c ---------------------------------- */
1013 [BTTV_BOARD_SIGMA_TVII_FM] = {
1014 .name = "Sigma TVII-FM",
1015 .video_inputs = 2,
1016 /* .audio_inputs= 1, */
1017 .svhs = NO_SVHS,
1018 .gpiomask = 3,
1019 .muxsel = MUXSEL(2, 3, 1, 1),
1020 .gpiomux = { 1, 1, 0, 2 },
1021 .gpiomute = 3,
1022 .no_msp34xx = 1,
1023 .pll = PLL_NONE,
1024 .tuner_type = UNSET,
1025 .tuner_addr = ADDR_UNSET,
1026 },
1027 [BTTV_BOARD_MATRIX_VISION2] = {
1028 .name = "MATRIX-Vision MV-Delta 2",
1029 .video_inputs = 5,
1030 /* .audio_inputs= 1, */
1031 .svhs = 3,
1032 .gpiomask = 0,
1033 .muxsel = MUXSEL(2, 3, 1, 0, 0),
1034 .gpiomux = { 0 },
1035 .no_msp34xx = 1,
1036 .pll = PLL_28,
1037 .tuner_type = TUNER_ABSENT,
1038 .tuner_addr = ADDR_UNSET,
1039 },
1040 [BTTV_BOARD_ZOLTRIX_GENIE] = {
1041 .name = "Zoltrix Genie TV/FM",
1042 .video_inputs = 3,
1043 /* .audio_inputs= 1, */
1044 .svhs = 2,
1045 .gpiomask = 0xbcf03f,
1046 .muxsel = MUXSEL(2, 3, 1, 1),
1047 .gpiomux = { 0xbc803f, 0xbc903f, 0xbcb03f, 0 },
1048 .gpiomute = 0xbcb03f,
1049 .no_msp34xx = 1,
1050 .pll = PLL_28,
1051 .tuner_type = TUNER_TEMIC_4039FR5_NTSC,
1052 .tuner_addr = ADDR_UNSET,
1053 },
1054 [BTTV_BOARD_TERRATVRADIO] = {
1055 .name = "Terratec TV/Radio+",
1056 .video_inputs = 3,
1057 /* .audio_inputs= 1, */
1058 .svhs = 2,
1059 .gpiomask = 0x70000,
1060 .muxsel = MUXSEL(2, 3, 1, 1),
1061 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 },
1062 .gpiomute = 0x40000,
1063 .needs_tvaudio = 1,
1064 .no_msp34xx = 1,
1065 .pll = PLL_35,
1066 .tuner_type = TUNER_PHILIPS_PAL_I,
1067 .tuner_addr = ADDR_UNSET,
1068 .has_radio = 1,
1069 },
1070
1071 /* ---- card 0x30 ---------------------------------- */
1072 [BTTV_BOARD_DYNALINK] = {
1073 .name = "Askey CPH03x/ Dynalink Magic TView",
1074 .video_inputs = 3,
1075 /* .audio_inputs= 1, */
1076 .svhs = 2,
1077 .gpiomask = 15,
1078 .muxsel = MUXSEL(2, 3, 1, 1),
1079 .gpiomux = {2,0,0,0 },
1080 .gpiomute = 1,
1081 .needs_tvaudio = 1,
1082 .pll = PLL_28,
1083 .tuner_type = UNSET,
1084 .tuner_addr = ADDR_UNSET,
1085 },
1086 [BTTV_BOARD_GVBCTV3PCI] = {
1087 .name = "IODATA GV-BCTV3/PCI",
1088 .video_inputs = 3,
1089 /* .audio_inputs= 1, */
1090 .svhs = 2,
1091 .gpiomask = 0x010f00,
1092 .muxsel = MUXSEL(2, 3, 0, 0),
1093 .gpiomux = {0x10000, 0, 0x10000, 0 },
1094 .no_msp34xx = 1,
1095 .pll = PLL_28,
1096 .tuner_type = TUNER_ALPS_TSHC6_NTSC,
1097 .tuner_addr = ADDR_UNSET,
1098 .audio_mode_gpio= gvbctv3pci_audio,
1099 },
1100 [BTTV_BOARD_PXELVWPLTVPAK] = {
1101 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP",
1102 .video_inputs = 5,
1103 /* .audio_inputs= 1, */
1104 .svhs = 3,
1105 .has_dig_in = 1,
1106 .gpiomask = 0xAA0000,
1107 .muxsel = MUXSEL(2, 3, 1, 1, 0), /* in 4 is digital */
1108 /* .digital_mode= DIGITAL_MODE_CAMERA, */
1109 .gpiomux = { 0x20000, 0, 0x80000, 0x80000 },
1110 .gpiomute = 0xa8000,
1111 .no_msp34xx = 1,
1112 .pll = PLL_28,
1113 .tuner_type = TUNER_PHILIPS_PAL_I,
1114 .tuner_addr = ADDR_UNSET,
1115 .has_remote = 1,
1116 /* GPIO wiring: (different from Rev.4C !)
1117 GPIO17: U4.A0 (first hef4052bt)
1118 GPIO19: U4.A1
1119 GPIO20: U5.A1 (second hef4052bt)
1120 GPIO21: U4.nEN
1121 GPIO22: BT832 Reset Line
1122 GPIO23: A5,A0, U5,nEN
1123 Note: At i2c=0x8a is a Bt832 chip, which changes to 0x88 after being reset via GPIO22
1124 */
1125 },
1126 [BTTV_BOARD_EAGLE] = {
1127 .name = "Eagle Wireless Capricorn2 (bt878A)",
1128 .video_inputs = 4,
1129 /* .audio_inputs= 1, */
1130 .svhs = 2,
1131 .gpiomask = 7,
1132 .muxsel = MUXSEL(2, 0, 1, 1),
1133 .gpiomux = { 0, 1, 2, 3 },
1134 .gpiomute = 4,
1135 .pll = PLL_28,
1136 .tuner_type = UNSET /* TUNER_ALPS_TMDH2_NTSC */,
1137 .tuner_addr = ADDR_UNSET,
1138 },
1139
1140 /* ---- card 0x34 ---------------------------------- */
1141 [BTTV_BOARD_PINNACLEPRO] = {
1142 /* David Härdeman <david@2gen.com> */
1143 .name = "Pinnacle PCTV Studio Pro",
1144 .video_inputs = 4,
1145 /* .audio_inputs= 1, */
1146 .svhs = 3,
1147 .gpiomask = 0x03000F,
1148 .muxsel = MUXSEL(2, 3, 1, 1),
1149 .gpiomux = { 1, 0xd0001, 0, 0 },
1150 .gpiomute = 10,
1151 /* sound path (5 sources):
1152 MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable)
1153 0= ext. Audio IN
1154 1= from MUX2
1155 2= Mono TV sound from Tuner
1156 3= not connected
1157 MUX2 (mask 0x30000):
1158 0,2,3= from MSP34xx
1159 1= FM stereo Radio from Tuner */
1160 .needs_tvaudio = 0,
1161 .pll = PLL_28,
1162 .tuner_type = UNSET,
1163 .tuner_addr = ADDR_UNSET,
1164 },
1165 [BTTV_BOARD_TVIEW_RDS_FM] = {
1166 /* Claas Langbehn <claas@bigfoot.com>,
1167 Sven Grothklags <sven@upb.de> */
1168 .name = "Typhoon TView RDS + FM Stereo / KNC1 TV Station RDS",
1169 .video_inputs = 4,
1170 /* .audio_inputs= 3, */
1171 .svhs = 2,
1172 .gpiomask = 0x1c,
1173 .muxsel = MUXSEL(2, 3, 1, 1),
1174 .gpiomux = { 0, 0, 0x10, 8 },
1175 .gpiomute = 4,
1176 .needs_tvaudio = 1,
1177 .pll = PLL_28,
1178 .tuner_type = TUNER_PHILIPS_PAL,
1179 .tuner_addr = ADDR_UNSET,
1180 .has_radio = 1,
1181 },
1182 [BTTV_BOARD_LIFETEC_9415] = {
1183 /* Tim Röstermundt <rosterm@uni-muenster.de>
1184 in de.comp.os.unix.linux.hardware:
1185 options bttv card=0 pll=1 radio=1 gpiomask=0x18e0
1186 gpiomux =0x44c71f,0x44d71f,0,0x44d71f,0x44dfff
1187 options tuner type=5 */
1188 .name = "Lifeview FlyVideo 2000 /FlyVideo A2/ Lifetec LT 9415 TV [LR90]",
1189 .video_inputs = 4,
1190 /* .audio_inputs= 1, */
1191 .svhs = 2,
1192 .gpiomask = 0x18e0,
1193 .muxsel = MUXSEL(2, 3, 1, 1),
1194 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 },
1195 .gpiomute = 0x18e0,
1196 /* For cards with tda9820/tda9821:
1197 0x0000: Tuner normal stereo
1198 0x0080: Tuner A2 SAP (second audio program = Zweikanalton)
1199 0x0880: Tuner A2 stereo */
1200 .pll = PLL_28,
1201 .tuner_type = UNSET,
1202 .tuner_addr = ADDR_UNSET,
1203 },
1204 [BTTV_BOARD_BESTBUY_EASYTV] = {
1205 /* Miguel Angel Alvarez <maacruz@navegalia.com>
1206 old Easy TV BT848 version (model CPH031) */
1207 .name = "Askey CPH031/ BESTBUY Easy TV",
1208 .video_inputs = 4,
1209 /* .audio_inputs= 1, */
1210 .svhs = 2,
1211 .gpiomask = 0xF,
1212 .muxsel = MUXSEL(2, 3, 1, 0),
1213 .gpiomux = { 2, 0, 0, 0 },
1214 .gpiomute = 10,
1215 .needs_tvaudio = 0,
1216 .pll = PLL_28,
1217 .tuner_type = TUNER_TEMIC_PAL,
1218 .tuner_addr = ADDR_UNSET,
1219 },
1220
1221 /* ---- card 0x38 ---------------------------------- */
1222 [BTTV_BOARD_FLYVIDEO_98FM] = {
1223 /* Gordon Heydon <gjheydon@bigfoot.com ('98) */
1224 .name = "Lifeview FlyVideo 98FM LR50",
1225 .video_inputs = 4,
1226 /* .audio_inputs= 3, */
1227 .svhs = 2,
1228 .gpiomask = 0x1800,
1229 .muxsel = MUXSEL(2, 3, 1, 1),
1230 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
1231 .gpiomute = 0x1800,
1232 .pll = PLL_28,
1233 .tuner_type = TUNER_PHILIPS_PAL,
1234 .tuner_addr = ADDR_UNSET,
1235 },
1236 /* This is the ultimate cheapo capture card
1237 * just a BT848A on a small PCB!
1238 * Steve Hosgood <steve@equiinet.com> */
1239 [BTTV_BOARD_GRANDTEC] = {
1240 .name = "GrandTec 'Grand Video Capture' (Bt848)",
1241 .video_inputs = 2,
1242 /* .audio_inputs= 0, */
1243 .svhs = 1,
1244 .gpiomask = 0,
1245 .muxsel = MUXSEL(3, 1),
1246 .gpiomux = { 0 },
1247 .needs_tvaudio = 0,
1248 .no_msp34xx = 1,
1249 .pll = PLL_35,
1250 .tuner_type = TUNER_ABSENT,
1251 .tuner_addr = ADDR_UNSET,
1252 },
1253 [BTTV_BOARD_ASKEY_CPH060] = {
1254 /* Daniel Herrington <daniel.herrington@home.com> */
1255 .name = "Askey CPH060/ Phoebe TV Master Only (No FM)",
1256 .video_inputs = 3,
1257 /* .audio_inputs= 1, */
1258 .svhs = 2,
1259 .gpiomask = 0xe00,
1260 .muxsel = MUXSEL(2, 3, 1, 1),
1261 .gpiomux = { 0x400, 0x400, 0x400, 0x400 },
1262 .gpiomute = 0x800,
1263 .needs_tvaudio = 1,
1264 .pll = PLL_28,
1265 .tuner_type = TUNER_TEMIC_4036FY5_NTSC,
1266 .tuner_addr = ADDR_UNSET,
1267 },
1268 [BTTV_BOARD_ASKEY_CPH03X] = {
1269 /* Matti Mottus <mottus@physic.ut.ee> */
1270 .name = "Askey CPH03x TV Capturer",
1271 .video_inputs = 4,
1272 /* .audio_inputs= 1, */
1273 .svhs = 2,
1274 .gpiomask = 0x03000F,
1275 .muxsel = MUXSEL(2, 3, 1, 0),
1276 .gpiomux = { 2, 0, 0, 0 },
1277 .gpiomute = 1,
1278 .pll = PLL_28,
1279 .tuner_type = TUNER_TEMIC_PAL,
1280 .tuner_addr = ADDR_UNSET,
1281 .has_remote = 1,
1282 },
1283
1284 /* ---- card 0x3c ---------------------------------- */
1285 [BTTV_BOARD_MM100PCTV] = {
1286 /* Philip Blundell <philb@gnu.org> */
1287 .name = "Modular Technology MM100PCTV",
1288 .video_inputs = 2,
1289 /* .audio_inputs= 2, */
1290 .svhs = NO_SVHS,
1291 .gpiomask = 11,
1292 .muxsel = MUXSEL(2, 3, 1, 1),
1293 .gpiomux = { 2, 0, 0, 1 },
1294 .gpiomute = 8,
1295 .pll = PLL_35,
1296 .tuner_type = TUNER_TEMIC_PAL,
1297 .tuner_addr = ADDR_UNSET,
1298 },
1299 [BTTV_BOARD_GMV1] = {
1300 /* Adrian Cox <adrian@humboldt.co.uk */
1301 .name = "AG Electronics GMV1",
1302 .video_inputs = 2,
1303 /* .audio_inputs= 0, */
1304 .svhs = 1,
1305 .gpiomask = 0xF,
1306 .muxsel = MUXSEL(2, 2),
1307 .gpiomux = { },
1308 .no_msp34xx = 1,
1309 .needs_tvaudio = 0,
1310 .pll = PLL_28,
1311 .tuner_type = TUNER_ABSENT,
1312 .tuner_addr = ADDR_UNSET,
1313 },
1314 [BTTV_BOARD_BESTBUY_EASYTV2] = {
1315 /* Miguel Angel Alvarez <maacruz@navegalia.com>
1316 new Easy TV BT878 version (model CPH061)
1317 special thanks to Informatica Mieres for providing the card */
1318 .name = "Askey CPH061/ BESTBUY Easy TV (bt878)",
1319 .video_inputs = 3,
1320 /* .audio_inputs= 2, */
1321 .svhs = 2,
1322 .gpiomask = 0xFF,
1323 .muxsel = MUXSEL(2, 3, 1, 0),
1324 .gpiomux = { 1, 0, 4, 4 },
1325 .gpiomute = 9,
1326 .needs_tvaudio = 0,
1327 .pll = PLL_28,
1328 .tuner_type = TUNER_PHILIPS_PAL,
1329 .tuner_addr = ADDR_UNSET,
1330 },
1331 [BTTV_BOARD_ATI_TVWONDER] = {
1332 /* Lukas Gebauer <geby@volny.cz> */
1333 .name = "ATI TV-Wonder",
1334 .video_inputs = 3,
1335 /* .audio_inputs= 1, */
1336 .svhs = 2,
1337 .gpiomask = 0xf03f,
1338 .muxsel = MUXSEL(2, 3, 1, 0),
1339 .gpiomux = { 0xbffe, 0, 0xbfff, 0 },
1340 .gpiomute = 0xbffe,
1341 .pll = PLL_28,
1342 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1343 .tuner_addr = ADDR_UNSET,
1344 },
1345
1346 /* ---- card 0x40 ---------------------------------- */
1347 [BTTV_BOARD_ATI_TVWONDERVE] = {
1348 /* Lukas Gebauer <geby@volny.cz> */
1349 .name = "ATI TV-Wonder VE",
1350 .video_inputs = 2,
1351 /* .audio_inputs= 1, */
1352 .svhs = NO_SVHS,
1353 .gpiomask = 1,
1354 .muxsel = MUXSEL(2, 3, 0, 1),
1355 .gpiomux = { 0, 0, 1, 0 },
1356 .no_msp34xx = 1,
1357 .pll = PLL_28,
1358 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1359 .tuner_addr = ADDR_UNSET,
1360 },
1361 [BTTV_BOARD_FLYVIDEO2000] = {
1362 /* DeeJay <deejay@westel900.net (2000S) */
1363 .name = "Lifeview FlyVideo 2000S LR90",
1364 .video_inputs = 3,
1365 /* .audio_inputs= 3, */
1366 .svhs = 2,
1367 .gpiomask = 0x18e0,
1368 .muxsel = MUXSEL(2, 3, 0, 1),
1369 /* Radio changed from 1e80 to 0x800 to make
1370 FlyVideo2000S in .hu happy (gm)*/
1371 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */
1372 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 },
1373 .gpiomute = 0x1800,
1374 .audio_mode_gpio= fv2000s_audio,
1375 .no_msp34xx = 1,
1376 .needs_tvaudio = 1,
1377 .pll = PLL_28,
1378 .tuner_type = TUNER_PHILIPS_PAL,
1379 .tuner_addr = ADDR_UNSET,
1380 },
1381 [BTTV_BOARD_TERRATVALUER] = {
1382 .name = "Terratec TValueRadio",
1383 .video_inputs = 3,
1384 /* .audio_inputs= 1, */
1385 .svhs = 2,
1386 .gpiomask = 0xffff00,
1387 .muxsel = MUXSEL(2, 3, 1, 1),
1388 .gpiomux = { 0x500, 0x500, 0x300, 0x900 },
1389 .gpiomute = 0x900,
1390 .needs_tvaudio = 1,
1391 .pll = PLL_28,
1392 .tuner_type = TUNER_PHILIPS_PAL,
1393 .tuner_addr = ADDR_UNSET,
1394 .has_radio = 1,
1395 },
1396 [BTTV_BOARD_GVBCTV4PCI] = {
1397 /* TANAKA Kei <peg00625@nifty.com> */
1398 .name = "IODATA GV-BCTV4/PCI",
1399 .video_inputs = 3,
1400 /* .audio_inputs= 1, */
1401 .svhs = 2,
1402 .gpiomask = 0x010f00,
1403 .muxsel = MUXSEL(2, 3, 0, 0),
1404 .gpiomux = {0x10000, 0, 0x10000, 0 },
1405 .no_msp34xx = 1,
1406 .pll = PLL_28,
1407 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC,
1408 .tuner_addr = ADDR_UNSET,
1409 .audio_mode_gpio= gvbctv3pci_audio,
1410 },
1411
1412 /* ---- card 0x44 ---------------------------------- */
1413 [BTTV_BOARD_VOODOOTV_FM] = {
1414 .name = "3Dfx VoodooTV FM (Euro)",
1415 /* try "insmod msp3400 simple=0" if you have
1416 * sound problems with this card. */
1417 .video_inputs = 4,
1418 /* .audio_inputs= 1, */
1419 .svhs = NO_SVHS,
1420 .gpiomask = 0x4f8a00,
1421 /* 0x100000: 1=MSP enabled (0=disable again)
1422 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */
1423 .gpiomux = {0x947fff, 0x987fff,0x947fff,0x947fff },
1424 .gpiomute = 0x947fff,
1425 /* tvtuner, radio, external,internal, mute, stereo
1426 * tuner, Composit, SVid, Composit-on-Svid-adapter */
1427 .muxsel = MUXSEL(2, 3, 0, 1),
1428 .tuner_type = TUNER_MT2032,
1429 .tuner_addr = ADDR_UNSET,
1430 .pll = PLL_28,
1431 .has_radio = 1,
1432 },
1433 [BTTV_BOARD_VOODOOTV_200] = {
1434 .name = "VoodooTV 200 (USA)",
1435 /* try "insmod msp3400 simple=0" if you have
1436 * sound problems with this card. */
1437 .video_inputs = 4,
1438 /* .audio_inputs= 1, */
1439 .svhs = NO_SVHS,
1440 .gpiomask = 0x4f8a00,
1441 /* 0x100000: 1=MSP enabled (0=disable again)
1442 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */
1443 .gpiomux = {0x947fff, 0x987fff,0x947fff,0x947fff },
1444 .gpiomute = 0x947fff,
1445 /* tvtuner, radio, external,internal, mute, stereo
1446 * tuner, Composit, SVid, Composit-on-Svid-adapter */
1447 .muxsel = MUXSEL(2, 3, 0, 1),
1448 .tuner_type = TUNER_MT2032,
1449 .tuner_addr = ADDR_UNSET,
1450 .pll = PLL_28,
1451 .has_radio = 1,
1452 },
1453 [BTTV_BOARD_AIMMS] = {
1454 /* Philip Blundell <pb@nexus.co.uk> */
1455 .name = "Active Imaging AIMMS",
1456 .video_inputs = 1,
1457 /* .audio_inputs= 0, */
1458 .tuner_type = TUNER_ABSENT,
1459 .tuner_addr = ADDR_UNSET,
1460 .pll = PLL_28,
1461 .muxsel = MUXSEL(2),
1462 .gpiomask = 0
1463 },
1464 [BTTV_BOARD_PV_BT878P_PLUS] = {
1465 /* Tomasz Pyra <hellfire@sedez.iq.pl> */
1466 .name = "Prolink Pixelview PV-BT878P+ (Rev.4C,8E)",
1467 .video_inputs = 3,
1468 /* .audio_inputs= 4, */
1469 .svhs = 2,
1470 .gpiomask = 15,
1471 .muxsel = MUXSEL(2, 3, 1, 1),
1472 .gpiomux = { 0, 0, 11, 7 }, /* TV and Radio with same GPIO ! */
1473 .gpiomute = 13,
1474 .needs_tvaudio = 1,
1475 .pll = PLL_28,
1476 .tuner_type = TUNER_LG_PAL_I_FM,
1477 .tuner_addr = ADDR_UNSET,
1478 .has_remote = 1,
1479 /* GPIO wiring:
1480 GPIO0: U4.A0 (hef4052bt)
1481 GPIO1: U4.A1
1482 GPIO2: U4.A1 (second hef4052bt)
1483 GPIO3: U4.nEN, U5.A0, A5.nEN
1484 GPIO8-15: vrd866b ?
1485 */
1486 },
1487 [BTTV_BOARD_FLYVIDEO98EZ] = {
1488 .name = "Lifeview FlyVideo 98EZ (capture only) LR51",
1489 .video_inputs = 4,
1490 /* .audio_inputs= 0, */
1491 .svhs = 2,
1492 /* AV1, AV2, SVHS, CVid adapter on SVHS */
1493 .muxsel = MUXSEL(2, 3, 1, 1),
1494 .pll = PLL_28,
1495 .no_msp34xx = 1,
1496 .tuner_type = TUNER_ABSENT,
1497 .tuner_addr = ADDR_UNSET,
1498 },
1499
1500 /* ---- card 0x48 ---------------------------------- */
1501 [BTTV_BOARD_PV_BT878P_9B] = {
1502 /* Dariusz Kowalewski <darekk@automex.pl> */
1503 .name = "Prolink Pixelview PV-BT878P+9B (PlayTV Pro rev.9B FM+NICAM)",
1504 .video_inputs = 4,
1505 /* .audio_inputs= 1, */
1506 .svhs = 2,
1507 .gpiomask = 0x3f,
1508 .muxsel = MUXSEL(2, 3, 1, 1),
1509 .gpiomux = { 0x01, 0x00, 0x03, 0x03 },
1510 .gpiomute = 0x09,
1511 .needs_tvaudio = 1,
1512 .no_msp34xx = 1,
1513 .pll = PLL_28,
1514 .tuner_type = TUNER_PHILIPS_PAL,
1515 .tuner_addr = ADDR_UNSET,
1516 .audio_mode_gpio= pvbt878p9b_audio, /* Note: not all cards have stereo */
1517 .has_radio = 1, /* Note: not all cards have radio */
1518 .has_remote = 1,
1519 /* GPIO wiring:
1520 GPIO0: A0 hef4052
1521 GPIO1: A1 hef4052
1522 GPIO3: nEN hef4052
1523 GPIO8-15: vrd866b
1524 GPIO20,22,23: R30,R29,R28
1525 */
1526 },
1527 [BTTV_BOARD_SENSORAY311] = {
1528 /* Clay Kunz <ckunz@mail.arc.nasa.gov> */
1529 /* you must jumper JP5 for the card to work */
1530 .name = "Sensoray 311",
1531 .video_inputs = 5,
1532 /* .audio_inputs= 0, */
1533 .svhs = 4,
1534 .gpiomask = 0,
1535 .muxsel = MUXSEL(2, 3, 1, 0, 0),
1536 .gpiomux = { 0 },
1537 .needs_tvaudio = 0,
1538 .tuner_type = TUNER_ABSENT,
1539 .tuner_addr = ADDR_UNSET,
1540 },
1541 [BTTV_BOARD_RV605] = {
1542 /* Miguel Freitas <miguel@cetuc.puc-rio.br> */
1543 .name = "RemoteVision MX (RV605)",
1544 .video_inputs = 16,
1545 /* .audio_inputs= 0, */
1546 .svhs = NO_SVHS,
1547 .gpiomask = 0x00,
1548 .gpiomask2 = 0x07ff,
1549 .muxsel = MUXSEL(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
1550 .no_msp34xx = 1,
1551 .tuner_type = TUNER_ABSENT,
1552 .tuner_addr = ADDR_UNSET,
1553 .muxsel_hook = rv605_muxsel,
1554 },
1555 [BTTV_BOARD_POWERCLR_MTV878] = {
1556 .name = "Powercolor MTV878/ MTV878R/ MTV878F",
1557 .video_inputs = 3,
1558 /* .audio_inputs= 2, */
1559 .svhs = 2,
1560 .gpiomask = 0x1C800F, /* Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset */
1561 .muxsel = MUXSEL(2, 1, 1),
1562 .gpiomux = { 0, 1, 2, 2 },
1563 .gpiomute = 4,
1564 .needs_tvaudio = 0,
1565 .tuner_type = TUNER_PHILIPS_PAL,
1566 .tuner_addr = ADDR_UNSET,
1567 .pll = PLL_28,
1568 .has_radio = 1,
1569 },
1570
1571 /* ---- card 0x4c ---------------------------------- */
1572 [BTTV_BOARD_WINDVR] = {
1573 /* Masaki Suzuki <masaki@btree.org> */
1574 .name = "Canopus WinDVR PCI (COMPAQ Presario 3524JP, 5112JP)",
1575 .video_inputs = 3,
1576 /* .audio_inputs= 1, */
1577 .svhs = 2,
1578 .gpiomask = 0x140007,
1579 .muxsel = MUXSEL(2, 3, 1, 1),
1580 .gpiomux = { 0, 1, 2, 3 },
1581 .gpiomute = 4,
1582 .tuner_type = TUNER_PHILIPS_NTSC,
1583 .tuner_addr = ADDR_UNSET,
1584 .audio_mode_gpio= windvr_audio,
1585 },
1586 [BTTV_BOARD_GRANDTEC_MULTI] = {
1587 .name = "GrandTec Multi Capture Card (Bt878)",
1588 .video_inputs = 4,
1589 /* .audio_inputs= 0, */
1590 .svhs = NO_SVHS,
1591 .gpiomask = 0,
1592 .muxsel = MUXSEL(2, 3, 1, 0),
1593 .gpiomux = { 0 },
1594 .needs_tvaudio = 0,
1595 .no_msp34xx = 1,
1596 .pll = PLL_28,
1597 .tuner_type = TUNER_ABSENT,
1598 .tuner_addr = ADDR_UNSET,
1599 },
1600 [BTTV_BOARD_KWORLD] = {
1601 .name = "Jetway TV/Capture JW-TV878-FBK, Kworld KW-TV878RF",
1602 .video_inputs = 4,
1603 /* .audio_inputs= 3, */
1604 .svhs = 2,
1605 .gpiomask = 7,
1606 /* Tuner, SVid, SVHS, SVid to SVHS connector */
1607 .muxsel = MUXSEL(2, 3, 1, 1),
1608 .gpiomux = { 0, 0, 4, 4 },/* Yes, this tuner uses the same audio output for TV and FM radio!
1609 * This card lacks external Audio In, so we mute it on Ext. & Int.
1610 * The PCB can take a sbx1637/sbx1673, wiring unknown.
1611 * This card lacks PCI subsystem ID, sigh.
1612 * gpiomux =1: lower volume, 2+3: mute
1613 * btwincap uses 0x80000/0x80003
1614 */
1615 .gpiomute = 4,
1616 .needs_tvaudio = 0,
1617 .no_msp34xx = 1,
1618 .pll = PLL_28,
1619 .tuner_type = TUNER_PHILIPS_PAL,
1620 .tuner_addr = ADDR_UNSET,
1621 /* Samsung TCPA9095PC27A (BG+DK), philips compatible, w/FM, stereo and
1622 radio signal strength indicators work fine. */
1623 .has_radio = 1,
1624 /* GPIO Info:
1625 GPIO0,1: HEF4052 A0,A1
1626 GPIO2: HEF4052 nENABLE
1627 GPIO3-7: n.c.
1628 GPIO8-13: IRDC357 data0-5 (data6 n.c. ?) [chip not present on my card]
1629 GPIO14,15: ??
1630 GPIO16-21: n.c.
1631 GPIO22,23: ??
1632 ?? : mtu8b56ep microcontroller for IR (GPIO wiring unknown)*/
1633 },
1634 [BTTV_BOARD_DSP_TCVIDEO] = {
1635 /* Arthur Tetzlaff-Deas, DSP Design Ltd <software@dspdesign.com> */
1636 .name = "DSP Design TCVIDEO",
1637 .video_inputs = 4,
1638 .svhs = NO_SVHS,
1639 .muxsel = MUXSEL(2, 3, 1, 0),
1640 .pll = PLL_28,
1641 .tuner_type = UNSET,
1642 .tuner_addr = ADDR_UNSET,
1643 },
1644
1645 /* ---- card 0x50 ---------------------------------- */
1646 [BTTV_BOARD_HAUPPAUGEPVR] = {
1647 .name = "Hauppauge WinTV PVR",
1648 .video_inputs = 4,
1649 /* .audio_inputs= 1, */
1650 .svhs = 2,
1651 .muxsel = MUXSEL(2, 0, 1, 1),
1652 .needs_tvaudio = 1,
1653 .pll = PLL_28,
1654 .tuner_type = UNSET,
1655 .tuner_addr = ADDR_UNSET,
1656
1657 .gpiomask = 7,
1658 .gpiomux = {7},
1659 },
1660 [BTTV_BOARD_GVBCTV5PCI] = {
1661 .name = "IODATA GV-BCTV5/PCI",
1662 .video_inputs = 3,
1663 /* .audio_inputs= 1, */
1664 .svhs = 2,
1665 .gpiomask = 0x0f0f80,
1666 .muxsel = MUXSEL(2, 3, 1, 0),
1667 .gpiomux = {0x030000, 0x010000, 0, 0 },
1668 .gpiomute = 0x020000,
1669 .no_msp34xx = 1,
1670 .pll = PLL_28,
1671 .tuner_type = TUNER_PHILIPS_NTSC_M,
1672 .tuner_addr = ADDR_UNSET,
1673 .audio_mode_gpio= gvbctv5pci_audio,
1674 .has_radio = 1,
1675 },
1676 [BTTV_BOARD_OSPREY1x0] = {
1677 .name = "Osprey 100/150 (878)", /* 0x1(2|3)-45C6-C1 */
1678 .video_inputs = 4, /* id-inputs-clock */
1679 /* .audio_inputs= 0, */
1680 .svhs = 3,
1681 .muxsel = MUXSEL(3, 2, 0, 1),
1682 .pll = PLL_28,
1683 .tuner_type = TUNER_ABSENT,
1684 .tuner_addr = ADDR_UNSET,
1685 .no_msp34xx = 1,
1686 .no_tda7432 = 1,
1687 },
1688 [BTTV_BOARD_OSPREY1x0_848] = {
1689 .name = "Osprey 100/150 (848)", /* 0x04-54C0-C1 & older boards */
1690 .video_inputs = 3,
1691 /* .audio_inputs= 0, */
1692 .svhs = 2,
1693 .muxsel = MUXSEL(2, 3, 1),
1694 .pll = PLL_28,
1695 .tuner_type = TUNER_ABSENT,
1696 .tuner_addr = ADDR_UNSET,
1697 .no_msp34xx = 1,
1698 .no_tda7432 = 1,
1699 },
1700
1701 /* ---- card 0x54 ---------------------------------- */
1702 [BTTV_BOARD_OSPREY101_848] = {
1703 .name = "Osprey 101 (848)", /* 0x05-40C0-C1 */
1704 .video_inputs = 2,
1705 /* .audio_inputs= 0, */
1706 .svhs = 1,
1707 .muxsel = MUXSEL(3, 1),
1708 .pll = PLL_28,
1709 .tuner_type = TUNER_ABSENT,
1710 .tuner_addr = ADDR_UNSET,
1711 .no_msp34xx = 1,
1712 .no_tda7432 = 1,
1713 },
1714 [BTTV_BOARD_OSPREY1x1] = {
1715 .name = "Osprey 101/151", /* 0x1(4|5)-0004-C4 */
1716 .video_inputs = 1,
1717 /* .audio_inputs= 0, */
1718 .svhs = NO_SVHS,
1719 .muxsel = MUXSEL(0),
1720 .pll = PLL_28,
1721 .tuner_type = TUNER_ABSENT,
1722 .tuner_addr = ADDR_UNSET,
1723 .no_msp34xx = 1,
1724 .no_tda7432 = 1,
1725 },
1726 [BTTV_BOARD_OSPREY1x1_SVID] = {
1727 .name = "Osprey 101/151 w/ svid", /* 0x(16|17|20)-00C4-C1 */
1728 .video_inputs = 2,
1729 /* .audio_inputs= 0, */
1730 .svhs = 1,
1731 .muxsel = MUXSEL(0, 1),
1732 .pll = PLL_28,
1733 .tuner_type = TUNER_ABSENT,
1734 .tuner_addr = ADDR_UNSET,
1735 .no_msp34xx = 1,
1736 .no_tda7432 = 1,
1737 },
1738 [BTTV_BOARD_OSPREY2xx] = {
1739 .name = "Osprey 200/201/250/251", /* 0x1(8|9|E|F)-0004-C4 */
1740 .video_inputs = 1,
1741 /* .audio_inputs= 1, */
1742 .svhs = NO_SVHS,
1743 .muxsel = MUXSEL(0),
1744 .pll = PLL_28,
1745 .tuner_type = TUNER_ABSENT,
1746 .tuner_addr = ADDR_UNSET,
1747 .no_msp34xx = 1,
1748 .no_tda7432 = 1,
1749 },
1750
1751 /* ---- card 0x58 ---------------------------------- */
1752 [BTTV_BOARD_OSPREY2x0_SVID] = {
1753 .name = "Osprey 200/250", /* 0x1(A|B)-00C4-C1 */
1754 .video_inputs = 2,
1755 /* .audio_inputs= 1, */
1756 .svhs = 1,
1757 .muxsel = MUXSEL(0, 1),
1758 .pll = PLL_28,
1759 .tuner_type = TUNER_ABSENT,
1760 .tuner_addr = ADDR_UNSET,
1761 .no_msp34xx = 1,
1762 .no_tda7432 = 1,
1763 },
1764 [BTTV_BOARD_OSPREY2x0] = {
1765 .name = "Osprey 210/220/230", /* 0x1(A|B)-04C0-C1 */
1766 .video_inputs = 2,
1767 /* .audio_inputs= 1, */
1768 .svhs = 1,
1769 .muxsel = MUXSEL(2, 3),
1770 .pll = PLL_28,
1771 .tuner_type = TUNER_ABSENT,
1772 .tuner_addr = ADDR_UNSET,
1773 .no_msp34xx = 1,
1774 .no_tda7432 = 1,
1775 },
1776 [BTTV_BOARD_OSPREY500] = {
1777 .name = "Osprey 500", /* 500 */
1778 .video_inputs = 2,
1779 /* .audio_inputs= 1, */
1780 .svhs = 1,
1781 .muxsel = MUXSEL(2, 3),
1782 .pll = PLL_28,
1783 .tuner_type = TUNER_ABSENT,
1784 .tuner_addr = ADDR_UNSET,
1785 .no_msp34xx = 1,
1786 .no_tda7432 = 1,
1787 },
1788 [BTTV_BOARD_OSPREY540] = {
1789 .name = "Osprey 540", /* 540 */
1790 .video_inputs = 4,
1791 /* .audio_inputs= 1, */
1792 .pll = PLL_28,
1793 .tuner_type = TUNER_ABSENT,
1794 .tuner_addr = ADDR_UNSET,
1795 .no_msp34xx = 1,
1796 .no_tda7432 = 1,
1797 },
1798
1799 /* ---- card 0x5C ---------------------------------- */
1800 [BTTV_BOARD_OSPREY2000] = {
1801 .name = "Osprey 2000", /* 2000 */
1802 .video_inputs = 2,
1803 /* .audio_inputs= 1, */
1804 .svhs = 1,
1805 .muxsel = MUXSEL(2, 3),
1806 .pll = PLL_28,
1807 .tuner_type = TUNER_ABSENT,
1808 .tuner_addr = ADDR_UNSET,
1809 .no_msp34xx = 1,
1810 .no_tda7432 = 1, /* must avoid, conflicts with the bt860 */
1811 },
1812 [BTTV_BOARD_IDS_EAGLE] = {
1813 /* M G Berberich <berberic@forwiss.uni-passau.de> */
1814 .name = "IDS Eagle",
1815 .video_inputs = 4,
1816 /* .audio_inputs= 0, */
1817 .tuner_type = TUNER_ABSENT,
1818 .tuner_addr = ADDR_UNSET,
1819 .svhs = NO_SVHS,
1820 .gpiomask = 0,
1821 .muxsel = MUXSEL(2, 2, 2, 2),
1822 .muxsel_hook = eagle_muxsel,
1823 .no_msp34xx = 1,
1824 .pll = PLL_28,
1825 },
1826 [BTTV_BOARD_PINNACLESAT] = {
1827 .name = "Pinnacle PCTV Sat",
1828 .video_inputs = 2,
1829 /* .audio_inputs= 0, */
1830 .svhs = 1,
1831 .tuner_type = TUNER_ABSENT,
1832 .tuner_addr = ADDR_UNSET,
1833 .no_msp34xx = 1,
1834 .no_tda7432 = 1,
1835 .muxsel = MUXSEL(3, 1),
1836 .pll = PLL_28,
1837 .no_gpioirq = 1,
1838 .has_dvb = 1,
1839 },
1840 [BTTV_BOARD_FORMAC_PROTV] = {
1841 .name = "Formac ProTV II (bt878)",
1842 .video_inputs = 4,
1843 /* .audio_inputs= 1, */
1844 .svhs = 3,
1845 .gpiomask = 2,
1846 /* TV, Comp1, Composite over SVID con, SVID */
1847 .muxsel = MUXSEL(2, 3, 1, 1),
1848 .gpiomux = { 2, 2, 0, 0 },
1849 .pll = PLL_28,
1850 .has_radio = 1,
1851 .tuner_type = TUNER_PHILIPS_PAL,
1852 .tuner_addr = ADDR_UNSET,
1853 /* sound routing:
1854 GPIO=0x00,0x01,0x03: mute (?)
1855 0x02: both TV and radio (tuner: FM1216/I)
1856 The card has onboard audio connectors labeled "cdrom" and "board",
1857 not soldered here, though unknown wiring.
1858 Card lacks: external audio in, pci subsystem id.
1859 */
1860 },
1861
1862 /* ---- card 0x60 ---------------------------------- */
1863 [BTTV_BOARD_MACHTV] = {
1864 .name = "MachTV",
1865 .video_inputs = 3,
1866 /* .audio_inputs= 1, */
1867 .svhs = NO_SVHS,
1868 .gpiomask = 7,
1869 .muxsel = MUXSEL(2, 3, 1, 1),
1870 .gpiomux = { 0, 1, 2, 3},
1871 .gpiomute = 4,
1872 .needs_tvaudio = 1,
1873 .tuner_type = TUNER_PHILIPS_PAL,
1874 .tuner_addr = ADDR_UNSET,
1875 .pll = PLL_28,
1876 },
1877 [BTTV_BOARD_EURESYS_PICOLO] = {
1878 .name = "Euresys Picolo",
1879 .video_inputs = 3,
1880 /* .audio_inputs= 0, */
1881 .svhs = 2,
1882 .gpiomask = 0,
1883 .no_msp34xx = 1,
1884 .no_tda7432 = 1,
1885 .muxsel = MUXSEL(2, 0, 1),
1886 .pll = PLL_28,
1887 .tuner_type = TUNER_ABSENT,
1888 .tuner_addr = ADDR_UNSET,
1889 },
1890 [BTTV_BOARD_PV150] = {
1891 /* Luc Van Hoeylandt <luc@e-magic.be> */
1892 .name = "ProVideo PV150", /* 0x4f */
1893 .video_inputs = 2,
1894 /* .audio_inputs= 0, */
1895 .svhs = NO_SVHS,
1896 .gpiomask = 0,
1897 .muxsel = MUXSEL(2, 3),
1898 .gpiomux = { 0 },
1899 .needs_tvaudio = 0,
1900 .no_msp34xx = 1,
1901 .pll = PLL_28,
1902 .tuner_type = TUNER_ABSENT,
1903 .tuner_addr = ADDR_UNSET,
1904 },
1905 [BTTV_BOARD_AD_TVK503] = {
1906 /* Hiroshi Takekawa <sian@big.or.jp> */
1907 /* This card lacks subsystem ID */
1908 .name = "AD-TVK503", /* 0x63 */
1909 .video_inputs = 4,
1910 /* .audio_inputs= 1, */
1911 .svhs = 2,
1912 .gpiomask = 0x001e8007,
1913 .muxsel = MUXSEL(2, 3, 1, 0),
1914 /* Tuner, Radio, external, internal, off, on */
1915 .gpiomux = { 0x08, 0x0f, 0x0a, 0x08 },
1916 .gpiomute = 0x0f,
1917 .needs_tvaudio = 0,
1918 .no_msp34xx = 1,
1919 .pll = PLL_28,
1920 .tuner_type = TUNER_PHILIPS_NTSC,
1921 .tuner_addr = ADDR_UNSET,
1922 .audio_mode_gpio= adtvk503_audio,
1923 },
1924
1925 /* ---- card 0x64 ---------------------------------- */
1926 [BTTV_BOARD_HERCULES_SM_TV] = {
1927 .name = "Hercules Smart TV Stereo",
1928 .video_inputs = 4,
1929 /* .audio_inputs= 1, */
1930 .svhs = 2,
1931 .gpiomask = 0x00,
1932 .muxsel = MUXSEL(2, 3, 1, 1),
1933 .needs_tvaudio = 1,
1934 .no_msp34xx = 1,
1935 .pll = PLL_28,
1936 .tuner_type = TUNER_PHILIPS_PAL,
1937 .tuner_addr = ADDR_UNSET,
1938 /* Notes:
1939 - card lacks subsystem ID
1940 - stereo variant w/ daughter board with tda9874a @0xb0
1941 - Audio Routing:
1942 always from tda9874 independent of GPIO (?)
1943 external line in: unknown
1944 - Other chips: em78p156elp @ 0x96 (probably IR remote control)
1945 hef4053 (instead 4052) for unknown function
1946 */
1947 },
1948 [BTTV_BOARD_PACETV] = {
1949 .name = "Pace TV & Radio Card",
1950 .video_inputs = 4,
1951 /* .audio_inputs= 1, */
1952 .svhs = 2,
1953 /* Tuner, CVid, SVid, CVid over SVid connector */
1954 .muxsel = MUXSEL(2, 3, 1, 1),
1955 .gpiomask = 0,
1956 .no_tda7432 = 1,
1957 .tuner_type = TUNER_PHILIPS_PAL_I,
1958 .tuner_addr = ADDR_UNSET,
1959 .has_radio = 1,
1960 .pll = PLL_28,
1961 /* Bt878, Bt832, FI1246 tuner; no pci subsystem id
1962 only internal line out: (4pin header) RGGL
1963 Radio must be decoded by msp3410d (not routed through)*/
1964 /*
1965 .digital_mode = DIGITAL_MODE_CAMERA, todo!
1966 */
1967 },
1968 [BTTV_BOARD_IVC200] = {
1969 /* Chris Willing <chris@vislab.usyd.edu.au> */
1970 .name = "IVC-200",
1971 .video_inputs = 1,
1972 /* .audio_inputs= 0, */
1973 .tuner_type = TUNER_ABSENT,
1974 .tuner_addr = ADDR_UNSET,
1975 .svhs = NO_SVHS,
1976 .gpiomask = 0xdf,
1977 .muxsel = MUXSEL(2),
1978 .pll = PLL_28,
1979 },
1980 [BTTV_BOARD_IVCE8784] = {
1981 .name = "IVCE-8784",
1982 .video_inputs = 1,
1983 /* .audio_inputs= 0, */
1984 .tuner_type = TUNER_ABSENT,
1985 .tuner_addr = ADDR_UNSET,
1986 .svhs = NO_SVHS,
1987 .gpiomask = 0xdf,
1988 .muxsel = MUXSEL(2),
1989 .pll = PLL_28,
1990 },
1991 [BTTV_BOARD_XGUARD] = {
1992 .name = "Grand X-Guard / Trust 814PCI",
1993 .video_inputs = 16,
1994 /* .audio_inputs= 0, */
1995 .svhs = NO_SVHS,
1996 .tuner_type = TUNER_ABSENT,
1997 .tuner_addr = ADDR_UNSET,
1998 .gpiomask2 = 0xff,
1999 .muxsel = MUXSEL(2,2,2,2, 3,3,3,3, 1,1,1,1, 0,0,0,0),
2000 .muxsel_hook = xguard_muxsel,
2001 .no_msp34xx = 1,
2002 .no_tda7432 = 1,
2003 .pll = PLL_28,
2004 },
2005
2006 /* ---- card 0x68 ---------------------------------- */
2007 [BTTV_BOARD_NEBULA_DIGITV] = {
2008 .name = "Nebula Electronics DigiTV",
2009 .video_inputs = 1,
2010 .svhs = NO_SVHS,
2011 .muxsel = MUXSEL(2, 3, 1, 0),
2012 .no_msp34xx = 1,
2013 .no_tda7432 = 1,
2014 .pll = PLL_28,
2015 .tuner_type = TUNER_ABSENT,
2016 .tuner_addr = ADDR_UNSET,
2017 .has_dvb = 1,
2018 .has_remote = 1,
2019 .gpiomask = 0x1b,
2020 .no_gpioirq = 1,
2021 },
2022 [BTTV_BOARD_PV143] = {
2023 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */
2024 .name = "ProVideo PV143",
2025 .video_inputs = 4,
2026 /* .audio_inputs= 0, */
2027 .svhs = NO_SVHS,
2028 .gpiomask = 0,
2029 .muxsel = MUXSEL(2, 3, 1, 0),
2030 .gpiomux = { 0 },
2031 .needs_tvaudio = 0,
2032 .no_msp34xx = 1,
2033 .pll = PLL_28,
2034 .tuner_type = TUNER_ABSENT,
2035 .tuner_addr = ADDR_UNSET,
2036 },
2037 [BTTV_BOARD_VD009X1_VD011_MINIDIN] = {
2038 /* M.Klahr@phytec.de */
2039 .name = "PHYTEC VD-009-X1 VD-011 MiniDIN (bt878)",
2040 .video_inputs = 4,
2041 /* .audio_inputs= 0, */
2042 .svhs = 3,
2043 .gpiomask = 0x00,
2044 .muxsel = MUXSEL(2, 3, 1, 0),
2045 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2046 .needs_tvaudio = 0,
2047 .pll = PLL_28,
2048 .tuner_type = TUNER_ABSENT,
2049 .tuner_addr = ADDR_UNSET,
2050 },
2051 [BTTV_BOARD_VD009X1_VD011_COMBI] = {
2052 .name = "PHYTEC VD-009-X1 VD-011 Combi (bt878)",
2053 .video_inputs = 4,
2054 /* .audio_inputs= 0, */
2055 .svhs = 3,
2056 .gpiomask = 0x00,
2057 .muxsel = MUXSEL(2, 3, 1, 1),
2058 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2059 .needs_tvaudio = 0,
2060 .pll = PLL_28,
2061 .tuner_type = TUNER_ABSENT,
2062 .tuner_addr = ADDR_UNSET,
2063 },
2064
2065 /* ---- card 0x6c ---------------------------------- */
2066 [BTTV_BOARD_VD009_MINIDIN] = {
2067 .name = "PHYTEC VD-009 MiniDIN (bt878)",
2068 .video_inputs = 10,
2069 /* .audio_inputs= 0, */
2070 .svhs = 9,
2071 .gpiomask = 0x00,
2072 .gpiomask2 = 0x03, /* used for external vodeo mux */
2073 .muxsel = MUXSEL(2, 2, 2, 2, 3, 3, 3, 3, 1, 0),
2074 .muxsel_hook = phytec_muxsel,
2075 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2076 .needs_tvaudio = 1,
2077 .pll = PLL_28,
2078 .tuner_type = TUNER_ABSENT,
2079 .tuner_addr = ADDR_UNSET,
2080 },
2081 [BTTV_BOARD_VD009_COMBI] = {
2082 .name = "PHYTEC VD-009 Combi (bt878)",
2083 .video_inputs = 10,
2084 /* .audio_inputs= 0, */
2085 .svhs = 9,
2086 .gpiomask = 0x00,
2087 .gpiomask2 = 0x03, /* used for external vodeo mux */
2088 .muxsel = MUXSEL(2, 2, 2, 2, 3, 3, 3, 3, 1, 1),
2089 .muxsel_hook = phytec_muxsel,
2090 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2091 .needs_tvaudio = 1,
2092 .pll = PLL_28,
2093 .tuner_type = TUNER_ABSENT,
2094 .tuner_addr = ADDR_UNSET,
2095 },
2096 [BTTV_BOARD_IVC100] = {
2097 .name = "IVC-100",
2098 .video_inputs = 4,
2099 /* .audio_inputs= 0, */
2100 .tuner_type = TUNER_ABSENT,
2101 .tuner_addr = ADDR_UNSET,
2102 .svhs = NO_SVHS,
2103 .gpiomask = 0xdf,
2104 .muxsel = MUXSEL(2, 3, 1, 0),
2105 .pll = PLL_28,
2106 },
2107 [BTTV_BOARD_IVC120] = {
2108 /* IVC-120G - Alan Garfield <alan@fromorbit.com> */
2109 .name = "IVC-120G",
2110 .video_inputs = 16,
2111 /* .audio_inputs= 0, */
2112 .tuner_type = TUNER_ABSENT,
2113 .tuner_addr = ADDR_UNSET,
2114 .svhs = NO_SVHS, /* card has no svhs */
2115 .needs_tvaudio = 0,
2116 .no_msp34xx = 1,
2117 .no_tda7432 = 1,
2118 .gpiomask = 0x00,
2119 .muxsel = MUXSEL(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
2120 .muxsel_hook = ivc120_muxsel,
2121 .pll = PLL_28,
2122 },
2123
2124 /* ---- card 0x70 ---------------------------------- */
2125 [BTTV_BOARD_PC_HDTV] = {
2126 .name = "pcHDTV HD-2000 TV",
2127 .video_inputs = 4,
2128 /* .audio_inputs= 1, */
2129 .svhs = 2,
2130 .muxsel = MUXSEL(2, 3, 1, 0),
2131 .tuner_type = TUNER_PHILIPS_FCV1236D,
2132 .tuner_addr = ADDR_UNSET,
2133 .has_dvb = 1,
2134 },
2135 [BTTV_BOARD_TWINHAN_DST] = {
2136 .name = "Twinhan DST + clones",
2137 .no_msp34xx = 1,
2138 .no_tda7432 = 1,
2139 .tuner_type = TUNER_ABSENT,
2140 .tuner_addr = ADDR_UNSET,
2141 .no_video = 1,
2142 .has_dvb = 1,
2143 },
2144 [BTTV_BOARD_WINFASTVC100] = {
2145 .name = "Winfast VC100",
2146 .video_inputs = 3,
2147 /* .audio_inputs= 0, */
2148 .svhs = 1,
2149 /* Vid In, SVid In, Vid over SVid in connector */
2150 .muxsel = MUXSEL(3, 1, 1, 3),
2151 .no_msp34xx = 1,
2152 .no_tda7432 = 1,
2153 .tuner_type = TUNER_ABSENT,
2154 .tuner_addr = ADDR_UNSET,
2155 .pll = PLL_28,
2156 },
2157 [BTTV_BOARD_TEV560] = {
2158 .name = "Teppro TEV-560/InterVision IV-560",
2159 .video_inputs = 3,
2160 /* .audio_inputs= 1, */
2161 .svhs = 2,
2162 .gpiomask = 3,
2163 .muxsel = MUXSEL(2, 3, 1, 1),
2164 .gpiomux = { 1, 1, 1, 1 },
2165 .needs_tvaudio = 1,
2166 .tuner_type = TUNER_PHILIPS_PAL,
2167 .tuner_addr = ADDR_UNSET,
2168 .pll = PLL_35,
2169 },
2170
2171 /* ---- card 0x74 ---------------------------------- */
2172 [BTTV_BOARD_SIMUS_GVC1100] = {
2173 .name = "SIMUS GVC1100",
2174 .video_inputs = 4,
2175 /* .audio_inputs= 0, */
2176 .svhs = NO_SVHS,
2177 .tuner_type = TUNER_ABSENT,
2178 .tuner_addr = ADDR_UNSET,
2179 .pll = PLL_28,
2180 .muxsel = MUXSEL(2, 2, 2, 2),
2181 .gpiomask = 0x3F,
2182 .muxsel_hook = gvc1100_muxsel,
2183 },
2184 [BTTV_BOARD_NGSTV_PLUS] = {
2185 /* Carlos Silva r3pek@r3pek.homelinux.org || card 0x75 */
2186 .name = "NGS NGSTV+",
2187 .video_inputs = 3,
2188 .svhs = 2,
2189 .gpiomask = 0x008007,
2190 .muxsel = MUXSEL(2, 3, 0, 0),
2191 .gpiomux = { 0, 0, 0, 0 },
2192 .gpiomute = 0x000003,
2193 .pll = PLL_28,
2194 .tuner_type = TUNER_PHILIPS_PAL,
2195 .tuner_addr = ADDR_UNSET,
2196 .has_remote = 1,
2197 },
2198 [BTTV_BOARD_LMLBT4] = {
2199 /* http://linuxmedialabs.com */
2200 .name = "LMLBT4",
2201 .video_inputs = 4, /* IN1,IN2,IN3,IN4 */
2202 /* .audio_inputs= 0, */
2203 .svhs = NO_SVHS,
2204 .muxsel = MUXSEL(2, 3, 1, 0),
2205 .no_msp34xx = 1,
2206 .no_tda7432 = 1,
2207 .needs_tvaudio = 0,
2208 .tuner_type = TUNER_ABSENT,
2209 .tuner_addr = ADDR_UNSET,
2210 },
2211 [BTTV_BOARD_TEKRAM_M205] = {
2212 /* Helmroos Harri <harri.helmroos@pp.inet.fi> */
2213 .name = "Tekram M205 PRO",
2214 .video_inputs = 3,
2215 /* .audio_inputs= 1, */
2216 .tuner_type = TUNER_PHILIPS_PAL,
2217 .tuner_addr = ADDR_UNSET,
2218 .svhs = 2,
2219 .needs_tvaudio = 0,
2220 .gpiomask = 0x68,
2221 .muxsel = MUXSEL(2, 3, 1),
2222 .gpiomux = { 0x68, 0x68, 0x61, 0x61 },
2223 .pll = PLL_28,
2224 },
2225
2226 /* ---- card 0x78 ---------------------------------- */
2227 [BTTV_BOARD_CONTVFMI] = {
2228 /* Javier Cendan Ares <jcendan@lycos.es> */
2229 /* bt878 TV + FM without subsystem ID */
2230 .name = "Conceptronic CONTVFMi",
2231 .video_inputs = 3,
2232 /* .audio_inputs= 1, */
2233 .svhs = 2,
2234 .gpiomask = 0x008007,
2235 .muxsel = MUXSEL(2, 3, 1, 1),
2236 .gpiomux = { 0, 1, 2, 2 },
2237 .gpiomute = 3,
2238 .needs_tvaudio = 0,
2239 .pll = PLL_28,
2240 .tuner_type = TUNER_PHILIPS_PAL,
2241 .tuner_addr = ADDR_UNSET,
2242 .has_remote = 1,
2243 .has_radio = 1,
2244 },
2245 [BTTV_BOARD_PICOLO_TETRA_CHIP] = {
2246 /*Eric DEBIEF <debief@telemsa.com>*/
2247 /*EURESYS Picolo Tetra : 4 Conexant Fusion 878A, no audio, video input set with analog multiplexers GPIO controlled*/
2248 /* adds picolo_tetra_muxsel(), picolo_tetra_init(), the following declaration strucure, and #define BTTV_BOARD_PICOLO_TETRA_CHIP*/
2249 /*0x79 in bttv.h*/
2250 .name = "Euresys Picolo Tetra",
2251 .video_inputs = 4,
2252 /* .audio_inputs= 0, */
2253 .svhs = NO_SVHS,
2254 .gpiomask = 0,
2255 .gpiomask2 = 0x3C<<16,/*Set the GPIO[18]->GPIO[21] as output pin.==> drive the video inputs through analog multiplexers*/
2256 .no_msp34xx = 1,
2257 .no_tda7432 = 1,
2258 /*878A input is always MUX0, see above.*/
2259 .muxsel = MUXSEL(2, 2, 2, 2),
2260 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2261 .pll = PLL_28,
2262 .needs_tvaudio = 0,
2263 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/
2264 .tuner_type = TUNER_ABSENT,
2265 .tuner_addr = ADDR_UNSET,
2266 },
2267 [BTTV_BOARD_SPIRIT_TV] = {
2268 /* Spirit TV Tuner from http://spiritmodems.com.au */
2269 /* Stafford Goodsell <surge@goliath.homeunix.org> */
2270 .name = "Spirit TV Tuner",
2271 .video_inputs = 3,
2272 /* .audio_inputs= 1, */
2273 .svhs = 2,
2274 .gpiomask = 0x0000000f,
2275 .muxsel = MUXSEL(2, 1, 1),
2276 .gpiomux = { 0x02, 0x00, 0x00, 0x00 },
2277 .tuner_type = TUNER_TEMIC_PAL,
2278 .tuner_addr = ADDR_UNSET,
2279 .no_msp34xx = 1,
2280 },
2281 [BTTV_BOARD_AVDVBT_771] = {
2282 /* Wolfram Joost <wojo@frokaschwei.de> */
2283 .name = "AVerMedia AVerTV DVB-T 771",
2284 .video_inputs = 2,
2285 .svhs = 1,
2286 .tuner_type = TUNER_ABSENT,
2287 .tuner_addr = ADDR_UNSET,
2288 .muxsel = MUXSEL(3, 3),
2289 .no_msp34xx = 1,
2290 .no_tda7432 = 1,
2291 .pll = PLL_28,
2292 .has_dvb = 1,
2293 .no_gpioirq = 1,
2294 .has_remote = 1,
2295 },
2296 /* ---- card 0x7c ---------------------------------- */
2297 [BTTV_BOARD_AVDVBT_761] = {
2298 /* Matt Jesson <dvb@jesson.eclipse.co.uk> */
2299 /* Based on the Nebula card data - added remote and new card number - BTTV_BOARD_AVDVBT_761, see also ir-kbd-gpio.c */
2300 .name = "AverMedia AverTV DVB-T 761",
2301 .video_inputs = 2,
2302 .svhs = 1,
2303 .muxsel = MUXSEL(3, 1, 2, 0), /* Comp0, S-Video, ?, ? */
2304 .no_msp34xx = 1,
2305 .no_tda7432 = 1,
2306 .pll = PLL_28,
2307 .tuner_type = TUNER_ABSENT,
2308 .tuner_addr = ADDR_UNSET,
2309 .has_dvb = 1,
2310 .no_gpioirq = 1,
2311 .has_remote = 1,
2312 },
2313 [BTTV_BOARD_MATRIX_VISIONSQ] = {
2314 /* andre.schwarz@matrix-vision.de */
2315 .name = "MATRIX Vision Sigma-SQ",
2316 .video_inputs = 16,
2317 /* .audio_inputs= 0, */
2318 .svhs = NO_SVHS,
2319 .gpiomask = 0x0,
2320 .muxsel = MUXSEL(2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3),
2321 .muxsel_hook = sigmaSQ_muxsel,
2322 .gpiomux = { 0 },
2323 .no_msp34xx = 1,
2324 .pll = PLL_28,
2325 .tuner_type = TUNER_ABSENT,
2326 .tuner_addr = ADDR_UNSET,
2327 },
2328 [BTTV_BOARD_MATRIX_VISIONSLC] = {
2329 /* andre.schwarz@matrix-vision.de */
2330 .name = "MATRIX Vision Sigma-SLC",
2331 .video_inputs = 4,
2332 /* .audio_inputs= 0, */
2333 .svhs = NO_SVHS,
2334 .gpiomask = 0x0,
2335 .muxsel = MUXSEL(2, 2, 2, 2),
2336 .muxsel_hook = sigmaSLC_muxsel,
2337 .gpiomux = { 0 },
2338 .no_msp34xx = 1,
2339 .pll = PLL_28,
2340 .tuner_type = TUNER_ABSENT,
2341 .tuner_addr = ADDR_UNSET,
2342 },
2343 /* BTTV_BOARD_APAC_VIEWCOMP */
2344 [BTTV_BOARD_APAC_VIEWCOMP] = {
2345 /* Attila Kondoros <attila.kondoros@chello.hu> */
2346 /* bt878 TV + FM 0x00000000 subsystem ID */
2347 .name = "APAC Viewcomp 878(AMAX)",
2348 .video_inputs = 2,
2349 /* .audio_inputs= 1, */
2350 .svhs = NO_SVHS,
2351 .gpiomask = 0xFF,
2352 .muxsel = MUXSEL(2, 3, 1, 1),
2353 .gpiomux = { 2, 0, 0, 0 },
2354 .gpiomute = 10,
2355 .needs_tvaudio = 0,
2356 .pll = PLL_28,
2357 .tuner_type = TUNER_PHILIPS_PAL,
2358 .tuner_addr = ADDR_UNSET,
2359 .has_remote = 1, /* miniremote works, see ir-kbd-gpio.c */
2360 .has_radio = 1, /* not every card has radio */
2361 },
2362
2363 /* ---- card 0x80 ---------------------------------- */
2364 [BTTV_BOARD_DVICO_DVBT_LITE] = {
2365 /* Chris Pascoe <c.pascoe@itee.uq.edu.au> */
2366 .name = "DViCO FusionHDTV DVB-T Lite",
2367 .no_msp34xx = 1,
2368 .no_tda7432 = 1,
2369 .pll = PLL_28,
2370 .no_video = 1,
2371 .has_dvb = 1,
2372 .tuner_type = TUNER_ABSENT,
2373 .tuner_addr = ADDR_UNSET,
2374 },
2375 [BTTV_BOARD_VGEAR_MYVCD] = {
2376 /* Steven <photon38@pchome.com.tw> */
2377 .name = "V-Gear MyVCD",
2378 .video_inputs = 3,
2379 /* .audio_inputs= 1, */
2380 .svhs = 2,
2381 .gpiomask = 0x3f,
2382 .muxsel = MUXSEL(2, 3, 1, 0),
2383 .gpiomux = {0x31, 0x31, 0x31, 0x31 },
2384 .gpiomute = 0x31,
2385 .no_msp34xx = 1,
2386 .pll = PLL_28,
2387 .tuner_type = TUNER_PHILIPS_NTSC_M,
2388 .tuner_addr = ADDR_UNSET,
2389 .has_radio = 0,
2390 },
2391 [BTTV_BOARD_SUPER_TV] = {
2392 /* Rick C <cryptdragoon@gmail.com> */
2393 .name = "Super TV Tuner",
2394 .video_inputs = 4,
2395 /* .audio_inputs= 1, */
2396 .svhs = 2,
2397 .muxsel = MUXSEL(2, 3, 1, 0),
2398 .tuner_type = TUNER_PHILIPS_NTSC,
2399 .tuner_addr = ADDR_UNSET,
2400 .gpiomask = 0x008007,
2401 .gpiomux = { 0, 0x000001,0,0 },
2402 .needs_tvaudio = 1,
2403 .has_radio = 1,
2404 },
2405 [BTTV_BOARD_TIBET_CS16] = {
2406 /* Chris Fanning <video4linux@haydon.net> */
2407 .name = "Tibet Systems 'Progress DVR' CS16",
2408 .video_inputs = 16,
2409 /* .audio_inputs= 0, */
2410 .svhs = NO_SVHS,
2411 .muxsel = MUXSEL(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
2412 .pll = PLL_28,
2413 .no_msp34xx = 1,
2414 .no_tda7432 = 1,
2415 .tuner_type = TUNER_ABSENT,
2416 .tuner_addr = ADDR_UNSET,
2417 .muxsel_hook = tibetCS16_muxsel,
2418 },
2419 [BTTV_BOARD_KODICOM_4400R] = {
2420 /* Bill Brack <wbrack@mmm.com.hk> */
2421 /*
2422 * Note that, because of the card's wiring, the "master"
2423 * BT878A chip (i.e. the one which controls the analog switch
2424 * and must use this card type) is the 2nd one detected. The
2425 * other 3 chips should use card type 0x85, whose description
2426 * follows this one. There is a EEPROM on the card (which is
2427 * connected to the I2C of one of those other chips), but is
2428 * not currently handled. There is also a facility for a
2429 * "monitor", which is also not currently implemented.
2430 */
2431 .name = "Kodicom 4400R (master)",
2432 .video_inputs = 16,
2433 /* .audio_inputs= 0, */
2434 .tuner_type = TUNER_ABSENT,
2435 .tuner_addr = ADDR_UNSET,
2436 .svhs = NO_SVHS,
2437 /* GPIO bits 0-9 used for analog switch:
2438 * 00 - 03: camera selector
2439 * 04 - 06: channel (controller) selector
2440 * 07: data (1->on, 0->off)
2441 * 08: strobe
2442 * 09: reset
2443 * bit 16 is input from sync separator for the channel
2444 */
2445 .gpiomask = 0x0003ff,
2446 .no_gpioirq = 1,
2447 .muxsel = MUXSEL(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
2448 .pll = PLL_28,
2449 .no_msp34xx = 1,
2450 .no_tda7432 = 1,
2451 .muxsel_hook = kodicom4400r_muxsel,
2452 },
2453 [BTTV_BOARD_KODICOM_4400R_SL] = {
2454 /* Bill Brack <wbrack@mmm.com.hk> */
2455 /* Note that, for reasons unknown, the "master" BT878A chip (i.e. the
2456 * one which controls the analog switch, and must use the card type)
2457 * is the 2nd one detected. The other 3 chips should use this card
2458 * type
2459 */
2460 .name = "Kodicom 4400R (slave)",
2461 .video_inputs = 16,
2462 /* .audio_inputs= 0, */
2463 .tuner_type = TUNER_ABSENT,
2464 .tuner_addr = ADDR_UNSET,
2465 .svhs = NO_SVHS,
2466 .gpiomask = 0x010000,
2467 .no_gpioirq = 1,
2468 .muxsel = MUXSEL(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
2469 .pll = PLL_28,
2470 .no_msp34xx = 1,
2471 .no_tda7432 = 1,
2472 .muxsel_hook = kodicom4400r_muxsel,
2473 },
2474 /* ---- card 0x86---------------------------------- */
2475 [BTTV_BOARD_ADLINK_RTV24] = {
2476 /* Michael Henson <mhenson@clarityvi.com> */
2477 /* Adlink RTV24 with special unlock codes */
2478 .name = "Adlink RTV24",
2479 .video_inputs = 4,
2480 /* .audio_inputs= 1, */
2481 .svhs = 2,
2482 .muxsel = MUXSEL(2, 3, 1, 0),
2483 .tuner_type = UNSET,
2484 .tuner_addr = ADDR_UNSET,
2485 .pll = PLL_28,
2486 },
2487 /* ---- card 0x87---------------------------------- */
2488 [BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE] = {
2489 /* Michael Krufky <mkrufky@m1k.net> */
2490 .name = "DViCO FusionHDTV 5 Lite",
2491 .tuner_type = TUNER_LG_TDVS_H06XF, /* TDVS-H064F */
2492 .tuner_addr = ADDR_UNSET,
2493 .video_inputs = 3,
2494 /* .audio_inputs= 1, */
2495 .svhs = 2,
2496 .muxsel = MUXSEL(2, 3, 1),
2497 .gpiomask = 0x00e00007,
2498 .gpiomux = { 0x00400005, 0, 0x00000001, 0 },
2499 .gpiomute = 0x00c00007,
2500 .no_msp34xx = 1,
2501 .no_tda7432 = 1,
2502 .has_dvb = 1,
2503 },
2504 /* ---- card 0x88---------------------------------- */
2505 [BTTV_BOARD_ACORP_Y878F] = {
2506 /* Mauro Carvalho Chehab <mchehab@infradead.org> */
2507 .name = "Acorp Y878F",
2508 .video_inputs = 3,
2509 /* .audio_inputs= 1, */
2510 .svhs = 2,
2511 .gpiomask = 0x01fe00,
2512 .muxsel = MUXSEL(2, 3, 1, 1),
2513 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
2514 .gpiomute = 0x002000,
2515 .needs_tvaudio = 1,
2516 .pll = PLL_28,
2517 .tuner_type = TUNER_YMEC_TVF66T5_B_DFF,
2518 .tuner_addr = 0xc1 >>1,
2519 .has_radio = 1,
2520 },
2521 /* ---- card 0x89 ---------------------------------- */
2522 [BTTV_BOARD_CONCEPTRONIC_CTVFMI2] = {
2523 .name = "Conceptronic CTVFMi v2",
2524 .video_inputs = 3,
2525 /* .audio_inputs= 1, */
2526 .svhs = 2,
2527 .gpiomask = 0x001c0007,
2528 .muxsel = MUXSEL(2, 3, 1, 1),
2529 .gpiomux = { 0, 1, 2, 2 },
2530 .gpiomute = 3,
2531 .needs_tvaudio = 0,
2532 .pll = PLL_28,
2533 .tuner_type = TUNER_TENA_9533_DI,
2534 .tuner_addr = ADDR_UNSET,
2535 .has_remote = 1,
2536 .has_radio = 1,
2537 },
2538 /* ---- card 0x8a ---------------------------------- */
2539 [BTTV_BOARD_PV_BT878P_2E] = {
2540 .name = "Prolink Pixelview PV-BT878P+ (Rev.2E)",
2541 .video_inputs = 5,
2542 /* .audio_inputs= 1, */
2543 .svhs = 3,
2544 .has_dig_in = 1,
2545 .gpiomask = 0x01fe00,
2546 .muxsel = MUXSEL(2, 3, 1, 1, 0), /* in 4 is digital */
2547 /* .digital_mode= DIGITAL_MODE_CAMERA, */
2548 .gpiomux = { 0x00400, 0x10400, 0x04400, 0x80000 },
2549 .gpiomute = 0x12400,
2550 .no_msp34xx = 1,
2551 .pll = PLL_28,
2552 .tuner_type = TUNER_LG_PAL_FM,
2553 .tuner_addr = ADDR_UNSET,
2554 .has_remote = 1,
2555 },
2556 /* ---- card 0x8b ---------------------------------- */
2557 [BTTV_BOARD_PV_M4900] = {
2558 /* Sérgio Fortier <sergiofortier@yahoo.com.br> */
2559 .name = "Prolink PixelView PlayTV MPEG2 PV-M4900",
2560 .video_inputs = 3,
2561 /* .audio_inputs= 1, */
2562 .svhs = 2,
2563 .gpiomask = 0x3f,
2564 .muxsel = MUXSEL(2, 3, 1, 1),
2565 .gpiomux = { 0x21, 0x20, 0x24, 0x2c },
2566 .gpiomute = 0x29,
2567 .no_msp34xx = 1,
2568 .pll = PLL_28,
2569 .tuner_type = TUNER_YMEC_TVF_5533MF,
2570 .tuner_addr = ADDR_UNSET,
2571 .has_radio = 1,
2572 .has_remote = 1,
2573 },
2574 /* ---- card 0x8c ---------------------------------- */
2575 /* Has four Bt878 chips behind a PCI bridge, each chip has:
2576 one external BNC composite input (mux 2)
2577 three internal composite inputs (unknown muxes)
2578 an 18-bit stereo A/D (CS5331A), which has:
2579 one external stereo unblanced (RCA) audio connection
2580 one (or 3?) internal stereo balanced (XLR) audio connection
2581 input is selected via gpio to a 14052B mux
2582 (mask=0x300, unbal=0x000, bal=0x100, ??=0x200,0x300)
2583 gain is controlled via an X9221A chip on the I2C bus @0x28
2584 sample rate is controlled via gpio to an MK1413S
2585 (mask=0x3, 32kHz=0x0, 44.1kHz=0x1, 48kHz=0x2, ??=0x3)
2586 There is neither a tuner nor an svideo input. */
2587 [BTTV_BOARD_OSPREY440] = {
2588 .name = "Osprey 440",
2589 .video_inputs = 4,
2590 /* .audio_inputs= 2, */
2591 .svhs = NO_SVHS,
2592 .muxsel = MUXSEL(2, 3, 0, 1), /* 3,0,1 are guesses */
2593 .gpiomask = 0x303,
2594 .gpiomute = 0x000, /* int + 32kHz */
2595 .gpiomux = { 0, 0, 0x000, 0x100},
2596 .pll = PLL_28,
2597 .tuner_type = TUNER_ABSENT,
2598 .tuner_addr = ADDR_UNSET,
2599 .no_msp34xx = 1,
2600 .no_tda7432 = 1,
2601 },
2602 /* ---- card 0x8d ---------------------------------- */
2603 [BTTV_BOARD_ASOUND_SKYEYE] = {
2604 .name = "Asound Skyeye PCTV",
2605 .video_inputs = 3,
2606 /* .audio_inputs= 1, */
2607 .svhs = 2,
2608 .gpiomask = 15,
2609 .muxsel = MUXSEL(2, 3, 1, 1),
2610 .gpiomux = { 2, 0, 0, 0 },
2611 .gpiomute = 1,
2612 .needs_tvaudio = 1,
2613 .pll = PLL_28,
2614 .tuner_type = TUNER_PHILIPS_NTSC,
2615 .tuner_addr = ADDR_UNSET,
2616 },
2617 /* ---- card 0x8e ---------------------------------- */
2618 [BTTV_BOARD_SABRENT_TVFM] = {
2619 .name = "Sabrent TV-FM (bttv version)",
2620 .video_inputs = 3,
2621 /* .audio_inputs= 1, */
2622 .svhs = 2,
2623 .gpiomask = 0x108007,
2624 .muxsel = MUXSEL(2, 3, 1, 1),
2625 .gpiomux = { 100000, 100002, 100002, 100000 },
2626 .no_msp34xx = 1,
2627 .no_tda7432 = 1,
2628 .pll = PLL_28,
2629 .tuner_type = TUNER_TNF_5335MF,
2630 .tuner_addr = ADDR_UNSET,
2631 .has_radio = 1,
2632 },
2633 /* ---- card 0x8f ---------------------------------- */
2634 [BTTV_BOARD_HAUPPAUGE_IMPACTVCB] = {
2635 .name = "Hauppauge ImpactVCB (bt878)",
2636 .video_inputs = 4,
2637 /* .audio_inputs= 0, */
2638 .svhs = NO_SVHS,
2639 .gpiomask = 0x0f, /* old: 7 */
2640 .muxsel = MUXSEL(0, 1, 3, 2), /* Composite 0-3 */
2641 .no_msp34xx = 1,
2642 .no_tda7432 = 1,
2643 .tuner_type = TUNER_ABSENT,
2644 .tuner_addr = ADDR_UNSET,
2645 },
2646 [BTTV_BOARD_MACHTV_MAGICTV] = {
2647 /* Julian Calaby <julian.calaby@gmail.com>
2648 * Slightly different from original MachTV definition (0x60)
2649
2650 * FIXME: RegSpy says gpiomask should be "0x001c800f", but it
2651 * stuffs up remote chip. Bug is a pin on the jaecs is not set
2652 * properly (methinks) causing no keyup bits being set */
2653
2654 .name = "MagicTV", /* rebranded MachTV */
2655 .video_inputs = 3,
2656 /* .audio_inputs= 1, */
2657 .svhs = 2,
2658 .gpiomask = 7,
2659 .muxsel = MUXSEL(2, 3, 1, 1),
2660 .gpiomux = { 0, 1, 2, 3 },
2661 .gpiomute = 4,
2662 .tuner_type = TUNER_TEMIC_4009FR5_PAL,
2663 .tuner_addr = ADDR_UNSET,
2664 .pll = PLL_28,
2665 .has_radio = 1,
2666 .has_remote = 1,
2667 },
2668 [BTTV_BOARD_SSAI_SECURITY] = {
2669 .name = "SSAI Security Video Interface",
2670 .video_inputs = 4,
2671 /* .audio_inputs= 0, */
2672 .svhs = NO_SVHS,
2673 .muxsel = MUXSEL(0, 1, 2, 3),
2674 .tuner_type = TUNER_ABSENT,
2675 .tuner_addr = ADDR_UNSET,
2676 },
2677 [BTTV_BOARD_SSAI_ULTRASOUND] = {
2678 .name = "SSAI Ultrasound Video Interface",
2679 .video_inputs = 2,
2680 /* .audio_inputs= 0, */
2681 .svhs = 1,
2682 .muxsel = MUXSEL(2, 0, 1, 3),
2683 .tuner_type = TUNER_ABSENT,
2684 .tuner_addr = ADDR_UNSET,
2685 },
2686 /* ---- card 0x94---------------------------------- */
2687 [BTTV_BOARD_DVICO_FUSIONHDTV_2] = {
2688 .name = "DViCO FusionHDTV 2",
2689 .tuner_type = TUNER_PHILIPS_FCV1236D,
2690 .tuner_addr = ADDR_UNSET,
2691 .video_inputs = 3,
2692 /* .audio_inputs= 1, */
2693 .svhs = 2,
2694 .muxsel = MUXSEL(2, 3, 1),
2695 .gpiomask = 0x00e00007,
2696 .gpiomux = { 0x00400005, 0, 0x00000001, 0 },
2697 .gpiomute = 0x00c00007,
2698 .no_msp34xx = 1,
2699 .no_tda7432 = 1,
2700 },
2701 /* ---- card 0x95---------------------------------- */
2702 [BTTV_BOARD_TYPHOON_TVTUNERPCI] = {
2703 .name = "Typhoon TV-Tuner PCI (50684)",
2704 .video_inputs = 3,
2705 /* .audio_inputs= 1, */
2706 .svhs = 2,
2707 .gpiomask = 0x3014f,
2708 .muxsel = MUXSEL(2, 3, 1, 1),
2709 .gpiomux = { 0x20001,0x10001, 0, 0 },
2710 .gpiomute = 10,
2711 .needs_tvaudio = 1,
2712 .pll = PLL_28,
2713 .tuner_type = TUNER_PHILIPS_PAL_I,
2714 .tuner_addr = ADDR_UNSET,
2715 },
2716 [BTTV_BOARD_GEOVISION_GV600] = {
2717 /* emhn@usb.ve */
2718 .name = "Geovision GV-600",
2719 .video_inputs = 16,
2720 /* .audio_inputs= 0, */
2721 .svhs = NO_SVHS,
2722 .gpiomask = 0x0,
2723 .muxsel = MUXSEL(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
2724 .muxsel_hook = geovision_muxsel,
2725 .gpiomux = { 0 },
2726 .no_msp34xx = 1,
2727 .pll = PLL_28,
2728 .tuner_type = TUNER_ABSENT,
2729 .tuner_addr = ADDR_UNSET,
2730 },
2731 [BTTV_BOARD_KOZUMI_KTV_01C] = {
2732 /* Mauro Lacy <mauro@lacy.com.ar>
2733 * Based on MagicTV and Conceptronic CONTVFMi */
2734
2735 .name = "Kozumi KTV-01C",
2736 .video_inputs = 3,
2737 /* .audio_inputs= 1, */
2738 .svhs = 2,
2739 .gpiomask = 0x008007,
2740 .muxsel = MUXSEL(2, 3, 1, 1),
2741 .gpiomux = { 0, 1, 2, 2 }, /* CONTVFMi */
2742 .gpiomute = 3, /* CONTVFMi */
2743 .needs_tvaudio = 0,
2744 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, /* TCL MK3 */
2745 .tuner_addr = ADDR_UNSET,
2746 .pll = PLL_28,
2747 .has_radio = 1,
2748 .has_remote = 1,
2749 },
2750 [BTTV_BOARD_ENLTV_FM_2] = {
2751 /* Encore TV Tuner Pro ENL TV-FM-2
2752 Mauro Carvalho Chehab <mchehab@infradead.org */
2753 .name = "Encore ENL TV-FM-2",
2754 .video_inputs = 3,
2755 /* .audio_inputs= 1, */
2756 .svhs = 2,
2757 /* bit 6 -> IR disabled
2758 bit 18/17 = 00 -> mute
2759 01 -> enable external audio input
2760 10 -> internal audio input (mono?)
2761 11 -> internal audio input
2762 */
2763 .gpiomask = 0x060040,
2764 .muxsel = MUXSEL(2, 3, 3),
2765 .gpiomux = { 0x60000, 0x60000, 0x20000, 0x20000 },
2766 .gpiomute = 0,
2767 .tuner_type = TUNER_TCL_MF02GIP_5N,
2768 .tuner_addr = ADDR_UNSET,
2769 .pll = PLL_28,
2770 .has_radio = 1,
2771 .has_remote = 1,
2772 },
2773 [BTTV_BOARD_VD012] = {
2774 /* D.Heer@Phytec.de */
2775 .name = "PHYTEC VD-012 (bt878)",
2776 .video_inputs = 4,
2777 /* .audio_inputs= 0, */
2778 .svhs = NO_SVHS,
2779 .gpiomask = 0x00,
2780 .muxsel = MUXSEL(0, 2, 3, 1),
2781 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2782 .needs_tvaudio = 0,
2783 .pll = PLL_28,
2784 .tuner_type = TUNER_ABSENT,
2785 .tuner_addr = ADDR_UNSET,
2786 },
2787 [BTTV_BOARD_VD012_X1] = {
2788 /* D.Heer@Phytec.de */
2789 .name = "PHYTEC VD-012-X1 (bt878)",
2790 .video_inputs = 4,
2791 /* .audio_inputs= 0, */
2792 .svhs = 3,
2793 .gpiomask = 0x00,
2794 .muxsel = MUXSEL(2, 3, 1),
2795 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2796 .needs_tvaudio = 0,
2797 .pll = PLL_28,
2798 .tuner_type = TUNER_ABSENT,
2799 .tuner_addr = ADDR_UNSET,
2800 },
2801 [BTTV_BOARD_VD012_X2] = {
2802 /* D.Heer@Phytec.de */
2803 .name = "PHYTEC VD-012-X2 (bt878)",
2804 .video_inputs = 4,
2805 /* .audio_inputs= 0, */
2806 .svhs = 3,
2807 .gpiomask = 0x00,
2808 .muxsel = MUXSEL(3, 2, 1),
2809 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2810 .needs_tvaudio = 0,
2811 .pll = PLL_28,
2812 .tuner_type = TUNER_ABSENT,
2813 .tuner_addr = ADDR_UNSET,
2814 },
2815 [BTTV_BOARD_GEOVISION_GV800S] = {
2816 /* Bruno Christo <bchristo@inf.ufsm.br>
2817 *
2818 * GeoVision GV-800(S) has 4 Conexant Fusion 878A:
2819 * 1 audio input per BT878A = 4 audio inputs
2820 * 4 video inputs per BT878A = 16 video inputs
2821 * This is the first BT878A chip of the GV-800(S). It's the
2822 * "master" chip and it controls the video inputs through an
2823 * analog multiplexer (a CD22M3494) via some GPIO pins. The
2824 * slaves should use card type 0x9e (following this one).
2825 * There is a EEPROM on the card which is currently not handled.
2826 * The audio input is not working yet.
2827 */
2828 .name = "Geovision GV-800(S) (master)",
2829 .video_inputs = 4,
2830 /* .audio_inputs= 1, */
2831 .tuner_type = TUNER_ABSENT,
2832 .tuner_addr = ADDR_UNSET,
2833 .svhs = NO_SVHS,
2834 .gpiomask = 0xf107f,
2835 .no_gpioirq = 1,
2836 .muxsel = MUXSEL(2, 2, 2, 2),
2837 .pll = PLL_28,
2838 .no_msp34xx = 1,
2839 .no_tda7432 = 1,
2840 .muxsel_hook = gv800s_muxsel,
2841 },
2842 [BTTV_BOARD_GEOVISION_GV800S_SL] = {
2843 /* Bruno Christo <bchristo@inf.ufsm.br>
2844 *
2845 * GeoVision GV-800(S) has 4 Conexant Fusion 878A:
2846 * 1 audio input per BT878A = 4 audio inputs
2847 * 4 video inputs per BT878A = 16 video inputs
2848 * The 3 other BT878A chips are "slave" chips of the GV-800(S)
2849 * and should use this card type.
2850 * The audio input is not working yet.
2851 */
2852 .name = "Geovision GV-800(S) (slave)",
2853 .video_inputs = 4,
2854 /* .audio_inputs= 1, */
2855 .tuner_type = TUNER_ABSENT,
2856 .tuner_addr = ADDR_UNSET,
2857 .svhs = NO_SVHS,
2858 .gpiomask = 0x00,
2859 .no_gpioirq = 1,
2860 .muxsel = MUXSEL(2, 2, 2, 2),
2861 .pll = PLL_28,
2862 .no_msp34xx = 1,
2863 .no_tda7432 = 1,
2864 .muxsel_hook = gv800s_muxsel,
2865 },
2866 [BTTV_BOARD_PV183] = {
2867 .name = "ProVideo PV183", /* 0x9f */
2868 .video_inputs = 2,
2869 /* .audio_inputs= 0, */
2870 .svhs = NO_SVHS,
2871 .gpiomask = 0,
2872 .muxsel = MUXSEL(2, 3),
2873 .gpiomux = { 0 },
2874 .needs_tvaudio = 0,
2875 .no_msp34xx = 1,
2876 .pll = PLL_28,
2877 .tuner_type = TUNER_ABSENT,
2878 .tuner_addr = ADDR_UNSET,
2879 },
2880};
2881
2882static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
2883
2884/* ----------------------------------------------------------------------- */
2885
2886static unsigned char eeprom_data[256];
2887
2888/*
2889 * identify card
2890 */
2891void __devinit bttv_idcard(struct bttv *btv)
2892{
2893 unsigned int gpiobits;
2894 int i,type;
2895
2896 /* read PCI subsystem ID */
2897 btv->cardid = btv->c.pci->subsystem_device << 16;
2898 btv->cardid |= btv->c.pci->subsystem_vendor;
2899
2900 if (0 != btv->cardid && 0xffffffff != btv->cardid) {
2901 /* look for the card */
2902 for (type = -1, i = 0; cards[i].id != 0; i++)
2903 if (cards[i].id == btv->cardid)
2904 type = i;
2905
2906 if (type != -1) {
2907 /* found it */
2908 printk(KERN_INFO "bttv%d: detected: %s [card=%d], "
2909 "PCI subsystem ID is %04x:%04x\n",
2910 btv->c.nr,cards[type].name,cards[type].cardnr,
2911 btv->cardid & 0xffff,
2912 (btv->cardid >> 16) & 0xffff);
2913 btv->c.type = cards[type].cardnr;
2914 } else {
2915 /* 404 */
2916 printk(KERN_INFO "bttv%d: subsystem: %04x:%04x (UNKNOWN)\n",
2917 btv->c.nr, btv->cardid & 0xffff,
2918 (btv->cardid >> 16) & 0xffff);
2919 printk(KERN_DEBUG "please mail id, board name and "
2920 "the correct card= insmod option to linux-media@vger.kernel.org\n");
2921 }
2922 }
2923
2924 /* let the user override the autodetected type */
2925 if (card[btv->c.nr] < bttv_num_tvcards)
2926 btv->c.type=card[btv->c.nr];
2927
2928 /* print which card config we are using */
2929 printk(KERN_INFO "bttv%d: using: %s [card=%d,%s]\n",btv->c.nr,
2930 bttv_tvcards[btv->c.type].name, btv->c.type,
2931 card[btv->c.nr] < bttv_num_tvcards
2932 ? "insmod option" : "autodetected");
2933
2934 /* overwrite gpio stuff ?? */
2935 if (UNSET == audioall && UNSET == audiomux[0])
2936 return;
2937
2938 if (UNSET != audiomux[0]) {
2939 gpiobits = 0;
2940 for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
2941 bttv_tvcards[btv->c.type].gpiomux[i] = audiomux[i];
2942 gpiobits |= audiomux[i];
2943 }
2944 } else {
2945 gpiobits = audioall;
2946 for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
2947 bttv_tvcards[btv->c.type].gpiomux[i] = audioall;
2948 }
2949 }
2950 bttv_tvcards[btv->c.type].gpiomask = (UNSET != gpiomask) ? gpiomask : gpiobits;
2951 printk(KERN_INFO "bttv%d: gpio config override: mask=0x%x, mux=",
2952 btv->c.nr,bttv_tvcards[btv->c.type].gpiomask);
2953 for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
2954 printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].gpiomux[i]);
2955 }
2956 printk("\n");
2957}
2958
2959/*
2960 * (most) board specific initialisations goes here
2961 */
2962
2963/* Some Modular Technology cards have an eeprom, but no subsystem ID */
2964static void identify_by_eeprom(struct bttv *btv, unsigned char eeprom_data[256])
2965{
2966 int type = -1;
2967
2968 if (0 == strncmp(eeprom_data,"GET MM20xPCTV",13))
2969 type = BTTV_BOARD_MODTEC_205;
2970 else if (0 == strncmp(eeprom_data+20,"Picolo",7))
2971 type = BTTV_BOARD_EURESYS_PICOLO;
2972 else if (eeprom_data[0] == 0x84 && eeprom_data[2]== 0)
2973 type = BTTV_BOARD_HAUPPAUGE; /* old bt848 */
2974
2975 if (-1 != type) {
2976 btv->c.type = type;
2977 printk("bttv%d: detected by eeprom: %s [card=%d]\n",
2978 btv->c.nr, bttv_tvcards[btv->c.type].name, btv->c.type);
2979 }
2980}
2981
2982static void flyvideo_gpio(struct bttv *btv)
2983{
2984 int gpio, has_remote, has_radio, is_capture_only;
2985 int is_lr90, has_tda9820_tda9821;
2986 int tuner_type = UNSET, ttype;
2987
2988 gpio_inout(0xffffff, 0);
2989 udelay(8); /* without this we would see the 0x1800 mask */
2990 gpio = gpio_read();
2991 /* FIXME: must restore OUR_EN ??? */
2992
2993 /* all cards provide GPIO info, some have an additional eeprom
2994 * LR50: GPIO coding can be found lower right CP1 .. CP9
2995 * CP9=GPIO23 .. CP1=GPIO15; when OPEN, the corresponding GPIO reads 1.
2996 * GPIO14-12: n.c.
2997 * LR90: GP9=GPIO23 .. GP1=GPIO15 (right above the bt878)
2998
2999 * lowest 3 bytes are remote control codes (no handshake needed)
3000 * xxxFFF: No remote control chip soldered
3001 * xxxF00(LR26/LR50), xxxFE0(LR90): Remote control chip (LVA001 or CF45) soldered
3002 * Note: Some bits are Audio_Mask !
3003 */
3004 ttype = (gpio & 0x0f0000) >> 16;
3005 switch (ttype) {
3006 case 0x0:
3007 tuner_type = 2; /* NTSC, e.g. TPI8NSR11P */
3008 break;
3009 case 0x2:
3010 tuner_type = 39; /* LG NTSC (newer TAPC series) TAPC-H701P */
3011 break;
3012 case 0x4:
3013 tuner_type = 5; /* Philips PAL TPI8PSB02P, TPI8PSB12P, TPI8PSB12D or FI1216, FM1216 */
3014 break;
3015 case 0x6:
3016 tuner_type = 37; /* LG PAL (newer TAPC series) TAPC-G702P */
3017 break;
3018 case 0xC:
3019 tuner_type = 3; /* Philips SECAM(+PAL) FQ1216ME or FI1216MF */
3020 break;
3021 default:
3022 printk(KERN_INFO "bttv%d: FlyVideo_gpio: unknown tuner type.\n", btv->c.nr);
3023 break;
3024 }
3025
3026 has_remote = gpio & 0x800000;
3027 has_radio = gpio & 0x400000;
3028 /* unknown 0x200000;
3029 * unknown2 0x100000; */
3030 is_capture_only = !(gpio & 0x008000); /* GPIO15 */
3031 has_tda9820_tda9821 = !(gpio & 0x004000);
3032 is_lr90 = !(gpio & 0x002000); /* else LR26/LR50 (LR38/LR51 f. capture only) */
3033 /*
3034 * gpio & 0x001000 output bit for audio routing */
3035
3036 if (is_capture_only)
3037 tuner_type = TUNER_ABSENT; /* No tuner present */
3038
3039 printk(KERN_INFO "bttv%d: FlyVideo Radio=%s RemoteControl=%s Tuner=%d gpio=0x%06x\n",
3040 btv->c.nr, has_radio ? "yes" : "no ",
3041 has_remote ? "yes" : "no ", tuner_type, gpio);
3042 printk(KERN_INFO "bttv%d: FlyVideo LR90=%s tda9821/tda9820=%s capture_only=%s\n",
3043 btv->c.nr, is_lr90 ? "yes" : "no ",
3044 has_tda9820_tda9821 ? "yes" : "no ",
3045 is_capture_only ? "yes" : "no ");
3046
3047 if (tuner_type != UNSET) /* only set if known tuner autodetected, else let insmod option through */
3048 btv->tuner_type = tuner_type;
3049 btv->has_radio = has_radio;
3050
3051 /* LR90 Audio Routing is done by 2 hef4052, so Audio_Mask has 4 bits: 0x001c80
3052 * LR26/LR50 only has 1 hef4052, Audio_Mask 0x000c00
3053 * Audio options: from tuner, from tda9821/tda9821(mono,stereo,sap), from tda9874, ext., mute */
3054 if (has_tda9820_tda9821)
3055 btv->audio_mode_gpio = lt9415_audio;
3056 /* todo: if(has_tda9874) btv->audio_mode_gpio = fv2000s_audio; */
3057}
3058
3059static int miro_tunermap[] = { 0,6,2,3, 4,5,6,0, 3,0,4,5, 5,2,16,1,
3060 14,2,17,1, 4,1,4,3, 1,2,16,1, 4,4,4,4 };
3061static int miro_fmtuner[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1,
3062 1,1,1,1, 1,1,1,0, 0,0,0,0, 0,1,0,0 };
3063
3064static void miro_pinnacle_gpio(struct bttv *btv)
3065{
3066 int id,msp,gpio;
3067 char *info;
3068
3069 gpio_inout(0xffffff, 0);
3070 gpio = gpio_read();
3071 id = ((gpio>>10) & 63) -1;
3072 msp = bttv_I2CRead(btv, I2C_ADDR_MSP3400, "MSP34xx");
3073 if (id < 32) {
3074 btv->tuner_type = miro_tunermap[id];
3075 if (0 == (gpio & 0x20)) {
3076 btv->has_radio = 1;
3077 if (!miro_fmtuner[id]) {
3078 btv->has_matchbox = 1;
3079 btv->mbox_we = (1<<6);
3080 btv->mbox_most = (1<<7);
3081 btv->mbox_clk = (1<<8);
3082 btv->mbox_data = (1<<9);
3083 btv->mbox_mask = (1<<6)|(1<<7)|(1<<8)|(1<<9);
3084 }
3085 } else {
3086 btv->has_radio = 0;
3087 }
3088 if (-1 != msp) {
3089 if (btv->c.type == BTTV_BOARD_MIRO)
3090 btv->c.type = BTTV_BOARD_MIROPRO;
3091 if (btv->c.type == BTTV_BOARD_PINNACLE)
3092 btv->c.type = BTTV_BOARD_PINNACLEPRO;
3093 }
3094 printk(KERN_INFO
3095 "bttv%d: miro: id=%d tuner=%d radio=%s stereo=%s\n",
3096 btv->c.nr, id+1, btv->tuner_type,
3097 !btv->has_radio ? "no" :
3098 (btv->has_matchbox ? "matchbox" : "fmtuner"),
3099 (-1 == msp) ? "no" : "yes");
3100 } else {
3101 /* new cards with microtune tuner */
3102 id = 63 - id;
3103 btv->has_radio = 0;
3104 switch (id) {
3105 case 1:
3106 info = "PAL / mono";
3107 btv->tda9887_conf = TDA9887_INTERCARRIER;
3108 break;
3109 case 2:
3110 info = "PAL+SECAM / stereo";
3111 btv->has_radio = 1;
3112 btv->tda9887_conf = TDA9887_QSS;
3113 break;
3114 case 3:
3115 info = "NTSC / stereo";
3116 btv->has_radio = 1;
3117 btv->tda9887_conf = TDA9887_QSS;
3118 break;
3119 case 4:
3120 info = "PAL+SECAM / mono";
3121 btv->tda9887_conf = TDA9887_QSS;
3122 break;
3123 case 5:
3124 info = "NTSC / mono";
3125 btv->tda9887_conf = TDA9887_INTERCARRIER;
3126 break;
3127 case 6:
3128 info = "NTSC / stereo";
3129 btv->tda9887_conf = TDA9887_INTERCARRIER;
3130 break;
3131 case 7:
3132 info = "PAL / stereo";
3133 btv->tda9887_conf = TDA9887_INTERCARRIER;
3134 break;
3135 default:
3136 info = "oops: unknown card";
3137 break;
3138 }
3139 if (-1 != msp)
3140 btv->c.type = BTTV_BOARD_PINNACLEPRO;
3141 printk(KERN_INFO
3142 "bttv%d: pinnacle/mt: id=%d info=\"%s\" radio=%s\n",
3143 btv->c.nr, id, info, btv->has_radio ? "yes" : "no");
3144 btv->tuner_type = TUNER_MT2032;
3145 }
3146}
3147
3148/* GPIO21 L: Buffer aktiv, H: Buffer inaktiv */
3149#define LM1882_SYNC_DRIVE 0x200000L
3150
3151static void init_ids_eagle(struct bttv *btv)
3152{
3153 gpio_inout(0xffffff,0xFFFF37);
3154 gpio_write(0x200020);
3155
3156 /* flash strobe inverter ?! */
3157 gpio_write(0x200024);
3158
3159 /* switch sync drive off */
3160 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
3161
3162 /* set BT848 muxel to 2 */
3163 btaor((2)<<5, ~(2<<5), BT848_IFORM);
3164}
3165
3166/* Muxsel helper for the IDS Eagle.
3167 * the eagles does not use the standard muxsel-bits but
3168 * has its own multiplexer */
3169static void eagle_muxsel(struct bttv *btv, unsigned int input)
3170{
3171 gpio_bits(3, input & 3);
3172
3173 /* composite */
3174 /* set chroma ADC to sleep */
3175 btor(BT848_ADC_C_SLEEP, BT848_ADC);
3176 /* set to composite video */
3177 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
3178 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
3179
3180 /* switch sync drive off */
3181 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
3182}
3183
3184static void gvc1100_muxsel(struct bttv *btv, unsigned int input)
3185{
3186 static const int masks[] = {0x30, 0x01, 0x12, 0x23};
3187 gpio_write(masks[input%4]);
3188}
3189
3190/* LMLBT4x initialization - to allow access to GPIO bits for sensors input and
3191 alarms output
3192
3193 GPIObit | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
3194 assignment | TI | O3|INx| O2| O1|IN4|IN3|IN2|IN1| | |
3195
3196 IN - sensor inputs, INx - sensor inputs and TI XORed together
3197 O1,O2,O3 - alarm outputs (relays)
3198
3199 OUT ENABLE 1 1 0 . 1 1 0 0 . 0 0 0 0 = 0x6C0
3200
3201*/
3202
3203static void init_lmlbt4x(struct bttv *btv)
3204{
3205 printk(KERN_DEBUG "LMLBT4x init\n");
3206 btwrite(0x000000, BT848_GPIO_REG_INP);
3207 gpio_inout(0xffffff, 0x0006C0);
3208 gpio_write(0x000000);
3209}
3210
3211static void sigmaSQ_muxsel(struct bttv *btv, unsigned int input)
3212{
3213 unsigned int inmux = input % 8;
3214 gpio_inout( 0xf, 0xf );
3215 gpio_bits( 0xf, inmux );
3216}
3217
3218static void sigmaSLC_muxsel(struct bttv *btv, unsigned int input)
3219{
3220 unsigned int inmux = input % 4;
3221 gpio_inout( 3<<9, 3<<9 );
3222 gpio_bits( 3<<9, inmux<<9 );
3223}
3224
3225static void geovision_muxsel(struct bttv *btv, unsigned int input)
3226{
3227 unsigned int inmux = input % 16;
3228 gpio_inout(0xf, 0xf);
3229 gpio_bits(0xf, inmux);
3230}
3231
3232/* ----------------------------------------------------------------------- */
3233
3234static void bttv_reset_audio(struct bttv *btv)
3235{
3236 /*
3237 * BT878A has a audio-reset register.
3238 * 1. This register is an audio reset function but it is in
3239 * function-0 (video capture) address space.
3240 * 2. It is enough to do this once per power-up of the card.
3241 * 3. There is a typo in the Conexant doc -- it is not at
3242 * 0x5B, but at 0x058. (B is an odd-number, obviously a typo!).
3243 * --//Shrikumar 030609
3244 */
3245 if (btv->id != 878)
3246 return;
3247
3248 if (bttv_debug)
3249 printk("bttv%d: BT878A ARESET\n",btv->c.nr);
3250 btwrite((1<<7), 0x058);
3251 udelay(10);
3252 btwrite( 0, 0x058);
3253}
3254
3255/* initialization part one -- before registering i2c bus */
3256void __devinit bttv_init_card1(struct bttv *btv)
3257{
3258 switch (btv->c.type) {
3259 case BTTV_BOARD_HAUPPAUGE:
3260 case BTTV_BOARD_HAUPPAUGE878:
3261 boot_msp34xx(btv,5);
3262 break;
3263 case BTTV_BOARD_VOODOOTV_200:
3264 case BTTV_BOARD_VOODOOTV_FM:
3265 boot_msp34xx(btv,20);
3266 break;
3267 case BTTV_BOARD_AVERMEDIA98:
3268 boot_msp34xx(btv,11);
3269 break;
3270 case BTTV_BOARD_HAUPPAUGEPVR:
3271 pvr_boot(btv);
3272 break;
3273 case BTTV_BOARD_TWINHAN_DST:
3274 case BTTV_BOARD_AVDVBT_771:
3275 case BTTV_BOARD_PINNACLESAT:
3276 btv->use_i2c_hw = 1;
3277 break;
3278 case BTTV_BOARD_ADLINK_RTV24:
3279 init_RTV24( btv );
3280 break;
3281
3282 }
3283 if (!bttv_tvcards[btv->c.type].has_dvb)
3284 bttv_reset_audio(btv);
3285}
3286
3287/* initialization part two -- after registering i2c bus */
3288void __devinit bttv_init_card2(struct bttv *btv)
3289{
3290 btv->tuner_type = UNSET;
3291
3292 if (BTTV_BOARD_UNKNOWN == btv->c.type) {
3293 bttv_readee(btv,eeprom_data,0xa0);
3294 identify_by_eeprom(btv,eeprom_data);
3295 }
3296
3297 switch (btv->c.type) {
3298 case BTTV_BOARD_MIRO:
3299 case BTTV_BOARD_MIROPRO:
3300 case BTTV_BOARD_PINNACLE:
3301 case BTTV_BOARD_PINNACLEPRO:
3302 /* miro/pinnacle */
3303 miro_pinnacle_gpio(btv);
3304 break;
3305 case BTTV_BOARD_FLYVIDEO_98:
3306 case BTTV_BOARD_MAXI:
3307 case BTTV_BOARD_LIFE_FLYKIT:
3308 case BTTV_BOARD_FLYVIDEO:
3309 case BTTV_BOARD_TYPHOON_TVIEW:
3310 case BTTV_BOARD_CHRONOS_VS2:
3311 case BTTV_BOARD_FLYVIDEO_98FM:
3312 case BTTV_BOARD_FLYVIDEO2000:
3313 case BTTV_BOARD_FLYVIDEO98EZ:
3314 case BTTV_BOARD_CONFERENCETV:
3315 case BTTV_BOARD_LIFETEC_9415:
3316 flyvideo_gpio(btv);
3317 break;
3318 case BTTV_BOARD_HAUPPAUGE:
3319 case BTTV_BOARD_HAUPPAUGE878:
3320 case BTTV_BOARD_HAUPPAUGEPVR:
3321 /* pick up some config infos from the eeprom */
3322 bttv_readee(btv,eeprom_data,0xa0);
3323 hauppauge_eeprom(btv);
3324 break;
3325 case BTTV_BOARD_AVERMEDIA98:
3326 case BTTV_BOARD_AVPHONE98:
3327 bttv_readee(btv,eeprom_data,0xa0);
3328 avermedia_eeprom(btv);
3329 break;
3330 case BTTV_BOARD_PXC200:
3331 init_PXC200(btv);
3332 break;
3333 case BTTV_BOARD_PICOLO_TETRA_CHIP:
3334 picolo_tetra_init(btv);
3335 break;
3336 case BTTV_BOARD_VHX:
3337 btv->has_radio = 1;
3338 btv->has_matchbox = 1;
3339 btv->mbox_we = 0x20;
3340 btv->mbox_most = 0;
3341 btv->mbox_clk = 0x08;
3342 btv->mbox_data = 0x10;
3343 btv->mbox_mask = 0x38;
3344 break;
3345 case BTTV_BOARD_VOBIS_BOOSTAR:
3346 case BTTV_BOARD_TERRATV:
3347 terratec_active_radio_upgrade(btv);
3348 break;
3349 case BTTV_BOARD_MAGICTVIEW061:
3350 if (btv->cardid == 0x3002144f) {
3351 btv->has_radio=1;
3352 printk("bttv%d: radio detected by subsystem id (CPH05x)\n",btv->c.nr);
3353 }
3354 break;
3355 case BTTV_BOARD_STB2:
3356 if (btv->cardid == 0x3060121a) {
3357 /* Fix up entry for 3DFX VoodooTV 100,
3358 which is an OEM STB card variant. */
3359 btv->has_radio=0;
3360 btv->tuner_type=TUNER_TEMIC_NTSC;
3361 }
3362 break;
3363 case BTTV_BOARD_OSPREY1x0:
3364 case BTTV_BOARD_OSPREY1x0_848:
3365 case BTTV_BOARD_OSPREY101_848:
3366 case BTTV_BOARD_OSPREY1x1:
3367 case BTTV_BOARD_OSPREY1x1_SVID:
3368 case BTTV_BOARD_OSPREY2xx:
3369 case BTTV_BOARD_OSPREY2x0_SVID:
3370 case BTTV_BOARD_OSPREY2x0:
3371 case BTTV_BOARD_OSPREY440:
3372 case BTTV_BOARD_OSPREY500:
3373 case BTTV_BOARD_OSPREY540:
3374 case BTTV_BOARD_OSPREY2000:
3375 bttv_readee(btv,eeprom_data,0xa0);
3376 osprey_eeprom(btv, eeprom_data);
3377 break;
3378 case BTTV_BOARD_IDS_EAGLE:
3379 init_ids_eagle(btv);
3380 break;
3381 case BTTV_BOARD_MODTEC_205:
3382 bttv_readee(btv,eeprom_data,0xa0);
3383 modtec_eeprom(btv);
3384 break;
3385 case BTTV_BOARD_LMLBT4:
3386 init_lmlbt4x(btv);
3387 break;
3388 case BTTV_BOARD_TIBET_CS16:
3389 tibetCS16_init(btv);
3390 break;
3391 case BTTV_BOARD_KODICOM_4400R:
3392 kodicom4400r_init(btv);
3393 break;
3394 case BTTV_BOARD_GEOVISION_GV800S:
3395 gv800s_init(btv);
3396 break;
3397 }
3398
3399 /* pll configuration */
3400 if (!(btv->id==848 && btv->revision==0x11)) {
3401 /* defaults from card list */
3402 if (PLL_28 == bttv_tvcards[btv->c.type].pll) {
3403 btv->pll.pll_ifreq=28636363;
3404 btv->pll.pll_crystal=BT848_IFORM_XT0;
3405 }
3406 if (PLL_35 == bttv_tvcards[btv->c.type].pll) {
3407 btv->pll.pll_ifreq=35468950;
3408 btv->pll.pll_crystal=BT848_IFORM_XT1;
3409 }
3410 /* insmod options can override */
3411 switch (pll[btv->c.nr]) {
3412 case 0: /* none */
3413 btv->pll.pll_crystal = 0;
3414 btv->pll.pll_ifreq = 0;
3415 btv->pll.pll_ofreq = 0;
3416 break;
3417 case 1: /* 28 MHz */
3418 case 28:
3419 btv->pll.pll_ifreq = 28636363;
3420 btv->pll.pll_ofreq = 0;
3421 btv->pll.pll_crystal = BT848_IFORM_XT0;
3422 break;
3423 case 2: /* 35 MHz */
3424 case 35:
3425 btv->pll.pll_ifreq = 35468950;
3426 btv->pll.pll_ofreq = 0;
3427 btv->pll.pll_crystal = BT848_IFORM_XT1;
3428 break;
3429 }
3430 }
3431 btv->pll.pll_current = -1;
3432
3433 /* tuner configuration (from card list / autodetect / insmod option) */
3434 if (UNSET != bttv_tvcards[btv->c.type].tuner_type)
3435 if (UNSET == btv->tuner_type)
3436 btv->tuner_type = bttv_tvcards[btv->c.type].tuner_type;
3437 if (UNSET != tuner[btv->c.nr])
3438 btv->tuner_type = tuner[btv->c.nr];
3439
3440 if (btv->tuner_type == TUNER_ABSENT)
3441 printk(KERN_INFO "bttv%d: tuner absent\n", btv->c.nr);
3442 else if(btv->tuner_type == UNSET)
3443 printk(KERN_WARNING "bttv%d: tuner type unset\n", btv->c.nr);
3444 else
3445 printk(KERN_INFO "bttv%d: tuner type=%d\n", btv->c.nr,
3446 btv->tuner_type);
3447
3448 if (autoload != UNSET) {
3449 printk(KERN_WARNING "bttv%d: the autoload option is obsolete.\n", btv->c.nr);
3450 printk(KERN_WARNING "bttv%d: use option msp3400, tda7432 or tvaudio to\n", btv->c.nr);
3451 printk(KERN_WARNING "bttv%d: override which audio module should be used.\n", btv->c.nr);
3452 }
3453
3454 if (UNSET == btv->tuner_type)
3455 btv->tuner_type = TUNER_ABSENT;
3456
3457 btv->dig = bttv_tvcards[btv->c.type].has_dig_in ?
3458 bttv_tvcards[btv->c.type].video_inputs - 1 : UNSET;
3459 btv->svhs = bttv_tvcards[btv->c.type].svhs == NO_SVHS ?
3460 UNSET : bttv_tvcards[btv->c.type].svhs;
3461 if (svhs[btv->c.nr] != UNSET)
3462 btv->svhs = svhs[btv->c.nr];
3463 if (remote[btv->c.nr] != UNSET)
3464 btv->has_remote = remote[btv->c.nr];
3465
3466 if (bttv_tvcards[btv->c.type].has_radio)
3467 btv->has_radio = 1;
3468 if (bttv_tvcards[btv->c.type].has_remote)
3469 btv->has_remote = 1;
3470 if (!bttv_tvcards[btv->c.type].no_gpioirq)
3471 btv->gpioirq = 1;
3472 if (bttv_tvcards[btv->c.type].volume_gpio)
3473 btv->volume_gpio = bttv_tvcards[btv->c.type].volume_gpio;
3474 if (bttv_tvcards[btv->c.type].audio_mode_gpio)
3475 btv->audio_mode_gpio = bttv_tvcards[btv->c.type].audio_mode_gpio;
3476
3477 if (btv->tuner_type == TUNER_ABSENT)
3478 return; /* no tuner or related drivers to load */
3479
3480 if (btv->has_saa6588 || saa6588[btv->c.nr]) {
3481 /* Probe for RDS receiver chip */
3482 static const unsigned short addrs[] = {
3483 0x20 >> 1,
3484 0x22 >> 1,
3485 I2C_CLIENT_END
3486 };
3487 struct v4l2_subdev *sd;
3488
3489 sd = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3490 &btv->c.i2c_adap, "saa6588", 0, addrs);
3491 btv->has_saa6588 = (sd != NULL);
3492 }
3493
3494 /* try to detect audio/fader chips */
3495
3496 /* First check if the user specified the audio chip via a module
3497 option. */
3498
3499 switch (audiodev[btv->c.nr]) {
3500 case -1:
3501 return; /* do not load any audio module */
3502
3503 case 0: /* autodetect */
3504 break;
3505
3506 case 1: {
3507 /* The user specified that we should probe for msp3400 */
3508 static const unsigned short addrs[] = {
3509 I2C_ADDR_MSP3400 >> 1,
3510 I2C_ADDR_MSP3400_ALT >> 1,
3511 I2C_CLIENT_END
3512 };
3513
3514 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3515 &btv->c.i2c_adap, "msp3400", 0, addrs);
3516 if (btv->sd_msp34xx)
3517 return;
3518 goto no_audio;
3519 }
3520
3521 case 2: {
3522 /* The user specified that we should probe for tda7432 */
3523 static const unsigned short addrs[] = {
3524 I2C_ADDR_TDA7432 >> 1,
3525 I2C_CLIENT_END
3526 };
3527
3528 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3529 &btv->c.i2c_adap, "tda7432", 0, addrs))
3530 return;
3531 goto no_audio;
3532 }
3533
3534 case 3: {
3535 /* The user specified that we should probe for tvaudio */
3536 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3537 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3538 if (btv->sd_tvaudio)
3539 return;
3540 goto no_audio;
3541 }
3542
3543 default:
3544 printk(KERN_WARNING "bttv%d: unknown audiodev value!\n",
3545 btv->c.nr);
3546 return;
3547 }
3548
3549 /* There were no overrides, so now we try to discover this through the
3550 card definition */
3551
3552 /* probe for msp3400 first: this driver can detect whether or not
3553 it really is a msp3400, so it will return NULL when the device
3554 found is really something else (e.g. a tea6300). */
3555 if (!bttv_tvcards[btv->c.type].no_msp34xx) {
3556 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3557 &btv->c.i2c_adap, "msp3400",
3558 0, I2C_ADDRS(I2C_ADDR_MSP3400 >> 1));
3559 } else if (bttv_tvcards[btv->c.type].msp34xx_alt) {
3560 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3561 &btv->c.i2c_adap, "msp3400",
3562 0, I2C_ADDRS(I2C_ADDR_MSP3400_ALT >> 1));
3563 }
3564
3565 /* If we found a msp34xx, then we're done. */
3566 if (btv->sd_msp34xx)
3567 return;
3568
3569 /* it might also be a tda7432. */
3570 if (!bttv_tvcards[btv->c.type].no_tda7432) {
3571 static const unsigned short addrs[] = {
3572 I2C_ADDR_TDA7432 >> 1,
3573 I2C_CLIENT_END
3574 };
3575
3576 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3577 &btv->c.i2c_adap, "tda7432", 0, addrs))
3578 return;
3579 }
3580
3581 /* Now see if we can find one of the tvaudio devices. */
3582 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3583 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3584 if (btv->sd_tvaudio)
3585 return;
3586
3587no_audio:
3588 printk(KERN_WARNING "bttv%d: audio absent, no audio device found!\n",
3589 btv->c.nr);
3590}
3591
3592
3593/* initialize the tuner */
3594void __devinit bttv_init_tuner(struct bttv *btv)
3595{
3596 int addr = ADDR_UNSET;
3597
3598 if (ADDR_UNSET != bttv_tvcards[btv->c.type].tuner_addr)
3599 addr = bttv_tvcards[btv->c.type].tuner_addr;
3600
3601 if (btv->tuner_type != TUNER_ABSENT) {
3602 struct tuner_setup tun_setup;
3603
3604 /* Load tuner module before issuing tuner config call! */
3605 if (bttv_tvcards[btv->c.type].has_radio)
3606 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3607 &btv->c.i2c_adap, "tuner",
3608 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3609 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3610 &btv->c.i2c_adap, "tuner",
3611 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
3612 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3613 &btv->c.i2c_adap, "tuner",
3614 0, v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD));
3615
3616 tun_setup.mode_mask = T_ANALOG_TV;
3617 tun_setup.type = btv->tuner_type;
3618 tun_setup.addr = addr;
3619
3620 if (bttv_tvcards[btv->c.type].has_radio)
3621 tun_setup.mode_mask |= T_RADIO;
3622
3623 bttv_call_all(btv, tuner, s_type_addr, &tun_setup);
3624 }
3625
3626 if (btv->tda9887_conf) {
3627 struct v4l2_priv_tun_config tda9887_cfg;
3628
3629 tda9887_cfg.tuner = TUNER_TDA9887;
3630 tda9887_cfg.priv = &btv->tda9887_conf;
3631
3632 bttv_call_all(btv, tuner, s_config, &tda9887_cfg);
3633 }
3634}
3635
3636/* ----------------------------------------------------------------------- */
3637
3638static void modtec_eeprom(struct bttv *btv)
3639{
3640 if( strncmp(&(eeprom_data[0x1e]),"Temic 4066 FY5",14) ==0) {
3641 btv->tuner_type=TUNER_TEMIC_4066FY5_PAL_I;
3642 printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
3643 btv->c.nr,&eeprom_data[0x1e]);
3644 } else if (strncmp(&(eeprom_data[0x1e]),"Alps TSBB5",10) ==0) {
3645 btv->tuner_type=TUNER_ALPS_TSBB5_PAL_I;
3646 printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
3647 btv->c.nr,&eeprom_data[0x1e]);
3648 } else if (strncmp(&(eeprom_data[0x1e]),"Philips FM1246",14) ==0) {
3649 btv->tuner_type=TUNER_PHILIPS_NTSC;
3650 printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
3651 btv->c.nr,&eeprom_data[0x1e]);
3652 } else {
3653 printk("bttv%d: Modtec: Unknown TunerString: %s\n",
3654 btv->c.nr,&eeprom_data[0x1e]);
3655 }
3656}
3657
3658static void __devinit hauppauge_eeprom(struct bttv *btv)
3659{
3660 struct tveeprom tv;
3661
3662 tveeprom_hauppauge_analog(&btv->i2c_client, &tv, eeprom_data);
3663 btv->tuner_type = tv.tuner_type;
3664 btv->has_radio = tv.has_radio;
3665
3666 printk("bttv%d: Hauppauge eeprom indicates model#%d\n",
3667 btv->c.nr, tv.model);
3668
3669 /*
3670 * Some of the 878 boards have duplicate PCI IDs. Switch the board
3671 * type based on model #.
3672 */
3673 if(tv.model == 64900) {
3674 printk("bttv%d: Switching board type from %s to %s\n",
3675 btv->c.nr,
3676 bttv_tvcards[btv->c.type].name,
3677 bttv_tvcards[BTTV_BOARD_HAUPPAUGE_IMPACTVCB].name);
3678 btv->c.type = BTTV_BOARD_HAUPPAUGE_IMPACTVCB;
3679 }
3680}
3681
3682static int terratec_active_radio_upgrade(struct bttv *btv)
3683{
3684 int freq;
3685
3686 btv->has_radio = 1;
3687 btv->has_matchbox = 1;
3688 btv->mbox_we = 0x10;
3689 btv->mbox_most = 0x20;
3690 btv->mbox_clk = 0x08;
3691 btv->mbox_data = 0x04;
3692 btv->mbox_mask = 0x3c;
3693
3694 btv->mbox_iow = 1 << 8;
3695 btv->mbox_ior = 1 << 9;
3696 btv->mbox_csel = 1 << 10;
3697
3698 freq=88000/62.5;
3699 tea5757_write(btv, 5 * freq + 0x358); /* write 0x1ed8 */
3700 if (0x1ed8 == tea5757_read(btv)) {
3701 printk("bttv%d: Terratec Active Radio Upgrade found.\n",
3702 btv->c.nr);
3703 btv->has_radio = 1;
3704 btv->has_saa6588 = 1;
3705 btv->has_matchbox = 1;
3706 } else {
3707 btv->has_radio = 0;
3708 btv->has_matchbox = 0;
3709 }
3710 return 0;
3711}
3712
3713
3714/* ----------------------------------------------------------------------- */
3715
3716/*
3717 * minimal bootstrap for the WinTV/PVR -- upload altera firmware.
3718 *
3719 * The hcwamc.rbf firmware file is on the Hauppauge driver CD. Have
3720 * a look at Pvr/pvr45xxx.EXE (self-extracting zip archive, can be
3721 * unpacked with unzip).
3722 */
3723#define PVR_GPIO_DELAY 10
3724
3725#define BTTV_ALT_DATA 0x000001
3726#define BTTV_ALT_DCLK 0x100000
3727#define BTTV_ALT_NCONFIG 0x800000
3728
3729static int __devinit pvr_altera_load(struct bttv *btv, const u8 *micro,
3730 u32 microlen)
3731{
3732 u32 n;
3733 u8 bits;
3734 int i;
3735
3736 gpio_inout(0xffffff,BTTV_ALT_DATA|BTTV_ALT_DCLK|BTTV_ALT_NCONFIG);
3737 gpio_write(0);
3738 udelay(PVR_GPIO_DELAY);
3739
3740 gpio_write(BTTV_ALT_NCONFIG);
3741 udelay(PVR_GPIO_DELAY);
3742
3743 for (n = 0; n < microlen; n++) {
3744 bits = micro[n];
3745 for (i = 0 ; i < 8 ; i++) {
3746 gpio_bits(BTTV_ALT_DCLK,0);
3747 if (bits & 0x01)
3748 gpio_bits(BTTV_ALT_DATA,BTTV_ALT_DATA);
3749 else
3750 gpio_bits(BTTV_ALT_DATA,0);
3751 gpio_bits(BTTV_ALT_DCLK,BTTV_ALT_DCLK);
3752 bits >>= 1;
3753 }
3754 }
3755 gpio_bits(BTTV_ALT_DCLK,0);
3756 udelay(PVR_GPIO_DELAY);
3757
3758 /* begin Altera init loop (Not necessary,but doesn't hurt) */
3759 for (i = 0 ; i < 30 ; i++) {
3760 gpio_bits(BTTV_ALT_DCLK,0);
3761 gpio_bits(BTTV_ALT_DCLK,BTTV_ALT_DCLK);
3762 }
3763 gpio_bits(BTTV_ALT_DCLK,0);
3764 return 0;
3765}
3766
3767static int __devinit pvr_boot(struct bttv *btv)
3768{
3769 const struct firmware *fw_entry;
3770 int rc;
3771
3772 rc = request_firmware(&fw_entry, "hcwamc.rbf", &btv->c.pci->dev);
3773 if (rc != 0) {
3774 printk(KERN_WARNING "bttv%d: no altera firmware [via hotplug]\n",
3775 btv->c.nr);
3776 return rc;
3777 }
3778 rc = pvr_altera_load(btv, fw_entry->data, fw_entry->size);
3779 printk(KERN_INFO "bttv%d: altera firmware upload %s\n",
3780 btv->c.nr, (rc < 0) ? "failed" : "ok");
3781 release_firmware(fw_entry);
3782 return rc;
3783}
3784
3785/* ----------------------------------------------------------------------- */
3786/* some osprey specific stuff */
3787
3788static void __devinit osprey_eeprom(struct bttv *btv, const u8 ee[256])
3789{
3790 int i;
3791 u32 serial = 0;
3792 int cardid = -1;
3793
3794 /* This code will nevery actually get called in this case.... */
3795 if (btv->c.type == BTTV_BOARD_UNKNOWN) {
3796 /* this might be an antique... check for MMAC label in eeprom */
3797 if (!strncmp(ee, "MMAC", 4)) {
3798 u8 checksum = 0;
3799 for (i = 0; i < 21; i++)
3800 checksum += ee[i];
3801 if (checksum != ee[21])
3802 return;
3803 cardid = BTTV_BOARD_OSPREY1x0_848;
3804 for (i = 12; i < 21; i++)
3805 serial *= 10, serial += ee[i] - '0';
3806 }
3807 } else {
3808 unsigned short type;
3809
3810 for (i = 4*16; i < 8*16; i += 16) {
3811 u16 checksum = ip_compute_csum(ee + i, 16);
3812
3813 if ((checksum&0xff) + (checksum>>8) == 0xff)
3814 break;
3815 }
3816 if (i >= 8*16)
3817 return;
3818 ee += i;
3819
3820 /* found a valid descriptor */
3821 type = get_unaligned_be16((__be16 *)(ee+4));
3822
3823 switch(type) {
3824 /* 848 based */
3825 case 0x0004:
3826 cardid = BTTV_BOARD_OSPREY1x0_848;
3827 break;
3828 case 0x0005:
3829 cardid = BTTV_BOARD_OSPREY101_848;
3830 break;
3831
3832 /* 878 based */
3833 case 0x0012:
3834 case 0x0013:
3835 cardid = BTTV_BOARD_OSPREY1x0;
3836 break;
3837 case 0x0014:
3838 case 0x0015:
3839 cardid = BTTV_BOARD_OSPREY1x1;
3840 break;
3841 case 0x0016:
3842 case 0x0017:
3843 case 0x0020:
3844 cardid = BTTV_BOARD_OSPREY1x1_SVID;
3845 break;
3846 case 0x0018:
3847 case 0x0019:
3848 case 0x001E:
3849 case 0x001F:
3850 cardid = BTTV_BOARD_OSPREY2xx;
3851 break;
3852 case 0x001A:
3853 case 0x001B:
3854 cardid = BTTV_BOARD_OSPREY2x0_SVID;
3855 break;
3856 case 0x0040:
3857 cardid = BTTV_BOARD_OSPREY500;
3858 break;
3859 case 0x0050:
3860 case 0x0056:
3861 cardid = BTTV_BOARD_OSPREY540;
3862 /* bttv_osprey_540_init(btv); */
3863 break;
3864 case 0x0060:
3865 case 0x0070:
3866 case 0x00A0:
3867 cardid = BTTV_BOARD_OSPREY2x0;
3868 /* enable output on select control lines */
3869 gpio_inout(0xffffff,0x000303);
3870 break;
3871 case 0x00D8:
3872 cardid = BTTV_BOARD_OSPREY440;
3873 break;
3874 default:
3875 /* unknown...leave generic, but get serial # */
3876 printk(KERN_INFO "bttv%d: "
3877 "osprey eeprom: unknown card type 0x%04x\n",
3878 btv->c.nr, type);
3879 break;
3880 }
3881 serial = get_unaligned_be32((__be32 *)(ee+6));
3882 }
3883
3884 printk(KERN_INFO "bttv%d: osprey eeprom: card=%d '%s' serial=%u\n",
3885 btv->c.nr, cardid,
3886 cardid>0 ? bttv_tvcards[cardid].name : "Unknown", serial);
3887
3888 if (cardid<0 || btv->c.type == cardid)
3889 return;
3890
3891 /* card type isn't set correctly */
3892 if (card[btv->c.nr] < bttv_num_tvcards) {
3893 printk(KERN_WARNING "bttv%d: osprey eeprom: "
3894 "Not overriding user specified card type\n", btv->c.nr);
3895 } else {
3896 printk(KERN_INFO "bttv%d: osprey eeprom: "
3897 "Changing card type from %d to %d\n", btv->c.nr,
3898 btv->c.type, cardid);
3899 btv->c.type = cardid;
3900 }
3901}
3902
3903/* ----------------------------------------------------------------------- */
3904/* AVermedia specific stuff, from bktr_card.c */
3905
3906static int tuner_0_table[] = {
3907 TUNER_PHILIPS_NTSC, TUNER_PHILIPS_PAL /* PAL-BG*/,
3908 TUNER_PHILIPS_PAL, TUNER_PHILIPS_PAL /* PAL-I*/,
3909 TUNER_PHILIPS_PAL, TUNER_PHILIPS_PAL,
3910 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_SECAM,
3911 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_PAL,
3912 TUNER_PHILIPS_FM1216ME_MK3 };
3913
3914static int tuner_1_table[] = {
3915 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL,
3916 TUNER_TEMIC_PAL, TUNER_TEMIC_PAL,
3917 TUNER_TEMIC_PAL, TUNER_TEMIC_PAL,
3918 TUNER_TEMIC_4012FY5, TUNER_TEMIC_4012FY5, /* TUNER_TEMIC_SECAM */
3919 TUNER_TEMIC_4012FY5, TUNER_TEMIC_PAL};
3920
3921static void __devinit avermedia_eeprom(struct bttv *btv)
3922{
3923 int tuner_make, tuner_tv_fm, tuner_format, tuner_type = 0;
3924
3925 tuner_make = (eeprom_data[0x41] & 0x7);
3926 tuner_tv_fm = (eeprom_data[0x41] & 0x18) >> 3;
3927 tuner_format = (eeprom_data[0x42] & 0xf0) >> 4;
3928 btv->has_remote = (eeprom_data[0x42] & 0x01);
3929
3930 if (tuner_make == 0 || tuner_make == 2)
3931 if (tuner_format <= 0x0a)
3932 tuner_type = tuner_0_table[tuner_format];
3933 if (tuner_make == 1)
3934 if (tuner_format <= 9)
3935 tuner_type = tuner_1_table[tuner_format];
3936
3937 if (tuner_make == 4)
3938 if (tuner_format == 0x09)
3939 tuner_type = TUNER_LG_NTSC_NEW_TAPC; /* TAPC-G702P */
3940
3941 printk(KERN_INFO "bttv%d: Avermedia eeprom[0x%02x%02x]: tuner=",
3942 btv->c.nr, eeprom_data[0x41], eeprom_data[0x42]);
3943 if (tuner_type) {
3944 btv->tuner_type = tuner_type;
3945 printk(KERN_CONT "%d", tuner_type);
3946 } else
3947 printk(KERN_CONT "Unknown type");
3948 printk(KERN_CONT " radio:%s remote control:%s\n",
3949 tuner_tv_fm ? "yes" : "no",
3950 btv->has_remote ? "yes" : "no");
3951}
3952
3953/*
3954 * For Voodoo TV/FM and Voodoo 200. These cards' tuners use a TDA9880
3955 * analog demod, which is not I2C controlled like the newer and more common
3956 * TDA9887 series. Instead is has two tri-state input pins, S0 and S1,
3957 * that control the IF for the video and audio. Apparently, bttv GPIO
3958 * 0x10000 is connected to S0. S0 low selects a 38.9 MHz VIF for B/G/D/K/I
3959 * (i.e., PAL) while high selects 45.75 MHz for M/N (i.e., NTSC).
3960 */
3961u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits)
3962{
3963
3964 if (btv->audio == TVAUDIO_INPUT_TUNER) {
3965 if (bttv_tvnorms[btv->tvnorm].v4l2_id & V4L2_STD_MN)
3966 gpiobits |= 0x10000;
3967 else
3968 gpiobits &= ~0x10000;
3969 }
3970
3971 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpiobits);
3972 return gpiobits;
3973}
3974
3975
3976/*
3977 * reset/enable the MSP on some Hauppauge cards
3978 * Thanks to Kyösti Mälkki (kmalkki@cc.hut.fi)!
3979 *
3980 * Hauppauge: pin 5
3981 * Voodoo: pin 20
3982 */
3983static void __devinit boot_msp34xx(struct bttv *btv, int pin)
3984{
3985 int mask = (1 << pin);
3986
3987 gpio_inout(mask,mask);
3988 gpio_bits(mask,0);
3989 mdelay(2);
3990 udelay(500);
3991 gpio_bits(mask,mask);
3992
3993 if (bttv_gpio)
3994 bttv_gpio_tracking(btv,"msp34xx");
3995 if (bttv_verbose)
3996 printk(KERN_INFO "bttv%d: Hauppauge/Voodoo msp34xx: reset line "
3997 "init [%d]\n", btv->c.nr, pin);
3998}
3999
4000/* ----------------------------------------------------------------------- */
4001/* Imagenation L-Model PXC200 Framegrabber */
4002/* This is basically the same procedure as
4003 * used by Alessandro Rubini in his pxc200
4004 * driver, but using BTTV functions */
4005
4006static void __devinit init_PXC200(struct bttv *btv)
4007{
4008 static int vals[] __devinitdata = { 0x08, 0x09, 0x0a, 0x0b, 0x0d, 0x0d,
4009 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
4010 0x00 };
4011 unsigned int i;
4012 int tmp;
4013 u32 val;
4014
4015 /* Initialise GPIO-connevted stuff */
4016 gpio_inout(0xffffff, (1<<13));
4017 gpio_write(0);
4018 udelay(3);
4019 gpio_write(1<<13);
4020 /* GPIO inputs are pulled up, so no need to drive
4021 * reset pin any longer */
4022 gpio_bits(0xffffff, 0);
4023 if (bttv_gpio)
4024 bttv_gpio_tracking(btv,"pxc200");
4025
4026 /* we could/should try and reset/control the AD pots? but
4027 right now we simply turned off the crushing. Without
4028 this the AGC drifts drifts
4029 remember the EN is reverse logic -->
4030 setting BT848_ADC_AGC_EN disable the AGC
4031 tboult@eecs.lehigh.edu
4032 */
4033
4034 btwrite(BT848_ADC_RESERVED|BT848_ADC_AGC_EN, BT848_ADC);
4035
4036 /* Initialise MAX517 DAC */
4037 printk(KERN_INFO "Setting DAC reference voltage level ...\n");
4038 bttv_I2CWrite(btv,0x5E,0,0x80,1);
4039
4040 /* Initialise 12C508 PIC */
4041 /* The I2CWrite and I2CRead commmands are actually to the
4042 * same chips - but the R/W bit is included in the address
4043 * argument so the numbers are different */
4044
4045
4046 printk(KERN_INFO "Initialising 12C508 PIC chip ...\n");
4047
4048 /* First of all, enable the clock line. This is used in the PXC200-F */
4049 val = btread(BT848_GPIO_DMA_CTL);
4050 val |= BT848_GPIO_DMA_CTL_GPCLKMODE;
4051 btwrite(val, BT848_GPIO_DMA_CTL);
4052
4053 /* Then, push to 0 the reset pin long enough to reset the *
4054 * device same as above for the reset line, but not the same
4055 * value sent to the GPIO-connected stuff
4056 * which one is the good one? */
4057 gpio_inout(0xffffff,(1<<2));
4058 gpio_write(0);
4059 udelay(10);
4060 gpio_write(1<<2);
4061
4062 for (i = 0; i < ARRAY_SIZE(vals); i++) {
4063 tmp=bttv_I2CWrite(btv,0x1E,0,vals[i],1);
4064 if (tmp != -1) {
4065 printk(KERN_INFO
4066 "I2C Write(%2.2x) = %i\nI2C Read () = %2.2x\n\n",
4067 vals[i],tmp,bttv_I2CRead(btv,0x1F,NULL));
4068 }
4069 }
4070
4071 printk(KERN_INFO "PXC200 Initialised.\n");
4072}
4073
4074
4075
4076/* ----------------------------------------------------------------------- */
4077/*
4078 * The Adlink RTV-24 (aka Angelo) has some special initialisation to unlock
4079 * it. This apparently involves the following procedure for each 878 chip:
4080 *
4081 * 1) write 0x00C3FEFF to the GPIO_OUT_EN register
4082 *
4083 * 2) write to GPIO_DATA
4084 * - 0x0E
4085 * - sleep 1ms
4086 * - 0x10 + 0x0E
4087 * - sleep 10ms
4088 * - 0x0E
4089 * read from GPIO_DATA into buf (uint_32)
4090 * - if ( data>>18 & 0x01 != 0) || ( buf>>19 & 0x01 != 1 )
4091 * error. ERROR_CPLD_Check_Failed stop.
4092 *
4093 * 3) write to GPIO_DATA
4094 * - write 0x4400 + 0x0E
4095 * - sleep 10ms
4096 * - write 0x4410 + 0x0E
4097 * - sleep 1ms
4098 * - write 0x0E
4099 * read from GPIO_DATA into buf (uint_32)
4100 * - if ( buf>>18 & 0x01 ) || ( buf>>19 & 0x01 != 0 )
4101 * error. ERROR_CPLD_Check_Failed.
4102 */
4103/* ----------------------------------------------------------------------- */
4104static void
4105init_RTV24 (struct bttv *btv)
4106{
4107 uint32_t dataRead = 0;
4108 long watchdog_value = 0x0E;
4109
4110 printk (KERN_INFO
4111 "bttv%d: Adlink RTV-24 initialisation in progress ...\n",
4112 btv->c.nr);
4113
4114 btwrite (0x00c3feff, BT848_GPIO_OUT_EN);
4115
4116 btwrite (0 + watchdog_value, BT848_GPIO_DATA);
4117 msleep (1);
4118 btwrite (0x10 + watchdog_value, BT848_GPIO_DATA);
4119 msleep (10);
4120 btwrite (0 + watchdog_value, BT848_GPIO_DATA);
4121
4122 dataRead = btread (BT848_GPIO_DATA);
4123
4124 if ((((dataRead >> 18) & 0x01) != 0) || (((dataRead >> 19) & 0x01) != 1)) {
4125 printk (KERN_INFO
4126 "bttv%d: Adlink RTV-24 initialisation(1) ERROR_CPLD_Check_Failed (read %d)\n",
4127 btv->c.nr, dataRead);
4128 }
4129
4130 btwrite (0x4400 + watchdog_value, BT848_GPIO_DATA);
4131 msleep (10);
4132 btwrite (0x4410 + watchdog_value, BT848_GPIO_DATA);
4133 msleep (1);
4134 btwrite (watchdog_value, BT848_GPIO_DATA);
4135 msleep (1);
4136 dataRead = btread (BT848_GPIO_DATA);
4137
4138 if ((((dataRead >> 18) & 0x01) != 0) || (((dataRead >> 19) & 0x01) != 0)) {
4139 printk (KERN_INFO
4140 "bttv%d: Adlink RTV-24 initialisation(2) ERROR_CPLD_Check_Failed (read %d)\n",
4141 btv->c.nr, dataRead);
4142
4143 return;
4144 }
4145
4146 printk (KERN_INFO
4147 "bttv%d: Adlink RTV-24 initialisation complete.\n", btv->c.nr);
4148}
4149
4150
4151
4152/* ----------------------------------------------------------------------- */
4153/* Miro Pro radio stuff -- the tea5757 is connected to some GPIO ports */
4154/*
4155 * Copyright (c) 1999 Csaba Halasz <qgehali@uni-miskolc.hu>
4156 * This code is placed under the terms of the GNU General Public License
4157 *
4158 * Brutally hacked by Dan Sheridan <dan.sheridan@contact.org.uk> djs52 8/3/00
4159 */
4160
4161static void bus_low(struct bttv *btv, int bit)
4162{
4163 if (btv->mbox_ior) {
4164 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4165 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4166 udelay(5);
4167 }
4168
4169 gpio_bits(bit,0);
4170 udelay(5);
4171
4172 if (btv->mbox_ior) {
4173 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
4174 udelay(5);
4175 }
4176}
4177
4178static void bus_high(struct bttv *btv, int bit)
4179{
4180 if (btv->mbox_ior) {
4181 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4182 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4183 udelay(5);
4184 }
4185
4186 gpio_bits(bit,bit);
4187 udelay(5);
4188
4189 if (btv->mbox_ior) {
4190 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
4191 udelay(5);
4192 }
4193}
4194
4195static int bus_in(struct bttv *btv, int bit)
4196{
4197 if (btv->mbox_ior) {
4198 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4199 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4200 udelay(5);
4201
4202 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
4203 udelay(5);
4204 }
4205 return gpio_read() & (bit);
4206}
4207
4208/* TEA5757 register bits */
4209#define TEA_FREQ 0:14
4210#define TEA_BUFFER 15:15
4211
4212#define TEA_SIGNAL_STRENGTH 16:17
4213
4214#define TEA_PORT1 18:18
4215#define TEA_PORT0 19:19
4216
4217#define TEA_BAND 20:21
4218#define TEA_BAND_FM 0
4219#define TEA_BAND_MW 1
4220#define TEA_BAND_LW 2
4221#define TEA_BAND_SW 3
4222
4223#define TEA_MONO 22:22
4224#define TEA_ALLOW_STEREO 0
4225#define TEA_FORCE_MONO 1
4226
4227#define TEA_SEARCH_DIRECTION 23:23
4228#define TEA_SEARCH_DOWN 0
4229#define TEA_SEARCH_UP 1
4230
4231#define TEA_STATUS 24:24
4232#define TEA_STATUS_TUNED 0
4233#define TEA_STATUS_SEARCHING 1
4234
4235/* Low-level stuff */
4236static int tea5757_read(struct bttv *btv)
4237{
4238 unsigned long timeout;
4239 int value = 0;
4240 int i;
4241
4242 /* better safe than sorry */
4243 gpio_inout(btv->mbox_mask, btv->mbox_clk | btv->mbox_we);
4244
4245 if (btv->mbox_ior) {
4246 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4247 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4248 udelay(5);
4249 }
4250
4251 if (bttv_gpio)
4252 bttv_gpio_tracking(btv,"tea5757 read");
4253
4254 bus_low(btv,btv->mbox_we);
4255 bus_low(btv,btv->mbox_clk);
4256
4257 udelay(10);
4258 timeout= jiffies + msecs_to_jiffies(1000);
4259
4260 /* wait for DATA line to go low; error if it doesn't */
4261 while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout))
4262 schedule();
4263 if (bus_in(btv,btv->mbox_data)) {
4264 printk(KERN_WARNING "bttv%d: tea5757: read timeout\n",btv->c.nr);
4265 return -1;
4266 }
4267
4268 dprintk("bttv%d: tea5757:",btv->c.nr);
4269 for (i = 0; i < 24; i++) {
4270 udelay(5);
4271 bus_high(btv,btv->mbox_clk);
4272 udelay(5);
4273 dprintk("%c",(bus_in(btv,btv->mbox_most) == 0)?'T':'-');
4274 bus_low(btv,btv->mbox_clk);
4275 value <<= 1;
4276 value |= (bus_in(btv,btv->mbox_data) == 0)?0:1; /* MSB first */
4277 dprintk("%c", (bus_in(btv,btv->mbox_most) == 0)?'S':'M');
4278 }
4279 dprintk("\nbttv%d: tea5757: read 0x%X\n", btv->c.nr, value);
4280 return value;
4281}
4282
4283static int tea5757_write(struct bttv *btv, int value)
4284{
4285 int i;
4286 int reg = value;
4287
4288 gpio_inout(btv->mbox_mask, btv->mbox_clk | btv->mbox_we | btv->mbox_data);
4289
4290 if (btv->mbox_ior) {
4291 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4292 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4293 udelay(5);
4294 }
4295 if (bttv_gpio)
4296 bttv_gpio_tracking(btv,"tea5757 write");
4297
4298 dprintk("bttv%d: tea5757: write 0x%X\n", btv->c.nr, value);
4299 bus_low(btv,btv->mbox_clk);
4300 bus_high(btv,btv->mbox_we);
4301 for (i = 0; i < 25; i++) {
4302 if (reg & 0x1000000)
4303 bus_high(btv,btv->mbox_data);
4304 else
4305 bus_low(btv,btv->mbox_data);
4306 reg <<= 1;
4307 bus_high(btv,btv->mbox_clk);
4308 udelay(10);
4309 bus_low(btv,btv->mbox_clk);
4310 udelay(10);
4311 }
4312 bus_low(btv,btv->mbox_we); /* unmute !!! */
4313 return 0;
4314}
4315
4316void tea5757_set_freq(struct bttv *btv, unsigned short freq)
4317{
4318 dprintk("tea5757_set_freq %d\n",freq);
4319 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */
4320}
4321
4322/* RemoteVision MX (rv605) muxsel helper [Miguel Freitas]
4323 *
4324 * This is needed because rv605 don't use a normal multiplex, but a crosspoint
4325 * switch instead (CD22M3494E). This IC can have multiple active connections
4326 * between Xn (input) and Yn (output) pins. We need to clear any existing
4327 * connection prior to establish a new one, pulsing the STROBE pin.
4328 *
4329 * The board hardwire Y0 (xpoint) to MUX1 and MUXOUT to Yin.
4330 * GPIO pins are wired as:
4331 * GPIO[0:3] - AX[0:3] (xpoint) - P1[0:3] (microcontroller)
4332 * GPIO[4:6] - AY[0:2] (xpoint) - P1[4:6] (microcontroller)
4333 * GPIO[7] - DATA (xpoint) - P1[7] (microcontroller)
4334 * GPIO[8] - - P3[5] (microcontroller)
4335 * GPIO[9] - RESET (xpoint) - P3[6] (microcontroller)
4336 * GPIO[10] - STROBE (xpoint) - P3[7] (microcontroller)
4337 * GPINTR - - P3[4] (microcontroller)
4338 *
4339 * The microcontroller is a 80C32 like. It should be possible to change xpoint
4340 * configuration either directly (as we are doing) or using the microcontroller
4341 * which is also wired to I2C interface. I have no further info on the
4342 * microcontroller features, one would need to disassembly the firmware.
4343 * note: the vendor refused to give any information on this product, all
4344 * that stuff was found using a multimeter! :)
4345 */
4346static void rv605_muxsel(struct bttv *btv, unsigned int input)
4347{
4348 static const u8 muxgpio[] = { 0x3, 0x1, 0x2, 0x4, 0xf, 0x7, 0xe, 0x0,
4349 0xd, 0xb, 0xc, 0x6, 0x9, 0x5, 0x8, 0xa };
4350
4351 gpio_bits(0x07f, muxgpio[input]);
4352
4353 /* reset all conections */
4354 gpio_bits(0x200,0x200);
4355 mdelay(1);
4356 gpio_bits(0x200,0x000);
4357 mdelay(1);
4358
4359 /* create a new connection */
4360 gpio_bits(0x480,0x480);
4361 mdelay(1);
4362 gpio_bits(0x480,0x080);
4363 mdelay(1);
4364}
4365
4366/* Tibet Systems 'Progress DVR' CS16 muxsel helper [Chris Fanning]
4367 *
4368 * The CS16 (available on eBay cheap) is a PCI board with four Fusion
4369 * 878A chips, a PCI bridge, an Atmel microcontroller, four sync separator
4370 * chips, ten eight input analog multiplexors, a not chip and a few
4371 * other components.
4372 *
4373 * 16 inputs on a secondary bracket are provided and can be selected
4374 * from each of the four capture chips. Two of the eight input
4375 * multiplexors are used to select from any of the 16 input signals.
4376 *
4377 * Unsupported hardware capabilities:
4378 * . A video output monitor on the secondary bracket can be selected from
4379 * one of the 878A chips.
4380 * . Another passthrough but I haven't spent any time investigating it.
4381 * . Digital I/O (logic level connected to GPIO) is available from an
4382 * onboard header.
4383 *
4384 * The on chip input mux should always be set to 2.
4385 * GPIO[16:19] - Video input selection
4386 * GPIO[0:3] - Video output monitor select (only available from one 878A)
4387 * GPIO[?:?] - Digital I/O.
4388 *
4389 * There is an ATMEL microcontroller with an 8031 core on board. I have not
4390 * determined what function (if any) it provides. With the microcontroller
4391 * and sync separator chips a guess is that it might have to do with video
4392 * switching and maybe some digital I/O.
4393 */
4394static void tibetCS16_muxsel(struct bttv *btv, unsigned int input)
4395{
4396 /* video mux */
4397 gpio_bits(0x0f0000, input << 16);
4398}
4399
4400static void tibetCS16_init(struct bttv *btv)
4401{
4402 /* enable gpio bits, mask obtained via btSpy */
4403 gpio_inout(0xffffff, 0x0f7fff);
4404 gpio_write(0x0f7fff);
4405}
4406
4407/*
4408 * The following routines for the Kodicom-4400r get a little mind-twisting.
4409 * There is a "master" controller and three "slave" controllers, together
4410 * an analog switch which connects any of 16 cameras to any of the BT87A's.
4411 * The analog switch is controlled by the "master", but the detection order
4412 * of the four BT878A chips is in an order which I just don't understand.
4413 * The "master" is actually the second controller to be detected. The
4414 * logic on the board uses logical numbers for the 4 controllers, but
4415 * those numbers are different from the detection sequence. When working
4416 * with the analog switch, we need to "map" from the detection sequence
4417 * over to the board's logical controller number. This mapping sequence
4418 * is {3, 0, 2, 1}, i.e. the first controller to be detected is logical
4419 * unit 3, the second (which is the master) is logical unit 0, etc.
4420 * We need to maintain the status of the analog switch (which of the 16
4421 * cameras is connected to which of the 4 controllers). Rather than
4422 * add to the bttv structure for this, we use the data reserved for
4423 * the mbox (unused for this card type).
4424 */
4425
4426/*
4427 * First a routine to set the analog switch, which controls which camera
4428 * is routed to which controller. The switch comprises an X-address
4429 * (gpio bits 0-3, representing the camera, ranging from 0-15), and a
4430 * Y-address (gpio bits 4-6, representing the controller, ranging from 0-3).
4431 * A data value (gpio bit 7) of '1' enables the switch, and '0' disables
4432 * the switch. A STROBE bit (gpio bit 8) latches the data value into the
4433 * specified address. The idea is to set the address and data, then bring
4434 * STROBE high, and finally bring STROBE back to low.
4435 */
4436static void kodicom4400r_write(struct bttv *btv,
4437 unsigned char xaddr,
4438 unsigned char yaddr,
4439 unsigned char data) {
4440 unsigned int udata;
4441
4442 udata = (data << 7) | ((yaddr&3) << 4) | (xaddr&0xf);
4443 gpio_bits(0x1ff, udata); /* write ADDR and DAT */
4444 gpio_bits(0x1ff, udata | (1 << 8)); /* strobe high */
4445 gpio_bits(0x1ff, udata); /* strobe low */
4446}
4447
4448/*
4449 * Next the mux select. Both the "master" and "slave" 'cards' (controllers)
4450 * use this routine. The routine finds the "master" for the card, maps
4451 * the controller number from the detected position over to the logical
4452 * number, writes the appropriate data to the analog switch, and housekeeps
4453 * the local copy of the switch information. The parameter 'input' is the
4454 * requested camera number (0 - 15).
4455 */
4456static void kodicom4400r_muxsel(struct bttv *btv, unsigned int input)
4457{
4458 char *sw_status;
4459 int xaddr, yaddr;
4460 struct bttv *mctlr;
4461 static unsigned char map[4] = {3, 0, 2, 1};
4462
4463 mctlr = master[btv->c.nr];
4464 if (mctlr == NULL) { /* ignore if master not yet detected */
4465 return;
4466 }
4467 yaddr = (btv->c.nr - mctlr->c.nr + 1) & 3; /* the '&' is for safety */
4468 yaddr = map[yaddr];
4469 sw_status = (char *)(&mctlr->mbox_we);
4470 xaddr = input & 0xf;
4471 /* Check if the controller/camera pair has changed, else ignore */
4472 if (sw_status[yaddr] != xaddr)
4473 {
4474 /* "open" the old switch, "close" the new one, save the new */
4475 kodicom4400r_write(mctlr, sw_status[yaddr], yaddr, 0);
4476 sw_status[yaddr] = xaddr;
4477 kodicom4400r_write(mctlr, xaddr, yaddr, 1);
4478 }
4479}
4480
4481/*
4482 * During initialisation, we need to reset the analog switch. We
4483 * also preset the switch to map the 4 connectors on the card to the
4484 * *user's* (see above description of kodicom4400r_muxsel) channels
4485 * 0 through 3
4486 */
4487static void kodicom4400r_init(struct bttv *btv)
4488{
4489 char *sw_status = (char *)(&btv->mbox_we);
4490 int ix;
4491
4492 gpio_inout(0x0003ff, 0x0003ff);
4493 gpio_write(1 << 9); /* reset MUX */
4494 gpio_write(0);
4495 /* Preset camera 0 to the 4 controllers */
4496 for (ix = 0; ix < 4; ix++) {
4497 sw_status[ix] = ix;
4498 kodicom4400r_write(btv, ix, ix, 1);
4499 }
4500 /*
4501 * Since this is the "master", we need to set up the
4502 * other three controller chips' pointers to this structure
4503 * for later use in the muxsel routine.
4504 */
4505 if ((btv->c.nr<1) || (btv->c.nr>BTTV_MAX-3))
4506 return;
4507 master[btv->c.nr-1] = btv;
4508 master[btv->c.nr] = btv;
4509 master[btv->c.nr+1] = btv;
4510 master[btv->c.nr+2] = btv;
4511}
4512
4513/* The Grandtec X-Guard framegrabber card uses two Dual 4-channel
4514 * video multiplexers to provide up to 16 video inputs. These
4515 * multiplexers are controlled by the lower 8 GPIO pins of the
4516 * bt878. The multiplexers probably Pericom PI5V331Q or similar.
4517
4518 * xxx0 is pin xxx of multiplexer U5,
4519 * yyy1 is pin yyy of multiplexer U2
4520 */
4521#define ENA0 0x01
4522#define ENB0 0x02
4523#define ENA1 0x04
4524#define ENB1 0x08
4525
4526#define IN10 0x10
4527#define IN00 0x20
4528#define IN11 0x40
4529#define IN01 0x80
4530
4531static void xguard_muxsel(struct bttv *btv, unsigned int input)
4532{
4533 static const int masks[] = {
4534 ENB0, ENB0|IN00, ENB0|IN10, ENB0|IN00|IN10,
4535 ENA0, ENA0|IN00, ENA0|IN10, ENA0|IN00|IN10,
4536 ENB1, ENB1|IN01, ENB1|IN11, ENB1|IN01|IN11,
4537 ENA1, ENA1|IN01, ENA1|IN11, ENA1|IN01|IN11,
4538 };
4539 gpio_write(masks[input%16]);
4540}
4541static void picolo_tetra_init(struct bttv *btv)
4542{
4543 /*This is the video input redirection fonctionality : I DID NOT USED IT. */
4544 btwrite (0x08<<16,BT848_GPIO_DATA);/*GPIO[19] [==> 4053 B+C] set to 1 */
4545 btwrite (0x04<<16,BT848_GPIO_DATA);/*GPIO[18] [==> 4053 A] set to 1*/
4546}
4547static void picolo_tetra_muxsel (struct bttv* btv, unsigned int input)
4548{
4549
4550 dprintk (KERN_DEBUG "bttv%d : picolo_tetra_muxsel => input = %d\n",btv->c.nr,input);
4551 /*Just set the right path in the analog multiplexers : channel 1 -> 4 ==> Analog Mux ==> MUX0*/
4552 /*GPIO[20]&GPIO[21] used to choose the right input*/
4553 btwrite (input<<20,BT848_GPIO_DATA);
4554
4555}
4556
4557/*
4558 * ivc120_muxsel [Added by Alan Garfield <alan@fromorbit.com>]
4559 *
4560 * The IVC120G security card has 4 i2c controlled TDA8540 matrix
4561 * swichers to provide 16 channels to MUX0. The TDA8540's have
4562 * 4 independent outputs and as such the IVC120G also has the
4563 * optional "Monitor Out" bus. This allows the card to be looking
4564 * at one input while the monitor is looking at another.
4565 *
4566 * Since I've couldn't be bothered figuring out how to add an
4567 * independent muxsel for the monitor bus, I've just set it to
4568 * whatever the card is looking at.
4569 *
4570 * OUT0 of the TDA8540's is connected to MUX0 (0x03)
4571 * OUT1 of the TDA8540's is connected to "Monitor Out" (0x0C)
4572 *
4573 * TDA8540_ALT3 IN0-3 = Channel 13 - 16 (0x03)
4574 * TDA8540_ALT4 IN0-3 = Channel 1 - 4 (0x03)
4575 * TDA8540_ALT5 IN0-3 = Channel 5 - 8 (0x03)
4576 * TDA8540_ALT6 IN0-3 = Channel 9 - 12 (0x03)
4577 *
4578 */
4579
4580/* All 7 possible sub-ids for the TDA8540 Matrix Switcher */
4581#define I2C_TDA8540 0x90
4582#define I2C_TDA8540_ALT1 0x92
4583#define I2C_TDA8540_ALT2 0x94
4584#define I2C_TDA8540_ALT3 0x96
4585#define I2C_TDA8540_ALT4 0x98
4586#define I2C_TDA8540_ALT5 0x9a
4587#define I2C_TDA8540_ALT6 0x9c
4588
4589static void ivc120_muxsel(struct bttv *btv, unsigned int input)
4590{
4591 /* Simple maths */
4592 int key = input % 4;
4593 int matrix = input / 4;
4594
4595 dprintk("bttv%d: ivc120_muxsel: Input - %02d | TDA - %02d | In - %02d\n",
4596 btv->c.nr, input, matrix, key);
4597
4598 /* Handles the input selection on the TDA8540's */
4599 bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x00,
4600 ((matrix == 3) ? (key | key << 2) : 0x00), 1);
4601 bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x00,
4602 ((matrix == 0) ? (key | key << 2) : 0x00), 1);
4603 bttv_I2CWrite(btv, I2C_TDA8540_ALT5, 0x00,
4604 ((matrix == 1) ? (key | key << 2) : 0x00), 1);
4605 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x00,
4606 ((matrix == 2) ? (key | key << 2) : 0x00), 1);
4607
4608 /* Handles the output enables on the TDA8540's */
4609 bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x02,
4610 ((matrix == 3) ? 0x03 : 0x00), 1); /* 13 - 16 */
4611 bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x02,
4612 ((matrix == 0) ? 0x03 : 0x00), 1); /* 1-4 */
4613 bttv_I2CWrite(btv, I2C_TDA8540_ALT5, 0x02,
4614 ((matrix == 1) ? 0x03 : 0x00), 1); /* 5-8 */
4615 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x02,
4616 ((matrix == 2) ? 0x03 : 0x00), 1); /* 9-12 */
4617
4618 /* 878's MUX0 is already selected for input via muxsel values */
4619}
4620
4621
4622/* PXC200 muxsel helper
4623 * luke@syseng.anu.edu.au
4624 * another transplant
4625 * from Alessandro Rubini (rubini@linux.it)
4626 *
4627 * There are 4 kinds of cards:
4628 * PXC200L which is bt848
4629 * PXC200F which is bt848 with PIC controlling mux
4630 * PXC200AL which is bt878
4631 * PXC200AF which is bt878 with PIC controlling mux
4632 */
4633#define PX_CFG_PXC200F 0x01
4634#define PX_FLAG_PXC200A 0x00001000 /* a pxc200A is bt-878 based */
4635#define PX_I2C_PIC 0x0f
4636#define PX_PXC200A_CARDID 0x200a1295
4637#define PX_I2C_CMD_CFG 0x00
4638
4639static void PXC200_muxsel(struct bttv *btv, unsigned int input)
4640{
4641 int rc;
4642 long mux;
4643 int bitmask;
4644 unsigned char buf[2];
4645
4646 /* Read PIC config to determine if this is a PXC200F */
4647 /* PX_I2C_CMD_CFG*/
4648 buf[0]=0;
4649 buf[1]=0;
4650 rc=bttv_I2CWrite(btv,(PX_I2C_PIC<<1),buf[0],buf[1],1);
4651 if (rc) {
4652 printk(KERN_DEBUG "bttv%d: PXC200_muxsel: pic cfg write failed:%d\n", btv->c.nr,rc);
4653 /* not PXC ? do nothing */
4654 return;
4655 }
4656
4657 rc=bttv_I2CRead(btv,(PX_I2C_PIC<<1),NULL);
4658 if (!(rc & PX_CFG_PXC200F)) {
4659 printk(KERN_DEBUG "bttv%d: PXC200_muxsel: not PXC200F rc:%d \n", btv->c.nr,rc);
4660 return;
4661 }
4662
4663
4664 /* The multiplexer in the 200F is handled by the GPIO port */
4665 /* get correct mapping between inputs */
4666 /* mux = bttv_tvcards[btv->type].muxsel[input] & 3; */
4667 /* ** not needed!? */
4668 mux = input;
4669
4670 /* make sure output pins are enabled */
4671 /* bitmask=0x30f; */
4672 bitmask=0x302;
4673 /* check whether we have a PXC200A */
4674 if (btv->cardid == PX_PXC200A_CARDID) {
4675 bitmask ^= 0x180; /* use 7 and 9, not 8 and 9 */
4676 bitmask |= 7<<4; /* the DAC */
4677 }
4678 btwrite(bitmask, BT848_GPIO_OUT_EN);
4679
4680 bitmask = btread(BT848_GPIO_DATA);
4681 if (btv->cardid == PX_PXC200A_CARDID)
4682 bitmask = (bitmask & ~0x280) | ((mux & 2) << 8) | ((mux & 1) << 7);
4683 else /* older device */
4684 bitmask = (bitmask & ~0x300) | ((mux & 3) << 8);
4685 btwrite(bitmask,BT848_GPIO_DATA);
4686
4687 /*
4688 * Was "to be safe, set the bt848 to input 0"
4689 * Actually, since it's ok at load time, better not messing
4690 * with these bits (on PXC200AF you need to set mux 2 here)
4691 *
4692 * needed because bttv-driver sets mux before calling this function
4693 */
4694 if (btv->cardid == PX_PXC200A_CARDID)
4695 btaor(2<<5, ~BT848_IFORM_MUXSEL, BT848_IFORM);
4696 else /* older device */
4697 btand(~BT848_IFORM_MUXSEL,BT848_IFORM);
4698
4699 printk(KERN_DEBUG "bttv%d: setting input channel to:%d\n", btv->c.nr,(int)mux);
4700}
4701
4702static void phytec_muxsel(struct bttv *btv, unsigned int input)
4703{
4704 unsigned int mux = input % 4;
4705
4706 if (input == btv->svhs)
4707 mux = 0;
4708
4709 gpio_bits(0x3, mux);
4710}
4711
4712/*
4713 * GeoVision GV-800(S) functions
4714 * Bruno Christo <bchristo@inf.ufsm.br>
4715*/
4716
4717/* This is a function to control the analog switch, which determines which
4718 * camera is routed to which controller. The switch comprises an X-address
4719 * (gpio bits 0-3, representing the camera, ranging from 0-15), and a
4720 * Y-address (gpio bits 4-6, representing the controller, ranging from 0-3).
4721 * A data value (gpio bit 18) of '1' enables the switch, and '0' disables
4722 * the switch. A STROBE bit (gpio bit 17) latches the data value into the
4723 * specified address. There is also a chip select (gpio bit 16).
4724 * The idea is to set the address and chip select together, bring
4725 * STROBE high, write the data, and finally bring STROBE back to low.
4726 */
4727static void gv800s_write(struct bttv *btv,
4728 unsigned char xaddr,
4729 unsigned char yaddr,
4730 unsigned char data) {
4731 /* On the "master" 878A:
4732 * GPIO bits 0-9 are used for the analog switch:
4733 * 00 - 03: camera selector
4734 * 04 - 06: 878A (controller) selector
4735 * 16: cselect
4736 * 17: strobe
4737 * 18: data (1->on, 0->off)
4738 * 19: reset
4739 */
4740 const u32 ADDRESS = ((xaddr&0xf) | (yaddr&3)<<4);
4741 const u32 CSELECT = 1<<16;
4742 const u32 STROBE = 1<<17;
4743 const u32 DATA = data<<18;
4744
4745 gpio_bits(0x1007f, ADDRESS | CSELECT); /* write ADDRESS and CSELECT */
4746 gpio_bits(0x20000, STROBE); /* STROBE high */
4747 gpio_bits(0x40000, DATA); /* write DATA */
4748 gpio_bits(0x20000, ~STROBE); /* STROBE low */
4749}
4750
4751/*
4752 * GeoVision GV-800(S) muxsel
4753 *
4754 * Each of the 4 cards (controllers) use this function.
4755 * The controller using this function selects the input through the GPIO pins
4756 * of the "master" card. A pointer to this card is stored in master[btv->c.nr].
4757 *
4758 * The parameter 'input' is the requested camera number (0-4) on the controller.
4759 * The map array has the address of each input. Note that the addresses in the
4760 * array are in the sequence the original GeoVision driver uses, that is, set
4761 * every controller to input 0, then to input 1, 2, 3, repeat. This means that
4762 * the physical "camera 1" connector corresponds to controller 0 input 0,
4763 * "camera 2" corresponds to controller 1 input 0, and so on.
4764 *
4765 * After getting the input address, the function then writes the appropriate
4766 * data to the analog switch, and housekeeps the local copy of the switch
4767 * information.
4768 */
4769static void gv800s_muxsel(struct bttv *btv, unsigned int input)
4770{
4771 struct bttv *mctlr;
4772 char *sw_status;
4773 int xaddr, yaddr;
4774 static unsigned int map[4][4] = { { 0x0, 0x4, 0xa, 0x6 },
4775 { 0x1, 0x5, 0xb, 0x7 },
4776 { 0x2, 0x8, 0xc, 0xe },
4777 { 0x3, 0x9, 0xd, 0xf } };
4778 input = input%4;
4779 mctlr = master[btv->c.nr];
4780 if (mctlr == NULL) {
4781 /* do nothing until the "master" is detected */
4782 return;
4783 }
4784 yaddr = (btv->c.nr - mctlr->c.nr) & 3;
4785 sw_status = (char *)(&mctlr->mbox_we);
4786 xaddr = map[yaddr][input] & 0xf;
4787
4788 /* Check if the controller/camera pair has changed, ignore otherwise */
4789 if (sw_status[yaddr] != xaddr) {
4790 /* disable the old switch, enable the new one and save status */
4791 gv800s_write(mctlr, sw_status[yaddr], yaddr, 0);
4792 sw_status[yaddr] = xaddr;
4793 gv800s_write(mctlr, xaddr, yaddr, 1);
4794 }
4795}
4796
4797/* GeoVision GV-800(S) "master" chip init */
4798static void gv800s_init(struct bttv *btv)
4799{
4800 char *sw_status = (char *)(&btv->mbox_we);
4801 int ix;
4802
4803 gpio_inout(0xf107f, 0xf107f);
4804 gpio_write(1<<19); /* reset the analog MUX */
4805 gpio_write(0);
4806
4807 /* Preset camera 0 to the 4 controllers */
4808 for (ix = 0; ix < 4; ix++) {
4809 sw_status[ix] = ix;
4810 gv800s_write(btv, ix, ix, 1);
4811 }
4812
4813 /* Inputs on the "master" controller need this brightness fix */
4814 bttv_I2CWrite(btv, 0x18, 0x5, 0x90, 1);
4815
4816 if (btv->c.nr > BTTV_MAX-4)
4817 return;
4818 /*
4819 * Store the "master" controller pointer in the master
4820 * array for later use in the muxsel function.
4821 */
4822 master[btv->c.nr] = btv;
4823 master[btv->c.nr+1] = btv;
4824 master[btv->c.nr+2] = btv;
4825 master[btv->c.nr+3] = btv;
4826}
4827
4828/* ----------------------------------------------------------------------- */
4829/* motherboard chipset specific stuff */
4830
4831void __init bttv_check_chipset(void)
4832{
4833 int pcipci_fail = 0;
4834 struct pci_dev *dev = NULL;
4835
4836 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) /* should check if target is AGP */
4837 pcipci_fail = 1;
4838 if (pci_pci_problems & (PCIPCI_TRITON|PCIPCI_NATOMA|PCIPCI_VIAETBF))
4839 triton1 = 1;
4840 if (pci_pci_problems & PCIPCI_VSFX)
4841 vsfx = 1;
4842#ifdef PCIPCI_ALIMAGIK
4843 if (pci_pci_problems & PCIPCI_ALIMAGIK)
4844 latency = 0x0A;
4845#endif
4846
4847
4848 /* print warnings about any quirks found */
4849 if (triton1)
4850 printk(KERN_INFO "bttv: Host bridge needs ETBF enabled.\n");
4851 if (vsfx)
4852 printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n");
4853 if (pcipci_fail) {
4854 printk(KERN_INFO "bttv: bttv and your chipset may not work "
4855 "together.\n");
4856 if (!no_overlay) {
4857 printk(KERN_INFO "bttv: overlay will be disabled.\n");
4858 no_overlay = 1;
4859 } else {
4860 printk(KERN_INFO "bttv: overlay forced. Use this "
4861 "option at your own risk.\n");
4862 }
4863 }
4864 if (UNSET != latency)
4865 printk(KERN_INFO "bttv: pci latency fixup [%d]\n",latency);
4866 while ((dev = pci_get_device(PCI_VENDOR_ID_INTEL,
4867 PCI_DEVICE_ID_INTEL_82441, dev))) {
4868 unsigned char b;
4869 pci_read_config_byte(dev, 0x53, &b);
4870 if (bttv_debug)
4871 printk(KERN_INFO "bttv: Host bridge: 82441FX Natoma, "
4872 "bufcon=0x%02x\n",b);
4873 }
4874}
4875
4876int __devinit bttv_handle_chipset(struct bttv *btv)
4877{
4878 unsigned char command;
4879
4880 if (!triton1 && !vsfx && UNSET == latency)
4881 return 0;
4882
4883 if (bttv_verbose) {
4884 if (triton1)
4885 printk(KERN_INFO "bttv%d: enabling ETBF (430FX/VP3 compatibilty)\n",btv->c.nr);
4886 if (vsfx && btv->id >= 878)
4887 printk(KERN_INFO "bttv%d: enabling VSFX\n",btv->c.nr);
4888 if (UNSET != latency)
4889 printk(KERN_INFO "bttv%d: setting pci timer to %d\n",
4890 btv->c.nr,latency);
4891 }
4892
4893 if (btv->id < 878) {
4894 /* bt848 (mis)uses a bit in the irq mask for etbf */
4895 if (triton1)
4896 btv->triton1 = BT848_INT_ETBF;
4897 } else {
4898 /* bt878 has a bit in the pci config space for it */
4899 pci_read_config_byte(btv->c.pci, BT878_DEVCTRL, &command);
4900 if (triton1)
4901 command |= BT878_EN_TBFX;
4902 if (vsfx)
4903 command |= BT878_EN_VSFX;
4904 pci_write_config_byte(btv->c.pci, BT878_DEVCTRL, command);
4905 }
4906 if (UNSET != latency)
4907 pci_write_config_byte(btv->c.pci, PCI_LATENCY_TIMER, latency);
4908 return 0;
4909}
4910
4911
4912/*
4913 * Local variables:
4914 * c-basic-offset: 8
4915 * End:
4916 */
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
new file mode 100644
index 00000000000..14444de67d5
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -0,0 +1,4626 @@
1/*
2
3 bttv - Bt848 frame grabber driver
4
5 Copyright (C) 1996,97,98 Ralph Metzler <rjkm@thp.uni-koeln.de>
6 & Marcus Metzler <mocm@thp.uni-koeln.de>
7 (c) 1999-2002 Gerd Knorr <kraxel@bytesex.org>
8
9 some v4l2 code lines are taken from Justin's bttv2 driver which is
10 (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za>
11
12 V4L1 removal from:
13 (c) 2005-2006 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
14
15 Fixes to be fully V4L2 compliant by
16 (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
17
18 Cropping and overscan support
19 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at>
20 Sponsored by OPQ Systems AB
21
22 This program is free software; you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation; either version 2 of the License, or
25 (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35*/
36
37#include <linux/init.h>
38#include <linux/module.h>
39#include <linux/delay.h>
40#include <linux/slab.h>
41#include <linux/errno.h>
42#include <linux/fs.h>
43#include <linux/kernel.h>
44#include <linux/sched.h>
45#include <linux/interrupt.h>
46#include <linux/kdev_t.h>
47#include "bttvp.h"
48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
50#include <media/tvaudio.h>
51#include <media/msp3400.h>
52
53#include <linux/dma-mapping.h>
54
55#include <asm/io.h>
56#include <asm/byteorder.h>
57
58#include <media/saa6588.h>
59
60#define BTTV_VERSION "0.9.19"
61
62unsigned int bttv_num; /* number of Bt848s in use */
63struct bttv *bttvs[BTTV_MAX];
64
65unsigned int bttv_debug;
66unsigned int bttv_verbose = 1;
67unsigned int bttv_gpio;
68
69/* config variables */
70#ifdef __BIG_ENDIAN
71static unsigned int bigendian=1;
72#else
73static unsigned int bigendian;
74#endif
75static unsigned int radio[BTTV_MAX];
76static unsigned int irq_debug;
77static unsigned int gbuffers = 8;
78static unsigned int gbufsize = 0x208000;
79static unsigned int reset_crop = 1;
80
81static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
82static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
83static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
84static int debug_latency;
85static int disable_ir;
86
87static unsigned int fdsr;
88
89/* options */
90static unsigned int combfilter;
91static unsigned int lumafilter;
92static unsigned int automute = 1;
93static unsigned int chroma_agc;
94static unsigned int adc_crush = 1;
95static unsigned int whitecrush_upper = 0xCF;
96static unsigned int whitecrush_lower = 0x7F;
97static unsigned int vcr_hack;
98static unsigned int irq_iswitch;
99static unsigned int uv_ratio = 50;
100static unsigned int full_luma_range;
101static unsigned int coring;
102
103/* API features (turn on/off stuff for testing) */
104static unsigned int v4l2 = 1;
105
106/* insmod args */
107module_param(bttv_verbose, int, 0644);
108module_param(bttv_gpio, int, 0644);
109module_param(bttv_debug, int, 0644);
110module_param(irq_debug, int, 0644);
111module_param(debug_latency, int, 0644);
112module_param(disable_ir, int, 0444);
113
114module_param(fdsr, int, 0444);
115module_param(gbuffers, int, 0444);
116module_param(gbufsize, int, 0444);
117module_param(reset_crop, int, 0444);
118
119module_param(v4l2, int, 0644);
120module_param(bigendian, int, 0644);
121module_param(irq_iswitch, int, 0644);
122module_param(combfilter, int, 0444);
123module_param(lumafilter, int, 0444);
124module_param(automute, int, 0444);
125module_param(chroma_agc, int, 0444);
126module_param(adc_crush, int, 0444);
127module_param(whitecrush_upper, int, 0444);
128module_param(whitecrush_lower, int, 0444);
129module_param(vcr_hack, int, 0444);
130module_param(uv_ratio, int, 0444);
131module_param(full_luma_range, int, 0444);
132module_param(coring, int, 0444);
133
134module_param_array(radio, int, NULL, 0444);
135module_param_array(video_nr, int, NULL, 0444);
136module_param_array(radio_nr, int, NULL, 0444);
137module_param_array(vbi_nr, int, NULL, 0444);
138
139MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)");
140MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian");
141MODULE_PARM_DESC(bttv_verbose,"verbose startup messages, default is 1 (yes)");
142MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)");
143MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)");
144MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)");
145MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
146MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8");
147MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000");
148MODULE_PARM_DESC(reset_crop,"reset cropping parameters at open(), default "
149 "is 1 (yes) for compatibility with older applications");
150MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)");
151MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)");
152MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)");
153MODULE_PARM_DESC(whitecrush_upper,"sets the white crush upper value, default is 207");
154MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127");
155MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)");
156MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler");
157MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50");
158MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)");
159MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)");
160MODULE_PARM_DESC(video_nr, "video device numbers");
161MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
162MODULE_PARM_DESC(radio_nr, "radio device numbers");
163
164MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");
165MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
166MODULE_LICENSE("GPL");
167MODULE_VERSION(BTTV_VERSION);
168
169/* ----------------------------------------------------------------------- */
170/* sysfs */
171
172static ssize_t show_card(struct device *cd,
173 struct device_attribute *attr, char *buf)
174{
175 struct video_device *vfd = container_of(cd, struct video_device, dev);
176 struct bttv *btv = video_get_drvdata(vfd);
177 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
178}
179static DEVICE_ATTR(card, S_IRUGO, show_card, NULL);
180
181/* ----------------------------------------------------------------------- */
182/* dvb auto-load setup */
183#if defined(CONFIG_MODULES) && defined(MODULE)
184static void request_module_async(struct work_struct *work)
185{
186 request_module("dvb-bt8xx");
187}
188
189static void request_modules(struct bttv *dev)
190{
191 INIT_WORK(&dev->request_module_wk, request_module_async);
192 schedule_work(&dev->request_module_wk);
193}
194
195static void flush_request_modules(struct bttv *dev)
196{
197 flush_work_sync(&dev->request_module_wk);
198}
199#else
200#define request_modules(dev)
201#define flush_request_modules(dev)
202#endif /* CONFIG_MODULES */
203
204
205/* ----------------------------------------------------------------------- */
206/* static data */
207
208/* special timing tables from conexant... */
209static u8 SRAM_Table[][60] =
210{
211 /* PAL digital input over GPIO[7:0] */
212 {
213 45, // 45 bytes following
214 0x36,0x11,0x01,0x00,0x90,0x02,0x05,0x10,0x04,0x16,
215 0x12,0x05,0x11,0x00,0x04,0x12,0xC0,0x00,0x31,0x00,
216 0x06,0x51,0x08,0x03,0x89,0x08,0x07,0xC0,0x44,0x00,
217 0x81,0x01,0x01,0xA9,0x0D,0x02,0x02,0x50,0x03,0x37,
218 0x37,0x00,0xAF,0x21,0x00
219 },
220 /* NTSC digital input over GPIO[7:0] */
221 {
222 51, // 51 bytes following
223 0x0C,0xC0,0x00,0x00,0x90,0x02,0x03,0x10,0x03,0x06,
224 0x10,0x04,0x12,0x12,0x05,0x02,0x13,0x04,0x19,0x00,
225 0x04,0x39,0x00,0x06,0x59,0x08,0x03,0x83,0x08,0x07,
226 0x03,0x50,0x00,0xC0,0x40,0x00,0x86,0x01,0x01,0xA6,
227 0x0D,0x02,0x03,0x11,0x01,0x05,0x37,0x00,0xAC,0x21,
228 0x00,
229 },
230 // TGB_NTSC392 // quartzsight
231 // This table has been modified to be used for Fusion Rev D
232 {
233 0x2A, // size of table = 42
234 0x06, 0x08, 0x04, 0x0a, 0xc0, 0x00, 0x18, 0x08, 0x03, 0x24,
235 0x08, 0x07, 0x02, 0x90, 0x02, 0x08, 0x10, 0x04, 0x0c, 0x10,
236 0x05, 0x2c, 0x11, 0x04, 0x55, 0x48, 0x00, 0x05, 0x50, 0x00,
237 0xbf, 0x0c, 0x02, 0x2f, 0x3d, 0x00, 0x2f, 0x3f, 0x00, 0xc3,
238 0x20, 0x00
239 }
240};
241
242/* minhdelayx1 first video pixel we can capture on a line and
243 hdelayx1 start of active video, both relative to rising edge of
244 /HRESET pulse (0H) in 1 / fCLKx1.
245 swidth width of active video and
246 totalwidth total line width, both in 1 / fCLKx1.
247 sqwidth total line width in square pixels.
248 vdelay start of active video in 2 * field lines relative to
249 trailing edge of /VRESET pulse (VDELAY register).
250 sheight height of active video in 2 * field lines.
251 videostart0 ITU-R frame line number of the line corresponding
252 to vdelay in the first field. */
253#define CROPCAP(minhdelayx1, hdelayx1, swidth, totalwidth, sqwidth, \
254 vdelay, sheight, videostart0) \
255 .cropcap.bounds.left = minhdelayx1, \
256 /* * 2 because vertically we count field lines times two, */ \
257 /* e.g. 23 * 2 to 23 * 2 + 576 in PAL-BGHI defrect. */ \
258 .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \
259 /* 4 is a safety margin at the end of the line. */ \
260 .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \
261 .cropcap.bounds.height = (sheight) + (vdelay) - MIN_VDELAY, \
262 .cropcap.defrect.left = hdelayx1, \
263 .cropcap.defrect.top = (videostart0) * 2, \
264 .cropcap.defrect.width = swidth, \
265 .cropcap.defrect.height = sheight, \
266 .cropcap.pixelaspect.numerator = totalwidth, \
267 .cropcap.pixelaspect.denominator = sqwidth,
268
269const struct bttv_tvnorm bttv_tvnorms[] = {
270 /* PAL-BDGHI */
271 /* max. active video is actually 922, but 924 is divisible by 4 and 3! */
272 /* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */
273 {
274 .v4l2_id = V4L2_STD_PAL,
275 .name = "PAL",
276 .Fsc = 35468950,
277 .swidth = 924,
278 .sheight = 576,
279 .totalwidth = 1135,
280 .adelay = 0x7f,
281 .bdelay = 0x72,
282 .iform = (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1),
283 .scaledtwidth = 1135,
284 .hdelayx1 = 186,
285 .hactivex1 = 924,
286 .vdelay = 0x20,
287 .vbipack = 255, /* min (2048 / 4, 0x1ff) & 0xff */
288 .sram = 0,
289 /* ITU-R frame line number of the first VBI line
290 we can capture, of the first and second field.
291 The last line is determined by cropcap.bounds. */
292 .vbistart = { 7, 320 },
293 CROPCAP(/* minhdelayx1 */ 68,
294 /* hdelayx1 */ 186,
295 /* Should be (768 * 1135 + 944 / 2) / 944.
296 cropcap.defrect is used for image width
297 checks, so we keep the old value 924. */
298 /* swidth */ 924,
299 /* totalwidth */ 1135,
300 /* sqwidth */ 944,
301 /* vdelay */ 0x20,
302 /* sheight */ 576,
303 /* videostart0 */ 23)
304 /* bt878 (and bt848?) can capture another
305 line below active video. */
306 .cropcap.bounds.height = (576 + 2) + 0x20 - 2,
307 },{
308 .v4l2_id = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR,
309 .name = "NTSC",
310 .Fsc = 28636363,
311 .swidth = 768,
312 .sheight = 480,
313 .totalwidth = 910,
314 .adelay = 0x68,
315 .bdelay = 0x5d,
316 .iform = (BT848_IFORM_NTSC|BT848_IFORM_XT0),
317 .scaledtwidth = 910,
318 .hdelayx1 = 128,
319 .hactivex1 = 910,
320 .vdelay = 0x1a,
321 .vbipack = 144, /* min (1600 / 4, 0x1ff) & 0xff */
322 .sram = 1,
323 .vbistart = { 10, 273 },
324 CROPCAP(/* minhdelayx1 */ 68,
325 /* hdelayx1 */ 128,
326 /* Should be (640 * 910 + 780 / 2) / 780? */
327 /* swidth */ 768,
328 /* totalwidth */ 910,
329 /* sqwidth */ 780,
330 /* vdelay */ 0x1a,
331 /* sheight */ 480,
332 /* videostart0 */ 23)
333 },{
334 .v4l2_id = V4L2_STD_SECAM,
335 .name = "SECAM",
336 .Fsc = 35468950,
337 .swidth = 924,
338 .sheight = 576,
339 .totalwidth = 1135,
340 .adelay = 0x7f,
341 .bdelay = 0xb0,
342 .iform = (BT848_IFORM_SECAM|BT848_IFORM_XT1),
343 .scaledtwidth = 1135,
344 .hdelayx1 = 186,
345 .hactivex1 = 922,
346 .vdelay = 0x20,
347 .vbipack = 255,
348 .sram = 0, /* like PAL, correct? */
349 .vbistart = { 7, 320 },
350 CROPCAP(/* minhdelayx1 */ 68,
351 /* hdelayx1 */ 186,
352 /* swidth */ 924,
353 /* totalwidth */ 1135,
354 /* sqwidth */ 944,
355 /* vdelay */ 0x20,
356 /* sheight */ 576,
357 /* videostart0 */ 23)
358 },{
359 .v4l2_id = V4L2_STD_PAL_Nc,
360 .name = "PAL-Nc",
361 .Fsc = 28636363,
362 .swidth = 640,
363 .sheight = 576,
364 .totalwidth = 910,
365 .adelay = 0x68,
366 .bdelay = 0x5d,
367 .iform = (BT848_IFORM_PAL_NC|BT848_IFORM_XT0),
368 .scaledtwidth = 780,
369 .hdelayx1 = 130,
370 .hactivex1 = 734,
371 .vdelay = 0x1a,
372 .vbipack = 144,
373 .sram = -1,
374 .vbistart = { 7, 320 },
375 CROPCAP(/* minhdelayx1 */ 68,
376 /* hdelayx1 */ 130,
377 /* swidth */ (640 * 910 + 780 / 2) / 780,
378 /* totalwidth */ 910,
379 /* sqwidth */ 780,
380 /* vdelay */ 0x1a,
381 /* sheight */ 576,
382 /* videostart0 */ 23)
383 },{
384 .v4l2_id = V4L2_STD_PAL_M,
385 .name = "PAL-M",
386 .Fsc = 28636363,
387 .swidth = 640,
388 .sheight = 480,
389 .totalwidth = 910,
390 .adelay = 0x68,
391 .bdelay = 0x5d,
392 .iform = (BT848_IFORM_PAL_M|BT848_IFORM_XT0),
393 .scaledtwidth = 780,
394 .hdelayx1 = 135,
395 .hactivex1 = 754,
396 .vdelay = 0x1a,
397 .vbipack = 144,
398 .sram = -1,
399 .vbistart = { 10, 273 },
400 CROPCAP(/* minhdelayx1 */ 68,
401 /* hdelayx1 */ 135,
402 /* swidth */ (640 * 910 + 780 / 2) / 780,
403 /* totalwidth */ 910,
404 /* sqwidth */ 780,
405 /* vdelay */ 0x1a,
406 /* sheight */ 480,
407 /* videostart0 */ 23)
408 },{
409 .v4l2_id = V4L2_STD_PAL_N,
410 .name = "PAL-N",
411 .Fsc = 35468950,
412 .swidth = 768,
413 .sheight = 576,
414 .totalwidth = 1135,
415 .adelay = 0x7f,
416 .bdelay = 0x72,
417 .iform = (BT848_IFORM_PAL_N|BT848_IFORM_XT1),
418 .scaledtwidth = 944,
419 .hdelayx1 = 186,
420 .hactivex1 = 922,
421 .vdelay = 0x20,
422 .vbipack = 144,
423 .sram = -1,
424 .vbistart = { 7, 320 },
425 CROPCAP(/* minhdelayx1 */ 68,
426 /* hdelayx1 */ 186,
427 /* swidth */ (768 * 1135 + 944 / 2) / 944,
428 /* totalwidth */ 1135,
429 /* sqwidth */ 944,
430 /* vdelay */ 0x20,
431 /* sheight */ 576,
432 /* videostart0 */ 23)
433 },{
434 .v4l2_id = V4L2_STD_NTSC_M_JP,
435 .name = "NTSC-JP",
436 .Fsc = 28636363,
437 .swidth = 640,
438 .sheight = 480,
439 .totalwidth = 910,
440 .adelay = 0x68,
441 .bdelay = 0x5d,
442 .iform = (BT848_IFORM_NTSC_J|BT848_IFORM_XT0),
443 .scaledtwidth = 780,
444 .hdelayx1 = 135,
445 .hactivex1 = 754,
446 .vdelay = 0x16,
447 .vbipack = 144,
448 .sram = -1,
449 .vbistart = { 10, 273 },
450 CROPCAP(/* minhdelayx1 */ 68,
451 /* hdelayx1 */ 135,
452 /* swidth */ (640 * 910 + 780 / 2) / 780,
453 /* totalwidth */ 910,
454 /* sqwidth */ 780,
455 /* vdelay */ 0x16,
456 /* sheight */ 480,
457 /* videostart0 */ 23)
458 },{
459 /* that one hopefully works with the strange timing
460 * which video recorders produce when playing a NTSC
461 * tape on a PAL TV ... */
462 .v4l2_id = V4L2_STD_PAL_60,
463 .name = "PAL-60",
464 .Fsc = 35468950,
465 .swidth = 924,
466 .sheight = 480,
467 .totalwidth = 1135,
468 .adelay = 0x7f,
469 .bdelay = 0x72,
470 .iform = (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1),
471 .scaledtwidth = 1135,
472 .hdelayx1 = 186,
473 .hactivex1 = 924,
474 .vdelay = 0x1a,
475 .vbipack = 255,
476 .vtotal = 524,
477 .sram = -1,
478 .vbistart = { 10, 273 },
479 CROPCAP(/* minhdelayx1 */ 68,
480 /* hdelayx1 */ 186,
481 /* swidth */ 924,
482 /* totalwidth */ 1135,
483 /* sqwidth */ 944,
484 /* vdelay */ 0x1a,
485 /* sheight */ 480,
486 /* videostart0 */ 23)
487 }
488};
489static const unsigned int BTTV_TVNORMS = ARRAY_SIZE(bttv_tvnorms);
490
491/* ----------------------------------------------------------------------- */
492/* bttv format list
493 packed pixel formats must come first */
494static const struct bttv_format formats[] = {
495 {
496 .name = "8 bpp, gray",
497 .fourcc = V4L2_PIX_FMT_GREY,
498 .btformat = BT848_COLOR_FMT_Y8,
499 .depth = 8,
500 .flags = FORMAT_FLAGS_PACKED,
501 },{
502 .name = "8 bpp, dithered color",
503 .fourcc = V4L2_PIX_FMT_HI240,
504 .btformat = BT848_COLOR_FMT_RGB8,
505 .depth = 8,
506 .flags = FORMAT_FLAGS_PACKED | FORMAT_FLAGS_DITHER,
507 },{
508 .name = "15 bpp RGB, le",
509 .fourcc = V4L2_PIX_FMT_RGB555,
510 .btformat = BT848_COLOR_FMT_RGB15,
511 .depth = 16,
512 .flags = FORMAT_FLAGS_PACKED,
513 },{
514 .name = "15 bpp RGB, be",
515 .fourcc = V4L2_PIX_FMT_RGB555X,
516 .btformat = BT848_COLOR_FMT_RGB15,
517 .btswap = 0x03, /* byteswap */
518 .depth = 16,
519 .flags = FORMAT_FLAGS_PACKED,
520 },{
521 .name = "16 bpp RGB, le",
522 .fourcc = V4L2_PIX_FMT_RGB565,
523 .btformat = BT848_COLOR_FMT_RGB16,
524 .depth = 16,
525 .flags = FORMAT_FLAGS_PACKED,
526 },{
527 .name = "16 bpp RGB, be",
528 .fourcc = V4L2_PIX_FMT_RGB565X,
529 .btformat = BT848_COLOR_FMT_RGB16,
530 .btswap = 0x03, /* byteswap */
531 .depth = 16,
532 .flags = FORMAT_FLAGS_PACKED,
533 },{
534 .name = "24 bpp RGB, le",
535 .fourcc = V4L2_PIX_FMT_BGR24,
536 .btformat = BT848_COLOR_FMT_RGB24,
537 .depth = 24,
538 .flags = FORMAT_FLAGS_PACKED,
539 },{
540 .name = "32 bpp RGB, le",
541 .fourcc = V4L2_PIX_FMT_BGR32,
542 .btformat = BT848_COLOR_FMT_RGB32,
543 .depth = 32,
544 .flags = FORMAT_FLAGS_PACKED,
545 },{
546 .name = "32 bpp RGB, be",
547 .fourcc = V4L2_PIX_FMT_RGB32,
548 .btformat = BT848_COLOR_FMT_RGB32,
549 .btswap = 0x0f, /* byte+word swap */
550 .depth = 32,
551 .flags = FORMAT_FLAGS_PACKED,
552 },{
553 .name = "4:2:2, packed, YUYV",
554 .fourcc = V4L2_PIX_FMT_YUYV,
555 .btformat = BT848_COLOR_FMT_YUY2,
556 .depth = 16,
557 .flags = FORMAT_FLAGS_PACKED,
558 },{
559 .name = "4:2:2, packed, YUYV",
560 .fourcc = V4L2_PIX_FMT_YUYV,
561 .btformat = BT848_COLOR_FMT_YUY2,
562 .depth = 16,
563 .flags = FORMAT_FLAGS_PACKED,
564 },{
565 .name = "4:2:2, packed, UYVY",
566 .fourcc = V4L2_PIX_FMT_UYVY,
567 .btformat = BT848_COLOR_FMT_YUY2,
568 .btswap = 0x03, /* byteswap */
569 .depth = 16,
570 .flags = FORMAT_FLAGS_PACKED,
571 },{
572 .name = "4:2:2, planar, Y-Cb-Cr",
573 .fourcc = V4L2_PIX_FMT_YUV422P,
574 .btformat = BT848_COLOR_FMT_YCrCb422,
575 .depth = 16,
576 .flags = FORMAT_FLAGS_PLANAR,
577 .hshift = 1,
578 .vshift = 0,
579 },{
580 .name = "4:2:0, planar, Y-Cb-Cr",
581 .fourcc = V4L2_PIX_FMT_YUV420,
582 .btformat = BT848_COLOR_FMT_YCrCb422,
583 .depth = 12,
584 .flags = FORMAT_FLAGS_PLANAR,
585 .hshift = 1,
586 .vshift = 1,
587 },{
588 .name = "4:2:0, planar, Y-Cr-Cb",
589 .fourcc = V4L2_PIX_FMT_YVU420,
590 .btformat = BT848_COLOR_FMT_YCrCb422,
591 .depth = 12,
592 .flags = FORMAT_FLAGS_PLANAR | FORMAT_FLAGS_CrCb,
593 .hshift = 1,
594 .vshift = 1,
595 },{
596 .name = "4:1:1, planar, Y-Cb-Cr",
597 .fourcc = V4L2_PIX_FMT_YUV411P,
598 .btformat = BT848_COLOR_FMT_YCrCb411,
599 .depth = 12,
600 .flags = FORMAT_FLAGS_PLANAR,
601 .hshift = 2,
602 .vshift = 0,
603 },{
604 .name = "4:1:0, planar, Y-Cb-Cr",
605 .fourcc = V4L2_PIX_FMT_YUV410,
606 .btformat = BT848_COLOR_FMT_YCrCb411,
607 .depth = 9,
608 .flags = FORMAT_FLAGS_PLANAR,
609 .hshift = 2,
610 .vshift = 2,
611 },{
612 .name = "4:1:0, planar, Y-Cr-Cb",
613 .fourcc = V4L2_PIX_FMT_YVU410,
614 .btformat = BT848_COLOR_FMT_YCrCb411,
615 .depth = 9,
616 .flags = FORMAT_FLAGS_PLANAR | FORMAT_FLAGS_CrCb,
617 .hshift = 2,
618 .vshift = 2,
619 },{
620 .name = "raw scanlines",
621 .fourcc = -1,
622 .btformat = BT848_COLOR_FMT_RAW,
623 .depth = 8,
624 .flags = FORMAT_FLAGS_RAW,
625 }
626};
627static const unsigned int FORMATS = ARRAY_SIZE(formats);
628
629/* ----------------------------------------------------------------------- */
630
631#define V4L2_CID_PRIVATE_CHROMA_AGC (V4L2_CID_PRIVATE_BASE + 0)
632#define V4L2_CID_PRIVATE_COMBFILTER (V4L2_CID_PRIVATE_BASE + 1)
633#define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 2)
634#define V4L2_CID_PRIVATE_LUMAFILTER (V4L2_CID_PRIVATE_BASE + 3)
635#define V4L2_CID_PRIVATE_AGC_CRUSH (V4L2_CID_PRIVATE_BASE + 4)
636#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5)
637#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6)
638#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7)
639#define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_PRIVATE_BASE + 8)
640#define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_PRIVATE_BASE + 9)
641#define V4L2_CID_PRIVATE_CORING (V4L2_CID_PRIVATE_BASE + 10)
642#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 11)
643
644static const struct v4l2_queryctrl no_ctl = {
645 .name = "42",
646 .flags = V4L2_CTRL_FLAG_DISABLED,
647};
648static const struct v4l2_queryctrl bttv_ctls[] = {
649 /* --- video --- */
650 {
651 .id = V4L2_CID_BRIGHTNESS,
652 .name = "Brightness",
653 .minimum = 0,
654 .maximum = 65535,
655 .step = 256,
656 .default_value = 32768,
657 .type = V4L2_CTRL_TYPE_INTEGER,
658 },{
659 .id = V4L2_CID_CONTRAST,
660 .name = "Contrast",
661 .minimum = 0,
662 .maximum = 65535,
663 .step = 128,
664 .default_value = 32768,
665 .type = V4L2_CTRL_TYPE_INTEGER,
666 },{
667 .id = V4L2_CID_SATURATION,
668 .name = "Saturation",
669 .minimum = 0,
670 .maximum = 65535,
671 .step = 128,
672 .default_value = 32768,
673 .type = V4L2_CTRL_TYPE_INTEGER,
674 },{
675 .id = V4L2_CID_HUE,
676 .name = "Hue",
677 .minimum = 0,
678 .maximum = 65535,
679 .step = 256,
680 .default_value = 32768,
681 .type = V4L2_CTRL_TYPE_INTEGER,
682 },
683 /* --- audio --- */
684 {
685 .id = V4L2_CID_AUDIO_MUTE,
686 .name = "Mute",
687 .minimum = 0,
688 .maximum = 1,
689 .type = V4L2_CTRL_TYPE_BOOLEAN,
690 },{
691 .id = V4L2_CID_AUDIO_VOLUME,
692 .name = "Volume",
693 .minimum = 0,
694 .maximum = 65535,
695 .step = 65535/100,
696 .default_value = 65535,
697 .type = V4L2_CTRL_TYPE_INTEGER,
698 },{
699 .id = V4L2_CID_AUDIO_BALANCE,
700 .name = "Balance",
701 .minimum = 0,
702 .maximum = 65535,
703 .step = 65535/100,
704 .default_value = 32768,
705 .type = V4L2_CTRL_TYPE_INTEGER,
706 },{
707 .id = V4L2_CID_AUDIO_BASS,
708 .name = "Bass",
709 .minimum = 0,
710 .maximum = 65535,
711 .step = 65535/100,
712 .default_value = 32768,
713 .type = V4L2_CTRL_TYPE_INTEGER,
714 },{
715 .id = V4L2_CID_AUDIO_TREBLE,
716 .name = "Treble",
717 .minimum = 0,
718 .maximum = 65535,
719 .step = 65535/100,
720 .default_value = 32768,
721 .type = V4L2_CTRL_TYPE_INTEGER,
722 },
723 /* --- private --- */
724 {
725 .id = V4L2_CID_PRIVATE_CHROMA_AGC,
726 .name = "chroma agc",
727 .minimum = 0,
728 .maximum = 1,
729 .type = V4L2_CTRL_TYPE_BOOLEAN,
730 },{
731 .id = V4L2_CID_PRIVATE_COMBFILTER,
732 .name = "combfilter",
733 .minimum = 0,
734 .maximum = 1,
735 .type = V4L2_CTRL_TYPE_BOOLEAN,
736 },{
737 .id = V4L2_CID_PRIVATE_AUTOMUTE,
738 .name = "automute",
739 .minimum = 0,
740 .maximum = 1,
741 .type = V4L2_CTRL_TYPE_BOOLEAN,
742 },{
743 .id = V4L2_CID_PRIVATE_LUMAFILTER,
744 .name = "luma decimation filter",
745 .minimum = 0,
746 .maximum = 1,
747 .type = V4L2_CTRL_TYPE_BOOLEAN,
748 },{
749 .id = V4L2_CID_PRIVATE_AGC_CRUSH,
750 .name = "agc crush",
751 .minimum = 0,
752 .maximum = 1,
753 .type = V4L2_CTRL_TYPE_BOOLEAN,
754 },{
755 .id = V4L2_CID_PRIVATE_VCR_HACK,
756 .name = "vcr hack",
757 .minimum = 0,
758 .maximum = 1,
759 .type = V4L2_CTRL_TYPE_BOOLEAN,
760 },{
761 .id = V4L2_CID_PRIVATE_WHITECRUSH_UPPER,
762 .name = "whitecrush upper",
763 .minimum = 0,
764 .maximum = 255,
765 .step = 1,
766 .default_value = 0xCF,
767 .type = V4L2_CTRL_TYPE_INTEGER,
768 },{
769 .id = V4L2_CID_PRIVATE_WHITECRUSH_LOWER,
770 .name = "whitecrush lower",
771 .minimum = 0,
772 .maximum = 255,
773 .step = 1,
774 .default_value = 0x7F,
775 .type = V4L2_CTRL_TYPE_INTEGER,
776 },{
777 .id = V4L2_CID_PRIVATE_UV_RATIO,
778 .name = "uv ratio",
779 .minimum = 0,
780 .maximum = 100,
781 .step = 1,
782 .default_value = 50,
783 .type = V4L2_CTRL_TYPE_INTEGER,
784 },{
785 .id = V4L2_CID_PRIVATE_FULL_LUMA_RANGE,
786 .name = "full luma range",
787 .minimum = 0,
788 .maximum = 1,
789 .type = V4L2_CTRL_TYPE_BOOLEAN,
790 },{
791 .id = V4L2_CID_PRIVATE_CORING,
792 .name = "coring",
793 .minimum = 0,
794 .maximum = 3,
795 .step = 1,
796 .default_value = 0,
797 .type = V4L2_CTRL_TYPE_INTEGER,
798 }
799
800
801
802};
803
804static const struct v4l2_queryctrl *ctrl_by_id(int id)
805{
806 int i;
807
808 for (i = 0; i < ARRAY_SIZE(bttv_ctls); i++)
809 if (bttv_ctls[i].id == id)
810 return bttv_ctls+i;
811
812 return NULL;
813}
814
815/* ----------------------------------------------------------------------- */
816/* resource management */
817
818/*
819 RESOURCE_ allocated by freed by
820
821 VIDEO_READ bttv_read 1) bttv_read 2)
822
823 VIDEO_STREAM VIDIOC_STREAMON VIDIOC_STREAMOFF
824 VIDIOC_QBUF 1) bttv_release
825 VIDIOCMCAPTURE 1)
826
827 OVERLAY VIDIOCCAPTURE on VIDIOCCAPTURE off
828 VIDIOC_OVERLAY on VIDIOC_OVERLAY off
829 3) bttv_release
830
831 VBI VIDIOC_STREAMON VIDIOC_STREAMOFF
832 VIDIOC_QBUF 1) bttv_release
833 bttv_read, bttv_poll 1) 4)
834
835 1) The resource must be allocated when we enter buffer prepare functions
836 and remain allocated while buffers are in the DMA queue.
837 2) This is a single frame read.
838 3) VIDIOC_S_FBUF and VIDIOC_S_FMT (OVERLAY) still work when
839 RESOURCE_OVERLAY is allocated.
840 4) This is a continuous read, implies VIDIOC_STREAMON.
841
842 Note this driver permits video input and standard changes regardless if
843 resources are allocated.
844*/
845
846#define VBI_RESOURCES (RESOURCE_VBI)
847#define VIDEO_RESOURCES (RESOURCE_VIDEO_READ | \
848 RESOURCE_VIDEO_STREAM | \
849 RESOURCE_OVERLAY)
850
851static
852int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit)
853{
854 int xbits; /* mutual exclusive resources */
855
856 if (fh->resources & bit)
857 /* have it already allocated */
858 return 1;
859
860 xbits = bit;
861 if (bit & (RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM))
862 xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM;
863
864 /* is it free? */
865 if (btv->resources & xbits) {
866 /* no, someone else uses it */
867 goto fail;
868 }
869
870 if ((bit & VIDEO_RESOURCES)
871 && 0 == (btv->resources & VIDEO_RESOURCES)) {
872 /* Do crop - use current, don't - use default parameters. */
873 __s32 top = btv->crop[!!fh->do_crop].rect.top;
874
875 if (btv->vbi_end > top)
876 goto fail;
877
878 /* We cannot capture the same line as video and VBI data.
879 Claim scan lines crop[].rect.top to bottom. */
880 btv->crop_start = top;
881 } else if (bit & VBI_RESOURCES) {
882 __s32 end = fh->vbi_fmt.end;
883
884 if (end > btv->crop_start)
885 goto fail;
886
887 /* Claim scan lines above fh->vbi_fmt.end. */
888 btv->vbi_end = end;
889 }
890
891 /* it's free, grab it */
892 fh->resources |= bit;
893 btv->resources |= bit;
894 return 1;
895
896 fail:
897 return 0;
898}
899
900static
901int check_btres(struct bttv_fh *fh, int bit)
902{
903 return (fh->resources & bit);
904}
905
906static
907int locked_btres(struct bttv *btv, int bit)
908{
909 return (btv->resources & bit);
910}
911
912/* Call with btv->lock down. */
913static void
914disclaim_vbi_lines(struct bttv *btv)
915{
916 btv->vbi_end = 0;
917}
918
919/* Call with btv->lock down. */
920static void
921disclaim_video_lines(struct bttv *btv)
922{
923 const struct bttv_tvnorm *tvnorm;
924 u8 crop;
925
926 tvnorm = &bttv_tvnorms[btv->tvnorm];
927 btv->crop_start = tvnorm->cropcap.bounds.top
928 + tvnorm->cropcap.bounds.height;
929
930 /* VBI capturing ends at VDELAY, start of video capturing, no
931 matter how many lines the VBI RISC program expects. When video
932 capturing is off, it shall no longer "preempt" VBI capturing,
933 so we set VDELAY to maximum. */
934 crop = btread(BT848_E_CROP) | 0xc0;
935 btwrite(crop, BT848_E_CROP);
936 btwrite(0xfe, BT848_E_VDELAY_LO);
937 btwrite(crop, BT848_O_CROP);
938 btwrite(0xfe, BT848_O_VDELAY_LO);
939}
940
941static
942void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits)
943{
944 if ((fh->resources & bits) != bits) {
945 /* trying to free ressources not allocated by us ... */
946 printk("bttv: BUG! (btres)\n");
947 }
948 fh->resources &= ~bits;
949 btv->resources &= ~bits;
950
951 bits = btv->resources;
952
953 if (0 == (bits & VIDEO_RESOURCES))
954 disclaim_video_lines(btv);
955
956 if (0 == (bits & VBI_RESOURCES))
957 disclaim_vbi_lines(btv);
958}
959
960/* ----------------------------------------------------------------------- */
961/* If Bt848a or Bt849, use PLL for PAL/SECAM and crystal for NTSC */
962
963/* Frequency = (F_input / PLL_X) * PLL_I.PLL_F/PLL_C
964 PLL_X = Reference pre-divider (0=1, 1=2)
965 PLL_C = Post divider (0=6, 1=4)
966 PLL_I = Integer input
967 PLL_F = Fractional input
968
969 F_input = 28.636363 MHz:
970 PAL (CLKx2 = 35.46895 MHz): PLL_X = 1, PLL_I = 0x0E, PLL_F = 0xDCF9, PLL_C = 0
971*/
972
973static void set_pll_freq(struct bttv *btv, unsigned int fin, unsigned int fout)
974{
975 unsigned char fl, fh, fi;
976
977 /* prevent overflows */
978 fin/=4;
979 fout/=4;
980
981 fout*=12;
982 fi=fout/fin;
983
984 fout=(fout%fin)*256;
985 fh=fout/fin;
986
987 fout=(fout%fin)*256;
988 fl=fout/fin;
989
990 btwrite(fl, BT848_PLL_F_LO);
991 btwrite(fh, BT848_PLL_F_HI);
992 btwrite(fi|BT848_PLL_X, BT848_PLL_XCI);
993}
994
995static void set_pll(struct bttv *btv)
996{
997 int i;
998
999 if (!btv->pll.pll_crystal)
1000 return;
1001
1002 if (btv->pll.pll_ofreq == btv->pll.pll_current) {
1003 dprintk("bttv%d: PLL: no change required\n",btv->c.nr);
1004 return;
1005 }
1006
1007 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) {
1008 /* no PLL needed */
1009 if (btv->pll.pll_current == 0)
1010 return;
1011 bttv_printk(KERN_INFO "bttv%d: PLL can sleep, using XTAL (%d).\n",
1012 btv->c.nr,btv->pll.pll_ifreq);
1013 btwrite(0x00,BT848_TGCTRL);
1014 btwrite(0x00,BT848_PLL_XCI);
1015 btv->pll.pll_current = 0;
1016 return;
1017 }
1018
1019 bttv_printk(KERN_INFO "bttv%d: PLL: %d => %d ",btv->c.nr,
1020 btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1021 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1022
1023 for (i=0; i<10; i++) {
1024 /* Let other people run while the PLL stabilizes */
1025 bttv_printk(".");
1026 msleep(10);
1027
1028 if (btread(BT848_DSTATUS) & BT848_DSTATUS_PLOCK) {
1029 btwrite(0,BT848_DSTATUS);
1030 } else {
1031 btwrite(0x08,BT848_TGCTRL);
1032 btv->pll.pll_current = btv->pll.pll_ofreq;
1033 bttv_printk(" ok\n");
1034 return;
1035 }
1036 }
1037 btv->pll.pll_current = -1;
1038 bttv_printk("failed\n");
1039 return;
1040}
1041
1042/* used to switch between the bt848's analog/digital video capture modes */
1043static void bt848A_set_timing(struct bttv *btv)
1044{
1045 int i, len;
1046 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
1047 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
1048
1049 if (btv->input == btv->dig) {
1050 dprintk("bttv%d: load digital timing table (table_idx=%d)\n",
1051 btv->c.nr,table_idx);
1052
1053 /* timing change...reset timing generator address */
1054 btwrite(0x00, BT848_TGCTRL);
1055 btwrite(0x02, BT848_TGCTRL);
1056 btwrite(0x00, BT848_TGCTRL);
1057
1058 len=SRAM_Table[table_idx][0];
1059 for(i = 1; i <= len; i++)
1060 btwrite(SRAM_Table[table_idx][i],BT848_TGLB);
1061 btv->pll.pll_ofreq = 27000000;
1062
1063 set_pll(btv);
1064 btwrite(0x11, BT848_TGCTRL);
1065 btwrite(0x41, BT848_DVSIF);
1066 } else {
1067 btv->pll.pll_ofreq = fsc;
1068 set_pll(btv);
1069 btwrite(0x0, BT848_DVSIF);
1070 }
1071}
1072
1073/* ----------------------------------------------------------------------- */
1074
1075static void bt848_bright(struct bttv *btv, int bright)
1076{
1077 int value;
1078
1079 // printk("bttv: set bright: %d\n",bright); // DEBUG
1080 btv->bright = bright;
1081
1082 /* We want -128 to 127 we get 0-65535 */
1083 value = (bright >> 8) - 128;
1084 btwrite(value & 0xff, BT848_BRIGHT);
1085}
1086
1087static void bt848_hue(struct bttv *btv, int hue)
1088{
1089 int value;
1090
1091 btv->hue = hue;
1092
1093 /* -128 to 127 */
1094 value = (hue >> 8) - 128;
1095 btwrite(value & 0xff, BT848_HUE);
1096}
1097
1098static void bt848_contrast(struct bttv *btv, int cont)
1099{
1100 int value,hibit;
1101
1102 btv->contrast = cont;
1103
1104 /* 0-511 */
1105 value = (cont >> 7);
1106 hibit = (value >> 6) & 4;
1107 btwrite(value & 0xff, BT848_CONTRAST_LO);
1108 btaor(hibit, ~4, BT848_E_CONTROL);
1109 btaor(hibit, ~4, BT848_O_CONTROL);
1110}
1111
1112static void bt848_sat(struct bttv *btv, int color)
1113{
1114 int val_u,val_v,hibits;
1115
1116 btv->saturation = color;
1117
1118 /* 0-511 for the color */
1119 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
1120 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
1121 hibits = (val_u >> 7) & 2;
1122 hibits |= (val_v >> 8) & 1;
1123 btwrite(val_u & 0xff, BT848_SAT_U_LO);
1124 btwrite(val_v & 0xff, BT848_SAT_V_LO);
1125 btaor(hibits, ~3, BT848_E_CONTROL);
1126 btaor(hibits, ~3, BT848_O_CONTROL);
1127}
1128
1129/* ----------------------------------------------------------------------- */
1130
1131static int
1132video_mux(struct bttv *btv, unsigned int input)
1133{
1134 int mux,mask2;
1135
1136 if (input >= bttv_tvcards[btv->c.type].video_inputs)
1137 return -EINVAL;
1138
1139 /* needed by RemoteVideo MX */
1140 mask2 = bttv_tvcards[btv->c.type].gpiomask2;
1141 if (mask2)
1142 gpio_inout(mask2,mask2);
1143
1144 if (input == btv->svhs) {
1145 btor(BT848_CONTROL_COMP, BT848_E_CONTROL);
1146 btor(BT848_CONTROL_COMP, BT848_O_CONTROL);
1147 } else {
1148 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
1149 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
1150 }
1151 mux = bttv_muxsel(btv, input);
1152 btaor(mux<<5, ~(3<<5), BT848_IFORM);
1153 dprintk(KERN_DEBUG "bttv%d: video mux: input=%d mux=%d\n",
1154 btv->c.nr,input,mux);
1155
1156 /* card specific hook */
1157 if(bttv_tvcards[btv->c.type].muxsel_hook)
1158 bttv_tvcards[btv->c.type].muxsel_hook (btv, input);
1159 return 0;
1160}
1161
1162static char *audio_modes[] = {
1163 "audio: tuner", "audio: radio", "audio: extern",
1164 "audio: intern", "audio: mute"
1165};
1166
1167static int
1168audio_mux(struct bttv *btv, int input, int mute)
1169{
1170 int gpio_val, signal;
1171 struct v4l2_control ctrl;
1172
1173 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
1174 bttv_tvcards[btv->c.type].gpiomask);
1175 signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC;
1176
1177 btv->mute = mute;
1178 btv->audio = input;
1179
1180 /* automute */
1181 mute = mute || (btv->opt_automute && !signal && !btv->radio_user);
1182
1183 if (mute)
1184 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
1185 else
1186 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
1187
1188 switch (btv->c.type) {
1189 case BTTV_BOARD_VOODOOTV_FM:
1190 case BTTV_BOARD_VOODOOTV_200:
1191 gpio_val = bttv_tda9880_setnorm(btv, gpio_val);
1192 break;
1193
1194 default:
1195 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
1196 }
1197
1198 if (bttv_gpio)
1199 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
1200 if (in_interrupt())
1201 return 0;
1202
1203 ctrl.id = V4L2_CID_AUDIO_MUTE;
1204 ctrl.value = btv->mute;
1205 bttv_call_all(btv, core, s_ctrl, &ctrl);
1206 if (btv->sd_msp34xx) {
1207 u32 in;
1208
1209 /* Note: the inputs tuner/radio/extern/intern are translated
1210 to msp routings. This assumes common behavior for all msp3400
1211 based TV cards. When this assumption fails, then the
1212 specific MSP routing must be added to the card table.
1213 For now this is sufficient. */
1214 switch (input) {
1215 case TVAUDIO_INPUT_RADIO:
1216 in = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1,
1217 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
1218 break;
1219 case TVAUDIO_INPUT_EXTERN:
1220 in = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
1221 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
1222 break;
1223 case TVAUDIO_INPUT_INTERN:
1224 /* Yes, this is the same input as for RADIO. I doubt
1225 if this is ever used. The only board with an INTERN
1226 input is the BTTV_BOARD_AVERMEDIA98. I wonder how
1227 that was tested. My guess is that the whole INTERN
1228 input does not work. */
1229 in = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1,
1230 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
1231 break;
1232 case TVAUDIO_INPUT_TUNER:
1233 default:
1234 /* This is the only card that uses TUNER2, and afaik,
1235 is the only difference between the VOODOOTV_FM
1236 and VOODOOTV_200 */
1237 if (btv->c.type == BTTV_BOARD_VOODOOTV_200)
1238 in = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER2, \
1239 MSP_DSP_IN_TUNER, MSP_DSP_IN_TUNER);
1240 else
1241 in = MSP_INPUT_DEFAULT;
1242 break;
1243 }
1244 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing,
1245 in, MSP_OUTPUT_DEFAULT, 0);
1246 }
1247 if (btv->sd_tvaudio) {
1248 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
1249 input, 0, 0);
1250 }
1251 return 0;
1252}
1253
1254static inline int
1255audio_mute(struct bttv *btv, int mute)
1256{
1257 return audio_mux(btv, btv->audio, mute);
1258}
1259
1260static inline int
1261audio_input(struct bttv *btv, int input)
1262{
1263 return audio_mux(btv, input, btv->mute);
1264}
1265
1266static void
1267bttv_crop_calc_limits(struct bttv_crop *c)
1268{
1269 /* Scale factor min. 1:1, max. 16:1. Min. image size
1270 48 x 32. Scaled width must be a multiple of 4. */
1271
1272 if (1) {
1273 /* For bug compatibility with VIDIOCGCAP and image
1274 size checks in earlier driver versions. */
1275 c->min_scaled_width = 48;
1276 c->min_scaled_height = 32;
1277 } else {
1278 c->min_scaled_width =
1279 (max(48, c->rect.width >> 4) + 3) & ~3;
1280 c->min_scaled_height =
1281 max(32, c->rect.height >> 4);
1282 }
1283
1284 c->max_scaled_width = c->rect.width & ~3;
1285 c->max_scaled_height = c->rect.height;
1286}
1287
1288static void
1289bttv_crop_reset(struct bttv_crop *c, unsigned int norm)
1290{
1291 c->rect = bttv_tvnorms[norm].cropcap.defrect;
1292 bttv_crop_calc_limits(c);
1293}
1294
1295/* Call with btv->lock down. */
1296static int
1297set_tvnorm(struct bttv *btv, unsigned int norm)
1298{
1299 const struct bttv_tvnorm *tvnorm;
1300 v4l2_std_id id;
1301
1302 BUG_ON(norm >= BTTV_TVNORMS);
1303 BUG_ON(btv->tvnorm >= BTTV_TVNORMS);
1304
1305 tvnorm = &bttv_tvnorms[norm];
1306
1307 if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap,
1308 sizeof (tvnorm->cropcap))) {
1309 bttv_crop_reset(&btv->crop[0], norm);
1310 btv->crop[1] = btv->crop[0]; /* current = default */
1311
1312 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1313 btv->crop_start = tvnorm->cropcap.bounds.top
1314 + tvnorm->cropcap.bounds.height;
1315 }
1316 }
1317
1318 btv->tvnorm = norm;
1319
1320 btwrite(tvnorm->adelay, BT848_ADELAY);
1321 btwrite(tvnorm->bdelay, BT848_BDELAY);
1322 btaor(tvnorm->iform,~(BT848_IFORM_NORM|BT848_IFORM_XTBOTH),
1323 BT848_IFORM);
1324 btwrite(tvnorm->vbipack, BT848_VBI_PACK_SIZE);
1325 btwrite(1, BT848_VBI_PACK_DEL);
1326 bt848A_set_timing(btv);
1327
1328 switch (btv->c.type) {
1329 case BTTV_BOARD_VOODOOTV_FM:
1330 case BTTV_BOARD_VOODOOTV_200:
1331 bttv_tda9880_setnorm(btv, gpio_read());
1332 break;
1333 }
1334 id = tvnorm->v4l2_id;
1335 bttv_call_all(btv, core, s_std, id);
1336
1337 return 0;
1338}
1339
1340/* Call with btv->lock down. */
1341static void
1342set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1343{
1344 unsigned long flags;
1345
1346 btv->input = input;
1347 if (irq_iswitch) {
1348 spin_lock_irqsave(&btv->s_lock,flags);
1349 if (btv->curr.frame_irq) {
1350 /* active capture -> delayed input switch */
1351 btv->new_input = input;
1352 } else {
1353 video_mux(btv,input);
1354 }
1355 spin_unlock_irqrestore(&btv->s_lock,flags);
1356 } else {
1357 video_mux(btv,input);
1358 }
1359 audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1360 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN);
1361 set_tvnorm(btv, norm);
1362}
1363
1364static void init_irqreg(struct bttv *btv)
1365{
1366 /* clear status */
1367 btwrite(0xfffffUL, BT848_INT_STAT);
1368
1369 if (bttv_tvcards[btv->c.type].no_video) {
1370 /* i2c only */
1371 btwrite(BT848_INT_I2CDONE,
1372 BT848_INT_MASK);
1373 } else {
1374 /* full video */
1375 btwrite((btv->triton1) |
1376 (btv->gpioirq ? BT848_INT_GPINT : 0) |
1377 BT848_INT_SCERR |
1378 (fdsr ? BT848_INT_FDSR : 0) |
1379 BT848_INT_RISCI | BT848_INT_OCERR |
1380 BT848_INT_FMTCHG|BT848_INT_HLOCK|
1381 BT848_INT_I2CDONE,
1382 BT848_INT_MASK);
1383 }
1384}
1385
1386static void init_bt848(struct bttv *btv)
1387{
1388 int val;
1389
1390 if (bttv_tvcards[btv->c.type].no_video) {
1391 /* very basic init only */
1392 init_irqreg(btv);
1393 return;
1394 }
1395
1396 btwrite(0x00, BT848_CAP_CTL);
1397 btwrite(BT848_COLOR_CTL_GAMMA, BT848_COLOR_CTL);
1398 btwrite(BT848_IFORM_XTAUTO | BT848_IFORM_AUTO, BT848_IFORM);
1399
1400 /* set planar and packed mode trigger points and */
1401 /* set rising edge of inverted GPINTR pin as irq trigger */
1402 btwrite(BT848_GPIO_DMA_CTL_PKTP_32|
1403 BT848_GPIO_DMA_CTL_PLTP1_16|
1404 BT848_GPIO_DMA_CTL_PLTP23_16|
1405 BT848_GPIO_DMA_CTL_GPINTC|
1406 BT848_GPIO_DMA_CTL_GPINTI,
1407 BT848_GPIO_DMA_CTL);
1408
1409 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1410 btwrite(val, BT848_E_SCLOOP);
1411 btwrite(val, BT848_O_SCLOOP);
1412
1413 btwrite(0x20, BT848_E_VSCALE_HI);
1414 btwrite(0x20, BT848_O_VSCALE_HI);
1415 btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1416 BT848_ADC);
1417
1418 btwrite(whitecrush_upper, BT848_WC_UP);
1419 btwrite(whitecrush_lower, BT848_WC_DOWN);
1420
1421 if (btv->opt_lumafilter) {
1422 btwrite(0, BT848_E_CONTROL);
1423 btwrite(0, BT848_O_CONTROL);
1424 } else {
1425 btwrite(BT848_CONTROL_LDEC, BT848_E_CONTROL);
1426 btwrite(BT848_CONTROL_LDEC, BT848_O_CONTROL);
1427 }
1428
1429 bt848_bright(btv, btv->bright);
1430 bt848_hue(btv, btv->hue);
1431 bt848_contrast(btv, btv->contrast);
1432 bt848_sat(btv, btv->saturation);
1433
1434 /* interrupt */
1435 init_irqreg(btv);
1436}
1437
1438static void bttv_reinit_bt848(struct bttv *btv)
1439{
1440 unsigned long flags;
1441
1442 if (bttv_verbose)
1443 printk(KERN_INFO "bttv%d: reset, reinitialize\n",btv->c.nr);
1444 spin_lock_irqsave(&btv->s_lock,flags);
1445 btv->errors=0;
1446 bttv_set_dma(btv,0);
1447 spin_unlock_irqrestore(&btv->s_lock,flags);
1448
1449 init_bt848(btv);
1450 btv->pll.pll_current = -1;
1451 set_input(btv, btv->input, btv->tvnorm);
1452}
1453
1454static int bttv_g_ctrl(struct file *file, void *priv,
1455 struct v4l2_control *c)
1456{
1457 struct bttv_fh *fh = priv;
1458 struct bttv *btv = fh->btv;
1459
1460 switch (c->id) {
1461 case V4L2_CID_BRIGHTNESS:
1462 c->value = btv->bright;
1463 break;
1464 case V4L2_CID_HUE:
1465 c->value = btv->hue;
1466 break;
1467 case V4L2_CID_CONTRAST:
1468 c->value = btv->contrast;
1469 break;
1470 case V4L2_CID_SATURATION:
1471 c->value = btv->saturation;
1472 break;
1473
1474 case V4L2_CID_AUDIO_MUTE:
1475 case V4L2_CID_AUDIO_VOLUME:
1476 case V4L2_CID_AUDIO_BALANCE:
1477 case V4L2_CID_AUDIO_BASS:
1478 case V4L2_CID_AUDIO_TREBLE:
1479 bttv_call_all(btv, core, g_ctrl, c);
1480 break;
1481
1482 case V4L2_CID_PRIVATE_CHROMA_AGC:
1483 c->value = btv->opt_chroma_agc;
1484 break;
1485 case V4L2_CID_PRIVATE_COMBFILTER:
1486 c->value = btv->opt_combfilter;
1487 break;
1488 case V4L2_CID_PRIVATE_LUMAFILTER:
1489 c->value = btv->opt_lumafilter;
1490 break;
1491 case V4L2_CID_PRIVATE_AUTOMUTE:
1492 c->value = btv->opt_automute;
1493 break;
1494 case V4L2_CID_PRIVATE_AGC_CRUSH:
1495 c->value = btv->opt_adc_crush;
1496 break;
1497 case V4L2_CID_PRIVATE_VCR_HACK:
1498 c->value = btv->opt_vcr_hack;
1499 break;
1500 case V4L2_CID_PRIVATE_WHITECRUSH_UPPER:
1501 c->value = btv->opt_whitecrush_upper;
1502 break;
1503 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER:
1504 c->value = btv->opt_whitecrush_lower;
1505 break;
1506 case V4L2_CID_PRIVATE_UV_RATIO:
1507 c->value = btv->opt_uv_ratio;
1508 break;
1509 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1510 c->value = btv->opt_full_luma_range;
1511 break;
1512 case V4L2_CID_PRIVATE_CORING:
1513 c->value = btv->opt_coring;
1514 break;
1515 default:
1516 return -EINVAL;
1517 }
1518 return 0;
1519}
1520
1521static int bttv_s_ctrl(struct file *file, void *f,
1522 struct v4l2_control *c)
1523{
1524 int err;
1525 int val;
1526 struct bttv_fh *fh = f;
1527 struct bttv *btv = fh->btv;
1528
1529 err = v4l2_prio_check(&btv->prio, fh->prio);
1530 if (0 != err)
1531 return err;
1532
1533 switch (c->id) {
1534 case V4L2_CID_BRIGHTNESS:
1535 bt848_bright(btv, c->value);
1536 break;
1537 case V4L2_CID_HUE:
1538 bt848_hue(btv, c->value);
1539 break;
1540 case V4L2_CID_CONTRAST:
1541 bt848_contrast(btv, c->value);
1542 break;
1543 case V4L2_CID_SATURATION:
1544 bt848_sat(btv, c->value);
1545 break;
1546 case V4L2_CID_AUDIO_MUTE:
1547 audio_mute(btv, c->value);
1548 /* fall through */
1549 case V4L2_CID_AUDIO_VOLUME:
1550 if (btv->volume_gpio)
1551 btv->volume_gpio(btv, c->value);
1552
1553 bttv_call_all(btv, core, s_ctrl, c);
1554 break;
1555 case V4L2_CID_AUDIO_BALANCE:
1556 case V4L2_CID_AUDIO_BASS:
1557 case V4L2_CID_AUDIO_TREBLE:
1558 bttv_call_all(btv, core, s_ctrl, c);
1559 break;
1560
1561 case V4L2_CID_PRIVATE_CHROMA_AGC:
1562 btv->opt_chroma_agc = c->value;
1563 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1564 btwrite(val, BT848_E_SCLOOP);
1565 btwrite(val, BT848_O_SCLOOP);
1566 break;
1567 case V4L2_CID_PRIVATE_COMBFILTER:
1568 btv->opt_combfilter = c->value;
1569 break;
1570 case V4L2_CID_PRIVATE_LUMAFILTER:
1571 btv->opt_lumafilter = c->value;
1572 if (btv->opt_lumafilter) {
1573 btand(~BT848_CONTROL_LDEC, BT848_E_CONTROL);
1574 btand(~BT848_CONTROL_LDEC, BT848_O_CONTROL);
1575 } else {
1576 btor(BT848_CONTROL_LDEC, BT848_E_CONTROL);
1577 btor(BT848_CONTROL_LDEC, BT848_O_CONTROL);
1578 }
1579 break;
1580 case V4L2_CID_PRIVATE_AUTOMUTE:
1581 btv->opt_automute = c->value;
1582 break;
1583 case V4L2_CID_PRIVATE_AGC_CRUSH:
1584 btv->opt_adc_crush = c->value;
1585 btwrite(BT848_ADC_RESERVED |
1586 (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1587 BT848_ADC);
1588 break;
1589 case V4L2_CID_PRIVATE_VCR_HACK:
1590 btv->opt_vcr_hack = c->value;
1591 break;
1592 case V4L2_CID_PRIVATE_WHITECRUSH_UPPER:
1593 btv->opt_whitecrush_upper = c->value;
1594 btwrite(c->value, BT848_WC_UP);
1595 break;
1596 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER:
1597 btv->opt_whitecrush_lower = c->value;
1598 btwrite(c->value, BT848_WC_DOWN);
1599 break;
1600 case V4L2_CID_PRIVATE_UV_RATIO:
1601 btv->opt_uv_ratio = c->value;
1602 bt848_sat(btv, btv->saturation);
1603 break;
1604 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1605 btv->opt_full_luma_range = c->value;
1606 btaor((c->value<<7), ~BT848_OFORM_RANGE, BT848_OFORM);
1607 break;
1608 case V4L2_CID_PRIVATE_CORING:
1609 btv->opt_coring = c->value;
1610 btaor((c->value<<5), ~BT848_OFORM_CORE32, BT848_OFORM);
1611 break;
1612 default:
1613 return -EINVAL;
1614 }
1615 return 0;
1616}
1617
1618/* ----------------------------------------------------------------------- */
1619
1620void bttv_gpio_tracking(struct bttv *btv, char *comment)
1621{
1622 unsigned int outbits, data;
1623 outbits = btread(BT848_GPIO_OUT_EN);
1624 data = btread(BT848_GPIO_DATA);
1625 printk(KERN_DEBUG "bttv%d: gpio: en=%08x, out=%08x in=%08x [%s]\n",
1626 btv->c.nr,outbits,data & outbits, data & ~outbits, comment);
1627}
1628
1629static void bttv_field_count(struct bttv *btv)
1630{
1631 int need_count = 0;
1632
1633 if (btv->users)
1634 need_count++;
1635
1636 if (need_count) {
1637 /* start field counter */
1638 btor(BT848_INT_VSYNC,BT848_INT_MASK);
1639 } else {
1640 /* stop field counter */
1641 btand(~BT848_INT_VSYNC,BT848_INT_MASK);
1642 btv->field_count = 0;
1643 }
1644}
1645
1646static const struct bttv_format*
1647format_by_fourcc(int fourcc)
1648{
1649 unsigned int i;
1650
1651 for (i = 0; i < FORMATS; i++) {
1652 if (-1 == formats[i].fourcc)
1653 continue;
1654 if (formats[i].fourcc == fourcc)
1655 return formats+i;
1656 }
1657 return NULL;
1658}
1659
1660/* ----------------------------------------------------------------------- */
1661/* misc helpers */
1662
1663static int
1664bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1665 struct bttv_buffer *new)
1666{
1667 struct bttv_buffer *old;
1668 unsigned long flags;
1669 int retval = 0;
1670
1671 dprintk("switch_overlay: enter [new=%p]\n",new);
1672 if (new)
1673 new->vb.state = VIDEOBUF_DONE;
1674 spin_lock_irqsave(&btv->s_lock,flags);
1675 old = btv->screen;
1676 btv->screen = new;
1677 btv->loop_irq |= 1;
1678 bttv_set_dma(btv, 0x03);
1679 spin_unlock_irqrestore(&btv->s_lock,flags);
1680 if (NULL != old) {
1681 dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state);
1682 bttv_dma_free(&fh->cap,btv, old);
1683 kfree(old);
1684 }
1685 if (NULL == new)
1686 free_btres_lock(btv,fh,RESOURCE_OVERLAY);
1687 dprintk("switch_overlay: done\n");
1688 return retval;
1689}
1690
1691/* ----------------------------------------------------------------------- */
1692/* video4linux (1) interface */
1693
1694static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1695 struct bttv_buffer *buf,
1696 const struct bttv_format *fmt,
1697 unsigned int width, unsigned int height,
1698 enum v4l2_field field)
1699{
1700 struct bttv_fh *fh = q->priv_data;
1701 int redo_dma_risc = 0;
1702 struct bttv_crop c;
1703 int norm;
1704 int rc;
1705
1706 /* check settings */
1707 if (NULL == fmt)
1708 return -EINVAL;
1709 if (fmt->btformat == BT848_COLOR_FMT_RAW) {
1710 width = RAW_BPL;
1711 height = RAW_LINES*2;
1712 if (width*height > buf->vb.bsize)
1713 return -EINVAL;
1714 buf->vb.size = buf->vb.bsize;
1715
1716 /* Make sure tvnorm and vbi_end remain consistent
1717 until we're done. */
1718
1719 norm = btv->tvnorm;
1720
1721 /* In this mode capturing always starts at defrect.top
1722 (default VDELAY), ignoring cropping parameters. */
1723 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1724 return -EINVAL;
1725 }
1726
1727 c.rect = bttv_tvnorms[norm].cropcap.defrect;
1728 } else {
1729 norm = btv->tvnorm;
1730 c = btv->crop[!!fh->do_crop];
1731
1732 if (width < c.min_scaled_width ||
1733 width > c.max_scaled_width ||
1734 height < c.min_scaled_height)
1735 return -EINVAL;
1736
1737 switch (field) {
1738 case V4L2_FIELD_TOP:
1739 case V4L2_FIELD_BOTTOM:
1740 case V4L2_FIELD_ALTERNATE:
1741 /* btv->crop counts frame lines. Max. scale
1742 factor is 16:1 for frames, 8:1 for fields. */
1743 if (height * 2 > c.max_scaled_height)
1744 return -EINVAL;
1745 break;
1746
1747 default:
1748 if (height > c.max_scaled_height)
1749 return -EINVAL;
1750 break;
1751 }
1752
1753 buf->vb.size = (width * height * fmt->depth) >> 3;
1754 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
1755 return -EINVAL;
1756 }
1757
1758 /* alloc + fill struct bttv_buffer (if changed) */
1759 if (buf->vb.width != width || buf->vb.height != height ||
1760 buf->vb.field != field ||
1761 buf->tvnorm != norm || buf->fmt != fmt ||
1762 buf->crop.top != c.rect.top ||
1763 buf->crop.left != c.rect.left ||
1764 buf->crop.width != c.rect.width ||
1765 buf->crop.height != c.rect.height) {
1766 buf->vb.width = width;
1767 buf->vb.height = height;
1768 buf->vb.field = field;
1769 buf->tvnorm = norm;
1770 buf->fmt = fmt;
1771 buf->crop = c.rect;
1772 redo_dma_risc = 1;
1773 }
1774
1775 /* alloc risc memory */
1776 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1777 redo_dma_risc = 1;
1778 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf)))
1779 goto fail;
1780 }
1781
1782 if (redo_dma_risc)
1783 if (0 != (rc = bttv_buffer_risc(btv,buf)))
1784 goto fail;
1785
1786 buf->vb.state = VIDEOBUF_PREPARED;
1787 return 0;
1788
1789 fail:
1790 bttv_dma_free(q,btv,buf);
1791 return rc;
1792}
1793
1794static int
1795buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
1796{
1797 struct bttv_fh *fh = q->priv_data;
1798
1799 *size = fh->fmt->depth*fh->width*fh->height >> 3;
1800 if (0 == *count)
1801 *count = gbuffers;
1802 if (*size * *count > gbuffers * gbufsize)
1803 *count = (gbuffers * gbufsize) / *size;
1804 return 0;
1805}
1806
1807static int
1808buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
1809 enum v4l2_field field)
1810{
1811 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
1812 struct bttv_fh *fh = q->priv_data;
1813
1814 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt,
1815 fh->width, fh->height, field);
1816}
1817
1818static void
1819buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1820{
1821 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
1822 struct bttv_fh *fh = q->priv_data;
1823 struct bttv *btv = fh->btv;
1824
1825 buf->vb.state = VIDEOBUF_QUEUED;
1826 list_add_tail(&buf->vb.queue,&btv->capture);
1827 if (!btv->curr.frame_irq) {
1828 btv->loop_irq |= 1;
1829 bttv_set_dma(btv, 0x03);
1830 }
1831}
1832
1833static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1834{
1835 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
1836 struct bttv_fh *fh = q->priv_data;
1837
1838 bttv_dma_free(q,fh->btv,buf);
1839}
1840
1841static struct videobuf_queue_ops bttv_video_qops = {
1842 .buf_setup = buffer_setup,
1843 .buf_prepare = buffer_prepare,
1844 .buf_queue = buffer_queue,
1845 .buf_release = buffer_release,
1846};
1847
1848static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)
1849{
1850 struct bttv_fh *fh = priv;
1851 struct bttv *btv = fh->btv;
1852 unsigned int i;
1853 int err;
1854
1855 err = v4l2_prio_check(&btv->prio, fh->prio);
1856 if (err)
1857 goto err;
1858
1859 for (i = 0; i < BTTV_TVNORMS; i++)
1860 if (*id & bttv_tvnorms[i].v4l2_id)
1861 break;
1862 if (i == BTTV_TVNORMS) {
1863 err = -EINVAL;
1864 goto err;
1865 }
1866
1867 set_tvnorm(btv, i);
1868
1869err:
1870
1871 return err;
1872}
1873
1874static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id)
1875{
1876 struct bttv_fh *fh = f;
1877 struct bttv *btv = fh->btv;
1878
1879 if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML)
1880 *id = V4L2_STD_625_50;
1881 else
1882 *id = V4L2_STD_525_60;
1883 return 0;
1884}
1885
1886static int bttv_enum_input(struct file *file, void *priv,
1887 struct v4l2_input *i)
1888{
1889 struct bttv_fh *fh = priv;
1890 struct bttv *btv = fh->btv;
1891 int rc = 0;
1892
1893 if (i->index >= bttv_tvcards[btv->c.type].video_inputs) {
1894 rc = -EINVAL;
1895 goto err;
1896 }
1897
1898 i->type = V4L2_INPUT_TYPE_CAMERA;
1899 i->audioset = 1;
1900
1901 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) {
1902 sprintf(i->name, "Television");
1903 i->type = V4L2_INPUT_TYPE_TUNER;
1904 i->tuner = 0;
1905 } else if (i->index == btv->svhs) {
1906 sprintf(i->name, "S-Video");
1907 } else {
1908 sprintf(i->name, "Composite%d", i->index);
1909 }
1910
1911 if (i->index == btv->input) {
1912 __u32 dstatus = btread(BT848_DSTATUS);
1913 if (0 == (dstatus & BT848_DSTATUS_PRES))
1914 i->status |= V4L2_IN_ST_NO_SIGNAL;
1915 if (0 == (dstatus & BT848_DSTATUS_HLOC))
1916 i->status |= V4L2_IN_ST_NO_H_LOCK;
1917 }
1918
1919 i->std = BTTV_NORMS;
1920
1921err:
1922
1923 return rc;
1924}
1925
1926static int bttv_g_input(struct file *file, void *priv, unsigned int *i)
1927{
1928 struct bttv_fh *fh = priv;
1929 struct bttv *btv = fh->btv;
1930
1931 *i = btv->input;
1932
1933 return 0;
1934}
1935
1936static int bttv_s_input(struct file *file, void *priv, unsigned int i)
1937{
1938 struct bttv_fh *fh = priv;
1939 struct bttv *btv = fh->btv;
1940
1941 int err;
1942
1943 err = v4l2_prio_check(&btv->prio, fh->prio);
1944 if (unlikely(err))
1945 goto err;
1946
1947 if (i > bttv_tvcards[btv->c.type].video_inputs) {
1948 err = -EINVAL;
1949 goto err;
1950 }
1951
1952 set_input(btv, i, btv->tvnorm);
1953
1954err:
1955 return 0;
1956}
1957
1958static int bttv_s_tuner(struct file *file, void *priv,
1959 struct v4l2_tuner *t)
1960{
1961 struct bttv_fh *fh = priv;
1962 struct bttv *btv = fh->btv;
1963 int err;
1964
1965 if (unlikely(0 != t->index))
1966 return -EINVAL;
1967
1968 if (unlikely(btv->tuner_type == TUNER_ABSENT)) {
1969 err = -EINVAL;
1970 goto err;
1971 }
1972
1973 err = v4l2_prio_check(&btv->prio, fh->prio);
1974 if (unlikely(err))
1975 goto err;
1976
1977 bttv_call_all(btv, tuner, s_tuner, t);
1978
1979 if (btv->audio_mode_gpio)
1980 btv->audio_mode_gpio(btv, t, 1);
1981
1982err:
1983
1984 return 0;
1985}
1986
1987static int bttv_g_frequency(struct file *file, void *priv,
1988 struct v4l2_frequency *f)
1989{
1990 struct bttv_fh *fh = priv;
1991 struct bttv *btv = fh->btv;
1992
1993 f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1994 f->frequency = btv->freq;
1995
1996 return 0;
1997}
1998
1999static int bttv_s_frequency(struct file *file, void *priv,
2000 struct v4l2_frequency *f)
2001{
2002 struct bttv_fh *fh = priv;
2003 struct bttv *btv = fh->btv;
2004 int err;
2005
2006 if (unlikely(f->tuner != 0))
2007 return -EINVAL;
2008
2009 err = v4l2_prio_check(&btv->prio, fh->prio);
2010 if (unlikely(err))
2011 goto err;
2012
2013 if (unlikely(f->type != (btv->radio_user
2014 ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV))) {
2015 err = -EINVAL;
2016 goto err;
2017 }
2018 btv->freq = f->frequency;
2019 bttv_call_all(btv, tuner, s_frequency, f);
2020 if (btv->has_matchbox && btv->radio_user)
2021 tea5757_set_freq(btv, btv->freq);
2022err:
2023
2024 return 0;
2025}
2026
2027static int bttv_log_status(struct file *file, void *f)
2028{
2029 struct bttv_fh *fh = f;
2030 struct bttv *btv = fh->btv;
2031
2032 printk(KERN_INFO "bttv%d: ======== START STATUS CARD #%d ========\n",
2033 btv->c.nr, btv->c.nr);
2034 bttv_call_all(btv, core, log_status);
2035 printk(KERN_INFO "bttv%d: ======== END STATUS CARD #%d ========\n",
2036 btv->c.nr, btv->c.nr);
2037 return 0;
2038}
2039
2040#ifdef CONFIG_VIDEO_ADV_DEBUG
2041static int bttv_g_register(struct file *file, void *f,
2042 struct v4l2_dbg_register *reg)
2043{
2044 struct bttv_fh *fh = f;
2045 struct bttv *btv = fh->btv;
2046
2047 if (!capable(CAP_SYS_ADMIN))
2048 return -EPERM;
2049
2050 if (!v4l2_chip_match_host(&reg->match))
2051 return -EINVAL;
2052
2053 /* bt848 has a 12-bit register space */
2054 reg->reg &= 0xfff;
2055 reg->val = btread(reg->reg);
2056 reg->size = 1;
2057
2058 return 0;
2059}
2060
2061static int bttv_s_register(struct file *file, void *f,
2062 struct v4l2_dbg_register *reg)
2063{
2064 struct bttv_fh *fh = f;
2065 struct bttv *btv = fh->btv;
2066
2067 if (!capable(CAP_SYS_ADMIN))
2068 return -EPERM;
2069
2070 if (!v4l2_chip_match_host(&reg->match))
2071 return -EINVAL;
2072
2073 /* bt848 has a 12-bit register space */
2074 reg->reg &= 0xfff;
2075 btwrite(reg->val, reg->reg);
2076
2077 return 0;
2078}
2079#endif
2080
2081/* Given cropping boundaries b and the scaled width and height of a
2082 single field or frame, which must not exceed hardware limits, this
2083 function adjusts the cropping parameters c. */
2084static void
2085bttv_crop_adjust (struct bttv_crop * c,
2086 const struct v4l2_rect * b,
2087 __s32 width,
2088 __s32 height,
2089 enum v4l2_field field)
2090{
2091 __s32 frame_height = height << !V4L2_FIELD_HAS_BOTH(field);
2092 __s32 max_left;
2093 __s32 max_top;
2094
2095 if (width < c->min_scaled_width) {
2096 /* Max. hor. scale factor 16:1. */
2097 c->rect.width = width * 16;
2098 } else if (width > c->max_scaled_width) {
2099 /* Min. hor. scale factor 1:1. */
2100 c->rect.width = width;
2101
2102 max_left = b->left + b->width - width;
2103 max_left = min(max_left, (__s32) MAX_HDELAY);
2104 if (c->rect.left > max_left)
2105 c->rect.left = max_left;
2106 }
2107
2108 if (height < c->min_scaled_height) {
2109 /* Max. vert. scale factor 16:1, single fields 8:1. */
2110 c->rect.height = height * 16;
2111 } else if (frame_height > c->max_scaled_height) {
2112 /* Min. vert. scale factor 1:1.
2113 Top and height count field lines times two. */
2114 c->rect.height = (frame_height + 1) & ~1;
2115
2116 max_top = b->top + b->height - c->rect.height;
2117 if (c->rect.top > max_top)
2118 c->rect.top = max_top;
2119 }
2120
2121 bttv_crop_calc_limits(c);
2122}
2123
2124/* Returns an error if scaling to a frame or single field with the given
2125 width and height is not possible with the current cropping parameters
2126 and width aligned according to width_mask. If adjust_size is TRUE the
2127 function may adjust the width and/or height instead, rounding width
2128 to (width + width_bias) & width_mask. If adjust_crop is TRUE it may
2129 also adjust the current cropping parameters to get closer to the
2130 desired image size. */
2131static int
2132limit_scaled_size_lock (struct bttv_fh * fh,
2133 __s32 * width,
2134 __s32 * height,
2135 enum v4l2_field field,
2136 unsigned int width_mask,
2137 unsigned int width_bias,
2138 int adjust_size,
2139 int adjust_crop)
2140{
2141 struct bttv *btv = fh->btv;
2142 const struct v4l2_rect *b;
2143 struct bttv_crop *c;
2144 __s32 min_width;
2145 __s32 min_height;
2146 __s32 max_width;
2147 __s32 max_height;
2148 int rc;
2149
2150 BUG_ON((int) width_mask >= 0 ||
2151 width_bias >= (unsigned int) -width_mask);
2152
2153 /* Make sure tvnorm, vbi_end and the current cropping parameters
2154 remain consistent until we're done. */
2155
2156 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2157
2158 /* Do crop - use current, don't - use default parameters. */
2159 c = &btv->crop[!!fh->do_crop];
2160
2161 if (fh->do_crop
2162 && adjust_size
2163 && adjust_crop
2164 && !locked_btres(btv, VIDEO_RESOURCES)) {
2165 min_width = 48;
2166 min_height = 32;
2167
2168 /* We cannot scale up. When the scaled image is larger
2169 than crop.rect we adjust the crop.rect as required
2170 by the V4L2 spec, hence cropcap.bounds are our limit. */
2171 max_width = min(b->width, (__s32) MAX_HACTIVE);
2172 max_height = b->height;
2173
2174 /* We cannot capture the same line as video and VBI data.
2175 Note btv->vbi_end is really a minimum, see
2176 bttv_vbi_try_fmt(). */
2177 if (btv->vbi_end > b->top) {
2178 max_height -= btv->vbi_end - b->top;
2179 rc = -EBUSY;
2180 if (min_height > max_height)
2181 goto fail;
2182 }
2183 } else {
2184 rc = -EBUSY;
2185 if (btv->vbi_end > c->rect.top)
2186 goto fail;
2187
2188 min_width = c->min_scaled_width;
2189 min_height = c->min_scaled_height;
2190 max_width = c->max_scaled_width;
2191 max_height = c->max_scaled_height;
2192
2193 adjust_crop = 0;
2194 }
2195
2196 min_width = (min_width - width_mask - 1) & width_mask;
2197 max_width = max_width & width_mask;
2198
2199 /* Max. scale factor is 16:1 for frames, 8:1 for fields. */
2200 min_height = min_height;
2201 /* Min. scale factor is 1:1. */
2202 max_height >>= !V4L2_FIELD_HAS_BOTH(field);
2203
2204 if (adjust_size) {
2205 *width = clamp(*width, min_width, max_width);
2206 *height = clamp(*height, min_height, max_height);
2207
2208 /* Round after clamping to avoid overflow. */
2209 *width = (*width + width_bias) & width_mask;
2210
2211 if (adjust_crop) {
2212 bttv_crop_adjust(c, b, *width, *height, field);
2213
2214 if (btv->vbi_end > c->rect.top) {
2215 /* Move the crop window out of the way. */
2216 c->rect.top = btv->vbi_end;
2217 }
2218 }
2219 } else {
2220 rc = -EINVAL;
2221 if (*width < min_width ||
2222 *height < min_height ||
2223 *width > max_width ||
2224 *height > max_height ||
2225 0 != (*width & ~width_mask))
2226 goto fail;
2227 }
2228
2229 rc = 0; /* success */
2230
2231 fail:
2232
2233 return rc;
2234}
2235
2236/* Returns an error if the given overlay window dimensions are not
2237 possible with the current cropping parameters. If adjust_size is
2238 TRUE the function may adjust the window width and/or height
2239 instead, however it always rounds the horizontal position and
2240 width as btcx_align() does. If adjust_crop is TRUE the function
2241 may also adjust the current cropping parameters to get closer
2242 to the desired window size. */
2243static int
2244verify_window_lock (struct bttv_fh * fh,
2245 struct v4l2_window * win,
2246 int adjust_size,
2247 int adjust_crop)
2248{
2249 enum v4l2_field field;
2250 unsigned int width_mask;
2251 int rc;
2252
2253 if (win->w.width < 48 || win->w.height < 32)
2254 return -EINVAL;
2255 if (win->clipcount > 2048)
2256 return -EINVAL;
2257
2258 field = win->field;
2259
2260 if (V4L2_FIELD_ANY == field) {
2261 __s32 height2;
2262
2263 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2264 field = (win->w.height > height2)
2265 ? V4L2_FIELD_INTERLACED
2266 : V4L2_FIELD_TOP;
2267 }
2268 switch (field) {
2269 case V4L2_FIELD_TOP:
2270 case V4L2_FIELD_BOTTOM:
2271 case V4L2_FIELD_INTERLACED:
2272 break;
2273 default:
2274 return -EINVAL;
2275 }
2276
2277 /* 4-byte alignment. */
2278 if (NULL == fh->ovfmt)
2279 return -EINVAL;
2280 width_mask = ~0;
2281 switch (fh->ovfmt->depth) {
2282 case 8:
2283 case 24:
2284 width_mask = ~3;
2285 break;
2286 case 16:
2287 width_mask = ~1;
2288 break;
2289 case 32:
2290 break;
2291 default:
2292 BUG();
2293 }
2294
2295 win->w.width -= win->w.left & ~width_mask;
2296 win->w.left = (win->w.left - width_mask - 1) & width_mask;
2297
2298 rc = limit_scaled_size_lock(fh, &win->w.width, &win->w.height,
2299 field, width_mask,
2300 /* width_bias: round down */ 0,
2301 adjust_size, adjust_crop);
2302 if (0 != rc)
2303 return rc;
2304
2305 win->field = field;
2306 return 0;
2307}
2308
2309static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,
2310 struct v4l2_window *win, int fixup)
2311{
2312 struct v4l2_clip *clips = NULL;
2313 int n,size,retval = 0;
2314
2315 if (NULL == fh->ovfmt)
2316 return -EINVAL;
2317 if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED))
2318 return -EINVAL;
2319 retval = verify_window_lock(fh, win,
2320 /* adjust_size */ fixup,
2321 /* adjust_crop */ fixup);
2322 if (0 != retval)
2323 return retval;
2324
2325 /* copy clips -- luckily v4l1 + v4l2 are binary
2326 compatible here ...*/
2327 n = win->clipcount;
2328 size = sizeof(*clips)*(n+4);
2329 clips = kmalloc(size,GFP_KERNEL);
2330 if (NULL == clips)
2331 return -ENOMEM;
2332 if (n > 0) {
2333 if (copy_from_user(clips,win->clips,sizeof(struct v4l2_clip)*n)) {
2334 kfree(clips);
2335 return -EFAULT;
2336 }
2337 }
2338
2339 /* clip against screen */
2340 if (NULL != btv->fbuf.base)
2341 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height,
2342 &win->w, clips, n);
2343 btcx_sort_clips(clips,n);
2344
2345 /* 4-byte alignments */
2346 switch (fh->ovfmt->depth) {
2347 case 8:
2348 case 24:
2349 btcx_align(&win->w, clips, n, 3);
2350 break;
2351 case 16:
2352 btcx_align(&win->w, clips, n, 1);
2353 break;
2354 case 32:
2355 /* no alignment fixups needed */
2356 break;
2357 default:
2358 BUG();
2359 }
2360
2361 kfree(fh->ov.clips);
2362 fh->ov.clips = clips;
2363 fh->ov.nclips = n;
2364
2365 fh->ov.w = win->w;
2366 fh->ov.field = win->field;
2367 fh->ov.setup_ok = 1;
2368
2369 btv->init.ov.w.width = win->w.width;
2370 btv->init.ov.w.height = win->w.height;
2371 btv->init.ov.field = win->field;
2372
2373 /* update overlay if needed */
2374 retval = 0;
2375 if (check_btres(fh, RESOURCE_OVERLAY)) {
2376 struct bttv_buffer *new;
2377
2378 new = videobuf_sg_alloc(sizeof(*new));
2379 new->crop = btv->crop[!!fh->do_crop].rect;
2380 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2381 retval = bttv_switch_overlay(btv,fh,new);
2382 }
2383 return retval;
2384}
2385
2386/* ----------------------------------------------------------------------- */
2387
2388static struct videobuf_queue* bttv_queue(struct bttv_fh *fh)
2389{
2390 struct videobuf_queue* q = NULL;
2391
2392 switch (fh->type) {
2393 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2394 q = &fh->cap;
2395 break;
2396 case V4L2_BUF_TYPE_VBI_CAPTURE:
2397 q = &fh->vbi;
2398 break;
2399 default:
2400 BUG();
2401 }
2402 return q;
2403}
2404
2405static int bttv_resource(struct bttv_fh *fh)
2406{
2407 int res = 0;
2408
2409 switch (fh->type) {
2410 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2411 res = RESOURCE_VIDEO_STREAM;
2412 break;
2413 case V4L2_BUF_TYPE_VBI_CAPTURE:
2414 res = RESOURCE_VBI;
2415 break;
2416 default:
2417 BUG();
2418 }
2419 return res;
2420}
2421
2422static int bttv_switch_type(struct bttv_fh *fh, enum v4l2_buf_type type)
2423{
2424 struct videobuf_queue *q = bttv_queue(fh);
2425 int res = bttv_resource(fh);
2426
2427 if (check_btres(fh,res))
2428 return -EBUSY;
2429 if (videobuf_queue_is_busy(q))
2430 return -EBUSY;
2431 fh->type = type;
2432 return 0;
2433}
2434
2435static void
2436pix_format_set_size (struct v4l2_pix_format * f,
2437 const struct bttv_format * fmt,
2438 unsigned int width,
2439 unsigned int height)
2440{
2441 f->width = width;
2442 f->height = height;
2443
2444 if (fmt->flags & FORMAT_FLAGS_PLANAR) {
2445 f->bytesperline = width; /* Y plane */
2446 f->sizeimage = (width * height * fmt->depth) >> 3;
2447 } else {
2448 f->bytesperline = (width * fmt->depth) >> 3;
2449 f->sizeimage = height * f->bytesperline;
2450 }
2451}
2452
2453static int bttv_g_fmt_vid_cap(struct file *file, void *priv,
2454 struct v4l2_format *f)
2455{
2456 struct bttv_fh *fh = priv;
2457
2458 pix_format_set_size(&f->fmt.pix, fh->fmt,
2459 fh->width, fh->height);
2460 f->fmt.pix.field = fh->cap.field;
2461 f->fmt.pix.pixelformat = fh->fmt->fourcc;
2462
2463 return 0;
2464}
2465
2466static int bttv_g_fmt_vid_overlay(struct file *file, void *priv,
2467 struct v4l2_format *f)
2468{
2469 struct bttv_fh *fh = priv;
2470
2471 f->fmt.win.w = fh->ov.w;
2472 f->fmt.win.field = fh->ov.field;
2473
2474 return 0;
2475}
2476
2477static int bttv_try_fmt_vid_cap(struct file *file, void *priv,
2478 struct v4l2_format *f)
2479{
2480 const struct bttv_format *fmt;
2481 struct bttv_fh *fh = priv;
2482 struct bttv *btv = fh->btv;
2483 enum v4l2_field field;
2484 __s32 width, height;
2485 int rc;
2486
2487 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2488 if (NULL == fmt)
2489 return -EINVAL;
2490
2491 field = f->fmt.pix.field;
2492
2493 if (V4L2_FIELD_ANY == field) {
2494 __s32 height2;
2495
2496 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2497 field = (f->fmt.pix.height > height2)
2498 ? V4L2_FIELD_INTERLACED
2499 : V4L2_FIELD_BOTTOM;
2500 }
2501
2502 if (V4L2_FIELD_SEQ_BT == field)
2503 field = V4L2_FIELD_SEQ_TB;
2504
2505 switch (field) {
2506 case V4L2_FIELD_TOP:
2507 case V4L2_FIELD_BOTTOM:
2508 case V4L2_FIELD_ALTERNATE:
2509 case V4L2_FIELD_INTERLACED:
2510 break;
2511 case V4L2_FIELD_SEQ_TB:
2512 if (fmt->flags & FORMAT_FLAGS_PLANAR)
2513 return -EINVAL;
2514 break;
2515 default:
2516 return -EINVAL;
2517 }
2518
2519 width = f->fmt.pix.width;
2520 height = f->fmt.pix.height;
2521
2522 rc = limit_scaled_size_lock(fh, &width, &height, field,
2523 /* width_mask: 4 pixels */ ~3,
2524 /* width_bias: nearest */ 2,
2525 /* adjust_size */ 1,
2526 /* adjust_crop */ 0);
2527 if (0 != rc)
2528 return rc;
2529
2530 /* update data for the application */
2531 f->fmt.pix.field = field;
2532 pix_format_set_size(&f->fmt.pix, fmt, width, height);
2533
2534 return 0;
2535}
2536
2537static int bttv_try_fmt_vid_overlay(struct file *file, void *priv,
2538 struct v4l2_format *f)
2539{
2540 struct bttv_fh *fh = priv;
2541
2542 return verify_window_lock(fh, &f->fmt.win,
2543 /* adjust_size */ 1,
2544 /* adjust_crop */ 0);
2545}
2546
2547static int bttv_s_fmt_vid_cap(struct file *file, void *priv,
2548 struct v4l2_format *f)
2549{
2550 int retval;
2551 const struct bttv_format *fmt;
2552 struct bttv_fh *fh = priv;
2553 struct bttv *btv = fh->btv;
2554 __s32 width, height;
2555 enum v4l2_field field;
2556
2557 retval = bttv_switch_type(fh, f->type);
2558 if (0 != retval)
2559 return retval;
2560
2561 retval = bttv_try_fmt_vid_cap(file, priv, f);
2562 if (0 != retval)
2563 return retval;
2564
2565 width = f->fmt.pix.width;
2566 height = f->fmt.pix.height;
2567 field = f->fmt.pix.field;
2568
2569 retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field,
2570 /* width_mask: 4 pixels */ ~3,
2571 /* width_bias: nearest */ 2,
2572 /* adjust_size */ 1,
2573 /* adjust_crop */ 1);
2574 if (0 != retval)
2575 return retval;
2576
2577 f->fmt.pix.field = field;
2578
2579 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2580
2581 /* update our state informations */
2582 fh->fmt = fmt;
2583 fh->cap.field = f->fmt.pix.field;
2584 fh->cap.last = V4L2_FIELD_NONE;
2585 fh->width = f->fmt.pix.width;
2586 fh->height = f->fmt.pix.height;
2587 btv->init.fmt = fmt;
2588 btv->init.width = f->fmt.pix.width;
2589 btv->init.height = f->fmt.pix.height;
2590
2591 return 0;
2592}
2593
2594static int bttv_s_fmt_vid_overlay(struct file *file, void *priv,
2595 struct v4l2_format *f)
2596{
2597 struct bttv_fh *fh = priv;
2598 struct bttv *btv = fh->btv;
2599
2600 if (no_overlay > 0) {
2601 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2602 return -EINVAL;
2603 }
2604
2605 return setup_window_lock(fh, btv, &f->fmt.win, 1);
2606}
2607
2608static int bttv_querycap(struct file *file, void *priv,
2609 struct v4l2_capability *cap)
2610{
2611 struct bttv_fh *fh = priv;
2612 struct bttv *btv = fh->btv;
2613
2614 if (0 == v4l2)
2615 return -EINVAL;
2616
2617 strlcpy(cap->driver, "bttv", sizeof(cap->driver));
2618 strlcpy(cap->card, btv->video_dev->name, sizeof(cap->card));
2619 snprintf(cap->bus_info, sizeof(cap->bus_info),
2620 "PCI:%s", pci_name(btv->c.pci));
2621 cap->capabilities =
2622 V4L2_CAP_VIDEO_CAPTURE |
2623 V4L2_CAP_VBI_CAPTURE |
2624 V4L2_CAP_READWRITE |
2625 V4L2_CAP_STREAMING;
2626 if (no_overlay <= 0)
2627 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
2628
2629 /*
2630 * No need to lock here: those vars are initialized during board
2631 * probe and remains untouched during the rest of the driver lifecycle
2632 */
2633 if (btv->has_saa6588)
2634 cap->capabilities |= V4L2_CAP_RDS_CAPTURE;
2635 if (btv->tuner_type != TUNER_ABSENT)
2636 cap->capabilities |= V4L2_CAP_TUNER;
2637 return 0;
2638}
2639
2640static int bttv_enum_fmt_cap_ovr(struct v4l2_fmtdesc *f)
2641{
2642 int index = -1, i;
2643
2644 for (i = 0; i < FORMATS; i++) {
2645 if (formats[i].fourcc != -1)
2646 index++;
2647 if ((unsigned int)index == f->index)
2648 break;
2649 }
2650 if (FORMATS == i)
2651 return -EINVAL;
2652
2653 f->pixelformat = formats[i].fourcc;
2654 strlcpy(f->description, formats[i].name, sizeof(f->description));
2655
2656 return i;
2657}
2658
2659static int bttv_enum_fmt_vid_cap(struct file *file, void *priv,
2660 struct v4l2_fmtdesc *f)
2661{
2662 int rc = bttv_enum_fmt_cap_ovr(f);
2663
2664 if (rc < 0)
2665 return rc;
2666
2667 return 0;
2668}
2669
2670static int bttv_enum_fmt_vid_overlay(struct file *file, void *priv,
2671 struct v4l2_fmtdesc *f)
2672{
2673 int rc;
2674
2675 if (no_overlay > 0) {
2676 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2677 return -EINVAL;
2678 }
2679
2680 rc = bttv_enum_fmt_cap_ovr(f);
2681
2682 if (rc < 0)
2683 return rc;
2684
2685 if (!(formats[rc].flags & FORMAT_FLAGS_PACKED))
2686 return -EINVAL;
2687
2688 return 0;
2689}
2690
2691static int bttv_g_fbuf(struct file *file, void *f,
2692 struct v4l2_framebuffer *fb)
2693{
2694 struct bttv_fh *fh = f;
2695 struct bttv *btv = fh->btv;
2696
2697 *fb = btv->fbuf;
2698 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
2699 if (fh->ovfmt)
2700 fb->fmt.pixelformat = fh->ovfmt->fourcc;
2701 return 0;
2702}
2703
2704static int bttv_overlay(struct file *file, void *f, unsigned int on)
2705{
2706 struct bttv_fh *fh = f;
2707 struct bttv *btv = fh->btv;
2708 struct bttv_buffer *new;
2709 int retval = 0;
2710
2711 if (on) {
2712 /* verify args */
2713 if (unlikely(!btv->fbuf.base)) {
2714 return -EINVAL;
2715 }
2716 if (unlikely(!fh->ov.setup_ok)) {
2717 dprintk("bttv%d: overlay: !setup_ok\n", btv->c.nr);
2718 retval = -EINVAL;
2719 }
2720 if (retval)
2721 return retval;
2722 }
2723
2724 if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY))
2725 return -EBUSY;
2726
2727 if (on) {
2728 fh->ov.tvnorm = btv->tvnorm;
2729 new = videobuf_sg_alloc(sizeof(*new));
2730 new->crop = btv->crop[!!fh->do_crop].rect;
2731 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2732 } else {
2733 new = NULL;
2734 }
2735
2736 /* switch over */
2737 retval = bttv_switch_overlay(btv, fh, new);
2738 return retval;
2739}
2740
2741static int bttv_s_fbuf(struct file *file, void *f,
2742 struct v4l2_framebuffer *fb)
2743{
2744 struct bttv_fh *fh = f;
2745 struct bttv *btv = fh->btv;
2746 const struct bttv_format *fmt;
2747 int retval;
2748
2749 if (!capable(CAP_SYS_ADMIN) &&
2750 !capable(CAP_SYS_RAWIO))
2751 return -EPERM;
2752
2753 /* check args */
2754 fmt = format_by_fourcc(fb->fmt.pixelformat);
2755 if (NULL == fmt)
2756 return -EINVAL;
2757 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED))
2758 return -EINVAL;
2759
2760 retval = -EINVAL;
2761 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) {
2762 __s32 width = fb->fmt.width;
2763 __s32 height = fb->fmt.height;
2764
2765 retval = limit_scaled_size_lock(fh, &width, &height,
2766 V4L2_FIELD_INTERLACED,
2767 /* width_mask */ ~3,
2768 /* width_bias */ 2,
2769 /* adjust_size */ 0,
2770 /* adjust_crop */ 0);
2771 if (0 != retval)
2772 return retval;
2773 }
2774
2775 /* ok, accept it */
2776 btv->fbuf.base = fb->base;
2777 btv->fbuf.fmt.width = fb->fmt.width;
2778 btv->fbuf.fmt.height = fb->fmt.height;
2779 if (0 != fb->fmt.bytesperline)
2780 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline;
2781 else
2782 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8;
2783
2784 retval = 0;
2785 fh->ovfmt = fmt;
2786 btv->init.ovfmt = fmt;
2787 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) {
2788 fh->ov.w.left = 0;
2789 fh->ov.w.top = 0;
2790 fh->ov.w.width = fb->fmt.width;
2791 fh->ov.w.height = fb->fmt.height;
2792 btv->init.ov.w.width = fb->fmt.width;
2793 btv->init.ov.w.height = fb->fmt.height;
2794 kfree(fh->ov.clips);
2795 fh->ov.clips = NULL;
2796 fh->ov.nclips = 0;
2797
2798 if (check_btres(fh, RESOURCE_OVERLAY)) {
2799 struct bttv_buffer *new;
2800
2801 new = videobuf_sg_alloc(sizeof(*new));
2802 new->crop = btv->crop[!!fh->do_crop].rect;
2803 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2804 retval = bttv_switch_overlay(btv, fh, new);
2805 }
2806 }
2807 return retval;
2808}
2809
2810static int bttv_reqbufs(struct file *file, void *priv,
2811 struct v4l2_requestbuffers *p)
2812{
2813 struct bttv_fh *fh = priv;
2814 return videobuf_reqbufs(bttv_queue(fh), p);
2815}
2816
2817static int bttv_querybuf(struct file *file, void *priv,
2818 struct v4l2_buffer *b)
2819{
2820 struct bttv_fh *fh = priv;
2821 return videobuf_querybuf(bttv_queue(fh), b);
2822}
2823
2824static int bttv_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2825{
2826 struct bttv_fh *fh = priv;
2827 struct bttv *btv = fh->btv;
2828 int res = bttv_resource(fh);
2829
2830 if (!check_alloc_btres_lock(btv, fh, res))
2831 return -EBUSY;
2832
2833 return videobuf_qbuf(bttv_queue(fh), b);
2834}
2835
2836static int bttv_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2837{
2838 struct bttv_fh *fh = priv;
2839 return videobuf_dqbuf(bttv_queue(fh), b,
2840 file->f_flags & O_NONBLOCK);
2841}
2842
2843static int bttv_streamon(struct file *file, void *priv,
2844 enum v4l2_buf_type type)
2845{
2846 struct bttv_fh *fh = priv;
2847 struct bttv *btv = fh->btv;
2848 int res = bttv_resource(fh);
2849
2850 if (!check_alloc_btres_lock(btv, fh, res))
2851 return -EBUSY;
2852 return videobuf_streamon(bttv_queue(fh));
2853}
2854
2855
2856static int bttv_streamoff(struct file *file, void *priv,
2857 enum v4l2_buf_type type)
2858{
2859 struct bttv_fh *fh = priv;
2860 struct bttv *btv = fh->btv;
2861 int retval;
2862 int res = bttv_resource(fh);
2863
2864
2865 retval = videobuf_streamoff(bttv_queue(fh));
2866 if (retval < 0)
2867 return retval;
2868 free_btres_lock(btv, fh, res);
2869 return 0;
2870}
2871
2872static int bttv_queryctrl(struct file *file, void *priv,
2873 struct v4l2_queryctrl *c)
2874{
2875 struct bttv_fh *fh = priv;
2876 struct bttv *btv = fh->btv;
2877 const struct v4l2_queryctrl *ctrl;
2878
2879 if ((c->id < V4L2_CID_BASE ||
2880 c->id >= V4L2_CID_LASTP1) &&
2881 (c->id < V4L2_CID_PRIVATE_BASE ||
2882 c->id >= V4L2_CID_PRIVATE_LASTP1))
2883 return -EINVAL;
2884
2885 if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME))
2886 *c = no_ctl;
2887 else {
2888 ctrl = ctrl_by_id(c->id);
2889
2890 *c = (NULL != ctrl) ? *ctrl : no_ctl;
2891 }
2892
2893 return 0;
2894}
2895
2896static int bttv_g_parm(struct file *file, void *f,
2897 struct v4l2_streamparm *parm)
2898{
2899 struct bttv_fh *fh = f;
2900 struct bttv *btv = fh->btv;
2901
2902 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2903 &parm->parm.capture.timeperframe);
2904
2905 return 0;
2906}
2907
2908static int bttv_g_tuner(struct file *file, void *priv,
2909 struct v4l2_tuner *t)
2910{
2911 struct bttv_fh *fh = priv;
2912 struct bttv *btv = fh->btv;
2913
2914 if (btv->tuner_type == TUNER_ABSENT)
2915 return -EINVAL;
2916 if (0 != t->index)
2917 return -EINVAL;
2918
2919 t->rxsubchans = V4L2_TUNER_SUB_MONO;
2920 bttv_call_all(btv, tuner, g_tuner, t);
2921 strcpy(t->name, "Television");
2922 t->capability = V4L2_TUNER_CAP_NORM;
2923 t->type = V4L2_TUNER_ANALOG_TV;
2924 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC)
2925 t->signal = 0xffff;
2926
2927 if (btv->audio_mode_gpio)
2928 btv->audio_mode_gpio(btv, t, 0);
2929
2930 return 0;
2931}
2932
2933static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p)
2934{
2935 struct bttv_fh *fh = f;
2936 struct bttv *btv = fh->btv;
2937
2938 *p = v4l2_prio_max(&btv->prio);
2939
2940 return 0;
2941}
2942
2943static int bttv_s_priority(struct file *file, void *f,
2944 enum v4l2_priority prio)
2945{
2946 struct bttv_fh *fh = f;
2947 struct bttv *btv = fh->btv;
2948 int rc;
2949
2950 rc = v4l2_prio_change(&btv->prio, &fh->prio, prio);
2951
2952 return rc;
2953}
2954
2955static int bttv_cropcap(struct file *file, void *priv,
2956 struct v4l2_cropcap *cap)
2957{
2958 struct bttv_fh *fh = priv;
2959 struct bttv *btv = fh->btv;
2960
2961 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
2962 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
2963 return -EINVAL;
2964
2965 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
2966
2967 return 0;
2968}
2969
2970static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop)
2971{
2972 struct bttv_fh *fh = f;
2973 struct bttv *btv = fh->btv;
2974
2975 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
2976 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
2977 return -EINVAL;
2978
2979 /* No fh->do_crop = 1; because btv->crop[1] may be
2980 inconsistent with fh->width or fh->height and apps
2981 do not expect a change here. */
2982
2983 crop->c = btv->crop[!!fh->do_crop].rect;
2984
2985 return 0;
2986}
2987
2988static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
2989{
2990 struct bttv_fh *fh = f;
2991 struct bttv *btv = fh->btv;
2992 const struct v4l2_rect *b;
2993 int retval;
2994 struct bttv_crop c;
2995 __s32 b_left;
2996 __s32 b_top;
2997 __s32 b_right;
2998 __s32 b_bottom;
2999
3000 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3001 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3002 return -EINVAL;
3003
3004 /* Make sure tvnorm, vbi_end and the current cropping
3005 parameters remain consistent until we're done. Note
3006 read() may change vbi_end in check_alloc_btres_lock(). */
3007 retval = v4l2_prio_check(&btv->prio, fh->prio);
3008 if (0 != retval) {
3009 return retval;
3010 }
3011
3012 retval = -EBUSY;
3013
3014 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
3015 return retval;
3016 }
3017
3018 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
3019
3020 b_left = b->left;
3021 b_right = b_left + b->width;
3022 b_bottom = b->top + b->height;
3023
3024 b_top = max(b->top, btv->vbi_end);
3025 if (b_top + 32 >= b_bottom) {
3026 return retval;
3027 }
3028
3029 /* Min. scaled size 48 x 32. */
3030 c.rect.left = clamp(crop->c.left, b_left, b_right - 48);
3031 c.rect.left = min(c.rect.left, (__s32) MAX_HDELAY);
3032
3033 c.rect.width = clamp(crop->c.width,
3034 48, b_right - c.rect.left);
3035
3036 c.rect.top = clamp(crop->c.top, b_top, b_bottom - 32);
3037 /* Top and height must be a multiple of two. */
3038 c.rect.top = (c.rect.top + 1) & ~1;
3039
3040 c.rect.height = clamp(crop->c.height,
3041 32, b_bottom - c.rect.top);
3042 c.rect.height = (c.rect.height + 1) & ~1;
3043
3044 bttv_crop_calc_limits(&c);
3045
3046 btv->crop[1] = c;
3047
3048 fh->do_crop = 1;
3049
3050 if (fh->width < c.min_scaled_width) {
3051 fh->width = c.min_scaled_width;
3052 btv->init.width = c.min_scaled_width;
3053 } else if (fh->width > c.max_scaled_width) {
3054 fh->width = c.max_scaled_width;
3055 btv->init.width = c.max_scaled_width;
3056 }
3057
3058 if (fh->height < c.min_scaled_height) {
3059 fh->height = c.min_scaled_height;
3060 btv->init.height = c.min_scaled_height;
3061 } else if (fh->height > c.max_scaled_height) {
3062 fh->height = c.max_scaled_height;
3063 btv->init.height = c.max_scaled_height;
3064 }
3065
3066 return 0;
3067}
3068
3069static int bttv_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
3070{
3071 if (unlikely(a->index))
3072 return -EINVAL;
3073
3074 strcpy(a->name, "audio");
3075 return 0;
3076}
3077
3078static int bttv_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
3079{
3080 if (unlikely(a->index))
3081 return -EINVAL;
3082
3083 return 0;
3084}
3085
3086static ssize_t bttv_read(struct file *file, char __user *data,
3087 size_t count, loff_t *ppos)
3088{
3089 struct bttv_fh *fh = file->private_data;
3090 int retval = 0;
3091
3092 if (fh->btv->errors)
3093 bttv_reinit_bt848(fh->btv);
3094 dprintk("bttv%d: read count=%d type=%s\n",
3095 fh->btv->c.nr,(int)count,v4l2_type_names[fh->type]);
3096
3097 switch (fh->type) {
3098 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3099 if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) {
3100 /* VIDEO_READ in use by another fh,
3101 or VIDEO_STREAM by any fh. */
3102 return -EBUSY;
3103 }
3104 retval = videobuf_read_one(&fh->cap, data, count, ppos,
3105 file->f_flags & O_NONBLOCK);
3106 free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ);
3107 break;
3108 case V4L2_BUF_TYPE_VBI_CAPTURE:
3109 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI))
3110 return -EBUSY;
3111 retval = videobuf_read_stream(&fh->vbi, data, count, ppos, 1,
3112 file->f_flags & O_NONBLOCK);
3113 break;
3114 default:
3115 BUG();
3116 }
3117 return retval;
3118}
3119
3120static unsigned int bttv_poll(struct file *file, poll_table *wait)
3121{
3122 struct bttv_fh *fh = file->private_data;
3123 struct bttv_buffer *buf;
3124 enum v4l2_field field;
3125 unsigned int rc = POLLERR;
3126
3127 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
3128 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI))
3129 return POLLERR;
3130 return videobuf_poll_stream(file, &fh->vbi, wait);
3131 }
3132
3133 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) {
3134 /* streaming capture */
3135 if (list_empty(&fh->cap.stream))
3136 goto err;
3137 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream);
3138 } else {
3139 /* read() capture */
3140 if (NULL == fh->cap.read_buf) {
3141 /* need to capture a new frame */
3142 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM))
3143 goto err;
3144 fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize);
3145 if (NULL == fh->cap.read_buf)
3146 goto err;
3147 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR;
3148 field = videobuf_next_field(&fh->cap);
3149 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) {
3150 kfree (fh->cap.read_buf);
3151 fh->cap.read_buf = NULL;
3152 goto err;
3153 }
3154 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
3155 fh->cap.read_off = 0;
3156 }
3157 buf = (struct bttv_buffer*)fh->cap.read_buf;
3158 }
3159
3160 poll_wait(file, &buf->vb.done, wait);
3161 if (buf->vb.state == VIDEOBUF_DONE ||
3162 buf->vb.state == VIDEOBUF_ERROR)
3163 rc = POLLIN|POLLRDNORM;
3164 else
3165 rc = 0;
3166err:
3167 return rc;
3168}
3169
3170static int bttv_open(struct file *file)
3171{
3172 struct video_device *vdev = video_devdata(file);
3173 struct bttv *btv = video_drvdata(file);
3174 struct bttv_fh *fh;
3175 enum v4l2_buf_type type = 0;
3176
3177 dprintk(KERN_DEBUG "bttv: open dev=%s\n", video_device_node_name(vdev));
3178
3179 if (vdev->vfl_type == VFL_TYPE_GRABBER) {
3180 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
3181 } else if (vdev->vfl_type == VFL_TYPE_VBI) {
3182 type = V4L2_BUF_TYPE_VBI_CAPTURE;
3183 } else {
3184 WARN_ON(1);
3185 return -ENODEV;
3186 }
3187
3188 dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n",
3189 btv->c.nr,v4l2_type_names[type]);
3190
3191 /* allocate per filehandle data */
3192 fh = kmalloc(sizeof(*fh), GFP_KERNEL);
3193 if (unlikely(!fh))
3194 return -ENOMEM;
3195 file->private_data = fh;
3196
3197 *fh = btv->init;
3198
3199 fh->type = type;
3200 fh->ov.setup_ok = 0;
3201
3202 v4l2_prio_open(&btv->prio, &fh->prio);
3203
3204 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops,
3205 &btv->c.pci->dev, &btv->s_lock,
3206 V4L2_BUF_TYPE_VIDEO_CAPTURE,
3207 V4L2_FIELD_INTERLACED,
3208 sizeof(struct bttv_buffer),
3209 fh, &btv->lock);
3210 videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops,
3211 &btv->c.pci->dev, &btv->s_lock,
3212 V4L2_BUF_TYPE_VBI_CAPTURE,
3213 V4L2_FIELD_SEQ_TB,
3214 sizeof(struct bttv_buffer),
3215 fh, &btv->lock);
3216 set_tvnorm(btv,btv->tvnorm);
3217 set_input(btv, btv->input, btv->tvnorm);
3218
3219 btv->users++;
3220
3221 /* The V4L2 spec requires one global set of cropping parameters
3222 which only change on request. These are stored in btv->crop[1].
3223 However for compatibility with V4L apps and cropping unaware
3224 V4L2 apps we now reset the cropping parameters as seen through
3225 this fh, which is to say VIDIOC_G_CROP and scaling limit checks
3226 will use btv->crop[0], the default cropping parameters for the
3227 current video standard, and VIDIOC_S_FMT will not implicitely
3228 change the cropping parameters until VIDIOC_S_CROP has been
3229 called. */
3230 fh->do_crop = !reset_crop; /* module parameter */
3231
3232 /* Likewise there should be one global set of VBI capture
3233 parameters, but for compatibility with V4L apps and earlier
3234 driver versions each fh has its own parameters. */
3235 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3236
3237 bttv_field_count(btv);
3238 return 0;
3239}
3240
3241static int bttv_release(struct file *file)
3242{
3243 struct bttv_fh *fh = file->private_data;
3244 struct bttv *btv = fh->btv;
3245
3246 /* turn off overlay */
3247 if (check_btres(fh, RESOURCE_OVERLAY))
3248 bttv_switch_overlay(btv,fh,NULL);
3249
3250 /* stop video capture */
3251 if (check_btres(fh, RESOURCE_VIDEO_STREAM)) {
3252 videobuf_streamoff(&fh->cap);
3253 free_btres_lock(btv,fh,RESOURCE_VIDEO_STREAM);
3254 }
3255 if (fh->cap.read_buf) {
3256 buffer_release(&fh->cap,fh->cap.read_buf);
3257 kfree(fh->cap.read_buf);
3258 }
3259 if (check_btres(fh, RESOURCE_VIDEO_READ)) {
3260 free_btres_lock(btv, fh, RESOURCE_VIDEO_READ);
3261 }
3262
3263 /* stop vbi capture */
3264 if (check_btres(fh, RESOURCE_VBI)) {
3265 videobuf_stop(&fh->vbi);
3266 free_btres_lock(btv,fh,RESOURCE_VBI);
3267 }
3268
3269 /* free stuff */
3270
3271 videobuf_mmap_free(&fh->cap);
3272 videobuf_mmap_free(&fh->vbi);
3273 v4l2_prio_close(&btv->prio, fh->prio);
3274 file->private_data = NULL;
3275 kfree(fh);
3276
3277 btv->users--;
3278 bttv_field_count(btv);
3279
3280 if (!btv->users)
3281 audio_mute(btv, 1);
3282
3283 return 0;
3284}
3285
3286static int
3287bttv_mmap(struct file *file, struct vm_area_struct *vma)
3288{
3289 struct bttv_fh *fh = file->private_data;
3290
3291 dprintk("bttv%d: mmap type=%s 0x%lx+%ld\n",
3292 fh->btv->c.nr, v4l2_type_names[fh->type],
3293 vma->vm_start, vma->vm_end - vma->vm_start);
3294 return videobuf_mmap_mapper(bttv_queue(fh),vma);
3295}
3296
3297static const struct v4l2_file_operations bttv_fops =
3298{
3299 .owner = THIS_MODULE,
3300 .open = bttv_open,
3301 .release = bttv_release,
3302 .unlocked_ioctl = video_ioctl2,
3303 .read = bttv_read,
3304 .mmap = bttv_mmap,
3305 .poll = bttv_poll,
3306};
3307
3308static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3309 .vidioc_querycap = bttv_querycap,
3310 .vidioc_enum_fmt_vid_cap = bttv_enum_fmt_vid_cap,
3311 .vidioc_g_fmt_vid_cap = bttv_g_fmt_vid_cap,
3312 .vidioc_try_fmt_vid_cap = bttv_try_fmt_vid_cap,
3313 .vidioc_s_fmt_vid_cap = bttv_s_fmt_vid_cap,
3314 .vidioc_enum_fmt_vid_overlay = bttv_enum_fmt_vid_overlay,
3315 .vidioc_g_fmt_vid_overlay = bttv_g_fmt_vid_overlay,
3316 .vidioc_try_fmt_vid_overlay = bttv_try_fmt_vid_overlay,
3317 .vidioc_s_fmt_vid_overlay = bttv_s_fmt_vid_overlay,
3318 .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap,
3319 .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap,
3320 .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap,
3321 .vidioc_g_audio = bttv_g_audio,
3322 .vidioc_s_audio = bttv_s_audio,
3323 .vidioc_cropcap = bttv_cropcap,
3324 .vidioc_reqbufs = bttv_reqbufs,
3325 .vidioc_querybuf = bttv_querybuf,
3326 .vidioc_qbuf = bttv_qbuf,
3327 .vidioc_dqbuf = bttv_dqbuf,
3328 .vidioc_s_std = bttv_s_std,
3329 .vidioc_enum_input = bttv_enum_input,
3330 .vidioc_g_input = bttv_g_input,
3331 .vidioc_s_input = bttv_s_input,
3332 .vidioc_queryctrl = bttv_queryctrl,
3333 .vidioc_g_ctrl = bttv_g_ctrl,
3334 .vidioc_s_ctrl = bttv_s_ctrl,
3335 .vidioc_streamon = bttv_streamon,
3336 .vidioc_streamoff = bttv_streamoff,
3337 .vidioc_g_tuner = bttv_g_tuner,
3338 .vidioc_s_tuner = bttv_s_tuner,
3339 .vidioc_g_crop = bttv_g_crop,
3340 .vidioc_s_crop = bttv_s_crop,
3341 .vidioc_g_fbuf = bttv_g_fbuf,
3342 .vidioc_s_fbuf = bttv_s_fbuf,
3343 .vidioc_overlay = bttv_overlay,
3344 .vidioc_g_priority = bttv_g_priority,
3345 .vidioc_s_priority = bttv_s_priority,
3346 .vidioc_g_parm = bttv_g_parm,
3347 .vidioc_g_frequency = bttv_g_frequency,
3348 .vidioc_s_frequency = bttv_s_frequency,
3349 .vidioc_log_status = bttv_log_status,
3350 .vidioc_querystd = bttv_querystd,
3351#ifdef CONFIG_VIDEO_ADV_DEBUG
3352 .vidioc_g_register = bttv_g_register,
3353 .vidioc_s_register = bttv_s_register,
3354#endif
3355};
3356
3357static struct video_device bttv_video_template = {
3358 .fops = &bttv_fops,
3359 .ioctl_ops = &bttv_ioctl_ops,
3360 .tvnorms = BTTV_NORMS,
3361 .current_norm = V4L2_STD_PAL,
3362};
3363
3364/* ----------------------------------------------------------------------- */
3365/* radio interface */
3366
3367static int radio_open(struct file *file)
3368{
3369 struct video_device *vdev = video_devdata(file);
3370 struct bttv *btv = video_drvdata(file);
3371 struct bttv_fh *fh;
3372
3373 dprintk("bttv: open dev=%s\n", video_device_node_name(vdev));
3374
3375 dprintk("bttv%d: open called (radio)\n",btv->c.nr);
3376
3377 /* allocate per filehandle data */
3378 fh = kmalloc(sizeof(*fh), GFP_KERNEL);
3379 if (unlikely(!fh))
3380 return -ENOMEM;
3381 file->private_data = fh;
3382 *fh = btv->init;
3383
3384 v4l2_prio_open(&btv->prio, &fh->prio);
3385
3386 btv->radio_user++;
3387
3388 bttv_call_all(btv, tuner, s_radio);
3389 audio_input(btv,TVAUDIO_INPUT_RADIO);
3390
3391 return 0;
3392}
3393
3394static int radio_release(struct file *file)
3395{
3396 struct bttv_fh *fh = file->private_data;
3397 struct bttv *btv = fh->btv;
3398 struct saa6588_command cmd;
3399
3400 v4l2_prio_close(&btv->prio, fh->prio);
3401 file->private_data = NULL;
3402 kfree(fh);
3403
3404 btv->radio_user--;
3405
3406 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
3407
3408 return 0;
3409}
3410
3411static int radio_querycap(struct file *file, void *priv,
3412 struct v4l2_capability *cap)
3413{
3414 struct bttv_fh *fh = priv;
3415 struct bttv *btv = fh->btv;
3416
3417 strcpy(cap->driver, "bttv");
3418 strlcpy(cap->card, btv->radio_dev->name, sizeof(cap->card));
3419 sprintf(cap->bus_info, "PCI:%s", pci_name(btv->c.pci));
3420 cap->capabilities = V4L2_CAP_TUNER;
3421
3422 return 0;
3423}
3424
3425static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3426{
3427 struct bttv_fh *fh = priv;
3428 struct bttv *btv = fh->btv;
3429
3430 if (btv->tuner_type == TUNER_ABSENT)
3431 return -EINVAL;
3432 if (0 != t->index)
3433 return -EINVAL;
3434 strcpy(t->name, "Radio");
3435 t->type = V4L2_TUNER_RADIO;
3436
3437 bttv_call_all(btv, tuner, g_tuner, t);
3438
3439 if (btv->audio_mode_gpio)
3440 btv->audio_mode_gpio(btv, t, 0);
3441
3442 return 0;
3443}
3444
3445static int radio_enum_input(struct file *file, void *priv,
3446 struct v4l2_input *i)
3447{
3448 if (i->index != 0)
3449 return -EINVAL;
3450
3451 strcpy(i->name, "Radio");
3452 i->type = V4L2_INPUT_TYPE_TUNER;
3453
3454 return 0;
3455}
3456
3457static int radio_g_audio(struct file *file, void *priv,
3458 struct v4l2_audio *a)
3459{
3460 if (unlikely(a->index))
3461 return -EINVAL;
3462
3463 strcpy(a->name, "Radio");
3464
3465 return 0;
3466}
3467
3468static int radio_s_tuner(struct file *file, void *priv,
3469 struct v4l2_tuner *t)
3470{
3471 struct bttv_fh *fh = priv;
3472 struct bttv *btv = fh->btv;
3473
3474 if (0 != t->index)
3475 return -EINVAL;
3476
3477 bttv_call_all(btv, tuner, s_tuner, t);
3478 return 0;
3479}
3480
3481static int radio_s_audio(struct file *file, void *priv,
3482 struct v4l2_audio *a)
3483{
3484 if (unlikely(a->index))
3485 return -EINVAL;
3486
3487 return 0;
3488}
3489
3490static int radio_s_input(struct file *filp, void *priv, unsigned int i)
3491{
3492 if (unlikely(i))
3493 return -EINVAL;
3494
3495 return 0;
3496}
3497
3498static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
3499{
3500 return 0;
3501}
3502
3503static int radio_queryctrl(struct file *file, void *priv,
3504 struct v4l2_queryctrl *c)
3505{
3506 const struct v4l2_queryctrl *ctrl;
3507
3508 if (c->id < V4L2_CID_BASE ||
3509 c->id >= V4L2_CID_LASTP1)
3510 return -EINVAL;
3511
3512 if (c->id == V4L2_CID_AUDIO_MUTE) {
3513 ctrl = ctrl_by_id(c->id);
3514 *c = *ctrl;
3515 } else
3516 *c = no_ctl;
3517
3518 return 0;
3519}
3520
3521static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
3522{
3523 *i = 0;
3524 return 0;
3525}
3526
3527static ssize_t radio_read(struct file *file, char __user *data,
3528 size_t count, loff_t *ppos)
3529{
3530 struct bttv_fh *fh = file->private_data;
3531 struct bttv *btv = fh->btv;
3532 struct saa6588_command cmd;
3533 cmd.block_count = count/3;
3534 cmd.buffer = data;
3535 cmd.instance = file;
3536 cmd.result = -ENODEV;
3537
3538 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd);
3539
3540 return cmd.result;
3541}
3542
3543static unsigned int radio_poll(struct file *file, poll_table *wait)
3544{
3545 struct bttv_fh *fh = file->private_data;
3546 struct bttv *btv = fh->btv;
3547 struct saa6588_command cmd;
3548 cmd.instance = file;
3549 cmd.event_list = wait;
3550 cmd.result = -ENODEV;
3551 bttv_call_all(btv, core, ioctl, SAA6588_CMD_POLL, &cmd);
3552
3553 return cmd.result;
3554}
3555
3556static const struct v4l2_file_operations radio_fops =
3557{
3558 .owner = THIS_MODULE,
3559 .open = radio_open,
3560 .read = radio_read,
3561 .release = radio_release,
3562 .unlocked_ioctl = video_ioctl2,
3563 .poll = radio_poll,
3564};
3565
3566static const struct v4l2_ioctl_ops radio_ioctl_ops = {
3567 .vidioc_querycap = radio_querycap,
3568 .vidioc_g_tuner = radio_g_tuner,
3569 .vidioc_enum_input = radio_enum_input,
3570 .vidioc_g_audio = radio_g_audio,
3571 .vidioc_s_tuner = radio_s_tuner,
3572 .vidioc_s_audio = radio_s_audio,
3573 .vidioc_s_input = radio_s_input,
3574 .vidioc_s_std = radio_s_std,
3575 .vidioc_queryctrl = radio_queryctrl,
3576 .vidioc_g_input = radio_g_input,
3577 .vidioc_g_ctrl = bttv_g_ctrl,
3578 .vidioc_s_ctrl = bttv_s_ctrl,
3579 .vidioc_g_frequency = bttv_g_frequency,
3580 .vidioc_s_frequency = bttv_s_frequency,
3581};
3582
3583static struct video_device radio_template = {
3584 .fops = &radio_fops,
3585 .ioctl_ops = &radio_ioctl_ops,
3586};
3587
3588/* ----------------------------------------------------------------------- */
3589/* some debug code */
3590
3591static int bttv_risc_decode(u32 risc)
3592{
3593 static char *instr[16] = {
3594 [ BT848_RISC_WRITE >> 28 ] = "write",
3595 [ BT848_RISC_SKIP >> 28 ] = "skip",
3596 [ BT848_RISC_WRITEC >> 28 ] = "writec",
3597 [ BT848_RISC_JUMP >> 28 ] = "jump",
3598 [ BT848_RISC_SYNC >> 28 ] = "sync",
3599 [ BT848_RISC_WRITE123 >> 28 ] = "write123",
3600 [ BT848_RISC_SKIP123 >> 28 ] = "skip123",
3601 [ BT848_RISC_WRITE1S23 >> 28 ] = "write1s23",
3602 };
3603 static int incr[16] = {
3604 [ BT848_RISC_WRITE >> 28 ] = 2,
3605 [ BT848_RISC_JUMP >> 28 ] = 2,
3606 [ BT848_RISC_SYNC >> 28 ] = 2,
3607 [ BT848_RISC_WRITE123 >> 28 ] = 5,
3608 [ BT848_RISC_SKIP123 >> 28 ] = 2,
3609 [ BT848_RISC_WRITE1S23 >> 28 ] = 3,
3610 };
3611 static char *bits[] = {
3612 "be0", "be1", "be2", "be3/resync",
3613 "set0", "set1", "set2", "set3",
3614 "clr0", "clr1", "clr2", "clr3",
3615 "irq", "res", "eol", "sol",
3616 };
3617 int i;
3618
3619 printk("0x%08x [ %s", risc,
3620 instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
3621 for (i = ARRAY_SIZE(bits)-1; i >= 0; i--)
3622 if (risc & (1 << (i + 12)))
3623 printk(" %s",bits[i]);
3624 printk(" count=%d ]\n", risc & 0xfff);
3625 return incr[risc >> 28] ? incr[risc >> 28] : 1;
3626}
3627
3628static void bttv_risc_disasm(struct bttv *btv,
3629 struct btcx_riscmem *risc)
3630{
3631 unsigned int i,j,n;
3632
3633 printk("%s: risc disasm: %p [dma=0x%08lx]\n",
3634 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
3635 for (i = 0; i < (risc->size >> 2); i += n) {
3636 printk("%s: 0x%lx: ", btv->c.v4l2_dev.name,
3637 (unsigned long)(risc->dma + (i<<2)));
3638 n = bttv_risc_decode(le32_to_cpu(risc->cpu[i]));
3639 for (j = 1; j < n; j++)
3640 printk("%s: 0x%lx: 0x%08x [ arg #%d ]\n",
3641 btv->c.v4l2_dev.name, (unsigned long)(risc->dma + ((i+j)<<2)),
3642 risc->cpu[i+j], j);
3643 if (0 == risc->cpu[i])
3644 break;
3645 }
3646}
3647
3648static void bttv_print_riscaddr(struct bttv *btv)
3649{
3650 printk(" main: %08Lx\n",
3651 (unsigned long long)btv->main.dma);
3652 printk(" vbi : o=%08Lx e=%08Lx\n",
3653 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
3654 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
3655 printk(" cap : o=%08Lx e=%08Lx\n",
3656 btv->curr.top ? (unsigned long long)btv->curr.top->top.dma : 0,
3657 btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
3658 printk(" scr : o=%08Lx e=%08Lx\n",
3659 btv->screen ? (unsigned long long)btv->screen->top.dma : 0,
3660 btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0);
3661 bttv_risc_disasm(btv, &btv->main);
3662}
3663
3664/* ----------------------------------------------------------------------- */
3665/* irq handler */
3666
3667static char *irq_name[] = {
3668 "FMTCHG", // format change detected (525 vs. 625)
3669 "VSYNC", // vertical sync (new field)
3670 "HSYNC", // horizontal sync
3671 "OFLOW", // chroma/luma AGC overflow
3672 "HLOCK", // horizontal lock changed
3673 "VPRES", // video presence changed
3674 "6", "7",
3675 "I2CDONE", // hw irc operation finished
3676 "GPINT", // gpio port triggered irq
3677 "10",
3678 "RISCI", // risc instruction triggered irq
3679 "FBUS", // pixel data fifo dropped data (high pci bus latencies)
3680 "FTRGT", // pixel data fifo overrun
3681 "FDSR", // fifo data stream resyncronisation
3682 "PPERR", // parity error (data transfer)
3683 "RIPERR", // parity error (read risc instructions)
3684 "PABORT", // pci abort
3685 "OCERR", // risc instruction error
3686 "SCERR", // syncronisation error
3687};
3688
3689static void bttv_print_irqbits(u32 print, u32 mark)
3690{
3691 unsigned int i;
3692
3693 printk("bits:");
3694 for (i = 0; i < ARRAY_SIZE(irq_name); i++) {
3695 if (print & (1 << i))
3696 printk(" %s",irq_name[i]);
3697 if (mark & (1 << i))
3698 printk("*");
3699 }
3700}
3701
3702static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc)
3703{
3704 printk("bttv%d: irq: skipped frame [main=%lx,o_vbi=%lx,o_field=%lx,rc=%lx]\n",
3705 btv->c.nr,
3706 (unsigned long)btv->main.dma,
3707 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
3708 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
3709 (unsigned long)rc);
3710
3711 if (0 == (btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC)) {
3712 printk("bttv%d: Oh, there (temporarely?) is no input signal. "
3713 "Ok, then this is harmless, don't worry ;)\n",
3714 btv->c.nr);
3715 return;
3716 }
3717 printk("bttv%d: Uhm. Looks like we have unusual high IRQ latencies.\n",
3718 btv->c.nr);
3719 printk("bttv%d: Lets try to catch the culpit red-handed ...\n",
3720 btv->c.nr);
3721 dump_stack();
3722}
3723
3724static int
3725bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set)
3726{
3727 struct bttv_buffer *item;
3728
3729 memset(set,0,sizeof(*set));
3730
3731 /* capture request ? */
3732 if (!list_empty(&btv->capture)) {
3733 set->frame_irq = 1;
3734 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
3735 if (V4L2_FIELD_HAS_TOP(item->vb.field))
3736 set->top = item;
3737 if (V4L2_FIELD_HAS_BOTTOM(item->vb.field))
3738 set->bottom = item;
3739
3740 /* capture request for other field ? */
3741 if (!V4L2_FIELD_HAS_BOTH(item->vb.field) &&
3742 (item->vb.queue.next != &btv->capture)) {
3743 item = list_entry(item->vb.queue.next, struct bttv_buffer, vb.queue);
3744 /* Mike Isely <isely@pobox.com> - Only check
3745 * and set up the bottom field in the logic
3746 * below. Don't ever do the top field. This
3747 * of course means that if we set up the
3748 * bottom field in the above code that we'll
3749 * actually skip a field. But that's OK.
3750 * Having processed only a single buffer this
3751 * time, then the next time around the first
3752 * available buffer should be for a top field.
3753 * That will then cause us here to set up a
3754 * top then a bottom field in the normal way.
3755 * The alternative to this understanding is
3756 * that we set up the second available buffer
3757 * as a top field, but that's out of order
3758 * since this driver always processes the top
3759 * field first - the effect will be the two
3760 * buffers being returned in the wrong order,
3761 * with the second buffer also being delayed
3762 * by one field time (owing to the fifo nature
3763 * of videobuf). Worse still, we'll be stuck
3764 * doing fields out of order now every time
3765 * until something else causes a field to be
3766 * dropped. By effectively forcing a field to
3767 * drop this way then we always get back into
3768 * sync within a single frame time. (Out of
3769 * order fields can screw up deinterlacing
3770 * algorithms.) */
3771 if (!V4L2_FIELD_HAS_BOTH(item->vb.field)) {
3772 if (NULL == set->bottom &&
3773 V4L2_FIELD_BOTTOM == item->vb.field) {
3774 set->bottom = item;
3775 }
3776 if (NULL != set->top && NULL != set->bottom)
3777 set->top_irq = 2;
3778 }
3779 }
3780 }
3781
3782 /* screen overlay ? */
3783 if (NULL != btv->screen) {
3784 if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) {
3785 if (NULL == set->top && NULL == set->bottom) {
3786 set->top = btv->screen;
3787 set->bottom = btv->screen;
3788 }
3789 } else {
3790 if (V4L2_FIELD_TOP == btv->screen->vb.field &&
3791 NULL == set->top) {
3792 set->top = btv->screen;
3793 }
3794 if (V4L2_FIELD_BOTTOM == btv->screen->vb.field &&
3795 NULL == set->bottom) {
3796 set->bottom = btv->screen;
3797 }
3798 }
3799 }
3800
3801 dprintk("bttv%d: next set: top=%p bottom=%p [screen=%p,irq=%d,%d]\n",
3802 btv->c.nr,set->top, set->bottom,
3803 btv->screen,set->frame_irq,set->top_irq);
3804 return 0;
3805}
3806
3807static void
3808bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
3809 struct bttv_buffer_set *curr, unsigned int state)
3810{
3811 struct timeval ts;
3812
3813 do_gettimeofday(&ts);
3814
3815 if (wakeup->top == wakeup->bottom) {
3816 if (NULL != wakeup->top && curr->top != wakeup->top) {
3817 if (irq_debug > 1)
3818 printk("bttv%d: wakeup: both=%p\n",btv->c.nr,wakeup->top);
3819 wakeup->top->vb.ts = ts;
3820 wakeup->top->vb.field_count = btv->field_count;
3821 wakeup->top->vb.state = state;
3822 wake_up(&wakeup->top->vb.done);
3823 }
3824 } else {
3825 if (NULL != wakeup->top && curr->top != wakeup->top) {
3826 if (irq_debug > 1)
3827 printk("bttv%d: wakeup: top=%p\n",btv->c.nr,wakeup->top);
3828 wakeup->top->vb.ts = ts;
3829 wakeup->top->vb.field_count = btv->field_count;
3830 wakeup->top->vb.state = state;
3831 wake_up(&wakeup->top->vb.done);
3832 }
3833 if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) {
3834 if (irq_debug > 1)
3835 printk("bttv%d: wakeup: bottom=%p\n",btv->c.nr,wakeup->bottom);
3836 wakeup->bottom->vb.ts = ts;
3837 wakeup->bottom->vb.field_count = btv->field_count;
3838 wakeup->bottom->vb.state = state;
3839 wake_up(&wakeup->bottom->vb.done);
3840 }
3841 }
3842}
3843
3844static void
3845bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
3846 unsigned int state)
3847{
3848 struct timeval ts;
3849
3850 if (NULL == wakeup)
3851 return;
3852
3853 do_gettimeofday(&ts);
3854 wakeup->vb.ts = ts;
3855 wakeup->vb.field_count = btv->field_count;
3856 wakeup->vb.state = state;
3857 wake_up(&wakeup->vb.done);
3858}
3859
3860static void bttv_irq_timeout(unsigned long data)
3861{
3862 struct bttv *btv = (struct bttv *)data;
3863 struct bttv_buffer_set old,new;
3864 struct bttv_buffer *ovbi;
3865 struct bttv_buffer *item;
3866 unsigned long flags;
3867
3868 if (bttv_verbose) {
3869 printk(KERN_INFO "bttv%d: timeout: drop=%d irq=%d/%d, risc=%08x, ",
3870 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
3871 btread(BT848_RISC_COUNT));
3872 bttv_print_irqbits(btread(BT848_INT_STAT),0);
3873 printk("\n");
3874 }
3875
3876 spin_lock_irqsave(&btv->s_lock,flags);
3877
3878 /* deactivate stuff */
3879 memset(&new,0,sizeof(new));
3880 old = btv->curr;
3881 ovbi = btv->cvbi;
3882 btv->curr = new;
3883 btv->cvbi = NULL;
3884 btv->loop_irq = 0;
3885 bttv_buffer_activate_video(btv, &new);
3886 bttv_buffer_activate_vbi(btv, NULL);
3887 bttv_set_dma(btv, 0);
3888
3889 /* wake up */
3890 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_ERROR);
3891 bttv_irq_wakeup_vbi(btv, ovbi, VIDEOBUF_ERROR);
3892
3893 /* cancel all outstanding capture / vbi requests */
3894 while (!list_empty(&btv->capture)) {
3895 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
3896 list_del(&item->vb.queue);
3897 item->vb.state = VIDEOBUF_ERROR;
3898 wake_up(&item->vb.done);
3899 }
3900 while (!list_empty(&btv->vcapture)) {
3901 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
3902 list_del(&item->vb.queue);
3903 item->vb.state = VIDEOBUF_ERROR;
3904 wake_up(&item->vb.done);
3905 }
3906
3907 btv->errors++;
3908 spin_unlock_irqrestore(&btv->s_lock,flags);
3909}
3910
3911static void
3912bttv_irq_wakeup_top(struct bttv *btv)
3913{
3914 struct bttv_buffer *wakeup = btv->curr.top;
3915
3916 if (NULL == wakeup)
3917 return;
3918
3919 spin_lock(&btv->s_lock);
3920 btv->curr.top_irq = 0;
3921 btv->curr.top = NULL;
3922 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
3923
3924 do_gettimeofday(&wakeup->vb.ts);
3925 wakeup->vb.field_count = btv->field_count;
3926 wakeup->vb.state = VIDEOBUF_DONE;
3927 wake_up(&wakeup->vb.done);
3928 spin_unlock(&btv->s_lock);
3929}
3930
3931static inline int is_active(struct btcx_riscmem *risc, u32 rc)
3932{
3933 if (rc < risc->dma)
3934 return 0;
3935 if (rc > risc->dma + risc->size)
3936 return 0;
3937 return 1;
3938}
3939
3940static void
3941bttv_irq_switch_video(struct bttv *btv)
3942{
3943 struct bttv_buffer_set new;
3944 struct bttv_buffer_set old;
3945 dma_addr_t rc;
3946
3947 spin_lock(&btv->s_lock);
3948
3949 /* new buffer set */
3950 bttv_irq_next_video(btv, &new);
3951 rc = btread(BT848_RISC_COUNT);
3952 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) ||
3953 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) {
3954 btv->framedrop++;
3955 if (debug_latency)
3956 bttv_irq_debug_low_latency(btv, rc);
3957 spin_unlock(&btv->s_lock);
3958 return;
3959 }
3960
3961 /* switch over */
3962 old = btv->curr;
3963 btv->curr = new;
3964 btv->loop_irq &= ~1;
3965 bttv_buffer_activate_video(btv, &new);
3966 bttv_set_dma(btv, 0);
3967
3968 /* switch input */
3969 if (UNSET != btv->new_input) {
3970 video_mux(btv,btv->new_input);
3971 btv->new_input = UNSET;
3972 }
3973
3974 /* wake up finished buffers */
3975 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_DONE);
3976 spin_unlock(&btv->s_lock);
3977}
3978
3979static void
3980bttv_irq_switch_vbi(struct bttv *btv)
3981{
3982 struct bttv_buffer *new = NULL;
3983 struct bttv_buffer *old;
3984 u32 rc;
3985
3986 spin_lock(&btv->s_lock);
3987
3988 if (!list_empty(&btv->vcapture))
3989 new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
3990 old = btv->cvbi;
3991
3992 rc = btread(BT848_RISC_COUNT);
3993 if (NULL != old && (is_active(&old->top, rc) ||
3994 is_active(&old->bottom, rc))) {
3995 btv->framedrop++;
3996 if (debug_latency)
3997 bttv_irq_debug_low_latency(btv, rc);
3998 spin_unlock(&btv->s_lock);
3999 return;
4000 }
4001
4002 /* switch */
4003 btv->cvbi = new;
4004 btv->loop_irq &= ~4;
4005 bttv_buffer_activate_vbi(btv, new);
4006 bttv_set_dma(btv, 0);
4007
4008 bttv_irq_wakeup_vbi(btv, old, VIDEOBUF_DONE);
4009 spin_unlock(&btv->s_lock);
4010}
4011
4012static irqreturn_t bttv_irq(int irq, void *dev_id)
4013{
4014 u32 stat,astat;
4015 u32 dstat;
4016 int count;
4017 struct bttv *btv;
4018 int handled = 0;
4019
4020 btv=(struct bttv *)dev_id;
4021
4022 count=0;
4023 while (1) {
4024 /* get/clear interrupt status bits */
4025 stat=btread(BT848_INT_STAT);
4026 astat=stat&btread(BT848_INT_MASK);
4027 if (!astat)
4028 break;
4029 handled = 1;
4030 btwrite(stat,BT848_INT_STAT);
4031
4032 /* get device status bits */
4033 dstat=btread(BT848_DSTATUS);
4034
4035 if (irq_debug) {
4036 printk(KERN_DEBUG "bttv%d: irq loop=%d fc=%d "
4037 "riscs=%x, riscc=%08x, ",
4038 btv->c.nr, count, btv->field_count,
4039 stat>>28, btread(BT848_RISC_COUNT));
4040 bttv_print_irqbits(stat,astat);
4041 if (stat & BT848_INT_HLOCK)
4042 printk(" HLOC => %s", (dstat & BT848_DSTATUS_HLOC)
4043 ? "yes" : "no");
4044 if (stat & BT848_INT_VPRES)
4045 printk(" PRES => %s", (dstat & BT848_DSTATUS_PRES)
4046 ? "yes" : "no");
4047 if (stat & BT848_INT_FMTCHG)
4048 printk(" NUML => %s", (dstat & BT848_DSTATUS_NUML)
4049 ? "625" : "525");
4050 printk("\n");
4051 }
4052
4053 if (astat&BT848_INT_VSYNC)
4054 btv->field_count++;
4055
4056 if ((astat & BT848_INT_GPINT) && btv->remote) {
4057 bttv_input_irq(btv);
4058 }
4059
4060 if (astat & BT848_INT_I2CDONE) {
4061 btv->i2c_done = stat;
4062 wake_up(&btv->i2c_queue);
4063 }
4064
4065 if ((astat & BT848_INT_RISCI) && (stat & (4<<28)))
4066 bttv_irq_switch_vbi(btv);
4067
4068 if ((astat & BT848_INT_RISCI) && (stat & (2<<28)))
4069 bttv_irq_wakeup_top(btv);
4070
4071 if ((astat & BT848_INT_RISCI) && (stat & (1<<28)))
4072 bttv_irq_switch_video(btv);
4073
4074 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
4075 audio_mute(btv, btv->mute); /* trigger automute */
4076
4077 if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) {
4078 printk(KERN_INFO "bttv%d: %s%s @ %08x,",btv->c.nr,
4079 (astat & BT848_INT_SCERR) ? "SCERR" : "",
4080 (astat & BT848_INT_OCERR) ? "OCERR" : "",
4081 btread(BT848_RISC_COUNT));
4082 bttv_print_irqbits(stat,astat);
4083 printk("\n");
4084 if (bttv_debug)
4085 bttv_print_riscaddr(btv);
4086 }
4087 if (fdsr && astat & BT848_INT_FDSR) {
4088 printk(KERN_INFO "bttv%d: FDSR @ %08x\n",
4089 btv->c.nr,btread(BT848_RISC_COUNT));
4090 if (bttv_debug)
4091 bttv_print_riscaddr(btv);
4092 }
4093
4094 count++;
4095 if (count > 4) {
4096
4097 if (count > 8 || !(astat & BT848_INT_GPINT)) {
4098 btwrite(0, BT848_INT_MASK);
4099
4100 printk(KERN_ERR
4101 "bttv%d: IRQ lockup, cleared int mask [", btv->c.nr);
4102 } else {
4103 printk(KERN_ERR
4104 "bttv%d: IRQ lockup, clearing GPINT from int mask [", btv->c.nr);
4105
4106 btwrite(btread(BT848_INT_MASK) & (-1 ^ BT848_INT_GPINT),
4107 BT848_INT_MASK);
4108 };
4109
4110 bttv_print_irqbits(stat,astat);
4111
4112 printk("]\n");
4113 }
4114 }
4115 btv->irq_total++;
4116 if (handled)
4117 btv->irq_me++;
4118 return IRQ_RETVAL(handled);
4119}
4120
4121
4122/* ----------------------------------------------------------------------- */
4123/* initialitation */
4124
4125static struct video_device *vdev_init(struct bttv *btv,
4126 const struct video_device *template,
4127 const char *type_name)
4128{
4129 struct video_device *vfd;
4130
4131 vfd = video_device_alloc();
4132 if (NULL == vfd)
4133 return NULL;
4134 *vfd = *template;
4135 vfd->v4l2_dev = &btv->c.v4l2_dev;
4136 vfd->release = video_device_release;
4137 vfd->debug = bttv_debug;
4138 video_set_drvdata(vfd, btv);
4139 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
4140 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4141 type_name, bttv_tvcards[btv->c.type].name);
4142 return vfd;
4143}
4144
4145static void bttv_unregister_video(struct bttv *btv)
4146{
4147 if (btv->video_dev) {
4148 if (video_is_registered(btv->video_dev))
4149 video_unregister_device(btv->video_dev);
4150 else
4151 video_device_release(btv->video_dev);
4152 btv->video_dev = NULL;
4153 }
4154 if (btv->vbi_dev) {
4155 if (video_is_registered(btv->vbi_dev))
4156 video_unregister_device(btv->vbi_dev);
4157 else
4158 video_device_release(btv->vbi_dev);
4159 btv->vbi_dev = NULL;
4160 }
4161 if (btv->radio_dev) {
4162 if (video_is_registered(btv->radio_dev))
4163 video_unregister_device(btv->radio_dev);
4164 else
4165 video_device_release(btv->radio_dev);
4166 btv->radio_dev = NULL;
4167 }
4168}
4169
4170/* register video4linux devices */
4171static int __devinit bttv_register_video(struct bttv *btv)
4172{
4173 if (no_overlay > 0)
4174 printk("bttv: Overlay support disabled.\n");
4175
4176 /* video */
4177 btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
4178
4179 if (NULL == btv->video_dev)
4180 goto err;
4181 if (video_register_device(btv->video_dev, VFL_TYPE_GRABBER,
4182 video_nr[btv->c.nr]) < 0)
4183 goto err;
4184 printk(KERN_INFO "bttv%d: registered device %s\n",
4185 btv->c.nr, video_device_node_name(btv->video_dev));
4186 if (device_create_file(&btv->video_dev->dev,
4187 &dev_attr_card)<0) {
4188 printk(KERN_ERR "bttv%d: device_create_file 'card' "
4189 "failed\n", btv->c.nr);
4190 goto err;
4191 }
4192
4193 /* vbi */
4194 btv->vbi_dev = vdev_init(btv, &bttv_video_template, "vbi");
4195
4196 if (NULL == btv->vbi_dev)
4197 goto err;
4198 if (video_register_device(btv->vbi_dev, VFL_TYPE_VBI,
4199 vbi_nr[btv->c.nr]) < 0)
4200 goto err;
4201 printk(KERN_INFO "bttv%d: registered device %s\n",
4202 btv->c.nr, video_device_node_name(btv->vbi_dev));
4203
4204 if (!btv->has_radio)
4205 return 0;
4206 /* radio */
4207 btv->radio_dev = vdev_init(btv, &radio_template, "radio");
4208 if (NULL == btv->radio_dev)
4209 goto err;
4210 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,
4211 radio_nr[btv->c.nr]) < 0)
4212 goto err;
4213 printk(KERN_INFO "bttv%d: registered device %s\n",
4214 btv->c.nr, video_device_node_name(btv->radio_dev));
4215
4216 /* all done */
4217 return 0;
4218
4219 err:
4220 bttv_unregister_video(btv);
4221 return -1;
4222}
4223
4224
4225/* on OpenFirmware machines (PowerMac at least), PCI memory cycle */
4226/* response on cards with no firmware is not enabled by OF */
4227static void pci_set_command(struct pci_dev *dev)
4228{
4229#if defined(__powerpc__)
4230 unsigned int cmd;
4231
4232 pci_read_config_dword(dev, PCI_COMMAND, &cmd);
4233 cmd = (cmd | PCI_COMMAND_MEMORY );
4234 pci_write_config_dword(dev, PCI_COMMAND, cmd);
4235#endif
4236}
4237
4238static int __devinit bttv_probe(struct pci_dev *dev,
4239 const struct pci_device_id *pci_id)
4240{
4241 int result;
4242 unsigned char lat;
4243 struct bttv *btv;
4244
4245 if (bttv_num == BTTV_MAX)
4246 return -ENOMEM;
4247 printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num);
4248 bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
4249 if (btv == NULL) {
4250 printk(KERN_ERR "bttv: out of memory.\n");
4251 return -ENOMEM;
4252 }
4253 btv->c.nr = bttv_num;
4254 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name),
4255 "bttv%d", btv->c.nr);
4256
4257 /* initialize structs / fill in defaults */
4258 mutex_init(&btv->lock);
4259 spin_lock_init(&btv->s_lock);
4260 spin_lock_init(&btv->gpio_lock);
4261 init_waitqueue_head(&btv->i2c_queue);
4262 INIT_LIST_HEAD(&btv->c.subs);
4263 INIT_LIST_HEAD(&btv->capture);
4264 INIT_LIST_HEAD(&btv->vcapture);
4265 v4l2_prio_init(&btv->prio);
4266
4267 init_timer(&btv->timeout);
4268 btv->timeout.function = bttv_irq_timeout;
4269 btv->timeout.data = (unsigned long)btv;
4270
4271 btv->i2c_rc = -1;
4272 btv->tuner_type = UNSET;
4273 btv->new_input = UNSET;
4274 btv->has_radio=radio[btv->c.nr];
4275
4276 /* pci stuff (init, get irq/mmio, ... */
4277 btv->c.pci = dev;
4278 btv->id = dev->device;
4279 if (pci_enable_device(dev)) {
4280 printk(KERN_WARNING "bttv%d: Can't enable device.\n",
4281 btv->c.nr);
4282 return -EIO;
4283 }
4284 if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
4285 printk(KERN_WARNING "bttv%d: No suitable DMA available.\n",
4286 btv->c.nr);
4287 return -EIO;
4288 }
4289 if (!request_mem_region(pci_resource_start(dev,0),
4290 pci_resource_len(dev,0),
4291 btv->c.v4l2_dev.name)) {
4292 printk(KERN_WARNING "bttv%d: can't request iomem (0x%llx).\n",
4293 btv->c.nr,
4294 (unsigned long long)pci_resource_start(dev,0));
4295 return -EBUSY;
4296 }
4297 pci_set_master(dev);
4298 pci_set_command(dev);
4299
4300 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev);
4301 if (result < 0) {
4302 printk(KERN_WARNING "bttv%d: v4l2_device_register() failed\n", btv->c.nr);
4303 goto fail0;
4304 }
4305
4306 btv->revision = dev->revision;
4307 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
4308 printk(KERN_INFO "bttv%d: Bt%d (rev %d) at %s, ",
4309 bttv_num,btv->id, btv->revision, pci_name(dev));
4310 printk("irq: %d, latency: %d, mmio: 0x%llx\n",
4311 btv->c.pci->irq, lat,
4312 (unsigned long long)pci_resource_start(dev,0));
4313 schedule();
4314
4315 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
4316 if (NULL == btv->bt848_mmio) {
4317 printk("bttv%d: ioremap() failed\n", btv->c.nr);
4318 result = -EIO;
4319 goto fail1;
4320 }
4321
4322 /* identify card */
4323 bttv_idcard(btv);
4324
4325 /* disable irqs, register irq handler */
4326 btwrite(0, BT848_INT_MASK);
4327 result = request_irq(btv->c.pci->irq, bttv_irq,
4328 IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv);
4329 if (result < 0) {
4330 printk(KERN_ERR "bttv%d: can't get IRQ %d\n",
4331 bttv_num,btv->c.pci->irq);
4332 goto fail1;
4333 }
4334
4335 if (0 != bttv_handle_chipset(btv)) {
4336 result = -EIO;
4337 goto fail2;
4338 }
4339
4340 /* init options from insmod args */
4341 btv->opt_combfilter = combfilter;
4342 btv->opt_lumafilter = lumafilter;
4343 btv->opt_automute = automute;
4344 btv->opt_chroma_agc = chroma_agc;
4345 btv->opt_adc_crush = adc_crush;
4346 btv->opt_vcr_hack = vcr_hack;
4347 btv->opt_whitecrush_upper = whitecrush_upper;
4348 btv->opt_whitecrush_lower = whitecrush_lower;
4349 btv->opt_uv_ratio = uv_ratio;
4350 btv->opt_full_luma_range = full_luma_range;
4351 btv->opt_coring = coring;
4352
4353 /* fill struct bttv with some useful defaults */
4354 btv->init.btv = btv;
4355 btv->init.ov.w.width = 320;
4356 btv->init.ov.w.height = 240;
4357 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
4358 btv->init.width = 320;
4359 btv->init.height = 240;
4360 btv->input = 0;
4361
4362 /* initialize hardware */
4363 if (bttv_gpio)
4364 bttv_gpio_tracking(btv,"pre-init");
4365
4366 bttv_risc_init_main(btv);
4367 init_bt848(btv);
4368
4369 /* gpio */
4370 btwrite(0x00, BT848_GPIO_REG_INP);
4371 btwrite(0x00, BT848_GPIO_OUT_EN);
4372 if (bttv_verbose)
4373 bttv_gpio_tracking(btv,"init");
4374
4375 /* needs to be done before i2c is registered */
4376 bttv_init_card1(btv);
4377
4378 /* register i2c + gpio */
4379 init_bttv_i2c(btv);
4380
4381 /* some card-specific stuff (needs working i2c) */
4382 bttv_init_card2(btv);
4383 bttv_init_tuner(btv);
4384 init_irqreg(btv);
4385
4386 /* register video4linux + input */
4387 if (!bttv_tvcards[btv->c.type].no_video) {
4388 bttv_register_video(btv);
4389 bt848_bright(btv,32768);
4390 bt848_contrast(btv,32768);
4391 bt848_hue(btv,32768);
4392 bt848_sat(btv,32768);
4393 audio_mute(btv, 1);
4394 set_input(btv, 0, btv->tvnorm);
4395 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4396 btv->crop[1] = btv->crop[0]; /* current = default */
4397 disclaim_vbi_lines(btv);
4398 disclaim_video_lines(btv);
4399 }
4400
4401 /* add subdevices and autoload dvb-bt8xx if needed */
4402 if (bttv_tvcards[btv->c.type].has_dvb) {
4403 bttv_sub_add_device(&btv->c, "dvb");
4404 request_modules(btv);
4405 }
4406
4407 if (!disable_ir) {
4408 init_bttv_i2c_ir(btv);
4409 bttv_input_init(btv);
4410 }
4411
4412 /* everything is fine */
4413 bttv_num++;
4414 return 0;
4415
4416fail2:
4417 free_irq(btv->c.pci->irq,btv);
4418
4419fail1:
4420 v4l2_device_unregister(&btv->c.v4l2_dev);
4421
4422fail0:
4423 if (btv->bt848_mmio)
4424 iounmap(btv->bt848_mmio);
4425 release_mem_region(pci_resource_start(btv->c.pci,0),
4426 pci_resource_len(btv->c.pci,0));
4427 return result;
4428}
4429
4430static void __devexit bttv_remove(struct pci_dev *pci_dev)
4431{
4432 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4433 struct bttv *btv = to_bttv(v4l2_dev);
4434
4435 if (bttv_verbose)
4436 printk("bttv%d: unloading\n",btv->c.nr);
4437
4438 if (bttv_tvcards[btv->c.type].has_dvb)
4439 flush_request_modules(btv);
4440
4441 /* shutdown everything (DMA+IRQs) */
4442 btand(~15, BT848_GPIO_DMA_CTL);
4443 btwrite(0, BT848_INT_MASK);
4444 btwrite(~0x0, BT848_INT_STAT);
4445 btwrite(0x0, BT848_GPIO_OUT_EN);
4446 if (bttv_gpio)
4447 bttv_gpio_tracking(btv,"cleanup");
4448
4449 /* tell gpio modules we are leaving ... */
4450 btv->shutdown=1;
4451 bttv_input_fini(btv);
4452 bttv_sub_del_devices(&btv->c);
4453
4454 /* unregister i2c_bus + input */
4455 fini_bttv_i2c(btv);
4456
4457 /* unregister video4linux */
4458 bttv_unregister_video(btv);
4459
4460 /* free allocated memory */
4461 btcx_riscmem_free(btv->c.pci,&btv->main);
4462
4463 /* free ressources */
4464 free_irq(btv->c.pci->irq,btv);
4465 iounmap(btv->bt848_mmio);
4466 release_mem_region(pci_resource_start(btv->c.pci,0),
4467 pci_resource_len(btv->c.pci,0));
4468
4469 v4l2_device_unregister(&btv->c.v4l2_dev);
4470 bttvs[btv->c.nr] = NULL;
4471 kfree(btv);
4472
4473 return;
4474}
4475
4476#ifdef CONFIG_PM
4477static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
4478{
4479 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4480 struct bttv *btv = to_bttv(v4l2_dev);
4481 struct bttv_buffer_set idle;
4482 unsigned long flags;
4483
4484 dprintk("bttv%d: suspend %d\n", btv->c.nr, state.event);
4485
4486 /* stop dma + irqs */
4487 spin_lock_irqsave(&btv->s_lock,flags);
4488 memset(&idle, 0, sizeof(idle));
4489 btv->state.video = btv->curr;
4490 btv->state.vbi = btv->cvbi;
4491 btv->state.loop_irq = btv->loop_irq;
4492 btv->curr = idle;
4493 btv->loop_irq = 0;
4494 bttv_buffer_activate_video(btv, &idle);
4495 bttv_buffer_activate_vbi(btv, NULL);
4496 bttv_set_dma(btv, 0);
4497 btwrite(0, BT848_INT_MASK);
4498 spin_unlock_irqrestore(&btv->s_lock,flags);
4499
4500 /* save bt878 state */
4501 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
4502 btv->state.gpio_data = gpio_read();
4503
4504 /* save pci state */
4505 pci_save_state(pci_dev);
4506 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
4507 pci_disable_device(pci_dev);
4508 btv->state.disabled = 1;
4509 }
4510 return 0;
4511}
4512
4513static int bttv_resume(struct pci_dev *pci_dev)
4514{
4515 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4516 struct bttv *btv = to_bttv(v4l2_dev);
4517 unsigned long flags;
4518 int err;
4519
4520 dprintk("bttv%d: resume\n", btv->c.nr);
4521
4522 /* restore pci state */
4523 if (btv->state.disabled) {
4524 err=pci_enable_device(pci_dev);
4525 if (err) {
4526 printk(KERN_WARNING "bttv%d: Can't enable device.\n",
4527 btv->c.nr);
4528 return err;
4529 }
4530 btv->state.disabled = 0;
4531 }
4532 err=pci_set_power_state(pci_dev, PCI_D0);
4533 if (err) {
4534 pci_disable_device(pci_dev);
4535 printk(KERN_WARNING "bttv%d: Can't enable device.\n",
4536 btv->c.nr);
4537 btv->state.disabled = 1;
4538 return err;
4539 }
4540
4541 pci_restore_state(pci_dev);
4542
4543 /* restore bt878 state */
4544 bttv_reinit_bt848(btv);
4545 gpio_inout(0xffffff, btv->state.gpio_enable);
4546 gpio_write(btv->state.gpio_data);
4547
4548 /* restart dma */
4549 spin_lock_irqsave(&btv->s_lock,flags);
4550 btv->curr = btv->state.video;
4551 btv->cvbi = btv->state.vbi;
4552 btv->loop_irq = btv->state.loop_irq;
4553 bttv_buffer_activate_video(btv, &btv->curr);
4554 bttv_buffer_activate_vbi(btv, btv->cvbi);
4555 bttv_set_dma(btv, 0);
4556 spin_unlock_irqrestore(&btv->s_lock,flags);
4557 return 0;
4558}
4559#endif
4560
4561static struct pci_device_id bttv_pci_tbl[] = {
4562 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT848), 0},
4563 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT849), 0},
4564 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT878), 0},
4565 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT879), 0},
4566 {0,}
4567};
4568
4569MODULE_DEVICE_TABLE(pci, bttv_pci_tbl);
4570
4571static struct pci_driver bttv_pci_driver = {
4572 .name = "bttv",
4573 .id_table = bttv_pci_tbl,
4574 .probe = bttv_probe,
4575 .remove = __devexit_p(bttv_remove),
4576#ifdef CONFIG_PM
4577 .suspend = bttv_suspend,
4578 .resume = bttv_resume,
4579#endif
4580};
4581
4582static int __init bttv_init_module(void)
4583{
4584 int ret;
4585
4586 bttv_num = 0;
4587
4588 printk(KERN_INFO "bttv: driver version %s loaded\n",
4589 BTTV_VERSION);
4590 if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME)
4591 gbuffers = 2;
4592 if (gbufsize > BTTV_MAX_FBUF)
4593 gbufsize = BTTV_MAX_FBUF;
4594 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK;
4595 if (bttv_verbose)
4596 printk(KERN_INFO "bttv: using %d buffers with %dk (%d pages) each for capture\n",
4597 gbuffers, gbufsize >> 10, gbufsize >> PAGE_SHIFT);
4598
4599 bttv_check_chipset();
4600
4601 ret = bus_register(&bttv_sub_bus_type);
4602 if (ret < 0) {
4603 printk(KERN_WARNING "bttv: bus_register error: %d\n", ret);
4604 return ret;
4605 }
4606 ret = pci_register_driver(&bttv_pci_driver);
4607 if (ret < 0)
4608 bus_unregister(&bttv_sub_bus_type);
4609
4610 return ret;
4611}
4612
4613static void __exit bttv_cleanup_module(void)
4614{
4615 pci_unregister_driver(&bttv_pci_driver);
4616 bus_unregister(&bttv_sub_bus_type);
4617}
4618
4619module_init(bttv_init_module);
4620module_exit(bttv_cleanup_module);
4621
4622/*
4623 * Local variables:
4624 * c-basic-offset: 8
4625 * End:
4626 */
diff --git a/drivers/media/video/bt8xx/bttv-gpio.c b/drivers/media/video/bt8xx/bttv-gpio.c
new file mode 100644
index 00000000000..13ce72c04b3
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-gpio.c
@@ -0,0 +1,187 @@
1/*
2
3 bttv-gpio.c -- gpio sub drivers
4
5 sysfs-based sub driver interface for bttv
6 mainly intended for gpio access
7
8
9 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
10 & Marcus Metzler (mocm@thp.uni-koeln.de)
11 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27*/
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/device.h>
33#include <linux/slab.h>
34#include <asm/io.h>
35
36#include "bttvp.h"
37
38/* ----------------------------------------------------------------------- */
39/* internal: the bttv "bus" */
40
41static int bttv_sub_bus_match(struct device *dev, struct device_driver *drv)
42{
43 struct bttv_sub_driver *sub = to_bttv_sub_drv(drv);
44 int len = strlen(sub->wanted);
45
46 if (0 == strncmp(dev_name(dev), sub->wanted, len))
47 return 1;
48 return 0;
49}
50
51static int bttv_sub_probe(struct device *dev)
52{
53 struct bttv_sub_device *sdev = to_bttv_sub_dev(dev);
54 struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver);
55
56 return sub->probe ? sub->probe(sdev) : -ENODEV;
57}
58
59static int bttv_sub_remove(struct device *dev)
60{
61 struct bttv_sub_device *sdev = to_bttv_sub_dev(dev);
62 struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver);
63
64 if (sub->remove)
65 sub->remove(sdev);
66 return 0;
67}
68
69struct bus_type bttv_sub_bus_type = {
70 .name = "bttv-sub",
71 .match = &bttv_sub_bus_match,
72 .probe = bttv_sub_probe,
73 .remove = bttv_sub_remove,
74};
75
76static void release_sub_device(struct device *dev)
77{
78 struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
79 kfree(sub);
80}
81
82int bttv_sub_add_device(struct bttv_core *core, char *name)
83{
84 struct bttv_sub_device *sub;
85 int err;
86
87 sub = kzalloc(sizeof(*sub),GFP_KERNEL);
88 if (NULL == sub)
89 return -ENOMEM;
90
91 sub->core = core;
92 sub->dev.parent = &core->pci->dev;
93 sub->dev.bus = &bttv_sub_bus_type;
94 sub->dev.release = release_sub_device;
95 dev_set_name(&sub->dev, "%s%d", name, core->nr);
96
97 err = device_register(&sub->dev);
98 if (0 != err) {
99 kfree(sub);
100 return err;
101 }
102 printk("bttv%d: add subdevice \"%s\"\n", core->nr, dev_name(&sub->dev));
103 list_add_tail(&sub->list,&core->subs);
104 return 0;
105}
106
107int bttv_sub_del_devices(struct bttv_core *core)
108{
109 struct bttv_sub_device *sub, *save;
110
111 list_for_each_entry_safe(sub, save, &core->subs, list) {
112 list_del(&sub->list);
113 device_unregister(&sub->dev);
114 }
115 return 0;
116}
117
118/* ----------------------------------------------------------------------- */
119/* external: sub-driver register/unregister */
120
121int bttv_sub_register(struct bttv_sub_driver *sub, char *wanted)
122{
123 sub->drv.bus = &bttv_sub_bus_type;
124 snprintf(sub->wanted,sizeof(sub->wanted),"%s",wanted);
125 return driver_register(&sub->drv);
126}
127EXPORT_SYMBOL(bttv_sub_register);
128
129int bttv_sub_unregister(struct bttv_sub_driver *sub)
130{
131 driver_unregister(&sub->drv);
132 return 0;
133}
134EXPORT_SYMBOL(bttv_sub_unregister);
135
136/* ----------------------------------------------------------------------- */
137/* external: gpio access functions */
138
139void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits)
140{
141 struct bttv *btv = container_of(core, struct bttv, c);
142 unsigned long flags;
143 u32 data;
144
145 spin_lock_irqsave(&btv->gpio_lock,flags);
146 data = btread(BT848_GPIO_OUT_EN);
147 data = data & ~mask;
148 data = data | (mask & outbits);
149 btwrite(data,BT848_GPIO_OUT_EN);
150 spin_unlock_irqrestore(&btv->gpio_lock,flags);
151}
152
153u32 bttv_gpio_read(struct bttv_core *core)
154{
155 struct bttv *btv = container_of(core, struct bttv, c);
156 u32 value;
157
158 value = btread(BT848_GPIO_DATA);
159 return value;
160}
161
162void bttv_gpio_write(struct bttv_core *core, u32 value)
163{
164 struct bttv *btv = container_of(core, struct bttv, c);
165
166 btwrite(value,BT848_GPIO_DATA);
167}
168
169void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits)
170{
171 struct bttv *btv = container_of(core, struct bttv, c);
172 unsigned long flags;
173 u32 data;
174
175 spin_lock_irqsave(&btv->gpio_lock,flags);
176 data = btread(BT848_GPIO_DATA);
177 data = data & ~mask;
178 data = data | (mask & bits);
179 btwrite(data,BT848_GPIO_DATA);
180 spin_unlock_irqrestore(&btv->gpio_lock,flags);
181}
182
183/*
184 * Local variables:
185 * c-basic-offset: 8
186 * End:
187 */
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
new file mode 100644
index 00000000000..d49b675045f
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -0,0 +1,391 @@
1/*
2
3 bttv-i2c.c -- all the i2c code is here
4
5 bttv - Bt848 frame grabber driver
6
7 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
8 & Marcus Metzler (mocm@thp.uni-koeln.de)
9 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
10
11 (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
12 - Multituner support and i2c address binding
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28*/
29
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33
34#include "bttvp.h"
35#include <media/v4l2-common.h>
36#include <linux/jiffies.h>
37#include <asm/io.h>
38
39static int i2c_debug;
40static int i2c_hw;
41static int i2c_scan;
42module_param(i2c_debug, int, 0644);
43MODULE_PARM_DESC(i2c_debug, "configure i2c debug level");
44module_param(i2c_hw, int, 0444);
45MODULE_PARM_DESC(i2c_hw,"force use of hardware i2c support, "
46 "instead of software bitbang");
47module_param(i2c_scan, int, 0444);
48MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
49
50static unsigned int i2c_udelay = 5;
51module_param(i2c_udelay, int, 0444);
52MODULE_PARM_DESC(i2c_udelay,"soft i2c delay at insmod time, in usecs "
53 "(should be 5 or higher). Lower value means higher bus speed.");
54
55/* ----------------------------------------------------------------------- */
56/* I2C functions - bitbanging adapter (software i2c) */
57
58static void bttv_bit_setscl(void *data, int state)
59{
60 struct bttv *btv = (struct bttv*)data;
61
62 if (state)
63 btv->i2c_state |= 0x02;
64 else
65 btv->i2c_state &= ~0x02;
66 btwrite(btv->i2c_state, BT848_I2C);
67 btread(BT848_I2C);
68}
69
70static void bttv_bit_setsda(void *data, int state)
71{
72 struct bttv *btv = (struct bttv*)data;
73
74 if (state)
75 btv->i2c_state |= 0x01;
76 else
77 btv->i2c_state &= ~0x01;
78 btwrite(btv->i2c_state, BT848_I2C);
79 btread(BT848_I2C);
80}
81
82static int bttv_bit_getscl(void *data)
83{
84 struct bttv *btv = (struct bttv*)data;
85 int state;
86
87 state = btread(BT848_I2C) & 0x02 ? 1 : 0;
88 return state;
89}
90
91static int bttv_bit_getsda(void *data)
92{
93 struct bttv *btv = (struct bttv*)data;
94 int state;
95
96 state = btread(BT848_I2C) & 0x01;
97 return state;
98}
99
100static struct i2c_algo_bit_data __devinitdata bttv_i2c_algo_bit_template = {
101 .setsda = bttv_bit_setsda,
102 .setscl = bttv_bit_setscl,
103 .getsda = bttv_bit_getsda,
104 .getscl = bttv_bit_getscl,
105 .udelay = 16,
106 .timeout = 200,
107};
108
109/* ----------------------------------------------------------------------- */
110/* I2C functions - hardware i2c */
111
112static u32 functionality(struct i2c_adapter *adap)
113{
114 return I2C_FUNC_SMBUS_EMUL;
115}
116
117static int
118bttv_i2c_wait_done(struct bttv *btv)
119{
120 int rc = 0;
121
122 /* timeout */
123 if (wait_event_interruptible_timeout(btv->i2c_queue,
124 btv->i2c_done, msecs_to_jiffies(85)) == -ERESTARTSYS)
125 rc = -EIO;
126
127 if (btv->i2c_done & BT848_INT_RACK)
128 rc = 1;
129 btv->i2c_done = 0;
130 return rc;
131}
132
133#define I2C_HW (BT878_I2C_MODE | BT848_I2C_SYNC |\
134 BT848_I2C_SCL | BT848_I2C_SDA)
135
136static int
137bttv_i2c_sendbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
138{
139 u32 xmit;
140 int retval,cnt;
141
142 /* sanity checks */
143 if (0 == msg->len)
144 return -EINVAL;
145
146 /* start, address + first byte */
147 xmit = (msg->addr << 25) | (msg->buf[0] << 16) | I2C_HW;
148 if (msg->len > 1 || !last)
149 xmit |= BT878_I2C_NOSTOP;
150 btwrite(xmit, BT848_I2C);
151 retval = bttv_i2c_wait_done(btv);
152 if (retval < 0)
153 goto err;
154 if (retval == 0)
155 goto eio;
156 if (i2c_debug) {
157 printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
158 if (!(xmit & BT878_I2C_NOSTOP))
159 printk(" >\n");
160 }
161
162 for (cnt = 1; cnt < msg->len; cnt++ ) {
163 /* following bytes */
164 xmit = (msg->buf[cnt] << 24) | I2C_HW | BT878_I2C_NOSTART;
165 if (cnt < msg->len-1 || !last)
166 xmit |= BT878_I2C_NOSTOP;
167 btwrite(xmit, BT848_I2C);
168 retval = bttv_i2c_wait_done(btv);
169 if (retval < 0)
170 goto err;
171 if (retval == 0)
172 goto eio;
173 if (i2c_debug) {
174 printk(" %02x", msg->buf[cnt]);
175 if (!(xmit & BT878_I2C_NOSTOP))
176 printk(" >\n");
177 }
178 }
179 return msg->len;
180
181 eio:
182 retval = -EIO;
183 err:
184 if (i2c_debug)
185 printk(" ERR: %d\n",retval);
186 return retval;
187}
188
189static int
190bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
191{
192 u32 xmit;
193 u32 cnt;
194 int retval;
195
196 for(cnt = 0; cnt < msg->len; cnt++) {
197 xmit = (msg->addr << 25) | (1 << 24) | I2C_HW;
198 if (cnt < msg->len-1)
199 xmit |= BT848_I2C_W3B;
200 if (cnt < msg->len-1 || !last)
201 xmit |= BT878_I2C_NOSTOP;
202 if (cnt)
203 xmit |= BT878_I2C_NOSTART;
204 btwrite(xmit, BT848_I2C);
205 retval = bttv_i2c_wait_done(btv);
206 if (retval < 0)
207 goto err;
208 if (retval == 0)
209 goto eio;
210 msg->buf[cnt] = ((u32)btread(BT848_I2C) >> 8) & 0xff;
211 if (i2c_debug) {
212 if (!(xmit & BT878_I2C_NOSTART))
213 printk(" <R %02x", (msg->addr << 1) +1);
214 printk(" =%02x", msg->buf[cnt]);
215 if (!(xmit & BT878_I2C_NOSTOP))
216 printk(" >\n");
217 }
218 }
219 return msg->len;
220
221 eio:
222 retval = -EIO;
223 err:
224 if (i2c_debug)
225 printk(" ERR: %d\n",retval);
226 return retval;
227}
228
229static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
230{
231 struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap);
232 struct bttv *btv = to_bttv(v4l2_dev);
233 int retval = 0;
234 int i;
235
236 if (i2c_debug)
237 printk("bt-i2c:");
238 btwrite(BT848_INT_I2CDONE|BT848_INT_RACK, BT848_INT_STAT);
239 for (i = 0 ; i < num; i++) {
240 if (msgs[i].flags & I2C_M_RD) {
241 /* read */
242 retval = bttv_i2c_readbytes(btv, &msgs[i], i+1 == num);
243 if (retval < 0)
244 goto err;
245 } else {
246 /* write */
247 retval = bttv_i2c_sendbytes(btv, &msgs[i], i+1 == num);
248 if (retval < 0)
249 goto err;
250 }
251 }
252 return num;
253
254 err:
255 return retval;
256}
257
258static const struct i2c_algorithm bttv_algo = {
259 .master_xfer = bttv_i2c_xfer,
260 .functionality = functionality,
261};
262
263/* ----------------------------------------------------------------------- */
264/* I2C functions - common stuff */
265
266/* read I2C */
267int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for)
268{
269 unsigned char buffer = 0;
270
271 if (0 != btv->i2c_rc)
272 return -1;
273 if (bttv_verbose && NULL != probe_for)
274 printk(KERN_INFO "bttv%d: i2c: checking for %s @ 0x%02x... ",
275 btv->c.nr,probe_for,addr);
276 btv->i2c_client.addr = addr >> 1;
277 if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
278 if (NULL != probe_for) {
279 if (bttv_verbose)
280 printk("not found\n");
281 } else
282 printk(KERN_WARNING "bttv%d: i2c read 0x%x: error\n",
283 btv->c.nr,addr);
284 return -1;
285 }
286 if (bttv_verbose && NULL != probe_for)
287 printk("found\n");
288 return buffer;
289}
290
291/* write I2C */
292int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
293 unsigned char b2, int both)
294{
295 unsigned char buffer[2];
296 int bytes = both ? 2 : 1;
297
298 if (0 != btv->i2c_rc)
299 return -1;
300 btv->i2c_client.addr = addr >> 1;
301 buffer[0] = b1;
302 buffer[1] = b2;
303 if (bytes != i2c_master_send(&btv->i2c_client, buffer, bytes))
304 return -1;
305 return 0;
306}
307
308/* read EEPROM content */
309void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr)
310{
311 memset(eedata, 0, 256);
312 if (0 != btv->i2c_rc)
313 return;
314 btv->i2c_client.addr = addr >> 1;
315 tveeprom_read(&btv->i2c_client, eedata, 256);
316}
317
318static char *i2c_devs[128] = {
319 [ 0x1c >> 1 ] = "lgdt330x",
320 [ 0x30 >> 1 ] = "IR (hauppauge)",
321 [ 0x80 >> 1 ] = "msp34xx",
322 [ 0x86 >> 1 ] = "tda9887",
323 [ 0xa0 >> 1 ] = "eeprom",
324 [ 0xc0 >> 1 ] = "tuner (analog)",
325 [ 0xc2 >> 1 ] = "tuner (analog)",
326};
327
328static void do_i2c_scan(char *name, struct i2c_client *c)
329{
330 unsigned char buf;
331 int i,rc;
332
333 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
334 c->addr = i;
335 rc = i2c_master_recv(c,&buf,0);
336 if (rc < 0)
337 continue;
338 printk("%s: i2c scan: found device @ 0x%x [%s]\n",
339 name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
340 }
341}
342
343/* init + register i2c algo-bit adapter */
344int __devinit init_bttv_i2c(struct bttv *btv)
345{
346 strlcpy(btv->i2c_client.name, "bttv internal", I2C_NAME_SIZE);
347
348 if (i2c_hw)
349 btv->use_i2c_hw = 1;
350 if (btv->use_i2c_hw) {
351 /* bt878 */
352 strlcpy(btv->c.i2c_adap.name, "bt878",
353 sizeof(btv->c.i2c_adap.name));
354 btv->c.i2c_adap.algo = &bttv_algo;
355 } else {
356 /* bt848 */
357 /* Prevents usage of invalid delay values */
358 if (i2c_udelay<5)
359 i2c_udelay=5;
360
361 strlcpy(btv->c.i2c_adap.name, "bttv",
362 sizeof(btv->c.i2c_adap.name));
363 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template,
364 sizeof(bttv_i2c_algo_bit_template));
365 btv->i2c_algo.udelay = i2c_udelay;
366 btv->i2c_algo.data = btv;
367 btv->c.i2c_adap.algo_data = &btv->i2c_algo;
368 }
369 btv->c.i2c_adap.owner = THIS_MODULE;
370
371 btv->c.i2c_adap.dev.parent = &btv->c.pci->dev;
372 snprintf(btv->c.i2c_adap.name, sizeof(btv->c.i2c_adap.name),
373 "bt%d #%d [%s]", btv->id, btv->c.nr,
374 btv->use_i2c_hw ? "hw" : "sw");
375
376 i2c_set_adapdata(&btv->c.i2c_adap, &btv->c.v4l2_dev);
377 btv->i2c_client.adapter = &btv->c.i2c_adap;
378
379
380 if (btv->use_i2c_hw) {
381 btv->i2c_rc = i2c_add_adapter(&btv->c.i2c_adap);
382 } else {
383 bttv_bit_setscl(btv,1);
384 bttv_bit_setsda(btv,1);
385 btv->i2c_rc = i2c_bit_add_bus(&btv->c.i2c_adap);
386 }
387 if (0 == btv->i2c_rc && i2c_scan)
388 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client);
389
390 return btv->i2c_rc;
391}
diff --git a/drivers/media/video/bt8xx/bttv-if.c b/drivers/media/video/bt8xx/bttv-if.c
new file mode 100644
index 00000000000..a6a540dc9e4
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-if.c
@@ -0,0 +1,121 @@
1/*
2
3 bttv-if.c -- old gpio interface to other kernel modules
4 don't use in new code, will go away in 2.7
5 have a look at bttv-gpio.c instead.
6
7 bttv - Bt848 frame grabber driver
8
9 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
10 & Marcus Metzler (mocm@thp.uni-koeln.de)
11 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27*/
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <asm/io.h>
33
34#include "bttvp.h"
35
36EXPORT_SYMBOL(bttv_get_pcidev);
37EXPORT_SYMBOL(bttv_gpio_enable);
38EXPORT_SYMBOL(bttv_read_gpio);
39EXPORT_SYMBOL(bttv_write_gpio);
40
41/* ----------------------------------------------------------------------- */
42/* Exported functions - for other modules which want to access the */
43/* gpio ports (IR for example) */
44/* see bttv.h for comments */
45
46struct pci_dev* bttv_get_pcidev(unsigned int card)
47{
48 if (card >= bttv_num)
49 return NULL;
50 if (!bttvs[card])
51 return NULL;
52
53 return bttvs[card]->c.pci;
54}
55
56
57int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
58{
59 struct bttv *btv;
60
61 if (card >= bttv_num) {
62 return -EINVAL;
63 }
64
65 btv = bttvs[card];
66 if (!btv)
67 return -ENODEV;
68
69 gpio_inout(mask,data);
70 if (bttv_gpio)
71 bttv_gpio_tracking(btv,"extern enable");
72 return 0;
73}
74
75int bttv_read_gpio(unsigned int card, unsigned long *data)
76{
77 struct bttv *btv;
78
79 if (card >= bttv_num) {
80 return -EINVAL;
81 }
82
83 btv = bttvs[card];
84 if (!btv)
85 return -ENODEV;
86
87 if(btv->shutdown) {
88 return -ENODEV;
89 }
90
91/* prior setting BT848_GPIO_REG_INP is (probably) not needed
92 because we set direct input on init */
93 *data = gpio_read();
94 return 0;
95}
96
97int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
98{
99 struct bttv *btv;
100
101 if (card >= bttv_num) {
102 return -EINVAL;
103 }
104
105 btv = bttvs[card];
106 if (!btv)
107 return -ENODEV;
108
109/* prior setting BT848_GPIO_REG_INP is (probably) not needed
110 because direct input is set on init */
111 gpio_bits(mask,data);
112 if (bttv_gpio)
113 bttv_gpio_tracking(btv,"extern write");
114 return 0;
115}
116
117/*
118 * Local variables:
119 * c-basic-offset: 8
120 * End:
121 */
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
new file mode 100644
index 00000000000..677d70c0e1c
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -0,0 +1,588 @@
1/*
2 *
3 * Copyright (c) 2003 Gerd Knorr
4 * Copyright (c) 2003 Pavel Machek
5 *
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.
10 *
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.
15 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/interrupt.h>
25#include <linux/input.h>
26#include <linux/slab.h>
27
28#include "bttv.h"
29#include "bttvp.h"
30
31
32static int ir_debug;
33module_param(ir_debug, int, 0644);
34
35static int ir_rc5_remote_gap = 885;
36module_param(ir_rc5_remote_gap, int, 0644);
37
38#undef dprintk
39#define dprintk(arg...) do { \
40 if (ir_debug >= 1) \
41 printk(arg); \
42} while (0)
43
44#define DEVNAME "bttv-input"
45
46#define MODULE_NAME "bttv"
47
48/* ---------------------------------------------------------------------- */
49
50static void ir_handle_key(struct bttv *btv)
51{
52 struct bttv_ir *ir = btv->remote;
53 u32 gpio,data;
54
55 /* read gpio value */
56 gpio = bttv_gpio_read(&btv->c);
57 if (ir->polling) {
58 if (ir->last_gpio == gpio)
59 return;
60 ir->last_gpio = gpio;
61 }
62
63 /* extract data */
64 data = ir_extract_bits(gpio, ir->mask_keycode);
65 dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
66 gpio, data,
67 ir->polling ? "poll" : "irq",
68 (gpio & ir->mask_keydown) ? " down" : "",
69 (gpio & ir->mask_keyup) ? " up" : "");
70
71 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
72 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
73 rc_keydown_notimeout(ir->dev, data, 0);
74 } else {
75 /* HACK: Probably, ir->mask_keydown is missing
76 for this board */
77 if (btv->c.type == BTTV_BOARD_WINFAST2000)
78 rc_keydown_notimeout(ir->dev, data, 0);
79
80 rc_keyup(ir->dev);
81 }
82}
83
84static void ir_enltv_handle_key(struct bttv *btv)
85{
86 struct bttv_ir *ir = btv->remote;
87 u32 gpio, data, keyup;
88
89 /* read gpio value */
90 gpio = bttv_gpio_read(&btv->c);
91
92 /* extract data */
93 data = ir_extract_bits(gpio, ir->mask_keycode);
94
95 /* Check if it is keyup */
96 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
97
98 if ((ir->last_gpio & 0x7f) != data) {
99 dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
100 gpio, data,
101 (gpio & ir->mask_keyup) ? " up" : "up/down");
102
103 rc_keydown_notimeout(ir->dev, data, 0);
104 if (keyup)
105 rc_keyup(ir->dev);
106 } else {
107 if ((ir->last_gpio & 1 << 31) == keyup)
108 return;
109
110 dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
111 gpio, data,
112 (gpio & ir->mask_keyup) ? " up" : "down");
113
114 if (keyup)
115 rc_keyup(ir->dev);
116 else
117 rc_keydown_notimeout(ir->dev, data, 0);
118 }
119
120 ir->last_gpio = data | keyup;
121}
122
123static int bttv_rc5_irq(struct bttv *btv);
124
125void bttv_input_irq(struct bttv *btv)
126{
127 struct bttv_ir *ir = btv->remote;
128
129 if (ir->rc5_gpio)
130 bttv_rc5_irq(btv);
131 else if (!ir->polling)
132 ir_handle_key(btv);
133}
134
135static void bttv_input_timer(unsigned long data)
136{
137 struct bttv *btv = (struct bttv*)data;
138 struct bttv_ir *ir = btv->remote;
139
140 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
141 ir_enltv_handle_key(btv);
142 else
143 ir_handle_key(btv);
144 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
145}
146
147/*
148 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
149 * on the rc-core way. As we need to be sure that both IRQ transitions are
150 * properly triggered, Better to touch it only with this hardware for
151 * testing.
152 */
153
154#define RC5_START(x) (((x) >> 12) & 3)
155#define RC5_TOGGLE(x) (((x) >> 11) & 1)
156#define RC5_ADDR(x) (((x) >> 6) & 31)
157#define RC5_INSTR(x) ((x) & 63)
158
159/* decode raw bit pattern to RC5 code */
160static u32 bttv_rc5_decode(unsigned int code)
161{
162 unsigned int org_code = code;
163 unsigned int pair;
164 unsigned int rc5 = 0;
165 int i;
166
167 for (i = 0; i < 14; ++i) {
168 pair = code & 0x3;
169 code >>= 2;
170
171 rc5 <<= 1;
172 switch (pair) {
173 case 0:
174 case 2:
175 break;
176 case 1:
177 rc5 |= 1;
178 break;
179 case 3:
180 dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
181 org_code);
182 return 0;
183 }
184 }
185 dprintk(KERN_INFO DEVNAME ":"
186 "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
187 "instr=%x\n", rc5, org_code, RC5_START(rc5),
188 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
189 return rc5;
190}
191
192static void bttv_rc5_timer_end(unsigned long data)
193{
194 struct bttv_ir *ir = (struct bttv_ir *)data;
195 struct timeval tv;
196 u32 gap;
197 u32 rc5 = 0;
198
199 /* get time */
200 do_gettimeofday(&tv);
201
202 /* avoid overflow with gap >1s */
203 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
204 gap = 200000;
205 } else {
206 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
207 tv.tv_usec - ir->base_time.tv_usec;
208 }
209
210 /* signal we're ready to start a new code */
211 ir->active = false;
212
213 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
214 if (gap < 28000) {
215 dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
216 return;
217 }
218
219 if (ir->last_bit < 20) {
220 /* ignore spurious codes (caused by light/other remotes) */
221 dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
222 } else {
223 ir->code = (ir->code << ir->shift_by) | 1;
224 rc5 = bttv_rc5_decode(ir->code);
225
226 /* two start bits? */
227 if (RC5_START(rc5) != ir->start) {
228 printk(KERN_INFO DEVNAME ":"
229 " rc5 start bits invalid: %u\n", RC5_START(rc5));
230
231 /* right address? */
232 } else if (RC5_ADDR(rc5) == ir->addr) {
233 u32 toggle = RC5_TOGGLE(rc5);
234 u32 instr = RC5_INSTR(rc5);
235
236 /* Good code */
237 rc_keydown(ir->dev, instr, toggle);
238 dprintk(KERN_INFO DEVNAME ":"
239 " instruction %x, toggle %x\n",
240 instr, toggle);
241 }
242 }
243}
244
245static int bttv_rc5_irq(struct bttv *btv)
246{
247 struct bttv_ir *ir = btv->remote;
248 struct timeval tv;
249 u32 gpio;
250 u32 gap;
251 unsigned long current_jiffies;
252
253 /* read gpio port */
254 gpio = bttv_gpio_read(&btv->c);
255
256 /* get time of bit */
257 current_jiffies = jiffies;
258 do_gettimeofday(&tv);
259
260 /* avoid overflow with gap >1s */
261 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
262 gap = 200000;
263 } else {
264 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
265 tv.tv_usec - ir->base_time.tv_usec;
266 }
267
268 dprintk(KERN_INFO DEVNAME ": RC5 IRQ: gap %d us for %s\n",
269 gap, (gpio & 0x20) ? "mark" : "space");
270
271 /* remote IRQ? */
272 if (!(gpio & 0x20))
273 return 0;
274
275 /* active code => add bit */
276 if (ir->active) {
277 /* only if in the code (otherwise spurious IRQ or timer
278 late) */
279 if (ir->last_bit < 28) {
280 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
281 ir_rc5_remote_gap;
282 ir->code |= 1 << ir->last_bit;
283 }
284 /* starting new code */
285 } else {
286 ir->active = true;
287 ir->code = 0;
288 ir->base_time = tv;
289 ir->last_bit = 0;
290
291 mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30));
292 }
293
294 /* toggle GPIO pin 4 to reset the irq */
295 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
296 bttv_gpio_write(&btv->c, gpio | (1 << 4));
297 return 1;
298}
299
300/* ---------------------------------------------------------------------- */
301
302static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
303{
304 if (ir->polling) {
305 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
306 ir->timer.expires = jiffies + msecs_to_jiffies(1000);
307 add_timer(&ir->timer);
308 } else if (ir->rc5_gpio) {
309 /* set timer_end for code completion */
310 setup_timer(&ir->timer, bttv_rc5_timer_end, (unsigned long)ir);
311 ir->shift_by = 1;
312 ir->start = 3;
313 ir->addr = 0x0;
314 ir->rc5_remote_gap = ir_rc5_remote_gap;
315 }
316}
317
318static void bttv_ir_stop(struct bttv *btv)
319{
320 if (btv->remote->polling)
321 del_timer_sync(&btv->remote->timer);
322
323 if (btv->remote->rc5_gpio) {
324 u32 gpio;
325
326 del_timer_sync(&btv->remote->timer);
327
328 gpio = bttv_gpio_read(&btv->c);
329 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
330 }
331}
332
333/*
334 * Get_key functions used by I2C remotes
335 */
336
337static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
338{
339 unsigned char b;
340
341 /* poll IR chip */
342 if (1 != i2c_master_recv(ir->c, &b, 1)) {
343 dprintk(KERN_INFO DEVNAME ": read error\n");
344 return -EIO;
345 }
346
347 /* ignore 0xaa */
348 if (b==0xaa)
349 return 0;
350 dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
351
352 /*
353 * NOTE:
354 * lirc_i2c maps the pv951 code as:
355 * addr = 0x61D6
356 * cmd = bit_reverse (b)
357 * So, it seems that this device uses NEC extended
358 * I decided to not fix the table, due to two reasons:
359 * 1) Without the actual device, this is only a guess;
360 * 2) As the addr is not reported via I2C, nor can be changed,
361 * the device is bound to the vendor-provided RC.
362 */
363
364 *ir_key = b;
365 *ir_raw = b;
366 return 1;
367}
368
369/* Instantiate the I2C IR receiver device, if present */
370void __devinit init_bttv_i2c_ir(struct bttv *btv)
371{
372 const unsigned short addr_list[] = {
373 0x1a, 0x18, 0x64, 0x30, 0x71,
374 I2C_CLIENT_END
375 };
376 struct i2c_board_info info;
377
378 if (0 != btv->i2c_rc)
379 return;
380
381 memset(&info, 0, sizeof(struct i2c_board_info));
382 memset(&btv->init_data, 0, sizeof(btv->init_data));
383 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
384
385 switch (btv->c.type) {
386 case BTTV_BOARD_PV951:
387 btv->init_data.name = "PV951";
388 btv->init_data.get_key = get_key_pv951;
389 btv->init_data.ir_codes = RC_MAP_PV951;
390 info.addr = 0x4b;
391 break;
392 default:
393 /*
394 * The external IR receiver is at i2c address 0x34 (0x35 for
395 * reads). Future Hauppauge cards will have an internal
396 * receiver at 0x30 (0x31 for reads). In theory, both can be
397 * fitted, and Hauppauge suggest an external overrides an
398 * internal.
399 * That's why we probe 0x1a (~0x34) first. CB
400 */
401
402 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
403 return;
404 }
405
406 if (btv->init_data.name)
407 info.platform_data = &btv->init_data;
408 i2c_new_device(&btv->c.i2c_adap, &info);
409
410 return;
411}
412
413int __devexit fini_bttv_i2c(struct bttv *btv)
414{
415 if (0 != btv->i2c_rc)
416 return 0;
417
418 return i2c_del_adapter(&btv->c.i2c_adap);
419}
420
421int bttv_input_init(struct bttv *btv)
422{
423 struct bttv_ir *ir;
424 char *ir_codes = NULL;
425 struct rc_dev *rc;
426 int err = -ENOMEM;
427
428 if (!btv->has_remote)
429 return -ENODEV;
430
431 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
432 rc = rc_allocate_device();
433 if (!ir || !rc)
434 goto err_out_free;
435
436 /* detect & configure */
437 switch (btv->c.type) {
438 case BTTV_BOARD_AVERMEDIA:
439 case BTTV_BOARD_AVPHONE98:
440 case BTTV_BOARD_AVERMEDIA98:
441 ir_codes = RC_MAP_AVERMEDIA;
442 ir->mask_keycode = 0xf88000;
443 ir->mask_keydown = 0x010000;
444 ir->polling = 50; // ms
445 break;
446
447 case BTTV_BOARD_AVDVBT_761:
448 case BTTV_BOARD_AVDVBT_771:
449 ir_codes = RC_MAP_AVERMEDIA_DVBT;
450 ir->mask_keycode = 0x0f00c0;
451 ir->mask_keydown = 0x000020;
452 ir->polling = 50; // ms
453 break;
454
455 case BTTV_BOARD_PXELVWPLTVPAK:
456 ir_codes = RC_MAP_PIXELVIEW;
457 ir->mask_keycode = 0x003e00;
458 ir->mask_keyup = 0x010000;
459 ir->polling = 50; // ms
460 break;
461 case BTTV_BOARD_PV_M4900:
462 case BTTV_BOARD_PV_BT878P_9B:
463 case BTTV_BOARD_PV_BT878P_PLUS:
464 ir_codes = RC_MAP_PIXELVIEW;
465 ir->mask_keycode = 0x001f00;
466 ir->mask_keyup = 0x008000;
467 ir->polling = 50; // ms
468 break;
469
470 case BTTV_BOARD_WINFAST2000:
471 ir_codes = RC_MAP_WINFAST;
472 ir->mask_keycode = 0x1f8;
473 break;
474 case BTTV_BOARD_MAGICTVIEW061:
475 case BTTV_BOARD_MAGICTVIEW063:
476 ir_codes = RC_MAP_WINFAST;
477 ir->mask_keycode = 0x0008e000;
478 ir->mask_keydown = 0x00200000;
479 break;
480 case BTTV_BOARD_APAC_VIEWCOMP:
481 ir_codes = RC_MAP_APAC_VIEWCOMP;
482 ir->mask_keycode = 0x001f00;
483 ir->mask_keyup = 0x008000;
484 ir->polling = 50; // ms
485 break;
486 case BTTV_BOARD_ASKEY_CPH03X:
487 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
488 case BTTV_BOARD_CONTVFMI:
489 ir_codes = RC_MAP_PIXELVIEW;
490 ir->mask_keycode = 0x001F00;
491 ir->mask_keyup = 0x006000;
492 ir->polling = 50; // ms
493 break;
494 case BTTV_BOARD_NEBULA_DIGITV:
495 ir_codes = RC_MAP_NEBULA;
496 ir->rc5_gpio = true;
497 break;
498 case BTTV_BOARD_MACHTV_MAGICTV:
499 ir_codes = RC_MAP_APAC_VIEWCOMP;
500 ir->mask_keycode = 0x001F00;
501 ir->mask_keyup = 0x004000;
502 ir->polling = 50; /* ms */
503 break;
504 case BTTV_BOARD_KOZUMI_KTV_01C:
505 ir_codes = RC_MAP_PCTV_SEDNA;
506 ir->mask_keycode = 0x001f00;
507 ir->mask_keyup = 0x006000;
508 ir->polling = 50; /* ms */
509 break;
510 case BTTV_BOARD_ENLTV_FM_2:
511 ir_codes = RC_MAP_ENCORE_ENLTV2;
512 ir->mask_keycode = 0x00fd00;
513 ir->mask_keyup = 0x000080;
514 ir->polling = 1; /* ms */
515 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
516 ir->mask_keycode);
517 break;
518 }
519 if (NULL == ir_codes) {
520 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
521 err = -ENODEV;
522 goto err_out_free;
523 }
524
525 if (ir->rc5_gpio) {
526 u32 gpio;
527 /* enable remote irq */
528 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
529 gpio = bttv_gpio_read(&btv->c);
530 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
531 bttv_gpio_write(&btv->c, gpio | (1 << 4));
532 } else {
533 /* init hardware-specific stuff */
534 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
535 }
536
537 /* init input device */
538 ir->dev = rc;
539
540 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
541 btv->c.type);
542 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
543 pci_name(btv->c.pci));
544
545 rc->input_name = ir->name;
546 rc->input_phys = ir->phys;
547 rc->input_id.bustype = BUS_PCI;
548 rc->input_id.version = 1;
549 if (btv->c.pci->subsystem_vendor) {
550 rc->input_id.vendor = btv->c.pci->subsystem_vendor;
551 rc->input_id.product = btv->c.pci->subsystem_device;
552 } else {
553 rc->input_id.vendor = btv->c.pci->vendor;
554 rc->input_id.product = btv->c.pci->device;
555 }
556 rc->dev.parent = &btv->c.pci->dev;
557 rc->map_name = ir_codes;
558 rc->driver_name = MODULE_NAME;
559
560 btv->remote = ir;
561 bttv_ir_start(btv, ir);
562
563 /* all done */
564 err = rc_register_device(rc);
565 if (err)
566 goto err_out_stop;
567
568 return 0;
569
570 err_out_stop:
571 bttv_ir_stop(btv);
572 btv->remote = NULL;
573 err_out_free:
574 rc_free_device(rc);
575 kfree(ir);
576 return err;
577}
578
579void bttv_input_fini(struct bttv *btv)
580{
581 if (btv->remote == NULL)
582 return;
583
584 bttv_ir_stop(btv);
585 rc_unregister_device(btv->remote->dev);
586 kfree(btv->remote);
587 btv->remote = NULL;
588}
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
new file mode 100644
index 00000000000..9b57d091da4
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -0,0 +1,910 @@
1/*
2
3 bttv-risc.c -- interfaces to other kernel modules
4
5 bttv risc code handling
6 - memory management
7 - generation
8
9 (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25*/
26
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <linux/vmalloc.h>
32#include <linux/interrupt.h>
33#include <asm/page.h>
34#include <asm/pgtable.h>
35#include <media/v4l2-ioctl.h>
36
37#include "bttvp.h"
38
39#define VCR_HACK_LINES 4
40
41/* ---------------------------------------------------------- */
42/* risc code generators */
43
44int
45bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
46 struct scatterlist *sglist,
47 unsigned int offset, unsigned int bpl,
48 unsigned int padding, unsigned int skip_lines,
49 unsigned int store_lines)
50{
51 u32 instructions,line,todo;
52 struct scatterlist *sg;
53 __le32 *rp;
54 int rc;
55
56 /* estimate risc mem: worst case is one write per page border +
57 one write per scan line + sync + jump (all 2 dwords). padding
58 can cause next bpl to start close to a page border. First DMA
59 region may be smaller than PAGE_SIZE */
60 instructions = skip_lines * 4;
61 instructions += (1 + ((bpl + padding) * store_lines)
62 / PAGE_SIZE + store_lines) * 8;
63 instructions += 2 * 8;
64 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions)) < 0)
65 return rc;
66
67 /* sync instruction */
68 rp = risc->cpu;
69 *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM1);
70 *(rp++) = cpu_to_le32(0);
71
72 while (skip_lines-- > 0) {
73 *(rp++) = cpu_to_le32(BT848_RISC_SKIP | BT848_RISC_SOL |
74 BT848_RISC_EOL | bpl);
75 }
76
77 /* scan lines */
78 sg = sglist;
79 for (line = 0; line < store_lines; line++) {
80 if ((btv->opt_vcr_hack) &&
81 (line >= (store_lines - VCR_HACK_LINES)))
82 continue;
83 while (offset && offset >= sg_dma_len(sg)) {
84 offset -= sg_dma_len(sg);
85 sg++;
86 }
87 if (bpl <= sg_dma_len(sg)-offset) {
88 /* fits into current chunk */
89 *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_SOL|
90 BT848_RISC_EOL|bpl);
91 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
92 offset+=bpl;
93 } else {
94 /* scanline needs to be splitted */
95 todo = bpl;
96 *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_SOL|
97 (sg_dma_len(sg)-offset));
98 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
99 todo -= (sg_dma_len(sg)-offset);
100 offset = 0;
101 sg++;
102 while (todo > sg_dma_len(sg)) {
103 *(rp++)=cpu_to_le32(BT848_RISC_WRITE|
104 sg_dma_len(sg));
105 *(rp++)=cpu_to_le32(sg_dma_address(sg));
106 todo -= sg_dma_len(sg);
107 sg++;
108 }
109 *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_EOL|
110 todo);
111 *(rp++)=cpu_to_le32(sg_dma_address(sg));
112 offset += todo;
113 }
114 offset += padding;
115 }
116
117 /* save pointer to jmp instruction address */
118 risc->jmp = rp;
119 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
120 return 0;
121}
122
123static int
124bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
125 struct scatterlist *sglist,
126 unsigned int yoffset, unsigned int ybpl,
127 unsigned int ypadding, unsigned int ylines,
128 unsigned int uoffset, unsigned int voffset,
129 unsigned int hshift, unsigned int vshift,
130 unsigned int cpadding)
131{
132 unsigned int instructions,line,todo,ylen,chroma;
133 __le32 *rp;
134 u32 ri;
135 struct scatterlist *ysg;
136 struct scatterlist *usg;
137 struct scatterlist *vsg;
138 int topfield = (0 == yoffset);
139 int rc;
140
141 /* estimate risc mem: worst case is one write per page border +
142 one write per scan line (5 dwords)
143 plus sync + jump (2 dwords) */
144 instructions = ((3 + (ybpl + ypadding) * ylines * 2)
145 / PAGE_SIZE) + ylines;
146 instructions += 2;
147 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*4*5)) < 0)
148 return rc;
149
150 /* sync instruction */
151 rp = risc->cpu;
152 *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM3);
153 *(rp++) = cpu_to_le32(0);
154
155 /* scan lines */
156 ysg = sglist;
157 usg = sglist;
158 vsg = sglist;
159 for (line = 0; line < ylines; line++) {
160 if ((btv->opt_vcr_hack) &&
161 (line >= (ylines - VCR_HACK_LINES)))
162 continue;
163 switch (vshift) {
164 case 0:
165 chroma = 1;
166 break;
167 case 1:
168 if (topfield)
169 chroma = ((line & 1) == 0);
170 else
171 chroma = ((line & 1) == 1);
172 break;
173 case 2:
174 if (topfield)
175 chroma = ((line & 3) == 0);
176 else
177 chroma = ((line & 3) == 2);
178 break;
179 default:
180 chroma = 0;
181 break;
182 }
183
184 for (todo = ybpl; todo > 0; todo -= ylen) {
185 /* go to next sg entry if needed */
186 while (yoffset && yoffset >= sg_dma_len(ysg)) {
187 yoffset -= sg_dma_len(ysg);
188 ysg++;
189 }
190 while (uoffset && uoffset >= sg_dma_len(usg)) {
191 uoffset -= sg_dma_len(usg);
192 usg++;
193 }
194 while (voffset && voffset >= sg_dma_len(vsg)) {
195 voffset -= sg_dma_len(vsg);
196 vsg++;
197 }
198
199 /* calculate max number of bytes we can write */
200 ylen = todo;
201 if (yoffset + ylen > sg_dma_len(ysg))
202 ylen = sg_dma_len(ysg) - yoffset;
203 if (chroma) {
204 if (uoffset + (ylen>>hshift) > sg_dma_len(usg))
205 ylen = (sg_dma_len(usg) - uoffset) << hshift;
206 if (voffset + (ylen>>hshift) > sg_dma_len(vsg))
207 ylen = (sg_dma_len(vsg) - voffset) << hshift;
208 ri = BT848_RISC_WRITE123;
209 } else {
210 ri = BT848_RISC_WRITE1S23;
211 }
212 if (ybpl == todo)
213 ri |= BT848_RISC_SOL;
214 if (ylen == todo)
215 ri |= BT848_RISC_EOL;
216
217 /* write risc instruction */
218 *(rp++)=cpu_to_le32(ri | ylen);
219 *(rp++)=cpu_to_le32(((ylen >> hshift) << 16) |
220 (ylen >> hshift));
221 *(rp++)=cpu_to_le32(sg_dma_address(ysg)+yoffset);
222 yoffset += ylen;
223 if (chroma) {
224 *(rp++)=cpu_to_le32(sg_dma_address(usg)+uoffset);
225 uoffset += ylen >> hshift;
226 *(rp++)=cpu_to_le32(sg_dma_address(vsg)+voffset);
227 voffset += ylen >> hshift;
228 }
229 }
230 yoffset += ypadding;
231 if (chroma) {
232 uoffset += cpadding;
233 voffset += cpadding;
234 }
235 }
236
237 /* save pointer to jmp instruction address */
238 risc->jmp = rp;
239 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
240 return 0;
241}
242
243static int
244bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
245 const struct bttv_format *fmt, struct bttv_overlay *ov,
246 int skip_even, int skip_odd)
247{
248 int dwords, rc, line, maxy, start, end;
249 unsigned skip, nskips;
250 struct btcx_skiplist *skips;
251 __le32 *rp;
252 u32 ri,ra;
253 u32 addr;
254
255 /* skip list for window clipping */
256 if (NULL == (skips = kmalloc(sizeof(*skips) * ov->nclips,GFP_KERNEL)))
257 return -ENOMEM;
258
259 /* estimate risc mem: worst case is (1.5*clip+1) * lines instructions
260 + sync + jump (all 2 dwords) */
261 dwords = (3 * ov->nclips + 2) *
262 ((skip_even || skip_odd) ? (ov->w.height+1)>>1 : ov->w.height);
263 dwords += 4;
264 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,dwords*4)) < 0) {
265 kfree(skips);
266 return rc;
267 }
268
269 /* sync instruction */
270 rp = risc->cpu;
271 *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM1);
272 *(rp++) = cpu_to_le32(0);
273
274 addr = (unsigned long)btv->fbuf.base;
275 addr += btv->fbuf.fmt.bytesperline * ov->w.top;
276 addr += (fmt->depth >> 3) * ov->w.left;
277
278 /* scan lines */
279 for (maxy = -1, line = 0; line < ov->w.height;
280 line++, addr += btv->fbuf.fmt.bytesperline) {
281 if ((btv->opt_vcr_hack) &&
282 (line >= (ov->w.height - VCR_HACK_LINES)))
283 continue;
284 if ((line%2) == 0 && skip_even)
285 continue;
286 if ((line%2) == 1 && skip_odd)
287 continue;
288
289 /* calculate clipping */
290 if (line > maxy)
291 btcx_calc_skips(line, ov->w.width, &maxy,
292 skips, &nskips, ov->clips, ov->nclips);
293
294 /* write out risc code */
295 for (start = 0, skip = 0; start < ov->w.width; start = end) {
296 if (skip >= nskips) {
297 ri = BT848_RISC_WRITE;
298 end = ov->w.width;
299 } else if (start < skips[skip].start) {
300 ri = BT848_RISC_WRITE;
301 end = skips[skip].start;
302 } else {
303 ri = BT848_RISC_SKIP;
304 end = skips[skip].end;
305 skip++;
306 }
307 if (BT848_RISC_WRITE == ri)
308 ra = addr + (fmt->depth>>3)*start;
309 else
310 ra = 0;
311
312 if (0 == start)
313 ri |= BT848_RISC_SOL;
314 if (ov->w.width == end)
315 ri |= BT848_RISC_EOL;
316 ri |= (fmt->depth>>3) * (end-start);
317
318 *(rp++)=cpu_to_le32(ri);
319 if (0 != ra)
320 *(rp++)=cpu_to_le32(ra);
321 }
322 }
323
324 /* save pointer to jmp instruction address */
325 risc->jmp = rp;
326 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
327 kfree(skips);
328 return 0;
329}
330
331/* ---------------------------------------------------------- */
332
333static void
334bttv_calc_geo_old(struct bttv *btv, struct bttv_geometry *geo,
335 int width, int height, int interleaved,
336 const struct bttv_tvnorm *tvnorm)
337{
338 u32 xsf, sr;
339 int vdelay;
340
341 int swidth = tvnorm->swidth;
342 int totalwidth = tvnorm->totalwidth;
343 int scaledtwidth = tvnorm->scaledtwidth;
344
345 if (btv->input == btv->dig) {
346 swidth = 720;
347 totalwidth = 858;
348 scaledtwidth = 858;
349 }
350
351 vdelay = tvnorm->vdelay;
352
353 xsf = (width*scaledtwidth)/swidth;
354 geo->hscale = ((totalwidth*4096UL)/xsf-4096);
355 geo->hdelay = tvnorm->hdelayx1;
356 geo->hdelay = (geo->hdelay*width)/swidth;
357 geo->hdelay &= 0x3fe;
358 sr = ((tvnorm->sheight >> (interleaved?0:1))*512)/height - 512;
359 geo->vscale = (0x10000UL-sr) & 0x1fff;
360 geo->crop = ((width>>8)&0x03) | ((geo->hdelay>>6)&0x0c) |
361 ((tvnorm->sheight>>4)&0x30) | ((vdelay>>2)&0xc0);
362 geo->vscale |= interleaved ? (BT848_VSCALE_INT<<8) : 0;
363 geo->vdelay = vdelay;
364 geo->width = width;
365 geo->sheight = tvnorm->sheight;
366 geo->vtotal = tvnorm->vtotal;
367
368 if (btv->opt_combfilter) {
369 geo->vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
370 geo->comb = (width < 769) ? 1 : 0;
371 } else {
372 geo->vtc = 0;
373 geo->comb = 0;
374 }
375}
376
377static void
378bttv_calc_geo (struct bttv * btv,
379 struct bttv_geometry * geo,
380 unsigned int width,
381 unsigned int height,
382 int both_fields,
383 const struct bttv_tvnorm * tvnorm,
384 const struct v4l2_rect * crop)
385{
386 unsigned int c_width;
387 unsigned int c_height;
388 u32 sr;
389
390 if ((crop->left == tvnorm->cropcap.defrect.left
391 && crop->top == tvnorm->cropcap.defrect.top
392 && crop->width == tvnorm->cropcap.defrect.width
393 && crop->height == tvnorm->cropcap.defrect.height
394 && width <= tvnorm->swidth /* see PAL-Nc et al */)
395 || btv->input == btv->dig) {
396 bttv_calc_geo_old(btv, geo, width, height,
397 both_fields, tvnorm);
398 return;
399 }
400
401 /* For bug compatibility the image size checks permit scale
402 factors > 16. See bttv_crop_calc_limits(). */
403 c_width = min((unsigned int) crop->width, width * 16);
404 c_height = min((unsigned int) crop->height, height * 16);
405
406 geo->width = width;
407 geo->hscale = (c_width * 4096U + (width >> 1)) / width - 4096;
408 /* Even to store Cb first, odd for Cr. */
409 geo->hdelay = ((crop->left * width + c_width) / c_width) & ~1;
410
411 geo->sheight = c_height;
412 geo->vdelay = crop->top - tvnorm->cropcap.bounds.top + MIN_VDELAY;
413 sr = c_height >> !both_fields;
414 sr = (sr * 512U + (height >> 1)) / height - 512;
415 geo->vscale = (0x10000UL - sr) & 0x1fff;
416 geo->vscale |= both_fields ? (BT848_VSCALE_INT << 8) : 0;
417 geo->vtotal = tvnorm->vtotal;
418
419 geo->crop = (((geo->width >> 8) & 0x03) |
420 ((geo->hdelay >> 6) & 0x0c) |
421 ((geo->sheight >> 4) & 0x30) |
422 ((geo->vdelay >> 2) & 0xc0));
423
424 if (btv->opt_combfilter) {
425 geo->vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
426 geo->comb = (width < 769) ? 1 : 0;
427 } else {
428 geo->vtc = 0;
429 geo->comb = 0;
430 }
431}
432
433static void
434bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int odd)
435{
436 int off = odd ? 0x80 : 0x00;
437
438 if (geo->comb)
439 btor(BT848_VSCALE_COMB, BT848_E_VSCALE_HI+off);
440 else
441 btand(~BT848_VSCALE_COMB, BT848_E_VSCALE_HI+off);
442
443 btwrite(geo->vtc, BT848_E_VTC+off);
444 btwrite(geo->hscale >> 8, BT848_E_HSCALE_HI+off);
445 btwrite(geo->hscale & 0xff, BT848_E_HSCALE_LO+off);
446 btaor((geo->vscale>>8), 0xe0, BT848_E_VSCALE_HI+off);
447 btwrite(geo->vscale & 0xff, BT848_E_VSCALE_LO+off);
448 btwrite(geo->width & 0xff, BT848_E_HACTIVE_LO+off);
449 btwrite(geo->hdelay & 0xff, BT848_E_HDELAY_LO+off);
450 btwrite(geo->sheight & 0xff, BT848_E_VACTIVE_LO+off);
451 btwrite(geo->vdelay & 0xff, BT848_E_VDELAY_LO+off);
452 btwrite(geo->crop, BT848_E_CROP+off);
453 btwrite(geo->vtotal>>8, BT848_VTOTAL_HI);
454 btwrite(geo->vtotal & 0xff, BT848_VTOTAL_LO);
455}
456
457/* ---------------------------------------------------------- */
458/* risc group / risc main loop / dma management */
459
460void
461bttv_set_dma(struct bttv *btv, int override)
462{
463 unsigned long cmd;
464 int capctl;
465
466 btv->cap_ctl = 0;
467 if (NULL != btv->curr.top) btv->cap_ctl |= 0x02;
468 if (NULL != btv->curr.bottom) btv->cap_ctl |= 0x01;
469 if (NULL != btv->cvbi) btv->cap_ctl |= 0x0c;
470
471 capctl = 0;
472 capctl |= (btv->cap_ctl & 0x03) ? 0x03 : 0x00; /* capture */
473 capctl |= (btv->cap_ctl & 0x0c) ? 0x0c : 0x00; /* vbi data */
474 capctl |= override;
475
476 d2printk(KERN_DEBUG
477 "bttv%d: capctl=%x lirq=%d top=%08Lx/%08Lx even=%08Lx/%08Lx\n",
478 btv->c.nr,capctl,btv->loop_irq,
479 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
480 btv->curr.top ? (unsigned long long)btv->curr.top->top.dma : 0,
481 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0,
482 btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
483
484 cmd = BT848_RISC_JUMP;
485 if (btv->loop_irq) {
486 cmd |= BT848_RISC_IRQ;
487 cmd |= (btv->loop_irq & 0x0f) << 16;
488 cmd |= (~btv->loop_irq & 0x0f) << 20;
489 }
490 if (btv->curr.frame_irq || btv->loop_irq || btv->cvbi) {
491 mod_timer(&btv->timeout, jiffies+BTTV_TIMEOUT);
492 } else {
493 del_timer(&btv->timeout);
494 }
495 btv->main.cpu[RISC_SLOT_LOOP] = cpu_to_le32(cmd);
496
497 btaor(capctl, ~0x0f, BT848_CAP_CTL);
498 if (capctl) {
499 if (btv->dma_on)
500 return;
501 btwrite(btv->main.dma, BT848_RISC_STRT_ADD);
502 btor(3, BT848_GPIO_DMA_CTL);
503 btv->dma_on = 1;
504 } else {
505 if (!btv->dma_on)
506 return;
507 btand(~3, BT848_GPIO_DMA_CTL);
508 btv->dma_on = 0;
509 }
510 return;
511}
512
513int
514bttv_risc_init_main(struct bttv *btv)
515{
516 int rc;
517
518 if ((rc = btcx_riscmem_alloc(btv->c.pci,&btv->main,PAGE_SIZE)) < 0)
519 return rc;
520 dprintk(KERN_DEBUG "bttv%d: risc main @ %08Lx\n",
521 btv->c.nr,(unsigned long long)btv->main.dma);
522
523 btv->main.cpu[0] = cpu_to_le32(BT848_RISC_SYNC | BT848_RISC_RESYNC |
524 BT848_FIFO_STATUS_VRE);
525 btv->main.cpu[1] = cpu_to_le32(0);
526 btv->main.cpu[2] = cpu_to_le32(BT848_RISC_JUMP);
527 btv->main.cpu[3] = cpu_to_le32(btv->main.dma + (4<<2));
528
529 /* top field */
530 btv->main.cpu[4] = cpu_to_le32(BT848_RISC_JUMP);
531 btv->main.cpu[5] = cpu_to_le32(btv->main.dma + (6<<2));
532 btv->main.cpu[6] = cpu_to_le32(BT848_RISC_JUMP);
533 btv->main.cpu[7] = cpu_to_le32(btv->main.dma + (8<<2));
534
535 btv->main.cpu[8] = cpu_to_le32(BT848_RISC_SYNC | BT848_RISC_RESYNC |
536 BT848_FIFO_STATUS_VRO);
537 btv->main.cpu[9] = cpu_to_le32(0);
538
539 /* bottom field */
540 btv->main.cpu[10] = cpu_to_le32(BT848_RISC_JUMP);
541 btv->main.cpu[11] = cpu_to_le32(btv->main.dma + (12<<2));
542 btv->main.cpu[12] = cpu_to_le32(BT848_RISC_JUMP);
543 btv->main.cpu[13] = cpu_to_le32(btv->main.dma + (14<<2));
544
545 /* jump back to top field */
546 btv->main.cpu[14] = cpu_to_le32(BT848_RISC_JUMP);
547 btv->main.cpu[15] = cpu_to_le32(btv->main.dma + (0<<2));
548
549 return 0;
550}
551
552int
553bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
554 int irqflags)
555{
556 unsigned long cmd;
557 unsigned long next = btv->main.dma + ((slot+2) << 2);
558
559 if (NULL == risc) {
560 d2printk(KERN_DEBUG "bttv%d: risc=%p slot[%d]=NULL\n",
561 btv->c.nr,risc,slot);
562 btv->main.cpu[slot+1] = cpu_to_le32(next);
563 } else {
564 d2printk(KERN_DEBUG "bttv%d: risc=%p slot[%d]=%08Lx irq=%d\n",
565 btv->c.nr,risc,slot,(unsigned long long)risc->dma,irqflags);
566 cmd = BT848_RISC_JUMP;
567 if (irqflags) {
568 cmd |= BT848_RISC_IRQ;
569 cmd |= (irqflags & 0x0f) << 16;
570 cmd |= (~irqflags & 0x0f) << 20;
571 }
572 risc->jmp[0] = cpu_to_le32(cmd);
573 risc->jmp[1] = cpu_to_le32(next);
574 btv->main.cpu[slot+1] = cpu_to_le32(risc->dma);
575 }
576 return 0;
577}
578
579void
580bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf)
581{
582 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
583
584 BUG_ON(in_interrupt());
585 videobuf_waiton(q, &buf->vb, 0, 0);
586 videobuf_dma_unmap(q->dev, dma);
587 videobuf_dma_free(dma);
588 btcx_riscmem_free(btv->c.pci,&buf->bottom);
589 btcx_riscmem_free(btv->c.pci,&buf->top);
590 buf->vb.state = VIDEOBUF_NEEDS_INIT;
591}
592
593int
594bttv_buffer_activate_vbi(struct bttv *btv,
595 struct bttv_buffer *vbi)
596{
597 struct btcx_riscmem *top;
598 struct btcx_riscmem *bottom;
599 int top_irq_flags;
600 int bottom_irq_flags;
601
602 top = NULL;
603 bottom = NULL;
604 top_irq_flags = 0;
605 bottom_irq_flags = 0;
606
607 if (vbi) {
608 unsigned int crop, vdelay;
609
610 vbi->vb.state = VIDEOBUF_ACTIVE;
611 list_del(&vbi->vb.queue);
612
613 /* VDELAY is start of video, end of VBI capturing. */
614 crop = btread(BT848_E_CROP);
615 vdelay = btread(BT848_E_VDELAY_LO) + ((crop & 0xc0) << 2);
616
617 if (vbi->geo.vdelay > vdelay) {
618 vdelay = vbi->geo.vdelay & 0xfe;
619 crop = (crop & 0x3f) | ((vbi->geo.vdelay >> 2) & 0xc0);
620
621 btwrite(vdelay, BT848_E_VDELAY_LO);
622 btwrite(crop, BT848_E_CROP);
623 btwrite(vdelay, BT848_O_VDELAY_LO);
624 btwrite(crop, BT848_O_CROP);
625 }
626
627 if (vbi->vbi_count[0] > 0) {
628 top = &vbi->top;
629 top_irq_flags = 4;
630 }
631
632 if (vbi->vbi_count[1] > 0) {
633 top_irq_flags = 0;
634 bottom = &vbi->bottom;
635 bottom_irq_flags = 4;
636 }
637 }
638
639 bttv_risc_hook(btv, RISC_SLOT_O_VBI, top, top_irq_flags);
640 bttv_risc_hook(btv, RISC_SLOT_E_VBI, bottom, bottom_irq_flags);
641
642 return 0;
643}
644
645int
646bttv_buffer_activate_video(struct bttv *btv,
647 struct bttv_buffer_set *set)
648{
649 /* video capture */
650 if (NULL != set->top && NULL != set->bottom) {
651 if (set->top == set->bottom) {
652 set->top->vb.state = VIDEOBUF_ACTIVE;
653 if (set->top->vb.queue.next)
654 list_del(&set->top->vb.queue);
655 } else {
656 set->top->vb.state = VIDEOBUF_ACTIVE;
657 set->bottom->vb.state = VIDEOBUF_ACTIVE;
658 if (set->top->vb.queue.next)
659 list_del(&set->top->vb.queue);
660 if (set->bottom->vb.queue.next)
661 list_del(&set->bottom->vb.queue);
662 }
663 bttv_apply_geo(btv, &set->top->geo, 1);
664 bttv_apply_geo(btv, &set->bottom->geo,0);
665 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, &set->top->top,
666 set->top_irq);
667 bttv_risc_hook(btv, RISC_SLOT_E_FIELD, &set->bottom->bottom,
668 set->frame_irq);
669 btaor((set->top->btformat & 0xf0) | (set->bottom->btformat & 0x0f),
670 ~0xff, BT848_COLOR_FMT);
671 btaor((set->top->btswap & 0x0a) | (set->bottom->btswap & 0x05),
672 ~0x0f, BT848_COLOR_CTL);
673 } else if (NULL != set->top) {
674 set->top->vb.state = VIDEOBUF_ACTIVE;
675 if (set->top->vb.queue.next)
676 list_del(&set->top->vb.queue);
677 bttv_apply_geo(btv, &set->top->geo,1);
678 bttv_apply_geo(btv, &set->top->geo,0);
679 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, &set->top->top,
680 set->frame_irq);
681 bttv_risc_hook(btv, RISC_SLOT_E_FIELD, NULL, 0);
682 btaor(set->top->btformat & 0xff, ~0xff, BT848_COLOR_FMT);
683 btaor(set->top->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL);
684 } else if (NULL != set->bottom) {
685 set->bottom->vb.state = VIDEOBUF_ACTIVE;
686 if (set->bottom->vb.queue.next)
687 list_del(&set->bottom->vb.queue);
688 bttv_apply_geo(btv, &set->bottom->geo,1);
689 bttv_apply_geo(btv, &set->bottom->geo,0);
690 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
691 bttv_risc_hook(btv, RISC_SLOT_E_FIELD, &set->bottom->bottom,
692 set->frame_irq);
693 btaor(set->bottom->btformat & 0xff, ~0xff, BT848_COLOR_FMT);
694 btaor(set->bottom->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL);
695 } else {
696 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
697 bttv_risc_hook(btv, RISC_SLOT_E_FIELD, NULL, 0);
698 }
699 return 0;
700}
701
702/* ---------------------------------------------------------- */
703
704/* calculate geometry, build risc code */
705int
706bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
707{
708 const struct bttv_tvnorm *tvnorm = bttv_tvnorms + buf->tvnorm;
709 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
710
711 dprintk(KERN_DEBUG
712 "bttv%d: buffer field: %s format: %s size: %dx%d\n",
713 btv->c.nr, v4l2_field_names[buf->vb.field],
714 buf->fmt->name, buf->vb.width, buf->vb.height);
715
716 /* packed pixel modes */
717 if (buf->fmt->flags & FORMAT_FLAGS_PACKED) {
718 int bpl = (buf->fmt->depth >> 3) * buf->vb.width;
719 int bpf = bpl * (buf->vb.height >> 1);
720
721 bttv_calc_geo(btv,&buf->geo,buf->vb.width,buf->vb.height,
722 V4L2_FIELD_HAS_BOTH(buf->vb.field),
723 tvnorm,&buf->crop);
724
725 switch (buf->vb.field) {
726 case V4L2_FIELD_TOP:
727 bttv_risc_packed(btv,&buf->top,dma->sglist,
728 /* offset */ 0,bpl,
729 /* padding */ 0,/* skip_lines */ 0,
730 buf->vb.height);
731 break;
732 case V4L2_FIELD_BOTTOM:
733 bttv_risc_packed(btv,&buf->bottom,dma->sglist,
734 0,bpl,0,0,buf->vb.height);
735 break;
736 case V4L2_FIELD_INTERLACED:
737 bttv_risc_packed(btv,&buf->top,dma->sglist,
738 0,bpl,bpl,0,buf->vb.height >> 1);
739 bttv_risc_packed(btv,&buf->bottom,dma->sglist,
740 bpl,bpl,bpl,0,buf->vb.height >> 1);
741 break;
742 case V4L2_FIELD_SEQ_TB:
743 bttv_risc_packed(btv,&buf->top,dma->sglist,
744 0,bpl,0,0,buf->vb.height >> 1);
745 bttv_risc_packed(btv,&buf->bottom,dma->sglist,
746 bpf,bpl,0,0,buf->vb.height >> 1);
747 break;
748 default:
749 BUG();
750 }
751 }
752
753 /* planar modes */
754 if (buf->fmt->flags & FORMAT_FLAGS_PLANAR) {
755 int uoffset, voffset;
756 int ypadding, cpadding, lines;
757
758 /* calculate chroma offsets */
759 uoffset = buf->vb.width * buf->vb.height;
760 voffset = buf->vb.width * buf->vb.height;
761 if (buf->fmt->flags & FORMAT_FLAGS_CrCb) {
762 /* Y-Cr-Cb plane order */
763 uoffset >>= buf->fmt->hshift;
764 uoffset >>= buf->fmt->vshift;
765 uoffset += voffset;
766 } else {
767 /* Y-Cb-Cr plane order */
768 voffset >>= buf->fmt->hshift;
769 voffset >>= buf->fmt->vshift;
770 voffset += uoffset;
771 }
772
773 switch (buf->vb.field) {
774 case V4L2_FIELD_TOP:
775 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
776 buf->vb.height,/* both_fields */ 0,
777 tvnorm,&buf->crop);
778 bttv_risc_planar(btv, &buf->top, dma->sglist,
779 0,buf->vb.width,0,buf->vb.height,
780 uoffset,voffset,buf->fmt->hshift,
781 buf->fmt->vshift,0);
782 break;
783 case V4L2_FIELD_BOTTOM:
784 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
785 buf->vb.height,0,
786 tvnorm,&buf->crop);
787 bttv_risc_planar(btv, &buf->bottom, dma->sglist,
788 0,buf->vb.width,0,buf->vb.height,
789 uoffset,voffset,buf->fmt->hshift,
790 buf->fmt->vshift,0);
791 break;
792 case V4L2_FIELD_INTERLACED:
793 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
794 buf->vb.height,1,
795 tvnorm,&buf->crop);
796 lines = buf->vb.height >> 1;
797 ypadding = buf->vb.width;
798 cpadding = buf->vb.width >> buf->fmt->hshift;
799 bttv_risc_planar(btv,&buf->top,
800 dma->sglist,
801 0,buf->vb.width,ypadding,lines,
802 uoffset,voffset,
803 buf->fmt->hshift,
804 buf->fmt->vshift,
805 cpadding);
806 bttv_risc_planar(btv,&buf->bottom,
807 dma->sglist,
808 ypadding,buf->vb.width,ypadding,lines,
809 uoffset+cpadding,
810 voffset+cpadding,
811 buf->fmt->hshift,
812 buf->fmt->vshift,
813 cpadding);
814 break;
815 case V4L2_FIELD_SEQ_TB:
816 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
817 buf->vb.height,1,
818 tvnorm,&buf->crop);
819 lines = buf->vb.height >> 1;
820 ypadding = buf->vb.width;
821 cpadding = buf->vb.width >> buf->fmt->hshift;
822 bttv_risc_planar(btv,&buf->top,
823 dma->sglist,
824 0,buf->vb.width,0,lines,
825 uoffset >> 1,
826 voffset >> 1,
827 buf->fmt->hshift,
828 buf->fmt->vshift,
829 0);
830 bttv_risc_planar(btv,&buf->bottom,
831 dma->sglist,
832 lines * ypadding,buf->vb.width,0,lines,
833 lines * ypadding + (uoffset >> 1),
834 lines * ypadding + (voffset >> 1),
835 buf->fmt->hshift,
836 buf->fmt->vshift,
837 0);
838 break;
839 default:
840 BUG();
841 }
842 }
843
844 /* raw data */
845 if (buf->fmt->flags & FORMAT_FLAGS_RAW) {
846 /* build risc code */
847 buf->vb.field = V4L2_FIELD_SEQ_TB;
848 bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight,
849 1,tvnorm,&buf->crop);
850 bttv_risc_packed(btv, &buf->top, dma->sglist,
851 /* offset */ 0, RAW_BPL, /* padding */ 0,
852 /* skip_lines */ 0, RAW_LINES);
853 bttv_risc_packed(btv, &buf->bottom, dma->sglist,
854 buf->vb.size/2 , RAW_BPL, 0, 0, RAW_LINES);
855 }
856
857 /* copy format info */
858 buf->btformat = buf->fmt->btformat;
859 buf->btswap = buf->fmt->btswap;
860 return 0;
861}
862
863/* ---------------------------------------------------------- */
864
865/* calculate geometry, build risc code */
866int
867bttv_overlay_risc(struct bttv *btv,
868 struct bttv_overlay *ov,
869 const struct bttv_format *fmt,
870 struct bttv_buffer *buf)
871{
872 /* check interleave, bottom+top fields */
873 dprintk(KERN_DEBUG
874 "bttv%d: overlay fields: %s format: %s size: %dx%d\n",
875 btv->c.nr, v4l2_field_names[buf->vb.field],
876 fmt->name,ov->w.width,ov->w.height);
877
878 /* calculate geometry */
879 bttv_calc_geo(btv,&buf->geo,ov->w.width,ov->w.height,
880 V4L2_FIELD_HAS_BOTH(ov->field),
881 &bttv_tvnorms[ov->tvnorm],&buf->crop);
882
883 /* build risc code */
884 switch (ov->field) {
885 case V4L2_FIELD_TOP:
886 bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 0);
887 break;
888 case V4L2_FIELD_BOTTOM:
889 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 0);
890 break;
891 case V4L2_FIELD_INTERLACED:
892 bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 1);
893 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 1, 0);
894 break;
895 default:
896 BUG();
897 }
898
899 /* copy format info */
900 buf->btformat = fmt->btformat;
901 buf->btswap = fmt->btswap;
902 buf->vb.field = ov->field;
903 return 0;
904}
905
906/*
907 * Local variables:
908 * c-basic-offset: 8
909 * End:
910 */
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
new file mode 100644
index 00000000000..e79a402fa6c
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -0,0 +1,454 @@
1/*
2
3 bttv - Bt848 frame grabber driver
4 vbi interface
5
6 (c) 2002 Gerd Knorr <kraxel@bytesex.org>
7
8 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at>
9 Sponsored by OPQ Systems AB
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
26#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/fs.h>
29#include <linux/kernel.h>
30#include <linux/interrupt.h>
31#include <linux/kdev_t.h>
32#include <media/v4l2-ioctl.h>
33#include <asm/io.h>
34#include "bttvp.h"
35
36/* Offset from line sync pulse leading edge (0H) to start of VBI capture,
37 in fCLKx2 pixels. According to the datasheet, VBI capture starts
38 VBI_HDELAY fCLKx1 pixels from the tailing edgeof /HRESET, and /HRESET
39 is 64 fCLKx1 pixels wide. VBI_HDELAY is set to 0, so this should be
40 (64 + 0) * 2 = 128 fCLKx2 pixels. But it's not! The datasheet is
41 Just Plain Wrong. The real value appears to be different for
42 different revisions of the bt8x8 chips, and to be affected by the
43 horizontal scaling factor. Experimentally, the value is measured
44 to be about 244. */
45#define VBI_OFFSET 244
46
47/* 2048 for compatibility with earlier driver versions. The driver
48 really stores 1024 + tvnorm->vbipack * 4 samples per line in the
49 buffer. Note tvnorm->vbipack is <= 0xFF (limit of VBIPACK_LO + HI
50 is 0x1FF DWORDs) and VBI read()s store a frame counter in the last
51 four bytes of the VBI image. */
52#define VBI_BPL 2048
53
54/* Compatibility. */
55#define VBI_DEFLINES 16
56
57static unsigned int vbibufs = 4;
58static unsigned int vbi_debug;
59
60module_param(vbibufs, int, 0444);
61module_param(vbi_debug, int, 0644);
62MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32, default 4");
63MODULE_PARM_DESC(vbi_debug,"vbi code debug messages, default is 0 (no)");
64
65#ifdef dprintk
66# undef dprintk
67#endif
68#define dprintk(fmt, arg...) if (vbi_debug) \
69 printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg)
70
71#define IMAGE_SIZE(fmt) \
72 (((fmt)->count[0] + (fmt)->count[1]) * (fmt)->samples_per_line)
73
74/* ----------------------------------------------------------------------- */
75/* vbi risc code + mm */
76
77static int vbi_buffer_setup(struct videobuf_queue *q,
78 unsigned int *count, unsigned int *size)
79{
80 struct bttv_fh *fh = q->priv_data;
81 struct bttv *btv = fh->btv;
82
83 if (0 == *count)
84 *count = vbibufs;
85
86 *size = IMAGE_SIZE(&fh->vbi_fmt.fmt);
87
88 dprintk("setup: samples=%u start=%d,%d count=%u,%u\n",
89 fh->vbi_fmt.fmt.samples_per_line,
90 fh->vbi_fmt.fmt.start[0],
91 fh->vbi_fmt.fmt.start[1],
92 fh->vbi_fmt.fmt.count[0],
93 fh->vbi_fmt.fmt.count[1]);
94
95 return 0;
96}
97
98static int vbi_buffer_prepare(struct videobuf_queue *q,
99 struct videobuf_buffer *vb,
100 enum v4l2_field field)
101{
102 struct bttv_fh *fh = q->priv_data;
103 struct bttv *btv = fh->btv;
104 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
105 const struct bttv_tvnorm *tvnorm;
106 unsigned int skip_lines0, skip_lines1, min_vdelay;
107 int redo_dma_risc;
108 int rc;
109
110 buf->vb.size = IMAGE_SIZE(&fh->vbi_fmt.fmt);
111 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
112 return -EINVAL;
113
114 tvnorm = fh->vbi_fmt.tvnorm;
115
116 /* There's no VBI_VDELAY register, RISC must skip the lines
117 we don't want. With default parameters we skip zero lines
118 as earlier driver versions did. The driver permits video
119 standard changes while capturing, so we use vbi_fmt.tvnorm
120 instead of btv->tvnorm to skip zero lines after video
121 standard changes as well. */
122
123 skip_lines0 = 0;
124 skip_lines1 = 0;
125
126 if (fh->vbi_fmt.fmt.count[0] > 0)
127 skip_lines0 = max(0, (fh->vbi_fmt.fmt.start[0]
128 - tvnorm->vbistart[0]));
129 if (fh->vbi_fmt.fmt.count[1] > 0)
130 skip_lines1 = max(0, (fh->vbi_fmt.fmt.start[1]
131 - tvnorm->vbistart[1]));
132
133 redo_dma_risc = 0;
134
135 if (buf->vbi_skip[0] != skip_lines0 ||
136 buf->vbi_skip[1] != skip_lines1 ||
137 buf->vbi_count[0] != fh->vbi_fmt.fmt.count[0] ||
138 buf->vbi_count[1] != fh->vbi_fmt.fmt.count[1]) {
139 buf->vbi_skip[0] = skip_lines0;
140 buf->vbi_skip[1] = skip_lines1;
141 buf->vbi_count[0] = fh->vbi_fmt.fmt.count[0];
142 buf->vbi_count[1] = fh->vbi_fmt.fmt.count[1];
143 redo_dma_risc = 1;
144 }
145
146 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
147 redo_dma_risc = 1;
148 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL)))
149 goto fail;
150 }
151
152 if (redo_dma_risc) {
153 unsigned int bpl, padding, offset;
154 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
155
156 bpl = 2044; /* max. vbipack */
157 padding = VBI_BPL - bpl;
158
159 if (fh->vbi_fmt.fmt.count[0] > 0) {
160 rc = bttv_risc_packed(btv, &buf->top,
161 dma->sglist,
162 /* offset */ 0, bpl,
163 padding, skip_lines0,
164 fh->vbi_fmt.fmt.count[0]);
165 if (0 != rc)
166 goto fail;
167 }
168
169 if (fh->vbi_fmt.fmt.count[1] > 0) {
170 offset = fh->vbi_fmt.fmt.count[0] * VBI_BPL;
171
172 rc = bttv_risc_packed(btv, &buf->bottom,
173 dma->sglist,
174 offset, bpl,
175 padding, skip_lines1,
176 fh->vbi_fmt.fmt.count[1]);
177 if (0 != rc)
178 goto fail;
179 }
180 }
181
182 /* VBI capturing ends at VDELAY, start of video capturing,
183 no matter where the RISC program ends. VDELAY minimum is 2,
184 bounds.top is the corresponding first field line number
185 times two. VDELAY counts half field lines. */
186 min_vdelay = MIN_VDELAY;
187 if (fh->vbi_fmt.end >= tvnorm->cropcap.bounds.top)
188 min_vdelay += fh->vbi_fmt.end - tvnorm->cropcap.bounds.top;
189
190 /* For bttv_buffer_activate_vbi(). */
191 buf->geo.vdelay = min_vdelay;
192
193 buf->vb.state = VIDEOBUF_PREPARED;
194 buf->vb.field = field;
195 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
196 vb, &buf->top, &buf->bottom,
197 v4l2_field_names[buf->vb.field]);
198 return 0;
199
200 fail:
201 bttv_dma_free(q,btv,buf);
202 return rc;
203}
204
205static void
206vbi_buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
207{
208 struct bttv_fh *fh = q->priv_data;
209 struct bttv *btv = fh->btv;
210 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
211
212 dprintk("queue %p\n",vb);
213 buf->vb.state = VIDEOBUF_QUEUED;
214 list_add_tail(&buf->vb.queue,&btv->vcapture);
215 if (NULL == btv->cvbi) {
216 fh->btv->loop_irq |= 4;
217 bttv_set_dma(btv,0x0c);
218 }
219}
220
221static void vbi_buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
222{
223 struct bttv_fh *fh = q->priv_data;
224 struct bttv *btv = fh->btv;
225 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
226
227 dprintk("free %p\n",vb);
228 bttv_dma_free(q,fh->btv,buf);
229}
230
231struct videobuf_queue_ops bttv_vbi_qops = {
232 .buf_setup = vbi_buffer_setup,
233 .buf_prepare = vbi_buffer_prepare,
234 .buf_queue = vbi_buffer_queue,
235 .buf_release = vbi_buffer_release,
236};
237
238/* ----------------------------------------------------------------------- */
239
240static int try_fmt(struct v4l2_vbi_format *f, const struct bttv_tvnorm *tvnorm,
241 __s32 crop_start)
242{
243 __s32 min_start, max_start, max_end, f2_offset;
244 unsigned int i;
245
246 /* For compatibility with earlier driver versions we must pretend
247 the VBI and video capture window may overlap. In reality RISC
248 magic aborts VBI capturing at the first line of video capturing,
249 leaving the rest of the buffer unchanged, usually all zero.
250 VBI capturing must always start before video capturing. >> 1
251 because cropping counts field lines times two. */
252 min_start = tvnorm->vbistart[0];
253 max_start = (crop_start >> 1) - 1;
254 max_end = (tvnorm->cropcap.bounds.top
255 + tvnorm->cropcap.bounds.height) >> 1;
256
257 if (min_start > max_start)
258 return -EBUSY;
259
260 BUG_ON(max_start >= max_end);
261
262 f->sampling_rate = tvnorm->Fsc;
263 f->samples_per_line = VBI_BPL;
264 f->sample_format = V4L2_PIX_FMT_GREY;
265 f->offset = VBI_OFFSET;
266
267 f2_offset = tvnorm->vbistart[1] - tvnorm->vbistart[0];
268
269 for (i = 0; i < 2; ++i) {
270 if (0 == f->count[i]) {
271 /* No data from this field. We leave f->start[i]
272 alone because VIDIOCSVBIFMT is w/o and EINVALs
273 when a driver does not support exactly the
274 requested parameters. */
275 } else {
276 s64 start, count;
277
278 start = clamp(f->start[i], min_start, max_start);
279 /* s64 to prevent overflow. */
280 count = (s64) f->start[i] + f->count[i] - start;
281 f->start[i] = start;
282 f->count[i] = clamp(count, (s64) 1,
283 max_end - start);
284 }
285
286 min_start += f2_offset;
287 max_start += f2_offset;
288 max_end += f2_offset;
289 }
290
291 if (0 == (f->count[0] | f->count[1])) {
292 /* As in earlier driver versions. */
293 f->start[0] = tvnorm->vbistart[0];
294 f->start[1] = tvnorm->vbistart[1];
295 f->count[0] = 1;
296 f->count[1] = 1;
297 }
298
299 f->flags = 0;
300
301 f->reserved[0] = 0;
302 f->reserved[1] = 0;
303
304 return 0;
305}
306
307int bttv_try_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt)
308{
309 struct bttv_fh *fh = f;
310 struct bttv *btv = fh->btv;
311 const struct bttv_tvnorm *tvnorm;
312 __s32 crop_start;
313
314 mutex_lock(&btv->lock);
315
316 tvnorm = &bttv_tvnorms[btv->tvnorm];
317 crop_start = btv->crop_start;
318
319 mutex_unlock(&btv->lock);
320
321 return try_fmt(&frt->fmt.vbi, tvnorm, crop_start);
322}
323
324
325int bttv_s_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt)
326{
327 struct bttv_fh *fh = f;
328 struct bttv *btv = fh->btv;
329 const struct bttv_tvnorm *tvnorm;
330 __s32 start1, end;
331 int rc;
332
333 mutex_lock(&btv->lock);
334
335 rc = -EBUSY;
336 if (fh->resources & RESOURCE_VBI)
337 goto fail;
338
339 tvnorm = &bttv_tvnorms[btv->tvnorm];
340
341 rc = try_fmt(&frt->fmt.vbi, tvnorm, btv->crop_start);
342 if (0 != rc)
343 goto fail;
344
345 start1 = frt->fmt.vbi.start[1] - tvnorm->vbistart[1] +
346 tvnorm->vbistart[0];
347
348 /* First possible line of video capturing. Should be
349 max(f->start[0] + f->count[0], start1 + f->count[1]) * 2
350 when capturing both fields. But for compatibility we must
351 pretend the VBI and video capture window may overlap,
352 so end = start + 1, the lowest possible value, times two
353 because vbi_fmt.end counts field lines times two. */
354 end = max(frt->fmt.vbi.start[0], start1) * 2 + 2;
355
356 mutex_lock(&fh->vbi.vb_lock);
357
358 fh->vbi_fmt.fmt = frt->fmt.vbi;
359 fh->vbi_fmt.tvnorm = tvnorm;
360 fh->vbi_fmt.end = end;
361
362 mutex_unlock(&fh->vbi.vb_lock);
363
364 rc = 0;
365
366 fail:
367 mutex_unlock(&btv->lock);
368
369 return rc;
370}
371
372
373int bttv_g_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt)
374{
375 struct bttv_fh *fh = f;
376 const struct bttv_tvnorm *tvnorm;
377
378 frt->fmt.vbi = fh->vbi_fmt.fmt;
379
380 tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
381
382 if (tvnorm != fh->vbi_fmt.tvnorm) {
383 __s32 max_end;
384 unsigned int i;
385
386 /* As in vbi_buffer_prepare() this imitates the
387 behaviour of earlier driver versions after video
388 standard changes, with default parameters anyway. */
389
390 max_end = (tvnorm->cropcap.bounds.top
391 + tvnorm->cropcap.bounds.height) >> 1;
392
393 frt->fmt.vbi.sampling_rate = tvnorm->Fsc;
394
395 for (i = 0; i < 2; ++i) {
396 __s32 new_start;
397
398 new_start = frt->fmt.vbi.start[i]
399 + tvnorm->vbistart[i]
400 - fh->vbi_fmt.tvnorm->vbistart[i];
401
402 frt->fmt.vbi.start[i] = min(new_start, max_end - 1);
403 frt->fmt.vbi.count[i] =
404 min((__s32) frt->fmt.vbi.count[i],
405 max_end - frt->fmt.vbi.start[i]);
406
407 max_end += tvnorm->vbistart[1]
408 - tvnorm->vbistart[0];
409 }
410 }
411 return 0;
412}
413
414void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm)
415{
416 const struct bttv_tvnorm *tvnorm;
417 unsigned int real_samples_per_line;
418 unsigned int real_count;
419
420 tvnorm = &bttv_tvnorms[norm];
421
422 f->fmt.sampling_rate = tvnorm->Fsc;
423 f->fmt.samples_per_line = VBI_BPL;
424 f->fmt.sample_format = V4L2_PIX_FMT_GREY;
425 f->fmt.offset = VBI_OFFSET;
426 f->fmt.start[0] = tvnorm->vbistart[0];
427 f->fmt.start[1] = tvnorm->vbistart[1];
428 f->fmt.count[0] = VBI_DEFLINES;
429 f->fmt.count[1] = VBI_DEFLINES;
430 f->fmt.flags = 0;
431 f->fmt.reserved[0] = 0;
432 f->fmt.reserved[1] = 0;
433
434 /* For compatibility the buffer size must be 2 * VBI_DEFLINES *
435 VBI_BPL regardless of the current video standard. */
436 real_samples_per_line = 1024 + tvnorm->vbipack * 4;
437 real_count = ((tvnorm->cropcap.defrect.top >> 1)
438 - tvnorm->vbistart[0]);
439
440 BUG_ON(real_samples_per_line > VBI_BPL);
441 BUG_ON(real_count > VBI_DEFLINES);
442
443 f->tvnorm = tvnorm;
444
445 /* See bttv_vbi_fmt_set(). */
446 f->end = tvnorm->vbistart[0] * 2 + 2;
447}
448
449/* ----------------------------------------------------------------------- */
450/*
451 * Local variables:
452 * c-basic-offset: 8
453 * End:
454 */
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
new file mode 100644
index 00000000000..c6333595c6b
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -0,0 +1,376 @@
1/*
2 *
3 * bttv - Bt848 frame grabber driver
4 *
5 * card ID's and external interfaces of the bttv driver
6 * basically stuff needed by other drivers (i2c, lirc, ...)
7 * and is supported not to change much over time.
8 *
9 * Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de)
10 * (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
11 *
12 */
13
14#ifndef _BTTV_H_
15#define _BTTV_H_
16
17#include <linux/videodev2.h>
18#include <linux/i2c.h>
19#include <media/v4l2-device.h>
20#include <media/i2c-addr.h>
21#include <media/tuner.h>
22
23/* ---------------------------------------------------------- */
24/* exported by bttv-cards.c */
25
26#define BTTV_BOARD_UNKNOWN 0x00
27#define BTTV_BOARD_MIRO 0x01
28#define BTTV_BOARD_HAUPPAUGE 0x02
29#define BTTV_BOARD_STB 0x03
30#define BTTV_BOARD_INTEL 0x04
31#define BTTV_BOARD_DIAMOND 0x05
32#define BTTV_BOARD_AVERMEDIA 0x06
33#define BTTV_BOARD_MATRIX_VISION 0x07
34#define BTTV_BOARD_FLYVIDEO 0x08
35#define BTTV_BOARD_TURBOTV 0x09
36#define BTTV_BOARD_HAUPPAUGE878 0x0a
37#define BTTV_BOARD_MIROPRO 0x0b
38#define BTTV_BOARD_ADSTECH_TV 0x0c
39#define BTTV_BOARD_AVERMEDIA98 0x0d
40#define BTTV_BOARD_VHX 0x0e
41#define BTTV_BOARD_ZOLTRIX 0x0f
42#define BTTV_BOARD_PIXVIEWPLAYTV 0x10
43#define BTTV_BOARD_WINVIEW_601 0x11
44#define BTTV_BOARD_AVEC_INTERCAP 0x12
45#define BTTV_BOARD_LIFE_FLYKIT 0x13
46#define BTTV_BOARD_CEI_RAFFLES 0x14
47#define BTTV_BOARD_CONFERENCETV 0x15
48#define BTTV_BOARD_PHOEBE_TVMAS 0x16
49#define BTTV_BOARD_MODTEC_205 0x17
50#define BTTV_BOARD_MAGICTVIEW061 0x18
51#define BTTV_BOARD_VOBIS_BOOSTAR 0x19
52#define BTTV_BOARD_HAUPPAUG_WCAM 0x1a
53#define BTTV_BOARD_MAXI 0x1b
54#define BTTV_BOARD_TERRATV 0x1c
55#define BTTV_BOARD_PXC200 0x1d
56#define BTTV_BOARD_FLYVIDEO_98 0x1e
57#define BTTV_BOARD_IPROTV 0x1f
58#define BTTV_BOARD_INTEL_C_S_PCI 0x20
59#define BTTV_BOARD_TERRATVALUE 0x21
60#define BTTV_BOARD_WINFAST2000 0x22
61#define BTTV_BOARD_CHRONOS_VS2 0x23
62#define BTTV_BOARD_TYPHOON_TVIEW 0x24
63#define BTTV_BOARD_PXELVWPLTVPRO 0x25
64#define BTTV_BOARD_MAGICTVIEW063 0x26
65#define BTTV_BOARD_PINNACLE 0x27
66#define BTTV_BOARD_STB2 0x28
67#define BTTV_BOARD_AVPHONE98 0x29
68#define BTTV_BOARD_PV951 0x2a
69#define BTTV_BOARD_ONAIR_TV 0x2b
70#define BTTV_BOARD_SIGMA_TVII_FM 0x2c
71#define BTTV_BOARD_MATRIX_VISION2 0x2d
72#define BTTV_BOARD_ZOLTRIX_GENIE 0x2e
73#define BTTV_BOARD_TERRATVRADIO 0x2f
74#define BTTV_BOARD_DYNALINK 0x30
75#define BTTV_BOARD_GVBCTV3PCI 0x31
76#define BTTV_BOARD_PXELVWPLTVPAK 0x32
77#define BTTV_BOARD_EAGLE 0x33
78#define BTTV_BOARD_PINNACLEPRO 0x34
79#define BTTV_BOARD_TVIEW_RDS_FM 0x35
80#define BTTV_BOARD_LIFETEC_9415 0x36
81#define BTTV_BOARD_BESTBUY_EASYTV 0x37
82#define BTTV_BOARD_FLYVIDEO_98FM 0x38
83#define BTTV_BOARD_GRANDTEC 0x39
84#define BTTV_BOARD_ASKEY_CPH060 0x3a
85#define BTTV_BOARD_ASKEY_CPH03X 0x3b
86#define BTTV_BOARD_MM100PCTV 0x3c
87#define BTTV_BOARD_GMV1 0x3d
88#define BTTV_BOARD_BESTBUY_EASYTV2 0x3e
89#define BTTV_BOARD_ATI_TVWONDER 0x3f
90#define BTTV_BOARD_ATI_TVWONDERVE 0x40
91#define BTTV_BOARD_FLYVIDEO2000 0x41
92#define BTTV_BOARD_TERRATVALUER 0x42
93#define BTTV_BOARD_GVBCTV4PCI 0x43
94#define BTTV_BOARD_VOODOOTV_FM 0x44
95#define BTTV_BOARD_AIMMS 0x45
96#define BTTV_BOARD_PV_BT878P_PLUS 0x46
97#define BTTV_BOARD_FLYVIDEO98EZ 0x47
98#define BTTV_BOARD_PV_BT878P_9B 0x48
99#define BTTV_BOARD_SENSORAY311 0x49
100#define BTTV_BOARD_RV605 0x4a
101#define BTTV_BOARD_POWERCLR_MTV878 0x4b
102#define BTTV_BOARD_WINDVR 0x4c
103#define BTTV_BOARD_GRANDTEC_MULTI 0x4d
104#define BTTV_BOARD_KWORLD 0x4e
105#define BTTV_BOARD_DSP_TCVIDEO 0x4f
106#define BTTV_BOARD_HAUPPAUGEPVR 0x50
107#define BTTV_BOARD_GVBCTV5PCI 0x51
108#define BTTV_BOARD_OSPREY1x0 0x52
109#define BTTV_BOARD_OSPREY1x0_848 0x53
110#define BTTV_BOARD_OSPREY101_848 0x54
111#define BTTV_BOARD_OSPREY1x1 0x55
112#define BTTV_BOARD_OSPREY1x1_SVID 0x56
113#define BTTV_BOARD_OSPREY2xx 0x57
114#define BTTV_BOARD_OSPREY2x0_SVID 0x58
115#define BTTV_BOARD_OSPREY2x0 0x59
116#define BTTV_BOARD_OSPREY500 0x5a
117#define BTTV_BOARD_OSPREY540 0x5b
118#define BTTV_BOARD_OSPREY2000 0x5c
119#define BTTV_BOARD_IDS_EAGLE 0x5d
120#define BTTV_BOARD_PINNACLESAT 0x5e
121#define BTTV_BOARD_FORMAC_PROTV 0x5f
122#define BTTV_BOARD_MACHTV 0x60
123#define BTTV_BOARD_EURESYS_PICOLO 0x61
124#define BTTV_BOARD_PV150 0x62
125#define BTTV_BOARD_AD_TVK503 0x63
126#define BTTV_BOARD_HERCULES_SM_TV 0x64
127#define BTTV_BOARD_PACETV 0x65
128#define BTTV_BOARD_IVC200 0x66
129#define BTTV_BOARD_XGUARD 0x67
130#define BTTV_BOARD_NEBULA_DIGITV 0x68
131#define BTTV_BOARD_PV143 0x69
132#define BTTV_BOARD_VD009X1_VD011_MINIDIN 0x6a
133#define BTTV_BOARD_VD009X1_VD011_COMBI 0x6b
134#define BTTV_BOARD_VD009_MINIDIN 0x6c
135#define BTTV_BOARD_VD009_COMBI 0x6d
136#define BTTV_BOARD_IVC100 0x6e
137#define BTTV_BOARD_IVC120 0x6f
138#define BTTV_BOARD_PC_HDTV 0x70
139#define BTTV_BOARD_TWINHAN_DST 0x71
140#define BTTV_BOARD_WINFASTVC100 0x72
141#define BTTV_BOARD_TEV560 0x73
142#define BTTV_BOARD_SIMUS_GVC1100 0x74
143#define BTTV_BOARD_NGSTV_PLUS 0x75
144#define BTTV_BOARD_LMLBT4 0x76
145#define BTTV_BOARD_TEKRAM_M205 0x77
146#define BTTV_BOARD_CONTVFMI 0x78
147#define BTTV_BOARD_PICOLO_TETRA_CHIP 0x79
148#define BTTV_BOARD_SPIRIT_TV 0x7a
149#define BTTV_BOARD_AVDVBT_771 0x7b
150#define BTTV_BOARD_AVDVBT_761 0x7c
151#define BTTV_BOARD_MATRIX_VISIONSQ 0x7d
152#define BTTV_BOARD_MATRIX_VISIONSLC 0x7e
153#define BTTV_BOARD_APAC_VIEWCOMP 0x7f
154#define BTTV_BOARD_DVICO_DVBT_LITE 0x80
155#define BTTV_BOARD_VGEAR_MYVCD 0x81
156#define BTTV_BOARD_SUPER_TV 0x82
157#define BTTV_BOARD_TIBET_CS16 0x83
158#define BTTV_BOARD_KODICOM_4400R 0x84
159#define BTTV_BOARD_KODICOM_4400R_SL 0x85
160#define BTTV_BOARD_ADLINK_RTV24 0x86
161#define BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE 0x87
162#define BTTV_BOARD_ACORP_Y878F 0x88
163#define BTTV_BOARD_CONCEPTRONIC_CTVFMI2 0x89
164#define BTTV_BOARD_PV_BT878P_2E 0x8a
165#define BTTV_BOARD_PV_M4900 0x8b
166#define BTTV_BOARD_OSPREY440 0x8c
167#define BTTV_BOARD_ASOUND_SKYEYE 0x8d
168#define BTTV_BOARD_SABRENT_TVFM 0x8e
169#define BTTV_BOARD_HAUPPAUGE_IMPACTVCB 0x8f
170#define BTTV_BOARD_MACHTV_MAGICTV 0x90
171#define BTTV_BOARD_SSAI_SECURITY 0x91
172#define BTTV_BOARD_SSAI_ULTRASOUND 0x92
173#define BTTV_BOARD_VOODOOTV_200 0x93
174#define BTTV_BOARD_DVICO_FUSIONHDTV_2 0x94
175#define BTTV_BOARD_TYPHOON_TVTUNERPCI 0x95
176#define BTTV_BOARD_GEOVISION_GV600 0x96
177#define BTTV_BOARD_KOZUMI_KTV_01C 0x97
178#define BTTV_BOARD_ENLTV_FM_2 0x98
179#define BTTV_BOARD_VD012 0x99
180#define BTTV_BOARD_VD012_X1 0x9a
181#define BTTV_BOARD_VD012_X2 0x9b
182#define BTTV_BOARD_IVCE8784 0x9c
183#define BTTV_BOARD_GEOVISION_GV800S 0x9d
184#define BTTV_BOARD_GEOVISION_GV800S_SL 0x9e
185#define BTTV_BOARD_PV183 0x9f
186
187
188/* more card-specific defines */
189#define PT2254_L_CHANNEL 0x10
190#define PT2254_R_CHANNEL 0x08
191#define PT2254_DBS_IN_2 0x400
192#define PT2254_DBS_IN_10 0x20000
193#define WINVIEW_PT2254_CLK 0x40
194#define WINVIEW_PT2254_DATA 0x20
195#define WINVIEW_PT2254_STROBE 0x80
196
197struct bttv_core {
198 /* device structs */
199 struct v4l2_device v4l2_dev;
200 struct pci_dev *pci;
201 struct i2c_adapter i2c_adap;
202 struct list_head subs; /* struct bttv_sub_device */
203
204 /* device config */
205 unsigned int nr; /* dev nr (for printk("bttv%d: ..."); */
206 unsigned int type; /* card type (pointer into tvcards[]) */
207};
208
209struct bttv;
210
211struct tvcard {
212 char *name;
213 void (*volume_gpio)(struct bttv *btv, __u16 volume);
214 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
215 void (*muxsel_hook)(struct bttv *btv, unsigned int input);
216
217 /* MUX bits for each input, two bits per input starting with the LSB */
218 u32 muxsel; /* Use MUXSEL() to set */
219
220 u32 gpiomask;
221 u32 gpiomux[4]; /* Tuner, Radio, external, internal */
222 u32 gpiomute; /* GPIO mute setting */
223 u32 gpiomask2; /* GPIO MUX mask */
224
225 unsigned int tuner_type;
226 u8 tuner_addr;
227 u8 video_inputs; /* Number of inputs */
228 unsigned int svhs:4; /* Which input is s-video */
229#define NO_SVHS 15
230 unsigned int pll:2;
231#define PLL_NONE 0
232#define PLL_28 1
233#define PLL_35 2
234
235 /* i2c audio flags */
236 unsigned int no_msp34xx:1;
237 unsigned int no_tda7432:1;
238 unsigned int needs_tvaudio:1;
239 unsigned int msp34xx_alt:1;
240 /* Note: currently no card definition needs to mark the presence
241 of a RDS saa6588 chip. If this is ever needed, then add a new
242 'has_saa6588' bit here. */
243
244 unsigned int no_video:1; /* video pci function is unused */
245 unsigned int has_dvb:1;
246 unsigned int has_remote:1;
247 unsigned int has_radio:1;
248 unsigned int has_dig_in:1; /* Has digital input (always last input) */
249 unsigned int no_gpioirq:1;
250};
251
252extern struct tvcard bttv_tvcards[];
253
254/*
255 * This bit of cpp voodoo is used to create a macro with a variable number of
256 * arguments (1 to 16). It will pack each argument into a word two bits at a
257 * time. It can't be a function because it needs to be compile time constant to
258 * initialize structures. Since each argument must fit in two bits, it's ok
259 * that they are changed to octal. One should not use hex number, macros, or
260 * anything else with this macro. Just use plain integers from 0 to 3.
261 */
262#define _MUXSELf(a) 0##a << 30
263#define _MUXSELe(a, b...) 0##a << 28 | _MUXSELf(b)
264#define _MUXSELd(a, b...) 0##a << 26 | _MUXSELe(b)
265#define _MUXSELc(a, b...) 0##a << 24 | _MUXSELd(b)
266#define _MUXSELb(a, b...) 0##a << 22 | _MUXSELc(b)
267#define _MUXSELa(a, b...) 0##a << 20 | _MUXSELb(b)
268#define _MUXSEL9(a, b...) 0##a << 18 | _MUXSELa(b)
269#define _MUXSEL8(a, b...) 0##a << 16 | _MUXSEL9(b)
270#define _MUXSEL7(a, b...) 0##a << 14 | _MUXSEL8(b)
271#define _MUXSEL6(a, b...) 0##a << 12 | _MUXSEL7(b)
272#define _MUXSEL5(a, b...) 0##a << 10 | _MUXSEL6(b)
273#define _MUXSEL4(a, b...) 0##a << 8 | _MUXSEL5(b)
274#define _MUXSEL3(a, b...) 0##a << 6 | _MUXSEL4(b)
275#define _MUXSEL2(a, b...) 0##a << 4 | _MUXSEL3(b)
276#define _MUXSEL1(a, b...) 0##a << 2 | _MUXSEL2(b)
277#define MUXSEL(a, b...) (a | _MUXSEL1(b))
278
279/* identification / initialization of the card */
280extern void bttv_idcard(struct bttv *btv);
281extern void bttv_init_card1(struct bttv *btv);
282extern void bttv_init_card2(struct bttv *btv);
283extern void bttv_init_tuner(struct bttv *btv);
284
285/* card-specific funtions */
286extern void tea5757_set_freq(struct bttv *btv, unsigned short freq);
287extern u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits);
288
289/* extra tweaks for some chipsets */
290extern void bttv_check_chipset(void);
291extern int bttv_handle_chipset(struct bttv *btv);
292
293/* ---------------------------------------------------------- */
294/* exported by bttv-if.c */
295
296/* this obsolete -- please use the sysfs-based
297 interface below for new code */
298
299extern struct pci_dev* bttv_get_pcidev(unsigned int card);
300
301/* sets GPOE register (BT848_GPIO_OUT_EN) to new value:
302 data | (current_GPOE_value & ~mask)
303 returns negative value if error occurred
304*/
305extern int bttv_gpio_enable(unsigned int card,
306 unsigned long mask, unsigned long data);
307
308/* fills data with GPDATA register contents
309 returns negative value if error occurred
310*/
311extern int bttv_read_gpio(unsigned int card, unsigned long *data);
312
313/* sets GPDATA register to new value:
314 (data & mask) | (current_GPDATA_value & ~mask)
315 returns negative value if error occurred
316*/
317extern int bttv_write_gpio(unsigned int card,
318 unsigned long mask, unsigned long data);
319
320
321
322
323/* ---------------------------------------------------------- */
324/* sysfs/driver-moded based gpio access interface */
325
326struct bttv_sub_device {
327 struct device dev;
328 struct bttv_core *core;
329 struct list_head list;
330};
331#define to_bttv_sub_dev(x) container_of((x), struct bttv_sub_device, dev)
332
333struct bttv_sub_driver {
334 struct device_driver drv;
335 char wanted[20];
336 int (*probe)(struct bttv_sub_device *sub);
337 void (*remove)(struct bttv_sub_device *sub);
338};
339#define to_bttv_sub_drv(x) container_of((x), struct bttv_sub_driver, drv)
340
341int bttv_sub_register(struct bttv_sub_driver *drv, char *wanted);
342int bttv_sub_unregister(struct bttv_sub_driver *drv);
343
344/* gpio access functions */
345void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits);
346u32 bttv_gpio_read(struct bttv_core *core);
347void bttv_gpio_write(struct bttv_core *core, u32 value);
348void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits);
349
350#define gpio_inout(mask,bits) bttv_gpio_inout(&btv->c, mask, bits)
351#define gpio_read() bttv_gpio_read(&btv->c)
352#define gpio_write(value) bttv_gpio_write(&btv->c, value)
353#define gpio_bits(mask,bits) bttv_gpio_bits(&btv->c, mask, bits)
354
355
356/* ---------------------------------------------------------- */
357/* i2c */
358
359#define bttv_call_all(btv, o, f, args...) \
360 v4l2_device_call_all(&btv->c.v4l2_dev, 0, o, f, ##args)
361
362extern int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for);
363extern int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
364 unsigned char b2, int both);
365extern void bttv_readee(struct bttv *btv, unsigned char *eedata, int addr);
366
367extern int bttv_input_init(struct bttv *dev);
368extern void bttv_input_fini(struct bttv *dev);
369extern void bttv_input_irq(struct bttv *dev);
370
371#endif /* _BTTV_H_ */
372/*
373 * Local variables:
374 * c-basic-offset: 8
375 * End:
376 */
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
new file mode 100644
index 00000000000..318edf2830b
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -0,0 +1,522 @@
1/*
2
3 bttv - Bt848 frame grabber driver
4
5 bttv's *private* header file -- nobody other than bttv itself
6 should ever include this file.
7
8 (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
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/types.h>
29#include <linux/wait.h>
30#include <linux/i2c.h>
31#include <linux/i2c-algo-bit.h>
32#include <linux/pci.h>
33#include <linux/input.h>
34#include <linux/mutex.h>
35#include <linux/scatterlist.h>
36#include <asm/io.h>
37#include <media/v4l2-common.h>
38#include <linux/device.h>
39#include <media/videobuf-dma-sg.h>
40#include <media/tveeprom.h>
41#include <media/rc-core.h>
42#include <media/ir-kbd-i2c.h>
43
44#include "bt848.h"
45#include "bttv.h"
46#include "btcx-risc.h"
47
48#ifdef __KERNEL__
49
50#define FORMAT_FLAGS_DITHER 0x01
51#define FORMAT_FLAGS_PACKED 0x02
52#define FORMAT_FLAGS_PLANAR 0x04
53#define FORMAT_FLAGS_RAW 0x08
54#define FORMAT_FLAGS_CrCb 0x10
55
56#define RISC_SLOT_O_VBI 4
57#define RISC_SLOT_O_FIELD 6
58#define RISC_SLOT_E_VBI 10
59#define RISC_SLOT_E_FIELD 12
60#define RISC_SLOT_LOOP 14
61
62#define RESOURCE_OVERLAY 1
63#define RESOURCE_VIDEO_STREAM 2
64#define RESOURCE_VBI 4
65#define RESOURCE_VIDEO_READ 8
66
67#define RAW_LINES 640
68#define RAW_BPL 1024
69
70#define UNSET (-1U)
71
72/* Min. value in VDELAY register. */
73#define MIN_VDELAY 2
74/* Even to get Cb first, odd for Cr. */
75#define MAX_HDELAY (0x3FF & -2)
76/* Limits scaled width, which must be a multiple of 4. */
77#define MAX_HACTIVE (0x3FF & -4)
78
79#define BTTV_NORMS (\
80 V4L2_STD_PAL | V4L2_STD_PAL_N | \
81 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
82 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
83 V4L2_STD_PAL_60)
84/* ---------------------------------------------------------- */
85
86struct bttv_tvnorm {
87 int v4l2_id;
88 char *name;
89 u32 Fsc;
90 u16 swidth, sheight; /* scaled standard width, height */
91 u16 totalwidth;
92 u8 adelay, bdelay, iform;
93 u32 scaledtwidth;
94 u16 hdelayx1, hactivex1;
95 u16 vdelay;
96 u8 vbipack;
97 u16 vtotal;
98 int sram;
99 /* ITU-R frame line number of the first VBI line we can
100 capture, of the first and second field. The last possible line
101 is determined by cropcap.bounds. */
102 u16 vbistart[2];
103 /* Horizontally this counts fCLKx1 samples following the leading
104 edge of the horizontal sync pulse, vertically ITU-R frame line
105 numbers of the first field times two (2, 4, 6, ... 524 or 624). */
106 struct v4l2_cropcap cropcap;
107};
108extern const struct bttv_tvnorm bttv_tvnorms[];
109
110struct bttv_format {
111 char *name;
112 int fourcc; /* video4linux 2 */
113 int btformat; /* BT848_COLOR_FMT_* */
114 int btswap; /* BT848_COLOR_CTL_* */
115 int depth; /* bit/pixel */
116 int flags;
117 int hshift,vshift; /* for planar modes */
118};
119
120struct bttv_ir {
121 struct rc_dev *dev;
122 struct timer_list timer;
123
124 char name[32];
125 char phys[32];
126
127 /* Usual gpio signalling */
128 u32 mask_keycode;
129 u32 mask_keydown;
130 u32 mask_keyup;
131 u32 polling;
132 u32 last_gpio;
133 int shift_by;
134 int start; // What should RC5_START() be
135 int addr; // What RC5_ADDR() should be.
136 int rc5_remote_gap;
137
138 /* RC5 gpio */
139 bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */
140 u32 last_bit; /* last raw bit seen */
141 u32 code; /* raw code under construction */
142 struct timeval base_time; /* time of last seen code */
143 bool active; /* building raw code */
144};
145
146
147/* ---------------------------------------------------------- */
148
149struct bttv_geometry {
150 u8 vtc,crop,comb;
151 u16 width,hscale,hdelay;
152 u16 sheight,vscale,vdelay,vtotal;
153};
154
155struct bttv_buffer {
156 /* common v4l buffer stuff -- must be first */
157 struct videobuf_buffer vb;
158
159 /* bttv specific */
160 const struct bttv_format *fmt;
161 unsigned int tvnorm;
162 int btformat;
163 int btswap;
164 struct bttv_geometry geo;
165 struct btcx_riscmem top;
166 struct btcx_riscmem bottom;
167 struct v4l2_rect crop;
168 unsigned int vbi_skip[2];
169 unsigned int vbi_count[2];
170};
171
172struct bttv_buffer_set {
173 struct bttv_buffer *top; /* top field buffer */
174 struct bttv_buffer *bottom; /* bottom field buffer */
175 unsigned int top_irq;
176 unsigned int frame_irq;
177};
178
179struct bttv_overlay {
180 unsigned int tvnorm;
181 struct v4l2_rect w;
182 enum v4l2_field field;
183 struct v4l2_clip *clips;
184 int nclips;
185 int setup_ok;
186};
187
188struct bttv_vbi_fmt {
189 struct v4l2_vbi_format fmt;
190
191 /* fmt.start[] and count[] refer to this video standard. */
192 const struct bttv_tvnorm *tvnorm;
193
194 /* Earliest possible start of video capturing with this
195 v4l2_vbi_format, in struct bttv_crop.rect units. */
196 __s32 end;
197};
198
199/* bttv-vbi.c */
200void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
201
202struct bttv_crop {
203 /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */
204 struct v4l2_rect rect;
205
206 /* Scaled image size limits with this crop rect. Divide
207 max_height, but not min_height, by two when capturing
208 single fields. See also bttv_crop_reset() and
209 bttv_crop_adjust() in bttv-driver.c. */
210 __s32 min_scaled_width;
211 __s32 min_scaled_height;
212 __s32 max_scaled_width;
213 __s32 max_scaled_height;
214};
215
216struct bttv_fh {
217 struct bttv *btv;
218 int resources;
219#ifdef VIDIOC_G_PRIORITY
220 enum v4l2_priority prio;
221#endif
222 enum v4l2_buf_type type;
223
224 /* video capture */
225 struct videobuf_queue cap;
226 const struct bttv_format *fmt;
227 int width;
228 int height;
229
230 /* video overlay */
231 const struct bttv_format *ovfmt;
232 struct bttv_overlay ov;
233
234 /* Application called VIDIOC_S_CROP. */
235 int do_crop;
236
237 /* vbi capture */
238 struct videobuf_queue vbi;
239 /* Current VBI capture window as seen through this fh (cannot
240 be global for compatibility with earlier drivers). Protected
241 by struct bttv.lock and struct bttv_fh.vbi.lock. */
242 struct bttv_vbi_fmt vbi_fmt;
243};
244
245/* ---------------------------------------------------------- */
246/* bttv-risc.c */
247
248/* risc code generators - capture */
249int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
250 struct scatterlist *sglist,
251 unsigned int offset, unsigned int bpl,
252 unsigned int pitch, unsigned int skip_lines,
253 unsigned int store_lines);
254
255/* control dma register + risc main loop */
256void bttv_set_dma(struct bttv *btv, int override);
257int bttv_risc_init_main(struct bttv *btv);
258int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
259 int irqflags);
260
261/* capture buffer handling */
262int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
263int bttv_buffer_activate_video(struct bttv *btv,
264 struct bttv_buffer_set *set);
265int bttv_buffer_activate_vbi(struct bttv *btv,
266 struct bttv_buffer *vbi);
267void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
268 struct bttv_buffer *buf);
269
270/* overlay handling */
271int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
272 const struct bttv_format *fmt,
273 struct bttv_buffer *buf);
274
275
276/* ---------------------------------------------------------- */
277/* bttv-vbi.c */
278
279int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
280int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
281int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
282
283extern struct videobuf_queue_ops bttv_vbi_qops;
284
285/* ---------------------------------------------------------- */
286/* bttv-gpio.c */
287
288extern struct bus_type bttv_sub_bus_type;
289int bttv_sub_add_device(struct bttv_core *core, char *name);
290int bttv_sub_del_devices(struct bttv_core *core);
291
292/* ---------------------------------------------------------- */
293/* bttv-cards.c */
294
295extern int no_overlay;
296
297/* ---------------------------------------------------------- */
298/* bttv-input.c */
299
300extern void init_bttv_i2c_ir(struct bttv *btv);
301extern int fini_bttv_i2c(struct bttv *btv);
302
303/* ---------------------------------------------------------- */
304/* bttv-driver.c */
305
306/* insmod options */
307extern unsigned int bttv_verbose;
308extern unsigned int bttv_debug;
309extern unsigned int bttv_gpio;
310extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
311extern int init_bttv_i2c(struct bttv *btv);
312
313#define bttv_printk if (bttv_verbose) printk
314#define dprintk if (bttv_debug >= 1) printk
315#define d2printk if (bttv_debug >= 2) printk
316
317#define BTTV_MAX_FBUF 0x208000
318#define BTTV_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
319#define BTTV_FREE_IDLE msecs_to_jiffies(1000) /* one second */
320
321
322struct bttv_pll_info {
323 unsigned int pll_ifreq; /* PLL input frequency */
324 unsigned int pll_ofreq; /* PLL output frequency */
325 unsigned int pll_crystal; /* Crystal used for input */
326 unsigned int pll_current; /* Currently programmed ofreq */
327};
328
329/* for gpio-connected remote control */
330struct bttv_input {
331 struct input_dev *dev;
332 char name[32];
333 char phys[32];
334 u32 mask_keycode;
335 u32 mask_keydown;
336};
337
338struct bttv_suspend_state {
339 u32 gpio_enable;
340 u32 gpio_data;
341 int disabled;
342 int loop_irq;
343 struct bttv_buffer_set video;
344 struct bttv_buffer *vbi;
345};
346
347struct bttv {
348 struct bttv_core c;
349
350 /* pci device config */
351 unsigned short id;
352 unsigned char revision;
353 unsigned char __iomem *bt848_mmio; /* pointer to mmio */
354
355 /* card configuration info */
356 unsigned int cardid; /* pci subsystem id (bt878 based ones) */
357 unsigned int tuner_type; /* tuner chip type */
358 unsigned int tda9887_conf;
359 unsigned int svhs, dig;
360 unsigned int has_saa6588:1;
361 struct bttv_pll_info pll;
362 int triton1;
363 int gpioirq;
364
365 int use_i2c_hw;
366
367 /* old gpio interface */
368 int shutdown;
369
370 void (*volume_gpio)(struct bttv *btv, __u16 volume);
371 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
372
373 /* new gpio interface */
374 spinlock_t gpio_lock;
375
376 /* i2c layer */
377 struct i2c_algo_bit_data i2c_algo;
378 struct i2c_client i2c_client;
379 int i2c_state, i2c_rc;
380 int i2c_done;
381 wait_queue_head_t i2c_queue;
382 struct v4l2_subdev *sd_msp34xx;
383 struct v4l2_subdev *sd_tvaudio;
384
385 /* video4linux (1) */
386 struct video_device *video_dev;
387 struct video_device *radio_dev;
388 struct video_device *vbi_dev;
389
390 /* infrared remote */
391 int has_remote;
392 struct bttv_ir *remote;
393
394 /* I2C remote data */
395 struct IR_i2c_init_data init_data;
396
397 /* locking */
398 spinlock_t s_lock;
399 struct mutex lock;
400 int resources;
401#ifdef VIDIOC_G_PRIORITY
402 struct v4l2_prio_state prio;
403#endif
404
405 /* video state */
406 unsigned int input;
407 unsigned int audio;
408 unsigned int mute;
409 unsigned long freq;
410 unsigned int tvnorm;
411 int hue, contrast, bright, saturation;
412 struct v4l2_framebuffer fbuf;
413 unsigned int field_count;
414
415 /* various options */
416 int opt_combfilter;
417 int opt_lumafilter;
418 int opt_automute;
419 int opt_chroma_agc;
420 int opt_adc_crush;
421 int opt_vcr_hack;
422 int opt_whitecrush_upper;
423 int opt_whitecrush_lower;
424 int opt_uv_ratio;
425 int opt_full_luma_range;
426 int opt_coring;
427
428 /* radio data/state */
429 int has_radio;
430 int radio_user;
431
432 /* miro/pinnacle + Aimslab VHX
433 philips matchbox (tea5757 radio tuner) support */
434 int has_matchbox;
435 int mbox_we;
436 int mbox_data;
437 int mbox_clk;
438 int mbox_most;
439 int mbox_mask;
440
441 /* ISA stuff (Terratec Active Radio Upgrade) */
442 int mbox_ior;
443 int mbox_iow;
444 int mbox_csel;
445
446 /* risc memory management data
447 - must acquire s_lock before changing these
448 - only the irq handler is supported to touch top + bottom + vcurr */
449 struct btcx_riscmem main;
450 struct bttv_buffer *screen; /* overlay */
451 struct list_head capture; /* video capture queue */
452 struct list_head vcapture; /* vbi capture queue */
453 struct bttv_buffer_set curr; /* active buffers */
454 struct bttv_buffer *cvbi; /* active vbi buffer */
455 int loop_irq;
456 int new_input;
457
458 unsigned long cap_ctl;
459 unsigned long dma_on;
460 struct timer_list timeout;
461 struct bttv_suspend_state state;
462
463 /* stats */
464 unsigned int errors;
465 unsigned int framedrop;
466 unsigned int irq_total;
467 unsigned int irq_me;
468
469 unsigned int users;
470 struct bttv_fh init;
471
472 /* used to make dvb-bt8xx autoloadable */
473 struct work_struct request_module_wk;
474
475 /* Default (0) and current (1) video capturing and overlay
476 cropping parameters in bttv_tvnorm.cropcap units. Protected
477 by bttv.lock. */
478 struct bttv_crop crop[2];
479
480 /* Earliest possible start of video capturing in
481 bttv_tvnorm.cropcap line units. Set by check_alloc_btres()
482 and free_btres(). Protected by bttv.lock. */
483 __s32 vbi_end;
484
485 /* Latest possible end of VBI capturing (= crop[x].rect.top when
486 VIDEO_RESOURCES are locked). Set by check_alloc_btres()
487 and free_btres(). Protected by bttv.lock. */
488 __s32 crop_start;
489};
490
491static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
492{
493 return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
494}
495
496/* our devices */
497#define BTTV_MAX 32
498extern unsigned int bttv_num;
499extern struct bttv *bttvs[BTTV_MAX];
500
501static inline unsigned int bttv_muxsel(const struct bttv *btv,
502 unsigned int input)
503{
504 return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
505}
506
507#endif
508
509#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
510#define btread(adr) readl(btv->bt848_mmio+(adr))
511
512#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
513#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
514#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
515
516#endif /* _BTTVP_H_ */
517
518/*
519 * Local variables:
520 * c-basic-offset: 8
521 * End:
522 */