26 static int dvb_usb_af9015_remote;
42 buf[1] = state->
seq++;
44 buf[3] = req->
addr >> 8;
45 buf[4] = req->
addr & 0xff;
63 if (((req->
addr & 0xff00) == 0xff00) ||
64 ((req->
addr & 0xff00) == 0xae00))
73 KBUILD_MODNAME, req->
cmd);
79 if ((write && (req->
data_len > BUF_LEN - REQ_HDR_LEN)) ||
80 (!write && (req->
data_len > BUF_LEN - ACK_HDR_LEN))) {
81 dev_err(&d->
udev->dev,
"%s: too much data; cmd=%d len=%d\n",
107 if (rlen && buf[1]) {
109 KBUILD_MODNAME, buf[1]);
126 return af9015_ctrl_msg(d, &req);
133 return af9015_ctrl_msg(d, &req);
138 return af9015_write_regs(d, addr, &val, 1);
143 return af9015_read_regs(d, addr, val, 1);
156 return af9015_ctrl_msg(d, &req);
169 return af9015_ctrl_msg(d, &req);
177 ret = af9015_read_reg(d, addr, &val);
191 return af9015_write_reg(d, addr, val);
196 return af9015_do_reg_bit(d, addr, bit, 1);
201 return af9015_do_reg_bit(d, addr, bit, 0);
242 addr = msg[
i].
buf[0] << 8;
243 addr += msg[
i].
buf[1];
247 addr = msg[
i].
buf[0];
253 if (msg[
i].len > 3 || msg[
i+1].len > 61) {
267 ret = af9015_ctrl_msg(d, &req);
269 }
else if (msg[
i].
flags & I2C_M_RD) {
270 if (msg[
i].len > 61) {
285 ret = af9015_ctrl_msg(d, &req);
288 if (msg[
i].len > 21) {
302 ret = af9015_ctrl_msg(d, &req);
323 .master_xfer = af9015_i2c_xfer,
324 .functionality = af9015_i2c_func,
333 ret = af9015_ctrl_msg(d, &req);
337 dev_dbg(&d->
udev->dev,
"%s: reply=%02x\n", __func__, reply);
357 for (i = 0; i < fw->
size; i++)
358 checksum += fw->
data[i];
363 #define FW_ADDR 0x5100
365 for (remaining = fw->
size; remaining > 0; remaining -= LEN_MAX) {
372 req.
addr = FW_ADDR + fw->
size - remaining;
374 ret = af9015_ctrl_msg(d, &req);
377 "%s: firmware download failed=%d\n",
378 KBUILD_MODNAME, ret);
386 ret = af9015_ctrl_msg(d, &req);
388 dev_err(&d->
udev->dev,
"%s: firmware boot failed=%d\n",
389 KBUILD_MODNAME, ret);
402 static const unsigned int AF9015_EEPROM_SIZE = 256;
403 u8 buf[AF9015_EEPROM_SIZE];
407 for (i = 0; i < AF9015_EEPROM_SIZE; i++) {
410 ret = af9015_ctrl_msg(d, &req);
416 for (i = 0; i < AF9015_EEPROM_SIZE /
sizeof(
u32); i++) {
421 for (i = 0; i < AF9015_EEPROM_SIZE; i += 16)
422 dev_dbg(&d->
udev->dev,
"%s: %*ph\n", __func__, 16, buf + i);
428 dev_err(&d->
udev->dev,
"%s: eeprom failed=%d\n", KBUILD_MODNAME, ret);
444 for (i = 0; i < 4; i++) {
445 ret = af9015_ctrl_msg(d, &req);
452 ret = af9015_eeprom_hash(d);
457 dev_dbg(&d->
udev->dev,
"%s: IR mode=%d\n", __func__, val);
461 ret = af9015_ctrl_msg(d, &req);
475 ret = af9015_ctrl_msg(d, &req);
482 for (i = 0; i < state->
dual_mode + 1; i++) {
487 ret = af9015_ctrl_msg(d, &req);
504 dev_dbg(&d->
udev->dev,
"%s: [%d] xtal=%d set clock=%d\n",
510 ret = af9015_ctrl_msg(d, &req);
517 ret = af9015_ctrl_msg(d, &req);
523 dev_dbg(&d->
udev->dev,
"%s: [%d] IF frequency=%d\n", __func__,
528 ret = af9015_ctrl_msg(d, &req);
533 ret = af9015_ctrl_msg(d, &req);
537 dev_dbg(&d->
udev->dev,
"%s: [%d] MT2060 IF1=%d\n", __func__, i,
542 ret = af9015_ctrl_msg(d, &req);
568 "supported, please report!\n",
569 KBUILD_MODNAME, val);
580 dev_err(&d->
udev->dev,
"%s: eeprom read failed=%d\n",
581 KBUILD_MODNAME, ret);
592 "%s: AverMedia A850: overriding config\n",
604 static int af9015_get_stream_config(
struct dvb_frontend *fe,
u8 *ts_type,
623 static int af9015_af9013_set_frontend(
struct dvb_frontend *fe)
639 static int af9015_af9013_read_status(
struct dvb_frontend *fe,
737 ret = af9015_read_reg_i2c(d, state->
af9013_config[1].i2c_addr,
742 dev_dbg(&d->
udev->dev,
"%s: firmware status=%02x\n",
749 ret = af9015_write_reg(d, 0xd416, 0x04);
756 ret = af9015_ctrl_msg(d, &req);
758 dev_err(&d->
udev->dev,
"%s: firmware copy cmd failed=%d\n",
759 KBUILD_MODNAME, ret);
761 dev_dbg(&d->
udev->dev,
"%s: firmware copy done\n", __func__);
764 ret = af9015_write_reg(d, 0xd416, 0x14);
769 ret = af9015_write_reg_i2c(d, state->
af9013_config[1].i2c_addr,
771 dev_dbg(&d->
udev->dev,
"%s: firmware boot cmd status=%d\n",
776 for (i = 0; i < 15; i++) {
780 ret = af9015_read_reg_i2c(d, state->
af9013_config[1].i2c_addr,
782 dev_dbg(&d->
udev->dev,
"%s: firmware status cmd status=%d " \
783 "firmware status=%02x\n", __func__, ret, val);
787 if (val == 0x0c || val == 0x04)
792 dev_err(&d->
udev->dev,
"%s: firmware did not run\n",
795 }
else if (val != 0x0c) {
796 dev_err(&d->
udev->dev,
"%s: firmware boot timeout\n",
816 }
else if (adap->
id == 1) {
824 ret = af9015_copy_firmware(
adap_to_d(adap));
827 "%s: firmware copy to 2nd " \
828 "frontend failed, will " \
829 "disable it\n", KBUILD_MODNAME);
851 adap->
fe[0]->ops.set_frontend;
852 adap->
fe[0]->ops.set_frontend =
853 af9015_af9013_set_frontend;
856 adap->
fe[0]->ops.read_status;
857 adap->
fe[0]->ops.read_status =
858 af9015_af9013_read_status;
860 state->
init[adap->
id] = adap->
fe[0]->ops.init;
861 adap->
fe[0]->ops.init = af9015_af9013_init;
863 state->
sleep[adap->
id] = adap->
fe[0]->ops.sleep;
864 adap->
fe[0]->ops.sleep = af9015_af9013_sleep;
898 .AgcMasterByte = 0x00,
915 .AgcMasterByte = 0x00,
944 &
adap_to_d(adap)->i2c_adap, &af9015_mt2060_config,
957 &af9015_tda18271_config) ==
NULL ? -
ENODEV : 0;
962 &af9015_tda18218_config) ==
NULL ? -
ENODEV : 0;
967 &af9015_mxl5003_config) ==
NULL ? -
ENODEV : 0;
973 &af9015_mxl5005_config) ==
NULL ? -
ENODEV : 0;
983 &af9015_mc44s803_config) ==
NULL ? -
ENODEV : 0;
988 0xc0, &af9015_mxl5007t_config) ==
NULL ? -
ENODEV : 0;
992 dev_err(&d->
udev->dev,
"%s: unknown tuner id=%d\n",
998 if (adap->
fe[0]->ops.tuner_ops.init) {
1000 adap->
fe[0]->ops.tuner_ops.init;
1001 adap->
fe[0]->ops.tuner_ops.init = af9015_tuner_init;
1004 if (adap->
fe[0]->ops.tuner_ops.sleep) {
1006 adap->
fe[0]->ops.tuner_ops.sleep;
1007 adap->
fe[0]->ops.tuner_ops.sleep = af9015_tuner_sleep;
1017 dev_dbg(&d->
udev->dev,
"%s: onoff=%d\n", __func__, onoff);
1020 ret = af9015_set_reg_bit(d, 0xd503, 0);
1022 ret = af9015_clear_reg_bit(d, 0xd503, 0);
1033 dev_dbg(&d->
udev->dev,
"%s: index=%d pid=%04x onoff=%d\n",
1034 __func__, index, pid, onoff);
1036 ret = af9015_write_reg(d, 0xd505, (pid & 0xff));
1040 ret = af9015_write_reg(d, 0xd506, (pid >> 8));
1044 idx = ((index & 0x1f) | (1 << 5));
1045 ret = af9015_write_reg(d, 0xd504, idx);
1057 dev_dbg(&d->
udev->dev,
"%s: USB speed=%d\n", __func__, d->
udev->speed);
1067 ret = af9015_set_reg_bit(d, 0xd507, 2);
1070 ret = af9015_set_reg_bit(d, 0xd50b, 1);
1073 ret = af9015_clear_reg_bit(d, 0xdd11, 5);
1076 ret = af9015_clear_reg_bit(d, 0xdd11, 6);
1079 ret = af9015_set_reg_bit(d, 0xdd11, 5);
1083 ret = af9015_set_reg_bit(d, 0xdd11, 6);
1087 ret = af9015_clear_reg_bit(d, 0xdd13, 5);
1091 ret = af9015_clear_reg_bit(d, 0xdd13, 6);
1096 ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
1099 ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
1103 ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
1106 ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
1109 ret = af9015_write_reg(d, 0xdd0c, packet_size);
1112 ret = af9015_write_reg(d, 0xdd0d, packet_size);
1115 ret = af9015_clear_reg_bit(d, 0xd507, 2);
1119 ret = af9015_clear_reg_bit(d, 0xd50b, 1);
1126 ret = af9015_set_reg_bit(d, 0xd50b, 0);
1128 ret = af9015_clear_reg_bit(d, 0xd50b, 0);
1132 dev_err(&d->
udev->dev,
"%s: endpoint init failed=%d\n",
1133 KBUILD_MODNAME, ret);
1147 ret = af9015_write_reg(d, 0x98e9, 0xff);
1151 ret = af9015_init_endpoint(d);
1164 static char *af9015_rc_setup_match(
unsigned int id,
1168 if (table->
id ==
id)
1197 ret = af9015_read_regs(d, 0x98d9, buf,
sizeof(buf));
1202 if (buf[1] || buf[2] || buf[3]) {
1203 dev_dbg(&d->
udev->dev,
"%s: invalid data\n", __func__);
1208 if ((state->
rc_repeat != buf[6] || buf[0]) &&
1210 dev_dbg(&d->
udev->dev,
"%s: key repeated\n", __func__);
1217 if (buf[16] != 0xff && buf[0] != 0x01) {
1219 __func__, 4, buf + 12);
1222 ret = af9015_write_reg(d, 0x98e9, 0xff);
1228 if (buf[14] == (
u8) ~buf[15]) {
1229 if (buf[12] == (
u8) ~buf[13]) {
1235 buf[13] << 8 | buf[14];
1239 state->
rc_keycode = buf[12] << 24 | buf[13] << 16 |
1240 buf[14] << 8 | buf[15];
1244 dev_dbg(&d->
udev->dev,
"%s: no key press\n", __func__);
1256 KBUILD_MODNAME, ret);
1278 rc->
map_name = af9015_rc_setup_match(dvb_usb_af9015_remote,
1279 af9015_rc_setup_modparam);
1284 af9015_rc_setup_hashes);
1293 memset(manufacturer, 0,
sizeof(manufacturer));
1295 manufacturer,
sizeof(manufacturer));
1296 if (!
strcmp(
"MSI", manufacturer)) {
1299 rc->
map_name = af9015_rc_setup_match(
1301 af9015_rc_setup_modparam);
1310 rc->
query = af9015_rc_query;
1319 .driver_name = KBUILD_MODNAME,
1324 .generic_bulk_ctrl_endpoint = 0x02,
1325 .generic_bulk_ctrl_endpoint_response = 0x81,
1327 .identify_state = af9015_identify_state,
1329 .download_firmware = af9015_download_firmware,
1331 .i2c_algo = &af9015_i2c_algo,
1332 .read_config = af9015_read_config,
1333 .frontend_attach = af9015_af9013_frontend_attach,
1334 .tuner_attach = af9015_tuner_attach,
1335 .init = af9015_init,
1336 .get_rc_config = af9015_get_rc_config,
1337 .get_stream_config = af9015_get_stream_config,
1339 .get_adapter_count = af9015_get_adapter_count,
1344 .pid_filter_count = 32,
1345 .pid_filter = af9015_pid_filter,
1346 .pid_filter_ctrl = af9015_pid_filter_ctrl,
1357 &af9015_props,
"Afatech AF9015 reference design",
NULL) },
1359 &af9015_props,
"Afatech AF9015 reference design",
NULL) },
1363 &af9015_props,
"Pinnacle PCTV 71e",
NULL) },
1365 &af9015_props,
"KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)",
NULL) },
1371 &af9015_props,
"TerraTec Cinergy T USB XE",
NULL) },
1373 &af9015_props,
"KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)",
NULL) },
1377 &af9015_props,
"Xtensions XD-380",
NULL) },
1381 &af9015_props,
"Fujitsu-Siemens Slim Mobile USB DVB-T",
NULL) },
1383 &af9015_props,
"Telestar Starstick 2",
NULL) },
1385 &af9015_props,
"AVerMedia A309",
NULL) },
1389 &af9015_props,
"KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)",
NULL) },
1391 &af9015_props,
"KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)",
NULL) },
1393 &af9015_props,
"KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)",
NULL) },
1397 &af9015_props,
"AverMedia AVerTV Volar Black HD (A850)",
NULL) },
1399 &af9015_props,
"AverMedia AVerTV Volar GPS 805 (A805)",
NULL) },
1401 &af9015_props,
"Conceptronic USB2.0 DVB-T CTVDIGRCU V3.0",
NULL) },
1403 &af9015_props,
"KWorld Digial MC-810",
NULL) },
1405 &af9015_props,
"Genius TVGo DVB-T03",
NULL) },
1407 &af9015_props,
"KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)",
NULL) },
1409 &af9015_props,
"KWorld PlusTV DVB-T PCI Pro Card (DVB-T PC160-T)",
NULL) },
1411 &af9015_props,
"Sveon STV20 Tuner USB DVB-T HDTV",
NULL) },
1417 &af9015_props,
"KWorld USB DVB-T Stick Mobile (UB383-T)",
NULL) },
1419 &af9015_props,
"KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)",
NULL) },
1421 &af9015_props,
"AverMedia AVerTV Volar M (A815Mac)",
NULL) },
1427 &af9015_props,
"AverMedia AVerTV Red HD+ (A850T)",
NULL) },
1437 static struct usb_driver af9015_usb_driver = {
1438 .name = KBUILD_MODNAME,
1439 .id_table = af9015_id_table,