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 ctl
= dvb_attach(stv6110x_attach
, chan
->fe
, tunerconf
, i2c
);
142 dev_err(pdev
, "No STV6110X found!\n");
146 feconf
->tuner_init
= ctl
->tuner_init
;
147 feconf
->tuner_sleep
= ctl
->tuner_sleep
;
148 feconf
->tuner_set_mode
= ctl
->tuner_set_mode
;
149 feconf
->tuner_set_frequency
= ctl
->tuner_set_frequency
;
150 feconf
->tuner_get_frequency
= ctl
->tuner_get_frequency
;
151 feconf
->tuner_set_bandwidth
= ctl
->tuner_set_bandwidth
;
152 feconf
->tuner_get_bandwidth
= ctl
->tuner_get_bandwidth
;
153 feconf
->tuner_set_bbgain
= ctl
->tuner_set_bbgain
;
154 feconf
->tuner_get_bbgain
= ctl
->tuner_get_bbgain
;
155 feconf
->tuner_set_refclk
= ctl
->tuner_set_refclk
;
156 feconf
->tuner_get_status
= ctl
->tuner_get_status
;
161 static int tuner_attach_stv6111(struct ngene_channel
*chan
)
163 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
164 struct i2c_adapter
*i2c
= i2c_adapter_from_chan(chan
);
165 struct dvb_frontend
*fe
;
166 u8 adr
= 4 + ((chan
->number
& 1) ? 0x63 : 0x60);
168 fe
= dvb_attach(stv6111_attach
, chan
->fe
, i2c
, adr
);
170 fe
= dvb_attach(stv6111_attach
, chan
->fe
, i2c
, adr
& ~4);
172 dev_err(pdev
, "stv6111_attach() failed!\n");
179 static int drxk_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
181 struct ngene_channel
*chan
= fe
->sec_priv
;
185 down(&chan
->dev
->pll_mutex
);
186 status
= chan
->gate_ctrl(fe
, 1);
188 status
= chan
->gate_ctrl(fe
, 0);
189 up(&chan
->dev
->pll_mutex
);
194 static int tuner_attach_tda18271(struct ngene_channel
*chan
)
196 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
197 struct i2c_adapter
*i2c
= i2c_adapter_from_chan(chan
);
198 struct dvb_frontend
*fe
;
200 if (chan
->fe
->ops
.i2c_gate_ctrl
)
201 chan
->fe
->ops
.i2c_gate_ctrl(chan
->fe
, 1);
202 fe
= dvb_attach(tda18271c2dd_attach
, chan
->fe
, i2c
, 0x60);
203 if (chan
->fe
->ops
.i2c_gate_ctrl
)
204 chan
->fe
->ops
.i2c_gate_ctrl(chan
->fe
, 0);
206 dev_err(pdev
, "No TDA18271 found!\n");
213 static int tuner_tda18212_ping(struct ngene_channel
*chan
,
214 struct i2c_adapter
*i2c
,
217 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
221 dev_dbg(pdev
, "stv0367-tda18212 tuner ping\n");
222 if (chan
->fe
->ops
.i2c_gate_ctrl
)
223 chan
->fe
->ops
.i2c_gate_ctrl(chan
->fe
, 1);
225 if (i2c_read_regs(i2c
, adr
, subaddr
, tda_id
, sizeof(tda_id
)) < 0)
226 dev_dbg(pdev
, "tda18212 ping 1 fail\n");
227 if (i2c_read_regs(i2c
, adr
, subaddr
, tda_id
, sizeof(tda_id
)) < 0)
228 dev_warn(pdev
, "tda18212 ping failed, expect problems\n");
230 if (chan
->fe
->ops
.i2c_gate_ctrl
)
231 chan
->fe
->ops
.i2c_gate_ctrl(chan
->fe
, 0);
236 static int tuner_attach_tda18212(struct ngene_channel
*chan
, u32 dmdtype
)
238 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
239 struct i2c_adapter
*i2c
= i2c_adapter_from_chan(chan
);
240 struct i2c_client
*client
;
241 struct tda18212_config config
= {
251 u8 addr
= (chan
->number
& 1) ? 0x63 : 0x60;
254 * due to a hardware quirk with the I2C gate on the stv0367+tda18212
255 * combo, the tda18212 must be probed by reading it's id _twice_ when
256 * cold started, or it very likely will fail.
258 if (dmdtype
== DEMOD_TYPE_STV0367
)
259 tuner_tda18212_ping(chan
, i2c
, addr
);
261 /* perform tuner probe/init/attach */
262 client
= dvb_module_probe("tda18212", NULL
, i2c
, addr
, &config
);
266 chan
->i2c_client
[0] = client
;
267 chan
->i2c_client_fe
= 1;
271 dev_err(pdev
, "TDA18212 tuner not found. Device is not fully operational.\n");
275 static int tuner_attach_probe(struct ngene_channel
*chan
)
277 switch (chan
->demod_type
) {
278 case DEMOD_TYPE_STV090X
:
279 return tuner_attach_stv6110(chan
);
280 case DEMOD_TYPE_DRXK
:
281 return tuner_attach_tda18271(chan
);
282 case DEMOD_TYPE_STV0367
:
283 case DEMOD_TYPE_SONY_CT2
:
284 case DEMOD_TYPE_SONY_ISDBT
:
285 case DEMOD_TYPE_SONY_C2T2
:
286 case DEMOD_TYPE_SONY_C2T2I
:
287 return tuner_attach_tda18212(chan
, chan
->demod_type
);
288 case DEMOD_TYPE_STV0910
:
289 return tuner_attach_stv6111(chan
);
295 static int demod_attach_stv0900(struct ngene_channel
*chan
)
297 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
298 struct i2c_adapter
*i2c
= i2c_adapter_from_chan(chan
);
299 struct stv090x_config
*feconf
= (struct stv090x_config
*)
300 chan
->dev
->card_info
->fe_config
[chan
->number
];
302 chan
->fe
= dvb_attach(stv090x_attach
, feconf
, i2c
,
303 (chan
->number
& 1) == 0 ? STV090x_DEMODULATOR_0
304 : STV090x_DEMODULATOR_1
);
305 if (chan
->fe
== NULL
) {
306 dev_err(pdev
, "No STV0900 found!\n");
310 /* store channel info */
311 if (feconf
->tuner_i2c_lock
)
312 chan
->fe
->analog_demod_priv
= chan
;
314 if (!dvb_attach(lnbh24_attach
, chan
->fe
, i2c
, 0,
315 0, chan
->dev
->card_info
->lnb
[chan
->number
])) {
316 dev_err(pdev
, "No LNBH24 found!\n");
317 dvb_frontend_detach(chan
->fe
);
325 static struct stv0910_cfg stv0910_p
= {
333 static struct lnbh25_config lnbh25_cfg
= {
334 .i2c_address
= 0x0c << 1,
335 .data2_config
= LNBH25_TEN
338 static int demod_attach_stv0910(struct ngene_channel
*chan
,
339 struct i2c_adapter
*i2c
)
341 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
342 struct stv0910_cfg cfg
= stv0910_p
;
343 struct lnbh25_config lnbcfg
= lnbh25_cfg
;
345 chan
->fe
= dvb_attach(stv0910_attach
, i2c
, &cfg
, (chan
->number
& 1));
348 chan
->fe
= dvb_attach(stv0910_attach
, i2c
,
349 &cfg
, (chan
->number
& 1));
352 dev_err(pdev
, "stv0910_attach() failed!\n");
357 * attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
360 lnbcfg
.i2c_address
= (((chan
->number
& 1) ? 0x0d : 0x0c) << 1);
361 if (!dvb_attach(lnbh25_attach
, chan
->fe
, &lnbcfg
, i2c
)) {
362 lnbcfg
.i2c_address
= (((chan
->number
& 1) ? 0x09 : 0x08) << 1);
363 if (!dvb_attach(lnbh25_attach
, chan
->fe
, &lnbcfg
, i2c
)) {
364 dev_err(pdev
, "lnbh25_attach() failed!\n");
365 dvb_frontend_detach(chan
->fe
);
374 static struct stv0367_config ddb_stv0367_config
[] = {
376 .demod_address
= 0x1f,
379 .if_iq_mode
= FE_TER_NORMAL_IF_TUNER
,
380 .ts_mode
= STV0367_SERIAL_PUNCT_CLOCK
,
381 .clk_pol
= STV0367_CLOCKPOLARITY_DEFAULT
,
383 .demod_address
= 0x1e,
386 .if_iq_mode
= FE_TER_NORMAL_IF_TUNER
,
387 .ts_mode
= STV0367_SERIAL_PUNCT_CLOCK
,
388 .clk_pol
= STV0367_CLOCKPOLARITY_DEFAULT
,
392 static int demod_attach_stv0367(struct ngene_channel
*chan
,
393 struct i2c_adapter
*i2c
)
395 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
397 chan
->fe
= dvb_attach(stv0367ddb_attach
,
398 &ddb_stv0367_config
[(chan
->number
& 1)], i2c
);
401 dev_err(pdev
, "stv0367ddb_attach() failed!\n");
405 chan
->fe
->sec_priv
= chan
;
406 chan
->gate_ctrl
= chan
->fe
->ops
.i2c_gate_ctrl
;
407 chan
->fe
->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
411 static int demod_attach_cxd28xx(struct ngene_channel
*chan
,
412 struct i2c_adapter
*i2c
, int osc24
)
414 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
415 struct cxd2841er_config cfg
;
417 /* the cxd2841er driver expects 8bit/shifted I2C addresses */
418 cfg
.i2c_addr
= ((chan
->number
& 1) ? 0x6d : 0x6c) << 1;
420 cfg
.xtal
= osc24
? SONY_XTAL_24000
: SONY_XTAL_20500
;
421 cfg
.flags
= CXD2841ER_AUTO_IFHZ
| CXD2841ER_EARLY_TUNE
|
422 CXD2841ER_NO_WAIT_LOCK
| CXD2841ER_NO_AGCNEG
|
423 CXD2841ER_TSBITS
| CXD2841ER_TS_SERIAL
;
425 /* attach frontend */
426 chan
->fe
= dvb_attach(cxd2841er_attach_t_c
, &cfg
, i2c
);
429 dev_err(pdev
, "CXD28XX attach failed!\n");
433 chan
->fe
->sec_priv
= chan
;
434 chan
->gate_ctrl
= chan
->fe
->ops
.i2c_gate_ctrl
;
435 chan
->fe
->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
439 static void cineS2_tuner_i2c_lock(struct dvb_frontend
*fe
, int lock
)
441 struct ngene_channel
*chan
= fe
->analog_demod_priv
;
444 down(&chan
->dev
->pll_mutex
);
446 up(&chan
->dev
->pll_mutex
);
449 static int port_has_stv0900(struct i2c_adapter
*i2c
, int port
)
452 if (i2c_read_reg16(i2c
, 0x68+port
/2, 0xf100, &val
) < 0)
457 static int port_has_drxk(struct i2c_adapter
*i2c
, int port
)
461 if (i2c_read(i2c
, 0x29+port
, &val
) < 0)
466 static int port_has_stv0367(struct i2c_adapter
*i2c
)
470 if (i2c_read_reg16(i2c
, 0x1e, 0xf000, &val
) < 0)
474 if (i2c_read_reg16(i2c
, 0x1f, 0xf000, &val
) < 0)
481 int ngene_port_has_cxd2099(struct i2c_adapter
*i2c
, u8
*type
)
484 u8 probe
[4] = { 0xe0, 0x00, 0x00, 0x00 }, data
[4];
485 struct i2c_msg msgs
[2] = {{ .addr
= 0x40, .flags
= 0,
486 .buf
= probe
, .len
= 4 },
487 { .addr
= 0x40, .flags
= I2C_M_RD
,
488 .buf
= data
, .len
= 4 } };
489 val
= i2c_transfer(i2c
, msgs
, 2);
493 if (data
[0] == 0x02 && data
[1] == 0x2b && data
[3] == 0x43)
500 static int demod_attach_drxk(struct ngene_channel
*chan
,
501 struct i2c_adapter
*i2c
)
503 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
504 struct drxk_config config
;
506 memset(&config
, 0, sizeof(config
));
507 config
.microcode_name
= "drxk_a3.mc";
508 config
.qam_demod_parameter_count
= 4;
509 config
.adr
= 0x29 + (chan
->number
^ 2);
511 chan
->fe
= dvb_attach(drxk_attach
, &config
, i2c
);
513 dev_err(pdev
, "No DRXK found!\n");
516 chan
->fe
->sec_priv
= chan
;
517 chan
->gate_ctrl
= chan
->fe
->ops
.i2c_gate_ctrl
;
518 chan
->fe
->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
522 /****************************************************************************/
523 /* XO2 related lists and functions ******************************************/
524 /****************************************************************************/
526 static char *xo2names
[] = {
530 "DUAL DVB-C/C2/T/T2",
532 "DUAL DVB-C/C2/T/T2/I",
535 static int init_xo2(struct ngene_channel
*chan
, struct i2c_adapter
*i2c
)
537 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
542 res
= i2c_read_regs(i2c
, addr
, 0x04, data
, 2);
546 if (data
[0] != 0x01) {
547 dev_info(pdev
, "Invalid XO2 on channel %d\n", chan
->number
);
551 i2c_read_reg(i2c
, addr
, 0x08, &val
);
553 i2c_write_reg(i2c
, addr
, 0x08, 0x00);
556 /* Enable tuner power, disable pll, reset demods */
557 i2c_write_reg(i2c
, addr
, 0x08, 0x04);
558 usleep_range(2000, 3000);
559 /* Release demod resets */
560 i2c_write_reg(i2c
, addr
, 0x08, 0x07);
563 * speed: 0=55,1=75,2=90,3=104 MBit/s
564 * Note: The ngene hardware must be run at 75 MBit/s compared
565 * to more modern ddbridge hardware which runs at 90 MBit/s,
566 * else there will be issues with the data transport and non-
567 * working secondary/slave demods/tuners.
569 i2c_write_reg(i2c
, addr
, 0x09, 1);
571 i2c_write_reg(i2c
, addr
, 0x0a, 0x01);
572 i2c_write_reg(i2c
, addr
, 0x0b, 0x01);
574 usleep_range(2000, 3000);
576 i2c_write_reg(i2c
, addr
, 0x08, 0x87);
581 static int port_has_xo2(struct i2c_adapter
*i2c
, u8
*type
, u8
*id
)
583 u8 probe
[1] = { 0x00 }, data
[4];
586 *type
= NGENE_XO2_TYPE_NONE
;
588 if (i2c_io(i2c
, addr
, probe
, 1, data
, 4))
590 if (data
[0] == 'D' && data
[1] == 'F') {
592 *type
= NGENE_XO2_TYPE_DUOFLEX
;
595 if (data
[0] == 'C' && data
[1] == 'I') {
597 *type
= NGENE_XO2_TYPE_CI
;
603 /****************************************************************************/
604 /* Probing and port/channel handling ****************************************/
605 /****************************************************************************/
607 static int cineS2_probe(struct ngene_channel
*chan
)
609 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
610 struct i2c_adapter
*i2c
= i2c_adapter_from_chan(chan
);
611 struct stv090x_config
*fe_conf
;
613 u8 xo2_type
, xo2_id
, xo2_demodtype
;
615 struct i2c_msg i2c_msg
= { .flags
= 0, .buf
= buf
};
618 if (port_has_xo2(i2c
, &xo2_type
, &xo2_id
)) {
620 dev_dbg(pdev
, "XO2 on channel %d (type %d, id %d)\n",
621 chan
->number
, xo2_type
, xo2_id
);
624 case NGENE_XO2_TYPE_DUOFLEX
:
625 if (chan
->number
& 1)
627 "skipping XO2 init on odd channel %d",
632 xo2_demodtype
= DEMOD_TYPE_XO2
+ xo2_id
;
634 switch (xo2_demodtype
) {
635 case DEMOD_TYPE_SONY_CT2
:
636 case DEMOD_TYPE_SONY_ISDBT
:
637 case DEMOD_TYPE_SONY_C2T2
:
638 case DEMOD_TYPE_SONY_C2T2I
:
639 dev_info(pdev
, "%s (XO2) on channel %d\n",
640 xo2names
[xo2_id
], chan
->number
);
641 chan
->demod_type
= xo2_demodtype
;
642 if (xo2_demodtype
== DEMOD_TYPE_SONY_C2T2I
)
645 demod_attach_cxd28xx(chan
, i2c
, sony_osc24
);
647 case DEMOD_TYPE_STV0910
:
648 dev_info(pdev
, "%s (XO2) on channel %d\n",
649 xo2names
[xo2_id
], chan
->number
);
650 chan
->demod_type
= xo2_demodtype
;
651 demod_attach_stv0910(chan
, i2c
);
655 "Unsupported XO2 module on channel %d\n",
660 case NGENE_XO2_TYPE_CI
:
661 dev_info(pdev
, "DuoFlex CI modules not supported\n");
664 dev_info(pdev
, "Unsupported XO2 module type\n");
667 } else if (port_has_stv0900(i2c
, chan
->number
)) {
668 chan
->demod_type
= DEMOD_TYPE_STV090X
;
669 fe_conf
= chan
->dev
->card_info
->fe_config
[chan
->number
];
670 /* demod found, attach it */
671 rc
= demod_attach_stv0900(chan
);
672 if (rc
< 0 || chan
->number
< 2)
675 /* demod #2: reprogram outputs DPN1 & DPN2 */
676 i2c_msg
.addr
= fe_conf
->address
;
679 switch (chan
->number
) {
691 rc
= i2c_transfer(i2c
, &i2c_msg
, 1);
693 dev_err(pdev
, "Could not setup DPNx\n");
696 } else if (port_has_drxk(i2c
, chan
->number
^2)) {
697 chan
->demod_type
= DEMOD_TYPE_DRXK
;
698 demod_attach_drxk(chan
, i2c
);
699 } else if (port_has_stv0367(i2c
)) {
700 chan
->demod_type
= DEMOD_TYPE_STV0367
;
701 dev_info(pdev
, "STV0367 on channel %d\n", chan
->number
);
702 demod_attach_stv0367(chan
, i2c
);
704 dev_info(pdev
, "No demod found on chan %d\n", chan
->number
);
711 static struct lgdt330x_config aver_m780
= {
712 .demod_chip
= LGDT3303
,
713 .serial_mpeg
= 0x00, /* PARALLEL */
714 .clock_polarity_flip
= 1,
717 static struct mt2131_config m780_tunerconfig
= {
721 /* A single func to attach the demo and tuner, rather than
722 * use two sep funcs like the current design mandates.
724 static int demod_attach_lg330x(struct ngene_channel
*chan
)
726 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
728 chan
->fe
= dvb_attach(lgdt330x_attach
, &aver_m780
,
729 0xb2 >> 1, &chan
->i2c_adapter
);
730 if (chan
->fe
== NULL
) {
731 dev_err(pdev
, "No LGDT330x found!\n");
735 dvb_attach(mt2131_attach
, chan
->fe
, &chan
->i2c_adapter
,
736 &m780_tunerconfig
, 0);
738 return (chan
->fe
) ? 0 : -ENODEV
;
741 static int demod_attach_drxd(struct ngene_channel
*chan
)
743 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
744 struct drxd_config
*feconf
;
746 feconf
= chan
->dev
->card_info
->fe_config
[chan
->number
];
748 chan
->fe
= dvb_attach(drxd_attach
, feconf
, chan
,
749 &chan
->i2c_adapter
, &chan
->dev
->pci_dev
->dev
);
751 dev_err(pdev
, "No DRXD found!\n");
757 static int tuner_attach_dtt7520x(struct ngene_channel
*chan
)
759 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
760 struct drxd_config
*feconf
;
762 feconf
= chan
->dev
->card_info
->fe_config
[chan
->number
];
764 if (!dvb_attach(dvb_pll_attach
, chan
->fe
, feconf
->pll_address
,
767 dev_err(pdev
, "No pll(%d) found!\n", feconf
->pll_type
);
773 /****************************************************************************/
774 /* EEPROM TAGS **************************************************************/
775 /****************************************************************************/
777 #define MICNG_EE_START 0x0100
778 #define MICNG_EE_END 0x0FF0
780 #define MICNG_EETAG_END0 0x0000
781 #define MICNG_EETAG_END1 0xFFFF
783 /* 0x0001 - 0x000F reserved for housekeeping */
784 /* 0xFFFF - 0xFFFE reserved for housekeeping */
786 /* Micronas assigned tags
787 EEProm tags for hardware support */
789 #define MICNG_EETAG_DRXD1_OSCDEVIATION 0x1000 /* 2 Bytes data */
790 #define MICNG_EETAG_DRXD2_OSCDEVIATION 0x1001 /* 2 Bytes data */
792 #define MICNG_EETAG_MT2060_1_1STIF 0x1100 /* 2 Bytes data */
793 #define MICNG_EETAG_MT2060_2_1STIF 0x1101 /* 2 Bytes data */
795 /* Tag range for OEMs */
797 #define MICNG_EETAG_OEM_FIRST 0xC000
798 #define MICNG_EETAG_OEM_LAST 0xFFEF
800 static int i2c_write_eeprom(struct i2c_adapter
*adapter
,
801 u8 adr
, u16 reg
, u8 data
)
803 struct device
*pdev
= adapter
->dev
.parent
;
804 u8 m
[3] = {(reg
>> 8), (reg
& 0xff), data
};
805 struct i2c_msg msg
= {.addr
= adr
, .flags
= 0, .buf
= m
,
808 if (i2c_transfer(adapter
, &msg
, 1) != 1) {
809 dev_err(pdev
, "Error writing EEPROM!\n");
815 static int i2c_read_eeprom(struct i2c_adapter
*adapter
,
816 u8 adr
, u16 reg
, u8
*data
, int len
)
818 struct device
*pdev
= adapter
->dev
.parent
;
819 u8 msg
[2] = {(reg
>> 8), (reg
& 0xff)};
820 struct i2c_msg msgs
[2] = {{.addr
= adr
, .flags
= 0,
821 .buf
= msg
, .len
= 2 },
822 {.addr
= adr
, .flags
= I2C_M_RD
,
823 .buf
= data
, .len
= len
} };
825 if (i2c_transfer(adapter
, msgs
, 2) != 2) {
826 dev_err(pdev
, "Error reading EEPROM\n");
832 static int ReadEEProm(struct i2c_adapter
*adapter
,
833 u16 Tag
, u32 MaxLen
, u8
*data
, u32
*pLength
)
835 struct device
*pdev
= adapter
->dev
.parent
;
837 u16 Addr
= MICNG_EE_START
, Length
, tag
= 0;
840 while (Addr
+ sizeof(u16
) + 1 < MICNG_EE_END
) {
841 if (i2c_read_eeprom(adapter
, 0x50, Addr
, EETag
, sizeof(EETag
)))
843 tag
= (EETag
[0] << 8) | EETag
[1];
844 if (tag
== MICNG_EETAG_END0
|| tag
== MICNG_EETAG_END1
)
848 Addr
+= sizeof(u16
) + 1 + EETag
[2];
850 if (Addr
+ sizeof(u16
) + 1 + EETag
[2] > MICNG_EE_END
) {
851 dev_err(pdev
, "Reached EOEE @ Tag = %04x Length = %3d\n",
857 Length
= (u16
) MaxLen
;
859 Addr
+= sizeof(u16
) + 1;
860 status
= i2c_read_eeprom(adapter
, 0x50, Addr
, data
, Length
);
864 if (Length
< EETag
[2])
865 status
= STATUS_BUFFER_OVERFLOW
;
872 static int WriteEEProm(struct i2c_adapter
*adapter
,
873 u16 Tag
, u32 Length
, u8
*data
)
875 struct device
*pdev
= adapter
->dev
.parent
;
877 u16 Addr
= MICNG_EE_START
;
882 while (Addr
+ sizeof(u16
) + 1 < MICNG_EE_END
) {
883 if (i2c_read_eeprom(adapter
, 0x50, Addr
, EETag
, sizeof(EETag
)))
885 tag
= (EETag
[0] << 8) | EETag
[1];
886 if (tag
== MICNG_EETAG_END0
|| tag
== MICNG_EETAG_END1
)
890 Addr
+= sizeof(u16
) + 1 + EETag
[2];
892 if (Addr
+ sizeof(u16
) + 1 + EETag
[2] > MICNG_EE_END
) {
893 dev_err(pdev
, "Reached EOEE @ Tag = %04x Length = %3d\n",
898 if (Length
> EETag
[2])
900 /* Note: We write the data one byte at a time to avoid
901 issues with page sizes. (which are different for
902 each manufacture and eeprom size)
904 Addr
+= sizeof(u16
) + 1;
905 for (i
= 0; i
< Length
; i
++, Addr
++) {
906 status
= i2c_write_eeprom(adapter
, 0x50, Addr
, data
[i
]);
911 /* Poll for finishing write cycle */
917 status
= i2c_read_eeprom(adapter
, 0x50, Addr
, &Tmp
, 1);
921 dev_err(pdev
, "eeprom write error\n");
925 dev_err(pdev
, "Timeout polling eeprom\n");
932 static int eeprom_read_ushort(struct i2c_adapter
*adapter
, u16 tag
, u16
*data
)
938 stat
= ReadEEProm(adapter
, tag
, 2, buf
, &len
);
944 *data
= (buf
[0] << 8) | buf
[1];
948 static int eeprom_write_ushort(struct i2c_adapter
*adapter
, u16 tag
, u16 data
)
954 buf
[1] = data
& 0xff;
955 stat
= WriteEEProm(adapter
, tag
, 2, buf
);
961 static s16
osc_deviation(void *priv
, s16 deviation
, int flag
)
963 struct ngene_channel
*chan
= priv
;
964 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
965 struct i2c_adapter
*adap
= &chan
->i2c_adapter
;
969 data
= (u16
) deviation
;
970 dev_info(pdev
, "write deviation %d\n",
972 eeprom_write_ushort(adap
, 0x1000 + chan
->number
, data
);
974 if (eeprom_read_ushort(adap
, 0x1000 + chan
->number
, &data
))
976 dev_info(pdev
, "read deviation %d\n",
983 /****************************************************************************/
984 /* Switch control (I2C gates, etc.) *****************************************/
985 /****************************************************************************/
988 static struct stv090x_config fe_cineS2
= {
990 .demod_mode
= STV090x_DUAL
,
991 .clk_mode
= STV090x_CLK_EXT
,
996 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
997 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
999 .repeater_level
= STV090x_RPTLEVEL_16
,
1001 .adc1_range
= STV090x_ADC_1Vpp
,
1002 .adc2_range
= STV090x_ADC_1Vpp
,
1004 .diseqc_envelope_mode
= true,
1006 .tuner_i2c_lock
= cineS2_tuner_i2c_lock
,
1009 static struct stv090x_config fe_cineS2_2
= {
1011 .demod_mode
= STV090x_DUAL
,
1012 .clk_mode
= STV090x_CLK_EXT
,
1017 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1018 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1020 .repeater_level
= STV090x_RPTLEVEL_16
,
1022 .adc1_range
= STV090x_ADC_1Vpp
,
1023 .adc2_range
= STV090x_ADC_1Vpp
,
1025 .diseqc_envelope_mode
= true,
1027 .tuner_i2c_lock
= cineS2_tuner_i2c_lock
,
1030 static struct stv6110x_config tuner_cineS2_0
= {
1036 static struct stv6110x_config tuner_cineS2_1
= {
1042 static const struct ngene_info ngene_info_cineS2
= {
1043 .type
= NGENE_SIDEWINDER
,
1044 .name
= "Linux4Media cineS2 DVB-S2 Twin Tuner",
1045 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
},
1046 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
},
1047 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
},
1048 .fe_config
= {&fe_cineS2
, &fe_cineS2
},
1049 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
},
1050 .lnb
= {0x0b, 0x08},
1053 .msi_supported
= true,
1056 static const struct ngene_info ngene_info_satixS2
= {
1057 .type
= NGENE_SIDEWINDER
,
1058 .name
= "Mystique SaTiX-S2 Dual",
1059 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
},
1060 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
},
1061 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
},
1062 .fe_config
= {&fe_cineS2
, &fe_cineS2
},
1063 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
},
1064 .lnb
= {0x0b, 0x08},
1067 .msi_supported
= true,
1070 static const struct ngene_info ngene_info_satixS2v2
= {
1071 .type
= NGENE_SIDEWINDER
,
1072 .name
= "Mystique SaTiX-S2 Dual (v2)",
1073 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
,
1075 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
, cineS2_probe
, cineS2_probe
},
1076 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_probe
, tuner_attach_probe
},
1077 .fe_config
= {&fe_cineS2
, &fe_cineS2
, &fe_cineS2_2
, &fe_cineS2_2
},
1078 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
, &tuner_cineS2_0
, &tuner_cineS2_1
},
1079 .lnb
= {0x0a, 0x08, 0x0b, 0x09},
1082 .msi_supported
= true,
1085 static const struct ngene_info ngene_info_cineS2v5
= {
1086 .type
= NGENE_SIDEWINDER
,
1087 .name
= "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
1088 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
,
1090 .demod_attach
= {demod_attach_stv0900
, demod_attach_stv0900
, cineS2_probe
, cineS2_probe
},
1091 .tuner_attach
= {tuner_attach_stv6110
, tuner_attach_stv6110
, tuner_attach_probe
, tuner_attach_probe
},
1092 .fe_config
= {&fe_cineS2
, &fe_cineS2
, &fe_cineS2_2
, &fe_cineS2_2
},
1093 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
, &tuner_cineS2_0
, &tuner_cineS2_1
},
1094 .lnb
= {0x0a, 0x08, 0x0b, 0x09},
1097 .msi_supported
= true,
1101 static const struct ngene_info ngene_info_duoFlex
= {
1102 .type
= NGENE_SIDEWINDER
,
1103 .name
= "Digital Devices DuoFlex PCIe or miniPCIe",
1104 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
, NGENE_IO_TSIN
,
1106 .demod_attach
= {cineS2_probe
, cineS2_probe
, cineS2_probe
, cineS2_probe
},
1107 .tuner_attach
= {tuner_attach_probe
, tuner_attach_probe
, tuner_attach_probe
, tuner_attach_probe
},
1108 .fe_config
= {&fe_cineS2
, &fe_cineS2
, &fe_cineS2_2
, &fe_cineS2_2
},
1109 .tuner_config
= {&tuner_cineS2_0
, &tuner_cineS2_1
, &tuner_cineS2_0
, &tuner_cineS2_1
},
1110 .lnb
= {0x0a, 0x08, 0x0b, 0x09},
1113 .msi_supported
= true,
1116 static const struct ngene_info ngene_info_m780
= {
1118 .name
= "Aver M780 ATSC/QAM-B",
1120 /* Channel 0 is analog, which is currently unsupported */
1121 .io_type
= { NGENE_IO_NONE
, NGENE_IO_TSIN
},
1122 .demod_attach
= { NULL
, demod_attach_lg330x
},
1124 /* Ensure these are NULL else the frame will call them (as funcs) */
1125 .tuner_attach
= { NULL
, NULL
, NULL
, NULL
},
1126 .fe_config
= { NULL
, &aver_m780
},
1129 /* A custom electrical interface config for the demod to bridge */
1134 static struct drxd_config fe_terratec_dvbt_0
= {
1136 .demod_address
= 0x70,
1137 .demod_revision
= 0xa2,
1138 .demoda_address
= 0x00,
1139 .pll_address
= 0x60,
1140 .pll_type
= DVB_PLL_THOMSON_DTT7520X
,
1142 .osc_deviation
= osc_deviation
,
1145 static struct drxd_config fe_terratec_dvbt_1
= {
1147 .demod_address
= 0x71,
1148 .demod_revision
= 0xa2,
1149 .demoda_address
= 0x00,
1150 .pll_address
= 0x60,
1151 .pll_type
= DVB_PLL_THOMSON_DTT7520X
,
1153 .osc_deviation
= osc_deviation
,
1156 static const struct ngene_info ngene_info_terratec
= {
1157 .type
= NGENE_TERRATEC
,
1158 .name
= "Terratec Integra/Cinergy2400i Dual DVB-T",
1159 .io_type
= {NGENE_IO_TSIN
, NGENE_IO_TSIN
},
1160 .demod_attach
= {demod_attach_drxd
, demod_attach_drxd
},
1161 .tuner_attach
= {tuner_attach_dtt7520x
, tuner_attach_dtt7520x
},
1162 .fe_config
= {&fe_terratec_dvbt_0
, &fe_terratec_dvbt_1
},
1166 /****************************************************************************/
1170 /****************************************************************************/
1171 /* PCI Subsystem ID *********************************************************/
1172 /****************************************************************************/
1174 #define NGENE_ID(_subvend, _subdev, _driverdata) { \
1175 .vendor = NGENE_VID, .device = NGENE_PID, \
1176 .subvendor = _subvend, .subdevice = _subdev, \
1177 .driver_data = (unsigned long) &_driverdata }
1179 /****************************************************************************/
1181 static const struct pci_device_id ngene_id_tbl
[] = {
1182 NGENE_ID(0x18c3, 0xab04, ngene_info_cineS2
),
1183 NGENE_ID(0x18c3, 0xab05, ngene_info_cineS2v5
),
1184 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2
),
1185 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2
),
1186 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2
),
1187 NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2
),
1188 NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5
),
1189 NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex
),
1190 NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex
),
1191 NGENE_ID(0x1461, 0x062e, ngene_info_m780
),
1192 NGENE_ID(0x153b, 0x1167, ngene_info_terratec
),
1195 MODULE_DEVICE_TABLE(pci
, ngene_id_tbl
);
1197 /****************************************************************************/
1198 /* Init/Exit ****************************************************************/
1199 /****************************************************************************/
1201 static pci_ers_result_t
ngene_error_detected(struct pci_dev
*dev
,
1202 enum pci_channel_state state
)
1204 dev_err(&dev
->dev
, "PCI error\n");
1205 if (state
== pci_channel_io_perm_failure
)
1206 return PCI_ERS_RESULT_DISCONNECT
;
1207 if (state
== pci_channel_io_frozen
)
1208 return PCI_ERS_RESULT_NEED_RESET
;
1209 return PCI_ERS_RESULT_CAN_RECOVER
;
1212 static pci_ers_result_t
ngene_slot_reset(struct pci_dev
*dev
)
1214 dev_info(&dev
->dev
, "slot reset\n");
1218 static void ngene_resume(struct pci_dev
*dev
)
1220 dev_info(&dev
->dev
, "resume\n");
1223 static const struct pci_error_handlers ngene_errors
= {
1224 .error_detected
= ngene_error_detected
,
1225 .slot_reset
= ngene_slot_reset
,
1226 .resume
= ngene_resume
,
1229 static struct pci_driver ngene_pci_driver
= {
1231 .id_table
= ngene_id_tbl
,
1232 .probe
= ngene_probe
,
1233 .remove
= ngene_remove
,
1234 .err_handler
= &ngene_errors
,
1235 .shutdown
= ngene_shutdown
,
1238 static __init
int module_init_ngene(void)
1240 /* pr_*() since we don't have a device to use with dev_*() yet */
1241 pr_info("nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
1243 return pci_register_driver(&ngene_pci_driver
);
1246 static __exit
void module_exit_ngene(void)
1248 pci_unregister_driver(&ngene_pci_driver
);
1251 module_init(module_init_ngene
);
1252 module_exit(module_exit_ngene
);
1254 MODULE_DESCRIPTION("nGene");
1255 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
1256 MODULE_LICENSE("GPL");