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...) do { if (debug) \
64 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
67 #define wprintk(fmt, arg...) \
68 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
70 /* ------------------------------------------------------------------
71 * mt352 based DVB-T cards
74 static int pinnacle_antenna_pwr(struct saa7134_dev
*dev
, int on
)
79 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 26));
80 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
84 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 26));
85 saa_setl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
88 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 28));
89 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 28));
91 saa_setl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 28));
93 ok
= saa_readl(SAA7134_GPIO_GPSTATUS0
) & (1 << 27);
94 dprintk("%s %s\n", __FUNCTION__
, ok
? "on" : "off");
97 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
101 static int mt352_pinnacle_init(struct dvb_frontend
* fe
)
103 static u8 clock_config
[] = { CLOCK_CTL
, 0x3d, 0x28 };
104 static u8 reset
[] = { RESET
, 0x80 };
105 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
106 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0xa0 };
107 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x31 };
108 static u8 fsm_ctl_cfg
[] = { 0x7b, 0x04 };
109 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x0f };
110 static u8 scan_ctl_cfg
[] = { SCAN_CTL
, 0x0d };
111 static u8 irq_cfg
[] = { INTERRUPT_EN_0
, 0x00, 0x00, 0x00, 0x00 };
112 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
114 dprintk("%s called\n", __FUNCTION__
);
116 mt352_write(fe
, clock_config
, sizeof(clock_config
));
118 mt352_write(fe
, reset
, sizeof(reset
));
119 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
120 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
121 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
122 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
124 mt352_write(fe
, fsm_ctl_cfg
, sizeof(fsm_ctl_cfg
));
125 mt352_write(fe
, scan_ctl_cfg
, sizeof(scan_ctl_cfg
));
126 mt352_write(fe
, irq_cfg
, sizeof(irq_cfg
));
131 static int mt352_aver777_init(struct dvb_frontend
* fe
)
133 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x2d };
134 static u8 reset
[] = { RESET
, 0x80 };
135 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
136 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0xa0 };
137 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x33 };
139 mt352_write(fe
, clock_config
, sizeof(clock_config
));
141 mt352_write(fe
, reset
, sizeof(reset
));
142 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
143 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
144 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
149 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend
* fe
,
150 struct dvb_frontend_parameters
* params
)
152 u8 off
[] = { 0x00, 0xf1};
153 u8 on
[] = { 0x00, 0x71};
154 struct i2c_msg msg
= {.addr
=0x43, .flags
=0, .buf
=off
, .len
= sizeof(off
)};
156 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
157 struct v4l2_frequency f
;
159 /* set frequency (mt2050) */
161 f
.type
= V4L2_TUNER_DIGITAL_TV
;
162 f
.frequency
= params
->frequency
/ 1000 * 16 / 1000;
163 if (fe
->ops
.i2c_gate_ctrl
)
164 fe
->ops
.i2c_gate_ctrl(fe
, 1);
165 i2c_transfer(&dev
->i2c_adap
, &msg
, 1);
166 saa7134_i2c_call_clients(dev
,VIDIOC_S_FREQUENCY
,&f
);
168 if (fe
->ops
.i2c_gate_ctrl
)
169 fe
->ops
.i2c_gate_ctrl(fe
, 1);
170 i2c_transfer(&dev
->i2c_adap
, &msg
, 1);
172 pinnacle_antenna_pwr(dev
, antenna_pwr
);
175 return mt352_pinnacle_init(fe
);
178 static int mt352_aver777_tuner_calc_regs(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
, u8
* pllbuf
, int buf_len
)
184 dvb_pll_configure(&dvb_pll_philips_td1316
, pllbuf
+1,
186 params
->u
.ofdm
.bandwidth
);
190 static struct mt352_config pinnacle_300i
= {
191 .demod_address
= 0x3c >> 1,
195 .demod_init
= mt352_pinnacle_init
,
198 static struct mt352_config avermedia_777
= {
199 .demod_address
= 0xf,
200 .demod_init
= mt352_aver777_init
,
203 /* ==================================================================
204 * tda1004x based DVB-T cards, helper functions
207 static int philips_tda1004x_request_firmware(struct dvb_frontend
*fe
,
208 const struct firmware
**fw
, char *name
)
210 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
211 return request_firmware(fw
, name
, &dev
->pci
->dev
);
214 /* ------------------------------------------------------------------
215 * these tuners are tu1216, td1316(a)
218 static int philips_tda6651_pll_set(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
220 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
221 struct tda1004x_state
*state
= fe
->demodulator_priv
;
222 u8 addr
= state
->config
->tuner_address
;
224 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= tuner_buf
,.len
=
226 int tuner_frequency
= 0;
229 /* determine charge pump */
230 tuner_frequency
= params
->frequency
+ 36166000;
231 if (tuner_frequency
< 87000000)
233 else if (tuner_frequency
< 130000000)
235 else if (tuner_frequency
< 160000000)
237 else if (tuner_frequency
< 200000000)
239 else if (tuner_frequency
< 290000000)
241 else if (tuner_frequency
< 420000000)
243 else if (tuner_frequency
< 480000000)
245 else if (tuner_frequency
< 620000000)
247 else if (tuner_frequency
< 830000000)
249 else if (tuner_frequency
< 895000000)
255 if (params
->frequency
< 49000000)
257 else if (params
->frequency
< 161000000)
259 else if (params
->frequency
< 444000000)
261 else if (params
->frequency
< 861000000)
266 /* setup PLL filter */
267 switch (params
->u
.ofdm
.bandwidth
) {
268 case BANDWIDTH_6_MHZ
:
272 case BANDWIDTH_7_MHZ
:
276 case BANDWIDTH_8_MHZ
:
285 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
287 tuner_frequency
= (((params
->frequency
/ 1000) * 6) + 217496) / 1000;
289 /* setup tuner buffer */
290 tuner_buf
[0] = (tuner_frequency
>> 8) & 0x7f;
291 tuner_buf
[1] = tuner_frequency
& 0xff;
293 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
295 if (fe
->ops
.i2c_gate_ctrl
)
296 fe
->ops
.i2c_gate_ctrl(fe
, 1);
297 if (i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1) != 1) {
298 wprintk("could not write to tuner at addr: 0x%02x\n",
306 static int philips_tu1216_init(struct dvb_frontend
*fe
)
308 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
309 struct tda1004x_state
*state
= fe
->demodulator_priv
;
310 u8 addr
= state
->config
->tuner_address
;
311 static u8 tu1216_init
[] = { 0x0b, 0xf5, 0x85, 0xab };
312 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= tu1216_init
,.len
= sizeof(tu1216_init
) };
314 /* setup PLL configuration */
315 if (fe
->ops
.i2c_gate_ctrl
)
316 fe
->ops
.i2c_gate_ctrl(fe
, 1);
317 if (i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1) != 1)
324 /* ------------------------------------------------------------------ */
326 static struct tda1004x_config philips_tu1216_60_config
= {
327 .demod_address
= 0x8,
330 .xtal_freq
= TDA10046_XTAL_4M
,
331 .agc_config
= TDA10046_AGC_DEFAULT
,
332 .if_freq
= TDA10046_FREQ_3617
,
333 .tuner_address
= 0x60,
334 .request_firmware
= philips_tda1004x_request_firmware
337 static struct tda1004x_config philips_tu1216_61_config
= {
339 .demod_address
= 0x8,
342 .xtal_freq
= TDA10046_XTAL_4M
,
343 .agc_config
= TDA10046_AGC_DEFAULT
,
344 .if_freq
= TDA10046_FREQ_3617
,
345 .tuner_address
= 0x61,
346 .request_firmware
= philips_tda1004x_request_firmware
349 /* ------------------------------------------------------------------ */
351 static int philips_td1316_tuner_init(struct dvb_frontend
*fe
)
353 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
354 struct tda1004x_state
*state
= fe
->demodulator_priv
;
355 u8 addr
= state
->config
->tuner_address
;
356 static u8 msg
[] = { 0x0b, 0xf5, 0x86, 0xab };
357 struct i2c_msg init_msg
= {.addr
= addr
,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
359 /* setup PLL configuration */
360 if (fe
->ops
.i2c_gate_ctrl
)
361 fe
->ops
.i2c_gate_ctrl(fe
, 1);
362 if (i2c_transfer(&dev
->i2c_adap
, &init_msg
, 1) != 1)
367 static int philips_td1316_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
369 return philips_tda6651_pll_set(fe
, params
);
372 static int philips_td1316_tuner_sleep(struct dvb_frontend
*fe
)
374 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
375 struct tda1004x_state
*state
= fe
->demodulator_priv
;
376 u8 addr
= state
->config
->tuner_address
;
377 static u8 msg
[] = { 0x0b, 0xdc, 0x86, 0xa4 };
378 struct i2c_msg analog_msg
= {.addr
= addr
,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
380 /* switch the tuner to analog mode */
381 if (fe
->ops
.i2c_gate_ctrl
)
382 fe
->ops
.i2c_gate_ctrl(fe
, 1);
383 if (i2c_transfer(&dev
->i2c_adap
, &analog_msg
, 1) != 1)
388 /* ------------------------------------------------------------------ */
390 static int philips_europa_tuner_init(struct dvb_frontend
*fe
)
392 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
393 static u8 msg
[] = { 0x00, 0x40};
394 struct i2c_msg init_msg
= {.addr
= 0x43,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
397 if (philips_td1316_tuner_init(fe
))
400 if (i2c_transfer(&dev
->i2c_adap
, &init_msg
, 1) != 1)
406 static int philips_europa_tuner_sleep(struct dvb_frontend
*fe
)
408 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
410 static u8 msg
[] = { 0x00, 0x14 };
411 struct i2c_msg analog_msg
= {.addr
= 0x43,.flags
= 0,.buf
= msg
,.len
= sizeof(msg
) };
413 if (philips_td1316_tuner_sleep(fe
))
416 /* switch the board to analog mode */
417 if (fe
->ops
.i2c_gate_ctrl
)
418 fe
->ops
.i2c_gate_ctrl(fe
, 1);
419 i2c_transfer(&dev
->i2c_adap
, &analog_msg
, 1);
423 static int philips_europa_demod_sleep(struct dvb_frontend
*fe
)
425 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
427 if (dev
->original_demod_sleep
)
428 dev
->original_demod_sleep(fe
);
429 fe
->ops
.i2c_gate_ctrl(fe
, 1);
433 static struct tda1004x_config philips_europa_config
= {
435 .demod_address
= 0x8,
438 .xtal_freq
= TDA10046_XTAL_4M
,
439 .agc_config
= TDA10046_AGC_IFO_AUTO_POS
,
440 .if_freq
= TDA10046_FREQ_052
,
441 .tuner_address
= 0x61,
442 .request_firmware
= philips_tda1004x_request_firmware
445 /* ------------------------------------------------------------------ */
447 static int philips_fmd1216_tuner_init(struct dvb_frontend
*fe
)
449 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
450 struct tda1004x_state
*state
= fe
->demodulator_priv
;
451 u8 addr
= state
->config
->tuner_address
;
452 /* this message is to set up ATC and ALC */
453 static u8 fmd1216_init
[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
454 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= fmd1216_init
,.len
= sizeof(fmd1216_init
) };
456 if (fe
->ops
.i2c_gate_ctrl
)
457 fe
->ops
.i2c_gate_ctrl(fe
, 1);
458 if (i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1) != 1)
465 static int philips_fmd1216_tuner_sleep(struct dvb_frontend
*fe
)
467 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
468 struct tda1004x_state
*state
= fe
->demodulator_priv
;
469 u8 addr
= state
->config
->tuner_address
;
470 /* this message actually turns the tuner back to analog mode */
471 u8 fmd1216_init
[] = { 0x0b, 0xdc, 0x9c, 0x60 };
472 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= fmd1216_init
,.len
= sizeof(fmd1216_init
) };
474 if (fe
->ops
.i2c_gate_ctrl
)
475 fe
->ops
.i2c_gate_ctrl(fe
, 1);
476 i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1);
478 fmd1216_init
[2] = 0x86;
479 fmd1216_init
[3] = 0x54;
480 if (fe
->ops
.i2c_gate_ctrl
)
481 fe
->ops
.i2c_gate_ctrl(fe
, 1);
482 i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1);
487 static int philips_fmd1216_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
489 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
490 struct tda1004x_state
*state
= fe
->demodulator_priv
;
491 u8 addr
= state
->config
->tuner_address
;
493 struct i2c_msg tuner_msg
= {.addr
= addr
,.flags
= 0,.buf
= tuner_buf
,.len
=
495 int tuner_frequency
= 0;
499 /* determine charge pump */
500 tuner_frequency
= params
->frequency
+ 36130000;
501 if (tuner_frequency
< 87000000)
504 else if (tuner_frequency
< 180000000) {
508 } else if (tuner_frequency
< 195000000) {
513 } else if (tuner_frequency
< 366000000) {
514 if (params
->u
.ofdm
.bandwidth
== BANDWIDTH_8_MHZ
) {
521 } else if (tuner_frequency
< 478000000) {
522 if (params
->u
.ofdm
.bandwidth
== BANDWIDTH_8_MHZ
) {
530 } else if (tuner_frequency
< 662000000) {
531 if (params
->u
.ofdm
.bandwidth
== BANDWIDTH_8_MHZ
) {
538 } else if (tuner_frequency
< 840000000) {
539 if (params
->u
.ofdm
.bandwidth
== BANDWIDTH_8_MHZ
) {
547 if (params
->u
.ofdm
.bandwidth
== BANDWIDTH_8_MHZ
) {
556 /* calculate divisor */
557 /* ((36166000 + Finput) / 166666) rounded! */
558 divider
= (tuner_frequency
+ 83333) / 166667;
560 /* setup tuner buffer */
561 tuner_buf
[0] = (divider
>> 8) & 0x7f;
562 tuner_buf
[1] = divider
& 0xff;
563 tuner_buf
[2] = 0x80 | (cp
<< 6) | (mode
<< 3) | 4;
564 tuner_buf
[3] = 0x40 | band
;
566 if (fe
->ops
.i2c_gate_ctrl
)
567 fe
->ops
.i2c_gate_ctrl(fe
, 1);
568 if (i2c_transfer(&dev
->i2c_adap
, &tuner_msg
, 1) != 1) {
569 wprintk("could not write to tuner at addr: 0x%02x\n",
576 static struct tda1004x_config medion_cardbus
= {
577 .demod_address
= 0x08,
580 .xtal_freq
= TDA10046_XTAL_16M
,
581 .agc_config
= TDA10046_AGC_IFO_AUTO_NEG
,
582 .if_freq
= TDA10046_FREQ_3613
,
583 .tuner_address
= 0x61,
584 .request_firmware
= philips_tda1004x_request_firmware
587 /* ------------------------------------------------------------------
588 * tda 1004x based cards with philips silicon tuner
591 static void philips_tda827x_lna_gain(struct dvb_frontend
*fe
, int high
)
593 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
594 struct tda1004x_state
*state
= fe
->demodulator_priv
;
595 u8 addr
= state
->config
->i2c_gate
;
596 u8 config
= state
->config
->tuner_config
;
597 u8 GP00_CF
[] = {0x20, 0x01};
598 u8 GP00_LEV
[] = {0x22, 0x00};
600 struct i2c_msg msg
= {.addr
= addr
,.flags
= 0,.buf
= GP00_CF
, .len
= 2};
603 dprintk("setting LNA to high gain\n");
605 dprintk("setting LNA to low gain\n");
611 case 1: /* switch is GPIO 0 of tda8290 */
614 saa7134_set_gpio(dev
, 22, 0);
615 GP00_LEV
[1] = high
? 0 : 1;
616 if (i2c_transfer(&dev
->i2c_adap
, &msg
, 1) != 1) {
617 wprintk("could not access tda8290 at addr: 0x%02x\n",
623 GP00_LEV
[1] = high
? 1 : 0;
624 i2c_transfer(&dev
->i2c_adap
, &msg
, 1);
626 case 3: /* switch with GPIO of saa713x */
627 saa7134_set_gpio(dev
, 22, high
);
632 static int tda8290_i2c_gate_ctrl( struct dvb_frontend
* fe
, int enable
)
634 struct tda1004x_state
*state
= fe
->demodulator_priv
;
636 u8 addr
= state
->config
->i2c_gate
;
637 static u8 tda8290_close
[] = { 0x21, 0xc0};
638 static u8 tda8290_open
[] = { 0x21, 0x80};
639 struct i2c_msg tda8290_msg
= {.addr
= addr
,.flags
= 0, .len
= 2};
641 tda8290_msg
.buf
= tda8290_close
;
643 tda8290_msg
.buf
= tda8290_open
;
645 if (i2c_transfer(state
->i2c
, &tda8290_msg
, 1) != 1) {
646 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
647 wprintk("could not access tda8290 I2C gate\n");
654 /* ------------------------------------------------------------------ */
656 static int philips_tda827x_tuner_init(struct dvb_frontend
*fe
)
658 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
659 struct tda1004x_state
*state
= fe
->demodulator_priv
;
661 switch (state
->config
->antenna_switch
) {
663 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
664 saa7134_set_gpio(dev
, 21, 0);
666 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
667 saa7134_set_gpio(dev
, 21, 1);
673 static int philips_tda827x_tuner_sleep(struct dvb_frontend
*fe
)
675 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
676 struct tda1004x_state
*state
= fe
->demodulator_priv
;
678 switch (state
->config
->antenna_switch
) {
680 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
681 saa7134_set_gpio(dev
, 21, 1);
683 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
684 saa7134_set_gpio(dev
, 21, 0);
690 static struct tda827x_config tda827x_cfg
= {
691 .lna_gain
= philips_tda827x_lna_gain
,
692 .init
= philips_tda827x_tuner_init
,
693 .sleep
= philips_tda827x_tuner_sleep
696 static void configure_tda827x_fe(struct saa7134_dev
*dev
, struct tda1004x_config
*tda_conf
)
698 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
, tda_conf
, &dev
->i2c_adap
);
699 if (dev
->dvb
.frontend
) {
700 if (tda_conf
->i2c_gate
)
701 dev
->dvb
.frontend
->ops
.i2c_gate_ctrl
= tda8290_i2c_gate_ctrl
;
702 if (dvb_attach(tda827x_attach
, dev
->dvb
.frontend
, tda_conf
->tuner_address
,
703 &dev
->i2c_adap
,&tda827x_cfg
) == NULL
) {
704 wprintk("no tda827x tuner found at addr: %02x\n",
705 tda_conf
->tuner_address
);
710 /* ------------------------------------------------------------------ */
711 static struct tda1004x_config tda827x_lifeview_config
= {
712 .demod_address
= 0x08,
715 .xtal_freq
= TDA10046_XTAL_16M
,
716 .agc_config
= TDA10046_AGC_TDA827X
,
717 .gpio_config
= TDA10046_GP11_I
,
718 .if_freq
= TDA10046_FREQ_045
,
719 .tuner_address
= 0x60,
720 .request_firmware
= philips_tda1004x_request_firmware
723 static struct tda1004x_config philips_tiger_config
= {
724 .demod_address
= 0x08,
727 .xtal_freq
= TDA10046_XTAL_16M
,
728 .agc_config
= TDA10046_AGC_TDA827X
,
729 .gpio_config
= TDA10046_GP11_I
,
730 .if_freq
= TDA10046_FREQ_045
,
732 .tuner_address
= 0x61,
735 .request_firmware
= philips_tda1004x_request_firmware
738 static struct tda1004x_config cinergy_ht_config
= {
739 .demod_address
= 0x08,
742 .xtal_freq
= TDA10046_XTAL_16M
,
743 .agc_config
= TDA10046_AGC_TDA827X
,
744 .gpio_config
= TDA10046_GP01_I
,
745 .if_freq
= TDA10046_FREQ_045
,
747 .tuner_address
= 0x61,
749 .request_firmware
= philips_tda1004x_request_firmware
752 static struct tda1004x_config cinergy_ht_pci_config
= {
753 .demod_address
= 0x08,
756 .xtal_freq
= TDA10046_XTAL_16M
,
757 .agc_config
= TDA10046_AGC_TDA827X
,
758 .gpio_config
= TDA10046_GP01_I
,
759 .if_freq
= TDA10046_FREQ_045
,
761 .tuner_address
= 0x60,
763 .request_firmware
= philips_tda1004x_request_firmware
766 static struct tda1004x_config philips_tiger_s_config
= {
767 .demod_address
= 0x08,
770 .xtal_freq
= TDA10046_XTAL_16M
,
771 .agc_config
= TDA10046_AGC_TDA827X
,
772 .gpio_config
= TDA10046_GP01_I
,
773 .if_freq
= TDA10046_FREQ_045
,
775 .tuner_address
= 0x61,
778 .request_firmware
= philips_tda1004x_request_firmware
781 static struct tda1004x_config pinnacle_pctv_310i_config
= {
782 .demod_address
= 0x08,
785 .xtal_freq
= TDA10046_XTAL_16M
,
786 .agc_config
= TDA10046_AGC_TDA827X
,
787 .gpio_config
= TDA10046_GP11_I
,
788 .if_freq
= TDA10046_FREQ_045
,
790 .tuner_address
= 0x61,
792 .request_firmware
= philips_tda1004x_request_firmware
795 static struct tda1004x_config hauppauge_hvr_1110_config
= {
796 .demod_address
= 0x08,
799 .xtal_freq
= TDA10046_XTAL_16M
,
800 .agc_config
= TDA10046_AGC_TDA827X
,
801 .gpio_config
= TDA10046_GP11_I
,
802 .if_freq
= TDA10046_FREQ_045
,
804 .tuner_address
= 0x61,
805 .request_firmware
= philips_tda1004x_request_firmware
808 static struct tda1004x_config asus_p7131_dual_config
= {
809 .demod_address
= 0x08,
812 .xtal_freq
= TDA10046_XTAL_16M
,
813 .agc_config
= TDA10046_AGC_TDA827X
,
814 .gpio_config
= TDA10046_GP11_I
,
815 .if_freq
= TDA10046_FREQ_045
,
817 .tuner_address
= 0x61,
820 .request_firmware
= philips_tda1004x_request_firmware
823 static struct tda1004x_config lifeview_trio_config
= {
824 .demod_address
= 0x09,
827 .xtal_freq
= TDA10046_XTAL_16M
,
828 .agc_config
= TDA10046_AGC_TDA827X
,
829 .gpio_config
= TDA10046_GP00_I
,
830 .if_freq
= TDA10046_FREQ_045
,
831 .tuner_address
= 0x60,
832 .request_firmware
= philips_tda1004x_request_firmware
835 static struct tda1004x_config tevion_dvbt220rf_config
= {
836 .demod_address
= 0x08,
839 .xtal_freq
= TDA10046_XTAL_16M
,
840 .agc_config
= TDA10046_AGC_TDA827X
,
841 .gpio_config
= TDA10046_GP11_I
,
842 .if_freq
= TDA10046_FREQ_045
,
843 .tuner_address
= 0x60,
844 .request_firmware
= philips_tda1004x_request_firmware
847 static struct tda1004x_config md8800_dvbt_config
= {
848 .demod_address
= 0x08,
851 .xtal_freq
= TDA10046_XTAL_16M
,
852 .agc_config
= TDA10046_AGC_TDA827X
,
853 .gpio_config
= TDA10046_GP01_I
,
854 .if_freq
= TDA10046_FREQ_045
,
856 .tuner_address
= 0x60,
858 .request_firmware
= philips_tda1004x_request_firmware
861 static struct tda1004x_config asus_p7131_4871_config
= {
862 .demod_address
= 0x08,
865 .xtal_freq
= TDA10046_XTAL_16M
,
866 .agc_config
= TDA10046_AGC_TDA827X
,
867 .gpio_config
= TDA10046_GP01_I
,
868 .if_freq
= TDA10046_FREQ_045
,
870 .tuner_address
= 0x61,
873 .request_firmware
= philips_tda1004x_request_firmware
876 static struct tda1004x_config asus_p7131_hybrid_lna_config
= {
877 .demod_address
= 0x08,
880 .xtal_freq
= TDA10046_XTAL_16M
,
881 .agc_config
= TDA10046_AGC_TDA827X
,
882 .gpio_config
= TDA10046_GP11_I
,
883 .if_freq
= TDA10046_FREQ_045
,
885 .tuner_address
= 0x61,
888 .request_firmware
= philips_tda1004x_request_firmware
890 /* ------------------------------------------------------------------
891 * special case: this card uses saa713x GPIO22 for the mode switch
894 static int ads_duo_tuner_init(struct dvb_frontend
*fe
)
896 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
897 philips_tda827x_tuner_init(fe
);
898 /* route TDA8275a AGC input to the channel decoder */
899 saa7134_set_gpio(dev
, 22, 1);
903 static int ads_duo_tuner_sleep(struct dvb_frontend
*fe
)
905 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
906 /* route TDA8275a AGC input to the analog IF chip*/
907 saa7134_set_gpio(dev
, 22, 0);
908 philips_tda827x_tuner_sleep(fe
);
912 static struct tda827x_config ads_duo_cfg
= {
913 .lna_gain
= philips_tda827x_lna_gain
,
914 .init
= ads_duo_tuner_init
,
915 .sleep
= ads_duo_tuner_sleep
918 static struct tda1004x_config ads_tech_duo_config
= {
919 .demod_address
= 0x08,
922 .xtal_freq
= TDA10046_XTAL_16M
,
923 .agc_config
= TDA10046_AGC_TDA827X
,
924 .gpio_config
= TDA10046_GP00_I
,
925 .if_freq
= TDA10046_FREQ_045
,
926 .tuner_address
= 0x61,
927 .request_firmware
= philips_tda1004x_request_firmware
930 /* ==================================================================
931 * tda10086 based DVB-S cards, helper functions
934 static struct tda10086_config flydvbs
= {
935 .demod_address
= 0x0e,
939 /* ==================================================================
940 * nxt200x based ATSC cards, helper functions
943 static struct nxt200x_config avertvhda180
= {
944 .demod_address
= 0x0a,
947 static int nxt200x_set_pll_input(u8
*buf
, int input
)
956 static struct nxt200x_config kworldatsc110
= {
957 .demod_address
= 0x0a,
958 .set_pll_input
= nxt200x_set_pll_input
,
961 /* ==================================================================
965 static int dvb_init(struct saa7134_dev
*dev
)
968 /* init struct videobuf_dvb */
969 dev
->ts
.nr_bufs
= 32;
970 dev
->ts
.nr_packets
= 32*4;
971 dev
->dvb
.name
= dev
->name
;
972 videobuf_queue_init(&dev
->dvb
.dvbq
, &saa7134_ts_qops
,
973 dev
->pci
, &dev
->slock
,
974 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
975 V4L2_FIELD_ALTERNATE
,
976 sizeof(struct saa7134_buf
),
979 switch (dev
->board
) {
980 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
981 dprintk("pinnacle 300i dvb setup\n");
982 dev
->dvb
.frontend
= dvb_attach(mt352_attach
, &pinnacle_300i
,
984 if (dev
->dvb
.frontend
) {
985 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= mt352_pinnacle_tuner_set_params
;
988 case SAA7134_BOARD_AVERMEDIA_777
:
989 case SAA7134_BOARD_AVERMEDIA_A16AR
:
990 dprintk("avertv 777 dvb setup\n");
991 dev
->dvb
.frontend
= dvb_attach(mt352_attach
, &avermedia_777
,
993 if (dev
->dvb
.frontend
) {
994 dev
->dvb
.frontend
->ops
.tuner_ops
.calc_regs
= mt352_aver777_tuner_calc_regs
;
997 case SAA7134_BOARD_MD7134
:
998 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1001 if (dev
->dvb
.frontend
) {
1002 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_fmd1216_tuner_init
;
1003 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_fmd1216_tuner_sleep
;
1004 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_fmd1216_tuner_set_params
;
1007 case SAA7134_BOARD_PHILIPS_TOUGH
:
1008 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1009 &philips_tu1216_60_config
,
1011 if (dev
->dvb
.frontend
) {
1012 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_tu1216_init
;
1013 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_tda6651_pll_set
;
1016 case SAA7134_BOARD_FLYDVBTDUO
:
1017 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS
:
1018 configure_tda827x_fe(dev
, &tda827x_lifeview_config
);
1020 case SAA7134_BOARD_PHILIPS_EUROPA
:
1021 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
1022 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1023 &philips_europa_config
,
1025 if (dev
->dvb
.frontend
) {
1026 dev
->original_demod_sleep
= dev
->dvb
.frontend
->ops
.sleep
;
1027 dev
->dvb
.frontend
->ops
.sleep
= philips_europa_demod_sleep
;
1028 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_europa_tuner_init
;
1029 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_europa_tuner_sleep
;
1030 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_td1316_tuner_set_params
;
1033 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
1034 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1035 &philips_tu1216_61_config
,
1037 if (dev
->dvb
.frontend
) {
1038 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_tu1216_init
;
1039 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_tda6651_pll_set
;
1042 case SAA7134_BOARD_PHILIPS_TIGER
:
1043 configure_tda827x_fe(dev
, &philips_tiger_config
);
1045 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
1046 configure_tda827x_fe(dev
, &pinnacle_pctv_310i_config
);
1048 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
1049 configure_tda827x_fe(dev
, &hauppauge_hvr_1110_config
);
1051 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
1052 configure_tda827x_fe(dev
, &asus_p7131_dual_config
);
1054 case SAA7134_BOARD_FLYDVBT_LR301
:
1055 configure_tda827x_fe(dev
, &tda827x_lifeview_config
);
1057 case SAA7134_BOARD_FLYDVB_TRIO
:
1058 if(! use_frontend
) { //terrestrial
1059 configure_tda827x_fe(dev
, &lifeview_trio_config
);
1060 } else { //satellite
1061 dev
->dvb
.frontend
= dvb_attach(tda10086_attach
, &flydvbs
, &dev
->i2c_adap
);
1062 if (dev
->dvb
.frontend
) {
1063 if (dvb_attach(tda826x_attach
, dev
->dvb
.frontend
, 0x63,
1064 &dev
->i2c_adap
, 0) == NULL
) {
1065 wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__
);
1067 if (dvb_attach(isl6421_attach
, dev
->dvb
.frontend
, &dev
->i2c_adap
,
1068 0x08, 0, 0) == NULL
) {
1069 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__
);
1074 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331
:
1075 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS
:
1076 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1077 &ads_tech_duo_config
,
1079 if (dev
->dvb
.frontend
) {
1080 if (dvb_attach(tda827x_attach
,dev
->dvb
.frontend
,
1081 ads_tech_duo_config
.tuner_address
,
1082 &dev
->i2c_adap
,&ads_duo_cfg
) == NULL
) {
1083 wprintk("no tda827x tuner found at addr: %02x\n",
1084 ads_tech_duo_config
.tuner_address
);
1088 case SAA7134_BOARD_TEVION_DVBT_220RF
:
1089 configure_tda827x_fe(dev
, &tevion_dvbt220rf_config
);
1091 case SAA7134_BOARD_MEDION_MD8800_QUADRO
:
1092 configure_tda827x_fe(dev
, &md8800_dvbt_config
);
1094 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180
:
1095 dev
->dvb
.frontend
= dvb_attach(nxt200x_attach
, &avertvhda180
,
1097 if (dev
->dvb
.frontend
) {
1098 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
1099 NULL
, &dvb_pll_tdhu2
);
1102 case SAA7134_BOARD_KWORLD_ATSC110
:
1103 dev
->dvb
.frontend
= dvb_attach(nxt200x_attach
, &kworldatsc110
,
1105 if (dev
->dvb
.frontend
) {
1106 dvb_attach(dvb_pll_attach
, dev
->dvb
.frontend
, 0x61,
1107 NULL
, &dvb_pll_tuv1236d
);
1110 case SAA7134_BOARD_FLYDVBS_LR300
:
1111 dev
->dvb
.frontend
= dvb_attach(tda10086_attach
, &flydvbs
,
1113 if (dev
->dvb
.frontend
) {
1114 if (dvb_attach(tda826x_attach
, dev
->dvb
.frontend
, 0x60,
1115 &dev
->i2c_adap
, 0) == NULL
) {
1116 wprintk("%s: No tda826x found!\n", __FUNCTION__
);
1118 if (dvb_attach(isl6421_attach
, dev
->dvb
.frontend
,
1119 &dev
->i2c_adap
, 0x08, 0, 0) == NULL
) {
1120 wprintk("%s: No ISL6421 found!\n", __FUNCTION__
);
1124 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID
:
1125 dev
->dvb
.frontend
= tda10046_attach(&medion_cardbus
,
1127 if (dev
->dvb
.frontend
) {
1128 dev
->original_demod_sleep
= dev
->dvb
.frontend
->ops
.sleep
;
1129 dev
->dvb
.frontend
->ops
.sleep
= philips_europa_demod_sleep
;
1130 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_fmd1216_tuner_init
;
1131 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
= philips_fmd1216_tuner_sleep
;
1132 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_fmd1216_tuner_set_params
;
1135 case SAA7134_BOARD_VIDEOMATE_DVBT_200A
:
1136 dev
->dvb
.frontend
= dvb_attach(tda10046_attach
,
1137 &philips_europa_config
,
1139 if (dev
->dvb
.frontend
) {
1140 dev
->dvb
.frontend
->ops
.tuner_ops
.init
= philips_td1316_tuner_init
;
1141 dev
->dvb
.frontend
->ops
.tuner_ops
.set_params
= philips_td1316_tuner_set_params
;
1144 case SAA7134_BOARD_CINERGY_HT_PCMCIA
:
1145 configure_tda827x_fe(dev
, &cinergy_ht_config
);
1147 case SAA7134_BOARD_CINERGY_HT_PCI
:
1148 configure_tda827x_fe(dev
, &cinergy_ht_pci_config
);
1150 case SAA7134_BOARD_PHILIPS_TIGER_S
:
1151 configure_tda827x_fe(dev
, &philips_tiger_s_config
);
1153 case SAA7134_BOARD_ASUS_P7131_4871
:
1154 configure_tda827x_fe(dev
, &asus_p7131_4871_config
);
1156 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
1157 configure_tda827x_fe(dev
, &asus_p7131_hybrid_lna_config
);
1160 wprintk("Huh? unknown DVB card?\n");
1164 if (NULL
== dev
->dvb
.frontend
) {
1165 printk(KERN_ERR
"%s/dvb: frontend initialization failed\n", dev
->name
);
1169 /* register everything else */
1170 ret
= videobuf_dvb_register(&dev
->dvb
, THIS_MODULE
, dev
, &dev
->pci
->dev
);
1172 /* this sequence is necessary to make the tda1004x load its firmware
1173 * and to enter analog mode of hybrid boards
1176 if (dev
->dvb
.frontend
->ops
.init
)
1177 dev
->dvb
.frontend
->ops
.init(dev
->dvb
.frontend
);
1178 if (dev
->dvb
.frontend
->ops
.sleep
)
1179 dev
->dvb
.frontend
->ops
.sleep(dev
->dvb
.frontend
);
1180 if (dev
->dvb
.frontend
->ops
.tuner_ops
.sleep
)
1181 dev
->dvb
.frontend
->ops
.tuner_ops
.sleep(dev
->dvb
.frontend
);
1186 static int dvb_fini(struct saa7134_dev
*dev
)
1188 static int on
= TDA9887_PRESENT
| TDA9887_PORT2_INACTIVE
;
1190 switch (dev
->board
) {
1191 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
1192 /* otherwise we don't detect the tuner on next insmod */
1193 saa7134_i2c_call_clients(dev
,TDA9887_SET_CONFIG
,&on
);
1196 videobuf_dvb_unregister(&dev
->dvb
);
1200 static struct saa7134_mpeg_ops dvb_ops
= {
1201 .type
= SAA7134_MPEG_DVB
,
1206 static int __init
dvb_register(void)
1208 return saa7134_ts_register(&dvb_ops
);
1211 static void __exit
dvb_unregister(void)
1213 saa7134_ts_unregister(&dvb_ops
);
1216 module_init(dvb_register
);
1217 module_exit(dvb_unregister
);
1219 /* ------------------------------------------------------------------ */