1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include "../wifi.h"
31#include "../base.h"
32#include "../pci.h"
33#include "reg.h"
34#include "def.h"
35#include "phy.h"
36#include "dm.h"
37#include "../rtl8192c/fw_common.h"
38
39void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw)
40{
41 struct rtl_priv *rtlpriv = rtl_priv(hw);
42 struct rtl_phy *rtlphy = &(rtlpriv->phy);
43 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
44 long undec_sm_pwdb;
45
46 if (!rtlpriv->dm.dynamic_txpower_enable)
47 return;
48
49 if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) {
50 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
51 return;
52 }
53
54 if ((mac->link_state < MAC80211_LINKED) &&
55 (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) {
56 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
57 "Not connected to any\n");
58
59 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
60
61 rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
62 return;
63 }
64
65 if (mac->link_state >= MAC80211_LINKED) {
66 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
67 undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb;
68 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
69 "AP Client PWDB = 0x%lx\n",
70 undec_sm_pwdb);
71 } else {
72 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
73 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
74 "STA Default Port PWDB = 0x%lx\n",
75 undec_sm_pwdb);
76 }
77 } else {
78 undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb;
79
80 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
81 "AP Ext Port PWDB = 0x%lx\n",
82 undec_sm_pwdb);
83 }
84
85 if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) {
86 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
87 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
88 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
89 } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) &&
90 (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL1)) {
91
92 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
93 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
94 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
95 } else if (undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) {
96 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
97 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
98 "TXHIGHPWRLEVEL_NORMAL\n");
99 }
100
101 if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) {
102 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
103 "PHY_SetTxPowerLevel8192S() Channel = %d\n",
104 rtlphy->current_channel);
105 rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
106 }
107
108 rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
109}
110