Merge branch 'fix/asoc' into for-linus
[pandora-kernel.git] / drivers / media / video / saa7134 / saa7134-dvb.c
1 /*
2  *
3  * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
4  *
5  *  Extended 3 / 2005 by Hartmut Hackmann to support various
6  *  cards with the tda10046 DVB-T channel decoder
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/delay.h>
28 #include <linux/kthread.h>
29 #include <linux/suspend.h>
30
31 #include "saa7134-reg.h"
32 #include "saa7134.h"
33 #include <media/v4l2-common.h>
34 #include "dvb-pll.h"
35 #include <dvb_frontend.h>
36
37 #include "mt352.h"
38 #include "mt352_priv.h" /* FIXME */
39 #include "tda1004x.h"
40 #include "nxt200x.h"
41 #include "tuner-xc2028.h"
42 #include "xc5000.h"
43
44 #include "tda10086.h"
45 #include "tda826x.h"
46 #include "tda827x.h"
47 #include "isl6421.h"
48 #include "isl6405.h"
49 #include "lnbp21.h"
50 #include "tuner-simple.h"
51 #include "tda10048.h"
52 #include "tda18271.h"
53 #include "lgdt3305.h"
54 #include "tda8290.h"
55 #include "mb86a20s.h"
56
57 #include "zl10353.h"
58
59 #include "zl10036.h"
60 #include "zl10039.h"
61 #include "mt312.h"
62
63 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
64 MODULE_LICENSE("GPL");
65
66 static unsigned int antenna_pwr;
67
68 module_param(antenna_pwr, int, 0444);
69 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
70
71 static int use_frontend;
72 module_param(use_frontend, int, 0644);
73 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
74
75 static int debug;
76 module_param(debug, int, 0644);
77 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
78
79 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
80
81 #define dprintk(fmt, arg...)    do { if (debug) \
82         printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
83
84 /* Print a warning */
85 #define wprintk(fmt, arg...) \
86         printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
87
88 /* ------------------------------------------------------------------
89  * mt352 based DVB-T cards
90  */
91
92 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
93 {
94         u32 ok;
95
96         if (!on) {
97                 saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
98                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
99                 return 0;
100         }
101
102         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
103         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
104         udelay(10);
105
106         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 28));
107         saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
108         udelay(10);
109         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 28));
110         udelay(10);
111         ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
112         dprintk("%s %s\n", __func__, ok ? "on" : "off");
113
114         if (!ok)
115                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
116         return ok;
117 }
118
119 static int mt352_pinnacle_init(struct dvb_frontend* fe)
120 {
121         static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x28 };
122         static u8 reset []         = { RESET,      0x80 };
123         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
124         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
125         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
126         static u8 fsm_ctl_cfg[]    = { 0x7b,       0x04 };
127         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x0f };
128         static u8 scan_ctl_cfg []  = { SCAN_CTL,   0x0d };
129         static u8 irq_cfg []       = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
130         struct saa7134_dev *dev= fe->dvb->priv;
131
132         dprintk("%s called\n", __func__);
133
134         mt352_write(fe, clock_config,   sizeof(clock_config));
135         udelay(200);
136         mt352_write(fe, reset,          sizeof(reset));
137         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
138         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
139         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
140         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
141
142         mt352_write(fe, fsm_ctl_cfg,    sizeof(fsm_ctl_cfg));
143         mt352_write(fe, scan_ctl_cfg,   sizeof(scan_ctl_cfg));
144         mt352_write(fe, irq_cfg,        sizeof(irq_cfg));
145
146         return 0;
147 }
148
149 static int mt352_aver777_init(struct dvb_frontend* fe)
150 {
151         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x2d };
152         static u8 reset []         = { RESET,      0x80 };
153         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
154         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
155         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
156
157         mt352_write(fe, clock_config,   sizeof(clock_config));
158         udelay(200);
159         mt352_write(fe, reset,          sizeof(reset));
160         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
161         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
162         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
163
164         return 0;
165 }
166
167 static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
168 {
169         static u8 clock_config []  = { CLOCK_CTL, 0x38, 0x2d };
170         static u8 reset []         = { RESET, 0x80 };
171         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
172         static u8 agc_cfg []       = { AGC_TARGET, 0xe };
173         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
174
175         mt352_write(fe, clock_config,   sizeof(clock_config));
176         udelay(200);
177         mt352_write(fe, reset,          sizeof(reset));
178         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
179         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
180         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
181         return 0;
182 }
183
184 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
185                                            struct dvb_frontend_parameters* params)
186 {
187         u8 off[] = { 0x00, 0xf1};
188         u8 on[]  = { 0x00, 0x71};
189         struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
190
191         struct saa7134_dev *dev = fe->dvb->priv;
192         struct v4l2_frequency f;
193
194         /* set frequency (mt2050) */
195         f.tuner     = 0;
196         f.type      = V4L2_TUNER_DIGITAL_TV;
197         f.frequency = params->frequency / 1000 * 16 / 1000;
198         if (fe->ops.i2c_gate_ctrl)
199                 fe->ops.i2c_gate_ctrl(fe, 1);
200         i2c_transfer(&dev->i2c_adap, &msg, 1);
201         saa_call_all(dev, tuner, s_frequency, &f);
202         msg.buf = on;
203         if (fe->ops.i2c_gate_ctrl)
204                 fe->ops.i2c_gate_ctrl(fe, 1);
205         i2c_transfer(&dev->i2c_adap, &msg, 1);
206
207         pinnacle_antenna_pwr(dev, antenna_pwr);
208
209         /* mt352 setup */
210         return mt352_pinnacle_init(fe);
211 }
212
213 static struct mt352_config pinnacle_300i = {
214         .demod_address = 0x3c >> 1,
215         .adc_clock     = 20333,
216         .if2           = 36150,
217         .no_tuner      = 1,
218         .demod_init    = mt352_pinnacle_init,
219 };
220
221 static struct mt352_config avermedia_777 = {
222         .demod_address = 0xf,
223         .demod_init    = mt352_aver777_init,
224 };
225
226 static struct mt352_config avermedia_xc3028_mt352_dev = {
227         .demod_address   = (0x1e >> 1),
228         .no_tuner        = 1,
229         .demod_init      = mt352_avermedia_xc3028_init,
230 };
231
232 static struct tda18271_std_map mb86a20s_tda18271_std_map = {
233         .dvbt_6   = { .if_freq = 3300, .agc_mode = 3, .std = 4,
234                       .if_lvl = 7, .rfagc_top = 0x37, },
235 };
236
237 static struct tda18271_config kworld_tda18271_config = {
238         .std_map = &mb86a20s_tda18271_std_map,
239         .gate    = TDA18271_GATE_DIGITAL,
240 };
241
242 static const struct mb86a20s_config kworld_mb86a20s_config = {
243         .demod_address = 0x10,
244 };
245
246 /* ==================================================================
247  * tda1004x based DVB-T cards, helper functions
248  */
249
250 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
251                                            const struct firmware **fw, char *name)
252 {
253         struct saa7134_dev *dev = fe->dvb->priv;
254         return request_firmware(fw, name, &dev->pci->dev);
255 }
256
257 /* ------------------------------------------------------------------
258  * these tuners are tu1216, td1316(a)
259  */
260
261 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
262 {
263         struct saa7134_dev *dev = fe->dvb->priv;
264         struct tda1004x_state *state = fe->demodulator_priv;
265         u8 addr = state->config->tuner_address;
266         u8 tuner_buf[4];
267         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
268                         sizeof(tuner_buf) };
269         int tuner_frequency = 0;
270         u8 band, cp, filter;
271
272         /* determine charge pump */
273         tuner_frequency = params->frequency + 36166000;
274         if (tuner_frequency < 87000000)
275                 return -EINVAL;
276         else if (tuner_frequency < 130000000)
277                 cp = 3;
278         else if (tuner_frequency < 160000000)
279                 cp = 5;
280         else if (tuner_frequency < 200000000)
281                 cp = 6;
282         else if (tuner_frequency < 290000000)
283                 cp = 3;
284         else if (tuner_frequency < 420000000)
285                 cp = 5;
286         else if (tuner_frequency < 480000000)
287                 cp = 6;
288         else if (tuner_frequency < 620000000)
289                 cp = 3;
290         else if (tuner_frequency < 830000000)
291                 cp = 5;
292         else if (tuner_frequency < 895000000)
293                 cp = 7;
294         else
295                 return -EINVAL;
296
297         /* determine band */
298         if (params->frequency < 49000000)
299                 return -EINVAL;
300         else if (params->frequency < 161000000)
301                 band = 1;
302         else if (params->frequency < 444000000)
303                 band = 2;
304         else if (params->frequency < 861000000)
305                 band = 4;
306         else
307                 return -EINVAL;
308
309         /* setup PLL filter */
310         switch (params->u.ofdm.bandwidth) {
311         case BANDWIDTH_6_MHZ:
312                 filter = 0;
313                 break;
314
315         case BANDWIDTH_7_MHZ:
316                 filter = 0;
317                 break;
318
319         case BANDWIDTH_8_MHZ:
320                 filter = 1;
321                 break;
322
323         default:
324                 return -EINVAL;
325         }
326
327         /* calculate divisor
328          * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
329          */
330         tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
331
332         /* setup tuner buffer */
333         tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
334         tuner_buf[1] = tuner_frequency & 0xff;
335         tuner_buf[2] = 0xca;
336         tuner_buf[3] = (cp << 5) | (filter << 3) | band;
337
338         if (fe->ops.i2c_gate_ctrl)
339                 fe->ops.i2c_gate_ctrl(fe, 1);
340         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
341                 wprintk("could not write to tuner at addr: 0x%02x\n",
342                         addr << 1);
343                 return -EIO;
344         }
345         msleep(1);
346         return 0;
347 }
348
349 static int philips_tu1216_init(struct dvb_frontend *fe)
350 {
351         struct saa7134_dev *dev = fe->dvb->priv;
352         struct tda1004x_state *state = fe->demodulator_priv;
353         u8 addr = state->config->tuner_address;
354         static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
355         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
356
357         /* setup PLL configuration */
358         if (fe->ops.i2c_gate_ctrl)
359                 fe->ops.i2c_gate_ctrl(fe, 1);
360         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
361                 return -EIO;
362         msleep(1);
363
364         return 0;
365 }
366
367 /* ------------------------------------------------------------------ */
368
369 static struct tda1004x_config philips_tu1216_60_config = {
370         .demod_address = 0x8,
371         .invert        = 1,
372         .invert_oclk   = 0,
373         .xtal_freq     = TDA10046_XTAL_4M,
374         .agc_config    = TDA10046_AGC_DEFAULT,
375         .if_freq       = TDA10046_FREQ_3617,
376         .tuner_address = 0x60,
377         .request_firmware = philips_tda1004x_request_firmware
378 };
379
380 static struct tda1004x_config philips_tu1216_61_config = {
381
382         .demod_address = 0x8,
383         .invert        = 1,
384         .invert_oclk   = 0,
385         .xtal_freq     = TDA10046_XTAL_4M,
386         .agc_config    = TDA10046_AGC_DEFAULT,
387         .if_freq       = TDA10046_FREQ_3617,
388         .tuner_address = 0x61,
389         .request_firmware = philips_tda1004x_request_firmware
390 };
391
392 /* ------------------------------------------------------------------ */
393
394 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
395 {
396         struct saa7134_dev *dev = fe->dvb->priv;
397         struct tda1004x_state *state = fe->demodulator_priv;
398         u8 addr = state->config->tuner_address;
399         static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
400         struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
401
402         /* setup PLL configuration */
403         if (fe->ops.i2c_gate_ctrl)
404                 fe->ops.i2c_gate_ctrl(fe, 1);
405         if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
406                 return -EIO;
407         return 0;
408 }
409
410 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
411 {
412         return philips_tda6651_pll_set(fe, params);
413 }
414
415 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
416 {
417         struct saa7134_dev *dev = fe->dvb->priv;
418         struct tda1004x_state *state = fe->demodulator_priv;
419         u8 addr = state->config->tuner_address;
420         static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
421         struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
422
423         /* switch the tuner to analog mode */
424         if (fe->ops.i2c_gate_ctrl)
425                 fe->ops.i2c_gate_ctrl(fe, 1);
426         if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
427                 return -EIO;
428         return 0;
429 }
430
431 /* ------------------------------------------------------------------ */
432
433 static int philips_europa_tuner_init(struct dvb_frontend *fe)
434 {
435         struct saa7134_dev *dev = fe->dvb->priv;
436         static u8 msg[] = { 0x00, 0x40};
437         struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
438
439
440         if (philips_td1316_tuner_init(fe))
441                 return -EIO;
442         msleep(1);
443         if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
444                 return -EIO;
445
446         return 0;
447 }
448
449 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
450 {
451         struct saa7134_dev *dev = fe->dvb->priv;
452
453         static u8 msg[] = { 0x00, 0x14 };
454         struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
455
456         if (philips_td1316_tuner_sleep(fe))
457                 return -EIO;
458
459         /* switch the board to analog mode */
460         if (fe->ops.i2c_gate_ctrl)
461                 fe->ops.i2c_gate_ctrl(fe, 1);
462         i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
463         return 0;
464 }
465
466 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
467 {
468         struct saa7134_dev *dev = fe->dvb->priv;
469
470         if (dev->original_demod_sleep)
471                 dev->original_demod_sleep(fe);
472         fe->ops.i2c_gate_ctrl(fe, 1);
473         return 0;
474 }
475
476 static struct tda1004x_config philips_europa_config = {
477
478         .demod_address = 0x8,
479         .invert        = 0,
480         .invert_oclk   = 0,
481         .xtal_freq     = TDA10046_XTAL_4M,
482         .agc_config    = TDA10046_AGC_IFO_AUTO_POS,
483         .if_freq       = TDA10046_FREQ_052,
484         .tuner_address = 0x61,
485         .request_firmware = philips_tda1004x_request_firmware
486 };
487
488 static struct tda1004x_config medion_cardbus = {
489         .demod_address = 0x08,
490         .invert        = 1,
491         .invert_oclk   = 0,
492         .xtal_freq     = TDA10046_XTAL_16M,
493         .agc_config    = TDA10046_AGC_IFO_AUTO_NEG,
494         .if_freq       = TDA10046_FREQ_3613,
495         .tuner_address = 0x61,
496         .request_firmware = philips_tda1004x_request_firmware
497 };
498
499 static struct tda1004x_config technotrend_budget_t3000_config = {
500         .demod_address = 0x8,
501         .invert        = 1,
502         .invert_oclk   = 0,
503         .xtal_freq     = TDA10046_XTAL_4M,
504         .agc_config    = TDA10046_AGC_DEFAULT,
505         .if_freq       = TDA10046_FREQ_3617,
506         .tuner_address = 0x63,
507         .request_firmware = philips_tda1004x_request_firmware
508 };
509
510 /* ------------------------------------------------------------------
511  * tda 1004x based cards with philips silicon tuner
512  */
513
514 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
515 {
516         struct tda1004x_state *state = fe->demodulator_priv;
517
518         u8 addr = state->config->i2c_gate;
519         static u8 tda8290_close[] = { 0x21, 0xc0};
520         static u8 tda8290_open[]  = { 0x21, 0x80};
521         struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
522         if (enable) {
523                 tda8290_msg.buf = tda8290_close;
524         } else {
525                 tda8290_msg.buf = tda8290_open;
526         }
527         if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
528                 struct saa7134_dev *dev = fe->dvb->priv;
529                 wprintk("could not access tda8290 I2C gate\n");
530                 return -EIO;
531         }
532         msleep(20);
533         return 0;
534 }
535
536 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
537 {
538         struct saa7134_dev *dev = fe->dvb->priv;
539         struct tda1004x_state *state = fe->demodulator_priv;
540
541         switch (state->config->antenna_switch) {
542         case 0: break;
543         case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
544                 saa7134_set_gpio(dev, 21, 0);
545                 break;
546         case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
547                 saa7134_set_gpio(dev, 21, 1);
548                 break;
549         }
550         return 0;
551 }
552
553 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
554 {
555         struct saa7134_dev *dev = fe->dvb->priv;
556         struct tda1004x_state *state = fe->demodulator_priv;
557
558         switch (state->config->antenna_switch) {
559         case 0: break;
560         case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
561                 saa7134_set_gpio(dev, 21, 1);
562                 break;
563         case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
564                 saa7134_set_gpio(dev, 21, 0);
565                 break;
566         }
567         return 0;
568 }
569
570 static int configure_tda827x_fe(struct saa7134_dev *dev,
571                                 struct tda1004x_config *cdec_conf,
572                                 struct tda827x_config *tuner_conf)
573 {
574         struct videobuf_dvb_frontend *fe0;
575
576         /* Get the first frontend */
577         fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
578
579         fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
580         if (fe0->dvb.frontend) {
581                 if (cdec_conf->i2c_gate)
582                         fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
583                 if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
584                                cdec_conf->tuner_address,
585                                &dev->i2c_adap, tuner_conf))
586                         return 0;
587
588                 wprintk("no tda827x tuner found at addr: %02x\n",
589                                 cdec_conf->tuner_address);
590         }
591         return -EINVAL;
592 }
593
594 /* ------------------------------------------------------------------ */
595
596 static struct tda827x_config tda827x_cfg_0 = {
597         .init = philips_tda827x_tuner_init,
598         .sleep = philips_tda827x_tuner_sleep,
599         .config = 0,
600         .switch_addr = 0
601 };
602
603 static struct tda827x_config tda827x_cfg_1 = {
604         .init = philips_tda827x_tuner_init,
605         .sleep = philips_tda827x_tuner_sleep,
606         .config = 1,
607         .switch_addr = 0x4b
608 };
609
610 static struct tda827x_config tda827x_cfg_2 = {
611         .init = philips_tda827x_tuner_init,
612         .sleep = philips_tda827x_tuner_sleep,
613         .config = 2,
614         .switch_addr = 0x4b
615 };
616
617 static struct tda827x_config tda827x_cfg_2_sw42 = {
618         .init = philips_tda827x_tuner_init,
619         .sleep = philips_tda827x_tuner_sleep,
620         .config = 2,
621         .switch_addr = 0x42
622 };
623
624 /* ------------------------------------------------------------------ */
625
626 static int __kworld_sbtvd_i2c_gate_ctrl(struct saa7134_dev *dev, int enable)
627 {
628         unsigned char initmsg[] = {0x45, 0x97};
629         unsigned char msg_enable[] = {0x45, 0xc1};
630         unsigned char msg_disable[] = {0x45, 0x81};
631         struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
632
633         if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
634                 wprintk("could not access the I2C gate\n");
635                 return -EIO;
636         }
637         if (enable)
638                 msg.buf = msg_enable;
639         else
640                 msg.buf = msg_disable;
641         if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
642                 wprintk("could not access the I2C gate\n");
643                 return -EIO;
644         }
645         msleep(20);
646         return 0;
647 }
648 static int kworld_sbtvd_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
649 {
650         struct saa7134_dev *dev = fe->dvb->priv;
651
652         return __kworld_sbtvd_i2c_gate_ctrl(dev, enable);
653 }
654
655 /* ------------------------------------------------------------------ */
656
657 static struct tda1004x_config tda827x_lifeview_config = {
658         .demod_address = 0x08,
659         .invert        = 1,
660         .invert_oclk   = 0,
661         .xtal_freq     = TDA10046_XTAL_16M,
662         .agc_config    = TDA10046_AGC_TDA827X,
663         .gpio_config   = TDA10046_GP11_I,
664         .if_freq       = TDA10046_FREQ_045,
665         .tuner_address = 0x60,
666         .request_firmware = philips_tda1004x_request_firmware
667 };
668
669 static struct tda1004x_config philips_tiger_config = {
670         .demod_address = 0x08,
671         .invert        = 1,
672         .invert_oclk   = 0,
673         .xtal_freq     = TDA10046_XTAL_16M,
674         .agc_config    = TDA10046_AGC_TDA827X,
675         .gpio_config   = TDA10046_GP11_I,
676         .if_freq       = TDA10046_FREQ_045,
677         .i2c_gate      = 0x4b,
678         .tuner_address = 0x61,
679         .antenna_switch= 1,
680         .request_firmware = philips_tda1004x_request_firmware
681 };
682
683 static struct tda1004x_config cinergy_ht_config = {
684         .demod_address = 0x08,
685         .invert        = 1,
686         .invert_oclk   = 0,
687         .xtal_freq     = TDA10046_XTAL_16M,
688         .agc_config    = TDA10046_AGC_TDA827X,
689         .gpio_config   = TDA10046_GP01_I,
690         .if_freq       = TDA10046_FREQ_045,
691         .i2c_gate      = 0x4b,
692         .tuner_address = 0x61,
693         .request_firmware = philips_tda1004x_request_firmware
694 };
695
696 static struct tda1004x_config cinergy_ht_pci_config = {
697         .demod_address = 0x08,
698         .invert        = 1,
699         .invert_oclk   = 0,
700         .xtal_freq     = TDA10046_XTAL_16M,
701         .agc_config    = TDA10046_AGC_TDA827X,
702         .gpio_config   = TDA10046_GP01_I,
703         .if_freq       = TDA10046_FREQ_045,
704         .i2c_gate      = 0x4b,
705         .tuner_address = 0x60,
706         .request_firmware = philips_tda1004x_request_firmware
707 };
708
709 static struct tda1004x_config philips_tiger_s_config = {
710         .demod_address = 0x08,
711         .invert        = 1,
712         .invert_oclk   = 0,
713         .xtal_freq     = TDA10046_XTAL_16M,
714         .agc_config    = TDA10046_AGC_TDA827X,
715         .gpio_config   = TDA10046_GP01_I,
716         .if_freq       = TDA10046_FREQ_045,
717         .i2c_gate      = 0x4b,
718         .tuner_address = 0x61,
719         .antenna_switch= 1,
720         .request_firmware = philips_tda1004x_request_firmware
721 };
722
723 static struct tda1004x_config pinnacle_pctv_310i_config = {
724         .demod_address = 0x08,
725         .invert        = 1,
726         .invert_oclk   = 0,
727         .xtal_freq     = TDA10046_XTAL_16M,
728         .agc_config    = TDA10046_AGC_TDA827X,
729         .gpio_config   = TDA10046_GP11_I,
730         .if_freq       = TDA10046_FREQ_045,
731         .i2c_gate      = 0x4b,
732         .tuner_address = 0x61,
733         .request_firmware = philips_tda1004x_request_firmware
734 };
735
736 static struct tda1004x_config hauppauge_hvr_1110_config = {
737         .demod_address = 0x08,
738         .invert        = 1,
739         .invert_oclk   = 0,
740         .xtal_freq     = TDA10046_XTAL_16M,
741         .agc_config    = TDA10046_AGC_TDA827X,
742         .gpio_config   = TDA10046_GP11_I,
743         .if_freq       = TDA10046_FREQ_045,
744         .i2c_gate      = 0x4b,
745         .tuner_address = 0x61,
746         .request_firmware = philips_tda1004x_request_firmware
747 };
748
749 static struct tda1004x_config asus_p7131_dual_config = {
750         .demod_address = 0x08,
751         .invert        = 1,
752         .invert_oclk   = 0,
753         .xtal_freq     = TDA10046_XTAL_16M,
754         .agc_config    = TDA10046_AGC_TDA827X,
755         .gpio_config   = TDA10046_GP11_I,
756         .if_freq       = TDA10046_FREQ_045,
757         .i2c_gate      = 0x4b,
758         .tuner_address = 0x61,
759         .antenna_switch= 2,
760         .request_firmware = philips_tda1004x_request_firmware
761 };
762
763 static struct tda1004x_config lifeview_trio_config = {
764         .demod_address = 0x09,
765         .invert        = 1,
766         .invert_oclk   = 0,
767         .xtal_freq     = TDA10046_XTAL_16M,
768         .agc_config    = TDA10046_AGC_TDA827X,
769         .gpio_config   = TDA10046_GP00_I,
770         .if_freq       = TDA10046_FREQ_045,
771         .tuner_address = 0x60,
772         .request_firmware = philips_tda1004x_request_firmware
773 };
774
775 static struct tda1004x_config tevion_dvbt220rf_config = {
776         .demod_address = 0x08,
777         .invert        = 1,
778         .invert_oclk   = 0,
779         .xtal_freq     = TDA10046_XTAL_16M,
780         .agc_config    = TDA10046_AGC_TDA827X,
781         .gpio_config   = TDA10046_GP11_I,
782         .if_freq       = TDA10046_FREQ_045,
783         .tuner_address = 0x60,
784         .request_firmware = philips_tda1004x_request_firmware
785 };
786
787 static struct tda1004x_config md8800_dvbt_config = {
788         .demod_address = 0x08,
789         .invert        = 1,
790         .invert_oclk   = 0,
791         .xtal_freq     = TDA10046_XTAL_16M,
792         .agc_config    = TDA10046_AGC_TDA827X,
793         .gpio_config   = TDA10046_GP01_I,
794         .if_freq       = TDA10046_FREQ_045,
795         .i2c_gate      = 0x4b,
796         .tuner_address = 0x60,
797         .request_firmware = philips_tda1004x_request_firmware
798 };
799
800 static struct tda1004x_config asus_p7131_4871_config = {
801         .demod_address = 0x08,
802         .invert        = 1,
803         .invert_oclk   = 0,
804         .xtal_freq     = TDA10046_XTAL_16M,
805         .agc_config    = TDA10046_AGC_TDA827X,
806         .gpio_config   = TDA10046_GP01_I,
807         .if_freq       = TDA10046_FREQ_045,
808         .i2c_gate      = 0x4b,
809         .tuner_address = 0x61,
810         .antenna_switch= 2,
811         .request_firmware = philips_tda1004x_request_firmware
812 };
813
814 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
815         .demod_address = 0x08,
816         .invert        = 1,
817         .invert_oclk   = 0,
818         .xtal_freq     = TDA10046_XTAL_16M,
819         .agc_config    = TDA10046_AGC_TDA827X,
820         .gpio_config   = TDA10046_GP11_I,
821         .if_freq       = TDA10046_FREQ_045,
822         .i2c_gate      = 0x4b,
823         .tuner_address = 0x61,
824         .antenna_switch= 2,
825         .request_firmware = philips_tda1004x_request_firmware
826 };
827
828 static struct tda1004x_config kworld_dvb_t_210_config = {
829         .demod_address = 0x08,
830         .invert        = 1,
831         .invert_oclk   = 0,
832         .xtal_freq     = TDA10046_XTAL_16M,
833         .agc_config    = TDA10046_AGC_TDA827X,
834         .gpio_config   = TDA10046_GP11_I,
835         .if_freq       = TDA10046_FREQ_045,
836         .i2c_gate      = 0x4b,
837         .tuner_address = 0x61,
838         .antenna_switch= 1,
839         .request_firmware = philips_tda1004x_request_firmware
840 };
841
842 static struct tda1004x_config avermedia_super_007_config = {
843         .demod_address = 0x08,
844         .invert        = 1,
845         .invert_oclk   = 0,
846         .xtal_freq     = TDA10046_XTAL_16M,
847         .agc_config    = TDA10046_AGC_TDA827X,
848         .gpio_config   = TDA10046_GP01_I,
849         .if_freq       = TDA10046_FREQ_045,
850         .i2c_gate      = 0x4b,
851         .tuner_address = 0x60,
852         .antenna_switch= 1,
853         .request_firmware = philips_tda1004x_request_firmware
854 };
855
856 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
857         .demod_address = 0x08,
858         .invert        = 1,
859         .invert_oclk   = 0,
860         .xtal_freq     = TDA10046_XTAL_16M,
861         .agc_config    = TDA10046_AGC_TDA827X,
862         .gpio_config   = TDA10046_GP01_I,
863         .if_freq       = TDA10046_FREQ_045,
864         .i2c_gate      = 0x42,
865         .tuner_address = 0x61,
866         .antenna_switch = 1,
867         .request_firmware = philips_tda1004x_request_firmware
868 };
869
870 static struct tda1004x_config asus_tiger_3in1_config = {
871         .demod_address = 0x0b,
872         .invert        = 1,
873         .invert_oclk   = 0,
874         .xtal_freq     = TDA10046_XTAL_16M,
875         .agc_config    = TDA10046_AGC_TDA827X,
876         .gpio_config   = TDA10046_GP11_I,
877         .if_freq       = TDA10046_FREQ_045,
878         .i2c_gate      = 0x4b,
879         .tuner_address = 0x61,
880         .antenna_switch = 1,
881         .request_firmware = philips_tda1004x_request_firmware
882 };
883
884 /* ------------------------------------------------------------------
885  * special case: this card uses saa713x GPIO22 for the mode switch
886  */
887
888 static int ads_duo_tuner_init(struct dvb_frontend *fe)
889 {
890         struct saa7134_dev *dev = fe->dvb->priv;
891         philips_tda827x_tuner_init(fe);
892         /* route TDA8275a AGC input to the channel decoder */
893         saa7134_set_gpio(dev, 22, 1);
894         return 0;
895 }
896
897 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
898 {
899         struct saa7134_dev *dev = fe->dvb->priv;
900         /* route TDA8275a AGC input to the analog IF chip*/
901         saa7134_set_gpio(dev, 22, 0);
902         philips_tda827x_tuner_sleep(fe);
903         return 0;
904 }
905
906 static struct tda827x_config ads_duo_cfg = {
907         .init = ads_duo_tuner_init,
908         .sleep = ads_duo_tuner_sleep,
909         .config = 0
910 };
911
912 static struct tda1004x_config ads_tech_duo_config = {
913         .demod_address = 0x08,
914         .invert        = 1,
915         .invert_oclk   = 0,
916         .xtal_freq     = TDA10046_XTAL_16M,
917         .agc_config    = TDA10046_AGC_TDA827X,
918         .gpio_config   = TDA10046_GP00_I,
919         .if_freq       = TDA10046_FREQ_045,
920         .tuner_address = 0x61,
921         .request_firmware = philips_tda1004x_request_firmware
922 };
923
924 static struct zl10353_config behold_h6_config = {
925         .demod_address = 0x1e>>1,
926         .no_tuner      = 1,
927         .parallel_ts   = 1,
928         .disable_i2c_gate_ctrl = 1,
929 };
930
931 static struct xc5000_config behold_x7_tunerconfig = {
932         .i2c_address      = 0xc2>>1,
933         .if_khz           = 4560,
934         .radio_input      = XC5000_RADIO_FM1,
935 };
936
937 static struct zl10353_config behold_x7_config = {
938         .demod_address = 0x1e>>1,
939         .if2           = 45600,
940         .no_tuner      = 1,
941         .parallel_ts   = 1,
942         .disable_i2c_gate_ctrl = 1,
943 };
944
945 /* ==================================================================
946  * tda10086 based DVB-S cards, helper functions
947  */
948
949 static struct tda10086_config flydvbs = {
950         .demod_address = 0x0e,
951         .invert = 0,
952         .diseqc_tone = 0,
953         .xtal_freq = TDA10086_XTAL_16M,
954 };
955
956 static struct tda10086_config sd1878_4m = {
957         .demod_address = 0x0e,
958         .invert = 0,
959         .diseqc_tone = 0,
960         .xtal_freq = TDA10086_XTAL_4M,
961 };
962
963 /* ------------------------------------------------------------------
964  * special case: lnb supply is connected to the gated i2c
965  */
966
967 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
968 {
969         int res = -EIO;
970         struct saa7134_dev *dev = fe->dvb->priv;
971         if (fe->ops.i2c_gate_ctrl) {
972                 fe->ops.i2c_gate_ctrl(fe, 1);
973                 if (dev->original_set_voltage)
974                         res = dev->original_set_voltage(fe, voltage);
975                 fe->ops.i2c_gate_ctrl(fe, 0);
976         }
977         return res;
978 };
979
980 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
981 {
982         int res = -EIO;
983         struct saa7134_dev *dev = fe->dvb->priv;
984         if (fe->ops.i2c_gate_ctrl) {
985                 fe->ops.i2c_gate_ctrl(fe, 1);
986                 if (dev->original_set_high_voltage)
987                         res = dev->original_set_high_voltage(fe, arg);
988                 fe->ops.i2c_gate_ctrl(fe, 0);
989         }
990         return res;
991 };
992
993 static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
994 {
995         struct saa7134_dev *dev = fe->dvb->priv;
996         u8 wbuf[2] = { 0x1f, 00 };
997         u8 rbuf;
998         struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
999                                  { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
1000
1001         if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
1002                 return -EIO;
1003         /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
1004         if (voltage == SEC_VOLTAGE_18)
1005                 wbuf[1] = rbuf | 0x10;
1006         else
1007                 wbuf[1] = rbuf & 0xef;
1008         msg[0].len = 2;
1009         i2c_transfer(&dev->i2c_adap, msg, 1);
1010         return 0;
1011 }
1012
1013 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
1014 {
1015         struct saa7134_dev *dev = fe->dvb->priv;
1016         wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
1017         return -EIO;
1018 }
1019
1020 /* ==================================================================
1021  * nxt200x based ATSC cards, helper functions
1022  */
1023
1024 static struct nxt200x_config avertvhda180 = {
1025         .demod_address    = 0x0a,
1026 };
1027
1028 static struct nxt200x_config kworldatsc110 = {
1029         .demod_address    = 0x0a,
1030 };
1031
1032 /* ------------------------------------------------------------------ */
1033
1034 static struct mt312_config avertv_a700_mt312 = {
1035         .demod_address = 0x0e,
1036         .voltage_inverted = 1,
1037 };
1038
1039 static struct zl10036_config avertv_a700_tuner = {
1040         .tuner_address = 0x60,
1041 };
1042
1043 static struct mt312_config zl10313_compro_s350_config = {
1044         .demod_address = 0x0e,
1045 };
1046
1047 static struct lgdt3305_config hcw_lgdt3305_config = {
1048         .i2c_addr           = 0x0e,
1049         .mpeg_mode          = LGDT3305_MPEG_SERIAL,
1050         .tpclk_edge         = LGDT3305_TPCLK_RISING_EDGE,
1051         .tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
1052         .deny_i2c_rptr      = 1,
1053         .spectral_inversion = 1,
1054         .qam_if_khz         = 4000,
1055         .vsb_if_khz         = 3250,
1056 };
1057
1058 static struct tda10048_config hcw_tda10048_config = {
1059         .demod_address    = 0x10 >> 1,
1060         .output_mode      = TDA10048_SERIAL_OUTPUT,
1061         .fwbulkwritelen   = TDA10048_BULKWRITE_200,
1062         .inversion        = TDA10048_INVERSION_ON,
1063         .dtv6_if_freq_khz = TDA10048_IF_3300,
1064         .dtv7_if_freq_khz = TDA10048_IF_3500,
1065         .dtv8_if_freq_khz = TDA10048_IF_4000,
1066         .clk_freq_khz     = TDA10048_CLK_16000,
1067         .disable_gate_access = 1,
1068 };
1069
1070 static struct tda18271_std_map hauppauge_tda18271_std_map = {
1071         .atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 4,
1072                       .if_lvl = 1, .rfagc_top = 0x58, },
1073         .qam_6    = { .if_freq = 4000, .agc_mode = 3, .std = 5,
1074                       .if_lvl = 1, .rfagc_top = 0x58, },
1075 };
1076
1077 static struct tda18271_config hcw_tda18271_config = {
1078         .std_map = &hauppauge_tda18271_std_map,
1079         .gate    = TDA18271_GATE_ANALOG,
1080         .config  = 3,
1081         .output_opt = TDA18271_OUTPUT_LT_OFF,
1082 };
1083
1084 static struct tda829x_config tda829x_no_probe = {
1085         .probe_tuner = TDA829X_DONT_PROBE,
1086 };
1087
1088 static struct tda10048_config zolid_tda10048_config = {
1089         .demod_address    = 0x10 >> 1,
1090         .output_mode      = TDA10048_PARALLEL_OUTPUT,
1091         .fwbulkwritelen   = TDA10048_BULKWRITE_200,
1092         .inversion        = TDA10048_INVERSION_ON,
1093         .dtv6_if_freq_khz = TDA10048_IF_3300,
1094         .dtv7_if_freq_khz = TDA10048_IF_3500,
1095         .dtv8_if_freq_khz = TDA10048_IF_4000,
1096         .clk_freq_khz     = TDA10048_CLK_16000,
1097         .disable_gate_access = 1,
1098 };
1099
1100 static struct tda18271_config zolid_tda18271_config = {
1101         .gate    = TDA18271_GATE_ANALOG,
1102 };
1103
1104 static struct tda10048_config dtv1000s_tda10048_config = {
1105         .demod_address    = 0x10 >> 1,
1106         .output_mode      = TDA10048_PARALLEL_OUTPUT,
1107         .fwbulkwritelen   = TDA10048_BULKWRITE_200,
1108         .inversion        = TDA10048_INVERSION_ON,
1109         .dtv6_if_freq_khz = TDA10048_IF_3300,
1110         .dtv7_if_freq_khz = TDA10048_IF_3800,
1111         .dtv8_if_freq_khz = TDA10048_IF_4300,
1112         .clk_freq_khz     = TDA10048_CLK_16000,
1113         .disable_gate_access = 1,
1114 };
1115
1116 static struct tda18271_std_map dtv1000s_tda18271_std_map = {
1117         .dvbt_6   = { .if_freq = 3300, .agc_mode = 3, .std = 4,
1118                       .if_lvl = 1, .rfagc_top = 0x37, },
1119         .dvbt_7   = { .if_freq = 3800, .agc_mode = 3, .std = 5,
1120                       .if_lvl = 1, .rfagc_top = 0x37, },
1121         .dvbt_8   = { .if_freq = 4300, .agc_mode = 3, .std = 6,
1122                       .if_lvl = 1, .rfagc_top = 0x37, },
1123 };
1124
1125 static struct tda18271_config dtv1000s_tda18271_config = {
1126         .std_map = &dtv1000s_tda18271_std_map,
1127         .gate    = TDA18271_GATE_ANALOG,
1128 };
1129
1130 /* ==================================================================
1131  * Core code
1132  */
1133
1134 static int dvb_init(struct saa7134_dev *dev)
1135 {
1136         int ret;
1137         int attach_xc3028 = 0;
1138         struct videobuf_dvb_frontend *fe0;
1139
1140         /* FIXME: add support for multi-frontend */
1141         mutex_init(&dev->frontends.lock);
1142         INIT_LIST_HEAD(&dev->frontends.felist);
1143
1144         printk(KERN_INFO "%s() allocating 1 frontend\n", __func__);
1145         fe0 = videobuf_dvb_alloc_frontend(&dev->frontends, 1);
1146         if (!fe0) {
1147                 printk(KERN_ERR "%s() failed to alloc\n", __func__);
1148                 return -ENOMEM;
1149         }
1150
1151         /* init struct videobuf_dvb */
1152         dev->ts.nr_bufs    = 32;
1153         dev->ts.nr_packets = 32*4;
1154         fe0->dvb.name = dev->name;
1155         videobuf_queue_sg_init(&fe0->dvb.dvbq, &saa7134_ts_qops,
1156                             &dev->pci->dev, &dev->slock,
1157                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
1158                             V4L2_FIELD_ALTERNATE,
1159                             sizeof(struct saa7134_buf),
1160                             dev, NULL);
1161
1162         switch (dev->board) {
1163         case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1164                 dprintk("pinnacle 300i dvb setup\n");
1165                 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
1166                                                &dev->i2c_adap);
1167                 if (fe0->dvb.frontend) {
1168                         fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
1169                 }
1170                 break;
1171         case SAA7134_BOARD_AVERMEDIA_777:
1172         case SAA7134_BOARD_AVERMEDIA_A16AR:
1173                 dprintk("avertv 777 dvb setup\n");
1174                 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1175                                                &dev->i2c_adap);
1176                 if (fe0->dvb.frontend) {
1177                         dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1178                                    &dev->i2c_adap, 0x61,
1179                                    TUNER_PHILIPS_TD1316);
1180                 }
1181                 break;
1182         case SAA7134_BOARD_AVERMEDIA_A16D:
1183                 dprintk("AverMedia A16D dvb setup\n");
1184                 fe0->dvb.frontend = dvb_attach(mt352_attach,
1185                                                 &avermedia_xc3028_mt352_dev,
1186                                                 &dev->i2c_adap);
1187                 attach_xc3028 = 1;
1188                 break;
1189         case SAA7134_BOARD_MD7134:
1190                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1191                                                &medion_cardbus,
1192                                                &dev->i2c_adap);
1193                 if (fe0->dvb.frontend) {
1194                         dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1195                                    &dev->i2c_adap, medion_cardbus.tuner_address,
1196                                    TUNER_PHILIPS_FMD1216ME_MK3);
1197                 }
1198                 break;
1199         case SAA7134_BOARD_PHILIPS_TOUGH:
1200                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1201                                                &philips_tu1216_60_config,
1202                                                &dev->i2c_adap);
1203                 if (fe0->dvb.frontend) {
1204                         fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1205                         fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1206                 }
1207                 break;
1208         case SAA7134_BOARD_FLYDVBTDUO:
1209         case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1210                 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1211                                          &tda827x_cfg_0) < 0)
1212                         goto dettach_frontend;
1213                 break;
1214         case SAA7134_BOARD_PHILIPS_EUROPA:
1215         case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1216         case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
1217                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1218                                                &philips_europa_config,
1219                                                &dev->i2c_adap);
1220                 if (fe0->dvb.frontend) {
1221                         dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1222                         fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1223                         fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1224                         fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1225                         fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1226                 }
1227                 break;
1228         case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
1229                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1230                                                &technotrend_budget_t3000_config,
1231                                                &dev->i2c_adap);
1232                 if (fe0->dvb.frontend) {
1233                         dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1234                         fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1235                         fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1236                         fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1237                         fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1238                 }
1239                 break;
1240         case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1241                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1242                                                &philips_tu1216_61_config,
1243                                                &dev->i2c_adap);
1244                 if (fe0->dvb.frontend) {
1245                         fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1246                         fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1247                 }
1248                 break;
1249         case SAA7134_BOARD_KWORLD_DVBT_210:
1250                 if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
1251                                          &tda827x_cfg_2) < 0)
1252                         goto dettach_frontend;
1253                 break;
1254         case SAA7134_BOARD_HAUPPAUGE_HVR1120:
1255                 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1256                                                &hcw_tda10048_config,
1257                                                &dev->i2c_adap);
1258                 if (fe0->dvb.frontend != NULL) {
1259                         dvb_attach(tda829x_attach, fe0->dvb.frontend,
1260                                    &dev->i2c_adap, 0x4b,
1261                                    &tda829x_no_probe);
1262                         dvb_attach(tda18271_attach, fe0->dvb.frontend,
1263                                    0x60, &dev->i2c_adap,
1264                                    &hcw_tda18271_config);
1265                 }
1266                 break;
1267         case SAA7134_BOARD_PHILIPS_TIGER:
1268                 if (configure_tda827x_fe(dev, &philips_tiger_config,
1269                                          &tda827x_cfg_0) < 0)
1270                         goto dettach_frontend;
1271                 break;
1272         case SAA7134_BOARD_PINNACLE_PCTV_310i:
1273                 if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
1274                                          &tda827x_cfg_1) < 0)
1275                         goto dettach_frontend;
1276                 break;
1277         case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1278                 if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
1279                                          &tda827x_cfg_1) < 0)
1280                         goto dettach_frontend;
1281                 break;
1282         case SAA7134_BOARD_HAUPPAUGE_HVR1150:
1283                 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1284                                                &hcw_lgdt3305_config,
1285                                                &dev->i2c_adap);
1286                 if (fe0->dvb.frontend) {
1287                         dvb_attach(tda829x_attach, fe0->dvb.frontend,
1288                                    &dev->i2c_adap, 0x4b,
1289                                    &tda829x_no_probe);
1290                         dvb_attach(tda18271_attach, fe0->dvb.frontend,
1291                                    0x60, &dev->i2c_adap,
1292                                    &hcw_tda18271_config);
1293                 }
1294                 break;
1295         case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1296                 if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
1297                                          &tda827x_cfg_0) < 0)
1298                         goto dettach_frontend;
1299                 break;
1300         case SAA7134_BOARD_FLYDVBT_LR301:
1301                 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1302                                          &tda827x_cfg_0) < 0)
1303                         goto dettach_frontend;
1304                 break;
1305         case SAA7134_BOARD_FLYDVB_TRIO:
1306                 if (!use_frontend) {    /* terrestrial */
1307                         if (configure_tda827x_fe(dev, &lifeview_trio_config,
1308                                                  &tda827x_cfg_0) < 0)
1309                                 goto dettach_frontend;
1310                 } else {                /* satellite */
1311                         fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1312                         if (fe0->dvb.frontend) {
1313                                 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
1314                                                                         &dev->i2c_adap, 0) == NULL) {
1315                                         wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
1316                                         goto dettach_frontend;
1317                                 }
1318                                 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap,
1319                                                                                 0x08, 0, 0) == NULL) {
1320                                         wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1321                                         goto dettach_frontend;
1322                                 }
1323                         }
1324                 }
1325                 break;
1326         case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1327         case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1328                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1329                                                &ads_tech_duo_config,
1330                                                &dev->i2c_adap);
1331                 if (fe0->dvb.frontend) {
1332                         if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
1333                                    ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1334                                                                 &ads_duo_cfg) == NULL) {
1335                                 wprintk("no tda827x tuner found at addr: %02x\n",
1336                                         ads_tech_duo_config.tuner_address);
1337                                 goto dettach_frontend;
1338                         }
1339                 } else
1340                         wprintk("failed to attach tda10046\n");
1341                 break;
1342         case SAA7134_BOARD_TEVION_DVBT_220RF:
1343                 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
1344                                          &tda827x_cfg_0) < 0)
1345                         goto dettach_frontend;
1346                 break;
1347         case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1348                 if (!use_frontend) {     /* terrestrial */
1349                         if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1350                                                  &tda827x_cfg_0) < 0)
1351                                 goto dettach_frontend;
1352                 } else {        /* satellite */
1353                         fe0->dvb.frontend = dvb_attach(tda10086_attach,
1354                                                         &flydvbs, &dev->i2c_adap);
1355                         if (fe0->dvb.frontend) {
1356                                 struct dvb_frontend *fe = fe0->dvb.frontend;
1357                                 u8 dev_id = dev->eedata[2];
1358                                 u8 data = 0xc4;
1359                                 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1360
1361                                 if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
1362                                                 0x60, &dev->i2c_adap, 0) == NULL) {
1363                                         wprintk("%s: Medion Quadro, no tda826x "
1364                                                 "found !\n", __func__);
1365                                         goto dettach_frontend;
1366                                 }
1367                                 if (dev_id != 0x08) {
1368                                         /* we need to open the i2c gate (we know it exists) */
1369                                         fe->ops.i2c_gate_ctrl(fe, 1);
1370                                         if (dvb_attach(isl6405_attach, fe,
1371                                                         &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1372                                                 wprintk("%s: Medion Quadro, no ISL6405 "
1373                                                         "found !\n", __func__);
1374                                                 goto dettach_frontend;
1375                                         }
1376                                         if (dev_id == 0x07) {
1377                                                 /* fire up the 2nd section of the LNB supply since
1378                                                    we can't do this from the other section */
1379                                                 msg.buf = &data;
1380                                                 i2c_transfer(&dev->i2c_adap, &msg, 1);
1381                                         }
1382                                         fe->ops.i2c_gate_ctrl(fe, 0);
1383                                         dev->original_set_voltage = fe->ops.set_voltage;
1384                                         fe->ops.set_voltage = md8800_set_voltage;
1385                                         dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1386                                         fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1387                                 } else {
1388                                         fe->ops.set_voltage = md8800_set_voltage2;
1389                                         fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1390                                 }
1391                         }
1392                 }
1393                 break;
1394         case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1395                 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1396                                                &dev->i2c_adap);
1397                 if (fe0->dvb.frontend)
1398                         dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
1399                                    NULL, DVB_PLL_TDHU2);
1400                 break;
1401         case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
1402         case SAA7134_BOARD_KWORLD_ATSC110:
1403                 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1404                                                &dev->i2c_adap);
1405                 if (fe0->dvb.frontend)
1406                         dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1407                                    &dev->i2c_adap, 0x61,
1408                                    TUNER_PHILIPS_TUV1236D);
1409                 break;
1410         case SAA7134_BOARD_FLYDVBS_LR300:
1411                 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1412                                                &dev->i2c_adap);
1413                 if (fe0->dvb.frontend) {
1414                         if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1415                                        &dev->i2c_adap, 0) == NULL) {
1416                                 wprintk("%s: No tda826x found!\n", __func__);
1417                                 goto dettach_frontend;
1418                         }
1419                         if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1420                                        &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1421                                 wprintk("%s: No ISL6421 found!\n", __func__);
1422                                 goto dettach_frontend;
1423                         }
1424                 }
1425                 break;
1426         case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1427                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1428                                                &medion_cardbus,
1429                                                &dev->i2c_adap);
1430                 if (fe0->dvb.frontend) {
1431                         dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1432                         fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1433
1434                         dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1435                                    &dev->i2c_adap, medion_cardbus.tuner_address,
1436                                    TUNER_PHILIPS_FMD1216ME_MK3);
1437                 }
1438                 break;
1439         case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1440                 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1441                                 &philips_europa_config,
1442                                 &dev->i2c_adap);
1443                 if (fe0->dvb.frontend) {
1444                         fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1445                         fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1446                 }
1447                 break;
1448         case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1449                 if (configure_tda827x_fe(dev, &cinergy_ht_config,
1450                                          &tda827x_cfg_0) < 0)
1451                         goto dettach_frontend;
1452                 break;
1453         case SAA7134_BOARD_CINERGY_HT_PCI:
1454                 if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
1455                                          &tda827x_cfg_0) < 0)
1456                         goto dettach_frontend;
1457                 break;
1458         case SAA7134_BOARD_PHILIPS_TIGER_S:
1459                 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1460                                          &tda827x_cfg_2) < 0)
1461                         goto dettach_frontend;
1462                 break;
1463         case SAA7134_BOARD_ASUS_P7131_4871:
1464                 if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
1465                                          &tda827x_cfg_2) < 0)
1466                         goto dettach_frontend;
1467                 break;
1468         case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1469                 if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
1470                                          &tda827x_cfg_2) < 0)
1471                         goto dettach_frontend;
1472                 break;
1473         case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1474                 if (configure_tda827x_fe(dev, &avermedia_super_007_config,
1475                                          &tda827x_cfg_0) < 0)
1476                         goto dettach_frontend;
1477                 break;
1478         case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1479                 if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
1480                                          &tda827x_cfg_2_sw42) < 0)
1481                         goto dettach_frontend;
1482                 break;
1483         case SAA7134_BOARD_PHILIPS_SNAKE:
1484                 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1485                                                 &dev->i2c_adap);
1486                 if (fe0->dvb.frontend) {
1487                         if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1488                                         &dev->i2c_adap, 0) == NULL) {
1489                                 wprintk("%s: No tda826x found!\n", __func__);
1490                                 goto dettach_frontend;
1491                         }
1492                         if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1493                                         &dev->i2c_adap, 0, 0) == NULL) {
1494                                 wprintk("%s: No lnbp21 found!\n", __func__);
1495                                 goto dettach_frontend;
1496                         }
1497                 }
1498                 break;
1499         case SAA7134_BOARD_CREATIX_CTX953:
1500                 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1501                                          &tda827x_cfg_0) < 0)
1502                         goto dettach_frontend;
1503                 break;
1504         case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1505                 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1506                                          &tda827x_cfg_2) < 0)
1507                         goto dettach_frontend;
1508                 break;
1509         case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1510                 dprintk("AverMedia E506R dvb setup\n");
1511                 saa7134_set_gpio(dev, 25, 0);
1512                 msleep(10);
1513                 saa7134_set_gpio(dev, 25, 1);
1514                 fe0->dvb.frontend = dvb_attach(mt352_attach,
1515                                                 &avermedia_xc3028_mt352_dev,
1516                                                 &dev->i2c_adap);
1517                 attach_xc3028 = 1;
1518                 break;
1519         case SAA7134_BOARD_MD7134_BRIDGE_2:
1520                 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1521                                                 &sd1878_4m, &dev->i2c_adap);
1522                 if (fe0->dvb.frontend) {
1523                         struct dvb_frontend *fe;
1524                         if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1525                                   &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
1526                                 wprintk("%s: MD7134 DVB-S, no SD1878 "
1527                                         "found !\n", __func__);
1528                                 goto dettach_frontend;
1529                         }
1530                         /* we need to open the i2c gate (we know it exists) */
1531                         fe = fe0->dvb.frontend;
1532                         fe->ops.i2c_gate_ctrl(fe, 1);
1533                         if (dvb_attach(isl6405_attach, fe,
1534                                         &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1535                                 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1536                                         "found !\n", __func__);
1537                                 goto dettach_frontend;
1538                         }
1539                         fe->ops.i2c_gate_ctrl(fe, 0);
1540                         dev->original_set_voltage = fe->ops.set_voltage;
1541                         fe->ops.set_voltage = md8800_set_voltage;
1542                         dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1543                         fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1544                 }
1545                 break;
1546         case SAA7134_BOARD_AVERMEDIA_M103:
1547                 saa7134_set_gpio(dev, 25, 0);
1548                 msleep(10);
1549                 saa7134_set_gpio(dev, 25, 1);
1550                 fe0->dvb.frontend = dvb_attach(mt352_attach,
1551                                                 &avermedia_xc3028_mt352_dev,
1552                                                 &dev->i2c_adap);
1553                 attach_xc3028 = 1;
1554                 break;
1555         case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1556                 if (!use_frontend) {     /* terrestrial */
1557                         if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1558                                                         &tda827x_cfg_2) < 0)
1559                                 goto dettach_frontend;
1560                 } else {                /* satellite */
1561                         fe0->dvb.frontend = dvb_attach(tda10086_attach,
1562                                                 &flydvbs, &dev->i2c_adap);
1563                         if (fe0->dvb.frontend) {
1564                                 if (dvb_attach(tda826x_attach,
1565                                                 fe0->dvb.frontend, 0x60,
1566                                                 &dev->i2c_adap, 0) == NULL) {
1567                                         wprintk("%s: Asus Tiger 3in1, no "
1568                                                 "tda826x found!\n", __func__);
1569                                         goto dettach_frontend;
1570                                 }
1571                                 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1572                                                 &dev->i2c_adap, 0, 0) == NULL) {
1573                                         wprintk("%s: Asus Tiger 3in1, no lnbp21"
1574                                                 " found!\n", __func__);
1575                                         goto dettach_frontend;
1576                                 }
1577                         }
1578                 }
1579                 break;
1580         case SAA7134_BOARD_ASUSTeK_TIGER:
1581                 if (configure_tda827x_fe(dev, &philips_tiger_config,
1582                                          &tda827x_cfg_0) < 0)
1583                         goto dettach_frontend;
1584                 break;
1585         case SAA7134_BOARD_BEHOLD_H6:
1586                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1587                                                 &behold_h6_config,
1588                                                 &dev->i2c_adap);
1589                 if (fe0->dvb.frontend) {
1590                         dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1591                                    &dev->i2c_adap, 0x61,
1592                                    TUNER_PHILIPS_FMD1216MEX_MK3);
1593                 }
1594                 break;
1595         case SAA7134_BOARD_BEHOLD_X7:
1596                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1597                                                 &behold_x7_config,
1598                                                 &dev->i2c_adap);
1599                 if (fe0->dvb.frontend) {
1600                         dvb_attach(xc5000_attach, fe0->dvb.frontend,
1601                                    &dev->i2c_adap, &behold_x7_tunerconfig);
1602                 }
1603                 break;
1604         case SAA7134_BOARD_BEHOLD_H7:
1605                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1606                                                 &behold_x7_config,
1607                                                 &dev->i2c_adap);
1608                 if (fe0->dvb.frontend) {
1609                         dvb_attach(xc5000_attach, fe0->dvb.frontend,
1610                                    &dev->i2c_adap, &behold_x7_tunerconfig);
1611                 }
1612                 break;
1613         case SAA7134_BOARD_AVERMEDIA_A700_PRO:
1614         case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
1615                 /* Zarlink ZL10313 */
1616                 fe0->dvb.frontend = dvb_attach(mt312_attach,
1617                         &avertv_a700_mt312, &dev->i2c_adap);
1618                 if (fe0->dvb.frontend) {
1619                         if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
1620                                         &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
1621                                 wprintk("%s: No zl10036 found!\n",
1622                                         __func__);
1623                         }
1624                 }
1625                 break;
1626         case SAA7134_BOARD_VIDEOMATE_S350:
1627                 fe0->dvb.frontend = dvb_attach(mt312_attach,
1628                                 &zl10313_compro_s350_config, &dev->i2c_adap);
1629                 if (fe0->dvb.frontend)
1630                         if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1631                                         0x60, &dev->i2c_adap) == NULL)
1632                                 wprintk("%s: No zl10039 found!\n",
1633                                         __func__);
1634
1635                 break;
1636         case SAA7134_BOARD_ZOLID_HYBRID_PCI:
1637                 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1638                                                &zolid_tda10048_config,
1639                                                &dev->i2c_adap);
1640                 if (fe0->dvb.frontend != NULL) {
1641                         dvb_attach(tda829x_attach, fe0->dvb.frontend,
1642                                    &dev->i2c_adap, 0x4b,
1643                                    &tda829x_no_probe);
1644                         dvb_attach(tda18271_attach, fe0->dvb.frontend,
1645                                    0x60, &dev->i2c_adap,
1646                                    &zolid_tda18271_config);
1647                 }
1648                 break;
1649         case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
1650                 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1651                                                &dtv1000s_tda10048_config,
1652                                                &dev->i2c_adap);
1653                 if (fe0->dvb.frontend != NULL) {
1654                         dvb_attach(tda829x_attach, fe0->dvb.frontend,
1655                                    &dev->i2c_adap, 0x4b,
1656                                    &tda829x_no_probe);
1657                         dvb_attach(tda18271_attach, fe0->dvb.frontend,
1658                                    0x60, &dev->i2c_adap,
1659                                    &dtv1000s_tda18271_config);
1660                 }
1661                 break;
1662         case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
1663                 __kworld_sbtvd_i2c_gate_ctrl(dev, 0);
1664                 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x14000);
1665                 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x14000);
1666                 msleep(20);
1667                 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x54000);
1668                 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x54000);
1669                 msleep(20);
1670                 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1671                                                &kworld_mb86a20s_config,
1672                                                &dev->i2c_adap);
1673                 __kworld_sbtvd_i2c_gate_ctrl(dev, 1);
1674                 if (fe0->dvb.frontend != NULL) {
1675                         dvb_attach(tda18271_attach, fe0->dvb.frontend,
1676                                    0x60, &dev->i2c_adap,
1677                                    &kworld_tda18271_config);
1678                         /*
1679                          * Only after success, it can initialize the gate, otherwise
1680                          * an OOPS will hit, due to kfree(fe0->dvb.frontend)
1681                          */
1682                         fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_i2c_gate_ctrl;
1683                 }
1684                 break;
1685         default:
1686                 wprintk("Huh? unknown DVB card?\n");
1687                 break;
1688         }
1689
1690         if (attach_xc3028) {
1691                 struct dvb_frontend *fe;
1692                 struct xc2028_config cfg = {
1693                         .i2c_adap  = &dev->i2c_adap,
1694                         .i2c_addr  = 0x61,
1695                 };
1696
1697                 if (!fe0->dvb.frontend)
1698                         goto dettach_frontend;
1699
1700                 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
1701                 if (!fe) {
1702                         printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1703                                dev->name);
1704                         goto dettach_frontend;
1705                 }
1706         }
1707
1708         if (NULL == fe0->dvb.frontend) {
1709                 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1710                 goto dettach_frontend;
1711         }
1712         /* define general-purpose callback pointer */
1713         fe0->dvb.frontend->callback = saa7134_tuner_callback;
1714
1715         /* register everything else */
1716         ret = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
1717                                         &dev->pci->dev, adapter_nr, 0, NULL);
1718
1719         /* this sequence is necessary to make the tda1004x load its firmware
1720          * and to enter analog mode of hybrid boards
1721          */
1722         if (!ret) {
1723                 if (fe0->dvb.frontend->ops.init)
1724                         fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
1725                 if (fe0->dvb.frontend->ops.sleep)
1726                         fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
1727                 if (fe0->dvb.frontend->ops.tuner_ops.sleep)
1728                         fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
1729         }
1730         return ret;
1731
1732 dettach_frontend:
1733         videobuf_dvb_dealloc_frontends(&dev->frontends);
1734         return -EINVAL;
1735 }
1736
1737 static int dvb_fini(struct saa7134_dev *dev)
1738 {
1739         struct videobuf_dvb_frontend *fe0;
1740
1741         /* Get the first frontend */
1742         fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
1743         if (!fe0)
1744                 return -EINVAL;
1745
1746         /* FIXME: I suspect that this code is bogus, since the entry for
1747            Pinnacle 300I DVB-T PAL already defines the proper init to allow
1748            the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1749          */
1750         if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1751                 struct v4l2_priv_tun_config tda9887_cfg;
1752                 static int on  = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1753
1754                 tda9887_cfg.tuner = TUNER_TDA9887;
1755                 tda9887_cfg.priv  = &on;
1756
1757                 /* otherwise we don't detect the tuner on next insmod */
1758                 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1759         } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1760                 if ((dev->eedata[2] == 0x07) && use_frontend) {
1761                         /* turn off the 2nd lnb supply */
1762                         u8 data = 0x80;
1763                         struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1764                         struct dvb_frontend *fe;
1765                         fe = fe0->dvb.frontend;
1766                         if (fe->ops.i2c_gate_ctrl) {
1767                                 fe->ops.i2c_gate_ctrl(fe, 1);
1768                                 i2c_transfer(&dev->i2c_adap, &msg, 1);
1769                                 fe->ops.i2c_gate_ctrl(fe, 0);
1770                         }
1771                 }
1772         }
1773         videobuf_dvb_unregister_bus(&dev->frontends);
1774         return 0;
1775 }
1776
1777 static struct saa7134_mpeg_ops dvb_ops = {
1778         .type          = SAA7134_MPEG_DVB,
1779         .init          = dvb_init,
1780         .fini          = dvb_fini,
1781 };
1782
1783 static int __init dvb_register(void)
1784 {
1785         return saa7134_ts_register(&dvb_ops);
1786 }
1787
1788 static void __exit dvb_unregister(void)
1789 {
1790         saa7134_ts_unregister(&dvb_ops);
1791 }
1792
1793 module_init(dvb_register);
1794 module_exit(dvb_unregister);
1795
1796 /* ------------------------------------------------------------------ */
1797 /*
1798  * Local variables:
1799  * c-basic-offset: 8
1800  * End:
1801  */