summaryrefslogtreecommitdiff
path: root/drivers/media/usb/dvb-usb-v2/af9035.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/usb/dvb-usb-v2/af9035.c')
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c600
1 files changed, 389 insertions, 211 deletions
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index f11cc42454f0..b638fc1cd574 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -41,79 +41,84 @@ static u16 af9035_checksum(const u8 *buf, size_t len)
static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req)
{
-#define BUF_LEN 64
#define REQ_HDR_LEN 4 /* send header size */
#define ACK_HDR_LEN 3 /* rece header size */
#define CHECKSUM_LEN 2
#define USB_TIMEOUT 2000
struct state *state = d_to_priv(d);
int ret, wlen, rlen;
- u8 buf[BUF_LEN];
u16 checksum, tmp_checksum;
+ mutex_lock(&d->usb_mutex);
+
/* buffer overflow check */
if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) {
dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n",
__func__, req->wlen, req->rlen);
- return -EINVAL;
+ ret = -EINVAL;
+ goto exit;
}
- buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1;
- buf[1] = req->mbox;
- buf[2] = req->cmd;
- buf[3] = state->seq++;
- memcpy(&buf[REQ_HDR_LEN], req->wbuf, req->wlen);
+ state->buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1;
+ state->buf[1] = req->mbox;
+ state->buf[2] = req->cmd;
+ state->buf[3] = state->seq++;
+ memcpy(&state->buf[REQ_HDR_LEN], req->wbuf, req->wlen);
wlen = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN;
rlen = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN;
/* calc and add checksum */
- checksum = af9035_checksum(buf, buf[0] - 1);
- buf[buf[0] - 1] = (checksum >> 8);
- buf[buf[0] - 0] = (checksum & 0xff);
+ checksum = af9035_checksum(state->buf, state->buf[0] - 1);
+ state->buf[state->buf[0] - 1] = (checksum >> 8);
+ state->buf[state->buf[0] - 0] = (checksum & 0xff);
/* no ack for these packets */
if (req->cmd == CMD_FW_DL)
rlen = 0;
- ret = dvb_usbv2_generic_rw(d, buf, wlen, buf, rlen);
+ ret = dvb_usbv2_generic_rw_locked(d,
+ state->buf, wlen, state->buf, rlen);
if (ret)
- goto err;
+ goto exit;
/* no ack for those packets */
if (req->cmd == CMD_FW_DL)
goto exit;
/* verify checksum */
- checksum = af9035_checksum(buf, rlen - 2);
- tmp_checksum = (buf[rlen - 2] << 8) | buf[rlen - 1];
+ checksum = af9035_checksum(state->buf, rlen - 2);
+ tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1];
if (tmp_checksum != checksum) {
dev_err(&d->udev->dev, "%s: command=%02x checksum mismatch " \
"(%04x != %04x)\n", KBUILD_MODNAME, req->cmd,
tmp_checksum, checksum);
ret = -EIO;
- goto err;
+ goto exit;
}
/* check status */
- if (buf[2]) {
+ if (state->buf[2]) {
+ /* fw returns status 1 when IR code was not received */
+ if (req->cmd == CMD_IR_GET || state->buf[2] == 1) {
+ ret = 1;
+ goto exit;
+ }
+
dev_dbg(&d->udev->dev, "%s: command=%02x failed fw error=%d\n",
- __func__, req->cmd, buf[2]);
+ __func__, req->cmd, state->buf[2]);
ret = -EIO;
- goto err;
+ goto exit;
}
/* read request, copy returned data to return buf */
if (req->rlen)
- memcpy(req->rbuf, &buf[ACK_HDR_LEN], req->rlen);
-
+ memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen);
exit:
- return 0;
-
-err:
- dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
-
+ mutex_unlock(&d->usb_mutex);
+ if (ret < 0)
+ dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
return ret;
}
@@ -292,12 +297,40 @@ static struct i2c_algorithm af9035_i2c_algo = {
static int af9035_identify_state(struct dvb_usb_device *d, const char **name)
{
+ struct state *state = d_to_priv(d);
int ret;
u8 wbuf[1] = { 1 };
u8 rbuf[4];
struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf,
sizeof(rbuf), rbuf };
+ ret = af9035_rd_regs(d, 0x1222, rbuf, 3);
+ if (ret < 0)
+ goto err;
+
+ state->chip_version = rbuf[0];
+ state->chip_type = rbuf[2] << 8 | rbuf[1] << 0;
+
+ ret = af9035_rd_reg(d, 0x384f, &state->prechip_version);
+ if (ret < 0)
+ goto err;
+
+ dev_info(&d->udev->dev,
+ "%s: prechip_version=%02x chip_version=%02x chip_type=%04x\n",
+ __func__, state->prechip_version, state->chip_version,
+ state->chip_type);
+
+ if (state->chip_type == 0x9135) {
+ if (state->chip_version == 0x02)
+ *name = AF9035_FIRMWARE_IT9135_V2;
+ else
+ *name = AF9035_FIRMWARE_IT9135_V1;
+ state->eeprom_addr = EEPROM_BASE_IT9135;
+ } else {
+ *name = AF9035_FIRMWARE_AF9035;
+ state->eeprom_addr = EEPROM_BASE_AF9035;
+ }
+
ret = af9035_ctrl_msg(d, &req);
if (ret < 0)
goto err;
@@ -316,66 +349,19 @@ err:
return ret;
}
-static int af9035_download_firmware(struct dvb_usb_device *d,
+static int af9035_download_firmware_old(struct dvb_usb_device *d,
const struct firmware *fw)
{
int ret, i, j, len;
u8 wbuf[1];
- u8 rbuf[4];
struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL };
- struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
- u8 hdr_core, tmp;
+ u8 hdr_core;
u16 hdr_addr, hdr_data_len, hdr_checksum;
#define MAX_DATA 58
#define HDR_SIZE 7
/*
- * In case of dual tuner configuration we need to do some extra
- * initialization in order to download firmware to slave demod too,
- * which is done by master demod.
- * Master feeds also clock and controls power via GPIO.
- */
- ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp);
- if (ret < 0)
- goto err;
-
- if (tmp) {
- /* configure gpioh1, reset & power slave demod */
- ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
- if (ret < 0)
- goto err;
-
- ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01);
- if (ret < 0)
- goto err;
-
- ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01);
- if (ret < 0)
- goto err;
-
- usleep_range(10000, 50000);
-
- ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01);
- if (ret < 0)
- goto err;
-
- /* tell the slave I2C address */
- ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp);
- if (ret < 0)
- goto err;
-
- ret = af9035_wr_reg(d, 0x00417f, tmp);
- if (ret < 0)
- goto err;
-
- /* enable clock out */
- ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01);
- if (ret < 0)
- goto err;
- }
-
- /*
* Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info!
*
* byte 0: MCS 51 core
@@ -441,28 +427,6 @@ static int af9035_download_firmware(struct dvb_usb_device *d,
if (i)
dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME);
- /* firmware loaded, request boot */
- req.cmd = CMD_FW_BOOT;
- ret = af9035_ctrl_msg(d, &req);
- if (ret < 0)
- goto err;
-
- /* ensure firmware starts */
- wbuf[0] = 1;
- ret = af9035_ctrl_msg(d, &req_fw_ver);
- if (ret < 0)
- goto err;
-
- if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) {
- dev_err(&d->udev->dev, "%s: firmware did not run\n",
- KBUILD_MODNAME);
- ret = -ENODEV;
- goto err;
- }
-
- dev_info(&d->udev->dev, "%s: firmware version=%d.%d.%d.%d",
- KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
-
return 0;
err:
@@ -471,15 +435,11 @@ err:
return ret;
}
-static int af9035_download_firmware_it9135(struct dvb_usb_device *d,
+static int af9035_download_firmware_new(struct dvb_usb_device *d,
const struct firmware *fw)
{
int ret, i, i_prev;
- u8 wbuf[1];
- u8 rbuf[4];
- struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
struct usb_req req_fw_dl = { CMD_FW_SCATTER_WR, 0, 0, NULL, 0, NULL };
- struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
#define HDR_SIZE 7
/*
@@ -494,7 +454,6 @@ static int af9035_download_firmware_it9135(struct dvb_usb_device *d,
* 5: addr LSB
* 6: count of data bytes ?
*/
-
for (i = HDR_SIZE, i_prev = 0; i <= fw->size; i++) {
if (i == fw->size ||
(fw->data[i + 0] == 0x03 &&
@@ -513,6 +472,86 @@ static int af9035_download_firmware_it9135(struct dvb_usb_device *d,
}
}
+ return 0;
+
+err:
+ dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
+
+ return ret;
+}
+
+static int af9035_download_firmware(struct dvb_usb_device *d,
+ const struct firmware *fw)
+{
+ struct state *state = d_to_priv(d);
+ int ret;
+ u8 wbuf[1];
+ u8 rbuf[4];
+ u8 tmp;
+ struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
+ struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
+ dev_dbg(&d->udev->dev, "%s:\n", __func__);
+
+ /*
+ * In case of dual tuner configuration we need to do some extra
+ * initialization in order to download firmware to slave demod too,
+ * which is done by master demod.
+ * Master feeds also clock and controls power via GPIO.
+ */
+ ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_DUAL_MODE, &tmp);
+ if (ret < 0)
+ goto err;
+
+ if (tmp) {
+ /* configure gpioh1, reset & power slave demod */
+ ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
+ if (ret < 0)
+ goto err;
+
+ ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01);
+ if (ret < 0)
+ goto err;
+
+ ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01);
+ if (ret < 0)
+ goto err;
+
+ usleep_range(10000, 50000);
+
+ ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01);
+ if (ret < 0)
+ goto err;
+
+ /* tell the slave I2C address */
+ ret = af9035_rd_reg(d,
+ state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR,
+ &tmp);
+ if (ret < 0)
+ goto err;
+
+ if (state->chip_type == 0x9135) {
+ ret = af9035_wr_reg(d, 0x004bfb, tmp);
+ if (ret < 0)
+ goto err;
+ } else {
+ ret = af9035_wr_reg(d, 0x00417f, tmp);
+ if (ret < 0)
+ goto err;
+
+ /* enable clock out */
+ ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01);
+ if (ret < 0)
+ goto err;
+ }
+ }
+
+ if (fw->data[0] == 0x01)
+ ret = af9035_download_firmware_old(d, fw);
+ else
+ ret = af9035_download_firmware_new(d, fw);
+ if (ret < 0)
+ goto err;
+
/* firmware loaded, request boot */
req.cmd = CMD_FW_BOOT;
ret = af9035_ctrl_msg(d, &req);
@@ -546,15 +585,42 @@ err:
static int af9035_read_config(struct dvb_usb_device *d)
{
struct state *state = d_to_priv(d);
- int ret, i, eeprom_shift = 0;
+ int ret, i;
u8 tmp;
- u16 tmp16;
+ u16 tmp16, addr;
/* demod I2C "address" */
state->af9033_config[0].i2c_addr = 0x38;
+ state->af9033_config[0].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
+ state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
+ state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
+ state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL;
+
+ /* eeprom memory mapped location */
+ if (state->chip_type == 0x9135) {
+ if (state->chip_version == 0x02) {
+ state->af9033_config[0].tuner = AF9033_TUNER_IT9135_60;
+ state->af9033_config[1].tuner = AF9033_TUNER_IT9135_60;
+ tmp16 = 0x00461d;
+ } else {
+ state->af9033_config[0].tuner = AF9033_TUNER_IT9135_38;
+ state->af9033_config[1].tuner = AF9033_TUNER_IT9135_38;
+ tmp16 = 0x00461b;
+ }
+
+ /* check if eeprom exists */
+ ret = af9035_rd_reg(d, tmp16, &tmp);
+ if (ret < 0)
+ goto err;
+
+ if (tmp == 0x00) {
+ dev_dbg(&d->udev->dev, "%s: no eeprom\n", __func__);
+ goto skip_eeprom;
+ }
+ }
/* check if there is dual tuners */
- ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp);
+ ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_DUAL_MODE, &tmp);
if (ret < 0)
goto err;
@@ -564,7 +630,9 @@ static int af9035_read_config(struct dvb_usb_device *d)
if (state->dual_mode) {
/* read 2nd demodulator I2C address */
- ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp);
+ ret = af9035_rd_reg(d,
+ state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR,
+ &tmp);
if (ret < 0)
goto err;
@@ -573,17 +641,25 @@ static int af9035_read_config(struct dvb_usb_device *d)
__func__, tmp);
}
+ addr = state->eeprom_addr;
+
for (i = 0; i < state->dual_mode + 1; i++) {
/* tuner */
- ret = af9035_rd_reg(d, EEPROM_1_TUNER_ID + eeprom_shift, &tmp);
+ ret = af9035_rd_reg(d, addr + EEPROM_1_TUNER_ID, &tmp);
if (ret < 0)
goto err;
- state->af9033_config[i].tuner = tmp;
+ if (tmp == 0x00)
+ dev_dbg(&d->udev->dev,
+ "%s: [%d]tuner not set, using default\n",
+ __func__, i);
+ else
+ state->af9033_config[i].tuner = tmp;
+
dev_dbg(&d->udev->dev, "%s: [%d]tuner=%02x\n",
- __func__, i, tmp);
+ __func__, i, state->af9033_config[i].tuner);
- switch (tmp) {
+ switch (state->af9033_config[i].tuner) {
case AF9033_TUNER_TUA9001:
case AF9033_TUNER_FC0011:
case AF9033_TUNER_MXL5007T:
@@ -592,32 +668,46 @@ static int af9035_read_config(struct dvb_usb_device *d)
case AF9033_TUNER_FC0012:
state->af9033_config[i].spec_inv = 1;
break;
+ case AF9033_TUNER_IT9135_38:
+ case AF9033_TUNER_IT9135_51:
+ case AF9033_TUNER_IT9135_52:
+ case AF9033_TUNER_IT9135_60:
+ case AF9033_TUNER_IT9135_61:
+ case AF9033_TUNER_IT9135_62:
+ break;
default:
- dev_warn(&d->udev->dev, "%s: tuner id=%02x not " \
- "supported, please report!",
+ dev_warn(&d->udev->dev,
+ "%s: tuner id=%02x not supported, please report!",
KBUILD_MODNAME, tmp);
}
/* disable dual mode if driver does not support it */
if (i == 1)
- switch (tmp) {
+ switch (state->af9033_config[i].tuner) {
case AF9033_TUNER_FC0012:
+ case AF9033_TUNER_IT9135_38:
+ case AF9033_TUNER_IT9135_51:
+ case AF9033_TUNER_IT9135_52:
+ case AF9033_TUNER_IT9135_60:
+ case AF9033_TUNER_IT9135_61:
+ case AF9033_TUNER_IT9135_62:
+ case AF9033_TUNER_MXL5007T:
break;
default:
state->dual_mode = false;
- dev_info(&d->udev->dev, "%s: driver does not " \
- "support 2nd tuner and will " \
- "disable it", KBUILD_MODNAME);
+ dev_info(&d->udev->dev,
+ "%s: driver does not support 2nd tuner and will disable it",
+ KBUILD_MODNAME);
}
/* tuner IF frequency */
- ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_L + eeprom_shift, &tmp);
+ ret = af9035_rd_reg(d, addr + EEPROM_1_IF_L, &tmp);
if (ret < 0)
goto err;
tmp16 = tmp;
- ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_H + eeprom_shift, &tmp);
+ ret = af9035_rd_reg(d, addr + EEPROM_1_IF_H, &tmp);
if (ret < 0)
goto err;
@@ -625,9 +715,10 @@ static int af9035_read_config(struct dvb_usb_device *d)
dev_dbg(&d->udev->dev, "%s: [%d]IF=%d\n", __func__, i, tmp16);
- eeprom_shift = 0x10; /* shift for the 2nd tuner params */
+ addr += 0x10; /* shift for the 2nd tuner params */
}
+skip_eeprom:
/* get demod clock */
ret = af9035_rd_reg(d, 0x00d800, &tmp);
if (ret < 0)
@@ -635,34 +726,12 @@ static int af9035_read_config(struct dvb_usb_device *d)
tmp = (tmp >> 0) & 0x0f;
- for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++)
- state->af9033_config[i].clock = clock_lut[tmp];
-
- return 0;
-
-err:
- dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
-
- return ret;
-}
-
-static int af9035_read_config_it9135(struct dvb_usb_device *d)
-{
- struct state *state = d_to_priv(d);
- int ret, i;
- u8 tmp;
-
- state->dual_mode = false;
-
- /* get demod clock */
- ret = af9035_rd_reg(d, 0x00d800, &tmp);
- if (ret < 0)
- goto err;
-
- tmp = (tmp >> 0) & 0x0f;
-
- for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++)
- state->af9033_config[i].clock = clock_lut_it9135[tmp];
+ for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++) {
+ if (state->chip_type == 0x9135)
+ state->af9033_config[i].clock = clock_lut_it9135[tmp];
+ else
+ state->af9033_config[i].clock = clock_lut_af9035[tmp];
+ }
return 0;
@@ -821,7 +890,12 @@ static int af9035_frontend_callback(void *adapter_priv, int component,
static int af9035_get_adapter_count(struct dvb_usb_device *d)
{
struct state *state = d_to_priv(d);
- return state->dual_mode + 1;
+
+ /* disable 2nd adapter as we don't have PID filters implemented */
+ if (d->udev->speed == USB_SPEED_FULL)
+ return 1;
+ else
+ return state->dual_mode + 1;
}
static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
@@ -829,6 +903,7 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
struct state *state = adap_to_priv(adap);
struct dvb_usb_device *d = adap_to_d(adap);
int ret;
+ dev_dbg(&d->udev->dev, "%s:\n", __func__);
if (!state->af9033_config[adap->id].tuner) {
/* unsupported tuner */
@@ -836,20 +911,6 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
goto err;
}
- if (adap->id == 0) {
- state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
- state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL;
-
- ret = af9035_wr_reg(d, 0x00417f,
- state->af9033_config[1].i2c_addr);
- if (ret < 0)
- goto err;
-
- ret = af9035_wr_reg(d, 0x00d81a, state->dual_mode);
- if (ret < 0)
- goto err;
- }
-
/* attach demodulator */
adap->fe[0] = dvb_attach(af9033_attach, &state->af9033_config[adap->id],
&d->i2c_adap);
@@ -928,6 +989,8 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
struct dvb_frontend *fe;
struct i2c_msg msg[1];
u8 tuner_addr;
+ dev_dbg(&d->udev->dev, "%s:\n", __func__);
+
/*
* XXX: Hack used in that function: we abuse unused I2C address bit [7]
* to carry info about used I2C bus for dual tuner configuration.
@@ -1082,6 +1145,17 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap,
&af9035_fc0012_config[adap->id]);
break;
+ case AF9033_TUNER_IT9135_38:
+ case AF9033_TUNER_IT9135_51:
+ case AF9033_TUNER_IT9135_52:
+ case AF9033_TUNER_IT9135_60:
+ case AF9033_TUNER_IT9135_61:
+ case AF9033_TUNER_IT9135_62:
+ /* attach tuner */
+ fe = dvb_attach(it913x_attach, adap->fe[0], &d->i2c_adap,
+ state->af9033_config[adap->id].i2c_addr,
+ state->af9033_config[0].tuner);
+ break;
default:
fe = NULL;
}
@@ -1103,8 +1177,8 @@ static int af9035_init(struct dvb_usb_device *d)
{
struct state *state = d_to_priv(d);
int ret, i;
- u16 frame_size = 87 * 188 / 4;
- u8 packet_size = 512 / 4;
+ u16 frame_size = (d->udev->speed == USB_SPEED_FULL ? 5 : 87) * 188 / 4;
+ u8 packet_size = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4;
struct reg_val_mask tab[] = {
{ 0x80f99d, 0x01, 0x01 },
{ 0x80f9a4, 0x01, 0x01 },
@@ -1149,40 +1223,49 @@ err:
#if IS_ENABLED(CONFIG_RC_CORE)
static int af9035_rc_query(struct dvb_usb_device *d)
{
- unsigned int key;
- unsigned char b[4];
int ret;
- struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, b };
+ u32 key;
+ u8 buf[4];
+ struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, buf };
ret = af9035_ctrl_msg(d, &req);
- if (ret < 0)
+ if (ret == 1)
+ return 0;
+ else if (ret < 0)
goto err;
- if ((b[2] + b[3]) == 0xff) {
- if ((b[0] + b[1]) == 0xff) {
- /* NEC */
- key = b[0] << 8 | b[2];
+ if ((buf[2] + buf[3]) == 0xff) {
+ if ((buf[0] + buf[1]) == 0xff) {
+ /* NEC standard 16bit */
+ key = buf[0] << 8 | buf[2];
} else {
- /* ext. NEC */
- key = b[0] << 16 | b[1] << 8 | b[2];
+ /* NEC extended 24bit */
+ key = buf[0] << 16 | buf[1] << 8 | buf[2];
}
} else {
- key = b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3];
+ /* NEC full code 32bit */
+ key = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
}
+ dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 4, buf);
+
rc_keydown(d->rc_dev, key, 0);
-err:
- /* ignore errors */
return 0;
+
+err:
+ dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
+
+ return ret;
}
static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
{
+ struct state *state = d_to_priv(d);
int ret;
u8 tmp;
- ret = af9035_rd_reg(d, EEPROM_IR_MODE, &tmp);
+ ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_MODE, &tmp);
if (ret < 0)
goto err;
@@ -1190,7 +1273,8 @@ static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
/* don't activate rc if in HID mode or if not available */
if (tmp == 5) {
- ret = af9035_rd_reg(d, EEPROM_IR_TYPE, &tmp);
+ ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_TYPE,
+ &tmp);
if (ret < 0)
goto err;
@@ -1225,6 +1309,109 @@ err:
#define af9035_get_rc_config NULL
#endif
+static int af9035_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
+ struct usb_data_stream_properties *stream)
+{
+ struct dvb_usb_device *d = fe_to_d(fe);
+ dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, fe_to_adap(fe)->id);
+
+ if (d->udev->speed == USB_SPEED_FULL)
+ stream->u.bulk.buffersize = 5 * 188;
+
+ return 0;
+}
+
+/*
+ * FIXME: PID filter is property of demodulator and should be moved to the
+ * correct driver. Also we support only adapter #0 PID filter and will
+ * disable adapter #1 if USB1.1 is used.
+ */
+static int af9035_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
+{
+ struct dvb_usb_device *d = adap_to_d(adap);
+ int ret;
+
+ dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
+
+ ret = af9035_wr_reg_mask(d, 0x80f993, onoff, 0x01);
+ if (ret < 0)
+ goto err;
+
+ return 0;
+
+err:
+ dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
+
+ return ret;
+}
+
+static int af9035_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
+ int onoff)
+{
+ struct dvb_usb_device *d = adap_to_d(adap);
+ int ret;
+ u8 wbuf[2] = {(pid >> 0) & 0xff, (pid >> 8) & 0xff};
+
+ dev_dbg(&d->udev->dev, "%s: index=%d pid=%04x onoff=%d\n",
+ __func__, index, pid, onoff);
+
+ ret = af9035_wr_regs(d, 0x80f996, wbuf, 2);
+ if (ret < 0)
+ goto err;
+
+ ret = af9035_wr_reg(d, 0x80f994, onoff);
+ if (ret < 0)
+ goto err;
+
+ ret = af9035_wr_reg(d, 0x80f995, index);
+ if (ret < 0)
+ goto err;
+
+ return 0;
+
+err:
+ dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
+
+ return ret;
+}
+
+static int af9035_probe(struct usb_interface *intf,
+ const struct usb_device_id *id)
+{
+ struct usb_device *udev = interface_to_usbdev(intf);
+ char manufacturer[sizeof("Afatech")];
+
+ memset(manufacturer, 0, sizeof(manufacturer));
+ usb_string(udev, udev->descriptor.iManufacturer,
+ manufacturer, sizeof(manufacturer));
+ /*
+ * There is two devices having same ID but different chipset. One uses
+ * AF9015 and the other IT9135 chipset. Only difference seen on lsusb
+ * is iManufacturer string.
+ *
+ * idVendor 0x0ccd TerraTec Electronic GmbH
+ * idProduct 0x0099
+ * bcdDevice 2.00
+ * iManufacturer 1 Afatech
+ * iProduct 2 DVB-T 2
+ *
+ * idVendor 0x0ccd TerraTec Electronic GmbH
+ * idProduct 0x0099
+ * bcdDevice 2.00
+ * iManufacturer 1 ITE Technologies, Inc.
+ * iProduct 2 DVB-T TV Stick
+ */
+ if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) &&
+ (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) {
+ if (!strcmp("Afatech", manufacturer)) {
+ dev_dbg(&udev->dev, "%s: rejecting device\n", __func__);
+ return -ENODEV;
+ }
+ }
+
+ return dvb_usbv2_probe(intf, id);
+}
+
/* interface 0 is used by DVB-T receiver and
interface 1 is for remote controller (HID) */
static const struct dvb_usb_device_properties af9035_props = {
@@ -1237,7 +1424,6 @@ static const struct dvb_usb_device_properties af9035_props = {
.generic_bulk_ctrl_endpoint_response = 0x81,
.identify_state = af9035_identify_state,
- .firmware = AF9035_FIRMWARE_AF9035,
.download_firmware = af9035_download_firmware,
.i2c_algo = &af9035_i2c_algo,
@@ -1246,40 +1432,18 @@ static const struct dvb_usb_device_properties af9035_props = {
.tuner_attach = af9035_tuner_attach,
.init = af9035_init,
.get_rc_config = af9035_get_rc_config,
+ .get_stream_config = af9035_get_stream_config,
.get_adapter_count = af9035_get_adapter_count,
.adapter = {
{
- .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
- }, {
- .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
- },
- },
-};
-
-static const struct dvb_usb_device_properties it9135_props = {
- .driver_name = KBUILD_MODNAME,
- .owner = THIS_MODULE,
- .adapter_nr = adapter_nr,
- .size_of_priv = sizeof(struct state),
+ .caps = DVB_USB_ADAP_HAS_PID_FILTER |
+ DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
- .generic_bulk_ctrl_endpoint = 0x02,
- .generic_bulk_ctrl_endpoint_response = 0x81,
-
- .identify_state = af9035_identify_state,
- .firmware = AF9035_FIRMWARE_IT9135,
- .download_firmware = af9035_download_firmware_it9135,
+ .pid_filter_count = 32,
+ .pid_filter_ctrl = af9035_pid_filter_ctrl,
+ .pid_filter = af9035_pid_filter,
- .i2c_algo = &af9035_i2c_algo,
- .read_config = af9035_read_config_it9135,
- .frontend_attach = af9035_frontend_attach,
- .tuner_attach = af9035_tuner_attach,
- .init = af9035_init,
- .get_rc_config = af9035_get_rc_config,
-
- .num_adapters = 1,
- .adapter = {
- {
.stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
}, {
.stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
@@ -1288,6 +1452,7 @@ static const struct dvb_usb_device_properties it9135_props = {
};
static const struct usb_device_id af9035_id_table[] = {
+ /* AF9035 devices */
{ DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_9035,
&af9035_props, "Afatech AF9035 reference design", NULL) },
{ DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1000,
@@ -1312,6 +1477,18 @@ static const struct usb_device_id af9035_id_table[] = {
&af9035_props, "AVerMedia Twinstar (A825)", NULL) },
{ DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS,
&af9035_props, "Asus U3100Mini Plus", NULL) },
+ { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa,
+ &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) },
+ /* IT9135 devices */
+#if 0
+ { DVB_USB_DEVICE(0x048d, 0x9135,
+ &af9035_props, "IT9135 reference design", NULL) },
+ { DVB_USB_DEVICE(0x048d, 0x9006,
+ &af9035_props, "IT9135 reference design", NULL) },
+#endif
+ /* XXX: that same ID [0ccd:0099] is used by af9015 driver too */
+ { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099,
+ &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", NULL) },
{ }
};
MODULE_DEVICE_TABLE(usb, af9035_id_table);
@@ -1319,7 +1496,7 @@ MODULE_DEVICE_TABLE(usb, af9035_id_table);
static struct usb_driver af9035_usb_driver = {
.name = KBUILD_MODNAME,
.id_table = af9035_id_table,
- .probe = dvb_usbv2_probe,
+ .probe = af9035_probe,
.disconnect = dvb_usbv2_disconnect,
.suspend = dvb_usbv2_suspend,
.resume = dvb_usbv2_resume,
@@ -1334,4 +1511,5 @@ MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
MODULE_DESCRIPTION("Afatech AF9035 driver");
MODULE_LICENSE("GPL");
MODULE_FIRMWARE(AF9035_FIRMWARE_AF9035);
-MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135);
+MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V1);
+MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V2);