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