1 /* 2 * Driver for the Conexant CX23885 PCIe bridge 3 * 4 * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * 15 * GNU General Public License for more details. 16 */ 17 18 #include <linux/module.h> 19 #include <linux/init.h> 20 #include <linux/device.h> 21 #include <linux/fs.h> 22 #include <linux/kthread.h> 23 #include <linux/file.h> 24 #include <linux/suspend.h> 25 26 #include "cx23885.h" 27 #include <media/v4l2-common.h> 28 29 #include "dvb_ca_en50221.h" 30 #include "s5h1409.h" 31 #include "s5h1411.h" 32 #include "mt2131.h" 33 #include "tda8290.h" 34 #include "tda18271.h" 35 #include "lgdt330x.h" 36 #include "xc4000.h" 37 #include "xc5000.h" 38 #include "max2165.h" 39 #include "tda10048.h" 40 #include "tuner-xc2028.h" 41 #include "tuner-simple.h" 42 #include "dib7000p.h" 43 #include "dib0070.h" 44 #include "dibx000_common.h" 45 #include "zl10353.h" 46 #include "stv0900.h" 47 #include "stv0900_reg.h" 48 #include "stv6110.h" 49 #include "lnbh24.h" 50 #include "cx24116.h" 51 #include "cx24117.h" 52 #include "cimax2.h" 53 #include "lgs8gxx.h" 54 #include "netup-eeprom.h" 55 #include "netup-init.h" 56 #include "lgdt3305.h" 57 #include "atbm8830.h" 58 #include "ts2020.h" 59 #include "ds3000.h" 60 #include "cx23885-f300.h" 61 #include "altera-ci.h" 62 #include "stv0367.h" 63 #include "drxk.h" 64 #include "mt2063.h" 65 #include "stv090x.h" 66 #include "stb6100.h" 67 #include "stb6100_cfg.h" 68 #include "tda10071.h" 69 #include "a8293.h" 70 #include "mb86a20s.h" 71 #include "si2165.h" 72 #include "si2168.h" 73 #include "si2157.h" 74 #include "sp2.h" 75 #include "m88ds3103.h" 76 #include "m88rs6000t.h" 77 #include "lgdt3306a.h" 78 79 static unsigned int debug; 80 81 #define dprintk(level, fmt, arg...)\ 82 do { if (debug >= level)\ 83 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ 84 } while (0) 85 86 /* ------------------------------------------------------------------ */ 87 88 static unsigned int alt_tuner; 89 module_param(alt_tuner, int, 0644); 90 MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration"); 91 92 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 93 94 /* ------------------------------------------------------------------ */ 95 96 static int queue_setup(struct vb2_queue *q, 97 unsigned int *num_buffers, unsigned int *num_planes, 98 unsigned int sizes[], struct device *alloc_devs[]) 99 { 100 struct cx23885_tsport *port = q->drv_priv; 101 102 port->ts_packet_size = 188 * 4; 103 port->ts_packet_count = 32; 104 *num_planes = 1; 105 sizes[0] = port->ts_packet_size * port->ts_packet_count; 106 *num_buffers = 32; 107 return 0; 108 } 109 110 111 static int buffer_prepare(struct vb2_buffer *vb) 112 { 113 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 114 struct cx23885_tsport *port = vb->vb2_queue->drv_priv; 115 struct cx23885_buffer *buf = 116 container_of(vbuf, struct cx23885_buffer, vb); 117 118 return cx23885_buf_prepare(buf, port); 119 } 120 121 static void buffer_finish(struct vb2_buffer *vb) 122 { 123 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 124 struct cx23885_tsport *port = vb->vb2_queue->drv_priv; 125 struct cx23885_dev *dev = port->dev; 126 struct cx23885_buffer *buf = container_of(vbuf, 127 struct cx23885_buffer, vb); 128 129 cx23885_free_buffer(dev, buf); 130 } 131 132 static void buffer_queue(struct vb2_buffer *vb) 133 { 134 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 135 struct cx23885_tsport *port = vb->vb2_queue->drv_priv; 136 struct cx23885_buffer *buf = container_of(vbuf, 137 struct cx23885_buffer, vb); 138 139 cx23885_buf_queue(port, buf); 140 } 141 142 static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open) 143 { 144 struct vb2_dvb_frontends *f; 145 struct vb2_dvb_frontend *fe; 146 147 f = &port->frontends; 148 149 if (f->gate <= 1) /* undefined or fe0 */ 150 fe = vb2_dvb_get_frontend(f, 1); 151 else 152 fe = vb2_dvb_get_frontend(f, f->gate); 153 154 if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl) 155 fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open); 156 } 157 158 static int cx23885_start_streaming(struct vb2_queue *q, unsigned int count) 159 { 160 struct cx23885_tsport *port = q->drv_priv; 161 struct cx23885_dmaqueue *dmaq = &port->mpegq; 162 struct cx23885_buffer *buf = list_entry(dmaq->active.next, 163 struct cx23885_buffer, queue); 164 165 cx23885_start_dma(port, dmaq, buf); 166 return 0; 167 } 168 169 static void cx23885_stop_streaming(struct vb2_queue *q) 170 { 171 struct cx23885_tsport *port = q->drv_priv; 172 173 cx23885_cancel_buffers(port); 174 } 175 176 static const struct vb2_ops dvb_qops = { 177 .queue_setup = queue_setup, 178 .buf_prepare = buffer_prepare, 179 .buf_finish = buffer_finish, 180 .buf_queue = buffer_queue, 181 .wait_prepare = vb2_ops_wait_prepare, 182 .wait_finish = vb2_ops_wait_finish, 183 .start_streaming = cx23885_start_streaming, 184 .stop_streaming = cx23885_stop_streaming, 185 }; 186 187 static struct s5h1409_config hauppauge_generic_config = { 188 .demod_address = 0x32 >> 1, 189 .output_mode = S5H1409_SERIAL_OUTPUT, 190 .gpio = S5H1409_GPIO_ON, 191 .qam_if = 44000, 192 .inversion = S5H1409_INVERSION_OFF, 193 .status_mode = S5H1409_DEMODLOCKING, 194 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 195 }; 196 197 static struct tda10048_config hauppauge_hvr1200_config = { 198 .demod_address = 0x10 >> 1, 199 .output_mode = TDA10048_SERIAL_OUTPUT, 200 .fwbulkwritelen = TDA10048_BULKWRITE_200, 201 .inversion = TDA10048_INVERSION_ON, 202 .dtv6_if_freq_khz = TDA10048_IF_3300, 203 .dtv7_if_freq_khz = TDA10048_IF_3800, 204 .dtv8_if_freq_khz = TDA10048_IF_4300, 205 .clk_freq_khz = TDA10048_CLK_16000, 206 }; 207 208 static struct tda10048_config hauppauge_hvr1210_config = { 209 .demod_address = 0x10 >> 1, 210 .output_mode = TDA10048_SERIAL_OUTPUT, 211 .fwbulkwritelen = TDA10048_BULKWRITE_200, 212 .inversion = TDA10048_INVERSION_ON, 213 .dtv6_if_freq_khz = TDA10048_IF_3300, 214 .dtv7_if_freq_khz = TDA10048_IF_3500, 215 .dtv8_if_freq_khz = TDA10048_IF_4000, 216 .clk_freq_khz = TDA10048_CLK_16000, 217 }; 218 219 static struct s5h1409_config hauppauge_ezqam_config = { 220 .demod_address = 0x32 >> 1, 221 .output_mode = S5H1409_SERIAL_OUTPUT, 222 .gpio = S5H1409_GPIO_OFF, 223 .qam_if = 4000, 224 .inversion = S5H1409_INVERSION_ON, 225 .status_mode = S5H1409_DEMODLOCKING, 226 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 227 }; 228 229 static struct s5h1409_config hauppauge_hvr1800lp_config = { 230 .demod_address = 0x32 >> 1, 231 .output_mode = S5H1409_SERIAL_OUTPUT, 232 .gpio = S5H1409_GPIO_OFF, 233 .qam_if = 44000, 234 .inversion = S5H1409_INVERSION_OFF, 235 .status_mode = S5H1409_DEMODLOCKING, 236 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 237 }; 238 239 static struct s5h1409_config hauppauge_hvr1500_config = { 240 .demod_address = 0x32 >> 1, 241 .output_mode = S5H1409_SERIAL_OUTPUT, 242 .gpio = S5H1409_GPIO_OFF, 243 .inversion = S5H1409_INVERSION_OFF, 244 .status_mode = S5H1409_DEMODLOCKING, 245 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 246 }; 247 248 static struct mt2131_config hauppauge_generic_tunerconfig = { 249 0x61 250 }; 251 252 static struct lgdt330x_config fusionhdtv_5_express = { 253 .demod_address = 0x0e, 254 .demod_chip = LGDT3303, 255 .serial_mpeg = 0x40, 256 }; 257 258 static struct s5h1409_config hauppauge_hvr1500q_config = { 259 .demod_address = 0x32 >> 1, 260 .output_mode = S5H1409_SERIAL_OUTPUT, 261 .gpio = S5H1409_GPIO_ON, 262 .qam_if = 44000, 263 .inversion = S5H1409_INVERSION_OFF, 264 .status_mode = S5H1409_DEMODLOCKING, 265 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 266 }; 267 268 static struct s5h1409_config dvico_s5h1409_config = { 269 .demod_address = 0x32 >> 1, 270 .output_mode = S5H1409_SERIAL_OUTPUT, 271 .gpio = S5H1409_GPIO_ON, 272 .qam_if = 44000, 273 .inversion = S5H1409_INVERSION_OFF, 274 .status_mode = S5H1409_DEMODLOCKING, 275 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 276 }; 277 278 static struct s5h1411_config dvico_s5h1411_config = { 279 .output_mode = S5H1411_SERIAL_OUTPUT, 280 .gpio = S5H1411_GPIO_ON, 281 .qam_if = S5H1411_IF_44000, 282 .vsb_if = S5H1411_IF_44000, 283 .inversion = S5H1411_INVERSION_OFF, 284 .status_mode = S5H1411_DEMODLOCKING, 285 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 286 }; 287 288 static struct s5h1411_config hcw_s5h1411_config = { 289 .output_mode = S5H1411_SERIAL_OUTPUT, 290 .gpio = S5H1411_GPIO_OFF, 291 .vsb_if = S5H1411_IF_44000, 292 .qam_if = S5H1411_IF_4000, 293 .inversion = S5H1411_INVERSION_ON, 294 .status_mode = S5H1411_DEMODLOCKING, 295 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 296 }; 297 298 static struct xc5000_config hauppauge_hvr1500q_tunerconfig = { 299 .i2c_address = 0x61, 300 .if_khz = 5380, 301 }; 302 303 static struct xc5000_config dvico_xc5000_tunerconfig = { 304 .i2c_address = 0x64, 305 .if_khz = 5380, 306 }; 307 308 static struct tda829x_config tda829x_no_probe = { 309 .probe_tuner = TDA829X_DONT_PROBE, 310 }; 311 312 static struct tda18271_std_map hauppauge_tda18271_std_map = { 313 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, 314 .if_lvl = 6, .rfagc_top = 0x37 }, 315 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0, 316 .if_lvl = 6, .rfagc_top = 0x37 }, 317 }; 318 319 static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = { 320 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4, 321 .if_lvl = 1, .rfagc_top = 0x37, }, 322 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5, 323 .if_lvl = 1, .rfagc_top = 0x37, }, 324 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6, 325 .if_lvl = 1, .rfagc_top = 0x37, }, 326 }; 327 328 static struct tda18271_config hauppauge_tda18271_config = { 329 .std_map = &hauppauge_tda18271_std_map, 330 .gate = TDA18271_GATE_ANALOG, 331 .output_opt = TDA18271_OUTPUT_LT_OFF, 332 }; 333 334 static struct tda18271_config hauppauge_hvr1200_tuner_config = { 335 .std_map = &hauppauge_hvr1200_tda18271_std_map, 336 .gate = TDA18271_GATE_ANALOG, 337 .output_opt = TDA18271_OUTPUT_LT_OFF, 338 }; 339 340 static struct tda18271_config hauppauge_hvr1210_tuner_config = { 341 .gate = TDA18271_GATE_DIGITAL, 342 .output_opt = TDA18271_OUTPUT_LT_OFF, 343 }; 344 345 static struct tda18271_config hauppauge_hvr4400_tuner_config = { 346 .gate = TDA18271_GATE_DIGITAL, 347 .output_opt = TDA18271_OUTPUT_LT_OFF, 348 }; 349 350 static struct tda18271_std_map hauppauge_hvr127x_std_map = { 351 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4, 352 .if_lvl = 1, .rfagc_top = 0x58 }, 353 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5, 354 .if_lvl = 1, .rfagc_top = 0x58 }, 355 }; 356 357 static struct tda18271_config hauppauge_hvr127x_config = { 358 .std_map = &hauppauge_hvr127x_std_map, 359 .output_opt = TDA18271_OUTPUT_LT_OFF, 360 }; 361 362 static struct lgdt3305_config hauppauge_lgdt3305_config = { 363 .i2c_addr = 0x0e, 364 .mpeg_mode = LGDT3305_MPEG_SERIAL, 365 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, 366 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, 367 .deny_i2c_rptr = 1, 368 .spectral_inversion = 1, 369 .qam_if_khz = 4000, 370 .vsb_if_khz = 3250, 371 }; 372 373 static struct dibx000_agc_config xc3028_agc_config = { 374 BAND_VHF | BAND_UHF, /* band_caps */ 375 376 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0, 377 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, 378 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, 379 * P_agc_nb_est=2, P_agc_write=0 380 */ 381 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | 382 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */ 383 384 712, /* inv_gain */ 385 21, /* time_stabiliz */ 386 387 0, /* alpha_level */ 388 118, /* thlock */ 389 390 0, /* wbd_inv */ 391 2867, /* wbd_ref */ 392 0, /* wbd_sel */ 393 2, /* wbd_alpha */ 394 395 0, /* agc1_max */ 396 0, /* agc1_min */ 397 39718, /* agc2_max */ 398 9930, /* agc2_min */ 399 0, /* agc1_pt1 */ 400 0, /* agc1_pt2 */ 401 0, /* agc1_pt3 */ 402 0, /* agc1_slope1 */ 403 0, /* agc1_slope2 */ 404 0, /* agc2_pt1 */ 405 128, /* agc2_pt2 */ 406 29, /* agc2_slope1 */ 407 29, /* agc2_slope2 */ 408 409 17, /* alpha_mant */ 410 27, /* alpha_exp */ 411 23, /* beta_mant */ 412 51, /* beta_exp */ 413 414 1, /* perform_agc_softsplit */ 415 }; 416 417 /* PLL Configuration for COFDM BW_MHz = 8.000000 418 * With external clock = 30.000000 */ 419 static struct dibx000_bandwidth_config xc3028_bw_config = { 420 60000, /* internal */ 421 30000, /* sampling */ 422 1, /* pll_cfg: prediv */ 423 8, /* pll_cfg: ratio */ 424 3, /* pll_cfg: range */ 425 1, /* pll_cfg: reset */ 426 0, /* pll_cfg: bypass */ 427 0, /* misc: refdiv */ 428 0, /* misc: bypclk_div */ 429 1, /* misc: IO_CLK_en_core */ 430 1, /* misc: ADClkSrc */ 431 0, /* misc: modulo */ 432 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */ 433 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */ 434 20452225, /* timf */ 435 30000000 /* xtal_hz */ 436 }; 437 438 static struct dib7000p_config hauppauge_hvr1400_dib7000_config = { 439 .output_mpeg2_in_188_bytes = 1, 440 .hostbus_diversity = 1, 441 .tuner_is_baseband = 0, 442 .update_lna = NULL, 443 444 .agc_config_count = 1, 445 .agc = &xc3028_agc_config, 446 .bw = &xc3028_bw_config, 447 448 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS, 449 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES, 450 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS, 451 452 .pwm_freq_div = 0, 453 .agc_control = NULL, 454 .spur_protect = 0, 455 456 .output_mode = OUTMODE_MPEG2_SERIAL, 457 }; 458 459 static struct zl10353_config dvico_fusionhdtv_xc3028 = { 460 .demod_address = 0x0f, 461 .if2 = 45600, 462 .no_tuner = 1, 463 .disable_i2c_gate_ctrl = 1, 464 }; 465 466 static struct stv0900_reg stv0900_ts_regs[] = { 467 { R0900_TSGENERAL, 0x00 }, 468 { R0900_P1_TSSPEED, 0x40 }, 469 { R0900_P2_TSSPEED, 0x40 }, 470 { R0900_P1_TSCFGM, 0xc0 }, 471 { R0900_P2_TSCFGM, 0xc0 }, 472 { R0900_P1_TSCFGH, 0xe0 }, 473 { R0900_P2_TSCFGH, 0xe0 }, 474 { R0900_P1_TSCFGL, 0x20 }, 475 { R0900_P2_TSCFGL, 0x20 }, 476 { 0xffff, 0xff }, /* terminate */ 477 }; 478 479 static struct stv0900_config netup_stv0900_config = { 480 .demod_address = 0x68, 481 .demod_mode = 1, /* dual */ 482 .xtal = 8000000, 483 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */ 484 .diseqc_mode = 2,/* 2/3 PWM */ 485 .ts_config_regs = stv0900_ts_regs, 486 .tun1_maddress = 0,/* 0x60 */ 487 .tun2_maddress = 3,/* 0x63 */ 488 .tun1_adc = 1,/* 1 Vpp */ 489 .tun2_adc = 1,/* 1 Vpp */ 490 }; 491 492 static struct stv6110_config netup_stv6110_tunerconfig_a = { 493 .i2c_address = 0x60, 494 .mclk = 16000000, 495 .clk_div = 1, 496 .gain = 8, /* +16 dB - maximum gain */ 497 }; 498 499 static struct stv6110_config netup_stv6110_tunerconfig_b = { 500 .i2c_address = 0x63, 501 .mclk = 16000000, 502 .clk_div = 1, 503 .gain = 8, /* +16 dB - maximum gain */ 504 }; 505 506 static struct cx24116_config tbs_cx24116_config = { 507 .demod_address = 0x55, 508 }; 509 510 static struct cx24117_config tbs_cx24117_config = { 511 .demod_address = 0x55, 512 }; 513 514 static struct ds3000_config tevii_ds3000_config = { 515 .demod_address = 0x68, 516 }; 517 518 static struct ts2020_config tevii_ts2020_config = { 519 .tuner_address = 0x60, 520 .clk_out_div = 1, 521 .frequency_div = 1146000, 522 }; 523 524 static struct cx24116_config dvbworld_cx24116_config = { 525 .demod_address = 0x05, 526 }; 527 528 static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = { 529 .prod = LGS8GXX_PROD_LGS8GL5, 530 .demod_address = 0x19, 531 .serial_ts = 0, 532 .ts_clk_pol = 1, 533 .ts_clk_gated = 1, 534 .if_clk_freq = 30400, /* 30.4 MHz */ 535 .if_freq = 5380, /* 5.38 MHz */ 536 .if_neg_center = 1, 537 .ext_adc = 0, 538 .adc_signed = 0, 539 .if_neg_edge = 0, 540 }; 541 542 static struct xc5000_config mygica_x8506_xc5000_config = { 543 .i2c_address = 0x61, 544 .if_khz = 5380, 545 }; 546 547 static struct mb86a20s_config mygica_x8507_mb86a20s_config = { 548 .demod_address = 0x10, 549 }; 550 551 static struct xc5000_config mygica_x8507_xc5000_config = { 552 .i2c_address = 0x61, 553 .if_khz = 4000, 554 }; 555 556 static struct stv090x_config prof_8000_stv090x_config = { 557 .device = STV0903, 558 .demod_mode = STV090x_SINGLE, 559 .clk_mode = STV090x_CLK_EXT, 560 .xtal = 27000000, 561 .address = 0x6A, 562 .ts1_mode = STV090x_TSMODE_PARALLEL_PUNCTURED, 563 .repeater_level = STV090x_RPTLEVEL_64, 564 .adc1_range = STV090x_ADC_2Vpp, 565 .diseqc_envelope_mode = false, 566 567 .tuner_get_frequency = stb6100_get_frequency, 568 .tuner_set_frequency = stb6100_set_frequency, 569 .tuner_set_bandwidth = stb6100_set_bandwidth, 570 .tuner_get_bandwidth = stb6100_get_bandwidth, 571 }; 572 573 static struct stb6100_config prof_8000_stb6100_config = { 574 .tuner_address = 0x60, 575 .refclock = 27000000, 576 }; 577 578 static struct lgdt3306a_config hauppauge_quadHD_ATSC_a_config = { 579 .i2c_addr = 0x59, 580 .qam_if_khz = 4000, 581 .vsb_if_khz = 3250, 582 .deny_i2c_rptr = 1, /* Disabled */ 583 .spectral_inversion = 0, /* Disabled */ 584 .mpeg_mode = LGDT3306A_MPEG_SERIAL, 585 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE, 586 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH, 587 .xtalMHz = 25, /* 24 or 25 */ 588 }; 589 590 static struct lgdt3306a_config hauppauge_quadHD_ATSC_b_config = { 591 .i2c_addr = 0x0e, 592 .qam_if_khz = 4000, 593 .vsb_if_khz = 3250, 594 .deny_i2c_rptr = 1, /* Disabled */ 595 .spectral_inversion = 0, /* Disabled */ 596 .mpeg_mode = LGDT3306A_MPEG_SERIAL, 597 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE, 598 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH, 599 .xtalMHz = 25, /* 24 or 25 */ 600 }; 601 602 static int p8000_set_voltage(struct dvb_frontend *fe, 603 enum fe_sec_voltage voltage) 604 { 605 struct cx23885_tsport *port = fe->dvb->priv; 606 struct cx23885_dev *dev = port->dev; 607 608 if (voltage == SEC_VOLTAGE_18) 609 cx_write(MC417_RWD, 0x00001e00); 610 else if (voltage == SEC_VOLTAGE_13) 611 cx_write(MC417_RWD, 0x00001a00); 612 else 613 cx_write(MC417_RWD, 0x00001800); 614 return 0; 615 } 616 617 static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe, 618 enum fe_sec_voltage voltage) 619 { 620 struct cx23885_tsport *port = fe->dvb->priv; 621 struct cx23885_dev *dev = port->dev; 622 623 cx23885_gpio_enable(dev, GPIO_0 | GPIO_1, 1); 624 625 switch (voltage) { 626 case SEC_VOLTAGE_13: 627 cx23885_gpio_set(dev, GPIO_1); 628 cx23885_gpio_clear(dev, GPIO_0); 629 break; 630 case SEC_VOLTAGE_18: 631 cx23885_gpio_set(dev, GPIO_1); 632 cx23885_gpio_set(dev, GPIO_0); 633 break; 634 case SEC_VOLTAGE_OFF: 635 cx23885_gpio_clear(dev, GPIO_1); 636 cx23885_gpio_clear(dev, GPIO_0); 637 break; 638 } 639 640 /* call the frontend set_voltage function */ 641 port->fe_set_voltage(fe, voltage); 642 643 return 0; 644 } 645 646 static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe, 647 enum fe_sec_voltage voltage) 648 { 649 struct cx23885_tsport *port = fe->dvb->priv; 650 struct cx23885_dev *dev = port->dev; 651 652 cx23885_gpio_enable(dev, GPIO_12 | GPIO_13, 1); 653 654 switch (voltage) { 655 case SEC_VOLTAGE_13: 656 cx23885_gpio_set(dev, GPIO_13); 657 cx23885_gpio_clear(dev, GPIO_12); 658 break; 659 case SEC_VOLTAGE_18: 660 cx23885_gpio_set(dev, GPIO_13); 661 cx23885_gpio_set(dev, GPIO_12); 662 break; 663 case SEC_VOLTAGE_OFF: 664 cx23885_gpio_clear(dev, GPIO_13); 665 cx23885_gpio_clear(dev, GPIO_12); 666 break; 667 } 668 /* call the frontend set_voltage function */ 669 return port->fe_set_voltage(fe, voltage); 670 } 671 672 static int cx23885_sp2_ci_ctrl(void *priv, u8 read, int addr, 673 u8 data, int *mem) 674 { 675 /* MC417 */ 676 #define SP2_DATA 0x000000ff 677 #define SP2_WR 0x00008000 678 #define SP2_RD 0x00004000 679 #define SP2_ACK 0x00001000 680 #define SP2_ADHI 0x00000800 681 #define SP2_ADLO 0x00000400 682 #define SP2_CS1 0x00000200 683 #define SP2_CS0 0x00000100 684 #define SP2_EN_ALL 0x00001000 685 #define SP2_CTRL_OFF (SP2_CS1 | SP2_CS0 | SP2_WR | SP2_RD) 686 687 struct cx23885_tsport *port = priv; 688 struct cx23885_dev *dev = port->dev; 689 int ret; 690 int tmp = 0; 691 unsigned long timeout; 692 693 mutex_lock(&dev->gpio_lock); 694 695 /* write addr */ 696 cx_write(MC417_OEN, SP2_EN_ALL); 697 cx_write(MC417_RWD, SP2_CTRL_OFF | 698 SP2_ADLO | (0xff & addr)); 699 cx_clear(MC417_RWD, SP2_ADLO); 700 cx_write(MC417_RWD, SP2_CTRL_OFF | 701 SP2_ADHI | (0xff & (addr >> 8))); 702 cx_clear(MC417_RWD, SP2_ADHI); 703 704 if (read) 705 /* data in */ 706 cx_write(MC417_OEN, SP2_EN_ALL | SP2_DATA); 707 else 708 /* data out */ 709 cx_write(MC417_RWD, SP2_CTRL_OFF | data); 710 711 /* chip select 0 */ 712 cx_clear(MC417_RWD, SP2_CS0); 713 714 /* read/write */ 715 cx_clear(MC417_RWD, (read) ? SP2_RD : SP2_WR); 716 717 /* wait for a maximum of 1 msec */ 718 timeout = jiffies + msecs_to_jiffies(1); 719 while (!time_after(jiffies, timeout)) { 720 tmp = cx_read(MC417_RWD); 721 if ((tmp & SP2_ACK) == 0) 722 break; 723 usleep_range(50, 100); 724 } 725 726 cx_set(MC417_RWD, SP2_CTRL_OFF); 727 *mem = tmp & 0xff; 728 729 mutex_unlock(&dev->gpio_lock); 730 731 if (!read) { 732 if (*mem < 0) { 733 ret = -EREMOTEIO; 734 goto err; 735 } 736 } 737 738 return 0; 739 err: 740 return ret; 741 } 742 743 static int cx23885_dvb_set_frontend(struct dvb_frontend *fe) 744 { 745 struct dtv_frontend_properties *p = &fe->dtv_property_cache; 746 struct cx23885_tsport *port = fe->dvb->priv; 747 struct cx23885_dev *dev = port->dev; 748 749 switch (dev->board) { 750 case CX23885_BOARD_HAUPPAUGE_HVR1275: 751 switch (p->modulation) { 752 case VSB_8: 753 cx23885_gpio_clear(dev, GPIO_5); 754 break; 755 case QAM_64: 756 case QAM_256: 757 default: 758 cx23885_gpio_set(dev, GPIO_5); 759 break; 760 } 761 break; 762 case CX23885_BOARD_MYGICA_X8506: 763 case CX23885_BOARD_MYGICA_X8507: 764 case CX23885_BOARD_MAGICPRO_PROHDTVE2: 765 /* Select Digital TV */ 766 cx23885_gpio_set(dev, GPIO_0); 767 break; 768 } 769 770 /* Call the real set_frontend */ 771 if (port->set_frontend) 772 return port->set_frontend(fe); 773 774 return 0; 775 } 776 777 static void cx23885_set_frontend_hook(struct cx23885_tsport *port, 778 struct dvb_frontend *fe) 779 { 780 port->set_frontend = fe->ops.set_frontend; 781 fe->ops.set_frontend = cx23885_dvb_set_frontend; 782 } 783 784 static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = { 785 .prod = LGS8GXX_PROD_LGS8G75, 786 .demod_address = 0x19, 787 .serial_ts = 0, 788 .ts_clk_pol = 1, 789 .ts_clk_gated = 1, 790 .if_clk_freq = 30400, /* 30.4 MHz */ 791 .if_freq = 6500, /* 6.50 MHz */ 792 .if_neg_center = 1, 793 .ext_adc = 0, 794 .adc_signed = 1, 795 .adc_vpp = 2, /* 1.6 Vpp */ 796 .if_neg_edge = 1, 797 }; 798 799 static struct xc5000_config magicpro_prohdtve2_xc5000_config = { 800 .i2c_address = 0x61, 801 .if_khz = 6500, 802 }; 803 804 static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = { 805 .prod = ATBM8830_PROD_8830, 806 .demod_address = 0x44, 807 .serial_ts = 0, 808 .ts_sampling_edge = 1, 809 .ts_clk_gated = 0, 810 .osc_clk_freq = 30400, /* in kHz */ 811 .if_freq = 0, /* zero IF */ 812 .zif_swap_iq = 1, 813 .agc_min = 0x2E, 814 .agc_max = 0xFF, 815 .agc_hold_loop = 0, 816 }; 817 818 static struct max2165_config mygic_x8558pro_max2165_cfg1 = { 819 .i2c_address = 0x60, 820 .osc_clk = 20 821 }; 822 823 static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = { 824 .prod = ATBM8830_PROD_8830, 825 .demod_address = 0x44, 826 .serial_ts = 1, 827 .ts_sampling_edge = 1, 828 .ts_clk_gated = 0, 829 .osc_clk_freq = 30400, /* in kHz */ 830 .if_freq = 0, /* zero IF */ 831 .zif_swap_iq = 1, 832 .agc_min = 0x2E, 833 .agc_max = 0xFF, 834 .agc_hold_loop = 0, 835 }; 836 837 static struct max2165_config mygic_x8558pro_max2165_cfg2 = { 838 .i2c_address = 0x60, 839 .osc_clk = 20 840 }; 841 static struct stv0367_config netup_stv0367_config[] = { 842 { 843 .demod_address = 0x1c, 844 .xtal = 27000000, 845 .if_khz = 4500, 846 .if_iq_mode = 0, 847 .ts_mode = 1, 848 .clk_pol = 0, 849 }, { 850 .demod_address = 0x1d, 851 .xtal = 27000000, 852 .if_khz = 4500, 853 .if_iq_mode = 0, 854 .ts_mode = 1, 855 .clk_pol = 0, 856 }, 857 }; 858 859 static struct xc5000_config netup_xc5000_config[] = { 860 { 861 .i2c_address = 0x61, 862 .if_khz = 4500, 863 }, { 864 .i2c_address = 0x64, 865 .if_khz = 4500, 866 }, 867 }; 868 869 static struct drxk_config terratec_drxk_config[] = { 870 { 871 .adr = 0x29, 872 .no_i2c_bridge = 1, 873 }, { 874 .adr = 0x2a, 875 .no_i2c_bridge = 1, 876 }, 877 }; 878 879 static struct mt2063_config terratec_mt2063_config[] = { 880 { 881 .tuner_address = 0x60, 882 }, { 883 .tuner_address = 0x67, 884 }, 885 }; 886 887 static const struct tda10071_platform_data hauppauge_tda10071_pdata = { 888 .clk = 40444000, /* 40.444 MHz */ 889 .i2c_wr_max = 64, 890 .ts_mode = TDA10071_TS_SERIAL, 891 .pll_multiplier = 20, 892 .tuner_i2c_addr = 0x54, 893 }; 894 895 static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = { 896 .i2c_addr = 0x68, 897 .clock = 27000000, 898 .i2c_wr_max = 33, 899 .clock_out = 0, 900 .ts_mode = M88DS3103_TS_PARALLEL, 901 .ts_clk = 16000, 902 .ts_clk_pol = 1, 903 .lnb_en_pol = 1, 904 .lnb_hv_pol = 0, 905 .agc = 0x99, 906 }; 907 908 static const struct m88ds3103_config dvbsky_s950c_m88ds3103_config = { 909 .i2c_addr = 0x68, 910 .clock = 27000000, 911 .i2c_wr_max = 33, 912 .clock_out = 0, 913 .ts_mode = M88DS3103_TS_CI, 914 .ts_clk = 10000, 915 .ts_clk_pol = 1, 916 .lnb_en_pol = 1, 917 .lnb_hv_pol = 0, 918 .agc = 0x99, 919 }; 920 921 static const struct m88ds3103_config dvbsky_s952_portc_m88ds3103_config = { 922 .i2c_addr = 0x68, 923 .clock = 27000000, 924 .i2c_wr_max = 33, 925 .clock_out = 0, 926 .ts_mode = M88DS3103_TS_SERIAL, 927 .ts_clk = 96000, 928 .ts_clk_pol = 0, 929 .lnb_en_pol = 1, 930 .lnb_hv_pol = 0, 931 .agc = 0x99, 932 }; 933 934 static const struct m88ds3103_config hauppauge_hvr5525_m88ds3103_config = { 935 .i2c_addr = 0x69, 936 .clock = 27000000, 937 .i2c_wr_max = 33, 938 .ts_mode = M88DS3103_TS_PARALLEL, 939 .ts_clk = 16000, 940 .ts_clk_pol = 1, 941 .agc = 0x99, 942 }; 943 944 static int netup_altera_fpga_rw(void *device, int flag, int data, int read) 945 { 946 struct cx23885_dev *dev = (struct cx23885_dev *)device; 947 unsigned long timeout = jiffies + msecs_to_jiffies(1); 948 uint32_t mem = 0; 949 950 mem = cx_read(MC417_RWD); 951 if (read) 952 cx_set(MC417_OEN, ALT_DATA); 953 else { 954 cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */ 955 mem &= ~ALT_DATA; 956 mem |= (data & ALT_DATA); 957 } 958 959 if (flag) 960 mem |= ALT_AD_RG; 961 else 962 mem &= ~ALT_AD_RG; 963 964 mem &= ~ALT_CS; 965 if (read) 966 mem = (mem & ~ALT_RD) | ALT_WR; 967 else 968 mem = (mem & ~ALT_WR) | ALT_RD; 969 970 cx_write(MC417_RWD, mem); /* start RW cycle */ 971 972 for (;;) { 973 mem = cx_read(MC417_RWD); 974 if ((mem & ALT_RDY) == 0) 975 break; 976 if (time_after(jiffies, timeout)) 977 break; 978 udelay(1); 979 } 980 981 cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS); 982 if (read) 983 return mem & ALT_DATA; 984 985 return 0; 986 }; 987 988 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff) 989 { 990 struct dib7000p_ops *dib7000p_ops = fe->sec_priv; 991 992 return dib7000p_ops->set_gpio(fe, 8, 0, !onoff); 993 } 994 995 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff) 996 { 997 return 0; 998 } 999 1000 static struct dib0070_config dib7070p_dib0070_config = { 1001 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS, 1002 .reset = dib7070_tuner_reset, 1003 .sleep = dib7070_tuner_sleep, 1004 .clock_khz = 12000, 1005 .freq_offset_khz_vhf = 550, 1006 /* .flip_chip = 1, */ 1007 }; 1008 1009 /* DIB7070 generic */ 1010 static struct dibx000_agc_config dib7070_agc_config = { 1011 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND, 1012 1013 /* 1014 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, 1015 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0, 1016 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 1017 */ 1018 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | 1019 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), 1020 .inv_gain = 600, 1021 .time_stabiliz = 10, 1022 .alpha_level = 0, 1023 .thlock = 118, 1024 .wbd_inv = 0, 1025 .wbd_ref = 3530, 1026 .wbd_sel = 1, 1027 .wbd_alpha = 5, 1028 .agc1_max = 65535, 1029 .agc1_min = 0, 1030 .agc2_max = 65535, 1031 .agc2_min = 0, 1032 .agc1_pt1 = 0, 1033 .agc1_pt2 = 40, 1034 .agc1_pt3 = 183, 1035 .agc1_slope1 = 206, 1036 .agc1_slope2 = 255, 1037 .agc2_pt1 = 72, 1038 .agc2_pt2 = 152, 1039 .agc2_slope1 = 88, 1040 .agc2_slope2 = 90, 1041 .alpha_mant = 17, 1042 .alpha_exp = 27, 1043 .beta_mant = 23, 1044 .beta_exp = 51, 1045 .perform_agc_softsplit = 0, 1046 }; 1047 1048 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = { 1049 .internal = 60000, 1050 .sampling = 15000, 1051 .pll_prediv = 1, 1052 .pll_ratio = 20, 1053 .pll_range = 3, 1054 .pll_reset = 1, 1055 .pll_bypass = 0, 1056 .enable_refdiv = 0, 1057 .bypclk_div = 0, 1058 .IO_CLK_en_core = 1, 1059 .ADClkSrc = 1, 1060 .modulo = 2, 1061 /* refsel, sel, freq_15k */ 1062 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0), 1063 .ifreq = (0 << 25) | 0, 1064 .timf = 20452225, 1065 .xtal_hz = 12000000, 1066 }; 1067 1068 static struct dib7000p_config dib7070p_dib7000p_config = { 1069 /* .output_mode = OUTMODE_MPEG2_FIFO, */ 1070 .output_mode = OUTMODE_MPEG2_SERIAL, 1071 /* .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK, */ 1072 .output_mpeg2_in_188_bytes = 1, 1073 1074 .agc_config_count = 1, 1075 .agc = &dib7070_agc_config, 1076 .bw = &dib7070_bw_config_12_mhz, 1077 .tuner_is_baseband = 1, 1078 .spur_protect = 1, 1079 1080 .gpio_dir = 0xfcef, /* DIB7000P_GPIO_DEFAULT_DIRECTIONS, */ 1081 .gpio_val = 0x0110, /* DIB7000P_GPIO_DEFAULT_VALUES, */ 1082 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS, 1083 1084 .hostbus_diversity = 1, 1085 }; 1086 1087 static int dvb_register_ci_mac(struct cx23885_tsport *port) 1088 { 1089 struct cx23885_dev *dev = port->dev; 1090 struct i2c_client *client_ci = NULL; 1091 struct vb2_dvb_frontend *fe0; 1092 1093 fe0 = vb2_dvb_get_frontend(&port->frontends, 1); 1094 if (!fe0) 1095 return -EINVAL; 1096 1097 switch (dev->board) { 1098 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: { 1099 static struct netup_card_info cinfo; 1100 1101 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo); 1102 memcpy(port->frontends.adapter.proposed_mac, 1103 cinfo.port[port->nr - 1].mac, 6); 1104 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n", 1105 port->nr, port->frontends.adapter.proposed_mac); 1106 1107 netup_ci_init(port); 1108 return 0; 1109 } 1110 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: { 1111 struct altera_ci_config netup_ci_cfg = { 1112 .dev = dev,/* magic number to identify*/ 1113 .adapter = &port->frontends.adapter,/* for CI */ 1114 .demux = &fe0->dvb.demux,/* for hw pid filter */ 1115 .fpga_rw = netup_altera_fpga_rw, 1116 }; 1117 1118 altera_ci_init(&netup_ci_cfg, port->nr); 1119 return 0; 1120 } 1121 case CX23885_BOARD_TEVII_S470: { 1122 u8 eeprom[256]; /* 24C02 i2c eeprom */ 1123 1124 if (port->nr != 1) 1125 return 0; 1126 1127 /* Read entire EEPROM */ 1128 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; 1129 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom)); 1130 printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0); 1131 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6); 1132 return 0; 1133 } 1134 case CX23885_BOARD_DVBSKY_T9580: 1135 case CX23885_BOARD_DVBSKY_S950: 1136 case CX23885_BOARD_DVBSKY_S952: 1137 case CX23885_BOARD_DVBSKY_T982: { 1138 u8 eeprom[256]; /* 24C02 i2c eeprom */ 1139 1140 if (port->nr > 2) 1141 return 0; 1142 1143 /* Read entire EEPROM */ 1144 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; 1145 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, 1146 sizeof(eeprom)); 1147 printk(KERN_INFO "%s port %d MAC address: %pM\n", 1148 cx23885_boards[dev->board].name, port->nr, 1149 eeprom + 0xc0 + (port->nr-1) * 8); 1150 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 + 1151 (port->nr-1) * 8, 6); 1152 return 0; 1153 } 1154 case CX23885_BOARD_DVBSKY_S950C: 1155 case CX23885_BOARD_DVBSKY_T980C: 1156 case CX23885_BOARD_TT_CT2_4500_CI: { 1157 u8 eeprom[256]; /* 24C02 i2c eeprom */ 1158 struct sp2_config sp2_config; 1159 struct i2c_board_info info; 1160 struct cx23885_i2c *i2c_bus = &dev->i2c_bus[0]; 1161 1162 /* attach CI */ 1163 memset(&sp2_config, 0, sizeof(sp2_config)); 1164 sp2_config.dvb_adap = &port->frontends.adapter; 1165 sp2_config.priv = port; 1166 sp2_config.ci_control = cx23885_sp2_ci_ctrl; 1167 memset(&info, 0, sizeof(struct i2c_board_info)); 1168 strlcpy(info.type, "sp2", I2C_NAME_SIZE); 1169 info.addr = 0x40; 1170 info.platform_data = &sp2_config; 1171 request_module(info.type); 1172 client_ci = i2c_new_device(&i2c_bus->i2c_adap, &info); 1173 if (client_ci == NULL || client_ci->dev.driver == NULL) 1174 return -ENODEV; 1175 if (!try_module_get(client_ci->dev.driver->owner)) { 1176 i2c_unregister_device(client_ci); 1177 return -ENODEV; 1178 } 1179 port->i2c_client_ci = client_ci; 1180 1181 if (port->nr != 1) 1182 return 0; 1183 1184 /* Read entire EEPROM */ 1185 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; 1186 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, 1187 sizeof(eeprom)); 1188 printk(KERN_INFO "%s MAC address: %pM\n", 1189 cx23885_boards[dev->board].name, eeprom + 0xc0); 1190 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6); 1191 return 0; 1192 } 1193 } 1194 return 0; 1195 } 1196 1197 static int dvb_register(struct cx23885_tsport *port) 1198 { 1199 struct dib7000p_ops dib7000p_ops; 1200 struct cx23885_dev *dev = port->dev; 1201 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL; 1202 struct vb2_dvb_frontend *fe0, *fe1 = NULL; 1203 struct si2168_config si2168_config; 1204 struct si2165_platform_data si2165_pdata; 1205 struct si2157_config si2157_config; 1206 struct ts2020_config ts2020_config; 1207 struct i2c_board_info info; 1208 struct i2c_adapter *adapter; 1209 struct i2c_client *client_demod = NULL, *client_tuner = NULL; 1210 struct i2c_client *client_sec = NULL; 1211 const struct m88ds3103_config *p_m88ds3103_config = NULL; 1212 int (*p_set_voltage)(struct dvb_frontend *fe, 1213 enum fe_sec_voltage voltage) = NULL; 1214 int mfe_shared = 0; /* bus not shared by default */ 1215 int ret; 1216 1217 /* Get the first frontend */ 1218 fe0 = vb2_dvb_get_frontend(&port->frontends, 1); 1219 if (!fe0) 1220 return -EINVAL; 1221 1222 /* init struct vb2_dvb */ 1223 fe0->dvb.name = dev->name; 1224 1225 /* multi-frontend gate control is undefined or defaults to fe0 */ 1226 port->frontends.gate = 0; 1227 1228 /* Sets the gate control callback to be used by i2c command calls */ 1229 port->gate_ctrl = cx23885_dvb_gate_ctrl; 1230 1231 /* init frontend */ 1232 switch (dev->board) { 1233 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1234 i2c_bus = &dev->i2c_bus[0]; 1235 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1236 &hauppauge_generic_config, 1237 &i2c_bus->i2c_adap); 1238 if (fe0->dvb.frontend == NULL) 1239 break; 1240 dvb_attach(mt2131_attach, fe0->dvb.frontend, 1241 &i2c_bus->i2c_adap, 1242 &hauppauge_generic_tunerconfig, 0); 1243 break; 1244 case CX23885_BOARD_HAUPPAUGE_HVR1270: 1245 case CX23885_BOARD_HAUPPAUGE_HVR1275: 1246 i2c_bus = &dev->i2c_bus[0]; 1247 fe0->dvb.frontend = dvb_attach(lgdt3305_attach, 1248 &hauppauge_lgdt3305_config, 1249 &i2c_bus->i2c_adap); 1250 if (fe0->dvb.frontend == NULL) 1251 break; 1252 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1253 0x60, &dev->i2c_bus[1].i2c_adap, 1254 &hauppauge_hvr127x_config); 1255 if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1275) 1256 cx23885_set_frontend_hook(port, fe0->dvb.frontend); 1257 break; 1258 case CX23885_BOARD_HAUPPAUGE_HVR1255: 1259 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111: 1260 i2c_bus = &dev->i2c_bus[0]; 1261 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 1262 &hcw_s5h1411_config, 1263 &i2c_bus->i2c_adap); 1264 if (fe0->dvb.frontend == NULL) 1265 break; 1266 1267 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1268 0x60, &dev->i2c_bus[1].i2c_adap, 1269 &hauppauge_tda18271_config); 1270 1271 tda18271_attach(&dev->ts1.analog_fe, 1272 0x60, &dev->i2c_bus[1].i2c_adap, 1273 &hauppauge_tda18271_config); 1274 1275 break; 1276 case CX23885_BOARD_HAUPPAUGE_HVR1800: 1277 i2c_bus = &dev->i2c_bus[0]; 1278 switch (alt_tuner) { 1279 case 1: 1280 fe0->dvb.frontend = 1281 dvb_attach(s5h1409_attach, 1282 &hauppauge_ezqam_config, 1283 &i2c_bus->i2c_adap); 1284 if (fe0->dvb.frontend == NULL) 1285 break; 1286 1287 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1288 &dev->i2c_bus[1].i2c_adap, 0x42, 1289 &tda829x_no_probe); 1290 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1291 0x60, &dev->i2c_bus[1].i2c_adap, 1292 &hauppauge_tda18271_config); 1293 break; 1294 case 0: 1295 default: 1296 fe0->dvb.frontend = 1297 dvb_attach(s5h1409_attach, 1298 &hauppauge_generic_config, 1299 &i2c_bus->i2c_adap); 1300 if (fe0->dvb.frontend == NULL) 1301 break; 1302 dvb_attach(mt2131_attach, fe0->dvb.frontend, 1303 &i2c_bus->i2c_adap, 1304 &hauppauge_generic_tunerconfig, 0); 1305 } 1306 break; 1307 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 1308 i2c_bus = &dev->i2c_bus[0]; 1309 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1310 &hauppauge_hvr1800lp_config, 1311 &i2c_bus->i2c_adap); 1312 if (fe0->dvb.frontend == NULL) 1313 break; 1314 dvb_attach(mt2131_attach, fe0->dvb.frontend, 1315 &i2c_bus->i2c_adap, 1316 &hauppauge_generic_tunerconfig, 0); 1317 break; 1318 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP: 1319 i2c_bus = &dev->i2c_bus[0]; 1320 fe0->dvb.frontend = dvb_attach(lgdt330x_attach, 1321 &fusionhdtv_5_express, 1322 &i2c_bus->i2c_adap); 1323 if (fe0->dvb.frontend == NULL) 1324 break; 1325 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1326 &i2c_bus->i2c_adap, 0x61, 1327 TUNER_LG_TDVS_H06XF); 1328 break; 1329 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 1330 i2c_bus = &dev->i2c_bus[1]; 1331 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1332 &hauppauge_hvr1500q_config, 1333 &dev->i2c_bus[0].i2c_adap); 1334 if (fe0->dvb.frontend == NULL) 1335 break; 1336 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1337 &i2c_bus->i2c_adap, 1338 &hauppauge_hvr1500q_tunerconfig); 1339 break; 1340 case CX23885_BOARD_HAUPPAUGE_HVR1500: 1341 i2c_bus = &dev->i2c_bus[1]; 1342 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1343 &hauppauge_hvr1500_config, 1344 &dev->i2c_bus[0].i2c_adap); 1345 if (fe0->dvb.frontend != NULL) { 1346 struct dvb_frontend *fe; 1347 struct xc2028_config cfg = { 1348 .i2c_adap = &i2c_bus->i2c_adap, 1349 .i2c_addr = 0x61, 1350 }; 1351 static struct xc2028_ctrl ctl = { 1352 .fname = XC2028_DEFAULT_FIRMWARE, 1353 .max_len = 64, 1354 .demod = XC3028_FE_OREN538, 1355 }; 1356 1357 fe = dvb_attach(xc2028_attach, 1358 fe0->dvb.frontend, &cfg); 1359 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL) 1360 fe->ops.tuner_ops.set_config(fe, &ctl); 1361 } 1362 break; 1363 case CX23885_BOARD_HAUPPAUGE_HVR1200: 1364 case CX23885_BOARD_HAUPPAUGE_HVR1700: 1365 i2c_bus = &dev->i2c_bus[0]; 1366 fe0->dvb.frontend = dvb_attach(tda10048_attach, 1367 &hauppauge_hvr1200_config, 1368 &i2c_bus->i2c_adap); 1369 if (fe0->dvb.frontend == NULL) 1370 break; 1371 dvb_attach(tda829x_attach, fe0->dvb.frontend, 1372 &dev->i2c_bus[1].i2c_adap, 0x42, 1373 &tda829x_no_probe); 1374 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1375 0x60, &dev->i2c_bus[1].i2c_adap, 1376 &hauppauge_hvr1200_tuner_config); 1377 break; 1378 case CX23885_BOARD_HAUPPAUGE_HVR1210: 1379 i2c_bus = &dev->i2c_bus[0]; 1380 fe0->dvb.frontend = dvb_attach(tda10048_attach, 1381 &hauppauge_hvr1210_config, 1382 &i2c_bus->i2c_adap); 1383 if (fe0->dvb.frontend != NULL) { 1384 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1385 0x60, &dev->i2c_bus[1].i2c_adap, 1386 &hauppauge_hvr1210_tuner_config); 1387 } 1388 break; 1389 case CX23885_BOARD_HAUPPAUGE_HVR1400: 1390 i2c_bus = &dev->i2c_bus[0]; 1391 1392 if (!dvb_attach(dib7000p_attach, &dib7000p_ops)) 1393 return -ENODEV; 1394 1395 fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap, 1396 0x12, &hauppauge_hvr1400_dib7000_config); 1397 if (fe0->dvb.frontend != NULL) { 1398 struct dvb_frontend *fe; 1399 struct xc2028_config cfg = { 1400 .i2c_adap = &dev->i2c_bus[1].i2c_adap, 1401 .i2c_addr = 0x64, 1402 }; 1403 static struct xc2028_ctrl ctl = { 1404 .fname = XC3028L_DEFAULT_FIRMWARE, 1405 .max_len = 64, 1406 .demod = XC3028_FE_DIBCOM52, 1407 /* This is true for all demods with 1408 v36 firmware? */ 1409 .type = XC2028_D2633, 1410 }; 1411 1412 fe = dvb_attach(xc2028_attach, 1413 fe0->dvb.frontend, &cfg); 1414 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL) 1415 fe->ops.tuner_ops.set_config(fe, &ctl); 1416 } 1417 break; 1418 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP: 1419 i2c_bus = &dev->i2c_bus[port->nr - 1]; 1420 1421 fe0->dvb.frontend = dvb_attach(s5h1409_attach, 1422 &dvico_s5h1409_config, 1423 &i2c_bus->i2c_adap); 1424 if (fe0->dvb.frontend == NULL) 1425 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 1426 &dvico_s5h1411_config, 1427 &i2c_bus->i2c_adap); 1428 if (fe0->dvb.frontend != NULL) 1429 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1430 &i2c_bus->i2c_adap, 1431 &dvico_xc5000_tunerconfig); 1432 break; 1433 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: { 1434 i2c_bus = &dev->i2c_bus[port->nr - 1]; 1435 1436 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1437 &dvico_fusionhdtv_xc3028, 1438 &i2c_bus->i2c_adap); 1439 if (fe0->dvb.frontend != NULL) { 1440 struct dvb_frontend *fe; 1441 struct xc2028_config cfg = { 1442 .i2c_adap = &i2c_bus->i2c_adap, 1443 .i2c_addr = 0x61, 1444 }; 1445 static struct xc2028_ctrl ctl = { 1446 .fname = XC2028_DEFAULT_FIRMWARE, 1447 .max_len = 64, 1448 .demod = XC3028_FE_ZARLINK456, 1449 }; 1450 1451 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, 1452 &cfg); 1453 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL) 1454 fe->ops.tuner_ops.set_config(fe, &ctl); 1455 } 1456 break; 1457 } 1458 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2: { 1459 i2c_bus = &dev->i2c_bus[port->nr - 1]; 1460 /* cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); */ 1461 /* cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1); */ 1462 1463 if (!dvb_attach(dib7000p_attach, &dib7000p_ops)) 1464 return -ENODEV; 1465 1466 if (dib7000p_ops.i2c_enumeration(&i2c_bus->i2c_adap, 1, 0x12, &dib7070p_dib7000p_config) < 0) { 1467 printk(KERN_WARNING "Unable to enumerate dib7000p\n"); 1468 return -ENODEV; 1469 } 1470 fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap, 0x80, &dib7070p_dib7000p_config); 1471 if (fe0->dvb.frontend != NULL) { 1472 struct i2c_adapter *tun_i2c; 1473 1474 fe0->dvb.frontend->sec_priv = kmalloc(sizeof(dib7000p_ops), GFP_KERNEL); 1475 memcpy(fe0->dvb.frontend->sec_priv, &dib7000p_ops, sizeof(dib7000p_ops)); 1476 tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1); 1477 if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config)) 1478 return -ENODEV; 1479 } 1480 break; 1481 } 1482 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 1483 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 1484 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 1485 i2c_bus = &dev->i2c_bus[0]; 1486 1487 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1488 &dvico_fusionhdtv_xc3028, 1489 &i2c_bus->i2c_adap); 1490 if (fe0->dvb.frontend != NULL) { 1491 struct dvb_frontend *fe; 1492 struct xc2028_config cfg = { 1493 .i2c_adap = &dev->i2c_bus[1].i2c_adap, 1494 .i2c_addr = 0x61, 1495 }; 1496 static struct xc2028_ctrl ctl = { 1497 .fname = XC2028_DEFAULT_FIRMWARE, 1498 .max_len = 64, 1499 .demod = XC3028_FE_ZARLINK456, 1500 }; 1501 1502 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, 1503 &cfg); 1504 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL) 1505 fe->ops.tuner_ops.set_config(fe, &ctl); 1506 } 1507 break; 1508 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000: 1509 i2c_bus = &dev->i2c_bus[0]; 1510 1511 fe0->dvb.frontend = dvb_attach(zl10353_attach, 1512 &dvico_fusionhdtv_xc3028, 1513 &i2c_bus->i2c_adap); 1514 if (fe0->dvb.frontend != NULL) { 1515 struct dvb_frontend *fe; 1516 struct xc4000_config cfg = { 1517 .i2c_address = 0x61, 1518 .default_pm = 0, 1519 .dvb_amplitude = 134, 1520 .set_smoothedcvbs = 1, 1521 .if_khz = 4560 1522 }; 1523 1524 fe = dvb_attach(xc4000_attach, fe0->dvb.frontend, 1525 &dev->i2c_bus[1].i2c_adap, &cfg); 1526 if (!fe) { 1527 printk(KERN_ERR "%s/2: xc4000 attach failed\n", 1528 dev->name); 1529 goto frontend_detach; 1530 } 1531 } 1532 break; 1533 case CX23885_BOARD_TBS_6920: 1534 i2c_bus = &dev->i2c_bus[1]; 1535 1536 fe0->dvb.frontend = dvb_attach(cx24116_attach, 1537 &tbs_cx24116_config, 1538 &i2c_bus->i2c_adap); 1539 if (fe0->dvb.frontend != NULL) 1540 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage; 1541 1542 break; 1543 case CX23885_BOARD_TBS_6980: 1544 case CX23885_BOARD_TBS_6981: 1545 i2c_bus = &dev->i2c_bus[1]; 1546 1547 switch (port->nr) { 1548 /* PORT B */ 1549 case 1: 1550 fe0->dvb.frontend = dvb_attach(cx24117_attach, 1551 &tbs_cx24117_config, 1552 &i2c_bus->i2c_adap); 1553 break; 1554 /* PORT C */ 1555 case 2: 1556 fe0->dvb.frontend = dvb_attach(cx24117_attach, 1557 &tbs_cx24117_config, 1558 &i2c_bus->i2c_adap); 1559 break; 1560 } 1561 break; 1562 case CX23885_BOARD_TEVII_S470: 1563 i2c_bus = &dev->i2c_bus[1]; 1564 1565 fe0->dvb.frontend = dvb_attach(ds3000_attach, 1566 &tevii_ds3000_config, 1567 &i2c_bus->i2c_adap); 1568 if (fe0->dvb.frontend != NULL) { 1569 dvb_attach(ts2020_attach, fe0->dvb.frontend, 1570 &tevii_ts2020_config, &i2c_bus->i2c_adap); 1571 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage; 1572 } 1573 1574 break; 1575 case CX23885_BOARD_DVBWORLD_2005: 1576 i2c_bus = &dev->i2c_bus[1]; 1577 1578 fe0->dvb.frontend = dvb_attach(cx24116_attach, 1579 &dvbworld_cx24116_config, 1580 &i2c_bus->i2c_adap); 1581 break; 1582 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: 1583 i2c_bus = &dev->i2c_bus[0]; 1584 switch (port->nr) { 1585 /* port B */ 1586 case 1: 1587 fe0->dvb.frontend = dvb_attach(stv0900_attach, 1588 &netup_stv0900_config, 1589 &i2c_bus->i2c_adap, 0); 1590 if (fe0->dvb.frontend != NULL) { 1591 if (dvb_attach(stv6110_attach, 1592 fe0->dvb.frontend, 1593 &netup_stv6110_tunerconfig_a, 1594 &i2c_bus->i2c_adap)) { 1595 if (!dvb_attach(lnbh24_attach, 1596 fe0->dvb.frontend, 1597 &i2c_bus->i2c_adap, 1598 LNBH24_PCL | LNBH24_TTX, 1599 LNBH24_TEN, 0x09)) 1600 printk(KERN_ERR 1601 "No LNBH24 found!\n"); 1602 1603 } 1604 } 1605 break; 1606 /* port C */ 1607 case 2: 1608 fe0->dvb.frontend = dvb_attach(stv0900_attach, 1609 &netup_stv0900_config, 1610 &i2c_bus->i2c_adap, 1); 1611 if (fe0->dvb.frontend != NULL) { 1612 if (dvb_attach(stv6110_attach, 1613 fe0->dvb.frontend, 1614 &netup_stv6110_tunerconfig_b, 1615 &i2c_bus->i2c_adap)) { 1616 if (!dvb_attach(lnbh24_attach, 1617 fe0->dvb.frontend, 1618 &i2c_bus->i2c_adap, 1619 LNBH24_PCL | LNBH24_TTX, 1620 LNBH24_TEN, 0x0a)) 1621 printk(KERN_ERR 1622 "No LNBH24 found!\n"); 1623 1624 } 1625 } 1626 break; 1627 } 1628 break; 1629 case CX23885_BOARD_MYGICA_X8506: 1630 i2c_bus = &dev->i2c_bus[0]; 1631 i2c_bus2 = &dev->i2c_bus[1]; 1632 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach, 1633 &mygica_x8506_lgs8gl5_config, 1634 &i2c_bus->i2c_adap); 1635 if (fe0->dvb.frontend == NULL) 1636 break; 1637 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1638 &i2c_bus2->i2c_adap, &mygica_x8506_xc5000_config); 1639 cx23885_set_frontend_hook(port, fe0->dvb.frontend); 1640 break; 1641 case CX23885_BOARD_MYGICA_X8507: 1642 i2c_bus = &dev->i2c_bus[0]; 1643 i2c_bus2 = &dev->i2c_bus[1]; 1644 fe0->dvb.frontend = dvb_attach(mb86a20s_attach, 1645 &mygica_x8507_mb86a20s_config, 1646 &i2c_bus->i2c_adap); 1647 if (fe0->dvb.frontend == NULL) 1648 break; 1649 1650 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1651 &i2c_bus2->i2c_adap, 1652 &mygica_x8507_xc5000_config); 1653 cx23885_set_frontend_hook(port, fe0->dvb.frontend); 1654 break; 1655 case CX23885_BOARD_MAGICPRO_PROHDTVE2: 1656 i2c_bus = &dev->i2c_bus[0]; 1657 i2c_bus2 = &dev->i2c_bus[1]; 1658 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach, 1659 &magicpro_prohdtve2_lgs8g75_config, 1660 &i2c_bus->i2c_adap); 1661 if (fe0->dvb.frontend == NULL) 1662 break; 1663 dvb_attach(xc5000_attach, fe0->dvb.frontend, 1664 &i2c_bus2->i2c_adap, 1665 &magicpro_prohdtve2_xc5000_config); 1666 cx23885_set_frontend_hook(port, fe0->dvb.frontend); 1667 break; 1668 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1669 i2c_bus = &dev->i2c_bus[0]; 1670 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 1671 &hcw_s5h1411_config, 1672 &i2c_bus->i2c_adap); 1673 if (fe0->dvb.frontend == NULL) 1674 break; 1675 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1676 0x60, &dev->i2c_bus[0].i2c_adap, 1677 &hauppauge_tda18271_config); 1678 1679 tda18271_attach(&dev->ts1.analog_fe, 1680 0x60, &dev->i2c_bus[1].i2c_adap, 1681 &hauppauge_tda18271_config); 1682 1683 break; 1684 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1685 i2c_bus = &dev->i2c_bus[0]; 1686 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 1687 &hcw_s5h1411_config, 1688 &i2c_bus->i2c_adap); 1689 if (fe0->dvb.frontend == NULL) 1690 break; 1691 dvb_attach(tda18271_attach, fe0->dvb.frontend, 1692 0x60, &dev->i2c_bus[0].i2c_adap, 1693 &hauppauge_tda18271_config); 1694 break; 1695 case CX23885_BOARD_MYGICA_X8558PRO: 1696 switch (port->nr) { 1697 /* port B */ 1698 case 1: 1699 i2c_bus = &dev->i2c_bus[0]; 1700 fe0->dvb.frontend = dvb_attach(atbm8830_attach, 1701 &mygica_x8558pro_atbm8830_cfg1, 1702 &i2c_bus->i2c_adap); 1703 if (fe0->dvb.frontend == NULL) 1704 break; 1705 dvb_attach(max2165_attach, fe0->dvb.frontend, 1706 &i2c_bus->i2c_adap, 1707 &mygic_x8558pro_max2165_cfg1); 1708 break; 1709 /* port C */ 1710 case 2: 1711 i2c_bus = &dev->i2c_bus[1]; 1712 fe0->dvb.frontend = dvb_attach(atbm8830_attach, 1713 &mygica_x8558pro_atbm8830_cfg2, 1714 &i2c_bus->i2c_adap); 1715 if (fe0->dvb.frontend == NULL) 1716 break; 1717 dvb_attach(max2165_attach, fe0->dvb.frontend, 1718 &i2c_bus->i2c_adap, 1719 &mygic_x8558pro_max2165_cfg2); 1720 } 1721 break; 1722 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: 1723 if (port->nr > 2) 1724 return 0; 1725 1726 i2c_bus = &dev->i2c_bus[0]; 1727 mfe_shared = 1;/* MFE */ 1728 port->frontends.gate = 0;/* not clear for me yet */ 1729 /* ports B, C */ 1730 /* MFE frontend 1 DVB-T */ 1731 fe0->dvb.frontend = dvb_attach(stv0367ter_attach, 1732 &netup_stv0367_config[port->nr - 1], 1733 &i2c_bus->i2c_adap); 1734 if (fe0->dvb.frontend == NULL) 1735 break; 1736 if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend, 1737 &i2c_bus->i2c_adap, 1738 &netup_xc5000_config[port->nr - 1])) 1739 goto frontend_detach; 1740 /* load xc5000 firmware */ 1741 fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend); 1742 1743 /* MFE frontend 2 */ 1744 fe1 = vb2_dvb_get_frontend(&port->frontends, 2); 1745 if (fe1 == NULL) 1746 goto frontend_detach; 1747 /* DVB-C init */ 1748 fe1->dvb.frontend = dvb_attach(stv0367cab_attach, 1749 &netup_stv0367_config[port->nr - 1], 1750 &i2c_bus->i2c_adap); 1751 if (fe1->dvb.frontend == NULL) 1752 break; 1753 1754 fe1->dvb.frontend->id = 1; 1755 if (NULL == dvb_attach(xc5000_attach, 1756 fe1->dvb.frontend, 1757 &i2c_bus->i2c_adap, 1758 &netup_xc5000_config[port->nr - 1])) 1759 goto frontend_detach; 1760 break; 1761 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1762 i2c_bus = &dev->i2c_bus[0]; 1763 i2c_bus2 = &dev->i2c_bus[1]; 1764 1765 switch (port->nr) { 1766 /* port b */ 1767 case 1: 1768 fe0->dvb.frontend = dvb_attach(drxk_attach, 1769 &terratec_drxk_config[0], 1770 &i2c_bus->i2c_adap); 1771 if (fe0->dvb.frontend == NULL) 1772 break; 1773 if (!dvb_attach(mt2063_attach, 1774 fe0->dvb.frontend, 1775 &terratec_mt2063_config[0], 1776 &i2c_bus2->i2c_adap)) 1777 goto frontend_detach; 1778 break; 1779 /* port c */ 1780 case 2: 1781 fe0->dvb.frontend = dvb_attach(drxk_attach, 1782 &terratec_drxk_config[1], 1783 &i2c_bus->i2c_adap); 1784 if (fe0->dvb.frontend == NULL) 1785 break; 1786 if (!dvb_attach(mt2063_attach, 1787 fe0->dvb.frontend, 1788 &terratec_mt2063_config[1], 1789 &i2c_bus2->i2c_adap)) 1790 goto frontend_detach; 1791 break; 1792 } 1793 break; 1794 case CX23885_BOARD_TEVII_S471: 1795 i2c_bus = &dev->i2c_bus[1]; 1796 1797 fe0->dvb.frontend = dvb_attach(ds3000_attach, 1798 &tevii_ds3000_config, 1799 &i2c_bus->i2c_adap); 1800 if (fe0->dvb.frontend == NULL) 1801 break; 1802 dvb_attach(ts2020_attach, fe0->dvb.frontend, 1803 &tevii_ts2020_config, &i2c_bus->i2c_adap); 1804 break; 1805 case CX23885_BOARD_PROF_8000: 1806 i2c_bus = &dev->i2c_bus[0]; 1807 1808 fe0->dvb.frontend = dvb_attach(stv090x_attach, 1809 &prof_8000_stv090x_config, 1810 &i2c_bus->i2c_adap, 1811 STV090x_DEMODULATOR_0); 1812 if (fe0->dvb.frontend == NULL) 1813 break; 1814 if (!dvb_attach(stb6100_attach, 1815 fe0->dvb.frontend, 1816 &prof_8000_stb6100_config, 1817 &i2c_bus->i2c_adap)) 1818 goto frontend_detach; 1819 1820 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage; 1821 break; 1822 case CX23885_BOARD_HAUPPAUGE_HVR4400: { 1823 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata; 1824 struct a8293_platform_data a8293_pdata = {}; 1825 1826 i2c_bus = &dev->i2c_bus[0]; 1827 i2c_bus2 = &dev->i2c_bus[1]; 1828 switch (port->nr) { 1829 /* port b */ 1830 case 1: 1831 /* attach demod + tuner combo */ 1832 memset(&info, 0, sizeof(info)); 1833 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE); 1834 info.addr = 0x05; 1835 info.platform_data = &tda10071_pdata; 1836 request_module("tda10071"); 1837 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 1838 if (!client_demod || !client_demod->dev.driver) 1839 goto frontend_detach; 1840 if (!try_module_get(client_demod->dev.driver->owner)) { 1841 i2c_unregister_device(client_demod); 1842 goto frontend_detach; 1843 } 1844 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod); 1845 port->i2c_client_demod = client_demod; 1846 1847 /* attach SEC */ 1848 a8293_pdata.dvb_frontend = fe0->dvb.frontend; 1849 memset(&info, 0, sizeof(info)); 1850 strlcpy(info.type, "a8293", I2C_NAME_SIZE); 1851 info.addr = 0x0b; 1852 info.platform_data = &a8293_pdata; 1853 request_module("a8293"); 1854 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info); 1855 if (!client_sec || !client_sec->dev.driver) 1856 goto frontend_detach; 1857 if (!try_module_get(client_sec->dev.driver->owner)) { 1858 i2c_unregister_device(client_sec); 1859 goto frontend_detach; 1860 } 1861 port->i2c_client_sec = client_sec; 1862 break; 1863 /* port c */ 1864 case 2: 1865 /* attach frontend */ 1866 memset(&si2165_pdata, 0, sizeof(si2165_pdata)); 1867 si2165_pdata.fe = &fe0->dvb.frontend; 1868 si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL, 1869 si2165_pdata.ref_freq_Hz = 16000000, 1870 memset(&info, 0, sizeof(struct i2c_board_info)); 1871 strlcpy(info.type, "si2165", I2C_NAME_SIZE); 1872 info.addr = 0x64; 1873 info.platform_data = &si2165_pdata; 1874 request_module(info.type); 1875 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 1876 if (client_demod == NULL || 1877 client_demod->dev.driver == NULL) 1878 goto frontend_detach; 1879 if (!try_module_get(client_demod->dev.driver->owner)) { 1880 i2c_unregister_device(client_demod); 1881 goto frontend_detach; 1882 } 1883 port->i2c_client_demod = client_demod; 1884 1885 if (fe0->dvb.frontend == NULL) 1886 break; 1887 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL; 1888 if (!dvb_attach(tda18271_attach, 1889 fe0->dvb.frontend, 1890 0x60, &i2c_bus2->i2c_adap, 1891 &hauppauge_hvr4400_tuner_config)) 1892 goto frontend_detach; 1893 break; 1894 } 1895 break; 1896 } 1897 case CX23885_BOARD_HAUPPAUGE_STARBURST: { 1898 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata; 1899 struct a8293_platform_data a8293_pdata = {}; 1900 1901 i2c_bus = &dev->i2c_bus[0]; 1902 1903 /* attach demod + tuner combo */ 1904 memset(&info, 0, sizeof(info)); 1905 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE); 1906 info.addr = 0x05; 1907 info.platform_data = &tda10071_pdata; 1908 request_module("tda10071"); 1909 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 1910 if (!client_demod || !client_demod->dev.driver) 1911 goto frontend_detach; 1912 if (!try_module_get(client_demod->dev.driver->owner)) { 1913 i2c_unregister_device(client_demod); 1914 goto frontend_detach; 1915 } 1916 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod); 1917 port->i2c_client_demod = client_demod; 1918 1919 /* attach SEC */ 1920 a8293_pdata.dvb_frontend = fe0->dvb.frontend; 1921 memset(&info, 0, sizeof(info)); 1922 strlcpy(info.type, "a8293", I2C_NAME_SIZE); 1923 info.addr = 0x0b; 1924 info.platform_data = &a8293_pdata; 1925 request_module("a8293"); 1926 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info); 1927 if (!client_sec || !client_sec->dev.driver) 1928 goto frontend_detach; 1929 if (!try_module_get(client_sec->dev.driver->owner)) { 1930 i2c_unregister_device(client_sec); 1931 goto frontend_detach; 1932 } 1933 port->i2c_client_sec = client_sec; 1934 break; 1935 } 1936 case CX23885_BOARD_DVBSKY_T9580: 1937 case CX23885_BOARD_DVBSKY_S950: 1938 i2c_bus = &dev->i2c_bus[0]; 1939 i2c_bus2 = &dev->i2c_bus[1]; 1940 switch (port->nr) { 1941 /* port b - satellite */ 1942 case 1: 1943 /* attach frontend */ 1944 fe0->dvb.frontend = dvb_attach(m88ds3103_attach, 1945 &dvbsky_t9580_m88ds3103_config, 1946 &i2c_bus2->i2c_adap, &adapter); 1947 if (fe0->dvb.frontend == NULL) 1948 break; 1949 1950 /* attach tuner */ 1951 memset(&ts2020_config, 0, sizeof(ts2020_config)); 1952 ts2020_config.fe = fe0->dvb.frontend; 1953 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm; 1954 memset(&info, 0, sizeof(struct i2c_board_info)); 1955 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 1956 info.addr = 0x60; 1957 info.platform_data = &ts2020_config; 1958 request_module(info.type); 1959 client_tuner = i2c_new_device(adapter, &info); 1960 if (client_tuner == NULL || 1961 client_tuner->dev.driver == NULL) 1962 goto frontend_detach; 1963 if (!try_module_get(client_tuner->dev.driver->owner)) { 1964 i2c_unregister_device(client_tuner); 1965 goto frontend_detach; 1966 } 1967 1968 /* delegate signal strength measurement to tuner */ 1969 fe0->dvb.frontend->ops.read_signal_strength = 1970 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength; 1971 1972 /* 1973 * for setting the voltage we need to set GPIOs on 1974 * the card. 1975 */ 1976 port->fe_set_voltage = 1977 fe0->dvb.frontend->ops.set_voltage; 1978 fe0->dvb.frontend->ops.set_voltage = 1979 dvbsky_t9580_set_voltage; 1980 1981 port->i2c_client_tuner = client_tuner; 1982 1983 break; 1984 /* port c - terrestrial/cable */ 1985 case 2: 1986 /* attach frontend */ 1987 memset(&si2168_config, 0, sizeof(si2168_config)); 1988 si2168_config.i2c_adapter = &adapter; 1989 si2168_config.fe = &fe0->dvb.frontend; 1990 si2168_config.ts_mode = SI2168_TS_SERIAL; 1991 memset(&info, 0, sizeof(struct i2c_board_info)); 1992 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 1993 info.addr = 0x64; 1994 info.platform_data = &si2168_config; 1995 request_module(info.type); 1996 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 1997 if (client_demod == NULL || 1998 client_demod->dev.driver == NULL) 1999 goto frontend_detach; 2000 if (!try_module_get(client_demod->dev.driver->owner)) { 2001 i2c_unregister_device(client_demod); 2002 goto frontend_detach; 2003 } 2004 port->i2c_client_demod = client_demod; 2005 2006 /* attach tuner */ 2007 memset(&si2157_config, 0, sizeof(si2157_config)); 2008 si2157_config.fe = fe0->dvb.frontend; 2009 si2157_config.if_port = 1; 2010 memset(&info, 0, sizeof(struct i2c_board_info)); 2011 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2012 info.addr = 0x60; 2013 info.platform_data = &si2157_config; 2014 request_module(info.type); 2015 client_tuner = i2c_new_device(adapter, &info); 2016 if (client_tuner == NULL || 2017 client_tuner->dev.driver == NULL) 2018 goto frontend_detach; 2019 2020 if (!try_module_get(client_tuner->dev.driver->owner)) { 2021 i2c_unregister_device(client_tuner); 2022 goto frontend_detach; 2023 } 2024 port->i2c_client_tuner = client_tuner; 2025 break; 2026 } 2027 break; 2028 case CX23885_BOARD_DVBSKY_T980C: 2029 case CX23885_BOARD_TT_CT2_4500_CI: 2030 i2c_bus = &dev->i2c_bus[0]; 2031 i2c_bus2 = &dev->i2c_bus[1]; 2032 2033 /* attach frontend */ 2034 memset(&si2168_config, 0, sizeof(si2168_config)); 2035 si2168_config.i2c_adapter = &adapter; 2036 si2168_config.fe = &fe0->dvb.frontend; 2037 si2168_config.ts_mode = SI2168_TS_PARALLEL; 2038 memset(&info, 0, sizeof(struct i2c_board_info)); 2039 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 2040 info.addr = 0x64; 2041 info.platform_data = &si2168_config; 2042 request_module(info.type); 2043 client_demod = i2c_new_device(&i2c_bus2->i2c_adap, &info); 2044 if (client_demod == NULL || client_demod->dev.driver == NULL) 2045 goto frontend_detach; 2046 if (!try_module_get(client_demod->dev.driver->owner)) { 2047 i2c_unregister_device(client_demod); 2048 goto frontend_detach; 2049 } 2050 port->i2c_client_demod = client_demod; 2051 2052 /* attach tuner */ 2053 memset(&si2157_config, 0, sizeof(si2157_config)); 2054 si2157_config.fe = fe0->dvb.frontend; 2055 si2157_config.if_port = 1; 2056 memset(&info, 0, sizeof(struct i2c_board_info)); 2057 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2058 info.addr = 0x60; 2059 info.platform_data = &si2157_config; 2060 request_module(info.type); 2061 client_tuner = i2c_new_device(adapter, &info); 2062 if (client_tuner == NULL || 2063 client_tuner->dev.driver == NULL) 2064 goto frontend_detach; 2065 if (!try_module_get(client_tuner->dev.driver->owner)) { 2066 i2c_unregister_device(client_tuner); 2067 goto frontend_detach; 2068 } 2069 port->i2c_client_tuner = client_tuner; 2070 break; 2071 case CX23885_BOARD_DVBSKY_S950C: 2072 i2c_bus = &dev->i2c_bus[0]; 2073 i2c_bus2 = &dev->i2c_bus[1]; 2074 2075 /* attach frontend */ 2076 fe0->dvb.frontend = dvb_attach(m88ds3103_attach, 2077 &dvbsky_s950c_m88ds3103_config, 2078 &i2c_bus2->i2c_adap, &adapter); 2079 if (fe0->dvb.frontend == NULL) 2080 break; 2081 2082 /* attach tuner */ 2083 memset(&ts2020_config, 0, sizeof(ts2020_config)); 2084 ts2020_config.fe = fe0->dvb.frontend; 2085 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm; 2086 memset(&info, 0, sizeof(struct i2c_board_info)); 2087 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 2088 info.addr = 0x60; 2089 info.platform_data = &ts2020_config; 2090 request_module(info.type); 2091 client_tuner = i2c_new_device(adapter, &info); 2092 if (client_tuner == NULL || client_tuner->dev.driver == NULL) 2093 goto frontend_detach; 2094 if (!try_module_get(client_tuner->dev.driver->owner)) { 2095 i2c_unregister_device(client_tuner); 2096 goto frontend_detach; 2097 } 2098 2099 /* delegate signal strength measurement to tuner */ 2100 fe0->dvb.frontend->ops.read_signal_strength = 2101 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength; 2102 2103 port->i2c_client_tuner = client_tuner; 2104 break; 2105 case CX23885_BOARD_DVBSKY_S952: 2106 switch (port->nr) { 2107 /* port b */ 2108 case 1: 2109 i2c_bus = &dev->i2c_bus[1]; 2110 p_m88ds3103_config = &dvbsky_t9580_m88ds3103_config; 2111 p_set_voltage = dvbsky_t9580_set_voltage; 2112 break; 2113 /* port c */ 2114 case 2: 2115 i2c_bus = &dev->i2c_bus[0]; 2116 p_m88ds3103_config = &dvbsky_s952_portc_m88ds3103_config; 2117 p_set_voltage = dvbsky_s952_portc_set_voltage; 2118 break; 2119 } 2120 2121 /* attach frontend */ 2122 fe0->dvb.frontend = dvb_attach(m88ds3103_attach, 2123 p_m88ds3103_config, 2124 &i2c_bus->i2c_adap, &adapter); 2125 if (fe0->dvb.frontend == NULL) 2126 break; 2127 2128 /* attach tuner */ 2129 memset(&ts2020_config, 0, sizeof(ts2020_config)); 2130 ts2020_config.fe = fe0->dvb.frontend; 2131 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm; 2132 memset(&info, 0, sizeof(struct i2c_board_info)); 2133 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 2134 info.addr = 0x60; 2135 info.platform_data = &ts2020_config; 2136 request_module(info.type); 2137 client_tuner = i2c_new_device(adapter, &info); 2138 if (client_tuner == NULL || client_tuner->dev.driver == NULL) 2139 goto frontend_detach; 2140 if (!try_module_get(client_tuner->dev.driver->owner)) { 2141 i2c_unregister_device(client_tuner); 2142 goto frontend_detach; 2143 } 2144 2145 /* delegate signal strength measurement to tuner */ 2146 fe0->dvb.frontend->ops.read_signal_strength = 2147 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength; 2148 2149 /* 2150 * for setting the voltage we need to set GPIOs on 2151 * the card. 2152 */ 2153 port->fe_set_voltage = 2154 fe0->dvb.frontend->ops.set_voltage; 2155 fe0->dvb.frontend->ops.set_voltage = p_set_voltage; 2156 2157 port->i2c_client_tuner = client_tuner; 2158 break; 2159 case CX23885_BOARD_DVBSKY_T982: 2160 memset(&si2168_config, 0, sizeof(si2168_config)); 2161 switch (port->nr) { 2162 /* port b */ 2163 case 1: 2164 i2c_bus = &dev->i2c_bus[1]; 2165 si2168_config.ts_mode = SI2168_TS_PARALLEL; 2166 break; 2167 /* port c */ 2168 case 2: 2169 i2c_bus = &dev->i2c_bus[0]; 2170 si2168_config.ts_mode = SI2168_TS_SERIAL; 2171 break; 2172 } 2173 2174 /* attach frontend */ 2175 si2168_config.i2c_adapter = &adapter; 2176 si2168_config.fe = &fe0->dvb.frontend; 2177 memset(&info, 0, sizeof(struct i2c_board_info)); 2178 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 2179 info.addr = 0x64; 2180 info.platform_data = &si2168_config; 2181 request_module(info.type); 2182 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 2183 if (client_demod == NULL || client_demod->dev.driver == NULL) 2184 goto frontend_detach; 2185 if (!try_module_get(client_demod->dev.driver->owner)) { 2186 i2c_unregister_device(client_demod); 2187 goto frontend_detach; 2188 } 2189 port->i2c_client_demod = client_demod; 2190 2191 /* attach tuner */ 2192 memset(&si2157_config, 0, sizeof(si2157_config)); 2193 si2157_config.fe = fe0->dvb.frontend; 2194 si2157_config.if_port = 1; 2195 memset(&info, 0, sizeof(struct i2c_board_info)); 2196 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2197 info.addr = 0x60; 2198 info.platform_data = &si2157_config; 2199 request_module(info.type); 2200 client_tuner = i2c_new_device(adapter, &info); 2201 if (client_tuner == NULL || 2202 client_tuner->dev.driver == NULL) 2203 goto frontend_detach; 2204 if (!try_module_get(client_tuner->dev.driver->owner)) { 2205 i2c_unregister_device(client_tuner); 2206 goto frontend_detach; 2207 } 2208 port->i2c_client_tuner = client_tuner; 2209 break; 2210 case CX23885_BOARD_HAUPPAUGE_HVR5525: { 2211 struct m88rs6000t_config m88rs6000t_config; 2212 struct a8293_platform_data a8293_pdata = {}; 2213 2214 switch (port->nr) { 2215 2216 /* port b - satellite */ 2217 case 1: 2218 /* attach frontend */ 2219 fe0->dvb.frontend = dvb_attach(m88ds3103_attach, 2220 &hauppauge_hvr5525_m88ds3103_config, 2221 &dev->i2c_bus[0].i2c_adap, &adapter); 2222 if (fe0->dvb.frontend == NULL) 2223 break; 2224 2225 /* attach SEC */ 2226 a8293_pdata.dvb_frontend = fe0->dvb.frontend; 2227 memset(&info, 0, sizeof(info)); 2228 strlcpy(info.type, "a8293", I2C_NAME_SIZE); 2229 info.addr = 0x0b; 2230 info.platform_data = &a8293_pdata; 2231 request_module("a8293"); 2232 client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info); 2233 if (!client_sec || !client_sec->dev.driver) 2234 goto frontend_detach; 2235 if (!try_module_get(client_sec->dev.driver->owner)) { 2236 i2c_unregister_device(client_sec); 2237 goto frontend_detach; 2238 } 2239 port->i2c_client_sec = client_sec; 2240 2241 /* attach tuner */ 2242 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config)); 2243 m88rs6000t_config.fe = fe0->dvb.frontend; 2244 memset(&info, 0, sizeof(struct i2c_board_info)); 2245 strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE); 2246 info.addr = 0x21; 2247 info.platform_data = &m88rs6000t_config; 2248 request_module("%s", info.type); 2249 client_tuner = i2c_new_device(adapter, &info); 2250 if (!client_tuner || !client_tuner->dev.driver) 2251 goto frontend_detach; 2252 if (!try_module_get(client_tuner->dev.driver->owner)) { 2253 i2c_unregister_device(client_tuner); 2254 goto frontend_detach; 2255 } 2256 port->i2c_client_tuner = client_tuner; 2257 2258 /* delegate signal strength measurement to tuner */ 2259 fe0->dvb.frontend->ops.read_signal_strength = 2260 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength; 2261 break; 2262 /* port c - terrestrial/cable */ 2263 case 2: 2264 /* attach frontend */ 2265 memset(&si2168_config, 0, sizeof(si2168_config)); 2266 si2168_config.i2c_adapter = &adapter; 2267 si2168_config.fe = &fe0->dvb.frontend; 2268 si2168_config.ts_mode = SI2168_TS_SERIAL; 2269 memset(&info, 0, sizeof(struct i2c_board_info)); 2270 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 2271 info.addr = 0x64; 2272 info.platform_data = &si2168_config; 2273 request_module("%s", info.type); 2274 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info); 2275 if (!client_demod || !client_demod->dev.driver) 2276 goto frontend_detach; 2277 if (!try_module_get(client_demod->dev.driver->owner)) { 2278 i2c_unregister_device(client_demod); 2279 goto frontend_detach; 2280 } 2281 port->i2c_client_demod = client_demod; 2282 2283 /* attach tuner */ 2284 memset(&si2157_config, 0, sizeof(si2157_config)); 2285 si2157_config.fe = fe0->dvb.frontend; 2286 si2157_config.if_port = 1; 2287 memset(&info, 0, sizeof(struct i2c_board_info)); 2288 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2289 info.addr = 0x60; 2290 info.platform_data = &si2157_config; 2291 request_module("%s", info.type); 2292 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info); 2293 if (!client_tuner || !client_tuner->dev.driver) { 2294 module_put(client_demod->dev.driver->owner); 2295 i2c_unregister_device(client_demod); 2296 port->i2c_client_demod = NULL; 2297 goto frontend_detach; 2298 } 2299 if (!try_module_get(client_tuner->dev.driver->owner)) { 2300 i2c_unregister_device(client_tuner); 2301 module_put(client_demod->dev.driver->owner); 2302 i2c_unregister_device(client_demod); 2303 port->i2c_client_demod = NULL; 2304 goto frontend_detach; 2305 } 2306 port->i2c_client_tuner = client_tuner; 2307 break; 2308 } 2309 break; 2310 } 2311 case CX23885_BOARD_HAUPPAUGE_QUADHD_DVB: 2312 switch (port->nr) { 2313 /* port b - Terrestrial/cable */ 2314 case 1: 2315 /* attach frontend */ 2316 memset(&si2168_config, 0, sizeof(si2168_config)); 2317 si2168_config.i2c_adapter = &adapter; 2318 si2168_config.fe = &fe0->dvb.frontend; 2319 si2168_config.ts_mode = SI2168_TS_SERIAL; 2320 memset(&info, 0, sizeof(struct i2c_board_info)); 2321 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 2322 info.addr = 0x64; 2323 info.platform_data = &si2168_config; 2324 request_module("%s", info.type); 2325 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info); 2326 if (!client_demod || !client_demod->dev.driver) 2327 goto frontend_detach; 2328 if (!try_module_get(client_demod->dev.driver->owner)) { 2329 i2c_unregister_device(client_demod); 2330 goto frontend_detach; 2331 } 2332 port->i2c_client_demod = client_demod; 2333 2334 /* attach tuner */ 2335 memset(&si2157_config, 0, sizeof(si2157_config)); 2336 si2157_config.fe = fe0->dvb.frontend; 2337 si2157_config.if_port = 1; 2338 memset(&info, 0, sizeof(struct i2c_board_info)); 2339 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2340 info.addr = 0x60; 2341 info.platform_data = &si2157_config; 2342 request_module("%s", info.type); 2343 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info); 2344 if (!client_tuner || !client_tuner->dev.driver) { 2345 module_put(client_demod->dev.driver->owner); 2346 i2c_unregister_device(client_demod); 2347 port->i2c_client_demod = NULL; 2348 goto frontend_detach; 2349 } 2350 if (!try_module_get(client_tuner->dev.driver->owner)) { 2351 i2c_unregister_device(client_tuner); 2352 module_put(client_demod->dev.driver->owner); 2353 i2c_unregister_device(client_demod); 2354 port->i2c_client_demod = NULL; 2355 goto frontend_detach; 2356 } 2357 port->i2c_client_tuner = client_tuner; 2358 break; 2359 2360 /* port c - terrestrial/cable */ 2361 case 2: 2362 /* attach frontend */ 2363 memset(&si2168_config, 0, sizeof(si2168_config)); 2364 si2168_config.i2c_adapter = &adapter; 2365 si2168_config.fe = &fe0->dvb.frontend; 2366 si2168_config.ts_mode = SI2168_TS_SERIAL; 2367 memset(&info, 0, sizeof(struct i2c_board_info)); 2368 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 2369 info.addr = 0x66; 2370 info.platform_data = &si2168_config; 2371 request_module("%s", info.type); 2372 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info); 2373 if (!client_demod || !client_demod->dev.driver) 2374 goto frontend_detach; 2375 if (!try_module_get(client_demod->dev.driver->owner)) { 2376 i2c_unregister_device(client_demod); 2377 goto frontend_detach; 2378 } 2379 port->i2c_client_demod = client_demod; 2380 2381 /* attach tuner */ 2382 memset(&si2157_config, 0, sizeof(si2157_config)); 2383 si2157_config.fe = fe0->dvb.frontend; 2384 si2157_config.if_port = 1; 2385 memset(&info, 0, sizeof(struct i2c_board_info)); 2386 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2387 info.addr = 0x62; 2388 info.platform_data = &si2157_config; 2389 request_module("%s", info.type); 2390 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info); 2391 if (!client_tuner || !client_tuner->dev.driver) { 2392 module_put(client_demod->dev.driver->owner); 2393 i2c_unregister_device(client_demod); 2394 port->i2c_client_demod = NULL; 2395 goto frontend_detach; 2396 } 2397 if (!try_module_get(client_tuner->dev.driver->owner)) { 2398 i2c_unregister_device(client_tuner); 2399 module_put(client_demod->dev.driver->owner); 2400 i2c_unregister_device(client_demod); 2401 port->i2c_client_demod = NULL; 2402 goto frontend_detach; 2403 } 2404 port->i2c_client_tuner = client_tuner; 2405 break; 2406 } 2407 break; 2408 case CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC: 2409 switch (port->nr) { 2410 /* port b - Terrestrial/cable */ 2411 case 1: 2412 /* attach frontend */ 2413 i2c_bus = &dev->i2c_bus[0]; 2414 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach, 2415 &hauppauge_quadHD_ATSC_a_config, &i2c_bus->i2c_adap); 2416 if (fe0->dvb.frontend == NULL) 2417 break; 2418 2419 /* attach tuner */ 2420 memset(&si2157_config, 0, sizeof(si2157_config)); 2421 si2157_config.fe = fe0->dvb.frontend; 2422 si2157_config.if_port = 1; 2423 si2157_config.inversion = 1; 2424 memset(&info, 0, sizeof(struct i2c_board_info)); 2425 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2426 info.addr = 0x60; 2427 info.platform_data = &si2157_config; 2428 request_module("%s", info.type); 2429 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info); 2430 if (!client_tuner || !client_tuner->dev.driver) { 2431 module_put(client_demod->dev.driver->owner); 2432 i2c_unregister_device(client_demod); 2433 port->i2c_client_demod = NULL; 2434 goto frontend_detach; 2435 } 2436 if (!try_module_get(client_tuner->dev.driver->owner)) { 2437 i2c_unregister_device(client_tuner); 2438 module_put(client_demod->dev.driver->owner); 2439 i2c_unregister_device(client_demod); 2440 port->i2c_client_demod = NULL; 2441 goto frontend_detach; 2442 } 2443 port->i2c_client_tuner = client_tuner; 2444 break; 2445 2446 /* port c - terrestrial/cable */ 2447 case 2: 2448 /* attach frontend */ 2449 i2c_bus = &dev->i2c_bus[0]; 2450 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach, 2451 &hauppauge_quadHD_ATSC_b_config, &i2c_bus->i2c_adap); 2452 if (fe0->dvb.frontend == NULL) 2453 break; 2454 2455 /* attach tuner */ 2456 memset(&si2157_config, 0, sizeof(si2157_config)); 2457 si2157_config.fe = fe0->dvb.frontend; 2458 si2157_config.if_port = 1; 2459 si2157_config.inversion = 1; 2460 memset(&info, 0, sizeof(struct i2c_board_info)); 2461 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2462 info.addr = 0x62; 2463 info.platform_data = &si2157_config; 2464 request_module("%s", info.type); 2465 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info); 2466 if (!client_tuner || !client_tuner->dev.driver) { 2467 module_put(client_demod->dev.driver->owner); 2468 i2c_unregister_device(client_demod); 2469 port->i2c_client_demod = NULL; 2470 goto frontend_detach; 2471 } 2472 if (!try_module_get(client_tuner->dev.driver->owner)) { 2473 i2c_unregister_device(client_tuner); 2474 module_put(client_demod->dev.driver->owner); 2475 i2c_unregister_device(client_demod); 2476 port->i2c_client_demod = NULL; 2477 goto frontend_detach; 2478 } 2479 port->i2c_client_tuner = client_tuner; 2480 break; 2481 } 2482 break; 2483 2484 default: 2485 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card " 2486 " isn't supported yet\n", 2487 dev->name); 2488 break; 2489 } 2490 2491 if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) { 2492 printk(KERN_ERR "%s: frontend initialization failed\n", 2493 dev->name); 2494 goto frontend_detach; 2495 } 2496 2497 /* define general-purpose callback pointer */ 2498 fe0->dvb.frontend->callback = cx23885_tuner_callback; 2499 if (fe1) 2500 fe1->dvb.frontend->callback = cx23885_tuner_callback; 2501 #if 0 2502 /* Ensure all frontends negotiate bus access */ 2503 fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl; 2504 if (fe1) 2505 fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl; 2506 #endif 2507 2508 /* Put the analog decoder in standby to keep it quiet */ 2509 call_all(dev, core, s_power, 0); 2510 2511 if (fe0->dvb.frontend->ops.analog_ops.standby) 2512 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend); 2513 2514 /* register everything */ 2515 ret = vb2_dvb_register_bus(&port->frontends, THIS_MODULE, port, 2516 &dev->pci->dev, NULL, 2517 adapter_nr, mfe_shared); 2518 if (ret) 2519 goto frontend_detach; 2520 2521 ret = dvb_register_ci_mac(port); 2522 if (ret) 2523 goto frontend_detach; 2524 2525 return 0; 2526 2527 frontend_detach: 2528 /* remove I2C client for SEC */ 2529 client_sec = port->i2c_client_sec; 2530 if (client_sec) { 2531 module_put(client_sec->dev.driver->owner); 2532 i2c_unregister_device(client_sec); 2533 port->i2c_client_sec = NULL; 2534 } 2535 2536 /* remove I2C client for tuner */ 2537 client_tuner = port->i2c_client_tuner; 2538 if (client_tuner) { 2539 module_put(client_tuner->dev.driver->owner); 2540 i2c_unregister_device(client_tuner); 2541 port->i2c_client_tuner = NULL; 2542 } 2543 2544 /* remove I2C client for demodulator */ 2545 client_demod = port->i2c_client_demod; 2546 if (client_demod) { 2547 module_put(client_demod->dev.driver->owner); 2548 i2c_unregister_device(client_demod); 2549 port->i2c_client_demod = NULL; 2550 } 2551 2552 port->gate_ctrl = NULL; 2553 vb2_dvb_dealloc_frontends(&port->frontends); 2554 return -EINVAL; 2555 } 2556 2557 int cx23885_dvb_register(struct cx23885_tsport *port) 2558 { 2559 2560 struct vb2_dvb_frontend *fe0; 2561 struct cx23885_dev *dev = port->dev; 2562 int err, i; 2563 2564 /* Here we need to allocate the correct number of frontends, 2565 * as reflected in the cards struct. The reality is that currently 2566 * no cx23885 boards support this - yet. But, if we don't modify this 2567 * code then the second frontend would never be allocated (later) 2568 * and fail with error before the attach in dvb_register(). 2569 * Without these changes we risk an OOPS later. The changes here 2570 * are for safety, and should provide a good foundation for the 2571 * future addition of any multi-frontend cx23885 based boards. 2572 */ 2573 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__, 2574 port->num_frontends); 2575 2576 for (i = 1; i <= port->num_frontends; i++) { 2577 struct vb2_queue *q; 2578 2579 if (vb2_dvb_alloc_frontend( 2580 &port->frontends, i) == NULL) { 2581 printk(KERN_ERR "%s() failed to alloc\n", __func__); 2582 return -ENOMEM; 2583 } 2584 2585 fe0 = vb2_dvb_get_frontend(&port->frontends, i); 2586 if (!fe0) 2587 return -EINVAL; 2588 2589 dprintk(1, "%s\n", __func__); 2590 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n", 2591 dev->board, 2592 dev->name, 2593 dev->pci_bus, 2594 dev->pci_slot); 2595 2596 err = -ENODEV; 2597 2598 /* dvb stuff */ 2599 /* We have to init the queue for each frontend on a port. */ 2600 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name); 2601 q = &fe0->dvb.dvbq; 2602 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2603 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; 2604 q->gfp_flags = GFP_DMA32; 2605 q->min_buffers_needed = 2; 2606 q->drv_priv = port; 2607 q->buf_struct_size = sizeof(struct cx23885_buffer); 2608 q->ops = &dvb_qops; 2609 q->mem_ops = &vb2_dma_sg_memops; 2610 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 2611 q->lock = &dev->lock; 2612 q->dev = &dev->pci->dev; 2613 2614 err = vb2_queue_init(q); 2615 if (err < 0) 2616 return err; 2617 } 2618 err = dvb_register(port); 2619 if (err != 0) 2620 printk(KERN_ERR "%s() dvb_register failed err = %d\n", 2621 __func__, err); 2622 2623 return err; 2624 } 2625 2626 int cx23885_dvb_unregister(struct cx23885_tsport *port) 2627 { 2628 struct vb2_dvb_frontend *fe0; 2629 struct i2c_client *client; 2630 2631 /* remove I2C client for CI */ 2632 client = port->i2c_client_ci; 2633 if (client) { 2634 module_put(client->dev.driver->owner); 2635 i2c_unregister_device(client); 2636 } 2637 2638 /* remove I2C client for SEC */ 2639 client = port->i2c_client_sec; 2640 if (client) { 2641 module_put(client->dev.driver->owner); 2642 i2c_unregister_device(client); 2643 } 2644 2645 /* remove I2C client for tuner */ 2646 client = port->i2c_client_tuner; 2647 if (client) { 2648 module_put(client->dev.driver->owner); 2649 i2c_unregister_device(client); 2650 } 2651 2652 /* remove I2C client for demodulator */ 2653 client = port->i2c_client_demod; 2654 if (client) { 2655 module_put(client->dev.driver->owner); 2656 i2c_unregister_device(client); 2657 } 2658 2659 fe0 = vb2_dvb_get_frontend(&port->frontends, 1); 2660 2661 if (fe0 && fe0->dvb.frontend) 2662 vb2_dvb_unregister_bus(&port->frontends); 2663 2664 switch (port->dev->board) { 2665 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: 2666 netup_ci_exit(port); 2667 break; 2668 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: 2669 altera_ci_release(port->dev, port->nr); 2670 break; 2671 } 2672 2673 port->gate_ctrl = NULL; 2674 2675 return 0; 2676 } 2677