V4L/DVB (5632): Dvb-pll: pass dvb_frontend_parameters to generic set() function
[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
42 #include "tda10086.h"
43 #include "tda826x.h"
44 #include "tda827x.h"
45 #include "isl6421.h"
46
47 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48 MODULE_LICENSE("GPL");
49
50 static unsigned int antenna_pwr = 0;
51
52 module_param(antenna_pwr, int, 0444);
53 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
54
55 static int use_frontend = 0;
56 module_param(use_frontend, int, 0644);
57 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
58
59 static int debug = 0;
60 module_param(debug, int, 0644);
61 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
62
63 #define dprintk(fmt, arg...)    do { if (debug) \
64         printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
65
66 /* Print a warning */
67 #define wprintk(fmt, arg...) \
68         printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
69
70 /* ------------------------------------------------------------------
71  * mt352 based DVB-T cards
72  */
73
74 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
75 {
76         u32 ok;
77
78         if (!on) {
79                 saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
80                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
81                 return 0;
82         }
83
84         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
85         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
86         udelay(10);
87
88         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 28));
89         saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
90         udelay(10);
91         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 28));
92         udelay(10);
93         ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
94         dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off");
95
96         if (!ok)
97                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
98         return ok;
99 }
100
101 static int mt352_pinnacle_init(struct dvb_frontend* fe)
102 {
103         static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x28 };
104         static u8 reset []         = { RESET,      0x80 };
105         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
106         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
107         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
108         static u8 fsm_ctl_cfg[]    = { 0x7b,       0x04 };
109         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x0f };
110         static u8 scan_ctl_cfg []  = { SCAN_CTL,   0x0d };
111         static u8 irq_cfg []       = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
112         struct saa7134_dev *dev= fe->dvb->priv;
113
114         dprintk("%s called\n", __FUNCTION__);
115
116         mt352_write(fe, clock_config,   sizeof(clock_config));
117         udelay(200);
118         mt352_write(fe, reset,          sizeof(reset));
119         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
120         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
121         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
122         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
123
124         mt352_write(fe, fsm_ctl_cfg,    sizeof(fsm_ctl_cfg));
125         mt352_write(fe, scan_ctl_cfg,   sizeof(scan_ctl_cfg));
126         mt352_write(fe, irq_cfg,        sizeof(irq_cfg));
127
128         return 0;
129 }
130
131 static int mt352_aver777_init(struct dvb_frontend* fe)
132 {
133         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x2d };
134         static u8 reset []         = { RESET,      0x80 };
135         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
136         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
137         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
138
139         mt352_write(fe, clock_config,   sizeof(clock_config));
140         udelay(200);
141         mt352_write(fe, reset,          sizeof(reset));
142         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
143         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
144         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
145
146         return 0;
147 }
148
149 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
150                                            struct dvb_frontend_parameters* params)
151 {
152         u8 off[] = { 0x00, 0xf1};
153         u8 on[]  = { 0x00, 0x71};
154         struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
155
156         struct saa7134_dev *dev = fe->dvb->priv;
157         struct v4l2_frequency f;
158
159         /* set frequency (mt2050) */
160         f.tuner     = 0;
161         f.type      = V4L2_TUNER_DIGITAL_TV;
162         f.frequency = params->frequency / 1000 * 16 / 1000;
163         if (fe->ops.i2c_gate_ctrl)
164                 fe->ops.i2c_gate_ctrl(fe, 1);
165         i2c_transfer(&dev->i2c_adap, &msg, 1);
166         saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
167         msg.buf = on;
168         if (fe->ops.i2c_gate_ctrl)
169                 fe->ops.i2c_gate_ctrl(fe, 1);
170         i2c_transfer(&dev->i2c_adap, &msg, 1);
171
172         pinnacle_antenna_pwr(dev, antenna_pwr);
173
174         /* mt352 setup */
175         return mt352_pinnacle_init(fe);
176 }
177
178 static int mt352_aver777_tuner_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
179 {
180         if (buf_len < 5)
181                 return -EINVAL;
182
183         pllbuf[0] = 0x61;
184         dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1, params);
185         return 5;
186 }
187
188 static struct mt352_config pinnacle_300i = {
189         .demod_address = 0x3c >> 1,
190         .adc_clock     = 20333,
191         .if2           = 36150,
192         .no_tuner      = 1,
193         .demod_init    = mt352_pinnacle_init,
194 };
195
196 static struct mt352_config avermedia_777 = {
197         .demod_address = 0xf,
198         .demod_init    = mt352_aver777_init,
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 /* ------------------------------------------------------------------ */
444
445 static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
446 {
447         struct saa7134_dev *dev = fe->dvb->priv;
448         struct tda1004x_state *state = fe->demodulator_priv;
449         u8 addr = state->config->tuner_address;
450         /* this message is to set up ATC and ALC */
451         static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
452         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
453
454         if (fe->ops.i2c_gate_ctrl)
455                 fe->ops.i2c_gate_ctrl(fe, 1);
456         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
457                 return -EIO;
458         msleep(1);
459
460         return 0;
461 }
462
463 static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
464 {
465         struct saa7134_dev *dev = fe->dvb->priv;
466         struct tda1004x_state *state = fe->demodulator_priv;
467         u8 addr = state->config->tuner_address;
468         /* this message actually turns the tuner back to analog mode */
469         u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
470         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
471
472         if (fe->ops.i2c_gate_ctrl)
473                 fe->ops.i2c_gate_ctrl(fe, 1);
474         i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
475         msleep(1);
476         fmd1216_init[2] = 0x86;
477         fmd1216_init[3] = 0x54;
478         if (fe->ops.i2c_gate_ctrl)
479                 fe->ops.i2c_gate_ctrl(fe, 1);
480         i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
481         msleep(1);
482         return 0;
483 }
484
485 static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
486 {
487         struct saa7134_dev *dev = fe->dvb->priv;
488         struct tda1004x_state *state = fe->demodulator_priv;
489         u8 addr = state->config->tuner_address;
490         u8 tuner_buf[4];
491         struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
492                         sizeof(tuner_buf) };
493         int tuner_frequency = 0;
494         int divider = 0;
495         u8 band, mode, cp;
496
497         /* determine charge pump */
498         tuner_frequency = params->frequency + 36130000;
499         if (tuner_frequency < 87000000)
500                 return -EINVAL;
501         /* low band */
502         else if (tuner_frequency < 180000000) {
503                 band = 1;
504                 mode = 7;
505                 cp   = 0;
506         } else if (tuner_frequency < 195000000) {
507                 band = 1;
508                 mode = 6;
509                 cp   = 1;
510         /* mid band     */
511         } else if (tuner_frequency < 366000000) {
512                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
513                         band = 10;
514                 } else {
515                         band = 2;
516                 }
517                 mode = 7;
518                 cp   = 0;
519         } else if (tuner_frequency < 478000000) {
520                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
521                         band = 10;
522                 } else {
523                         band = 2;
524                 }
525                 mode = 6;
526                 cp   = 1;
527         /* high band */
528         } else if (tuner_frequency < 662000000) {
529                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
530                         band = 12;
531                 } else {
532                         band = 4;
533                 }
534                 mode = 7;
535                 cp   = 0;
536         } else if (tuner_frequency < 840000000) {
537                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
538                         band = 12;
539                 } else {
540                         band = 4;
541                 }
542                 mode = 6;
543                 cp   = 1;
544         } else {
545                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
546                         band = 12;
547                 } else {
548                         band = 4;
549                 }
550                 mode = 7;
551                 cp   = 1;
552
553         }
554         /* calculate divisor */
555         /* ((36166000 + Finput) / 166666) rounded! */
556         divider = (tuner_frequency + 83333) / 166667;
557
558         /* setup tuner buffer */
559         tuner_buf[0] = (divider >> 8) & 0x7f;
560         tuner_buf[1] = divider & 0xff;
561         tuner_buf[2] = 0x80 | (cp << 6) | (mode  << 3) | 4;
562         tuner_buf[3] = 0x40 | band;
563
564         if (fe->ops.i2c_gate_ctrl)
565                 fe->ops.i2c_gate_ctrl(fe, 1);
566         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
567                 wprintk("could not write to tuner at addr: 0x%02x\n",
568                         addr << 1);
569                 return -EIO;
570         }
571         return 0;
572 }
573
574 static struct tda1004x_config medion_cardbus = {
575         .demod_address = 0x08,
576         .invert        = 1,
577         .invert_oclk   = 0,
578         .xtal_freq     = TDA10046_XTAL_16M,
579         .agc_config    = TDA10046_AGC_IFO_AUTO_NEG,
580         .if_freq       = TDA10046_FREQ_3613,
581         .tuner_address = 0x61,
582         .request_firmware = philips_tda1004x_request_firmware
583 };
584
585 /* ------------------------------------------------------------------
586  * tda 1004x based cards with philips silicon tuner
587  */
588
589 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
590 {
591         struct saa7134_dev *dev = fe->dvb->priv;
592         struct tda1004x_state *state = fe->demodulator_priv;
593         u8 addr = state->config->i2c_gate;
594         u8 config = state->config->tuner_config;
595         u8 GP00_CF[] = {0x20, 0x01};
596         u8 GP00_LEV[] = {0x22, 0x00};
597
598         struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
599         if (config) {
600                 if (high) {
601                         dprintk("setting LNA to high gain\n");
602                 } else {
603                         dprintk("setting LNA to low gain\n");
604                 }
605         }
606         switch (config) {
607         case 0: /* no LNA */
608                 break;
609         case 1: /* switch is GPIO 0 of tda8290 */
610         case 2:
611                 /* turn Vsync off */
612                 saa7134_set_gpio(dev, 22, 0);
613                 GP00_LEV[1] = high ? 0 : 1;
614                 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
615                         wprintk("could not access tda8290 at addr: 0x%02x\n",
616                                 addr << 1);
617                         return;
618                 }
619                 msg.buf = GP00_LEV;
620                 if (config == 2)
621                         GP00_LEV[1] = high ? 1 : 0;
622                 i2c_transfer(&dev->i2c_adap, &msg, 1);
623                 break;
624         case 3: /* switch with GPIO of saa713x */
625                 saa7134_set_gpio(dev, 22, high);
626                 break;
627         }
628 }
629
630 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
631 {
632         struct tda1004x_state *state = fe->demodulator_priv;
633
634         u8 addr = state->config->i2c_gate;
635         static u8 tda8290_close[] = { 0x21, 0xc0};
636         static u8 tda8290_open[]  = { 0x21, 0x80};
637         struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
638         if (enable) {
639                 tda8290_msg.buf = tda8290_close;
640         } else {
641                 tda8290_msg.buf = tda8290_open;
642         }
643         if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
644                 struct saa7134_dev *dev = fe->dvb->priv;
645                 wprintk("could not access tda8290 I2C gate\n");
646                 return -EIO;
647         }
648         msleep(20);
649         return 0;
650 }
651
652 /* ------------------------------------------------------------------ */
653
654 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
655 {
656         struct saa7134_dev *dev = fe->dvb->priv;
657         struct tda1004x_state *state = fe->demodulator_priv;
658
659         switch (state->config->antenna_switch) {
660         case 0: break;
661         case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
662                 saa7134_set_gpio(dev, 21, 0);
663                 break;
664         case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
665                 saa7134_set_gpio(dev, 21, 1);
666                 break;
667         }
668         return 0;
669 }
670
671 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
672 {
673         struct saa7134_dev *dev = fe->dvb->priv;
674         struct tda1004x_state *state = fe->demodulator_priv;
675
676         switch (state->config->antenna_switch) {
677         case 0: break;
678         case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
679                 saa7134_set_gpio(dev, 21, 1);
680                 break;
681         case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
682                 saa7134_set_gpio(dev, 21, 0);
683                 break;
684         }
685         return 0;
686 }
687
688 static struct tda827x_config tda827x_cfg = {
689         .lna_gain = philips_tda827x_lna_gain,
690         .init = philips_tda827x_tuner_init,
691         .sleep = philips_tda827x_tuner_sleep
692 };
693
694 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
695 {
696         dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
697         if (dev->dvb.frontend) {
698                 if (tda_conf->i2c_gate)
699                         dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
700                 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
701                                                 &dev->i2c_adap,&tda827x_cfg) == NULL) {
702                         wprintk("no tda827x tuner found at addr: %02x\n",
703                                 tda_conf->tuner_address);
704                 }
705         }
706 }
707
708 /* ------------------------------------------------------------------ */
709 static struct tda1004x_config tda827x_lifeview_config = {
710         .demod_address = 0x08,
711         .invert        = 1,
712         .invert_oclk   = 0,
713         .xtal_freq     = TDA10046_XTAL_16M,
714         .agc_config    = TDA10046_AGC_TDA827X,
715         .gpio_config   = TDA10046_GP11_I,
716         .if_freq       = TDA10046_FREQ_045,
717         .tuner_address = 0x60,
718         .request_firmware = philips_tda1004x_request_firmware
719 };
720
721 static struct tda1004x_config philips_tiger_config = {
722         .demod_address = 0x08,
723         .invert        = 1,
724         .invert_oclk   = 0,
725         .xtal_freq     = TDA10046_XTAL_16M,
726         .agc_config    = TDA10046_AGC_TDA827X,
727         .gpio_config   = TDA10046_GP11_I,
728         .if_freq       = TDA10046_FREQ_045,
729         .i2c_gate      = 0x4b,
730         .tuner_address = 0x61,
731         .tuner_config  = 0,
732         .antenna_switch= 1,
733         .request_firmware = philips_tda1004x_request_firmware
734 };
735
736 static struct tda1004x_config cinergy_ht_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_GP01_I,
743         .if_freq       = TDA10046_FREQ_045,
744         .i2c_gate      = 0x4b,
745         .tuner_address = 0x61,
746         .tuner_config  = 0,
747         .request_firmware = philips_tda1004x_request_firmware
748 };
749
750 static struct tda1004x_config cinergy_ht_pci_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         .tuner_config  = 0,
761         .request_firmware = philips_tda1004x_request_firmware
762 };
763
764 static struct tda1004x_config philips_tiger_s_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      = 0x4b,
773         .tuner_address = 0x61,
774         .tuner_config  = 2,
775         .antenna_switch= 1,
776         .request_firmware = philips_tda1004x_request_firmware
777 };
778
779 static struct tda1004x_config pinnacle_pctv_310i_config = {
780         .demod_address = 0x08,
781         .invert        = 1,
782         .invert_oclk   = 0,
783         .xtal_freq     = TDA10046_XTAL_16M,
784         .agc_config    = TDA10046_AGC_TDA827X,
785         .gpio_config   = TDA10046_GP11_I,
786         .if_freq       = TDA10046_FREQ_045,
787         .i2c_gate      = 0x4b,
788         .tuner_address = 0x61,
789         .tuner_config  = 1,
790         .request_firmware = philips_tda1004x_request_firmware
791 };
792
793 static struct tda1004x_config hauppauge_hvr_1110_config = {
794         .demod_address = 0x08,
795         .invert        = 1,
796         .invert_oclk   = 0,
797         .xtal_freq     = TDA10046_XTAL_16M,
798         .agc_config    = TDA10046_AGC_TDA827X,
799         .gpio_config   = TDA10046_GP11_I,
800         .if_freq       = TDA10046_FREQ_045,
801         .i2c_gate      = 0x4b,
802         .tuner_address = 0x61,
803         .request_firmware = philips_tda1004x_request_firmware
804 };
805
806 static struct tda1004x_config asus_p7131_dual_config = {
807         .demod_address = 0x08,
808         .invert        = 1,
809         .invert_oclk   = 0,
810         .xtal_freq     = TDA10046_XTAL_16M,
811         .agc_config    = TDA10046_AGC_TDA827X,
812         .gpio_config   = TDA10046_GP11_I,
813         .if_freq       = TDA10046_FREQ_045,
814         .i2c_gate      = 0x4b,
815         .tuner_address = 0x61,
816         .tuner_config  = 0,
817         .antenna_switch= 2,
818         .request_firmware = philips_tda1004x_request_firmware
819 };
820
821 static struct tda1004x_config lifeview_trio_config = {
822         .demod_address = 0x09,
823         .invert        = 1,
824         .invert_oclk   = 0,
825         .xtal_freq     = TDA10046_XTAL_16M,
826         .agc_config    = TDA10046_AGC_TDA827X,
827         .gpio_config   = TDA10046_GP00_I,
828         .if_freq       = TDA10046_FREQ_045,
829         .tuner_address = 0x60,
830         .request_firmware = philips_tda1004x_request_firmware
831 };
832
833 static struct tda1004x_config tevion_dvbt220rf_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_GP11_I,
840         .if_freq       = TDA10046_FREQ_045,
841         .tuner_address = 0x60,
842         .request_firmware = philips_tda1004x_request_firmware
843 };
844
845 static struct tda1004x_config md8800_dvbt_config = {
846         .demod_address = 0x08,
847         .invert        = 1,
848         .invert_oclk   = 0,
849         .xtal_freq     = TDA10046_XTAL_16M,
850         .agc_config    = TDA10046_AGC_TDA827X,
851         .gpio_config   = TDA10046_GP01_I,
852         .if_freq       = TDA10046_FREQ_045,
853         .i2c_gate      = 0x4b,
854         .tuner_address = 0x60,
855         .tuner_config  = 0,
856         .request_firmware = philips_tda1004x_request_firmware
857 };
858
859 static struct tda1004x_config asus_p7131_4871_config = {
860         .demod_address = 0x08,
861         .invert        = 1,
862         .invert_oclk   = 0,
863         .xtal_freq     = TDA10046_XTAL_16M,
864         .agc_config    = TDA10046_AGC_TDA827X,
865         .gpio_config   = TDA10046_GP01_I,
866         .if_freq       = TDA10046_FREQ_045,
867         .i2c_gate      = 0x4b,
868         .tuner_address = 0x61,
869         .tuner_config  = 2,
870         .antenna_switch= 2,
871         .request_firmware = philips_tda1004x_request_firmware
872 };
873
874 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
875         .demod_address = 0x08,
876         .invert        = 1,
877         .invert_oclk   = 0,
878         .xtal_freq     = TDA10046_XTAL_16M,
879         .agc_config    = TDA10046_AGC_TDA827X,
880         .gpio_config   = TDA10046_GP11_I,
881         .if_freq       = TDA10046_FREQ_045,
882         .i2c_gate      = 0x4b,
883         .tuner_address = 0x61,
884         .tuner_config  = 2,
885         .antenna_switch= 2,
886         .request_firmware = philips_tda1004x_request_firmware
887 };
888 static struct tda1004x_config kworld_dvb_t_210_config = {
889         .demod_address = 0x08,
890         .invert        = 1,
891         .invert_oclk   = 0,
892         .xtal_freq     = TDA10046_XTAL_16M,
893         .agc_config    = TDA10046_AGC_TDA827X,
894         .gpio_config   = TDA10046_GP11_I,
895         .if_freq       = TDA10046_FREQ_045,
896         .i2c_gate      = 0x4b,
897         .tuner_address = 0x61,
898         .tuner_config  = 2,
899         .antenna_switch= 1,
900         .request_firmware = philips_tda1004x_request_firmware
901 };
902 /* ------------------------------------------------------------------
903  * special case: this card uses saa713x GPIO22 for the mode switch
904  */
905
906 static int ads_duo_tuner_init(struct dvb_frontend *fe)
907 {
908         struct saa7134_dev *dev = fe->dvb->priv;
909         philips_tda827x_tuner_init(fe);
910         /* route TDA8275a AGC input to the channel decoder */
911         saa7134_set_gpio(dev, 22, 1);
912         return 0;
913 }
914
915 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
916 {
917         struct saa7134_dev *dev = fe->dvb->priv;
918         /* route TDA8275a AGC input to the analog IF chip*/
919         saa7134_set_gpio(dev, 22, 0);
920         philips_tda827x_tuner_sleep(fe);
921         return 0;
922 }
923
924 static struct tda827x_config ads_duo_cfg = {
925         .lna_gain = philips_tda827x_lna_gain,
926         .init = ads_duo_tuner_init,
927         .sleep = ads_duo_tuner_sleep
928 };
929
930 static struct tda1004x_config ads_tech_duo_config = {
931         .demod_address = 0x08,
932         .invert        = 1,
933         .invert_oclk   = 0,
934         .xtal_freq     = TDA10046_XTAL_16M,
935         .agc_config    = TDA10046_AGC_TDA827X,
936         .gpio_config   = TDA10046_GP00_I,
937         .if_freq       = TDA10046_FREQ_045,
938         .tuner_address = 0x61,
939         .request_firmware = philips_tda1004x_request_firmware
940 };
941
942 /* ==================================================================
943  * tda10086 based DVB-S cards, helper functions
944  */
945
946 static struct tda10086_config flydvbs = {
947         .demod_address = 0x0e,
948         .invert = 0,
949 };
950
951 /* ==================================================================
952  * nxt200x based ATSC cards, helper functions
953  */
954
955 static struct nxt200x_config avertvhda180 = {
956         .demod_address    = 0x0a,
957 };
958
959 static int nxt200x_set_pll_input(u8 *buf, int input)
960 {
961         if (input)
962                 buf[3] |= 0x08;
963         else
964                 buf[3] &= ~0x08;
965         return 0;
966 }
967
968 static struct nxt200x_config kworldatsc110 = {
969         .demod_address    = 0x0a,
970         .set_pll_input    = nxt200x_set_pll_input,
971 };
972
973 /* ==================================================================
974  * Core code
975  */
976
977 static int dvb_init(struct saa7134_dev *dev)
978 {
979         int ret;
980         /* init struct videobuf_dvb */
981         dev->ts.nr_bufs    = 32;
982         dev->ts.nr_packets = 32*4;
983         dev->dvb.name = dev->name;
984         videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
985                             dev->pci, &dev->slock,
986                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
987                             V4L2_FIELD_ALTERNATE,
988                             sizeof(struct saa7134_buf),
989                             dev);
990
991         switch (dev->board) {
992         case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
993                 dprintk("pinnacle 300i dvb setup\n");
994                 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
995                                                &dev->i2c_adap);
996                 if (dev->dvb.frontend) {
997                         dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
998                 }
999                 break;
1000         case SAA7134_BOARD_AVERMEDIA_777:
1001         case SAA7134_BOARD_AVERMEDIA_A16AR:
1002                 dprintk("avertv 777 dvb setup\n");
1003                 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1004                                                &dev->i2c_adap);
1005                 if (dev->dvb.frontend) {
1006                         dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
1007                 }
1008                 break;
1009         case SAA7134_BOARD_MD7134:
1010                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1011                                                &medion_cardbus,
1012                                                &dev->i2c_adap);
1013                 if (dev->dvb.frontend) {
1014                         dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1015                         dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1016                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1017                 }
1018                 break;
1019         case SAA7134_BOARD_PHILIPS_TOUGH:
1020                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1021                                                &philips_tu1216_60_config,
1022                                                &dev->i2c_adap);
1023                 if (dev->dvb.frontend) {
1024                         dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1025                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1026                 }
1027                 break;
1028         case SAA7134_BOARD_FLYDVBTDUO:
1029         case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1030                 configure_tda827x_fe(dev, &tda827x_lifeview_config);
1031                 break;
1032         case SAA7134_BOARD_PHILIPS_EUROPA:
1033         case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1034                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1035                                                &philips_europa_config,
1036                                                &dev->i2c_adap);
1037                 if (dev->dvb.frontend) {
1038                         dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1039                         dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1040                         dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1041                         dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1042                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1043                 }
1044                 break;
1045         case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1046                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1047                                                &philips_tu1216_61_config,
1048                                                &dev->i2c_adap);
1049                 if (dev->dvb.frontend) {
1050                         dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1051                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1052                 }
1053                 break;
1054         case SAA7134_BOARD_KWORLD_DVBT_210:
1055                 configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
1056                 break;
1057         case SAA7134_BOARD_PHILIPS_TIGER:
1058                 configure_tda827x_fe(dev, &philips_tiger_config);
1059                 break;
1060         case SAA7134_BOARD_PINNACLE_PCTV_310i:
1061                 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
1062                 break;
1063         case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1064                 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
1065                 break;
1066         case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1067                 configure_tda827x_fe(dev, &asus_p7131_dual_config);
1068                 break;
1069         case SAA7134_BOARD_FLYDVBT_LR301:
1070                 configure_tda827x_fe(dev, &tda827x_lifeview_config);
1071                 break;
1072         case SAA7134_BOARD_FLYDVB_TRIO:
1073                 if(! use_frontend) {    //terrestrial
1074                         configure_tda827x_fe(dev, &lifeview_trio_config);
1075                 } else {              //satellite
1076                         dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1077                         if (dev->dvb.frontend) {
1078                                 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1079                                                                         &dev->i2c_adap, 0) == NULL) {
1080                                         wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1081                                 }
1082                                 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1083                                                                                 0x08, 0, 0) == NULL) {
1084                                         wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1085                                 }
1086                         }
1087                 }
1088                 break;
1089         case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1090         case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1091                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1092                                                &ads_tech_duo_config,
1093                                                &dev->i2c_adap);
1094                 if (dev->dvb.frontend) {
1095                         if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1096                                    ads_tech_duo_config.tuner_address,
1097                                    &dev->i2c_adap,&ads_duo_cfg) == NULL) {
1098                                 wprintk("no tda827x tuner found at addr: %02x\n",
1099                                         ads_tech_duo_config.tuner_address);
1100                         }
1101                 }
1102                 break;
1103         case SAA7134_BOARD_TEVION_DVBT_220RF:
1104                 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1105                 break;
1106         case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1107                 configure_tda827x_fe(dev, &md8800_dvbt_config);
1108                 break;
1109         case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1110                 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1111                                                &dev->i2c_adap);
1112                 if (dev->dvb.frontend) {
1113                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1114                                    NULL, &dvb_pll_tdhu2);
1115                 }
1116                 break;
1117         case SAA7134_BOARD_KWORLD_ATSC110:
1118                 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1119                                                &dev->i2c_adap);
1120                 if (dev->dvb.frontend) {
1121                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1122                                    NULL, &dvb_pll_tuv1236d);
1123                 }
1124                 break;
1125         case SAA7134_BOARD_FLYDVBS_LR300:
1126                 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1127                                                &dev->i2c_adap);
1128                 if (dev->dvb.frontend) {
1129                         if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1130                                        &dev->i2c_adap, 0) == NULL) {
1131                                 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1132                         }
1133                         if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1134                                        &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1135                                 wprintk("%s: No ISL6421 found!\n", __FUNCTION__);
1136                         }
1137                 }
1138                 break;
1139         case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1140                 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1141                                                     &dev->i2c_adap);
1142                 if (dev->dvb.frontend) {
1143                         dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1144                         dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1145                         dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1146                         dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1147                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1148                 }
1149                 break;
1150         case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1151                 dev->dvb.frontend = dvb_attach(tda10046_attach,
1152                                 &philips_europa_config,
1153                                 &dev->i2c_adap);
1154                 if (dev->dvb.frontend) {
1155                         dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1156                         dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1157                 }
1158                 break;
1159         case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1160                 configure_tda827x_fe(dev, &cinergy_ht_config);
1161                 break;
1162         case SAA7134_BOARD_CINERGY_HT_PCI:
1163                 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1164                 break;
1165         case SAA7134_BOARD_PHILIPS_TIGER_S:
1166                 configure_tda827x_fe(dev, &philips_tiger_s_config);
1167                 break;
1168         case SAA7134_BOARD_ASUS_P7131_4871:
1169                 configure_tda827x_fe(dev, &asus_p7131_4871_config);
1170                 break;
1171         case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1172                 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1173                 break;
1174         default:
1175                 wprintk("Huh? unknown DVB card?\n");
1176                 break;
1177         }
1178
1179         if (NULL == dev->dvb.frontend) {
1180                 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1181                 return -1;
1182         }
1183
1184         /* register everything else */
1185         ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1186
1187         /* this sequence is necessary to make the tda1004x load its firmware
1188          * and to enter analog mode of hybrid boards
1189          */
1190         if (!ret) {
1191                 if (dev->dvb.frontend->ops.init)
1192                         dev->dvb.frontend->ops.init(dev->dvb.frontend);
1193                 if (dev->dvb.frontend->ops.sleep)
1194                         dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1195                 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1196                         dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1197         }
1198         return ret;
1199 }
1200
1201 static int dvb_fini(struct saa7134_dev *dev)
1202 {
1203         static int on  = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1204
1205         switch (dev->board) {
1206         case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1207                 /* otherwise we don't detect the tuner on next insmod */
1208                 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1209                 break;
1210         };
1211         videobuf_dvb_unregister(&dev->dvb);
1212         return 0;
1213 }
1214
1215 static struct saa7134_mpeg_ops dvb_ops = {
1216         .type          = SAA7134_MPEG_DVB,
1217         .init          = dvb_init,
1218         .fini          = dvb_fini,
1219 };
1220
1221 static int __init dvb_register(void)
1222 {
1223         return saa7134_ts_register(&dvb_ops);
1224 }
1225
1226 static void __exit dvb_unregister(void)
1227 {
1228         saa7134_ts_unregister(&dvb_ops);
1229 }
1230
1231 module_init(dvb_register);
1232 module_exit(dvb_unregister);
1233
1234 /* ------------------------------------------------------------------ */
1235 /*
1236  * Local variables:
1237  * c-basic-offset: 8
1238  * End:
1239  */