3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * Extended 3 / 2005 by Hartmut Hackmann to support various
6 * cards with the tda10046 DVB-T channel decoder
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.
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.
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.
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>
32 #include "saa7134-reg.h"
34 #include <media/v4l2-common.h>
38 #include "mt352_priv.h" /* FIXME */
47 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48 MODULE_LICENSE("GPL");
50 static unsigned int antenna_pwr
= 0;
52 module_param(antenna_pwr
, int, 0444);
53 MODULE_PARM_DESC(antenna_pwr
,"enable antenna power (Pinnacle 300i)");
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)");
60 module_param(debug
, int, 0644);
61 MODULE_PARM_DESC(debug
, "Turn on/off module debugging (default:off).");
63 #define dprintk(fmt, arg...) do { if (debug) \
64 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
67 #define wprintk(fmt, arg...) \
68 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
70 /* ------------------------------------------------------------------
71 * mt352 based DVB-T cards
74 static int pinnacle_antenna_pwr(struct saa7134_dev
*dev
, int on
)
79 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 26));
80 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
84 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 26));
85 saa_setl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
88 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 28));
89 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 28));
91 saa_setl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 28));
93 ok
= saa_readl(SAA7134_GPIO_GPSTATUS0
) & (1 << 27);
94 dprintk("%s %s\n", __FUNCTION__
, ok
? "on" : "off");
97 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
101 static int mt352_pinnacle_init(struct dvb_frontend
* fe
)
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
;
114 dprintk("%s called\n", __FUNCTION__
);
116 mt352_write(fe
, clock_config
, sizeof(clock_config
));
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
));
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
));
131 static int mt352_aver777_init(struct dvb_frontend
* fe
)
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 };
139 mt352_write(fe
, clock_config
, sizeof(clock_config
));
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
));
149 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend
* fe
,
150 struct dvb_frontend_parameters
* params
)
152 u8 off
[] = { 0x00, 0xf1};
153 u8 on
[] = { 0x00, 0x71};
154 struct i2c_msg msg
= {.addr
=0x43, .flags
=0, .buf
=off
, .len
= sizeof(off
)};
156 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
157 struct v4l2_frequency f
;
159 /* set frequency (mt2050) */
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
);
168 if (fe
->ops
.i2c_gate_ctrl
)
169 fe
->ops
.i2c_gate_ctrl(fe
, 1);
170 i2c_transfer(&dev
->i2c_adap
, &msg
, 1);
172 pinnacle_antenna_pwr(dev
, antenna_pwr
);
175 return mt352_pinnacle_init(fe
);
178 static struct mt352_config pinnacle_300i
= {
179 .demod_address
= 0x3c >> 1,
183 .demod_init
= mt352_pinnacle_init
,
186 static struct mt352_config avermedia_777
= {
187 .demod_address
= 0xf,
188 .demod_init
= mt352_aver777_init
,
191 /* ==================================================================
192 * tda1004x based DVB-T cards, helper functions
195 static int philips_tda1004x_request_firmware(struct dvb_frontend
*fe
,
196 const struct firmware
**fw
, char *name
)
198 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
199 return request_firmware(fw
, name
, &dev
->pci
->dev
);
202 /* ------------------------------------------------------------------
203 * these tuners are tu1216, td1316(a)
206 static int philips_tda6651_pll_set(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
208 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
209 struct tda1004x_state
*state
= fe
->demodulator_priv
;
210 u8 addr
= state
->config
->tuner_address
;
212 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= tuner_buf
,.len
=
214 int tuner_frequency
= 0;
217 /* determine charge pump */
218 tuner_frequency
= params
->frequency
+ 36166000;
219 if (tuner_frequency
< 87000000)
221 else if (tuner_frequency
< 130000000)
223 else if (tuner_frequency
< 160000000)
225 else if (tuner_frequency
< 200000000)
227 else if (tuner_frequency
< 290000000)
229 else if (tuner_frequency
< 420000000)
231 else if (tuner_frequency
< 480000000)
233 else if (tuner_frequency
< 620000000)
235 else if (tuner_frequency
< 830000000)
237 else if (tuner_frequency
< 895000000)
243 if (params
->frequency
< 49000000)
245 else if (params
->frequency
< 161000000)
247 else if (params
->frequency
< 444000000)
249 else if (params
->frequency
< 861000000)
254 /* setup PLL filter */
255 switch (params
->u
.ofdm
.bandwidth
) {
256 case BANDWIDTH_6_MHZ
:
260 case BANDWIDTH_7_MHZ
:
264 case BANDWIDTH_8_MHZ
:
273 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
275 tuner_frequency
= (((params
->frequency
/ 1000) * 6) + 217496) / 1000;
277 /* setup tuner buffer */
278 tuner_buf
[0] = (tuner_frequency
>> 8) & 0x7f;
279 tuner_buf
[1] = tuner_frequency
& 0xff;
281 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
283 if (fe
->ops
.i2c_gate_ctrl
)
284 fe
->ops
.i2c_gate_ctrl(fe
, 1);
285 if (i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1) != 1) {
286 wprintk("could not write to tuner at addr: 0x%02x\n",
294 static int philips_tu1216_init(struct dvb_frontend
*fe
)
296 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
297 struct tda1004x_state
*state
= fe
->demodulator_priv
;
298 u8 addr
= state
->config
->tuner_address
;
299 static u8 tu1216_init
[] = { 0x0b, 0xf5, 0x85, 0xab };
300 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= tu1216_init
,.len
= sizeof(tu1216_init
) };
302 /* setup PLL configuration */
303 if (fe
->ops
.i2c_gate_ctrl
)
304 fe
->ops
.i2c_gate_ctrl(fe
, 1);
305 if (i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1) != 1)
312 /* ------------------------------------------------------------------ */
314 static struct tda1004x_config philips_tu1216_60_config
= {
315 .demod_address
= 0x8,
318 .xtal_freq
= TDA10046_XTAL_4M
,
319 .agc_config
= TDA10046_AGC_DEFAULT
,
320 .if_freq
= TDA10046_FREQ_3617
,
321 .tuner_address
= 0x60,
322 .request_firmware
= philips_tda1004x_request_firmware
325 static struct tda1004x_config philips_tu1216_61_config
= {
327 .demod_address
= 0x8,
330 .xtal_freq
= TDA10046_XTAL_4M
,
331 .agc_config
= TDA10046_AGC_DEFAULT
,
332 .if_freq
= TDA10046_FREQ_3617
,
333 .tuner_address
= 0x61,
334 .request_firmware
= philips_tda1004x_request_firmware
337 /* ------------------------------------------------------------------ */
339 static int philips_td1316_tuner_init(struct dvb_frontend
*fe
)
341 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
342 struct tda1004x_state
*state
= fe
->demodulator_priv
;
343 u8 addr
= state
->config
->tuner_address
;
344 static u8 msg
[] = { 0x0b, 0xf5, 0x86, 0xab };
345 struct i2c_msg init_msg
= {.addr
= addr
,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
347 /* setup PLL configuration */
348 if (fe
->ops
.i2c_gate_ctrl
)
349 fe
->ops
.i2c_gate_ctrl(fe
, 1);
350 if (i2c_transfer(&dev
->i2c_adap
, &init_msg
, 1) != 1)
355 static int philips_td1316_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
357 return philips_tda6651_pll_set(fe
, params
);
360 static int philips_td1316_tuner_sleep(struct dvb_frontend
*fe
)
362 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
363 struct tda1004x_state
*state
= fe
->demodulator_priv
;
364 u8 addr
= state
->config
->tuner_address
;
365 static u8 msg
[] = { 0x0b, 0xdc, 0x86, 0xa4 };
366 struct i2c_msg analog_msg
= {.addr
= addr
,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
368 /* switch the tuner to analog mode */
369 if (fe
->ops
.i2c_gate_ctrl
)
370 fe
->ops
.i2c_gate_ctrl(fe
, 1);
371 if (i2c_transfer(&dev
->i2c_adap
, &analog_msg
, 1) != 1)
376 /* ------------------------------------------------------------------ */
378 static int philips_europa_tuner_init(struct dvb_frontend
*fe
)
380 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
381 static u8 msg
[] = { 0x00, 0x40};
382 struct i2c_msg init_msg
= {.addr
= 0x43,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
385 if (philips_td1316_tuner_init(fe
))
388 if (i2c_transfer(&dev
->i2c_adap
, &init_msg
, 1) != 1)
394 static int philips_europa_tuner_sleep(struct dvb_frontend
*fe
)
396 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
398 static u8 msg
[] = { 0x00, 0x14 };
399 struct i2c_msg analog_msg
= {.addr
= 0x43,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
401 if (philips_td1316_tuner_sleep(fe
))
404 /* switch the board to analog mode */
405 if (fe
->ops
.i2c_gate_ctrl
)
406 fe
->ops
.i2c_gate_ctrl(fe
, 1);
407 i2c_transfer(&dev
->i2c_adap
, &analog_msg
, 1);
411 static int philips_europa_demod_sleep(struct dvb_frontend
*fe
)
413 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
415 if (dev
->original_demod_sleep
)
416 dev
->original_demod_sleep(fe
);
417 fe
->ops
.i2c_gate_ctrl(fe
, 1);
421 static struct tda1004x_config philips_europa_config
= {
423 .demod_address
= 0x8,
426 .xtal_freq
= TDA10046_XTAL_4M
,
427 .agc_config
= TDA10046_AGC_IFO_AUTO_POS
,
428 .if_freq
= TDA10046_FREQ_052
,
429 .tuner_address
= 0x61,
430 .request_firmware
= philips_tda1004x_request_firmware
433 /* ------------------------------------------------------------------ */
435 static struct tda1004x_config medion_cardbus
= {
436 .demod_address
= 0x08,
439 .xtal_freq
= TDA10046_XTAL_16M
,
440 .agc_config
= TDA10046_AGC_IFO_AUTO_NEG
,
441 .if_freq
= TDA10046_FREQ_3613
,
442 .tuner_address
= 0x61,
443 .request_firmware
= philips_tda1004x_request_firmware
446 /* ------------------------------------------------------------------
447 * tda 1004x based cards with philips silicon tuner
450 static void philips_tda827x_lna_gain(struct dvb_frontend
*fe
, int high
)
452 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
453 struct tda1004x_state
*state
= fe
->demodulator_priv
;
454 u8 addr
= state
->config
->i2c_gate
;
455 u8 config
= state
->config
->tuner_config
;
456 u8 GP00_CF
[] = {0x20, 0x01};
457 u8 GP00_LEV
[] = {0x22, 0x00};
459 struct i2c_msg msg
= {.addr
= addr
,.flags
= 0,.buf
= GP00_CF
, .len
= 2};
462 dprintk("setting LNA to high gain\n");
464 dprintk("setting LNA to low gain\n");
470 case 1: /* switch is GPIO 0 of tda8290 */
473 saa7134_set_gpio(dev
, 22, 0);
474 GP00_LEV
[1] = high
? 0 : 1;
475 if (i2c_transfer(&dev
->i2c_adap
, &msg
, 1) != 1) {
476 wprintk("could not access tda8290 at addr: 0x%02x\n",
482 GP00_LEV
[1] = high
? 1 : 0;
483 i2c_transfer(&dev
->i2c_adap
, &msg
, 1);
485 case 3: /* switch with GPIO of saa713x */
486 saa7134_set_gpio(dev
, 22, high
);
491 static int tda8290_i2c_gate_ctrl( struct dvb_frontend
* fe
, int enable
)
493 struct tda1004x_state
*state
= fe
->demodulator_priv
;
495 u8 addr
= state
->config
->i2c_gate
;
496 static u8 tda8290_close
[] = { 0x21, 0xc0};
497 static u8 tda8290_open
[] = { 0x21, 0x80};
498 struct i2c_msg tda8290_msg
= {.addr
= addr
,.flags
= 0, .len
= 2};
500 tda8290_msg
.buf
= tda8290_close
;
502 tda8290_msg
.buf
= tda8290_open
;
504 if (i2c_transfer(state
->i2c
, &tda8290_msg
, 1) != 1) {
505 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
506 wprintk("could not access tda8290 I2C gate\n");
513 /* ------------------------------------------------------------------ */
515 static int philips_tda827x_tuner_init(struct dvb_frontend
*fe
)
517 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
518 struct tda1004x_state
*state
= fe
->demodulator_priv
;
520 switch (state
->config
->antenna_switch
) {
522 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
523 saa7134_set_gpio(dev
, 21, 0);
525 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
526 saa7134_set_gpio(dev
, 21, 1);
532 static int philips_tda827x_tuner_sleep(struct dvb_frontend
*fe
)
534 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
535 struct tda1004x_state
*state
= fe
->demodulator_priv
;
537 switch (state
->config
->antenna_switch
) {
539 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
540 saa7134_set_gpio(dev
, 21, 1);
542 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
543 saa7134_set_gpio(dev
, 21, 0);
549 static struct tda827x_config tda827x_cfg
= {
550 .lna_gain
= philips_tda827x_lna_gain
,
551 .init
= philips_tda827x_tuner_init
,
552 .sleep
= philips_tda827x_tuner_sleep
555 static void configure_tda827x_fe(struct saa7134_dev
*dev
, struct tda1004x_config
*tda_conf
)
557 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
, tda_conf
, &dev
->i2c_adap
);
558 if (dev
->dvb
.frontend
) {
559 if (tda_conf
->i2c_gate
)
560 dev
->dvb
.frontend
->ops
.i2c_gate_ctrl
= tda8290_i2c_gate_ctrl
;
561 if (dvb_attach(tda827x_attach
, dev
->dvb
.frontend
, tda_conf
->tuner_address
,
562 &dev
->i2c_adap
,&tda827x_cfg
) == NULL
) {
563 wprintk("no tda827x tuner found at addr: %02x\n",
564 tda_conf
->tuner_address
);
569 /* ------------------------------------------------------------------ */
570 static struct tda1004x_config tda827x_lifeview_config
= {
571 .demod_address
= 0x08,
574 .xtal_freq
= TDA10046_XTAL_16M
,
575 .agc_config
= TDA10046_AGC_TDA827X
,
576 .gpio_config
= TDA10046_GP11_I
,
577 .if_freq
= TDA10046_FREQ_045
,
578 .tuner_address
= 0x60,
579 .request_firmware
= philips_tda1004x_request_firmware
582 static struct tda1004x_config philips_tiger_config
= {
583 .demod_address
= 0x08,
586 .xtal_freq
= TDA10046_XTAL_16M
,
587 .agc_config
= TDA10046_AGC_TDA827X
,
588 .gpio_config
= TDA10046_GP11_I
,
589 .if_freq
= TDA10046_FREQ_045
,
591 .tuner_address
= 0x61,
594 .request_firmware
= philips_tda1004x_request_firmware
597 static struct tda1004x_config cinergy_ht_config
= {
598 .demod_address
= 0x08,
601 .xtal_freq
= TDA10046_XTAL_16M
,
602 .agc_config
= TDA10046_AGC_TDA827X
,
603 .gpio_config
= TDA10046_GP01_I
,
604 .if_freq
= TDA10046_FREQ_045
,
606 .tuner_address
= 0x61,
608 .request_firmware
= philips_tda1004x_request_firmware
611 static struct tda1004x_config cinergy_ht_pci_config
= {
612 .demod_address
= 0x08,
615 .xtal_freq
= TDA10046_XTAL_16M
,
616 .agc_config
= TDA10046_AGC_TDA827X
,
617 .gpio_config
= TDA10046_GP01_I
,
618 .if_freq
= TDA10046_FREQ_045
,
620 .tuner_address
= 0x60,
622 .request_firmware
= philips_tda1004x_request_firmware
625 static struct tda1004x_config philips_tiger_s_config
= {
626 .demod_address
= 0x08,
629 .xtal_freq
= TDA10046_XTAL_16M
,
630 .agc_config
= TDA10046_AGC_TDA827X
,
631 .gpio_config
= TDA10046_GP01_I
,
632 .if_freq
= TDA10046_FREQ_045
,
634 .tuner_address
= 0x61,
637 .request_firmware
= philips_tda1004x_request_firmware
640 static struct tda1004x_config pinnacle_pctv_310i_config
= {
641 .demod_address
= 0x08,
644 .xtal_freq
= TDA10046_XTAL_16M
,
645 .agc_config
= TDA10046_AGC_TDA827X
,
646 .gpio_config
= TDA10046_GP11_I
,
647 .if_freq
= TDA10046_FREQ_045
,
649 .tuner_address
= 0x61,
651 .request_firmware
= philips_tda1004x_request_firmware
654 static struct tda1004x_config hauppauge_hvr_1110_config
= {
655 .demod_address
= 0x08,
658 .xtal_freq
= TDA10046_XTAL_16M
,
659 .agc_config
= TDA10046_AGC_TDA827X
,
660 .gpio_config
= TDA10046_GP11_I
,
661 .if_freq
= TDA10046_FREQ_045
,
663 .tuner_address
= 0x61,
664 .request_firmware
= philips_tda1004x_request_firmware
667 static struct tda1004x_config asus_p7131_dual_config
= {
668 .demod_address
= 0x08,
671 .xtal_freq
= TDA10046_XTAL_16M
,
672 .agc_config
= TDA10046_AGC_TDA827X
,
673 .gpio_config
= TDA10046_GP11_I
,
674 .if_freq
= TDA10046_FREQ_045
,
676 .tuner_address
= 0x61,
679 .request_firmware
= philips_tda1004x_request_firmware
682 static struct tda1004x_config lifeview_trio_config
= {
683 .demod_address
= 0x09,
686 .xtal_freq
= TDA10046_XTAL_16M
,
687 .agc_config
= TDA10046_AGC_TDA827X
,
688 .gpio_config
= TDA10046_GP00_I
,
689 .if_freq
= TDA10046_FREQ_045
,
690 .tuner_address
= 0x60,
691 .request_firmware
= philips_tda1004x_request_firmware
694 static struct tda1004x_config tevion_dvbt220rf_config
= {
695 .demod_address
= 0x08,
698 .xtal_freq
= TDA10046_XTAL_16M
,
699 .agc_config
= TDA10046_AGC_TDA827X
,
700 .gpio_config
= TDA10046_GP11_I
,
701 .if_freq
= TDA10046_FREQ_045
,
702 .tuner_address
= 0x60,
703 .request_firmware
= philips_tda1004x_request_firmware
706 static struct tda1004x_config md8800_dvbt_config
= {
707 .demod_address
= 0x08,
710 .xtal_freq
= TDA10046_XTAL_16M
,
711 .agc_config
= TDA10046_AGC_TDA827X
,
712 .gpio_config
= TDA10046_GP01_I
,
713 .if_freq
= TDA10046_FREQ_045
,
715 .tuner_address
= 0x60,
717 .request_firmware
= philips_tda1004x_request_firmware
720 static struct tda1004x_config asus_p7131_4871_config
= {
721 .demod_address
= 0x08,
724 .xtal_freq
= TDA10046_XTAL_16M
,
725 .agc_config
= TDA10046_AGC_TDA827X
,
726 .gpio_config
= TDA10046_GP01_I
,
727 .if_freq
= TDA10046_FREQ_045
,
729 .tuner_address
= 0x61,
732 .request_firmware
= philips_tda1004x_request_firmware
735 static struct tda1004x_config asus_p7131_hybrid_lna_config
= {
736 .demod_address
= 0x08,
739 .xtal_freq
= TDA10046_XTAL_16M
,
740 .agc_config
= TDA10046_AGC_TDA827X
,
741 .gpio_config
= TDA10046_GP11_I
,
742 .if_freq
= TDA10046_FREQ_045
,
744 .tuner_address
= 0x61,
747 .request_firmware
= philips_tda1004x_request_firmware
749 static struct tda1004x_config kworld_dvb_t_210_config
= {
750 .demod_address
= 0x08,
753 .xtal_freq
= TDA10046_XTAL_16M
,
754 .agc_config
= TDA10046_AGC_TDA827X
,
755 .gpio_config
= TDA10046_GP11_I
,
756 .if_freq
= TDA10046_FREQ_045
,
758 .tuner_address
= 0x61,
761 .request_firmware
= philips_tda1004x_request_firmware
763 /* ------------------------------------------------------------------
764 * special case: this card uses saa713x GPIO22 for the mode switch
767 static int ads_duo_tuner_init(struct dvb_frontend
*fe
)
769 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
770 philips_tda827x_tuner_init(fe
);
771 /* route TDA8275a AGC input to the channel decoder */
772 saa7134_set_gpio(dev
, 22, 1);
776 static int ads_duo_tuner_sleep(struct dvb_frontend
*fe
)
778 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
779 /* route TDA8275a AGC input to the analog IF chip*/
780 saa7134_set_gpio(dev
, 22, 0);
781 philips_tda827x_tuner_sleep(fe
);
785 static struct tda827x_config ads_duo_cfg
= {
786 .lna_gain
= philips_tda827x_lna_gain
,
787 .init
= ads_duo_tuner_init
,
788 .sleep
= ads_duo_tuner_sleep
791 static struct tda1004x_config ads_tech_duo_config
= {
792 .demod_address
= 0x08,
795 .xtal_freq
= TDA10046_XTAL_16M
,
796 .agc_config
= TDA10046_AGC_TDA827X
,
797 .gpio_config
= TDA10046_GP00_I
,
798 .if_freq
= TDA10046_FREQ_045
,
799 .tuner_address
= 0x61,
800 .request_firmware
= philips_tda1004x_request_firmware
803 /* ==================================================================
804 * tda10086 based DVB-S cards, helper functions
807 static struct tda10086_config flydvbs
= {
808 .demod_address
= 0x0e,
812 /* ==================================================================
813 * nxt200x based ATSC cards, helper functions
816 static struct nxt200x_config avertvhda180
= {
817 .demod_address
= 0x0a,
820 static struct nxt200x_config kworldatsc110
= {
821 .demod_address
= 0x0a,
824 /* ==================================================================
828 static int dvb_init(struct saa7134_dev
*dev
)
831 /* init struct videobuf_dvb */
832 dev
->ts
.nr_bufs
= 32;
833 dev
->ts
.nr_packets
= 32*4;
834 dev
->dvb
.name
= dev
->name
;
835 videobuf_queue_init(&dev
->dvb
.dvbq
, &saa7134_ts_qops
,
836 dev
->pci
, &dev
->slock
,
837 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
838 V4L2_FIELD_ALTERNATE
,
839 sizeof(struct saa7134_buf
),
842 switch (dev
->board
) {
843 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
844 dprintk("pinnacle 300i dvb setup\n");
845 dev
->dvb
.frontend
= dvb_attach(mt352_attach
, &pinnacle_300i
,
847 if (dev
->dvb
.frontend
) {
848 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= mt352_pinnacle_tuner_set_params
;
851 case SAA7134_BOARD_AVERMEDIA_777
:
852 case SAA7134_BOARD_AVERMEDIA_A16AR
:
853 dprintk("avertv 777 dvb setup\n");
854 dev
->dvb
.frontend
= dvb_attach(mt352_attach
, &avermedia_777
,
856 if (dev
->dvb
.frontend
) {
857 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
858 NULL
, DVB_PLL_PHILIPS_TD1316
);
861 case SAA7134_BOARD_MD7134
:
862 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
865 if (dev
->dvb
.frontend
) {
866 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, medion_cardbus
.tuner_address
,
867 &dev
->i2c_adap
, DVB_PLL_FMD1216ME
);
870 case SAA7134_BOARD_PHILIPS_TOUGH
:
871 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
872 &philips_tu1216_60_config
,
874 if (dev
->dvb
.frontend
) {
875 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_tu1216_init
;
876 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_tda6651_pll_set
;
879 case SAA7134_BOARD_FLYDVBTDUO
:
880 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS
:
881 configure_tda827x_fe(dev
, &tda827x_lifeview_config
);
883 case SAA7134_BOARD_PHILIPS_EUROPA
:
884 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
885 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
886 &philips_europa_config
,
888 if (dev
->dvb
.frontend
) {
889 dev
->original_demod_sleep
= dev
->dvb
.frontend
->ops
.sleep
;
890 dev
->dvb
.frontend
->ops
.sleep
= philips_europa_demod_sleep
;
891 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_europa_tuner_init
;
892 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_europa_tuner_sleep
;
893 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_td1316_tuner_set_params
;
896 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
897 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
898 &philips_tu1216_61_config
,
900 if (dev
->dvb
.frontend
) {
901 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_tu1216_init
;
902 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_tda6651_pll_set
;
905 case SAA7134_BOARD_KWORLD_DVBT_210
:
906 configure_tda827x_fe(dev
, &kworld_dvb_t_210_config
);
908 case SAA7134_BOARD_PHILIPS_TIGER
:
909 configure_tda827x_fe(dev
, &philips_tiger_config
);
911 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
912 configure_tda827x_fe(dev
, &pinnacle_pctv_310i_config
);
914 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
915 configure_tda827x_fe(dev
, &hauppauge_hvr_1110_config
);
917 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
918 configure_tda827x_fe(dev
, &asus_p7131_dual_config
);
920 case SAA7134_BOARD_FLYDVBT_LR301
:
921 configure_tda827x_fe(dev
, &tda827x_lifeview_config
);
923 case SAA7134_BOARD_FLYDVB_TRIO
:
924 if(! use_frontend
) { //terrestrial
925 configure_tda827x_fe(dev
, &lifeview_trio_config
);
927 dev
->dvb
.frontend
= dvb_attach(tda10086_attach
, &flydvbs
, &dev
->i2c_adap
);
928 if (dev
->dvb
.frontend
) {
929 if (dvb_attach(tda826x_attach
, dev
->dvb
.frontend
, 0x63,
930 &dev
->i2c_adap
, 0) == NULL
) {
931 wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__
);
933 if (dvb_attach(isl6421_attach
, dev
->dvb
.frontend
, &dev
->i2c_adap
,
934 0x08, 0, 0) == NULL
) {
935 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__
);
940 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331
:
941 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS
:
942 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
943 &ads_tech_duo_config
,
945 if (dev
->dvb
.frontend
) {
946 if (dvb_attach(tda827x_attach
,dev
->dvb
.frontend
,
947 ads_tech_duo_config
.tuner_address
,
948 &dev
->i2c_adap
,&ads_duo_cfg
) == NULL
) {
949 wprintk("no tda827x tuner found at addr: %02x\n",
950 ads_tech_duo_config
.tuner_address
);
954 case SAA7134_BOARD_TEVION_DVBT_220RF
:
955 configure_tda827x_fe(dev
, &tevion_dvbt220rf_config
);
957 case SAA7134_BOARD_MEDION_MD8800_QUADRO
:
958 configure_tda827x_fe(dev
, &md8800_dvbt_config
);
960 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180
:
961 dev
->dvb
.frontend
= dvb_attach(nxt200x_attach
, &avertvhda180
,
963 if (dev
->dvb
.frontend
) {
964 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
965 NULL
, DVB_PLL_TDHU2
);
968 case SAA7134_BOARD_KWORLD_ATSC110
:
969 dev
->dvb
.frontend
= dvb_attach(nxt200x_attach
, &kworldatsc110
,
971 if (dev
->dvb
.frontend
) {
972 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
973 NULL
, DVB_PLL_TUV1236D
);
976 case SAA7134_BOARD_FLYDVBS_LR300
:
977 dev
->dvb
.frontend
= dvb_attach(tda10086_attach
, &flydvbs
,
979 if (dev
->dvb
.frontend
) {
980 if (dvb_attach(tda826x_attach
, dev
->dvb
.frontend
, 0x60,
981 &dev
->i2c_adap
, 0) == NULL
) {
982 wprintk("%s: No tda826x found!\n", __FUNCTION__
);
984 if (dvb_attach(isl6421_attach
, dev
->dvb
.frontend
,
985 &dev
->i2c_adap
, 0x08, 0, 0) == NULL
) {
986 wprintk("%s: No ISL6421 found!\n", __FUNCTION__
);
990 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID
:
991 dev
->dvb
.frontend
= tda10046_attach(&medion_cardbus
,
993 if (dev
->dvb
.frontend
) {
994 dev
->original_demod_sleep
= dev
->dvb
.frontend
->ops
.sleep
;
995 dev
->dvb
.frontend
->ops
.sleep
= philips_europa_demod_sleep
;
997 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, medion_cardbus
.tuner_address
,
998 &dev
->i2c_adap
, DVB_PLL_FMD1216ME
);
1001 case SAA7134_BOARD_VIDEOMATE_DVBT_200A
:
1002 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1003 &philips_europa_config
,
1005 if (dev
->dvb
.frontend
) {
1006 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_td1316_tuner_init
;
1007 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_td1316_tuner_set_params
;
1010 case SAA7134_BOARD_CINERGY_HT_PCMCIA
:
1011 configure_tda827x_fe(dev
, &cinergy_ht_config
);
1013 case SAA7134_BOARD_CINERGY_HT_PCI
:
1014 configure_tda827x_fe(dev
, &cinergy_ht_pci_config
);
1016 case SAA7134_BOARD_PHILIPS_TIGER_S
:
1017 configure_tda827x_fe(dev
, &philips_tiger_s_config
);
1019 case SAA7134_BOARD_ASUS_P7131_4871
:
1020 configure_tda827x_fe(dev
, &asus_p7131_4871_config
);
1022 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
1023 configure_tda827x_fe(dev
, &asus_p7131_hybrid_lna_config
);
1026 wprintk("Huh? unknown DVB card?\n");
1030 if (NULL
== dev
->dvb
.frontend
) {
1031 printk(KERN_ERR
"%s/dvb: frontend initialization failed\n", dev
->name
);
1035 /* register everything else */
1036 ret
= videobuf_dvb_register(&dev
->dvb
, THIS_MODULE
, dev
, &dev
->pci
->dev
);
1038 /* this sequence is necessary to make the tda1004x load its firmware
1039 * and to enter analog mode of hybrid boards
1042 if (dev
->dvb
.frontend
->ops
.init
)
1043 dev
->dvb
.frontend
->ops
.init(dev
->dvb
.frontend
);
1044 if (dev
->dvb
.frontend
->ops
.sleep
)
1045 dev
->dvb
.frontend
->ops
.sleep(dev
->dvb
.frontend
);
1046 if (dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
)
1047 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep(dev
->dvb
.frontend
);
1052 static int dvb_fini(struct saa7134_dev
*dev
)
1054 static int on
= TDA9887_PRESENT
| TDA9887_PORT2_INACTIVE
;
1056 switch (dev
->board
) {
1057 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
1058 /* otherwise we don't detect the tuner on next insmod */
1059 saa7134_i2c_call_clients(dev
,TDA9887_SET_CONFIG
,&on
);
1062 videobuf_dvb_unregister(&dev
->dvb
);
1066 static struct saa7134_mpeg_ops dvb_ops
= {
1067 .type
= SAA7134_MPEG_DVB
,
1072 static int __init
dvb_register(void)
1074 return saa7134_ts_register(&dvb_ops
);
1077 static void __exit
dvb_unregister(void)
1079 saa7134_ts_unregister(&dvb_ops
);
1082 module_init(dvb_register
);
1083 module_exit(dvb_unregister
);
1085 /* ------------------------------------------------------------------ */