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