dm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "../wifi.h"
  26. #include "../base.h"
  27. #include "../pci.h"
  28. #include "../core.h"
  29. #include "reg.h"
  30. #include "def.h"
  31. #include "phy.h"
  32. #include "dm.h"
  33. #include "../rtl8192c/fw_common.h"
  34. void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw)
  35. {
  36. struct rtl_priv *rtlpriv = rtl_priv(hw);
  37. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  38. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  39. long undec_sm_pwdb;
  40. if (!rtlpriv->dm.dynamic_txpower_enable)
  41. return;
  42. if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) {
  43. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
  44. return;
  45. }
  46. if ((mac->link_state < MAC80211_LINKED) &&
  47. (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) {
  48. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  49. "Not connected to any\n");
  50. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
  51. rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
  52. return;
  53. }
  54. if (mac->link_state >= MAC80211_LINKED) {
  55. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  56. undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb;
  57. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  58. "AP Client PWDB = 0x%lx\n",
  59. undec_sm_pwdb);
  60. } else {
  61. undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
  62. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  63. "STA Default Port PWDB = 0x%lx\n",
  64. undec_sm_pwdb);
  65. }
  66. } else {
  67. undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb;
  68. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  69. "AP Ext Port PWDB = 0x%lx\n",
  70. undec_sm_pwdb);
  71. }
  72. if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) {
  73. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
  74. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  75. "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
  76. } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) &&
  77. (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL1)) {
  78. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
  79. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  80. "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
  81. } else if (undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) {
  82. rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
  83. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  84. "TXHIGHPWRLEVEL_NORMAL\n");
  85. }
  86. if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) {
  87. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  88. "PHY_SetTxPowerLevel8192S() Channel = %d\n",
  89. rtlphy->current_channel);
  90. rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
  91. }
  92. rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
  93. }