xref: /openbmc/linux/drivers/net/wireless/realtek/rtlwifi/rtl8192c/phy_common.c (revision 1188f7f111c61394ec56beb8e30322305a8220b6)
1e7011369SLarry Finger // SPDX-License-Identifier: GPL-2.0
2e7011369SLarry Finger /* Copyright(c) 2009-2012  Realtek Corporation.*/
3f1d2b4d3SLarry Finger 
4f1d2b4d3SLarry Finger #include "../wifi.h"
5f1d2b4d3SLarry Finger #include "../rtl8192ce/reg.h"
6f1d2b4d3SLarry Finger #include "../rtl8192ce/def.h"
7f1d2b4d3SLarry Finger #include "dm_common.h"
8f1d2b4d3SLarry Finger #include "fw_common.h"
9f1d2b4d3SLarry Finger #include "phy_common.h"
10f1d2b4d3SLarry Finger #include <linux/export.h>
11f1d2b4d3SLarry Finger 
rtl92c_phy_query_bb_reg(struct ieee80211_hw * hw,u32 regaddr,u32 bitmask)12f1d2b4d3SLarry Finger u32 rtl92c_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask)
13f1d2b4d3SLarry Finger {
14f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
15f1d2b4d3SLarry Finger 	u32 returnvalue, originalvalue, bitshift;
16f1d2b4d3SLarry Finger 
175b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, "regaddr(%#x), bitmask(%#x)\n",
18f1d2b4d3SLarry Finger 		regaddr, bitmask);
19f1d2b4d3SLarry Finger 	originalvalue = rtl_read_dword(rtlpriv, regaddr);
20*b2127790SSu Hui 	bitshift = calculate_bit_shift(bitmask);
21f1d2b4d3SLarry Finger 	returnvalue = (originalvalue & bitmask) >> bitshift;
22f1d2b4d3SLarry Finger 
235b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
24f1d2b4d3SLarry Finger 		"BBR MASK=0x%x Addr[0x%x]=0x%x\n",
25f1d2b4d3SLarry Finger 		bitmask, regaddr, originalvalue);
26f1d2b4d3SLarry Finger 
27f1d2b4d3SLarry Finger 	return returnvalue;
28f1d2b4d3SLarry Finger }
29f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_query_bb_reg);
30f1d2b4d3SLarry Finger 
rtl92c_phy_set_bb_reg(struct ieee80211_hw * hw,u32 regaddr,u32 bitmask,u32 data)31f1d2b4d3SLarry Finger void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw,
32f1d2b4d3SLarry Finger 			   u32 regaddr, u32 bitmask, u32 data)
33f1d2b4d3SLarry Finger {
34f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
35f1d2b4d3SLarry Finger 	u32 originalvalue, bitshift;
36f1d2b4d3SLarry Finger 
375b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
38f1d2b4d3SLarry Finger 		"regaddr(%#x), bitmask(%#x), data(%#x)\n",
39f1d2b4d3SLarry Finger 		regaddr, bitmask, data);
40f1d2b4d3SLarry Finger 
41f1d2b4d3SLarry Finger 	if (bitmask != MASKDWORD) {
42f1d2b4d3SLarry Finger 		originalvalue = rtl_read_dword(rtlpriv, regaddr);
43*b2127790SSu Hui 		bitshift = calculate_bit_shift(bitmask);
44f1d2b4d3SLarry Finger 		data = ((originalvalue & (~bitmask)) | (data << bitshift));
45f1d2b4d3SLarry Finger 	}
46f1d2b4d3SLarry Finger 
47f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, regaddr, data);
48f1d2b4d3SLarry Finger 
495b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
50f1d2b4d3SLarry Finger 		"regaddr(%#x), bitmask(%#x), data(%#x)\n",
51f1d2b4d3SLarry Finger 		regaddr, bitmask, data);
52f1d2b4d3SLarry Finger }
53f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_set_bb_reg);
54f1d2b4d3SLarry Finger 
_rtl92c_phy_fw_rf_serial_read(struct ieee80211_hw * hw,enum radio_path rfpath,u32 offset)55f1d2b4d3SLarry Finger u32 _rtl92c_phy_fw_rf_serial_read(struct ieee80211_hw *hw,
56f1d2b4d3SLarry Finger 				  enum radio_path rfpath, u32 offset)
57f1d2b4d3SLarry Finger {
58531940f9SLarry Finger 	WARN_ONCE(true, "rtl8192c-common: _rtl92c_phy_fw_rf_serial_read deprecated!\n");
59f1d2b4d3SLarry Finger 	return 0;
60f1d2b4d3SLarry Finger }
61f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_read);
62f1d2b4d3SLarry Finger 
_rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw * hw,enum radio_path rfpath,u32 offset,u32 data)63f1d2b4d3SLarry Finger void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw,
64f1d2b4d3SLarry Finger 				    enum radio_path rfpath, u32 offset,
65f1d2b4d3SLarry Finger 				    u32 data)
66f1d2b4d3SLarry Finger {
67531940f9SLarry Finger 	WARN_ONCE(true, "rtl8192c-common: _rtl92c_phy_fw_rf_serial_write deprecated!\n");
68f1d2b4d3SLarry Finger }
69f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_write);
70f1d2b4d3SLarry Finger 
_rtl92c_phy_rf_serial_read(struct ieee80211_hw * hw,enum radio_path rfpath,u32 offset)71f1d2b4d3SLarry Finger u32 _rtl92c_phy_rf_serial_read(struct ieee80211_hw *hw,
72f1d2b4d3SLarry Finger 			       enum radio_path rfpath, u32 offset)
73f1d2b4d3SLarry Finger {
74f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
75f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
76f1d2b4d3SLarry Finger 	struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
77f1d2b4d3SLarry Finger 	u32 newoffset;
78f1d2b4d3SLarry Finger 	u32 tmplong, tmplong2;
79f1d2b4d3SLarry Finger 	u8 rfpi_enable = 0;
80f1d2b4d3SLarry Finger 	u32 retvalue;
81f1d2b4d3SLarry Finger 
82f1d2b4d3SLarry Finger 	offset &= 0x3f;
83f1d2b4d3SLarry Finger 	newoffset = offset;
84f1d2b4d3SLarry Finger 	if (RT_CANNOT_IO(hw)) {
850fc30e93SLarry Finger 		pr_err("return all one\n");
86f1d2b4d3SLarry Finger 		return 0xFFFFFFFF;
87f1d2b4d3SLarry Finger 	}
88f1d2b4d3SLarry Finger 	tmplong = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD);
89f1d2b4d3SLarry Finger 	if (rfpath == RF90_PATH_A)
90f1d2b4d3SLarry Finger 		tmplong2 = tmplong;
91f1d2b4d3SLarry Finger 	else
92f1d2b4d3SLarry Finger 		tmplong2 = rtl_get_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD);
93f1d2b4d3SLarry Finger 	tmplong2 = (tmplong2 & (~BLSSIREADADDRESS)) |
94f1d2b4d3SLarry Finger 	    (newoffset << 23) | BLSSIREADEDGE;
95f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD,
96f1d2b4d3SLarry Finger 		      tmplong & (~BLSSIREADEDGE));
97f1d2b4d3SLarry Finger 	mdelay(1);
98f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2);
99f1d2b4d3SLarry Finger 	mdelay(1);
100f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD,
101f1d2b4d3SLarry Finger 		      tmplong | BLSSIREADEDGE);
102f1d2b4d3SLarry Finger 	mdelay(1);
103f1d2b4d3SLarry Finger 	if (rfpath == RF90_PATH_A)
104f1d2b4d3SLarry Finger 		rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1,
105f1d2b4d3SLarry Finger 						 BIT(8));
106f1d2b4d3SLarry Finger 	else if (rfpath == RF90_PATH_B)
107f1d2b4d3SLarry Finger 		rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XB_HSSIPARAMETER1,
108f1d2b4d3SLarry Finger 						 BIT(8));
109f1d2b4d3SLarry Finger 	if (rfpi_enable)
110f1d2b4d3SLarry Finger 		retvalue = rtl_get_bbreg(hw, pphyreg->rf_rbpi,
111f1d2b4d3SLarry Finger 					 BLSSIREADBACKDATA);
112f1d2b4d3SLarry Finger 	else
113f1d2b4d3SLarry Finger 		retvalue = rtl_get_bbreg(hw, pphyreg->rf_rb,
114f1d2b4d3SLarry Finger 					 BLSSIREADBACKDATA);
1155b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, "RFR-%d Addr[0x%x]=0x%x\n",
116f1d2b4d3SLarry Finger 		rfpath, pphyreg->rf_rb,
117f1d2b4d3SLarry Finger 		retvalue);
118f1d2b4d3SLarry Finger 	return retvalue;
119f1d2b4d3SLarry Finger }
120f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_rf_serial_read);
121f1d2b4d3SLarry Finger 
_rtl92c_phy_rf_serial_write(struct ieee80211_hw * hw,enum radio_path rfpath,u32 offset,u32 data)122f1d2b4d3SLarry Finger void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw,
123f1d2b4d3SLarry Finger 				 enum radio_path rfpath, u32 offset,
124f1d2b4d3SLarry Finger 				 u32 data)
125f1d2b4d3SLarry Finger {
126f1d2b4d3SLarry Finger 	u32 data_and_addr;
127f1d2b4d3SLarry Finger 	u32 newoffset;
128f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
129f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
130f1d2b4d3SLarry Finger 	struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
131f1d2b4d3SLarry Finger 
132f1d2b4d3SLarry Finger 	if (RT_CANNOT_IO(hw)) {
1330fc30e93SLarry Finger 		pr_err("stop\n");
134f1d2b4d3SLarry Finger 		return;
135f1d2b4d3SLarry Finger 	}
136f1d2b4d3SLarry Finger 	offset &= 0x3f;
137f1d2b4d3SLarry Finger 	newoffset = offset;
138f1d2b4d3SLarry Finger 	data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff;
139f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, pphyreg->rf3wire_offset, MASKDWORD, data_and_addr);
1405b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, "RFW-%d Addr[0x%x]=0x%x\n",
141f1d2b4d3SLarry Finger 		rfpath, pphyreg->rf3wire_offset,
142f1d2b4d3SLarry Finger 		data_and_addr);
143f1d2b4d3SLarry Finger }
144f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_rf_serial_write);
145f1d2b4d3SLarry Finger 
_rtl92c_phy_bb_config_1t(struct ieee80211_hw * hw)146f1d2b4d3SLarry Finger static void _rtl92c_phy_bb_config_1t(struct ieee80211_hw *hw)
147f1d2b4d3SLarry Finger {
148f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA0_TXINFO, 0x3, 0x2);
149f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA1_TXINFO, 0x300033, 0x200022);
150f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RCCK0_AFESETTING, MASKBYTE3, 0x45);
151f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0, 0x23);
152f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, ROFDM0_AGCPARAMETER1, 0x30, 0x1);
153f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe74, 0x0c000000, 0x2);
154f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe78, 0x0c000000, 0x2);
155f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe7c, 0x0c000000, 0x2);
156f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe80, 0x0c000000, 0x2);
157f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe88, 0x0c000000, 0x2);
158f1d2b4d3SLarry Finger }
159f1d2b4d3SLarry Finger 
rtl92c_phy_rf_config(struct ieee80211_hw * hw)160f1d2b4d3SLarry Finger bool rtl92c_phy_rf_config(struct ieee80211_hw *hw)
161f1d2b4d3SLarry Finger {
162f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
163f1d2b4d3SLarry Finger 
164f1d2b4d3SLarry Finger 	return rtlpriv->cfg->ops->phy_rf6052_config(hw);
165f1d2b4d3SLarry Finger }
166f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_rf_config);
167f1d2b4d3SLarry Finger 
_rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw * hw)168f1d2b4d3SLarry Finger bool _rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw *hw)
169f1d2b4d3SLarry Finger {
170f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
171f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
172f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
173f1d2b4d3SLarry Finger 	bool rtstatus;
174f1d2b4d3SLarry Finger 
175f1d2b4d3SLarry Finger 	rtstatus = rtlpriv->cfg->ops->config_bb_with_headerfile(hw,
176f1d2b4d3SLarry Finger 						 BASEBAND_CONFIG_PHY_REG);
177f1d2b4d3SLarry Finger 	if (!rtstatus) {
1780fc30e93SLarry Finger 		pr_err("Write BB Reg Fail!!\n");
179f1d2b4d3SLarry Finger 		return false;
180f1d2b4d3SLarry Finger 	}
181f1d2b4d3SLarry Finger 	if (rtlphy->rf_type == RF_1T2R) {
182f1d2b4d3SLarry Finger 		_rtl92c_phy_bb_config_1t(hw);
1835b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Config to 1T!!\n");
184f1d2b4d3SLarry Finger 	}
185f1d2b4d3SLarry Finger 	if (rtlefuse->autoload_failflag == false) {
186f1d2b4d3SLarry Finger 		rtlphy->pwrgroup_cnt = 0;
187f1d2b4d3SLarry Finger 		rtstatus = rtlpriv->cfg->ops->config_bb_with_pgheaderfile(hw,
188f1d2b4d3SLarry Finger 						   BASEBAND_CONFIG_PHY_REG);
189f1d2b4d3SLarry Finger 	}
190f1d2b4d3SLarry Finger 	if (!rtstatus) {
1910fc30e93SLarry Finger 		pr_err("BB_PG Reg Fail!!\n");
192f1d2b4d3SLarry Finger 		return false;
193f1d2b4d3SLarry Finger 	}
194f1d2b4d3SLarry Finger 	rtstatus = rtlpriv->cfg->ops->config_bb_with_headerfile(hw,
195f1d2b4d3SLarry Finger 						 BASEBAND_CONFIG_AGC_TAB);
196f1d2b4d3SLarry Finger 	if (!rtstatus) {
1970fc30e93SLarry Finger 		pr_err("AGC Table Fail\n");
198f1d2b4d3SLarry Finger 		return false;
199f1d2b4d3SLarry Finger 	}
200f1d2b4d3SLarry Finger 	rtlphy->cck_high_power =
201f1d2b4d3SLarry Finger 		(bool)(rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, 0x200));
202f1d2b4d3SLarry Finger 
203f1d2b4d3SLarry Finger 	return true;
204f1d2b4d3SLarry Finger }
205f1d2b4d3SLarry Finger 
206f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_bb8192c_config_parafile);
207f1d2b4d3SLarry Finger 
_rtl92c_store_pwrindex_diffrate_offset(struct ieee80211_hw * hw,u32 regaddr,u32 bitmask,u32 data)208ff970453SLarry Finger void _rtl92c_store_pwrindex_diffrate_offset(struct ieee80211_hw *hw,
209f1d2b4d3SLarry Finger 					    u32 regaddr, u32 bitmask,
210f1d2b4d3SLarry Finger 					    u32 data)
211f1d2b4d3SLarry Finger {
212f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
213f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
214f1d2b4d3SLarry Finger 
215f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_RATE18_06) {
216f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][0] =
217f1d2b4d3SLarry Finger 		    data;
2185b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
219f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n",
220f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
2215b4e998bSLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset
2225b4e998bSLarry Finger 			[rtlphy->pwrgroup_cnt][0]);
223f1d2b4d3SLarry Finger 	}
224f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_RATE54_24) {
225f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][1] =
226f1d2b4d3SLarry Finger 		    data;
2275b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
228f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x\n",
229f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
2305b4e998bSLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset
2315b4e998bSLarry Finger 			[rtlphy->pwrgroup_cnt][1]);
232f1d2b4d3SLarry Finger 	}
233f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_CCK1_MCS32) {
234f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][6] =
235f1d2b4d3SLarry Finger 		    data;
2365b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
237f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n",
238f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
2395b4e998bSLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset
2405b4e998bSLarry Finger 			[rtlphy->pwrgroup_cnt][6]);
241f1d2b4d3SLarry Finger 	}
242f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00) {
243f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][7] =
244f1d2b4d3SLarry Finger 		    data;
2455b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
246f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n",
247f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
248f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
249f1d2b4d3SLarry Finger 							    pwrgroup_cnt][7]);
250f1d2b4d3SLarry Finger 	}
251f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_MCS03_MCS00) {
252f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][2] =
253f1d2b4d3SLarry Finger 		    data;
2545b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
255f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x\n",
256f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
257f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
258f1d2b4d3SLarry Finger 							    pwrgroup_cnt][2]);
259f1d2b4d3SLarry Finger 	}
260f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_MCS07_MCS04) {
261f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][3] =
262f1d2b4d3SLarry Finger 		    data;
2635b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
264f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x\n",
265f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
266f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
267f1d2b4d3SLarry Finger 							    pwrgroup_cnt][3]);
268f1d2b4d3SLarry Finger 	}
269f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_MCS11_MCS08) {
270f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][4] =
271f1d2b4d3SLarry Finger 		    data;
2725b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
273f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n",
274f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
275f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
276f1d2b4d3SLarry Finger 							    pwrgroup_cnt][4]);
277f1d2b4d3SLarry Finger 	}
278f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_A_MCS15_MCS12) {
279f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][5] =
280f1d2b4d3SLarry Finger 		    data;
2815b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
282f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x\n",
283f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
284f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
285f1d2b4d3SLarry Finger 							    pwrgroup_cnt][5]);
286f1d2b4d3SLarry Finger 	}
287f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_RATE18_06) {
288f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][8] =
289f1d2b4d3SLarry Finger 		    data;
2905b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
291f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x\n",
292f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
293f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
294f1d2b4d3SLarry Finger 							    pwrgroup_cnt][8]);
295f1d2b4d3SLarry Finger 	}
296f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_RATE54_24) {
297f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][9] =
298f1d2b4d3SLarry Finger 		    data;
2995b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
300f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n",
301f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
302f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
303f1d2b4d3SLarry Finger 							    pwrgroup_cnt][9]);
304f1d2b4d3SLarry Finger 	}
305f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_CCK1_55_MCS32) {
306f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][14] =
307f1d2b4d3SLarry Finger 		    data;
3085b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
309f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n",
310f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
311f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
312f1d2b4d3SLarry Finger 							    pwrgroup_cnt][14]);
313f1d2b4d3SLarry Finger 	}
314f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) {
315f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][15] =
316f1d2b4d3SLarry Finger 		    data;
3175b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
318f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n",
319f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
320f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
321f1d2b4d3SLarry Finger 							    pwrgroup_cnt][15]);
322f1d2b4d3SLarry Finger 	}
323f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_MCS03_MCS00) {
324f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][10] =
325f1d2b4d3SLarry Finger 		    data;
3265b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
327f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n",
328f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
329f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
330f1d2b4d3SLarry Finger 							    pwrgroup_cnt][10]);
331f1d2b4d3SLarry Finger 	}
332f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_MCS07_MCS04) {
333f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][11] =
334f1d2b4d3SLarry Finger 		    data;
3355b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
336f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n",
337f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
338f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
339f1d2b4d3SLarry Finger 							    pwrgroup_cnt][11]);
340f1d2b4d3SLarry Finger 	}
341f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_MCS11_MCS08) {
342f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][12] =
343f1d2b4d3SLarry Finger 		    data;
3445b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
345f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n",
346f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
347f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
348f1d2b4d3SLarry Finger 							    pwrgroup_cnt][12]);
349f1d2b4d3SLarry Finger 	}
350f1d2b4d3SLarry Finger 	if (regaddr == RTXAGC_B_MCS15_MCS12) {
351f1d2b4d3SLarry Finger 		rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][13] =
352f1d2b4d3SLarry Finger 		    data;
3535b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
354f1d2b4d3SLarry Finger 			"MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n",
355f1d2b4d3SLarry Finger 			rtlphy->pwrgroup_cnt,
356f1d2b4d3SLarry Finger 			rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
357f1d2b4d3SLarry Finger 							    pwrgroup_cnt][13]);
358f1d2b4d3SLarry Finger 
359f1d2b4d3SLarry Finger 		rtlphy->pwrgroup_cnt++;
360f1d2b4d3SLarry Finger 	}
361f1d2b4d3SLarry Finger }
362ff970453SLarry Finger EXPORT_SYMBOL(_rtl92c_store_pwrindex_diffrate_offset);
363f1d2b4d3SLarry Finger 
rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw * hw)364f1d2b4d3SLarry Finger void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw)
365f1d2b4d3SLarry Finger {
366f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
367f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
368f1d2b4d3SLarry Finger 
369f1d2b4d3SLarry Finger 	rtlphy->default_initialgain[0] =
370f1d2b4d3SLarry Finger 	    (u8)rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0);
371f1d2b4d3SLarry Finger 	rtlphy->default_initialgain[1] =
372f1d2b4d3SLarry Finger 	    (u8)rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0);
373f1d2b4d3SLarry Finger 	rtlphy->default_initialgain[2] =
374f1d2b4d3SLarry Finger 	    (u8)rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0);
375f1d2b4d3SLarry Finger 	rtlphy->default_initialgain[3] =
376f1d2b4d3SLarry Finger 	    (u8)rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0);
377f1d2b4d3SLarry Finger 
3785b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
379f1d2b4d3SLarry Finger 		"Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
380f1d2b4d3SLarry Finger 		rtlphy->default_initialgain[0],
381f1d2b4d3SLarry Finger 		rtlphy->default_initialgain[1],
382f1d2b4d3SLarry Finger 		rtlphy->default_initialgain[2],
383f1d2b4d3SLarry Finger 		rtlphy->default_initialgain[3]);
384f1d2b4d3SLarry Finger 
385f1d2b4d3SLarry Finger 	rtlphy->framesync = (u8)rtl_get_bbreg(hw,
386f1d2b4d3SLarry Finger 					       ROFDM0_RXDETECTOR3, MASKBYTE0);
387f1d2b4d3SLarry Finger 	rtlphy->framesync_c34 = rtl_get_bbreg(hw,
388f1d2b4d3SLarry Finger 					      ROFDM0_RXDETECTOR2, MASKDWORD);
389f1d2b4d3SLarry Finger 
3905b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
391f1d2b4d3SLarry Finger 		"Default framesync (0x%x) = 0x%x\n",
392f1d2b4d3SLarry Finger 		ROFDM0_RXDETECTOR3, rtlphy->framesync);
393f1d2b4d3SLarry Finger }
394f1d2b4d3SLarry Finger 
_rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw * hw)395f1d2b4d3SLarry Finger void _rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw)
396f1d2b4d3SLarry Finger {
397f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
398f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
399f1d2b4d3SLarry Finger 
400f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW;
401f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW;
402f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW;
403f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW;
404f1d2b4d3SLarry Finger 
405f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB;
406f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB;
407f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB;
408f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB;
409f1d2b4d3SLarry Finger 
410f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE;
411f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE;
412f1d2b4d3SLarry Finger 
413f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE;
414f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE;
415f1d2b4d3SLarry Finger 
416f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset =
417f1d2b4d3SLarry Finger 	    RFPGA0_XA_LSSIPARAMETER;
418f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset =
419f1d2b4d3SLarry Finger 	    RFPGA0_XB_LSSIPARAMETER;
420f1d2b4d3SLarry Finger 
421ff970453SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = RFPGA0_XAB_RFPARAMETER;
422ff970453SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = RFPGA0_XAB_RFPARAMETER;
423ff970453SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = RFPGA0_XCD_RFPARAMETER;
424ff970453SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = RFPGA0_XCD_RFPARAMETER;
425f1d2b4d3SLarry Finger 
426f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE;
427f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE;
428f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE;
429f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE;
430f1d2b4d3SLarry Finger 
431f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1;
432f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1;
433f1d2b4d3SLarry Finger 
434f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2;
435f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2;
436f1d2b4d3SLarry Finger 
437f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfsw_ctrl = RFPGA0_XAB_SWITCHCONTROL;
438f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfsw_ctrl = RFPGA0_XAB_SWITCHCONTROL;
439f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfsw_ctrl = RFPGA0_XCD_SWITCHCONTROL;
440f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfsw_ctrl = RFPGA0_XCD_SWITCHCONTROL;
441f1d2b4d3SLarry Finger 
442f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1;
443f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1;
444f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1;
445f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1;
446f1d2b4d3SLarry Finger 
447f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2;
448f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2;
449f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2;
450f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2;
451f1d2b4d3SLarry Finger 
452f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbal = ROFDM0_XARXIQIMBALANCE;
453f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbal = ROFDM0_XBRXIQIMBALANCE;
454f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbal = ROFDM0_XCRXIQIMBANLANCE;
455f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbal = ROFDM0_XDRXIQIMBALANCE;
456f1d2b4d3SLarry Finger 
457f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE;
458f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE;
459f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE;
460f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE;
461f1d2b4d3SLarry Finger 
462f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbal = ROFDM0_XATXIQIMBALANCE;
463f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbal = ROFDM0_XBTXIQIMBALANCE;
464f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbal = ROFDM0_XCTXIQIMBALANCE;
465f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbal = ROFDM0_XDTXIQIMBALANCE;
466f1d2b4d3SLarry Finger 
467f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATXAFE;
468f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTXAFE;
469f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rftx_afe = ROFDM0_XCTXAFE;
470f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rftx_afe = ROFDM0_XDTXAFE;
471f1d2b4d3SLarry Finger 
472f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK;
473f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK;
474f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_C].rf_rb = RFPGA0_XC_LSSIREADBACK;
475f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_D].rf_rb = RFPGA0_XD_LSSIREADBACK;
476f1d2b4d3SLarry Finger 
477f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVEA_HSPI_READBACK;
478f1d2b4d3SLarry Finger 	rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVEB_HSPI_READBACK;
479f1d2b4d3SLarry Finger 
480f1d2b4d3SLarry Finger }
481f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_init_bb_rf_register_definition);
482f1d2b4d3SLarry Finger 
rtl92c_phy_get_txpower_level(struct ieee80211_hw * hw,long * powerlevel)483f1d2b4d3SLarry Finger void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel)
484f1d2b4d3SLarry Finger {
485f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
486f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
487f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
488f1d2b4d3SLarry Finger 	u8 txpwr_level;
489f1d2b4d3SLarry Finger 	long txpwr_dbm;
490f1d2b4d3SLarry Finger 
491f1d2b4d3SLarry Finger 	txpwr_level = rtlphy->cur_cck_txpwridx;
492f1d2b4d3SLarry Finger 	txpwr_dbm = _rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_B,
493f1d2b4d3SLarry Finger 						 txpwr_level);
494f1d2b4d3SLarry Finger 	txpwr_level = rtlphy->cur_ofdm24g_txpwridx +
495f1d2b4d3SLarry Finger 	    rtlefuse->legacy_ht_txpowerdiff;
496f1d2b4d3SLarry Finger 	if (_rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G,
497f1d2b4d3SLarry Finger 					 txpwr_level) > txpwr_dbm)
498f1d2b4d3SLarry Finger 		txpwr_dbm =
499f1d2b4d3SLarry Finger 		    _rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G,
500f1d2b4d3SLarry Finger 						 txpwr_level);
501f1d2b4d3SLarry Finger 	txpwr_level = rtlphy->cur_ofdm24g_txpwridx;
502f1d2b4d3SLarry Finger 	if (_rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G,
503f1d2b4d3SLarry Finger 					 txpwr_level) > txpwr_dbm)
504f1d2b4d3SLarry Finger 		txpwr_dbm =
505f1d2b4d3SLarry Finger 		    _rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G,
506f1d2b4d3SLarry Finger 						 txpwr_level);
507f1d2b4d3SLarry Finger 	*powerlevel = txpwr_dbm;
508f1d2b4d3SLarry Finger }
509f1d2b4d3SLarry Finger 
_rtl92c_get_txpower_index(struct ieee80211_hw * hw,u8 channel,u8 * cckpowerlevel,u8 * ofdmpowerlevel)510f1d2b4d3SLarry Finger static void _rtl92c_get_txpower_index(struct ieee80211_hw *hw, u8 channel,
511f1d2b4d3SLarry Finger 				      u8 *cckpowerlevel, u8 *ofdmpowerlevel)
512f1d2b4d3SLarry Finger {
513f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
514f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
515f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
516f1d2b4d3SLarry Finger 	u8 index = (channel - 1);
517f1d2b4d3SLarry Finger 
518f1d2b4d3SLarry Finger 	cckpowerlevel[RF90_PATH_A] =
519f1d2b4d3SLarry Finger 	    rtlefuse->txpwrlevel_cck[RF90_PATH_A][index];
520f1d2b4d3SLarry Finger 	cckpowerlevel[RF90_PATH_B] =
521f1d2b4d3SLarry Finger 	    rtlefuse->txpwrlevel_cck[RF90_PATH_B][index];
522f1d2b4d3SLarry Finger 	if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_1T1R) {
523f1d2b4d3SLarry Finger 		ofdmpowerlevel[RF90_PATH_A] =
524f1d2b4d3SLarry Finger 		    rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index];
525f1d2b4d3SLarry Finger 		ofdmpowerlevel[RF90_PATH_B] =
526f1d2b4d3SLarry Finger 		    rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index];
527f1d2b4d3SLarry Finger 	} else if (get_rf_type(rtlphy) == RF_2T2R) {
528f1d2b4d3SLarry Finger 		ofdmpowerlevel[RF90_PATH_A] =
529f1d2b4d3SLarry Finger 		    rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_A][index];
530f1d2b4d3SLarry Finger 		ofdmpowerlevel[RF90_PATH_B] =
531f1d2b4d3SLarry Finger 		    rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_B][index];
532f1d2b4d3SLarry Finger 	}
533f1d2b4d3SLarry Finger }
534f1d2b4d3SLarry Finger 
_rtl92c_ccxpower_index_check(struct ieee80211_hw * hw,u8 channel,u8 * cckpowerlevel,u8 * ofdmpowerlevel)535f1d2b4d3SLarry Finger static void _rtl92c_ccxpower_index_check(struct ieee80211_hw *hw,
536f1d2b4d3SLarry Finger 					 u8 channel, u8 *cckpowerlevel,
537f1d2b4d3SLarry Finger 					 u8 *ofdmpowerlevel)
538f1d2b4d3SLarry Finger {
539f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
540f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
541f1d2b4d3SLarry Finger 
542f1d2b4d3SLarry Finger 	rtlphy->cur_cck_txpwridx = cckpowerlevel[0];
543f1d2b4d3SLarry Finger 	rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0];
544f1d2b4d3SLarry Finger }
545f1d2b4d3SLarry Finger 
rtl92c_phy_set_txpower_level(struct ieee80211_hw * hw,u8 channel)546f1d2b4d3SLarry Finger void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
547f1d2b4d3SLarry Finger {
548f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
549f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
550f1d2b4d3SLarry Finger 	u8 cckpowerlevel[2], ofdmpowerlevel[2];
551f1d2b4d3SLarry Finger 
552f1d2b4d3SLarry Finger 	if (!rtlefuse->txpwr_fromeprom)
553f1d2b4d3SLarry Finger 		return;
554f1d2b4d3SLarry Finger 	_rtl92c_get_txpower_index(hw, channel,
555f1d2b4d3SLarry Finger 				  &cckpowerlevel[0], &ofdmpowerlevel[0]);
556f1d2b4d3SLarry Finger 	_rtl92c_ccxpower_index_check(hw, channel, &cckpowerlevel[0],
557f1d2b4d3SLarry Finger 				     &ofdmpowerlevel[0]);
558f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->phy_rf6052_set_cck_txpower(hw, &cckpowerlevel[0]);
559f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0],
560f1d2b4d3SLarry Finger 						       channel);
561f1d2b4d3SLarry Finger }
562f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_set_txpower_level);
563f1d2b4d3SLarry Finger 
rtl92c_phy_update_txpower_dbm(struct ieee80211_hw * hw,long power_indbm)564f1d2b4d3SLarry Finger bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, long power_indbm)
565f1d2b4d3SLarry Finger {
566f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
567f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
568f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
569f1d2b4d3SLarry Finger 	u8 idx;
570f1d2b4d3SLarry Finger 	u8 rf_path;
571f1d2b4d3SLarry Finger 	u8 ccktxpwridx = _rtl92c_phy_dbm_to_txpwr_idx(hw, WIRELESS_MODE_B,
572f1d2b4d3SLarry Finger 						      power_indbm);
573f1d2b4d3SLarry Finger 	u8 ofdmtxpwridx = _rtl92c_phy_dbm_to_txpwr_idx(hw, WIRELESS_MODE_N_24G,
574f1d2b4d3SLarry Finger 						       power_indbm);
575f1d2b4d3SLarry Finger 	if (ofdmtxpwridx - rtlefuse->legacy_ht_txpowerdiff > 0)
576f1d2b4d3SLarry Finger 		ofdmtxpwridx -= rtlefuse->legacy_ht_txpowerdiff;
577f1d2b4d3SLarry Finger 	else
578f1d2b4d3SLarry Finger 		ofdmtxpwridx = 0;
5795b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_TXAGC, DBG_TRACE,
580f1d2b4d3SLarry Finger 		"%lx dBm, ccktxpwridx = %d, ofdmtxpwridx = %d\n",
581f1d2b4d3SLarry Finger 		power_indbm, ccktxpwridx, ofdmtxpwridx);
582f1d2b4d3SLarry Finger 	for (idx = 0; idx < 14; idx++) {
583f1d2b4d3SLarry Finger 		for (rf_path = 0; rf_path < 2; rf_path++) {
584f1d2b4d3SLarry Finger 			rtlefuse->txpwrlevel_cck[rf_path][idx] = ccktxpwridx;
585f1d2b4d3SLarry Finger 			rtlefuse->txpwrlevel_ht40_1s[rf_path][idx] =
586f1d2b4d3SLarry Finger 			    ofdmtxpwridx;
587f1d2b4d3SLarry Finger 			rtlefuse->txpwrlevel_ht40_2s[rf_path][idx] =
588f1d2b4d3SLarry Finger 			    ofdmtxpwridx;
589f1d2b4d3SLarry Finger 		}
590f1d2b4d3SLarry Finger 	}
591f1d2b4d3SLarry Finger 	rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
592f1d2b4d3SLarry Finger 	return true;
593f1d2b4d3SLarry Finger }
594f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_update_txpower_dbm);
595f1d2b4d3SLarry Finger 
_rtl92c_phy_dbm_to_txpwr_idx(struct ieee80211_hw * hw,enum wireless_mode wirelessmode,long power_indbm)596f1d2b4d3SLarry Finger u8 _rtl92c_phy_dbm_to_txpwr_idx(struct ieee80211_hw *hw,
597f1d2b4d3SLarry Finger 				enum wireless_mode wirelessmode,
598f1d2b4d3SLarry Finger 				long power_indbm)
599f1d2b4d3SLarry Finger {
600f1d2b4d3SLarry Finger 	u8 txpwridx;
601f1d2b4d3SLarry Finger 	long offset;
602f1d2b4d3SLarry Finger 
603f1d2b4d3SLarry Finger 	switch (wirelessmode) {
604f1d2b4d3SLarry Finger 	case WIRELESS_MODE_B:
605f1d2b4d3SLarry Finger 		offset = -7;
606f1d2b4d3SLarry Finger 		break;
607f1d2b4d3SLarry Finger 	case WIRELESS_MODE_G:
608f1d2b4d3SLarry Finger 	case WIRELESS_MODE_N_24G:
609f1d2b4d3SLarry Finger 		offset = -8;
610f1d2b4d3SLarry Finger 		break;
611f1d2b4d3SLarry Finger 	default:
612f1d2b4d3SLarry Finger 		offset = -8;
613f1d2b4d3SLarry Finger 		break;
614f1d2b4d3SLarry Finger 	}
615f1d2b4d3SLarry Finger 
616f1d2b4d3SLarry Finger 	if ((power_indbm - offset) > 0)
617f1d2b4d3SLarry Finger 		txpwridx = (u8)((power_indbm - offset) * 2);
618f1d2b4d3SLarry Finger 	else
619f1d2b4d3SLarry Finger 		txpwridx = 0;
620f1d2b4d3SLarry Finger 
621f1d2b4d3SLarry Finger 	if (txpwridx > MAX_TXPWR_IDX_NMODE_92S)
622f1d2b4d3SLarry Finger 		txpwridx = MAX_TXPWR_IDX_NMODE_92S;
623f1d2b4d3SLarry Finger 
624f1d2b4d3SLarry Finger 	return txpwridx;
625f1d2b4d3SLarry Finger }
626f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_dbm_to_txpwr_idx);
627f1d2b4d3SLarry Finger 
_rtl92c_phy_txpwr_idx_to_dbm(struct ieee80211_hw * hw,enum wireless_mode wirelessmode,u8 txpwridx)628f1d2b4d3SLarry Finger long _rtl92c_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
629f1d2b4d3SLarry Finger 				  enum wireless_mode wirelessmode,
630f1d2b4d3SLarry Finger 				  u8 txpwridx)
631f1d2b4d3SLarry Finger {
632f1d2b4d3SLarry Finger 	long offset;
633f1d2b4d3SLarry Finger 	long pwrout_dbm;
634f1d2b4d3SLarry Finger 
635f1d2b4d3SLarry Finger 	switch (wirelessmode) {
636f1d2b4d3SLarry Finger 	case WIRELESS_MODE_B:
637f1d2b4d3SLarry Finger 		offset = -7;
638f1d2b4d3SLarry Finger 		break;
639f1d2b4d3SLarry Finger 	case WIRELESS_MODE_G:
640f1d2b4d3SLarry Finger 	case WIRELESS_MODE_N_24G:
641f1d2b4d3SLarry Finger 		offset = -8;
642f1d2b4d3SLarry Finger 		break;
643f1d2b4d3SLarry Finger 	default:
644f1d2b4d3SLarry Finger 		offset = -8;
645f1d2b4d3SLarry Finger 		break;
646f1d2b4d3SLarry Finger 	}
647f1d2b4d3SLarry Finger 	pwrout_dbm = txpwridx / 2 + offset;
648f1d2b4d3SLarry Finger 	return pwrout_dbm;
649f1d2b4d3SLarry Finger }
650f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_txpwr_idx_to_dbm);
651f1d2b4d3SLarry Finger 
rtl92c_phy_set_bw_mode(struct ieee80211_hw * hw,enum nl80211_channel_type ch_type)652f1d2b4d3SLarry Finger void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
653f1d2b4d3SLarry Finger 			    enum nl80211_channel_type ch_type)
654f1d2b4d3SLarry Finger {
655f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
656f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
657f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
658f1d2b4d3SLarry Finger 	u8 tmp_bw = rtlphy->current_chan_bw;
659f1d2b4d3SLarry Finger 
660f1d2b4d3SLarry Finger 	if (rtlphy->set_bwmode_inprogress)
661f1d2b4d3SLarry Finger 		return;
662f1d2b4d3SLarry Finger 	rtlphy->set_bwmode_inprogress = true;
663f1d2b4d3SLarry Finger 	if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
664f1d2b4d3SLarry Finger 		rtlpriv->cfg->ops->phy_set_bw_mode_callback(hw);
665f1d2b4d3SLarry Finger 	} else {
6665b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING,
667f1d2b4d3SLarry Finger 			"false driver sleep or unload\n");
668f1d2b4d3SLarry Finger 		rtlphy->set_bwmode_inprogress = false;
669f1d2b4d3SLarry Finger 		rtlphy->current_chan_bw = tmp_bw;
670f1d2b4d3SLarry Finger 	}
671f1d2b4d3SLarry Finger }
672f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_set_bw_mode);
673f1d2b4d3SLarry Finger 
rtl92c_phy_sw_chnl_callback(struct ieee80211_hw * hw)674f1d2b4d3SLarry Finger void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw)
675f1d2b4d3SLarry Finger {
676f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
677f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
678f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
679f1d2b4d3SLarry Finger 	u32 delay;
680f1d2b4d3SLarry Finger 
6815b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE,
682f1d2b4d3SLarry Finger 		"switch to channel%d\n", rtlphy->current_channel);
683f1d2b4d3SLarry Finger 	if (is_hal_stop(rtlhal))
684f1d2b4d3SLarry Finger 		return;
685f1d2b4d3SLarry Finger 	do {
686f1d2b4d3SLarry Finger 		if (!rtlphy->sw_chnl_inprogress)
687f1d2b4d3SLarry Finger 			break;
688f1d2b4d3SLarry Finger 		if (!_rtl92c_phy_sw_chnl_step_by_step
689f1d2b4d3SLarry Finger 		    (hw, rtlphy->current_channel, &rtlphy->sw_chnl_stage,
690f1d2b4d3SLarry Finger 		     &rtlphy->sw_chnl_step, &delay)) {
691f1d2b4d3SLarry Finger 			if (delay > 0)
692f1d2b4d3SLarry Finger 				mdelay(delay);
693f1d2b4d3SLarry Finger 			else
694f1d2b4d3SLarry Finger 				continue;
695f1d2b4d3SLarry Finger 		} else {
696f1d2b4d3SLarry Finger 			rtlphy->sw_chnl_inprogress = false;
697f1d2b4d3SLarry Finger 		}
698f1d2b4d3SLarry Finger 		break;
699f1d2b4d3SLarry Finger 	} while (true);
7005b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "\n");
701f1d2b4d3SLarry Finger }
702f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_sw_chnl_callback);
703f1d2b4d3SLarry Finger 
rtl92c_phy_sw_chnl(struct ieee80211_hw * hw)704f1d2b4d3SLarry Finger u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw)
705f1d2b4d3SLarry Finger {
706f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
707f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
708f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
709f1d2b4d3SLarry Finger 
710f1d2b4d3SLarry Finger 	if (rtlphy->sw_chnl_inprogress)
711f1d2b4d3SLarry Finger 		return 0;
712f1d2b4d3SLarry Finger 	if (rtlphy->set_bwmode_inprogress)
713f1d2b4d3SLarry Finger 		return 0;
714531940f9SLarry Finger 	WARN_ONCE((rtlphy->current_channel > 14),
715531940f9SLarry Finger 		  "rtl8192c-common: WIRELESS_MODE_G but channel>14");
716f1d2b4d3SLarry Finger 	rtlphy->sw_chnl_inprogress = true;
717f1d2b4d3SLarry Finger 	rtlphy->sw_chnl_stage = 0;
718f1d2b4d3SLarry Finger 	rtlphy->sw_chnl_step = 0;
719f1d2b4d3SLarry Finger 	if (!(is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
720f1d2b4d3SLarry Finger 		rtl92c_phy_sw_chnl_callback(hw);
7215b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_CHAN, DBG_LOUD,
7228a190237SMasanari Iida 			"sw_chnl_inprogress false schedule workitem\n");
723f1d2b4d3SLarry Finger 		rtlphy->sw_chnl_inprogress = false;
724f1d2b4d3SLarry Finger 	} else {
7255b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_CHAN, DBG_LOUD,
726f1d2b4d3SLarry Finger 			"sw_chnl_inprogress false driver sleep or unload\n");
727f1d2b4d3SLarry Finger 		rtlphy->sw_chnl_inprogress = false;
728f1d2b4d3SLarry Finger 	}
729f1d2b4d3SLarry Finger 	return 1;
730f1d2b4d3SLarry Finger }
731f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_sw_chnl);
732f1d2b4d3SLarry Finger 
_rtl92c_phy_sw_rf_seting(struct ieee80211_hw * hw,u8 channel)733f1d2b4d3SLarry Finger static void _rtl92c_phy_sw_rf_seting(struct ieee80211_hw *hw, u8 channel)
734f1d2b4d3SLarry Finger {
735f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
736f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
737f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
73852f88657SLarry Finger 
739f1d2b4d3SLarry Finger 	if (IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version)) {
740f1d2b4d3SLarry Finger 		if (channel == 6 &&
741f1d2b4d3SLarry Finger 		    rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) {
742f1d2b4d3SLarry Finger 			rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1,
743f1d2b4d3SLarry Finger 				      MASKDWORD, 0x00255);
744f1d2b4d3SLarry Finger 		} else {
745f1d2b4d3SLarry Finger 			u32 backuprf0x1A =
746f1d2b4d3SLarry Finger 			  (u32)rtl_get_rfreg(hw, RF90_PATH_A, RF_RX_G1,
747f1d2b4d3SLarry Finger 					     RFREG_OFFSET_MASK);
748f1d2b4d3SLarry Finger 			rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD,
749f1d2b4d3SLarry Finger 				      backuprf0x1A);
750f1d2b4d3SLarry Finger 		}
751f1d2b4d3SLarry Finger 	}
752f1d2b4d3SLarry Finger }
753f1d2b4d3SLarry Finger 
_rtl92c_phy_set_sw_chnl_cmdarray(struct swchnlcmd * cmdtable,u32 cmdtableidx,u32 cmdtablesz,enum swchnlcmd_id cmdid,u32 para1,u32 para2,u32 msdelay)754f1d2b4d3SLarry Finger static bool _rtl92c_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
755f1d2b4d3SLarry Finger 					     u32 cmdtableidx, u32 cmdtablesz,
756f1d2b4d3SLarry Finger 					     enum swchnlcmd_id cmdid,
757f1d2b4d3SLarry Finger 					     u32 para1, u32 para2, u32 msdelay)
758f1d2b4d3SLarry Finger {
759f1d2b4d3SLarry Finger 	struct swchnlcmd *pcmd;
760f1d2b4d3SLarry Finger 
761f1d2b4d3SLarry Finger 	if (cmdtable == NULL) {
762531940f9SLarry Finger 		WARN_ONCE(true, "rtl8192c-common: cmdtable cannot be NULL.\n");
763f1d2b4d3SLarry Finger 		return false;
764f1d2b4d3SLarry Finger 	}
765f1d2b4d3SLarry Finger 
766f1d2b4d3SLarry Finger 	if (cmdtableidx >= cmdtablesz)
767f1d2b4d3SLarry Finger 		return false;
768f1d2b4d3SLarry Finger 
769f1d2b4d3SLarry Finger 	pcmd = cmdtable + cmdtableidx;
770f1d2b4d3SLarry Finger 	pcmd->cmdid = cmdid;
771f1d2b4d3SLarry Finger 	pcmd->para1 = para1;
772f1d2b4d3SLarry Finger 	pcmd->para2 = para2;
773f1d2b4d3SLarry Finger 	pcmd->msdelay = msdelay;
774f1d2b4d3SLarry Finger 	return true;
775f1d2b4d3SLarry Finger }
776f1d2b4d3SLarry Finger 
_rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw * hw,u8 channel,u8 * stage,u8 * step,u32 * delay)777f1d2b4d3SLarry Finger bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
778f1d2b4d3SLarry Finger 				      u8 channel, u8 *stage, u8 *step,
779f1d2b4d3SLarry Finger 				      u32 *delay)
780f1d2b4d3SLarry Finger {
781f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
782f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
783f1d2b4d3SLarry Finger 	struct swchnlcmd precommoncmd[MAX_PRECMD_CNT];
784f1d2b4d3SLarry Finger 	u32 precommoncmdcnt;
785f1d2b4d3SLarry Finger 	struct swchnlcmd postcommoncmd[MAX_POSTCMD_CNT];
786f1d2b4d3SLarry Finger 	u32 postcommoncmdcnt;
787f1d2b4d3SLarry Finger 	struct swchnlcmd rfdependcmd[MAX_RFDEPENDCMD_CNT];
788f1d2b4d3SLarry Finger 	u32 rfdependcmdcnt;
789f1d2b4d3SLarry Finger 	struct swchnlcmd *currentcmd = NULL;
790f1d2b4d3SLarry Finger 	u8 rfpath;
791f1d2b4d3SLarry Finger 	u8 num_total_rfpath = rtlphy->num_total_rfpath;
792f1d2b4d3SLarry Finger 
793f1d2b4d3SLarry Finger 	precommoncmdcnt = 0;
794f1d2b4d3SLarry Finger 	_rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
795f1d2b4d3SLarry Finger 					 MAX_PRECMD_CNT,
796f1d2b4d3SLarry Finger 					 CMDID_SET_TXPOWEROWER_LEVEL, 0, 0, 0);
797f1d2b4d3SLarry Finger 	_rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
798f1d2b4d3SLarry Finger 					 MAX_PRECMD_CNT, CMDID_END, 0, 0, 0);
799f1d2b4d3SLarry Finger 
800f1d2b4d3SLarry Finger 	postcommoncmdcnt = 0;
801f1d2b4d3SLarry Finger 
802f1d2b4d3SLarry Finger 	_rtl92c_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++,
803f1d2b4d3SLarry Finger 					 MAX_POSTCMD_CNT, CMDID_END, 0, 0, 0);
804f1d2b4d3SLarry Finger 
805f1d2b4d3SLarry Finger 	rfdependcmdcnt = 0;
806f1d2b4d3SLarry Finger 
807531940f9SLarry Finger 	WARN_ONCE((channel < 1 || channel > 14),
808531940f9SLarry Finger 		  "rtl8192c-common: illegal channel for Zebra: %d\n", channel);
809f1d2b4d3SLarry Finger 
810f1d2b4d3SLarry Finger 	_rtl92c_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
811f1d2b4d3SLarry Finger 					 MAX_RFDEPENDCMD_CNT, CMDID_RF_WRITEREG,
812f1d2b4d3SLarry Finger 					 RF_CHNLBW, channel, 10);
813f1d2b4d3SLarry Finger 
814f1d2b4d3SLarry Finger 	_rtl92c_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
815f1d2b4d3SLarry Finger 					 MAX_RFDEPENDCMD_CNT, CMDID_END, 0, 0,
816f1d2b4d3SLarry Finger 					 0);
817f1d2b4d3SLarry Finger 
818f1d2b4d3SLarry Finger 	do {
819f1d2b4d3SLarry Finger 		switch (*stage) {
820f1d2b4d3SLarry Finger 		case 0:
821f1d2b4d3SLarry Finger 			currentcmd = &precommoncmd[*step];
822f1d2b4d3SLarry Finger 			break;
823f1d2b4d3SLarry Finger 		case 1:
824f1d2b4d3SLarry Finger 			currentcmd = &rfdependcmd[*step];
825f1d2b4d3SLarry Finger 			break;
826f1d2b4d3SLarry Finger 		case 2:
827f1d2b4d3SLarry Finger 			currentcmd = &postcommoncmd[*step];
828f1d2b4d3SLarry Finger 			break;
829f1d2b4d3SLarry Finger 		default:
8300fc30e93SLarry Finger 			pr_err("Invalid 'stage' = %d, Check it!\n",
8310fc30e93SLarry Finger 			       *stage);
832f1d2b4d3SLarry Finger 			return true;
833f1d2b4d3SLarry Finger 		}
834f1d2b4d3SLarry Finger 
835f1d2b4d3SLarry Finger 		if (currentcmd->cmdid == CMDID_END) {
836f1d2b4d3SLarry Finger 			if ((*stage) == 2) {
837f1d2b4d3SLarry Finger 				return true;
838f1d2b4d3SLarry Finger 			} else {
839f1d2b4d3SLarry Finger 				(*stage)++;
840f1d2b4d3SLarry Finger 				(*step) = 0;
841f1d2b4d3SLarry Finger 				continue;
842f1d2b4d3SLarry Finger 			}
843f1d2b4d3SLarry Finger 		}
844f1d2b4d3SLarry Finger 
845f1d2b4d3SLarry Finger 		switch (currentcmd->cmdid) {
846f1d2b4d3SLarry Finger 		case CMDID_SET_TXPOWEROWER_LEVEL:
847f1d2b4d3SLarry Finger 			rtl92c_phy_set_txpower_level(hw, channel);
848f1d2b4d3SLarry Finger 			break;
849f1d2b4d3SLarry Finger 		case CMDID_WRITEPORT_ULONG:
850f1d2b4d3SLarry Finger 			rtl_write_dword(rtlpriv, currentcmd->para1,
851f1d2b4d3SLarry Finger 					currentcmd->para2);
852f1d2b4d3SLarry Finger 			break;
853f1d2b4d3SLarry Finger 		case CMDID_WRITEPORT_USHORT:
854f1d2b4d3SLarry Finger 			rtl_write_word(rtlpriv, currentcmd->para1,
855f1d2b4d3SLarry Finger 				       (u16) currentcmd->para2);
856f1d2b4d3SLarry Finger 			break;
857f1d2b4d3SLarry Finger 		case CMDID_WRITEPORT_UCHAR:
858f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, currentcmd->para1,
859f1d2b4d3SLarry Finger 				       (u8)currentcmd->para2);
860f1d2b4d3SLarry Finger 			break;
861f1d2b4d3SLarry Finger 		case CMDID_RF_WRITEREG:
862f1d2b4d3SLarry Finger 			for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) {
863f1d2b4d3SLarry Finger 				rtlphy->rfreg_chnlval[rfpath] =
864f1d2b4d3SLarry Finger 				    ((rtlphy->rfreg_chnlval[rfpath] &
865f1d2b4d3SLarry Finger 				      0xfffffc00) | currentcmd->para2);
866f1d2b4d3SLarry Finger 
867f1d2b4d3SLarry Finger 				rtl_set_rfreg(hw, (enum radio_path)rfpath,
868f1d2b4d3SLarry Finger 					      currentcmd->para1,
869f1d2b4d3SLarry Finger 					      RFREG_OFFSET_MASK,
870f1d2b4d3SLarry Finger 					      rtlphy->rfreg_chnlval[rfpath]);
871f1d2b4d3SLarry Finger 			}
872f1d2b4d3SLarry Finger 			_rtl92c_phy_sw_rf_seting(hw, channel);
873f1d2b4d3SLarry Finger 			break;
874f1d2b4d3SLarry Finger 		default:
8755b4e998bSLarry Finger 			rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
876ad574889SJoe Perches 				"switch case %#x not processed\n",
877ad574889SJoe Perches 				currentcmd->cmdid);
878f1d2b4d3SLarry Finger 			break;
879f1d2b4d3SLarry Finger 		}
880f1d2b4d3SLarry Finger 
881f1d2b4d3SLarry Finger 		break;
882f1d2b4d3SLarry Finger 	} while (true);
883f1d2b4d3SLarry Finger 
884f1d2b4d3SLarry Finger 	(*delay) = currentcmd->msdelay;
885f1d2b4d3SLarry Finger 	(*step)++;
886f1d2b4d3SLarry Finger 	return false;
887f1d2b4d3SLarry Finger }
888f1d2b4d3SLarry Finger 
rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw * hw,u32 rfpath)889f1d2b4d3SLarry Finger bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, u32 rfpath)
890f1d2b4d3SLarry Finger {
891f1d2b4d3SLarry Finger 	return true;
892f1d2b4d3SLarry Finger }
893f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl8192_phy_check_is_legal_rfpath);
894f1d2b4d3SLarry Finger 
_rtl92c_phy_path_a_iqk(struct ieee80211_hw * hw,bool config_pathb)895f1d2b4d3SLarry Finger static u8 _rtl92c_phy_path_a_iqk(struct ieee80211_hw *hw, bool config_pathb)
896f1d2b4d3SLarry Finger {
897f1d2b4d3SLarry Finger 	u32 reg_eac, reg_e94, reg_e9c, reg_ea4;
898f1d2b4d3SLarry Finger 	u8 result = 0x00;
899f1d2b4d3SLarry Finger 
900f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x10008c1f);
901f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x10008c1f);
902f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x82140102);
903f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe3c, MASKDWORD,
904f1d2b4d3SLarry Finger 		      config_pathb ? 0x28160202 : 0x28160502);
905f1d2b4d3SLarry Finger 
906f1d2b4d3SLarry Finger 	if (config_pathb) {
907f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0xe50, MASKDWORD, 0x10008c22);
908f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0xe54, MASKDWORD, 0x10008c22);
909f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0xe58, MASKDWORD, 0x82140102);
910f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0xe5c, MASKDWORD, 0x28160202);
911f1d2b4d3SLarry Finger 	}
912f1d2b4d3SLarry Finger 
913f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x001028d1);
914f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf9000000);
915f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000);
916f1d2b4d3SLarry Finger 
917f1d2b4d3SLarry Finger 	mdelay(IQK_DELAY_TIME);
918f1d2b4d3SLarry Finger 
919f1d2b4d3SLarry Finger 	reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD);
920f1d2b4d3SLarry Finger 	reg_e94 = rtl_get_bbreg(hw, 0xe94, MASKDWORD);
921f1d2b4d3SLarry Finger 	reg_e9c = rtl_get_bbreg(hw, 0xe9c, MASKDWORD);
922f1d2b4d3SLarry Finger 	reg_ea4 = rtl_get_bbreg(hw, 0xea4, MASKDWORD);
923f1d2b4d3SLarry Finger 
924f1d2b4d3SLarry Finger 	if (!(reg_eac & BIT(28)) &&
925f1d2b4d3SLarry Finger 	    (((reg_e94 & 0x03FF0000) >> 16) != 0x142) &&
926f1d2b4d3SLarry Finger 	    (((reg_e9c & 0x03FF0000) >> 16) != 0x42))
927f1d2b4d3SLarry Finger 		result |= 0x01;
928f1d2b4d3SLarry Finger 	else
929f1d2b4d3SLarry Finger 		return result;
930f1d2b4d3SLarry Finger 
931f1d2b4d3SLarry Finger 	if (!(reg_eac & BIT(27)) &&
932f1d2b4d3SLarry Finger 	    (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) &&
933f1d2b4d3SLarry Finger 	    (((reg_eac & 0x03FF0000) >> 16) != 0x36))
934f1d2b4d3SLarry Finger 		result |= 0x02;
935f1d2b4d3SLarry Finger 	return result;
936f1d2b4d3SLarry Finger }
937f1d2b4d3SLarry Finger 
_rtl92c_phy_path_b_iqk(struct ieee80211_hw * hw)938f1d2b4d3SLarry Finger static u8 _rtl92c_phy_path_b_iqk(struct ieee80211_hw *hw)
939f1d2b4d3SLarry Finger {
940f1d2b4d3SLarry Finger 	u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
941f1d2b4d3SLarry Finger 	u8 result = 0x00;
942f1d2b4d3SLarry Finger 
943f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000002);
944f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000000);
945f1d2b4d3SLarry Finger 	mdelay(IQK_DELAY_TIME);
946f1d2b4d3SLarry Finger 	reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD);
947f1d2b4d3SLarry Finger 	reg_eb4 = rtl_get_bbreg(hw, 0xeb4, MASKDWORD);
948f1d2b4d3SLarry Finger 	reg_ebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD);
949f1d2b4d3SLarry Finger 	reg_ec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD);
950f1d2b4d3SLarry Finger 	reg_ecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD);
951f1d2b4d3SLarry Finger 
952f1d2b4d3SLarry Finger 	if (!(reg_eac & BIT(31)) &&
953f1d2b4d3SLarry Finger 	    (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) &&
954f1d2b4d3SLarry Finger 	    (((reg_ebc & 0x03FF0000) >> 16) != 0x42))
955f1d2b4d3SLarry Finger 		result |= 0x01;
956f1d2b4d3SLarry Finger 	else
957f1d2b4d3SLarry Finger 		return result;
958f1d2b4d3SLarry Finger 	if (!(reg_eac & BIT(30)) &&
959f1d2b4d3SLarry Finger 	    (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) &&
960f1d2b4d3SLarry Finger 	    (((reg_ecc & 0x03FF0000) >> 16) != 0x36))
961f1d2b4d3SLarry Finger 		result |= 0x02;
962f1d2b4d3SLarry Finger 	return result;
963f1d2b4d3SLarry Finger }
964f1d2b4d3SLarry Finger 
_rtl92c_phy_path_a_fill_iqk_matrix(struct ieee80211_hw * hw,bool b_iqk_ok,long result[][8],u8 final_candidate,bool btxonly)965f1d2b4d3SLarry Finger static void _rtl92c_phy_path_a_fill_iqk_matrix(struct ieee80211_hw *hw,
966f1d2b4d3SLarry Finger 					       bool b_iqk_ok, long result[][8],
967f1d2b4d3SLarry Finger 					       u8 final_candidate, bool btxonly)
968f1d2b4d3SLarry Finger {
969f1d2b4d3SLarry Finger 	u32 oldval_0, x, tx0_a, reg;
970f1d2b4d3SLarry Finger 	long y, tx0_c;
971f1d2b4d3SLarry Finger 
972f1d2b4d3SLarry Finger 	if (final_candidate == 0xFF) {
973f1d2b4d3SLarry Finger 		return;
974f1d2b4d3SLarry Finger 	} else if (b_iqk_ok) {
975f1d2b4d3SLarry Finger 		oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE,
976f1d2b4d3SLarry Finger 					  MASKDWORD) >> 22) & 0x3FF;
977f1d2b4d3SLarry Finger 		x = result[final_candidate][0];
978f1d2b4d3SLarry Finger 		if ((x & 0x00000200) != 0)
979f1d2b4d3SLarry Finger 			x = x | 0xFFFFFC00;
980f1d2b4d3SLarry Finger 		tx0_a = (x * oldval_0) >> 8;
981f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x3FF, tx0_a);
982f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(31),
983f1d2b4d3SLarry Finger 			      ((x * oldval_0 >> 7) & 0x1));
984f1d2b4d3SLarry Finger 		y = result[final_candidate][1];
985f1d2b4d3SLarry Finger 		if ((y & 0x00000200) != 0)
986f1d2b4d3SLarry Finger 			y = y | 0xFFFFFC00;
987f1d2b4d3SLarry Finger 		tx0_c = (y * oldval_0) >> 8;
988f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XCTXAFE, 0xF0000000,
989f1d2b4d3SLarry Finger 			      ((tx0_c & 0x3C0) >> 6));
990f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x003F0000,
991f1d2b4d3SLarry Finger 			      (tx0_c & 0x3F));
992f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(29),
993f1d2b4d3SLarry Finger 			      ((y * oldval_0 >> 7) & 0x1));
994f1d2b4d3SLarry Finger 		if (btxonly)
995f1d2b4d3SLarry Finger 			return;
996f1d2b4d3SLarry Finger 		reg = result[final_candidate][2];
997f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0x3FF, reg);
998f1d2b4d3SLarry Finger 		reg = result[final_candidate][3] & 0x3F;
999f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0xFC00, reg);
1000f1d2b4d3SLarry Finger 		reg = (result[final_candidate][3] >> 6) & 0xF;
1001f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg);
1002f1d2b4d3SLarry Finger 	}
1003f1d2b4d3SLarry Finger }
1004f1d2b4d3SLarry Finger 
_rtl92c_phy_path_b_fill_iqk_matrix(struct ieee80211_hw * hw,bool b_iqk_ok,long result[][8],u8 final_candidate,bool btxonly)1005f1d2b4d3SLarry Finger static void _rtl92c_phy_path_b_fill_iqk_matrix(struct ieee80211_hw *hw,
1006f1d2b4d3SLarry Finger 					       bool b_iqk_ok, long result[][8],
1007f1d2b4d3SLarry Finger 					       u8 final_candidate, bool btxonly)
1008f1d2b4d3SLarry Finger {
1009f1d2b4d3SLarry Finger 	u32 oldval_1, x, tx1_a, reg;
1010f1d2b4d3SLarry Finger 	long y, tx1_c;
1011f1d2b4d3SLarry Finger 
1012f1d2b4d3SLarry Finger 	if (final_candidate == 0xFF) {
1013f1d2b4d3SLarry Finger 		return;
1014f1d2b4d3SLarry Finger 	} else if (b_iqk_ok) {
1015f1d2b4d3SLarry Finger 		oldval_1 = (rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE,
1016f1d2b4d3SLarry Finger 					  MASKDWORD) >> 22) & 0x3FF;
1017f1d2b4d3SLarry Finger 		x = result[final_candidate][4];
1018f1d2b4d3SLarry Finger 		if ((x & 0x00000200) != 0)
1019f1d2b4d3SLarry Finger 			x = x | 0xFFFFFC00;
1020f1d2b4d3SLarry Finger 		tx1_a = (x * oldval_1) >> 8;
1021f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 0x3FF, tx1_a);
1022f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(27),
1023f1d2b4d3SLarry Finger 			      ((x * oldval_1 >> 7) & 0x1));
1024f1d2b4d3SLarry Finger 		y = result[final_candidate][5];
1025f1d2b4d3SLarry Finger 		if ((y & 0x00000200) != 0)
1026f1d2b4d3SLarry Finger 			y = y | 0xFFFFFC00;
1027f1d2b4d3SLarry Finger 		tx1_c = (y * oldval_1) >> 8;
1028f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XDTXAFE, 0xF0000000,
1029f1d2b4d3SLarry Finger 			      ((tx1_c & 0x3C0) >> 6));
1030f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 0x003F0000,
1031f1d2b4d3SLarry Finger 			      (tx1_c & 0x3F));
1032f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(25),
1033f1d2b4d3SLarry Finger 			      ((y * oldval_1 >> 7) & 0x1));
1034f1d2b4d3SLarry Finger 		if (btxonly)
1035f1d2b4d3SLarry Finger 			return;
1036f1d2b4d3SLarry Finger 		reg = result[final_candidate][6];
1037f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0x3FF, reg);
1038f1d2b4d3SLarry Finger 		reg = result[final_candidate][7] & 0x3F;
1039f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0xFC00, reg);
1040f1d2b4d3SLarry Finger 		reg = (result[final_candidate][7] >> 6) & 0xF;
1041f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, 0x0000F000, reg);
1042f1d2b4d3SLarry Finger 	}
1043f1d2b4d3SLarry Finger }
1044f1d2b4d3SLarry Finger 
_rtl92c_phy_save_adda_registers(struct ieee80211_hw * hw,u32 * addareg,u32 * addabackup,u32 registernum)1045f1d2b4d3SLarry Finger static void _rtl92c_phy_save_adda_registers(struct ieee80211_hw *hw,
1046f1d2b4d3SLarry Finger 					    u32 *addareg, u32 *addabackup,
1047f1d2b4d3SLarry Finger 					    u32 registernum)
1048f1d2b4d3SLarry Finger {
1049f1d2b4d3SLarry Finger 	u32 i;
1050f1d2b4d3SLarry Finger 
1051f1d2b4d3SLarry Finger 	for (i = 0; i < registernum; i++)
1052f1d2b4d3SLarry Finger 		addabackup[i] = rtl_get_bbreg(hw, addareg[i], MASKDWORD);
1053f1d2b4d3SLarry Finger }
1054f1d2b4d3SLarry Finger 
_rtl92c_phy_save_mac_registers(struct ieee80211_hw * hw,u32 * macreg,u32 * macbackup)1055f1d2b4d3SLarry Finger static void _rtl92c_phy_save_mac_registers(struct ieee80211_hw *hw,
1056f1d2b4d3SLarry Finger 					   u32 *macreg, u32 *macbackup)
1057f1d2b4d3SLarry Finger {
1058f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1059f1d2b4d3SLarry Finger 	u32 i;
1060f1d2b4d3SLarry Finger 
1061f1d2b4d3SLarry Finger 	for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
1062f1d2b4d3SLarry Finger 		macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]);
1063f1d2b4d3SLarry Finger 	macbackup[i] = rtl_read_dword(rtlpriv, macreg[i]);
1064f1d2b4d3SLarry Finger }
1065f1d2b4d3SLarry Finger 
_rtl92c_phy_reload_adda_registers(struct ieee80211_hw * hw,u32 * addareg,u32 * addabackup,u32 regiesternum)1066f1d2b4d3SLarry Finger static void _rtl92c_phy_reload_adda_registers(struct ieee80211_hw *hw,
1067f1d2b4d3SLarry Finger 					      u32 *addareg, u32 *addabackup,
1068f1d2b4d3SLarry Finger 					      u32 regiesternum)
1069f1d2b4d3SLarry Finger {
1070f1d2b4d3SLarry Finger 	u32 i;
1071f1d2b4d3SLarry Finger 
1072f1d2b4d3SLarry Finger 	for (i = 0; i < regiesternum; i++)
1073f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, addareg[i], MASKDWORD, addabackup[i]);
1074f1d2b4d3SLarry Finger }
1075f1d2b4d3SLarry Finger 
_rtl92c_phy_reload_mac_registers(struct ieee80211_hw * hw,u32 * macreg,u32 * macbackup)1076f1d2b4d3SLarry Finger static void _rtl92c_phy_reload_mac_registers(struct ieee80211_hw *hw,
1077f1d2b4d3SLarry Finger 					     u32 *macreg, u32 *macbackup)
1078f1d2b4d3SLarry Finger {
1079f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1080f1d2b4d3SLarry Finger 	u32 i;
1081f1d2b4d3SLarry Finger 
1082f1d2b4d3SLarry Finger 	for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
1083f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, macreg[i], (u8)macbackup[i]);
1084f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, macreg[i], macbackup[i]);
1085f1d2b4d3SLarry Finger }
1086f1d2b4d3SLarry Finger 
_rtl92c_phy_path_adda_on(struct ieee80211_hw * hw,u32 * addareg,bool is_patha_on,bool is2t)1087f1d2b4d3SLarry Finger static void _rtl92c_phy_path_adda_on(struct ieee80211_hw *hw,
1088f1d2b4d3SLarry Finger 				     u32 *addareg, bool is_patha_on, bool is2t)
1089f1d2b4d3SLarry Finger {
1090ff970453SLarry Finger 	u32 pathon;
1091f1d2b4d3SLarry Finger 	u32 i;
1092f1d2b4d3SLarry Finger 
1093ff970453SLarry Finger 	pathon = is_patha_on ? 0x04db25a4 : 0x0b1b25a4;
10944cff897cSZheng Bin 	if (!is2t) {
1095ff970453SLarry Finger 		pathon = 0x0bdb25a0;
1096f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, addareg[0], MASKDWORD, 0x0b1b25a0);
1097f1d2b4d3SLarry Finger 	} else {
1098ff970453SLarry Finger 		rtl_set_bbreg(hw, addareg[0], MASKDWORD, pathon);
1099f1d2b4d3SLarry Finger 	}
1100f1d2b4d3SLarry Finger 
1101f1d2b4d3SLarry Finger 	for (i = 1; i < IQK_ADDA_REG_NUM; i++)
1102ff970453SLarry Finger 		rtl_set_bbreg(hw, addareg[i], MASKDWORD, pathon);
1103f1d2b4d3SLarry Finger }
1104f1d2b4d3SLarry Finger 
_rtl92c_phy_mac_setting_calibration(struct ieee80211_hw * hw,u32 * macreg,u32 * macbackup)1105f1d2b4d3SLarry Finger static void _rtl92c_phy_mac_setting_calibration(struct ieee80211_hw *hw,
1106f1d2b4d3SLarry Finger 						u32 *macreg, u32 *macbackup)
1107f1d2b4d3SLarry Finger {
1108f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1109f1d2b4d3SLarry Finger 	u32 i = 0;
1110f1d2b4d3SLarry Finger 
1111f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, macreg[i], 0x3F);
1112f1d2b4d3SLarry Finger 
1113f1d2b4d3SLarry Finger 	for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++)
1114f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, macreg[i],
1115f1d2b4d3SLarry Finger 			       (u8)(macbackup[i] & (~BIT(3))));
1116f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, macreg[i], (u8)(macbackup[i] & (~BIT(5))));
1117f1d2b4d3SLarry Finger }
1118f1d2b4d3SLarry Finger 
_rtl92c_phy_path_a_standby(struct ieee80211_hw * hw)1119f1d2b4d3SLarry Finger static void _rtl92c_phy_path_a_standby(struct ieee80211_hw *hw)
1120f1d2b4d3SLarry Finger {
1121f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x0);
1122f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000);
1123f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000);
1124f1d2b4d3SLarry Finger }
1125f1d2b4d3SLarry Finger 
_rtl92c_phy_pi_mode_switch(struct ieee80211_hw * hw,bool pi_mode)1126f1d2b4d3SLarry Finger static void _rtl92c_phy_pi_mode_switch(struct ieee80211_hw *hw, bool pi_mode)
1127f1d2b4d3SLarry Finger {
1128f1d2b4d3SLarry Finger 	u32 mode;
1129f1d2b4d3SLarry Finger 
1130f1d2b4d3SLarry Finger 	mode = pi_mode ? 0x01000100 : 0x01000000;
1131f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0x820, MASKDWORD, mode);
1132f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0x828, MASKDWORD, mode);
1133f1d2b4d3SLarry Finger }
1134f1d2b4d3SLarry Finger 
_rtl92c_phy_simularity_compare(struct ieee80211_hw * hw,long result[][8],u8 c1,u8 c2)1135f1d2b4d3SLarry Finger static bool _rtl92c_phy_simularity_compare(struct ieee80211_hw *hw,
1136f1d2b4d3SLarry Finger 					   long result[][8], u8 c1, u8 c2)
1137f1d2b4d3SLarry Finger {
1138f1d2b4d3SLarry Finger 	u32 i, j, diff, simularity_bitmap, bound;
1139f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1140f1d2b4d3SLarry Finger 
1141f1d2b4d3SLarry Finger 	u8 final_candidate[2] = { 0xFF, 0xFF };
1142f1d2b4d3SLarry Finger 	bool bresult = true, is2t = IS_92C_SERIAL(rtlhal->version);
1143f1d2b4d3SLarry Finger 
1144f1d2b4d3SLarry Finger 	if (is2t)
1145f1d2b4d3SLarry Finger 		bound = 8;
1146f1d2b4d3SLarry Finger 	else
1147f1d2b4d3SLarry Finger 		bound = 4;
1148f1d2b4d3SLarry Finger 
1149f1d2b4d3SLarry Finger 	simularity_bitmap = 0;
1150f1d2b4d3SLarry Finger 
1151f1d2b4d3SLarry Finger 	for (i = 0; i < bound; i++) {
1152f1d2b4d3SLarry Finger 		diff = (result[c1][i] > result[c2][i]) ?
1153f1d2b4d3SLarry Finger 		    (result[c1][i] - result[c2][i]) :
1154f1d2b4d3SLarry Finger 		    (result[c2][i] - result[c1][i]);
1155f1d2b4d3SLarry Finger 
1156f1d2b4d3SLarry Finger 		if (diff > MAX_TOLERANCE) {
1157f1d2b4d3SLarry Finger 			if ((i == 2 || i == 6) && !simularity_bitmap) {
1158f1d2b4d3SLarry Finger 				if (result[c1][i] + result[c1][i + 1] == 0)
1159f1d2b4d3SLarry Finger 					final_candidate[(i / 4)] = c2;
1160f1d2b4d3SLarry Finger 				else if (result[c2][i] + result[c2][i + 1] == 0)
1161f1d2b4d3SLarry Finger 					final_candidate[(i / 4)] = c1;
1162f1d2b4d3SLarry Finger 				else
1163f1d2b4d3SLarry Finger 					simularity_bitmap = simularity_bitmap |
1164f1d2b4d3SLarry Finger 					    (1 << i);
1165f1d2b4d3SLarry Finger 			} else
1166f1d2b4d3SLarry Finger 				simularity_bitmap =
1167f1d2b4d3SLarry Finger 				    simularity_bitmap | (1 << i);
1168f1d2b4d3SLarry Finger 		}
1169f1d2b4d3SLarry Finger 	}
1170f1d2b4d3SLarry Finger 
1171f1d2b4d3SLarry Finger 	if (simularity_bitmap == 0) {
1172f1d2b4d3SLarry Finger 		for (i = 0; i < (bound / 4); i++) {
1173f1d2b4d3SLarry Finger 			if (final_candidate[i] != 0xFF) {
1174f1d2b4d3SLarry Finger 				for (j = i * 4; j < (i + 1) * 4 - 2; j++)
1175f1d2b4d3SLarry Finger 					result[3][j] =
1176f1d2b4d3SLarry Finger 					    result[final_candidate[i]][j];
1177f1d2b4d3SLarry Finger 				bresult = false;
1178f1d2b4d3SLarry Finger 			}
1179f1d2b4d3SLarry Finger 		}
1180f1d2b4d3SLarry Finger 		return bresult;
1181f1d2b4d3SLarry Finger 	} else if (!(simularity_bitmap & 0x0F)) {
1182f1d2b4d3SLarry Finger 		for (i = 0; i < 4; i++)
1183f1d2b4d3SLarry Finger 			result[3][i] = result[c1][i];
1184f1d2b4d3SLarry Finger 		return false;
1185f1d2b4d3SLarry Finger 	} else if (!(simularity_bitmap & 0xF0) && is2t) {
1186f1d2b4d3SLarry Finger 		for (i = 4; i < 8; i++)
1187f1d2b4d3SLarry Finger 			result[3][i] = result[c1][i];
1188f1d2b4d3SLarry Finger 		return false;
1189f1d2b4d3SLarry Finger 	} else {
1190f1d2b4d3SLarry Finger 		return false;
1191f1d2b4d3SLarry Finger 	}
1192f1d2b4d3SLarry Finger }
1193f1d2b4d3SLarry Finger 
_rtl92c_phy_iq_calibrate(struct ieee80211_hw * hw,long result[][8],u8 t,bool is2t)1194f1d2b4d3SLarry Finger static void _rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw,
1195f1d2b4d3SLarry Finger 				     long result[][8], u8 t, bool is2t)
1196f1d2b4d3SLarry Finger {
1197f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1198f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1199f1d2b4d3SLarry Finger 	u32 i;
1200f1d2b4d3SLarry Finger 	u8 patha_ok, pathb_ok;
1201f1d2b4d3SLarry Finger 	u32 adda_reg[IQK_ADDA_REG_NUM] = {
1202f1d2b4d3SLarry Finger 		0x85c, 0xe6c, 0xe70, 0xe74,
1203f1d2b4d3SLarry Finger 		0xe78, 0xe7c, 0xe80, 0xe84,
1204f1d2b4d3SLarry Finger 		0xe88, 0xe8c, 0xed0, 0xed4,
1205f1d2b4d3SLarry Finger 		0xed8, 0xedc, 0xee0, 0xeec
1206f1d2b4d3SLarry Finger 	};
1207f1d2b4d3SLarry Finger 	u32 iqk_mac_reg[IQK_MAC_REG_NUM] = {
1208f1d2b4d3SLarry Finger 		0x522, 0x550, 0x551, 0x040
1209f1d2b4d3SLarry Finger 	};
1210f1d2b4d3SLarry Finger 	const u32 retrycount = 2;
1211f1d2b4d3SLarry Finger 
1212f1d2b4d3SLarry Finger 	if (t == 0) {
1213e9cf68ffSLee Jones 		rtl_get_bbreg(hw, 0x800, MASKDWORD);
1214f1d2b4d3SLarry Finger 
1215f1d2b4d3SLarry Finger 		_rtl92c_phy_save_adda_registers(hw, adda_reg,
1216f1d2b4d3SLarry Finger 						rtlphy->adda_backup, 16);
1217f1d2b4d3SLarry Finger 		_rtl92c_phy_save_mac_registers(hw, iqk_mac_reg,
1218f1d2b4d3SLarry Finger 					       rtlphy->iqk_mac_backup);
1219f1d2b4d3SLarry Finger 	}
1220f1d2b4d3SLarry Finger 	_rtl92c_phy_path_adda_on(hw, adda_reg, true, is2t);
1221f1d2b4d3SLarry Finger 	if (t == 0) {
1222f1d2b4d3SLarry Finger 		rtlphy->rfpi_enable =
1223f1d2b4d3SLarry Finger 		   (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1,
1224f1d2b4d3SLarry Finger 				     BIT(8));
1225f1d2b4d3SLarry Finger 	}
1226f1d2b4d3SLarry Finger 
1227f1d2b4d3SLarry Finger 	if (!rtlphy->rfpi_enable)
1228f1d2b4d3SLarry Finger 		_rtl92c_phy_pi_mode_switch(hw, true);
1229f1d2b4d3SLarry Finger 	if (t == 0) {
1230f1d2b4d3SLarry Finger 		rtlphy->reg_c04 = rtl_get_bbreg(hw, 0xc04, MASKDWORD);
1231f1d2b4d3SLarry Finger 		rtlphy->reg_c08 = rtl_get_bbreg(hw, 0xc08, MASKDWORD);
1232f1d2b4d3SLarry Finger 		rtlphy->reg_874 = rtl_get_bbreg(hw, 0x874, MASKDWORD);
1233f1d2b4d3SLarry Finger 	}
1234f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xc04, MASKDWORD, 0x03a05600);
1235f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xc08, MASKDWORD, 0x000800e4);
1236f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0x874, MASKDWORD, 0x22204000);
1237f1d2b4d3SLarry Finger 	if (is2t) {
1238f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000);
1239f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00010000);
1240f1d2b4d3SLarry Finger 	}
1241f1d2b4d3SLarry Finger 	_rtl92c_phy_mac_setting_calibration(hw, iqk_mac_reg,
1242f1d2b4d3SLarry Finger 					    rtlphy->iqk_mac_backup);
1243f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xb68, MASKDWORD, 0x00080000);
1244f1d2b4d3SLarry Finger 	if (is2t)
1245f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0xb6c, MASKDWORD, 0x00080000);
1246f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000);
1247f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe40, MASKDWORD, 0x01007c00);
1248f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe44, MASKDWORD, 0x01004800);
1249f1d2b4d3SLarry Finger 	for (i = 0; i < retrycount; i++) {
1250f1d2b4d3SLarry Finger 		patha_ok = _rtl92c_phy_path_a_iqk(hw, is2t);
1251f1d2b4d3SLarry Finger 		if (patha_ok == 0x03) {
1252f1d2b4d3SLarry Finger 			result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) &
1253f1d2b4d3SLarry Finger 					0x3FF0000) >> 16;
1254f1d2b4d3SLarry Finger 			result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) &
1255f1d2b4d3SLarry Finger 					0x3FF0000) >> 16;
1256f1d2b4d3SLarry Finger 			result[t][2] = (rtl_get_bbreg(hw, 0xea4, MASKDWORD) &
1257f1d2b4d3SLarry Finger 					0x3FF0000) >> 16;
1258f1d2b4d3SLarry Finger 			result[t][3] = (rtl_get_bbreg(hw, 0xeac, MASKDWORD) &
1259f1d2b4d3SLarry Finger 					0x3FF0000) >> 16;
1260f1d2b4d3SLarry Finger 			break;
1261f1d2b4d3SLarry Finger 		} else if (i == (retrycount - 1) && patha_ok == 0x01)
1262f1d2b4d3SLarry Finger 
1263f1d2b4d3SLarry Finger 			result[t][0] = (rtl_get_bbreg(hw, 0xe94,
1264f1d2b4d3SLarry Finger 						      MASKDWORD) & 0x3FF0000) >>
1265f1d2b4d3SLarry Finger 			    16;
1266f1d2b4d3SLarry Finger 		result[t][1] =
1267f1d2b4d3SLarry Finger 		    (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 0x3FF0000) >> 16;
1268f1d2b4d3SLarry Finger 
1269f1d2b4d3SLarry Finger 	}
1270f1d2b4d3SLarry Finger 
1271f1d2b4d3SLarry Finger 	if (is2t) {
1272f1d2b4d3SLarry Finger 		_rtl92c_phy_path_a_standby(hw);
1273f1d2b4d3SLarry Finger 		_rtl92c_phy_path_adda_on(hw, adda_reg, false, is2t);
1274f1d2b4d3SLarry Finger 		for (i = 0; i < retrycount; i++) {
1275f1d2b4d3SLarry Finger 			pathb_ok = _rtl92c_phy_path_b_iqk(hw);
1276f1d2b4d3SLarry Finger 			if (pathb_ok == 0x03) {
1277f1d2b4d3SLarry Finger 				result[t][4] = (rtl_get_bbreg(hw,
1278f1d2b4d3SLarry Finger 							      0xeb4,
1279f1d2b4d3SLarry Finger 							      MASKDWORD) &
1280f1d2b4d3SLarry Finger 						0x3FF0000) >> 16;
1281f1d2b4d3SLarry Finger 				result[t][5] =
1282f1d2b4d3SLarry Finger 				    (rtl_get_bbreg(hw, 0xebc, MASKDWORD) &
1283f1d2b4d3SLarry Finger 				     0x3FF0000) >> 16;
1284f1d2b4d3SLarry Finger 				result[t][6] =
1285f1d2b4d3SLarry Finger 				    (rtl_get_bbreg(hw, 0xec4, MASKDWORD) &
1286f1d2b4d3SLarry Finger 				     0x3FF0000) >> 16;
1287f1d2b4d3SLarry Finger 				result[t][7] =
1288f1d2b4d3SLarry Finger 				    (rtl_get_bbreg(hw, 0xecc, MASKDWORD) &
1289f1d2b4d3SLarry Finger 				     0x3FF0000) >> 16;
1290f1d2b4d3SLarry Finger 				break;
1291f1d2b4d3SLarry Finger 			} else if (i == (retrycount - 1) && pathb_ok == 0x01) {
1292f1d2b4d3SLarry Finger 				result[t][4] = (rtl_get_bbreg(hw,
1293f1d2b4d3SLarry Finger 							      0xeb4,
1294f1d2b4d3SLarry Finger 							      MASKDWORD) &
1295f1d2b4d3SLarry Finger 						0x3FF0000) >> 16;
1296f1d2b4d3SLarry Finger 			}
1297f1d2b4d3SLarry Finger 			result[t][5] = (rtl_get_bbreg(hw, 0xebc, MASKDWORD) &
1298f1d2b4d3SLarry Finger 					0x3FF0000) >> 16;
1299f1d2b4d3SLarry Finger 		}
1300f1d2b4d3SLarry Finger 	}
1301f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xc04, MASKDWORD, rtlphy->reg_c04);
1302f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0x874, MASKDWORD, rtlphy->reg_874);
1303f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xc08, MASKDWORD, rtlphy->reg_c08);
1304f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0);
1305f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00032ed3);
1306f1d2b4d3SLarry Finger 	if (is2t)
1307f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00032ed3);
1308f1d2b4d3SLarry Finger 	if (t != 0) {
1309f1d2b4d3SLarry Finger 		if (!rtlphy->rfpi_enable)
1310f1d2b4d3SLarry Finger 			_rtl92c_phy_pi_mode_switch(hw, false);
1311f1d2b4d3SLarry Finger 		_rtl92c_phy_reload_adda_registers(hw, adda_reg,
1312f1d2b4d3SLarry Finger 						  rtlphy->adda_backup, 16);
1313f1d2b4d3SLarry Finger 		_rtl92c_phy_reload_mac_registers(hw, iqk_mac_reg,
1314f1d2b4d3SLarry Finger 						 rtlphy->iqk_mac_backup);
1315f1d2b4d3SLarry Finger 	}
1316f1d2b4d3SLarry Finger }
1317f1d2b4d3SLarry Finger 
_rtl92c_phy_ap_calibrate(struct ieee80211_hw * hw,s8 delta,bool is2t)1318f1d2b4d3SLarry Finger static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw,
131908aba42fSArnd Bergmann 				     s8 delta, bool is2t)
1320f1d2b4d3SLarry Finger {
1321f1d2b4d3SLarry Finger }
1322f1d2b4d3SLarry Finger 
_rtl92c_phy_set_rfpath_switch(struct ieee80211_hw * hw,bool bmain,bool is2t)1323f1d2b4d3SLarry Finger static void _rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw,
1324f1d2b4d3SLarry Finger 					  bool bmain, bool is2t)
1325f1d2b4d3SLarry Finger {
1326f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1327f1d2b4d3SLarry Finger 
1328f1d2b4d3SLarry Finger 	if (is_hal_stop(rtlhal)) {
1329f1d2b4d3SLarry Finger 		rtl_set_bbreg(hw, REG_LEDCFG0, BIT(23), 0x01);
1330ff970453SLarry Finger 		rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(13), 0x01);
1331f1d2b4d3SLarry Finger 	}
1332f1d2b4d3SLarry Finger 	if (is2t) {
1333f1d2b4d3SLarry Finger 		if (bmain)
1334f1d2b4d3SLarry Finger 			rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
1335f1d2b4d3SLarry Finger 				      BIT(5) | BIT(6), 0x1);
1336f1d2b4d3SLarry Finger 		else
1337f1d2b4d3SLarry Finger 			rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
1338f1d2b4d3SLarry Finger 				      BIT(5) | BIT(6), 0x2);
1339f1d2b4d3SLarry Finger 	} else {
1340f1d2b4d3SLarry Finger 		if (bmain)
1341f1d2b4d3SLarry Finger 			rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 0x300, 0x2);
1342f1d2b4d3SLarry Finger 		else
1343f1d2b4d3SLarry Finger 			rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 0x300, 0x1);
1344f1d2b4d3SLarry Finger 	}
1345f1d2b4d3SLarry Finger }
1346f1d2b4d3SLarry Finger 
1347f1d2b4d3SLarry Finger #undef IQK_ADDA_REG_NUM
1348f1d2b4d3SLarry Finger #undef IQK_DELAY_TIME
1349f1d2b4d3SLarry Finger 
rtl92c_phy_iq_calibrate(struct ieee80211_hw * hw,bool b_recovery)1350f1d2b4d3SLarry Finger void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery)
1351f1d2b4d3SLarry Finger {
1352f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1353f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1354f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1355f1d2b4d3SLarry Finger 
1356f1d2b4d3SLarry Finger 	long result[4][8];
1357f1d2b4d3SLarry Finger 	u8 i, final_candidate;
1358f1d2b4d3SLarry Finger 	bool b_patha_ok, b_pathb_ok;
1359a003aec3Szhengbin 	long reg_e94, reg_e9c, reg_ea4, reg_eb4, reg_ebc, reg_ec4,
1360a003aec3Szhengbin 	    reg_tmp = 0;
1361f1d2b4d3SLarry Finger 	bool is12simular, is13simular, is23simular;
1362f1d2b4d3SLarry Finger 	u32 iqk_bb_reg[10] = {
1363f1d2b4d3SLarry Finger 		ROFDM0_XARXIQIMBALANCE,
1364f1d2b4d3SLarry Finger 		ROFDM0_XBRXIQIMBALANCE,
1365f1d2b4d3SLarry Finger 		ROFDM0_ECCATHRESHOLD,
1366f1d2b4d3SLarry Finger 		ROFDM0_AGCRSSITABLE,
1367f1d2b4d3SLarry Finger 		ROFDM0_XATXIQIMBALANCE,
1368f1d2b4d3SLarry Finger 		ROFDM0_XBTXIQIMBALANCE,
1369f1d2b4d3SLarry Finger 		ROFDM0_XCTXIQIMBALANCE,
1370f1d2b4d3SLarry Finger 		ROFDM0_XCTXAFE,
1371f1d2b4d3SLarry Finger 		ROFDM0_XDTXAFE,
1372f1d2b4d3SLarry Finger 		ROFDM0_RXIQEXTANTA
1373f1d2b4d3SLarry Finger 	};
1374f1d2b4d3SLarry Finger 
1375f1d2b4d3SLarry Finger 	if (b_recovery) {
1376f1d2b4d3SLarry Finger 		_rtl92c_phy_reload_adda_registers(hw,
1377f1d2b4d3SLarry Finger 						  iqk_bb_reg,
1378f1d2b4d3SLarry Finger 						  rtlphy->iqk_bb_backup, 10);
1379f1d2b4d3SLarry Finger 		return;
1380f1d2b4d3SLarry Finger 	}
1381f1d2b4d3SLarry Finger 	for (i = 0; i < 8; i++) {
1382f1d2b4d3SLarry Finger 		result[0][i] = 0;
1383f1d2b4d3SLarry Finger 		result[1][i] = 0;
1384f1d2b4d3SLarry Finger 		result[2][i] = 0;
1385f1d2b4d3SLarry Finger 		result[3][i] = 0;
1386f1d2b4d3SLarry Finger 	}
1387f1d2b4d3SLarry Finger 	final_candidate = 0xff;
1388f1d2b4d3SLarry Finger 	b_patha_ok = false;
1389f1d2b4d3SLarry Finger 	b_pathb_ok = false;
1390f1d2b4d3SLarry Finger 	is12simular = false;
1391f1d2b4d3SLarry Finger 	is23simular = false;
1392f1d2b4d3SLarry Finger 	is13simular = false;
1393f1d2b4d3SLarry Finger 	for (i = 0; i < 3; i++) {
1394f1d2b4d3SLarry Finger 		if (IS_92C_SERIAL(rtlhal->version))
1395f1d2b4d3SLarry Finger 			_rtl92c_phy_iq_calibrate(hw, result, i, true);
1396f1d2b4d3SLarry Finger 		else
1397f1d2b4d3SLarry Finger 			_rtl92c_phy_iq_calibrate(hw, result, i, false);
1398f1d2b4d3SLarry Finger 		if (i == 1) {
1399f1d2b4d3SLarry Finger 			is12simular = _rtl92c_phy_simularity_compare(hw,
1400f1d2b4d3SLarry Finger 								     result, 0,
1401f1d2b4d3SLarry Finger 								     1);
1402f1d2b4d3SLarry Finger 			if (is12simular) {
1403f1d2b4d3SLarry Finger 				final_candidate = 0;
1404f1d2b4d3SLarry Finger 				break;
1405f1d2b4d3SLarry Finger 			}
1406f1d2b4d3SLarry Finger 		}
1407f1d2b4d3SLarry Finger 		if (i == 2) {
1408f1d2b4d3SLarry Finger 			is13simular = _rtl92c_phy_simularity_compare(hw,
1409f1d2b4d3SLarry Finger 								     result, 0,
1410f1d2b4d3SLarry Finger 								     2);
1411f1d2b4d3SLarry Finger 			if (is13simular) {
1412f1d2b4d3SLarry Finger 				final_candidate = 0;
1413f1d2b4d3SLarry Finger 				break;
1414f1d2b4d3SLarry Finger 			}
1415f1d2b4d3SLarry Finger 			is23simular = _rtl92c_phy_simularity_compare(hw,
1416f1d2b4d3SLarry Finger 								     result, 1,
1417f1d2b4d3SLarry Finger 								     2);
1418f1d2b4d3SLarry Finger 			if (is23simular)
1419f1d2b4d3SLarry Finger 				final_candidate = 1;
1420f1d2b4d3SLarry Finger 			else {
1421f1d2b4d3SLarry Finger 				for (i = 0; i < 8; i++)
1422f1d2b4d3SLarry Finger 					reg_tmp += result[3][i];
1423f1d2b4d3SLarry Finger 
1424f1d2b4d3SLarry Finger 				if (reg_tmp != 0)
1425f1d2b4d3SLarry Finger 					final_candidate = 3;
1426f1d2b4d3SLarry Finger 				else
1427f1d2b4d3SLarry Finger 					final_candidate = 0xFF;
1428f1d2b4d3SLarry Finger 			}
1429f1d2b4d3SLarry Finger 		}
1430f1d2b4d3SLarry Finger 	}
1431f1d2b4d3SLarry Finger 	for (i = 0; i < 4; i++) {
1432f1d2b4d3SLarry Finger 		reg_e94 = result[i][0];
1433f1d2b4d3SLarry Finger 		reg_e9c = result[i][1];
1434f1d2b4d3SLarry Finger 		reg_ea4 = result[i][2];
1435f1d2b4d3SLarry Finger 		reg_eb4 = result[i][4];
1436f1d2b4d3SLarry Finger 		reg_ebc = result[i][5];
1437f1d2b4d3SLarry Finger 		reg_ec4 = result[i][6];
1438f1d2b4d3SLarry Finger 	}
1439f1d2b4d3SLarry Finger 	if (final_candidate != 0xff) {
1440f1d2b4d3SLarry Finger 		rtlphy->reg_e94 = reg_e94 = result[final_candidate][0];
1441f1d2b4d3SLarry Finger 		rtlphy->reg_e9c = reg_e9c = result[final_candidate][1];
1442f1d2b4d3SLarry Finger 		reg_ea4 = result[final_candidate][2];
1443f1d2b4d3SLarry Finger 		rtlphy->reg_eb4 = reg_eb4 = result[final_candidate][4];
1444f1d2b4d3SLarry Finger 		rtlphy->reg_ebc = reg_ebc = result[final_candidate][5];
1445f1d2b4d3SLarry Finger 		reg_ec4 = result[final_candidate][6];
1446f1d2b4d3SLarry Finger 		b_patha_ok = true;
1447f1d2b4d3SLarry Finger 		b_pathb_ok = true;
1448f1d2b4d3SLarry Finger 	} else {
1449f1d2b4d3SLarry Finger 		rtlphy->reg_e94 = rtlphy->reg_eb4 = 0x100;
1450f1d2b4d3SLarry Finger 		rtlphy->reg_e9c = rtlphy->reg_ebc = 0x0;
1451f1d2b4d3SLarry Finger 	}
1452f1d2b4d3SLarry Finger 	if (reg_e94 != 0) /*&&(reg_ea4 != 0) */
1453f1d2b4d3SLarry Finger 		_rtl92c_phy_path_a_fill_iqk_matrix(hw, b_patha_ok, result,
1454f1d2b4d3SLarry Finger 						   final_candidate,
1455f1d2b4d3SLarry Finger 						   (reg_ea4 == 0));
1456f1d2b4d3SLarry Finger 	if (IS_92C_SERIAL(rtlhal->version)) {
1457f1d2b4d3SLarry Finger 		if (reg_eb4 != 0) /*&&(reg_ec4 != 0) */
1458f1d2b4d3SLarry Finger 			_rtl92c_phy_path_b_fill_iqk_matrix(hw, b_pathb_ok,
1459f1d2b4d3SLarry Finger 							   result,
1460f1d2b4d3SLarry Finger 							   final_candidate,
1461f1d2b4d3SLarry Finger 							   (reg_ec4 == 0));
1462f1d2b4d3SLarry Finger 	}
1463f1d2b4d3SLarry Finger 	_rtl92c_phy_save_adda_registers(hw, iqk_bb_reg,
1464f1d2b4d3SLarry Finger 					rtlphy->iqk_bb_backup, 10);
1465f1d2b4d3SLarry Finger }
1466f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_iq_calibrate);
1467f1d2b4d3SLarry Finger 
rtl92c_phy_lc_calibrate(struct ieee80211_hw * hw)1468f1d2b4d3SLarry Finger void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw)
1469f1d2b4d3SLarry Finger {
1470f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1471f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1472f1d2b4d3SLarry Finger 
1473f1d2b4d3SLarry Finger 	if (IS_92C_SERIAL(rtlhal->version))
1474f1d2b4d3SLarry Finger 		rtlpriv->cfg->ops->phy_lc_calibrate(hw, true);
1475f1d2b4d3SLarry Finger 	else
1476f1d2b4d3SLarry Finger 		rtlpriv->cfg->ops->phy_lc_calibrate(hw, false);
1477f1d2b4d3SLarry Finger }
1478f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_lc_calibrate);
1479f1d2b4d3SLarry Finger 
rtl92c_phy_ap_calibrate(struct ieee80211_hw * hw,s8 delta)148008aba42fSArnd Bergmann void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, s8 delta)
1481f1d2b4d3SLarry Finger {
1482f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1483f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1484f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1485f1d2b4d3SLarry Finger 
1486f1d2b4d3SLarry Finger 	if (rtlphy->apk_done)
1487f1d2b4d3SLarry Finger 		return;
1488f1d2b4d3SLarry Finger 	if (IS_92C_SERIAL(rtlhal->version))
1489f1d2b4d3SLarry Finger 		_rtl92c_phy_ap_calibrate(hw, delta, true);
1490f1d2b4d3SLarry Finger 	else
1491f1d2b4d3SLarry Finger 		_rtl92c_phy_ap_calibrate(hw, delta, false);
1492f1d2b4d3SLarry Finger }
1493f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_ap_calibrate);
1494f1d2b4d3SLarry Finger 
rtl92c_phy_set_rfpath_switch(struct ieee80211_hw * hw,bool bmain)1495f1d2b4d3SLarry Finger void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain)
1496f1d2b4d3SLarry Finger {
1497f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1498f1d2b4d3SLarry Finger 
1499f1d2b4d3SLarry Finger 	if (IS_92C_SERIAL(rtlhal->version))
1500f1d2b4d3SLarry Finger 		_rtl92c_phy_set_rfpath_switch(hw, bmain, true);
1501f1d2b4d3SLarry Finger 	else
1502f1d2b4d3SLarry Finger 		_rtl92c_phy_set_rfpath_switch(hw, bmain, false);
1503f1d2b4d3SLarry Finger }
1504f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_set_rfpath_switch);
1505f1d2b4d3SLarry Finger 
rtl92c_phy_set_io_cmd(struct ieee80211_hw * hw,enum io_type iotype)1506f1d2b4d3SLarry Finger bool rtl92c_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
1507f1d2b4d3SLarry Finger {
1508f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1509f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1510f1d2b4d3SLarry Finger 	bool postprocessing = false;
1511f1d2b4d3SLarry Finger 
15125b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
1513f1d2b4d3SLarry Finger 		"-->IO Cmd(%#x), set_io_inprogress(%d)\n",
1514f1d2b4d3SLarry Finger 		iotype, rtlphy->set_io_inprogress);
1515f1d2b4d3SLarry Finger 	do {
1516f1d2b4d3SLarry Finger 		switch (iotype) {
1517f1d2b4d3SLarry Finger 		case IO_CMD_RESUME_DM_BY_SCAN:
15185b4e998bSLarry Finger 			rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
1519f1d2b4d3SLarry Finger 				"[IO CMD] Resume DM after scan.\n");
1520f1d2b4d3SLarry Finger 			postprocessing = true;
1521f1d2b4d3SLarry Finger 			break;
1522f1d2b4d3SLarry Finger 		case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
15235b4e998bSLarry Finger 			rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
1524f1d2b4d3SLarry Finger 				"[IO CMD] Pause DM before scan.\n");
1525f1d2b4d3SLarry Finger 			postprocessing = true;
1526f1d2b4d3SLarry Finger 			break;
1527f1d2b4d3SLarry Finger 		default:
15285b4e998bSLarry Finger 			rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
1529ad574889SJoe Perches 				"switch case %#x not processed\n", iotype);
1530f1d2b4d3SLarry Finger 			break;
1531f1d2b4d3SLarry Finger 		}
1532f1d2b4d3SLarry Finger 	} while (false);
1533f1d2b4d3SLarry Finger 	if (postprocessing && !rtlphy->set_io_inprogress) {
1534f1d2b4d3SLarry Finger 		rtlphy->set_io_inprogress = true;
1535f1d2b4d3SLarry Finger 		rtlphy->current_io_type = iotype;
1536f1d2b4d3SLarry Finger 	} else {
1537f1d2b4d3SLarry Finger 		return false;
1538f1d2b4d3SLarry Finger 	}
1539f1d2b4d3SLarry Finger 	rtl92c_phy_set_io(hw);
15405b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "IO Type(%#x)\n", iotype);
1541f1d2b4d3SLarry Finger 	return true;
1542f1d2b4d3SLarry Finger }
1543f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_set_io_cmd);
1544f1d2b4d3SLarry Finger 
rtl92c_phy_set_io(struct ieee80211_hw * hw)1545f1d2b4d3SLarry Finger void rtl92c_phy_set_io(struct ieee80211_hw *hw)
1546f1d2b4d3SLarry Finger {
1547f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1548f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1549f1d2b4d3SLarry Finger 	struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
1550f1d2b4d3SLarry Finger 
15515b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
1552f1d2b4d3SLarry Finger 		"--->Cmd(%#x), set_io_inprogress(%d)\n",
1553f1d2b4d3SLarry Finger 		rtlphy->current_io_type, rtlphy->set_io_inprogress);
1554f1d2b4d3SLarry Finger 	switch (rtlphy->current_io_type) {
1555f1d2b4d3SLarry Finger 	case IO_CMD_RESUME_DM_BY_SCAN:
1556f1d2b4d3SLarry Finger 		dm_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1;
1557f1d2b4d3SLarry Finger 		rtl92c_dm_write_dig(hw);
1558f1d2b4d3SLarry Finger 		rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
1559f1d2b4d3SLarry Finger 		break;
1560f1d2b4d3SLarry Finger 	case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
1561f1d2b4d3SLarry Finger 		rtlphy->initgain_backup.xaagccore1 = dm_digtable->cur_igvalue;
1562f1d2b4d3SLarry Finger 		dm_digtable->cur_igvalue = 0x17;
1563f1d2b4d3SLarry Finger 		rtl92c_dm_write_dig(hw);
1564f1d2b4d3SLarry Finger 		break;
1565f1d2b4d3SLarry Finger 	default:
15665b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
1567ad574889SJoe Perches 			"switch case %#x not processed\n",
1568ad574889SJoe Perches 			rtlphy->current_io_type);
1569f1d2b4d3SLarry Finger 		break;
1570f1d2b4d3SLarry Finger 	}
1571f1d2b4d3SLarry Finger 	rtlphy->set_io_inprogress = false;
15725b4e998bSLarry Finger 	rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE,
1573f1d2b4d3SLarry Finger 		"(%#x)\n", rtlphy->current_io_type);
1574f1d2b4d3SLarry Finger }
1575f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92c_phy_set_io);
1576f1d2b4d3SLarry Finger 
rtl92ce_phy_set_rf_on(struct ieee80211_hw * hw)1577f1d2b4d3SLarry Finger void rtl92ce_phy_set_rf_on(struct ieee80211_hw *hw)
1578f1d2b4d3SLarry Finger {
1579f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1580f1d2b4d3SLarry Finger 
1581f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
1582f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
1583f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
1584f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
1585f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
1586f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
1587f1d2b4d3SLarry Finger }
1588f1d2b4d3SLarry Finger EXPORT_SYMBOL(rtl92ce_phy_set_rf_on);
1589f1d2b4d3SLarry Finger 
_rtl92c_phy_set_rf_sleep(struct ieee80211_hw * hw)1590f1d2b4d3SLarry Finger void _rtl92c_phy_set_rf_sleep(struct ieee80211_hw *hw)
1591f1d2b4d3SLarry Finger {
1592f1d2b4d3SLarry Finger 	u32 u4b_tmp;
1593f1d2b4d3SLarry Finger 	u8 delay = 5;
1594f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1595f1d2b4d3SLarry Finger 
1596f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
1597f1d2b4d3SLarry Finger 	rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
1598f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
1599f1d2b4d3SLarry Finger 	u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
1600f1d2b4d3SLarry Finger 	while (u4b_tmp != 0 && delay > 0) {
1601f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
1602f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
1603f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
1604f1d2b4d3SLarry Finger 		u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
1605f1d2b4d3SLarry Finger 		delay--;
1606f1d2b4d3SLarry Finger 	}
1607f1d2b4d3SLarry Finger 	if (delay == 0) {
1608f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
1609f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
1610f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
1611f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
16125b4e998bSLarry Finger 		rtl_dbg(rtlpriv, COMP_POWER, DBG_TRACE,
1613f1d2b4d3SLarry Finger 			"Switch RF timeout !!!.\n");
1614f1d2b4d3SLarry Finger 		return;
1615f1d2b4d3SLarry Finger 	}
1616f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
1617f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
1618f1d2b4d3SLarry Finger }
1619f1d2b4d3SLarry Finger EXPORT_SYMBOL(_rtl92c_phy_set_rf_sleep);
1620