Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ngene-cards.c: nGene PCIe bridge driver - card specific info
0004  *
0005  * Copyright (C) 2005-2007 Micronas
0006  *
0007  * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
0008  *                         Modifications for new nGene firmware,
0009  *                         support for EEPROM-copying,
0010  *                         support for new dual DVB-S2 card prototype
0011  */
0012 
0013 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0014 
0015 #include <linux/module.h>
0016 #include <linux/init.h>
0017 #include <linux/pci.h>
0018 #include <linux/pci_ids.h>
0019 
0020 #include "ngene.h"
0021 
0022 /* demods/tuners */
0023 #include "stv6110x.h"
0024 #include "stv090x.h"
0025 #include "lnbh24.h"
0026 #include "lgdt330x.h"
0027 #include "mt2131.h"
0028 #include "tda18271c2dd.h"
0029 #include "drxk.h"
0030 #include "drxd.h"
0031 #include "dvb-pll.h"
0032 #include "stv0367.h"
0033 #include "stv0367_priv.h"
0034 #include "tda18212.h"
0035 #include "cxd2841er.h"
0036 #include "stv0910.h"
0037 #include "stv6111.h"
0038 #include "lnbh25.h"
0039 
0040 /****************************************************************************/
0041 /* I2C transfer functions used for demod/tuner probing***********************/
0042 /****************************************************************************/
0043 
0044 static int i2c_io(struct i2c_adapter *adapter, u8 adr,
0045           u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
0046 {
0047     struct i2c_msg msgs[2] = {{.addr = adr,  .flags = 0,
0048                    .buf  = wbuf, .len   = wlen },
0049                   {.addr = adr,  .flags = I2C_M_RD,
0050                    .buf  = rbuf,  .len   = rlen } };
0051     return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
0052 }
0053 
0054 static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
0055 {
0056     struct i2c_msg msg = {.addr = adr, .flags = 0,
0057                   .buf = data, .len = len};
0058 
0059     return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
0060 }
0061 
0062 static int i2c_write_reg(struct i2c_adapter *adap, u8 adr,
0063              u8 reg, u8 val)
0064 {
0065     u8 msg[2] = {reg, val};
0066 
0067     return i2c_write(adap, adr, msg, 2);
0068 }
0069 
0070 static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
0071 {
0072     struct i2c_msg msgs[1] = {{.addr = adr,  .flags = I2C_M_RD,
0073                    .buf  = val,  .len   = 1 } };
0074     return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
0075 }
0076 
0077 static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
0078               u16 reg, u8 *val)
0079 {
0080     u8 msg[2] = {reg >> 8, reg & 0xff};
0081     struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
0082                    .buf  = msg, .len   = 2},
0083                   {.addr = adr, .flags = I2C_M_RD,
0084                    .buf  = val, .len   = 1} };
0085     return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
0086 }
0087 
0088 static int i2c_read_regs(struct i2c_adapter *adapter,
0089              u8 adr, u8 reg, u8 *val, u8 len)
0090 {
0091     struct i2c_msg msgs[2] = {{.addr = adr,  .flags = 0,
0092                    .buf  = &reg, .len   = 1},
0093                   {.addr = adr,  .flags = I2C_M_RD,
0094                    .buf  = val,  .len   = len} };
0095 
0096     return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
0097 }
0098 
0099 static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, u8 reg, u8 *val)
0100 {
0101     return i2c_read_regs(adapter, adr, reg, val, 1);
0102 }
0103 
0104 /****************************************************************************/
0105 /* Demod/tuner attachment ***************************************************/
0106 /****************************************************************************/
0107 
0108 static struct i2c_adapter *i2c_adapter_from_chan(struct ngene_channel *chan)
0109 {
0110     /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
0111     if (chan->number < 2)
0112         return &chan->dev->channel[0].i2c_adapter;
0113 
0114     return &chan->dev->channel[1].i2c_adapter;
0115 }
0116 
0117 static int tuner_attach_stv6110(struct ngene_channel *chan)
0118 {
0119     struct device *pdev = &chan->dev->pci_dev->dev;
0120     struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
0121     struct stv090x_config *feconf = (struct stv090x_config *)
0122         chan->dev->card_info->fe_config[chan->number];
0123     struct stv6110x_config *tunerconf = (struct stv6110x_config *)
0124         chan->dev->card_info->tuner_config[chan->number];
0125     const struct stv6110x_devctl *ctl;
0126 
0127     ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
0128     if (ctl == NULL) {
0129         dev_err(pdev, "No STV6110X found!\n");
0130         return -ENODEV;
0131     }
0132 
0133     feconf->tuner_init          = ctl->tuner_init;
0134     feconf->tuner_sleep         = ctl->tuner_sleep;
0135     feconf->tuner_set_mode      = ctl->tuner_set_mode;
0136     feconf->tuner_set_frequency = ctl->tuner_set_frequency;
0137     feconf->tuner_get_frequency = ctl->tuner_get_frequency;
0138     feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
0139     feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
0140     feconf->tuner_set_bbgain    = ctl->tuner_set_bbgain;
0141     feconf->tuner_get_bbgain    = ctl->tuner_get_bbgain;
0142     feconf->tuner_set_refclk    = ctl->tuner_set_refclk;
0143     feconf->tuner_get_status    = ctl->tuner_get_status;
0144 
0145     return 0;
0146 }
0147 
0148 static int tuner_attach_stv6111(struct ngene_channel *chan)
0149 {
0150     struct device *pdev = &chan->dev->pci_dev->dev;
0151     struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
0152     struct dvb_frontend *fe;
0153     u8 adr = 4 + ((chan->number & 1) ? 0x63 : 0x60);
0154 
0155     fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr);
0156     if (!fe) {
0157         fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4);
0158         if (!fe) {
0159             dev_err(pdev, "stv6111_attach() failed!\n");
0160             return -ENODEV;
0161         }
0162     }
0163     return 0;
0164 }
0165 
0166 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
0167 {
0168     struct ngene_channel *chan = fe->sec_priv;
0169     int status;
0170 
0171     if (enable) {
0172         down(&chan->dev->pll_mutex);
0173         status = chan->gate_ctrl(fe, 1);
0174     } else {
0175         status = chan->gate_ctrl(fe, 0);
0176         up(&chan->dev->pll_mutex);
0177     }
0178     return status;
0179 }
0180 
0181 static int tuner_attach_tda18271(struct ngene_channel *chan)
0182 {
0183     struct device *pdev = &chan->dev->pci_dev->dev;
0184     struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
0185     struct dvb_frontend *fe;
0186 
0187     if (chan->fe->ops.i2c_gate_ctrl)
0188         chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
0189     fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60);
0190     if (chan->fe->ops.i2c_gate_ctrl)
0191         chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
0192     if (!fe) {
0193         dev_err(pdev, "No TDA18271 found!\n");
0194         return -ENODEV;
0195     }
0196 
0197     return 0;
0198 }
0199 
0200 static int tuner_tda18212_ping(struct ngene_channel *chan,
0201                    struct i2c_adapter *i2c,
0202                    unsigned short adr)
0203 {
0204     struct device *pdev = &chan->dev->pci_dev->dev;
0205     u8 tda_id[2];
0206     u8 subaddr = 0x00;
0207 
0208     dev_dbg(pdev, "stv0367-tda18212 tuner ping\n");
0209     if (chan->fe->ops.i2c_gate_ctrl)
0210         chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
0211 
0212     if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
0213         dev_dbg(pdev, "tda18212 ping 1 fail\n");
0214     if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
0215         dev_warn(pdev, "tda18212 ping failed, expect problems\n");
0216 
0217     if (chan->fe->ops.i2c_gate_ctrl)
0218         chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
0219 
0220     return 0;
0221 }
0222 
0223 static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
0224 {
0225     struct device *pdev = &chan->dev->pci_dev->dev;
0226     struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
0227     struct i2c_client *client;
0228     struct tda18212_config config = {
0229         .fe = chan->fe,
0230         .if_dvbt_6 = 3550,
0231         .if_dvbt_7 = 3700,
0232         .if_dvbt_8 = 4150,
0233         .if_dvbt2_6 = 3250,
0234         .if_dvbt2_7 = 4000,
0235         .if_dvbt2_8 = 4000,
0236         .if_dvbc = 5000,
0237     };
0238     u8 addr = (chan->number & 1) ? 0x63 : 0x60;
0239 
0240     /*
0241      * due to a hardware quirk with the I2C gate on the stv0367+tda18212
0242      * combo, the tda18212 must be probed by reading it's id _twice_ when
0243      * cold started, or it very likely will fail.
0244      */
0245     if (dmdtype == DEMOD_TYPE_STV0367)
0246         tuner_tda18212_ping(chan, i2c, addr);
0247 
0248     /* perform tuner probe/init/attach */
0249     client = dvb_module_probe("tda18212", NULL, i2c, addr, &config);
0250     if (!client)
0251         goto err;
0252 
0253     chan->i2c_client[0] = client;
0254     chan->i2c_client_fe = 1;
0255 
0256     return 0;
0257 err:
0258     dev_err(pdev, "TDA18212 tuner not found. Device is not fully operational.\n");
0259     return -ENODEV;
0260 }
0261 
0262 static int tuner_attach_probe(struct ngene_channel *chan)
0263 {
0264     switch (chan->demod_type) {
0265     case DEMOD_TYPE_STV090X:
0266         return tuner_attach_stv6110(chan);
0267     case DEMOD_TYPE_DRXK:
0268         return tuner_attach_tda18271(chan);
0269     case DEMOD_TYPE_STV0367:
0270     case DEMOD_TYPE_SONY_CT2:
0271     case DEMOD_TYPE_SONY_ISDBT:
0272     case DEMOD_TYPE_SONY_C2T2:
0273     case DEMOD_TYPE_SONY_C2T2I:
0274         return tuner_attach_tda18212(chan, chan->demod_type);
0275     case DEMOD_TYPE_STV0910:
0276         return tuner_attach_stv6111(chan);
0277     }
0278 
0279     return -EINVAL;
0280 }
0281 
0282 static int demod_attach_stv0900(struct ngene_channel *chan)
0283 {
0284     struct device *pdev = &chan->dev->pci_dev->dev;
0285     struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
0286     struct stv090x_config *feconf = (struct stv090x_config *)
0287         chan->dev->card_info->fe_config[chan->number];
0288 
0289     chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
0290             (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
0291                         : STV090x_DEMODULATOR_1);
0292     if (chan->fe == NULL) {
0293         dev_err(pdev, "No STV0900 found!\n");
0294         return -ENODEV;
0295     }
0296 
0297     /* store channel info */
0298     if (feconf->tuner_i2c_lock)
0299         chan->fe->analog_demod_priv = chan;
0300 
0301     if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
0302             0, chan->dev->card_info->lnb[chan->number])) {
0303         dev_err(pdev, "No LNBH24 found!\n");
0304         dvb_frontend_detach(chan->fe);
0305         chan->fe = NULL;
0306         return -ENODEV;
0307     }
0308 
0309     return 0;
0310 }
0311 
0312 static struct stv0910_cfg stv0910_p = {
0313     .adr      = 0x68,
0314     .parallel = 1,
0315     .rptlvl   = 4,
0316     .clk      = 30000000,
0317     .tsspeed  = 0x28,
0318 };
0319 
0320 static struct lnbh25_config lnbh25_cfg = {
0321     .i2c_address = 0x0c << 1,
0322     .data2_config = LNBH25_TEN
0323 };
0324 
0325 static int demod_attach_stv0910(struct ngene_channel *chan,
0326                 struct i2c_adapter *i2c)
0327 {
0328     struct device *pdev = &chan->dev->pci_dev->dev;
0329     struct stv0910_cfg cfg = stv0910_p;
0330     struct lnbh25_config lnbcfg = lnbh25_cfg;
0331 
0332     chan->fe = dvb_attach(stv0910_attach, i2c, &cfg, (chan->number & 1));
0333     if (!chan->fe) {
0334         cfg.adr = 0x6c;
0335         chan->fe = dvb_attach(stv0910_attach, i2c,
0336                       &cfg, (chan->number & 1));
0337     }
0338     if (!chan->fe) {
0339         dev_err(pdev, "stv0910_attach() failed!\n");
0340         return -ENODEV;
0341     }
0342 
0343     /*
0344      * attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
0345      * i2c addresses
0346      */
0347     lnbcfg.i2c_address = (((chan->number & 1) ? 0x0d : 0x0c) << 1);
0348     if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
0349         lnbcfg.i2c_address = (((chan->number & 1) ? 0x09 : 0x08) << 1);
0350         if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
0351             dev_err(pdev, "lnbh25_attach() failed!\n");
0352             dvb_frontend_detach(chan->fe);
0353             chan->fe = NULL;
0354             return -ENODEV;
0355         }
0356     }
0357 
0358     return 0;
0359 }
0360 
0361 static struct stv0367_config ddb_stv0367_config[] = {
0362     {
0363         .demod_address = 0x1f,
0364         .xtal = 27000000,
0365         .if_khz = 0,
0366         .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
0367         .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
0368         .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
0369     }, {
0370         .demod_address = 0x1e,
0371         .xtal = 27000000,
0372         .if_khz = 0,
0373         .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
0374         .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
0375         .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
0376     },
0377 };
0378 
0379 static int demod_attach_stv0367(struct ngene_channel *chan,
0380                 struct i2c_adapter *i2c)
0381 {
0382     struct device *pdev = &chan->dev->pci_dev->dev;
0383 
0384     chan->fe = dvb_attach(stv0367ddb_attach,
0385                   &ddb_stv0367_config[(chan->number & 1)], i2c);
0386 
0387     if (!chan->fe) {
0388         dev_err(pdev, "stv0367ddb_attach() failed!\n");
0389         return -ENODEV;
0390     }
0391 
0392     chan->fe->sec_priv = chan;
0393     chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
0394     chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
0395     return 0;
0396 }
0397 
0398 static int demod_attach_cxd28xx(struct ngene_channel *chan,
0399                 struct i2c_adapter *i2c, int osc24)
0400 {
0401     struct device *pdev = &chan->dev->pci_dev->dev;
0402     struct cxd2841er_config cfg;
0403 
0404     /* the cxd2841er driver expects 8bit/shifted I2C addresses */
0405     cfg.i2c_addr = ((chan->number & 1) ? 0x6d : 0x6c) << 1;
0406 
0407     cfg.xtal = osc24 ? SONY_XTAL_24000 : SONY_XTAL_20500;
0408     cfg.flags = CXD2841ER_AUTO_IFHZ | CXD2841ER_EARLY_TUNE |
0409         CXD2841ER_NO_WAIT_LOCK | CXD2841ER_NO_AGCNEG |
0410         CXD2841ER_TSBITS | CXD2841ER_TS_SERIAL;
0411 
0412     /* attach frontend */
0413     chan->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
0414 
0415     if (!chan->fe) {
0416         dev_err(pdev, "CXD28XX attach failed!\n");
0417         return -ENODEV;
0418     }
0419 
0420     chan->fe->sec_priv = chan;
0421     chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
0422     chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
0423     return 0;
0424 }
0425 
0426 static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
0427 {
0428     struct ngene_channel *chan = fe->analog_demod_priv;
0429 
0430     if (lock)
0431         down(&chan->dev->pll_mutex);
0432     else
0433         up(&chan->dev->pll_mutex);
0434 }
0435 
0436 static int port_has_stv0900(struct i2c_adapter *i2c, int port)
0437 {
0438     u8 val;
0439     if (i2c_read_reg16(i2c, 0x68+port/2, 0xf100, &val) < 0)
0440         return 0;
0441     return 1;
0442 }
0443 
0444 static int port_has_drxk(struct i2c_adapter *i2c, int port)
0445 {
0446     u8 val;
0447 
0448     if (i2c_read(i2c, 0x29+port, &val) < 0)
0449         return 0;
0450     return 1;
0451 }
0452 
0453 static int port_has_stv0367(struct i2c_adapter *i2c)
0454 {
0455     u8 val;
0456 
0457     if (i2c_read_reg16(i2c, 0x1e, 0xf000, &val) < 0)
0458         return 0;
0459     if (val != 0x60)
0460         return 0;
0461     if (i2c_read_reg16(i2c, 0x1f, 0xf000, &val) < 0)
0462         return 0;
0463     if (val != 0x60)
0464         return 0;
0465     return 1;
0466 }
0467 
0468 int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type)
0469 {
0470     u8 val;
0471     u8 probe[4] = { 0xe0, 0x00, 0x00, 0x00 }, data[4];
0472     struct i2c_msg msgs[2] = {{ .addr = 0x40,  .flags = 0,
0473                     .buf  = probe, .len   = 4 },
0474                   { .addr = 0x40,  .flags = I2C_M_RD,
0475                     .buf  = data,  .len   = 4 } };
0476     val = i2c_transfer(i2c, msgs, 2);
0477     if (val != 2)
0478         return 0;
0479 
0480     if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43)
0481         *type = 2;
0482     else
0483         *type = 1;
0484     return 1;
0485 }
0486 
0487 static int demod_attach_drxk(struct ngene_channel *chan,
0488                  struct i2c_adapter *i2c)
0489 {
0490     struct device *pdev = &chan->dev->pci_dev->dev;
0491     struct drxk_config config;
0492 
0493     memset(&config, 0, sizeof(config));
0494     config.microcode_name = "drxk_a3.mc";
0495     config.qam_demod_parameter_count = 4;
0496     config.adr = 0x29 + (chan->number ^ 2);
0497 
0498     chan->fe = dvb_attach(drxk_attach, &config, i2c);
0499     if (!chan->fe) {
0500         dev_err(pdev, "No DRXK found!\n");
0501         return -ENODEV;
0502     }
0503     chan->fe->sec_priv = chan;
0504     chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
0505     chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
0506     return 0;
0507 }
0508 
0509 /****************************************************************************/
0510 /* XO2 related lists and functions ******************************************/
0511 /****************************************************************************/
0512 
0513 static char *xo2names[] = {
0514     "DUAL DVB-S2",
0515     "DUAL DVB-C/T/T2",
0516     "DUAL DVB-ISDBT",
0517     "DUAL DVB-C/C2/T/T2",
0518     "DUAL ATSC",
0519     "DUAL DVB-C/C2/T/T2/I",
0520 };
0521 
0522 static int init_xo2(struct ngene_channel *chan, struct i2c_adapter *i2c)
0523 {
0524     struct device *pdev = &chan->dev->pci_dev->dev;
0525     u8 addr = 0x10;
0526     u8 val, data[2];
0527     int res;
0528 
0529     res = i2c_read_regs(i2c, addr, 0x04, data, 2);
0530     if (res < 0)
0531         return res;
0532 
0533     if (data[0] != 0x01)  {
0534         dev_info(pdev, "Invalid XO2 on channel %d\n", chan->number);
0535         return -1;
0536     }
0537 
0538     i2c_read_reg(i2c, addr, 0x08, &val);
0539     if (val != 0) {
0540         i2c_write_reg(i2c, addr, 0x08, 0x00);
0541         msleep(100);
0542     }
0543     /* Enable tuner power, disable pll, reset demods */
0544     i2c_write_reg(i2c, addr, 0x08, 0x04);
0545     usleep_range(2000, 3000);
0546     /* Release demod resets */
0547     i2c_write_reg(i2c, addr, 0x08, 0x07);
0548 
0549     /*
0550      * speed: 0=55,1=75,2=90,3=104 MBit/s
0551      * Note: The ngene hardware must be run at 75 MBit/s compared
0552      * to more modern ddbridge hardware which runs at 90 MBit/s,
0553      * else there will be issues with the data transport and non-
0554      * working secondary/slave demods/tuners.
0555      */
0556     i2c_write_reg(i2c, addr, 0x09, 1);
0557 
0558     i2c_write_reg(i2c, addr, 0x0a, 0x01);
0559     i2c_write_reg(i2c, addr, 0x0b, 0x01);
0560 
0561     usleep_range(2000, 3000);
0562     /* Start XO2 PLL */
0563     i2c_write_reg(i2c, addr, 0x08, 0x87);
0564 
0565     return 0;
0566 }
0567 
0568 static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, u8 *id)
0569 {
0570     u8 probe[1] = { 0x00 }, data[4];
0571     u8 addr = 0x10;
0572 
0573     *type = NGENE_XO2_TYPE_NONE;
0574 
0575     if (i2c_io(i2c, addr, probe, 1, data, 4))
0576         return 0;
0577     if (data[0] == 'D' && data[1] == 'F') {
0578         *id = data[2];
0579         *type = NGENE_XO2_TYPE_DUOFLEX;
0580         return 1;
0581     }
0582     if (data[0] == 'C' && data[1] == 'I') {
0583         *id = data[2];
0584         *type = NGENE_XO2_TYPE_CI;
0585         return 1;
0586     }
0587     return 0;
0588 }
0589 
0590 /****************************************************************************/
0591 /* Probing and port/channel handling ****************************************/
0592 /****************************************************************************/
0593 
0594 static int cineS2_probe(struct ngene_channel *chan)
0595 {
0596     struct device *pdev = &chan->dev->pci_dev->dev;
0597     struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
0598     struct stv090x_config *fe_conf;
0599     u8 buf[3];
0600     u8 xo2_type, xo2_id, xo2_demodtype;
0601     u8 sony_osc24 = 0;
0602     struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
0603     int rc;
0604 
0605     if (port_has_xo2(i2c, &xo2_type, &xo2_id)) {
0606         xo2_id >>= 2;
0607         dev_dbg(pdev, "XO2 on channel %d (type %d, id %d)\n",
0608             chan->number, xo2_type, xo2_id);
0609 
0610         switch (xo2_type) {
0611         case NGENE_XO2_TYPE_DUOFLEX:
0612             if (chan->number & 1)
0613                 dev_dbg(pdev,
0614                     "skipping XO2 init on odd channel %d",
0615                     chan->number);
0616             else
0617                 init_xo2(chan, i2c);
0618 
0619             xo2_demodtype = DEMOD_TYPE_XO2 + xo2_id;
0620 
0621             switch (xo2_demodtype) {
0622             case DEMOD_TYPE_SONY_CT2:
0623             case DEMOD_TYPE_SONY_ISDBT:
0624             case DEMOD_TYPE_SONY_C2T2:
0625             case DEMOD_TYPE_SONY_C2T2I:
0626                 dev_info(pdev, "%s (XO2) on channel %d\n",
0627                      xo2names[xo2_id], chan->number);
0628                 chan->demod_type = xo2_demodtype;
0629                 if (xo2_demodtype == DEMOD_TYPE_SONY_C2T2I)
0630                     sony_osc24 = 1;
0631 
0632                 demod_attach_cxd28xx(chan, i2c, sony_osc24);
0633                 break;
0634             case DEMOD_TYPE_STV0910:
0635                 dev_info(pdev, "%s (XO2) on channel %d\n",
0636                      xo2names[xo2_id], chan->number);
0637                 chan->demod_type = xo2_demodtype;
0638                 demod_attach_stv0910(chan, i2c);
0639                 break;
0640             default:
0641                 dev_warn(pdev,
0642                      "Unsupported XO2 module on channel %d\n",
0643                      chan->number);
0644                 return -ENODEV;
0645             }
0646             break;
0647         case NGENE_XO2_TYPE_CI:
0648             dev_info(pdev, "DuoFlex CI modules not supported\n");
0649             return -ENODEV;
0650         default:
0651             dev_info(pdev, "Unsupported XO2 module type\n");
0652             return -ENODEV;
0653         }
0654     } else if (port_has_stv0900(i2c, chan->number)) {
0655         chan->demod_type = DEMOD_TYPE_STV090X;
0656         fe_conf = chan->dev->card_info->fe_config[chan->number];
0657         /* demod found, attach it */
0658         rc = demod_attach_stv0900(chan);
0659         if (rc < 0 || chan->number < 2)
0660             return rc;
0661 
0662         /* demod #2: reprogram outputs DPN1 & DPN2 */
0663         i2c_msg.addr = fe_conf->address;
0664         i2c_msg.len = 3;
0665         buf[0] = 0xf1;
0666         switch (chan->number) {
0667         case 2:
0668             buf[1] = 0x5c;
0669             buf[2] = 0xc2;
0670             break;
0671         case 3:
0672             buf[1] = 0x61;
0673             buf[2] = 0xcc;
0674             break;
0675         default:
0676             return -ENODEV;
0677         }
0678         rc = i2c_transfer(i2c, &i2c_msg, 1);
0679         if (rc != 1) {
0680             dev_err(pdev, "Could not setup DPNx\n");
0681             return -EIO;
0682         }
0683     } else if (port_has_drxk(i2c, chan->number^2)) {
0684         chan->demod_type = DEMOD_TYPE_DRXK;
0685         demod_attach_drxk(chan, i2c);
0686     } else if (port_has_stv0367(i2c)) {
0687         chan->demod_type = DEMOD_TYPE_STV0367;
0688         dev_info(pdev, "STV0367 on channel %d\n", chan->number);
0689         demod_attach_stv0367(chan, i2c);
0690     } else {
0691         dev_info(pdev, "No demod found on chan %d\n", chan->number);
0692         return -ENODEV;
0693     }
0694     return 0;
0695 }
0696 
0697 
0698 static struct lgdt330x_config aver_m780 = {
0699     .demod_chip    = LGDT3303,
0700     .serial_mpeg   = 0x00, /* PARALLEL */
0701     .clock_polarity_flip = 1,
0702 };
0703 
0704 static struct mt2131_config m780_tunerconfig = {
0705     0xc0 >> 1
0706 };
0707 
0708 /* A single func to attach the demo and tuner, rather than
0709  * use two sep funcs like the current design mandates.
0710  */
0711 static int demod_attach_lg330x(struct ngene_channel *chan)
0712 {
0713     struct device *pdev = &chan->dev->pci_dev->dev;
0714 
0715     chan->fe = dvb_attach(lgdt330x_attach, &aver_m780,
0716                   0xb2 >> 1, &chan->i2c_adapter);
0717     if (chan->fe == NULL) {
0718         dev_err(pdev, "No LGDT330x found!\n");
0719         return -ENODEV;
0720     }
0721 
0722     dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
0723            &m780_tunerconfig, 0);
0724 
0725     return (chan->fe) ? 0 : -ENODEV;
0726 }
0727 
0728 static int demod_attach_drxd(struct ngene_channel *chan)
0729 {
0730     struct device *pdev = &chan->dev->pci_dev->dev;
0731     struct drxd_config *feconf;
0732 
0733     feconf = chan->dev->card_info->fe_config[chan->number];
0734 
0735     chan->fe = dvb_attach(drxd_attach, feconf, chan,
0736             &chan->i2c_adapter, &chan->dev->pci_dev->dev);
0737     if (!chan->fe) {
0738         dev_err(pdev, "No DRXD found!\n");
0739         return -ENODEV;
0740     }
0741     return 0;
0742 }
0743 
0744 static int tuner_attach_dtt7520x(struct ngene_channel *chan)
0745 {
0746     struct device *pdev = &chan->dev->pci_dev->dev;
0747     struct drxd_config *feconf;
0748 
0749     feconf = chan->dev->card_info->fe_config[chan->number];
0750 
0751     if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
0752             &chan->i2c_adapter,
0753             feconf->pll_type)) {
0754         dev_err(pdev, "No pll(%d) found!\n", feconf->pll_type);
0755         return -ENODEV;
0756     }
0757     return 0;
0758 }
0759 
0760 /****************************************************************************/
0761 /* EEPROM TAGS **************************************************************/
0762 /****************************************************************************/
0763 
0764 #define MICNG_EE_START      0x0100
0765 #define MICNG_EE_END        0x0FF0
0766 
0767 #define MICNG_EETAG_END0    0x0000
0768 #define MICNG_EETAG_END1    0xFFFF
0769 
0770 /* 0x0001 - 0x000F reserved for housekeeping */
0771 /* 0xFFFF - 0xFFFE reserved for housekeeping */
0772 
0773 /* Micronas assigned tags
0774    EEProm tags for hardware support */
0775 
0776 #define MICNG_EETAG_DRXD1_OSCDEVIATION  0x1000  /* 2 Bytes data */
0777 #define MICNG_EETAG_DRXD2_OSCDEVIATION  0x1001  /* 2 Bytes data */
0778 
0779 #define MICNG_EETAG_MT2060_1_1STIF      0x1100  /* 2 Bytes data */
0780 #define MICNG_EETAG_MT2060_2_1STIF      0x1101  /* 2 Bytes data */
0781 
0782 /* Tag range for OEMs */
0783 
0784 #define MICNG_EETAG_OEM_FIRST  0xC000
0785 #define MICNG_EETAG_OEM_LAST   0xFFEF
0786 
0787 static int i2c_write_eeprom(struct i2c_adapter *adapter,
0788                 u8 adr, u16 reg, u8 data)
0789 {
0790     struct device *pdev = adapter->dev.parent;
0791     u8 m[3] = {(reg >> 8), (reg & 0xff), data};
0792     struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m,
0793                   .len = sizeof(m)};
0794 
0795     if (i2c_transfer(adapter, &msg, 1) != 1) {
0796         dev_err(pdev, "Error writing EEPROM!\n");
0797         return -EIO;
0798     }
0799     return 0;
0800 }
0801 
0802 static int i2c_read_eeprom(struct i2c_adapter *adapter,
0803                u8 adr, u16 reg, u8 *data, int len)
0804 {
0805     struct device *pdev = adapter->dev.parent;
0806     u8 msg[2] = {(reg >> 8), (reg & 0xff)};
0807     struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
0808                    .buf = msg, .len = 2 },
0809                   {.addr = adr, .flags = I2C_M_RD,
0810                    .buf = data, .len = len} };
0811 
0812     if (i2c_transfer(adapter, msgs, 2) != 2) {
0813         dev_err(pdev, "Error reading EEPROM\n");
0814         return -EIO;
0815     }
0816     return 0;
0817 }
0818 
0819 static int ReadEEProm(struct i2c_adapter *adapter,
0820               u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
0821 {
0822     struct device *pdev = adapter->dev.parent;
0823     int status = 0;
0824     u16 Addr = MICNG_EE_START, Length, tag = 0;
0825     u8  EETag[3];
0826 
0827     while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
0828         if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
0829             return -1;
0830         tag = (EETag[0] << 8) | EETag[1];
0831         if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
0832             return -1;
0833         if (tag == Tag)
0834             break;
0835         Addr += sizeof(u16) + 1 + EETag[2];
0836     }
0837     if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
0838         dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
0839             tag, EETag[2]);
0840         return -1;
0841     }
0842     Length = EETag[2];
0843     if (Length > MaxLen)
0844         Length = (u16) MaxLen;
0845     if (Length > 0) {
0846         Addr += sizeof(u16) + 1;
0847         status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
0848         if (!status) {
0849             *pLength = EETag[2];
0850 #if 0
0851             if (Length < EETag[2])
0852                 status = STATUS_BUFFER_OVERFLOW;
0853 #endif
0854         }
0855     }
0856     return status;
0857 }
0858 
0859 static int WriteEEProm(struct i2c_adapter *adapter,
0860                u16 Tag, u32 Length, u8 *data)
0861 {
0862     struct device *pdev = adapter->dev.parent;
0863     int status = 0;
0864     u16 Addr = MICNG_EE_START;
0865     u8 EETag[3];
0866     u16 tag = 0;
0867     int retry, i;
0868 
0869     while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
0870         if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
0871             return -1;
0872         tag = (EETag[0] << 8) | EETag[1];
0873         if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
0874             return -1;
0875         if (tag == Tag)
0876             break;
0877         Addr += sizeof(u16) + 1 + EETag[2];
0878     }
0879     if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
0880         dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
0881             tag, EETag[2]);
0882         return -1;
0883     }
0884 
0885     if (Length > EETag[2])
0886         return -EINVAL;
0887     /* Note: We write the data one byte at a time to avoid
0888        issues with page sizes. (which are different for
0889        each manufacture and eeprom size)
0890      */
0891     Addr += sizeof(u16) + 1;
0892     for (i = 0; i < Length; i++, Addr++) {
0893         status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
0894 
0895         if (status)
0896             break;
0897 
0898         /* Poll for finishing write cycle */
0899         retry = 10;
0900         while (retry) {
0901             u8 Tmp;
0902 
0903             msleep(50);
0904             status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
0905             if (status)
0906                 break;
0907             if (Tmp != data[i])
0908                 dev_err(pdev, "eeprom write error\n");
0909             retry -= 1;
0910         }
0911         if (status) {
0912             dev_err(pdev, "Timeout polling eeprom\n");
0913             break;
0914         }
0915     }
0916     return status;
0917 }
0918 
0919 static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
0920 {
0921     int stat;
0922     u8 buf[2];
0923     u32 len = 0;
0924 
0925     stat = ReadEEProm(adapter, tag, 2, buf, &len);
0926     if (stat)
0927         return stat;
0928     if (len != 2)
0929         return -EINVAL;
0930 
0931     *data = (buf[0] << 8) | buf[1];
0932     return 0;
0933 }
0934 
0935 static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
0936 {
0937     u8 buf[2];
0938 
0939     buf[0] = data >> 8;
0940     buf[1] = data & 0xff;
0941     return WriteEEProm(adapter, tag, 2, buf);
0942 }
0943 
0944 static s16 osc_deviation(void *priv, s16 deviation, int flag)
0945 {
0946     struct ngene_channel *chan = priv;
0947     struct device *pdev = &chan->dev->pci_dev->dev;
0948     struct i2c_adapter *adap = &chan->i2c_adapter;
0949     u16 data = 0;
0950 
0951     if (flag) {
0952         data = (u16) deviation;
0953         dev_info(pdev, "write deviation %d\n",
0954              deviation);
0955         eeprom_write_ushort(adap, 0x1000 + chan->number, data);
0956     } else {
0957         if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
0958             data = 0;
0959         dev_info(pdev, "read deviation %d\n",
0960              (s16)data);
0961     }
0962 
0963     return (s16) data;
0964 }
0965 
0966 /****************************************************************************/
0967 /* Switch control (I2C gates, etc.) *****************************************/
0968 /****************************************************************************/
0969 
0970 
0971 static struct stv090x_config fe_cineS2 = {
0972     .device         = STV0900,
0973     .demod_mode     = STV090x_DUAL,
0974     .clk_mode       = STV090x_CLK_EXT,
0975 
0976     .xtal           = 27000000,
0977     .address        = 0x68,
0978 
0979     .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
0980     .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
0981 
0982     .repeater_level = STV090x_RPTLEVEL_16,
0983 
0984     .adc1_range = STV090x_ADC_1Vpp,
0985     .adc2_range = STV090x_ADC_1Vpp,
0986 
0987     .diseqc_envelope_mode = true,
0988 
0989     .tuner_i2c_lock = cineS2_tuner_i2c_lock,
0990 };
0991 
0992 static struct stv090x_config fe_cineS2_2 = {
0993     .device         = STV0900,
0994     .demod_mode     = STV090x_DUAL,
0995     .clk_mode       = STV090x_CLK_EXT,
0996 
0997     .xtal           = 27000000,
0998     .address        = 0x69,
0999 
1000     .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
1001     .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
1002 
1003     .repeater_level = STV090x_RPTLEVEL_16,
1004 
1005     .adc1_range = STV090x_ADC_1Vpp,
1006     .adc2_range = STV090x_ADC_1Vpp,
1007 
1008     .diseqc_envelope_mode = true,
1009 
1010     .tuner_i2c_lock = cineS2_tuner_i2c_lock,
1011 };
1012 
1013 static struct stv6110x_config tuner_cineS2_0 = {
1014     .addr   = 0x60,
1015     .refclk = 27000000,
1016     .clk_div = 1,
1017 };
1018 
1019 static struct stv6110x_config tuner_cineS2_1 = {
1020     .addr   = 0x63,
1021     .refclk = 27000000,
1022     .clk_div = 1,
1023 };
1024 
1025 static const struct ngene_info ngene_info_cineS2 = {
1026     .type       = NGENE_SIDEWINDER,
1027     .name       = "Linux4Media cineS2 DVB-S2 Twin Tuner",
1028     .io_type    = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1029     .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
1030     .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
1031     .fe_config  = {&fe_cineS2, &fe_cineS2},
1032     .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
1033     .lnb        = {0x0b, 0x08},
1034     .tsf        = {3, 3},
1035     .fw_version = 18,
1036     .msi_supported  = true,
1037 };
1038 
1039 static const struct ngene_info ngene_info_satixS2 = {
1040     .type       = NGENE_SIDEWINDER,
1041     .name       = "Mystique SaTiX-S2 Dual",
1042     .io_type    = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1043     .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
1044     .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
1045     .fe_config  = {&fe_cineS2, &fe_cineS2},
1046     .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
1047     .lnb        = {0x0b, 0x08},
1048     .tsf        = {3, 3},
1049     .fw_version = 18,
1050     .msi_supported  = true,
1051 };
1052 
1053 static const struct ngene_info ngene_info_satixS2v2 = {
1054     .type       = NGENE_SIDEWINDER,
1055     .name       = "Mystique SaTiX-S2 Dual (v2)",
1056     .io_type    = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
1057                NGENE_IO_TSOUT},
1058     .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
1059     .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
1060     .fe_config  = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
1061     .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
1062     .lnb        = {0x0a, 0x08, 0x0b, 0x09},
1063     .tsf        = {3, 3},
1064     .fw_version = 18,
1065     .msi_supported  = true,
1066 };
1067 
1068 static const struct ngene_info ngene_info_cineS2v5 = {
1069     .type       = NGENE_SIDEWINDER,
1070     .name       = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
1071     .io_type    = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
1072                NGENE_IO_TSOUT},
1073     .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
1074     .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
1075     .fe_config  = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
1076     .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
1077     .lnb        = {0x0a, 0x08, 0x0b, 0x09},
1078     .tsf        = {3, 3},
1079     .fw_version = 18,
1080     .msi_supported  = true,
1081 };
1082 
1083 
1084 static const struct ngene_info ngene_info_duoFlex = {
1085     .type           = NGENE_SIDEWINDER,
1086     .name           = "Digital Devices DuoFlex PCIe or miniPCIe",
1087     .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
1088                NGENE_IO_TSOUT},
1089     .demod_attach   = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
1090     .tuner_attach   = {tuner_attach_probe, tuner_attach_probe, tuner_attach_probe, tuner_attach_probe},
1091     .fe_config      = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
1092     .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
1093     .lnb            = {0x0a, 0x08, 0x0b, 0x09},
1094     .tsf            = {3, 3},
1095     .fw_version     = 18,
1096     .msi_supported  = true,
1097 };
1098 
1099 static const struct ngene_info ngene_info_m780 = {
1100     .type           = NGENE_APP,
1101     .name           = "Aver M780 ATSC/QAM-B",
1102 
1103     /* Channel 0 is analog, which is currently unsupported */
1104     .io_type        = { NGENE_IO_NONE, NGENE_IO_TSIN },
1105     .demod_attach   = { NULL, demod_attach_lg330x },
1106 
1107     /* Ensure these are NULL else the frame will call them (as funcs) */
1108     .tuner_attach   = { NULL, NULL, NULL, NULL },
1109     .fe_config      = { NULL, &aver_m780 },
1110     .avf            = { 0 },
1111 
1112     /* A custom electrical interface config for the demod to bridge */
1113     .tsf        = { 4, 4 },
1114     .fw_version = 15,
1115 };
1116 
1117 static struct drxd_config fe_terratec_dvbt_0 = {
1118     .index          = 0,
1119     .demod_address  = 0x70,
1120     .demod_revision = 0xa2,
1121     .demoda_address = 0x00,
1122     .pll_address    = 0x60,
1123     .pll_type       = DVB_PLL_THOMSON_DTT7520X,
1124     .clock          = 20000,
1125     .osc_deviation  = osc_deviation,
1126 };
1127 
1128 static struct drxd_config fe_terratec_dvbt_1 = {
1129     .index          = 1,
1130     .demod_address  = 0x71,
1131     .demod_revision = 0xa2,
1132     .demoda_address = 0x00,
1133     .pll_address    = 0x60,
1134     .pll_type       = DVB_PLL_THOMSON_DTT7520X,
1135     .clock          = 20000,
1136     .osc_deviation  = osc_deviation,
1137 };
1138 
1139 static const struct ngene_info ngene_info_terratec = {
1140     .type           = NGENE_TERRATEC,
1141     .name           = "Terratec Integra/Cinergy2400i Dual DVB-T",
1142     .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1143     .demod_attach   = {demod_attach_drxd, demod_attach_drxd},
1144     .tuner_attach   = {tuner_attach_dtt7520x, tuner_attach_dtt7520x},
1145     .fe_config      = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
1146     .i2c_access     = 1,
1147 };
1148 
1149 /****************************************************************************/
1150 
1151 
1152 
1153 /****************************************************************************/
1154 /* PCI Subsystem ID *********************************************************/
1155 /****************************************************************************/
1156 
1157 #define NGENE_ID(_subvend, _subdev, _driverdata) { \
1158     .vendor = NGENE_VID, .device = NGENE_PID, \
1159     .subvendor = _subvend, .subdevice = _subdev, \
1160     .driver_data = (unsigned long) &_driverdata }
1161 
1162 /****************************************************************************/
1163 
1164 static const struct pci_device_id ngene_id_tbl[] = {
1165     NGENE_ID(0x18c3, 0xab04, ngene_info_cineS2),
1166     NGENE_ID(0x18c3, 0xab05, ngene_info_cineS2v5),
1167     NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
1168     NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
1169     NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
1170     NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
1171     NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
1172     NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex),
1173     NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex),
1174     NGENE_ID(0x1461, 0x062e, ngene_info_m780),
1175     NGENE_ID(0x153b, 0x1167, ngene_info_terratec),
1176     {0}
1177 };
1178 MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
1179 
1180 /****************************************************************************/
1181 /* Init/Exit ****************************************************************/
1182 /****************************************************************************/
1183 
1184 static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
1185                          pci_channel_state_t state)
1186 {
1187     dev_err(&dev->dev, "PCI error\n");
1188     if (state == pci_channel_io_perm_failure)
1189         return PCI_ERS_RESULT_DISCONNECT;
1190     if (state == pci_channel_io_frozen)
1191         return PCI_ERS_RESULT_NEED_RESET;
1192     return PCI_ERS_RESULT_CAN_RECOVER;
1193 }
1194 
1195 static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
1196 {
1197     dev_info(&dev->dev, "slot reset\n");
1198     return 0;
1199 }
1200 
1201 static void ngene_resume(struct pci_dev *dev)
1202 {
1203     dev_info(&dev->dev, "resume\n");
1204 }
1205 
1206 static const struct pci_error_handlers ngene_errors = {
1207     .error_detected = ngene_error_detected,
1208     .slot_reset = ngene_slot_reset,
1209     .resume = ngene_resume,
1210 };
1211 
1212 static struct pci_driver ngene_pci_driver = {
1213     .name        = "ngene",
1214     .id_table    = ngene_id_tbl,
1215     .probe       = ngene_probe,
1216     .remove      = ngene_remove,
1217     .err_handler = &ngene_errors,
1218     .shutdown    = ngene_shutdown,
1219 };
1220 
1221 static __init int module_init_ngene(void)
1222 {
1223     /* pr_*() since we don't have a device to use with dev_*() yet */
1224     pr_info("nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
1225 
1226     return pci_register_driver(&ngene_pci_driver);
1227 }
1228 
1229 static __exit void module_exit_ngene(void)
1230 {
1231     pci_unregister_driver(&ngene_pci_driver);
1232 }
1233 
1234 module_init(module_init_ngene);
1235 module_exit(module_exit_ngene);
1236 
1237 MODULE_DESCRIPTION("nGene");
1238 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
1239 MODULE_LICENSE("GPL");