Revert "[PATCH] paravirt: Add startup infrastructure for paravirtualization"
[pv_ops_mirror.git] / drivers / media / video / saa7134 / saa7134-dvb.c
blob65aec881bbde9a4e6f5dd622b3032a34963f9c15
1 /*
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"
33 #include "saa7134.h"
34 #include <media/v4l2-common.h>
35 #include "dvb-pll.h"
37 #include "mt352.h"
38 #include "mt352_priv.h" /* FIXME */
39 #include "tda1004x.h"
40 #include "nxt200x.h"
42 #include "tda10086.h"
43 #include "tda826x.h"
44 #include "tda827x.h"
45 #include "isl6421.h"
47 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48 MODULE_LICENSE("GPL");
50 static unsigned int antenna_pwr = 0;
52 module_param(antenna_pwr, int, 0444);
53 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
55 static int use_frontend = 0;
56 module_param(use_frontend, int, 0644);
57 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
59 static int debug = 0;
60 module_param(debug, int, 0644);
61 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
63 #define dprintk(fmt, arg...) do { if (debug) \
64 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
66 /* Print a warning */
67 #define wprintk(fmt, arg...) \
68 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
70 /* ------------------------------------------------------------------
71 * mt352 based DVB-T cards
74 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
76 u32 ok;
78 if (!on) {
79 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
80 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
81 return 0;
84 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
85 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
86 udelay(10);
88 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
89 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
90 udelay(10);
91 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
92 udelay(10);
93 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
94 dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off");
96 if (!ok)
97 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
98 return ok;
101 static int mt352_pinnacle_init(struct dvb_frontend* fe)
103 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
104 static u8 reset [] = { RESET, 0x80 };
105 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
106 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
107 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
108 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
109 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
110 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
111 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
112 struct saa7134_dev *dev= fe->dvb->priv;
114 dprintk("%s called\n", __FUNCTION__);
116 mt352_write(fe, clock_config, sizeof(clock_config));
117 udelay(200);
118 mt352_write(fe, reset, sizeof(reset));
119 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
120 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
121 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
122 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
124 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
125 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
126 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
128 return 0;
131 static int mt352_aver777_init(struct dvb_frontend* fe)
133 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
134 static u8 reset [] = { RESET, 0x80 };
135 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
136 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
137 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
139 mt352_write(fe, clock_config, sizeof(clock_config));
140 udelay(200);
141 mt352_write(fe, reset, sizeof(reset));
142 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
143 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
144 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
146 return 0;
149 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
150 struct dvb_frontend_parameters* params)
152 u8 off[] = { 0x00, 0xf1};
153 u8 on[] = { 0x00, 0x71};
154 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
156 struct saa7134_dev *dev = fe->dvb->priv;
157 struct v4l2_frequency f;
159 /* set frequency (mt2050) */
160 f.tuner = 0;
161 f.type = V4L2_TUNER_DIGITAL_TV;
162 f.frequency = params->frequency / 1000 * 16 / 1000;
163 if (fe->ops.i2c_gate_ctrl)
164 fe->ops.i2c_gate_ctrl(fe, 1);
165 i2c_transfer(&dev->i2c_adap, &msg, 1);
166 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
167 msg.buf = on;
168 if (fe->ops.i2c_gate_ctrl)
169 fe->ops.i2c_gate_ctrl(fe, 1);
170 i2c_transfer(&dev->i2c_adap, &msg, 1);
172 pinnacle_antenna_pwr(dev, antenna_pwr);
174 /* mt352 setup */
175 return mt352_pinnacle_init(fe);
178 static int mt352_aver777_tuner_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
180 if (buf_len < 5)
181 return -EINVAL;
183 pllbuf[0] = 0x61;
184 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
185 params->frequency,
186 params->u.ofdm.bandwidth);
187 return 5;
190 static struct mt352_config pinnacle_300i = {
191 .demod_address = 0x3c >> 1,
192 .adc_clock = 20333,
193 .if2 = 36150,
194 .no_tuner = 1,
195 .demod_init = mt352_pinnacle_init,
198 static struct mt352_config avermedia_777 = {
199 .demod_address = 0xf,
200 .demod_init = mt352_aver777_init,
203 /* ==================================================================
204 * tda1004x based DVB-T cards, helper functions
207 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
208 const struct firmware **fw, char *name)
210 struct saa7134_dev *dev = fe->dvb->priv;
211 return request_firmware(fw, name, &dev->pci->dev);
214 /* ------------------------------------------------------------------
215 * these tuners are tu1216, td1316(a)
218 static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
220 struct saa7134_dev *dev = fe->dvb->priv;
221 struct tda1004x_state *state = fe->demodulator_priv;
222 u8 addr = state->config->tuner_address;
223 u8 tuner_buf[4];
224 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
225 sizeof(tuner_buf) };
226 int tuner_frequency = 0;
227 u8 band, cp, filter;
229 /* determine charge pump */
230 tuner_frequency = params->frequency + 36166000;
231 if (tuner_frequency < 87000000)
232 return -EINVAL;
233 else if (tuner_frequency < 130000000)
234 cp = 3;
235 else if (tuner_frequency < 160000000)
236 cp = 5;
237 else if (tuner_frequency < 200000000)
238 cp = 6;
239 else if (tuner_frequency < 290000000)
240 cp = 3;
241 else if (tuner_frequency < 420000000)
242 cp = 5;
243 else if (tuner_frequency < 480000000)
244 cp = 6;
245 else if (tuner_frequency < 620000000)
246 cp = 3;
247 else if (tuner_frequency < 830000000)
248 cp = 5;
249 else if (tuner_frequency < 895000000)
250 cp = 7;
251 else
252 return -EINVAL;
254 /* determine band */
255 if (params->frequency < 49000000)
256 return -EINVAL;
257 else if (params->frequency < 161000000)
258 band = 1;
259 else if (params->frequency < 444000000)
260 band = 2;
261 else if (params->frequency < 861000000)
262 band = 4;
263 else
264 return -EINVAL;
266 /* setup PLL filter */
267 switch (params->u.ofdm.bandwidth) {
268 case BANDWIDTH_6_MHZ:
269 filter = 0;
270 break;
272 case BANDWIDTH_7_MHZ:
273 filter = 0;
274 break;
276 case BANDWIDTH_8_MHZ:
277 filter = 1;
278 break;
280 default:
281 return -EINVAL;
284 /* calculate divisor
285 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
287 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
289 /* setup tuner buffer */
290 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
291 tuner_buf[1] = tuner_frequency & 0xff;
292 tuner_buf[2] = 0xca;
293 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
295 if (fe->ops.i2c_gate_ctrl)
296 fe->ops.i2c_gate_ctrl(fe, 1);
297 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
298 wprintk("could not write to tuner at addr: 0x%02x\n",
299 addr << 1);
300 return -EIO;
302 msleep(1);
303 return 0;
306 static int philips_tu1216_init(struct dvb_frontend *fe)
308 struct saa7134_dev *dev = fe->dvb->priv;
309 struct tda1004x_state *state = fe->demodulator_priv;
310 u8 addr = state->config->tuner_address;
311 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
312 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
314 /* setup PLL configuration */
315 if (fe->ops.i2c_gate_ctrl)
316 fe->ops.i2c_gate_ctrl(fe, 1);
317 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
318 return -EIO;
319 msleep(1);
321 return 0;
324 /* ------------------------------------------------------------------ */
326 static struct tda1004x_config philips_tu1216_60_config = {
327 .demod_address = 0x8,
328 .invert = 1,
329 .invert_oclk = 0,
330 .xtal_freq = TDA10046_XTAL_4M,
331 .agc_config = TDA10046_AGC_DEFAULT,
332 .if_freq = TDA10046_FREQ_3617,
333 .tuner_address = 0x60,
334 .request_firmware = philips_tda1004x_request_firmware
337 static struct tda1004x_config philips_tu1216_61_config = {
339 .demod_address = 0x8,
340 .invert = 1,
341 .invert_oclk = 0,
342 .xtal_freq = TDA10046_XTAL_4M,
343 .agc_config = TDA10046_AGC_DEFAULT,
344 .if_freq = TDA10046_FREQ_3617,
345 .tuner_address = 0x61,
346 .request_firmware = philips_tda1004x_request_firmware
349 /* ------------------------------------------------------------------ */
351 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
353 struct saa7134_dev *dev = fe->dvb->priv;
354 struct tda1004x_state *state = fe->demodulator_priv;
355 u8 addr = state->config->tuner_address;
356 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
357 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
359 /* setup PLL configuration */
360 if (fe->ops.i2c_gate_ctrl)
361 fe->ops.i2c_gate_ctrl(fe, 1);
362 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
363 return -EIO;
364 return 0;
367 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
369 return philips_tda6651_pll_set(fe, params);
372 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
374 struct saa7134_dev *dev = fe->dvb->priv;
375 struct tda1004x_state *state = fe->demodulator_priv;
376 u8 addr = state->config->tuner_address;
377 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
378 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
380 /* switch the tuner to analog mode */
381 if (fe->ops.i2c_gate_ctrl)
382 fe->ops.i2c_gate_ctrl(fe, 1);
383 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
384 return -EIO;
385 return 0;
388 /* ------------------------------------------------------------------ */
390 static int philips_europa_tuner_init(struct dvb_frontend *fe)
392 struct saa7134_dev *dev = fe->dvb->priv;
393 static u8 msg[] = { 0x00, 0x40};
394 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
397 if (philips_td1316_tuner_init(fe))
398 return -EIO;
399 msleep(1);
400 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
401 return -EIO;
403 return 0;
406 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
408 struct saa7134_dev *dev = fe->dvb->priv;
410 static u8 msg[] = { 0x00, 0x14 };
411 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
413 if (philips_td1316_tuner_sleep(fe))
414 return -EIO;
416 /* switch the board to analog mode */
417 if (fe->ops.i2c_gate_ctrl)
418 fe->ops.i2c_gate_ctrl(fe, 1);
419 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
420 return 0;
423 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
425 struct saa7134_dev *dev = fe->dvb->priv;
427 if (dev->original_demod_sleep)
428 dev->original_demod_sleep(fe);
429 fe->ops.i2c_gate_ctrl(fe, 1);
430 return 0;
433 static struct tda1004x_config philips_europa_config = {
435 .demod_address = 0x8,
436 .invert = 0,
437 .invert_oclk = 0,
438 .xtal_freq = TDA10046_XTAL_4M,
439 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
440 .if_freq = TDA10046_FREQ_052,
441 .tuner_address = 0x61,
442 .request_firmware = philips_tda1004x_request_firmware
445 /* ------------------------------------------------------------------ */
447 static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
449 struct saa7134_dev *dev = fe->dvb->priv;
450 struct tda1004x_state *state = fe->demodulator_priv;
451 u8 addr = state->config->tuner_address;
452 /* this message is to set up ATC and ALC */
453 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
454 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
456 if (fe->ops.i2c_gate_ctrl)
457 fe->ops.i2c_gate_ctrl(fe, 1);
458 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
459 return -EIO;
460 msleep(1);
462 return 0;
465 static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
467 struct saa7134_dev *dev = fe->dvb->priv;
468 struct tda1004x_state *state = fe->demodulator_priv;
469 u8 addr = state->config->tuner_address;
470 /* this message actually turns the tuner back to analog mode */
471 u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
472 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
474 if (fe->ops.i2c_gate_ctrl)
475 fe->ops.i2c_gate_ctrl(fe, 1);
476 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
477 msleep(1);
478 fmd1216_init[2] = 0x86;
479 fmd1216_init[3] = 0x54;
480 if (fe->ops.i2c_gate_ctrl)
481 fe->ops.i2c_gate_ctrl(fe, 1);
482 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
483 msleep(1);
484 return 0;
487 static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
489 struct saa7134_dev *dev = fe->dvb->priv;
490 struct tda1004x_state *state = fe->demodulator_priv;
491 u8 addr = state->config->tuner_address;
492 u8 tuner_buf[4];
493 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
494 sizeof(tuner_buf) };
495 int tuner_frequency = 0;
496 int divider = 0;
497 u8 band, mode, cp;
499 /* determine charge pump */
500 tuner_frequency = params->frequency + 36130000;
501 if (tuner_frequency < 87000000)
502 return -EINVAL;
503 /* low band */
504 else if (tuner_frequency < 180000000) {
505 band = 1;
506 mode = 7;
507 cp = 0;
508 } else if (tuner_frequency < 195000000) {
509 band = 1;
510 mode = 6;
511 cp = 1;
512 /* mid band */
513 } else if (tuner_frequency < 366000000) {
514 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
515 band = 10;
516 } else {
517 band = 2;
519 mode = 7;
520 cp = 0;
521 } else if (tuner_frequency < 478000000) {
522 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
523 band = 10;
524 } else {
525 band = 2;
527 mode = 6;
528 cp = 1;
529 /* high band */
530 } else if (tuner_frequency < 662000000) {
531 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
532 band = 12;
533 } else {
534 band = 4;
536 mode = 7;
537 cp = 0;
538 } else if (tuner_frequency < 840000000) {
539 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
540 band = 12;
541 } else {
542 band = 4;
544 mode = 6;
545 cp = 1;
546 } else {
547 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
548 band = 12;
549 } else {
550 band = 4;
552 mode = 7;
553 cp = 1;
556 /* calculate divisor */
557 /* ((36166000 + Finput) / 166666) rounded! */
558 divider = (tuner_frequency + 83333) / 166667;
560 /* setup tuner buffer */
561 tuner_buf[0] = (divider >> 8) & 0x7f;
562 tuner_buf[1] = divider & 0xff;
563 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
564 tuner_buf[3] = 0x40 | band;
566 if (fe->ops.i2c_gate_ctrl)
567 fe->ops.i2c_gate_ctrl(fe, 1);
568 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
569 wprintk("could not write to tuner at addr: 0x%02x\n",
570 addr << 1);
571 return -EIO;
573 return 0;
576 static struct tda1004x_config medion_cardbus = {
577 .demod_address = 0x08,
578 .invert = 1,
579 .invert_oclk = 0,
580 .xtal_freq = TDA10046_XTAL_16M,
581 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
582 .if_freq = TDA10046_FREQ_3613,
583 .tuner_address = 0x61,
584 .request_firmware = philips_tda1004x_request_firmware
587 /* ------------------------------------------------------------------
588 * tda 1004x based cards with philips silicon tuner
591 static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
593 struct saa7134_dev *dev = fe->dvb->priv;
594 struct tda1004x_state *state = fe->demodulator_priv;
595 u8 addr = state->config->i2c_gate;
596 u8 config = state->config->tuner_config;
597 u8 GP00_CF[] = {0x20, 0x01};
598 u8 GP00_LEV[] = {0x22, 0x00};
600 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
601 if (config) {
602 if (high) {
603 dprintk("setting LNA to high gain\n");
604 } else {
605 dprintk("setting LNA to low gain\n");
608 switch (config) {
609 case 0: /* no LNA */
610 break;
611 case 1: /* switch is GPIO 0 of tda8290 */
612 case 2:
613 /* turn Vsync off */
614 saa7134_set_gpio(dev, 22, 0);
615 GP00_LEV[1] = high ? 0 : 1;
616 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
617 wprintk("could not access tda8290 at addr: 0x%02x\n",
618 addr << 1);
619 return;
621 msg.buf = GP00_LEV;
622 if (config == 2)
623 GP00_LEV[1] = high ? 1 : 0;
624 i2c_transfer(&dev->i2c_adap, &msg, 1);
625 break;
626 case 3: /* switch with GPIO of saa713x */
627 saa7134_set_gpio(dev, 22, high);
628 break;
632 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
634 struct tda1004x_state *state = fe->demodulator_priv;
636 u8 addr = state->config->i2c_gate;
637 static u8 tda8290_close[] = { 0x21, 0xc0};
638 static u8 tda8290_open[] = { 0x21, 0x80};
639 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
640 if (enable) {
641 tda8290_msg.buf = tda8290_close;
642 } else {
643 tda8290_msg.buf = tda8290_open;
645 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
646 struct saa7134_dev *dev = fe->dvb->priv;
647 wprintk("could not access tda8290 I2C gate\n");
648 return -EIO;
650 msleep(20);
651 return 0;
654 /* ------------------------------------------------------------------ */
656 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
658 struct saa7134_dev *dev = fe->dvb->priv;
659 struct tda1004x_state *state = fe->demodulator_priv;
661 switch (state->config->antenna_switch) {
662 case 0: break;
663 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
664 saa7134_set_gpio(dev, 21, 0);
665 break;
666 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
667 saa7134_set_gpio(dev, 21, 1);
668 break;
670 return 0;
673 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
675 struct saa7134_dev *dev = fe->dvb->priv;
676 struct tda1004x_state *state = fe->demodulator_priv;
678 switch (state->config->antenna_switch) {
679 case 0: break;
680 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
681 saa7134_set_gpio(dev, 21, 1);
682 break;
683 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
684 saa7134_set_gpio(dev, 21, 0);
685 break;
687 return 0;
690 static struct tda827x_config tda827x_cfg = {
691 .lna_gain = philips_tda827x_lna_gain,
692 .init = philips_tda827x_tuner_init,
693 .sleep = philips_tda827x_tuner_sleep
696 static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
698 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
699 if (dev->dvb.frontend) {
700 if (tda_conf->i2c_gate)
701 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
702 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
703 &dev->i2c_adap,&tda827x_cfg) == NULL) {
704 wprintk("no tda827x tuner found at addr: %02x\n",
705 tda_conf->tuner_address);
710 /* ------------------------------------------------------------------ */
711 static struct tda1004x_config tda827x_lifeview_config = {
712 .demod_address = 0x08,
713 .invert = 1,
714 .invert_oclk = 0,
715 .xtal_freq = TDA10046_XTAL_16M,
716 .agc_config = TDA10046_AGC_TDA827X,
717 .gpio_config = TDA10046_GP11_I,
718 .if_freq = TDA10046_FREQ_045,
719 .tuner_address = 0x60,
720 .request_firmware = philips_tda1004x_request_firmware
723 static struct tda1004x_config philips_tiger_config = {
724 .demod_address = 0x08,
725 .invert = 1,
726 .invert_oclk = 0,
727 .xtal_freq = TDA10046_XTAL_16M,
728 .agc_config = TDA10046_AGC_TDA827X,
729 .gpio_config = TDA10046_GP11_I,
730 .if_freq = TDA10046_FREQ_045,
731 .i2c_gate = 0x4b,
732 .tuner_address = 0x61,
733 .tuner_config = 0,
734 .antenna_switch= 1,
735 .request_firmware = philips_tda1004x_request_firmware
738 static struct tda1004x_config cinergy_ht_config = {
739 .demod_address = 0x08,
740 .invert = 1,
741 .invert_oclk = 0,
742 .xtal_freq = TDA10046_XTAL_16M,
743 .agc_config = TDA10046_AGC_TDA827X,
744 .gpio_config = TDA10046_GP01_I,
745 .if_freq = TDA10046_FREQ_045,
746 .i2c_gate = 0x4b,
747 .tuner_address = 0x61,
748 .tuner_config = 0,
749 .request_firmware = philips_tda1004x_request_firmware
752 static struct tda1004x_config cinergy_ht_pci_config = {
753 .demod_address = 0x08,
754 .invert = 1,
755 .invert_oclk = 0,
756 .xtal_freq = TDA10046_XTAL_16M,
757 .agc_config = TDA10046_AGC_TDA827X,
758 .gpio_config = TDA10046_GP01_I,
759 .if_freq = TDA10046_FREQ_045,
760 .i2c_gate = 0x4b,
761 .tuner_address = 0x60,
762 .tuner_config = 0,
763 .request_firmware = philips_tda1004x_request_firmware
766 static struct tda1004x_config philips_tiger_s_config = {
767 .demod_address = 0x08,
768 .invert = 1,
769 .invert_oclk = 0,
770 .xtal_freq = TDA10046_XTAL_16M,
771 .agc_config = TDA10046_AGC_TDA827X,
772 .gpio_config = TDA10046_GP01_I,
773 .if_freq = TDA10046_FREQ_045,
774 .i2c_gate = 0x4b,
775 .tuner_address = 0x61,
776 .tuner_config = 2,
777 .antenna_switch= 1,
778 .request_firmware = philips_tda1004x_request_firmware
781 static struct tda1004x_config pinnacle_pctv_310i_config = {
782 .demod_address = 0x08,
783 .invert = 1,
784 .invert_oclk = 0,
785 .xtal_freq = TDA10046_XTAL_16M,
786 .agc_config = TDA10046_AGC_TDA827X,
787 .gpio_config = TDA10046_GP11_I,
788 .if_freq = TDA10046_FREQ_045,
789 .i2c_gate = 0x4b,
790 .tuner_address = 0x61,
791 .tuner_config = 1,
792 .request_firmware = philips_tda1004x_request_firmware
795 static struct tda1004x_config hauppauge_hvr_1110_config = {
796 .demod_address = 0x08,
797 .invert = 1,
798 .invert_oclk = 0,
799 .xtal_freq = TDA10046_XTAL_16M,
800 .agc_config = TDA10046_AGC_TDA827X,
801 .gpio_config = TDA10046_GP11_I,
802 .if_freq = TDA10046_FREQ_045,
803 .i2c_gate = 0x4b,
804 .tuner_address = 0x61,
805 .request_firmware = philips_tda1004x_request_firmware
808 static struct tda1004x_config asus_p7131_dual_config = {
809 .demod_address = 0x08,
810 .invert = 1,
811 .invert_oclk = 0,
812 .xtal_freq = TDA10046_XTAL_16M,
813 .agc_config = TDA10046_AGC_TDA827X,
814 .gpio_config = TDA10046_GP11_I,
815 .if_freq = TDA10046_FREQ_045,
816 .i2c_gate = 0x4b,
817 .tuner_address = 0x61,
818 .tuner_config = 0,
819 .antenna_switch= 2,
820 .request_firmware = philips_tda1004x_request_firmware
823 static struct tda1004x_config lifeview_trio_config = {
824 .demod_address = 0x09,
825 .invert = 1,
826 .invert_oclk = 0,
827 .xtal_freq = TDA10046_XTAL_16M,
828 .agc_config = TDA10046_AGC_TDA827X,
829 .gpio_config = TDA10046_GP00_I,
830 .if_freq = TDA10046_FREQ_045,
831 .tuner_address = 0x60,
832 .request_firmware = philips_tda1004x_request_firmware
835 static struct tda1004x_config tevion_dvbt220rf_config = {
836 .demod_address = 0x08,
837 .invert = 1,
838 .invert_oclk = 0,
839 .xtal_freq = TDA10046_XTAL_16M,
840 .agc_config = TDA10046_AGC_TDA827X,
841 .gpio_config = TDA10046_GP11_I,
842 .if_freq = TDA10046_FREQ_045,
843 .tuner_address = 0x60,
844 .request_firmware = philips_tda1004x_request_firmware
847 static struct tda1004x_config md8800_dvbt_config = {
848 .demod_address = 0x08,
849 .invert = 1,
850 .invert_oclk = 0,
851 .xtal_freq = TDA10046_XTAL_16M,
852 .agc_config = TDA10046_AGC_TDA827X,
853 .gpio_config = TDA10046_GP01_I,
854 .if_freq = TDA10046_FREQ_045,
855 .i2c_gate = 0x4b,
856 .tuner_address = 0x60,
857 .tuner_config = 0,
858 .request_firmware = philips_tda1004x_request_firmware
861 static struct tda1004x_config asus_p7131_4871_config = {
862 .demod_address = 0x08,
863 .invert = 1,
864 .invert_oclk = 0,
865 .xtal_freq = TDA10046_XTAL_16M,
866 .agc_config = TDA10046_AGC_TDA827X,
867 .gpio_config = TDA10046_GP01_I,
868 .if_freq = TDA10046_FREQ_045,
869 .i2c_gate = 0x4b,
870 .tuner_address = 0x61,
871 .tuner_config = 2,
872 .antenna_switch= 2,
873 .request_firmware = philips_tda1004x_request_firmware
876 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
877 .demod_address = 0x08,
878 .invert = 1,
879 .invert_oclk = 0,
880 .xtal_freq = TDA10046_XTAL_16M,
881 .agc_config = TDA10046_AGC_TDA827X,
882 .gpio_config = TDA10046_GP11_I,
883 .if_freq = TDA10046_FREQ_045,
884 .i2c_gate = 0x4b,
885 .tuner_address = 0x61,
886 .tuner_config = 2,
887 .antenna_switch= 2,
888 .request_firmware = philips_tda1004x_request_firmware
890 /* ------------------------------------------------------------------
891 * special case: this card uses saa713x GPIO22 for the mode switch
894 static int ads_duo_tuner_init(struct dvb_frontend *fe)
896 struct saa7134_dev *dev = fe->dvb->priv;
897 philips_tda827x_tuner_init(fe);
898 /* route TDA8275a AGC input to the channel decoder */
899 saa7134_set_gpio(dev, 22, 1);
900 return 0;
903 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
905 struct saa7134_dev *dev = fe->dvb->priv;
906 /* route TDA8275a AGC input to the analog IF chip*/
907 saa7134_set_gpio(dev, 22, 0);
908 philips_tda827x_tuner_sleep(fe);
909 return 0;
912 static struct tda827x_config ads_duo_cfg = {
913 .lna_gain = philips_tda827x_lna_gain,
914 .init = ads_duo_tuner_init,
915 .sleep = ads_duo_tuner_sleep
918 static struct tda1004x_config ads_tech_duo_config = {
919 .demod_address = 0x08,
920 .invert = 1,
921 .invert_oclk = 0,
922 .xtal_freq = TDA10046_XTAL_16M,
923 .agc_config = TDA10046_AGC_TDA827X,
924 .gpio_config = TDA10046_GP00_I,
925 .if_freq = TDA10046_FREQ_045,
926 .tuner_address = 0x61,
927 .request_firmware = philips_tda1004x_request_firmware
930 /* ==================================================================
931 * tda10086 based DVB-S cards, helper functions
934 static struct tda10086_config flydvbs = {
935 .demod_address = 0x0e,
936 .invert = 0,
939 /* ==================================================================
940 * nxt200x based ATSC cards, helper functions
943 static struct nxt200x_config avertvhda180 = {
944 .demod_address = 0x0a,
947 static int nxt200x_set_pll_input(u8 *buf, int input)
949 if (input)
950 buf[3] |= 0x08;
951 else
952 buf[3] &= ~0x08;
953 return 0;
956 static struct nxt200x_config kworldatsc110 = {
957 .demod_address = 0x0a,
958 .set_pll_input = nxt200x_set_pll_input,
961 /* ==================================================================
962 * Core code
965 static int dvb_init(struct saa7134_dev *dev)
967 int ret;
968 /* init struct videobuf_dvb */
969 dev->ts.nr_bufs = 32;
970 dev->ts.nr_packets = 32*4;
971 dev->dvb.name = dev->name;
972 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
973 dev->pci, &dev->slock,
974 V4L2_BUF_TYPE_VIDEO_CAPTURE,
975 V4L2_FIELD_ALTERNATE,
976 sizeof(struct saa7134_buf),
977 dev);
979 switch (dev->board) {
980 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
981 dprintk("pinnacle 300i dvb setup\n");
982 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
983 &dev->i2c_adap);
984 if (dev->dvb.frontend) {
985 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
987 break;
988 case SAA7134_BOARD_AVERMEDIA_777:
989 case SAA7134_BOARD_AVERMEDIA_A16AR:
990 dprintk("avertv 777 dvb setup\n");
991 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
992 &dev->i2c_adap);
993 if (dev->dvb.frontend) {
994 dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
996 break;
997 case SAA7134_BOARD_MD7134:
998 dev->dvb.frontend = dvb_attach(tda10046_attach,
999 &medion_cardbus,
1000 &dev->i2c_adap);
1001 if (dev->dvb.frontend) {
1002 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1003 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1004 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1006 break;
1007 case SAA7134_BOARD_PHILIPS_TOUGH:
1008 dev->dvb.frontend = dvb_attach(tda10046_attach,
1009 &philips_tu1216_60_config,
1010 &dev->i2c_adap);
1011 if (dev->dvb.frontend) {
1012 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1013 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1015 break;
1016 case SAA7134_BOARD_FLYDVBTDUO:
1017 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1018 configure_tda827x_fe(dev, &tda827x_lifeview_config);
1019 break;
1020 case SAA7134_BOARD_PHILIPS_EUROPA:
1021 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1022 dev->dvb.frontend = dvb_attach(tda10046_attach,
1023 &philips_europa_config,
1024 &dev->i2c_adap);
1025 if (dev->dvb.frontend) {
1026 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1027 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1028 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1029 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1030 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1032 break;
1033 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1034 dev->dvb.frontend = dvb_attach(tda10046_attach,
1035 &philips_tu1216_61_config,
1036 &dev->i2c_adap);
1037 if (dev->dvb.frontend) {
1038 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1039 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1041 break;
1042 case SAA7134_BOARD_PHILIPS_TIGER:
1043 configure_tda827x_fe(dev, &philips_tiger_config);
1044 break;
1045 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1046 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
1047 break;
1048 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1049 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
1050 break;
1051 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1052 configure_tda827x_fe(dev, &asus_p7131_dual_config);
1053 break;
1054 case SAA7134_BOARD_FLYDVBT_LR301:
1055 configure_tda827x_fe(dev, &tda827x_lifeview_config);
1056 break;
1057 case SAA7134_BOARD_FLYDVB_TRIO:
1058 if(! use_frontend) { //terrestrial
1059 configure_tda827x_fe(dev, &lifeview_trio_config);
1060 } else { //satellite
1061 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1062 if (dev->dvb.frontend) {
1063 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1064 &dev->i2c_adap, 0) == NULL) {
1065 wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1067 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1068 0x08, 0, 0) == NULL) {
1069 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1073 break;
1074 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1075 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1076 dev->dvb.frontend = dvb_attach(tda10046_attach,
1077 &ads_tech_duo_config,
1078 &dev->i2c_adap);
1079 if (dev->dvb.frontend) {
1080 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
1081 ads_tech_duo_config.tuner_address,
1082 &dev->i2c_adap,&ads_duo_cfg) == NULL) {
1083 wprintk("no tda827x tuner found at addr: %02x\n",
1084 ads_tech_duo_config.tuner_address);
1087 break;
1088 case SAA7134_BOARD_TEVION_DVBT_220RF:
1089 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
1090 break;
1091 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1092 configure_tda827x_fe(dev, &md8800_dvbt_config);
1093 break;
1094 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1095 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1096 &dev->i2c_adap);
1097 if (dev->dvb.frontend) {
1098 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1099 NULL, &dvb_pll_tdhu2);
1101 break;
1102 case SAA7134_BOARD_KWORLD_ATSC110:
1103 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1104 &dev->i2c_adap);
1105 if (dev->dvb.frontend) {
1106 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1107 NULL, &dvb_pll_tuv1236d);
1109 break;
1110 case SAA7134_BOARD_FLYDVBS_LR300:
1111 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1112 &dev->i2c_adap);
1113 if (dev->dvb.frontend) {
1114 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1115 &dev->i2c_adap, 0) == NULL) {
1116 wprintk("%s: No tda826x found!\n", __FUNCTION__);
1118 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1119 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1120 wprintk("%s: No ISL6421 found!\n", __FUNCTION__);
1123 break;
1124 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1125 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1126 &dev->i2c_adap);
1127 if (dev->dvb.frontend) {
1128 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1129 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1130 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1131 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1132 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1134 break;
1135 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1136 dev->dvb.frontend = dvb_attach(tda10046_attach,
1137 &philips_europa_config,
1138 &dev->i2c_adap);
1139 if (dev->dvb.frontend) {
1140 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1141 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1143 break;
1144 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1145 configure_tda827x_fe(dev, &cinergy_ht_config);
1146 break;
1147 case SAA7134_BOARD_CINERGY_HT_PCI:
1148 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
1149 break;
1150 case SAA7134_BOARD_PHILIPS_TIGER_S:
1151 configure_tda827x_fe(dev, &philips_tiger_s_config);
1152 break;
1153 case SAA7134_BOARD_ASUS_P7131_4871:
1154 configure_tda827x_fe(dev, &asus_p7131_4871_config);
1155 break;
1156 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1157 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1158 break;
1159 default:
1160 wprintk("Huh? unknown DVB card?\n");
1161 break;
1164 if (NULL == dev->dvb.frontend) {
1165 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1166 return -1;
1169 /* register everything else */
1170 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1172 /* this sequence is necessary to make the tda1004x load its firmware
1173 * and to enter analog mode of hybrid boards
1175 if (!ret) {
1176 if (dev->dvb.frontend->ops.init)
1177 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1178 if (dev->dvb.frontend->ops.sleep)
1179 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1180 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1181 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
1183 return ret;
1186 static int dvb_fini(struct saa7134_dev *dev)
1188 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1190 switch (dev->board) {
1191 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1192 /* otherwise we don't detect the tuner on next insmod */
1193 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1194 break;
1196 videobuf_dvb_unregister(&dev->dvb);
1197 return 0;
1200 static struct saa7134_mpeg_ops dvb_ops = {
1201 .type = SAA7134_MPEG_DVB,
1202 .init = dvb_init,
1203 .fini = dvb_fini,
1206 static int __init dvb_register(void)
1208 return saa7134_ts_register(&dvb_ops);
1211 static void __exit dvb_unregister(void)
1213 saa7134_ts_unregister(&dvb_ops);
1216 module_init(dvb_register);
1217 module_exit(dvb_unregister);
1219 /* ------------------------------------------------------------------ */
1221 * Local variables:
1222 * c-basic-offset: 8
1223 * End: