dm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 Realtek Corporation.
  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. #include "../wifi.h"
  30. #include "../base.h"
  31. #include "reg.h"
  32. #include "def.h"
  33. #include "phy.h"
  34. #include "dm.h"
  35. void rtl92cu_dm_dynamic_txpower(struct ieee80211_hw *hw)
  36. {
  37. struct rtl_priv *rtlpriv = rtl_priv(hw);
  38. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  39. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  40. long undecorated_smoothed_pwdb;
  41. if (!rtlpriv->dm.dynamic_txpower_enable)
  42. return;
  43. if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) {
  44. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
  45. return;
  46. }
  47. if ((mac->link_state < MAC80211_LINKED) &&
  48. (rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb == 0)) {
  49. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  50. ("Not connected to any\n"));
  51. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
  52. rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
  53. return;
  54. }
  55. if (mac->link_state >= MAC80211_LINKED) {
  56. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  57. undecorated_smoothed_pwdb =
  58. rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb;
  59. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  60. ("AP Client PWDB = 0x%lx\n",
  61. undecorated_smoothed_pwdb));
  62. } else {
  63. undecorated_smoothed_pwdb =
  64. rtlpriv->dm.undecorated_smoothed_pwdb;
  65. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  66. ("STA Default Port PWDB = 0x%lx\n",
  67. undecorated_smoothed_pwdb));
  68. }
  69. } else {
  70. undecorated_smoothed_pwdb =
  71. rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb;
  72. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  73. ("AP Ext Port PWDB = 0x%lx\n",
  74. undecorated_smoothed_pwdb));
  75. }
  76. if (undecorated_smoothed_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) {
  77. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
  78. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  79. ("TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n"));
  80. } else if ((undecorated_smoothed_pwdb <
  81. (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) &&
  82. (undecorated_smoothed_pwdb >=
  83. TX_POWER_NEAR_FIELD_THRESH_LVL1)) {
  84. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
  85. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  86. ("TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n"));
  87. } else if (undecorated_smoothed_pwdb <
  88. (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) {
  89. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
  90. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  91. ("TXHIGHPWRLEVEL_NORMAL\n"));
  92. }
  93. if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) {
  94. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  95. ("PHY_SetTxPowerLevel8192S() Channel = %d\n",
  96. rtlphy->current_channel));
  97. rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
  98. }
  99. rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
  100. }