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