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));
116 static int mt352_aver777_init(struct dvb_frontend* fe)
118 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
119 static u8 reset [] = { RESET, 0x80 };
120 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
121 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
122 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
124 mt352_write(fe, clock_config, sizeof(clock_config));
126 mt352_write(fe, reset, sizeof(reset));
127 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
128 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
129 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
134 static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
135 struct dvb_frontend_parameters* params,
138 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
139 static int off = TDA9887_PRESENT | TDA9887_PORT2_ACTIVE;
140 struct saa7134_dev *dev = fe->dvb->priv;
141 struct v4l2_frequency f;
143 /* set frequency (mt2050) */
145 f.type = V4L2_TUNER_DIGITAL_TV;
146 f.frequency = params->frequency / 1000 * 16 / 1000;
147 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
148 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
149 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&off);
151 pinnacle_antenna_pwr(dev, antenna_pwr);
154 mt352_pinnacle_init(fe);
163 static int mt352_aver777_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf)
166 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
168 params->u.ofdm.bandwidth);
172 static struct mt352_config pinnacle_300i = {
173 .demod_address = 0x3c >> 1,
177 .demod_init = mt352_pinnacle_init,
178 .pll_set = mt352_pinnacle_pll_set,
181 static struct mt352_config avermedia_777 = {
182 .demod_address = 0xf,
183 .demod_init = mt352_aver777_init,
184 .pll_set = mt352_aver777_pll_set,
188 /* ------------------------------------------------------------------ */
192 static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
194 struct saa7134_dev *dev = fe->dvb->priv;
196 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
198 int tuner_frequency = 0;
201 /* determine charge pump */
202 tuner_frequency = params->frequency + 36166000;
203 if (tuner_frequency < 87000000)
205 else if (tuner_frequency < 130000000)
207 else if (tuner_frequency < 160000000)
209 else if (tuner_frequency < 200000000)
211 else if (tuner_frequency < 290000000)
213 else if (tuner_frequency < 420000000)
215 else if (tuner_frequency < 480000000)
217 else if (tuner_frequency < 620000000)
219 else if (tuner_frequency < 830000000)
221 else if (tuner_frequency < 895000000)
227 if (params->frequency < 49000000)
229 else if (params->frequency < 161000000)
231 else if (params->frequency < 444000000)
233 else if (params->frequency < 861000000)
238 /* setup PLL filter */
239 switch (params->u.ofdm.bandwidth) {
240 case BANDWIDTH_6_MHZ:
244 case BANDWIDTH_7_MHZ:
248 case BANDWIDTH_8_MHZ:
257 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
259 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
261 /* setup tuner buffer */
262 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
263 tuner_buf[1] = tuner_frequency & 0xff;
265 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
267 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
273 static int philips_tda6651_pll_init(u8 addr, struct dvb_frontend *fe)
275 struct saa7134_dev *dev = fe->dvb->priv;
276 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
277 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
279 /* setup PLL configuration */
280 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
287 /* ------------------------------------------------------------------ */
289 static int philips_tu1216_pll_60_init(struct dvb_frontend *fe)
291 return philips_tda6651_pll_init(0x60, fe);
294 static int philips_tu1216_pll_60_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
296 return philips_tda6651_pll_set(0x60, fe, params);
299 static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
300 const struct firmware **fw, char *name)
302 struct saa7134_dev *dev = fe->dvb->priv;
303 return request_firmware(fw, name, &dev->pci->dev);
306 static struct tda1004x_config philips_tu1216_60_config = {
308 .demod_address = 0x8,
311 .xtal_freq = TDA10046_XTAL_4M,
312 .agc_config = TDA10046_AGC_DEFAULT,
313 .if_freq = TDA10046_FREQ_3617,
314 .pll_init = philips_tu1216_pll_60_init,
315 .pll_set = philips_tu1216_pll_60_set,
317 .request_firmware = philips_tu1216_request_firmware,
320 /* ------------------------------------------------------------------ */
322 static int philips_tu1216_pll_61_init(struct dvb_frontend *fe)
324 return philips_tda6651_pll_init(0x61, fe);
327 static int philips_tu1216_pll_61_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
329 return philips_tda6651_pll_set(0x61, fe, params);
332 static struct tda1004x_config philips_tu1216_61_config = {
334 .demod_address = 0x8,
337 .xtal_freq = TDA10046_XTAL_4M,
338 .agc_config = TDA10046_AGC_DEFAULT,
339 .if_freq = TDA10046_FREQ_3617,
340 .pll_init = philips_tu1216_pll_61_init,
341 .pll_set = philips_tu1216_pll_61_set,
343 .request_firmware = philips_tu1216_request_firmware,
346 /* ------------------------------------------------------------------ */
348 static int philips_europa_pll_init(struct dvb_frontend *fe)
350 struct saa7134_dev *dev = fe->dvb->priv;
351 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
352 struct i2c_msg init_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
354 /* setup PLL configuration */
355 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
359 /* switch the board to dvb mode */
360 init_msg.addr = 0x43;
364 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
370 static int philips_td1316_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
372 return philips_tda6651_pll_set(0x61, fe, params);
375 static void philips_europa_analog(struct dvb_frontend *fe)
377 struct saa7134_dev *dev = fe->dvb->priv;
378 /* this message actually turns the tuner back to analog mode */
379 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
380 struct i2c_msg analog_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
382 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
385 /* switch the board to analog mode */
386 analog_msg.addr = 0x43;
387 analog_msg.len = 0x02;
390 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
393 static struct tda1004x_config philips_europa_config = {
395 .demod_address = 0x8,
398 .xtal_freq = TDA10046_XTAL_4M,
399 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
400 .if_freq = TDA10046_FREQ_052,
401 .pll_init = philips_europa_pll_init,
402 .pll_set = philips_td1316_pll_set,
403 .pll_sleep = philips_europa_analog,
404 .request_firmware = NULL,
407 /* ------------------------------------------------------------------ */
409 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
411 struct saa7134_dev *dev = fe->dvb->priv;
412 /* this message is to set up ATC and ALC */
413 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
414 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
416 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
423 static void philips_fmd1216_analog(struct dvb_frontend *fe)
425 struct saa7134_dev *dev = fe->dvb->priv;
426 /* this message actually turns the tuner back to analog mode */
427 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
428 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
430 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
432 fmd1216_init[2] = 0x86;
433 fmd1216_init[3] = 0x54;
434 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
438 static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
440 struct saa7134_dev *dev = fe->dvb->priv;
442 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
444 int tuner_frequency = 0;
448 /* determine charge pump */
449 tuner_frequency = params->frequency + 36130000;
450 if (tuner_frequency < 87000000)
453 else if (tuner_frequency < 180000000) {
457 } else if (tuner_frequency < 195000000) {
462 } else if (tuner_frequency < 366000000) {
463 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
470 } else if (tuner_frequency < 478000000) {
471 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
479 } else if (tuner_frequency < 662000000) {
480 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
487 } else if (tuner_frequency < 840000000) {
488 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
496 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
505 /* calculate divisor */
506 /* ((36166000 + Finput) / 166666) rounded! */
507 divider = (tuner_frequency + 83333) / 166667;
509 /* setup tuner buffer */
510 tuner_buf[0] = (divider >> 8) & 0x7f;
511 tuner_buf[1] = divider & 0xff;
512 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
513 tuner_buf[3] = 0x40 | band;
515 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
520 static struct tda1004x_config medion_cardbus = {
521 .demod_address = 0x08,
524 .xtal_freq = TDA10046_XTAL_16M,
525 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
526 .if_freq = TDA10046_FREQ_3613,
527 .pll_init = philips_fmd1216_pll_init,
528 .pll_set = philips_fmd1216_pll_set,
529 .pll_sleep = philips_fmd1216_analog,
530 .request_firmware = NULL,
533 /* ------------------------------------------------------------------ */
535 struct tda827x_data {
545 static struct tda827x_data tda827x_dvbt[] = {
546 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
547 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
548 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
549 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
550 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
551 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
552 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
553 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
554 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
555 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
556 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
557 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
558 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
559 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
560 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
561 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
562 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
563 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
564 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
565 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
566 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
567 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
568 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
569 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
570 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
571 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
572 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
573 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
574 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
577 static int philips_tda827x_pll_init(struct dvb_frontend *fe)
582 static int philips_tda827x_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
584 struct saa7134_dev *dev = fe->dvb->priv;
587 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
588 .len = sizeof(tuner_buf) };
589 int i, tuner_freq, if_freq;
591 switch (params->u.ofdm.bandwidth) {
592 case BANDWIDTH_6_MHZ:
595 case BANDWIDTH_7_MHZ:
598 default: /* 8 MHz or Auto */
602 tuner_freq = params->frequency + if_freq;
605 while (tda827x_dvbt[i].lomax < tuner_freq) {
606 if(tda827x_dvbt[i + 1].lomax == 0)
611 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
613 tuner_buf[1] = (N>>8) | 0x40;
614 tuner_buf[2] = N & 0xff;
617 tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
618 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
619 tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
623 tuner_buf[10] = 0xff;
624 tuner_buf[11] = 0x00;
625 tuner_buf[12] = 0x00;
626 tuner_buf[13] = 0x40;
629 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
633 /* correct CP value */
635 tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
637 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
642 static void philips_tda827x_pll_sleep(struct dvb_frontend *fe)
644 struct saa7134_dev *dev = fe->dvb->priv;
645 static u8 tda827x_sleep[] = { 0x30, 0xd0};
646 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
647 .len = sizeof(tda827x_sleep) };
648 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
651 static struct tda1004x_config tda827x_lifeview_config = {
652 .demod_address = 0x08,
655 .xtal_freq = TDA10046_XTAL_16M,
656 .agc_config = TDA10046_AGC_TDA827X,
657 .if_freq = TDA10046_FREQ_045,
658 .pll_init = philips_tda827x_pll_init,
659 .pll_set = philips_tda827x_pll_set,
660 .pll_sleep = philips_tda827x_pll_sleep,
661 .request_firmware = NULL,
664 /* ------------------------------------------------------------------ */
666 struct tda827xa_data {
675 static struct tda827xa_data tda827xa_dvbt[] = {
676 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
677 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
678 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
679 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
680 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
681 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
682 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
683 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
684 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
685 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
686 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
687 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
688 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
689 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
690 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
691 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
692 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
693 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
694 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
695 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
696 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
697 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
698 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
699 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
700 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
701 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
702 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}};
705 static int philips_tda827xa_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
707 struct saa7134_dev *dev = fe->dvb->priv;
709 unsigned char reg2[2];
711 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = tuner_buf};
712 int i, tuner_freq, if_freq;
715 switch (params->u.ofdm.bandwidth) {
716 case BANDWIDTH_6_MHZ:
719 case BANDWIDTH_7_MHZ:
722 default: /* 8 MHz or Auto */
726 tuner_freq = params->frequency + if_freq;
729 while (tda827xa_dvbt[i].lomax < tuner_freq) {
730 if(tda827xa_dvbt[i + 1].lomax == 0)
735 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
736 tuner_buf[0] = 0; // subaddress
737 tuner_buf[1] = N >> 8;
738 tuner_buf[2] = N & 0xff;
741 tuner_buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
742 tda827xa_dvbt[i].sbs;
743 tuner_buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
747 tuner_buf[10] = 0xff;
748 tuner_buf[11] = 0x60;
749 tuner_buf[12] = 0x00;
750 tuner_buf[13] = 0x39; // lpsel
752 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
759 i2c_transfer(&dev->i2c_adap, &msg, 1);
763 i2c_transfer(&dev->i2c_adap, &msg, 1);
766 /* correct CP value */
768 reg2[1] = 0x10 + tda827xa_dvbt[i].scr;
770 i2c_transfer(&dev->i2c_adap, &msg, 1);
774 reg2[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
775 i2c_transfer(&dev->i2c_adap, &msg, 1);
781 static void philips_tda827xa_pll_sleep(u8 addr, struct dvb_frontend *fe)
783 struct saa7134_dev *dev = fe->dvb->priv;
784 static u8 tda827xa_sleep[] = { 0x30, 0x90};
785 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tda827xa_sleep,
786 .len = sizeof(tda827xa_sleep) };
787 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
791 /* ------------------------------------------------------------------ */
793 static int philips_tiger_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
796 struct saa7134_dev *dev = fe->dvb->priv;
797 static u8 tda8290_close[] = { 0x21, 0xc0};
798 static u8 tda8290_open[] = { 0x21, 0x80};
799 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
800 /* close tda8290 i2c bridge */
801 tda8290_msg.buf = tda8290_close;
802 ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
806 ret = philips_tda827xa_pll_set(0x61, fe, params);
809 /* open tda8290 i2c bridge */
810 tda8290_msg.buf = tda8290_open;
811 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
815 static int philips_tiger_dvb_mode(struct dvb_frontend *fe)
817 struct saa7134_dev *dev = fe->dvb->priv;
818 static u8 data[] = { 0x3c, 0x33, 0x6a};
819 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
821 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
826 static void philips_tiger_analog_mode(struct dvb_frontend *fe)
828 struct saa7134_dev *dev = fe->dvb->priv;
829 static u8 data[] = { 0x3c, 0x33, 0x68};
830 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
832 i2c_transfer(&dev->i2c_adap, &msg, 1);
833 philips_tda827xa_pll_sleep( 0x61, fe);
836 static struct tda1004x_config philips_tiger_config = {
837 .demod_address = 0x08,
840 .xtal_freq = TDA10046_XTAL_16M,
841 .agc_config = TDA10046_AGC_TDA827X,
842 .if_freq = TDA10046_FREQ_045,
843 .pll_init = philips_tiger_dvb_mode,
844 .pll_set = philips_tiger_pll_set,
845 .pll_sleep = philips_tiger_analog_mode,
846 .request_firmware = NULL,
849 /* ------------------------------------------------------------------ */
851 static int ads_duo_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
855 ret = philips_tda827xa_pll_set(0x61, fe, params);
859 static int ads_duo_dvb_mode(struct dvb_frontend *fe)
861 struct saa7134_dev *dev = fe->dvb->priv;
862 /* route TDA8275a AGC input to the channel decoder */
863 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x60);
867 static void ads_duo_analog_mode(struct dvb_frontend *fe)
869 struct saa7134_dev *dev = fe->dvb->priv;
870 /* route TDA8275a AGC input to the analog IF chip*/
871 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x20);
872 philips_tda827xa_pll_sleep( 0x61, fe);
875 static struct tda1004x_config ads_tech_duo_config = {
876 .demod_address = 0x08,
879 .xtal_freq = TDA10046_XTAL_16M,
880 .agc_config = TDA10046_AGC_TDA827X_GPL,
881 .if_freq = TDA10046_FREQ_045,
882 .pll_init = ads_duo_dvb_mode,
883 .pll_set = ads_duo_pll_set,
884 .pll_sleep = ads_duo_analog_mode,
885 .request_firmware = NULL,
888 /* ------------------------------------------------------------------ */
890 static int tevion_dvb220rf_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
893 ret = philips_tda827xa_pll_set(0x60, fe, params);
897 static int tevion_dvb220rf_pll_init(struct dvb_frontend *fe)
902 static void tevion_dvb220rf_pll_sleep(struct dvb_frontend *fe)
904 philips_tda827xa_pll_sleep( 0x61, fe);
907 static struct tda1004x_config tevion_dvbt220rf_config = {
908 .demod_address = 0x08,
911 .xtal_freq = TDA10046_XTAL_16M,
912 .agc_config = TDA10046_AGC_TDA827X,
913 .if_freq = TDA10046_FREQ_045,
914 .pll_init = tevion_dvb220rf_pll_init,
915 .pll_set = tevion_dvb220rf_pll_set,
916 .pll_sleep = tevion_dvb220rf_pll_sleep,
917 .request_firmware = NULL,
922 /* ------------------------------------------------------------------ */
925 static struct nxt200x_config avertvhda180 = {
926 .demod_address = 0x0a,
928 .pll_desc = &dvb_pll_tdhu2,
931 static int nxt200x_set_pll_input(u8 *buf, int input)
940 static struct nxt200x_config kworldatsc110 = {
941 .demod_address = 0x0a,
943 .pll_desc = &dvb_pll_tuv1236d,
944 .set_pll_input = nxt200x_set_pll_input,
948 /* ------------------------------------------------------------------ */
950 static int dvb_init(struct saa7134_dev *dev)
952 /* init struct videobuf_dvb */
953 dev->ts.nr_bufs = 32;
954 dev->ts.nr_packets = 32*4;
955 dev->dvb.name = dev->name;
956 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
957 dev->pci, &dev->slock,
958 V4L2_BUF_TYPE_VIDEO_CAPTURE,
959 V4L2_FIELD_ALTERNATE,
960 sizeof(struct saa7134_buf),
963 switch (dev->board) {
965 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
966 printk("%s: pinnacle 300i dvb setup\n",dev->name);
967 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
971 case SAA7134_BOARD_AVERMEDIA_777:
972 printk("%s: avertv 777 dvb setup\n",dev->name);
973 dev->dvb.frontend = mt352_attach(&avermedia_777,
978 case SAA7134_BOARD_MD7134:
979 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
982 case SAA7134_BOARD_PHILIPS_TOUGH:
983 dev->dvb.frontend = tda10046_attach(&philips_tu1216_60_config,
986 case SAA7134_BOARD_FLYDVBTDUO:
987 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
990 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
991 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
994 case SAA7134_BOARD_PHILIPS_EUROPA:
995 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
998 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
999 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
1002 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1003 dev->dvb.frontend = tda10046_attach(&philips_tu1216_61_config,
1006 case SAA7134_BOARD_PHILIPS_TIGER:
1007 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
1010 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1011 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
1014 case SAA7134_BOARD_FLYDVBT_LR301:
1015 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1018 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1019 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1022 case SAA7134_BOARD_TEVION_DVBT_220RF:
1023 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config,
1028 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1029 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap);
1031 case SAA7134_BOARD_KWORLD_ATSC110:
1032 dev->dvb.frontend = nxt200x_attach(&kworldatsc110, &dev->i2c_adap);
1036 printk("%s: Huh? unknown DVB card?\n",dev->name);
1040 if (NULL == dev->dvb.frontend) {
1041 printk("%s: frontend initialization failed\n",dev->name);
1045 /* register everything else */
1046 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
1049 static int dvb_fini(struct saa7134_dev *dev)
1051 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1053 switch (dev->board) {
1054 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1055 /* otherwise we don't detect the tuner on next insmod */
1056 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1059 videobuf_dvb_unregister(&dev->dvb);
1063 static struct saa7134_mpeg_ops dvb_ops = {
1064 .type = SAA7134_MPEG_DVB,
1069 static int __init dvb_register(void)
1071 return saa7134_ts_register(&dvb_ops);
1074 static void __exit dvb_unregister(void)
1076 saa7134_ts_unregister(&dvb_ops);
1079 module_init(dvb_register);
1080 module_exit(dvb_unregister);
1082 /* ------------------------------------------------------------------ */