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