George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | c1d6604 | 2012-01-07 20:46:45 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 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" |
| 32 | #include "reg.h" |
| 33 | #include "def.h" |
| 34 | #include "phy.h" |
| 35 | #include "dm.h" |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 36 | |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 37 | void rtl92cu_dm_dynamic_txpower(struct ieee80211_hw *hw) |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 38 | { |
| 39 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 40 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 41 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 42 | long undec_sm_pwdb; |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 43 | |
| 44 | if (!rtlpriv->dm.dynamic_txpower_enable) |
| 45 | return; |
| 46 | |
| 47 | if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) { |
| 48 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if ((mac->link_state < MAC80211_LINKED) && |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 53 | (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) { |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 54 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 55 | "Not connected to any\n"); |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 56 | |
| 57 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 58 | |
| 59 | rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if (mac->link_state >= MAC80211_LINKED) { |
| 64 | if (mac->opmode == NL80211_IFTYPE_ADHOC) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 65 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 66 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 67 | "AP Client PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 68 | undec_sm_pwdb); |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 69 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 70 | undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 71 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 72 | "STA Default Port PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 73 | undec_sm_pwdb); |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 74 | } |
| 75 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 76 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 77 | |
| 78 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 79 | "AP Ext Port PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 80 | undec_sm_pwdb); |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 81 | } |
| 82 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 83 | if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) { |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 84 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
| 85 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 86 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n"); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 87 | } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) && |
| 88 | (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL1)) { |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 89 | |
| 90 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
| 91 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 92 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n"); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 93 | } else if (undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) { |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 94 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 95 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 96 | "TXHIGHPWRLEVEL_NORMAL\n"); |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) { |
| 100 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 101 | "PHY_SetTxPowerLevel8192S() Channel = %d\n", |
| 102 | rtlphy->current_channel); |
George | 442888c | 2011-02-19 16:29:17 -0600 | [diff] [blame] | 103 | rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel); |
| 104 | } |
| 105 | |
| 106 | rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl; |
| 107 | } |