18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 28c2ecf20Sopenharmony_ci/* Copyright(c) 2018-2019 Realtek Corporation 38c2ecf20Sopenharmony_ci */ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/module.h> 68c2ecf20Sopenharmony_ci#include "main.h" 78c2ecf20Sopenharmony_ci#include "coex.h" 88c2ecf20Sopenharmony_ci#include "fw.h" 98c2ecf20Sopenharmony_ci#include "tx.h" 108c2ecf20Sopenharmony_ci#include "rx.h" 118c2ecf20Sopenharmony_ci#include "phy.h" 128c2ecf20Sopenharmony_ci#include "rtw8723d.h" 138c2ecf20Sopenharmony_ci#include "rtw8723d_table.h" 148c2ecf20Sopenharmony_ci#include "mac.h" 158c2ecf20Sopenharmony_ci#include "reg.h" 168c2ecf20Sopenharmony_ci#include "debug.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic const struct rtw_hw_reg rtw8723d_txagc[] = { 198c2ecf20Sopenharmony_ci [DESC_RATE1M] = { .addr = 0xe08, .mask = 0x0000ff00 }, 208c2ecf20Sopenharmony_ci [DESC_RATE2M] = { .addr = 0x86c, .mask = 0x0000ff00 }, 218c2ecf20Sopenharmony_ci [DESC_RATE5_5M] = { .addr = 0x86c, .mask = 0x00ff0000 }, 228c2ecf20Sopenharmony_ci [DESC_RATE11M] = { .addr = 0x86c, .mask = 0xff000000 }, 238c2ecf20Sopenharmony_ci [DESC_RATE6M] = { .addr = 0xe00, .mask = 0x000000ff }, 248c2ecf20Sopenharmony_ci [DESC_RATE9M] = { .addr = 0xe00, .mask = 0x0000ff00 }, 258c2ecf20Sopenharmony_ci [DESC_RATE12M] = { .addr = 0xe00, .mask = 0x00ff0000 }, 268c2ecf20Sopenharmony_ci [DESC_RATE18M] = { .addr = 0xe00, .mask = 0xff000000 }, 278c2ecf20Sopenharmony_ci [DESC_RATE24M] = { .addr = 0xe04, .mask = 0x000000ff }, 288c2ecf20Sopenharmony_ci [DESC_RATE36M] = { .addr = 0xe04, .mask = 0x0000ff00 }, 298c2ecf20Sopenharmony_ci [DESC_RATE48M] = { .addr = 0xe04, .mask = 0x00ff0000 }, 308c2ecf20Sopenharmony_ci [DESC_RATE54M] = { .addr = 0xe04, .mask = 0xff000000 }, 318c2ecf20Sopenharmony_ci [DESC_RATEMCS0] = { .addr = 0xe10, .mask = 0x000000ff }, 328c2ecf20Sopenharmony_ci [DESC_RATEMCS1] = { .addr = 0xe10, .mask = 0x0000ff00 }, 338c2ecf20Sopenharmony_ci [DESC_RATEMCS2] = { .addr = 0xe10, .mask = 0x00ff0000 }, 348c2ecf20Sopenharmony_ci [DESC_RATEMCS3] = { .addr = 0xe10, .mask = 0xff000000 }, 358c2ecf20Sopenharmony_ci [DESC_RATEMCS4] = { .addr = 0xe14, .mask = 0x000000ff }, 368c2ecf20Sopenharmony_ci [DESC_RATEMCS5] = { .addr = 0xe14, .mask = 0x0000ff00 }, 378c2ecf20Sopenharmony_ci [DESC_RATEMCS6] = { .addr = 0xe14, .mask = 0x00ff0000 }, 388c2ecf20Sopenharmony_ci [DESC_RATEMCS7] = { .addr = 0xe14, .mask = 0xff000000 }, 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define WLAN_TXQ_RPT_EN 0x1F 428c2ecf20Sopenharmony_ci#define WLAN_SLOT_TIME 0x09 438c2ecf20Sopenharmony_ci#define WLAN_RL_VAL 0x3030 448c2ecf20Sopenharmony_ci#define WLAN_BAR_VAL 0x0201ffff 458c2ecf20Sopenharmony_ci#define BIT_MASK_TBTT_HOLD 0x00000fff 468c2ecf20Sopenharmony_ci#define BIT_SHIFT_TBTT_HOLD 8 478c2ecf20Sopenharmony_ci#define BIT_MASK_TBTT_SETUP 0x000000ff 488c2ecf20Sopenharmony_ci#define BIT_SHIFT_TBTT_SETUP 0 498c2ecf20Sopenharmony_ci#define BIT_MASK_TBTT_MASK ((BIT_MASK_TBTT_HOLD << BIT_SHIFT_TBTT_HOLD) | \ 508c2ecf20Sopenharmony_ci (BIT_MASK_TBTT_SETUP << BIT_SHIFT_TBTT_SETUP)) 518c2ecf20Sopenharmony_ci#define TBTT_TIME(s, h)((((s) & BIT_MASK_TBTT_SETUP) << BIT_SHIFT_TBTT_SETUP) |\ 528c2ecf20Sopenharmony_ci (((h) & BIT_MASK_TBTT_HOLD) << BIT_SHIFT_TBTT_HOLD)) 538c2ecf20Sopenharmony_ci#define WLAN_TBTT_TIME_NORMAL TBTT_TIME(0x04, 0x80) 548c2ecf20Sopenharmony_ci#define WLAN_TBTT_TIME_STOP_BCN TBTT_TIME(0x04, 0x64) 558c2ecf20Sopenharmony_ci#define WLAN_PIFS_VAL 0 568c2ecf20Sopenharmony_ci#define WLAN_AGG_BRK_TIME 0x16 578c2ecf20Sopenharmony_ci#define WLAN_NAV_PROT_LEN 0x0040 588c2ecf20Sopenharmony_ci#define WLAN_SPEC_SIFS 0x100a 598c2ecf20Sopenharmony_ci#define WLAN_RX_PKT_LIMIT 0x17 608c2ecf20Sopenharmony_ci#define WLAN_MAX_AGG_NR 0x0A 618c2ecf20Sopenharmony_ci#define WLAN_AMPDU_MAX_TIME 0x1C 628c2ecf20Sopenharmony_ci#define WLAN_ANT_SEL 0x82 638c2ecf20Sopenharmony_ci#define WLAN_LTR_IDLE_LAT 0x883C883C 648c2ecf20Sopenharmony_ci#define WLAN_LTR_ACT_LAT 0x880B880B 658c2ecf20Sopenharmony_ci#define WLAN_LTR_CTRL1 0xCB004010 668c2ecf20Sopenharmony_ci#define WLAN_LTR_CTRL2 0x01233425 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic void rtw8723d_lck(struct rtw_dev *rtwdev) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci u32 lc_cal; 718c2ecf20Sopenharmony_ci u8 val_ctx, rf_val; 728c2ecf20Sopenharmony_ci int ret; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci val_ctx = rtw_read8(rtwdev, REG_CTX); 758c2ecf20Sopenharmony_ci if ((val_ctx & BIT_MASK_CTX_TYPE) != 0) 768c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_CTX, val_ctx & ~BIT_MASK_CTX_TYPE); 778c2ecf20Sopenharmony_ci else 788c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_TXPAUSE, 0xFF); 798c2ecf20Sopenharmony_ci lc_cal = rtw_read_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, lc_cal | BIT_LCK); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci ret = read_poll_timeout(rtw_read_rf, rf_val, rf_val != 0x1, 848c2ecf20Sopenharmony_ci 10000, 1000000, false, 858c2ecf20Sopenharmony_ci rtwdev, RF_PATH_A, RF_CFGCH, BIT_LCK); 868c2ecf20Sopenharmony_ci if (ret) 878c2ecf20Sopenharmony_ci rtw_warn(rtwdev, "failed to poll LCK status bit\n"); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, lc_cal); 908c2ecf20Sopenharmony_ci if ((val_ctx & BIT_MASK_CTX_TYPE) != 0) 918c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_CTX, val_ctx); 928c2ecf20Sopenharmony_ci else 938c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_TXPAUSE, 0x00); 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic const u32 rtw8723d_ofdm_swing_table[] = { 978c2ecf20Sopenharmony_ci 0x0b40002d, 0x0c000030, 0x0cc00033, 0x0d800036, 0x0e400039, 0x0f00003c, 988c2ecf20Sopenharmony_ci 0x10000040, 0x11000044, 0x12000048, 0x1300004c, 0x14400051, 0x15800056, 998c2ecf20Sopenharmony_ci 0x16c0005b, 0x18000060, 0x19800066, 0x1b00006c, 0x1c800072, 0x1e400079, 1008c2ecf20Sopenharmony_ci 0x20000080, 0x22000088, 0x24000090, 0x26000098, 0x288000a2, 0x2ac000ab, 1018c2ecf20Sopenharmony_ci 0x2d4000b5, 0x300000c0, 0x32c000cb, 0x35c000d7, 0x390000e4, 0x3c8000f2, 1028c2ecf20Sopenharmony_ci 0x40000100, 0x43c0010f, 0x47c0011f, 0x4c000130, 0x50800142, 0x55400155, 1038c2ecf20Sopenharmony_ci 0x5a400169, 0x5fc0017f, 0x65400195, 0x6b8001ae, 0x71c001c7, 0x788001e2, 1048c2ecf20Sopenharmony_ci 0x7f8001fe, 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const u32 rtw8723d_cck_swing_table[] = { 1088c2ecf20Sopenharmony_ci 0x0CD, 0x0D9, 0x0E6, 0x0F3, 0x102, 0x111, 0x121, 0x132, 0x144, 0x158, 1098c2ecf20Sopenharmony_ci 0x16C, 0x182, 0x198, 0x1B1, 0x1CA, 0x1E5, 0x202, 0x221, 0x241, 0x263, 1108c2ecf20Sopenharmony_ci 0x287, 0x2AE, 0x2D6, 0x301, 0x32F, 0x35F, 0x392, 0x3C9, 0x402, 0x43F, 1118c2ecf20Sopenharmony_ci 0x47F, 0x4C3, 0x50C, 0x558, 0x5A9, 0x5FF, 0x65A, 0x6BA, 0x720, 0x78C, 1128c2ecf20Sopenharmony_ci 0x7FF, 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define RTW_OFDM_SWING_TABLE_SIZE ARRAY_SIZE(rtw8723d_ofdm_swing_table) 1168c2ecf20Sopenharmony_ci#define RTW_CCK_SWING_TABLE_SIZE ARRAY_SIZE(rtw8723d_cck_swing_table) 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_cistatic void rtw8723d_pwrtrack_init(struct rtw_dev *rtwdev) 1198c2ecf20Sopenharmony_ci{ 1208c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 1218c2ecf20Sopenharmony_ci u8 path; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci dm_info->default_ofdm_index = RTW_DEF_OFDM_SWING_INDEX; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci for (path = RF_PATH_A; path < rtwdev->hal.rf_path_num; path++) { 1268c2ecf20Sopenharmony_ci ewma_thermal_init(&dm_info->avg_thermal[path]); 1278c2ecf20Sopenharmony_ci dm_info->delta_power_index[path] = 0; 1288c2ecf20Sopenharmony_ci } 1298c2ecf20Sopenharmony_ci dm_info->pwr_trk_triggered = false; 1308c2ecf20Sopenharmony_ci dm_info->pwr_trk_init_trigger = true; 1318c2ecf20Sopenharmony_ci dm_info->thermal_meter_k = rtwdev->efuse.thermal_meter_k; 1328c2ecf20Sopenharmony_ci dm_info->txagc_remnant_cck = 0; 1338c2ecf20Sopenharmony_ci dm_info->txagc_remnant_ofdm = 0; 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic void rtw8723d_phy_set_param(struct rtw_dev *rtwdev) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci u8 xtal_cap; 1398c2ecf20Sopenharmony_ci u32 val32; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci /* power on BB/RF domain */ 1428c2ecf20Sopenharmony_ci rtw_write16_set(rtwdev, REG_SYS_FUNC_EN, 1438c2ecf20Sopenharmony_ci BIT_FEN_EN_25_1 | BIT_FEN_BB_GLB_RST | BIT_FEN_BB_RSTB); 1448c2ecf20Sopenharmony_ci rtw_write8_set(rtwdev, REG_RF_CTRL, 1458c2ecf20Sopenharmony_ci BIT_RF_EN | BIT_RF_RSTB | BIT_RF_SDM_RSTB); 1468c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_AFE_CTRL1 + 1, 0x80); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci rtw_phy_load_tables(rtwdev); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* post init after header files config */ 1518c2ecf20Sopenharmony_ci rtw_write32_clr(rtwdev, REG_RCR, BIT_RCR_ADF); 1528c2ecf20Sopenharmony_ci rtw_write8_set(rtwdev, REG_HIQ_NO_LMT_EN, BIT_HIQ_NO_LMT_EN_ROOT); 1538c2ecf20Sopenharmony_ci rtw_write16_set(rtwdev, REG_AFE_CTRL_4, BIT_CK320M_AFE_EN | BIT_EN_SYN); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci xtal_cap = rtwdev->efuse.crystal_cap & 0x3F; 1568c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_AFE_CTRL3, BIT_MASK_XTAL, 1578c2ecf20Sopenharmony_ci xtal_cap | (xtal_cap << 6)); 1588c2ecf20Sopenharmony_ci rtw_write32_set(rtwdev, REG_FPGA0_RFMOD, BIT_CCKEN | BIT_OFDMEN); 1598c2ecf20Sopenharmony_ci if ((rtwdev->efuse.afe >> 4) == 14) { 1608c2ecf20Sopenharmony_ci rtw_write32_set(rtwdev, REG_AFE_CTRL3, BIT_XTAL_GMP_BIT4); 1618c2ecf20Sopenharmony_ci rtw_write32_clr(rtwdev, REG_AFE_CTRL1, BITS_PLL); 1628c2ecf20Sopenharmony_ci rtw_write32_set(rtwdev, REG_LDO_SWR_CTRL, BIT_XTA1); 1638c2ecf20Sopenharmony_ci rtw_write32_clr(rtwdev, REG_LDO_SWR_CTRL, BIT_XTA0); 1648c2ecf20Sopenharmony_ci } 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_SLOT, WLAN_SLOT_TIME); 1678c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 1, WLAN_TXQ_RPT_EN); 1688c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_RETRY_LIMIT, WLAN_RL_VAL); 1698c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BAR_MODE_CTRL, WLAN_BAR_VAL); 1708c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_ATIMWND, 0x2); 1718c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_BCN_CTRL, 1728c2ecf20Sopenharmony_ci BIT_DIS_TSF_UDT | BIT_EN_BCN_FUNCTION | BIT_EN_TXBCN_RPT); 1738c2ecf20Sopenharmony_ci val32 = rtw_read32(rtwdev, REG_TBTT_PROHIBIT); 1748c2ecf20Sopenharmony_ci val32 &= ~BIT_MASK_TBTT_MASK; 1758c2ecf20Sopenharmony_ci val32 |= WLAN_TBTT_TIME_STOP_BCN; 1768c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_TBTT_PROHIBIT, val32); 1778c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_PIFS, WLAN_PIFS_VAL); 1788c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_AGGR_BREAK_TIME, WLAN_AGG_BRK_TIME); 1798c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_NAV_PROT_LEN, WLAN_NAV_PROT_LEN); 1808c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_MAC_SPEC_SIFS, WLAN_SPEC_SIFS); 1818c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_SIFS, WLAN_SPEC_SIFS); 1828c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_SIFS + 2, WLAN_SPEC_SIFS); 1838c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_SINGLE_AMPDU_CTRL, BIT_EN_SINGLE_APMDU); 1848c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_RX_PKT_LIMIT, WLAN_RX_PKT_LIMIT); 1858c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_MAX_AGGR_NUM, WLAN_MAX_AGG_NR); 1868c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_AMPDU_MAX_TIME, WLAN_AMPDU_MAX_TIME); 1878c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_LEDCFG2, WLAN_ANT_SEL); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTR_IDLE_LATENCY, WLAN_LTR_IDLE_LAT); 1908c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTR_ACTIVE_LATENCY, WLAN_LTR_ACT_LAT); 1918c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTR_CTRL_BASIC, WLAN_LTR_CTRL1); 1928c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTR_CTRL_BASIC + 4, WLAN_LTR_CTRL2); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci rtw_phy_init(rtwdev); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci rtw_write16_set(rtwdev, REG_TXDMA_OFFSET_CHK, BIT_DROP_DATA_EN); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci rtw8723d_lck(rtwdev); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, 0x50); 2018c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, 0x20); 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_init(rtwdev); 2048c2ecf20Sopenharmony_ci} 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_cistatic void rtw8723de_efuse_parsing(struct rtw_efuse *efuse, 2078c2ecf20Sopenharmony_ci struct rtw8723d_efuse *map) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci ether_addr_copy(efuse->addr, map->e.mac_addr); 2108c2ecf20Sopenharmony_ci} 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistatic int rtw8723d_read_efuse(struct rtw_dev *rtwdev, u8 *log_map) 2138c2ecf20Sopenharmony_ci{ 2148c2ecf20Sopenharmony_ci struct rtw_efuse *efuse = &rtwdev->efuse; 2158c2ecf20Sopenharmony_ci struct rtw8723d_efuse *map; 2168c2ecf20Sopenharmony_ci int i; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci map = (struct rtw8723d_efuse *)log_map; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci efuse->rfe_option = 0; 2218c2ecf20Sopenharmony_ci efuse->rf_board_option = map->rf_board_option; 2228c2ecf20Sopenharmony_ci efuse->crystal_cap = map->xtal_k; 2238c2ecf20Sopenharmony_ci efuse->pa_type_2g = map->pa_type; 2248c2ecf20Sopenharmony_ci efuse->lna_type_2g = map->lna_type_2g[0]; 2258c2ecf20Sopenharmony_ci efuse->channel_plan = map->channel_plan; 2268c2ecf20Sopenharmony_ci efuse->country_code[0] = map->country_code[0]; 2278c2ecf20Sopenharmony_ci efuse->country_code[1] = map->country_code[1]; 2288c2ecf20Sopenharmony_ci efuse->bt_setting = map->rf_bt_setting; 2298c2ecf20Sopenharmony_ci efuse->regd = map->rf_board_option & 0x7; 2308c2ecf20Sopenharmony_ci efuse->thermal_meter[0] = map->thermal_meter; 2318c2ecf20Sopenharmony_ci efuse->thermal_meter_k = map->thermal_meter; 2328c2ecf20Sopenharmony_ci efuse->afe = map->afe; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) 2358c2ecf20Sopenharmony_ci efuse->txpwr_idx_table[i] = map->txpwr_idx_table[i]; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci switch (rtw_hci_type(rtwdev)) { 2388c2ecf20Sopenharmony_ci case RTW_HCI_TYPE_PCIE: 2398c2ecf20Sopenharmony_ci rtw8723de_efuse_parsing(efuse, map); 2408c2ecf20Sopenharmony_ci break; 2418c2ecf20Sopenharmony_ci default: 2428c2ecf20Sopenharmony_ci /* unsupported now */ 2438c2ecf20Sopenharmony_ci return -ENOTSUPP; 2448c2ecf20Sopenharmony_ci } 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci return 0; 2478c2ecf20Sopenharmony_ci} 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic void query_phy_status_page0(struct rtw_dev *rtwdev, u8 *phy_status, 2508c2ecf20Sopenharmony_ci struct rtw_rx_pkt_stat *pkt_stat) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 2538c2ecf20Sopenharmony_ci s8 min_rx_power = -120; 2548c2ecf20Sopenharmony_ci u8 pwdb = GET_PHY_STAT_P0_PWDB(phy_status); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci pkt_stat->rx_power[RF_PATH_A] = pwdb - 97; 2578c2ecf20Sopenharmony_ci pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1); 2588c2ecf20Sopenharmony_ci pkt_stat->bw = RTW_CHANNEL_WIDTH_20; 2598c2ecf20Sopenharmony_ci pkt_stat->signal_power = max(pkt_stat->rx_power[RF_PATH_A], 2608c2ecf20Sopenharmony_ci min_rx_power); 2618c2ecf20Sopenharmony_ci dm_info->rssi[RF_PATH_A] = pkt_stat->rssi; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic void query_phy_status_page1(struct rtw_dev *rtwdev, u8 *phy_status, 2658c2ecf20Sopenharmony_ci struct rtw_rx_pkt_stat *pkt_stat) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 2688c2ecf20Sopenharmony_ci u8 rxsc, bw; 2698c2ecf20Sopenharmony_ci s8 min_rx_power = -120; 2708c2ecf20Sopenharmony_ci s8 rx_evm; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci if (pkt_stat->rate > DESC_RATE11M && pkt_stat->rate < DESC_RATEMCS0) 2738c2ecf20Sopenharmony_ci rxsc = GET_PHY_STAT_P1_L_RXSC(phy_status); 2748c2ecf20Sopenharmony_ci else 2758c2ecf20Sopenharmony_ci rxsc = GET_PHY_STAT_P1_HT_RXSC(phy_status); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci if (GET_PHY_STAT_P1_RF_MODE(phy_status) == 0) 2788c2ecf20Sopenharmony_ci bw = RTW_CHANNEL_WIDTH_20; 2798c2ecf20Sopenharmony_ci else if ((rxsc == 1) || (rxsc == 2)) 2808c2ecf20Sopenharmony_ci bw = RTW_CHANNEL_WIDTH_20; 2818c2ecf20Sopenharmony_ci else 2828c2ecf20Sopenharmony_ci bw = RTW_CHANNEL_WIDTH_40; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci pkt_stat->rx_power[RF_PATH_A] = GET_PHY_STAT_P1_PWDB_A(phy_status) - 110; 2858c2ecf20Sopenharmony_ci pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1); 2868c2ecf20Sopenharmony_ci pkt_stat->bw = bw; 2878c2ecf20Sopenharmony_ci pkt_stat->signal_power = max(pkt_stat->rx_power[RF_PATH_A], 2888c2ecf20Sopenharmony_ci min_rx_power); 2898c2ecf20Sopenharmony_ci pkt_stat->rx_evm[RF_PATH_A] = GET_PHY_STAT_P1_RXEVM_A(phy_status); 2908c2ecf20Sopenharmony_ci pkt_stat->rx_snr[RF_PATH_A] = GET_PHY_STAT_P1_RXSNR_A(phy_status); 2918c2ecf20Sopenharmony_ci pkt_stat->cfo_tail[RF_PATH_A] = GET_PHY_STAT_P1_CFO_TAIL_A(phy_status); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci dm_info->curr_rx_rate = pkt_stat->rate; 2948c2ecf20Sopenharmony_ci dm_info->rssi[RF_PATH_A] = pkt_stat->rssi; 2958c2ecf20Sopenharmony_ci dm_info->rx_snr[RF_PATH_A] = pkt_stat->rx_snr[RF_PATH_A] >> 1; 2968c2ecf20Sopenharmony_ci dm_info->cfo_tail[RF_PATH_A] = (pkt_stat->cfo_tail[RF_PATH_A] * 5) >> 1; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci rx_evm = clamp_t(s8, -pkt_stat->rx_evm[RF_PATH_A] >> 1, 0, 64); 2998c2ecf20Sopenharmony_ci rx_evm &= 0x3F; /* 64->0: second path of 1SS rate is 64 */ 3008c2ecf20Sopenharmony_ci dm_info->rx_evm_dbm[RF_PATH_A] = rx_evm; 3018c2ecf20Sopenharmony_ci} 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_cistatic void query_phy_status(struct rtw_dev *rtwdev, u8 *phy_status, 3048c2ecf20Sopenharmony_ci struct rtw_rx_pkt_stat *pkt_stat) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci u8 page; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci page = *phy_status & 0xf; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci switch (page) { 3118c2ecf20Sopenharmony_ci case 0: 3128c2ecf20Sopenharmony_ci query_phy_status_page0(rtwdev, phy_status, pkt_stat); 3138c2ecf20Sopenharmony_ci break; 3148c2ecf20Sopenharmony_ci case 1: 3158c2ecf20Sopenharmony_ci query_phy_status_page1(rtwdev, phy_status, pkt_stat); 3168c2ecf20Sopenharmony_ci break; 3178c2ecf20Sopenharmony_ci default: 3188c2ecf20Sopenharmony_ci rtw_warn(rtwdev, "unused phy status page (%d)\n", page); 3198c2ecf20Sopenharmony_ci return; 3208c2ecf20Sopenharmony_ci } 3218c2ecf20Sopenharmony_ci} 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistatic void rtw8723d_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc, 3248c2ecf20Sopenharmony_ci struct rtw_rx_pkt_stat *pkt_stat, 3258c2ecf20Sopenharmony_ci struct ieee80211_rx_status *rx_status) 3268c2ecf20Sopenharmony_ci{ 3278c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr; 3288c2ecf20Sopenharmony_ci u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz; 3298c2ecf20Sopenharmony_ci u8 *phy_status = NULL; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci memset(pkt_stat, 0, sizeof(*pkt_stat)); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc); 3348c2ecf20Sopenharmony_ci pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc); 3358c2ecf20Sopenharmony_ci pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc); 3368c2ecf20Sopenharmony_ci pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc) && 3378c2ecf20Sopenharmony_ci GET_RX_DESC_ENC_TYPE(rx_desc) != RX_DESC_ENC_NONE; 3388c2ecf20Sopenharmony_ci pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc); 3398c2ecf20Sopenharmony_ci pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc); 3408c2ecf20Sopenharmony_ci pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc); 3418c2ecf20Sopenharmony_ci pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc); 3428c2ecf20Sopenharmony_ci pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc); 3438c2ecf20Sopenharmony_ci pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc); 3448c2ecf20Sopenharmony_ci pkt_stat->ppdu_cnt = 0; 3458c2ecf20Sopenharmony_ci pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci /* drv_info_sz is in unit of 8-bytes */ 3488c2ecf20Sopenharmony_ci pkt_stat->drv_info_sz *= 8; 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci /* c2h cmd pkt's rx/phy status is not interested */ 3518c2ecf20Sopenharmony_ci if (pkt_stat->is_c2h) 3528c2ecf20Sopenharmony_ci return; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift + 3558c2ecf20Sopenharmony_ci pkt_stat->drv_info_sz); 3568c2ecf20Sopenharmony_ci if (pkt_stat->phy_status) { 3578c2ecf20Sopenharmony_ci phy_status = rx_desc + desc_sz + pkt_stat->shift; 3588c2ecf20Sopenharmony_ci query_phy_status(rtwdev, phy_status, pkt_stat); 3598c2ecf20Sopenharmony_ci } 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status); 3628c2ecf20Sopenharmony_ci} 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_cistatic bool rtw8723d_check_spur_ov_thres(struct rtw_dev *rtwdev, 3658c2ecf20Sopenharmony_ci u8 channel, u32 thres) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci u32 freq; 3688c2ecf20Sopenharmony_ci bool ret = false; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci if (channel == 13) 3718c2ecf20Sopenharmony_ci freq = FREQ_CH13; 3728c2ecf20Sopenharmony_ci else if (channel == 14) 3738c2ecf20Sopenharmony_ci freq = FREQ_CH14; 3748c2ecf20Sopenharmony_ci else 3758c2ecf20Sopenharmony_ci return false; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_ANALOG_P4, DIS_3WIRE); 3788c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_PSDFN, freq); 3798c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_PSDFN, START_PSD | freq); 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci msleep(30); 3828c2ecf20Sopenharmony_ci if (rtw_read32(rtwdev, REG_PSDRPT) >= thres) 3838c2ecf20Sopenharmony_ci ret = true; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_PSDFN, freq); 3868c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_ANALOG_P4, EN_3WIRE); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci return ret; 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_cistatic void rtw8723d_cfg_notch(struct rtw_dev *rtwdev, u8 channel, bool notch) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci if (!notch) { 3948c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_MASK_RXDSP, 0x1f); 3958c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_EN_RXDSP, 0x0); 3968c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI1, 0x00000000); 3978c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI2, 0x00000000); 3988c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI3, 0x00000000); 3998c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI4, 0x00000000); 4008c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM1_CFOTRK, BIT_EN_CFOTRK, 0x0); 4018c2ecf20Sopenharmony_ci return; 4028c2ecf20Sopenharmony_ci } 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci switch (channel) { 4058c2ecf20Sopenharmony_ci case 13: 4068c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_MASK_RXDSP, 0xb); 4078c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_EN_RXDSP, 0x1); 4088c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI1, 0x04000000); 4098c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI2, 0x00000000); 4108c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI3, 0x00000000); 4118c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI4, 0x00000000); 4128c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM1_CFOTRK, BIT_EN_CFOTRK, 0x1); 4138c2ecf20Sopenharmony_ci break; 4148c2ecf20Sopenharmony_ci case 14: 4158c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_MASK_RXDSP, 0x5); 4168c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_EN_RXDSP, 0x1); 4178c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI1, 0x00000000); 4188c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI2, 0x00000000); 4198c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI3, 0x00000000); 4208c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM1_CSI4, 0x00080000); 4218c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM1_CFOTRK, BIT_EN_CFOTRK, 0x1); 4228c2ecf20Sopenharmony_ci break; 4238c2ecf20Sopenharmony_ci default: 4248c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_RXDSP, BIT_EN_RXDSP, 0x0); 4258c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM1_CFOTRK, BIT_EN_CFOTRK, 0x0); 4268c2ecf20Sopenharmony_ci break; 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci} 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_cistatic void rtw8723d_spur_cal(struct rtw_dev *rtwdev, u8 channel) 4318c2ecf20Sopenharmony_ci{ 4328c2ecf20Sopenharmony_ci bool notch; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci if (channel < 13) { 4358c2ecf20Sopenharmony_ci rtw8723d_cfg_notch(rtwdev, channel, false); 4368c2ecf20Sopenharmony_ci return; 4378c2ecf20Sopenharmony_ci } 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci notch = rtw8723d_check_spur_ov_thres(rtwdev, channel, SPUR_THRES); 4408c2ecf20Sopenharmony_ci rtw8723d_cfg_notch(rtwdev, channel, notch); 4418c2ecf20Sopenharmony_ci} 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_cistatic void rtw8723d_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw) 4448c2ecf20Sopenharmony_ci{ 4458c2ecf20Sopenharmony_ci u32 rf_cfgch_a, rf_cfgch_b; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci rf_cfgch_a = rtw_read_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK); 4488c2ecf20Sopenharmony_ci rf_cfgch_b = rtw_read_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci rf_cfgch_a &= ~RFCFGCH_CHANNEL_MASK; 4518c2ecf20Sopenharmony_ci rf_cfgch_b &= ~RFCFGCH_CHANNEL_MASK; 4528c2ecf20Sopenharmony_ci rf_cfgch_a |= (channel & RFCFGCH_CHANNEL_MASK); 4538c2ecf20Sopenharmony_ci rf_cfgch_b |= (channel & RFCFGCH_CHANNEL_MASK); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci rf_cfgch_a &= ~RFCFGCH_BW_MASK; 4568c2ecf20Sopenharmony_ci switch (bw) { 4578c2ecf20Sopenharmony_ci case RTW_CHANNEL_WIDTH_20: 4588c2ecf20Sopenharmony_ci rf_cfgch_a |= RFCFGCH_BW_20M; 4598c2ecf20Sopenharmony_ci break; 4608c2ecf20Sopenharmony_ci case RTW_CHANNEL_WIDTH_40: 4618c2ecf20Sopenharmony_ci rf_cfgch_a |= RFCFGCH_BW_40M; 4628c2ecf20Sopenharmony_ci break; 4638c2ecf20Sopenharmony_ci default: 4648c2ecf20Sopenharmony_ci break; 4658c2ecf20Sopenharmony_ci } 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_cfgch_a); 4688c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_cfgch_b); 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci rtw8723d_spur_cal(rtwdev, channel); 4718c2ecf20Sopenharmony_ci} 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_cistatic const struct rtw_backup_info cck_dfir_cfg[][CCK_DFIR_NR] = { 4748c2ecf20Sopenharmony_ci [0] = { 4758c2ecf20Sopenharmony_ci { .len = 4, .reg = 0xA24, .val = 0x64B80C1C }, 4768c2ecf20Sopenharmony_ci { .len = 4, .reg = 0xA28, .val = 0x00008810 }, 4778c2ecf20Sopenharmony_ci { .len = 4, .reg = 0xAAC, .val = 0x01235667 }, 4788c2ecf20Sopenharmony_ci }, 4798c2ecf20Sopenharmony_ci [1] = { 4808c2ecf20Sopenharmony_ci { .len = 4, .reg = 0xA24, .val = 0x0000B81C }, 4818c2ecf20Sopenharmony_ci { .len = 4, .reg = 0xA28, .val = 0x00000000 }, 4828c2ecf20Sopenharmony_ci { .len = 4, .reg = 0xAAC, .val = 0x00003667 }, 4838c2ecf20Sopenharmony_ci }, 4848c2ecf20Sopenharmony_ci}; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic void rtw8723d_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw, 4878c2ecf20Sopenharmony_ci u8 primary_ch_idx) 4888c2ecf20Sopenharmony_ci{ 4898c2ecf20Sopenharmony_ci const struct rtw_backup_info *cck_dfir; 4908c2ecf20Sopenharmony_ci int i; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci cck_dfir = channel <= 13 ? cck_dfir_cfg[0] : cck_dfir_cfg[1]; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci for (i = 0; i < CCK_DFIR_NR; i++, cck_dfir++) 4958c2ecf20Sopenharmony_ci rtw_write32(rtwdev, cck_dfir->reg, cck_dfir->val); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci switch (bw) { 4988c2ecf20Sopenharmony_ci case RTW_CHANNEL_WIDTH_20: 4998c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_RFMOD, BIT_MASK_RFMOD, 0x0); 5008c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA1_RFMOD, BIT_MASK_RFMOD, 0x0); 5018c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_BBRX_DFIR, BIT_RXBB_DFIR_EN, 1); 5028c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_BBRX_DFIR, BIT_MASK_RXBB_DFIR, 0xa); 5038c2ecf20Sopenharmony_ci break; 5048c2ecf20Sopenharmony_ci case RTW_CHANNEL_WIDTH_40: 5058c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_RFMOD, BIT_MASK_RFMOD, 0x1); 5068c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA1_RFMOD, BIT_MASK_RFMOD, 0x1); 5078c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_BBRX_DFIR, BIT_RXBB_DFIR_EN, 0); 5088c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK0_SYS, BIT_CCK_SIDE_BAND, 5098c2ecf20Sopenharmony_ci (primary_ch_idx == RTW_SC_20_UPPER ? 1 : 0)); 5108c2ecf20Sopenharmony_ci break; 5118c2ecf20Sopenharmony_ci default: 5128c2ecf20Sopenharmony_ci break; 5138c2ecf20Sopenharmony_ci } 5148c2ecf20Sopenharmony_ci} 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_cistatic void rtw8723d_set_channel(struct rtw_dev *rtwdev, u8 channel, u8 bw, 5178c2ecf20Sopenharmony_ci u8 primary_chan_idx) 5188c2ecf20Sopenharmony_ci{ 5198c2ecf20Sopenharmony_ci rtw8723d_set_channel_rf(rtwdev, channel, bw); 5208c2ecf20Sopenharmony_ci rtw_set_channel_mac(rtwdev, channel, bw, primary_chan_idx); 5218c2ecf20Sopenharmony_ci rtw8723d_set_channel_bb(rtwdev, channel, bw, primary_chan_idx); 5228c2ecf20Sopenharmony_ci} 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci#define BIT_CFENDFORM BIT(9) 5258c2ecf20Sopenharmony_ci#define BIT_WMAC_TCR_ERR0 BIT(12) 5268c2ecf20Sopenharmony_ci#define BIT_WMAC_TCR_ERR1 BIT(13) 5278c2ecf20Sopenharmony_ci#define BIT_TCR_CFG (BIT_CFENDFORM | BIT_WMAC_TCR_ERR0 | \ 5288c2ecf20Sopenharmony_ci BIT_WMAC_TCR_ERR1) 5298c2ecf20Sopenharmony_ci#define WLAN_RX_FILTER0 0xFFFF 5308c2ecf20Sopenharmony_ci#define WLAN_RX_FILTER1 0x400 5318c2ecf20Sopenharmony_ci#define WLAN_RX_FILTER2 0xFFFF 5328c2ecf20Sopenharmony_ci#define WLAN_RCR_CFG 0x700060CE 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_cistatic int rtw8723d_mac_init(struct rtw_dev *rtwdev) 5358c2ecf20Sopenharmony_ci{ 5368c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 1, WLAN_TXQ_RPT_EN); 5378c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TCR, BIT_TCR_CFG); 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_RXFLTMAP0, WLAN_RX_FILTER0); 5408c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_RXFLTMAP1, WLAN_RX_FILTER1); 5418c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_RXFLTMAP2, WLAN_RX_FILTER2); 5428c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RCR, WLAN_RCR_CFG); 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_INT_MIG, 0); 5458c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_MCUTST_1, 0x0); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_MISC_CTRL, BIT_DIS_SECOND_CCA); 5488c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_2ND_CCA_CTRL, 0); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci return 0; 5518c2ecf20Sopenharmony_ci} 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_cistatic void rtw8723d_shutdown(struct rtw_dev *rtwdev) 5548c2ecf20Sopenharmony_ci{ 5558c2ecf20Sopenharmony_ci rtw_write16_set(rtwdev, REG_HCI_OPT_CTRL, BIT_USB_SUS_DIS); 5568c2ecf20Sopenharmony_ci} 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_cistatic void rtw8723d_cfg_ldo25(struct rtw_dev *rtwdev, bool enable) 5598c2ecf20Sopenharmony_ci{ 5608c2ecf20Sopenharmony_ci u8 ldo_pwr; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci ldo_pwr = rtw_read8(rtwdev, REG_LDO_EFUSE_CTRL + 3); 5638c2ecf20Sopenharmony_ci if (enable) { 5648c2ecf20Sopenharmony_ci ldo_pwr &= ~BIT_MASK_LDO25_VOLTAGE; 5658c2ecf20Sopenharmony_ci ldo_pwr |= (BIT_LDO25_VOLTAGE_V25 << 4) | BIT_LDO25_EN; 5668c2ecf20Sopenharmony_ci } else { 5678c2ecf20Sopenharmony_ci ldo_pwr &= ~BIT_LDO25_EN; 5688c2ecf20Sopenharmony_ci } 5698c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_LDO_EFUSE_CTRL + 3, ldo_pwr); 5708c2ecf20Sopenharmony_ci} 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_cistatic void 5738c2ecf20Sopenharmony_cirtw8723d_set_tx_power_index_by_rate(struct rtw_dev *rtwdev, u8 path, u8 rs) 5748c2ecf20Sopenharmony_ci{ 5758c2ecf20Sopenharmony_ci struct rtw_hal *hal = &rtwdev->hal; 5768c2ecf20Sopenharmony_ci const struct rtw_hw_reg *txagc; 5778c2ecf20Sopenharmony_ci u8 rate, pwr_index; 5788c2ecf20Sopenharmony_ci int j; 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci for (j = 0; j < rtw_rate_size[rs]; j++) { 5818c2ecf20Sopenharmony_ci rate = rtw_rate_section[rs][j]; 5828c2ecf20Sopenharmony_ci pwr_index = hal->tx_pwr_tbl[path][rate]; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci if (rate >= ARRAY_SIZE(rtw8723d_txagc)) { 5858c2ecf20Sopenharmony_ci rtw_warn(rtwdev, "rate 0x%x isn't supported\n", rate); 5868c2ecf20Sopenharmony_ci continue; 5878c2ecf20Sopenharmony_ci } 5888c2ecf20Sopenharmony_ci txagc = &rtw8723d_txagc[rate]; 5898c2ecf20Sopenharmony_ci if (!txagc->addr) { 5908c2ecf20Sopenharmony_ci rtw_warn(rtwdev, "rate 0x%x isn't defined\n", rate); 5918c2ecf20Sopenharmony_ci continue; 5928c2ecf20Sopenharmony_ci } 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, txagc->addr, txagc->mask, pwr_index); 5958c2ecf20Sopenharmony_ci } 5968c2ecf20Sopenharmony_ci} 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_cistatic void rtw8723d_set_tx_power_index(struct rtw_dev *rtwdev) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci struct rtw_hal *hal = &rtwdev->hal; 6018c2ecf20Sopenharmony_ci int rs, path; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci for (path = 0; path < hal->rf_path_num; path++) { 6048c2ecf20Sopenharmony_ci for (rs = 0; rs <= RTW_RATE_SECTION_HT_1S; rs++) 6058c2ecf20Sopenharmony_ci rtw8723d_set_tx_power_index_by_rate(rtwdev, path, rs); 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci} 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_cistatic void rtw8723d_efuse_grant(struct rtw_dev *rtwdev, bool on) 6108c2ecf20Sopenharmony_ci{ 6118c2ecf20Sopenharmony_ci if (on) { 6128c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_EFUSE_ACCESS, EFUSE_ACCESS_ON); 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci rtw_write16_set(rtwdev, REG_SYS_FUNC_EN, BIT_FEN_ELDR); 6158c2ecf20Sopenharmony_ci rtw_write16_set(rtwdev, REG_SYS_CLKR, BIT_LOADER_CLK_EN | BIT_ANA8M); 6168c2ecf20Sopenharmony_ci } else { 6178c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_EFUSE_ACCESS, EFUSE_ACCESS_OFF); 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci} 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_cistatic void rtw8723d_false_alarm_statistics(struct rtw_dev *rtwdev) 6228c2ecf20Sopenharmony_ci{ 6238c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 6248c2ecf20Sopenharmony_ci u32 cck_fa_cnt; 6258c2ecf20Sopenharmony_ci u32 ofdm_fa_cnt; 6268c2ecf20Sopenharmony_ci u32 crc32_cnt; 6278c2ecf20Sopenharmony_ci u32 val32; 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci /* hold counter */ 6308c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_HOLDC_11N, BIT_MASK_OFDM_FA_KEEP, 1); 6318c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTD_11N, BIT_MASK_OFDM_FA_KEEP1, 1); 6328c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_FA_RST_11N, BIT_MASK_CCK_CNT_KEEP, 1); 6338c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_FA_RST_11N, BIT_MASK_CCK_FA_KEEP, 1); 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci cck_fa_cnt = rtw_read32_mask(rtwdev, REG_CCK_FA_LSB_11N, MASKBYTE0); 6368c2ecf20Sopenharmony_ci cck_fa_cnt += rtw_read32_mask(rtwdev, REG_CCK_FA_MSB_11N, MASKBYTE3) << 8; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci val32 = rtw_read32(rtwdev, REG_OFDM_FA_TYPE1_11N); 6398c2ecf20Sopenharmony_ci ofdm_fa_cnt = u32_get_bits(val32, BIT_MASK_OFDM_FF_CNT); 6408c2ecf20Sopenharmony_ci ofdm_fa_cnt += u32_get_bits(val32, BIT_MASK_OFDM_SF_CNT); 6418c2ecf20Sopenharmony_ci val32 = rtw_read32(rtwdev, REG_OFDM_FA_TYPE2_11N); 6428c2ecf20Sopenharmony_ci dm_info->ofdm_cca_cnt = u32_get_bits(val32, BIT_MASK_OFDM_CCA_CNT); 6438c2ecf20Sopenharmony_ci ofdm_fa_cnt += u32_get_bits(val32, BIT_MASK_OFDM_PF_CNT); 6448c2ecf20Sopenharmony_ci val32 = rtw_read32(rtwdev, REG_OFDM_FA_TYPE3_11N); 6458c2ecf20Sopenharmony_ci ofdm_fa_cnt += u32_get_bits(val32, BIT_MASK_OFDM_RI_CNT); 6468c2ecf20Sopenharmony_ci ofdm_fa_cnt += u32_get_bits(val32, BIT_MASK_OFDM_CRC_CNT); 6478c2ecf20Sopenharmony_ci val32 = rtw_read32(rtwdev, REG_OFDM_FA_TYPE4_11N); 6488c2ecf20Sopenharmony_ci ofdm_fa_cnt += u32_get_bits(val32, BIT_MASK_OFDM_MNS_CNT); 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci dm_info->cck_fa_cnt = cck_fa_cnt; 6518c2ecf20Sopenharmony_ci dm_info->ofdm_fa_cnt = ofdm_fa_cnt; 6528c2ecf20Sopenharmony_ci dm_info->total_fa_cnt = cck_fa_cnt + ofdm_fa_cnt; 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci dm_info->cck_err_cnt = rtw_read32(rtwdev, REG_IGI_C_11N); 6558c2ecf20Sopenharmony_ci dm_info->cck_ok_cnt = rtw_read32(rtwdev, REG_IGI_D_11N); 6568c2ecf20Sopenharmony_ci crc32_cnt = rtw_read32(rtwdev, REG_OFDM_CRC32_CNT_11N); 6578c2ecf20Sopenharmony_ci dm_info->ofdm_err_cnt = u32_get_bits(crc32_cnt, BIT_MASK_OFDM_LCRC_ERR); 6588c2ecf20Sopenharmony_ci dm_info->ofdm_ok_cnt = u32_get_bits(crc32_cnt, BIT_MASK_OFDM_LCRC_OK); 6598c2ecf20Sopenharmony_ci crc32_cnt = rtw_read32(rtwdev, REG_HT_CRC32_CNT_11N); 6608c2ecf20Sopenharmony_ci dm_info->ht_err_cnt = u32_get_bits(crc32_cnt, BIT_MASK_HT_CRC_ERR); 6618c2ecf20Sopenharmony_ci dm_info->ht_ok_cnt = u32_get_bits(crc32_cnt, BIT_MASK_HT_CRC_OK); 6628c2ecf20Sopenharmony_ci dm_info->vht_err_cnt = 0; 6638c2ecf20Sopenharmony_ci dm_info->vht_ok_cnt = 0; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci val32 = rtw_read32(rtwdev, REG_CCK_CCA_CNT_11N); 6668c2ecf20Sopenharmony_ci dm_info->cck_cca_cnt = (u32_get_bits(val32, BIT_MASK_CCK_FA_MSB) << 8) | 6678c2ecf20Sopenharmony_ci u32_get_bits(val32, BIT_MASK_CCK_FA_LSB); 6688c2ecf20Sopenharmony_ci dm_info->total_cca_cnt = dm_info->cck_cca_cnt + dm_info->ofdm_cca_cnt; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci /* reset counter */ 6718c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTC_11N, BIT_MASK_OFDM_FA_RST, 1); 6728c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTC_11N, BIT_MASK_OFDM_FA_RST, 0); 6738c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTD_11N, BIT_MASK_OFDM_FA_RST1, 1); 6748c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTD_11N, BIT_MASK_OFDM_FA_RST1, 0); 6758c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_HOLDC_11N, BIT_MASK_OFDM_FA_KEEP, 0); 6768c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_FA_RSTD_11N, BIT_MASK_OFDM_FA_KEEP1, 0); 6778c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_FA_RST_11N, BIT_MASK_CCK_CNT_KPEN, 0); 6788c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_FA_RST_11N, BIT_MASK_CCK_CNT_KPEN, 2); 6798c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_FA_RST_11N, BIT_MASK_CCK_FA_KPEN, 0); 6808c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_FA_RST_11N, BIT_MASK_CCK_FA_KPEN, 2); 6818c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_PAGE_F_RST_11N, BIT_MASK_F_RST_ALL, 1); 6828c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_PAGE_F_RST_11N, BIT_MASK_F_RST_ALL, 0); 6838c2ecf20Sopenharmony_ci} 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_cistatic const u32 iqk_adda_regs[] = { 6868c2ecf20Sopenharmony_ci 0x85c, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, 0xe88, 0xe8c, 6878c2ecf20Sopenharmony_ci 0xed0, 0xed4, 0xed8, 0xedc, 0xee0, 0xeec 6888c2ecf20Sopenharmony_ci}; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_cistatic const u32 iqk_mac8_regs[] = {0x522, 0x550, 0x551}; 6918c2ecf20Sopenharmony_cistatic const u32 iqk_mac32_regs[] = {0x40}; 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_cistatic const u32 iqk_bb_regs[] = { 6948c2ecf20Sopenharmony_ci 0xc04, 0xc08, 0x874, 0xb68, 0xb6c, 0x870, 0x860, 0x864, 0xa04 6958c2ecf20Sopenharmony_ci}; 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci#define IQK_ADDA_REG_NUM ARRAY_SIZE(iqk_adda_regs) 6988c2ecf20Sopenharmony_ci#define IQK_MAC8_REG_NUM ARRAY_SIZE(iqk_mac8_regs) 6998c2ecf20Sopenharmony_ci#define IQK_MAC32_REG_NUM ARRAY_SIZE(iqk_mac32_regs) 7008c2ecf20Sopenharmony_ci#define IQK_BB_REG_NUM ARRAY_SIZE(iqk_bb_regs) 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_cistruct iqk_backup_regs { 7038c2ecf20Sopenharmony_ci u32 adda[IQK_ADDA_REG_NUM]; 7048c2ecf20Sopenharmony_ci u8 mac8[IQK_MAC8_REG_NUM]; 7058c2ecf20Sopenharmony_ci u32 mac32[IQK_MAC32_REG_NUM]; 7068c2ecf20Sopenharmony_ci u32 bb[IQK_BB_REG_NUM]; 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci u32 lte_path; 7098c2ecf20Sopenharmony_ci u32 lte_gnt; 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci u32 bb_sel_btg; 7128c2ecf20Sopenharmony_ci u8 btg_sel; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci u8 igia; 7158c2ecf20Sopenharmony_ci u8 igib; 7168c2ecf20Sopenharmony_ci}; 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_backup_regs(struct rtw_dev *rtwdev, 7198c2ecf20Sopenharmony_ci struct iqk_backup_regs *backup) 7208c2ecf20Sopenharmony_ci{ 7218c2ecf20Sopenharmony_ci int i; 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci for (i = 0; i < IQK_ADDA_REG_NUM; i++) 7248c2ecf20Sopenharmony_ci backup->adda[i] = rtw_read32(rtwdev, iqk_adda_regs[i]); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci for (i = 0; i < IQK_MAC8_REG_NUM; i++) 7278c2ecf20Sopenharmony_ci backup->mac8[i] = rtw_read8(rtwdev, iqk_mac8_regs[i]); 7288c2ecf20Sopenharmony_ci for (i = 0; i < IQK_MAC32_REG_NUM; i++) 7298c2ecf20Sopenharmony_ci backup->mac32[i] = rtw_read32(rtwdev, iqk_mac32_regs[i]); 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci for (i = 0; i < IQK_BB_REG_NUM; i++) 7328c2ecf20Sopenharmony_ci backup->bb[i] = rtw_read32(rtwdev, iqk_bb_regs[i]); 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci backup->igia = rtw_read32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0); 7358c2ecf20Sopenharmony_ci backup->igib = rtw_read32_mask(rtwdev, REG_OFDM0_XBAGC1, MASKBYTE0); 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci backup->bb_sel_btg = rtw_read32(rtwdev, REG_BB_SEL_BTG); 7388c2ecf20Sopenharmony_ci} 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_restore_regs(struct rtw_dev *rtwdev, 7418c2ecf20Sopenharmony_ci const struct iqk_backup_regs *backup) 7428c2ecf20Sopenharmony_ci{ 7438c2ecf20Sopenharmony_ci int i; 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci for (i = 0; i < IQK_ADDA_REG_NUM; i++) 7468c2ecf20Sopenharmony_ci rtw_write32(rtwdev, iqk_adda_regs[i], backup->adda[i]); 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci for (i = 0; i < IQK_MAC8_REG_NUM; i++) 7498c2ecf20Sopenharmony_ci rtw_write8(rtwdev, iqk_mac8_regs[i], backup->mac8[i]); 7508c2ecf20Sopenharmony_ci for (i = 0; i < IQK_MAC32_REG_NUM; i++) 7518c2ecf20Sopenharmony_ci rtw_write32(rtwdev, iqk_mac32_regs[i], backup->mac32[i]); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci for (i = 0; i < IQK_BB_REG_NUM; i++) 7548c2ecf20Sopenharmony_ci rtw_write32(rtwdev, iqk_bb_regs[i], backup->bb[i]); 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, 0x50); 7578c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_XAAGC1, MASKBYTE0, backup->igia); 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_XBAGC1, MASKBYTE0, 0x50); 7608c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM0_XBAGC1, MASKBYTE0, backup->igib); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x01008c00); 7638c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x01008c00); 7648c2ecf20Sopenharmony_ci} 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_backup_path_ctrl(struct rtw_dev *rtwdev, 7678c2ecf20Sopenharmony_ci struct iqk_backup_regs *backup) 7688c2ecf20Sopenharmony_ci{ 7698c2ecf20Sopenharmony_ci backup->btg_sel = rtw_read8(rtwdev, REG_BTG_SEL); 7708c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] original 0x67 = 0x%x\n", 7718c2ecf20Sopenharmony_ci backup->btg_sel); 7728c2ecf20Sopenharmony_ci} 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_config_path_ctrl(struct rtw_dev *rtwdev) 7758c2ecf20Sopenharmony_ci{ 7768c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_PAD_CTRL1, BIT_BT_BTG_SEL, 0x1); 7778c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] set 0x67 = 0x%x\n", 7788c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_PAD_CTRL1, MASKBYTE3)); 7798c2ecf20Sopenharmony_ci} 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_restore_path_ctrl(struct rtw_dev *rtwdev, 7828c2ecf20Sopenharmony_ci const struct iqk_backup_regs *backup) 7838c2ecf20Sopenharmony_ci{ 7848c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_BTG_SEL, backup->btg_sel); 7858c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] restore 0x67 = 0x%x\n", 7868c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_PAD_CTRL1, MASKBYTE3)); 7878c2ecf20Sopenharmony_ci} 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_backup_lte_path_gnt(struct rtw_dev *rtwdev, 7908c2ecf20Sopenharmony_ci struct iqk_backup_regs *backup) 7918c2ecf20Sopenharmony_ci{ 7928c2ecf20Sopenharmony_ci backup->lte_path = rtw_read32(rtwdev, REG_LTECOEX_PATH_CONTROL); 7938c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_CTRL, 0x800f0038); 7948c2ecf20Sopenharmony_ci mdelay(1); 7958c2ecf20Sopenharmony_ci backup->lte_gnt = rtw_read32(rtwdev, REG_LTECOEX_READ_DATA); 7968c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] OriginalGNT = 0x%x\n", 7978c2ecf20Sopenharmony_ci backup->lte_gnt); 7988c2ecf20Sopenharmony_ci} 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_config_lte_path_gnt(struct rtw_dev *rtwdev) 8018c2ecf20Sopenharmony_ci{ 8028c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_WRITE_DATA, 0x0000ff00); 8038c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_CTRL, 0xc0020038); 8048c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_LTECOEX_PATH_CONTROL, BIT_LTE_MUX_CTRL_PATH, 0x1); 8058c2ecf20Sopenharmony_ci} 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_restore_lte_path_gnt(struct rtw_dev *rtwdev, 8088c2ecf20Sopenharmony_ci const struct iqk_backup_regs *bak) 8098c2ecf20Sopenharmony_ci{ 8108c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_WRITE_DATA, bak->lte_gnt); 8118c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_CTRL, 0xc00f0038); 8128c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_PATH_CONTROL, bak->lte_path); 8138c2ecf20Sopenharmony_ci} 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_cistruct rtw_8723d_iqk_cfg { 8168c2ecf20Sopenharmony_ci const char *name; 8178c2ecf20Sopenharmony_ci u32 val_bb_sel_btg; 8188c2ecf20Sopenharmony_ci u32 reg_lutwe; 8198c2ecf20Sopenharmony_ci u32 val_txiqk_pi; 8208c2ecf20Sopenharmony_ci u32 reg_padlut; 8218c2ecf20Sopenharmony_ci u32 reg_gaintx; 8228c2ecf20Sopenharmony_ci u32 reg_bspad; 8238c2ecf20Sopenharmony_ci u32 val_wlint; 8248c2ecf20Sopenharmony_ci u32 val_wlsel; 8258c2ecf20Sopenharmony_ci u32 val_iqkpts; 8268c2ecf20Sopenharmony_ci}; 8278c2ecf20Sopenharmony_ci 8288c2ecf20Sopenharmony_cistatic const struct rtw_8723d_iqk_cfg iqk_tx_cfg[PATH_NR] = { 8298c2ecf20Sopenharmony_ci [PATH_S1] = { 8308c2ecf20Sopenharmony_ci .name = "S1", 8318c2ecf20Sopenharmony_ci .val_bb_sel_btg = 0x99000000, 8328c2ecf20Sopenharmony_ci .reg_lutwe = RF_LUTWE, 8338c2ecf20Sopenharmony_ci .val_txiqk_pi = 0x8214019f, 8348c2ecf20Sopenharmony_ci .reg_padlut = RF_LUTDBG, 8358c2ecf20Sopenharmony_ci .reg_gaintx = RF_GAINTX, 8368c2ecf20Sopenharmony_ci .reg_bspad = RF_BSPAD, 8378c2ecf20Sopenharmony_ci .val_wlint = 0xe0d, 8388c2ecf20Sopenharmony_ci .val_wlsel = 0x60d, 8398c2ecf20Sopenharmony_ci .val_iqkpts = 0xfa000000, 8408c2ecf20Sopenharmony_ci }, 8418c2ecf20Sopenharmony_ci [PATH_S0] = { 8428c2ecf20Sopenharmony_ci .name = "S0", 8438c2ecf20Sopenharmony_ci .val_bb_sel_btg = 0x99000280, 8448c2ecf20Sopenharmony_ci .reg_lutwe = RF_LUTWE2, 8458c2ecf20Sopenharmony_ci .val_txiqk_pi = 0x8214018a, 8468c2ecf20Sopenharmony_ci .reg_padlut = RF_TXADBG, 8478c2ecf20Sopenharmony_ci .reg_gaintx = RF_TRXIQ, 8488c2ecf20Sopenharmony_ci .reg_bspad = RF_TXATANK, 8498c2ecf20Sopenharmony_ci .val_wlint = 0xe6d, 8508c2ecf20Sopenharmony_ci .val_wlsel = 0x66d, 8518c2ecf20Sopenharmony_ci .val_iqkpts = 0xf9000000, 8528c2ecf20Sopenharmony_ci }, 8538c2ecf20Sopenharmony_ci}; 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_cistatic u8 rtw8723d_iqk_check_tx_failed(struct rtw_dev *rtwdev, 8568c2ecf20Sopenharmony_ci const struct rtw_8723d_iqk_cfg *iqk_cfg) 8578c2ecf20Sopenharmony_ci{ 8588c2ecf20Sopenharmony_ci s32 tx_x, tx_y; 8598c2ecf20Sopenharmony_ci u32 tx_fail; 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xeac = 0x%x\n", 8628c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_IQK_RES_RY)); 8638c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xe94 = 0x%x, 0xe9c = 0x%x\n", 8648c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_IQK_RES_TX), 8658c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_IQK_RES_TY)); 8668c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 8678c2ecf20Sopenharmony_ci "[IQK] 0xe90(before IQK)= 0x%x, 0xe98(afer IQK) = 0x%x\n", 8688c2ecf20Sopenharmony_ci rtw_read32(rtwdev, 0xe90), 8698c2ecf20Sopenharmony_ci rtw_read32(rtwdev, 0xe98)); 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci tx_fail = rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_IQK_TX_FAIL); 8728c2ecf20Sopenharmony_ci tx_x = rtw_read32_mask(rtwdev, REG_IQK_RES_TX, BIT_MASK_RES_TX); 8738c2ecf20Sopenharmony_ci tx_y = rtw_read32_mask(rtwdev, REG_IQK_RES_TY, BIT_MASK_RES_TY); 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_ci if (!tx_fail && tx_x != IQK_TX_X_ERR && tx_y != IQK_TX_Y_ERR) 8768c2ecf20Sopenharmony_ci return IQK_TX_OK; 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] %s TXIQK is failed\n", 8798c2ecf20Sopenharmony_ci iqk_cfg->name); 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ci return 0; 8828c2ecf20Sopenharmony_ci} 8838c2ecf20Sopenharmony_ci 8848c2ecf20Sopenharmony_cistatic u8 rtw8723d_iqk_check_rx_failed(struct rtw_dev *rtwdev, 8858c2ecf20Sopenharmony_ci const struct rtw_8723d_iqk_cfg *iqk_cfg) 8868c2ecf20Sopenharmony_ci{ 8878c2ecf20Sopenharmony_ci s32 rx_x, rx_y; 8888c2ecf20Sopenharmony_ci u32 rx_fail; 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xea4 = 0x%x, 0xeac = 0x%x\n", 8918c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_IQK_RES_RX), 8928c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_IQK_RES_RY)); 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 8958c2ecf20Sopenharmony_ci "[IQK] 0xea0(before IQK)= 0x%x, 0xea8(afer IQK) = 0x%x\n", 8968c2ecf20Sopenharmony_ci rtw_read32(rtwdev, 0xea0), 8978c2ecf20Sopenharmony_ci rtw_read32(rtwdev, 0xea8)); 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci rx_fail = rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_IQK_RX_FAIL); 9008c2ecf20Sopenharmony_ci rx_x = rtw_read32_mask(rtwdev, REG_IQK_RES_RX, BIT_MASK_RES_RX); 9018c2ecf20Sopenharmony_ci rx_y = rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_MASK_RES_RY); 9028c2ecf20Sopenharmony_ci rx_y = abs(iqkxy_to_s32(rx_y)); 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci if (!rx_fail && rx_x < IQK_RX_X_UPPER && rx_x > IQK_RX_X_LOWER && 9058c2ecf20Sopenharmony_ci rx_y < IQK_RX_Y_LMT) 9068c2ecf20Sopenharmony_ci return IQK_RX_OK; 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] %s RXIQK STEP2 is failed\n", 9098c2ecf20Sopenharmony_ci iqk_cfg->name); 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci return 0; 9128c2ecf20Sopenharmony_ci} 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_one_shot(struct rtw_dev *rtwdev, bool tx, 9158c2ecf20Sopenharmony_ci const struct rtw_8723d_iqk_cfg *iqk_cfg) 9168c2ecf20Sopenharmony_ci{ 9178c2ecf20Sopenharmony_ci u32 pts = (tx ? iqk_cfg->val_iqkpts : 0xf9000000); 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci /* enter IQK mode */ 9208c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, EN_IQK); 9218c2ecf20Sopenharmony_ci rtw8723d_iqk_config_lte_path_gnt(rtwdev); 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_LTECOEX_CTRL, 0x800f0054); 9248c2ecf20Sopenharmony_ci mdelay(1); 9258c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] GNT_BT @%s %sIQK1 = 0x%x\n", 9268c2ecf20Sopenharmony_ci iqk_cfg->name, tx ? "TX" : "RX", 9278c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_LTECOEX_READ_DATA)); 9288c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0x948 @%s %sIQK1 = 0x%x\n", 9298c2ecf20Sopenharmony_ci iqk_cfg->name, tx ? "TX" : "RX", 9308c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_BB_SEL_BTG)); 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_ci /* One shot, LOK & IQK */ 9338c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, pts); 9348c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_IQK_AGC_PTS_11N, 0xf8000000); 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci if (!check_hw_ready(rtwdev, REG_IQK_RES_RY, BIT_IQK_DONE, 1)) 9378c2ecf20Sopenharmony_ci rtw_warn(rtwdev, "%s %s IQK isn't done\n", iqk_cfg->name, 9388c2ecf20Sopenharmony_ci tx ? "TX" : "RX"); 9398c2ecf20Sopenharmony_ci} 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_txrx_path_post(struct rtw_dev *rtwdev, 9428c2ecf20Sopenharmony_ci const struct rtw_8723d_iqk_cfg *iqk_cfg, 9438c2ecf20Sopenharmony_ci const struct iqk_backup_regs *backup) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci rtw8723d_iqk_restore_lte_path_gnt(rtwdev, backup); 9468c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BB_SEL_BTG, backup->bb_sel_btg); 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci /* leave IQK mode */ 9498c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, RST_IQK); 9508c2ecf20Sopenharmony_ci mdelay(1); 9518c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_padlut, 0x800, 0x0); 9528c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_WLINT, BIT(0), 0x0); 9538c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_WLSEL, BIT(0), 0x0); 9548c2ecf20Sopenharmony_ci} 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_cistatic u8 rtw8723d_iqk_tx_path(struct rtw_dev *rtwdev, 9578c2ecf20Sopenharmony_ci const struct rtw_8723d_iqk_cfg *iqk_cfg, 9588c2ecf20Sopenharmony_ci const struct iqk_backup_regs *backup) 9598c2ecf20Sopenharmony_ci{ 9608c2ecf20Sopenharmony_ci u8 status; 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path %s TXIQK!!\n", iqk_cfg->name); 9638c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0x67 @%s TXIQK = 0x%x\n", 9648c2ecf20Sopenharmony_ci iqk_cfg->name, 9658c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_PAD_CTRL1, MASKBYTE3)); 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BB_SEL_BTG, iqk_cfg->val_bb_sel_btg); 9688c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, RST_IQK); 9698c2ecf20Sopenharmony_ci mdelay(1); 9708c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, RFREG_MASK, 0x80000); 9718c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, RFREG_MASK, 0x00004); 9728c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD1, RFREG_MASK, 0x0005d); 9738c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, RFREG_MASK, 0xBFFE0); 9748c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, RFREG_MASK, 0x00000); 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci /* IQK setting */ 9778c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x08008c0c); 9788c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x38008c1c); 9798c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_PI_A_11N, iqk_cfg->val_txiqk_pi); 9808c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_PI_A_11N, 0x28160200); 9818c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_11N, 0x01007c00); 9828c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci /* LOK setting */ 9858c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_IQK_AGC_RSP_11N, 0x00462911); 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci /* PA, PAD setting */ 9888c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_padlut, 0x800, 0x1); 9898c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_gaintx, 0x600, 0x0); 9908c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_gaintx, 0x1E0, 0x3); 9918c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_RXIQGEN, 0x1F, 0xf); 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_ci /* LOK setting for 8723D */ 9948c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, 0x10, 0x1); 9958c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_bspad, 0x1, 0x1); 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK, iqk_cfg->val_wlint); 9988c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_WLSEL, RFREG_MASK, iqk_cfg->val_wlsel); 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] RF0x1 @%s TXIQK = 0x%x\n", 10018c2ecf20Sopenharmony_ci iqk_cfg->name, 10028c2ecf20Sopenharmony_ci rtw_read_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK)); 10038c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] RF0x2 @%s TXIQK = 0x%x\n", 10048c2ecf20Sopenharmony_ci iqk_cfg->name, 10058c2ecf20Sopenharmony_ci rtw_read_rf(rtwdev, RF_PATH_A, RF_WLSEL, RFREG_MASK)); 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci rtw8723d_iqk_one_shot(rtwdev, true, iqk_cfg); 10088c2ecf20Sopenharmony_ci status = rtw8723d_iqk_check_tx_failed(rtwdev, iqk_cfg); 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci rtw8723d_iqk_txrx_path_post(rtwdev, iqk_cfg, backup); 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci return status; 10138c2ecf20Sopenharmony_ci} 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_cistatic u8 rtw8723d_iqk_rx_path(struct rtw_dev *rtwdev, 10168c2ecf20Sopenharmony_ci const struct rtw_8723d_iqk_cfg *iqk_cfg, 10178c2ecf20Sopenharmony_ci const struct iqk_backup_regs *backup) 10188c2ecf20Sopenharmony_ci{ 10198c2ecf20Sopenharmony_ci u32 tx_x, tx_y; 10208c2ecf20Sopenharmony_ci u8 status; 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path %s RXIQK Step1!!\n", 10238c2ecf20Sopenharmony_ci iqk_cfg->name); 10248c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0x67 @%s RXIQK1 = 0x%x\n", 10258c2ecf20Sopenharmony_ci iqk_cfg->name, 10268c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_PAD_CTRL1, MASKBYTE3)); 10278c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BB_SEL_BTG, iqk_cfg->val_bb_sel_btg); 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, RST_IQK); 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci /* IQK setting */ 10328c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_11N, 0x01007c00); 10338c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci /* path IQK setting */ 10368c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x18008c1c); 10378c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x38008c1c); 10388c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TX_IQK_TONE_B, 0x38008c1c); 10398c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RX_IQK_TONE_B, 0x38008c1c); 10408c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_PI_A_11N, 0x82160000); 10418c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_PI_A_11N, 0x28160000); 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci /* LOK setting */ 10448c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_IQK_AGC_RSP_11N, 0x0046a911); 10458c2ecf20Sopenharmony_ci 10468c2ecf20Sopenharmony_ci /* RXIQK mode */ 10478c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, RFREG_MASK, 0x80000); 10488c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, RFREG_MASK, 0x00006); 10498c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD1, RFREG_MASK, 0x0005f); 10508c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, RFREG_MASK, 0xa7ffb); 10518c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, RFREG_MASK, 0x00000); 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci /* PA/PAD=0 */ 10548c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_padlut, 0x800, 0x1); 10558c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_gaintx, 0x600, 0x0); 10568c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK, iqk_cfg->val_wlint); 10578c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_WLSEL, RFREG_MASK, iqk_cfg->val_wlsel); 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] RF0x1@ path %s RXIQK1 = 0x%x\n", 10608c2ecf20Sopenharmony_ci iqk_cfg->name, 10618c2ecf20Sopenharmony_ci rtw_read_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK)); 10628c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] RF0x2@ path %s RXIQK1 = 0x%x\n", 10638c2ecf20Sopenharmony_ci iqk_cfg->name, 10648c2ecf20Sopenharmony_ci rtw_read_rf(rtwdev, RF_PATH_A, RF_WLSEL, RFREG_MASK)); 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_ci rtw8723d_iqk_one_shot(rtwdev, false, iqk_cfg); 10678c2ecf20Sopenharmony_ci status = rtw8723d_iqk_check_tx_failed(rtwdev, iqk_cfg); 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci if (!status) 10708c2ecf20Sopenharmony_ci goto restore; 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci /* second round */ 10738c2ecf20Sopenharmony_ci tx_x = rtw_read32_mask(rtwdev, REG_IQK_RES_TX, BIT_MASK_RES_TX); 10748c2ecf20Sopenharmony_ci tx_y = rtw_read32_mask(rtwdev, REG_IQK_RES_TY, BIT_MASK_RES_TY); 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_11N, BIT_SET_TXIQK_11N(tx_x, tx_y)); 10778c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0xe40 = 0x%x u4tmp = 0x%x\n", 10788c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_TXIQK_11N), 10798c2ecf20Sopenharmony_ci BIT_SET_TXIQK_11N(tx_x, tx_y)); 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path %s RXIQK STEP2!!\n", 10828c2ecf20Sopenharmony_ci iqk_cfg->name); 10838c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] 0x67 @%s RXIQK2 = 0x%x\n", 10848c2ecf20Sopenharmony_ci iqk_cfg->name, 10858c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_PAD_CTRL1, MASKBYTE3)); 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); 10888c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_TONE_A_11N, 0x38008c1c); 10898c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_TONE_A_11N, 0x18008c1c); 10908c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TX_IQK_TONE_B, 0x38008c1c); 10918c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RX_IQK_TONE_B, 0x38008c1c); 10928c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_PI_A_11N, 0x82170000); 10938c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_PI_A_11N, 0x28171400); 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci /* LOK setting */ 10968c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_IQK_AGC_RSP_11N, 0x0046a8d1); 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci /* RXIQK mode */ 10998c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, RST_IQK); 11008c2ecf20Sopenharmony_ci mdelay(1); 11018c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, 0x80000, 0x1); 11028c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, RFREG_MASK, 0x00007); 11038c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD1, RFREG_MASK, 0x0005f); 11048c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, RFREG_MASK, 0xb3fdb); 11058c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, iqk_cfg->reg_lutwe, RFREG_MASK, 0x00000); 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] RF0x1 @%s RXIQK2 = 0x%x\n", 11088c2ecf20Sopenharmony_ci iqk_cfg->name, 11098c2ecf20Sopenharmony_ci rtw_read_rf(rtwdev, RF_PATH_A, RF_WLINT, RFREG_MASK)); 11108c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] RF0x2 @%s RXIQK2 = 0x%x\n", 11118c2ecf20Sopenharmony_ci iqk_cfg->name, 11128c2ecf20Sopenharmony_ci rtw_read_rf(rtwdev, RF_PATH_A, RF_WLSEL, RFREG_MASK)); 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci rtw8723d_iqk_one_shot(rtwdev, false, iqk_cfg); 11158c2ecf20Sopenharmony_ci status |= rtw8723d_iqk_check_rx_failed(rtwdev, iqk_cfg); 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_cirestore: 11188c2ecf20Sopenharmony_ci rtw8723d_iqk_txrx_path_post(rtwdev, iqk_cfg, backup); 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci return status; 11218c2ecf20Sopenharmony_ci} 11228c2ecf20Sopenharmony_ci 11238c2ecf20Sopenharmony_cistatic 11248c2ecf20Sopenharmony_civoid rtw8723d_iqk_fill_s1_matrix(struct rtw_dev *rtwdev, const s32 result[]) 11258c2ecf20Sopenharmony_ci{ 11268c2ecf20Sopenharmony_ci s32 oldval_1; 11278c2ecf20Sopenharmony_ci s32 x, y; 11288c2ecf20Sopenharmony_ci s32 tx1_a, tx1_a_ext; 11298c2ecf20Sopenharmony_ci s32 tx1_c, tx1_c_ext; 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci if (result[IQK_S1_TX_X] == 0) 11328c2ecf20Sopenharmony_ci return; 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci oldval_1 = rtw_read32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 11358c2ecf20Sopenharmony_ci BIT_MASK_TXIQ_ELM_D); 11368c2ecf20Sopenharmony_ci 11378c2ecf20Sopenharmony_ci x = iqkxy_to_s32(result[IQK_S1_TX_X]); 11388c2ecf20Sopenharmony_ci tx1_a = iqk_mult(x, oldval_1, &tx1_a_ext); 11398c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 11408c2ecf20Sopenharmony_ci BIT_MASK_TXIQ_ELM_A, tx1_a); 11418c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, 11428c2ecf20Sopenharmony_ci BIT_MASK_OFDM0_EXT_A, tx1_a_ext); 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci y = iqkxy_to_s32(result[IQK_S1_TX_Y]); 11458c2ecf20Sopenharmony_ci tx1_c = iqk_mult(y, oldval_1, &tx1_c_ext); 11468c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N, MASKH4BITS, 11478c2ecf20Sopenharmony_ci BIT_SET_TXIQ_ELM_C1(tx1_c)); 11488c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 11498c2ecf20Sopenharmony_ci BIT_MASK_TXIQ_ELM_C, BIT_SET_TXIQ_ELM_C2(tx1_c)); 11508c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, 11518c2ecf20Sopenharmony_ci BIT_MASK_OFDM0_EXT_C, tx1_c_ext); 11528c2ecf20Sopenharmony_ci 11538c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 11548c2ecf20Sopenharmony_ci "[IQK] X = 0x%x, TX1_A = 0x%x, oldval_1 0x%x\n", 11558c2ecf20Sopenharmony_ci x, tx1_a, oldval_1); 11568c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 11578c2ecf20Sopenharmony_ci "[IQK] Y = 0x%x, TX1_C = 0x%x\n", y, tx1_c); 11588c2ecf20Sopenharmony_ci 11598c2ecf20Sopenharmony_ci if (result[IQK_S1_RX_X] == 0) 11608c2ecf20Sopenharmony_ci return; 11618c2ecf20Sopenharmony_ci 11628c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_A_RXIQI, BIT_MASK_RXIQ_S1_X, 11638c2ecf20Sopenharmony_ci result[IQK_S1_RX_X]); 11648c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_A_RXIQI, BIT_MASK_RXIQ_S1_Y1, 11658c2ecf20Sopenharmony_ci BIT_SET_RXIQ_S1_Y1(result[IQK_S1_RX_Y])); 11668c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_RXIQK_MATRIX_LSB_11N, BIT_MASK_RXIQ_S1_Y2, 11678c2ecf20Sopenharmony_ci BIT_SET_RXIQ_S1_Y2(result[IQK_S1_RX_Y])); 11688c2ecf20Sopenharmony_ci} 11698c2ecf20Sopenharmony_ci 11708c2ecf20Sopenharmony_cistatic 11718c2ecf20Sopenharmony_civoid rtw8723d_iqk_fill_s0_matrix(struct rtw_dev *rtwdev, const s32 result[]) 11728c2ecf20Sopenharmony_ci{ 11738c2ecf20Sopenharmony_ci s32 oldval_0; 11748c2ecf20Sopenharmony_ci s32 x, y; 11758c2ecf20Sopenharmony_ci s32 tx0_a, tx0_a_ext; 11768c2ecf20Sopenharmony_ci s32 tx0_c, tx0_c_ext; 11778c2ecf20Sopenharmony_ci 11788c2ecf20Sopenharmony_ci if (result[IQK_S0_TX_X] == 0) 11798c2ecf20Sopenharmony_ci return; 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ci oldval_0 = rtw_read32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_D_S0); 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci x = iqkxy_to_s32(result[IQK_S0_TX_X]); 11848c2ecf20Sopenharmony_ci tx0_a = iqk_mult(x, oldval_0, &tx0_a_ext); 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_A_S0, tx0_a); 11878c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_A_EXT_S0, tx0_a_ext); 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci y = iqkxy_to_s32(result[IQK_S0_TX_Y]); 11908c2ecf20Sopenharmony_ci tx0_c = iqk_mult(y, oldval_0, &tx0_c_ext); 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_C_S0, tx0_c); 11938c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_C_EXT_S0, tx0_c_ext); 11948c2ecf20Sopenharmony_ci 11958c2ecf20Sopenharmony_ci if (result[IQK_S0_RX_X] == 0) 11968c2ecf20Sopenharmony_ci return; 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_RXIQ_AB_S0, BIT_MASK_RXIQ_X_S0, 11998c2ecf20Sopenharmony_ci result[IQK_S0_RX_X]); 12008c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_RXIQ_AB_S0, BIT_MASK_RXIQ_Y_S0, 12018c2ecf20Sopenharmony_ci result[IQK_S0_RX_Y]); 12028c2ecf20Sopenharmony_ci} 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_path_adda_on(struct rtw_dev *rtwdev) 12058c2ecf20Sopenharmony_ci{ 12068c2ecf20Sopenharmony_ci int i; 12078c2ecf20Sopenharmony_ci 12088c2ecf20Sopenharmony_ci for (i = 0; i < IQK_ADDA_REG_NUM; i++) 12098c2ecf20Sopenharmony_ci rtw_write32(rtwdev, iqk_adda_regs[i], 0x03c00016); 12108c2ecf20Sopenharmony_ci} 12118c2ecf20Sopenharmony_ci 12128c2ecf20Sopenharmony_cistatic void rtw8723d_iqk_config_mac(struct rtw_dev *rtwdev) 12138c2ecf20Sopenharmony_ci{ 12148c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_TXPAUSE, 0xff); 12158c2ecf20Sopenharmony_ci} 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_cistatic 12188c2ecf20Sopenharmony_civoid rtw8723d_iqk_rf_standby(struct rtw_dev *rtwdev, enum rtw_rf_path path) 12198c2ecf20Sopenharmony_ci{ 12208c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path-%s standby mode!\n", 12218c2ecf20Sopenharmony_ci path == RF_PATH_A ? "S1" : "S0"); 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, RST_IQK); 12248c2ecf20Sopenharmony_ci mdelay(1); 12258c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, path, RF_MODE, RFREG_MASK, 0x10000); 12268c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, EN_IQK); 12278c2ecf20Sopenharmony_ci} 12288c2ecf20Sopenharmony_ci 12298c2ecf20Sopenharmony_cistatic 12308c2ecf20Sopenharmony_cibool rtw8723d_iqk_similarity_cmp(struct rtw_dev *rtwdev, s32 result[][IQK_NR], 12318c2ecf20Sopenharmony_ci u8 c1, u8 c2) 12328c2ecf20Sopenharmony_ci{ 12338c2ecf20Sopenharmony_ci u32 i, j, diff; 12348c2ecf20Sopenharmony_ci u32 bitmap = 0; 12358c2ecf20Sopenharmony_ci u8 candidate[PATH_NR] = {IQK_ROUND_INVALID, IQK_ROUND_INVALID}; 12368c2ecf20Sopenharmony_ci bool ret = true; 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci s32 tmp1, tmp2; 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci for (i = 0; i < IQK_NR; i++) { 12418c2ecf20Sopenharmony_ci tmp1 = iqkxy_to_s32(result[c1][i]); 12428c2ecf20Sopenharmony_ci tmp2 = iqkxy_to_s32(result[c2][i]); 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_ci diff = abs(tmp1 - tmp2); 12458c2ecf20Sopenharmony_ci 12468c2ecf20Sopenharmony_ci if (diff <= MAX_TOLERANCE) 12478c2ecf20Sopenharmony_ci continue; 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci if ((i == IQK_S1_RX_X || i == IQK_S0_RX_X) && !bitmap) { 12508c2ecf20Sopenharmony_ci if (result[c1][i] + result[c1][i + 1] == 0) 12518c2ecf20Sopenharmony_ci candidate[i / IQK_SX_NR] = c2; 12528c2ecf20Sopenharmony_ci else if (result[c2][i] + result[c2][i + 1] == 0) 12538c2ecf20Sopenharmony_ci candidate[i / IQK_SX_NR] = c1; 12548c2ecf20Sopenharmony_ci else 12558c2ecf20Sopenharmony_ci bitmap |= BIT(i); 12568c2ecf20Sopenharmony_ci } else { 12578c2ecf20Sopenharmony_ci bitmap |= BIT(i); 12588c2ecf20Sopenharmony_ci } 12598c2ecf20Sopenharmony_ci } 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci if (bitmap != 0) 12628c2ecf20Sopenharmony_ci goto check_sim; 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci for (i = 0; i < PATH_NR; i++) { 12658c2ecf20Sopenharmony_ci if (candidate[i] == IQK_ROUND_INVALID) 12668c2ecf20Sopenharmony_ci continue; 12678c2ecf20Sopenharmony_ci 12688c2ecf20Sopenharmony_ci for (j = i * IQK_SX_NR; j < i * IQK_SX_NR + 2; j++) 12698c2ecf20Sopenharmony_ci result[IQK_ROUND_HYBRID][j] = result[candidate[i]][j]; 12708c2ecf20Sopenharmony_ci ret = false; 12718c2ecf20Sopenharmony_ci } 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci return ret; 12748c2ecf20Sopenharmony_ci 12758c2ecf20Sopenharmony_cicheck_sim: 12768c2ecf20Sopenharmony_ci for (i = 0; i < IQK_NR; i++) { 12778c2ecf20Sopenharmony_ci j = i & ~1; /* 2 bits are a pair for IQ[X, Y] */ 12788c2ecf20Sopenharmony_ci if (bitmap & GENMASK(j + 1, j)) 12798c2ecf20Sopenharmony_ci continue; 12808c2ecf20Sopenharmony_ci 12818c2ecf20Sopenharmony_ci result[IQK_ROUND_HYBRID][i] = result[c1][i]; 12828c2ecf20Sopenharmony_ci } 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci return false; 12858c2ecf20Sopenharmony_ci} 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_cistatic 12888c2ecf20Sopenharmony_civoid rtw8723d_iqk_precfg_path(struct rtw_dev *rtwdev, enum rtw8723d_path path) 12898c2ecf20Sopenharmony_ci{ 12908c2ecf20Sopenharmony_ci if (path == PATH_S0) { 12918c2ecf20Sopenharmony_ci rtw8723d_iqk_rf_standby(rtwdev, RF_PATH_A); 12928c2ecf20Sopenharmony_ci rtw8723d_iqk_path_adda_on(rtwdev); 12938c2ecf20Sopenharmony_ci } 12948c2ecf20Sopenharmony_ci 12958c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, EN_IQK); 12968c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TXIQK_11N, 0x01007c00); 12978c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_RXIQK_11N, 0x01004800); 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_ci if (path == PATH_S1) { 13008c2ecf20Sopenharmony_ci rtw8723d_iqk_rf_standby(rtwdev, RF_PATH_B); 13018c2ecf20Sopenharmony_ci rtw8723d_iqk_path_adda_on(rtwdev); 13028c2ecf20Sopenharmony_ci } 13038c2ecf20Sopenharmony_ci} 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_cistatic 13068c2ecf20Sopenharmony_civoid rtw8723d_iqk_one_round(struct rtw_dev *rtwdev, s32 result[][IQK_NR], u8 t, 13078c2ecf20Sopenharmony_ci const struct iqk_backup_regs *backup) 13088c2ecf20Sopenharmony_ci{ 13098c2ecf20Sopenharmony_ci u32 i; 13108c2ecf20Sopenharmony_ci u8 s1_ok, s0_ok; 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 13138c2ecf20Sopenharmony_ci "[IQK] IQ Calibration for 1T1R_S0/S1 for %d times\n", t); 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci rtw8723d_iqk_path_adda_on(rtwdev); 13168c2ecf20Sopenharmony_ci rtw8723d_iqk_config_mac(rtwdev); 13178c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_CCK_ANT_SEL_11N, 0x0f000000, 0xf); 13188c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BB_RX_PATH_11N, 0x03a05611); 13198c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_TRMUX_11N, 0x000800e4); 13208c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BB_PWR_SAV1_11N, 0x25204200); 13218c2ecf20Sopenharmony_ci rtw8723d_iqk_precfg_path(rtwdev, PATH_S1); 13228c2ecf20Sopenharmony_ci 13238c2ecf20Sopenharmony_ci for (i = 0; i < PATH_IQK_RETRY; i++) { 13248c2ecf20Sopenharmony_ci s1_ok = rtw8723d_iqk_tx_path(rtwdev, &iqk_tx_cfg[PATH_S1], backup); 13258c2ecf20Sopenharmony_ci if (s1_ok == IQK_TX_OK) { 13268c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 13278c2ecf20Sopenharmony_ci "[IQK] path S1 Tx IQK Success!!\n"); 13288c2ecf20Sopenharmony_ci result[t][IQK_S1_TX_X] = 13298c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_TX, BIT_MASK_RES_TX); 13308c2ecf20Sopenharmony_ci result[t][IQK_S1_TX_Y] = 13318c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_TY, BIT_MASK_RES_TY); 13328c2ecf20Sopenharmony_ci break; 13338c2ecf20Sopenharmony_ci } 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path S1 Tx IQK Fail!!\n"); 13368c2ecf20Sopenharmony_ci result[t][IQK_S1_TX_X] = 0x100; 13378c2ecf20Sopenharmony_ci result[t][IQK_S1_TX_Y] = 0x0; 13388c2ecf20Sopenharmony_ci } 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci for (i = 0; i < PATH_IQK_RETRY; i++) { 13418c2ecf20Sopenharmony_ci s1_ok = rtw8723d_iqk_rx_path(rtwdev, &iqk_tx_cfg[PATH_S1], backup); 13428c2ecf20Sopenharmony_ci if (s1_ok == (IQK_TX_OK | IQK_RX_OK)) { 13438c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 13448c2ecf20Sopenharmony_ci "[IQK] path S1 Rx IQK Success!!\n"); 13458c2ecf20Sopenharmony_ci result[t][IQK_S1_RX_X] = 13468c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_RX, BIT_MASK_RES_RX); 13478c2ecf20Sopenharmony_ci result[t][IQK_S1_RX_Y] = 13488c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_MASK_RES_RY); 13498c2ecf20Sopenharmony_ci break; 13508c2ecf20Sopenharmony_ci } 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path S1 Rx IQK Fail!!\n"); 13538c2ecf20Sopenharmony_ci result[t][IQK_S1_RX_X] = 0x100; 13548c2ecf20Sopenharmony_ci result[t][IQK_S1_RX_Y] = 0x0; 13558c2ecf20Sopenharmony_ci } 13568c2ecf20Sopenharmony_ci 13578c2ecf20Sopenharmony_ci if (s1_ok == 0x0) 13588c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path S1 IQK is failed!!\n"); 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_ci rtw8723d_iqk_precfg_path(rtwdev, PATH_S0); 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_ci for (i = 0; i < PATH_IQK_RETRY; i++) { 13638c2ecf20Sopenharmony_ci s0_ok = rtw8723d_iqk_tx_path(rtwdev, &iqk_tx_cfg[PATH_S0], backup); 13648c2ecf20Sopenharmony_ci if (s0_ok == IQK_TX_OK) { 13658c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 13668c2ecf20Sopenharmony_ci "[IQK] path S0 Tx IQK Success!!\n"); 13678c2ecf20Sopenharmony_ci result[t][IQK_S0_TX_X] = 13688c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_TX, BIT_MASK_RES_TX); 13698c2ecf20Sopenharmony_ci result[t][IQK_S0_TX_Y] = 13708c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_TY, BIT_MASK_RES_TY); 13718c2ecf20Sopenharmony_ci break; 13728c2ecf20Sopenharmony_ci } 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path S0 Tx IQK Fail!!\n"); 13758c2ecf20Sopenharmony_ci result[t][IQK_S0_TX_X] = 0x100; 13768c2ecf20Sopenharmony_ci result[t][IQK_S0_TX_Y] = 0x0; 13778c2ecf20Sopenharmony_ci } 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_ci for (i = 0; i < PATH_IQK_RETRY; i++) { 13808c2ecf20Sopenharmony_ci s0_ok = rtw8723d_iqk_rx_path(rtwdev, &iqk_tx_cfg[PATH_S0], backup); 13818c2ecf20Sopenharmony_ci if (s0_ok == (IQK_TX_OK | IQK_RX_OK)) { 13828c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 13838c2ecf20Sopenharmony_ci "[IQK] path S0 Rx IQK Success!!\n"); 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci result[t][IQK_S0_RX_X] = 13868c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_RX, BIT_MASK_RES_RX); 13878c2ecf20Sopenharmony_ci result[t][IQK_S0_RX_Y] = 13888c2ecf20Sopenharmony_ci rtw_read32_mask(rtwdev, REG_IQK_RES_RY, BIT_MASK_RES_RY); 13898c2ecf20Sopenharmony_ci break; 13908c2ecf20Sopenharmony_ci } 13918c2ecf20Sopenharmony_ci 13928c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path S0 Rx IQK Fail!!\n"); 13938c2ecf20Sopenharmony_ci result[t][IQK_S0_RX_X] = 0x100; 13948c2ecf20Sopenharmony_ci result[t][IQK_S0_RX_Y] = 0x0; 13958c2ecf20Sopenharmony_ci } 13968c2ecf20Sopenharmony_ci 13978c2ecf20Sopenharmony_ci if (s0_ok == 0x0) 13988c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] path S0 IQK is failed!!\n"); 13998c2ecf20Sopenharmony_ci 14008c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_FPGA0_IQK_11N, BIT_MASK_IQK_MOD, RST_IQK); 14018c2ecf20Sopenharmony_ci mdelay(1); 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 14048c2ecf20Sopenharmony_ci "[IQK] back to BB mode, load original value!\n"); 14058c2ecf20Sopenharmony_ci} 14068c2ecf20Sopenharmony_ci 14078c2ecf20Sopenharmony_cistatic void rtw8723d_phy_calibration(struct rtw_dev *rtwdev) 14088c2ecf20Sopenharmony_ci{ 14098c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 14108c2ecf20Sopenharmony_ci s32 result[IQK_ROUND_SIZE][IQK_NR]; 14118c2ecf20Sopenharmony_ci struct iqk_backup_regs backup; 14128c2ecf20Sopenharmony_ci u8 i, j; 14138c2ecf20Sopenharmony_ci u8 final_candidate = IQK_ROUND_INVALID; 14148c2ecf20Sopenharmony_ci bool good; 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] Start!!!\n"); 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci memset(result, 0, sizeof(result)); 14198c2ecf20Sopenharmony_ci 14208c2ecf20Sopenharmony_ci rtw8723d_iqk_backup_path_ctrl(rtwdev, &backup); 14218c2ecf20Sopenharmony_ci rtw8723d_iqk_backup_lte_path_gnt(rtwdev, &backup); 14228c2ecf20Sopenharmony_ci rtw8723d_iqk_backup_regs(rtwdev, &backup); 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ci for (i = IQK_ROUND_0; i <= IQK_ROUND_2; i++) { 14258c2ecf20Sopenharmony_ci rtw8723d_iqk_config_path_ctrl(rtwdev); 14268c2ecf20Sopenharmony_ci rtw8723d_iqk_config_lte_path_gnt(rtwdev); 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci rtw8723d_iqk_one_round(rtwdev, result, i, &backup); 14298c2ecf20Sopenharmony_ci 14308c2ecf20Sopenharmony_ci if (i > IQK_ROUND_0) 14318c2ecf20Sopenharmony_ci rtw8723d_iqk_restore_regs(rtwdev, &backup); 14328c2ecf20Sopenharmony_ci rtw8723d_iqk_restore_lte_path_gnt(rtwdev, &backup); 14338c2ecf20Sopenharmony_ci rtw8723d_iqk_restore_path_ctrl(rtwdev, &backup); 14348c2ecf20Sopenharmony_ci 14358c2ecf20Sopenharmony_ci for (j = IQK_ROUND_0; j < i; j++) { 14368c2ecf20Sopenharmony_ci good = rtw8723d_iqk_similarity_cmp(rtwdev, result, j, i); 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci if (good) { 14398c2ecf20Sopenharmony_ci final_candidate = j; 14408c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 14418c2ecf20Sopenharmony_ci "[IQK] cmp %d:%d final_candidate is %x\n", 14428c2ecf20Sopenharmony_ci j, i, final_candidate); 14438c2ecf20Sopenharmony_ci goto iqk_done; 14448c2ecf20Sopenharmony_ci } 14458c2ecf20Sopenharmony_ci } 14468c2ecf20Sopenharmony_ci } 14478c2ecf20Sopenharmony_ci 14488c2ecf20Sopenharmony_ci if (final_candidate == IQK_ROUND_INVALID) { 14498c2ecf20Sopenharmony_ci s32 reg_tmp = 0; 14508c2ecf20Sopenharmony_ci 14518c2ecf20Sopenharmony_ci for (i = 0; i < IQK_NR; i++) 14528c2ecf20Sopenharmony_ci reg_tmp += result[IQK_ROUND_HYBRID][i]; 14538c2ecf20Sopenharmony_ci 14548c2ecf20Sopenharmony_ci if (reg_tmp != 0) { 14558c2ecf20Sopenharmony_ci final_candidate = IQK_ROUND_HYBRID; 14568c2ecf20Sopenharmony_ci } else { 14578c2ecf20Sopenharmony_ci WARN(1, "IQK is failed\n"); 14588c2ecf20Sopenharmony_ci goto out; 14598c2ecf20Sopenharmony_ci } 14608c2ecf20Sopenharmony_ci } 14618c2ecf20Sopenharmony_ci 14628c2ecf20Sopenharmony_ciiqk_done: 14638c2ecf20Sopenharmony_ci rtw8723d_iqk_fill_s1_matrix(rtwdev, result[final_candidate]); 14648c2ecf20Sopenharmony_ci rtw8723d_iqk_fill_s0_matrix(rtwdev, result[final_candidate]); 14658c2ecf20Sopenharmony_ci 14668c2ecf20Sopenharmony_ci dm_info->iqk.result.s1_x = result[final_candidate][IQK_S1_TX_X]; 14678c2ecf20Sopenharmony_ci dm_info->iqk.result.s1_y = result[final_candidate][IQK_S1_TX_Y]; 14688c2ecf20Sopenharmony_ci dm_info->iqk.result.s0_x = result[final_candidate][IQK_S0_TX_X]; 14698c2ecf20Sopenharmony_ci dm_info->iqk.result.s0_y = result[final_candidate][IQK_S0_TX_Y]; 14708c2ecf20Sopenharmony_ci dm_info->iqk.done = true; 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_ciout: 14738c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_BB_SEL_BTG, backup.bb_sel_btg); 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] final_candidate is %x\n", 14768c2ecf20Sopenharmony_ci final_candidate); 14778c2ecf20Sopenharmony_ci 14788c2ecf20Sopenharmony_ci for (i = IQK_ROUND_0; i < IQK_ROUND_SIZE; i++) 14798c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 14808c2ecf20Sopenharmony_ci "[IQK] Result %u: rege94_s1=%x rege9c_s1=%x regea4_s1=%x regeac_s1=%x rege94_s0=%x rege9c_s0=%x regea4_s0=%x regeac_s0=%x %s\n", 14818c2ecf20Sopenharmony_ci i, 14828c2ecf20Sopenharmony_ci result[i][0], result[i][1], result[i][2], result[i][3], 14838c2ecf20Sopenharmony_ci result[i][4], result[i][5], result[i][6], result[i][7], 14848c2ecf20Sopenharmony_ci final_candidate == i ? "(final candidate)" : ""); 14858c2ecf20Sopenharmony_ci 14868c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 14878c2ecf20Sopenharmony_ci "[IQK]0xc80 = 0x%x 0xc94 = 0x%x 0xc14 = 0x%x 0xca0 = 0x%x\n", 14888c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE), 14898c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N), 14908c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_A_RXIQI), 14918c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_RXIQK_MATRIX_LSB_11N)); 14928c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, 14938c2ecf20Sopenharmony_ci "[IQK]0xcd0 = 0x%x 0xcd4 = 0x%x 0xcd8 = 0x%x\n", 14948c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_TXIQ_AB_S0), 14958c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_TXIQ_CD_S0), 14968c2ecf20Sopenharmony_ci rtw_read32(rtwdev, REG_RXIQ_AB_S0)); 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_RFK, "[IQK] finished\n"); 14998c2ecf20Sopenharmony_ci} 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci/* for coex */ 15028c2ecf20Sopenharmony_cistatic void rtw8723d_coex_cfg_init(struct rtw_dev *rtwdev) 15038c2ecf20Sopenharmony_ci{ 15048c2ecf20Sopenharmony_ci /* enable TBTT nterrupt */ 15058c2ecf20Sopenharmony_ci rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION); 15068c2ecf20Sopenharmony_ci 15078c2ecf20Sopenharmony_ci /* BT report packet sample rate */ 15088c2ecf20Sopenharmony_ci /* 0x790[5:0]=0x5 */ 15098c2ecf20Sopenharmony_ci rtw_write8_set(rtwdev, REG_BT_TDMA_TIME, 0x05); 15108c2ecf20Sopenharmony_ci 15118c2ecf20Sopenharmony_ci /* enable BT counter statistics */ 15128c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_BT_STAT_CTRL, 0x1); 15138c2ecf20Sopenharmony_ci 15148c2ecf20Sopenharmony_ci /* enable PTA (3-wire function form BT side) */ 15158c2ecf20Sopenharmony_ci rtw_write32_set(rtwdev, REG_GPIO_MUXCFG, BIT_BT_PTA_EN); 15168c2ecf20Sopenharmony_ci rtw_write32_set(rtwdev, REG_GPIO_MUXCFG, BIT_BT_AOD_GPIO3); 15178c2ecf20Sopenharmony_ci 15188c2ecf20Sopenharmony_ci /* enable PTA (tx/rx signal form WiFi side) */ 15198c2ecf20Sopenharmony_ci rtw_write8_set(rtwdev, REG_QUEUE_CTRL, BIT_PTA_WL_TX_EN); 15208c2ecf20Sopenharmony_ci} 15218c2ecf20Sopenharmony_ci 15228c2ecf20Sopenharmony_cistatic void rtw8723d_coex_cfg_gnt_fix(struct rtw_dev *rtwdev) 15238c2ecf20Sopenharmony_ci{ 15248c2ecf20Sopenharmony_ci} 15258c2ecf20Sopenharmony_ci 15268c2ecf20Sopenharmony_cistatic void rtw8723d_coex_cfg_gnt_debug(struct rtw_dev *rtwdev) 15278c2ecf20Sopenharmony_ci{ 15288c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_LEDCFG2, BIT(6), 0); 15298c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_PAD_CTRL1 + 3, BIT(0), 0); 15308c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_GPIO_INTM + 2, BIT(4), 0); 15318c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_GPIO_MUXCFG + 2, BIT(1), 0); 15328c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_PAD_CTRL1 + 3, BIT(1), 0); 15338c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_PAD_CTRL1 + 2, BIT(7), 0); 15348c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_SYS_CLKR + 1, BIT(1), 0); 15358c2ecf20Sopenharmony_ci rtw_write8_mask(rtwdev, REG_SYS_SDIO_CTRL + 3, BIT(3), 0); 15368c2ecf20Sopenharmony_ci} 15378c2ecf20Sopenharmony_ci 15388c2ecf20Sopenharmony_cistatic void rtw8723d_coex_cfg_rfe_type(struct rtw_dev *rtwdev) 15398c2ecf20Sopenharmony_ci{ 15408c2ecf20Sopenharmony_ci struct rtw_efuse *efuse = &rtwdev->efuse; 15418c2ecf20Sopenharmony_ci struct rtw_coex *coex = &rtwdev->coex; 15428c2ecf20Sopenharmony_ci struct rtw_coex_rfe *coex_rfe = &coex->rfe; 15438c2ecf20Sopenharmony_ci bool aux = efuse->bt_setting & BIT(6); 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_ci coex_rfe->rfe_module_type = rtwdev->efuse.rfe_option; 15468c2ecf20Sopenharmony_ci coex_rfe->ant_switch_polarity = 0; 15478c2ecf20Sopenharmony_ci coex_rfe->ant_switch_exist = false; 15488c2ecf20Sopenharmony_ci coex_rfe->ant_switch_with_bt = false; 15498c2ecf20Sopenharmony_ci coex_rfe->ant_switch_diversity = false; 15508c2ecf20Sopenharmony_ci coex_rfe->wlg_at_btg = true; 15518c2ecf20Sopenharmony_ci 15528c2ecf20Sopenharmony_ci /* decide antenna at main or aux */ 15538c2ecf20Sopenharmony_ci if (efuse->share_ant) { 15548c2ecf20Sopenharmony_ci if (aux) 15558c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_BB_SEL_BTG, 0x80); 15568c2ecf20Sopenharmony_ci else 15578c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_BB_SEL_BTG, 0x200); 15588c2ecf20Sopenharmony_ci } else { 15598c2ecf20Sopenharmony_ci if (aux) 15608c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_BB_SEL_BTG, 0x280); 15618c2ecf20Sopenharmony_ci else 15628c2ecf20Sopenharmony_ci rtw_write16(rtwdev, REG_BB_SEL_BTG, 0x0); 15638c2ecf20Sopenharmony_ci } 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_ci /* disable LTE coex in wifi side */ 15668c2ecf20Sopenharmony_ci rtw_coex_write_indirect_reg(rtwdev, LTE_COEX_CTRL, BIT_LTE_COEX_EN, 0x0); 15678c2ecf20Sopenharmony_ci rtw_coex_write_indirect_reg(rtwdev, LTE_WL_TRX_CTRL, MASKLWORD, 0xffff); 15688c2ecf20Sopenharmony_ci rtw_coex_write_indirect_reg(rtwdev, LTE_BT_TRX_CTRL, MASKLWORD, 0xffff); 15698c2ecf20Sopenharmony_ci} 15708c2ecf20Sopenharmony_ci 15718c2ecf20Sopenharmony_cistatic void rtw8723d_coex_cfg_wl_tx_power(struct rtw_dev *rtwdev, u8 wl_pwr) 15728c2ecf20Sopenharmony_ci{ 15738c2ecf20Sopenharmony_ci struct rtw_coex *coex = &rtwdev->coex; 15748c2ecf20Sopenharmony_ci struct rtw_coex_dm *coex_dm = &coex->dm; 15758c2ecf20Sopenharmony_ci static const u8 wl_tx_power[] = {0xb2, 0x90}; 15768c2ecf20Sopenharmony_ci u8 pwr; 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_ci if (wl_pwr == coex_dm->cur_wl_pwr_lvl) 15798c2ecf20Sopenharmony_ci return; 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_ci coex_dm->cur_wl_pwr_lvl = wl_pwr; 15828c2ecf20Sopenharmony_ci 15838c2ecf20Sopenharmony_ci if (coex_dm->cur_wl_pwr_lvl >= ARRAY_SIZE(wl_tx_power)) 15848c2ecf20Sopenharmony_ci coex_dm->cur_wl_pwr_lvl = ARRAY_SIZE(wl_tx_power) - 1; 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci pwr = wl_tx_power[coex_dm->cur_wl_pwr_lvl]; 15878c2ecf20Sopenharmony_ci 15888c2ecf20Sopenharmony_ci rtw_write8(rtwdev, REG_ANA_PARAM1 + 3, pwr); 15898c2ecf20Sopenharmony_ci} 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_cistatic void rtw8723d_coex_cfg_wl_rx_gain(struct rtw_dev *rtwdev, bool low_gain) 15928c2ecf20Sopenharmony_ci{ 15938c2ecf20Sopenharmony_ci struct rtw_coex *coex = &rtwdev->coex; 15948c2ecf20Sopenharmony_ci struct rtw_coex_dm *coex_dm = &coex->dm; 15958c2ecf20Sopenharmony_ci /* WL Rx Low gain on */ 15968c2ecf20Sopenharmony_ci static const u32 wl_rx_low_gain_on[] = { 15978c2ecf20Sopenharmony_ci 0xec120101, 0xeb130101, 0xce140101, 0xcd150101, 0xcc160101, 15988c2ecf20Sopenharmony_ci 0xcb170101, 0xca180101, 0x8d190101, 0x8c1a0101, 0x8b1b0101, 15998c2ecf20Sopenharmony_ci 0x4f1c0101, 0x4e1d0101, 0x4d1e0101, 0x4c1f0101, 0x0e200101, 16008c2ecf20Sopenharmony_ci 0x0d210101, 0x0c220101, 0x0b230101, 0xcf240001, 0xce250001, 16018c2ecf20Sopenharmony_ci 0xcd260001, 0xcc270001, 0x8f280001 16028c2ecf20Sopenharmony_ci }; 16038c2ecf20Sopenharmony_ci /* WL Rx Low gain off */ 16048c2ecf20Sopenharmony_ci static const u32 wl_rx_low_gain_off[] = { 16058c2ecf20Sopenharmony_ci 0xec120101, 0xeb130101, 0xea140101, 0xe9150101, 0xe8160101, 16068c2ecf20Sopenharmony_ci 0xe7170101, 0xe6180101, 0xe5190101, 0xe41a0101, 0xe31b0101, 16078c2ecf20Sopenharmony_ci 0xe21c0101, 0xe11d0101, 0xe01e0101, 0x861f0101, 0x85200101, 16088c2ecf20Sopenharmony_ci 0x84210101, 0x83220101, 0x82230101, 0x81240101, 0x80250101, 16098c2ecf20Sopenharmony_ci 0x44260101, 0x43270101, 0x42280101 16108c2ecf20Sopenharmony_ci }; 16118c2ecf20Sopenharmony_ci u8 i; 16128c2ecf20Sopenharmony_ci 16138c2ecf20Sopenharmony_ci if (low_gain == coex_dm->cur_wl_rx_low_gain_en) 16148c2ecf20Sopenharmony_ci return; 16158c2ecf20Sopenharmony_ci 16168c2ecf20Sopenharmony_ci coex_dm->cur_wl_rx_low_gain_en = low_gain; 16178c2ecf20Sopenharmony_ci 16188c2ecf20Sopenharmony_ci if (coex_dm->cur_wl_rx_low_gain_en) { 16198c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(wl_rx_low_gain_on); i++) 16208c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_AGCRSSI, wl_rx_low_gain_on[i]); 16218c2ecf20Sopenharmony_ci } else { 16228c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(wl_rx_low_gain_off); i++) 16238c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_AGCRSSI, wl_rx_low_gain_off[i]); 16248c2ecf20Sopenharmony_ci } 16258c2ecf20Sopenharmony_ci} 16268c2ecf20Sopenharmony_ci 16278c2ecf20Sopenharmony_cistatic u8 rtw8723d_pwrtrack_get_limit_ofdm(struct rtw_dev *rtwdev) 16288c2ecf20Sopenharmony_ci{ 16298c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 16308c2ecf20Sopenharmony_ci u8 tx_rate = dm_info->tx_rate; 16318c2ecf20Sopenharmony_ci u8 limit_ofdm = 30; 16328c2ecf20Sopenharmony_ci 16338c2ecf20Sopenharmony_ci switch (tx_rate) { 16348c2ecf20Sopenharmony_ci case DESC_RATE1M...DESC_RATE5_5M: 16358c2ecf20Sopenharmony_ci case DESC_RATE11M: 16368c2ecf20Sopenharmony_ci break; 16378c2ecf20Sopenharmony_ci case DESC_RATE6M...DESC_RATE48M: 16388c2ecf20Sopenharmony_ci limit_ofdm = 36; 16398c2ecf20Sopenharmony_ci break; 16408c2ecf20Sopenharmony_ci case DESC_RATE54M: 16418c2ecf20Sopenharmony_ci limit_ofdm = 34; 16428c2ecf20Sopenharmony_ci break; 16438c2ecf20Sopenharmony_ci case DESC_RATEMCS0...DESC_RATEMCS2: 16448c2ecf20Sopenharmony_ci limit_ofdm = 38; 16458c2ecf20Sopenharmony_ci break; 16468c2ecf20Sopenharmony_ci case DESC_RATEMCS3...DESC_RATEMCS4: 16478c2ecf20Sopenharmony_ci limit_ofdm = 36; 16488c2ecf20Sopenharmony_ci break; 16498c2ecf20Sopenharmony_ci case DESC_RATEMCS5...DESC_RATEMCS7: 16508c2ecf20Sopenharmony_ci limit_ofdm = 34; 16518c2ecf20Sopenharmony_ci break; 16528c2ecf20Sopenharmony_ci default: 16538c2ecf20Sopenharmony_ci rtw_warn(rtwdev, "pwrtrack unhandled tx_rate 0x%x\n", tx_rate); 16548c2ecf20Sopenharmony_ci break; 16558c2ecf20Sopenharmony_ci } 16568c2ecf20Sopenharmony_ci 16578c2ecf20Sopenharmony_ci return limit_ofdm; 16588c2ecf20Sopenharmony_ci} 16598c2ecf20Sopenharmony_ci 16608c2ecf20Sopenharmony_cistatic void rtw8723d_set_iqk_matrix_by_result(struct rtw_dev *rtwdev, 16618c2ecf20Sopenharmony_ci u32 ofdm_swing, u8 rf_path) 16628c2ecf20Sopenharmony_ci{ 16638c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 16648c2ecf20Sopenharmony_ci s32 ele_A, ele_D, ele_C; 16658c2ecf20Sopenharmony_ci s32 ele_A_ext, ele_C_ext, ele_D_ext; 16668c2ecf20Sopenharmony_ci s32 iqk_result_x; 16678c2ecf20Sopenharmony_ci s32 iqk_result_y; 16688c2ecf20Sopenharmony_ci s32 value32; 16698c2ecf20Sopenharmony_ci 16708c2ecf20Sopenharmony_ci switch (rf_path) { 16718c2ecf20Sopenharmony_ci default: 16728c2ecf20Sopenharmony_ci case RF_PATH_A: 16738c2ecf20Sopenharmony_ci iqk_result_x = dm_info->iqk.result.s1_x; 16748c2ecf20Sopenharmony_ci iqk_result_y = dm_info->iqk.result.s1_y; 16758c2ecf20Sopenharmony_ci break; 16768c2ecf20Sopenharmony_ci case RF_PATH_B: 16778c2ecf20Sopenharmony_ci iqk_result_x = dm_info->iqk.result.s0_x; 16788c2ecf20Sopenharmony_ci iqk_result_y = dm_info->iqk.result.s0_y; 16798c2ecf20Sopenharmony_ci break; 16808c2ecf20Sopenharmony_ci } 16818c2ecf20Sopenharmony_ci 16828c2ecf20Sopenharmony_ci /* new element D */ 16838c2ecf20Sopenharmony_ci ele_D = OFDM_SWING_D(ofdm_swing); 16848c2ecf20Sopenharmony_ci iqk_mult(iqk_result_x, ele_D, &ele_D_ext); 16858c2ecf20Sopenharmony_ci /* new element A */ 16868c2ecf20Sopenharmony_ci iqk_result_x = iqkxy_to_s32(iqk_result_x); 16878c2ecf20Sopenharmony_ci ele_A = iqk_mult(iqk_result_x, ele_D, &ele_A_ext); 16888c2ecf20Sopenharmony_ci /* new element C */ 16898c2ecf20Sopenharmony_ci iqk_result_y = iqkxy_to_s32(iqk_result_y); 16908c2ecf20Sopenharmony_ci ele_C = iqk_mult(iqk_result_y, ele_D, &ele_C_ext); 16918c2ecf20Sopenharmony_ci 16928c2ecf20Sopenharmony_ci switch (rf_path) { 16938c2ecf20Sopenharmony_ci case RF_PATH_A: 16948c2ecf20Sopenharmony_ci default: 16958c2ecf20Sopenharmony_ci /* write new elements A, C, D, and element B is always 0 */ 16968c2ecf20Sopenharmony_ci value32 = BIT_SET_TXIQ_ELM_ACD(ele_A, ele_C, ele_D); 16978c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, value32); 16988c2ecf20Sopenharmony_ci value32 = BIT_SET_TXIQ_ELM_C1(ele_C); 16998c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N, MASKH4BITS, 17008c2ecf20Sopenharmony_ci value32); 17018c2ecf20Sopenharmony_ci value32 = rtw_read32(rtwdev, REG_OFDM_0_ECCA_THRESHOLD); 17028c2ecf20Sopenharmony_ci value32 &= ~BIT_MASK_OFDM0_EXTS; 17038c2ecf20Sopenharmony_ci value32 |= BIT_SET_OFDM0_EXTS(ele_A_ext, ele_C_ext, ele_D_ext); 17048c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, value32); 17058c2ecf20Sopenharmony_ci break; 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci case RF_PATH_B: 17088c2ecf20Sopenharmony_ci /* write new elements A, C, D, and element B is always 0 */ 17098c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_D_S0, ele_D); 17108c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_C_S0, ele_C); 17118c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_A_S0, ele_A); 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_D_EXT_S0, 17148c2ecf20Sopenharmony_ci ele_D_ext); 17158c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_A_EXT_S0, 17168c2ecf20Sopenharmony_ci ele_A_ext); 17178c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_C_EXT_S0, 17188c2ecf20Sopenharmony_ci ele_C_ext); 17198c2ecf20Sopenharmony_ci break; 17208c2ecf20Sopenharmony_ci } 17218c2ecf20Sopenharmony_ci} 17228c2ecf20Sopenharmony_ci 17238c2ecf20Sopenharmony_cistatic void rtw8723d_set_iqk_matrix(struct rtw_dev *rtwdev, s8 ofdm_index, 17248c2ecf20Sopenharmony_ci u8 rf_path) 17258c2ecf20Sopenharmony_ci{ 17268c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 17278c2ecf20Sopenharmony_ci s32 value32; 17288c2ecf20Sopenharmony_ci u32 ofdm_swing; 17298c2ecf20Sopenharmony_ci 17308c2ecf20Sopenharmony_ci if (ofdm_index >= RTW_OFDM_SWING_TABLE_SIZE) 17318c2ecf20Sopenharmony_ci ofdm_index = RTW_OFDM_SWING_TABLE_SIZE - 1; 17328c2ecf20Sopenharmony_ci else if (ofdm_index < 0) 17338c2ecf20Sopenharmony_ci ofdm_index = 0; 17348c2ecf20Sopenharmony_ci 17358c2ecf20Sopenharmony_ci ofdm_swing = rtw8723d_ofdm_swing_table[ofdm_index]; 17368c2ecf20Sopenharmony_ci 17378c2ecf20Sopenharmony_ci if (dm_info->iqk.done) { 17388c2ecf20Sopenharmony_ci rtw8723d_set_iqk_matrix_by_result(rtwdev, ofdm_swing, rf_path); 17398c2ecf20Sopenharmony_ci return; 17408c2ecf20Sopenharmony_ci } 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci switch (rf_path) { 17438c2ecf20Sopenharmony_ci case RF_PATH_A: 17448c2ecf20Sopenharmony_ci default: 17458c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM_0_XA_TX_IQ_IMBALANCE, ofdm_swing); 17468c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQK_MATRIXA_LSB2_11N, MASKH4BITS, 17478c2ecf20Sopenharmony_ci 0x00); 17488c2ecf20Sopenharmony_ci value32 = rtw_read32(rtwdev, REG_OFDM_0_ECCA_THRESHOLD); 17498c2ecf20Sopenharmony_ci value32 &= ~BIT_MASK_OFDM0_EXTS; 17508c2ecf20Sopenharmony_ci rtw_write32(rtwdev, REG_OFDM_0_ECCA_THRESHOLD, value32); 17518c2ecf20Sopenharmony_ci break; 17528c2ecf20Sopenharmony_ci 17538c2ecf20Sopenharmony_ci case RF_PATH_B: 17548c2ecf20Sopenharmony_ci /* image S1:c80 to S0:Cd0 and Cd4 */ 17558c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_A_S0, 17568c2ecf20Sopenharmony_ci OFDM_SWING_A(ofdm_swing)); 17578c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_B_S0, 17588c2ecf20Sopenharmony_ci OFDM_SWING_B(ofdm_swing)); 17598c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_C_S0, 17608c2ecf20Sopenharmony_ci OFDM_SWING_C(ofdm_swing)); 17618c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_D_S0, 17628c2ecf20Sopenharmony_ci OFDM_SWING_D(ofdm_swing)); 17638c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_D_EXT_S0, 0x0); 17648c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_CD_S0, BIT_MASK_TXIQ_C_EXT_S0, 0x0); 17658c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_TXIQ_AB_S0, BIT_MASK_TXIQ_A_EXT_S0, 0x0); 17668c2ecf20Sopenharmony_ci break; 17678c2ecf20Sopenharmony_ci } 17688c2ecf20Sopenharmony_ci} 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_cistatic void rtw8723d_pwrtrack_set_ofdm_pwr(struct rtw_dev *rtwdev, s8 swing_idx, 17718c2ecf20Sopenharmony_ci s8 txagc_idx) 17728c2ecf20Sopenharmony_ci{ 17738c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 17748c2ecf20Sopenharmony_ci 17758c2ecf20Sopenharmony_ci dm_info->txagc_remnant_ofdm = txagc_idx; 17768c2ecf20Sopenharmony_ci 17778c2ecf20Sopenharmony_ci rtw8723d_set_iqk_matrix(rtwdev, swing_idx, RF_PATH_A); 17788c2ecf20Sopenharmony_ci rtw8723d_set_iqk_matrix(rtwdev, swing_idx, RF_PATH_B); 17798c2ecf20Sopenharmony_ci} 17808c2ecf20Sopenharmony_ci 17818c2ecf20Sopenharmony_cistatic void rtw8723d_pwrtrack_set_cck_pwr(struct rtw_dev *rtwdev, s8 swing_idx, 17828c2ecf20Sopenharmony_ci s8 txagc_idx) 17838c2ecf20Sopenharmony_ci{ 17848c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 17858c2ecf20Sopenharmony_ci 17868c2ecf20Sopenharmony_ci dm_info->txagc_remnant_cck = txagc_idx; 17878c2ecf20Sopenharmony_ci 17888c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, 0xab4, 0x000007FF, 17898c2ecf20Sopenharmony_ci rtw8723d_cck_swing_table[swing_idx]); 17908c2ecf20Sopenharmony_ci} 17918c2ecf20Sopenharmony_ci 17928c2ecf20Sopenharmony_cistatic void rtw8723d_pwrtrack_set(struct rtw_dev *rtwdev, u8 path) 17938c2ecf20Sopenharmony_ci{ 17948c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 17958c2ecf20Sopenharmony_ci struct rtw_hal *hal = &rtwdev->hal; 17968c2ecf20Sopenharmony_ci u8 limit_ofdm; 17978c2ecf20Sopenharmony_ci u8 limit_cck = 40; 17988c2ecf20Sopenharmony_ci s8 final_ofdm_swing_index; 17998c2ecf20Sopenharmony_ci s8 final_cck_swing_index; 18008c2ecf20Sopenharmony_ci 18018c2ecf20Sopenharmony_ci limit_ofdm = rtw8723d_pwrtrack_get_limit_ofdm(rtwdev); 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci final_ofdm_swing_index = RTW_DEF_OFDM_SWING_INDEX + 18048c2ecf20Sopenharmony_ci dm_info->delta_power_index[path]; 18058c2ecf20Sopenharmony_ci final_cck_swing_index = RTW_DEF_CCK_SWING_INDEX + 18068c2ecf20Sopenharmony_ci dm_info->delta_power_index[path]; 18078c2ecf20Sopenharmony_ci 18088c2ecf20Sopenharmony_ci if (final_ofdm_swing_index > limit_ofdm) 18098c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_ofdm_pwr(rtwdev, limit_ofdm, 18108c2ecf20Sopenharmony_ci final_ofdm_swing_index - limit_ofdm); 18118c2ecf20Sopenharmony_ci else if (final_ofdm_swing_index < 0) 18128c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_ofdm_pwr(rtwdev, 0, 18138c2ecf20Sopenharmony_ci final_ofdm_swing_index); 18148c2ecf20Sopenharmony_ci else 18158c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_ofdm_pwr(rtwdev, final_ofdm_swing_index, 0); 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci if (final_cck_swing_index > limit_cck) 18188c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_cck_pwr(rtwdev, limit_cck, 18198c2ecf20Sopenharmony_ci final_cck_swing_index - limit_cck); 18208c2ecf20Sopenharmony_ci else if (final_cck_swing_index < 0) 18218c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_cck_pwr(rtwdev, 0, 18228c2ecf20Sopenharmony_ci final_cck_swing_index); 18238c2ecf20Sopenharmony_ci else 18248c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_cck_pwr(rtwdev, final_cck_swing_index, 0); 18258c2ecf20Sopenharmony_ci 18268c2ecf20Sopenharmony_ci rtw_phy_set_tx_power_level(rtwdev, hal->current_channel); 18278c2ecf20Sopenharmony_ci} 18288c2ecf20Sopenharmony_ci 18298c2ecf20Sopenharmony_cistatic void rtw8723d_pwrtrack_set_xtal(struct rtw_dev *rtwdev, u8 therm_path, 18308c2ecf20Sopenharmony_ci u8 delta) 18318c2ecf20Sopenharmony_ci{ 18328c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 18338c2ecf20Sopenharmony_ci const struct rtw_pwr_track_tbl *tbl = rtwdev->chip->pwr_track_tbl; 18348c2ecf20Sopenharmony_ci const s8 *pwrtrk_xtal; 18358c2ecf20Sopenharmony_ci s8 xtal_cap; 18368c2ecf20Sopenharmony_ci 18378c2ecf20Sopenharmony_ci if (dm_info->thermal_avg[therm_path] > 18388c2ecf20Sopenharmony_ci rtwdev->efuse.thermal_meter[therm_path]) 18398c2ecf20Sopenharmony_ci pwrtrk_xtal = tbl->pwrtrk_xtal_p; 18408c2ecf20Sopenharmony_ci else 18418c2ecf20Sopenharmony_ci pwrtrk_xtal = tbl->pwrtrk_xtal_n; 18428c2ecf20Sopenharmony_ci 18438c2ecf20Sopenharmony_ci xtal_cap = rtwdev->efuse.crystal_cap & 0x3F; 18448c2ecf20Sopenharmony_ci xtal_cap = clamp_t(s8, xtal_cap + pwrtrk_xtal[delta], 0, 0x3F); 18458c2ecf20Sopenharmony_ci rtw_write32_mask(rtwdev, REG_AFE_CTRL3, BIT_MASK_XTAL, 18468c2ecf20Sopenharmony_ci xtal_cap | (xtal_cap << 6)); 18478c2ecf20Sopenharmony_ci} 18488c2ecf20Sopenharmony_ci 18498c2ecf20Sopenharmony_cistatic void rtw8723d_phy_pwrtrack(struct rtw_dev *rtwdev) 18508c2ecf20Sopenharmony_ci{ 18518c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 18528c2ecf20Sopenharmony_ci struct rtw_swing_table swing_table; 18538c2ecf20Sopenharmony_ci u8 thermal_value, delta, path; 18548c2ecf20Sopenharmony_ci bool do_iqk = false; 18558c2ecf20Sopenharmony_ci 18568c2ecf20Sopenharmony_ci rtw_phy_config_swing_table(rtwdev, &swing_table); 18578c2ecf20Sopenharmony_ci 18588c2ecf20Sopenharmony_ci if (rtwdev->efuse.thermal_meter[0] == 0xff) 18598c2ecf20Sopenharmony_ci return; 18608c2ecf20Sopenharmony_ci 18618c2ecf20Sopenharmony_ci thermal_value = rtw_read_rf(rtwdev, RF_PATH_A, RF_T_METER, 0xfc00); 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_ci rtw_phy_pwrtrack_avg(rtwdev, thermal_value, RF_PATH_A); 18648c2ecf20Sopenharmony_ci 18658c2ecf20Sopenharmony_ci do_iqk = rtw_phy_pwrtrack_need_iqk(rtwdev); 18668c2ecf20Sopenharmony_ci 18678c2ecf20Sopenharmony_ci if (do_iqk) 18688c2ecf20Sopenharmony_ci rtw8723d_lck(rtwdev); 18698c2ecf20Sopenharmony_ci 18708c2ecf20Sopenharmony_ci if (dm_info->pwr_trk_init_trigger) 18718c2ecf20Sopenharmony_ci dm_info->pwr_trk_init_trigger = false; 18728c2ecf20Sopenharmony_ci else if (!rtw_phy_pwrtrack_thermal_changed(rtwdev, thermal_value, 18738c2ecf20Sopenharmony_ci RF_PATH_A)) 18748c2ecf20Sopenharmony_ci goto iqk; 18758c2ecf20Sopenharmony_ci 18768c2ecf20Sopenharmony_ci delta = rtw_phy_pwrtrack_get_delta(rtwdev, RF_PATH_A); 18778c2ecf20Sopenharmony_ci 18788c2ecf20Sopenharmony_ci delta = min_t(u8, delta, RTW_PWR_TRK_TBL_SZ - 1); 18798c2ecf20Sopenharmony_ci 18808c2ecf20Sopenharmony_ci for (path = 0; path < rtwdev->hal.rf_path_num; path++) { 18818c2ecf20Sopenharmony_ci s8 delta_cur, delta_last; 18828c2ecf20Sopenharmony_ci 18838c2ecf20Sopenharmony_ci delta_last = dm_info->delta_power_index[path]; 18848c2ecf20Sopenharmony_ci delta_cur = rtw_phy_pwrtrack_get_pwridx(rtwdev, &swing_table, 18858c2ecf20Sopenharmony_ci path, RF_PATH_A, delta); 18868c2ecf20Sopenharmony_ci if (delta_last == delta_cur) 18878c2ecf20Sopenharmony_ci continue; 18888c2ecf20Sopenharmony_ci 18898c2ecf20Sopenharmony_ci dm_info->delta_power_index[path] = delta_cur; 18908c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set(rtwdev, path); 18918c2ecf20Sopenharmony_ci } 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci rtw8723d_pwrtrack_set_xtal(rtwdev, RF_PATH_A, delta); 18948c2ecf20Sopenharmony_ci 18958c2ecf20Sopenharmony_ciiqk: 18968c2ecf20Sopenharmony_ci if (do_iqk) 18978c2ecf20Sopenharmony_ci rtw8723d_phy_calibration(rtwdev); 18988c2ecf20Sopenharmony_ci} 18998c2ecf20Sopenharmony_ci 19008c2ecf20Sopenharmony_cistatic void rtw8723d_pwr_track(struct rtw_dev *rtwdev) 19018c2ecf20Sopenharmony_ci{ 19028c2ecf20Sopenharmony_ci struct rtw_efuse *efuse = &rtwdev->efuse; 19038c2ecf20Sopenharmony_ci struct rtw_dm_info *dm_info = &rtwdev->dm_info; 19048c2ecf20Sopenharmony_ci 19058c2ecf20Sopenharmony_ci if (efuse->power_track_type != 0) 19068c2ecf20Sopenharmony_ci return; 19078c2ecf20Sopenharmony_ci 19088c2ecf20Sopenharmony_ci if (!dm_info->pwr_trk_triggered) { 19098c2ecf20Sopenharmony_ci rtw_write_rf(rtwdev, RF_PATH_A, RF_T_METER, 19108c2ecf20Sopenharmony_ci GENMASK(17, 16), 0x03); 19118c2ecf20Sopenharmony_ci dm_info->pwr_trk_triggered = true; 19128c2ecf20Sopenharmony_ci return; 19138c2ecf20Sopenharmony_ci } 19148c2ecf20Sopenharmony_ci 19158c2ecf20Sopenharmony_ci rtw8723d_phy_pwrtrack(rtwdev); 19168c2ecf20Sopenharmony_ci dm_info->pwr_trk_triggered = false; 19178c2ecf20Sopenharmony_ci} 19188c2ecf20Sopenharmony_ci 19198c2ecf20Sopenharmony_cistatic struct rtw_chip_ops rtw8723d_ops = { 19208c2ecf20Sopenharmony_ci .phy_set_param = rtw8723d_phy_set_param, 19218c2ecf20Sopenharmony_ci .read_efuse = rtw8723d_read_efuse, 19228c2ecf20Sopenharmony_ci .query_rx_desc = rtw8723d_query_rx_desc, 19238c2ecf20Sopenharmony_ci .set_channel = rtw8723d_set_channel, 19248c2ecf20Sopenharmony_ci .mac_init = rtw8723d_mac_init, 19258c2ecf20Sopenharmony_ci .shutdown = rtw8723d_shutdown, 19268c2ecf20Sopenharmony_ci .read_rf = rtw_phy_read_rf_sipi, 19278c2ecf20Sopenharmony_ci .write_rf = rtw_phy_write_rf_reg_sipi, 19288c2ecf20Sopenharmony_ci .set_tx_power_index = rtw8723d_set_tx_power_index, 19298c2ecf20Sopenharmony_ci .set_antenna = NULL, 19308c2ecf20Sopenharmony_ci .cfg_ldo25 = rtw8723d_cfg_ldo25, 19318c2ecf20Sopenharmony_ci .efuse_grant = rtw8723d_efuse_grant, 19328c2ecf20Sopenharmony_ci .false_alarm_statistics = rtw8723d_false_alarm_statistics, 19338c2ecf20Sopenharmony_ci .phy_calibration = rtw8723d_phy_calibration, 19348c2ecf20Sopenharmony_ci .pwr_track = rtw8723d_pwr_track, 19358c2ecf20Sopenharmony_ci .config_bfee = NULL, 19368c2ecf20Sopenharmony_ci .set_gid_table = NULL, 19378c2ecf20Sopenharmony_ci .cfg_csi_rate = NULL, 19388c2ecf20Sopenharmony_ci 19398c2ecf20Sopenharmony_ci .coex_set_init = rtw8723d_coex_cfg_init, 19408c2ecf20Sopenharmony_ci .coex_set_ant_switch = NULL, 19418c2ecf20Sopenharmony_ci .coex_set_gnt_fix = rtw8723d_coex_cfg_gnt_fix, 19428c2ecf20Sopenharmony_ci .coex_set_gnt_debug = rtw8723d_coex_cfg_gnt_debug, 19438c2ecf20Sopenharmony_ci .coex_set_rfe_type = rtw8723d_coex_cfg_rfe_type, 19448c2ecf20Sopenharmony_ci .coex_set_wl_tx_power = rtw8723d_coex_cfg_wl_tx_power, 19458c2ecf20Sopenharmony_ci .coex_set_wl_rx_gain = rtw8723d_coex_cfg_wl_rx_gain, 19468c2ecf20Sopenharmony_ci}; 19478c2ecf20Sopenharmony_ci 19488c2ecf20Sopenharmony_ci/* Shared-Antenna Coex Table */ 19498c2ecf20Sopenharmony_cistatic const struct coex_table_para table_sant_8723d[] = { 19508c2ecf20Sopenharmony_ci {0xffffffff, 0xffffffff}, /* case-0 */ 19518c2ecf20Sopenharmony_ci {0x55555555, 0x55555555}, 19528c2ecf20Sopenharmony_ci {0x65555555, 0x65555555}, 19538c2ecf20Sopenharmony_ci {0xaaaaaaaa, 0xaaaaaaaa}, 19548c2ecf20Sopenharmony_ci {0x5a5a5a5a, 0x5a5a5a5a}, 19558c2ecf20Sopenharmony_ci {0xfafafafa, 0xfafafafa}, /* case-5 */ 19568c2ecf20Sopenharmony_ci {0xa5555555, 0xaaaa5aaa}, 19578c2ecf20Sopenharmony_ci {0x6a5a5a5a, 0x5a5a5a5a}, 19588c2ecf20Sopenharmony_ci {0x6a5a5a5a, 0x6a5a5a5a}, 19598c2ecf20Sopenharmony_ci {0x66555555, 0x5a5a5a5a}, 19608c2ecf20Sopenharmony_ci {0x65555555, 0x6a5a5a5a}, /* case-10 */ 19618c2ecf20Sopenharmony_ci {0x65555555, 0xfafafafa}, 19628c2ecf20Sopenharmony_ci {0x66555555, 0x5a5a5aaa}, 19638c2ecf20Sopenharmony_ci {0x65555555, 0x5aaa5aaa}, 19648c2ecf20Sopenharmony_ci {0x65555555, 0xaaaa5aaa}, 19658c2ecf20Sopenharmony_ci {0x66555555, 0xaaaaaaaa}, /* case-15 */ 19668c2ecf20Sopenharmony_ci {0xffff55ff, 0xfafafafa}, 19678c2ecf20Sopenharmony_ci {0xffff55ff, 0x6afa5afa}, 19688c2ecf20Sopenharmony_ci {0xaaffffaa, 0xfafafafa}, 19698c2ecf20Sopenharmony_ci {0xaa5555aa, 0x5a5a5a5a}, 19708c2ecf20Sopenharmony_ci {0xaa5555aa, 0x6a5a5a5a}, /* case-20 */ 19718c2ecf20Sopenharmony_ci {0xaa5555aa, 0xaaaaaaaa}, 19728c2ecf20Sopenharmony_ci {0xffffffff, 0x5a5a5a5a}, 19738c2ecf20Sopenharmony_ci {0xffffffff, 0x6a5a5a5a}, 19748c2ecf20Sopenharmony_ci {0xffffffff, 0x55555555}, 19758c2ecf20Sopenharmony_ci {0xffffffff, 0x6a5a5aaa}, /* case-25 */ 19768c2ecf20Sopenharmony_ci {0x55555555, 0x5a5a5a5a}, 19778c2ecf20Sopenharmony_ci {0x55555555, 0xaaaaaaaa}, 19788c2ecf20Sopenharmony_ci {0x55555555, 0x6a6a6a6a}, 19798c2ecf20Sopenharmony_ci {0x656a656a, 0x656a656a} 19808c2ecf20Sopenharmony_ci}; 19818c2ecf20Sopenharmony_ci 19828c2ecf20Sopenharmony_ci/* Non-Shared-Antenna Coex Table */ 19838c2ecf20Sopenharmony_cistatic const struct coex_table_para table_nsant_8723d[] = { 19848c2ecf20Sopenharmony_ci {0xffffffff, 0xffffffff}, /* case-100 */ 19858c2ecf20Sopenharmony_ci {0x55555555, 0x55555555}, 19868c2ecf20Sopenharmony_ci {0x65555555, 0x65555555}, 19878c2ecf20Sopenharmony_ci {0xaaaaaaaa, 0xaaaaaaaa}, 19888c2ecf20Sopenharmony_ci {0x5a5a5a5a, 0x5a5a5a5a}, 19898c2ecf20Sopenharmony_ci {0xfafafafa, 0xfafafafa}, /* case-105 */ 19908c2ecf20Sopenharmony_ci {0x5afa5afa, 0x5afa5afa}, 19918c2ecf20Sopenharmony_ci {0x55555555, 0xfafafafa}, 19928c2ecf20Sopenharmony_ci {0x65555555, 0xfafafafa}, 19938c2ecf20Sopenharmony_ci {0x65555555, 0x5a5a5a5a}, 19948c2ecf20Sopenharmony_ci {0x65555555, 0x6a5a5a5a}, /* case-110 */ 19958c2ecf20Sopenharmony_ci {0x65555555, 0xaaaaaaaa}, 19968c2ecf20Sopenharmony_ci {0xffff55ff, 0xfafafafa}, 19978c2ecf20Sopenharmony_ci {0xffff55ff, 0x5afa5afa}, 19988c2ecf20Sopenharmony_ci {0xffff55ff, 0xaaaaaaaa}, 19998c2ecf20Sopenharmony_ci {0xaaffffaa, 0xfafafafa}, /* case-115 */ 20008c2ecf20Sopenharmony_ci {0xaaffffaa, 0x5afa5afa}, 20018c2ecf20Sopenharmony_ci {0xaaffffaa, 0xaaaaaaaa}, 20028c2ecf20Sopenharmony_ci {0xffffffff, 0xfafafafa}, 20038c2ecf20Sopenharmony_ci {0xffffffff, 0x5afa5afa}, 20048c2ecf20Sopenharmony_ci {0xffffffff, 0xaaaaaaaa},/* case-120 */ 20058c2ecf20Sopenharmony_ci {0x55ff55ff, 0x5afa5afa}, 20068c2ecf20Sopenharmony_ci {0x55ff55ff, 0xaaaaaaaa}, 20078c2ecf20Sopenharmony_ci {0x55ff55ff, 0x55ff55ff} 20088c2ecf20Sopenharmony_ci}; 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_ci/* Shared-Antenna TDMA */ 20118c2ecf20Sopenharmony_cistatic const struct coex_tdma_para tdma_sant_8723d[] = { 20128c2ecf20Sopenharmony_ci { {0x08, 0x00, 0x00, 0x00, 0x00} }, /* case-0 */ 20138c2ecf20Sopenharmony_ci { {0x61, 0x45, 0x03, 0x11, 0x11} }, /* case-1 */ 20148c2ecf20Sopenharmony_ci { {0x61, 0x3a, 0x03, 0x11, 0x11} }, 20158c2ecf20Sopenharmony_ci { {0x61, 0x20, 0x03, 0x11, 0x11} }, 20168c2ecf20Sopenharmony_ci { {0x61, 0x30, 0x03, 0x11, 0x11} }, 20178c2ecf20Sopenharmony_ci { {0x61, 0x10, 0x03, 0x11, 0x11} }, /* case-5 */ 20188c2ecf20Sopenharmony_ci { {0x61, 0x48, 0x03, 0x11, 0x10} }, 20198c2ecf20Sopenharmony_ci { {0x61, 0x3a, 0x03, 0x11, 0x10} }, 20208c2ecf20Sopenharmony_ci { {0x61, 0x30, 0x03, 0x11, 0x10} }, 20218c2ecf20Sopenharmony_ci { {0x61, 0x20, 0x03, 0x11, 0x10} }, 20228c2ecf20Sopenharmony_ci { {0x61, 0x10, 0x03, 0x11, 0x10} }, /* case-10 */ 20238c2ecf20Sopenharmony_ci { {0x61, 0x10, 0x03, 0x11, 0x14} }, 20248c2ecf20Sopenharmony_ci { {0x61, 0x08, 0x03, 0x10, 0x14} }, 20258c2ecf20Sopenharmony_ci { {0x51, 0x10, 0x03, 0x10, 0x54} }, 20268c2ecf20Sopenharmony_ci { {0x51, 0x10, 0x03, 0x10, 0x55} }, 20278c2ecf20Sopenharmony_ci { {0x51, 0x10, 0x07, 0x10, 0x54} }, /* case-15 */ 20288c2ecf20Sopenharmony_ci { {0x51, 0x45, 0x03, 0x10, 0x50} }, 20298c2ecf20Sopenharmony_ci { {0x51, 0x3a, 0x03, 0x10, 0x50} }, 20308c2ecf20Sopenharmony_ci { {0x51, 0x30, 0x03, 0x10, 0x50} }, 20318c2ecf20Sopenharmony_ci { {0x51, 0x20, 0x03, 0x10, 0x50} }, 20328c2ecf20Sopenharmony_ci { {0x51, 0x15, 0x03, 0x10, 0x50} }, /* case-20 */ 20338c2ecf20Sopenharmony_ci { {0x51, 0x4a, 0x03, 0x10, 0x50} }, 20348c2ecf20Sopenharmony_ci { {0x51, 0x0c, 0x03, 0x10, 0x54} }, 20358c2ecf20Sopenharmony_ci { {0x55, 0x08, 0x03, 0x10, 0x54} }, 20368c2ecf20Sopenharmony_ci { {0x65, 0x10, 0x03, 0x11, 0x11} }, 20378c2ecf20Sopenharmony_ci { {0x51, 0x10, 0x03, 0x10, 0x51} }, /* case-25 */ 20388c2ecf20Sopenharmony_ci { {0x51, 0x08, 0x03, 0x10, 0x50} }, 20398c2ecf20Sopenharmony_ci { {0x61, 0x08, 0x03, 0x11, 0x11} } 20408c2ecf20Sopenharmony_ci}; 20418c2ecf20Sopenharmony_ci 20428c2ecf20Sopenharmony_ci/* Non-Shared-Antenna TDMA */ 20438c2ecf20Sopenharmony_cistatic const struct coex_tdma_para tdma_nsant_8723d[] = { 20448c2ecf20Sopenharmony_ci { {0x00, 0x00, 0x00, 0x40, 0x01} }, /* case-100 */ 20458c2ecf20Sopenharmony_ci { {0x61, 0x45, 0x03, 0x11, 0x11} }, /* case-101 */ 20468c2ecf20Sopenharmony_ci { {0x61, 0x3a, 0x03, 0x11, 0x11} }, 20478c2ecf20Sopenharmony_ci { {0x61, 0x30, 0x03, 0x11, 0x11} }, 20488c2ecf20Sopenharmony_ci { {0x61, 0x20, 0x03, 0x11, 0x11} }, 20498c2ecf20Sopenharmony_ci { {0x61, 0x10, 0x03, 0x11, 0x11} }, /* case-105 */ 20508c2ecf20Sopenharmony_ci { {0x61, 0x45, 0x03, 0x11, 0x10} }, 20518c2ecf20Sopenharmony_ci { {0x61, 0x3a, 0x03, 0x11, 0x10} }, 20528c2ecf20Sopenharmony_ci { {0x61, 0x30, 0x03, 0x11, 0x10} }, 20538c2ecf20Sopenharmony_ci { {0x61, 0x20, 0x03, 0x11, 0x10} }, 20548c2ecf20Sopenharmony_ci { {0x61, 0x10, 0x03, 0x11, 0x10} }, /* case-110 */ 20558c2ecf20Sopenharmony_ci { {0x61, 0x08, 0x03, 0x11, 0x14} }, 20568c2ecf20Sopenharmony_ci { {0x61, 0x08, 0x03, 0x10, 0x14} }, 20578c2ecf20Sopenharmony_ci { {0x51, 0x08, 0x03, 0x10, 0x54} }, 20588c2ecf20Sopenharmony_ci { {0x51, 0x08, 0x03, 0x10, 0x55} }, 20598c2ecf20Sopenharmony_ci { {0x51, 0x08, 0x07, 0x10, 0x54} }, /* case-115 */ 20608c2ecf20Sopenharmony_ci { {0x51, 0x45, 0x03, 0x10, 0x50} }, 20618c2ecf20Sopenharmony_ci { {0x51, 0x3a, 0x03, 0x10, 0x50} }, 20628c2ecf20Sopenharmony_ci { {0x51, 0x30, 0x03, 0x10, 0x50} }, 20638c2ecf20Sopenharmony_ci { {0x51, 0x20, 0x03, 0x10, 0x50} }, 20648c2ecf20Sopenharmony_ci { {0x51, 0x10, 0x03, 0x10, 0x50} }, /* case-120 */ 20658c2ecf20Sopenharmony_ci { {0x51, 0x08, 0x03, 0x10, 0x50} }, 20668c2ecf20Sopenharmony_ci}; 20678c2ecf20Sopenharmony_ci 20688c2ecf20Sopenharmony_ci/* rssi in percentage % (dbm = % - 100) */ 20698c2ecf20Sopenharmony_cistatic const u8 wl_rssi_step_8723d[] = {60, 50, 44, 30}; 20708c2ecf20Sopenharmony_cistatic const u8 bt_rssi_step_8723d[] = {30, 30, 30, 30}; 20718c2ecf20Sopenharmony_cistatic const struct coex_5g_afh_map afh_5g_8723d[] = { {0, 0, 0} }; 20728c2ecf20Sopenharmony_ci 20738c2ecf20Sopenharmony_cistatic const struct rtw_hw_reg btg_reg_8723d = { 20748c2ecf20Sopenharmony_ci .addr = REG_BTG_SEL, .mask = BIT_MASK_BTG_WL, 20758c2ecf20Sopenharmony_ci}; 20768c2ecf20Sopenharmony_ci 20778c2ecf20Sopenharmony_ci/* wl_tx_dec_power, bt_tx_dec_power, wl_rx_gain, bt_rx_lna_constrain */ 20788c2ecf20Sopenharmony_cistatic const struct coex_rf_para rf_para_tx_8723d[] = { 20798c2ecf20Sopenharmony_ci {0, 0, false, 7}, /* for normal */ 20808c2ecf20Sopenharmony_ci {0, 10, false, 7}, /* for WL-CPT */ 20818c2ecf20Sopenharmony_ci {1, 0, true, 4}, 20828c2ecf20Sopenharmony_ci {1, 2, true, 4}, 20838c2ecf20Sopenharmony_ci {1, 10, true, 4}, 20848c2ecf20Sopenharmony_ci {1, 15, true, 4} 20858c2ecf20Sopenharmony_ci}; 20868c2ecf20Sopenharmony_ci 20878c2ecf20Sopenharmony_cistatic const struct coex_rf_para rf_para_rx_8723d[] = { 20888c2ecf20Sopenharmony_ci {0, 0, false, 7}, /* for normal */ 20898c2ecf20Sopenharmony_ci {0, 10, false, 7}, /* for WL-CPT */ 20908c2ecf20Sopenharmony_ci {1, 0, true, 5}, 20918c2ecf20Sopenharmony_ci {1, 2, true, 5}, 20928c2ecf20Sopenharmony_ci {1, 10, true, 5}, 20938c2ecf20Sopenharmony_ci {1, 15, true, 5} 20948c2ecf20Sopenharmony_ci}; 20958c2ecf20Sopenharmony_ci 20968c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8723d[] = { 20978c2ecf20Sopenharmony_ci {0x0005, 20988c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 20998c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21008c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21018c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(3) | BIT(7), 0}, 21028c2ecf20Sopenharmony_ci {0x0086, 21038c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21048c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 21058c2ecf20Sopenharmony_ci RTW_PWR_ADDR_SDIO, 21068c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 21078c2ecf20Sopenharmony_ci {0x0086, 21088c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21098c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 21108c2ecf20Sopenharmony_ci RTW_PWR_ADDR_SDIO, 21118c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, 21128c2ecf20Sopenharmony_ci {0x004A, 21138c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21148c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK, 21158c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21168c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 21178c2ecf20Sopenharmony_ci {0x0005, 21188c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21198c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21208c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21218c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), 0}, 21228c2ecf20Sopenharmony_ci {0x0023, 21238c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21248c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 21258c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21268c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(4), 0}, 21278c2ecf20Sopenharmony_ci {0x0301, 21288c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21298c2ecf20Sopenharmony_ci RTW_PWR_INTF_PCI_MSK, 21308c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21318c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0}, 21328c2ecf20Sopenharmony_ci {0xFFFF, 21338c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21348c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21358c2ecf20Sopenharmony_ci 0, 21368c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 21378c2ecf20Sopenharmony_ci}; 21388c2ecf20Sopenharmony_ci 21398c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_cardemu_to_act_8723d[] = { 21408c2ecf20Sopenharmony_ci {0x0020, 21418c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21428c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, 21438c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21448c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 21458c2ecf20Sopenharmony_ci {0x0001, 21468c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21478c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, 21488c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21498c2ecf20Sopenharmony_ci RTW_PWR_CMD_DELAY, 1, RTW_PWR_DELAY_MS}, 21508c2ecf20Sopenharmony_ci {0x0000, 21518c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21528c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, 21538c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21548c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(5), 0}, 21558c2ecf20Sopenharmony_ci {0x0005, 21568c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21578c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21588c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21598c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0}, 21608c2ecf20Sopenharmony_ci {0x0075, 21618c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21628c2ecf20Sopenharmony_ci RTW_PWR_INTF_PCI_MSK, 21638c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21648c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 21658c2ecf20Sopenharmony_ci {0x0006, 21668c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21678c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21688c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21698c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, BIT(1), BIT(1)}, 21708c2ecf20Sopenharmony_ci {0x0075, 21718c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21728c2ecf20Sopenharmony_ci RTW_PWR_INTF_PCI_MSK, 21738c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21748c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 21758c2ecf20Sopenharmony_ci {0x0006, 21768c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21778c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21788c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21798c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 21808c2ecf20Sopenharmony_ci {0x0005, 21818c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21828c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21838c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21848c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, (BIT(1) | BIT(0)), 0}, 21858c2ecf20Sopenharmony_ci {0x0005, 21868c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21878c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21888c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21898c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(7), 0}, 21908c2ecf20Sopenharmony_ci {0x0005, 21918c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21928c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21938c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21948c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3)), 0}, 21958c2ecf20Sopenharmony_ci {0x0005, 21968c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 21978c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 21988c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 21998c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 22008c2ecf20Sopenharmony_ci {0x0005, 22018c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22028c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22038c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22048c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, BIT(0), 0}, 22058c2ecf20Sopenharmony_ci {0x0010, 22068c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22078c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22088c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22098c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(6), BIT(6)}, 22108c2ecf20Sopenharmony_ci {0x0049, 22118c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22128c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22138c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22148c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, 22158c2ecf20Sopenharmony_ci {0x0063, 22168c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22178c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22188c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22198c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, 22208c2ecf20Sopenharmony_ci {0x0062, 22218c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22228c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22238c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22248c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), 0}, 22258c2ecf20Sopenharmony_ci {0x0058, 22268c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22278c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22288c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22298c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 22308c2ecf20Sopenharmony_ci {0x005A, 22318c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22328c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22338c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22348c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, 22358c2ecf20Sopenharmony_ci {0x0068, 22368c2ecf20Sopenharmony_ci RTW_PWR_CUT_TEST_MSK, 22378c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22388c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22398c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(3), BIT(3)}, 22408c2ecf20Sopenharmony_ci {0x0069, 22418c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22428c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22438c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22448c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(6), BIT(6)}, 22458c2ecf20Sopenharmony_ci {0x001f, 22468c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22478c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22488c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22498c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x00}, 22508c2ecf20Sopenharmony_ci {0x0077, 22518c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22528c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22538c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22548c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x00}, 22558c2ecf20Sopenharmony_ci {0x001f, 22568c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22578c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22588c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22598c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x07}, 22608c2ecf20Sopenharmony_ci {0x0077, 22618c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22628c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22638c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22648c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x07}, 22658c2ecf20Sopenharmony_ci {0xFFFF, 22668c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22678c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22688c2ecf20Sopenharmony_ci 0, 22698c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 22708c2ecf20Sopenharmony_ci}; 22718c2ecf20Sopenharmony_ci 22728c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd *card_enable_flow_8723d[] = { 22738c2ecf20Sopenharmony_ci trans_carddis_to_cardemu_8723d, 22748c2ecf20Sopenharmony_ci trans_cardemu_to_act_8723d, 22758c2ecf20Sopenharmony_ci NULL 22768c2ecf20Sopenharmony_ci}; 22778c2ecf20Sopenharmony_ci 22788c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_act_to_lps_8723d[] = { 22798c2ecf20Sopenharmony_ci {0x0301, 22808c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22818c2ecf20Sopenharmony_ci RTW_PWR_INTF_PCI_MSK, 22828c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22838c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0xFF}, 22848c2ecf20Sopenharmony_ci {0x0522, 22858c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22868c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22878c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22888c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0xFF}, 22898c2ecf20Sopenharmony_ci {0x05F8, 22908c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22918c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22928c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22938c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, 0xFF, 0}, 22948c2ecf20Sopenharmony_ci {0x05F9, 22958c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 22968c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 22978c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 22988c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, 0xFF, 0}, 22998c2ecf20Sopenharmony_ci {0x05FA, 23008c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23018c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23028c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23038c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, 0xFF, 0}, 23048c2ecf20Sopenharmony_ci {0x05FB, 23058c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23068c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23078c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23088c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, 0xFF, 0}, 23098c2ecf20Sopenharmony_ci {0x0002, 23108c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23118c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23128c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23138c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 23148c2ecf20Sopenharmony_ci {0x0002, 23158c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23168c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23178c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23188c2ecf20Sopenharmony_ci RTW_PWR_CMD_DELAY, 0, RTW_PWR_DELAY_US}, 23198c2ecf20Sopenharmony_ci {0x0002, 23208c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23218c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23228c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23238c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), 0}, 23248c2ecf20Sopenharmony_ci {0x0100, 23258c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23268c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23278c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23288c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x03}, 23298c2ecf20Sopenharmony_ci {0x0101, 23308c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23318c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23328c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23338c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), 0}, 23348c2ecf20Sopenharmony_ci {0x0093, 23358c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23368c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 23378c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23388c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x00}, 23398c2ecf20Sopenharmony_ci {0x0553, 23408c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23418c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23428c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23438c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(5), BIT(5)}, 23448c2ecf20Sopenharmony_ci {0xFFFF, 23458c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23468c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23478c2ecf20Sopenharmony_ci 0, 23488c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 23498c2ecf20Sopenharmony_ci}; 23508c2ecf20Sopenharmony_ci 23518c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_act_to_pre_carddis_8723d[] = { 23528c2ecf20Sopenharmony_ci {0x0003, 23538c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23548c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23558c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23568c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(2), 0}, 23578c2ecf20Sopenharmony_ci {0x0080, 23588c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23598c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23608c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23618c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0}, 23628c2ecf20Sopenharmony_ci {0xFFFF, 23638c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23648c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23658c2ecf20Sopenharmony_ci 0, 23668c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 23678c2ecf20Sopenharmony_ci}; 23688c2ecf20Sopenharmony_ci 23698c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_act_to_cardemu_8723d[] = { 23708c2ecf20Sopenharmony_ci {0x0002, 23718c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23728c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23738c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23748c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 23758c2ecf20Sopenharmony_ci {0x0049, 23768c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23778c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23788c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23798c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), 0}, 23808c2ecf20Sopenharmony_ci {0x0006, 23818c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23828c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23838c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23848c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 23858c2ecf20Sopenharmony_ci {0x0005, 23868c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23878c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23888c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23898c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(1), BIT(1)}, 23908c2ecf20Sopenharmony_ci {0x0005, 23918c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23928c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23938c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23948c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, BIT(1), 0}, 23958c2ecf20Sopenharmony_ci {0x0010, 23968c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 23978c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 23988c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 23998c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(6), 0}, 24008c2ecf20Sopenharmony_ci {0x0000, 24018c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24028c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, 24038c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24048c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(5), BIT(5)}, 24058c2ecf20Sopenharmony_ci {0x0020, 24068c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24078c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, 24088c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24098c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 24108c2ecf20Sopenharmony_ci {0xFFFF, 24118c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24128c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 24138c2ecf20Sopenharmony_ci 0, 24148c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 24158c2ecf20Sopenharmony_ci}; 24168c2ecf20Sopenharmony_ci 24178c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_cardemu_to_carddis_8723d[] = { 24188c2ecf20Sopenharmony_ci {0x0007, 24198c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24208c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 24218c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24228c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x20}, 24238c2ecf20Sopenharmony_ci {0x0005, 24248c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24258c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK, 24268c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24278c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)}, 24288c2ecf20Sopenharmony_ci {0x0005, 24298c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24308c2ecf20Sopenharmony_ci RTW_PWR_INTF_PCI_MSK, 24318c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24328c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(2), BIT(2)}, 24338c2ecf20Sopenharmony_ci {0x0005, 24348c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24358c2ecf20Sopenharmony_ci RTW_PWR_INTF_PCI_MSK, 24368c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24378c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3) | BIT(4)}, 24388c2ecf20Sopenharmony_ci {0x004A, 24398c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24408c2ecf20Sopenharmony_ci RTW_PWR_INTF_USB_MSK, 24418c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24428c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 1}, 24438c2ecf20Sopenharmony_ci {0x0023, 24448c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24458c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 24468c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24478c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(4), BIT(4)}, 24488c2ecf20Sopenharmony_ci {0x0086, 24498c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24508c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 24518c2ecf20Sopenharmony_ci RTW_PWR_ADDR_SDIO, 24528c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 24538c2ecf20Sopenharmony_ci {0x0086, 24548c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24558c2ecf20Sopenharmony_ci RTW_PWR_INTF_SDIO_MSK, 24568c2ecf20Sopenharmony_ci RTW_PWR_ADDR_SDIO, 24578c2ecf20Sopenharmony_ci RTW_PWR_CMD_POLLING, BIT(1), 0}, 24588c2ecf20Sopenharmony_ci {0xFFFF, 24598c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24608c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 24618c2ecf20Sopenharmony_ci 0, 24628c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 24638c2ecf20Sopenharmony_ci}; 24648c2ecf20Sopenharmony_ci 24658c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd trans_act_to_post_carddis_8723d[] = { 24668c2ecf20Sopenharmony_ci {0x001D, 24678c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24688c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 24698c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24708c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), 0}, 24718c2ecf20Sopenharmony_ci {0x001D, 24728c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24738c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 24748c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24758c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, BIT(0), BIT(0)}, 24768c2ecf20Sopenharmony_ci {0x001C, 24778c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24788c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 24798c2ecf20Sopenharmony_ci RTW_PWR_ADDR_MAC, 24808c2ecf20Sopenharmony_ci RTW_PWR_CMD_WRITE, 0xFF, 0x0E}, 24818c2ecf20Sopenharmony_ci {0xFFFF, 24828c2ecf20Sopenharmony_ci RTW_PWR_CUT_ALL_MSK, 24838c2ecf20Sopenharmony_ci RTW_PWR_INTF_ALL_MSK, 24848c2ecf20Sopenharmony_ci 0, 24858c2ecf20Sopenharmony_ci RTW_PWR_CMD_END, 0, 0}, 24868c2ecf20Sopenharmony_ci}; 24878c2ecf20Sopenharmony_ci 24888c2ecf20Sopenharmony_cistatic const struct rtw_pwr_seq_cmd *card_disable_flow_8723d[] = { 24898c2ecf20Sopenharmony_ci trans_act_to_lps_8723d, 24908c2ecf20Sopenharmony_ci trans_act_to_pre_carddis_8723d, 24918c2ecf20Sopenharmony_ci trans_act_to_cardemu_8723d, 24928c2ecf20Sopenharmony_ci trans_cardemu_to_carddis_8723d, 24938c2ecf20Sopenharmony_ci trans_act_to_post_carddis_8723d, 24948c2ecf20Sopenharmony_ci NULL 24958c2ecf20Sopenharmony_ci}; 24968c2ecf20Sopenharmony_ci 24978c2ecf20Sopenharmony_cistatic const struct rtw_page_table page_table_8723d[] = { 24988c2ecf20Sopenharmony_ci {12, 2, 2, 0, 1}, 24998c2ecf20Sopenharmony_ci {12, 2, 2, 0, 1}, 25008c2ecf20Sopenharmony_ci {12, 2, 2, 0, 1}, 25018c2ecf20Sopenharmony_ci {12, 2, 2, 0, 1}, 25028c2ecf20Sopenharmony_ci {12, 2, 2, 0, 1}, 25038c2ecf20Sopenharmony_ci}; 25048c2ecf20Sopenharmony_ci 25058c2ecf20Sopenharmony_cistatic const struct rtw_rqpn rqpn_table_8723d[] = { 25068c2ecf20Sopenharmony_ci {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, 25078c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, 25088c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH}, 25098c2ecf20Sopenharmony_ci {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, 25108c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, 25118c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH}, 25128c2ecf20Sopenharmony_ci {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, 25138c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_HIGH, 25148c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, 25158c2ecf20Sopenharmony_ci {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, 25168c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, 25178c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH}, 25188c2ecf20Sopenharmony_ci {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL, 25198c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW, 25208c2ecf20Sopenharmony_ci RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH}, 25218c2ecf20Sopenharmony_ci}; 25228c2ecf20Sopenharmony_ci 25238c2ecf20Sopenharmony_cistatic const struct rtw_prioq_addrs prioq_addrs_8723d = { 25248c2ecf20Sopenharmony_ci .prio[RTW_DMA_MAPPING_EXTRA] = { 25258c2ecf20Sopenharmony_ci .rsvd = REG_RQPN_NPQ + 2, .avail = REG_RQPN_NPQ + 3, 25268c2ecf20Sopenharmony_ci }, 25278c2ecf20Sopenharmony_ci .prio[RTW_DMA_MAPPING_LOW] = { 25288c2ecf20Sopenharmony_ci .rsvd = REG_RQPN + 1, .avail = REG_FIFOPAGE_CTRL_2 + 1, 25298c2ecf20Sopenharmony_ci }, 25308c2ecf20Sopenharmony_ci .prio[RTW_DMA_MAPPING_NORMAL] = { 25318c2ecf20Sopenharmony_ci .rsvd = REG_RQPN_NPQ, .avail = REG_RQPN_NPQ + 1, 25328c2ecf20Sopenharmony_ci }, 25338c2ecf20Sopenharmony_ci .prio[RTW_DMA_MAPPING_HIGH] = { 25348c2ecf20Sopenharmony_ci .rsvd = REG_RQPN, .avail = REG_FIFOPAGE_CTRL_2, 25358c2ecf20Sopenharmony_ci }, 25368c2ecf20Sopenharmony_ci .wsize = false, 25378c2ecf20Sopenharmony_ci}; 25388c2ecf20Sopenharmony_ci 25398c2ecf20Sopenharmony_cistatic const struct rtw_intf_phy_para pcie_gen1_param_8723d[] = { 25408c2ecf20Sopenharmony_ci {0x0008, 0x4a22, 25418c2ecf20Sopenharmony_ci RTW_IP_SEL_PHY, 25428c2ecf20Sopenharmony_ci RTW_INTF_PHY_CUT_ALL, 25438c2ecf20Sopenharmony_ci RTW_INTF_PHY_PLATFORM_ALL}, 25448c2ecf20Sopenharmony_ci {0x0009, 0x1000, 25458c2ecf20Sopenharmony_ci RTW_IP_SEL_PHY, 25468c2ecf20Sopenharmony_ci ~(RTW_INTF_PHY_CUT_A | RTW_INTF_PHY_CUT_B), 25478c2ecf20Sopenharmony_ci RTW_INTF_PHY_PLATFORM_ALL}, 25488c2ecf20Sopenharmony_ci {0xFFFF, 0x0000, 25498c2ecf20Sopenharmony_ci RTW_IP_SEL_PHY, 25508c2ecf20Sopenharmony_ci RTW_INTF_PHY_CUT_ALL, 25518c2ecf20Sopenharmony_ci RTW_INTF_PHY_PLATFORM_ALL}, 25528c2ecf20Sopenharmony_ci}; 25538c2ecf20Sopenharmony_ci 25548c2ecf20Sopenharmony_cistatic const struct rtw_intf_phy_para_table phy_para_table_8723d = { 25558c2ecf20Sopenharmony_ci .gen1_para = pcie_gen1_param_8723d, 25568c2ecf20Sopenharmony_ci .n_gen1_para = ARRAY_SIZE(pcie_gen1_param_8723d), 25578c2ecf20Sopenharmony_ci}; 25588c2ecf20Sopenharmony_ci 25598c2ecf20Sopenharmony_cistatic const struct rtw_hw_reg rtw8723d_dig[] = { 25608c2ecf20Sopenharmony_ci [0] = { .addr = 0xc50, .mask = 0x7f }, 25618c2ecf20Sopenharmony_ci [1] = { .addr = 0xc50, .mask = 0x7f }, 25628c2ecf20Sopenharmony_ci}; 25638c2ecf20Sopenharmony_ci 25648c2ecf20Sopenharmony_cistatic const struct rtw_hw_reg rtw8723d_dig_cck[] = { 25658c2ecf20Sopenharmony_ci [0] = { .addr = 0xa0c, .mask = 0x3f00 }, 25668c2ecf20Sopenharmony_ci}; 25678c2ecf20Sopenharmony_ci 25688c2ecf20Sopenharmony_cistatic const struct rtw_rf_sipi_addr rtw8723d_rf_sipi_addr[] = { 25698c2ecf20Sopenharmony_ci [RF_PATH_A] = { .hssi_1 = 0x820, .lssi_read = 0x8a0, 25708c2ecf20Sopenharmony_ci .hssi_2 = 0x824, .lssi_read_pi = 0x8b8}, 25718c2ecf20Sopenharmony_ci [RF_PATH_B] = { .hssi_1 = 0x828, .lssi_read = 0x8a4, 25728c2ecf20Sopenharmony_ci .hssi_2 = 0x82c, .lssi_read_pi = 0x8bc}, 25738c2ecf20Sopenharmony_ci}; 25748c2ecf20Sopenharmony_ci 25758c2ecf20Sopenharmony_cistatic const struct rtw_ltecoex_addr rtw8723d_ltecoex_addr = { 25768c2ecf20Sopenharmony_ci .ctrl = REG_LTECOEX_CTRL, 25778c2ecf20Sopenharmony_ci .wdata = REG_LTECOEX_WRITE_DATA, 25788c2ecf20Sopenharmony_ci .rdata = REG_LTECOEX_READ_DATA, 25798c2ecf20Sopenharmony_ci}; 25808c2ecf20Sopenharmony_ci 25818c2ecf20Sopenharmony_cistatic const struct rtw_rfe_def rtw8723d_rfe_defs[] = { 25828c2ecf20Sopenharmony_ci [0] = { .phy_pg_tbl = &rtw8723d_bb_pg_tbl, 25838c2ecf20Sopenharmony_ci .txpwr_lmt_tbl = &rtw8723d_txpwr_lmt_tbl,}, 25848c2ecf20Sopenharmony_ci}; 25858c2ecf20Sopenharmony_ci 25868c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2gb_n[] = { 25878c2ecf20Sopenharmony_ci 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 25888c2ecf20Sopenharmony_ci 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 25898c2ecf20Sopenharmony_ci}; 25908c2ecf20Sopenharmony_ci 25918c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2gb_p[] = { 25928c2ecf20Sopenharmony_ci 0, 0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 25938c2ecf20Sopenharmony_ci 7, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10 25948c2ecf20Sopenharmony_ci}; 25958c2ecf20Sopenharmony_ci 25968c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2ga_n[] = { 25978c2ecf20Sopenharmony_ci 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 25988c2ecf20Sopenharmony_ci 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 25998c2ecf20Sopenharmony_ci}; 26008c2ecf20Sopenharmony_ci 26018c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2ga_p[] = { 26028c2ecf20Sopenharmony_ci 0, 0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 26038c2ecf20Sopenharmony_ci 7, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10 26048c2ecf20Sopenharmony_ci}; 26058c2ecf20Sopenharmony_ci 26068c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2g_cck_b_n[] = { 26078c2ecf20Sopenharmony_ci 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 26088c2ecf20Sopenharmony_ci 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11 26098c2ecf20Sopenharmony_ci}; 26108c2ecf20Sopenharmony_ci 26118c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2g_cck_b_p[] = { 26128c2ecf20Sopenharmony_ci 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 26138c2ecf20Sopenharmony_ci 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11 26148c2ecf20Sopenharmony_ci}; 26158c2ecf20Sopenharmony_ci 26168c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2g_cck_a_n[] = { 26178c2ecf20Sopenharmony_ci 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 26188c2ecf20Sopenharmony_ci 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11 26198c2ecf20Sopenharmony_ci}; 26208c2ecf20Sopenharmony_ci 26218c2ecf20Sopenharmony_cistatic const u8 rtw8723d_pwrtrk_2g_cck_a_p[] = { 26228c2ecf20Sopenharmony_ci 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 26238c2ecf20Sopenharmony_ci 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11 26248c2ecf20Sopenharmony_ci}; 26258c2ecf20Sopenharmony_ci 26268c2ecf20Sopenharmony_cistatic const s8 rtw8723d_pwrtrk_xtal_n[] = { 26278c2ecf20Sopenharmony_ci 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26288c2ecf20Sopenharmony_ci 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 26298c2ecf20Sopenharmony_ci}; 26308c2ecf20Sopenharmony_ci 26318c2ecf20Sopenharmony_cistatic const s8 rtw8723d_pwrtrk_xtal_p[] = { 26328c2ecf20Sopenharmony_ci 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26338c2ecf20Sopenharmony_ci 0, -10, -12, -14, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16 26348c2ecf20Sopenharmony_ci}; 26358c2ecf20Sopenharmony_ci 26368c2ecf20Sopenharmony_cistatic const struct rtw_pwr_track_tbl rtw8723d_rtw_pwr_track_tbl = { 26378c2ecf20Sopenharmony_ci .pwrtrk_2gb_n = rtw8723d_pwrtrk_2gb_n, 26388c2ecf20Sopenharmony_ci .pwrtrk_2gb_p = rtw8723d_pwrtrk_2gb_p, 26398c2ecf20Sopenharmony_ci .pwrtrk_2ga_n = rtw8723d_pwrtrk_2ga_n, 26408c2ecf20Sopenharmony_ci .pwrtrk_2ga_p = rtw8723d_pwrtrk_2ga_p, 26418c2ecf20Sopenharmony_ci .pwrtrk_2g_cckb_n = rtw8723d_pwrtrk_2g_cck_b_n, 26428c2ecf20Sopenharmony_ci .pwrtrk_2g_cckb_p = rtw8723d_pwrtrk_2g_cck_b_p, 26438c2ecf20Sopenharmony_ci .pwrtrk_2g_ccka_n = rtw8723d_pwrtrk_2g_cck_a_n, 26448c2ecf20Sopenharmony_ci .pwrtrk_2g_ccka_p = rtw8723d_pwrtrk_2g_cck_a_p, 26458c2ecf20Sopenharmony_ci .pwrtrk_xtal_p = rtw8723d_pwrtrk_xtal_p, 26468c2ecf20Sopenharmony_ci .pwrtrk_xtal_n = rtw8723d_pwrtrk_xtal_n, 26478c2ecf20Sopenharmony_ci}; 26488c2ecf20Sopenharmony_ci 26498c2ecf20Sopenharmony_cistatic const struct rtw_reg_domain coex_info_hw_regs_8723d[] = { 26508c2ecf20Sopenharmony_ci {0x948, MASKDWORD, RTW_REG_DOMAIN_MAC32}, 26518c2ecf20Sopenharmony_ci {0x67, BIT(7), RTW_REG_DOMAIN_MAC8}, 26528c2ecf20Sopenharmony_ci {0, 0, RTW_REG_DOMAIN_NL}, 26538c2ecf20Sopenharmony_ci {0x964, BIT(1), RTW_REG_DOMAIN_MAC8}, 26548c2ecf20Sopenharmony_ci {0x864, BIT(0), RTW_REG_DOMAIN_MAC8}, 26558c2ecf20Sopenharmony_ci {0xab7, BIT(5), RTW_REG_DOMAIN_MAC8}, 26568c2ecf20Sopenharmony_ci {0xa01, BIT(7), RTW_REG_DOMAIN_MAC8}, 26578c2ecf20Sopenharmony_ci {0, 0, RTW_REG_DOMAIN_NL}, 26588c2ecf20Sopenharmony_ci {0x430, MASKDWORD, RTW_REG_DOMAIN_MAC32}, 26598c2ecf20Sopenharmony_ci {0x434, MASKDWORD, RTW_REG_DOMAIN_MAC32}, 26608c2ecf20Sopenharmony_ci {0x42a, MASKLWORD, RTW_REG_DOMAIN_MAC16}, 26618c2ecf20Sopenharmony_ci {0x426, MASKBYTE0, RTW_REG_DOMAIN_MAC8}, 26628c2ecf20Sopenharmony_ci {0x45e, BIT(3), RTW_REG_DOMAIN_MAC8}, 26638c2ecf20Sopenharmony_ci {0, 0, RTW_REG_DOMAIN_NL}, 26648c2ecf20Sopenharmony_ci {0x4c6, BIT(4), RTW_REG_DOMAIN_MAC8}, 26658c2ecf20Sopenharmony_ci {0x40, BIT(5), RTW_REG_DOMAIN_MAC8}, 26668c2ecf20Sopenharmony_ci {0x550, MASKDWORD, RTW_REG_DOMAIN_MAC32}, 26678c2ecf20Sopenharmony_ci {0x522, MASKBYTE0, RTW_REG_DOMAIN_MAC8}, 26688c2ecf20Sopenharmony_ci {0x953, BIT(1), RTW_REG_DOMAIN_MAC8}, 26698c2ecf20Sopenharmony_ci}; 26708c2ecf20Sopenharmony_ci 26718c2ecf20Sopenharmony_cistruct rtw_chip_info rtw8723d_hw_spec = { 26728c2ecf20Sopenharmony_ci .ops = &rtw8723d_ops, 26738c2ecf20Sopenharmony_ci .id = RTW_CHIP_TYPE_8723D, 26748c2ecf20Sopenharmony_ci .fw_name = "rtw88/rtw8723d_fw.bin", 26758c2ecf20Sopenharmony_ci .wlan_cpu = RTW_WCPU_11N, 26768c2ecf20Sopenharmony_ci .tx_pkt_desc_sz = 40, 26778c2ecf20Sopenharmony_ci .tx_buf_desc_sz = 16, 26788c2ecf20Sopenharmony_ci .rx_pkt_desc_sz = 24, 26798c2ecf20Sopenharmony_ci .rx_buf_desc_sz = 8, 26808c2ecf20Sopenharmony_ci .phy_efuse_size = 512, 26818c2ecf20Sopenharmony_ci .log_efuse_size = 512, 26828c2ecf20Sopenharmony_ci .ptct_efuse_size = 96 + 1, 26838c2ecf20Sopenharmony_ci .txff_size = 32768, 26848c2ecf20Sopenharmony_ci .rxff_size = 16384, 26858c2ecf20Sopenharmony_ci .txgi_factor = 1, 26868c2ecf20Sopenharmony_ci .is_pwr_by_rate_dec = true, 26878c2ecf20Sopenharmony_ci .max_power_index = 0x3f, 26888c2ecf20Sopenharmony_ci .csi_buf_pg_num = 0, 26898c2ecf20Sopenharmony_ci .band = RTW_BAND_2G, 26908c2ecf20Sopenharmony_ci .page_size = 128, 26918c2ecf20Sopenharmony_ci .dig_min = 0x20, 26928c2ecf20Sopenharmony_ci .ht_supported = true, 26938c2ecf20Sopenharmony_ci .vht_supported = false, 26948c2ecf20Sopenharmony_ci .lps_deep_mode_supported = 0, 26958c2ecf20Sopenharmony_ci .sys_func_en = 0xFD, 26968c2ecf20Sopenharmony_ci .pwr_on_seq = card_enable_flow_8723d, 26978c2ecf20Sopenharmony_ci .pwr_off_seq = card_disable_flow_8723d, 26988c2ecf20Sopenharmony_ci .page_table = page_table_8723d, 26998c2ecf20Sopenharmony_ci .rqpn_table = rqpn_table_8723d, 27008c2ecf20Sopenharmony_ci .prioq_addrs = &prioq_addrs_8723d, 27018c2ecf20Sopenharmony_ci .intf_table = &phy_para_table_8723d, 27028c2ecf20Sopenharmony_ci .dig = rtw8723d_dig, 27038c2ecf20Sopenharmony_ci .dig_cck = rtw8723d_dig_cck, 27048c2ecf20Sopenharmony_ci .rf_sipi_addr = {0x840, 0x844}, 27058c2ecf20Sopenharmony_ci .rf_sipi_read_addr = rtw8723d_rf_sipi_addr, 27068c2ecf20Sopenharmony_ci .fix_rf_phy_num = 2, 27078c2ecf20Sopenharmony_ci .ltecoex_addr = &rtw8723d_ltecoex_addr, 27088c2ecf20Sopenharmony_ci .mac_tbl = &rtw8723d_mac_tbl, 27098c2ecf20Sopenharmony_ci .agc_tbl = &rtw8723d_agc_tbl, 27108c2ecf20Sopenharmony_ci .bb_tbl = &rtw8723d_bb_tbl, 27118c2ecf20Sopenharmony_ci .rf_tbl = {&rtw8723d_rf_a_tbl}, 27128c2ecf20Sopenharmony_ci .rfe_defs = rtw8723d_rfe_defs, 27138c2ecf20Sopenharmony_ci .rfe_defs_size = ARRAY_SIZE(rtw8723d_rfe_defs), 27148c2ecf20Sopenharmony_ci .rx_ldpc = false, 27158c2ecf20Sopenharmony_ci .pwr_track_tbl = &rtw8723d_rtw_pwr_track_tbl, 27168c2ecf20Sopenharmony_ci .iqk_threshold = 8, 27178c2ecf20Sopenharmony_ci 27188c2ecf20Sopenharmony_ci .coex_para_ver = 0x2007022f, 27198c2ecf20Sopenharmony_ci .bt_desired_ver = 0x2f, 27208c2ecf20Sopenharmony_ci .scbd_support = true, 27218c2ecf20Sopenharmony_ci .new_scbd10_def = true, 27228c2ecf20Sopenharmony_ci .pstdma_type = COEX_PSTDMA_FORCE_LPSOFF, 27238c2ecf20Sopenharmony_ci .bt_rssi_type = COEX_BTRSSI_RATIO, 27248c2ecf20Sopenharmony_ci .ant_isolation = 15, 27258c2ecf20Sopenharmony_ci .rssi_tolerance = 2, 27268c2ecf20Sopenharmony_ci .wl_rssi_step = wl_rssi_step_8723d, 27278c2ecf20Sopenharmony_ci .bt_rssi_step = bt_rssi_step_8723d, 27288c2ecf20Sopenharmony_ci .table_sant_num = ARRAY_SIZE(table_sant_8723d), 27298c2ecf20Sopenharmony_ci .table_sant = table_sant_8723d, 27308c2ecf20Sopenharmony_ci .table_nsant_num = ARRAY_SIZE(table_nsant_8723d), 27318c2ecf20Sopenharmony_ci .table_nsant = table_nsant_8723d, 27328c2ecf20Sopenharmony_ci .tdma_sant_num = ARRAY_SIZE(tdma_sant_8723d), 27338c2ecf20Sopenharmony_ci .tdma_sant = tdma_sant_8723d, 27348c2ecf20Sopenharmony_ci .tdma_nsant_num = ARRAY_SIZE(tdma_nsant_8723d), 27358c2ecf20Sopenharmony_ci .tdma_nsant = tdma_nsant_8723d, 27368c2ecf20Sopenharmony_ci .wl_rf_para_num = ARRAY_SIZE(rf_para_tx_8723d), 27378c2ecf20Sopenharmony_ci .wl_rf_para_tx = rf_para_tx_8723d, 27388c2ecf20Sopenharmony_ci .wl_rf_para_rx = rf_para_rx_8723d, 27398c2ecf20Sopenharmony_ci .bt_afh_span_bw20 = 0x20, 27408c2ecf20Sopenharmony_ci .bt_afh_span_bw40 = 0x30, 27418c2ecf20Sopenharmony_ci .afh_5g_num = ARRAY_SIZE(afh_5g_8723d), 27428c2ecf20Sopenharmony_ci .afh_5g = afh_5g_8723d, 27438c2ecf20Sopenharmony_ci .btg_reg = &btg_reg_8723d, 27448c2ecf20Sopenharmony_ci 27458c2ecf20Sopenharmony_ci .coex_info_hw_regs_num = ARRAY_SIZE(coex_info_hw_regs_8723d), 27468c2ecf20Sopenharmony_ci .coex_info_hw_regs = coex_info_hw_regs_8723d, 27478c2ecf20Sopenharmony_ci}; 27488c2ecf20Sopenharmony_ciEXPORT_SYMBOL(rtw8723d_hw_spec); 27498c2ecf20Sopenharmony_ci 27508c2ecf20Sopenharmony_ciMODULE_FIRMWARE("rtw88/rtw8723d_fw.bin"); 27518c2ecf20Sopenharmony_ci 27528c2ecf20Sopenharmony_ciMODULE_AUTHOR("Realtek Corporation"); 27538c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Realtek 802.11n wireless 8723d driver"); 27548c2ecf20Sopenharmony_ciMODULE_LICENSE("Dual BSD/GPL"); 2755