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