.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Realtek RTL28xxU DVB USB driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
---|
5 | 6 | * Copyright (C) 2011 Antti Palosaari <crope@iki.fi> |
---|
6 | 7 | * 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. |
---|
21 | 8 | */ |
---|
22 | 9 | |
---|
23 | 10 | #include "rtl28xxu.h" |
---|
.. | .. |
---|
189 | 176 | ret = -EOPNOTSUPP; |
---|
190 | 177 | goto err_mutex_unlock; |
---|
191 | 178 | } 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 | + } |
---|
192 | 183 | /* method 1 - integrated demod */ |
---|
193 | 184 | if (msg[0].buf[0] == 0x00) { |
---|
194 | 185 | /* return demod page from driver cache */ |
---|
.. | .. |
---|
202 | 193 | ret = rtl28xxu_ctrl_msg(d, &req); |
---|
203 | 194 | } |
---|
204 | 195 | } else if (msg[0].len < 2) { |
---|
| 196 | + if (msg[0].len < 1) { |
---|
| 197 | + ret = -EOPNOTSUPP; |
---|
| 198 | + goto err_mutex_unlock; |
---|
| 199 | + } |
---|
205 | 200 | /* method 2 - old I2C */ |
---|
206 | 201 | req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); |
---|
207 | 202 | req.index = CMD_I2C_RD; |
---|
.. | .. |
---|
230 | 225 | ret = -EOPNOTSUPP; |
---|
231 | 226 | goto err_mutex_unlock; |
---|
232 | 227 | } else if (msg[0].addr == 0x10) { |
---|
| 228 | + if (msg[0].len < 1) { |
---|
| 229 | + ret = -EOPNOTSUPP; |
---|
| 230 | + goto err_mutex_unlock; |
---|
| 231 | + } |
---|
233 | 232 | /* method 1 - integrated demod */ |
---|
234 | 233 | if (msg[0].buf[0] == 0x00) { |
---|
| 234 | + if (msg[0].len < 2) { |
---|
| 235 | + ret = -EOPNOTSUPP; |
---|
| 236 | + goto err_mutex_unlock; |
---|
| 237 | + } |
---|
235 | 238 | /* save demod page for later demod access */ |
---|
236 | 239 | dev->page = msg[0].buf[1]; |
---|
237 | 240 | ret = 0; |
---|
.. | .. |
---|
244 | 247 | ret = rtl28xxu_ctrl_msg(d, &req); |
---|
245 | 248 | } |
---|
246 | 249 | } 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 | + } |
---|
247 | 254 | /* method 2 - old I2C */ |
---|
248 | 255 | req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); |
---|
249 | 256 | req.index = CMD_I2C_WR; |
---|
.. | .. |
---|
393 | 400 | struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf}; |
---|
394 | 401 | struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf}; |
---|
395 | 402 | struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf}; |
---|
| 403 | + struct rtl28xxu_req req_cxd2837er = {0xfdd8, CMD_I2C_RD, 1, buf}; |
---|
396 | 404 | struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf}; |
---|
397 | 405 | struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf}; |
---|
398 | 406 | |
---|
.. | .. |
---|
549 | 557 | |
---|
550 | 558 | /* probe slave demod */ |
---|
551 | 559 | 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 */ |
---|
553 | 572 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01); |
---|
554 | 573 | if (ret) |
---|
555 | 574 | goto err; |
---|
.. | .. |
---|
562 | 581 | if (ret) |
---|
563 | 582 | goto err; |
---|
564 | 583 | |
---|
565 | | - /* check MN88472 answers */ |
---|
| 584 | + /* slave demod needs some time to wake up */ |
---|
| 585 | + msleep(20); |
---|
| 586 | + |
---|
| 587 | + /* check slave answers */ |
---|
566 | 588 | ret = rtl28xxu_ctrl_msg(d, &req_mn88472); |
---|
567 | 589 | if (ret == 0 && buf[0] == 0x02) { |
---|
568 | 590 | dev_dbg(&d->intf->dev, "MN88472 found\n"); |
---|
.. | .. |
---|
574 | 596 | if (ret == 0 && buf[0] == 0x03) { |
---|
575 | 597 | dev_dbg(&d->intf->dev, "MN88473 found\n"); |
---|
576 | 598 | 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; |
---|
577 | 606 | goto demod_found; |
---|
578 | 607 | } |
---|
579 | 608 | } |
---|
.. | .. |
---|
696 | 725 | |
---|
697 | 726 | /* attach demodulator */ |
---|
698 | 727 | 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); |
---|
700 | 729 | board_info.addr = 0x10; |
---|
701 | 730 | board_info.platform_data = pdata; |
---|
702 | 731 | 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)) { |
---|
705 | 734 | ret = -ENODEV; |
---|
706 | 735 | goto err; |
---|
707 | 736 | } |
---|
.. | .. |
---|
917 | 946 | |
---|
918 | 947 | /* attach demodulator */ |
---|
919 | 948 | 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); |
---|
921 | 950 | board_info.addr = 0x10; |
---|
922 | 951 | board_info.platform_data = pdata; |
---|
923 | 952 | 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)) { |
---|
926 | 955 | ret = -ENODEV; |
---|
927 | 956 | goto err; |
---|
928 | 957 | } |
---|
.. | .. |
---|
956 | 985 | |
---|
957 | 986 | mn88472_config.fe = &adap->fe[1]; |
---|
958 | 987 | mn88472_config.i2c_wr_max = 22, |
---|
959 | | - strlcpy(info.type, "mn88472", I2C_NAME_SIZE); |
---|
| 988 | + strscpy(info.type, "mn88472", I2C_NAME_SIZE); |
---|
960 | 989 | mn88472_config.xtal = 20500000; |
---|
961 | 990 | mn88472_config.ts_mode = SERIAL_TS_MODE; |
---|
962 | 991 | mn88472_config.ts_clock = VARIABLE_TS_CLOCK; |
---|
963 | 992 | info.addr = 0x18; |
---|
964 | 993 | info.platform_data = &mn88472_config; |
---|
965 | 994 | 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)) { |
---|
968 | 997 | dev->slave_demod = SLAVE_DEMOD_NONE; |
---|
969 | 998 | goto err_slave_demod_failed; |
---|
970 | 999 | } |
---|
.. | .. |
---|
981 | 1010 | |
---|
982 | 1011 | mn88473_config.fe = &adap->fe[1]; |
---|
983 | 1012 | mn88473_config.i2c_wr_max = 22, |
---|
984 | | - strlcpy(info.type, "mn88473", I2C_NAME_SIZE); |
---|
| 1013 | + strscpy(info.type, "mn88473", I2C_NAME_SIZE); |
---|
985 | 1014 | info.addr = 0x18; |
---|
986 | 1015 | info.platform_data = &mn88473_config; |
---|
987 | 1016 | 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)) { |
---|
990 | 1019 | dev->slave_demod = SLAVE_DEMOD_NONE; |
---|
991 | 1020 | goto err_slave_demod_failed; |
---|
992 | 1021 | } |
---|
.. | .. |
---|
998 | 1027 | } |
---|
999 | 1028 | |
---|
1000 | 1029 | 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; |
---|
1001 | 1047 | } else { |
---|
1002 | 1048 | struct si2168_config si2168_config = {}; |
---|
1003 | 1049 | struct i2c_adapter *adapter; |
---|
.. | .. |
---|
1007 | 1053 | si2168_config.ts_mode = SI2168_TS_SERIAL; |
---|
1008 | 1054 | si2168_config.ts_clock_inv = false; |
---|
1009 | 1055 | si2168_config.ts_clock_gapped = true; |
---|
1010 | | - strlcpy(info.type, "si2168", I2C_NAME_SIZE); |
---|
| 1056 | + strscpy(info.type, "si2168", I2C_NAME_SIZE); |
---|
1011 | 1057 | info.addr = 0x64; |
---|
1012 | 1058 | info.platform_data = &si2168_config; |
---|
1013 | 1059 | 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)) { |
---|
1016 | 1062 | dev->slave_demod = SLAVE_DEMOD_NONE; |
---|
1017 | 1063 | goto err_slave_demod_failed; |
---|
1018 | 1064 | } |
---|
.. | .. |
---|
1198 | 1244 | .clock = 28800000, |
---|
1199 | 1245 | }; |
---|
1200 | 1246 | |
---|
1201 | | - strlcpy(info.type, "e4000", I2C_NAME_SIZE); |
---|
| 1247 | + strscpy(info.type, "e4000", I2C_NAME_SIZE); |
---|
1202 | 1248 | info.addr = 0x64; |
---|
1203 | 1249 | info.platform_data = &e4000_config; |
---|
1204 | 1250 | |
---|
1205 | 1251 | 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)) |
---|
1208 | 1255 | break; |
---|
1209 | 1256 | |
---|
1210 | 1257 | if (!try_module_get(client->dev.driver->owner)) { |
---|
.. | .. |
---|
1222 | 1269 | }; |
---|
1223 | 1270 | struct i2c_board_info board_info = {}; |
---|
1224 | 1271 | |
---|
1225 | | - strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE); |
---|
| 1272 | + strscpy(board_info.type, "fc2580", I2C_NAME_SIZE); |
---|
1226 | 1273 | board_info.addr = 0x56; |
---|
1227 | 1274 | board_info.platform_data = &fc2580_pdata; |
---|
1228 | 1275 | 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)) |
---|
1232 | 1279 | break; |
---|
1233 | 1280 | if (!try_module_get(client->dev.driver->owner)) { |
---|
1234 | 1281 | i2c_unregister_device(client); |
---|
.. | .. |
---|
1253 | 1300 | if (ret) |
---|
1254 | 1301 | goto err; |
---|
1255 | 1302 | |
---|
1256 | | - strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE); |
---|
| 1303 | + strscpy(board_info.type, "tua9001", I2C_NAME_SIZE); |
---|
1257 | 1304 | board_info.addr = 0x60; |
---|
1258 | 1305 | board_info.platform_data = &tua9001_pdata; |
---|
1259 | 1306 | 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)) |
---|
1262 | 1310 | break; |
---|
1263 | 1311 | if (!try_module_get(client->dev.driver->owner)) { |
---|
1264 | 1312 | i2c_unregister_device(client); |
---|
.. | .. |
---|
1298 | 1346 | .inversion = false, |
---|
1299 | 1347 | }; |
---|
1300 | 1348 | |
---|
1301 | | - strlcpy(info.type, "si2157", I2C_NAME_SIZE); |
---|
| 1349 | + strscpy(info.type, "si2157", I2C_NAME_SIZE); |
---|
1302 | 1350 | info.addr = 0x60; |
---|
1303 | 1351 | info.platform_data = &si2157_config; |
---|
1304 | 1352 | 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)) |
---|
1307 | 1355 | break; |
---|
1308 | 1356 | |
---|
1309 | 1357 | if (!try_module_get(client->dev.driver->owner)) { |
---|
.. | .. |
---|
1694 | 1742 | { |
---|
1695 | 1743 | int ret, i, len; |
---|
1696 | 1744 | struct rtl28xxu_dev *dev = d->priv; |
---|
1697 | | - struct ir_raw_event ev; |
---|
| 1745 | + struct ir_raw_event ev = {}; |
---|
1698 | 1746 | u8 buf[128]; |
---|
1699 | 1747 | static const struct rtl28xxu_reg_val_mask refresh_tab[] = { |
---|
1700 | 1748 | {IR_RX_IF, 0x03, 0xff}, |
---|
.. | .. |
---|
1760 | 1808 | } |
---|
1761 | 1809 | |
---|
1762 | 1810 | /* pass data to Kernel IR decoder */ |
---|
1763 | | - init_ir_raw_event(&ev); |
---|
1764 | | - |
---|
1765 | 1811 | for (i = 0; i < len; i++) { |
---|
1766 | 1812 | ev.pulse = buf[i] >> 7; |
---|
1767 | | - ev.duration = 50800 * (buf[i] & 0x7f); |
---|
| 1813 | + ev.duration = 51 * (buf[i] & 0x7f); |
---|
1768 | 1814 | ir_raw_event_store_with_filter(d->rc_dev, &ev); |
---|
1769 | 1815 | } |
---|
1770 | 1816 | |
---|
1771 | 1817 | /* 'flush' ir_raw_event_store_with_filter() */ |
---|
1772 | | - ir_raw_event_set_idle(d->rc_dev, true); |
---|
1773 | 1818 | ir_raw_event_handle(d->rc_dev); |
---|
1774 | 1819 | exit: |
---|
1775 | 1820 | return ret; |
---|
.. | .. |
---|
1792 | 1837 | rc->driver_type = RC_DRIVER_IR_RAW; |
---|
1793 | 1838 | rc->query = rtl2832u_rc_query; |
---|
1794 | 1839 | rc->interval = 200; |
---|
| 1840 | + /* we program idle len to 0xc0, set timeout to one less */ |
---|
| 1841 | + rc->timeout = 0xbf * 51; |
---|
1795 | 1842 | |
---|
1796 | 1843 | return 0; |
---|
1797 | 1844 | } |
---|
.. | .. |
---|
1942 | 1989 | &rtl28xxu_props, "Sveon STV27", NULL) }, |
---|
1943 | 1990 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000, |
---|
1944 | 1991 | &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) }, |
---|
1945 | 1994 | |
---|
1946 | 1995 | /* RTL2832P devices: */ |
---|
1947 | 1996 | { 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) }, |
---|
1949 | 1999 | { DVB_USB_DEVICE(0x5654, 0xca42, |
---|
1950 | 2000 | &rtl28xxu_props, "GoTView MasterHD 3", NULL) }, |
---|
1951 | 2001 | { } |
---|