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 saa7134_dev *dev = fe->dvb->priv;
638 struct tda1004x_state *state = fe->demodulator_priv;
640 u8 addr = state->config->i2c_gate;
641 static u8 tda8290_close[] = { 0x21, 0xc0};
642 static u8 tda8290_open[] = { 0x21, 0x80};
643 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
645 tda8290_msg.buf = tda8290_close;
647 tda8290_msg.buf = tda8290_open;
649 if (i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1) != 1) {
650 printk("%s/dvb: could not access tda8290 I2C gate\n",dev->name);
657 /* ------------------------------------------------------------------ */
659 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
661 struct saa7134_dev *dev = fe->dvb->priv;
662 struct tda1004x_state *state = fe->demodulator_priv;
664 switch (state->config->antenna_switch) {
666 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
667 saa7134_set_gpio(dev, 21, 0);
669 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
670 saa7134_set_gpio(dev, 21, 1);
676 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
678 struct saa7134_dev *dev = fe->dvb->priv;
679 struct tda1004x_state *state = fe->demodulator_priv;
681 switch (state->config->antenna_switch) {
683 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
684 saa7134_set_gpio(dev, 21, 1);
686 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
687 saa7134_set_gpio(dev, 21, 0);
693 static struct tda827x_config tda827x_cfg = {
694 .lna_gain = philips_tda827x_lna_gain,
695 .init = philips_tda827x_tuner_init,
696 .sleep = philips_tda827x_tuner_sleep
699 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf,
702 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
703 if (dev->dvb.frontend) {
704 if (tda_conf->i2c_gate)
705 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
706 dvb_attach(tda827x_attach,dev->dvb.frontend,
707 tda_conf->tuner_address,&dev->i2c_adap,&tda827x_cfg);
709 philips_tda1004x_set_board_name(dev->dvb.frontend, board_name);
712 /* ------------------------------------------------------------------ */
713 static struct tda1004x_config tda827x_lifeview_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,
721 .tuner_address = 0x60,
722 .request_firmware = philips_tda1004x_request_firmware
725 static struct tda1004x_config philips_tiger_config = {
726 .demod_address = 0x08,
729 .xtal_freq = TDA10046_XTAL_16M,
730 .agc_config = TDA10046_AGC_TDA827X,
731 .gpio_config = TDA10046_GP11_I,
732 .if_freq = TDA10046_FREQ_045,
734 .tuner_address = 0x61,
737 .request_firmware = philips_tda1004x_request_firmware
740 static struct tda1004x_config cinergy_ht_config = {
741 .demod_address = 0x08,
744 .xtal_freq = TDA10046_XTAL_16M,
745 .agc_config = TDA10046_AGC_TDA827X,
746 .gpio_config = TDA10046_GP01_I,
747 .if_freq = TDA10046_FREQ_045,
749 .tuner_address = 0x61,
751 .request_firmware = philips_tda1004x_request_firmware
754 static struct tda1004x_config cinergy_ht_pci_config = {
755 .demod_address = 0x08,
758 .xtal_freq = TDA10046_XTAL_16M,
759 .agc_config = TDA10046_AGC_TDA827X,
760 .gpio_config = TDA10046_GP01_I,
761 .if_freq = TDA10046_FREQ_045,
763 .tuner_address = 0x60,
765 .request_firmware = philips_tda1004x_request_firmware
768 static struct tda1004x_config philips_tiger_s_config = {
769 .demod_address = 0x08,
772 .xtal_freq = TDA10046_XTAL_16M,
773 .agc_config = TDA10046_AGC_TDA827X,
774 .gpio_config = TDA10046_GP01_I,
775 .if_freq = TDA10046_FREQ_045,
777 .tuner_address = 0x61,
780 .request_firmware = philips_tda1004x_request_firmware
783 static struct tda1004x_config pinnacle_pctv_310i_config = {
784 .demod_address = 0x08,
787 .xtal_freq = TDA10046_XTAL_16M,
788 .agc_config = TDA10046_AGC_TDA827X,
789 .gpio_config = TDA10046_GP11_I,
790 .if_freq = TDA10046_FREQ_045,
792 .tuner_address = 0x61,
794 .request_firmware = philips_tda1004x_request_firmware
797 static struct tda1004x_config hauppauge_hvr_1110_config = {
798 .demod_address = 0x08,
801 .xtal_freq = TDA10046_XTAL_16M,
802 .agc_config = TDA10046_AGC_TDA827X,
803 .gpio_config = TDA10046_GP11_I,
804 .if_freq = TDA10046_FREQ_045,
806 .tuner_address = 0x61,
807 .request_firmware = philips_tda1004x_request_firmware
810 static struct tda1004x_config asus_p7131_dual_config = {
811 .demod_address = 0x08,
814 .xtal_freq = TDA10046_XTAL_16M,
815 .agc_config = TDA10046_AGC_TDA827X,
816 .gpio_config = TDA10046_GP11_I,
817 .if_freq = TDA10046_FREQ_045,
819 .tuner_address = 0x61,
822 .request_firmware = philips_tda1004x_request_firmware
825 static struct tda1004x_config lifeview_trio_config = {
826 .demod_address = 0x09,
829 .xtal_freq = TDA10046_XTAL_16M,
830 .agc_config = TDA10046_AGC_TDA827X,
831 .gpio_config = TDA10046_GP00_I,
832 .if_freq = TDA10046_FREQ_045,
833 .tuner_address = 0x60,
834 .request_firmware = philips_tda1004x_request_firmware
837 static struct tda1004x_config tevion_dvbt220rf_config = {
838 .demod_address = 0x08,
841 .xtal_freq = TDA10046_XTAL_16M,
842 .agc_config = TDA10046_AGC_TDA827X,
843 .gpio_config = TDA10046_GP11_I,
844 .if_freq = TDA10046_FREQ_045,
845 .tuner_address = 0x60,
846 .request_firmware = philips_tda1004x_request_firmware
849 static struct tda1004x_config md8800_dvbt_config = {
850 .demod_address = 0x08,
853 .xtal_freq = TDA10046_XTAL_16M,
854 .agc_config = TDA10046_AGC_TDA827X,
855 .gpio_config = TDA10046_GP01_I,
856 .if_freq = TDA10046_FREQ_045,
858 .tuner_address = 0x60,
860 .request_firmware = philips_tda1004x_request_firmware
863 /* ------------------------------------------------------------------
864 * special case: this card uses saa713x GPIO22 for the mode switch
867 static int ads_duo_tuner_init(struct dvb_frontend *fe)
869 struct saa7134_dev *dev = fe->dvb->priv;
870 philips_tda827x_tuner_init(fe);
871 /* route TDA8275a AGC input to the channel decoder */
872 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0400000);
876 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
878 struct saa7134_dev *dev = fe->dvb->priv;
879 /* route TDA8275a AGC input to the analog IF chip*/
880 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0400000);
881 philips_tda827x_tuner_sleep(fe);
885 static struct tda827x_config ads_duo_cfg = {
886 .lna_gain = philips_tda827x_lna_gain,
887 .init = ads_duo_tuner_init,
888 .sleep = ads_duo_tuner_sleep
891 static struct tda1004x_config ads_tech_duo_config = {
892 .demod_address = 0x08,
895 .xtal_freq = TDA10046_XTAL_16M,
896 .agc_config = TDA10046_AGC_TDA827X,
897 .gpio_config = TDA10046_GP00_I,
898 .if_freq = TDA10046_FREQ_045,
899 .tuner_address = 0x61,
900 .request_firmware = philips_tda1004x_request_firmware
903 /* ==================================================================
904 * tda10086 based DVB-S cards, helper functions
907 static struct tda10086_config flydvbs = {
908 .demod_address = 0x0e,
912 /* ==================================================================
913 * nxt200x based ATSC cards, helper functions
916 static struct nxt200x_config avertvhda180 = {
917 .demod_address = 0x0a,
920 static int nxt200x_set_pll_input(u8 *buf, int input)
929 static struct nxt200x_config kworldatsc110 = {
930 .demod_address = 0x0a,
931 .set_pll_input = nxt200x_set_pll_input,
934 /* ==================================================================
938 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 P7137 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 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1152 static int dvb_fini(struct saa7134_dev *dev)
1154 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1156 switch (dev->board) {
1157 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1158 /* otherwise we don't detect the tuner on next insmod */
1159 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1162 videobuf_dvb_unregister(&dev->dvb);
1166 static struct saa7134_mpeg_ops dvb_ops = {
1167 .type = SAA7134_MPEG_DVB,
1172 static int __init dvb_register(void)
1174 return saa7134_ts_register(&dvb_ops);
1177 static void __exit dvb_unregister(void)
1179 saa7134_ts_unregister(&dvb_ops);
1182 module_init(dvb_register);
1183 module_exit(dvb_unregister);
1185 /* ------------------------------------------------------------------ */