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 = XC2028_DEFAULT_FIRMWARE,
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 = XC3028L_DEFAULT_FIRMWARE,
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 = XC2028_DEFAULT_FIRMWARE,
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 = kmalloc(sizeof(dib7000p_ops), GFP_KERNEL);
1464 memcpy(fe0->dvb.frontend->sec_priv, &dib7000p_ops, sizeof(dib7000p_ops));
1465 tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1);
1466 if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config))
1471 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1472 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1473 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
1474 i2c_bus = &dev->i2c_bus[0];
1476 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1477 &dvico_fusionhdtv_xc3028,
1478 &i2c_bus->i2c_adap);
1479 if (fe0->dvb.frontend != NULL) {
1480 struct dvb_frontend *fe;
1481 struct xc2028_config cfg = {
1482 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
1485 static struct xc2028_ctrl ctl = {
1486 .fname = XC2028_DEFAULT_FIRMWARE,
1488 .demod = XC3028_FE_ZARLINK456,
1491 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
1493 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1494 fe->ops.tuner_ops.set_config(fe, &ctl);
1497 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1498 i2c_bus = &dev->i2c_bus[0];
1500 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1501 &dvico_fusionhdtv_xc3028,
1502 &i2c_bus->i2c_adap);
1503 if (fe0->dvb.frontend != NULL) {
1504 struct dvb_frontend *fe;
1505 struct xc4000_config cfg = {
1506 .i2c_address = 0x61,
1508 .dvb_amplitude = 134,
1509 .set_smoothedcvbs = 1,
1513 fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
1514 &dev->i2c_bus[1].i2c_adap, &cfg);
1516 pr_err("%s/2: xc4000 attach failed\n",
1518 goto frontend_detach;
1522 case CX23885_BOARD_TBS_6920:
1523 i2c_bus = &dev->i2c_bus[1];
1525 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1526 &tbs_cx24116_config,
1527 &i2c_bus->i2c_adap);
1528 if (fe0->dvb.frontend != NULL)
1529 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1532 case CX23885_BOARD_TBS_6980:
1533 case CX23885_BOARD_TBS_6981:
1534 i2c_bus = &dev->i2c_bus[1];
1539 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1540 &tbs_cx24117_config,
1541 &i2c_bus->i2c_adap);
1545 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1546 &tbs_cx24117_config,
1547 &i2c_bus->i2c_adap);
1551 case CX23885_BOARD_TEVII_S470:
1552 i2c_bus = &dev->i2c_bus[1];
1554 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1555 &tevii_ds3000_config,
1556 &i2c_bus->i2c_adap);
1557 if (fe0->dvb.frontend != NULL) {
1558 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1559 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1560 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1564 case CX23885_BOARD_DVBWORLD_2005:
1565 i2c_bus = &dev->i2c_bus[1];
1567 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1568 &dvbworld_cx24116_config,
1569 &i2c_bus->i2c_adap);
1571 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1572 i2c_bus = &dev->i2c_bus[0];
1576 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1577 &netup_stv0900_config,
1578 &i2c_bus->i2c_adap, 0);
1579 if (fe0->dvb.frontend != NULL) {
1580 if (dvb_attach(stv6110_attach,
1582 &netup_stv6110_tunerconfig_a,
1583 &i2c_bus->i2c_adap)) {
1584 if (!dvb_attach(lnbh24_attach,
1587 LNBH24_PCL | LNBH24_TTX,
1589 pr_err("No LNBH24 found!\n");
1596 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1597 &netup_stv0900_config,
1598 &i2c_bus->i2c_adap, 1);
1599 if (fe0->dvb.frontend != NULL) {
1600 if (dvb_attach(stv6110_attach,
1602 &netup_stv6110_tunerconfig_b,
1603 &i2c_bus->i2c_adap)) {
1604 if (!dvb_attach(lnbh24_attach,
1607 LNBH24_PCL | LNBH24_TTX,
1609 pr_err("No LNBH24 found!\n");
1616 case CX23885_BOARD_MYGICA_X8506:
1617 i2c_bus = &dev->i2c_bus[0];
1618 i2c_bus2 = &dev->i2c_bus[1];
1619 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1620 &mygica_x8506_lgs8gl5_config,
1621 &i2c_bus->i2c_adap);
1622 if (fe0->dvb.frontend == NULL)
1624 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1625 &i2c_bus2->i2c_adap, &mygica_x8506_xc5000_config);
1626 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1628 case CX23885_BOARD_MYGICA_X8507:
1629 i2c_bus = &dev->i2c_bus[0];
1630 i2c_bus2 = &dev->i2c_bus[1];
1631 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1632 &mygica_x8507_mb86a20s_config,
1633 &i2c_bus->i2c_adap);
1634 if (fe0->dvb.frontend == NULL)
1637 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1638 &i2c_bus2->i2c_adap,
1639 &mygica_x8507_xc5000_config);
1640 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1642 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1643 i2c_bus = &dev->i2c_bus[0];
1644 i2c_bus2 = &dev->i2c_bus[1];
1645 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1646 &magicpro_prohdtve2_lgs8g75_config,
1647 &i2c_bus->i2c_adap);
1648 if (fe0->dvb.frontend == NULL)
1650 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1651 &i2c_bus2->i2c_adap,
1652 &magicpro_prohdtve2_xc5000_config);
1653 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1655 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1656 i2c_bus = &dev->i2c_bus[0];
1657 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1658 &hcw_s5h1411_config,
1659 &i2c_bus->i2c_adap);
1660 if (fe0->dvb.frontend == NULL)
1662 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1663 0x60, &dev->i2c_bus[0].i2c_adap,
1664 &hauppauge_tda18271_config);
1666 tda18271_attach(&dev->ts1.analog_fe,
1667 0x60, &dev->i2c_bus[1].i2c_adap,
1668 &hauppauge_tda18271_config);
1671 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1672 i2c_bus = &dev->i2c_bus[0];
1673 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1674 &hcw_s5h1411_config,
1675 &i2c_bus->i2c_adap);
1676 if (fe0->dvb.frontend == NULL)
1678 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1679 0x60, &dev->i2c_bus[0].i2c_adap,
1680 &hauppauge_tda18271_config);
1682 case CX23885_BOARD_MYGICA_X8558PRO:
1686 i2c_bus = &dev->i2c_bus[0];
1687 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1688 &mygica_x8558pro_atbm8830_cfg1,
1689 &i2c_bus->i2c_adap);
1690 if (fe0->dvb.frontend == NULL)
1692 dvb_attach(max2165_attach, fe0->dvb.frontend,
1694 &mygic_x8558pro_max2165_cfg1);
1698 i2c_bus = &dev->i2c_bus[1];
1699 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1700 &mygica_x8558pro_atbm8830_cfg2,
1701 &i2c_bus->i2c_adap);
1702 if (fe0->dvb.frontend == NULL)
1704 dvb_attach(max2165_attach, fe0->dvb.frontend,
1706 &mygic_x8558pro_max2165_cfg2);
1709 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1713 i2c_bus = &dev->i2c_bus[0];
1714 mfe_shared = 1;/* MFE */
1715 port->frontends.gate = 0;/* not clear for me yet */
1717 /* MFE frontend 1 DVB-T */
1718 fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
1719 &netup_stv0367_config[port->nr - 1],
1720 &i2c_bus->i2c_adap);
1721 if (fe0->dvb.frontend == NULL)
1723 if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend,
1725 &netup_xc5000_config[port->nr - 1]))
1726 goto frontend_detach;
1727 /* load xc5000 firmware */
1728 fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
1730 /* MFE frontend 2 */
1731 fe1 = vb2_dvb_get_frontend(&port->frontends, 2);
1733 goto frontend_detach;
1735 fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
1736 &netup_stv0367_config[port->nr - 1],
1737 &i2c_bus->i2c_adap);
1738 if (fe1->dvb.frontend == NULL)
1741 fe1->dvb.frontend->id = 1;
1742 if (NULL == dvb_attach(xc5000_attach,
1745 &netup_xc5000_config[port->nr - 1]))
1746 goto frontend_detach;
1748 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1749 i2c_bus = &dev->i2c_bus[0];
1750 i2c_bus2 = &dev->i2c_bus[1];
1755 fe0->dvb.frontend = dvb_attach(drxk_attach,
1756 &terratec_drxk_config[0],
1757 &i2c_bus->i2c_adap);
1758 if (fe0->dvb.frontend == NULL)
1760 if (!dvb_attach(mt2063_attach,
1762 &terratec_mt2063_config[0],
1763 &i2c_bus2->i2c_adap))
1764 goto frontend_detach;
1768 fe0->dvb.frontend = dvb_attach(drxk_attach,
1769 &terratec_drxk_config[1],
1770 &i2c_bus->i2c_adap);
1771 if (fe0->dvb.frontend == NULL)
1773 if (!dvb_attach(mt2063_attach,
1775 &terratec_mt2063_config[1],
1776 &i2c_bus2->i2c_adap))
1777 goto frontend_detach;
1781 case CX23885_BOARD_TEVII_S471:
1782 i2c_bus = &dev->i2c_bus[1];
1784 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1785 &tevii_ds3000_config,
1786 &i2c_bus->i2c_adap);
1787 if (fe0->dvb.frontend == NULL)
1789 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1790 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1792 case CX23885_BOARD_PROF_8000:
1793 i2c_bus = &dev->i2c_bus[0];
1795 fe0->dvb.frontend = dvb_attach(stv090x_attach,
1796 &prof_8000_stv090x_config,
1798 STV090x_DEMODULATOR_0);
1799 if (fe0->dvb.frontend == NULL)
1801 if (!dvb_attach(stb6100_attach,
1803 &prof_8000_stb6100_config,
1804 &i2c_bus->i2c_adap))
1805 goto frontend_detach;
1807 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
1809 case CX23885_BOARD_HAUPPAUGE_HVR4400: {
1810 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1811 struct a8293_platform_data a8293_pdata = {};
1813 i2c_bus = &dev->i2c_bus[0];
1814 i2c_bus2 = &dev->i2c_bus[1];
1818 /* attach demod + tuner combo */
1819 memset(&info, 0, sizeof(info));
1820 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1822 info.platform_data = &tda10071_pdata;
1823 request_module("tda10071");
1824 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1825 if (!client_demod || !client_demod->dev.driver)
1826 goto frontend_detach;
1827 if (!try_module_get(client_demod->dev.driver->owner)) {
1828 i2c_unregister_device(client_demod);
1829 goto frontend_detach;
1831 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1832 port->i2c_client_demod = client_demod;
1835 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1836 memset(&info, 0, sizeof(info));
1837 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1839 info.platform_data = &a8293_pdata;
1840 request_module("a8293");
1841 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1842 if (!client_sec || !client_sec->dev.driver)
1843 goto frontend_detach;
1844 if (!try_module_get(client_sec->dev.driver->owner)) {
1845 i2c_unregister_device(client_sec);
1846 goto frontend_detach;
1848 port->i2c_client_sec = client_sec;
1852 /* attach frontend */
1853 memset(&si2165_pdata, 0, sizeof(si2165_pdata));
1854 si2165_pdata.fe = &fe0->dvb.frontend;
1855 si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
1856 si2165_pdata.ref_freq_Hz = 16000000,
1857 memset(&info, 0, sizeof(struct i2c_board_info));
1858 strlcpy(info.type, "si2165", I2C_NAME_SIZE);
1860 info.platform_data = &si2165_pdata;
1861 request_module(info.type);
1862 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1863 if (client_demod == NULL ||
1864 client_demod->dev.driver == NULL)
1865 goto frontend_detach;
1866 if (!try_module_get(client_demod->dev.driver->owner)) {
1867 i2c_unregister_device(client_demod);
1868 goto frontend_detach;
1870 port->i2c_client_demod = client_demod;
1872 if (fe0->dvb.frontend == NULL)
1874 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1875 if (!dvb_attach(tda18271_attach,
1877 0x60, &i2c_bus2->i2c_adap,
1878 &hauppauge_hvr4400_tuner_config))
1879 goto frontend_detach;
1884 case CX23885_BOARD_HAUPPAUGE_STARBURST: {
1885 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1886 struct a8293_platform_data a8293_pdata = {};
1888 i2c_bus = &dev->i2c_bus[0];
1890 /* attach demod + tuner combo */
1891 memset(&info, 0, sizeof(info));
1892 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1894 info.platform_data = &tda10071_pdata;
1895 request_module("tda10071");
1896 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1897 if (!client_demod || !client_demod->dev.driver)
1898 goto frontend_detach;
1899 if (!try_module_get(client_demod->dev.driver->owner)) {
1900 i2c_unregister_device(client_demod);
1901 goto frontend_detach;
1903 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1904 port->i2c_client_demod = client_demod;
1907 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1908 memset(&info, 0, sizeof(info));
1909 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1911 info.platform_data = &a8293_pdata;
1912 request_module("a8293");
1913 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1914 if (!client_sec || !client_sec->dev.driver)
1915 goto frontend_detach;
1916 if (!try_module_get(client_sec->dev.driver->owner)) {
1917 i2c_unregister_device(client_sec);
1918 goto frontend_detach;
1920 port->i2c_client_sec = client_sec;
1923 case CX23885_BOARD_DVBSKY_T9580:
1924 case CX23885_BOARD_DVBSKY_S950:
1925 i2c_bus = &dev->i2c_bus[0];
1926 i2c_bus2 = &dev->i2c_bus[1];
1928 /* port b - satellite */
1930 /* attach frontend */
1931 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
1932 &dvbsky_t9580_m88ds3103_config,
1933 &i2c_bus2->i2c_adap, &adapter);
1934 if (fe0->dvb.frontend == NULL)
1938 memset(&ts2020_config, 0, sizeof(ts2020_config));
1939 ts2020_config.fe = fe0->dvb.frontend;
1940 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
1941 memset(&info, 0, sizeof(struct i2c_board_info));
1942 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
1944 info.platform_data = &ts2020_config;
1945 request_module(info.type);
1946 client_tuner = i2c_new_device(adapter, &info);
1947 if (client_tuner == NULL ||
1948 client_tuner->dev.driver == NULL)
1949 goto frontend_detach;
1950 if (!try_module_get(client_tuner->dev.driver->owner)) {
1951 i2c_unregister_device(client_tuner);
1952 goto frontend_detach;
1955 /* delegate signal strength measurement to tuner */
1956 fe0->dvb.frontend->ops.read_signal_strength =
1957 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
1960 * for setting the voltage we need to set GPIOs on
1963 port->fe_set_voltage =
1964 fe0->dvb.frontend->ops.set_voltage;
1965 fe0->dvb.frontend->ops.set_voltage =
1966 dvbsky_t9580_set_voltage;
1968 port->i2c_client_tuner = client_tuner;
1971 /* port c - terrestrial/cable */
1973 /* attach frontend */
1974 memset(&si2168_config, 0, sizeof(si2168_config));
1975 si2168_config.i2c_adapter = &adapter;
1976 si2168_config.fe = &fe0->dvb.frontend;
1977 si2168_config.ts_mode = SI2168_TS_SERIAL;
1978 memset(&info, 0, sizeof(struct i2c_board_info));
1979 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1981 info.platform_data = &si2168_config;
1982 request_module(info.type);
1983 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1984 if (client_demod == NULL ||
1985 client_demod->dev.driver == NULL)
1986 goto frontend_detach;
1987 if (!try_module_get(client_demod->dev.driver->owner)) {
1988 i2c_unregister_device(client_demod);
1989 goto frontend_detach;
1991 port->i2c_client_demod = client_demod;
1994 memset(&si2157_config, 0, sizeof(si2157_config));
1995 si2157_config.fe = fe0->dvb.frontend;
1996 si2157_config.if_port = 1;
1997 memset(&info, 0, sizeof(struct i2c_board_info));
1998 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2000 info.platform_data = &si2157_config;
2001 request_module(info.type);
2002 client_tuner = i2c_new_device(adapter, &info);
2003 if (client_tuner == NULL ||
2004 client_tuner->dev.driver == NULL)
2005 goto frontend_detach;
2007 if (!try_module_get(client_tuner->dev.driver->owner)) {
2008 i2c_unregister_device(client_tuner);
2009 goto frontend_detach;
2011 port->i2c_client_tuner = client_tuner;
2015 case CX23885_BOARD_DVBSKY_T980C:
2016 case CX23885_BOARD_TT_CT2_4500_CI:
2017 i2c_bus = &dev->i2c_bus[0];
2018 i2c_bus2 = &dev->i2c_bus[1];
2020 /* attach frontend */
2021 memset(&si2168_config, 0, sizeof(si2168_config));
2022 si2168_config.i2c_adapter = &adapter;
2023 si2168_config.fe = &fe0->dvb.frontend;
2024 si2168_config.ts_mode = SI2168_TS_PARALLEL;
2025 memset(&info, 0, sizeof(struct i2c_board_info));
2026 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2028 info.platform_data = &si2168_config;
2029 request_module(info.type);
2030 client_demod = i2c_new_device(&i2c_bus2->i2c_adap, &info);
2031 if (client_demod == NULL || client_demod->dev.driver == NULL)
2032 goto frontend_detach;
2033 if (!try_module_get(client_demod->dev.driver->owner)) {
2034 i2c_unregister_device(client_demod);
2035 goto frontend_detach;
2037 port->i2c_client_demod = client_demod;
2040 memset(&si2157_config, 0, sizeof(si2157_config));
2041 si2157_config.fe = fe0->dvb.frontend;
2042 si2157_config.if_port = 1;
2043 memset(&info, 0, sizeof(struct i2c_board_info));
2044 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2046 info.platform_data = &si2157_config;
2047 request_module(info.type);
2048 client_tuner = i2c_new_device(adapter, &info);
2049 if (client_tuner == NULL ||
2050 client_tuner->dev.driver == NULL)
2051 goto frontend_detach;
2052 if (!try_module_get(client_tuner->dev.driver->owner)) {
2053 i2c_unregister_device(client_tuner);
2054 goto frontend_detach;
2056 port->i2c_client_tuner = client_tuner;
2058 case CX23885_BOARD_DVBSKY_S950C:
2059 i2c_bus = &dev->i2c_bus[0];
2060 i2c_bus2 = &dev->i2c_bus[1];
2062 /* attach frontend */
2063 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2064 &dvbsky_s950c_m88ds3103_config,
2065 &i2c_bus2->i2c_adap, &adapter);
2066 if (fe0->dvb.frontend == NULL)
2070 memset(&ts2020_config, 0, sizeof(ts2020_config));
2071 ts2020_config.fe = fe0->dvb.frontend;
2072 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2073 memset(&info, 0, sizeof(struct i2c_board_info));
2074 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2076 info.platform_data = &ts2020_config;
2077 request_module(info.type);
2078 client_tuner = i2c_new_device(adapter, &info);
2079 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
2080 goto frontend_detach;
2081 if (!try_module_get(client_tuner->dev.driver->owner)) {
2082 i2c_unregister_device(client_tuner);
2083 goto frontend_detach;
2086 /* delegate signal strength measurement to tuner */
2087 fe0->dvb.frontend->ops.read_signal_strength =
2088 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2090 port->i2c_client_tuner = client_tuner;
2092 case CX23885_BOARD_DVBSKY_S952:
2093 /* attach frontend */
2094 memset(&m88ds3103_pdata, 0, sizeof(m88ds3103_pdata));
2095 m88ds3103_pdata.clk = 27000000;
2096 m88ds3103_pdata.i2c_wr_max = 33;
2097 m88ds3103_pdata.agc = 0x99;
2098 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_DISABLED;
2099 m88ds3103_pdata.lnb_en_pol = 1;
2104 i2c_bus = &dev->i2c_bus[1];
2105 m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
2106 m88ds3103_pdata.ts_clk = 16000;
2107 m88ds3103_pdata.ts_clk_pol = 1;
2108 p_set_voltage = dvbsky_t9580_set_voltage;
2112 i2c_bus = &dev->i2c_bus[0];
2113 m88ds3103_pdata.ts_mode = M88DS3103_TS_SERIAL;
2114 m88ds3103_pdata.ts_clk = 96000;
2115 m88ds3103_pdata.ts_clk_pol = 0;
2116 p_set_voltage = dvbsky_s952_portc_set_voltage;
2122 memset(&info, 0, sizeof(info));
2123 strlcpy(info.type, "m88ds3103", I2C_NAME_SIZE);
2125 info.platform_data = &m88ds3103_pdata;
2126 request_module(info.type);
2127 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
2128 if (client_demod == NULL || client_demod->dev.driver == NULL)
2129 goto frontend_detach;
2130 if (!try_module_get(client_demod->dev.driver->owner)) {
2131 i2c_unregister_device(client_demod);
2132 goto frontend_detach;
2134 port->i2c_client_demod = client_demod;
2135 adapter = m88ds3103_pdata.get_i2c_adapter(client_demod);
2136 fe0->dvb.frontend = m88ds3103_pdata.get_dvb_frontend(client_demod);
2139 memset(&ts2020_config, 0, sizeof(ts2020_config));
2140 ts2020_config.fe = fe0->dvb.frontend;
2141 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2142 memset(&info, 0, sizeof(struct i2c_board_info));
2143 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2145 info.platform_data = &ts2020_config;
2146 request_module(info.type);
2147 client_tuner = i2c_new_device(adapter, &info);
2148 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
2149 goto frontend_detach;
2150 if (!try_module_get(client_tuner->dev.driver->owner)) {
2151 i2c_unregister_device(client_tuner);
2152 goto frontend_detach;
2155 /* delegate signal strength measurement to tuner */
2156 fe0->dvb.frontend->ops.read_signal_strength =
2157 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2160 * for setting the voltage we need to set GPIOs on
2163 port->fe_set_voltage =
2164 fe0->dvb.frontend->ops.set_voltage;
2165 fe0->dvb.frontend->ops.set_voltage = p_set_voltage;
2167 port->i2c_client_tuner = client_tuner;
2169 case CX23885_BOARD_DVBSKY_T982:
2170 memset(&si2168_config, 0, sizeof(si2168_config));
2174 i2c_bus = &dev->i2c_bus[1];
2175 si2168_config.ts_mode = SI2168_TS_PARALLEL;
2179 i2c_bus = &dev->i2c_bus[0];
2180 si2168_config.ts_mode = SI2168_TS_SERIAL;
2184 /* attach frontend */
2185 si2168_config.i2c_adapter = &adapter;
2186 si2168_config.fe = &fe0->dvb.frontend;
2187 memset(&info, 0, sizeof(struct i2c_board_info));
2188 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2190 info.platform_data = &si2168_config;
2191 request_module(info.type);
2192 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
2193 if (client_demod == NULL || client_demod->dev.driver == NULL)
2194 goto frontend_detach;
2195 if (!try_module_get(client_demod->dev.driver->owner)) {
2196 i2c_unregister_device(client_demod);
2197 goto frontend_detach;
2199 port->i2c_client_demod = client_demod;
2202 memset(&si2157_config, 0, sizeof(si2157_config));
2203 si2157_config.fe = fe0->dvb.frontend;
2204 si2157_config.if_port = 1;
2205 memset(&info, 0, sizeof(struct i2c_board_info));
2206 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2208 info.platform_data = &si2157_config;
2209 request_module(info.type);
2210 client_tuner = i2c_new_device(adapter, &info);
2211 if (client_tuner == NULL ||
2212 client_tuner->dev.driver == NULL)
2213 goto frontend_detach;
2214 if (!try_module_get(client_tuner->dev.driver->owner)) {
2215 i2c_unregister_device(client_tuner);
2216 goto frontend_detach;
2218 port->i2c_client_tuner = client_tuner;
2220 case CX23885_BOARD_HAUPPAUGE_HVR5525: {
2221 struct m88rs6000t_config m88rs6000t_config;
2222 struct a8293_platform_data a8293_pdata = {};
2226 /* port b - satellite */
2228 /* attach frontend */
2229 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2230 &hauppauge_hvr5525_m88ds3103_config,
2231 &dev->i2c_bus[0].i2c_adap, &adapter);
2232 if (fe0->dvb.frontend == NULL)
2236 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
2237 memset(&info, 0, sizeof(info));
2238 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
2240 info.platform_data = &a8293_pdata;
2241 request_module("a8293");
2242 client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2243 if (!client_sec || !client_sec->dev.driver)
2244 goto frontend_detach;
2245 if (!try_module_get(client_sec->dev.driver->owner)) {
2246 i2c_unregister_device(client_sec);
2247 goto frontend_detach;
2249 port->i2c_client_sec = client_sec;
2252 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
2253 m88rs6000t_config.fe = fe0->dvb.frontend;
2254 memset(&info, 0, sizeof(struct i2c_board_info));
2255 strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE);
2257 info.platform_data = &m88rs6000t_config;
2258 request_module("%s", info.type);
2259 client_tuner = i2c_new_device(adapter, &info);
2260 if (!client_tuner || !client_tuner->dev.driver)
2261 goto frontend_detach;
2262 if (!try_module_get(client_tuner->dev.driver->owner)) {
2263 i2c_unregister_device(client_tuner);
2264 goto frontend_detach;
2266 port->i2c_client_tuner = client_tuner;
2268 /* delegate signal strength measurement to tuner */
2269 fe0->dvb.frontend->ops.read_signal_strength =
2270 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2272 /* port c - terrestrial/cable */
2274 /* attach frontend */
2275 memset(&si2168_config, 0, sizeof(si2168_config));
2276 si2168_config.i2c_adapter = &adapter;
2277 si2168_config.fe = &fe0->dvb.frontend;
2278 si2168_config.ts_mode = SI2168_TS_SERIAL;
2279 memset(&info, 0, sizeof(struct i2c_board_info));
2280 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2282 info.platform_data = &si2168_config;
2283 request_module("%s", info.type);
2284 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2285 if (!client_demod || !client_demod->dev.driver)
2286 goto frontend_detach;
2287 if (!try_module_get(client_demod->dev.driver->owner)) {
2288 i2c_unregister_device(client_demod);
2289 goto frontend_detach;
2291 port->i2c_client_demod = client_demod;
2294 memset(&si2157_config, 0, sizeof(si2157_config));
2295 si2157_config.fe = fe0->dvb.frontend;
2296 si2157_config.if_port = 1;
2297 memset(&info, 0, sizeof(struct i2c_board_info));
2298 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2300 info.platform_data = &si2157_config;
2301 request_module("%s", info.type);
2302 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2303 if (!client_tuner || !client_tuner->dev.driver) {
2304 module_put(client_demod->dev.driver->owner);
2305 i2c_unregister_device(client_demod);
2306 port->i2c_client_demod = NULL;
2307 goto frontend_detach;
2309 if (!try_module_get(client_tuner->dev.driver->owner)) {
2310 i2c_unregister_device(client_tuner);
2311 module_put(client_demod->dev.driver->owner);
2312 i2c_unregister_device(client_demod);
2313 port->i2c_client_demod = NULL;
2314 goto frontend_detach;
2316 port->i2c_client_tuner = client_tuner;
2321 case CX23885_BOARD_HAUPPAUGE_QUADHD_DVB:
2323 /* port b - Terrestrial/cable */
2325 /* attach frontend */
2326 memset(&si2168_config, 0, sizeof(si2168_config));
2327 si2168_config.i2c_adapter = &adapter;
2328 si2168_config.fe = &fe0->dvb.frontend;
2329 si2168_config.ts_mode = SI2168_TS_SERIAL;
2330 memset(&info, 0, sizeof(struct i2c_board_info));
2331 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2333 info.platform_data = &si2168_config;
2334 request_module("%s", info.type);
2335 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2336 if (!client_demod || !client_demod->dev.driver)
2337 goto frontend_detach;
2338 if (!try_module_get(client_demod->dev.driver->owner)) {
2339 i2c_unregister_device(client_demod);
2340 goto frontend_detach;
2342 port->i2c_client_demod = client_demod;
2345 memset(&si2157_config, 0, sizeof(si2157_config));
2346 si2157_config.fe = fe0->dvb.frontend;
2347 si2157_config.if_port = 1;
2348 memset(&info, 0, sizeof(struct i2c_board_info));
2349 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2351 info.platform_data = &si2157_config;
2352 request_module("%s", info.type);
2353 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2354 if (!client_tuner || !client_tuner->dev.driver) {
2355 module_put(client_demod->dev.driver->owner);
2356 i2c_unregister_device(client_demod);
2357 port->i2c_client_demod = NULL;
2358 goto frontend_detach;
2360 if (!try_module_get(client_tuner->dev.driver->owner)) {
2361 i2c_unregister_device(client_tuner);
2362 module_put(client_demod->dev.driver->owner);
2363 i2c_unregister_device(client_demod);
2364 port->i2c_client_demod = NULL;
2365 goto frontend_detach;
2367 port->i2c_client_tuner = client_tuner;
2370 /* port c - terrestrial/cable */
2372 /* attach frontend */
2373 memset(&si2168_config, 0, sizeof(si2168_config));
2374 si2168_config.i2c_adapter = &adapter;
2375 si2168_config.fe = &fe0->dvb.frontend;
2376 si2168_config.ts_mode = SI2168_TS_SERIAL;
2377 memset(&info, 0, sizeof(struct i2c_board_info));
2378 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2380 info.platform_data = &si2168_config;
2381 request_module("%s", info.type);
2382 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2383 if (!client_demod || !client_demod->dev.driver)
2384 goto frontend_detach;
2385 if (!try_module_get(client_demod->dev.driver->owner)) {
2386 i2c_unregister_device(client_demod);
2387 goto frontend_detach;
2389 port->i2c_client_demod = client_demod;
2392 memset(&si2157_config, 0, sizeof(si2157_config));
2393 si2157_config.fe = fe0->dvb.frontend;
2394 si2157_config.if_port = 1;
2395 memset(&info, 0, sizeof(struct i2c_board_info));
2396 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2398 info.platform_data = &si2157_config;
2399 request_module("%s", info.type);
2400 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2401 if (!client_tuner || !client_tuner->dev.driver) {
2402 module_put(client_demod->dev.driver->owner);
2403 i2c_unregister_device(client_demod);
2404 port->i2c_client_demod = NULL;
2405 goto frontend_detach;
2407 if (!try_module_get(client_tuner->dev.driver->owner)) {
2408 i2c_unregister_device(client_tuner);
2409 module_put(client_demod->dev.driver->owner);
2410 i2c_unregister_device(client_demod);
2411 port->i2c_client_demod = NULL;
2412 goto frontend_detach;
2414 port->i2c_client_tuner = client_tuner;
2418 case CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC:
2420 /* port b - Terrestrial/cable */
2422 /* attach frontend */
2423 i2c_bus = &dev->i2c_bus[0];
2424 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
2425 &hauppauge_quadHD_ATSC_a_config, &i2c_bus->i2c_adap);
2426 if (fe0->dvb.frontend == NULL)
2430 memset(&si2157_config, 0, sizeof(si2157_config));
2431 si2157_config.fe = fe0->dvb.frontend;
2432 si2157_config.if_port = 1;
2433 si2157_config.inversion = 1;
2434 memset(&info, 0, sizeof(struct i2c_board_info));
2435 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2437 info.platform_data = &si2157_config;
2438 request_module("%s", info.type);
2439 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2440 if (!client_tuner || !client_tuner->dev.driver) {
2441 module_put(client_demod->dev.driver->owner);
2442 i2c_unregister_device(client_demod);
2443 port->i2c_client_demod = NULL;
2444 goto frontend_detach;
2446 if (!try_module_get(client_tuner->dev.driver->owner)) {
2447 i2c_unregister_device(client_tuner);
2448 module_put(client_demod->dev.driver->owner);
2449 i2c_unregister_device(client_demod);
2450 port->i2c_client_demod = NULL;
2451 goto frontend_detach;
2453 port->i2c_client_tuner = client_tuner;
2456 /* port c - terrestrial/cable */
2458 /* attach frontend */
2459 i2c_bus = &dev->i2c_bus[0];
2460 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
2461 &hauppauge_quadHD_ATSC_b_config, &i2c_bus->i2c_adap);
2462 if (fe0->dvb.frontend == NULL)
2466 memset(&si2157_config, 0, sizeof(si2157_config));
2467 si2157_config.fe = fe0->dvb.frontend;
2468 si2157_config.if_port = 1;
2469 si2157_config.inversion = 1;
2470 memset(&info, 0, sizeof(struct i2c_board_info));
2471 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2473 info.platform_data = &si2157_config;
2474 request_module("%s", info.type);
2475 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2476 if (!client_tuner || !client_tuner->dev.driver) {
2477 module_put(client_demod->dev.driver->owner);
2478 i2c_unregister_device(client_demod);
2479 port->i2c_client_demod = NULL;
2480 goto frontend_detach;
2482 if (!try_module_get(client_tuner->dev.driver->owner)) {
2483 i2c_unregister_device(client_tuner);
2484 module_put(client_demod->dev.driver->owner);
2485 i2c_unregister_device(client_demod);
2486 port->i2c_client_demod = NULL;
2487 goto frontend_detach;
2489 port->i2c_client_tuner = client_tuner;
2495 pr_info("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
2500 if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
2501 pr_err("%s: frontend initialization failed\n",
2503 goto frontend_detach;
2506 /* define general-purpose callback pointer */
2507 fe0->dvb.frontend->callback = cx23885_tuner_callback;
2509 fe1->dvb.frontend->callback = cx23885_tuner_callback;
2511 /* Ensure all frontends negotiate bus access */
2512 fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
2514 fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
2517 /* Put the analog decoder in standby to keep it quiet */
2518 call_all(dev, core, s_power, 0);
2520 if (fe0->dvb.frontend->ops.analog_ops.standby)
2521 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
2523 /* register everything */
2524 ret = vb2_dvb_register_bus(&port->frontends, THIS_MODULE, port,
2525 &dev->pci->dev, NULL,
2526 adapter_nr, mfe_shared);
2528 goto frontend_detach;
2530 ret = dvb_register_ci_mac(port);
2532 goto frontend_detach;
2537 /* remove I2C client for SEC */
2538 client_sec = port->i2c_client_sec;
2540 module_put(client_sec->dev.driver->owner);
2541 i2c_unregister_device(client_sec);
2542 port->i2c_client_sec = NULL;
2545 /* remove I2C client for tuner */
2546 client_tuner = port->i2c_client_tuner;
2548 module_put(client_tuner->dev.driver->owner);
2549 i2c_unregister_device(client_tuner);
2550 port->i2c_client_tuner = NULL;
2553 /* remove I2C client for demodulator */
2554 client_demod = port->i2c_client_demod;
2556 module_put(client_demod->dev.driver->owner);
2557 i2c_unregister_device(client_demod);
2558 port->i2c_client_demod = NULL;
2561 port->gate_ctrl = NULL;
2562 vb2_dvb_dealloc_frontends(&port->frontends);
2566 int cx23885_dvb_register(struct cx23885_tsport *port)
2569 struct vb2_dvb_frontend *fe0;
2570 struct cx23885_dev *dev = port->dev;
2573 /* Here we need to allocate the correct number of frontends,
2574 * as reflected in the cards struct. The reality is that currently
2575 * no cx23885 boards support this - yet. But, if we don't modify this
2576 * code then the second frontend would never be allocated (later)
2577 * and fail with error before the attach in dvb_register().
2578 * Without these changes we risk an OOPS later. The changes here
2579 * are for safety, and should provide a good foundation for the
2580 * future addition of any multi-frontend cx23885 based boards.
2582 pr_info("%s() allocating %d frontend(s)\n", __func__,
2583 port->num_frontends);
2585 for (i = 1; i <= port->num_frontends; i++) {
2586 struct vb2_queue *q;
2588 if (vb2_dvb_alloc_frontend(
2589 &port->frontends, i) == NULL) {
2590 pr_err("%s() failed to alloc\n", __func__);
2594 fe0 = vb2_dvb_get_frontend(&port->frontends, i);
2598 dprintk(1, "%s\n", __func__);
2599 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
2608 /* We have to init the queue for each frontend on a port. */
2609 pr_info("%s: cx23885 based dvb card\n", dev->name);
2611 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2612 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
2613 q->gfp_flags = GFP_DMA32;
2614 q->min_buffers_needed = 2;
2616 q->buf_struct_size = sizeof(struct cx23885_buffer);
2618 q->mem_ops = &vb2_dma_sg_memops;
2619 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2620 q->lock = &dev->lock;
2621 q->dev = &dev->pci->dev;
2623 err = vb2_queue_init(q);
2627 err = dvb_register(port);
2629 pr_err("%s() dvb_register failed err = %d\n",
2635 int cx23885_dvb_unregister(struct cx23885_tsport *port)
2637 struct vb2_dvb_frontend *fe0;
2638 struct i2c_client *client;
2640 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
2642 if (fe0 && fe0->dvb.frontend)
2643 vb2_dvb_unregister_bus(&port->frontends);
2645 /* remove I2C client for CI */
2646 client = port->i2c_client_ci;
2648 module_put(client->dev.driver->owner);
2649 i2c_unregister_device(client);
2652 /* remove I2C client for SEC */
2653 client = port->i2c_client_sec;
2655 module_put(client->dev.driver->owner);
2656 i2c_unregister_device(client);
2659 /* remove I2C client for tuner */
2660 client = port->i2c_client_tuner;
2662 module_put(client->dev.driver->owner);
2663 i2c_unregister_device(client);
2666 /* remove I2C client for demodulator */
2667 client = port->i2c_client_demod;
2669 module_put(client->dev.driver->owner);
2670 i2c_unregister_device(client);
2673 switch (port->dev->board) {
2674 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
2675 netup_ci_exit(port);
2677 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
2678 altera_ci_release(port->dev, port->nr);
2682 port->gate_ctrl = NULL;