ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / media / video / bttv-cards.c
1 /*
2     bttv-cards.c
3
4     this file has configuration informations - card-specific stuff
5     like the big tvcards array for the most part
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-2001 Gerd Knorr <kraxel@goldbach.in-berlin.de>
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/config.h>
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 #ifdef CONFIG_FW_LOADER
35 # include <linux/firmware.h>
36 #endif
37
38 #include <asm/io.h>
39
40 #include "bttvp.h"
41 #include "bt832.h"
42
43 /* fwd decl */
44 static void boot_msp34xx(struct bttv *btv, int pin);
45 static void boot_bt832(struct bttv *btv);
46 static void hauppauge_eeprom(struct bttv *btv);
47 static void avermedia_eeprom(struct bttv *btv);
48 static void osprey_eeprom(struct bttv *btv);
49 static void modtec_eeprom(struct bttv *btv);
50 static void init_PXC200(struct bttv *btv);
51
52 static void winview_audio(struct bttv *btv, struct video_audio *v, int set);
53 static void lt9415_audio(struct bttv *btv, struct video_audio *v, int set);
54 static void avermedia_tvphone_audio(struct bttv *btv, struct video_audio *v,
55                                     int set);
56 static void avermedia_tv_stereo_audio(struct bttv *btv, struct video_audio *v,
57                                       int set);
58 static void terratv_audio(struct bttv *btv, struct video_audio *v, int set);
59 static void gvbctv3pci_audio(struct bttv *btv, struct video_audio *v, int set);
60 static void gvbctv5pci_audio(struct bttv *btv, struct video_audio *v, int set);
61 static void winfast2000_audio(struct bttv *btv, struct video_audio *v, int set);
62 static void pvbt878p9b_audio(struct bttv *btv, struct video_audio *v, int set);
63 static void fv2000s_audio(struct bttv *btv, struct video_audio *v, int set);
64 static void windvr_audio(struct bttv *btv, struct video_audio *v, int set);
65 static void adtvk503_audio(struct bttv *btv, struct video_audio *v, int set);
66 static void rv605_muxsel(struct bttv *btv, unsigned int input);
67 static void eagle_muxsel(struct bttv *btv, unsigned int input);
68 static void xguard_muxsel(struct bttv *btv, unsigned int input);
69 static void ivc120_muxsel(struct bttv *btv, unsigned int input);
70 static void gvc1100_muxsel(struct bttv *btv, unsigned int input);
71
72 static void PXC200_muxsel(struct bttv *btv, unsigned int input);
73
74 static int terratec_active_radio_upgrade(struct bttv *btv);
75 static int tea5757_read(struct bttv *btv);
76 static int tea5757_write(struct bttv *btv, int value);
77 static void identify_by_eeprom(struct bttv *btv,
78                                unsigned char eeprom_data[256]);
79
80 /* config variables */
81 static unsigned int triton1=0;
82 static unsigned int vsfx=0;
83 static unsigned int latency = UNSET;
84 unsigned int no_overlay=-1;
85
86 static unsigned int card[BTTV_MAX]   = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
87 static unsigned int pll[BTTV_MAX]    = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
88 static unsigned int tuner[BTTV_MAX]  = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
89 static unsigned int svhs[BTTV_MAX]   = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
90 static unsigned int remote[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
91 #ifdef MODULE
92 static unsigned int autoload = 1;
93 #else
94 static unsigned int autoload = 0;
95 #endif
96 static unsigned int gpiomask = UNSET;
97 static unsigned int audioall = UNSET;
98 static unsigned int audiomux[5] = { [ 0 ... 4 ] = UNSET };
99
100 /* insmod options */
101 MODULE_PARM(triton1,"i");
102 MODULE_PARM_DESC(triton1,"set ETBF pci config bit "
103                  "[enable bug compatibility for triton1 + others]");
104 MODULE_PARM(vsfx,"i");
105 MODULE_PARM_DESC(vsfx,"set VSFX pci config bit "
106                  "[yet another chipset flaw workaround]");
107 MODULE_PARM(no_overlay,"i");
108 MODULE_PARM(latency,"i");
109 MODULE_PARM_DESC(latency,"pci latency timer");
110 MODULE_PARM(card,"1-" __stringify(BTTV_MAX) "i");
111 MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a list");
112 MODULE_PARM(pll,"1-" __stringify(BTTV_MAX) "i");
113 MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)");
114 MODULE_PARM(tuner,"1-" __stringify(BTTV_MAX) "i");
115 MODULE_PARM_DESC(tuner,"specify installed tuner type");
116 MODULE_PARM(autoload,"i");
117 MODULE_PARM_DESC(autoload,"automatically load i2c modules like tuner.o, default is 1 (yes)");
118
119 MODULE_PARM(svhs,"1-" __stringify(BTTV_MAX) "i");
120 MODULE_PARM(remote,"1-" __stringify(BTTV_MAX) "i");
121
122 MODULE_PARM(gpiomask,"i");
123 MODULE_PARM(audioall,"i");
124 MODULE_PARM(audiomux,"1-6i");
125
126 /* kernel args */
127 #ifndef MODULE
128 static int __init p_card(char *str)  { return bttv_parse(str,BTTV_MAX,card);  }
129 static int __init p_pll(char *str)   { return bttv_parse(str,BTTV_MAX,pll);   }
130 static int __init p_tuner(char *str) { return bttv_parse(str,BTTV_MAX,tuner); }
131 __setup("bttv.card=",  p_card);
132 __setup("bttv.pll=",   p_pll);
133 __setup("bttv.tuner=", p_tuner);
134
135 int __init bttv_parse(char *str, int max, int *vals)
136 {
137         int i,number,res = 2;
138         
139         for (i = 0; res == 2 && i < max; i++) {
140                 res = get_option(&str,&number);
141                 if (res)
142                         vals[i] = number;
143         }
144         return 1;
145 }
146 #endif
147
148 /* ----------------------------------------------------------------------- */
149 /* list of card IDs for bt878+ cards                                       */
150
151 static struct CARD {
152         unsigned id;
153         int cardnr;
154         char *name;
155 } cards[] __devinitdata = {
156         { 0x13eb0070, BTTV_HAUPPAUGE878,  "Hauppauge WinTV" },
157         { 0x39000070, BTTV_HAUPPAUGE878,  "Hauppauge WinTV-D" },
158         { 0x45000070, BTTV_HAUPPAUGEPVR,  "Hauppauge WinTV/PVR" },
159         { 0xff000070, BTTV_OSPREY1x0,     "Osprey-100" },
160         { 0xff010070, BTTV_OSPREY2x0_SVID,"Osprey-200" },
161         { 0xff020070, BTTV_OSPREY500,     "Osprey-500" },
162         { 0xff030070, BTTV_OSPREY2000,    "Osprey-2000" },
163         { 0xff040070, BTTV_OSPREY540,     "Osprey-540" },
164
165         { 0x00011002, BTTV_ATI_TVWONDER,  "ATI TV Wonder" },
166         { 0x00031002, BTTV_ATI_TVWONDERVE,"ATI TV Wonder/VE" },
167
168         { 0x6606107d, BTTV_WINFAST2000,   "Leadtek WinFast TV 2000" },
169         { 0x6607107d, BTTV_WINFASTVC100,  "Leadtek WinFast VC 100" },
170         { 0x263610b4, BTTV_STB2,          "STB TV PCI FM, Gateway P/N 6000704" },
171         { 0x264510b4, BTTV_STB2,          "STB TV PCI FM, Gateway P/N 6000704" },
172         { 0x402010fc, BTTV_GVBCTV3PCI,    "I-O Data Co. GV-BCTV3/PCI" },
173         { 0x405010fc, BTTV_GVBCTV4PCI,    "I-O Data Co. GV-BCTV4/PCI" },
174         { 0x407010fc, BTTV_GVBCTV5PCI,    "I-O Data Co. GV-BCTV5/PCI" },
175         { 0xd01810fc, BTTV_GVBCTV5PCI,    "I-O Data Co. GV-BCTV5/PCI" },
176
177         { 0x001211bd, BTTV_PINNACLE,      "Pinnacle PCTV" },
178         { 0x001c11bd, BTTV_PINNACLESAT,   "Pinnacle PCTV Sat" },
179         // some cards ship with byteswapped IDs ...
180         { 0x1200bd11, BTTV_PINNACLE,      "Pinnacle PCTV [bswap]" },
181         { 0xff00bd11, BTTV_PINNACLE,      "Pinnacle PCTV [bswap]" },
182
183         { 0x3000121a, BTTV_VOODOOTV_FM,   "3Dfx VoodooTV FM/ VoodooTV 200" },
184         { 0x3060121a, BTTV_STB2,          "3Dfx VoodooTV 100/ STB OEM" },
185         
186         { 0x3000144f, BTTV_MAGICTVIEW063, "(Askey Magic/others) TView99 CPH06x" },
187         { 0x3002144f, BTTV_MAGICTVIEW061, "(Askey Magic/others) TView99 CPH05x" },
188         { 0x3005144f, BTTV_MAGICTVIEW061, "(Askey Magic/others) TView99 CPH061/06L (T1/LC)" },
189         { 0x5000144f, BTTV_MAGICTVIEW061, "Askey CPH050" },
190         { 0x300014ff, BTTV_MAGICTVIEW061, "TView 99 (CPH061)" },
191         { 0x300214ff, BTTV_PHOEBE_TVMAS,  "Phoebe TV Master (CPH060)" },
192
193         { 0x00011461, BTTV_AVPHONE98,     "AVerMedia TVPhone98" },
194         { 0x00021461, BTTV_AVERMEDIA98,   "AVermedia TVCapture 98" },
195         { 0x00031461, BTTV_AVPHONE98,     "AVerMedia TVPhone98" },
196         { 0x00041461, BTTV_AVERMEDIA98,   "AVerMedia TVCapture 98" },
197         { 0x03001461, BTTV_AVERMEDIA98,   "VDOMATE TV TUNER CARD" },
198
199         { 0x1117153b, BTTV_TERRATVALUE,   "Terratec TValue (Philips PAL B/G)" },
200         { 0x1118153b, BTTV_TERRATVALUE,   "Terratec TValue (Temic PAL B/G)" },
201         { 0x1119153b, BTTV_TERRATVALUE,   "Terratec TValue (Philips PAL I)" },
202         { 0x111a153b, BTTV_TERRATVALUE,   "Terratec TValue (Temic PAL I)" },
203  
204         { 0x1123153b, BTTV_TERRATVRADIO,  "Terratec TV Radio+" },
205         { 0x1127153b, BTTV_TERRATV,       "Terratec TV+ (V1.05)"    },
206         // clashes with FlyVideo
207         //{ 0x18521852, BTTV_TERRATV,     "Terratec TV+ (V1.10)"    },
208         { 0x1134153b, BTTV_TERRATVALUE,   "Terratec TValue (LR102)" },
209         { 0x1135153b, BTTV_TERRATVALUER,  "Terratec TValue Radio" }, // LR102
210         { 0x5018153b, BTTV_TERRATVALUE,   "Terratec TValue" },       // ??
211         { 0xff3b153b, BTTV_TERRATVALUER,  "Terratec TValue Radio" }, // ??
212
213         { 0x400015b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV" },
214         { 0x400a15b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV" },
215         { 0x400d15b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV / Radio" },
216         { 0x401015b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV / Radio" },
217         { 0x401615b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV / Radio" },
218
219         { 0x1430aa00, BTTV_PV143,         "Provideo PV143A" },
220         { 0x1431aa00, BTTV_PV143,         "Provideo PV143B" },
221         { 0x1432aa00, BTTV_PV143,         "Provideo PV143C" },
222         { 0x1433aa00, BTTV_PV143,         "Provideo PV143D" },
223
224         { 0x1460aa00, BTTV_PV150,         "Provideo PV150A-1" },
225         { 0x1461aa01, BTTV_PV150,         "Provideo PV150A-2" },
226         { 0x1462aa02, BTTV_PV150,         "Provideo PV150A-3" },
227         { 0x1463aa03, BTTV_PV150,         "Provideo PV150A-4" },
228
229         { 0x1464aa04, BTTV_PV150,         "Provideo PV150B-1" },
230         { 0x1465aa05, BTTV_PV150,         "Provideo PV150B-2" },
231         { 0x1466aa06, BTTV_PV150,         "Provideo PV150B-3" },
232         { 0x1467aa07, BTTV_PV150,         "Provideo PV150B-4" },
233
234         { 0xa132ff00, BTTV_IVC100,        "IVC-100"  },
235         { 0xa1550000, BTTV_IVC200,        "IVC-200"  },
236         { 0xa1550001, BTTV_IVC200,        "IVC-200"  },
237         { 0xa1550002, BTTV_IVC200,        "IVC-200"  },
238         { 0xa1550003, BTTV_IVC200,        "IVC-200"  }, 
239         { 0xa1550100, BTTV_IVC200,        "IVC-200G" },
240         { 0xa1550101, BTTV_IVC200,        "IVC-200G" },
241         { 0xa1550102, BTTV_IVC200,        "IVC-200G" },
242         { 0xa1550103, BTTV_IVC200,        "IVC-200G" },
243         { 0xa182ff00, BTTV_IVC120,        "IVC-120G" },
244         { 0xa182ff01, BTTV_IVC120,        "IVC-120G" },
245         { 0xa182ff02, BTTV_IVC120,        "IVC-120G" },
246         { 0xa182ff03, BTTV_IVC120,        "IVC-120G" },
247         { 0xa182ff04, BTTV_IVC120,        "IVC-120G" },
248         { 0xa182ff05, BTTV_IVC120,        "IVC-120G" },
249         { 0xa182ff06, BTTV_IVC120,        "IVC-120G" },
250         { 0xa182ff07, BTTV_IVC120,        "IVC-120G" },
251         { 0xa182ff08, BTTV_IVC120,        "IVC-120G" },
252         { 0xa182ff09, BTTV_IVC120,        "IVC-120G" },
253         { 0xa182ff0a, BTTV_IVC120,        "IVC-120G" },
254         { 0xa182ff0b, BTTV_IVC120,        "IVC-120G" },
255         { 0xa182ff0c, BTTV_IVC120,        "IVC-120G" },
256         { 0xa182ff0d, BTTV_IVC120,        "IVC-120G" },
257         { 0xa182ff0e, BTTV_IVC120,        "IVC-120G" },
258         { 0xa182ff0f, BTTV_IVC120,        "IVC-120G" },
259         
260         { 0x41424344, BTTV_GRANDTEC,      "GrandTec Multi Capture" },
261         { 0x01020304, BTTV_XGUARD,        "Grandtec Grand X-Guard" },
262         
263         { 0x010115cb, BTTV_GMV1,          "AG GMV1" },
264         { 0x010114c7, BTTV_MODTEC_205,    "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV" },
265         { 0x18501851, BTTV_CHRONOS_VS2,   "FlyVideo 98 (LR50)/ Chronos Video Shuttle II" },
266         { 0x18511851, BTTV_FLYVIDEO98EZ,  "FlyVideo 98EZ (LR51)/ CyberMail AV" },
267         { 0x18521852, BTTV_TYPHOON_TVIEW, "FlyVideo 98FM (LR50)/ Typhoon TView TV/FM Tuner" },
268         { 0x41a0a051, BTTV_FLYVIDEO_98FM, "Lifeview FlyVideo 98 LR50 Rev Q" },
269         { 0x10b42636, BTTV_HAUPPAUGE878,  "STB ???" },
270         { 0x217d6606, BTTV_WINFAST2000,   "Leadtek WinFast TV 2000" },
271         { 0xfff6f6ff, BTTV_WINFAST2000,   "Leadtek WinFast TV 2000" },
272         { 0x03116000, BTTV_SENSORAY311,   "Sensoray 311" },
273         { 0x00790e11, BTTV_WINDVR,        "Canopus WinDVR PCI" },
274         { 0xa0fca1a0, BTTV_ZOLTRIX,       "Face to Face Tvmax" },
275         { 0x20007063, BTTV_PC_HDTV,       "pcHDTV HD-2000 TV"},
276         { 0x82b2aa6a, BTTV_SIMUS_GVC1100, "SIMUS GVC1100" },
277         { 0x146caa0c, BTTV_PV951,         "ituner spectra8" },
278         { 0x200a1295, BTTV_PXC200,        "ImageNation PXC200A" },
279
280         { 0x40111554, BTTV_PV_BT878P_9B,  "Prolink Pixelview PV-BT" },
281         { 0x17de0a01, BTTV_KWORLD,        "Mecer TV/FM/Video Tuner" },
282
283         // likely broken, vendor id doesn't match the other magic views ...
284         //{ 0xa0fca04f, BTTV_MAGICTVIEW063, "Guillemot Maxi TV Video 3" },
285         
286         // DVB cards (using pci function .1 for mpeg data xfer)
287         { 0x01010071, BTTV_NEBULA_DIGITV, "Nebula Electronics DigiTV" },
288         { 0x002611bd, BTTV_TWINHAN_DST,   "Pinnacle PCTV SAT CI" },
289         { 0x00011822, BTTV_TWINHAN_DST,   "Twinhan VisionPlus DVB-T" },
290         { 0xfc00270f, BTTV_TWINHAN_DST,   "ChainTech digitop DST-1000 DVB-S" },
291         
292         { 0, -1, NULL }
293 };
294
295 /* ----------------------------------------------------------------------- */
296 /* array with description for bt848 / bt878 tv/grabber cards               */
297
298 struct tvcard bttv_tvcards[] = {
299 {
300 /* ---- card 0x00 ---------------------------------- */
301         .name           = " *** UNKNOWN/GENERIC *** ",
302         .video_inputs   = 4,
303         .audio_inputs   = 1,
304         .tuner          = 0,
305         .svhs           = 2,
306         .muxsel         = { 2, 3, 1, 0},
307         .tuner_type     = -1,
308 },{
309         .name           = "MIRO PCTV",
310         .video_inputs   = 4,
311         .audio_inputs   = 1,
312         .tuner          = 0,
313         .svhs           = 2,
314         .gpiomask       = 15,
315         .muxsel         = { 2, 3, 1, 1},
316         .audiomux       = { 2, 0, 0, 0, 10},
317         .needs_tvaudio  = 1,
318         .tuner_type     = -1,
319 },{
320         .name           = "Hauppauge (bt848)",
321         .video_inputs   = 4,
322         .audio_inputs   = 1,
323         .tuner          = 0,
324         .svhs           = 2,
325         .gpiomask       = 7,
326         .muxsel         = { 2, 3, 1, 1},
327         .audiomux       = { 0, 1, 2, 3, 4},
328         .needs_tvaudio  = 1,
329         .tuner_type     = -1,
330 },{
331         .name           = "STB, Gateway P/N 6000699 (bt848)",
332         .video_inputs   = 3,
333         .audio_inputs   = 1,
334         .tuner          = 0,
335         .svhs           = 2,
336         .gpiomask       = 7,
337         .muxsel         = { 2, 3, 1, 1},
338         .audiomux       = { 4, 0, 2, 3, 1},
339         .no_msp34xx     = 1,
340         .needs_tvaudio  = 1,
341         .tuner_type     = TUNER_PHILIPS_NTSC,
342         .pll            = PLL_28,
343         .has_radio      = 1,
344 },{
345
346 /* ---- card 0x04 ---------------------------------- */
347         .name           = "Intel Create and Share PCI/ Smart Video Recorder III",
348         .video_inputs   = 4,
349         .audio_inputs   = 0,
350         .tuner          = -1,
351         .svhs           = 2,
352         .gpiomask       = 0,
353         .muxsel         = { 2, 3, 1, 1},
354         .audiomux       = { 0 },
355         .needs_tvaudio  = 0,
356         .tuner_type     = 4,
357 },{
358         .name           = "Diamond DTV2000",
359         .video_inputs   = 4,
360         .audio_inputs   = 1,
361         .tuner          = 0,
362         .svhs           = 2,
363         .gpiomask       = 3,
364         .muxsel         = { 2, 3, 1, 0},
365         .audiomux       = { 0, 1, 0, 1, 3},
366         .needs_tvaudio  = 1,
367         .tuner_type     = -1,
368 },{
369         .name           = "AVerMedia TVPhone",
370         .video_inputs   = 3,
371         .audio_inputs   = 1,
372         .tuner          = 0,
373         .svhs           = 3,
374         .muxsel         = { 2, 3, 1, 1},
375         .gpiomask       = 0x0f,
376         .audiomux       = { 0x0c, 0x04, 0x08, 0x04, 0},
377         /*                0x04 for some cards ?? */
378         .needs_tvaudio  = 1,
379         .tuner_type     = -1,
380         .audio_hook     = avermedia_tvphone_audio,
381         .has_remote     = 1,
382 },{
383         .name           = "MATRIX-Vision MV-Delta",
384         .video_inputs   = 5,
385         .audio_inputs   = 1,
386         .tuner          = -1,
387         .svhs           = 3,
388         .gpiomask       = 0,
389         .muxsel         = { 2, 3, 1, 0, 0},
390         .audiomux       = {0 },
391         .needs_tvaudio  = 1,
392         .tuner_type     = -1,
393 },{
394
395 /* ---- card 0x08 ---------------------------------- */
396         .name           = "Lifeview FlyVideo II (Bt848) LR26 / MAXI TV Video PCI2 LR26",
397         .video_inputs   = 4,
398         .audio_inputs   = 1,
399         .tuner          = 0,
400         .svhs           = 2,
401         .gpiomask       = 0xc00,
402         .muxsel         = { 2, 3, 1, 1},
403         .audiomux       = { 0, 0xc00, 0x800, 0x400, 0xc00, 0},
404         .needs_tvaudio  = 1,
405         .pll            = PLL_28,
406         .tuner_type     = -1,
407 },{
408         .name           = "IMS/IXmicro TurboTV",
409         .video_inputs   = 3,
410         .audio_inputs   = 1,
411         .tuner          = 0,
412         .svhs           = 2,
413         .gpiomask       = 3,
414         .muxsel         = { 2, 3, 1, 1},
415         .audiomux       = { 1, 1, 2, 3, 0},
416         .needs_tvaudio  = 0,
417         .pll            = PLL_28,
418         .tuner_type     = TUNER_TEMIC_PAL,
419 },{
420         .name           = "Hauppauge (bt878)",
421         .video_inputs   = 4,
422         .audio_inputs   = 1,
423         .tuner          = 0,
424         .svhs           = 2,
425         .gpiomask       = 0x0f, /* old: 7 */
426         .muxsel         = { 2, 0, 1, 1},
427         .audiomux       = { 0, 1, 2, 3, 4},
428         .needs_tvaudio  = 1,
429         .pll            = PLL_28,
430         .tuner_type     = -1,
431 },{
432         .name           = "MIRO PCTV pro",
433         .video_inputs   = 3,
434         .audio_inputs   = 1,
435         .tuner          = 0,
436         .svhs           = 2,
437         .gpiomask       = 0x3014f,
438         .muxsel         = { 2, 3, 1, 1},
439         .audiomux       = { 0x20001,0x10001, 0, 0,10},
440         .needs_tvaudio  = 1,
441         .tuner_type     = -1,
442 },{
443
444 /* ---- card 0x0c ---------------------------------- */
445         .name           = "ADS Technologies Channel Surfer TV (bt848)",
446         .video_inputs   = 3,
447         .audio_inputs   = 1,
448         .tuner          = 0,
449         .svhs           = 2,
450         .gpiomask       = 15,
451         .muxsel         = { 2, 3, 1, 1},
452         .audiomux       = { 13, 14, 11, 7, 0, 0},
453         .needs_tvaudio  = 1,
454         .tuner_type     = -1,
455 },{
456         .name           = "AVerMedia TVCapture 98",
457         .video_inputs   = 3,
458         .audio_inputs   = 4,
459         .tuner          = 0,
460         .svhs           = 2,
461         .gpiomask       = 15,
462         .muxsel         = { 2, 3, 1, 1},
463         .audiomux       = { 13, 14, 11, 7, 0, 0},
464         .needs_tvaudio  = 1,
465         .msp34xx_alt    = 1,
466         .pll            = PLL_28,
467         .tuner_type     = TUNER_PHILIPS_PAL,
468         .audio_hook     = avermedia_tv_stereo_audio,
469 },{
470         .name           = "Aimslab Video Highway Xtreme (VHX)",
471         .video_inputs   = 3,
472         .audio_inputs   = 1,
473         .tuner          = 0,
474         .svhs           = 2,
475         .gpiomask       = 7,
476         .muxsel         = { 2, 3, 1, 1},
477         .audiomux       = { 0, 2, 1, 3, 4}, /* old: { 0, 1, 2, 3, 4} */
478         .needs_tvaudio  = 1,
479         .pll            = PLL_28,
480         .tuner_type     = -1,
481 },{
482         .name           = "Zoltrix TV-Max",
483         .video_inputs   = 3,
484         .audio_inputs   = 1,
485         .tuner          = 0,
486         .svhs           = 2,
487         .gpiomask       = 15,
488         .muxsel         = { 2, 3, 1, 1},
489         .audiomux       = {0 , 0, 1 , 0, 10},
490         .needs_tvaudio  = 1,
491         .tuner_type     = -1,
492 },{
493
494 /* ---- card 0x10 ---------------------------------- */
495         .name           = "Prolink Pixelview PlayTV (bt878)",
496         .video_inputs   = 3,
497         .audio_inputs   = 1,
498         .tuner          = 0,
499         .svhs           = 2,
500         .gpiomask       = 0x01fe00,
501         .muxsel         = { 2, 3, 1, 1},
502 #if 0
503         // old
504         .audiomux       = { 0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 },
505 #else
506         // 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru>
507         .audiomux       = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 },
508 #endif
509         .needs_tvaudio  = 1,
510         .pll            = PLL_28,
511         .tuner_type     = -1,
512 },{
513         .name           = "Leadtek WinView 601",
514         .video_inputs   = 3,
515         .audio_inputs   = 1,
516         .tuner          = 0,
517         .svhs           = 2,
518         .gpiomask       = 0x8300f8,
519         .muxsel         = { 2, 3, 1, 1,0},
520         .audiomux       = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007},
521         .needs_tvaudio  = 1,
522         .tuner_type     = -1,
523         .audio_hook     = winview_audio,
524         .has_radio      = 1,
525 },{
526         .name           = "AVEC Intercapture",
527         .video_inputs   = 3,
528         .audio_inputs   = 2,
529         .tuner          = 0,
530         .svhs           = 2,
531         .gpiomask       = 0,
532         .muxsel         = {2, 3, 1, 1},
533         .audiomux       = {1, 0, 0, 0, 0},
534         .needs_tvaudio  = 1,
535         .tuner_type     = -1,
536 },{
537         .name           = "Lifeview FlyVideo II EZ /FlyKit LR38 Bt848 (capture only)",
538         .video_inputs   = 4,
539         .audio_inputs   = 1,
540         .tuner          = -1,
541         .svhs           = -1,
542         .gpiomask       = 0x8dff00,
543         .muxsel         = { 2, 3, 1, 1},
544         .audiomux       = { 0 },
545         .no_msp34xx     = 1,
546         .tuner_type     = -1,
547 },{
548
549 /* ---- card 0x14 ---------------------------------- */
550         .name           = "CEI Raffles Card",
551         .video_inputs   = 3,
552         .audio_inputs   = 3,
553         .tuner          = 0,
554         .svhs           = 2,
555         .muxsel         = {2, 3, 1, 1},
556         .tuner_type     = -1,
557 },{
558         .name           = "Lifeview FlyVideo 98/ Lucky Star Image World ConferenceTV LR50",
559         .video_inputs   = 4,
560         .audio_inputs   = 2,  // tuner, line in
561         .tuner          = 0,
562         .svhs           = 2,
563         .gpiomask       = 0x1800,
564         .muxsel         = { 2, 3, 1, 1},
565         .audiomux       = { 0, 0x800, 0x1000, 0x1000, 0x1800},
566         .pll            = PLL_28,
567         .tuner_type     = TUNER_PHILIPS_PAL_I,
568 },{
569         .name           = "Askey CPH050/ Phoebe Tv Master + FM",
570         .video_inputs   = 3,
571         .audio_inputs   = 1,
572         .tuner          = 0,
573         .svhs           = 2,
574         .gpiomask       = 0xc00,
575         .muxsel         = { 2, 3, 1, 1},
576         .audiomux       = {0, 1, 0x800, 0x400, 0xc00, 0},
577         .needs_tvaudio  = 1,
578         .pll            = PLL_28,
579         .tuner_type     = -1,
580 },{
581         .name           = "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV, bt878",
582         .video_inputs   = 3,
583         .audio_inputs   = 1,
584         .tuner          = 0,
585         .svhs           = -1,
586         .gpiomask       = 7,
587         .muxsel         = { 2, 3, -1 },
588         .digital_mode   = DIGITAL_MODE_CAMERA,
589         .audiomux       = { 0, 0, 0, 0, 0 },
590         .no_msp34xx     = 1,
591         .pll            = PLL_28,
592         .tuner_type     = TUNER_ALPS_TSBB5_PAL_I,
593 },{
594
595 /* ---- card 0x18 ---------------------------------- */
596         .name           = "Askey CPH05X/06X (bt878) [many vendors]",
597         .video_inputs   = 3,
598         .audio_inputs   = 1,
599         .tuner          = 0,
600         .svhs           = 2,
601         .gpiomask       = 0xe00,
602         .muxsel         = { 2, 3, 1, 1},
603         .audiomux       = {0x400, 0x400, 0x400, 0x400, 0xc00},
604         .needs_tvaudio  = 1,
605         .pll            = PLL_28,
606         .tuner_type     = -1,
607         .has_remote     = 1,
608 },{
609         .name           = "Terratec TerraTV+ Version 1.0 (Bt848)/ Terra TValue Version 1.0/ Vobis TV-Boostar",
610         .video_inputs   = 3,
611         .audio_inputs   = 1,
612         .tuner          = 0,
613         .svhs           = 2,
614         .gpiomask       = 0x1f0fff,
615         .muxsel         = { 2, 3, 1, 1},
616         .audiomux       = { 0x20000, 0x30000, 0x10000, 0, 0x40000},
617         .needs_tvaudio  = 0,
618         .tuner_type     = TUNER_PHILIPS_PAL,
619         .audio_hook     = terratv_audio,
620 },{
621         .name           = "Hauppauge WinCam newer (bt878)",
622         .video_inputs   = 4,
623         .audio_inputs   = 1,
624         .tuner          = 0,
625         .svhs           = 3,
626         .gpiomask       = 7,
627         .muxsel         = { 2, 0, 1, 1},
628         .audiomux       = { 0, 1, 2, 3, 4},
629         .needs_tvaudio  = 1,
630         .tuner_type     = -1,
631 },{
632         .name           = "Lifeview FlyVideo 98/ MAXI TV Video PCI2 LR50",
633         .video_inputs   = 4,
634         .audio_inputs   = 2,
635         .tuner          = 0,
636         .svhs           = 2,
637         .gpiomask       = 0x1800,
638         .muxsel         = { 2, 3, 1, 1},
639         .audiomux       = { 0, 0x800, 0x1000, 0x1000, 0x1800},
640         .pll            = PLL_28,
641         .tuner_type     = TUNER_PHILIPS_SECAM,
642 },{
643
644 /* ---- card 0x1c ---------------------------------- */
645         .name           = "Terratec TerraTV+ Version 1.1 (bt878)",
646         .video_inputs   = 3,
647         .audio_inputs   = 1,
648         .tuner          = 0,
649         .svhs           = 2,
650         .gpiomask       = 0x1f0fff,
651         .muxsel         = { 2, 3, 1, 1},
652         .audiomux       = { 0x20000, 0x30000, 0x10000, 0x00000, 0x40000},
653         .needs_tvaudio  = 0,
654         .tuner_type     = TUNER_PHILIPS_PAL,
655         .audio_hook     = terratv_audio,
656         /* GPIO wiring:
657                External 20 pin connector (for Active Radio Upgrade board)
658                gpio00: i2c-sda
659                gpio01: i2c-scl
660                gpio02: om5610-data
661                gpio03: om5610-clk
662                gpio04: om5610-wre
663                gpio05: om5610-stereo
664                gpio06: rds6588-davn
665                gpio07: Pin 7 n.c.
666                gpio08: nIOW
667                gpio09+10: nIOR, nSEL ?? (bt878)
668                 gpio09: nIOR (bt848)
669                 gpio10: nSEL (bt848)
670               Sound Routing:
671                gpio16: u2-A0 (1st 4052bt)
672                gpio17: u2-A1
673                gpio18: u2-nEN
674                gpio19: u4-A0 (2nd 4052)
675                gpio20: u4-A1
676                        u4-nEN - GND
677             Btspy:
678                 00000 : Cdrom (internal audio input)
679                 10000 : ext. Video audio input
680                 20000 : TV Mono
681                 a0000 : TV Mono/2
682                1a0000 : TV Stereo       
683                 30000 : Radio
684                 40000 : Mute
685        */
686
687 },{
688         /* Jannik Fritsch <jannik@techfak.uni-bielefeld.de> */
689         .name           = "Imagenation PXC200",
690         .video_inputs   = 5,
691         .audio_inputs   = 1,
692         .tuner          = -1,
693         .svhs           = 1, /* was: 4 */
694         .gpiomask       = 0,
695         .muxsel         = { 2, 3, 1, 0, 0},
696         .audiomux       = { 0 },
697         .needs_tvaudio  = 1,
698         .tuner_type     = -1,
699         .muxsel_hook    = PXC200_muxsel,
700
701 },{
702         .name           = "Lifeview FlyVideo 98 LR50",
703         .video_inputs   = 4,
704         .audio_inputs   = 1,
705         .tuner          = 0,
706         .svhs           = 2,
707         .gpiomask       = 0x1800,  //0x8dfe00
708         .muxsel         = { 2, 3, 1, 1},
709         .audiomux       = { 0, 0x0800, 0x1000, 0x1000, 0x1800, 0 },
710         .pll            = PLL_28,
711         .tuner_type     = -1,
712 },{
713         .name           = "Formac iProTV, Formac ProTV I (bt848)",
714         .video_inputs   = 4,
715         .audio_inputs   = 1,
716         .tuner          = 0,
717         .svhs           = 3,
718         .gpiomask       = 1,
719         .muxsel         = { 2, 3, 1, 1},
720         .audiomux       = { 1, 0, 0, 0, 0 },
721         .pll            = PLL_28,
722         .tuner_type     = TUNER_PHILIPS_PAL,
723 },{
724
725 /* ---- card 0x20 ---------------------------------- */
726         .name           = "Intel Create and Share PCI/ Smart Video Recorder III",
727         .video_inputs   = 4,
728         .audio_inputs   = 0,
729         .tuner          = -1,
730         .svhs           = 2,
731         .gpiomask       = 0,
732         .muxsel         = { 2, 3, 1, 1},
733         .audiomux       = { 0 },
734         .needs_tvaudio  = 0,
735         .tuner_type     = 4,
736 },{
737         .name           = "Terratec TerraTValue Version Bt878",
738         .video_inputs   = 3,
739         .audio_inputs   = 1,
740         .tuner          = 0,
741         .svhs           = 2,
742         .gpiomask       = 0xffff00,
743         .muxsel         = { 2, 3, 1, 1},
744         .audiomux       = { 0x500, 0, 0x300, 0x900, 0x900},
745         .needs_tvaudio  = 1,
746         .pll            = PLL_28,
747         .tuner_type     = TUNER_PHILIPS_PAL,
748 },{
749         .name           = "Leadtek WinFast 2000/ WinFast 2000 XP",
750         .video_inputs   = 4,
751         .audio_inputs   = 1,
752         .tuner          = 0,
753         .svhs           = 2,
754         .muxsel         = { 2, 3, 1, 1, 0}, // TV, CVid, SVid, CVid over SVid connector
755 #if 0
756         .gpiomask       = 0xc33000,
757         .audiomux       = { 0x422000,0x1000,0x0000,0x620000,0x800000 },
758 #else
759         /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
760         .gpiomask       = 0xb33000,
761         .audiomux       = { 0x122000,0x1000,0x0000,0x620000,0x800000 },
762 #endif
763         /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
764                 gpio23 -- hef4052:nEnable (0x800000)
765                 gpio12 -- hef4052:A1
766                 gpio13 -- hef4052:A0
767             0x0000: external audio
768             0x1000: FM
769             0x2000: TV
770             0x3000: n.c.
771           Note: There exists another variant "Winfast 2000" with tv stereo !?
772           Note: eeprom only contains FF and pci subsystem id 107d:6606
773          */
774         .needs_tvaudio  = 0,
775         .pll            = PLL_28,
776         .has_radio      = 1,
777         .tuner_type     = 5, // default for now, gpio reads BFFF06 for Pal bg+dk
778         .audio_hook     = winfast2000_audio,
779         .has_remote     = 1,
780 },{
781         .name           = "Lifeview FlyVideo 98 LR50 / Chronos Video Shuttle II",
782         .video_inputs   = 4,
783         .audio_inputs   = 3,
784         .tuner          = 0,
785         .svhs           = 2,
786         .gpiomask       = 0x1800,
787         .muxsel         = { 2, 3, 1, 1},
788         .audiomux       = { 0, 0x800, 0x1000, 0x1000, 0x1800},
789         .pll            = PLL_28,
790         .tuner_type     = -1,
791 },{
792
793 /* ---- card 0x24 ---------------------------------- */
794         .name           = "Lifeview FlyVideo 98FM LR50 / Typhoon TView TV/FM Tuner",
795         .video_inputs   = 4,
796         .audio_inputs   = 3,
797         .tuner          = 0,
798         .svhs           = 2,
799         .gpiomask       = 0x1800,
800         .muxsel         = { 2, 3, 1, 1},
801         .audiomux       = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 },
802         .pll            = PLL_28,
803         .tuner_type     = -1,
804         .has_radio      = 1,
805 },{
806         .name           = "Prolink PixelView PlayTV pro",
807         .video_inputs   = 3,
808         .audio_inputs   = 1,
809         .tuner          = 0,
810         .svhs           = 2,
811         .gpiomask       = 0xff,
812         .muxsel         = { 2, 3, 1, 1 },
813         .audiomux       = { 0x21, 0x20, 0x24, 0x2c, 0x29, 0x29 },
814         .no_msp34xx     = 1,
815         .pll            = PLL_28,
816         .tuner_type     = -1,
817 },{
818         .name           = "Askey CPH06X TView99",
819         .video_inputs   = 4,
820         .audio_inputs   = 1,
821         .tuner          = 0,
822         .svhs           = 2,
823         .gpiomask       = 0x551e00,
824         .muxsel         = { 2, 3, 1, 0},
825         .audiomux       = { 0x551400, 0x551200, 0, 0, 0x551c00, 0x551200 },
826         .needs_tvaudio  = 1,
827         .pll            = PLL_28,
828         .tuner_type     = 1,
829         .has_remote     = 1,
830 },{
831         .name           = "Pinnacle PCTV Studio/Rave",
832         .video_inputs   = 3,
833         .audio_inputs   = 1,
834         .tuner          = 0,
835         .svhs           = 2,
836         .gpiomask       = 0x03000F,
837         .muxsel         = { 2, 3, 1, 1},
838         .audiomux       = { 2, 0, 0, 0, 1},
839         .needs_tvaudio  = 0,
840         .pll            = PLL_28,
841         .tuner_type     = -1,
842 },{
843
844 /* ---- card 0x28 ---------------------------------- */
845         .name           = "STB TV PCI FM, Gateway P/N 6000704 (bt878), 3Dfx VoodooTV 100",
846         .video_inputs   = 3,
847         .audio_inputs   = 1,
848         .tuner          = 0,
849         .svhs           = 2,
850         .gpiomask       = 7,
851         .muxsel         = { 2, 3, 1, 1},
852         .audiomux       = { 4, 0, 2, 3, 1},
853         .no_msp34xx     = 1,
854         .needs_tvaudio  = 1,
855         .tuner_type     = TUNER_PHILIPS_NTSC,
856         .pll            = PLL_28,
857         .has_radio      = 1,
858 },{
859         .name           = "AVerMedia TVPhone 98",
860         .video_inputs   = 3,
861         .audio_inputs   = 4,
862         .tuner          = 0,
863         .svhs           = 2,
864         .gpiomask       = 15,
865         .muxsel         = { 2, 3, 1, 1},
866         .audiomux       = { 13, 4, 11, 7, 0, 0},
867         .needs_tvaudio  = 1,
868         .pll            = PLL_28,
869         .tuner_type     = -1,
870         .has_radio      = 1,
871         .audio_hook     = avermedia_tvphone_audio,
872 },{
873         .name           = "ProVideo PV951", /* pic16c54 */
874         .video_inputs   = 3,
875         .audio_inputs   = 1,
876         .tuner          = 0,
877         .svhs           = 2,
878         .gpiomask       = 0,
879         .muxsel         = { 2, 3, 1, 1},
880         .audiomux       = { 0, 0, 0, 0, 0},
881         .needs_tvaudio  = 1,
882         .no_msp34xx     = 1,
883         .pll            = PLL_28,
884         .tuner_type     = 1,
885 },{
886         .name           = "Little OnAir TV",
887         .video_inputs   = 3,
888         .audio_inputs   = 1,
889         .tuner          = 0,
890         .svhs           = 2,
891         .gpiomask       = 0xe00b,
892         .muxsel         = {2, 3, 1, 1},
893         .audiomux       = {0xff9ff6, 0xff9ff6, 0xff1ff7, 0, 0xff3ffc},
894         .no_msp34xx     = 1,
895         .tuner_type     = -1,
896 },{
897
898 /* ---- card 0x2c ---------------------------------- */
899         .name           = "Sigma TVII-FM",
900         .video_inputs   = 2,
901         .audio_inputs   = 1,
902         .tuner          = 0,
903         .svhs           = -1,
904         .gpiomask       = 3,
905         .muxsel         = {2, 3, 1, 1},
906         .audiomux       = {1, 1, 0, 2, 3},
907         .no_msp34xx     = 1,
908         .pll            = PLL_NONE,
909         .tuner_type     = -1,
910 },{
911         .name           = "MATRIX-Vision MV-Delta 2",
912         .video_inputs   = 5,
913         .audio_inputs   = 1,
914         .tuner          = -1,
915         .svhs           = 3,
916         .gpiomask       = 0,
917         .muxsel         = { 2, 3, 1, 0, 0},
918         .audiomux       = {0 },
919         .no_msp34xx     = 1,
920         .pll            = PLL_28,
921         .tuner_type     = -1,
922 },{
923         .name           = "Zoltrix Genie TV/FM",
924         .video_inputs   = 3,
925         .audio_inputs   = 1,
926         .tuner          = 0,
927         .svhs           = 2,
928         .gpiomask       = 0xbcf03f,
929         .muxsel         = { 2, 3, 1, 1},
930         .audiomux       = { 0xbc803f, 0xbc903f, 0xbcb03f, 0, 0xbcb03f},
931         .no_msp34xx     = 1,
932         .pll            = PLL_28,
933         .tuner_type     = 21,
934 },{
935         .name           = "Terratec TV/Radio+",
936         .video_inputs   = 3,
937         .audio_inputs   = 1,
938         .tuner          = 0,
939         .svhs           = 2,
940         .gpiomask       = 0x70000,
941         .muxsel         = { 2, 3, 1, 1},
942         .audiomux       = { 0x20000, 0x30000, 0x10000, 0, 0x40000, 0x20000 },
943         .needs_tvaudio  = 1,
944         .no_msp34xx     = 1,
945         .pll            = PLL_35,
946         .tuner_type     = 1,
947         .has_radio      = 1,
948 },{
949
950 /* ---- card 0x30 ---------------------------------- */
951         .name           = "Askey CPH03x/ Dynalink Magic TView",
952         .video_inputs   = 3,
953         .audio_inputs   = 1,
954         .tuner          = 0,
955         .svhs           = 2,
956         .gpiomask       = 15,
957         .muxsel         = { 2, 3, 1, 1},
958         .audiomux       = {2,0,0,0,1},
959         .needs_tvaudio  = 1,
960         .pll            = PLL_28,
961         .tuner_type     = -1,
962 },{
963         .name           = "IODATA GV-BCTV3/PCI",
964         .video_inputs   = 3,
965         .audio_inputs   = 1,
966         .tuner          = 0,
967         .svhs           = 2,
968         .gpiomask       = 0x010f00,
969         .muxsel         = {2, 3, 0, 0},
970         .audiomux       = {0x10000, 0, 0x10000, 0, 0, 0},
971         .no_msp34xx     = 1,
972         .pll            = PLL_28,
973         .tuner_type     = TUNER_ALPS_TSHC6_NTSC,
974         .audio_hook     = gvbctv3pci_audio,
975 },{
976         .name           = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP",
977         .video_inputs   = 5,
978         .audio_inputs   = 1,
979         .tuner          = 0,
980         .svhs           = 3,
981         .gpiomask       = 0xAA0000,
982         .muxsel         = { 2,3,1,1,-1 },
983         .digital_mode   = DIGITAL_MODE_CAMERA,
984         .audiomux       = { 0x20000, 0, 0x80000, 0x80000, 0xa8000, 0x46000  },
985         .no_msp34xx     = 1,
986         .pll            = PLL_28,
987         .tuner_type     = TUNER_PHILIPS_PAL_I,
988         .has_remote     = 1,
989         /* GPIO wiring: (different from Rev.4C !)
990                 GPIO17: U4.A0 (first hef4052bt)
991                 GPIO19: U4.A1
992                 GPIO20: U5.A1 (second hef4052bt)
993                 GPIO21: U4.nEN
994                 GPIO22: BT832 Reset Line
995                 GPIO23: A5,A0, U5,nEN
996            Note: At i2c=0x8a is a Bt832 chip, which changes to 0x88 after being reset via GPIO22
997          */
998 },{
999         .name           = "Eagle Wireless Capricorn2 (bt878A)",
1000         .video_inputs   = 4,
1001         .audio_inputs   = 1,
1002         .tuner          = 0,
1003         .svhs           = 2,
1004         .gpiomask       = 7,
1005         .muxsel         = { 2, 0, 1, 1},
1006         .audiomux       = { 0, 1, 2, 3, 4},
1007         .pll            = PLL_28,
1008         .tuner_type     = -1 /* TUNER_ALPS_TMDH2_NTSC */,
1009 },{
1010
1011 /* ---- card 0x34 ---------------------------------- */
1012         /* David Härdeman <david@2gen.com> */
1013         .name           = "Pinnacle PCTV Studio Pro",
1014         .video_inputs   = 4,
1015         .audio_inputs   = 1,
1016         .tuner          = 0,
1017         .svhs           = 3,
1018         .gpiomask       = 0x03000F,
1019         .muxsel         = { 2, 3, 1, 1},
1020         .audiomux       = { 1, 0xd0001, 0, 0, 10},
1021                         /* sound path (5 sources):
1022                            MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable)
1023                                 0= ext. Audio IN
1024                                 1= from MUX2
1025                                 2= Mono TV sound from Tuner
1026                                 3= not connected
1027                            MUX2 (mask 0x30000):
1028                                 0,2,3= from MSP34xx
1029                                 1= FM stereo Radio from Tuner */
1030         .needs_tvaudio  = 0,
1031         .pll            = PLL_28,
1032         .tuner_type     = -1,
1033 },{
1034         /* Claas Langbehn <claas@bigfoot.com>,
1035            Sven Grothklags <sven@upb.de> */
1036         .name           = "Typhoon TView RDS + FM Stereo / KNC1 TV Station RDS",
1037         .video_inputs   = 4,
1038         .audio_inputs   = 3,
1039         .tuner          = 0,
1040         .svhs           = 2,
1041         .gpiomask       = 0x1c,
1042         .muxsel         = { 2, 3, 1, 1},
1043         .audiomux       = { 0, 0, 0x10, 8, 4 },
1044         .needs_tvaudio  = 1,
1045         .pll            = PLL_28,
1046         .tuner_type     = TUNER_PHILIPS_PAL,
1047         .has_radio      = 1,
1048 },{
1049         /* Tim Röstermundt <rosterm@uni-muenster.de>
1050            in de.comp.os.unix.linux.hardware:
1051                 options bttv card=0 pll=1 radio=1 gpiomask=0x18e0
1052                 audiomux=0x44c71f,0x44d71f,0,0x44d71f,0x44dfff
1053                 options tuner type=5 */
1054         .name           = "Lifeview FlyVideo 2000 /FlyVideo A2/ Lifetec LT 9415 TV [LR90]",
1055         .video_inputs   = 4,
1056         .audio_inputs   = 1,
1057         .tuner          = 0,
1058         .svhs           = 2,
1059         .gpiomask       = 0x18e0,
1060         .muxsel         = { 2, 3, 1, 1},
1061         .audiomux       = { 0x0000,0x0800,0x1000,0x1000,0x18e0 },
1062                        /* For cards with tda9820/tda9821:
1063                           0x0000: Tuner normal stereo
1064                           0x0080: Tuner A2 SAP (second audio program = Zweikanalton)
1065                           0x0880: Tuner A2 stereo */
1066         .pll            = PLL_28,
1067         .tuner_type     = -1,
1068 },{
1069         /* Miguel Angel Alvarez <maacruz@navegalia.com>
1070            old Easy TV BT848 version (model CPH031) */
1071         .name           = "Askey CPH031/ BESTBUY Easy TV",
1072         .video_inputs   = 4,
1073         .audio_inputs   = 1,
1074         .tuner          = 0,
1075         .svhs           = 2,
1076         .gpiomask       = 0xF,
1077         .muxsel         = { 2, 3, 1, 0},
1078         .audiomux       = { 2, 0, 0, 0, 10},
1079         .needs_tvaudio  = 0,
1080         .pll            = PLL_28,
1081         .tuner_type     = TUNER_TEMIC_PAL,
1082 },{
1083
1084 /* ---- card 0x38 ---------------------------------- */
1085         /* Gordon Heydon <gjheydon@bigfoot.com ('98) */
1086         .name           = "Lifeview FlyVideo 98FM LR50",
1087         .video_inputs   = 4,
1088         .audio_inputs   = 3,
1089         .tuner          = 0,
1090         .svhs           = 2,
1091         .gpiomask       = 0x1800,
1092         .muxsel         = { 2, 3, 1, 1},
1093         .audiomux       = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 },
1094         .pll            = PLL_28,
1095         .tuner_type     = 5,
1096 },{
1097         /* This is the ultimate cheapo capture card 
1098          * just a BT848A on a small PCB!
1099          * Steve Hosgood <steve@equiinet.com> */
1100         .name           = "GrandTec 'Grand Video Capture' (Bt848)",
1101         .video_inputs   = 2,
1102         .audio_inputs   = 0,
1103         .tuner          = -1,
1104         .svhs           = 1,
1105         .gpiomask       = 0,
1106         .muxsel         = { 3, 1 },
1107         .audiomux       = { 0 },
1108         .needs_tvaudio  = 0,
1109         .no_msp34xx     = 1,
1110         .pll            = PLL_35,
1111         .tuner_type     = -1,
1112 },{
1113         /* Daniel Herrington <daniel.herrington@home.com> */
1114         .name           = "Askey CPH060/ Phoebe TV Master Only (No FM)",
1115         .video_inputs   = 3,
1116         .audio_inputs   = 1,
1117         .tuner          = 0,
1118         .svhs           = 2,
1119         .gpiomask       = 0xe00,
1120         .muxsel         = { 2, 3, 1, 1},
1121         .audiomux       = { 0x400, 0x400, 0x400, 0x400, 0x800, 0x400 },
1122         .needs_tvaudio  = 1,
1123         .pll            = PLL_28,
1124         .tuner_type     = TUNER_TEMIC_4036FY5_NTSC,
1125 },{
1126         /* Matti Mottus <mottus@physic.ut.ee> */
1127         .name           = "Askey CPH03x TV Capturer",
1128         .video_inputs   = 4,
1129         .audio_inputs   = 1,
1130         .tuner          = 0,
1131         .svhs           = 2,
1132         .gpiomask       = 0x03000F,
1133         .muxsel         = { 2, 3, 1, 0},
1134         .audiomux       = { 2,0,0,0,1 },
1135         .pll            = PLL_28,
1136         .tuner_type     = 0,
1137 },{
1138
1139 /* ---- card 0x3c ---------------------------------- */
1140         /* Philip Blundell <philb@gnu.org> */
1141         .name           = "Modular Technology MM100PCTV",
1142         .video_inputs   = 2,
1143         .audio_inputs   = 2,
1144         .tuner          = 0,
1145         .svhs           = -1,
1146         .gpiomask       = 11,
1147         .muxsel         = { 2, 3, 1, 1},
1148         .audiomux       = { 2, 0, 0, 1, 8},
1149         .pll            = PLL_35,
1150         .tuner_type     = TUNER_TEMIC_PAL,
1151
1152 },{
1153         /* Adrian Cox <adrian@humboldt.co.uk */
1154         .name           = "AG Electronics GMV1",
1155         .video_inputs   = 2,
1156         .audio_inputs   = 0,
1157         .tuner          = -1,
1158         .svhs           = 1,
1159         .gpiomask       = 0xF,
1160         .muxsel         = { 2, 2},
1161         .audiomux       = { },
1162         .no_msp34xx     = 1,
1163         .needs_tvaudio  = 0,
1164         .pll            = PLL_28,
1165         .tuner_type     = -1,
1166 },{
1167         /* Miguel Angel Alvarez <maacruz@navegalia.com>
1168            new Easy TV BT878 version (model CPH061) 
1169            special thanks to Informatica Mieres for providing the card */
1170         .name           = "Askey CPH061/ BESTBUY Easy TV (bt878)",
1171         .video_inputs   = 3,
1172         .audio_inputs   = 2,
1173         .tuner          = 0,
1174         .svhs           = 2,
1175         .gpiomask       = 0xFF,
1176         .muxsel         = { 2, 3, 1, 0},
1177         .audiomux       = { 1, 0, 4, 4, 9},
1178         .needs_tvaudio  = 0,
1179         .pll            = PLL_28,
1180         .tuner_type     = TUNER_PHILIPS_PAL,
1181 },{
1182         /* Lukas Gebauer <geby@volny.cz> */
1183         .name           = "ATI TV-Wonder",
1184         .video_inputs   = 3,
1185         .audio_inputs   = 1,
1186         .tuner          = 0,
1187         .svhs           = 2,
1188         .gpiomask       = 0xf03f,
1189         .muxsel         = { 2, 3, 1, 0 },
1190         .audiomux       = { 0xbffe, 0, 0xbfff, 0, 0xbffe},
1191         .pll            = PLL_28,
1192         .tuner_type     = TUNER_TEMIC_4006FN5_MULTI_PAL,
1193 },{
1194
1195 /* ---- card 0x40 ---------------------------------- */
1196         /* Lukas Gebauer <geby@volny.cz> */
1197         .name           = "ATI TV-Wonder VE",
1198         .video_inputs   = 2,
1199         .audio_inputs   = 1,
1200         .tuner          = 0,
1201         .svhs           = -1,
1202         .gpiomask       = 1,
1203         .muxsel         = { 2, 3, 0, 1},
1204         .audiomux       = { 0, 0, 1, 0, 0},
1205         .no_msp34xx     = 1,
1206         .pll            = PLL_28,
1207         .tuner_type     = TUNER_TEMIC_4006FN5_MULTI_PAL,
1208 },{
1209         /* DeeJay <deejay@westel900.net (2000S) */
1210         .name           = "Lifeview FlyVideo 2000S LR90",
1211         .video_inputs   = 3,
1212         .audio_inputs   = 3,
1213         .tuner          = 0,
1214         .svhs           = 2,
1215         .gpiomask       = 0x18e0,
1216         .muxsel         = { 2, 3, 0, 1},
1217                         /* Radio changed from 1e80 to 0x800 to make
1218                            FlyVideo2000S in .hu happy (gm)*/
1219                         /* -dk-???: set mute=0x1800 for tda9874h daughterboard */
1220         .audiomux       = { 0x0000,0x0800,0x1000,0x1000,0x1800, 0x1080 },
1221         .audio_hook     = fv2000s_audio,
1222         .no_msp34xx     = 1,
1223         .no_tda9875     = 1,
1224         .needs_tvaudio  = 1,
1225         .pll            = PLL_28,
1226         .tuner_type     = 5,
1227 },{
1228         .name           = "Terratec TValueRadio",
1229         .video_inputs   = 3,
1230         .audio_inputs   = 1,
1231         .tuner          = 0,
1232         .svhs           = 2,
1233         .gpiomask       = 0xffff00,
1234         .muxsel         = { 2, 3, 1, 1},
1235         .audiomux       = { 0x500, 0x500, 0x300, 0x900, 0x900},
1236         .needs_tvaudio  = 1,
1237         .pll            = PLL_28,
1238         .tuner_type     = TUNER_PHILIPS_PAL,
1239         .has_radio      = 1,
1240 },{
1241         /* TANAKA Kei <peg00625@nifty.com> */
1242         .name           = "IODATA GV-BCTV4/PCI",
1243         .video_inputs   = 3,
1244         .audio_inputs   = 1,
1245         .tuner          = 0,
1246         .svhs           = 2,
1247         .gpiomask       = 0x010f00,
1248         .muxsel         = {2, 3, 0, 0},
1249         .audiomux       = {0x10000, 0, 0x10000, 0, 0, 0},
1250         .no_msp34xx     = 1,
1251         .pll            = PLL_28,
1252         .tuner_type     = TUNER_SHARP_2U5JF5540_NTSC,
1253         .audio_hook     = gvbctv3pci_audio,
1254 },{
1255
1256 /* ---- card 0x44 ---------------------------------- */
1257         .name           = "3Dfx VoodooTV FM (Euro), VoodooTV 200 (USA)",
1258         // try "insmod msp3400 simple=0" if you have
1259         // sound problems with this card.
1260         .video_inputs   = 4,
1261         .audio_inputs   = 1,
1262         .tuner          = 0,
1263         .svhs           = -1,
1264         .gpiomask       = 0x4f8a00,
1265         // 0x100000: 1=MSP enabled (0=disable again)
1266         // 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC)
1267         .audiomux       = {0x947fff, 0x987fff,0x947fff,0x947fff, 0x947fff},
1268         // tvtuner, radio,   external,internal, mute,  stereo
1269         /* tuner, Composit, SVid, Composit-on-Svid-adapter*/
1270         .muxsel         = { 2, 3 ,0 ,1},
1271         .tuner_type     = TUNER_MT2032,
1272         .pll            = PLL_28,
1273         .has_radio      = 1,
1274 },{
1275         /* Philip Blundell <pb@nexus.co.uk> */
1276         .name           = "Active Imaging AIMMS",
1277         .video_inputs   = 1,
1278         .audio_inputs   = 0,
1279         .tuner          = -1,
1280         .tuner_type     = -1,
1281         .pll            = PLL_28,
1282         .muxsel         = { 2 },
1283         .gpiomask       = 0
1284 },{
1285         /* Tomasz Pyra <hellfire@sedez.iq.pl> */
1286         .name           = "Prolink Pixelview PV-BT878P+ (Rev.4C,8E)",
1287         .video_inputs   = 3,
1288         .audio_inputs   = 4,
1289         .tuner          = 0,
1290         .svhs           = 2,
1291         .gpiomask       = 15,
1292         .muxsel         = { 2, 3, 1, 1},
1293         .audiomux       = { 0, 0, 11, 7, 13, 0}, // TV and Radio with same GPIO !
1294         .needs_tvaudio  = 1,
1295         .pll            = PLL_28,
1296         .tuner_type     = 25,
1297         .has_remote     = 1,
1298         /* GPIO wiring:
1299                 GPIO0: U4.A0 (hef4052bt)
1300                 GPIO1: U4.A1
1301                 GPIO2: U4.A1 (second hef4052bt)
1302                 GPIO3: U4.nEN, U5.A0, A5.nEN
1303                 GPIO8-15: vrd866b ?
1304          */
1305 },{
1306         .name           = "Lifeview FlyVideo 98EZ (capture only) LR51",
1307         .video_inputs   = 4,
1308         .audio_inputs   = 0,
1309         .tuner          = -1,
1310         .svhs           = 2,
1311         .muxsel         = { 2, 3, 1, 1}, // AV1, AV2, SVHS, CVid adapter on SVHS
1312         .pll            = PLL_28,
1313         .no_msp34xx     = 1,
1314 },{
1315
1316 /* ---- card 0x48 ---------------------------------- */
1317         /* Dariusz Kowalewski <darekk@automex.pl> */
1318         .name           = "Prolink Pixelview PV-BT878P+9B (PlayTV Pro rev.9B FM+NICAM)",
1319         .video_inputs   = 4,
1320         .audio_inputs   = 1,
1321         .tuner          = 0,
1322         .svhs           = 2,
1323         .gpiomask       = 0x3f,
1324         .muxsel         = { 2, 3, 1, 1 },
1325         .audiomux       = { 0x01, 0x00, 0x03, 0x03, 0x09, 0x02 },
1326         .needs_tvaudio  = 1,
1327         .no_msp34xx     = 1,
1328         .no_tda9875     = 1,
1329         .pll            = PLL_28,
1330         .tuner_type     = 5,
1331         .audio_hook     = pvbt878p9b_audio, // Note: not all cards have stereo
1332         .has_radio      = 1,  // Note: not all cards have radio
1333         .has_remote     = 1,
1334         /* GPIO wiring:
1335                 GPIO0: A0 hef4052
1336                 GPIO1: A1 hef4052
1337                 GPIO3: nEN hef4052
1338                 GPIO8-15: vrd866b
1339                 GPIO20,22,23: R30,R29,R28
1340          */
1341 },{
1342         /* Clay Kunz <ckunz@mail.arc.nasa.gov> */
1343         /* you must jumper JP5 for the card to work */
1344         .name           = "Sensoray 311",
1345         .video_inputs   = 5,
1346         .audio_inputs   = 0,
1347         .tuner          = -1,
1348         .svhs           = 4,
1349         .gpiomask       = 0,
1350         .muxsel         = { 2, 3, 1, 0, 0},
1351         .audiomux       = { 0 },
1352         .needs_tvaudio  = 0,
1353         .tuner_type     = -1,
1354 },{
1355         /* Miguel Freitas <miguel@cetuc.puc-rio.br> */
1356         .name           = "RemoteVision MX (RV605)",
1357         .video_inputs   = 16,
1358         .audio_inputs   = 0,
1359         .tuner          = -1,
1360         .svhs           = -1,
1361         .gpiomask       = 0x00,
1362         .gpiomask2      = 0x07ff,
1363         .muxsel         = { 0x33, 0x13, 0x23, 0x43, 0xf3, 0x73, 0xe3, 0x03,
1364                           0xd3, 0xb3, 0xc3, 0x63, 0x93, 0x53, 0x83, 0xa3 },
1365         .no_msp34xx     = 1,
1366         .no_tda9875     = 1,
1367         .tuner_type     = -1,
1368         .muxsel_hook    = rv605_muxsel,
1369 },{
1370         .name           = "Powercolor MTV878/ MTV878R/ MTV878F",
1371         .video_inputs   = 3,
1372         .audio_inputs   = 2, 
1373         .tuner          = 0,
1374         .svhs           = 2,
1375         .gpiomask       = 0x1C800F,  // Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset
1376         .muxsel         = { 2, 1, 1, },
1377         .audiomux       = { 0, 1, 2, 2, 4 },
1378         .needs_tvaudio  = 0,
1379         .tuner_type     = TUNER_PHILIPS_PAL,
1380         .pll            = PLL_28,
1381         .has_radio      = 1,
1382 },{
1383
1384 /* ---- card 0x4c ---------------------------------- */
1385         /* Masaki Suzuki <masaki@btree.org> */
1386         .name           = "Canopus WinDVR PCI (COMPAQ Presario 3524JP, 5112JP)",
1387         .video_inputs   = 3,
1388         .audio_inputs   = 1,
1389         .tuner          = 0,
1390         .svhs           = 2,
1391         .gpiomask       = 0x140007,
1392         .muxsel         = { 2, 3, 1, 1 },
1393         .audiomux       = { 0, 1, 2, 3, 4, 0 },
1394         .tuner_type     = TUNER_PHILIPS_NTSC,
1395         .audio_hook     = windvr_audio,
1396 },{
1397         .name           = "GrandTec Multi Capture Card (Bt878)",
1398         .video_inputs   = 4,
1399         .audio_inputs   = 0,
1400         .tuner          = -1,
1401         .svhs           = -1,
1402         .gpiomask       = 0,
1403         .muxsel         = { 2, 3, 1, 0 },
1404         .audiomux       = { 0 },
1405         .needs_tvaudio  = 0,
1406         .no_msp34xx     = 1,
1407         .pll            = PLL_28,
1408         .tuner_type     = -1,
1409 },{
1410         .name           = "Jetway TV/Capture JW-TV878-FBK, Kworld KW-TV878RF",
1411         .video_inputs   = 4,
1412         .audio_inputs   = 3,
1413         .tuner          = 0,
1414         .svhs           = 2,
1415         .gpiomask       = 7,
1416         .muxsel         = { 2, 3, 1, 1 },   // Tuner, SVid, SVHS, SVid to SVHS connector
1417         .audiomux       = { 0 ,0 ,4, 4,4,4},// Yes, this tuner uses the same audio output for TV and FM radio!
1418                                           // This card lacks external Audio In, so we mute it on Ext. & Int.
1419                                           // The PCB can take a sbx1637/sbx1673, wiring unknown.
1420                                           // This card lacks PCI subsystem ID, sigh.
1421                                           // audiomux=1: lower volume, 2+3: mute
1422                                           // btwincap uses 0x80000/0x80003
1423         .needs_tvaudio  = 0,
1424         .no_msp34xx     = 1,
1425         .pll            = PLL_28,
1426         .tuner_type     = 5, // Samsung TCPA9095PC27A (BG+DK), philips compatible, w/FM, stereo and
1427                            // radio signal strength indicators work fine.
1428         .has_radio              = 1,
1429         /* GPIO Info:
1430                 GPIO0,1:   HEF4052 A0,A1
1431                 GPIO2:     HEF4052 nENABLE
1432                 GPIO3-7:   n.c.
1433                 GPIO8-13:  IRDC357 data0-5 (data6 n.c. ?) [chip not present on my card]
1434                 GPIO14,15: ??
1435                 GPIO16-21: n.c.
1436                 GPIO22,23: ??
1437                 ??       : mtu8b56ep microcontroller for IR (GPIO wiring unknown)*/
1438 },{
1439         /* Arthur Tetzlaff-Deas, DSP Design Ltd <software@dspdesign.com> */
1440         .name           = "DSP Design TCVIDEO",
1441         .video_inputs   = 4,
1442         .svhs           = -1,
1443         .muxsel         = { 2, 3, 1, 0},
1444         .pll            = PLL_28,
1445         .tuner_type     = -1,
1446 },{
1447
1448         /* ---- card 0x50 ---------------------------------- */
1449         .name           = "Hauppauge WinTV PVR",
1450         .video_inputs   = 4,
1451         .audio_inputs   = 1,
1452         .tuner          = 0,
1453         .svhs           = 2,
1454         .muxsel         = { 2, 0, 1, 1},
1455         .needs_tvaudio  = 1,
1456         .pll            = PLL_28,
1457         .tuner_type     = -1,
1458
1459         .gpiomask       = 7,
1460         .audiomux       = {7},
1461 },{
1462         .name           = "IODATA GV-BCTV5/PCI",
1463         .video_inputs   = 3,
1464         .audio_inputs   = 1,
1465         .tuner          = 0,
1466         .svhs           = 2,
1467         .gpiomask       = 0x0f0f80,
1468         .muxsel         = {2, 3, 1, 0},
1469         .audiomux       = {0x030000, 0x010000, 0, 0, 0x020000, 0},
1470         .no_msp34xx     = 1,
1471         .pll            = PLL_28,
1472         .tuner_type     = TUNER_PHILIPS_NTSC_M,
1473         .audio_hook     = gvbctv5pci_audio,
1474         .has_radio      = 1,
1475 },{
1476         .name           = "Osprey 100/150 (878)", /* 0x1(2|3)-45C6-C1 */
1477         .video_inputs   = 4,                  /* id-inputs-clock */
1478         .audio_inputs   = 0,
1479         .tuner          = -1,
1480         .svhs           = 3,
1481         .muxsel         = { 3, 2, 0, 1 },
1482         .pll            = PLL_28,
1483         .tuner_type     = -1,
1484         .no_msp34xx     = 1,
1485         .no_tda9875     = 1,
1486         .no_tda7432     = 1,
1487 },{
1488         .name           = "Osprey 100/150 (848)", /* 0x04-54C0-C1 & older boards */
1489         .video_inputs   = 3,
1490         .audio_inputs   = 0,
1491         .tuner          = -1,
1492         .svhs           = 2,
1493         .muxsel         = { 2, 3, 1 },
1494         .pll            = PLL_28,
1495         .tuner_type     = -1,
1496         .no_msp34xx     = 1,
1497         .no_tda9875     = 1,
1498         .no_tda7432     = 1,
1499 },{
1500
1501         /* ---- card 0x54 ---------------------------------- */
1502         .name           = "Osprey 101 (848)", /* 0x05-40C0-C1 */
1503         .video_inputs   = 2,
1504         .audio_inputs   = 0,
1505         .tuner          = -1,
1506         .svhs           = 1,
1507         .muxsel         = { 3, 1 },
1508         .pll            = PLL_28,
1509         .tuner_type     = -1,
1510         .no_msp34xx     = 1,
1511         .no_tda9875     = 1,
1512         .no_tda7432     = 1,
1513 },{
1514         .name           = "Osprey 101/151",       /* 0x1(4|5)-0004-C4 */
1515         .video_inputs   = 1,
1516         .audio_inputs   = 0,
1517         .tuner          = -1,
1518         .svhs           = -1,
1519         .muxsel         = { 0 },
1520         .pll            = PLL_28,
1521         .tuner_type     = -1,
1522         .no_msp34xx     = 1,
1523         .no_tda9875     = 1,
1524         .no_tda7432     = 1,
1525 },{
1526         .name           = "Osprey 101/151 w/ svid",  /* 0x(16|17|20)-00C4-C1 */
1527         .video_inputs   = 2,
1528         .audio_inputs   = 0,
1529         .tuner          = -1,
1530         .svhs           = 1,
1531         .muxsel         = { 0, 1 },
1532         .pll            = PLL_28,
1533         .tuner_type     = -1,
1534         .no_msp34xx     = 1,
1535         .no_tda9875     = 1,
1536         .no_tda7432     = 1,
1537 },{
1538         .name           = "Osprey 200/201/250/251",  /* 0x1(8|9|E|F)-0004-C4 */
1539         .video_inputs   = 1,
1540         .audio_inputs   = 1,
1541         .tuner          = -1,
1542         .svhs           = -1,
1543         .muxsel         = { 0 },
1544         .pll            = PLL_28,
1545         .tuner_type     = -1,
1546         .no_msp34xx     = 1,
1547         .no_tda9875     = 1,
1548         .no_tda7432     = 1,
1549 },{
1550         
1551         /* ---- card 0x58 ---------------------------------- */
1552         .name           = "Osprey 200/250",   /* 0x1(A|B)-00C4-C1 */
1553         .video_inputs   = 2,
1554         .audio_inputs   = 1,
1555         .tuner          = -1,
1556         .svhs           = 1,
1557         .muxsel         = { 0, 1 },
1558         .pll            = PLL_28,
1559         .tuner_type     = -1,
1560         .no_msp34xx     = 1,
1561         .no_tda9875     = 1,
1562         .no_tda7432     = 1,
1563 },{
1564         .name           = "Osprey 210/220",   /* 0x1(A|B)-04C0-C1 */
1565         .video_inputs   = 2,
1566         .audio_inputs   = 1,
1567         .tuner          = -1,
1568         .svhs           = 1,
1569         .muxsel         = { 2, 3 },
1570         .pll            = PLL_28,
1571         .tuner_type     = -1,
1572         .no_msp34xx     = 1,
1573         .no_tda9875     = 1,
1574         .no_tda7432     = 1,
1575 },{
1576         .name           = "Osprey 500",   /* 500 */
1577         .video_inputs   = 2,
1578         .audio_inputs   = 1,
1579         .tuner          = -1,
1580         .svhs           = 1,
1581         .muxsel         = { 2, 3 },
1582         .pll            = PLL_28,
1583         .tuner_type     = -1,
1584         .no_msp34xx     = 1,
1585         .no_tda9875     = 1,
1586         .no_tda7432     = 1,
1587 },{
1588        .name           = "Osprey 540",   /* 540 */
1589        .video_inputs   = 4,
1590        .audio_inputs   = 1,
1591        .tuner          = -1,
1592 #if 0 /* TODO ... */
1593        .svhs           = OSPREY540_SVID_ANALOG,
1594        .muxsel         = {       [OSPREY540_COMP_ANALOG] = 2,
1595                                [OSPREY540_SVID_ANALOG] = 3, },
1596 #endif
1597        .pll            = PLL_28,
1598        .tuner_type     = -1,
1599        .no_msp34xx     = 1,
1600        .no_tda9875     = 1,
1601        .no_tda7432     = 1,
1602 #if 0 /* TODO ... */
1603        .muxsel_hook    = osprey_540_muxsel,
1604        .picture_hook   = osprey_540_set_picture,
1605 #endif
1606 },{
1607
1608         /* ---- card 0x5C ---------------------------------- */
1609         .name           = "Osprey 2000",  /* 2000 */
1610         .video_inputs   = 2,
1611         .audio_inputs   = 1,
1612         .tuner          = -1,
1613         .svhs           = 1,
1614         .muxsel         = { 2, 3 },
1615         .pll            = PLL_28,
1616         .tuner_type     = -1,
1617         .no_msp34xx     = 1,
1618         .no_tda9875     = 1,
1619         .no_tda7432     = 1,      /* must avoid, conflicts with the bt860 */
1620 },{
1621         /* M G Berberich <berberic@forwiss.uni-passau.de> */
1622         .name           = "IDS Eagle",
1623         .video_inputs   = 4,
1624         .audio_inputs   = 0,
1625         .tuner          = -1,
1626         .tuner_type     = -1,
1627         .svhs           = -1,
1628         .gpiomask       = 0,
1629         .muxsel         = { 0, 1, 2, 3 },
1630         .muxsel_hook    = eagle_muxsel,
1631         .no_msp34xx     = 1,
1632         .no_tda9875     = 1,
1633         .pll            = PLL_28,
1634 },{
1635         .name           = "Pinnacle PCTV Sat",
1636         .video_inputs   = 2,
1637         .audio_inputs   = 0,
1638         .svhs           = 1,
1639         .tuner          = -1,
1640         .tuner_type     = -1,
1641         .no_msp34xx     = 1,
1642         .no_tda9875     = 1,
1643         .no_tda7432     = 1,   
1644         .gpiomask       = 0x01,
1645         .audiomux       = { 0, 0, 0, 0, 1 },
1646         .muxsel         = { 3, 0, 1, 2},
1647         .needs_tvaudio  = 0, 
1648         .pll            = PLL_28,
1649 },{
1650         .name           = "Formac ProTV II (bt878)",
1651         .video_inputs   = 4,
1652         .audio_inputs   = 1,
1653         .tuner          = 0,
1654         .svhs           = 3,
1655         .gpiomask       = 2,
1656         // TV, Comp1, Composite over SVID con, SVID
1657         .muxsel         = { 2, 3, 1, 1},
1658         .audiomux       = { 2, 2, 0, 0, 0 }, 
1659         .pll            = PLL_28,
1660         .has_radio      = 1,
1661         .tuner_type     = TUNER_PHILIPS_PAL,
1662       /* sound routing:
1663            GPIO=0x00,0x01,0x03: mute (?)
1664               0x02: both TV and radio (tuner: FM1216/I)
1665          The card has onboard audio connectors labeled "cdrom" and "board",
1666          not soldered here, though unknown wiring.
1667          Card lacks: external audio in, pci subsystem id.
1668        */
1669 },{
1670
1671         /* ---- card 0x60 ---------------------------------- */
1672         .name           = "MachTV",
1673         .video_inputs   = 3,
1674         .audio_inputs   = 1,
1675         .tuner          = 0,
1676         .svhs           = -1,
1677         .gpiomask       = 7,
1678         .muxsel         = { 2, 3, 1, 1},
1679         .audiomux       = { 0, 1, 2, 3, 4},
1680         .needs_tvaudio  = 1,
1681         .tuner_type     = 5,
1682         .pll            = 1,
1683 },{
1684         .name           = "Euresys Picolo",
1685         .video_inputs   = 3,
1686         .audio_inputs   = 0,
1687         .tuner          = -1,
1688         .svhs           = 2,
1689         .gpiomask       = 0,
1690         .no_msp34xx     = 1,
1691         .no_tda9875     = 1,
1692         .no_tda7432     = 1,
1693         .muxsel         = { 2, 0, 1},
1694         .pll            = PLL_28,
1695 },{
1696         /* Luc Van Hoeylandt <luc@e-magic.be> */
1697         .name           = "ProVideo PV150", /* 0x4f */
1698         .video_inputs   = 2,
1699         .audio_inputs   = 0,
1700         .tuner          = -1,
1701         .svhs           = -1,
1702         .gpiomask       = 0,
1703         .muxsel         = { 2, 3 },
1704         .audiomux       = { 0 },
1705         .needs_tvaudio  = 0,
1706         .no_msp34xx     = 1,
1707         .pll            = PLL_28,
1708         .tuner_type     = -1,
1709 },{
1710         /* Hiroshi Takekawa <sian@big.or.jp> */
1711         /* This card lacks subsystem ID */
1712         .name           = "AD-TVK503", /* 0x63 */
1713         .video_inputs   = 4,
1714         .audio_inputs   = 1,
1715         .tuner          = 0,
1716         .svhs           = 2,
1717         .gpiomask       = 0x001e8007,
1718         .muxsel         = { 2, 3, 1, 0 },
1719         /*                  Tuner, Radio, external, internal, off,  on */
1720         .audiomux       = { 0x08,  0x0f,  0x0a,     0x08,     0x0f, 0x08 },
1721         .needs_tvaudio  = 0,
1722         .no_msp34xx     = 1,
1723         .pll            = PLL_28,
1724         .tuner_type     = 2,
1725         .audio_hook     = adtvk503_audio,
1726 },{
1727
1728         /* ---- card 0x64 ---------------------------------- */
1729         .name           = "Hercules Smart TV Stereo",
1730         .video_inputs   = 4,
1731         .audio_inputs   = 1,
1732         .tuner          = 0,
1733         .svhs           = 2,
1734         .gpiomask       = 0x00,
1735         .muxsel         = { 2, 3, 1, 1 },
1736         .needs_tvaudio  = 1,
1737         .no_msp34xx     = 1,
1738         .pll            = PLL_28,
1739         .tuner_type     = 5,
1740         /* Notes:
1741            - card lacks subsystem ID
1742            - stereo variant w/ daughter board with tda9874a @0xb0
1743            - Audio Routing: 
1744                 always from tda9874 independent of GPIO (?)
1745                 external line in: unknown
1746            - Other chips: em78p156elp @ 0x96 (probably IR remote control)
1747                       hef4053 (instead 4052) for unknown function
1748         */
1749 },{
1750         .name           = "Pace TV & Radio Card",
1751         .video_inputs   = 4,
1752         .audio_inputs   = 1,
1753         .tuner          = 0,
1754         .svhs           = 2,
1755         .muxsel         = { 2, 3, 1, 1}, // Tuner, CVid, SVid, CVid over SVid connector
1756         .gpiomask       = 0,
1757         .no_tda9875     = 1,
1758         .no_tda7432     = 1,
1759         .tuner_type     = 1,
1760         .has_radio      = 1,
1761         .pll            = PLL_28,
1762         /* Bt878, Bt832, FI1246 tuner; no pci subsystem id
1763            only internal line out: (4pin header) RGGL
1764            Radio must be decoded by msp3410d (not routed through)*/
1765         //         .digital_mode   = DIGITAL_MODE_CAMERA, // todo!
1766 },{
1767         /* Chris Willing <chris@vislab.usyd.edu.au> */
1768         .name           = "IVC-200",
1769         .video_inputs   = 1,
1770         .audio_inputs   = 0,
1771         .tuner          = -1,
1772         .tuner_type     = -1,
1773         .svhs           = -1,
1774         .gpiomask       = 0xdf,
1775         .muxsel         = { 2 },
1776         .pll            = PLL_28,
1777 },{
1778         .name           = "Grand X-Guard / Trust 814PCI",
1779         .video_inputs   = 16,
1780         .audio_inputs   = 0,
1781         .tuner          = -1,
1782         .svhs           = -1,
1783         .tuner_type     = 4,
1784         .gpiomask2      = 0xff,
1785         .muxsel         = { 2,2,2,2, 3,3,3,3, 1,1,1,1, 0,0,0,0 },
1786         .muxsel_hook    = xguard_muxsel,
1787         .no_msp34xx     = 1,
1788         .no_tda9875     = 1,
1789         .no_tda7432     = 1,
1790         .pll            = PLL_28,
1791 },{
1792
1793         /* ---- card 0x68 ---------------------------------- */
1794         .name           = "Nebula Electronics DigiTV",
1795         .video_inputs   = 1,
1796         .tuner          = -1,
1797         .svhs           = -1,
1798         .muxsel         = { 2, 3, 1, 0},
1799         .no_msp34xx     = 1,
1800         .no_tda9875     = 1,
1801         .no_tda7432     = 1,
1802         .pll            = PLL_28,
1803         .tuner_type     = -1,
1804         .has_dvb        = 1,
1805         .no_gpioirq     = 1,
1806 },{
1807         /* Jorge Boncompte - DTI2 <jorge@dti2.net> */
1808         .name           = "ProVideo PV143",
1809         .video_inputs   = 4,
1810         .audio_inputs   = 0,
1811         .tuner          = -1,
1812         .svhs           = -1,
1813         .gpiomask       = 0,
1814         .muxsel         = { 2, 3, 1, 0 },
1815         .audiomux       = { 0 },
1816         .needs_tvaudio  = 0,
1817         .no_msp34xx     = 1,
1818         .pll            = PLL_28,
1819         .tuner_type     = -1,
1820 },{
1821         /* M.Klahr@phytec.de */
1822         .name           = "PHYTEC VD-009-X1 MiniDIN (bt878)",
1823         .video_inputs   = 4,
1824         .audio_inputs   = 0,
1825         .tuner          = -1, /* card has no tuner */
1826         .svhs           = 3,
1827         .gpiomask       = 0x00, 
1828         .muxsel         = { 2, 3, 1, 0},
1829         .audiomux       = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
1830         .needs_tvaudio  = 1,
1831         .pll            = PLL_28,
1832         .tuner_type     = -1,
1833 },{
1834         .name           = "PHYTEC VD-009-X1 Combi (bt878)",
1835         .video_inputs   = 4,
1836         .audio_inputs   = 0,
1837         .tuner          = -1, /* card has no tuner */
1838         .svhs           = 3,
1839         .gpiomask       = 0x00,
1840         .muxsel         = { 2, 3, 1, 1},
1841         .audiomux       = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
1842         .needs_tvaudio  = 1,
1843         .pll            = PLL_28,
1844         .tuner_type     = -1,
1845 },{
1846
1847         /* ---- card 0x6c ---------------------------------- */
1848         .name           = "PHYTEC VD-009 MiniDIN (bt878)",
1849         .video_inputs   = 10,
1850         .audio_inputs   = 0,
1851         .tuner          = -1, /* card has no tuner */
1852         .svhs           = 9,
1853         .gpiomask       = 0x00,
1854         .gpiomask2      = 0x03, /* gpiomask2 defines the bits used to switch audio
1855                                    via the upper nibble of muxsel. here: used for
1856                                    xternal video-mux */
1857         .muxsel         = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x00 },
1858         .audiomux       = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
1859         .needs_tvaudio  = 1,
1860         .pll            = PLL_28,
1861         .tuner_type     = -1,
1862 },{
1863         .name           = "PHYTEC VD-009 Combi (bt878)",
1864         .video_inputs   = 10,
1865         .audio_inputs   = 0,
1866         .tuner          = -1, /* card has no tuner */
1867         .svhs           = 9,
1868         .gpiomask       = 0x00,
1869         .gpiomask2      = 0x03, /* gpiomask2 defines the bits used to switch audio
1870                                    via the upper nibble of muxsel. here: used for
1871                                    xternal video-mux */
1872         .muxsel         = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x01 },
1873         .audiomux       = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
1874         .needs_tvaudio  = 1,
1875         .pll            = PLL_28,
1876         .tuner_type     = -1,
1877 },{
1878         .name           = "IVC-100",
1879         .video_inputs   = 4,
1880         .audio_inputs   = 0,
1881         .tuner          = -1,
1882         .tuner_type     = -1,
1883         .svhs           = -1,
1884         .gpiomask       = 0xdf,
1885         .muxsel         = { 2, 3, 1, 0 },
1886         .pll            = PLL_28,
1887 },{
1888         /* IVC-120G - Alan Garfield <alan@fromorbit.com> */
1889         .name           = "IVC-120G",
1890         .video_inputs   = 16,
1891         .audio_inputs   = 0,    /* card has no audio */
1892         .tuner          = -1,   /* card has no tuner */
1893         .tuner_type     = -1,
1894         .svhs           = -1,   /* card has no svhs */
1895         .needs_tvaudio  = 0,
1896         .no_msp34xx     = 1,
1897         .no_tda9875     = 1,
1898         .no_tda7432     = 1,
1899         .gpiomask       = 0x00,
1900         .muxsel         = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
1901                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 },
1902         .muxsel_hook    = ivc120_muxsel,
1903         .pll            = PLL_28,
1904 },{
1905
1906         /* ---- card 0x70 ---------------------------------- */
1907         .name           = "pcHDTV HD-2000 TV",
1908         .video_inputs   = 4,
1909         .audio_inputs   = 1,
1910         .tuner          = 0,
1911         .svhs           = 2,
1912         .muxsel         = { 2, 3, 1, 0},
1913         .tuner_type     = TUNER_PHILIPS_ATSC,
1914 },{
1915         .name           = "Twinhan DST + clones",
1916         .no_msp34xx     = 1,
1917         .no_tda9875     = 1,
1918         .no_tda7432     = 1,
1919         .tuner_type     = TUNER_ABSENT,
1920         .no_video       = 1,
1921         .has_dvb        = 1,
1922 },{
1923         .name           = "Winfast VC100",
1924         .video_inputs   = 3,
1925         .audio_inputs   = 0,
1926         .svhs           = 1,
1927         .tuner          = -1, // no tuner
1928         .muxsel         = { 3, 1, 1, 3}, // Vid In, SVid In, Vid over SVid in connector
1929         .no_msp34xx     = 1,
1930         .no_tda9875     = 1,
1931         .no_tda7432     = 1,
1932         .tuner_type     = TUNER_ABSENT,
1933         .no_video       = 1,
1934         .pll            = PLL_28,
1935 },{
1936         .name           = "Teppro TEV-560/InterVision IV-560",
1937         .video_inputs   = 3,
1938         .audio_inputs   = 1,
1939         .tuner          = 0,
1940         .svhs           = 2,
1941         .gpiomask       = 3,
1942         .muxsel         = { 2, 3, 1, 1},
1943         .audiomux       = { 1, 1, 1, 1, 0},
1944         .needs_tvaudio  = 1,
1945         .tuner_type     = TUNER_PHILIPS_PAL,
1946         .pll            = PLL_35,
1947 },{
1948
1949         /* ---- card 0x74 ---------------------------------- */
1950         .name           = "SIMUS GVC1100",
1951         .video_inputs   = 4,
1952         .audio_inputs   = 0,
1953         .tuner          = -1,
1954         .svhs           = -1,
1955         .tuner_type     = -1,
1956         .pll            = PLL_28,
1957         .muxsel         = { 2, 2, 2, 2},
1958         .gpiomask       = 0x3F,
1959         .muxsel_hook    = gvc1100_muxsel,
1960 },{
1961         /* Carlos Silva r3pek@r3pek.homelinux.org || card 0x75 */
1962         .name           = "NGS NGSTV+",
1963         .video_inputs   = 3,
1964         .tuner          = 0,
1965         .svhs           = 2,
1966         .gpiomask       = 0x008007,
1967         .muxsel         = {2, 3, 0, 0},
1968         .audiomux       = {0, 0, 0, 0, 0x000003, 0},
1969         .pll            = PLL_28,
1970         .tuner_type     = TUNER_PHILIPS_PAL,
1971         .has_remote     = 1,
1972 },{
1973         /* http://linuxmedialabs.com */
1974         .name           = "LMLBT4",
1975         .video_inputs   = 4, /* IN1,IN2,IN3,IN4 */
1976         .audio_inputs   = 0,
1977         .tuner          = -1,
1978         .svhs           = -1,
1979         .muxsel         = { 2, 3, 1, 0 },
1980         .no_msp34xx     = 1,
1981         .no_tda9875     = 1,
1982         .no_tda7432     = 1,
1983         .needs_tvaudio  = 0,
1984 },{
1985         /* Helmroos Harri <harri.helmroos@pp.inet.fi> */
1986         .name           = "Tekram M205 PRO",
1987         .video_inputs   = 3,
1988         .audio_inputs   = 1,
1989         .tuner          = 0,
1990         .tuner_type     = TUNER_PHILIPS_PAL,
1991         .svhs           = 2,
1992         .needs_tvaudio  = 0,
1993         .gpiomask       = 0x68,
1994         .muxsel         = { 2, 3, 1},
1995         .audiomux       = { 0x68, 0x68, 0x61, 0x61, 0x00 },
1996         .pll            = PLL_28,
1997 },{
1998
1999         /* ---- card 0x78 ---------------------------------- */
2000         /* Javier Cendan Ares <jcendan@lycos.es> */
2001         /* bt878 TV + FM without subsystem ID */
2002         .name           = "Conceptronic CONTVFMi",
2003         .video_inputs   = 3,
2004         .audio_inputs   = 1,
2005         .tuner          = 0,
2006         .svhs           = 2,
2007         .gpiomask       = 0x008007,
2008         .muxsel         = { 2, 3, 1, 1 },
2009         .audiomux       = { 0, 1, 2, 2, 3 },
2010         .needs_tvaudio  = 0,
2011         .pll            = PLL_28,
2012         .tuner_type     = TUNER_PHILIPS_PAL,
2013         .has_remote     = 1,
2014         .has_radio      = 1,
2015 }};
2016
2017 const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
2018
2019 /* ----------------------------------------------------------------------- */
2020
2021 static unsigned char eeprom_data[256];
2022
2023 /*
2024  * identify card
2025  */
2026 void __devinit bttv_idcard(struct bttv *btv)
2027 {
2028         unsigned int gpiobits;
2029         int i,type;
2030         unsigned short tmp;
2031
2032         /* read PCI subsystem ID */
2033         pci_read_config_word(btv->c.pci, PCI_SUBSYSTEM_ID, &tmp);
2034         btv->cardid = tmp << 16;
2035         pci_read_config_word(btv->c.pci, PCI_SUBSYSTEM_VENDOR_ID, &tmp);
2036         btv->cardid |= tmp;
2037
2038         if (0 != btv->cardid && 0xffffffff != btv->cardid) {
2039                 /* look for the card */
2040                 for (type = -1, i = 0; cards[i].id != 0; i++)
2041                         if (cards[i].id  == btv->cardid)
2042                                 type = i;
2043                 
2044                 if (type != -1) {
2045                         /* found it */
2046                         printk(KERN_INFO "bttv%d: detected: %s [card=%d], "
2047                                "PCI subsystem ID is %04x:%04x\n",
2048                                btv->c.nr,cards[type].name,cards[type].cardnr,
2049                                btv->cardid & 0xffff,
2050                                (btv->cardid >> 16) & 0xffff);
2051                         btv->c.type = cards[type].cardnr;
2052                 } else {
2053                         /* 404 */
2054                         printk(KERN_INFO "bttv%d: subsystem: %04x:%04x (UNKNOWN)\n",
2055                                btv->c.nr, btv->cardid & 0xffff,
2056                                (btv->cardid >> 16) & 0xffff);
2057                         printk(KERN_DEBUG "please mail id, board name and "
2058                                "the correct card= insmod option to kraxel@bytesex.org\n");
2059                 }
2060         } 
2061
2062         /* let the user override the autodetected type */
2063         if (card[btv->c.nr] < bttv_num_tvcards)
2064                 btv->c.type=card[btv->c.nr];
2065         
2066         /* print which card config we are using */
2067         printk(KERN_INFO "bttv%d: using: %s [card=%d,%s]\n",btv->c.nr,
2068                bttv_tvcards[btv->c.type].name, btv->c.type,
2069                card[btv->c.nr] < bttv_num_tvcards
2070                ? "insmod option" : "autodetected");
2071
2072         /* overwrite gpio stuff ?? */
2073         if (UNSET == audioall && UNSET == audiomux[0])
2074                 return;
2075
2076         if (UNSET != audiomux[0]) {
2077                 gpiobits = 0;
2078                 for (i = 0; i < 5; i++) {
2079                         bttv_tvcards[btv->c.type].audiomux[i] = audiomux[i];
2080                         gpiobits |= audiomux[i];
2081                 }
2082         } else {
2083                 gpiobits = audioall;
2084                 for (i = 0; i < 5; i++) {
2085                         bttv_tvcards[btv->c.type].audiomux[i] = audioall;
2086                 }
2087         }
2088         bttv_tvcards[btv->c.type].gpiomask = (UNSET != gpiomask) ? gpiomask : gpiobits;
2089         printk(KERN_INFO "bttv%d: gpio config override: mask=0x%x, mux=",
2090                btv->c.nr,bttv_tvcards[btv->c.type].gpiomask);
2091         for (i = 0; i < 5; i++) {
2092                 printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].audiomux[i]);
2093         }
2094         printk("\n");
2095 }
2096
2097 /*
2098  * (most) board specific initialisations goes here
2099  */
2100
2101 /* Some Modular Technology cards have an eeprom, but no subsystem ID */
2102 void identify_by_eeprom(struct bttv *btv, unsigned char eeprom_data[256])
2103 {
2104         int type = -1;
2105         
2106         if (0 == strncmp(eeprom_data,"GET MM20xPCTV",13))
2107                 type = BTTV_MODTEC_205;
2108         else if (0 == strncmp(eeprom_data+20,"Picolo",7))
2109                 type = BTTV_EURESYS_PICOLO;
2110         else if (eeprom_data[0] == 0x84 && eeprom_data[2]== 0)
2111                 type = BTTV_HAUPPAUGE; /* old bt848 */
2112
2113         if (-1 != type) {
2114                 btv->c.type = type;
2115                 printk("bttv%d: detected by eeprom: %s [card=%d]\n",
2116                        btv->c.nr, bttv_tvcards[btv->c.type].name, btv->c.type);
2117         }
2118 }
2119
2120 static void flyvideo_gpio(struct bttv *btv)
2121
2122         int gpio,has_remote,has_radio,is_capture_only,is_lr90,has_tda9820_tda9821;
2123         int tuner=-1,ttype;
2124
2125         gpio_inout(0xffffff, 0);
2126         udelay(8);  // without this we would see the 0x1800 mask
2127         gpio = gpio_read();
2128         /* FIXME: must restore OUR_EN ??? */
2129
2130         // all cards provide GPIO info, some have an additional eeprom
2131         // LR50: GPIO coding can be found lower right CP1 .. CP9
2132         //       CP9=GPIO23 .. CP1=GPIO15; when OPEN, the corresponding GPIO reads 1.
2133         //       GPIO14-12: n.c.
2134         // LR90: GP9=GPIO23 .. GP1=GPIO15 (right above the bt878)
2135         
2136         // lowest 3 bytes are remote control codes (no handshake needed)
2137         // xxxFFF: No remote control chip soldered
2138         // xxxF00(LR26/LR50), xxxFE0(LR90): Remote control chip (LVA001 or CF45) soldered 
2139         // Note: Some bits are Audio_Mask !
2140
2141         ttype=(gpio&0x0f0000)>>16;
2142         switch(ttype) {
2143         case 0x0: tuner=2; // NTSC, e.g. TPI8NSR11P
2144                 break;
2145         case 0x2: tuner=39;// LG NTSC (newer TAPC series) TAPC-H701P
2146                 break;
2147         case 0x4: tuner=5; // Philips PAL TPI8PSB02P, TPI8PSB12P, TPI8PSB12D or FI1216, FM1216
2148                 break;
2149         case 0x6: tuner=37; // LG PAL (newer TAPC series) TAPC-G702P
2150                 break;
2151         case 0xC: tuner=3; // Philips SECAM(+PAL) FQ1216ME or FI1216MF
2152                 break;
2153         default:
2154                 printk(KERN_INFO "bttv%d: FlyVideo_gpio: unknown tuner type.\n", btv->c.nr);
2155         }
2156
2157         has_remote          =   gpio & 0x800000;
2158         has_radio           =   gpio & 0x400000;
2159         //   unknown                   0x200000;
2160         //   unknown2                  0x100000;
2161         is_capture_only     = !(gpio & 0x008000); //GPIO15
2162         has_tda9820_tda9821 = !(gpio & 0x004000);
2163         is_lr90             = !(gpio & 0x002000); // else LR26/LR50 (LR38/LR51 f. capture only)
2164         //                      gpio & 0x001000 // output bit for audio routing
2165
2166         if(is_capture_only) 
2167                 tuner=4; // No tuner present 
2168
2169         printk(KERN_INFO "bttv%d: FlyVideo Radio=%s RemoteControl=%s Tuner=%d gpio=0x%06x\n", 
2170                btv->c.nr, has_radio? "yes":"no ", has_remote? "yes":"no ", tuner, gpio); 
2171         printk(KERN_INFO "bttv%d: FlyVideo  LR90=%s tda9821/tda9820=%s capture_only=%s\n",
2172                 btv->c.nr, is_lr90?"yes":"no ", has_tda9820_tda9821?"yes":"no ", 
2173                 is_capture_only?"yes":"no ");
2174
2175         if(tuner!= -1) // only set if known tuner autodetected, else let insmod option through
2176                 btv->tuner_type = tuner;
2177         btv->has_radio = has_radio;  
2178
2179         // LR90 Audio Routing is done by 2 hef4052, so Audio_Mask has 4 bits: 0x001c80
2180         // LR26/LR50 only has 1 hef4052, Audio_Mask 0x000c00
2181         // Audio options: from tuner, from tda9821/tda9821(mono,stereo,sap), from tda9874, ext., mute
2182         if(has_tda9820_tda9821) btv->audio_hook = lt9415_audio;
2183         //todo: if(has_tda9874) btv->audio_hook = fv2000s_audio;
2184 }
2185
2186 int miro_tunermap[] = { 0,6,2,3,   4,5,6,0,  3,0,4,5,  5,2,16,1,
2187                         14,2,17,1, 4,1,4,3,  1,2,16,1, 4,4,4,4 };
2188 int miro_fmtuner[]  = { 0,0,0,0,   0,0,0,0,  0,0,0,0,  0,0,0,1,
2189                         1,1,1,1,   1,1,1,0,  0,0,0,0,  0,1,0,0 };
2190
2191 static void miro_pinnacle_gpio(struct bttv *btv)
2192 {
2193         int id,msp,gpio;
2194         char *info;
2195
2196         gpio_inout(0xffffff, 0);
2197         gpio = gpio_read();
2198         id   = ((gpio>>10) & 63) -1;
2199         msp  = bttv_I2CRead(btv, I2C_MSP3400, "MSP34xx");
2200         if (id < 32) {
2201                 btv->tuner_type = miro_tunermap[id];
2202                 if (0 == (gpio & 0x20)) {
2203                         btv->has_radio = 1;
2204                         if (!miro_fmtuner[id]) {
2205                                 btv->has_matchbox = 1;
2206                                 btv->mbox_we    = (1<<6);
2207                                 btv->mbox_most  = (1<<7);
2208                                 btv->mbox_clk   = (1<<8);
2209                                 btv->mbox_data  = (1<<9);
2210                                 btv->mbox_mask  = (1<<6)|(1<<7)|(1<<8)|(1<<9);
2211                         }
2212                 } else {
2213                         btv->has_radio = 0;
2214                 }
2215                 if (-1 != msp) {
2216                         if (btv->c.type == BTTV_MIRO)
2217                                 btv->c.type = BTTV_MIROPRO;
2218                         if (btv->c.type == BTTV_PINNACLE)
2219                                 btv->c.type = BTTV_PINNACLEPRO;
2220                 }
2221                 printk(KERN_INFO
2222                        "bttv%d: miro: id=%d tuner=%d radio=%s stereo=%s\n",
2223                        btv->c.nr, id+1, btv->tuner_type,
2224                        !btv->has_radio ? "no" :
2225                        (btv->has_matchbox ? "matchbox" : "fmtuner"),
2226                        (-1 == msp) ? "no" : "yes");
2227         } else {
2228                 /* new cards with microtune tuner */
2229                 id = 63 - id;
2230                 btv->has_radio = 0;
2231                 switch (id) {
2232                 case 1:
2233                         info = "PAL / mono";
2234                         break;
2235                 case 2:
2236                         info = "PAL+SECAM / stereo";
2237                         btv->has_radio = 1;
2238                         break;
2239                 case 3:
2240                         info = "NTSC / stereo";
2241                         btv->has_radio = 1;
2242                         break;
2243                 case 4:
2244                         info = "PAL+SECAM / mono";
2245                         break;
2246                 case 5:
2247                         info = "NTSC / mono";
2248                         break;
2249                 case 6:
2250                         info = "NTSC / stereo";
2251                         break;
2252                 case 7:
2253                         info = "PAL / stereo";
2254                         break;
2255                 default:
2256                         info = "oops: unknown card";
2257                         break;
2258                 }
2259                 if (-1 != msp)
2260                         btv->c.type = BTTV_PINNACLEPRO;
2261                 printk(KERN_INFO
2262                        "bttv%d: pinnacle/mt: id=%d info=\"%s\" radio=%s\n",
2263                        btv->c.nr, id, info, btv->has_radio ? "yes" : "no");
2264                 btv->tuner_type  = 33;
2265                 btv->pinnacle_id = id;
2266         }
2267 }
2268
2269 /* GPIO21   L: Buffer aktiv, H: Buffer inaktiv */
2270 #define LM1882_SYNC_DRIVE     0x200000L
2271
2272 static void init_ids_eagle(struct bttv *btv)
2273 {
2274         gpio_inout(0xffffff,0xFFFF37);
2275         gpio_write(0x200020);
2276         
2277         /* flash strobe inverter ?! */
2278         gpio_write(0x200024);
2279         
2280         /* switch sync drive off */
2281         gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
2282         
2283         /* set BT848 muxel to 2 */
2284         btaor((2)<<5, ~(2<<5), BT848_IFORM);
2285 }
2286
2287 /* Muxsel helper for the IDS Eagle.
2288  * the eagles does not use the standard muxsel-bits but
2289  * has its own multiplexer */
2290 static void eagle_muxsel(struct bttv *btv, unsigned int input)
2291 {
2292         btaor((2)<<5, ~(3<<5), BT848_IFORM);
2293         gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]);
2294
2295 #if 0
2296        /* svhs */
2297        /* wake chroma ADC */
2298        btand(~BT848_ADC_C_SLEEP, BT848_ADC);
2299        /* set to YC video */
2300        btor(BT848_CONTROL_COMP, BT848_E_CONTROL);
2301        btor(BT848_CONTROL_COMP, BT848_O_CONTROL);
2302 #else
2303        /* composite */
2304        /* set chroma ADC to sleep */
2305        btor(BT848_ADC_C_SLEEP, BT848_ADC);
2306        /* set to composite video */
2307        btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
2308        btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
2309 #endif
2310
2311        /* switch sync drive off */
2312        gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
2313 }
2314
2315 static void gvc1100_muxsel(struct bttv *btv, unsigned int input)
2316 {
2317         static const int masks[] = {0x30, 0x01, 0x12, 0x23};
2318         gpio_write(masks[input%4]);
2319 }
2320
2321 /* LMLBT4x initialization - to allow access to GPIO bits for sensors input and
2322    alarms output
2323
2324    GPIObit    | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
2325    assignment | TI | O3|INx| O2| O1|IN4|IN3|IN2|IN1|   |   |
2326
2327    IN - sensor inputs, INx - sensor inputs and TI XORed together
2328    O1,O2,O3 - alarm outputs (relays)
2329
2330    OUT ENABLE   1    1   0  . 1  1   0   0 . 0   0   0    0   = 0x6C0
2331
2332 */
2333
2334 static void init_lmlbt4x(struct bttv *btv)
2335 {
2336         printk(KERN_DEBUG "LMLBT4x init\n");
2337         btwrite(0x000000, BT848_GPIO_REG_INP);
2338         gpio_inout(0xffffff, 0x0006C0);
2339         gpio_write(0x000000);
2340 }
2341
2342
2343 /* ----------------------------------------------------------------------- */
2344
2345 void bttv_reset_audio(struct bttv *btv)
2346 {
2347         /*
2348          * BT878A has a audio-reset register.
2349          * 1. This register is an audio reset function but it is in
2350          *    function-0 (video capture) address space.
2351          * 2. It is enough to do this once per power-up of the card.
2352          * 3. There is a typo in the Conexant doc -- it is not at
2353          *    0x5B, but at 0x058. (B is an odd-number, obviously a typo!).
2354          * --//Shrikumar 030609
2355          */
2356         if (btv->id != 878)
2357                 return;
2358         
2359         if (bttv_debug)
2360                 printk("bttv%d: BT878A ARESET\n",btv->c.nr);
2361         btwrite((1<<7), 0x058);
2362         udelay(10);
2363         btwrite(     0, 0x058);
2364 }
2365
2366 /* initialization part one -- before registering i2c bus */
2367 void __devinit bttv_init_card1(struct bttv *btv)
2368 {
2369         switch (btv->c.type) {
2370         case BTTV_HAUPPAUGE:
2371         case BTTV_HAUPPAUGE878:
2372                 boot_msp34xx(btv,5);
2373                 break;
2374         case BTTV_VOODOOTV_FM:
2375                 boot_msp34xx(btv,20);
2376                 break;
2377         case BTTV_AVERMEDIA98:
2378                 boot_msp34xx(btv,11);
2379                 break;
2380         case BTTV_HAUPPAUGEPVR:
2381                 pvr_boot(btv);
2382                 break;
2383         case BTTV_TWINHAN_DST:
2384                 btv->use_i2c_hw = 1;
2385                 break;
2386         }
2387 }
2388
2389 /* initialization part two -- after registering i2c bus */
2390 void __devinit bttv_init_card2(struct bttv *btv)
2391 {
2392         btv->tuner_type = -1;
2393
2394         if (BTTV_UNKNOWN == btv->c.type) {
2395                 bttv_readee(btv,eeprom_data,0xa0);
2396                 identify_by_eeprom(btv,eeprom_data);
2397         }
2398
2399         switch (btv->c.type) {
2400         case BTTV_MIRO:
2401         case BTTV_MIROPRO:
2402         case BTTV_PINNACLE:
2403         case BTTV_PINNACLEPRO: 
2404                 /* miro/pinnacle */
2405                 miro_pinnacle_gpio(btv);
2406                 break;
2407         case BTTV_FLYVIDEO_98:
2408         case BTTV_MAXI:
2409         case BTTV_LIFE_FLYKIT:
2410         case BTTV_FLYVIDEO:
2411         case BTTV_TYPHOON_TVIEW:
2412         case BTTV_CHRONOS_VS2:
2413         case BTTV_FLYVIDEO_98FM:
2414         case BTTV_FLYVIDEO2000:
2415         case BTTV_FLYVIDEO98EZ:
2416         case BTTV_CONFERENCETV:
2417         case BTTV_LIFETEC_9415:
2418                 flyvideo_gpio(btv);
2419                 break;
2420         case BTTV_HAUPPAUGE:
2421         case BTTV_HAUPPAUGE878:
2422         case BTTV_HAUPPAUGEPVR:
2423                 /* pick up some config infos from the eeprom */
2424                 bttv_readee(btv,eeprom_data,0xa0);
2425                 hauppauge_eeprom(btv);
2426                 break;
2427         case BTTV_AVERMEDIA98:
2428         case BTTV_AVPHONE98:
2429                 bttv_readee(btv,eeprom_data,0xa0);
2430                 avermedia_eeprom(btv);
2431                 break;
2432         case BTTV_PXC200:
2433                 init_PXC200(btv);
2434                 break;
2435         case BTTV_VHX:
2436                 btv->has_radio    = 1;
2437                 btv->has_matchbox = 1;
2438                 btv->mbox_we      = 0x20;
2439                 btv->mbox_most    = 0;
2440                 btv->mbox_clk     = 0x08;
2441                 btv->mbox_data    = 0x10;
2442                 btv->mbox_mask    = 0x38;
2443                 break;
2444         case BTTV_VOBIS_BOOSTAR:
2445         case BTTV_TERRATV:
2446                 terratec_active_radio_upgrade(btv);
2447                 break;
2448         case BTTV_MAGICTVIEW061:
2449                 if (btv->cardid == 0x3002144f) {
2450                         btv->has_radio=1;
2451                         printk("bttv%d: radio detected by subsystem id (CPH05x)\n",btv->c.nr);
2452                 }
2453                 break;
2454        case BTTV_STB2:
2455                 if (btv->cardid == 0x3060121a) {
2456                         /* Fix up entry for 3DFX VoodooTV 100,
2457                            which is an OEM STB card variant. */
2458                         btv->has_radio=0;
2459                         btv->tuner_type=TUNER_TEMIC_NTSC;
2460                 }
2461                 break;
2462         case BTTV_OSPREY1x0:
2463         case BTTV_OSPREY1x0_848:
2464         case BTTV_OSPREY101_848:
2465         case BTTV_OSPREY1x1:
2466         case BTTV_OSPREY1x1_SVID:
2467         case BTTV_OSPREY2xx:
2468         case BTTV_OSPREY2x0_SVID:
2469         case BTTV_OSPREY2x0:
2470         case BTTV_OSPREY500:
2471         case BTTV_OSPREY540:
2472         case BTTV_OSPREY2000:
2473                 bttv_readee(btv,eeprom_data,0xa0);
2474                 osprey_eeprom(btv);
2475                 break;
2476         case BTTV_IDS_EAGLE:
2477                 init_ids_eagle(btv);
2478                 break;
2479         case BTTV_MODTEC_205:
2480                 bttv_readee(btv,eeprom_data,0xa0);
2481                 modtec_eeprom(btv);
2482                 break;
2483         case BTTV_LMLBT4:
2484                 init_lmlbt4x(btv);
2485                 break;
2486         }
2487
2488         /* pll configuration */
2489         if (!(btv->id==848 && btv->revision==0x11)) {
2490                 /* defaults from card list */
2491                 if (PLL_28 == bttv_tvcards[btv->c.type].pll) {
2492                         btv->pll.pll_ifreq=28636363;
2493                         btv->pll.pll_crystal=BT848_IFORM_XT0;
2494                 }
2495                 if (PLL_35 == bttv_tvcards[btv->c.type].pll) {
2496                         btv->pll.pll_ifreq=35468950;
2497                         btv->pll.pll_crystal=BT848_IFORM_XT1;
2498                 }
2499                 /* insmod options can override */
2500                 switch (pll[btv->c.nr]) {
2501                 case 0: /* none */
2502                         btv->pll.pll_crystal = 0;
2503                         btv->pll.pll_ifreq   = 0;
2504                         btv->pll.pll_ofreq   = 0;
2505                         break;
2506                 case 1: /* 28 MHz */
2507                 case 28:
2508                         btv->pll.pll_ifreq   = 28636363;
2509                         btv->pll.pll_ofreq   = 0;
2510                         btv->pll.pll_crystal = BT848_IFORM_XT0;
2511                         break;
2512                 case 2: /* 35 MHz */
2513                 case 35:
2514                         btv->pll.pll_ifreq   = 35468950;
2515                         btv->pll.pll_ofreq   = 0;
2516                         btv->pll.pll_crystal = BT848_IFORM_XT1;
2517                         break;
2518                 }
2519         }
2520         btv->pll.pll_current = -1;
2521
2522         /* tuner configuration (from card list / autodetect / insmod option) */
2523         if (UNSET != bttv_tvcards[btv->c.type].tuner_type)
2524                 if(UNSET == btv->tuner_type) 
2525                         btv->tuner_type = bttv_tvcards[btv->c.type].tuner_type;
2526         if (UNSET != tuner[btv->c.nr])
2527                 btv->tuner_type = tuner[btv->c.nr];
2528         printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type);
2529         if (btv->pinnacle_id != UNSET)
2530                 bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE,
2531                                       &btv->pinnacle_id);
2532         if (btv->tuner_type != UNSET)
2533                 bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type);
2534         btv->svhs = bttv_tvcards[btv->c.type].svhs;
2535         if (svhs[btv->c.nr] != UNSET)
2536                 btv->svhs = svhs[btv->c.nr];
2537         if (remote[btv->c.nr] != UNSET)
2538                 btv->has_remote = remote[btv->c.nr];
2539
2540         if (bttv_tvcards[btv->c.type].has_radio)
2541                 btv->has_radio=1;
2542         if (bttv_tvcards[btv->c.type].has_remote)
2543                 btv->has_remote=1;
2544         if (bttv_tvcards[btv->c.type].no_gpioirq)
2545                 btv->gpioirq=0;
2546         if (bttv_tvcards[btv->c.type].audio_hook)
2547                 btv->audio_hook=bttv_tvcards[btv->c.type].audio_hook;
2548
2549         if (bttv_tvcards[btv->c.type].digital_mode == DIGITAL_MODE_CAMERA) {
2550                 /* detect Bt832 chip for quartzsight digital camera */
2551                 if ((bttv_I2CRead(btv, I2C_BT832_ALT1, "Bt832") >=0) ||
2552                     (bttv_I2CRead(btv, I2C_BT832_ALT2, "Bt832") >=0))
2553                         boot_bt832(btv);
2554         }
2555
2556         /* try to detect audio/fader chips */
2557         if (!bttv_tvcards[btv->c.type].no_msp34xx &&
2558             bttv_I2CRead(btv, I2C_MSP3400, "MSP34xx") >=0) {
2559                 if (autoload)
2560                         request_module("msp3400");
2561         }
2562
2563         if (bttv_tvcards[btv->c.type].msp34xx_alt &&
2564             bttv_I2CRead(btv, I2C_MSP3400_ALT, "MSP34xx (alternate address)") >=0) {
2565                 if (autoload)
2566                         request_module("msp3400");
2567         }
2568
2569         if (!bttv_tvcards[btv->c.type].no_tda9875 &&
2570             bttv_I2CRead(btv, I2C_TDA9875, "TDA9875") >=0) {
2571                 if (autoload)
2572                         request_module("tda9875");
2573         }
2574
2575         if (!bttv_tvcards[btv->c.type].no_tda7432 && 
2576             bttv_I2CRead(btv, I2C_TDA7432, "TDA7432") >=0) {
2577                 if (autoload)
2578                         request_module("tda7432");
2579         }
2580
2581         if (bttv_tvcards[btv->c.type].needs_tvaudio) {
2582                 if (autoload)
2583                         request_module("tvaudio");
2584         }
2585
2586         /* tuner modules */
2587         if (btv->pinnacle_id != UNSET) {
2588                 if (autoload)
2589                         request_module("tda9887");
2590         }
2591         if (btv->tuner_type != UNSET) {
2592                 if (autoload)
2593                         request_module("tuner");
2594         }
2595 }
2596
2597
2598 /* ----------------------------------------------------------------------- */
2599 /* some hauppauge specific stuff                                           */
2600
2601 static struct HAUPPAUGE_TUNER 
2602 {
2603         int  id;
2604         char *name;
2605
2606 hauppauge_tuner[] __devinitdata = 
2607 {
2608         { TUNER_ABSENT,        "" },
2609         { TUNER_ABSENT,        "External" },
2610         { TUNER_ABSENT,        "Unspecified" },
2611         { TUNER_PHILIPS_PAL,   "Philips FI1216" },
2612         { TUNER_PHILIPS_SECAM, "Philips FI1216MF" },
2613         { TUNER_PHILIPS_NTSC,  "Philips FI1236" },
2614         { TUNER_PHILIPS_PAL_I, "Philips FI1246" },
2615         { TUNER_PHILIPS_PAL_DK,"Philips FI1256" },
2616         { TUNER_PHILIPS_PAL,   "Philips FI1216 MK2" },
2617         { TUNER_PHILIPS_SECAM, "Philips FI1216MF MK2" },
2618         { TUNER_PHILIPS_NTSC,  "Philips FI1236 MK2" },
2619         { TUNER_PHILIPS_PAL_I, "Philips FI1246 MK2" },
2620         { TUNER_PHILIPS_PAL_DK,"Philips FI1256 MK2" },
2621         { TUNER_TEMIC_NTSC,    "Temic 4032FY5" },
2622         { TUNER_TEMIC_PAL,     "Temic 4002FH5" },
2623         { TUNER_TEMIC_PAL_I,   "Temic 4062FY5" },
2624         { TUNER_PHILIPS_PAL,   "Philips FR1216 MK2" },
2625         { TUNER_PHILIPS_SECAM, "Philips FR1216MF MK2" },
2626         { TUNER_PHILIPS_NTSC,  "Philips FR1236 MK2" },
2627         { TUNER_PHILIPS_PAL_I, "Philips FR1246 MK2" },
2628         { TUNER_PHILIPS_PAL_DK,"Philips FR1256 MK2" },
2629         { TUNER_PHILIPS_PAL,   "Philips FM1216" },
2630         { TUNER_PHILIPS_SECAM, "Philips FM1216MF" },
2631         { TUNER_PHILIPS_NTSC,  "Philips FM1236" },
2632         { TUNER_PHILIPS_PAL_I, "Philips FM1246" },
2633         { TUNER_PHILIPS_PAL_DK,"Philips FM1256" },
2634         { TUNER_TEMIC_4036FY5_NTSC, "Temic 4036FY5" },
2635         { TUNER_ABSENT,        "Samsung TCPN9082D" },
2636         { TUNER_ABSENT,        "Samsung TCPM9092P" },
2637         { TUNER_TEMIC_4006FH5_PAL, "Temic 4006FH5" },
2638         { TUNER_ABSENT,        "Samsung TCPN9085D" },
2639         { TUNER_ABSENT,        "Samsung TCPB9085P" },
2640         { TUNER_ABSENT,        "Samsung TCPL9091P" },
2641         { TUNER_TEMIC_4039FR5_NTSC, "Temic 4039FR5" },
2642         { TUNER_PHILIPS_FQ1216ME,   "Philips FQ1216 ME" },
2643         { TUNER_TEMIC_4066FY5_PAL_I, "Temic 4066FY5" },
2644         { TUNER_PHILIPS_NTSC,        "Philips TD1536" },
2645         { TUNER_PHILIPS_NTSC,        "Philips TD1536D" },
2646         { TUNER_PHILIPS_NTSC,  "Philips FMR1236" }, /* mono radio */
2647         { TUNER_ABSENT,        "Philips FI1256MP" },
2648         { TUNER_ABSENT,        "Samsung TCPQ9091P" },
2649         { TUNER_TEMIC_4006FN5_MULTI_PAL, "Temic 4006FN5" },
2650         { TUNER_TEMIC_4009FR5_PAL, "Temic 4009FR5" },
2651         { TUNER_TEMIC_4046FM5,     "Temic 4046FM5" },
2652         { TUNER_TEMIC_4009FN5_MULTI_PAL_FM, "Temic 4009FN5" },
2653         { TUNER_ABSENT,        "Philips TD1536D_FH_44"},
2654         { TUNER_LG_NTSC_FM,    "LG TPI8NSR01F"},
2655         { TUNER_LG_PAL_FM,     "LG TPI8PSB01D"},
2656         { TUNER_LG_PAL,        "LG TPI8PSB11D"},        
2657         { TUNER_LG_PAL_I_FM,   "LG TAPC-I001D"},
2658         { TUNER_LG_PAL_I,      "LG TAPC-I701D"}
2659 };
2660
2661 static void modtec_eeprom(struct bttv *btv)
2662 {
2663         if( strncmp(&(eeprom_data[0x1e]),"Temic 4066 FY5",14) ==0) {
2664                 btv->tuner_type=TUNER_TEMIC_4066FY5_PAL_I;
2665                 printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
2666                        btv->c.nr,&eeprom_data[0x1e]);
2667         } else if (strncmp(&(eeprom_data[0x1e]),"Alps TSBB5",10) ==0) {
2668                 btv->tuner_type=TUNER_ALPS_TSBB5_PAL_I;
2669                 printk("bttv%d: Modtec: Tuner autodetected by eeprom: %s\n",
2670                        btv->c.nr,&eeprom_data[0x1e]);
2671         } else {
2672                 printk("bttv%d: Modtec: Unknown TunerString: %s\n",
2673                        btv->c.nr,&eeprom_data[0x1e]);
2674         }
2675 }
2676
2677 static void __devinit hauppauge_eeprom(struct bttv *btv)
2678 {
2679         unsigned int blk2,tuner,radio,model;
2680
2681         if (eeprom_data[0] != 0x84 || eeprom_data[2] != 0)
2682                 printk(KERN_WARNING "bttv%d: Hauppauge eeprom: invalid\n",
2683                        btv->c.nr);
2684
2685         /* Block 2 starts after len+3 bytes header */
2686         blk2 = eeprom_data[1] + 3;
2687
2688         /* decode + use some config infos */
2689         model = eeprom_data[12] << 8 | eeprom_data[11];
2690         tuner = eeprom_data[9];
2691         radio = eeprom_data[blk2-1] & 0x01;
2692         
2693         if (tuner < ARRAY_SIZE(hauppauge_tuner))
2694                 btv->tuner_type = hauppauge_tuner[tuner].id;
2695         if (radio)
2696                 btv->has_radio = 1;
2697         
2698         if (bttv_verbose)
2699                 printk(KERN_INFO "bttv%d: Hauppauge eeprom: model=%d, "
2700                        "tuner=%s (%d), radio=%s\n",
2701                        btv->c.nr, model, hauppauge_tuner[tuner].name,
2702                        btv->tuner_type, radio ? "yes" : "no");
2703 }
2704
2705 static int terratec_active_radio_upgrade(struct bttv *btv)
2706 {
2707         int freq;
2708
2709         btv->has_radio    = 1;
2710         btv->has_matchbox = 1;
2711         btv->mbox_we      = 0x10;
2712         btv->mbox_most    = 0x20;
2713         btv->mbox_clk     = 0x08;
2714         btv->mbox_data    = 0x04;
2715         btv->mbox_mask    = 0x3c;
2716
2717         btv->mbox_iow     = 1 <<  8;
2718         btv->mbox_ior     = 1 <<  9;
2719         btv->mbox_csel    = 1 << 10;
2720
2721         freq=88000/62.5;
2722         tea5757_write(btv, 5 * freq + 0x358); // write 0x1ed8
2723         if (0x1ed8 == tea5757_read(btv)) {
2724                 printk("bttv%d: Terratec Active Radio Upgrade found.\n",
2725                        btv->c.nr);
2726                 btv->has_radio    = 1;
2727                 btv->has_matchbox = 1;
2728         } else {
2729                 btv->has_radio    = 0;
2730                 btv->has_matchbox = 0;
2731         }
2732         return 0;
2733 }       
2734
2735
2736 /* ----------------------------------------------------------------------- */
2737
2738 /*
2739  * minimal bootstrap for the WinTV/PVR -- upload altera firmware.
2740  *
2741  * The hcwamc.rbf firmware file is on the Hauppauge driver CD.  Have
2742  * a look at Pvr/pvr45xxx.EXE (self-extracting zip archive, can be
2743  * unpacked with unzip).
2744  */
2745 #define PVR_GPIO_DELAY          10
2746
2747 #define BTTV_ALT_DATA           0x000001
2748 #define BTTV_ALT_DCLK           0x100000
2749 #define BTTV_ALT_NCONFIG        0x800000
2750
2751 static int __devinit pvr_altera_load(struct bttv *btv, u8 *micro, u32 microlen)
2752 {
2753         u32 n;
2754         u8 bits;
2755         int i;
2756
2757         gpio_inout(0xffffff,BTTV_ALT_DATA|BTTV_ALT_DCLK|BTTV_ALT_NCONFIG);
2758         gpio_write(0);
2759         udelay(PVR_GPIO_DELAY);
2760         
2761         gpio_write(BTTV_ALT_NCONFIG);
2762         udelay(PVR_GPIO_DELAY);
2763
2764         for (n = 0; n < microlen; n++) {
2765                 bits = micro[n];
2766                 for ( i = 0 ; i < 8 ; i++ ) {
2767                         gpio_bits(BTTV_ALT_DCLK,0);
2768                         if (bits & 0x01)
2769                                 gpio_bits(BTTV_ALT_DATA,BTTV_ALT_DATA);
2770                         else 
2771                                 gpio_bits(BTTV_ALT_DATA,0);
2772                         gpio_bits(BTTV_ALT_DCLK,BTTV_ALT_DCLK);
2773                         bits >>= 1;
2774                 }
2775         }
2776         gpio_bits(BTTV_ALT_DCLK,0);
2777         udelay(PVR_GPIO_DELAY);
2778         
2779         /* begin Altera init loop (Not necessary,but doesn't hurt) */
2780         for (i = 0 ; i < 30 ; i++) {
2781                 gpio_bits(BTTV_ALT_DCLK,0);
2782                 gpio_bits(BTTV_ALT_DCLK,BTTV_ALT_DCLK);
2783         }
2784         gpio_bits(BTTV_ALT_DCLK,0);
2785         return 0;
2786 }
2787
2788 #ifndef CONFIG_FW_LOADER
2789 /* old 2.4.x way -- via soundcore's mod_firmware_load */
2790    
2791 static char *firm_altera = "/usr/lib/video4linux/hcwamc.rbf";
2792 MODULE_PARM(firm_altera,"s");
2793 MODULE_PARM_DESC(firm_altera,"WinTV/PVR firmware "
2794                  "(driver CD => unzip pvr45xxx.exe => hcwamc.rbf)");
2795
2796 extern int mod_firmware_load(const char *fn, char **fp);
2797
2798 int __devinit pvr_boot(struct bttv *btv)
2799 {
2800         u32 microlen;
2801         u8 *micro;
2802         int result;
2803
2804         microlen = mod_firmware_load(firm_altera, (char**) &micro);
2805         if (!microlen) {
2806                 printk(KERN_WARNING "bttv%d: altera firmware not found [%s]\n",
2807                        btv->c.nr, firm_altera);
2808                 return -1;
2809         }
2810         
2811         printk(KERN_INFO "bttv%d: uploading altera firmware [%s] ...\n",
2812                btv->c.nr, firm_altera);
2813         result = pvr_altera_load(btv, micro, microlen);
2814         printk(KERN_INFO "bttv%d: ... upload %s\n",
2815                btv->c.nr, (result < 0) ? "failed" : "ok");
2816         vfree(micro);
2817         return result;
2818 }
2819 #else
2820 /* new 2.5.x way -- via hotplug firmware loader */
2821
2822 int __devinit pvr_boot(struct bttv *btv)
2823 {
2824         const struct firmware *fw_entry;
2825         int rc;
2826
2827         rc = request_firmware(&fw_entry, "hcwamc.rbf", &btv->c.pci->dev);
2828         if (rc != 0) {
2829                 printk(KERN_WARNING "bttv%d: no altera firmware [via hotplug]\n",
2830                        btv->c.nr);
2831                 return rc;
2832         }
2833         rc = pvr_altera_load(btv, fw_entry->data, fw_entry->size);
2834         printk(KERN_INFO "bttv%d: altera firmware upload %s\n",
2835                btv->c.nr, (rc < 0) ? "failed" : "ok");
2836         release_firmware(fw_entry);
2837         return rc;
2838 }       
2839 #endif
2840
2841 /* ----------------------------------------------------------------------- */
2842 /* some osprey specific stuff                                              */
2843
2844 static void __devinit osprey_eeprom(struct bttv *btv)
2845 {
2846        int i = 0;
2847        unsigned char *ee = eeprom_data;
2848        unsigned long serial = 0;
2849     
2850        if (btv->c.type == 0) {
2851                /* this might be an antique... check for MMAC label in eeprom */
2852                if ((ee[0]=='M') && (ee[1]=='M') && (ee[2]=='A') && (ee[3]=='C')) {
2853                        unsigned char checksum = 0;
2854                        for (i =0; i<21; i++)
2855                                checksum += ee[i];
2856                        if (checksum != ee[21])
2857                                return;
2858                        btv->c.type = BTTV_OSPREY1x0_848;
2859                        for (i = 12; i < 21; i++)
2860                                serial *= 10, serial += ee[i] - '0';
2861                }
2862        } else {
2863                unsigned short type;
2864                int offset = 4*16;
2865         
2866                for(; offset < 8*16; offset += 16) {
2867                        unsigned short checksum = 0;
2868                        /* verify the checksum */
2869                        for(i = 0; i<14; i++) checksum += ee[i+offset];
2870                                checksum = ~checksum;  /* no idea why */
2871                                if ((((checksum>>8)&0x0FF) == ee[offset+14]) &&
2872                                    ((checksum & 0x0FF) == ee[offset+15])) {
2873                                break;
2874                        }
2875                }
2876         
2877                if (offset >= 8*16)
2878                        return;
2879
2880                /* found a valid descriptor */
2881                type = (ee[offset+4]<<8) | (ee[offset+5]);
2882                
2883                switch(type) {
2884
2885                /* 848 based */
2886                case 0x0004:
2887                        btv->c.type = BTTV_OSPREY1x0_848;
2888                        break;
2889                case 0x0005:
2890                        btv->c.type = BTTV_OSPREY101_848;
2891                        break;
2892                        
2893                /* 878 based */
2894                case 0x0012:
2895                case 0x0013:
2896                        btv->c.type = BTTV_OSPREY1x0;
2897                        break;
2898                case 0x0014:
2899                case 0x0015:
2900                        btv->c.type = BTTV_OSPREY1x1;
2901                        break;
2902                case 0x0016:
2903                case 0x0017:
2904                case 0x0020:
2905                        btv->c.type = BTTV_OSPREY1x1_SVID;
2906                        break;
2907                case 0x0018:
2908                case 0x0019:
2909                case 0x001E:
2910                case 0x001F:
2911                        btv->c.type = BTTV_OSPREY2xx;
2912                        break;
2913                case 0x001A:
2914                case 0x001B:
2915                        btv->c.type = BTTV_OSPREY2x0_SVID;
2916                        break;
2917                case 0x0040:
2918                        btv->c.type = BTTV_OSPREY500;
2919                        break;
2920                case 0x0050:
2921                case 0x0056:
2922                        btv->c.type = BTTV_OSPREY540;
2923                        /* bttv_osprey_540_init(btv); */
2924                        break;
2925                case 0x0060:
2926                case 0x0070:
2927                        btv->c.type = BTTV_OSPREY2x0;
2928                        //enable output on select control lines
2929                        gpio_inout(0xffffff,0x000303);
2930                        break;
2931                default:
2932                        /* unknown...leave generic, but get serial # */
2933                        break;
2934                }
2935                serial =  (ee[offset+6] << 24)
2936                        | (ee[offset+7] << 16)
2937                        | (ee[offset+8] <<  8)
2938                        | (ee[offset+9]);
2939        }
2940        
2941        printk(KERN_INFO "bttv%d: osprey eeprom: card=%d name=%s serial=%ld\n",
2942               btv->c.nr, btv->c.type, bttv_tvcards[btv->c.type].name,serial);
2943 }       
2944
2945 /* ----------------------------------------------------------------------- */
2946 /* AVermedia specific stuff, from  bktr_card.c                             */
2947
2948 int tuner_0_table[] = {
2949         TUNER_PHILIPS_NTSC,  TUNER_PHILIPS_PAL /* PAL-BG*/,
2950         TUNER_PHILIPS_PAL,   TUNER_PHILIPS_PAL /* PAL-I*/,
2951         TUNER_PHILIPS_PAL,   TUNER_PHILIPS_PAL,
2952         TUNER_PHILIPS_SECAM, TUNER_PHILIPS_SECAM,
2953         TUNER_PHILIPS_SECAM, TUNER_PHILIPS_PAL};
2954 #if 0
2955 int tuner_0_fm_table[] = {
2956         PHILIPS_FR1236_NTSC,  PHILIPS_FR1216_PAL,
2957         PHILIPS_FR1216_PAL,   PHILIPS_FR1216_PAL,
2958         PHILIPS_FR1216_PAL,   PHILIPS_FR1216_PAL,
2959         PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
2960         PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
2961 #endif
2962
2963 int tuner_1_table[] = {
2964         TUNER_TEMIC_NTSC,  TUNER_TEMIC_PAL,
2965         TUNER_TEMIC_PAL,   TUNER_TEMIC_PAL,
2966         TUNER_TEMIC_PAL,   TUNER_TEMIC_PAL,
2967         TUNER_TEMIC_4012FY5, TUNER_TEMIC_4012FY5, //TUNER_TEMIC_SECAM
2968         TUNER_TEMIC_4012FY5, TUNER_TEMIC_PAL};
2969
2970 static void __devinit avermedia_eeprom(struct bttv *btv)
2971 {
2972         int tuner_make,tuner_tv_fm,tuner_format,tuner=0;
2973
2974         tuner_make      = (eeprom_data[0x41] & 0x7);
2975         tuner_tv_fm     = (eeprom_data[0x41] & 0x18) >> 3;
2976         tuner_format    = (eeprom_data[0x42] & 0xf0) >> 4;
2977         btv->has_remote = (eeprom_data[0x42] & 0x01);
2978
2979         if (tuner_make == 0 || tuner_make == 2)
2980                 if(tuner_format <=9)
2981                         tuner = tuner_0_table[tuner_format];
2982         if (tuner_make == 1)
2983                 if(tuner_format <=9)
2984                         tuner = tuner_1_table[tuner_format];
2985         
2986         printk(KERN_INFO "bttv%d: Avermedia eeprom[0x%02x%02x]: tuner=",
2987                 btv->c.nr,eeprom_data[0x41],eeprom_data[0x42]);
2988         if(tuner) {
2989                 btv->tuner_type=tuner;
2990                 printk("%d",tuner);
2991         } else
2992                 printk("Unknown type");
2993         printk(" radio:%s remote control:%s\n",
2994                tuner_tv_fm     ? "yes" : "no",
2995                btv->has_remote ? "yes" : "no");
2996 }
2997
2998 /* used on Voodoo TV/FM (Voodoo 200), S0 wired to 0x10000 */
2999 void bttv_tda9880_setnorm(struct bttv *btv, int norm)
3000 {
3001         // fix up our card entry
3002         if(norm==VIDEO_MODE_NTSC) {
3003                 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[0]=0x957fff;
3004                 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[4]=0x957fff;
3005                 dprintk("bttv_tda9880_setnorm to NTSC\n");
3006         }
3007         else {
3008                 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[0]=0x947fff;
3009                 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[4]=0x947fff;
3010                 dprintk("bttv_tda9880_setnorm to PAL\n");
3011         }
3012         // set GPIO according
3013         gpio_bits(bttv_tvcards[btv->c.type].gpiomask,
3014                   bttv_tvcards[btv->c.type].audiomux[btv->audio]);
3015 }
3016
3017
3018 /*
3019  * reset/enable the MSP on some Hauppauge cards
3020  * Thanks to Kyösti Mälkki (kmalkki@cc.hut.fi)!
3021  *
3022  * Hauppauge:  pin  5
3023  * Voodoo:     pin 20
3024  */
3025 static void __devinit boot_msp34xx(struct bttv *btv, int pin)
3026 {
3027         int mask = (1 << pin);
3028
3029         gpio_inout(mask,mask);
3030         gpio_bits(mask,0);
3031         udelay(2500);
3032         gpio_bits(mask,mask);
3033
3034         if (bttv_gpio)
3035                 bttv_gpio_tracking(btv,"msp34xx");
3036         if (bttv_verbose)
3037                 printk(KERN_INFO "bttv%d: Hauppauge/Voodoo msp34xx: reset line "
3038                        "init [%d]\n", btv->c.nr, pin);
3039 }
3040
3041 static void __devinit boot_bt832(struct bttv *btv)
3042 {
3043         int resetbit=0;
3044
3045         switch (btv->c.type) {
3046         case BTTV_PXELVWPLTVPAK:
3047                 resetbit = 0x400000;
3048                 break;
3049         case BTTV_MODTEC_205:
3050                 resetbit = 1<<9;
3051                 break;
3052         default:
3053                 BUG();
3054         }
3055
3056         request_module("bt832");
3057         bttv_call_i2c_clients(btv, BT832_HEXDUMP, NULL);
3058
3059         printk("bttv%d: Reset Bt832 [line=0x%x]\n",btv->c.nr,resetbit);
3060         gpio_write(0);
3061         gpio_inout(resetbit, resetbit);
3062         udelay(5);
3063         gpio_bits(resetbit, resetbit);
3064         udelay(5);
3065         gpio_bits(resetbit, 0);
3066         udelay(5);
3067
3068         // bt832 on pixelview changes from i2c 0x8a to 0x88 after
3069         // being reset as above. So we must follow by this:
3070         bttv_call_i2c_clients(btv, BT832_REATTACH, NULL);
3071 }
3072
3073 /* ----------------------------------------------------------------------- */
3074 /*  Imagenation L-Model PXC200 Framegrabber */
3075 /*  This is basically the same procedure as 
3076  *  used by Alessandro Rubini in his pxc200 
3077  *  driver, but using BTTV functions */
3078
3079 static void __devinit init_PXC200(struct bttv *btv)
3080 {
3081         static int vals[] __devinitdata = { 0x08, 0x09, 0x0a, 0x0b, 0x0d, 0x0d,
3082                                             0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
3083                                             0x00 };
3084         unsigned int i;
3085         int tmp;
3086         u32 val;
3087         
3088         /* Initialise GPIO-connevted stuff */
3089         gpio_inout(0xffffff, (1<<13));
3090         gpio_write(0);
3091         udelay(3);
3092         gpio_write(1<<13);
3093         /* GPIO inputs are pulled up, so no need to drive 
3094          * reset pin any longer */
3095         gpio_bits(0xffffff, 0);
3096         if (bttv_gpio)
3097                 bttv_gpio_tracking(btv,"pxc200");
3098
3099         /*  we could/should try and reset/control the AD pots? but
3100             right now  we simply  turned off the crushing.  Without
3101             this the AGC drifts drifts
3102             remember the EN is reverse logic -->
3103             setting BT848_ADC_AGC_EN disable the AGC
3104             tboult@eecs.lehigh.edu
3105         */
3106
3107         btwrite(BT848_ADC_RESERVED|BT848_ADC_AGC_EN, BT848_ADC);
3108         
3109         /*      Initialise MAX517 DAC */
3110         printk(KERN_INFO "Setting DAC reference voltage level ...\n");
3111         bttv_I2CWrite(btv,0x5E,0,0x80,1);
3112         
3113         /*      Initialise 12C508 PIC */
3114         /*      The I2CWrite and I2CRead commmands are actually to the 
3115          *      same chips - but the R/W bit is included in the address
3116          *      argument so the numbers are different */
3117         
3118
3119         printk(KERN_INFO "Initialising 12C508 PIC chip ...\n");
3120
3121         /* First of all, enable the clock line. This is used in the PXC200-F */
3122         val = btread(BT848_GPIO_DMA_CTL);
3123         val |= BT848_GPIO_DMA_CTL_GPCLKMODE;
3124         btwrite(val, BT848_GPIO_DMA_CTL);
3125         
3126         /* Then, push to 0 the reset pin long enough to reset the *
3127          * device same as above for the reset line, but not the same
3128          * value sent to the GPIO-connected stuff
3129          * which one is the good one? */
3130         gpio_inout(0xffffff,(1<<2));
3131         gpio_write(0);
3132         udelay(10);
3133         gpio_write(1<<2);
3134
3135         for (i = 0; i < ARRAY_SIZE(vals); i++) {
3136                 tmp=bttv_I2CWrite(btv,0x1E,0,vals[i],1);
3137                 if (tmp != -1) {
3138                         printk(KERN_INFO
3139                                "I2C Write(%2.2x) = %i\nI2C Read () = %2.2x\n\n",
3140                                vals[i],tmp,bttv_I2CRead(btv,0x1F,NULL));
3141                 }
3142         }
3143
3144         printk(KERN_INFO "PXC200 Initialised.\n");
3145 }
3146
3147
3148 /* ----------------------------------------------------------------------- */
3149 /* Miro Pro radio stuff -- the tea5757 is connected to some GPIO ports     */
3150 /*
3151  * Copyright (c) 1999 Csaba Halasz <qgehali@uni-miskolc.hu>
3152  * This code is placed under the terms of the GNU General Public License
3153  *
3154  * Brutally hacked by Dan Sheridan <dan.sheridan@contact.org.uk> djs52 8/3/00
3155  */
3156
3157 void bus_low(struct bttv *btv, int bit)
3158 {
3159         if (btv->mbox_ior) {
3160                 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3161                           btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3162                 udelay(5);
3163         }
3164
3165         gpio_bits(bit,0);
3166         udelay(5);
3167
3168         if (btv->mbox_ior) {
3169                 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
3170                 udelay(5);
3171         }
3172 }
3173
3174 void bus_high(struct bttv *btv, int bit)
3175 {
3176         if (btv->mbox_ior) {
3177                 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3178                           btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3179                 udelay(5);
3180         }
3181
3182         gpio_bits(bit,bit);
3183         udelay(5);
3184
3185         if (btv->mbox_ior) {
3186                 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
3187                 udelay(5);
3188         }
3189 }
3190
3191 int bus_in(struct bttv *btv, int bit)
3192 {
3193         if (btv->mbox_ior) {
3194                 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3195                           btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3196                 udelay(5);
3197
3198                 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
3199                 udelay(5);
3200         }
3201         return gpio_read() & (bit);
3202 }
3203
3204 /* TEA5757 register bits */
3205 #define TEA_FREQ                0:14
3206 #define TEA_BUFFER              15:15
3207
3208 #define TEA_SIGNAL_STRENGTH     16:17
3209
3210 #define TEA_PORT1               18:18
3211 #define TEA_PORT0               19:19
3212
3213 #define TEA_BAND                20:21
3214 #define TEA_BAND_FM             0
3215 #define TEA_BAND_MW             1
3216 #define TEA_BAND_LW             2
3217 #define TEA_BAND_SW             3
3218
3219 #define TEA_MONO                22:22
3220 #define TEA_ALLOW_STEREO        0
3221 #define TEA_FORCE_MONO          1
3222
3223 #define TEA_SEARCH_DIRECTION    23:23
3224 #define TEA_SEARCH_DOWN         0
3225 #define TEA_SEARCH_UP           1
3226
3227 #define TEA_STATUS              24:24
3228 #define TEA_STATUS_TUNED        0
3229 #define TEA_STATUS_SEARCHING    1
3230
3231 /* Low-level stuff */
3232 static int tea5757_read(struct bttv *btv)
3233 {
3234         unsigned long timeout;
3235         int value = 0;
3236         int i;
3237         
3238         /* better safe than sorry */
3239         gpio_inout(btv->mbox_mask, btv->mbox_clk | btv->mbox_we);
3240
3241         if (btv->mbox_ior) {
3242                 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3243                           btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3244                 udelay(5);
3245         }
3246
3247         if (bttv_gpio)
3248                 bttv_gpio_tracking(btv,"tea5757 read");
3249         
3250         bus_low(btv,btv->mbox_we);
3251         bus_low(btv,btv->mbox_clk);
3252         
3253         udelay(10);
3254         timeout= jiffies + HZ;
3255
3256         // wait for DATA line to go low; error if it doesn't
3257         while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout))
3258                 schedule();
3259         if (bus_in(btv,btv->mbox_data)) {
3260                 printk(KERN_WARNING "bttv%d: tea5757: read timeout\n",btv->c.nr);
3261                 return -1;
3262         }
3263
3264         dprintk("bttv%d: tea5757:",btv->c.nr);
3265         for(i = 0; i < 24; i++)
3266         {
3267                 udelay(5);
3268                 bus_high(btv,btv->mbox_clk);
3269                 udelay(5);
3270                 dprintk("%c",(bus_in(btv,btv->mbox_most) == 0)?'T':'-');
3271                 bus_low(btv,btv->mbox_clk);
3272                 value <<= 1;
3273                 value |= (bus_in(btv,btv->mbox_data) == 0)?0:1;  /* MSB first */
3274                 dprintk("%c", (bus_in(btv,btv->mbox_most) == 0)?'S':'M');
3275         }
3276         dprintk("\nbttv%d: tea5757: read 0x%X\n", btv->c.nr, value);
3277         return value;
3278 }
3279
3280 static int tea5757_write(struct bttv *btv, int value)
3281 {
3282         int i;
3283         int reg = value;
3284         
3285         gpio_inout(btv->mbox_mask, btv->mbox_clk | btv->mbox_we | btv->mbox_data);
3286
3287         if (btv->mbox_ior) {
3288                 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3289                           btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3290                 udelay(5);
3291         }
3292         if (bttv_gpio)
3293                 bttv_gpio_tracking(btv,"tea5757 write");
3294
3295         dprintk("bttv%d: tea5757: write 0x%X\n", btv->c.nr, value);
3296         bus_low(btv,btv->mbox_clk);
3297         bus_high(btv,btv->mbox_we);
3298         for(i = 0; i < 25; i++)
3299         {
3300                 if (reg & 0x1000000)
3301                         bus_high(btv,btv->mbox_data);
3302                 else
3303                         bus_low(btv,btv->mbox_data);
3304                 reg <<= 1;
3305                 bus_high(btv,btv->mbox_clk);
3306                 udelay(10);
3307                 bus_low(btv,btv->mbox_clk);
3308                 udelay(10);
3309         }
3310         bus_low(btv,btv->mbox_we);  /* unmute !!! */
3311         return 0;
3312 }
3313
3314 void tea5757_set_freq(struct bttv *btv, unsigned short freq)
3315 {
3316         dprintk("tea5757_set_freq %d\n",freq);
3317         tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */
3318 #if 0
3319         /* breaks Miro PCTV */
3320         value = tea5757_read(btv);
3321         dprintk("bttv%d: tea5757 readback=0x%x\n",btv->c.nr,value);
3322 #endif
3323 }
3324
3325
3326 /* ----------------------------------------------------------------------- */
3327 /* winview                                                                 */
3328
3329 void winview_audio(struct bttv *btv, struct video_audio *v, int set)
3330 {
3331         /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
3332         int bits_out, loops, vol, data;
3333
3334         if (!set) {
3335                 /* Fixed by Leandro Lucarella <luca@linuxmendoza.org.ar (07/31/01) */
3336                 v->flags |= VIDEO_AUDIO_VOLUME;
3337                 return;
3338         }
3339         
3340         /* 32 levels logarithmic */
3341         vol = 32 - ((v->volume>>11));
3342         /* units */
3343         bits_out = (PT2254_DBS_IN_2>>(vol%5));
3344         /* tens */
3345         bits_out |= (PT2254_DBS_IN_10>>(vol/5));
3346         bits_out |= PT2254_L_CHANNEL | PT2254_R_CHANNEL;
3347         data = gpio_read();
3348         data &= ~(WINVIEW_PT2254_CLK| WINVIEW_PT2254_DATA|
3349                   WINVIEW_PT2254_STROBE);
3350         for (loops = 17; loops >= 0 ; loops--) {
3351                 if (bits_out & (1<<loops))
3352                         data |=  WINVIEW_PT2254_DATA;
3353                 else
3354                         data &= ~WINVIEW_PT2254_DATA;
3355                 gpio_write(data);
3356                 udelay(5);
3357                 data |= WINVIEW_PT2254_CLK;
3358                 gpio_write(data);
3359                 udelay(5);
3360                 data &= ~WINVIEW_PT2254_CLK;
3361                 gpio_write(data);
3362         }
3363         data |=  WINVIEW_PT2254_STROBE;
3364         data &= ~WINVIEW_PT2254_DATA;
3365         gpio_write(data);
3366         udelay(10);                     
3367         data &= ~WINVIEW_PT2254_STROBE;
3368         gpio_write(data);
3369 }
3370
3371 /* ----------------------------------------------------------------------- */
3372 /* mono/stereo control for various cards (which don't use i2c chips but    */
3373 /* connect something to the GPIO pins                                      */
3374
3375 static void
3376 gvbctv3pci_audio(struct bttv *btv, struct video_audio *v, int set)
3377 {
3378         unsigned int con = 0;
3379
3380         if (set) {
3381                 gpio_inout(0x300, 0x300);
3382                 if (v->mode & VIDEO_SOUND_LANG1)
3383                         con = 0x000;
3384                 if (v->mode & VIDEO_SOUND_LANG2)
3385                         con = 0x300;
3386                 if (v->mode & VIDEO_SOUND_STEREO)
3387                         con = 0x200;
3388 //              if (v->mode & VIDEO_SOUND_MONO)
3389 //                      con = 0x100;
3390                 gpio_bits(0x300, con);
3391         } else {
3392                 v->mode = VIDEO_SOUND_STEREO |
3393                           VIDEO_SOUND_LANG1  | VIDEO_SOUND_LANG2;
3394         }
3395 }
3396
3397 static void
3398 gvbctv5pci_audio(struct bttv *btv, struct video_audio *v, int set)
3399 {
3400         unsigned int val, con;
3401
3402 #if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3403         if (btv->radio_user)
3404                 return;
3405 #else
3406         if (btv->radio)
3407                 return;
3408 #endif
3409
3410         val = gpio_read();
3411         if (set) {
3412                 con = 0x000;
3413                 if (v->mode & VIDEO_SOUND_LANG2) {
3414                         if (v->mode & VIDEO_SOUND_LANG1) {
3415                                 /* LANG1 + LANG2 */
3416                                 con = 0x100;
3417                         }
3418                         else {
3419                                 /* LANG2 */
3420                                 con = 0x300;
3421                         }
3422                 }
3423                 if (con != (val & 0x300)) {
3424                         gpio_bits(0x300, con);
3425                         if (bttv_gpio)
3426                                 bttv_gpio_tracking(btv,"gvbctv5pci");
3427                 }
3428         } else {
3429                 switch (val & 0x70) {
3430                   case 0x10:
3431                         v->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3432                         break;
3433                   case 0x30:
3434                         v->mode = VIDEO_SOUND_LANG2;
3435                         break;
3436                   case 0x50:
3437                         v->mode = VIDEO_SOUND_LANG1;
3438                         break;
3439                   case 0x60:
3440                         v->mode = VIDEO_SOUND_STEREO;
3441                         break;
3442                   case 0x70:
3443                         v->mode = VIDEO_SOUND_MONO;
3444                         break;
3445                   default:
3446                         v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3447                                   VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3448                 }
3449         }
3450 }
3451
3452 /*
3453  * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
3454  *  I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
3455  *  0xdde enables mono and 0xccd enables sap
3456  *
3457  * Petr Vandrovec <VANDROVE@vc.cvut.cz>
3458  *  P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
3459  *  input/output sound connection, so both must be set for output mode.
3460  *
3461  * Looks like it's needed only for the "tvphone", the "tvphone 98"
3462  * handles this with a tda9840
3463  *
3464  */
3465 static void
3466 avermedia_tvphone_audio(struct bttv *btv, struct video_audio *v, int set)
3467 {
3468         int val = 0;
3469
3470         if (set) {
3471                 if (v->mode & VIDEO_SOUND_LANG2)   /* SAP */
3472                         val = 0x02;
3473                 if (v->mode & VIDEO_SOUND_STEREO)
3474                         val = 0x01;
3475                 if (val) {
3476                         gpio_bits(0x03,val);
3477                         if (bttv_gpio)
3478                                 bttv_gpio_tracking(btv,"avermedia");
3479                 }
3480         } else {
3481                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3482                         VIDEO_SOUND_LANG1;
3483                 return;
3484         }
3485 }
3486
3487 static void
3488 avermedia_tv_stereo_audio(struct bttv *btv, struct video_audio *v, int set)
3489 {
3490         int val = 0;
3491         
3492         if (set) {
3493                 if (v->mode & VIDEO_SOUND_LANG2)   /* SAP */
3494                         val = 0x01;
3495                 if (v->mode & VIDEO_SOUND_STEREO)  /* STEREO */
3496                         val = 0x02;
3497                 btaor(val, ~0x03, BT848_GPIO_DATA);
3498                 if (bttv_gpio)
3499                         bttv_gpio_tracking(btv,"avermedia");
3500         } else {
3501                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3502                         VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3503                 return;
3504         }
3505 }
3506
3507 /* Lifetec 9415 handling */
3508 static void
3509 lt9415_audio(struct bttv *btv, struct video_audio *v, int set)
3510 {
3511         int val = 0;
3512
3513         if (gpio_read() & 0x4000) {
3514                 v->mode = VIDEO_SOUND_MONO;
3515                 return;
3516         }
3517
3518         if (set) {
3519                 if (v->mode & VIDEO_SOUND_LANG2)  /* A2 SAP */
3520                         val = 0x0080;
3521                 if (v->mode & VIDEO_SOUND_STEREO) /* A2 stereo */
3522                         val = 0x0880;
3523                 if ((v->mode & VIDEO_SOUND_LANG1) ||
3524                     (v->mode & VIDEO_SOUND_MONO))
3525                         val = 0;
3526                 gpio_bits(0x0880, val);
3527                 if (bttv_gpio)
3528                         bttv_gpio_tracking(btv,"lt9415");
3529         } else {
3530                 /* autodetect doesn't work with this card :-( */
3531                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3532                         VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3533                 return;
3534         }
3535 }
3536
3537 // TDA9821 on TerraTV+ Bt848, Bt878
3538 static void
3539 terratv_audio(struct bttv *btv, struct video_audio *v, int set)
3540 {
3541         unsigned int con = 0;
3542
3543         if (set) {
3544                 gpio_inout(0x180000,0x180000);
3545                 if (v->mode & VIDEO_SOUND_LANG2)
3546                         con = 0x080000;
3547                 if (v->mode & VIDEO_SOUND_STEREO)
3548                         con = 0x180000;
3549                 gpio_bits(0x180000, con);
3550                 if (bttv_gpio)
3551                         bttv_gpio_tracking(btv,"terratv");
3552         } else {
3553                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3554                         VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3555         }
3556 }
3557
3558 static void
3559 winfast2000_audio(struct bttv *btv, struct video_audio *v, int set)
3560 {
3561         unsigned long val = 0;
3562
3563         if (set) {
3564                 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
3565                 if (v->mode & VIDEO_SOUND_MONO)         /* Mono */
3566                         val = 0x420000;
3567                 if (v->mode & VIDEO_SOUND_LANG1)        /* Mono */
3568                         val = 0x420000;
3569                 if (v->mode & VIDEO_SOUND_LANG2)        /* SAP */
3570                         val = 0x410000;
3571                 if (v->mode & VIDEO_SOUND_STEREO)       /* Stereo */
3572                         val = 0x020000;
3573                 if (val) {
3574                         gpio_bits(0x430000, val);
3575                         if (bttv_gpio)
3576                                 bttv_gpio_tracking(btv,"winfast2000");
3577                 }
3578         } else {
3579                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3580                           VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3581         }
3582 }
3583
3584 /*
3585  * Dariusz Kowalewski <darekk@automex.pl>
3586  * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
3587  * revision 9B has on-board TDA9874A sound decoder).
3588  *
3589  * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
3590  *       will mute this cards.
3591  */
3592 static void
3593 pvbt878p9b_audio(struct bttv *btv, struct video_audio *v, int set)
3594 {
3595         unsigned int val = 0;
3596
3597 #if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3598         if (btv->radio_user)
3599                 return;
3600 #else
3601         if (btv->radio)
3602                 return;
3603 #endif
3604
3605         if (set) {
3606                 if (v->mode & VIDEO_SOUND_MONO) {
3607                         val = 0x01;
3608                 }
3609                 if ((v->mode & (VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2))
3610                     || (v->mode & VIDEO_SOUND_STEREO)) {
3611                         val = 0x02;
3612                 }
3613                 if (val) {
3614                         gpio_bits(0x03,val);
3615                         if (bttv_gpio)
3616                                 bttv_gpio_tracking(btv,"pvbt878p9b");
3617                 }
3618         } else {
3619                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3620                         VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3621         }
3622 }
3623
3624 /*
3625  * Dariusz Kowalewski <darekk@automex.pl>
3626  * sound control for FlyVideo 2000S (with tda9874 decoder) 
3627  * based on pvbt878p9b_audio() - this is not tested, please fix!!!
3628  */
3629 static void
3630 fv2000s_audio(struct bttv *btv, struct video_audio *v, int set)
3631 {
3632         unsigned int val = 0xffff;
3633
3634 #if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3635         if (btv->radio_user)
3636                 return;
3637 #else
3638         if (btv->radio)
3639                 return;
3640 #endif
3641         if (set) {
3642                 if (v->mode & VIDEO_SOUND_MONO) {
3643                         val = 0x0000;
3644                 }
3645                 if ((v->mode & (VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2))
3646                     || (v->mode & VIDEO_SOUND_STEREO)) {
3647                         val = 0x1080; //-dk-???: 0x0880, 0x0080, 0x1800 ...
3648                 }
3649                 if (val != 0xffff) {
3650                         gpio_bits(0x1800, val);
3651                         if (bttv_gpio)
3652                                 bttv_gpio_tracking(btv,"fv2000s");
3653                 }
3654         } else {
3655                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3656                         VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3657         }
3658 }
3659
3660 /*
3661  * sound control for Canopus WinDVR PCI
3662  * Masaki Suzuki <masaki@btree.org>
3663  */
3664 static void
3665 windvr_audio(struct bttv *btv, struct video_audio *v, int set)
3666 {
3667         unsigned long val = 0;
3668
3669         if (set) {
3670                 if (v->mode & VIDEO_SOUND_MONO)
3671                         val = 0x040000;
3672                 if (v->mode & VIDEO_SOUND_LANG1)
3673                         val = 0;
3674                 if (v->mode & VIDEO_SOUND_LANG2)
3675                         val = 0x100000;
3676                 if (v->mode & VIDEO_SOUND_STEREO)
3677                         val = 0;
3678                 if (val) {
3679                         gpio_bits(0x140000, val);
3680                         if (bttv_gpio)
3681                                 bttv_gpio_tracking(btv,"windvr");
3682                 }
3683         } else {
3684                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3685                           VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
3686         }
3687 }
3688
3689 /*
3690  * sound control for AD-TVK503
3691  * Hiroshi Takekawa <sian@big.or.jp>
3692  */
3693 static void
3694 adtvk503_audio(struct bttv *btv, struct video_audio *v, int set)
3695 {
3696         unsigned int con = 0xffffff;
3697
3698         //btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN);
3699
3700         if (set) {
3701                 //btor(***, BT848_GPIO_OUT_EN);
3702                 if (v->mode & VIDEO_SOUND_LANG1)
3703                         con = 0x00000000;
3704                 if (v->mode & VIDEO_SOUND_LANG2)
3705                         con = 0x00180000;
3706                 if (v->mode & VIDEO_SOUND_STEREO)
3707                         con = 0x00000000;
3708                 if (v->mode & VIDEO_SOUND_MONO)
3709                         con = 0x00060000;
3710                 if (con != 0xffffff) {
3711                         gpio_bits(0x1e0000,con);
3712                         if (bttv_gpio)
3713                                 bttv_gpio_tracking(btv, "adtvk503");
3714                 }
3715         } else {
3716                 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
3717                           VIDEO_SOUND_LANG1  | VIDEO_SOUND_LANG2;
3718         }
3719 }
3720
3721 /* RemoteVision MX (rv605) muxsel helper [Miguel Freitas]
3722  *
3723  * This is needed because rv605 don't use a normal multiplex, but a crosspoint
3724  * switch instead (CD22M3494E). This IC can have multiple active connections
3725  * between Xn (input) and Yn (output) pins. We need to clear any existing
3726  * connection prior to establish a new one, pulsing the STROBE pin.
3727  *
3728  * The board hardwire Y0 (xpoint) to MUX1 and MUXOUT to Yin.
3729  * GPIO pins are wired as:
3730  *  GPIO[0:3] - AX[0:3] (xpoint) - P1[0:3] (microcontroler)
3731  *  GPIO[4:6] - AY[0:2] (xpoint) - P1[4:6] (microcontroler)
3732  *  GPIO[7]   - DATA (xpoint)    - P1[7] (microcontroler)
3733  *  GPIO[8]   -                  - P3[5] (microcontroler)
3734  *  GPIO[9]   - RESET (xpoint)   - P3[6] (microcontroler)
3735  *  GPIO[10]  - STROBE (xpoint)  - P3[7] (microcontroler)
3736  *  GPINTR    -                  - P3[4] (microcontroler)
3737  *
3738  * The microcontroler is a 80C32 like. It should be possible to change xpoint
3739  * configuration either directly (as we are doing) or using the microcontroler
3740  * which is also wired to I2C interface. I have no further info on the
3741  * microcontroler features, one would need to disassembly the firmware.
3742  * note: the vendor refused to give any information on this product, all
3743  *       that stuff was found using a multimeter! :)
3744  */
3745 static void rv605_muxsel(struct bttv *btv, unsigned int input)
3746 {
3747         /* reset all conections */
3748         gpio_bits(0x200,0x200);
3749         mdelay(1);
3750         gpio_bits(0x200,0x000);
3751         mdelay(1);
3752
3753         /* create a new conection */
3754         gpio_bits(0x480,0x080);
3755         gpio_bits(0x480,0x480);
3756         mdelay(1);
3757         gpio_bits(0x480,0x080);
3758         mdelay(1);
3759 }
3760
3761 // The Grandtec X-Guard framegrabber card uses two Dual 4-channel
3762 // video multiplexers to provide up to 16 video inputs. These
3763 // multiplexers are controlled by the lower 8 GPIO pins of the
3764 // bt878. The multiplexers probably Pericom PI5V331Q or similar.
3765
3766 // xxx0 is pin xxx of multiplexer U5,
3767 // yyy1 is pin yyy of multiplexer U2
3768
3769 #define ENA0    0x01
3770 #define ENB0    0x02
3771 #define ENA1    0x04
3772 #define ENB1    0x08
3773
3774 #define IN10    0x10
3775 #define IN00    0x20
3776 #define IN11    0x40
3777 #define IN01    0x80
3778
3779 static void xguard_muxsel(struct bttv *btv, unsigned int input)
3780 {
3781         static const int masks[] = {
3782                 ENB0, ENB0|IN00, ENB0|IN10, ENB0|IN00|IN10,
3783                 ENA0, ENA0|IN00, ENA0|IN10, ENA0|IN00|IN10,
3784                 ENB1, ENB1|IN01, ENB1|IN11, ENB1|IN01|IN11,
3785                 ENA1, ENA1|IN01, ENA1|IN11, ENA1|IN01|IN11,
3786         };
3787         gpio_write(masks[input%16]);
3788 }
3789
3790 /*
3791  * ivc120_muxsel [Added by Alan Garfield <alan@fromorbit.com>]
3792  *
3793  * The IVC120G security card has 4 i2c controlled TDA8540 matrix
3794  * swichers to provide 16 channels to MUX0. The TDA8540's have 
3795  * 4 indepedant outputs and as such the IVC120G also has the 
3796  * optional "Monitor Out" bus. This allows the card to be looking 
3797  * at one input while the monitor is looking at another.
3798  *
3799  * Since I've couldn't be bothered figuring out how to add an
3800  * independant muxsel for the monitor bus, I've just set it to 
3801  * whatever the card is looking at.
3802  *
3803  *  OUT0 of the TDA8540's is connected to MUX0         (0x03)
3804  *  OUT1 of the TDA8540's is connected to "Monitor Out"        (0x0C)
3805  *
3806  *  TDA8540_ALT3 IN0-3 = Channel 13 - 16       (0x03)
3807  *  TDA8540_ALT4 IN0-3 = Channel 1 - 4         (0x03)
3808  *  TDA8540_ALT5 IN0-3 = Channel 5 - 8         (0x03)
3809  *  TDA8540_ALT6 IN0-3 = Channel 9 - 12                (0x03)
3810  *
3811  */
3812
3813 /* All 7 possible sub-ids for the TDA8540 Matrix Switcher */
3814 #define I2C_TDA8540        0x90
3815 #define I2C_TDA8540_ALT1   0x92
3816 #define I2C_TDA8540_ALT2   0x94
3817 #define I2C_TDA8540_ALT3   0x96
3818 #define I2C_TDA8540_ALT4   0x98
3819 #define I2C_TDA8540_ALT5   0x9a
3820 #define I2C_TDA8540_ALT6   0x9c
3821
3822 static void ivc120_muxsel(struct bttv *btv, unsigned int input)
3823 {
3824         // Simple maths
3825         int key = input % 4;    
3826         int matrix = input / 4;
3827         
3828         dprintk("bttv%d: ivc120_muxsel: Input - %02d | TDA - %02d | In - %02d\n",
3829                 btv->c.nr, input, matrix, key);
3830         
3831         // Handles the input selection on the TDA8540's
3832         bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x00,
3833                       ((matrix == 3) ? (key | key << 2) : 0x00), 1);
3834         bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x00,
3835                       ((matrix == 0) ? (key | key << 2) : 0x00), 1);
3836         bttv_I2CWrite(btv, I2C_TDA8540_ALT5, 0x00,
3837                       ((matrix == 1) ? (key | key << 2) : 0x00), 1);
3838         bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x00,
3839                       ((matrix == 2) ? (key | key << 2) : 0x00), 1);
3840         
3841         // Handles the output enables on the TDA8540's
3842         bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x02,
3843                       ((matrix == 3) ? 0x03 : 0x00), 1);  // 13 - 16
3844         bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x02,
3845                       ((matrix == 0) ? 0x03 : 0x00), 1);  // 1-4
3846         bttv_I2CWrite(btv, I2C_TDA8540_ALT5, 0x02,
3847                       ((matrix == 1) ? 0x03 : 0x00), 1);  // 5-8 
3848         bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x02,
3849                       ((matrix == 2) ? 0x03 : 0x00), 1);  // 9-12
3850         
3851         // Selects MUX0 for input on the 878
3852         btaor((0)<<5, ~(3<<5), BT848_IFORM);
3853 }
3854
3855
3856 /* ----------------------------------------------------------------------- */
3857 /* motherboard chipset specific stuff                                      */
3858
3859 void __devinit bttv_check_chipset(void)
3860 {
3861         int pcipci_fail = 0;
3862         struct pci_dev *dev = NULL;
3863
3864         if (pci_pci_problems & PCIPCI_FAIL)
3865                 pcipci_fail = 1;
3866         if (pci_pci_problems & (PCIPCI_TRITON|PCIPCI_NATOMA|PCIPCI_VIAETBF))
3867                 triton1 = 1;
3868         if (pci_pci_problems & PCIPCI_VSFX)
3869                 vsfx = 1;
3870 #ifdef PCIPCI_ALIMAGIK
3871         if (pci_pci_problems & PCIPCI_ALIMAGIK)
3872                 latency = 0x0A;
3873 #endif
3874
3875 #if 0
3876         /* print which chipset we have */
3877         while ((dev = pci_find_class(PCI_CLASS_BRIDGE_HOST << 8,dev)))
3878                 printk(KERN_INFO "bttv: Host bridge is %s\n",pci_name(dev));
3879 #endif
3880
3881         /* print warnings about any quirks found */
3882         if (triton1)
3883                 printk(KERN_INFO "bttv: Host bridge needs ETBF enabled.\n");
3884         if (vsfx)
3885                 printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n");
3886         if (pcipci_fail) {
3887                 printk(KERN_WARNING "bttv: BT848 and your chipset may not work together.\n");
3888                 if (UNSET == no_overlay) {
3889                         printk(KERN_WARNING "bttv: going to disable overlay.\n");
3890                         no_overlay = 1;
3891                 }
3892         }
3893         if (UNSET != latency)
3894                 printk(KERN_INFO "bttv: pci latency fixup [%d]\n",latency);
3895
3896         while ((dev = pci_find_device(PCI_VENDOR_ID_INTEL,
3897                                       PCI_DEVICE_ID_INTEL_82441, dev))) {
3898                 unsigned char b;
3899                 pci_read_config_byte(dev, 0x53, &b);
3900                 if (bttv_debug)
3901                         printk(KERN_INFO "bttv: Host bridge: 82441FX Natoma, "
3902                                "bufcon=0x%02x\n",b);
3903         }
3904 }
3905
3906 int __devinit bttv_handle_chipset(struct bttv *btv)
3907 {
3908         unsigned char command;
3909
3910         if (!triton1 && !vsfx && UNSET == latency)
3911                 return 0;
3912
3913         if (bttv_verbose) {
3914                 if (triton1)
3915                         printk(KERN_INFO "bttv%d: enabling ETBF (430FX/VP3 compatibilty)\n",btv->c.nr);
3916                 if (vsfx && btv->id >= 878)
3917                         printk(KERN_INFO "bttv%d: enabling VSFX\n",btv->c.nr);
3918                 if (UNSET != latency)
3919                         printk(KERN_INFO "bttv%d: setting pci timer to %d\n",
3920                                btv->c.nr,latency);
3921         }
3922
3923         if (btv->id < 878) {
3924                 /* bt848 (mis)uses a bit in the irq mask for etbf */
3925                 if (triton1)
3926                         btv->triton1 = BT848_INT_ETBF;
3927         } else {
3928                 /* bt878 has a bit in the pci config space for it */
3929                 pci_read_config_byte(btv->c.pci, BT878_DEVCTRL, &command);
3930                 if (triton1)
3931                         command |= BT878_EN_TBFX;
3932                 if (vsfx)
3933                         command |= BT878_EN_VSFX;
3934                 pci_write_config_byte(btv->c.pci, BT878_DEVCTRL, command);
3935         }
3936         if (UNSET != latency)
3937                 pci_write_config_byte(btv->c.pci, PCI_LATENCY_TIMER, latency);
3938         return 0;
3939 }
3940
3941
3942 /* PXC200 muxsel helper
3943  * luke@syseng.anu.edu.au
3944  * another transplant
3945  * from Alessandro Rubini (rubini@linux.it)
3946  *
3947  * There are 4 kinds of cards:
3948  * PXC200L which is bt848
3949  * PXC200F which is bt848 with PIC controlling mux
3950  * PXC200AL which is bt878
3951  * PXC200AF which is bt878 with PIC controlling mux
3952  */
3953 #define PX_CFG_PXC200F 0x01
3954 #define PX_FLAG_PXC200A  0x00001000 /* a pxc200A is bt-878 based */
3955 #define PX_I2C_PIC       0x0f
3956 #define PX_PXC200A_CARDID 0x200a1295
3957 #define PX_I2C_CMD_CFG   0x00
3958
3959 static void PXC200_muxsel(struct bttv *btv, unsigned int input)
3960 {
3961         int rc;
3962         long mux;
3963         int bitmask;
3964         unsigned char buf[2];
3965
3966         /* Read PIC config to determine if this is a PXC200F */
3967         /* PX_I2C_CMD_CFG*/
3968         buf[0]=0;
3969         buf[1]=0;
3970         rc=bttv_I2CWrite(btv,(PX_I2C_PIC<<1),buf[0],buf[1],1);
3971         if (rc) {
3972           printk(KERN_DEBUG "bttv%d: PXC200_muxsel: pic cfg write failed:%d\n", btv->c.nr,rc);
3973           /* not PXC ? do nothing */
3974           return;
3975         }
3976
3977         rc=bttv_I2CRead(btv,(PX_I2C_PIC<<1),0);
3978         if (!(rc & PX_CFG_PXC200F)) {
3979           printk(KERN_DEBUG "bttv%d: PXC200_muxsel: not PXC200F rc:%d \n", btv->c.nr,rc);
3980           return;
3981         }
3982
3983
3984         /* The multiplexer in the 200F is handled by the GPIO port */
3985         /* get correct mapping between inputs  */
3986         /*  mux = bttv_tvcards[btv->type].muxsel[input] & 3; */
3987         /* ** not needed!?   */
3988         mux = input;
3989
3990         /* make sure output pins are enabled */
3991         /* bitmask=0x30f; */
3992         bitmask=0x302;
3993         /* check whether we have a PXC200A */
3994         if (btv->cardid == PX_PXC200A_CARDID)  {
3995            bitmask ^= 0x180; /* use 7 and 9, not 8 and 9 */
3996            bitmask |= 7<<4; /* the DAC */
3997         }
3998         btwrite(bitmask, BT848_GPIO_OUT_EN);
3999
4000         bitmask = btread(BT848_GPIO_DATA);
4001         if (btv->cardid == PX_PXC200A_CARDID)
4002           bitmask = (bitmask & ~0x280) | ((mux & 2) << 8) | ((mux & 1) << 7);
4003         else /* older device */
4004           bitmask = (bitmask & ~0x300) | ((mux & 3) << 8);
4005         btwrite(bitmask,BT848_GPIO_DATA);
4006
4007         /*
4008          * Was "to be safe, set the bt848 to input 0"
4009          * Actually, since it's ok at load time, better not messing
4010          * with these bits (on PXC200AF you need to set mux 2 here)
4011          *
4012          * needed because bttv-driver sets mux before calling this function
4013          */
4014         if (btv->cardid == PX_PXC200A_CARDID)
4015           btaor(2<<5, ~BT848_IFORM_MUXSEL, BT848_IFORM);
4016         else /* older device */
4017           btand(~BT848_IFORM_MUXSEL,BT848_IFORM);
4018
4019         printk(KERN_DEBUG "bttv%d: setting input channel to:%d\n", btv->c.nr,(int)mux);
4020 }
4021
4022 /*
4023  * Local variables:
4024  * c-basic-offset: 8
4025  * End:
4026  */