| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Afatech AF9035 DVB USB driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
|---|
| 5 | 6 | * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 9 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | | - * (at your option) any later version. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | | - * GNU General Public License for more details. |
|---|
| 16 | | - * |
|---|
| 17 | | - * You should have received a copy of the GNU General Public License along |
|---|
| 18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 20 | 7 | */ |
|---|
| 21 | 8 | |
|---|
| 22 | 9 | #include "af9035.h" |
|---|
| .. | .. |
|---|
| 120 | 107 | memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen); |
|---|
| 121 | 108 | exit: |
|---|
| 122 | 109 | mutex_unlock(&d->usb_mutex); |
|---|
| 123 | | - if (ret < 0) |
|---|
| 124 | | - dev_dbg(&intf->dev, "failed=%d\n", ret); |
|---|
| 125 | 110 | return ret; |
|---|
| 126 | 111 | } |
|---|
| 127 | 112 | |
|---|
| .. | .. |
|---|
| 204 | 189 | .platform_data = platform_data, |
|---|
| 205 | 190 | }; |
|---|
| 206 | 191 | |
|---|
| 207 | | - strlcpy(board_info.type, type, I2C_NAME_SIZE); |
|---|
| 192 | + strscpy(board_info.type, type, I2C_NAME_SIZE); |
|---|
| 208 | 193 | |
|---|
| 209 | 194 | /* find first free client */ |
|---|
| 210 | 195 | for (num = 0; num < AF9035_I2C_CLIENT_MAX; num++) { |
|---|
| .. | .. |
|---|
| 223 | 208 | request_module("%s", board_info.type); |
|---|
| 224 | 209 | |
|---|
| 225 | 210 | /* register I2C device */ |
|---|
| 226 | | - client = i2c_new_device(adapter, &board_info); |
|---|
| 227 | | - if (client == NULL || client->dev.driver == NULL) { |
|---|
| 211 | + client = i2c_new_client_device(adapter, &board_info); |
|---|
| 212 | + if (!i2c_client_has_driver(client)) { |
|---|
| 228 | 213 | ret = -ENODEV; |
|---|
| 229 | 214 | goto err; |
|---|
| 230 | 215 | } |
|---|
| .. | .. |
|---|
| 846 | 831 | state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X; |
|---|
| 847 | 832 | state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB; |
|---|
| 848 | 833 | state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL; |
|---|
| 834 | + state->it930x_addresses = 0; |
|---|
| 849 | 835 | |
|---|
| 850 | 836 | if (state->chip_type == 0x9135) { |
|---|
| 851 | 837 | /* feed clock for integrated RF tuner */ |
|---|
| .. | .. |
|---|
| 872 | 858 | * IT930x is an USB bridge, only single demod-single tuner |
|---|
| 873 | 859 | * configurations seen so far. |
|---|
| 874 | 860 | */ |
|---|
| 861 | + if ((le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_AVERMEDIA) && |
|---|
| 862 | + (le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_AVERMEDIA_TD310)) { |
|---|
| 863 | + state->it930x_addresses = 1; |
|---|
| 864 | + } |
|---|
| 875 | 865 | return 0; |
|---|
| 876 | 866 | } |
|---|
| 877 | 867 | |
|---|
| .. | .. |
|---|
| 1207 | 1197 | return ret; |
|---|
| 1208 | 1198 | } |
|---|
| 1209 | 1199 | |
|---|
| 1200 | +/* |
|---|
| 1201 | + * The I2C speed register is calculated with: |
|---|
| 1202 | + * I2C speed register = (1000000000 / (24.4 * 16 * I2C_speed)) |
|---|
| 1203 | + * |
|---|
| 1204 | + * The default speed register for it930x is 7, with means a |
|---|
| 1205 | + * speed of ~366 kbps |
|---|
| 1206 | + */ |
|---|
| 1207 | +#define I2C_SPEED_366K 7 |
|---|
| 1208 | + |
|---|
| 1210 | 1209 | static int it930x_frontend_attach(struct dvb_usb_adapter *adap) |
|---|
| 1211 | 1210 | { |
|---|
| 1212 | 1211 | struct state *state = adap_to_priv(adap); |
|---|
| .. | .. |
|---|
| 1218 | 1217 | |
|---|
| 1219 | 1218 | dev_dbg(&intf->dev, "adap->id=%d\n", adap->id); |
|---|
| 1220 | 1219 | |
|---|
| 1220 | + /* I2C master bus 2 clock speed 366k */ |
|---|
| 1221 | + ret = af9035_wr_reg(d, 0x00f6a7, I2C_SPEED_366K); |
|---|
| 1222 | + if (ret < 0) |
|---|
| 1223 | + goto err; |
|---|
| 1224 | + |
|---|
| 1225 | + /* I2C master bus 1,3 clock speed 366k */ |
|---|
| 1226 | + ret = af9035_wr_reg(d, 0x00f103, I2C_SPEED_366K); |
|---|
| 1227 | + if (ret < 0) |
|---|
| 1228 | + goto err; |
|---|
| 1229 | + |
|---|
| 1230 | + /* set gpio11 low */ |
|---|
| 1231 | + ret = af9035_wr_reg_mask(d, 0xd8d4, 0x01, 0x01); |
|---|
| 1232 | + if (ret < 0) |
|---|
| 1233 | + goto err; |
|---|
| 1234 | + |
|---|
| 1235 | + ret = af9035_wr_reg_mask(d, 0xd8d5, 0x01, 0x01); |
|---|
| 1236 | + if (ret < 0) |
|---|
| 1237 | + goto err; |
|---|
| 1238 | + |
|---|
| 1239 | + ret = af9035_wr_reg_mask(d, 0xd8d3, 0x01, 0x01); |
|---|
| 1240 | + if (ret < 0) |
|---|
| 1241 | + goto err; |
|---|
| 1242 | + |
|---|
| 1243 | + /* Tuner enable using gpiot2_en, gpiot2_on and gpiot2_o (reset) */ |
|---|
| 1244 | + ret = af9035_wr_reg_mask(d, 0xd8b8, 0x01, 0x01); |
|---|
| 1245 | + if (ret < 0) |
|---|
| 1246 | + goto err; |
|---|
| 1247 | + |
|---|
| 1248 | + ret = af9035_wr_reg_mask(d, 0xd8b9, 0x01, 0x01); |
|---|
| 1249 | + if (ret < 0) |
|---|
| 1250 | + goto err; |
|---|
| 1251 | + |
|---|
| 1252 | + ret = af9035_wr_reg_mask(d, 0xd8b7, 0x00, 0x01); |
|---|
| 1253 | + if (ret < 0) |
|---|
| 1254 | + goto err; |
|---|
| 1255 | + |
|---|
| 1256 | + msleep(200); |
|---|
| 1257 | + |
|---|
| 1258 | + ret = af9035_wr_reg_mask(d, 0xd8b7, 0x01, 0x01); |
|---|
| 1259 | + if (ret < 0) |
|---|
| 1260 | + goto err; |
|---|
| 1261 | + |
|---|
| 1221 | 1262 | memset(&si2168_config, 0, sizeof(si2168_config)); |
|---|
| 1222 | 1263 | si2168_config.i2c_adapter = &adapter; |
|---|
| 1223 | 1264 | si2168_config.fe = &adap->fe[0]; |
|---|
| .. | .. |
|---|
| 1225 | 1266 | |
|---|
| 1226 | 1267 | state->af9033_config[adap->id].fe = &adap->fe[0]; |
|---|
| 1227 | 1268 | state->af9033_config[adap->id].ops = &state->ops; |
|---|
| 1228 | | - ret = af9035_add_i2c_dev(d, "si2168", 0x67, &si2168_config, |
|---|
| 1229 | | - &d->i2c_adap); |
|---|
| 1269 | + ret = af9035_add_i2c_dev(d, "si2168", |
|---|
| 1270 | + it930x_addresses_table[state->it930x_addresses].frontend_i2c_addr, |
|---|
| 1271 | + &si2168_config, &d->i2c_adap); |
|---|
| 1230 | 1272 | if (ret) |
|---|
| 1231 | 1273 | goto err; |
|---|
| 1232 | 1274 | |
|---|
| .. | .. |
|---|
| 1575 | 1617 | |
|---|
| 1576 | 1618 | dev_dbg(&intf->dev, "adap->id=%d\n", adap->id); |
|---|
| 1577 | 1619 | |
|---|
| 1578 | | - /* I2C master bus 2 clock speed 300k */ |
|---|
| 1579 | | - ret = af9035_wr_reg(d, 0x00f6a7, 0x07); |
|---|
| 1580 | | - if (ret < 0) |
|---|
| 1581 | | - goto err; |
|---|
| 1582 | | - |
|---|
| 1583 | | - /* I2C master bus 1,3 clock speed 300k */ |
|---|
| 1584 | | - ret = af9035_wr_reg(d, 0x00f103, 0x07); |
|---|
| 1585 | | - if (ret < 0) |
|---|
| 1586 | | - goto err; |
|---|
| 1587 | | - |
|---|
| 1588 | | - /* set gpio11 low */ |
|---|
| 1589 | | - ret = af9035_wr_reg_mask(d, 0xd8d4, 0x01, 0x01); |
|---|
| 1590 | | - if (ret < 0) |
|---|
| 1591 | | - goto err; |
|---|
| 1592 | | - |
|---|
| 1593 | | - ret = af9035_wr_reg_mask(d, 0xd8d5, 0x01, 0x01); |
|---|
| 1594 | | - if (ret < 0) |
|---|
| 1595 | | - goto err; |
|---|
| 1596 | | - |
|---|
| 1597 | | - ret = af9035_wr_reg_mask(d, 0xd8d3, 0x01, 0x01); |
|---|
| 1598 | | - if (ret < 0) |
|---|
| 1599 | | - goto err; |
|---|
| 1600 | | - |
|---|
| 1601 | | - /* Tuner enable using gpiot2_en, gpiot2_on and gpiot2_o (reset) */ |
|---|
| 1602 | | - ret = af9035_wr_reg_mask(d, 0xd8b8, 0x01, 0x01); |
|---|
| 1603 | | - if (ret < 0) |
|---|
| 1604 | | - goto err; |
|---|
| 1605 | | - |
|---|
| 1606 | | - ret = af9035_wr_reg_mask(d, 0xd8b9, 0x01, 0x01); |
|---|
| 1607 | | - if (ret < 0) |
|---|
| 1608 | | - goto err; |
|---|
| 1609 | | - |
|---|
| 1610 | | - ret = af9035_wr_reg_mask(d, 0xd8b7, 0x00, 0x01); |
|---|
| 1611 | | - if (ret < 0) |
|---|
| 1612 | | - goto err; |
|---|
| 1613 | | - |
|---|
| 1614 | | - msleep(200); |
|---|
| 1615 | | - |
|---|
| 1616 | | - ret = af9035_wr_reg_mask(d, 0xd8b7, 0x01, 0x01); |
|---|
| 1617 | | - if (ret < 0) |
|---|
| 1618 | | - goto err; |
|---|
| 1619 | | - |
|---|
| 1620 | 1620 | memset(&si2157_config, 0, sizeof(si2157_config)); |
|---|
| 1621 | 1621 | si2157_config.fe = adap->fe[0]; |
|---|
| 1622 | | - si2157_config.if_port = 1; |
|---|
| 1623 | | - ret = af9035_add_i2c_dev(d, "si2157", 0x63, |
|---|
| 1624 | | - &si2157_config, state->i2c_adapter_demod); |
|---|
| 1625 | 1622 | |
|---|
| 1623 | + /* |
|---|
| 1624 | + * HACK: The Logilink VG0022A and TerraTec TC2 Stick have |
|---|
| 1625 | + * a bug: when the si2157 firmware that came with the device |
|---|
| 1626 | + * is replaced by a new one, the I2C transfers to the tuner |
|---|
| 1627 | + * will return just 0xff. |
|---|
| 1628 | + * |
|---|
| 1629 | + * Probably, the vendor firmware has some patch specifically |
|---|
| 1630 | + * designed for this device. So, we can't replace by the |
|---|
| 1631 | + * generic firmware. The right solution would be to extract |
|---|
| 1632 | + * the si2157 firmware from the original driver and ask the |
|---|
| 1633 | + * driver to load the specifically designed firmware, but, |
|---|
| 1634 | + * while we don't have that, the next best solution is to just |
|---|
| 1635 | + * keep the original firmware at the device. |
|---|
| 1636 | + */ |
|---|
| 1637 | + if ((le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_DEXATEK && |
|---|
| 1638 | + le16_to_cpu(d->udev->descriptor.idProduct) == 0x0100) || |
|---|
| 1639 | + (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_TERRATEC && |
|---|
| 1640 | + le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_TERRATEC_CINERGY_TC2_STICK)) |
|---|
| 1641 | + si2157_config.dont_load_firmware = true; |
|---|
| 1642 | + |
|---|
| 1643 | + si2157_config.if_port = it930x_addresses_table[state->it930x_addresses].tuner_if_port; |
|---|
| 1644 | + ret = af9035_add_i2c_dev(d, "si2157", |
|---|
| 1645 | + it930x_addresses_table[state->it930x_addresses].tuner_i2c_addr, |
|---|
| 1646 | + &si2157_config, state->i2c_adapter_demod); |
|---|
| 1626 | 1647 | if (ret) |
|---|
| 1627 | 1648 | goto err; |
|---|
| 1628 | 1649 | |
|---|
| .. | .. |
|---|
| 2128 | 2149 | /* IT930x devices */ |
|---|
| 2129 | 2150 | { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303, |
|---|
| 2130 | 2151 | &it930x_props, "ITE 9303 Generic", NULL) }, |
|---|
| 2152 | + { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_TD310, |
|---|
| 2153 | + &it930x_props, "AVerMedia TD310 DVB-T2", NULL) }, |
|---|
| 2154 | + { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x0100, |
|---|
| 2155 | + &it930x_props, "Logilink VG0022A", NULL) }, |
|---|
| 2156 | + { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_TC2_STICK, |
|---|
| 2157 | + &it930x_props, "TerraTec Cinergy TC2 Stick", NULL) }, |
|---|
| 2131 | 2158 | { } |
|---|
| 2132 | 2159 | }; |
|---|
| 2133 | 2160 | MODULE_DEVICE_TABLE(usb, af9035_id_table); |
|---|