1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
6 * Extended 3 / 2005 by Hartmut Hackmann to support various
7 * cards with the tda10046 DVB-T channel decoder
11 #include "saa7134-reg.h"
13 #include <linux/init.h>
14 #include <linux/list.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/delay.h>
18 #include <linux/kthread.h>
19 #include <linux/suspend.h>
21 #include <media/v4l2-common.h>
23 #include <media/dvb_frontend.h>
26 #include "mt352_priv.h" /* FIXME */
38 #include "tuner-simple.h"
54 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
55 MODULE_LICENSE("GPL");
57 static unsigned int antenna_pwr;
59 module_param(antenna_pwr, int, 0444);
60 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
62 static int use_frontend;
63 module_param(use_frontend, int, 0644);
64 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
66 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
68 /* ------------------------------------------------------------------
69 * mt352 based DVB-T cards
72 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
77 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
78 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
82 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
83 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
86 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
87 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
89 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
91 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
92 pr_debug("%s %s\n", __func__, ok ? "on" : "off");
95 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
99 static int mt352_pinnacle_init(struct dvb_frontend* fe)
101 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
102 static u8 reset [] = { RESET, 0x80 };
103 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
104 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
105 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
106 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
107 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
108 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
109 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
111 pr_debug("%s called\n", __func__);
113 mt352_write(fe, clock_config, sizeof(clock_config));
115 mt352_write(fe, reset, sizeof(reset));
116 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
117 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
118 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
119 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
121 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
122 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
123 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
128 static int mt352_aver777_init(struct dvb_frontend* fe)
130 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
131 static u8 reset [] = { RESET, 0x80 };
132 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
133 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
134 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
136 mt352_write(fe, clock_config, sizeof(clock_config));
138 mt352_write(fe, reset, sizeof(reset));
139 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
140 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
141 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
146 static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
148 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
149 static u8 reset [] = { RESET, 0x80 };
150 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
151 static u8 agc_cfg [] = { AGC_TARGET, 0xe };
152 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
154 mt352_write(fe, clock_config, sizeof(clock_config));
156 mt352_write(fe, reset, sizeof(reset));
157 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
158 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
159 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
163 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend *fe)
165 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
166 u8 off[] = { 0x00, 0xf1};
167 u8 on[] = { 0x00, 0x71};
168 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
170 struct saa7134_dev *dev = fe->dvb->priv;
171 struct v4l2_frequency f;
173 /* set frequency (mt2050) */
175 f.type = V4L2_TUNER_DIGITAL_TV;
176 f.frequency = c->frequency / 1000 * 16 / 1000;
177 if (fe->ops.i2c_gate_ctrl)
178 fe->ops.i2c_gate_ctrl(fe, 1);
179 i2c_transfer(&dev->i2c_adap, &msg, 1);
180 saa_call_all(dev, tuner, s_frequency, &f);
182 if (fe->ops.i2c_gate_ctrl)
183 fe->ops.i2c_gate_ctrl(fe, 1);
184 i2c_transfer(&dev->i2c_adap, &msg, 1);
186 pinnacle_antenna_pwr(dev, antenna_pwr);
189 return mt352_pinnacle_init(fe);
192 static struct mt352_config pinnacle_300i = {
193 .demod_address = 0x3c >> 1,
197 .demod_init = mt352_pinnacle_init,
200 static struct mt352_config avermedia_777 = {
201 .demod_address = 0xf,
202 .demod_init = mt352_aver777_init,
205 static struct mt352_config avermedia_xc3028_mt352_dev = {
206 .demod_address = (0x1e >> 1),
208 .demod_init = mt352_avermedia_xc3028_init,
211 static struct tda18271_std_map mb86a20s_tda18271_std_map = {
212 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
213 .if_lvl = 7, .rfagc_top = 0x37, },
216 static struct tda18271_config kworld_tda18271_config = {
217 .std_map = &mb86a20s_tda18271_std_map,
218 .gate = TDA18271_GATE_DIGITAL,
219 .config = 3, /* Use tuner callback for AGC */
223 static const struct mb86a20s_config kworld_mb86a20s_config = {
224 .demod_address = 0x10,
227 static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)
229 struct saa7134_dev *dev = fe->dvb->priv;
231 unsigned char initmsg[] = {0x45, 0x97};
232 unsigned char msg_enable[] = {0x45, 0xc1};
233 unsigned char msg_disable[] = {0x45, 0x81};
234 struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
236 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
237 pr_warn("could not access the I2C gate\n");
241 msg.buf = msg_enable;
243 msg.buf = msg_disable;
244 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
245 pr_warn("could not access the I2C gate\n");
252 /* ==================================================================
253 * tda1004x based DVB-T cards, helper functions
256 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
257 const struct firmware **fw, char *name)
259 struct saa7134_dev *dev = fe->dvb->priv;
260 return reject_firmware(fw, name, &dev->pci->dev);
263 /* ------------------------------------------------------------------
264 * these tuners are tu1216, td1316(a)
267 static int philips_tda6651_pll_set(struct dvb_frontend *fe)
269 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
270 struct saa7134_dev *dev = fe->dvb->priv;
271 struct tda1004x_state *state = fe->demodulator_priv;
272 u8 addr = state->config->tuner_address;
274 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
276 int tuner_frequency = 0;
279 /* determine charge pump */
280 tuner_frequency = c->frequency + 36166000;
281 if (tuner_frequency < 87000000)
283 else if (tuner_frequency < 130000000)
285 else if (tuner_frequency < 160000000)
287 else if (tuner_frequency < 200000000)
289 else if (tuner_frequency < 290000000)
291 else if (tuner_frequency < 420000000)
293 else if (tuner_frequency < 480000000)
295 else if (tuner_frequency < 620000000)
297 else if (tuner_frequency < 830000000)
299 else if (tuner_frequency < 895000000)
305 if (c->frequency < 49000000)
307 else if (c->frequency < 161000000)
309 else if (c->frequency < 444000000)
311 else if (c->frequency < 861000000)
316 /* setup PLL filter */
317 switch (c->bandwidth_hz) {
335 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
337 tuner_frequency = (((c->frequency / 1000) * 6) + 217496) / 1000;
339 /* setup tuner buffer */
340 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
341 tuner_buf[1] = tuner_frequency & 0xff;
343 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
345 if (fe->ops.i2c_gate_ctrl)
346 fe->ops.i2c_gate_ctrl(fe, 1);
347 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
348 pr_warn("could not write to tuner at addr: 0x%02x\n",
356 static int philips_tu1216_init(struct dvb_frontend *fe)
358 struct saa7134_dev *dev = fe->dvb->priv;
359 struct tda1004x_state *state = fe->demodulator_priv;
360 u8 addr = state->config->tuner_address;
361 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
362 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
364 /* setup PLL configuration */
365 if (fe->ops.i2c_gate_ctrl)
366 fe->ops.i2c_gate_ctrl(fe, 1);
367 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
374 /* ------------------------------------------------------------------ */
376 static struct tda1004x_config philips_tu1216_60_config = {
377 .demod_address = 0x8,
380 .xtal_freq = TDA10046_XTAL_4M,
381 .agc_config = TDA10046_AGC_DEFAULT,
382 .if_freq = TDA10046_FREQ_3617,
383 .tuner_address = 0x60,
384 .request_firmware = philips_tda1004x_request_firmware
387 static struct tda1004x_config philips_tu1216_61_config = {
389 .demod_address = 0x8,
392 .xtal_freq = TDA10046_XTAL_4M,
393 .agc_config = TDA10046_AGC_DEFAULT,
394 .if_freq = TDA10046_FREQ_3617,
395 .tuner_address = 0x61,
396 .request_firmware = philips_tda1004x_request_firmware
399 /* ------------------------------------------------------------------ */
401 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
403 struct saa7134_dev *dev = fe->dvb->priv;
404 struct tda1004x_state *state = fe->demodulator_priv;
405 u8 addr = state->config->tuner_address;
406 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
407 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
409 /* setup PLL configuration */
410 if (fe->ops.i2c_gate_ctrl)
411 fe->ops.i2c_gate_ctrl(fe, 1);
412 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
417 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe)
419 return philips_tda6651_pll_set(fe);
422 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
424 struct saa7134_dev *dev = fe->dvb->priv;
425 struct tda1004x_state *state = fe->demodulator_priv;
426 u8 addr = state->config->tuner_address;
427 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
428 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
430 /* switch the tuner to analog mode */
431 if (fe->ops.i2c_gate_ctrl)
432 fe->ops.i2c_gate_ctrl(fe, 1);
433 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
438 /* ------------------------------------------------------------------ */
440 static int philips_europa_tuner_init(struct dvb_frontend *fe)
442 struct saa7134_dev *dev = fe->dvb->priv;
443 static u8 msg[] = { 0x00, 0x40};
444 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
447 if (philips_td1316_tuner_init(fe))
450 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
456 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
458 struct saa7134_dev *dev = fe->dvb->priv;
460 static u8 msg[] = { 0x00, 0x14 };
461 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
463 if (philips_td1316_tuner_sleep(fe))
466 /* switch the board to analog mode */
467 if (fe->ops.i2c_gate_ctrl)
468 fe->ops.i2c_gate_ctrl(fe, 1);
469 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
473 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
475 struct saa7134_dev *dev = fe->dvb->priv;
477 if (dev->original_demod_sleep)
478 dev->original_demod_sleep(fe);
479 fe->ops.i2c_gate_ctrl(fe, 1);
483 static struct tda1004x_config philips_europa_config = {
485 .demod_address = 0x8,
488 .xtal_freq = TDA10046_XTAL_4M,
489 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
490 .if_freq = TDA10046_FREQ_052,
491 .tuner_address = 0x61,
492 .request_firmware = philips_tda1004x_request_firmware
495 static struct tda1004x_config medion_cardbus = {
496 .demod_address = 0x08,
499 .xtal_freq = TDA10046_XTAL_16M,
500 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
501 .if_freq = TDA10046_FREQ_3613,
502 .tuner_address = 0x61,
503 .request_firmware = philips_tda1004x_request_firmware
506 static struct tda1004x_config technotrend_budget_t3000_config = {
507 .demod_address = 0x8,
510 .xtal_freq = TDA10046_XTAL_4M,
511 .agc_config = TDA10046_AGC_DEFAULT,
512 .if_freq = TDA10046_FREQ_3617,
513 .tuner_address = 0x63,
514 .request_firmware = philips_tda1004x_request_firmware
517 /* ------------------------------------------------------------------
518 * tda 1004x based cards with philips silicon tuner
521 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
523 struct tda1004x_state *state = fe->demodulator_priv;
525 u8 addr = state->config->i2c_gate;
526 static u8 tda8290_close[] = { 0x21, 0xc0};
527 static u8 tda8290_open[] = { 0x21, 0x80};
528 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
530 tda8290_msg.buf = tda8290_close;
532 tda8290_msg.buf = tda8290_open;
534 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
535 pr_warn("could not access tda8290 I2C gate\n");
542 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
544 struct saa7134_dev *dev = fe->dvb->priv;
545 struct tda1004x_state *state = fe->demodulator_priv;
547 switch (state->config->antenna_switch) {
551 pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
552 saa7134_set_gpio(dev, 21, 0);
555 pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
556 saa7134_set_gpio(dev, 21, 1);
562 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
564 struct saa7134_dev *dev = fe->dvb->priv;
565 struct tda1004x_state *state = fe->demodulator_priv;
567 switch (state->config->antenna_switch) {
571 pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
572 saa7134_set_gpio(dev, 21, 1);
575 pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
576 saa7134_set_gpio(dev, 21, 0);
582 static int configure_tda827x_fe(struct saa7134_dev *dev,
583 struct tda1004x_config *cdec_conf,
584 struct tda827x_config *tuner_conf)
586 struct vb2_dvb_frontend *fe0;
588 /* Get the first frontend */
589 fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
594 fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
595 if (fe0->dvb.frontend) {
596 if (cdec_conf->i2c_gate)
597 fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
598 if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
599 cdec_conf->tuner_address,
600 &dev->i2c_adap, tuner_conf))
603 pr_warn("no tda827x tuner found at addr: %02x\n",
604 cdec_conf->tuner_address);
609 /* ------------------------------------------------------------------ */
611 static struct tda827x_config tda827x_cfg_0 = {
612 .init = philips_tda827x_tuner_init,
613 .sleep = philips_tda827x_tuner_sleep,
618 static struct tda827x_config tda827x_cfg_1 = {
619 .init = philips_tda827x_tuner_init,
620 .sleep = philips_tda827x_tuner_sleep,
625 static struct tda827x_config tda827x_cfg_2 = {
626 .init = philips_tda827x_tuner_init,
627 .sleep = philips_tda827x_tuner_sleep,
632 static struct tda827x_config tda827x_cfg_2_sw42 = {
633 .init = philips_tda827x_tuner_init,
634 .sleep = philips_tda827x_tuner_sleep,
639 /* ------------------------------------------------------------------ */
641 static struct tda1004x_config tda827x_lifeview_config = {
642 .demod_address = 0x08,
645 .xtal_freq = TDA10046_XTAL_16M,
646 .agc_config = TDA10046_AGC_TDA827X,
647 .gpio_config = TDA10046_GP11_I,
648 .if_freq = TDA10046_FREQ_045,
649 .tuner_address = 0x60,
650 .request_firmware = philips_tda1004x_request_firmware
653 static struct tda1004x_config philips_tiger_config = {
654 .demod_address = 0x08,
657 .xtal_freq = TDA10046_XTAL_16M,
658 .agc_config = TDA10046_AGC_TDA827X,
659 .gpio_config = TDA10046_GP11_I,
660 .if_freq = TDA10046_FREQ_045,
662 .tuner_address = 0x61,
664 .request_firmware = philips_tda1004x_request_firmware
667 static struct tda1004x_config cinergy_ht_config = {
668 .demod_address = 0x08,
671 .xtal_freq = TDA10046_XTAL_16M,
672 .agc_config = TDA10046_AGC_TDA827X,
673 .gpio_config = TDA10046_GP01_I,
674 .if_freq = TDA10046_FREQ_045,
676 .tuner_address = 0x61,
677 .request_firmware = philips_tda1004x_request_firmware
680 static struct tda1004x_config cinergy_ht_pci_config = {
681 .demod_address = 0x08,
684 .xtal_freq = TDA10046_XTAL_16M,
685 .agc_config = TDA10046_AGC_TDA827X,
686 .gpio_config = TDA10046_GP01_I,
687 .if_freq = TDA10046_FREQ_045,
689 .tuner_address = 0x60,
690 .request_firmware = philips_tda1004x_request_firmware
693 static struct tda1004x_config philips_tiger_s_config = {
694 .demod_address = 0x08,
697 .xtal_freq = TDA10046_XTAL_16M,
698 .agc_config = TDA10046_AGC_TDA827X,
699 .gpio_config = TDA10046_GP01_I,
700 .if_freq = TDA10046_FREQ_045,
702 .tuner_address = 0x61,
704 .request_firmware = philips_tda1004x_request_firmware
707 static struct tda1004x_config pinnacle_pctv_310i_config = {
708 .demod_address = 0x08,
711 .xtal_freq = TDA10046_XTAL_16M,
712 .agc_config = TDA10046_AGC_TDA827X,
713 .gpio_config = TDA10046_GP11_I,
714 .if_freq = TDA10046_FREQ_045,
716 .tuner_address = 0x61,
717 .request_firmware = philips_tda1004x_request_firmware
720 static struct tda1004x_config hauppauge_hvr_1110_config = {
721 .demod_address = 0x08,
724 .xtal_freq = TDA10046_XTAL_16M,
725 .agc_config = TDA10046_AGC_TDA827X,
726 .gpio_config = TDA10046_GP11_I,
727 .if_freq = TDA10046_FREQ_045,
729 .tuner_address = 0x61,
730 .request_firmware = philips_tda1004x_request_firmware
733 static struct tda1004x_config asus_p7131_dual_config = {
734 .demod_address = 0x08,
737 .xtal_freq = TDA10046_XTAL_16M,
738 .agc_config = TDA10046_AGC_TDA827X,
739 .gpio_config = TDA10046_GP11_I,
740 .if_freq = TDA10046_FREQ_045,
742 .tuner_address = 0x61,
744 .request_firmware = philips_tda1004x_request_firmware
747 static struct tda1004x_config lifeview_trio_config = {
748 .demod_address = 0x09,
751 .xtal_freq = TDA10046_XTAL_16M,
752 .agc_config = TDA10046_AGC_TDA827X,
753 .gpio_config = TDA10046_GP00_I,
754 .if_freq = TDA10046_FREQ_045,
755 .tuner_address = 0x60,
756 .request_firmware = philips_tda1004x_request_firmware
759 static struct tda1004x_config tevion_dvbt220rf_config = {
760 .demod_address = 0x08,
763 .xtal_freq = TDA10046_XTAL_16M,
764 .agc_config = TDA10046_AGC_TDA827X,
765 .gpio_config = TDA10046_GP11_I,
766 .if_freq = TDA10046_FREQ_045,
767 .tuner_address = 0x60,
768 .request_firmware = philips_tda1004x_request_firmware
771 static struct tda1004x_config md8800_dvbt_config = {
772 .demod_address = 0x08,
775 .xtal_freq = TDA10046_XTAL_16M,
776 .agc_config = TDA10046_AGC_TDA827X,
777 .gpio_config = TDA10046_GP01_I,
778 .if_freq = TDA10046_FREQ_045,
780 .tuner_address = 0x60,
781 .request_firmware = philips_tda1004x_request_firmware
784 static struct tda1004x_config asus_p7131_4871_config = {
785 .demod_address = 0x08,
788 .xtal_freq = TDA10046_XTAL_16M,
789 .agc_config = TDA10046_AGC_TDA827X,
790 .gpio_config = TDA10046_GP01_I,
791 .if_freq = TDA10046_FREQ_045,
793 .tuner_address = 0x61,
795 .request_firmware = philips_tda1004x_request_firmware
798 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
799 .demod_address = 0x08,
802 .xtal_freq = TDA10046_XTAL_16M,
803 .agc_config = TDA10046_AGC_TDA827X,
804 .gpio_config = TDA10046_GP11_I,
805 .if_freq = TDA10046_FREQ_045,
807 .tuner_address = 0x61,
809 .request_firmware = philips_tda1004x_request_firmware
812 static struct tda1004x_config kworld_dvb_t_210_config = {
813 .demod_address = 0x08,
816 .xtal_freq = TDA10046_XTAL_16M,
817 .agc_config = TDA10046_AGC_TDA827X,
818 .gpio_config = TDA10046_GP11_I,
819 .if_freq = TDA10046_FREQ_045,
821 .tuner_address = 0x61,
823 .request_firmware = philips_tda1004x_request_firmware
826 static struct tda1004x_config avermedia_super_007_config = {
827 .demod_address = 0x08,
830 .xtal_freq = TDA10046_XTAL_16M,
831 .agc_config = TDA10046_AGC_TDA827X,
832 .gpio_config = TDA10046_GP01_I,
833 .if_freq = TDA10046_FREQ_045,
835 .tuner_address = 0x60,
837 .request_firmware = philips_tda1004x_request_firmware
840 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
841 .demod_address = 0x08,
844 .xtal_freq = TDA10046_XTAL_16M,
845 .agc_config = TDA10046_AGC_TDA827X,
846 .gpio_config = TDA10046_GP01_I,
847 .if_freq = TDA10046_FREQ_045,
849 .tuner_address = 0x61,
851 .request_firmware = philips_tda1004x_request_firmware
854 static struct tda1004x_config asus_tiger_3in1_config = {
855 .demod_address = 0x0b,
858 .xtal_freq = TDA10046_XTAL_16M,
859 .agc_config = TDA10046_AGC_TDA827X,
860 .gpio_config = TDA10046_GP11_I,
861 .if_freq = TDA10046_FREQ_045,
863 .tuner_address = 0x61,
865 .request_firmware = philips_tda1004x_request_firmware
868 static struct tda1004x_config asus_ps3_100_config = {
869 .demod_address = 0x0b,
872 .xtal_freq = TDA10046_XTAL_16M,
873 .agc_config = TDA10046_AGC_TDA827X,
874 .gpio_config = TDA10046_GP11_I,
875 .if_freq = TDA10046_FREQ_045,
877 .tuner_address = 0x61,
879 .request_firmware = philips_tda1004x_request_firmware
882 /* ------------------------------------------------------------------
883 * special case: this card uses saa713x GPIO22 for the mode switch
886 static int ads_duo_tuner_init(struct dvb_frontend *fe)
888 struct saa7134_dev *dev = fe->dvb->priv;
889 philips_tda827x_tuner_init(fe);
890 /* route TDA8275a AGC input to the channel decoder */
891 saa7134_set_gpio(dev, 22, 1);
895 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
897 struct saa7134_dev *dev = fe->dvb->priv;
898 /* route TDA8275a AGC input to the analog IF chip*/
899 saa7134_set_gpio(dev, 22, 0);
900 philips_tda827x_tuner_sleep(fe);
904 static struct tda827x_config ads_duo_cfg = {
905 .init = ads_duo_tuner_init,
906 .sleep = ads_duo_tuner_sleep,
910 static struct tda1004x_config ads_tech_duo_config = {
911 .demod_address = 0x08,
914 .xtal_freq = TDA10046_XTAL_16M,
915 .agc_config = TDA10046_AGC_TDA827X,
916 .gpio_config = TDA10046_GP00_I,
917 .if_freq = TDA10046_FREQ_045,
918 .tuner_address = 0x61,
919 .request_firmware = philips_tda1004x_request_firmware
922 static struct zl10353_config behold_h6_config = {
923 .demod_address = 0x1e>>1,
926 .disable_i2c_gate_ctrl = 1,
929 static struct xc5000_config behold_x7_tunerconfig = {
930 .i2c_address = 0xc2>>1,
932 .radio_input = XC5000_RADIO_FM1,
935 static struct zl10353_config behold_x7_config = {
936 .demod_address = 0x1e>>1,
940 .disable_i2c_gate_ctrl = 1,
943 static struct zl10353_config videomate_t750_zl10353_config = {
944 .demod_address = 0x0f,
947 .disable_i2c_gate_ctrl = 1,
950 static struct qt1010_config videomate_t750_qt1010_config = {
955 /* ==================================================================
956 * tda10086 based DVB-S cards, helper functions
959 static struct tda10086_config flydvbs = {
960 .demod_address = 0x0e,
963 .xtal_freq = TDA10086_XTAL_16M,
966 static struct tda10086_config sd1878_4m = {
967 .demod_address = 0x0e,
970 .xtal_freq = TDA10086_XTAL_4M,
973 /* ------------------------------------------------------------------
974 * special case: lnb supply is connected to the gated i2c
977 static int md8800_set_voltage(struct dvb_frontend *fe,
978 enum fe_sec_voltage voltage)
981 struct saa7134_dev *dev = fe->dvb->priv;
982 if (fe->ops.i2c_gate_ctrl) {
983 fe->ops.i2c_gate_ctrl(fe, 1);
984 if (dev->original_set_voltage)
985 res = dev->original_set_voltage(fe, voltage);
986 fe->ops.i2c_gate_ctrl(fe, 0);
991 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
994 struct saa7134_dev *dev = fe->dvb->priv;
995 if (fe->ops.i2c_gate_ctrl) {
996 fe->ops.i2c_gate_ctrl(fe, 1);
997 if (dev->original_set_high_voltage)
998 res = dev->original_set_high_voltage(fe, arg);
999 fe->ops.i2c_gate_ctrl(fe, 0);
1004 static int md8800_set_voltage2(struct dvb_frontend *fe,
1005 enum fe_sec_voltage voltage)
1007 struct saa7134_dev *dev = fe->dvb->priv;
1008 u8 wbuf[2] = { 0x1f, 00 };
1010 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
1011 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
1013 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
1015 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
1016 if (voltage == SEC_VOLTAGE_18)
1017 wbuf[1] = rbuf | 0x10;
1019 wbuf[1] = rbuf & 0xef;
1021 i2c_transfer(&dev->i2c_adap, msg, 1);
1025 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
1027 pr_warn("%s: sorry can't set high LNB supply voltage from here\n",
1032 /* ==================================================================
1033 * nxt200x based ATSC cards, helper functions
1036 static const struct nxt200x_config avertvhda180 = {
1037 .demod_address = 0x0a,
1040 static const struct nxt200x_config kworldatsc110 = {
1041 .demod_address = 0x0a,
1044 /* ------------------------------------------------------------------ */
1046 static struct mt312_config avertv_a700_mt312 = {
1047 .demod_address = 0x0e,
1048 .voltage_inverted = 1,
1051 static struct zl10036_config avertv_a700_tuner = {
1052 .tuner_address = 0x60,
1055 static struct mt312_config zl10313_compro_s350_config = {
1056 .demod_address = 0x0e,
1059 static struct mt312_config zl10313_avermedia_a706_config = {
1060 .demod_address = 0x0e,
1063 static struct lgdt3305_config hcw_lgdt3305_config = {
1065 .mpeg_mode = LGDT3305_MPEG_SERIAL,
1066 .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
1067 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
1069 .spectral_inversion = 1,
1074 static struct tda10048_config hcw_tda10048_config = {
1075 .demod_address = 0x10 >> 1,
1076 .output_mode = TDA10048_SERIAL_OUTPUT,
1077 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1078 .inversion = TDA10048_INVERSION_ON,
1079 .dtv6_if_freq_khz = TDA10048_IF_3300,
1080 .dtv7_if_freq_khz = TDA10048_IF_3500,
1081 .dtv8_if_freq_khz = TDA10048_IF_4000,
1082 .clk_freq_khz = TDA10048_CLK_16000,
1083 .disable_gate_access = 1,
1086 static struct tda18271_std_map hauppauge_tda18271_std_map = {
1087 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
1088 .if_lvl = 1, .rfagc_top = 0x58, },
1089 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
1090 .if_lvl = 1, .rfagc_top = 0x58, },
1093 static struct tda18271_config hcw_tda18271_config = {
1094 .std_map = &hauppauge_tda18271_std_map,
1095 .gate = TDA18271_GATE_ANALOG,
1097 .output_opt = TDA18271_OUTPUT_LT_OFF,
1100 static struct tda829x_config tda829x_no_probe = {
1101 .probe_tuner = TDA829X_DONT_PROBE,
1104 static struct tda10048_config zolid_tda10048_config = {
1105 .demod_address = 0x10 >> 1,
1106 .output_mode = TDA10048_PARALLEL_OUTPUT,
1107 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1108 .inversion = TDA10048_INVERSION_ON,
1109 .dtv6_if_freq_khz = TDA10048_IF_3300,
1110 .dtv7_if_freq_khz = TDA10048_IF_3500,
1111 .dtv8_if_freq_khz = TDA10048_IF_4000,
1112 .clk_freq_khz = TDA10048_CLK_16000,
1113 .disable_gate_access = 1,
1116 static struct tda18271_config zolid_tda18271_config = {
1117 .gate = TDA18271_GATE_ANALOG,
1120 static struct tda10048_config dtv1000s_tda10048_config = {
1121 .demod_address = 0x10 >> 1,
1122 .output_mode = TDA10048_PARALLEL_OUTPUT,
1123 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1124 .inversion = TDA10048_INVERSION_ON,
1125 .dtv6_if_freq_khz = TDA10048_IF_3300,
1126 .dtv7_if_freq_khz = TDA10048_IF_3800,
1127 .dtv8_if_freq_khz = TDA10048_IF_4300,
1128 .clk_freq_khz = TDA10048_CLK_16000,
1129 .disable_gate_access = 1,
1132 static struct tda18271_std_map dtv1000s_tda18271_std_map = {
1133 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
1134 .if_lvl = 1, .rfagc_top = 0x37, },
1135 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
1136 .if_lvl = 1, .rfagc_top = 0x37, },
1137 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
1138 .if_lvl = 1, .rfagc_top = 0x37, },
1141 static struct tda18271_config dtv1000s_tda18271_config = {
1142 .std_map = &dtv1000s_tda18271_std_map,
1143 .gate = TDA18271_GATE_ANALOG,
1146 static struct lgs8gxx_config prohdtv_pro2_lgs8g75_config = {
1147 .prod = LGS8GXX_PROD_LGS8G75,
1148 .demod_address = 0x1d,
1152 .if_clk_freq = 30400, /* 30.4 MHz */
1153 .if_freq = 4000, /* 4.00 MHz */
1157 .adc_vpp = 3, /* 2.0 Vpp */
1161 static struct tda18271_config prohdtv_pro2_tda18271_config = {
1162 .gate = TDA18271_GATE_ANALOG,
1163 .output_opt = TDA18271_OUTPUT_LT_OFF,
1166 static struct tda18271_std_map kworld_tda18271_std_map = {
1167 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 3,
1168 .if_lvl = 6, .rfagc_top = 0x37 },
1169 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
1170 .if_lvl = 6, .rfagc_top = 0x37 },
1173 static struct tda18271_config kworld_pc150u_tda18271_config = {
1174 .std_map = &kworld_tda18271_std_map,
1175 .gate = TDA18271_GATE_ANALOG,
1176 .output_opt = TDA18271_OUTPUT_LT_OFF,
1177 .config = 3, /* Use tuner callback for AGC */
1178 .rf_cal_on_startup = 1
1181 static struct s5h1411_config kworld_s5h1411_config = {
1182 .output_mode = S5H1411_PARALLEL_OUTPUT,
1183 .gpio = S5H1411_GPIO_OFF,
1184 .qam_if = S5H1411_IF_4000,
1185 .vsb_if = S5H1411_IF_3250,
1186 .inversion = S5H1411_INVERSION_ON,
1187 .status_mode = S5H1411_DEMODLOCKING,
1189 S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
1192 static struct tda18271_config hdtv200h_tda18271_config = {
1193 .gate = TDA18271_GATE_ANALOG,
1194 .config = 3 /* Use tuner callback for AGC */
1197 static struct s5h1411_config hdtv200h_s5h1411_config = {
1198 .output_mode = S5H1411_PARALLEL_OUTPUT,
1199 .gpio = S5H1411_GPIO_OFF,
1200 .qam_if = S5H1411_IF_4000,
1201 .vsb_if = S5H1411_IF_3250,
1202 .inversion = S5H1411_INVERSION_ON,
1203 .status_mode = S5H1411_DEMODLOCKING,
1205 S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
1209 /* ==================================================================
1213 static int dvb_init(struct saa7134_dev *dev)
1216 int attach_xc3028 = 0;
1217 struct vb2_dvb_frontend *fe0;
1218 struct vb2_queue *q;
1220 /* FIXME: add support for multi-frontend */
1221 mutex_init(&dev->frontends.lock);
1222 INIT_LIST_HEAD(&dev->frontends.felist);
1224 pr_info("%s() allocating 1 frontend\n", __func__);
1225 fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1);
1227 pr_err("%s() failed to alloc\n", __func__);
1231 /* init struct vb2_dvb */
1232 dev->ts.nr_bufs = 32;
1233 dev->ts.nr_packets = 32*4;
1234 fe0->dvb.name = dev->name;
1236 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1237 q->io_modes = VB2_MMAP | VB2_READ;
1238 q->drv_priv = &dev->ts_q;
1239 q->ops = &saa7134_ts_qops;
1240 q->mem_ops = &vb2_dma_sg_memops;
1241 q->buf_struct_size = sizeof(struct saa7134_buf);
1242 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1243 q->lock = &dev->lock;
1244 q->dev = &dev->pci->dev;
1245 ret = vb2_queue_init(q);
1247 vb2_dvb_dealloc_frontends(&dev->frontends);
1251 switch (dev->board) {
1252 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1253 pr_debug("pinnacle 300i dvb setup\n");
1254 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
1256 if (fe0->dvb.frontend) {
1257 fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
1260 case SAA7134_BOARD_AVERMEDIA_777:
1261 case SAA7134_BOARD_AVERMEDIA_A16AR:
1262 pr_debug("avertv 777 dvb setup\n");
1263 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1265 if (fe0->dvb.frontend) {
1266 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1267 &dev->i2c_adap, 0x61,
1268 TUNER_PHILIPS_TD1316);
1271 case SAA7134_BOARD_AVERMEDIA_A16D:
1272 pr_debug("AverMedia A16D dvb setup\n");
1273 fe0->dvb.frontend = dvb_attach(mt352_attach,
1274 &avermedia_xc3028_mt352_dev,
1278 case SAA7134_BOARD_MD7134:
1279 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1282 if (fe0->dvb.frontend) {
1284 * The TV tuner on this board is actually NOT
1285 * behind the demod i2c gate.
1286 * However, the demod EEPROM is indeed there and it
1287 * conflicts with the SAA7134 chip config EEPROM
1288 * if the i2c gate is open (since they have same
1289 * bus addresses) resulting in card PCI SVID / SSID
1290 * being garbage after a reboot from time to time.
1292 * Let's just leave the gate permanently closed -
1293 * saa7134_i2c_eeprom_md7134_gate() will close it for
1294 * us at probe time if it was open for some reason.
1296 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1297 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1298 &dev->i2c_adap, medion_cardbus.tuner_address,
1299 TUNER_PHILIPS_FMD1216ME_MK3);
1302 case SAA7134_BOARD_PHILIPS_TOUGH:
1303 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1304 &philips_tu1216_60_config,
1306 if (fe0->dvb.frontend) {
1307 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1308 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1311 case SAA7134_BOARD_FLYDVBTDUO:
1312 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1313 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1314 &tda827x_cfg_0) < 0)
1315 goto detach_frontend;
1317 case SAA7134_BOARD_PHILIPS_EUROPA:
1318 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1319 case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
1320 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1321 &philips_europa_config,
1323 if (fe0->dvb.frontend) {
1324 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1325 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1326 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1327 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1328 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1331 case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
1332 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1333 &technotrend_budget_t3000_config,
1335 if (fe0->dvb.frontend) {
1336 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1337 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1338 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1339 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1340 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1343 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1344 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1345 &philips_tu1216_61_config,
1347 if (fe0->dvb.frontend) {
1348 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1349 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1352 case SAA7134_BOARD_KWORLD_DVBT_210:
1353 if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
1354 &tda827x_cfg_2) < 0)
1355 goto detach_frontend;
1357 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
1358 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1359 &hcw_tda10048_config,
1361 if (fe0->dvb.frontend != NULL) {
1362 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1363 &dev->i2c_adap, 0x4b,
1365 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1366 0x60, &dev->i2c_adap,
1367 &hcw_tda18271_config);
1370 case SAA7134_BOARD_PHILIPS_TIGER:
1371 if (configure_tda827x_fe(dev, &philips_tiger_config,
1372 &tda827x_cfg_0) < 0)
1373 goto detach_frontend;
1375 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1376 if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
1377 &tda827x_cfg_1) < 0)
1378 goto detach_frontend;
1380 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1381 if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
1382 &tda827x_cfg_1) < 0)
1383 goto detach_frontend;
1385 case SAA7134_BOARD_HAUPPAUGE_HVR1150:
1386 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1387 &hcw_lgdt3305_config,
1389 if (fe0->dvb.frontend) {
1390 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1391 &dev->i2c_adap, 0x4b,
1393 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1394 0x60, &dev->i2c_adap,
1395 &hcw_tda18271_config);
1398 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1399 if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
1400 &tda827x_cfg_0) < 0)
1401 goto detach_frontend;
1403 case SAA7134_BOARD_FLYDVBT_LR301:
1404 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1405 &tda827x_cfg_0) < 0)
1406 goto detach_frontend;
1408 case SAA7134_BOARD_FLYDVB_TRIO:
1409 if (!use_frontend) { /* terrestrial */
1410 if (configure_tda827x_fe(dev, &lifeview_trio_config,
1411 &tda827x_cfg_0) < 0)
1412 goto detach_frontend;
1413 } else { /* satellite */
1414 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1415 if (fe0->dvb.frontend) {
1416 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
1417 &dev->i2c_adap, 0) == NULL) {
1418 pr_warn("%s: Lifeview Trio, No tda826x found!\n",
1420 goto detach_frontend;
1422 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1424 0x08, 0, 0, false) == NULL) {
1425 pr_warn("%s: Lifeview Trio, No ISL6421 found!\n",
1427 goto detach_frontend;
1432 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1433 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1434 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1435 &ads_tech_duo_config,
1437 if (fe0->dvb.frontend) {
1438 if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
1439 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1440 &ads_duo_cfg) == NULL) {
1441 pr_warn("no tda827x tuner found at addr: %02x\n",
1442 ads_tech_duo_config.tuner_address);
1443 goto detach_frontend;
1446 pr_warn("failed to attach tda10046\n");
1448 case SAA7134_BOARD_TEVION_DVBT_220RF:
1449 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
1450 &tda827x_cfg_0) < 0)
1451 goto detach_frontend;
1453 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1454 if (!use_frontend) { /* terrestrial */
1455 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1456 &tda827x_cfg_0) < 0)
1457 goto detach_frontend;
1458 } else { /* satellite */
1459 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1460 &flydvbs, &dev->i2c_adap);
1461 if (fe0->dvb.frontend) {
1462 struct dvb_frontend *fe = fe0->dvb.frontend;
1463 u8 dev_id = dev->eedata[2];
1465 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1467 if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
1468 0x60, &dev->i2c_adap, 0) == NULL) {
1469 pr_warn("%s: Medion Quadro, no tda826x found !\n",
1471 goto detach_frontend;
1473 if (dev_id != 0x08) {
1474 /* we need to open the i2c gate (we know it exists) */
1475 fe->ops.i2c_gate_ctrl(fe, 1);
1476 if (dvb_attach(isl6405_attach, fe,
1477 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1478 pr_warn("%s: Medion Quadro, no ISL6405 found !\n",
1480 goto detach_frontend;
1482 if (dev_id == 0x07) {
1483 /* fire up the 2nd section of the LNB supply since
1484 we can't do this from the other section */
1486 i2c_transfer(&dev->i2c_adap, &msg, 1);
1488 fe->ops.i2c_gate_ctrl(fe, 0);
1489 dev->original_set_voltage = fe->ops.set_voltage;
1490 fe->ops.set_voltage = md8800_set_voltage;
1491 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1492 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1494 fe->ops.set_voltage = md8800_set_voltage2;
1495 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1500 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1501 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1503 if (fe0->dvb.frontend)
1504 dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
1505 NULL, DVB_PLL_TDHU2);
1507 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
1508 case SAA7134_BOARD_KWORLD_ATSC110:
1509 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1511 if (fe0->dvb.frontend)
1512 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1513 &dev->i2c_adap, 0x61,
1514 TUNER_PHILIPS_TUV1236D);
1516 case SAA7134_BOARD_KWORLD_PC150U:
1517 saa7134_set_gpio(dev, 18, 1); /* Switch to digital mode */
1518 saa7134_tuner_callback(dev, 0,
1519 TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
1520 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1521 &kworld_s5h1411_config,
1523 if (fe0->dvb.frontend != NULL) {
1524 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1525 &dev->i2c_adap, 0x4b,
1527 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1528 0x60, &dev->i2c_adap,
1529 &kworld_pc150u_tda18271_config);
1532 case SAA7134_BOARD_FLYDVBS_LR300:
1533 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1535 if (fe0->dvb.frontend) {
1536 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1537 &dev->i2c_adap, 0) == NULL) {
1538 pr_warn("%s: No tda826x found!\n", __func__);
1539 goto detach_frontend;
1541 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1543 0x08, 0, 0, false) == NULL) {
1544 pr_warn("%s: No ISL6421 found!\n", __func__);
1545 goto detach_frontend;
1549 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1550 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1553 if (fe0->dvb.frontend) {
1554 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1555 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1557 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1558 &dev->i2c_adap, medion_cardbus.tuner_address,
1559 TUNER_PHILIPS_FMD1216ME_MK3);
1562 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1563 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1564 &philips_europa_config,
1566 if (fe0->dvb.frontend) {
1567 fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1568 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1571 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1572 if (configure_tda827x_fe(dev, &cinergy_ht_config,
1573 &tda827x_cfg_0) < 0)
1574 goto detach_frontend;
1576 case SAA7134_BOARD_CINERGY_HT_PCI:
1577 if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
1578 &tda827x_cfg_0) < 0)
1579 goto detach_frontend;
1581 case SAA7134_BOARD_PHILIPS_TIGER_S:
1582 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1583 &tda827x_cfg_2) < 0)
1584 goto detach_frontend;
1586 case SAA7134_BOARD_ASUS_P7131_4871:
1587 if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
1588 &tda827x_cfg_2) < 0)
1589 goto detach_frontend;
1591 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1592 if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
1593 &tda827x_cfg_2) < 0)
1594 goto detach_frontend;
1596 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1597 if (configure_tda827x_fe(dev, &avermedia_super_007_config,
1598 &tda827x_cfg_0) < 0)
1599 goto detach_frontend;
1601 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1602 if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
1603 &tda827x_cfg_2_sw42) < 0)
1604 goto detach_frontend;
1606 case SAA7134_BOARD_PHILIPS_SNAKE:
1607 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1609 if (fe0->dvb.frontend) {
1610 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1611 &dev->i2c_adap, 0) == NULL) {
1612 pr_warn("%s: No tda826x found!\n", __func__);
1613 goto detach_frontend;
1615 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1616 &dev->i2c_adap, 0, 0) == NULL) {
1617 pr_warn("%s: No lnbp21 found!\n", __func__);
1618 goto detach_frontend;
1622 case SAA7134_BOARD_CREATIX_CTX953:
1623 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1624 &tda827x_cfg_0) < 0)
1625 goto detach_frontend;
1627 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1628 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1629 &tda827x_cfg_2) < 0)
1630 goto detach_frontend;
1632 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1633 pr_debug("AverMedia E506R dvb setup\n");
1634 saa7134_set_gpio(dev, 25, 0);
1636 saa7134_set_gpio(dev, 25, 1);
1637 fe0->dvb.frontend = dvb_attach(mt352_attach,
1638 &avermedia_xc3028_mt352_dev,
1642 case SAA7134_BOARD_MD7134_BRIDGE_2:
1643 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1644 &sd1878_4m, &dev->i2c_adap);
1645 if (fe0->dvb.frontend) {
1646 struct dvb_frontend *fe;
1647 if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1648 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
1649 pr_warn("%s: MD7134 DVB-S, no SD1878 found !\n",
1651 goto detach_frontend;
1653 /* we need to open the i2c gate (we know it exists) */
1654 fe = fe0->dvb.frontend;
1655 fe->ops.i2c_gate_ctrl(fe, 1);
1656 if (dvb_attach(isl6405_attach, fe,
1657 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1658 pr_warn("%s: MD7134 DVB-S, no ISL6405 found !\n",
1660 goto detach_frontend;
1662 fe->ops.i2c_gate_ctrl(fe, 0);
1663 dev->original_set_voltage = fe->ops.set_voltage;
1664 fe->ops.set_voltage = md8800_set_voltage;
1665 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1666 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1669 case SAA7134_BOARD_AVERMEDIA_M103:
1670 saa7134_set_gpio(dev, 25, 0);
1672 saa7134_set_gpio(dev, 25, 1);
1673 fe0->dvb.frontend = dvb_attach(mt352_attach,
1674 &avermedia_xc3028_mt352_dev,
1678 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1679 if (!use_frontend) { /* terrestrial */
1680 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1681 &tda827x_cfg_2) < 0)
1682 goto detach_frontend;
1683 } else { /* satellite */
1684 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1685 &flydvbs, &dev->i2c_adap);
1686 if (fe0->dvb.frontend) {
1687 if (dvb_attach(tda826x_attach,
1688 fe0->dvb.frontend, 0x60,
1689 &dev->i2c_adap, 0) == NULL) {
1690 pr_warn("%s: Asus Tiger 3in1, no tda826x found!\n",
1692 goto detach_frontend;
1694 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1695 &dev->i2c_adap, 0, 0) == NULL) {
1696 pr_warn("%s: Asus Tiger 3in1, no lnbp21 found!\n",
1698 goto detach_frontend;
1703 case SAA7134_BOARD_ASUSTeK_PS3_100:
1704 if (!use_frontend) { /* terrestrial */
1705 if (configure_tda827x_fe(dev, &asus_ps3_100_config,
1706 &tda827x_cfg_2) < 0)
1707 goto detach_frontend;
1708 } else { /* satellite */
1709 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1710 &flydvbs, &dev->i2c_adap);
1711 if (fe0->dvb.frontend) {
1712 if (dvb_attach(tda826x_attach,
1713 fe0->dvb.frontend, 0x60,
1714 &dev->i2c_adap, 0) == NULL) {
1715 pr_warn("%s: Asus My Cinema PS3-100, no tda826x found!\n",
1717 goto detach_frontend;
1719 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1720 &dev->i2c_adap, 0, 0) == NULL) {
1721 pr_warn("%s: Asus My Cinema PS3-100, no lnbp21 found!\n",
1723 goto detach_frontend;
1728 case SAA7134_BOARD_ASUSTeK_TIGER:
1729 if (configure_tda827x_fe(dev, &philips_tiger_config,
1730 &tda827x_cfg_0) < 0)
1731 goto detach_frontend;
1733 case SAA7134_BOARD_BEHOLD_H6:
1734 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1737 if (fe0->dvb.frontend) {
1738 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1739 &dev->i2c_adap, 0x61,
1740 TUNER_PHILIPS_FMD1216MEX_MK3);
1743 case SAA7134_BOARD_BEHOLD_X7:
1744 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1747 if (fe0->dvb.frontend) {
1748 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1749 &dev->i2c_adap, &behold_x7_tunerconfig);
1752 case SAA7134_BOARD_BEHOLD_H7:
1753 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1756 if (fe0->dvb.frontend) {
1757 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1758 &dev->i2c_adap, &behold_x7_tunerconfig);
1761 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
1762 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
1763 /* Zarlink ZL10313 */
1764 fe0->dvb.frontend = dvb_attach(mt312_attach,
1765 &avertv_a700_mt312, &dev->i2c_adap);
1766 if (fe0->dvb.frontend) {
1767 if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
1768 &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
1769 pr_warn("%s: No zl10036 found!\n",
1774 case SAA7134_BOARD_VIDEOMATE_S350:
1775 fe0->dvb.frontend = dvb_attach(mt312_attach,
1776 &zl10313_compro_s350_config, &dev->i2c_adap);
1777 if (fe0->dvb.frontend)
1778 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1779 0x60, &dev->i2c_adap) == NULL)
1780 pr_warn("%s: No zl10039 found!\n",
1784 case SAA7134_BOARD_VIDEOMATE_T750:
1785 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1786 &videomate_t750_zl10353_config,
1788 if (fe0->dvb.frontend != NULL) {
1789 if (dvb_attach(qt1010_attach,
1792 &videomate_t750_qt1010_config) == NULL)
1793 pr_warn("error attaching QT1010\n");
1796 case SAA7134_BOARD_ZOLID_HYBRID_PCI:
1797 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1798 &zolid_tda10048_config,
1800 if (fe0->dvb.frontend != NULL) {
1801 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1802 &dev->i2c_adap, 0x4b,
1804 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1805 0x60, &dev->i2c_adap,
1806 &zolid_tda18271_config);
1809 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
1810 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1811 &dtv1000s_tda10048_config,
1813 if (fe0->dvb.frontend != NULL) {
1814 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1815 &dev->i2c_adap, 0x4b,
1817 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1818 0x60, &dev->i2c_adap,
1819 &dtv1000s_tda18271_config);
1822 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
1823 /* Switch to digital mode */
1824 saa7134_tuner_callback(dev, 0,
1825 TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
1826 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1827 &kworld_mb86a20s_config,
1829 if (fe0->dvb.frontend != NULL) {
1830 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1831 &dev->i2c_adap, 0x4b,
1833 fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_gate_ctrl;
1834 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1835 0x60, &dev->i2c_adap,
1836 &kworld_tda18271_config);
1839 /* mb86a20s need to use the I2C gateway */
1841 case SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2:
1842 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1843 &prohdtv_pro2_lgs8g75_config,
1845 if (fe0->dvb.frontend != NULL) {
1846 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1847 &dev->i2c_adap, 0x4b,
1849 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1850 0x60, &dev->i2c_adap,
1851 &prohdtv_pro2_tda18271_config);
1854 case SAA7134_BOARD_AVERMEDIA_A706:
1855 /* Enable all DVB-S devices now */
1856 /* CE5039 DVB-S tuner SLEEP pin low */
1857 saa7134_set_gpio(dev, 23, 0);
1858 /* CE6313 DVB-S demod SLEEP pin low */
1859 saa7134_set_gpio(dev, 9, 0);
1860 /* CE6313 DVB-S demod RESET# pin high */
1861 saa7134_set_gpio(dev, 25, 1);
1863 fe0->dvb.frontend = dvb_attach(mt312_attach,
1864 &zl10313_avermedia_a706_config, &dev->i2c_adap);
1865 if (fe0->dvb.frontend) {
1866 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1867 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1868 0x60, &dev->i2c_adap) == NULL)
1869 pr_warn("%s: No zl10039 found!\n",
1873 case SAA7134_BOARD_LEADTEK_WINFAST_HDTV200_H:
1874 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1875 &hdtv200h_s5h1411_config,
1877 if (fe0->dvb.frontend) {
1878 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1879 &dev->i2c_adap, 0x4b,
1881 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1882 0x60, &dev->i2c_adap,
1883 &hdtv200h_tda18271_config);
1887 pr_warn("Huh? unknown DVB card?\n");
1891 if (attach_xc3028) {
1892 struct dvb_frontend *fe;
1893 struct xc2028_config cfg = {
1894 .i2c_adap = &dev->i2c_adap,
1898 if (!fe0->dvb.frontend)
1899 goto detach_frontend;
1901 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
1903 pr_err("%s/2: xc3028 attach failed\n",
1905 goto detach_frontend;
1909 if (NULL == fe0->dvb.frontend) {
1910 pr_err("%s/dvb: frontend initialization failed\n", dev->name);
1911 goto detach_frontend;
1913 /* define general-purpose callback pointer */
1914 fe0->dvb.frontend->callback = saa7134_tuner_callback;
1916 /* register everything else */
1917 #ifndef CONFIG_MEDIA_CONTROLLER_DVB
1918 ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
1919 &dev->pci->dev, NULL,
1922 ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
1923 &dev->pci->dev, dev->media_dev,
1927 /* this sequence is necessary to make the tda1004x load its firmware
1928 * and to enter analog mode of hybrid boards
1931 if (fe0->dvb.frontend->ops.init)
1932 fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
1933 if (fe0->dvb.frontend->ops.sleep)
1934 fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
1935 if (fe0->dvb.frontend->ops.tuner_ops.sleep)
1936 fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
1941 vb2_dvb_dealloc_frontends(&dev->frontends);
1942 vb2_queue_release(&fe0->dvb.dvbq);
1946 static int dvb_fini(struct saa7134_dev *dev)
1948 struct vb2_dvb_frontend *fe0;
1950 /* Get the first frontend */
1951 fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
1955 /* FIXME: I suspect that this code is bogus, since the entry for
1956 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1957 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1959 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1960 struct v4l2_priv_tun_config tda9887_cfg;
1961 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1963 tda9887_cfg.tuner = TUNER_TDA9887;
1964 tda9887_cfg.priv = &on;
1966 /* otherwise we don't detect the tuner on next insmod */
1967 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1968 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1969 if ((dev->eedata[2] == 0x07) && use_frontend) {
1970 /* turn off the 2nd lnb supply */
1972 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1973 struct dvb_frontend *fe;
1974 fe = fe0->dvb.frontend;
1975 if (fe->ops.i2c_gate_ctrl) {
1976 fe->ops.i2c_gate_ctrl(fe, 1);
1977 i2c_transfer(&dev->i2c_adap, &msg, 1);
1978 fe->ops.i2c_gate_ctrl(fe, 0);
1982 vb2_dvb_unregister_bus(&dev->frontends);
1983 vb2_queue_release(&fe0->dvb.dvbq);
1987 static struct saa7134_mpeg_ops dvb_ops = {
1988 .type = SAA7134_MPEG_DVB,
1993 static int __init dvb_register(void)
1995 return saa7134_ts_register(&dvb_ops);
1998 static void __exit dvb_unregister(void)
2000 saa7134_ts_unregister(&dvb_ops);
2003 module_init(dvb_register);
2004 module_exit(dvb_unregister);