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