hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Realtek RTL28xxU DVB USB driver
34 *
45 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
56 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
67 * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License along
19
- * with this program; if not, write to the Free Software Foundation, Inc.,
20
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
218 */
229
2310 #include "rtl28xxu.h"
....@@ -189,6 +176,10 @@
189176 ret = -EOPNOTSUPP;
190177 goto err_mutex_unlock;
191178 } else if (msg[0].addr == 0x10) {
179
+ if (msg[0].len < 1 || msg[1].len < 1) {
180
+ ret = -EOPNOTSUPP;
181
+ goto err_mutex_unlock;
182
+ }
192183 /* method 1 - integrated demod */
193184 if (msg[0].buf[0] == 0x00) {
194185 /* return demod page from driver cache */
....@@ -202,6 +193,10 @@
202193 ret = rtl28xxu_ctrl_msg(d, &req);
203194 }
204195 } else if (msg[0].len < 2) {
196
+ if (msg[0].len < 1) {
197
+ ret = -EOPNOTSUPP;
198
+ goto err_mutex_unlock;
199
+ }
205200 /* method 2 - old I2C */
206201 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
207202 req.index = CMD_I2C_RD;
....@@ -230,8 +225,16 @@
230225 ret = -EOPNOTSUPP;
231226 goto err_mutex_unlock;
232227 } else if (msg[0].addr == 0x10) {
228
+ if (msg[0].len < 1) {
229
+ ret = -EOPNOTSUPP;
230
+ goto err_mutex_unlock;
231
+ }
233232 /* method 1 - integrated demod */
234233 if (msg[0].buf[0] == 0x00) {
234
+ if (msg[0].len < 2) {
235
+ ret = -EOPNOTSUPP;
236
+ goto err_mutex_unlock;
237
+ }
235238 /* save demod page for later demod access */
236239 dev->page = msg[0].buf[1];
237240 ret = 0;
....@@ -244,6 +247,10 @@
244247 ret = rtl28xxu_ctrl_msg(d, &req);
245248 }
246249 } else if ((msg[0].len < 23) && (!dev->new_i2c_write)) {
250
+ if (msg[0].len < 1) {
251
+ ret = -EOPNOTSUPP;
252
+ goto err_mutex_unlock;
253
+ }
247254 /* method 2 - old I2C */
248255 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
249256 req.index = CMD_I2C_WR;
....@@ -393,6 +400,7 @@
393400 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
394401 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
395402 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
403
+ struct rtl28xxu_req req_cxd2837er = {0xfdd8, CMD_I2C_RD, 1, buf};
396404 struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf};
397405 struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf};
398406
....@@ -549,7 +557,18 @@
549557
550558 /* probe slave demod */
551559 if (dev->tuner == TUNER_RTL2832_R828D) {
552
- /* power on MN88472 demod on GPIO0 */
560
+ /* power off slave demod on GPIO0 to reset CXD2837ER */
561
+ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x01);
562
+ if (ret)
563
+ goto err;
564
+
565
+ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x00, 0x01);
566
+ if (ret)
567
+ goto err;
568
+
569
+ msleep(50);
570
+
571
+ /* power on slave demod on GPIO0 */
553572 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
554573 if (ret)
555574 goto err;
....@@ -562,7 +581,10 @@
562581 if (ret)
563582 goto err;
564583
565
- /* check MN88472 answers */
584
+ /* slave demod needs some time to wake up */
585
+ msleep(20);
586
+
587
+ /* check slave answers */
566588 ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
567589 if (ret == 0 && buf[0] == 0x02) {
568590 dev_dbg(&d->intf->dev, "MN88472 found\n");
....@@ -574,6 +596,13 @@
574596 if (ret == 0 && buf[0] == 0x03) {
575597 dev_dbg(&d->intf->dev, "MN88473 found\n");
576598 dev->slave_demod = SLAVE_DEMOD_MN88473;
599
+ goto demod_found;
600
+ }
601
+
602
+ ret = rtl28xxu_ctrl_msg(d, &req_cxd2837er);
603
+ if (ret == 0 && buf[0] == 0xb1) {
604
+ dev_dbg(&d->intf->dev, "CXD2837ER found\n");
605
+ dev->slave_demod = SLAVE_DEMOD_CXD2837ER;
577606 goto demod_found;
578607 }
579608 }
....@@ -696,12 +725,12 @@
696725
697726 /* attach demodulator */
698727 memset(&board_info, 0, sizeof(board_info));
699
- strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
728
+ strscpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
700729 board_info.addr = 0x10;
701730 board_info.platform_data = pdata;
702731 request_module("%s", board_info.type);
703
- client = i2c_new_device(&d->i2c_adap, &board_info);
704
- if (client == NULL || client->dev.driver == NULL) {
732
+ client = i2c_new_client_device(&d->i2c_adap, &board_info);
733
+ if (!i2c_client_has_driver(client)) {
705734 ret = -ENODEV;
706735 goto err;
707736 }
....@@ -917,12 +946,12 @@
917946
918947 /* attach demodulator */
919948 memset(&board_info, 0, sizeof(board_info));
920
- strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
949
+ strscpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
921950 board_info.addr = 0x10;
922951 board_info.platform_data = pdata;
923952 request_module("%s", board_info.type);
924
- client = i2c_new_device(&d->i2c_adap, &board_info);
925
- if (client == NULL || client->dev.driver == NULL) {
953
+ client = i2c_new_client_device(&d->i2c_adap, &board_info);
954
+ if (!i2c_client_has_driver(client)) {
926955 ret = -ENODEV;
927956 goto err;
928957 }
....@@ -956,15 +985,15 @@
956985
957986 mn88472_config.fe = &adap->fe[1];
958987 mn88472_config.i2c_wr_max = 22,
959
- strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
988
+ strscpy(info.type, "mn88472", I2C_NAME_SIZE);
960989 mn88472_config.xtal = 20500000;
961990 mn88472_config.ts_mode = SERIAL_TS_MODE;
962991 mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
963992 info.addr = 0x18;
964993 info.platform_data = &mn88472_config;
965994 request_module(info.type);
966
- client = i2c_new_device(&d->i2c_adap, &info);
967
- if (client == NULL || client->dev.driver == NULL) {
995
+ client = i2c_new_client_device(&d->i2c_adap, &info);
996
+ if (!i2c_client_has_driver(client)) {
968997 dev->slave_demod = SLAVE_DEMOD_NONE;
969998 goto err_slave_demod_failed;
970999 }
....@@ -981,12 +1010,12 @@
9811010
9821011 mn88473_config.fe = &adap->fe[1];
9831012 mn88473_config.i2c_wr_max = 22,
984
- strlcpy(info.type, "mn88473", I2C_NAME_SIZE);
1013
+ strscpy(info.type, "mn88473", I2C_NAME_SIZE);
9851014 info.addr = 0x18;
9861015 info.platform_data = &mn88473_config;
9871016 request_module(info.type);
988
- client = i2c_new_device(&d->i2c_adap, &info);
989
- if (client == NULL || client->dev.driver == NULL) {
1017
+ client = i2c_new_client_device(&d->i2c_adap, &info);
1018
+ if (!i2c_client_has_driver(client)) {
9901019 dev->slave_demod = SLAVE_DEMOD_NONE;
9911020 goto err_slave_demod_failed;
9921021 }
....@@ -998,6 +1027,23 @@
9981027 }
9991028
10001029 dev->i2c_client_slave_demod = client;
1030
+ } else if (dev->slave_demod == SLAVE_DEMOD_CXD2837ER) {
1031
+ struct cxd2841er_config cxd2837er_config = {};
1032
+
1033
+ cxd2837er_config.i2c_addr = 0xd8;
1034
+ cxd2837er_config.xtal = SONY_XTAL_20500;
1035
+ cxd2837er_config.flags = (CXD2841ER_AUTO_IFHZ |
1036
+ CXD2841ER_NO_AGCNEG | CXD2841ER_TSBITS |
1037
+ CXD2841ER_EARLY_TUNE | CXD2841ER_TS_SERIAL);
1038
+ adap->fe[1] = dvb_attach(cxd2841er_attach_t_c,
1039
+ &cxd2837er_config,
1040
+ &d->i2c_adap);
1041
+ if (!adap->fe[1]) {
1042
+ dev->slave_demod = SLAVE_DEMOD_NONE;
1043
+ goto err_slave_demod_failed;
1044
+ }
1045
+ adap->fe[1]->id = 1;
1046
+ dev->i2c_client_slave_demod = NULL;
10011047 } else {
10021048 struct si2168_config si2168_config = {};
10031049 struct i2c_adapter *adapter;
....@@ -1007,12 +1053,12 @@
10071053 si2168_config.ts_mode = SI2168_TS_SERIAL;
10081054 si2168_config.ts_clock_inv = false;
10091055 si2168_config.ts_clock_gapped = true;
1010
- strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1056
+ strscpy(info.type, "si2168", I2C_NAME_SIZE);
10111057 info.addr = 0x64;
10121058 info.platform_data = &si2168_config;
10131059 request_module(info.type);
1014
- client = i2c_new_device(&d->i2c_adap, &info);
1015
- if (client == NULL || client->dev.driver == NULL) {
1060
+ client = i2c_new_client_device(&d->i2c_adap, &info);
1061
+ if (!i2c_client_has_driver(client)) {
10161062 dev->slave_demod = SLAVE_DEMOD_NONE;
10171063 goto err_slave_demod_failed;
10181064 }
....@@ -1198,13 +1244,14 @@
11981244 .clock = 28800000,
11991245 };
12001246
1201
- strlcpy(info.type, "e4000", I2C_NAME_SIZE);
1247
+ strscpy(info.type, "e4000", I2C_NAME_SIZE);
12021248 info.addr = 0x64;
12031249 info.platform_data = &e4000_config;
12041250
12051251 request_module(info.type);
1206
- client = i2c_new_device(dev->demod_i2c_adapter, &info);
1207
- if (client == NULL || client->dev.driver == NULL)
1252
+ client = i2c_new_client_device(dev->demod_i2c_adapter,
1253
+ &info);
1254
+ if (!i2c_client_has_driver(client))
12081255 break;
12091256
12101257 if (!try_module_get(client->dev.driver->owner)) {
....@@ -1222,13 +1269,13 @@
12221269 };
12231270 struct i2c_board_info board_info = {};
12241271
1225
- strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE);
1272
+ strscpy(board_info.type, "fc2580", I2C_NAME_SIZE);
12261273 board_info.addr = 0x56;
12271274 board_info.platform_data = &fc2580_pdata;
12281275 request_module("fc2580");
1229
- client = i2c_new_device(dev->demod_i2c_adapter,
1230
- &board_info);
1231
- if (client == NULL || client->dev.driver == NULL)
1276
+ client = i2c_new_client_device(dev->demod_i2c_adapter,
1277
+ &board_info);
1278
+ if (!i2c_client_has_driver(client))
12321279 break;
12331280 if (!try_module_get(client->dev.driver->owner)) {
12341281 i2c_unregister_device(client);
....@@ -1253,12 +1300,13 @@
12531300 if (ret)
12541301 goto err;
12551302
1256
- strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE);
1303
+ strscpy(board_info.type, "tua9001", I2C_NAME_SIZE);
12571304 board_info.addr = 0x60;
12581305 board_info.platform_data = &tua9001_pdata;
12591306 request_module("tua9001");
1260
- client = i2c_new_device(dev->demod_i2c_adapter, &board_info);
1261
- if (client == NULL || client->dev.driver == NULL)
1307
+ client = i2c_new_client_device(dev->demod_i2c_adapter,
1308
+ &board_info);
1309
+ if (!i2c_client_has_driver(client))
12621310 break;
12631311 if (!try_module_get(client->dev.driver->owner)) {
12641312 i2c_unregister_device(client);
....@@ -1298,12 +1346,12 @@
12981346 .inversion = false,
12991347 };
13001348
1301
- strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1349
+ strscpy(info.type, "si2157", I2C_NAME_SIZE);
13021350 info.addr = 0x60;
13031351 info.platform_data = &si2157_config;
13041352 request_module(info.type);
1305
- client = i2c_new_device(&d->i2c_adap, &info);
1306
- if (client == NULL || client->dev.driver == NULL)
1353
+ client = i2c_new_client_device(&d->i2c_adap, &info);
1354
+ if (!i2c_client_has_driver(client))
13071355 break;
13081356
13091357 if (!try_module_get(client->dev.driver->owner)) {
....@@ -1694,7 +1742,7 @@
16941742 {
16951743 int ret, i, len;
16961744 struct rtl28xxu_dev *dev = d->priv;
1697
- struct ir_raw_event ev;
1745
+ struct ir_raw_event ev = {};
16981746 u8 buf[128];
16991747 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
17001748 {IR_RX_IF, 0x03, 0xff},
....@@ -1760,16 +1808,13 @@
17601808 }
17611809
17621810 /* pass data to Kernel IR decoder */
1763
- init_ir_raw_event(&ev);
1764
-
17651811 for (i = 0; i < len; i++) {
17661812 ev.pulse = buf[i] >> 7;
1767
- ev.duration = 50800 * (buf[i] & 0x7f);
1813
+ ev.duration = 51 * (buf[i] & 0x7f);
17681814 ir_raw_event_store_with_filter(d->rc_dev, &ev);
17691815 }
17701816
17711817 /* 'flush' ir_raw_event_store_with_filter() */
1772
- ir_raw_event_set_idle(d->rc_dev, true);
17731818 ir_raw_event_handle(d->rc_dev);
17741819 exit:
17751820 return ret;
....@@ -1792,6 +1837,8 @@
17921837 rc->driver_type = RC_DRIVER_IR_RAW;
17931838 rc->query = rtl2832u_rc_query;
17941839 rc->interval = 200;
1840
+ /* we program idle len to 0xc0, set timeout to one less */
1841
+ rc->timeout = 0xbf * 51;
17951842
17961843 return 0;
17971844 }
....@@ -1942,10 +1989,13 @@
19421989 &rtl28xxu_props, "Sveon STV27", NULL) },
19431990 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000,
19441991 &rtl28xxu_props, "TURBO-X Pure TV Tuner DTT-2000", NULL) },
1992
+ { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_PROLECTRIX_DV107669,
1993
+ &rtl28xxu_props, "PROlectrix DV107669", NULL) },
19451994
19461995 /* RTL2832P devices: */
19471996 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
1948
- &rtl28xxu_props, "Astrometa DVB-T2", NULL) },
1997
+ &rtl28xxu_props, "Astrometa DVB-T2",
1998
+ RC_MAP_ASTROMETA_T2HYBRID) },
19491999 { DVB_USB_DEVICE(0x5654, 0xca42,
19502000 &rtl28xxu_props, "GoTView MasterHD 3", NULL) },
19512001 { }