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