| .. | .. |
|---|
| 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" |
|---|
| .. | .. |
|---|
| 393 | 380 | struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf}; |
|---|
| 394 | 381 | struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf}; |
|---|
| 395 | 382 | struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf}; |
|---|
| 383 | + struct rtl28xxu_req req_cxd2837er = {0xfdd8, CMD_I2C_RD, 1, buf}; |
|---|
| 396 | 384 | struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf}; |
|---|
| 397 | 385 | struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf}; |
|---|
| 398 | 386 | |
|---|
| .. | .. |
|---|
| 549 | 537 | |
|---|
| 550 | 538 | /* probe slave demod */ |
|---|
| 551 | 539 | 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 */ |
|---|
| 553 | 552 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01); |
|---|
| 554 | 553 | if (ret) |
|---|
| 555 | 554 | goto err; |
|---|
| .. | .. |
|---|
| 562 | 561 | if (ret) |
|---|
| 563 | 562 | goto err; |
|---|
| 564 | 563 | |
|---|
| 565 | | - /* check MN88472 answers */ |
|---|
| 564 | + /* slave demod needs some time to wake up */ |
|---|
| 565 | + msleep(20); |
|---|
| 566 | + |
|---|
| 567 | + /* check slave answers */ |
|---|
| 566 | 568 | ret = rtl28xxu_ctrl_msg(d, &req_mn88472); |
|---|
| 567 | 569 | if (ret == 0 && buf[0] == 0x02) { |
|---|
| 568 | 570 | dev_dbg(&d->intf->dev, "MN88472 found\n"); |
|---|
| .. | .. |
|---|
| 574 | 576 | if (ret == 0 && buf[0] == 0x03) { |
|---|
| 575 | 577 | dev_dbg(&d->intf->dev, "MN88473 found\n"); |
|---|
| 576 | 578 | 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; |
|---|
| 577 | 586 | goto demod_found; |
|---|
| 578 | 587 | } |
|---|
| 579 | 588 | } |
|---|
| .. | .. |
|---|
| 696 | 705 | |
|---|
| 697 | 706 | /* attach demodulator */ |
|---|
| 698 | 707 | 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); |
|---|
| 700 | 709 | board_info.addr = 0x10; |
|---|
| 701 | 710 | board_info.platform_data = pdata; |
|---|
| 702 | 711 | 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)) { |
|---|
| 705 | 714 | ret = -ENODEV; |
|---|
| 706 | 715 | goto err; |
|---|
| 707 | 716 | } |
|---|
| .. | .. |
|---|
| 917 | 926 | |
|---|
| 918 | 927 | /* attach demodulator */ |
|---|
| 919 | 928 | 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); |
|---|
| 921 | 930 | board_info.addr = 0x10; |
|---|
| 922 | 931 | board_info.platform_data = pdata; |
|---|
| 923 | 932 | 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)) { |
|---|
| 926 | 935 | ret = -ENODEV; |
|---|
| 927 | 936 | goto err; |
|---|
| 928 | 937 | } |
|---|
| .. | .. |
|---|
| 956 | 965 | |
|---|
| 957 | 966 | mn88472_config.fe = &adap->fe[1]; |
|---|
| 958 | 967 | mn88472_config.i2c_wr_max = 22, |
|---|
| 959 | | - strlcpy(info.type, "mn88472", I2C_NAME_SIZE); |
|---|
| 968 | + strscpy(info.type, "mn88472", I2C_NAME_SIZE); |
|---|
| 960 | 969 | mn88472_config.xtal = 20500000; |
|---|
| 961 | 970 | mn88472_config.ts_mode = SERIAL_TS_MODE; |
|---|
| 962 | 971 | mn88472_config.ts_clock = VARIABLE_TS_CLOCK; |
|---|
| 963 | 972 | info.addr = 0x18; |
|---|
| 964 | 973 | info.platform_data = &mn88472_config; |
|---|
| 965 | 974 | 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)) { |
|---|
| 968 | 977 | dev->slave_demod = SLAVE_DEMOD_NONE; |
|---|
| 969 | 978 | goto err_slave_demod_failed; |
|---|
| 970 | 979 | } |
|---|
| .. | .. |
|---|
| 981 | 990 | |
|---|
| 982 | 991 | mn88473_config.fe = &adap->fe[1]; |
|---|
| 983 | 992 | mn88473_config.i2c_wr_max = 22, |
|---|
| 984 | | - strlcpy(info.type, "mn88473", I2C_NAME_SIZE); |
|---|
| 993 | + strscpy(info.type, "mn88473", I2C_NAME_SIZE); |
|---|
| 985 | 994 | info.addr = 0x18; |
|---|
| 986 | 995 | info.platform_data = &mn88473_config; |
|---|
| 987 | 996 | 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)) { |
|---|
| 990 | 999 | dev->slave_demod = SLAVE_DEMOD_NONE; |
|---|
| 991 | 1000 | goto err_slave_demod_failed; |
|---|
| 992 | 1001 | } |
|---|
| .. | .. |
|---|
| 998 | 1007 | } |
|---|
| 999 | 1008 | |
|---|
| 1000 | 1009 | 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; |
|---|
| 1001 | 1027 | } else { |
|---|
| 1002 | 1028 | struct si2168_config si2168_config = {}; |
|---|
| 1003 | 1029 | struct i2c_adapter *adapter; |
|---|
| .. | .. |
|---|
| 1007 | 1033 | si2168_config.ts_mode = SI2168_TS_SERIAL; |
|---|
| 1008 | 1034 | si2168_config.ts_clock_inv = false; |
|---|
| 1009 | 1035 | si2168_config.ts_clock_gapped = true; |
|---|
| 1010 | | - strlcpy(info.type, "si2168", I2C_NAME_SIZE); |
|---|
| 1036 | + strscpy(info.type, "si2168", I2C_NAME_SIZE); |
|---|
| 1011 | 1037 | info.addr = 0x64; |
|---|
| 1012 | 1038 | info.platform_data = &si2168_config; |
|---|
| 1013 | 1039 | 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)) { |
|---|
| 1016 | 1042 | dev->slave_demod = SLAVE_DEMOD_NONE; |
|---|
| 1017 | 1043 | goto err_slave_demod_failed; |
|---|
| 1018 | 1044 | } |
|---|
| .. | .. |
|---|
| 1198 | 1224 | .clock = 28800000, |
|---|
| 1199 | 1225 | }; |
|---|
| 1200 | 1226 | |
|---|
| 1201 | | - strlcpy(info.type, "e4000", I2C_NAME_SIZE); |
|---|
| 1227 | + strscpy(info.type, "e4000", I2C_NAME_SIZE); |
|---|
| 1202 | 1228 | info.addr = 0x64; |
|---|
| 1203 | 1229 | info.platform_data = &e4000_config; |
|---|
| 1204 | 1230 | |
|---|
| 1205 | 1231 | 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)) |
|---|
| 1208 | 1235 | break; |
|---|
| 1209 | 1236 | |
|---|
| 1210 | 1237 | if (!try_module_get(client->dev.driver->owner)) { |
|---|
| .. | .. |
|---|
| 1222 | 1249 | }; |
|---|
| 1223 | 1250 | struct i2c_board_info board_info = {}; |
|---|
| 1224 | 1251 | |
|---|
| 1225 | | - strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE); |
|---|
| 1252 | + strscpy(board_info.type, "fc2580", I2C_NAME_SIZE); |
|---|
| 1226 | 1253 | board_info.addr = 0x56; |
|---|
| 1227 | 1254 | board_info.platform_data = &fc2580_pdata; |
|---|
| 1228 | 1255 | 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)) |
|---|
| 1232 | 1259 | break; |
|---|
| 1233 | 1260 | if (!try_module_get(client->dev.driver->owner)) { |
|---|
| 1234 | 1261 | i2c_unregister_device(client); |
|---|
| .. | .. |
|---|
| 1253 | 1280 | if (ret) |
|---|
| 1254 | 1281 | goto err; |
|---|
| 1255 | 1282 | |
|---|
| 1256 | | - strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE); |
|---|
| 1283 | + strscpy(board_info.type, "tua9001", I2C_NAME_SIZE); |
|---|
| 1257 | 1284 | board_info.addr = 0x60; |
|---|
| 1258 | 1285 | board_info.platform_data = &tua9001_pdata; |
|---|
| 1259 | 1286 | 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)) |
|---|
| 1262 | 1290 | break; |
|---|
| 1263 | 1291 | if (!try_module_get(client->dev.driver->owner)) { |
|---|
| 1264 | 1292 | i2c_unregister_device(client); |
|---|
| .. | .. |
|---|
| 1298 | 1326 | .inversion = false, |
|---|
| 1299 | 1327 | }; |
|---|
| 1300 | 1328 | |
|---|
| 1301 | | - strlcpy(info.type, "si2157", I2C_NAME_SIZE); |
|---|
| 1329 | + strscpy(info.type, "si2157", I2C_NAME_SIZE); |
|---|
| 1302 | 1330 | info.addr = 0x60; |
|---|
| 1303 | 1331 | info.platform_data = &si2157_config; |
|---|
| 1304 | 1332 | 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)) |
|---|
| 1307 | 1335 | break; |
|---|
| 1308 | 1336 | |
|---|
| 1309 | 1337 | if (!try_module_get(client->dev.driver->owner)) { |
|---|
| .. | .. |
|---|
| 1694 | 1722 | { |
|---|
| 1695 | 1723 | int ret, i, len; |
|---|
| 1696 | 1724 | struct rtl28xxu_dev *dev = d->priv; |
|---|
| 1697 | | - struct ir_raw_event ev; |
|---|
| 1725 | + struct ir_raw_event ev = {}; |
|---|
| 1698 | 1726 | u8 buf[128]; |
|---|
| 1699 | 1727 | static const struct rtl28xxu_reg_val_mask refresh_tab[] = { |
|---|
| 1700 | 1728 | {IR_RX_IF, 0x03, 0xff}, |
|---|
| .. | .. |
|---|
| 1760 | 1788 | } |
|---|
| 1761 | 1789 | |
|---|
| 1762 | 1790 | /* pass data to Kernel IR decoder */ |
|---|
| 1763 | | - init_ir_raw_event(&ev); |
|---|
| 1764 | | - |
|---|
| 1765 | 1791 | for (i = 0; i < len; i++) { |
|---|
| 1766 | 1792 | ev.pulse = buf[i] >> 7; |
|---|
| 1767 | | - ev.duration = 50800 * (buf[i] & 0x7f); |
|---|
| 1793 | + ev.duration = 51 * (buf[i] & 0x7f); |
|---|
| 1768 | 1794 | ir_raw_event_store_with_filter(d->rc_dev, &ev); |
|---|
| 1769 | 1795 | } |
|---|
| 1770 | 1796 | |
|---|
| 1771 | 1797 | /* 'flush' ir_raw_event_store_with_filter() */ |
|---|
| 1772 | | - ir_raw_event_set_idle(d->rc_dev, true); |
|---|
| 1773 | 1798 | ir_raw_event_handle(d->rc_dev); |
|---|
| 1774 | 1799 | exit: |
|---|
| 1775 | 1800 | return ret; |
|---|
| .. | .. |
|---|
| 1792 | 1817 | rc->driver_type = RC_DRIVER_IR_RAW; |
|---|
| 1793 | 1818 | rc->query = rtl2832u_rc_query; |
|---|
| 1794 | 1819 | rc->interval = 200; |
|---|
| 1820 | + /* we program idle len to 0xc0, set timeout to one less */ |
|---|
| 1821 | + rc->timeout = 0xbf * 51; |
|---|
| 1795 | 1822 | |
|---|
| 1796 | 1823 | return 0; |
|---|
| 1797 | 1824 | } |
|---|
| .. | .. |
|---|
| 1942 | 1969 | &rtl28xxu_props, "Sveon STV27", NULL) }, |
|---|
| 1943 | 1970 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000, |
|---|
| 1944 | 1971 | &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) }, |
|---|
| 1945 | 1974 | |
|---|
| 1946 | 1975 | /* RTL2832P devices: */ |
|---|
| 1947 | 1976 | { 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) }, |
|---|
| 1949 | 1979 | { DVB_USB_DEVICE(0x5654, 0xca42, |
|---|
| 1950 | 1980 | &rtl28xxu_props, "GoTView MasterHD 3", NULL) }, |
|---|
| 1951 | 1981 | { } |
|---|