2 * Driver for the Conexant CX23885 PCIe bridge
4 * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org>
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.
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
15 * GNU General Public License for more details.
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/device.h>
24 #include <linux/kthread.h>
25 #include <linux/file.h>
26 #include <linux/suspend.h>
28 #include <media/v4l2-common.h>
30 #include "dvb_ca_en50221.h"
41 #include "tuner-xc2028.h"
42 #include "tuner-simple.h"
45 #include "dibx000_common.h"
48 #include "stv0900_reg.h"
55 #include "netup-eeprom.h"
56 #include "netup-init.h"
61 #include "cx23885-f300.h"
62 #include "altera-ci.h"
68 #include "stb6100_cfg.h"
76 #include "m88ds3103.h"
77 #include "m88rs6000t.h"
78 #include "lgdt3306a.h"
80 static unsigned int debug;
82 #define dprintk(level, fmt, arg...)\
83 do { if (debug >= level)\
84 printk(KERN_DEBUG pr_fmt("%s dvb: " fmt), \
88 /* ------------------------------------------------------------------ */
90 static unsigned int alt_tuner;
91 module_param(alt_tuner, int, 0644);
92 MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
94 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
96 /* ------------------------------------------------------------------ */
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[])
102 struct cx23885_tsport *port = q->drv_priv;
104 port->ts_packet_size = 188 * 4;
105 port->ts_packet_count = 32;
107 sizes[0] = port->ts_packet_size * port->ts_packet_count;
113 static int buffer_prepare(struct vb2_buffer *vb)
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);
120 return cx23885_buf_prepare(buf, port);
123 static void buffer_finish(struct vb2_buffer *vb)
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);
131 cx23885_free_buffer(dev, buf);
134 static void buffer_queue(struct vb2_buffer *vb)
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);
141 cx23885_buf_queue(port, buf);
144 static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open)
146 struct vb2_dvb_frontends *f;
147 struct vb2_dvb_frontend *fe;
149 f = &port->frontends;
151 if (f->gate <= 1) /* undefined or fe0 */
152 fe = vb2_dvb_get_frontend(f, 1);
154 fe = vb2_dvb_get_frontend(f, f->gate);
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);
160 static int cx23885_start_streaming(struct vb2_queue *q, unsigned int count)
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);
167 cx23885_start_dma(port, dmaq, buf);
171 static void cx23885_stop_streaming(struct vb2_queue *q)
173 struct cx23885_tsport *port = q->drv_priv;
175 cx23885_cancel_buffers(port);
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,
189 static struct s5h1409_config hauppauge_generic_config = {
190 .demod_address = 0x32 >> 1,
191 .output_mode = S5H1409_SERIAL_OUTPUT,
192 .gpio = S5H1409_GPIO_ON,
194 .inversion = S5H1409_INVERSION_OFF,
195 .status_mode = S5H1409_DEMODLOCKING,
196 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
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,
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,
221 static struct s5h1409_config hauppauge_ezqam_config = {
222 .demod_address = 0x32 >> 1,
223 .output_mode = S5H1409_SERIAL_OUTPUT,
224 .gpio = S5H1409_GPIO_OFF,
226 .inversion = S5H1409_INVERSION_ON,
227 .status_mode = S5H1409_DEMODLOCKING,
228 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
231 static struct s5h1409_config hauppauge_hvr1800lp_config = {
232 .demod_address = 0x32 >> 1,
233 .output_mode = S5H1409_SERIAL_OUTPUT,
234 .gpio = S5H1409_GPIO_OFF,
236 .inversion = S5H1409_INVERSION_OFF,
237 .status_mode = S5H1409_DEMODLOCKING,
238 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
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_CONTINOUS_NONINVERTING_CLOCK,
250 static struct mt2131_config hauppauge_generic_tunerconfig = {
254 static struct lgdt330x_config fusionhdtv_5_express = {
255 .demod_address = 0x0e,
256 .demod_chip = LGDT3303,
260 static struct s5h1409_config hauppauge_hvr1500q_config = {
261 .demod_address = 0x32 >> 1,
262 .output_mode = S5H1409_SERIAL_OUTPUT,
263 .gpio = S5H1409_GPIO_ON,
265 .inversion = S5H1409_INVERSION_OFF,
266 .status_mode = S5H1409_DEMODLOCKING,
267 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
270 static struct s5h1409_config dvico_s5h1409_config = {
271 .demod_address = 0x32 >> 1,
272 .output_mode = S5H1409_SERIAL_OUTPUT,
273 .gpio = S5H1409_GPIO_ON,
275 .inversion = S5H1409_INVERSION_OFF,
276 .status_mode = S5H1409_DEMODLOCKING,
277 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
280 static struct s5h1411_config dvico_s5h1411_config = {
281 .output_mode = S5H1411_SERIAL_OUTPUT,
282 .gpio = S5H1411_GPIO_ON,
283 .qam_if = S5H1411_IF_44000,
284 .vsb_if = S5H1411_IF_44000,
285 .inversion = S5H1411_INVERSION_OFF,
286 .status_mode = S5H1411_DEMODLOCKING,
287 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
290 static struct s5h1411_config hcw_s5h1411_config = {
291 .output_mode = S5H1411_SERIAL_OUTPUT,
292 .gpio = S5H1411_GPIO_OFF,
293 .vsb_if = S5H1411_IF_44000,
294 .qam_if = S5H1411_IF_4000,
295 .inversion = S5H1411_INVERSION_ON,
296 .status_mode = S5H1411_DEMODLOCKING,
297 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
300 static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
305 static struct xc5000_config dvico_xc5000_tunerconfig = {
310 static struct tda829x_config tda829x_no_probe = {
311 .probe_tuner = TDA829X_DONT_PROBE,
314 static struct tda18271_std_map hauppauge_tda18271_std_map = {
315 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
316 .if_lvl = 6, .rfagc_top = 0x37 },
317 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
318 .if_lvl = 6, .rfagc_top = 0x37 },
321 static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
322 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
323 .if_lvl = 1, .rfagc_top = 0x37, },
324 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
325 .if_lvl = 1, .rfagc_top = 0x37, },
326 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
327 .if_lvl = 1, .rfagc_top = 0x37, },
330 static struct tda18271_config hauppauge_tda18271_config = {
331 .std_map = &hauppauge_tda18271_std_map,
332 .gate = TDA18271_GATE_ANALOG,
333 .output_opt = TDA18271_OUTPUT_LT_OFF,
336 static struct tda18271_config hauppauge_hvr1200_tuner_config = {
337 .std_map = &hauppauge_hvr1200_tda18271_std_map,
338 .gate = TDA18271_GATE_ANALOG,
339 .output_opt = TDA18271_OUTPUT_LT_OFF,
342 static struct tda18271_config hauppauge_hvr1210_tuner_config = {
343 .gate = TDA18271_GATE_DIGITAL,
344 .output_opt = TDA18271_OUTPUT_LT_OFF,
347 static struct tda18271_config hauppauge_hvr4400_tuner_config = {
348 .gate = TDA18271_GATE_DIGITAL,
349 .output_opt = TDA18271_OUTPUT_LT_OFF,
352 static struct tda18271_std_map hauppauge_hvr127x_std_map = {
353 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
354 .if_lvl = 1, .rfagc_top = 0x58 },
355 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
356 .if_lvl = 1, .rfagc_top = 0x58 },
359 static struct tda18271_config hauppauge_hvr127x_config = {
360 .std_map = &hauppauge_hvr127x_std_map,
361 .output_opt = TDA18271_OUTPUT_LT_OFF,
364 static struct lgdt3305_config hauppauge_lgdt3305_config = {
366 .mpeg_mode = LGDT3305_MPEG_SERIAL,
367 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
368 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
370 .spectral_inversion = 1,
375 static struct dibx000_agc_config xc3028_agc_config = {
376 BAND_VHF | BAND_UHF, /* band_caps */
378 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
379 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
380 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
381 * P_agc_nb_est=2, P_agc_write=0
383 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
384 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
387 21, /* time_stabiliz */
399 39718, /* agc2_max */
408 29, /* agc2_slope1 */
409 29, /* agc2_slope2 */
416 1, /* perform_agc_softsplit */
419 /* PLL Configuration for COFDM BW_MHz = 8.000000
420 * With external clock = 30.000000 */
421 static struct dibx000_bandwidth_config xc3028_bw_config = {
422 60000, /* internal */
423 30000, /* sampling */
424 1, /* pll_cfg: prediv */
425 8, /* pll_cfg: ratio */
426 3, /* pll_cfg: range */
427 1, /* pll_cfg: reset */
428 0, /* pll_cfg: bypass */
429 0, /* misc: refdiv */
430 0, /* misc: bypclk_div */
431 1, /* misc: IO_CLK_en_core */
432 1, /* misc: ADClkSrc */
433 0, /* misc: modulo */
434 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
435 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
437 30000000 /* xtal_hz */
440 static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
441 .output_mpeg2_in_188_bytes = 1,
442 .hostbus_diversity = 1,
443 .tuner_is_baseband = 0,
446 .agc_config_count = 1,
447 .agc = &xc3028_agc_config,
448 .bw = &xc3028_bw_config,
450 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
451 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
452 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
458 .output_mode = OUTMODE_MPEG2_SERIAL,
461 static struct zl10353_config dvico_fusionhdtv_xc3028 = {
462 .demod_address = 0x0f,
465 .disable_i2c_gate_ctrl = 1,
468 static struct stv0900_reg stv0900_ts_regs[] = {
469 { R0900_TSGENERAL, 0x00 },
470 { R0900_P1_TSSPEED, 0x40 },
471 { R0900_P2_TSSPEED, 0x40 },
472 { R0900_P1_TSCFGM, 0xc0 },
473 { R0900_P2_TSCFGM, 0xc0 },
474 { R0900_P1_TSCFGH, 0xe0 },
475 { R0900_P2_TSCFGH, 0xe0 },
476 { R0900_P1_TSCFGL, 0x20 },
477 { R0900_P2_TSCFGL, 0x20 },
478 { 0xffff, 0xff }, /* terminate */
481 static struct stv0900_config netup_stv0900_config = {
482 .demod_address = 0x68,
483 .demod_mode = 1, /* dual */
485 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
486 .diseqc_mode = 2,/* 2/3 PWM */
487 .ts_config_regs = stv0900_ts_regs,
488 .tun1_maddress = 0,/* 0x60 */
489 .tun2_maddress = 3,/* 0x63 */
490 .tun1_adc = 1,/* 1 Vpp */
491 .tun2_adc = 1,/* 1 Vpp */
494 static struct stv6110_config netup_stv6110_tunerconfig_a = {
498 .gain = 8, /* +16 dB - maximum gain */
501 static struct stv6110_config netup_stv6110_tunerconfig_b = {
505 .gain = 8, /* +16 dB - maximum gain */
508 static struct cx24116_config tbs_cx24116_config = {
509 .demod_address = 0x55,
512 static struct cx24117_config tbs_cx24117_config = {
513 .demod_address = 0x55,
516 static struct ds3000_config tevii_ds3000_config = {
517 .demod_address = 0x68,
520 static struct ts2020_config tevii_ts2020_config = {
521 .tuner_address = 0x60,
523 .frequency_div = 1146000,
526 static struct cx24116_config dvbworld_cx24116_config = {
527 .demod_address = 0x05,
530 static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
531 .prod = LGS8GXX_PROD_LGS8GL5,
532 .demod_address = 0x19,
536 .if_clk_freq = 30400, /* 30.4 MHz */
537 .if_freq = 5380, /* 5.38 MHz */
544 static struct xc5000_config mygica_x8506_xc5000_config = {
549 static struct mb86a20s_config mygica_x8507_mb86a20s_config = {
550 .demod_address = 0x10,
553 static struct xc5000_config mygica_x8507_xc5000_config = {
558 static struct stv090x_config prof_8000_stv090x_config = {
560 .demod_mode = STV090x_SINGLE,
561 .clk_mode = STV090x_CLK_EXT,
564 .ts1_mode = STV090x_TSMODE_PARALLEL_PUNCTURED,
565 .repeater_level = STV090x_RPTLEVEL_64,
566 .adc1_range = STV090x_ADC_2Vpp,
567 .diseqc_envelope_mode = false,
569 .tuner_get_frequency = stb6100_get_frequency,
570 .tuner_set_frequency = stb6100_set_frequency,
571 .tuner_set_bandwidth = stb6100_set_bandwidth,
572 .tuner_get_bandwidth = stb6100_get_bandwidth,
575 static struct stb6100_config prof_8000_stb6100_config = {
576 .tuner_address = 0x60,
577 .refclock = 27000000,
580 static struct lgdt3306a_config hauppauge_quadHD_ATSC_a_config = {
584 .deny_i2c_rptr = 1, /* Disabled */
585 .spectral_inversion = 0, /* Disabled */
586 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
587 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
588 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
589 .xtalMHz = 25, /* 24 or 25 */
592 static struct lgdt3306a_config hauppauge_quadHD_ATSC_b_config = {
596 .deny_i2c_rptr = 1, /* Disabled */
597 .spectral_inversion = 0, /* Disabled */
598 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
599 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
600 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
601 .xtalMHz = 25, /* 24 or 25 */
604 static int p8000_set_voltage(struct dvb_frontend *fe,
605 enum fe_sec_voltage voltage)
607 struct cx23885_tsport *port = fe->dvb->priv;
608 struct cx23885_dev *dev = port->dev;
610 if (voltage == SEC_VOLTAGE_18)
611 cx_write(MC417_RWD, 0x00001e00);
612 else if (voltage == SEC_VOLTAGE_13)
613 cx_write(MC417_RWD, 0x00001a00);
615 cx_write(MC417_RWD, 0x00001800);
619 static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe,
620 enum fe_sec_voltage voltage)
622 struct cx23885_tsport *port = fe->dvb->priv;
623 struct cx23885_dev *dev = port->dev;
625 cx23885_gpio_enable(dev, GPIO_0 | GPIO_1, 1);
629 cx23885_gpio_set(dev, GPIO_1);
630 cx23885_gpio_clear(dev, GPIO_0);
633 cx23885_gpio_set(dev, GPIO_1);
634 cx23885_gpio_set(dev, GPIO_0);
636 case SEC_VOLTAGE_OFF:
637 cx23885_gpio_clear(dev, GPIO_1);
638 cx23885_gpio_clear(dev, GPIO_0);
642 /* call the frontend set_voltage function */
643 port->fe_set_voltage(fe, voltage);
648 static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe,
649 enum fe_sec_voltage voltage)
651 struct cx23885_tsport *port = fe->dvb->priv;
652 struct cx23885_dev *dev = port->dev;
654 cx23885_gpio_enable(dev, GPIO_12 | GPIO_13, 1);
658 cx23885_gpio_set(dev, GPIO_13);
659 cx23885_gpio_clear(dev, GPIO_12);
662 cx23885_gpio_set(dev, GPIO_13);
663 cx23885_gpio_set(dev, GPIO_12);
665 case SEC_VOLTAGE_OFF:
666 cx23885_gpio_clear(dev, GPIO_13);
667 cx23885_gpio_clear(dev, GPIO_12);
670 /* call the frontend set_voltage function */
671 return port->fe_set_voltage(fe, voltage);
674 static int cx23885_sp2_ci_ctrl(void *priv, u8 read, int addr,
678 #define SP2_DATA 0x000000ff
679 #define SP2_WR 0x00008000
680 #define SP2_RD 0x00004000
681 #define SP2_ACK 0x00001000
682 #define SP2_ADHI 0x00000800
683 #define SP2_ADLO 0x00000400
684 #define SP2_CS1 0x00000200
685 #define SP2_CS0 0x00000100
686 #define SP2_EN_ALL 0x00001000
687 #define SP2_CTRL_OFF (SP2_CS1 | SP2_CS0 | SP2_WR | SP2_RD)
689 struct cx23885_tsport *port = priv;
690 struct cx23885_dev *dev = port->dev;
693 unsigned long timeout;
695 mutex_lock(&dev->gpio_lock);
698 cx_write(MC417_OEN, SP2_EN_ALL);
699 cx_write(MC417_RWD, SP2_CTRL_OFF |
700 SP2_ADLO | (0xff & addr));
701 cx_clear(MC417_RWD, SP2_ADLO);
702 cx_write(MC417_RWD, SP2_CTRL_OFF |
703 SP2_ADHI | (0xff & (addr >> 8)));
704 cx_clear(MC417_RWD, SP2_ADHI);
708 cx_write(MC417_OEN, SP2_EN_ALL | SP2_DATA);
711 cx_write(MC417_RWD, SP2_CTRL_OFF | data);
714 cx_clear(MC417_RWD, SP2_CS0);
717 cx_clear(MC417_RWD, (read) ? SP2_RD : SP2_WR);
719 /* wait for a maximum of 1 msec */
720 timeout = jiffies + msecs_to_jiffies(1);
721 while (!time_after(jiffies, timeout)) {
722 tmp = cx_read(MC417_RWD);
723 if ((tmp & SP2_ACK) == 0)
725 usleep_range(50, 100);
728 cx_set(MC417_RWD, SP2_CTRL_OFF);
731 mutex_unlock(&dev->gpio_lock);
745 static int cx23885_dvb_set_frontend(struct dvb_frontend *fe)
747 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
748 struct cx23885_tsport *port = fe->dvb->priv;
749 struct cx23885_dev *dev = port->dev;
751 switch (dev->board) {
752 case CX23885_BOARD_HAUPPAUGE_HVR1275:
753 switch (p->modulation) {
755 cx23885_gpio_clear(dev, GPIO_5);
760 cx23885_gpio_set(dev, GPIO_5);
764 case CX23885_BOARD_MYGICA_X8506:
765 case CX23885_BOARD_MYGICA_X8507:
766 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
767 /* Select Digital TV */
768 cx23885_gpio_set(dev, GPIO_0);
772 /* Call the real set_frontend */
773 if (port->set_frontend)
774 return port->set_frontend(fe);
779 static void cx23885_set_frontend_hook(struct cx23885_tsport *port,
780 struct dvb_frontend *fe)
782 port->set_frontend = fe->ops.set_frontend;
783 fe->ops.set_frontend = cx23885_dvb_set_frontend;
786 static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
787 .prod = LGS8GXX_PROD_LGS8G75,
788 .demod_address = 0x19,
792 .if_clk_freq = 30400, /* 30.4 MHz */
793 .if_freq = 6500, /* 6.50 MHz */
797 .adc_vpp = 2, /* 1.6 Vpp */
801 static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
806 static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
807 .prod = ATBM8830_PROD_8830,
808 .demod_address = 0x44,
810 .ts_sampling_edge = 1,
812 .osc_clk_freq = 30400, /* in kHz */
813 .if_freq = 0, /* zero IF */
820 static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
825 static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
826 .prod = ATBM8830_PROD_8830,
827 .demod_address = 0x44,
829 .ts_sampling_edge = 1,
831 .osc_clk_freq = 30400, /* in kHz */
832 .if_freq = 0, /* zero IF */
839 static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
843 static struct stv0367_config netup_stv0367_config[] = {
845 .demod_address = 0x1c,
852 .demod_address = 0x1d,
861 static struct xc5000_config netup_xc5000_config[] = {
871 static struct drxk_config terratec_drxk_config[] = {
881 static struct mt2063_config terratec_mt2063_config[] = {
883 .tuner_address = 0x60,
885 .tuner_address = 0x67,
889 static const struct tda10071_platform_data hauppauge_tda10071_pdata = {
890 .clk = 40444000, /* 40.444 MHz */
892 .ts_mode = TDA10071_TS_SERIAL,
893 .pll_multiplier = 20,
894 .tuner_i2c_addr = 0x54,
897 static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = {
902 .ts_mode = M88DS3103_TS_PARALLEL,
910 static const struct m88ds3103_config dvbsky_s950c_m88ds3103_config = {
915 .ts_mode = M88DS3103_TS_CI,
923 static const struct m88ds3103_config hauppauge_hvr5525_m88ds3103_config = {
927 .ts_mode = M88DS3103_TS_PARALLEL,
933 static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
935 struct cx23885_dev *dev = (struct cx23885_dev *)device;
936 unsigned long timeout = jiffies + msecs_to_jiffies(1);
939 mem = cx_read(MC417_RWD);
941 cx_set(MC417_OEN, ALT_DATA);
943 cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */
945 mem |= (data & ALT_DATA);
955 mem = (mem & ~ALT_RD) | ALT_WR;
957 mem = (mem & ~ALT_WR) | ALT_RD;
959 cx_write(MC417_RWD, mem); /* start RW cycle */
962 mem = cx_read(MC417_RWD);
963 if ((mem & ALT_RDY) == 0)
965 if (time_after(jiffies, timeout))
970 cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);
972 return mem & ALT_DATA;
977 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
979 struct dib7000p_ops *dib7000p_ops = fe->sec_priv;
981 return dib7000p_ops->set_gpio(fe, 8, 0, !onoff);
984 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
989 static struct dib0070_config dib7070p_dib0070_config = {
990 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
991 .reset = dib7070_tuner_reset,
992 .sleep = dib7070_tuner_sleep,
994 .freq_offset_khz_vhf = 550,
995 /* .flip_chip = 1, */
998 /* DIB7070 generic */
999 static struct dibx000_agc_config dib7070_agc_config = {
1000 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1003 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
1004 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1005 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
1007 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
1008 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1010 .time_stabiliz = 10,
1034 .perform_agc_softsplit = 0,
1037 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
1047 .IO_CLK_en_core = 1,
1050 /* refsel, sel, freq_15k */
1051 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1052 .ifreq = (0 << 25) | 0,
1054 .xtal_hz = 12000000,
1057 static struct dib7000p_config dib7070p_dib7000p_config = {
1058 /* .output_mode = OUTMODE_MPEG2_FIFO, */
1059 .output_mode = OUTMODE_MPEG2_SERIAL,
1060 /* .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK, */
1061 .output_mpeg2_in_188_bytes = 1,
1063 .agc_config_count = 1,
1064 .agc = &dib7070_agc_config,
1065 .bw = &dib7070_bw_config_12_mhz,
1066 .tuner_is_baseband = 1,
1069 .gpio_dir = 0xfcef, /* DIB7000P_GPIO_DEFAULT_DIRECTIONS, */
1070 .gpio_val = 0x0110, /* DIB7000P_GPIO_DEFAULT_VALUES, */
1071 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1073 .hostbus_diversity = 1,
1076 static int dvb_register_ci_mac(struct cx23885_tsport *port)
1078 struct cx23885_dev *dev = port->dev;
1079 struct i2c_client *client_ci = NULL;
1080 struct vb2_dvb_frontend *fe0;
1082 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
1086 switch (dev->board) {
1087 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
1088 static struct netup_card_info cinfo;
1090 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
1091 memcpy(port->frontends.adapter.proposed_mac,
1092 cinfo.port[port->nr - 1].mac, 6);
1093 pr_info("NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
1094 port->nr, port->frontends.adapter.proposed_mac);
1096 netup_ci_init(port);
1099 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
1100 struct altera_ci_config netup_ci_cfg = {
1101 .dev = dev,/* magic number to identify*/
1102 .adapter = &port->frontends.adapter,/* for CI */
1103 .demux = &fe0->dvb.demux,/* for hw pid filter */
1104 .fpga_rw = netup_altera_fpga_rw,
1107 altera_ci_init(&netup_ci_cfg, port->nr);
1110 case CX23885_BOARD_TEVII_S470: {
1111 u8 eeprom[256]; /* 24C02 i2c eeprom */
1116 /* Read entire EEPROM */
1117 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1118 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
1119 pr_info("TeVii S470 MAC= %pM\n", eeprom + 0xa0);
1120 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
1123 case CX23885_BOARD_DVBSKY_T9580:
1124 case CX23885_BOARD_DVBSKY_S950:
1125 case CX23885_BOARD_DVBSKY_S952:
1126 case CX23885_BOARD_DVBSKY_T982: {
1127 u8 eeprom[256]; /* 24C02 i2c eeprom */
1132 /* Read entire EEPROM */
1133 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1134 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
1136 pr_info("%s port %d MAC address: %pM\n",
1137 cx23885_boards[dev->board].name, port->nr,
1138 eeprom + 0xc0 + (port->nr-1) * 8);
1139 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 +
1140 (port->nr-1) * 8, 6);
1143 case CX23885_BOARD_DVBSKY_S950C:
1144 case CX23885_BOARD_DVBSKY_T980C:
1145 case CX23885_BOARD_TT_CT2_4500_CI: {
1146 u8 eeprom[256]; /* 24C02 i2c eeprom */
1147 struct sp2_config sp2_config;
1148 struct i2c_board_info info;
1149 struct cx23885_i2c *i2c_bus = &dev->i2c_bus[0];
1152 memset(&sp2_config, 0, sizeof(sp2_config));
1153 sp2_config.dvb_adap = &port->frontends.adapter;
1154 sp2_config.priv = port;
1155 sp2_config.ci_control = cx23885_sp2_ci_ctrl;
1156 memset(&info, 0, sizeof(struct i2c_board_info));
1157 strlcpy(info.type, "sp2", I2C_NAME_SIZE);
1159 info.platform_data = &sp2_config;
1160 request_module(info.type);
1161 client_ci = i2c_new_device(&i2c_bus->i2c_adap, &info);
1162 if (client_ci == NULL || client_ci->dev.driver == NULL)
1164 if (!try_module_get(client_ci->dev.driver->owner)) {
1165 i2c_unregister_device(client_ci);
1168 port->i2c_client_ci = client_ci;
1173 /* Read entire EEPROM */
1174 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1175 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
1177 pr_info("%s MAC address: %pM\n",
1178 cx23885_boards[dev->board].name, eeprom + 0xc0);
1179 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6);
1186 static int dvb_register(struct cx23885_tsport *port)
1188 struct dib7000p_ops dib7000p_ops;
1189 struct cx23885_dev *dev = port->dev;
1190 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
1191 struct vb2_dvb_frontend *fe0, *fe1 = NULL;
1192 struct si2168_config si2168_config;
1193 struct si2165_platform_data si2165_pdata;
1194 struct si2157_config si2157_config;
1195 struct ts2020_config ts2020_config;
1196 struct m88ds3103_platform_data m88ds3103_pdata;
1197 struct i2c_board_info info;
1198 struct i2c_adapter *adapter;
1199 struct i2c_client *client_demod = NULL, *client_tuner = NULL;
1200 struct i2c_client *client_sec = NULL;
1201 int (*p_set_voltage)(struct dvb_frontend *fe,
1202 enum fe_sec_voltage voltage) = NULL;
1203 int mfe_shared = 0; /* bus not shared by default */
1206 /* Get the first frontend */
1207 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
1211 /* init struct vb2_dvb */
1212 fe0->dvb.name = dev->name;
1214 /* multi-frontend gate control is undefined or defaults to fe0 */
1215 port->frontends.gate = 0;
1217 /* Sets the gate control callback to be used by i2c command calls */
1218 port->gate_ctrl = cx23885_dvb_gate_ctrl;
1221 switch (dev->board) {
1222 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1223 i2c_bus = &dev->i2c_bus[0];
1224 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1225 &hauppauge_generic_config,
1226 &i2c_bus->i2c_adap);
1227 if (fe0->dvb.frontend == NULL)
1229 dvb_attach(mt2131_attach, fe0->dvb.frontend,
1231 &hauppauge_generic_tunerconfig, 0);
1233 case CX23885_BOARD_HAUPPAUGE_HVR1270:
1234 case CX23885_BOARD_HAUPPAUGE_HVR1275:
1235 i2c_bus = &dev->i2c_bus[0];
1236 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1237 &hauppauge_lgdt3305_config,
1238 &i2c_bus->i2c_adap);
1239 if (fe0->dvb.frontend == NULL)
1241 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1242 0x60, &dev->i2c_bus[1].i2c_adap,
1243 &hauppauge_hvr127x_config);
1244 if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1275)
1245 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1247 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1248 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1249 i2c_bus = &dev->i2c_bus[0];
1250 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1251 &hcw_s5h1411_config,
1252 &i2c_bus->i2c_adap);
1253 if (fe0->dvb.frontend == NULL)
1256 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1257 0x60, &dev->i2c_bus[1].i2c_adap,
1258 &hauppauge_tda18271_config);
1260 tda18271_attach(&dev->ts1.analog_fe,
1261 0x60, &dev->i2c_bus[1].i2c_adap,
1262 &hauppauge_tda18271_config);
1265 case CX23885_BOARD_HAUPPAUGE_HVR1800:
1266 i2c_bus = &dev->i2c_bus[0];
1267 switch (alt_tuner) {
1270 dvb_attach(s5h1409_attach,
1271 &hauppauge_ezqam_config,
1272 &i2c_bus->i2c_adap);
1273 if (fe0->dvb.frontend == NULL)
1276 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1277 &dev->i2c_bus[1].i2c_adap, 0x42,
1279 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1280 0x60, &dev->i2c_bus[1].i2c_adap,
1281 &hauppauge_tda18271_config);
1286 dvb_attach(s5h1409_attach,
1287 &hauppauge_generic_config,
1288 &i2c_bus->i2c_adap);
1289 if (fe0->dvb.frontend == NULL)
1291 dvb_attach(mt2131_attach, fe0->dvb.frontend,
1293 &hauppauge_generic_tunerconfig, 0);
1296 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
1297 i2c_bus = &dev->i2c_bus[0];
1298 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1299 &hauppauge_hvr1800lp_config,
1300 &i2c_bus->i2c_adap);
1301 if (fe0->dvb.frontend == NULL)
1303 dvb_attach(mt2131_attach, fe0->dvb.frontend,
1305 &hauppauge_generic_tunerconfig, 0);
1307 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
1308 i2c_bus = &dev->i2c_bus[0];
1309 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
1310 &fusionhdtv_5_express,
1311 &i2c_bus->i2c_adap);
1312 if (fe0->dvb.frontend == NULL)
1314 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1315 &i2c_bus->i2c_adap, 0x61,
1316 TUNER_LG_TDVS_H06XF);
1318 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
1319 i2c_bus = &dev->i2c_bus[1];
1320 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1321 &hauppauge_hvr1500q_config,
1322 &dev->i2c_bus[0].i2c_adap);
1323 if (fe0->dvb.frontend == NULL)
1325 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1327 &hauppauge_hvr1500q_tunerconfig);
1329 case CX23885_BOARD_HAUPPAUGE_HVR1500:
1330 i2c_bus = &dev->i2c_bus[1];
1331 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1332 &hauppauge_hvr1500_config,
1333 &dev->i2c_bus[0].i2c_adap);
1334 if (fe0->dvb.frontend != NULL) {
1335 struct dvb_frontend *fe;
1336 struct xc2028_config cfg = {
1337 .i2c_adap = &i2c_bus->i2c_adap,
1340 static struct xc2028_ctrl ctl = {
1341 .fname = "/*(DEBLOBBED)*/",
1343 .demod = XC3028_FE_OREN538,
1346 fe = dvb_attach(xc2028_attach,
1347 fe0->dvb.frontend, &cfg);
1348 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1349 fe->ops.tuner_ops.set_config(fe, &ctl);
1352 case CX23885_BOARD_HAUPPAUGE_HVR1200:
1353 case CX23885_BOARD_HAUPPAUGE_HVR1700:
1354 i2c_bus = &dev->i2c_bus[0];
1355 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1356 &hauppauge_hvr1200_config,
1357 &i2c_bus->i2c_adap);
1358 if (fe0->dvb.frontend == NULL)
1360 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1361 &dev->i2c_bus[1].i2c_adap, 0x42,
1363 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1364 0x60, &dev->i2c_bus[1].i2c_adap,
1365 &hauppauge_hvr1200_tuner_config);
1367 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1368 i2c_bus = &dev->i2c_bus[0];
1369 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1370 &hauppauge_hvr1210_config,
1371 &i2c_bus->i2c_adap);
1372 if (fe0->dvb.frontend != NULL) {
1373 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1374 0x60, &dev->i2c_bus[1].i2c_adap,
1375 &hauppauge_hvr1210_tuner_config);
1378 case CX23885_BOARD_HAUPPAUGE_HVR1400:
1379 i2c_bus = &dev->i2c_bus[0];
1381 if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
1384 fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap,
1385 0x12, &hauppauge_hvr1400_dib7000_config);
1386 if (fe0->dvb.frontend != NULL) {
1387 struct dvb_frontend *fe;
1388 struct xc2028_config cfg = {
1389 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
1392 static struct xc2028_ctrl ctl = {
1393 .fname = "/*(DEBLOBBED)*/",
1395 .demod = XC3028_FE_DIBCOM52,
1396 /* This is true for all demods with
1398 .type = XC2028_D2633,
1401 fe = dvb_attach(xc2028_attach,
1402 fe0->dvb.frontend, &cfg);
1403 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1404 fe->ops.tuner_ops.set_config(fe, &ctl);
1407 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
1408 i2c_bus = &dev->i2c_bus[port->nr - 1];
1410 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1411 &dvico_s5h1409_config,
1412 &i2c_bus->i2c_adap);
1413 if (fe0->dvb.frontend == NULL)
1414 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1415 &dvico_s5h1411_config,
1416 &i2c_bus->i2c_adap);
1417 if (fe0->dvb.frontend != NULL)
1418 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1420 &dvico_xc5000_tunerconfig);
1422 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
1423 i2c_bus = &dev->i2c_bus[port->nr - 1];
1425 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1426 &dvico_fusionhdtv_xc3028,
1427 &i2c_bus->i2c_adap);
1428 if (fe0->dvb.frontend != NULL) {
1429 struct dvb_frontend *fe;
1430 struct xc2028_config cfg = {
1431 .i2c_adap = &i2c_bus->i2c_adap,
1434 static struct xc2028_ctrl ctl = {
1435 .fname = "/*(DEBLOBBED)*/",
1437 .demod = XC3028_FE_ZARLINK456,
1440 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
1442 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1443 fe->ops.tuner_ops.set_config(fe, &ctl);
1447 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2: {
1448 i2c_bus = &dev->i2c_bus[port->nr - 1];
1449 /* cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); */
1450 /* cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1); */
1452 if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
1455 if (dib7000p_ops.i2c_enumeration(&i2c_bus->i2c_adap, 1, 0x12, &dib7070p_dib7000p_config) < 0) {
1456 pr_warn("Unable to enumerate dib7000p\n");
1459 fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap, 0x80, &dib7070p_dib7000p_config);
1460 if (fe0->dvb.frontend != NULL) {
1461 struct i2c_adapter *tun_i2c;
1463 fe0->dvb.frontend->sec_priv = kmemdup(&dib7000p_ops, sizeof(dib7000p_ops), GFP_KERNEL);
1464 if (!fe0->dvb.frontend->sec_priv)
1466 tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1);
1467 if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config))
1472 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1473 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1474 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
1475 i2c_bus = &dev->i2c_bus[0];
1477 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1478 &dvico_fusionhdtv_xc3028,
1479 &i2c_bus->i2c_adap);
1480 if (fe0->dvb.frontend != NULL) {
1481 struct dvb_frontend *fe;
1482 struct xc2028_config cfg = {
1483 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
1486 static struct xc2028_ctrl ctl = {
1487 .fname = "/*(DEBLOBBED)*/",
1489 .demod = XC3028_FE_ZARLINK456,
1492 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
1494 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1495 fe->ops.tuner_ops.set_config(fe, &ctl);
1498 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1499 i2c_bus = &dev->i2c_bus[0];
1501 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1502 &dvico_fusionhdtv_xc3028,
1503 &i2c_bus->i2c_adap);
1504 if (fe0->dvb.frontend != NULL) {
1505 struct dvb_frontend *fe;
1506 struct xc4000_config cfg = {
1507 .i2c_address = 0x61,
1509 .dvb_amplitude = 134,
1510 .set_smoothedcvbs = 1,
1514 fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
1515 &dev->i2c_bus[1].i2c_adap, &cfg);
1517 pr_err("%s/2: xc4000 attach failed\n",
1519 goto frontend_detach;
1523 case CX23885_BOARD_TBS_6920:
1524 i2c_bus = &dev->i2c_bus[1];
1526 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1527 &tbs_cx24116_config,
1528 &i2c_bus->i2c_adap);
1529 if (fe0->dvb.frontend != NULL)
1530 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1533 case CX23885_BOARD_TBS_6980:
1534 case CX23885_BOARD_TBS_6981:
1535 i2c_bus = &dev->i2c_bus[1];
1540 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1541 &tbs_cx24117_config,
1542 &i2c_bus->i2c_adap);
1546 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1547 &tbs_cx24117_config,
1548 &i2c_bus->i2c_adap);
1552 case CX23885_BOARD_TEVII_S470:
1553 i2c_bus = &dev->i2c_bus[1];
1555 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1556 &tevii_ds3000_config,
1557 &i2c_bus->i2c_adap);
1558 if (fe0->dvb.frontend != NULL) {
1559 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1560 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1561 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1565 case CX23885_BOARD_DVBWORLD_2005:
1566 i2c_bus = &dev->i2c_bus[1];
1568 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1569 &dvbworld_cx24116_config,
1570 &i2c_bus->i2c_adap);
1572 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1573 i2c_bus = &dev->i2c_bus[0];
1577 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1578 &netup_stv0900_config,
1579 &i2c_bus->i2c_adap, 0);
1580 if (fe0->dvb.frontend != NULL) {
1581 if (dvb_attach(stv6110_attach,
1583 &netup_stv6110_tunerconfig_a,
1584 &i2c_bus->i2c_adap)) {
1585 if (!dvb_attach(lnbh24_attach,
1588 LNBH24_PCL | LNBH24_TTX,
1590 pr_err("No LNBH24 found!\n");
1597 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1598 &netup_stv0900_config,
1599 &i2c_bus->i2c_adap, 1);
1600 if (fe0->dvb.frontend != NULL) {
1601 if (dvb_attach(stv6110_attach,
1603 &netup_stv6110_tunerconfig_b,
1604 &i2c_bus->i2c_adap)) {
1605 if (!dvb_attach(lnbh24_attach,
1608 LNBH24_PCL | LNBH24_TTX,
1610 pr_err("No LNBH24 found!\n");
1617 case CX23885_BOARD_MYGICA_X8506:
1618 i2c_bus = &dev->i2c_bus[0];
1619 i2c_bus2 = &dev->i2c_bus[1];
1620 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1621 &mygica_x8506_lgs8gl5_config,
1622 &i2c_bus->i2c_adap);
1623 if (fe0->dvb.frontend == NULL)
1625 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1626 &i2c_bus2->i2c_adap, &mygica_x8506_xc5000_config);
1627 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1629 case CX23885_BOARD_MYGICA_X8507:
1630 i2c_bus = &dev->i2c_bus[0];
1631 i2c_bus2 = &dev->i2c_bus[1];
1632 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1633 &mygica_x8507_mb86a20s_config,
1634 &i2c_bus->i2c_adap);
1635 if (fe0->dvb.frontend == NULL)
1638 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1639 &i2c_bus2->i2c_adap,
1640 &mygica_x8507_xc5000_config);
1641 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1643 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1644 i2c_bus = &dev->i2c_bus[0];
1645 i2c_bus2 = &dev->i2c_bus[1];
1646 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1647 &magicpro_prohdtve2_lgs8g75_config,
1648 &i2c_bus->i2c_adap);
1649 if (fe0->dvb.frontend == NULL)
1651 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1652 &i2c_bus2->i2c_adap,
1653 &magicpro_prohdtve2_xc5000_config);
1654 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1656 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1657 i2c_bus = &dev->i2c_bus[0];
1658 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1659 &hcw_s5h1411_config,
1660 &i2c_bus->i2c_adap);
1661 if (fe0->dvb.frontend == NULL)
1663 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1664 0x60, &dev->i2c_bus[0].i2c_adap,
1665 &hauppauge_tda18271_config);
1667 tda18271_attach(&dev->ts1.analog_fe,
1668 0x60, &dev->i2c_bus[1].i2c_adap,
1669 &hauppauge_tda18271_config);
1672 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1673 i2c_bus = &dev->i2c_bus[0];
1674 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1675 &hcw_s5h1411_config,
1676 &i2c_bus->i2c_adap);
1677 if (fe0->dvb.frontend == NULL)
1679 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1680 0x60, &dev->i2c_bus[0].i2c_adap,
1681 &hauppauge_tda18271_config);
1683 case CX23885_BOARD_MYGICA_X8558PRO:
1687 i2c_bus = &dev->i2c_bus[0];
1688 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1689 &mygica_x8558pro_atbm8830_cfg1,
1690 &i2c_bus->i2c_adap);
1691 if (fe0->dvb.frontend == NULL)
1693 dvb_attach(max2165_attach, fe0->dvb.frontend,
1695 &mygic_x8558pro_max2165_cfg1);
1699 i2c_bus = &dev->i2c_bus[1];
1700 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1701 &mygica_x8558pro_atbm8830_cfg2,
1702 &i2c_bus->i2c_adap);
1703 if (fe0->dvb.frontend == NULL)
1705 dvb_attach(max2165_attach, fe0->dvb.frontend,
1707 &mygic_x8558pro_max2165_cfg2);
1710 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1714 i2c_bus = &dev->i2c_bus[0];
1715 mfe_shared = 1;/* MFE */
1716 port->frontends.gate = 0;/* not clear for me yet */
1718 /* MFE frontend 1 DVB-T */
1719 fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
1720 &netup_stv0367_config[port->nr - 1],
1721 &i2c_bus->i2c_adap);
1722 if (fe0->dvb.frontend == NULL)
1724 if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend,
1726 &netup_xc5000_config[port->nr - 1]))
1727 goto frontend_detach;
1728 /* load xc5000 firmware */
1729 fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
1731 /* MFE frontend 2 */
1732 fe1 = vb2_dvb_get_frontend(&port->frontends, 2);
1734 goto frontend_detach;
1736 fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
1737 &netup_stv0367_config[port->nr - 1],
1738 &i2c_bus->i2c_adap);
1739 if (fe1->dvb.frontend == NULL)
1742 fe1->dvb.frontend->id = 1;
1743 if (NULL == dvb_attach(xc5000_attach,
1746 &netup_xc5000_config[port->nr - 1]))
1747 goto frontend_detach;
1749 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1750 i2c_bus = &dev->i2c_bus[0];
1751 i2c_bus2 = &dev->i2c_bus[1];
1756 fe0->dvb.frontend = dvb_attach(drxk_attach,
1757 &terratec_drxk_config[0],
1758 &i2c_bus->i2c_adap);
1759 if (fe0->dvb.frontend == NULL)
1761 if (!dvb_attach(mt2063_attach,
1763 &terratec_mt2063_config[0],
1764 &i2c_bus2->i2c_adap))
1765 goto frontend_detach;
1769 fe0->dvb.frontend = dvb_attach(drxk_attach,
1770 &terratec_drxk_config[1],
1771 &i2c_bus->i2c_adap);
1772 if (fe0->dvb.frontend == NULL)
1774 if (!dvb_attach(mt2063_attach,
1776 &terratec_mt2063_config[1],
1777 &i2c_bus2->i2c_adap))
1778 goto frontend_detach;
1782 case CX23885_BOARD_TEVII_S471:
1783 i2c_bus = &dev->i2c_bus[1];
1785 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1786 &tevii_ds3000_config,
1787 &i2c_bus->i2c_adap);
1788 if (fe0->dvb.frontend == NULL)
1790 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1791 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1793 case CX23885_BOARD_PROF_8000:
1794 i2c_bus = &dev->i2c_bus[0];
1796 fe0->dvb.frontend = dvb_attach(stv090x_attach,
1797 &prof_8000_stv090x_config,
1799 STV090x_DEMODULATOR_0);
1800 if (fe0->dvb.frontend == NULL)
1802 if (!dvb_attach(stb6100_attach,
1804 &prof_8000_stb6100_config,
1805 &i2c_bus->i2c_adap))
1806 goto frontend_detach;
1808 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
1810 case CX23885_BOARD_HAUPPAUGE_HVR4400: {
1811 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1812 struct a8293_platform_data a8293_pdata = {};
1814 i2c_bus = &dev->i2c_bus[0];
1815 i2c_bus2 = &dev->i2c_bus[1];
1819 /* attach demod + tuner combo */
1820 memset(&info, 0, sizeof(info));
1821 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1823 info.platform_data = &tda10071_pdata;
1824 request_module("tda10071");
1825 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1826 if (!client_demod || !client_demod->dev.driver)
1827 goto frontend_detach;
1828 if (!try_module_get(client_demod->dev.driver->owner)) {
1829 i2c_unregister_device(client_demod);
1830 goto frontend_detach;
1832 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1833 port->i2c_client_demod = client_demod;
1836 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1837 memset(&info, 0, sizeof(info));
1838 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1840 info.platform_data = &a8293_pdata;
1841 request_module("a8293");
1842 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1843 if (!client_sec || !client_sec->dev.driver)
1844 goto frontend_detach;
1845 if (!try_module_get(client_sec->dev.driver->owner)) {
1846 i2c_unregister_device(client_sec);
1847 goto frontend_detach;
1849 port->i2c_client_sec = client_sec;
1853 /* attach frontend */
1854 memset(&si2165_pdata, 0, sizeof(si2165_pdata));
1855 si2165_pdata.fe = &fe0->dvb.frontend;
1856 si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
1857 si2165_pdata.ref_freq_Hz = 16000000,
1858 memset(&info, 0, sizeof(struct i2c_board_info));
1859 strlcpy(info.type, "si2165", I2C_NAME_SIZE);
1861 info.platform_data = &si2165_pdata;
1862 request_module(info.type);
1863 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1864 if (client_demod == NULL ||
1865 client_demod->dev.driver == NULL)
1866 goto frontend_detach;
1867 if (!try_module_get(client_demod->dev.driver->owner)) {
1868 i2c_unregister_device(client_demod);
1869 goto frontend_detach;
1871 port->i2c_client_demod = client_demod;
1873 if (fe0->dvb.frontend == NULL)
1875 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1876 if (!dvb_attach(tda18271_attach,
1878 0x60, &i2c_bus2->i2c_adap,
1879 &hauppauge_hvr4400_tuner_config))
1880 goto frontend_detach;
1885 case CX23885_BOARD_HAUPPAUGE_STARBURST: {
1886 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1887 struct a8293_platform_data a8293_pdata = {};
1889 i2c_bus = &dev->i2c_bus[0];
1891 /* attach demod + tuner combo */
1892 memset(&info, 0, sizeof(info));
1893 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1895 info.platform_data = &tda10071_pdata;
1896 request_module("tda10071");
1897 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1898 if (!client_demod || !client_demod->dev.driver)
1899 goto frontend_detach;
1900 if (!try_module_get(client_demod->dev.driver->owner)) {
1901 i2c_unregister_device(client_demod);
1902 goto frontend_detach;
1904 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1905 port->i2c_client_demod = client_demod;
1908 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1909 memset(&info, 0, sizeof(info));
1910 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1912 info.platform_data = &a8293_pdata;
1913 request_module("a8293");
1914 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1915 if (!client_sec || !client_sec->dev.driver)
1916 goto frontend_detach;
1917 if (!try_module_get(client_sec->dev.driver->owner)) {
1918 i2c_unregister_device(client_sec);
1919 goto frontend_detach;
1921 port->i2c_client_sec = client_sec;
1924 case CX23885_BOARD_DVBSKY_T9580:
1925 case CX23885_BOARD_DVBSKY_S950:
1926 i2c_bus = &dev->i2c_bus[0];
1927 i2c_bus2 = &dev->i2c_bus[1];
1929 /* port b - satellite */
1931 /* attach frontend */
1932 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
1933 &dvbsky_t9580_m88ds3103_config,
1934 &i2c_bus2->i2c_adap, &adapter);
1935 if (fe0->dvb.frontend == NULL)
1939 memset(&ts2020_config, 0, sizeof(ts2020_config));
1940 ts2020_config.fe = fe0->dvb.frontend;
1941 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
1942 memset(&info, 0, sizeof(struct i2c_board_info));
1943 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
1945 info.platform_data = &ts2020_config;
1946 request_module(info.type);
1947 client_tuner = i2c_new_device(adapter, &info);
1948 if (client_tuner == NULL ||
1949 client_tuner->dev.driver == NULL)
1950 goto frontend_detach;
1951 if (!try_module_get(client_tuner->dev.driver->owner)) {
1952 i2c_unregister_device(client_tuner);
1953 goto frontend_detach;
1956 /* delegate signal strength measurement to tuner */
1957 fe0->dvb.frontend->ops.read_signal_strength =
1958 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
1961 * for setting the voltage we need to set GPIOs on
1964 port->fe_set_voltage =
1965 fe0->dvb.frontend->ops.set_voltage;
1966 fe0->dvb.frontend->ops.set_voltage =
1967 dvbsky_t9580_set_voltage;
1969 port->i2c_client_tuner = client_tuner;
1972 /* port c - terrestrial/cable */
1974 /* attach frontend */
1975 memset(&si2168_config, 0, sizeof(si2168_config));
1976 si2168_config.i2c_adapter = &adapter;
1977 si2168_config.fe = &fe0->dvb.frontend;
1978 si2168_config.ts_mode = SI2168_TS_SERIAL;
1979 memset(&info, 0, sizeof(struct i2c_board_info));
1980 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1982 info.platform_data = &si2168_config;
1983 request_module(info.type);
1984 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1985 if (client_demod == NULL ||
1986 client_demod->dev.driver == NULL)
1987 goto frontend_detach;
1988 if (!try_module_get(client_demod->dev.driver->owner)) {
1989 i2c_unregister_device(client_demod);
1990 goto frontend_detach;
1992 port->i2c_client_demod = client_demod;
1995 memset(&si2157_config, 0, sizeof(si2157_config));
1996 si2157_config.fe = fe0->dvb.frontend;
1997 si2157_config.if_port = 1;
1998 memset(&info, 0, sizeof(struct i2c_board_info));
1999 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2001 info.platform_data = &si2157_config;
2002 request_module(info.type);
2003 client_tuner = i2c_new_device(adapter, &info);
2004 if (client_tuner == NULL ||
2005 client_tuner->dev.driver == NULL)
2006 goto frontend_detach;
2008 if (!try_module_get(client_tuner->dev.driver->owner)) {
2009 i2c_unregister_device(client_tuner);
2010 goto frontend_detach;
2012 port->i2c_client_tuner = client_tuner;
2016 case CX23885_BOARD_DVBSKY_T980C:
2017 case CX23885_BOARD_TT_CT2_4500_CI:
2018 i2c_bus = &dev->i2c_bus[0];
2019 i2c_bus2 = &dev->i2c_bus[1];
2021 /* attach frontend */
2022 memset(&si2168_config, 0, sizeof(si2168_config));
2023 si2168_config.i2c_adapter = &adapter;
2024 si2168_config.fe = &fe0->dvb.frontend;
2025 si2168_config.ts_mode = SI2168_TS_PARALLEL;
2026 memset(&info, 0, sizeof(struct i2c_board_info));
2027 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2029 info.platform_data = &si2168_config;
2030 request_module(info.type);
2031 client_demod = i2c_new_device(&i2c_bus2->i2c_adap, &info);
2032 if (client_demod == NULL || client_demod->dev.driver == NULL)
2033 goto frontend_detach;
2034 if (!try_module_get(client_demod->dev.driver->owner)) {
2035 i2c_unregister_device(client_demod);
2036 goto frontend_detach;
2038 port->i2c_client_demod = client_demod;
2041 memset(&si2157_config, 0, sizeof(si2157_config));
2042 si2157_config.fe = fe0->dvb.frontend;
2043 si2157_config.if_port = 1;
2044 memset(&info, 0, sizeof(struct i2c_board_info));
2045 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2047 info.platform_data = &si2157_config;
2048 request_module(info.type);
2049 client_tuner = i2c_new_device(adapter, &info);
2050 if (client_tuner == NULL ||
2051 client_tuner->dev.driver == NULL)
2052 goto frontend_detach;
2053 if (!try_module_get(client_tuner->dev.driver->owner)) {
2054 i2c_unregister_device(client_tuner);
2055 goto frontend_detach;
2057 port->i2c_client_tuner = client_tuner;
2059 case CX23885_BOARD_DVBSKY_S950C:
2060 i2c_bus = &dev->i2c_bus[0];
2061 i2c_bus2 = &dev->i2c_bus[1];
2063 /* attach frontend */
2064 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2065 &dvbsky_s950c_m88ds3103_config,
2066 &i2c_bus2->i2c_adap, &adapter);
2067 if (fe0->dvb.frontend == NULL)
2071 memset(&ts2020_config, 0, sizeof(ts2020_config));
2072 ts2020_config.fe = fe0->dvb.frontend;
2073 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2074 memset(&info, 0, sizeof(struct i2c_board_info));
2075 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2077 info.platform_data = &ts2020_config;
2078 request_module(info.type);
2079 client_tuner = i2c_new_device(adapter, &info);
2080 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
2081 goto frontend_detach;
2082 if (!try_module_get(client_tuner->dev.driver->owner)) {
2083 i2c_unregister_device(client_tuner);
2084 goto frontend_detach;
2087 /* delegate signal strength measurement to tuner */
2088 fe0->dvb.frontend->ops.read_signal_strength =
2089 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2091 port->i2c_client_tuner = client_tuner;
2093 case CX23885_BOARD_DVBSKY_S952:
2094 /* attach frontend */
2095 memset(&m88ds3103_pdata, 0, sizeof(m88ds3103_pdata));
2096 m88ds3103_pdata.clk = 27000000;
2097 m88ds3103_pdata.i2c_wr_max = 33;
2098 m88ds3103_pdata.agc = 0x99;
2099 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_DISABLED;
2100 m88ds3103_pdata.lnb_en_pol = 1;
2105 i2c_bus = &dev->i2c_bus[1];
2106 m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
2107 m88ds3103_pdata.ts_clk = 16000;
2108 m88ds3103_pdata.ts_clk_pol = 1;
2109 p_set_voltage = dvbsky_t9580_set_voltage;
2113 i2c_bus = &dev->i2c_bus[0];
2114 m88ds3103_pdata.ts_mode = M88DS3103_TS_SERIAL;
2115 m88ds3103_pdata.ts_clk = 96000;
2116 m88ds3103_pdata.ts_clk_pol = 0;
2117 p_set_voltage = dvbsky_s952_portc_set_voltage;
2123 memset(&info, 0, sizeof(info));
2124 strlcpy(info.type, "m88ds3103", I2C_NAME_SIZE);
2126 info.platform_data = &m88ds3103_pdata;
2127 request_module(info.type);
2128 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
2129 if (client_demod == NULL || client_demod->dev.driver == NULL)
2130 goto frontend_detach;
2131 if (!try_module_get(client_demod->dev.driver->owner)) {
2132 i2c_unregister_device(client_demod);
2133 goto frontend_detach;
2135 port->i2c_client_demod = client_demod;
2136 adapter = m88ds3103_pdata.get_i2c_adapter(client_demod);
2137 fe0->dvb.frontend = m88ds3103_pdata.get_dvb_frontend(client_demod);
2140 memset(&ts2020_config, 0, sizeof(ts2020_config));
2141 ts2020_config.fe = fe0->dvb.frontend;
2142 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2143 memset(&info, 0, sizeof(struct i2c_board_info));
2144 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2146 info.platform_data = &ts2020_config;
2147 request_module(info.type);
2148 client_tuner = i2c_new_device(adapter, &info);
2149 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
2150 goto frontend_detach;
2151 if (!try_module_get(client_tuner->dev.driver->owner)) {
2152 i2c_unregister_device(client_tuner);
2153 goto frontend_detach;
2156 /* delegate signal strength measurement to tuner */
2157 fe0->dvb.frontend->ops.read_signal_strength =
2158 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2161 * for setting the voltage we need to set GPIOs on
2164 port->fe_set_voltage =
2165 fe0->dvb.frontend->ops.set_voltage;
2166 fe0->dvb.frontend->ops.set_voltage = p_set_voltage;
2168 port->i2c_client_tuner = client_tuner;
2170 case CX23885_BOARD_DVBSKY_T982:
2171 memset(&si2168_config, 0, sizeof(si2168_config));
2175 i2c_bus = &dev->i2c_bus[1];
2176 si2168_config.ts_mode = SI2168_TS_PARALLEL;
2180 i2c_bus = &dev->i2c_bus[0];
2181 si2168_config.ts_mode = SI2168_TS_SERIAL;
2185 /* attach frontend */
2186 si2168_config.i2c_adapter = &adapter;
2187 si2168_config.fe = &fe0->dvb.frontend;
2188 memset(&info, 0, sizeof(struct i2c_board_info));
2189 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2191 info.platform_data = &si2168_config;
2192 request_module(info.type);
2193 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
2194 if (client_demod == NULL || client_demod->dev.driver == NULL)
2195 goto frontend_detach;
2196 if (!try_module_get(client_demod->dev.driver->owner)) {
2197 i2c_unregister_device(client_demod);
2198 goto frontend_detach;
2200 port->i2c_client_demod = client_demod;
2203 memset(&si2157_config, 0, sizeof(si2157_config));
2204 si2157_config.fe = fe0->dvb.frontend;
2205 si2157_config.if_port = 1;
2206 memset(&info, 0, sizeof(struct i2c_board_info));
2207 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2209 info.platform_data = &si2157_config;
2210 request_module(info.type);
2211 client_tuner = i2c_new_device(adapter, &info);
2212 if (client_tuner == NULL ||
2213 client_tuner->dev.driver == NULL)
2214 goto frontend_detach;
2215 if (!try_module_get(client_tuner->dev.driver->owner)) {
2216 i2c_unregister_device(client_tuner);
2217 goto frontend_detach;
2219 port->i2c_client_tuner = client_tuner;
2221 case CX23885_BOARD_HAUPPAUGE_HVR5525: {
2222 struct m88rs6000t_config m88rs6000t_config;
2223 struct a8293_platform_data a8293_pdata = {};
2227 /* port b - satellite */
2229 /* attach frontend */
2230 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2231 &hauppauge_hvr5525_m88ds3103_config,
2232 &dev->i2c_bus[0].i2c_adap, &adapter);
2233 if (fe0->dvb.frontend == NULL)
2237 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
2238 memset(&info, 0, sizeof(info));
2239 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
2241 info.platform_data = &a8293_pdata;
2242 request_module("a8293");
2243 client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2244 if (!client_sec || !client_sec->dev.driver)
2245 goto frontend_detach;
2246 if (!try_module_get(client_sec->dev.driver->owner)) {
2247 i2c_unregister_device(client_sec);
2248 goto frontend_detach;
2250 port->i2c_client_sec = client_sec;
2253 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
2254 m88rs6000t_config.fe = fe0->dvb.frontend;
2255 memset(&info, 0, sizeof(struct i2c_board_info));
2256 strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE);
2258 info.platform_data = &m88rs6000t_config;
2259 request_module("%s", info.type);
2260 client_tuner = i2c_new_device(adapter, &info);
2261 if (!client_tuner || !client_tuner->dev.driver)
2262 goto frontend_detach;
2263 if (!try_module_get(client_tuner->dev.driver->owner)) {
2264 i2c_unregister_device(client_tuner);
2265 goto frontend_detach;
2267 port->i2c_client_tuner = client_tuner;
2269 /* delegate signal strength measurement to tuner */
2270 fe0->dvb.frontend->ops.read_signal_strength =
2271 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2273 /* port c - terrestrial/cable */
2275 /* attach frontend */
2276 memset(&si2168_config, 0, sizeof(si2168_config));
2277 si2168_config.i2c_adapter = &adapter;
2278 si2168_config.fe = &fe0->dvb.frontend;
2279 si2168_config.ts_mode = SI2168_TS_SERIAL;
2280 memset(&info, 0, sizeof(struct i2c_board_info));
2281 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2283 info.platform_data = &si2168_config;
2284 request_module("%s", info.type);
2285 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2286 if (!client_demod || !client_demod->dev.driver)
2287 goto frontend_detach;
2288 if (!try_module_get(client_demod->dev.driver->owner)) {
2289 i2c_unregister_device(client_demod);
2290 goto frontend_detach;
2292 port->i2c_client_demod = client_demod;
2295 memset(&si2157_config, 0, sizeof(si2157_config));
2296 si2157_config.fe = fe0->dvb.frontend;
2297 si2157_config.if_port = 1;
2298 memset(&info, 0, sizeof(struct i2c_board_info));
2299 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2301 info.platform_data = &si2157_config;
2302 request_module("%s", info.type);
2303 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2304 if (!client_tuner || !client_tuner->dev.driver) {
2305 module_put(client_demod->dev.driver->owner);
2306 i2c_unregister_device(client_demod);
2307 port->i2c_client_demod = NULL;
2308 goto frontend_detach;
2310 if (!try_module_get(client_tuner->dev.driver->owner)) {
2311 i2c_unregister_device(client_tuner);
2312 module_put(client_demod->dev.driver->owner);
2313 i2c_unregister_device(client_demod);
2314 port->i2c_client_demod = NULL;
2315 goto frontend_detach;
2317 port->i2c_client_tuner = client_tuner;
2322 case CX23885_BOARD_HAUPPAUGE_QUADHD_DVB:
2324 /* port b - Terrestrial/cable */
2326 /* attach frontend */
2327 memset(&si2168_config, 0, sizeof(si2168_config));
2328 si2168_config.i2c_adapter = &adapter;
2329 si2168_config.fe = &fe0->dvb.frontend;
2330 si2168_config.ts_mode = SI2168_TS_SERIAL;
2331 memset(&info, 0, sizeof(struct i2c_board_info));
2332 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2334 info.platform_data = &si2168_config;
2335 request_module("%s", info.type);
2336 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2337 if (!client_demod || !client_demod->dev.driver)
2338 goto frontend_detach;
2339 if (!try_module_get(client_demod->dev.driver->owner)) {
2340 i2c_unregister_device(client_demod);
2341 goto frontend_detach;
2343 port->i2c_client_demod = client_demod;
2346 memset(&si2157_config, 0, sizeof(si2157_config));
2347 si2157_config.fe = fe0->dvb.frontend;
2348 si2157_config.if_port = 1;
2349 memset(&info, 0, sizeof(struct i2c_board_info));
2350 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2352 info.platform_data = &si2157_config;
2353 request_module("%s", info.type);
2354 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2355 if (!client_tuner || !client_tuner->dev.driver) {
2356 module_put(client_demod->dev.driver->owner);
2357 i2c_unregister_device(client_demod);
2358 port->i2c_client_demod = NULL;
2359 goto frontend_detach;
2361 if (!try_module_get(client_tuner->dev.driver->owner)) {
2362 i2c_unregister_device(client_tuner);
2363 module_put(client_demod->dev.driver->owner);
2364 i2c_unregister_device(client_demod);
2365 port->i2c_client_demod = NULL;
2366 goto frontend_detach;
2368 port->i2c_client_tuner = client_tuner;
2371 /* port c - terrestrial/cable */
2373 /* attach frontend */
2374 memset(&si2168_config, 0, sizeof(si2168_config));
2375 si2168_config.i2c_adapter = &adapter;
2376 si2168_config.fe = &fe0->dvb.frontend;
2377 si2168_config.ts_mode = SI2168_TS_SERIAL;
2378 memset(&info, 0, sizeof(struct i2c_board_info));
2379 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2381 info.platform_data = &si2168_config;
2382 request_module("%s", info.type);
2383 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2384 if (!client_demod || !client_demod->dev.driver)
2385 goto frontend_detach;
2386 if (!try_module_get(client_demod->dev.driver->owner)) {
2387 i2c_unregister_device(client_demod);
2388 goto frontend_detach;
2390 port->i2c_client_demod = client_demod;
2393 memset(&si2157_config, 0, sizeof(si2157_config));
2394 si2157_config.fe = fe0->dvb.frontend;
2395 si2157_config.if_port = 1;
2396 memset(&info, 0, sizeof(struct i2c_board_info));
2397 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2399 info.platform_data = &si2157_config;
2400 request_module("%s", info.type);
2401 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2402 if (!client_tuner || !client_tuner->dev.driver) {
2403 module_put(client_demod->dev.driver->owner);
2404 i2c_unregister_device(client_demod);
2405 port->i2c_client_demod = NULL;
2406 goto frontend_detach;
2408 if (!try_module_get(client_tuner->dev.driver->owner)) {
2409 i2c_unregister_device(client_tuner);
2410 module_put(client_demod->dev.driver->owner);
2411 i2c_unregister_device(client_demod);
2412 port->i2c_client_demod = NULL;
2413 goto frontend_detach;
2415 port->i2c_client_tuner = client_tuner;
2419 case CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC:
2421 /* port b - Terrestrial/cable */
2423 /* attach frontend */
2424 i2c_bus = &dev->i2c_bus[0];
2425 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
2426 &hauppauge_quadHD_ATSC_a_config, &i2c_bus->i2c_adap);
2427 if (fe0->dvb.frontend == NULL)
2431 memset(&si2157_config, 0, sizeof(si2157_config));
2432 si2157_config.fe = fe0->dvb.frontend;
2433 si2157_config.if_port = 1;
2434 si2157_config.inversion = 1;
2435 memset(&info, 0, sizeof(struct i2c_board_info));
2436 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2438 info.platform_data = &si2157_config;
2439 request_module("%s", info.type);
2440 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2441 if (!client_tuner || !client_tuner->dev.driver) {
2442 module_put(client_demod->dev.driver->owner);
2443 i2c_unregister_device(client_demod);
2444 port->i2c_client_demod = NULL;
2445 goto frontend_detach;
2447 if (!try_module_get(client_tuner->dev.driver->owner)) {
2448 i2c_unregister_device(client_tuner);
2449 module_put(client_demod->dev.driver->owner);
2450 i2c_unregister_device(client_demod);
2451 port->i2c_client_demod = NULL;
2452 goto frontend_detach;
2454 port->i2c_client_tuner = client_tuner;
2457 /* port c - terrestrial/cable */
2459 /* attach frontend */
2460 i2c_bus = &dev->i2c_bus[0];
2461 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
2462 &hauppauge_quadHD_ATSC_b_config, &i2c_bus->i2c_adap);
2463 if (fe0->dvb.frontend == NULL)
2467 memset(&si2157_config, 0, sizeof(si2157_config));
2468 si2157_config.fe = fe0->dvb.frontend;
2469 si2157_config.if_port = 1;
2470 si2157_config.inversion = 1;
2471 memset(&info, 0, sizeof(struct i2c_board_info));
2472 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2474 info.platform_data = &si2157_config;
2475 request_module("%s", info.type);
2476 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2477 if (!client_tuner || !client_tuner->dev.driver) {
2478 module_put(client_demod->dev.driver->owner);
2479 i2c_unregister_device(client_demod);
2480 port->i2c_client_demod = NULL;
2481 goto frontend_detach;
2483 if (!try_module_get(client_tuner->dev.driver->owner)) {
2484 i2c_unregister_device(client_tuner);
2485 module_put(client_demod->dev.driver->owner);
2486 i2c_unregister_device(client_demod);
2487 port->i2c_client_demod = NULL;
2488 goto frontend_detach;
2490 port->i2c_client_tuner = client_tuner;
2496 pr_info("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
2501 if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
2502 pr_err("%s: frontend initialization failed\n",
2504 goto frontend_detach;
2507 /* define general-purpose callback pointer */
2508 fe0->dvb.frontend->callback = cx23885_tuner_callback;
2510 fe1->dvb.frontend->callback = cx23885_tuner_callback;
2512 /* Ensure all frontends negotiate bus access */
2513 fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
2515 fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
2518 /* Put the analog decoder in standby to keep it quiet */
2519 call_all(dev, core, s_power, 0);
2521 if (fe0->dvb.frontend->ops.analog_ops.standby)
2522 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
2524 /* register everything */
2525 ret = vb2_dvb_register_bus(&port->frontends, THIS_MODULE, port,
2526 &dev->pci->dev, NULL,
2527 adapter_nr, mfe_shared);
2529 goto frontend_detach;
2531 ret = dvb_register_ci_mac(port);
2533 goto frontend_detach;
2538 /* remove I2C client for SEC */
2539 client_sec = port->i2c_client_sec;
2541 module_put(client_sec->dev.driver->owner);
2542 i2c_unregister_device(client_sec);
2543 port->i2c_client_sec = NULL;
2546 /* remove I2C client for tuner */
2547 client_tuner = port->i2c_client_tuner;
2549 module_put(client_tuner->dev.driver->owner);
2550 i2c_unregister_device(client_tuner);
2551 port->i2c_client_tuner = NULL;
2554 /* remove I2C client for demodulator */
2555 client_demod = port->i2c_client_demod;
2557 module_put(client_demod->dev.driver->owner);
2558 i2c_unregister_device(client_demod);
2559 port->i2c_client_demod = NULL;
2562 port->gate_ctrl = NULL;
2563 vb2_dvb_dealloc_frontends(&port->frontends);
2567 int cx23885_dvb_register(struct cx23885_tsport *port)
2570 struct vb2_dvb_frontend *fe0;
2571 struct cx23885_dev *dev = port->dev;
2574 /* Here we need to allocate the correct number of frontends,
2575 * as reflected in the cards struct. The reality is that currently
2576 * no cx23885 boards support this - yet. But, if we don't modify this
2577 * code then the second frontend would never be allocated (later)
2578 * and fail with error before the attach in dvb_register().
2579 * Without these changes we risk an OOPS later. The changes here
2580 * are for safety, and should provide a good foundation for the
2581 * future addition of any multi-frontend cx23885 based boards.
2583 pr_info("%s() allocating %d frontend(s)\n", __func__,
2584 port->num_frontends);
2586 for (i = 1; i <= port->num_frontends; i++) {
2587 struct vb2_queue *q;
2589 if (vb2_dvb_alloc_frontend(
2590 &port->frontends, i) == NULL) {
2591 pr_err("%s() failed to alloc\n", __func__);
2595 fe0 = vb2_dvb_get_frontend(&port->frontends, i);
2599 dprintk(1, "%s\n", __func__);
2600 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
2609 /* We have to init the queue for each frontend on a port. */
2610 pr_info("%s: cx23885 based dvb card\n", dev->name);
2612 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2613 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
2614 q->gfp_flags = GFP_DMA32;
2615 q->min_buffers_needed = 2;
2617 q->buf_struct_size = sizeof(struct cx23885_buffer);
2619 q->mem_ops = &vb2_dma_sg_memops;
2620 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2621 q->lock = &dev->lock;
2622 q->dev = &dev->pci->dev;
2624 err = vb2_queue_init(q);
2628 err = dvb_register(port);
2630 pr_err("%s() dvb_register failed err = %d\n",
2636 int cx23885_dvb_unregister(struct cx23885_tsport *port)
2638 struct vb2_dvb_frontend *fe0;
2639 struct i2c_client *client;
2641 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
2643 if (fe0 && fe0->dvb.frontend)
2644 vb2_dvb_unregister_bus(&port->frontends);
2646 /* remove I2C client for CI */
2647 client = port->i2c_client_ci;
2649 module_put(client->dev.driver->owner);
2650 i2c_unregister_device(client);
2653 /* remove I2C client for SEC */
2654 client = port->i2c_client_sec;
2656 module_put(client->dev.driver->owner);
2657 i2c_unregister_device(client);
2660 /* remove I2C client for tuner */
2661 client = port->i2c_client_tuner;
2663 module_put(client->dev.driver->owner);
2664 i2c_unregister_device(client);
2667 /* remove I2C client for demodulator */
2668 client = port->i2c_client_demod;
2670 module_put(client->dev.driver->owner);
2671 i2c_unregister_device(client);
2674 switch (port->dev->board) {
2675 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
2676 netup_ci_exit(port);
2678 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
2679 altera_ci_release(port->dev, port->nr);
2683 port->gate_ctrl = NULL;