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.
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/device.h>
22 #include <linux/kthread.h>
23 #include <linux/file.h>
24 #include <linux/suspend.h>
27 #include <media/v4l2-common.h>
29 #include "dvb_ca_en50221.h"
40 #include "tuner-xc2028.h"
41 #include "tuner-simple.h"
44 #include "dibx000_common.h"
47 #include "stv0900_reg.h"
54 #include "netup-eeprom.h"
55 #include "netup-init.h"
60 #include "cx23885-f300.h"
61 #include "altera-ci.h"
67 #include "stb6100_cfg.h"
75 #include "m88ds3103.h"
76 #include "m88rs6000t.h"
77 #include "lgdt3306a.h"
79 static unsigned int debug;
81 #define dprintk(level, fmt, arg...)\
82 do { if (debug >= level)\
83 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
86 /* ------------------------------------------------------------------ */
88 static unsigned int alt_tuner;
89 module_param(alt_tuner, int, 0644);
90 MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
92 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
94 /* ------------------------------------------------------------------ */
96 static int queue_setup(struct vb2_queue *q,
97 unsigned int *num_buffers, unsigned int *num_planes,
98 unsigned int sizes[], struct device *alloc_devs[])
100 struct cx23885_tsport *port = q->drv_priv;
102 port->ts_packet_size = 188 * 4;
103 port->ts_packet_count = 32;
105 sizes[0] = port->ts_packet_size * port->ts_packet_count;
111 static int buffer_prepare(struct vb2_buffer *vb)
113 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
114 struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
115 struct cx23885_buffer *buf =
116 container_of(vbuf, struct cx23885_buffer, vb);
118 return cx23885_buf_prepare(buf, port);
121 static void buffer_finish(struct vb2_buffer *vb)
123 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
124 struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
125 struct cx23885_dev *dev = port->dev;
126 struct cx23885_buffer *buf = container_of(vbuf,
127 struct cx23885_buffer, vb);
129 cx23885_free_buffer(dev, buf);
132 static void buffer_queue(struct vb2_buffer *vb)
134 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
135 struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
136 struct cx23885_buffer *buf = container_of(vbuf,
137 struct cx23885_buffer, vb);
139 cx23885_buf_queue(port, buf);
142 static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open)
144 struct vb2_dvb_frontends *f;
145 struct vb2_dvb_frontend *fe;
147 f = &port->frontends;
149 if (f->gate <= 1) /* undefined or fe0 */
150 fe = vb2_dvb_get_frontend(f, 1);
152 fe = vb2_dvb_get_frontend(f, f->gate);
154 if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
155 fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
158 static int cx23885_start_streaming(struct vb2_queue *q, unsigned int count)
160 struct cx23885_tsport *port = q->drv_priv;
161 struct cx23885_dmaqueue *dmaq = &port->mpegq;
162 struct cx23885_buffer *buf = list_entry(dmaq->active.next,
163 struct cx23885_buffer, queue);
165 cx23885_start_dma(port, dmaq, buf);
169 static void cx23885_stop_streaming(struct vb2_queue *q)
171 struct cx23885_tsport *port = q->drv_priv;
173 cx23885_cancel_buffers(port);
176 static const struct vb2_ops dvb_qops = {
177 .queue_setup = queue_setup,
178 .buf_prepare = buffer_prepare,
179 .buf_finish = buffer_finish,
180 .buf_queue = buffer_queue,
181 .wait_prepare = vb2_ops_wait_prepare,
182 .wait_finish = vb2_ops_wait_finish,
183 .start_streaming = cx23885_start_streaming,
184 .stop_streaming = cx23885_stop_streaming,
187 static struct s5h1409_config hauppauge_generic_config = {
188 .demod_address = 0x32 >> 1,
189 .output_mode = S5H1409_SERIAL_OUTPUT,
190 .gpio = S5H1409_GPIO_ON,
192 .inversion = S5H1409_INVERSION_OFF,
193 .status_mode = S5H1409_DEMODLOCKING,
194 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
197 static struct tda10048_config hauppauge_hvr1200_config = {
198 .demod_address = 0x10 >> 1,
199 .output_mode = TDA10048_SERIAL_OUTPUT,
200 .fwbulkwritelen = TDA10048_BULKWRITE_200,
201 .inversion = TDA10048_INVERSION_ON,
202 .dtv6_if_freq_khz = TDA10048_IF_3300,
203 .dtv7_if_freq_khz = TDA10048_IF_3800,
204 .dtv8_if_freq_khz = TDA10048_IF_4300,
205 .clk_freq_khz = TDA10048_CLK_16000,
208 static struct tda10048_config hauppauge_hvr1210_config = {
209 .demod_address = 0x10 >> 1,
210 .output_mode = TDA10048_SERIAL_OUTPUT,
211 .fwbulkwritelen = TDA10048_BULKWRITE_200,
212 .inversion = TDA10048_INVERSION_ON,
213 .dtv6_if_freq_khz = TDA10048_IF_3300,
214 .dtv7_if_freq_khz = TDA10048_IF_3500,
215 .dtv8_if_freq_khz = TDA10048_IF_4000,
216 .clk_freq_khz = TDA10048_CLK_16000,
219 static struct s5h1409_config hauppauge_ezqam_config = {
220 .demod_address = 0x32 >> 1,
221 .output_mode = S5H1409_SERIAL_OUTPUT,
222 .gpio = S5H1409_GPIO_OFF,
224 .inversion = S5H1409_INVERSION_ON,
225 .status_mode = S5H1409_DEMODLOCKING,
226 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
229 static struct s5h1409_config hauppauge_hvr1800lp_config = {
230 .demod_address = 0x32 >> 1,
231 .output_mode = S5H1409_SERIAL_OUTPUT,
232 .gpio = S5H1409_GPIO_OFF,
234 .inversion = S5H1409_INVERSION_OFF,
235 .status_mode = S5H1409_DEMODLOCKING,
236 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
239 static struct s5h1409_config hauppauge_hvr1500_config = {
240 .demod_address = 0x32 >> 1,
241 .output_mode = S5H1409_SERIAL_OUTPUT,
242 .gpio = S5H1409_GPIO_OFF,
243 .inversion = S5H1409_INVERSION_OFF,
244 .status_mode = S5H1409_DEMODLOCKING,
245 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
248 static struct mt2131_config hauppauge_generic_tunerconfig = {
252 static struct lgdt330x_config fusionhdtv_5_express = {
253 .demod_address = 0x0e,
254 .demod_chip = LGDT3303,
258 static struct s5h1409_config hauppauge_hvr1500q_config = {
259 .demod_address = 0x32 >> 1,
260 .output_mode = S5H1409_SERIAL_OUTPUT,
261 .gpio = S5H1409_GPIO_ON,
263 .inversion = S5H1409_INVERSION_OFF,
264 .status_mode = S5H1409_DEMODLOCKING,
265 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
268 static struct s5h1409_config dvico_s5h1409_config = {
269 .demod_address = 0x32 >> 1,
270 .output_mode = S5H1409_SERIAL_OUTPUT,
271 .gpio = S5H1409_GPIO_ON,
273 .inversion = S5H1409_INVERSION_OFF,
274 .status_mode = S5H1409_DEMODLOCKING,
275 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
278 static struct s5h1411_config dvico_s5h1411_config = {
279 .output_mode = S5H1411_SERIAL_OUTPUT,
280 .gpio = S5H1411_GPIO_ON,
281 .qam_if = S5H1411_IF_44000,
282 .vsb_if = S5H1411_IF_44000,
283 .inversion = S5H1411_INVERSION_OFF,
284 .status_mode = S5H1411_DEMODLOCKING,
285 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
288 static struct s5h1411_config hcw_s5h1411_config = {
289 .output_mode = S5H1411_SERIAL_OUTPUT,
290 .gpio = S5H1411_GPIO_OFF,
291 .vsb_if = S5H1411_IF_44000,
292 .qam_if = S5H1411_IF_4000,
293 .inversion = S5H1411_INVERSION_ON,
294 .status_mode = S5H1411_DEMODLOCKING,
295 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
298 static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
303 static struct xc5000_config dvico_xc5000_tunerconfig = {
308 static struct tda829x_config tda829x_no_probe = {
309 .probe_tuner = TDA829X_DONT_PROBE,
312 static struct tda18271_std_map hauppauge_tda18271_std_map = {
313 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
314 .if_lvl = 6, .rfagc_top = 0x37 },
315 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
316 .if_lvl = 6, .rfagc_top = 0x37 },
319 static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
320 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
321 .if_lvl = 1, .rfagc_top = 0x37, },
322 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
323 .if_lvl = 1, .rfagc_top = 0x37, },
324 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
325 .if_lvl = 1, .rfagc_top = 0x37, },
328 static struct tda18271_config hauppauge_tda18271_config = {
329 .std_map = &hauppauge_tda18271_std_map,
330 .gate = TDA18271_GATE_ANALOG,
331 .output_opt = TDA18271_OUTPUT_LT_OFF,
334 static struct tda18271_config hauppauge_hvr1200_tuner_config = {
335 .std_map = &hauppauge_hvr1200_tda18271_std_map,
336 .gate = TDA18271_GATE_ANALOG,
337 .output_opt = TDA18271_OUTPUT_LT_OFF,
340 static struct tda18271_config hauppauge_hvr1210_tuner_config = {
341 .gate = TDA18271_GATE_DIGITAL,
342 .output_opt = TDA18271_OUTPUT_LT_OFF,
345 static struct tda18271_config hauppauge_hvr4400_tuner_config = {
346 .gate = TDA18271_GATE_DIGITAL,
347 .output_opt = TDA18271_OUTPUT_LT_OFF,
350 static struct tda18271_std_map hauppauge_hvr127x_std_map = {
351 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
352 .if_lvl = 1, .rfagc_top = 0x58 },
353 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
354 .if_lvl = 1, .rfagc_top = 0x58 },
357 static struct tda18271_config hauppauge_hvr127x_config = {
358 .std_map = &hauppauge_hvr127x_std_map,
359 .output_opt = TDA18271_OUTPUT_LT_OFF,
362 static struct lgdt3305_config hauppauge_lgdt3305_config = {
364 .mpeg_mode = LGDT3305_MPEG_SERIAL,
365 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
366 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
368 .spectral_inversion = 1,
373 static struct dibx000_agc_config xc3028_agc_config = {
374 BAND_VHF | BAND_UHF, /* band_caps */
376 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
377 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
378 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
379 * P_agc_nb_est=2, P_agc_write=0
381 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
382 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
385 21, /* time_stabiliz */
397 39718, /* agc2_max */
406 29, /* agc2_slope1 */
407 29, /* agc2_slope2 */
414 1, /* perform_agc_softsplit */
417 /* PLL Configuration for COFDM BW_MHz = 8.000000
418 * With external clock = 30.000000 */
419 static struct dibx000_bandwidth_config xc3028_bw_config = {
420 60000, /* internal */
421 30000, /* sampling */
422 1, /* pll_cfg: prediv */
423 8, /* pll_cfg: ratio */
424 3, /* pll_cfg: range */
425 1, /* pll_cfg: reset */
426 0, /* pll_cfg: bypass */
427 0, /* misc: refdiv */
428 0, /* misc: bypclk_div */
429 1, /* misc: IO_CLK_en_core */
430 1, /* misc: ADClkSrc */
431 0, /* misc: modulo */
432 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
433 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
435 30000000 /* xtal_hz */
438 static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
439 .output_mpeg2_in_188_bytes = 1,
440 .hostbus_diversity = 1,
441 .tuner_is_baseband = 0,
444 .agc_config_count = 1,
445 .agc = &xc3028_agc_config,
446 .bw = &xc3028_bw_config,
448 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
449 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
450 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
456 .output_mode = OUTMODE_MPEG2_SERIAL,
459 static struct zl10353_config dvico_fusionhdtv_xc3028 = {
460 .demod_address = 0x0f,
463 .disable_i2c_gate_ctrl = 1,
466 static struct stv0900_reg stv0900_ts_regs[] = {
467 { R0900_TSGENERAL, 0x00 },
468 { R0900_P1_TSSPEED, 0x40 },
469 { R0900_P2_TSSPEED, 0x40 },
470 { R0900_P1_TSCFGM, 0xc0 },
471 { R0900_P2_TSCFGM, 0xc0 },
472 { R0900_P1_TSCFGH, 0xe0 },
473 { R0900_P2_TSCFGH, 0xe0 },
474 { R0900_P1_TSCFGL, 0x20 },
475 { R0900_P2_TSCFGL, 0x20 },
476 { 0xffff, 0xff }, /* terminate */
479 static struct stv0900_config netup_stv0900_config = {
480 .demod_address = 0x68,
481 .demod_mode = 1, /* dual */
483 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
484 .diseqc_mode = 2,/* 2/3 PWM */
485 .ts_config_regs = stv0900_ts_regs,
486 .tun1_maddress = 0,/* 0x60 */
487 .tun2_maddress = 3,/* 0x63 */
488 .tun1_adc = 1,/* 1 Vpp */
489 .tun2_adc = 1,/* 1 Vpp */
492 static struct stv6110_config netup_stv6110_tunerconfig_a = {
496 .gain = 8, /* +16 dB - maximum gain */
499 static struct stv6110_config netup_stv6110_tunerconfig_b = {
503 .gain = 8, /* +16 dB - maximum gain */
506 static struct cx24116_config tbs_cx24116_config = {
507 .demod_address = 0x55,
510 static struct cx24117_config tbs_cx24117_config = {
511 .demod_address = 0x55,
514 static struct ds3000_config tevii_ds3000_config = {
515 .demod_address = 0x68,
518 static struct ts2020_config tevii_ts2020_config = {
519 .tuner_address = 0x60,
521 .frequency_div = 1146000,
524 static struct cx24116_config dvbworld_cx24116_config = {
525 .demod_address = 0x05,
528 static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
529 .prod = LGS8GXX_PROD_LGS8GL5,
530 .demod_address = 0x19,
534 .if_clk_freq = 30400, /* 30.4 MHz */
535 .if_freq = 5380, /* 5.38 MHz */
542 static struct xc5000_config mygica_x8506_xc5000_config = {
547 static struct mb86a20s_config mygica_x8507_mb86a20s_config = {
548 .demod_address = 0x10,
551 static struct xc5000_config mygica_x8507_xc5000_config = {
556 static struct stv090x_config prof_8000_stv090x_config = {
558 .demod_mode = STV090x_SINGLE,
559 .clk_mode = STV090x_CLK_EXT,
562 .ts1_mode = STV090x_TSMODE_PARALLEL_PUNCTURED,
563 .repeater_level = STV090x_RPTLEVEL_64,
564 .adc1_range = STV090x_ADC_2Vpp,
565 .diseqc_envelope_mode = false,
567 .tuner_get_frequency = stb6100_get_frequency,
568 .tuner_set_frequency = stb6100_set_frequency,
569 .tuner_set_bandwidth = stb6100_set_bandwidth,
570 .tuner_get_bandwidth = stb6100_get_bandwidth,
573 static struct stb6100_config prof_8000_stb6100_config = {
574 .tuner_address = 0x60,
575 .refclock = 27000000,
578 static struct lgdt3306a_config hauppauge_quadHD_ATSC_a_config = {
582 .deny_i2c_rptr = 1, /* Disabled */
583 .spectral_inversion = 0, /* Disabled */
584 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
585 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
586 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
587 .xtalMHz = 25, /* 24 or 25 */
590 static struct lgdt3306a_config hauppauge_quadHD_ATSC_b_config = {
594 .deny_i2c_rptr = 1, /* Disabled */
595 .spectral_inversion = 0, /* Disabled */
596 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
597 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
598 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
599 .xtalMHz = 25, /* 24 or 25 */
602 static int p8000_set_voltage(struct dvb_frontend *fe,
603 enum fe_sec_voltage voltage)
605 struct cx23885_tsport *port = fe->dvb->priv;
606 struct cx23885_dev *dev = port->dev;
608 if (voltage == SEC_VOLTAGE_18)
609 cx_write(MC417_RWD, 0x00001e00);
610 else if (voltage == SEC_VOLTAGE_13)
611 cx_write(MC417_RWD, 0x00001a00);
613 cx_write(MC417_RWD, 0x00001800);
617 static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe,
618 enum fe_sec_voltage voltage)
620 struct cx23885_tsport *port = fe->dvb->priv;
621 struct cx23885_dev *dev = port->dev;
623 cx23885_gpio_enable(dev, GPIO_0 | GPIO_1, 1);
627 cx23885_gpio_set(dev, GPIO_1);
628 cx23885_gpio_clear(dev, GPIO_0);
631 cx23885_gpio_set(dev, GPIO_1);
632 cx23885_gpio_set(dev, GPIO_0);
634 case SEC_VOLTAGE_OFF:
635 cx23885_gpio_clear(dev, GPIO_1);
636 cx23885_gpio_clear(dev, GPIO_0);
640 /* call the frontend set_voltage function */
641 port->fe_set_voltage(fe, voltage);
646 static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe,
647 enum fe_sec_voltage voltage)
649 struct cx23885_tsport *port = fe->dvb->priv;
650 struct cx23885_dev *dev = port->dev;
652 cx23885_gpio_enable(dev, GPIO_12 | GPIO_13, 1);
656 cx23885_gpio_set(dev, GPIO_13);
657 cx23885_gpio_clear(dev, GPIO_12);
660 cx23885_gpio_set(dev, GPIO_13);
661 cx23885_gpio_set(dev, GPIO_12);
663 case SEC_VOLTAGE_OFF:
664 cx23885_gpio_clear(dev, GPIO_13);
665 cx23885_gpio_clear(dev, GPIO_12);
668 /* call the frontend set_voltage function */
669 return port->fe_set_voltage(fe, voltage);
672 static int cx23885_sp2_ci_ctrl(void *priv, u8 read, int addr,
676 #define SP2_DATA 0x000000ff
677 #define SP2_WR 0x00008000
678 #define SP2_RD 0x00004000
679 #define SP2_ACK 0x00001000
680 #define SP2_ADHI 0x00000800
681 #define SP2_ADLO 0x00000400
682 #define SP2_CS1 0x00000200
683 #define SP2_CS0 0x00000100
684 #define SP2_EN_ALL 0x00001000
685 #define SP2_CTRL_OFF (SP2_CS1 | SP2_CS0 | SP2_WR | SP2_RD)
687 struct cx23885_tsport *port = priv;
688 struct cx23885_dev *dev = port->dev;
691 unsigned long timeout;
693 mutex_lock(&dev->gpio_lock);
696 cx_write(MC417_OEN, SP2_EN_ALL);
697 cx_write(MC417_RWD, SP2_CTRL_OFF |
698 SP2_ADLO | (0xff & addr));
699 cx_clear(MC417_RWD, SP2_ADLO);
700 cx_write(MC417_RWD, SP2_CTRL_OFF |
701 SP2_ADHI | (0xff & (addr >> 8)));
702 cx_clear(MC417_RWD, SP2_ADHI);
706 cx_write(MC417_OEN, SP2_EN_ALL | SP2_DATA);
709 cx_write(MC417_RWD, SP2_CTRL_OFF | data);
712 cx_clear(MC417_RWD, SP2_CS0);
715 cx_clear(MC417_RWD, (read) ? SP2_RD : SP2_WR);
717 /* wait for a maximum of 1 msec */
718 timeout = jiffies + msecs_to_jiffies(1);
719 while (!time_after(jiffies, timeout)) {
720 tmp = cx_read(MC417_RWD);
721 if ((tmp & SP2_ACK) == 0)
723 usleep_range(50, 100);
726 cx_set(MC417_RWD, SP2_CTRL_OFF);
729 mutex_unlock(&dev->gpio_lock);
743 static int cx23885_dvb_set_frontend(struct dvb_frontend *fe)
745 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
746 struct cx23885_tsport *port = fe->dvb->priv;
747 struct cx23885_dev *dev = port->dev;
749 switch (dev->board) {
750 case CX23885_BOARD_HAUPPAUGE_HVR1275:
751 switch (p->modulation) {
753 cx23885_gpio_clear(dev, GPIO_5);
758 cx23885_gpio_set(dev, GPIO_5);
762 case CX23885_BOARD_MYGICA_X8506:
763 case CX23885_BOARD_MYGICA_X8507:
764 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
765 /* Select Digital TV */
766 cx23885_gpio_set(dev, GPIO_0);
770 /* Call the real set_frontend */
771 if (port->set_frontend)
772 return port->set_frontend(fe);
777 static void cx23885_set_frontend_hook(struct cx23885_tsport *port,
778 struct dvb_frontend *fe)
780 port->set_frontend = fe->ops.set_frontend;
781 fe->ops.set_frontend = cx23885_dvb_set_frontend;
784 static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
785 .prod = LGS8GXX_PROD_LGS8G75,
786 .demod_address = 0x19,
790 .if_clk_freq = 30400, /* 30.4 MHz */
791 .if_freq = 6500, /* 6.50 MHz */
795 .adc_vpp = 2, /* 1.6 Vpp */
799 static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
804 static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
805 .prod = ATBM8830_PROD_8830,
806 .demod_address = 0x44,
808 .ts_sampling_edge = 1,
810 .osc_clk_freq = 30400, /* in kHz */
811 .if_freq = 0, /* zero IF */
818 static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
823 static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
824 .prod = ATBM8830_PROD_8830,
825 .demod_address = 0x44,
827 .ts_sampling_edge = 1,
829 .osc_clk_freq = 30400, /* in kHz */
830 .if_freq = 0, /* zero IF */
837 static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
841 static struct stv0367_config netup_stv0367_config[] = {
843 .demod_address = 0x1c,
850 .demod_address = 0x1d,
859 static struct xc5000_config netup_xc5000_config[] = {
869 static struct drxk_config terratec_drxk_config[] = {
879 static struct mt2063_config terratec_mt2063_config[] = {
881 .tuner_address = 0x60,
883 .tuner_address = 0x67,
887 static const struct tda10071_platform_data hauppauge_tda10071_pdata = {
888 .clk = 40444000, /* 40.444 MHz */
890 .ts_mode = TDA10071_TS_SERIAL,
891 .pll_multiplier = 20,
892 .tuner_i2c_addr = 0x54,
895 static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = {
900 .ts_mode = M88DS3103_TS_PARALLEL,
908 static const struct m88ds3103_config dvbsky_s950c_m88ds3103_config = {
913 .ts_mode = M88DS3103_TS_CI,
921 static const struct m88ds3103_config dvbsky_s952_portc_m88ds3103_config = {
926 .ts_mode = M88DS3103_TS_SERIAL,
934 static const struct m88ds3103_config hauppauge_hvr5525_m88ds3103_config = {
938 .ts_mode = M88DS3103_TS_PARALLEL,
944 static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
946 struct cx23885_dev *dev = (struct cx23885_dev *)device;
947 unsigned long timeout = jiffies + msecs_to_jiffies(1);
950 mem = cx_read(MC417_RWD);
952 cx_set(MC417_OEN, ALT_DATA);
954 cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */
956 mem |= (data & ALT_DATA);
966 mem = (mem & ~ALT_RD) | ALT_WR;
968 mem = (mem & ~ALT_WR) | ALT_RD;
970 cx_write(MC417_RWD, mem); /* start RW cycle */
973 mem = cx_read(MC417_RWD);
974 if ((mem & ALT_RDY) == 0)
976 if (time_after(jiffies, timeout))
981 cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);
983 return mem & ALT_DATA;
988 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
990 struct dib7000p_ops *dib7000p_ops = fe->sec_priv;
992 return dib7000p_ops->set_gpio(fe, 8, 0, !onoff);
995 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1000 static struct dib0070_config dib7070p_dib0070_config = {
1001 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1002 .reset = dib7070_tuner_reset,
1003 .sleep = dib7070_tuner_sleep,
1005 .freq_offset_khz_vhf = 550,
1006 /* .flip_chip = 1, */
1009 /* DIB7070 generic */
1010 static struct dibx000_agc_config dib7070_agc_config = {
1011 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1014 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
1015 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1016 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
1018 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
1019 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1021 .time_stabiliz = 10,
1045 .perform_agc_softsplit = 0,
1048 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
1058 .IO_CLK_en_core = 1,
1061 /* refsel, sel, freq_15k */
1062 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1063 .ifreq = (0 << 25) | 0,
1065 .xtal_hz = 12000000,
1068 static struct dib7000p_config dib7070p_dib7000p_config = {
1069 /* .output_mode = OUTMODE_MPEG2_FIFO, */
1070 .output_mode = OUTMODE_MPEG2_SERIAL,
1071 /* .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK, */
1072 .output_mpeg2_in_188_bytes = 1,
1074 .agc_config_count = 1,
1075 .agc = &dib7070_agc_config,
1076 .bw = &dib7070_bw_config_12_mhz,
1077 .tuner_is_baseband = 1,
1080 .gpio_dir = 0xfcef, /* DIB7000P_GPIO_DEFAULT_DIRECTIONS, */
1081 .gpio_val = 0x0110, /* DIB7000P_GPIO_DEFAULT_VALUES, */
1082 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1084 .hostbus_diversity = 1,
1087 static int dvb_register_ci_mac(struct cx23885_tsport *port)
1089 struct cx23885_dev *dev = port->dev;
1090 struct i2c_client *client_ci = NULL;
1091 struct vb2_dvb_frontend *fe0;
1093 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
1097 switch (dev->board) {
1098 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
1099 static struct netup_card_info cinfo;
1101 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
1102 memcpy(port->frontends.adapter.proposed_mac,
1103 cinfo.port[port->nr - 1].mac, 6);
1104 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
1105 port->nr, port->frontends.adapter.proposed_mac);
1107 netup_ci_init(port);
1110 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
1111 struct altera_ci_config netup_ci_cfg = {
1112 .dev = dev,/* magic number to identify*/
1113 .adapter = &port->frontends.adapter,/* for CI */
1114 .demux = &fe0->dvb.demux,/* for hw pid filter */
1115 .fpga_rw = netup_altera_fpga_rw,
1118 altera_ci_init(&netup_ci_cfg, port->nr);
1121 case CX23885_BOARD_TEVII_S470: {
1122 u8 eeprom[256]; /* 24C02 i2c eeprom */
1127 /* Read entire EEPROM */
1128 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1129 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
1130 printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);
1131 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
1134 case CX23885_BOARD_DVBSKY_T9580:
1135 case CX23885_BOARD_DVBSKY_S950:
1136 case CX23885_BOARD_DVBSKY_S952:
1137 case CX23885_BOARD_DVBSKY_T982: {
1138 u8 eeprom[256]; /* 24C02 i2c eeprom */
1143 /* Read entire EEPROM */
1144 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1145 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
1147 printk(KERN_INFO "%s port %d MAC address: %pM\n",
1148 cx23885_boards[dev->board].name, port->nr,
1149 eeprom + 0xc0 + (port->nr-1) * 8);
1150 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 +
1151 (port->nr-1) * 8, 6);
1154 case CX23885_BOARD_DVBSKY_S950C:
1155 case CX23885_BOARD_DVBSKY_T980C:
1156 case CX23885_BOARD_TT_CT2_4500_CI: {
1157 u8 eeprom[256]; /* 24C02 i2c eeprom */
1158 struct sp2_config sp2_config;
1159 struct i2c_board_info info;
1160 struct cx23885_i2c *i2c_bus = &dev->i2c_bus[0];
1163 memset(&sp2_config, 0, sizeof(sp2_config));
1164 sp2_config.dvb_adap = &port->frontends.adapter;
1165 sp2_config.priv = port;
1166 sp2_config.ci_control = cx23885_sp2_ci_ctrl;
1167 memset(&info, 0, sizeof(struct i2c_board_info));
1168 strlcpy(info.type, "sp2", I2C_NAME_SIZE);
1170 info.platform_data = &sp2_config;
1171 request_module(info.type);
1172 client_ci = i2c_new_device(&i2c_bus->i2c_adap, &info);
1173 if (client_ci == NULL || client_ci->dev.driver == NULL)
1175 if (!try_module_get(client_ci->dev.driver->owner)) {
1176 i2c_unregister_device(client_ci);
1179 port->i2c_client_ci = client_ci;
1184 /* Read entire EEPROM */
1185 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1186 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
1188 printk(KERN_INFO "%s MAC address: %pM\n",
1189 cx23885_boards[dev->board].name, eeprom + 0xc0);
1190 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6);
1197 static int dvb_register(struct cx23885_tsport *port)
1199 struct dib7000p_ops dib7000p_ops;
1200 struct cx23885_dev *dev = port->dev;
1201 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
1202 struct vb2_dvb_frontend *fe0, *fe1 = NULL;
1203 struct si2168_config si2168_config;
1204 struct si2165_platform_data si2165_pdata;
1205 struct si2157_config si2157_config;
1206 struct ts2020_config ts2020_config;
1207 struct i2c_board_info info;
1208 struct i2c_adapter *adapter;
1209 struct i2c_client *client_demod = NULL, *client_tuner = NULL;
1210 struct i2c_client *client_sec = NULL;
1211 const struct m88ds3103_config *p_m88ds3103_config = NULL;
1212 int (*p_set_voltage)(struct dvb_frontend *fe,
1213 enum fe_sec_voltage voltage) = NULL;
1214 int mfe_shared = 0; /* bus not shared by default */
1217 /* Get the first frontend */
1218 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
1222 /* init struct vb2_dvb */
1223 fe0->dvb.name = dev->name;
1225 /* multi-frontend gate control is undefined or defaults to fe0 */
1226 port->frontends.gate = 0;
1228 /* Sets the gate control callback to be used by i2c command calls */
1229 port->gate_ctrl = cx23885_dvb_gate_ctrl;
1232 switch (dev->board) {
1233 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1234 i2c_bus = &dev->i2c_bus[0];
1235 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1236 &hauppauge_generic_config,
1237 &i2c_bus->i2c_adap);
1238 if (fe0->dvb.frontend == NULL)
1240 dvb_attach(mt2131_attach, fe0->dvb.frontend,
1242 &hauppauge_generic_tunerconfig, 0);
1244 case CX23885_BOARD_HAUPPAUGE_HVR1270:
1245 case CX23885_BOARD_HAUPPAUGE_HVR1275:
1246 i2c_bus = &dev->i2c_bus[0];
1247 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1248 &hauppauge_lgdt3305_config,
1249 &i2c_bus->i2c_adap);
1250 if (fe0->dvb.frontend == NULL)
1252 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1253 0x60, &dev->i2c_bus[1].i2c_adap,
1254 &hauppauge_hvr127x_config);
1255 if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1275)
1256 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1258 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1259 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1260 i2c_bus = &dev->i2c_bus[0];
1261 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1262 &hcw_s5h1411_config,
1263 &i2c_bus->i2c_adap);
1264 if (fe0->dvb.frontend == NULL)
1267 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1268 0x60, &dev->i2c_bus[1].i2c_adap,
1269 &hauppauge_tda18271_config);
1271 tda18271_attach(&dev->ts1.analog_fe,
1272 0x60, &dev->i2c_bus[1].i2c_adap,
1273 &hauppauge_tda18271_config);
1276 case CX23885_BOARD_HAUPPAUGE_HVR1800:
1277 i2c_bus = &dev->i2c_bus[0];
1278 switch (alt_tuner) {
1281 dvb_attach(s5h1409_attach,
1282 &hauppauge_ezqam_config,
1283 &i2c_bus->i2c_adap);
1284 if (fe0->dvb.frontend == NULL)
1287 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1288 &dev->i2c_bus[1].i2c_adap, 0x42,
1290 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1291 0x60, &dev->i2c_bus[1].i2c_adap,
1292 &hauppauge_tda18271_config);
1297 dvb_attach(s5h1409_attach,
1298 &hauppauge_generic_config,
1299 &i2c_bus->i2c_adap);
1300 if (fe0->dvb.frontend == NULL)
1302 dvb_attach(mt2131_attach, fe0->dvb.frontend,
1304 &hauppauge_generic_tunerconfig, 0);
1307 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
1308 i2c_bus = &dev->i2c_bus[0];
1309 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1310 &hauppauge_hvr1800lp_config,
1311 &i2c_bus->i2c_adap);
1312 if (fe0->dvb.frontend == NULL)
1314 dvb_attach(mt2131_attach, fe0->dvb.frontend,
1316 &hauppauge_generic_tunerconfig, 0);
1318 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
1319 i2c_bus = &dev->i2c_bus[0];
1320 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
1321 &fusionhdtv_5_express,
1322 &i2c_bus->i2c_adap);
1323 if (fe0->dvb.frontend == NULL)
1325 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1326 &i2c_bus->i2c_adap, 0x61,
1327 TUNER_LG_TDVS_H06XF);
1329 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
1330 i2c_bus = &dev->i2c_bus[1];
1331 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1332 &hauppauge_hvr1500q_config,
1333 &dev->i2c_bus[0].i2c_adap);
1334 if (fe0->dvb.frontend == NULL)
1336 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1338 &hauppauge_hvr1500q_tunerconfig);
1340 case CX23885_BOARD_HAUPPAUGE_HVR1500:
1341 i2c_bus = &dev->i2c_bus[1];
1342 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1343 &hauppauge_hvr1500_config,
1344 &dev->i2c_bus[0].i2c_adap);
1345 if (fe0->dvb.frontend != NULL) {
1346 struct dvb_frontend *fe;
1347 struct xc2028_config cfg = {
1348 .i2c_adap = &i2c_bus->i2c_adap,
1351 static struct xc2028_ctrl ctl = {
1352 .fname = "/*(DEBLOBBED)*/",
1354 .demod = XC3028_FE_OREN538,
1357 fe = dvb_attach(xc2028_attach,
1358 fe0->dvb.frontend, &cfg);
1359 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1360 fe->ops.tuner_ops.set_config(fe, &ctl);
1363 case CX23885_BOARD_HAUPPAUGE_HVR1200:
1364 case CX23885_BOARD_HAUPPAUGE_HVR1700:
1365 i2c_bus = &dev->i2c_bus[0];
1366 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1367 &hauppauge_hvr1200_config,
1368 &i2c_bus->i2c_adap);
1369 if (fe0->dvb.frontend == NULL)
1371 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1372 &dev->i2c_bus[1].i2c_adap, 0x42,
1374 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1375 0x60, &dev->i2c_bus[1].i2c_adap,
1376 &hauppauge_hvr1200_tuner_config);
1378 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1379 i2c_bus = &dev->i2c_bus[0];
1380 fe0->dvb.frontend = dvb_attach(tda10048_attach,
1381 &hauppauge_hvr1210_config,
1382 &i2c_bus->i2c_adap);
1383 if (fe0->dvb.frontend != NULL) {
1384 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1385 0x60, &dev->i2c_bus[1].i2c_adap,
1386 &hauppauge_hvr1210_tuner_config);
1389 case CX23885_BOARD_HAUPPAUGE_HVR1400:
1390 i2c_bus = &dev->i2c_bus[0];
1392 if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
1395 fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap,
1396 0x12, &hauppauge_hvr1400_dib7000_config);
1397 if (fe0->dvb.frontend != NULL) {
1398 struct dvb_frontend *fe;
1399 struct xc2028_config cfg = {
1400 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
1403 static struct xc2028_ctrl ctl = {
1404 .fname = "/*(DEBLOBBED)*/",
1406 .demod = XC3028_FE_DIBCOM52,
1407 /* This is true for all demods with
1409 .type = XC2028_D2633,
1412 fe = dvb_attach(xc2028_attach,
1413 fe0->dvb.frontend, &cfg);
1414 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1415 fe->ops.tuner_ops.set_config(fe, &ctl);
1418 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
1419 i2c_bus = &dev->i2c_bus[port->nr - 1];
1421 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1422 &dvico_s5h1409_config,
1423 &i2c_bus->i2c_adap);
1424 if (fe0->dvb.frontend == NULL)
1425 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1426 &dvico_s5h1411_config,
1427 &i2c_bus->i2c_adap);
1428 if (fe0->dvb.frontend != NULL)
1429 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1431 &dvico_xc5000_tunerconfig);
1433 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
1434 i2c_bus = &dev->i2c_bus[port->nr - 1];
1436 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1437 &dvico_fusionhdtv_xc3028,
1438 &i2c_bus->i2c_adap);
1439 if (fe0->dvb.frontend != NULL) {
1440 struct dvb_frontend *fe;
1441 struct xc2028_config cfg = {
1442 .i2c_adap = &i2c_bus->i2c_adap,
1445 static struct xc2028_ctrl ctl = {
1446 .fname = "/*(DEBLOBBED)*/",
1448 .demod = XC3028_FE_ZARLINK456,
1451 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
1453 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1454 fe->ops.tuner_ops.set_config(fe, &ctl);
1458 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2: {
1459 i2c_bus = &dev->i2c_bus[port->nr - 1];
1460 /* cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); */
1461 /* cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1); */
1463 if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
1466 if (dib7000p_ops.i2c_enumeration(&i2c_bus->i2c_adap, 1, 0x12, &dib7070p_dib7000p_config) < 0) {
1467 printk(KERN_WARNING "Unable to enumerate dib7000p\n");
1470 fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap, 0x80, &dib7070p_dib7000p_config);
1471 if (fe0->dvb.frontend != NULL) {
1472 struct i2c_adapter *tun_i2c;
1474 fe0->dvb.frontend->sec_priv = kmemdup(&dib7000p_ops, sizeof(dib7000p_ops), GFP_KERNEL);
1475 if (!fe0->dvb.frontend->sec_priv)
1477 tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1);
1478 if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config))
1483 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1484 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1485 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
1486 i2c_bus = &dev->i2c_bus[0];
1488 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1489 &dvico_fusionhdtv_xc3028,
1490 &i2c_bus->i2c_adap);
1491 if (fe0->dvb.frontend != NULL) {
1492 struct dvb_frontend *fe;
1493 struct xc2028_config cfg = {
1494 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
1497 static struct xc2028_ctrl ctl = {
1498 .fname = "/*(DEBLOBBED)*/",
1500 .demod = XC3028_FE_ZARLINK456,
1503 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
1505 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1506 fe->ops.tuner_ops.set_config(fe, &ctl);
1509 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1510 i2c_bus = &dev->i2c_bus[0];
1512 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1513 &dvico_fusionhdtv_xc3028,
1514 &i2c_bus->i2c_adap);
1515 if (fe0->dvb.frontend != NULL) {
1516 struct dvb_frontend *fe;
1517 struct xc4000_config cfg = {
1518 .i2c_address = 0x61,
1520 .dvb_amplitude = 134,
1521 .set_smoothedcvbs = 1,
1525 fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
1526 &dev->i2c_bus[1].i2c_adap, &cfg);
1528 printk(KERN_ERR "%s/2: xc4000 attach failed\n",
1530 goto frontend_detach;
1534 case CX23885_BOARD_TBS_6920:
1535 i2c_bus = &dev->i2c_bus[1];
1537 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1538 &tbs_cx24116_config,
1539 &i2c_bus->i2c_adap);
1540 if (fe0->dvb.frontend != NULL)
1541 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1544 case CX23885_BOARD_TBS_6980:
1545 case CX23885_BOARD_TBS_6981:
1546 i2c_bus = &dev->i2c_bus[1];
1551 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1552 &tbs_cx24117_config,
1553 &i2c_bus->i2c_adap);
1557 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1558 &tbs_cx24117_config,
1559 &i2c_bus->i2c_adap);
1563 case CX23885_BOARD_TEVII_S470:
1564 i2c_bus = &dev->i2c_bus[1];
1566 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1567 &tevii_ds3000_config,
1568 &i2c_bus->i2c_adap);
1569 if (fe0->dvb.frontend != NULL) {
1570 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1571 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1572 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1576 case CX23885_BOARD_DVBWORLD_2005:
1577 i2c_bus = &dev->i2c_bus[1];
1579 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1580 &dvbworld_cx24116_config,
1581 &i2c_bus->i2c_adap);
1583 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1584 i2c_bus = &dev->i2c_bus[0];
1588 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1589 &netup_stv0900_config,
1590 &i2c_bus->i2c_adap, 0);
1591 if (fe0->dvb.frontend != NULL) {
1592 if (dvb_attach(stv6110_attach,
1594 &netup_stv6110_tunerconfig_a,
1595 &i2c_bus->i2c_adap)) {
1596 if (!dvb_attach(lnbh24_attach,
1599 LNBH24_PCL | LNBH24_TTX,
1602 "No LNBH24 found!\n");
1609 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1610 &netup_stv0900_config,
1611 &i2c_bus->i2c_adap, 1);
1612 if (fe0->dvb.frontend != NULL) {
1613 if (dvb_attach(stv6110_attach,
1615 &netup_stv6110_tunerconfig_b,
1616 &i2c_bus->i2c_adap)) {
1617 if (!dvb_attach(lnbh24_attach,
1620 LNBH24_PCL | LNBH24_TTX,
1623 "No LNBH24 found!\n");
1630 case CX23885_BOARD_MYGICA_X8506:
1631 i2c_bus = &dev->i2c_bus[0];
1632 i2c_bus2 = &dev->i2c_bus[1];
1633 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1634 &mygica_x8506_lgs8gl5_config,
1635 &i2c_bus->i2c_adap);
1636 if (fe0->dvb.frontend == NULL)
1638 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1639 &i2c_bus2->i2c_adap, &mygica_x8506_xc5000_config);
1640 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1642 case CX23885_BOARD_MYGICA_X8507:
1643 i2c_bus = &dev->i2c_bus[0];
1644 i2c_bus2 = &dev->i2c_bus[1];
1645 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1646 &mygica_x8507_mb86a20s_config,
1647 &i2c_bus->i2c_adap);
1648 if (fe0->dvb.frontend == NULL)
1651 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1652 &i2c_bus2->i2c_adap,
1653 &mygica_x8507_xc5000_config);
1654 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1656 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1657 i2c_bus = &dev->i2c_bus[0];
1658 i2c_bus2 = &dev->i2c_bus[1];
1659 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1660 &magicpro_prohdtve2_lgs8g75_config,
1661 &i2c_bus->i2c_adap);
1662 if (fe0->dvb.frontend == NULL)
1664 dvb_attach(xc5000_attach, fe0->dvb.frontend,
1665 &i2c_bus2->i2c_adap,
1666 &magicpro_prohdtve2_xc5000_config);
1667 cx23885_set_frontend_hook(port, fe0->dvb.frontend);
1669 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1670 i2c_bus = &dev->i2c_bus[0];
1671 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1672 &hcw_s5h1411_config,
1673 &i2c_bus->i2c_adap);
1674 if (fe0->dvb.frontend == NULL)
1676 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1677 0x60, &dev->i2c_bus[0].i2c_adap,
1678 &hauppauge_tda18271_config);
1680 tda18271_attach(&dev->ts1.analog_fe,
1681 0x60, &dev->i2c_bus[1].i2c_adap,
1682 &hauppauge_tda18271_config);
1685 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1686 i2c_bus = &dev->i2c_bus[0];
1687 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1688 &hcw_s5h1411_config,
1689 &i2c_bus->i2c_adap);
1690 if (fe0->dvb.frontend == NULL)
1692 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1693 0x60, &dev->i2c_bus[0].i2c_adap,
1694 &hauppauge_tda18271_config);
1696 case CX23885_BOARD_MYGICA_X8558PRO:
1700 i2c_bus = &dev->i2c_bus[0];
1701 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1702 &mygica_x8558pro_atbm8830_cfg1,
1703 &i2c_bus->i2c_adap);
1704 if (fe0->dvb.frontend == NULL)
1706 dvb_attach(max2165_attach, fe0->dvb.frontend,
1708 &mygic_x8558pro_max2165_cfg1);
1712 i2c_bus = &dev->i2c_bus[1];
1713 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1714 &mygica_x8558pro_atbm8830_cfg2,
1715 &i2c_bus->i2c_adap);
1716 if (fe0->dvb.frontend == NULL)
1718 dvb_attach(max2165_attach, fe0->dvb.frontend,
1720 &mygic_x8558pro_max2165_cfg2);
1723 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1727 i2c_bus = &dev->i2c_bus[0];
1728 mfe_shared = 1;/* MFE */
1729 port->frontends.gate = 0;/* not clear for me yet */
1731 /* MFE frontend 1 DVB-T */
1732 fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
1733 &netup_stv0367_config[port->nr - 1],
1734 &i2c_bus->i2c_adap);
1735 if (fe0->dvb.frontend == NULL)
1737 if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend,
1739 &netup_xc5000_config[port->nr - 1]))
1740 goto frontend_detach;
1741 /* load xc5000 firmware */
1742 fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
1744 /* MFE frontend 2 */
1745 fe1 = vb2_dvb_get_frontend(&port->frontends, 2);
1747 goto frontend_detach;
1749 fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
1750 &netup_stv0367_config[port->nr - 1],
1751 &i2c_bus->i2c_adap);
1752 if (fe1->dvb.frontend == NULL)
1755 fe1->dvb.frontend->id = 1;
1756 if (NULL == dvb_attach(xc5000_attach,
1759 &netup_xc5000_config[port->nr - 1]))
1760 goto frontend_detach;
1762 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1763 i2c_bus = &dev->i2c_bus[0];
1764 i2c_bus2 = &dev->i2c_bus[1];
1769 fe0->dvb.frontend = dvb_attach(drxk_attach,
1770 &terratec_drxk_config[0],
1771 &i2c_bus->i2c_adap);
1772 if (fe0->dvb.frontend == NULL)
1774 if (!dvb_attach(mt2063_attach,
1776 &terratec_mt2063_config[0],
1777 &i2c_bus2->i2c_adap))
1778 goto frontend_detach;
1782 fe0->dvb.frontend = dvb_attach(drxk_attach,
1783 &terratec_drxk_config[1],
1784 &i2c_bus->i2c_adap);
1785 if (fe0->dvb.frontend == NULL)
1787 if (!dvb_attach(mt2063_attach,
1789 &terratec_mt2063_config[1],
1790 &i2c_bus2->i2c_adap))
1791 goto frontend_detach;
1795 case CX23885_BOARD_TEVII_S471:
1796 i2c_bus = &dev->i2c_bus[1];
1798 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1799 &tevii_ds3000_config,
1800 &i2c_bus->i2c_adap);
1801 if (fe0->dvb.frontend == NULL)
1803 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1804 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1806 case CX23885_BOARD_PROF_8000:
1807 i2c_bus = &dev->i2c_bus[0];
1809 fe0->dvb.frontend = dvb_attach(stv090x_attach,
1810 &prof_8000_stv090x_config,
1812 STV090x_DEMODULATOR_0);
1813 if (fe0->dvb.frontend == NULL)
1815 if (!dvb_attach(stb6100_attach,
1817 &prof_8000_stb6100_config,
1818 &i2c_bus->i2c_adap))
1819 goto frontend_detach;
1821 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
1823 case CX23885_BOARD_HAUPPAUGE_HVR4400: {
1824 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1825 struct a8293_platform_data a8293_pdata = {};
1827 i2c_bus = &dev->i2c_bus[0];
1828 i2c_bus2 = &dev->i2c_bus[1];
1832 /* attach demod + tuner combo */
1833 memset(&info, 0, sizeof(info));
1834 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1836 info.platform_data = &tda10071_pdata;
1837 request_module("tda10071");
1838 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1839 if (!client_demod || !client_demod->dev.driver)
1840 goto frontend_detach;
1841 if (!try_module_get(client_demod->dev.driver->owner)) {
1842 i2c_unregister_device(client_demod);
1843 goto frontend_detach;
1845 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1846 port->i2c_client_demod = client_demod;
1849 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1850 memset(&info, 0, sizeof(info));
1851 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1853 info.platform_data = &a8293_pdata;
1854 request_module("a8293");
1855 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1856 if (!client_sec || !client_sec->dev.driver)
1857 goto frontend_detach;
1858 if (!try_module_get(client_sec->dev.driver->owner)) {
1859 i2c_unregister_device(client_sec);
1860 goto frontend_detach;
1862 port->i2c_client_sec = client_sec;
1866 /* attach frontend */
1867 memset(&si2165_pdata, 0, sizeof(si2165_pdata));
1868 si2165_pdata.fe = &fe0->dvb.frontend;
1869 si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
1870 si2165_pdata.ref_freq_Hz = 16000000,
1871 memset(&info, 0, sizeof(struct i2c_board_info));
1872 strlcpy(info.type, "si2165", I2C_NAME_SIZE);
1874 info.platform_data = &si2165_pdata;
1875 request_module(info.type);
1876 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1877 if (client_demod == NULL ||
1878 client_demod->dev.driver == NULL)
1879 goto frontend_detach;
1880 if (!try_module_get(client_demod->dev.driver->owner)) {
1881 i2c_unregister_device(client_demod);
1882 goto frontend_detach;
1884 port->i2c_client_demod = client_demod;
1886 if (fe0->dvb.frontend == NULL)
1888 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1889 if (!dvb_attach(tda18271_attach,
1891 0x60, &i2c_bus2->i2c_adap,
1892 &hauppauge_hvr4400_tuner_config))
1893 goto frontend_detach;
1898 case CX23885_BOARD_HAUPPAUGE_STARBURST: {
1899 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1900 struct a8293_platform_data a8293_pdata = {};
1902 i2c_bus = &dev->i2c_bus[0];
1904 /* attach demod + tuner combo */
1905 memset(&info, 0, sizeof(info));
1906 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1908 info.platform_data = &tda10071_pdata;
1909 request_module("tda10071");
1910 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1911 if (!client_demod || !client_demod->dev.driver)
1912 goto frontend_detach;
1913 if (!try_module_get(client_demod->dev.driver->owner)) {
1914 i2c_unregister_device(client_demod);
1915 goto frontend_detach;
1917 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1918 port->i2c_client_demod = client_demod;
1921 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1922 memset(&info, 0, sizeof(info));
1923 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1925 info.platform_data = &a8293_pdata;
1926 request_module("a8293");
1927 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1928 if (!client_sec || !client_sec->dev.driver)
1929 goto frontend_detach;
1930 if (!try_module_get(client_sec->dev.driver->owner)) {
1931 i2c_unregister_device(client_sec);
1932 goto frontend_detach;
1934 port->i2c_client_sec = client_sec;
1937 case CX23885_BOARD_DVBSKY_T9580:
1938 case CX23885_BOARD_DVBSKY_S950:
1939 i2c_bus = &dev->i2c_bus[0];
1940 i2c_bus2 = &dev->i2c_bus[1];
1942 /* port b - satellite */
1944 /* attach frontend */
1945 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
1946 &dvbsky_t9580_m88ds3103_config,
1947 &i2c_bus2->i2c_adap, &adapter);
1948 if (fe0->dvb.frontend == NULL)
1952 memset(&ts2020_config, 0, sizeof(ts2020_config));
1953 ts2020_config.fe = fe0->dvb.frontend;
1954 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
1955 memset(&info, 0, sizeof(struct i2c_board_info));
1956 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
1958 info.platform_data = &ts2020_config;
1959 request_module(info.type);
1960 client_tuner = i2c_new_device(adapter, &info);
1961 if (client_tuner == NULL ||
1962 client_tuner->dev.driver == NULL)
1963 goto frontend_detach;
1964 if (!try_module_get(client_tuner->dev.driver->owner)) {
1965 i2c_unregister_device(client_tuner);
1966 goto frontend_detach;
1969 /* delegate signal strength measurement to tuner */
1970 fe0->dvb.frontend->ops.read_signal_strength =
1971 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
1974 * for setting the voltage we need to set GPIOs on
1977 port->fe_set_voltage =
1978 fe0->dvb.frontend->ops.set_voltage;
1979 fe0->dvb.frontend->ops.set_voltage =
1980 dvbsky_t9580_set_voltage;
1982 port->i2c_client_tuner = client_tuner;
1985 /* port c - terrestrial/cable */
1987 /* attach frontend */
1988 memset(&si2168_config, 0, sizeof(si2168_config));
1989 si2168_config.i2c_adapter = &adapter;
1990 si2168_config.fe = &fe0->dvb.frontend;
1991 si2168_config.ts_mode = SI2168_TS_SERIAL;
1992 memset(&info, 0, sizeof(struct i2c_board_info));
1993 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1995 info.platform_data = &si2168_config;
1996 request_module(info.type);
1997 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1998 if (client_demod == NULL ||
1999 client_demod->dev.driver == NULL)
2000 goto frontend_detach;
2001 if (!try_module_get(client_demod->dev.driver->owner)) {
2002 i2c_unregister_device(client_demod);
2003 goto frontend_detach;
2005 port->i2c_client_demod = client_demod;
2008 memset(&si2157_config, 0, sizeof(si2157_config));
2009 si2157_config.fe = fe0->dvb.frontend;
2010 si2157_config.if_port = 1;
2011 memset(&info, 0, sizeof(struct i2c_board_info));
2012 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2014 info.platform_data = &si2157_config;
2015 request_module(info.type);
2016 client_tuner = i2c_new_device(adapter, &info);
2017 if (client_tuner == NULL ||
2018 client_tuner->dev.driver == NULL)
2019 goto frontend_detach;
2021 if (!try_module_get(client_tuner->dev.driver->owner)) {
2022 i2c_unregister_device(client_tuner);
2023 goto frontend_detach;
2025 port->i2c_client_tuner = client_tuner;
2029 case CX23885_BOARD_DVBSKY_T980C:
2030 case CX23885_BOARD_TT_CT2_4500_CI:
2031 i2c_bus = &dev->i2c_bus[0];
2032 i2c_bus2 = &dev->i2c_bus[1];
2034 /* attach frontend */
2035 memset(&si2168_config, 0, sizeof(si2168_config));
2036 si2168_config.i2c_adapter = &adapter;
2037 si2168_config.fe = &fe0->dvb.frontend;
2038 si2168_config.ts_mode = SI2168_TS_PARALLEL;
2039 memset(&info, 0, sizeof(struct i2c_board_info));
2040 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2042 info.platform_data = &si2168_config;
2043 request_module(info.type);
2044 client_demod = i2c_new_device(&i2c_bus2->i2c_adap, &info);
2045 if (client_demod == NULL || client_demod->dev.driver == NULL)
2046 goto frontend_detach;
2047 if (!try_module_get(client_demod->dev.driver->owner)) {
2048 i2c_unregister_device(client_demod);
2049 goto frontend_detach;
2051 port->i2c_client_demod = client_demod;
2054 memset(&si2157_config, 0, sizeof(si2157_config));
2055 si2157_config.fe = fe0->dvb.frontend;
2056 si2157_config.if_port = 1;
2057 memset(&info, 0, sizeof(struct i2c_board_info));
2058 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2060 info.platform_data = &si2157_config;
2061 request_module(info.type);
2062 client_tuner = i2c_new_device(adapter, &info);
2063 if (client_tuner == NULL ||
2064 client_tuner->dev.driver == NULL)
2065 goto frontend_detach;
2066 if (!try_module_get(client_tuner->dev.driver->owner)) {
2067 i2c_unregister_device(client_tuner);
2068 goto frontend_detach;
2070 port->i2c_client_tuner = client_tuner;
2072 case CX23885_BOARD_DVBSKY_S950C:
2073 i2c_bus = &dev->i2c_bus[0];
2074 i2c_bus2 = &dev->i2c_bus[1];
2076 /* attach frontend */
2077 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2078 &dvbsky_s950c_m88ds3103_config,
2079 &i2c_bus2->i2c_adap, &adapter);
2080 if (fe0->dvb.frontend == NULL)
2084 memset(&ts2020_config, 0, sizeof(ts2020_config));
2085 ts2020_config.fe = fe0->dvb.frontend;
2086 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2087 memset(&info, 0, sizeof(struct i2c_board_info));
2088 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2090 info.platform_data = &ts2020_config;
2091 request_module(info.type);
2092 client_tuner = i2c_new_device(adapter, &info);
2093 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
2094 goto frontend_detach;
2095 if (!try_module_get(client_tuner->dev.driver->owner)) {
2096 i2c_unregister_device(client_tuner);
2097 goto frontend_detach;
2100 /* delegate signal strength measurement to tuner */
2101 fe0->dvb.frontend->ops.read_signal_strength =
2102 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2104 port->i2c_client_tuner = client_tuner;
2106 case CX23885_BOARD_DVBSKY_S952:
2110 i2c_bus = &dev->i2c_bus[1];
2111 p_m88ds3103_config = &dvbsky_t9580_m88ds3103_config;
2112 p_set_voltage = dvbsky_t9580_set_voltage;
2116 i2c_bus = &dev->i2c_bus[0];
2117 p_m88ds3103_config = &dvbsky_s952_portc_m88ds3103_config;
2118 p_set_voltage = dvbsky_s952_portc_set_voltage;
2122 /* attach frontend */
2123 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2125 &i2c_bus->i2c_adap, &adapter);
2126 if (fe0->dvb.frontend == NULL)
2130 memset(&ts2020_config, 0, sizeof(ts2020_config));
2131 ts2020_config.fe = fe0->dvb.frontend;
2132 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2133 memset(&info, 0, sizeof(struct i2c_board_info));
2134 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2136 info.platform_data = &ts2020_config;
2137 request_module(info.type);
2138 client_tuner = i2c_new_device(adapter, &info);
2139 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
2140 goto frontend_detach;
2141 if (!try_module_get(client_tuner->dev.driver->owner)) {
2142 i2c_unregister_device(client_tuner);
2143 goto frontend_detach;
2146 /* delegate signal strength measurement to tuner */
2147 fe0->dvb.frontend->ops.read_signal_strength =
2148 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2151 * for setting the voltage we need to set GPIOs on
2154 port->fe_set_voltage =
2155 fe0->dvb.frontend->ops.set_voltage;
2156 fe0->dvb.frontend->ops.set_voltage = p_set_voltage;
2158 port->i2c_client_tuner = client_tuner;
2160 case CX23885_BOARD_DVBSKY_T982:
2161 memset(&si2168_config, 0, sizeof(si2168_config));
2165 i2c_bus = &dev->i2c_bus[1];
2166 si2168_config.ts_mode = SI2168_TS_PARALLEL;
2170 i2c_bus = &dev->i2c_bus[0];
2171 si2168_config.ts_mode = SI2168_TS_SERIAL;
2175 /* attach frontend */
2176 si2168_config.i2c_adapter = &adapter;
2177 si2168_config.fe = &fe0->dvb.frontend;
2178 memset(&info, 0, sizeof(struct i2c_board_info));
2179 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2181 info.platform_data = &si2168_config;
2182 request_module(info.type);
2183 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
2184 if (client_demod == NULL || client_demod->dev.driver == NULL)
2185 goto frontend_detach;
2186 if (!try_module_get(client_demod->dev.driver->owner)) {
2187 i2c_unregister_device(client_demod);
2188 goto frontend_detach;
2190 port->i2c_client_demod = client_demod;
2193 memset(&si2157_config, 0, sizeof(si2157_config));
2194 si2157_config.fe = fe0->dvb.frontend;
2195 si2157_config.if_port = 1;
2196 memset(&info, 0, sizeof(struct i2c_board_info));
2197 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2199 info.platform_data = &si2157_config;
2200 request_module(info.type);
2201 client_tuner = i2c_new_device(adapter, &info);
2202 if (client_tuner == NULL ||
2203 client_tuner->dev.driver == NULL)
2204 goto frontend_detach;
2205 if (!try_module_get(client_tuner->dev.driver->owner)) {
2206 i2c_unregister_device(client_tuner);
2207 goto frontend_detach;
2209 port->i2c_client_tuner = client_tuner;
2211 case CX23885_BOARD_HAUPPAUGE_HVR5525: {
2212 struct m88rs6000t_config m88rs6000t_config;
2213 struct a8293_platform_data a8293_pdata = {};
2217 /* port b - satellite */
2219 /* attach frontend */
2220 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2221 &hauppauge_hvr5525_m88ds3103_config,
2222 &dev->i2c_bus[0].i2c_adap, &adapter);
2223 if (fe0->dvb.frontend == NULL)
2227 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
2228 memset(&info, 0, sizeof(info));
2229 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
2231 info.platform_data = &a8293_pdata;
2232 request_module("a8293");
2233 client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2234 if (!client_sec || !client_sec->dev.driver)
2235 goto frontend_detach;
2236 if (!try_module_get(client_sec->dev.driver->owner)) {
2237 i2c_unregister_device(client_sec);
2238 goto frontend_detach;
2240 port->i2c_client_sec = client_sec;
2243 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
2244 m88rs6000t_config.fe = fe0->dvb.frontend;
2245 memset(&info, 0, sizeof(struct i2c_board_info));
2246 strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE);
2248 info.platform_data = &m88rs6000t_config;
2249 request_module("%s", info.type);
2250 client_tuner = i2c_new_device(adapter, &info);
2251 if (!client_tuner || !client_tuner->dev.driver)
2252 goto frontend_detach;
2253 if (!try_module_get(client_tuner->dev.driver->owner)) {
2254 i2c_unregister_device(client_tuner);
2255 goto frontend_detach;
2257 port->i2c_client_tuner = client_tuner;
2259 /* delegate signal strength measurement to tuner */
2260 fe0->dvb.frontend->ops.read_signal_strength =
2261 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2263 /* port c - terrestrial/cable */
2265 /* attach frontend */
2266 memset(&si2168_config, 0, sizeof(si2168_config));
2267 si2168_config.i2c_adapter = &adapter;
2268 si2168_config.fe = &fe0->dvb.frontend;
2269 si2168_config.ts_mode = SI2168_TS_SERIAL;
2270 memset(&info, 0, sizeof(struct i2c_board_info));
2271 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2273 info.platform_data = &si2168_config;
2274 request_module("%s", info.type);
2275 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2276 if (!client_demod || !client_demod->dev.driver)
2277 goto frontend_detach;
2278 if (!try_module_get(client_demod->dev.driver->owner)) {
2279 i2c_unregister_device(client_demod);
2280 goto frontend_detach;
2282 port->i2c_client_demod = client_demod;
2285 memset(&si2157_config, 0, sizeof(si2157_config));
2286 si2157_config.fe = fe0->dvb.frontend;
2287 si2157_config.if_port = 1;
2288 memset(&info, 0, sizeof(struct i2c_board_info));
2289 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2291 info.platform_data = &si2157_config;
2292 request_module("%s", info.type);
2293 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2294 if (!client_tuner || !client_tuner->dev.driver) {
2295 module_put(client_demod->dev.driver->owner);
2296 i2c_unregister_device(client_demod);
2297 port->i2c_client_demod = NULL;
2298 goto frontend_detach;
2300 if (!try_module_get(client_tuner->dev.driver->owner)) {
2301 i2c_unregister_device(client_tuner);
2302 module_put(client_demod->dev.driver->owner);
2303 i2c_unregister_device(client_demod);
2304 port->i2c_client_demod = NULL;
2305 goto frontend_detach;
2307 port->i2c_client_tuner = client_tuner;
2312 case CX23885_BOARD_HAUPPAUGE_QUADHD_DVB:
2314 /* port b - Terrestrial/cable */
2316 /* attach frontend */
2317 memset(&si2168_config, 0, sizeof(si2168_config));
2318 si2168_config.i2c_adapter = &adapter;
2319 si2168_config.fe = &fe0->dvb.frontend;
2320 si2168_config.ts_mode = SI2168_TS_SERIAL;
2321 memset(&info, 0, sizeof(struct i2c_board_info));
2322 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2324 info.platform_data = &si2168_config;
2325 request_module("%s", info.type);
2326 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2327 if (!client_demod || !client_demod->dev.driver)
2328 goto frontend_detach;
2329 if (!try_module_get(client_demod->dev.driver->owner)) {
2330 i2c_unregister_device(client_demod);
2331 goto frontend_detach;
2333 port->i2c_client_demod = client_demod;
2336 memset(&si2157_config, 0, sizeof(si2157_config));
2337 si2157_config.fe = fe0->dvb.frontend;
2338 si2157_config.if_port = 1;
2339 memset(&info, 0, sizeof(struct i2c_board_info));
2340 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2342 info.platform_data = &si2157_config;
2343 request_module("%s", info.type);
2344 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2345 if (!client_tuner || !client_tuner->dev.driver) {
2346 module_put(client_demod->dev.driver->owner);
2347 i2c_unregister_device(client_demod);
2348 port->i2c_client_demod = NULL;
2349 goto frontend_detach;
2351 if (!try_module_get(client_tuner->dev.driver->owner)) {
2352 i2c_unregister_device(client_tuner);
2353 module_put(client_demod->dev.driver->owner);
2354 i2c_unregister_device(client_demod);
2355 port->i2c_client_demod = NULL;
2356 goto frontend_detach;
2358 port->i2c_client_tuner = client_tuner;
2361 /* port c - terrestrial/cable */
2363 /* attach frontend */
2364 memset(&si2168_config, 0, sizeof(si2168_config));
2365 si2168_config.i2c_adapter = &adapter;
2366 si2168_config.fe = &fe0->dvb.frontend;
2367 si2168_config.ts_mode = SI2168_TS_SERIAL;
2368 memset(&info, 0, sizeof(struct i2c_board_info));
2369 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2371 info.platform_data = &si2168_config;
2372 request_module("%s", info.type);
2373 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2374 if (!client_demod || !client_demod->dev.driver)
2375 goto frontend_detach;
2376 if (!try_module_get(client_demod->dev.driver->owner)) {
2377 i2c_unregister_device(client_demod);
2378 goto frontend_detach;
2380 port->i2c_client_demod = client_demod;
2383 memset(&si2157_config, 0, sizeof(si2157_config));
2384 si2157_config.fe = fe0->dvb.frontend;
2385 si2157_config.if_port = 1;
2386 memset(&info, 0, sizeof(struct i2c_board_info));
2387 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2389 info.platform_data = &si2157_config;
2390 request_module("%s", info.type);
2391 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2392 if (!client_tuner || !client_tuner->dev.driver) {
2393 module_put(client_demod->dev.driver->owner);
2394 i2c_unregister_device(client_demod);
2395 port->i2c_client_demod = NULL;
2396 goto frontend_detach;
2398 if (!try_module_get(client_tuner->dev.driver->owner)) {
2399 i2c_unregister_device(client_tuner);
2400 module_put(client_demod->dev.driver->owner);
2401 i2c_unregister_device(client_demod);
2402 port->i2c_client_demod = NULL;
2403 goto frontend_detach;
2405 port->i2c_client_tuner = client_tuner;
2409 case CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC:
2411 /* port b - Terrestrial/cable */
2413 /* attach frontend */
2414 i2c_bus = &dev->i2c_bus[0];
2415 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
2416 &hauppauge_quadHD_ATSC_a_config, &i2c_bus->i2c_adap);
2417 if (fe0->dvb.frontend == NULL)
2421 memset(&si2157_config, 0, sizeof(si2157_config));
2422 si2157_config.fe = fe0->dvb.frontend;
2423 si2157_config.if_port = 1;
2424 si2157_config.inversion = 1;
2425 memset(&info, 0, sizeof(struct i2c_board_info));
2426 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2428 info.platform_data = &si2157_config;
2429 request_module("%s", info.type);
2430 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2431 if (!client_tuner || !client_tuner->dev.driver) {
2432 module_put(client_demod->dev.driver->owner);
2433 i2c_unregister_device(client_demod);
2434 port->i2c_client_demod = NULL;
2435 goto frontend_detach;
2437 if (!try_module_get(client_tuner->dev.driver->owner)) {
2438 i2c_unregister_device(client_tuner);
2439 module_put(client_demod->dev.driver->owner);
2440 i2c_unregister_device(client_demod);
2441 port->i2c_client_demod = NULL;
2442 goto frontend_detach;
2444 port->i2c_client_tuner = client_tuner;
2447 /* port c - terrestrial/cable */
2449 /* attach frontend */
2450 i2c_bus = &dev->i2c_bus[0];
2451 fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
2452 &hauppauge_quadHD_ATSC_b_config, &i2c_bus->i2c_adap);
2453 if (fe0->dvb.frontend == NULL)
2457 memset(&si2157_config, 0, sizeof(si2157_config));
2458 si2157_config.fe = fe0->dvb.frontend;
2459 si2157_config.if_port = 1;
2460 si2157_config.inversion = 1;
2461 memset(&info, 0, sizeof(struct i2c_board_info));
2462 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2464 info.platform_data = &si2157_config;
2465 request_module("%s", info.type);
2466 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2467 if (!client_tuner || !client_tuner->dev.driver) {
2468 module_put(client_demod->dev.driver->owner);
2469 i2c_unregister_device(client_demod);
2470 port->i2c_client_demod = NULL;
2471 goto frontend_detach;
2473 if (!try_module_get(client_tuner->dev.driver->owner)) {
2474 i2c_unregister_device(client_tuner);
2475 module_put(client_demod->dev.driver->owner);
2476 i2c_unregister_device(client_demod);
2477 port->i2c_client_demod = NULL;
2478 goto frontend_detach;
2480 port->i2c_client_tuner = client_tuner;
2486 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
2487 " isn't supported yet\n",
2492 if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
2493 printk(KERN_ERR "%s: frontend initialization failed\n",
2495 goto frontend_detach;
2498 /* define general-purpose callback pointer */
2499 fe0->dvb.frontend->callback = cx23885_tuner_callback;
2501 fe1->dvb.frontend->callback = cx23885_tuner_callback;
2503 /* Ensure all frontends negotiate bus access */
2504 fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
2506 fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
2509 /* Put the analog decoder in standby to keep it quiet */
2510 call_all(dev, core, s_power, 0);
2512 if (fe0->dvb.frontend->ops.analog_ops.standby)
2513 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
2515 /* register everything */
2516 ret = vb2_dvb_register_bus(&port->frontends, THIS_MODULE, port,
2517 &dev->pci->dev, NULL,
2518 adapter_nr, mfe_shared);
2520 goto frontend_detach;
2522 ret = dvb_register_ci_mac(port);
2524 goto frontend_detach;
2529 /* remove I2C client for SEC */
2530 client_sec = port->i2c_client_sec;
2532 module_put(client_sec->dev.driver->owner);
2533 i2c_unregister_device(client_sec);
2534 port->i2c_client_sec = NULL;
2537 /* remove I2C client for tuner */
2538 client_tuner = port->i2c_client_tuner;
2540 module_put(client_tuner->dev.driver->owner);
2541 i2c_unregister_device(client_tuner);
2542 port->i2c_client_tuner = NULL;
2545 /* remove I2C client for demodulator */
2546 client_demod = port->i2c_client_demod;
2548 module_put(client_demod->dev.driver->owner);
2549 i2c_unregister_device(client_demod);
2550 port->i2c_client_demod = NULL;
2553 port->gate_ctrl = NULL;
2554 vb2_dvb_dealloc_frontends(&port->frontends);
2558 int cx23885_dvb_register(struct cx23885_tsport *port)
2561 struct vb2_dvb_frontend *fe0;
2562 struct cx23885_dev *dev = port->dev;
2565 /* Here we need to allocate the correct number of frontends,
2566 * as reflected in the cards struct. The reality is that currently
2567 * no cx23885 boards support this - yet. But, if we don't modify this
2568 * code then the second frontend would never be allocated (later)
2569 * and fail with error before the attach in dvb_register().
2570 * Without these changes we risk an OOPS later. The changes here
2571 * are for safety, and should provide a good foundation for the
2572 * future addition of any multi-frontend cx23885 based boards.
2574 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
2575 port->num_frontends);
2577 for (i = 1; i <= port->num_frontends; i++) {
2578 struct vb2_queue *q;
2580 if (vb2_dvb_alloc_frontend(
2581 &port->frontends, i) == NULL) {
2582 printk(KERN_ERR "%s() failed to alloc\n", __func__);
2586 fe0 = vb2_dvb_get_frontend(&port->frontends, i);
2590 dprintk(1, "%s\n", __func__);
2591 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
2600 /* We have to init the queue for each frontend on a port. */
2601 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
2603 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2604 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
2605 q->gfp_flags = GFP_DMA32;
2606 q->min_buffers_needed = 2;
2608 q->buf_struct_size = sizeof(struct cx23885_buffer);
2610 q->mem_ops = &vb2_dma_sg_memops;
2611 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2612 q->lock = &dev->lock;
2613 q->dev = &dev->pci->dev;
2615 err = vb2_queue_init(q);
2619 err = dvb_register(port);
2621 printk(KERN_ERR "%s() dvb_register failed err = %d\n",
2627 int cx23885_dvb_unregister(struct cx23885_tsport *port)
2629 struct vb2_dvb_frontend *fe0;
2630 struct i2c_client *client;
2632 /* remove I2C client for CI */
2633 client = port->i2c_client_ci;
2635 module_put(client->dev.driver->owner);
2636 i2c_unregister_device(client);
2639 /* remove I2C client for SEC */
2640 client = port->i2c_client_sec;
2642 module_put(client->dev.driver->owner);
2643 i2c_unregister_device(client);
2646 /* remove I2C client for tuner */
2647 client = port->i2c_client_tuner;
2649 module_put(client->dev.driver->owner);
2650 i2c_unregister_device(client);
2653 /* remove I2C client for demodulator */
2654 client = port->i2c_client_demod;
2656 module_put(client->dev.driver->owner);
2657 i2c_unregister_device(client);
2660 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
2662 if (fe0 && fe0->dvb.frontend)
2663 vb2_dvb_unregister_bus(&port->frontends);
2665 switch (port->dev->board) {
2666 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
2667 netup_ci_exit(port);
2669 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
2670 altera_ci_release(port->dev, port->nr);
2674 port->gate_ctrl = NULL;