30
30
#include "tda826x.h"
31
31
#include "tda10086.h"
32
32
#include "tda1002x.h"
33
34
#include "tda827x.h"
34
35
#include "lnbp21.h"
37
#include "dvb_ca_en50221.h"
37
40
static int dvb_usb_ttusb2_debug;
38
41
#define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args)
39
42
module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
40
43
MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
44
static int dvb_usb_ttusb2_debug_ci;
45
module_param_named(debug_ci,dvb_usb_ttusb2_debug_ci, int, 0644);
46
MODULE_PARM_DESC(debug_ci, "set debugging ci." DVB_USB_DEBUG_STATUS);
42
48
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
50
#define ci_dbg(format, arg...) \
52
if (dvb_usb_ttusb2_debug_ci) \
53
printk(KERN_DEBUG DVB_USB_LOG_PREFIX \
54
": %s " format "\n" , __func__, ## arg); \
58
TT3650_CMD_CI_TEST = 0x40,
59
TT3650_CMD_CI_RD_CTRL,
60
TT3650_CMD_CI_WR_CTRL,
61
TT3650_CMD_CI_RD_ATTR,
62
TT3650_CMD_CI_WR_ATTR,
64
TT3650_CMD_CI_SET_VIDEO_PORT
44
67
struct ttusb2_state {
68
struct dvb_ca_en50221 ca;
69
struct mutex ca_mutex;
107
static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data, unsigned int write_len, unsigned int read_len)
110
u8 rx[60];/* (64 -4) */
111
ret = ttusb2_msg(d, cmd, data, write_len, rx, read_len);
113
memcpy(data, rx, read_len);
117
static int tt3650_ci_msg_locked(struct dvb_ca_en50221 *ca, u8 cmd, u8 *data, unsigned int write_len, unsigned int read_len)
119
struct dvb_usb_device *d = ca->data;
120
struct ttusb2_state *state = d->priv;
123
mutex_lock(&state->ca_mutex);
124
ret = tt3650_ci_msg(d, cmd, data, write_len, read_len);
125
mutex_unlock(&state->ca_mutex);
130
static int tt3650_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
138
buf[0] = (address >> 8) & 0x0F;
142
ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_ATTR, buf, 2, 3);
144
ci_dbg("%04x -> %d 0x%02x", address, ret, buf[2]);
152
static int tt3650_ci_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
156
ci_dbg("%d 0x%04x 0x%02x", slot, address, value);
161
buf[0] = (address >> 8) & 0x0F;
165
return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_ATTR, buf, 3, 3);
168
static int tt3650_ci_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
176
buf[0] = address & 3;
178
ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_CTRL, buf, 1, 2);
180
ci_dbg("0x%02x -> %d 0x%02x", address, ret, buf[1]);
188
static int tt3650_ci_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
192
ci_dbg("%d 0x%02x 0x%02x", slot, address, value);
200
return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_CTRL, buf, 2, 2);
203
static int tt3650_ci_set_video_port(struct dvb_ca_en50221 *ca, int slot, int enable)
208
ci_dbg("%d %d", slot, enable);
215
ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
219
if (enable != buf[0]) {
220
err("CI not %sabled.", enable ? "en" : "dis");
227
static int tt3650_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
229
return tt3650_ci_set_video_port(ca, slot, 0);
232
static int tt3650_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
234
return tt3650_ci_set_video_port(ca, slot, 1);
237
static int tt3650_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
239
struct dvb_usb_device *d = ca->data;
240
struct ttusb2_state *state = d->priv;
251
mutex_lock(&state->ca_mutex);
253
ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
261
ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
267
buf[0] = 0; /* FTA */
269
ret = tt3650_ci_msg(d, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
274
mutex_unlock(&state->ca_mutex);
279
static int tt3650_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
287
ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_TEST, buf, 0, 1);
292
return DVB_CA_EN50221_POLL_CAM_PRESENT |
293
DVB_CA_EN50221_POLL_CAM_READY;
298
static void tt3650_ci_uninit(struct dvb_usb_device *d)
300
struct ttusb2_state *state;
311
if (NULL == state->ca.data)
314
dvb_ca_en50221_release(&state->ca);
316
memset(&state->ca, 0, sizeof(state->ca));
319
static int tt3650_ci_init(struct dvb_usb_adapter *a)
321
struct dvb_usb_device *d = a->dev;
322
struct ttusb2_state *state = d->priv;
327
mutex_init(&state->ca_mutex);
329
state->ca.owner = THIS_MODULE;
330
state->ca.read_attribute_mem = tt3650_ci_read_attribute_mem;
331
state->ca.write_attribute_mem = tt3650_ci_write_attribute_mem;
332
state->ca.read_cam_control = tt3650_ci_read_cam_control;
333
state->ca.write_cam_control = tt3650_ci_write_cam_control;
334
state->ca.slot_reset = tt3650_ci_slot_reset;
335
state->ca.slot_shutdown = tt3650_ci_slot_shutdown;
336
state->ca.slot_ts_enable = tt3650_ci_slot_ts_enable;
337
state->ca.poll_slot_status = tt3650_ci_poll_slot_status;
340
ret = dvb_ca_en50221_init(&a->dvb_adap,
345
err("Cannot initialize CI: Error %d.", ret);
346
memset(&state->ca, 0, sizeof(state->ca));
350
info("CI initialized.");
81
355
static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
83
357
struct dvb_usb_device *d = i2c_get_adapdata(adap);
84
358
static u8 obuf[60], ibuf[60];
359
int i, write_read, read;
87
361
if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
91
365
warn("more than 2 i2c messages at a time is not handled yet. TODO.");
93
367
for (i = 0; i < num; i++) {
94
read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
368
write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
369
read = msg[i].flags & I2C_M_RD;
96
obuf[0] = (msg[i].addr << 1) | read;
371
obuf[0] = (msg[i].addr << 1) | (write_read | read);
375
obuf[1] = msg[i].len;
99
377
/* read request */
101
379
obuf[2] = msg[i+1].len;
381
obuf[2] = msg[i].len;
105
memcpy(&obuf[3],msg[i].buf,msg[i].len);
385
memcpy(&obuf[3], msg[i].buf, msg[i].len);
107
387
if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
108
388
err("i2c transfer failed.");
113
memcpy(msg[i+1].buf,&ibuf[3],msg[i+1].len);
393
memcpy(msg[i+1].buf, &ibuf[3], msg[i+1].len);
396
memcpy(msg[i].buf, &ibuf[3], msg[i].len);
118
399
mutex_unlock(&d->i2c_mutex);
190
471
.deltaf = 0xa511,
474
static struct tda10048_config tda10048_config = {
475
.demod_address = 0x10 >> 1,
476
.output_mode = TDA10048_PARALLEL_OUTPUT,
477
.inversion = TDA10048_INVERSION_ON,
478
.dtv6_if_freq_khz = TDA10048_IF_4000,
479
.dtv7_if_freq_khz = TDA10048_IF_4500,
480
.dtv8_if_freq_khz = TDA10048_IF_5000,
481
.clk_freq_khz = TDA10048_CLK_16000,
489
static struct tda827x_config tda827x_config = {
193
493
static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap)
195
495
if (usb_set_interface(adap->dev->udev,0,3) < 0)
196
496
err("set interface to alts=3 failed");
198
if ((adap->fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
498
if ((adap->fe_adap[0].fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
199
499
deb_info("TDA10086 attach failed\n");
506
static int ttusb2_ct3650_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
508
struct dvb_usb_adapter *adap = fe->dvb->priv;
510
return adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, enable);
206
513
static int ttusb2_frontend_tda10023_attach(struct dvb_usb_adapter *adap)
208
515
if (usb_set_interface(adap->dev->udev, 0, 3) < 0)
209
516
err("set interface to alts=3 failed");
210
if ((adap->fe = dvb_attach(tda10023_attach, &tda10023_config, &adap->dev->i2c_adap, 0x48)) == NULL) {
211
deb_info("TDA10023 attach failed\n");
518
if (adap->fe_adap[0].fe == NULL) {
520
adap->fe_adap[0].fe = dvb_attach(tda10023_attach,
521
&tda10023_config, &adap->dev->i2c_adap, 0x48);
523
if (adap->fe_adap[0].fe == NULL) {
524
deb_info("TDA10023 attach failed\n");
527
tt3650_ci_init(adap);
529
adap->fe_adap[1].fe = dvb_attach(tda10048_attach,
530
&tda10048_config, &adap->dev->i2c_adap);
532
if (adap->fe_adap[1].fe == NULL) {
533
deb_info("TDA10048 attach failed\n");
537
/* tuner is behind TDA10023 I2C-gate */
538
adap->fe_adap[1].fe->ops.i2c_gate_ctrl = ttusb2_ct3650_i2c_gate_ctrl;
217
545
static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap)
219
if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL) {
547
struct dvb_frontend *fe;
549
/* MFE: select correct FE to attach tuner since that's called twice */
550
if (adap->fe_adap[1].fe == NULL)
551
fe = adap->fe_adap[0].fe;
553
fe = adap->fe_adap[1].fe;
556
if (dvb_attach(tda827x_attach, fe, 0x61, &adap->dev->i2c_adap, &tda827x_config) == NULL) {
220
557
printk(KERN_ERR "%s: No tda827x found!\n", __func__);