Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | 9003a4a | 2012-01-07 20:46:44 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -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" |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 32 | #include "../pci.h" |
John W. Linville | 5c405b5 | 2010-12-16 15:43:36 -0500 | [diff] [blame] | 33 | #include "reg.h" |
| 34 | #include "def.h" |
| 35 | #include "phy.h" |
| 36 | #include "dm.h" |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 37 | #include "../rtl8192c/fw_common.h" |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 38 | |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 39 | void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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 undecorated_smoothed_pwdb; |
| 45 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 46 | if (!rtlpriv->dm.dynamic_txpower_enable) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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_undecoratedsmoothed_pwdb == 0)) { |
| 56 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 57 | "Not connected to any\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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 | undecorated_smoothed_pwdb = |
| 68 | rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb; |
| 69 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 70 | "AP Client PWDB = 0x%lx\n", |
| 71 | undecorated_smoothed_pwdb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 72 | } else { |
| 73 | undecorated_smoothed_pwdb = |
| 74 | rtlpriv->dm.undecorated_smoothed_pwdb; |
| 75 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 76 | "STA Default Port PWDB = 0x%lx\n", |
| 77 | undecorated_smoothed_pwdb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 78 | } |
| 79 | } else { |
| 80 | undecorated_smoothed_pwdb = |
| 81 | rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb; |
| 82 | |
| 83 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 84 | "AP Ext Port PWDB = 0x%lx\n", |
| 85 | undecorated_smoothed_pwdb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | if (undecorated_smoothed_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) { |
| 89 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
| 90 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 91 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 92 | } else if ((undecorated_smoothed_pwdb < |
| 93 | (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) && |
| 94 | (undecorated_smoothed_pwdb >= |
| 95 | TX_POWER_NEAR_FIELD_THRESH_LVL1)) { |
| 96 | |
| 97 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
| 98 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 99 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 100 | } else if (undecorated_smoothed_pwdb < |
| 101 | (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) { |
| 102 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 103 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 104 | "TXHIGHPWRLEVEL_NORMAL\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) { |
| 108 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 109 | "PHY_SetTxPowerLevel8192S() Channel = %d\n", |
| 110 | rtlphy->current_channel); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 111 | rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel); |
| 112 | } |
| 113 | |
| 114 | rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl; |
| 115 | } |