18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2012 Realtek Corporation.*/ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include "../wifi.h" 58c2ecf20Sopenharmony_ci#include "reg.h" 68c2ecf20Sopenharmony_ci#include "def.h" 78c2ecf20Sopenharmony_ci#include "phy.h" 88c2ecf20Sopenharmony_ci#include "rf.h" 98c2ecf20Sopenharmony_ci#include "dm.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistatic bool _rtl8723e_phy_rf6052_config_parafile(struct ieee80211_hw *hw); 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_civoid rtl8723e_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 168c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci switch (bandwidth) { 198c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20: 208c2ecf20Sopenharmony_ci rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] & 218c2ecf20Sopenharmony_ci 0xfffff3ff) | 0x0400); 228c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK, 238c2ecf20Sopenharmony_ci rtlphy->rfreg_chnlval[0]); 248c2ecf20Sopenharmony_ci break; 258c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20_40: 268c2ecf20Sopenharmony_ci rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] & 278c2ecf20Sopenharmony_ci 0xfffff3ff)); 288c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK, 298c2ecf20Sopenharmony_ci rtlphy->rfreg_chnlval[0]); 308c2ecf20Sopenharmony_ci break; 318c2ecf20Sopenharmony_ci default: 328c2ecf20Sopenharmony_ci pr_err("unknown bandwidth: %#X\n", bandwidth); 338c2ecf20Sopenharmony_ci break; 348c2ecf20Sopenharmony_ci } 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_civoid rtl8723e_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 388c2ecf20Sopenharmony_ci u8 *ppowerlevel) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 418c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 428c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 438c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 448c2ecf20Sopenharmony_ci u32 tx_agc[2] = {0, 0}, tmpval; 458c2ecf20Sopenharmony_ci bool turbo_scanoff = false; 468c2ecf20Sopenharmony_ci u8 idx1, idx2; 478c2ecf20Sopenharmony_ci u8 *ptr; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci if (rtlefuse->eeprom_regulatory != 0) 508c2ecf20Sopenharmony_ci turbo_scanoff = true; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci if (mac->act_scanning) { 538c2ecf20Sopenharmony_ci tx_agc[RF90_PATH_A] = 0x3f3f3f3f; 548c2ecf20Sopenharmony_ci tx_agc[RF90_PATH_B] = 0x3f3f3f3f; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci if (turbo_scanoff) { 578c2ecf20Sopenharmony_ci for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; 588c2ecf20Sopenharmony_ci idx1++) { 598c2ecf20Sopenharmony_ci tx_agc[idx1] = ppowerlevel[idx1] | 608c2ecf20Sopenharmony_ci (ppowerlevel[idx1] << 8) | 618c2ecf20Sopenharmony_ci (ppowerlevel[idx1] << 16) | 628c2ecf20Sopenharmony_ci (ppowerlevel[idx1] << 24); 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci } 658c2ecf20Sopenharmony_ci } else { 668c2ecf20Sopenharmony_ci for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 678c2ecf20Sopenharmony_ci tx_agc[idx1] = ppowerlevel[idx1] | 688c2ecf20Sopenharmony_ci (ppowerlevel[idx1] << 8) | 698c2ecf20Sopenharmony_ci (ppowerlevel[idx1] << 16) | 708c2ecf20Sopenharmony_ci (ppowerlevel[idx1] << 24); 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci if (rtlefuse->eeprom_regulatory == 0) { 748c2ecf20Sopenharmony_ci tmpval = 758c2ecf20Sopenharmony_ci (rtlphy->mcs_txpwrlevel_origoffset[0][6]) + 768c2ecf20Sopenharmony_ci (rtlphy->mcs_txpwrlevel_origoffset[0][7] << 778c2ecf20Sopenharmony_ci 8); 788c2ecf20Sopenharmony_ci tx_agc[RF90_PATH_A] += tmpval; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci tmpval = (rtlphy->mcs_txpwrlevel_origoffset[0][14]) + 818c2ecf20Sopenharmony_ci (rtlphy->mcs_txpwrlevel_origoffset[0][15] << 828c2ecf20Sopenharmony_ci 24); 838c2ecf20Sopenharmony_ci tx_agc[RF90_PATH_B] += tmpval; 848c2ecf20Sopenharmony_ci } 858c2ecf20Sopenharmony_ci } 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 888c2ecf20Sopenharmony_ci ptr = (u8 *)&tx_agc[idx1]; 898c2ecf20Sopenharmony_ci for (idx2 = 0; idx2 < 4; idx2++) { 908c2ecf20Sopenharmony_ci if (*ptr > RF6052_MAX_TX_PWR) 918c2ecf20Sopenharmony_ci *ptr = RF6052_MAX_TX_PWR; 928c2ecf20Sopenharmony_ci ptr++; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci } 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci tmpval = tx_agc[RF90_PATH_A] & 0xff; 978c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, MASKBYTE1, tmpval); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1008c2ecf20Sopenharmony_ci "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 1018c2ecf20Sopenharmony_ci RTXAGC_A_CCK1_MCS32); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci tmpval = tx_agc[RF90_PATH_A] >> 8; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci tmpval = tmpval & 0xff00ffff; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1108c2ecf20Sopenharmony_ci "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 1118c2ecf20Sopenharmony_ci RTXAGC_B_CCK11_A_CCK2_11); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci tmpval = tx_agc[RF90_PATH_B] >> 24; 1148c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, MASKBYTE0, tmpval); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1178c2ecf20Sopenharmony_ci "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 1188c2ecf20Sopenharmony_ci RTXAGC_B_CCK11_A_CCK2_11); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff; 1218c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1248c2ecf20Sopenharmony_ci "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 1258c2ecf20Sopenharmony_ci RTXAGC_B_CCK1_55_MCS32); 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic void rtl8723e_phy_get_power_base(struct ieee80211_hw *hw, 1298c2ecf20Sopenharmony_ci u8 *ppowerlevel, u8 channel, 1308c2ecf20Sopenharmony_ci u32 *ofdmbase, u32 *mcsbase) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1338c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 1348c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1358c2ecf20Sopenharmony_ci u32 powerbase0, powerbase1; 1368c2ecf20Sopenharmony_ci u8 legacy_pwrdiff, ht20_pwrdiff; 1378c2ecf20Sopenharmony_ci u8 i, powerlevel[2]; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci for (i = 0; i < 2; i++) { 1408c2ecf20Sopenharmony_ci powerlevel[i] = ppowerlevel[i]; 1418c2ecf20Sopenharmony_ci legacy_pwrdiff = rtlefuse->txpwr_legacyhtdiff[i][channel - 1]; 1428c2ecf20Sopenharmony_ci powerbase0 = powerlevel[i] + legacy_pwrdiff; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) | 1458c2ecf20Sopenharmony_ci (powerbase0 << 8) | powerbase0; 1468c2ecf20Sopenharmony_ci *(ofdmbase + i) = powerbase0; 1478c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1488c2ecf20Sopenharmony_ci " [OFDM power base index rf(%c) = 0x%x]\n", 1498c2ecf20Sopenharmony_ci ((i == 0) ? 'A' : 'B'), *(ofdmbase + i)); 1508c2ecf20Sopenharmony_ci } 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci for (i = 0; i < 2; i++) { 1538c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) { 1548c2ecf20Sopenharmony_ci ht20_pwrdiff = 1558c2ecf20Sopenharmony_ci rtlefuse->txpwr_ht20diff[i][channel - 1]; 1568c2ecf20Sopenharmony_ci powerlevel[i] += ht20_pwrdiff; 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci powerbase1 = powerlevel[i]; 1598c2ecf20Sopenharmony_ci powerbase1 = (powerbase1 << 24) | 1608c2ecf20Sopenharmony_ci (powerbase1 << 16) | (powerbase1 << 8) | powerbase1; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci *(mcsbase + i) = powerbase1; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1658c2ecf20Sopenharmony_ci " [MCS power base index rf(%c) = 0x%x]\n", 1668c2ecf20Sopenharmony_ci ((i == 0) ? 'A' : 'B'), *(mcsbase + i)); 1678c2ecf20Sopenharmony_ci } 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic void get_txpower_writeval_by_reg(struct ieee80211_hw *hw, 1718c2ecf20Sopenharmony_ci u8 channel, u8 index, 1728c2ecf20Sopenharmony_ci u32 *powerbase0, 1738c2ecf20Sopenharmony_ci u32 *powerbase1, 1748c2ecf20Sopenharmony_ci u32 *p_outwriteval) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1778c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 1788c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1798c2ecf20Sopenharmony_ci u8 i, chnlgroup = 0, pwr_diff_limit[4]; 1808c2ecf20Sopenharmony_ci u32 writeval, customer_limit, rf; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci for (rf = 0; rf < 2; rf++) { 1838c2ecf20Sopenharmony_ci switch (rtlefuse->eeprom_regulatory) { 1848c2ecf20Sopenharmony_ci case 0: 1858c2ecf20Sopenharmony_ci chnlgroup = 0; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci writeval = 1888c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[chnlgroup][index + 1898c2ecf20Sopenharmony_ci (rf ? 8 : 0)] 1908c2ecf20Sopenharmony_ci + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1938c2ecf20Sopenharmony_ci "RTK better performance, writeval(%c) = 0x%x\n", 1948c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 1958c2ecf20Sopenharmony_ci break; 1968c2ecf20Sopenharmony_ci case 1: 1978c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) { 1988c2ecf20Sopenharmony_ci writeval = ((index < 2) ? powerbase0[rf] : 1998c2ecf20Sopenharmony_ci powerbase1[rf]); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2028c2ecf20Sopenharmony_ci "Realtek regulatory, 40MHz, writeval(%c) = 0x%x\n", 2038c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2048c2ecf20Sopenharmony_ci } else { 2058c2ecf20Sopenharmony_ci if (rtlphy->pwrgroup_cnt == 1) 2068c2ecf20Sopenharmony_ci chnlgroup = 0; 2078c2ecf20Sopenharmony_ci if (rtlphy->pwrgroup_cnt >= 3) { 2088c2ecf20Sopenharmony_ci if (channel <= 3) 2098c2ecf20Sopenharmony_ci chnlgroup = 0; 2108c2ecf20Sopenharmony_ci else if (channel >= 4 && channel <= 9) 2118c2ecf20Sopenharmony_ci chnlgroup = 1; 2128c2ecf20Sopenharmony_ci else if (channel > 9) 2138c2ecf20Sopenharmony_ci chnlgroup = 2; 2148c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == 2158c2ecf20Sopenharmony_ci HT_CHANNEL_WIDTH_20) 2168c2ecf20Sopenharmony_ci chnlgroup++; 2178c2ecf20Sopenharmony_ci else 2188c2ecf20Sopenharmony_ci chnlgroup += 4; 2198c2ecf20Sopenharmony_ci } 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci writeval = 2228c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 2238c2ecf20Sopenharmony_ci [index + (rf ? 8 : 0)] + ((index < 2) ? 2248c2ecf20Sopenharmony_ci powerbase0[rf] : 2258c2ecf20Sopenharmony_ci powerbase1[rf]); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2288c2ecf20Sopenharmony_ci "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n", 2298c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2308c2ecf20Sopenharmony_ci } 2318c2ecf20Sopenharmony_ci break; 2328c2ecf20Sopenharmony_ci case 2: 2338c2ecf20Sopenharmony_ci writeval = 2348c2ecf20Sopenharmony_ci ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2378c2ecf20Sopenharmony_ci "Better regulatory, writeval(%c) = 0x%x\n", 2388c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2398c2ecf20Sopenharmony_ci break; 2408c2ecf20Sopenharmony_ci case 3: 2418c2ecf20Sopenharmony_ci chnlgroup = 0; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) { 2448c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2458c2ecf20Sopenharmony_ci "customer's limit, 40MHz rf(%c) = 0x%x\n", 2468c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), 2478c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht40[rf][channel - 2488c2ecf20Sopenharmony_ci 1]); 2498c2ecf20Sopenharmony_ci } else { 2508c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2518c2ecf20Sopenharmony_ci "customer's limit, 20MHz rf(%c) = 0x%x\n", 2528c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), 2538c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht20[rf][channel - 2548c2ecf20Sopenharmony_ci 1]); 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 2578c2ecf20Sopenharmony_ci pwr_diff_limit[i] = 2588c2ecf20Sopenharmony_ci (u8)((rtlphy->mcs_txpwrlevel_origoffset 2598c2ecf20Sopenharmony_ci [chnlgroup][index + 2608c2ecf20Sopenharmony_ci (rf ? 8 : 0)] & (0x7f << 2618c2ecf20Sopenharmony_ci (i * 8))) >> (i * 8)); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == 2648c2ecf20Sopenharmony_ci HT_CHANNEL_WIDTH_20_40) { 2658c2ecf20Sopenharmony_ci if (pwr_diff_limit[i] > 2668c2ecf20Sopenharmony_ci rtlefuse-> 2678c2ecf20Sopenharmony_ci pwrgroup_ht40[rf][channel - 1]) 2688c2ecf20Sopenharmony_ci pwr_diff_limit[i] = 2698c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht40[rf] 2708c2ecf20Sopenharmony_ci [channel - 1]; 2718c2ecf20Sopenharmony_ci } else { 2728c2ecf20Sopenharmony_ci if (pwr_diff_limit[i] > 2738c2ecf20Sopenharmony_ci rtlefuse-> 2748c2ecf20Sopenharmony_ci pwrgroup_ht20[rf][channel - 1]) 2758c2ecf20Sopenharmony_ci pwr_diff_limit[i] = 2768c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht20[rf] 2778c2ecf20Sopenharmony_ci [channel - 1]; 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci customer_limit = (pwr_diff_limit[3] << 24) | 2828c2ecf20Sopenharmony_ci (pwr_diff_limit[2] << 16) | 2838c2ecf20Sopenharmony_ci (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2868c2ecf20Sopenharmony_ci "Customer's limit rf(%c) = 0x%x\n", 2878c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), customer_limit); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci writeval = customer_limit + 2908c2ecf20Sopenharmony_ci ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2938c2ecf20Sopenharmony_ci "Customer, writeval rf(%c)= 0x%x\n", 2948c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2958c2ecf20Sopenharmony_ci break; 2968c2ecf20Sopenharmony_ci default: 2978c2ecf20Sopenharmony_ci chnlgroup = 0; 2988c2ecf20Sopenharmony_ci writeval = 2998c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 3008c2ecf20Sopenharmony_ci [index + (rf ? 8 : 0)] 3018c2ecf20Sopenharmony_ci + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 3048c2ecf20Sopenharmony_ci "RTK better performance, writeval rf(%c) = 0x%x\n", 3058c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 3068c2ecf20Sopenharmony_ci break; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1) 3108c2ecf20Sopenharmony_ci writeval = writeval - 0x06060606; 3118c2ecf20Sopenharmony_ci else if (rtlpriv->dm.dynamic_txhighpower_lvl == 3128c2ecf20Sopenharmony_ci TXHIGHPWRLEVEL_BT2) 3138c2ecf20Sopenharmony_ci writeval = writeval - 0x0c0c0c0c; 3148c2ecf20Sopenharmony_ci *(p_outwriteval + rf) = writeval; 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci} 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_cistatic void _rtl8723e_write_ofdm_power_reg(struct ieee80211_hw *hw, 3198c2ecf20Sopenharmony_ci u8 index, u32 *pvalue) 3208c2ecf20Sopenharmony_ci{ 3218c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3228c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci u16 regoffset_a[6] = { 3258c2ecf20Sopenharmony_ci RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24, 3268c2ecf20Sopenharmony_ci RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04, 3278c2ecf20Sopenharmony_ci RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12 3288c2ecf20Sopenharmony_ci }; 3298c2ecf20Sopenharmony_ci u16 regoffset_b[6] = { 3308c2ecf20Sopenharmony_ci RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24, 3318c2ecf20Sopenharmony_ci RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04, 3328c2ecf20Sopenharmony_ci RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12 3338c2ecf20Sopenharmony_ci }; 3348c2ecf20Sopenharmony_ci u8 i, rf, pwr_val[4]; 3358c2ecf20Sopenharmony_ci u32 writeval; 3368c2ecf20Sopenharmony_ci u16 regoffset; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci for (rf = 0; rf < 2; rf++) { 3398c2ecf20Sopenharmony_ci writeval = pvalue[rf]; 3408c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 3418c2ecf20Sopenharmony_ci pwr_val[i] = (u8)((writeval & (0x7f << 3428c2ecf20Sopenharmony_ci (i * 8))) >> (i * 8)); 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci if (pwr_val[i] > RF6052_MAX_TX_PWR) 3458c2ecf20Sopenharmony_ci pwr_val[i] = RF6052_MAX_TX_PWR; 3468c2ecf20Sopenharmony_ci } 3478c2ecf20Sopenharmony_ci writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) | 3488c2ecf20Sopenharmony_ci (pwr_val[1] << 8) | pwr_val[0]; 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci if (rf == 0) 3518c2ecf20Sopenharmony_ci regoffset = regoffset_a[index]; 3528c2ecf20Sopenharmony_ci else 3538c2ecf20Sopenharmony_ci regoffset = regoffset_b[index]; 3548c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, regoffset, MASKDWORD, writeval); 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 3578c2ecf20Sopenharmony_ci "Set 0x%x = %08x\n", regoffset, writeval); 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci if (((get_rf_type(rtlphy) == RF_2T2R) && 3608c2ecf20Sopenharmony_ci (regoffset == RTXAGC_A_MCS15_MCS12 || 3618c2ecf20Sopenharmony_ci regoffset == RTXAGC_B_MCS15_MCS12)) || 3628c2ecf20Sopenharmony_ci ((get_rf_type(rtlphy) != RF_2T2R) && 3638c2ecf20Sopenharmony_ci (regoffset == RTXAGC_A_MCS07_MCS04 || 3648c2ecf20Sopenharmony_ci regoffset == RTXAGC_B_MCS07_MCS04))) { 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci writeval = pwr_val[3]; 3678c2ecf20Sopenharmony_ci if (regoffset == RTXAGC_A_MCS15_MCS12 || 3688c2ecf20Sopenharmony_ci regoffset == RTXAGC_A_MCS07_MCS04) 3698c2ecf20Sopenharmony_ci regoffset = 0xc90; 3708c2ecf20Sopenharmony_ci if (regoffset == RTXAGC_B_MCS15_MCS12 || 3718c2ecf20Sopenharmony_ci regoffset == RTXAGC_B_MCS07_MCS04) 3728c2ecf20Sopenharmony_ci regoffset = 0xc98; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci for (i = 0; i < 3; i++) { 3758c2ecf20Sopenharmony_ci writeval = (writeval > 6) ? (writeval - 6) : 0; 3768c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, (u32) (regoffset + i), 3778c2ecf20Sopenharmony_ci (u8)writeval); 3788c2ecf20Sopenharmony_ci } 3798c2ecf20Sopenharmony_ci } 3808c2ecf20Sopenharmony_ci } 3818c2ecf20Sopenharmony_ci} 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_civoid rtl8723e_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw, 3848c2ecf20Sopenharmony_ci u8 *ppowerlevel, u8 channel) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci u32 writeval[2], powerbase0[2], powerbase1[2]; 3878c2ecf20Sopenharmony_ci u8 index; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci rtl8723e_phy_get_power_base(hw, ppowerlevel, 3908c2ecf20Sopenharmony_ci channel, &powerbase0[0], &powerbase1[0]); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci for (index = 0; index < 6; index++) { 3938c2ecf20Sopenharmony_ci get_txpower_writeval_by_reg(hw, channel, index, &powerbase0[0], 3948c2ecf20Sopenharmony_ci &powerbase1[0], 3958c2ecf20Sopenharmony_ci &writeval[0]); 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci _rtl8723e_write_ofdm_power_reg(hw, index, &writeval[0]); 3988c2ecf20Sopenharmony_ci } 3998c2ecf20Sopenharmony_ci} 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_cibool rtl8723e_phy_rf6052_config(struct ieee80211_hw *hw) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 4048c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci if (rtlphy->rf_type == RF_1T1R) 4078c2ecf20Sopenharmony_ci rtlphy->num_total_rfpath = 1; 4088c2ecf20Sopenharmony_ci else 4098c2ecf20Sopenharmony_ci rtlphy->num_total_rfpath = 2; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci return _rtl8723e_phy_rf6052_config_parafile(hw); 4128c2ecf20Sopenharmony_ci} 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_cistatic bool _rtl8723e_phy_rf6052_config_parafile(struct ieee80211_hw *hw) 4158c2ecf20Sopenharmony_ci{ 4168c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 4178c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 4188c2ecf20Sopenharmony_ci u32 u4_regvalue = 0; 4198c2ecf20Sopenharmony_ci u8 rfpath; 4208c2ecf20Sopenharmony_ci bool rtstatus = true; 4218c2ecf20Sopenharmony_ci struct bb_reg_def *pphyreg; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci pphyreg = &rtlphy->phyreg_def[rfpath]; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci switch (rfpath) { 4288c2ecf20Sopenharmony_ci case RF90_PATH_A: 4298c2ecf20Sopenharmony_ci case RF90_PATH_C: 4308c2ecf20Sopenharmony_ci u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs, 4318c2ecf20Sopenharmony_ci BRFSI_RFENV); 4328c2ecf20Sopenharmony_ci break; 4338c2ecf20Sopenharmony_ci case RF90_PATH_B: 4348c2ecf20Sopenharmony_ci case RF90_PATH_D: 4358c2ecf20Sopenharmony_ci u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs, 4368c2ecf20Sopenharmony_ci BRFSI_RFENV << 16); 4378c2ecf20Sopenharmony_ci break; 4388c2ecf20Sopenharmony_ci } 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1); 4418c2ecf20Sopenharmony_ci udelay(1); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1); 4448c2ecf20Sopenharmony_ci udelay(1); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfhssi_para2, 4478c2ecf20Sopenharmony_ci B3WIREADDREAALENGTH, 0x0); 4488c2ecf20Sopenharmony_ci udelay(1); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0); 4518c2ecf20Sopenharmony_ci udelay(1); 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci switch (rfpath) { 4548c2ecf20Sopenharmony_ci case RF90_PATH_A: 4558c2ecf20Sopenharmony_ci rtstatus = rtl8723e_phy_config_rf_with_headerfile(hw, 4568c2ecf20Sopenharmony_ci (enum radio_path)rfpath); 4578c2ecf20Sopenharmony_ci break; 4588c2ecf20Sopenharmony_ci case RF90_PATH_B: 4598c2ecf20Sopenharmony_ci rtstatus = 4608c2ecf20Sopenharmony_ci rtl8723e_phy_config_rf_with_headerfile(hw, 4618c2ecf20Sopenharmony_ci (enum radio_path)rfpath); 4628c2ecf20Sopenharmony_ci break; 4638c2ecf20Sopenharmony_ci case RF90_PATH_C: 4648c2ecf20Sopenharmony_ci break; 4658c2ecf20Sopenharmony_ci case RF90_PATH_D: 4668c2ecf20Sopenharmony_ci break; 4678c2ecf20Sopenharmony_ci } 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci switch (rfpath) { 4708c2ecf20Sopenharmony_ci case RF90_PATH_A: 4718c2ecf20Sopenharmony_ci case RF90_PATH_C: 4728c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfs, 4738c2ecf20Sopenharmony_ci BRFSI_RFENV, u4_regvalue); 4748c2ecf20Sopenharmony_ci break; 4758c2ecf20Sopenharmony_ci case RF90_PATH_B: 4768c2ecf20Sopenharmony_ci case RF90_PATH_D: 4778c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfs, 4788c2ecf20Sopenharmony_ci BRFSI_RFENV << 16, u4_regvalue); 4798c2ecf20Sopenharmony_ci break; 4808c2ecf20Sopenharmony_ci } 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci if (!rtstatus) { 4838c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 4848c2ecf20Sopenharmony_ci "Radio[%d] Fail!!\n", rfpath); 4858c2ecf20Sopenharmony_ci return false; 4868c2ecf20Sopenharmony_ci } 4878c2ecf20Sopenharmony_ci } 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "\n"); 4908c2ecf20Sopenharmony_ci return rtstatus; 4918c2ecf20Sopenharmony_ci} 492