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 if (dvb_attach(tda827x_attach
, dev
->dvb
.frontend
, tda_conf
->tuner_address
,
696 &dev
->i2c_adap
,&tda827x_cfg
) == NULL
) {
697 printk ("saa7134/dvb: no tda827x tuner found at addr: %02x\n",
698 tda_conf
->tuner_address
);
703 /* ------------------------------------------------------------------ */
704 static struct tda1004x_config tda827x_lifeview_config
= {
705 .demod_address
= 0x08,
708 .xtal_freq
= TDA10046_XTAL_16M
,
709 .agc_config
= TDA10046_AGC_TDA827X
,
710 .gpio_config
= TDA10046_GP11_I
,
711 .if_freq
= TDA10046_FREQ_045
,
712 .tuner_address
= 0x60,
713 .request_firmware
= philips_tda1004x_request_firmware
716 static struct tda1004x_config philips_tiger_config
= {
717 .demod_address
= 0x08,
720 .xtal_freq
= TDA10046_XTAL_16M
,
721 .agc_config
= TDA10046_AGC_TDA827X
,
722 .gpio_config
= TDA10046_GP11_I
,
723 .if_freq
= TDA10046_FREQ_045
,
725 .tuner_address
= 0x61,
728 .request_firmware
= philips_tda1004x_request_firmware
731 static struct tda1004x_config cinergy_ht_config
= {
732 .demod_address
= 0x08,
735 .xtal_freq
= TDA10046_XTAL_16M
,
736 .agc_config
= TDA10046_AGC_TDA827X
,
737 .gpio_config
= TDA10046_GP01_I
,
738 .if_freq
= TDA10046_FREQ_045
,
740 .tuner_address
= 0x61,
742 .request_firmware
= philips_tda1004x_request_firmware
745 static struct tda1004x_config cinergy_ht_pci_config
= {
746 .demod_address
= 0x08,
749 .xtal_freq
= TDA10046_XTAL_16M
,
750 .agc_config
= TDA10046_AGC_TDA827X
,
751 .gpio_config
= TDA10046_GP01_I
,
752 .if_freq
= TDA10046_FREQ_045
,
754 .tuner_address
= 0x60,
756 .request_firmware
= philips_tda1004x_request_firmware
759 static struct tda1004x_config philips_tiger_s_config
= {
760 .demod_address
= 0x08,
763 .xtal_freq
= TDA10046_XTAL_16M
,
764 .agc_config
= TDA10046_AGC_TDA827X
,
765 .gpio_config
= TDA10046_GP01_I
,
766 .if_freq
= TDA10046_FREQ_045
,
768 .tuner_address
= 0x61,
771 .request_firmware
= philips_tda1004x_request_firmware
774 static struct tda1004x_config pinnacle_pctv_310i_config
= {
775 .demod_address
= 0x08,
778 .xtal_freq
= TDA10046_XTAL_16M
,
779 .agc_config
= TDA10046_AGC_TDA827X
,
780 .gpio_config
= TDA10046_GP11_I
,
781 .if_freq
= TDA10046_FREQ_045
,
783 .tuner_address
= 0x61,
785 .request_firmware
= philips_tda1004x_request_firmware
788 static struct tda1004x_config hauppauge_hvr_1110_config
= {
789 .demod_address
= 0x08,
792 .xtal_freq
= TDA10046_XTAL_16M
,
793 .agc_config
= TDA10046_AGC_TDA827X
,
794 .gpio_config
= TDA10046_GP11_I
,
795 .if_freq
= TDA10046_FREQ_045
,
797 .tuner_address
= 0x61,
798 .request_firmware
= philips_tda1004x_request_firmware
801 static struct tda1004x_config asus_p7131_dual_config
= {
802 .demod_address
= 0x08,
805 .xtal_freq
= TDA10046_XTAL_16M
,
806 .agc_config
= TDA10046_AGC_TDA827X
,
807 .gpio_config
= TDA10046_GP11_I
,
808 .if_freq
= TDA10046_FREQ_045
,
810 .tuner_address
= 0x61,
813 .request_firmware
= philips_tda1004x_request_firmware
816 static struct tda1004x_config lifeview_trio_config
= {
817 .demod_address
= 0x09,
820 .xtal_freq
= TDA10046_XTAL_16M
,
821 .agc_config
= TDA10046_AGC_TDA827X
,
822 .gpio_config
= TDA10046_GP00_I
,
823 .if_freq
= TDA10046_FREQ_045
,
824 .tuner_address
= 0x60,
825 .request_firmware
= philips_tda1004x_request_firmware
828 static struct tda1004x_config tevion_dvbt220rf_config
= {
829 .demod_address
= 0x08,
832 .xtal_freq
= TDA10046_XTAL_16M
,
833 .agc_config
= TDA10046_AGC_TDA827X
,
834 .gpio_config
= TDA10046_GP11_I
,
835 .if_freq
= TDA10046_FREQ_045
,
836 .tuner_address
= 0x60,
837 .request_firmware
= philips_tda1004x_request_firmware
840 static struct tda1004x_config md8800_dvbt_config
= {
841 .demod_address
= 0x08,
844 .xtal_freq
= TDA10046_XTAL_16M
,
845 .agc_config
= TDA10046_AGC_TDA827X
,
846 .gpio_config
= TDA10046_GP01_I
,
847 .if_freq
= TDA10046_FREQ_045
,
849 .tuner_address
= 0x60,
851 .request_firmware
= philips_tda1004x_request_firmware
854 /* ------------------------------------------------------------------
855 * special case: this card uses saa713x GPIO22 for the mode switch
858 static int ads_duo_tuner_init(struct dvb_frontend
*fe
)
860 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
861 philips_tda827x_tuner_init(fe
);
862 /* route TDA8275a AGC input to the channel decoder */
863 saa7134_set_gpio(dev
, 22, 1);
867 static int ads_duo_tuner_sleep(struct dvb_frontend
*fe
)
869 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
870 /* route TDA8275a AGC input to the analog IF chip*/
871 saa7134_set_gpio(dev
, 22, 0);
872 philips_tda827x_tuner_sleep(fe
);
876 static struct tda827x_config ads_duo_cfg
= {
877 .lna_gain
= philips_tda827x_lna_gain
,
878 .init
= ads_duo_tuner_init
,
879 .sleep
= ads_duo_tuner_sleep
882 static struct tda1004x_config ads_tech_duo_config
= {
883 .demod_address
= 0x08,
886 .xtal_freq
= TDA10046_XTAL_16M
,
887 .agc_config
= TDA10046_AGC_TDA827X
,
888 .gpio_config
= TDA10046_GP00_I
,
889 .if_freq
= TDA10046_FREQ_045
,
890 .tuner_address
= 0x61,
891 .request_firmware
= philips_tda1004x_request_firmware
894 /* ==================================================================
895 * tda10086 based DVB-S cards, helper functions
898 static struct tda10086_config flydvbs
= {
899 .demod_address
= 0x0e,
903 /* ==================================================================
904 * nxt200x based ATSC cards, helper functions
907 static struct nxt200x_config avertvhda180
= {
908 .demod_address
= 0x0a,
911 static int nxt200x_set_pll_input(u8
*buf
, int input
)
920 static struct nxt200x_config kworldatsc110
= {
921 .demod_address
= 0x0a,
922 .set_pll_input
= nxt200x_set_pll_input
,
925 /* ==================================================================
929 static int dvb_init(struct saa7134_dev
*dev
)
932 /* init struct videobuf_dvb */
933 dev
->ts
.nr_bufs
= 32;
934 dev
->ts
.nr_packets
= 32*4;
935 dev
->dvb
.name
= dev
->name
;
936 videobuf_queue_init(&dev
->dvb
.dvbq
, &saa7134_ts_qops
,
937 dev
->pci
, &dev
->slock
,
938 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
939 V4L2_FIELD_ALTERNATE
,
940 sizeof(struct saa7134_buf
),
943 switch (dev
->board
) {
944 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
945 printk("%s: pinnacle 300i dvb setup\n",dev
->name
);
946 dev
->dvb
.frontend
= dvb_attach(mt352_attach
, &pinnacle_300i
,
948 if (dev
->dvb
.frontend
) {
949 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= mt352_pinnacle_tuner_set_params
;
952 case SAA7134_BOARD_AVERMEDIA_777
:
953 case SAA7134_BOARD_AVERMEDIA_A16AR
:
954 printk("%s: avertv 777 dvb setup\n",dev
->name
);
955 dev
->dvb
.frontend
= dvb_attach(mt352_attach
, &avermedia_777
,
957 if (dev
->dvb
.frontend
) {
958 dev
->dvb
.frontend
->ops
.tuner_ops
.calc_regs
= mt352_aver777_tuner_calc_regs
;
961 case SAA7134_BOARD_MD7134
:
962 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
965 if (dev
->dvb
.frontend
) {
966 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_fmd1216_tuner_init
;
967 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_fmd1216_tuner_sleep
;
968 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_fmd1216_tuner_set_params
;
971 case SAA7134_BOARD_PHILIPS_TOUGH
:
972 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
973 &philips_tu1216_60_config
,
975 if (dev
->dvb
.frontend
) {
976 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_tu1216_init
;
977 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_tda6651_pll_set
;
980 case SAA7134_BOARD_FLYDVBTDUO
:
981 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS
:
982 configure_tda827x_fe(dev
, &tda827x_lifeview_config
);
984 case SAA7134_BOARD_PHILIPS_EUROPA
:
985 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
986 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
987 &philips_europa_config
,
989 if (dev
->dvb
.frontend
) {
990 dev
->original_demod_sleep
= dev
->dvb
.frontend
->ops
.sleep
;
991 dev
->dvb
.frontend
->ops
.sleep
= philips_europa_demod_sleep
;
992 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_europa_tuner_init
;
993 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_europa_tuner_sleep
;
994 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_td1316_tuner_set_params
;
997 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
998 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
999 &philips_tu1216_61_config
,
1001 if (dev
->dvb
.frontend
) {
1002 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_tu1216_init
;
1003 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_tda6651_pll_set
;
1006 case SAA7134_BOARD_PHILIPS_TIGER
:
1007 configure_tda827x_fe(dev
, &philips_tiger_config
);
1009 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
1010 configure_tda827x_fe(dev
, &pinnacle_pctv_310i_config
);
1012 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
1013 configure_tda827x_fe(dev
, &hauppauge_hvr_1110_config
);
1015 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
1016 configure_tda827x_fe(dev
, &asus_p7131_dual_config
);
1018 case SAA7134_BOARD_FLYDVBT_LR301
:
1019 configure_tda827x_fe(dev
, &tda827x_lifeview_config
);
1021 case SAA7134_BOARD_FLYDVB_TRIO
:
1022 if(! use_frontend
) { //terrestrial
1023 configure_tda827x_fe(dev
, &lifeview_trio_config
);
1024 } else { //satellite
1025 dev
->dvb
.frontend
= dvb_attach(tda10086_attach
, &flydvbs
, &dev
->i2c_adap
);
1026 if (dev
->dvb
.frontend
) {
1027 if (dvb_attach(tda826x_attach
, dev
->dvb
.frontend
, 0x63,
1028 &dev
->i2c_adap
, 0) == NULL
) {
1029 printk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__
);
1031 if (dvb_attach(isl6421_attach
, dev
->dvb
.frontend
, &dev
->i2c_adap
,
1032 0x08, 0, 0) == NULL
) {
1033 printk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__
);
1038 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331
:
1039 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS
:
1040 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1041 &ads_tech_duo_config
,
1043 if (dev
->dvb
.frontend
) {
1044 if (dvb_attach(tda827x_attach
,dev
->dvb
.frontend
,
1045 ads_tech_duo_config
.tuner_address
,
1046 &dev
->i2c_adap
,&ads_duo_cfg
) == NULL
) {
1047 printk ("saa7134/dvb: no tda827x tuner found at addr: %02x\n",
1048 ads_tech_duo_config
.tuner_address
);
1052 case SAA7134_BOARD_TEVION_DVBT_220RF
:
1053 configure_tda827x_fe(dev
, &tevion_dvbt220rf_config
);
1055 case SAA7134_BOARD_MEDION_MD8800_QUADRO
:
1056 configure_tda827x_fe(dev
, &md8800_dvbt_config
);
1058 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180
:
1059 dev
->dvb
.frontend
= dvb_attach(nxt200x_attach
, &avertvhda180
,
1061 if (dev
->dvb
.frontend
) {
1062 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
1063 NULL
, &dvb_pll_tdhu2
);
1066 case SAA7134_BOARD_KWORLD_ATSC110
:
1067 dev
->dvb
.frontend
= dvb_attach(nxt200x_attach
, &kworldatsc110
,
1069 if (dev
->dvb
.frontend
) {
1070 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
1071 NULL
, &dvb_pll_tuv1236d
);
1074 case SAA7134_BOARD_FLYDVBS_LR300
:
1075 dev
->dvb
.frontend
= dvb_attach(tda10086_attach
, &flydvbs
,
1077 if (dev
->dvb
.frontend
) {
1078 if (dvb_attach(tda826x_attach
, dev
->dvb
.frontend
, 0x60,
1079 &dev
->i2c_adap
, 0) == NULL
) {
1080 printk("%s: No tda826x found!\n", __FUNCTION__
);
1082 if (dvb_attach(isl6421_attach
, dev
->dvb
.frontend
,
1083 &dev
->i2c_adap
, 0x08, 0, 0) == NULL
) {
1084 printk("%s: No ISL6421 found!\n", __FUNCTION__
);
1088 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID
:
1089 dev
->dvb
.frontend
= tda10046_attach(&medion_cardbus
,
1091 if (dev
->dvb
.frontend
) {
1092 dev
->original_demod_sleep
= dev
->dvb
.frontend
->ops
.sleep
;
1093 dev
->dvb
.frontend
->ops
.sleep
= philips_europa_demod_sleep
;
1094 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_fmd1216_tuner_init
;
1095 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_fmd1216_tuner_sleep
;
1096 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_fmd1216_tuner_set_params
;
1099 case SAA7134_BOARD_VIDEOMATE_DVBT_200A
:
1100 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1101 &philips_europa_config
,
1103 if (dev
->dvb
.frontend
) {
1104 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_td1316_tuner_init
;
1105 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_td1316_tuner_set_params
;
1108 case SAA7134_BOARD_CINERGY_HT_PCMCIA
:
1109 configure_tda827x_fe(dev
, &cinergy_ht_config
);
1111 case SAA7134_BOARD_CINERGY_HT_PCI
:
1112 configure_tda827x_fe(dev
, &cinergy_ht_pci_config
);
1114 case SAA7134_BOARD_PHILIPS_TIGER_S
:
1115 configure_tda827x_fe(dev
, &philips_tiger_s_config
);
1118 printk("%s: Huh? unknown DVB card?\n",dev
->name
);
1122 if (NULL
== dev
->dvb
.frontend
) {
1123 printk("%s: frontend initialization failed\n",dev
->name
);
1127 /* register everything else */
1128 ret
= videobuf_dvb_register(&dev
->dvb
, THIS_MODULE
, dev
, &dev
->pci
->dev
);
1130 /* this sequence is necessary to make the tda1004x load its firmware
1131 * and to enter analog mode of hybrid boards
1134 if (dev
->dvb
.frontend
->ops
.init
)
1135 dev
->dvb
.frontend
->ops
.init(dev
->dvb
.frontend
);
1136 if (dev
->dvb
.frontend
->ops
.sleep
)
1137 dev
->dvb
.frontend
->ops
.sleep(dev
->dvb
.frontend
);
1142 static int dvb_fini(struct saa7134_dev
*dev
)
1144 static int on
= TDA9887_PRESENT
| TDA9887_PORT2_INACTIVE
;
1146 switch (dev
->board
) {
1147 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
1148 /* otherwise we don't detect the tuner on next insmod */
1149 saa7134_i2c_call_clients(dev
,TDA9887_SET_CONFIG
,&on
);
1152 videobuf_dvb_unregister(&dev
->dvb
);
1156 static struct saa7134_mpeg_ops dvb_ops
= {
1157 .type
= SAA7134_MPEG_DVB
,
1162 static int __init
dvb_register(void)
1164 return saa7134_ts_register(&dvb_ops
);
1167 static void __exit
dvb_unregister(void)
1169 saa7134_ts_unregister(&dvb_ops
);
1172 module_init(dvb_register
);
1173 module_exit(dvb_unregister
);
1175 /* ------------------------------------------------------------------ */