2 * ngene-cards.c: nGene PCIe bridge driver - card specific info
4 * Copyright (C) 2005-2007 Micronas
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
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.
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.
22 * To obtain the license, point your browser to
23 * http://www.gnu.org/copyleft/gpl.html
26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
31 #include <linux/pci_ids.h>
41 #include "tda18271c2dd.h"
46 #include "stv0367_priv.h"
48 #include "cxd2841er.h"
53 /****************************************************************************/
54 /* I2C transfer functions used for demod/tuner probing***********************/
55 /****************************************************************************/
57 static int i2c_io(struct i2c_adapter *adapter, u8 adr,
58 u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
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;
67 static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
69 struct i2c_msg msg = {.addr = adr, .flags = 0,
70 .buf = data, .len = len};
72 return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
75 static int i2c_write_reg(struct i2c_adapter *adap, u8 adr,
78 u8 msg[2] = {reg, val};
80 return i2c_write(adap, adr, msg, 2);
83 static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
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;
90 static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
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;
101 static int i2c_read_regs(struct i2c_adapter *adapter,
102 u8 adr, u8 reg, u8 *val, u8 len)
104 struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
105 .buf = ®, .len = 1},
106 {.addr = adr, .flags = I2C_M_RD,
107 .buf = val, .len = len} };
109 return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
112 static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, u8 reg, u8 *val)
114 return i2c_read_regs(adapter, adr, reg, val, 1);
117 /****************************************************************************/
118 /* Demod/tuner attachment ***************************************************/
119 /****************************************************************************/
121 static struct i2c_adapter *i2c_adapter_from_chan(struct ngene_channel *chan)
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;
127 return &chan->dev->channel[1].i2c_adapter;
130 static int tuner_attach_stv6110(struct ngene_channel *chan)
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;
140 if (chan->number < 2)
141 i2c = &chan->dev->channel[0].i2c_adapter;
143 i2c = &chan->dev->channel[1].i2c_adapter;
145 ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
147 dev_err(pdev, "No STV6110X found!\n");
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;
166 static int tuner_attach_stv6111(struct ngene_channel *chan)
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);
173 fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr);
175 fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4);
177 dev_err(pdev, "stv6111_attach() failed!\n");
184 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
186 struct ngene_channel *chan = fe->sec_priv;
190 down(&chan->dev->pll_mutex);
191 status = chan->gate_ctrl(fe, 1);
193 status = chan->gate_ctrl(fe, 0);
194 up(&chan->dev->pll_mutex);
199 static int tuner_attach_tda18271(struct ngene_channel *chan)
201 struct device *pdev = &chan->dev->pci_dev->dev;
202 struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
203 struct dvb_frontend *fe;
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);
211 dev_err(pdev, "No TDA18271 found!\n");
218 static int tuner_tda18212_ping(struct ngene_channel *chan,
219 struct i2c_adapter *i2c,
222 struct device *pdev = &chan->dev->pci_dev->dev;
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);
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");
235 if (chan->fe->ops.i2c_gate_ctrl)
236 chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
241 static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
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 = {
256 struct i2c_board_info board_info = {
258 .platform_data = &config,
261 if (chan->number & 1)
262 board_info.addr = 0x63;
264 board_info.addr = 0x60;
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.
271 if (dmdtype == DEMOD_TYPE_STV0367)
272 tuner_tda18212_ping(chan, i2c, board_info.addr);
274 request_module(board_info.type);
276 /* perform tuner init/attach */
277 client = i2c_new_device(i2c, &board_info);
278 if (!client || !client->dev.driver)
281 if (!try_module_get(client->dev.driver->owner)) {
282 i2c_unregister_device(client);
286 chan->i2c_client[0] = client;
287 chan->i2c_client_fe = 1;
291 dev_err(pdev, "TDA18212 tuner not found. Device is not fully operational.\n");
295 static int tuner_attach_probe(struct ngene_channel *chan)
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);
315 static int demod_attach_stv0900(struct ngene_channel *chan)
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];
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;
328 i2c = &chan->dev->channel[1].i2c_adapter;
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");
338 /* store channel info */
339 if (feconf->tuner_i2c_lock)
340 chan->fe->analog_demod_priv = chan;
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);
353 static struct stv0910_cfg stv0910_p = {
360 static struct lnbh25_config lnbh25_cfg = {
361 .i2c_address = 0x0c << 1,
362 .data2_config = LNBH25_TEN
365 static int demod_attach_stv0910(struct ngene_channel *chan,
366 struct i2c_adapter *i2c)
368 struct device *pdev = &chan->dev->pci_dev->dev;
369 struct stv0910_cfg cfg = stv0910_p;
370 struct lnbh25_config lnbcfg = lnbh25_cfg;
372 chan->fe = dvb_attach(stv0910_attach, i2c, &cfg, (chan->number & 1));
375 chan->fe = dvb_attach(stv0910_attach, i2c,
376 &cfg, (chan->number & 1));
379 dev_err(pdev, "stv0910_attach() failed!\n");
384 * attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
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);
401 static struct stv0367_config ddb_stv0367_config[] = {
403 .demod_address = 0x1f,
406 .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
407 .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
408 .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
410 .demod_address = 0x1e,
413 .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
414 .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
415 .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
419 static int demod_attach_stv0367(struct ngene_channel *chan,
420 struct i2c_adapter *i2c)
422 struct device *pdev = &chan->dev->pci_dev->dev;
424 chan->fe = dvb_attach(stv0367ddb_attach,
425 &ddb_stv0367_config[(chan->number & 1)], i2c);
428 dev_err(pdev, "stv0367ddb_attach() failed!\n");
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;
438 static int demod_attach_cxd28xx(struct ngene_channel *chan,
439 struct i2c_adapter *i2c, int osc24)
441 struct device *pdev = &chan->dev->pci_dev->dev;
442 struct cxd2841er_config cfg;
444 /* the cxd2841er driver expects 8bit/shifted I2C addresses */
445 cfg.i2c_addr = ((chan->number & 1) ? 0x6d : 0x6c) << 1;
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;
452 /* attach frontend */
453 chan->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
456 dev_err(pdev, "CXD28XX attach failed!\n");
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;
466 static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
468 struct ngene_channel *chan = fe->analog_demod_priv;
471 down(&chan->dev->pll_mutex);
473 up(&chan->dev->pll_mutex);
476 static int port_has_stv0900(struct i2c_adapter *i2c, int port)
479 if (i2c_read_reg16(i2c, 0x68+port/2, 0xf100, &val) < 0)
484 static int port_has_drxk(struct i2c_adapter *i2c, int port)
488 if (i2c_read(i2c, 0x29+port, &val) < 0)
493 static int port_has_stv0367(struct i2c_adapter *i2c)
497 if (i2c_read_reg16(i2c, 0x1e, 0xf000, &val) < 0)
501 if (i2c_read_reg16(i2c, 0x1f, 0xf000, &val) < 0)
508 int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type)
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);
520 if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43)
527 static int demod_attach_drxk(struct ngene_channel *chan,
528 struct i2c_adapter *i2c)
530 struct device *pdev = &chan->dev->pci_dev->dev;
531 struct drxk_config config;
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);
538 chan->fe = dvb_attach(drxk_attach, &config, i2c);
540 dev_err(pdev, "No DRXK found!\n");
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;
549 /****************************************************************************/
550 /* XO2 related lists and functions ******************************************/
551 /****************************************************************************/
553 static char *xo2names[] = {
557 "DUAL DVB-C/C2/T/T2",
559 "DUAL DVB-C/C2/T/T2/I",
562 static int init_xo2(struct ngene_channel *chan, struct i2c_adapter *i2c)
564 struct device *pdev = &chan->dev->pci_dev->dev;
569 res = i2c_read_regs(i2c, addr, 0x04, data, 2);
573 if (data[0] != 0x01) {
574 dev_info(pdev, "Invalid XO2 on channel %d\n", chan->number);
578 i2c_read_reg(i2c, addr, 0x08, &val);
580 i2c_write_reg(i2c, addr, 0x08, 0x00);
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);
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.
596 i2c_write_reg(i2c, addr, 0x09, 1);
598 i2c_write_reg(i2c, addr, 0x0a, 0x01);
599 i2c_write_reg(i2c, addr, 0x0b, 0x01);
601 usleep_range(2000, 3000);
603 i2c_write_reg(i2c, addr, 0x08, 0x87);
608 static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, u8 *id)
610 u8 probe[1] = { 0x00 }, data[4];
613 *type = NGENE_XO2_TYPE_NONE;
615 if (i2c_io(i2c, addr, probe, 1, data, 4))
617 if (data[0] == 'D' && data[1] == 'F') {
619 *type = NGENE_XO2_TYPE_DUOFLEX;
622 if (data[0] == 'C' && data[1] == 'I') {
624 *type = NGENE_XO2_TYPE_CI;
630 /****************************************************************************/
631 /* Probing and port/channel handling ****************************************/
632 /****************************************************************************/
634 static int cineS2_probe(struct ngene_channel *chan)
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;
640 u8 xo2_type, xo2_id, xo2_demodtype;
642 struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
645 if (port_has_xo2(i2c, &xo2_type, &xo2_id)) {
647 dev_dbg(pdev, "XO2 on channel %d (type %d, id %d)\n",
648 chan->number, xo2_type, xo2_id);
651 case NGENE_XO2_TYPE_DUOFLEX:
652 if (chan->number & 1)
654 "skipping XO2 init on odd channel %d",
659 xo2_demodtype = DEMOD_TYPE_XO2 + xo2_id;
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)
672 demod_attach_cxd28xx(chan, i2c, sony_osc24);
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);
682 "Unsupported XO2 module on channel %d\n",
687 case NGENE_XO2_TYPE_CI:
688 dev_info(pdev, "DuoFlex CI modules not supported\n");
691 dev_info(pdev, "Unsupported XO2 module type\n");
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)
702 /* demod #2: reprogram outputs DPN1 & DPN2 */
703 i2c_msg.addr = fe_conf->address;
706 switch (chan->number) {
718 rc = i2c_transfer(i2c, &i2c_msg, 1);
720 dev_err(pdev, "Could not setup DPNx\n");
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);
731 dev_info(pdev, "No demod found on chan %d\n", chan->number);
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,
745 static struct mt2131_config m780_tunerconfig = {
749 /* A single func to attach the demo and tuner, rather than
750 * use two sep funcs like the current design mandates.
752 static int demod_attach_lg330x(struct ngene_channel *chan)
754 struct device *pdev = &chan->dev->pci_dev->dev;
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");
762 dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
763 &m780_tunerconfig, 0);
765 return (chan->fe) ? 0 : -ENODEV;
768 static int demod_attach_drxd(struct ngene_channel *chan)
770 struct device *pdev = &chan->dev->pci_dev->dev;
771 struct drxd_config *feconf;
773 feconf = chan->dev->card_info->fe_config[chan->number];
775 chan->fe = dvb_attach(drxd_attach, feconf, chan,
776 &chan->i2c_adapter, &chan->dev->pci_dev->dev);
778 dev_err(pdev, "No DRXD found!\n");
784 static int tuner_attach_dtt7520x(struct ngene_channel *chan)
786 struct device *pdev = &chan->dev->pci_dev->dev;
787 struct drxd_config *feconf;
789 feconf = chan->dev->card_info->fe_config[chan->number];
791 if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
794 dev_err(pdev, "No pll(%d) found!\n", feconf->pll_type);
800 /****************************************************************************/
801 /* EEPROM TAGS **************************************************************/
802 /****************************************************************************/
804 #define MICNG_EE_START 0x0100
805 #define MICNG_EE_END 0x0FF0
807 #define MICNG_EETAG_END0 0x0000
808 #define MICNG_EETAG_END1 0xFFFF
810 /* 0x0001 - 0x000F reserved for housekeeping */
811 /* 0xFFFF - 0xFFFE reserved for housekeeping */
813 /* Micronas assigned tags
814 EEProm tags for hardware support */
816 #define MICNG_EETAG_DRXD1_OSCDEVIATION 0x1000 /* 2 Bytes data */
817 #define MICNG_EETAG_DRXD2_OSCDEVIATION 0x1001 /* 2 Bytes data */
819 #define MICNG_EETAG_MT2060_1_1STIF 0x1100 /* 2 Bytes data */
820 #define MICNG_EETAG_MT2060_2_1STIF 0x1101 /* 2 Bytes data */
822 /* Tag range for OEMs */
824 #define MICNG_EETAG_OEM_FIRST 0xC000
825 #define MICNG_EETAG_OEM_LAST 0xFFEF
827 static int i2c_write_eeprom(struct i2c_adapter *adapter,
828 u8 adr, u16 reg, u8 data)
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,
835 if (i2c_transfer(adapter, &msg, 1) != 1) {
836 dev_err(pdev, "Error writing EEPROM!\n");
842 static int i2c_read_eeprom(struct i2c_adapter *adapter,
843 u8 adr, u16 reg, u8 *data, int len)
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} };
852 if (i2c_transfer(adapter, msgs, 2) != 2) {
853 dev_err(pdev, "Error reading EEPROM\n");
859 static int ReadEEProm(struct i2c_adapter *adapter,
860 u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
862 struct device *pdev = adapter->dev.parent;
864 u16 Addr = MICNG_EE_START, Length, tag = 0;
867 while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
868 if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
870 tag = (EETag[0] << 8) | EETag[1];
871 if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
875 Addr += sizeof(u16) + 1 + EETag[2];
877 if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
878 dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
884 Length = (u16) MaxLen;
886 Addr += sizeof(u16) + 1;
887 status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
891 if (Length < EETag[2])
892 status = STATUS_BUFFER_OVERFLOW;
899 static int WriteEEProm(struct i2c_adapter *adapter,
900 u16 Tag, u32 Length, u8 *data)
902 struct device *pdev = adapter->dev.parent;
904 u16 Addr = MICNG_EE_START;
909 while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
910 if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
912 tag = (EETag[0] << 8) | EETag[1];
913 if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
917 Addr += sizeof(u16) + 1 + EETag[2];
919 if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
920 dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
925 if (Length > EETag[2])
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)
931 Addr += sizeof(u16) + 1;
932 for (i = 0; i < Length; i++, Addr++) {
933 status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
938 /* Poll for finishing write cycle */
944 status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
948 dev_err(pdev, "eeprom write error\n");
952 dev_err(pdev, "Timeout polling eeprom\n");
959 static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
965 stat = ReadEEProm(adapter, tag, 2, buf, &len);
971 *data = (buf[0] << 8) | buf[1];
975 static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
981 buf[1] = data & 0xff;
982 stat = WriteEEProm(adapter, tag, 2, buf);
988 static s16 osc_deviation(void *priv, s16 deviation, int flag)
990 struct ngene_channel *chan = priv;
991 struct device *pdev = &chan->dev->pci_dev->dev;
992 struct i2c_adapter *adap = &chan->i2c_adapter;
996 data = (u16) deviation;
997 dev_info(pdev, "write deviation %d\n",
999 eeprom_write_ushort(adap, 0x1000 + chan->number, data);
1001 if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
1003 dev_info(pdev, "read deviation %d\n",
1010 /****************************************************************************/
1011 /* Switch control (I2C gates, etc.) *****************************************/
1012 /****************************************************************************/
1015 static struct stv090x_config fe_cineS2 = {
1017 .demod_mode = STV090x_DUAL,
1018 .clk_mode = STV090x_CLK_EXT,
1023 .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
1024 .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
1026 .repeater_level = STV090x_RPTLEVEL_16,
1028 .adc1_range = STV090x_ADC_1Vpp,
1029 .adc2_range = STV090x_ADC_1Vpp,
1031 .diseqc_envelope_mode = true,
1033 .tuner_i2c_lock = cineS2_tuner_i2c_lock,
1036 static struct stv090x_config fe_cineS2_2 = {
1038 .demod_mode = STV090x_DUAL,
1039 .clk_mode = STV090x_CLK_EXT,
1044 .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
1045 .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
1047 .repeater_level = STV090x_RPTLEVEL_16,
1049 .adc1_range = STV090x_ADC_1Vpp,
1050 .adc2_range = STV090x_ADC_1Vpp,
1052 .diseqc_envelope_mode = true,
1054 .tuner_i2c_lock = cineS2_tuner_i2c_lock,
1057 static struct stv6110x_config tuner_cineS2_0 = {
1063 static struct stv6110x_config tuner_cineS2_1 = {
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},
1080 .msi_supported = true,
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},
1094 .msi_supported = true,
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,
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},
1109 .msi_supported = true,
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,
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},
1124 .msi_supported = true,
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,
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},
1140 .msi_supported = true,
1143 static const struct ngene_info ngene_info_m780 = {
1145 .name = "Aver M780 ATSC/QAM-B",
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 },
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 },
1156 /* A custom electrical interface config for the demod to bridge */
1161 static struct drxd_config fe_terratec_dvbt_0 = {
1163 .demod_address = 0x70,
1164 .demod_revision = 0xa2,
1165 .demoda_address = 0x00,
1166 .pll_address = 0x60,
1167 .pll_type = DVB_PLL_THOMSON_DTT7520X,
1169 .osc_deviation = osc_deviation,
1172 static struct drxd_config fe_terratec_dvbt_1 = {
1174 .demod_address = 0x71,
1175 .demod_revision = 0xa2,
1176 .demoda_address = 0x00,
1177 .pll_address = 0x60,
1178 .pll_type = DVB_PLL_THOMSON_DTT7520X,
1180 .osc_deviation = osc_deviation,
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},
1193 /****************************************************************************/
1197 /****************************************************************************/
1198 /* PCI Subsystem ID *********************************************************/
1199 /****************************************************************************/
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 }
1206 /****************************************************************************/
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),
1222 MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
1224 /****************************************************************************/
1225 /* Init/Exit ****************************************************************/
1226 /****************************************************************************/
1228 static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
1229 enum pci_channel_state state)
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;
1239 static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
1241 dev_info(&dev->dev, "slot reset\n");
1245 static void ngene_resume(struct pci_dev *dev)
1247 dev_info(&dev->dev, "resume\n");
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,
1256 static struct pci_driver ngene_pci_driver = {
1258 .id_table = ngene_id_tbl,
1259 .probe = ngene_probe,
1260 .remove = ngene_remove,
1261 .err_handler = &ngene_errors,
1262 .shutdown = ngene_shutdown,
1265 static __init int module_init_ngene(void)
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");
1270 return pci_register_driver(&ngene_pci_driver);
1273 static __exit void module_exit_ngene(void)
1275 pci_unregister_driver(&ngene_pci_driver);
1278 module_init(module_init_ngene);
1279 module_exit(module_exit_ngene);
1281 MODULE_DESCRIPTION("nGene");
1282 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
1283 MODULE_LICENSE("GPL");