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