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>
36 #include <dvb_frontend.h>
39 #include "mt352_priv.h" /* FIXME */
42 #include "tuner-xc2028.h"
50 #include "tuner-simple.h"
52 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
53 MODULE_LICENSE("GPL");
55 static unsigned int antenna_pwr;
57 module_param(antenna_pwr, int, 0444);
58 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
60 static int use_frontend;
61 module_param(use_frontend, int, 0644);
62 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
65 module_param(debug, int, 0644);
66 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
68 #define dprintk(fmt, arg...) do { if (debug) \
69 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
72 #define wprintk(fmt, arg...) \
73 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
75 /* ------------------------------------------------------------------
76 * mt352 based DVB-T cards
79 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
84 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
85 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
89 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
90 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
93 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
94 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
96 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
98 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
99 dprintk("%s %s\n", __func__, ok ? "on" : "off");
102 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
106 static int mt352_pinnacle_init(struct dvb_frontend* fe)
108 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
109 static u8 reset [] = { RESET, 0x80 };
110 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
111 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
112 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
113 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
114 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
115 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
116 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
117 struct saa7134_dev *dev= fe->dvb->priv;
119 dprintk("%s called\n", __func__);
121 mt352_write(fe, clock_config, sizeof(clock_config));
123 mt352_write(fe, reset, sizeof(reset));
124 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
125 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
126 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
127 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
129 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
130 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
131 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
136 static int mt352_aver777_init(struct dvb_frontend* fe)
138 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
139 static u8 reset [] = { RESET, 0x80 };
140 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
141 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
142 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
144 mt352_write(fe, clock_config, sizeof(clock_config));
146 mt352_write(fe, reset, sizeof(reset));
147 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
148 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
149 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
154 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
155 struct dvb_frontend_parameters* params)
157 u8 off[] = { 0x00, 0xf1};
158 u8 on[] = { 0x00, 0x71};
159 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
161 struct saa7134_dev *dev = fe->dvb->priv;
162 struct v4l2_frequency f;
164 /* set frequency (mt2050) */
166 f.type = V4L2_TUNER_DIGITAL_TV;
167 f.frequency = params->frequency / 1000 * 16 / 1000;
168 if (fe->ops.i2c_gate_ctrl)
169 fe->ops.i2c_gate_ctrl(fe, 1);
170 i2c_transfer(&dev->i2c_adap, &msg, 1);
171 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
173 if (fe->ops.i2c_gate_ctrl)
174 fe->ops.i2c_gate_ctrl(fe, 1);
175 i2c_transfer(&dev->i2c_adap, &msg, 1);
177 pinnacle_antenna_pwr(dev, antenna_pwr);
180 return mt352_pinnacle_init(fe);
183 static struct mt352_config pinnacle_300i = {
184 .demod_address = 0x3c >> 1,
188 .demod_init = mt352_pinnacle_init,
191 static struct mt352_config avermedia_777 = {
192 .demod_address = 0xf,
193 .demod_init = mt352_aver777_init,
196 static struct mt352_config avermedia_e506r_mt352_dev = {
197 .demod_address = (0x1e >> 1),
201 /* ==================================================================
202 * tda1004x based DVB-T cards, helper functions
205 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
206 const struct firmware **fw, char *name)
208 struct saa7134_dev *dev = fe->dvb->priv;
209 return request_firmware(fw, name, &dev->pci->dev);
212 /* ------------------------------------------------------------------
213 * these tuners are tu1216, td1316(a)
216 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
218 struct saa7134_dev *dev = fe->dvb->priv;
219 struct tda1004x_state *state = fe->demodulator_priv;
220 u8 addr = state->config->tuner_address;
222 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
224 int tuner_frequency = 0;
227 /* determine charge pump */
228 tuner_frequency = params->frequency + 36166000;
229 if (tuner_frequency < 87000000)
231 else if (tuner_frequency < 130000000)
233 else if (tuner_frequency < 160000000)
235 else if (tuner_frequency < 200000000)
237 else if (tuner_frequency < 290000000)
239 else if (tuner_frequency < 420000000)
241 else if (tuner_frequency < 480000000)
243 else if (tuner_frequency < 620000000)
245 else if (tuner_frequency < 830000000)
247 else if (tuner_frequency < 895000000)
253 if (params->frequency < 49000000)
255 else if (params->frequency < 161000000)
257 else if (params->frequency < 444000000)
259 else if (params->frequency < 861000000)
264 /* setup PLL filter */
265 switch (params->u.ofdm.bandwidth) {
266 case BANDWIDTH_6_MHZ:
270 case BANDWIDTH_7_MHZ:
274 case BANDWIDTH_8_MHZ:
283 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
285 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
287 /* setup tuner buffer */
288 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
289 tuner_buf[1] = tuner_frequency & 0xff;
291 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
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",
304 static int philips_tu1216_init(struct dvb_frontend *fe)
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) };
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)
322 /* ------------------------------------------------------------------ */
324 static struct tda1004x_config philips_tu1216_60_config = {
325 .demod_address = 0x8,
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
335 static struct tda1004x_config philips_tu1216_61_config = {
337 .demod_address = 0x8,
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
347 /* ------------------------------------------------------------------ */
349 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
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) };
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)
365 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
367 return philips_tda6651_pll_set(fe, params);
370 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
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) };
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)
386 /* ------------------------------------------------------------------ */
388 static int philips_europa_tuner_init(struct dvb_frontend *fe)
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) };
395 if (philips_td1316_tuner_init(fe))
398 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
404 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
406 struct saa7134_dev *dev = fe->dvb->priv;
408 static u8 msg[] = { 0x00, 0x14 };
409 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
411 if (philips_td1316_tuner_sleep(fe))
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);
421 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
423 struct saa7134_dev *dev = fe->dvb->priv;
425 if (dev->original_demod_sleep)
426 dev->original_demod_sleep(fe);
427 fe->ops.i2c_gate_ctrl(fe, 1);
431 static struct tda1004x_config philips_europa_config = {
433 .demod_address = 0x8,
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
443 static struct tda1004x_config medion_cardbus = {
444 .demod_address = 0x08,
447 .xtal_freq = TDA10046_XTAL_16M,
448 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
449 .if_freq = TDA10046_FREQ_3613,
450 .tuner_address = 0x61,
451 .request_firmware = philips_tda1004x_request_firmware
454 /* ------------------------------------------------------------------
455 * tda 1004x based cards with philips silicon tuner
458 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
460 struct tda1004x_state *state = fe->demodulator_priv;
462 u8 addr = state->config->i2c_gate;
463 static u8 tda8290_close[] = { 0x21, 0xc0};
464 static u8 tda8290_open[] = { 0x21, 0x80};
465 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
467 tda8290_msg.buf = tda8290_close;
469 tda8290_msg.buf = tda8290_open;
471 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
472 struct saa7134_dev *dev = fe->dvb->priv;
473 wprintk("could not access tda8290 I2C gate\n");
480 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
482 struct saa7134_dev *dev = fe->dvb->priv;
483 struct tda1004x_state *state = fe->demodulator_priv;
485 switch (state->config->antenna_switch) {
487 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
488 saa7134_set_gpio(dev, 21, 0);
490 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
491 saa7134_set_gpio(dev, 21, 1);
497 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
499 struct saa7134_dev *dev = fe->dvb->priv;
500 struct tda1004x_state *state = fe->demodulator_priv;
502 switch (state->config->antenna_switch) {
504 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
505 saa7134_set_gpio(dev, 21, 1);
507 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
508 saa7134_set_gpio(dev, 21, 0);
514 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *cdec_conf,
515 struct tda827x_config *tuner_conf)
517 dev->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
518 if (dev->dvb.frontend) {
519 if (cdec_conf->i2c_gate)
520 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
521 if (dvb_attach(tda827x_attach, dev->dvb.frontend, cdec_conf->tuner_address,
522 &dev->i2c_adap, tuner_conf) == NULL) {
523 wprintk("no tda827x tuner found at addr: %02x\n",
524 cdec_conf->tuner_address);
529 /* ------------------------------------------------------------------ */
531 static struct tda827x_config tda827x_cfg_0 = {
532 .tuner_callback = saa7134_tuner_callback,
533 .init = philips_tda827x_tuner_init,
534 .sleep = philips_tda827x_tuner_sleep,
539 static struct tda827x_config tda827x_cfg_1 = {
540 .tuner_callback = saa7134_tuner_callback,
541 .init = philips_tda827x_tuner_init,
542 .sleep = philips_tda827x_tuner_sleep,
547 static struct tda827x_config tda827x_cfg_2 = {
548 .tuner_callback = saa7134_tuner_callback,
549 .init = philips_tda827x_tuner_init,
550 .sleep = philips_tda827x_tuner_sleep,
555 static struct tda827x_config tda827x_cfg_2_sw42 = {
556 .tuner_callback = saa7134_tuner_callback,
557 .init = philips_tda827x_tuner_init,
558 .sleep = philips_tda827x_tuner_sleep,
563 /* ------------------------------------------------------------------ */
565 static struct tda1004x_config tda827x_lifeview_config = {
566 .demod_address = 0x08,
569 .xtal_freq = TDA10046_XTAL_16M,
570 .agc_config = TDA10046_AGC_TDA827X,
571 .gpio_config = TDA10046_GP11_I,
572 .if_freq = TDA10046_FREQ_045,
573 .tuner_address = 0x60,
574 .request_firmware = philips_tda1004x_request_firmware
577 static struct tda1004x_config philips_tiger_config = {
578 .demod_address = 0x08,
581 .xtal_freq = TDA10046_XTAL_16M,
582 .agc_config = TDA10046_AGC_TDA827X,
583 .gpio_config = TDA10046_GP11_I,
584 .if_freq = TDA10046_FREQ_045,
586 .tuner_address = 0x61,
588 .request_firmware = philips_tda1004x_request_firmware
591 static struct tda1004x_config cinergy_ht_config = {
592 .demod_address = 0x08,
595 .xtal_freq = TDA10046_XTAL_16M,
596 .agc_config = TDA10046_AGC_TDA827X,
597 .gpio_config = TDA10046_GP01_I,
598 .if_freq = TDA10046_FREQ_045,
600 .tuner_address = 0x61,
601 .request_firmware = philips_tda1004x_request_firmware
604 static struct tda1004x_config cinergy_ht_pci_config = {
605 .demod_address = 0x08,
608 .xtal_freq = TDA10046_XTAL_16M,
609 .agc_config = TDA10046_AGC_TDA827X,
610 .gpio_config = TDA10046_GP01_I,
611 .if_freq = TDA10046_FREQ_045,
613 .tuner_address = 0x60,
614 .request_firmware = philips_tda1004x_request_firmware
617 static struct tda1004x_config philips_tiger_s_config = {
618 .demod_address = 0x08,
621 .xtal_freq = TDA10046_XTAL_16M,
622 .agc_config = TDA10046_AGC_TDA827X,
623 .gpio_config = TDA10046_GP01_I,
624 .if_freq = TDA10046_FREQ_045,
626 .tuner_address = 0x61,
628 .request_firmware = philips_tda1004x_request_firmware
631 static struct tda1004x_config pinnacle_pctv_310i_config = {
632 .demod_address = 0x08,
635 .xtal_freq = TDA10046_XTAL_16M,
636 .agc_config = TDA10046_AGC_TDA827X,
637 .gpio_config = TDA10046_GP11_I,
638 .if_freq = TDA10046_FREQ_045,
640 .tuner_address = 0x61,
641 .request_firmware = philips_tda1004x_request_firmware
644 static struct tda1004x_config hauppauge_hvr_1110_config = {
645 .demod_address = 0x08,
648 .xtal_freq = TDA10046_XTAL_16M,
649 .agc_config = TDA10046_AGC_TDA827X,
650 .gpio_config = TDA10046_GP11_I,
651 .if_freq = TDA10046_FREQ_045,
653 .tuner_address = 0x61,
654 .request_firmware = philips_tda1004x_request_firmware
657 static struct tda1004x_config asus_p7131_dual_config = {
658 .demod_address = 0x08,
661 .xtal_freq = TDA10046_XTAL_16M,
662 .agc_config = TDA10046_AGC_TDA827X,
663 .gpio_config = TDA10046_GP11_I,
664 .if_freq = TDA10046_FREQ_045,
666 .tuner_address = 0x61,
668 .request_firmware = philips_tda1004x_request_firmware
671 static struct tda1004x_config lifeview_trio_config = {
672 .demod_address = 0x09,
675 .xtal_freq = TDA10046_XTAL_16M,
676 .agc_config = TDA10046_AGC_TDA827X,
677 .gpio_config = TDA10046_GP00_I,
678 .if_freq = TDA10046_FREQ_045,
679 .tuner_address = 0x60,
680 .request_firmware = philips_tda1004x_request_firmware
683 static struct tda1004x_config tevion_dvbt220rf_config = {
684 .demod_address = 0x08,
687 .xtal_freq = TDA10046_XTAL_16M,
688 .agc_config = TDA10046_AGC_TDA827X,
689 .gpio_config = TDA10046_GP11_I,
690 .if_freq = TDA10046_FREQ_045,
691 .tuner_address = 0x60,
692 .request_firmware = philips_tda1004x_request_firmware
695 static struct tda1004x_config md8800_dvbt_config = {
696 .demod_address = 0x08,
699 .xtal_freq = TDA10046_XTAL_16M,
700 .agc_config = TDA10046_AGC_TDA827X,
701 .gpio_config = TDA10046_GP01_I,
702 .if_freq = TDA10046_FREQ_045,
704 .tuner_address = 0x60,
705 .request_firmware = philips_tda1004x_request_firmware
708 static struct tda1004x_config asus_p7131_4871_config = {
709 .demod_address = 0x08,
712 .xtal_freq = TDA10046_XTAL_16M,
713 .agc_config = TDA10046_AGC_TDA827X,
714 .gpio_config = TDA10046_GP01_I,
715 .if_freq = TDA10046_FREQ_045,
717 .tuner_address = 0x61,
719 .request_firmware = philips_tda1004x_request_firmware
722 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
723 .demod_address = 0x08,
726 .xtal_freq = TDA10046_XTAL_16M,
727 .agc_config = TDA10046_AGC_TDA827X,
728 .gpio_config = TDA10046_GP11_I,
729 .if_freq = TDA10046_FREQ_045,
731 .tuner_address = 0x61,
733 .request_firmware = philips_tda1004x_request_firmware
736 static struct tda1004x_config kworld_dvb_t_210_config = {
737 .demod_address = 0x08,
740 .xtal_freq = TDA10046_XTAL_16M,
741 .agc_config = TDA10046_AGC_TDA827X,
742 .gpio_config = TDA10046_GP11_I,
743 .if_freq = TDA10046_FREQ_045,
745 .tuner_address = 0x61,
747 .request_firmware = philips_tda1004x_request_firmware
750 static struct tda1004x_config avermedia_super_007_config = {
751 .demod_address = 0x08,
754 .xtal_freq = TDA10046_XTAL_16M,
755 .agc_config = TDA10046_AGC_TDA827X,
756 .gpio_config = TDA10046_GP01_I,
757 .if_freq = TDA10046_FREQ_045,
759 .tuner_address = 0x60,
761 .request_firmware = philips_tda1004x_request_firmware
764 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
765 .demod_address = 0x08,
768 .xtal_freq = TDA10046_XTAL_16M,
769 .agc_config = TDA10046_AGC_TDA827X,
770 .gpio_config = TDA10046_GP01_I,
771 .if_freq = TDA10046_FREQ_045,
773 .tuner_address = 0x61,
775 .request_firmware = philips_tda1004x_request_firmware
778 /* ------------------------------------------------------------------
779 * special case: this card uses saa713x GPIO22 for the mode switch
782 static int ads_duo_tuner_init(struct dvb_frontend *fe)
784 struct saa7134_dev *dev = fe->dvb->priv;
785 philips_tda827x_tuner_init(fe);
786 /* route TDA8275a AGC input to the channel decoder */
787 saa7134_set_gpio(dev, 22, 1);
791 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
793 struct saa7134_dev *dev = fe->dvb->priv;
794 /* route TDA8275a AGC input to the analog IF chip*/
795 saa7134_set_gpio(dev, 22, 0);
796 philips_tda827x_tuner_sleep(fe);
800 static struct tda827x_config ads_duo_cfg = {
801 .tuner_callback = saa7134_tuner_callback,
802 .init = ads_duo_tuner_init,
803 .sleep = ads_duo_tuner_sleep,
807 static struct tda1004x_config ads_tech_duo_config = {
808 .demod_address = 0x08,
811 .xtal_freq = TDA10046_XTAL_16M,
812 .agc_config = TDA10046_AGC_TDA827X,
813 .gpio_config = TDA10046_GP00_I,
814 .if_freq = TDA10046_FREQ_045,
815 .tuner_address = 0x61,
816 .request_firmware = philips_tda1004x_request_firmware
819 /* ==================================================================
820 * tda10086 based DVB-S cards, helper functions
823 static struct tda10086_config flydvbs = {
824 .demod_address = 0x0e,
829 /* ------------------------------------------------------------------
830 * special case: lnb supply is connected to the gated i2c
833 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
836 struct saa7134_dev *dev = fe->dvb->priv;
837 if (fe->ops.i2c_gate_ctrl) {
838 fe->ops.i2c_gate_ctrl(fe, 1);
839 if (dev->original_set_voltage)
840 res = dev->original_set_voltage(fe, voltage);
841 fe->ops.i2c_gate_ctrl(fe, 0);
846 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
849 struct saa7134_dev *dev = fe->dvb->priv;
850 if (fe->ops.i2c_gate_ctrl) {
851 fe->ops.i2c_gate_ctrl(fe, 1);
852 if (dev->original_set_high_voltage)
853 res = dev->original_set_high_voltage(fe, arg);
854 fe->ops.i2c_gate_ctrl(fe, 0);
859 static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
861 struct saa7134_dev *dev = fe->dvb->priv;
862 u8 wbuf[2] = { 0x1f, 00 };
864 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
865 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
867 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
869 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
870 if (voltage == SEC_VOLTAGE_18)
871 wbuf[1] = rbuf | 0x10;
873 wbuf[1] = rbuf & 0xef;
875 i2c_transfer(&dev->i2c_adap, msg, 1);
879 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
881 struct saa7134_dev *dev = fe->dvb->priv;
882 wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
886 /* ==================================================================
887 * nxt200x based ATSC cards, helper functions
890 static struct nxt200x_config avertvhda180 = {
891 .demod_address = 0x0a,
894 static struct nxt200x_config kworldatsc110 = {
895 .demod_address = 0x0a,
898 /* ==================================================================
902 static int dvb_init(struct saa7134_dev *dev)
905 int attach_xc3028 = 0;
907 /* init struct videobuf_dvb */
908 dev->ts.nr_bufs = 32;
909 dev->ts.nr_packets = 32*4;
910 dev->dvb.name = dev->name;
911 videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
912 &dev->pci->dev, &dev->slock,
913 V4L2_BUF_TYPE_VIDEO_CAPTURE,
914 V4L2_FIELD_ALTERNATE,
915 sizeof(struct saa7134_buf),
918 switch (dev->board) {
919 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
920 dprintk("pinnacle 300i dvb setup\n");
921 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
923 if (dev->dvb.frontend) {
924 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
927 case SAA7134_BOARD_AVERMEDIA_777:
928 case SAA7134_BOARD_AVERMEDIA_A16AR:
929 dprintk("avertv 777 dvb setup\n");
930 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
932 if (dev->dvb.frontend) {
933 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
934 &dev->i2c_adap, 0x61,
935 TUNER_PHILIPS_TD1316);
938 case SAA7134_BOARD_MD7134:
939 dev->dvb.frontend = dvb_attach(tda10046_attach,
942 if (dev->dvb.frontend) {
943 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
944 &dev->i2c_adap, medion_cardbus.tuner_address,
945 TUNER_PHILIPS_FMD1216ME_MK3);
948 case SAA7134_BOARD_PHILIPS_TOUGH:
949 dev->dvb.frontend = dvb_attach(tda10046_attach,
950 &philips_tu1216_60_config,
952 if (dev->dvb.frontend) {
953 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
954 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
957 case SAA7134_BOARD_FLYDVBTDUO:
958 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
959 configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
961 case SAA7134_BOARD_PHILIPS_EUROPA:
962 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
963 dev->dvb.frontend = dvb_attach(tda10046_attach,
964 &philips_europa_config,
966 if (dev->dvb.frontend) {
967 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
968 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
969 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
970 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
971 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
974 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
975 dev->dvb.frontend = dvb_attach(tda10046_attach,
976 &philips_tu1216_61_config,
978 if (dev->dvb.frontend) {
979 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
980 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
983 case SAA7134_BOARD_KWORLD_DVBT_210:
984 configure_tda827x_fe(dev, &kworld_dvb_t_210_config, &tda827x_cfg_2);
986 case SAA7134_BOARD_PHILIPS_TIGER:
987 configure_tda827x_fe(dev, &philips_tiger_config, &tda827x_cfg_0);
989 case SAA7134_BOARD_PINNACLE_PCTV_310i:
990 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config, &tda827x_cfg_1);
992 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
993 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config, &tda827x_cfg_1);
995 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
996 configure_tda827x_fe(dev, &asus_p7131_dual_config, &tda827x_cfg_0);
998 case SAA7134_BOARD_FLYDVBT_LR301:
999 configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
1001 case SAA7134_BOARD_FLYDVB_TRIO:
1002 if(! use_frontend) { /* terrestrial */
1003 configure_tda827x_fe(dev, &lifeview_trio_config, &tda827x_cfg_0);
1004 } else { /* satellite */
1005 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1006 if (dev->dvb.frontend) {
1007 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1008 &dev->i2c_adap, 0) == NULL) {
1009 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
1011 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1012 0x08, 0, 0) == NULL) {
1013 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1018 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1019 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1020 dev->dvb.frontend = dvb_attach(tda10046_attach,
1021 &ads_tech_duo_config,
1023 if (dev->dvb.frontend) {
1024 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1025 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1026 &ads_duo_cfg) == NULL) {
1027 wprintk("no tda827x tuner found at addr: %02x\n",
1028 ads_tech_duo_config.tuner_address);
1032 case SAA7134_BOARD_TEVION_DVBT_220RF:
1033 configure_tda827x_fe(dev, &tevion_dvbt220rf_config, &tda827x_cfg_0);
1035 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1036 if (!use_frontend) { /* terrestrial */
1037 configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
1038 } else { /* satellite */
1039 dev->dvb.frontend = dvb_attach(tda10086_attach,
1040 &flydvbs, &dev->i2c_adap);
1041 if (dev->dvb.frontend) {
1042 struct dvb_frontend *fe = dev->dvb.frontend;
1043 u8 dev_id = dev->eedata[2];
1045 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1047 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1048 0x60, &dev->i2c_adap, 0) == NULL)
1049 wprintk("%s: Medion Quadro, no tda826x "
1050 "found !\n", __func__);
1051 if (dev_id != 0x08) {
1052 /* we need to open the i2c gate (we know it exists) */
1053 fe->ops.i2c_gate_ctrl(fe, 1);
1054 if (dvb_attach(isl6405_attach, fe,
1055 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1056 wprintk("%s: Medion Quadro, no ISL6405 "
1057 "found !\n", __func__);
1058 if (dev_id == 0x07) {
1059 /* fire up the 2nd section of the LNB supply since
1060 we can't do this from the other section */
1062 i2c_transfer(&dev->i2c_adap, &msg, 1);
1064 fe->ops.i2c_gate_ctrl(fe, 0);
1065 dev->original_set_voltage = fe->ops.set_voltage;
1066 fe->ops.set_voltage = md8800_set_voltage;
1067 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1068 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1070 fe->ops.set_voltage = md8800_set_voltage2;
1071 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1076 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1077 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1079 if (dev->dvb.frontend) {
1080 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1081 NULL, DVB_PLL_TDHU2);
1084 case SAA7134_BOARD_KWORLD_ATSC110:
1085 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1087 if (dev->dvb.frontend) {
1088 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1089 NULL, DVB_PLL_TUV1236D);
1092 case SAA7134_BOARD_FLYDVBS_LR300:
1093 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1095 if (dev->dvb.frontend) {
1096 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1097 &dev->i2c_adap, 0) == NULL) {
1098 wprintk("%s: No tda826x found!\n", __func__);
1100 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1101 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1102 wprintk("%s: No ISL6421 found!\n", __func__);
1106 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1107 dev->dvb.frontend = dvb_attach(tda10046_attach,
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;
1114 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
1115 &dev->i2c_adap, medion_cardbus.tuner_address,
1116 TUNER_PHILIPS_FMD1216ME_MK3);
1119 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1120 dev->dvb.frontend = dvb_attach(tda10046_attach,
1121 &philips_europa_config,
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;
1128 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1129 configure_tda827x_fe(dev, &cinergy_ht_config, &tda827x_cfg_0);
1131 case SAA7134_BOARD_CINERGY_HT_PCI:
1132 configure_tda827x_fe(dev, &cinergy_ht_pci_config, &tda827x_cfg_0);
1134 case SAA7134_BOARD_PHILIPS_TIGER_S:
1135 configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
1137 case SAA7134_BOARD_ASUS_P7131_4871:
1138 configure_tda827x_fe(dev, &asus_p7131_4871_config, &tda827x_cfg_2);
1140 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1141 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config, &tda827x_cfg_2);
1143 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1144 configure_tda827x_fe(dev, &avermedia_super_007_config, &tda827x_cfg_0);
1146 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1147 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config, &tda827x_cfg_2_sw42);
1149 case SAA7134_BOARD_PHILIPS_SNAKE:
1150 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1152 if (dev->dvb.frontend) {
1153 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1154 &dev->i2c_adap, 0) == NULL)
1155 wprintk("%s: No tda826x found!\n", __func__);
1156 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1157 &dev->i2c_adap, 0, 0) == NULL)
1158 wprintk("%s: No lnbp21 found!\n", __func__);
1161 case SAA7134_BOARD_CREATIX_CTX953:
1162 configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
1164 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1165 configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
1167 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1168 dev->dvb.frontend = dvb_attach(mt352_attach,
1169 &avermedia_e506r_mt352_dev,
1173 case SAA7134_BOARD_MD7134_BRIDGE_2:
1174 dev->dvb.frontend = dvb_attach(tda10086_attach,
1175 &flydvbs, &dev->i2c_adap);
1176 if (dev->dvb.frontend) {
1177 struct dvb_frontend *fe;
1178 if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
1179 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL)
1180 wprintk("%s: MD7134 DVB-S, no SD1878 "
1181 "found !\n", __func__);
1182 /* we need to open the i2c gate (we know it exists) */
1183 fe = dev->dvb.frontend;
1184 fe->ops.i2c_gate_ctrl(fe, 1);
1185 if (dvb_attach(isl6405_attach, fe,
1186 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1187 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1188 "found !\n", __func__);
1189 fe->ops.i2c_gate_ctrl(fe, 0);
1190 dev->original_set_voltage = fe->ops.set_voltage;
1191 fe->ops.set_voltage = md8800_set_voltage;
1192 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1193 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1197 wprintk("Huh? unknown DVB card?\n");
1201 if (attach_xc3028) {
1202 struct dvb_frontend *fe;
1203 struct xc2028_config cfg = {
1204 .i2c_adap = &dev->i2c_adap,
1207 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1209 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1211 dvb_frontend_detach(dev->dvb.frontend);
1212 dvb_unregister_frontend(dev->dvb.frontend);
1213 dev->dvb.frontend = NULL;
1218 if (NULL == dev->dvb.frontend) {
1219 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1223 /* register everything else */
1224 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1226 /* this sequence is necessary to make the tda1004x load its firmware
1227 * and to enter analog mode of hybrid boards
1230 if (dev->dvb.frontend->ops.init)
1231 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1232 if (dev->dvb.frontend->ops.sleep)
1233 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1234 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1235 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1240 static int dvb_fini(struct saa7134_dev *dev)
1242 /* FIXME: I suspect that this code is bogus, since the entry for
1243 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1244 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1246 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1247 struct v4l2_priv_tun_config tda9887_cfg;
1248 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1250 tda9887_cfg.tuner = TUNER_TDA9887;
1251 tda9887_cfg.priv = &on;
1253 /* otherwise we don't detect the tuner on next insmod */
1254 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1255 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1256 if ((dev->eedata[2] == 0x07) && use_frontend) {
1257 /* turn off the 2nd lnb supply */
1259 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1260 struct dvb_frontend *fe;
1261 fe = dev->dvb.frontend;
1262 if (fe->ops.i2c_gate_ctrl) {
1263 fe->ops.i2c_gate_ctrl(fe, 1);
1264 i2c_transfer(&dev->i2c_adap, &msg, 1);
1265 fe->ops.i2c_gate_ctrl(fe, 0);
1269 videobuf_dvb_unregister(&dev->dvb);
1273 static struct saa7134_mpeg_ops dvb_ops = {
1274 .type = SAA7134_MPEG_DVB,
1279 static int __init dvb_register(void)
1281 return saa7134_ts_register(&dvb_ops);
1284 static void __exit dvb_unregister(void)
1286 saa7134_ts_unregister(&dvb_ops);
1289 module_init(dvb_register);
1290 module_exit(dvb_unregister);
1292 /* ------------------------------------------------------------------ */