forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/media/usb/dvb-usb-v2/af9035.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Afatech AF9035 DVB USB driver
34 *
45 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
56 * 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.
207 */
218
229 #include "af9035.h"
....@@ -120,8 +107,6 @@
120107 memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen);
121108 exit:
122109 mutex_unlock(&d->usb_mutex);
123
- if (ret < 0)
124
- dev_dbg(&intf->dev, "failed=%d\n", ret);
125110 return ret;
126111 }
127112
....@@ -204,7 +189,7 @@
204189 .platform_data = platform_data,
205190 };
206191
207
- strlcpy(board_info.type, type, I2C_NAME_SIZE);
192
+ strscpy(board_info.type, type, I2C_NAME_SIZE);
208193
209194 /* find first free client */
210195 for (num = 0; num < AF9035_I2C_CLIENT_MAX; num++) {
....@@ -223,8 +208,8 @@
223208 request_module("%s", board_info.type);
224209
225210 /* 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)) {
228213 ret = -ENODEV;
229214 goto err;
230215 }
....@@ -846,6 +831,7 @@
846831 state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
847832 state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
848833 state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL;
834
+ state->it930x_addresses = 0;
849835
850836 if (state->chip_type == 0x9135) {
851837 /* feed clock for integrated RF tuner */
....@@ -872,6 +858,10 @@
872858 * IT930x is an USB bridge, only single demod-single tuner
873859 * configurations seen so far.
874860 */
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
+ }
875865 return 0;
876866 }
877867
....@@ -1207,6 +1197,15 @@
12071197 return ret;
12081198 }
12091199
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
+
12101209 static int it930x_frontend_attach(struct dvb_usb_adapter *adap)
12111210 {
12121211 struct state *state = adap_to_priv(adap);
....@@ -1218,6 +1217,48 @@
12181217
12191218 dev_dbg(&intf->dev, "adap->id=%d\n", adap->id);
12201219
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
+
12211262 memset(&si2168_config, 0, sizeof(si2168_config));
12221263 si2168_config.i2c_adapter = &adapter;
12231264 si2168_config.fe = &adap->fe[0];
....@@ -1225,8 +1266,9 @@
12251266
12261267 state->af9033_config[adap->id].fe = &adap->fe[0];
12271268 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);
12301272 if (ret)
12311273 goto err;
12321274
....@@ -1575,54 +1617,33 @@
15751617
15761618 dev_dbg(&intf->dev, "adap->id=%d\n", adap->id);
15771619
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
-
16201620 memset(&si2157_config, 0, sizeof(si2157_config));
16211621 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);
16251622
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);
16261647 if (ret)
16271648 goto err;
16281649
....@@ -2128,6 +2149,12 @@
21282149 /* IT930x devices */
21292150 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303,
21302151 &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) },
21312158 { }
21322159 };
21332160 MODULE_DEVICE_TABLE(usb, af9035_id_table);