Commit | Line | Data |
---|---|---|
0c817338 LF |
1 | /****************************************************************************** |
2 | * | |
9003a4ab | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
0c817338 LF |
4 | * |
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. | |
8 | * | |
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 | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | |
17 | * | |
18 | * The full GNU General Public License is included in this distribution in the | |
19 | * file called LICENSE. | |
20 | * | |
21 | * Contact Information: | |
22 | * wlanfae <wlanfae@realtek.com> | |
23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | |
24 | * Hsinchu 300, Taiwan. | |
25 | * | |
26 | * Larry Finger <Larry.Finger@lwfinger.net> | |
27 | * | |
28 | *****************************************************************************/ | |
29 | ||
30 | #include "../wifi.h" | |
31 | #include "../base.h" | |
2b8359f8 | 32 | #include "../pci.h" |
6f8214b6 | 33 | #include "../core.h" |
5c405b5c JL |
34 | #include "reg.h" |
35 | #include "def.h" | |
36 | #include "phy.h" | |
37 | #include "dm.h" | |
2b8359f8 | 38 | #include "../rtl8192c/fw_common.h" |
0c817338 | 39 | |
1472d3a8 | 40 | void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw) |
0c817338 LF |
41 | { |
42 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
43 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | |
44 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
da17fcff | 45 | long undec_sm_pwdb; |
0c817338 | 46 | |
7ea47240 | 47 | if (!rtlpriv->dm.dynamic_txpower_enable) |
0c817338 LF |
48 | return; |
49 | ||
50 | if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) { | |
51 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; | |
52 | return; | |
53 | } | |
54 | ||
55 | if ((mac->link_state < MAC80211_LINKED) && | |
da17fcff | 56 | (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) { |
0c817338 | 57 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
f30d7507 | 58 | "Not connected to any\n"); |
0c817338 LF |
59 | |
60 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; | |
61 | ||
62 | rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL; | |
63 | return; | |
64 | } | |
65 | ||
66 | if (mac->link_state >= MAC80211_LINKED) { | |
67 | if (mac->opmode == NL80211_IFTYPE_ADHOC) { | |
da17fcff | 68 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
0c817338 | 69 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
f30d7507 | 70 | "AP Client PWDB = 0x%lx\n", |
da17fcff | 71 | undec_sm_pwdb); |
0c817338 | 72 | } else { |
da17fcff | 73 | undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; |
0c817338 | 74 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
f30d7507 | 75 | "STA Default Port PWDB = 0x%lx\n", |
da17fcff | 76 | undec_sm_pwdb); |
0c817338 LF |
77 | } |
78 | } else { | |
da17fcff | 79 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
0c817338 LF |
80 | |
81 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | |
f30d7507 | 82 | "AP Ext Port PWDB = 0x%lx\n", |
da17fcff | 83 | undec_sm_pwdb); |
0c817338 LF |
84 | } |
85 | ||
da17fcff | 86 | if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) { |
0c817338 LF |
87 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
88 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | |
f30d7507 | 89 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n"); |
da17fcff LF |
90 | } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) && |
91 | (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL1)) { | |
0c817338 LF |
92 | |
93 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; | |
94 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | |
f30d7507 | 95 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n"); |
da17fcff | 96 | } else if (undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) { |
0c817338 LF |
97 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
98 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | |
f30d7507 | 99 | "TXHIGHPWRLEVEL_NORMAL\n"); |
0c817338 LF |
100 | } |
101 | ||
102 | if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) { | |
103 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | |
f30d7507 JP |
104 | "PHY_SetTxPowerLevel8192S() Channel = %d\n", |
105 | rtlphy->current_channel); | |
0c817338 LF |
106 | rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel); |
107 | } | |
108 | ||
109 | rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl; | |
110 | } |