10770f718SLarry Finger // SPDX-License-Identifier: GPL-2.0
20770f718SLarry Finger /* Copyright(c) 2009-2012 Realtek Corporation.*/
3f1d2b4d3SLarry Finger
4f1d2b4d3SLarry Finger #include "../wifi.h"
5f1d2b4d3SLarry Finger #include "../base.h"
6f1d2b4d3SLarry Finger #include "../pci.h"
7f1d2b4d3SLarry Finger #include "../core.h"
8f1d2b4d3SLarry Finger #include "reg.h"
9f1d2b4d3SLarry Finger #include "def.h"
10f1d2b4d3SLarry Finger #include "phy.h"
11f1d2b4d3SLarry Finger #include "dm.h"
12f1d2b4d3SLarry Finger #include "../rtl8192c/fw_common.h"
13f1d2b4d3SLarry Finger
rtl92ce_dm_dynamic_txpower(struct ieee80211_hw * hw)14f1d2b4d3SLarry Finger void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw)
15f1d2b4d3SLarry Finger {
16f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
17f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy);
18f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
19f1d2b4d3SLarry Finger long undec_sm_pwdb;
20f1d2b4d3SLarry Finger
21f1d2b4d3SLarry Finger if (!rtlpriv->dm.dynamic_txpower_enable)
22f1d2b4d3SLarry Finger return;
23f1d2b4d3SLarry Finger
24f1d2b4d3SLarry Finger if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) {
25f1d2b4d3SLarry Finger rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
26f1d2b4d3SLarry Finger return;
27f1d2b4d3SLarry Finger }
28f1d2b4d3SLarry Finger
29f1d2b4d3SLarry Finger if ((mac->link_state < MAC80211_LINKED) &&
30f1d2b4d3SLarry Finger (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) {
31*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_TRACE,
32f1d2b4d3SLarry Finger "Not connected to any\n");
33f1d2b4d3SLarry Finger
34f1d2b4d3SLarry Finger rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
35f1d2b4d3SLarry Finger
36f1d2b4d3SLarry Finger rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
37f1d2b4d3SLarry Finger return;
38f1d2b4d3SLarry Finger }
39f1d2b4d3SLarry Finger
40f1d2b4d3SLarry Finger if (mac->link_state >= MAC80211_LINKED) {
41f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_ADHOC) {
42f1d2b4d3SLarry Finger undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb;
43*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
44f1d2b4d3SLarry Finger "AP Client PWDB = 0x%lx\n",
45f1d2b4d3SLarry Finger undec_sm_pwdb);
46f1d2b4d3SLarry Finger } else {
47f1d2b4d3SLarry Finger undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
48*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
49f1d2b4d3SLarry Finger "STA Default Port PWDB = 0x%lx\n",
50f1d2b4d3SLarry Finger undec_sm_pwdb);
51f1d2b4d3SLarry Finger }
52f1d2b4d3SLarry Finger } else {
53f1d2b4d3SLarry Finger undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb;
54f1d2b4d3SLarry Finger
55*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
56f1d2b4d3SLarry Finger "AP Ext Port PWDB = 0x%lx\n",
57f1d2b4d3SLarry Finger undec_sm_pwdb);
58f1d2b4d3SLarry Finger }
59f1d2b4d3SLarry Finger
60f1d2b4d3SLarry Finger if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) {
61f1d2b4d3SLarry Finger rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
62*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
63f1d2b4d3SLarry Finger "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
64f1d2b4d3SLarry Finger } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) &&
65f1d2b4d3SLarry Finger (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL1)) {
66f1d2b4d3SLarry Finger
67f1d2b4d3SLarry Finger rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
68*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
69f1d2b4d3SLarry Finger "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
70f1d2b4d3SLarry Finger } else if (undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) {
71f1d2b4d3SLarry Finger rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
72*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
73f1d2b4d3SLarry Finger "TXHIGHPWRLEVEL_NORMAL\n");
74f1d2b4d3SLarry Finger }
75f1d2b4d3SLarry Finger
76f1d2b4d3SLarry Finger if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) {
77*de0c8a96SLarry Finger rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
78f1d2b4d3SLarry Finger "PHY_SetTxPowerLevel8192S() Channel = %d\n",
79f1d2b4d3SLarry Finger rtlphy->current_channel);
80f1d2b4d3SLarry Finger rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
81f1d2b4d3SLarry Finger }
82f1d2b4d3SLarry Finger
83f1d2b4d3SLarry Finger rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
84f1d2b4d3SLarry Finger }
85