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