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_tuner_pllbuf(struct dvb_frontend* fe,
136 struct dvb_frontend_parameters* params,
137 u8* pllbuf, int buf_len)
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;
149 /* set frequency (mt2050) */
151 f.type = V4L2_TUNER_DIGITAL_TV;
152 f.frequency = params->frequency / 1000 * 16 / 1000;
153 i2c_transfer(&dev->i2c_adap, &msg, 1);
154 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
156 i2c_transfer(&dev->i2c_adap, &msg, 1);
158 pinnacle_antenna_pwr(dev, antenna_pwr);
161 mt352_pinnacle_init(fe);
170 static int mt352_aver777_tuner_pllbuf(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
176 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
178 params->u.ofdm.bandwidth);
182 static struct mt352_config pinnacle_300i = {
183 .demod_address = 0x3c >> 1,
187 .demod_init = mt352_pinnacle_init,
190 static struct mt352_config avermedia_777 = {
191 .demod_address = 0xf,
192 .demod_init = mt352_aver777_init,
196 /* ------------------------------------------------------------------ */
200 static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
202 struct saa7134_dev *dev = fe->dvb->priv;
204 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
206 int tuner_frequency = 0;
209 /* determine charge pump */
210 tuner_frequency = params->frequency + 36166000;
211 if (tuner_frequency < 87000000)
213 else if (tuner_frequency < 130000000)
215 else if (tuner_frequency < 160000000)
217 else if (tuner_frequency < 200000000)
219 else if (tuner_frequency < 290000000)
221 else if (tuner_frequency < 420000000)
223 else if (tuner_frequency < 480000000)
225 else if (tuner_frequency < 620000000)
227 else if (tuner_frequency < 830000000)
229 else if (tuner_frequency < 895000000)
235 if (params->frequency < 49000000)
237 else if (params->frequency < 161000000)
239 else if (params->frequency < 444000000)
241 else if (params->frequency < 861000000)
246 /* setup PLL filter */
247 switch (params->u.ofdm.bandwidth) {
248 case BANDWIDTH_6_MHZ:
252 case BANDWIDTH_7_MHZ:
256 case BANDWIDTH_8_MHZ:
265 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
267 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
269 /* setup tuner buffer */
270 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
271 tuner_buf[1] = tuner_frequency & 0xff;
273 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
275 if (fe->ops->i2c_gate_ctrl)
276 fe->ops->i2c_gate_ctrl(fe, 1);
277 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
283 static int philips_tda6651_pll_init(u8 addr, struct dvb_frontend *fe)
285 struct saa7134_dev *dev = fe->dvb->priv;
286 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
287 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
289 /* setup PLL configuration */
290 if (fe->ops->i2c_gate_ctrl)
291 fe->ops->i2c_gate_ctrl(fe, 1);
292 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
299 /* ------------------------------------------------------------------ */
301 static int philips_tu1216_tuner_60_init(struct dvb_frontend *fe)
303 return philips_tda6651_pll_init(0x60, fe);
306 static int philips_tu1216_tuner_60_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
308 return philips_tda6651_pll_set(0x60, fe, params);
311 static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
312 const struct firmware **fw, char *name)
314 struct saa7134_dev *dev = fe->dvb->priv;
315 return request_firmware(fw, name, &dev->pci->dev);
318 static struct tda1004x_config philips_tu1216_60_config = {
320 .demod_address = 0x8,
323 .xtal_freq = TDA10046_XTAL_4M,
324 .agc_config = TDA10046_AGC_DEFAULT,
325 .if_freq = TDA10046_FREQ_3617,
326 .request_firmware = philips_tu1216_request_firmware,
329 /* ------------------------------------------------------------------ */
331 static int philips_tu1216_tuner_61_init(struct dvb_frontend *fe)
333 return philips_tda6651_pll_init(0x61, fe);
336 static int philips_tu1216_tuner_61_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
338 return philips_tda6651_pll_set(0x61, fe, params);
341 static struct tda1004x_config philips_tu1216_61_config = {
343 .demod_address = 0x8,
346 .xtal_freq = TDA10046_XTAL_4M,
347 .agc_config = TDA10046_AGC_DEFAULT,
348 .if_freq = TDA10046_FREQ_3617,
349 .request_firmware = philips_tu1216_request_firmware,
352 /* ------------------------------------------------------------------ */
354 static int philips_europa_tuner_init(struct dvb_frontend *fe)
356 struct saa7134_dev *dev = fe->dvb->priv;
357 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
358 struct i2c_msg init_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
360 /* setup PLL configuration */
361 if (fe->ops->i2c_gate_ctrl)
362 fe->ops->i2c_gate_ctrl(fe, 1);
363 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
367 /* switch the board to dvb mode */
368 init_msg.addr = 0x43;
372 if (fe->ops->i2c_gate_ctrl)
373 fe->ops->i2c_gate_ctrl(fe, 1);
374 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
380 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
382 return philips_tda6651_pll_set(0x61, fe, params);
385 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
387 struct saa7134_dev *dev = fe->dvb->priv;
388 /* this message actually turns the tuner back to analog mode */
389 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
390 struct i2c_msg analog_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
392 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
395 /* switch the board to analog mode */
396 analog_msg.addr = 0x43;
397 analog_msg.len = 0x02;
400 if (fe->ops->i2c_gate_ctrl)
401 fe->ops->i2c_gate_ctrl(fe, 1);
402 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
406 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
408 struct saa7134_dev *dev = fe->dvb->priv;
410 if (dev->original_demod_sleep)
411 dev->original_demod_sleep(fe);
412 fe->ops->i2c_gate_ctrl(fe, 1);
416 static struct tda1004x_config philips_europa_config = {
418 .demod_address = 0x8,
421 .xtal_freq = TDA10046_XTAL_4M,
422 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
423 .if_freq = TDA10046_FREQ_052,
424 .request_firmware = NULL,
427 /* ------------------------------------------------------------------ */
429 static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
431 struct saa7134_dev *dev = fe->dvb->priv;
432 /* this message is to set up ATC and ALC */
433 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
434 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
436 if (fe->ops->i2c_gate_ctrl)
437 fe->ops->i2c_gate_ctrl(fe, 1);
438 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
445 static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
447 struct saa7134_dev *dev = fe->dvb->priv;
448 /* this message actually turns the tuner back to analog mode */
449 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
450 struct i2c_msg tuner_msg = {.addr = 0x61,.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 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
456 fmd1216_init[2] = 0x86;
457 fmd1216_init[3] = 0x54;
458 if (fe->ops->i2c_gate_ctrl)
459 fe->ops->i2c_gate_ctrl(fe, 1);
460 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
465 static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
467 struct saa7134_dev *dev = fe->dvb->priv;
469 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
471 int tuner_frequency = 0;
475 /* determine charge pump */
476 tuner_frequency = params->frequency + 36130000;
477 if (tuner_frequency < 87000000)
480 else if (tuner_frequency < 180000000) {
484 } else if (tuner_frequency < 195000000) {
489 } else if (tuner_frequency < 366000000) {
490 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
497 } else if (tuner_frequency < 478000000) {
498 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
506 } else if (tuner_frequency < 662000000) {
507 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
514 } else if (tuner_frequency < 840000000) {
515 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
523 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
532 /* calculate divisor */
533 /* ((36166000 + Finput) / 166666) rounded! */
534 divider = (tuner_frequency + 83333) / 166667;
536 /* setup tuner buffer */
537 tuner_buf[0] = (divider >> 8) & 0x7f;
538 tuner_buf[1] = divider & 0xff;
539 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
540 tuner_buf[3] = 0x40 | band;
542 if (fe->ops->i2c_gate_ctrl)
543 fe->ops->i2c_gate_ctrl(fe, 1);
544 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
549 static struct tda1004x_config medion_cardbus = {
550 .demod_address = 0x08,
553 .xtal_freq = TDA10046_XTAL_16M,
554 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
555 .if_freq = TDA10046_FREQ_3613,
556 .request_firmware = NULL,
559 /* ------------------------------------------------------------------ */
561 struct tda827x_data {
571 static struct tda827x_data tda827x_dvbt[] = {
572 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
573 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
574 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
575 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
576 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
577 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
578 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
579 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
580 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
581 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
582 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
583 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
584 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
585 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
586 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
587 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
588 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
589 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
590 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
591 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
592 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
593 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
594 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
595 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
596 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
597 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
598 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
599 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
600 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
603 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
608 static int philips_tda827x_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
610 struct saa7134_dev *dev = fe->dvb->priv;
613 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
614 .len = sizeof(tuner_buf) };
615 int i, tuner_freq, if_freq;
617 switch (params->u.ofdm.bandwidth) {
618 case BANDWIDTH_6_MHZ:
621 case BANDWIDTH_7_MHZ:
624 default: /* 8 MHz or Auto */
628 tuner_freq = params->frequency + if_freq;
631 while (tda827x_dvbt[i].lomax < tuner_freq) {
632 if(tda827x_dvbt[i + 1].lomax == 0)
637 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
639 tuner_buf[1] = (N>>8) | 0x40;
640 tuner_buf[2] = N & 0xff;
643 tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
644 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
645 tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
649 tuner_buf[10] = 0xff;
650 tuner_buf[11] = 0x00;
651 tuner_buf[12] = 0x00;
652 tuner_buf[13] = 0x40;
655 if (fe->ops->i2c_gate_ctrl)
656 fe->ops->i2c_gate_ctrl(fe, 1);
657 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
661 /* correct CP value */
663 tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
665 if (fe->ops->i2c_gate_ctrl)
666 fe->ops->i2c_gate_ctrl(fe, 1);
667 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
672 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
674 struct saa7134_dev *dev = fe->dvb->priv;
675 static u8 tda827x_sleep[] = { 0x30, 0xd0};
676 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
677 .len = sizeof(tda827x_sleep) };
678 if (fe->ops->i2c_gate_ctrl)
679 fe->ops->i2c_gate_ctrl(fe, 1);
680 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
684 static struct tda1004x_config tda827x_lifeview_config = {
685 .demod_address = 0x08,
688 .xtal_freq = TDA10046_XTAL_16M,
689 .agc_config = TDA10046_AGC_TDA827X,
690 .if_freq = TDA10046_FREQ_045,
691 .request_firmware = NULL,
694 /* ------------------------------------------------------------------ */
696 struct tda827xa_data {
705 static struct tda827xa_data tda827xa_dvbt[] = {
706 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
707 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
708 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
709 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
710 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
711 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
712 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
713 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
714 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
715 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
716 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
717 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
718 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
719 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
720 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
721 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
722 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
723 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
724 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
725 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
726 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
727 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
728 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
729 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
730 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
731 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
732 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}};
735 static int philips_tda827xa_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
737 struct saa7134_dev *dev = fe->dvb->priv;
739 unsigned char reg2[2];
741 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = tuner_buf};
742 int i, tuner_freq, if_freq;
745 switch (params->u.ofdm.bandwidth) {
746 case BANDWIDTH_6_MHZ:
749 case BANDWIDTH_7_MHZ:
752 default: /* 8 MHz or Auto */
756 tuner_freq = params->frequency + if_freq;
759 while (tda827xa_dvbt[i].lomax < tuner_freq) {
760 if(tda827xa_dvbt[i + 1].lomax == 0)
765 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
766 tuner_buf[0] = 0; // subaddress
767 tuner_buf[1] = N >> 8;
768 tuner_buf[2] = N & 0xff;
771 tuner_buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
772 tda827xa_dvbt[i].sbs;
773 tuner_buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
777 tuner_buf[10] = 0xff;
778 tuner_buf[11] = 0x60;
779 tuner_buf[12] = 0x00;
780 tuner_buf[13] = 0x39; // lpsel
782 if (fe->ops->i2c_gate_ctrl)
783 fe->ops->i2c_gate_ctrl(fe, 1);
784 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
791 if (fe->ops->i2c_gate_ctrl)
792 fe->ops->i2c_gate_ctrl(fe, 1);
793 i2c_transfer(&dev->i2c_adap, &msg, 1);
797 if (fe->ops->i2c_gate_ctrl)
798 fe->ops->i2c_gate_ctrl(fe, 1);
799 i2c_transfer(&dev->i2c_adap, &msg, 1);
802 /* correct CP value */
804 reg2[1] = 0x10 + tda827xa_dvbt[i].scr;
806 if (fe->ops->i2c_gate_ctrl)
807 fe->ops->i2c_gate_ctrl(fe, 1);
808 i2c_transfer(&dev->i2c_adap, &msg, 1);
812 reg2[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
813 if (fe->ops->i2c_gate_ctrl)
814 fe->ops->i2c_gate_ctrl(fe, 1);
815 i2c_transfer(&dev->i2c_adap, &msg, 1);
821 static int philips_tda827xa_tuner_sleep(u8 addr, struct dvb_frontend *fe)
823 struct saa7134_dev *dev = fe->dvb->priv;
824 static u8 tda827xa_sleep[] = { 0x30, 0x90};
825 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tda827xa_sleep,
826 .len = sizeof(tda827xa_sleep) };
827 if (fe->ops->i2c_gate_ctrl)
828 fe->ops->i2c_gate_ctrl(fe, 1);
829 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
833 /* ------------------------------------------------------------------ */
835 static int philips_tiger_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
838 struct saa7134_dev *dev = fe->dvb->priv;
839 static u8 tda8290_close[] = { 0x21, 0xc0};
840 static u8 tda8290_open[] = { 0x21, 0x80};
841 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
843 /* close tda8290 i2c bridge */
844 tda8290_msg.buf = tda8290_close;
845 ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
849 ret = philips_tda827xa_pll_set(0x61, fe, params);
852 /* open tda8290 i2c bridge */
853 tda8290_msg.buf = tda8290_open;
854 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
858 static int philips_tiger_tuner_init(struct dvb_frontend *fe)
860 struct saa7134_dev *dev = fe->dvb->priv;
861 static u8 data[] = { 0x3c, 0x33, 0x6a};
862 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
864 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
869 static int philips_tiger_tuner_sleep(struct dvb_frontend *fe)
871 struct saa7134_dev *dev = fe->dvb->priv;
872 static u8 data[] = { 0x3c, 0x33, 0x68};
873 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
875 i2c_transfer(&dev->i2c_adap, &msg, 1);
876 philips_tda827xa_tuner_sleep( 0x61, fe);
880 static struct tda1004x_config philips_tiger_config = {
881 .demod_address = 0x08,
884 .xtal_freq = TDA10046_XTAL_16M,
885 .agc_config = TDA10046_AGC_TDA827X,
886 .if_freq = TDA10046_FREQ_045,
887 .request_firmware = NULL,
890 /* ------------------------------------------------------------------ */
892 static int lifeview_trio_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
896 ret = philips_tda827xa_pll_set(0x60, fe, params);
900 static int lifeview_trio_tuner_sleep(struct dvb_frontend *fe)
902 philips_tda827xa_tuner_sleep(0x60, fe);
906 static struct tda1004x_config lifeview_trio_config = {
907 .demod_address = 0x09,
910 .xtal_freq = TDA10046_XTAL_16M,
911 .agc_config = TDA10046_AGC_TDA827X_GPL,
912 .if_freq = TDA10046_FREQ_045,
913 .request_firmware = NULL,
916 /* ------------------------------------------------------------------ */
918 static int ads_duo_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
922 ret = philips_tda827xa_pll_set(0x61, fe, params);
926 static int ads_duo_tuner_init(struct dvb_frontend *fe)
928 struct saa7134_dev *dev = fe->dvb->priv;
929 /* route TDA8275a AGC input to the channel decoder */
930 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x60);
934 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
936 struct saa7134_dev *dev = fe->dvb->priv;
937 /* route TDA8275a AGC input to the analog IF chip*/
938 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x20);
939 philips_tda827xa_tuner_sleep( 0x61, fe);
943 static struct tda1004x_config ads_tech_duo_config = {
944 .demod_address = 0x08,
947 .xtal_freq = TDA10046_XTAL_16M,
948 .agc_config = TDA10046_AGC_TDA827X_GPL,
949 .if_freq = TDA10046_FREQ_045,
950 .request_firmware = NULL,
953 /* ------------------------------------------------------------------ */
955 static int tevion_dvb220rf_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
958 ret = philips_tda827xa_pll_set(0x60, fe, params);
962 static int tevion_dvb220rf_tuner_sleep(struct dvb_frontend *fe)
964 philips_tda827xa_tuner_sleep( 0x61, fe);
968 static struct tda1004x_config tevion_dvbt220rf_config = {
969 .demod_address = 0x08,
972 .xtal_freq = TDA10046_XTAL_16M,
973 .agc_config = TDA10046_AGC_TDA827X,
974 .if_freq = TDA10046_FREQ_045,
975 .request_firmware = NULL,
980 /* ------------------------------------------------------------------ */
983 static struct nxt200x_config avertvhda180 = {
984 .demod_address = 0x0a,
987 static int nxt200x_set_pll_input(u8 *buf, int input)
996 static struct nxt200x_config kworldatsc110 = {
997 .demod_address = 0x0a,
998 .set_pll_input = nxt200x_set_pll_input,
1002 /* ------------------------------------------------------------------ */
1004 static int dvb_init(struct saa7134_dev *dev)
1006 /* init struct videobuf_dvb */
1007 dev->ts.nr_bufs = 32;
1008 dev->ts.nr_packets = 32*4;
1009 dev->dvb.name = dev->name;
1010 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
1011 dev->pci, &dev->slock,
1012 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1013 V4L2_FIELD_ALTERNATE,
1014 sizeof(struct saa7134_buf),
1017 switch (dev->board) {
1019 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1020 printk("%s: pinnacle 300i dvb setup\n",dev->name);
1021 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
1023 dev->dvb.frontend->ops->tuner_ops.pllbuf = mt352_pinnacle_tuner_pllbuf;
1026 case SAA7134_BOARD_AVERMEDIA_777:
1027 printk("%s: avertv 777 dvb setup\n",dev->name);
1028 dev->dvb.frontend = mt352_attach(&avermedia_777,
1030 dev->dvb.frontend->ops->tuner_ops.pllbuf = mt352_aver777_tuner_pllbuf;
1033 #ifdef HAVE_TDA1004X
1034 case SAA7134_BOARD_MD7134:
1035 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1037 dev->dvb.frontend->ops->tuner_ops.init = philips_fmd1216_tuner_init;
1038 dev->dvb.frontend->ops->tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1039 dev->dvb.frontend->ops->tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1041 case SAA7134_BOARD_PHILIPS_TOUGH:
1042 dev->dvb.frontend = tda10046_attach(&philips_tu1216_60_config,
1044 dev->dvb.frontend->ops->tuner_ops.init = philips_tu1216_tuner_60_init;
1045 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tu1216_tuner_60_set_params;
1047 case SAA7134_BOARD_FLYDVBTDUO:
1048 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1050 dev->dvb.frontend->ops->tuner_ops.init = philips_tda827x_tuner_init;
1051 dev->dvb.frontend->ops->tuner_ops.sleep = philips_tda827x_tuner_sleep;
1052 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tda827x_tuner_set_params;
1054 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1055 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1057 dev->dvb.frontend->ops->tuner_ops.init = philips_tda827x_tuner_init;
1058 dev->dvb.frontend->ops->tuner_ops.sleep = philips_tda827x_tuner_sleep;
1059 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tda827x_tuner_set_params;
1061 case SAA7134_BOARD_PHILIPS_EUROPA:
1062 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
1064 dev->original_demod_sleep = dev->dvb.frontend->ops->sleep;
1065 dev->dvb.frontend->ops->sleep = philips_europa_demod_sleep;
1066 dev->dvb.frontend->ops->tuner_ops.init = philips_europa_tuner_init;
1067 dev->dvb.frontend->ops->tuner_ops.sleep = philips_europa_tuner_sleep;
1068 dev->dvb.frontend->ops->tuner_ops.set_params = philips_td1316_tuner_set_params;
1070 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1071 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
1073 dev->dvb.frontend->ops->tuner_ops.init = philips_europa_tuner_init;
1074 dev->dvb.frontend->ops->tuner_ops.sleep = philips_europa_tuner_sleep;
1075 dev->dvb.frontend->ops->tuner_ops.set_params = philips_td1316_tuner_set_params;
1077 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1078 dev->dvb.frontend = tda10046_attach(&philips_tu1216_61_config,
1080 dev->dvb.frontend->ops->tuner_ops.init = philips_tu1216_tuner_61_init;
1081 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tu1216_tuner_61_set_params;
1083 case SAA7134_BOARD_PHILIPS_TIGER:
1084 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
1086 dev->dvb.frontend->ops->tuner_ops.init = philips_tiger_tuner_init;
1087 dev->dvb.frontend->ops->tuner_ops.sleep = philips_tiger_tuner_sleep;
1088 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tiger_tuner_set_params;
1090 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1091 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
1093 dev->dvb.frontend->ops->tuner_ops.init = philips_tiger_tuner_init;
1094 dev->dvb.frontend->ops->tuner_ops.sleep = philips_tiger_tuner_sleep;
1095 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tiger_tuner_set_params;
1097 case SAA7134_BOARD_FLYDVBT_LR301:
1098 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
1100 dev->dvb.frontend->ops->tuner_ops.init = philips_tda827x_tuner_init;
1101 dev->dvb.frontend->ops->tuner_ops.sleep = philips_tda827x_tuner_sleep;
1102 dev->dvb.frontend->ops->tuner_ops.set_params = philips_tda827x_tuner_set_params;
1104 case SAA7134_BOARD_FLYDVB_TRIO:
1105 dev->dvb.frontend = tda10046_attach(&lifeview_trio_config,
1107 dev->dvb.frontend->ops->tuner_ops.sleep = lifeview_trio_tuner_sleep;
1108 dev->dvb.frontend->ops->tuner_ops.set_params = lifeview_trio_tuner_set_params;
1110 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1111 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1113 dev->dvb.frontend->ops->tuner_ops.init = ads_duo_tuner_init;
1114 dev->dvb.frontend->ops->tuner_ops.sleep = ads_duo_tuner_sleep;
1115 dev->dvb.frontend->ops->tuner_ops.set_params = ads_duo_tuner_set_params;
1117 case SAA7134_BOARD_TEVION_DVBT_220RF:
1118 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config,
1120 dev->dvb.frontend->ops->tuner_ops.sleep = tevion_dvb220rf_tuner_sleep;
1121 dev->dvb.frontend->ops->tuner_ops.set_params = tevion_dvb220rf_tuner_set_params;
1123 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1124 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1126 dev->dvb.frontend->ops->tuner_ops.init = ads_duo_tuner_init;
1127 dev->dvb.frontend->ops->tuner_ops.sleep = ads_duo_tuner_sleep;
1128 dev->dvb.frontend->ops->tuner_ops.set_params = ads_duo_tuner_set_params;
1132 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1133 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap);
1134 if (dev->dvb.frontend) {
1135 dvb_pll_attach(dev->dvb.frontend, 0x61, &dev->i2c_adap, &dvb_pll_tdhu2);
1138 case SAA7134_BOARD_KWORLD_ATSC110:
1139 dev->dvb.frontend = nxt200x_attach(&kworldatsc110, &dev->i2c_adap);
1140 if (dev->dvb.frontend) {
1141 dvb_pll_attach(dev->dvb.frontend, 0x61, &dev->i2c_adap, &dvb_pll_tuv1236d);
1146 printk("%s: Huh? unknown DVB card?\n",dev->name);
1150 if (NULL == dev->dvb.frontend) {
1151 printk("%s: frontend initialization failed\n",dev->name);
1155 /* register everything else */
1156 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1159 static int dvb_fini(struct saa7134_dev *dev)
1161 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1163 switch (dev->board) {
1164 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1165 /* otherwise we don't detect the tuner on next insmod */
1166 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1169 videobuf_dvb_unregister(&dev->dvb);
1173 static struct saa7134_mpeg_ops dvb_ops = {
1174 .type = SAA7134_MPEG_DVB,
1179 static int __init dvb_register(void)
1181 return saa7134_ts_register(&dvb_ops);
1184 static void __exit dvb_unregister(void)
1186 saa7134_ts_unregister(&dvb_ops);
1189 module_init(dvb_register);
1190 module_exit(dvb_unregister);
1192 /* ------------------------------------------------------------------ */