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