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>
39 # include "mt352_priv.h" /* FIXME */
42 # include "tda1004x.h"
48 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
49 MODULE_LICENSE("GPL");
51 static unsigned int antenna_pwr = 0;
53 module_param(antenna_pwr, int, 0444);
54 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
56 /* ------------------------------------------------------------------ */
59 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
64 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
65 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
69 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
70 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
73 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
74 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
76 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
78 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
79 printk("%s: %s %s\n", dev->name, __FUNCTION__,
83 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
87 static int mt352_pinnacle_init(struct dvb_frontend* fe)
89 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
90 static u8 reset [] = { RESET, 0x80 };
91 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
92 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
93 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
94 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
95 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
96 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
97 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
98 struct saa7134_dev *dev= fe->dvb->priv;
100 printk("%s: %s called\n",dev->name,__FUNCTION__);
102 mt352_write(fe, clock_config, sizeof(clock_config));
104 mt352_write(fe, reset, sizeof(reset));
105 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
106 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
107 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
108 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
110 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
111 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
112 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
117 static int mt352_aver777_init(struct dvb_frontend* fe)
119 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
120 static u8 reset [] = { RESET, 0x80 };
121 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
122 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
123 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
125 mt352_write(fe, clock_config, sizeof(clock_config));
127 mt352_write(fe, reset, sizeof(reset));
128 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
129 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
130 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
135 static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
136 struct dvb_frontend_parameters* params,
139 u8 off[] = { 0x00, 0xf1};
140 u8 on[] = { 0x00, 0x71};
141 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
143 struct saa7134_dev *dev = fe->dvb->priv;
144 struct v4l2_frequency f;
146 /* set frequency (mt2050) */
148 f.type = V4L2_TUNER_DIGITAL_TV;
149 f.frequency = params->frequency / 1000 * 16 / 1000;
150 i2c_transfer(&dev->i2c_adap, &msg, 1);
151 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
153 i2c_transfer(&dev->i2c_adap, &msg, 1);
155 pinnacle_antenna_pwr(dev, antenna_pwr);
158 mt352_pinnacle_init(fe);
167 static int mt352_aver777_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf)
170 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
172 params->u.ofdm.bandwidth);
176 static struct mt352_config pinnacle_300i = {
177 .demod_address = 0x3c >> 1,
181 .demod_init = mt352_pinnacle_init,
182 .pll_set = mt352_pinnacle_pll_set,
185 static struct mt352_config avermedia_777 = {
186 .demod_address = 0xf,
187 .demod_init = mt352_aver777_init,
188 .pll_set = mt352_aver777_pll_set,
192 /* ------------------------------------------------------------------ */
196 static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
198 struct saa7134_dev *dev = fe->dvb->priv;
200 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
202 int tuner_frequency = 0;
205 /* determine charge pump */
206 tuner_frequency = params->frequency + 36166000;
207 if (tuner_frequency < 87000000)
209 else if (tuner_frequency < 130000000)
211 else if (tuner_frequency < 160000000)
213 else if (tuner_frequency < 200000000)
215 else if (tuner_frequency < 290000000)
217 else if (tuner_frequency < 420000000)
219 else if (tuner_frequency < 480000000)
221 else if (tuner_frequency < 620000000)
223 else if (tuner_frequency < 830000000)
225 else if (tuner_frequency < 895000000)
231 if (params->frequency < 49000000)
233 else if (params->frequency < 161000000)
235 else if (params->frequency < 444000000)
237 else if (params->frequency < 861000000)
242 /* setup PLL filter */
243 switch (params->u.ofdm.bandwidth) {
244 case BANDWIDTH_6_MHZ:
248 case BANDWIDTH_7_MHZ:
252 case BANDWIDTH_8_MHZ:
261 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
263 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
265 /* setup tuner buffer */
266 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
267 tuner_buf[1] = tuner_frequency & 0xff;
269 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
271 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
277 static int philips_tda6651_pll_init(u8 addr, struct dvb_frontend *fe)
279 struct saa7134_dev *dev = fe->dvb->priv;
280 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
281 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
283 /* setup PLL configuration */
284 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
291 /* ------------------------------------------------------------------ */
293 static int philips_tu1216_pll_60_init(struct dvb_frontend *fe)
295 return philips_tda6651_pll_init(0x60, fe);
298 static int philips_tu1216_pll_60_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
300 return philips_tda6651_pll_set(0x60, fe, params);
303 static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
304 const struct firmware **fw, char *name)
306 struct saa7134_dev *dev = fe->dvb->priv;
307 return request_firmware(fw, name, &dev->pci->dev);
310 static struct tda1004x_config philips_tu1216_60_config = {
312 .demod_address = 0x8,
315 .xtal_freq = TDA10046_XTAL_4M,
316 .agc_config = TDA10046_AGC_DEFAULT,
317 .if_freq = TDA10046_FREQ_3617,
318 .pll_init = philips_tu1216_pll_60_init,
319 .pll_set = philips_tu1216_pll_60_set,
321 .request_firmware = philips_tu1216_request_firmware,
324 /* ------------------------------------------------------------------ */
326 static int philips_tu1216_pll_61_init(struct dvb_frontend *fe)
328 return philips_tda6651_pll_init(0x61, fe);
331 static int philips_tu1216_pll_61_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
333 return philips_tda6651_pll_set(0x61, fe, params);
336 static struct tda1004x_config philips_tu1216_61_config = {
338 .demod_address = 0x8,
341 .xtal_freq = TDA10046_XTAL_4M,
342 .agc_config = TDA10046_AGC_DEFAULT,
343 .if_freq = TDA10046_FREQ_3617,
344 .pll_init = philips_tu1216_pll_61_init,
345 .pll_set = philips_tu1216_pll_61_set,
347 .request_firmware = philips_tu1216_request_firmware,
350 /* ------------------------------------------------------------------ */
352 static int philips_europa_pll_init(struct dvb_frontend *fe)
354 struct saa7134_dev *dev = fe->dvb->priv;
355 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
356 struct i2c_msg init_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
358 /* setup PLL configuration */
359 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
363 /* switch the board to dvb mode */
364 init_msg.addr = 0x43;
368 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
374 static int philips_td1316_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
376 return philips_tda6651_pll_set(0x61, fe, params);
379 static void philips_europa_analog(struct dvb_frontend *fe)
381 struct saa7134_dev *dev = fe->dvb->priv;
382 /* this message actually turns the tuner back to analog mode */
383 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
384 struct i2c_msg analog_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
386 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
389 /* switch the board to analog mode */
390 analog_msg.addr = 0x43;
391 analog_msg.len = 0x02;
394 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
397 static struct tda1004x_config philips_europa_config = {
399 .demod_address = 0x8,
402 .xtal_freq = TDA10046_XTAL_4M,
403 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
404 .if_freq = TDA10046_FREQ_052,
405 .pll_init = philips_europa_pll_init,
406 .pll_set = philips_td1316_pll_set,
407 .pll_sleep = philips_europa_analog,
408 .request_firmware = NULL,
411 /* ------------------------------------------------------------------ */
413 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
415 struct saa7134_dev *dev = fe->dvb->priv;
416 /* this message is to set up ATC and ALC */
417 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
418 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
420 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
427 static void philips_fmd1216_analog(struct dvb_frontend *fe)
429 struct saa7134_dev *dev = fe->dvb->priv;
430 /* this message actually turns the tuner back to analog mode */
431 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
432 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
434 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
436 fmd1216_init[2] = 0x86;
437 fmd1216_init[3] = 0x54;
438 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
442 static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
444 struct saa7134_dev *dev = fe->dvb->priv;
446 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
448 int tuner_frequency = 0;
452 /* determine charge pump */
453 tuner_frequency = params->frequency + 36130000;
454 if (tuner_frequency < 87000000)
457 else if (tuner_frequency < 180000000) {
461 } else if (tuner_frequency < 195000000) {
466 } else if (tuner_frequency < 366000000) {
467 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
474 } else if (tuner_frequency < 478000000) {
475 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
483 } else if (tuner_frequency < 662000000) {
484 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
491 } else if (tuner_frequency < 840000000) {
492 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
500 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
509 /* calculate divisor */
510 /* ((36166000 + Finput) / 166666) rounded! */
511 divider = (tuner_frequency + 83333) / 166667;
513 /* setup tuner buffer */
514 tuner_buf[0] = (divider >> 8) & 0x7f;
515 tuner_buf[1] = divider & 0xff;
516 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
517 tuner_buf[3] = 0x40 | band;
519 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
524 static struct tda1004x_config medion_cardbus = {
525 .demod_address = 0x08,
528 .xtal_freq = TDA10046_XTAL_16M,
529 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
530 .if_freq = TDA10046_FREQ_3613,
531 .pll_init = philips_fmd1216_pll_init,
532 .pll_set = philips_fmd1216_pll_set,
533 .pll_sleep = philips_fmd1216_analog,
534 .request_firmware = NULL,
537 /* ------------------------------------------------------------------ */
539 struct tda827x_data {
549 static struct tda827x_data tda827x_dvbt[] = {
550 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
551 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
552 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
553 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
554 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
555 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
556 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
557 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
558 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
559 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
560 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
561 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
562 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
563 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
564 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
565 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
566 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
567 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
568 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
569 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
570 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
571 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
572 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
573 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
574 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
575 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
576 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
577 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
578 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
581 static int philips_tda827x_pll_init(struct dvb_frontend *fe)
586 static int philips_tda827x_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
588 struct saa7134_dev *dev = fe->dvb->priv;
591 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
592 .len = sizeof(tuner_buf) };
593 int i, tuner_freq, if_freq;
595 switch (params->u.ofdm.bandwidth) {
596 case BANDWIDTH_6_MHZ:
599 case BANDWIDTH_7_MHZ:
602 default: /* 8 MHz or Auto */
606 tuner_freq = params->frequency + if_freq;
609 while (tda827x_dvbt[i].lomax < tuner_freq) {
610 if(tda827x_dvbt[i + 1].lomax == 0)
615 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
617 tuner_buf[1] = (N>>8) | 0x40;
618 tuner_buf[2] = N & 0xff;
621 tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
622 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
623 tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
627 tuner_buf[10] = 0xff;
628 tuner_buf[11] = 0x00;
629 tuner_buf[12] = 0x00;
630 tuner_buf[13] = 0x40;
633 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
637 /* correct CP value */
639 tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
641 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
646 static void philips_tda827x_pll_sleep(struct dvb_frontend *fe)
648 struct saa7134_dev *dev = fe->dvb->priv;
649 static u8 tda827x_sleep[] = { 0x30, 0xd0};
650 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
651 .len = sizeof(tda827x_sleep) };
652 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
655 static struct tda1004x_config tda827x_lifeview_config = {
656 .demod_address = 0x08,
659 .xtal_freq = TDA10046_XTAL_16M,
660 .agc_config = TDA10046_AGC_TDA827X,
661 .if_freq = TDA10046_FREQ_045,
662 .pll_init = philips_tda827x_pll_init,
663 .pll_set = philips_tda827x_pll_set,
664 .pll_sleep = philips_tda827x_pll_sleep,
665 .request_firmware = NULL,
668 /* ------------------------------------------------------------------ */
670 struct tda827xa_data {
679 static struct tda827xa_data tda827xa_dvbt[] = {
680 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
681 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
682 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
683 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
684 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
685 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
686 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
687 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
688 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
689 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
690 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
691 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
692 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
693 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
694 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
695 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
696 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
697 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
698 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
699 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
700 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
701 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
702 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
703 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
704 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
705 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
706 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}};
709 static int philips_tda827xa_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
711 struct saa7134_dev *dev = fe->dvb->priv;
713 unsigned char reg2[2];
715 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = tuner_buf};
716 int i, tuner_freq, if_freq;
719 switch (params->u.ofdm.bandwidth) {
720 case BANDWIDTH_6_MHZ:
723 case BANDWIDTH_7_MHZ:
726 default: /* 8 MHz or Auto */
730 tuner_freq = params->frequency + if_freq;
733 while (tda827xa_dvbt[i].lomax < tuner_freq) {
734 if(tda827xa_dvbt[i + 1].lomax == 0)
739 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
740 tuner_buf[0] = 0; // subaddress
741 tuner_buf[1] = N >> 8;
742 tuner_buf[2] = N & 0xff;
745 tuner_buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
746 tda827xa_dvbt[i].sbs;
747 tuner_buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
751 tuner_buf[10] = 0xff;
752 tuner_buf[11] = 0x60;
753 tuner_buf[12] = 0x00;
754 tuner_buf[13] = 0x39; // lpsel
756 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
763 i2c_transfer(&dev->i2c_adap, &msg, 1);
767 i2c_transfer(&dev->i2c_adap, &msg, 1);
770 /* correct CP value */
772 reg2[1] = 0x10 + tda827xa_dvbt[i].scr;
774 i2c_transfer(&dev->i2c_adap, &msg, 1);
778 reg2[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
779 i2c_transfer(&dev->i2c_adap, &msg, 1);
785 static void philips_tda827xa_pll_sleep(u8 addr, struct dvb_frontend *fe)
787 struct saa7134_dev *dev = fe->dvb->priv;
788 static u8 tda827xa_sleep[] = { 0x30, 0x90};
789 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tda827xa_sleep,
790 .len = sizeof(tda827xa_sleep) };
791 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
795 /* ------------------------------------------------------------------ */
797 static int philips_tiger_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
800 struct saa7134_dev *dev = fe->dvb->priv;
801 static u8 tda8290_close[] = { 0x21, 0xc0};
802 static u8 tda8290_open[] = { 0x21, 0x80};
803 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
804 /* close tda8290 i2c bridge */
805 tda8290_msg.buf = tda8290_close;
806 ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
810 ret = philips_tda827xa_pll_set(0x61, fe, params);
813 /* open tda8290 i2c bridge */
814 tda8290_msg.buf = tda8290_open;
815 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
819 static int philips_tiger_dvb_mode(struct dvb_frontend *fe)
821 struct saa7134_dev *dev = fe->dvb->priv;
822 static u8 data[] = { 0x3c, 0x33, 0x6a};
823 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
825 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
830 static void philips_tiger_analog_mode(struct dvb_frontend *fe)
832 struct saa7134_dev *dev = fe->dvb->priv;
833 static u8 data[] = { 0x3c, 0x33, 0x68};
834 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
836 i2c_transfer(&dev->i2c_adap, &msg, 1);
837 philips_tda827xa_pll_sleep( 0x61, fe);
840 static struct tda1004x_config philips_tiger_config = {
841 .demod_address = 0x08,
844 .xtal_freq = TDA10046_XTAL_16M,
845 .agc_config = TDA10046_AGC_TDA827X,
846 .if_freq = TDA10046_FREQ_045,
847 .pll_init = philips_tiger_dvb_mode,
848 .pll_set = philips_tiger_pll_set,
849 .pll_sleep = philips_tiger_analog_mode,
850 .request_firmware = NULL,
853 /* ------------------------------------------------------------------ */
855 static int lifeview_trio_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
859 ret = philips_tda827xa_pll_set(0x60, fe, params);
863 static int lifeview_trio_dvb_mode(struct dvb_frontend *fe)
868 static void lifeview_trio_analog_mode(struct dvb_frontend *fe)
870 philips_tda827xa_pll_sleep(0x60, fe);
873 static struct tda1004x_config lifeview_trio_config = {
874 .demod_address = 0x09,
877 .xtal_freq = TDA10046_XTAL_16M,
878 .agc_config = TDA10046_AGC_TDA827X_GPL,
879 .if_freq = TDA10046_FREQ_045,
880 .pll_init = lifeview_trio_dvb_mode,
881 .pll_set = lifeview_trio_pll_set,
882 .pll_sleep = lifeview_trio_analog_mode,
883 .request_firmware = NULL,
886 /* ------------------------------------------------------------------ */
888 static int ads_duo_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
892 ret = philips_tda827xa_pll_set(0x61, fe, params);
896 static int ads_duo_dvb_mode(struct dvb_frontend *fe)
898 struct saa7134_dev *dev = fe->dvb->priv;
899 /* route TDA8275a AGC input to the channel decoder */
900 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x60);
904 static void ads_duo_analog_mode(struct dvb_frontend *fe)
906 struct saa7134_dev *dev = fe->dvb->priv;
907 /* route TDA8275a AGC input to the analog IF chip*/
908 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x20);
909 philips_tda827xa_pll_sleep( 0x61, fe);
912 static struct tda1004x_config ads_tech_duo_config = {
913 .demod_address = 0x08,
916 .xtal_freq = TDA10046_XTAL_16M,
917 .agc_config = TDA10046_AGC_TDA827X_GPL,
918 .if_freq = TDA10046_FREQ_045,
919 .pll_init = ads_duo_dvb_mode,
920 .pll_set = ads_duo_pll_set,
921 .pll_sleep = ads_duo_analog_mode,
922 .request_firmware = NULL,
925 /* ------------------------------------------------------------------ */
927 static int tevion_dvb220rf_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
930 ret = philips_tda827xa_pll_set(0x60, fe, params);
934 static int tevion_dvb220rf_pll_init(struct dvb_frontend *fe)
939 static void tevion_dvb220rf_pll_sleep(struct dvb_frontend *fe)
941 philips_tda827xa_pll_sleep( 0x61, fe);
944 static struct tda1004x_config tevion_dvbt220rf_config = {
945 .demod_address = 0x08,
948 .xtal_freq = TDA10046_XTAL_16M,
949 .agc_config = TDA10046_AGC_TDA827X,
950 .if_freq = TDA10046_FREQ_045,
951 .pll_init = tevion_dvb220rf_pll_init,
952 .pll_set = tevion_dvb220rf_pll_set,
953 .pll_sleep = tevion_dvb220rf_pll_sleep,
954 .request_firmware = NULL,
959 /* ------------------------------------------------------------------ */
962 static struct nxt200x_config avertvhda180 = {
963 .demod_address = 0x0a,
965 .pll_desc = &dvb_pll_tdhu2,
968 static int nxt200x_set_pll_input(u8 *buf, int input)
977 static struct nxt200x_config kworldatsc110 = {
978 .demod_address = 0x0a,
980 .pll_desc = &dvb_pll_tuv1236d,
981 .set_pll_input = nxt200x_set_pll_input,
985 /* ------------------------------------------------------------------ */
987 static int dvb_init(struct saa7134_dev *dev)
989 /* init struct videobuf_dvb */
990 dev->ts.nr_bufs = 32;
991 dev->ts.nr_packets = 32*4;
992 dev->dvb.name = dev->name;
993 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
994 dev->pci, &dev->slock,
995 V4L2_BUF_TYPE_VIDEO_CAPTURE,
996 V4L2_FIELD_ALTERNATE,
997 sizeof(struct saa7134_buf),
1000 switch (dev->board) {
1002 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1003 printk("%s: pinnacle 300i dvb setup\n",dev->name);
1004 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
1008 case SAA7134_BOARD_AVERMEDIA_777:
1009 printk("%s: avertv 777 dvb setup\n",dev->name);
1010 dev->dvb.frontend = mt352_attach(&avermedia_777,
1014 #ifdef HAVE_TDA1004X
1015 case SAA7134_BOARD_MD7134:
1016 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1019 case SAA7134_BOARD_PHILIPS_TOUGH:
1020 dev->dvb.frontend = tda10046_attach(&philips_tu1216_60_config,
1023 case SAA7134_BOARD_FLYDVBTDUO:
1024 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1027 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1028 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1031 case SAA7134_BOARD_PHILIPS_EUROPA:
1032 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
1035 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1036 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
1039 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1040 dev->dvb.frontend = tda10046_attach(&philips_tu1216_61_config,
1043 case SAA7134_BOARD_PHILIPS_TIGER:
1044 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
1047 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1048 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
1051 case SAA7134_BOARD_FLYDVBT_LR301:
1052 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1055 case SAA7134_BOARD_FLYDVB_TRIO:
1056 dev->dvb.frontend = tda10046_attach(&lifeview_trio_config,
1059 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1060 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1063 case SAA7134_BOARD_TEVION_DVBT_220RF:
1064 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config,
1067 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1068 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1073 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1074 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap);
1076 case SAA7134_BOARD_KWORLD_ATSC110:
1077 dev->dvb.frontend = nxt200x_attach(&kworldatsc110, &dev->i2c_adap);
1081 printk("%s: Huh? unknown DVB card?\n",dev->name);
1085 if (NULL == dev->dvb.frontend) {
1086 printk("%s: frontend initialization failed\n",dev->name);
1090 /* register everything else */
1091 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
1094 static int dvb_fini(struct saa7134_dev *dev)
1096 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1098 switch (dev->board) {
1099 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1100 /* otherwise we don't detect the tuner on next insmod */
1101 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1104 videobuf_dvb_unregister(&dev->dvb);
1108 static struct saa7134_mpeg_ops dvb_ops = {
1109 .type = SAA7134_MPEG_DVB,
1114 static int __init dvb_register(void)
1116 return saa7134_ts_register(&dvb_ops);
1119 static void __exit dvb_unregister(void)
1121 saa7134_ts_unregister(&dvb_ops);
1124 module_init(dvb_register);
1125 module_exit(dvb_unregister);
1127 /* ------------------------------------------------------------------ */