37e9f0eb6d20bc8bec3fa9e5a10ae13e99627ab3
[sfrench/cifs-2.6.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  * To obtain the license, point your browser to
23  * http://www.gnu.org/copyleft/gpl.html
24  */
25
26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
31 #include <linux/pci_ids.h>
32
33 #include "ngene.h"
34
35 /* demods/tuners */
36 #include "stv6110x.h"
37 #include "stv090x.h"
38 #include "lnbh24.h"
39 #include "lgdt330x.h"
40 #include "mt2131.h"
41 #include "tda18271c2dd.h"
42 #include "drxk.h"
43 #include "drxd.h"
44 #include "dvb-pll.h"
45 #include "stv0367.h"
46 #include "stv0367_priv.h"
47 #include "tda18212.h"
48 #include "cxd2841er.h"
49 #include "stv0910.h"
50 #include "stv6111.h"
51 #include "lnbh25.h"
52
53 /****************************************************************************/
54 /* I2C transfer functions used for demod/tuner probing***********************/
55 /****************************************************************************/
56
57 static int i2c_io(struct i2c_adapter *adapter, u8 adr,
58                   u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
59 {
60         struct i2c_msg msgs[2] = {{.addr = adr,  .flags = 0,
61                                    .buf  = wbuf, .len   = wlen },
62                                   {.addr = adr,  .flags = I2C_M_RD,
63                                    .buf  = rbuf,  .len   = rlen } };
64         return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
65 }
66
67 static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
68 {
69         struct i2c_msg msg = {.addr = adr, .flags = 0,
70                               .buf = data, .len = len};
71
72         return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
73 }
74
75 static int i2c_write_reg(struct i2c_adapter *adap, u8 adr,
76                          u8 reg, u8 val)
77 {
78         u8 msg[2] = {reg, val};
79
80         return i2c_write(adap, adr, msg, 2);
81 }
82
83 static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
84 {
85         struct i2c_msg msgs[1] = {{.addr = adr,  .flags = I2C_M_RD,
86                                    .buf  = val,  .len   = 1 } };
87         return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
88 }
89
90 static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
91                           u16 reg, u8 *val)
92 {
93         u8 msg[2] = {reg >> 8, reg & 0xff};
94         struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
95                                    .buf  = msg, .len   = 2},
96                                   {.addr = adr, .flags = I2C_M_RD,
97                                    .buf  = val, .len   = 1} };
98         return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
99 }
100
101 static int i2c_read_regs(struct i2c_adapter *adapter,
102                          u8 adr, u8 reg, u8 *val, u8 len)
103 {
104         struct i2c_msg msgs[2] = {{.addr = adr,  .flags = 0,
105                                    .buf  = &reg, .len   = 1},
106                                   {.addr = adr,  .flags = I2C_M_RD,
107                                    .buf  = val,  .len   = len} };
108
109         return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
110 }
111
112 static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, u8 reg, u8 *val)
113 {
114         return i2c_read_regs(adapter, adr, reg, val, 1);
115 }
116
117 /****************************************************************************/
118 /* Demod/tuner attachment ***************************************************/
119 /****************************************************************************/
120
121 static struct i2c_adapter *i2c_adapter_from_chan(struct ngene_channel *chan)
122 {
123         /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
124         if (chan->number < 2)
125                 return &chan->dev->channel[0].i2c_adapter;
126
127         return &chan->dev->channel[1].i2c_adapter;
128 }
129
130 static int tuner_attach_stv6110(struct ngene_channel *chan)
131 {
132         struct device *pdev = &chan->dev->pci_dev->dev;
133         struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
134         struct stv090x_config *feconf = (struct stv090x_config *)
135                 chan->dev->card_info->fe_config[chan->number];
136         struct stv6110x_config *tunerconf = (struct stv6110x_config *)
137                 chan->dev->card_info->tuner_config[chan->number];
138         const struct stv6110x_devctl *ctl;
139
140         if (chan->number < 2)
141                 i2c = &chan->dev->channel[0].i2c_adapter;
142         else
143                 i2c = &chan->dev->channel[1].i2c_adapter;
144
145         ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
146         if (ctl == NULL) {
147                 dev_err(pdev, "No STV6110X found!\n");
148                 return -ENODEV;
149         }
150
151         feconf->tuner_init          = ctl->tuner_init;
152         feconf->tuner_sleep         = ctl->tuner_sleep;
153         feconf->tuner_set_mode      = ctl->tuner_set_mode;
154         feconf->tuner_set_frequency = ctl->tuner_set_frequency;
155         feconf->tuner_get_frequency = ctl->tuner_get_frequency;
156         feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
157         feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
158         feconf->tuner_set_bbgain    = ctl->tuner_set_bbgain;
159         feconf->tuner_get_bbgain    = ctl->tuner_get_bbgain;
160         feconf->tuner_set_refclk    = ctl->tuner_set_refclk;
161         feconf->tuner_get_status    = ctl->tuner_get_status;
162
163         return 0;
164 }
165
166 static int tuner_attach_stv6111(struct ngene_channel *chan)
167 {
168         struct device *pdev = &chan->dev->pci_dev->dev;
169         struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
170         struct dvb_frontend *fe;
171         u8 adr = 4 + ((chan->number & 1) ? 0x63 : 0x60);
172
173         fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr);
174         if (!fe) {
175                 fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4);
176                 if (!fe) {
177                         dev_err(pdev, "stv6111_attach() failed!\n");
178                         return -ENODEV;
179                 }
180         }
181         return 0;
182 }
183
184 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
185 {
186         struct ngene_channel *chan = fe->sec_priv;
187         int status;
188
189         if (enable) {
190                 down(&chan->dev->pll_mutex);
191                 status = chan->gate_ctrl(fe, 1);
192         } else {
193                 status = chan->gate_ctrl(fe, 0);
194                 up(&chan->dev->pll_mutex);
195         }
196         return status;
197 }
198
199 static int tuner_attach_tda18271(struct ngene_channel *chan)
200 {
201         struct device *pdev = &chan->dev->pci_dev->dev;
202         struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
203         struct dvb_frontend *fe;
204
205         if (chan->fe->ops.i2c_gate_ctrl)
206                 chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
207         fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60);
208         if (chan->fe->ops.i2c_gate_ctrl)
209                 chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
210         if (!fe) {
211                 dev_err(pdev, "No TDA18271 found!\n");
212                 return -ENODEV;
213         }
214
215         return 0;
216 }
217
218 static int tuner_tda18212_ping(struct ngene_channel *chan,
219                                struct i2c_adapter *i2c,
220                                unsigned short adr)
221 {
222         struct device *pdev = &chan->dev->pci_dev->dev;
223         u8 tda_id[2];
224         u8 subaddr = 0x00;
225
226         dev_dbg(pdev, "stv0367-tda18212 tuner ping\n");
227         if (chan->fe->ops.i2c_gate_ctrl)
228                 chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
229
230         if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
231                 dev_dbg(pdev, "tda18212 ping 1 fail\n");
232         if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
233                 dev_warn(pdev, "tda18212 ping failed, expect problems\n");
234
235         if (chan->fe->ops.i2c_gate_ctrl)
236                 chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
237
238         return 0;
239 }
240
241 static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
242 {
243         struct device *pdev = &chan->dev->pci_dev->dev;
244         struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
245         struct i2c_client *client;
246         struct tda18212_config config = {
247                 .fe = chan->fe,
248                 .if_dvbt_6 = 3550,
249                 .if_dvbt_7 = 3700,
250                 .if_dvbt_8 = 4150,
251                 .if_dvbt2_6 = 3250,
252                 .if_dvbt2_7 = 4000,
253                 .if_dvbt2_8 = 4000,
254                 .if_dvbc = 5000,
255         };
256         struct i2c_board_info board_info = {
257                 .type = "tda18212",
258                 .platform_data = &config,
259         };
260
261         if (chan->number & 1)
262                 board_info.addr = 0x63;
263         else
264                 board_info.addr = 0x60;
265
266         /*
267          * due to a hardware quirk with the I2C gate on the stv0367+tda18212
268          * combo, the tda18212 must be probed by reading it's id _twice_ when
269          * cold started, or it very likely will fail.
270          */
271         if (dmdtype == DEMOD_TYPE_STV0367)
272                 tuner_tda18212_ping(chan, i2c, board_info.addr);
273
274         request_module(board_info.type);
275
276         /* perform tuner init/attach */
277         client = i2c_new_device(i2c, &board_info);
278         if (!client || !client->dev.driver)
279                 goto err;
280
281         if (!try_module_get(client->dev.driver->owner)) {
282                 i2c_unregister_device(client);
283                 goto err;
284         }
285
286         chan->i2c_client[0] = client;
287         chan->i2c_client_fe = 1;
288
289         return 0;
290 err:
291         dev_err(pdev, "TDA18212 tuner not found. Device is not fully operational.\n");
292         return -ENODEV;
293 }
294
295 static int tuner_attach_probe(struct ngene_channel *chan)
296 {
297         switch (chan->demod_type) {
298         case DEMOD_TYPE_STV090X:
299                 return tuner_attach_stv6110(chan);
300         case DEMOD_TYPE_DRXK:
301                 return tuner_attach_tda18271(chan);
302         case DEMOD_TYPE_STV0367:
303         case DEMOD_TYPE_SONY_CT2:
304         case DEMOD_TYPE_SONY_ISDBT:
305         case DEMOD_TYPE_SONY_C2T2:
306         case DEMOD_TYPE_SONY_C2T2I:
307                 return tuner_attach_tda18212(chan, chan->demod_type);
308         case DEMOD_TYPE_STV0910:
309                 return tuner_attach_stv6111(chan);
310         }
311
312         return -EINVAL;
313 }
314
315 static int demod_attach_stv0900(struct ngene_channel *chan)
316 {
317         struct device *pdev = &chan->dev->pci_dev->dev;
318         struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
319         struct stv090x_config *feconf = (struct stv090x_config *)
320                 chan->dev->card_info->fe_config[chan->number];
321
322         /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
323         /* Note: Both adapters share the same i2c bus, but the demod     */
324         /*       driver requires that each demod has its own i2c adapter */
325         if (chan->number < 2)
326                 i2c = &chan->dev->channel[0].i2c_adapter;
327         else
328                 i2c = &chan->dev->channel[1].i2c_adapter;
329
330         chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
331                         (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
332                                                 : STV090x_DEMODULATOR_1);
333         if (chan->fe == NULL) {
334                 dev_err(pdev, "No STV0900 found!\n");
335                 return -ENODEV;
336         }
337
338         /* store channel info */
339         if (feconf->tuner_i2c_lock)
340                 chan->fe->analog_demod_priv = chan;
341
342         if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
343                         0, chan->dev->card_info->lnb[chan->number])) {
344                 dev_err(pdev, "No LNBH24 found!\n");
345                 dvb_frontend_detach(chan->fe);
346                 chan->fe = NULL;
347                 return -ENODEV;
348         }
349
350         return 0;
351 }
352
353 static struct stv0910_cfg stv0910_p = {
354         .adr      = 0x68,
355         .parallel = 1,
356         .rptlvl   = 4,
357         .clk      = 30000000,
358 };
359
360 static struct lnbh25_config lnbh25_cfg = {
361         .i2c_address = 0x0c << 1,
362         .data2_config = LNBH25_TEN
363 };
364
365 static int demod_attach_stv0910(struct ngene_channel *chan,
366                                 struct i2c_adapter *i2c)
367 {
368         struct device *pdev = &chan->dev->pci_dev->dev;
369         struct stv0910_cfg cfg = stv0910_p;
370         struct lnbh25_config lnbcfg = lnbh25_cfg;
371
372         chan->fe = dvb_attach(stv0910_attach, i2c, &cfg, (chan->number & 1));
373         if (!chan->fe) {
374                 cfg.adr = 0x6c;
375                 chan->fe = dvb_attach(stv0910_attach, i2c,
376                                       &cfg, (chan->number & 1));
377         }
378         if (!chan->fe) {
379                 dev_err(pdev, "stv0910_attach() failed!\n");
380                 return -ENODEV;
381         }
382
383         /*
384          * attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
385          * i2c addresses
386          */
387         lnbcfg.i2c_address = (((chan->number & 1) ? 0x0d : 0x0c) << 1);
388         if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
389                 lnbcfg.i2c_address = (((chan->number & 1) ? 0x09 : 0x08) << 1);
390                 if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
391                         dev_err(pdev, "lnbh25_attach() failed!\n");
392                         dvb_frontend_detach(chan->fe);
393                         chan->fe = NULL;
394                         return -ENODEV;
395                 }
396         }
397
398         return 0;
399 }
400
401 static struct stv0367_config ddb_stv0367_config[] = {
402         {
403                 .demod_address = 0x1f,
404                 .xtal = 27000000,
405                 .if_khz = 0,
406                 .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
407                 .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
408                 .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
409         }, {
410                 .demod_address = 0x1e,
411                 .xtal = 27000000,
412                 .if_khz = 0,
413                 .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
414                 .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
415                 .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
416         },
417 };
418
419 static int demod_attach_stv0367(struct ngene_channel *chan,
420                                 struct i2c_adapter *i2c)
421 {
422         struct device *pdev = &chan->dev->pci_dev->dev;
423
424         chan->fe = dvb_attach(stv0367ddb_attach,
425                               &ddb_stv0367_config[(chan->number & 1)], i2c);
426
427         if (!chan->fe) {
428                 dev_err(pdev, "stv0367ddb_attach() failed!\n");
429                 return -ENODEV;
430         }
431
432         chan->fe->sec_priv = chan;
433         chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
434         chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
435         return 0;
436 }
437
438 static int demod_attach_cxd28xx(struct ngene_channel *chan,
439                                 struct i2c_adapter *i2c, int osc24)
440 {
441         struct device *pdev = &chan->dev->pci_dev->dev;
442         struct cxd2841er_config cfg;
443
444         /* the cxd2841er driver expects 8bit/shifted I2C addresses */
445         cfg.i2c_addr = ((chan->number & 1) ? 0x6d : 0x6c) << 1;
446
447         cfg.xtal = osc24 ? SONY_XTAL_24000 : SONY_XTAL_20500;
448         cfg.flags = CXD2841ER_AUTO_IFHZ | CXD2841ER_EARLY_TUNE |
449                 CXD2841ER_NO_WAIT_LOCK | CXD2841ER_NO_AGCNEG |
450                 CXD2841ER_TSBITS | CXD2841ER_TS_SERIAL;
451
452         /* attach frontend */
453         chan->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
454
455         if (!chan->fe) {
456                 dev_err(pdev, "CXD28XX attach failed!\n");
457                 return -ENODEV;
458         }
459
460         chan->fe->sec_priv = chan;
461         chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
462         chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
463         return 0;
464 }
465
466 static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
467 {
468         struct ngene_channel *chan = fe->analog_demod_priv;
469
470         if (lock)
471                 down(&chan->dev->pll_mutex);
472         else
473                 up(&chan->dev->pll_mutex);
474 }
475
476 static int port_has_stv0900(struct i2c_adapter *i2c, int port)
477 {
478         u8 val;
479         if (i2c_read_reg16(i2c, 0x68+port/2, 0xf100, &val) < 0)
480                 return 0;
481         return 1;
482 }
483
484 static int port_has_drxk(struct i2c_adapter *i2c, int port)
485 {
486         u8 val;
487
488         if (i2c_read(i2c, 0x29+port, &val) < 0)
489                 return 0;
490         return 1;
491 }
492
493 static int port_has_stv0367(struct i2c_adapter *i2c)
494 {
495         u8 val;
496
497         if (i2c_read_reg16(i2c, 0x1e, 0xf000, &val) < 0)
498                 return 0;
499         if (val != 0x60)
500                 return 0;
501         if (i2c_read_reg16(i2c, 0x1f, 0xf000, &val) < 0)
502                 return 0;
503         if (val != 0x60)
504                 return 0;
505         return 1;
506 }
507
508 int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type)
509 {
510         u8 val;
511         u8 probe[4] = { 0xe0, 0x00, 0x00, 0x00 }, data[4];
512         struct i2c_msg msgs[2] = {{ .addr = 0x40,  .flags = 0,
513                                     .buf  = probe, .len   = 4 },
514                                   { .addr = 0x40,  .flags = I2C_M_RD,
515                                     .buf  = data,  .len   = 4 } };
516         val = i2c_transfer(i2c, msgs, 2);
517         if (val != 2)
518                 return 0;
519
520         if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43)
521                 *type = 2;
522         else
523                 *type = 1;
524         return 1;
525 }
526
527 static int demod_attach_drxk(struct ngene_channel *chan,
528                              struct i2c_adapter *i2c)
529 {
530         struct device *pdev = &chan->dev->pci_dev->dev;
531         struct drxk_config config;
532
533         memset(&config, 0, sizeof(config));
534         config.microcode_name = "drxk_a3.mc";
535         config.qam_demod_parameter_count = 4;
536         config.adr = 0x29 + (chan->number ^ 2);
537
538         chan->fe = dvb_attach(drxk_attach, &config, i2c);
539         if (!chan->fe) {
540                 dev_err(pdev, "No DRXK found!\n");
541                 return -ENODEV;
542         }
543         chan->fe->sec_priv = chan;
544         chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
545         chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
546         return 0;
547 }
548
549 /****************************************************************************/
550 /* XO2 related lists and functions ******************************************/
551 /****************************************************************************/
552
553 static char *xo2names[] = {
554         "DUAL DVB-S2",
555         "DUAL DVB-C/T/T2",
556         "DUAL DVB-ISDBT",
557         "DUAL DVB-C/C2/T/T2",
558         "DUAL ATSC",
559         "DUAL DVB-C/C2/T/T2/I",
560 };
561
562 static int init_xo2(struct ngene_channel *chan, struct i2c_adapter *i2c)
563 {
564         struct device *pdev = &chan->dev->pci_dev->dev;
565         u8 addr = 0x10;
566         u8 val, data[2];
567         int res;
568
569         res = i2c_read_regs(i2c, addr, 0x04, data, 2);
570         if (res < 0)
571                 return res;
572
573         if (data[0] != 0x01)  {
574                 dev_info(pdev, "Invalid XO2 on channel %d\n", chan->number);
575                 return -1;
576         }
577
578         i2c_read_reg(i2c, addr, 0x08, &val);
579         if (val != 0) {
580                 i2c_write_reg(i2c, addr, 0x08, 0x00);
581                 msleep(100);
582         }
583         /* Enable tuner power, disable pll, reset demods */
584         i2c_write_reg(i2c, addr, 0x08, 0x04);
585         usleep_range(2000, 3000);
586         /* Release demod resets */
587         i2c_write_reg(i2c, addr, 0x08, 0x07);
588
589         /*
590          * speed: 0=55,1=75,2=90,3=104 MBit/s
591          * Note: The ngene hardware must be run at 75 MBit/s compared
592          * to more modern ddbridge hardware which runs at 90 MBit/s,
593          * else there will be issues with the data transport and non-
594          * working secondary/slave demods/tuners.
595          */
596         i2c_write_reg(i2c, addr, 0x09, 1);
597
598         i2c_write_reg(i2c, addr, 0x0a, 0x01);
599         i2c_write_reg(i2c, addr, 0x0b, 0x01);
600
601         usleep_range(2000, 3000);
602         /* Start XO2 PLL */
603         i2c_write_reg(i2c, addr, 0x08, 0x87);
604
605         return 0;
606 }
607
608 static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, u8 *id)
609 {
610         u8 probe[1] = { 0x00 }, data[4];
611         u8 addr = 0x10;
612
613         *type = NGENE_XO2_TYPE_NONE;
614
615         if (i2c_io(i2c, addr, probe, 1, data, 4))
616                 return 0;
617         if (data[0] == 'D' && data[1] == 'F') {
618                 *id = data[2];
619                 *type = NGENE_XO2_TYPE_DUOFLEX;
620                 return 1;
621         }
622         if (data[0] == 'C' && data[1] == 'I') {
623                 *id = data[2];
624                 *type = NGENE_XO2_TYPE_CI;
625                 return 1;
626         }
627         return 0;
628 }
629
630 /****************************************************************************/
631 /* Probing and port/channel handling ****************************************/
632 /****************************************************************************/
633
634 static int cineS2_probe(struct ngene_channel *chan)
635 {
636         struct device *pdev = &chan->dev->pci_dev->dev;
637         struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
638         struct stv090x_config *fe_conf;
639         u8 buf[3];
640         u8 xo2_type, xo2_id, xo2_demodtype;
641         u8 sony_osc24 = 0;
642         struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
643         int rc;
644
645         if (port_has_xo2(i2c, &xo2_type, &xo2_id)) {
646                 xo2_id >>= 2;
647                 dev_dbg(pdev, "XO2 on channel %d (type %d, id %d)\n",
648                         chan->number, xo2_type, xo2_id);
649
650                 switch (xo2_type) {
651                 case NGENE_XO2_TYPE_DUOFLEX:
652                         if (chan->number & 1)
653                                 dev_dbg(pdev,
654                                         "skipping XO2 init on odd channel %d",
655                                         chan->number);
656                         else
657                                 init_xo2(chan, i2c);
658
659                         xo2_demodtype = DEMOD_TYPE_XO2 + xo2_id;
660
661                         switch (xo2_demodtype) {
662                         case DEMOD_TYPE_SONY_CT2:
663                         case DEMOD_TYPE_SONY_ISDBT:
664                         case DEMOD_TYPE_SONY_C2T2:
665                         case DEMOD_TYPE_SONY_C2T2I:
666                                 dev_info(pdev, "%s (XO2) on channel %d\n",
667                                          xo2names[xo2_id], chan->number);
668                                 chan->demod_type = xo2_demodtype;
669                                 if (xo2_demodtype == DEMOD_TYPE_SONY_C2T2I)
670                                         sony_osc24 = 1;
671
672                                 demod_attach_cxd28xx(chan, i2c, sony_osc24);
673                                 break;
674                         case DEMOD_TYPE_STV0910:
675                                 dev_info(pdev, "%s (XO2) on channel %d\n",
676                                          xo2names[xo2_id], chan->number);
677                                 chan->demod_type = xo2_demodtype;
678                                 demod_attach_stv0910(chan, i2c);
679                                 break;
680                         default:
681                                 dev_warn(pdev,
682                                          "Unsupported XO2 module on channel %d\n",
683                                          chan->number);
684                                 return -ENODEV;
685                         }
686                         break;
687                 case NGENE_XO2_TYPE_CI:
688                         dev_info(pdev, "DuoFlex CI modules not supported\n");
689                         return -ENODEV;
690                 default:
691                         dev_info(pdev, "Unsupported XO2 module type\n");
692                         return -ENODEV;
693                 }
694         } else if (port_has_stv0900(i2c, chan->number)) {
695                 chan->demod_type = DEMOD_TYPE_STV090X;
696                 fe_conf = chan->dev->card_info->fe_config[chan->number];
697                 /* demod found, attach it */
698                 rc = demod_attach_stv0900(chan);
699                 if (rc < 0 || chan->number < 2)
700                         return rc;
701
702                 /* demod #2: reprogram outputs DPN1 & DPN2 */
703                 i2c_msg.addr = fe_conf->address;
704                 i2c_msg.len = 3;
705                 buf[0] = 0xf1;
706                 switch (chan->number) {
707                 case 2:
708                         buf[1] = 0x5c;
709                         buf[2] = 0xc2;
710                         break;
711                 case 3:
712                         buf[1] = 0x61;
713                         buf[2] = 0xcc;
714                         break;
715                 default:
716                         return -ENODEV;
717                 }
718                 rc = i2c_transfer(i2c, &i2c_msg, 1);
719                 if (rc != 1) {
720                         dev_err(pdev, "Could not setup DPNx\n");
721                         return -EIO;
722                 }
723         } else if (port_has_drxk(i2c, chan->number^2)) {
724                 chan->demod_type = DEMOD_TYPE_DRXK;
725                 demod_attach_drxk(chan, i2c);
726         } else if (port_has_stv0367(i2c)) {
727                 chan->demod_type = DEMOD_TYPE_STV0367;
728                 dev_info(pdev, "STV0367 on channel %d\n", chan->number);
729                 demod_attach_stv0367(chan, i2c);
730         } else {
731                 dev_info(pdev, "No demod found on chan %d\n", chan->number);
732                 return -ENODEV;
733         }
734         return 0;
735 }
736
737
738 static struct lgdt330x_config aver_m780 = {
739         .demod_address = 0xb2 >> 1,
740         .demod_chip    = LGDT3303,
741         .serial_mpeg   = 0x00, /* PARALLEL */
742         .clock_polarity_flip = 1,
743 };
744
745 static struct mt2131_config m780_tunerconfig = {
746         0xc0 >> 1
747 };
748
749 /* A single func to attach the demo and tuner, rather than
750  * use two sep funcs like the current design mandates.
751  */
752 static int demod_attach_lg330x(struct ngene_channel *chan)
753 {
754         struct device *pdev = &chan->dev->pci_dev->dev;
755
756         chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter);
757         if (chan->fe == NULL) {
758                 dev_err(pdev, "No LGDT330x found!\n");
759                 return -ENODEV;
760         }
761
762         dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
763                    &m780_tunerconfig, 0);
764
765         return (chan->fe) ? 0 : -ENODEV;
766 }
767
768 static int demod_attach_drxd(struct ngene_channel *chan)
769 {
770         struct device *pdev = &chan->dev->pci_dev->dev;
771         struct drxd_config *feconf;
772
773         feconf = chan->dev->card_info->fe_config[chan->number];
774
775         chan->fe = dvb_attach(drxd_attach, feconf, chan,
776                         &chan->i2c_adapter, &chan->dev->pci_dev->dev);
777         if (!chan->fe) {
778                 dev_err(pdev, "No DRXD found!\n");
779                 return -ENODEV;
780         }
781         return 0;
782 }
783
784 static int tuner_attach_dtt7520x(struct ngene_channel *chan)
785 {
786         struct device *pdev = &chan->dev->pci_dev->dev;
787         struct drxd_config *feconf;
788
789         feconf = chan->dev->card_info->fe_config[chan->number];
790
791         if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
792                         &chan->i2c_adapter,
793                         feconf->pll_type)) {
794                 dev_err(pdev, "No pll(%d) found!\n", feconf->pll_type);
795                 return -ENODEV;
796         }
797         return 0;
798 }
799
800 /****************************************************************************/
801 /* EEPROM TAGS **************************************************************/
802 /****************************************************************************/
803
804 #define MICNG_EE_START      0x0100
805 #define MICNG_EE_END        0x0FF0
806
807 #define MICNG_EETAG_END0    0x0000
808 #define MICNG_EETAG_END1    0xFFFF
809
810 /* 0x0001 - 0x000F reserved for housekeeping */
811 /* 0xFFFF - 0xFFFE reserved for housekeeping */
812
813 /* Micronas assigned tags
814    EEProm tags for hardware support */
815
816 #define MICNG_EETAG_DRXD1_OSCDEVIATION  0x1000  /* 2 Bytes data */
817 #define MICNG_EETAG_DRXD2_OSCDEVIATION  0x1001  /* 2 Bytes data */
818
819 #define MICNG_EETAG_MT2060_1_1STIF      0x1100  /* 2 Bytes data */
820 #define MICNG_EETAG_MT2060_2_1STIF      0x1101  /* 2 Bytes data */
821
822 /* Tag range for OEMs */
823
824 #define MICNG_EETAG_OEM_FIRST  0xC000
825 #define MICNG_EETAG_OEM_LAST   0xFFEF
826
827 static int i2c_write_eeprom(struct i2c_adapter *adapter,
828                             u8 adr, u16 reg, u8 data)
829 {
830         struct device *pdev = adapter->dev.parent;
831         u8 m[3] = {(reg >> 8), (reg & 0xff), data};
832         struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m,
833                               .len = sizeof(m)};
834
835         if (i2c_transfer(adapter, &msg, 1) != 1) {
836                 dev_err(pdev, "Error writing EEPROM!\n");
837                 return -EIO;
838         }
839         return 0;
840 }
841
842 static int i2c_read_eeprom(struct i2c_adapter *adapter,
843                            u8 adr, u16 reg, u8 *data, int len)
844 {
845         struct device *pdev = adapter->dev.parent;
846         u8 msg[2] = {(reg >> 8), (reg & 0xff)};
847         struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
848                                    .buf = msg, .len = 2 },
849                                   {.addr = adr, .flags = I2C_M_RD,
850                                    .buf = data, .len = len} };
851
852         if (i2c_transfer(adapter, msgs, 2) != 2) {
853                 dev_err(pdev, "Error reading EEPROM\n");
854                 return -EIO;
855         }
856         return 0;
857 }
858
859 static int ReadEEProm(struct i2c_adapter *adapter,
860                       u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
861 {
862         struct device *pdev = adapter->dev.parent;
863         int status = 0;
864         u16 Addr = MICNG_EE_START, Length, tag = 0;
865         u8  EETag[3];
866
867         while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
868                 if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
869                         return -1;
870                 tag = (EETag[0] << 8) | EETag[1];
871                 if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
872                         return -1;
873                 if (tag == Tag)
874                         break;
875                 Addr += sizeof(u16) + 1 + EETag[2];
876         }
877         if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
878                 dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
879                         tag, EETag[2]);
880                 return -1;
881         }
882         Length = EETag[2];
883         if (Length > MaxLen)
884                 Length = (u16) MaxLen;
885         if (Length > 0) {
886                 Addr += sizeof(u16) + 1;
887                 status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
888                 if (!status) {
889                         *pLength = EETag[2];
890 #if 0
891                         if (Length < EETag[2])
892                                 status = STATUS_BUFFER_OVERFLOW;
893 #endif
894                 }
895         }
896         return status;
897 }
898
899 static int WriteEEProm(struct i2c_adapter *adapter,
900                        u16 Tag, u32 Length, u8 *data)
901 {
902         struct device *pdev = adapter->dev.parent;
903         int status = 0;
904         u16 Addr = MICNG_EE_START;
905         u8 EETag[3];
906         u16 tag = 0;
907         int retry, i;
908
909         while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
910                 if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
911                         return -1;
912                 tag = (EETag[0] << 8) | EETag[1];
913                 if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
914                         return -1;
915                 if (tag == Tag)
916                         break;
917                 Addr += sizeof(u16) + 1 + EETag[2];
918         }
919         if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
920                 dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
921                         tag, EETag[2]);
922                 return -1;
923         }
924
925         if (Length > EETag[2])
926                 return -EINVAL;
927         /* Note: We write the data one byte at a time to avoid
928            issues with page sizes. (which are different for
929            each manufacture and eeprom size)
930          */
931         Addr += sizeof(u16) + 1;
932         for (i = 0; i < Length; i++, Addr++) {
933                 status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
934
935                 if (status)
936                         break;
937
938                 /* Poll for finishing write cycle */
939                 retry = 10;
940                 while (retry) {
941                         u8 Tmp;
942
943                         msleep(50);
944                         status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
945                         if (status)
946                                 break;
947                         if (Tmp != data[i])
948                                 dev_err(pdev, "eeprom write error\n");
949                         retry -= 1;
950                 }
951                 if (status) {
952                         dev_err(pdev, "Timeout polling eeprom\n");
953                         break;
954                 }
955         }
956         return status;
957 }
958
959 static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
960 {
961         int stat;
962         u8 buf[2];
963         u32 len = 0;
964
965         stat = ReadEEProm(adapter, tag, 2, buf, &len);
966         if (stat)
967                 return stat;
968         if (len != 2)
969                 return -EINVAL;
970
971         *data = (buf[0] << 8) | buf[1];
972         return 0;
973 }
974
975 static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
976 {
977         int stat;
978         u8 buf[2];
979
980         buf[0] = data >> 8;
981         buf[1] = data & 0xff;
982         stat = WriteEEProm(adapter, tag, 2, buf);
983         if (stat)
984                 return stat;
985         return 0;
986 }
987
988 static s16 osc_deviation(void *priv, s16 deviation, int flag)
989 {
990         struct ngene_channel *chan = priv;
991         struct device *pdev = &chan->dev->pci_dev->dev;
992         struct i2c_adapter *adap = &chan->i2c_adapter;
993         u16 data = 0;
994
995         if (flag) {
996                 data = (u16) deviation;
997                 dev_info(pdev, "write deviation %d\n",
998                          deviation);
999                 eeprom_write_ushort(adap, 0x1000 + chan->number, data);
1000         } else {
1001                 if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
1002                         data = 0;
1003                 dev_info(pdev, "read deviation %d\n",
1004                          (s16)data);
1005         }
1006
1007         return (s16) data;
1008 }
1009
1010 /****************************************************************************/
1011 /* Switch control (I2C gates, etc.) *****************************************/
1012 /****************************************************************************/
1013
1014
1015 static struct stv090x_config fe_cineS2 = {
1016         .device         = STV0900,
1017         .demod_mode     = STV090x_DUAL,
1018         .clk_mode       = STV090x_CLK_EXT,
1019
1020         .xtal           = 27000000,
1021         .address        = 0x68,
1022
1023         .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
1024         .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
1025
1026         .repeater_level = STV090x_RPTLEVEL_16,
1027
1028         .adc1_range     = STV090x_ADC_1Vpp,
1029         .adc2_range     = STV090x_ADC_1Vpp,
1030
1031         .diseqc_envelope_mode = true,
1032
1033         .tuner_i2c_lock = cineS2_tuner_i2c_lock,
1034 };
1035
1036 static struct stv090x_config fe_cineS2_2 = {
1037         .device         = STV0900,
1038         .demod_mode     = STV090x_DUAL,
1039         .clk_mode       = STV090x_CLK_EXT,
1040
1041         .xtal           = 27000000,
1042         .address        = 0x69,
1043
1044         .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
1045         .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
1046
1047         .repeater_level = STV090x_RPTLEVEL_16,
1048
1049         .adc1_range     = STV090x_ADC_1Vpp,
1050         .adc2_range     = STV090x_ADC_1Vpp,
1051
1052         .diseqc_envelope_mode = true,
1053
1054         .tuner_i2c_lock = cineS2_tuner_i2c_lock,
1055 };
1056
1057 static struct stv6110x_config tuner_cineS2_0 = {
1058         .addr   = 0x60,
1059         .refclk = 27000000,
1060         .clk_div = 1,
1061 };
1062
1063 static struct stv6110x_config tuner_cineS2_1 = {
1064         .addr   = 0x63,
1065         .refclk = 27000000,
1066         .clk_div = 1,
1067 };
1068
1069 static const struct ngene_info ngene_info_cineS2 = {
1070         .type           = NGENE_SIDEWINDER,
1071         .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner",
1072         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1073         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
1074         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
1075         .fe_config      = {&fe_cineS2, &fe_cineS2},
1076         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
1077         .lnb            = {0x0b, 0x08},
1078         .tsf            = {3, 3},
1079         .fw_version     = 18,
1080         .msi_supported  = true,
1081 };
1082
1083 static const struct ngene_info ngene_info_satixS2 = {
1084         .type           = NGENE_SIDEWINDER,
1085         .name           = "Mystique SaTiX-S2 Dual",
1086         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1087         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
1088         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
1089         .fe_config      = {&fe_cineS2, &fe_cineS2},
1090         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
1091         .lnb            = {0x0b, 0x08},
1092         .tsf            = {3, 3},
1093         .fw_version     = 18,
1094         .msi_supported  = true,
1095 };
1096
1097 static const struct ngene_info ngene_info_satixS2v2 = {
1098         .type           = NGENE_SIDEWINDER,
1099         .name           = "Mystique SaTiX-S2 Dual (v2)",
1100         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
1101                            NGENE_IO_TSOUT},
1102         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
1103         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
1104         .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
1105         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
1106         .lnb            = {0x0a, 0x08, 0x0b, 0x09},
1107         .tsf            = {3, 3},
1108         .fw_version     = 18,
1109         .msi_supported  = true,
1110 };
1111
1112 static const struct ngene_info ngene_info_cineS2v5 = {
1113         .type           = NGENE_SIDEWINDER,
1114         .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
1115         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
1116                            NGENE_IO_TSOUT},
1117         .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
1118         .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
1119         .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
1120         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
1121         .lnb            = {0x0a, 0x08, 0x0b, 0x09},
1122         .tsf            = {3, 3},
1123         .fw_version     = 18,
1124         .msi_supported  = true,
1125 };
1126
1127
1128 static const struct ngene_info ngene_info_duoFlex = {
1129         .type           = NGENE_SIDEWINDER,
1130         .name           = "Digital Devices DuoFlex PCIe or miniPCIe",
1131         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
1132                            NGENE_IO_TSOUT},
1133         .demod_attach   = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
1134         .tuner_attach   = {tuner_attach_probe, tuner_attach_probe, tuner_attach_probe, tuner_attach_probe},
1135         .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
1136         .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
1137         .lnb            = {0x0a, 0x08, 0x0b, 0x09},
1138         .tsf            = {3, 3},
1139         .fw_version     = 18,
1140         .msi_supported  = true,
1141 };
1142
1143 static const struct ngene_info ngene_info_m780 = {
1144         .type           = NGENE_APP,
1145         .name           = "Aver M780 ATSC/QAM-B",
1146
1147         /* Channel 0 is analog, which is currently unsupported */
1148         .io_type        = { NGENE_IO_NONE, NGENE_IO_TSIN },
1149         .demod_attach   = { NULL, demod_attach_lg330x },
1150
1151         /* Ensure these are NULL else the frame will call them (as funcs) */
1152         .tuner_attach   = { NULL, NULL, NULL, NULL },
1153         .fe_config      = { NULL, &aver_m780 },
1154         .avf            = { 0 },
1155
1156         /* A custom electrical interface config for the demod to bridge */
1157         .tsf            = { 4, 4 },
1158         .fw_version     = 15,
1159 };
1160
1161 static struct drxd_config fe_terratec_dvbt_0 = {
1162         .index          = 0,
1163         .demod_address  = 0x70,
1164         .demod_revision = 0xa2,
1165         .demoda_address = 0x00,
1166         .pll_address    = 0x60,
1167         .pll_type       = DVB_PLL_THOMSON_DTT7520X,
1168         .clock          = 20000,
1169         .osc_deviation  = osc_deviation,
1170 };
1171
1172 static struct drxd_config fe_terratec_dvbt_1 = {
1173         .index          = 1,
1174         .demod_address  = 0x71,
1175         .demod_revision = 0xa2,
1176         .demoda_address = 0x00,
1177         .pll_address    = 0x60,
1178         .pll_type       = DVB_PLL_THOMSON_DTT7520X,
1179         .clock          = 20000,
1180         .osc_deviation  = osc_deviation,
1181 };
1182
1183 static const struct ngene_info ngene_info_terratec = {
1184         .type           = NGENE_TERRATEC,
1185         .name           = "Terratec Integra/Cinergy2400i Dual DVB-T",
1186         .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1187         .demod_attach   = {demod_attach_drxd, demod_attach_drxd},
1188         .tuner_attach   = {tuner_attach_dtt7520x, tuner_attach_dtt7520x},
1189         .fe_config      = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
1190         .i2c_access     = 1,
1191 };
1192
1193 /****************************************************************************/
1194
1195
1196
1197 /****************************************************************************/
1198 /* PCI Subsystem ID *********************************************************/
1199 /****************************************************************************/
1200
1201 #define NGENE_ID(_subvend, _subdev, _driverdata) { \
1202         .vendor = NGENE_VID, .device = NGENE_PID, \
1203         .subvendor = _subvend, .subdevice = _subdev, \
1204         .driver_data = (unsigned long) &_driverdata }
1205
1206 /****************************************************************************/
1207
1208 static const struct pci_device_id ngene_id_tbl[] = {
1209         NGENE_ID(0x18c3, 0xab04, ngene_info_cineS2),
1210         NGENE_ID(0x18c3, 0xab05, ngene_info_cineS2v5),
1211         NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
1212         NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
1213         NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
1214         NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
1215         NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
1216         NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex),
1217         NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex),
1218         NGENE_ID(0x1461, 0x062e, ngene_info_m780),
1219         NGENE_ID(0x153b, 0x1167, ngene_info_terratec),
1220         {0}
1221 };
1222 MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
1223
1224 /****************************************************************************/
1225 /* Init/Exit ****************************************************************/
1226 /****************************************************************************/
1227
1228 static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
1229                                              enum pci_channel_state state)
1230 {
1231         dev_err(&dev->dev, "PCI error\n");
1232         if (state == pci_channel_io_perm_failure)
1233                 return PCI_ERS_RESULT_DISCONNECT;
1234         if (state == pci_channel_io_frozen)
1235                 return PCI_ERS_RESULT_NEED_RESET;
1236         return PCI_ERS_RESULT_CAN_RECOVER;
1237 }
1238
1239 static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
1240 {
1241         dev_info(&dev->dev, "slot reset\n");
1242         return 0;
1243 }
1244
1245 static void ngene_resume(struct pci_dev *dev)
1246 {
1247         dev_info(&dev->dev, "resume\n");
1248 }
1249
1250 static const struct pci_error_handlers ngene_errors = {
1251         .error_detected = ngene_error_detected,
1252         .slot_reset = ngene_slot_reset,
1253         .resume = ngene_resume,
1254 };
1255
1256 static struct pci_driver ngene_pci_driver = {
1257         .name        = "ngene",
1258         .id_table    = ngene_id_tbl,
1259         .probe       = ngene_probe,
1260         .remove      = ngene_remove,
1261         .err_handler = &ngene_errors,
1262         .shutdown    = ngene_shutdown,
1263 };
1264
1265 static __init int module_init_ngene(void)
1266 {
1267         /* pr_*() since we don't have a device to use with dev_*() yet */
1268         pr_info("nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
1269
1270         return pci_register_driver(&ngene_pci_driver);
1271 }
1272
1273 static __exit void module_exit_ngene(void)
1274 {
1275         pci_unregister_driver(&ngene_pci_driver);
1276 }
1277
1278 module_init(module_init_ngene);
1279 module_exit(module_exit_ngene);
1280
1281 MODULE_DESCRIPTION("nGene");
1282 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
1283 MODULE_LICENSE("GPL");