2 * ngene-cards.c: nGene PCIe bridge driver - card specific info
4 * Copyright (C) 2005-2007 Micronas
6 * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
7 * Modifications for new nGene firmware,
8 * support for EEPROM-copying,
9 * support for new dual DVB-S2 card prototype
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 only, as published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/pci_ids.h>
45 /****************************************************************************/
46 /* Demod/tuner attachment ***************************************************/
47 /****************************************************************************/
49 static int tuner_attach_stv6110(struct ngene_channel
*chan
)
51 struct i2c_adapter
*i2c
;
52 struct stv090x_config
*feconf
= (struct stv090x_config
*)
53 chan
->dev
->card_info
->fe_config
[chan
->number
];
54 struct stv6110x_config
*tunerconf
= (struct stv6110x_config
*)
55 chan
->dev
->card_info
->tuner_config
[chan
->number
];
56 struct stv6110x_devctl
*ctl
;
58 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
60 i2c
= &chan
->dev
->channel
[0].i2c_adapter
;
62 i2c
= &chan
->dev
->channel
[1].i2c_adapter
;
64 ctl
= dvb_attach(stv6110x_attach
, chan
->fe
, tunerconf
, i2c
);
66 printk(KERN_ERR DEVICE_NAME
": No STV6110X found!\n");
70 feconf
->tuner_init
= ctl
->tuner_init
;
71 feconf
->tuner_sleep
= ctl
->tuner_sleep
;
72 feconf
->tuner_set_mode
= ctl
->tuner_set_mode
;
73 feconf
->tuner_set_frequency
= ctl
->tuner_set_frequency
;
74 feconf
->tuner_get_frequency
= ctl
->tuner_get_frequency
;
75 feconf
->tuner_set_bandwidth
= ctl
->tuner_set_bandwidth
;
76 feconf
->tuner_get_bandwidth
= ctl
->tuner_get_bandwidth
;
77 feconf
->tuner_set_bbgain
= ctl
->tuner_set_bbgain
;
78 feconf
->tuner_get_bbgain
= ctl
->tuner_get_bbgain
;
79 feconf
->tuner_set_refclk
= ctl
->tuner_set_refclk
;
80 feconf
->tuner_get_status
= ctl
->tuner_get_status
;
86 static int demod_attach_stv0900(struct ngene_channel
*chan
)
88 struct i2c_adapter
*i2c
;
89 struct stv090x_config
*feconf
= (struct stv090x_config
*)
90 chan
->dev
->card_info
->fe_config
[chan
->number
];
92 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
93 /* Note: Both adapters share the same i2c bus, but the demod */
94 /* driver requires that each demod has its own i2c adapter */
96 i2c
= &chan
->dev
->channel
[0].i2c_adapter
;
98 i2c
= &chan
->dev
->channel
[1].i2c_adapter
;
100 chan
->fe
= dvb_attach(stv090x_attach
, feconf
, i2c
,
101 (chan
->number
& 1) == 0 ? STV090x_DEMODULATOR_0
102 : STV090x_DEMODULATOR_1
);
103 if (chan
->fe
== NULL
) {
104 printk(KERN_ERR DEVICE_NAME
": No STV0900 found!\n");
108 /* store channel info */
109 if (feconf
->tuner_i2c_lock
)
110 chan
->fe
->analog_demod_priv
= chan
;
112 if (!dvb_attach(lnbh24_attach
, chan
->fe
, i2c
, 0,
113 0, chan
->dev
->card_info
->lnb
[chan
->number
])) {
114 printk(KERN_ERR DEVICE_NAME
": No LNBH24 found!\n");
115 dvb_frontend_detach(chan
->fe
);
123 static void cineS2_tuner_i2c_lock(struct dvb_frontend
*fe
, int lock
)
125 struct ngene_channel
*chan
= fe
->analog_demod_priv
;
128 down(&chan
->dev
->pll_mutex
);
130 up(&chan
->dev
->pll_mutex
);
133 static int cineS2_probe(struct ngene_channel
*chan
)
135 struct i2c_adapter
*i2c
;
136 struct stv090x_config
*fe_conf
;
138 struct i2c_msg i2c_msg
= { .flags
= 0, .buf
= buf
};
141 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
142 if (chan
->number
< 2)
143 i2c
= &chan
->dev
->channel
[0].i2c_adapter
;
145 i2c
= &chan
->dev
->channel
[1].i2c_adapter
;
147 fe_conf
= chan
->dev
->card_info
->fe_config
[chan
->number
];
148 i2c_msg
.addr
= fe_conf
->address
;
154 rc
= i2c_transfer(i2c
, &i2c_msg
, 1);
158 /* demod found, attach it */
159 rc
= demod_attach_stv0900(chan
);
160 if (rc
< 0 || chan
->number
< 2)
163 /* demod #2: reprogram outputs DPN1 & DPN2 */
166 switch (chan
->number
) {
178 rc
= i2c_transfer(i2c
, &i2c_msg
, 1);
180 printk(KERN_ERR DEVICE_NAME
": could not setup DPNx\n");
188 static struct lgdt330x_config aver_m780
= {
189 .demod_address
= 0xb2 >> 1,
190 .demod_chip
= LGDT3303
,
191 .serial_mpeg
= 0x00, /* PARALLEL */
192 .clock_polarity_flip
= 1,
195 static struct mt2131_config m780_tunerconfig
= {
199 /* A single func to attach the demo and tuner, rather than
200 * use two sep funcs like the current design mandates.
202 static int demod_attach_lg330x(struct ngene_channel
*chan
)
204 chan
->fe
= dvb_attach(lgdt330x_attach
, &aver_m780
, &chan
->i2c_adapter
);
205 if (chan
->fe
== NULL
) {
206 printk(KERN_ERR DEVICE_NAME
": No LGDT330x found!\n");
210 dvb_attach(mt2131_attach
, chan
->fe
, &chan
->i2c_adapter
,
211 &m780_tunerconfig
, 0);
213 return (chan
->fe
) ? 0 : -ENODEV
;
216 /****************************************************************************/
217 /* Switch control (I2C gates, etc.) *****************************************/
218 /****************************************************************************/
221 static struct stv090x_config fe_cineS2
= {
223 .demod_mode
= STV090x_DUAL
,
224 .clk_mode
= STV090x_CLK_EXT
,
229 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
230 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
232 .repeater_level
= STV090x_RPTLEVEL_16
,
234 .adc1_range
= STV090x_ADC_1Vpp
,
235 .adc2_range
= STV090x_ADC_1Vpp
,
237 .diseqc_envelope_mode
= true,
239 .tuner_i2c_lock
= cineS2_tuner_i2c_lock
,
242 static struct stv090x_config fe_cineS2_2
= {
244 .demod_mode
= STV090x_DUAL
,
245 .clk_mode
= STV090x_CLK_EXT
,
250 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
251 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
253 .repeater_level
= STV090x_RPTLEVEL_16
,
255 .adc1_range
= STV090x_ADC_1Vpp
,
256 .adc2_range
= STV090x_ADC_1Vpp
,
258 .diseqc_envelope_mode
= true,
260 .tuner_i2c_lock
= cineS2_tuner_i2c_lock
,
263 static struct stv6110x_config tuner_cineS2_0
= {
269 static struct stv6110x_config tuner_cineS2_1
= {
275 static struct ngene_info ngene_info_cineS2
= {
276 .type
= NGENE_SIDEWINDER
,
277 .name
= "Linux4Media cineS2 DVB-S2 Twin Tuner",
278 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
},
279 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
},
280 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
},
281 .fe_config
= {&fe_cineS2
, &fe_cineS2
},
282 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
},
286 .msi_supported
= true,
289 static struct ngene_info ngene_info_satixS2
= {
290 .type
= NGENE_SIDEWINDER
,
291 .name
= "Mystique SaTiX-S2 Dual",
292 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
},
293 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
},
294 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
},
295 .fe_config
= {&fe_cineS2
, &fe_cineS2
},
296 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
},
300 .msi_supported
= true,
303 static struct ngene_info ngene_info_satixS2v2
= {
304 .type
= NGENE_SIDEWINDER
,
305 .name
= "Mystique SaTiX-S2 Dual (v2)",
306 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
,
308 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
, cineS2_probe
, cineS2_probe
},
309 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_stv6110
},
310 .fe_config
= {&fe_cineS2
, &fe_cineS2
, &fe_cineS2_2
, &fe_cineS2_2
},
311 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
, &tuner_cineS2_0
, &tuner_cineS2_1
},
312 .lnb
= {0x0a, 0x08, 0x0b, 0x09},
315 .msi_supported
= true,
318 static struct ngene_info ngene_info_cineS2v5
= {
319 .type
= NGENE_SIDEWINDER
,
320 .name
= "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
321 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
,
323 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
, cineS2_probe
, cineS2_probe
},
324 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_stv6110
},
325 .fe_config
= {&fe_cineS2
, &fe_cineS2
, &fe_cineS2_2
, &fe_cineS2_2
},
326 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
, &tuner_cineS2_0
, &tuner_cineS2_1
},
327 .lnb
= {0x0a, 0x08, 0x0b, 0x09},
330 .msi_supported
= true,
334 static struct ngene_info ngene_info_duoFlexS2
= {
335 .type
= NGENE_SIDEWINDER
,
336 .name
= "Digital Devices DuoFlex S2 miniPCIe",
337 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
,
339 .demod_attach
= {cineS2_probe
, cineS2_probe
, cineS2_probe
, cineS2_probe
},
340 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_stv6110
},
341 .fe_config
= {&fe_cineS2
, &fe_cineS2
, &fe_cineS2_2
, &fe_cineS2_2
},
342 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
, &tuner_cineS2_0
, &tuner_cineS2_1
},
343 .lnb
= {0x0a, 0x08, 0x0b, 0x09},
346 .msi_supported
= true,
349 static struct ngene_info ngene_info_m780
= {
351 .name
= "Aver M780 ATSC/QAM-B",
353 /* Channel 0 is analog, which is currently unsupported */
354 .io_type
= { NGENE_IO_NONE
, NGENE_IO_TSIN
},
355 .demod_attach
= { NULL
, demod_attach_lg330x
},
357 /* Ensure these are NULL else the frame will call them (as funcs) */
358 .tuner_attach
= { 0, 0, 0, 0 },
359 .fe_config
= { NULL
, &aver_m780
},
362 /* A custom electrical interface config for the demod to bridge */
367 /****************************************************************************/
371 /****************************************************************************/
372 /* PCI Subsystem ID *********************************************************/
373 /****************************************************************************/
375 #define NGENE_ID(_subvend, _subdev, _driverdata) { \
376 .vendor = NGENE_VID, .device = NGENE_PID, \
377 .subvendor = _subvend, .subdevice = _subdev, \
378 .driver_data = (unsigned long) &_driverdata }
380 /****************************************************************************/
382 static const struct pci_device_id ngene_id_tbl
[] __devinitdata
= {
383 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2
),
384 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2
),
385 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2
),
386 NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2
),
387 NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5
),
388 NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlexS2
),
389 NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlexS2
),
390 NGENE_ID(0x1461, 0x062e, ngene_info_m780
),
393 MODULE_DEVICE_TABLE(pci
, ngene_id_tbl
);
395 /****************************************************************************/
396 /* Init/Exit ****************************************************************/
397 /****************************************************************************/
399 static pci_ers_result_t
ngene_error_detected(struct pci_dev
*dev
,
400 enum pci_channel_state state
)
402 printk(KERN_ERR DEVICE_NAME
": PCI error\n");
403 if (state
== pci_channel_io_perm_failure
)
404 return PCI_ERS_RESULT_DISCONNECT
;
405 if (state
== pci_channel_io_frozen
)
406 return PCI_ERS_RESULT_NEED_RESET
;
407 return PCI_ERS_RESULT_CAN_RECOVER
;
410 static pci_ers_result_t
ngene_link_reset(struct pci_dev
*dev
)
412 printk(KERN_INFO DEVICE_NAME
": link reset\n");
416 static pci_ers_result_t
ngene_slot_reset(struct pci_dev
*dev
)
418 printk(KERN_INFO DEVICE_NAME
": slot reset\n");
422 static void ngene_resume(struct pci_dev
*dev
)
424 printk(KERN_INFO DEVICE_NAME
": resume\n");
427 static struct pci_error_handlers ngene_errors
= {
428 .error_detected
= ngene_error_detected
,
429 .link_reset
= ngene_link_reset
,
430 .slot_reset
= ngene_slot_reset
,
431 .resume
= ngene_resume
,
434 static struct pci_driver ngene_pci_driver
= {
436 .id_table
= ngene_id_tbl
,
437 .probe
= ngene_probe
,
438 .remove
= __devexit_p(ngene_remove
),
439 .err_handler
= &ngene_errors
,
440 .shutdown
= ngene_shutdown
,
443 static __init
int module_init_ngene(void)
446 "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
447 return pci_register_driver(&ngene_pci_driver
);
450 static __exit
void module_exit_ngene(void)
452 pci_unregister_driver(&ngene_pci_driver
);
455 module_init(module_init_ngene
);
456 module_exit(module_exit_ngene
);
458 MODULE_DESCRIPTION("nGene");
459 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
460 MODULE_LICENSE("GPL");