V4L/DVB (7262): Add support for xc3028-based boards
[safe/jmp/linux-2.6] / 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/slab.h>
28 #include <linux/delay.h>
29 #include <linux/kthread.h>
30 #include <linux/suspend.h>
31
32 #include "saa7134-reg.h"
33 #include "saa7134.h"
34 #include <media/v4l2-common.h>
35 #include "dvb-pll.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
43 #include "tda10086.h"
44 #include "tda826x.h"
45 #include "tda827x.h"
46 #include "isl6421.h"
47 #include "isl6405.h"
48 #include "lnbp21.h"
49
50 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
51 MODULE_LICENSE("GPL");
52
53 static unsigned int antenna_pwr;
54
55 module_param(antenna_pwr, int, 0444);
56 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
57
58 static int use_frontend;
59 module_param(use_frontend, int, 0644);
60 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
61
62 static int debug;
63 module_param(debug, int, 0644);
64 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
65
66 #define dprintk(fmt, arg...)    do { if (debug) \
67         printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
68
69 /* Print a warning */
70 #define wprintk(fmt, arg...) \
71         printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
72
73 /* ------------------------------------------------------------------
74  * mt352 based DVB-T cards
75  */
76
77 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
78 {
79         u32 ok;
80
81         if (!on) {
82                 saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
83                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
84                 return 0;
85         }
86
87         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
88         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
89         udelay(10);
90
91         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 28));
92         saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
93         udelay(10);
94         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 28));
95         udelay(10);
96         ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
97         dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off");
98
99         if (!ok)
100                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
101         return ok;
102 }
103
104 static int mt352_pinnacle_init(struct dvb_frontend* fe)
105 {
106         static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x28 };
107         static u8 reset []         = { RESET,      0x80 };
108         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
109         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
110         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
111         static u8 fsm_ctl_cfg[]    = { 0x7b,       0x04 };
112         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x0f };
113         static u8 scan_ctl_cfg []  = { SCAN_CTL,   0x0d };
114         static u8 irq_cfg []       = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
115         struct saa7134_dev *dev= fe->dvb->priv;
116
117         dprintk("%s called\n", __FUNCTION__);
118
119         mt352_write(fe, clock_config,   sizeof(clock_config));
120         udelay(200);
121         mt352_write(fe, reset,          sizeof(reset));
122         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
123         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
124         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
125         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
126
127         mt352_write(fe, fsm_ctl_cfg,    sizeof(fsm_ctl_cfg));
128         mt352_write(fe, scan_ctl_cfg,   sizeof(scan_ctl_cfg));
129         mt352_write(fe, irq_cfg,        sizeof(irq_cfg));
130
131         return 0;
132 }
133
134 static int mt352_aver777_init(struct dvb_frontend* fe)
135 {
136         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x2d };
137         static u8 reset []         = { RESET,      0x80 };
138         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
139         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
140         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
141
142         mt352_write(fe, clock_config,   sizeof(clock_config));
143         udelay(200);
144         mt352_write(fe, reset,          sizeof(reset));
145         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
146         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
147         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
148
149         return 0;
150 }
151
152 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
153                                            struct dvb_frontend_parameters* params)
154 {
155         u8 off[] = { 0x00, 0xf1};
156         u8 on[]  = { 0x00, 0x71};
157         struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
158
159         struct saa7134_dev *dev = fe->dvb->priv;
160         struct v4l2_frequency f;
161
162         /* set frequency (mt2050) */
163         f.tuner     = 0;
164         f.type      = V4L2_TUNER_DIGITAL_TV;
165         f.frequency = params->frequency / 1000 * 16 / 1000;
166         if (fe->ops.i2c_gate_ctrl)
167                 fe->ops.i2c_gate_ctrl(fe, 1);
168         i2c_transfer(&dev->i2c_adap, &msg, 1);
169         saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
170         msg.buf = on;
171         if (fe->ops.i2c_gate_ctrl)
172                 fe->ops.i2c_gate_ctrl(fe, 1);
173         i2c_transfer(&dev->i2c_adap, &msg, 1);
174
175         pinnacle_antenna_pwr(dev, antenna_pwr);
176
177         /* mt352 setup */
178         return mt352_pinnacle_init(fe);
179 }
180
181 static struct mt352_config pinnacle_300i = {
182         .demod_address = 0x3c >> 1,
183         .adc_clock     = 20333,
184         .if2           = 36150,
185         .no_tuner      = 1,
186         .demod_init    = mt352_pinnacle_init,
187 };
188
189 static struct mt352_config avermedia_777 = {
190         .demod_address = 0xf,
191         .demod_init    = mt352_aver777_init,
192 };
193
194 static struct mt352_config avermedia_e506r_mt352_dev = {
195         .demod_address   = (0x1e >> 1),
196         .no_tuner        = 1,
197 };
198
199 /* ==================================================================
200  * tda1004x based DVB-T cards, helper functions
201  */
202
203 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
204                                            const struct firmware **fw, char *name)
205 {
206         struct saa7134_dev *dev = fe->dvb->priv;
207         return request_firmware(fw, name, &dev->pci->dev);
208 }
209
210 /* ------------------------------------------------------------------
211  * these tuners are tu1216, td1316(a)
212  */
213
214 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
215 {
216         struct saa7134_dev *dev = fe->dvb->priv;
217         struct tda1004x_state *state = fe->demodulator_priv;
218         u8 addr = state->config->tuner_address;
219         u8 tuner_buf[4];
220         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
221                         sizeof(tuner_buf) };
222         int tuner_frequency = 0;
223         u8 band, cp, filter;
224
225         /* determine charge pump */
226         tuner_frequency = params->frequency + 36166000;
227         if (tuner_frequency < 87000000)
228                 return -EINVAL;
229         else if (tuner_frequency < 130000000)
230                 cp = 3;
231         else if (tuner_frequency < 160000000)
232                 cp = 5;
233         else if (tuner_frequency < 200000000)
234                 cp = 6;
235         else if (tuner_frequency < 290000000)
236                 cp = 3;
237         else if (tuner_frequency < 420000000)
238                 cp = 5;
239         else if (tuner_frequency < 480000000)
240                 cp = 6;
241         else if (tuner_frequency < 620000000)
242                 cp = 3;
243         else if (tuner_frequency < 830000000)
244                 cp = 5;
245         else if (tuner_frequency < 895000000)
246                 cp = 7;
247         else
248                 return -EINVAL;
249
250         /* determine band */
251         if (params->frequency < 49000000)
252                 return -EINVAL;
253         else if (params->frequency < 161000000)
254                 band = 1;
255         else if (params->frequency < 444000000)
256                 band = 2;
257         else if (params->frequency < 861000000)
258                 band = 4;
259         else
260                 return -EINVAL;
261
262         /* setup PLL filter */
263         switch (params->u.ofdm.bandwidth) {
264         case BANDWIDTH_6_MHZ:
265                 filter = 0;
266                 break;
267
268         case BANDWIDTH_7_MHZ:
269                 filter = 0;
270                 break;
271
272         case BANDWIDTH_8_MHZ:
273                 filter = 1;
274                 break;
275
276         default:
277                 return -EINVAL;
278         }
279
280         /* calculate divisor
281          * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
282          */
283         tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
284
285         /* setup tuner buffer */
286         tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
287         tuner_buf[1] = tuner_frequency & 0xff;
288         tuner_buf[2] = 0xca;
289         tuner_buf[3] = (cp << 5) | (filter << 3) | band;
290
291         if (fe->ops.i2c_gate_ctrl)
292                 fe->ops.i2c_gate_ctrl(fe, 1);
293         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
294                 wprintk("could not write to tuner at addr: 0x%02x\n",
295                         addr << 1);
296                 return -EIO;
297         }
298         msleep(1);
299         return 0;
300 }
301
302 static int philips_tu1216_init(struct dvb_frontend *fe)
303 {
304         struct saa7134_dev *dev = fe->dvb->priv;
305         struct tda1004x_state *state = fe->demodulator_priv;
306         u8 addr = state->config->tuner_address;
307         static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
308         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
309
310         /* setup PLL configuration */
311         if (fe->ops.i2c_gate_ctrl)
312                 fe->ops.i2c_gate_ctrl(fe, 1);
313         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
314                 return -EIO;
315         msleep(1);
316
317         return 0;
318 }
319
320 /* ------------------------------------------------------------------ */
321
322 static struct tda1004x_config philips_tu1216_60_config = {
323         .demod_address = 0x8,
324         .invert        = 1,
325         .invert_oclk   = 0,
326         .xtal_freq     = TDA10046_XTAL_4M,
327         .agc_config    = TDA10046_AGC_DEFAULT,
328         .if_freq       = TDA10046_FREQ_3617,
329         .tuner_address = 0x60,
330         .request_firmware = philips_tda1004x_request_firmware
331 };
332
333 static struct tda1004x_config philips_tu1216_61_config = {
334
335         .demod_address = 0x8,
336         .invert        = 1,
337         .invert_oclk   = 0,
338         .xtal_freq     = TDA10046_XTAL_4M,
339         .agc_config    = TDA10046_AGC_DEFAULT,
340         .if_freq       = TDA10046_FREQ_3617,
341         .tuner_address = 0x61,
342         .request_firmware = philips_tda1004x_request_firmware
343 };
344
345 /* ------------------------------------------------------------------ */
346
347 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
348 {
349         struct saa7134_dev *dev = fe->dvb->priv;
350         struct tda1004x_state *state = fe->demodulator_priv;
351         u8 addr = state->config->tuner_address;
352         static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
353         struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
354
355         /* setup PLL configuration */
356         if (fe->ops.i2c_gate_ctrl)
357                 fe->ops.i2c_gate_ctrl(fe, 1);
358         if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
359                 return -EIO;
360         return 0;
361 }
362
363 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
364 {
365         return philips_tda6651_pll_set(fe, params);
366 }
367
368 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
369 {
370         struct saa7134_dev *dev = fe->dvb->priv;
371         struct tda1004x_state *state = fe->demodulator_priv;
372         u8 addr = state->config->tuner_address;
373         static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
374         struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
375
376         /* switch the tuner to analog mode */
377         if (fe->ops.i2c_gate_ctrl)
378                 fe->ops.i2c_gate_ctrl(fe, 1);
379         if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
380                 return -EIO;
381         return 0;
382 }
383
384 /* ------------------------------------------------------------------ */
385
386 static int philips_europa_tuner_init(struct dvb_frontend *fe)
387 {
388         struct saa7134_dev *dev = fe->dvb->priv;
389         static u8 msg[] = { 0x00, 0x40};
390         struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
391
392
393         if (philips_td1316_tuner_init(fe))
394                 return -EIO;
395         msleep(1);
396         if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
397                 return -EIO;
398
399         return 0;
400 }
401
402 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
403 {
404         struct saa7134_dev *dev = fe->dvb->priv;
405
406         static u8 msg[] = { 0x00, 0x14 };
407         struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
408
409         if (philips_td1316_tuner_sleep(fe))
410                 return -EIO;
411
412         /* switch the board to analog mode */
413         if (fe->ops.i2c_gate_ctrl)
414                 fe->ops.i2c_gate_ctrl(fe, 1);
415         i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
416         return 0;
417 }
418
419 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
420 {
421         struct saa7134_dev *dev = fe->dvb->priv;
422
423         if (dev->original_demod_sleep)
424                 dev->original_demod_sleep(fe);
425         fe->ops.i2c_gate_ctrl(fe, 1);
426         return 0;
427 }
428
429 static struct tda1004x_config philips_europa_config = {
430
431         .demod_address = 0x8,
432         .invert        = 0,
433         .invert_oclk   = 0,
434         .xtal_freq     = TDA10046_XTAL_4M,
435         .agc_config    = TDA10046_AGC_IFO_AUTO_POS,
436         .if_freq       = TDA10046_FREQ_052,
437         .tuner_address = 0x61,
438         .request_firmware = philips_tda1004x_request_firmware
439 };
440
441 /* ------------------------------------------------------------------ */
442
443 static struct tda1004x_config medion_cardbus = {
444         .demod_address = 0x08,
445         .invert        = 1,
446         .invert_oclk   = 0,
447         .xtal_freq     = TDA10046_XTAL_16M,
448         .agc_config    = TDA10046_AGC_IFO_AUTO_NEG,
449         .if_freq       = TDA10046_FREQ_3613,
450         .tuner_address = 0x61,
451         .request_firmware = philips_tda1004x_request_firmware
452 };
453
454 /* ------------------------------------------------------------------
455  * tda 1004x based cards with philips silicon tuner
456  */
457
458 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
459 {
460         struct saa7134_dev *dev = fe->dvb->priv;
461         struct tda1004x_state *state = fe->demodulator_priv;
462         u8 addr = state->config->i2c_gate;
463         u8 config = state->config->tuner_config;
464         u8 GP00_CF[] = {0x20, 0x01};
465         u8 GP00_LEV[] = {0x22, 0x00};
466
467         struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
468         if (config) {
469                 if (high) {
470                         dprintk("setting LNA to high gain\n");
471                 } else {
472                         dprintk("setting LNA to low gain\n");
473                 }
474         }
475         switch (config) {
476         case 0: /* no LNA */
477                 break;
478         case 1: /* switch is GPIO 0 of tda8290 */
479         case 2:
480                 /* turn Vsync off */
481                 saa7134_set_gpio(dev, 22, 0);
482                 GP00_LEV[1] = high ? 0 : 1;
483                 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
484                         wprintk("could not access tda8290 at addr: 0x%02x\n",
485                                 addr << 1);
486                         return;
487                 }
488                 msg.buf = GP00_LEV;
489                 if (config == 2)
490                         GP00_LEV[1] = high ? 1 : 0;
491                 i2c_transfer(&dev->i2c_adap, &msg, 1);
492                 break;
493         case 3: /* switch with GPIO of saa713x */
494                 saa7134_set_gpio(dev, 22, high);
495                 break;
496         }
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 /* ------------------------------------------------------------------ */
522
523 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
524 {
525         struct saa7134_dev *dev = fe->dvb->priv;
526         struct tda1004x_state *state = fe->demodulator_priv;
527
528         switch (state->config->antenna_switch) {
529         case 0: break;
530         case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
531                 saa7134_set_gpio(dev, 21, 0);
532                 break;
533         case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
534                 saa7134_set_gpio(dev, 21, 1);
535                 break;
536         }
537         return 0;
538 }
539
540 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
541 {
542         struct saa7134_dev *dev = fe->dvb->priv;
543         struct tda1004x_state *state = fe->demodulator_priv;
544
545         switch (state->config->antenna_switch) {
546         case 0: break;
547         case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
548                 saa7134_set_gpio(dev, 21, 1);
549                 break;
550         case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
551                 saa7134_set_gpio(dev, 21, 0);
552                 break;
553         }
554         return 0;
555 }
556
557 static struct tda827x_config tda827x_cfg = {
558         .lna_gain = philips_tda827x_lna_gain,
559         .init = philips_tda827x_tuner_init,
560         .sleep = philips_tda827x_tuner_sleep
561 };
562
563 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
564 {
565         dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
566         if (dev->dvb.frontend) {
567                 if (tda_conf->i2c_gate)
568                         dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
569                 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
570                                                 &dev->i2c_adap,&tda827x_cfg) == NULL) {
571                         wprintk("no tda827x tuner found at addr: %02x\n",
572                                 tda_conf->tuner_address);
573                 }
574         }
575 }
576
577 /* ------------------------------------------------------------------ */
578
579 static struct tda1004x_config tda827x_lifeview_config = {
580         .demod_address = 0x08,
581         .invert        = 1,
582         .invert_oclk   = 0,
583         .xtal_freq     = TDA10046_XTAL_16M,
584         .agc_config    = TDA10046_AGC_TDA827X,
585         .gpio_config   = TDA10046_GP11_I,
586         .if_freq       = TDA10046_FREQ_045,
587         .tuner_address = 0x60,
588         .request_firmware = philips_tda1004x_request_firmware
589 };
590
591 static struct tda1004x_config philips_tiger_config = {
592         .demod_address = 0x08,
593         .invert        = 1,
594         .invert_oclk   = 0,
595         .xtal_freq     = TDA10046_XTAL_16M,
596         .agc_config    = TDA10046_AGC_TDA827X,
597         .gpio_config   = TDA10046_GP11_I,
598         .if_freq       = TDA10046_FREQ_045,
599         .i2c_gate      = 0x4b,
600         .tuner_address = 0x61,
601         .tuner_config  = 0,
602         .antenna_switch= 1,
603         .request_firmware = philips_tda1004x_request_firmware
604 };
605
606 static struct tda1004x_config cinergy_ht_config = {
607         .demod_address = 0x08,
608         .invert        = 1,
609         .invert_oclk   = 0,
610         .xtal_freq     = TDA10046_XTAL_16M,
611         .agc_config    = TDA10046_AGC_TDA827X,
612         .gpio_config   = TDA10046_GP01_I,
613         .if_freq       = TDA10046_FREQ_045,
614         .i2c_gate      = 0x4b,
615         .tuner_address = 0x61,
616         .tuner_config  = 0,
617         .request_firmware = philips_tda1004x_request_firmware
618 };
619
620 static struct tda1004x_config cinergy_ht_pci_config = {
621         .demod_address = 0x08,
622         .invert        = 1,
623         .invert_oclk   = 0,
624         .xtal_freq     = TDA10046_XTAL_16M,
625         .agc_config    = TDA10046_AGC_TDA827X,
626         .gpio_config   = TDA10046_GP01_I,
627         .if_freq       = TDA10046_FREQ_045,
628         .i2c_gate      = 0x4b,
629         .tuner_address = 0x60,
630         .tuner_config  = 0,
631         .request_firmware = philips_tda1004x_request_firmware
632 };
633
634 static struct tda1004x_config philips_tiger_s_config = {
635         .demod_address = 0x08,
636         .invert        = 1,
637         .invert_oclk   = 0,
638         .xtal_freq     = TDA10046_XTAL_16M,
639         .agc_config    = TDA10046_AGC_TDA827X,
640         .gpio_config   = TDA10046_GP01_I,
641         .if_freq       = TDA10046_FREQ_045,
642         .i2c_gate      = 0x4b,
643         .tuner_address = 0x61,
644         .tuner_config  = 2,
645         .antenna_switch= 1,
646         .request_firmware = philips_tda1004x_request_firmware
647 };
648
649 static struct tda1004x_config pinnacle_pctv_310i_config = {
650         .demod_address = 0x08,
651         .invert        = 1,
652         .invert_oclk   = 0,
653         .xtal_freq     = TDA10046_XTAL_16M,
654         .agc_config    = TDA10046_AGC_TDA827X,
655         .gpio_config   = TDA10046_GP11_I,
656         .if_freq       = TDA10046_FREQ_045,
657         .i2c_gate      = 0x4b,
658         .tuner_address = 0x61,
659         .tuner_config  = 1,
660         .request_firmware = philips_tda1004x_request_firmware
661 };
662
663 static struct tda1004x_config hauppauge_hvr_1110_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_GP11_I,
670         .if_freq       = TDA10046_FREQ_045,
671         .i2c_gate      = 0x4b,
672         .tuner_address = 0x61,
673         .tuner_config  = 1,
674         .request_firmware = philips_tda1004x_request_firmware
675 };
676
677 static struct tda1004x_config asus_p7131_dual_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         .tuner_config  = 0,
688         .antenna_switch= 2,
689         .request_firmware = philips_tda1004x_request_firmware
690 };
691
692 static struct tda1004x_config lifeview_trio_config = {
693         .demod_address = 0x09,
694         .invert        = 1,
695         .invert_oclk   = 0,
696         .xtal_freq     = TDA10046_XTAL_16M,
697         .agc_config    = TDA10046_AGC_TDA827X,
698         .gpio_config   = TDA10046_GP00_I,
699         .if_freq       = TDA10046_FREQ_045,
700         .tuner_address = 0x60,
701         .request_firmware = philips_tda1004x_request_firmware
702 };
703
704 static struct tda1004x_config tevion_dvbt220rf_config = {
705         .demod_address = 0x08,
706         .invert        = 1,
707         .invert_oclk   = 0,
708         .xtal_freq     = TDA10046_XTAL_16M,
709         .agc_config    = TDA10046_AGC_TDA827X,
710         .gpio_config   = TDA10046_GP11_I,
711         .if_freq       = TDA10046_FREQ_045,
712         .tuner_address = 0x60,
713         .request_firmware = philips_tda1004x_request_firmware
714 };
715
716 static struct tda1004x_config md8800_dvbt_config = {
717         .demod_address = 0x08,
718         .invert        = 1,
719         .invert_oclk   = 0,
720         .xtal_freq     = TDA10046_XTAL_16M,
721         .agc_config    = TDA10046_AGC_TDA827X,
722         .gpio_config   = TDA10046_GP01_I,
723         .if_freq       = TDA10046_FREQ_045,
724         .i2c_gate      = 0x4b,
725         .tuner_address = 0x60,
726         .tuner_config  = 0,
727         .request_firmware = philips_tda1004x_request_firmware
728 };
729
730 static struct tda1004x_config asus_p7131_4871_config = {
731         .demod_address = 0x08,
732         .invert        = 1,
733         .invert_oclk   = 0,
734         .xtal_freq     = TDA10046_XTAL_16M,
735         .agc_config    = TDA10046_AGC_TDA827X,
736         .gpio_config   = TDA10046_GP01_I,
737         .if_freq       = TDA10046_FREQ_045,
738         .i2c_gate      = 0x4b,
739         .tuner_address = 0x61,
740         .tuner_config  = 2,
741         .antenna_switch= 2,
742         .request_firmware = philips_tda1004x_request_firmware
743 };
744
745 static struct tda1004x_config asus_p7131_hybrid_lna_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         .tuner_config  = 2,
756         .antenna_switch= 2,
757         .request_firmware = philips_tda1004x_request_firmware
758 };
759
760 static struct tda1004x_config kworld_dvb_t_210_config = {
761         .demod_address = 0x08,
762         .invert        = 1,
763         .invert_oclk   = 0,
764         .xtal_freq     = TDA10046_XTAL_16M,
765         .agc_config    = TDA10046_AGC_TDA827X,
766         .gpio_config   = TDA10046_GP11_I,
767         .if_freq       = TDA10046_FREQ_045,
768         .i2c_gate      = 0x4b,
769         .tuner_address = 0x61,
770         .tuner_config  = 2,
771         .antenna_switch= 1,
772         .request_firmware = philips_tda1004x_request_firmware
773 };
774
775 static struct tda1004x_config avermedia_super_007_config = {
776         .demod_address = 0x08,
777         .invert        = 1,
778         .invert_oclk   = 0,
779         .xtal_freq     = TDA10046_XTAL_16M,
780         .agc_config    = TDA10046_AGC_TDA827X,
781         .gpio_config   = TDA10046_GP01_I,
782         .if_freq       = TDA10046_FREQ_045,
783         .i2c_gate      = 0x4b,
784         .tuner_address = 0x60,
785         .tuner_config  = 0,
786         .antenna_switch= 1,
787         .request_firmware = philips_tda1004x_request_firmware
788 };
789
790 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
791         .demod_address = 0x08,
792         .invert        = 1,
793         .invert_oclk   = 0,
794         .xtal_freq     = TDA10046_XTAL_16M,
795         .agc_config    = TDA10046_AGC_TDA827X,
796         .gpio_config   = TDA10046_GP01_I,
797         .if_freq       = TDA10046_FREQ_045,
798         .i2c_gate      = 0x42,
799         .tuner_address = 0x61,
800         .tuner_config  = 2,
801         .antenna_switch = 1,
802         .request_firmware = philips_tda1004x_request_firmware
803 };
804
805 /* ------------------------------------------------------------------
806  * special case: this card uses saa713x GPIO22 for the mode switch
807  */
808
809 static int ads_duo_tuner_init(struct dvb_frontend *fe)
810 {
811         struct saa7134_dev *dev = fe->dvb->priv;
812         philips_tda827x_tuner_init(fe);
813         /* route TDA8275a AGC input to the channel decoder */
814         saa7134_set_gpio(dev, 22, 1);
815         return 0;
816 }
817
818 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
819 {
820         struct saa7134_dev *dev = fe->dvb->priv;
821         /* route TDA8275a AGC input to the analog IF chip*/
822         saa7134_set_gpio(dev, 22, 0);
823         philips_tda827x_tuner_sleep(fe);
824         return 0;
825 }
826
827 static struct tda827x_config ads_duo_cfg = {
828         .lna_gain = philips_tda827x_lna_gain,
829         .init = ads_duo_tuner_init,
830         .sleep = ads_duo_tuner_sleep
831 };
832
833 static struct tda1004x_config ads_tech_duo_config = {
834         .demod_address = 0x08,
835         .invert        = 1,
836         .invert_oclk   = 0,
837         .xtal_freq     = TDA10046_XTAL_16M,
838         .agc_config    = TDA10046_AGC_TDA827X,
839         .gpio_config   = TDA10046_GP00_I,
840         .if_freq       = TDA10046_FREQ_045,
841         .tuner_address = 0x61,
842         .request_firmware = philips_tda1004x_request_firmware
843 };
844
845 /* ==================================================================
846  * tda10086 based DVB-S cards, helper functions
847  */
848
849 static struct tda10086_config flydvbs = {
850         .demod_address = 0x0e,
851         .invert = 0,
852         .diseqc_tone = 0,
853 };
854
855 /* ------------------------------------------------------------------
856  * special case: lnb supply is connected to the gated i2c
857  */
858
859 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
860 {
861         int res = -EIO;
862         struct saa7134_dev *dev = fe->dvb->priv;
863         if (fe->ops.i2c_gate_ctrl) {
864                 fe->ops.i2c_gate_ctrl(fe, 1);
865                 if (dev->original_set_voltage)
866                         res = dev->original_set_voltage(fe, voltage);
867                 fe->ops.i2c_gate_ctrl(fe, 0);
868         }
869         return res;
870 };
871
872 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
873 {
874         int res = -EIO;
875         struct saa7134_dev *dev = fe->dvb->priv;
876         if (fe->ops.i2c_gate_ctrl) {
877                 fe->ops.i2c_gate_ctrl(fe, 1);
878                 if (dev->original_set_high_voltage)
879                         res = dev->original_set_high_voltage(fe, arg);
880                 fe->ops.i2c_gate_ctrl(fe, 0);
881         }
882         return res;
883 };
884
885 /* ==================================================================
886  * nxt200x based ATSC cards, helper functions
887  */
888
889 static struct nxt200x_config avertvhda180 = {
890         .demod_address    = 0x0a,
891 };
892
893 static struct nxt200x_config kworldatsc110 = {
894         .demod_address    = 0x0a,
895 };
896
897 /* ==================================================================
898  * Core code
899  */
900
901 static int dvb_init(struct saa7134_dev *dev)
902 {
903         int ret;
904         int attach_xc3028 = 0;
905
906         /* init struct videobuf_dvb */
907         dev->ts.nr_bufs    = 32;
908         dev->ts.nr_packets = 32*4;
909         dev->dvb.name = dev->name;
910         videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
911                             &dev->pci->dev, &dev->slock,
912                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
913                             V4L2_FIELD_ALTERNATE,
914                             sizeof(struct saa7134_buf),
915                             dev);
916
917         switch (dev->board) {
918         case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
919                 dprintk("pinnacle 300i dvb setup\n");
920                 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
921                                                &dev->i2c_adap);
922                 if (dev->dvb.frontend) {
923                         dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
924                 }
925                 break;
926         case SAA7134_BOARD_AVERMEDIA_777:
927         case SAA7134_BOARD_AVERMEDIA_A16AR:
928                 dprintk("avertv 777 dvb setup\n");
929                 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
930                                                &dev->i2c_adap);
931                 if (dev->dvb.frontend) {
932                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
933                                    NULL, DVB_PLL_PHILIPS_TD1316);
934                 }
935                 break;
936         case SAA7134_BOARD_MD7134:
937                 dev->dvb.frontend = dvb_attach(tda10046_attach,
938                                                &medion_cardbus,
939                                                &dev->i2c_adap);
940                 if (dev->dvb.frontend) {
941                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
942                                    &dev->i2c_adap, DVB_PLL_FMD1216ME);
943                 }
944                 break;
945         case SAA7134_BOARD_PHILIPS_TOUGH:
946                 dev->dvb.frontend = dvb_attach(tda10046_attach,
947                                                &philips_tu1216_60_config,
948                                                &dev->i2c_adap);
949                 if (dev->dvb.frontend) {
950                         dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
951                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
952                 }
953                 break;
954         case SAA7134_BOARD_FLYDVBTDUO:
955         case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
956                 configure_tda827x_fe(dev, &tda827x_lifeview_config);
957                 break;
958         case SAA7134_BOARD_PHILIPS_EUROPA:
959         case SAA7134_BOARD_VIDEOMATE_DVBT_300:
960                 dev->dvb.frontend = dvb_attach(tda10046_attach,
961                                                &philips_europa_config,
962                                                &dev->i2c_adap);
963                 if (dev->dvb.frontend) {
964                         dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
965                         dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
966                         dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
967                         dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
968                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
969                 }
970                 break;
971         case SAA7134_BOARD_VIDEOMATE_DVBT_200:
972                 dev->dvb.frontend = dvb_attach(tda10046_attach,
973                                                &philips_tu1216_61_config,
974                                                &dev->i2c_adap);
975                 if (dev->dvb.frontend) {
976                         dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
977                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
978                 }
979                 break;
980         case SAA7134_BOARD_KWORLD_DVBT_210:
981                 configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
982                 break;
983         case SAA7134_BOARD_PHILIPS_TIGER:
984                 configure_tda827x_fe(dev, &philips_tiger_config);
985                 break;
986         case SAA7134_BOARD_PINNACLE_PCTV_310i:
987                 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
988                 break;
989         case SAA7134_BOARD_HAUPPAUGE_HVR1110:
990                 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
991                 break;
992         case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
993                 configure_tda827x_fe(dev, &asus_p7131_dual_config);
994                 break;
995         case SAA7134_BOARD_FLYDVBT_LR301:
996                 configure_tda827x_fe(dev, &tda827x_lifeview_config);
997                 break;
998         case SAA7134_BOARD_FLYDVB_TRIO:
999                 if(! use_frontend) {    /* terrestrial */
1000                         configure_tda827x_fe(dev, &lifeview_trio_config);
1001                 } else {                /* satellite */
1002                         dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1003                         if (dev->dvb.frontend) {
1004                                 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1005                                                                         &dev->i2c_adap, 0) == NULL) {
1006                                         wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1007                                 }
1008                                 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1009                                                                                 0x08, 0, 0) == NULL) {
1010                                         wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1011                                 }
1012                         }
1013                 }
1014                 break;
1015         case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1016         case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1017                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1018                                                &ads_tech_duo_config,
1019                                                &dev->i2c_adap);
1020                 if (dev->dvb.frontend) {
1021                         if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1022                                    ads_tech_duo_config.tuner_address,
1023                                    &dev->i2c_adap,&ads_duo_cfg) == NULL) {
1024                                 wprintk("no tda827x tuner found at addr: %02x\n",
1025                                         ads_tech_duo_config.tuner_address);
1026                         }
1027                 }
1028                 break;
1029         case SAA7134_BOARD_TEVION_DVBT_220RF:
1030                 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1031                 break;
1032         case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1033                 if (!use_frontend) {     /* terrestrial */
1034                         configure_tda827x_fe(dev, &md8800_dvbt_config);
1035                 } else {        /* satellite */
1036                         dev->dvb.frontend = dvb_attach(tda10086_attach,
1037                                                         &flydvbs, &dev->i2c_adap);
1038                         if (dev->dvb.frontend) {
1039                                 struct dvb_frontend *fe;
1040                                 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1041                                                 0x60, &dev->i2c_adap, 0) == NULL)
1042                                         wprintk("%s: Medion Quadro, no tda826x "
1043                                                 "found !\n", __FUNCTION__);
1044                                 /* Note 10.2. Hac
1045                                  * up to here. configuration for ctx948 and and one branch
1046                                  * of md8800 should be identical
1047                                  */
1048                                 /* we need to open the i2c gate (we know it exists) */
1049                                 fe = dev->dvb.frontend;
1050                                 fe->ops.i2c_gate_ctrl(fe, 1);
1051                                 if (dvb_attach(isl6405_attach, fe,
1052                                                 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1053                                         wprintk("%s: Medion Quadro, no ISL6405 "
1054                                                 "found !\n", __FUNCTION__);
1055                                 fe->ops.i2c_gate_ctrl(fe, 0);
1056                                 dev->original_set_voltage = fe->ops.set_voltage;
1057                                 fe->ops.set_voltage = md8800_set_voltage;
1058                                 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1059                                 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1060                         }
1061                 }
1062                 break;
1063         case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1064                 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1065                                                &dev->i2c_adap);
1066                 if (dev->dvb.frontend) {
1067                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1068                                    NULL, DVB_PLL_TDHU2);
1069                 }
1070                 break;
1071         case SAA7134_BOARD_KWORLD_ATSC110:
1072                 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1073                                                &dev->i2c_adap);
1074                 if (dev->dvb.frontend) {
1075                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1076                                    NULL, DVB_PLL_TUV1236D);
1077                 }
1078                 break;
1079         case SAA7134_BOARD_FLYDVBS_LR300:
1080                 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1081                                                &dev->i2c_adap);
1082                 if (dev->dvb.frontend) {
1083                         if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1084                                        &dev->i2c_adap, 0) == NULL) {
1085                                 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1086                         }
1087                         if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1088                                        &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1089                                 wprintk("%s: No ISL6421 found!\n", __FUNCTION__);
1090                         }
1091                 }
1092                 break;
1093         case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1094                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1095                                                &medion_cardbus,
1096                                                &dev->i2c_adap);
1097                 if (dev->dvb.frontend) {
1098                         dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1099                         dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1100
1101                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
1102                                    &dev->i2c_adap, DVB_PLL_FMD1216ME);
1103                 }
1104                 break;
1105         case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1106                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1107                                 &philips_europa_config,
1108                                 &dev->i2c_adap);
1109                 if (dev->dvb.frontend) {
1110                         dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1111                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1112                 }
1113                 break;
1114         case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1115                 configure_tda827x_fe(dev, &cinergy_ht_config);
1116                 break;
1117         case SAA7134_BOARD_CINERGY_HT_PCI:
1118                 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1119                 break;
1120         case SAA7134_BOARD_PHILIPS_TIGER_S:
1121                 configure_tda827x_fe(dev, &philips_tiger_s_config);
1122                 break;
1123         case SAA7134_BOARD_ASUS_P7131_4871:
1124                 configure_tda827x_fe(dev, &asus_p7131_4871_config);
1125                 break;
1126         case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1127                 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1128                 break;
1129         case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1130                 configure_tda827x_fe(dev, &avermedia_super_007_config);
1131                 break;
1132         case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1133                 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config);
1134                 break;
1135         case SAA7134_BOARD_PHILIPS_SNAKE:
1136                 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1137                                                 &dev->i2c_adap);
1138                 if (dev->dvb.frontend) {
1139                         if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1140                                         &dev->i2c_adap, 0) == NULL)
1141                                 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1142                         if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1143                                         &dev->i2c_adap, 0, 0) == NULL)
1144                                 wprintk("%s: No lnbp21 found!\n", __FUNCTION__);
1145                 }
1146                 break;
1147         case SAA7134_BOARD_CREATIX_CTX953:
1148                 configure_tda827x_fe(dev, &md8800_dvbt_config);
1149                 break;
1150         case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1151                 configure_tda827x_fe(dev, &philips_tiger_s_config);
1152                 break;
1153         case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1154                 dev->dvb.frontend = dvb_attach(mt352_attach,
1155                                                &avermedia_e506r_mt352_dev,
1156                                                &dev->i2c_adap);
1157                 attach_xc3028 = 1;
1158                 break;
1159         default:
1160                 wprintk("Huh? unknown DVB card?\n");
1161                 break;
1162         }
1163
1164         if (attach_xc3028) {
1165                 struct dvb_frontend *fe;
1166                 struct xc2028_config cfg = {
1167                         .i2c_adap  = &dev->i2c_adap,
1168                         .i2c_addr  = 0x61,
1169                         .video_dev = dev,
1170                 };
1171                 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1172                 if (!fe) {
1173                         printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1174                                dev->name);
1175                         dvb_frontend_detach(dev->dvb.frontend);
1176                         dvb_unregister_frontend(dev->dvb.frontend);
1177                         dev->dvb.frontend = NULL;
1178                         return -1;
1179                 }
1180         }
1181
1182         if (NULL == dev->dvb.frontend) {
1183                 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1184                 return -1;
1185         }
1186
1187         /* register everything else */
1188         ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1189
1190         /* this sequence is necessary to make the tda1004x load its firmware
1191          * and to enter analog mode of hybrid boards
1192          */
1193         if (!ret) {
1194                 if (dev->dvb.frontend->ops.init)
1195                         dev->dvb.frontend->ops.init(dev->dvb.frontend);
1196                 if (dev->dvb.frontend->ops.sleep)
1197                         dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1198                 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1199                         dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1200         }
1201         return ret;
1202 }
1203
1204 static int dvb_fini(struct saa7134_dev *dev)
1205 {
1206         /* FIXME: I suspect that this code is bogus, since the entry for
1207            Pinnacle 300I DVB-T PAL already defines the proper init to allow
1208            the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1209          */
1210         if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1211                 struct v4l2_priv_tun_config tda9887_cfg;
1212                 static int on  = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1213
1214                 tda9887_cfg.tuner = TUNER_TDA9887;
1215                 tda9887_cfg.priv  = &on;
1216
1217                 /* otherwise we don't detect the tuner on next insmod */
1218                 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1219         }
1220
1221         videobuf_dvb_unregister(&dev->dvb);
1222         return 0;
1223 }
1224
1225 static struct saa7134_mpeg_ops dvb_ops = {
1226         .type          = SAA7134_MPEG_DVB,
1227         .init          = dvb_init,
1228         .fini          = dvb_fini,
1229 };
1230
1231 static int __init dvb_register(void)
1232 {
1233         return saa7134_ts_register(&dvb_ops);
1234 }
1235
1236 static void __exit dvb_unregister(void)
1237 {
1238         saa7134_ts_unregister(&dvb_ops);
1239 }
1240
1241 module_init(dvb_register);
1242 module_exit(dvb_unregister);
1243
1244 /* ------------------------------------------------------------------ */
1245 /*
1246  * Local variables:
1247  * c-basic-offset: 8
1248  * End:
1249  */