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/delay.h>
28 #include <linux/kthread.h>
29 #include <linux/suspend.h>
31 #include "saa7134-reg.h"
33 #include <media/v4l2-common.h>
35 #include <dvb_frontend.h>
38 #include "mt352_priv.h" /* FIXME */
41 #include "tuner-xc2028.h"
50 #include "tuner-simple.h"
63 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
64 MODULE_LICENSE("GPL");
66 static unsigned int antenna_pwr;
68 module_param(antenna_pwr, int, 0444);
69 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
71 static int use_frontend;
72 module_param(use_frontend, int, 0644);
73 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
76 module_param(debug, int, 0644);
77 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
79 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
81 #define dprintk(fmt, arg...) do { if (debug) \
82 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
85 #define wprintk(fmt, arg...) \
86 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
88 /* ------------------------------------------------------------------
89 * mt352 based DVB-T cards
92 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
97 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
98 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
102 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
103 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
106 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
107 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
109 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
111 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
112 dprintk("%s %s\n", __func__, ok ? "on" : "off");
115 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
119 static int mt352_pinnacle_init(struct dvb_frontend* fe)
121 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
122 static u8 reset [] = { RESET, 0x80 };
123 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
124 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
125 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
126 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
127 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
128 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
129 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
130 struct saa7134_dev *dev= fe->dvb->priv;
132 dprintk("%s called\n", __func__);
134 mt352_write(fe, clock_config, sizeof(clock_config));
136 mt352_write(fe, reset, sizeof(reset));
137 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
138 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
139 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
140 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
142 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
143 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
144 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
149 static int mt352_aver777_init(struct dvb_frontend* fe)
151 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
152 static u8 reset [] = { RESET, 0x80 };
153 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
154 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
155 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
157 mt352_write(fe, clock_config, sizeof(clock_config));
159 mt352_write(fe, reset, sizeof(reset));
160 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
161 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
162 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
167 static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
169 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
170 static u8 reset [] = { RESET, 0x80 };
171 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
172 static u8 agc_cfg [] = { AGC_TARGET, 0xe };
173 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
175 mt352_write(fe, clock_config, sizeof(clock_config));
177 mt352_write(fe, reset, sizeof(reset));
178 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
179 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
180 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
184 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
185 struct dvb_frontend_parameters* params)
187 u8 off[] = { 0x00, 0xf1};
188 u8 on[] = { 0x00, 0x71};
189 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
191 struct saa7134_dev *dev = fe->dvb->priv;
192 struct v4l2_frequency f;
194 /* set frequency (mt2050) */
196 f.type = V4L2_TUNER_DIGITAL_TV;
197 f.frequency = params->frequency / 1000 * 16 / 1000;
198 if (fe->ops.i2c_gate_ctrl)
199 fe->ops.i2c_gate_ctrl(fe, 1);
200 i2c_transfer(&dev->i2c_adap, &msg, 1);
201 saa_call_all(dev, tuner, s_frequency, &f);
203 if (fe->ops.i2c_gate_ctrl)
204 fe->ops.i2c_gate_ctrl(fe, 1);
205 i2c_transfer(&dev->i2c_adap, &msg, 1);
207 pinnacle_antenna_pwr(dev, antenna_pwr);
210 return mt352_pinnacle_init(fe);
213 static struct mt352_config pinnacle_300i = {
214 .demod_address = 0x3c >> 1,
218 .demod_init = mt352_pinnacle_init,
221 static struct mt352_config avermedia_777 = {
222 .demod_address = 0xf,
223 .demod_init = mt352_aver777_init,
226 static struct mt352_config avermedia_xc3028_mt352_dev = {
227 .demod_address = (0x1e >> 1),
229 .demod_init = mt352_avermedia_xc3028_init,
232 static struct tda18271_std_map mb86a20s_tda18271_std_map = {
233 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
234 .if_lvl = 7, .rfagc_top = 0x37, },
237 static struct tda18271_config kworld_tda18271_config = {
238 .std_map = &mb86a20s_tda18271_std_map,
239 .gate = TDA18271_GATE_DIGITAL,
242 static const struct mb86a20s_config kworld_mb86a20s_config = {
243 .demod_address = 0x10,
246 /* ==================================================================
247 * tda1004x based DVB-T cards, helper functions
250 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
251 const struct firmware **fw, char *name)
253 struct saa7134_dev *dev = fe->dvb->priv;
254 return request_firmware(fw, name, &dev->pci->dev);
257 /* ------------------------------------------------------------------
258 * these tuners are tu1216, td1316(a)
261 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
263 struct saa7134_dev *dev = fe->dvb->priv;
264 struct tda1004x_state *state = fe->demodulator_priv;
265 u8 addr = state->config->tuner_address;
267 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
269 int tuner_frequency = 0;
272 /* determine charge pump */
273 tuner_frequency = params->frequency + 36166000;
274 if (tuner_frequency < 87000000)
276 else if (tuner_frequency < 130000000)
278 else if (tuner_frequency < 160000000)
280 else if (tuner_frequency < 200000000)
282 else if (tuner_frequency < 290000000)
284 else if (tuner_frequency < 420000000)
286 else if (tuner_frequency < 480000000)
288 else if (tuner_frequency < 620000000)
290 else if (tuner_frequency < 830000000)
292 else if (tuner_frequency < 895000000)
298 if (params->frequency < 49000000)
300 else if (params->frequency < 161000000)
302 else if (params->frequency < 444000000)
304 else if (params->frequency < 861000000)
309 /* setup PLL filter */
310 switch (params->u.ofdm.bandwidth) {
311 case BANDWIDTH_6_MHZ:
315 case BANDWIDTH_7_MHZ:
319 case BANDWIDTH_8_MHZ:
328 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
330 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
332 /* setup tuner buffer */
333 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
334 tuner_buf[1] = tuner_frequency & 0xff;
336 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
338 if (fe->ops.i2c_gate_ctrl)
339 fe->ops.i2c_gate_ctrl(fe, 1);
340 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
341 wprintk("could not write to tuner at addr: 0x%02x\n",
349 static int philips_tu1216_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 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
355 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
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, &tuner_msg, 1) != 1)
367 /* ------------------------------------------------------------------ */
369 static struct tda1004x_config philips_tu1216_60_config = {
370 .demod_address = 0x8,
373 .xtal_freq = TDA10046_XTAL_4M,
374 .agc_config = TDA10046_AGC_DEFAULT,
375 .if_freq = TDA10046_FREQ_3617,
376 .tuner_address = 0x60,
377 .request_firmware = philips_tda1004x_request_firmware
380 static struct tda1004x_config philips_tu1216_61_config = {
382 .demod_address = 0x8,
385 .xtal_freq = TDA10046_XTAL_4M,
386 .agc_config = TDA10046_AGC_DEFAULT,
387 .if_freq = TDA10046_FREQ_3617,
388 .tuner_address = 0x61,
389 .request_firmware = philips_tda1004x_request_firmware
392 /* ------------------------------------------------------------------ */
394 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
396 struct saa7134_dev *dev = fe->dvb->priv;
397 struct tda1004x_state *state = fe->demodulator_priv;
398 u8 addr = state->config->tuner_address;
399 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
400 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
402 /* setup PLL configuration */
403 if (fe->ops.i2c_gate_ctrl)
404 fe->ops.i2c_gate_ctrl(fe, 1);
405 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
410 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
412 return philips_tda6651_pll_set(fe, params);
415 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
417 struct saa7134_dev *dev = fe->dvb->priv;
418 struct tda1004x_state *state = fe->demodulator_priv;
419 u8 addr = state->config->tuner_address;
420 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
421 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
423 /* switch the tuner to analog mode */
424 if (fe->ops.i2c_gate_ctrl)
425 fe->ops.i2c_gate_ctrl(fe, 1);
426 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
431 /* ------------------------------------------------------------------ */
433 static int philips_europa_tuner_init(struct dvb_frontend *fe)
435 struct saa7134_dev *dev = fe->dvb->priv;
436 static u8 msg[] = { 0x00, 0x40};
437 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
440 if (philips_td1316_tuner_init(fe))
443 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
449 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
451 struct saa7134_dev *dev = fe->dvb->priv;
453 static u8 msg[] = { 0x00, 0x14 };
454 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
456 if (philips_td1316_tuner_sleep(fe))
459 /* switch the board to analog mode */
460 if (fe->ops.i2c_gate_ctrl)
461 fe->ops.i2c_gate_ctrl(fe, 1);
462 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
466 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
468 struct saa7134_dev *dev = fe->dvb->priv;
470 if (dev->original_demod_sleep)
471 dev->original_demod_sleep(fe);
472 fe->ops.i2c_gate_ctrl(fe, 1);
476 static struct tda1004x_config philips_europa_config = {
478 .demod_address = 0x8,
481 .xtal_freq = TDA10046_XTAL_4M,
482 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
483 .if_freq = TDA10046_FREQ_052,
484 .tuner_address = 0x61,
485 .request_firmware = philips_tda1004x_request_firmware
488 static struct tda1004x_config medion_cardbus = {
489 .demod_address = 0x08,
492 .xtal_freq = TDA10046_XTAL_16M,
493 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
494 .if_freq = TDA10046_FREQ_3613,
495 .tuner_address = 0x61,
496 .request_firmware = philips_tda1004x_request_firmware
499 static struct tda1004x_config technotrend_budget_t3000_config = {
500 .demod_address = 0x8,
503 .xtal_freq = TDA10046_XTAL_4M,
504 .agc_config = TDA10046_AGC_DEFAULT,
505 .if_freq = TDA10046_FREQ_3617,
506 .tuner_address = 0x63,
507 .request_firmware = philips_tda1004x_request_firmware
510 /* ------------------------------------------------------------------
511 * tda 1004x based cards with philips silicon tuner
514 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
516 struct tda1004x_state *state = fe->demodulator_priv;
518 u8 addr = state->config->i2c_gate;
519 static u8 tda8290_close[] = { 0x21, 0xc0};
520 static u8 tda8290_open[] = { 0x21, 0x80};
521 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
523 tda8290_msg.buf = tda8290_close;
525 tda8290_msg.buf = tda8290_open;
527 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
528 struct saa7134_dev *dev = fe->dvb->priv;
529 wprintk("could not access tda8290 I2C gate\n");
536 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
538 struct saa7134_dev *dev = fe->dvb->priv;
539 struct tda1004x_state *state = fe->demodulator_priv;
541 switch (state->config->antenna_switch) {
543 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
544 saa7134_set_gpio(dev, 21, 0);
546 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
547 saa7134_set_gpio(dev, 21, 1);
553 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
555 struct saa7134_dev *dev = fe->dvb->priv;
556 struct tda1004x_state *state = fe->demodulator_priv;
558 switch (state->config->antenna_switch) {
560 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
561 saa7134_set_gpio(dev, 21, 1);
563 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
564 saa7134_set_gpio(dev, 21, 0);
570 static int configure_tda827x_fe(struct saa7134_dev *dev,
571 struct tda1004x_config *cdec_conf,
572 struct tda827x_config *tuner_conf)
574 struct videobuf_dvb_frontend *fe0;
576 /* Get the first frontend */
577 fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
579 fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
580 if (fe0->dvb.frontend) {
581 if (cdec_conf->i2c_gate)
582 fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
583 if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
584 cdec_conf->tuner_address,
585 &dev->i2c_adap, tuner_conf))
588 wprintk("no tda827x tuner found at addr: %02x\n",
589 cdec_conf->tuner_address);
594 /* ------------------------------------------------------------------ */
596 static struct tda827x_config tda827x_cfg_0 = {
597 .init = philips_tda827x_tuner_init,
598 .sleep = philips_tda827x_tuner_sleep,
603 static struct tda827x_config tda827x_cfg_1 = {
604 .init = philips_tda827x_tuner_init,
605 .sleep = philips_tda827x_tuner_sleep,
610 static struct tda827x_config tda827x_cfg_2 = {
611 .init = philips_tda827x_tuner_init,
612 .sleep = philips_tda827x_tuner_sleep,
617 static struct tda827x_config tda827x_cfg_2_sw42 = {
618 .init = philips_tda827x_tuner_init,
619 .sleep = philips_tda827x_tuner_sleep,
624 /* ------------------------------------------------------------------ */
626 static int __kworld_sbtvd_i2c_gate_ctrl(struct saa7134_dev *dev, int enable)
628 unsigned char initmsg[] = {0x45, 0x97};
629 unsigned char msg_enable[] = {0x45, 0xc1};
630 unsigned char msg_disable[] = {0x45, 0x81};
631 struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
633 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
634 wprintk("could not access the I2C gate\n");
638 msg.buf = msg_enable;
640 msg.buf = msg_disable;
641 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
642 wprintk("could not access the I2C gate\n");
648 static int kworld_sbtvd_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
650 struct saa7134_dev *dev = fe->dvb->priv;
652 return __kworld_sbtvd_i2c_gate_ctrl(dev, enable);
655 /* ------------------------------------------------------------------ */
657 static struct tda1004x_config tda827x_lifeview_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,
665 .tuner_address = 0x60,
666 .request_firmware = philips_tda1004x_request_firmware
669 static struct tda1004x_config philips_tiger_config = {
670 .demod_address = 0x08,
673 .xtal_freq = TDA10046_XTAL_16M,
674 .agc_config = TDA10046_AGC_TDA827X,
675 .gpio_config = TDA10046_GP11_I,
676 .if_freq = TDA10046_FREQ_045,
678 .tuner_address = 0x61,
680 .request_firmware = philips_tda1004x_request_firmware
683 static struct tda1004x_config cinergy_ht_config = {
684 .demod_address = 0x08,
687 .xtal_freq = TDA10046_XTAL_16M,
688 .agc_config = TDA10046_AGC_TDA827X,
689 .gpio_config = TDA10046_GP01_I,
690 .if_freq = TDA10046_FREQ_045,
692 .tuner_address = 0x61,
693 .request_firmware = philips_tda1004x_request_firmware
696 static struct tda1004x_config cinergy_ht_pci_config = {
697 .demod_address = 0x08,
700 .xtal_freq = TDA10046_XTAL_16M,
701 .agc_config = TDA10046_AGC_TDA827X,
702 .gpio_config = TDA10046_GP01_I,
703 .if_freq = TDA10046_FREQ_045,
705 .tuner_address = 0x60,
706 .request_firmware = philips_tda1004x_request_firmware
709 static struct tda1004x_config philips_tiger_s_config = {
710 .demod_address = 0x08,
713 .xtal_freq = TDA10046_XTAL_16M,
714 .agc_config = TDA10046_AGC_TDA827X,
715 .gpio_config = TDA10046_GP01_I,
716 .if_freq = TDA10046_FREQ_045,
718 .tuner_address = 0x61,
720 .request_firmware = philips_tda1004x_request_firmware
723 static struct tda1004x_config pinnacle_pctv_310i_config = {
724 .demod_address = 0x08,
727 .xtal_freq = TDA10046_XTAL_16M,
728 .agc_config = TDA10046_AGC_TDA827X,
729 .gpio_config = TDA10046_GP11_I,
730 .if_freq = TDA10046_FREQ_045,
732 .tuner_address = 0x61,
733 .request_firmware = philips_tda1004x_request_firmware
736 static struct tda1004x_config hauppauge_hvr_1110_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,
746 .request_firmware = philips_tda1004x_request_firmware
749 static struct tda1004x_config asus_p7131_dual_config = {
750 .demod_address = 0x08,
753 .xtal_freq = TDA10046_XTAL_16M,
754 .agc_config = TDA10046_AGC_TDA827X,
755 .gpio_config = TDA10046_GP11_I,
756 .if_freq = TDA10046_FREQ_045,
758 .tuner_address = 0x61,
760 .request_firmware = philips_tda1004x_request_firmware
763 static struct tda1004x_config lifeview_trio_config = {
764 .demod_address = 0x09,
767 .xtal_freq = TDA10046_XTAL_16M,
768 .agc_config = TDA10046_AGC_TDA827X,
769 .gpio_config = TDA10046_GP00_I,
770 .if_freq = TDA10046_FREQ_045,
771 .tuner_address = 0x60,
772 .request_firmware = philips_tda1004x_request_firmware
775 static struct tda1004x_config tevion_dvbt220rf_config = {
776 .demod_address = 0x08,
779 .xtal_freq = TDA10046_XTAL_16M,
780 .agc_config = TDA10046_AGC_TDA827X,
781 .gpio_config = TDA10046_GP11_I,
782 .if_freq = TDA10046_FREQ_045,
783 .tuner_address = 0x60,
784 .request_firmware = philips_tda1004x_request_firmware
787 static struct tda1004x_config md8800_dvbt_config = {
788 .demod_address = 0x08,
791 .xtal_freq = TDA10046_XTAL_16M,
792 .agc_config = TDA10046_AGC_TDA827X,
793 .gpio_config = TDA10046_GP01_I,
794 .if_freq = TDA10046_FREQ_045,
796 .tuner_address = 0x60,
797 .request_firmware = philips_tda1004x_request_firmware
800 static struct tda1004x_config asus_p7131_4871_config = {
801 .demod_address = 0x08,
804 .xtal_freq = TDA10046_XTAL_16M,
805 .agc_config = TDA10046_AGC_TDA827X,
806 .gpio_config = TDA10046_GP01_I,
807 .if_freq = TDA10046_FREQ_045,
809 .tuner_address = 0x61,
811 .request_firmware = philips_tda1004x_request_firmware
814 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
815 .demod_address = 0x08,
818 .xtal_freq = TDA10046_XTAL_16M,
819 .agc_config = TDA10046_AGC_TDA827X,
820 .gpio_config = TDA10046_GP11_I,
821 .if_freq = TDA10046_FREQ_045,
823 .tuner_address = 0x61,
825 .request_firmware = philips_tda1004x_request_firmware
828 static struct tda1004x_config kworld_dvb_t_210_config = {
829 .demod_address = 0x08,
832 .xtal_freq = TDA10046_XTAL_16M,
833 .agc_config = TDA10046_AGC_TDA827X,
834 .gpio_config = TDA10046_GP11_I,
835 .if_freq = TDA10046_FREQ_045,
837 .tuner_address = 0x61,
839 .request_firmware = philips_tda1004x_request_firmware
842 static struct tda1004x_config avermedia_super_007_config = {
843 .demod_address = 0x08,
846 .xtal_freq = TDA10046_XTAL_16M,
847 .agc_config = TDA10046_AGC_TDA827X,
848 .gpio_config = TDA10046_GP01_I,
849 .if_freq = TDA10046_FREQ_045,
851 .tuner_address = 0x60,
853 .request_firmware = philips_tda1004x_request_firmware
856 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
857 .demod_address = 0x08,
860 .xtal_freq = TDA10046_XTAL_16M,
861 .agc_config = TDA10046_AGC_TDA827X,
862 .gpio_config = TDA10046_GP01_I,
863 .if_freq = TDA10046_FREQ_045,
865 .tuner_address = 0x61,
867 .request_firmware = philips_tda1004x_request_firmware
870 static struct tda1004x_config asus_tiger_3in1_config = {
871 .demod_address = 0x0b,
874 .xtal_freq = TDA10046_XTAL_16M,
875 .agc_config = TDA10046_AGC_TDA827X,
876 .gpio_config = TDA10046_GP11_I,
877 .if_freq = TDA10046_FREQ_045,
879 .tuner_address = 0x61,
881 .request_firmware = philips_tda1004x_request_firmware
884 /* ------------------------------------------------------------------
885 * special case: this card uses saa713x GPIO22 for the mode switch
888 static int ads_duo_tuner_init(struct dvb_frontend *fe)
890 struct saa7134_dev *dev = fe->dvb->priv;
891 philips_tda827x_tuner_init(fe);
892 /* route TDA8275a AGC input to the channel decoder */
893 saa7134_set_gpio(dev, 22, 1);
897 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
899 struct saa7134_dev *dev = fe->dvb->priv;
900 /* route TDA8275a AGC input to the analog IF chip*/
901 saa7134_set_gpio(dev, 22, 0);
902 philips_tda827x_tuner_sleep(fe);
906 static struct tda827x_config ads_duo_cfg = {
907 .init = ads_duo_tuner_init,
908 .sleep = ads_duo_tuner_sleep,
912 static struct tda1004x_config ads_tech_duo_config = {
913 .demod_address = 0x08,
916 .xtal_freq = TDA10046_XTAL_16M,
917 .agc_config = TDA10046_AGC_TDA827X,
918 .gpio_config = TDA10046_GP00_I,
919 .if_freq = TDA10046_FREQ_045,
920 .tuner_address = 0x61,
921 .request_firmware = philips_tda1004x_request_firmware
924 static struct zl10353_config behold_h6_config = {
925 .demod_address = 0x1e>>1,
928 .disable_i2c_gate_ctrl = 1,
931 static struct xc5000_config behold_x7_tunerconfig = {
932 .i2c_address = 0xc2>>1,
934 .radio_input = XC5000_RADIO_FM1,
937 static struct zl10353_config behold_x7_config = {
938 .demod_address = 0x1e>>1,
942 .disable_i2c_gate_ctrl = 1,
945 /* ==================================================================
946 * tda10086 based DVB-S cards, helper functions
949 static struct tda10086_config flydvbs = {
950 .demod_address = 0x0e,
953 .xtal_freq = TDA10086_XTAL_16M,
956 static struct tda10086_config sd1878_4m = {
957 .demod_address = 0x0e,
960 .xtal_freq = TDA10086_XTAL_4M,
963 /* ------------------------------------------------------------------
964 * special case: lnb supply is connected to the gated i2c
967 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
970 struct saa7134_dev *dev = fe->dvb->priv;
971 if (fe->ops.i2c_gate_ctrl) {
972 fe->ops.i2c_gate_ctrl(fe, 1);
973 if (dev->original_set_voltage)
974 res = dev->original_set_voltage(fe, voltage);
975 fe->ops.i2c_gate_ctrl(fe, 0);
980 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
983 struct saa7134_dev *dev = fe->dvb->priv;
984 if (fe->ops.i2c_gate_ctrl) {
985 fe->ops.i2c_gate_ctrl(fe, 1);
986 if (dev->original_set_high_voltage)
987 res = dev->original_set_high_voltage(fe, arg);
988 fe->ops.i2c_gate_ctrl(fe, 0);
993 static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
995 struct saa7134_dev *dev = fe->dvb->priv;
996 u8 wbuf[2] = { 0x1f, 00 };
998 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
999 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
1001 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
1003 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
1004 if (voltage == SEC_VOLTAGE_18)
1005 wbuf[1] = rbuf | 0x10;
1007 wbuf[1] = rbuf & 0xef;
1009 i2c_transfer(&dev->i2c_adap, msg, 1);
1013 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
1015 struct saa7134_dev *dev = fe->dvb->priv;
1016 wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
1020 /* ==================================================================
1021 * nxt200x based ATSC cards, helper functions
1024 static struct nxt200x_config avertvhda180 = {
1025 .demod_address = 0x0a,
1028 static struct nxt200x_config kworldatsc110 = {
1029 .demod_address = 0x0a,
1032 /* ------------------------------------------------------------------ */
1034 static struct mt312_config avertv_a700_mt312 = {
1035 .demod_address = 0x0e,
1036 .voltage_inverted = 1,
1039 static struct zl10036_config avertv_a700_tuner = {
1040 .tuner_address = 0x60,
1043 static struct mt312_config zl10313_compro_s350_config = {
1044 .demod_address = 0x0e,
1047 static struct lgdt3305_config hcw_lgdt3305_config = {
1049 .mpeg_mode = LGDT3305_MPEG_SERIAL,
1050 .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
1051 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
1053 .spectral_inversion = 1,
1058 static struct tda10048_config hcw_tda10048_config = {
1059 .demod_address = 0x10 >> 1,
1060 .output_mode = TDA10048_SERIAL_OUTPUT,
1061 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1062 .inversion = TDA10048_INVERSION_ON,
1063 .dtv6_if_freq_khz = TDA10048_IF_3300,
1064 .dtv7_if_freq_khz = TDA10048_IF_3500,
1065 .dtv8_if_freq_khz = TDA10048_IF_4000,
1066 .clk_freq_khz = TDA10048_CLK_16000,
1067 .disable_gate_access = 1,
1070 static struct tda18271_std_map hauppauge_tda18271_std_map = {
1071 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
1072 .if_lvl = 1, .rfagc_top = 0x58, },
1073 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
1074 .if_lvl = 1, .rfagc_top = 0x58, },
1077 static struct tda18271_config hcw_tda18271_config = {
1078 .std_map = &hauppauge_tda18271_std_map,
1079 .gate = TDA18271_GATE_ANALOG,
1081 .output_opt = TDA18271_OUTPUT_LT_OFF,
1084 static struct tda829x_config tda829x_no_probe = {
1085 .probe_tuner = TDA829X_DONT_PROBE,
1088 static struct tda10048_config zolid_tda10048_config = {
1089 .demod_address = 0x10 >> 1,
1090 .output_mode = TDA10048_PARALLEL_OUTPUT,
1091 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1092 .inversion = TDA10048_INVERSION_ON,
1093 .dtv6_if_freq_khz = TDA10048_IF_3300,
1094 .dtv7_if_freq_khz = TDA10048_IF_3500,
1095 .dtv8_if_freq_khz = TDA10048_IF_4000,
1096 .clk_freq_khz = TDA10048_CLK_16000,
1097 .disable_gate_access = 1,
1100 static struct tda18271_config zolid_tda18271_config = {
1101 .gate = TDA18271_GATE_ANALOG,
1104 static struct tda10048_config dtv1000s_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_3800,
1111 .dtv8_if_freq_khz = TDA10048_IF_4300,
1112 .clk_freq_khz = TDA10048_CLK_16000,
1113 .disable_gate_access = 1,
1116 static struct tda18271_std_map dtv1000s_tda18271_std_map = {
1117 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
1118 .if_lvl = 1, .rfagc_top = 0x37, },
1119 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
1120 .if_lvl = 1, .rfagc_top = 0x37, },
1121 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
1122 .if_lvl = 1, .rfagc_top = 0x37, },
1125 static struct tda18271_config dtv1000s_tda18271_config = {
1126 .std_map = &dtv1000s_tda18271_std_map,
1127 .gate = TDA18271_GATE_ANALOG,
1130 /* ==================================================================
1134 static int dvb_init(struct saa7134_dev *dev)
1137 int attach_xc3028 = 0;
1138 struct videobuf_dvb_frontend *fe0;
1140 /* FIXME: add support for multi-frontend */
1141 mutex_init(&dev->frontends.lock);
1142 INIT_LIST_HEAD(&dev->frontends.felist);
1144 printk(KERN_INFO "%s() allocating 1 frontend\n", __func__);
1145 fe0 = videobuf_dvb_alloc_frontend(&dev->frontends, 1);
1147 printk(KERN_ERR "%s() failed to alloc\n", __func__);
1151 /* init struct videobuf_dvb */
1152 dev->ts.nr_bufs = 32;
1153 dev->ts.nr_packets = 32*4;
1154 fe0->dvb.name = dev->name;
1155 videobuf_queue_sg_init(&fe0->dvb.dvbq, &saa7134_ts_qops,
1156 &dev->pci->dev, &dev->slock,
1157 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1158 V4L2_FIELD_ALTERNATE,
1159 sizeof(struct saa7134_buf),
1162 switch (dev->board) {
1163 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1164 dprintk("pinnacle 300i dvb setup\n");
1165 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
1167 if (fe0->dvb.frontend) {
1168 fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
1171 case SAA7134_BOARD_AVERMEDIA_777:
1172 case SAA7134_BOARD_AVERMEDIA_A16AR:
1173 dprintk("avertv 777 dvb setup\n");
1174 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1176 if (fe0->dvb.frontend) {
1177 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1178 &dev->i2c_adap, 0x61,
1179 TUNER_PHILIPS_TD1316);
1182 case SAA7134_BOARD_AVERMEDIA_A16D:
1183 dprintk("AverMedia A16D dvb setup\n");
1184 fe0->dvb.frontend = dvb_attach(mt352_attach,
1185 &avermedia_xc3028_mt352_dev,
1189 case SAA7134_BOARD_MD7134:
1190 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1193 if (fe0->dvb.frontend) {
1194 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1195 &dev->i2c_adap, medion_cardbus.tuner_address,
1196 TUNER_PHILIPS_FMD1216ME_MK3);
1199 case SAA7134_BOARD_PHILIPS_TOUGH:
1200 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1201 &philips_tu1216_60_config,
1203 if (fe0->dvb.frontend) {
1204 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1205 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1208 case SAA7134_BOARD_FLYDVBTDUO:
1209 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1210 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1211 &tda827x_cfg_0) < 0)
1212 goto dettach_frontend;
1214 case SAA7134_BOARD_PHILIPS_EUROPA:
1215 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1216 case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
1217 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1218 &philips_europa_config,
1220 if (fe0->dvb.frontend) {
1221 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1222 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1223 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1224 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1225 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1228 case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
1229 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1230 &technotrend_budget_t3000_config,
1232 if (fe0->dvb.frontend) {
1233 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1234 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1235 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1236 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1237 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1240 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1241 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1242 &philips_tu1216_61_config,
1244 if (fe0->dvb.frontend) {
1245 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1246 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1249 case SAA7134_BOARD_KWORLD_DVBT_210:
1250 if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
1251 &tda827x_cfg_2) < 0)
1252 goto dettach_frontend;
1254 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
1255 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1256 &hcw_tda10048_config,
1258 if (fe0->dvb.frontend != NULL) {
1259 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1260 &dev->i2c_adap, 0x4b,
1262 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1263 0x60, &dev->i2c_adap,
1264 &hcw_tda18271_config);
1267 case SAA7134_BOARD_PHILIPS_TIGER:
1268 if (configure_tda827x_fe(dev, &philips_tiger_config,
1269 &tda827x_cfg_0) < 0)
1270 goto dettach_frontend;
1272 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1273 if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
1274 &tda827x_cfg_1) < 0)
1275 goto dettach_frontend;
1277 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1278 if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
1279 &tda827x_cfg_1) < 0)
1280 goto dettach_frontend;
1282 case SAA7134_BOARD_HAUPPAUGE_HVR1150:
1283 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1284 &hcw_lgdt3305_config,
1286 if (fe0->dvb.frontend) {
1287 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1288 &dev->i2c_adap, 0x4b,
1290 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1291 0x60, &dev->i2c_adap,
1292 &hcw_tda18271_config);
1295 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1296 if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
1297 &tda827x_cfg_0) < 0)
1298 goto dettach_frontend;
1300 case SAA7134_BOARD_FLYDVBT_LR301:
1301 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1302 &tda827x_cfg_0) < 0)
1303 goto dettach_frontend;
1305 case SAA7134_BOARD_FLYDVB_TRIO:
1306 if (!use_frontend) { /* terrestrial */
1307 if (configure_tda827x_fe(dev, &lifeview_trio_config,
1308 &tda827x_cfg_0) < 0)
1309 goto dettach_frontend;
1310 } else { /* satellite */
1311 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1312 if (fe0->dvb.frontend) {
1313 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
1314 &dev->i2c_adap, 0) == NULL) {
1315 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
1316 goto dettach_frontend;
1318 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap,
1319 0x08, 0, 0) == NULL) {
1320 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1321 goto dettach_frontend;
1326 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1327 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1328 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1329 &ads_tech_duo_config,
1331 if (fe0->dvb.frontend) {
1332 if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
1333 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1334 &ads_duo_cfg) == NULL) {
1335 wprintk("no tda827x tuner found at addr: %02x\n",
1336 ads_tech_duo_config.tuner_address);
1337 goto dettach_frontend;
1340 wprintk("failed to attach tda10046\n");
1342 case SAA7134_BOARD_TEVION_DVBT_220RF:
1343 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
1344 &tda827x_cfg_0) < 0)
1345 goto dettach_frontend;
1347 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1348 if (!use_frontend) { /* terrestrial */
1349 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1350 &tda827x_cfg_0) < 0)
1351 goto dettach_frontend;
1352 } else { /* satellite */
1353 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1354 &flydvbs, &dev->i2c_adap);
1355 if (fe0->dvb.frontend) {
1356 struct dvb_frontend *fe = fe0->dvb.frontend;
1357 u8 dev_id = dev->eedata[2];
1359 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1361 if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
1362 0x60, &dev->i2c_adap, 0) == NULL) {
1363 wprintk("%s: Medion Quadro, no tda826x "
1364 "found !\n", __func__);
1365 goto dettach_frontend;
1367 if (dev_id != 0x08) {
1368 /* we need to open the i2c gate (we know it exists) */
1369 fe->ops.i2c_gate_ctrl(fe, 1);
1370 if (dvb_attach(isl6405_attach, fe,
1371 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1372 wprintk("%s: Medion Quadro, no ISL6405 "
1373 "found !\n", __func__);
1374 goto dettach_frontend;
1376 if (dev_id == 0x07) {
1377 /* fire up the 2nd section of the LNB supply since
1378 we can't do this from the other section */
1380 i2c_transfer(&dev->i2c_adap, &msg, 1);
1382 fe->ops.i2c_gate_ctrl(fe, 0);
1383 dev->original_set_voltage = fe->ops.set_voltage;
1384 fe->ops.set_voltage = md8800_set_voltage;
1385 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1386 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1388 fe->ops.set_voltage = md8800_set_voltage2;
1389 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1394 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1395 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1397 if (fe0->dvb.frontend)
1398 dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
1399 NULL, DVB_PLL_TDHU2);
1401 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
1402 case SAA7134_BOARD_KWORLD_ATSC110:
1403 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1405 if (fe0->dvb.frontend)
1406 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1407 &dev->i2c_adap, 0x61,
1408 TUNER_PHILIPS_TUV1236D);
1410 case SAA7134_BOARD_FLYDVBS_LR300:
1411 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1413 if (fe0->dvb.frontend) {
1414 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1415 &dev->i2c_adap, 0) == NULL) {
1416 wprintk("%s: No tda826x found!\n", __func__);
1417 goto dettach_frontend;
1419 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1420 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1421 wprintk("%s: No ISL6421 found!\n", __func__);
1422 goto dettach_frontend;
1426 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1427 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1430 if (fe0->dvb.frontend) {
1431 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1432 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1434 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1435 &dev->i2c_adap, medion_cardbus.tuner_address,
1436 TUNER_PHILIPS_FMD1216ME_MK3);
1439 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1440 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1441 &philips_europa_config,
1443 if (fe0->dvb.frontend) {
1444 fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1445 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1448 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1449 if (configure_tda827x_fe(dev, &cinergy_ht_config,
1450 &tda827x_cfg_0) < 0)
1451 goto dettach_frontend;
1453 case SAA7134_BOARD_CINERGY_HT_PCI:
1454 if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
1455 &tda827x_cfg_0) < 0)
1456 goto dettach_frontend;
1458 case SAA7134_BOARD_PHILIPS_TIGER_S:
1459 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1460 &tda827x_cfg_2) < 0)
1461 goto dettach_frontend;
1463 case SAA7134_BOARD_ASUS_P7131_4871:
1464 if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
1465 &tda827x_cfg_2) < 0)
1466 goto dettach_frontend;
1468 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1469 if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
1470 &tda827x_cfg_2) < 0)
1471 goto dettach_frontend;
1473 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1474 if (configure_tda827x_fe(dev, &avermedia_super_007_config,
1475 &tda827x_cfg_0) < 0)
1476 goto dettach_frontend;
1478 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1479 if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
1480 &tda827x_cfg_2_sw42) < 0)
1481 goto dettach_frontend;
1483 case SAA7134_BOARD_PHILIPS_SNAKE:
1484 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1486 if (fe0->dvb.frontend) {
1487 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1488 &dev->i2c_adap, 0) == NULL) {
1489 wprintk("%s: No tda826x found!\n", __func__);
1490 goto dettach_frontend;
1492 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1493 &dev->i2c_adap, 0, 0) == NULL) {
1494 wprintk("%s: No lnbp21 found!\n", __func__);
1495 goto dettach_frontend;
1499 case SAA7134_BOARD_CREATIX_CTX953:
1500 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1501 &tda827x_cfg_0) < 0)
1502 goto dettach_frontend;
1504 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1505 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1506 &tda827x_cfg_2) < 0)
1507 goto dettach_frontend;
1509 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1510 dprintk("AverMedia E506R dvb setup\n");
1511 saa7134_set_gpio(dev, 25, 0);
1513 saa7134_set_gpio(dev, 25, 1);
1514 fe0->dvb.frontend = dvb_attach(mt352_attach,
1515 &avermedia_xc3028_mt352_dev,
1519 case SAA7134_BOARD_MD7134_BRIDGE_2:
1520 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1521 &sd1878_4m, &dev->i2c_adap);
1522 if (fe0->dvb.frontend) {
1523 struct dvb_frontend *fe;
1524 if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1525 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
1526 wprintk("%s: MD7134 DVB-S, no SD1878 "
1527 "found !\n", __func__);
1528 goto dettach_frontend;
1530 /* we need to open the i2c gate (we know it exists) */
1531 fe = fe0->dvb.frontend;
1532 fe->ops.i2c_gate_ctrl(fe, 1);
1533 if (dvb_attach(isl6405_attach, fe,
1534 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1535 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1536 "found !\n", __func__);
1537 goto dettach_frontend;
1539 fe->ops.i2c_gate_ctrl(fe, 0);
1540 dev->original_set_voltage = fe->ops.set_voltage;
1541 fe->ops.set_voltage = md8800_set_voltage;
1542 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1543 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1546 case SAA7134_BOARD_AVERMEDIA_M103:
1547 saa7134_set_gpio(dev, 25, 0);
1549 saa7134_set_gpio(dev, 25, 1);
1550 fe0->dvb.frontend = dvb_attach(mt352_attach,
1551 &avermedia_xc3028_mt352_dev,
1555 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1556 if (!use_frontend) { /* terrestrial */
1557 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1558 &tda827x_cfg_2) < 0)
1559 goto dettach_frontend;
1560 } else { /* satellite */
1561 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1562 &flydvbs, &dev->i2c_adap);
1563 if (fe0->dvb.frontend) {
1564 if (dvb_attach(tda826x_attach,
1565 fe0->dvb.frontend, 0x60,
1566 &dev->i2c_adap, 0) == NULL) {
1567 wprintk("%s: Asus Tiger 3in1, no "
1568 "tda826x found!\n", __func__);
1569 goto dettach_frontend;
1571 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1572 &dev->i2c_adap, 0, 0) == NULL) {
1573 wprintk("%s: Asus Tiger 3in1, no lnbp21"
1574 " found!\n", __func__);
1575 goto dettach_frontend;
1580 case SAA7134_BOARD_ASUSTeK_TIGER:
1581 if (configure_tda827x_fe(dev, &philips_tiger_config,
1582 &tda827x_cfg_0) < 0)
1583 goto dettach_frontend;
1585 case SAA7134_BOARD_BEHOLD_H6:
1586 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1589 if (fe0->dvb.frontend) {
1590 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1591 &dev->i2c_adap, 0x61,
1592 TUNER_PHILIPS_FMD1216MEX_MK3);
1595 case SAA7134_BOARD_BEHOLD_X7:
1596 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1599 if (fe0->dvb.frontend) {
1600 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1601 &dev->i2c_adap, &behold_x7_tunerconfig);
1604 case SAA7134_BOARD_BEHOLD_H7:
1605 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1608 if (fe0->dvb.frontend) {
1609 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1610 &dev->i2c_adap, &behold_x7_tunerconfig);
1613 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
1614 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
1615 /* Zarlink ZL10313 */
1616 fe0->dvb.frontend = dvb_attach(mt312_attach,
1617 &avertv_a700_mt312, &dev->i2c_adap);
1618 if (fe0->dvb.frontend) {
1619 if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
1620 &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
1621 wprintk("%s: No zl10036 found!\n",
1626 case SAA7134_BOARD_VIDEOMATE_S350:
1627 fe0->dvb.frontend = dvb_attach(mt312_attach,
1628 &zl10313_compro_s350_config, &dev->i2c_adap);
1629 if (fe0->dvb.frontend)
1630 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1631 0x60, &dev->i2c_adap) == NULL)
1632 wprintk("%s: No zl10039 found!\n",
1636 case SAA7134_BOARD_ZOLID_HYBRID_PCI:
1637 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1638 &zolid_tda10048_config,
1640 if (fe0->dvb.frontend != NULL) {
1641 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1642 &dev->i2c_adap, 0x4b,
1644 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1645 0x60, &dev->i2c_adap,
1646 &zolid_tda18271_config);
1649 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
1650 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1651 &dtv1000s_tda10048_config,
1653 if (fe0->dvb.frontend != NULL) {
1654 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1655 &dev->i2c_adap, 0x4b,
1657 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1658 0x60, &dev->i2c_adap,
1659 &dtv1000s_tda18271_config);
1662 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
1663 __kworld_sbtvd_i2c_gate_ctrl(dev, 0);
1664 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x14000);
1665 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x14000);
1667 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x54000);
1668 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x54000);
1670 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1671 &kworld_mb86a20s_config,
1673 __kworld_sbtvd_i2c_gate_ctrl(dev, 1);
1674 if (fe0->dvb.frontend != NULL) {
1675 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1676 0x60, &dev->i2c_adap,
1677 &kworld_tda18271_config);
1679 * Only after success, it can initialize the gate, otherwise
1680 * an OOPS will hit, due to kfree(fe0->dvb.frontend)
1682 fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_i2c_gate_ctrl;
1686 wprintk("Huh? unknown DVB card?\n");
1690 if (attach_xc3028) {
1691 struct dvb_frontend *fe;
1692 struct xc2028_config cfg = {
1693 .i2c_adap = &dev->i2c_adap,
1697 if (!fe0->dvb.frontend)
1698 goto dettach_frontend;
1700 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
1702 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1704 goto dettach_frontend;
1708 if (NULL == fe0->dvb.frontend) {
1709 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1710 goto dettach_frontend;
1712 /* define general-purpose callback pointer */
1713 fe0->dvb.frontend->callback = saa7134_tuner_callback;
1715 /* register everything else */
1716 ret = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
1717 &dev->pci->dev, adapter_nr, 0, NULL);
1719 /* this sequence is necessary to make the tda1004x load its firmware
1720 * and to enter analog mode of hybrid boards
1723 if (fe0->dvb.frontend->ops.init)
1724 fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
1725 if (fe0->dvb.frontend->ops.sleep)
1726 fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
1727 if (fe0->dvb.frontend->ops.tuner_ops.sleep)
1728 fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
1733 videobuf_dvb_dealloc_frontends(&dev->frontends);
1737 static int dvb_fini(struct saa7134_dev *dev)
1739 struct videobuf_dvb_frontend *fe0;
1741 /* Get the first frontend */
1742 fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
1746 /* FIXME: I suspect that this code is bogus, since the entry for
1747 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1748 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1750 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1751 struct v4l2_priv_tun_config tda9887_cfg;
1752 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1754 tda9887_cfg.tuner = TUNER_TDA9887;
1755 tda9887_cfg.priv = &on;
1757 /* otherwise we don't detect the tuner on next insmod */
1758 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1759 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1760 if ((dev->eedata[2] == 0x07) && use_frontend) {
1761 /* turn off the 2nd lnb supply */
1763 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1764 struct dvb_frontend *fe;
1765 fe = fe0->dvb.frontend;
1766 if (fe->ops.i2c_gate_ctrl) {
1767 fe->ops.i2c_gate_ctrl(fe, 1);
1768 i2c_transfer(&dev->i2c_adap, &msg, 1);
1769 fe->ops.i2c_gate_ctrl(fe, 0);
1773 videobuf_dvb_unregister_bus(&dev->frontends);
1777 static struct saa7134_mpeg_ops dvb_ops = {
1778 .type = SAA7134_MPEG_DVB,
1783 static int __init dvb_register(void)
1785 return saa7134_ts_register(&dvb_ops);
1788 static void __exit dvb_unregister(void)
1790 saa7134_ts_unregister(&dvb_ops);
1793 module_init(dvb_register);
1794 module_exit(dvb_unregister);
1796 /* ------------------------------------------------------------------ */