1 /******************************************************************************
3 * Copyright(c) 2009-2014 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
33 static bool _rtl8723be_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
35 void rtl8723be_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
37 struct rtl_priv *rtlpriv = rtl_priv(hw);
38 struct rtl_phy *rtlphy = &(rtlpriv->phy);
41 case HT_CHANNEL_WIDTH_20:
42 rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
43 0xfffff3ff) | BIT(10) | BIT(11));
44 rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
45 rtlphy->rfreg_chnlval[0]);
47 case HT_CHANNEL_WIDTH_20_40:
48 rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
49 0xfffff3ff) | BIT(10));
50 rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
51 rtlphy->rfreg_chnlval[0]);
54 pr_err("unknown bandwidth: %#X\n", bandwidth);
59 void rtl8723be_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
62 struct rtl_priv *rtlpriv = rtl_priv(hw);
63 struct rtl_phy *rtlphy = &(rtlpriv->phy);
64 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
65 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
66 u32 tx_agc[2] = {0, 0}, tmpval;
67 bool turbo_scanoff = false;
73 if (rtlefuse->eeprom_regulatory != 0)
76 if (mac->act_scanning) {
77 tx_agc[RF90_PATH_A] = 0x3f3f3f3f;
78 tx_agc[RF90_PATH_B] = 0x3f3f3f3f;
81 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
82 tx_agc[idx1] = ppowerlevel[idx1] |
83 (ppowerlevel[idx1] << 8) |
84 (ppowerlevel[idx1] << 16) |
85 (ppowerlevel[idx1] << 24);
89 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
90 tx_agc[idx1] = ppowerlevel[idx1] |
91 (ppowerlevel[idx1] << 8) |
92 (ppowerlevel[idx1] << 16) |
93 (ppowerlevel[idx1] << 24);
96 if (rtlefuse->eeprom_regulatory == 0) {
98 (rtlphy->mcs_txpwrlevel_origoffset[0][6]) +
99 (rtlphy->mcs_txpwrlevel_origoffset[0][7] << 8);
100 tx_agc[RF90_PATH_A] += tmpval;
102 tmpval = (rtlphy->mcs_txpwrlevel_origoffset[0][14]) +
103 (rtlphy->mcs_txpwrlevel_origoffset[0][15] <<
105 tx_agc[RF90_PATH_B] += tmpval;
109 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
110 ptr = (u8 *)(&(tx_agc[idx1]));
111 for (idx2 = 0; idx2 < 4; idx2++) {
112 if (*ptr > RF6052_MAX_TX_PWR)
113 *ptr = RF6052_MAX_TX_PWR;
117 rtl8723be_dm_txpower_track_adjust(hw, 1, &direction, &pwrtrac_value);
118 if (direction == 1) {
119 tx_agc[0] += pwrtrac_value;
120 tx_agc[1] += pwrtrac_value;
121 } else if (direction == 2) {
122 tx_agc[0] -= pwrtrac_value;
123 tx_agc[1] -= pwrtrac_value;
125 tmpval = tx_agc[RF90_PATH_A] & 0xff;
126 rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, MASKBYTE1, tmpval);
128 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
129 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval,
130 RTXAGC_A_CCK1_MCS32);
132 tmpval = tx_agc[RF90_PATH_A] >> 8;
134 /*tmpval = tmpval & 0xff00ffff;*/
136 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
138 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
139 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval,
140 RTXAGC_B_CCK11_A_CCK2_11);
142 tmpval = tx_agc[RF90_PATH_B] >> 24;
143 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, MASKBYTE0, tmpval);
145 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
146 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval,
147 RTXAGC_B_CCK11_A_CCK2_11);
149 tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff;
150 rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval);
152 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
153 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval,
154 RTXAGC_B_CCK1_55_MCS32);
157 static void rtl8723be_phy_get_power_base(struct ieee80211_hw *hw,
158 u8 *ppowerlevel_ofdm,
159 u8 *ppowerlevel_bw20,
160 u8 *ppowerlevel_bw40,
161 u8 channel, u32 *ofdmbase,
164 struct rtl_priv *rtlpriv = rtl_priv(hw);
165 struct rtl_phy *rtlphy = &(rtlpriv->phy);
166 u32 powerbase0, powerbase1;
169 for (i = 0; i < 2; i++) {
170 powerbase0 = ppowerlevel_ofdm[i];
172 powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) |
173 (powerbase0 << 8) | powerbase0;
174 *(ofdmbase + i) = powerbase0;
175 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
176 " [OFDM power base index rf(%c) = 0x%x]\n",
177 ((i == 0) ? 'A' : 'B'), *(ofdmbase + i));
180 for (i = 0; i < 2; i++) {
181 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20)
182 powerlevel[i] = ppowerlevel_bw20[i];
184 powerlevel[i] = ppowerlevel_bw40[i];
186 powerbase1 = powerlevel[i];
187 powerbase1 = (powerbase1 << 24) | (powerbase1 << 16) |
188 (powerbase1 << 8) | powerbase1;
190 *(mcsbase + i) = powerbase1;
192 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
193 " [MCS power base index rf(%c) = 0x%x]\n",
194 ((i == 0) ? 'A' : 'B'), *(mcsbase + i));
198 static void _rtl8723be_get_txpower_writeval_by_regulatory(
199 struct ieee80211_hw *hw,
200 u8 channel, u8 index,
205 struct rtl_priv *rtlpriv = rtl_priv(hw);
206 struct rtl_phy *rtlphy = &(rtlpriv->phy);
207 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
208 u8 i, chnlgroup = 0, pwr_diff_limit[4], pwr_diff = 0, customer_pwr_diff;
209 u32 writeval, customer_limit, rf;
211 for (rf = 0; rf < 2; rf++) {
212 switch (rtlefuse->eeprom_regulatory) {
217 rtlphy->mcs_txpwrlevel_origoffset[chnlgroup][index +
219 + ((index < 2) ? powerbase0[rf] : powerbase1[rf]);
221 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
222 "RTK better performance, writeval(%c) = 0x%x\n",
223 ((rf == 0) ? 'A' : 'B'), writeval);
226 if (rtlphy->pwrgroup_cnt == 1) {
231 else if (channel < 6)
233 else if (channel < 9)
235 else if (channel < 12)
237 else if (channel < 14)
239 else if (channel == 14)
244 rtlphy->mcs_txpwrlevel_origoffset[chnlgroup]
245 [index + (rf ? 8 : 0)] + ((index < 2) ?
249 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
250 "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n",
251 ((rf == 0) ? 'A' : 'B'), writeval);
256 ((index < 2) ? powerbase0[rf] : powerbase1[rf]);
258 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
259 "Better regulatory, writeval(%c) = 0x%x\n",
260 ((rf == 0) ? 'A' : 'B'), writeval);
265 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
266 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
267 "customer's limit, 40MHz rf(%c) = 0x%x\n",
268 ((rf == 0) ? 'A' : 'B'),
269 rtlefuse->pwrgroup_ht40
272 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
273 "customer's limit, 20MHz rf(%c) = 0x%x\n",
274 ((rf == 0) ? 'A' : 'B'),
275 rtlefuse->pwrgroup_ht20
281 rtlefuse->txpwr_legacyhtdiff[rf][channel-1];
282 else if (rtlphy->current_chan_bw ==
285 rtlefuse->txpwr_ht20diff[rf][channel-1];
287 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40)
289 rtlefuse->pwrgroup_ht40[rf][channel-1];
292 rtlefuse->pwrgroup_ht20[rf][channel-1];
294 if (pwr_diff > customer_pwr_diff)
297 pwr_diff = customer_pwr_diff - pwr_diff;
299 for (i = 0; i < 4; i++) {
301 (u8)((rtlphy->mcs_txpwrlevel_origoffset
302 [chnlgroup][index + (rf ? 8 : 0)] &
303 (0x7f << (i * 8))) >> (i * 8));
305 if (pwr_diff_limit[i] > pwr_diff)
306 pwr_diff_limit[i] = pwr_diff;
309 customer_limit = (pwr_diff_limit[3] << 24) |
310 (pwr_diff_limit[2] << 16) |
311 (pwr_diff_limit[1] << 8) |
314 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
315 "Customer's limit rf(%c) = 0x%x\n",
316 ((rf == 0) ? 'A' : 'B'), customer_limit);
318 writeval = customer_limit + ((index < 2) ?
322 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
323 "Customer, writeval rf(%c)= 0x%x\n",
324 ((rf == 0) ? 'A' : 'B'), writeval);
329 rtlphy->mcs_txpwrlevel_origoffset[chnlgroup]
330 [index + (rf ? 8 : 0)]
331 + ((index < 2) ? powerbase0[rf] : powerbase1[rf]);
333 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
334 "RTK better performance, writeval rf(%c) = 0x%x\n",
335 ((rf == 0) ? 'A' : 'B'), writeval);
339 if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1)
340 writeval = writeval - 0x06060606;
341 else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
343 writeval = writeval - 0x0c0c0c0c;
344 *(p_outwriteval + rf) = writeval;
348 static void _rtl8723be_write_ofdm_power_reg(struct ieee80211_hw *hw,
349 u8 index, u32 *pvalue)
351 struct rtl_priv *rtlpriv = rtl_priv(hw);
352 u16 regoffset_a[6] = {
353 RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24,
354 RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04,
355 RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12
357 u16 regoffset_b[6] = {
358 RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24,
359 RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04,
360 RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12
362 u8 i, rf, pwr_val[4];
366 for (rf = 0; rf < 2; rf++) {
367 writeval = pvalue[rf];
368 for (i = 0; i < 4; i++) {
369 pwr_val[i] = (u8)((writeval & (0x7f <<
370 (i * 8))) >> (i * 8));
372 if (pwr_val[i] > RF6052_MAX_TX_PWR)
373 pwr_val[i] = RF6052_MAX_TX_PWR;
375 writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) |
376 (pwr_val[1] << 8) | pwr_val[0];
379 regoffset = regoffset_a[index];
381 regoffset = regoffset_b[index];
382 rtl_set_bbreg(hw, regoffset, MASKDWORD, writeval);
384 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
385 "Set 0x%x = %08x\n", regoffset, writeval);
389 void rtl8723be_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
390 u8 *ppowerlevel_ofdm,
391 u8 *ppowerlevel_bw20,
392 u8 *ppowerlevel_bw40, u8 channel)
394 u32 writeval[2], powerbase0[2], powerbase1[2];
399 rtl8723be_phy_get_power_base(hw, ppowerlevel_ofdm, ppowerlevel_bw20,
400 ppowerlevel_bw40, channel,
401 &powerbase0[0], &powerbase1[0]);
403 rtl8723be_dm_txpower_track_adjust(hw, 1, &direction, &pwrtrac_value);
405 for (index = 0; index < 6; index++) {
406 _rtl8723be_get_txpower_writeval_by_regulatory(hw,
411 if (direction == 1) {
412 writeval[0] += pwrtrac_value;
413 writeval[1] += pwrtrac_value;
414 } else if (direction == 2) {
415 writeval[0] -= pwrtrac_value;
416 writeval[1] -= pwrtrac_value;
418 _rtl8723be_write_ofdm_power_reg(hw, index, &writeval[0]);
422 bool rtl8723be_phy_rf6052_config(struct ieee80211_hw *hw)
424 struct rtl_priv *rtlpriv = rtl_priv(hw);
425 struct rtl_phy *rtlphy = &(rtlpriv->phy);
427 if (rtlphy->rf_type == RF_1T1R)
428 rtlphy->num_total_rfpath = 1;
430 rtlphy->num_total_rfpath = 2;
432 return _rtl8723be_phy_rf6052_config_parafile(hw);
436 static bool _rtl8723be_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
438 struct rtl_priv *rtlpriv = rtl_priv(hw);
439 struct rtl_phy *rtlphy = &(rtlpriv->phy);
442 bool rtstatus = true;
443 struct bb_reg_def *pphyreg;
445 for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
446 pphyreg = &rtlphy->phyreg_def[rfpath];
451 u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
456 u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
461 rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
464 rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
467 rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
468 B3WIREADDREAALENGTH, 0x0);
471 rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
476 rtstatus = rtl8723be_phy_config_rf_with_headerfile(hw,
477 (enum radio_path)rfpath);
480 rtstatus = rtl8723be_phy_config_rf_with_headerfile(hw,
481 (enum radio_path)rfpath);
492 rtl_set_bbreg(hw, pphyreg->rfintfs,
493 BRFSI_RFENV, u4_regvalue);
497 rtl_set_bbreg(hw, pphyreg->rfintfs,
498 BRFSI_RFENV << 16, u4_regvalue);
503 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
504 "Radio[%d] Fail!!\n", rfpath);
509 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "\n");