26 static u16 af9035_checksum(
const u8 *
buf,
size_t len)
31 for (i = 1; i < len; i++) {
33 checksum += buf[
i] << 8;
47 #define CHECKSUM_LEN 2
48 #define USB_TIMEOUT 2000
55 if (req->
wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
56 req->
rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) {
57 dev_err(&d->
udev->dev,
"%s: too much data wlen=%d rlen=%d\n",
65 buf[3] = state->
seq++;
72 checksum = af9035_checksum(buf, buf[0] - 1);
73 buf[buf[0] - 1] = (checksum >> 8);
74 buf[buf[0] - 0] = (checksum & 0xff);
89 checksum = af9035_checksum(buf, rlen - 2);
90 tmp_checksum = (buf[rlen - 2] << 8) | buf[rlen - 1];
91 if (tmp_checksum != checksum) {
92 dev_err(&d->
udev->dev,
"%s: command=%02x checksum mismatch " \
93 "(%04x != %04x)\n", KBUILD_MODNAME, req->
cmd,
94 tmp_checksum, checksum);
101 dev_dbg(&d->
udev->dev,
"%s: command=%02x failed fw error=%d\n",
102 __func__, req->
cmd, buf[2]);
115 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
124 u8 mbox = (reg >> 16) & 0xff;
131 wbuf[4] = (reg >> 8) & 0xff;
132 wbuf[5] = (reg >> 0) & 0xff;
133 memcpy(&wbuf[6], val, len);
135 return af9035_ctrl_msg(d, &req);
141 u8 wbuf[] = { len, 2, 0, 0, (reg >> 8) & 0xff, reg & 0xff };
142 u8 mbox = (reg >> 16) & 0xff;
145 return af9035_ctrl_msg(d, &req);
151 return af9035_wr_regs(d, reg, &val, 1);
157 return af9035_rd_regs(d, reg, val, 1);
169 ret = af9035_rd_regs(d, reg, &tmp, 1);
178 return af9035_wr_regs(d, reg, &val, 1);
181 static int af9035_i2c_master_xfer(
struct i2c_adapter *adap,
208 (msg[1].
flags & I2C_M_RD)) {
209 if (msg[0].len > 40 || msg[1].len > 40) {
214 u32 reg = msg[0].
buf[0] << 16 | msg[0].
buf[1] << 8 |
216 ret = af9035_rd_regs(d, reg, &msg[1].buf[0],
220 u8 buf[5 + msg[0].
len];
222 buf, msg[1].len, msg[1].buf };
224 buf[1] = msg[0].addr << 1;
228 memcpy(&buf[5], msg[0].buf, msg[0].len);
229 ret = af9035_ctrl_msg(d, &req);
231 }
else if (num == 1 && !(msg[0].
flags & I2C_M_RD)) {
232 if (msg[0].len > 40) {
237 u32 reg = msg[0].
buf[0] << 16 | msg[0].
buf[1] << 8 |
239 ret = af9035_wr_regs(d, reg, &msg[0].buf[3],
243 u8 buf[5 + msg[0].
len];
247 buf[1] = msg[0].addr << 1;
251 memcpy(&buf[5], msg[0].buf, msg[0].len);
252 ret = af9035_ctrl_msg(d, &req);
277 .master_xfer = af9035_i2c_master_xfer,
278 .functionality = af9035_i2c_functionality,
287 sizeof(rbuf), rbuf };
289 ret = af9035_ctrl_msg(d, &req);
293 dev_dbg(&d->
udev->dev,
"%s: reply=%*ph\n", __func__, 4, rbuf);
294 if (rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])
302 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
333 for (i = fw->
size; i > HDR_SIZE;) {
334 hdr_core = fw->
data[fw->
size - i + 0];
335 hdr_addr = fw->
data[fw->
size - i + 1] << 8;
336 hdr_addr |= fw->
data[fw->
size - i + 2] << 0;
337 hdr_data_len = fw->
data[fw->
size - i + 3] << 8;
338 hdr_data_len |= fw->
data[fw->
size - i + 4] << 0;
339 hdr_checksum = fw->
data[fw->
size - i + 5] << 8;
340 hdr_checksum |= fw->
data[fw->
size - i + 6] << 0;
342 dev_dbg(&d->
udev->dev,
"%s: core=%d addr=%04x data_len=%d " \
343 "checksum=%04x\n", __func__, hdr_core, hdr_addr,
344 hdr_data_len, hdr_checksum);
346 if (((hdr_core != 1) && (hdr_core != 2)) ||
347 (hdr_data_len > i)) {
348 dev_dbg(&d->
udev->dev,
"%s: bad firmware\n", __func__);
354 ret = af9035_ctrl_msg(d, &req);
359 for (j = HDR_SIZE + hdr_data_len; j > 0; j -=
MAX_DATA) {
363 req_fw_dl.
wlen = len;
365 HDR_SIZE + hdr_data_len - j];
366 ret = af9035_ctrl_msg(d, &req_fw_dl);
373 ret = af9035_ctrl_msg(d, &req);
380 __func__, fw->
size - i);
385 ret = af9035_ctrl_msg(d, &req);
391 ret = af9035_ctrl_msg(d, &req_fw_ver);
395 if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) {
396 dev_err(&d->
udev->dev,
"%s: firmware did not run\n",
402 dev_info(&d->
udev->dev,
"%s: firmware version=%d.%d.%d.%d",
403 KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
408 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
413 static int af9035_download_firmware_it9135(
struct dvb_usb_device *d,
437 for (i = HDR_SIZE, i_prev = 0; i <= fw->
size; i++) {
439 (fw->
data[i + 0] == 0x03 &&
440 (fw->
data[i + 1] == 0x00 ||
441 fw->
data[i + 1] == 0x01) &&
442 fw->
data[i + 2] == 0x00)) {
443 req_fw_dl.
wlen = i - i_prev;
446 ret = af9035_ctrl_msg(d, &req_fw_dl);
457 ret = af9035_ctrl_msg(d, &req);
463 ret = af9035_ctrl_msg(d, &req_fw_ver);
467 if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) {
468 dev_err(&d->
udev->dev,
"%s: firmware did not run\n",
474 dev_info(&d->
udev->dev,
"%s: firmware version=%d.%d.%d.%d",
475 KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
480 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
488 int ret,
i, eeprom_shift = 0;
501 for (i = 0; i < state->
dual_mode + 1; i++) {
521 "supported, please report!",
522 KBUILD_MODNAME, tmp);
538 dev_dbg(&d->
udev->dev,
"%s: [%d]IF=%d\n", __func__, i, tmp16);
544 ret = af9035_rd_reg(d, 0x00d800, &tmp);
548 tmp = (tmp >> 0) & 0x0f;
556 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
570 ret = af9035_rd_reg(d, 0x00d800, &tmp);
574 tmp = (tmp >> 0) & 0x0f;
582 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
587 static int af9035_tua9001_tuner_callback(
struct dvb_usb_device *d,
593 dev_dbg(&d->
udev->dev,
"%s: cmd=%d arg=%d\n", __func__, cmd, arg);
608 ret = af9035_wr_reg_mask(d, 0x00d8e7, val, 0x01);
618 ret = af9035_wr_reg_mask(d, 0x00d8eb, val, 0x01);
627 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
641 ret = af9035_wr_reg_mask(d, 0xd8eb, 1, 1);
645 ret = af9035_wr_reg_mask(d, 0xd8ec, 1, 1);
649 ret = af9035_wr_reg_mask(d, 0xd8ed, 1, 1);
654 ret = af9035_wr_reg_mask(d, 0xd8d0, 1, 1);
658 ret = af9035_wr_reg_mask(d, 0xd8d1, 1, 1);
665 ret = af9035_wr_reg(d, 0xd8e9, 1);
669 ret = af9035_wr_reg(d, 0xd8e8, 1);
673 ret = af9035_wr_reg(d, 0xd8e7, 1);
679 ret = af9035_wr_reg(d, 0xd8e7, 0);
693 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
698 static int af9035_tuner_callback(
struct dvb_usb_device *d,
int cmd,
int arg)
704 return af9035_fc0011_tuner_callback(d, cmd, arg);
706 return af9035_tua9001_tuner_callback(d, cmd, arg);
714 static int af9035_frontend_callback(
void *adapter_priv,
int component,
720 dev_dbg(&d->
udev->dev,
"%s: component=%d cmd=%d arg=%d\n",
721 __func__, component, cmd, arg);
725 return af9035_tuner_callback(d, cmd, arg);
749 ret = af9035_wr_reg(d, 0x00417f,
754 ret = af9035_wr_reg(d, 0x00d81a,
763 if (adap->
fe[0] ==
NULL) {
769 adap->
fe[0]->ops.i2c_gate_ctrl =
NULL;
770 adap->
fe[0]->callback = af9035_frontend_callback;
775 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
792 .loop_thru_enable = 0,
820 ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01);
824 ret = af9035_wr_reg_mask(d, 0x00d8ed, 0x01, 0x01);
828 ret = af9035_wr_reg_mask(d, 0x00d8e8, 0x01, 0x01);
832 ret = af9035_wr_reg_mask(d, 0x00d8e9, 0x01, 0x01);
838 &d->
i2c_adap, &af9035_tua9001_config);
842 &d->
i2c_adap, &af9035_fc0011_config);
845 ret = af9035_wr_reg(d, 0x00d8e0, 1);
848 ret = af9035_wr_reg(d, 0x00d8e1, 1);
851 ret = af9035_wr_reg(d, 0x00d8df, 0);
857 ret = af9035_wr_reg(d, 0x00d8df, 1);
863 ret = af9035_wr_reg(d, 0x00d8c0, 1);
866 ret = af9035_wr_reg(d, 0x00d8c1, 1);
869 ret = af9035_wr_reg(d, 0x00d8bf, 0);
872 ret = af9035_wr_reg(d, 0x00d8b4, 1);
875 ret = af9035_wr_reg(d, 0x00d8b5, 1);
878 ret = af9035_wr_reg(d, 0x00d8b3, 1);
884 &d->
i2c_adap, 0x60, &af9035_mxl5007t_config);
889 &d->
i2c_adap, &af9035_tda18218_config);
893 ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01);
897 ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01);
901 ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01);
908 &d->
i2c_adap, &af9035_fc2580_config);
922 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
931 u16 frame_size = 87 * 188 / 4;
932 u8 packet_size = 512 / 4;
934 { 0x80f99d, 0x01, 0x01 },
935 { 0x80f9a4, 0x01, 0x01 },
936 { 0x00dd11, 0x00, 0x20 },
937 { 0x00dd11, 0x00, 0x40 },
938 { 0x00dd13, 0x00, 0x20 },
939 { 0x00dd13, 0x00, 0x40 },
940 { 0x00dd11, 0x20, 0x20 },
941 { 0x00dd88, (frame_size >> 0) & 0xff, 0xff},
942 { 0x00dd89, (frame_size >> 8) & 0xff, 0xff},
943 { 0x00dd0c, packet_size, 0xff},
944 { 0x00dd11, state->
dual_mode << 6, 0x40 },
945 { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff},
946 { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff},
947 { 0x00dd0d, packet_size, 0xff },
948 { 0x80f9a3, 0x00, 0x01 },
949 { 0x80f9cd, 0x00, 0x01 },
950 { 0x80f99d, 0x00, 0x01 },
951 { 0x80f9a4, 0x00, 0x01 },
954 dev_dbg(&d->
udev->dev,
"%s: USB speed=%d frame_size=%04x " \
955 "packet_size=%02x\n", __func__,
956 d->
udev->speed, frame_size, packet_size);
960 ret = af9035_wr_reg_mask(d, tab[i].reg, tab[i].val,
969 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
981 ret = af9035_ctrl_msg(d, &req);
985 if ((b[2] + b[3]) == 0xff) {
986 if ((b[0] + b[1]) == 0xff) {
988 key = b[0] << 8 | b[2];
991 key = b[0] << 16 | b[1] << 8 | b[2];
994 key = b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3];
1013 dev_dbg(&d->
udev->dev,
"%s: ir_mode=%02x\n", __func__, tmp);
1021 dev_dbg(&d->
udev->dev,
"%s: ir_type=%02x\n", __func__, tmp);
1033 rc->
query = af9035_rc_query;
1044 dev_dbg(&d->
udev->dev,
"%s: failed=%d\n", __func__, ret);
1052 .driver_name = KBUILD_MODNAME,
1055 .size_of_priv =
sizeof(
struct state),
1057 .generic_bulk_ctrl_endpoint = 0x02,
1058 .generic_bulk_ctrl_endpoint_response = 0x81,
1060 .identify_state = af9035_identify_state,
1062 .download_firmware = af9035_download_firmware,
1064 .i2c_algo = &af9035_i2c_algo,
1065 .read_config = af9035_read_config,
1066 .frontend_attach = af9035_frontend_attach,
1067 .tuner_attach = af9035_tuner_attach,
1068 .init = af9035_init,
1069 .get_rc_config = af9035_get_rc_config,
1082 .driver_name = KBUILD_MODNAME,
1085 .size_of_priv =
sizeof(
struct state),
1087 .generic_bulk_ctrl_endpoint = 0x02,
1088 .generic_bulk_ctrl_endpoint_response = 0x81,
1090 .identify_state = af9035_identify_state,
1092 .download_firmware = af9035_download_firmware_it9135,
1094 .i2c_algo = &af9035_i2c_algo,
1095 .read_config = af9035_read_config_it9135,
1096 .frontend_attach = af9035_frontend_attach,
1097 .tuner_attach = af9035_tuner_attach,
1098 .init = af9035_init,
1099 .get_rc_config = af9035_get_rc_config,
1113 &af9035_props,
"Afatech AF9035 reference design",
NULL) },
1115 &af9035_props,
"Afatech AF9035 reference design",
NULL) },
1117 &af9035_props,
"Afatech AF9035 reference design",
NULL) },
1119 &af9035_props,
"Afatech AF9035 reference design",
NULL) },
1121 &af9035_props,
"Afatech AF9035 reference design",
NULL) },
1123 &af9035_props,
"TerraTec Cinergy T Stick",
NULL) },
1125 &af9035_props,
"AVerMedia AVerTV Volar HD/PRO (A835)",
NULL) },
1127 &af9035_props,
"AVerMedia AVerTV Volar HD/PRO (A835)",
NULL) },
1129 &af9035_props,
"AVerMedia HD Volar (A867)",
NULL) },
1131 &af9035_props,
"AVerMedia HD Volar (A867)",
NULL) },
1133 &af9035_props,
"AVerMedia Twinstar (A825)",
NULL) },
1135 &af9035_props,
"Asus U3100Mini Plus",
NULL) },
1140 static struct usb_driver af9035_usb_driver = {
1141 .name = KBUILD_MODNAME,
1142 .id_table = af9035_id_table,