3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * Extended 3 / 2005 by Hartmut Hackmann to support various
6 * cards with the tda10046 DVB-T channel decoder
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
29 #include <linux/kthread.h>
30 #include <linux/suspend.h>
32 #include "saa7134-reg.h"
34 #include <media/v4l2-common.h>
36 #include <dvb_frontend.h>
39 #include "mt352_priv.h" /* FIXME */
42 #include "tuner-xc2028.h"
51 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
52 MODULE_LICENSE("GPL");
54 static unsigned int antenna_pwr;
56 module_param(antenna_pwr, int, 0444);
57 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
59 static int use_frontend;
60 module_param(use_frontend, int, 0644);
61 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
64 module_param(debug, int, 0644);
65 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
67 #define dprintk(fmt, arg...) do { if (debug) \
68 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
71 #define wprintk(fmt, arg...) \
72 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
74 /* ------------------------------------------------------------------
75 * mt352 based DVB-T cards
78 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
83 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
84 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
88 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
89 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
92 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
93 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
95 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
97 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
98 dprintk("%s %s\n", __func__, ok ? "on" : "off");
101 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
105 static int mt352_pinnacle_init(struct dvb_frontend* fe)
107 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
108 static u8 reset [] = { RESET, 0x80 };
109 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
110 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
111 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
112 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
113 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
114 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
115 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
116 struct saa7134_dev *dev= fe->dvb->priv;
118 dprintk("%s called\n", __func__);
120 mt352_write(fe, clock_config, sizeof(clock_config));
122 mt352_write(fe, reset, sizeof(reset));
123 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
124 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
125 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
126 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
128 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
129 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
130 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
135 static int mt352_aver777_init(struct dvb_frontend* fe)
137 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
138 static u8 reset [] = { RESET, 0x80 };
139 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
140 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
141 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
143 mt352_write(fe, clock_config, sizeof(clock_config));
145 mt352_write(fe, reset, sizeof(reset));
146 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
147 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
148 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
153 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
154 struct dvb_frontend_parameters* params)
156 u8 off[] = { 0x00, 0xf1};
157 u8 on[] = { 0x00, 0x71};
158 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
160 struct saa7134_dev *dev = fe->dvb->priv;
161 struct v4l2_frequency f;
163 /* set frequency (mt2050) */
165 f.type = V4L2_TUNER_DIGITAL_TV;
166 f.frequency = params->frequency / 1000 * 16 / 1000;
167 if (fe->ops.i2c_gate_ctrl)
168 fe->ops.i2c_gate_ctrl(fe, 1);
169 i2c_transfer(&dev->i2c_adap, &msg, 1);
170 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
172 if (fe->ops.i2c_gate_ctrl)
173 fe->ops.i2c_gate_ctrl(fe, 1);
174 i2c_transfer(&dev->i2c_adap, &msg, 1);
176 pinnacle_antenna_pwr(dev, antenna_pwr);
179 return mt352_pinnacle_init(fe);
182 static struct mt352_config pinnacle_300i = {
183 .demod_address = 0x3c >> 1,
187 .demod_init = mt352_pinnacle_init,
190 static struct mt352_config avermedia_777 = {
191 .demod_address = 0xf,
192 .demod_init = mt352_aver777_init,
195 static struct mt352_config avermedia_e506r_mt352_dev = {
196 .demod_address = (0x1e >> 1),
200 /* ==================================================================
201 * tda1004x based DVB-T cards, helper functions
204 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
205 const struct firmware **fw, char *name)
207 struct saa7134_dev *dev = fe->dvb->priv;
208 return request_firmware(fw, name, &dev->pci->dev);
211 /* ------------------------------------------------------------------
212 * these tuners are tu1216, td1316(a)
215 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
217 struct saa7134_dev *dev = fe->dvb->priv;
218 struct tda1004x_state *state = fe->demodulator_priv;
219 u8 addr = state->config->tuner_address;
221 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
223 int tuner_frequency = 0;
226 /* determine charge pump */
227 tuner_frequency = params->frequency + 36166000;
228 if (tuner_frequency < 87000000)
230 else if (tuner_frequency < 130000000)
232 else if (tuner_frequency < 160000000)
234 else if (tuner_frequency < 200000000)
236 else if (tuner_frequency < 290000000)
238 else if (tuner_frequency < 420000000)
240 else if (tuner_frequency < 480000000)
242 else if (tuner_frequency < 620000000)
244 else if (tuner_frequency < 830000000)
246 else if (tuner_frequency < 895000000)
252 if (params->frequency < 49000000)
254 else if (params->frequency < 161000000)
256 else if (params->frequency < 444000000)
258 else if (params->frequency < 861000000)
263 /* setup PLL filter */
264 switch (params->u.ofdm.bandwidth) {
265 case BANDWIDTH_6_MHZ:
269 case BANDWIDTH_7_MHZ:
273 case BANDWIDTH_8_MHZ:
282 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
284 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
286 /* setup tuner buffer */
287 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
288 tuner_buf[1] = tuner_frequency & 0xff;
290 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
292 if (fe->ops.i2c_gate_ctrl)
293 fe->ops.i2c_gate_ctrl(fe, 1);
294 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
295 wprintk("could not write to tuner at addr: 0x%02x\n",
303 static int philips_tu1216_init(struct dvb_frontend *fe)
305 struct saa7134_dev *dev = fe->dvb->priv;
306 struct tda1004x_state *state = fe->demodulator_priv;
307 u8 addr = state->config->tuner_address;
308 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
309 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
311 /* setup PLL configuration */
312 if (fe->ops.i2c_gate_ctrl)
313 fe->ops.i2c_gate_ctrl(fe, 1);
314 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
321 /* ------------------------------------------------------------------ */
323 static struct tda1004x_config philips_tu1216_60_config = {
324 .demod_address = 0x8,
327 .xtal_freq = TDA10046_XTAL_4M,
328 .agc_config = TDA10046_AGC_DEFAULT,
329 .if_freq = TDA10046_FREQ_3617,
330 .tuner_address = 0x60,
331 .request_firmware = philips_tda1004x_request_firmware
334 static struct tda1004x_config philips_tu1216_61_config = {
336 .demod_address = 0x8,
339 .xtal_freq = TDA10046_XTAL_4M,
340 .agc_config = TDA10046_AGC_DEFAULT,
341 .if_freq = TDA10046_FREQ_3617,
342 .tuner_address = 0x61,
343 .request_firmware = philips_tda1004x_request_firmware
346 /* ------------------------------------------------------------------ */
348 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
350 struct saa7134_dev *dev = fe->dvb->priv;
351 struct tda1004x_state *state = fe->demodulator_priv;
352 u8 addr = state->config->tuner_address;
353 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
354 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
356 /* setup PLL configuration */
357 if (fe->ops.i2c_gate_ctrl)
358 fe->ops.i2c_gate_ctrl(fe, 1);
359 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
364 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
366 return philips_tda6651_pll_set(fe, params);
369 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
371 struct saa7134_dev *dev = fe->dvb->priv;
372 struct tda1004x_state *state = fe->demodulator_priv;
373 u8 addr = state->config->tuner_address;
374 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
375 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
377 /* switch the tuner to analog mode */
378 if (fe->ops.i2c_gate_ctrl)
379 fe->ops.i2c_gate_ctrl(fe, 1);
380 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
385 /* ------------------------------------------------------------------ */
387 static int philips_europa_tuner_init(struct dvb_frontend *fe)
389 struct saa7134_dev *dev = fe->dvb->priv;
390 static u8 msg[] = { 0x00, 0x40};
391 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
394 if (philips_td1316_tuner_init(fe))
397 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
403 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
405 struct saa7134_dev *dev = fe->dvb->priv;
407 static u8 msg[] = { 0x00, 0x14 };
408 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
410 if (philips_td1316_tuner_sleep(fe))
413 /* switch the board to analog mode */
414 if (fe->ops.i2c_gate_ctrl)
415 fe->ops.i2c_gate_ctrl(fe, 1);
416 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
420 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
422 struct saa7134_dev *dev = fe->dvb->priv;
424 if (dev->original_demod_sleep)
425 dev->original_demod_sleep(fe);
426 fe->ops.i2c_gate_ctrl(fe, 1);
430 static struct tda1004x_config philips_europa_config = {
432 .demod_address = 0x8,
435 .xtal_freq = TDA10046_XTAL_4M,
436 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
437 .if_freq = TDA10046_FREQ_052,
438 .tuner_address = 0x61,
439 .request_firmware = philips_tda1004x_request_firmware
442 /* ------------------------------------------------------------------ */
444 static struct tda1004x_config medion_cardbus = {
445 .demod_address = 0x08,
448 .xtal_freq = TDA10046_XTAL_16M,
449 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
450 .if_freq = TDA10046_FREQ_3613,
451 .tuner_address = 0x61,
452 .request_firmware = philips_tda1004x_request_firmware
455 /* ------------------------------------------------------------------
456 * tda 1004x based cards with philips silicon tuner
459 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
461 struct saa7134_dev *dev = fe->dvb->priv;
462 struct tda1004x_state *state = fe->demodulator_priv;
463 u8 addr = state->config->i2c_gate;
464 u8 config = state->config->tuner_config;
465 u8 GP00_CF[] = {0x20, 0x01};
466 u8 GP00_LEV[] = {0x22, 0x00};
468 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
471 dprintk("setting LNA to high gain\n");
473 dprintk("setting LNA to low gain\n");
479 case 1: /* switch is GPIO 0 of tda8290 */
482 saa7134_set_gpio(dev, 22, 0);
483 GP00_LEV[1] = high ? 0 : 1;
484 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
485 wprintk("could not access tda8290 at addr: 0x%02x\n",
491 GP00_LEV[1] = high ? 1 : 0;
492 i2c_transfer(&dev->i2c_adap, &msg, 1);
494 case 3: /* switch with GPIO of saa713x */
495 saa7134_set_gpio(dev, 22, high);
500 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
502 struct tda1004x_state *state = fe->demodulator_priv;
504 u8 addr = state->config->i2c_gate;
505 static u8 tda8290_close[] = { 0x21, 0xc0};
506 static u8 tda8290_open[] = { 0x21, 0x80};
507 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
509 tda8290_msg.buf = tda8290_close;
511 tda8290_msg.buf = tda8290_open;
513 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
514 struct saa7134_dev *dev = fe->dvb->priv;
515 wprintk("could not access tda8290 I2C gate\n");
522 /* ------------------------------------------------------------------ */
524 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
526 struct saa7134_dev *dev = fe->dvb->priv;
527 struct tda1004x_state *state = fe->demodulator_priv;
529 switch (state->config->antenna_switch) {
531 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
532 saa7134_set_gpio(dev, 21, 0);
534 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
535 saa7134_set_gpio(dev, 21, 1);
541 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
543 struct saa7134_dev *dev = fe->dvb->priv;
544 struct tda1004x_state *state = fe->demodulator_priv;
546 switch (state->config->antenna_switch) {
548 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
549 saa7134_set_gpio(dev, 21, 1);
551 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
552 saa7134_set_gpio(dev, 21, 0);
558 static struct tda827x_config tda827x_cfg = {
559 .lna_gain = philips_tda827x_lna_gain,
560 .init = philips_tda827x_tuner_init,
561 .sleep = philips_tda827x_tuner_sleep
564 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
566 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
567 if (dev->dvb.frontend) {
568 if (tda_conf->i2c_gate)
569 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
570 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
571 &dev->i2c_adap,&tda827x_cfg) == NULL) {
572 wprintk("no tda827x tuner found at addr: %02x\n",
573 tda_conf->tuner_address);
578 /* ------------------------------------------------------------------ */
580 static struct tda1004x_config tda827x_lifeview_config = {
581 .demod_address = 0x08,
584 .xtal_freq = TDA10046_XTAL_16M,
585 .agc_config = TDA10046_AGC_TDA827X,
586 .gpio_config = TDA10046_GP11_I,
587 .if_freq = TDA10046_FREQ_045,
588 .tuner_address = 0x60,
589 .request_firmware = philips_tda1004x_request_firmware
592 static struct tda1004x_config philips_tiger_config = {
593 .demod_address = 0x08,
596 .xtal_freq = TDA10046_XTAL_16M,
597 .agc_config = TDA10046_AGC_TDA827X,
598 .gpio_config = TDA10046_GP11_I,
599 .if_freq = TDA10046_FREQ_045,
601 .tuner_address = 0x61,
604 .request_firmware = philips_tda1004x_request_firmware
607 static struct tda1004x_config cinergy_ht_config = {
608 .demod_address = 0x08,
611 .xtal_freq = TDA10046_XTAL_16M,
612 .agc_config = TDA10046_AGC_TDA827X,
613 .gpio_config = TDA10046_GP01_I,
614 .if_freq = TDA10046_FREQ_045,
616 .tuner_address = 0x61,
618 .request_firmware = philips_tda1004x_request_firmware
621 static struct tda1004x_config cinergy_ht_pci_config = {
622 .demod_address = 0x08,
625 .xtal_freq = TDA10046_XTAL_16M,
626 .agc_config = TDA10046_AGC_TDA827X,
627 .gpio_config = TDA10046_GP01_I,
628 .if_freq = TDA10046_FREQ_045,
630 .tuner_address = 0x60,
632 .request_firmware = philips_tda1004x_request_firmware
635 static struct tda1004x_config philips_tiger_s_config = {
636 .demod_address = 0x08,
639 .xtal_freq = TDA10046_XTAL_16M,
640 .agc_config = TDA10046_AGC_TDA827X,
641 .gpio_config = TDA10046_GP01_I,
642 .if_freq = TDA10046_FREQ_045,
644 .tuner_address = 0x61,
647 .request_firmware = philips_tda1004x_request_firmware
650 static struct tda1004x_config pinnacle_pctv_310i_config = {
651 .demod_address = 0x08,
654 .xtal_freq = TDA10046_XTAL_16M,
655 .agc_config = TDA10046_AGC_TDA827X,
656 .gpio_config = TDA10046_GP11_I,
657 .if_freq = TDA10046_FREQ_045,
659 .tuner_address = 0x61,
661 .request_firmware = philips_tda1004x_request_firmware
664 static struct tda1004x_config hauppauge_hvr_1110_config = {
665 .demod_address = 0x08,
668 .xtal_freq = TDA10046_XTAL_16M,
669 .agc_config = TDA10046_AGC_TDA827X,
670 .gpio_config = TDA10046_GP11_I,
671 .if_freq = TDA10046_FREQ_045,
673 .tuner_address = 0x61,
675 .request_firmware = philips_tda1004x_request_firmware
678 static struct tda1004x_config asus_p7131_dual_config = {
679 .demod_address = 0x08,
682 .xtal_freq = TDA10046_XTAL_16M,
683 .agc_config = TDA10046_AGC_TDA827X,
684 .gpio_config = TDA10046_GP11_I,
685 .if_freq = TDA10046_FREQ_045,
687 .tuner_address = 0x61,
690 .request_firmware = philips_tda1004x_request_firmware
693 static struct tda1004x_config lifeview_trio_config = {
694 .demod_address = 0x09,
697 .xtal_freq = TDA10046_XTAL_16M,
698 .agc_config = TDA10046_AGC_TDA827X,
699 .gpio_config = TDA10046_GP00_I,
700 .if_freq = TDA10046_FREQ_045,
701 .tuner_address = 0x60,
702 .request_firmware = philips_tda1004x_request_firmware
705 static struct tda1004x_config tevion_dvbt220rf_config = {
706 .demod_address = 0x08,
709 .xtal_freq = TDA10046_XTAL_16M,
710 .agc_config = TDA10046_AGC_TDA827X,
711 .gpio_config = TDA10046_GP11_I,
712 .if_freq = TDA10046_FREQ_045,
713 .tuner_address = 0x60,
714 .request_firmware = philips_tda1004x_request_firmware
717 static struct tda1004x_config md8800_dvbt_config = {
718 .demod_address = 0x08,
721 .xtal_freq = TDA10046_XTAL_16M,
722 .agc_config = TDA10046_AGC_TDA827X,
723 .gpio_config = TDA10046_GP01_I,
724 .if_freq = TDA10046_FREQ_045,
726 .tuner_address = 0x60,
728 .request_firmware = philips_tda1004x_request_firmware
731 static struct tda1004x_config asus_p7131_4871_config = {
732 .demod_address = 0x08,
735 .xtal_freq = TDA10046_XTAL_16M,
736 .agc_config = TDA10046_AGC_TDA827X,
737 .gpio_config = TDA10046_GP01_I,
738 .if_freq = TDA10046_FREQ_045,
740 .tuner_address = 0x61,
743 .request_firmware = philips_tda1004x_request_firmware
746 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
747 .demod_address = 0x08,
750 .xtal_freq = TDA10046_XTAL_16M,
751 .agc_config = TDA10046_AGC_TDA827X,
752 .gpio_config = TDA10046_GP11_I,
753 .if_freq = TDA10046_FREQ_045,
755 .tuner_address = 0x61,
758 .request_firmware = philips_tda1004x_request_firmware
761 static struct tda1004x_config kworld_dvb_t_210_config = {
762 .demod_address = 0x08,
765 .xtal_freq = TDA10046_XTAL_16M,
766 .agc_config = TDA10046_AGC_TDA827X,
767 .gpio_config = TDA10046_GP11_I,
768 .if_freq = TDA10046_FREQ_045,
770 .tuner_address = 0x61,
773 .request_firmware = philips_tda1004x_request_firmware
776 static struct tda1004x_config avermedia_super_007_config = {
777 .demod_address = 0x08,
780 .xtal_freq = TDA10046_XTAL_16M,
781 .agc_config = TDA10046_AGC_TDA827X,
782 .gpio_config = TDA10046_GP01_I,
783 .if_freq = TDA10046_FREQ_045,
785 .tuner_address = 0x60,
788 .request_firmware = philips_tda1004x_request_firmware
791 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
792 .demod_address = 0x08,
795 .xtal_freq = TDA10046_XTAL_16M,
796 .agc_config = TDA10046_AGC_TDA827X,
797 .gpio_config = TDA10046_GP01_I,
798 .if_freq = TDA10046_FREQ_045,
800 .tuner_address = 0x61,
803 .request_firmware = philips_tda1004x_request_firmware
806 /* ------------------------------------------------------------------
807 * special case: this card uses saa713x GPIO22 for the mode switch
810 static int ads_duo_tuner_init(struct dvb_frontend *fe)
812 struct saa7134_dev *dev = fe->dvb->priv;
813 philips_tda827x_tuner_init(fe);
814 /* route TDA8275a AGC input to the channel decoder */
815 saa7134_set_gpio(dev, 22, 1);
819 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
821 struct saa7134_dev *dev = fe->dvb->priv;
822 /* route TDA8275a AGC input to the analog IF chip*/
823 saa7134_set_gpio(dev, 22, 0);
824 philips_tda827x_tuner_sleep(fe);
828 static struct tda827x_config ads_duo_cfg = {
829 .lna_gain = philips_tda827x_lna_gain,
830 .init = ads_duo_tuner_init,
831 .sleep = ads_duo_tuner_sleep
834 static struct tda1004x_config ads_tech_duo_config = {
835 .demod_address = 0x08,
838 .xtal_freq = TDA10046_XTAL_16M,
839 .agc_config = TDA10046_AGC_TDA827X,
840 .gpio_config = TDA10046_GP00_I,
841 .if_freq = TDA10046_FREQ_045,
842 .tuner_address = 0x61,
843 .request_firmware = philips_tda1004x_request_firmware
846 /* ==================================================================
847 * tda10086 based DVB-S cards, helper functions
850 static struct tda10086_config flydvbs = {
851 .demod_address = 0x0e,
856 /* ------------------------------------------------------------------
857 * special case: lnb supply is connected to the gated i2c
860 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
863 struct saa7134_dev *dev = fe->dvb->priv;
864 if (fe->ops.i2c_gate_ctrl) {
865 fe->ops.i2c_gate_ctrl(fe, 1);
866 if (dev->original_set_voltage)
867 res = dev->original_set_voltage(fe, voltage);
868 fe->ops.i2c_gate_ctrl(fe, 0);
873 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
876 struct saa7134_dev *dev = fe->dvb->priv;
877 if (fe->ops.i2c_gate_ctrl) {
878 fe->ops.i2c_gate_ctrl(fe, 1);
879 if (dev->original_set_high_voltage)
880 res = dev->original_set_high_voltage(fe, arg);
881 fe->ops.i2c_gate_ctrl(fe, 0);
886 static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
888 struct saa7134_dev *dev = fe->dvb->priv;
889 u8 wbuf[2] = { 0x1f, 00 };
891 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
892 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
894 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
896 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
897 if (voltage == SEC_VOLTAGE_18)
898 wbuf[1] = rbuf | 0x10;
900 wbuf[1] = rbuf & 0xef;
902 i2c_transfer(&dev->i2c_adap, msg, 1);
906 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
908 struct saa7134_dev *dev = fe->dvb->priv;
909 wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
913 /* ==================================================================
914 * nxt200x based ATSC cards, helper functions
917 static struct nxt200x_config avertvhda180 = {
918 .demod_address = 0x0a,
921 static struct nxt200x_config kworldatsc110 = {
922 .demod_address = 0x0a,
925 /* ==================================================================
929 static int dvb_init(struct saa7134_dev *dev)
932 int attach_xc3028 = 0;
934 /* init struct videobuf_dvb */
935 dev->ts.nr_bufs = 32;
936 dev->ts.nr_packets = 32*4;
937 dev->dvb.name = dev->name;
938 videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
939 &dev->pci->dev, &dev->slock,
940 V4L2_BUF_TYPE_VIDEO_CAPTURE,
941 V4L2_FIELD_ALTERNATE,
942 sizeof(struct saa7134_buf),
945 switch (dev->board) {
946 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
947 dprintk("pinnacle 300i dvb setup\n");
948 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
950 if (dev->dvb.frontend) {
951 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
954 case SAA7134_BOARD_AVERMEDIA_777:
955 case SAA7134_BOARD_AVERMEDIA_A16AR:
956 dprintk("avertv 777 dvb setup\n");
957 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
959 if (dev->dvb.frontend) {
960 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
961 NULL, DVB_PLL_PHILIPS_TD1316);
964 case SAA7134_BOARD_MD7134:
965 dev->dvb.frontend = dvb_attach(tda10046_attach,
968 if (dev->dvb.frontend) {
969 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
970 &dev->i2c_adap, DVB_PLL_FMD1216ME);
973 case SAA7134_BOARD_PHILIPS_TOUGH:
974 dev->dvb.frontend = dvb_attach(tda10046_attach,
975 &philips_tu1216_60_config,
977 if (dev->dvb.frontend) {
978 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
979 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
982 case SAA7134_BOARD_FLYDVBTDUO:
983 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
984 configure_tda827x_fe(dev, &tda827x_lifeview_config);
986 case SAA7134_BOARD_PHILIPS_EUROPA:
987 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
988 dev->dvb.frontend = dvb_attach(tda10046_attach,
989 &philips_europa_config,
991 if (dev->dvb.frontend) {
992 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
993 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
994 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
995 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
996 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
999 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1000 dev->dvb.frontend = dvb_attach(tda10046_attach,
1001 &philips_tu1216_61_config,
1003 if (dev->dvb.frontend) {
1004 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1005 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1008 case SAA7134_BOARD_KWORLD_DVBT_210:
1009 configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
1011 case SAA7134_BOARD_PHILIPS_TIGER:
1012 configure_tda827x_fe(dev, &philips_tiger_config);
1014 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1015 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
1017 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1018 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
1020 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1021 configure_tda827x_fe(dev, &asus_p7131_dual_config);
1023 case SAA7134_BOARD_FLYDVBT_LR301:
1024 configure_tda827x_fe(dev, &tda827x_lifeview_config);
1026 case SAA7134_BOARD_FLYDVB_TRIO:
1027 if(! use_frontend) { /* terrestrial */
1028 configure_tda827x_fe(dev, &lifeview_trio_config);
1029 } else { /* satellite */
1030 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1031 if (dev->dvb.frontend) {
1032 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1033 &dev->i2c_adap, 0) == NULL) {
1034 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
1036 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1037 0x08, 0, 0) == NULL) {
1038 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1043 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1044 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1045 dev->dvb.frontend = dvb_attach(tda10046_attach,
1046 &ads_tech_duo_config,
1048 if (dev->dvb.frontend) {
1049 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1050 ads_tech_duo_config.tuner_address,
1051 &dev->i2c_adap,&ads_duo_cfg) == NULL) {
1052 wprintk("no tda827x tuner found at addr: %02x\n",
1053 ads_tech_duo_config.tuner_address);
1057 case SAA7134_BOARD_TEVION_DVBT_220RF:
1058 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1060 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1061 if (!use_frontend) { /* terrestrial */
1062 configure_tda827x_fe(dev, &md8800_dvbt_config);
1063 } else { /* satellite */
1064 dev->dvb.frontend = dvb_attach(tda10086_attach,
1065 &flydvbs, &dev->i2c_adap);
1066 if (dev->dvb.frontend) {
1067 struct dvb_frontend *fe = dev->dvb.frontend;
1068 u8 dev_id = dev->eedata[2];
1070 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1072 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1073 0x60, &dev->i2c_adap, 0) == NULL)
1074 wprintk("%s: Medion Quadro, no tda826x "
1075 "found !\n", __func__);
1076 if (dev_id != 0x08) {
1077 /* we need to open the i2c gate (we know it exists) */
1078 fe->ops.i2c_gate_ctrl(fe, 1);
1079 if (dvb_attach(isl6405_attach, fe,
1080 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1081 wprintk("%s: Medion Quadro, no ISL6405 "
1082 "found !\n", __func__);
1083 /* fire up the 2nd section of the LNB supply since we can't do
1084 this from the other section */
1086 i2c_transfer(&dev->i2c_adap, &msg, 1);
1087 fe->ops.i2c_gate_ctrl(fe, 0);
1088 dev->original_set_voltage = fe->ops.set_voltage;
1089 fe->ops.set_voltage = md8800_set_voltage;
1090 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1091 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1093 fe->ops.set_voltage = md8800_set_voltage2;
1094 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1099 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1100 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1102 if (dev->dvb.frontend) {
1103 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1104 NULL, DVB_PLL_TDHU2);
1107 case SAA7134_BOARD_KWORLD_ATSC110:
1108 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1110 if (dev->dvb.frontend) {
1111 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1112 NULL, DVB_PLL_TUV1236D);
1115 case SAA7134_BOARD_FLYDVBS_LR300:
1116 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1118 if (dev->dvb.frontend) {
1119 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1120 &dev->i2c_adap, 0) == NULL) {
1121 wprintk("%s: No tda826x found!\n", __func__);
1123 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1124 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1125 wprintk("%s: No ISL6421 found!\n", __func__);
1129 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1130 dev->dvb.frontend = dvb_attach(tda10046_attach,
1133 if (dev->dvb.frontend) {
1134 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1135 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1137 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
1138 &dev->i2c_adap, DVB_PLL_FMD1216ME);
1141 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1142 dev->dvb.frontend = dvb_attach(tda10046_attach,
1143 &philips_europa_config,
1145 if (dev->dvb.frontend) {
1146 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1147 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1150 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1151 configure_tda827x_fe(dev, &cinergy_ht_config);
1153 case SAA7134_BOARD_CINERGY_HT_PCI:
1154 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1156 case SAA7134_BOARD_PHILIPS_TIGER_S:
1157 configure_tda827x_fe(dev, &philips_tiger_s_config);
1159 case SAA7134_BOARD_ASUS_P7131_4871:
1160 configure_tda827x_fe(dev, &asus_p7131_4871_config);
1162 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1163 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1165 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1166 configure_tda827x_fe(dev, &avermedia_super_007_config);
1168 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1169 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config);
1171 case SAA7134_BOARD_PHILIPS_SNAKE:
1172 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1174 if (dev->dvb.frontend) {
1175 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1176 &dev->i2c_adap, 0) == NULL)
1177 wprintk("%s: No tda826x found!\n", __func__);
1178 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1179 &dev->i2c_adap, 0, 0) == NULL)
1180 wprintk("%s: No lnbp21 found!\n", __func__);
1183 case SAA7134_BOARD_CREATIX_CTX953:
1184 configure_tda827x_fe(dev, &md8800_dvbt_config);
1186 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1187 configure_tda827x_fe(dev, &philips_tiger_s_config);
1189 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1190 dev->dvb.frontend = dvb_attach(mt352_attach,
1191 &avermedia_e506r_mt352_dev,
1195 case SAA7134_BOARD_MD7134_BRIDGE_2:
1196 dev->dvb.frontend = dvb_attach(tda10086_attach,
1197 &flydvbs, &dev->i2c_adap);
1198 if (dev->dvb.frontend) {
1199 struct dvb_frontend *fe;
1200 if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
1201 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL)
1202 wprintk("%s: MD7134 DVB-S, no SD1878 "
1203 "found !\n", __func__);
1204 /* we need to open the i2c gate (we know it exists) */
1205 fe = dev->dvb.frontend;
1206 fe->ops.i2c_gate_ctrl(fe, 1);
1207 if (dvb_attach(isl6405_attach, fe,
1208 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1209 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1210 "found !\n", __func__);
1211 fe->ops.i2c_gate_ctrl(fe, 0);
1212 dev->original_set_voltage = fe->ops.set_voltage;
1213 fe->ops.set_voltage = md8800_set_voltage;
1214 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1215 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1219 wprintk("Huh? unknown DVB card?\n");
1223 if (attach_xc3028) {
1224 struct dvb_frontend *fe;
1225 struct xc2028_config cfg = {
1226 .i2c_adap = &dev->i2c_adap,
1228 .video_dev = dev->i2c_adap.algo_data,
1230 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1232 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1234 dvb_frontend_detach(dev->dvb.frontend);
1235 dvb_unregister_frontend(dev->dvb.frontend);
1236 dev->dvb.frontend = NULL;
1241 if (NULL == dev->dvb.frontend) {
1242 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1246 /* register everything else */
1247 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1249 /* this sequence is necessary to make the tda1004x load its firmware
1250 * and to enter analog mode of hybrid boards
1253 if (dev->dvb.frontend->ops.init)
1254 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1255 if (dev->dvb.frontend->ops.sleep)
1256 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1257 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1258 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1263 static int dvb_fini(struct saa7134_dev *dev)
1265 /* FIXME: I suspect that this code is bogus, since the entry for
1266 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1267 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1269 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1270 struct v4l2_priv_tun_config tda9887_cfg;
1271 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1273 tda9887_cfg.tuner = TUNER_TDA9887;
1274 tda9887_cfg.priv = &on;
1276 /* otherwise we don't detect the tuner on next insmod */
1277 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1278 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1279 if ((dev->eedata[2] != 0x08) && use_frontend) {
1280 /* turn off the 2nd lnb supply */
1282 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1283 struct dvb_frontend *fe;
1284 fe = dev->dvb.frontend;
1285 if (fe->ops.i2c_gate_ctrl) {
1286 fe->ops.i2c_gate_ctrl(fe, 1);
1287 i2c_transfer(&dev->i2c_adap, &msg, 1);
1288 fe->ops.i2c_gate_ctrl(fe, 0);
1292 videobuf_dvb_unregister(&dev->dvb);
1296 static struct saa7134_mpeg_ops dvb_ops = {
1297 .type = SAA7134_MPEG_DVB,
1302 static int __init dvb_register(void)
1304 return saa7134_ts_register(&dvb_ops);
1307 static void __exit dvb_unregister(void)
1309 saa7134_ts_unregister(&dvb_ops);
1312 module_init(dvb_register);
1313 module_exit(dvb_unregister);
1315 /* ------------------------------------------------------------------ */