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