7edb49729489c04b733209637fbc193ffff865a0
[deliverable/linux.git] / drivers / media / pci / saa7134 / saa7134-dvb.c
1 /*
2 *
3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
4 *
5 * Extended 3 / 2005 by Hartmut Hackmann to support various
6 * cards with the tda10046 DVB-T channel decoder
7 *
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.
12 *
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.
17 *
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.
21 */
22
23 #include "saa7134.h"
24 #include "saa7134-reg.h"
25
26 #include <linux/init.h>
27 #include <linux/list.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/delay.h>
31 #include <linux/kthread.h>
32 #include <linux/suspend.h>
33
34 #include <media/v4l2-common.h>
35 #include "dvb-pll.h"
36 #include <dvb_frontend.h>
37
38 #include "mt352.h"
39 #include "mt352_priv.h" /* FIXME */
40 #include "tda1004x.h"
41 #include "nxt200x.h"
42 #include "tuner-xc2028.h"
43 #include "xc5000.h"
44
45 #include "tda10086.h"
46 #include "tda826x.h"
47 #include "tda827x.h"
48 #include "isl6421.h"
49 #include "isl6405.h"
50 #include "lnbp21.h"
51 #include "tuner-simple.h"
52 #include "tda10048.h"
53 #include "tda18271.h"
54 #include "lgdt3305.h"
55 #include "tda8290.h"
56 #include "mb86a20s.h"
57 #include "lgs8gxx.h"
58
59 #include "zl10353.h"
60 #include "qt1010.h"
61
62 #include "zl10036.h"
63 #include "zl10039.h"
64 #include "mt312.h"
65 #include "s5h1411.h"
66
67 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
68 MODULE_LICENSE("GPL");
69
70 static unsigned int antenna_pwr;
71
72 module_param(antenna_pwr, int, 0444);
73 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
74
75 static int use_frontend;
76 module_param(use_frontend, int, 0644);
77 MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
78
79 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
80
81 /* ------------------------------------------------------------------
82 * mt352 based DVB-T cards
83 */
84
85 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
86 {
87 u32 ok;
88
89 if (!on) {
90 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
91 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
92 return 0;
93 }
94
95 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
96 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
97 udelay(10);
98
99 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
100 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
101 udelay(10);
102 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
103 udelay(10);
104 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
105 pr_debug("%s %s\n", __func__, ok ? "on" : "off");
106
107 if (!ok)
108 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
109 return ok;
110 }
111
112 static int mt352_pinnacle_init(struct dvb_frontend* fe)
113 {
114 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
115 static u8 reset [] = { RESET, 0x80 };
116 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
117 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
118 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
119 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
120 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
121 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
122 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
123
124 pr_debug("%s called\n", __func__);
125
126 mt352_write(fe, clock_config, sizeof(clock_config));
127 udelay(200);
128 mt352_write(fe, reset, sizeof(reset));
129 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
130 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
131 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
132 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
133
134 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
135 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
136 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
137
138 return 0;
139 }
140
141 static int mt352_aver777_init(struct dvb_frontend* fe)
142 {
143 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
144 static u8 reset [] = { RESET, 0x80 };
145 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
146 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
147 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
148
149 mt352_write(fe, clock_config, sizeof(clock_config));
150 udelay(200);
151 mt352_write(fe, reset, sizeof(reset));
152 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
153 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
154 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
155
156 return 0;
157 }
158
159 static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
160 {
161 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
162 static u8 reset [] = { RESET, 0x80 };
163 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
164 static u8 agc_cfg [] = { AGC_TARGET, 0xe };
165 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
166
167 mt352_write(fe, clock_config, sizeof(clock_config));
168 udelay(200);
169 mt352_write(fe, reset, sizeof(reset));
170 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
171 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
172 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
173 return 0;
174 }
175
176 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend *fe)
177 {
178 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
179 u8 off[] = { 0x00, 0xf1};
180 u8 on[] = { 0x00, 0x71};
181 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
182
183 struct saa7134_dev *dev = fe->dvb->priv;
184 struct v4l2_frequency f;
185
186 /* set frequency (mt2050) */
187 f.tuner = 0;
188 f.type = V4L2_TUNER_DIGITAL_TV;
189 f.frequency = c->frequency / 1000 * 16 / 1000;
190 if (fe->ops.i2c_gate_ctrl)
191 fe->ops.i2c_gate_ctrl(fe, 1);
192 i2c_transfer(&dev->i2c_adap, &msg, 1);
193 saa_call_all(dev, tuner, s_frequency, &f);
194 msg.buf = on;
195 if (fe->ops.i2c_gate_ctrl)
196 fe->ops.i2c_gate_ctrl(fe, 1);
197 i2c_transfer(&dev->i2c_adap, &msg, 1);
198
199 pinnacle_antenna_pwr(dev, antenna_pwr);
200
201 /* mt352 setup */
202 return mt352_pinnacle_init(fe);
203 }
204
205 static struct mt352_config pinnacle_300i = {
206 .demod_address = 0x3c >> 1,
207 .adc_clock = 20333,
208 .if2 = 36150,
209 .no_tuner = 1,
210 .demod_init = mt352_pinnacle_init,
211 };
212
213 static struct mt352_config avermedia_777 = {
214 .demod_address = 0xf,
215 .demod_init = mt352_aver777_init,
216 };
217
218 static struct mt352_config avermedia_xc3028_mt352_dev = {
219 .demod_address = (0x1e >> 1),
220 .no_tuner = 1,
221 .demod_init = mt352_avermedia_xc3028_init,
222 };
223
224 static struct tda18271_std_map mb86a20s_tda18271_std_map = {
225 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
226 .if_lvl = 7, .rfagc_top = 0x37, },
227 };
228
229 static struct tda18271_config kworld_tda18271_config = {
230 .std_map = &mb86a20s_tda18271_std_map,
231 .gate = TDA18271_GATE_DIGITAL,
232 .config = 3, /* Use tuner callback for AGC */
233
234 };
235
236 static const struct mb86a20s_config kworld_mb86a20s_config = {
237 .demod_address = 0x10,
238 };
239
240 static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)
241 {
242 struct saa7134_dev *dev = fe->dvb->priv;
243
244 unsigned char initmsg[] = {0x45, 0x97};
245 unsigned char msg_enable[] = {0x45, 0xc1};
246 unsigned char msg_disable[] = {0x45, 0x81};
247 struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
248
249 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
250 pr_warn("could not access the I2C gate\n");
251 return -EIO;
252 }
253 if (enable)
254 msg.buf = msg_enable;
255 else
256 msg.buf = msg_disable;
257 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
258 pr_warn("could not access the I2C gate\n");
259 return -EIO;
260 }
261 msleep(20);
262 return 0;
263 }
264
265 /* ==================================================================
266 * tda1004x based DVB-T cards, helper functions
267 */
268
269 static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
270 const struct firmware **fw, char *name)
271 {
272 struct saa7134_dev *dev = fe->dvb->priv;
273 return request_firmware(fw, name, &dev->pci->dev);
274 }
275
276 /* ------------------------------------------------------------------
277 * these tuners are tu1216, td1316(a)
278 */
279
280 static int philips_tda6651_pll_set(struct dvb_frontend *fe)
281 {
282 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
283 struct saa7134_dev *dev = fe->dvb->priv;
284 struct tda1004x_state *state = fe->demodulator_priv;
285 u8 addr = state->config->tuner_address;
286 u8 tuner_buf[4];
287 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
288 sizeof(tuner_buf) };
289 int tuner_frequency = 0;
290 u8 band, cp, filter;
291
292 /* determine charge pump */
293 tuner_frequency = c->frequency + 36166000;
294 if (tuner_frequency < 87000000)
295 return -EINVAL;
296 else if (tuner_frequency < 130000000)
297 cp = 3;
298 else if (tuner_frequency < 160000000)
299 cp = 5;
300 else if (tuner_frequency < 200000000)
301 cp = 6;
302 else if (tuner_frequency < 290000000)
303 cp = 3;
304 else if (tuner_frequency < 420000000)
305 cp = 5;
306 else if (tuner_frequency < 480000000)
307 cp = 6;
308 else if (tuner_frequency < 620000000)
309 cp = 3;
310 else if (tuner_frequency < 830000000)
311 cp = 5;
312 else if (tuner_frequency < 895000000)
313 cp = 7;
314 else
315 return -EINVAL;
316
317 /* determine band */
318 if (c->frequency < 49000000)
319 return -EINVAL;
320 else if (c->frequency < 161000000)
321 band = 1;
322 else if (c->frequency < 444000000)
323 band = 2;
324 else if (c->frequency < 861000000)
325 band = 4;
326 else
327 return -EINVAL;
328
329 /* setup PLL filter */
330 switch (c->bandwidth_hz) {
331 case 6000000:
332 filter = 0;
333 break;
334
335 case 7000000:
336 filter = 0;
337 break;
338
339 case 8000000:
340 filter = 1;
341 break;
342
343 default:
344 return -EINVAL;
345 }
346
347 /* calculate divisor
348 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
349 */
350 tuner_frequency = (((c->frequency / 1000) * 6) + 217496) / 1000;
351
352 /* setup tuner buffer */
353 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
354 tuner_buf[1] = tuner_frequency & 0xff;
355 tuner_buf[2] = 0xca;
356 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
357
358 if (fe->ops.i2c_gate_ctrl)
359 fe->ops.i2c_gate_ctrl(fe, 1);
360 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
361 pr_warn("could not write to tuner at addr: 0x%02x\n",
362 addr << 1);
363 return -EIO;
364 }
365 msleep(1);
366 return 0;
367 }
368
369 static int philips_tu1216_init(struct dvb_frontend *fe)
370 {
371 struct saa7134_dev *dev = fe->dvb->priv;
372 struct tda1004x_state *state = fe->demodulator_priv;
373 u8 addr = state->config->tuner_address;
374 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
375 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
376
377 /* setup PLL configuration */
378 if (fe->ops.i2c_gate_ctrl)
379 fe->ops.i2c_gate_ctrl(fe, 1);
380 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
381 return -EIO;
382 msleep(1);
383
384 return 0;
385 }
386
387 /* ------------------------------------------------------------------ */
388
389 static struct tda1004x_config philips_tu1216_60_config = {
390 .demod_address = 0x8,
391 .invert = 1,
392 .invert_oclk = 0,
393 .xtal_freq = TDA10046_XTAL_4M,
394 .agc_config = TDA10046_AGC_DEFAULT,
395 .if_freq = TDA10046_FREQ_3617,
396 .tuner_address = 0x60,
397 .request_firmware = philips_tda1004x_request_firmware
398 };
399
400 static struct tda1004x_config philips_tu1216_61_config = {
401
402 .demod_address = 0x8,
403 .invert = 1,
404 .invert_oclk = 0,
405 .xtal_freq = TDA10046_XTAL_4M,
406 .agc_config = TDA10046_AGC_DEFAULT,
407 .if_freq = TDA10046_FREQ_3617,
408 .tuner_address = 0x61,
409 .request_firmware = philips_tda1004x_request_firmware
410 };
411
412 /* ------------------------------------------------------------------ */
413
414 static int philips_td1316_tuner_init(struct dvb_frontend *fe)
415 {
416 struct saa7134_dev *dev = fe->dvb->priv;
417 struct tda1004x_state *state = fe->demodulator_priv;
418 u8 addr = state->config->tuner_address;
419 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
420 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
421
422 /* setup PLL configuration */
423 if (fe->ops.i2c_gate_ctrl)
424 fe->ops.i2c_gate_ctrl(fe, 1);
425 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
426 return -EIO;
427 return 0;
428 }
429
430 static int philips_td1316_tuner_set_params(struct dvb_frontend *fe)
431 {
432 return philips_tda6651_pll_set(fe);
433 }
434
435 static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
436 {
437 struct saa7134_dev *dev = fe->dvb->priv;
438 struct tda1004x_state *state = fe->demodulator_priv;
439 u8 addr = state->config->tuner_address;
440 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
441 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
442
443 /* switch the tuner to analog mode */
444 if (fe->ops.i2c_gate_ctrl)
445 fe->ops.i2c_gate_ctrl(fe, 1);
446 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
447 return -EIO;
448 return 0;
449 }
450
451 /* ------------------------------------------------------------------ */
452
453 static int philips_europa_tuner_init(struct dvb_frontend *fe)
454 {
455 struct saa7134_dev *dev = fe->dvb->priv;
456 static u8 msg[] = { 0x00, 0x40};
457 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
458
459
460 if (philips_td1316_tuner_init(fe))
461 return -EIO;
462 msleep(1);
463 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
464 return -EIO;
465
466 return 0;
467 }
468
469 static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
470 {
471 struct saa7134_dev *dev = fe->dvb->priv;
472
473 static u8 msg[] = { 0x00, 0x14 };
474 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
475
476 if (philips_td1316_tuner_sleep(fe))
477 return -EIO;
478
479 /* switch the board to analog mode */
480 if (fe->ops.i2c_gate_ctrl)
481 fe->ops.i2c_gate_ctrl(fe, 1);
482 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
483 return 0;
484 }
485
486 static int philips_europa_demod_sleep(struct dvb_frontend *fe)
487 {
488 struct saa7134_dev *dev = fe->dvb->priv;
489
490 if (dev->original_demod_sleep)
491 dev->original_demod_sleep(fe);
492 fe->ops.i2c_gate_ctrl(fe, 1);
493 return 0;
494 }
495
496 static struct tda1004x_config philips_europa_config = {
497
498 .demod_address = 0x8,
499 .invert = 0,
500 .invert_oclk = 0,
501 .xtal_freq = TDA10046_XTAL_4M,
502 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
503 .if_freq = TDA10046_FREQ_052,
504 .tuner_address = 0x61,
505 .request_firmware = philips_tda1004x_request_firmware
506 };
507
508 static struct tda1004x_config medion_cardbus = {
509 .demod_address = 0x08,
510 .invert = 1,
511 .invert_oclk = 0,
512 .xtal_freq = TDA10046_XTAL_16M,
513 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
514 .if_freq = TDA10046_FREQ_3613,
515 .tuner_address = 0x61,
516 .request_firmware = philips_tda1004x_request_firmware
517 };
518
519 static struct tda1004x_config technotrend_budget_t3000_config = {
520 .demod_address = 0x8,
521 .invert = 1,
522 .invert_oclk = 0,
523 .xtal_freq = TDA10046_XTAL_4M,
524 .agc_config = TDA10046_AGC_DEFAULT,
525 .if_freq = TDA10046_FREQ_3617,
526 .tuner_address = 0x63,
527 .request_firmware = philips_tda1004x_request_firmware
528 };
529
530 /* ------------------------------------------------------------------
531 * tda 1004x based cards with philips silicon tuner
532 */
533
534 static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
535 {
536 struct tda1004x_state *state = fe->demodulator_priv;
537
538 u8 addr = state->config->i2c_gate;
539 static u8 tda8290_close[] = { 0x21, 0xc0};
540 static u8 tda8290_open[] = { 0x21, 0x80};
541 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
542 if (enable) {
543 tda8290_msg.buf = tda8290_close;
544 } else {
545 tda8290_msg.buf = tda8290_open;
546 }
547 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
548 pr_warn("could not access tda8290 I2C gate\n");
549 return -EIO;
550 }
551 msleep(20);
552 return 0;
553 }
554
555 static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
556 {
557 struct saa7134_dev *dev = fe->dvb->priv;
558 struct tda1004x_state *state = fe->demodulator_priv;
559
560 switch (state->config->antenna_switch) {
561 case 0: break;
562 case 1: pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
563 saa7134_set_gpio(dev, 21, 0);
564 break;
565 case 2: pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
566 saa7134_set_gpio(dev, 21, 1);
567 break;
568 }
569 return 0;
570 }
571
572 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
573 {
574 struct saa7134_dev *dev = fe->dvb->priv;
575 struct tda1004x_state *state = fe->demodulator_priv;
576
577 switch (state->config->antenna_switch) {
578 case 0: break;
579 case 1: pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
580 saa7134_set_gpio(dev, 21, 1);
581 break;
582 case 2: pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
583 saa7134_set_gpio(dev, 21, 0);
584 break;
585 }
586 return 0;
587 }
588
589 static int configure_tda827x_fe(struct saa7134_dev *dev,
590 struct tda1004x_config *cdec_conf,
591 struct tda827x_config *tuner_conf)
592 {
593 struct vb2_dvb_frontend *fe0;
594
595 /* Get the first frontend */
596 fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
597
598 if (!fe0)
599 return -EINVAL;
600
601 fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
602 if (fe0->dvb.frontend) {
603 if (cdec_conf->i2c_gate)
604 fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
605 if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
606 cdec_conf->tuner_address,
607 &dev->i2c_adap, tuner_conf))
608 return 0;
609
610 pr_warn("no tda827x tuner found at addr: %02x\n",
611 cdec_conf->tuner_address);
612 }
613 return -EINVAL;
614 }
615
616 /* ------------------------------------------------------------------ */
617
618 static struct tda827x_config tda827x_cfg_0 = {
619 .init = philips_tda827x_tuner_init,
620 .sleep = philips_tda827x_tuner_sleep,
621 .config = 0,
622 .switch_addr = 0
623 };
624
625 static struct tda827x_config tda827x_cfg_1 = {
626 .init = philips_tda827x_tuner_init,
627 .sleep = philips_tda827x_tuner_sleep,
628 .config = 1,
629 .switch_addr = 0x4b
630 };
631
632 static struct tda827x_config tda827x_cfg_2 = {
633 .init = philips_tda827x_tuner_init,
634 .sleep = philips_tda827x_tuner_sleep,
635 .config = 2,
636 .switch_addr = 0x4b
637 };
638
639 static struct tda827x_config tda827x_cfg_2_sw42 = {
640 .init = philips_tda827x_tuner_init,
641 .sleep = philips_tda827x_tuner_sleep,
642 .config = 2,
643 .switch_addr = 0x42
644 };
645
646 /* ------------------------------------------------------------------ */
647
648 static struct tda1004x_config tda827x_lifeview_config = {
649 .demod_address = 0x08,
650 .invert = 1,
651 .invert_oclk = 0,
652 .xtal_freq = TDA10046_XTAL_16M,
653 .agc_config = TDA10046_AGC_TDA827X,
654 .gpio_config = TDA10046_GP11_I,
655 .if_freq = TDA10046_FREQ_045,
656 .tuner_address = 0x60,
657 .request_firmware = philips_tda1004x_request_firmware
658 };
659
660 static struct tda1004x_config philips_tiger_config = {
661 .demod_address = 0x08,
662 .invert = 1,
663 .invert_oclk = 0,
664 .xtal_freq = TDA10046_XTAL_16M,
665 .agc_config = TDA10046_AGC_TDA827X,
666 .gpio_config = TDA10046_GP11_I,
667 .if_freq = TDA10046_FREQ_045,
668 .i2c_gate = 0x4b,
669 .tuner_address = 0x61,
670 .antenna_switch= 1,
671 .request_firmware = philips_tda1004x_request_firmware
672 };
673
674 static struct tda1004x_config cinergy_ht_config = {
675 .demod_address = 0x08,
676 .invert = 1,
677 .invert_oclk = 0,
678 .xtal_freq = TDA10046_XTAL_16M,
679 .agc_config = TDA10046_AGC_TDA827X,
680 .gpio_config = TDA10046_GP01_I,
681 .if_freq = TDA10046_FREQ_045,
682 .i2c_gate = 0x4b,
683 .tuner_address = 0x61,
684 .request_firmware = philips_tda1004x_request_firmware
685 };
686
687 static struct tda1004x_config cinergy_ht_pci_config = {
688 .demod_address = 0x08,
689 .invert = 1,
690 .invert_oclk = 0,
691 .xtal_freq = TDA10046_XTAL_16M,
692 .agc_config = TDA10046_AGC_TDA827X,
693 .gpio_config = TDA10046_GP01_I,
694 .if_freq = TDA10046_FREQ_045,
695 .i2c_gate = 0x4b,
696 .tuner_address = 0x60,
697 .request_firmware = philips_tda1004x_request_firmware
698 };
699
700 static struct tda1004x_config philips_tiger_s_config = {
701 .demod_address = 0x08,
702 .invert = 1,
703 .invert_oclk = 0,
704 .xtal_freq = TDA10046_XTAL_16M,
705 .agc_config = TDA10046_AGC_TDA827X,
706 .gpio_config = TDA10046_GP01_I,
707 .if_freq = TDA10046_FREQ_045,
708 .i2c_gate = 0x4b,
709 .tuner_address = 0x61,
710 .antenna_switch= 1,
711 .request_firmware = philips_tda1004x_request_firmware
712 };
713
714 static struct tda1004x_config pinnacle_pctv_310i_config = {
715 .demod_address = 0x08,
716 .invert = 1,
717 .invert_oclk = 0,
718 .xtal_freq = TDA10046_XTAL_16M,
719 .agc_config = TDA10046_AGC_TDA827X,
720 .gpio_config = TDA10046_GP11_I,
721 .if_freq = TDA10046_FREQ_045,
722 .i2c_gate = 0x4b,
723 .tuner_address = 0x61,
724 .request_firmware = philips_tda1004x_request_firmware
725 };
726
727 static struct tda1004x_config hauppauge_hvr_1110_config = {
728 .demod_address = 0x08,
729 .invert = 1,
730 .invert_oclk = 0,
731 .xtal_freq = TDA10046_XTAL_16M,
732 .agc_config = TDA10046_AGC_TDA827X,
733 .gpio_config = TDA10046_GP11_I,
734 .if_freq = TDA10046_FREQ_045,
735 .i2c_gate = 0x4b,
736 .tuner_address = 0x61,
737 .request_firmware = philips_tda1004x_request_firmware
738 };
739
740 static struct tda1004x_config asus_p7131_dual_config = {
741 .demod_address = 0x08,
742 .invert = 1,
743 .invert_oclk = 0,
744 .xtal_freq = TDA10046_XTAL_16M,
745 .agc_config = TDA10046_AGC_TDA827X,
746 .gpio_config = TDA10046_GP11_I,
747 .if_freq = TDA10046_FREQ_045,
748 .i2c_gate = 0x4b,
749 .tuner_address = 0x61,
750 .antenna_switch= 2,
751 .request_firmware = philips_tda1004x_request_firmware
752 };
753
754 static struct tda1004x_config lifeview_trio_config = {
755 .demod_address = 0x09,
756 .invert = 1,
757 .invert_oclk = 0,
758 .xtal_freq = TDA10046_XTAL_16M,
759 .agc_config = TDA10046_AGC_TDA827X,
760 .gpio_config = TDA10046_GP00_I,
761 .if_freq = TDA10046_FREQ_045,
762 .tuner_address = 0x60,
763 .request_firmware = philips_tda1004x_request_firmware
764 };
765
766 static struct tda1004x_config tevion_dvbt220rf_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_GP11_I,
773 .if_freq = TDA10046_FREQ_045,
774 .tuner_address = 0x60,
775 .request_firmware = philips_tda1004x_request_firmware
776 };
777
778 static struct tda1004x_config md8800_dvbt_config = {
779 .demod_address = 0x08,
780 .invert = 1,
781 .invert_oclk = 0,
782 .xtal_freq = TDA10046_XTAL_16M,
783 .agc_config = TDA10046_AGC_TDA827X,
784 .gpio_config = TDA10046_GP01_I,
785 .if_freq = TDA10046_FREQ_045,
786 .i2c_gate = 0x4b,
787 .tuner_address = 0x60,
788 .request_firmware = philips_tda1004x_request_firmware
789 };
790
791 static struct tda1004x_config asus_p7131_4871_config = {
792 .demod_address = 0x08,
793 .invert = 1,
794 .invert_oclk = 0,
795 .xtal_freq = TDA10046_XTAL_16M,
796 .agc_config = TDA10046_AGC_TDA827X,
797 .gpio_config = TDA10046_GP01_I,
798 .if_freq = TDA10046_FREQ_045,
799 .i2c_gate = 0x4b,
800 .tuner_address = 0x61,
801 .antenna_switch= 2,
802 .request_firmware = philips_tda1004x_request_firmware
803 };
804
805 static struct tda1004x_config asus_p7131_hybrid_lna_config = {
806 .demod_address = 0x08,
807 .invert = 1,
808 .invert_oclk = 0,
809 .xtal_freq = TDA10046_XTAL_16M,
810 .agc_config = TDA10046_AGC_TDA827X,
811 .gpio_config = TDA10046_GP11_I,
812 .if_freq = TDA10046_FREQ_045,
813 .i2c_gate = 0x4b,
814 .tuner_address = 0x61,
815 .antenna_switch= 2,
816 .request_firmware = philips_tda1004x_request_firmware
817 };
818
819 static struct tda1004x_config kworld_dvb_t_210_config = {
820 .demod_address = 0x08,
821 .invert = 1,
822 .invert_oclk = 0,
823 .xtal_freq = TDA10046_XTAL_16M,
824 .agc_config = TDA10046_AGC_TDA827X,
825 .gpio_config = TDA10046_GP11_I,
826 .if_freq = TDA10046_FREQ_045,
827 .i2c_gate = 0x4b,
828 .tuner_address = 0x61,
829 .antenna_switch= 1,
830 .request_firmware = philips_tda1004x_request_firmware
831 };
832
833 static struct tda1004x_config avermedia_super_007_config = {
834 .demod_address = 0x08,
835 .invert = 1,
836 .invert_oclk = 0,
837 .xtal_freq = TDA10046_XTAL_16M,
838 .agc_config = TDA10046_AGC_TDA827X,
839 .gpio_config = TDA10046_GP01_I,
840 .if_freq = TDA10046_FREQ_045,
841 .i2c_gate = 0x4b,
842 .tuner_address = 0x60,
843 .antenna_switch= 1,
844 .request_firmware = philips_tda1004x_request_firmware
845 };
846
847 static struct tda1004x_config twinhan_dtv_dvb_3056_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 = 0x42,
856 .tuner_address = 0x61,
857 .antenna_switch = 1,
858 .request_firmware = philips_tda1004x_request_firmware
859 };
860
861 static struct tda1004x_config asus_tiger_3in1_config = {
862 .demod_address = 0x0b,
863 .invert = 1,
864 .invert_oclk = 0,
865 .xtal_freq = TDA10046_XTAL_16M,
866 .agc_config = TDA10046_AGC_TDA827X,
867 .gpio_config = TDA10046_GP11_I,
868 .if_freq = TDA10046_FREQ_045,
869 .i2c_gate = 0x4b,
870 .tuner_address = 0x61,
871 .antenna_switch = 1,
872 .request_firmware = philips_tda1004x_request_firmware
873 };
874
875 static struct tda1004x_config asus_ps3_100_config = {
876 .demod_address = 0x0b,
877 .invert = 1,
878 .invert_oclk = 0,
879 .xtal_freq = TDA10046_XTAL_16M,
880 .agc_config = TDA10046_AGC_TDA827X,
881 .gpio_config = TDA10046_GP11_I,
882 .if_freq = TDA10046_FREQ_045,
883 .i2c_gate = 0x4b,
884 .tuner_address = 0x61,
885 .antenna_switch = 1,
886 .request_firmware = philips_tda1004x_request_firmware
887 };
888
889 /* ------------------------------------------------------------------
890 * special case: this card uses saa713x GPIO22 for the mode switch
891 */
892
893 static int ads_duo_tuner_init(struct dvb_frontend *fe)
894 {
895 struct saa7134_dev *dev = fe->dvb->priv;
896 philips_tda827x_tuner_init(fe);
897 /* route TDA8275a AGC input to the channel decoder */
898 saa7134_set_gpio(dev, 22, 1);
899 return 0;
900 }
901
902 static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
903 {
904 struct saa7134_dev *dev = fe->dvb->priv;
905 /* route TDA8275a AGC input to the analog IF chip*/
906 saa7134_set_gpio(dev, 22, 0);
907 philips_tda827x_tuner_sleep(fe);
908 return 0;
909 }
910
911 static struct tda827x_config ads_duo_cfg = {
912 .init = ads_duo_tuner_init,
913 .sleep = ads_duo_tuner_sleep,
914 .config = 0
915 };
916
917 static struct tda1004x_config ads_tech_duo_config = {
918 .demod_address = 0x08,
919 .invert = 1,
920 .invert_oclk = 0,
921 .xtal_freq = TDA10046_XTAL_16M,
922 .agc_config = TDA10046_AGC_TDA827X,
923 .gpio_config = TDA10046_GP00_I,
924 .if_freq = TDA10046_FREQ_045,
925 .tuner_address = 0x61,
926 .request_firmware = philips_tda1004x_request_firmware
927 };
928
929 static struct zl10353_config behold_h6_config = {
930 .demod_address = 0x1e>>1,
931 .no_tuner = 1,
932 .parallel_ts = 1,
933 .disable_i2c_gate_ctrl = 1,
934 };
935
936 static struct xc5000_config behold_x7_tunerconfig = {
937 .i2c_address = 0xc2>>1,
938 .if_khz = 4560,
939 .radio_input = XC5000_RADIO_FM1,
940 };
941
942 static struct zl10353_config behold_x7_config = {
943 .demod_address = 0x1e>>1,
944 .if2 = 45600,
945 .no_tuner = 1,
946 .parallel_ts = 1,
947 .disable_i2c_gate_ctrl = 1,
948 };
949
950 static struct zl10353_config videomate_t750_zl10353_config = {
951 .demod_address = 0x0f,
952 .no_tuner = 1,
953 .parallel_ts = 1,
954 .disable_i2c_gate_ctrl = 1,
955 };
956
957 static struct qt1010_config videomate_t750_qt1010_config = {
958 .i2c_address = 0x62
959 };
960
961
962 /* ==================================================================
963 * tda10086 based DVB-S cards, helper functions
964 */
965
966 static struct tda10086_config flydvbs = {
967 .demod_address = 0x0e,
968 .invert = 0,
969 .diseqc_tone = 0,
970 .xtal_freq = TDA10086_XTAL_16M,
971 };
972
973 static struct tda10086_config sd1878_4m = {
974 .demod_address = 0x0e,
975 .invert = 0,
976 .diseqc_tone = 0,
977 .xtal_freq = TDA10086_XTAL_4M,
978 };
979
980 /* ------------------------------------------------------------------
981 * special case: lnb supply is connected to the gated i2c
982 */
983
984 static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
985 {
986 int res = -EIO;
987 struct saa7134_dev *dev = fe->dvb->priv;
988 if (fe->ops.i2c_gate_ctrl) {
989 fe->ops.i2c_gate_ctrl(fe, 1);
990 if (dev->original_set_voltage)
991 res = dev->original_set_voltage(fe, voltage);
992 fe->ops.i2c_gate_ctrl(fe, 0);
993 }
994 return res;
995 };
996
997 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
998 {
999 int res = -EIO;
1000 struct saa7134_dev *dev = fe->dvb->priv;
1001 if (fe->ops.i2c_gate_ctrl) {
1002 fe->ops.i2c_gate_ctrl(fe, 1);
1003 if (dev->original_set_high_voltage)
1004 res = dev->original_set_high_voltage(fe, arg);
1005 fe->ops.i2c_gate_ctrl(fe, 0);
1006 }
1007 return res;
1008 };
1009
1010 static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
1011 {
1012 struct saa7134_dev *dev = fe->dvb->priv;
1013 u8 wbuf[2] = { 0x1f, 00 };
1014 u8 rbuf;
1015 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
1016 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
1017
1018 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
1019 return -EIO;
1020 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
1021 if (voltage == SEC_VOLTAGE_18)
1022 wbuf[1] = rbuf | 0x10;
1023 else
1024 wbuf[1] = rbuf & 0xef;
1025 msg[0].len = 2;
1026 i2c_transfer(&dev->i2c_adap, msg, 1);
1027 return 0;
1028 }
1029
1030 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
1031 {
1032 pr_warn("%s: sorry can't set high LNB supply voltage from here\n", __func__);
1033 return -EIO;
1034 }
1035
1036 /* ==================================================================
1037 * nxt200x based ATSC cards, helper functions
1038 */
1039
1040 static struct nxt200x_config avertvhda180 = {
1041 .demod_address = 0x0a,
1042 };
1043
1044 static struct nxt200x_config kworldatsc110 = {
1045 .demod_address = 0x0a,
1046 };
1047
1048 /* ------------------------------------------------------------------ */
1049
1050 static struct mt312_config avertv_a700_mt312 = {
1051 .demod_address = 0x0e,
1052 .voltage_inverted = 1,
1053 };
1054
1055 static struct zl10036_config avertv_a700_tuner = {
1056 .tuner_address = 0x60,
1057 };
1058
1059 static struct mt312_config zl10313_compro_s350_config = {
1060 .demod_address = 0x0e,
1061 };
1062
1063 static struct mt312_config zl10313_avermedia_a706_config = {
1064 .demod_address = 0x0e,
1065 };
1066
1067 static struct lgdt3305_config hcw_lgdt3305_config = {
1068 .i2c_addr = 0x0e,
1069 .mpeg_mode = LGDT3305_MPEG_SERIAL,
1070 .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
1071 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
1072 .deny_i2c_rptr = 1,
1073 .spectral_inversion = 1,
1074 .qam_if_khz = 4000,
1075 .vsb_if_khz = 3250,
1076 };
1077
1078 static struct tda10048_config hcw_tda10048_config = {
1079 .demod_address = 0x10 >> 1,
1080 .output_mode = TDA10048_SERIAL_OUTPUT,
1081 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1082 .inversion = TDA10048_INVERSION_ON,
1083 .dtv6_if_freq_khz = TDA10048_IF_3300,
1084 .dtv7_if_freq_khz = TDA10048_IF_3500,
1085 .dtv8_if_freq_khz = TDA10048_IF_4000,
1086 .clk_freq_khz = TDA10048_CLK_16000,
1087 .disable_gate_access = 1,
1088 };
1089
1090 static struct tda18271_std_map hauppauge_tda18271_std_map = {
1091 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
1092 .if_lvl = 1, .rfagc_top = 0x58, },
1093 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
1094 .if_lvl = 1, .rfagc_top = 0x58, },
1095 };
1096
1097 static struct tda18271_config hcw_tda18271_config = {
1098 .std_map = &hauppauge_tda18271_std_map,
1099 .gate = TDA18271_GATE_ANALOG,
1100 .config = 3,
1101 .output_opt = TDA18271_OUTPUT_LT_OFF,
1102 };
1103
1104 static struct tda829x_config tda829x_no_probe = {
1105 .probe_tuner = TDA829X_DONT_PROBE,
1106 };
1107
1108 static struct tda10048_config zolid_tda10048_config = {
1109 .demod_address = 0x10 >> 1,
1110 .output_mode = TDA10048_PARALLEL_OUTPUT,
1111 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1112 .inversion = TDA10048_INVERSION_ON,
1113 .dtv6_if_freq_khz = TDA10048_IF_3300,
1114 .dtv7_if_freq_khz = TDA10048_IF_3500,
1115 .dtv8_if_freq_khz = TDA10048_IF_4000,
1116 .clk_freq_khz = TDA10048_CLK_16000,
1117 .disable_gate_access = 1,
1118 };
1119
1120 static struct tda18271_config zolid_tda18271_config = {
1121 .gate = TDA18271_GATE_ANALOG,
1122 };
1123
1124 static struct tda10048_config dtv1000s_tda10048_config = {
1125 .demod_address = 0x10 >> 1,
1126 .output_mode = TDA10048_PARALLEL_OUTPUT,
1127 .fwbulkwritelen = TDA10048_BULKWRITE_200,
1128 .inversion = TDA10048_INVERSION_ON,
1129 .dtv6_if_freq_khz = TDA10048_IF_3300,
1130 .dtv7_if_freq_khz = TDA10048_IF_3800,
1131 .dtv8_if_freq_khz = TDA10048_IF_4300,
1132 .clk_freq_khz = TDA10048_CLK_16000,
1133 .disable_gate_access = 1,
1134 };
1135
1136 static struct tda18271_std_map dtv1000s_tda18271_std_map = {
1137 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
1138 .if_lvl = 1, .rfagc_top = 0x37, },
1139 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
1140 .if_lvl = 1, .rfagc_top = 0x37, },
1141 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
1142 .if_lvl = 1, .rfagc_top = 0x37, },
1143 };
1144
1145 static struct tda18271_config dtv1000s_tda18271_config = {
1146 .std_map = &dtv1000s_tda18271_std_map,
1147 .gate = TDA18271_GATE_ANALOG,
1148 };
1149
1150 static struct lgs8gxx_config prohdtv_pro2_lgs8g75_config = {
1151 .prod = LGS8GXX_PROD_LGS8G75,
1152 .demod_address = 0x1d,
1153 .serial_ts = 0,
1154 .ts_clk_pol = 1,
1155 .ts_clk_gated = 0,
1156 .if_clk_freq = 30400, /* 30.4 MHz */
1157 .if_freq = 4000, /* 4.00 MHz */
1158 .if_neg_center = 0,
1159 .ext_adc = 0,
1160 .adc_signed = 1,
1161 .adc_vpp = 3, /* 2.0 Vpp */
1162 .if_neg_edge = 1,
1163 };
1164
1165 static struct tda18271_config prohdtv_pro2_tda18271_config = {
1166 .gate = TDA18271_GATE_ANALOG,
1167 .output_opt = TDA18271_OUTPUT_LT_OFF,
1168 };
1169
1170 static struct tda18271_std_map kworld_tda18271_std_map = {
1171 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 3,
1172 .if_lvl = 6, .rfagc_top = 0x37 },
1173 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
1174 .if_lvl = 6, .rfagc_top = 0x37 },
1175 };
1176
1177 static struct tda18271_config kworld_pc150u_tda18271_config = {
1178 .std_map = &kworld_tda18271_std_map,
1179 .gate = TDA18271_GATE_ANALOG,
1180 .output_opt = TDA18271_OUTPUT_LT_OFF,
1181 .config = 3, /* Use tuner callback for AGC */
1182 .rf_cal_on_startup = 1
1183 };
1184
1185 static struct s5h1411_config kworld_s5h1411_config = {
1186 .output_mode = S5H1411_PARALLEL_OUTPUT,
1187 .gpio = S5H1411_GPIO_OFF,
1188 .qam_if = S5H1411_IF_4000,
1189 .vsb_if = S5H1411_IF_3250,
1190 .inversion = S5H1411_INVERSION_ON,
1191 .status_mode = S5H1411_DEMODLOCKING,
1192 .mpeg_timing =
1193 S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
1194 };
1195
1196
1197 /* ==================================================================
1198 * Core code
1199 */
1200
1201 static int dvb_init(struct saa7134_dev *dev)
1202 {
1203 int ret;
1204 int attach_xc3028 = 0;
1205 struct vb2_dvb_frontend *fe0;
1206 struct vb2_queue *q;
1207
1208 /* FIXME: add support for multi-frontend */
1209 mutex_init(&dev->frontends.lock);
1210 INIT_LIST_HEAD(&dev->frontends.felist);
1211
1212 pr_info("%s() allocating 1 frontend\n", __func__);
1213 fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1);
1214 if (!fe0) {
1215 pr_err("%s() failed to alloc\n", __func__);
1216 return -ENOMEM;
1217 }
1218
1219 /* init struct vb2_dvb */
1220 dev->ts.nr_bufs = 32;
1221 dev->ts.nr_packets = 32*4;
1222 fe0->dvb.name = dev->name;
1223 q = &fe0->dvb.dvbq;
1224 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1225 q->io_modes = VB2_MMAP | VB2_READ;
1226 q->drv_priv = &dev->ts_q;
1227 q->ops = &saa7134_ts_qops;
1228 q->mem_ops = &vb2_dma_sg_memops;
1229 q->buf_struct_size = sizeof(struct saa7134_buf);
1230 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1231 q->lock = &dev->lock;
1232 ret = vb2_queue_init(q);
1233 if (ret) {
1234 vb2_dvb_dealloc_frontends(&dev->frontends);
1235 return ret;
1236 }
1237
1238 switch (dev->board) {
1239 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1240 pr_debug("pinnacle 300i dvb setup\n");
1241 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
1242 &dev->i2c_adap);
1243 if (fe0->dvb.frontend) {
1244 fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
1245 }
1246 break;
1247 case SAA7134_BOARD_AVERMEDIA_777:
1248 case SAA7134_BOARD_AVERMEDIA_A16AR:
1249 pr_debug("avertv 777 dvb setup\n");
1250 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1251 &dev->i2c_adap);
1252 if (fe0->dvb.frontend) {
1253 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1254 &dev->i2c_adap, 0x61,
1255 TUNER_PHILIPS_TD1316);
1256 }
1257 break;
1258 case SAA7134_BOARD_AVERMEDIA_A16D:
1259 pr_debug("AverMedia A16D dvb setup\n");
1260 fe0->dvb.frontend = dvb_attach(mt352_attach,
1261 &avermedia_xc3028_mt352_dev,
1262 &dev->i2c_adap);
1263 attach_xc3028 = 1;
1264 break;
1265 case SAA7134_BOARD_MD7134:
1266 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1267 &medion_cardbus,
1268 &dev->i2c_adap);
1269 if (fe0->dvb.frontend) {
1270 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1271 &dev->i2c_adap, medion_cardbus.tuner_address,
1272 TUNER_PHILIPS_FMD1216ME_MK3);
1273 }
1274 break;
1275 case SAA7134_BOARD_PHILIPS_TOUGH:
1276 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1277 &philips_tu1216_60_config,
1278 &dev->i2c_adap);
1279 if (fe0->dvb.frontend) {
1280 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1281 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1282 }
1283 break;
1284 case SAA7134_BOARD_FLYDVBTDUO:
1285 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1286 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1287 &tda827x_cfg_0) < 0)
1288 goto detach_frontend;
1289 break;
1290 case SAA7134_BOARD_PHILIPS_EUROPA:
1291 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1292 case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
1293 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1294 &philips_europa_config,
1295 &dev->i2c_adap);
1296 if (fe0->dvb.frontend) {
1297 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1298 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1299 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1300 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1301 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1302 }
1303 break;
1304 case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
1305 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1306 &technotrend_budget_t3000_config,
1307 &dev->i2c_adap);
1308 if (fe0->dvb.frontend) {
1309 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1310 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1311 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1312 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1313 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1314 }
1315 break;
1316 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1317 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1318 &philips_tu1216_61_config,
1319 &dev->i2c_adap);
1320 if (fe0->dvb.frontend) {
1321 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1322 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1323 }
1324 break;
1325 case SAA7134_BOARD_KWORLD_DVBT_210:
1326 if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
1327 &tda827x_cfg_2) < 0)
1328 goto detach_frontend;
1329 break;
1330 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
1331 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1332 &hcw_tda10048_config,
1333 &dev->i2c_adap);
1334 if (fe0->dvb.frontend != NULL) {
1335 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1336 &dev->i2c_adap, 0x4b,
1337 &tda829x_no_probe);
1338 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1339 0x60, &dev->i2c_adap,
1340 &hcw_tda18271_config);
1341 }
1342 break;
1343 case SAA7134_BOARD_PHILIPS_TIGER:
1344 if (configure_tda827x_fe(dev, &philips_tiger_config,
1345 &tda827x_cfg_0) < 0)
1346 goto detach_frontend;
1347 break;
1348 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1349 if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
1350 &tda827x_cfg_1) < 0)
1351 goto detach_frontend;
1352 break;
1353 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1354 if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
1355 &tda827x_cfg_1) < 0)
1356 goto detach_frontend;
1357 break;
1358 case SAA7134_BOARD_HAUPPAUGE_HVR1150:
1359 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1360 &hcw_lgdt3305_config,
1361 &dev->i2c_adap);
1362 if (fe0->dvb.frontend) {
1363 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1364 &dev->i2c_adap, 0x4b,
1365 &tda829x_no_probe);
1366 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1367 0x60, &dev->i2c_adap,
1368 &hcw_tda18271_config);
1369 }
1370 break;
1371 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1372 if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
1373 &tda827x_cfg_0) < 0)
1374 goto detach_frontend;
1375 break;
1376 case SAA7134_BOARD_FLYDVBT_LR301:
1377 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1378 &tda827x_cfg_0) < 0)
1379 goto detach_frontend;
1380 break;
1381 case SAA7134_BOARD_FLYDVB_TRIO:
1382 if (!use_frontend) { /* terrestrial */
1383 if (configure_tda827x_fe(dev, &lifeview_trio_config,
1384 &tda827x_cfg_0) < 0)
1385 goto detach_frontend;
1386 } else { /* satellite */
1387 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1388 if (fe0->dvb.frontend) {
1389 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
1390 &dev->i2c_adap, 0) == NULL) {
1391 pr_warn("%s: Lifeview Trio, No tda826x found!\n", __func__);
1392 goto detach_frontend;
1393 }
1394 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1395 &dev->i2c_adap,
1396 0x08, 0, 0, false) == NULL) {
1397 pr_warn("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1398 goto detach_frontend;
1399 }
1400 }
1401 }
1402 break;
1403 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1404 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1405 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1406 &ads_tech_duo_config,
1407 &dev->i2c_adap);
1408 if (fe0->dvb.frontend) {
1409 if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
1410 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1411 &ads_duo_cfg) == NULL) {
1412 pr_warn("no tda827x tuner found at addr: %02x\n",
1413 ads_tech_duo_config.tuner_address);
1414 goto detach_frontend;
1415 }
1416 } else
1417 pr_warn("failed to attach tda10046\n");
1418 break;
1419 case SAA7134_BOARD_TEVION_DVBT_220RF:
1420 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
1421 &tda827x_cfg_0) < 0)
1422 goto detach_frontend;
1423 break;
1424 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1425 if (!use_frontend) { /* terrestrial */
1426 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1427 &tda827x_cfg_0) < 0)
1428 goto detach_frontend;
1429 } else { /* satellite */
1430 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1431 &flydvbs, &dev->i2c_adap);
1432 if (fe0->dvb.frontend) {
1433 struct dvb_frontend *fe = fe0->dvb.frontend;
1434 u8 dev_id = dev->eedata[2];
1435 u8 data = 0xc4;
1436 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1437
1438 if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
1439 0x60, &dev->i2c_adap, 0) == NULL) {
1440 pr_warn("%s: Medion Quadro, no tda826x "
1441 "found !\n", __func__);
1442 goto detach_frontend;
1443 }
1444 if (dev_id != 0x08) {
1445 /* we need to open the i2c gate (we know it exists) */
1446 fe->ops.i2c_gate_ctrl(fe, 1);
1447 if (dvb_attach(isl6405_attach, fe,
1448 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1449 pr_warn("%s: Medion Quadro, no ISL6405 "
1450 "found !\n", __func__);
1451 goto detach_frontend;
1452 }
1453 if (dev_id == 0x07) {
1454 /* fire up the 2nd section of the LNB supply since
1455 we can't do this from the other section */
1456 msg.buf = &data;
1457 i2c_transfer(&dev->i2c_adap, &msg, 1);
1458 }
1459 fe->ops.i2c_gate_ctrl(fe, 0);
1460 dev->original_set_voltage = fe->ops.set_voltage;
1461 fe->ops.set_voltage = md8800_set_voltage;
1462 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1463 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1464 } else {
1465 fe->ops.set_voltage = md8800_set_voltage2;
1466 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1467 }
1468 }
1469 }
1470 break;
1471 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1472 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1473 &dev->i2c_adap);
1474 if (fe0->dvb.frontend)
1475 dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
1476 NULL, DVB_PLL_TDHU2);
1477 break;
1478 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
1479 case SAA7134_BOARD_KWORLD_ATSC110:
1480 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1481 &dev->i2c_adap);
1482 if (fe0->dvb.frontend)
1483 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1484 &dev->i2c_adap, 0x61,
1485 TUNER_PHILIPS_TUV1236D);
1486 break;
1487 case SAA7134_BOARD_KWORLD_PC150U:
1488 saa7134_set_gpio(dev, 18, 1); /* Switch to digital mode */
1489 saa7134_tuner_callback(dev, 0,
1490 TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
1491 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1492 &kworld_s5h1411_config,
1493 &dev->i2c_adap);
1494 if (fe0->dvb.frontend != NULL) {
1495 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1496 &dev->i2c_adap, 0x4b,
1497 &tda829x_no_probe);
1498 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1499 0x60, &dev->i2c_adap,
1500 &kworld_pc150u_tda18271_config);
1501 }
1502 break;
1503 case SAA7134_BOARD_FLYDVBS_LR300:
1504 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1505 &dev->i2c_adap);
1506 if (fe0->dvb.frontend) {
1507 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1508 &dev->i2c_adap, 0) == NULL) {
1509 pr_warn("%s: No tda826x found!\n", __func__);
1510 goto detach_frontend;
1511 }
1512 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1513 &dev->i2c_adap,
1514 0x08, 0, 0, false) == NULL) {
1515 pr_warn("%s: No ISL6421 found!\n", __func__);
1516 goto detach_frontend;
1517 }
1518 }
1519 break;
1520 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1521 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1522 &medion_cardbus,
1523 &dev->i2c_adap);
1524 if (fe0->dvb.frontend) {
1525 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1526 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1527
1528 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1529 &dev->i2c_adap, medion_cardbus.tuner_address,
1530 TUNER_PHILIPS_FMD1216ME_MK3);
1531 }
1532 break;
1533 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1534 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1535 &philips_europa_config,
1536 &dev->i2c_adap);
1537 if (fe0->dvb.frontend) {
1538 fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1539 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1540 }
1541 break;
1542 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1543 if (configure_tda827x_fe(dev, &cinergy_ht_config,
1544 &tda827x_cfg_0) < 0)
1545 goto detach_frontend;
1546 break;
1547 case SAA7134_BOARD_CINERGY_HT_PCI:
1548 if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
1549 &tda827x_cfg_0) < 0)
1550 goto detach_frontend;
1551 break;
1552 case SAA7134_BOARD_PHILIPS_TIGER_S:
1553 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1554 &tda827x_cfg_2) < 0)
1555 goto detach_frontend;
1556 break;
1557 case SAA7134_BOARD_ASUS_P7131_4871:
1558 if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
1559 &tda827x_cfg_2) < 0)
1560 goto detach_frontend;
1561 break;
1562 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1563 if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
1564 &tda827x_cfg_2) < 0)
1565 goto detach_frontend;
1566 break;
1567 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1568 if (configure_tda827x_fe(dev, &avermedia_super_007_config,
1569 &tda827x_cfg_0) < 0)
1570 goto detach_frontend;
1571 break;
1572 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1573 if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
1574 &tda827x_cfg_2_sw42) < 0)
1575 goto detach_frontend;
1576 break;
1577 case SAA7134_BOARD_PHILIPS_SNAKE:
1578 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1579 &dev->i2c_adap);
1580 if (fe0->dvb.frontend) {
1581 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1582 &dev->i2c_adap, 0) == NULL) {
1583 pr_warn("%s: No tda826x found!\n", __func__);
1584 goto detach_frontend;
1585 }
1586 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1587 &dev->i2c_adap, 0, 0) == NULL) {
1588 pr_warn("%s: No lnbp21 found!\n", __func__);
1589 goto detach_frontend;
1590 }
1591 }
1592 break;
1593 case SAA7134_BOARD_CREATIX_CTX953:
1594 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1595 &tda827x_cfg_0) < 0)
1596 goto detach_frontend;
1597 break;
1598 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1599 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1600 &tda827x_cfg_2) < 0)
1601 goto detach_frontend;
1602 break;
1603 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1604 pr_debug("AverMedia E506R dvb setup\n");
1605 saa7134_set_gpio(dev, 25, 0);
1606 msleep(10);
1607 saa7134_set_gpio(dev, 25, 1);
1608 fe0->dvb.frontend = dvb_attach(mt352_attach,
1609 &avermedia_xc3028_mt352_dev,
1610 &dev->i2c_adap);
1611 attach_xc3028 = 1;
1612 break;
1613 case SAA7134_BOARD_MD7134_BRIDGE_2:
1614 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1615 &sd1878_4m, &dev->i2c_adap);
1616 if (fe0->dvb.frontend) {
1617 struct dvb_frontend *fe;
1618 if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1619 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
1620 pr_warn("%s: MD7134 DVB-S, no SD1878 "
1621 "found !\n", __func__);
1622 goto detach_frontend;
1623 }
1624 /* we need to open the i2c gate (we know it exists) */
1625 fe = fe0->dvb.frontend;
1626 fe->ops.i2c_gate_ctrl(fe, 1);
1627 if (dvb_attach(isl6405_attach, fe,
1628 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1629 pr_warn("%s: MD7134 DVB-S, no ISL6405 "
1630 "found !\n", __func__);
1631 goto detach_frontend;
1632 }
1633 fe->ops.i2c_gate_ctrl(fe, 0);
1634 dev->original_set_voltage = fe->ops.set_voltage;
1635 fe->ops.set_voltage = md8800_set_voltage;
1636 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1637 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1638 }
1639 break;
1640 case SAA7134_BOARD_AVERMEDIA_M103:
1641 saa7134_set_gpio(dev, 25, 0);
1642 msleep(10);
1643 saa7134_set_gpio(dev, 25, 1);
1644 fe0->dvb.frontend = dvb_attach(mt352_attach,
1645 &avermedia_xc3028_mt352_dev,
1646 &dev->i2c_adap);
1647 attach_xc3028 = 1;
1648 break;
1649 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1650 if (!use_frontend) { /* terrestrial */
1651 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1652 &tda827x_cfg_2) < 0)
1653 goto detach_frontend;
1654 } else { /* satellite */
1655 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1656 &flydvbs, &dev->i2c_adap);
1657 if (fe0->dvb.frontend) {
1658 if (dvb_attach(tda826x_attach,
1659 fe0->dvb.frontend, 0x60,
1660 &dev->i2c_adap, 0) == NULL) {
1661 pr_warn("%s: Asus Tiger 3in1, no "
1662 "tda826x found!\n", __func__);
1663 goto detach_frontend;
1664 }
1665 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1666 &dev->i2c_adap, 0, 0) == NULL) {
1667 pr_warn("%s: Asus Tiger 3in1, no lnbp21"
1668 " found!\n", __func__);
1669 goto detach_frontend;
1670 }
1671 }
1672 }
1673 break;
1674 case SAA7134_BOARD_ASUSTeK_PS3_100:
1675 if (!use_frontend) { /* terrestrial */
1676 if (configure_tda827x_fe(dev, &asus_ps3_100_config,
1677 &tda827x_cfg_2) < 0)
1678 goto detach_frontend;
1679 } else { /* satellite */
1680 fe0->dvb.frontend = dvb_attach(tda10086_attach,
1681 &flydvbs, &dev->i2c_adap);
1682 if (fe0->dvb.frontend) {
1683 if (dvb_attach(tda826x_attach,
1684 fe0->dvb.frontend, 0x60,
1685 &dev->i2c_adap, 0) == NULL) {
1686 pr_warn("%s: Asus My Cinema PS3-100, no "
1687 "tda826x found!\n", __func__);
1688 goto detach_frontend;
1689 }
1690 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1691 &dev->i2c_adap, 0, 0) == NULL) {
1692 pr_warn("%s: Asus My Cinema PS3-100, no lnbp21"
1693 " found!\n", __func__);
1694 goto detach_frontend;
1695 }
1696 }
1697 }
1698 break;
1699 case SAA7134_BOARD_ASUSTeK_TIGER:
1700 if (configure_tda827x_fe(dev, &philips_tiger_config,
1701 &tda827x_cfg_0) < 0)
1702 goto detach_frontend;
1703 break;
1704 case SAA7134_BOARD_BEHOLD_H6:
1705 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1706 &behold_h6_config,
1707 &dev->i2c_adap);
1708 if (fe0->dvb.frontend) {
1709 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1710 &dev->i2c_adap, 0x61,
1711 TUNER_PHILIPS_FMD1216MEX_MK3);
1712 }
1713 break;
1714 case SAA7134_BOARD_BEHOLD_X7:
1715 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1716 &behold_x7_config,
1717 &dev->i2c_adap);
1718 if (fe0->dvb.frontend) {
1719 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1720 &dev->i2c_adap, &behold_x7_tunerconfig);
1721 }
1722 break;
1723 case SAA7134_BOARD_BEHOLD_H7:
1724 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1725 &behold_x7_config,
1726 &dev->i2c_adap);
1727 if (fe0->dvb.frontend) {
1728 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1729 &dev->i2c_adap, &behold_x7_tunerconfig);
1730 }
1731 break;
1732 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
1733 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
1734 /* Zarlink ZL10313 */
1735 fe0->dvb.frontend = dvb_attach(mt312_attach,
1736 &avertv_a700_mt312, &dev->i2c_adap);
1737 if (fe0->dvb.frontend) {
1738 if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
1739 &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
1740 pr_warn("%s: No zl10036 found!\n",
1741 __func__);
1742 }
1743 }
1744 break;
1745 case SAA7134_BOARD_VIDEOMATE_S350:
1746 fe0->dvb.frontend = dvb_attach(mt312_attach,
1747 &zl10313_compro_s350_config, &dev->i2c_adap);
1748 if (fe0->dvb.frontend)
1749 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1750 0x60, &dev->i2c_adap) == NULL)
1751 pr_warn("%s: No zl10039 found!\n",
1752 __func__);
1753
1754 break;
1755 case SAA7134_BOARD_VIDEOMATE_T750:
1756 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1757 &videomate_t750_zl10353_config,
1758 &dev->i2c_adap);
1759 if (fe0->dvb.frontend != NULL) {
1760 if (dvb_attach(qt1010_attach,
1761 fe0->dvb.frontend,
1762 &dev->i2c_adap,
1763 &videomate_t750_qt1010_config) == NULL)
1764 pr_warn("error attaching QT1010\n");
1765 }
1766 break;
1767 case SAA7134_BOARD_ZOLID_HYBRID_PCI:
1768 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1769 &zolid_tda10048_config,
1770 &dev->i2c_adap);
1771 if (fe0->dvb.frontend != NULL) {
1772 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1773 &dev->i2c_adap, 0x4b,
1774 &tda829x_no_probe);
1775 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1776 0x60, &dev->i2c_adap,
1777 &zolid_tda18271_config);
1778 }
1779 break;
1780 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
1781 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1782 &dtv1000s_tda10048_config,
1783 &dev->i2c_adap);
1784 if (fe0->dvb.frontend != NULL) {
1785 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1786 &dev->i2c_adap, 0x4b,
1787 &tda829x_no_probe);
1788 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1789 0x60, &dev->i2c_adap,
1790 &dtv1000s_tda18271_config);
1791 }
1792 break;
1793 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
1794 /* Switch to digital mode */
1795 saa7134_tuner_callback(dev, 0,
1796 TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
1797 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1798 &kworld_mb86a20s_config,
1799 &dev->i2c_adap);
1800 if (fe0->dvb.frontend != NULL) {
1801 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1802 &dev->i2c_adap, 0x4b,
1803 &tda829x_no_probe);
1804 fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_gate_ctrl;
1805 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1806 0x60, &dev->i2c_adap,
1807 &kworld_tda18271_config);
1808 }
1809
1810 /* mb86a20s need to use the I2C gateway */
1811 break;
1812 case SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2:
1813 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1814 &prohdtv_pro2_lgs8g75_config,
1815 &dev->i2c_adap);
1816 if (fe0->dvb.frontend != NULL) {
1817 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1818 &dev->i2c_adap, 0x4b,
1819 &tda829x_no_probe);
1820 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1821 0x60, &dev->i2c_adap,
1822 &prohdtv_pro2_tda18271_config);
1823 }
1824 break;
1825 case SAA7134_BOARD_AVERMEDIA_A706:
1826 /* Enable all DVB-S devices now */
1827 /* CE5039 DVB-S tuner SLEEP pin low */
1828 saa7134_set_gpio(dev, 23, 0);
1829 /* CE6313 DVB-S demod SLEEP pin low */
1830 saa7134_set_gpio(dev, 9, 0);
1831 /* CE6313 DVB-S demod RESET# pin high */
1832 saa7134_set_gpio(dev, 25, 1);
1833 msleep(1);
1834 fe0->dvb.frontend = dvb_attach(mt312_attach,
1835 &zl10313_avermedia_a706_config, &dev->i2c_adap);
1836 if (fe0->dvb.frontend) {
1837 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1838 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1839 0x60, &dev->i2c_adap) == NULL)
1840 pr_warn("%s: No zl10039 found!\n",
1841 __func__);
1842 }
1843 break;
1844 default:
1845 pr_warn("Huh? unknown DVB card?\n");
1846 break;
1847 }
1848
1849 if (attach_xc3028) {
1850 struct dvb_frontend *fe;
1851 struct xc2028_config cfg = {
1852 .i2c_adap = &dev->i2c_adap,
1853 .i2c_addr = 0x61,
1854 };
1855
1856 if (!fe0->dvb.frontend)
1857 goto detach_frontend;
1858
1859 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
1860 if (!fe) {
1861 pr_err("%s/2: xc3028 attach failed\n",
1862 dev->name);
1863 goto detach_frontend;
1864 }
1865 }
1866
1867 if (NULL == fe0->dvb.frontend) {
1868 pr_err("%s/dvb: frontend initialization failed\n", dev->name);
1869 goto detach_frontend;
1870 }
1871 /* define general-purpose callback pointer */
1872 fe0->dvb.frontend->callback = saa7134_tuner_callback;
1873
1874 /* register everything else */
1875 ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
1876 &dev->pci->dev, adapter_nr, 0);
1877
1878 /* this sequence is necessary to make the tda1004x load its firmware
1879 * and to enter analog mode of hybrid boards
1880 */
1881 if (!ret) {
1882 if (fe0->dvb.frontend->ops.init)
1883 fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
1884 if (fe0->dvb.frontend->ops.sleep)
1885 fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
1886 if (fe0->dvb.frontend->ops.tuner_ops.sleep)
1887 fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
1888 }
1889 return ret;
1890
1891 detach_frontend:
1892 vb2_dvb_dealloc_frontends(&dev->frontends);
1893 vb2_queue_release(&fe0->dvb.dvbq);
1894 return -EINVAL;
1895 }
1896
1897 static int dvb_fini(struct saa7134_dev *dev)
1898 {
1899 struct vb2_dvb_frontend *fe0;
1900
1901 /* Get the first frontend */
1902 fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
1903 if (!fe0)
1904 return -EINVAL;
1905
1906 /* FIXME: I suspect that this code is bogus, since the entry for
1907 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1908 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1909 */
1910 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1911 struct v4l2_priv_tun_config tda9887_cfg;
1912 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1913
1914 tda9887_cfg.tuner = TUNER_TDA9887;
1915 tda9887_cfg.priv = &on;
1916
1917 /* otherwise we don't detect the tuner on next insmod */
1918 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1919 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1920 if ((dev->eedata[2] == 0x07) && use_frontend) {
1921 /* turn off the 2nd lnb supply */
1922 u8 data = 0x80;
1923 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1924 struct dvb_frontend *fe;
1925 fe = fe0->dvb.frontend;
1926 if (fe->ops.i2c_gate_ctrl) {
1927 fe->ops.i2c_gate_ctrl(fe, 1);
1928 i2c_transfer(&dev->i2c_adap, &msg, 1);
1929 fe->ops.i2c_gate_ctrl(fe, 0);
1930 }
1931 }
1932 }
1933 vb2_dvb_unregister_bus(&dev->frontends);
1934 vb2_queue_release(&fe0->dvb.dvbq);
1935 return 0;
1936 }
1937
1938 static struct saa7134_mpeg_ops dvb_ops = {
1939 .type = SAA7134_MPEG_DVB,
1940 .init = dvb_init,
1941 .fini = dvb_fini,
1942 };
1943
1944 static int __init dvb_register(void)
1945 {
1946 return saa7134_ts_register(&dvb_ops);
1947 }
1948
1949 static void __exit dvb_unregister(void)
1950 {
1951 saa7134_ts_unregister(&dvb_ops);
1952 }
1953
1954 module_init(dvb_register);
1955 module_exit(dvb_unregister);
This page took 0.069982 seconds and 4 git commands to generate.