1f1d2b4d3SLarry Finger /****************************************************************************** 2f1d2b4d3SLarry Finger * 3f1d2b4d3SLarry Finger * Copyright(c) 2009-2012 Realtek Corporation. 4f1d2b4d3SLarry Finger * 5f1d2b4d3SLarry Finger * This program is free software; you can redistribute it and/or modify it 6f1d2b4d3SLarry Finger * under the terms of version 2 of the GNU General Public License as 7f1d2b4d3SLarry Finger * published by the Free Software Foundation. 8f1d2b4d3SLarry Finger * 9f1d2b4d3SLarry Finger * This program is distributed in the hope that it will be useful, but WITHOUT 10f1d2b4d3SLarry Finger * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11f1d2b4d3SLarry Finger * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12f1d2b4d3SLarry Finger * more details. 13f1d2b4d3SLarry Finger * 14f1d2b4d3SLarry Finger * The full GNU General Public License is included in this distribution in the 15f1d2b4d3SLarry Finger * file called LICENSE. 16f1d2b4d3SLarry Finger * 17f1d2b4d3SLarry Finger * Contact Information: 18f1d2b4d3SLarry Finger * wlanfae <wlanfae@realtek.com> 19f1d2b4d3SLarry Finger * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 20f1d2b4d3SLarry Finger * Hsinchu 300, Taiwan. 21f1d2b4d3SLarry Finger * 22f1d2b4d3SLarry Finger * Larry Finger <Larry.Finger@lwfinger.net> 23f1d2b4d3SLarry Finger * 24f1d2b4d3SLarry Finger *****************************************************************************/ 25f1d2b4d3SLarry Finger 26f1d2b4d3SLarry Finger #include "../wifi.h" 27f1d2b4d3SLarry Finger #include "reg.h" 28f1d2b4d3SLarry Finger #include "def.h" 29f1d2b4d3SLarry Finger #include "phy.h" 30f1d2b4d3SLarry Finger #include "rf.h" 31f1d2b4d3SLarry Finger #include "dm.h" 32f1d2b4d3SLarry Finger 33f1d2b4d3SLarry Finger static bool _rtl8723e_phy_rf6052_config_parafile(struct ieee80211_hw *hw); 34f1d2b4d3SLarry Finger 35f1d2b4d3SLarry Finger void rtl8723e_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) 36f1d2b4d3SLarry Finger { 37f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 38f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 39f1d2b4d3SLarry Finger 40f1d2b4d3SLarry Finger switch (bandwidth) { 41f1d2b4d3SLarry Finger case HT_CHANNEL_WIDTH_20: 42f1d2b4d3SLarry Finger rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] & 43f1d2b4d3SLarry Finger 0xfffff3ff) | 0x0400); 44f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK, 45f1d2b4d3SLarry Finger rtlphy->rfreg_chnlval[0]); 46f1d2b4d3SLarry Finger break; 47f1d2b4d3SLarry Finger case HT_CHANNEL_WIDTH_20_40: 48f1d2b4d3SLarry Finger rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] & 49f1d2b4d3SLarry Finger 0xfffff3ff)); 50f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK, 51f1d2b4d3SLarry Finger rtlphy->rfreg_chnlval[0]); 52f1d2b4d3SLarry Finger break; 53f1d2b4d3SLarry Finger default: 54f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 55f1d2b4d3SLarry Finger "unknown bandwidth: %#X\n", bandwidth); 56f1d2b4d3SLarry Finger break; 57f1d2b4d3SLarry Finger } 58f1d2b4d3SLarry Finger } 59f1d2b4d3SLarry Finger 60f1d2b4d3SLarry Finger void rtl8723e_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 61f1d2b4d3SLarry Finger u8 *ppowerlevel) 62f1d2b4d3SLarry Finger { 63f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 64f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 65f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 66f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 67f1d2b4d3SLarry Finger u32 tx_agc[2] = {0, 0}, tmpval; 68f1d2b4d3SLarry Finger bool turbo_scanoff = false; 69f1d2b4d3SLarry Finger u8 idx1, idx2; 70f1d2b4d3SLarry Finger u8 *ptr; 71f1d2b4d3SLarry Finger 72f1d2b4d3SLarry Finger if (rtlefuse->eeprom_regulatory != 0) 73f1d2b4d3SLarry Finger turbo_scanoff = true; 74f1d2b4d3SLarry Finger 75f1d2b4d3SLarry Finger if (mac->act_scanning == true) { 76f1d2b4d3SLarry Finger tx_agc[RF90_PATH_A] = 0x3f3f3f3f; 77f1d2b4d3SLarry Finger tx_agc[RF90_PATH_B] = 0x3f3f3f3f; 78f1d2b4d3SLarry Finger 79f1d2b4d3SLarry Finger if (turbo_scanoff) { 80f1d2b4d3SLarry Finger for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; 81f1d2b4d3SLarry Finger idx1++) { 82f1d2b4d3SLarry Finger tx_agc[idx1] = ppowerlevel[idx1] | 83f1d2b4d3SLarry Finger (ppowerlevel[idx1] << 8) | 84f1d2b4d3SLarry Finger (ppowerlevel[idx1] << 16) | 85f1d2b4d3SLarry Finger (ppowerlevel[idx1] << 24); 86f1d2b4d3SLarry Finger } 87f1d2b4d3SLarry Finger } 88f1d2b4d3SLarry Finger } else { 89f1d2b4d3SLarry Finger for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 90f1d2b4d3SLarry Finger tx_agc[idx1] = ppowerlevel[idx1] | 91f1d2b4d3SLarry Finger (ppowerlevel[idx1] << 8) | 92f1d2b4d3SLarry Finger (ppowerlevel[idx1] << 16) | 93f1d2b4d3SLarry Finger (ppowerlevel[idx1] << 24); 94f1d2b4d3SLarry Finger } 95f1d2b4d3SLarry Finger 96f1d2b4d3SLarry Finger if (rtlefuse->eeprom_regulatory == 0) { 97f1d2b4d3SLarry Finger tmpval = 98f1d2b4d3SLarry Finger (rtlphy->mcs_txpwrlevel_origoffset[0][6]) + 99f1d2b4d3SLarry Finger (rtlphy->mcs_txpwrlevel_origoffset[0][7] << 100f1d2b4d3SLarry Finger 8); 101f1d2b4d3SLarry Finger tx_agc[RF90_PATH_A] += tmpval; 102f1d2b4d3SLarry Finger 103f1d2b4d3SLarry Finger tmpval = (rtlphy->mcs_txpwrlevel_origoffset[0][14]) + 104f1d2b4d3SLarry Finger (rtlphy->mcs_txpwrlevel_origoffset[0][15] << 105f1d2b4d3SLarry Finger 24); 106f1d2b4d3SLarry Finger tx_agc[RF90_PATH_B] += tmpval; 107f1d2b4d3SLarry Finger } 108f1d2b4d3SLarry Finger } 109f1d2b4d3SLarry Finger 110f1d2b4d3SLarry Finger for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 111f1d2b4d3SLarry Finger ptr = (u8 *)&tx_agc[idx1]; 112f1d2b4d3SLarry Finger for (idx2 = 0; idx2 < 4; idx2++) { 113f1d2b4d3SLarry Finger if (*ptr > RF6052_MAX_TX_PWR) 114f1d2b4d3SLarry Finger *ptr = RF6052_MAX_TX_PWR; 115f1d2b4d3SLarry Finger ptr++; 116f1d2b4d3SLarry Finger } 117f1d2b4d3SLarry Finger } 118f1d2b4d3SLarry Finger 119f1d2b4d3SLarry Finger tmpval = tx_agc[RF90_PATH_A] & 0xff; 120f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, MASKBYTE1, tmpval); 121f1d2b4d3SLarry Finger 122f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 123f1d2b4d3SLarry Finger "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 124f1d2b4d3SLarry Finger RTXAGC_A_CCK1_MCS32); 125f1d2b4d3SLarry Finger 126f1d2b4d3SLarry Finger tmpval = tx_agc[RF90_PATH_A] >> 8; 127f1d2b4d3SLarry Finger 128f1d2b4d3SLarry Finger tmpval = tmpval & 0xff00ffff; 129f1d2b4d3SLarry Finger 130f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval); 131f1d2b4d3SLarry Finger 132f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 133f1d2b4d3SLarry Finger "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 134f1d2b4d3SLarry Finger RTXAGC_B_CCK11_A_CCK2_11); 135f1d2b4d3SLarry Finger 136f1d2b4d3SLarry Finger tmpval = tx_agc[RF90_PATH_B] >> 24; 137f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, MASKBYTE0, tmpval); 138f1d2b4d3SLarry Finger 139f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 140f1d2b4d3SLarry Finger "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 141f1d2b4d3SLarry Finger RTXAGC_B_CCK11_A_CCK2_11); 142f1d2b4d3SLarry Finger 143f1d2b4d3SLarry Finger tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff; 144f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval); 145f1d2b4d3SLarry Finger 146f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 147f1d2b4d3SLarry Finger "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 148f1d2b4d3SLarry Finger RTXAGC_B_CCK1_55_MCS32); 149f1d2b4d3SLarry Finger } 150f1d2b4d3SLarry Finger 151f1d2b4d3SLarry Finger static void rtl8723e_phy_get_power_base(struct ieee80211_hw *hw, 152f1d2b4d3SLarry Finger u8 *ppowerlevel, u8 channel, 153f1d2b4d3SLarry Finger u32 *ofdmbase, u32 *mcsbase) 154f1d2b4d3SLarry Finger { 155f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 156f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 157f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 158f1d2b4d3SLarry Finger u32 powerbase0, powerbase1; 159f1d2b4d3SLarry Finger u8 legacy_pwrdiff, ht20_pwrdiff; 160f1d2b4d3SLarry Finger u8 i, powerlevel[2]; 161f1d2b4d3SLarry Finger 162f1d2b4d3SLarry Finger for (i = 0; i < 2; i++) { 163f1d2b4d3SLarry Finger powerlevel[i] = ppowerlevel[i]; 164f1d2b4d3SLarry Finger legacy_pwrdiff = rtlefuse->txpwr_legacyhtdiff[i][channel - 1]; 165f1d2b4d3SLarry Finger powerbase0 = powerlevel[i] + legacy_pwrdiff; 166f1d2b4d3SLarry Finger 167f1d2b4d3SLarry Finger powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) | 168f1d2b4d3SLarry Finger (powerbase0 << 8) | powerbase0; 169f1d2b4d3SLarry Finger *(ofdmbase + i) = powerbase0; 170f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 171f1d2b4d3SLarry Finger " [OFDM power base index rf(%c) = 0x%x]\n", 172f1d2b4d3SLarry Finger ((i == 0) ? 'A' : 'B'), *(ofdmbase + i)); 173f1d2b4d3SLarry Finger } 174f1d2b4d3SLarry Finger 175f1d2b4d3SLarry Finger for (i = 0; i < 2; i++) { 176f1d2b4d3SLarry Finger if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) { 177f1d2b4d3SLarry Finger ht20_pwrdiff = 178f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[i][channel - 1]; 179f1d2b4d3SLarry Finger powerlevel[i] += ht20_pwrdiff; 180f1d2b4d3SLarry Finger } 181f1d2b4d3SLarry Finger powerbase1 = powerlevel[i]; 182f1d2b4d3SLarry Finger powerbase1 = (powerbase1 << 24) | 183f1d2b4d3SLarry Finger (powerbase1 << 16) | (powerbase1 << 8) | powerbase1; 184f1d2b4d3SLarry Finger 185f1d2b4d3SLarry Finger *(mcsbase + i) = powerbase1; 186f1d2b4d3SLarry Finger 187f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 188f1d2b4d3SLarry Finger " [MCS power base index rf(%c) = 0x%x]\n", 189f1d2b4d3SLarry Finger ((i == 0) ? 'A' : 'B'), *(mcsbase + i)); 190f1d2b4d3SLarry Finger } 191f1d2b4d3SLarry Finger } 192f1d2b4d3SLarry Finger 193f1d2b4d3SLarry Finger static void get_txpower_writeval_by_reg(struct ieee80211_hw *hw, 194f1d2b4d3SLarry Finger u8 channel, u8 index, 195f1d2b4d3SLarry Finger u32 *powerbase0, 196f1d2b4d3SLarry Finger u32 *powerbase1, 197f1d2b4d3SLarry Finger u32 *p_outwriteval) 198f1d2b4d3SLarry Finger { 199f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 200f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 201f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 202f1d2b4d3SLarry Finger u8 i, chnlgroup = 0, pwr_diff_limit[4]; 203f1d2b4d3SLarry Finger u32 writeval, customer_limit, rf; 204f1d2b4d3SLarry Finger 205f1d2b4d3SLarry Finger for (rf = 0; rf < 2; rf++) { 206f1d2b4d3SLarry Finger switch (rtlefuse->eeprom_regulatory) { 207f1d2b4d3SLarry Finger case 0: 208f1d2b4d3SLarry Finger chnlgroup = 0; 209f1d2b4d3SLarry Finger 210f1d2b4d3SLarry Finger writeval = 211f1d2b4d3SLarry Finger rtlphy->mcs_txpwrlevel_origoffset[chnlgroup][index + 212f1d2b4d3SLarry Finger (rf ? 8 : 0)] 213f1d2b4d3SLarry Finger + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 214f1d2b4d3SLarry Finger 215f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 216f1d2b4d3SLarry Finger "RTK better performance, writeval(%c) = 0x%x\n", 217f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), writeval); 218f1d2b4d3SLarry Finger break; 219f1d2b4d3SLarry Finger case 1: 220f1d2b4d3SLarry Finger if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) { 221f1d2b4d3SLarry Finger writeval = ((index < 2) ? powerbase0[rf] : 222f1d2b4d3SLarry Finger powerbase1[rf]); 223f1d2b4d3SLarry Finger 224f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 225f1d2b4d3SLarry Finger "Realtek regulatory, 40MHz, writeval(%c) = 0x%x\n", 226f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), writeval); 227f1d2b4d3SLarry Finger } else { 228f1d2b4d3SLarry Finger if (rtlphy->pwrgroup_cnt == 1) 229f1d2b4d3SLarry Finger chnlgroup = 0; 230f1d2b4d3SLarry Finger if (rtlphy->pwrgroup_cnt >= 3) { 231f1d2b4d3SLarry Finger if (channel <= 3) 232f1d2b4d3SLarry Finger chnlgroup = 0; 233f1d2b4d3SLarry Finger else if (channel >= 4 && channel <= 9) 234f1d2b4d3SLarry Finger chnlgroup = 1; 235f1d2b4d3SLarry Finger else if (channel > 9) 236f1d2b4d3SLarry Finger chnlgroup = 2; 237f1d2b4d3SLarry Finger if (rtlphy->current_chan_bw == 238f1d2b4d3SLarry Finger HT_CHANNEL_WIDTH_20) 239f1d2b4d3SLarry Finger chnlgroup++; 240f1d2b4d3SLarry Finger else 241f1d2b4d3SLarry Finger chnlgroup += 4; 242f1d2b4d3SLarry Finger } 243f1d2b4d3SLarry Finger 244f1d2b4d3SLarry Finger writeval = 245f1d2b4d3SLarry Finger rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 246f1d2b4d3SLarry Finger [index + (rf ? 8 : 0)] + ((index < 2) ? 247f1d2b4d3SLarry Finger powerbase0[rf] : 248f1d2b4d3SLarry Finger powerbase1[rf]); 249f1d2b4d3SLarry Finger 250f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 251f1d2b4d3SLarry Finger "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n", 252f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), writeval); 253f1d2b4d3SLarry Finger } 254f1d2b4d3SLarry Finger break; 255f1d2b4d3SLarry Finger case 2: 256f1d2b4d3SLarry Finger writeval = 257f1d2b4d3SLarry Finger ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 258f1d2b4d3SLarry Finger 259f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 260f1d2b4d3SLarry Finger "Better regulatory, writeval(%c) = 0x%x\n", 261f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), writeval); 262f1d2b4d3SLarry Finger break; 263f1d2b4d3SLarry Finger case 3: 264f1d2b4d3SLarry Finger chnlgroup = 0; 265f1d2b4d3SLarry Finger 266f1d2b4d3SLarry Finger if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) { 267f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 268f1d2b4d3SLarry Finger "customer's limit, 40MHz rf(%c) = 0x%x\n", 269f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), 270f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht40[rf][channel - 271f1d2b4d3SLarry Finger 1]); 272f1d2b4d3SLarry Finger } else { 273f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 274f1d2b4d3SLarry Finger "customer's limit, 20MHz rf(%c) = 0x%x\n", 275f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), 276f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht20[rf][channel - 277f1d2b4d3SLarry Finger 1]); 278f1d2b4d3SLarry Finger } 279f1d2b4d3SLarry Finger for (i = 0; i < 4; i++) { 280f1d2b4d3SLarry Finger pwr_diff_limit[i] = 281f1d2b4d3SLarry Finger (u8)((rtlphy->mcs_txpwrlevel_origoffset 282f1d2b4d3SLarry Finger [chnlgroup][index + 283f1d2b4d3SLarry Finger (rf ? 8 : 0)] & (0x7f << 284f1d2b4d3SLarry Finger (i * 8))) >> (i * 8)); 285f1d2b4d3SLarry Finger 286f1d2b4d3SLarry Finger if (rtlphy->current_chan_bw == 287f1d2b4d3SLarry Finger HT_CHANNEL_WIDTH_20_40) { 288f1d2b4d3SLarry Finger if (pwr_diff_limit[i] > 289f1d2b4d3SLarry Finger rtlefuse-> 290f1d2b4d3SLarry Finger pwrgroup_ht40[rf][channel - 1]) 291f1d2b4d3SLarry Finger pwr_diff_limit[i] = 292f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht40[rf] 293f1d2b4d3SLarry Finger [channel - 1]; 294f1d2b4d3SLarry Finger } else { 295f1d2b4d3SLarry Finger if (pwr_diff_limit[i] > 296f1d2b4d3SLarry Finger rtlefuse-> 297f1d2b4d3SLarry Finger pwrgroup_ht20[rf][channel - 1]) 298f1d2b4d3SLarry Finger pwr_diff_limit[i] = 299f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht20[rf] 300f1d2b4d3SLarry Finger [channel - 1]; 301f1d2b4d3SLarry Finger } 302f1d2b4d3SLarry Finger } 303f1d2b4d3SLarry Finger 304f1d2b4d3SLarry Finger customer_limit = (pwr_diff_limit[3] << 24) | 305f1d2b4d3SLarry Finger (pwr_diff_limit[2] << 16) | 306f1d2b4d3SLarry Finger (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]); 307f1d2b4d3SLarry Finger 308f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 309f1d2b4d3SLarry Finger "Customer's limit rf(%c) = 0x%x\n", 310f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), customer_limit); 311f1d2b4d3SLarry Finger 312f1d2b4d3SLarry Finger writeval = customer_limit + 313f1d2b4d3SLarry Finger ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 314f1d2b4d3SLarry Finger 315f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 316f1d2b4d3SLarry Finger "Customer, writeval rf(%c)= 0x%x\n", 317f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), writeval); 318f1d2b4d3SLarry Finger break; 319f1d2b4d3SLarry Finger default: 320f1d2b4d3SLarry Finger chnlgroup = 0; 321f1d2b4d3SLarry Finger writeval = 322f1d2b4d3SLarry Finger rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 323f1d2b4d3SLarry Finger [index + (rf ? 8 : 0)] 324f1d2b4d3SLarry Finger + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); 325f1d2b4d3SLarry Finger 326f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 327f1d2b4d3SLarry Finger "RTK better performance, writeval rf(%c) = 0x%x\n", 328f1d2b4d3SLarry Finger ((rf == 0) ? 'A' : 'B'), writeval); 329f1d2b4d3SLarry Finger break; 330f1d2b4d3SLarry Finger } 331f1d2b4d3SLarry Finger 332f1d2b4d3SLarry Finger if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1) 333f1d2b4d3SLarry Finger writeval = writeval - 0x06060606; 334f1d2b4d3SLarry Finger else if (rtlpriv->dm.dynamic_txhighpower_lvl == 335f1d2b4d3SLarry Finger TXHIGHPWRLEVEL_BT2) 336f1d2b4d3SLarry Finger writeval = writeval - 0x0c0c0c0c; 337f1d2b4d3SLarry Finger *(p_outwriteval + rf) = writeval; 338f1d2b4d3SLarry Finger } 339f1d2b4d3SLarry Finger } 340f1d2b4d3SLarry Finger 341f1d2b4d3SLarry Finger static void _rtl8723e_write_ofdm_power_reg(struct ieee80211_hw *hw, 342f1d2b4d3SLarry Finger u8 index, u32 *pvalue) 343f1d2b4d3SLarry Finger { 344f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 345f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 346f1d2b4d3SLarry Finger 347f1d2b4d3SLarry Finger u16 regoffset_a[6] = { 348f1d2b4d3SLarry Finger RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24, 349f1d2b4d3SLarry Finger RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04, 350f1d2b4d3SLarry Finger RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12 351f1d2b4d3SLarry Finger }; 352f1d2b4d3SLarry Finger u16 regoffset_b[6] = { 353f1d2b4d3SLarry Finger RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24, 354f1d2b4d3SLarry Finger RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04, 355f1d2b4d3SLarry Finger RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12 356f1d2b4d3SLarry Finger }; 357f1d2b4d3SLarry Finger u8 i, rf, pwr_val[4]; 358f1d2b4d3SLarry Finger u32 writeval; 359f1d2b4d3SLarry Finger u16 regoffset; 360f1d2b4d3SLarry Finger 361f1d2b4d3SLarry Finger for (rf = 0; rf < 2; rf++) { 362f1d2b4d3SLarry Finger writeval = pvalue[rf]; 363f1d2b4d3SLarry Finger for (i = 0; i < 4; i++) { 364f1d2b4d3SLarry Finger pwr_val[i] = (u8)((writeval & (0x7f << 365f1d2b4d3SLarry Finger (i * 8))) >> (i * 8)); 366f1d2b4d3SLarry Finger 367f1d2b4d3SLarry Finger if (pwr_val[i] > RF6052_MAX_TX_PWR) 368f1d2b4d3SLarry Finger pwr_val[i] = RF6052_MAX_TX_PWR; 369f1d2b4d3SLarry Finger } 370f1d2b4d3SLarry Finger writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) | 371f1d2b4d3SLarry Finger (pwr_val[1] << 8) | pwr_val[0]; 372f1d2b4d3SLarry Finger 373f1d2b4d3SLarry Finger if (rf == 0) 374f1d2b4d3SLarry Finger regoffset = regoffset_a[index]; 375f1d2b4d3SLarry Finger else 376f1d2b4d3SLarry Finger regoffset = regoffset_b[index]; 377f1d2b4d3SLarry Finger rtl_set_bbreg(hw, regoffset, MASKDWORD, writeval); 378f1d2b4d3SLarry Finger 379f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 380f1d2b4d3SLarry Finger "Set 0x%x = %08x\n", regoffset, writeval); 381f1d2b4d3SLarry Finger 382f1d2b4d3SLarry Finger if (((get_rf_type(rtlphy) == RF_2T2R) && 383f1d2b4d3SLarry Finger (regoffset == RTXAGC_A_MCS15_MCS12 || 384f1d2b4d3SLarry Finger regoffset == RTXAGC_B_MCS15_MCS12)) || 385f1d2b4d3SLarry Finger ((get_rf_type(rtlphy) != RF_2T2R) && 386f1d2b4d3SLarry Finger (regoffset == RTXAGC_A_MCS07_MCS04 || 387f1d2b4d3SLarry Finger regoffset == RTXAGC_B_MCS07_MCS04))) { 388f1d2b4d3SLarry Finger 389f1d2b4d3SLarry Finger writeval = pwr_val[3]; 390f1d2b4d3SLarry Finger if (regoffset == RTXAGC_A_MCS15_MCS12 || 391f1d2b4d3SLarry Finger regoffset == RTXAGC_A_MCS07_MCS04) 392f1d2b4d3SLarry Finger regoffset = 0xc90; 393f1d2b4d3SLarry Finger if (regoffset == RTXAGC_B_MCS15_MCS12 || 394f1d2b4d3SLarry Finger regoffset == RTXAGC_B_MCS07_MCS04) 395f1d2b4d3SLarry Finger regoffset = 0xc98; 396f1d2b4d3SLarry Finger 397f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) { 398f1d2b4d3SLarry Finger writeval = (writeval > 6) ? (writeval - 6) : 0; 399f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, (u32) (regoffset + i), 400f1d2b4d3SLarry Finger (u8)writeval); 401f1d2b4d3SLarry Finger } 402f1d2b4d3SLarry Finger } 403f1d2b4d3SLarry Finger } 404f1d2b4d3SLarry Finger } 405f1d2b4d3SLarry Finger 406f1d2b4d3SLarry Finger void rtl8723e_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw, 407f1d2b4d3SLarry Finger u8 *ppowerlevel, u8 channel) 408f1d2b4d3SLarry Finger { 409f1d2b4d3SLarry Finger u32 writeval[2], powerbase0[2], powerbase1[2]; 410f1d2b4d3SLarry Finger u8 index; 411f1d2b4d3SLarry Finger 412f1d2b4d3SLarry Finger rtl8723e_phy_get_power_base(hw, ppowerlevel, 413f1d2b4d3SLarry Finger channel, &powerbase0[0], &powerbase1[0]); 414f1d2b4d3SLarry Finger 415f1d2b4d3SLarry Finger for (index = 0; index < 6; index++) { 416f1d2b4d3SLarry Finger get_txpower_writeval_by_reg(hw, channel, index, &powerbase0[0], 417f1d2b4d3SLarry Finger &powerbase1[0], 418f1d2b4d3SLarry Finger &writeval[0]); 419f1d2b4d3SLarry Finger 420f1d2b4d3SLarry Finger _rtl8723e_write_ofdm_power_reg(hw, index, &writeval[0]); 421f1d2b4d3SLarry Finger } 422f1d2b4d3SLarry Finger } 423f1d2b4d3SLarry Finger 424f1d2b4d3SLarry Finger bool rtl8723e_phy_rf6052_config(struct ieee80211_hw *hw) 425f1d2b4d3SLarry Finger { 426f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 427f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 428f1d2b4d3SLarry Finger 429f1d2b4d3SLarry Finger if (rtlphy->rf_type == RF_1T1R) 430f1d2b4d3SLarry Finger rtlphy->num_total_rfpath = 1; 431f1d2b4d3SLarry Finger else 432f1d2b4d3SLarry Finger rtlphy->num_total_rfpath = 2; 433f1d2b4d3SLarry Finger 434f1d2b4d3SLarry Finger return _rtl8723e_phy_rf6052_config_parafile(hw); 435f1d2b4d3SLarry Finger } 436f1d2b4d3SLarry Finger 437f1d2b4d3SLarry Finger static bool _rtl8723e_phy_rf6052_config_parafile(struct ieee80211_hw *hw) 438f1d2b4d3SLarry Finger { 439f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 440f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &rtlpriv->phy; 441f1d2b4d3SLarry Finger u32 u4_regvalue = 0; 442f1d2b4d3SLarry Finger u8 rfpath; 443f1d2b4d3SLarry Finger bool rtstatus = true; 444f1d2b4d3SLarry Finger struct bb_reg_def *pphyreg; 445f1d2b4d3SLarry Finger 446f1d2b4d3SLarry Finger for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { 447f1d2b4d3SLarry Finger 448f1d2b4d3SLarry Finger pphyreg = &rtlphy->phyreg_def[rfpath]; 449f1d2b4d3SLarry Finger 450f1d2b4d3SLarry Finger switch (rfpath) { 451f1d2b4d3SLarry Finger case RF90_PATH_A: 452f1d2b4d3SLarry Finger case RF90_PATH_C: 453f1d2b4d3SLarry Finger u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs, 454f1d2b4d3SLarry Finger BRFSI_RFENV); 455f1d2b4d3SLarry Finger break; 456f1d2b4d3SLarry Finger case RF90_PATH_B: 457f1d2b4d3SLarry Finger case RF90_PATH_D: 458f1d2b4d3SLarry Finger u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs, 459f1d2b4d3SLarry Finger BRFSI_RFENV << 16); 460f1d2b4d3SLarry Finger break; 461f1d2b4d3SLarry Finger } 462f1d2b4d3SLarry Finger 463f1d2b4d3SLarry Finger rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1); 464f1d2b4d3SLarry Finger udelay(1); 465f1d2b4d3SLarry Finger 466f1d2b4d3SLarry Finger rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1); 467f1d2b4d3SLarry Finger udelay(1); 468f1d2b4d3SLarry Finger 469f1d2b4d3SLarry Finger rtl_set_bbreg(hw, pphyreg->rfhssi_para2, 470f1d2b4d3SLarry Finger B3WIREADDREAALENGTH, 0x0); 471f1d2b4d3SLarry Finger udelay(1); 472f1d2b4d3SLarry Finger 473f1d2b4d3SLarry Finger rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0); 474f1d2b4d3SLarry Finger udelay(1); 475f1d2b4d3SLarry Finger 476f1d2b4d3SLarry Finger switch (rfpath) { 477f1d2b4d3SLarry Finger case RF90_PATH_A: 478f1d2b4d3SLarry Finger rtstatus = rtl8723e_phy_config_rf_with_headerfile(hw, 479f1d2b4d3SLarry Finger (enum radio_path)rfpath); 480f1d2b4d3SLarry Finger break; 481f1d2b4d3SLarry Finger case RF90_PATH_B: 482f1d2b4d3SLarry Finger rtstatus = 483f1d2b4d3SLarry Finger rtl8723e_phy_config_rf_with_headerfile(hw, 484f1d2b4d3SLarry Finger (enum radio_path)rfpath); 485f1d2b4d3SLarry Finger break; 486f1d2b4d3SLarry Finger case RF90_PATH_C: 487f1d2b4d3SLarry Finger break; 488f1d2b4d3SLarry Finger case RF90_PATH_D: 489f1d2b4d3SLarry Finger break; 490f1d2b4d3SLarry Finger } 491f1d2b4d3SLarry Finger 492f1d2b4d3SLarry Finger switch (rfpath) { 493f1d2b4d3SLarry Finger case RF90_PATH_A: 494f1d2b4d3SLarry Finger case RF90_PATH_C: 495f1d2b4d3SLarry Finger rtl_set_bbreg(hw, pphyreg->rfintfs, 496f1d2b4d3SLarry Finger BRFSI_RFENV, u4_regvalue); 497f1d2b4d3SLarry Finger break; 498f1d2b4d3SLarry Finger case RF90_PATH_B: 499f1d2b4d3SLarry Finger case RF90_PATH_D: 500f1d2b4d3SLarry Finger rtl_set_bbreg(hw, pphyreg->rfintfs, 501f1d2b4d3SLarry Finger BRFSI_RFENV << 16, u4_regvalue); 502f1d2b4d3SLarry Finger break; 503f1d2b4d3SLarry Finger } 504f1d2b4d3SLarry Finger 505f1d2b4d3SLarry Finger if (rtstatus != true) { 506f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 507*4713bd1cSJoe Perches "Radio[%d] Fail!!\n", rfpath); 508f1d2b4d3SLarry Finger return false; 509f1d2b4d3SLarry Finger } 510f1d2b4d3SLarry Finger } 511f1d2b4d3SLarry Finger 512f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "\n"); 513f1d2b4d3SLarry Finger return rtstatus; 514f1d2b4d3SLarry Finger } 515