forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
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"
....@@ -393,6 +380,7 @@
393380 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
394381 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
395382 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
383
+ struct rtl28xxu_req req_cxd2837er = {0xfdd8, CMD_I2C_RD, 1, buf};
396384 struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf};
397385 struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf};
398386
....@@ -549,7 +537,18 @@
549537
550538 /* probe slave demod */
551539 if (dev->tuner == TUNER_RTL2832_R828D) {
552
- /* power on MN88472 demod on GPIO0 */
540
+ /* power off slave demod on GPIO0 to reset CXD2837ER */
541
+ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x01);
542
+ if (ret)
543
+ goto err;
544
+
545
+ ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x00, 0x01);
546
+ if (ret)
547
+ goto err;
548
+
549
+ msleep(50);
550
+
551
+ /* power on slave demod on GPIO0 */
553552 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
554553 if (ret)
555554 goto err;
....@@ -562,7 +561,10 @@
562561 if (ret)
563562 goto err;
564563
565
- /* check MN88472 answers */
564
+ /* slave demod needs some time to wake up */
565
+ msleep(20);
566
+
567
+ /* check slave answers */
566568 ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
567569 if (ret == 0 && buf[0] == 0x02) {
568570 dev_dbg(&d->intf->dev, "MN88472 found\n");
....@@ -574,6 +576,13 @@
574576 if (ret == 0 && buf[0] == 0x03) {
575577 dev_dbg(&d->intf->dev, "MN88473 found\n");
576578 dev->slave_demod = SLAVE_DEMOD_MN88473;
579
+ goto demod_found;
580
+ }
581
+
582
+ ret = rtl28xxu_ctrl_msg(d, &req_cxd2837er);
583
+ if (ret == 0 && buf[0] == 0xb1) {
584
+ dev_dbg(&d->intf->dev, "CXD2837ER found\n");
585
+ dev->slave_demod = SLAVE_DEMOD_CXD2837ER;
577586 goto demod_found;
578587 }
579588 }
....@@ -696,12 +705,12 @@
696705
697706 /* attach demodulator */
698707 memset(&board_info, 0, sizeof(board_info));
699
- strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
708
+ strscpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
700709 board_info.addr = 0x10;
701710 board_info.platform_data = pdata;
702711 request_module("%s", board_info.type);
703
- client = i2c_new_device(&d->i2c_adap, &board_info);
704
- if (client == NULL || client->dev.driver == NULL) {
712
+ client = i2c_new_client_device(&d->i2c_adap, &board_info);
713
+ if (!i2c_client_has_driver(client)) {
705714 ret = -ENODEV;
706715 goto err;
707716 }
....@@ -917,12 +926,12 @@
917926
918927 /* attach demodulator */
919928 memset(&board_info, 0, sizeof(board_info));
920
- strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
929
+ strscpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
921930 board_info.addr = 0x10;
922931 board_info.platform_data = pdata;
923932 request_module("%s", board_info.type);
924
- client = i2c_new_device(&d->i2c_adap, &board_info);
925
- if (client == NULL || client->dev.driver == NULL) {
933
+ client = i2c_new_client_device(&d->i2c_adap, &board_info);
934
+ if (!i2c_client_has_driver(client)) {
926935 ret = -ENODEV;
927936 goto err;
928937 }
....@@ -956,15 +965,15 @@
956965
957966 mn88472_config.fe = &adap->fe[1];
958967 mn88472_config.i2c_wr_max = 22,
959
- strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
968
+ strscpy(info.type, "mn88472", I2C_NAME_SIZE);
960969 mn88472_config.xtal = 20500000;
961970 mn88472_config.ts_mode = SERIAL_TS_MODE;
962971 mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
963972 info.addr = 0x18;
964973 info.platform_data = &mn88472_config;
965974 request_module(info.type);
966
- client = i2c_new_device(&d->i2c_adap, &info);
967
- if (client == NULL || client->dev.driver == NULL) {
975
+ client = i2c_new_client_device(&d->i2c_adap, &info);
976
+ if (!i2c_client_has_driver(client)) {
968977 dev->slave_demod = SLAVE_DEMOD_NONE;
969978 goto err_slave_demod_failed;
970979 }
....@@ -981,12 +990,12 @@
981990
982991 mn88473_config.fe = &adap->fe[1];
983992 mn88473_config.i2c_wr_max = 22,
984
- strlcpy(info.type, "mn88473", I2C_NAME_SIZE);
993
+ strscpy(info.type, "mn88473", I2C_NAME_SIZE);
985994 info.addr = 0x18;
986995 info.platform_data = &mn88473_config;
987996 request_module(info.type);
988
- client = i2c_new_device(&d->i2c_adap, &info);
989
- if (client == NULL || client->dev.driver == NULL) {
997
+ client = i2c_new_client_device(&d->i2c_adap, &info);
998
+ if (!i2c_client_has_driver(client)) {
990999 dev->slave_demod = SLAVE_DEMOD_NONE;
9911000 goto err_slave_demod_failed;
9921001 }
....@@ -998,6 +1007,23 @@
9981007 }
9991008
10001009 dev->i2c_client_slave_demod = client;
1010
+ } else if (dev->slave_demod == SLAVE_DEMOD_CXD2837ER) {
1011
+ struct cxd2841er_config cxd2837er_config = {};
1012
+
1013
+ cxd2837er_config.i2c_addr = 0xd8;
1014
+ cxd2837er_config.xtal = SONY_XTAL_20500;
1015
+ cxd2837er_config.flags = (CXD2841ER_AUTO_IFHZ |
1016
+ CXD2841ER_NO_AGCNEG | CXD2841ER_TSBITS |
1017
+ CXD2841ER_EARLY_TUNE | CXD2841ER_TS_SERIAL);
1018
+ adap->fe[1] = dvb_attach(cxd2841er_attach_t_c,
1019
+ &cxd2837er_config,
1020
+ &d->i2c_adap);
1021
+ if (!adap->fe[1]) {
1022
+ dev->slave_demod = SLAVE_DEMOD_NONE;
1023
+ goto err_slave_demod_failed;
1024
+ }
1025
+ adap->fe[1]->id = 1;
1026
+ dev->i2c_client_slave_demod = NULL;
10011027 } else {
10021028 struct si2168_config si2168_config = {};
10031029 struct i2c_adapter *adapter;
....@@ -1007,12 +1033,12 @@
10071033 si2168_config.ts_mode = SI2168_TS_SERIAL;
10081034 si2168_config.ts_clock_inv = false;
10091035 si2168_config.ts_clock_gapped = true;
1010
- strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1036
+ strscpy(info.type, "si2168", I2C_NAME_SIZE);
10111037 info.addr = 0x64;
10121038 info.platform_data = &si2168_config;
10131039 request_module(info.type);
1014
- client = i2c_new_device(&d->i2c_adap, &info);
1015
- if (client == NULL || client->dev.driver == NULL) {
1040
+ client = i2c_new_client_device(&d->i2c_adap, &info);
1041
+ if (!i2c_client_has_driver(client)) {
10161042 dev->slave_demod = SLAVE_DEMOD_NONE;
10171043 goto err_slave_demod_failed;
10181044 }
....@@ -1198,13 +1224,14 @@
11981224 .clock = 28800000,
11991225 };
12001226
1201
- strlcpy(info.type, "e4000", I2C_NAME_SIZE);
1227
+ strscpy(info.type, "e4000", I2C_NAME_SIZE);
12021228 info.addr = 0x64;
12031229 info.platform_data = &e4000_config;
12041230
12051231 request_module(info.type);
1206
- client = i2c_new_device(dev->demod_i2c_adapter, &info);
1207
- if (client == NULL || client->dev.driver == NULL)
1232
+ client = i2c_new_client_device(dev->demod_i2c_adapter,
1233
+ &info);
1234
+ if (!i2c_client_has_driver(client))
12081235 break;
12091236
12101237 if (!try_module_get(client->dev.driver->owner)) {
....@@ -1222,13 +1249,13 @@
12221249 };
12231250 struct i2c_board_info board_info = {};
12241251
1225
- strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE);
1252
+ strscpy(board_info.type, "fc2580", I2C_NAME_SIZE);
12261253 board_info.addr = 0x56;
12271254 board_info.platform_data = &fc2580_pdata;
12281255 request_module("fc2580");
1229
- client = i2c_new_device(dev->demod_i2c_adapter,
1230
- &board_info);
1231
- if (client == NULL || client->dev.driver == NULL)
1256
+ client = i2c_new_client_device(dev->demod_i2c_adapter,
1257
+ &board_info);
1258
+ if (!i2c_client_has_driver(client))
12321259 break;
12331260 if (!try_module_get(client->dev.driver->owner)) {
12341261 i2c_unregister_device(client);
....@@ -1253,12 +1280,13 @@
12531280 if (ret)
12541281 goto err;
12551282
1256
- strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE);
1283
+ strscpy(board_info.type, "tua9001", I2C_NAME_SIZE);
12571284 board_info.addr = 0x60;
12581285 board_info.platform_data = &tua9001_pdata;
12591286 request_module("tua9001");
1260
- client = i2c_new_device(dev->demod_i2c_adapter, &board_info);
1261
- if (client == NULL || client->dev.driver == NULL)
1287
+ client = i2c_new_client_device(dev->demod_i2c_adapter,
1288
+ &board_info);
1289
+ if (!i2c_client_has_driver(client))
12621290 break;
12631291 if (!try_module_get(client->dev.driver->owner)) {
12641292 i2c_unregister_device(client);
....@@ -1298,12 +1326,12 @@
12981326 .inversion = false,
12991327 };
13001328
1301
- strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1329
+ strscpy(info.type, "si2157", I2C_NAME_SIZE);
13021330 info.addr = 0x60;
13031331 info.platform_data = &si2157_config;
13041332 request_module(info.type);
1305
- client = i2c_new_device(&d->i2c_adap, &info);
1306
- if (client == NULL || client->dev.driver == NULL)
1333
+ client = i2c_new_client_device(&d->i2c_adap, &info);
1334
+ if (!i2c_client_has_driver(client))
13071335 break;
13081336
13091337 if (!try_module_get(client->dev.driver->owner)) {
....@@ -1694,7 +1722,7 @@
16941722 {
16951723 int ret, i, len;
16961724 struct rtl28xxu_dev *dev = d->priv;
1697
- struct ir_raw_event ev;
1725
+ struct ir_raw_event ev = {};
16981726 u8 buf[128];
16991727 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
17001728 {IR_RX_IF, 0x03, 0xff},
....@@ -1760,16 +1788,13 @@
17601788 }
17611789
17621790 /* pass data to Kernel IR decoder */
1763
- init_ir_raw_event(&ev);
1764
-
17651791 for (i = 0; i < len; i++) {
17661792 ev.pulse = buf[i] >> 7;
1767
- ev.duration = 50800 * (buf[i] & 0x7f);
1793
+ ev.duration = 51 * (buf[i] & 0x7f);
17681794 ir_raw_event_store_with_filter(d->rc_dev, &ev);
17691795 }
17701796
17711797 /* 'flush' ir_raw_event_store_with_filter() */
1772
- ir_raw_event_set_idle(d->rc_dev, true);
17731798 ir_raw_event_handle(d->rc_dev);
17741799 exit:
17751800 return ret;
....@@ -1792,6 +1817,8 @@
17921817 rc->driver_type = RC_DRIVER_IR_RAW;
17931818 rc->query = rtl2832u_rc_query;
17941819 rc->interval = 200;
1820
+ /* we program idle len to 0xc0, set timeout to one less */
1821
+ rc->timeout = 0xbf * 51;
17951822
17961823 return 0;
17971824 }
....@@ -1942,10 +1969,13 @@
19421969 &rtl28xxu_props, "Sveon STV27", NULL) },
19431970 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000,
19441971 &rtl28xxu_props, "TURBO-X Pure TV Tuner DTT-2000", NULL) },
1972
+ { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_PROLECTRIX_DV107669,
1973
+ &rtl28xxu_props, "PROlectrix DV107669", NULL) },
19451974
19461975 /* RTL2832P devices: */
19471976 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
1948
- &rtl28xxu_props, "Astrometa DVB-T2", NULL) },
1977
+ &rtl28xxu_props, "Astrometa DVB-T2",
1978
+ RC_MAP_ASTROMETA_T2HYBRID) },
19491979 { DVB_USB_DEVICE(0x5654, 0xca42,
19501980 &rtl28xxu_props, "GoTView MasterHD 3", NULL) },
19511981 { }