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 static void philips_tda1004x_set_board_name(struct dvb_frontend *fe, char *name)
215 len = sizeof(fe->ops.info.name);
216 strncpy(fe->ops.info.name, name, len);
217 fe->ops.info.name[len - 1] = 0;
220 /* ------------------------------------------------------------------
221 * these tuners are tu1216, td1316(a)
224 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
226 struct saa7134_dev *dev = fe->dvb->priv;
227 struct tda1004x_state *state = fe->demodulator_priv;
228 u8 addr = state->config->tuner_address;
230 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
232 int tuner_frequency = 0;
235 /* determine charge pump */
236 tuner_frequency = params->frequency + 36166000;
237 if (tuner_frequency < 87000000)
239 else if (tuner_frequency < 130000000)
241 else if (tuner_frequency < 160000000)
243 else if (tuner_frequency < 200000000)
245 else if (tuner_frequency < 290000000)
247 else if (tuner_frequency < 420000000)
249 else if (tuner_frequency < 480000000)
251 else if (tuner_frequency < 620000000)
253 else if (tuner_frequency < 830000000)
255 else if (tuner_frequency < 895000000)
261 if (params->frequency < 49000000)
263 else if (params->frequency < 161000000)
265 else if (params->frequency < 444000000)
267 else if (params->frequency < 861000000)
272 /* setup PLL filter */
273 switch (params->u.ofdm.bandwidth) {
274 case BANDWIDTH_6_MHZ:
278 case BANDWIDTH_7_MHZ:
282 case BANDWIDTH_8_MHZ:
291 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
293 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
295 /* setup tuner buffer */
296 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
297 tuner_buf[1] = tuner_frequency & 0xff;
299 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
301 if (fe->ops.i2c_gate_ctrl)
302 fe->ops.i2c_gate_ctrl(fe, 1);
303 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
304 printk("%s/dvb: could not write to tuner at addr: 0x%02x\n",dev->name, addr << 1);
311 static int philips_tu1216_init(struct dvb_frontend *fe)
313 struct saa7134_dev *dev = fe->dvb->priv;
314 struct tda1004x_state *state = fe->demodulator_priv;
315 u8 addr = state->config->tuner_address;
316 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
317 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
319 /* setup PLL configuration */
320 if (fe->ops.i2c_gate_ctrl)
321 fe->ops.i2c_gate_ctrl(fe, 1);
322 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
329 /* ------------------------------------------------------------------ */
331 static struct tda1004x_config philips_tu1216_60_config = {
332 .demod_address = 0x8,
335 .xtal_freq = TDA10046_XTAL_4M,
336 .agc_config = TDA10046_AGC_DEFAULT,
337 .if_freq = TDA10046_FREQ_3617,
338 .tuner_address = 0x60,
339 .request_firmware = philips_tda1004x_request_firmware
342 static struct tda1004x_config philips_tu1216_61_config = {
344 .demod_address = 0x8,
347 .xtal_freq = TDA10046_XTAL_4M,
348 .agc_config = TDA10046_AGC_DEFAULT,
349 .if_freq = TDA10046_FREQ_3617,
350 .tuner_address = 0x61,
351 .request_firmware = philips_tda1004x_request_firmware
354 /* ------------------------------------------------------------------ */
356 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
358 struct saa7134_dev *dev = fe->dvb->priv;
359 struct tda1004x_state *state = fe->demodulator_priv;
360 u8 addr = state->config->tuner_address;
361 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
362 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
364 /* setup PLL configuration */
365 if (fe->ops.i2c_gate_ctrl)
366 fe->ops.i2c_gate_ctrl(fe, 1);
367 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
372 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
374 return philips_tda6651_pll_set(fe, params);
377 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
379 struct saa7134_dev *dev = fe->dvb->priv;
380 struct tda1004x_state *state = fe->demodulator_priv;
381 u8 addr = state->config->tuner_address;
382 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
383 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
385 /* switch the tuner to analog mode */
386 if (fe->ops.i2c_gate_ctrl)
387 fe->ops.i2c_gate_ctrl(fe, 1);
388 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
393 /* ------------------------------------------------------------------ */
395 static int philips_europa_tuner_init(struct dvb_frontend *fe)
397 struct saa7134_dev *dev = fe->dvb->priv;
398 static u8 msg[] = { 0x00, 0x40};
399 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
402 if (philips_td1316_tuner_init(fe))
405 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
411 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
413 struct saa7134_dev *dev = fe->dvb->priv;
415 static u8 msg[] = { 0x00, 0x14 };
416 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
418 if (philips_td1316_tuner_sleep(fe))
421 /* switch the board to analog mode */
422 if (fe->ops.i2c_gate_ctrl)
423 fe->ops.i2c_gate_ctrl(fe, 1);
424 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
428 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
430 struct saa7134_dev *dev = fe->dvb->priv;
432 if (dev->original_demod_sleep)
433 dev->original_demod_sleep(fe);
434 fe->ops.i2c_gate_ctrl(fe, 1);
438 static struct tda1004x_config philips_europa_config = {
440 .demod_address = 0x8,
443 .xtal_freq = TDA10046_XTAL_4M,
444 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
445 .if_freq = TDA10046_FREQ_052,
446 .tuner_address = 0x61,
447 .request_firmware = philips_tda1004x_request_firmware
450 /* ------------------------------------------------------------------ */
452 static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
454 struct saa7134_dev *dev = fe->dvb->priv;
455 struct tda1004x_state *state = fe->demodulator_priv;
456 u8 addr = state->config->tuner_address;
457 /* this message is to set up ATC and ALC */
458 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
459 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
461 if (fe->ops.i2c_gate_ctrl)
462 fe->ops.i2c_gate_ctrl(fe, 1);
463 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
470 static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
472 struct saa7134_dev *dev = fe->dvb->priv;
473 struct tda1004x_state *state = fe->demodulator_priv;
474 u8 addr = state->config->tuner_address;
475 /* this message actually turns the tuner back to analog mode */
476 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
477 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
479 if (fe->ops.i2c_gate_ctrl)
480 fe->ops.i2c_gate_ctrl(fe, 1);
481 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
483 fmd1216_init[2] = 0x86;
484 fmd1216_init[3] = 0x54;
485 if (fe->ops.i2c_gate_ctrl)
486 fe->ops.i2c_gate_ctrl(fe, 1);
487 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
492 static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
494 struct saa7134_dev *dev = fe->dvb->priv;
495 struct tda1004x_state *state = fe->demodulator_priv;
496 u8 addr = state->config->tuner_address;
498 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
500 int tuner_frequency = 0;
504 /* determine charge pump */
505 tuner_frequency = params->frequency + 36130000;
506 if (tuner_frequency < 87000000)
509 else if (tuner_frequency < 180000000) {
513 } else if (tuner_frequency < 195000000) {
518 } else if (tuner_frequency < 366000000) {
519 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
526 } else if (tuner_frequency < 478000000) {
527 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
535 } else if (tuner_frequency < 662000000) {
536 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
543 } else if (tuner_frequency < 840000000) {
544 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
552 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
561 /* calculate divisor */
562 /* ((36166000 + Finput) / 166666) rounded! */
563 divider = (tuner_frequency + 83333) / 166667;
565 /* setup tuner buffer */
566 tuner_buf[0] = (divider >> 8) & 0x7f;
567 tuner_buf[1] = divider & 0xff;
568 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
569 tuner_buf[3] = 0x40 | band;
571 if (fe->ops.i2c_gate_ctrl)
572 fe->ops.i2c_gate_ctrl(fe, 1);
573 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
574 printk("%s/dvb: could not write to tuner at addr: 0x%02x\n",dev->name, addr << 1);
580 static struct tda1004x_config medion_cardbus = {
581 .demod_address = 0x08,
584 .xtal_freq = TDA10046_XTAL_16M,
585 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
586 .if_freq = TDA10046_FREQ_3613,
587 .tuner_address = 0x61,
588 .request_firmware = philips_tda1004x_request_firmware
591 /* ------------------------------------------------------------------
592 * tda 1004x based cards with philips silicon tuner
595 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
597 struct saa7134_dev *dev = fe->dvb->priv;
598 struct tda1004x_state *state = fe->demodulator_priv;
599 u8 addr = state->config->i2c_gate;
600 u8 config = state->config->tuner_config;
601 u8 GP00_CF[] = {0x20, 0x01};
602 u8 GP00_LEV[] = {0x22, 0x00};
604 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
607 dprintk("setting LNA to high gain\n");
609 dprintk("setting LNA to low gain\n");
615 case 1: /* switch is GPIO 0 of tda8290 */
618 saa7134_set_gpio(dev, 22, 0);
619 GP00_LEV[1] = high ? 0 : 1;
620 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
621 printk("%s/dvb: could not access tda8290 at addr: 0x%02x\n",dev->name, addr << 1);
626 GP00_LEV[1] = high ? 1 : 0;
627 i2c_transfer(&dev->i2c_adap, &msg, 1);
629 case 3: /* switch with GPIO of saa713x */
630 saa7134_set_gpio(dev, 22, high);
635 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
637 struct tda1004x_state *state = fe->demodulator_priv;
639 u8 addr = state->config->i2c_gate;
640 static u8 tda8290_close[] = { 0x21, 0xc0};
641 static u8 tda8290_open[] = { 0x21, 0x80};
642 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
644 tda8290_msg.buf = tda8290_close;
646 tda8290_msg.buf = tda8290_open;
648 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
649 printk("saa7134/dvb: could not access tda8290 I2C gate\n");
656 /* ------------------------------------------------------------------ */
658 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
660 struct saa7134_dev *dev = fe->dvb->priv;
661 struct tda1004x_state *state = fe->demodulator_priv;
663 switch (state->config->antenna_switch) {
665 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
666 saa7134_set_gpio(dev, 21, 0);
668 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
669 saa7134_set_gpio(dev, 21, 1);
675 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
677 struct saa7134_dev *dev = fe->dvb->priv;
678 struct tda1004x_state *state = fe->demodulator_priv;
680 switch (state->config->antenna_switch) {
682 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
683 saa7134_set_gpio(dev, 21, 1);
685 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
686 saa7134_set_gpio(dev, 21, 0);
692 static struct tda827x_config tda827x_cfg = {
693 .lna_gain = philips_tda827x_lna_gain,
694 .init = philips_tda827x_tuner_init,
695 .sleep = philips_tda827x_tuner_sleep
698 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf,
701 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
702 if (dev->dvb.frontend) {
703 if (tda_conf->i2c_gate)
704 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
705 dvb_attach(tda827x_attach,dev->dvb.frontend,
706 tda_conf->tuner_address,&dev->i2c_adap,&tda827x_cfg);
708 philips_tda1004x_set_board_name(dev->dvb.frontend, board_name);
711 /* ------------------------------------------------------------------ */
712 static struct tda1004x_config tda827x_lifeview_config = {
713 .demod_address = 0x08,
716 .xtal_freq = TDA10046_XTAL_16M,
717 .agc_config = TDA10046_AGC_TDA827X,
718 .gpio_config = TDA10046_GP11_I,
719 .if_freq = TDA10046_FREQ_045,
720 .tuner_address = 0x60,
721 .request_firmware = philips_tda1004x_request_firmware
724 static struct tda1004x_config philips_tiger_config = {
725 .demod_address = 0x08,
728 .xtal_freq = TDA10046_XTAL_16M,
729 .agc_config = TDA10046_AGC_TDA827X,
730 .gpio_config = TDA10046_GP11_I,
731 .if_freq = TDA10046_FREQ_045,
733 .tuner_address = 0x61,
736 .request_firmware = philips_tda1004x_request_firmware
739 static struct tda1004x_config cinergy_ht_config = {
740 .demod_address = 0x08,
743 .xtal_freq = TDA10046_XTAL_16M,
744 .agc_config = TDA10046_AGC_TDA827X,
745 .gpio_config = TDA10046_GP01_I,
746 .if_freq = TDA10046_FREQ_045,
748 .tuner_address = 0x61,
750 .request_firmware = philips_tda1004x_request_firmware
753 static struct tda1004x_config cinergy_ht_pci_config = {
754 .demod_address = 0x08,
757 .xtal_freq = TDA10046_XTAL_16M,
758 .agc_config = TDA10046_AGC_TDA827X,
759 .gpio_config = TDA10046_GP01_I,
760 .if_freq = TDA10046_FREQ_045,
762 .tuner_address = 0x60,
764 .request_firmware = philips_tda1004x_request_firmware
767 static struct tda1004x_config philips_tiger_s_config = {
768 .demod_address = 0x08,
771 .xtal_freq = TDA10046_XTAL_16M,
772 .agc_config = TDA10046_AGC_TDA827X,
773 .gpio_config = TDA10046_GP01_I,
774 .if_freq = TDA10046_FREQ_045,
776 .tuner_address = 0x61,
779 .request_firmware = philips_tda1004x_request_firmware
782 static struct tda1004x_config pinnacle_pctv_310i_config = {
783 .demod_address = 0x08,
786 .xtal_freq = TDA10046_XTAL_16M,
787 .agc_config = TDA10046_AGC_TDA827X,
788 .gpio_config = TDA10046_GP11_I,
789 .if_freq = TDA10046_FREQ_045,
791 .tuner_address = 0x61,
793 .request_firmware = philips_tda1004x_request_firmware
796 static struct tda1004x_config hauppauge_hvr_1110_config = {
797 .demod_address = 0x08,
800 .xtal_freq = TDA10046_XTAL_16M,
801 .agc_config = TDA10046_AGC_TDA827X,
802 .gpio_config = TDA10046_GP11_I,
803 .if_freq = TDA10046_FREQ_045,
805 .tuner_address = 0x61,
806 .request_firmware = philips_tda1004x_request_firmware
809 static struct tda1004x_config asus_p7131_dual_config = {
810 .demod_address = 0x08,
813 .xtal_freq = TDA10046_XTAL_16M,
814 .agc_config = TDA10046_AGC_TDA827X,
815 .gpio_config = TDA10046_GP11_I,
816 .if_freq = TDA10046_FREQ_045,
818 .tuner_address = 0x61,
821 .request_firmware = philips_tda1004x_request_firmware
824 static struct tda1004x_config lifeview_trio_config = {
825 .demod_address = 0x09,
828 .xtal_freq = TDA10046_XTAL_16M,
829 .agc_config = TDA10046_AGC_TDA827X,
830 .gpio_config = TDA10046_GP00_I,
831 .if_freq = TDA10046_FREQ_045,
832 .tuner_address = 0x60,
833 .request_firmware = philips_tda1004x_request_firmware
836 static struct tda1004x_config tevion_dvbt220rf_config = {
837 .demod_address = 0x08,
840 .xtal_freq = TDA10046_XTAL_16M,
841 .agc_config = TDA10046_AGC_TDA827X,
842 .gpio_config = TDA10046_GP11_I,
843 .if_freq = TDA10046_FREQ_045,
844 .tuner_address = 0x60,
845 .request_firmware = philips_tda1004x_request_firmware
848 static struct tda1004x_config md8800_dvbt_config = {
849 .demod_address = 0x08,
852 .xtal_freq = TDA10046_XTAL_16M,
853 .agc_config = TDA10046_AGC_TDA827X,
854 .gpio_config = TDA10046_GP01_I,
855 .if_freq = TDA10046_FREQ_045,
857 .tuner_address = 0x60,
859 .request_firmware = philips_tda1004x_request_firmware
862 /* ------------------------------------------------------------------
863 * special case: this card uses saa713x GPIO22 for the mode switch
866 static int ads_duo_tuner_init(struct dvb_frontend *fe)
868 struct saa7134_dev *dev = fe->dvb->priv;
869 philips_tda827x_tuner_init(fe);
870 /* route TDA8275a AGC input to the channel decoder */
871 saa7134_set_gpio(dev, 22, 1);
875 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
877 struct saa7134_dev *dev = fe->dvb->priv;
878 /* route TDA8275a AGC input to the analog IF chip*/
879 saa7134_set_gpio(dev, 22, 0);
880 philips_tda827x_tuner_sleep(fe);
884 static struct tda827x_config ads_duo_cfg = {
885 .lna_gain = philips_tda827x_lna_gain,
886 .init = ads_duo_tuner_init,
887 .sleep = ads_duo_tuner_sleep
890 static struct tda1004x_config ads_tech_duo_config = {
891 .demod_address = 0x08,
894 .xtal_freq = TDA10046_XTAL_16M,
895 .agc_config = TDA10046_AGC_TDA827X,
896 .gpio_config = TDA10046_GP00_I,
897 .if_freq = TDA10046_FREQ_045,
898 .tuner_address = 0x61,
899 .request_firmware = philips_tda1004x_request_firmware
902 /* ==================================================================
903 * tda10086 based DVB-S cards, helper functions
906 static struct tda10086_config flydvbs = {
907 .demod_address = 0x0e,
911 /* ==================================================================
912 * nxt200x based ATSC cards, helper functions
915 static struct nxt200x_config avertvhda180 = {
916 .demod_address = 0x0a,
919 static int nxt200x_set_pll_input(u8 *buf, int input)
928 static struct nxt200x_config kworldatsc110 = {
929 .demod_address = 0x0a,
930 .set_pll_input = nxt200x_set_pll_input,
933 /* ==================================================================
937 static int dvb_init(struct saa7134_dev *dev)
941 /* init struct videobuf_dvb */
942 dev->ts.nr_bufs = 32;
943 dev->ts.nr_packets = 32*4;
944 dev->dvb.name = dev->name;
945 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
946 dev->pci, &dev->slock,
947 V4L2_BUF_TYPE_VIDEO_CAPTURE,
948 V4L2_FIELD_ALTERNATE,
949 sizeof(struct saa7134_buf),
952 switch (dev->board) {
953 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
954 printk("%s: pinnacle 300i dvb setup\n",dev->name);
955 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
957 if (dev->dvb.frontend) {
958 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
961 case SAA7134_BOARD_AVERMEDIA_777:
962 case SAA7134_BOARD_AVERMEDIA_A16AR:
963 printk("%s: avertv 777 dvb setup\n",dev->name);
964 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
966 if (dev->dvb.frontend) {
967 dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
970 case SAA7134_BOARD_MD7134:
971 dev->dvb.frontend = dvb_attach(tda10046_attach,
974 if (dev->dvb.frontend) {
975 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
976 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
977 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
978 philips_tda1004x_set_board_name(dev->dvb.frontend, "DVB-T Medion MD7134");
981 case SAA7134_BOARD_PHILIPS_TOUGH:
982 dev->dvb.frontend = dvb_attach(tda10046_attach,
983 &philips_tu1216_60_config,
985 if (dev->dvb.frontend) {
986 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
987 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
988 philips_tda1004x_set_board_name(dev->dvb.frontend, "DVB-T Philips TOUGH");
991 case SAA7134_BOARD_FLYDVBTDUO:
992 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
993 configure_tda827x_fe(dev, &tda827x_lifeview_config, "DVB-T Lifeview FlyDVB Duo");
995 case SAA7134_BOARD_PHILIPS_EUROPA:
996 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
997 dev->dvb.frontend = dvb_attach(tda10046_attach,
998 &philips_europa_config,
1000 if (dev->dvb.frontend) {
1001 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1002 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1003 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1004 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1005 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1006 if (dev->board == SAA7134_BOARD_VIDEOMATE_DVBT_300)
1007 board_name = "DVB-T Compro VideoMate 300";
1009 board_name = "DVB-T Philips Europa";
1010 philips_tda1004x_set_board_name(dev->dvb.frontend, board_name);
1013 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1014 dev->dvb.frontend = dvb_attach(tda10046_attach,
1015 &philips_tu1216_61_config,
1017 if (dev->dvb.frontend) {
1018 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1019 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1020 philips_tda1004x_set_board_name(dev->dvb.frontend, "DVB-T Compro VideoMate 200");
1023 case SAA7134_BOARD_PHILIPS_TIGER:
1024 configure_tda827x_fe(dev, &philips_tiger_config, "DVB-T Philips Tiger");
1026 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1027 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config, "DVB-T Pinnacle PCTV 310i");
1029 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1030 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config, "DVB-T Hauppauge HVR 1110");
1032 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1033 configure_tda827x_fe(dev, &asus_p7131_dual_config, "DVB-T Asus P7131 Dual");
1035 case SAA7134_BOARD_FLYDVBT_LR301:
1036 configure_tda827x_fe(dev, &tda827x_lifeview_config, "DVB-T Lifeview FlyDVBT LR301");
1038 case SAA7134_BOARD_FLYDVB_TRIO:
1039 if(! use_frontend) { //terrestrial
1040 configure_tda827x_fe(dev, &lifeview_trio_config, NULL);
1041 } else { //satellite
1042 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1043 if (dev->dvb.frontend) {
1044 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1045 &dev->i2c_adap, 0) == NULL) {
1046 printk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1048 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1049 0x08, 0, 0) == NULL) {
1050 printk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1055 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1056 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1057 dev->dvb.frontend = dvb_attach(tda10046_attach,
1058 &ads_tech_duo_config,
1060 if (dev->dvb.frontend) {
1061 dvb_attach(tda827x_attach,dev->dvb.frontend,
1062 ads_tech_duo_config.tuner_address,
1063 &dev->i2c_adap,&ads_duo_cfg);
1064 if (dev->board == SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331)
1065 board_name = "DVB-T ADS DUO Cardbus PTV331";
1067 board_name = "DVB-T Lifeview FlyDVT Cardbus";
1068 philips_tda1004x_set_board_name(dev->dvb.frontend, board_name);
1071 case SAA7134_BOARD_TEVION_DVBT_220RF:
1072 configure_tda827x_fe(dev, &tevion_dvbt220rf_config, "DVB-T Tevion 220RF");
1074 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1075 configure_tda827x_fe(dev, &md8800_dvbt_config, "DVB-T Medion MD8800");
1077 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1078 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1080 if (dev->dvb.frontend) {
1081 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1082 NULL, &dvb_pll_tdhu2);
1085 case SAA7134_BOARD_KWORLD_ATSC110:
1086 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1088 if (dev->dvb.frontend) {
1089 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1090 NULL, &dvb_pll_tuv1236d);
1093 case SAA7134_BOARD_FLYDVBS_LR300:
1094 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1096 if (dev->dvb.frontend) {
1097 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1098 &dev->i2c_adap, 0) == NULL) {
1099 printk("%s: No tda826x found!\n", __FUNCTION__);
1101 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1102 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1103 printk("%s: No ISL6421 found!\n", __FUNCTION__);
1107 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1108 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1110 if (dev->dvb.frontend) {
1111 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1112 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1113 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1114 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1115 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1116 philips_tda1004x_set_board_name(dev->dvb.frontend, "DVBT Asus Europa 2 Hybrid");
1119 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1120 dev->dvb.frontend = dvb_attach(tda10046_attach,
1121 &philips_europa_config,
1123 if (dev->dvb.frontend) {
1124 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1125 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1126 philips_tda1004x_set_board_name(dev->dvb.frontend, "DVBT Compro Videomate 200a");
1129 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1130 configure_tda827x_fe(dev, &cinergy_ht_config, "DVB-T Terratec Cinergy HT Cardbus");
1132 case SAA7134_BOARD_CINERGY_HT_PCI:
1133 configure_tda827x_fe(dev, &cinergy_ht_pci_config, "DVB-T Terratec Cinergy HT PCI");
1135 case SAA7134_BOARD_PHILIPS_TIGER_S:
1136 configure_tda827x_fe(dev, &philips_tiger_s_config, "DVB-T Philips Tiger S");
1139 printk("%s: Huh? unknown DVB card?\n",dev->name);
1143 if (NULL == dev->dvb.frontend) {
1144 printk("%s: frontend initialization failed\n",dev->name);
1148 /* register everything else */
1149 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1151 /* this sequence is necessary to make the tda1004x load its firmware
1152 * and to enter analog mode of hybrid boards
1155 if (dev->dvb.frontend->ops.init)
1156 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1157 if (dev->dvb.frontend->ops.sleep)
1158 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1163 static int dvb_fini(struct saa7134_dev *dev)
1165 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1167 switch (dev->board) {
1168 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1169 /* otherwise we don't detect the tuner on next insmod */
1170 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1173 videobuf_dvb_unregister(&dev->dvb);
1177 static struct saa7134_mpeg_ops dvb_ops = {
1178 .type = SAA7134_MPEG_DVB,
1183 static int __init dvb_register(void)
1185 return saa7134_ts_register(&dvb_ops);
1188 static void __exit dvb_unregister(void)
1190 saa7134_ts_unregister(&dvb_ops);
1193 module_init(dvb_register);
1194 module_exit(dvb_unregister);
1196 /* ------------------------------------------------------------------ */