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