Commit 04b8b21d authored by Malcolm Priestley's avatar Malcolm Priestley Committed by Mauro Carvalho Chehab

[media] it913x ver 1.32 driver moved to dvb-usb-v2

Functional changes

PID filter is default to off and controlled from dvb-usb-v2

Driver now supports suspend and resume changes in dvb-usb-v2

USB bus repeater functions have been removed.
Signed-off-by: default avatarMalcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 251658e5
......@@ -102,6 +102,13 @@ config DVB_USB_GL861
Say Y here to support the MSI Megasky 580 (55801) DVB-T USB2.0
receiver with USB ID 0db0:5581.
config DVB_USB_IT913X
tristate "ITE IT913X DVB-T USB2.0 support"
depends on DVB_USB_V2
select DVB_IT913X_FE
help
Say Y here to support the ITE IT913X DVB-T USB2.0
config DVB_USB_LME2510
tristate "LME DM04/QQBOX DVB-S USB2.0 support"
depends on DVB_USB_V2
......
......@@ -25,6 +25,9 @@ obj-$(CONFIG_DVB_USB_CE6230) += dvb-usb-ce6230.o
dvb-usb-ec168-objs = ec168.o
obj-$(CONFIG_DVB_USB_EC168) += dvb-usb-ec168.o
dvb-usb-it913x-objs = it913x.o
obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o
dvb-usb-lmedm04-objs = lmedm04.o
obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o
......
/* DVB USB compliant linux driver for IT9137
/*
* DVB USB compliant linux driver for ITE IT9135 and IT9137
*
* Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
* IT9135 (C) ITE Tech Inc.
* IT9137 (C) ITE Tech Inc.
*
* This program is free software; you can redistribute it and/or modify
......@@ -27,88 +29,37 @@
#include <linux/usb/input.h>
#include <media/rc-core.h>
#include "dvb-usb.h"
#include "dvb_usb.h"
#include "it913x-fe.h"
/* debug */
static int dvb_usb_it913x_debug;
#define l_dprintk(var, level, args...) do { \
if ((var >= level)) \
printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \
#define it_debug(var, level, args...) \
do { if ((var & level)) pr_debug(DVB_USB_LOG_PREFIX": " args); \
} while (0)
#define deb_info(level, args...) l_dprintk(dvb_usb_it913x_debug, level, args)
#define debug_data_snipet(level, name, p) \
deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
*p, *(p+1), *(p+2), *(p+3), *(p+4), \
*(p+5), *(p+6), *(p+7));
#define deb_info(level, args...) it_debug(dvb_usb_it913x_debug, level, args)
#define info(args...) pr_info(DVB_USB_LOG_PREFIX": " args)
module_param_named(debug, dvb_usb_it913x_debug, int, 0644);
MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."
DVB_USB_DEBUG_STATUS);
static int pid_filter;
module_param_named(pid, pid_filter, int, 0644);
MODULE_PARM_DESC(pid, "set default 0=on 1=off");
MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
static int dvb_usb_it913x_firmware;
module_param_named(firmware, dvb_usb_it913x_firmware, int, 0644);
MODULE_PARM_DESC(firmware, "set firmware 0=auto 1=IT9137 2=IT9135V1");
int cmd_counter;
MODULE_PARM_DESC(firmware, "set firmware 0=auto"\
"1=IT9137 2=IT9135 V1 3=IT9135 V2");
#define FW_IT9137 "dvb-usb-it9137-01.fw"
#define FW_IT9135_V1 "dvb-usb-it9135-01.fw"
#define FW_IT9135_V2 "dvb-usb-it9135-02.fw"
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
struct it913x_state {
u8 id;
struct ite_config it913x_config;
u8 pid_filter_onoff;
bool proprietary_ir;
int cmd_counter;
};
struct ite_config it913x_config;
#define IT913X_RETRY 10
#define IT913X_SND_TIMEOUT 100
#define IT913X_RCV_TIMEOUT 200
static int it913x_bulk_write(struct usb_device *dev,
u8 *snd, int len, u8 pipe)
{
int ret, actual_l, i;
for (i = 0; i < IT913X_RETRY; i++) {
ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
snd, len , &actual_l, IT913X_SND_TIMEOUT);
if (ret != -EBUSY && ret != -ETIMEDOUT)
break;
}
if (len != actual_l && ret == 0)
ret = -EAGAIN;
return ret;
}
static int it913x_bulk_read(struct usb_device *dev,
u8 *rev, int len, u8 pipe)
{
int ret, actual_l, i;
for (i = 0; i < IT913X_RETRY; i++) {
ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
rev, len , &actual_l, IT913X_RCV_TIMEOUT);
if (ret != -EBUSY && ret != -ETIMEDOUT)
break;
}
if (len != actual_l && ret == 0)
ret = -EAGAIN;
return ret;
}
static u16 check_sum(u8 *p, u8 len)
{
u16 sum = 0;
......@@ -118,9 +69,10 @@ static u16 check_sum(u8 *p, u8 len)
return ~sum;
}
static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro,
static int it913x_io(struct dvb_usb_device *d, u8 mode, u8 pro,
u8 cmd, u32 reg, u8 addr, u8 *data, u8 len)
{
struct it913x_state *st = d->priv;
int ret = 0, i, buf_size = 1;
u8 *buff;
u8 rlen;
......@@ -134,7 +86,7 @@ static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro,
buff[buf_size++] = pro;
buff[buf_size++] = cmd;
buff[buf_size++] = cmd_counter;
buff[buf_size++] = st->cmd_counter;
switch (mode) {
case READ_LONG:
......@@ -176,12 +128,8 @@ static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro,
buff[0] = buf_size;
buff[buf_size++] = (chk_sum & 0xff);
ret = it913x_bulk_write(udev, buff, buf_size , 0x02);
if (ret < 0)
goto error;
ret = it913x_bulk_read(udev, buff, (mode & 1) ?
5 : len + 5 , 0x01);
ret = dvb_usbv2_generic_rw(d, buff, buf_size, buff, (mode & 1) ?
5 : len + 5);
if (ret < 0)
goto error;
......@@ -192,58 +140,44 @@ static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro,
else
memcpy(data, &buff[3], rlen);
cmd_counter++;
st->cmd_counter++;
error: kfree(buff);
return ret;
}
static int it913x_io(struct usb_device *udev, u8 mode, u8 pro,
u8 cmd, u32 reg, u8 addr, u8 *data, u8 len)
{
int ret, i;
for (i = 0; i < IT913X_RETRY; i++) {
ret = it913x_usb_talk(udev, mode, pro,
cmd, reg, addr, data, len);
if (ret != -EAGAIN)
break;
}
return ret;
}
static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data)
static int it913x_wr_reg(struct dvb_usb_device *d, u8 pro, u32 reg , u8 data)
{
int ret;
u8 b[1];
b[0] = data;
ret = it913x_io(udev, WRITE_LONG, pro,
ret = it913x_io(d, WRITE_LONG, pro,
CMD_DEMOD_WRITE, reg, 0, b, sizeof(b));
return ret;
}
static int it913x_read_reg(struct usb_device *udev, u32 reg)
static int it913x_read_reg(struct dvb_usb_device *d, u32 reg)
{
int ret;
u8 data[1];
ret = it913x_io(udev, READ_LONG, DEV_0,
CMD_DEMOD_READ, reg, 0, &data[0], 1);
ret = it913x_io(d, READ_LONG, DEV_0,
CMD_DEMOD_READ, reg, 0, &data[0], sizeof(data));
return (ret < 0) ? ret : data[0];
}
static u32 it913x_query(struct usb_device *udev, u8 pro)
static int it913x_query(struct dvb_usb_device *d, u8 pro)
{
struct it913x_state *st = d->priv;
int ret, i;
u8 data[4];
u8 ver;
for (i = 0; i < 5; i++) {
ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
ret = it913x_io(d, READ_LONG, pro, CMD_DEMOD_READ,
0x1222, 0, &data[0], 3);
ver = data[0];
if (ver > 0 && ver < 3)
......@@ -253,84 +187,83 @@ static u32 it913x_query(struct usb_device *udev, u8 pro)
if (ver < 1 || ver > 2) {
info("Failed to identify chip version applying 1");
it913x_config.chip_ver = 0x1;
it913x_config.chip_type = 0x9135;
st->it913x_config.chip_ver = 0x1;
st->it913x_config.chip_type = 0x9135;
return 0;
}
it913x_config.chip_ver = ver;
it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
st->it913x_config.chip_ver = ver;
st->it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver,
it913x_config.chip_type);
info("Chip Version=%02x Chip Type=%04x", st->it913x_config.chip_ver,
st->it913x_config.chip_type);
ret |= it913x_io(udev, READ_SHORT, pro,
ret = it913x_io(d, READ_SHORT, pro,
CMD_QUERYINFO, 0, 0x1, &data[0], 4);
it913x_config.firmware = (data[0] << 24) + (data[1] << 16) +
(data[2] << 8) + data[3];
st->it913x_config.firmware = (data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | data[3];
return (ret < 0) ? 0 : it913x_config.firmware;
return ret;
}
static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
struct it913x_state *st = adap->dev->priv;
struct usb_device *udev = adap->dev->udev;
struct dvb_usb_device *d = adap_to_d(adap);
struct it913x_state *st = adap_to_priv(adap);
int ret;
u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
mutex_lock(&adap->dev->i2c_mutex);
mutex_lock(&d->i2c_mutex);
deb_info(1, "PID_C (%02x)", onoff);
ret = it913x_wr_reg(udev, pro, PID_EN, st->pid_filter_onoff);
ret = it913x_wr_reg(d, pro, PID_EN, st->pid_filter_onoff);
mutex_unlock(&adap->dev->i2c_mutex);
mutex_unlock(&d->i2c_mutex);
return ret;
}
static int it913x_pid_filter(struct dvb_usb_adapter *adap,
int index, u16 pid, int onoff)
{
struct it913x_state *st = adap->dev->priv;
struct usb_device *udev = adap->dev->udev;
struct dvb_usb_device *d = adap_to_d(adap);
struct it913x_state *st = adap_to_priv(adap);
int ret;
u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
mutex_lock(&adap->dev->i2c_mutex);
mutex_lock(&d->i2c_mutex);
deb_info(1, "PID_F (%02x)", onoff);
ret = it913x_wr_reg(udev, pro, PID_LSB, (u8)(pid & 0xff));
ret = it913x_wr_reg(d, pro, PID_LSB, (u8)(pid & 0xff));
ret |= it913x_wr_reg(udev, pro, PID_MSB, (u8)(pid >> 8));
ret |= it913x_wr_reg(d, pro, PID_MSB, (u8)(pid >> 8));
ret |= it913x_wr_reg(udev, pro, PID_INX_EN, (u8)onoff);
ret |= it913x_wr_reg(d, pro, PID_INX_EN, (u8)onoff);
ret |= it913x_wr_reg(udev, pro, PID_INX, (u8)(index & 0x1f));
ret |= it913x_wr_reg(d, pro, PID_INX, (u8)(index & 0x1f));
if (udev->speed == USB_SPEED_HIGH && pid == 0x2000) {
ret |= it913x_wr_reg(udev, pro, PID_EN, !onoff);
if (d->udev->speed == USB_SPEED_HIGH && pid == 0x2000) {
ret |= it913x_wr_reg(d , pro, PID_EN, !onoff);
st->pid_filter_onoff = !onoff;
} else
st->pid_filter_onoff =
adap->fe_adap[adap->active_fe].pid_filtering;
adap->pid_filtering;
mutex_unlock(&adap->dev->i2c_mutex);
mutex_unlock(&d->i2c_mutex);
return 0;
}
static int it913x_return_status(struct usb_device *udev)
static int it913x_return_status(struct dvb_usb_device *d)
{
u32 firm = 0;
struct it913x_state *st = d->priv;
int ret = it913x_query(d, DEV_0);
if (st->it913x_config.firmware > 0)
info("Firmware Version %d", st->it913x_config.firmware);
firm = it913x_query(udev, DEV_0);
if (firm > 0)
info("Firmware Version %d", firm);
return (firm > 0) ? firm : 0;
return ret;
}
static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
......@@ -344,7 +277,6 @@ static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
mutex_lock(&d->i2c_mutex);
debug_data_snipet(1, "Message out", msg[0].buf);
deb_info(2, "num of messages %d address %02x", num, msg[0].addr);
pro = (msg[0].addr & 0x2) ? DEV_0_DMOD : 0x0;
......@@ -353,11 +285,11 @@ static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
reg = (data[0] << 24) + (data[1] << 16) +
(data[2] << 8) + data[3];
if (num == 2) {
ret = it913x_io(d->udev, READ_LONG, pro,
ret = it913x_io(d, READ_LONG, pro,
CMD_DEMOD_READ, reg, 0, data, msg[1].len);
memcpy(msg[1].buf, data, msg[1].len);
} else
ret = it913x_io(d->udev, WRITE_LONG, pro, CMD_DEMOD_WRITE,
ret = it913x_io(d, WRITE_LONG, pro, CMD_DEMOD_WRITE,
reg, 0, &data[4], msg[0].len - 4);
mutex_unlock(&d->i2c_mutex);
......@@ -385,7 +317,7 @@ static int it913x_rc_query(struct dvb_usb_device *d)
/* Avoid conflict with frontends*/
mutex_lock(&d->i2c_mutex);
ret = it913x_io(d->udev, READ_LONG, PRO_LINK, CMD_IR_GET,
ret = it913x_io(d, READ_LONG, PRO_LINK, CMD_IR_GET,
0, 0, &ibuf[0], sizeof(ibuf));
if ((ibuf[2] + ibuf[3]) == 0xff) {
......@@ -403,18 +335,19 @@ static int it913x_rc_query(struct dvb_usb_device *d)
}
/* Firmware sets raw */
const char fw_it9135_v1[] = "dvb-usb-it9135-01.fw";
const char fw_it9135_v2[] = "dvb-usb-it9135-02.fw";
const char fw_it9137[] = "dvb-usb-it9137-01.fw";
static const char fw_it9135_v1[] = FW_IT9135_V1;
static const char fw_it9135_v2[] = FW_IT9135_V2;
static const char fw_it9137[] = FW_IT9137;
static int ite_firmware_select(struct usb_device *udev,
struct dvb_usb_device_properties *props)
static void ite_get_firmware_name(struct dvb_usb_device *d,
const char **name)
{
struct it913x_state *st = d->priv;
int sw;
/* auto switch */
if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_KWORLD_2)
if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_KWORLD_2)
sw = IT9137_FW;
else if (it913x_config.chip_ver == 1)
else if (st->it913x_config.chip_ver == 1)
sw = IT9135_V1_FW;
else
sw = IT9135_V2_FW;
......@@ -425,47 +358,34 @@ static int ite_firmware_select(struct usb_device *udev,
switch (sw) {
case IT9135_V1_FW:
it913x_config.firmware_ver = 1;
it913x_config.adc_x2 = 1;
it913x_config.read_slevel = false;
props->firmware = fw_it9135_v1;
st->it913x_config.firmware_ver = 1;
st->it913x_config.adc_x2 = 1;
st->it913x_config.read_slevel = false;
*name = fw_it9135_v1;
break;
case IT9135_V2_FW:
it913x_config.firmware_ver = 1;
it913x_config.adc_x2 = 1;
it913x_config.read_slevel = false;
props->firmware = fw_it9135_v2;
switch (it913x_config.tuner_id_0) {
st->it913x_config.firmware_ver = 1;
st->it913x_config.adc_x2 = 1;
st->it913x_config.read_slevel = false;
*name = fw_it9135_v2;
switch (st->it913x_config.tuner_id_0) {
case IT9135_61:
case IT9135_62:
break;
default:
info("Unknown tuner ID applying default 0x60");
case IT9135_60:
it913x_config.tuner_id_0 = IT9135_60;
st->it913x_config.tuner_id_0 = IT9135_60;
}
break;
case IT9137_FW:
default:
it913x_config.firmware_ver = 0;
it913x_config.adc_x2 = 0;
it913x_config.read_slevel = true;
props->firmware = fw_it9137;
st->it913x_config.firmware_ver = 0;
st->it913x_config.adc_x2 = 0;
st->it913x_config.read_slevel = true;
*name = fw_it9137;
}
return 0;
}
static void it913x_select_remote(struct usb_device *udev,
struct dvb_usb_device_properties *props)
{
switch (le16_to_cpu(udev->descriptor.idProduct)) {
case USB_PID_ITETECH_IT9135_9005:
props->rc.core.rc_codes = RC_MAP_IT913X_V2;
return;
default:
props->rc.core.rc_codes = RC_MAP_IT913X_V1;
}
return;
}
......@@ -475,186 +395,160 @@ static void it913x_select_remote(struct usb_device *udev,
#define EP_HIGH 348
#define TS_BUFFER_SIZE_MAX (EP_HIGH*TS_MPEG_PKT_SIZE)
static int it913x_select_config(struct usb_device *udev,
struct dvb_usb_device_properties *props)
static int it913x_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
struct usb_data_stream_properties *stream)
{
struct dvb_usb_adapter *adap = fe_to_adap(fe);
if (adap->pid_filtering)
stream->u.bulk.buffersize = TS_BUFFER_SIZE_PID;
else
stream->u.bulk.buffersize = TS_BUFFER_SIZE_MAX;
return 0;
}
static int it913x_select_config(struct dvb_usb_device *d)
{
int ret = 0, reg;
bool proprietary_ir = false;
struct it913x_state *st = d->priv;
int ret, reg;
ret = it913x_return_status(d);
if (ret < 0)
return ret;
if (it913x_config.chip_ver == 0x02
&& it913x_config.chip_type == 0x9135)
reg = it913x_read_reg(udev, 0x461d);
if (st->it913x_config.chip_ver == 0x02
&& st->it913x_config.chip_type == 0x9135)
reg = it913x_read_reg(d, 0x461d);
else
reg = it913x_read_reg(udev, 0x461b);
reg = it913x_read_reg(d, 0x461b);
if (reg < 0)
return reg;
if (reg == 0) {
it913x_config.dual_mode = 0;
it913x_config.tuner_id_0 = IT9135_38;
proprietary_ir = true;
st->it913x_config.dual_mode = 0;
st->it913x_config.tuner_id_0 = IT9135_38;
st->proprietary_ir = true;
} else {
/* TS mode */
reg = it913x_read_reg(udev, 0x49c5);
reg = it913x_read_reg(d, 0x49c5);
if (reg < 0)
return reg;
it913x_config.dual_mode = reg;
st->it913x_config.dual_mode = reg;
/* IR mode type */
reg = it913x_read_reg(udev, 0x49ac);
reg = it913x_read_reg(d, 0x49ac);
if (reg < 0)
return reg;
if (reg == 5) {
info("Remote propriety (raw) mode");
proprietary_ir = true;
st->proprietary_ir = true;
} else if (reg == 1) {
info("Remote HID mode NOT SUPPORTED");
proprietary_ir = false;
props->rc.core.rc_codes = NULL;
} else
props->rc.core.rc_codes = NULL;
st->proprietary_ir = false;
}
/* Tuner_id */
reg = it913x_read_reg(udev, 0x49d0);
reg = it913x_read_reg(d, 0x49d0);
if (reg < 0)
return reg;
it913x_config.tuner_id_0 = reg;
st->it913x_config.tuner_id_0 = reg;
}
if (proprietary_ir)
it913x_select_remote(udev, props);
if (udev->speed != USB_SPEED_HIGH) {
props->adapter[0].fe[0].pid_filter_count = 5;
info("USB 1 low speed mode - connect to USB 2 port");
if (pid_filter > 0)
pid_filter = 0;
if (it913x_config.dual_mode) {
it913x_config.dual_mode = 0;
info("Dual mode not supported in USB 1");
}
} else /* For replugging */
if(props->adapter[0].fe[0].pid_filter_count == 5)
props->adapter[0].fe[0].pid_filter_count = 31;
/* Select Stream Buffer Size and pid filter option*/
if (pid_filter) {
props->adapter[0].fe[0].stream.u.bulk.buffersize =
TS_BUFFER_SIZE_MAX;
props->adapter[0].fe[0].caps &=
~DVB_USB_ADAP_NEED_PID_FILTERING;
} else
props->adapter[0].fe[0].stream.u.bulk.buffersize =
TS_BUFFER_SIZE_PID;
if (it913x_config.dual_mode) {
props->adapter[1].fe[0].stream.u.bulk.buffersize =
props->adapter[0].fe[0].stream.u.bulk.buffersize;
props->num_adapters = 2;
if (pid_filter)
props->adapter[1].fe[0].caps =
props->adapter[0].fe[0].caps;
} else
props->num_adapters = 1;
info("Dual mode=%x Tuner Type=%x", st->it913x_config.dual_mode,
st->it913x_config.tuner_id_0);
return ret;
}
static int it913x_streaming_ctrl(struct dvb_frontend *fe, int onoff)
{
struct dvb_usb_adapter *adap = fe_to_adap(fe);
struct dvb_usb_device *d = adap_to_d(adap);
struct it913x_state *st = fe_to_priv(fe);
int ret = 0;
u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
info("Dual mode=%x Tuner Type=%x", it913x_config.dual_mode,
it913x_config.tuner_id_0);
deb_info(1, "STM (%02x)", onoff);
if (!onoff) {
mutex_lock(&d->i2c_mutex);
ret = it913x_wr_reg(d, pro, PID_RST, 0x1);
ret = ite_firmware_select(udev, props);
mutex_unlock(&d->i2c_mutex);
st->pid_filter_onoff =
adap->pid_filtering;
}
return ret;
}
static int it913x_identify_state(struct usb_device *udev,
struct dvb_usb_device_properties *props,
struct dvb_usb_device_description **desc,
int *cold)
static int it913x_identify_state(struct dvb_usb_device *d, const char **name)
{
int ret = 0, firm_no;
struct it913x_state *st = d->priv;
int ret;
u8 reg;
firm_no = it913x_return_status(udev);
/* Read and select config */
ret = it913x_select_config(udev, props);
ret = it913x_select_config(d);
if (ret < 0)
return ret;
if (firm_no > 0) {
*cold = 0;
return 0;
}
ite_get_firmware_name(d, name);
if (st->it913x_config.firmware > 0)
return WARM;
if (it913x_config.dual_mode) {
it913x_config.tuner_id_1 = it913x_read_reg(udev, 0x49e0);
ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1);
ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1);
ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
if (st->it913x_config.dual_mode) {
st->it913x_config.tuner_id_1 = it913x_read_reg(d, 0x49e0);
ret = it913x_wr_reg(d, DEV_0, GPIOH1_EN, 0x1);
ret |= it913x_wr_reg(d, DEV_0, GPIOH1_ON, 0x1);
ret |= it913x_wr_reg(d, DEV_0, GPIOH1_O, 0x1);
msleep(50);
ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0);
ret |= it913x_wr_reg(d, DEV_0, GPIOH1_O, 0x0);
msleep(50);
reg = it913x_read_reg(udev, GPIOH1_O);
reg = it913x_read_reg(d, GPIOH1_O);
if (reg == 0) {
ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
ret |= it913x_return_status(udev);
ret |= it913x_wr_reg(d, DEV_0, GPIOH1_O, 0x1);
ret |= it913x_return_status(d);
if (ret != 0)
ret = it913x_wr_reg(udev, DEV_0,
ret = it913x_wr_reg(d, DEV_0,
GPIOH1_O, 0x0);
}
}
reg = it913x_read_reg(udev, IO_MUX_POWER_CLK);
reg = it913x_read_reg(d, IO_MUX_POWER_CLK);
if (it913x_config.dual_mode) {
ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
if (it913x_config.firmware_ver == 1)
ret |= it913x_wr_reg(udev, DEV_0, 0xcfff, 0x1);
if (st->it913x_config.dual_mode) {
ret |= it913x_wr_reg(d, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
if (st->it913x_config.firmware_ver == 1)
ret |= it913x_wr_reg(d, DEV_0, 0xcfff, 0x1);
else
ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1);
ret |= it913x_wr_reg(d, DEV_0, CLK_O_EN, 0x1);
} else {
ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, 0x0);
if (it913x_config.firmware_ver == 1)
ret |= it913x_wr_reg(udev, DEV_0, 0xcfff, 0x0);
ret |= it913x_wr_reg(d, DEV_0, 0x4bfb, 0x0);
if (st->it913x_config.firmware_ver == 1)
ret |= it913x_wr_reg(d, DEV_0, 0xcfff, 0x0);
else
ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x0);
ret |= it913x_wr_reg(d, DEV_0, CLK_O_EN, 0x0);
}
*cold = 1;
return (ret < 0) ? -ENODEV : 0;
}
static int it913x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
struct it913x_state *st = adap->dev->priv;
int ret = 0;
u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
deb_info(1, "STM (%02x)", onoff);
if (!onoff) {
mutex_lock(&adap->dev->i2c_mutex);
ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1);
ret |= it913x_wr_reg(d, DEV_0, I2C_CLK, I2C_CLK_100);
mutex_unlock(&adap->dev->i2c_mutex);
st->pid_filter_onoff =
adap->fe_adap[adap->active_fe].pid_filtering;
}
return ret;
return (ret < 0) ? ret : COLD;
}
static int it913x_download_firmware(struct usb_device *udev,
static int it913x_download_firmware(struct dvb_usb_device *d,
const struct firmware *fw)
{
struct it913x_state *st = d->priv;
int ret = 0, i = 0, pos = 0;
u8 packet_size, min_pkt;
u8 *fw_data;
ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100);
ret = it913x_wr_reg(d, DEV_0, I2C_CLK, I2C_CLK_100);
info("FRM Starting Firmware Download");
......@@ -663,7 +557,7 @@ static int it913x_download_firmware(struct usb_device *udev,
/* The firmware must start with 03 XX 00 */
/* and be the extact firmware length */
if (it913x_config.chip_ver == 2)
if (st->it913x_config.chip_ver == 2)
min_pkt = 0x11;
else
min_pkt = 0x19;
......@@ -676,7 +570,7 @@ static int it913x_download_firmware(struct usb_device *udev,
fw_data = (u8 *)(fw->data + pos);
pos += packet_size;
if (packet_size > 0) {
ret = it913x_io(udev, WRITE_DATA,
ret = it913x_io(d, WRITE_DATA,
DEV_0, CMD_SCATTER_WRITE, 0,
0, fw_data, packet_size);
if (ret < 0)
......@@ -695,35 +589,35 @@ static int it913x_download_firmware(struct usb_device *udev,
msleep(30);
ret = it913x_io(udev, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0);
ret = it913x_io(d, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0);
if (ret < 0)
info("FRM Device not responding to reboot");
ret = it913x_return_status(udev);
if (ret == 0) {
ret = it913x_return_status(d);
if (st->it913x_config.firmware == 0) {
info("FRM Failed to reboot device");
return -ENODEV;
}
msleep(30);
ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400);
ret = it913x_wr_reg(d, DEV_0, I2C_CLK, I2C_CLK_400);
msleep(30);
/* Tuner function */
if (it913x_config.dual_mode)
ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
if (st->it913x_config.dual_mode)
ret |= it913x_wr_reg(d, DEV_0_DMOD , 0xec4c, 0xa0);
else
ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0x68);
if ((it913x_config.chip_ver == 1) &&
(it913x_config.chip_type == 0x9135)) {
ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0);
ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0);
if (it913x_config.dual_mode) {
ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0);
ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0);
ret |= it913x_wr_reg(d, DEV_0_DMOD , 0xec4c, 0x68);
if ((st->it913x_config.chip_ver == 1) &&
(st->it913x_config.chip_type == 0x9135)) {
ret |= it913x_wr_reg(d, DEV_0, PADODPU, 0x0);
ret |= it913x_wr_reg(d, DEV_0, AGC_O_D, 0x0);
if (st->it913x_config.dual_mode) {
ret |= it913x_wr_reg(d, DEV_1, PADODPU, 0x0);
ret |= it913x_wr_reg(d, DEV_1, AGC_O_D, 0x0);
}
}
......@@ -732,9 +626,10 @@ static int it913x_download_firmware(struct usb_device *udev,
static int it913x_name(struct dvb_usb_adapter *adap)
{
const char *desc = adap->dev->desc->name;
struct dvb_usb_device *d = adap_to_d(adap);
const char *desc = d->name;
char *fe_name[] = {"_1", "_2", "_3", "_4"};
char *name = adap->fe_adap[0].fe->ops.info.name;
char *name = adap->fe[0]->ops.info.name;
strlcpy(name, desc, 128);
strlcat(name, fe_name[adap->id], 128);
......@@ -744,188 +639,161 @@ static int it913x_name(struct dvb_usb_adapter *adap)
static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
{
struct usb_device *udev = adap->dev->udev;
struct it913x_state *st = adap->dev->priv;
struct dvb_usb_device *d = adap_to_d(adap);
struct it913x_state *st = d->priv;
int ret = 0;
u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize / 4;
u16 ep_size = adap->stream.buf_size / 4;
u8 pkt_size = 0x80;
if (adap->dev->udev->speed != USB_SPEED_HIGH)
if (d->udev->speed != USB_SPEED_HIGH)
pkt_size = 0x10;
it913x_config.adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
if (adap->id == 0)
memcpy(&st->it913x_config, &it913x_config,
sizeof(struct ite_config));
st->it913x_config.adf = it913x_read_reg(d, IO_MUX_POWER_CLK);
adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
&adap->dev->i2c_adap, adap_addr, &st->it913x_config);
adap->fe[0] = dvb_attach(it913x_fe_attach,
&d->i2c_adap, adap_addr, &st->it913x_config);
if (adap->id == 0 && adap->fe_adap[0].fe) {
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x1);
ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x0f);
ret = it913x_wr_reg(udev, DEV_0, EP0_TX_NAK, 0x1b);
ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x2f);
ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_LSB,
if (adap->id == 0 && adap->fe[0]) {
it913x_wr_reg(d, DEV_0_DMOD, MP2_SW_RST, 0x1);
it913x_wr_reg(d, DEV_0_DMOD, MP2IF2_SW_RST, 0x1);
it913x_wr_reg(d, DEV_0, EP0_TX_EN, 0x0f);
it913x_wr_reg(d, DEV_0, EP0_TX_NAK, 0x1b);
it913x_wr_reg(d, DEV_0, EP0_TX_EN, 0x2f);
it913x_wr_reg(d, DEV_0, EP4_TX_LEN_LSB,
ep_size & 0xff);
ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_MSB, ep_size >> 8);
ret = it913x_wr_reg(udev, DEV_0, EP4_MAX_PKT, pkt_size);
} else if (adap->id == 1 && adap->fe_adap[0].fe) {
ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x6f);
ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_LSB,
it913x_wr_reg(d, DEV_0, EP4_TX_LEN_MSB, ep_size >> 8);
ret = it913x_wr_reg(d, DEV_0, EP4_MAX_PKT, pkt_size);
} else if (adap->id == 1 && adap->fe[0]) {
it913x_wr_reg(d, DEV_0, EP0_TX_EN, 0x6f);
it913x_wr_reg(d, DEV_0, EP5_TX_LEN_LSB,
ep_size & 0xff);
ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_MSB, ep_size >> 8);
ret = it913x_wr_reg(udev, DEV_0, EP5_MAX_PKT, pkt_size);
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_EN, 0x1);
ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_SERIAL, 0x1);
ret = it913x_wr_reg(udev, DEV_1, TOP_HOSTB_SER_MODE, 0x1);
ret = it913x_wr_reg(udev, DEV_0_DMOD, TSIS_ENABLE, 0x1);
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x0);
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x0);
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_HALF_PSB, 0x0);
ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF_STOP_EN, 0x1);
ret = it913x_wr_reg(udev, DEV_1_DMOD, MPEG_FULL_SPEED, 0x0);
ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_STOP_EN, 0x0);
it913x_wr_reg(d, DEV_0, EP5_TX_LEN_MSB, ep_size >> 8);
it913x_wr_reg(d, DEV_0, EP5_MAX_PKT, pkt_size);
it913x_wr_reg(d, DEV_0_DMOD, MP2IF2_EN, 0x1);
it913x_wr_reg(d, DEV_1_DMOD, MP2IF_SERIAL, 0x1);
it913x_wr_reg(d, DEV_1, TOP_HOSTB_SER_MODE, 0x1);
it913x_wr_reg(d, DEV_0_DMOD, TSIS_ENABLE, 0x1);
it913x_wr_reg(d, DEV_0_DMOD, MP2_SW_RST, 0x0);
it913x_wr_reg(d, DEV_0_DMOD, MP2IF2_SW_RST, 0x0);
it913x_wr_reg(d, DEV_0_DMOD, MP2IF2_HALF_PSB, 0x0);
it913x_wr_reg(d, DEV_0_DMOD, MP2IF_STOP_EN, 0x1);
it913x_wr_reg(d, DEV_1_DMOD, MPEG_FULL_SPEED, 0x0);
ret = it913x_wr_reg(d, DEV_1_DMOD, MP2IF_STOP_EN, 0x0);
} else
return -ENODEV;
ret = it913x_name(adap);
ret |= it913x_name(adap);
return ret;
}
/* DVB USB Driver */
static struct dvb_usb_device_properties it913x_properties;
static int it913x_probe(struct usb_interface *intf,
const struct usb_device_id *id)
static int it913x_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
{
cmd_counter = 0;
if (0 == dvb_usb_device_init(intf, &it913x_properties,
THIS_MODULE, NULL, adapter_nr)) {
info("DEV registering device driver");
struct it913x_state *st = d->priv;
if (st->proprietary_ir == false) {
rc->map_name = NULL;
return 0;
}
info("DEV it913x Error");
return -ENODEV;
rc->allowed_protos = RC_TYPE_NEC;
rc->query = it913x_rc_query;
rc->interval = 250;
return 0;
}
static struct usb_device_id it913x_table[] = {
{ USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) },
{ USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135) },
{ USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22_IT9137) },
{ USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9005) },
{ USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006) },
{} /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, it913x_table);
static int it913x_get_adapter_count(struct dvb_usb_device *d)
{
struct it913x_state *st = d->priv;
if (st->it913x_config.dual_mode)
return 2;
return 1;
}
static struct dvb_usb_device_properties it913x_properties = {
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
.usb_ctrl = DEVICE_SPECIFIC,
.download_firmware = it913x_download_firmware,
.firmware = "dvb-usb-it9137-01.fw",
.no_reconnect = 1,
.driver_name = KBUILD_MODNAME,
.owner = THIS_MODULE,
.bInterfaceNumber = 0,
.generic_bulk_ctrl_endpoint = 0x02,
.generic_bulk_ctrl_endpoint_response = 0x81,
.adapter_nr = adapter_nr,
.size_of_priv = sizeof(struct it913x_state),
.num_adapters = 2,
.identify_state = it913x_identify_state,
.i2c_algo = &it913x_i2c_algo,
.download_firmware = it913x_download_firmware,
.frontend_attach = it913x_frontend_attach,
.get_rc_config = it913x_get_rc_config,
.get_stream_config = it913x_get_stream_config,
.get_adapter_count = it913x_get_adapter_count,
.streaming_ctrl = it913x_streaming_ctrl,
.adapter = {
{
.num_frontends = 1,
.fe = {{
.caps = DVB_USB_ADAP_HAS_PID_FILTER|
DVB_USB_ADAP_NEED_PID_FILTERING|
DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
.streaming_ctrl = it913x_streaming_ctrl,
.pid_filter_count = 31,
.pid_filter_count = 32,
.pid_filter = it913x_pid_filter,
.pid_filter_ctrl = it913x_pid_filter_ctrl,
.frontend_attach = it913x_frontend_attach,
/* parameter for the MPEG2-data transfer */
.stream = {
.type = USB_BULK,
.count = 10,
.endpoint = 0x04,
.u = {/* Keep Low if PID filter on */
.bulk = {
.buffersize =
TS_BUFFER_SIZE_PID,
}
}
}
}},
.stream =
DVB_USB_STREAM_BULK(0x84, 10, TS_BUFFER_SIZE_MAX),
},
{
.num_frontends = 1,
.fe = {{
{
.caps = DVB_USB_ADAP_HAS_PID_FILTER|
DVB_USB_ADAP_NEED_PID_FILTERING|
DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
.streaming_ctrl = it913x_streaming_ctrl,
.pid_filter_count = 31,
.pid_filter_count = 32,
.pid_filter = it913x_pid_filter,
.pid_filter_ctrl = it913x_pid_filter_ctrl,
.frontend_attach = it913x_frontend_attach,
/* parameter for the MPEG2-data transfer */
.stream = {
.type = USB_BULK,
.count = 5,
.endpoint = 0x05,
.u = {
.bulk = {
.buffersize =
TS_BUFFER_SIZE_PID,
}
}
}
}},
.stream =
DVB_USB_STREAM_BULK(0x85, 10, TS_BUFFER_SIZE_MAX),
}
},
.identify_state = it913x_identify_state,
.rc.core = {
.protocol = RC_TYPE_NEC,
.module_name = "it913x",
.rc_query = it913x_rc_query,
.rc_interval = IT913X_POLL,
.allowed_protos = RC_TYPE_NEC,
.rc_codes = RC_MAP_IT913X_V1,
},
.i2c_algo = &it913x_i2c_algo,
.num_device_descs = 5,
.devices = {
{ "Kworld UB499-2T T09(IT9137)",
{ &it913x_table[0], NULL },
},
{ "ITE 9135 Generic",
{ &it913x_table[1], NULL },
},
{ "Sveon STV22 Dual DVB-T HDTV(IT9137)",
{ &it913x_table[2], NULL },
},
{ "ITE 9135(9005) Generic",
{ &it913x_table[3], NULL },
},
{ "ITE 9135(9006) Generic",
{ &it913x_table[4], NULL },
},
}
};
static const struct usb_device_id it913x_id_table[] = {
{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09,
&it913x_properties, "Kworld UB499-2T T09(IT9137)",
RC_MAP_IT913X_V1) },
{ DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135,
&it913x_properties, "ITE 9135 Generic",
RC_MAP_IT913X_V1) },
{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22_IT9137,
&it913x_properties, "Sveon STV22 Dual DVB-T HDTV(IT9137)",
RC_MAP_IT913X_V1) },
{ DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9005,
&it913x_properties, "ITE 9135(9005) Generic",
RC_MAP_IT913X_V2) },
{ DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006,
&it913x_properties, "ITE 9135(9006) Generic",
RC_MAP_IT913X_V1) },
{} /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, it913x_id_table);
static struct usb_driver it913x_driver = {
.name = "it913x",
.probe = it913x_probe,
.disconnect = dvb_usb_device_exit,
.id_table = it913x_table,
.name = KBUILD_MODNAME,
.probe = dvb_usbv2_probe,
.disconnect = dvb_usbv2_disconnect,
.suspend = dvb_usbv2_suspend,
.resume = dvb_usbv2_resume,
.id_table = it913x_id_table,
};
module_usb_driver(it913x_driver);
MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
MODULE_DESCRIPTION("it913x USB 2 Driver");
MODULE_VERSION("1.28");
MODULE_VERSION("1.32");
MODULE_LICENSE("GPL");
MODULE_FIRMWARE(FW_IT9135_V1);
MODULE_FIRMWARE(FW_IT9135_V2);
MODULE_FIRMWARE(FW_IT9137);
......@@ -311,11 +311,3 @@ config DVB_USB_TECHNISAT_USB2
select DVB_STV6110x if !DVB_FE_CUSTOMISE
help
Say Y here to support the Technisat USB2 DVB-S/S2 device
config DVB_USB_IT913X
tristate "it913x driver"
depends on DVB_USB
select DVB_IT913X_FE
help
Say Y here to support the it913x device
......@@ -75,9 +75,6 @@ obj-$(CONFIG_DVB_USB_AZ6027) += dvb-usb-az6027.o
dvb-usb-technisat-usb2-objs = technisat-usb2.o
obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o
dvb-usb-it913x-objs := it913x.o
obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o
ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
ccflags-y += -I$(srctree)/drivers/media/dvb/frontends/
# due to tuner-xc3028
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment