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