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 */
47 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48 MODULE_LICENSE("GPL");
50 static unsigned int antenna_pwr = 0;
52 module_param(antenna_pwr, int, 0444);
53 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
55 static int use_frontend = 0;
56 module_param(use_frontend, int, 0644);
57 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
60 module_param(debug, int, 0644);
61 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
63 #define dprintk(fmt, arg...) if (debug) \
64 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg)
66 /* ------------------------------------------------------------------
67 * mt352 based DVB-T cards
70 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
75 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
76 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
80 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
81 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
84 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
85 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
87 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
89 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
90 printk("%s: %s %s\n", dev->name, __FUNCTION__,
94 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
98 static int mt352_pinnacle_init(struct dvb_frontend* fe)
100 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
101 static u8 reset [] = { RESET, 0x80 };
102 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
103 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
104 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
105 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
106 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
107 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
108 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
109 struct saa7134_dev *dev= fe->dvb->priv;
111 printk("%s: %s called\n",dev->name,__FUNCTION__);
113 mt352_write(fe, clock_config, sizeof(clock_config));
115 mt352_write(fe, reset, sizeof(reset));
116 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
117 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
118 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
119 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
121 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
122 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
123 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
128 static int mt352_aver777_init(struct dvb_frontend* fe)
130 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
131 static u8 reset [] = { RESET, 0x80 };
132 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
133 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
134 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
136 mt352_write(fe, clock_config, sizeof(clock_config));
138 mt352_write(fe, reset, sizeof(reset));
139 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
140 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
141 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
146 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
147 struct dvb_frontend_parameters* params)
149 u8 off[] = { 0x00, 0xf1};
150 u8 on[] = { 0x00, 0x71};
151 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
153 struct saa7134_dev *dev = fe->dvb->priv;
154 struct v4l2_frequency f;
156 /* set frequency (mt2050) */
158 f.type = V4L2_TUNER_DIGITAL_TV;
159 f.frequency = params->frequency / 1000 * 16 / 1000;
160 if (fe->ops.i2c_gate_ctrl)
161 fe->ops.i2c_gate_ctrl(fe, 1);
162 i2c_transfer(&dev->i2c_adap, &msg, 1);
163 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
165 if (fe->ops.i2c_gate_ctrl)
166 fe->ops.i2c_gate_ctrl(fe, 1);
167 i2c_transfer(&dev->i2c_adap, &msg, 1);
169 pinnacle_antenna_pwr(dev, antenna_pwr);
172 return mt352_pinnacle_init(fe);
175 static int mt352_aver777_tuner_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
181 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
183 params->u.ofdm.bandwidth);
187 static struct mt352_config pinnacle_300i = {
188 .demod_address = 0x3c >> 1,
192 .demod_init = mt352_pinnacle_init,
195 static struct mt352_config avermedia_777 = {
196 .demod_address = 0xf,
197 .demod_init = mt352_aver777_init,
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 printk("%s/dvb: could not write to tuner at addr: 0x%02x\n",dev->name, addr << 1);
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 int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
445 struct saa7134_dev *dev = fe->dvb->priv;
446 struct tda1004x_state *state = fe->demodulator_priv;
447 u8 addr = state->config->tuner_address;
448 /* this message is to set up ATC and ALC */
449 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
450 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
452 if (fe->ops.i2c_gate_ctrl)
453 fe->ops.i2c_gate_ctrl(fe, 1);
454 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
461 static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
463 struct saa7134_dev *dev = fe->dvb->priv;
464 struct tda1004x_state *state = fe->demodulator_priv;
465 u8 addr = state->config->tuner_address;
466 /* this message actually turns the tuner back to analog mode */
467 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
468 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
470 if (fe->ops.i2c_gate_ctrl)
471 fe->ops.i2c_gate_ctrl(fe, 1);
472 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
474 fmd1216_init[2] = 0x86;
475 fmd1216_init[3] = 0x54;
476 if (fe->ops.i2c_gate_ctrl)
477 fe->ops.i2c_gate_ctrl(fe, 1);
478 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
483 static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
485 struct saa7134_dev *dev = fe->dvb->priv;
486 struct tda1004x_state *state = fe->demodulator_priv;
487 u8 addr = state->config->tuner_address;
489 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
491 int tuner_frequency = 0;
495 /* determine charge pump */
496 tuner_frequency = params->frequency + 36130000;
497 if (tuner_frequency < 87000000)
500 else if (tuner_frequency < 180000000) {
504 } else if (tuner_frequency < 195000000) {
509 } else if (tuner_frequency < 366000000) {
510 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
517 } else if (tuner_frequency < 478000000) {
518 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
526 } else if (tuner_frequency < 662000000) {
527 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
534 } else if (tuner_frequency < 840000000) {
535 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
543 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
552 /* calculate divisor */
553 /* ((36166000 + Finput) / 166666) rounded! */
554 divider = (tuner_frequency + 83333) / 166667;
556 /* setup tuner buffer */
557 tuner_buf[0] = (divider >> 8) & 0x7f;
558 tuner_buf[1] = divider & 0xff;
559 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
560 tuner_buf[3] = 0x40 | band;
562 if (fe->ops.i2c_gate_ctrl)
563 fe->ops.i2c_gate_ctrl(fe, 1);
564 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
565 printk("%s/dvb: could not write to tuner at addr: 0x%02x\n",dev->name, addr << 1);
571 static struct tda1004x_config medion_cardbus = {
572 .demod_address = 0x08,
575 .xtal_freq = TDA10046_XTAL_16M,
576 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
577 .if_freq = TDA10046_FREQ_3613,
578 .tuner_address = 0x61,
579 .request_firmware = philips_tda1004x_request_firmware
582 /* ------------------------------------------------------------------
583 * tda 1004x based cards with philips silicon tuner
586 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
588 struct saa7134_dev *dev = fe->dvb->priv;
589 struct tda1004x_state *state = fe->demodulator_priv;
590 u8 addr = state->config->i2c_gate;
591 u8 config = state->config->tuner_config;
592 u8 GP00_CF[] = {0x20, 0x01};
593 u8 GP00_LEV[] = {0x22, 0x00};
595 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
598 dprintk("setting LNA to high gain\n");
600 dprintk("setting LNA to low gain\n");
606 case 1: /* switch is GPIO 0 of tda8290 */
609 saa7134_set_gpio(dev, 22, 0);
610 GP00_LEV[1] = high ? 0 : 1;
611 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
612 printk("%s/dvb: could not access tda8290 at addr: 0x%02x\n",dev->name, addr << 1);
617 GP00_LEV[1] = high ? 1 : 0;
618 i2c_transfer(&dev->i2c_adap, &msg, 1);
620 case 3: /* switch with GPIO of saa713x */
621 saa7134_set_gpio(dev, 22, high);
626 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
628 struct tda1004x_state *state = fe->demodulator_priv;
630 u8 addr = state->config->i2c_gate;
631 static u8 tda8290_close[] = { 0x21, 0xc0};
632 static u8 tda8290_open[] = { 0x21, 0x80};
633 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
635 tda8290_msg.buf = tda8290_close;
637 tda8290_msg.buf = tda8290_open;
639 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
640 printk("saa7134/dvb: could not access tda8290 I2C gate\n");
647 /* ------------------------------------------------------------------ */
649 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
651 struct saa7134_dev *dev = fe->dvb->priv;
652 struct tda1004x_state *state = fe->demodulator_priv;
654 switch (state->config->antenna_switch) {
656 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
657 saa7134_set_gpio(dev, 21, 0);
659 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
660 saa7134_set_gpio(dev, 21, 1);
666 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
668 struct saa7134_dev *dev = fe->dvb->priv;
669 struct tda1004x_state *state = fe->demodulator_priv;
671 switch (state->config->antenna_switch) {
673 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
674 saa7134_set_gpio(dev, 21, 1);
676 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
677 saa7134_set_gpio(dev, 21, 0);
683 static struct tda827x_config tda827x_cfg = {
684 .lna_gain = philips_tda827x_lna_gain,
685 .init = philips_tda827x_tuner_init,
686 .sleep = philips_tda827x_tuner_sleep
689 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
691 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
692 if (dev->dvb.frontend) {
693 if (tda_conf->i2c_gate)
694 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
695 dvb_attach(tda827x_attach,dev->dvb.frontend,
696 tda_conf->tuner_address,&dev->i2c_adap,&tda827x_cfg);
700 /* ------------------------------------------------------------------ */
701 static struct tda1004x_config tda827x_lifeview_config = {
702 .demod_address = 0x08,
705 .xtal_freq = TDA10046_XTAL_16M,
706 .agc_config = TDA10046_AGC_TDA827X,
707 .gpio_config = TDA10046_GP11_I,
708 .if_freq = TDA10046_FREQ_045,
709 .tuner_address = 0x60,
710 .request_firmware = philips_tda1004x_request_firmware
713 static struct tda1004x_config philips_tiger_config = {
714 .demod_address = 0x08,
717 .xtal_freq = TDA10046_XTAL_16M,
718 .agc_config = TDA10046_AGC_TDA827X,
719 .gpio_config = TDA10046_GP11_I,
720 .if_freq = TDA10046_FREQ_045,
722 .tuner_address = 0x61,
725 .request_firmware = philips_tda1004x_request_firmware
728 static struct tda1004x_config cinergy_ht_config = {
729 .demod_address = 0x08,
732 .xtal_freq = TDA10046_XTAL_16M,
733 .agc_config = TDA10046_AGC_TDA827X,
734 .gpio_config = TDA10046_GP01_I,
735 .if_freq = TDA10046_FREQ_045,
737 .tuner_address = 0x61,
739 .request_firmware = philips_tda1004x_request_firmware
742 static struct tda1004x_config cinergy_ht_pci_config = {
743 .demod_address = 0x08,
746 .xtal_freq = TDA10046_XTAL_16M,
747 .agc_config = TDA10046_AGC_TDA827X,
748 .gpio_config = TDA10046_GP01_I,
749 .if_freq = TDA10046_FREQ_045,
751 .tuner_address = 0x60,
753 .request_firmware = philips_tda1004x_request_firmware
756 static struct tda1004x_config philips_tiger_s_config = {
757 .demod_address = 0x08,
760 .xtal_freq = TDA10046_XTAL_16M,
761 .agc_config = TDA10046_AGC_TDA827X,
762 .gpio_config = TDA10046_GP01_I,
763 .if_freq = TDA10046_FREQ_045,
765 .tuner_address = 0x61,
768 .request_firmware = philips_tda1004x_request_firmware
771 static struct tda1004x_config pinnacle_pctv_310i_config = {
772 .demod_address = 0x08,
775 .xtal_freq = TDA10046_XTAL_16M,
776 .agc_config = TDA10046_AGC_TDA827X,
777 .gpio_config = TDA10046_GP11_I,
778 .if_freq = TDA10046_FREQ_045,
780 .tuner_address = 0x61,
782 .request_firmware = philips_tda1004x_request_firmware
785 static struct tda1004x_config hauppauge_hvr_1110_config = {
786 .demod_address = 0x08,
789 .xtal_freq = TDA10046_XTAL_16M,
790 .agc_config = TDA10046_AGC_TDA827X,
791 .gpio_config = TDA10046_GP11_I,
792 .if_freq = TDA10046_FREQ_045,
794 .tuner_address = 0x61,
795 .request_firmware = philips_tda1004x_request_firmware
798 static struct tda1004x_config asus_p7131_dual_config = {
799 .demod_address = 0x08,
802 .xtal_freq = TDA10046_XTAL_16M,
803 .agc_config = TDA10046_AGC_TDA827X,
804 .gpio_config = TDA10046_GP11_I,
805 .if_freq = TDA10046_FREQ_045,
807 .tuner_address = 0x61,
810 .request_firmware = philips_tda1004x_request_firmware
813 static struct tda1004x_config lifeview_trio_config = {
814 .demod_address = 0x09,
817 .xtal_freq = TDA10046_XTAL_16M,
818 .agc_config = TDA10046_AGC_TDA827X,
819 .gpio_config = TDA10046_GP00_I,
820 .if_freq = TDA10046_FREQ_045,
821 .tuner_address = 0x60,
822 .request_firmware = philips_tda1004x_request_firmware
825 static struct tda1004x_config tevion_dvbt220rf_config = {
826 .demod_address = 0x08,
829 .xtal_freq = TDA10046_XTAL_16M,
830 .agc_config = TDA10046_AGC_TDA827X,
831 .gpio_config = TDA10046_GP11_I,
832 .if_freq = TDA10046_FREQ_045,
833 .tuner_address = 0x60,
834 .request_firmware = philips_tda1004x_request_firmware
837 static struct tda1004x_config md8800_dvbt_config = {
838 .demod_address = 0x08,
841 .xtal_freq = TDA10046_XTAL_16M,
842 .agc_config = TDA10046_AGC_TDA827X,
843 .gpio_config = TDA10046_GP01_I,
844 .if_freq = TDA10046_FREQ_045,
846 .tuner_address = 0x60,
848 .request_firmware = philips_tda1004x_request_firmware
851 /* ------------------------------------------------------------------
852 * special case: this card uses saa713x GPIO22 for the mode switch
855 static int ads_duo_tuner_init(struct dvb_frontend *fe)
857 struct saa7134_dev *dev = fe->dvb->priv;
858 philips_tda827x_tuner_init(fe);
859 /* route TDA8275a AGC input to the channel decoder */
860 saa7134_set_gpio(dev, 22, 1);
864 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
866 struct saa7134_dev *dev = fe->dvb->priv;
867 /* route TDA8275a AGC input to the analog IF chip*/
868 saa7134_set_gpio(dev, 22, 0);
869 philips_tda827x_tuner_sleep(fe);
873 static struct tda827x_config ads_duo_cfg = {
874 .lna_gain = philips_tda827x_lna_gain,
875 .init = ads_duo_tuner_init,
876 .sleep = ads_duo_tuner_sleep
879 static struct tda1004x_config ads_tech_duo_config = {
880 .demod_address = 0x08,
883 .xtal_freq = TDA10046_XTAL_16M,
884 .agc_config = TDA10046_AGC_TDA827X,
885 .gpio_config = TDA10046_GP00_I,
886 .if_freq = TDA10046_FREQ_045,
887 .tuner_address = 0x61,
888 .request_firmware = philips_tda1004x_request_firmware
891 /* ==================================================================
892 * tda10086 based DVB-S cards, helper functions
895 static struct tda10086_config flydvbs = {
896 .demod_address = 0x0e,
900 /* ==================================================================
901 * nxt200x based ATSC cards, helper functions
904 static struct nxt200x_config avertvhda180 = {
905 .demod_address = 0x0a,
908 static int nxt200x_set_pll_input(u8 *buf, int input)
917 static struct nxt200x_config kworldatsc110 = {
918 .demod_address = 0x0a,
919 .set_pll_input = nxt200x_set_pll_input,
922 /* ==================================================================
926 static int dvb_init(struct saa7134_dev *dev)
929 /* init struct videobuf_dvb */
930 dev->ts.nr_bufs = 32;
931 dev->ts.nr_packets = 32*4;
932 dev->dvb.name = dev->name;
933 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
934 dev->pci, &dev->slock,
935 V4L2_BUF_TYPE_VIDEO_CAPTURE,
936 V4L2_FIELD_ALTERNATE,
937 sizeof(struct saa7134_buf),
940 switch (dev->board) {
941 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
942 printk("%s: pinnacle 300i dvb setup\n",dev->name);
943 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
945 if (dev->dvb.frontend) {
946 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
949 case SAA7134_BOARD_AVERMEDIA_777:
950 case SAA7134_BOARD_AVERMEDIA_A16AR:
951 printk("%s: avertv 777 dvb setup\n",dev->name);
952 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
954 if (dev->dvb.frontend) {
955 dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
958 case SAA7134_BOARD_MD7134:
959 dev->dvb.frontend = dvb_attach(tda10046_attach,
962 if (dev->dvb.frontend) {
963 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
964 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
965 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
968 case SAA7134_BOARD_PHILIPS_TOUGH:
969 dev->dvb.frontend = dvb_attach(tda10046_attach,
970 &philips_tu1216_60_config,
972 if (dev->dvb.frontend) {
973 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
974 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
977 case SAA7134_BOARD_FLYDVBTDUO:
978 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
979 configure_tda827x_fe(dev, &tda827x_lifeview_config);
981 case SAA7134_BOARD_PHILIPS_EUROPA:
982 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
983 dev->dvb.frontend = dvb_attach(tda10046_attach,
984 &philips_europa_config,
986 if (dev->dvb.frontend) {
987 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
988 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
989 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
990 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
991 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
994 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
995 dev->dvb.frontend = dvb_attach(tda10046_attach,
996 &philips_tu1216_61_config,
998 if (dev->dvb.frontend) {
999 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1000 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1003 case SAA7134_BOARD_PHILIPS_TIGER:
1004 configure_tda827x_fe(dev, &philips_tiger_config);
1006 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1007 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
1009 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1010 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
1012 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1013 configure_tda827x_fe(dev, &asus_p7131_dual_config);
1015 case SAA7134_BOARD_FLYDVBT_LR301:
1016 configure_tda827x_fe(dev, &tda827x_lifeview_config);
1018 case SAA7134_BOARD_FLYDVB_TRIO:
1019 if(! use_frontend) { //terrestrial
1020 configure_tda827x_fe(dev, &lifeview_trio_config);
1021 } else { //satellite
1022 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1023 if (dev->dvb.frontend) {
1024 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1025 &dev->i2c_adap, 0) == NULL) {
1026 printk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1028 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1029 0x08, 0, 0) == NULL) {
1030 printk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1035 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1036 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1037 dev->dvb.frontend = dvb_attach(tda10046_attach,
1038 &ads_tech_duo_config,
1040 if (dev->dvb.frontend) {
1041 dvb_attach(tda827x_attach,dev->dvb.frontend,
1042 ads_tech_duo_config.tuner_address,
1043 &dev->i2c_adap,&ads_duo_cfg);
1046 case SAA7134_BOARD_TEVION_DVBT_220RF:
1047 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1049 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1050 configure_tda827x_fe(dev, &md8800_dvbt_config);
1052 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1053 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1055 if (dev->dvb.frontend) {
1056 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1057 NULL, &dvb_pll_tdhu2);
1060 case SAA7134_BOARD_KWORLD_ATSC110:
1061 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1063 if (dev->dvb.frontend) {
1064 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1065 NULL, &dvb_pll_tuv1236d);
1068 case SAA7134_BOARD_FLYDVBS_LR300:
1069 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1071 if (dev->dvb.frontend) {
1072 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1073 &dev->i2c_adap, 0) == NULL) {
1074 printk("%s: No tda826x found!\n", __FUNCTION__);
1076 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1077 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1078 printk("%s: No ISL6421 found!\n", __FUNCTION__);
1082 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1083 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1085 if (dev->dvb.frontend) {
1086 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1087 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1088 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1089 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1090 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1093 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1094 dev->dvb.frontend = dvb_attach(tda10046_attach,
1095 &philips_europa_config,
1097 if (dev->dvb.frontend) {
1098 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1099 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1102 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1103 configure_tda827x_fe(dev, &cinergy_ht_config);
1105 case SAA7134_BOARD_CINERGY_HT_PCI:
1106 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1108 case SAA7134_BOARD_PHILIPS_TIGER_S:
1109 configure_tda827x_fe(dev, &philips_tiger_s_config);
1112 printk("%s: Huh? unknown DVB card?\n",dev->name);
1116 if (NULL == dev->dvb.frontend) {
1117 printk("%s: frontend initialization failed\n",dev->name);
1121 /* register everything else */
1122 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1124 /* this sequence is necessary to make the tda1004x load its firmware
1125 * and to enter analog mode of hybrid boards
1128 if (dev->dvb.frontend->ops.init)
1129 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1130 if (dev->dvb.frontend->ops.sleep)
1131 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1136 static int dvb_fini(struct saa7134_dev *dev)
1138 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1140 switch (dev->board) {
1141 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1142 /* otherwise we don't detect the tuner on next insmod */
1143 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1146 videobuf_dvb_unregister(&dev->dvb);
1150 static struct saa7134_mpeg_ops dvb_ops = {
1151 .type = SAA7134_MPEG_DVB,
1156 static int __init dvb_register(void)
1158 return saa7134_ts_register(&dvb_ops);
1161 static void __exit dvb_unregister(void)
1163 saa7134_ts_unregister(&dvb_ops);
1166 module_init(dvb_register);
1167 module_exit(dvb_unregister);
1169 /* ------------------------------------------------------------------ */