3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * Extended 3 / 2005 by Hartmut Hackmann to support various
6 * cards with the tda10046 DVB-T channel decoder
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
29 #include <linux/kthread.h>
30 #include <linux/suspend.h>
32 #include "saa7134-reg.h"
34 #include <media/v4l2-common.h>
38 #include "mt352_priv.h" /* FIXME */
49 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
50 MODULE_LICENSE("GPL");
52 static unsigned int antenna_pwr;
54 module_param(antenna_pwr, int, 0444);
55 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
57 static int use_frontend;
58 module_param(use_frontend, int, 0644);
59 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
62 module_param(debug, int, 0644);
63 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
65 #define dprintk(fmt, arg...) do { if (debug) \
66 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
69 #define wprintk(fmt, arg...) \
70 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
72 /* ------------------------------------------------------------------
73 * mt352 based DVB-T cards
76 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
81 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
82 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
86 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
87 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
90 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
91 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
93 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
95 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
96 dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off");
99 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
103 static int mt352_pinnacle_init(struct dvb_frontend* fe)
105 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
106 static u8 reset [] = { RESET, 0x80 };
107 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
108 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
109 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
110 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
111 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
112 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
113 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
114 struct saa7134_dev *dev= fe->dvb->priv;
116 dprintk("%s called\n", __FUNCTION__);
118 mt352_write(fe, clock_config, sizeof(clock_config));
120 mt352_write(fe, reset, sizeof(reset));
121 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
122 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
123 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
124 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
126 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
127 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
128 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
133 static int mt352_aver777_init(struct dvb_frontend* fe)
135 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
136 static u8 reset [] = { RESET, 0x80 };
137 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
138 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
139 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
141 mt352_write(fe, clock_config, sizeof(clock_config));
143 mt352_write(fe, reset, sizeof(reset));
144 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
145 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
146 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
151 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
152 struct dvb_frontend_parameters* params)
154 u8 off[] = { 0x00, 0xf1};
155 u8 on[] = { 0x00, 0x71};
156 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
158 struct saa7134_dev *dev = fe->dvb->priv;
159 struct v4l2_frequency f;
161 /* set frequency (mt2050) */
163 f.type = V4L2_TUNER_DIGITAL_TV;
164 f.frequency = params->frequency / 1000 * 16 / 1000;
165 if (fe->ops.i2c_gate_ctrl)
166 fe->ops.i2c_gate_ctrl(fe, 1);
167 i2c_transfer(&dev->i2c_adap, &msg, 1);
168 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
170 if (fe->ops.i2c_gate_ctrl)
171 fe->ops.i2c_gate_ctrl(fe, 1);
172 i2c_transfer(&dev->i2c_adap, &msg, 1);
174 pinnacle_antenna_pwr(dev, antenna_pwr);
177 return mt352_pinnacle_init(fe);
180 static struct mt352_config pinnacle_300i = {
181 .demod_address = 0x3c >> 1,
185 .demod_init = mt352_pinnacle_init,
188 static struct mt352_config avermedia_777 = {
189 .demod_address = 0xf,
190 .demod_init = mt352_aver777_init,
193 /* ==================================================================
194 * tda1004x based DVB-T cards, helper functions
197 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
198 const struct firmware **fw, char *name)
200 struct saa7134_dev *dev = fe->dvb->priv;
201 return request_firmware(fw, name, &dev->pci->dev);
204 /* ------------------------------------------------------------------
205 * these tuners are tu1216, td1316(a)
208 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
210 struct saa7134_dev *dev = fe->dvb->priv;
211 struct tda1004x_state *state = fe->demodulator_priv;
212 u8 addr = state->config->tuner_address;
214 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
216 int tuner_frequency = 0;
219 /* determine charge pump */
220 tuner_frequency = params->frequency + 36166000;
221 if (tuner_frequency < 87000000)
223 else if (tuner_frequency < 130000000)
225 else if (tuner_frequency < 160000000)
227 else if (tuner_frequency < 200000000)
229 else if (tuner_frequency < 290000000)
231 else if (tuner_frequency < 420000000)
233 else if (tuner_frequency < 480000000)
235 else if (tuner_frequency < 620000000)
237 else if (tuner_frequency < 830000000)
239 else if (tuner_frequency < 895000000)
245 if (params->frequency < 49000000)
247 else if (params->frequency < 161000000)
249 else if (params->frequency < 444000000)
251 else if (params->frequency < 861000000)
256 /* setup PLL filter */
257 switch (params->u.ofdm.bandwidth) {
258 case BANDWIDTH_6_MHZ:
262 case BANDWIDTH_7_MHZ:
266 case BANDWIDTH_8_MHZ:
275 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
277 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
279 /* setup tuner buffer */
280 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
281 tuner_buf[1] = tuner_frequency & 0xff;
283 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
285 if (fe->ops.i2c_gate_ctrl)
286 fe->ops.i2c_gate_ctrl(fe, 1);
287 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
288 wprintk("could not write to tuner at addr: 0x%02x\n",
296 static int philips_tu1216_init(struct dvb_frontend *fe)
298 struct saa7134_dev *dev = fe->dvb->priv;
299 struct tda1004x_state *state = fe->demodulator_priv;
300 u8 addr = state->config->tuner_address;
301 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
302 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
304 /* setup PLL configuration */
305 if (fe->ops.i2c_gate_ctrl)
306 fe->ops.i2c_gate_ctrl(fe, 1);
307 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
314 /* ------------------------------------------------------------------ */
316 static struct tda1004x_config philips_tu1216_60_config = {
317 .demod_address = 0x8,
320 .xtal_freq = TDA10046_XTAL_4M,
321 .agc_config = TDA10046_AGC_DEFAULT,
322 .if_freq = TDA10046_FREQ_3617,
323 .tuner_address = 0x60,
324 .request_firmware = philips_tda1004x_request_firmware
327 static struct tda1004x_config philips_tu1216_61_config = {
329 .demod_address = 0x8,
332 .xtal_freq = TDA10046_XTAL_4M,
333 .agc_config = TDA10046_AGC_DEFAULT,
334 .if_freq = TDA10046_FREQ_3617,
335 .tuner_address = 0x61,
336 .request_firmware = philips_tda1004x_request_firmware
339 /* ------------------------------------------------------------------ */
341 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
343 struct saa7134_dev *dev = fe->dvb->priv;
344 struct tda1004x_state *state = fe->demodulator_priv;
345 u8 addr = state->config->tuner_address;
346 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
347 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
349 /* setup PLL configuration */
350 if (fe->ops.i2c_gate_ctrl)
351 fe->ops.i2c_gate_ctrl(fe, 1);
352 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
357 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
359 return philips_tda6651_pll_set(fe, params);
362 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
364 struct saa7134_dev *dev = fe->dvb->priv;
365 struct tda1004x_state *state = fe->demodulator_priv;
366 u8 addr = state->config->tuner_address;
367 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
368 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
370 /* switch the tuner to analog mode */
371 if (fe->ops.i2c_gate_ctrl)
372 fe->ops.i2c_gate_ctrl(fe, 1);
373 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
378 /* ------------------------------------------------------------------ */
380 static int philips_europa_tuner_init(struct dvb_frontend *fe)
382 struct saa7134_dev *dev = fe->dvb->priv;
383 static u8 msg[] = { 0x00, 0x40};
384 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
387 if (philips_td1316_tuner_init(fe))
390 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
396 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
398 struct saa7134_dev *dev = fe->dvb->priv;
400 static u8 msg[] = { 0x00, 0x14 };
401 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
403 if (philips_td1316_tuner_sleep(fe))
406 /* switch the board to analog mode */
407 if (fe->ops.i2c_gate_ctrl)
408 fe->ops.i2c_gate_ctrl(fe, 1);
409 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
413 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
415 struct saa7134_dev *dev = fe->dvb->priv;
417 if (dev->original_demod_sleep)
418 dev->original_demod_sleep(fe);
419 fe->ops.i2c_gate_ctrl(fe, 1);
423 static struct tda1004x_config philips_europa_config = {
425 .demod_address = 0x8,
428 .xtal_freq = TDA10046_XTAL_4M,
429 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
430 .if_freq = TDA10046_FREQ_052,
431 .tuner_address = 0x61,
432 .request_firmware = philips_tda1004x_request_firmware
435 /* ------------------------------------------------------------------ */
437 static struct tda1004x_config medion_cardbus = {
438 .demod_address = 0x08,
441 .xtal_freq = TDA10046_XTAL_16M,
442 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
443 .if_freq = TDA10046_FREQ_3613,
444 .tuner_address = 0x61,
445 .request_firmware = philips_tda1004x_request_firmware
448 /* ------------------------------------------------------------------
449 * tda 1004x based cards with philips silicon tuner
452 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
454 struct saa7134_dev *dev = fe->dvb->priv;
455 struct tda1004x_state *state = fe->demodulator_priv;
456 u8 addr = state->config->i2c_gate;
457 u8 config = state->config->tuner_config;
458 u8 GP00_CF[] = {0x20, 0x01};
459 u8 GP00_LEV[] = {0x22, 0x00};
461 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
464 dprintk("setting LNA to high gain\n");
466 dprintk("setting LNA to low gain\n");
472 case 1: /* switch is GPIO 0 of tda8290 */
475 saa7134_set_gpio(dev, 22, 0);
476 GP00_LEV[1] = high ? 0 : 1;
477 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
478 wprintk("could not access tda8290 at addr: 0x%02x\n",
484 GP00_LEV[1] = high ? 1 : 0;
485 i2c_transfer(&dev->i2c_adap, &msg, 1);
487 case 3: /* switch with GPIO of saa713x */
488 saa7134_set_gpio(dev, 22, high);
493 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
495 struct tda1004x_state *state = fe->demodulator_priv;
497 u8 addr = state->config->i2c_gate;
498 static u8 tda8290_close[] = { 0x21, 0xc0};
499 static u8 tda8290_open[] = { 0x21, 0x80};
500 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
502 tda8290_msg.buf = tda8290_close;
504 tda8290_msg.buf = tda8290_open;
506 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
507 struct saa7134_dev *dev = fe->dvb->priv;
508 wprintk("could not access tda8290 I2C gate\n");
515 /* ------------------------------------------------------------------ */
517 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
519 struct saa7134_dev *dev = fe->dvb->priv;
520 struct tda1004x_state *state = fe->demodulator_priv;
522 switch (state->config->antenna_switch) {
524 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
525 saa7134_set_gpio(dev, 21, 0);
527 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
528 saa7134_set_gpio(dev, 21, 1);
534 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
536 struct saa7134_dev *dev = fe->dvb->priv;
537 struct tda1004x_state *state = fe->demodulator_priv;
539 switch (state->config->antenna_switch) {
541 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
542 saa7134_set_gpio(dev, 21, 1);
544 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
545 saa7134_set_gpio(dev, 21, 0);
551 static struct tda827x_config tda827x_cfg = {
552 .lna_gain = philips_tda827x_lna_gain,
553 .init = philips_tda827x_tuner_init,
554 .sleep = philips_tda827x_tuner_sleep
557 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
559 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
560 if (dev->dvb.frontend) {
561 if (tda_conf->i2c_gate)
562 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
563 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
564 &dev->i2c_adap,&tda827x_cfg) == NULL) {
565 wprintk("no tda827x tuner found at addr: %02x\n",
566 tda_conf->tuner_address);
571 /* ------------------------------------------------------------------ */
573 static struct tda1004x_config tda827x_lifeview_config = {
574 .demod_address = 0x08,
577 .xtal_freq = TDA10046_XTAL_16M,
578 .agc_config = TDA10046_AGC_TDA827X,
579 .gpio_config = TDA10046_GP11_I,
580 .if_freq = TDA10046_FREQ_045,
581 .tuner_address = 0x60,
582 .request_firmware = philips_tda1004x_request_firmware
585 static struct tda1004x_config philips_tiger_config = {
586 .demod_address = 0x08,
589 .xtal_freq = TDA10046_XTAL_16M,
590 .agc_config = TDA10046_AGC_TDA827X,
591 .gpio_config = TDA10046_GP11_I,
592 .if_freq = TDA10046_FREQ_045,
594 .tuner_address = 0x61,
597 .request_firmware = philips_tda1004x_request_firmware
600 static struct tda1004x_config cinergy_ht_config = {
601 .demod_address = 0x08,
604 .xtal_freq = TDA10046_XTAL_16M,
605 .agc_config = TDA10046_AGC_TDA827X,
606 .gpio_config = TDA10046_GP01_I,
607 .if_freq = TDA10046_FREQ_045,
609 .tuner_address = 0x61,
611 .request_firmware = philips_tda1004x_request_firmware
614 static struct tda1004x_config cinergy_ht_pci_config = {
615 .demod_address = 0x08,
618 .xtal_freq = TDA10046_XTAL_16M,
619 .agc_config = TDA10046_AGC_TDA827X,
620 .gpio_config = TDA10046_GP01_I,
621 .if_freq = TDA10046_FREQ_045,
623 .tuner_address = 0x60,
625 .request_firmware = philips_tda1004x_request_firmware
628 static struct tda1004x_config philips_tiger_s_config = {
629 .demod_address = 0x08,
632 .xtal_freq = TDA10046_XTAL_16M,
633 .agc_config = TDA10046_AGC_TDA827X,
634 .gpio_config = TDA10046_GP01_I,
635 .if_freq = TDA10046_FREQ_045,
637 .tuner_address = 0x61,
640 .request_firmware = philips_tda1004x_request_firmware
643 static struct tda1004x_config pinnacle_pctv_310i_config = {
644 .demod_address = 0x08,
647 .xtal_freq = TDA10046_XTAL_16M,
648 .agc_config = TDA10046_AGC_TDA827X,
649 .gpio_config = TDA10046_GP11_I,
650 .if_freq = TDA10046_FREQ_045,
652 .tuner_address = 0x61,
654 .request_firmware = philips_tda1004x_request_firmware
657 static struct tda1004x_config hauppauge_hvr_1110_config = {
658 .demod_address = 0x08,
661 .xtal_freq = TDA10046_XTAL_16M,
662 .agc_config = TDA10046_AGC_TDA827X,
663 .gpio_config = TDA10046_GP11_I,
664 .if_freq = TDA10046_FREQ_045,
666 .tuner_address = 0x61,
668 .request_firmware = philips_tda1004x_request_firmware
671 static struct tda1004x_config asus_p7131_dual_config = {
672 .demod_address = 0x08,
675 .xtal_freq = TDA10046_XTAL_16M,
676 .agc_config = TDA10046_AGC_TDA827X,
677 .gpio_config = TDA10046_GP11_I,
678 .if_freq = TDA10046_FREQ_045,
680 .tuner_address = 0x61,
683 .request_firmware = philips_tda1004x_request_firmware
686 static struct tda1004x_config lifeview_trio_config = {
687 .demod_address = 0x09,
690 .xtal_freq = TDA10046_XTAL_16M,
691 .agc_config = TDA10046_AGC_TDA827X,
692 .gpio_config = TDA10046_GP00_I,
693 .if_freq = TDA10046_FREQ_045,
694 .tuner_address = 0x60,
695 .request_firmware = philips_tda1004x_request_firmware
698 static struct tda1004x_config tevion_dvbt220rf_config = {
699 .demod_address = 0x08,
702 .xtal_freq = TDA10046_XTAL_16M,
703 .agc_config = TDA10046_AGC_TDA827X,
704 .gpio_config = TDA10046_GP11_I,
705 .if_freq = TDA10046_FREQ_045,
706 .tuner_address = 0x60,
707 .request_firmware = philips_tda1004x_request_firmware
710 static struct tda1004x_config md8800_dvbt_config = {
711 .demod_address = 0x08,
714 .xtal_freq = TDA10046_XTAL_16M,
715 .agc_config = TDA10046_AGC_TDA827X,
716 .gpio_config = TDA10046_GP01_I,
717 .if_freq = TDA10046_FREQ_045,
719 .tuner_address = 0x60,
721 .request_firmware = philips_tda1004x_request_firmware
724 static struct tda1004x_config asus_p7131_4871_config = {
725 .demod_address = 0x08,
728 .xtal_freq = TDA10046_XTAL_16M,
729 .agc_config = TDA10046_AGC_TDA827X,
730 .gpio_config = TDA10046_GP01_I,
731 .if_freq = TDA10046_FREQ_045,
733 .tuner_address = 0x61,
736 .request_firmware = philips_tda1004x_request_firmware
739 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
740 .demod_address = 0x08,
743 .xtal_freq = TDA10046_XTAL_16M,
744 .agc_config = TDA10046_AGC_TDA827X,
745 .gpio_config = TDA10046_GP11_I,
746 .if_freq = TDA10046_FREQ_045,
748 .tuner_address = 0x61,
751 .request_firmware = philips_tda1004x_request_firmware
754 static struct tda1004x_config kworld_dvb_t_210_config = {
755 .demod_address = 0x08,
758 .xtal_freq = TDA10046_XTAL_16M,
759 .agc_config = TDA10046_AGC_TDA827X,
760 .gpio_config = TDA10046_GP11_I,
761 .if_freq = TDA10046_FREQ_045,
763 .tuner_address = 0x61,
766 .request_firmware = philips_tda1004x_request_firmware
769 static struct tda1004x_config avermedia_super_007_config = {
770 .demod_address = 0x08,
773 .xtal_freq = TDA10046_XTAL_16M,
774 .agc_config = TDA10046_AGC_TDA827X,
775 .gpio_config = TDA10046_GP01_I,
776 .if_freq = TDA10046_FREQ_045,
778 .tuner_address = 0x60,
781 .request_firmware = philips_tda1004x_request_firmware
784 static struct tda1004x_config twinhan_dtv_dvb_3056_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,
796 .request_firmware = philips_tda1004x_request_firmware
799 /* ------------------------------------------------------------------
800 * special case: this card uses saa713x GPIO22 for the mode switch
803 static int ads_duo_tuner_init(struct dvb_frontend *fe)
805 struct saa7134_dev *dev = fe->dvb->priv;
806 philips_tda827x_tuner_init(fe);
807 /* route TDA8275a AGC input to the channel decoder */
808 saa7134_set_gpio(dev, 22, 1);
812 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
814 struct saa7134_dev *dev = fe->dvb->priv;
815 /* route TDA8275a AGC input to the analog IF chip*/
816 saa7134_set_gpio(dev, 22, 0);
817 philips_tda827x_tuner_sleep(fe);
821 static struct tda827x_config ads_duo_cfg = {
822 .lna_gain = philips_tda827x_lna_gain,
823 .init = ads_duo_tuner_init,
824 .sleep = ads_duo_tuner_sleep
827 static struct tda1004x_config ads_tech_duo_config = {
828 .demod_address = 0x08,
831 .xtal_freq = TDA10046_XTAL_16M,
832 .agc_config = TDA10046_AGC_TDA827X,
833 .gpio_config = TDA10046_GP00_I,
834 .if_freq = TDA10046_FREQ_045,
835 .tuner_address = 0x61,
836 .request_firmware = philips_tda1004x_request_firmware
839 /* ==================================================================
840 * tda10086 based DVB-S cards, helper functions
843 static struct tda10086_config flydvbs = {
844 .demod_address = 0x0e,
849 /* ------------------------------------------------------------------
850 * special case: lnb supply is connected to the gated i2c
853 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
856 struct saa7134_dev *dev = fe->dvb->priv;
857 if (fe->ops.i2c_gate_ctrl) {
858 fe->ops.i2c_gate_ctrl(fe, 1);
859 if (dev->original_set_voltage)
860 res = dev->original_set_voltage(fe, voltage);
861 fe->ops.i2c_gate_ctrl(fe, 0);
866 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
869 struct saa7134_dev *dev = fe->dvb->priv;
870 if (fe->ops.i2c_gate_ctrl) {
871 fe->ops.i2c_gate_ctrl(fe, 1);
872 if (dev->original_set_high_voltage)
873 res = dev->original_set_high_voltage(fe, arg);
874 fe->ops.i2c_gate_ctrl(fe, 0);
879 /* ==================================================================
880 * nxt200x based ATSC cards, helper functions
883 static struct nxt200x_config avertvhda180 = {
884 .demod_address = 0x0a,
887 static struct nxt200x_config kworldatsc110 = {
888 .demod_address = 0x0a,
891 /* ==================================================================
895 static int dvb_init(struct saa7134_dev *dev)
898 /* init struct videobuf_dvb */
899 dev->ts.nr_bufs = 32;
900 dev->ts.nr_packets = 32*4;
901 dev->dvb.name = dev->name;
902 videobuf_queue_pci_init(&dev->dvb.dvbq, &saa7134_ts_qops,
903 dev->pci, &dev->slock,
904 V4L2_BUF_TYPE_VIDEO_CAPTURE,
905 V4L2_FIELD_ALTERNATE,
906 sizeof(struct saa7134_buf),
909 switch (dev->board) {
910 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
911 dprintk("pinnacle 300i dvb setup\n");
912 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
914 if (dev->dvb.frontend) {
915 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
918 case SAA7134_BOARD_AVERMEDIA_777:
919 case SAA7134_BOARD_AVERMEDIA_A16AR:
920 dprintk("avertv 777 dvb setup\n");
921 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
923 if (dev->dvb.frontend) {
924 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
925 NULL, DVB_PLL_PHILIPS_TD1316);
928 case SAA7134_BOARD_MD7134:
929 dev->dvb.frontend = dvb_attach(tda10046_attach,
932 if (dev->dvb.frontend) {
933 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
934 &dev->i2c_adap, DVB_PLL_FMD1216ME);
937 case SAA7134_BOARD_PHILIPS_TOUGH:
938 dev->dvb.frontend = dvb_attach(tda10046_attach,
939 &philips_tu1216_60_config,
941 if (dev->dvb.frontend) {
942 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
943 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
946 case SAA7134_BOARD_FLYDVBTDUO:
947 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
948 configure_tda827x_fe(dev, &tda827x_lifeview_config);
950 case SAA7134_BOARD_PHILIPS_EUROPA:
951 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
952 dev->dvb.frontend = dvb_attach(tda10046_attach,
953 &philips_europa_config,
955 if (dev->dvb.frontend) {
956 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
957 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
958 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
959 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
960 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
963 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
964 dev->dvb.frontend = dvb_attach(tda10046_attach,
965 &philips_tu1216_61_config,
967 if (dev->dvb.frontend) {
968 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
969 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
972 case SAA7134_BOARD_KWORLD_DVBT_210:
973 configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
975 case SAA7134_BOARD_PHILIPS_TIGER:
976 configure_tda827x_fe(dev, &philips_tiger_config);
978 case SAA7134_BOARD_PINNACLE_PCTV_310i:
979 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
981 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
982 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
984 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
985 configure_tda827x_fe(dev, &asus_p7131_dual_config);
987 case SAA7134_BOARD_FLYDVBT_LR301:
988 configure_tda827x_fe(dev, &tda827x_lifeview_config);
990 case SAA7134_BOARD_FLYDVB_TRIO:
991 if(! use_frontend) { /* terrestrial */
992 configure_tda827x_fe(dev, &lifeview_trio_config);
993 } else { /* satellite */
994 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
995 if (dev->dvb.frontend) {
996 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
997 &dev->i2c_adap, 0) == NULL) {
998 wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1000 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1001 0x08, 0, 0) == NULL) {
1002 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1007 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1008 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1009 dev->dvb.frontend = dvb_attach(tda10046_attach,
1010 &ads_tech_duo_config,
1012 if (dev->dvb.frontend) {
1013 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1014 ads_tech_duo_config.tuner_address,
1015 &dev->i2c_adap,&ads_duo_cfg) == NULL) {
1016 wprintk("no tda827x tuner found at addr: %02x\n",
1017 ads_tech_duo_config.tuner_address);
1021 case SAA7134_BOARD_TEVION_DVBT_220RF:
1022 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1024 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1025 if (!use_frontend) { /* terrestrial */
1026 configure_tda827x_fe(dev, &md8800_dvbt_config);
1027 } else { /* satellite */
1028 dev->dvb.frontend = dvb_attach(tda10086_attach,
1029 &flydvbs, &dev->i2c_adap);
1030 if (dev->dvb.frontend) {
1031 struct dvb_frontend *fe;
1032 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1033 0x60, &dev->i2c_adap, 0) == NULL)
1034 wprintk("%s: Medion Quadro, no tda826x "
1035 "found !\n", __FUNCTION__);
1037 * up to here. configuration for ctx948 and and one branch
1038 * of md8800 should be identical
1040 /* we need to open the i2c gate (we know it exists) */
1041 fe = dev->dvb.frontend;
1042 fe->ops.i2c_gate_ctrl(fe, 1);
1043 if (dvb_attach(isl6405_attach, fe,
1044 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1045 wprintk("%s: Medion Quadro, no ISL6405 "
1046 "found !\n", __FUNCTION__);
1047 fe->ops.i2c_gate_ctrl(fe, 0);
1048 dev->original_set_voltage = fe->ops.set_voltage;
1049 fe->ops.set_voltage = md8800_set_voltage;
1050 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1051 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1055 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1056 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1058 if (dev->dvb.frontend) {
1059 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1060 NULL, DVB_PLL_TDHU2);
1063 case SAA7134_BOARD_KWORLD_ATSC110:
1064 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1066 if (dev->dvb.frontend) {
1067 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1068 NULL, DVB_PLL_TUV1236D);
1071 case SAA7134_BOARD_FLYDVBS_LR300:
1072 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1074 if (dev->dvb.frontend) {
1075 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1076 &dev->i2c_adap, 0) == NULL) {
1077 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1079 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1080 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1081 wprintk("%s: No ISL6421 found!\n", __FUNCTION__);
1085 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1086 dev->dvb.frontend = dvb_attach(tda10046_attach,
1089 if (dev->dvb.frontend) {
1090 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1091 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1093 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
1094 &dev->i2c_adap, DVB_PLL_FMD1216ME);
1097 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1098 dev->dvb.frontend = dvb_attach(tda10046_attach,
1099 &philips_europa_config,
1101 if (dev->dvb.frontend) {
1102 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1103 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1106 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1107 configure_tda827x_fe(dev, &cinergy_ht_config);
1109 case SAA7134_BOARD_CINERGY_HT_PCI:
1110 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1112 case SAA7134_BOARD_PHILIPS_TIGER_S:
1113 configure_tda827x_fe(dev, &philips_tiger_s_config);
1115 case SAA7134_BOARD_ASUS_P7131_4871:
1116 configure_tda827x_fe(dev, &asus_p7131_4871_config);
1118 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1119 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1121 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1122 configure_tda827x_fe(dev, &avermedia_super_007_config);
1124 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1125 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config);
1127 case SAA7134_BOARD_PHILIPS_SNAKE:
1128 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1130 if (dev->dvb.frontend) {
1131 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1132 &dev->i2c_adap, 0) == NULL)
1133 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1134 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1135 &dev->i2c_adap, 0, 0) == NULL)
1136 wprintk("%s: No lnbp21 found!\n", __FUNCTION__);
1139 case SAA7134_BOARD_CREATIX_CTX953:
1140 configure_tda827x_fe(dev, &md8800_dvbt_config);
1143 wprintk("Huh? unknown DVB card?\n");
1147 if (NULL == dev->dvb.frontend) {
1148 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1152 /* register everything else */
1153 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1155 /* this sequence is necessary to make the tda1004x load its firmware
1156 * and to enter analog mode of hybrid boards
1159 if (dev->dvb.frontend->ops.init)
1160 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1161 if (dev->dvb.frontend->ops.sleep)
1162 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1163 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1164 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1169 static int dvb_fini(struct saa7134_dev *dev)
1171 /* FIXME: I suspect that this code is bogus, since the entry for
1172 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1173 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1175 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1176 struct v4l2_priv_tun_config tda9887_cfg;
1177 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1179 tda9887_cfg.tuner = TUNER_TDA9887;
1180 tda9887_cfg.priv = &on;
1182 /* otherwise we don't detect the tuner on next insmod */
1183 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1186 videobuf_dvb_unregister(&dev->dvb);
1190 static struct saa7134_mpeg_ops dvb_ops = {
1191 .type = SAA7134_MPEG_DVB,
1196 static int __init dvb_register(void)
1198 return saa7134_ts_register(&dvb_ops);
1201 static void __exit dvb_unregister(void)
1203 saa7134_ts_unregister(&dvb_ops);
1206 module_init(dvb_register);
1207 module_exit(dvb_unregister);
1209 /* ------------------------------------------------------------------ */