blob: e236df23370ea52f350fcb7e52e50aead5a56191 [file] [log] [blame]
Steven Tothd19770e2007-03-11 20:44:05 -03001/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
Steven Toth6d897612008-09-03 17:12:12 -03004 * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org>
Steven Tothd19770e2007-03-11 20:44:05 -03005 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/device.h>
25#include <linux/fs.h>
26#include <linux/kthread.h>
27#include <linux/file.h>
28#include <linux/suspend.h>
29
30#include "cx23885.h"
Steven Tothd19770e2007-03-11 20:44:05 -030031#include <media/v4l2-common.h>
32
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030033#include "dvb_ca_en50221.h"
Steven Tothd19770e2007-03-11 20:44:05 -030034#include "s5h1409.h"
Michael Krufky52b50452008-07-09 02:18:49 -030035#include "s5h1411.h"
Steven Tothd19770e2007-03-11 20:44:05 -030036#include "mt2131.h"
Michael Krufky3ba71d22007-12-07 01:40:36 -030037#include "tda8290.h"
Michael Krufky4041f1a2007-12-24 04:52:08 -030038#include "tda18271.h"
Michael Krufky9bc37ca2007-09-08 15:17:13 -030039#include "lgdt330x.h"
Steven Tothd1987d52007-12-18 01:57:06 -030040#include "xc5000.h"
Steven Tothb3ea0162008-04-19 01:14:19 -030041#include "tda10048.h"
Michael Krufky07b4a832007-12-18 01:09:11 -030042#include "tuner-xc2028.h"
Michael Krufky827855d2008-04-22 14:46:16 -030043#include "tuner-simple.h"
Steven Toth66762372008-04-22 15:38:26 -030044#include "dib7000p.h"
45#include "dibx000_common.h"
Steven Tothaef2d182008-08-04 21:39:53 -030046#include "zl10353.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030047#include "stv0900.h"
48#include "stv6110.h"
49#include "lnbh24.h"
Igor M. Liplianin96318d02009-01-17 12:11:20 -030050#include "cx24116.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030051#include "cimax2.h"
David Wong493b7122009-05-18 05:25:49 -030052#include "lgs8gxx.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030053#include "netup-eeprom.h"
54#include "netup-init.h"
Michael Krufkya5dbf452009-05-03 23:27:02 -030055#include "lgdt3305.h"
Steven Tothd19770e2007-03-11 20:44:05 -030056
Steven Toth4513fc692008-01-12 11:36:36 -030057static unsigned int debug;
Steven Tothd19770e2007-03-11 20:44:05 -030058
Steven Toth4513fc692008-01-12 11:36:36 -030059#define dprintk(level, fmt, arg...)\
60 do { if (debug >= level)\
61 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
62 } while (0)
Steven Tothd19770e2007-03-11 20:44:05 -030063
64/* ------------------------------------------------------------------ */
65
Michael Krufky3ba71d22007-12-07 01:40:36 -030066static unsigned int alt_tuner;
67module_param(alt_tuner, int, 0644);
68MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
69
Janne Grunau78e92002008-04-09 19:13:13 -030070DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
71
Michael Krufky3ba71d22007-12-07 01:40:36 -030072/* ------------------------------------------------------------------ */
73
Steven Tothd19770e2007-03-11 20:44:05 -030074static int dvb_buf_setup(struct videobuf_queue *q,
75 unsigned int *count, unsigned int *size)
76{
77 struct cx23885_tsport *port = q->priv_data;
78
79 port->ts_packet_size = 188 * 4;
80 port->ts_packet_count = 32;
81
82 *size = port->ts_packet_size * port->ts_packet_count;
83 *count = 32;
84 return 0;
85}
86
Michael Krufky44a64812007-03-20 23:00:18 -030087static int dvb_buf_prepare(struct videobuf_queue *q,
88 struct videobuf_buffer *vb, enum v4l2_field field)
Steven Tothd19770e2007-03-11 20:44:05 -030089{
90 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030091 return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
Steven Tothd19770e2007-03-11 20:44:05 -030092}
93
94static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
95{
96 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030097 cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -030098}
99
Michael Krufky44a64812007-03-20 23:00:18 -0300100static void dvb_buf_release(struct videobuf_queue *q,
101 struct videobuf_buffer *vb)
Steven Tothd19770e2007-03-11 20:44:05 -0300102{
Steven Toth9c8ced52008-10-16 20:18:44 -0300103 cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300104}
105
106static struct videobuf_queue_ops dvb_qops = {
107 .buf_setup = dvb_buf_setup,
108 .buf_prepare = dvb_buf_prepare,
109 .buf_queue = dvb_buf_queue,
110 .buf_release = dvb_buf_release,
111};
112
Steven Toth86184e02007-09-04 21:40:47 -0300113static struct s5h1409_config hauppauge_generic_config = {
Steven Tothd19770e2007-03-11 20:44:05 -0300114 .demod_address = 0x32 >> 1,
115 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothfc959be2007-09-08 19:08:17 -0300116 .gpio = S5H1409_GPIO_ON,
Michael Krufky2b032382007-12-13 10:04:10 -0300117 .qam_if = 44000,
Steven Tothfc959be2007-09-08 19:08:17 -0300118 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300119 .status_mode = S5H1409_DEMODLOCKING,
120 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothfc959be2007-09-08 19:08:17 -0300121};
122
Steven Tothb3ea0162008-04-19 01:14:19 -0300123static struct tda10048_config hauppauge_hvr1200_config = {
124 .demod_address = 0x10 >> 1,
125 .output_mode = TDA10048_SERIAL_OUTPUT,
126 .fwbulkwritelen = TDA10048_BULKWRITE_200,
Steven Toth484d9e02009-05-02 11:08:23 -0300127 .inversion = TDA10048_INVERSION_ON,
Steven Toth8816bef2009-05-15 21:04:18 -0300128 .dtv6_if_freq_khz = TDA10048_IF_3300,
129 .dtv7_if_freq_khz = TDA10048_IF_3800,
130 .dtv8_if_freq_khz = TDA10048_IF_4300,
Steven Toth484d9e02009-05-02 11:08:23 -0300131 .clk_freq_khz = TDA10048_CLK_16000,
Steven Tothb3ea0162008-04-19 01:14:19 -0300132};
133
Michael Krufky6b926ec2009-05-12 17:32:17 -0300134static struct tda10048_config hauppauge_hvr1210_config = {
135 .demod_address = 0x10 >> 1,
136 .output_mode = TDA10048_SERIAL_OUTPUT,
137 .fwbulkwritelen = TDA10048_BULKWRITE_200,
138 .inversion = TDA10048_INVERSION_ON,
Michael Krufkyc27586e2009-05-16 11:00:23 -0300139 .dtv6_if_freq_khz = TDA10048_IF_3300,
140 .dtv7_if_freq_khz = TDA10048_IF_3500,
141 .dtv8_if_freq_khz = TDA10048_IF_4000,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300142 .clk_freq_khz = TDA10048_CLK_16000,
143};
144
Michael Krufky3ba71d22007-12-07 01:40:36 -0300145static struct s5h1409_config hauppauge_ezqam_config = {
146 .demod_address = 0x32 >> 1,
147 .output_mode = S5H1409_SERIAL_OUTPUT,
148 .gpio = S5H1409_GPIO_OFF,
149 .qam_if = 4000,
150 .inversion = S5H1409_INVERSION_ON,
Steven Tothdfc1c082008-01-15 21:35:22 -0300151 .status_mode = S5H1409_DEMODLOCKING,
152 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300153};
154
Steven Tothfc959be2007-09-08 19:08:17 -0300155static struct s5h1409_config hauppauge_hvr1800lp_config = {
156 .demod_address = 0x32 >> 1,
157 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300158 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300159 .qam_if = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -0300160 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300161 .status_mode = S5H1409_DEMODLOCKING,
162 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd19770e2007-03-11 20:44:05 -0300163};
164
Michael Krufky07b4a832007-12-18 01:09:11 -0300165static struct s5h1409_config hauppauge_hvr1500_config = {
166 .demod_address = 0x32 >> 1,
167 .output_mode = S5H1409_SERIAL_OUTPUT,
168 .gpio = S5H1409_GPIO_OFF,
169 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300170 .status_mode = S5H1409_DEMODLOCKING,
171 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky07b4a832007-12-18 01:09:11 -0300172};
173
Steven Toth86184e02007-09-04 21:40:47 -0300174static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300175 0x61
176};
177
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300178static struct lgdt330x_config fusionhdtv_5_express = {
179 .demod_address = 0x0e,
180 .demod_chip = LGDT3303,
181 .serial_mpeg = 0x40,
182};
183
Steven Tothd1987d52007-12-18 01:57:06 -0300184static struct s5h1409_config hauppauge_hvr1500q_config = {
185 .demod_address = 0x32 >> 1,
186 .output_mode = S5H1409_SERIAL_OUTPUT,
187 .gpio = S5H1409_GPIO_ON,
188 .qam_if = 44000,
189 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300190 .status_mode = S5H1409_DEMODLOCKING,
191 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd1987d52007-12-18 01:57:06 -0300192};
193
Michael Krufky335377b2008-05-07 01:43:10 -0300194static struct s5h1409_config dvico_s5h1409_config = {
195 .demod_address = 0x32 >> 1,
196 .output_mode = S5H1409_SERIAL_OUTPUT,
197 .gpio = S5H1409_GPIO_ON,
198 .qam_if = 44000,
199 .inversion = S5H1409_INVERSION_OFF,
200 .status_mode = S5H1409_DEMODLOCKING,
201 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
202};
203
Michael Krufky52b50452008-07-09 02:18:49 -0300204static struct s5h1411_config dvico_s5h1411_config = {
205 .output_mode = S5H1411_SERIAL_OUTPUT,
206 .gpio = S5H1411_GPIO_ON,
207 .qam_if = S5H1411_IF_44000,
208 .vsb_if = S5H1411_IF_44000,
209 .inversion = S5H1411_INVERSION_OFF,
210 .status_mode = S5H1411_DEMODLOCKING,
211 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
212};
213
Michael Krufky19bc5792009-05-08 16:05:29 -0300214static struct s5h1411_config hcw_s5h1411_config = {
215 .output_mode = S5H1411_SERIAL_OUTPUT,
216 .gpio = S5H1411_GPIO_OFF,
217 .vsb_if = S5H1411_IF_44000,
218 .qam_if = S5H1411_IF_4000,
219 .inversion = S5H1411_INVERSION_ON,
220 .status_mode = S5H1411_DEMODLOCKING,
221 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
222};
223
Steven Tothd1987d52007-12-18 01:57:06 -0300224static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671cf2007-12-20 01:14:43 -0300225 .i2c_address = 0x61,
226 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300227};
228
Michael Krufky335377b2008-05-07 01:43:10 -0300229static struct xc5000_config dvico_xc5000_tunerconfig = {
230 .i2c_address = 0x64,
231 .if_khz = 5380,
Michael Krufky335377b2008-05-07 01:43:10 -0300232};
233
Michael Krufky4041f1a2007-12-24 04:52:08 -0300234static struct tda829x_config tda829x_no_probe = {
235 .probe_tuner = TDA829X_DONT_PROBE,
236};
237
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300238static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufkyc0dc0c12008-04-22 14:46:22 -0300239 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
240 .if_lvl = 6, .rfagc_top = 0x37 },
241 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
242 .if_lvl = 6, .rfagc_top = 0x37 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300243};
244
245static struct tda18271_config hauppauge_tda18271_config = {
246 .std_map = &hauppauge_tda18271_std_map,
247 .gate = TDA18271_GATE_ANALOG,
248};
249
Steven Tothb3ea0162008-04-19 01:14:19 -0300250static struct tda18271_config hauppauge_hvr1200_tuner_config = {
251 .gate = TDA18271_GATE_ANALOG,
252};
253
Michael Krufky6b926ec2009-05-12 17:32:17 -0300254static struct tda18271_config hauppauge_hvr1210_tuner_config = {
255 .gate = TDA18271_GATE_DIGITAL,
256};
257
Michael Krufky247bc542009-05-12 18:53:47 -0300258static struct tda18271_std_map hauppauge_hvr127x_std_map = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300259 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
260 .if_lvl = 1, .rfagc_top = 0x58 },
261 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
262 .if_lvl = 1, .rfagc_top = 0x58 },
263};
264
Michael Krufky247bc542009-05-12 18:53:47 -0300265static struct tda18271_config hauppauge_hvr127x_config = {
266 .std_map = &hauppauge_hvr127x_std_map,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300267};
268
Michael Krufky247bc542009-05-12 18:53:47 -0300269static struct lgdt3305_config hauppauge_lgdt3305_config = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300270 .i2c_addr = 0x0e,
271 .mpeg_mode = LGDT3305_MPEG_SERIAL,
272 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
273 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
274 .deny_i2c_rptr = 1,
275 .spectral_inversion = 1,
276 .qam_if_khz = 4000,
277 .vsb_if_khz = 3250,
278};
279
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700280static struct dibx000_agc_config xc3028_agc_config = {
Steven Toth66762372008-04-22 15:38:26 -0300281 BAND_VHF | BAND_UHF, /* band_caps */
282
283 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
284 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
285 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
286 * P_agc_nb_est=2, P_agc_write=0
287 */
288 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
289 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
290
291 712, /* inv_gain */
292 21, /* time_stabiliz */
293
294 0, /* alpha_level */
295 118, /* thlock */
296
297 0, /* wbd_inv */
298 2867, /* wbd_ref */
299 0, /* wbd_sel */
300 2, /* wbd_alpha */
301
302 0, /* agc1_max */
303 0, /* agc1_min */
304 39718, /* agc2_max */
305 9930, /* agc2_min */
306 0, /* agc1_pt1 */
307 0, /* agc1_pt2 */
308 0, /* agc1_pt3 */
309 0, /* agc1_slope1 */
310 0, /* agc1_slope2 */
311 0, /* agc2_pt1 */
312 128, /* agc2_pt2 */
313 29, /* agc2_slope1 */
314 29, /* agc2_slope2 */
315
316 17, /* alpha_mant */
317 27, /* alpha_exp */
318 23, /* beta_mant */
319 51, /* beta_exp */
320
321 1, /* perform_agc_softsplit */
322};
323
324/* PLL Configuration for COFDM BW_MHz = 8.000000
325 * With external clock = 30.000000 */
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700326static struct dibx000_bandwidth_config xc3028_bw_config = {
Steven Toth66762372008-04-22 15:38:26 -0300327 60000, /* internal */
328 30000, /* sampling */
329 1, /* pll_cfg: prediv */
330 8, /* pll_cfg: ratio */
331 3, /* pll_cfg: range */
332 1, /* pll_cfg: reset */
333 0, /* pll_cfg: bypass */
334 0, /* misc: refdiv */
335 0, /* misc: bypclk_div */
336 1, /* misc: IO_CLK_en_core */
337 1, /* misc: ADClkSrc */
338 0, /* misc: modulo */
339 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
340 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
341 20452225, /* timf */
342 30000000 /* xtal_hz */
343};
344
345static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
346 .output_mpeg2_in_188_bytes = 1,
347 .hostbus_diversity = 1,
348 .tuner_is_baseband = 0,
349 .update_lna = NULL,
350
351 .agc_config_count = 1,
352 .agc = &xc3028_agc_config,
353 .bw = &xc3028_bw_config,
354
355 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
356 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
357 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
358
359 .pwm_freq_div = 0,
360 .agc_control = NULL,
361 .spur_protect = 0,
362
363 .output_mode = OUTMODE_MPEG2_SERIAL,
364};
365
Steven Tothaef2d182008-08-04 21:39:53 -0300366static struct zl10353_config dvico_fusionhdtv_xc3028 = {
367 .demod_address = 0x0f,
368 .if2 = 45600,
369 .no_tuner = 1,
Christopher Pascoed4dc6732009-04-27 11:27:04 -0300370 .disable_i2c_gate_ctrl = 1,
Steven Tothaef2d182008-08-04 21:39:53 -0300371};
372
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300373static struct stv0900_config netup_stv0900_config = {
374 .demod_address = 0x68,
375 .xtal = 27000000,
376 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
377 .diseqc_mode = 2,/* 2/3 PWM */
378 .path1_mode = 2,/*Serial continues clock */
379 .path2_mode = 2,/*Serial continues clock */
380 .tun1_maddress = 0,/* 0x60 */
381 .tun2_maddress = 3,/* 0x63 */
382 .tun1_adc = 1,/* 1 Vpp */
383 .tun2_adc = 1,/* 1 Vpp */
384};
385
386static struct stv6110_config netup_stv6110_tunerconfig_a = {
387 .i2c_address = 0x60,
388 .mclk = 27000000,
389 .iq_wiring = 0,
390};
391
392static struct stv6110_config netup_stv6110_tunerconfig_b = {
393 .i2c_address = 0x63,
394 .mclk = 27000000,
395 .iq_wiring = 1,
396};
397
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300398static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
399{
400 struct cx23885_tsport *port = fe->dvb->priv;
401 struct cx23885_dev *dev = port->dev;
402
403 if (voltage == SEC_VOLTAGE_18)
404 cx_write(MC417_RWD, 0x00001e00);/* GPIO-13 high */
405 else if (voltage == SEC_VOLTAGE_13)
406 cx_write(MC417_RWD, 0x00001a00);/* GPIO-13 low */
407 else
408 cx_write(MC417_RWD, 0x00001800);/* GPIO-12 low */
409 return 0;
410}
411
412static struct cx24116_config tbs_cx24116_config = {
413 .demod_address = 0x05,
414};
415
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300416static struct cx24116_config tevii_cx24116_config = {
417 .demod_address = 0x55,
418};
419
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300420static struct cx24116_config dvbworld_cx24116_config = {
421 .demod_address = 0x05,
422};
423
David Wong493b7122009-05-18 05:25:49 -0300424static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
425 .prod = LGS8GXX_PROD_LGS8GL5,
426 .demod_address = 0x19,
427 .serial_ts = 0,
428 .ts_clk_pol = 1,
429 .ts_clk_gated = 1,
430 .if_clk_freq = 30400, /* 30.4 MHz */
431 .if_freq = 5380, /* 5.38 MHz */
432 .if_neg_center = 1,
433 .ext_adc = 0,
434 .adc_signed = 0,
435 .if_neg_edge = 0,
436};
437
438static struct xc5000_config mygica_x8506_xc5000_config = {
439 .i2c_address = 0x61,
440 .if_khz = 5380,
441};
442
Steven Tothd19770e2007-03-11 20:44:05 -0300443static int dvb_register(struct cx23885_tsport *port)
444{
445 struct cx23885_dev *dev = port->dev;
David Wong493b7122009-05-18 05:25:49 -0300446 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
Steven Toth363c35f2008-10-11 11:05:50 -0300447 struct videobuf_dvb_frontend *fe0;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300448 int ret;
Steven Toth363c35f2008-10-11 11:05:50 -0300449
Darron Broadf972e0bd2008-10-11 11:24:30 -0300450 /* Get the first frontend */
Darron Broad92abe9e2008-10-11 11:18:53 -0300451 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth363c35f2008-10-11 11:05:50 -0300452 if (!fe0)
453 return -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300454
455 /* init struct videobuf_dvb */
Steven Toth363c35f2008-10-11 11:05:50 -0300456 fe0->dvb.name = dev->name;
Steven Tothd19770e2007-03-11 20:44:05 -0300457
458 /* init frontend */
459 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300460 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300461 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300462 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300463 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300464 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300465 if (fe0->dvb.frontend != NULL) {
466 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300467 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300468 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300469 }
470 break;
Michael Krufkya5dbf452009-05-03 23:27:02 -0300471 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Michael Krufkyd099bec2009-05-08 22:39:24 -0300472 case CX23885_BOARD_HAUPPAUGE_HVR1275:
Michael Krufkya5dbf452009-05-03 23:27:02 -0300473 i2c_bus = &dev->i2c_bus[0];
474 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
Michael Krufky247bc542009-05-12 18:53:47 -0300475 &hauppauge_lgdt3305_config,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300476 &i2c_bus->i2c_adap);
477 if (fe0->dvb.frontend != NULL) {
478 dvb_attach(tda18271_attach, fe0->dvb.frontend,
479 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufky247bc542009-05-12 18:53:47 -0300480 &hauppauge_hvr127x_config);
Michael Krufkya5dbf452009-05-03 23:27:02 -0300481 }
482 break;
Michael Krufky19bc5792009-05-08 16:05:29 -0300483 case CX23885_BOARD_HAUPPAUGE_HVR1255:
484 i2c_bus = &dev->i2c_bus[0];
485 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
486 &hcw_s5h1411_config,
487 &i2c_bus->i2c_adap);
488 if (fe0->dvb.frontend != NULL) {
489 dvb_attach(tda18271_attach, fe0->dvb.frontend,
490 0x60, &dev->i2c_bus[1].i2c_adap,
491 &hauppauge_tda18271_config);
492 }
493 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300494 case CX23885_BOARD_HAUPPAUGE_HVR1800:
495 i2c_bus = &dev->i2c_bus[0];
Darron Broad92abe9e2008-10-11 11:18:53 -0300496 switch (alt_tuner) {
Michael Krufky3ba71d22007-12-07 01:40:36 -0300497 case 1:
Steven Toth363c35f2008-10-11 11:05:50 -0300498 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300499 dvb_attach(s5h1409_attach,
500 &hauppauge_ezqam_config,
501 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300502 if (fe0->dvb.frontend != NULL) {
503 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300504 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300505 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300506 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300507 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300508 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300509 }
510 break;
511 case 0:
512 default:
Steven Toth363c35f2008-10-11 11:05:50 -0300513 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300514 dvb_attach(s5h1409_attach,
515 &hauppauge_generic_config,
516 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300517 if (fe0->dvb.frontend != NULL)
518 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300519 &i2c_bus->i2c_adap,
520 &hauppauge_generic_tunerconfig, 0);
521 break;
522 }
523 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300524 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300525 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300526 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothfc959be2007-09-08 19:08:17 -0300527 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300528 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300529 if (fe0->dvb.frontend != NULL) {
530 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300531 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300532 &hauppauge_generic_tunerconfig, 0);
533 }
534 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300535 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300536 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300537 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300538 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300539 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300540 if (fe0->dvb.frontend != NULL) {
541 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
Michael Krufky827855d2008-04-22 14:46:16 -0300542 &i2c_bus->i2c_adap, 0x61,
543 TUNER_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300544 }
545 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300546 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
547 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300548 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothd1987d52007-12-18 01:57:06 -0300549 &hauppauge_hvr1500q_config,
550 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300551 if (fe0->dvb.frontend != NULL)
552 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300553 &i2c_bus->i2c_adap,
554 &hauppauge_hvr1500q_tunerconfig);
Steven Tothd1987d52007-12-18 01:57:06 -0300555 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300556 case CX23885_BOARD_HAUPPAUGE_HVR1500:
557 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300558 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky07b4a832007-12-18 01:09:11 -0300559 &hauppauge_hvr1500_config,
560 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300561 if (fe0->dvb.frontend != NULL) {
Michael Krufky07b4a832007-12-18 01:09:11 -0300562 struct dvb_frontend *fe;
563 struct xc2028_config cfg = {
564 .i2c_adap = &i2c_bus->i2c_adap,
565 .i2c_addr = 0x61,
Michael Krufky07b4a832007-12-18 01:09:11 -0300566 };
567 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300568 .fname = XC2028_DEFAULT_FIRMWARE,
Michael Krufky07b4a832007-12-18 01:09:11 -0300569 .max_len = 64,
Steven Toth52c3d292009-04-20 22:42:00 -0300570 .demod = XC3028_FE_OREN538,
Michael Krufky07b4a832007-12-18 01:09:11 -0300571 };
572
573 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300574 fe0->dvb.frontend, &cfg);
Michael Krufky07b4a832007-12-18 01:09:11 -0300575 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
576 fe->ops.tuner_ops.set_config(fe, &ctl);
577 }
578 break;
Steven Tothb3ea0162008-04-19 01:14:19 -0300579 case CX23885_BOARD_HAUPPAUGE_HVR1200:
Steven Totha780a312008-04-19 01:25:52 -0300580 case CX23885_BOARD_HAUPPAUGE_HVR1700:
Steven Tothb3ea0162008-04-19 01:14:19 -0300581 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300582 fe0->dvb.frontend = dvb_attach(tda10048_attach,
Steven Tothb3ea0162008-04-19 01:14:19 -0300583 &hauppauge_hvr1200_config,
584 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300585 if (fe0->dvb.frontend != NULL) {
586 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300587 &dev->i2c_bus[1].i2c_adap, 0x42,
588 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300589 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300590 0x60, &dev->i2c_bus[1].i2c_adap,
591 &hauppauge_hvr1200_tuner_config);
592 }
593 break;
Michael Krufky6b926ec2009-05-12 17:32:17 -0300594 case CX23885_BOARD_HAUPPAUGE_HVR1210:
595 i2c_bus = &dev->i2c_bus[0];
596 fe0->dvb.frontend = dvb_attach(tda10048_attach,
597 &hauppauge_hvr1210_config,
598 &i2c_bus->i2c_adap);
599 if (fe0->dvb.frontend != NULL) {
600 dvb_attach(tda18271_attach, fe0->dvb.frontend,
601 0x60, &dev->i2c_bus[1].i2c_adap,
602 &hauppauge_hvr1210_tuner_config);
603 }
604 break;
Steven Toth66762372008-04-22 15:38:26 -0300605 case CX23885_BOARD_HAUPPAUGE_HVR1400:
606 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300607 fe0->dvb.frontend = dvb_attach(dib7000p_attach,
Steven Toth66762372008-04-22 15:38:26 -0300608 &i2c_bus->i2c_adap,
609 0x12, &hauppauge_hvr1400_dib7000_config);
Steven Toth363c35f2008-10-11 11:05:50 -0300610 if (fe0->dvb.frontend != NULL) {
Steven Toth66762372008-04-22 15:38:26 -0300611 struct dvb_frontend *fe;
612 struct xc2028_config cfg = {
613 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
614 .i2c_addr = 0x64,
Steven Toth66762372008-04-22 15:38:26 -0300615 };
616 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300617 .fname = XC3028L_DEFAULT_FIRMWARE,
Steven Toth66762372008-04-22 15:38:26 -0300618 .max_len = 64,
619 .demod = 5000,
Steven Toth9c8ced52008-10-16 20:18:44 -0300620 /* This is true for all demods with
621 v36 firmware? */
Mauro Carvalho Chehab0975fc62008-09-28 02:24:44 -0300622 .type = XC2028_D2633,
Steven Toth66762372008-04-22 15:38:26 -0300623 };
624
625 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300626 fe0->dvb.frontend, &cfg);
Steven Toth66762372008-04-22 15:38:26 -0300627 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
628 fe->ops.tuner_ops.set_config(fe, &ctl);
629 }
630 break;
Michael Krufky335377b2008-05-07 01:43:10 -0300631 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
632 i2c_bus = &dev->i2c_bus[port->nr - 1];
633
Steven Toth363c35f2008-10-11 11:05:50 -0300634 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky335377b2008-05-07 01:43:10 -0300635 &dvico_s5h1409_config,
636 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300637 if (fe0->dvb.frontend == NULL)
638 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
Michael Krufky52b50452008-07-09 02:18:49 -0300639 &dvico_s5h1411_config,
640 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300641 if (fe0->dvb.frontend != NULL)
642 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300643 &i2c_bus->i2c_adap,
644 &dvico_xc5000_tunerconfig);
Michael Krufky335377b2008-05-07 01:43:10 -0300645 break;
Steven Tothaef2d182008-08-04 21:39:53 -0300646 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
647 i2c_bus = &dev->i2c_bus[port->nr - 1];
648
Steven Toth363c35f2008-10-11 11:05:50 -0300649 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Tothaef2d182008-08-04 21:39:53 -0300650 &dvico_fusionhdtv_xc3028,
651 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300652 if (fe0->dvb.frontend != NULL) {
Steven Tothaef2d182008-08-04 21:39:53 -0300653 struct dvb_frontend *fe;
654 struct xc2028_config cfg = {
655 .i2c_adap = &i2c_bus->i2c_adap,
656 .i2c_addr = 0x61,
Steven Tothaef2d182008-08-04 21:39:53 -0300657 };
658 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300659 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Tothaef2d182008-08-04 21:39:53 -0300660 .max_len = 64,
661 .demod = XC3028_FE_ZARLINK456,
662 };
663
Steven Toth363c35f2008-10-11 11:05:50 -0300664 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Tothaef2d182008-08-04 21:39:53 -0300665 &cfg);
666 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
667 fe->ops.tuner_ops.set_config(fe, &ctl);
668 }
669 break;
670 }
Steven Toth4c56b042008-08-12 13:30:03 -0300671 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
Igor M. Liplianin9bb1b7e2008-11-23 14:11:16 -0300672 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
Steven Toth4c56b042008-08-12 13:30:03 -0300673 i2c_bus = &dev->i2c_bus[0];
674
Steven Toth363c35f2008-10-11 11:05:50 -0300675 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Toth4c56b042008-08-12 13:30:03 -0300676 &dvico_fusionhdtv_xc3028,
677 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300678 if (fe0->dvb.frontend != NULL) {
Steven Toth4c56b042008-08-12 13:30:03 -0300679 struct dvb_frontend *fe;
680 struct xc2028_config cfg = {
681 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
682 .i2c_addr = 0x61,
Steven Toth4c56b042008-08-12 13:30:03 -0300683 };
684 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300685 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Toth4c56b042008-08-12 13:30:03 -0300686 .max_len = 64,
687 .demod = XC3028_FE_ZARLINK456,
688 };
689
Steven Toth363c35f2008-10-11 11:05:50 -0300690 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Toth4c56b042008-08-12 13:30:03 -0300691 &cfg);
692 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
693 fe->ops.tuner_ops.set_config(fe, &ctl);
694 }
695 break;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300696 case CX23885_BOARD_TBS_6920:
697 i2c_bus = &dev->i2c_bus[0];
698
699 fe0->dvb.frontend = dvb_attach(cx24116_attach,
700 &tbs_cx24116_config,
701 &i2c_bus->i2c_adap);
702 if (fe0->dvb.frontend != NULL)
703 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
704
705 break;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300706 case CX23885_BOARD_TEVII_S470:
707 i2c_bus = &dev->i2c_bus[1];
708
709 fe0->dvb.frontend = dvb_attach(cx24116_attach,
710 &tevii_cx24116_config,
711 &i2c_bus->i2c_adap);
712 if (fe0->dvb.frontend != NULL)
713 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
714
715 break;
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300716 case CX23885_BOARD_DVBWORLD_2005:
717 i2c_bus = &dev->i2c_bus[1];
718
719 fe0->dvb.frontend = dvb_attach(cx24116_attach,
720 &dvbworld_cx24116_config,
721 &i2c_bus->i2c_adap);
722 break;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300723 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
724 i2c_bus = &dev->i2c_bus[0];
725 switch (port->nr) {
726 /* port B */
727 case 1:
728 fe0->dvb.frontend = dvb_attach(stv0900_attach,
729 &netup_stv0900_config,
730 &i2c_bus->i2c_adap, 0);
731 if (fe0->dvb.frontend != NULL) {
732 if (dvb_attach(stv6110_attach,
733 fe0->dvb.frontend,
734 &netup_stv6110_tunerconfig_a,
735 &i2c_bus->i2c_adap)) {
736 if (!dvb_attach(lnbh24_attach,
737 fe0->dvb.frontend,
738 &i2c_bus->i2c_adap,
739 LNBH24_PCL, 0, 0x09))
740 printk(KERN_ERR
741 "No LNBH24 found!\n");
742
743 }
744 }
745 break;
746 /* port C */
747 case 2:
748 fe0->dvb.frontend = dvb_attach(stv0900_attach,
749 &netup_stv0900_config,
750 &i2c_bus->i2c_adap, 1);
751 if (fe0->dvb.frontend != NULL) {
752 if (dvb_attach(stv6110_attach,
753 fe0->dvb.frontend,
754 &netup_stv6110_tunerconfig_b,
755 &i2c_bus->i2c_adap)) {
756 if (!dvb_attach(lnbh24_attach,
757 fe0->dvb.frontend,
758 &i2c_bus->i2c_adap,
759 LNBH24_PCL, 0, 0x0a))
760 printk(KERN_ERR
761 "No LNBH24 found!\n");
762
763 }
764 }
765 break;
766 }
767 break;
David Wong493b7122009-05-18 05:25:49 -0300768 case CX23885_BOARD_MYGICA_X8506:
769 i2c_bus = &dev->i2c_bus[0];
770 i2c_bus2 = &dev->i2c_bus[1];
771 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
772 &mygica_x8506_lgs8gl5_config,
773 &i2c_bus->i2c_adap);
774 if (fe0->dvb.frontend != NULL) {
775 dvb_attach(xc5000_attach,
776 fe0->dvb.frontend,
777 &i2c_bus2->i2c_adap,
778 &mygica_x8506_xc5000_config);
779 }
780 break;
Steven Tothd19770e2007-03-11 20:44:05 -0300781 default:
Steven Toth9c8ced52008-10-16 20:18:44 -0300782 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
783 " isn't supported yet\n",
Steven Tothd19770e2007-03-11 20:44:05 -0300784 dev->name);
785 break;
786 }
Steven Toth363c35f2008-10-11 11:05:50 -0300787 if (NULL == fe0->dvb.frontend) {
Steven Toth9c8ced52008-10-16 20:18:44 -0300788 printk(KERN_ERR "%s: frontend initialization failed\n",
789 dev->name);
Steven Tothd19770e2007-03-11 20:44:05 -0300790 return -1;
791 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300792 /* define general-purpose callback pointer */
Steven Toth363c35f2008-10-11 11:05:50 -0300793 fe0->dvb.frontend->callback = cx23885_tuner_callback;
Steven Tothd19770e2007-03-11 20:44:05 -0300794
795 /* Put the analog decoder in standby to keep it quiet */
Hans Verkuil7c9fc9d2009-04-01 03:49:59 -0300796 call_all(dev, tuner, s_standby);
Steven Tothd19770e2007-03-11 20:44:05 -0300797
Steven Toth363c35f2008-10-11 11:05:50 -0300798 if (fe0->dvb.frontend->ops.analog_ops.standby)
799 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300800
Steven Tothd19770e2007-03-11 20:44:05 -0300801 /* register everything */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300802 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
Darron Broad59b18422008-10-11 11:44:05 -0300803 &dev->pci->dev, adapter_nr, 0);
Steven Toth363c35f2008-10-11 11:05:50 -0300804
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300805 /* init CI & MAC */
806 switch (dev->board) {
807 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
808 static struct netup_card_info cinfo;
809
810 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
811 memcpy(port->frontends.adapter.proposed_mac,
812 cinfo.port[port->nr - 1].mac, 6);
813 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
814 "%02X:%02X:%02X:%02X:%02X:%02X\n",
815 port->nr,
816 port->frontends.adapter.proposed_mac[0],
817 port->frontends.adapter.proposed_mac[1],
818 port->frontends.adapter.proposed_mac[2],
819 port->frontends.adapter.proposed_mac[3],
820 port->frontends.adapter.proposed_mac[4],
821 port->frontends.adapter.proposed_mac[5]);
822
823 netup_ci_init(port);
824 break;
825 }
826 }
827
828 return ret;
Steven Tothd19770e2007-03-11 20:44:05 -0300829}
830
831int cx23885_dvb_register(struct cx23885_tsport *port)
832{
Steven Toth363c35f2008-10-11 11:05:50 -0300833
834 struct videobuf_dvb_frontend *fe0;
Steven Tothd19770e2007-03-11 20:44:05 -0300835 struct cx23885_dev *dev = port->dev;
Steven Totheb0c58b2008-10-11 12:34:39 -0300836 int err, i;
Steven Tothd19770e2007-03-11 20:44:05 -0300837
Steven Totheb0c58b2008-10-11 12:34:39 -0300838 /* Here we need to allocate the correct number of frontends,
839 * as reflected in the cards struct. The reality is that currrently
840 * no cx23885 boards support this - yet. But, if we don't modify this
841 * code then the second frontend would never be allocated (later)
842 * and fail with error before the attach in dvb_register().
843 * Without these changes we risk an OOPS later. The changes here
844 * are for safety, and should provide a good foundation for the
845 * future addition of any multi-frontend cx23885 based boards.
846 */
847 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
848 port->num_frontends);
Steven Toth363c35f2008-10-11 11:05:50 -0300849
Steven Totheb0c58b2008-10-11 12:34:39 -0300850 for (i = 1; i <= port->num_frontends; i++) {
Darron Broad96b7a1a2008-10-15 20:26:34 -0300851 if (videobuf_dvb_alloc_frontend(
Steven Toth9c8ced52008-10-16 20:18:44 -0300852 &port->frontends, i) == NULL) {
Steven Totheb0c58b2008-10-11 12:34:39 -0300853 printk(KERN_ERR "%s() failed to alloc\n", __func__);
854 return -ENOMEM;
855 }
Steven Tothd19770e2007-03-11 20:44:05 -0300856
Steven Totheb0c58b2008-10-11 12:34:39 -0300857 fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
858 if (!fe0)
859 err = -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300860
Steven Totheb0c58b2008-10-11 12:34:39 -0300861 dprintk(1, "%s\n", __func__);
Steven Toth9c8ced52008-10-16 20:18:44 -0300862 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Totheb0c58b2008-10-11 12:34:39 -0300863 dev->board,
864 dev->name,
865 dev->pci_bus,
866 dev->pci_slot);
867
868 err = -ENODEV;
869
870 /* dvb stuff */
871 /* We have to init the queue for each frontend on a port. */
Steven Toth9c8ced52008-10-16 20:18:44 -0300872 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
873 videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
874 &dev->pci->dev, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -0300875 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
876 sizeof(struct cx23885_buffer), port);
Steven Totheb0c58b2008-10-11 12:34:39 -0300877 }
Steven Tothd19770e2007-03-11 20:44:05 -0300878 err = dvb_register(port);
879 if (err != 0)
Steven Toth9c8ced52008-10-16 20:18:44 -0300880 printk(KERN_ERR "%s() dvb_register failed err = %d\n",
881 __func__, err);
Steven Tothd19770e2007-03-11 20:44:05 -0300882
Steven Tothd19770e2007-03-11 20:44:05 -0300883 return err;
884}
885
886int cx23885_dvb_unregister(struct cx23885_tsport *port)
887{
Steven Toth363c35f2008-10-11 11:05:50 -0300888 struct videobuf_dvb_frontend *fe0;
889
Steven Totheb0c58b2008-10-11 12:34:39 -0300890 /* FIXME: in an error condition where the we have
891 * an expected number of frontends (attach problem)
892 * then this might not clean up correctly, if 1
893 * is invalid.
894 * This comment only applies to future boards IF they
895 * implement MFE support.
896 */
Darron Broad92abe9e2008-10-11 11:18:53 -0300897 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth9c8ced52008-10-16 20:18:44 -0300898 if (fe0->dvb.frontend)
Steven Toth363c35f2008-10-11 11:05:50 -0300899 videobuf_dvb_unregister_bus(&port->frontends);
Steven Tothd19770e2007-03-11 20:44:05 -0300900
Hans Verkuilafd96662009-03-13 13:24:19 -0300901 switch (port->dev->board) {
902 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
903 netup_ci_exit(port);
904 break;
905 }
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300906
Steven Tothd19770e2007-03-11 20:44:05 -0300907 return 0;
908}
Michael Krufky44a64812007-03-20 23:00:18 -0300909