18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2010 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 _rtl8821ae_phy_rf6052_config_parafile(struct ieee80211_hw *hw); 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_civoid rtl8821ae_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci switch (bandwidth) { 168c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20: 178c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, BIT(11)|BIT(10), 3); 188c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, BIT(11)|BIT(10), 3); 198c2ecf20Sopenharmony_ci break; 208c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20_40: 218c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, BIT(11)|BIT(10), 1); 228c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, BIT(11)|BIT(10), 1); 238c2ecf20Sopenharmony_ci break; 248c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_80: 258c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, BIT(11)|BIT(10), 0); 268c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, BIT(11)|BIT(10), 0); 278c2ecf20Sopenharmony_ci break; 288c2ecf20Sopenharmony_ci default: 298c2ecf20Sopenharmony_ci pr_err("unknown bandwidth: %#X\n", bandwidth); 308c2ecf20Sopenharmony_ci break; 318c2ecf20Sopenharmony_ci } 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_civoid rtl8821ae_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 358c2ecf20Sopenharmony_ci u8 *ppowerlevel) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 388c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 398c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 408c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 418c2ecf20Sopenharmony_ci u32 tx_agc[2] = {0, 0}, tmpval; 428c2ecf20Sopenharmony_ci bool turbo_scanoff = false; 438c2ecf20Sopenharmony_ci u8 idx1, idx2; 448c2ecf20Sopenharmony_ci u8 *ptr; 458c2ecf20Sopenharmony_ci u8 direction; 468c2ecf20Sopenharmony_ci u32 pwrtrac_value; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci if (rtlefuse->eeprom_regulatory != 0) 498c2ecf20Sopenharmony_ci turbo_scanoff = true; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci if (mac->act_scanning) { 528c2ecf20Sopenharmony_ci tx_agc[RF90_PATH_A] = 0x3f3f3f3f; 538c2ecf20Sopenharmony_ci tx_agc[RF90_PATH_B] = 0x3f3f3f3f; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci if (turbo_scanoff) { 568c2ecf20Sopenharmony_ci for (idx1 = RF90_PATH_A; 578c2ecf20Sopenharmony_ci 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 rtl8821ae_dm_txpower_track_adjust(hw, 1, &direction, &pwrtrac_value); 968c2ecf20Sopenharmony_ci if (direction == 1) { 978c2ecf20Sopenharmony_ci tx_agc[0] += pwrtrac_value; 988c2ecf20Sopenharmony_ci tx_agc[1] += pwrtrac_value; 998c2ecf20Sopenharmony_ci } else if (direction == 2) { 1008c2ecf20Sopenharmony_ci tx_agc[0] -= pwrtrac_value; 1018c2ecf20Sopenharmony_ci tx_agc[1] -= pwrtrac_value; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci tmpval = tx_agc[RF90_PATH_A]; 1048c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTXAGC_A_CCK11_CCK1, MASKDWORD, tmpval); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1078c2ecf20Sopenharmony_ci "CCK PWR 1~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 1088c2ecf20Sopenharmony_ci RTXAGC_A_CCK11_CCK1); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci tmpval = tx_agc[RF90_PATH_B]; 1118c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTXAGC_B_CCK11_CCK1, MASKDWORD, tmpval); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1148c2ecf20Sopenharmony_ci "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 1158c2ecf20Sopenharmony_ci RTXAGC_B_CCK11_CCK1); 1168c2ecf20Sopenharmony_ci} 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_cistatic void rtl8821ae_phy_get_power_base(struct ieee80211_hw *hw, 1198c2ecf20Sopenharmony_ci u8 *ppowerlevel_ofdm, 1208c2ecf20Sopenharmony_ci u8 *ppowerlevel_bw20, 1218c2ecf20Sopenharmony_ci u8 *ppowerlevel_bw40, u8 channel, 1228c2ecf20Sopenharmony_ci u32 *ofdmbase, u32 *mcsbase) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1258c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 1268c2ecf20Sopenharmony_ci u32 powerbase0, powerbase1; 1278c2ecf20Sopenharmony_ci u8 i, powerlevel[2]; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci for (i = 0; i < 2; i++) { 1308c2ecf20Sopenharmony_ci powerbase0 = ppowerlevel_ofdm[i]; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) | 1338c2ecf20Sopenharmony_ci (powerbase0 << 8) | powerbase0; 1348c2ecf20Sopenharmony_ci *(ofdmbase + i) = powerbase0; 1358c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1368c2ecf20Sopenharmony_ci " [OFDM power base index rf(%c) = 0x%x]\n", 1378c2ecf20Sopenharmony_ci ((i == 0) ? 'A' : 'B'), *(ofdmbase + i)); 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci for (i = 0; i < 2; i++) { 1418c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) 1428c2ecf20Sopenharmony_ci powerlevel[i] = ppowerlevel_bw20[i]; 1438c2ecf20Sopenharmony_ci else 1448c2ecf20Sopenharmony_ci powerlevel[i] = ppowerlevel_bw40[i]; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci powerbase1 = powerlevel[i]; 1478c2ecf20Sopenharmony_ci powerbase1 = (powerbase1 << 24) | 1488c2ecf20Sopenharmony_ci (powerbase1 << 16) | (powerbase1 << 8) | powerbase1; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci *(mcsbase + i) = powerbase1; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1538c2ecf20Sopenharmony_ci " [MCS power base index rf(%c) = 0x%x]\n", 1548c2ecf20Sopenharmony_ci ((i == 0) ? 'A' : 'B'), *(mcsbase + i)); 1558c2ecf20Sopenharmony_ci } 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic void get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw, 1598c2ecf20Sopenharmony_ci u8 channel, u8 index, 1608c2ecf20Sopenharmony_ci u32 *powerbase0, 1618c2ecf20Sopenharmony_ci u32 *powerbase1, 1628c2ecf20Sopenharmony_ci u32 *p_outwriteval) 1638c2ecf20Sopenharmony_ci{ 1648c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1658c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 1668c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1678c2ecf20Sopenharmony_ci u8 i, chnlgroup = 0, pwr_diff_limit[4], pwr_diff = 0, customer_pwr_diff; 1688c2ecf20Sopenharmony_ci u32 writeval, customer_limit, rf; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci for (rf = 0; rf < 2; rf++) { 1718c2ecf20Sopenharmony_ci switch (rtlefuse->eeprom_regulatory) { 1728c2ecf20Sopenharmony_ci case 0: 1738c2ecf20Sopenharmony_ci chnlgroup = 0; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci writeval = 1768c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[chnlgroup][index + 1778c2ecf20Sopenharmony_ci (rf ? 8 : 0)] 1788c2ecf20Sopenharmony_ci + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 1818c2ecf20Sopenharmony_ci "RTK better performance, writeval(%c) = 0x%x\n", 1828c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 1838c2ecf20Sopenharmony_ci break; 1848c2ecf20Sopenharmony_ci case 1: 1858c2ecf20Sopenharmony_ci if (rtlphy->pwrgroup_cnt == 1) { 1868c2ecf20Sopenharmony_ci chnlgroup = 0; 1878c2ecf20Sopenharmony_ci } else { 1888c2ecf20Sopenharmony_ci if (channel < 3) 1898c2ecf20Sopenharmony_ci chnlgroup = 0; 1908c2ecf20Sopenharmony_ci else if (channel < 6) 1918c2ecf20Sopenharmony_ci chnlgroup = 1; 1928c2ecf20Sopenharmony_ci else if (channel < 9) 1938c2ecf20Sopenharmony_ci chnlgroup = 2; 1948c2ecf20Sopenharmony_ci else if (channel < 12) 1958c2ecf20Sopenharmony_ci chnlgroup = 3; 1968c2ecf20Sopenharmony_ci else if (channel < 14) 1978c2ecf20Sopenharmony_ci chnlgroup = 4; 1988c2ecf20Sopenharmony_ci else if (channel == 14) 1998c2ecf20Sopenharmony_ci chnlgroup = 5; 2008c2ecf20Sopenharmony_ci } 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci writeval = 2038c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 2048c2ecf20Sopenharmony_ci [index + (rf ? 8 : 0)] + ((index < 2) ? 2058c2ecf20Sopenharmony_ci powerbase0[rf] : 2068c2ecf20Sopenharmony_ci powerbase1[rf]); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2098c2ecf20Sopenharmony_ci "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n", 2108c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci break; 2138c2ecf20Sopenharmony_ci case 2: 2148c2ecf20Sopenharmony_ci writeval = 2158c2ecf20Sopenharmony_ci ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2188c2ecf20Sopenharmony_ci "Better regulatory, writeval(%c) = 0x%x\n", 2198c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2208c2ecf20Sopenharmony_ci break; 2218c2ecf20Sopenharmony_ci case 3: 2228c2ecf20Sopenharmony_ci chnlgroup = 0; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) { 2258c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2268c2ecf20Sopenharmony_ci "customer's limit, 40MHz rf(%c) = 0x%x\n", 2278c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), 2288c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht40[rf][channel - 2298c2ecf20Sopenharmony_ci 1]); 2308c2ecf20Sopenharmony_ci } else { 2318c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2328c2ecf20Sopenharmony_ci "customer's limit, 20MHz rf(%c) = 0x%x\n", 2338c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), 2348c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht20[rf][channel - 2358c2ecf20Sopenharmony_ci 1]); 2368c2ecf20Sopenharmony_ci } 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci if (index < 2) 2398c2ecf20Sopenharmony_ci pwr_diff = rtlefuse->txpwr_legacyhtdiff[rf][channel-1]; 2408c2ecf20Sopenharmony_ci else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) 2418c2ecf20Sopenharmony_ci pwr_diff = 2428c2ecf20Sopenharmony_ci rtlefuse->txpwr_ht20diff[rf][channel-1]; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) 2458c2ecf20Sopenharmony_ci customer_pwr_diff = 2468c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht40[rf][channel-1]; 2478c2ecf20Sopenharmony_ci else 2488c2ecf20Sopenharmony_ci customer_pwr_diff = 2498c2ecf20Sopenharmony_ci rtlefuse->pwrgroup_ht20[rf][channel-1]; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci if (pwr_diff > customer_pwr_diff) 2528c2ecf20Sopenharmony_ci pwr_diff = 0; 2538c2ecf20Sopenharmony_ci else 2548c2ecf20Sopenharmony_ci pwr_diff = customer_pwr_diff - pwr_diff; 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 + (rf ? 8 : 0)] & 2608c2ecf20Sopenharmony_ci (0x7f << (i * 8))) >> (i * 8)); 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci if (pwr_diff_limit[i] > pwr_diff) 2638c2ecf20Sopenharmony_ci pwr_diff_limit[i] = pwr_diff; 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci customer_limit = (pwr_diff_limit[3] << 24) | 2678c2ecf20Sopenharmony_ci (pwr_diff_limit[2] << 16) | 2688c2ecf20Sopenharmony_ci (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]); 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2718c2ecf20Sopenharmony_ci "Customer's limit rf(%c) = 0x%x\n", 2728c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), customer_limit); 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci writeval = customer_limit + 2758c2ecf20Sopenharmony_ci ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2788c2ecf20Sopenharmony_ci "Customer, writeval rf(%c)= 0x%x\n", 2798c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2808c2ecf20Sopenharmony_ci break; 2818c2ecf20Sopenharmony_ci default: 2828c2ecf20Sopenharmony_ci chnlgroup = 0; 2838c2ecf20Sopenharmony_ci writeval = 2848c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 2858c2ecf20Sopenharmony_ci [index + (rf ? 8 : 0)] 2868c2ecf20Sopenharmony_ci + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 2898c2ecf20Sopenharmony_ci "RTK better performance, writeval rf(%c) = 0x%x\n", 2908c2ecf20Sopenharmony_ci ((rf == 0) ? 'A' : 'B'), writeval); 2918c2ecf20Sopenharmony_ci break; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1) 2958c2ecf20Sopenharmony_ci writeval = writeval - 0x06060606; 2968c2ecf20Sopenharmony_ci else if (rtlpriv->dm.dynamic_txhighpower_lvl == 2978c2ecf20Sopenharmony_ci TXHIGHPWRLEVEL_BT2) 2988c2ecf20Sopenharmony_ci writeval = writeval - 0x0c0c0c0c; 2998c2ecf20Sopenharmony_ci *(p_outwriteval + rf) = writeval; 3008c2ecf20Sopenharmony_ci } 3018c2ecf20Sopenharmony_ci} 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_cistatic void _rtl8821ae_write_ofdm_power_reg(struct ieee80211_hw *hw, 3048c2ecf20Sopenharmony_ci u8 index, u32 *pvalue) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3078c2ecf20Sopenharmony_ci u16 regoffset_a[6] = { 3088c2ecf20Sopenharmony_ci RTXAGC_A_OFDM18_OFDM6, RTXAGC_A_OFDM54_OFDM24, 3098c2ecf20Sopenharmony_ci RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04, 3108c2ecf20Sopenharmony_ci RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12 3118c2ecf20Sopenharmony_ci }; 3128c2ecf20Sopenharmony_ci u16 regoffset_b[6] = { 3138c2ecf20Sopenharmony_ci RTXAGC_B_OFDM18_OFDM6, RTXAGC_B_OFDM54_OFDM24, 3148c2ecf20Sopenharmony_ci RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04, 3158c2ecf20Sopenharmony_ci RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12 3168c2ecf20Sopenharmony_ci }; 3178c2ecf20Sopenharmony_ci u8 i, rf, pwr_val[4]; 3188c2ecf20Sopenharmony_ci u32 writeval; 3198c2ecf20Sopenharmony_ci u16 regoffset; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci for (rf = 0; rf < 2; rf++) { 3228c2ecf20Sopenharmony_ci writeval = pvalue[rf]; 3238c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 3248c2ecf20Sopenharmony_ci pwr_val[i] = (u8)((writeval & (0x7f << 3258c2ecf20Sopenharmony_ci (i * 8))) >> (i * 8)); 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci if (pwr_val[i] > RF6052_MAX_TX_PWR) 3288c2ecf20Sopenharmony_ci pwr_val[i] = RF6052_MAX_TX_PWR; 3298c2ecf20Sopenharmony_ci } 3308c2ecf20Sopenharmony_ci writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) | 3318c2ecf20Sopenharmony_ci (pwr_val[1] << 8) | pwr_val[0]; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci if (rf == 0) 3348c2ecf20Sopenharmony_ci regoffset = regoffset_a[index]; 3358c2ecf20Sopenharmony_ci else 3368c2ecf20Sopenharmony_ci regoffset = regoffset_b[index]; 3378c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, regoffset, MASKDWORD, writeval); 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 3408c2ecf20Sopenharmony_ci "Set 0x%x = %08x\n", regoffset, writeval); 3418c2ecf20Sopenharmony_ci } 3428c2ecf20Sopenharmony_ci} 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_civoid rtl8821ae_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw, 3458c2ecf20Sopenharmony_ci u8 *ppowerlevel_ofdm, 3468c2ecf20Sopenharmony_ci u8 *ppowerlevel_bw20, 3478c2ecf20Sopenharmony_ci u8 *ppowerlevel_bw40, 3488c2ecf20Sopenharmony_ci u8 channel) 3498c2ecf20Sopenharmony_ci{ 3508c2ecf20Sopenharmony_ci u32 writeval[2], powerbase0[2], powerbase1[2]; 3518c2ecf20Sopenharmony_ci u8 index; 3528c2ecf20Sopenharmony_ci u8 direction; 3538c2ecf20Sopenharmony_ci u32 pwrtrac_value; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci rtl8821ae_phy_get_power_base(hw, ppowerlevel_ofdm, 3568c2ecf20Sopenharmony_ci ppowerlevel_bw20, 3578c2ecf20Sopenharmony_ci ppowerlevel_bw40, 3588c2ecf20Sopenharmony_ci channel, 3598c2ecf20Sopenharmony_ci &powerbase0[0], 3608c2ecf20Sopenharmony_ci &powerbase1[0]); 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci rtl8821ae_dm_txpower_track_adjust(hw, 1, &direction, &pwrtrac_value); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci for (index = 0; index < 6; index++) { 3658c2ecf20Sopenharmony_ci get_txpower_writeval_by_regulatory(hw, channel, index, 3668c2ecf20Sopenharmony_ci &powerbase0[0], 3678c2ecf20Sopenharmony_ci &powerbase1[0], 3688c2ecf20Sopenharmony_ci &writeval[0]); 3698c2ecf20Sopenharmony_ci if (direction == 1) { 3708c2ecf20Sopenharmony_ci writeval[0] += pwrtrac_value; 3718c2ecf20Sopenharmony_ci writeval[1] += pwrtrac_value; 3728c2ecf20Sopenharmony_ci } else if (direction == 2) { 3738c2ecf20Sopenharmony_ci writeval[0] -= pwrtrac_value; 3748c2ecf20Sopenharmony_ci writeval[1] -= pwrtrac_value; 3758c2ecf20Sopenharmony_ci } 3768c2ecf20Sopenharmony_ci _rtl8821ae_write_ofdm_power_reg(hw, index, &writeval[0]); 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci} 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_cibool rtl8821ae_phy_rf6052_config(struct ieee80211_hw *hw) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3838c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci if (rtlphy->rf_type == RF_1T1R) 3868c2ecf20Sopenharmony_ci rtlphy->num_total_rfpath = 1; 3878c2ecf20Sopenharmony_ci else 3888c2ecf20Sopenharmony_ci rtlphy->num_total_rfpath = 2; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci return _rtl8821ae_phy_rf6052_config_parafile(hw); 3918c2ecf20Sopenharmony_ci} 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistatic bool _rtl8821ae_phy_rf6052_config_parafile(struct ieee80211_hw *hw) 3948c2ecf20Sopenharmony_ci{ 3958c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3968c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 3978c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 3988c2ecf20Sopenharmony_ci u8 rfpath; 3998c2ecf20Sopenharmony_ci bool rtstatus = true; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { 4028c2ecf20Sopenharmony_ci switch (rfpath) { 4038c2ecf20Sopenharmony_ci case RF90_PATH_A: { 4048c2ecf20Sopenharmony_ci if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) 4058c2ecf20Sopenharmony_ci rtstatus = 4068c2ecf20Sopenharmony_ci rtl8812ae_phy_config_rf_with_headerfile(hw, 4078c2ecf20Sopenharmony_ci (enum radio_path)rfpath); 4088c2ecf20Sopenharmony_ci else 4098c2ecf20Sopenharmony_ci rtstatus = 4108c2ecf20Sopenharmony_ci rtl8821ae_phy_config_rf_with_headerfile(hw, 4118c2ecf20Sopenharmony_ci (enum radio_path)rfpath); 4128c2ecf20Sopenharmony_ci break; 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci case RF90_PATH_B: 4158c2ecf20Sopenharmony_ci if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) 4168c2ecf20Sopenharmony_ci rtstatus = 4178c2ecf20Sopenharmony_ci rtl8812ae_phy_config_rf_with_headerfile(hw, 4188c2ecf20Sopenharmony_ci (enum radio_path)rfpath); 4198c2ecf20Sopenharmony_ci else 4208c2ecf20Sopenharmony_ci rtstatus = 4218c2ecf20Sopenharmony_ci rtl8821ae_phy_config_rf_with_headerfile(hw, 4228c2ecf20Sopenharmony_ci (enum radio_path)rfpath); 4238c2ecf20Sopenharmony_ci break; 4248c2ecf20Sopenharmony_ci case RF90_PATH_C: 4258c2ecf20Sopenharmony_ci break; 4268c2ecf20Sopenharmony_ci case RF90_PATH_D: 4278c2ecf20Sopenharmony_ci break; 4288c2ecf20Sopenharmony_ci } 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci if (!rtstatus) { 4318c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 4328c2ecf20Sopenharmony_ci "Radio[%d] Fail!!\n", rfpath); 4338c2ecf20Sopenharmony_ci return false; 4348c2ecf20Sopenharmony_ci } 4358c2ecf20Sopenharmony_ci } 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci /*put arrays in dm.c*/ 4388c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "\n"); 4398c2ecf20Sopenharmony_ci return rtstatus; 4408c2ecf20Sopenharmony_ci} 441