blob: 45784a384300f74ea1832f80fbc599917e040568 [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"
52#include "netup-eeprom.h"
53#include "netup-init.h"
Michael Krufkya5dbf452009-05-03 23:27:02 -030054#include "lgdt3305.h"
Steven Tothd19770e2007-03-11 20:44:05 -030055
Steven Toth4513fc692008-01-12 11:36:36 -030056static unsigned int debug;
Steven Tothd19770e2007-03-11 20:44:05 -030057
Steven Toth4513fc692008-01-12 11:36:36 -030058#define dprintk(level, fmt, arg...)\
59 do { if (debug >= level)\
60 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
61 } while (0)
Steven Tothd19770e2007-03-11 20:44:05 -030062
63/* ------------------------------------------------------------------ */
64
Michael Krufky3ba71d22007-12-07 01:40:36 -030065static unsigned int alt_tuner;
66module_param(alt_tuner, int, 0644);
67MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
68
Janne Grunau78e92002008-04-09 19:13:13 -030069DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
70
Michael Krufky3ba71d22007-12-07 01:40:36 -030071/* ------------------------------------------------------------------ */
72
Steven Tothd19770e2007-03-11 20:44:05 -030073static int dvb_buf_setup(struct videobuf_queue *q,
74 unsigned int *count, unsigned int *size)
75{
76 struct cx23885_tsport *port = q->priv_data;
77
78 port->ts_packet_size = 188 * 4;
79 port->ts_packet_count = 32;
80
81 *size = port->ts_packet_size * port->ts_packet_count;
82 *count = 32;
83 return 0;
84}
85
Michael Krufky44a64812007-03-20 23:00:18 -030086static int dvb_buf_prepare(struct videobuf_queue *q,
87 struct videobuf_buffer *vb, enum v4l2_field field)
Steven Tothd19770e2007-03-11 20:44:05 -030088{
89 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030090 return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
Steven Tothd19770e2007-03-11 20:44:05 -030091}
92
93static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
94{
95 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030096 cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -030097}
98
Michael Krufky44a64812007-03-20 23:00:18 -030099static void dvb_buf_release(struct videobuf_queue *q,
100 struct videobuf_buffer *vb)
Steven Tothd19770e2007-03-11 20:44:05 -0300101{
Steven Toth9c8ced52008-10-16 20:18:44 -0300102 cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300103}
104
105static struct videobuf_queue_ops dvb_qops = {
106 .buf_setup = dvb_buf_setup,
107 .buf_prepare = dvb_buf_prepare,
108 .buf_queue = dvb_buf_queue,
109 .buf_release = dvb_buf_release,
110};
111
Steven Toth86184e02007-09-04 21:40:47 -0300112static struct s5h1409_config hauppauge_generic_config = {
Steven Tothd19770e2007-03-11 20:44:05 -0300113 .demod_address = 0x32 >> 1,
114 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothfc959be2007-09-08 19:08:17 -0300115 .gpio = S5H1409_GPIO_ON,
Michael Krufky2b032382007-12-13 10:04:10 -0300116 .qam_if = 44000,
Steven Tothfc959be2007-09-08 19:08:17 -0300117 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300118 .status_mode = S5H1409_DEMODLOCKING,
119 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothfc959be2007-09-08 19:08:17 -0300120};
121
Steven Tothb3ea0162008-04-19 01:14:19 -0300122static struct tda10048_config hauppauge_hvr1200_config = {
123 .demod_address = 0x10 >> 1,
124 .output_mode = TDA10048_SERIAL_OUTPUT,
125 .fwbulkwritelen = TDA10048_BULKWRITE_200,
Steven Toth484d9e02009-05-02 11:08:23 -0300126 .inversion = TDA10048_INVERSION_ON,
Steven Toth8816bef2009-05-15 21:04:18 -0300127 .dtv6_if_freq_khz = TDA10048_IF_3300,
128 .dtv7_if_freq_khz = TDA10048_IF_3800,
129 .dtv8_if_freq_khz = TDA10048_IF_4300,
Steven Toth484d9e02009-05-02 11:08:23 -0300130 .clk_freq_khz = TDA10048_CLK_16000,
Steven Tothb3ea0162008-04-19 01:14:19 -0300131};
132
Michael Krufky6b926ec2009-05-12 17:32:17 -0300133static struct tda10048_config hauppauge_hvr1210_config = {
134 .demod_address = 0x10 >> 1,
135 .output_mode = TDA10048_SERIAL_OUTPUT,
136 .fwbulkwritelen = TDA10048_BULKWRITE_200,
137 .inversion = TDA10048_INVERSION_ON,
Michael Krufkyc27586e2009-05-16 11:00:23 -0300138 .dtv6_if_freq_khz = TDA10048_IF_3300,
139 .dtv7_if_freq_khz = TDA10048_IF_3500,
140 .dtv8_if_freq_khz = TDA10048_IF_4000,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300141 .clk_freq_khz = TDA10048_CLK_16000,
142};
143
Michael Krufky3ba71d22007-12-07 01:40:36 -0300144static struct s5h1409_config hauppauge_ezqam_config = {
145 .demod_address = 0x32 >> 1,
146 .output_mode = S5H1409_SERIAL_OUTPUT,
147 .gpio = S5H1409_GPIO_OFF,
148 .qam_if = 4000,
149 .inversion = S5H1409_INVERSION_ON,
Steven Tothdfc1c082008-01-15 21:35:22 -0300150 .status_mode = S5H1409_DEMODLOCKING,
151 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300152};
153
Steven Tothfc959be2007-09-08 19:08:17 -0300154static struct s5h1409_config hauppauge_hvr1800lp_config = {
155 .demod_address = 0x32 >> 1,
156 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300157 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300158 .qam_if = 44000,
Steven Tothfe475162007-03-20 15:27:53 -0300159 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300160 .status_mode = S5H1409_DEMODLOCKING,
161 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd19770e2007-03-11 20:44:05 -0300162};
163
Michael Krufky07b4a832007-12-18 01:09:11 -0300164static struct s5h1409_config hauppauge_hvr1500_config = {
165 .demod_address = 0x32 >> 1,
166 .output_mode = S5H1409_SERIAL_OUTPUT,
167 .gpio = S5H1409_GPIO_OFF,
168 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300169 .status_mode = S5H1409_DEMODLOCKING,
170 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky07b4a832007-12-18 01:09:11 -0300171};
172
Steven Toth86184e02007-09-04 21:40:47 -0300173static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300174 0x61
175};
176
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300177static struct lgdt330x_config fusionhdtv_5_express = {
178 .demod_address = 0x0e,
179 .demod_chip = LGDT3303,
180 .serial_mpeg = 0x40,
181};
182
Steven Tothd1987d52007-12-18 01:57:06 -0300183static struct s5h1409_config hauppauge_hvr1500q_config = {
184 .demod_address = 0x32 >> 1,
185 .output_mode = S5H1409_SERIAL_OUTPUT,
186 .gpio = S5H1409_GPIO_ON,
187 .qam_if = 44000,
188 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300189 .status_mode = S5H1409_DEMODLOCKING,
190 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd1987d52007-12-18 01:57:06 -0300191};
192
Michael Krufky335377b2008-05-07 01:43:10 -0300193static struct s5h1409_config dvico_s5h1409_config = {
194 .demod_address = 0x32 >> 1,
195 .output_mode = S5H1409_SERIAL_OUTPUT,
196 .gpio = S5H1409_GPIO_ON,
197 .qam_if = 44000,
198 .inversion = S5H1409_INVERSION_OFF,
199 .status_mode = S5H1409_DEMODLOCKING,
200 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
201};
202
Michael Krufky52b50452008-07-09 02:18:49 -0300203static struct s5h1411_config dvico_s5h1411_config = {
204 .output_mode = S5H1411_SERIAL_OUTPUT,
205 .gpio = S5H1411_GPIO_ON,
206 .qam_if = S5H1411_IF_44000,
207 .vsb_if = S5H1411_IF_44000,
208 .inversion = S5H1411_INVERSION_OFF,
209 .status_mode = S5H1411_DEMODLOCKING,
210 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
211};
212
Michael Krufky19bc5792009-05-08 16:05:29 -0300213static struct s5h1411_config hcw_s5h1411_config = {
214 .output_mode = S5H1411_SERIAL_OUTPUT,
215 .gpio = S5H1411_GPIO_OFF,
216 .vsb_if = S5H1411_IF_44000,
217 .qam_if = S5H1411_IF_4000,
218 .inversion = S5H1411_INVERSION_ON,
219 .status_mode = S5H1411_DEMODLOCKING,
220 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
221};
222
Steven Tothd1987d52007-12-18 01:57:06 -0300223static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671c2007-12-20 01:14:43 -0300224 .i2c_address = 0x61,
225 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300226};
227
Michael Krufky335377b2008-05-07 01:43:10 -0300228static struct xc5000_config dvico_xc5000_tunerconfig = {
229 .i2c_address = 0x64,
230 .if_khz = 5380,
Michael Krufky335377b2008-05-07 01:43:10 -0300231};
232
Michael Krufky4041f1a2007-12-24 04:52:08 -0300233static struct tda829x_config tda829x_no_probe = {
234 .probe_tuner = TDA829X_DONT_PROBE,
235};
236
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300237static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufkyc0dc0c12008-04-22 14:46:22 -0300238 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
239 .if_lvl = 6, .rfagc_top = 0x37 },
240 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
241 .if_lvl = 6, .rfagc_top = 0x37 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300242};
243
244static struct tda18271_config hauppauge_tda18271_config = {
245 .std_map = &hauppauge_tda18271_std_map,
246 .gate = TDA18271_GATE_ANALOG,
247};
248
Steven Tothb3ea0162008-04-19 01:14:19 -0300249static struct tda18271_config hauppauge_hvr1200_tuner_config = {
250 .gate = TDA18271_GATE_ANALOG,
251};
252
Michael Krufky6b926ec2009-05-12 17:32:17 -0300253static struct tda18271_config hauppauge_hvr1210_tuner_config = {
254 .gate = TDA18271_GATE_DIGITAL,
255};
256
Michael Krufky247bc542009-05-12 18:53:47 -0300257static struct tda18271_std_map hauppauge_hvr127x_std_map = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300258 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
259 .if_lvl = 1, .rfagc_top = 0x58 },
260 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
261 .if_lvl = 1, .rfagc_top = 0x58 },
262};
263
Michael Krufky247bc542009-05-12 18:53:47 -0300264static struct tda18271_config hauppauge_hvr127x_config = {
265 .std_map = &hauppauge_hvr127x_std_map,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300266};
267
Michael Krufky247bc542009-05-12 18:53:47 -0300268static struct lgdt3305_config hauppauge_lgdt3305_config = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300269 .i2c_addr = 0x0e,
270 .mpeg_mode = LGDT3305_MPEG_SERIAL,
271 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
272 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
273 .deny_i2c_rptr = 1,
274 .spectral_inversion = 1,
275 .qam_if_khz = 4000,
276 .vsb_if_khz = 3250,
277};
278
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700279static struct dibx000_agc_config xc3028_agc_config = {
Steven Toth66762372008-04-22 15:38:26 -0300280 BAND_VHF | BAND_UHF, /* band_caps */
281
282 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
283 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
284 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
285 * P_agc_nb_est=2, P_agc_write=0
286 */
287 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
288 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
289
290 712, /* inv_gain */
291 21, /* time_stabiliz */
292
293 0, /* alpha_level */
294 118, /* thlock */
295
296 0, /* wbd_inv */
297 2867, /* wbd_ref */
298 0, /* wbd_sel */
299 2, /* wbd_alpha */
300
301 0, /* agc1_max */
302 0, /* agc1_min */
303 39718, /* agc2_max */
304 9930, /* agc2_min */
305 0, /* agc1_pt1 */
306 0, /* agc1_pt2 */
307 0, /* agc1_pt3 */
308 0, /* agc1_slope1 */
309 0, /* agc1_slope2 */
310 0, /* agc2_pt1 */
311 128, /* agc2_pt2 */
312 29, /* agc2_slope1 */
313 29, /* agc2_slope2 */
314
315 17, /* alpha_mant */
316 27, /* alpha_exp */
317 23, /* beta_mant */
318 51, /* beta_exp */
319
320 1, /* perform_agc_softsplit */
321};
322
323/* PLL Configuration for COFDM BW_MHz = 8.000000
324 * With external clock = 30.000000 */
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700325static struct dibx000_bandwidth_config xc3028_bw_config = {
Steven Toth66762372008-04-22 15:38:26 -0300326 60000, /* internal */
327 30000, /* sampling */
328 1, /* pll_cfg: prediv */
329 8, /* pll_cfg: ratio */
330 3, /* pll_cfg: range */
331 1, /* pll_cfg: reset */
332 0, /* pll_cfg: bypass */
333 0, /* misc: refdiv */
334 0, /* misc: bypclk_div */
335 1, /* misc: IO_CLK_en_core */
336 1, /* misc: ADClkSrc */
337 0, /* misc: modulo */
338 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
339 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
340 20452225, /* timf */
341 30000000 /* xtal_hz */
342};
343
344static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
345 .output_mpeg2_in_188_bytes = 1,
346 .hostbus_diversity = 1,
347 .tuner_is_baseband = 0,
348 .update_lna = NULL,
349
350 .agc_config_count = 1,
351 .agc = &xc3028_agc_config,
352 .bw = &xc3028_bw_config,
353
354 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
355 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
356 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
357
358 .pwm_freq_div = 0,
359 .agc_control = NULL,
360 .spur_protect = 0,
361
362 .output_mode = OUTMODE_MPEG2_SERIAL,
363};
364
Steven Tothaef2d182008-08-04 21:39:53 -0300365static struct zl10353_config dvico_fusionhdtv_xc3028 = {
366 .demod_address = 0x0f,
367 .if2 = 45600,
368 .no_tuner = 1,
Christopher Pascoed4dc6732009-04-27 11:27:04 -0300369 .disable_i2c_gate_ctrl = 1,
Steven Tothaef2d182008-08-04 21:39:53 -0300370};
371
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300372static struct stv0900_config netup_stv0900_config = {
373 .demod_address = 0x68,
374 .xtal = 27000000,
375 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
376 .diseqc_mode = 2,/* 2/3 PWM */
377 .path1_mode = 2,/*Serial continues clock */
378 .path2_mode = 2,/*Serial continues clock */
379 .tun1_maddress = 0,/* 0x60 */
380 .tun2_maddress = 3,/* 0x63 */
381 .tun1_adc = 1,/* 1 Vpp */
382 .tun2_adc = 1,/* 1 Vpp */
383};
384
385static struct stv6110_config netup_stv6110_tunerconfig_a = {
386 .i2c_address = 0x60,
387 .mclk = 27000000,
388 .iq_wiring = 0,
389};
390
391static struct stv6110_config netup_stv6110_tunerconfig_b = {
392 .i2c_address = 0x63,
393 .mclk = 27000000,
394 .iq_wiring = 1,
395};
396
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300397static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
398{
399 struct cx23885_tsport *port = fe->dvb->priv;
400 struct cx23885_dev *dev = port->dev;
401
402 if (voltage == SEC_VOLTAGE_18)
403 cx_write(MC417_RWD, 0x00001e00);/* GPIO-13 high */
404 else if (voltage == SEC_VOLTAGE_13)
405 cx_write(MC417_RWD, 0x00001a00);/* GPIO-13 low */
406 else
407 cx_write(MC417_RWD, 0x00001800);/* GPIO-12 low */
408 return 0;
409}
410
411static struct cx24116_config tbs_cx24116_config = {
412 .demod_address = 0x05,
413};
414
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300415static struct cx24116_config tevii_cx24116_config = {
416 .demod_address = 0x55,
417};
418
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300419static struct cx24116_config dvbworld_cx24116_config = {
420 .demod_address = 0x05,
421};
422
Steven Tothd19770e2007-03-11 20:44:05 -0300423static int dvb_register(struct cx23885_tsport *port)
424{
425 struct cx23885_dev *dev = port->dev;
Michael Krufkyf139fa72007-09-09 03:55:34 -0300426 struct cx23885_i2c *i2c_bus = NULL;
Steven Toth363c35f2008-10-11 11:05:50 -0300427 struct videobuf_dvb_frontend *fe0;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300428 int ret;
Steven Toth363c35f2008-10-11 11:05:50 -0300429
Darron Broadf972e0b2008-10-11 11:24:30 -0300430 /* Get the first frontend */
Darron Broad92abe9e2008-10-11 11:18:53 -0300431 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth363c35f2008-10-11 11:05:50 -0300432 if (!fe0)
433 return -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300434
435 /* init struct videobuf_dvb */
Steven Toth363c35f2008-10-11 11:05:50 -0300436 fe0->dvb.name = dev->name;
Steven Tothd19770e2007-03-11 20:44:05 -0300437
438 /* init frontend */
439 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300440 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300441 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300442 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300443 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300444 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300445 if (fe0->dvb.frontend != NULL) {
446 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300447 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300448 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300449 }
450 break;
Michael Krufkya5dbf452009-05-03 23:27:02 -0300451 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Michael Krufkyd099bec2009-05-08 22:39:24 -0300452 case CX23885_BOARD_HAUPPAUGE_HVR1275:
Michael Krufkya5dbf452009-05-03 23:27:02 -0300453 i2c_bus = &dev->i2c_bus[0];
454 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
Michael Krufky247bc542009-05-12 18:53:47 -0300455 &hauppauge_lgdt3305_config,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300456 &i2c_bus->i2c_adap);
457 if (fe0->dvb.frontend != NULL) {
458 dvb_attach(tda18271_attach, fe0->dvb.frontend,
459 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufky247bc542009-05-12 18:53:47 -0300460 &hauppauge_hvr127x_config);
Michael Krufkya5dbf452009-05-03 23:27:02 -0300461 }
462 break;
Michael Krufky19bc5792009-05-08 16:05:29 -0300463 case CX23885_BOARD_HAUPPAUGE_HVR1255:
464 i2c_bus = &dev->i2c_bus[0];
465 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
466 &hcw_s5h1411_config,
467 &i2c_bus->i2c_adap);
468 if (fe0->dvb.frontend != NULL) {
469 dvb_attach(tda18271_attach, fe0->dvb.frontend,
470 0x60, &dev->i2c_bus[1].i2c_adap,
471 &hauppauge_tda18271_config);
472 }
473 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300474 case CX23885_BOARD_HAUPPAUGE_HVR1800:
475 i2c_bus = &dev->i2c_bus[0];
Darron Broad92abe9e2008-10-11 11:18:53 -0300476 switch (alt_tuner) {
Michael Krufky3ba71d22007-12-07 01:40:36 -0300477 case 1:
Steven Toth363c35f2008-10-11 11:05:50 -0300478 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300479 dvb_attach(s5h1409_attach,
480 &hauppauge_ezqam_config,
481 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300482 if (fe0->dvb.frontend != NULL) {
483 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300484 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300485 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300486 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300487 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300488 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300489 }
490 break;
491 case 0:
492 default:
Steven Toth363c35f2008-10-11 11:05:50 -0300493 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300494 dvb_attach(s5h1409_attach,
495 &hauppauge_generic_config,
496 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300497 if (fe0->dvb.frontend != NULL)
498 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300499 &i2c_bus->i2c_adap,
500 &hauppauge_generic_tunerconfig, 0);
501 break;
502 }
503 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300504 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300505 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300506 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothfc959be2007-09-08 19:08:17 -0300507 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300508 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300509 if (fe0->dvb.frontend != NULL) {
510 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300511 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300512 &hauppauge_generic_tunerconfig, 0);
513 }
514 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300515 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300516 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300517 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300518 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300519 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300520 if (fe0->dvb.frontend != NULL) {
521 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
Michael Krufky827855d2008-04-22 14:46:16 -0300522 &i2c_bus->i2c_adap, 0x61,
523 TUNER_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300524 }
525 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300526 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
527 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300528 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothd1987d52007-12-18 01:57:06 -0300529 &hauppauge_hvr1500q_config,
530 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300531 if (fe0->dvb.frontend != NULL)
532 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300533 &i2c_bus->i2c_adap,
534 &hauppauge_hvr1500q_tunerconfig);
Steven Tothd1987d52007-12-18 01:57:06 -0300535 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300536 case CX23885_BOARD_HAUPPAUGE_HVR1500:
537 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300538 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky07b4a832007-12-18 01:09:11 -0300539 &hauppauge_hvr1500_config,
540 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300541 if (fe0->dvb.frontend != NULL) {
Michael Krufky07b4a832007-12-18 01:09:11 -0300542 struct dvb_frontend *fe;
543 struct xc2028_config cfg = {
544 .i2c_adap = &i2c_bus->i2c_adap,
545 .i2c_addr = 0x61,
Michael Krufky07b4a832007-12-18 01:09:11 -0300546 };
547 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfe2008-09-16 02:15:30 -0300548 .fname = XC2028_DEFAULT_FIRMWARE,
Michael Krufky07b4a832007-12-18 01:09:11 -0300549 .max_len = 64,
Steven Toth52c3d292009-04-20 22:42:00 -0300550 .demod = XC3028_FE_OREN538,
Michael Krufky07b4a832007-12-18 01:09:11 -0300551 };
552
553 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300554 fe0->dvb.frontend, &cfg);
Michael Krufky07b4a832007-12-18 01:09:11 -0300555 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
556 fe->ops.tuner_ops.set_config(fe, &ctl);
557 }
558 break;
Steven Tothb3ea0162008-04-19 01:14:19 -0300559 case CX23885_BOARD_HAUPPAUGE_HVR1200:
Steven Totha780a312008-04-19 01:25:52 -0300560 case CX23885_BOARD_HAUPPAUGE_HVR1700:
Steven Tothb3ea0162008-04-19 01:14:19 -0300561 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300562 fe0->dvb.frontend = dvb_attach(tda10048_attach,
Steven Tothb3ea0162008-04-19 01:14:19 -0300563 &hauppauge_hvr1200_config,
564 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300565 if (fe0->dvb.frontend != NULL) {
566 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300567 &dev->i2c_bus[1].i2c_adap, 0x42,
568 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300569 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300570 0x60, &dev->i2c_bus[1].i2c_adap,
571 &hauppauge_hvr1200_tuner_config);
572 }
573 break;
Michael Krufky6b926ec2009-05-12 17:32:17 -0300574 case CX23885_BOARD_HAUPPAUGE_HVR1210:
575 i2c_bus = &dev->i2c_bus[0];
576 fe0->dvb.frontend = dvb_attach(tda10048_attach,
577 &hauppauge_hvr1210_config,
578 &i2c_bus->i2c_adap);
579 if (fe0->dvb.frontend != NULL) {
580 dvb_attach(tda18271_attach, fe0->dvb.frontend,
581 0x60, &dev->i2c_bus[1].i2c_adap,
582 &hauppauge_hvr1210_tuner_config);
583 }
584 break;
Steven Toth66762372008-04-22 15:38:26 -0300585 case CX23885_BOARD_HAUPPAUGE_HVR1400:
586 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300587 fe0->dvb.frontend = dvb_attach(dib7000p_attach,
Steven Toth66762372008-04-22 15:38:26 -0300588 &i2c_bus->i2c_adap,
589 0x12, &hauppauge_hvr1400_dib7000_config);
Steven Toth363c35f2008-10-11 11:05:50 -0300590 if (fe0->dvb.frontend != NULL) {
Steven Toth66762372008-04-22 15:38:26 -0300591 struct dvb_frontend *fe;
592 struct xc2028_config cfg = {
593 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
594 .i2c_addr = 0x64,
Steven Toth66762372008-04-22 15:38:26 -0300595 };
596 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfe2008-09-16 02:15:30 -0300597 .fname = XC3028L_DEFAULT_FIRMWARE,
Steven Toth66762372008-04-22 15:38:26 -0300598 .max_len = 64,
599 .demod = 5000,
Steven Toth9c8ced52008-10-16 20:18:44 -0300600 /* This is true for all demods with
601 v36 firmware? */
Mauro Carvalho Chehab0975fc62008-09-28 02:24:44 -0300602 .type = XC2028_D2633,
Steven Toth66762372008-04-22 15:38:26 -0300603 };
604
605 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300606 fe0->dvb.frontend, &cfg);
Steven Toth66762372008-04-22 15:38:26 -0300607 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
608 fe->ops.tuner_ops.set_config(fe, &ctl);
609 }
610 break;
Michael Krufky335377b2008-05-07 01:43:10 -0300611 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
612 i2c_bus = &dev->i2c_bus[port->nr - 1];
613
Steven Toth363c35f2008-10-11 11:05:50 -0300614 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky335377b2008-05-07 01:43:10 -0300615 &dvico_s5h1409_config,
616 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300617 if (fe0->dvb.frontend == NULL)
618 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
Michael Krufky52b50452008-07-09 02:18:49 -0300619 &dvico_s5h1411_config,
620 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300621 if (fe0->dvb.frontend != NULL)
622 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300623 &i2c_bus->i2c_adap,
624 &dvico_xc5000_tunerconfig);
Michael Krufky335377b2008-05-07 01:43:10 -0300625 break;
Steven Tothaef2d182008-08-04 21:39:53 -0300626 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
627 i2c_bus = &dev->i2c_bus[port->nr - 1];
628
Steven Toth363c35f2008-10-11 11:05:50 -0300629 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Tothaef2d182008-08-04 21:39:53 -0300630 &dvico_fusionhdtv_xc3028,
631 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300632 if (fe0->dvb.frontend != NULL) {
Steven Tothaef2d182008-08-04 21:39:53 -0300633 struct dvb_frontend *fe;
634 struct xc2028_config cfg = {
635 .i2c_adap = &i2c_bus->i2c_adap,
636 .i2c_addr = 0x61,
Steven Tothaef2d182008-08-04 21:39:53 -0300637 };
638 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfe2008-09-16 02:15:30 -0300639 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Tothaef2d182008-08-04 21:39:53 -0300640 .max_len = 64,
641 .demod = XC3028_FE_ZARLINK456,
642 };
643
Steven Toth363c35f2008-10-11 11:05:50 -0300644 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Tothaef2d182008-08-04 21:39:53 -0300645 &cfg);
646 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
647 fe->ops.tuner_ops.set_config(fe, &ctl);
648 }
649 break;
650 }
Steven Toth4c56b042008-08-12 13:30:03 -0300651 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
Igor M. Liplianin9bb1b7e2008-11-23 14:11:16 -0300652 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
Steven Toth4c56b042008-08-12 13:30:03 -0300653 i2c_bus = &dev->i2c_bus[0];
654
Steven Toth363c35f2008-10-11 11:05:50 -0300655 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Toth4c56b042008-08-12 13:30:03 -0300656 &dvico_fusionhdtv_xc3028,
657 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300658 if (fe0->dvb.frontend != NULL) {
Steven Toth4c56b042008-08-12 13:30:03 -0300659 struct dvb_frontend *fe;
660 struct xc2028_config cfg = {
661 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
662 .i2c_addr = 0x61,
Steven Toth4c56b042008-08-12 13:30:03 -0300663 };
664 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfe2008-09-16 02:15:30 -0300665 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Toth4c56b042008-08-12 13:30:03 -0300666 .max_len = 64,
667 .demod = XC3028_FE_ZARLINK456,
668 };
669
Steven Toth363c35f2008-10-11 11:05:50 -0300670 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Toth4c56b042008-08-12 13:30:03 -0300671 &cfg);
672 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
673 fe->ops.tuner_ops.set_config(fe, &ctl);
674 }
675 break;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300676 case CX23885_BOARD_TBS_6920:
677 i2c_bus = &dev->i2c_bus[0];
678
679 fe0->dvb.frontend = dvb_attach(cx24116_attach,
680 &tbs_cx24116_config,
681 &i2c_bus->i2c_adap);
682 if (fe0->dvb.frontend != NULL)
683 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
684
685 break;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300686 case CX23885_BOARD_TEVII_S470:
687 i2c_bus = &dev->i2c_bus[1];
688
689 fe0->dvb.frontend = dvb_attach(cx24116_attach,
690 &tevii_cx24116_config,
691 &i2c_bus->i2c_adap);
692 if (fe0->dvb.frontend != NULL)
693 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
694
695 break;
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300696 case CX23885_BOARD_DVBWORLD_2005:
697 i2c_bus = &dev->i2c_bus[1];
698
699 fe0->dvb.frontend = dvb_attach(cx24116_attach,
700 &dvbworld_cx24116_config,
701 &i2c_bus->i2c_adap);
702 break;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300703 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
704 i2c_bus = &dev->i2c_bus[0];
705 switch (port->nr) {
706 /* port B */
707 case 1:
708 fe0->dvb.frontend = dvb_attach(stv0900_attach,
709 &netup_stv0900_config,
710 &i2c_bus->i2c_adap, 0);
711 if (fe0->dvb.frontend != NULL) {
712 if (dvb_attach(stv6110_attach,
713 fe0->dvb.frontend,
714 &netup_stv6110_tunerconfig_a,
715 &i2c_bus->i2c_adap)) {
716 if (!dvb_attach(lnbh24_attach,
717 fe0->dvb.frontend,
718 &i2c_bus->i2c_adap,
719 LNBH24_PCL, 0, 0x09))
720 printk(KERN_ERR
721 "No LNBH24 found!\n");
722
723 }
724 }
725 break;
726 /* port C */
727 case 2:
728 fe0->dvb.frontend = dvb_attach(stv0900_attach,
729 &netup_stv0900_config,
730 &i2c_bus->i2c_adap, 1);
731 if (fe0->dvb.frontend != NULL) {
732 if (dvb_attach(stv6110_attach,
733 fe0->dvb.frontend,
734 &netup_stv6110_tunerconfig_b,
735 &i2c_bus->i2c_adap)) {
736 if (!dvb_attach(lnbh24_attach,
737 fe0->dvb.frontend,
738 &i2c_bus->i2c_adap,
739 LNBH24_PCL, 0, 0x0a))
740 printk(KERN_ERR
741 "No LNBH24 found!\n");
742
743 }
744 }
745 break;
746 }
747 break;
Steven Tothd19770e2007-03-11 20:44:05 -0300748 default:
Steven Toth9c8ced52008-10-16 20:18:44 -0300749 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
750 " isn't supported yet\n",
Steven Tothd19770e2007-03-11 20:44:05 -0300751 dev->name);
752 break;
753 }
Steven Toth363c35f2008-10-11 11:05:50 -0300754 if (NULL == fe0->dvb.frontend) {
Steven Toth9c8ced52008-10-16 20:18:44 -0300755 printk(KERN_ERR "%s: frontend initialization failed\n",
756 dev->name);
Steven Tothd19770e2007-03-11 20:44:05 -0300757 return -1;
758 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300759 /* define general-purpose callback pointer */
Steven Toth363c35f2008-10-11 11:05:50 -0300760 fe0->dvb.frontend->callback = cx23885_tuner_callback;
Steven Tothd19770e2007-03-11 20:44:05 -0300761
762 /* Put the analog decoder in standby to keep it quiet */
Hans Verkuil7c9fc9d2009-04-01 03:49:59 -0300763 call_all(dev, tuner, s_standby);
Steven Tothd19770e2007-03-11 20:44:05 -0300764
Steven Toth363c35f2008-10-11 11:05:50 -0300765 if (fe0->dvb.frontend->ops.analog_ops.standby)
766 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300767
Steven Tothd19770e2007-03-11 20:44:05 -0300768 /* register everything */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300769 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
Darron Broad59b18422008-10-11 11:44:05 -0300770 &dev->pci->dev, adapter_nr, 0);
Steven Toth363c35f2008-10-11 11:05:50 -0300771
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300772 /* init CI & MAC */
773 switch (dev->board) {
774 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
775 static struct netup_card_info cinfo;
776
777 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
778 memcpy(port->frontends.adapter.proposed_mac,
779 cinfo.port[port->nr - 1].mac, 6);
780 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
781 "%02X:%02X:%02X:%02X:%02X:%02X\n",
782 port->nr,
783 port->frontends.adapter.proposed_mac[0],
784 port->frontends.adapter.proposed_mac[1],
785 port->frontends.adapter.proposed_mac[2],
786 port->frontends.adapter.proposed_mac[3],
787 port->frontends.adapter.proposed_mac[4],
788 port->frontends.adapter.proposed_mac[5]);
789
790 netup_ci_init(port);
791 break;
792 }
793 }
794
795 return ret;
Steven Tothd19770e2007-03-11 20:44:05 -0300796}
797
798int cx23885_dvb_register(struct cx23885_tsport *port)
799{
Steven Toth363c35f2008-10-11 11:05:50 -0300800
801 struct videobuf_dvb_frontend *fe0;
Steven Tothd19770e2007-03-11 20:44:05 -0300802 struct cx23885_dev *dev = port->dev;
Steven Totheb0c58b2008-10-11 12:34:39 -0300803 int err, i;
Steven Tothd19770e2007-03-11 20:44:05 -0300804
Steven Totheb0c58b2008-10-11 12:34:39 -0300805 /* Here we need to allocate the correct number of frontends,
806 * as reflected in the cards struct. The reality is that currrently
807 * no cx23885 boards support this - yet. But, if we don't modify this
808 * code then the second frontend would never be allocated (later)
809 * and fail with error before the attach in dvb_register().
810 * Without these changes we risk an OOPS later. The changes here
811 * are for safety, and should provide a good foundation for the
812 * future addition of any multi-frontend cx23885 based boards.
813 */
814 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
815 port->num_frontends);
Steven Toth363c35f2008-10-11 11:05:50 -0300816
Steven Totheb0c58b2008-10-11 12:34:39 -0300817 for (i = 1; i <= port->num_frontends; i++) {
Darron Broad96b7a1a2008-10-15 20:26:34 -0300818 if (videobuf_dvb_alloc_frontend(
Steven Toth9c8ced52008-10-16 20:18:44 -0300819 &port->frontends, i) == NULL) {
Steven Totheb0c58b2008-10-11 12:34:39 -0300820 printk(KERN_ERR "%s() failed to alloc\n", __func__);
821 return -ENOMEM;
822 }
Steven Tothd19770e2007-03-11 20:44:05 -0300823
Steven Totheb0c58b2008-10-11 12:34:39 -0300824 fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
825 if (!fe0)
826 err = -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300827
Steven Totheb0c58b2008-10-11 12:34:39 -0300828 dprintk(1, "%s\n", __func__);
Steven Toth9c8ced52008-10-16 20:18:44 -0300829 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Totheb0c58b2008-10-11 12:34:39 -0300830 dev->board,
831 dev->name,
832 dev->pci_bus,
833 dev->pci_slot);
834
835 err = -ENODEV;
836
837 /* dvb stuff */
838 /* We have to init the queue for each frontend on a port. */
Steven Toth9c8ced52008-10-16 20:18:44 -0300839 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
840 videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
841 &dev->pci->dev, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -0300842 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
843 sizeof(struct cx23885_buffer), port);
Steven Totheb0c58b2008-10-11 12:34:39 -0300844 }
Steven Tothd19770e2007-03-11 20:44:05 -0300845 err = dvb_register(port);
846 if (err != 0)
Steven Toth9c8ced52008-10-16 20:18:44 -0300847 printk(KERN_ERR "%s() dvb_register failed err = %d\n",
848 __func__, err);
Steven Tothd19770e2007-03-11 20:44:05 -0300849
Steven Tothd19770e2007-03-11 20:44:05 -0300850 return err;
851}
852
853int cx23885_dvb_unregister(struct cx23885_tsport *port)
854{
Steven Toth363c35f2008-10-11 11:05:50 -0300855 struct videobuf_dvb_frontend *fe0;
856
Steven Totheb0c58b2008-10-11 12:34:39 -0300857 /* FIXME: in an error condition where the we have
858 * an expected number of frontends (attach problem)
859 * then this might not clean up correctly, if 1
860 * is invalid.
861 * This comment only applies to future boards IF they
862 * implement MFE support.
863 */
Darron Broad92abe9e2008-10-11 11:18:53 -0300864 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth9c8ced52008-10-16 20:18:44 -0300865 if (fe0->dvb.frontend)
Steven Toth363c35f2008-10-11 11:05:50 -0300866 videobuf_dvb_unregister_bus(&port->frontends);
Steven Tothd19770e2007-03-11 20:44:05 -0300867
Hans Verkuilafd96662009-03-13 13:24:19 -0300868 switch (port->dev->board) {
869 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
870 netup_ci_exit(port);
871 break;
872 }
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300873
Steven Tothd19770e2007-03-11 20:44:05 -0300874 return 0;
875}
Michael Krufky44a64812007-03-20 23:00:18 -0300876