1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
12 #include "../rtl8192c/fw_common.h"
14 void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw
*hw
)
16 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
17 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
18 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
21 if (!rtlpriv
->dm
.dynamic_txpower_enable
)
24 if (rtlpriv
->dm
.dm_flag
& HAL_DM_HIPWR_DISABLE
) {
25 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_NORMAL
;
29 if ((mac
->link_state
< MAC80211_LINKED
) &&
30 (rtlpriv
->dm
.entry_min_undec_sm_pwdb
== 0)) {
31 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
32 "Not connected to any\n");
34 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_NORMAL
;
36 rtlpriv
->dm
.last_dtp_lvl
= TXHIGHPWRLEVEL_NORMAL
;
40 if (mac
->link_state
>= MAC80211_LINKED
) {
41 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
42 undec_sm_pwdb
= rtlpriv
->dm
.entry_min_undec_sm_pwdb
;
43 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
44 "AP Client PWDB = 0x%lx\n",
47 undec_sm_pwdb
= rtlpriv
->dm
.undec_sm_pwdb
;
48 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
49 "STA Default Port PWDB = 0x%lx\n",
53 undec_sm_pwdb
= rtlpriv
->dm
.entry_min_undec_sm_pwdb
;
55 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
56 "AP Ext Port PWDB = 0x%lx\n",
60 if (undec_sm_pwdb
>= TX_POWER_NEAR_FIELD_THRESH_LVL2
) {
61 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_LEVEL1
;
62 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
63 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
64 } else if ((undec_sm_pwdb
< (TX_POWER_NEAR_FIELD_THRESH_LVL2
- 3)) &&
65 (undec_sm_pwdb
>= TX_POWER_NEAR_FIELD_THRESH_LVL1
)) {
67 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_LEVEL1
;
68 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
69 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
70 } else if (undec_sm_pwdb
< (TX_POWER_NEAR_FIELD_THRESH_LVL1
- 5)) {
71 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_NORMAL
;
72 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
73 "TXHIGHPWRLEVEL_NORMAL\n");
76 if ((rtlpriv
->dm
.dynamic_txhighpower_lvl
!= rtlpriv
->dm
.last_dtp_lvl
)) {
77 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
78 "PHY_SetTxPowerLevel8192S() Channel = %d\n",
79 rtlphy
->current_channel
);
80 rtl92c_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
83 rtlpriv
->dm
.last_dtp_lvl
= rtlpriv
->dm
.dynamic_txhighpower_lvl
;