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 */
41 #include "tuner-xc2028.h"
50 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
51 MODULE_LICENSE("GPL");
53 static unsigned int antenna_pwr;
55 module_param(antenna_pwr, int, 0444);
56 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
58 static int use_frontend;
59 module_param(use_frontend, int, 0644);
60 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
63 module_param(debug, int, 0644);
64 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
66 #define dprintk(fmt, arg...) do { if (debug) \
67 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
70 #define wprintk(fmt, arg...) \
71 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
73 /* ------------------------------------------------------------------
74 * mt352 based DVB-T cards
77 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
82 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
83 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
87 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
88 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
91 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
92 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
94 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
96 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
97 dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off");
100 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
104 static int mt352_pinnacle_init(struct dvb_frontend* fe)
106 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
107 static u8 reset [] = { RESET, 0x80 };
108 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
109 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
110 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
111 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
112 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
113 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
114 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
115 struct saa7134_dev *dev= fe->dvb->priv;
117 dprintk("%s called\n", __FUNCTION__);
119 mt352_write(fe, clock_config, sizeof(clock_config));
121 mt352_write(fe, reset, sizeof(reset));
122 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
123 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
124 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
125 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
127 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
128 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
129 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
134 static int mt352_aver777_init(struct dvb_frontend* fe)
136 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
137 static u8 reset [] = { RESET, 0x80 };
138 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
139 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
140 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
142 mt352_write(fe, clock_config, sizeof(clock_config));
144 mt352_write(fe, reset, sizeof(reset));
145 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
146 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
147 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
152 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
153 struct dvb_frontend_parameters* params)
155 u8 off[] = { 0x00, 0xf1};
156 u8 on[] = { 0x00, 0x71};
157 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
159 struct saa7134_dev *dev = fe->dvb->priv;
160 struct v4l2_frequency f;
162 /* set frequency (mt2050) */
164 f.type = V4L2_TUNER_DIGITAL_TV;
165 f.frequency = params->frequency / 1000 * 16 / 1000;
166 if (fe->ops.i2c_gate_ctrl)
167 fe->ops.i2c_gate_ctrl(fe, 1);
168 i2c_transfer(&dev->i2c_adap, &msg, 1);
169 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
171 if (fe->ops.i2c_gate_ctrl)
172 fe->ops.i2c_gate_ctrl(fe, 1);
173 i2c_transfer(&dev->i2c_adap, &msg, 1);
175 pinnacle_antenna_pwr(dev, antenna_pwr);
178 return mt352_pinnacle_init(fe);
181 static struct mt352_config pinnacle_300i = {
182 .demod_address = 0x3c >> 1,
186 .demod_init = mt352_pinnacle_init,
189 static struct mt352_config avermedia_777 = {
190 .demod_address = 0xf,
191 .demod_init = mt352_aver777_init,
194 static struct mt352_config avermedia_e506r_mt352_dev = {
195 .demod_address = (0x1e >> 1),
199 /* ==================================================================
200 * tda1004x based DVB-T cards, helper functions
203 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
204 const struct firmware **fw, char *name)
206 struct saa7134_dev *dev = fe->dvb->priv;
207 return request_firmware(fw, name, &dev->pci->dev);
210 /* ------------------------------------------------------------------
211 * these tuners are tu1216, td1316(a)
214 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
216 struct saa7134_dev *dev = fe->dvb->priv;
217 struct tda1004x_state *state = fe->demodulator_priv;
218 u8 addr = state->config->tuner_address;
220 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
222 int tuner_frequency = 0;
225 /* determine charge pump */
226 tuner_frequency = params->frequency + 36166000;
227 if (tuner_frequency < 87000000)
229 else if (tuner_frequency < 130000000)
231 else if (tuner_frequency < 160000000)
233 else if (tuner_frequency < 200000000)
235 else if (tuner_frequency < 290000000)
237 else if (tuner_frequency < 420000000)
239 else if (tuner_frequency < 480000000)
241 else if (tuner_frequency < 620000000)
243 else if (tuner_frequency < 830000000)
245 else if (tuner_frequency < 895000000)
251 if (params->frequency < 49000000)
253 else if (params->frequency < 161000000)
255 else if (params->frequency < 444000000)
257 else if (params->frequency < 861000000)
262 /* setup PLL filter */
263 switch (params->u.ofdm.bandwidth) {
264 case BANDWIDTH_6_MHZ:
268 case BANDWIDTH_7_MHZ:
272 case BANDWIDTH_8_MHZ:
281 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
283 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
285 /* setup tuner buffer */
286 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
287 tuner_buf[1] = tuner_frequency & 0xff;
289 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
291 if (fe->ops.i2c_gate_ctrl)
292 fe->ops.i2c_gate_ctrl(fe, 1);
293 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
294 wprintk("could not write to tuner at addr: 0x%02x\n",
302 static int philips_tu1216_init(struct dvb_frontend *fe)
304 struct saa7134_dev *dev = fe->dvb->priv;
305 struct tda1004x_state *state = fe->demodulator_priv;
306 u8 addr = state->config->tuner_address;
307 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
308 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
310 /* setup PLL configuration */
311 if (fe->ops.i2c_gate_ctrl)
312 fe->ops.i2c_gate_ctrl(fe, 1);
313 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
320 /* ------------------------------------------------------------------ */
322 static struct tda1004x_config philips_tu1216_60_config = {
323 .demod_address = 0x8,
326 .xtal_freq = TDA10046_XTAL_4M,
327 .agc_config = TDA10046_AGC_DEFAULT,
328 .if_freq = TDA10046_FREQ_3617,
329 .tuner_address = 0x60,
330 .request_firmware = philips_tda1004x_request_firmware
333 static struct tda1004x_config philips_tu1216_61_config = {
335 .demod_address = 0x8,
338 .xtal_freq = TDA10046_XTAL_4M,
339 .agc_config = TDA10046_AGC_DEFAULT,
340 .if_freq = TDA10046_FREQ_3617,
341 .tuner_address = 0x61,
342 .request_firmware = philips_tda1004x_request_firmware
345 /* ------------------------------------------------------------------ */
347 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
349 struct saa7134_dev *dev = fe->dvb->priv;
350 struct tda1004x_state *state = fe->demodulator_priv;
351 u8 addr = state->config->tuner_address;
352 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
353 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
355 /* setup PLL configuration */
356 if (fe->ops.i2c_gate_ctrl)
357 fe->ops.i2c_gate_ctrl(fe, 1);
358 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
363 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
365 return philips_tda6651_pll_set(fe, params);
368 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
370 struct saa7134_dev *dev = fe->dvb->priv;
371 struct tda1004x_state *state = fe->demodulator_priv;
372 u8 addr = state->config->tuner_address;
373 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
374 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
376 /* switch the tuner to analog mode */
377 if (fe->ops.i2c_gate_ctrl)
378 fe->ops.i2c_gate_ctrl(fe, 1);
379 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
384 /* ------------------------------------------------------------------ */
386 static int philips_europa_tuner_init(struct dvb_frontend *fe)
388 struct saa7134_dev *dev = fe->dvb->priv;
389 static u8 msg[] = { 0x00, 0x40};
390 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
393 if (philips_td1316_tuner_init(fe))
396 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
402 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
404 struct saa7134_dev *dev = fe->dvb->priv;
406 static u8 msg[] = { 0x00, 0x14 };
407 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
409 if (philips_td1316_tuner_sleep(fe))
412 /* switch the board to analog mode */
413 if (fe->ops.i2c_gate_ctrl)
414 fe->ops.i2c_gate_ctrl(fe, 1);
415 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
419 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
421 struct saa7134_dev *dev = fe->dvb->priv;
423 if (dev->original_demod_sleep)
424 dev->original_demod_sleep(fe);
425 fe->ops.i2c_gate_ctrl(fe, 1);
429 static struct tda1004x_config philips_europa_config = {
431 .demod_address = 0x8,
434 .xtal_freq = TDA10046_XTAL_4M,
435 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
436 .if_freq = TDA10046_FREQ_052,
437 .tuner_address = 0x61,
438 .request_firmware = philips_tda1004x_request_firmware
441 /* ------------------------------------------------------------------ */
443 static struct tda1004x_config medion_cardbus = {
444 .demod_address = 0x08,
447 .xtal_freq = TDA10046_XTAL_16M,
448 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
449 .if_freq = TDA10046_FREQ_3613,
450 .tuner_address = 0x61,
451 .request_firmware = philips_tda1004x_request_firmware
454 /* ------------------------------------------------------------------
455 * tda 1004x based cards with philips silicon tuner
458 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
460 struct saa7134_dev *dev = fe->dvb->priv;
461 struct tda1004x_state *state = fe->demodulator_priv;
462 u8 addr = state->config->i2c_gate;
463 u8 config = state->config->tuner_config;
464 u8 GP00_CF[] = {0x20, 0x01};
465 u8 GP00_LEV[] = {0x22, 0x00};
467 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
470 dprintk("setting LNA to high gain\n");
472 dprintk("setting LNA to low gain\n");
478 case 1: /* switch is GPIO 0 of tda8290 */
481 saa7134_set_gpio(dev, 22, 0);
482 GP00_LEV[1] = high ? 0 : 1;
483 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
484 wprintk("could not access tda8290 at addr: 0x%02x\n",
490 GP00_LEV[1] = high ? 1 : 0;
491 i2c_transfer(&dev->i2c_adap, &msg, 1);
493 case 3: /* switch with GPIO of saa713x */
494 saa7134_set_gpio(dev, 22, high);
499 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
501 struct tda1004x_state *state = fe->demodulator_priv;
503 u8 addr = state->config->i2c_gate;
504 static u8 tda8290_close[] = { 0x21, 0xc0};
505 static u8 tda8290_open[] = { 0x21, 0x80};
506 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
508 tda8290_msg.buf = tda8290_close;
510 tda8290_msg.buf = tda8290_open;
512 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
513 struct saa7134_dev *dev = fe->dvb->priv;
514 wprintk("could not access tda8290 I2C gate\n");
521 /* ------------------------------------------------------------------ */
523 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
525 struct saa7134_dev *dev = fe->dvb->priv;
526 struct tda1004x_state *state = fe->demodulator_priv;
528 switch (state->config->antenna_switch) {
530 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
531 saa7134_set_gpio(dev, 21, 0);
533 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
534 saa7134_set_gpio(dev, 21, 1);
540 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
542 struct saa7134_dev *dev = fe->dvb->priv;
543 struct tda1004x_state *state = fe->demodulator_priv;
545 switch (state->config->antenna_switch) {
547 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
548 saa7134_set_gpio(dev, 21, 1);
550 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
551 saa7134_set_gpio(dev, 21, 0);
557 static struct tda827x_config tda827x_cfg = {
558 .lna_gain = philips_tda827x_lna_gain,
559 .init = philips_tda827x_tuner_init,
560 .sleep = philips_tda827x_tuner_sleep
563 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
565 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
566 if (dev->dvb.frontend) {
567 if (tda_conf->i2c_gate)
568 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
569 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
570 &dev->i2c_adap,&tda827x_cfg) == NULL) {
571 wprintk("no tda827x tuner found at addr: %02x\n",
572 tda_conf->tuner_address);
577 /* ------------------------------------------------------------------ */
579 static struct tda1004x_config tda827x_lifeview_config = {
580 .demod_address = 0x08,
583 .xtal_freq = TDA10046_XTAL_16M,
584 .agc_config = TDA10046_AGC_TDA827X,
585 .gpio_config = TDA10046_GP11_I,
586 .if_freq = TDA10046_FREQ_045,
587 .tuner_address = 0x60,
588 .request_firmware = philips_tda1004x_request_firmware
591 static struct tda1004x_config philips_tiger_config = {
592 .demod_address = 0x08,
595 .xtal_freq = TDA10046_XTAL_16M,
596 .agc_config = TDA10046_AGC_TDA827X,
597 .gpio_config = TDA10046_GP11_I,
598 .if_freq = TDA10046_FREQ_045,
600 .tuner_address = 0x61,
603 .request_firmware = philips_tda1004x_request_firmware
606 static struct tda1004x_config cinergy_ht_config = {
607 .demod_address = 0x08,
610 .xtal_freq = TDA10046_XTAL_16M,
611 .agc_config = TDA10046_AGC_TDA827X,
612 .gpio_config = TDA10046_GP01_I,
613 .if_freq = TDA10046_FREQ_045,
615 .tuner_address = 0x61,
617 .request_firmware = philips_tda1004x_request_firmware
620 static struct tda1004x_config cinergy_ht_pci_config = {
621 .demod_address = 0x08,
624 .xtal_freq = TDA10046_XTAL_16M,
625 .agc_config = TDA10046_AGC_TDA827X,
626 .gpio_config = TDA10046_GP01_I,
627 .if_freq = TDA10046_FREQ_045,
629 .tuner_address = 0x60,
631 .request_firmware = philips_tda1004x_request_firmware
634 static struct tda1004x_config philips_tiger_s_config = {
635 .demod_address = 0x08,
638 .xtal_freq = TDA10046_XTAL_16M,
639 .agc_config = TDA10046_AGC_TDA827X,
640 .gpio_config = TDA10046_GP01_I,
641 .if_freq = TDA10046_FREQ_045,
643 .tuner_address = 0x61,
646 .request_firmware = philips_tda1004x_request_firmware
649 static struct tda1004x_config pinnacle_pctv_310i_config = {
650 .demod_address = 0x08,
653 .xtal_freq = TDA10046_XTAL_16M,
654 .agc_config = TDA10046_AGC_TDA827X,
655 .gpio_config = TDA10046_GP11_I,
656 .if_freq = TDA10046_FREQ_045,
658 .tuner_address = 0x61,
660 .request_firmware = philips_tda1004x_request_firmware
663 static struct tda1004x_config hauppauge_hvr_1110_config = {
664 .demod_address = 0x08,
667 .xtal_freq = TDA10046_XTAL_16M,
668 .agc_config = TDA10046_AGC_TDA827X,
669 .gpio_config = TDA10046_GP11_I,
670 .if_freq = TDA10046_FREQ_045,
672 .tuner_address = 0x61,
674 .request_firmware = philips_tda1004x_request_firmware
677 static struct tda1004x_config asus_p7131_dual_config = {
678 .demod_address = 0x08,
681 .xtal_freq = TDA10046_XTAL_16M,
682 .agc_config = TDA10046_AGC_TDA827X,
683 .gpio_config = TDA10046_GP11_I,
684 .if_freq = TDA10046_FREQ_045,
686 .tuner_address = 0x61,
689 .request_firmware = philips_tda1004x_request_firmware
692 static struct tda1004x_config lifeview_trio_config = {
693 .demod_address = 0x09,
696 .xtal_freq = TDA10046_XTAL_16M,
697 .agc_config = TDA10046_AGC_TDA827X,
698 .gpio_config = TDA10046_GP00_I,
699 .if_freq = TDA10046_FREQ_045,
700 .tuner_address = 0x60,
701 .request_firmware = philips_tda1004x_request_firmware
704 static struct tda1004x_config tevion_dvbt220rf_config = {
705 .demod_address = 0x08,
708 .xtal_freq = TDA10046_XTAL_16M,
709 .agc_config = TDA10046_AGC_TDA827X,
710 .gpio_config = TDA10046_GP11_I,
711 .if_freq = TDA10046_FREQ_045,
712 .tuner_address = 0x60,
713 .request_firmware = philips_tda1004x_request_firmware
716 static struct tda1004x_config md8800_dvbt_config = {
717 .demod_address = 0x08,
720 .xtal_freq = TDA10046_XTAL_16M,
721 .agc_config = TDA10046_AGC_TDA827X,
722 .gpio_config = TDA10046_GP01_I,
723 .if_freq = TDA10046_FREQ_045,
725 .tuner_address = 0x60,
727 .request_firmware = philips_tda1004x_request_firmware
730 static struct tda1004x_config asus_p7131_4871_config = {
731 .demod_address = 0x08,
734 .xtal_freq = TDA10046_XTAL_16M,
735 .agc_config = TDA10046_AGC_TDA827X,
736 .gpio_config = TDA10046_GP01_I,
737 .if_freq = TDA10046_FREQ_045,
739 .tuner_address = 0x61,
742 .request_firmware = philips_tda1004x_request_firmware
745 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
746 .demod_address = 0x08,
749 .xtal_freq = TDA10046_XTAL_16M,
750 .agc_config = TDA10046_AGC_TDA827X,
751 .gpio_config = TDA10046_GP11_I,
752 .if_freq = TDA10046_FREQ_045,
754 .tuner_address = 0x61,
757 .request_firmware = philips_tda1004x_request_firmware
760 static struct tda1004x_config kworld_dvb_t_210_config = {
761 .demod_address = 0x08,
764 .xtal_freq = TDA10046_XTAL_16M,
765 .agc_config = TDA10046_AGC_TDA827X,
766 .gpio_config = TDA10046_GP11_I,
767 .if_freq = TDA10046_FREQ_045,
769 .tuner_address = 0x61,
772 .request_firmware = philips_tda1004x_request_firmware
775 static struct tda1004x_config avermedia_super_007_config = {
776 .demod_address = 0x08,
779 .xtal_freq = TDA10046_XTAL_16M,
780 .agc_config = TDA10046_AGC_TDA827X,
781 .gpio_config = TDA10046_GP01_I,
782 .if_freq = TDA10046_FREQ_045,
784 .tuner_address = 0x60,
787 .request_firmware = philips_tda1004x_request_firmware
790 static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
791 .demod_address = 0x08,
794 .xtal_freq = TDA10046_XTAL_16M,
795 .agc_config = TDA10046_AGC_TDA827X,
796 .gpio_config = TDA10046_GP01_I,
797 .if_freq = TDA10046_FREQ_045,
799 .tuner_address = 0x61,
802 .request_firmware = philips_tda1004x_request_firmware
805 /* ------------------------------------------------------------------
806 * special case: this card uses saa713x GPIO22 for the mode switch
809 static int ads_duo_tuner_init(struct dvb_frontend *fe)
811 struct saa7134_dev *dev = fe->dvb->priv;
812 philips_tda827x_tuner_init(fe);
813 /* route TDA8275a AGC input to the channel decoder */
814 saa7134_set_gpio(dev, 22, 1);
818 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
820 struct saa7134_dev *dev = fe->dvb->priv;
821 /* route TDA8275a AGC input to the analog IF chip*/
822 saa7134_set_gpio(dev, 22, 0);
823 philips_tda827x_tuner_sleep(fe);
827 static struct tda827x_config ads_duo_cfg = {
828 .lna_gain = philips_tda827x_lna_gain,
829 .init = ads_duo_tuner_init,
830 .sleep = ads_duo_tuner_sleep
833 static struct tda1004x_config ads_tech_duo_config = {
834 .demod_address = 0x08,
837 .xtal_freq = TDA10046_XTAL_16M,
838 .agc_config = TDA10046_AGC_TDA827X,
839 .gpio_config = TDA10046_GP00_I,
840 .if_freq = TDA10046_FREQ_045,
841 .tuner_address = 0x61,
842 .request_firmware = philips_tda1004x_request_firmware
845 /* ==================================================================
846 * tda10086 based DVB-S cards, helper functions
849 static struct tda10086_config flydvbs = {
850 .demod_address = 0x0e,
855 /* ------------------------------------------------------------------
856 * special case: lnb supply is connected to the gated i2c
859 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
862 struct saa7134_dev *dev = fe->dvb->priv;
863 if (fe->ops.i2c_gate_ctrl) {
864 fe->ops.i2c_gate_ctrl(fe, 1);
865 if (dev->original_set_voltage)
866 res = dev->original_set_voltage(fe, voltage);
867 fe->ops.i2c_gate_ctrl(fe, 0);
872 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
875 struct saa7134_dev *dev = fe->dvb->priv;
876 if (fe->ops.i2c_gate_ctrl) {
877 fe->ops.i2c_gate_ctrl(fe, 1);
878 if (dev->original_set_high_voltage)
879 res = dev->original_set_high_voltage(fe, arg);
880 fe->ops.i2c_gate_ctrl(fe, 0);
885 /* ==================================================================
886 * nxt200x based ATSC cards, helper functions
889 static struct nxt200x_config avertvhda180 = {
890 .demod_address = 0x0a,
893 static struct nxt200x_config kworldatsc110 = {
894 .demod_address = 0x0a,
897 /* ==================================================================
901 static int dvb_init(struct saa7134_dev *dev)
904 int attach_xc3028 = 0;
906 /* init struct videobuf_dvb */
907 dev->ts.nr_bufs = 32;
908 dev->ts.nr_packets = 32*4;
909 dev->dvb.name = dev->name;
910 videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
911 &dev->pci->dev, &dev->slock,
912 V4L2_BUF_TYPE_VIDEO_CAPTURE,
913 V4L2_FIELD_ALTERNATE,
914 sizeof(struct saa7134_buf),
917 switch (dev->board) {
918 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
919 dprintk("pinnacle 300i dvb setup\n");
920 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
922 if (dev->dvb.frontend) {
923 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
926 case SAA7134_BOARD_AVERMEDIA_777:
927 case SAA7134_BOARD_AVERMEDIA_A16AR:
928 dprintk("avertv 777 dvb setup\n");
929 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
931 if (dev->dvb.frontend) {
932 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
933 NULL, DVB_PLL_PHILIPS_TD1316);
936 case SAA7134_BOARD_MD7134:
937 dev->dvb.frontend = dvb_attach(tda10046_attach,
940 if (dev->dvb.frontend) {
941 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
942 &dev->i2c_adap, DVB_PLL_FMD1216ME);
945 case SAA7134_BOARD_PHILIPS_TOUGH:
946 dev->dvb.frontend = dvb_attach(tda10046_attach,
947 &philips_tu1216_60_config,
949 if (dev->dvb.frontend) {
950 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
951 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
954 case SAA7134_BOARD_FLYDVBTDUO:
955 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
956 configure_tda827x_fe(dev, &tda827x_lifeview_config);
958 case SAA7134_BOARD_PHILIPS_EUROPA:
959 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
960 dev->dvb.frontend = dvb_attach(tda10046_attach,
961 &philips_europa_config,
963 if (dev->dvb.frontend) {
964 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
965 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
966 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
967 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
968 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
971 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
972 dev->dvb.frontend = dvb_attach(tda10046_attach,
973 &philips_tu1216_61_config,
975 if (dev->dvb.frontend) {
976 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
977 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
980 case SAA7134_BOARD_KWORLD_DVBT_210:
981 configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
983 case SAA7134_BOARD_PHILIPS_TIGER:
984 configure_tda827x_fe(dev, &philips_tiger_config);
986 case SAA7134_BOARD_PINNACLE_PCTV_310i:
987 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
989 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
990 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
992 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
993 configure_tda827x_fe(dev, &asus_p7131_dual_config);
995 case SAA7134_BOARD_FLYDVBT_LR301:
996 configure_tda827x_fe(dev, &tda827x_lifeview_config);
998 case SAA7134_BOARD_FLYDVB_TRIO:
999 if(! use_frontend) { /* terrestrial */
1000 configure_tda827x_fe(dev, &lifeview_trio_config);
1001 } else { /* satellite */
1002 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1003 if (dev->dvb.frontend) {
1004 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1005 &dev->i2c_adap, 0) == NULL) {
1006 wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1008 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1009 0x08, 0, 0) == NULL) {
1010 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1015 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1016 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1017 dev->dvb.frontend = dvb_attach(tda10046_attach,
1018 &ads_tech_duo_config,
1020 if (dev->dvb.frontend) {
1021 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1022 ads_tech_duo_config.tuner_address,
1023 &dev->i2c_adap,&ads_duo_cfg) == NULL) {
1024 wprintk("no tda827x tuner found at addr: %02x\n",
1025 ads_tech_duo_config.tuner_address);
1029 case SAA7134_BOARD_TEVION_DVBT_220RF:
1030 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1032 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1033 if (!use_frontend) { /* terrestrial */
1034 configure_tda827x_fe(dev, &md8800_dvbt_config);
1035 } else { /* satellite */
1036 dev->dvb.frontend = dvb_attach(tda10086_attach,
1037 &flydvbs, &dev->i2c_adap);
1038 if (dev->dvb.frontend) {
1039 struct dvb_frontend *fe;
1040 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1041 0x60, &dev->i2c_adap, 0) == NULL)
1042 wprintk("%s: Medion Quadro, no tda826x "
1043 "found !\n", __FUNCTION__);
1045 * up to here. configuration for ctx948 and and one branch
1046 * of md8800 should be identical
1048 /* we need to open the i2c gate (we know it exists) */
1049 fe = dev->dvb.frontend;
1050 fe->ops.i2c_gate_ctrl(fe, 1);
1051 if (dvb_attach(isl6405_attach, fe,
1052 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1053 wprintk("%s: Medion Quadro, no ISL6405 "
1054 "found !\n", __FUNCTION__);
1055 fe->ops.i2c_gate_ctrl(fe, 0);
1056 dev->original_set_voltage = fe->ops.set_voltage;
1057 fe->ops.set_voltage = md8800_set_voltage;
1058 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1059 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1063 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1064 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1066 if (dev->dvb.frontend) {
1067 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1068 NULL, DVB_PLL_TDHU2);
1071 case SAA7134_BOARD_KWORLD_ATSC110:
1072 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1074 if (dev->dvb.frontend) {
1075 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1076 NULL, DVB_PLL_TUV1236D);
1079 case SAA7134_BOARD_FLYDVBS_LR300:
1080 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1082 if (dev->dvb.frontend) {
1083 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1084 &dev->i2c_adap, 0) == NULL) {
1085 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1087 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1088 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1089 wprintk("%s: No ISL6421 found!\n", __FUNCTION__);
1093 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1094 dev->dvb.frontend = dvb_attach(tda10046_attach,
1097 if (dev->dvb.frontend) {
1098 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1099 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1101 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address,
1102 &dev->i2c_adap, DVB_PLL_FMD1216ME);
1105 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1106 dev->dvb.frontend = dvb_attach(tda10046_attach,
1107 &philips_europa_config,
1109 if (dev->dvb.frontend) {
1110 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1111 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1114 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1115 configure_tda827x_fe(dev, &cinergy_ht_config);
1117 case SAA7134_BOARD_CINERGY_HT_PCI:
1118 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1120 case SAA7134_BOARD_PHILIPS_TIGER_S:
1121 configure_tda827x_fe(dev, &philips_tiger_s_config);
1123 case SAA7134_BOARD_ASUS_P7131_4871:
1124 configure_tda827x_fe(dev, &asus_p7131_4871_config);
1126 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1127 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1129 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1130 configure_tda827x_fe(dev, &avermedia_super_007_config);
1132 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1133 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config);
1135 case SAA7134_BOARD_PHILIPS_SNAKE:
1136 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1138 if (dev->dvb.frontend) {
1139 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1140 &dev->i2c_adap, 0) == NULL)
1141 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1142 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1143 &dev->i2c_adap, 0, 0) == NULL)
1144 wprintk("%s: No lnbp21 found!\n", __FUNCTION__);
1147 case SAA7134_BOARD_CREATIX_CTX953:
1148 configure_tda827x_fe(dev, &md8800_dvbt_config);
1150 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1151 configure_tda827x_fe(dev, &philips_tiger_s_config);
1153 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1154 dev->dvb.frontend = dvb_attach(mt352_attach,
1155 &avermedia_e506r_mt352_dev,
1159 case SAA7134_BOARD_MD7134_BRIDGE_2:
1160 dev->dvb.frontend = dvb_attach(tda10086_attach,
1161 &flydvbs, &dev->i2c_adap);
1162 if (dev->dvb.frontend) {
1163 struct dvb_frontend *fe;
1164 if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
1165 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL)
1166 wprintk("%s: MD7134 DVB-S, no SD1878 "
1167 "found !\n", __FUNCTION__);
1168 /* we need to open the i2c gate (we know it exists) */
1169 fe = dev->dvb.frontend;
1170 fe->ops.i2c_gate_ctrl(fe, 1);
1171 if (dvb_attach(isl6405_attach, fe,
1172 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1173 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1174 "found !\n", __FUNCTION__);
1175 fe->ops.i2c_gate_ctrl(fe, 0);
1176 dev->original_set_voltage = fe->ops.set_voltage;
1177 fe->ops.set_voltage = md8800_set_voltage;
1178 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1179 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1183 wprintk("Huh? unknown DVB card?\n");
1187 if (attach_xc3028) {
1188 struct dvb_frontend *fe;
1189 struct xc2028_config cfg = {
1190 .i2c_adap = &dev->i2c_adap,
1192 .video_dev = dev->i2c_adap.algo_data,
1194 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1196 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1198 dvb_frontend_detach(dev->dvb.frontend);
1199 dvb_unregister_frontend(dev->dvb.frontend);
1200 dev->dvb.frontend = NULL;
1205 if (NULL == dev->dvb.frontend) {
1206 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1210 /* register everything else */
1211 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1213 /* this sequence is necessary to make the tda1004x load its firmware
1214 * and to enter analog mode of hybrid boards
1217 if (dev->dvb.frontend->ops.init)
1218 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1219 if (dev->dvb.frontend->ops.sleep)
1220 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1221 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1222 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1227 static int dvb_fini(struct saa7134_dev *dev)
1229 /* FIXME: I suspect that this code is bogus, since the entry for
1230 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1231 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1233 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1234 struct v4l2_priv_tun_config tda9887_cfg;
1235 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1237 tda9887_cfg.tuner = TUNER_TDA9887;
1238 tda9887_cfg.priv = &on;
1240 /* otherwise we don't detect the tuner on next insmod */
1241 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1244 videobuf_dvb_unregister(&dev->dvb);
1248 static struct saa7134_mpeg_ops dvb_ops = {
1249 .type = SAA7134_MPEG_DVB,
1254 static int __init dvb_register(void)
1256 return saa7134_ts_register(&dvb_ops);
1259 static void __exit dvb_unregister(void)
1261 saa7134_ts_unregister(&dvb_ops);
1264 module_init(dvb_register);
1265 module_exit(dvb_unregister);
1267 /* ------------------------------------------------------------------ */