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