[media] ngene: CXD2099AR Common Interface driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / dvb / ngene / ngene-cards.c
CommitLineData
cbddcba6
DH
1/*
2 * ngene-cards.c: nGene PCIe bridge driver - card specific info
3 *
4 * Copyright (C) 2005-2007 Micronas
5 *
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
10 *
11 *
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.
15 *
16 *
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.
21 *
22 *
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
26 * 02110-1301, USA
27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 */
29
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/pci.h>
33#include <linux/pci_ids.h>
34
35#include "ngene.h"
36
37/* demods/tuners */
38#include "stv6110x.h"
39#include "stv090x.h"
40#include "lnbh24.h"
41#include "lgdt330x.h"
42#include "mt2131.h"
43
44
45/****************************************************************************/
46/* Demod/tuner attachment ***************************************************/
47/****************************************************************************/
48
49static int tuner_attach_stv6110(struct ngene_channel *chan)
50{
5fec1857 51 struct i2c_adapter *i2c;
cbddcba6
DH
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;
57
5fec1857
OE
58 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
59 if (chan->number < 2)
60 i2c = &chan->dev->channel[0].i2c_adapter;
61 else
62 i2c = &chan->dev->channel[1].i2c_adapter;
63
64 ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
cbddcba6
DH
65 if (ctl == NULL) {
66 printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
67 return -ENODEV;
68 }
69
70 feconf->tuner_init = ctl->tuner_init;
5fec1857 71 feconf->tuner_sleep = ctl->tuner_sleep;
cbddcba6
DH
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;
81
82 return 0;
83}
84
85
86static int demod_attach_stv0900(struct ngene_channel *chan)
87{
5fec1857 88 struct i2c_adapter *i2c;
cbddcba6
DH
89 struct stv090x_config *feconf = (struct stv090x_config *)
90 chan->dev->card_info->fe_config[chan->number];
91
5fec1857
OE
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 */
95 if (chan->number < 2)
96 i2c = &chan->dev->channel[0].i2c_adapter;
97 else
98 i2c = &chan->dev->channel[1].i2c_adapter;
99
100 chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
101 (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
102 : STV090x_DEMODULATOR_1);
cbddcba6
DH
103 if (chan->fe == NULL) {
104 printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
105 return -ENODEV;
106 }
107
5fec1857
OE
108 /* store channel info */
109 if (feconf->tuner_i2c_lock)
110 chan->fe->analog_demod_priv = chan;
111
112 if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
cbddcba6
DH
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);
8a484719 116 chan->fe = NULL;
cbddcba6
DH
117 return -ENODEV;
118 }
119
120 return 0;
121}
122
5fec1857
OE
123static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
124{
125 struct ngene_channel *chan = fe->analog_demod_priv;
126
127 if (lock)
128 down(&chan->dev->pll_mutex);
129 else
130 up(&chan->dev->pll_mutex);
131}
132
133static int cineS2_probe(struct ngene_channel *chan)
134{
135 struct i2c_adapter *i2c;
136 struct stv090x_config *fe_conf;
137 u8 buf[3];
138 struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
139 int rc;
140
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;
144 else
145 i2c = &chan->dev->channel[1].i2c_adapter;
146
147 fe_conf = chan->dev->card_info->fe_config[chan->number];
148 i2c_msg.addr = fe_conf->address;
149
150 /* probe demod */
151 i2c_msg.len = 2;
152 buf[0] = 0xf1;
153 buf[1] = 0x00;
154 rc = i2c_transfer(i2c, &i2c_msg, 1);
155 if (rc != 1)
156 return -ENODEV;
157
158 /* demod found, attach it */
159 rc = demod_attach_stv0900(chan);
160 if (rc < 0 || chan->number < 2)
161 return rc;
162
163 /* demod #2: reprogram outputs DPN1 & DPN2 */
164 i2c_msg.len = 3;
165 buf[0] = 0xf1;
166 switch (chan->number) {
167 case 2:
168 buf[1] = 0x5c;
169 buf[2] = 0xc2;
170 break;
171 case 3:
172 buf[1] = 0x61;
173 buf[2] = 0xcc;
174 break;
175 default:
176 return -ENODEV;
177 }
178 rc = i2c_transfer(i2c, &i2c_msg, 1);
179 if (rc != 1) {
180 printk(KERN_ERR DEVICE_NAME ": could not setup DPNx\n");
181 return -EIO;
182 }
183
184 return 0;
185}
186
187
cbddcba6
DH
188static struct lgdt330x_config aver_m780 = {
189 .demod_address = 0xb2 >> 1,
190 .demod_chip = LGDT3303,
191 .serial_mpeg = 0x00, /* PARALLEL */
192 .clock_polarity_flip = 1,
193};
194
195static struct mt2131_config m780_tunerconfig = {
196 0xc0 >> 1
197};
198
199/* A single func to attach the demo and tuner, rather than
200 * use two sep funcs like the current design mandates.
201 */
202static int demod_attach_lg330x(struct ngene_channel *chan)
203{
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");
207 return -ENODEV;
208 }
209
210 dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
211 &m780_tunerconfig, 0);
212
213 return (chan->fe) ? 0 : -ENODEV;
214}
215
216/****************************************************************************/
217/* Switch control (I2C gates, etc.) *****************************************/
218/****************************************************************************/
219
220
221static struct stv090x_config fe_cineS2 = {
222 .device = STV0900,
223 .demod_mode = STV090x_DUAL,
224 .clk_mode = STV090x_CLK_EXT,
225
226 .xtal = 27000000,
227 .address = 0x68,
228
229 .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
230 .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
231
232 .repeater_level = STV090x_RPTLEVEL_16,
233
234 .adc1_range = STV090x_ADC_1Vpp,
235 .adc2_range = STV090x_ADC_1Vpp,
236
237 .diseqc_envelope_mode = true,
5fec1857
OE
238
239 .tuner_i2c_lock = cineS2_tuner_i2c_lock,
240};
241
242static struct stv090x_config fe_cineS2_2 = {
243 .device = STV0900,
244 .demod_mode = STV090x_DUAL,
245 .clk_mode = STV090x_CLK_EXT,
246
247 .xtal = 27000000,
248 .address = 0x69,
249
250 .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
251 .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
252
253 .repeater_level = STV090x_RPTLEVEL_16,
254
255 .adc1_range = STV090x_ADC_1Vpp,
256 .adc2_range = STV090x_ADC_1Vpp,
257
258 .diseqc_envelope_mode = true,
259
260 .tuner_i2c_lock = cineS2_tuner_i2c_lock,
cbddcba6
DH
261};
262
263static struct stv6110x_config tuner_cineS2_0 = {
264 .addr = 0x60,
265 .refclk = 27000000,
266 .clk_div = 1,
267};
268
269static struct stv6110x_config tuner_cineS2_1 = {
270 .addr = 0x63,
271 .refclk = 27000000,
272 .clk_div = 1,
273};
274
275static 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},
283 .lnb = {0x0b, 0x08},
284 .tsf = {3, 3},
5fec1857
OE
285 .fw_version = 18,
286 .msi_supported = true,
cbddcba6
DH
287};
288
289static 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},
297 .lnb = {0x0b, 0x08},
298 .tsf = {3, 3},
5fec1857
OE
299 .fw_version = 18,
300 .msi_supported = true,
cbddcba6
DH
301};
302
303static struct ngene_info ngene_info_satixS2v2 = {
304 .type = NGENE_SIDEWINDER,
305 .name = "Mystique SaTiX-S2 Dual (v2)",
5fec1857
OE
306 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN},
307 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
308 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
309 .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
310 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
311 .lnb = {0x0a, 0x08, 0x0b, 0x09},
cbddcba6 312 .tsf = {3, 3},
5fec1857
OE
313 .fw_version = 18,
314 .msi_supported = true,
cbddcba6
DH
315};
316
317static struct ngene_info ngene_info_cineS2v5 = {
318 .type = NGENE_SIDEWINDER,
319 .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
0f0b270f
RM
320 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
321 NGENE_IO_TSOUT},
5fec1857
OE
322 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
323 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
324 .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
325 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
326 .lnb = {0x0a, 0x08, 0x0b, 0x09},
cbddcba6 327 .tsf = {3, 3},
5fec1857
OE
328 .fw_version = 18,
329 .msi_supported = true,
cbddcba6
DH
330};
331
5fec1857 332
9d78f460
OE
333static struct ngene_info ngene_info_duoFlexS2 = {
334 .type = NGENE_SIDEWINDER,
335 .name = "Digital Devices DuoFlex S2 miniPCIe",
0f0b270f
RM
336 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
337 NGENE_IO_TSOUT},
5fec1857
OE
338 .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
339 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
340 .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
341 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
342 .lnb = {0x0a, 0x08, 0x0b, 0x09},
9d78f460 343 .tsf = {3, 3},
5fec1857
OE
344 .fw_version = 18,
345 .msi_supported = true,
9d78f460
OE
346};
347
cbddcba6
DH
348static struct ngene_info ngene_info_m780 = {
349 .type = NGENE_APP,
350 .name = "Aver M780 ATSC/QAM-B",
351
352 /* Channel 0 is analog, which is currently unsupported */
353 .io_type = { NGENE_IO_NONE, NGENE_IO_TSIN },
354 .demod_attach = { NULL, demod_attach_lg330x },
355
356 /* Ensure these are NULL else the frame will call them (as funcs) */
357 .tuner_attach = { 0, 0, 0, 0 },
358 .fe_config = { NULL, &aver_m780 },
359 .avf = { 0 },
360
361 /* A custom electrical interface config for the demod to bridge */
362 .tsf = { 4, 4 },
363 .fw_version = 15,
364};
365
366/****************************************************************************/
367
368
369
370/****************************************************************************/
371/* PCI Subsystem ID *********************************************************/
372/****************************************************************************/
373
374#define NGENE_ID(_subvend, _subdev, _driverdata) { \
375 .vendor = NGENE_VID, .device = NGENE_PID, \
376 .subvendor = _subvend, .subdevice = _subdev, \
377 .driver_data = (unsigned long) &_driverdata }
378
379/****************************************************************************/
380
381static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
382 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
383 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
384 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
385 NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
386 NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
9d78f460
OE
387 NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlexS2),
388 NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlexS2),
cbddcba6
DH
389 NGENE_ID(0x1461, 0x062e, ngene_info_m780),
390 {0}
391};
392MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
393
394/****************************************************************************/
395/* Init/Exit ****************************************************************/
396/****************************************************************************/
397
398static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
399 enum pci_channel_state state)
400{
401 printk(KERN_ERR DEVICE_NAME ": PCI error\n");
402 if (state == pci_channel_io_perm_failure)
403 return PCI_ERS_RESULT_DISCONNECT;
404 if (state == pci_channel_io_frozen)
405 return PCI_ERS_RESULT_NEED_RESET;
406 return PCI_ERS_RESULT_CAN_RECOVER;
407}
408
409static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
410{
411 printk(KERN_INFO DEVICE_NAME ": link reset\n");
412 return 0;
413}
414
415static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
416{
417 printk(KERN_INFO DEVICE_NAME ": slot reset\n");
418 return 0;
419}
420
421static void ngene_resume(struct pci_dev *dev)
422{
423 printk(KERN_INFO DEVICE_NAME ": resume\n");
424}
425
426static struct pci_error_handlers ngene_errors = {
427 .error_detected = ngene_error_detected,
428 .link_reset = ngene_link_reset,
429 .slot_reset = ngene_slot_reset,
430 .resume = ngene_resume,
431};
432
433static struct pci_driver ngene_pci_driver = {
434 .name = "ngene",
435 .id_table = ngene_id_tbl,
436 .probe = ngene_probe,
437 .remove = __devexit_p(ngene_remove),
438 .err_handler = &ngene_errors,
439};
440
441static __init int module_init_ngene(void)
442{
443 printk(KERN_INFO
444 "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
445 return pci_register_driver(&ngene_pci_driver);
446}
447
448static __exit void module_exit_ngene(void)
449{
450 pci_unregister_driver(&ngene_pci_driver);
451}
452
453module_init(module_init_ngene);
454module_exit(module_exit_ngene);
455
456MODULE_DESCRIPTION("nGene");
457MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
458MODULE_LICENSE("GPL");