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(dvb_pll_attach, dev->dvb.frontend, 0x61,
934 NULL, DVB_PLL_PHILIPS_TD1316);
937 case SAA7134_BOARD_MD7134:
938 dev->dvb.frontend = dvb_attach(tda10046_attach,
941 if (dev->dvb.frontend) {
942 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
943 &dev->i2c_adap, medion_cardbus.tuner_address,
944 TUNER_PHILIPS_FMD1216ME_MK3);
947 case SAA7134_BOARD_PHILIPS_TOUGH:
948 dev->dvb.frontend = dvb_attach(tda10046_attach,
949 &philips_tu1216_60_config,
951 if (dev->dvb.frontend) {
952 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
953 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
956 case SAA7134_BOARD_FLYDVBTDUO:
957 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
958 configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
960 case SAA7134_BOARD_PHILIPS_EUROPA:
961 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
962 dev->dvb.frontend = dvb_attach(tda10046_attach,
963 &philips_europa_config,
965 if (dev->dvb.frontend) {
966 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
967 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
968 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
969 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
970 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
973 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
974 dev->dvb.frontend = dvb_attach(tda10046_attach,
975 &philips_tu1216_61_config,
977 if (dev->dvb.frontend) {
978 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
979 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
982 case SAA7134_BOARD_KWORLD_DVBT_210:
983 configure_tda827x_fe(dev, &kworld_dvb_t_210_config, &tda827x_cfg_2);
985 case SAA7134_BOARD_PHILIPS_TIGER:
986 configure_tda827x_fe(dev, &philips_tiger_config, &tda827x_cfg_0);
988 case SAA7134_BOARD_PINNACLE_PCTV_310i:
989 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config, &tda827x_cfg_1);
991 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
992 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config, &tda827x_cfg_1);
994 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
995 configure_tda827x_fe(dev, &asus_p7131_dual_config, &tda827x_cfg_0);
997 case SAA7134_BOARD_FLYDVBT_LR301:
998 configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
1000 case SAA7134_BOARD_FLYDVB_TRIO:
1001 if(! use_frontend) { /* terrestrial */
1002 configure_tda827x_fe(dev, &lifeview_trio_config, &tda827x_cfg_0);
1003 } else { /* satellite */
1004 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1005 if (dev->dvb.frontend) {
1006 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1007 &dev->i2c_adap, 0) == NULL) {
1008 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
1010 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1011 0x08, 0, 0) == NULL) {
1012 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1017 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1018 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1019 dev->dvb.frontend = dvb_attach(tda10046_attach,
1020 &ads_tech_duo_config,
1022 if (dev->dvb.frontend) {
1023 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1024 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1025 &ads_duo_cfg) == NULL) {
1026 wprintk("no tda827x tuner found at addr: %02x\n",
1027 ads_tech_duo_config.tuner_address);
1031 case SAA7134_BOARD_TEVION_DVBT_220RF:
1032 configure_tda827x_fe(dev, &tevion_dvbt220rf_config, &tda827x_cfg_0);
1034 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1035 if (!use_frontend) { /* terrestrial */
1036 configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
1037 } else { /* satellite */
1038 dev->dvb.frontend = dvb_attach(tda10086_attach,
1039 &flydvbs, &dev->i2c_adap);
1040 if (dev->dvb.frontend) {
1041 struct dvb_frontend *fe = dev->dvb.frontend;
1042 u8 dev_id = dev->eedata[2];
1044 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1046 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1047 0x60, &dev->i2c_adap, 0) == NULL)
1048 wprintk("%s: Medion Quadro, no tda826x "
1049 "found !\n", __func__);
1050 if (dev_id != 0x08) {
1051 /* we need to open the i2c gate (we know it exists) */
1052 fe->ops.i2c_gate_ctrl(fe, 1);
1053 if (dvb_attach(isl6405_attach, fe,
1054 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1055 wprintk("%s: Medion Quadro, no ISL6405 "
1056 "found !\n", __func__);
1057 if (dev_id == 0x07) {
1058 /* fire up the 2nd section of the LNB supply since
1059 we can't do this from the other section */
1061 i2c_transfer(&dev->i2c_adap, &msg, 1);
1063 fe->ops.i2c_gate_ctrl(fe, 0);
1064 dev->original_set_voltage = fe->ops.set_voltage;
1065 fe->ops.set_voltage = md8800_set_voltage;
1066 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1067 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1069 fe->ops.set_voltage = md8800_set_voltage2;
1070 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1075 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1076 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1078 if (dev->dvb.frontend) {
1079 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1080 NULL, DVB_PLL_TDHU2);
1083 case SAA7134_BOARD_KWORLD_ATSC110:
1084 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1086 if (dev->dvb.frontend) {
1087 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1088 NULL, DVB_PLL_TUV1236D);
1091 case SAA7134_BOARD_FLYDVBS_LR300:
1092 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1094 if (dev->dvb.frontend) {
1095 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1096 &dev->i2c_adap, 0) == NULL) {
1097 wprintk("%s: No tda826x found!\n", __func__);
1099 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1100 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1101 wprintk("%s: No ISL6421 found!\n", __func__);
1105 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1106 dev->dvb.frontend = dvb_attach(tda10046_attach,
1109 if (dev->dvb.frontend) {
1110 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1111 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1113 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
1114 &dev->i2c_adap, medion_cardbus.tuner_address,
1115 TUNER_PHILIPS_FMD1216ME_MK3);
1118 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1119 dev->dvb.frontend = dvb_attach(tda10046_attach,
1120 &philips_europa_config,
1122 if (dev->dvb.frontend) {
1123 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1124 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1127 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1128 configure_tda827x_fe(dev, &cinergy_ht_config, &tda827x_cfg_0);
1130 case SAA7134_BOARD_CINERGY_HT_PCI:
1131 configure_tda827x_fe(dev, &cinergy_ht_pci_config, &tda827x_cfg_0);
1133 case SAA7134_BOARD_PHILIPS_TIGER_S:
1134 configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
1136 case SAA7134_BOARD_ASUS_P7131_4871:
1137 configure_tda827x_fe(dev, &asus_p7131_4871_config, &tda827x_cfg_2);
1139 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1140 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config, &tda827x_cfg_2);
1142 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1143 configure_tda827x_fe(dev, &avermedia_super_007_config, &tda827x_cfg_0);
1145 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1146 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config, &tda827x_cfg_2_sw42);
1148 case SAA7134_BOARD_PHILIPS_SNAKE:
1149 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1151 if (dev->dvb.frontend) {
1152 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1153 &dev->i2c_adap, 0) == NULL)
1154 wprintk("%s: No tda826x found!\n", __func__);
1155 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1156 &dev->i2c_adap, 0, 0) == NULL)
1157 wprintk("%s: No lnbp21 found!\n", __func__);
1160 case SAA7134_BOARD_CREATIX_CTX953:
1161 configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
1163 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1164 configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
1166 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1167 dev->dvb.frontend = dvb_attach(mt352_attach,
1168 &avermedia_e506r_mt352_dev,
1172 case SAA7134_BOARD_MD7134_BRIDGE_2:
1173 dev->dvb.frontend = dvb_attach(tda10086_attach,
1174 &flydvbs, &dev->i2c_adap);
1175 if (dev->dvb.frontend) {
1176 struct dvb_frontend *fe;
1177 if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
1178 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL)
1179 wprintk("%s: MD7134 DVB-S, no SD1878 "
1180 "found !\n", __func__);
1181 /* we need to open the i2c gate (we know it exists) */
1182 fe = dev->dvb.frontend;
1183 fe->ops.i2c_gate_ctrl(fe, 1);
1184 if (dvb_attach(isl6405_attach, fe,
1185 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1186 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1187 "found !\n", __func__);
1188 fe->ops.i2c_gate_ctrl(fe, 0);
1189 dev->original_set_voltage = fe->ops.set_voltage;
1190 fe->ops.set_voltage = md8800_set_voltage;
1191 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1192 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1196 wprintk("Huh? unknown DVB card?\n");
1200 if (attach_xc3028) {
1201 struct dvb_frontend *fe;
1202 struct xc2028_config cfg = {
1203 .i2c_adap = &dev->i2c_adap,
1206 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1208 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1210 dvb_frontend_detach(dev->dvb.frontend);
1211 dvb_unregister_frontend(dev->dvb.frontend);
1212 dev->dvb.frontend = NULL;
1217 if (NULL == dev->dvb.frontend) {
1218 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1222 /* register everything else */
1223 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1225 /* this sequence is necessary to make the tda1004x load its firmware
1226 * and to enter analog mode of hybrid boards
1229 if (dev->dvb.frontend->ops.init)
1230 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1231 if (dev->dvb.frontend->ops.sleep)
1232 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1233 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1234 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1239 static int dvb_fini(struct saa7134_dev *dev)
1241 /* FIXME: I suspect that this code is bogus, since the entry for
1242 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1243 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1245 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1246 struct v4l2_priv_tun_config tda9887_cfg;
1247 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1249 tda9887_cfg.tuner = TUNER_TDA9887;
1250 tda9887_cfg.priv = &on;
1252 /* otherwise we don't detect the tuner on next insmod */
1253 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1254 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1255 if ((dev->eedata[2] == 0x07) && use_frontend) {
1256 /* turn off the 2nd lnb supply */
1258 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1259 struct dvb_frontend *fe;
1260 fe = dev->dvb.frontend;
1261 if (fe->ops.i2c_gate_ctrl) {
1262 fe->ops.i2c_gate_ctrl(fe, 1);
1263 i2c_transfer(&dev->i2c_adap, &msg, 1);
1264 fe->ops.i2c_gate_ctrl(fe, 0);
1268 videobuf_dvb_unregister(&dev->dvb);
1272 static struct saa7134_mpeg_ops dvb_ops = {
1273 .type = SAA7134_MPEG_DVB,
1278 static int __init dvb_register(void)
1280 return saa7134_ts_register(&dvb_ops);
1283 static void __exit dvb_unregister(void)
1285 saa7134_ts_unregister(&dvb_ops);
1288 module_init(dvb_register);
1289 module_exit(dvb_unregister);
1291 /* ------------------------------------------------------------------ */