1 // SPDX-License-Identifier: GPL-2.0-only
3 * ngene-cards.c: nGene PCIe bridge driver - card specific info
5 * Copyright (C) 2005-2007 Micronas
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
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/pci.h>
18 #include <linux/pci_ids.h>
28 #include "tda18271c2dd.h"
33 #include "stv0367_priv.h"
35 #include "cxd2841er.h"
40 /****************************************************************************/
41 /* I2C transfer functions used for demod/tuner probing***********************/
42 /****************************************************************************/
44 static int i2c_io(struct i2c_adapter
*adapter
, u8 adr
,
45 u8
*wbuf
, u32 wlen
, u8
*rbuf
, u32 rlen
)
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;
54 static int i2c_write(struct i2c_adapter
*adap
, u8 adr
, u8
*data
, int len
)
56 struct i2c_msg msg
= {.addr
= adr
, .flags
= 0,
57 .buf
= data
, .len
= len
};
59 return (i2c_transfer(adap
, &msg
, 1) == 1) ? 0 : -1;
62 static int i2c_write_reg(struct i2c_adapter
*adap
, u8 adr
,
65 u8 msg
[2] = {reg
, val
};
67 return i2c_write(adap
, adr
, msg
, 2);
70 static int i2c_read(struct i2c_adapter
*adapter
, u8 adr
, u8
*val
)
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;
77 static int i2c_read_reg16(struct i2c_adapter
*adapter
, u8 adr
,
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;
88 static int i2c_read_regs(struct i2c_adapter
*adapter
,
89 u8 adr
, u8 reg
, u8
*val
, u8 len
)
91 struct i2c_msg msgs
[2] = {{.addr
= adr
, .flags
= 0,
92 .buf
= ®
, .len
= 1},
93 {.addr
= adr
, .flags
= I2C_M_RD
,
94 .buf
= val
, .len
= len
} };
96 return (i2c_transfer(adapter
, msgs
, 2) == 2) ? 0 : -1;
99 static int i2c_read_reg(struct i2c_adapter
*adapter
, u8 adr
, u8 reg
, u8
*val
)
101 return i2c_read_regs(adapter
, adr
, reg
, val
, 1);
104 /****************************************************************************/
105 /* Demod/tuner attachment ***************************************************/
106 /****************************************************************************/
108 static struct i2c_adapter
*i2c_adapter_from_chan(struct ngene_channel
*chan
)
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
;
114 return &chan
->dev
->channel
[1].i2c_adapter
;
117 static int tuner_attach_stv6110(struct ngene_channel
*chan
)
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
;
127 ctl
= dvb_attach(stv6110x_attach
, chan
->fe
, tunerconf
, i2c
);
129 dev_err(pdev
, "No STV6110X found!\n");
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
;
148 static int tuner_attach_stv6111(struct ngene_channel
*chan
)
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);
155 fe
= dvb_attach(stv6111_attach
, chan
->fe
, i2c
, adr
);
157 fe
= dvb_attach(stv6111_attach
, chan
->fe
, i2c
, adr
& ~4);
159 dev_err(pdev
, "stv6111_attach() failed!\n");
166 static int drxk_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
168 struct ngene_channel
*chan
= fe
->sec_priv
;
172 down(&chan
->dev
->pll_mutex
);
173 status
= chan
->gate_ctrl(fe
, 1);
175 status
= chan
->gate_ctrl(fe
, 0);
176 up(&chan
->dev
->pll_mutex
);
181 static int tuner_attach_tda18271(struct ngene_channel
*chan
)
183 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
184 struct i2c_adapter
*i2c
= i2c_adapter_from_chan(chan
);
185 struct dvb_frontend
*fe
;
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);
193 dev_err(pdev
, "No TDA18271 found!\n");
200 static int tuner_tda18212_ping(struct ngene_channel
*chan
,
201 struct i2c_adapter
*i2c
,
204 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
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);
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");
217 if (chan
->fe
->ops
.i2c_gate_ctrl
)
218 chan
->fe
->ops
.i2c_gate_ctrl(chan
->fe
, 0);
223 static int tuner_attach_tda18212(struct ngene_channel
*chan
, u32 dmdtype
)
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
= {
238 u8 addr
= (chan
->number
& 1) ? 0x63 : 0x60;
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.
245 if (dmdtype
== DEMOD_TYPE_STV0367
)
246 tuner_tda18212_ping(chan
, i2c
, addr
);
248 /* perform tuner probe/init/attach */
249 client
= dvb_module_probe("tda18212", NULL
, i2c
, addr
, &config
);
253 chan
->i2c_client
[0] = client
;
254 chan
->i2c_client_fe
= 1;
258 dev_err(pdev
, "TDA18212 tuner not found. Device is not fully operational.\n");
262 static int tuner_attach_probe(struct ngene_channel
*chan
)
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
);
282 static int demod_attach_stv0900(struct ngene_channel
*chan
)
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
];
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");
297 /* store channel info */
298 if (feconf
->tuner_i2c_lock
)
299 chan
->fe
->analog_demod_priv
= chan
;
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
);
312 static struct stv0910_cfg stv0910_p
= {
320 static struct lnbh25_config lnbh25_cfg
= {
321 .i2c_address
= 0x0c << 1,
322 .data2_config
= LNBH25_TEN
325 static int demod_attach_stv0910(struct ngene_channel
*chan
,
326 struct i2c_adapter
*i2c
)
328 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
329 struct stv0910_cfg cfg
= stv0910_p
;
330 struct lnbh25_config lnbcfg
= lnbh25_cfg
;
332 chan
->fe
= dvb_attach(stv0910_attach
, i2c
, &cfg
, (chan
->number
& 1));
335 chan
->fe
= dvb_attach(stv0910_attach
, i2c
,
336 &cfg
, (chan
->number
& 1));
339 dev_err(pdev
, "stv0910_attach() failed!\n");
344 * attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
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
);
361 static struct stv0367_config ddb_stv0367_config
[] = {
363 .demod_address
= 0x1f,
366 .if_iq_mode
= FE_TER_NORMAL_IF_TUNER
,
367 .ts_mode
= STV0367_SERIAL_PUNCT_CLOCK
,
368 .clk_pol
= STV0367_CLOCKPOLARITY_DEFAULT
,
370 .demod_address
= 0x1e,
373 .if_iq_mode
= FE_TER_NORMAL_IF_TUNER
,
374 .ts_mode
= STV0367_SERIAL_PUNCT_CLOCK
,
375 .clk_pol
= STV0367_CLOCKPOLARITY_DEFAULT
,
379 static int demod_attach_stv0367(struct ngene_channel
*chan
,
380 struct i2c_adapter
*i2c
)
382 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
384 chan
->fe
= dvb_attach(stv0367ddb_attach
,
385 &ddb_stv0367_config
[(chan
->number
& 1)], i2c
);
388 dev_err(pdev
, "stv0367ddb_attach() failed!\n");
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
;
398 static int demod_attach_cxd28xx(struct ngene_channel
*chan
,
399 struct i2c_adapter
*i2c
, int osc24
)
401 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
402 struct cxd2841er_config cfg
;
404 /* the cxd2841er driver expects 8bit/shifted I2C addresses */
405 cfg
.i2c_addr
= ((chan
->number
& 1) ? 0x6d : 0x6c) << 1;
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
;
412 /* attach frontend */
413 chan
->fe
= dvb_attach(cxd2841er_attach_t_c
, &cfg
, i2c
);
416 dev_err(pdev
, "CXD28XX attach failed!\n");
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
;
426 static void cineS2_tuner_i2c_lock(struct dvb_frontend
*fe
, int lock
)
428 struct ngene_channel
*chan
= fe
->analog_demod_priv
;
431 down(&chan
->dev
->pll_mutex
);
433 up(&chan
->dev
->pll_mutex
);
436 static int port_has_stv0900(struct i2c_adapter
*i2c
, int port
)
439 if (i2c_read_reg16(i2c
, 0x68+port
/2, 0xf100, &val
) < 0)
444 static int port_has_drxk(struct i2c_adapter
*i2c
, int port
)
448 if (i2c_read(i2c
, 0x29+port
, &val
) < 0)
453 static int port_has_stv0367(struct i2c_adapter
*i2c
)
457 if (i2c_read_reg16(i2c
, 0x1e, 0xf000, &val
) < 0)
461 if (i2c_read_reg16(i2c
, 0x1f, 0xf000, &val
) < 0)
468 int ngene_port_has_cxd2099(struct i2c_adapter
*i2c
, u8
*type
)
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);
480 if (data
[0] == 0x02 && data
[1] == 0x2b && data
[3] == 0x43)
487 static int demod_attach_drxk(struct ngene_channel
*chan
,
488 struct i2c_adapter
*i2c
)
490 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
491 struct drxk_config config
;
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);
498 chan
->fe
= dvb_attach(drxk_attach
, &config
, i2c
);
500 dev_err(pdev
, "No DRXK found!\n");
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
;
509 /****************************************************************************/
510 /* XO2 related lists and functions ******************************************/
511 /****************************************************************************/
513 static char *xo2names
[] = {
517 "DUAL DVB-C/C2/T/T2",
519 "DUAL DVB-C/C2/T/T2/I",
522 static int init_xo2(struct ngene_channel
*chan
, struct i2c_adapter
*i2c
)
524 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
529 res
= i2c_read_regs(i2c
, addr
, 0x04, data
, 2);
533 if (data
[0] != 0x01) {
534 dev_info(pdev
, "Invalid XO2 on channel %d\n", chan
->number
);
538 i2c_read_reg(i2c
, addr
, 0x08, &val
);
540 i2c_write_reg(i2c
, addr
, 0x08, 0x00);
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);
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.
556 i2c_write_reg(i2c
, addr
, 0x09, 1);
558 i2c_write_reg(i2c
, addr
, 0x0a, 0x01);
559 i2c_write_reg(i2c
, addr
, 0x0b, 0x01);
561 usleep_range(2000, 3000);
563 i2c_write_reg(i2c
, addr
, 0x08, 0x87);
568 static int port_has_xo2(struct i2c_adapter
*i2c
, u8
*type
, u8
*id
)
570 u8 probe
[1] = { 0x00 }, data
[4];
573 *type
= NGENE_XO2_TYPE_NONE
;
575 if (i2c_io(i2c
, addr
, probe
, 1, data
, 4))
577 if (data
[0] == 'D' && data
[1] == 'F') {
579 *type
= NGENE_XO2_TYPE_DUOFLEX
;
582 if (data
[0] == 'C' && data
[1] == 'I') {
584 *type
= NGENE_XO2_TYPE_CI
;
590 /****************************************************************************/
591 /* Probing and port/channel handling ****************************************/
592 /****************************************************************************/
594 static int cineS2_probe(struct ngene_channel
*chan
)
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
;
600 u8 xo2_type
, xo2_id
, xo2_demodtype
;
602 struct i2c_msg i2c_msg
= { .flags
= 0, .buf
= buf
};
605 if (port_has_xo2(i2c
, &xo2_type
, &xo2_id
)) {
607 dev_dbg(pdev
, "XO2 on channel %d (type %d, id %d)\n",
608 chan
->number
, xo2_type
, xo2_id
);
611 case NGENE_XO2_TYPE_DUOFLEX
:
612 if (chan
->number
& 1)
614 "skipping XO2 init on odd channel %d",
619 xo2_demodtype
= DEMOD_TYPE_XO2
+ xo2_id
;
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
)
632 demod_attach_cxd28xx(chan
, i2c
, sony_osc24
);
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
);
642 "Unsupported XO2 module on channel %d\n",
647 case NGENE_XO2_TYPE_CI
:
648 dev_info(pdev
, "DuoFlex CI modules not supported\n");
651 dev_info(pdev
, "Unsupported XO2 module type\n");
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)
662 /* demod #2: reprogram outputs DPN1 & DPN2 */
663 i2c_msg
.addr
= fe_conf
->address
;
666 switch (chan
->number
) {
678 rc
= i2c_transfer(i2c
, &i2c_msg
, 1);
680 dev_err(pdev
, "Could not setup DPNx\n");
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
);
691 dev_info(pdev
, "No demod found on chan %d\n", chan
->number
);
698 static struct lgdt330x_config aver_m780
= {
699 .demod_chip
= LGDT3303
,
700 .serial_mpeg
= 0x00, /* PARALLEL */
701 .clock_polarity_flip
= 1,
704 static struct mt2131_config m780_tunerconfig
= {
708 /* A single func to attach the demo and tuner, rather than
709 * use two sep funcs like the current design mandates.
711 static int demod_attach_lg330x(struct ngene_channel
*chan
)
713 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
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");
722 dvb_attach(mt2131_attach
, chan
->fe
, &chan
->i2c_adapter
,
723 &m780_tunerconfig
, 0);
725 return (chan
->fe
) ? 0 : -ENODEV
;
728 static int demod_attach_drxd(struct ngene_channel
*chan
)
730 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
731 struct drxd_config
*feconf
;
733 feconf
= chan
->dev
->card_info
->fe_config
[chan
->number
];
735 chan
->fe
= dvb_attach(drxd_attach
, feconf
, chan
,
736 &chan
->i2c_adapter
, &chan
->dev
->pci_dev
->dev
);
738 dev_err(pdev
, "No DRXD found!\n");
744 static int tuner_attach_dtt7520x(struct ngene_channel
*chan
)
746 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
747 struct drxd_config
*feconf
;
749 feconf
= chan
->dev
->card_info
->fe_config
[chan
->number
];
751 if (!dvb_attach(dvb_pll_attach
, chan
->fe
, feconf
->pll_address
,
754 dev_err(pdev
, "No pll(%d) found!\n", feconf
->pll_type
);
760 /****************************************************************************/
761 /* EEPROM TAGS **************************************************************/
762 /****************************************************************************/
764 #define MICNG_EE_START 0x0100
765 #define MICNG_EE_END 0x0FF0
767 #define MICNG_EETAG_END0 0x0000
768 #define MICNG_EETAG_END1 0xFFFF
770 /* 0x0001 - 0x000F reserved for housekeeping */
771 /* 0xFFFF - 0xFFFE reserved for housekeeping */
773 /* Micronas assigned tags
774 EEProm tags for hardware support */
776 #define MICNG_EETAG_DRXD1_OSCDEVIATION 0x1000 /* 2 Bytes data */
777 #define MICNG_EETAG_DRXD2_OSCDEVIATION 0x1001 /* 2 Bytes data */
779 #define MICNG_EETAG_MT2060_1_1STIF 0x1100 /* 2 Bytes data */
780 #define MICNG_EETAG_MT2060_2_1STIF 0x1101 /* 2 Bytes data */
782 /* Tag range for OEMs */
784 #define MICNG_EETAG_OEM_FIRST 0xC000
785 #define MICNG_EETAG_OEM_LAST 0xFFEF
787 static int i2c_write_eeprom(struct i2c_adapter
*adapter
,
788 u8 adr
, u16 reg
, u8 data
)
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
,
795 if (i2c_transfer(adapter
, &msg
, 1) != 1) {
796 dev_err(pdev
, "Error writing EEPROM!\n");
802 static int i2c_read_eeprom(struct i2c_adapter
*adapter
,
803 u8 adr
, u16 reg
, u8
*data
, int len
)
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
} };
812 if (i2c_transfer(adapter
, msgs
, 2) != 2) {
813 dev_err(pdev
, "Error reading EEPROM\n");
819 static int ReadEEProm(struct i2c_adapter
*adapter
,
820 u16 Tag
, u32 MaxLen
, u8
*data
, u32
*pLength
)
822 struct device
*pdev
= adapter
->dev
.parent
;
824 u16 Addr
= MICNG_EE_START
, Length
, tag
= 0;
827 while (Addr
+ sizeof(u16
) + 1 < MICNG_EE_END
) {
828 if (i2c_read_eeprom(adapter
, 0x50, Addr
, EETag
, sizeof(EETag
)))
830 tag
= (EETag
[0] << 8) | EETag
[1];
831 if (tag
== MICNG_EETAG_END0
|| tag
== MICNG_EETAG_END1
)
835 Addr
+= sizeof(u16
) + 1 + EETag
[2];
837 if (Addr
+ sizeof(u16
) + 1 + EETag
[2] > MICNG_EE_END
) {
838 dev_err(pdev
, "Reached EOEE @ Tag = %04x Length = %3d\n",
844 Length
= (u16
) MaxLen
;
846 Addr
+= sizeof(u16
) + 1;
847 status
= i2c_read_eeprom(adapter
, 0x50, Addr
, data
, Length
);
851 if (Length
< EETag
[2])
852 status
= STATUS_BUFFER_OVERFLOW
;
859 static int WriteEEProm(struct i2c_adapter
*adapter
,
860 u16 Tag
, u32 Length
, u8
*data
)
862 struct device
*pdev
= adapter
->dev
.parent
;
864 u16 Addr
= MICNG_EE_START
;
869 while (Addr
+ sizeof(u16
) + 1 < MICNG_EE_END
) {
870 if (i2c_read_eeprom(adapter
, 0x50, Addr
, EETag
, sizeof(EETag
)))
872 tag
= (EETag
[0] << 8) | EETag
[1];
873 if (tag
== MICNG_EETAG_END0
|| tag
== MICNG_EETAG_END1
)
877 Addr
+= sizeof(u16
) + 1 + EETag
[2];
879 if (Addr
+ sizeof(u16
) + 1 + EETag
[2] > MICNG_EE_END
) {
880 dev_err(pdev
, "Reached EOEE @ Tag = %04x Length = %3d\n",
885 if (Length
> EETag
[2])
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)
891 Addr
+= sizeof(u16
) + 1;
892 for (i
= 0; i
< Length
; i
++, Addr
++) {
893 status
= i2c_write_eeprom(adapter
, 0x50, Addr
, data
[i
]);
898 /* Poll for finishing write cycle */
904 status
= i2c_read_eeprom(adapter
, 0x50, Addr
, &Tmp
, 1);
908 dev_err(pdev
, "eeprom write error\n");
912 dev_err(pdev
, "Timeout polling eeprom\n");
919 static int eeprom_read_ushort(struct i2c_adapter
*adapter
, u16 tag
, u16
*data
)
925 stat
= ReadEEProm(adapter
, tag
, 2, buf
, &len
);
931 *data
= (buf
[0] << 8) | buf
[1];
935 static int eeprom_write_ushort(struct i2c_adapter
*adapter
, u16 tag
, u16 data
)
941 buf
[1] = data
& 0xff;
942 stat
= WriteEEProm(adapter
, tag
, 2, buf
);
948 static s16
osc_deviation(void *priv
, s16 deviation
, int flag
)
950 struct ngene_channel
*chan
= priv
;
951 struct device
*pdev
= &chan
->dev
->pci_dev
->dev
;
952 struct i2c_adapter
*adap
= &chan
->i2c_adapter
;
956 data
= (u16
) deviation
;
957 dev_info(pdev
, "write deviation %d\n",
959 eeprom_write_ushort(adap
, 0x1000 + chan
->number
, data
);
961 if (eeprom_read_ushort(adap
, 0x1000 + chan
->number
, &data
))
963 dev_info(pdev
, "read deviation %d\n",
970 /****************************************************************************/
971 /* Switch control (I2C gates, etc.) *****************************************/
972 /****************************************************************************/
975 static struct stv090x_config fe_cineS2
= {
977 .demod_mode
= STV090x_DUAL
,
978 .clk_mode
= STV090x_CLK_EXT
,
983 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
984 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
986 .repeater_level
= STV090x_RPTLEVEL_16
,
988 .adc1_range
= STV090x_ADC_1Vpp
,
989 .adc2_range
= STV090x_ADC_1Vpp
,
991 .diseqc_envelope_mode
= true,
993 .tuner_i2c_lock
= cineS2_tuner_i2c_lock
,
996 static struct stv090x_config fe_cineS2_2
= {
998 .demod_mode
= STV090x_DUAL
,
999 .clk_mode
= STV090x_CLK_EXT
,
1004 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1005 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1007 .repeater_level
= STV090x_RPTLEVEL_16
,
1009 .adc1_range
= STV090x_ADC_1Vpp
,
1010 .adc2_range
= STV090x_ADC_1Vpp
,
1012 .diseqc_envelope_mode
= true,
1014 .tuner_i2c_lock
= cineS2_tuner_i2c_lock
,
1017 static struct stv6110x_config tuner_cineS2_0
= {
1023 static struct stv6110x_config tuner_cineS2_1
= {
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},
1040 .msi_supported
= true,
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},
1054 .msi_supported
= true,
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
,
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},
1069 .msi_supported
= true,
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
,
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},
1084 .msi_supported
= true,
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
,
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},
1100 .msi_supported
= true,
1103 static const struct ngene_info ngene_info_m780
= {
1105 .name
= "Aver M780 ATSC/QAM-B",
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
},
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
},
1116 /* A custom electrical interface config for the demod to bridge */
1121 static struct drxd_config fe_terratec_dvbt_0
= {
1123 .demod_address
= 0x70,
1124 .demod_revision
= 0xa2,
1125 .demoda_address
= 0x00,
1126 .pll_address
= 0x60,
1127 .pll_type
= DVB_PLL_THOMSON_DTT7520X
,
1129 .osc_deviation
= osc_deviation
,
1132 static struct drxd_config fe_terratec_dvbt_1
= {
1134 .demod_address
= 0x71,
1135 .demod_revision
= 0xa2,
1136 .demoda_address
= 0x00,
1137 .pll_address
= 0x60,
1138 .pll_type
= DVB_PLL_THOMSON_DTT7520X
,
1140 .osc_deviation
= osc_deviation
,
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
},
1153 /****************************************************************************/
1157 /****************************************************************************/
1158 /* PCI Subsystem ID *********************************************************/
1159 /****************************************************************************/
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 }
1166 /****************************************************************************/
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
),
1182 MODULE_DEVICE_TABLE(pci
, ngene_id_tbl
);
1184 /****************************************************************************/
1185 /* Init/Exit ****************************************************************/
1186 /****************************************************************************/
1188 static pci_ers_result_t
ngene_error_detected(struct pci_dev
*dev
,
1189 pci_channel_state_t state
)
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
;
1199 static pci_ers_result_t
ngene_slot_reset(struct pci_dev
*dev
)
1201 dev_info(&dev
->dev
, "slot reset\n");
1205 static void ngene_resume(struct pci_dev
*dev
)
1207 dev_info(&dev
->dev
, "resume\n");
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
,
1216 static struct pci_driver ngene_pci_driver
= {
1218 .id_table
= ngene_id_tbl
,
1219 .probe
= ngene_probe
,
1220 .remove
= ngene_remove
,
1221 .err_handler
= &ngene_errors
,
1222 .shutdown
= ngene_shutdown
,
1225 static __init
int module_init_ngene(void)
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");
1230 return pci_register_driver(&ngene_pci_driver
);
1233 static __exit
void module_exit_ngene(void)
1235 pci_unregister_driver(&ngene_pci_driver
);
1238 module_init(module_init_ngene
);
1239 module_exit(module_exit_ngene
);
1241 MODULE_DESCRIPTION("nGene");
1242 MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
1243 MODULE_LICENSE("GPL");