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