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: 562 break; 563 case 1: 564 pr_debug("setting GPIO21 to 0 (TV antenna?)\n"); 565 saa7134_set_gpio(dev, 21, 0); 566 break; 567 case 2: 568 pr_debug("setting GPIO21 to 1 (Radio antenna?)\n"); 569 saa7134_set_gpio(dev, 21, 1); 570 break; 571 } 572 return 0; 573 } 574 575 static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe) 576 { 577 struct saa7134_dev *dev = fe->dvb->priv; 578 struct tda1004x_state *state = fe->demodulator_priv; 579 580 switch (state->config->antenna_switch) { 581 case 0: 582 break; 583 case 1: 584 pr_debug("setting GPIO21 to 1 (Radio antenna?)\n"); 585 saa7134_set_gpio(dev, 21, 1); 586 break; 587 case 2: 588 pr_debug("setting GPIO21 to 0 (TV antenna?)\n"); 589 saa7134_set_gpio(dev, 21, 0); 590 break; 591 } 592 return 0; 593 } 594 595 static int configure_tda827x_fe(struct saa7134_dev *dev, 596 struct tda1004x_config *cdec_conf, 597 struct tda827x_config *tuner_conf) 598 { 599 struct vb2_dvb_frontend *fe0; 600 601 /* Get the first frontend */ 602 fe0 = vb2_dvb_get_frontend(&dev->frontends, 1); 603 604 if (!fe0) 605 return -EINVAL; 606 607 fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap); 608 if (fe0->dvb.frontend) { 609 if (cdec_conf->i2c_gate) 610 fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl; 611 if (dvb_attach(tda827x_attach, fe0->dvb.frontend, 612 cdec_conf->tuner_address, 613 &dev->i2c_adap, tuner_conf)) 614 return 0; 615 616 pr_warn("no tda827x tuner found at addr: %02x\n", 617 cdec_conf->tuner_address); 618 } 619 return -EINVAL; 620 } 621 622 /* ------------------------------------------------------------------ */ 623 624 static struct tda827x_config tda827x_cfg_0 = { 625 .init = philips_tda827x_tuner_init, 626 .sleep = philips_tda827x_tuner_sleep, 627 .config = 0, 628 .switch_addr = 0 629 }; 630 631 static struct tda827x_config tda827x_cfg_1 = { 632 .init = philips_tda827x_tuner_init, 633 .sleep = philips_tda827x_tuner_sleep, 634 .config = 1, 635 .switch_addr = 0x4b 636 }; 637 638 static struct tda827x_config tda827x_cfg_2 = { 639 .init = philips_tda827x_tuner_init, 640 .sleep = philips_tda827x_tuner_sleep, 641 .config = 2, 642 .switch_addr = 0x4b 643 }; 644 645 static struct tda827x_config tda827x_cfg_2_sw42 = { 646 .init = philips_tda827x_tuner_init, 647 .sleep = philips_tda827x_tuner_sleep, 648 .config = 2, 649 .switch_addr = 0x42 650 }; 651 652 /* ------------------------------------------------------------------ */ 653 654 static struct tda1004x_config tda827x_lifeview_config = { 655 .demod_address = 0x08, 656 .invert = 1, 657 .invert_oclk = 0, 658 .xtal_freq = TDA10046_XTAL_16M, 659 .agc_config = TDA10046_AGC_TDA827X, 660 .gpio_config = TDA10046_GP11_I, 661 .if_freq = TDA10046_FREQ_045, 662 .tuner_address = 0x60, 663 .request_firmware = philips_tda1004x_request_firmware 664 }; 665 666 static struct tda1004x_config philips_tiger_config = { 667 .demod_address = 0x08, 668 .invert = 1, 669 .invert_oclk = 0, 670 .xtal_freq = TDA10046_XTAL_16M, 671 .agc_config = TDA10046_AGC_TDA827X, 672 .gpio_config = TDA10046_GP11_I, 673 .if_freq = TDA10046_FREQ_045, 674 .i2c_gate = 0x4b, 675 .tuner_address = 0x61, 676 .antenna_switch= 1, 677 .request_firmware = philips_tda1004x_request_firmware 678 }; 679 680 static struct tda1004x_config cinergy_ht_config = { 681 .demod_address = 0x08, 682 .invert = 1, 683 .invert_oclk = 0, 684 .xtal_freq = TDA10046_XTAL_16M, 685 .agc_config = TDA10046_AGC_TDA827X, 686 .gpio_config = TDA10046_GP01_I, 687 .if_freq = TDA10046_FREQ_045, 688 .i2c_gate = 0x4b, 689 .tuner_address = 0x61, 690 .request_firmware = philips_tda1004x_request_firmware 691 }; 692 693 static struct tda1004x_config cinergy_ht_pci_config = { 694 .demod_address = 0x08, 695 .invert = 1, 696 .invert_oclk = 0, 697 .xtal_freq = TDA10046_XTAL_16M, 698 .agc_config = TDA10046_AGC_TDA827X, 699 .gpio_config = TDA10046_GP01_I, 700 .if_freq = TDA10046_FREQ_045, 701 .i2c_gate = 0x4b, 702 .tuner_address = 0x60, 703 .request_firmware = philips_tda1004x_request_firmware 704 }; 705 706 static struct tda1004x_config philips_tiger_s_config = { 707 .demod_address = 0x08, 708 .invert = 1, 709 .invert_oclk = 0, 710 .xtal_freq = TDA10046_XTAL_16M, 711 .agc_config = TDA10046_AGC_TDA827X, 712 .gpio_config = TDA10046_GP01_I, 713 .if_freq = TDA10046_FREQ_045, 714 .i2c_gate = 0x4b, 715 .tuner_address = 0x61, 716 .antenna_switch= 1, 717 .request_firmware = philips_tda1004x_request_firmware 718 }; 719 720 static struct tda1004x_config pinnacle_pctv_310i_config = { 721 .demod_address = 0x08, 722 .invert = 1, 723 .invert_oclk = 0, 724 .xtal_freq = TDA10046_XTAL_16M, 725 .agc_config = TDA10046_AGC_TDA827X, 726 .gpio_config = TDA10046_GP11_I, 727 .if_freq = TDA10046_FREQ_045, 728 .i2c_gate = 0x4b, 729 .tuner_address = 0x61, 730 .request_firmware = philips_tda1004x_request_firmware 731 }; 732 733 static struct tda1004x_config hauppauge_hvr_1110_config = { 734 .demod_address = 0x08, 735 .invert = 1, 736 .invert_oclk = 0, 737 .xtal_freq = TDA10046_XTAL_16M, 738 .agc_config = TDA10046_AGC_TDA827X, 739 .gpio_config = TDA10046_GP11_I, 740 .if_freq = TDA10046_FREQ_045, 741 .i2c_gate = 0x4b, 742 .tuner_address = 0x61, 743 .request_firmware = philips_tda1004x_request_firmware 744 }; 745 746 static struct tda1004x_config asus_p7131_dual_config = { 747 .demod_address = 0x08, 748 .invert = 1, 749 .invert_oclk = 0, 750 .xtal_freq = TDA10046_XTAL_16M, 751 .agc_config = TDA10046_AGC_TDA827X, 752 .gpio_config = TDA10046_GP11_I, 753 .if_freq = TDA10046_FREQ_045, 754 .i2c_gate = 0x4b, 755 .tuner_address = 0x61, 756 .antenna_switch= 2, 757 .request_firmware = philips_tda1004x_request_firmware 758 }; 759 760 static struct tda1004x_config lifeview_trio_config = { 761 .demod_address = 0x09, 762 .invert = 1, 763 .invert_oclk = 0, 764 .xtal_freq = TDA10046_XTAL_16M, 765 .agc_config = TDA10046_AGC_TDA827X, 766 .gpio_config = TDA10046_GP00_I, 767 .if_freq = TDA10046_FREQ_045, 768 .tuner_address = 0x60, 769 .request_firmware = philips_tda1004x_request_firmware 770 }; 771 772 static struct tda1004x_config tevion_dvbt220rf_config = { 773 .demod_address = 0x08, 774 .invert = 1, 775 .invert_oclk = 0, 776 .xtal_freq = TDA10046_XTAL_16M, 777 .agc_config = TDA10046_AGC_TDA827X, 778 .gpio_config = TDA10046_GP11_I, 779 .if_freq = TDA10046_FREQ_045, 780 .tuner_address = 0x60, 781 .request_firmware = philips_tda1004x_request_firmware 782 }; 783 784 static struct tda1004x_config md8800_dvbt_config = { 785 .demod_address = 0x08, 786 .invert = 1, 787 .invert_oclk = 0, 788 .xtal_freq = TDA10046_XTAL_16M, 789 .agc_config = TDA10046_AGC_TDA827X, 790 .gpio_config = TDA10046_GP01_I, 791 .if_freq = TDA10046_FREQ_045, 792 .i2c_gate = 0x4b, 793 .tuner_address = 0x60, 794 .request_firmware = philips_tda1004x_request_firmware 795 }; 796 797 static struct tda1004x_config asus_p7131_4871_config = { 798 .demod_address = 0x08, 799 .invert = 1, 800 .invert_oclk = 0, 801 .xtal_freq = TDA10046_XTAL_16M, 802 .agc_config = TDA10046_AGC_TDA827X, 803 .gpio_config = TDA10046_GP01_I, 804 .if_freq = TDA10046_FREQ_045, 805 .i2c_gate = 0x4b, 806 .tuner_address = 0x61, 807 .antenna_switch= 2, 808 .request_firmware = philips_tda1004x_request_firmware 809 }; 810 811 static struct tda1004x_config asus_p7131_hybrid_lna_config = { 812 .demod_address = 0x08, 813 .invert = 1, 814 .invert_oclk = 0, 815 .xtal_freq = TDA10046_XTAL_16M, 816 .agc_config = TDA10046_AGC_TDA827X, 817 .gpio_config = TDA10046_GP11_I, 818 .if_freq = TDA10046_FREQ_045, 819 .i2c_gate = 0x4b, 820 .tuner_address = 0x61, 821 .antenna_switch= 2, 822 .request_firmware = philips_tda1004x_request_firmware 823 }; 824 825 static struct tda1004x_config kworld_dvb_t_210_config = { 826 .demod_address = 0x08, 827 .invert = 1, 828 .invert_oclk = 0, 829 .xtal_freq = TDA10046_XTAL_16M, 830 .agc_config = TDA10046_AGC_TDA827X, 831 .gpio_config = TDA10046_GP11_I, 832 .if_freq = TDA10046_FREQ_045, 833 .i2c_gate = 0x4b, 834 .tuner_address = 0x61, 835 .antenna_switch= 1, 836 .request_firmware = philips_tda1004x_request_firmware 837 }; 838 839 static struct tda1004x_config avermedia_super_007_config = { 840 .demod_address = 0x08, 841 .invert = 1, 842 .invert_oclk = 0, 843 .xtal_freq = TDA10046_XTAL_16M, 844 .agc_config = TDA10046_AGC_TDA827X, 845 .gpio_config = TDA10046_GP01_I, 846 .if_freq = TDA10046_FREQ_045, 847 .i2c_gate = 0x4b, 848 .tuner_address = 0x60, 849 .antenna_switch= 1, 850 .request_firmware = philips_tda1004x_request_firmware 851 }; 852 853 static struct tda1004x_config twinhan_dtv_dvb_3056_config = { 854 .demod_address = 0x08, 855 .invert = 1, 856 .invert_oclk = 0, 857 .xtal_freq = TDA10046_XTAL_16M, 858 .agc_config = TDA10046_AGC_TDA827X, 859 .gpio_config = TDA10046_GP01_I, 860 .if_freq = TDA10046_FREQ_045, 861 .i2c_gate = 0x42, 862 .tuner_address = 0x61, 863 .antenna_switch = 1, 864 .request_firmware = philips_tda1004x_request_firmware 865 }; 866 867 static struct tda1004x_config asus_tiger_3in1_config = { 868 .demod_address = 0x0b, 869 .invert = 1, 870 .invert_oclk = 0, 871 .xtal_freq = TDA10046_XTAL_16M, 872 .agc_config = TDA10046_AGC_TDA827X, 873 .gpio_config = TDA10046_GP11_I, 874 .if_freq = TDA10046_FREQ_045, 875 .i2c_gate = 0x4b, 876 .tuner_address = 0x61, 877 .antenna_switch = 1, 878 .request_firmware = philips_tda1004x_request_firmware 879 }; 880 881 static struct tda1004x_config asus_ps3_100_config = { 882 .demod_address = 0x0b, 883 .invert = 1, 884 .invert_oclk = 0, 885 .xtal_freq = TDA10046_XTAL_16M, 886 .agc_config = TDA10046_AGC_TDA827X, 887 .gpio_config = TDA10046_GP11_I, 888 .if_freq = TDA10046_FREQ_045, 889 .i2c_gate = 0x4b, 890 .tuner_address = 0x61, 891 .antenna_switch = 1, 892 .request_firmware = philips_tda1004x_request_firmware 893 }; 894 895 /* ------------------------------------------------------------------ 896 * special case: this card uses saa713x GPIO22 for the mode switch 897 */ 898 899 static int ads_duo_tuner_init(struct dvb_frontend *fe) 900 { 901 struct saa7134_dev *dev = fe->dvb->priv; 902 philips_tda827x_tuner_init(fe); 903 /* route TDA8275a AGC input to the channel decoder */ 904 saa7134_set_gpio(dev, 22, 1); 905 return 0; 906 } 907 908 static int ads_duo_tuner_sleep(struct dvb_frontend *fe) 909 { 910 struct saa7134_dev *dev = fe->dvb->priv; 911 /* route TDA8275a AGC input to the analog IF chip*/ 912 saa7134_set_gpio(dev, 22, 0); 913 philips_tda827x_tuner_sleep(fe); 914 return 0; 915 } 916 917 static struct tda827x_config ads_duo_cfg = { 918 .init = ads_duo_tuner_init, 919 .sleep = ads_duo_tuner_sleep, 920 .config = 0 921 }; 922 923 static struct tda1004x_config ads_tech_duo_config = { 924 .demod_address = 0x08, 925 .invert = 1, 926 .invert_oclk = 0, 927 .xtal_freq = TDA10046_XTAL_16M, 928 .agc_config = TDA10046_AGC_TDA827X, 929 .gpio_config = TDA10046_GP00_I, 930 .if_freq = TDA10046_FREQ_045, 931 .tuner_address = 0x61, 932 .request_firmware = philips_tda1004x_request_firmware 933 }; 934 935 static struct zl10353_config behold_h6_config = { 936 .demod_address = 0x1e>>1, 937 .no_tuner = 1, 938 .parallel_ts = 1, 939 .disable_i2c_gate_ctrl = 1, 940 }; 941 942 static struct xc5000_config behold_x7_tunerconfig = { 943 .i2c_address = 0xc2>>1, 944 .if_khz = 4560, 945 .radio_input = XC5000_RADIO_FM1, 946 }; 947 948 static struct zl10353_config behold_x7_config = { 949 .demod_address = 0x1e>>1, 950 .if2 = 45600, 951 .no_tuner = 1, 952 .parallel_ts = 1, 953 .disable_i2c_gate_ctrl = 1, 954 }; 955 956 static struct zl10353_config videomate_t750_zl10353_config = { 957 .demod_address = 0x0f, 958 .no_tuner = 1, 959 .parallel_ts = 1, 960 .disable_i2c_gate_ctrl = 1, 961 }; 962 963 static struct qt1010_config videomate_t750_qt1010_config = { 964 .i2c_address = 0x62 965 }; 966 967 968 /* ================================================================== 969 * tda10086 based DVB-S cards, helper functions 970 */ 971 972 static struct tda10086_config flydvbs = { 973 .demod_address = 0x0e, 974 .invert = 0, 975 .diseqc_tone = 0, 976 .xtal_freq = TDA10086_XTAL_16M, 977 }; 978 979 static struct tda10086_config sd1878_4m = { 980 .demod_address = 0x0e, 981 .invert = 0, 982 .diseqc_tone = 0, 983 .xtal_freq = TDA10086_XTAL_4M, 984 }; 985 986 /* ------------------------------------------------------------------ 987 * special case: lnb supply is connected to the gated i2c 988 */ 989 990 static int md8800_set_voltage(struct dvb_frontend *fe, 991 enum fe_sec_voltage voltage) 992 { 993 int res = -EIO; 994 struct saa7134_dev *dev = fe->dvb->priv; 995 if (fe->ops.i2c_gate_ctrl) { 996 fe->ops.i2c_gate_ctrl(fe, 1); 997 if (dev->original_set_voltage) 998 res = dev->original_set_voltage(fe, voltage); 999 fe->ops.i2c_gate_ctrl(fe, 0); 1000 } 1001 return res; 1002 }; 1003 1004 static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg) 1005 { 1006 int res = -EIO; 1007 struct saa7134_dev *dev = fe->dvb->priv; 1008 if (fe->ops.i2c_gate_ctrl) { 1009 fe->ops.i2c_gate_ctrl(fe, 1); 1010 if (dev->original_set_high_voltage) 1011 res = dev->original_set_high_voltage(fe, arg); 1012 fe->ops.i2c_gate_ctrl(fe, 0); 1013 } 1014 return res; 1015 }; 1016 1017 static int md8800_set_voltage2(struct dvb_frontend *fe, 1018 enum fe_sec_voltage voltage) 1019 { 1020 struct saa7134_dev *dev = fe->dvb->priv; 1021 u8 wbuf[2] = { 0x1f, 00 }; 1022 u8 rbuf; 1023 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 }, 1024 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } }; 1025 1026 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2) 1027 return -EIO; 1028 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */ 1029 if (voltage == SEC_VOLTAGE_18) 1030 wbuf[1] = rbuf | 0x10; 1031 else 1032 wbuf[1] = rbuf & 0xef; 1033 msg[0].len = 2; 1034 i2c_transfer(&dev->i2c_adap, msg, 1); 1035 return 0; 1036 } 1037 1038 static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg) 1039 { 1040 pr_warn("%s: sorry can't set high LNB supply voltage from here\n", 1041 __func__); 1042 return -EIO; 1043 } 1044 1045 /* ================================================================== 1046 * nxt200x based ATSC cards, helper functions 1047 */ 1048 1049 static struct nxt200x_config avertvhda180 = { 1050 .demod_address = 0x0a, 1051 }; 1052 1053 static struct nxt200x_config kworldatsc110 = { 1054 .demod_address = 0x0a, 1055 }; 1056 1057 /* ------------------------------------------------------------------ */ 1058 1059 static struct mt312_config avertv_a700_mt312 = { 1060 .demod_address = 0x0e, 1061 .voltage_inverted = 1, 1062 }; 1063 1064 static struct zl10036_config avertv_a700_tuner = { 1065 .tuner_address = 0x60, 1066 }; 1067 1068 static struct mt312_config zl10313_compro_s350_config = { 1069 .demod_address = 0x0e, 1070 }; 1071 1072 static struct mt312_config zl10313_avermedia_a706_config = { 1073 .demod_address = 0x0e, 1074 }; 1075 1076 static struct lgdt3305_config hcw_lgdt3305_config = { 1077 .i2c_addr = 0x0e, 1078 .mpeg_mode = LGDT3305_MPEG_SERIAL, 1079 .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE, 1080 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, 1081 .deny_i2c_rptr = 1, 1082 .spectral_inversion = 1, 1083 .qam_if_khz = 4000, 1084 .vsb_if_khz = 3250, 1085 }; 1086 1087 static struct tda10048_config hcw_tda10048_config = { 1088 .demod_address = 0x10 >> 1, 1089 .output_mode = TDA10048_SERIAL_OUTPUT, 1090 .fwbulkwritelen = TDA10048_BULKWRITE_200, 1091 .inversion = TDA10048_INVERSION_ON, 1092 .dtv6_if_freq_khz = TDA10048_IF_3300, 1093 .dtv7_if_freq_khz = TDA10048_IF_3500, 1094 .dtv8_if_freq_khz = TDA10048_IF_4000, 1095 .clk_freq_khz = TDA10048_CLK_16000, 1096 .disable_gate_access = 1, 1097 }; 1098 1099 static struct tda18271_std_map hauppauge_tda18271_std_map = { 1100 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4, 1101 .if_lvl = 1, .rfagc_top = 0x58, }, 1102 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5, 1103 .if_lvl = 1, .rfagc_top = 0x58, }, 1104 }; 1105 1106 static struct tda18271_config hcw_tda18271_config = { 1107 .std_map = &hauppauge_tda18271_std_map, 1108 .gate = TDA18271_GATE_ANALOG, 1109 .config = 3, 1110 .output_opt = TDA18271_OUTPUT_LT_OFF, 1111 }; 1112 1113 static struct tda829x_config tda829x_no_probe = { 1114 .probe_tuner = TDA829X_DONT_PROBE, 1115 }; 1116 1117 static struct tda10048_config zolid_tda10048_config = { 1118 .demod_address = 0x10 >> 1, 1119 .output_mode = TDA10048_PARALLEL_OUTPUT, 1120 .fwbulkwritelen = TDA10048_BULKWRITE_200, 1121 .inversion = TDA10048_INVERSION_ON, 1122 .dtv6_if_freq_khz = TDA10048_IF_3300, 1123 .dtv7_if_freq_khz = TDA10048_IF_3500, 1124 .dtv8_if_freq_khz = TDA10048_IF_4000, 1125 .clk_freq_khz = TDA10048_CLK_16000, 1126 .disable_gate_access = 1, 1127 }; 1128 1129 static struct tda18271_config zolid_tda18271_config = { 1130 .gate = TDA18271_GATE_ANALOG, 1131 }; 1132 1133 static struct tda10048_config dtv1000s_tda10048_config = { 1134 .demod_address = 0x10 >> 1, 1135 .output_mode = TDA10048_PARALLEL_OUTPUT, 1136 .fwbulkwritelen = TDA10048_BULKWRITE_200, 1137 .inversion = TDA10048_INVERSION_ON, 1138 .dtv6_if_freq_khz = TDA10048_IF_3300, 1139 .dtv7_if_freq_khz = TDA10048_IF_3800, 1140 .dtv8_if_freq_khz = TDA10048_IF_4300, 1141 .clk_freq_khz = TDA10048_CLK_16000, 1142 .disable_gate_access = 1, 1143 }; 1144 1145 static struct tda18271_std_map dtv1000s_tda18271_std_map = { 1146 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4, 1147 .if_lvl = 1, .rfagc_top = 0x37, }, 1148 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5, 1149 .if_lvl = 1, .rfagc_top = 0x37, }, 1150 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6, 1151 .if_lvl = 1, .rfagc_top = 0x37, }, 1152 }; 1153 1154 static struct tda18271_config dtv1000s_tda18271_config = { 1155 .std_map = &dtv1000s_tda18271_std_map, 1156 .gate = TDA18271_GATE_ANALOG, 1157 }; 1158 1159 static struct lgs8gxx_config prohdtv_pro2_lgs8g75_config = { 1160 .prod = LGS8GXX_PROD_LGS8G75, 1161 .demod_address = 0x1d, 1162 .serial_ts = 0, 1163 .ts_clk_pol = 1, 1164 .ts_clk_gated = 0, 1165 .if_clk_freq = 30400, /* 30.4 MHz */ 1166 .if_freq = 4000, /* 4.00 MHz */ 1167 .if_neg_center = 0, 1168 .ext_adc = 0, 1169 .adc_signed = 1, 1170 .adc_vpp = 3, /* 2.0 Vpp */ 1171 .if_neg_edge = 1, 1172 }; 1173 1174 static struct tda18271_config prohdtv_pro2_tda18271_config = { 1175 .gate = TDA18271_GATE_ANALOG, 1176 .output_opt = TDA18271_OUTPUT_LT_OFF, 1177 }; 1178 1179 static struct tda18271_std_map kworld_tda18271_std_map = { 1180 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 3, 1181 .if_lvl = 6, .rfagc_top = 0x37 }, 1182 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0, 1183 .if_lvl = 6, .rfagc_top = 0x37 }, 1184 }; 1185 1186 static struct tda18271_config kworld_pc150u_tda18271_config = { 1187 .std_map = &kworld_tda18271_std_map, 1188 .gate = TDA18271_GATE_ANALOG, 1189 .output_opt = TDA18271_OUTPUT_LT_OFF, 1190 .config = 3, /* Use tuner callback for AGC */ 1191 .rf_cal_on_startup = 1 1192 }; 1193 1194 static struct s5h1411_config kworld_s5h1411_config = { 1195 .output_mode = S5H1411_PARALLEL_OUTPUT, 1196 .gpio = S5H1411_GPIO_OFF, 1197 .qam_if = S5H1411_IF_4000, 1198 .vsb_if = S5H1411_IF_3250, 1199 .inversion = S5H1411_INVERSION_ON, 1200 .status_mode = S5H1411_DEMODLOCKING, 1201 .mpeg_timing = 1202 S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 1203 }; 1204 1205 1206 /* ================================================================== 1207 * Core code 1208 */ 1209 1210 static int dvb_init(struct saa7134_dev *dev) 1211 { 1212 int ret; 1213 int attach_xc3028 = 0; 1214 struct vb2_dvb_frontend *fe0; 1215 struct vb2_queue *q; 1216 1217 /* FIXME: add support for multi-frontend */ 1218 mutex_init(&dev->frontends.lock); 1219 INIT_LIST_HEAD(&dev->frontends.felist); 1220 1221 pr_info("%s() allocating 1 frontend\n", __func__); 1222 fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1); 1223 if (!fe0) { 1224 pr_err("%s() failed to alloc\n", __func__); 1225 return -ENOMEM; 1226 } 1227 1228 /* init struct vb2_dvb */ 1229 dev->ts.nr_bufs = 32; 1230 dev->ts.nr_packets = 32*4; 1231 fe0->dvb.name = dev->name; 1232 q = &fe0->dvb.dvbq; 1233 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1234 q->io_modes = VB2_MMAP | VB2_READ; 1235 q->drv_priv = &dev->ts_q; 1236 q->ops = &saa7134_ts_qops; 1237 q->mem_ops = &vb2_dma_sg_memops; 1238 q->buf_struct_size = sizeof(struct saa7134_buf); 1239 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1240 q->lock = &dev->lock; 1241 q->dev = &dev->pci->dev; 1242 ret = vb2_queue_init(q); 1243 if (ret) { 1244 vb2_dvb_dealloc_frontends(&dev->frontends); 1245 return ret; 1246 } 1247 1248 switch (dev->board) { 1249 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 1250 pr_debug("pinnacle 300i dvb setup\n"); 1251 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i, 1252 &dev->i2c_adap); 1253 if (fe0->dvb.frontend) { 1254 fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params; 1255 } 1256 break; 1257 case SAA7134_BOARD_AVERMEDIA_777: 1258 case SAA7134_BOARD_AVERMEDIA_A16AR: 1259 pr_debug("avertv 777 dvb setup\n"); 1260 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777, 1261 &dev->i2c_adap); 1262 if (fe0->dvb.frontend) { 1263 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1264 &dev->i2c_adap, 0x61, 1265 TUNER_PHILIPS_TD1316); 1266 } 1267 break; 1268 case SAA7134_BOARD_AVERMEDIA_A16D: 1269 pr_debug("AverMedia A16D dvb setup\n"); 1270 fe0->dvb.frontend = dvb_attach(mt352_attach, 1271 &avermedia_xc3028_mt352_dev, 1272 &dev->i2c_adap); 1273 attach_xc3028 = 1; 1274 break; 1275 case SAA7134_BOARD_MD7134: 1276 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1277 &medion_cardbus, 1278 &dev->i2c_adap); 1279 if (fe0->dvb.frontend) { 1280 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1281 &dev->i2c_adap, medion_cardbus.tuner_address, 1282 TUNER_PHILIPS_FMD1216ME_MK3); 1283 } 1284 break; 1285 case SAA7134_BOARD_PHILIPS_TOUGH: 1286 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1287 &philips_tu1216_60_config, 1288 &dev->i2c_adap); 1289 if (fe0->dvb.frontend) { 1290 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init; 1291 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set; 1292 } 1293 break; 1294 case SAA7134_BOARD_FLYDVBTDUO: 1295 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS: 1296 if (configure_tda827x_fe(dev, &tda827x_lifeview_config, 1297 &tda827x_cfg_0) < 0) 1298 goto detach_frontend; 1299 break; 1300 case SAA7134_BOARD_PHILIPS_EUROPA: 1301 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 1302 case SAA7134_BOARD_ASUS_EUROPA_HYBRID: 1303 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1304 &philips_europa_config, 1305 &dev->i2c_adap); 1306 if (fe0->dvb.frontend) { 1307 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep; 1308 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep; 1309 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init; 1310 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep; 1311 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params; 1312 } 1313 break; 1314 case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000: 1315 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1316 &technotrend_budget_t3000_config, 1317 &dev->i2c_adap); 1318 if (fe0->dvb.frontend) { 1319 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep; 1320 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep; 1321 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init; 1322 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep; 1323 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params; 1324 } 1325 break; 1326 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 1327 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1328 &philips_tu1216_61_config, 1329 &dev->i2c_adap); 1330 if (fe0->dvb.frontend) { 1331 fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init; 1332 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set; 1333 } 1334 break; 1335 case SAA7134_BOARD_KWORLD_DVBT_210: 1336 if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config, 1337 &tda827x_cfg_2) < 0) 1338 goto detach_frontend; 1339 break; 1340 case SAA7134_BOARD_HAUPPAUGE_HVR1120: 1341 fe0->dvb.frontend = dvb_attach(tda10048_attach, 1342 &hcw_tda10048_config, 1343 &dev->i2c_adap); 1344 if (fe0->dvb.frontend != NULL) { 1345 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1346 &dev->i2c_adap, 0x4b, 1347 &tda829x_no_probe); 1348 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1349 0x60, &dev->i2c_adap, 1350 &hcw_tda18271_config); 1351 } 1352 break; 1353 case SAA7134_BOARD_PHILIPS_TIGER: 1354 if (configure_tda827x_fe(dev, &philips_tiger_config, 1355 &tda827x_cfg_0) < 0) 1356 goto detach_frontend; 1357 break; 1358 case SAA7134_BOARD_PINNACLE_PCTV_310i: 1359 if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config, 1360 &tda827x_cfg_1) < 0) 1361 goto detach_frontend; 1362 break; 1363 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 1364 if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config, 1365 &tda827x_cfg_1) < 0) 1366 goto detach_frontend; 1367 break; 1368 case SAA7134_BOARD_HAUPPAUGE_HVR1150: 1369 fe0->dvb.frontend = dvb_attach(lgdt3305_attach, 1370 &hcw_lgdt3305_config, 1371 &dev->i2c_adap); 1372 if (fe0->dvb.frontend) { 1373 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1374 &dev->i2c_adap, 0x4b, 1375 &tda829x_no_probe); 1376 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1377 0x60, &dev->i2c_adap, 1378 &hcw_tda18271_config); 1379 } 1380 break; 1381 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 1382 if (configure_tda827x_fe(dev, &asus_p7131_dual_config, 1383 &tda827x_cfg_0) < 0) 1384 goto detach_frontend; 1385 break; 1386 case SAA7134_BOARD_FLYDVBT_LR301: 1387 if (configure_tda827x_fe(dev, &tda827x_lifeview_config, 1388 &tda827x_cfg_0) < 0) 1389 goto detach_frontend; 1390 break; 1391 case SAA7134_BOARD_FLYDVB_TRIO: 1392 if (!use_frontend) { /* terrestrial */ 1393 if (configure_tda827x_fe(dev, &lifeview_trio_config, 1394 &tda827x_cfg_0) < 0) 1395 goto detach_frontend; 1396 } else { /* satellite */ 1397 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap); 1398 if (fe0->dvb.frontend) { 1399 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63, 1400 &dev->i2c_adap, 0) == NULL) { 1401 pr_warn("%s: Lifeview Trio, No tda826x found!\n", 1402 __func__); 1403 goto detach_frontend; 1404 } 1405 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, 1406 &dev->i2c_adap, 1407 0x08, 0, 0, false) == NULL) { 1408 pr_warn("%s: Lifeview Trio, No ISL6421 found!\n", 1409 __func__); 1410 goto detach_frontend; 1411 } 1412 } 1413 } 1414 break; 1415 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331: 1416 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS: 1417 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1418 &ads_tech_duo_config, 1419 &dev->i2c_adap); 1420 if (fe0->dvb.frontend) { 1421 if (dvb_attach(tda827x_attach,fe0->dvb.frontend, 1422 ads_tech_duo_config.tuner_address, &dev->i2c_adap, 1423 &ads_duo_cfg) == NULL) { 1424 pr_warn("no tda827x tuner found at addr: %02x\n", 1425 ads_tech_duo_config.tuner_address); 1426 goto detach_frontend; 1427 } 1428 } else 1429 pr_warn("failed to attach tda10046\n"); 1430 break; 1431 case SAA7134_BOARD_TEVION_DVBT_220RF: 1432 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config, 1433 &tda827x_cfg_0) < 0) 1434 goto detach_frontend; 1435 break; 1436 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 1437 if (!use_frontend) { /* terrestrial */ 1438 if (configure_tda827x_fe(dev, &md8800_dvbt_config, 1439 &tda827x_cfg_0) < 0) 1440 goto detach_frontend; 1441 } else { /* satellite */ 1442 fe0->dvb.frontend = dvb_attach(tda10086_attach, 1443 &flydvbs, &dev->i2c_adap); 1444 if (fe0->dvb.frontend) { 1445 struct dvb_frontend *fe = fe0->dvb.frontend; 1446 u8 dev_id = dev->eedata[2]; 1447 u8 data = 0xc4; 1448 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1}; 1449 1450 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 1451 0x60, &dev->i2c_adap, 0) == NULL) { 1452 pr_warn("%s: Medion Quadro, no tda826x found !\n", 1453 __func__); 1454 goto detach_frontend; 1455 } 1456 if (dev_id != 0x08) { 1457 /* we need to open the i2c gate (we know it exists) */ 1458 fe->ops.i2c_gate_ctrl(fe, 1); 1459 if (dvb_attach(isl6405_attach, fe, 1460 &dev->i2c_adap, 0x08, 0, 0) == NULL) { 1461 pr_warn("%s: Medion Quadro, no ISL6405 found !\n", 1462 __func__); 1463 goto detach_frontend; 1464 } 1465 if (dev_id == 0x07) { 1466 /* fire up the 2nd section of the LNB supply since 1467 we can't do this from the other section */ 1468 msg.buf = &data; 1469 i2c_transfer(&dev->i2c_adap, &msg, 1); 1470 } 1471 fe->ops.i2c_gate_ctrl(fe, 0); 1472 dev->original_set_voltage = fe->ops.set_voltage; 1473 fe->ops.set_voltage = md8800_set_voltage; 1474 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage; 1475 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage; 1476 } else { 1477 fe->ops.set_voltage = md8800_set_voltage2; 1478 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2; 1479 } 1480 } 1481 } 1482 break; 1483 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180: 1484 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180, 1485 &dev->i2c_adap); 1486 if (fe0->dvb.frontend) 1487 dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61, 1488 NULL, DVB_PLL_TDHU2); 1489 break; 1490 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI: 1491 case SAA7134_BOARD_KWORLD_ATSC110: 1492 fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110, 1493 &dev->i2c_adap); 1494 if (fe0->dvb.frontend) 1495 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1496 &dev->i2c_adap, 0x61, 1497 TUNER_PHILIPS_TUV1236D); 1498 break; 1499 case SAA7134_BOARD_KWORLD_PC150U: 1500 saa7134_set_gpio(dev, 18, 1); /* Switch to digital mode */ 1501 saa7134_tuner_callback(dev, 0, 1502 TDA18271_CALLBACK_CMD_AGC_ENABLE, 1); 1503 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 1504 &kworld_s5h1411_config, 1505 &dev->i2c_adap); 1506 if (fe0->dvb.frontend != NULL) { 1507 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1508 &dev->i2c_adap, 0x4b, 1509 &tda829x_no_probe); 1510 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1511 0x60, &dev->i2c_adap, 1512 &kworld_pc150u_tda18271_config); 1513 } 1514 break; 1515 case SAA7134_BOARD_FLYDVBS_LR300: 1516 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, 1517 &dev->i2c_adap); 1518 if (fe0->dvb.frontend) { 1519 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60, 1520 &dev->i2c_adap, 0) == NULL) { 1521 pr_warn("%s: No tda826x found!\n", __func__); 1522 goto detach_frontend; 1523 } 1524 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, 1525 &dev->i2c_adap, 1526 0x08, 0, 0, false) == NULL) { 1527 pr_warn("%s: No ISL6421 found!\n", __func__); 1528 goto detach_frontend; 1529 } 1530 } 1531 break; 1532 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID: 1533 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1534 &medion_cardbus, 1535 &dev->i2c_adap); 1536 if (fe0->dvb.frontend) { 1537 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep; 1538 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep; 1539 1540 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1541 &dev->i2c_adap, medion_cardbus.tuner_address, 1542 TUNER_PHILIPS_FMD1216ME_MK3); 1543 } 1544 break; 1545 case SAA7134_BOARD_VIDEOMATE_DVBT_200A: 1546 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1547 &philips_europa_config, 1548 &dev->i2c_adap); 1549 if (fe0->dvb.frontend) { 1550 fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init; 1551 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params; 1552 } 1553 break; 1554 case SAA7134_BOARD_CINERGY_HT_PCMCIA: 1555 if (configure_tda827x_fe(dev, &cinergy_ht_config, 1556 &tda827x_cfg_0) < 0) 1557 goto detach_frontend; 1558 break; 1559 case SAA7134_BOARD_CINERGY_HT_PCI: 1560 if (configure_tda827x_fe(dev, &cinergy_ht_pci_config, 1561 &tda827x_cfg_0) < 0) 1562 goto detach_frontend; 1563 break; 1564 case SAA7134_BOARD_PHILIPS_TIGER_S: 1565 if (configure_tda827x_fe(dev, &philips_tiger_s_config, 1566 &tda827x_cfg_2) < 0) 1567 goto detach_frontend; 1568 break; 1569 case SAA7134_BOARD_ASUS_P7131_4871: 1570 if (configure_tda827x_fe(dev, &asus_p7131_4871_config, 1571 &tda827x_cfg_2) < 0) 1572 goto detach_frontend; 1573 break; 1574 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 1575 if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config, 1576 &tda827x_cfg_2) < 0) 1577 goto detach_frontend; 1578 break; 1579 case SAA7134_BOARD_AVERMEDIA_SUPER_007: 1580 if (configure_tda827x_fe(dev, &avermedia_super_007_config, 1581 &tda827x_cfg_0) < 0) 1582 goto detach_frontend; 1583 break; 1584 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056: 1585 if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config, 1586 &tda827x_cfg_2_sw42) < 0) 1587 goto detach_frontend; 1588 break; 1589 case SAA7134_BOARD_PHILIPS_SNAKE: 1590 fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, 1591 &dev->i2c_adap); 1592 if (fe0->dvb.frontend) { 1593 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60, 1594 &dev->i2c_adap, 0) == NULL) { 1595 pr_warn("%s: No tda826x found!\n", __func__); 1596 goto detach_frontend; 1597 } 1598 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend, 1599 &dev->i2c_adap, 0, 0) == NULL) { 1600 pr_warn("%s: No lnbp21 found!\n", __func__); 1601 goto detach_frontend; 1602 } 1603 } 1604 break; 1605 case SAA7134_BOARD_CREATIX_CTX953: 1606 if (configure_tda827x_fe(dev, &md8800_dvbt_config, 1607 &tda827x_cfg_0) < 0) 1608 goto detach_frontend; 1609 break; 1610 case SAA7134_BOARD_MSI_TVANYWHERE_AD11: 1611 if (configure_tda827x_fe(dev, &philips_tiger_s_config, 1612 &tda827x_cfg_2) < 0) 1613 goto detach_frontend; 1614 break; 1615 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: 1616 pr_debug("AverMedia E506R dvb setup\n"); 1617 saa7134_set_gpio(dev, 25, 0); 1618 msleep(10); 1619 saa7134_set_gpio(dev, 25, 1); 1620 fe0->dvb.frontend = dvb_attach(mt352_attach, 1621 &avermedia_xc3028_mt352_dev, 1622 &dev->i2c_adap); 1623 attach_xc3028 = 1; 1624 break; 1625 case SAA7134_BOARD_MD7134_BRIDGE_2: 1626 fe0->dvb.frontend = dvb_attach(tda10086_attach, 1627 &sd1878_4m, &dev->i2c_adap); 1628 if (fe0->dvb.frontend) { 1629 struct dvb_frontend *fe; 1630 if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60, 1631 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) { 1632 pr_warn("%s: MD7134 DVB-S, no SD1878 found !\n", 1633 __func__); 1634 goto detach_frontend; 1635 } 1636 /* we need to open the i2c gate (we know it exists) */ 1637 fe = fe0->dvb.frontend; 1638 fe->ops.i2c_gate_ctrl(fe, 1); 1639 if (dvb_attach(isl6405_attach, fe, 1640 &dev->i2c_adap, 0x08, 0, 0) == NULL) { 1641 pr_warn("%s: MD7134 DVB-S, no ISL6405 found !\n", 1642 __func__); 1643 goto detach_frontend; 1644 } 1645 fe->ops.i2c_gate_ctrl(fe, 0); 1646 dev->original_set_voltage = fe->ops.set_voltage; 1647 fe->ops.set_voltage = md8800_set_voltage; 1648 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage; 1649 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage; 1650 } 1651 break; 1652 case SAA7134_BOARD_AVERMEDIA_M103: 1653 saa7134_set_gpio(dev, 25, 0); 1654 msleep(10); 1655 saa7134_set_gpio(dev, 25, 1); 1656 fe0->dvb.frontend = dvb_attach(mt352_attach, 1657 &avermedia_xc3028_mt352_dev, 1658 &dev->i2c_adap); 1659 attach_xc3028 = 1; 1660 break; 1661 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1: 1662 if (!use_frontend) { /* terrestrial */ 1663 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config, 1664 &tda827x_cfg_2) < 0) 1665 goto detach_frontend; 1666 } else { /* satellite */ 1667 fe0->dvb.frontend = dvb_attach(tda10086_attach, 1668 &flydvbs, &dev->i2c_adap); 1669 if (fe0->dvb.frontend) { 1670 if (dvb_attach(tda826x_attach, 1671 fe0->dvb.frontend, 0x60, 1672 &dev->i2c_adap, 0) == NULL) { 1673 pr_warn("%s: Asus Tiger 3in1, no tda826x found!\n", 1674 __func__); 1675 goto detach_frontend; 1676 } 1677 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend, 1678 &dev->i2c_adap, 0, 0) == NULL) { 1679 pr_warn("%s: Asus Tiger 3in1, no lnbp21 found!\n", 1680 __func__); 1681 goto detach_frontend; 1682 } 1683 } 1684 } 1685 break; 1686 case SAA7134_BOARD_ASUSTeK_PS3_100: 1687 if (!use_frontend) { /* terrestrial */ 1688 if (configure_tda827x_fe(dev, &asus_ps3_100_config, 1689 &tda827x_cfg_2) < 0) 1690 goto detach_frontend; 1691 } else { /* satellite */ 1692 fe0->dvb.frontend = dvb_attach(tda10086_attach, 1693 &flydvbs, &dev->i2c_adap); 1694 if (fe0->dvb.frontend) { 1695 if (dvb_attach(tda826x_attach, 1696 fe0->dvb.frontend, 0x60, 1697 &dev->i2c_adap, 0) == NULL) { 1698 pr_warn("%s: Asus My Cinema PS3-100, no tda826x found!\n", 1699 __func__); 1700 goto detach_frontend; 1701 } 1702 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend, 1703 &dev->i2c_adap, 0, 0) == NULL) { 1704 pr_warn("%s: Asus My Cinema PS3-100, no lnbp21 found!\n", 1705 __func__); 1706 goto detach_frontend; 1707 } 1708 } 1709 } 1710 break; 1711 case SAA7134_BOARD_ASUSTeK_TIGER: 1712 if (configure_tda827x_fe(dev, &philips_tiger_config, 1713 &tda827x_cfg_0) < 0) 1714 goto detach_frontend; 1715 break; 1716 case SAA7134_BOARD_BEHOLD_H6: 1717 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1718 &behold_h6_config, 1719 &dev->i2c_adap); 1720 if (fe0->dvb.frontend) { 1721 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1722 &dev->i2c_adap, 0x61, 1723 TUNER_PHILIPS_FMD1216MEX_MK3); 1724 } 1725 break; 1726 case SAA7134_BOARD_BEHOLD_X7: 1727 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1728 &behold_x7_config, 1729 &dev->i2c_adap); 1730 if (fe0->dvb.frontend) { 1731 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1732 &dev->i2c_adap, &behold_x7_tunerconfig); 1733 } 1734 break; 1735 case SAA7134_BOARD_BEHOLD_H7: 1736 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1737 &behold_x7_config, 1738 &dev->i2c_adap); 1739 if (fe0->dvb.frontend) { 1740 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1741 &dev->i2c_adap, &behold_x7_tunerconfig); 1742 } 1743 break; 1744 case SAA7134_BOARD_AVERMEDIA_A700_PRO: 1745 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID: 1746 /* Zarlink ZL10313 */ 1747 fe0->dvb.frontend = dvb_attach(mt312_attach, 1748 &avertv_a700_mt312, &dev->i2c_adap); 1749 if (fe0->dvb.frontend) { 1750 if (dvb_attach(zl10036_attach, fe0->dvb.frontend, 1751 &avertv_a700_tuner, &dev->i2c_adap) == NULL) { 1752 pr_warn("%s: No zl10036 found!\n", 1753 __func__); 1754 } 1755 } 1756 break; 1757 case SAA7134_BOARD_VIDEOMATE_S350: 1758 fe0->dvb.frontend = dvb_attach(mt312_attach, 1759 &zl10313_compro_s350_config, &dev->i2c_adap); 1760 if (fe0->dvb.frontend) 1761 if (dvb_attach(zl10039_attach, fe0->dvb.frontend, 1762 0x60, &dev->i2c_adap) == NULL) 1763 pr_warn("%s: No zl10039 found!\n", 1764 __func__); 1765 1766 break; 1767 case SAA7134_BOARD_VIDEOMATE_T750: 1768 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1769 &videomate_t750_zl10353_config, 1770 &dev->i2c_adap); 1771 if (fe0->dvb.frontend != NULL) { 1772 if (dvb_attach(qt1010_attach, 1773 fe0->dvb.frontend, 1774 &dev->i2c_adap, 1775 &videomate_t750_qt1010_config) == NULL) 1776 pr_warn("error attaching QT1010\n"); 1777 } 1778 break; 1779 case SAA7134_BOARD_ZOLID_HYBRID_PCI: 1780 fe0->dvb.frontend = dvb_attach(tda10048_attach, 1781 &zolid_tda10048_config, 1782 &dev->i2c_adap); 1783 if (fe0->dvb.frontend != NULL) { 1784 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1785 &dev->i2c_adap, 0x4b, 1786 &tda829x_no_probe); 1787 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1788 0x60, &dev->i2c_adap, 1789 &zolid_tda18271_config); 1790 } 1791 break; 1792 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S: 1793 fe0->dvb.frontend = dvb_attach(tda10048_attach, 1794 &dtv1000s_tda10048_config, 1795 &dev->i2c_adap); 1796 if (fe0->dvb.frontend != NULL) { 1797 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1798 &dev->i2c_adap, 0x4b, 1799 &tda829x_no_probe); 1800 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1801 0x60, &dev->i2c_adap, 1802 &dtv1000s_tda18271_config); 1803 } 1804 break; 1805 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG: 1806 /* Switch to digital mode */ 1807 saa7134_tuner_callback(dev, 0, 1808 TDA18271_CALLBACK_CMD_AGC_ENABLE, 1); 1809 fe0->dvb.frontend = dvb_attach(mb86a20s_attach, 1810 &kworld_mb86a20s_config, 1811 &dev->i2c_adap); 1812 if (fe0->dvb.frontend != NULL) { 1813 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1814 &dev->i2c_adap, 0x4b, 1815 &tda829x_no_probe); 1816 fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_gate_ctrl; 1817 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1818 0x60, &dev->i2c_adap, 1819 &kworld_tda18271_config); 1820 } 1821 1822 /* mb86a20s need to use the I2C gateway */ 1823 break; 1824 case SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2: 1825 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach, 1826 &prohdtv_pro2_lgs8g75_config, 1827 &dev->i2c_adap); 1828 if (fe0->dvb.frontend != NULL) { 1829 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1830 &dev->i2c_adap, 0x4b, 1831 &tda829x_no_probe); 1832 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1833 0x60, &dev->i2c_adap, 1834 &prohdtv_pro2_tda18271_config); 1835 } 1836 break; 1837 case SAA7134_BOARD_AVERMEDIA_A706: 1838 /* Enable all DVB-S devices now */ 1839 /* CE5039 DVB-S tuner SLEEP pin low */ 1840 saa7134_set_gpio(dev, 23, 0); 1841 /* CE6313 DVB-S demod SLEEP pin low */ 1842 saa7134_set_gpio(dev, 9, 0); 1843 /* CE6313 DVB-S demod RESET# pin high */ 1844 saa7134_set_gpio(dev, 25, 1); 1845 msleep(1); 1846 fe0->dvb.frontend = dvb_attach(mt312_attach, 1847 &zl10313_avermedia_a706_config, &dev->i2c_adap); 1848 if (fe0->dvb.frontend) { 1849 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL; 1850 if (dvb_attach(zl10039_attach, fe0->dvb.frontend, 1851 0x60, &dev->i2c_adap) == NULL) 1852 pr_warn("%s: No zl10039 found!\n", 1853 __func__); 1854 } 1855 break; 1856 default: 1857 pr_warn("Huh? unknown DVB card?\n"); 1858 break; 1859 } 1860 1861 if (attach_xc3028) { 1862 struct dvb_frontend *fe; 1863 struct xc2028_config cfg = { 1864 .i2c_adap = &dev->i2c_adap, 1865 .i2c_addr = 0x61, 1866 }; 1867 1868 if (!fe0->dvb.frontend) 1869 goto detach_frontend; 1870 1871 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg); 1872 if (!fe) { 1873 pr_err("%s/2: xc3028 attach failed\n", 1874 dev->name); 1875 goto detach_frontend; 1876 } 1877 } 1878 1879 if (NULL == fe0->dvb.frontend) { 1880 pr_err("%s/dvb: frontend initialization failed\n", dev->name); 1881 goto detach_frontend; 1882 } 1883 /* define general-purpose callback pointer */ 1884 fe0->dvb.frontend->callback = saa7134_tuner_callback; 1885 1886 /* register everything else */ 1887 #ifndef CONFIG_MEDIA_CONTROLLER_DVB 1888 ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev, 1889 &dev->pci->dev, NULL, 1890 adapter_nr, 0); 1891 #else 1892 ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev, 1893 &dev->pci->dev, dev->media_dev, 1894 adapter_nr, 0); 1895 #endif 1896 1897 /* this sequence is necessary to make the tda1004x load its firmware 1898 * and to enter analog mode of hybrid boards 1899 */ 1900 if (!ret) { 1901 if (fe0->dvb.frontend->ops.init) 1902 fe0->dvb.frontend->ops.init(fe0->dvb.frontend); 1903 if (fe0->dvb.frontend->ops.sleep) 1904 fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend); 1905 if (fe0->dvb.frontend->ops.tuner_ops.sleep) 1906 fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend); 1907 } 1908 return ret; 1909 1910 detach_frontend: 1911 vb2_dvb_dealloc_frontends(&dev->frontends); 1912 vb2_queue_release(&fe0->dvb.dvbq); 1913 return -EINVAL; 1914 } 1915 1916 static int dvb_fini(struct saa7134_dev *dev) 1917 { 1918 struct vb2_dvb_frontend *fe0; 1919 1920 /* Get the first frontend */ 1921 fe0 = vb2_dvb_get_frontend(&dev->frontends, 1); 1922 if (!fe0) 1923 return -EINVAL; 1924 1925 /* FIXME: I suspect that this code is bogus, since the entry for 1926 Pinnacle 300I DVB-T PAL already defines the proper init to allow 1927 the detection of mt2032 (TDA9887_PORT2_INACTIVE) 1928 */ 1929 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) { 1930 struct v4l2_priv_tun_config tda9887_cfg; 1931 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE; 1932 1933 tda9887_cfg.tuner = TUNER_TDA9887; 1934 tda9887_cfg.priv = &on; 1935 1936 /* otherwise we don't detect the tuner on next insmod */ 1937 saa_call_all(dev, tuner, s_config, &tda9887_cfg); 1938 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) { 1939 if ((dev->eedata[2] == 0x07) && use_frontend) { 1940 /* turn off the 2nd lnb supply */ 1941 u8 data = 0x80; 1942 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1}; 1943 struct dvb_frontend *fe; 1944 fe = fe0->dvb.frontend; 1945 if (fe->ops.i2c_gate_ctrl) { 1946 fe->ops.i2c_gate_ctrl(fe, 1); 1947 i2c_transfer(&dev->i2c_adap, &msg, 1); 1948 fe->ops.i2c_gate_ctrl(fe, 0); 1949 } 1950 } 1951 } 1952 vb2_dvb_unregister_bus(&dev->frontends); 1953 vb2_queue_release(&fe0->dvb.dvbq); 1954 return 0; 1955 } 1956 1957 static struct saa7134_mpeg_ops dvb_ops = { 1958 .type = SAA7134_MPEG_DVB, 1959 .init = dvb_init, 1960 .fini = dvb_fini, 1961 }; 1962 1963 static int __init dvb_register(void) 1964 { 1965 return saa7134_ts_register(&dvb_ops); 1966 } 1967 1968 static void __exit dvb_unregister(void) 1969 { 1970 saa7134_ts_unregister(&dvb_ops); 1971 } 1972 1973 module_init(dvb_register); 1974 module_exit(dvb_unregister); 1975