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