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 */
41 # 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_pinnacle_pll_set(struct dvb_frontend* fe,
117 struct dvb_frontend_parameters* params,
120 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
121 static int off = TDA9887_PRESENT | TDA9887_PORT2_ACTIVE;
122 struct saa7134_dev *dev = fe->dvb->priv;
123 struct v4l2_frequency f;
125 /* set frequency (mt2050) */
127 f.type = V4L2_TUNER_DIGITAL_TV;
128 f.frequency = params->frequency / 1000 * 16 / 1000;
129 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
130 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
131 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&off);
133 pinnacle_antenna_pwr(dev, antenna_pwr);
136 mt352_pinnacle_init(fe);
145 static struct mt352_config pinnacle_300i = {
146 .demod_address = 0x3c >> 1,
150 .demod_init = mt352_pinnacle_init,
151 .pll_set = mt352_pinnacle_pll_set,
155 /* ------------------------------------------------------------------ */
159 static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
161 struct saa7134_dev *dev = fe->dvb->priv;
163 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
165 int tuner_frequency = 0;
168 /* determine charge pump */
169 tuner_frequency = params->frequency + 36166000;
170 if (tuner_frequency < 87000000)
172 else if (tuner_frequency < 130000000)
174 else if (tuner_frequency < 160000000)
176 else if (tuner_frequency < 200000000)
178 else if (tuner_frequency < 290000000)
180 else if (tuner_frequency < 420000000)
182 else if (tuner_frequency < 480000000)
184 else if (tuner_frequency < 620000000)
186 else if (tuner_frequency < 830000000)
188 else if (tuner_frequency < 895000000)
194 if (params->frequency < 49000000)
196 else if (params->frequency < 161000000)
198 else if (params->frequency < 444000000)
200 else if (params->frequency < 861000000)
205 /* setup PLL filter */
206 switch (params->u.ofdm.bandwidth) {
207 case BANDWIDTH_6_MHZ:
211 case BANDWIDTH_7_MHZ:
215 case BANDWIDTH_8_MHZ:
224 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
226 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
228 /* setup tuner buffer */
229 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
230 tuner_buf[1] = tuner_frequency & 0xff;
232 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
234 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
240 static int philips_tda6651_pll_init(u8 addr, struct dvb_frontend *fe)
242 struct saa7134_dev *dev = fe->dvb->priv;
243 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
244 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
246 /* setup PLL configuration */
247 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
254 /* ------------------------------------------------------------------ */
256 static int philips_tu1216_pll_60_init(struct dvb_frontend *fe)
258 return philips_tda6651_pll_init(0x60, fe);
261 static int philips_tu1216_pll_60_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
263 return philips_tda6651_pll_set(0x60, fe, params);
266 static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
267 const struct firmware **fw, char *name)
269 struct saa7134_dev *dev = fe->dvb->priv;
270 return request_firmware(fw, name, &dev->pci->dev);
273 static struct tda1004x_config philips_tu1216_60_config = {
275 .demod_address = 0x8,
278 .xtal_freq = TDA10046_XTAL_4M,
279 .agc_config = TDA10046_AGC_DEFAULT,
280 .if_freq = TDA10046_FREQ_3617,
281 .pll_init = philips_tu1216_pll_60_init,
282 .pll_set = philips_tu1216_pll_60_set,
284 .request_firmware = philips_tu1216_request_firmware,
287 /* ------------------------------------------------------------------ */
289 static int philips_tu1216_pll_61_init(struct dvb_frontend *fe)
291 return philips_tda6651_pll_init(0x61, fe);
294 static int philips_tu1216_pll_61_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
296 return philips_tda6651_pll_set(0x61, fe, params);
299 static struct tda1004x_config philips_tu1216_61_config = {
301 .demod_address = 0x8,
304 .xtal_freq = TDA10046_XTAL_4M,
305 .agc_config = TDA10046_AGC_DEFAULT,
306 .if_freq = TDA10046_FREQ_3617,
307 .pll_init = philips_tu1216_pll_61_init,
308 .pll_set = philips_tu1216_pll_61_set,
310 .request_firmware = philips_tu1216_request_firmware,
313 /* ------------------------------------------------------------------ */
315 static int philips_europa_pll_init(struct dvb_frontend *fe)
317 struct saa7134_dev *dev = fe->dvb->priv;
318 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
319 struct i2c_msg init_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
321 /* setup PLL configuration */
322 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
326 /* switch the board to dvb mode */
327 init_msg.addr = 0x43;
331 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
337 static int philips_td1316_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
339 return philips_tda6651_pll_set(0x61, fe, params);
342 static void philips_europa_analog(struct dvb_frontend *fe)
344 struct saa7134_dev *dev = fe->dvb->priv;
345 /* this message actually turns the tuner back to analog mode */
346 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
347 struct i2c_msg analog_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
349 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
352 /* switch the board to analog mode */
353 analog_msg.addr = 0x43;
354 analog_msg.len = 0x02;
357 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
360 static struct tda1004x_config philips_europa_config = {
362 .demod_address = 0x8,
365 .xtal_freq = TDA10046_XTAL_4M,
366 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
367 .if_freq = TDA10046_FREQ_052,
368 .pll_init = philips_europa_pll_init,
369 .pll_set = philips_td1316_pll_set,
370 .pll_sleep = philips_europa_analog,
371 .request_firmware = NULL,
374 /* ------------------------------------------------------------------ */
376 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
378 struct saa7134_dev *dev = fe->dvb->priv;
379 /* this message is to set up ATC and ALC */
380 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
381 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
383 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
390 static void philips_fmd1216_analog(struct dvb_frontend *fe)
392 struct saa7134_dev *dev = fe->dvb->priv;
393 /* this message actually turns the tuner back to analog mode */
394 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
395 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
397 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
399 fmd1216_init[2] = 0x86;
400 fmd1216_init[3] = 0x54;
401 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
405 static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
407 struct saa7134_dev *dev = fe->dvb->priv;
409 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
411 int tuner_frequency = 0;
415 /* determine charge pump */
416 tuner_frequency = params->frequency + 36130000;
417 if (tuner_frequency < 87000000)
420 else if (tuner_frequency < 180000000) {
424 } else if (tuner_frequency < 195000000) {
429 } else if (tuner_frequency < 366000000) {
430 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
437 } else if (tuner_frequency < 478000000) {
438 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
446 } else if (tuner_frequency < 662000000) {
447 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
454 } else if (tuner_frequency < 840000000) {
455 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
463 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
472 /* calculate divisor */
473 /* ((36166000 + Finput) / 166666) rounded! */
474 divider = (tuner_frequency + 83333) / 166667;
476 /* setup tuner buffer */
477 tuner_buf[0] = (divider >> 8) & 0x7f;
478 tuner_buf[1] = divider & 0xff;
479 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
480 tuner_buf[3] = 0x40 | band;
482 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
487 static struct tda1004x_config medion_cardbus = {
488 .demod_address = 0x08,
491 .xtal_freq = TDA10046_XTAL_16M,
492 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
493 .if_freq = TDA10046_FREQ_3613,
494 .pll_init = philips_fmd1216_pll_init,
495 .pll_set = philips_fmd1216_pll_set,
496 .pll_sleep = philips_fmd1216_analog,
497 .request_firmware = NULL,
500 /* ------------------------------------------------------------------ */
502 struct tda827x_data {
512 static struct tda827x_data tda827x_dvbt[] = {
513 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
514 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
515 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
516 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
517 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
518 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
519 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
520 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
521 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
522 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
523 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
524 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
525 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
526 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
527 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
528 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
529 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
530 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
531 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
532 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
533 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
534 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
535 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
536 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
537 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
538 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
539 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
540 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
541 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
544 static int philips_tda827x_pll_init(struct dvb_frontend *fe)
549 static int philips_tda827x_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
551 struct saa7134_dev *dev = fe->dvb->priv;
554 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
555 .len = sizeof(tuner_buf) };
556 int i, tuner_freq, if_freq;
558 switch (params->u.ofdm.bandwidth) {
559 case BANDWIDTH_6_MHZ:
562 case BANDWIDTH_7_MHZ:
565 default: /* 8 MHz or Auto */
569 tuner_freq = params->frequency + if_freq;
572 while (tda827x_dvbt[i].lomax < tuner_freq) {
573 if(tda827x_dvbt[i + 1].lomax == 0)
578 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
580 tuner_buf[1] = (N>>8) | 0x40;
581 tuner_buf[2] = N & 0xff;
584 tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
585 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
586 tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
590 tuner_buf[10] = 0xff;
591 tuner_buf[11] = 0x00;
592 tuner_buf[12] = 0x00;
593 tuner_buf[13] = 0x40;
596 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
600 /* correct CP value */
602 tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
604 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
609 static void philips_tda827x_pll_sleep(struct dvb_frontend *fe)
611 struct saa7134_dev *dev = fe->dvb->priv;
612 static u8 tda827x_sleep[] = { 0x30, 0xd0};
613 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
614 .len = sizeof(tda827x_sleep) };
615 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
618 static struct tda1004x_config tda827x_lifeview_config = {
619 .demod_address = 0x08,
622 .xtal_freq = TDA10046_XTAL_16M,
623 .agc_config = TDA10046_AGC_TDA827X,
624 .if_freq = TDA10046_FREQ_045,
625 .pll_init = philips_tda827x_pll_init,
626 .pll_set = philips_tda827x_pll_set,
627 .pll_sleep = philips_tda827x_pll_sleep,
628 .request_firmware = NULL,
631 /* ------------------------------------------------------------------ */
633 struct tda827xa_data {
642 static struct tda827xa_data tda827xa_dvbt[] = {
643 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
644 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
645 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
646 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
647 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
648 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
649 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
650 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
651 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
652 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
653 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
654 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
655 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
656 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
657 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
658 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
659 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
660 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
661 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
662 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
663 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
664 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
665 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
666 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
667 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
668 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
669 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}};
672 static int philips_tda827xa_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
674 struct saa7134_dev *dev = fe->dvb->priv;
676 unsigned char reg2[2];
678 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = tuner_buf};
679 int i, tuner_freq, if_freq;
682 switch (params->u.ofdm.bandwidth) {
683 case BANDWIDTH_6_MHZ:
686 case BANDWIDTH_7_MHZ:
689 default: /* 8 MHz or Auto */
693 tuner_freq = params->frequency + if_freq;
696 while (tda827xa_dvbt[i].lomax < tuner_freq) {
697 if(tda827xa_dvbt[i + 1].lomax == 0)
702 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
703 tuner_buf[0] = 0; // subaddress
704 tuner_buf[1] = N >> 8;
705 tuner_buf[2] = N & 0xff;
708 tuner_buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
709 tda827xa_dvbt[i].sbs;
710 tuner_buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
714 tuner_buf[10] = 0xff;
715 tuner_buf[11] = 0x60;
716 tuner_buf[12] = 0x00;
717 tuner_buf[13] = 0x39; // lpsel
719 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
726 i2c_transfer(&dev->i2c_adap, &msg, 1);
730 i2c_transfer(&dev->i2c_adap, &msg, 1);
733 /* correct CP value */
735 reg2[1] = 0x10 + tda827xa_dvbt[i].scr;
737 i2c_transfer(&dev->i2c_adap, &msg, 1);
741 reg2[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
742 i2c_transfer(&dev->i2c_adap, &msg, 1);
748 static void philips_tda827xa_pll_sleep(u8 addr, struct dvb_frontend *fe)
750 struct saa7134_dev *dev = fe->dvb->priv;
751 static u8 tda827xa_sleep[] = { 0x30, 0x90};
752 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tda827xa_sleep,
753 .len = sizeof(tda827xa_sleep) };
754 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
758 /* ------------------------------------------------------------------ */
760 static int philips_tiger_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
763 struct saa7134_dev *dev = fe->dvb->priv;
764 static u8 tda8290_close[] = { 0x21, 0xc0};
765 static u8 tda8290_open[] = { 0x21, 0x80};
766 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
767 /* close tda8290 i2c bridge */
768 tda8290_msg.buf = tda8290_close;
769 ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
773 ret = philips_tda827xa_pll_set(0x61, fe, params);
776 /* open tda8290 i2c bridge */
777 tda8290_msg.buf = tda8290_open;
778 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
782 static int philips_tiger_dvb_mode(struct dvb_frontend *fe)
784 struct saa7134_dev *dev = fe->dvb->priv;
785 static u8 data[] = { 0x3c, 0x33, 0x6a};
786 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
788 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
793 static void philips_tiger_analog_mode(struct dvb_frontend *fe)
795 struct saa7134_dev *dev = fe->dvb->priv;
796 static u8 data[] = { 0x3c, 0x33, 0x68};
797 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
799 i2c_transfer(&dev->i2c_adap, &msg, 1);
800 philips_tda827xa_pll_sleep( 0x61, fe);
803 static struct tda1004x_config philips_tiger_config = {
804 .demod_address = 0x08,
807 .xtal_freq = TDA10046_XTAL_16M,
808 .agc_config = TDA10046_AGC_TDA827X,
809 .if_freq = TDA10046_FREQ_045,
810 .pll_init = philips_tiger_dvb_mode,
811 .pll_set = philips_tiger_pll_set,
812 .pll_sleep = philips_tiger_analog_mode,
813 .request_firmware = NULL,
818 /* ------------------------------------------------------------------ */
821 static struct nxt200x_config avertvhda180 = {
822 .demod_address = 0x0a,
824 .pll_desc = &dvb_pll_tdhu2,
828 /* ------------------------------------------------------------------ */
830 static int dvb_init(struct saa7134_dev *dev)
832 /* init struct videobuf_dvb */
833 dev->ts.nr_bufs = 32;
834 dev->ts.nr_packets = 32*4;
835 dev->dvb.name = dev->name;
836 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
837 dev->pci, &dev->slock,
838 V4L2_BUF_TYPE_VIDEO_CAPTURE,
839 V4L2_FIELD_ALTERNATE,
840 sizeof(struct saa7134_buf),
843 switch (dev->board) {
845 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
846 printk("%s: pinnacle 300i dvb setup\n",dev->name);
847 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
852 case SAA7134_BOARD_MD7134:
853 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
856 case SAA7134_BOARD_PHILIPS_TOUGH:
857 dev->dvb.frontend = tda10046_attach(&philips_tu1216_60_config,
860 case SAA7134_BOARD_FLYDVBTDUO:
861 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
864 case SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS:
865 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
868 case SAA7134_BOARD_PHILIPS_EUROPA:
869 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
872 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
873 dev->dvb.frontend = tda10046_attach(&philips_europa_config,
876 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
877 dev->dvb.frontend = tda10046_attach(&philips_tu1216_61_config,
880 case SAA7134_BOARD_PHILIPS_TIGER:
881 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
884 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
885 dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
890 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
891 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap);
895 printk("%s: Huh? unknown DVB card?\n",dev->name);
899 if (NULL == dev->dvb.frontend) {
900 printk("%s: frontend initialization failed\n",dev->name);
904 /* register everything else */
905 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
908 static int dvb_fini(struct saa7134_dev *dev)
910 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
912 switch (dev->board) {
913 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
914 /* otherwise we don't detect the tuner on next insmod */
915 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
918 videobuf_dvb_unregister(&dev->dvb);
922 static struct saa7134_mpeg_ops dvb_ops = {
923 .type = SAA7134_MPEG_DVB,
928 static int __init dvb_register(void)
930 return saa7134_ts_register(&dvb_ops);
933 static void __exit dvb_unregister(void)
935 saa7134_ts_unregister(&dvb_ops);
938 module_init(dvb_register);
939 module_exit(dvb_unregister);
941 /* ------------------------------------------------------------------ */