]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/media/pci/ngene/ngene-cards.c
regmap: debugfs: Fix seeking from the cache
[karo-tx-linux.git] / drivers / media / pci / ngene / ngene-cards.c
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 #include "tda18271c2dd.h"
44 #include "drxk.h"
45 #include "drxd.h"
46 #include "dvb-pll.h"
47
48
49 /****************************************************************************/
50 /* Demod/tuner attachment ***************************************************/
51 /****************************************************************************/
52
53 static int tuner_attach_stv6110(struct ngene_channel *chan)
54 {
55         struct i2c_adapter *i2c;
56         struct stv090x_config *feconf = (struct stv090x_config *)
57                 chan->dev->card_info->fe_config[chan->number];
58         struct stv6110x_config *tunerconf = (struct stv6110x_config *)
59                 chan->dev->card_info->tuner_config[chan->number];
60         struct stv6110x_devctl *ctl;
61
62         /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
63         if (chan->number < 2)
64                 i2c = &chan->dev->channel[0].i2c_adapter;
65         else
66                 i2c = &chan->dev->channel[1].i2c_adapter;
67
68         ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
69         if (ctl == NULL) {
70                 printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
71                 return -ENODEV;
72         }
73
74         feconf->tuner_init          = ctl->tuner_init;
75         feconf->tuner_sleep         = ctl->tuner_sleep;
76         feconf->tuner_set_mode      = ctl->tuner_set_mode;
77         feconf->tuner_set_frequency = ctl->tuner_set_frequency;
78         feconf->tuner_get_frequency = ctl->tuner_get_frequency;
79         feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
80         feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
81         feconf->tuner_set_bbgain    = ctl->tuner_set_bbgain;
82         feconf->tuner_get_bbgain    = ctl->tuner_get_bbgain;
83         feconf->tuner_set_refclk    = ctl->tuner_set_refclk;
84         feconf->tuner_get_status    = ctl->tuner_get_status;
85
86         return 0;
87 }
88
89
90 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
91 {
92         struct ngene_channel *chan = fe->sec_priv;
93         int status;
94
95         if (enable) {
96                 down(&chan->dev->pll_mutex);
97                 status = chan->gate_ctrl(fe, 1);
98         } else {
99                 status = chan->gate_ctrl(fe, 0);
100                 up(&chan->dev->pll_mutex);
101         }
102         return status;
103 }
104
105 static int tuner_attach_tda18271(struct ngene_channel *chan)
106 {
107         struct i2c_adapter *i2c;
108         struct dvb_frontend *fe;
109
110         i2c = &chan->dev->channel[0].i2c_adapter;
111         if (chan->fe->ops.i2c_gate_ctrl)
112                 chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
113         fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60);
114         if (chan->fe->ops.i2c_gate_ctrl)
115                 chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
116         if (!fe) {
117                 printk(KERN_ERR "No TDA18271 found!\n");
118                 return -ENODEV;
119         }
120
121         return 0;
122 }
123
124 static int tuner_attach_probe(struct ngene_channel *chan)
125 {
126         if (chan->demod_type == 0)
127                 return tuner_attach_stv6110(chan);
128         if (chan->demod_type == 1)
129                 return tuner_attach_tda18271(chan);
130         return -EINVAL;
131 }
132
133 static int demod_attach_stv0900(struct ngene_channel *chan)
134 {
135         struct i2c_adapter *i2c;
136         struct stv090x_config *feconf = (struct stv090x_config *)
137                 chan->dev->card_info->fe_config[chan->number];
138
139         /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
140         /* Note: Both adapters share the same i2c bus, but the demod     */
141         /*       driver requires that each demod has its own i2c adapter */
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         chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
148                         (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
149                                                 : STV090x_DEMODULATOR_1);
150         if (chan->fe == NULL) {
151                 printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
152                 return -ENODEV;
153         }
154
155         /* store channel info */
156         if (feconf->tuner_i2c_lock)
157                 chan->fe->analog_demod_priv = chan;
158
159         if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
160                         0, chan->dev->card_info->lnb[chan->number])) {
161                 printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
162                 dvb_frontend_detach(chan->fe);
163                 chan->fe = NULL;
164                 return -ENODEV;
165         }
166
167         return 0;
168 }
169
170 static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
171 {
172         struct ngene_channel *chan = fe->analog_demod_priv;
173
174         if (lock)
175                 down(&chan->dev->pll_mutex);
176         else
177                 up(&chan->dev->pll_mutex);
178 }
179
180 static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
181 {
182         struct i2c_msg msgs[1] = {{.addr = adr,  .flags = I2C_M_RD,
183                                    .buf  = val,  .len   = 1 } };
184         return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
185 }
186
187 static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
188                           u16 reg, u8 *val)
189 {
190         u8 msg[2] = {reg>>8, reg&0xff};
191         struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
192                                    .buf  = msg, .len   = 2},
193                                   {.addr = adr, .flags = I2C_M_RD,
194                                    .buf  = val, .len   = 1} };
195         return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
196 }
197
198 static int port_has_stv0900(struct i2c_adapter *i2c, int port)
199 {
200         u8 val;
201         if (i2c_read_reg16(i2c, 0x68+port/2, 0xf100, &val) < 0)
202                 return 0;
203         return 1;
204 }
205
206 static int port_has_drxk(struct i2c_adapter *i2c, int port)
207 {
208         u8 val;
209
210         if (i2c_read(i2c, 0x29+port, &val) < 0)
211                 return 0;
212         return 1;
213 }
214
215 static int demod_attach_drxk(struct ngene_channel *chan,
216                              struct i2c_adapter *i2c)
217 {
218         struct drxk_config config;
219
220         memset(&config, 0, sizeof(config));
221         config.microcode_name = "drxk_a3.mc";
222         config.qam_demod_parameter_count = 4;
223         config.adr = 0x29 + (chan->number ^ 2);
224
225         chan->fe = dvb_attach(drxk_attach, &config, i2c);
226         if (!chan->fe) {
227                 printk(KERN_ERR "No DRXK found!\n");
228                 return -ENODEV;
229         }
230         chan->fe->sec_priv = chan;
231         chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
232         chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
233         return 0;
234 }
235
236 static int cineS2_probe(struct ngene_channel *chan)
237 {
238         struct i2c_adapter *i2c;
239         struct stv090x_config *fe_conf;
240         u8 buf[3];
241         struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
242         int rc;
243
244         /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
245         if (chan->number < 2)
246                 i2c = &chan->dev->channel[0].i2c_adapter;
247         else
248                 i2c = &chan->dev->channel[1].i2c_adapter;
249
250         if (port_has_stv0900(i2c, chan->number)) {
251                 chan->demod_type = 0;
252                 fe_conf = chan->dev->card_info->fe_config[chan->number];
253                 /* demod found, attach it */
254                 rc = demod_attach_stv0900(chan);
255                 if (rc < 0 || chan->number < 2)
256                         return rc;
257
258                 /* demod #2: reprogram outputs DPN1 & DPN2 */
259                 i2c_msg.addr = fe_conf->address;
260                 i2c_msg.len = 3;
261                 buf[0] = 0xf1;
262                 switch (chan->number) {
263                 case 2:
264                         buf[1] = 0x5c;
265                         buf[2] = 0xc2;
266                         break;
267                 case 3:
268                         buf[1] = 0x61;
269                         buf[2] = 0xcc;
270                         break;
271                 default:
272                         return -ENODEV;
273                 }
274                 rc = i2c_transfer(i2c, &i2c_msg, 1);
275                 if (rc != 1) {
276                         printk(KERN_ERR DEVICE_NAME ": could not setup DPNx\n");
277                         return -EIO;
278                 }
279         } else if (port_has_drxk(i2c, chan->number^2)) {
280                 chan->demod_type = 1;
281                 demod_attach_drxk(chan, i2c);
282         } else {
283                 printk(KERN_ERR "No demod found on chan %d\n", chan->number);
284                 return -ENODEV;
285         }
286         return 0;
287 }
288
289
290 static struct lgdt330x_config aver_m780 = {
291         .demod_address = 0xb2 >> 1,
292         .demod_chip    = LGDT3303,
293         .serial_mpeg   = 0x00, /* PARALLEL */
294         .clock_polarity_flip = 1,
295 };
296
297 static struct mt2131_config m780_tunerconfig = {
298         0xc0 >> 1
299 };
300
301 /* A single func to attach the demo and tuner, rather than
302  * use two sep funcs like the current design mandates.
303  */
304 static int demod_attach_lg330x(struct ngene_channel *chan)
305 {
306         chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter);
307         if (chan->fe == NULL) {
308                 printk(KERN_ERR DEVICE_NAME ": No LGDT330x found!\n");
309                 return -ENODEV;
310         }
311
312         dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
313                    &m780_tunerconfig, 0);
314
315         return (chan->fe) ? 0 : -ENODEV;
316 }
317
318 static int demod_attach_drxd(struct ngene_channel *chan)
319 {
320         struct drxd_config *feconf;
321
322         feconf = chan->dev->card_info->fe_config[chan->number];
323
324         chan->fe = dvb_attach(drxd_attach, feconf, chan,
325                         &chan->i2c_adapter, &chan->dev->pci_dev->dev);
326         if (!chan->fe) {
327                 pr_err("No DRXD found!\n");
328                 return -ENODEV;
329         }
330
331         if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
332                         &chan->i2c_adapter,
333                         feconf->pll_type)) {
334                 pr_err("No pll(%d) found!\n", feconf->pll_type);
335                 return -ENODEV;
336         }
337         return 0;
338 }
339
340 /****************************************************************************/
341 /* EEPROM TAGS **************************************************************/
342 /****************************************************************************/
343
344 #define MICNG_EE_START      0x0100
345 #define MICNG_EE_END        0x0FF0
346
347 #define MICNG_EETAG_END0    0x0000
348 #define MICNG_EETAG_END1    0xFFFF
349
350 /* 0x0001 - 0x000F reserved for housekeeping */
351 /* 0xFFFF - 0xFFFE reserved for housekeeping */
352
353 /* Micronas assigned tags
354    EEProm tags for hardware support */
355
356 #define MICNG_EETAG_DRXD1_OSCDEVIATION  0x1000  /* 2 Bytes data */
357 #define MICNG_EETAG_DRXD2_OSCDEVIATION  0x1001  /* 2 Bytes data */
358
359 #define MICNG_EETAG_MT2060_1_1STIF      0x1100  /* 2 Bytes data */
360 #define MICNG_EETAG_MT2060_2_1STIF      0x1101  /* 2 Bytes data */
361
362 /* Tag range for OEMs */
363
364 #define MICNG_EETAG_OEM_FIRST  0xC000
365 #define MICNG_EETAG_OEM_LAST   0xFFEF
366
367 static int i2c_write_eeprom(struct i2c_adapter *adapter,
368                             u8 adr, u16 reg, u8 data)
369 {
370         u8 m[3] = {(reg >> 8), (reg & 0xff), data};
371         struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m,
372                               .len = sizeof(m)};
373
374         if (i2c_transfer(adapter, &msg, 1) != 1) {
375                 pr_err(DEVICE_NAME ": Error writing EEPROM!\n");
376                 return -EIO;
377         }
378         return 0;
379 }
380
381 static int i2c_read_eeprom(struct i2c_adapter *adapter,
382                            u8 adr, u16 reg, u8 *data, int len)
383 {
384         u8 msg[2] = {(reg >> 8), (reg & 0xff)};
385         struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
386                                    .buf = msg, .len = 2 },
387                                   {.addr = adr, .flags = I2C_M_RD,
388                                    .buf = data, .len = len} };
389
390         if (i2c_transfer(adapter, msgs, 2) != 2) {
391                 pr_err(DEVICE_NAME ": Error reading EEPROM\n");
392                 return -EIO;
393         }
394         return 0;
395 }
396
397 static int ReadEEProm(struct i2c_adapter *adapter,
398                       u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
399 {
400         int status = 0;
401         u16 Addr = MICNG_EE_START, Length, tag = 0;
402         u8  EETag[3];
403
404         while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
405                 if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
406                         return -1;
407                 tag = (EETag[0] << 8) | EETag[1];
408                 if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
409                         return -1;
410                 if (tag == Tag)
411                         break;
412                 Addr += sizeof(u16) + 1 + EETag[2];
413         }
414         if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
415                 pr_err(DEVICE_NAME
416                        ": Reached EOEE @ Tag = %04x Length = %3d\n",
417                        tag, EETag[2]);
418                 return -1;
419         }
420         Length = EETag[2];
421         if (Length > MaxLen)
422                 Length = (u16) MaxLen;
423         if (Length > 0) {
424                 Addr += sizeof(u16) + 1;
425                 status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
426                 if (!status) {
427                         *pLength = EETag[2];
428 #if 0
429                         if (Length < EETag[2])
430                                 status = STATUS_BUFFER_OVERFLOW;
431 #endif
432                 }
433         }
434         return status;
435 }
436
437 static int WriteEEProm(struct i2c_adapter *adapter,
438                        u16 Tag, u32 Length, u8 *data)
439 {
440         int status = 0;
441         u16 Addr = MICNG_EE_START;
442         u8 EETag[3];
443         u16 tag = 0;
444         int retry, i;
445
446         while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
447                 if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
448                         return -1;
449                 tag = (EETag[0] << 8) | EETag[1];
450                 if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
451                         return -1;
452                 if (tag == Tag)
453                         break;
454                 Addr += sizeof(u16) + 1 + EETag[2];
455         }
456         if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
457                 pr_err(DEVICE_NAME
458                        ": Reached EOEE @ Tag = %04x Length = %3d\n",
459                        tag, EETag[2]);
460                 return -1;
461         }
462
463         if (Length > EETag[2])
464                 return -EINVAL;
465         /* Note: We write the data one byte at a time to avoid
466            issues with page sizes. (which are different for
467            each manufacture and eeprom size)
468          */
469         Addr += sizeof(u16) + 1;
470         for (i = 0; i < Length; i++, Addr++) {
471                 status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
472
473                 if (status)
474                         break;
475
476                 /* Poll for finishing write cycle */
477                 retry = 10;
478                 while (retry) {
479                         u8 Tmp;
480
481                         msleep(50);
482                         status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
483                         if (status)
484                                 break;
485                         if (Tmp != data[i])
486                                 pr_err(DEVICE_NAME
487                                        "eeprom write error\n");
488                         retry -= 1;
489                 }
490                 if (status) {
491                         pr_err(DEVICE_NAME
492                                ": Timeout polling eeprom\n");
493                         break;
494                 }
495         }
496         return status;
497 }
498
499 static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
500 {
501         int stat;
502         u8 buf[2];
503         u32 len = 0;
504
505         stat = ReadEEProm(adapter, tag, 2, buf, &len);
506         if (stat)
507                 return stat;
508         if (len != 2)
509                 return -EINVAL;
510
511         *data = (buf[0] << 8) | buf[1];
512         return 0;
513 }
514
515 static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
516 {
517         int stat;
518         u8 buf[2];
519
520         buf[0] = data >> 8;
521         buf[1] = data & 0xff;
522         stat = WriteEEProm(adapter, tag, 2, buf);
523         if (stat)
524                 return stat;
525         return 0;
526 }
527
528 static s16 osc_deviation(void *priv, s16 deviation, int flag)
529 {
530         struct ngene_channel *chan = priv;
531         struct i2c_adapter *adap = &chan->i2c_adapter;
532         u16 data = 0;
533
534         if (flag) {
535                 data = (u16) deviation;
536                 pr_info(DEVICE_NAME ": write deviation %d\n",
537                        deviation);
538                 eeprom_write_ushort(adap, 0x1000 + chan->number, data);
539         } else {
540                 if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
541                         data = 0;
542                 pr_info(DEVICE_NAME ": read deviation %d\n",
543                        (s16) data);
544         }
545
546         return (s16) data;
547 }
548
549 /****************************************************************************/
550 /* Switch control (I2C gates, etc.) *****************************************/
551 /****************************************************************************/
552
553
554 static struct stv090x_config fe_cineS2 = {
555         .device         = STV0900,
556         .demod_mode     = STV090x_DUAL,
557         .clk_mode       = STV090x_CLK_EXT,
558
559         .xtal           = 27000000,
560         .address        = 0x68,
561
562         .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
563         .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
564
565         .repeater_level = STV090x_RPTLEVEL_16,
566
567         .adc1_range     = STV090x_ADC_1Vpp,
568         .adc2_range     = STV090x_ADC_1Vpp,
569
570         .diseqc_envelope_mode = true,
571
572         .tuner_i2c_lock = cineS2_tuner_i2c_lock,
573 };
574
575 static struct stv090x_config fe_cineS2_2 = {
576         .device         = STV0900,
577         .demod_mode     = STV090x_DUAL,
578         .clk_mode       = STV090x_CLK_EXT,
579
580         .xtal           = 27000000,
581         .address        = 0x69,
582
583         .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
584         .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
585
586         .repeater_level = STV090x_RPTLEVEL_16,
587
588         .adc1_range     = STV090x_ADC_1Vpp,
589         .adc2_range     = STV090x_ADC_1Vpp,
590
591         .diseqc_envelope_mode = true,
592
593         .tuner_i2c_lock = cineS2_tuner_i2c_lock,
594 };
595
596 static struct stv6110x_config tuner_cineS2_0 = {
597         .addr   = 0x60,
598         .refclk = 27000000,
599         .clk_div = 1,
600 };
601
602 static struct stv6110x_config tuner_cineS2_1 = {
603         .addr   = 0x63,
604         .refclk = 27000000,
605         .clk_div = 1,
606 };
607
608 static struct ngene_info ngene_info_cineS2 = {
609         .type           = NGENE_SIDEWINDER,
610         .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner",
611         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
612         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
613         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
614         .fe_config      = {&fe_cineS2, &fe_cineS2},
615         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
616         .lnb            = {0x0b, 0x08},
617         .tsf            = {3, 3},
618         .fw_version     = 18,
619         .msi_supported  = true,
620 };
621
622 static struct ngene_info ngene_info_satixS2 = {
623         .type           = NGENE_SIDEWINDER,
624         .name           = "Mystique SaTiX-S2 Dual",
625         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
626         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
627         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
628         .fe_config      = {&fe_cineS2, &fe_cineS2},
629         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
630         .lnb            = {0x0b, 0x08},
631         .tsf            = {3, 3},
632         .fw_version     = 18,
633         .msi_supported  = true,
634 };
635
636 static struct ngene_info ngene_info_satixS2v2 = {
637         .type           = NGENE_SIDEWINDER,
638         .name           = "Mystique SaTiX-S2 Dual (v2)",
639         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
640                            NGENE_IO_TSOUT},
641         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
642         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
643         .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
644         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
645         .lnb            = {0x0a, 0x08, 0x0b, 0x09},
646         .tsf            = {3, 3},
647         .fw_version     = 18,
648         .msi_supported  = true,
649 };
650
651 static struct ngene_info ngene_info_cineS2v5 = {
652         .type           = NGENE_SIDEWINDER,
653         .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
654         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
655                            NGENE_IO_TSOUT},
656         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
657         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
658         .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
659         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
660         .lnb            = {0x0a, 0x08, 0x0b, 0x09},
661         .tsf            = {3, 3},
662         .fw_version     = 18,
663         .msi_supported  = true,
664 };
665
666
667 static struct ngene_info ngene_info_duoFlex = {
668         .type           = NGENE_SIDEWINDER,
669         .name           = "Digital Devices DuoFlex PCIe or miniPCIe",
670         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
671                            NGENE_IO_TSOUT},
672         .demod_attach   = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
673         .tuner_attach   = {tuner_attach_probe, tuner_attach_probe, tuner_attach_probe, tuner_attach_probe},
674         .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
675         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
676         .lnb            = {0x0a, 0x08, 0x0b, 0x09},
677         .tsf            = {3, 3},
678         .fw_version     = 18,
679         .msi_supported  = true,
680 };
681
682 static struct ngene_info ngene_info_m780 = {
683         .type           = NGENE_APP,
684         .name           = "Aver M780 ATSC/QAM-B",
685
686         /* Channel 0 is analog, which is currently unsupported */
687         .io_type        = { NGENE_IO_NONE, NGENE_IO_TSIN },
688         .demod_attach   = { NULL, demod_attach_lg330x },
689
690         /* Ensure these are NULL else the frame will call them (as funcs) */
691         .tuner_attach   = { 0, 0, 0, 0 },
692         .fe_config      = { NULL, &aver_m780 },
693         .avf            = { 0 },
694
695         /* A custom electrical interface config for the demod to bridge */
696         .tsf            = { 4, 4 },
697         .fw_version     = 15,
698 };
699
700 static struct drxd_config fe_terratec_dvbt_0 = {
701         .index          = 0,
702         .demod_address  = 0x70,
703         .demod_revision = 0xa2,
704         .demoda_address = 0x00,
705         .pll_address    = 0x60,
706         .pll_type       = DVB_PLL_THOMSON_DTT7520X,
707         .clock          = 20000,
708         .osc_deviation  = osc_deviation,
709 };
710
711 static struct drxd_config fe_terratec_dvbt_1 = {
712         .index          = 1,
713         .demod_address  = 0x71,
714         .demod_revision = 0xa2,
715         .demoda_address = 0x00,
716         .pll_address    = 0x60,
717         .pll_type       = DVB_PLL_THOMSON_DTT7520X,
718         .clock          = 20000,
719         .osc_deviation  = osc_deviation,
720 };
721
722 static struct ngene_info ngene_info_terratec = {
723         .type           = NGENE_TERRATEC,
724         .name           = "Terratec Integra/Cinergy2400i Dual DVB-T",
725         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
726         .demod_attach   = {demod_attach_drxd, demod_attach_drxd},
727         .fe_config      = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
728         .i2c_access     = 1,
729 };
730
731 /****************************************************************************/
732
733
734
735 /****************************************************************************/
736 /* PCI Subsystem ID *********************************************************/
737 /****************************************************************************/
738
739 #define NGENE_ID(_subvend, _subdev, _driverdata) { \
740         .vendor = NGENE_VID, .device = NGENE_PID, \
741         .subvendor = _subvend, .subdevice = _subdev, \
742         .driver_data = (unsigned long) &_driverdata }
743
744 /****************************************************************************/
745
746 static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
747         NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
748         NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
749         NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
750         NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
751         NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
752         NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex),
753         NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex),
754         NGENE_ID(0x1461, 0x062e, ngene_info_m780),
755         NGENE_ID(0x153b, 0x1167, ngene_info_terratec),
756         {0}
757 };
758 MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
759
760 /****************************************************************************/
761 /* Init/Exit ****************************************************************/
762 /****************************************************************************/
763
764 static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
765                                              enum pci_channel_state state)
766 {
767         printk(KERN_ERR DEVICE_NAME ": PCI error\n");
768         if (state == pci_channel_io_perm_failure)
769                 return PCI_ERS_RESULT_DISCONNECT;
770         if (state == pci_channel_io_frozen)
771                 return PCI_ERS_RESULT_NEED_RESET;
772         return PCI_ERS_RESULT_CAN_RECOVER;
773 }
774
775 static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
776 {
777         printk(KERN_INFO DEVICE_NAME ": link reset\n");
778         return 0;
779 }
780
781 static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
782 {
783         printk(KERN_INFO DEVICE_NAME ": slot reset\n");
784         return 0;
785 }
786
787 static void ngene_resume(struct pci_dev *dev)
788 {
789         printk(KERN_INFO DEVICE_NAME ": resume\n");
790 }
791
792 static const struct pci_error_handlers ngene_errors = {
793         .error_detected = ngene_error_detected,
794         .link_reset = ngene_link_reset,
795         .slot_reset = ngene_slot_reset,
796         .resume = ngene_resume,
797 };
798
799 static struct pci_driver ngene_pci_driver = {
800         .name        = "ngene",
801         .id_table    = ngene_id_tbl,
802         .probe       = ngene_probe,
803         .remove      = __devexit_p(ngene_remove),
804         .err_handler = &ngene_errors,
805         .shutdown    = ngene_shutdown,
806 };
807
808 static __init int module_init_ngene(void)
809 {
810         printk(KERN_INFO
811                "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
812         return pci_register_driver(&ngene_pci_driver);
813 }
814
815 static __exit void module_exit_ngene(void)
816 {
817         pci_unregister_driver(&ngene_pci_driver);
818 }
819
820 module_init(module_init_ngene);
821 module_exit(module_exit_ngene);
822
823 MODULE_DESCRIPTION("nGene");
824 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
825 MODULE_LICENSE("GPL");